Selaa lähdekoodia

Add Device::render_world()

Daniele Bartolini 12 vuotta sitten
vanhempi
sitoutus
d753ac613d
4 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 6 0
      engine/Device.cpp
  2. 4 0
      engine/Device.h
  3. 14 0
      engine/lua/LuaDevice.cpp
  4. 13 0
      engine/lua/LuaStack.h

+ 6 - 0
engine/Device.cpp

@@ -424,6 +424,12 @@ void Device::frame()
 	m_frame_count++;
 }
 
+//-----------------------------------------------------------------------------
+void Device::render_world(World& world, Camera& camera, float dt)
+{
+	world.update(camera, dt);
+}
+
 //-----------------------------------------------------------------------------
 World* Device::create_world()
 {

+ 4 - 0
engine/Device.h

@@ -52,6 +52,7 @@ class BundleCompiler;
 class ResourcePackage;
 class RPCServer;
 class World;
+class Camera;
 
 /// The Engine.
 /// It is the place where to look for accessing all of
@@ -106,6 +107,9 @@ public:
 	/// Updates all the subsystems
 	void					frame();
 
+	/// Updates the given @a world and renders it from the given @a camera.
+	void					render_world(World& world, Camera& camera, float dt);
+
 	World*					create_world();
 	void					destroy_world(World* world);
 

+ 14 - 0
engine/lua/LuaDevice.cpp

@@ -93,6 +93,19 @@ CE_EXPORT int device_destroy_world(lua_State* L)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int device_render_world(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+	Camera* camera = stack.get_camera(2);
+	const float dt = stack.get_float(3);
+
+	device()->render_world(*world, *camera, dt);
+	return 0;
+}
+
 //-----------------------------------------------------------------------------
 CE_EXPORT int device_create_resource_package(lua_State* L)
 {
@@ -124,6 +137,7 @@ void load_device(LuaEnvironment& env)
 	env.load_module_function("Device", "stop",                     device_stop);
 	env.load_module_function("Device", "create_world",             device_create_world);
 	env.load_module_function("Device", "destroy_world",            device_destroy_world);
+	env.load_module_function("Device", "render_world",             device_render_world);
 	env.load_module_function("Device", "create_resource_package",  device_create_resource_package);
 	env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);
 }

+ 13 - 0
engine/lua/LuaStack.h

@@ -38,6 +38,7 @@ class Mat4;
 class Quat;
 class Unit;
 class Camera;
+class World;
 
 class LuaStack
 {
@@ -147,6 +148,18 @@ public:
 		return lua_touserdata(m_state, index);	
 	}
 
+	//-----------------------------------------------------------------------------
+	void push_world(World* world)
+	{
+		lua_pushlightuserdata(m_state, world);
+	}
+
+	//-----------------------------------------------------------------------------
+	World* get_world(int32_t index)
+	{
+		return (World*) lua_touserdata(m_state, index);
+	}
+
 	//-----------------------------------------------------------------------------
 	void push_unit(Unit* unit)
 	{