VANetMessage.cpp 29 KB
Newer Older
1
2
3
4
5
6
/*
 *  --------------------------------------------------------------------------------------------
 *
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
7
 *       VVV  VVV     AAA        Copyright 2015-2020
8
9
10
11
12
13
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
 *
 *  --------------------------------------------------------------------------------------------
 */

Jonas Stienen's avatar
Jonas Stienen committed
14
15
16
17
18
19
#include "VANetMessage.h"

#include "VANetNetworkProtocol.h"

#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaBase/VistaExceptionBase.h>
20
#include <VistaBase/VistaStreamUtils.h>
Jonas Stienen's avatar
Jonas Stienen committed
21
22
23
24
25
26

#include <cassert>
#include <cstring>

static int S_nMessageIds = 0;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
27
CVANetMessage::CVANetMessage( const VistaSerializingToolset::ByteOrderSwapBehavior bSwapBuffers )
28
29
30
	: m_vecIncomingBuffer( 2048 )
	, m_oOutgoing( 2048 )
	, m_pConnection( NULL )
Jonas Stienen's avatar
Jonas Stienen committed
31
32
33
34
35
36
37
38
39
{
	m_oOutgoing.SetByteorderSwapFlag( bSwapBuffers );
	m_oIncoming.SetByteorderSwapFlag( bSwapBuffers );
	ResetMessage();
}

void CVANetMessage::ResetMessage()
{
	if( m_oIncoming.GetTailSize() > 0 )
40
		vstr::err() << "CVANetMessage::ResetMessage() called before message was fully processed!" << std::endl;
Jonas Stienen's avatar
Jonas Stienen committed
41
42
43
44

	// wait till sending is complete -> this prevents us
	// from deleting the buffer while it is still being read
	// by the connection
45
	if( m_pConnection )
Jonas Stienen's avatar
Jonas Stienen committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
		m_pConnection->WaitForSendFinish();

	m_nMessageId = S_nMessageIds++;

	m_oOutgoing.ClearBuffer();
	m_oOutgoing.WriteInt32( 0 ); // size dummy
	m_oOutgoing.WriteInt32( 0 ); // type dummy
	m_oOutgoing.WriteInt32( 0 ); // exceptmode dummy
	m_oOutgoing.WriteInt32( 0 ); // ID

	m_oIncoming.SetBuffer( NULL, 0 );

	m_nExceptionMode = CVANetNetworkProtocol::VA_NP_INVALID;
	m_nMessageType = CVANetNetworkProtocol::VA_NP_INVALID;
	m_nAnswerType = CVANetNetworkProtocol::VA_NP_INVALID;

	m_pConnection = NULL;
}

void CVANetMessage::SetConnection( VistaConnectionIP* pConn )
{
	m_pConnection = pConn;
}

void CVANetMessage::WriteMessage()
{
72
	VANetCompat::byte* pBuffer = ( VANetCompat::byte* )m_oOutgoing.GetBuffer();
Jonas Stienen's avatar
Jonas Stienen committed
73
74
75
	VANetCompat::sint32 iSwapDummy;

	// rewrite size dummy
76
	iSwapDummy = m_oOutgoing.GetBufferSize() - sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
77
78
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
79
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
80

81
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
82
83
84
85
86

	// rewrite type dummy
	iSwapDummy = m_nMessageType;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
87
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
88

89
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
90
91
92
93
94

	// rewrite exceptmode dummy
	iSwapDummy = m_nExceptionMode;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
95
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
96

97
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
98
99
100
101
102

	// rewrite messageid dummy
	iSwapDummy = m_nMessageId;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
103
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
104
105
106

	try
	{
107
108
		// It appears to be safe to transmit an entire buffer of arbitrary size on sender side
		int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), m_oOutgoing.GetBufferSize() );
Jonas Stienen's avatar
Jonas Stienen committed
109
110
		m_pConnection->WaitForSendFinish();
		if( nRet != m_oOutgoing.GetBufferSize() )
111
			VISTA_THROW( "Could not write the expected number of bytes", 255 );
Jonas Stienen's avatar
Jonas Stienen committed
112
	}
113
	catch( VistaExceptionBase& ex )
Jonas Stienen's avatar
Jonas Stienen committed
114
	{
115
		VA_EXCEPT2( NETWORK_ERROR, ex.GetExceptionText() );
Jonas Stienen's avatar
Jonas Stienen committed
116
117
118
119
120
121
122
123
124
	}
}

void CVANetMessage::ReadMessage()
{
	try
	{
		VANetCompat::sint32 nMessageSize;
		int nReturn = m_pConnection->ReadInt32( nMessageSize );
125
126
127

		if( nReturn != sizeof( VANetCompat::sint32 ) )
			VA_EXCEPT2( NETWORK_ERROR, "Received less bytes than expected" );
Jonas Stienen's avatar
Jonas Stienen committed
128
129

		// we need at least the three protocol ints
130
		assert( nMessageSize >= 3 * sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
131

132
		if( nMessageSize > ( int ) m_vecIncomingBuffer.size() )
Jonas Stienen's avatar
Jonas Stienen committed
133
134
			m_vecIncomingBuffer.resize( nMessageSize );

135
136
		int iBytesReadTotal = 0;
		while( nMessageSize != iBytesReadTotal )
137
138
		{
			int iIncommingBytes = m_pConnection->WaitForIncomingData( 0 );
139
140
141
142
			int iBytesRead = 0;
			if( iBytesReadTotal + iIncommingBytes > nMessageSize )
				iBytesRead = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ iBytesReadTotal ], nMessageSize - iBytesReadTotal ); // read residual bytes
			else
Jonas Stienen's avatar
Jonas Stienen committed
143
				iBytesRead = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ iBytesReadTotal ], iIncommingBytes ); // read all incoming bytes
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
144

145
			iBytesReadTotal += iBytesRead;
146
		}
147
		assert( iBytesReadTotal == nMessageSize );
Jonas Stienen's avatar
Jonas Stienen committed
148

149
		m_oIncoming.SetBuffer( ( VistaType::byte* ) &m_vecIncomingBuffer[ 0 ], nMessageSize, false );
Jonas Stienen's avatar
Jonas Stienen committed
150
	}
151
	catch( VistaExceptionBase& ex )
Jonas Stienen's avatar
Jonas Stienen committed
152
	{
153
154
		VA_EXCEPT2( NETWORK_ERROR, ex.GetExceptionText() );
	}
Jonas Stienen's avatar
Jonas Stienen committed
155
156
157
158
159
160
161
162

	m_nMessageType = ReadInt();
	m_nExceptionMode = ReadInt();
	m_nMessageId = ReadInt();
}

void CVANetMessage::WriteAnswer()
{
163
164
165
166
167

#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
	std::cout << "[ VANetMessage ][ DEBUG ] Writing answer" << std::endl;
#endif

168
	VANetCompat::byte* pBuffer = ( VANetCompat::byte* )m_oOutgoing.GetBuffer();
Jonas Stienen's avatar
Jonas Stienen committed
169
170
171
	VANetCompat::sint32 iSwapDummy;

	// rewrite size dummy
172
	iSwapDummy = m_oOutgoing.GetBufferSize() - sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
173
174
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
175
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
176

177
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
178
179
180
181
182

	// rewrite type dummy
	iSwapDummy = m_nAnswerType;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
183
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
184

185
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
186
187
188
189
190

	// rewrite exceptmode dummy
	iSwapDummy = m_nExceptionMode;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
191
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
192

193
	pBuffer += sizeof( VANetCompat::sint32 );
Jonas Stienen's avatar
Jonas Stienen committed
194
195
196
197
198

	// rewrite message dummy
	iSwapDummy = m_nMessageId;
	if( m_oOutgoing.GetByteorderSwapFlag() )
		VistaSerializingToolset::Swap4( &iSwapDummy );
199
	memcpy( pBuffer, &iSwapDummy, sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
200
201
202

	try
	{
203
204
		if (!m_pConnection)
			VISTA_THROW("Seems like the VA connections is lost, can not write VA net message answer", 255);
205
206
207
208
		
#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
		std::cout << "[ VANetMessage ][ DEBUG ] All seems good, will hand over buffer to network connection now" << std::endl;
#endif
209

210
211
		// It appears to be safe to transmit an entire buffer of arbitrary size on sender side
		int nRet = m_pConnection->WriteRawBuffer( m_oOutgoing.GetBuffer(), m_oOutgoing.GetBufferSize() );
Jonas Stienen's avatar
Jonas Stienen committed
212
		m_pConnection->WaitForSendFinish();
213
214
215
216
217

#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
		std::cout << "[ VANetMessage ][ DEBUG ] ... acknowledged." << std::endl;
#endif

Jonas Stienen's avatar
Jonas Stienen committed
218
		if( nRet != m_oOutgoing.GetBufferSize() )
219
			VISTA_THROW( "Could not write the expected number of bytes", 255 );
Jonas Stienen's avatar
Jonas Stienen committed
220
	}
221
	catch( VistaExceptionBase& ex )
Jonas Stienen's avatar
Jonas Stienen committed
222
	{
223
		VA_EXCEPT2( NETWORK_ERROR, ex.GetExceptionText() );
Jonas Stienen's avatar
Jonas Stienen committed
224
	}
225
226
227
228
229

#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
	std::cout << "[ VANetMessage ][ DEBUG ] Transmitted " << m_oOutgoing.GetBufferSize() << " bytes" << std::endl;
#endif

Jonas Stienen's avatar
Jonas Stienen committed
230
231
232
233
}

void CVANetMessage::ReadAnswer()
{
234
235
236
237
238
239
240

#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
	std::cout << "[ VANetMessage ][ DEBUG ] Reading answer" << std::endl;
#endif

	VANetCompat::sint32 nMessageSize;

Jonas Stienen's avatar
Jonas Stienen committed
241
242
	try
	{
243
244
245
246
247
248
249
250
251
		int nReturn;
		try
		{
			nReturn = m_pConnection->ReadInt32( nMessageSize );
		}
		catch( ... )
		{
			nReturn = -1; // Network connection error
		}
Dipl.-Ing. Jonas Stienen's avatar
style    
Dipl.-Ing. Jonas Stienen committed
252
253

		if( nReturn != sizeof( VANetCompat::sint32 ) )
254
		{
255
			VA_EXCEPT2( NETWORK_ERROR, "Received less bytes than expected during ReadAnswer of VANetMessage. Connection broken?" );
256
		}
Jonas Stienen's avatar
Jonas Stienen committed
257

258
259
		// we need at least the three protocol types
		assert( nMessageSize >= 3 * sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
260

261
		if( nMessageSize > ( int ) m_vecIncomingBuffer.size() )
Jonas Stienen's avatar
Jonas Stienen committed
262
263
			m_vecIncomingBuffer.resize( nMessageSize );

264
		int iBytesReceivedTotal = 0;
265
		while( nMessageSize > iBytesReceivedTotal )
266
267
268
269
270
271
272
273
		{
			int iIncommingBytes = m_pConnection->WaitForIncomingData( 0 );
			int iBytesReceived = m_pConnection->ReadRawBuffer( &m_vecIncomingBuffer[ iBytesReceivedTotal ], iIncommingBytes );
			iBytesReceivedTotal += iBytesReceived;
		}

		if( iBytesReceivedTotal != nMessageSize )
			VA_EXCEPT2( NETWORK_ERROR, "Reading message, but received less bytes than expected." );
Jonas Stienen's avatar
Jonas Stienen committed
274

275
		m_oIncoming.SetBuffer( ( VistaType::byte* ) &m_vecIncomingBuffer[ 0 ], nMessageSize, false );
Jonas Stienen's avatar
Jonas Stienen committed
276
	}
277
	catch( VistaExceptionBase& ex )
Jonas Stienen's avatar
Jonas Stienen committed
278
	{
279
		VA_EXCEPT2( NETWORK_ERROR, ex.GetExceptionText() );
Jonas Stienen's avatar
Jonas Stienen committed
280
281
282
283
284
285
286
	}

	m_nAnswerType = ReadInt();
	ReadInt(); // protocol overhead - just read and ignore
	int nMessageID = ReadInt();
	assert( nMessageID == m_nMessageId );
	m_nMessageId = nMessageID;
287
288
289
290
291

#ifdef VANET_NETWORK_COM_PRINT_DEBUG_INFOS
	std::cout << "[ VANetMessage ][ DEBUG ] Received " << nMessageSize << " bytes" << std::endl;
#endif

Jonas Stienen's avatar
Jonas Stienen committed
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
}

int CVANetMessage::GetExceptionMode() const
{
	return m_nExceptionMode;
}
int CVANetMessage::GetMessageType() const
{
	return m_nMessageType;
}
int CVANetMessage::GetAnswerType() const
{
	return m_nAnswerType;
}

307
void CVANetMessage::SetExceptionMode( const int nMode )
Jonas Stienen's avatar
Jonas Stienen committed
308
309
310
{
	m_nExceptionMode = nMode;
}
311
void CVANetMessage::SetMessageType( const int nType )
Jonas Stienen's avatar
Jonas Stienen committed
312
313
314
{
	m_nMessageType = nType;
}
315
void CVANetMessage::SetAnswerType( const int nType )
Jonas Stienen's avatar
Jonas Stienen committed
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
{
	m_nAnswerType = nType;
}

int CVANetMessage::GetIncomingMessageSize() const
{
	return m_oIncoming.GetTailSize();
}
int CVANetMessage::GetOutgoingMessageSize() const
{
	return m_oOutgoing.GetBufferSize();
}

bool CVANetMessage::GetOutgoingMessageHasData() const
{
331
	return ( m_oOutgoing.GetBufferSize() > 4 * sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
332
333
334
335
}

void CVANetMessage::WriteString( const std::string& sValue )
{
336
337
	m_oOutgoing.WriteInt32( ( VANetCompat::sint32 )sValue.size() );
	if( !sValue.empty() ) m_oOutgoing.WriteString( sValue );
Jonas Stienen's avatar
Jonas Stienen committed
338
339
340
}
void CVANetMessage::WriteInt( const int iValue )
{
341
	m_oOutgoing.WriteInt32( ( VANetCompat::sint32 )iValue );
Jonas Stienen's avatar
Jonas Stienen committed
342
343
344
}
void CVANetMessage::WriteUInt64( const uint64_t iValue )
{
345
	m_oOutgoing.WriteUInt64( ( VANetCompat::uint64 )iValue );
Jonas Stienen's avatar
Jonas Stienen committed
346
347
348
349
350
351
352
353
354
355
356
357
358
}
void CVANetMessage::WriteBool( const bool bValue )
{
	m_oOutgoing.WriteBool( bValue );
}
void CVANetMessage::WriteFloat( const float fValue )
{
	m_oOutgoing.WriteFloat32( fValue );
}
void CVANetMessage::WriteDouble( const double dValue )
{
	m_oOutgoing.WriteFloat64( dValue );
}
359

Jonas Stienen's avatar
Jonas Stienen committed
360
361
362
363
364
365
366
void CVANetMessage::WriteVec3( const VAVec3& oVec )
{
	WriteDouble( oVec.x );
	WriteDouble( oVec.y );
	WriteDouble( oVec.z );
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
367
void CVANetMessage::WriteQuat( const VAQuat& qOrient )
Jonas Stienen's avatar
Jonas Stienen committed
368
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
369
370
371
372
	WriteDouble( qOrient.x );
	WriteDouble( qOrient.y );
	WriteDouble( qOrient.z );
	WriteDouble( qOrient.w );
Jonas Stienen's avatar
Jonas Stienen committed
373
374
375
376
377
378
}

std::string CVANetMessage::ReadString()
{
	VANetCompat::sint32 nSize;
	int nReturn = m_oIncoming.ReadInt32( nSize );
379
380
	assert( nReturn == sizeof( VANetCompat::sint32 ) );

Jonas Stienen's avatar
Jonas Stienen committed
381
	// Empty string?
382
383
	if( nSize == 0 )
		return "";
Jonas Stienen's avatar
Jonas Stienen committed
384
385
386
387
388
389

	std::string sValue;
	nReturn = m_oIncoming.ReadString( sValue, nSize );
	assert( nReturn == nSize );
	return sValue;
}
390

Jonas Stienen's avatar
Jonas Stienen committed
391
392
393
394
int CVANetMessage::ReadInt()
{
	VANetCompat::sint32 nValue;
	int nReturn = m_oIncoming.ReadInt32( nValue );
395
	assert( nReturn == sizeof( VANetCompat::sint32 ) );
Jonas Stienen's avatar
Jonas Stienen committed
396
397
	return nValue;
}
398

Jonas Stienen's avatar
Jonas Stienen committed
399
400
401
402
uint64_t CVANetMessage::ReadUInt64()
{
	VANetCompat::uint64 nValue;
	int nReturn = m_oIncoming.ReadUInt64( nValue );
403
	assert( nReturn == sizeof( VANetCompat::uint64 ) );
Jonas Stienen's avatar
Jonas Stienen committed
404
405
	return nValue;
}
406

Jonas Stienen's avatar
Jonas Stienen committed
407
408
409
410
bool CVANetMessage::ReadBool()
{
	bool bValue;
	int nReturn = m_oIncoming.ReadBool( bValue );
411
	assert( nReturn == sizeof( bool ) );
Jonas Stienen's avatar
Jonas Stienen committed
412
413
	return bValue;
}
414

Jonas Stienen's avatar
Jonas Stienen committed
415
416
417
418
float CVANetMessage::ReadFloat()
{
	float fValue;
	int nReturn = m_oIncoming.ReadFloat32( fValue );
419
	assert( nReturn == sizeof( float ) );
Jonas Stienen's avatar
Jonas Stienen committed
420
421
	return fValue;
}
422

Jonas Stienen's avatar
Jonas Stienen committed
423
424
425
426
double CVANetMessage::ReadDouble()
{
	double dValue;
	int nReturn = m_oIncoming.ReadFloat64( dValue );
427
	assert( nReturn == sizeof( double ) );
Jonas Stienen's avatar
Jonas Stienen committed
428
429
430
431
432
433
434
435
	return dValue;
}

VAVec3 CVANetMessage::ReadVec3()
{
	double x = ReadDouble();
	double y = ReadDouble();
	double z = ReadDouble();
436
	return VAVec3( x, y, z );
Jonas Stienen's avatar
Jonas Stienen committed
437
438
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
439
VAQuat CVANetMessage::ReadQuat()
Jonas Stienen's avatar
Jonas Stienen committed
440
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
441
442
443
444
445
	double x = ReadDouble();
	double y = ReadDouble();
	double z = ReadDouble();
	double w = ReadDouble();
	return VAQuat( x, y, z, w );
Jonas Stienen's avatar
Jonas Stienen committed
446
447
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
448
void CVANetMessage::WriteEvent( const CVAEvent& oEvent )
Jonas Stienen's avatar
Jonas Stienen committed
449
{
450
	WriteUInt64( (size_t) oEvent.pSender );
Jonas Stienen's avatar
Jonas Stienen committed
451
452
453
454
455
456
457
458
459
460
461
462
	WriteInt( oEvent.iEventID );
	WriteUInt64( oEvent.iEventType );
	WriteInt( oEvent.iObjectID );
	WriteString( oEvent.sObjectID );
	WriteInt( oEvent.iParamID );
	WriteString( oEvent.sParam );
	WriteInt( oEvent.iIndex );
	WriteInt( oEvent.iAuralizationMode );
	WriteDouble( oEvent.dVolume );
	WriteDouble( oEvent.dState );
	WriteBool( oEvent.bMuted );
	WriteString( oEvent.sName );
463
	WriteString( oEvent.sFilenPath );
Jonas Stienen's avatar
Jonas Stienen committed
464
465
466
	WriteVec3( oEvent.vPos );
	WriteVec3( oEvent.vView );
	WriteVec3( oEvent.vUp );
467
	WriteQuat( oEvent.qHATO );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
468
	WriteQuat( oEvent.oOrientation );
Jonas Stienen's avatar
Jonas Stienen committed
469

470
471
472
	WriteInt( ( int ) oEvent.vfInputPeaks.size() );
	for( size_t i = 0; i < oEvent.vfInputPeaks.size(); i++ )
		WriteFloat( oEvent.vfInputPeaks[ i ] );
473
474
475
476
	WriteInt( ( int ) oEvent.vfInputRMSs.size() );
	for( size_t i = 0; i < oEvent.vfInputRMSs.size(); i++ )
		WriteFloat( oEvent.vfInputRMSs[ i ] );

477
478
479
	WriteInt( ( int ) oEvent.vfOutputPeaks.size() );
	for( size_t i = 0; i < oEvent.vfOutputPeaks.size(); i++ )
		WriteFloat( oEvent.vfOutputPeaks[ i ] );
480
481
482
	WriteInt( ( int ) oEvent.vfOutputRMSs.size() );
	for( size_t i = 0; i < oEvent.vfOutputRMSs.size(); i++ )
		WriteFloat( oEvent.vfOutputRMSs[ i ] );
Jonas Stienen's avatar
Jonas Stienen committed
483

484
485
486
	WriteFloat( oEvent.fSysLoad );
	WriteFloat( oEvent.fDSPLoad );
	WriteDouble( oEvent.dCoreClock );
487
488
489
490
491
492
493

	WriteInt( oEvent.oProgress.iCurrentStep );
	WriteInt( oEvent.oProgress.iMaxStep );
	WriteString( oEvent.oProgress.sAction );
	WriteString( oEvent.oProgress.sSubaction );

	WriteVAStruct( oEvent.oPrototypeParams );
Jonas Stienen's avatar
Jonas Stienen committed
494
495
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
496
CVAEvent CVANetMessage::ReadEvent()
Jonas Stienen's avatar
Jonas Stienen committed
497
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
498
	CVAEvent oEvent;
499
	oEvent.pSender = (IVAInterface*) ReadUInt64();
Jonas Stienen's avatar
Jonas Stienen committed
500
501
502
503
504
505
506
507
508
509
510
511
	oEvent.iEventID = ReadInt();
	oEvent.iEventType = ReadUInt64();
	oEvent.iObjectID = ReadInt();
	oEvent.sObjectID = ReadString();
	oEvent.iParamID = ReadInt();
	oEvent.sParam = ReadString();
	oEvent.iIndex = ReadInt();
	oEvent.iAuralizationMode = ReadInt();
	oEvent.dVolume = ReadDouble();
	oEvent.dState = ReadDouble();
	oEvent.bMuted = ReadBool();
	oEvent.sName = ReadString();
512
	oEvent.sFilenPath = ReadString();
Jonas Stienen's avatar
Jonas Stienen committed
513
514
515
	oEvent.vPos = ReadVec3();
	oEvent.vView = ReadVec3();
	oEvent.vUp = ReadVec3();
516
	oEvent.qHATO = ReadQuat();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
517
	oEvent.oOrientation = ReadQuat();
Jonas Stienen's avatar
Jonas Stienen committed
518
519

	int n = ReadInt();
520
521
	for( int i = 0; i < n; i++ )
		oEvent.vfInputPeaks.push_back( ReadFloat() );
Dipl.-Ing. Jonas Stienen's avatar
Bugfix    
Dipl.-Ing. Jonas Stienen committed
522
	n = ReadInt();
523
524
	for( int i = 0; i < n; i++ )
		oEvent.vfInputRMSs.push_back( ReadFloat() );
Jonas Stienen's avatar
Jonas Stienen committed
525
	n = ReadInt();
526
527
	for( int i = 0; i < n; i++ )
		oEvent.vfOutputPeaks.push_back( ReadFloat() );
528
529
530
	n = ReadInt();
	for( int i = 0; i < n; i++ )
		oEvent.vfOutputRMSs.push_back( ReadFloat() );
Jonas Stienen's avatar
Jonas Stienen committed
531
532
533
534
535

	oEvent.fSysLoad = ReadFloat();
	oEvent.fDSPLoad = ReadFloat();
	oEvent.dCoreClock = ReadDouble();

536
537
538
539
540
541
542
	oEvent.oProgress.iCurrentStep = ReadInt();
	oEvent.oProgress.iMaxStep = ReadInt();
	oEvent.oProgress.sAction = ReadString();
	oEvent.oProgress.sSubaction = ReadString();

	ReadVAStruct( oEvent.oPrototypeParams );

Jonas Stienen's avatar
Jonas Stienen committed
543
544
545
546
547
548
549
550
551
552
553
554
555
556
	return oEvent;
}


void CVANetMessage::WriteException( const CVAException& oException )
{
	WriteInt( oException.GetErrorCode() );
	WriteString( oException.GetErrorMessage() );
}

// Deserialize a VAException instance from a byte buffer (returns number of bytes read)
// (returns number of bytes read if successfull, otherwise -1)
CVAException CVANetMessage::ReadException()
{
557
	const int nType = ReadInt();
Jonas Stienen's avatar
Jonas Stienen committed
558
559
560
	return CVAException( nType, ReadString() );
}

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
561
void CVANetMessage::WriteVersionInfo( const CVAVersionInfo& oInfo )
Jonas Stienen's avatar
Jonas Stienen committed
562
563
564
565
566
567
{
	WriteString( oInfo.sVersion );
	WriteString( oInfo.sFlags );
	WriteString( oInfo.sDate );
	WriteString( oInfo.sComments );
}
568

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
569
CVAVersionInfo CVANetMessage::ReadVersionInfo()
Jonas Stienen's avatar
Jonas Stienen committed
570
{
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
571
	CVAVersionInfo oInfo;
Jonas Stienen's avatar
Jonas Stienen committed
572
573
574
575
576
577
	oInfo.sVersion = ReadString();
	oInfo.sFlags = ReadString();
	oInfo.sDate = ReadString();
	oInfo.sComments = ReadString();
	return oInfo;
}
578

Jonas Stienen's avatar
Jonas Stienen committed
579
580
581
void CVANetMessage::WriteDirectivityInfo( const CVADirectivityInfo& oInfo )
{
	WriteInt( oInfo.iID );
582
583
	WriteInt( oInfo.iClass );
	WriteString( oInfo.sName );
Jonas Stienen's avatar
Jonas Stienen committed
584
	WriteString( oInfo.sDesc );
585
586
	WriteInt( oInfo.iReferences );
	WriteVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
587
}
588

Jonas Stienen's avatar
Jonas Stienen committed
589
590
591
592
CVADirectivityInfo CVANetMessage::ReadDirectivityInfo()
{
	CVADirectivityInfo oInfo;
	oInfo.iID = ReadInt();
593
594
	oInfo.iClass = ReadInt();
	oInfo.sName = ReadString();
Jonas Stienen's avatar
Jonas Stienen committed
595
	oInfo.sDesc = ReadString();
596
597
	oInfo.iReferences = ReadInt();
	ReadVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
598
599
	return oInfo;
}
600

Jonas Stienen's avatar
Jonas Stienen committed
601
602
603
void CVANetMessage::WriteSignalSourceInfo( const CVASignalSourceInfo& oInfo )
{
	WriteString( oInfo.sID );
604
605
	WriteInt( oInfo.iType );
	WriteString( oInfo.sName );
Jonas Stienen's avatar
Jonas Stienen committed
606
	WriteString( oInfo.sDesc );
607
	WriteString( oInfo.sState );
Jonas Stienen's avatar
Jonas Stienen committed
608
609
	WriteInt( oInfo.iReferences );
}
610

Jonas Stienen's avatar
Jonas Stienen committed
611
612
613
614
CVASignalSourceInfo CVANetMessage::ReadSignalSourceInfo()
{
	CVASignalSourceInfo oInfo;
	oInfo.sID = ReadString();
615
616
	oInfo.iType = ReadInt();
	oInfo.sName = ReadString();
Jonas Stienen's avatar
Jonas Stienen committed
617
	oInfo.sDesc = ReadString();
618
	oInfo.sState = ReadString();
Jonas Stienen's avatar
Jonas Stienen committed
619
620
621
	oInfo.iReferences = ReadInt();
	return oInfo;
}
622

623
void CVANetMessage::WriteSceneInfo( const CVASceneInfo& oInfo )
Jonas Stienen's avatar
Jonas Stienen committed
624
{
625
626
627
628
	WriteString( oInfo.sID );
	WriteString( oInfo.sName );
	WriteBool( oInfo.bEnabled );
	WriteVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
629
630
631
632
633
}

CVASceneInfo CVANetMessage::ReadSceneInfo()
{
	CVASceneInfo oInfo;
634
635
636
637
	oInfo.sID = ReadString();
	oInfo.sName = ReadString();
	oInfo.bEnabled = ReadBool();
	ReadVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
638
639
640
641
642
643
644
	return oInfo;
}

void CVANetMessage::WriteModuleInfo( const CVAModuleInfo& oInfo )
{
	WriteString( oInfo.sName );
	WriteString( oInfo.sDesc );
645
	WriteVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
646
647
648
649
650
651
}

void CVANetMessage::ReadModuleInfo( CVAModuleInfo& oInfo )
{
	oInfo.sName = ReadString();
	oInfo.sDesc = ReadString();
652
	ReadVAStruct( oInfo.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
653
654
}

655
void CVANetMessage::WriteBlob( const void* pBuf, const int nBytes )
Jonas Stienen's avatar
Jonas Stienen committed
656
{
657
	m_oOutgoing.WriteRawBuffer( pBuf, nBytes );
Jonas Stienen's avatar
Jonas Stienen committed
658
659
}

660
void CVANetMessage::ReadBlob( void* pBuf, const int nBytes )
Jonas Stienen's avatar
Jonas Stienen committed
661
662
663
664
665
666
667
668
669
670
671
{
	int nReturn = m_oIncoming.ReadRawBuffer( pBuf, nBytes );
	assert( nReturn == nBytes );
}

void CVANetMessage::WriteVAStruct( const CVAStruct& oStruct )
{
	// Anzahl der Keys schreiben
	WriteInt( oStruct.Size() );

	int nBytes;
672
673
	for( CVAStruct::const_iterator cit = oStruct.Begin(); cit != oStruct.End(); ++cit )
	{
Jonas Stienen's avatar
Jonas Stienen committed
674
675
676
677
678
679
680
681
		// Schlsselnamen
		WriteString( cit->first );

		// Wert-Typ
		int iDatatype = cit->second.GetDatatype();
		WriteInt( iDatatype );

		// Wert
682
683
		switch( iDatatype )
		{
Jonas Stienen's avatar
Jonas Stienen committed
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
		case CVAStructValue::UNASSIGNED:
			// Keinen Wert => Nichts schreiben
			break;

		case CVAStructValue::BOOL:
			WriteBool( cit->second );
			break;

		case CVAStructValue::INT:
			WriteInt( cit->second );
			break;

		case CVAStructValue::DOUBLE:
			WriteDouble( cit->second );
			break;

		case CVAStructValue::STRING:
			WriteString( cit->second );
			break;

		case CVAStructValue::STRUCT:
			WriteVAStruct( cit->second.GetStruct() );
			break;

		case CVAStructValue::DATA:
			nBytes = cit->second.GetDataSize();
			WriteInt( nBytes );
			WriteBlob( cit->second.GetData(), nBytes );
			break;

		case CVAStructValue::SAMPLEBUFFER:
715
716
717
718
719
720
		{
			const CVASampleBuffer& oSampleBuffer( cit->second );
			WriteInt( oSampleBuffer.GetNumSamples() );
			for( int i = 0; i < oSampleBuffer.GetNumSamples(); i++ )
				WriteFloat( oSampleBuffer.vfSamples[ i ] );
		}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
721
		break;
Jonas Stienen's avatar
Jonas Stienen committed
722
723
724

		default:
			// Implementierung vergessen? Oder neuer Datentyp?
725
			VA_EXCEPT2( PROTOCOL_ERROR, "Unsupported key datatype" );
Jonas Stienen's avatar
Jonas Stienen committed
726
727
728
729
730
731
732
733
734
735
736
		}
	}
}

void CVANetMessage::ReadVAStruct( CVAStruct& oStruct )
{
	oStruct.Clear();

	// Anzahl der Keys lesen
	int nKeys = ReadInt();

737
738
	for( int i = 0; i < nKeys; i++ )
	{
Jonas Stienen's avatar
Jonas Stienen committed
739
740
741
742
743
744
745
		// Schlsselnamen
		std::string sKeyName = ReadString();

		// Wert-Typ
		int iDatatype = ReadInt();

		// Wert
746
747
		switch( iDatatype )
		{
Jonas Stienen's avatar
Jonas Stienen committed
748
749
		case CVAStructValue::UNASSIGNED:
			// Keinen Wert => Leeren Schssel
750
			oStruct[ sKeyName ];
Jonas Stienen's avatar
Jonas Stienen committed
751
752
753
			break;

		case CVAStructValue::BOOL:
754
			oStruct[ sKeyName ] = ReadBool();
Jonas Stienen's avatar
Jonas Stienen committed
755
756
757
			break;

		case CVAStructValue::INT:
758
			oStruct[ sKeyName ] = ReadInt();
Jonas Stienen's avatar
Jonas Stienen committed
759
760
761
			break;

		case CVAStructValue::DOUBLE:
762
			oStruct[ sKeyName ] = ReadDouble();
Jonas Stienen's avatar
Jonas Stienen committed
763
764
765
			break;

		case CVAStructValue::STRING:
766
			oStruct[ sKeyName ] = ReadString();
Jonas Stienen's avatar
Jonas Stienen committed
767
768
769
			break;

		case CVAStructValue::STRUCT:
770
771
772
773
774
		{
			CVAStruct oSubstruct;
			ReadVAStruct( oSubstruct );
			oStruct[ sKeyName ] = oSubstruct;
		}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
775
		break;
Jonas Stienen's avatar
Jonas Stienen committed
776
777

		case CVAStructValue::DATA:
778
779
780
781
		{
			int iDataSize = ReadInt();
			void* pData = ( void* ) new char[ iDataSize ];
			try
Jonas Stienen's avatar
Jonas Stienen committed
782
			{
783
				ReadBlob( pData, iDataSize );
Jonas Stienen's avatar
Jonas Stienen committed
784
			}
785
786
787
788
789
790
791
			catch( ... )
			{
				delete[] pData;
				throw;
			}
			oStruct[ sKeyName ] = CVAStructValue( pData, iDataSize );
		}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
792
		break;
Jonas Stienen's avatar
Jonas Stienen committed
793
794

		case CVAStructValue::SAMPLEBUFFER:
795
796
797
		{
			int iNumSamples = ReadInt();
			oStruct[ sKeyName ] = CVASampleBuffer( iNumSamples, false );
798
			CVASampleBuffer& oSampleBuffer( oStruct[ sKeyName.c_str() ] );
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
799
800
			for( int j= 0; j < iNumSamples; j++ )
				oSampleBuffer.vfSamples[ j ] = ReadFloat();
801
		}
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
802
		break;
Jonas Stienen's avatar
Jonas Stienen committed
803
804
805

		default:
			// Implementierung vergessen? Oder neuer Datentyp?
806
			VA_EXCEPT2( PROTOCOL_ERROR, "Structure contains unknown key datatype" );
Jonas Stienen's avatar
Jonas Stienen committed
807
808
		}
	}
809

Jonas Stienen's avatar
Jonas Stienen committed
810
811
812
813
814
815
816
817
818
819
820
821
}

VistaConnectionIP* CVANetMessage::GetConnection() const
{
	return m_pConnection;
}

void CVANetMessage::ClearConnection()
{
	m_pConnection = NULL;
}

822
823
824
825
826
827
828
829
830
CVAAcousticMaterial CVANetMessage::ReadAcousticMaterial()
{
	CVAAcousticMaterial oMaterial;
	oMaterial.iID = ReadInt();
	oMaterial.iType = ReadInt();
	ReadVAStruct( oMaterial.oParams );
	oMaterial.sName = ReadString();
	const size_t n = ReadInt();
	for( size_t i = 0; i < n; i++ )
831
832
833
834
835
836
837
		oMaterial.vfAbsorptionValues.push_back( ReadFloat() );
	const size_t o = ReadInt();
	for( size_t i = 0; i < o; i++ )
		oMaterial.vfScatteringValues.push_back( ReadFloat() );
	const size_t p = ReadInt();
	for( size_t i = 0; i < p; i++ )
		oMaterial.vfTransmissionValues.push_back( ReadFloat() );
838
839
840
841
842
843
844
845
846
	return oMaterial;
}

void CVANetMessage::WriteAcousticMaterial( const CVAAcousticMaterial& oMaterial )
{
	WriteInt( oMaterial.iID );
	WriteInt( oMaterial.iType );
	WriteVAStruct( oMaterial.oParams );
	WriteString( oMaterial.sName );
847
848
849
850
851
852
853
854
855
	WriteInt( ( int ) oMaterial.vfAbsorptionValues.size() );
	for( size_t i = 0; i < oMaterial.vfAbsorptionValues.size(); i++ )
		WriteFloat( oMaterial.vfAbsorptionValues[ i ] );
	WriteInt( ( int ) oMaterial.vfScatteringValues.size() );
	for( size_t i = 0; i < oMaterial.vfScatteringValues.size(); i++ )
		WriteFloat( oMaterial.vfScatteringValues[ i ] );
	WriteInt( ( int ) oMaterial.vfTransmissionValues.size() );
	for( size_t i = 0; i < oMaterial.vfTransmissionValues.size(); i++ )
		WriteFloat( oMaterial.vfTransmissionValues[ i ] );
856
857
}

858
void CVANetMessage::WriteAudioRenderingModuleInfo( const CVAAudioRendererInfo& oRenderer )
Jonas Stienen's avatar
Jonas Stienen committed
859
860
861
{
	WriteString( oRenderer.sID );
	WriteString( oRenderer.sClass );
862
	WriteString( oRenderer.sDescription );
863
864
865
866
867
	WriteBool( oRenderer.bEnabled );
	WriteBool( oRenderer.bOutputDetectorEnabled );
	WriteBool( oRenderer.bOutputRecordingEnabled );
	WriteString( oRenderer.sOutputRecordingFilePath );
	WriteVAStruct( oRenderer.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
868
869
}

870
871
872
873
874
875
876
877
878
879
880
881
882
883
CVAAudioRendererInfo CVANetMessage::ReadAudioRenderingModuleInfo()
{
	CVAAudioRendererInfo oRenderer;
	oRenderer.sID = ReadString();
	oRenderer.sClass = ReadString();
	oRenderer.sDescription = ReadString();
	oRenderer.bEnabled = ReadBool();
	oRenderer.bOutputDetectorEnabled = ReadBool();
	oRenderer.bOutputRecordingEnabled = ReadBool();
	oRenderer.sOutputRecordingFilePath = ReadString();
	ReadVAStruct( oRenderer.oParams );
	return oRenderer;
}

884
void CVANetMessage::WriteAudioReproductionModuleInfo( const CVAAudioReproductionInfo& oRepro )
Jonas Stienen's avatar
Jonas Stienen committed
885
886
887
{
	WriteString( oRepro.sID );
	WriteString( oRepro.sClass );
888
	WriteString( oRepro.sDescription );
889
890
891
892
893
894
895
896
	WriteBool( oRepro.bEnabled );
	WriteBool( oRepro.bInputDetectorEnabled );
	WriteBool( oRepro.bInputRecordingEnabled );
	WriteString( oRepro.sInputRecordingFilePath );
	WriteBool( oRepro.bOutputDetectorEnabled );
	WriteBool( oRepro.bOutputRecordingEnabled );
	WriteString( oRepro.sOutputRecordingFilePath );
	WriteVAStruct( oRepro.oParams );
Jonas Stienen's avatar
Jonas Stienen committed
897
898
}

899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
CVAAudioReproductionInfo CVANetMessage::ReadAudioReproductionModuleInfo()
{
	CVAAudioReproductionInfo oRepro;
	oRepro.sID = ReadString();
	oRepro.sClass = ReadString();
	oRepro.sDescription = ReadString();
	oRepro.bEnabled = ReadBool();
	oRepro.bInputDetectorEnabled = ReadBool();
	oRepro.bInputRecordingEnabled = ReadBool();
	oRepro.sInputRecordingFilePath = ReadString();
	oRepro.bOutputDetectorEnabled = ReadBool();
	oRepro.bOutputRecordingEnabled = ReadBool();
	oRepro.sOutputRecordingFilePath = ReadString();
	ReadVAStruct( oRepro.oParams );
	return oRepro;
}

916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
void CVANetMessage::WriteSoundSourceInfo( const CVASoundSourceInfo& oInfo )
{
	WriteBool( oInfo.bMuted );
	WriteDouble( oInfo.dSpoundPower );
	WriteInt( oInfo.iAuraMode );
	WriteInt( oInfo.iDirectivityID );
	WriteInt( oInfo.iID );
	WriteInt( oInfo.iSignalSourceID );
	WriteVAStruct( oInfo.oParams );
	WriteQuat( oInfo.qOrient );
	WriteString( oInfo.sName );
	WriteVec3( oInfo.v3Pos );
	WriteVec3( oInfo.v3Up );
	WriteVec3( oInfo.v3View );
}

932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
CVASoundSourceInfo CVANetMessage::ReadSoundSourceInfo()
{
	CVASoundSourceInfo oInfo;
	oInfo.bMuted = ReadBool();
	oInfo.dSpoundPower = ReadDouble();
	oInfo.iAuraMode = ReadInt();
	oInfo.iDirectivityID = ReadInt();
	oInfo.iID = ReadInt();
	oInfo.iSignalSourceID = ReadInt();
	ReadVAStruct( oInfo.oParams );
	oInfo.qOrient = ReadQuat();
	oInfo.sName = ReadString();
	oInfo.v3Pos = ReadVec3();
	oInfo.v3Up = ReadVec3();
	oInfo.v3View = ReadVec3();
	return oInfo;
}

950
951
952
953
954
955
956
957
958
959
960
961
void CVANetMessage::WriteSoundReceiverInfo( const CVASoundReceiverInfo& oInfo )
{
	WriteInt( oInfo.iID );
	WriteString( oInfo.sName );
	WriteInt( oInfo.iDirectivityID );
	WriteInt( oInfo.iAuraMode );
	WriteDouble( oInfo.dSensivitity );
	WriteBool( oInfo.bEnabled );
	WriteVec3( oInfo.v3Pos );
	WriteVec3( oInfo.v3View );
	WriteVec3( oInfo.v3Up );
	WriteQuat( oInfo.qOrient );
962
963
964
965
966
967
	WriteQuat( oInfo.qHeadAboveTorsoOrientation );
	WriteVec3( oInfo.v3RealWorldPos );
	WriteVec3( oInfo.v3RealWorldView );
	WriteVec3( oInfo.v3RealWorldUp );
	WriteQuat( oInfo.qRealWorldOrient );
	WriteQuat( oInfo.qRealWorldHeadAboveTorsoOrientation );
968
969
970
	WriteVAStruct( oInfo.oParams );
}

971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
CVASoundReceiverInfo CVANetMessage::ReadSoundReceiverInfo()
{
	CVASoundReceiverInfo oInfo;
	oInfo.iID = ReadInt();
	oInfo.sName = ReadString();
	oInfo.iDirectivityID = ReadInt();
	oInfo.iAuraMode = ReadInt();
	oInfo.dSensivitity = ReadDouble();
	oInfo.bEnabled = ReadBool();
	oInfo.v3Pos = ReadVec3();
	oInfo.v3View = ReadVec3();
	oInfo.v3Up = ReadVec3();
	oInfo.qOrient = ReadQuat();
	oInfo.qHeadAboveTorsoOrientation = ReadQuat();
	oInfo.v3RealWorldPos = ReadVec3();
	oInfo.v3RealWorldView = ReadVec3();
	oInfo.v3RealWorldUp = ReadVec3();
	oInfo.qRealWorldOrient = ReadQuat();
	oInfo.qRealWorldHeadAboveTorsoOrientation = ReadQuat();
	ReadVAStruct( oInfo.oParams );
	return oInfo;
}

994
void CVANetMessage::WriteSoundPortalInfo( const CVASoundPortalInfo& oInfo )
995
{
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
	WriteBool( oInfo.bEnabled );
	WriteInt( oInfo.iMaterialID );
	WriteInt( oInfo.iNextPortalID );
	WriteInt( oInfo.iSoundReceiverID );
	WriteInt( oInfo.iID );
	WriteInt( oInfo.iSoundSourceID );
	WriteVAStruct( oInfo.oParams );
	WriteQuat( oInfo.qOrient );
	WriteString( oInfo.sName );
	WriteVec3( oInfo.v3Pos );
	WriteVec3( oInfo.v3View );
	WriteVec3( oInfo.v3Up );
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
}

CVASoundPortalInfo CVANetMessage::ReadSoundPortalInfo()
{
	CVASoundPortalInfo oInfo;
	oInfo.bEnabled = ReadBool();
	oInfo.iMaterialID = ReadInt();
	oInfo.iNextPortalID = ReadInt();
	oInfo.iSoundReceiverID = ReadInt();
	oInfo.iID = ReadInt();
	oInfo.iSoundSourceID = ReadInt();
	ReadVAStruct( oInfo.oParams );
	oInfo.qOrient = ReadQuat();
	oInfo.sName = ReadString();
	oInfo.v3Pos = ReadVec3();
	oInfo.v3View = ReadVec3();
	oInfo.v3Up = ReadVec3();
	return oInfo;
}
1027

1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
void CVANetMessage::WriteGeometryMesh( const CVAGeometryMesh& oMesh )
{
	WriteBool( oMesh.bEnabled );
	WriteInt( oMesh.iID );
	WriteVAStruct( oMesh.oParams );
	WriteInt( int( oMesh.voFaces.size() ) );
	for( size_t i = 0; i < oMesh.voFaces.size(); i++ )
		WriteGeometryMeshFace( ( oMesh.voFaces[ i ] ) );
	WriteInt( int( oMesh.voVertices.size() ) );
	for( size_t i = 0; i < oMesh.voVertices.size(); i++ )
		WriteGeometryMeshVertex( oMesh.voVertices[ i ] );
}

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
CVAGeometryMesh CVANetMessage::ReadGeometryMesh()
{
	CVAGeometryMesh oMesh;
	oMesh.bEnabled = ReadBool();
	oMesh.iID = ReadInt();
	ReadVAStruct( oMesh.oParams );
	const int iNumFaces = ReadInt();
	for( int i = 0; i < iNumFaces; i++ )
		oMesh.voFaces.push_back( ReadGeometryMeshFace() );
	const int iNumVertices = ReadInt();
	for( int i = 0; i < iNumVertices; i++ )
		oMesh.voVertices.push_back( ReadGeometryMeshVertex() );
	return oMesh;
}

1056
1057
1058
1059
1060
1061
1062
1063
1064
void CVANetMessage::WriteGeometryMeshFace( const CVAGeometryMesh::CVAFace & oFace )
{
	WriteInt( oFace.iID );
	WriteInt( oFace.iMaterialID );
	WriteInt( int( oFace.viVertexList.size() ) );
	for( size_t i = 0; i < oFace.viVertexList.size(); i++ )
		WriteInt( oFace.viVertexList[ i ] );
}

1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
CVAGeometryMesh::CVAFace CVANetMessage::ReadGeometryMeshFace()
{
	CVAGeometryMesh::CVAFace oFace;
	oFace.iID = ReadInt();
	oFace.iMaterialID = ReadInt();
	const int iNumVertices = ReadInt();
	for( int i = 0; i < iNumVertices; i++ )
		oFace.viVertexList.push_back( ReadInt() );
	return oFace;
}

1076
1077
1078
1079
1080
1081
void CVANetMessage::WriteGeometryMeshVertex( const CVAGeometryMesh::CVAVertex & oVertex )
{
	WriteInt( oVertex.iID );
	WriteVec3( oVertex.v3Point );
}

1082
1083
1084
1085
1086
1087
1088
CVAGeometryMesh::CVAVertex CVANetMessage::ReadGeometryMeshVertex()
{
	CVAGeometryMesh::CVAVertex oVertex;
	oVertex.iID = ReadInt();
	oVertex.v3Point = ReadVec3();
	return oVertex;
}