From 63b657078974b7473164d2a6f3ca7b3d5e0668cb Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 10 Jan 2014 00:26:33 +0000 Subject: [PATCH] World|Client: Cleanup --- doomsday/client/include/client/cl_def.h | 52 +++-- doomsday/client/include/client/cl_frame.h | 29 ++- doomsday/client/include/client/cl_infine.h | 23 +-- doomsday/client/include/client/cl_mobj.h | 38 ++-- doomsday/client/include/client/cl_player.h | 86 +++++---- doomsday/client/include/client/cl_sound.h | 27 +-- doomsday/client/include/client/cl_world.h | 47 ++--- doomsday/client/include/world/map.h | 24 +-- doomsday/client/src/client/cl_frame.cpp | 128 ++++++------ doomsday/client/src/client/cl_infine.cpp | 16 +- doomsday/client/src/client/cl_main.cpp | 37 ++-- doomsday/client/src/client/cl_mobj.cpp | 128 +++++------- doomsday/client/src/client/cl_player.cpp | 74 +++---- doomsday/client/src/client/cl_sound.cpp | 35 ++-- doomsday/client/src/client/cl_world.cpp | 215 ++++++++++----------- doomsday/client/src/world/thinkers.cpp | 15 +- 16 files changed, 419 insertions(+), 555 deletions(-) diff --git a/doomsday/client/include/client/cl_def.h b/doomsday/client/include/client/cl_def.h index 7e6c89e93c..3ba02fc6b2 100644 --- a/doomsday/client/include/client/cl_def.h +++ b/doomsday/client/include/client/cl_def.h @@ -1,4 +1,4 @@ -/** @file +/** @file cl_def.h Client definitions. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2007-2013 Daniel Swanson @@ -17,34 +17,36 @@ * http://www.gnu.org/licenses */ -/** - * cl_def.h: Client Definitions - */ - -#ifndef __DOOMSDAY_CLIENT_H__ -#define __DOOMSDAY_CLIENT_H__ +#ifndef DENG_CLIENT_H +#define DENG_CLIENT_H #include "world/p_object.h" -#ifdef __cplusplus -extern "C" { -#endif - #define SHORTP(x) (*(short*) (x)) #define USHORTP(x) (*(unsigned short*) (x)) -extern ident_t clientID; -extern int serverTime; -extern boolean handshakeReceived; -extern int gameReady; -extern boolean netLoggedIn; -extern int clientPaused; +DENG_EXTERN_C ident_t clientID; +DENG_EXTERN_C int serverTime; +DENG_EXTERN_C boolean handshakeReceived; +DENG_EXTERN_C int gameReady; +DENG_EXTERN_C boolean netLoggedIn; +DENG_EXTERN_C int clientPaused; -void Cl_InitID(void); -void Cl_CleanUp(void); -void Cl_GetPackets(void); -void Cl_Ticker(timespan_t ticLength); -int Cl_GameReady(void); +void Cl_InitID(); + +void Cl_CleanUp(); + +/** + * Client's packet handler. Handles all the events the server sends. + */ +void Cl_GetPackets(); + +/** + * Client-side game ticker. + */ +void Cl_Ticker(timespan_t ticLength); + +int Cl_GameReady(); /** * Sends a hello packet. @@ -52,8 +54,4 @@ int Cl_GameReady(void); */ void Cl_SendHello(); -#ifdef __cplusplus -} // extern "C" -#endif - -#endif +#endif // DENG_CLIENT_H diff --git a/doomsday/client/include/client/cl_frame.h b/doomsday/client/include/client/cl_frame.h index 942c224c2f..75634cc5fa 100644 --- a/doomsday/client/include/client/cl_frame.h +++ b/doomsday/client/include/client/cl_frame.h @@ -1,4 +1,4 @@ -/** @file +/** @file cl_frame.h Client frame reception. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2007-2013 Daniel Swanson @@ -17,24 +17,17 @@ * http://www.gnu.org/licenses */ -/** - * cl_frame.h: Frame Reception - */ - -#ifndef __DOOMSDAY_CLIENT_FRAME_H__ -#define __DOOMSDAY_CLIENT_FRAME_H__ +#ifndef DENG_CLIENT_FRAME_H +#define DENG_CLIENT_FRAME_H -#ifdef __cplusplus -extern "C" { -#endif +void Cl_InitFrame(); +void Cl_ResetFrame(); -void Cl_InitFrame(void); -void Cl_ResetFrame(void); -void Cl_Frame2Received(int packetType); -float Cl_FrameGameTime(void); +/** + * Read a PSV_FRAME2/PSV_FIRST_FRAME2 packet. + */ +void Cl_Frame2Received(int packetType); -#ifdef __cplusplus -} // extern "C" -#endif +float Cl_FrameGameTime(); -#endif +#endif // DENG_CLIENT_FRAME_H diff --git a/doomsday/client/include/client/cl_infine.h b/doomsday/client/include/client/cl_infine.h index a6f24ae26a..eb8e41a1bb 100644 --- a/doomsday/client/include/client/cl_infine.h +++ b/doomsday/client/include/client/cl_infine.h @@ -1,4 +1,4 @@ -/** @file +/** @file cl_infine.h Clientside InFine. * * @authors Copyright © 2010 Daniel Swanson * @@ -16,33 +16,22 @@ * http://www.gnu.org/licenses */ -/** - * Client-side InFine. - */ - #ifndef DENG_CLIENT_INFINE #define DENG_CLIENT_INFINE +#include "api_infine.h" #include -#ifdef __cplusplus -extern "C" { -#endif - -finaleid_t Cl_CurrentFinale(void); +finaleid_t Cl_CurrentFinale(); /** * This is where clients start their InFine sequences. */ -void Cl_Finale(Reader* msg); +void Cl_Finale(Reader *msg); /** * Client sends a request to skip the finale. */ -void Cl_RequestFinaleSkip(void); - -#ifdef __cplusplus -} // extern "C" -#endif +void Cl_RequestFinaleSkip(); -#endif /* DENG_CLIENT_INFINE */ +#endif // DENG_CLIENT_INFINE diff --git a/doomsday/client/include/client/cl_mobj.h b/doomsday/client/include/client/cl_mobj.h index a69cd2e635..e48d90dd78 100644 --- a/doomsday/client/include/client/cl_mobj.h +++ b/doomsday/client/include/client/cl_mobj.h @@ -1,8 +1,8 @@ -/** @file cl_mobj.h Clientside map objects. +/** @file cl_mobj.h Clientside map objects. * @ingroup client * - * @author Copyright © 2003-2013 Jaakko Keränen - * @author Copyright © 2006-2013 Daniel Swanson + * @author Copyright © 2003-2013 Jaakko Keränen + * @author Copyright © 2006-2013 Daniel Swanson * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -18,8 +18,8 @@ * http://www.gnu.org/licenses */ -#ifndef __DOOMSDAY_CLIENT_MOBJ_H__ -#define __DOOMSDAY_CLIENT_MOBJ_H__ +#ifndef DENG_CLIENT_WORLD_MOBJ_H +#define DENG_CLIENT_WORLD_MOBJ_H #include "world/p_object.h" @@ -57,19 +57,15 @@ * gameside mobjs. The last 4 bytes must be CLM_MAGIC. */ typedef struct clmoinfo_s { - uint startMagic; // The client mobj magic number (CLM_MAGIC1). + uint startMagic; // The client mobj magic number (CLM_MAGIC1). struct clmoinfo_s *next, *prev; - int flags; - uint time; // Time of last update. - int sound; // Queued sound ID. - float volume; // Volume for queued sound. - uint endMagic; // The client mobj magic number (CLM_MAGIC2). + int flags; + uint time; // Time of last update. + int sound; // Queued sound ID. + float volume; // Volume for queued sound. + uint endMagic; // The client mobj magic number (CLM_MAGIC2). } clmoinfo_t; -#ifdef __cplusplus -extern "C" { -#endif - /** * Make the real player mobj identical with the client mobj. * The client mobj is always unlinked. Only the *real* mobj is visible. @@ -143,16 +139,14 @@ void ClMobj_SetState(mobj_t *mo, int stnum); // needed? * * For client mobjs that belong to players, updates the real player mobj * accordingly. - * - * @param skip If @c true, all read data is ignored. */ -void ClMobj_ReadDelta2(boolean skip); +void ClMobj_ReadDelta(); /** * Null mobjs deltas have their own type in a PSV_FRAME2 packet. * Here we remove the mobj in question. */ -void ClMobj_ReadNullDelta2(boolean skip); +void ClMobj_ReadNullDelta(); /** * Determines whether a mobj is a client mobj. @@ -163,8 +157,4 @@ void ClMobj_ReadNullDelta2(boolean skip); */ boolean Cl_IsClientMobj(mobj_t *mo); // public -#ifdef __cplusplus -} // extern "C" -#endif - -#endif +#endif // DENG_CLIENT_WORLD_MOBJ_H diff --git a/doomsday/client/include/client/cl_player.h b/doomsday/client/include/client/cl_player.h index 525545028a..55c0a88387 100644 --- a/doomsday/client/include/client/cl_player.h +++ b/doomsday/client/include/client/cl_player.h @@ -1,4 +1,4 @@ -/** @file cl_player.h +/** @file cl_player.h Clientside player management. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2007-2013 Daniel Swanson @@ -17,56 +17,49 @@ * http://www.gnu.org/licenses */ -/** - * Clientside Player Management - */ - #ifndef DENG_CLIENT_PLAYER_H #define DENG_CLIENT_PLAYER_H #include "cl_mobj.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * Information about a client player. */ typedef struct clplayerstate_s { - thid_t clMobjId; - float forwardMove; - float sideMove; - int angle; - angle_t turnDelta; - int friction; - int pendingFixes; - thid_t pendingFixTargetClMobjId; - angle_t pendingAngleFix; - float pendingLookDirFix; - coord_t pendingOriginFix[3]; - coord_t pendingMomFix[3]; + thid_t clMobjId; + float forwardMove; + float sideMove; + int angle; + angle_t turnDelta; + int friction; + int pendingFixes; + thid_t pendingFixTargetClMobjId; + angle_t pendingAngleFix; + float pendingLookDirFix; + coord_t pendingOriginFix[3]; + coord_t pendingMomFix[3]; } clplayerstate_t; -extern float pspMoveSpeed; -extern float cplrThrustMul; +DENG_EXTERN_C float pspMoveSpeed; +DENG_EXTERN_C float cplrThrustMul; -void Cl_InitPlayers(void); +/** + * Clears the player state table. + */ +void Cl_InitPlayers(); /** * Used in DEMOS. (Not in regular netgames.) * Applies the given dx and dy to the local player's coordinates. * - * @param dx Viewpoint X delta. - * @param dy Viewpoint Y delta. - * @param z Viewpoint absolute Z coordinate. - * @param onground If @c true the mobj's Z will be set to floorz, and - * the player's viewheight is set so that the viewpoint - * height is param 'z'. - * If @c false the mobj's Z will be param 'z' and - * viewheight is zero. + * @param dx Viewpoint X delta. + * @param dy Viewpoint Y delta. + * @param z Viewpoint absolute Z coordinate. + * @param onground If @c true the mobj's Z will be set to floorz, and the player's + * viewheight is set so that the viewpoint height is param 'z'. + * If @c false the mobj's Z will be param 'z' and viewheight is zero. */ -void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground); +void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, bool onground); /** * Move the (hidden, unlinked) client player mobj to the same coordinates @@ -74,15 +67,26 @@ void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground); */ void ClPlayer_UpdateOrigin(int plrnum); -void ClPlayer_HandleFix(void); -void ClPlayer_ApplyPendingFixes(int plrNum); -void ClPlayer_ReadDelta2(boolean skip); +void ClPlayer_HandleFix(); + +void ClPlayer_ApplyPendingFixes(int plrNum); + +/** + * Reads a single PSV_FRAME2 player delta from the message buffer and + * applies it to the player in question. + */ +void ClPlayer_ReadDelta(); + clplayerstate_t *ClPlayer_State(int plrNum); -mobj_t *ClPlayer_LocalGameMobj(int plrNum); -boolean ClPlayer_IsFreeToMove(int plrnum); -#ifdef __cplusplus -} // extern "C" -#endif +/** + * Returns the gameside local mobj of a player. + */ +mobj_t *ClPlayer_LocalGameMobj(int plrNum); + +/** + * Returns @c true iff the player is free to move according to floorz and ceilingz. + */ +bool ClPlayer_IsFreeToMove(int plrnum); #endif // DENG_CLIENT_PLAYER_H diff --git a/doomsday/client/include/client/cl_sound.h b/doomsday/client/include/client/cl_sound.h index d1c2e2aaf0..8170189cd6 100644 --- a/doomsday/client/include/client/cl_sound.h +++ b/doomsday/client/include/client/cl_sound.h @@ -1,4 +1,4 @@ -/** @file +/** @file cl_sound.h Clientside sounds. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2007-2013 Daniel Swanson @@ -17,24 +17,17 @@ * http://www.gnu.org/licenses */ -/** - * cl_sound.h: Clientside Sounds - */ - -#ifndef __DOOMSDAY_CLIENT_SOUND_H__ -#define __DOOMSDAY_CLIENT_SOUND_H__ +#ifndef DENG_CLIENT_SOUND_H +#define DENG_CLIENT_SOUND_H #include "network/protocol.h" -#ifdef __cplusplus -extern "C" { -#endif - -void Cl_ReadSoundDelta2(deltatype_t type, boolean skip); -void Cl_Sound(void); +/** + * Read a sound delta from the message buffer and play it. + * Only used with PSV_FRAME2 packets. + */ +void Cl_ReadSoundDelta(deltatype_t type); -#ifdef __cplusplus -} // extern "C" -#endif +void Cl_Sound(); -#endif +#endif // DENG_CLIENT_SOUND_H diff --git a/doomsday/client/include/client/cl_world.h b/doomsday/client/include/client/cl_world.h index b7c66b9028..366a2b3f4b 100644 --- a/doomsday/client/include/client/cl_world.h +++ b/doomsday/client/include/client/cl_world.h @@ -1,4 +1,4 @@ -/** @file +/** @file cl_world.h Clientside world management. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2006-2013 Daniel Swanson @@ -17,58 +17,53 @@ * http://www.gnu.org/licenses */ -/** - * cl_world.h: Clientside World Management - */ - -#ifndef __DOOMSDAY_CLIENT_WORLD_H__ -#define __DOOMSDAY_CLIENT_WORLD_H__ - -#ifdef __cplusplus -extern "C" { -#endif +#ifndef DENG_CLIENT_WORLD_MAP_H +#define DENG_CLIENT_WORLD_MAP_H /** * Clears the arrays that track active plane and polyobj mover thinkers. */ -void Cl_WorldInit(void); +void Cl_WorldInit(); /** * Removes all the active movers. */ -void Cl_WorldReset(void); +void Cl_WorldReset(); /** * Handles the PSV_MATERIAL_ARCHIVE packet sent by the server. The list of * materials is stored until the client disconnects. */ -void Cl_ReadServerMaterials(void); +void Cl_ReadServerMaterials(); /** * Handles the PSV_MOBJ_TYPE_ID_LIST packet sent by the server. */ -void Cl_ReadServerMobjTypeIDs(void); +void Cl_ReadServerMobjTypeIDs(); /** * Handles the PSV_MOBJ_STATE_ID_LIST packet sent by the server. */ -void Cl_ReadServerMobjStateIDs(void); +void Cl_ReadServerMobjStateIDs(); int Cl_LocalMobjType(int serverMobjType); int Cl_LocalMobjState(int serverMobjState); void Cl_SetPolyMover(uint number, int move, int rotate); -void Cl_ReadSectorDelta2(int deltaType, boolean skip); -void Cl_ReadSideDelta2(int deltaType, boolean skip); -void Cl_ReadPolyDelta2(boolean skip); +/** + * Reads a sector delta from the PSV_FRAME2 message buffer and applies it to the world. + */ +void Cl_ReadSectorDelta(int deltaType); -int Cl_ReadSectorDelta(void); // obsolete -int Cl_ReadSideDelta(void); // obsolete -int Cl_ReadPolyDelta(void); // obsolete +/** + * Reads a side delta from the message buffer and applies it to the world. + */ +void Cl_ReadSideDelta(int deltaType); -#ifdef __cplusplus -} // extern "C" -#endif +/** + * Reads a poly delta from the message buffer and applies it to the world. + */ +void Cl_ReadPolyDelta(); -#endif +#endif // DENG_CLIENT_WORLD_MAP_H diff --git a/doomsday/client/include/world/map.h b/doomsday/client/include/world/map.h index 8ec1fc507d..be8f4068de 100644 --- a/doomsday/client/include/world/map.h +++ b/doomsday/client/include/world/map.h @@ -75,8 +75,8 @@ typedef enum { CPT_CEILING } clplanetype_t; -struct clplane_s; -struct clpolyobj_s; +struct clplane_t; +struct clpolyobj_t; #endif // __CLIENT__ @@ -167,8 +167,8 @@ class Map #ifdef __CLIENT__ cmhash_t clMobjHash[CLIENT_MOBJ_HASH_SIZE]; - struct clplane_s *clActivePlanes[CLIENT_MAX_MOVERS]; - struct clpolyobj_s *clActivePolyobjs[CLIENT_MAX_MOVERS]; + struct clplane_t *clActivePlanes[CLIENT_MAX_MOVERS]; + struct clpolyobj_t *clActivePolyobjs[CLIENT_MAX_MOVERS]; #endif coord_t _globalGravity; // The defined gravity for this map. @@ -691,26 +691,26 @@ class Map * * @return The new mover or @c NULL if arguments are invalid. */ - struct clplane_s *newClPlane(int sectorIdx, clplanetype_t type, coord_t dest, float speed); + struct clplane_t *newClPlane(int sectorIdx, clplanetype_t type, coord_t dest, float speed); - void deleteClPlane(struct clplane_s *mover); + void deleteClPlane(struct clplane_t *mover); - int clPlaneIndex(struct clplane_s *mover); + int clPlaneIndex(struct clplane_t *mover); - struct clplane_s *clPlaneBySectorIndex(int index, clplanetype_t type); + struct clplane_t *clPlaneBySectorIndex(int index, clplanetype_t type); bool isValidClPlane(int i); /** * @note Assumes there is no existing ClPolyobj for Polyobj @a index. */ - struct clpolyobj_s *newClPolyobj(int polyobjIndex); + struct clpolyobj_t *newClPolyobj(int polyobjIndex); - void deleteClPolyobj(struct clpolyobj_s *mover); + void deleteClPolyobj(struct clpolyobj_t *mover); - int clPolyobjIndex(struct clpolyobj_s *mover); + int clPolyobjIndex(struct clpolyobj_t *mover); - struct clpolyobj_s *clPolyobjByPolyobjIndex(int index); + struct clpolyobj_t *clPolyobjByPolyobjIndex(int index); bool isValidClPolyobj(int i); diff --git a/doomsday/client/src/client/cl_frame.cpp b/doomsday/client/src/client/cl_frame.cpp index 5bcee272a0..1773ce4fb9 100644 --- a/doomsday/client/src/client/cl_frame.cpp +++ b/doomsday/client/src/client/cl_frame.cpp @@ -118,7 +118,7 @@ void Cl_InitFrame(void) /** * Called when the map changes. */ -void Cl_ResetFrame(void) +void Cl_ResetFrame() { gotFrame = false; @@ -127,24 +127,13 @@ void Cl_ResetFrame(void) gotFirstFrame = false; } -float Cl_FrameGameTime(void) +float Cl_FrameGameTime() { return frameGameTime; } -/** - * Read a PSV_FRAME2/PSV_FIRST_FRAME2 packet. - */ void Cl_Frame2Received(int packetType) { - byte deltaType; - boolean skip = false; -#ifdef _NETDEBUG - int deltaCount = 0; - int startOffset; - int deltaLength; -#endif - // The first thing in the frame is the gameTime. frameGameTime = Reader_ReadFloat(msgReader); @@ -161,68 +150,65 @@ void Cl_Frame2Received(int packetType) return; } + // Read and process the message. + while(!Reader_AtEnd(msgReader)) { - // Read and process the message. - while(!Reader_AtEnd(msgReader)) - { - deltaType = Reader_ReadByte(msgReader); - skip = false; - - switch(deltaType) - { - case DT_CREATE_MOBJ: - // The mobj will be created/shown. - ClMobj_ReadDelta2(skip); - break; - - case DT_MOBJ: - // The mobj will be hidden if it's not yet Created. - ClMobj_ReadDelta2(skip); - break; - - case DT_NULL_MOBJ: - // The mobj will be removed. - ClMobj_ReadNullDelta2(skip); - break; - - case DT_PLAYER: - ClPlayer_ReadDelta2(skip); - break; - - case DT_SECTOR: - Cl_ReadSectorDelta2(deltaType, skip); - break; - - //case DT_SIDE_R6: // Old format. - case DT_SIDE: - Cl_ReadSideDelta2(deltaType, skip); - break; - - case DT_POLY: - Cl_ReadPolyDelta2(skip); - break; - - case DT_SOUND: - case DT_MOBJ_SOUND: - case DT_SECTOR_SOUND: - case DT_SIDE_SOUND: - case DT_POLY_SOUND: - Cl_ReadSoundDelta2((deltatype_t) deltaType, skip); - break; - - default: - LOG_NET_ERROR("Received unknown delta type %i (message size: %i bytes)") - << deltaType << netBuffer.length; - return; - } - } + byte const deltaType = Reader_ReadByte(msgReader); - if(!gotFrame) + switch(deltaType) { - LOGDEV_NET_NOTE("First frame received"); + case DT_CREATE_MOBJ: + // The mobj will be created/shown. + ClMobj_ReadDelta(); + break; + + case DT_MOBJ: + // The mobj will be hidden if it's not yet Created. + ClMobj_ReadDelta(); + break; + + case DT_NULL_MOBJ: + // The mobj will be removed. + ClMobj_ReadNullDelta(); + break; + + case DT_PLAYER: + ClPlayer_ReadDelta(); + break; + + case DT_SECTOR: + Cl_ReadSectorDelta(deltaType); + break; + + //case DT_SIDE_R6: // Old format. + case DT_SIDE: + Cl_ReadSideDelta(deltaType); + break; + + case DT_POLY: + Cl_ReadPolyDelta(); + break; + + case DT_SOUND: + case DT_MOBJ_SOUND: + case DT_SECTOR_SOUND: + case DT_SIDE_SOUND: + case DT_POLY_SOUND: + Cl_ReadSoundDelta((deltatype_t) deltaType); + break; + + default: + LOG_NET_ERROR("Received unknown delta type %i (message size: %i bytes)") + << deltaType << netBuffer.length; + return; } + } - // We have now received a frame. - gotFrame = true; + if(!gotFrame) + { + LOGDEV_NET_NOTE("First frame received"); } + + // We have now received a frame. + gotFrame = true; } diff --git a/doomsday/client/src/client/cl_infine.cpp b/doomsday/client/src/client/cl_infine.cpp index d9cdb820c8..4a69506fc3 100644 --- a/doomsday/client/src/client/cl_infine.cpp +++ b/doomsday/client/src/client/cl_infine.cpp @@ -1,4 +1,4 @@ -/** @file +/** @file cl_infine.cpp Clientside InFine. * * @authors Copyright © 2003-2010 Jaakko Keränen * @authors Copyright © 2006-2010 Daniel Swanson @@ -17,29 +17,27 @@ * http://www.gnu.org/licenses */ -/** - * Client-side InFine. - */ #include "de_base.h" +#include "client/cl_infine.h" + #include "de_console.h" #include "de_infine.h" -#include "client/cl_infine.h" #include "network/net_main.h" #include "network/net_msg.h" static finaleid_t currentFinale = 0; static finaleid_t remoteFinale = 0; -finaleid_t Cl_CurrentFinale(void) +finaleid_t Cl_CurrentFinale() { return currentFinale; } -void Cl_Finale(Reader* msg) +void Cl_Finale(Reader *msg) { int flags = Reader_ReadByte(msg); - byte* script = 0; + byte *script = 0; int len; finaleid_t finaleId = Reader_ReadUInt32(msg); @@ -81,7 +79,7 @@ void Cl_Finale(Reader* msg) if(script) free(script); } -void Cl_RequestFinaleSkip(void) +void Cl_RequestFinaleSkip() { // First the flags. Msg_Begin(PCL_FINALE_REQUEST); diff --git a/doomsday/client/src/client/cl_main.cpp b/doomsday/client/src/client/cl_main.cpp index d4d44f7ec7..b5dc0bbafc 100644 --- a/doomsday/client/src/client/cl_main.cpp +++ b/doomsday/client/src/client/cl_main.cpp @@ -1,4 +1,4 @@ -/** @file cl_main.cpp Network Client +/** @file cl_main.cpp Network client. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2006-2013 Daniel Swanson @@ -17,11 +17,9 @@ * http://www.gnu.org/licenses */ -#include -#include -#include - #include "de_base.h" +#include "client/cl_def.h" + #include "de_console.h" #include "de_system.h" #include "de_network.h" @@ -32,9 +30,11 @@ #include "world/map.h" #include "render/r_main.h" -using namespace de; +#include +#include +#include -extern int gotFrame; +using namespace de; ident_t clientID; boolean handshakeReceived = false; @@ -43,10 +43,10 @@ int serverTime; boolean netLoggedIn = false; // Logged in to the server. int clientPaused = false; // Set by the server. -void Cl_InitID(void) +void Cl_InitID() { - int i; - FILE* file; + int i; + FILE *file; if((i = CommandLine_CheckWith("-id", 1)) != 0) { @@ -79,7 +79,7 @@ void Cl_InitID(void) } } -int Cl_GameReady(void) +int Cl_GameReady() { return (handshakeReceived && gameReady); } @@ -240,11 +240,7 @@ void Cl_PlayerLeaves(int plrNum) gx.NetPlayerEvent(plrNum, DDPE_EXIT, 0); } -/** - * Client's packet handler. - * Handles all the events the server sends. - */ -void Cl_GetPackets(void) +void Cl_GetPackets() { // All messages come from the server. while(Net_GetPacket()) @@ -430,13 +426,8 @@ void Cl_Assertions(int plrNum) } } -/** - * Client-side game ticker. - */ void Cl_Ticker(timespan_t ticLength) { - int i; - if(!isClient || !Cl_GameReady() || clientPaused) return; @@ -446,7 +437,7 @@ void Cl_Ticker(timespan_t ticLength) // the changes from the server) to match the changes. The game ticker // has already been run when Cl_Ticker() is called, so let's update the // player's clmobj to its updated state. - for(i = 0; i < DDMAXPLAYERS; ++i) + for(int i = 0; i < DDMAXPLAYERS; ++i) { if(!ddPlayers[i].shared.inGame) continue; @@ -468,7 +459,7 @@ void Cl_Ticker(timespan_t ticLength) ClPlayer_ApplyPendingFixes(i); ClPlayer_UpdateOrigin(i); -#ifdef _DEBUG +#ifdef DENG_DEBUG Cl_Assertions(i); #endif } diff --git a/doomsday/client/src/client/cl_mobj.cpp b/doomsday/client/src/client/cl_mobj.cpp index 89ae114ecd..3fe3e636a8 100644 --- a/doomsday/client/src/client/cl_mobj.cpp +++ b/doomsday/client/src/client/cl_mobj.cpp @@ -643,24 +643,22 @@ static boolean ClMobj_IsStuckInsideLocalPlayer(mobj_t *mo) return false; // Not stuck. } -void ClMobj_ReadDelta2(boolean skip) +void ClMobj_ReadDelta() { - boolean needsLinking = false, justCreated = false; + bool needsLinking = false, justCreated = false; clmoinfo_t *info = 0; - mobj_t *mo = 0; - mobj_t *d; - static mobj_t dummy; - int df = 0; - byte moreFlags = 0, fastMom = false; - short mom; - thid_t id = Reader_ReadUInt16(msgReader); // Read the ID. - boolean onFloor = false; - mobj_t oldState; + mobj_t *mo = 0; + mobj_t *d; + short mom; + thid_t id = Reader_ReadUInt16(msgReader); // Read the ID. + bool onFloor = false; + mobj_t oldState; // Flags. - df = Reader_ReadUInt16(msgReader); + int df = Reader_ReadUInt16(msgReader); // More flags? + byte moreFlags = 0, fastMom = false; if(df & MDF_MORE_FLAGS) { moreFlags = Reader_ReadByte(msgReader); @@ -670,63 +668,54 @@ void ClMobj_ReadDelta2(boolean skip) fastMom = true; } - LOG_NET_XVERBOSE("Reading mobj delta for %i (df:0x%x edf:0x%x skip:%i)") - << id << df << moreFlags << skip; + LOG_NET_XVERBOSE("Reading mobj delta for %i (df:0x%x edf:0x%x)") + << id << df << moreFlags; - if(!skip) + // Get a mobj for this. + mo = ClMobj_Find(id); + info = ClMobj_GetInfo(mo); + if(!mo) { - // Get a mobj for this. - mo = ClMobj_Find(id); - info = ClMobj_GetInfo(mo); - if(!mo) - { - LOG_NET_XVERBOSE("Creating new clmobj %i (hidden)") << id; + LOG_NET_XVERBOSE("Creating new clmobj %i (hidden)") << id; - // This is a new ID, allocate a new mobj. - mo = ClMobj_Create(id); - info = ClMobj_GetInfo(mo); - justCreated = true; - needsLinking = true; + // This is a new ID, allocate a new mobj. + mo = ClMobj_Create(id); + info = ClMobj_GetInfo(mo); + justCreated = true; + needsLinking = true; - // Always create new mobjs as hidden. They will be revealed when - // we know enough about them. - info->flags |= CLMF_HIDDEN; - } + // Always create new mobjs as hidden. They will be revealed when + // we know enough about them. + info->flags |= CLMF_HIDDEN; + } - if(!(info->flags & CLMF_NULLED)) - { - // Now that we've received a delta, the mobj's Predictable again. - info->flags &= ~CLMF_UNPREDICTABLE; + if(!(info->flags & CLMF_NULLED)) + { + // Now that we've received a delta, the mobj's Predictable again. + info->flags &= ~CLMF_UNPREDICTABLE; - // This clmobj is evidently alive. - info->time = Timer_RealMilliseconds(); - } + // This clmobj is evidently alive. + info->time = Timer_RealMilliseconds(); + } - d = mo; + d = mo; - /*if(d->dPlayer && d->dPlayer == &ddPlayers[consolePlayer]) - { - // Mark the local player known. - cmo->flags |= CLMF_KNOWN; - }*/ + /*if(d->dPlayer && d->dPlayer == &ddPlayers[consolePlayer]) + { + // Mark the local player known. + cmo->flags |= CLMF_KNOWN; + }*/ - // Need to unlink? (Flags because DDMF_SOLID determines block-linking.) - if(df & (MDF_ORIGIN_X | MDF_ORIGIN_Y | MDF_ORIGIN_Z | MDF_FLAGS) && - !justCreated && !d->dPlayer) - { - needsLinking = true; - ClMobj_Unlink(mo); - } - } - else + // Need to unlink? (Flags because DDMF_SOLID determines block-linking.) + if(df & (MDF_ORIGIN_X | MDF_ORIGIN_Y | MDF_ORIGIN_Z | MDF_FLAGS) && + !justCreated && !d->dPlayer) { - // We're skipping. - d = &dummy; - info = 0; + needsLinking = true; + ClMobj_Unlink(mo); } // Remember where the mobj used to be in case we need to cancel a move. - memcpy(&oldState, d, sizeof(mobj_t)); + zap(oldState); // Coordinates with three bytes. if(df & MDF_ORIGIN_X) @@ -807,7 +796,7 @@ void ClMobj_ReadDelta2(boolean skip) // When local actions are allowed, the assumption is that // the client will be doing the state changes. - if(!skip && !(info->flags & CLMF_LOCAL_ACTIONS)) + if(!(info->flags & CLMF_LOCAL_ACTIONS)) { ClMobj_SetState(d, stateIdx); info->flags |= CLMF_KNOWN_STATE; @@ -847,14 +836,8 @@ void ClMobj_ReadDelta2(boolean skip) { d->type = Cl_LocalMobjType(Reader_ReadInt32(msgReader)); d->info = &mobjInfo[d->type]; - assert(d->info); } - // The delta has now been read. We can now skip if necessary. - if(skip) return; - - assert(d != &dummy); - // Is it time to remove the Hidden status? if(info->flags & CLMF_HIDDEN) { @@ -870,8 +853,7 @@ void ClMobj_ReadDelta2(boolean skip) // different than the server-side floor. if(!d->dPlayer && onFloor && gx.MobjCheckPositionXYZ) { - coord_t *floorZ = (coord_t *) gx.GetVariable(DD_TM_FLOOR_Z); - if(floorZ) + if(coord_t *floorZ = (coord_t *) gx.GetVariable(DD_TM_FLOOR_Z)) { gx.MobjCheckPositionXYZ(d, d->origin[VX], d->origin[VY], DDMAXFLOAT); d->origin[VZ] = d->floorZ = *floorZ; @@ -912,29 +894,23 @@ void ClMobj_ReadDelta2(boolean skip) } } -void ClMobj_ReadNullDelta2(boolean skip) +void ClMobj_ReadNullDelta() { - mobj_t *mo; - clmoinfo_t* info; - thid_t id; - // The delta only contains an ID. - id = Reader_ReadUInt16(msgReader); - - if(skip) - return; + thid_t id = Reader_ReadUInt16(msgReader); LOG_AS("Cl_ReadNullMobjDelta2"); LOGDEV_NET_XVERBOSE("Null %i") << id; - if((mo = ClMobj_Find(id)) == NULL) + mobj_t *mo = ClMobj_Find(id); + if(!mo) { // Wasted bandwidth... LOGDEV_NET_MSG("Request to remove id %i that doesn't exist here") << id; return; } - info = ClMobj_GetInfo(mo); + clmoinfo_t *info = ClMobj_GetInfo(mo); // Get rid of this mobj. if(!mo->dPlayer) diff --git a/doomsday/client/src/client/cl_player.cpp b/doomsday/client/src/client/cl_player.cpp index 7a7422de7c..186f6b5bb6 100644 --- a/doomsday/client/src/client/cl_player.cpp +++ b/doomsday/client/src/client/cl_player.cpp @@ -1,4 +1,4 @@ -/** @file cl_player.cpp Clientside Player Management. +/** @file cl_player.cpp Clientside player management. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2006-2013 Daniel Swanson @@ -17,9 +17,9 @@ * http://www.gnu.org/licenses */ -#include - #include "de_base.h" +#include "client/cl_player.h" + #include "de_console.h" #include "de_network.h" #include "de_play.h" @@ -28,6 +28,8 @@ #include "BspLeaf" +#include + using namespace de; #define TOP_PSPY (32) @@ -45,10 +47,7 @@ static float pspY; // Console player demo momentum (used to smooth out abrupt momentum changes). static float cpMom[3][LOCALCAM_WRITE_TICS]; -/** - * Clears the player state table. - */ -void Cl_InitPlayers(void) +void Cl_InitPlayers() { //fixTics = 0; pspY = 0; @@ -59,7 +58,7 @@ void Cl_InitPlayers(void) clplayerstate_t *ClPlayer_State(int plrNum) { - assert(plrNum >= 0 && plrNum < DDMAXPLAYERS); + DENG2_ASSERT(plrNum >= 0 && plrNum < DDMAXPLAYERS); return &clPlayerStates[plrNum]; } @@ -201,7 +200,7 @@ void ClPlayer_ApplyPendingFixes(int plrNum) } } -void ClPlayer_HandleFix(void) +void ClPlayer_HandleFix() { int plrNum = 0; int fixes = 0; @@ -262,7 +261,7 @@ void ClPlayer_HandleFix(void) ClPlayer_ApplyPendingFixes(plrNum); } -void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground) +void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, bool onground) { player_t *plr = &ddPlayers[consolePlayer]; ddplayer_t *ddpl = &plr->shared; @@ -308,20 +307,13 @@ void ClPlayer_MoveLocal(coord_t dx, coord_t dy, coord_t z, boolean onground) ClPlayer_UpdateOrigin(consolePlayer); } -/** - * Reads a single PSV_FRAME2 player delta from the message buffer and - * applies it to the player in question. - */ -void ClPlayer_ReadDelta2(boolean skip) +void ClPlayer_ReadDelta() { - static player_t dummyPlayer; - static clplayerstate_t dummyClState; - - int df = 0, psdf, i, idx; - clplayerstate_t *s; - ddplayer_t *ddpl; - ddpsprite_t *psp; - unsigned short num, newId; + int df = 0, psdf, i, idx; + clplayerstate_t *s; + ddplayer_t *ddpl; + ddpsprite_t *psp; + ushort num, newId; LOG_AS("ClPlayer_ReadDelta2"); @@ -331,17 +323,8 @@ void ClPlayer_ReadDelta2(boolean skip) df |= Reader_ReadByte(msgReader); // Second byte is just flags. num &= 0xf; // Clear the upper bits of the number. - if(!skip) - { - s = &clPlayerStates[num]; - ddpl = &ddPlayers[num].shared; - } - else - { - // We're skipping, read the data into dummies. - s = &dummyClState; - ddpl = &dummyPlayer.shared; - } + s = &clPlayerStates[num]; + ddpl = &ddPlayers[num].shared; if(df & PDF_MOBJ) { @@ -351,12 +334,12 @@ void ClPlayer_ReadDelta2(boolean skip) // Make sure the 'new' mobj is different than the old one; // there will be linking problems otherwise. - if(!skip && newId != s->clMobjId) + if(newId != s->clMobjId) { // We are now changing the player's mobj. - mobj_t* clmo = 0; + mobj_t *clmo = 0; //clmoinfo_t* info = 0; - boolean justCreated = false; + bool justCreated = false; s->clMobjId = newId; @@ -410,7 +393,7 @@ void ClPlayer_ReadDelta2(boolean skip) << num << s->clMobjId << old << clmo->origin[VX] << clmo->origin[VY] << clmo->origin[VZ] << clmo->floorZ << clmo->ceilingZ; - LOGDEV_NET_VERBOSE("Player %i using mobj id %i") << (skip? -1 : num) << s->clMobjId; + LOGDEV_NET_VERBOSE("Player %i using mobj id %i") << num << s->clMobjId; } } @@ -437,7 +420,7 @@ void ClPlayer_ReadDelta2(boolean skip) } if(df & PDF_FILTER) { - unsigned int filter = Reader_ReadUInt32(msgReader); + uint filter = Reader_ReadUInt32(msgReader); ddpl->filterColor[CR] = (filter & 0xff) / 255.f; ddpl->filterColor[CG] = ((filter >> 8) & 0xff) / 255.f; @@ -489,23 +472,14 @@ void ClPlayer_ReadDelta2(boolean skip) } } -/** - * @return The gameside local mobj of a player. - */ mobj_t *ClPlayer_LocalGameMobj(int plrNum) { return ddPlayers[plrNum].shared.mo; } -/** - * Used by the client plane mover. - * - * @return @c true, if the player is free to move according to - * floorz and ceilingz. - */ -boolean ClPlayer_IsFreeToMove(int plrNum) +bool ClPlayer_IsFreeToMove(int plrNum) { - mobj_t* mo = ClPlayer_LocalGameMobj(plrNum); + mobj_t *mo = ClPlayer_LocalGameMobj(plrNum); if(!mo) return false; return (mo->origin[VZ] >= mo->floorZ && diff --git a/doomsday/client/src/client/cl_sound.cpp b/doomsday/client/src/client/cl_sound.cpp index 82dca2c0e7..f193c3e525 100644 --- a/doomsday/client/src/client/cl_sound.cpp +++ b/doomsday/client/src/client/cl_sound.cpp @@ -1,4 +1,4 @@ -/** @file cl_sound.cpp Clientside Sounds. +/** @file cl_sound.cpp Clientside sounds. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2006-2013 Daniel Swanson @@ -18,35 +18,30 @@ */ #include "de_base.h" +#include "client/cl_sound.h" + #include "de_console.h" #include "de_network.h" #include "de_play.h" #include "de_audio.h" -#include "client/cl_sound.h" - using namespace de; -/** - * Read a sound delta from the message buffer and play it. - * Only used with PSV_FRAME2 packets. - */ -void Cl_ReadSoundDelta2(deltatype_t type, boolean skip) +void Cl_ReadSoundDelta(deltatype_t type) { - uint16_t deltaId = 0; int sound = 0, soundFlags = 0; - byte flags = 0; - mobj_t *cmo = NULL; - thid_t mobjId = 0; - Sector *sector = NULL; - Polyobj *poly = NULL; - LineSide *side = NULL; - mobj_t *emitter = NULL; - float volume = 1; + mobj_t *cmo = 0; + thid_t mobjId = 0; + Sector *sector = 0; + Polyobj *poly = 0; + LineSide *side = 0; + mobj_t *emitter = 0; + float volume = 1; - deltaId = Reader_ReadUInt16(msgReader); - flags = Reader_ReadByte(msgReader); + uint16_t deltaId = Reader_ReadUInt16(msgReader); + byte flags = Reader_ReadByte(msgReader); + bool skip = false; if(type == DT_SOUND) { // Delta ID is the sound ID. @@ -179,7 +174,7 @@ void Cl_ReadSoundDelta2(deltatype_t type, boolean skip) // Do we need to queue this sound? if(type == DT_MOBJ_SOUND && !cmo) { - clmoinfo_t* info = 0; + clmoinfo_t *info = 0; // Create a new Hidden clmobj. cmo = ClMobj_Create(mobjId); diff --git a/doomsday/client/src/client/cl_world.cpp b/doomsday/client/src/client/cl_world.cpp index b0eb73b14b..279723da12 100644 --- a/doomsday/client/src/client/cl_world.cpp +++ b/doomsday/client/src/client/cl_world.cpp @@ -1,5 +1,4 @@ -/** @file cl_world.cpp Clientside world management. - * @ingroup client +/** @file cl_world.cpp Clientside world management. * * @authors Copyright © 2003-2013 Jaakko Keränen * @authors Copyright © 2006-2013 Daniel Swanson @@ -19,52 +18,58 @@ * 02110-1301 USA */ -#include - #include "de_base.h" +#include "client/cl_world.h" + #include "de_console.h" #include "de_network.h" #include "de_play.h" #include "de_filesys.h" #include "de_defs.h" #include "de_misc.h" + #include "api_map.h" #include "api_materialarchive.h" #include "world/map.h" #include "world/thinkers.h" -#include "client/cl_world.h" + #include "r_util.h" +#include + using namespace de; #define MAX_TRANSLATIONS 16384 -#define MVF_CEILING 0x1 // Move ceiling. -#define MVF_SET_FLOORPIC 0x2 // Set floor texture when move done. +#define MVF_CEILING 0x1 ///< Move ceiling. +#define MVF_SET_FLOORPIC 0x2 ///< Set floor texture when move done. -typedef struct clplane_s { - thinker_t thinker; - int sectorIndex; +struct clplane_t +{ + thinker_t thinker; + int sectorIndex; clplanetype_t type; - int property; // floor or ceiling - int dmuPlane; - coord_t destination; - float speed; -} clplane_t; - -typedef struct clpolyobj_s { - thinker_t thinker; - int number; - Polyobj *polyobj; - boolean move; - boolean rotate; -} clpolyobj_t; - -typedef struct { + int property; ///< Floor or ceiling + int dmuPlane; + coord_t destination; + float speed; +}; + +struct clpolyobj_t +{ + thinker_t thinker; + int number; + Polyobj *polyobj; + boolean move; + boolean rotate; +}; + +struct indextranstable_t +{ int size; int *serverToLocal; -} indextranstable_t; +}; /** * Plane mover. Makes changes in planes using DMU. @@ -73,11 +78,11 @@ void Cl_MoverThinker(clplane_t *mover); void Cl_PolyMoverThinker(clpolyobj_t *mover); -static MaterialArchive* serverMaterials; +static MaterialArchive *serverMaterials; static indextranstable_t xlatMobjType; static indextranstable_t xlatMobjState; -void Cl_ReadServerMaterials(void) +void Cl_ReadServerMaterials() { LOG_AS("Cl_ReadServerMaterials"); @@ -90,12 +95,11 @@ void Cl_ReadServerMaterials(void) LOGDEV_NET_VERBOSE("Received %i materials") << MaterialArchive_Count(serverMaterials); } -static void setTableSize(indextranstable_t* table, int size) +static void setTableSize(indextranstable_t *table, int size) { if(size > 0) { - table->serverToLocal = (int*) M_Realloc(table->serverToLocal, - sizeof(*table->serverToLocal) * size); + table->serverToLocal = (int *) M_Realloc(table->serverToLocal, sizeof(*table->serverToLocal) * size); } else { @@ -105,19 +109,19 @@ static void setTableSize(indextranstable_t* table, int size) table->size = size; } -void Cl_ReadServerMobjTypeIDs(void) +void Cl_ReadServerMobjTypeIDs() { - int i; - StringArray* ar = StringArray_New(); + LOG_AS("Cl_ReadServerMobjTypeIDs"); + + StringArray *ar = StringArray_New(); StringArray_Read(ar, msgReader); - LOG_AS("Cl_ReadServerMobjTypeIDs"); LOGDEV_NET_VERBOSE("Received %i mobj type IDs") << StringArray_Size(ar); setTableSize(&xlatMobjType, StringArray_Size(ar)); // Translate the type IDs to local. - for(i = 0; i < StringArray_Size(ar); ++i) + for(int i = 0; i < StringArray_Size(ar); ++i) { xlatMobjType.serverToLocal[i] = Def_GetMobjNum(StringArray_At(ar, i)); if(xlatMobjType.serverToLocal[i] < 0) @@ -130,19 +134,19 @@ void Cl_ReadServerMobjTypeIDs(void) StringArray_Delete(ar); } -void Cl_ReadServerMobjStateIDs(void) +void Cl_ReadServerMobjStateIDs() { - int i; - StringArray* ar = StringArray_New(); + LOG_AS("Cl_ReadServerMobjStateIDs"); + + StringArray *ar = StringArray_New(); StringArray_Read(ar, msgReader); - LOG_AS("Cl_ReadServerMobjStateIDs"); LOGDEV_NET_VERBOSE("Received %i mobj state IDs") << StringArray_Size(ar); setTableSize(&xlatMobjState, StringArray_Size(ar)); // Translate the type IDs to local. - for(i = 0; i < StringArray_Size(ar); ++i) + for(int i = 0; i < StringArray_Size(ar); ++i) { xlatMobjState.serverToLocal[i] = Def_GetStateNum(StringArray_At(ar, i)); if(xlatMobjState.serverToLocal[i] < 0) @@ -221,8 +225,8 @@ void Cl_WorldInit() } serverMaterials = 0; - std::memset(&xlatMobjType, 0, sizeof(xlatMobjType)); - std::memset(&xlatMobjState, 0, sizeof(xlatMobjState)); + zap(xlatMobjType); + zap(xlatMobjState); } void Cl_WorldReset() @@ -300,17 +304,13 @@ void Map::deleteClPolyobj(clpolyobj_t *mover) void Cl_MoverThinker(clplane_t *mover) { + LOG_AS("Cl_MoverThinker"); + Map &map = App_World().map(); /// @todo Do not assume mover is from the CURRENT map. - coord_t original; - boolean remove = false; - boolean freeMove; - float fspeed; // Can we think yet? if(!Cl_GameReady()) return; - LOG_AS("Cl_MoverThinker"); - #ifdef _DEBUG if(map.clPlaneIndex(mover) < 0) { @@ -319,12 +319,13 @@ void Cl_MoverThinker(clplane_t *mover) #endif // The move is cancelled if the consolePlayer becomes obstructed. - freeMove = ClPlayer_IsFreeToMove(consolePlayer); - fspeed = mover->speed; + bool const freeMove = ClPlayer_IsFreeToMove(consolePlayer); + float const fspeed = mover->speed; // How's the gap? - original = P_GetDouble(DMU_SECTOR, mover->sectorIndex, mover->property); - if(fabs(fspeed) > 0 && fabs(mover->destination - original) > fabs(fspeed)) + bool remove = false; + coord_t const original = P_GetDouble(DMU_SECTOR, mover->sectorIndex, mover->property); + if(de::abs(fspeed) > 0 && de::abs(mover->destination - original) > de::abs(fspeed)) { // Do the move. P_SetDouble(DMU_SECTOR, mover->sectorIndex, mover->property, original + fspeed); @@ -388,7 +389,7 @@ clplane_t *Map::newClPlane(int sectorIndex, clplanetype_t type, coord_t dest, fl if(sectorIndex < 0 || sectorIndex >= sectorCount()) { - DENG_ASSERT(false); // Invalid Sector index. + DENG2_ASSERT(false); // Invalid Sector index. return 0; } @@ -415,17 +416,20 @@ clplane_t *Map::newClPlane(int sectorIndex, clplanetype_t type, coord_t dest, fl // Allocate a new clplane_t thinker. clplane_t *mov = clActivePlanes[i] = (clplane_t *) Z_Calloc(sizeof(clplane_t), PU_MAP, &clActivePlanes[i]); + mov->thinker.function = reinterpret_cast(Cl_MoverThinker); - mov->type = type; + mov->type = type; mov->sectorIndex = sectorIndex; mov->destination = dest; - mov->speed = speed; - mov->property = dmuPlane | DMU_HEIGHT; - mov->dmuPlane = dmuPlane; + mov->speed = speed; + mov->property = dmuPlane | DMU_HEIGHT; + mov->dmuPlane = dmuPlane; // Set the right sign for speed. if(mov->destination < P_GetDouble(DMU_SECTOR, sectorIndex, mov->property)) + { mov->speed = -mov->speed; + } // Update speed and target height. P_SetDouble(DMU_SECTOR, sectorIndex, dmuPlane | DMU_TARGET_HEIGHT, dest); @@ -434,7 +438,7 @@ clplane_t *Map::newClPlane(int sectorIndex, clplanetype_t type, coord_t dest, fl thinkers().add(mov->thinker, false /*not public*/); // Immediate move? - if(FEQUAL(speed, 0)) + if(de::fequal(speed, 0)) { // This will remove the thinker immediately if the move is ok. Cl_MoverThinker(mov); @@ -447,7 +451,7 @@ clplane_t *Map::newClPlane(int sectorIndex, clplanetype_t type, coord_t dest, fl void Cl_PolyMoverThinker(clpolyobj_t *mover) { - DENG_ASSERT(mover != 0); + DENG2_ASSERT(mover != 0); LOG_AS("Cl_PolyMoverThinker"); @@ -531,12 +535,14 @@ clpolyobj_t *Map::newClPolyobj(int polyobjIndex) LOG_MAP_XVERBOSE("New polymover [%i] for polyobj #%i.") << i << polyobjIndex; - clpolyobj_t *mover = (clpolyobj_t *) Z_Calloc(sizeof(clpolyobj_t), PU_MAP, &clActivePolyobjs[i]); - clActivePolyobjs[i] = mover; + clpolyobj_t *mover = clActivePolyobjs[i] = (clpolyobj_t *) Z_Calloc(sizeof(clpolyobj_t), PU_MAP, &clActivePolyobjs[i]); + mover->thinker.function = reinterpret_cast(Cl_PolyMoverThinker); mover->polyobj = polyobjs().at(polyobjIndex); - mover->number = polyobjIndex; + mover->number = polyobjIndex; + thinkers().add(mover->thinker, false /*not public*/); + return mover; } @@ -579,14 +585,8 @@ clplane_t *Map::clPlaneBySectorIndex(int sectorIndex, clplanetype_t type) return 0; } -/** - * Reads a sector delta from the PSV_FRAME2 message buffer and applies it - * to the world. - */ -void Cl_ReadSectorDelta2(int deltaType, boolean /*skip*/) +void Cl_ReadSectorDelta(int /*deltaType*/) { - DENG_UNUSED(deltaType); - /// @todo Do not assume the CURRENT map. Map &map = App_World().map(); @@ -696,13 +696,8 @@ void Cl_ReadSectorDelta2(int deltaType, boolean /*skip*/) #undef PLN_FLOOR } -/** - * Reads a side delta from the message buffer and applies it to the world. - */ -void Cl_ReadSideDelta2(int deltaType, boolean skip) +void Cl_ReadSideDelta(int /*deltaType*/) { - DENG_UNUSED(deltaType); - ushort num; int df, topMat = 0, midMat = 0, botMat = 0; @@ -755,12 +750,8 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip) if(df & SIDF_FLAGS) sideFlags = Reader_ReadByte(msgReader); - // Must we skip this? - if(skip) - return; - LineSide *side = App_World().map().sideByIndex(num); - DENG_ASSERT(side != 0); + DENG2_ASSERT(side != 0); if(df & SIDF_TOP_MATERIAL) { @@ -834,55 +825,47 @@ void Cl_ReadSideDelta2(int deltaType, boolean skip) } } -/** - * Reads a poly delta from the message buffer and applies it to - * the world. - */ -void Cl_ReadPolyDelta2(boolean skip) +void Cl_ReadPolyDelta() { - int df; - unsigned short num; - Polyobj *po; - float destX = 0, destY = 0; - float speed = 0; - int destAngle = 0, angleSpeed = 0; - - num = Reader_ReadPackedUInt16(msgReader); + ushort const index = Reader_ReadPackedUInt16(msgReader); // Flags. - df = Reader_ReadByte(msgReader); - - if(df & PODF_DEST_X) - destX = Reader_ReadFloat(msgReader); - if(df & PODF_DEST_Y) - destY = Reader_ReadFloat(msgReader); - if(df & PODF_SPEED) - speed = Reader_ReadFloat(msgReader); - if(df & PODF_DEST_ANGLE) - destAngle = ((angle_t)Reader_ReadInt16(msgReader)) << 16; - if(df & PODF_ANGSPEED) - angleSpeed = ((angle_t)Reader_ReadInt16(msgReader)) << 16; + int const df = Reader_ReadByte(msgReader); - if(skip) - return; - - po = App_World().map().polyobjs().at(num); + Polyobj *po = App_World().map().polyobjs().at(index); if(df & PODF_DEST_X) - po->dest[VX] = destX; + { + po->dest[VX] = Reader_ReadFloat(msgReader); + } + if(df & PODF_DEST_Y) - po->dest[VY] = destY; + { + po->dest[VY] = Reader_ReadFloat(msgReader); + } + if(df & PODF_SPEED) - po->speed = speed; + { + po->speed = Reader_ReadFloat(msgReader); + } + if(df & PODF_DEST_ANGLE) - po->destAngle = destAngle; + { + po->destAngle = ((angle_t)Reader_ReadInt16(msgReader)) << 16; + } + if(df & PODF_ANGSPEED) - po->angleSpeed = angleSpeed; + { + po->angleSpeed = ((angle_t)Reader_ReadInt16(msgReader)) << 16; + } + if(df & PODF_PERPETUAL_ROTATE) + { po->destAngle = -1; + } // Update the polyobj's mover thinkers. - Cl_SetPolyMover(num, df & (PODF_DEST_X | PODF_DEST_Y | PODF_SPEED), + Cl_SetPolyMover(index, df & (PODF_DEST_X | PODF_DEST_Y | PODF_SPEED), df & (PODF_DEST_ANGLE | PODF_ANGSPEED | PODF_PERPETUAL_ROTATE)); } diff --git a/doomsday/client/src/world/thinkers.cpp b/doomsday/client/src/world/thinkers.cpp index db891a1455..52cdd4698f 100644 --- a/doomsday/client/src/world/thinkers.cpp +++ b/doomsday/client/src/world/thinkers.cpp @@ -19,14 +19,8 @@ #define DENG_NO_API_MACROS_THINKER -#include -#include - -#include - #include "de_base.h" -#include "world/map.h" -#include "world/p_object.h" +#include "world/thinkers.h" #ifdef __CLIENT__ # include "client/cl_mobj.h" @@ -37,7 +31,12 @@ # include "server/sv_pool.h" #endif -#include "world/thinkers.h" +#include "world/map.h" +#include "world/p_object.h" + +#include +#include +#include boolean Thinker_IsMobjFunc(thinkfunc_t func) {