Amuse
Entity.hpp
1 #ifndef __AMUSE_ENTITY_HPP__
2 #define __AMUSE_ENTITY_HPP__
3 
4 #include <stdint.h>
5 #include <functional>
6 #include <assert.h>
7 
8 namespace amuse
9 {
10 class Engine;
11 class AudioGroup;
12 
15 using ObjectId = uint16_t;
16 
18 class Entity
19 {
20  /* Only the Engine will manage Entity lifetimes,
21  * but shared_ptrs are issued to the client so it can safely track state */
22  friend class Engine;
23  friend class SoundMacroState;
24 protected:
25  bool m_destroyed = false;
26  void _destroy()
27  {
28 #ifndef NDEBUG
29  assert(!m_destroyed);
30 #endif
31  m_destroyed = true;
32  }
33  Engine& m_engine;
34  const AudioGroup& m_audioGroup;
35  int m_groupId;
36  ObjectId m_objectId = 0xffff; /* if applicable */
37 public:
38  Entity(Engine& engine, const AudioGroup& group, int groupId, ObjectId oid=ObjectId())
39  : m_engine(engine), m_audioGroup(group), m_groupId(groupId), m_objectId(oid) {}
40  ~Entity()
41  {
42 #ifndef NDEBUG
43  /* Ensure proper destruction procedure followed */
44  assert(m_destroyed);
45 #endif
46  }
47 
48  Engine& getEngine() {return m_engine;}
49  const AudioGroup& getAudioGroup() const {return m_audioGroup;}
50  int getGroupId() const {return m_groupId;}
51  ObjectId getObjectId() const {return m_objectId;}
52 };
53 
56 using Curve = uint8_t[128];
57 
58 }
59 
60 #endif // __AMUSE_ENTITY_HPP__