SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 
10 #include "NetStructures/Entity.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  bool operator()(const Entity *a,const Entity *b) const {
38  return getIdx(*a) < getIdx(*b);
39  }
40  };
41  using lEntity = std::set<Entity *,EntityIdxCompare>;
42 public:
44  lEntity m_live_entlist;
45  EntityManager();
46  void sendDebuggedEntities(BitStream &tgt) const;
47  void sendGlobalEntDebugInfo(BitStream &tgt) const;
48  void sendDeletes(BitStream &tgt, MapClientSession *client) const;
49  void sendEntities(BitStream &tgt, MapClientSession *target, bool is_incremental) const;
50  void InsertPlayer(Entity *);
51  Entity * CreatePlayer();
52  Entity * CreateNpc(const Parse_NPC &tpl, int idx, int variant);
54  size_t active_entities() { return m_live_entlist.size(); }
55  ACE_Thread_Mutex &getEntitiesMutex() { return m_mutex; }
56 
57 protected:
58  mutable ACE_Thread_Mutex m_mutex; // used to prevent world state reads during updates
59 };
Entity * CreateNpc(const Parse_NPC &tpl, int idx, int variant)
Definition: EntityStorage.cpp:155
Definition: EntityStorage.h:34
Definition: MapClientSession.h:32
ACE_Thread_Mutex & getEntitiesMutex()
Definition: EntityStorage.h:55
void sendEntities(BitStream &tgt, MapClientSession *target, bool is_incremental) const
Definition: EntityStorage.cpp:104
Definition: BitStream.h:30
size_t active_entities()
Definition: EntityStorage.h:54
EntityManager()
Definition: EntityStorage.cpp:55
ACE_Thread_Mutex m_mutex
Definition: EntityStorage.h:58
Definition: MapInstance.h:35
EntityStore m_store
Definition: EntityStorage.h:43
Definition: npc_definitions.h:57
Definition: Entity.h:221
void release(Entity *src)
Definition: EntityStorage.cpp:48
Entity * CreatePlayer()
Definition: EntityStorage.cpp:147
void sendGlobalEntDebugInfo(BitStream &tgt) const
Definition: EntityStorage.cpp:67
void sendDeletes(BitStream &tgt, MapClientSession *client) const
Definition: EntityStorage.cpp:80
void sendDebuggedEntities(BitStream &tgt) const
Definition: EntityStorage.cpp:59
void InsertPlayer(Entity *)
Definition: EntityStorage.cpp:142
EntityStore()
Definition: EntityStorage.cpp:23
lEntity m_live_entlist
Definition: EntityStorage.h:44
Definition: EntityStorage.h:24
void removeEntityFromActiveList(Entity *ent)
Definition: EntityStorage.cpp:164
uint32_t getIdx(const Entity &e)
Definition: DataHelpers.cpp:34
std::array< Entity, 10240 > m_map_entities
Definition: EntityStorage.h:29
std::deque< uint32_t > m_free_entries
Definition: EntityStorage.h:28