void netcpy(network_audio_header_NET* dest, const network_audio_header* src) { uint8* S = dest->data; ValueToStream(S, src->mReserved); ValueToStream(S, src->mFlags); assert(S == dest->data + SIZEOF_network_audio_header); }
static void PlayerStartToStream(uint8* &S, player_start_data& Object) { ValueToStream(S,Object.team); ValueToStream(S,Object.identifier); ValueToStream(S,Object.color); BytesToStream(S,Object.name,MAXIMUM_PLAYER_START_NAME_LENGTH+2); }
void netcpy(NetPacketHeader_NET* dest, const NetPacketHeader* src) { uint8 *S = dest->data; ValueToStream(S,src->tag); ValueToStream(S,src->sequence); assert(S == dest->data + SIZEOF_NetPacketHeader); }
void netcpy(NetDistributionPacket_NET* dest, const NetDistributionPacket* src) { uint8 *S = dest->data; ValueToStream(S,src->distribution_type); ValueToStream(S,src->first_player_index); ValueToStream(S,src->data_size); assert(S == dest->data + SIZEOF_NetDistributionPacket); }
void netcpy(NetPacket_NET* dest, const NetPacket* src) { uint8 *S = dest->data; *(S++) = src->ring_packet_type; *(S++) = src->server_player_index; ValueToStream(S,src->server_net_time); ValueToStream(S,src->required_action_flags); for (int i=0; i<MAXIMUM_NUMBER_OF_NETWORK_PLAYERS; i++) ValueToStream(S,src->action_flag_count[i]); assert(S == dest->data + SIZEOF_NetPacket); }
uint8 *pack_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++) { ValueToStream(S,ObjPtr->length); ValueToStream(S,ObjPtr->num_players); ValueToStream(S,ObjPtr->level_number); ValueToStream(S,ObjPtr->map_checksum); ValueToStream(S,ObjPtr->version); for (size_t m = 0; m < MAXIMUM_NUMBER_OF_PLAYERS; m++) PlayerStartToStream(S,ObjPtr->starts[m]); GameDataToStream(S,ObjPtr->game_information); } assert(static_cast<size_t>(S - Stream) == (Count*SIZEOF_recording_header)); return S; }
static void GameDataToStream(uint8* &S, game_data& Object) { ValueToStream(S,Object.game_time_remaining); ValueToStream(S,Object.game_type); ValueToStream(S,Object.game_options); ValueToStream(S,Object.kill_limit); ValueToStream(S,Object.initial_random_seed); ValueToStream(S,Object.difficulty_level); ListToStream(S,Object.parameters,2); }
/********************************************************************************************* * * Function: save_recording_queue_chunk * Purpose: saves one chunk of the queue to the recording file, using run-length encoding. * *********************************************************************************************/ void save_recording_queue_chunk( short player_index) { uint8 *location; uint32 last_flag, count, flag = 0; int16 i, run_count, num_flags_saved, max_flags; static uint8 *buffer= NULL; ActionQueue *queue; // The data format is (run length (int16)) + (action flag (uint32)) int DataSize = sizeof(int16) + sizeof(uint32); if (buffer == NULL) buffer = new byte[RECORD_CHUNK_SIZE * DataSize]; location= buffer; count= 0; // keeps track of how many bytes we'll save. last_flag= (uint32)NONE; queue= get_player_recording_queue(player_index); // don't want to save too much stuff max_flags= MIN(RECORD_CHUNK_SIZE, get_recording_queue_size(player_index)); // save what's in the queue run_count= num_flags_saved= 0; for (i = 0; i<max_flags; i++) { flag = queue->buffer[queue->read_index]; INCREMENT_QUEUE_COUNTER(queue->read_index); if (i && flag != last_flag) { ValueToStream(location,run_count); ValueToStream(location,last_flag); count += DataSize; num_flags_saved += run_count; run_count = 1; } else { run_count++; } last_flag = flag; } // now save the final run ValueToStream(location,run_count); ValueToStream(location,last_flag); count += DataSize; num_flags_saved += run_count; if (max_flags<RECORD_CHUNK_SIZE) { short end_indicator = END_OF_RECORDING_INDICATOR; ValueToStream(location,end_indicator); int32 end_flag = 0; ValueToStream(location,end_flag); count += DataSize; num_flags_saved += RECORD_CHUNK_SIZE-max_flags; } FilmFile.Write(count,buffer); replay.header.length+= count; vwarn(num_flags_saved == RECORD_CHUNK_SIZE, csprintf(temporary, "bad recording: %d flags, max=%d, count = %u;dm #%p #%u", num_flags_saved, max_flags, count, buffer, count)); }