From 4a774865ba25f20b4cdfae7ec207a8f3e8ece147 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 28 Jan 2016 05:50:27 +0600 Subject: [PATCH] Refactoring Added remaining functions of pm_math/pm_debug --- regamedll/dlls/bot/cs_bot_manager.cpp | 2 +- regamedll/dlls/bot/cs_bot_manager.h | 4 +- regamedll/dlls/multiplay_gamerules.cpp | 122 ++---------- regamedll/hookers/6153_hooker.cpp | 44 ++--- regamedll/pm_shared/pm_debug.cpp | 261 ++++++++++++++++++++----- regamedll/pm_shared/pm_debug.h | 12 +- regamedll/pm_shared/pm_math.cpp | 231 +++++++++++++++++----- regamedll/pm_shared/pm_math.h | 28 +-- 8 files changed, 452 insertions(+), 252 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index 5297e02b..ce9e5bfb 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -59,7 +59,7 @@ CCSBotManager::CCSBotManager(void) m_bServerActive = false; - TheBotPhrases = new BotPhraseManager; // TODO: Reverse me! + TheBotPhrases = new BotPhraseManager; // load the database of bot radio chatter TheBotPhrases->Initialize("BotChatter.db", 0); diff --git a/regamedll/dlls/bot/cs_bot_manager.h b/regamedll/dlls/bot/cs_bot_manager.h index 1d05a6e9..11cd9f4f 100644 --- a/regamedll/dlls/bot/cs_bot_manager.h +++ b/regamedll/dlls/bot/cs_bot_manager.h @@ -220,11 +220,11 @@ public: void SetNavPlace(unsigned int place) { m_navPlace = place; } enum SkillType { LOW, AVERAGE, HIGH, RANDOM }; - NOXREF NOBODY const char *GetRandomBotName(SkillType skill); + NOXREF const char *GetRandomBotName(SkillType skill); static void MonitorBotCVars(void); static void MaintainBotQuota(void); - NOBODY static bool AddBot(const BotProfile *profile, BotProfileTeamType team); + static bool AddBot(const BotProfile *profile, BotProfileTeamType team); #define FROM_CONSOLE true static bool BotAddCommand(BotProfileTeamType team, bool isFromConsole = false); // process the "bot_add" console command diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index ccae3b49..d8e82341 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -342,24 +342,11 @@ void EndRoundMessage(const char *sentence, int event) { if (teamTriggered) { - UTIL_LogPrintf - ( - "Team \"%s\" triggered \"%s\" (CT \"%i\") (T \"%i\")\n", - team, - message, - mp->m_iNumCTWins, - mp->m_iNumTerroristWins - ); + UTIL_LogPrintf("Team \"%s\" triggered \"%s\" (CT \"%i\") (T \"%i\")\n", team, message, mp->m_iNumCTWins, mp->m_iNumTerroristWins); } else { - UTIL_LogPrintf - ( - "World triggered \"%s\" (CT \"%i\") (T \"%i\")\n", - message, - mp->m_iNumCTWins, - mp->m_iNumTerroristWins - ); + UTIL_LogPrintf("World triggered \"%s\" (CT \"%i\") (T \"%i\")\n", message, mp->m_iNumCTWins, mp->m_iNumTerroristWins); } } @@ -437,7 +424,6 @@ void ReadMultiplayCvars(CHalfLifeMultiplay *mp) /* <11492c> ../cstrike/dlls/multiplay_gamerules.cpp:479 */ CHalfLifeMultiplay::CHalfLifeMultiplay(void) { - UNTESTED m_VoiceGameMgr.Init(&g_GameMgrHelper, gpGlobals->maxClients); RefreshSkillData(); @@ -512,7 +498,7 @@ CHalfLifeMultiplay::CHalfLifeMultiplay(void) m_bMapHasRescueZone = false; m_iStoredSpectValue = (int)allow_spectators.value; - for (int j = 0; j < MAX_VIP_QUEUES; j++) + for (int j = 0; j < MAX_VIP_QUEUES; ++j) { VIPQueue[j] = NULL; } @@ -860,14 +846,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(GiveC4)(void) player->HintMessage("#Hint_you_have_the_bomb", FALSE, TRUE); // Log this information - UTIL_LogPrintf - ( - "\"%s<%i><%s>\" triggered \"Spawned_With_The_Bomb\"\n", - STRING(player->pev->netname), - GETPLAYERUSERID(player->edict()), - GETPLAYERAUTHID(player->edict()) - ); - + UTIL_LogPrintf("\"%s<%i><%s>\" triggered \"Spawned_With_The_Bomb\"\n", STRING(player->pev->netname), GETPLAYERUSERID(player->edict()), GETPLAYERAUTHID(player->edict())); m_bBombDropped = FALSE; } } @@ -903,14 +882,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(GiveC4)(void) player->HintMessage("#Hint_you_have_the_bomb", FALSE, TRUE); // Log this information - UTIL_LogPrintf - ( - "\"%s<%i><%s>\" triggered \"Spawned_With_The_Bomb\"\n", - STRING(player->pev->netname), - GETPLAYERUSERID(player->edict()), - GETPLAYERAUTHID(player->edict()) - ); - + UTIL_LogPrintf("\"%s<%i><%s>\" triggered \"Spawned_With_The_Bomb\"\n", STRING(player->pev->netname), GETPLAYERUSERID(player->edict()), GETPLAYERAUTHID(player->edict())); m_bBombDropped = FALSE; return; } @@ -2546,9 +2518,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(Think)(void) pPlayer->m_iHideHUD |= HIDEHUD_ALL; m_fTeamCount = gpGlobals->time + 100000.0; - UTIL_LogPrintf("Career Round %d %d %d %d\n", m_iRoundWinStatus, m_iNumCTWins, - m_iNumTerroristWins, TheCareerTasks->AreAllTasksComplete()); - + UTIL_LogPrintf("Career Round %d %d %d %d\n", m_iRoundWinStatus, m_iNumCTWins, m_iNumTerroristWins, TheCareerTasks->AreAllTasksComplete()); break; } } @@ -2624,7 +2594,6 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(Think)(void) MESSAGE_END(); UTIL_LogPrintf("Career Match %d %d %d %d\n", m_iRoundWinStatus, m_iNumCTWins, m_iNumTerroristWins, TheCareerTasks->AreAllTasksComplete()); - SERVER_COMMAND("setpause\n"); } } @@ -2959,19 +2928,8 @@ void CHalfLifeMultiplay::CheckRestartRound(void) // log the restart UTIL_LogPrintf("World triggered \"Restart_Round_(%i_%s)\"\n", iRestartDelay, (iRestartDelay == 1) ? "second" : "seconds"); - UTIL_LogPrintf - ( - "Team \"CT\" scored \"%i\" with \"%i\" players\n", - m_iNumCTWins, - m_iNumCT - ); - - UTIL_LogPrintf - ( - "Team \"TERRORIST\" scored \"%i\" with \"%i\" players\n", - m_iNumTerroristWins, - m_iNumTerrorist - ); + UTIL_LogPrintf("Team \"CT\" scored \"%i\" with \"%i\" players\n", m_iNumCTWins, m_iNumCT); + UTIL_LogPrintf("Team \"TERRORIST\" scored \"%i\" with \"%i\" players\n", m_iNumTerroristWins, m_iNumTerrorist); // let the players know UTIL_ClientPrintAll(HUD_PRINTCENTER, "#Game_will_restart_in", UTIL_dtos1(iRestartDelay), (iRestartDelay == 1) ? "SECOND" : "SECONDS"); @@ -3211,13 +3169,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(InitHUD)(CBasePlayer *pl) int i; // notify other clients of player joining the game - UTIL_LogPrintf - ( - "\"%s<%i><%s><>\" entered the game\n", - STRING(pl->pev->netname), - GETPLAYERUSERID(pl->edict()), - GETPLAYERAUTHID(pl->edict()) - ); + UTIL_LogPrintf("\"%s<%i><%s><>\" entered the game\n", STRING(pl->pev->netname), GETPLAYERUSERID(pl->edict()), GETPLAYERAUTHID(pl->edict())); UpdateGameMode(pl); @@ -3417,14 +3369,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(ClientDisconnected)(edict_t *pClient) char *team = GetTeam(pPlayer->m_iTeam); FireTargets("game_playerleave", pPlayer, pPlayer, USE_TOGGLE, 0); - UTIL_LogPrintf - ( - "\"%s<%i><%s><%s>\" disconnected\n", - STRING(pPlayer->pev->netname), - GETPLAYERUSERID(pPlayer->edict()), - GETPLAYERAUTHID(pPlayer->edict()), - team - ); + UTIL_LogPrintf("\"%s<%i><%s><%s>\" disconnected\n", STRING(pPlayer->pev->netname), GETPLAYERUSERID(pPlayer->edict()), GETPLAYERAUTHID(pPlayer->edict()), team); // destroy all of the players weapons and items pPlayer->RemoveAllItems(TRUE); @@ -3740,13 +3685,7 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(PlayerKilled)(CBasePlayer *pVictim, entvar WRITE_LONG(DRC_FLAG_PRIO_MASK | DRC_FLAG_DRAMATIC | DRC_FLAG_FINAL); MESSAGE_END(); - UTIL_LogPrintf - ( - "\"%s<%i><%s>\" triggered \"Assassinated_The_VIP\"\n", - STRING(killer->pev->netname), - GETPLAYERUSERID(killer->edict()), - GETPLAYERAUTHID(killer->edict()) - ); + UTIL_LogPrintf("\"%s<%i><%s>\" triggered \"Assassinated_The_VIP\"\n", STRING(killer->pev->netname), GETPLAYERUSERID(killer->edict()), GETPLAYERAUTHID(killer->edict())); } else killer->AddAccount(REWARD_KILLED_ENEMY); @@ -3874,16 +3813,8 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(DeathNotice)(CBasePlayer *pVictim, entvars { // killed self char *team = GetTeam(pVictim->m_iTeam); - - UTIL_LogPrintf - ( - "\"%s<%i><%s><%s>\" committed suicide with \"%s\"\n", - STRING(pVictim->pev->netname), - GETPLAYERUSERID(pVictim->edict()), - GETPLAYERAUTHID(pVictim->edict()), - team, - killer_weapon_name - ); + UTIL_LogPrintf("\"%s<%i><%s><%s>\" committed suicide with \"%s\"\n", STRING(pVictim->pev->netname), GETPLAYERUSERID(pVictim->edict()), + GETPLAYERAUTHID(pVictim->edict()), team, killer_weapon_name); } else if (pKiller->flags & FL_CLIENT) { @@ -3892,34 +3823,15 @@ void CHalfLifeMultiplay::__MAKE_VHOOK(DeathNotice)(CBasePlayer *pVictim, entvars char *VictimTeam = GetTeam(pVictim->m_iTeam); char *KillerTeam = GetTeam(pPlayer->m_iTeam); - UTIL_LogPrintf - ( - "\"%s<%i><%s><%s>\" killed \"%s<%i><%s><%s>\" with \"%s\"\n", - STRING(pKiller->netname), - GETPLAYERUSERID(ENT(pKiller)), - GETPLAYERAUTHID(ENT(pKiller)), - KillerTeam, - STRING(pVictim->pev->netname), - GETPLAYERUSERID(pVictim->edict()), - GETPLAYERAUTHID(pVictim->edict()), - VictimTeam, - killer_weapon_name - ); + UTIL_LogPrintf("\"%s<%i><%s><%s>\" killed \"%s<%i><%s><%s>\" with \"%s\"\n", STRING(pKiller->netname), GETPLAYERUSERID(ENT(pKiller)), GETPLAYERAUTHID(ENT(pKiller)), + KillerTeam, STRING(pVictim->pev->netname), GETPLAYERUSERID(pVictim->edict()), GETPLAYERAUTHID(pVictim->edict()), VictimTeam, killer_weapon_name); } else { // killed by the world char *team = GetTeam(pVictim->m_iTeam); - - UTIL_LogPrintf - ( - "\"%s<%i><%s><%s>\" committed suicide with \"%s\" (world)\n", - STRING(pVictim->pev->netname), - GETPLAYERUSERID(pVictim->edict()), - GETPLAYERAUTHID(pVictim->edict()), - team, - killer_weapon_name - ); + UTIL_LogPrintf("\"%s<%i><%s><%s>\" committed suicide with \"%s\" (world)\n", STRING(pVictim->pev->netname), GETPLAYERUSERID(pVictim->edict()), + GETPLAYERAUTHID(pVictim->edict()), team, killer_weapon_name); } CheckWinConditions(); diff --git a/regamedll/hookers/6153_hooker.cpp b/regamedll/hookers/6153_hooker.cpp index d00c9d73..84afba3e 100644 --- a/regamedll/hookers/6153_hooker.cpp +++ b/regamedll/hookers/6153_hooker.cpp @@ -140,12 +140,12 @@ FunctionHook g_FunctionHooks[] = { 0x01DB6710, "PM_Init", (size_t)&PM_Init }, { 0x01DB1020, "PM_FindTextureType", (size_t)&PM_FindTextureType }, //pm_debug - //{ 0x0, "PM_ShowClipBox", (size_t)&PM_ShowClipBox }, - //{ 0x0, "PM_ParticleLine", (size_t)&PM_ParticleLine }, - //{ 0x0, "PM_DrawRectangle", (size_t)&PM_DrawRectangle }, - //{ 0x0, "PM_DrawPhysEntBBox", (size_t)&PM_DrawPhysEntBBox }, - //{ 0x0, "PM_DrawBBox", (size_t)&PM_DrawBBox }, - //{ 0x0, "PM_ViewEntity", (size_t)&PM_ViewEntity }, + //{ 0x01DAEEE0, "PM_ShowClipBox", (size_t)&PM_ShowClipBox }, // NOXREF + //{ 0x01DAEEF0, "PM_ParticleLine", (size_t)&PM_ParticleLine }, // NOXREF + //{ 0x01DAEFC0, "PM_DrawRectangle", (size_t)&PM_DrawRectangle }, // NOXREF + //{ 0x01DAF290, "PM_DrawPhysEntBBox", (size_t)&PM_DrawPhysEntBBox }, // NOXREF + //{ 0x01DAFB50, "PM_DrawBBox", (size_t)&PM_DrawBBox }, // NOXREF + //{ 0x01DAFF20, "PM_ViewEntity", (size_t)&PM_ViewEntity }, // NOXREF //pm_shared //{ 0x01DB0AB0, "PM_SwapTextures", (size_t)&PM_SwapTextures }, // NOXREF //{ 0x01DB0B30, "PM_IsThereGrassTexture", (size_t)&PM_IsThereGrassTexture }, // NOXREF @@ -203,28 +203,28 @@ FunctionHook g_FunctionHooks[] = //pm_math //{ 0x0, "anglemod", (size_t)&anglemod }, { 0x01DB0000, "AngleVectors", (size_t)&AngleVectors }, - //{ 0x0, "AngleVectorsTranspose", (size_t)&AngleVectorsTranspose }, + //{ 0x01DB0100, "AngleVectorsTranspose", (size_t)&AngleVectorsTranspose }, // NOXREF { 0x01DB0200, "AngleMatrix", (size_t)&AngleMatrix }, - //{ 0x0, "AngleIMatrix", (size_t)&AngleIMatrix }, - //{ 0x0, "NormalizeAngles", (size_t)&NormalizeAngles }, - //{ 0x0, "InterpolateAngles", (size_t)&InterpolateAngles }, - //{ 0x0, "AngleBetweenVectors", (size_t)&AngleBetweenVectors }, - //{ 0x0, "VectorTransform", (size_t)&VectorTransform }, + //{ 0x01DB02D0, "AngleIMatrix", (size_t)&AngleIMatrix }, // NOXREF + //{ 0x01DB03A0, "NormalizeAngles", (size_t)&NormalizeAngles }, // NOXREF + //{ 0x01DB03F0, "InterpolateAngles", (size_t)&InterpolateAngles }, // NOXREF + //{ 0x01DB0510, "AngleBetweenVectors", (size_t)&AngleBetweenVectors }, // NOXREF + //{ 0x01DB05B0, "VectorTransform", (size_t)&VectorTransform }, // NOXREF { 0x01DB0610, "VectorCompare", (size_t)&VectorCompare }, { 0x01DB0640, "VectorMA", (size_t)&VectorMA }, - //{ 0x01DB0680, "_DotProduct", (size_t)&_DotProduct }, // NOXREF - //{ 0x01DB06A0, "_VectorSubtract", (size_t)&_VectorSubtract }, // NOXREF - //{ 0x01DB06D0, "_VectorAdd", (size_t)&_VectorAdd }, // NOXREF - //{ 0x01DB0700, "_VectorCopy", (size_t)&_VectorCopy }, // NOXREF - //{ 0x01DB0720, "CrossProduct", (size_t)&_CrossProduct }, // NOXREF + //{ 0x01DB0680, "_DotProduct", (size_t)&_DotProduct }, // NOXREF + //{ 0x01DB06A0, "_VectorSubtract", (size_t)&_VectorSubtract }, // NOXREF + //{ 0x01DB06D0, "_VectorAdd", (size_t)&_VectorAdd }, // NOXREF + //{ 0x01DB0700, "_VectorCopy", (size_t)&_VectorCopy }, // NOXREF + //{ 0x01DB0720, "CrossProduct", (size_t)&_CrossProduct }, // NOXREF { 0x01DB0760, "Length", (size_t)&Length }, - //{ 0x0, "Distance", (size_t)&Distance }, + //{ 0x01DB0780, "Distance", (size_t)&Distance }, // NOXREF { 0x01DB07D0, "VectorNormalize", (size_t)&VectorNormalize }, - //{ 0x0, "VectorInverse", (size_t)&VectorInverse }, + //{ 0x01DB0820, "VectorInverse", (size_t)&VectorInverse }, { 0x01DB0840, "VectorScale", (size_t)&VectorScale }, - //{ 0x0, "Q_log2", (size_t)&Q_log2 }, - //{ 0x0, "VectorMatrix", (size_t)&VectorMatrix }, - //{ 0x0, "VectorAngles", (size_t)&VectorAngles }, + //{ 0x01DB0870, "Q_log2", (size_t)&Q_log2 }, + //{ 0x01DB0880, "VectorMatrix", (size_t)&VectorMatrix }, + //{ 0x01DB09D0, "VectorAngles", (size_t)&VectorAngles }, #endif // PM_Shared_Region diff --git a/regamedll/pm_shared/pm_debug.cpp b/regamedll/pm_shared/pm_debug.cpp index 68cc581a..e4aede47 100644 --- a/regamedll/pm_shared/pm_debug.cpp +++ b/regamedll/pm_shared/pm_debug.cpp @@ -1,5 +1,10 @@ #include "precompiled.h" +#undef vec3_t + +// Expand debugging BBOX particle hulls by this many units. +#define BOX_GAP 0.0f + static int PM_boxpnt[6][4] = { { 0, 4, 6, 2 }, // +X @@ -11,73 +16,233 @@ static int PM_boxpnt[6][4] = }; /* <2d0110> ../cstrike/pm_shared/pm_debug.c:43 */ -NOBODY void PM_ShowClipBox(void) +void PM_ShowClipBox(void) { +#ifdef _DEBUG + if (!pmove->runfuncs) + return; + + // More debugging, draw the particle bbox for player and for the entity we are looking directly at. + // aslo prints entity info to the console overlay. + if (!pmove->server) + return; + + // Draw entity in center of view + // Also draws the normal to the clip plane that intersects our movement ray. Leaves a particle + // trail at the intersection point. + PM_ViewEntity(); + + // Show our BBOX in particles. + //PM_DrawBBox(pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], pmove->origin, 132, 0.1); +/* + { + int i; + for (i = 0; i < pmove->numphysent; i++) + { + if (pmove->physents[ i ].info >= 1 && pmove->physents[ i ].info <= 4) + { + PM_DrawBBox(pmove->player_mins[pmove->usehull], pmove->player_maxs[pmove->usehull], pmove->physents[i].origin, 132, 0.1); + } + } + } +*/ +#endif // _DEBUG } /* <2d0012> ../cstrike/pm_shared/pm_debug.c:82 */ -NOBODY void PM_ParticleLine(vec3_t start, vec3_t end, int pcolor, float life, float vert) +void PM_ParticleLine(vec3_t start, vec3_t end, int pcolor, float life, float vert) { -// float linestep; // 84 -// float curdist; // 85 -// float len; // 86 -// vec3_t curpos; // 87 -// vec3_t diff; // 88 -// int i; // 89 + float linestep = 2.0f; + float curdist; + float len; + vec3_t curpos; + vec3_t diff; + int i; + // Determine distance; + + VectorSubtract(end, start, diff); + + len = VectorNormalize(diff); + + curdist = 0; + while (curdist <= len) + { + for (i = 0; i < 3; ++i) + curpos[i] = start[i] + curdist * diff[i]; + + pmove->PM_Particle(curpos, pcolor, life, 0, vert); + curdist += linestep; + } } /* <2d0197> ../cstrike/pm_shared/pm_debug.c:114 */ -NOBODY void PM_DrawRectangle(vec3_t tl, vec3_t bl, vec3_t tr, vec3_t br, int pcolor, float life) +void PM_DrawRectangle(vec3_t tl, vec3_t bl, vec3_t tr, vec3_t br, int pcolor, float life) { + PM_ParticleLine(tl, bl, pcolor, life, 0); + PM_ParticleLine(bl, br, pcolor, life, 0); + PM_ParticleLine(br, tr, pcolor, life, 0); + PM_ParticleLine(tr, tl, pcolor, life, 0); } /* <2cff57> ../cstrike/pm_shared/pm_debug.c:128 */ -NOBODY void PM_DrawPhysEntBBox(int num, int pcolor, float life) +void PM_DrawPhysEntBBox(int num, int pcolor, float life) { -// physent_t *pe; // 130 -// vec3_t org; // 131 -// int j; // 132 -// vec3_t tmp; // 133 -// vec_t p; // 134 -// float gap; // 135 -// vec3_t modelmins; // 136 -// vec3_t modelmaxs; // 136 -// { -// vec3_t forward; // 161 -// vec3_t right; // 161 -// vec3_t up; // 161 -// } + physent_t *pe; + vec3_t org; + int j; + vec3_t tmp; + vec3_t p[8]; + float gap = BOX_GAP; + vec3_t modelmins, modelmaxs; + + if (num >= pmove->numphysent || num <= 0) + return; + + pe = &pmove->physents[num]; + + if (pe->model) + { + VectorCopy(pe->origin, org); + + pmove->PM_GetModelBounds(pe->model, modelmins, modelmaxs); + for (j = 0; j < 8; ++j) + { + tmp[0] = (j & 1) ? modelmins[0] - gap : modelmaxs[0] + gap; + tmp[1] = (j & 2) ? modelmins[1] - gap : modelmaxs[1] + gap; + tmp[2] = (j & 4) ? modelmins[2] - gap : modelmaxs[2] + gap; + + VectorCopy(tmp, p[j]); + } + + // If the bbox should be rotated, do that + if (pe->angles[0] || pe->angles[1] || pe->angles[2]) + { + vec3_t forward, right, up; + + AngleVectorsTranspose(pe->angles, forward, right, up); + for (j = 0; j < 8; ++j) + { + VectorCopy(p[j], tmp); + p[j][0] = DotProduct(tmp, forward); + p[j][1] = DotProduct(tmp, right); + p[j][2] = DotProduct(tmp, up); + } + } + + // Offset by entity origin, if any. + for (j = 0; j < 8; ++j) + VectorAdd(p[j], org, p[j]); + + for (j = 0; j < 6; ++j) + { + PM_DrawRectangle( + p[PM_boxpnt[j][1]], + p[PM_boxpnt[j][0]], + p[PM_boxpnt[j][2]], + p[PM_boxpnt[j][3]], + pcolor, life); + } + } + else + { + for (j = 0; j < 8; ++j) + { + tmp[0] = (j & 1) ? pe->mins[0] : pe->maxs[0]; + tmp[1] = (j & 2) ? pe->mins[1] : pe->maxs[1]; + tmp[2] = (j & 4) ? pe->mins[2] : pe->maxs[2]; + + VectorAdd(tmp, pe->origin, tmp); + VectorCopy(tmp, p[j]); + } + + for (j = 0; j < 6; ++j) + { + PM_DrawRectangle( + p[PM_boxpnt[j][1]], + p[PM_boxpnt[j][0]], + p[PM_boxpnt[j][2]], + p[PM_boxpnt[j][3]], + pcolor, life); + } + } } /* <2d030c> ../cstrike/pm_shared/pm_debug.c:218 */ -NOBODY void PM_DrawBBox(vec3_t mins, vec3_t maxs, vec3_t origin, int pcolor, float life) +void PM_DrawBBox(vec3_t mins, vec3_t maxs, vec3_t origin, int pcolor, float life) { -// int j; // 220 -// vec3_t tmp; // 222 -// vec_t p; // 223 -// float gap; // 224 -// PM_DrawRectangle(vec3_t tl, -// vec3_t bl, -// vec3_t tr, -// vec3_t br, -// int pcolor, -// float life); // 238 + int j; + + vec3_t tmp; + vec3_t p[8]; + float gap = BOX_GAP; + + for (j = 0; j < 8; ++j) + { + tmp[0] = (j & 1) ? mins[0] - gap : maxs[0] + gap; + tmp[1] = (j & 2) ? mins[1] - gap : maxs[1] + gap; + tmp[2] = (j & 4) ? mins[2] - gap : maxs[2] + gap; + + VectorAdd(tmp, origin, tmp); + VectorCopy(tmp, p[j]); + } + + for (j = 0; j < 6; ++j) + { + PM_DrawRectangle( + p[PM_boxpnt[j][1]], + p[PM_boxpnt[j][0]], + p[PM_boxpnt[j][2]], + p[PM_boxpnt[j][3]], + pcolor, life); + } } +// Shows a particle trail from player to entity in crosshair. +// Shows particles at that entities bbox +// Tries to shoot a ray out by about 128 units. + /* <2d03e9> ../cstrike/pm_shared/pm_debug.c:260 */ -NOBODY void PM_ViewEntity(void) +void PM_ViewEntity(void) { -// vec3_t forward; // 262 -// vec3_t right; // 262 -// vec3_t up; // 262 -// float raydist; // 263 -// vec3_t origin; // 264 -// vec3_t end; // 265 -// int i; // 266 -// pmtrace_t trace; // 267 -// int pcolor; // 268 -// float fup; // 269 -// PM_DrawPhysEntBBox(int num, -// int pcolor, -// float life); // 294 + vec3_t forward, right, up; + float raydist = 256.0f; + vec3_t origin; + vec3_t end; + int i; + pmtrace_t trace; + int pcolor = 77; + float fup; + +#if 0 + if (!pm_showclip.value) + return; +#endif + + // Determine movement angles + AngleVectors(pmove->angles, forward, right, up); + + VectorCopy(pmove->origin, origin); + + fup = 0.5 * (pmove->_player_mins[pmove->usehull][2] + pmove->_player_maxs[pmove->usehull][2]); + fup += pmove->view_ofs[2]; + fup -= 4; + + for (i = 0; i < 3; i++) + { + end[i] = origin[i] + raydist * forward[i]; + } + + trace = pmove->PM_PlayerTrace(origin, end, PM_STUDIO_BOX, -1); + + // Not the world + if (trace.ent > 0) + { + pcolor = 111; + } + + // Draw the hull or bbox. + if (trace.ent > 0) + { + PM_DrawPhysEntBBox(trace.ent, pcolor, 0.3f); + } } diff --git a/regamedll/pm_shared/pm_debug.h b/regamedll/pm_shared/pm_debug.h index 3752682c..6323a607 100644 --- a/regamedll/pm_shared/pm_debug.h +++ b/regamedll/pm_shared/pm_debug.h @@ -32,11 +32,11 @@ #pragma once #endif -NOBODY void PM_ShowClipBox(void); -NOBODY void PM_ParticleLine(vec3_t start, vec3_t end, int pcolor, float life, float vert); -NOBODY void PM_DrawRectangle(vec3_t tl, vec3_t bl, vec3_t tr, vec3_t br, int pcolor, float life); -NOBODY void PM_DrawPhysEntBBox(int num, int pcolor, float life); -NOBODY void PM_DrawBBox(vec3_t mins, vec3_t maxs, vec3_t origin, int pcolor, float life); -NOBODY void PM_ViewEntity(void); +void PM_ShowClipBox(void); +void PM_ParticleLine(vec3_t start, vec3_t end, int pcolor, float life, float vert); +void PM_DrawRectangle(vec3_t tl, vec3_t bl, vec3_t tr, vec3_t br, int pcolor, float life); +void PM_DrawPhysEntBBox(int num, int pcolor, float life); +void PM_DrawBBox(vec3_t mins, vec3_t maxs, vec3_t origin, int pcolor, float life); +void PM_ViewEntity(void); #endif // PM_DEBUG_H diff --git a/regamedll/pm_shared/pm_math.cpp b/regamedll/pm_shared/pm_math.cpp index ca64da19..fd114d7e 100644 --- a/regamedll/pm_shared/pm_math.cpp +++ b/regamedll/pm_shared/pm_math.cpp @@ -16,7 +16,7 @@ int nanmask; #endif // HOOK_GAMEDLL /* <2ce436> ../cstrike/pm_shared/pm_math.c:35 */ -NOBODY float anglemod(float a) +float anglemod(float a) { a = (360.0 / 65536) * ((int)(a *(65536 / 360.0)) & 65535); return a; @@ -63,15 +63,39 @@ void AngleVectors(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up) } /* <2ce521> ../cstrike/pm_shared/pm_math.c:76 */ -NOBODY void AngleVectorsTranspose(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up) +void AngleVectorsTranspose(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up) { -// float angle; // 78 -// float sr; // 79 -// float sp; // 79 -// float sy; // 79 -// float cr; // 79 -// float cp; // 79 -// float cy; // 79 + float angle; + float sr, sp, sy, cr, cp, cy; + + angle = angles[YAW] * (M_PI * 2 / 360); + sy = sin(angle); + cy = cos(angle); + angle = angles[PITCH] * (M_PI * 2 / 360); + sp = sin(angle); + cp = cos(angle); + angle = angles[ROLL] * (M_PI * 2 / 360); + sr = sin(angle); + cr = cos(angle); + + if (forward) + { + forward[0] = cp * cy; + forward[1] = (sr * sp * cy + cr * -sy); + forward[2] = (cr * sp * cy + -sr * -sy); + } + if (right) + { + right[0] = cp * sy; + right[1] = (sr * sp * sy + cr * cy); + right[2] = (cr * sp * sy + -sr * cy); + } + if (up) + { + up[0] = -sp; + up[1] = sr * cp; + up[2] = cr * cp; + } } /* <2ce5d0> ../cstrike/pm_shared/pm_math.c:112 */ @@ -110,48 +134,111 @@ void AngleMatrix(const vec_t *angles, float (*matrix)[4]) } /* <2ce67b> ../cstrike/pm_shared/pm_math.c:142 */ -NOBODY void AngleIMatrix(const vec_t *angles, float (*matrix)[4]) +void AngleIMatrix(const vec_t *angles, float (*matrix)[4]) { -// float angle; // 144 -// float sr; // 145 -// float sp; // 145 -// float sy; // 145 -// float cr; // 145 -// float cp; // 145 -// float cy; // 145 + float angle; + float sr, sp, sy, cr, cp, cy; + + angle = angles[YAW] * (M_PI * 2 / 360); + sy = sin(angle); + cy = cos(angle); + angle = angles[PITCH] * (M_PI * 2 / 360); + sp = sin(angle); + cp = cos(angle); + angle = angles[ROLL] * (M_PI * 2 / 360); + sr = sin(angle); + cr = cos(angle); + + // matrix = (YAW * PITCH) * ROLL + matrix[0][0] = cp * cy; + matrix[0][1] = cp * sy; + matrix[0][2] = -sp; + matrix[1][0] = sr * sp * cy + cr * -sy; + matrix[1][1] = sr * sp * sy + cr * cy; + matrix[1][2] = sr * cp; + matrix[2][0] = (cr * sp * cy + -sr * -sy); + matrix[2][1] = (cr * sp * sy + -sr * cy); + matrix[2][2] = cr * cp; + matrix[0][3] = 0.0; + matrix[1][3] = 0.0; + matrix[2][3] = 0.0; } /* <2ce710> ../cstrike/pm_shared/pm_math.c:172 */ -NOBODY void NormalizeAngles(float *angles) +void NormalizeAngles(float *angles) { -// int i; // 174 + int i; + // Normalize angles + for (i = 0; i < 3; ++i) + { + if (angles[i] > 180.0) + { + angles[i] -= 360.0; + } + else if (angles[i] < -180.0) + { + angles[i] += 360.0; + } + } } +// Interpolate Euler angles. +// FIXME: Use Quaternions to avoid discontinuities +// Frac is 0.0 to 1.0 (i.e., should probably be clamped, but doesn't have to be) + /* <2ce75f> ../cstrike/pm_shared/pm_math.c:198 */ -NOBODY void InterpolateAngles(float *start, float *end, float *output, float frac) +void InterpolateAngles(float *start, float *end, float *output, float frac) { -// int i; // 200 -// float ang1; // 201 -// float ang2; // 201 -// float d; // 202 -// NormalizeAngles(float *angles); // 204 -// NormalizeAngles(float *angles); // 205 -// NormalizeAngles(float *angles); // 225 + int i; + float ang1, ang2; + float d; + + NormalizeAngles(start); + NormalizeAngles(end); + + for (i = 0; i < 3; ++i) + { + ang1 = start[i]; + ang2 = end[i]; + + d = ang2 - ang1; + if (d > 180) + { + d -= 360; + } + else if (d < -180) + { + d += 360; + } + + output[i] = ang1 + d * frac; + } + + NormalizeAngles(output); } /* <2ce893> ../cstrike/pm_shared/pm_math.c:235 */ -NOBODY float AngleBetweenVectors(const vec_t *v1, const vec_t *v2) +float AngleBetweenVectors(const vec_t *v1, const vec_t *v2) { -// float angle; // 237 -// float l1; // 238 -// float l2; // 239 -// Length(const vec_t *v); // 238 -// Length(const vec_t *v); // 239 + float angle; + float l1 = Length(v1); + float l2 = Length(v2); + + if (!l1 || !l2) + return 0.0f; + + angle = acos(DotProduct(v1, v2)) / (l1 * l2); + angle = (angle * 180.0f) / M_PI; + + return angle; } /* <2ce953> ../cstrike/pm_shared/pm_math.c:251 */ -NOBODY void VectorTransform(const vec_t *in1, float *in2, vec_t *out) +void VectorTransform(const vec_t *in1, float (*in2)[4], vec_t *out) { + out[0] = _DotProduct(in1, in2[0]) + in2[0][3]; + out[1] = _DotProduct(in1, in2[1]) + in2[1][3]; + out[2] = _DotProduct(in1, in2[2]) + in2[2][3]; } /* <2ce996> ../cstrike/pm_shared/pm_math.c:259 */ @@ -175,7 +262,7 @@ void VectorMA(const vec_t *veca, float scale, const vec_t *vecb, vec_t *vecc) } /* <2cea34> ../cstrike/pm_shared/pm_math.c:278 */ -float_precision _DotProduct(vec_t *v1, vec_t *v2) +float_precision _DotProduct(const vec_t *v1, const vec_t *v2) { return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; } @@ -225,10 +312,11 @@ float_precision Length(const vec_t *v) } /* <2cebc2> ../cstrike/pm_shared/pm_math.c:325 */ -NOBODY float Distance(const vec_t *v1, const vec_t *v2) +float Distance(const vec_t *v1, const vec_t *v2) { -// vec_t *d; // 327 -// Length(const vec_t *v); // 329 + vec_t d[3]; + VectorSubtract(v2, v1, d); + return Length(d); } /* <2cec3c> ../cstrike/pm_shared/pm_math.c:332 */ @@ -252,8 +340,11 @@ float_precision VectorNormalize(vec_t *v) } /* <2ceca2> ../cstrike/pm_shared/pm_math.c:351 */ -NOBODY void VectorInverse(vec_t *v) +void VectorInverse(vec_t *v) { + v[0] = -v[0]; + v[1] = -v[1]; + v[2] = -v[2]; } /* <2cecc9> ../cstrike/pm_shared/pm_math.c:358 */ @@ -265,7 +356,7 @@ void VectorScale(const vec_t *in, vec_t scale, vec_t *out) } /* <2ced0f> ../cstrike/pm_shared/pm_math.c:366 */ -NOBODY int Q_log2(int val) +int Q_log2(int val) { int answer = 0; while (val >>= 1) @@ -275,23 +366,55 @@ NOBODY int Q_log2(int val) } /* <2ced4d> ../cstrike/pm_shared/pm_math.c:374 */ -NOBODY void VectorMatrix(vec_t *forward, vec_t *right, vec_t *up) +void VectorMatrix(vec_t *forward, vec_t *right, vec_t *up) { -// vec3_t *tmp; // 376 -// CrossProduct(const vec_t *v1, -// const vec_t *v2, -// vec_t *cross); // 390 -// VectorNormalize(vec_t *v); // 391 -// CrossProduct(const vec_t *v1, -// const vec_t *v2, -// vec_t *cross); // 392 -// VectorNormalize(vec_t *v); // 393 + vec_t tmp[3]; + + if (forward[0] == 0 && forward[1] == 0) + { + right[0] = 1; + right[1] = 0; + right[2] = 0; + + up[0] = -forward[2]; + up[1] = 0; + up[2] = 0; + return; + } + + tmp[0] = 0; tmp[1] = 0; tmp[2] = 1.0; + _CrossProduct(forward, tmp, right); + VectorNormalize(right); + _CrossProduct(right, forward, up); + VectorNormalize(up); } /* <2cee68> ../cstrike/pm_shared/pm_math.c:398 */ -NOBODY void VectorAngles(const vec_t *forward, vec_t *angles) +void VectorAngles(const vec_t *forward, vec_t *angles) { -// float tmp; // 400 -// float yaw; // 400 -// float pitch; // 400 + float tmp, yaw, pitch; + + if (forward[1] == 0 && forward[0] == 0) + { + yaw = 0; + if (forward[2] > 0) + pitch = 90; + else + pitch = 270; + } + else + { + yaw = (atan2(forward[1], forward[0]) * 180 / M_PI); + if (yaw < 0) + yaw += 360; + + tmp = sqrt (forward[0]*forward[0] + forward[1]*forward[1]); + pitch = (atan2(forward[2], tmp) * 180 / M_PI); + if (pitch < 0) + pitch += 360; + } + + angles[0] = pitch; + angles[1] = yaw; + angles[2] = 0; } diff --git a/regamedll/pm_shared/pm_math.h b/regamedll/pm_shared/pm_math.h index 01f01e22..16dfe22a 100644 --- a/regamedll/pm_shared/pm_math.h +++ b/regamedll/pm_shared/pm_math.h @@ -48,32 +48,32 @@ extern int nanmask; #define IS_NAN(x) ((*reinterpret_cast(&(x)) & nanmask) == nanmask) -NOBODY float anglemod(float a); +float anglemod(float a); void AngleVectors(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up); -NOBODY void AngleVectorsTranspose(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up); +void AngleVectorsTranspose(const vec_t *angles, vec_t *forward, vec_t *right, vec_t *up); void AngleMatrix(const vec_t *angles, float (*matrix)[4]); -NOBODY void AngleIMatrix(const vec_t *angles, float (*matrix)[4]); -NOBODY void NormalizeAngles(float *angles); -NOBODY void InterpolateAngles(float *start, float *end, float *output, float frac); -NOBODY float AngleBetweenVectors(const vec_t *v1, const vec_t *v2); -NOBODY void VectorTransform(const vec_t *in1, float *in2, vec_t *out); +void AngleIMatrix(const vec_t *angles, float (*matrix)[4]); +void NormalizeAngles(float *angles); +void InterpolateAngles(float *start, float *end, float *output, float frac); +float AngleBetweenVectors(const vec_t *v1, const vec_t *v2); +void VectorTransform(const vec_t *in1, float *in2, vec_t *out); int VectorCompare(const vec_t *v1, const vec_t *v2); void VectorMA(const vec_t *veca, float scale, const vec_t *vecb, vec_t *vecc); -float_precision _DotProduct(vec_t *v1, vec_t *v2); +float_precision _DotProduct(const vec_t *v1, const vec_t *v2); void _VectorSubtract(vec_t *veca, vec_t *vecb, vec_t *out); void _VectorAdd(vec_t *veca, vec_t *vecb, vec_t *out); void _VectorCopy(vec_t *in, vec_t *out); void _CrossProduct(const vec_t *v1, const vec_t *v2, vec_t *cross); float_precision Length(const vec_t *v); -NOBODY float Distance(const vec_t *v1, const vec_t *v2); +float Distance(const vec_t *v1, const vec_t *v2); float_precision VectorNormalize(vec_t *v); -NOBODY void VectorInverse(vec_t *v); -NOBODY void VectorScale(const vec_t *in, vec_t scale, vec_t *out); -NOBODY int Q_log2(int val); -NOBODY void VectorMatrix(vec_t *forward, vec_t *right, vec_t *up); -NOBODY void VectorAngles(const vec_t *forward, vec_t *angles); +void VectorInverse(vec_t *v); +void VectorScale(const vec_t *in, vec_t scale, vec_t *out); +int Q_log2(int val); +void VectorMatrix(vec_t *forward, vec_t *right, vec_t *up); +void VectorAngles(const vec_t *forward, vec_t *angles); #endif // PM_MATH_H