Daniele Bartolini 11 лет назад
Родитель
Сommit
aa077477e5

+ 0 - 4
engine/config.h

@@ -90,10 +90,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 	#define CE_MAX_CAMERA_COMPONENTS 16 // Per unit
 #endif // CE_MAX
 
-#ifndef CE_MAX_MESH_COMPONENTS
-	#define CE_MAX_MESH_COMPONENTS 16 // Per unit
-#endif // CE_MAX
-
 #ifndef CE_MAX_SPRITE_COMPONENTS
 	#define CE_MAX_SPRITE_COMPONENTS 16 // Per unit
 #endif // CE_MAX

+ 0 - 111
engine/lua/lua_mesh.cpp

@@ -1,111 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "mesh.h"
-#include "quaternion.h"
-#include "lua_stack.h"
-#include "lua_environment.h"
-
-namespace crown
-{
-
-static int mesh_local_position(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_vector3(stack.get_mesh(1)->local_position());
-	return 1;
-}
-
-static int mesh_local_rotation(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_quaternion(stack.get_mesh(1)->local_rotation());
-	return 1;
-}
-
-static int mesh_local_pose(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_matrix4x4(stack.get_mesh(1)->local_pose());
-	return 1;
-}
-
-static int mesh_world_position(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_vector3(stack.get_mesh(1)->world_position());
-	return 1;
-}
-
-static int mesh_world_rotation(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_quaternion(stack.get_mesh(1)->world_rotation());
-	return 1;
-}
-
-static int mesh_world_pose(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.push_matrix4x4(stack.get_mesh(1)->world_pose());
-	return 1;
-}
-
-static int mesh_set_local_position(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.get_mesh(1)->set_local_position(stack.get_unit(2), stack.get_vector3(3));
-	return 0;
-}
-
-static int mesh_set_local_rotation(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.get_mesh(1)->set_local_rotation(stack.get_unit(2), stack.get_quaternion(3));
-	return 0;
-}
-
-static int mesh_set_local_pose(lua_State* L)
-{
-	LuaStack stack(L);
-	stack.get_mesh(1)->set_local_pose(stack.get_unit(2), stack.get_matrix4x4(3));
-	return 0;
-}
-
-void load_mesh(LuaEnvironment& env)
-{
-	env.load_module_function("Mesh", "local_position",     mesh_local_position);
-	env.load_module_function("Mesh", "local_rotation",     mesh_local_rotation);
-	env.load_module_function("Mesh", "local_pose",         mesh_local_pose);
-	env.load_module_function("Mesh", "world_position",     mesh_world_position);
-	env.load_module_function("Mesh", "world_rotation",     mesh_world_rotation);
-	env.load_module_function("Mesh", "world_pose",         mesh_world_pose);
-	env.load_module_function("Mesh", "set_local_position", mesh_set_local_position);
-	env.load_module_function("Mesh", "set_local_rotation", mesh_set_local_rotation);
-	env.load_module_function("Mesh", "set_local_pose",     mesh_set_local_pose);
-}
-
-} // namespace crown

+ 0 - 2
engine/lua/lua_system.cpp

@@ -56,7 +56,6 @@ extern void load_keyboard(LuaEnvironment& env);
 extern void load_math(LuaEnvironment& env);
 extern void load_matrix4x4(LuaEnvironment& env);
 extern void load_matrix4x4box(LuaEnvironment& env);
-extern void load_mesh(LuaEnvironment& env);
 extern void load_mouse(LuaEnvironment& env);
 extern void load_physics_world(LuaEnvironment& env);
 extern void load_quaternion(LuaEnvironment& env);
@@ -229,7 +228,6 @@ namespace lua_globals
 		load_keyboard(env);
 		load_math(env);
 		load_matrix4x4(env);
-		load_mesh(env);
 		load_mouse(env);
 		load_physics_world(env);
 		load_quaternion(env);

+ 0 - 17
engine/lua/lua_unit.cpp

@@ -161,22 +161,6 @@ static int unit_material(lua_State* L)
 	return 1;
 }
 
-static int unit_mesh(lua_State* L)
-{
-	LuaStack stack(L);
-
-	Unit* unit = stack.get_unit(1);
-
-	if (stack.is_number(2))
-	{
-		stack.push_mesh(unit->mesh((uint32_t) stack.get_int(2)));
-		return 1;
-	}
-
-	stack.push_mesh(unit->mesh(stack.get_string(2)));
-	return 1;
-}
-
 static int unit_sprite(lua_State* L)
 {
 	LuaStack stack(L);
@@ -325,7 +309,6 @@ void load_unit(LuaEnvironment& env)
 	env.load_module_function("Unit", "unlink_node",           unit_unlink_node);
 	env.load_module_function("Unit", "camera",                unit_camera);
 	env.load_module_function("Unit", "material",              unit_material);
-	env.load_module_function("Unit", "mesh",                  unit_mesh);
 	env.load_module_function("Unit", "sprite",                unit_sprite);
 	env.load_module_function("Unit", "actor",                 unit_actor);
 	env.load_module_function("Unit", "controller",            unit_controller);

+ 0 - 90
engine/renderers/mesh.cpp

@@ -1,90 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "mesh.h"
-#include "mesh_resource.h"
-#include "vector3.h"
-#include "matrix4x4.h"
-#include "quaternion.h"
-#include "unit.h"
-#include "scene_graph.h"
-
-namespace crown
-{
-
-Mesh::Mesh(SceneGraph& sg, int32_t node, const MeshResource* mr)
-	: m_scene_graph(sg)
-	, m_node(node)
-	, m_resource(mr)
-{
-}
-
-Vector3 Mesh::local_position() const
-{
-	return m_scene_graph.local_position(m_node);
-}
-
-Quaternion Mesh::local_rotation() const
-{
-	return m_scene_graph.local_rotation(m_node);
-}
-
-Matrix4x4 Mesh::local_pose() const
-{
-	return m_scene_graph.local_pose(m_node);
-}
-
-Vector3 Mesh::world_position() const
-{
-	return m_scene_graph.world_position(m_node);
-}
-
-Quaternion Mesh::world_rotation() const
-{
-	return m_scene_graph.world_rotation(m_node);
-}
-
-Matrix4x4 Mesh::world_pose() const
-{
-	return m_scene_graph.world_pose(m_node);
-}
-
-void Mesh::set_local_position(Unit* unit, const Vector3& pos)
-{
-	unit->set_local_position(m_node, pos);
-}
-
-void Mesh::set_local_rotation(Unit* unit, const Quaternion& rot)
-{
-	unit->set_local_rotation(m_node, rot);
-}
-
-void Mesh::set_local_pose(Unit* unit, const Matrix4x4& pose)
-{
-	unit->set_local_pose(m_node, pose);
-}
-
-} // namespace crown

+ 0 - 78
engine/renderers/mesh.h

@@ -1,78 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "matrix4x4.h"
-
-namespace crown
-{
-
-struct SceneGraph;
-struct MeshResource;
-struct Quaternion;
-struct Unit;
-struct Vector3;
-
-struct Mesh
-{
-	Mesh(SceneGraph& sg, int32_t node, const MeshResource* mr);
-
-	/// Returns the local position of the mesh.
-	Vector3 local_position() const;
-
-	/// Returns the local rotation of the mesh.	
-	Quaternion local_rotation() const;
-
-	/// Returns the local pose of the mesh.
-	Matrix4x4 local_pose() const;
-
-	/// Returns the world position of the mesh.
-	Vector3 world_position() const;
-
-	/// Returns the world rotation of the mesh.
-	Quaternion world_rotation() const;
-
-	/// Returns the world pose of the mesh.
-	Matrix4x4 world_pose() const;
-
-	/// Sets the local position of the mesh.
-	void set_local_position(Unit* unit, const Vector3& pos);
-
-	/// Sets the local rotation of the mesh.
-	void set_local_rotation(Unit* unit, const Quaternion& rot);
-
-	/// Sets the local pose of the mesh.
-	void set_local_pose(Unit* unit, const Matrix4x4& pose);
-
-public:
-
-	SceneGraph& m_scene_graph;
-	int32_t m_node;
-	const MeshResource* m_resource;
-};
-
-} // namespace crown

+ 4 - 23
engine/renderers/render_world.cpp

@@ -31,19 +31,19 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "resource.h"
 #include "log.h"
 #include "sprite_resource.h"
-#include "mesh.h"
 #include "sprite.h"
 #include "material.h"
 #include "config.h"
 #include "gui.h"
+#include "mesh_resource.h"
+#include "scene_graph.h"
 #include <bgfx.h>
 
 namespace crown
 {
 
 RenderWorld::RenderWorld()
-	: m_mesh_pool(default_allocator(), MAX_MESHES, sizeof(Mesh), CE_ALIGNOF(Mesh))
-	, m_sprite_pool(default_allocator(), MAX_SPRITES, sizeof(Sprite), CE_ALIGNOF(Sprite))
+	: m_sprite_pool(default_allocator(), MAX_SPRITES, sizeof(Sprite), CE_ALIGNOF(Sprite))
 	, m_gui_pool(default_allocator(), MAX_GUIS, sizeof(Gui), CE_ALIGNOF(Gui))
 {
 }
@@ -52,24 +52,6 @@ RenderWorld::~RenderWorld()
 {
 }
 
-MeshId RenderWorld::create_mesh(MeshResource* mr, SceneGraph& sg, int32_t node)
-{
-	Mesh* mesh = CE_NEW(m_mesh_pool, Mesh)(sg, node, mr);
-	return id_array::create(m_mesh, mesh);
-}
-
-void RenderWorld::destroy_mesh(MeshId id)
-{
-	Mesh* mesh = id_array::get(m_mesh, id);
-	CE_DELETE(m_mesh_pool, mesh);
-	id_array::destroy(m_mesh, id);
-}
-
-Mesh* RenderWorld::get_mesh(MeshId mesh)
-{
-	return id_array::get(m_mesh, mesh);
-}
-
 SpriteId RenderWorld::create_sprite(SpriteResource* sr, SceneGraph& sg, int32_t node)
 {
 	Sprite* sprite = CE_NEW(m_sprite_pool, Sprite)(*this, sg, node, sr);
@@ -113,8 +95,7 @@ void RenderWorld::update(const Matrix4x4& view, const Matrix4x4& projection, uin
 		, BGFX_CLEAR_COLOR_BIT|BGFX_CLEAR_DEPTH_BIT
 		, 0x353839FF
 		, 1.0f
-		, 0
-		);
+		, 0);
 
 	// Set view and projection matrix for view 0.
 	bgfx::setViewTransform(0, matrix4x4::to_float_ptr(view), matrix4x4::to_float_ptr(projection));

+ 3 - 11
engine/renderers/render_world.h

@@ -33,11 +33,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "pool_allocator.h"
 #include "render_world_types.h"
 #include "material_manager.h"
+#include "resource_types.h"
 
-#define MAX_MESHES 100
 #define MAX_SPRITES 512
 #define MAX_GUIS 8
 
+#include "mesh_component_manager.h"
+
 namespace crown
 {
 
@@ -59,14 +61,6 @@ public:
 	RenderWorld();
 	~RenderWorld();
 
-	MeshId create_mesh(MeshResource* mr, SceneGraph& sg, int32_t node);
-
-	/// Destroys the mesh @a id.
-	void destroy_mesh(MeshId id);
-
-	/// Returns the mesh @a id.
-	Mesh* get_mesh(MeshId mesh);
-
 	SpriteId create_sprite(SpriteResource* sr, SceneGraph& sg, int32_t node);
 
 	/// Destroys the sprite @a id.
@@ -83,11 +77,9 @@ public:
 
 private:
 
-	PoolAllocator m_mesh_pool;
 	PoolAllocator m_sprite_pool;
 	PoolAllocator m_gui_pool;
 
-	IdArray<MAX_MESHES, Mesh*> m_mesh;
 	IdArray<MAX_SPRITES, Sprite*> m_sprite;
 	IdArray<MAX_GUIS, Gui*> m_guis;
 };

+ 8 - 42
engine/world/unit.cpp

@@ -51,7 +51,6 @@ Unit::Unit(World& w, UnitId unit_id, StringId64 resid, const UnitResource* ur, c
 	, m_resource(ur)
 	, m_id(unit_id)
 	, m_num_cameras(0)
-	, m_num_meshes(0)
 	, m_num_sprites(0)
 	, m_num_actors(0)
 	, m_num_materials(0)
@@ -119,13 +118,6 @@ void Unit::destroy_objects()
 	}
 	m_num_cameras = 0;
 
-	// Destroy meshes
-	for (uint32_t i = 0; i < m_num_meshes; i++)
-	{
-		m_world.render_world()->destroy_mesh(m_meshes[i].component);
-	}
-	m_num_meshes = 0;
-
 	// Destroy sprites
 	for (uint32_t i = 0; i < m_num_sprites; i++)
 	{
@@ -170,6 +162,12 @@ void Unit::create_camera_objects()
 
 void Unit::create_renderable_objects()
 {
+	for (uint32_t i = 0; i < num_materials(m_resource); i++)
+	{
+		const UnitMaterial* mat = get_material(m_resource, i);
+		add_material(string::murmur2_32("default", string::strlen("default"), 0), material_manager::get()->create_material(mat->id));
+	}
+
 	// Create renderables
 	for (uint32_t i = 0; i < num_renderables(m_resource); i++)
 	{
@@ -177,9 +175,8 @@ void Unit::create_renderable_objects()
 
 		if (ur->type == UnitRenderable::MESH)
 		{
-			MeshResource* mr = (MeshResource*) device()->resource_manager()->get(MESH_TYPE, ur->resource);
-			MeshId mesh = m_world.render_world()->create_mesh(mr, m_scene_graph, ur->node);
-			add_mesh(ur->name, mesh);
+			// MeshResource* mr = (MeshResource*) device()->resource_manager()->get(MESH_TYPE, ur->resource);
+			// m_world.render_world()->create_mesh(mr, m_materials[0].component, m_scene_graph, ur->node);
 		}
 		else if (ur->type == UnitRenderable::SPRITE)
 		{
@@ -192,12 +189,6 @@ void Unit::create_renderable_objects()
 			CE_FATAL("Oops, bad renderable type");
 		}
 	}
-
-	for (uint32_t i = 0; i < num_materials(m_resource); i++)
-	{
-		const UnitMaterial* mat = get_material(m_resource, i);
-		add_material(string::murmur2_32("default", string::strlen("default"), 0), material_manager::get()->create_material(mat->id));
-	}
 }
 
 void Unit::create_physics_objects()
@@ -385,13 +376,6 @@ void Unit::add_camera(StringId32 name, CameraId camera)
 	add_component(name, camera, m_num_cameras, m_cameras);
 }
 
-void Unit::add_mesh(StringId32 name, MeshId mesh)
-{
-	CE_ASSERT(m_num_meshes < CE_MAX_MESH_COMPONENTS, "Max mesh number reached");
-
-	add_component(name, mesh, m_num_meshes, m_meshes);
-}
-
 void Unit::add_sprite(StringId32 name, SpriteId sprite)
 {
 	CE_ASSERT(m_num_sprites < CE_MAX_SPRITE_COMPONENTS, "Max sprite number reached");
@@ -437,24 +421,6 @@ Camera* Unit::camera(uint32_t i)
 	return m_world.get_camera(cam);
 }
 
-Mesh* Unit::mesh(const char* name)
-{
-	MeshId mesh = find_component(name, m_num_meshes, m_meshes);
-
-	CE_ASSERT(mesh.id != INVALID_ID, "Unit does not have mesh with name '%s'", name);
-
-	return m_world.render_world()->get_mesh(mesh);
-}
-
-Mesh* Unit::mesh(uint32_t i)
-{
-	MeshId mesh = find_component_by_index(i, m_num_meshes, m_meshes);
-
-	CE_ASSERT(mesh.id != INVALID_ID, "Unit does not have mesh with index '%d'", i);
-
-	return m_world.render_world()->get_mesh(mesh);
-}
-
 Sprite*	Unit::sprite(const char* name)
 {
 	SpriteId sprite = find_component(name, m_num_sprites, m_sprites);

+ 1 - 8
engine/world/unit.h

@@ -36,6 +36,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "render_world_types.h"
 #include "config.h"
 #include "sprite_animation.h"
+#include "resource_types.h"
 
 namespace crown
 {
@@ -70,7 +71,6 @@ struct Controller;
 struct Mesh;
 struct Sprite;
 struct Material;
-struct UnitResource;
 
 /// Represents a game entity.
 ///
@@ -138,7 +138,6 @@ struct Unit
 	Id find_component_by_name(StringId32 name, uint32_t size, Component* array);
 
 	void add_camera(StringId32 name, CameraId camera);
-	void add_mesh(StringId32 name, MeshId mesh);
 	void add_sprite(StringId32 name, SpriteId sprite);
 	void add_actor(StringId32 name, ActorId actor);
 	void set_controller(StringId32 name, ControllerId controller);
@@ -147,9 +146,6 @@ struct Unit
 	Camera* camera(const char* name);
 	Camera* camera(uint32_t i);
 
-	Mesh* mesh(const char* name);
-	Mesh* mesh(uint32_t i);
-
 	Sprite* sprite(const char* name);
 	Sprite* sprite(uint32_t i);
 
@@ -199,9 +195,6 @@ public:
 	uint32_t m_num_cameras;
 	Component m_cameras[CE_MAX_CAMERA_COMPONENTS];
 
-	uint32_t m_num_meshes;
-	Component m_meshes[CE_MAX_MESH_COMPONENTS];
-
 	uint32_t m_num_sprites;
 	Component m_sprites[CE_MAX_SPRITE_COMPONENTS];