Leviathan  0.8.0.0
Leviathan game engine
ScriptSystemWrapper.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
6 // ------------------------------------ //
7 
8 class asIScriptObject;
9 class asIScriptFunction;
10 class CScriptArray;
11 
12 namespace Leviathan {
13 
14 class GameWorld;
15 
18 
19  ScriptSystemUses(const std::string& name) : Name(name), UsesName(true) {}
20  ScriptSystemUses(uint16_t type) : Type(type), UsesName(false) {}
21  ScriptSystemUses() : Name("invalid"), UsesName(true) {}
23 
25  {
26  Type = other.Type;
27  Name = other.Name;
28  UsesName = other.UsesName;
29  return *this;
30  }
31 
32  static constexpr auto ANGELSCRIPT_TYPE = "ScriptSystemUses";
33 
34  uint16_t Type = -1;
35  std::string Name;
36  bool UsesName = false;
37 };
38 
40 DLLEXPORT void ScriptSystemNodeHelper(GameWorld* world, void* cachedcomponents,
41  int cachedtypeid, CScriptArray& systemcomponents);
42 
45 public:
48  DLLEXPORT ScriptSystemWrapper(const std::string& name, asIScriptObject* impl);
50 
51  // Wrap this in a std::unique_ptr
52  ScriptSystemWrapper(const ScriptSystemWrapper& other) = delete;
53  ScriptSystemWrapper& operator=(const ScriptSystemWrapper& other) = delete;
54 
56  DLLEXPORT asIScriptObject* GetASImplementationObject();
57 
58  // These functions are proxied to the script object
59  // Use these similarly to normal systems
60  DLLEXPORT void Init(GameWorld* world);
62  DLLEXPORT void Release();
63 
64  DLLEXPORT void Run(float elapsed);
65 
67 
68  DLLEXPORT void Clear();
69 
70  DLLEXPORT void Suspend();
71 
72  DLLEXPORT void Resume();
73 
74 
75  const std::string Name;
76 
77 protected:
79  DLLEXPORT bool _CallMethodOnUs(const std::string& methodname);
80 
84 
85 private:
88  asIScriptObject* ImplementationObject;
89 
90  // Cached methods for performance reasons
91  asIScriptFunction* RunMethod = nullptr;
92  asIScriptFunction* CreateAndDestroyNodesMethod = nullptr;
93 };
94 
95 } // namespace Leviathan
DLLEXPORT bool _CallMethodOnUs(const std::string &methodname)
Helper for reducing copy pasting between the functions that don't need extra parameters.
DLLEXPORT void Run(float elapsed)
DLLEXPORT void Init(GameWorld *world)
ScriptSystemWrapper & operator=(const ScriptSystemWrapper &other)=delete
DLLEXPORT asIScriptObject * GetASImplementationObject()
Returns the ImplementationObject increasing refcount.
DLLEXPORT ScriptSystemWrapper(const std::string &name, asIScriptObject *impl)
static constexpr auto ANGELSCRIPT_TYPE
DLLEXPORT void ScriptSystemNodeHelper(GameWorld *world, void *cachedcomponents, int cachedtypeid, CScriptArray &systemcomponents)
Helper for script systems to call to properly handle added and removed nodes.
unsigned short uint16_t
Definition: core.h:39
ScriptSystemUses(const std::string &name)
Wraps an AngelScript object that is an implementation of ScriptSystem.
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
ScriptSystemUses & operator=(const ScriptSystemUses &other)
Holds a single component type from c++ or from script, which a ScriptSystem uses.
Represents a world that contains entities.
Definition: GameWorld.h:57