void netcpy(NetDistributionPacket* dest, const NetDistributionPacket_NET* src) { uint8 *S = (uint8 *)src->data; StreamToValue(S,dest->distribution_type); StreamToValue(S,dest->first_player_index); StreamToValue(S,dest->data_size); assert(S == src->data + SIZEOF_NetDistributionPacket); }
void netcpy(NetPacket* dest, const NetPacket_NET* src) { uint8 *S = (uint8 *)src->data; dest->ring_packet_type = *(S++); dest->server_player_index = *(S++); StreamToValue(S,dest->server_net_time); StreamToValue(S,dest->required_action_flags); for (int i=0; i<MAXIMUM_NUMBER_OF_NETWORK_PLAYERS; i++) StreamToValue(S,dest->action_flag_count[i]); assert(S == src->data + SIZEOF_NetPacket); }
bool ReadChunkHeader(OpenedFile& OFile, ChunkHeaderData& ChunkHeader) { uint8 Buffer[SIZEOF_ChunkHeaderData]; if (!OFile.Read(SIZEOF_ChunkHeaderData,Buffer)) { logError1("ERROR reading chunk header in %s",Path); return false; } uint8 *S = Buffer; StreamToValue(S,ChunkHeader.ID); StreamToValue(S,ChunkHeader.Size); return true; }
bool ReadChunkHeader(OpenedFile& OFile, ChunkHeaderData& ChunkHeader) { uint8 Buffer[SIZEOF_ChunkHeaderData]; if (!OFile.Read(SIZEOF_ChunkHeaderData,Buffer)) { if (DBOut) fprintf(DBOut,"ERROR reading chunk header\n"); return false; } uint8 *S = Buffer; StreamToValue(S,ChunkHeader.ID); StreamToValue(S,ChunkHeader.Size); return true; }
uint8 *unpack_recording_header(uint8 *Stream, recording_header *Objects, size_t Count) { uint8* S = Stream; recording_header* ObjPtr = Objects; for (size_t k = 0; k < Count; k++, ObjPtr++) { StreamToValue(S,ObjPtr->length); StreamToValue(S,ObjPtr->num_players); StreamToValue(S,ObjPtr->level_number); StreamToValue(S,ObjPtr->map_checksum); StreamToValue(S,ObjPtr->version); for (int m = 0; m < MAXIMUM_NUMBER_OF_PLAYERS; m++) StreamToPlayerStart(S,ObjPtr->starts[m]); StreamToGameData(S,ObjPtr->game_information); } assert(static_cast<size_t>(S - Stream) == (Count*SIZEOF_recording_header)); return S; }
static void LoadTextureCoordinates() { uint8 *S = ChunkBufferBase(); uint16 Size; StreamToValue(S,Size); int NVals = 2*int(Size); ModelPtr->TxtrCoords.resize(NVals); LoadFloats(NVals,S,ModelPtr->TCBase()); }
static void LoadVertices() { uint8 *S = ChunkBufferBase(); uint16 Size; StreamToValue(S,Size); int NVals = 3*int(Size); ModelPtr->Positions.resize(NVals); LoadFloats(NVals,S,ModelPtr->PosBase()); }
static void StreamToGameData(uint8* &S, game_data& Object) { StreamToValue(S,Object.game_time_remaining); StreamToValue(S,Object.game_type); StreamToValue(S,Object.game_options); StreamToValue(S,Object.kill_limit); StreamToValue(S,Object.initial_random_seed); StreamToValue(S,Object.difficulty_level); StreamToList(S,Object.parameters,2); }
void LoadFloats(int NVals, uint8 *Stream, GLfloat *Floats) { // Test to see whether the destination floating-point values are the right size: assert(sizeof(GLfloat) == 4); uint32 IntVal; GLfloat *FloatPtr = Floats; for (int k=0; k<NVals; k++, FloatPtr++) { // Intermediate step: 4-byte integer // (won't have the right value if interpreted as an integer!) StreamToValue(Stream,IntVal); // This will work on any platform where // GLfloat is an IEEE 754 4-byte float. // Otherwise, use whatever appropriate conversion tricks are appropriate uint8 *SrcPtr = (uint8 *)(&IntVal); uint8 *DestPtr = (uint8 *)FloatPtr; for (int c=0; c<4; c++) DestPtr[c] = SrcPtr[c]; } }
static void read_recording_queue_chunks( void) { logContext("reading recording queue chunks"); int32 i, sizeof_read; uint32 action_flags; int16 count, player_index, num_flags; ActionQueue *queue; for (player_index = 0; player_index < dynamic_world->player_count; player_index++) { queue= get_player_recording_queue(player_index); for (count = 0; count < RECORD_CHUNK_SIZE; ) { if (replay.resource_data) { bool hit_end= false; if (replay.film_resource_offset >= replay.resource_data_size) { hit_end = true; } else { uint8* S; S = (uint8 *)(replay.resource_data + replay.film_resource_offset); StreamToValue(S,num_flags); replay.film_resource_offset += sizeof(num_flags); S = (uint8 *)(replay.resource_data + replay.film_resource_offset); StreamToValue(S,action_flags); replay.film_resource_offset+= sizeof(action_flags); } if (hit_end || num_flags == END_OF_RECORDING_INDICATOR) { replay.have_read_last_chunk= true; break; } } else { sizeof_read = sizeof(num_flags); uint8 NumFlagsBuffer[sizeof(num_flags)]; bool HitEOF = false; if (vblFSRead(FilmFile, &sizeof_read, NumFlagsBuffer, HitEOF)) { uint8 *S = NumFlagsBuffer; StreamToValue(S,num_flags); sizeof_read = sizeof(action_flags); uint8 ActionFlagsBuffer[sizeof(action_flags)]; bool status = vblFSRead(FilmFile, &sizeof_read, ActionFlagsBuffer, HitEOF); S = ActionFlagsBuffer; StreamToValue(S,action_flags); assert(status || (HitEOF && sizeof_read == sizeof(action_flags))); } if ((HitEOF && sizeof_read != sizeof(action_flags)) || num_flags == END_OF_RECORDING_INDICATOR) { replay.have_read_last_chunk = true; break; } } if (!(replay.have_read_last_chunk || num_flags)) { logAnomaly("chunk contains no flags"); } count += num_flags; for (i = 0; i < num_flags; i++) { *(queue->buffer + queue->write_index) = action_flags; INCREMENT_QUEUE_COUNTER(queue->write_index); assert(queue->read_index != queue->write_index); } } assert(replay.have_read_last_chunk || count == RECORD_CHUNK_SIZE); } }
// For reading the face-data chunk static bool ReadFaceData(OpenedFile& OFile, int32 ParentChunkEnd) { uint8 NFBuffer[2]; uint16 NumFaces; if (!OFile.Read(2,NFBuffer)) { if (DBOut) fprintf(DBOut,"ERROR reading number of faces\n"); return false; } uint8 *S = NFBuffer; StreamToValue(S,NumFaces); int32 DataSize = 4*sizeof(uint16)*int(NumFaces); SetChunkBufferSize(DataSize); if (!OFile.Read(DataSize,ChunkBufferBase())) { if (DBOut) fprintf(DBOut,"ERROR reading face-chunk contents\n"); return false; } S = ChunkBufferBase(); ModelPtr->VertIndices.resize(3*NumFaces); for (int k=0; k<NumFaces; k++) { uint16 *CurrPoly = ModelPtr->VIBase() + 3*k; uint16 Flags; StreamToList(S,CurrPoly,3); StreamToValue(S,Flags); } int32 Location = 0; OFile.GetPosition(Location); while(Location < ParentChunkEnd) { ChunkHeaderData ChunkHeader; if (!ReadChunkHeader(OFile,ChunkHeader)) return false; switch(ChunkHeader.ID) { /* case OBJECT: if (!ReadContainer(OFile,ChunkHeader,ReadObject)) return false; break; */ default: if (!SkipChunk(OFile,ChunkHeader)) return false; } // Where are we now? OFile.GetPosition(Location); } if (Location > ParentChunkEnd) { if (DBOut) fprintf(DBOut,"ERROR: Overran parent chunk: %ld > %ld\n",Location,ParentChunkEnd); return false; } return true; }