Leviathan  0.8.0.0
Leviathan game engine
ScriptComponentHolder.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2019 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
7 
8 #include <map>
9 
10 class asIScriptFunction;
11 class asIScriptObject;
12 class CScriptArray;
13 
14 namespace Leviathan {
15 
20 protected:
21  // These are protected for only constructing properly reference
22  // counted instances through MakeShared
24 
28  const std::string& name, asIScriptFunction* factory, GameWorld* world);
29 
30 public:
32 
36  DLLEXPORT bool ReleaseComponent(ObjectID entity);
37 
40 
46  DLLEXPORT asIScriptObject* Create(ObjectID entity);
47 
50  DLLEXPORT asIScriptObject* Find(ObjectID entity);
51 
55  DLLEXPORT inline bool Destroy(ObjectID entity)
56  {
57  return ReleaseComponent(entity);
58  }
59 
66  DLLEXPORT CScriptArray* GetIndex() const;
67 
68 
70  const auto& GetRemoved() const
71  {
72  return Removed;
73  }
74 
76  auto& GetAdded()
77  {
78  return Added;
79  }
80 
82  void ClearAdded()
83  {
84  Added.clear();
85  }
86 
88  void ClearRemoved()
89  {
90  Removed.clear();
91  }
92 
93 
95 
96  const std::string ComponentType;
97 
98 private:
99  asIScriptFunction* Factory;
100  GameWorld* World;
101 
102  std::map<ObjectID, asIScriptObject*> CreatedObjects;
103 
104  // Need to remember these for compatibility with caching
105  std::vector<std::tuple<asIScriptObject*, ObjectID>> Added;
106  std::vector<std::tuple<asIScriptObject*, ObjectID>> Removed;
107 };
108 
109 } // namespace Leviathan
DLLEXPORT asIScriptObject * Create(ObjectID entity)
Creates a new component of held type.
DLLEXPORT bool ReleaseComponent(ObjectID entity)
Releases a single component.
DLLEXPORT asIScriptObject * Find(ObjectID entity)
Finds a component for entity.
DLLEXPORT bool Destroy(ObjectID entity)
Destroys a component of held type for entity.
int32_t ObjectID
Definition: EntityCommon.h:11
DLLEXPORT CScriptArray * GetIndex() const
Returns all the created components.
REFERENCE_COUNTED_PTR_TYPE(ScriptComponentHolder)
DLLEXPORT void ReleaseAllComponents()
Releases all components.
void ClearRemoved()
Clears the removed list.
const auto & GetRemoved() const
Returns a reference to the vector of removed elements.
auto & GetAdded()
Returns a reference to the vector of added elements.
void ClearAdded()
Clears the added list.
DLLEXPORT ScriptComponentHolder(const std::string &name, asIScriptFunction *factory, GameWorld *world)
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Represents a world that contains entities.
Definition: GameWorld.h:57