SEGS  0.6.1-develop [3e741b81]
Super Entity Game Server
EntityStorage.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 
10 #include "GameData/Entity.h"
11 #include "GameData/EntityHelpers.h"
12 
13 #include <ace/Thread_Mutex.h>
14 #include <ace/Guard_T.h>
15 #include <array>
16 #include <set>
17 #include <deque>
18 
19 struct MapClientSession;
20 class MapInstance;
21 class Entity;
22 class BitStream;
23 
25 {
26 public:
27  EntityStore();
28  std::deque<uint32_t> m_free_entries;
29  std::array<Entity,10240> m_map_entities;
30  Entity *get();
31  void release(Entity *src);
32 };
33 
35 {
36  struct EntityIdxCompare
37  {
38  bool operator()(const Entity *a,const Entity *b) const
39  {
40  return getIdx(*a) < getIdx(*b);
41  }
42  };
43  using lEntity = std::set<Entity *,EntityIdxCompare>;
44 public:
46  lEntity m_live_entlist;
47  EntityManager();
48  void sendDebuggedEntities(BitStream &tgt) const;
49  void sendGlobalEntDebugInfo(BitStream &tgt) const;
50  void sendDeletes(BitStream &tgt, MapClientSession &client) const;
51  void sendEntities(BitStream &tgt, MapClientSession &target, bool is_incremental) const;
52  void InsertPlayer(Entity *);
53  Entity * CreatePlayer();
54  Entity * CreateNpc(const GameDataStore &data, const Parse_NPC &tpl, int idx, int variant);
55  Entity * CreateGeneric(const GameDataStore &data, const Parse_NPC &tpl, int idx, int variant, EntType type);
56  Entity * CreateCritter(const GameDataStore &data,const Parse_NPC &tpl,int idx,int variant, int level);
57  void removeEntityFromActiveList(Entity *ent);
58  size_t active_entities() { return m_live_entlist.size(); }
59  ACE_Thread_Mutex &getEntitiesMutex() { return m_mutex; }
60 
61 protected:
62  mutable ACE_Thread_Mutex m_mutex; // used to prevent world state reads during updates
63 };
Definition: EntityStorage.h:34
Definition: MapClientSession.h:32
ACE_Thread_Mutex & getEntitiesMutex()
Definition: EntityStorage.h:59
Definition: GameDataStore.h:27
Definition: BitStream.h:34
size_t active_entities()
Definition: EntityStorage.h:58
ACE_Thread_Mutex m_mutex
Definition: EntityStorage.h:62
Definition: MapInstance.h:132
EntityStore m_store
Definition: EntityStorage.h:45
Definition: npc_definitions.h:57
Definition: Entity.h:134
void release(Entity *src)
Definition: EntityStorage.cpp:48
EntType
Definition: Entity.h:57
EntityStore()
Definition: EntityStorage.cpp:23
lEntity m_live_entlist
Definition: EntityStorage.h:46
Definition: EntityStorage.h:24
std::array< Entity, 10240 > m_map_entities
Definition: EntityStorage.h:29
uint32_t getIdx(const Entity &e)
Definition: EntityHelpers.cpp:25
std::deque< uint32_t > m_free_entries
Definition: EntityStorage.h:28