Example #1
0
int CBlockMember::ReadMember( char **stream, long *streamPos, CIcarus* icarus )
{
	IGameInterface* game = icarus->GetGame();
	m_id = *(int *) (*stream + *streamPos);
	*streamPos += sizeof( int );

	if ( m_id == CIcarus::ID_RANDOM )
	{//special case, need to initialize this member's data to Q3_INFINITE so we can randomize the number only the first time random is checked when inside a wait
		m_size = sizeof( float );
		*streamPos += sizeof( long );
		m_data = game->Malloc( m_size );
		float infinite = game->MaxFloat();
		memcpy( m_data, &infinite, m_size );
	}
	else
	{
		m_size = *(long *) (*stream + *streamPos);
		*streamPos += sizeof( long );
		m_data = game->Malloc( m_size );
		memcpy( m_data, (*stream + *streamPos), m_size );
	}
	*streamPos += m_size;
	
	return true;
}
Example #2
0
int CBlockMember::ReadMember( char **stream, long *streamPos, CIcarus* icarus )
{
	IGameInterface* game = icarus->GetGame();
	m_id = LittleLong(*(int *) (*stream + *streamPos));
	*streamPos += sizeof( int );

	if ( m_id == CIcarus::ID_RANDOM )
	{//special case, need to initialize this member's data to Q3_INFINITE so we can randomize the number only the first time random is checked when inside a wait
		m_size = sizeof( float );
		*streamPos += sizeof( int );
		m_data = game->Malloc( m_size );
		float infinite = game->MaxFloat();
		memcpy( m_data, &infinite, m_size );
	}
	else
	{
		m_size = LittleLong(*(int *) (*stream + *streamPos));
		*streamPos += sizeof( int );
		m_data = game->Malloc( m_size );
		memcpy( m_data, (*stream + *streamPos), m_size );
#ifdef Q3_BIG_ENDIAN
		// only TK_INT, TK_VECTOR and TK_FLOAT has to be swapped, but just in case
		if (m_size == 4 && m_id != CIcarus::TK_STRING && m_id != CIcarus::TK_IDENTIFIER && m_id != CIcarus::TK_CHAR)
			*(int *)m_data = LittleLong(*(int *)m_data);
#endif
	}
	*streamPos += m_size;
	
	return true;
}
Example #3
0
void CBlockMember::SetData( void *data, int size, CIcarus* icarus)
{
	IGameInterface* game = icarus->GetGame();
	if ( m_data )
		game->Free( m_data );

	m_data = game->Malloc( size );
	memcpy( m_data, data, size );
	m_size = size;
}
Example #4
0
int CSequence::LoadCommand( CBlock *block, CIcarus *icarus )
{
	IGameInterface* game = icarus->GetGame();
	int				bID, bSize;
	void			*bData;
	unsigned char	flags;
	int				id, numMembers;

	// Data expected/loaded here (IBLK) (with the size as : 'IBSZ' ).
	//	Block ID.
	//	Block Flags.
	//	Number of Block Members.
	//	Block Members:
	//				- Block Member ID.
	//				- Block Data Size.
	//				- Block (Raw) Data.

	//Get the block ID.
	icarus->BufferRead( &id, sizeof( id ) );
	block->Create( id );

	//Read the block's flags
	icarus->BufferRead( &flags, sizeof( flags ) );
	block->SetFlags( flags );

	//Get the number of block members
	icarus->BufferRead( &numMembers, sizeof( numMembers ) );

	for ( int j = 0; j < numMembers; j++ )
	{
		//Get the member ID
		icarus->BufferRead( &bID, sizeof( bID ) );

		//Get the member size
		icarus->BufferRead( &bSize, sizeof( bSize ) );

		//Get the member's data
		if ( ( bData = game->Malloc( bSize ) ) == NULL )
			return false;

		//Get the actual raw data
		icarus->BufferRead( bData, bSize );

		//Write out the correct type
		switch ( bID )
		{
		case CIcarus::TK_INT:
			{
				assert(0);
				int data = *(int *) bData;
				block->Write( CIcarus::TK_FLOAT, (float) data, icarus );
			}
			break;

		case CIcarus::TK_FLOAT:
			block->Write( CIcarus::TK_FLOAT, *(float *) bData, icarus );
			break;

		case CIcarus::TK_STRING:
		case CIcarus::TK_IDENTIFIER:
		case CIcarus::TK_CHAR:
			block->Write( CIcarus::TK_STRING, (char *) bData, icarus );
			break;

		case CIcarus::TK_VECTOR:
		case CIcarus::TK_VECTOR_START:
			block->Write( CIcarus::TK_VECTOR, *(vec3_t *) bData, icarus );
			break;

		case CIcarus::ID_TAG:
			block->Write( CIcarus::ID_TAG, (float) CIcarus::ID_TAG, icarus );
			break;

		case CIcarus::ID_GET:
			block->Write( CIcarus::ID_GET, (float) CIcarus::ID_GET, icarus );
			break;

		case CIcarus::ID_RANDOM:
			block->Write( CIcarus::ID_RANDOM, *(float *) bData, icarus );//(float) ID_RANDOM );
			break;

		case CIcarus::TK_EQUALS:
		case CIcarus::TK_GREATER_THAN:
		case CIcarus::TK_LESS_THAN:
		case CIcarus::TK_NOT:
			block->Write( bID, 0, icarus );
			break;

		default:
			assert(0);
			return false;
			break;
		}

		//Get rid of the temp memory
		game->Free( bData );
	}

	return true;
}