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; }
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; }