Changed netdata struct array to use std array

This commit is contained in:
Jordan Cristiano 2015-10-15 00:40:40 -04:00
parent a7a9776d2a
commit e3ccd21314
5 changed files with 49 additions and 47 deletions

View File

@ -14,7 +14,7 @@
PacketTrailingBits ParsePacket(uint8_t* packet, size_t length, PacketTrailingBits ParsePacket(uint8_t* packet, size_t length,
SourceGameContext& context, IDemoWriter* writer, SourceGameContext& context, IDemoWriter* writer,
void* netDataStructs[32]) const NetHandlers::NetDataStructArray& netDataStructs)
{ {
assert(length <= NET_MAX_PAYLOAD); assert(length <= NET_MAX_PAYLOAD);
bf_read bitbuf(packet, length); bf_read bitbuf(packet, length);
@ -42,7 +42,7 @@ PacketTrailingBits ParsePacket(uint8_t* packet, size_t length,
void DemoReader::ProcessDem(std::FILE* inputFp, IDemoWriter* writer) void DemoReader::ProcessDem(std::FILE* inputFp, IDemoWriter* writer)
{ {
void* netDataStructs[32]; NetHandlers::NetDataStructArray netDataStructs;
void* demDataStructs[9]; void* demDataStructs[9];
NetHandlers::CreateNetMsgStructs(netDataStructs); NetHandlers::CreateNetMsgStructs(netDataStructs);
DemHandlers::CreateDemMsgStructs(demDataStructs); DemHandlers::CreateDemMsgStructs(demDataStructs);

View File

@ -25,7 +25,7 @@ int32_t ReadNetpacket(base::JsonReaderFile& jsonReader, PacketTrailingBits& trai
PacketTrailingBits ParsePacket(base::JsonReaderFile& jsonReader, PacketTrailingBits ParsePacket(base::JsonReaderFile& jsonReader,
SourceGameContext& context, IDemoWriter* writer, SourceGameContext& context, IDemoWriter* writer,
void* netDataStructs[32]) const NetHandlers::NetDataStructArray& netDataStructs)
{ {
PacketTrailingBits trailingBits = PacketTrailingBits(); PacketTrailingBits trailingBits = PacketTrailingBits();
NetPacket netPacket = NetPacket(); NetPacket netPacket = NetPacket();
@ -40,7 +40,7 @@ PacketTrailingBits ParsePacket(base::JsonReaderFile& jsonReader,
void DemoReader::ProcessJson(std::FILE* inputFp, IDemoWriter* writer) void DemoReader::ProcessJson(std::FILE* inputFp, IDemoWriter* writer)
{ {
void* netDataStructs[32]; NetHandlers::NetDataStructArray netDataStructs;
void* demDataStructs[9]; void* demDataStructs[9];
NetHandlers::CreateNetMsgStructs(netDataStructs); NetHandlers::CreateNetMsgStructs(netDataStructs);
DemHandlers::CreateDemMsgStructs(demDataStructs); DemHandlers::CreateDemMsgStructs(demDataStructs);

View File

@ -2,8 +2,46 @@
#include "nethandlers.h" #include "nethandlers.h"
#include "netmessages.h" #include "netmessages.h"
#include <cassert> #include <cassert>
#include <cstdint>
void NetHandlers::CreateNetMsgStructs(void* netDataStructs[32]) #if !defined( MAX_OSPATH )
#define MAX_OSPATH 260 // max length of a filesystem pathname
#endif
#include "net_nop.h"
#include "net_disconnect.h"
#include "net_file.h"
#include "net_tick.h"
#include "net_stringcmd.h"
#include "net_setconvar.h"
#include "net_signonstate.h"
#include "svc_print.h"
#include "svc_serverinfo.h"
#include "svc_sendtable.h"
#include "svc_classinfo.h"
#include "svc_setpause.h"
#include "svc_createstringtable.h"
#include "svc_updatestringtable.h"
#include "svc_voiceinit.h"
#include "svc_voicedata.h"
#include "svc_hltv.h"
#include "svc_sounds.h"
#include "svc_setview.h"
#include "svc_fixangle.h"
#include "svc_crosshairangle.h"
#include "svc_bspdecal.h"
#include "svc_terrainmod.h"
#include "svc_usermessage.h"
#include "svc_entitymessage.h"
#include "svc_gameevent.h"
#include "svc_packetentities.h"
#include "svc_tempentities.h"
#include "svc_prefetch.h"
#include "svc_menu.h"
#include "svc_gameeventlist.h"
#include "svc_getcvarvalue.h"
void NetHandlers::CreateNetMsgStructs(NetDataStructArray& netDataStructs)
{ {
netDataStructs[0] = new NetMsg::Net_NOP(); netDataStructs[0] = new NetMsg::Net_NOP();
netDataStructs[1] = new NetMsg::Net_Disconnect(); netDataStructs[1] = new NetMsg::Net_Disconnect();
@ -39,7 +77,7 @@ void NetHandlers::CreateNetMsgStructs(void* netDataStructs[32])
netDataStructs[31] = new NetMsg::SVC_GetCvarValue(); netDataStructs[31] = new NetMsg::SVC_GetCvarValue();
} }
void NetHandlers::DestroyNetMsgStructs(void* netDataStructs[32]) void NetHandlers::DestroyNetMsgStructs(NetDataStructArray& netDataStructs)
{ {
delete reinterpret_cast<NetMsg::Net_NOP*>(netDataStructs[0]); delete reinterpret_cast<NetMsg::Net_NOP*>(netDataStructs[0]);
delete reinterpret_cast<NetMsg::Net_Disconnect*>(netDataStructs[1]); delete reinterpret_cast<NetMsg::Net_Disconnect*>(netDataStructs[1]);

View File

@ -3,6 +3,8 @@
#include <cstdint> #include <cstdint>
#include <sstream> #include <sstream>
#include <array>
#include "netmessages.h"
namespace base namespace base
{ {
@ -64,8 +66,9 @@ struct SourceGameContext
namespace NetHandlers namespace NetHandlers
{ {
void CreateNetMsgStructs(void* netDataStructs[32]); using NetDataStructArray = std::array<void*, NetMsg::SVC_LASTMSG + 1>;
void DestroyNetMsgStructs(void* netDataStructs[32]); void CreateNetMsgStructs(NetDataStructArray& netDataStructs);
void DestroyNetMsgStructs(NetDataStructArray& netDataStructs);
bool NetMsg_BitRead(uint32_t type, BitRead& bitbuf, SourceGameContext& context, void* data); bool NetMsg_BitRead(uint32_t type, BitRead& bitbuf, SourceGameContext& context, void* data);
bool NetMsg_BitWrite(uint32_t type, BitWrite& bitbuf, const SourceGameContext& context, void* data); bool NetMsg_BitWrite(uint32_t type, BitWrite& bitbuf, const SourceGameContext& context, void* data);

View File

@ -1,45 +1,6 @@
#pragma once #pragma once
#include <cstdint>
#if !defined( MAX_OSPATH )
#define MAX_OSPATH 260 // max length of a filesystem pathname
#endif
#include "net_nop.h"
#include "net_disconnect.h"
#include "net_file.h"
#include "net_tick.h"
#include "net_stringcmd.h"
#include "net_setconvar.h"
#include "net_signonstate.h"
#include "svc_print.h"
#include "svc_serverinfo.h"
#include "svc_sendtable.h"
#include "svc_classinfo.h"
#include "svc_setpause.h"
#include "svc_createstringtable.h"
#include "svc_updatestringtable.h"
#include "svc_voiceinit.h"
#include "svc_voicedata.h"
#include "svc_hltv.h"
#include "svc_sounds.h"
#include "svc_setview.h"
#include "svc_fixangle.h"
#include "svc_crosshairangle.h"
#include "svc_bspdecal.h"
#include "svc_terrainmod.h"
#include "svc_usermessage.h"
#include "svc_entitymessage.h"
#include "svc_gameevent.h"
#include "svc_packetentities.h"
#include "svc_tempentities.h"
#include "svc_prefetch.h"
#include "svc_menu.h"
#include "svc_gameeventlist.h"
#include "svc_getcvarvalue.h"
namespace NetMsg namespace NetMsg
{ {
enum enum