From 31bfe3db7867197eb367ecfec109f835b075c2f1 Mon Sep 17 00:00:00 2001 From: dreamstalker Date: Thu, 21 May 2015 21:20:40 +0400 Subject: [PATCH] Moved optimized MSG_Write*Bits* under REHLDS_FIXES defined because it uses bf_write_s structure incompatible with the original engine Fixed wrong tex.coords formula in SurfaceAtPoint() Added missing calls to SV_CheckWaterTransition() in SV_Physics_Toss() Flight recorder: Lazy init with HOOK_ENGINE RehldsDemoPlayer: print heartbeat message every 10Mb of demo --- rehlds/engine/common.cpp | 27 ++++++++++++++------------- rehlds/engine/pr_cmds.cpp | 4 ++-- rehlds/engine/sv_phys.cpp | 6 +++++- rehlds/hookers/rehlds_debug.cpp | 5 +++++ rehlds/hookers/rehlds_debug.h | 1 + rehlds/msvc/ReHLDS.vcxproj | 4 ++-- rehlds/rehlds/flight_recorder.cpp | 10 ++++++++++ rehlds/testsuite/player.cpp | 14 +++++++++++++- rehlds/testsuite/player.h | 4 ++++ 9 files changed, 56 insertions(+), 19 deletions(-) diff --git a/rehlds/engine/common.cpp b/rehlds/engine/common.cpp index 94b7c3a..d5f9989 100644 --- a/rehlds/engine/common.cpp +++ b/rehlds/engine/common.cpp @@ -457,7 +457,7 @@ typedef struct bf_write_s { //For enhanced and safe bits writing functions -#if defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#if defined(REHLDS_FIXES) #pragma pack(push, 1) union { @@ -471,13 +471,13 @@ typedef struct bf_write_s int nCurOutputBit; sizebuf_t *pbuf; -#else //defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#else //defined(REHLDS_FIXES) int nCurOutputBit; unsigned char *pOutByte; sizebuf_t *pbuf; -#endif //defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#endif //defined(REHLDS_FIXES) } bf_write_t; typedef struct bf_read_s @@ -502,7 +502,7 @@ void COM_BitOpsInit(void) } //Enhanced and safe bits writing functions -#if defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#if defined(REHLDS_FIXES) void MSG_WBits_MaybeFlush() { if (bfwrite.nCurOutputBit < 32) @@ -561,7 +561,7 @@ void MSG_EndBitWriting(sizebuf_t *buf) } -#else //defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#else // defined(REHLDS_FIXES) void MSG_WriteOneBit(int nValue) { @@ -594,13 +594,6 @@ void MSG_StartBitWriting(sizebuf_t *buf) bfwrite.pOutByte = &buf->data[buf->cursize]; } -NOXREF qboolean MSG_IsBitWriting(void) -{ - NOXREFCHECK; - - return bfwrite.pbuf != 0; -} - void MSG_EndBitWriting(sizebuf_t *buf) { if (!(bfwrite.pbuf->flags & SIZEBUF_OVERFLOWED)) @@ -660,7 +653,14 @@ void MSG_WriteBits(uint32 data, int numbits) } } -#endif //defined(REHLDS_OPT_PEDANTIC) || defined(REHLDS_FIXES) +#endif //defined(REHLDS_FIXES) + +NOXREF qboolean MSG_IsBitWriting(void) +{ + NOXREFCHECK; + + return bfwrite.pbuf != 0; +} void MSG_WriteSBits(int data, int numbits) { @@ -1291,6 +1291,7 @@ void *SZ_GetSpace(sizebuf_t *buf, int length) void *data; const char *buffername = buf->buffername ? buf->buffername : "???"; + if (length < 0) { Sys_Error(__FUNCTION__ ": %i negative length on %s", length, buffername); diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp index 452dcf3..b5ec3b8 100644 --- a/rehlds/engine/pr_cmds.cpp +++ b/rehlds/engine/pr_cmds.cpp @@ -488,8 +488,8 @@ msurface_t *SurfaceAtPoint(model_t *pModel, mnode_t *node, vec_t *start, vec_t * { surf = &pModel->surfaces[node->firstsurface + i]; tex = surf->texinfo; - ds = (int)_DotProduct(mid, tex->vecs[0]); - dt = (int)_DotProduct(mid, tex->vecs[1]); + ds = (int)(_DotProduct(mid, tex->vecs[0]) + tex->vecs[0][3]); + dt = (int)(_DotProduct(mid, tex->vecs[1]) + tex->vecs[1][3]); if (ds >= surf->texturemins[0]) { if (dt >= surf->texturemins[1]) diff --git a/rehlds/engine/sv_phys.cpp b/rehlds/engine/sv_phys.cpp index e9bd903..5bc525b 100644 --- a/rehlds/engine/sv_phys.cpp +++ b/rehlds/engine/sv_phys.cpp @@ -1097,8 +1097,11 @@ void SV_Physics_Toss(edict_t *ent) } ClipVelocity(ent->v.velocity, trace.plane.normal, ent->v.velocity, backoff); - if (trace.plane.normal[2] <= 0.7f) + if (trace.plane.normal[2] <= 0.7) + { + SV_CheckWaterTransition(ent); return; + } move[0] = ent->v.basevelocity[0] + ent->v.velocity[0]; move[1] = ent->v.basevelocity[1] + ent->v.velocity[1]; @@ -1131,6 +1134,7 @@ void SV_Physics_Toss(edict_t *ent) ent->v.avelocity[0] = vec3_origin[0]; ent->v.avelocity[1] = vec3_origin[1]; ent->v.avelocity[2] = vec3_origin[2]; + SV_CheckWaterTransition(ent); } /* size: 3408000 */ /* ../engine/sv_phys.c:1668 */ diff --git a/rehlds/hookers/rehlds_debug.cpp b/rehlds/hookers/rehlds_debug.cpp index c67366e..1db7dfc 100644 --- a/rehlds/hookers/rehlds_debug.cpp +++ b/rehlds/hookers/rehlds_debug.cpp @@ -570,6 +570,11 @@ void Rehlds_Debug_LogDeltaFlags(delta_t* delta, int counter, bool verbose) { g_RehldsDebugLog.flush(); } +void Rehlds_Debug_LogSzAlloc(int counter, int cursize, int maxsize, int flags) { + g_RehldsDebugLog << "SZAlloc(c=" << counter << " sz=" << cursize << " maxsz= " << maxsize << " f=" << flags << ")\n"; + g_RehldsDebugLog.flush(); +} + void Rehlds_Debug_Init(Module* engine) { diff --git a/rehlds/hookers/rehlds_debug.h b/rehlds/hookers/rehlds_debug.h index b2b257d..7680dca 100644 --- a/rehlds/hookers/rehlds_debug.h +++ b/rehlds/hookers/rehlds_debug.h @@ -42,6 +42,7 @@ extern void Rehlds_Debug_logRealloc(size_t sz, void* oldPtr, void* newPtr); extern void Rehlds_Debug_logFree(void* ptr); extern void Rehlds_Debug_LogDeltaFlags(delta_t* delta, int counter, bool verbose); +extern void Rehlds_Debug_LogSzAlloc(int counter, int cursize, int maxsize, int flags); extern void Rehlds_Debug_Init(Module* engine); diff --git a/rehlds/msvc/ReHLDS.vcxproj b/rehlds/msvc/ReHLDS.vcxproj index 5f76cef..bb4d2e9 100644 --- a/rehlds/msvc/ReHLDS.vcxproj +++ b/rehlds/msvc/ReHLDS.vcxproj @@ -987,7 +987,7 @@ true true true - REHLDS_OPT_PEDANTIC;REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + REHLDS_SELF;HOOK_ENGINE;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded /arch:IA32 %(AdditionalOptions) Use @@ -1027,7 +1027,7 @@ true true true - REHLDS_FIXES;REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + REHLDS_OPT_PEDANTIC;REHLDS_SELF;REHLDS_CHECKS;USE_BREAKPAD_HANDLER;DEDICATED;SWDS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreaded /arch:IA32 %(AdditionalOptions) Use diff --git a/rehlds/rehlds/flight_recorder.cpp b/rehlds/rehlds/flight_recorder.cpp index ac7ee71..ceb936e 100644 --- a/rehlds/rehlds/flight_recorder.cpp +++ b/rehlds/rehlds/flight_recorder.cpp @@ -23,6 +23,12 @@ uint16 g_FRMsg_Frame; uint16 g_FRMsg_FreeEntPrivateData; uint16 g_FRMsg_AllocEntPrivateData; +void FR_CheckInit() { +#ifdef HOOK_ENGINE + if (!g_FlightRecorder) + FR_Init(); +#endif +} void FR_Init() { g_FlightRecorder = new CRehldsFlightRecorder(); @@ -33,23 +39,27 @@ void FR_Init() { } void FR_StartFrame() { + FR_CheckInit(); g_FlightRecorder->StartMessage(g_FRMsg_Frame, true); g_FlightRecorder->WriteDouble(realtime); g_FlightRecorder->EndMessage(g_FRMsg_Frame, true); } void FR_EndFrame() { + FR_CheckInit(); g_FlightRecorder->StartMessage(g_FRMsg_Frame, false); g_FlightRecorder->EndMessage(g_FRMsg_Frame, false); } void FR_AllocEntPrivateData(void* res) { + FR_CheckInit(); g_FlightRecorder->StartMessage(g_FRMsg_AllocEntPrivateData, true); g_FlightRecorder->WriteUInt32((size_t)res); g_FlightRecorder->EndMessage(g_FRMsg_AllocEntPrivateData, true); } void FR_FreeEntPrivateData(void* data) { + FR_CheckInit(); g_FlightRecorder->StartMessage(g_FRMsg_FreeEntPrivateData, true); g_FlightRecorder->WriteUInt32((size_t)data); g_FlightRecorder->EndMessage(g_FRMsg_FreeEntPrivateData, true); diff --git a/rehlds/testsuite/player.cpp b/rehlds/testsuite/player.cpp index 58a36a9..fc277b8 100644 --- a/rehlds/testsuite/player.cpp +++ b/rehlds/testsuite/player.cpp @@ -24,6 +24,9 @@ CPlayingEngExtInterceptor::CPlayingEngExtInterceptor(const char* fname, bool str m_GameServerWrapper = NULL; m_SteamBreakpadContext = NULL; + m_HeartBeatInterval = 10000000; + m_PrevHeartBeat = 0; + uint32 cmdlineLen = 0; char cmdLine[2048]; @@ -134,6 +137,8 @@ IEngExtCall* CPlayingEngExtInterceptor::getNextCallInternal(bool peek) { IEngExtCall* CPlayingEngExtInterceptor::getNextCall(bool peek, bool processCallbacks, ExtCallFuncs expectedOpcode, bool needStart, const char* callSource) { int size = (int)m_InStream.tellg(); + int sizeLeft = m_inStreamSize - size; + maybeHeartBeat(size); IEngExtCall* cmd = getNextCallInternal(peek); if (peek) { return cmd; @@ -158,7 +163,7 @@ IEngExtCall* CPlayingEngExtInterceptor::getNextCall(bool peek, bool processCallb } if (cmd->getOpcode() != expectedOpcode) { - rehlds_syserror("%s: bad opcode; expected %d got %d; size left: %d", __FUNCTION__, expectedOpcode, cmd->getOpcode(), m_inStreamSize - size); + rehlds_syserror("%s: bad opcode; expected %d got %d; size left: %d", __FUNCTION__, expectedOpcode, cmd->getOpcode(), sizeLeft); } if (needStart) { if (!cmd->m_Start) rehlds_syserror("%s: bad fcall %d; expected start flag", __FUNCTION__, cmd->getOpcode()); @@ -235,6 +240,13 @@ int CPlayingEngExtInterceptor::getOrRegisterSteamCallback(CCallbackBase* cb) { return id; } +void CPlayingEngExtInterceptor::maybeHeartBeat(int readPos) { + if (m_PrevHeartBeat + m_HeartBeatInterval <= readPos) { + m_PrevHeartBeat = readPos; + Con_Printf("%s: readPos=%u\n", __FUNCTION__, readPos); + } +} + uint32 CPlayingEngExtInterceptor::time(uint32* pTime) { CStdTimeCall* playCall = dynamic_cast(getNextCall(false, false, ECF_CSTD_TIME, true, __FUNCTION__)); diff --git a/rehlds/testsuite/player.h b/rehlds/testsuite/player.h index f99cbe9..90c527d 100644 --- a/rehlds/testsuite/player.h +++ b/rehlds/testsuite/player.h @@ -132,6 +132,8 @@ private: CSteamGameServerPlayingWrapper* m_GameServerWrapper; void* m_SteamBreakpadContext; + int m_HeartBeatInterval; + int m_PrevHeartBeat; hostent_data_t m_CurrentHostentData; struct hostent m_CurrentHostent; @@ -150,6 +152,8 @@ private: int getOrRegisterSteamCallback(CCallbackBase* cb); + void maybeHeartBeat(int readPos); + public: void* allocFuncCall(); void freeFuncCall(void* fcall);