Nebula
Loading...
Searching...
No Matches
featureunit.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
20#include "core/refcounted.h"
21#include "game/manager.h"
22#include "core/singleton.h"
24#include "io/jsonwriter.h"
26#include "util/arrayallocator.h"
27#include "game/component.h"
28
29//------------------------------------------------------------------------------
30namespace Game
31{
32
34{
36public:
40 virtual ~FeatureUnit();
41
43 template <typename COMPONENT_TYPE>
45
47 virtual void OnAttach();
49 virtual void OnRemove();
50
52 virtual void OnActivate();
54 virtual void OnDeactivate();
55
57 bool IsActive() const;
58
60 virtual void OnLoad(World* world);
62 virtual void OnStart(World* world);
64 virtual void OnSave(World* world);
65
67 virtual void OnBeforeLoad(World* world);
69 virtual void OnBeforeCleanup(World* world);
71 virtual void OnStop(World* world);
72
73
75 virtual void OnBeginFrame();
77 virtual void OnBeforeViews();
79 virtual void OnFrame();
81 virtual void OnEndFrame();
83 virtual void OnDecay();
84
86 virtual void OnRenderDebug();
87
89 virtual void AttachManager(Ptr<Manager> manager);
91 virtual void RemoveManager(Ptr<Manager> manager);
92
97
98protected:
100 bool active;
101
104};
105
106//------------------------------------------------------------------------------
111template <typename COMPONENT_TYPE>
114{
115 uint32_t componentFlags = 0;
116 componentFlags |= (uint32_t)COMPONENTFLAG_DECAY * (uint32_t)info.decay;
117
118 ComponentInterface* cInterface = new ComponentInterface(COMPONENT_TYPE::Traits::name, COMPONENT_TYPE(), componentFlags);
119 cInterface->Init = reinterpret_cast<ComponentInterface::ComponentInitFunc>(info.OnInit);
123
124 return cid;
125}
126
127//------------------------------------------------------------------------------
130inline bool
132{
133 return this->active;
134}
135
136//------------------------------------------------------------------------------
139inline void
141{
142 this->args = a;
143}
144
145//------------------------------------------------------------------------------
148inline const Util::CommandLineArgs&
150{
151 return this->args;
152}
153
154} // namespace FeatureUnit
155//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:38
static void Register(ComponentId component, DrawFunc)
Definition componentinspection.cc:55
These are registered to the attribute registry so that we can add more functionality to attributes.
Definition component.h:75
void(*)(Game::World *, Game::Entity, void *) ComponentInitFunc
Definition component.h:90
ComponentInitFunc Init
Definition component.h:91
static void Register(ComponentId component)
Definition componentserialization.h:70
A FeatureUnit is an encapsulated feature which can be added to an application.
Definition featureunit.h:34
virtual void OnStart(World *world)
called from within GameServer::OnStart() after OnLoad
Definition featureunit.cc:105
virtual void OnStop(World *world)
called from withing GameServer::Stop()
Definition featureunit.cc:294
Util::CommandLineArgs args
cmdline args for configuration from cmdline
Definition featureunit.h:103
virtual void OnAttach()
called from GameServer::AttachGameFeature()
Definition featureunit.cc:36
virtual void OnLoad(World *world)
called from within GameServer::Load()
Definition featureunit.cc:87
virtual void OnFrame()
called in the middle of the feature trigger cycle
Definition featureunit.cc:175
virtual void OnBeforeLoad(World *world)
called from within GameServer::NotifyBeforeLoad()
Definition featureunit.cc:273
virtual void OnBeforeCleanup(World *world)
called from within GameServer::NotifyBeforeCleanup()
Definition featureunit.cc:282
Util::Array< Ptr< Manager > > managers
Definition featureunit.h:99
virtual void OnDecay()
called after entities has been destroyed and before releasing their memory
Definition featureunit.cc:208
bool IsActive() const
return true if featureunit is currently active
Definition featureunit.h:131
void SetCmdLineArgs(const Util::CommandLineArgs &a)
set command line args
Definition featureunit.h:140
bool active
Definition featureunit.h:100
virtual void OnActivate()
called after GameServer::AttachGameFeature()
Definition featureunit.cc:56
virtual __DeclareClass(FeatureUnit) public ~FeatureUnit()
destructor
Definition featureunit.cc:27
virtual void OnSave(World *world)
called from within GameServer::Save()
Definition featureunit.cc:121
virtual void OnRenderDebug()
called when game debug visualization is on
Definition featureunit.cc:225
virtual void OnEndFrame()
called at the end of the feature trigger cycle
Definition featureunit.cc:193
virtual void OnRemove()
called from GameServer::RemoveGameFeature()
Definition featureunit.cc:45
ComponentId RegisterComponentType(ComponentRegisterInfo< COMPONENT_TYPE > info={})
Register a component type.
Definition featureunit.h:113
virtual void RemoveManager(Ptr< Manager > manager)
remove a manager from the feature unit
Definition featureunit.cc:255
virtual void OnBeginFrame()
called on begin of frame
Definition featureunit.cc:138
virtual void OnDeactivate()
called before GameServer::RemoveGameFeature()
Definition featureunit.cc:68
virtual void AttachManager(Ptr< Manager > manager)
attach a manager to the feature unit
Definition featureunit.cc:243
const Util::CommandLineArgs & GetCmdLineArgs() const
get command line args
Definition featureunit.h:149
virtual void OnBeforeViews()
Called between beginning of frame and before the views are iterated.
Definition featureunit.cc:156
A container of entities, their components, and processors.
static AttributeId Register(Util::StringAtom name, TYPE defaultValue, uint32_t flags=0)
register a type (templated)
Definition attributeregistry.h:99
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
Game::EditorState.
Definition graphicsmanager.h:60
@ COMPONENTFLAG_DECAY
Component will decay.
Definition component.h:38
void ComponentDrawFuncT(ComponentId component, void *data, bool *commit)
Definition componentinspection.h:106
#define __DeclareClass(type)
Used for registering component types to the game world.
Definition component.h:61
OnInitFunc OnInit
initialization function to run for the component, or nullptr if not needed.
Definition component.h:67
bool decay
Set to true if the component should end up in the decay buffer before being completely destroyed.
Definition component.h:65
Definition attributeid.h:19