Recast  1
Game with custom magic
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Box2DWorld.h
Go to the documentation of this file.
1 
8 #ifndef RECAST_SERVER_BOX2DWORLD_H
9 #define RECAST_SERVER_BOX2DWORLD_H
10 
11 #include <vector>
12 #include <set>
13 #include <unordered_map>
14 #include "world/wrappers/Entity.h"
15 #include <Box2D/Box2D.h>
16 #include <boost/lockfree/queue.hpp>
17 
18 class Spell;
19 
20 class Server;
21 
22 class SpellEntity;
23 
24 class DelayedSpellCreate;
25 
26 class Box2DWorld : public b2DestructionListener, b2ContactListener {
27 public:
28  Box2DWorld(Server *server);
29 
30  ~Box2DWorld();
31 
32  void update();
33 
34  std::vector<Entity> getAllEntityInChunk(float x1, float x2);
35 
36  Entity *createEntity(b2BodyDef &bodyDef, b2FixtureDef &fixtureDef);
37 
38  SpellEntity *createSpellEntity(b2Vec2 position, Spell *spell);
39 
40  Entity *getEntityById(int id) { return entitysId[id]; }
41  void asyncCreateSpellEntity(b2Vec2 position, Spell *spell);
42  void subscribeToUpdate(Entity *entity) { needTickEntity.push_back(entity); }
43 
44  void SayGoodbye(b2Fixture *fixture);
45 
46  void SayGoodbye(b2Joint *joint) {}
47 
48  void BeginContact(b2Contact *contact);
49 
50 private:
51  b2World *world;
52  std::set<int> existGround; // Костыль божественной мощи
53  std::vector<Entity *> needTickEntity;
54  std::vector<Entity *> beDestroyed;
55  std::unordered_map<int, Entity *> entitysId;
56  boost::lockfree::queue<DelayedSpellCreate *, boost::lockfree::capacity <10>> delayedSpell;
57  Server *server;
58  int freeId = 0;
59 
60  void checkAndCreateGround(float x1, float x2);
61 
62  void checkAndCreateGround(float x);
63 
64  void executeAllDelayed();
65 };
66 
67 
68 #endif //RECAST_SERVER_BOX2DWORLD_H
Main class in Recast Server.
Definition: Server.hpp:37
SpellEntity * createSpellEntity(b2Vec2 position, Spell *spell)
Definition: Box2DWorld.cpp:119
void BeginContact(b2Contact *contact)
Definition: Box2DWorld.cpp:147
Definition: Spell.hpp:15
std::vector< Entity > getAllEntityInChunk(float x1, float x2)
Definition: Box2DWorld.cpp:53
Definition: DelayedSpellCreate.h:16
Definition: SpellEntity.h:16
void SayGoodbye(b2Joint *joint)
Definition: Box2DWorld.h:46
Entity * createEntity(b2BodyDef &bodyDef, b2FixtureDef &fixtureDef)
Definition: Box2DWorld.cpp:81
void update()
Definition: Box2DWorld.cpp:41
void subscribeToUpdate(Entity *entity)
Definition: Box2DWorld.h:42
Definition: Entity.h:21
Definition: Box2DWorld.h:26
void SayGoodbye(b2Fixture *fixture)
Definition: Box2DWorld.cpp:99
Entity * getEntityById(int id)
Definition: Box2DWorld.h:40
~Box2DWorld()
Definition: Box2DWorld.cpp:37
Box2DWorld(Server *server)
Definition: Box2DWorld.cpp:19
void asyncCreateSpellEntity(b2Vec2 position, Spell *spell)
Definition: Box2DWorld.cpp:115