From c3e56a4c7d1468709b611c63037a6361e782e7ed Mon Sep 17 00:00:00 2001 From: danij Date: Wed, 26 Feb 2014 18:41:50 +0000 Subject: [PATCH] libcommon: Cleanup --- doomsday/client/src/world/map.cpp | 6 +- doomsday/plugins/common/include/d_netcl.h | 7 + doomsday/plugins/common/include/g_common.h | 4 +- doomsday/plugins/common/include/gamerules.h | 5 + doomsday/plugins/common/src/d_netcl.cpp | 185 +++++++------------- doomsday/plugins/common/src/d_netsv.cpp | 17 +- doomsday/plugins/common/src/g_game.cpp | 27 +-- doomsday/plugins/common/src/gamerules.cpp | 29 +++ doomsday/plugins/common/src/hu_stuff.cpp | 18 +- doomsday/plugins/common/src/p_saveg.cpp | 1 - 10 files changed, 143 insertions(+), 156 deletions(-) diff --git a/doomsday/client/src/world/map.cpp b/doomsday/client/src/world/map.cpp index e45398d04d..d159c8a085 100644 --- a/doomsday/client/src/world/map.cpp +++ b/doomsday/client/src/world/map.cpp @@ -1803,7 +1803,11 @@ coord_t Map::gravity() const void Map::setGravity(coord_t newGravity) { - _effectiveGravity = newGravity; + if(!de::fequal(_effectiveGravity, newGravity)) + { + _effectiveGravity = newGravity; + LOG_MAP_VERBOSE("Effective gravity for %s now %.1f") << d->uri.asText() << _effectiveGravity; + } } Thinkers &Map::thinkers() const diff --git a/doomsday/plugins/common/include/d_netcl.h b/doomsday/plugins/common/include/d_netcl.h index cc0df32dc8..b7cb7f29d7 100644 --- a/doomsday/plugins/common/include/d_netcl.h +++ b/doomsday/plugins/common/include/d_netcl.h @@ -40,6 +40,9 @@ void NetCl_UpdatePlayerState2(Reader *msg, int plrNum); void NetCl_UpdatePSpriteState(Reader *msg); +/** + * Set the jump power used in client mode. + */ void NetCl_UpdateJumpPower(Reader *msg); void NetCl_Intermission(Reader *msg); @@ -65,6 +68,10 @@ void NetCl_PlayerActionRequest(player_t *player, int actionType, int actionParam void NetCl_DamageRequest(mobj_t *target, mobj_t *inflictor, mobj_t *source, int damage); +/** + * Send a GPT_CHEAT_REQUEST packet to the server. If the server is allowing netgame cheating, + * the cheat will be executed on the server. + */ void NetCl_CheatRequest(char const *command); void NetCl_FloorHitRequest(player_t *player); diff --git a/doomsday/plugins/common/include/g_common.h b/doomsday/plugins/common/include/g_common.h index d4b18d5924..1d82db824d 100644 --- a/doomsday/plugins/common/include/g_common.h +++ b/doomsday/plugins/common/include/g_common.h @@ -61,8 +61,6 @@ void G_SetGameAction(gameaction_t action); AutoStr *G_IdentityKeyForLegacyGamemode(int gamemode, int saveVersion); -char const *P_GameRulesetDescription(void); - uint G_GenerateSessionId(void); /** @@ -253,7 +251,7 @@ GameRuleset &G_Rules(); extern "C" { #endif -GameRuleset *G_RulesPtr(); +GameRuleset *G_RulesPtr(void); #ifdef __cplusplus } // extern "C" diff --git a/doomsday/plugins/common/include/gamerules.h b/doomsday/plugins/common/include/gamerules.h index fff0ff7e81..e3a9a4baa1 100644 --- a/doomsday/plugins/common/include/gamerules.h +++ b/doomsday/plugins/common/include/gamerules.h @@ -24,6 +24,7 @@ #include "common.h" #ifdef __cplusplus +#include /** * @ingroup libcommon @@ -51,8 +52,12 @@ class GameRuleset GameRuleset &operator = (GameRuleset const &other); + de::String description() const; + void write(Writer *writer) const; void read(Reader *reader); + + de::String asText() const; }; #endif // __cplusplus diff --git a/doomsday/plugins/common/src/d_netcl.cpp b/doomsday/plugins/common/src/d_netcl.cpp index 502050dedc..5bab8476d0 100644 --- a/doomsday/plugins/common/src/d_netcl.cpp +++ b/doomsday/plugins/common/src/d_netcl.cpp @@ -36,59 +36,44 @@ void NetCl_UpdateGameState(Reader *msg) { - byte len; - byte gsFlags = 0; - char gsGameIdentity[256]; - Uri *mapUri; - uint gsEpisode = 0; - uint gsMap = 0; - //uint gsMapEntrance = 0; - byte configFlags = 0; - //byte gsDeathmatch = 0; - //byte gsMonsters = 0; - //byte gsRespawn = 0; - byte gsJumping = 0; - //byte gsSkill = 0; - coord_t gsGravity = 0; - GameRuleset gsRules = G_Rules(); // Make a copy of the current rules. - BusyMode_FreezeGameForBusyMode(); - gsFlags = Reader_ReadByte(msg); + byte gsFlags = Reader_ReadByte(msg); // Game identity key. - len = Reader_ReadByte(msg); - Reader_Read(msg, gsGameIdentity, len); - gsGameIdentity[len] = 0; + byte len = Reader_ReadByte(msg); + char gsGameIdentity[256]; + Reader_Read(msg, gsGameIdentity, len); gsGameIdentity[len] = 0; // Current map. - mapUri = Uri_FromReader(msg); - gsEpisode = Reader_ReadByte(msg); - gsMap = Reader_ReadByte(msg); + Uri *gsMapUri = Uri_FromReader(msg); + /*uint gsEpisode =*/ Reader_ReadByte(msg); + /*uint gsMap =*/ Reader_ReadByte(msg); /// @todo Not communicated to clients?? - //gsMapEntrance = ??; + //uint gsMapEntrance = ??; - configFlags = Reader_ReadByte(msg); - gsRules.deathmatch = configFlags & 0x3; - gsRules.noMonsters = !(configFlags & 0x4? true : false); + byte configFlags = Reader_ReadByte(msg); + + GameRuleset gsRules(G_Rules()); // Initialize with a copy of the current rules. + gsRules.deathmatch = configFlags & 0x3; + gsRules.noMonsters = !(configFlags & 0x4? true : false); #if !__JHEXEN__ gsRules.respawnMonsters = (configFlags & 0x8? true : false); #endif - gsJumping = (configFlags & 0x10? true : false); + /// @todo Not applied?? + /*byte gsJumping =*/ (configFlags & 0x10? true : false); - gsRules.skill = skillmode_t(Reader_ReadByte(msg)); + gsRules.skill = skillmode_t(Reader_ReadByte(msg)); // Interpret skill modes outside the normal range as "spawn no things". if(gsRules.skill < SM_BABY || gsRules.skill >= NUM_SKILL_MODES) { - gsRules.skill = SM_NOTHINGS; + gsRules.skill = SM_NOTHINGS; } - gsGravity = Reader_ReadFloat(msg); + coord_t gsGravity = Reader_ReadFloat(msg); - App_Log(DE2_DEV_MAP_NOTE, - "NetCl_UpdateGameState: Flags=%x, Map uri=\"%s\"", - gsFlags, Str_Text(Uri_ToString(mapUri))); + App_Log(DE2_DEV_MAP_NOTE, "NetCl_UpdateGameState: Flags=%x", gsFlags); // Demo game state changes are only effective during demo playback. if(gsFlags & GSF_DEMO && !Get(DD_PLAYBACK)) @@ -98,56 +83,35 @@ void NetCl_UpdateGameState(Reader *msg) /// @todo Automatically load the server's game if it is available. /// However, note that this can only occur if the server changes its game /// while a netgame is running (which currently will end the netgame). + GameInfo gameInfo; + DD_GameInfo(&gameInfo); + if(Str_Compare(gameInfo.identityKey, gsGameIdentity)) { - GameInfo gameInfo; - DD_GameInfo(&gameInfo); - if(Str_Compare(gameInfo.identityKey, gsGameIdentity)) - { - App_Log(DE2_NET_ERROR, "Game mismatch: server's game mode (%s) is different than yours (%s)", - gsGameIdentity, Str_Text(gameInfo.identityKey)); - DD_Execute(false, "net disconnect"); - return; - } + App_Log(DE2_NET_ERROR, "Game mismatch: server's identity key (%s) is different to yours (%s)", + gsGameIdentity, Str_Text(gameInfo.identityKey)); + DD_Execute(false, "net disconnect"); + return; } // Some statistics. -#if __JHEXEN__ - App_Log(DE2_LOG_NOTE, - "Game state: Map=%u Skill=%i %s", gsMap+1, gsRules.skill, - gsRules.deathmatch == 1 ? "Deathmatch" : - gsRules.deathmatch == 2 ? "Deathmatch2" : "Co-op"); -#else - App_Log(DE2_LOG_NOTE, - "Game state: Map=%u Episode=%u Skill=%i %s", gsMap+1, - gsEpisode+1, gsRules.skill, - gsRules.deathmatch == 1 ? "Deathmatch" : - gsRules.deathmatch == 2 ? "Deathmatch2" : "Co-op"); -#endif -#if !__JHEXEN__ - App_Log(DE2_LOG_NOTE, " Respawn=%s Monsters=%s Jumping=%s Gravity=%.1f", - gsRules.respawnMonsters ? "yes" : "no", !gsRules.noMonsters ? "yes" : "no", - gsJumping ? "yes" : "no", gsGravity); -#else - App_Log(DE2_NET_NOTE, " Monsters=%s Jumping=%s Gravity=%.1f", - !gsRules.noMonsters ? "yes" : "no", - gsJumping ? "yes" : "no", gsGravity); -#endif + App_Log(DE2_LOG_NOTE, "%s - %s\n %s", + gsRules.description().toLatin1().constData(), + Str_Text(Uri_ToString(gsMapUri)), + gsRules.asText().toLatin1().constData()); // Do we need to change the map? if(gsFlags & GSF_CHANGE_MAP) { - G_NewSession(mapUri, gameMapEntrance /*gsMapEntrance*/, &gsRules); - - /// @todo Necessary? - G_SetGameAction(GA_NONE); + G_NewSession(gsMapUri, gameMapEntrance /*gsMapEntrance*/, &gsRules); + G_SetGameAction(GA_NONE); /// @todo Necessary? } else { - gameEpisode = gsEpisode; - gameMap = gsMap; - Uri_Copy(gameMapUri, mapUri); + Uri_Copy(gameMapUri, gsMapUri); + gameEpisode = G_EpisodeNumberFor(gsMapUri); + gameMap = G_MapNumberFor(gsMapUri); //gameMapEntrance = gsMapEntrance; /// @todo Not communicated to clients?? - G_Rules() = gsRules; + G_Rules() = gsRules; } // Set gravity. @@ -158,32 +122,29 @@ void NetCl_UpdateGameState(Reader *msg) if(gsFlags & GSF_CAMERA_INIT) { player_t *pl = &players[CONSOLEPLAYER]; - mobj_t *mo; - - mo = pl->plr->mo; - if(mo) + if(mobj_t *mo = pl->plr->mo) { P_MobjUnlink(mo); mo->origin[VX] = Reader_ReadFloat(msg); mo->origin[VY] = Reader_ReadFloat(msg); mo->origin[VZ] = Reader_ReadFloat(msg); P_MobjLink(mo); - mo->angle = Reader_ReadUInt32(msg); + mo->angle = Reader_ReadUInt32(msg); // Update floorz and ceilingz. #if __JDOOM__ || __JDOOM64__ P_CheckPosition(mo, mo->origin); #else P_CheckPositionXY(mo, mo->origin[VX], mo->origin[VY]); #endif - mo->floorZ = tmFloorZ; - mo->ceilingZ = tmCeilingZ; + mo->floorZ = tmFloorZ; + mo->ceilingZ = tmCeilingZ; } - else // mo == NULL + else { - float mx = Reader_ReadFloat(msg); - float my = Reader_ReadFloat(msg); - float mz = Reader_ReadFloat(msg); - angle_t angle = Reader_ReadUInt32(msg); + float mx = Reader_ReadFloat(msg); + float my = Reader_ReadFloat(msg); + float mz = Reader_ReadFloat(msg); + angle_t angle = Reader_ReadUInt32(msg); App_Log(DE2_DEV_NET_WARNING, "NetCl_UpdateGameState: Got camera init, but player has no mobj; " @@ -195,15 +156,14 @@ void NetCl_UpdateGameState(Reader *msg) Net_SendPacket(0, DDPT_OK, 0, 0); } -void NetCl_MobjImpulse(Reader* msg) +void NetCl_MobjImpulse(Reader *msg) { - mobj_t* mo = players[CONSOLEPLAYER].plr->mo; - mobj_t* clmo = ClPlayer_ClMobj(CONSOLEPLAYER); - thid_t id = 0; + mobj_t *mo = players[CONSOLEPLAYER].plr->mo; + mobj_t *clmo = ClPlayer_ClMobj(CONSOLEPLAYER); if(!mo || !clmo) return; - id = Reader_ReadUInt16(msg); + thid_t id = Reader_ReadUInt16(msg); if(id != clmo->thinker.id) { // Not applicable; wrong mobj. @@ -218,23 +178,20 @@ void NetCl_MobjImpulse(Reader* msg) mo->mom[MZ] += Reader_ReadFloat(msg); } -void NetCl_PlayerSpawnPosition(Reader* msg) +void NetCl_PlayerSpawnPosition(Reader *msg) { - player_t* p = &players[CONSOLEPLAYER]; - coord_t x, y, z; - angle_t angle; - mobj_t* mo; + player_t *p = &players[CONSOLEPLAYER]; - x = Reader_ReadFloat(msg); - y = Reader_ReadFloat(msg); - z = Reader_ReadFloat(msg); - angle = Reader_ReadUInt32(msg); + coord_t x = Reader_ReadFloat(msg); + coord_t y = Reader_ReadFloat(msg); + coord_t z = Reader_ReadFloat(msg); + angle_t angle = Reader_ReadUInt32(msg); App_Log(DE2_DEV_MAP_NOTE, "Got player spawn position (%g, %g, %g) facing %x", x, y, z, angle); - mo = p->plr->mo; - DENG_ASSERT(mo != 0); + mobj_t *mo = p->plr->mo; + DENG2_ASSERT(mo != 0); P_TryMoveXYZ(mo, x, y, z); mo->angle = angle; @@ -818,12 +775,9 @@ void NetCl_UpdatePlayerInfo(Reader *msg) */ void NetCl_SendPlayerInfo() { - Writer* msg; - - if(!IS_CLIENT) - return; + if(!IS_CLIENT) return; - msg = D_NetWrite(); + Writer *msg = D_NetWrite(); Writer_WriteByte(msg, cfg.netColor); #ifdef __JHEXEN__ @@ -838,7 +792,7 @@ void NetCl_SendPlayerInfo() void NetCl_SaveGame(Reader *msg) { #if __JHEXEN__ - DENG_UNUSED(msg); + DENG2_UNUSED(msg); #endif if(Get(DD_PLAYBACK)) return; @@ -854,7 +808,7 @@ void NetCl_SaveGame(Reader *msg) void NetCl_LoadGame(Reader *msg) { #if __JHEXEN__ - DENG_UNUSED(msg); + DENG2_UNUSED(msg); #endif if(!IS_CLIENT || Get(DD_PLAYBACK)) return; @@ -867,27 +821,24 @@ void NetCl_LoadGame(Reader *msg) #endif } -/** - * Send a GPT_CHEAT_REQUEST packet to the server. If the server is allowing - * netgame cheating, the cheat will be executed on the server. - */ -void NetCl_CheatRequest(const char *command) +void NetCl_CheatRequest(char const *command) { - Writer* msg = D_NetWrite(); + Writer *msg = D_NetWrite(); Writer_WriteUInt16(msg, strlen(command)); Writer_Write(msg, command, strlen(command)); if(IS_CLIENT) + { Net_SendPacket(0, GPT_CHEAT_REQUEST, Writer_Data(msg), Writer_Size(msg)); + } else + { NetSv_ExecuteCheat(CONSOLEPLAYER, command); + } } -/** - * Set the jump power used in client mode. - */ -void NetCl_UpdateJumpPower(Reader* msg) +void NetCl_UpdateJumpPower(Reader *msg) { netJumpPower = Reader_ReadFloat(msg); diff --git a/doomsday/plugins/common/src/d_netsv.cpp b/doomsday/plugins/common/src/d_netsv.cpp index 9387823ae0..3004d2d83c 100644 --- a/doomsday/plugins/common/src/d_netsv.cpp +++ b/doomsday/plugins/common/src/d_netsv.cpp @@ -95,28 +95,39 @@ static int oldClasses[MAXPLAYERS]; void NetSv_UpdateGameConfigDescription() { - if(IS_CLIENT) - return; + if(IS_CLIENT) return; de::zap(gameConfigString); sprintf(gameConfigString, "skill%i", G_Rules().skill + 1); if(G_Rules().deathmatch > 1) + { sprintf(gameConfigString, " dm%i", G_Rules().deathmatch); + } else if(G_Rules().deathmatch) + { strcat(gameConfigString, " dm"); + } else + { strcat(gameConfigString, " coop"); + } if(G_Rules().noMonsters) + { strcat(gameConfigString, " nomonst"); + } #if !__JHEXEN__ if(G_Rules().respawnMonsters) + { strcat(gameConfigString, " respawn"); + } #endif if(cfg.jumpEnabled) + { strcat(gameConfigString, " jump"); + } } void NetSv_Ticker() @@ -182,7 +193,7 @@ void NetSv_Ticker() plr->update = 0; } -#if __JHERETIC__ || __JHEXEN__ || __JSTRIFE__ +#if __JHERETIC__ || __JHEXEN__ // Keep track of player class changes (fighter, cleric, mage, pig). // Notify clients accordingly. This is mostly just FYI (it'll update // pl->class_ on the clientside). diff --git a/doomsday/plugins/common/src/g_game.cpp b/doomsday/plugins/common/src/g_game.cpp index 66307ec6e5..8bfb49a5fc 100644 --- a/doomsday/plugins/common/src/g_game.cpp +++ b/doomsday/plugins/common/src/g_game.cpp @@ -1220,8 +1220,6 @@ void G_StartTitle() void G_StartHelp() { - ddfinale_t fin; - if(G_QuitInProgress()) return; if(IS_CLIENT) { @@ -1229,6 +1227,7 @@ void G_StartHelp() return; } + ddfinale_t fin; if(Def_Get(DD_DEF_FINALE, "help", &fin)) { Hu_MenuCommand(MCMD_CLOSEFAST); @@ -1246,7 +1245,7 @@ static void printMapBanner() { char const *title = P_MapTitle(0/*current map*/); - App_Log(DE2_LOG_MAP, DE2_ESC(R)); + App_Log(DE2_LOG_MESSAGE, DE2_ESC(R)); if(title) { char buf[64]; @@ -1257,18 +1256,15 @@ static void printMapBanner() #else dd_snprintf(buf, 64, "Map: %s - " DE2_ESC(b) "%s", Str_Text(Uri_ToString(gameMapUri)), title); #endif - App_Log(DE2_MAP_NOTE, "%s", buf); + App_Log(DE2_LOG_NOTE, "%s", buf); } #if !__JHEXEN__ - { char const *author = P_MapAuthor(0/*current map*/, P_MapIsCustom(Str_Text(Uri_Compose(gameMapUri)))); if(!author) author = "Unknown"; - App_Log(DE2_MAP_VERBOSE, "Author: %s", author); - } + App_Log(DE2_LOG_NOTE, "Author: %s", author); #endif - App_Log(DE2_LOG_MAP, ""); } void G_BeginMap() @@ -3460,9 +3456,9 @@ void G_NewSession(Uri const *mapUri, uint mapEntrance, GameRuleset const *rules) // Delete raw images to conserve texture memory. DD_Executef(true, "texreset raw"); + Uri_Copy(gameMapUri, mapUri); gameEpisode = G_EpisodeNumberFor(mapUri); gameMap = G_MapNumberFor(mapUri); - Uri_Copy(gameMapUri, mapUri); gameMapEntrance = mapEntrance; gameRules = *rules; @@ -3621,19 +3617,6 @@ AutoStr *G_IdentityKeyForLegacyGamemode(int gamemode, int saveVersion) return AutoStr_FromTextStd(identityKeys[gamemode]); } -char const *P_GameRulesetDescription() -{ - static char const *dm = "deathmatch"; - static char const *coop = "cooperative"; - static char const *sp = "singleplayer"; - if(IS_NETGAME) - { - if(gameRules.deathmatch) return dm; - return coop; - } - return sp; -} - uint G_GenerateSessionId() { return Timer_RealMilliseconds() + (mapTime << 24); diff --git a/doomsday/plugins/common/src/gamerules.cpp b/doomsday/plugins/common/src/gamerules.cpp index 243c9b72bc..31b9a4ba4a 100644 --- a/doomsday/plugins/common/src/gamerules.cpp +++ b/doomsday/plugins/common/src/gamerules.cpp @@ -65,6 +65,18 @@ GameRuleset &GameRuleset::operator = (GameRuleset const &other) return *this; } +de::String GameRuleset::description() const +{ + /// @todo Separate co-op behavior to new rules, avoiding netgame test. + if(IS_NETGAME) + { + if(deathmatch == 2) return "Deathmatch2"; + if(deathmatch) return "Deathmatch"; + return "Co-op"; + } + return "Singleplayer"; +} + void GameRuleset::write(Writer *writer) const { DENG2_ASSERT(writer != 0); @@ -105,6 +117,23 @@ void GameRuleset::read(Reader *reader) #endif } +de::String GameRuleset::asText() const +{ + de::String str; + QTextStream os(&str); + os << "skillmode: " << int(skill); + os << " jumping: " << (cfg.jumpEnabled ? "yes" : "no"); +#if __JHEXEN__ + os << " random player classes: " << (randomClasses ? "yes" : "no"); +#endif + os << " monsters: " << (!noMonsters ? "yes" : "no"); +#if !__JHEXEN__ + os << " (fast: " << (fast ? "yes" : "no"); + os << " respawn: " << (respawnMonsters ? "yes" : "no") << ")"; +#endif + return str; +} + // C wrapper API --------------------------------------------------------------- skillmode_t GameRuleset_Skill(GameRuleset const *rules) diff --git a/doomsday/plugins/common/src/hu_stuff.cpp b/doomsday/plugins/common/src/hu_stuff.cpp index c67e4aa21c..5f60078045 100644 --- a/doomsday/plugins/common/src/hu_stuff.cpp +++ b/doomsday/plugins/common/src/hu_stuff.cpp @@ -21,20 +21,13 @@ * 02110-1301 USA */ -#include -#include -#include -#include -#include -#include - #include "common.h" +#include "hu_stuff.h" #include "hu_chat.h" #include "hu_log.h" #include "hu_menu.h" #include "hu_msg.h" -#include "hu_stuff.h" #include "hu_inventory.h" #include "g_common.h" #include "p_mapsetup.h" @@ -43,6 +36,13 @@ #include "fi_lib.h" #include "r_common.h" +#include +#include +#include +#include +#include +#include + /** * @defgroup tableColumnFlags Table Column flags */ @@ -755,7 +755,7 @@ static void drawMapMetaData(float x, float y, float alpha) if(!title) title = "Unnamed"; char buf[256]; - dd_snprintf(buf, 256, "map: %s gamemode: %s", title, P_GameRulesetDescription()); + dd_snprintf(buf, 256, "%s - %s", G_Rules().description().toLatin1().constData(), title); FR_SetColorAndAlpha(1, 1, 1, alpha); FR_DrawTextXY2(buf, x + BORDER, y - BORDER, ALIGN_BOTTOMLEFT); diff --git a/doomsday/plugins/common/src/p_saveg.cpp b/doomsday/plugins/common/src/p_saveg.cpp index a95c9e0485..82be6e73cb 100644 --- a/doomsday/plugins/common/src/p_saveg.cpp +++ b/doomsday/plugins/common/src/p_saveg.cpp @@ -881,7 +881,6 @@ void SV_LoadGameClient(uint sessionId) } else { - /// @todo Necessary? G_Rules() = info->gameRules(); } mapTime = info->mapTime();