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"
31#include "api.h"
32#include "entitypool.h"
33#include "memdb/database.h"
34#include "world.h"
35#include "processor.h"
36
37//------------------------------------------------------------------------------
38namespace Game
39{
40
41//------------------------------------------------------------------------------
45{
48public:
50 GameServer();
52 virtual ~GameServer();
53
54 // initialize all features
55 virtual bool Open();
56 // start the game; starts running all processors
57 virtual bool Start();
58 // stop the game. Stops running the processors
59 virtual void Stop();
60 // shuts down all features
61 virtual void Close();
62
64 bool HasStarted() const;
65
67 virtual void OnBeginFrame();
69 virtual void OnFrame();
71 virtual void OnEndFrame();
72
74 virtual void NotifyBeforeLoad();
76 virtual void NotifyBeforeCleanup();
77
79 virtual void NotifyGameLoad();
81 virtual void NotifyGameSave();
82
84 void RenderDebug();
85
87 void AttachGameFeature(const Ptr<FeatureUnit>& feature);
89 void RemoveGameFeature(const Ptr<FeatureUnit>& feature);
91 bool IsFeatureAttached(const Util::String& stringName) const;
94
99
101 virtual void SetupEmptyWorld(World*);
103 virtual void CleanupWorld(World*);
104
108 World* GetWorld(WorldHash worldHash);
112 void DestroyWorld(WorldHash worldHash);
113
125
126protected:
127 bool isOpen;
131
132#if NEBULA_ENABLE_PROFILING
133 _declare_timer(GameServerOnBeginFrame);
134 _declare_timer(GameServerOnFrame);
135 _declare_timer(GameServerOnEndFrame);
136 _declare_timer(GameServerManageEntities);
137 Util::Array<Ptr<Debug::DebugTimer>> onBeginFrameTimers;
139 Util::Array<Ptr<Debug::DebugTimer>> onEndFrameTimers;
140#endif
141};
142
143//------------------------------------------------------------------------------
146inline void
148{
149 this->args = a;
150}
151
152//------------------------------------------------------------------------------
155inline const Util::CommandLineArgs&
157{
158 return this->args;
159}
160
161}; // namespace Game
162//------------------------------------------------------------------------------
163
164
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:45
void DestroyWorld(WorldHash worldHash)
destroy a world
Definition gameserver.cc:567
bool HasStarted() const
has the game world already started
Definition gameserver.cc:180
void SetCmdLineArgs(const Util::CommandLineArgs &a)
set command line args
Definition gameserver.h:147
virtual void NotifyGameLoad()
call OnLoad on all game features
Definition gameserver.cc:402
virtual __DeclareClass(GameServer) __DeclareSingleton(GameServer) public ~GameServer()
destructor
Definition gameserver.cc:36
virtual void OnEndFrame()
trigger actions after rendering the game world
Definition gameserver.cc:300
virtual void NotifyBeforeCleanup()
call OnBeforeCleanup on all game features
Definition gameserver.cc:381
struct Game::GameServer::State state
virtual void CleanupWorld(World *)
cleanup the game world
Definition gameserver.cc:520
void AttachGameFeature(const Ptr< FeatureUnit > &feature)
add game feature
Definition gameserver.cc:109
World * CreateWorld(WorldHash hash)
create a world. The game server handles all worlds
Definition gameserver.cc:530
virtual bool Start()
Start the game world, called after loading has completed.
Definition gameserver.cc:144
virtual bool Open()
Initialize the game server object.
Definition gameserver.cc:63
bool IsFeatureAttached(const Util::String &stringName) const
is feature attached
Definition gameserver.cc:480
virtual void SetupEmptyWorld(World *)
setup an empty game world
Definition gameserver.cc:508
Util::Array< Ptr< FeatureUnit > > gameFeatures
Definition gameserver.h:130
virtual void NotifyGameSave()
call OnSave on all game features
Definition gameserver.cc:434
void RemoveGameFeature(const Ptr< FeatureUnit > &feature)
remove game feature
Definition gameserver.cc:126
virtual void Stop()
Stop the game world.
Definition gameserver.cc:190
Util::Array< Ptr< FeatureUnit > > const & GetGameFeatures() const
access to all attached features units
Definition gameserver.cc:498
Util::CommandLineArgs args
Definition gameserver.h:129
bool isOpen
Definition gameserver.h:127
bool isStarted
Definition gameserver.h:128
const Util::CommandLineArgs & GetCmdLineArgs() const
get command line args
Definition gameserver.h:156
void RenderDebug()
call when debug gui and primitives are up for rendering
Definition gameserver.cc:466
World * GetWorld(WorldHash worldHash)
get a world by hash
Definition gameserver.cc:547
virtual void Close()
Close the game server object.
Definition gameserver.cc:93
virtual void OnBeginFrame()
trigger actions before rendering the game world
Definition gameserver.cc:215
virtual void OnFrame()
trigger the game world
Definition gameserver.cc:267
virtual void NotifyBeforeLoad()
call OnBeforeLoad on all game features
Definition gameserver.cc:360
A container of entities, their components, and processors.
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:60
A universal cmd line argument parser.
Definition commandlineargs.h:24
Organizes key/value pairs by a hash code.
Definition hashtable.h:42
#define _declare_timer(timer)
Definition debugtimer.h:35
Game::EditorState.
Definition graphicsmanager.h:60
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:116
uint numWorlds
Definition gameserver.h:118
Ptr< MemDb::Database > templateDatabase
Contains all templates.
Definition gameserver.h:123
Util::HashTable< WorldHash, WorldId, 32, 1 > worldTable
Definition gameserver.h:120
World * worlds[32]
Definition gameserver.h:117
Definition entity.h:29
Nebula's universal string class.
Definition string.h:50
unsigned int uint
Definition types.h:31