TrueReality  v0.1.1912
EntityBase.h
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #pragma once
23 
24 #include "Export.h"
25 
27 #include <trManager/EntityType.h>
28 #include <trManager/Invokable.h>
29 #include <trUtil/HashMap.h>
30 #include <trBase/ObsrvrPtr.h>
31 #include <trBase/SmrtPtr.h>
32 #include <trBase/Base.h>
33 
34 #include <vector>
35 
36 namespace trManager
37 {
38  class SystemManager;
39 
47  {
48  public:
49 
51 
52  const static trUtil::RefStr CLASS_TYPE;
53 
57 
65  EntityBase(const std::string& name = CLASS_TYPE);
66 
74  virtual const std::string& GetType() const override = 0;
75 
83  const EntityType& GetEntityType();
84 
93  virtual void SetSystemManager(trManager::SystemManager *sysMan);
94 
100  virtual void OnAddedToSysMan() {/*Meant for user to overwrite*/ };
101 
107  virtual void OnRemovedFromSysMan() {/*Meant for user to overwrite*/ };
108 
116  virtual const bool& IsRegistered();
117 
126  virtual void SetRegistration(bool isRegistered);
127 
135  virtual void AddInvokable(trManager::Invokable &newInvokable);
136 
144  virtual void RemoveInvokable(trManager::Invokable *invokable);
145 
153  virtual void RemoveInvokable(const std::string &invokableName);
154 
164  trManager::Invokable* GetInvokable(const std::string &name);
165 
173  void GetInvokables(std::vector<trManager::Invokable*> &toFill);
174 
182  void GetInvokables(std::vector<const trManager::Invokable*> &toFill) const;
183 
192  virtual void OnTick(const trManager::MessageBase &msg) = 0;
193 
202  virtual void OnTickRemote(const trManager::MessageBase &msg) = 0;
203 
213  virtual bool AddChild(trManager::EntityBase &child);
214 
224  virtual bool RemoveChild(trManager::EntityBase &child);
225 
233  virtual bool RemoveAllChildren();
234 
242  virtual std::vector<trBase::SmrtPtr<trManager::EntityBase>>* GetChildren();
243 
251  virtual const std::vector<trBase::SmrtPtr<trManager::EntityBase>>* GetChildren() const;
252 
262  virtual const trManager::EntityBase* FindChild(const trBase::UniqueId& childId);
263 
271  virtual int GetNumOfChildren();
272 
281  virtual void SetParent(trManager::EntityBase &parent);
282 
289  virtual void ForgetParent();
290 
298  trManager::EntityBase* GetParent();
299 
307  const trManager::EntityBase* GetParent() const;
308 
317  virtual void OnParentRemoved(trManager::EntityBase &parent);
318 
327  virtual void OnParentSet(trManager::EntityBase &parent);
328 
329 
337  virtual void Emancipate();
338 
347  virtual bool RemoveFromHierarchy();
348 
349  protected:
350 
354 
355  ~EntityBase();
356 
357  private:
358 
359  bool mIsRegistered = false;
360  std::vector<trBase::SmrtPtr<trManager::EntityBase>> mChildren;
362 
363  };
364 }
static const trUtil::RefStr CLASS_TYPE
Adds an easy and swappable access to the base class.
Definition: EntityBase.h:52
static const trUtil::RefStr ON_TICK_REMOTE_INVOKABLE
Invokable for Tick messages.
Definition: EntityBase.h:56
This class creates a GUID, or a Unique ID that is used through out TR to identify and distinguish one...
Definition: UniqueId.h:42
virtual void OnRemovedFromSysMan()
Called by the System Manager after removing and Unregistering the EntityBase.
Definition: EntityBase.h:107
An Invokable is a queriable method interface that can be added to a trManager::ActorBase Invoking the...
Definition: Invokable.h:84
A string wrapper that will make sure that all of the strings with the same value will point to the sa...
Definition: RefStr.h:50
A class that specifies what kind of entity an object is in the Entity System.
Definition: EntityType.h:37
trUtil::EnumerationPointer< const trManager::EntityType > mEntityType
Definition: EntityBase.h:352
System Manager class is a singleton that is responsible for all message routing and basic operations ...
Definition: SystemManager.h:46
static const trUtil::RefStr ON_TICK_INVOKABLE
Invokable for general messages.
Definition: EntityBase.h:55
This class is part of the internal garbage collection system.
Definition: SmrtClass.h:38
This is a Base class that carries the Class name and Unique ID of all the derived classes...
Definition: trBase/Base.h:36
static const trUtil::RefStr ON_MESSAGE_INVOKABLE
Holds the class type name for efficient comparisons.
Definition: EntityBase.h:54
trBase::ObsrvrPtr< trManager::SystemManager > mSysMan
Definition: EntityBase.h:351
trBase::SmrtPtr< trManager::EntityBase > mParent
Definition: EntityBase.h:361
trUtil::HashMap< std::string, trBase::SmrtPtr< trManager::Invokable > > mInvokables
Definition: EntityBase.h:353
std::vector< trBase::SmrtPtr< trManager::EntityBase > > mChildren
Definition: EntityBase.h:360
This serves as the base class for the Entity class and removes a circular dependency between Entity a...
Definition: EntityBase.h:46
This is the base class for all the messages in TR.
Definition: MessageBase.h:40
#define TR_MANAGER_EXPORT
virtual void OnAddedToSysMan()
Called by the System Manager when EntityBase Registration is complete.
Definition: EntityBase.h:100