1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (C) 2004-2010 by The Allacrost Project
3 // All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 /** ***************************************************************************
11 *** \file defs_engine.cpp
12 *** \author Daniel Steuernol, steu@allacrost.org
13 *** \brief Source file for Lua binding code
14 ***
15 *** All binding code for the game engine is contained within this file.
16 *** Therefore, everything that you see bound within this file will be made
17 *** available in Lua. All binding code is contained within this single file
18 *** because the binding code greatly increases the compilation time, but this
19 *** effect is mitigated if it is contained within a single file (Note: Binding
20 *** is now split out according to dependency level (engine, global, modes).
21 ***
22 *** \note To most C++ programmers, the syntax of the binding code found in this
23 *** file may be very unfamiliar and obtuse. Refer to the Luabind documentation
24 *** as necessary to gain an understanding of this code style.
25 *** **************************************************************************/
26
27 #include "defs.h"
28
29 #include "audio.h"
30 #include "input.h"
31 #include "mode_manager.h"
32 #include "script.h"
33 #include "system.h"
34 #include "video.h"
35
36 #include "global.h"
37
38 using namespace luabind;
39
40 namespace hoa_defs {
41
BindEngineToLua()42 void BindEngineToLua()
43 {
44 // ----- Audio Engine Bindings
45 {
46 using namespace hoa_audio;
47
48 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_audio")
49 [
50 class_<AudioEngine>("GameAudio")
51 .def("PlaySound", &AudioEngine::PlaySound)
52 ];
53
54 } // End using audio namespaces
55
56
57
58 // ----- Input Engine Bindings
59 {
60 using namespace hoa_input;
61
62 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_input")
63 [
64 class_<InputEngine>("GameInput")
65 ];
66
67 } // End using input namespaces
68
69
70
71 // ----- Mode Manager Engine Bindings
72 {
73 using namespace hoa_mode_manager;
74
75 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_mode_manager")
76 [
77 class_<GameMode>("GameMode")
78 ];
79
80 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_mode_manager")
81 [
82 class_<ModeEngine>("GameModeManager")
83 .def("Push", &ModeEngine::Push, adopt(_2))
84 .def("Pop", &ModeEngine::Pop)
85 .def("PopAll", &ModeEngine::PopAll)
86 .def("GetTop", &ModeEngine::GetTop)
87 .def("Get", &ModeEngine::Get)
88 .def("GetGameType", (uint8 (ModeEngine::*)(uint32))&ModeEngine::GetGameType)
89 .def("GetGameType", (uint8 (ModeEngine::*)())&ModeEngine::GetGameType)
90 ];
91
92 } // End using mode manager namespaces
93
94
95
96 // ----- Script Engine Bindings
97 {
98 using namespace hoa_script;
99
100 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_script")
101 [
102 class_<ScriptEngine>("GameScript")
103 ];
104
105 } // End using script namespaces
106
107
108
109 // ----- System Engine Bindings
110 {
111 using namespace hoa_system;
112
113 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_system")
114 [
115 def("Translate", &hoa_system::Translate),
116
117 class_<SystemTimer>("SystemTimer")
118 .def(constructor<>())
119 .def(constructor<uint32, int32>())
120 .def("Initialize", &SystemTimer::Initialize)
121 .def("EnableAutoUpdate", &SystemTimer::EnableAutoUpdate)
122 .def("EnableManualUpdate", &SystemTimer::EnableManualUpdate)
123 .def("Update", (void(SystemTimer::*)(void)) &SystemTimer::Update)
124 .def("Update", (void(SystemTimer::*)(uint32)) &SystemTimer::Update)
125 .def("Reset", &SystemTimer::Reset)
126 .def("Run", &SystemTimer::Run)
127 .def("Pause", &SystemTimer::Pause)
128 .def("Finish", &SystemTimer::Finish)
129 .def("IsInitial", &SystemTimer::IsInitial)
130 .def("IsRunning", &SystemTimer::IsRunning)
131 .def("IsPaused", &SystemTimer::IsPaused)
132 .def("IsFinished", &SystemTimer::IsFinished)
133 .def("CurrentLoop", &SystemTimer::CurrentLoop)
134 .def("TimeLeft", &SystemTimer::TimeLeft)
135 .def("PercentComplete", &SystemTimer::PercentComplete)
136 .def("SetDuration", &SystemTimer::SetDuration)
137 .def("SetNumberLoops", &SystemTimer::SetNumberLoops)
138 .def("SetModeOwner", &SystemTimer::SetModeOwner)
139 .def("GetState", &SystemTimer::GetState)
140 .def("GetDuration", &SystemTimer::GetDuration)
141 .def("GetNumberLoops", &SystemTimer::GetNumberLoops)
142 .def("IsAutoUpdate", &SystemTimer::IsAutoUpdate)
143 .def("GetModeOwner", &SystemTimer::GetModeOwner)
144 .def("GetTimeExpired", &SystemTimer::GetTimeExpired)
145 .def("GetTimesCompleted", &SystemTimer::GetTimesCompleted),
146
147 class_<SystemEngine>("GameSystem")
148 .def("GetUpdateTime", &SystemEngine::GetUpdateTime)
149 .def("SetPlayTime", &SystemEngine::SetPlayTime)
150 .def("GetPlayHours", &SystemEngine::GetPlayHours)
151 .def("GetPlayMinutes", &SystemEngine::GetPlayMinutes)
152 .def("GetPlaySeconds", &SystemEngine::GetPlaySeconds)
153 .def("GetLanguage", &SystemEngine::GetLanguage)
154 .def("SetLanguage", &SystemEngine::SetLanguage)
155 .def("NotDone", &SystemEngine::NotDone)
156 .def("ExitGame", &SystemEngine::ExitGame)
157 ];
158
159 } // End using system namespaces
160
161
162
163 // ----- Video Engine Bindings
164 {
165 using namespace hoa_video;
166
167 module(hoa_script::ScriptManager->GetGlobalState(), "hoa_video")
168 [
169 class_<VideoEngine>("GameVideo")
170 ];
171
172 } // End using video namespaces
173
174 // ---------- Bind engine class objects
175 luabind::object global_table = luabind::globals(hoa_script::ScriptManager->GetGlobalState());
176 global_table["AudioManager"] = hoa_audio::AudioManager;
177 global_table["InputManager"] = hoa_input::InputManager;
178 global_table["ModeManager"] = hoa_mode_manager::ModeManager;
179 global_table["ScriptManager"] = hoa_script::ScriptManager;
180 global_table["SystemManager"] = hoa_system::SystemManager;
181 global_table["VideoManager"] = hoa_video::VideoManager;
182 } // BindEngineToLua
183
184 } // namespace hoa_defs
185