Skip to content

Commit

Permalink
Cleanup: Register 'listmobjtypes' in Def_ConsoleRegister() (def_main.…
Browse files Browse the repository at this point in the history
…cpp)
  • Loading branch information
danij-deng committed Jul 7, 2015
1 parent 37edd0b commit 6a57c3f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 75 deletions.
36 changes: 11 additions & 25 deletions doomsday/apps/client/include/def_main.h
Expand Up @@ -20,13 +20,12 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_DEFINITIONS_MAIN_H
#define LIBDENG_DEFINITIONS_MAIN_H
#ifndef DEFINITIONS_MAIN_H
#define DEFINITIONS_MAIN_H

#include <vector>
#include <doomsday/defs/ded.h>
#include <doomsday/defs/dedtypes.h>
#include <de/stringarray.h>
#include "Material"

template <typename PODType>
Expand Down Expand Up @@ -132,6 +131,11 @@ extern RuntimeDefs runtimeDefs;
*/
void Def_Init(void);

/**
* Register the console commands and/or variables of this module.
*/
void Def_ConsoleRegister(void);

/**
* Retrieves the XG Class list from the Game.
* XGFunc links are provided by the Game, who owns the actual
Expand Down Expand Up @@ -173,7 +177,7 @@ int Def_GetModelNum(char const *id);
int Def_GetMusicNum(char const *id);
int Def_GetSoundNum(char const *id);
ded_value_t *Def_GetValueById(char const *id);
ded_value_t *Def_GetValueByUri(Uri const *uri);
ded_value_t *Def_GetValueByUri(uri_s const *uri);
ded_compositefont_t *Def_GetCompositeFont(char const *uri);
ded_light_t *Def_GetLightDef(int spr, int frame);

Expand All @@ -187,7 +191,7 @@ int Def_GetStateNum(de::String const &id);

spritenum_t Def_GetSpriteNum(de::String const &name);

ded_ptcgen_t *Def_GetGenerator(Uri const *uri);
ded_ptcgen_t *Def_GetGenerator(uri_s const *uri);
ded_ptcgen_t *Def_GetGenerator(de::Uri const &uri);

#ifdef __cplusplus
Expand Down Expand Up @@ -215,22 +219,6 @@ int Def_Set(int type, int index, int value, void const *ptr);
*/
dd_bool Def_SameStateSequence(state_t *snew, state_t *sold);

/**
* Compiles a list of all the defined mobj types. Indices in this list
* match those in the @c mobjInfo array.
*
* @return StringArray instance. Caller gets ownership.
*/
StringArray *Def_ListMobjTypeIDs(void);

/**
* Compiles a list of all the defined mobj states. Indices in this list
* match those in the @c states array.
*
* @return StringArray instance. Caller gets ownership.
*/
StringArray *Def_ListStateIDs(void);

/**
* Returns @c true iff @a def is compatible with the specified context.
*/
Expand All @@ -241,10 +229,8 @@ bool Def_IsAllowedReflection(ded_reflection_t const *def, /*bool hasExternal,*/
*/
bool Def_IsAllowedDetailTex(ded_detailtexture_t const *def, /*bool hasExternal,*/ bool isCustom);

D_CMD(ListMobjs);

#ifdef __cplusplus
} // extern "C"
} // extern "C"
#endif

#endif // LIBDENG_DEFINITIONS_MAIN_H
#endif // DEFINITIONS_MAIN_H
15 changes: 8 additions & 7 deletions doomsday/apps/client/src/client/cl_world.cpp
@@ -1,7 +1,7 @@
/** @file cl_world.cpp Clientside world management.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -21,19 +21,20 @@
#include "de_base.h"
#include "client/cl_world.h"

#include <QVector>
#include <de/stringarray.h>

#include "client/cl_player.h"

#include "api_map.h"
#include "api_materialarchive.h"

#include "network/net_msg.h"
#include "network/protocol.h"

#include "world/map.h"
#include "Sector"
#include "Surface"

#include <QVector>
#include "network/net_msg.h"
#include "network/protocol.h"

#include "api_materialarchive.h"

using namespace de;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -3184,14 +3184,14 @@ static void consoleRegister()
C_CMD("reset", "", Reset);
C_CMD("reload", "", ReloadGame);
C_CMD("unload", "*", Unload);
C_CMD("listmobjtypes", "", ListMobjs);
C_CMD("write", "s", WriteConsole);

#ifdef DENG2_DEBUG
C_CMD("fatalerror", nullptr, DebugError);
#endif

DD_RegisterLoop();
Def_ConsoleRegister();
FS1::consoleRegister();
Con_Register();
Games::consoleRegister();
Expand Down
26 changes: 6 additions & 20 deletions doomsday/apps/client/src/def_main.cpp
Expand Up @@ -30,6 +30,7 @@
#include <de/App>
#include <de/NativePath>
#include <de/RecordValue>
#include <doomsday/console/cmd.h>
#include <doomsday/defs/decoration.h>
#include <doomsday/defs/dedfile.h>
#include <doomsday/defs/dedparser.h>
Expand Down Expand Up @@ -2131,26 +2132,6 @@ int Def_Set(int type, int index, int value, void const *ptr)
return true;
}

StringArray *Def_ListMobjTypeIDs()
{
StringArray *array = StringArray_New();
for(int i = 0; i < defs.things.size(); ++i)
{
StringArray_Append(array, defs.things[i].gets("id").toUtf8());
}
return array;
}

StringArray *Def_ListStateIDs()
{
StringArray *array = StringArray_New();
for(int i = 0; i < defs.states.size(); ++i)
{
StringArray_Append(array, defs.states[i].gets("id").toUtf8());
}
return array;
}

bool Def_IsAllowedReflection(ded_reflection_t const *def, /*bool hasExternal,*/ bool isCustom)
{
//if(hasExternal) return (def->flags & REFF_EXTERNAL) != 0;
Expand Down Expand Up @@ -2192,6 +2173,11 @@ D_CMD(ListMobjs)
return true;
}

void Def_ConsoleRegister()
{
C_CMD("listmobjtypes", "", ListMobjs);
}

DENG_DECLARE_API(Def) =
{
{ DE_API_DEFINITIONS },
Expand Down
80 changes: 58 additions & 22 deletions doomsday/apps/server/src/server/sv_main.cpp
@@ -1,8 +1,8 @@
/** @file sv_main.cpp Network server.
/** @file sv_main.cpp Network server.
* @ingroup server
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -18,7 +18,7 @@
* http://www.gnu.org/licenses</small>
*/

#include <math.h>
#include <cmath>

#define DENG_NO_API_MACROS_SERVER
#include "api_server.h"
Expand All @@ -34,6 +34,7 @@

#include "api_materialarchive.h"

#include <de/stringarray.h>
#include <de/ArrayValue>
#include <de/NumberValue>
#include <de/Log>
Expand Down Expand Up @@ -758,20 +759,51 @@ void Sv_PlayerLeaves(unsigned int nodeID)
}

/**
* The player will be sent the introductory handshake packets.
* Compiles a list of all the defined thing types. Indices in this list match those
* in the @c mobjInfo array.
*
* @return StringArray instance. Caller gets ownership.
*/
void Sv_Handshake(int plrNum, dd_bool newPlayer)
static StringArray *listThingTypeIDs()
{
StringArray* ar;
int i;
uint playersInGame = 0;
StringArray *array = StringArray_New();
for(dint i = 0; i < defs.things.size(); ++i)
{
StringArray_Append(array, defs.things[i].gets("id").toUtf8());
}
return array;
}

/**
* Compiles a list of all the defined mobj states. Indices in this list match those
* in the @c states array.
*
* @return StringArray instance. Caller gets ownership.
*/
static StringArray *listStateIDs()
{
StringArray *array = StringArray_New();
for(dint i = 0; i < defs.states.size(); ++i)
{
StringArray_Append(array, defs.states[i].gets("id").toUtf8());
}
return array;
}

/**
* The player will be sent the introductory handshake packets.
*/
void Sv_Handshake(dint plrNum, dd_bool newPlayer)
{
LOG_AS("Sv_Handshake");
LOG_NET_VERBOSE("Shaking hands with player %i (newPlayer:%b)") << plrNum << newPlayer;

for(i = 0; i < DDMAXPLAYERS; ++i)
duint playersInGame = 0;
for(dint i = 0; i < DDMAXPLAYERS; ++i)
{
if(clients[i].connected)
playersInGame |= 1 << i;
}

Msg_Begin(PSV_HANDSHAKE);
Writer_WriteByte(msgWriter, SV_VERSION);
Expand All @@ -788,20 +820,24 @@ void Sv_Handshake(int plrNum, dd_bool newPlayer)
Net_SendBuffer(plrNum, 0);

// Include the list of thing Ids.
ar = Def_ListMobjTypeIDs();
Msg_Begin(PSV_MOBJ_TYPE_ID_LIST);
StringArray_Write(ar, msgWriter);
Msg_End();
Net_SendBuffer(plrNum, 0);
StringArray_Delete(ar);
{
StringArray *ar = listThingTypeIDs();
Msg_Begin(PSV_MOBJ_TYPE_ID_LIST);
StringArray_Write(ar, msgWriter);
Msg_End();
Net_SendBuffer(plrNum, 0);
StringArray_Delete(ar);
}

// Include the list of state Ids.
ar = Def_ListStateIDs();
Msg_Begin(PSV_MOBJ_STATE_ID_LIST);
StringArray_Write(ar, msgWriter);
Msg_End();
Net_SendBuffer(plrNum, 0);
StringArray_Delete(ar);
{
StringArray *ar = listStateIDs();
Msg_Begin(PSV_MOBJ_STATE_ID_LIST);
StringArray_Write(ar, msgWriter);
Msg_End();
Net_SendBuffer(plrNum, 0);
StringArray_Delete(ar);
}

if(newPlayer)
{
Expand All @@ -813,7 +849,7 @@ void Sv_Handshake(int plrNum, dd_bool newPlayer)
gx.NetWorldEvent(DDWE_HANDSHAKE, plrNum, (void *) &newPlayer);

// Propagate client information.
for(i = 0; i < DDMAXPLAYERS; ++i)
for(dint i = 0; i < DDMAXPLAYERS; ++i)
{
if(clients[i].connected)
{
Expand Down

0 comments on commit 6a57c3f

Please sign in to comment.