Skip to content

Commit

Permalink
Refactor|libdoom: Translated braindata_t into a simple C++ class name…
Browse files Browse the repository at this point in the history
…d BossBrain
  • Loading branch information
danij-deng committed Feb 9, 2014
1 parent 0aa892f commit ae0231c
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 242 deletions.
3 changes: 2 additions & 1 deletion doomsday/plugins/common/src/mapstatereader.cpp
Expand Up @@ -483,7 +483,8 @@ DENG2_PIMPL(MapStateReader)
void readBrain()
{
#if __JDOOM__
P_BrainRead(reader, mapVersion);
DENG_ASSERT(bossBrain != 0);
bossBrain->read(thisPublic);
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/plugins/common/src/mapstatewriter.cpp
Expand Up @@ -186,7 +186,8 @@ DENG2_PIMPL(MapStateWriter)
void writeBrain()
{
#if __JDOOM__
P_BrainWrite(writer);
DENG_ASSERT(bossBrain != 0);
bossBrain->write(thisPublic);
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -972,7 +972,8 @@ static void P_ResetWorldState()
#endif

#if __JDOOM__
P_BrainInitForMap();
delete bossBrain;
bossBrain = new BossBrain;
#endif

#if __JHEXEN__
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_start.cpp
Expand Up @@ -247,7 +247,7 @@ void P_Shutdown()
P_ShutdownTerrainTypes();
P_FreeWeaponSlots();
#if __JDOOM__
P_BrainShutdown();
delete bossBrain; bossBrain = 0;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions doomsday/plugins/common/src/p_switch.cpp
Expand Up @@ -26,6 +26,7 @@

#include "d_net.h"
#include "dmu_lib.h"
#include "dmu_archiveindex.h"
#include "p_plat.h"
#include "p_sound.h"
#include "p_saveg.h"
Expand Down
55 changes: 39 additions & 16 deletions doomsday/plugins/doom/include/bossbrain.h
Expand Up @@ -28,35 +28,58 @@
# error "Using jDoom headers without __JDOOM__"
#endif

#include "doomsday.h"
#include "p_mobj.h"
#include "jdoom.h"
#ifdef __cplusplus
#include "mapstatereader.h"
#include "mapstatewriter.h"

/**
* Global state of boss brain.
*
* @ingroup libdoom
*/
typedef struct bossbrain_s {
int easy;
int targetOn;
int numTargets;
int maxTargets;
mobj_t **targets;
} bossbrain_t;
class BossBrain
{
public:
BossBrain();

void clearTargets();

int targetCount() const;

void addTarget(struct mobj_s *mo);

struct mobj_s *nextTarget();

DENG_EXTERN_C bossbrain_t bossBrain;
void write(MapStateWriter *msw) const;

This comment has been minimized.

Copy link
@skyjake

skyjake Feb 9, 2014

Owner

Is this heading toward a de::ISerializable kind of mechanism? Meaning, something based on polymorphism where you can just write arbitrary map data objects into a writer?

I would much like to see the serialization of all of these game-side classes ultimately based on / working with the libdeng2 Writer/Reader/ISerializable classes in one way or another.

This comment has been minimized.

Copy link
@danij-deng

danij-deng Feb 9, 2014

Author Collaborator

Thats the plan yes. I intend to switch the low level serialization components once the rest of the save game framework is clean.

void read(MapStateReader *msr);

private:
DENG2_PRIVATE(d)
};
#endif // __cplusplus

// C wrapper API ---------------------------------------------------------------

#ifdef __cplusplus
extern "C" {
#else
typedef void *BossBrain;
#endif

void P_BrainInitForMap(void);
void P_BrainShutdown(void);
void P_BrainClearTargets(void);
void P_BrainWrite(Writer *writer);
void P_BrainRead(Reader *reader, int mapVersion);
void P_BrainAddTarget(mobj_t *mo);
void BossBrain_ClearTargets(BossBrain *brain);

int BossBrain_TargetCount(BossBrain const *brain);

void BossBrain_AddTarget(BossBrain *brain, struct mobj_s *mo);

struct mobj_s *BossBrain_NextTarget(BossBrain *brain);

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

/// The One BossBrain instance.
DENG_EXTERN_C BossBrain *bossBrain;

#endif // LIBDOOM_PLAY_BOSSBRAIN_H
80 changes: 40 additions & 40 deletions doomsday/plugins/doom/include/g_game.h
Expand Up @@ -39,46 +39,46 @@
#include "d_player.h"
#include "gamerules.h"

DENG_EXTERN_C int gaSaveGameSlot;
DENG_EXTERN_C int gaLoadGameSlot;

DENG_EXTERN_C player_t players[MAXPLAYERS];

DENG_EXTERN_C dd_bool gameInProgress;
DENG_EXTERN_C uint gameEpisode;
DENG_EXTERN_C uint gameMap;
DENG_EXTERN_C Uri *gameMapUri;
DENG_EXTERN_C uint gameMapEntrance;
DENG_EXTERN_C GameRuleset gameRules;

DENG_EXTERN_C uint nextMap; // If non zero this will be the next map.
DENG_EXTERN_C dd_bool secretExit;
DENG_EXTERN_C int totalKills, totalItems, totalSecret;
DENG_EXTERN_C dd_bool paused;
DENG_EXTERN_C dd_bool precache;
DENG_EXTERN_C dd_bool customPal;
DENG_EXTERN_C wbstartstruct_t wmInfo;
DENG_EXTERN_C int bodyQueueSlot;
DENG_EXTERN_C dd_bool briefDisabled;

DENG_EXTERN_C int gsvMapMusic;

#ifdef __cplusplus
extern "C" {
#endif

extern int gaSaveGameSlot;
extern int gaLoadGameSlot;

extern player_t players[MAXPLAYERS];

extern dd_bool gameInProgress;
extern uint gameEpisode;
extern uint gameMap;
extern Uri *gameMapUri;
extern uint gameMapEntrance;
extern GameRuleset gameRules;

extern uint nextMap; // If non zero this will be the next map.
extern dd_bool secretExit;
extern int totalKills, totalItems, totalSecret;
extern dd_bool paused;
extern dd_bool precache;
extern dd_bool customPal;
extern wbstartstruct_t wmInfo;
extern int bodyQueueSlot;
extern dd_bool briefDisabled;

extern int gsvMapMusic;

void G_Register(void);
void G_CommonPreInit(void);
void G_CommonPostInit(void);
void G_CommonShutdown(void);
void G_Register(void);
void G_CommonPreInit(void);
void G_CommonPostInit(void);
void G_CommonShutdown(void);

void R_InitRefresh(void);
void R_InitRefresh(void);

void G_PrintMapList(void);
void G_PrintMapList(void);

void G_DeferredPlayDemo(char* demo);
void G_DeferredPlayDemo(char* demo);

void G_QuitGame(void);
void G_QuitGame(void);

/// @return @c true = loading is presently possible.
dd_bool G_IsLoadGamePossible(void);
Expand All @@ -104,7 +104,7 @@ dd_bool G_IsSaveGamePossible(void);
dd_bool G_SaveGame2(int slot, const char* name);
dd_bool G_SaveGame(int slot);

void G_StopDemo(void);
void G_StopDemo(void);

/**
* Check if there is a finale before the map.
Expand All @@ -118,27 +118,27 @@ int G_BriefingEnabled(Uri const *mapUri, ddfinale_t *fin);
*/
int G_DebriefingEnabled(Uri const *mapUri, ddfinale_t *fin);

void G_DoReborn(int playernum);
void G_PlayerReborn(int player);
void G_DoReborn(int playernum);
void G_PlayerReborn(int player);

/**
* Called after intermission ends.
*/
void G_IntermissionDone(void);
void G_IntermissionDone(void);

void G_Ticker(timespan_t ticLength);
void G_Ticker(timespan_t ticLength);

/// @return @c true if the input event @a ev was eaten.
int G_PrivilegedResponder(event_t* ev);

/// @return @c true if the input event @a ev was eaten.
int G_Responder(event_t* ev);

void G_ScreenShot(void);
void G_ScreenShot(void);

void G_PrepareWIData(void);
void G_PrepareWIData(void);

void G_QueueBody(mobj_t* body);
void G_QueueBody(mobj_t* body);

#ifdef __cplusplus
} // extern "C"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/doom/include/jdoom.h
Expand Up @@ -32,7 +32,6 @@
#define __JDOOM_CONVENIENCE_H__

#include "../../doom/include/acfnlink.h"
#include "../../doom/include/bossbrain.h"
#include "../../doom/include/d_api.h"
#include "../../doom/include/d_config.h"
#include "../../doom/include/d_console.h"
Expand All @@ -47,6 +46,7 @@
#include "../../doom/include/m_cheat.h"
#include "../../doom/include/m_random.h"
#include "../../doom/include/p_enemy.h"
#include "../../doom/include/bossbrain.h"
#include "../../doom/include/p_inter.h"
#include "../../doom/include/p_lights.h"
#include "../../doom/include/p_local.h"
Expand Down

0 comments on commit ae0231c

Please sign in to comment.