Skip to content

Commit

Permalink
Map|Client: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jan 11, 2014
1 parent 3ce88f8 commit a0d050e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 30 deletions.
12 changes: 6 additions & 6 deletions doomsday/api/api_thinker.h
Expand Up @@ -45,9 +45,9 @@ typedef void (*thinkfunc_t) (void *);
*/
typedef struct thinker_s {
struct thinker_s *prev, *next;
thinkfunc_t function;
dd_bool inStasis;
thid_t id; ///< Only used for mobjs (zero is not an ID).
thinkfunc_t function;
dd_bool inStasis;
thid_t id; ///< Only used for mobjs (zero is not an ID).
} thinker_t;

DENG_API_TYPEDEF(Thinker)
Expand All @@ -56,8 +56,8 @@ DENG_API_TYPEDEF(Thinker)

void (*Init)(void);
void (*Run)(void);
void (*Add)(thinker_t* th);
void (*Remove)(thinker_t* th);
void (*Add)(thinker_t *th);
void (*Remove)(thinker_t *th);

/**
* Change the 'in stasis' state of a thinker (stop it from thinking).
Expand All @@ -67,7 +67,7 @@ DENG_API_TYPEDEF(Thinker)
*/
void (*SetStasis)(thinker_t *th, dd_bool on);

int (*Iterate)(thinkfunc_t func, int (*callback) (thinker_t*, void*), void* context);
int (*Iterate)(thinkfunc_t func, int (*callback) (thinker_t *, void *), void *context);
}
DENG_API_T(Thinker);

Expand Down
9 changes: 6 additions & 3 deletions doomsday/client/include/client/cl_mobj.h
Expand Up @@ -67,6 +67,11 @@ struct ClMobjInfo
uint endMagic; // The client mobj magic number (CLM_MAGIC2).

ClMobjInfo();

/**
* Returns the mobj_t instance associated with the client mobj.
*/
mobj_t *mobj();
};

/**
Expand All @@ -79,8 +84,6 @@ void Cl_UpdateRealPlayerMobj(mobj_t *localMobj, mobj_t *remoteClientMobj, int fl

ClMobjInfo *ClMobj_GetInfo(mobj_t *mo);

mobj_t *ClMobj_MobjForInfo(ClMobjInfo *info);

/**
* Call for Hidden client mobjs to make then visible.
* If a sound is waiting, it's now played.
Expand Down Expand Up @@ -132,6 +135,6 @@ void ClMobj_ReadNullDelta();
*
* @return @c true, if the mobj is a client mobj; otherwise @c false.
*/
dd_bool Cl_IsClientMobj(mobj_t *mo); // public
dd_bool Cl_IsClientMobj(mobj_t *mo);

#endif // DENG_CLIENT_WORLD_MOBJ_H
2 changes: 1 addition & 1 deletion doomsday/client/include/world/map.h
Expand Up @@ -794,7 +794,7 @@ class Map
void deleteClMobj(mobj_t *mo);

/**
* Iterate all client mobjs, making a callback for each. Iteration ends if
* Iterate all client mobjs, making a callback for each. Iteration ends if a
* callback returns a non-zero value.
*
* @param callback Function to callback for each client mobj.
Expand Down
7 changes: 5 additions & 2 deletions doomsday/client/src/client/cl_main.cpp
Expand Up @@ -376,9 +376,10 @@ void Cl_GetPackets()
}
}

#ifdef DENG_DEBUG

/**
* Check the state of the client on engineside. This is a debugging utility
* and only gets called when _DEBUG is defined.
* Check the state of the client on engineside. A debugging utility.
*/
static void assertPlayerIsValid(int plrNum)
{
Expand Down Expand Up @@ -417,6 +418,8 @@ static void assertPlayerIsValid(int plrNum)
}
}

#endif // DENG_DEBUG

void Cl_Ticker(timespan_t ticLength)
{
if(!isClient || !Cl_GameReady() || clientPaused)
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/src/client/cl_mobj.cpp
Expand Up @@ -33,7 +33,6 @@

#include "world/map.h"
#include "world/p_players.h"
#include "world/thinkers.h"

#include "api_sound.h"

Expand All @@ -58,12 +57,12 @@ ClMobjInfo::ClMobjInfo()
, endMagic (CLM_MAGIC2)
{}

mobj_t *ClMobj_MobjForInfo(ClMobjInfo *info)
mobj_t *ClMobjInfo::mobj()
{
DENG2_ASSERT(info->startMagic == CLM_MAGIC1);
DENG2_ASSERT(info->endMagic == CLM_MAGIC2);
DENG2_ASSERT(startMagic == CLM_MAGIC1);
DENG2_ASSERT(endMagic == CLM_MAGIC2);

return (mobj_t *) ((char *)info + sizeof(ClMobjInfo));
return reinterpret_cast<mobj_t *>((char *)this + sizeof(ClMobjInfo));
}

void ClMobj_Unlink(mobj_t *mo)
Expand Down Expand Up @@ -239,6 +238,7 @@ dd_bool ClMobj_IsValid(mobj_t *mo)

ClMobjInfo *ClMobj_GetInfo(mobj_t *mo)
{
DENG2_ASSERT(mo != 0);
ClMobjInfo *info = (ClMobjInfo *) ((char *)mo - sizeof(ClMobjInfo));
if(!mo || info->startMagic != CLM_MAGIC1 || info->endMagic != CLM_MAGIC2)
{
Expand Down Expand Up @@ -622,7 +622,7 @@ mobj_t *ClMobj_Find(thid_t id)
}

// cl_player.c
DENG_EXTERN_C mobj_t* ClPlayer_ClMobj(int plrNum);
DENG_EXTERN_C mobj_t *ClPlayer_ClMobj(int plrNum);

DENG_DECLARE_API(Client) =
{
Expand Down
7 changes: 0 additions & 7 deletions doomsday/client/src/client/cl_world.cpp
Expand Up @@ -21,10 +21,7 @@
#include "de_base.h"
#include "client/cl_world.h"

#include "client/cl_def.h"
#include "client/cl_player.h"
#include "client/clplanemover.h"
#include "client/clpolymover.h"

#include "api_map.h"
#include "api_materialarchive.h"
Expand All @@ -34,12 +31,8 @@

#include "Surface"
#include "world/map.h"
#include "world/p_players.h"
#include "world/thinkers.h"

#include <de/memoryzone.h>
#include <QVector>
#include <cmath>

using namespace de;

Expand Down
14 changes: 9 additions & 5 deletions doomsday/client/src/client/clmobjhash.cpp
Expand Up @@ -32,10 +32,12 @@ void ClMobjHash::clear()
for(int i = 0; i < SIZE; ++i)
for(ClMobjInfo *info = _buckets[i].first; info; info = info->next)
{
mobj_t *mo = ClMobj_MobjForInfo(info);
mobj_t *mo = info->mobj();
// Players' clmobjs are not linked anywhere.
if(!mo->dPlayer)
{
ClMobj_Unlink(mo);
}
}
}

Expand Down Expand Up @@ -106,9 +108,11 @@ mobj_t *ClMobjHash::find(thid_t id) const
Bucket const &bucket = bucketFor(id);
for(ClMobjInfo *info = bucket.first; info; info = info->next)
{
mobj_t *mo = ClMobj_MobjForInfo(info);
mobj_t *mo = info->mobj();
if(mo->thinker.id == id)
{
return mo;
}
}

// Not found!
Expand All @@ -123,7 +127,7 @@ int ClMobjHash::iterate(int (*callback) (mobj_t *, void *), void *context)
while(info)
{
ClMobjInfo *next = info->next;
if(int result = callback(ClMobj_MobjForInfo(info), context))
if(int result = callback(info->mobj(), context))
return result;
info = next;
}
Expand All @@ -139,11 +143,11 @@ void ClMobjHash::assertValid() const
int count1 = 0, count2 = 0;
for(ClMobjInfo *info = _buckets[i].first; info; info = info->next, count1++)
{
DENG2_ASSERT(ClMobj_MobjForInfo(info) != 0);
DENG2_ASSERT(info->mobj() != 0);
}
for(ClMobjInfo *info = _buckets[i].last; info; info = info->prev, count2++)
{
DENG2_ASSERT(ClMobj_MobjForInfo(info) != 0);
DENG2_ASSERT(info->mobj() != 0);
}
DENG2_ASSERT(count1 == count2);
}
Expand Down

0 comments on commit a0d050e

Please sign in to comment.