Leviathan  0.8.0.0
Leviathan game engine
GameWorld.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2019 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
7 #include "Common/ThreadSafe.h"
8 #include "Component.h"
10 #include "WorldNetworkSettings.h"
11 
12 // #include <type_traits>
13 #include "bsfCore/BsCorePrerequisites.h"
14 
15 class CScriptArray;
16 class asIScriptObject;
17 class asIScriptFunction;
18 
19 
20 namespace Leviathan {
21 
22 class Camera;
23 class PhysicalWorld;
24 class ScriptComponentHolder;
25 class ResponseEntityCreation;
26 class ResponseEntityDestruction;
27 class ResponseEntityUpdate;
28 class ResponseEntityLocalControlStatus;
29 
30 template<class StateT>
32 
33 class EntityState;
34 
36 
37  inline ComponentTypeInfo(uint16_t ltype, int astype) :
38  LeviathanType(ltype), AngelScriptType(astype)
39  {}
40 
43 };
44 
45 
46 #define WORLD_CLOCK_SYNC_PACKETS 12
47 #define WORLD_CLOCK_SYNC_ALLOW_FAILS 2
48 #define WORLD_OBJECT_UPDATE_CLIENTS_INTERVAL 2
49 
50 // //! Holds the returned entity that was hit during ray casting
51 // //! \todo Move to a new file
52 // class RayCastHitEntity : public ReferenceCounted {
53 // public:
54 // DLLEXPORT RayCastHitEntity(const NewtonBody* ptr = nullptr, const float& tvar = 0.f,
55 // RayCastData* ownerptr = nullptr);
56 
57 // DLLEXPORT RayCastHitEntity& operator=(const RayCastHitEntity& other);
58 
59 // // Compares the hit entity with nullptr //
60 // DLLEXPORT bool HasHit();
61 
62 // DLLEXPORT Float3 GetPosition();
63 
64 // DLLEXPORT bool DoesBodyMatchThisHit(NewtonBody* other);
65 
66 // //! Stores the entity, typed as NewtonBody to make sure that user knows
67 // //! what should be compared with this
68 // const NewtonBody* HitEntity;
69 
70 // //! The distance from the start of the ray to the hit location
71 // float HitVariable;
72 // Float3 HitLocation;
73 // };
74 
75 // // Internal object in ray casts //
76 // struct RayCastData {
77 // DLLEXPORT RayCastData(int maxcount, const Float3& from, const Float3& to);
78 // DLLEXPORT ~RayCastData();
79 
80 // // All hit entities that pass checks //
81 // std::vector<RayCastHitEntity*> HitEntities;
82 // // Used to stop after certain amount of entities found //
83 // int MaxCount;
84 // // Used to efficiently calculate many hit locations //
85 // Float3 BaseHitLocationCalcVar;
86 // };
87 
94 class GameWorld {
95  class Implementation;
96 
97 public:
100  DLLEXPORT GameWorld(int32_t worldtype,
101  const std::shared_ptr<PhysicsMaterialManager>& physicsMaterials, int worldid = -1);
103 
106  DLLEXPORT bool Init(const WorldNetworkSettings& network, Graphics* graphics);
107 
109  DLLEXPORT void Release();
110 
112  DLLEXPORT void MarkForClear();
113 
115  DLLEXPORT void ClearEntities();
116 
120  DLLEXPORT size_t GetEntityCount() const
121  {
122  return Entities.size();
123  }
124 
126  DLLEXPORT inline const auto& GetEntities() const
127  {
128  return Entities;
129  }
130 
135  DLLEXPORT void Tick(int currenttick);
136 
139  DLLEXPORT void Render(int mspassed, int tick, int timeintick);
140 
142  DLLEXPORT inline int GetTickNumber() const
143  {
144  return TickNumber;
145  }
146 
148  DLLEXPORT float GetTickProgress() const;
149 
154  DLLEXPORT std::tuple<int, int> GetTickAndTime() const;
155 
156 
159  DLLEXPORT int GetPhysicalMaterial(const std::string& name);
160 
161 
162  // //! \brief Casts a ray from point along a vector and returns the first physical
163  // //! object it hits
164  // //! \warning You need to call Release on the returned object once done
165  // DLLEXPORT RayCastHitEntity* CastRayGetFirstHit(const Float3& from, const Float3& to);
166 
170 
177 
180 
183  DLLEXPORT void SetEntitysParent(ObjectID child, ObjectID parent);
184 
187  {
188  for(const auto& entity : Entities) {
189  if(id == entity)
190  return true;
191  }
192 
193  return false;
194  }
195 
196 
198  DLLEXPORT virtual void DestroyAllIn(ObjectID id);
199 
204  template<class TComponent>
205  TComponent& GetComponent(ObjectID id)
206  {
207  std::tuple<void*, bool> component = GetComponent(id, TComponent::TYPE);
208 
209  if(!std::get<1>(component))
210  throw InvalidArgument("Unrecognized component type as template parameter");
211 
212  void* ptr = std::get<0>(component);
213 
214  if(!ptr)
215  throw NotFound("Component for entity with id was not found");
216 
217  return *static_cast<TComponent*>(ptr);
218  }
219 
224  template<class TComponent>
225  TComponent* GetComponentPtr(ObjectID id)
226  {
227  std::tuple<void*, bool> component = GetComponent(id, TComponent::TYPE);
228 
229  void* ptr = std::get<0>(component);
230 
231  if(!ptr)
232  return nullptr;
233 
234  return static_cast<TComponent*>(ptr);
235  }
236 
240  DLLEXPORT virtual std::tuple<void*, bool> GetComponent(ObjectID id, COMPONENT_TYPE type);
241 
245  DLLEXPORT virtual std::tuple<void*, ComponentTypeInfo, bool> GetComponentWithType(
246  ObjectID id, COMPONENT_TYPE type);
247 
252  template<class TComponent>
254  {
255  std::tuple<void*, bool> stateHolder = GetStatesFor(TComponent::TYPE);
256 
257  if(!std::get<1>(stateHolder))
258  throw InvalidArgument("Unrecognized component type as template parameter for "
259  "state holder");
260 
261  void* ptr = std::get<0>(stateHolder);
262 
263  return *static_cast<StateHolder<typename TComponent::StateT>*>(ptr);
264  }
265 
269  DLLEXPORT virtual std::tuple<void*, bool> GetStatesFor(COMPONENT_TYPE type);
270 
274  DLLEXPORT virtual bool GetRemovedFor(
275  COMPONENT_TYPE type, std::vector<std::tuple<void*, ObjectID>>& result);
276 
279  const std::string& name, std::vector<std::tuple<asIScriptObject*, ObjectID>>& result);
280 
285  DLLEXPORT virtual bool GetAddedFor(COMPONENT_TYPE type,
286  std::vector<std::tuple<void*, ObjectID, ComponentTypeInfo>>& result);
287 
289  DLLEXPORT bool GetAddedForScriptDefined(const std::string& name,
290  std::vector<std::tuple<asIScriptObject*, ObjectID, ScriptComponentHolder*>>& result);
291 
293  DLLEXPORT virtual void CaptureEntityState(ObjectID id, EntityState& curstate) const;
294 
299  ObjectID id, sf::Packet& receiver) const;
300 
305  DLLEXPORT void SetCamera(ObjectID object);
306 
313  DLLEXPORT bs::Ray CastRayFromCamera(int x, int y) const;
314 
315  inline bs::Scene* GetScene()
316  {
317  return &BSFLayerHack;
318  // return WorldsScene;
319  }
320 
324  DLLEXPORT bs::HSceneObject GetCameraSceneObject();
325 
326  // physics functions //
327  // DLLEXPORT Float3 GetGravityAtPosition(const Float3& pos);
328 
330  {
331  return _PhysicalWorld.get();
332  }
333 
335  DLLEXPORT inline int GetID() const
336  {
337  return ID;
338  }
339 
341  DLLEXPORT inline int32_t GetType() const
342  {
343  return WorldType;
344  }
345 
346  DLLEXPORT inline const auto& GetNetworkSettings() const
347  {
348  return NetworkSettings;
349  }
350 
352  DLLEXPORT void SetWorldPhysicsFrozenState(bool frozen);
353 
354  // Script proxies //
355 
356  //
357  // Networking methods
358  //
359 
363  DLLEXPORT bool ShouldPlayerReceiveEntity(Position& atposition, Connection& connection);
364 
367  DLLEXPORT bool IsConnectionInWorld(Connection& connection) const;
368 
370  DLLEXPORT void SetPlayerReceiveWorld(std::shared_ptr<ConnectedPlayer> ply);
371 
374  inline const auto& GetConnectedPlayers() const
375  {
376  return ReceivingPlayers;
377  }
378 
381  const std::shared_ptr<NetworkResponse>& response, RECEIVE_GUARANTEE guarantee) const;
382 
387  ObjectID id, bool enabled, const std::shared_ptr<Connection>& allowedconnection);
388 
390  DLLEXPORT const auto& GetOurLocalControl() const
391  {
392  return OurActiveLocalControl;
393  }
394 
400  {
401  for(const auto& entity : OurActiveLocalControl)
402  if(entity == id)
403  return true;
404  return false;
405  }
406 
409  DLLEXPORT void SetServerForLocalControl(const std::shared_ptr<Connection>& connection)
410  {
411  ClientToServerConnection = connection;
412  }
413 
415  {
416  return ClientToServerConnection;
417  }
418 
424  DLLEXPORT void HandleEntityPacket(ResponseEntityUpdate&& message, Connection& connection);
425 
427  DLLEXPORT ObjectID HandleEntityPacket(ResponseEntityCreation& message);
428 
429  DLLEXPORT void HandleEntityPacket(ResponseEntityDestruction& message);
430 
431  DLLEXPORT void HandleEntityPacket(ResponseEntityLocalControlStatus& message);
432 
433  // //! \brief Handles a world clock synchronizing packet
434  // //! \note This should only be allowed to be called on a client that has connected
435  // //! to a server
436  // DLLEXPORT void HandleClockSyncPacket(RequestWorldClockSync* data);
437 
438  // //! \brief Handles a world freeze/unfreeze packet
439  // //! \note Should only be called on a client
440  // DLLEXPORT void HandleWorldFrozenPacket(ResponseWorldFrozen* data);
441 
442  DLLEXPORT void SetSunlight();
443  DLLEXPORT void RemoveSunlight();
446  DLLEXPORT void SetLightProperties(const Float3& colour, float intensity = 0.0001f,
447  const Float3& direction = Float3(0.55f, -0.3f, 0.75f), float sourceradius = 0.5f,
448  bool castsshadows = true);
449 
451  DLLEXPORT void SetSkybox(const std::string& skyboxname, float brightness = 1.f);
452 
453  // ------------------------------------ //
454  // Script proxies for script system implementation (don't use from c++ systems)
455 
458  DLLEXPORT CScriptArray* GetRemovedIDsForComponents(CScriptArray* componenttypes);
459 
462  DLLEXPORT CScriptArray* GetRemovedIDsForScriptComponents(CScriptArray* typenames);
463 
466  const std::string& name, asIScriptFunction* factory);
467 
470  DLLEXPORT ScriptComponentHolder* GetScriptComponentHolder(const std::string& name);
471 
474  DLLEXPORT bool RegisterScriptSystem(const std::string& name, asIScriptObject* system);
475 
480  DLLEXPORT bool UnregisterScriptSystem(const std::string& name);
481 
484  DLLEXPORT asIScriptObject* GetScriptSystem(const std::string& name);
485 
486  // ------------------------------------ //
487  // Background worlds (used to stop ticking etc.)
488 
491  DLLEXPORT virtual void OnUnLinkedFromWindow(Window* window, Graphics* graphics);
492 
495  DLLEXPORT virtual void OnLinkToWindow(Window* window, Graphics* graphics);
496 
498  DLLEXPORT virtual void SetRunInBackground(bool tickinbackground);
499 
500 
502 
503 protected:
507 
508 public:
514  DLLEXPORT virtual void RunFrameRenderSystems(int tick, int timeintick);
515 
516 protected:
522  DLLEXPORT virtual void _RunTickSystems();
523 
529  DLLEXPORT virtual void HandleAddedAndDeleted();
530 
532  DLLEXPORT virtual void ClearAddedAndRemoved();
533 
535  DLLEXPORT virtual void _ResetSystems();
536 
538  DLLEXPORT virtual void _ResetOrReleaseComponents();
539 
541  DLLEXPORT virtual void _DoSystemsInit();
542 
544  DLLEXPORT virtual void _DoSystemsRelease();
545 
550  DLLEXPORT virtual void _DoSuspendSystems();
551 
553  DLLEXPORT virtual void _DoResumeSystems();
554 
557 
560 
567  ObjectID id, sf::Packet& data, int entriesleft, int decodedtype);
568 
572  DLLEXPORT virtual void _CreateStatesFromUpdateMessage(ObjectID id, int32_t ticknumber,
573  sf::Packet& data, int32_t referencetick, int decodedtype);
574 
581  DLLEXPORT virtual void _ApplyLocalControlUpdateMessage(ObjectID id, int32_t ticknumber,
582  sf::Packet& data, int32_t referencetick, int decodedtype);
583 
584 
589  DLLEXPORT virtual void _OnLocalControlUpdatedEntity(ObjectID id, int32_t ticknumber);
590 
591 private:
593  void UpdatePlayersPositionData(ConnectedPlayer& ply);
594 
595  void _CreateRenderingResources(Graphics* graphics);
596  void _DestroyRenderingResources();
597 
598  void _HandleDelayedDelete();
599 
601  void _ReportEntityDestruction(ObjectID id);
602 
605  void _DoDestroy(ObjectID id);
606 
608  void _SendEntityUpdates(ObjectID id, Sendable& sendable, int tick);
609 
610 
611 protected:
616  bool GraphicalMode = false;
617 
618 private:
619  // pimpl to reduce need of including tons of headers (this causes
620  // a double pointer dereference so don't put performance critical
621  // stuff here)
622  std::unique_ptr<Implementation> pimpl;
623 
625  bs::Scene BSFLayerHack = 0;
626 
627  // Ogre::Camera* WorldSceneCamera = nullptr;
628  // Ogre::SceneManager* WorldsScene = nullptr;
629 
630  // Ogre::CompositorWorkspace* WorldWorkspace = nullptr;
631 
633  Window* LinkedToWindow = nullptr;
634 
635  // Ogre::Light* Sunlight = nullptr;
636  // Ogre::SceneNode* SunLightNode = nullptr;
637 
638  // physics //
639  std::shared_ptr<PhysicsMaterialManager> PhysicsMaterials;
640  std::shared_ptr<PhysicalWorld> _PhysicalWorld;
641 
643  bool WorldFrozen = false;
644 
645 
647  bool ClearAllEntities = false;
648 
652  std::vector<std::shared_ptr<ConnectedPlayer>> ReceivingPlayers;
653 
656  std::map<ObjectID, Connection*> ActiveLocalControl;
657 
659  std::shared_ptr<Connection> ClientToServerConnection;
660 
662  std::vector<ObjectID> OurActiveLocalControl;
663 
665  WorldNetworkSettings NetworkSettings;
666 
667  // //! List of newly created entities that need to be created (or they have added new
668  // //! components and the initial value needs to be sent again)
669  // std::vector<ObjectID> NewlyCreatedEntities;
670 
671  // Entities //
672  std::vector<ObjectID> Entities;
673 
674  // Parented entities, used to destroy children
675  // First is the parent, second is child
676  std::vector<std::tuple<ObjectID, ObjectID>> Parents;
677 
679  const int ID;
680 
683  const int32_t WorldType;
684 
687  int TickNumber = 0;
688 
690  std::string DecoratedName;
691 
693  ObjectID CameraEntity = 0;
694 
698  Camera* AppliedCameraPropertiesPtr = nullptr;
699 
702  bool TickInProgress = false;
703 
705  bool TickWhileInBackground = false;
706 
712  bool InBackground = true;
713 
715  Mutex DeleteMutex;
716 
718  std::vector<ObjectID> DelayedDeleteIDS;
719 
720  // //! If true any pointers to this world are invalid
721  // std::shared_ptr<bool> WorldDestroyed = std::make_shared<bool>(false);
722 };
723 
724 } // namespace Leviathan
725 
726 #ifdef LEAK_INTO_GLOBAL
728 using Leviathan::ObjectID;
729 #endif
DLLEXPORT bs::HSceneObject GetCameraSceneObject()
Returns the scene object the camera is attached to.
Definition: GameWorld.cpp:474
virtual DLLEXPORT std::tuple< void *, ComponentTypeInfo, bool > GetComponentWithType(ObjectID id, COMPONENT_TYPE type)
Gets a component of type or returns nullptr.
Definition: GameWorld.cpp:1051
DLLEXPORT asIScriptObject * GetScriptSystem(const std::string &name)
Returns the underlying angelscript object that implements a script system.
Definition: GameWorld.cpp:1721
virtual DLLEXPORT void _DoSuspendSystems()
Called when this is put in the background and systems (the sound system) should suspend their active ...
Definition: GameWorld.cpp:1131
DLLEXPORT ObjectID CreateEntity()
Creates a new empty entity and returns its id.
Definition: GameWorld.cpp:815
DLLEXPORT const auto & GetEntities() const
Returns the created entity id vector.
Definition: GameWorld.h:126
int32_t ObjectID
Definition: EntityCommon.h:11
DLLEXPORT bool RegisterScriptComponentType(const std::string &name, asIScriptFunction *factory)
Registers a component type from scripts.
Definition: GameWorld.cpp:1642
DLLEXPORT void SetEntitysParent(ObjectID child, ObjectID parent)
Makes child entity be deleted when parent is deleted.
Definition: GameWorld.cpp:1041
virtual DLLEXPORT void OnLinkToWindow(Window *window, Graphics *graphics)
Called when this is added to a Window.
Definition: GameWorld.cpp:1765
DLLEXPORT void HandleEntityPacket(ResponseEntityUpdate &&message, Connection &connection)
Applies an entity update packet.
Definition: GameWorld.cpp:1272
COMPONENT_TYPE
Must contain all valid Component types.
Definition: Component.h:21
virtual DLLEXPORT void _DoSystemsRelease()
Called in Release when systems should run their shutdown logic.
Definition: GameWorld.cpp:1115
virtual DLLEXPORT void DestroyAllIn(ObjectID id)
Removes all components from an entity.
Definition: GameWorld.cpp:1164
PhysicalWorld * GetPhysicalWorld()
Definition: GameWorld.h:329
RECEIVE_GUARANTEE
Controls whether a packet is critical.
Definition: CommonNetwork.h:49
virtual DLLEXPORT void _CreateSendableComponentForEntity(ObjectID id)
Called when this base class wants to create a Sendable component.
Definition: GameWorld.cpp:1151
virtual DLLEXPORT void _ApplyLocalControlUpdateMessage(ObjectID id, int32_t ticknumber, sf::Packet &data, int32_t referencetick, int decodedtype)
Called to apply local control from a clients message.
Definition: GameWorld.cpp:640
DLLEXPORT void SetLightProperties(const Float3 &colour, float intensity=0.0001f, const Float3 &direction=Float3(0.55f, -0.3f, 0.75f), float sourceradius=0.5f, bool castsshadows=true)
Sets the sunlight properties.
Definition: GameWorld.cpp:338
DLLEXPORT int GetID() const
Definition: GameWorld.h:335
DLLEXPORT CScriptArray * GetRemovedIDsForComponents(CScriptArray *componenttypes)
Returns a list of ObjectIDs that have been removed from any of the specified component types.
Definition: GameWorld.cpp:1552
DLLEXPORT void SetLocalControl(ObjectID id, bool enabled, const std::shared_ptr< Connection > &allowedconnection)
Sets local control on a client over an entity or disables it.
Definition: GameWorld.cpp:1444
virtual DLLEXPORT void _CreateReceivedComponentForEntity(ObjectID id)
Called when this base class wants to create a Received component.
Definition: GameWorld.cpp:1157
virtual DLLEXPORT bool GetAddedFor(COMPONENT_TYPE type, std::vector< std::tuple< void *, ObjectID, ComponentTypeInfo >> &result)
Gets a list of created components of type.
Definition: GameWorld.cpp:1082
DLLEXPORT void QueueDestroyEntity(ObjectID id)
Deletes an entity during the next tick.
Definition: GameWorld.cpp:911
virtual DLLEXPORT void HandleAddedAndDeleted()
Handles added entities and components.
Definition: GameWorld.cpp:722
DLLEXPORT bool IsConnectionInWorld(Connection &connection) const
Returns true if a player with the given connection is receiving updates for this world.
Definition: GameWorld.cpp:485
DLLEXPORT bool GetRemovedForScriptDefined(const std::string &name, std::vector< std::tuple< asIScriptObject *, ObjectID >> &result)
Variant of GetRemovedFor for script defined types.
Definition: GameWorld.cpp:1068
ComponentTypeInfo(uint16_t ltype, int astype)
Definition: GameWorld.h:37
DLLEXPORT void ApplyQueuedPackets()
Applies packets that were received out of order. And throws out any too old packets.
Definition: GameWorld.cpp:1484
virtual DLLEXPORT void _ResetOrReleaseComponents()
Resets components in holders. Used together with _ResetSystems.
Definition: GameWorld.cpp:757
virtual DLLEXPORT void OnUnLinkedFromWindow(Window *window, Graphics *graphics)
Used to detect that this world is in the background and should not tick.
Definition: GameWorld.cpp:1738
DLLEXPORT void SetSunlight()
Definition: GameWorld.cpp:271
DLLEXPORT const auto & GetNetworkSettings() const
Definition: GameWorld.h:346
DLLEXPORT void SetWorldPhysicsFrozenState(bool frozen)
Definition: GameWorld.cpp:1185
DLLEXPORT const auto & GetServerForLocalControl() const
Definition: GameWorld.h:414
DLLEXPORT size_t GetEntityCount() const
Returns the number of ObjectIDs this world keeps track of.
Definition: GameWorld.h:120
TComponent & GetComponent(ObjectID id)
Definition: GameWorld.h:205
virtual DLLEXPORT void _CreateStatesFromUpdateMessage(ObjectID id, int32_t ticknumber, sf::Packet &data, int32_t referencetick, int decodedtype)
Called to deserialize entity component states from a packet.
Definition: GameWorld.cpp:632
DLLEXPORT CScriptArray * GetRemovedIDsForScriptComponents(CScriptArray *typenames)
Returns a list of ObjectIDs that have been removed from any of the script registered component types ...
Definition: GameWorld.cpp:1596
Entity has position and direction it is looking at.
Definition: Components.h:34
DLLEXPORT int32_t GetType() const
Definition: GameWorld.h:341
DLLEXPORT ~GameWorld()
Definition: GameWorld.cpp:92
DLLEXPORT bool Init(const WorldNetworkSettings &network, Graphics *graphics)
Creates resources for the world to work.
Definition: GameWorld.cpp:103
DLLEXPORT const auto & GetOurLocalControl() const
Definition: GameWorld.h:390
DLLEXPORT float GetTickProgress() const
Returns float between 0.f and 1.f based on how far current tick has progressed.
Definition: GameWorld.cpp:790
DLLEXPORT bool ShouldPlayerReceiveEntity(Position &atposition, Connection &connection)
Returns true when the player matching the connection should receive updates about an entity.
Definition: GameWorld.cpp:479
DLLEXPORT void SetServerForLocalControl(const std::shared_ptr< Connection > &connection)
Sets a connection that will be used to send local control entity updates to the server.
Definition: GameWorld.h:409
unsigned short uint16_t
Definition: core.h:39
std::mutex Mutex
Definition: ThreadSafe.h:16
bs::Scene * GetScene()
Definition: GameWorld.h:315
DLLEXPORT bool RegisterScriptSystem(const std::string &name, asIScriptObject *system)
Registers a new system defined in a script. Must implement the ScriptSystem interface.
Definition: GameWorld.cpp:1674
virtual DLLEXPORT void ClearAddedAndRemoved()
Clears the added components. Call after HandleAddedAndDeleted.
Definition: GameWorld.cpp:732
DLLEXPORT GameWorld(int32_t worldtype, const std::shared_ptr< PhysicsMaterialManager > &physicsMaterials, int worldid=-1)
Definition: GameWorld.cpp:85
StateHolder< typename TComponent::StateT > & GetStatesFor()
Definition: GameWorld.h:253
virtual DLLEXPORT void CaptureEntityState(ObjectID id, EntityState &curstate) const
Captures the current state of an entity.
Definition: GameWorld.cpp:615
DLLEXPORT void RemoveSunlight()
Definition: GameWorld.cpp:295
virtual DLLEXPORT void _OnLocalControlUpdatedEntity(ObjectID id, int32_t ticknumber)
This method is for doing checks after applying client sent state to the server.
Definition: GameWorld.cpp:1470
DLLEXPORT std::tuple< int, int > GetTickAndTime() const
Returns a tuple of the current tick number and how long it has passed since last tick.
Definition: GameWorld.cpp:800
DLLEXPORT void Release()
Release resources.
Definition: GameWorld.cpp:130
A class that represents a human player.
virtual DLLEXPORT void RunFrameRenderSystems(int tick, int timeintick)
Called by Render which is called from a Window if this is linked to one.
Definition: GameWorld.cpp:771
DLLEXPORT void Render(int mspassed, int tick, int timeintick)
Runs systems required for a rendering run. Also updates camera positions.
Definition: GameWorld.cpp:369
virtual DLLEXPORT void _CreateComponentsFromCreationMessage(ObjectID id, sf::Packet &data, int entriesleft, int decodedtype)
Called to deserialize initial entity components and their static state.
Definition: GameWorld.cpp:622
DLLEXPORT ScriptComponentHolder * GetScriptComponentHolder(const std::string &name)
Retrieves a script registered component type holder.
Definition: GameWorld.cpp:1659
DLLEXPORT bool IsUnderOurLocalControl(ObjectID id)
Definition: GameWorld.h:399
Properties that a camera entity has (will also need a Position component)
Definition: Components.h:713
Class that handles a single connection to another instance.
Definition: Connection.h:105
DLLEXPORT void Tick(int currenttick)
Used to keep track of passed ticks and trigger timed triggers.
Definition: GameWorld.cpp:647
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT void SetCamera(ObjectID object)
Sets the entity that acts as a camera.
Definition: GameWorld.cpp:435
DLLEXPORT void MarkForClear()
Marks all entities to be deleted.
Definition: GameWorld.cpp:1245
virtual DLLEXPORT void _DoResumeSystems()
Opposite of _DoSuspendSystems.
Definition: GameWorld.cpp:1141
virtual DLLEXPORT void _RunTickSystems()
Called by Tick.
Definition: GameWorld.cpp:780
DLLEXPORT bool GetAddedForScriptDefined(const std::string &name, std::vector< std::tuple< asIScriptObject *, ObjectID, ScriptComponentHolder * >> &result)
Variant of GetAddedFor for script defined types.
Definition: GameWorld.cpp:1088
virtual DLLEXPORT uint32_t CaptureEntityStaticState(ObjectID id, sf::Packet &receiver) const
Captures the initial parameters of an entity with components that don't have current state synchroniz...
Definition: GameWorld.cpp:617
DLLEXPORT void ClearEntities()
Clears all objects from the world.
Definition: GameWorld.cpp:842
Holds state objects of type for quick access by ObjectID.
Definition: GameWorld.h:31
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Holder of state for a whole entity.
unsigned int uint32_t
Definition: core.h:40
Entity is sendable to clients.
Definition: Components.h:115
virtual DLLEXPORT void SetRunInBackground(bool tickinbackground)
Configures this world to run tick even when not attached to a window.
Definition: GameWorld.cpp:1801
DLLEXPORT bool DoesEntityExist(ObjectID id) const
Returns true if entity exists.
Definition: GameWorld.h:186
DLLEXPORT void SetSkybox(const std::string &skyboxname, float brightness=1.f)
Definition: GameWorld.cpp:305
virtual DLLEXPORT bool GetRemovedFor(COMPONENT_TYPE type, std::vector< std::tuple< void *, ObjectID >> &result)
Gets a list of destroyed components of type.
Definition: GameWorld.cpp:1062
DLLEXPORT void SetPlayerReceiveWorld(std::shared_ptr< ConnectedPlayer > ply)
Verifies that player is receiving this world.
Definition: GameWorld.cpp:498
DLLEXPORT int GetTickNumber() const
Returns the current tick.
Definition: GameWorld.h:142
virtual DLLEXPORT void _DoSystemsInit()
Called in Init when systems should run their initialization logic.
Definition: GameWorld.cpp:1110
virtual DLLEXPORT void _ResetSystems()
Resets stored nodes in systems. Used together with _ResetComponents.
Definition: GameWorld.cpp:743
const auto & GetConnectedPlayers() const
This is used by Sendable system to loop all players.
Definition: GameWorld.h:374
bool GraphicalMode
If false a graphical Ogre window hasn't been created and purely graphical stuff should be skipped.
Definition: GameWorld.h:616
DLLEXPORT bool UnregisterScriptSystem(const std::string &name)
Unregisters a script system that was registered with RegisterScriptSystem.
Definition: GameWorld.cpp:1703
DLLEXPORT void DestroyEntity(ObjectID id)
Destroys an entity and all of its components.
Definition: GameWorld.cpp:887
REFERENCE_HANDLE_UNCOUNTED_TYPE(GameWorld)
DLLEXPORT bs::Ray CastRayFromCamera(int x, int y) const
Casts a ray from the active camera.
Definition: GameWorld.cpp:460
DLLEXPORT void SendToAllPlayers(const std::shared_ptr< NetworkResponse > &response, RECEIVE_GUARANTEE guarantee) const
Sends a packet to all connected players.
Definition: GameWorld.cpp:598
int32_t Scene
Definition: Define.h:68
DLLEXPORT int GetPhysicalMaterial(const std::string &name)
Fetches the physical material ID from the material manager.
Definition: GameWorld.cpp:879
Represents a world that contains entities.
Definition: GameWorld.h:94
TComponent * GetComponentPtr(ObjectID id)
Definition: GameWorld.h:225