CSEngine
Loading...
Searching...
No Matches
ScriptMgr.h
1#pragma once
2#include "../Component/CustomComponent.h"
3#include "../Util/Matrix.h"
4#include "Base/SContainerList.h"
5#include "Base/CoreBase.h"
6
7namespace CSE {
8
9 class ScriptMgr : public SContainerList<Sqrat::Object*>, public CoreBase {
10 public:
11 ScriptMgr();
12
13 ~ScriptMgr() override;
14
15 void Init() override;
16
17
18 static void RegisterScript(const std::string& script);
19
20 private:
21 void DefineClasses(HSQUIRRELVM vm = Sqrat::DefaultVM::Get());
22
23 void ReleaseSqratObject();
24
25 static void ReadScriptList() ;
26
27 template <class T>
28 Sqrat::Class<T>& SQRClassDef(std::string className, HSQUIRRELVM vm = Sqrat::DefaultVM::Get());
29
30 template <class T>
31 Sqrat::Class<T>& SQRComponentDef(std::string className, HSQUIRRELVM vm = Sqrat::DefaultVM::Get());
32
33 private:
34 int m_gameobjectIndex = -1;
35 };
36
37
38 template <class T>
39 Sqrat::Class<T>& ScriptMgr::SQRClassDef(std::string className, HSQUIRRELVM vm) {
40
41 Sqrat::Class<T>* sqClass = new Sqrat::Class<T>(Sqrat::DefaultVM::Get(), className);
42 Sqrat::RootTable(vm).Bind(className.c_str(), *sqClass);
43 Register(sqClass);
44
45 //���� ������Ʈ�ΰ�?
46 if (className == _SC("GameObject")) {
47 m_gameobjectIndex = m_objects.size();
48 }
49
50 return *sqClass;
51 }
52
53
54 template <class T>
55 Sqrat::Class<T>& ScriptMgr::SQRComponentDef(std::string className, HSQUIRRELVM vm) {
56 if (m_gameobjectIndex >= 0) {
57 auto sqClass = *static_cast<Sqrat::Class<SGameObject>*>(Get(m_gameobjectIndex));
58 sqClass.Func((std::string() + "GetComponent_" + className + "_").c_str(),
59 &SGameObject::GetComponent<T>);
60
61 }
62
63 return SQRClassDef<T>(className, vm);
64 }
65
66}