diff options
author | Stijn Buys <ingar@osirion.org> | 2011-01-27 12:36:26 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2011-01-27 12:36:26 +0000 |
commit | 2a87246be478e5ddd2bef4080f36382a889e02dd (patch) | |
tree | d203a9a49044f03764dc2661f688b1c6c836e56d /src | |
parent | 45b93da49b74acd7389e4faa1cfd5dba6cd75c95 (diff) |
Moved material loading from render to core, make sure the dedicated server reads materials.ini,
removed unnecessary CollisionMesh::translate() method.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/video.cc | 14 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 9 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 9 | ||||
-rw-r--r-- | src/model/collisionmesh.cc | 15 | ||||
-rw-r--r-- | src/model/collisionmesh.h | 2 | ||||
-rw-r--r-- | src/model/mapfile.cc | 90 | ||||
-rw-r--r-- | src/render/render.cc | 22 |
7 files changed, 80 insertions, 81 deletions
diff --git a/src/client/video.cc b/src/client/video.cc index 84bbe52..2949ae7 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -227,7 +227,7 @@ bool init() // initialize renderer render::init(width, height); - + // apply render options ui::root()->load_settings(); @@ -267,10 +267,22 @@ void resize(int w, int h) void restart() { shutdown(); + + // clear models and materials + /* resetting the rednder subsystem will force a reload of all materials + */ + model::Model::clear(); + + model::Material::clear(); + if (!init()) { client()->quit(1); } + + model::Material::init(); + render::load(); + input::reset(); } diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 58fe6be..76d46c4 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -148,6 +148,11 @@ void func_list_model(std::string const &args) } +void func_list_materials(std::string const &args) +{ + model::Material::list(); +} + void func_list_module(std::string const &args) { Loader::list(); @@ -266,6 +271,9 @@ void CommandBuffer::init() func = Func::add("list_zone", (FuncPtr)func_list_zone); func->set_info("list zones"); + + func = core::Func::add("list_materials", func_list_materials); + func->set_info("list materials"); Func::add("list_model", (FuncPtr) func_list_model); func->set_info("list 3d models"); @@ -303,6 +311,7 @@ void CommandBuffer::shutdown() Func::remove("list_info"); Func::remove("list_inventories"); Func::remove("list_ent"); + Func::remove("list_material"); Func::remove("list_model"); Func::remove("list_module"); Func::remove("list_zone"); diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 0a485bc..1d3e6fb 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -16,6 +16,7 @@ #include "core/gameinterface.h" #include "core/player.h" #include "core/zone.h" +#include "model/material.h" #include "model/model.h" #include "sys/sys.h" @@ -70,6 +71,7 @@ GameInterface::GameInterface() Func *func = Func::add("list_players", func_list_players); func->set_info("get the local list of connected players"); + // TODO this should be moved back into render size_t mb = (size_t) Cvar::mem_vertex->value(); if (mb < 4 * sizeof(float)) mb = 4 * sizeof(float); @@ -77,6 +79,8 @@ GameInterface::GameInterface() mb = 512; (*Cvar::mem_vertex) = (float) mb; game_vertexarray = new model::VertexArray(mb); + + model::Material::init(); } GameInterface::~GameInterface() @@ -106,8 +110,11 @@ void GameInterface::clear() // remove info records Info::clear(); - // remove all models + // remove models model::Model::clear(); + + // remove materials + model::Material::clear(); // clear player list for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) { diff --git a/src/model/collisionmesh.cc b/src/model/collisionmesh.cc index b20074f..90aafc3 100644 --- a/src/model/collisionmesh.cc +++ b/src/model/collisionmesh.cc @@ -34,7 +34,8 @@ void CollisionMesh::clear() con_debug << " clearing collision meshes" << std::endl; for (Registry::iterator i = collisionmesh_registry.begin(); i != collisionmesh_registry.end(); ++i) { - delete(*i).second; + delete (*i).second; + (*i).second = 0; } collisionmesh_registry.clear(); @@ -73,16 +74,4 @@ void CollisionMesh::add_triangle(const math::Vector3f & v0, const math::Vector3f collisionmesh_size += 1; } -void CollisionMesh::translate(const math::Vector3f translation) -{ - /* - IndexedMeshArray & indexes = collisionmesh_triangles->getIndexedMeshArray(); - for (size_t i =0; i < indexes.size(); i++) { - btIndexedMesh & mesh = indexes[i]; - - - } - */ -} - } // namespace model diff --git a/src/model/collisionmesh.h b/src/model/collisionmesh.h index 7329a0e..9efd21a 100644 --- a/src/model/collisionmesh.h +++ b/src/model/collisionmesh.h @@ -58,8 +58,6 @@ public: * @brief add a triangle to the collision mesh */ void add_triangle(const math::Vector3f & v0, const math::Vector3f & v1, const math::Vector3f & v2); - - void translate(const math::Vector3f translation); /* ---- static ----------------------------------------------------- */ diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index c5e2964..f3f347f 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1158,9 +1158,6 @@ void MapFile::clear_bbox() void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_type) { - if (!VertexArray::instance() || VertexArray::instance()->overflow()) - return; - if (!map_materials.size()) return; @@ -1198,7 +1195,20 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t // store triangles if (primitives->triangles().size()) { - if (!(primitives->material()->flags() & Material::Clip)) { + + if ((primitives->material()->flags() & Material::Clip) == Material::Clip) { + + if (map_load_clip) { + // clip materials are loaded into the CollisionMesh + for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) { + Triangle *triangle = (*tris_it); + //model->collisionmesh()->add_triangle(triangle->v0(), triangle->v1(), triangle->v2()); + map_collisiontriangles.add(*triangle); + } + } + + } else if (VertexArray::instance() && !VertexArray::instance()->overflow()) { + Fragment *fragment = new Fragment(Fragment::Triangles, primitives->material()); // add structural triangles to the fragment @@ -1231,54 +1241,50 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t // add the fragment to the group group->add_fragment(fragment); - - } else if (map_load_clip) { - // clip materials are loaded into the CollisionMesh - for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) { - Triangle *triangle = (*tris_it); - //model->collisionmesh()->add_triangle(triangle->v0(), triangle->v1(), triangle->v2()); - map_collisiontriangles.add(*triangle); - } } } // store quads if (primitives->quads().size()) { - Fragment *fragment = new Fragment(Fragment::Quads, primitives->material()); - - // add structural quads to the fragment - for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { - Quad *quad = (*quad_it); - if (!quad->detail()) { - size_t count = 0; - count += fragment->add_vertex(quad->v0() - translation, quad->n0(), quad->t0(), false); - count += fragment->add_vertex(quad->v1() - translation, quad->n1(), quad->t1(), false); - count += fragment->add_vertex(quad->v2() - translation, quad->n2(), quad->t2(), false); - count += fragment->add_vertex(quad->v3() - translation, quad->n3(), quad->t3(), false); - if (count == 4) { - model->model_quad_count++; + + if (VertexArray::instance() && !VertexArray::instance()->overflow()) { + + Fragment *fragment = new Fragment(Fragment::Quads, primitives->material()); + + // add structural quads to the fragment + for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { + Quad *quad = (*quad_it); + if (!quad->detail()) { + size_t count = 0; + count += fragment->add_vertex(quad->v0() - translation, quad->n0(), quad->t0(), false); + count += fragment->add_vertex(quad->v1() - translation, quad->n1(), quad->t1(), false); + count += fragment->add_vertex(quad->v2() - translation, quad->n2(), quad->t2(), false); + count += fragment->add_vertex(quad->v3() - translation, quad->n3(), quad->t3(), false); + if (count == 4) { + model->model_quad_count++; + } } } - } - // add detail quads to the fragment - for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { - Quad *quad = (*quad_it); - if (quad->detail()) { - size_t count = 0; - count += fragment->add_vertex(quad->v0() - translation, quad->n0(), quad->t0(), true); - count += fragment->add_vertex(quad->v1() - translation, quad->n1(), quad->t1(), true); - count += fragment->add_vertex(quad->v2() - translation, quad->n2(), quad->t2(), true); - count += fragment->add_vertex(quad->v3() - translation, quad->n3(), quad->t3(), true); - if (count == 4) { - model->model_quad_count++; - model->model_quad_detail_count++; + // add detail quads to the fragment + for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) { + Quad *quad = (*quad_it); + if (quad->detail()) { + size_t count = 0; + count += fragment->add_vertex(quad->v0() - translation, quad->n0(), quad->t0(), true); + count += fragment->add_vertex(quad->v1() - translation, quad->n1(), quad->t1(), true); + count += fragment->add_vertex(quad->v2() - translation, quad->n2(), quad->t2(), true); + count += fragment->add_vertex(quad->v3() - translation, quad->n3(), quad->t3(), true); + if (count == 4) { + model->model_quad_count++; + model->model_quad_detail_count++; + } } } - } - // add the fragment to the group - group->add_fragment(fragment); + // add the fragment to the group + group->add_fragment(fragment); + } } } @@ -1354,7 +1360,7 @@ Model * MapFile::load(std::string const &name) model->set_collisionmesh(CollisionMesh::find(name)); if (CollisionMesh::initialized() && !model->collisionmesh()) { - mapfile.map_load_clip = true; + mapfile.map_load_clip = true; } else { mapfile.map_load_clip = false; } diff --git a/src/render/render.cc b/src/render/render.cc index f24eb83..3d538da 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -50,11 +50,6 @@ void func_list_textures(std::string const &args) Textures::list(); } -void func_list_materials(std::string const &args) -{ - model::Material::list(); -} - void func_list_particles(std::string const &args) { ParticleScript::list(); @@ -141,23 +136,15 @@ void init(int width, int height) Dust::init(); - // read materials - model::Material::init(); - // engine functions core::Func *func = core::Func::add("list_textures", func_list_textures); func->set_info("list registered textures"); - func = core::Func::add("list_materials", func_list_materials); - func->set_info("list registered materials"); - func = core::Func::add("list_particles", func_list_particles); func->set_info("list registered particle scripts"); func = core::Func::add("r_loadmodels", func_load_info_models); func->set_info("load all models referenced by info record"); - - load(); } // unload game assets (zone change) @@ -212,12 +199,6 @@ void clear() } } - // clear model registry - model::Model::clear(); - - // clear materials - model::Material::clear(); - // clear particle system scripts ParticleScript::clear(); } @@ -272,8 +253,6 @@ void reset() Textures::init(); Dust::reset(); - - model::Material::init(); } void resize(int width, int height) @@ -285,7 +264,6 @@ void shutdown() { con_print << "^BShutting down renderer..." << std::endl; - core::Func::remove("list_materials"); core::Func::remove("list_particles"); core::Func::remove("list_textures"); core::Func::remove("r_loadmodels"); |