Ult3D
Implementation of "Ultimate 3D Game Engine Design & Architecture" by Allan Sherrod
Loading...
Searching...
No Matches
GameMonkey.h
Go to the documentation of this file.
1#ifndef ULT_GAME_MONKEY_H_INCLUDED
2#define ULT_GAME_MONKEY_H_INCLUDED
3
4#include <string>
5#include <gmThread.h>
6#include <gmCall.h>
7
11
12namespace Ult
13{
14
19typedef int GmScript;
20
26{
27public:
36
40 void AddIntParam(int param) {
41 mScriptCall.AddParamInt(param);
42 }
43
46 void AddFloatParam(float param) {
47 mScriptCall.AddParamFloat(param);
48 }
49
52 void AddStringParam(const std::string& param) {
53 mScriptCall.AddParamString(param.c_str());
54 }
55
59 void ExecuteCall() {
60 mScriptCall.End();
61 }
62
67 bool GetReturnValueAsInt(int& retVal) {
68 if (mScriptCall.GetReturnedInt(retVal)) {
69 return true;
70 }
71 return false;
72 }
73
77 bool GetReturnValueAsFloat(float& retVal) {
78 if (mScriptCall.GetReturnedFloat(retVal)) {
79 return true;
80 }
81 return false;
82 }
83
87 bool GetReturnValueAsString(const char* retVal) {
88 if (mScriptCall.GetReturnedString(retVal)) {
89 return true;
90 }
91 return false;
92 }
93
97 gmCall* GetCallPtr() { return &mScriptCall; }
98
99private:
100 gmCall mScriptCall;
101};
102
109{
110public:
115 {}
116
119 virtual ~GameMonkey()
120 {}
121
129 bool LoadScript(const std::string& script, GmScript* handle);
133 void ExecuteScript(GmScript handle);
134
141 bool GetScriptFunction(const std::string& name, GameMonkeyFunction& call);
147 void RegisterHostFunction(const std::string& name, gmCFunction func);
148
152 const char* GetError() { return mErrorBuffer.c_str(); }
153
154private:
155 gmMachine mGvm;
156 std::string mErrorBuffer;
157};
158
159} // namespace Ult
160
161#endif // ULT_GAME_MONKEY_H_INCLUDED
162
Definition GameMonkey.h:26
bool GetReturnValueAsFloat(float &retVal)
Definition GameMonkey.h:77
void AddIntParam(int param)
Definition GameMonkey.h:40
gmCall * GetCallPtr()
Definition GameMonkey.h:97
void AddStringParam(const std::string &param)
Definition GameMonkey.h:52
void ExecuteCall()
Definition GameMonkey.h:59
virtual ~GameMonkeyFunction()
Definition GameMonkey.h:35
bool GetReturnValueAsString(const char *retVal)
Definition GameMonkey.h:87
void AddFloatParam(float param)
Definition GameMonkey.h:46
bool GetReturnValueAsInt(int &retVal)
Definition GameMonkey.h:67
GameMonkeyFunction()
Definition GameMonkey.h:31
virtual ~GameMonkey()
Definition GameMonkey.h:119
bool LoadScript(const std::string &script, GmScript *handle)
Definition GameMonkey.cpp:6
void ExecuteScript(GmScript handle)
Definition GameMonkey.cpp:28
bool GetScriptFunction(const std::string &name, GameMonkeyFunction &call)
Definition GameMonkey.cpp:33
const char * GetError()
Definition GameMonkey.h:152
void RegisterHostFunction(const std::string &name, gmCFunction func)
Definition GameMonkey.cpp:42
GameMonkey()
Definition GameMonkey.h:114
int GmScript
Definition GameMonkey.h:19
Definition Archive.h:13