Forráskód Böngészése

include init,frame,shutdown in LuaEnvironment

mikymod 12 éve
szülő
commit
b585eb6acd
5 módosított fájl, 41 hozzáadás és 52 törlés
  1. 1 1
      src/CMakeLists.txt
  2. 3 3
      src/Device.cpp
  3. 0 44
      src/Game.cpp
  4. 33 0
      src/lua/LuaEnvironment.cpp
  5. 4 4
      src/lua/LuaEnvironment.h

+ 1 - 1
src/CMakeLists.txt

@@ -33,7 +33,7 @@ set (SRC
 	ArchiveBundle.cpp
 	FileBundle.cpp
 
-	Game.cpp
+	#Game.cpp
 	JSONParser.cpp
 	ConsoleServer.cpp
 

+ 3 - 3
src/Device.cpp

@@ -134,7 +134,7 @@ bool Device::init(int argc, char** argv)
 	Log::i("Initializing Game...");
 
 	// Initialize the game through init game function
-	crown::init();
+	m_lua_environment->init();
 
 	m_is_init = true;
 
@@ -158,7 +158,7 @@ void Device::shutdown()
 	}
 
 	// Shutdowns the game
-	crown::shutdown();
+	m_lua_environment->shutdown();
 
 	Log::i("Releasing ConsoleServer...");
 	if (m_console_server)
@@ -357,7 +357,7 @@ void Device::frame()
 	m_window->frame();
 	m_input_manager->frame();
 
-	crown::frame(last_delta_time());
+	m_lua_environment->frame(last_delta_time());
 
 	m_console_server->execute();
 

+ 0 - 44
src/Game.cpp

@@ -1,44 +0,0 @@
-#include "Crown.h"
-#include "Game.h"
-#include "lua.hpp"
-#include "ConsoleServer.h"
-
-namespace crown
-{
-
-StringSetting g_boot("boot_file", "lua main file", "lua/game.raw");
-
-
-void init()
-{
-	LuaEnvironment* env = device()->lua_environment();
-
-	const char* path = device()->filesystem()->os_path(g_boot.value());
-
-	env->load_file(path);
-	env->execute(0, 0);
-
-	env->get_global_symbol("init");
-	env->execute(0, 0);
-}
-
-void shutdown()
-{
-	LuaEnvironment* env = device()->lua_environment();
-
-	env->get_global_symbol("shutdown");
-	env->execute(0, 0);
-}
-
-void frame(float dt)
-{
-	LuaEnvironment* env = device()->lua_environment();
-
-	LuaStack stack(env->state());
-
-	env->get_global_symbol("frame");
-	stack.push_float(dt);
-	env->execute(1, 0);
-}
-
-}

+ 33 - 0
src/lua/LuaEnvironment.cpp

@@ -29,10 +29,14 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Assert.h"
 #include "Log.h"
 #include "LuaEnvironment.h"
+#include "StringSetting.h"
+#include "Filesystem.h"
 
 namespace crown
 {
 
+StringSetting g_boot("boot_file", "lua main file", "lua/game.raw");
+
 //-----------------------------------------------------------------------------
 LuaEnvironment::LuaEnvironment() :
 	m_state(luaL_newstate())
@@ -124,6 +128,35 @@ void LuaEnvironment::execute(int32_t args, int32_t results)
 	}
 }
 
+//-----------------------------------------------------------------------------
+void LuaEnvironment::init()
+{
+	const char* path = device()->filesystem()->os_path(g_boot.value());
+
+	load_file(path);
+	execute(0, 0);
+
+	get_global_symbol("init");
+	execute(0, 0);
+}
+
+//-----------------------------------------------------------------------------
+void LuaEnvironment::shutdown()
+{
+	get_global_symbol("shutdown");
+	execute(0, 0);
+}
+
+//-----------------------------------------------------------------------------
+void LuaEnvironment::frame(float dt)
+{
+	LuaStack stack(m_state);
+
+	get_global_symbol("frame");
+	stack.push_float(dt);
+	execute(1, 0);
+}
+
 //-----------------------------------------------------------------------------
 void LuaEnvironment::lua_error()
 {

+ 4 - 4
src/lua/LuaEnvironment.h

@@ -51,14 +51,14 @@ public:
 	/// Constructor
 						LuaEnvironment();
 
-	lua_State*			state();
-
-	const char*			error();
-
 	void				start();
 
 	void				stop();
 
+	lua_State*			state();
+
+	const char*			error();
+
 	void				load_buffer(const char* buffer, size_t len);
 
 	void				load_file(const char* file);