Nebula
Loading...
Searching...
No Matches
gameserver.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
25#include "core/refcounted.h"
26#include "core/ptr.h"
27#include "core/singleton.h"
28#include "game/featureunit.h"
29#include "debug/debugtimer.h"
30#include "api.h"
31#include "memdb/database.h"
32#include "world.h"
33#include "processor.h"
34
35//------------------------------------------------------------------------------
36namespace Game
37{
38
39//------------------------------------------------------------------------------
43{
46public:
48 GameServer();
50 virtual ~GameServer();
51
52 // initialize all features
53 virtual bool Open();
54 // start the game; starts running all processors
55 virtual bool Start();
56 // stop the game. Stops running the processors
57 virtual void Stop();
58 // shuts down all features
59 virtual void Close();
60
62 bool HasStarted() const;
63
65 virtual void OnBeginFrame();
67 virtual void OnFrame();
69 virtual void OnEndFrame();
70
72 virtual void NotifyBeforeLoad();
74 virtual void NotifyBeforeCleanup();
75
77 virtual void NotifyGameLoad();
79 virtual void NotifyGameSave();
80
82 void RenderDebug();
83
85 void AttachGameFeature(const Ptr<FeatureUnit>& feature);
87 void RemoveGameFeature(const Ptr<FeatureUnit>& feature);
89 bool IsFeatureAttached(const Util::String& stringName) const;
92
97
99 virtual void SetupEmptyWorld(World*);
101 virtual void CleanupWorld(World*);
102
106 World* GetWorld(WorldHash worldHash);
110 void DestroyWorld(WorldHash worldHash);
111
120
121protected:
122 bool isOpen;
126
127#if NEBULA_ENABLE_PROFILING
128 _declare_timer(GameServerOnBeginFrame);
129 _declare_timer(GameServerOnFrame);
130 _declare_timer(GameServerOnEndFrame);
131 _declare_timer(GameServerManageEntities);
132 Util::Array<Ptr<Debug::DebugTimer>> onBeginFrameTimers;
134 Util::Array<Ptr<Debug::DebugTimer>> onEndFrameTimers;
135#endif
136};
137
138//------------------------------------------------------------------------------
141inline void
143{
144 this->args = a;
145}
146
147//------------------------------------------------------------------------------
150inline const Util::CommandLineArgs&
152{
153 return this->args;
154}
155
156}; // namespace Game
157//------------------------------------------------------------------------------
158
159
The main programming interface for the Game Subsystem.
The common base class of Nebula.
Definition refcounted.h:38
The game server setups and runs the game world.
Definition gameserver.h:43
void DestroyWorld(WorldHash worldHash)
destroy a world
Definition gameserver.cc:587
bool HasStarted() const
has the game world already started
Definition gameserver.cc:176
void SetCmdLineArgs(const Util::CommandLineArgs &a)
set command line args
Definition gameserver.h:142
virtual void NotifyGameLoad()
call OnLoad on all game features
Definition gameserver.cc:422
virtual __DeclareClass(GameServer) __DeclareSingleton(GameServer) public ~GameServer()
destructor
Definition gameserver.cc:35
virtual void OnEndFrame()
trigger actions after rendering the game world
Definition gameserver.cc:310
virtual void NotifyBeforeCleanup()
call OnBeforeCleanup on all game features
Definition gameserver.cc:401
struct Game::GameServer::State state
virtual void CleanupWorld(World *)
cleanup the game world
Definition gameserver.cc:540
void AttachGameFeature(const Ptr< FeatureUnit > &feature)
add game feature
Definition gameserver.cc:105
World * CreateWorld(WorldHash hash)
create a world. The game server handles all worlds
Definition gameserver.cc:550
virtual bool Start()
Start the game world, called after loading has completed.
Definition gameserver.cc:140
virtual bool Open()
Initialize the game server object.
Definition gameserver.cc:60
bool IsFeatureAttached(const Util::String &stringName) const
is feature attached
Definition gameserver.cc:500
virtual void SetupEmptyWorld(World *)
setup an empty game world
Definition gameserver.cc:528
Util::Array< Ptr< FeatureUnit > > gameFeatures
Definition gameserver.h:125
virtual void NotifyGameSave()
call OnSave on all game features
Definition gameserver.cc:454
void RemoveGameFeature(const Ptr< FeatureUnit > &feature)
remove game feature
Definition gameserver.cc:122
virtual void Stop()
Stop the game world.
Definition gameserver.cc:186
Util::Array< Ptr< FeatureUnit > > const & GetGameFeatures() const
access to all attached features units
Definition gameserver.cc:518
Util::CommandLineArgs args
Definition gameserver.h:124
bool isOpen
Definition gameserver.h:122
bool isStarted
Definition gameserver.h:123
const Util::CommandLineArgs & GetCmdLineArgs() const
get command line args
Definition gameserver.h:151
void RenderDebug()
call when debug gui and primitives are up for rendering
Definition gameserver.cc:486
World * GetWorld(WorldHash worldHash)
get a world by hash
Definition gameserver.cc:567
virtual void Close()
Close the game server object.
Definition gameserver.cc:89
virtual void OnBeginFrame()
trigger actions before rendering the game world
Definition gameserver.cc:211
virtual void OnFrame()
trigger the game world
Definition gameserver.cc:274
virtual void NotifyBeforeLoad()
call OnBeforeLoad on all game features
Definition gameserver.cc:380
A container of entities, their components, and processors.
Definition world.h:70
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:61
A universal cmd line argument parser.
Definition commandlineargs.h:24
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
Nebula's universal string class.
Definition string.h:50
#define _declare_timer(timer)
Definition debugtimer.h:35
Resolves local hierarchical transforms into the mandatory world transform components.
Definition graphicsmanager.h:67
uint32_t WorldId
Definition entity.h:28
#define __DeclareSingleton(type)
Definition osxsingleton.h:24
#define __DeclareClass(type)
contains internal state and world management
Definition gameserver.h:114
uint numWorlds
Definition gameserver.h:116
Util::HashTable< WorldHash, WorldId, 32, 1 > worldTable
Definition gameserver.h:118
World * worlds[32]
Definition gameserver.h:115
Definition entity.h:29
unsigned int uint
Definition types.h:33