Skip to content

Commit

Permalink
Refactor: Moved ImpulseAccumulator to the World domain, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Nov 12, 2014
1 parent d79d3a8 commit 6c43c3e
Show file tree
Hide file tree
Showing 14 changed files with 626 additions and 633 deletions.
5 changes: 4 additions & 1 deletion doomsday/api/api_player.h
Expand Up @@ -196,10 +196,13 @@ DENG_API_TYPEDEF(Player)
void (*NewControl)(int id, impulsetype_t type, char const *name, char const *bindContext);

/**
* Determines if an impulse has been bound to anything.
* Determines if one or more bindings exist for a player and impulse Id in
* the associated binding context.
*
* @param playerNum Console/player number.
* @param impulseId Unique identifier of the impulse to lookup bindings for.
*
* @return @c true if one or more bindings exist.
*/
int (*IsControlBound)(int playerNum, int impulseId);

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/client.pro
Expand Up @@ -415,7 +415,6 @@ DENG_HEADERS += \
include/ui/joystick.h \
include/ui/mouse_qt.h \
include/ui/nativeui.h \
include/ui/playerimpulse.h \
include/ui/styledlogsinkformatter.h \
include/ui/sys_input.h \
include/ui/ui_main.h \
Expand Down Expand Up @@ -448,6 +447,7 @@ DENG_HEADERS += \
include/world/grabbable.h \
include/world/hand.h \
include/world/huecircle.h \
include/world/impulseaccumulator.h \
include/world/interceptor.h \
include/world/line.h \
include/world/lineblockmap.h \
Expand Down Expand Up @@ -717,7 +717,6 @@ SOURCES += \
src/ui/inputsystem.cpp \
src/ui/mouse_qt.cpp \
src/ui/nativeui.cpp \
src/ui/playerimpulse.cpp \
src/ui/progress.cpp \
src/ui/styledlogsinkformatter.cpp \
src/ui/sys_input.cpp \
Expand Down Expand Up @@ -773,6 +772,7 @@ SOURCES += \
src/world/grabbable.cpp \
src/world/hand.cpp \
src/world/huecircle.cpp \
src/world/impulseaccumulator.cpp \
src/world/interceptor.cpp \
src/world/line.cpp \
src/world/lineblockmap.cpp \
Expand Down
1 change: 0 additions & 1 deletion doomsday/client/include/de_play.h
Expand Up @@ -43,7 +43,6 @@
#include "world/p_players.h"
#include "world/thinkers.h"
#include "Material"
#include "ui/playerimpulse.h"
#include "r_util.h"

#include "api_map.h"
Expand Down
@@ -1,4 +1,4 @@
/** @file playerimpulse.h Player interaction impulse.
/** @file impulseaccumulator.h Player impulse accumulation.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
Expand All @@ -17,22 +17,18 @@
* http://www.gnu.org/licenses</small>
*/

#ifndef CLIENT_PLAY_PLAYERIMPULSE_H
#define CLIENT_PLAY_PLAYERIMPULSE_H
#ifndef CLIENT_PLAY_IMPULSEACCUMULATOR_H
#define CLIENT_PLAY_IMPULSEACCUMULATOR_H

#include <de/String>
#include "api_player.h"
#include "api_player.h" // impulsetype_t

/**
* Receives player interaction impulses and normalizes them for later consumption
* by the player Brain (on game side).
*
* @todo The player Brain should have ownership of it's ImpulseAccumulators.
*
* @todo Cleanup client/server confusion. On server side, each player will have a
* local model of a remote human player's impulses. However, Double-clicks can be
* handled entirely on client side. -ds
*
* @ingroup playsim
*/
class ImpulseAccumulator
Expand Down Expand Up @@ -82,7 +78,6 @@ class ImpulseAccumulator
* Register the console commands and variables of this module.
*/
static void consoleRegister();

#endif

private:
Expand All @@ -97,30 +92,9 @@ class ImpulseAccumulator
struct PlayerImpulse
{
int id = 0;
impulsetype_t type;
de::String name; ///< Symbolic. Used when resolving or generating textual binding descriptors.
de::String bindContextName; ///< Symbolic name of the associated binding context.

#ifdef __CLIENT__
/**
* Returns @c true if one or more bindings for this impulse exist, for the
* given @a localPlayer number in the associated BindContext.
*
* @param localPlayer Local player number.
*/
bool haveBindingsFor(int playerNumber) const;
#endif
impulsetype_t type = IT_ANALOG;
de::String name; ///< Symbolic. Used when resolving or generating textual binding descriptors.
de::String bindContextName; ///< Symbolic name of the associated binding context.
};

void P_ImpulseShutdown();

PlayerImpulse *P_ImpulsePtr(int id);

PlayerImpulse *P_ImpulseByName(de::String const &name);

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

#endif // CLIENT_PLAY_PLAYERIMPULSE_H
#endif // CLIENT_PLAY_IMPULSEACCUMULATOR_H
21 changes: 18 additions & 3 deletions doomsday/client/include/world/p_players.h
@@ -1,7 +1,7 @@
/** @file p_players.h World player entities.
/** @file p_players.h World player entities.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -59,6 +59,21 @@ float P_ShortToLookDir(short s);

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

#include <de/String>

struct PlayerImpulse;

void P_ClearPlayerImpulses();

PlayerImpulse *P_PlayerImpulsePtr(int id);

PlayerImpulse *P_PlayerImpulseByName(de::String const &name);

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

#endif // __cplusplus
#endif // DENG_WORLD_P_PLAYERS_H
7 changes: 5 additions & 2 deletions doomsday/client/src/con_config.cpp
Expand Up @@ -38,10 +38,13 @@

#ifdef __CLIENT__
# include "clientapp.h"

# include "world/impulseaccumulator.h"
# include "world/p_players.h"

# include "BindContext"
# include "CommandBinding"
# include "ImpulseBinding"
# include "ui/playerimpulse.h"
#endif

using namespace de;
Expand Down Expand Up @@ -222,7 +225,7 @@ static bool writeBindingsState(Path const &filePath)
context.forAllImpulseBindings([&file, &context] (Record &rec)
{
ImpulseBinding bind(rec);
PlayerImpulse const *impulse = P_ImpulsePtr(bind.geti("impulseId"));
PlayerImpulse const *impulse = P_PlayerImpulsePtr(bind.geti("impulseId"));
DENG2_ASSERT(impulse);

fprintf(file, "bindcontrol local%i-%s \"%s\"\n",
Expand Down
5 changes: 2 additions & 3 deletions doomsday/client/src/dd_main.cpp
Expand Up @@ -56,7 +56,6 @@
#include "world/worldsystem.h"
#include "world/map.h"
#include "ui/infine/infinesystem.h"
#include "ui/playerimpulse.h"
#include "ui/progress.h"
#include "ui/nativeui.h"

Expand Down Expand Up @@ -1513,7 +1512,7 @@ bool App_ChangeGame(Game &game, bool allowReload)
#ifdef __CLIENT__
R_ClearViewData();
R_DestroyContactLists();
P_ImpulseShutdown();
P_ClearPlayerImpulses();

Con_Execute(CMDS_DDAY, "clearbindings", true, false);
ClientApp::inputSystem().bindDefaults();
Expand Down Expand Up @@ -3284,7 +3283,7 @@ static void consoleRegister()
GL_Register();
UI_Register();
Demo_Register();
P_ImpulseConsoleRegister();
P_ConsoleRegister();
I_Register();
#endif

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_pinit.cpp
Expand Up @@ -163,7 +163,7 @@ void DD_ShutdownAll()
}
#endif

P_ImpulseShutdown();
P_ClearPlayerImpulses();
#ifdef __SERVER__
Sv_Shutdown();
#endif
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/ui/bindcontext.cpp
Expand Up @@ -25,10 +25,11 @@
#include <de/Log>
#include "clientapp.h"

#include "world/impulseaccumulator.h"

#include "CommandBinding"
#include "ImpulseBinding"
#include "ui/inputdevice.h"
#include "ui/playerimpulse.h"

using namespace de;

Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/ui/inputsystem.cpp
Expand Up @@ -38,6 +38,8 @@
#include "m_misc.h" // M_WriteTextEsc

#include "render/vr.h"

#include "world/impulseaccumulator.h"
#include "world/p_players.h"

#include "BindContext"
Expand All @@ -52,7 +54,6 @@
#include "ui/inputdeviceaxiscontrol.h"
#include "ui/inputdevicebuttoncontrol.h"
#include "ui/inputdevicehatcontrol.h"
#include "ui/playerimpulse.h"
#include "ui/sys_input.h"

#include "sys_system.h" // novideo
Expand Down Expand Up @@ -1447,7 +1448,7 @@ Record *InputSystem::bindImpulse(char const *ctrlDesc, char const *impulseDesc)

// The next part must be the impulse name.
impulseDesc = Str_CopyDelim(str, impulseDesc, '-');
PlayerImpulse const *impulse = P_ImpulseByName(Str_Text(str));
PlayerImpulse const *impulse = P_PlayerImpulseByName(Str_Text(str));
if(!impulse)
{
LOG_INPUT_WARNING("Player impulse \"%s\" not defined") << Str_Text(str);
Expand Down Expand Up @@ -1626,7 +1627,7 @@ D_CMD(ListBindings)
context.forAllImpulseBindings(pl, [&pl] (Record &rec)
{
ImpulseBinding bind(rec);
PlayerImpulse const *impulse = P_ImpulsePtr(bind.geti("impulseId"));
PlayerImpulse const *impulse = P_PlayerImpulsePtr(bind.geti("impulseId"));
DENG2_ASSERT(impulse);

LOG_INPUT_MSG(" [%3i] " _E(>) _E(b) "%s" _E(.) " player%i %s")
Expand Down Expand Up @@ -1776,7 +1777,7 @@ DENG_EXTERN_C int B_BindingsForControl(int localPlayer, char const *impulseNameC
ImpulseBinding bind(rec);
DENG2_ASSERT(bind.geti("localPlayer") == localPlayer);

PlayerImpulse const *impulse = P_ImpulsePtr(bind.geti("impulseId"));
PlayerImpulse const *impulse = P_PlayerImpulsePtr(bind.geti("impulseId"));
DENG2_ASSERT(impulse);

if(!impulse->name.compareWithoutCase(impulseName))
Expand Down

0 comments on commit 6c43c3e

Please sign in to comment.