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-2018 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 
14 
15 class CScriptArray;
16 class asIScriptObject;
17 class asIScriptFunction;
18 
19 namespace Ogre {
20 
21 class CompositorWorkspace;
22 class Plane;
23 } // namespace Ogre
24 
25 namespace Leviathan {
26 
27 class Camera;
28 class PhysicalWorld;
29 class ScriptComponentHolder;
30 class ResponseEntityCreation;
31 class ResponseEntityDestruction;
32 class ResponseEntityUpdate;
33 class ResponseEntityLocalControlStatus;
34 
35 template<class StateT>
37 
38 class EntityState;
39 
41 
42  inline ComponentTypeInfo(uint16_t ltype, int astype) :
43  LeviathanType(ltype), AngelScriptType(astype)
44  {}
45 
48 };
49 
50 
51 #define WORLD_CLOCK_SYNC_PACKETS 12
52 #define WORLD_CLOCK_SYNC_ALLOW_FAILS 2
53 #define WORLD_OBJECT_UPDATE_CLIENTS_INTERVAL 2
54 
55 // //! Holds the returned entity that was hit during ray casting
56 // //! \todo Move to a new file
57 // class RayCastHitEntity : public ReferenceCounted {
58 // public:
59 // DLLEXPORT RayCastHitEntity(const NewtonBody* ptr = nullptr, const float& tvar = 0.f,
60 // RayCastData* ownerptr = nullptr);
61 
62 // DLLEXPORT RayCastHitEntity& operator=(const RayCastHitEntity& other);
63 
64 // // Compares the hit entity with nullptr //
65 // DLLEXPORT bool HasHit();
66 
67 // DLLEXPORT Float3 GetPosition();
68 
69 // DLLEXPORT bool DoesBodyMatchThisHit(NewtonBody* other);
70 
71 // //! Stores the entity, typed as NewtonBody to make sure that user knows
72 // //! what should be compared with this
73 // const NewtonBody* HitEntity;
74 
75 // //! The distance from the start of the ray to the hit location
76 // float HitVariable;
77 // Float3 HitLocation;
78 // };
79 
80 // // Internal object in ray casts //
81 // struct RayCastData {
82 // DLLEXPORT RayCastData(int maxcount, const Float3& from, const Float3& to);
83 // DLLEXPORT ~RayCastData();
84 
85 // // All hit entities that pass checks //
86 // std::vector<RayCastHitEntity*> HitEntities;
87 // // Used to stop after certain amount of entities found //
88 // int MaxCount;
89 // // Used to efficiently calculate many hit locations //
90 // Float3 BaseHitLocationCalcVar;
91 // };
92 
99 class GameWorld {
100  class Implementation;
101 
102 public:
105  DLLEXPORT GameWorld(int32_t worldtype,
106  const std::shared_ptr<PhysicsMaterialManager>& physicsMaterials, int worldid = -1);
108 
111  DLLEXPORT bool Init(const WorldNetworkSettings& network, Ogre::Root* ogre);
112 
114  DLLEXPORT void Release();
115 
117  DLLEXPORT void MarkForClear();
118 
120  DLLEXPORT void ClearEntities();
121 
125  DLLEXPORT size_t GetEntityCount() const
126  {
127  return Entities.size();
128  }
129 
131  DLLEXPORT inline const auto& GetEntities() const
132  {
133  return Entities;
134  }
135 
140  DLLEXPORT void Tick(int currenttick);
141 
144  DLLEXPORT void Render(int mspassed, int tick, int timeintick);
145 
147  DLLEXPORT inline int GetTickNumber() const
148  {
149  return TickNumber;
150  }
151 
153  DLLEXPORT float GetTickProgress() const;
154 
159  DLLEXPORT std::tuple<int, int> GetTickAndTime() const;
160 
161 
164  DLLEXPORT int GetPhysicalMaterial(const std::string& name);
165 
166 
167  // //! \brief Casts a ray from point along a vector and returns the first physical
168  // //! object it hits
169  // //! \warning You need to call Release on the returned object once done
170  // DLLEXPORT RayCastHitEntity* CastRayGetFirstHit(const Float3& from, const Float3& to);
171 
175 
182 
185 
188  DLLEXPORT void SetEntitysParent(ObjectID child, ObjectID parent);
189 
192  {
193  for(const auto& entity : Entities) {
194  if(id == entity)
195  return true;
196  }
197 
198  return false;
199  }
200 
201 
203  DLLEXPORT virtual void DestroyAllIn(ObjectID id);
204 
209  template<class TComponent>
210  TComponent& GetComponent(ObjectID id)
211  {
212  std::tuple<void*, bool> component = GetComponent(id, TComponent::TYPE);
213 
214  if(!std::get<1>(component))
215  throw InvalidArgument("Unrecognized component type as template parameter");
216 
217  void* ptr = std::get<0>(component);
218 
219  if(!ptr)
220  throw NotFound("Component for entity with id was not found");
221 
222  return *static_cast<TComponent*>(ptr);
223  }
224 
229  template<class TComponent>
230  TComponent* GetComponentPtr(ObjectID id)
231  {
232  std::tuple<void*, bool> component = GetComponent(id, TComponent::TYPE);
233 
234  void* ptr = std::get<0>(component);
235 
236  if(!ptr)
237  return nullptr;
238 
239  return static_cast<TComponent*>(ptr);
240  }
241 
245  DLLEXPORT virtual std::tuple<void*, bool> GetComponent(ObjectID id, COMPONENT_TYPE type);
246 
250  DLLEXPORT virtual std::tuple<void*, ComponentTypeInfo, bool> GetComponentWithType(
251  ObjectID id, COMPONENT_TYPE type);
252 
257  template<class TComponent>
259  {
260  std::tuple<void*, bool> stateHolder = GetStatesFor(TComponent::TYPE);
261 
262  if(!std::get<1>(stateHolder))
263  throw InvalidArgument("Unrecognized component type as template parameter for "
264  "state holder");
265 
266  void* ptr = std::get<0>(stateHolder);
267 
268  return *static_cast<StateHolder<typename TComponent::StateT>*>(ptr);
269  }
270 
274  DLLEXPORT virtual std::tuple<void*, bool> GetStatesFor(COMPONENT_TYPE type);
275 
279  DLLEXPORT virtual bool GetRemovedFor(
280  COMPONENT_TYPE type, std::vector<std::tuple<void*, ObjectID>>& result);
281 
284  const std::string& name, std::vector<std::tuple<asIScriptObject*, ObjectID>>& result);
285 
290  DLLEXPORT virtual bool GetAddedFor(COMPONENT_TYPE type,
291  std::vector<std::tuple<void*, ObjectID, ComponentTypeInfo>>& result);
292 
294  DLLEXPORT bool GetAddedForScriptDefined(const std::string& name,
295  std::vector<std::tuple<asIScriptObject*, ObjectID, ScriptComponentHolder*>>& result);
296 
298  DLLEXPORT virtual void CaptureEntityState(ObjectID id, EntityState& curstate) const;
299 
304  ObjectID id, sf::Packet& receiver) const;
305 
310  DLLEXPORT void SetCamera(ObjectID object);
311 
317  DLLEXPORT Ogre::Ray CastRayFromCamera(float x, float y) const;
318 
319  // Ogre get functions //
320  inline Ogre::SceneManager* GetScene()
321  {
322  return WorldsScene;
323  }
324 
325  // physics functions //
326  // DLLEXPORT Float3 GetGravityAtPosition(const Float3& pos);
327 
329  {
330  return _PhysicalWorld.get();
331  }
332 
334  DLLEXPORT inline int GetID() const
335  {
336  return ID;
337  }
338 
340  DLLEXPORT inline int32_t GetType() const
341  {
342  return WorldType;
343  }
344 
345  DLLEXPORT inline const auto& GetNetworkSettings() const
346  {
347  return NetworkSettings;
348  }
349 
351  DLLEXPORT void SetWorldPhysicsFrozenState(bool frozen);
352 
353  // Script proxies //
354 
355  //
356  // Networking methods
357  //
358 
362  DLLEXPORT bool ShouldPlayerReceiveEntity(Position& atposition, Connection& connection);
363 
366  DLLEXPORT bool IsConnectionInWorld(Connection& connection) const;
367 
369  DLLEXPORT void SetPlayerReceiveWorld(std::shared_ptr<ConnectedPlayer> ply);
370 
373  inline const auto& GetConnectedPlayers() const
374  {
375  return ReceivingPlayers;
376  }
377 
380  const std::shared_ptr<NetworkResponse>& response, RECEIVE_GUARANTEE guarantee) const;
381 
386  ObjectID id, bool enabled, const std::shared_ptr<Connection>& allowedconnection);
387 
389  DLLEXPORT const auto& GetOurLocalControl() const
390  {
391  return OurActiveLocalControl;
392  }
393 
399  {
400  for(const auto& entity : OurActiveLocalControl)
401  if(entity == id)
402  return true;
403  return false;
404  }
405 
408  DLLEXPORT void SetServerForLocalControl(const std::shared_ptr<Connection>& connection)
409  {
410  ClientToServerConnection = connection;
411  }
412 
414  {
415  return ClientToServerConnection;
416  }
417 
423  DLLEXPORT void HandleEntityPacket(ResponseEntityUpdate&& message, Connection& connection);
424 
426  DLLEXPORT ObjectID HandleEntityPacket(ResponseEntityCreation& message);
427 
428  DLLEXPORT void HandleEntityPacket(ResponseEntityDestruction& message);
429 
430  DLLEXPORT void HandleEntityPacket(ResponseEntityLocalControlStatus& message);
431 
432  // //! \brief Handles a world clock synchronizing packet
433  // //! \note This should only be allowed to be called on a client that has connected
434  // //! to a server
435  // DLLEXPORT void HandleClockSyncPacket(RequestWorldClockSync* data);
436 
437  // //! \brief Handles a world freeze/unfreeze packet
438  // //! \note Should only be called on a client
439  // DLLEXPORT void HandleWorldFrozenPacket(ResponseWorldFrozen* data);
440 
442  DLLEXPORT void SetFog();
443 
444  DLLEXPORT void SetSunlight();
445  DLLEXPORT void RemoveSunlight();
448  DLLEXPORT void SetLightProperties(const Ogre::ColourValue& diffuse,
449  const Ogre::ColourValue& specular, const Ogre::Vector3& direction, float power,
450  const Ogre::ColourValue& upperhemisphere, const Ogre::ColourValue& lowerhemisphere,
451  const Ogre::Vector3& hemispheredir, float envmapscale = 1.0f);
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, Ogre::Root* ogre);
492 
495  DLLEXPORT virtual void OnLinkToWindow(Window* window, Ogre::Root* ogre);
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 _CreateOgreResources(Ogre::Root* ogre);
596  void _HandleDelayedDelete();
597 
599  void _ReportEntityDestruction(ObjectID id);
600 
603  void _DoDestroy(ObjectID id);
604 
606  void _SendEntityUpdates(ObjectID id, Sendable& sendable, int tick);
607 
608 
609 protected:
614  bool GraphicalMode = false;
615 
616 private:
617  // pimpl to reduce need of including tons of headers (this causes
618  // a double pointer dereference so don't put performance critical
619  // stuff here)
620  std::unique_ptr<Implementation> pimpl;
621 
622  Ogre::Camera* WorldSceneCamera = nullptr;
623  Ogre::SceneManager* WorldsScene = nullptr;
624 
625  Ogre::CompositorWorkspace* WorldWorkspace = nullptr;
626 
628  Window* LinkedToWindow = nullptr;
629 
630  Ogre::Light* Sunlight = nullptr;
631  Ogre::SceneNode* SunLightNode = nullptr;
632 
633  // physics //
634  std::shared_ptr<PhysicsMaterialManager> PhysicsMaterials;
635  std::shared_ptr<PhysicalWorld> _PhysicalWorld;
636 
638  bool WorldFrozen = false;
639 
640 
642  bool ClearAllEntities = false;
643 
647  std::vector<std::shared_ptr<ConnectedPlayer>> ReceivingPlayers;
648 
651  std::map<ObjectID, Connection*> ActiveLocalControl;
652 
654  std::shared_ptr<Connection> ClientToServerConnection;
655 
657  std::vector<ObjectID> OurActiveLocalControl;
658 
660  WorldNetworkSettings NetworkSettings;
661 
662  // //! List of newly created entities that need to be created (or they have added new
663  // //! components and the initial value needs to be sent again)
664  // std::vector<ObjectID> NewlyCreatedEntities;
665 
666  // Entities //
667  std::vector<ObjectID> Entities;
668 
669  // Parented entities, used to destroy children
670  // First is the parent, second is child
671  std::vector<std::tuple<ObjectID, ObjectID>> Parents;
672 
674  const int ID;
675 
678  const int32_t WorldType;
679 
682  int TickNumber = 0;
683 
685  std::string DecoratedName;
686 
688  ObjectID CameraEntity = 0;
689 
693  Camera* AppliedCameraPropertiesPtr = nullptr;
694 
697  bool TickInProgress = false;
698 
700  bool TickWhileInBackground = false;
701 
707  bool InBackground = true;
708 
710  Mutex DeleteMutex;
711 
713  std::vector<ObjectID> DelayedDeleteIDS;
714 
716  std::shared_ptr<bool> WorldDestroyed = std::make_shared<bool>(false);
717 };
718 
719 } // namespace Leviathan
720 
721 #ifdef LEAK_INTO_GLOBAL
723 using Leviathan::ObjectID;
724 #endif
virtual DLLEXPORT void OnLinkToWindow(Window *window, Ogre::Root *ogre)
Called when this is added to a Window.
Definition: GameWorld.cpp:1668
virtual DLLEXPORT std::tuple< void *, ComponentTypeInfo, bool > GetComponentWithType(ObjectID id, COMPONENT_TYPE type)
Gets a component of type or returns nullptr.
Definition: GameWorld.cpp:956
DLLEXPORT asIScriptObject * GetScriptSystem(const std::string &name)
Returns the underlying angelscript object that implements a script system.
Definition: GameWorld.cpp:1626
virtual DLLEXPORT void _DoSuspendSystems()
Called when this is put in the background and systems (the sound system) should suspend their active ...
Definition: GameWorld.cpp:1036
DLLEXPORT ObjectID CreateEntity()
Creates a new empty entity and returns its id.
Definition: GameWorld.cpp:720
DLLEXPORT const auto & GetEntities() const
Returns the created entity id vector.
Definition: GameWorld.h:131
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:1547
DLLEXPORT void SetEntitysParent(ObjectID child, ObjectID parent)
Makes child entity be deleted when parent is deleted.
Definition: GameWorld.cpp:946
DLLEXPORT bool Init(const WorldNetworkSettings &network, Ogre::Root *ogre)
Creates resources for the world to work.
Definition: GameWorld.cpp:91
DLLEXPORT void HandleEntityPacket(ResponseEntityUpdate &&message, Connection &connection)
Applies an entity update packet.
Definition: GameWorld.cpp:1177
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:1020
virtual DLLEXPORT void DestroyAllIn(ObjectID id)
Removes all components from an entity.
Definition: GameWorld.cpp:1069
PhysicalWorld * GetPhysicalWorld()
Definition: GameWorld.h:328
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:1056
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:545
DLLEXPORT int GetID() const
Definition: GameWorld.h:334
DLLEXPORT CScriptArray * GetRemovedIDsForComponents(CScriptArray *componenttypes)
Returns a list of ObjectIDs that have been removed from any of the specified component types...
Definition: GameWorld.cpp:1457
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:1349
Ogre::SceneManager * GetScene()
Definition: GameWorld.h:320
virtual DLLEXPORT void _CreateReceivedComponentForEntity(ObjectID id)
Called when this base class wants to create a Received component.
Definition: GameWorld.cpp:1062
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:987
DLLEXPORT void QueueDestroyEntity(ObjectID id)
Deletes an entity during the next tick.
Definition: GameWorld.cpp:816
virtual DLLEXPORT void HandleAddedAndDeleted()
Handles added entities and components.
Definition: GameWorld.cpp:627
DLLEXPORT bool IsConnectionInWorld(Connection &connection) const
Returns true if a player with the given connection is receiving updates for this world.
Definition: GameWorld.cpp:390
DLLEXPORT bool GetRemovedForScriptDefined(const std::string &name, std::vector< std::tuple< asIScriptObject *, ObjectID >> &result)
Variant of GetRemovedFor for script defined types.
Definition: GameWorld.cpp:973
ComponentTypeInfo(uint16_t ltype, int astype)
Definition: GameWorld.h:42
DLLEXPORT void ApplyQueuedPackets()
Applies packets that were received out of order. And throws out any too old packets.
Definition: GameWorld.cpp:1389
DLLEXPORT void SetFog()
Definition: GameWorld.cpp:209
virtual DLLEXPORT void _ResetOrReleaseComponents()
Resets components in holders. Used together with _ResetSystems.
Definition: GameWorld.cpp:662
DLLEXPORT void SetSunlight()
Definition: GameWorld.cpp:215
DLLEXPORT const auto & GetNetworkSettings() const
Definition: GameWorld.h:345
DLLEXPORT void SetWorldPhysicsFrozenState(bool frozen)
Definition: GameWorld.cpp:1090
DLLEXPORT const auto & GetServerForLocalControl() const
Definition: GameWorld.h:413
DLLEXPORT size_t GetEntityCount() const
Returns the number of ObjectIDs this world keeps track of.
Definition: GameWorld.h:125
TComponent & GetComponent(ObjectID id)
Definition: GameWorld.h:210
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:537
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:1501
Entity has position and direction it is looking at.
Definition: Components.h:38
DLLEXPORT int32_t GetType() const
Definition: GameWorld.h:340
DLLEXPORT ~GameWorld()
Definition: GameWorld.cpp:80
DLLEXPORT const auto & GetOurLocalControl() const
Definition: GameWorld.h:389
DLLEXPORT float GetTickProgress() const
Returns float between 0.f and 1.f based on how far current tick has progressed.
Definition: GameWorld.cpp:695
DLLEXPORT bool ShouldPlayerReceiveEntity(Position &atposition, Connection &connection)
Returns true when the player matching the connection should receive updates about an entity...
Definition: GameWorld.cpp:384
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:408
unsigned short uint16_t
Definition: core.h:39
std::mutex Mutex
Definition: ThreadSafe.h:16
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:1579
virtual DLLEXPORT void ClearAddedAndRemoved()
Clears the added components. Call after HandleAddedAndDeleted.
Definition: GameWorld.cpp:637
DLLEXPORT GameWorld(int32_t worldtype, const std::shared_ptr< PhysicsMaterialManager > &physicsMaterials, int worldid=-1)
Definition: GameWorld.cpp:73
DLLEXPORT Ogre::Ray CastRayFromCamera(float x, float y) const
Casts a ray from the active camera.
Definition: GameWorld.cpp:370
StateHolder< typename TComponent::StateT > & GetStatesFor()
Definition: GameWorld.h:258
virtual DLLEXPORT void CaptureEntityState(ObjectID id, EntityState &curstate) const
Captures the current state of an entity.
Definition: GameWorld.cpp:520
DLLEXPORT void RemoveSunlight()
Definition: GameWorld.cpp:249
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:1375
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:705
DLLEXPORT void Release()
Release to not use Ogre when deleting.
Definition: GameWorld.cpp:118
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:676
DLLEXPORT void Render(int mspassed, int tick, int timeintick)
Runs systems required for a rendering run. Also updates camera positions.
Definition: GameWorld.cpp:279
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:527
DLLEXPORT ScriptComponentHolder * GetScriptComponentHolder(const std::string &name)
Retrieves a script registered component type holder.
Definition: GameWorld.cpp:1564
DLLEXPORT bool IsUnderOurLocalControl(ObjectID id)
Definition: GameWorld.h:398
Properties that a camera entity has (will also need a Position component)
Definition: Components.h:699
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:552
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:993
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT void SetCamera(ObjectID object)
Sets the entity that acts as a camera.
Definition: GameWorld.cpp:345
DLLEXPORT void MarkForClear()
Marks all entities to be deleted.
Definition: GameWorld.cpp:1150
virtual DLLEXPORT void _DoResumeSystems()
Opposite of _DoSuspendSystems.
Definition: GameWorld.cpp:1046
virtual DLLEXPORT void OnUnLinkedFromWindow(Window *window, Ogre::Root *ogre)
Used to detect that this world is in the background and should not tick.
Definition: GameWorld.cpp:1643
virtual DLLEXPORT void _RunTickSystems()
Called by Tick.
Definition: GameWorld.cpp:685
virtual DLLEXPORT uint32_t CaptureEntityStaticState(ObjectID id, sf::Packet &receiver) const
Captures the initial parameters of an entity with components that don&#39;t have current state synchroniz...
Definition: GameWorld.cpp:522
DLLEXPORT void ClearEntities()
Clears all objects from the world.
Definition: GameWorld.cpp:747
Holds state objects of type for quick access by ObjectID.
Definition: GameWorld.h:36
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:112
virtual DLLEXPORT void SetRunInBackground(bool tickinbackground)
Configures this world to run tick even when not attached to a window.
Definition: GameWorld.cpp:1696
DLLEXPORT bool DoesEntityExist(ObjectID id) const
Returns true if entity exists.
Definition: GameWorld.h:191
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:967
DLLEXPORT void SetPlayerReceiveWorld(std::shared_ptr< ConnectedPlayer > ply)
Verifies that player is receiving this world.
Definition: GameWorld.cpp:403
DLLEXPORT int GetTickNumber() const
Returns the current tick.
Definition: GameWorld.h:147
DLLEXPORT void SetLightProperties(const Ogre::ColourValue &diffuse, const Ogre::ColourValue &specular, const Ogre::Vector3 &direction, float power, const Ogre::ColourValue &upperhemisphere, const Ogre::ColourValue &lowerhemisphere, const Ogre::Vector3 &hemispheredir, float envmapscale=1.0f)
Sets the sunlight properties.
Definition: GameWorld.cpp:259
virtual DLLEXPORT void _DoSystemsInit()
Called in Init when systems should run their initialization logic.
Definition: GameWorld.cpp:1015
virtual DLLEXPORT void _ResetSystems()
Resets stored nodes in systems. Used together with _ResetComponents.
Definition: GameWorld.cpp:648
const auto & GetConnectedPlayers() const
This is used by Sendable system to loop all players.
Definition: GameWorld.h:373
bool GraphicalMode
If false a graphical Ogre window hasn&#39;t been created and purely graphical stuff should be skipped...
Definition: GameWorld.h:614
DLLEXPORT bool UnregisterScriptSystem(const std::string &name)
Unregisters a script system that was registered with RegisterScriptSystem.
Definition: GameWorld.cpp:1608
DLLEXPORT void DestroyEntity(ObjectID id)
Destroys an entity and all of its components.
Definition: GameWorld.cpp:792
REFERENCE_HANDLE_UNCOUNTED_TYPE(GameWorld)
DLLEXPORT void SendToAllPlayers(const std::shared_ptr< NetworkResponse > &response, RECEIVE_GUARANTEE guarantee) const
Sends a packet to all connected players.
Definition: GameWorld.cpp:503
DLLEXPORT int GetPhysicalMaterial(const std::string &name)
Fetches the physical material ID from the material manager.
Definition: GameWorld.cpp:784
Represents a world that contains entities.
Definition: GameWorld.h:99
TComponent * GetComponentPtr(ObjectID id)
Definition: GameWorld.h:230