2
0
Эх сурвалжийг харах

Add Device::create/destroy_world() and fix lua bindings

Daniele Bartolini 12 жил өмнө
parent
commit
6890905ebf

+ 6 - 0
engine/CMakeLists.txt

@@ -73,6 +73,9 @@ set (CROWN_INCLUDES
 set (SRC
 	Camera.cpp
 	Device.cpp
+	World.cpp
+	Unit.cpp
+	SceneGraph.cpp
 )
 
 set (HEADERS
@@ -80,6 +83,9 @@ set (HEADERS
 	Config.h
 	Crown.h
 	Device.h
+	World.h
+	Unit.h
+	SceneGraph.h	
 )
 
 set (CORE_SRC

+ 15 - 0
engine/Device.cpp

@@ -54,6 +54,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ResourcePackage.h"
 #include "RPCServer.h"
 #include "SoundRenderer.h"
+#include "World.h"
 
 #if defined(LINUX) || defined(WINDOWS)
 	#include "BundleCompiler.h"
@@ -423,6 +424,20 @@ void Device::frame()
 	m_frame_count++;
 }
 
+//-----------------------------------------------------------------------------
+World* Device::create_world()
+{
+	return CE_NEW(default_allocator(), World);
+}
+
+//-----------------------------------------------------------------------------
+void Device::destroy_world(World* world)
+{
+	CE_ASSERT_NOT_NULL(world);
+
+	CE_DELETE(default_allocator(), world);
+}
+
 //-----------------------------------------------------------------------------
 ResourcePackage* Device::create_resource_package(const char* name)
 {

+ 4 - 0
engine/Device.h

@@ -51,6 +51,7 @@ class SoundRenderer;
 class BundleCompiler;
 class ResourcePackage;
 class RPCServer;
+class World;
 
 /// The Engine.
 /// It is the place where to look for accessing all of
@@ -105,6 +106,9 @@ public:
 	/// Updates all the subsystems
 	void					frame();
 
+	World*					create_world();
+	void					destroy_world(World* world);
+
 	/// Returns the resource package with the given @a package_name name.
 	ResourcePackage*		create_resource_package(const char* name);
 

+ 2 - 3
engine/World.cpp

@@ -31,8 +31,7 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-World::World() :
-	m_unit_table(m_allocator, MAX_UNITS)
+World::World()
 {
 }
 
@@ -84,7 +83,7 @@ Unit* World::unit(UnitId unit)
 }
 
 //-----------------------------------------------------------------------------
-void World::update(float dt)
+void World::update(float /*dt*/)
 {
 	m_scene_graph.update();
 }

+ 1 - 1
engine/World.h

@@ -62,7 +62,7 @@ private:
 
 	SceneGraph		m_scene_graph;
 
-	IdTable			m_unit_table;
+	IdTable<MAX_UNITS> m_unit_table;
 	Unit*			m_units[MAX_UNITS];
 };
 

+ 23 - 0
engine/lua/LuaDevice.cpp

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Device.h"
 #include "ResourcePackage.h"
+#include "World.h"
 #include "LuaEnvironment.h"
 #include "LuaStack.h"
 
@@ -72,6 +73,26 @@ CE_EXPORT int device_stop(lua_State* /*L*/)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int device_create_world(lua_State* L)
+{
+	LuaStack stack(L);
+
+	stack.push_lightdata(device()->create_world());
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int device_destroy_world(lua_State* L)
+{
+	LuaStack stack(L);
+
+	device()->destroy_world((World*) stack.get_lightdata(1));
+
+	return 0;
+}
+
 //-----------------------------------------------------------------------------
 CE_EXPORT int device_create_resource_package(lua_State* L)
 {
@@ -101,6 +122,8 @@ void load_device(LuaEnvironment& env)
 	env.load_module_function("Device", "last_delta_time",          device_last_delta_time);
 	env.load_module_function("Device", "start",                    device_start);
 	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", "create_resource_package",  device_create_resource_package);
 	env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);
 }

+ 5 - 5
engine/lua/LuaWorld.cpp

@@ -37,13 +37,13 @@ CE_EXPORT int world_spawn_unit(lua_State* L)
 {
 	LuaStack stack(L);
 
-	//World* world = stack.get_world(1);
-	const char* name = stack.get_string(1);
+	World* world = (World*) stack.get_lightdata(1);
+	const char* name = stack.get_string(2);
 
-	const Vec3& pos = stack.num_args() > 1 ? stack.get_vec3(2) : Vec3::ZERO;
-	const Quat& rot = stack.num_args() > 2 ? stack.get_quat(3) : Quat::IDENTITY;
+	const Vec3& pos = stack.num_args() > 2 ? stack.get_vec3(3) : Vec3::ZERO;
+	const Quat& rot = stack.num_args() > 3 ? stack.get_quat(4) : Quat::IDENTITY;
 
-	device()->world()->spawn_unit(name, pos, rot);
+	world->spawn_unit(name, pos, rot);
 
 	return 0;
 }