Skip to content

Commit

Permalink
Refactor|GameMap: Reworked GameMap_* funcs for thinkers/clmovers into…
Browse files Browse the repository at this point in the history
… class methods
  • Loading branch information
danij-deng committed Jun 6, 2013
1 parent f56ae7c commit 7dda063
Show file tree
Hide file tree
Showing 18 changed files with 435 additions and 459 deletions.
17 changes: 13 additions & 4 deletions doomsday/api/api_client.h
Expand Up @@ -18,22 +18,31 @@ DENG_API_TYPEDEF(Client)
*
* @return Pointer to the mobj.
*/
struct mobj_s* (*Mobj_Find)(thid_t id);
struct mobj_s *(*Mobj_Find)(thid_t id);

/**
* Enables or disables local action function execution on the client.
*
* @param mo Client mobj.
* @param enable @c true to enable local actions, @c false to disable.
*/
void (*Mobj_EnableLocalActions)(struct mobj_s* mo, boolean enable);
void (*Mobj_EnableLocalActions)(struct mobj_s *mo, boolean enable);

/**
* Determines if local action functions are enabled for client mobj @a mo.
*/
boolean (*Mobj_LocalActionsEnabled)(struct mobj_s* mo);
boolean (*Mobj_LocalActionsEnabled)(struct mobj_s *mo);

boolean (*Mobj_IsValid)(struct mobj_s* mo);
/**
* Determines whether a client mobj is valid for playsim.
* The primary reason for it not to be valid is that we haven't received
* enough information about it yet.
*
* @param mo Mobj to check.
*
* @return @c true, if the mobj is a client mobj; otherwise @c false.
*/
boolean (*Mobj_IsValid)(struct mobj_s *mo);

struct mobj_s* (*Mobj_PlayerMobj)(int plrNum);
}
Expand Down
103 changes: 85 additions & 18 deletions doomsday/client/include/client/cl_mobj.h
Expand Up @@ -43,7 +43,7 @@
#define CLMF_KNOWN_Y 0x20000
#define CLMF_KNOWN_Z 0x40000
#define CLMF_KNOWN_STATE 0x80000
#define CLMF_KNOWN 0xf0000 // combination of all the KNOWN-flags
#define CLMF_KNOWN 0xf0000 ///< combination of all the KNOWN-flags

// Magic number for client mobj information.
#define CLM_MAGIC1 0xdecafed1
Expand All @@ -57,29 +57,85 @@
* 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).
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

void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int flags, boolean onFloor);
/**
* Make the real player mobj identical with the client mobj.
* The client mobj is always unlinked. Only the *real* mobj is visible.
* (The real mobj was created by the Game.)
*/
void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int flags,
boolean onFloor);

/**
* Create a new client mobj.
*
* Memory layout of a client mobj:
* - client mobj magic1 (4 bytes)
* - engineside clmobj info
* - client mobj magic2 (4 bytes)
* - gameside mobj (mobjSize bytes) <- this is returned from the function
*
* To check whether a given mobj_t is a clmobj_t, just check the presence of
* the client mobj magic number (by calling Cl_IsClientMobj()).
* The clmoinfo_s can then be accessed with ClMobj_GetInfo().
*
* @param id Identifier of the client mobj. Every client mobj has a unique
* identifier.
*
* @return Pointer to the gameside mobj.
*/
mobj_t *ClMobj_Create(thid_t id);

mobj_t *ClMobj_Create(thid_t id);
void ClMobj_Destroy(mobj_t *mo);
clmoinfo_t *ClMobj_GetInfo(mobj_t* mo);
mobj_t *ClMobj_MobjForInfo(clmoinfo_t* info);
void ClMobj_Unlink(mobj_t *cmo); // needed?
void ClMobj_Link(mobj_t *cmo); // needed?
void ClMobj_SetState(mobj_t *mo, int stnum); // needed?
void ClMobj_CheckPlanes(mobj_t *mo, boolean justCreated);
/**
* Destroys the client mobj. Before this is called, the client mobj should be
* unlinked from the thinker list (GameMap_ThinkerRemove).
*/
void ClMobj_Destroy(mobj_t *mo);

clmoinfo_t *ClMobj_GetInfo(mobj_t *mo);

mobj_t *ClMobj_MobjForInfo(clmoinfo_t *info);

/**
* Call for Hidden client mobjs to make then visible.
* If a sound is waiting, it's now played.
*
* @return @c true, if the mobj was revealed.
*/
boolean ClMobj_Reveal(mobj_t *cmo);

/**
* Unlinks the mobj from sectorlinks and if the object is solid,
* the blockmap.
*/
void ClMobj_Unlink(mobj_t *cmo); // needed?

/**
* Links the mobj into sectorlinks and if the object is solid, the
* blockmap. Linking to sectorlinks makes the mobj visible and linking
* to the blockmap makes it possible to interact with it (collide).
* If the client mobj is Hidden, it will not be linked anywhere.
*/
void ClMobj_Link(mobj_t *cmo); // needed?

/**
* Change the state of a mobj.
*
* @todo Should use the gameside function for this?
*/
void ClMobj_SetState(mobj_t *mo, int stnum); // needed?

/**
* Reads a single mobj delta (inside PSV_FRAME2 packet) from the message buffer
Expand All @@ -90,11 +146,22 @@ void ClMobj_CheckPlanes(mobj_t *mo, boolean justCreated);
*
* @param skip If @c true, all read data is ignored.
*/
void ClMobj_ReadDelta2(boolean skip);
void ClMobj_ReadDelta2(boolean skip);

void ClMobj_ReadNullDelta2(boolean skip);
/**
* Null mobjs deltas have their own type in a PSV_FRAME2 packet.
* Here we remove the mobj in question.
*/
void ClMobj_ReadNullDelta2(boolean skip);

boolean Cl_IsClientMobj(mobj_t* mo); // public
/**
* Determines whether a mobj is a client mobj.
*
* @param mo Mobj to check.
*
* @return @c true, if the mobj is a client mobj; otherwise @c false.
*/
boolean Cl_IsClientMobj(mobj_t *mo); // public

#ifdef __cplusplus
} // extern "C"
Expand Down
25 changes: 16 additions & 9 deletions doomsday/client/include/client/cl_world.h
Expand Up @@ -28,8 +28,15 @@
extern "C" {
#endif

void Cl_WorldInit(void);
void Cl_WorldReset(void);
/**
* Clears the arrays that track active plane and polyobj mover thinkers.
*/
void Cl_WorldInit(void);

/**
* Removes all the active movers.
*/
void Cl_WorldReset(void);

/**
* Handles the PSV_MATERIAL_ARCHIVE packet sent by the server. The list of
Expand All @@ -50,15 +57,15 @@ void Cl_ReadServerMobjStateIDs(void);
int Cl_LocalMobjType(int serverMobjType);
int Cl_LocalMobjState(int serverMobjState);

void Cl_SetPolyMover(uint number, int move, int rotate);
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);
void Cl_ReadSectorDelta2(int deltaType, boolean skip);
void Cl_ReadSideDelta2(int deltaType, boolean skip);
void Cl_ReadPolyDelta2(boolean skip);

int Cl_ReadSectorDelta(void); // obsolete
int Cl_ReadSideDelta(void); // obsolete
int Cl_ReadPolyDelta(void); // obsolete
int Cl_ReadSectorDelta(void); // obsolete
int Cl_ReadSideDelta(void); // obsolete
int Cl_ReadPolyDelta(void); // obsolete

#ifdef __cplusplus
} // extern "C"
Expand Down
151 changes: 85 additions & 66 deletions doomsday/client/include/map/gamemap.h
Expand Up @@ -483,13 +483,38 @@ class GameMap
*/
int clMobjIterator(int (*callback) (struct mobj_s *, void *), void *context);

void initClMovers();

void resetClMovers();

/**
* Allocate a new client-side plane mover.
*
* @return The new mover or @c NULL if arguments are invalid.
*/
struct clplane_s *newClPlane(uint sectornum, clplanetype_t type, coord_t dest, float speed);

void deleteClPlane(struct clplane_s *mover);

int clPlaneIndex(struct clplane_s *mover);

struct clplane_s *clPlaneBySectorIndex(uint sectorIndex, clplanetype_t type);

boolean isValidClPlane(int i);

/**
* @note Assumes there is no existing ClPolyobj for Polyobj @a index.
*/
struct clpolyobj_s *newClPolyobj(uint polyobjIndex);

void deleteClPolyobj(struct clpolyobj_s *mover);

int clPolyobjIndex(struct clpolyobj_s *mover);

struct clpolyobj_s *clPolyobjByPolyobjIndex(uint index);

boolean isValidClPolyobj(int i);

/**
* Returns the set of decorated surfaces for the map.
*/
Expand Down Expand Up @@ -554,6 +579,66 @@ class GameMap
*/
Line::Side *sideByIndex(int index) const;

/**
* Returns @c true iff the thinker lists been initialized.
*/
boolean thinkerListInited() const;

/**
* Init the thinker lists.
*
* @param flags @c 0x1 = Init public thinkers.
* @c 0x2 = Init private (engine-internal) thinkers.
*/
void initThinkerLists(byte flags);

/**
* Iterate the list of thinkers making a callback for each.
*
* @param thinkFunc If not @c NULL, only make a callback for thinkers
* whose function matches this.
* @param flags Thinker filter flags.
* @param callback The callback to make. Iteration will continue
* until a callback returns a non-zero value.
* @param context Passed to the callback function.
*/
int iterateThinkers(thinkfunc_t thinkFunc, byte flags,
int (*callback) (thinker_t *th, void *), void *context);

/**
* @param thinker Thinker to be added.
* @param makePublic @c true = @a thinker will be visible publically
* via the Doomsday public API thinker interface(s).
*/
void thinkerAdd(thinker_t &thinker, boolean makePublic);

/**
* Deallocation is lazy -- it will not actually be freed until its
* thinking turn comes up.
*/
void thinkerRemove(thinker_t &thinker);

/**
* Locates a mobj by it's unique identifier in the map.
*
* @param id Unique id of the mobj to lookup.
*/
struct mobj_s *mobjById(int id);

/// @todo Make private.
void clearMobjIds();

/**
* @param id Thinker id to test.
*/
boolean isUsedMobjId(thid_t id);

/**
* @param id New thinker id.
* @param inUse In-use state of @a id. @c true = the id is in use.
*/
void setMobjId(thid_t id, boolean inUse);

public: /// @todo Make private:

void finishMapElements();
Expand Down Expand Up @@ -660,72 +745,6 @@ class GameMap
DENG2_PRIVATE(d)
};

/**
* Have the thinker lists been initialized yet?
* @param map GameMap instance.
*/
boolean GameMap_ThinkerListInited(GameMap *map);

/**
* Init the thinker lists.
*
* @param map GameMap instance.
* @param flags @c 0x1 = Init public thinkers.
* @c 0x2 = Init private (engine-internal) thinkers.
*/
void GameMap_InitThinkerLists(GameMap *map, byte flags);

/**
* Iterate the list of thinkers making a callback for each.
*
* @param map GameMap instance.
* @param thinkFunc If not @c NULL, only make a callback for thinkers
* whose function matches this.
* @param flags Thinker filter flags.
* @param callback The callback to make. Iteration will continue
* until a callback returns a non-zero value.
* @param context Passed to the callback function.
*/
int GameMap_IterateThinkers(GameMap *map, thinkfunc_t thinkFunc, byte flags,
int (*callback) (thinker_t *th, void *), void *context);

/**
* @param map GameMap instance.
* @param thinker Thinker to be added.
* @param makePublic @c true = @a thinker will be visible publically
* via the Doomsday public API thinker interface(s).
*/
void GameMap_ThinkerAdd(GameMap *map, thinker_t *thinker, boolean makePublic);

/**
* Deallocation is lazy -- it will not actually be freed until its
* thinking turn comes up.
*
* @param map GameMap instance.
*/
void GameMap_ThinkerRemove(GameMap *map, thinker_t *thinker);

/**
* Locates a mobj by it's unique identifier in the map.
*
* @param map GameMap instance.
* @param id Unique id of the mobj to lookup.
*/
struct mobj_s *GameMap_MobjByID(GameMap *map, int id);

/**
* @param map GameMap instance.
* @param id Thinker id to test.
*/
boolean GameMap_IsUsedMobjID(GameMap* map, thid_t id);

/**
* @param map GameMap instance.
* @param id New thinker id.
* @param inUse In-use state of @a id. @c true = the id is in use.
*/
void GameMap_SetMobjID(GameMap *map, thid_t id, boolean inUse);

// The current map.
DENG_EXTERN_C GameMap *theMap;

Expand Down

0 comments on commit 7dda063

Please sign in to comment.