Sfoglia il codice sorgente

Split update() and render() in World

Daniele Bartolini 12 anni fa
parent
commit
89dad358d5

+ 8 - 2
engine/Device.cpp

@@ -407,9 +407,15 @@ void Device::frame()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void Device::render_world(World& world, Camera& camera, float dt)
+void Device::update_world(World* world, float dt)
 {
 {
-	world.update(camera, dt);
+	world->update(dt);
+}
+
+//-----------------------------------------------------------------------------
+void Device::render_world(World* world, Camera* camera)
+{
+	world->render(camera);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 6 - 1
engine/Device.h

@@ -53,6 +53,8 @@ class RPCServer;
 class World;
 class World;
 class Camera;
 class Camera;
 
 
+typedef Id CameraId;
+
 /// The Engine.
 /// The Engine.
 /// It is the place where to look for accessing all of
 /// It is the place where to look for accessing all of
 /// the engine subsystems and related stuff.
 /// the engine subsystems and related stuff.
@@ -116,7 +118,10 @@ public:
 	void					frame();
 	void					frame();
 
 
 	/// Updates the given @a world and renders it from the given @a camera.
 	/// Updates the given @a world and renders it from the given @a camera.
-	void					render_world(World& world, Camera& camera, float dt);
+	void					update_world(World* world, float dt);
+
+	/// Renders the given @a world from the point of view of the given @æ camera.
+	void					render_world(World* world, Camera* camera);
 
 
 	World*					create_world();
 	World*					create_world();
 	void					destroy_world(World* world);
 	void					destroy_world(World* world);

+ 1 - 1
engine/RenderWorld.cpp

@@ -174,7 +174,7 @@ Sprite*	RenderWorld::lookup_sprite(SpriteId id)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uint16_t x, uint16_t y, uint16_t width, uint16_t height, float /*dt*/)
+void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 {
 {
 	static uint64_t frames = 0;
 	static uint64_t frames = 0;
 
 

+ 1 - 1
engine/RenderWorld.h

@@ -62,7 +62,7 @@ public:
 	void		destroy_sprite(SpriteId id);
 	void		destroy_sprite(SpriteId id);
 	Sprite*		lookup_sprite(SpriteId id);
 	Sprite*		lookup_sprite(SpriteId id);
 
 
-	void		update(const Matrix4x4& view, const Matrix4x4& projection, uint16_t x, uint16_t y, uint16_t width, uint16_t height, float dt);
+	void		update(const Matrix4x4& view, const Matrix4x4& projection, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
 
 
 private:
 private:
 
 

+ 1 - 1
engine/SceneGraphManager.h

@@ -26,7 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #pragma once
 #pragma once
 
 
-#include "IdArray.h"
+#include "List.h"
 
 
 namespace crown
 namespace crown
 {
 {

+ 12 - 9
engine/World.cpp

@@ -110,9 +110,9 @@ Unit* World::lookup_unit(UnitId unit)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 Camera* World::lookup_camera(CameraId camera)
 Camera* World::lookup_camera(CameraId camera)
 {
 {
-	CE_ASSERT(m_camera.has(camera), "Camera does not exist");
+	CE_ASSERT(m_cameras.has(camera), "Camera does not exist");
 
 
-	return m_camera.lookup(camera);
+	return m_cameras.lookup(camera);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -128,14 +128,17 @@ Sprite* World::lookup_sprite(SpriteId sprite)
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void World::update(Camera& camera, float dt)
+void World::update(float /*dt*/)
 {
 {
 	// Update scene graphs
 	// Update scene graphs
 	m_graph_manager.update();
 	m_graph_manager.update();
+}
 
 
-	// Update render world
-	m_render_world.update(camera.world_pose(), camera.m_projection, camera.m_view_x, camera.m_view_y,
-							camera.m_view_width, camera.m_view_height, dt);
+//-----------------------------------------------------------------------------
+void World::render(Camera* camera)
+{
+	m_render_world.update(camera->world_pose(), camera->m_projection, camera->m_view_x, camera->m_view_y,
+							camera->m_view_width, camera->m_view_height);
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -151,7 +154,7 @@ CameraId World::create_camera(SceneGraph& sg, int32_t node)
 	Camera* camera = CE_NEW(m_camera_pool, Camera)(sg, node);
 	Camera* camera = CE_NEW(m_camera_pool, Camera)(sg, node);
 
 
 	// Create Id for the camera
 	// Create Id for the camera
-	const CameraId camera_id = m_camera.create(camera);
+	const CameraId camera_id = m_cameras.create(camera);
 
 
 	return camera_id;
 	return camera_id;
 }
 }
@@ -159,9 +162,9 @@ CameraId World::create_camera(SceneGraph& sg, int32_t node)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void World::destroy_camera(CameraId id)
 void World::destroy_camera(CameraId id)
 {
 {
-	CE_ASSERT(m_camera.has(id), "Camera does not exist");
+	CE_ASSERT(m_cameras.has(id), "Camera does not exist");
 
 
-	Camera* camera = m_camera.lookup(id);
+	Camera* camera = m_cameras.lookup(id);
 	CE_DELETE(m_camera_pool, camera);
 	CE_DELETE(m_camera_pool, camera);
 }
 }
 
 

+ 3 - 2
engine/World.h

@@ -94,7 +94,8 @@ public:
 	Sprite*								lookup_sprite(SpriteId sprite);
 	Sprite*								lookup_sprite(SpriteId sprite);
 
 
 	RenderWorld&						render_world();
 	RenderWorld&						render_world();
-	void								update(Camera& camera, float dt);
+	void								update(float dt);
+	void								render(Camera* camera);
 
 
 	CameraId							create_camera(SceneGraph& sg, int32_t node);
 	CameraId							create_camera(SceneGraph& sg, int32_t node);
 	void								destroy_camera(CameraId id);
 	void								destroy_camera(CameraId id);
@@ -119,7 +120,7 @@ private:
 	PoolAllocator						m_camera_pool;
 	PoolAllocator						m_camera_pool;
 
 
 	IdArray<MAX_UNITS, Unit*>			m_units;
 	IdArray<MAX_UNITS, Unit*>			m_units;
-	IdArray<MAX_CAMERAS, Camera*>		m_camera;
+	IdArray<MAX_CAMERAS, Camera*>		m_cameras;
 	IdArray<MAX_SOUNDS, Sound> 			m_sounds;
 	IdArray<MAX_SOUNDS, Sound> 			m_sounds;
 
 
 	SceneGraphManager					m_graph_manager;
 	SceneGraphManager					m_graph_manager;

+ 14 - 2
engine/lua/LuaDevice.cpp

@@ -113,6 +113,18 @@ CE_EXPORT int device_destroy_world(lua_State* L)
 	return 0;
 	return 0;
 }
 }
 
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int device_update_world(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+	const float dt = stack.get_float(2);
+
+	device()->update_world(world, dt);
+	return 0;
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 CE_EXPORT int device_render_world(lua_State* L)
 CE_EXPORT int device_render_world(lua_State* L)
 {
 {
@@ -120,9 +132,8 @@ CE_EXPORT int device_render_world(lua_State* L)
 
 
 	World* world = stack.get_world(1);
 	World* world = stack.get_world(1);
 	Camera* camera = stack.get_camera(2);
 	Camera* camera = stack.get_camera(2);
-	const float dt = stack.get_float(3);
 
 
-	device()->render_world(*world, *camera, dt);
+	device()->render_world(world, camera);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -158,6 +169,7 @@ void load_device(LuaEnvironment& env)
 	env.load_module_function("Device", "stop",                     device_stop);
 	env.load_module_function("Device", "stop",                     device_stop);
 	env.load_module_function("Device", "create_world",             device_create_world);
 	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", "destroy_world",            device_destroy_world);
+	env.load_module_function("Device", "update_world",             device_update_world);
 	env.load_module_function("Device", "render_world",             device_render_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", "create_resource_package",  device_create_resource_package);
 	env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);
 	env.load_module_function("Device", "destroy_resource_package", device_destroy_resource_package);