Fling Engine  0.00.1
Fling Engine is a game engine written in Vulkan
LuaManager.h
Go to the documentation of this file.
1 #if WITH_LUA
2 #pragma once
3 
4 #include "Platform.h"
5 #include "Singleton.hpp"
6 #include "File.h"
7 #include <sol/sol.hpp>
8 #include "Components/Transform.h"
9 #include <entt/entity/registry.hpp>
10 #include "ScriptComponent.h"
11 
12 namespace Fling
13 {
17  struct LuaBehaviors
18  {
19  sol::state LuaState;
20  sol::function Tick = sol::nil;
21  sol::function Start = sol::nil;
22  };
23 
28  class LuaManager : public Singleton<LuaManager>
29  {
30  public:
31 
37  void Init(entt::registry* t_Registry);
38 
42  void Shutdown() override;
43 
47  void Start();
48 
54  void Tick(float t_deltaTime);
55 
56  private:
57 
64  void RegisterScript(File* t_ScriptFile, entt::entity t_Ent);
65 
73  void LoadScript(File* t_File, entt::entity t_Ent, LuaBehaviors* t_Behavior);
74 
82  void AddCallback(const sol::state& t_LuaState, const char* t_FunctionName, sol::function* t_Callbacks);
83 
89  void LuaPrint(const std::string& t_Message);
90 
96  void DefineLuaTypes(sol::state& t_LuaState);
97 
103  void DefineLuaFunctions(sol::state& t_LuaState);
104 
112  void LuaScriptAdded(entt::entity t_Ent, entt::registry& t_Reg, ScriptComponent& t_LuaScript);
113 
114  //A reference to the registry
115  entt::registry* m_Registry = nullptr;
116 
117  //A map of all of the registered lua behaviors
118  std::unordered_map<File*, LuaBehaviors> m_LuaComponents;
119  };
120 }
121 #endif
Definition: Engine.h:29