From 517d35b2bbaeb3ee4b7e29301cd41bb58628bf3e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 9 Mar 2008 18:40:31 +0000 Subject: parse of light entities in models --- src/core/model.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/core/model.cc') diff --git a/src/core/model.cc b/src/core/model.cc index 52f0dde..da179e5 100644 --- a/src/core/model.cc +++ b/src/core/model.cc @@ -21,6 +21,16 @@ namespace core const float MAX_BOUNDS = 8192; const float delta = 10e-10; +/* ---------- core::Light ------------------------------------------ */ + +Light::Light(math::Vector3f const & location, math::Color const & color) : + light_location(location), + light_color(color) +{} + +Light::~Light() +{} + /* ---------- core::Engine ------------------------------------------ */ Engine::Engine(math::Vector3f const & location) : @@ -102,6 +112,7 @@ Model::Model(std::string const & name) : std::string class_name; math::Vector3f class_origin; float class_angle; + math::Color class_color; while (ifs) { ifs.getline(data, 1023); @@ -113,6 +124,12 @@ Model::Model(std::string const & name) : //cout << " COMMENT!" << std::endl; continue; } else if (firstword == "{") { + if (!level) { + class_angle = 0; + class_name.clear(); + class_origin = math::Vector3f(0,0,0); + class_color = math::Color(1, 1, 1); + } level ++; //cout << " LEVEL +" << level << std::endl; } else if (firstword == "}") { @@ -135,6 +152,8 @@ Model::Model(std::string const & name) : } else if ((level == 1) && (class_name == "target_engine")) { //con_debug << " engine at " << class_origin << "\n"; add_engine(new Engine(class_origin * model_scale)); + } else if ((level == 1) && (class_name == "light")) { + add_light(new Light(class_origin * model_scale, class_color)); } if (level == 1) { @@ -170,7 +189,18 @@ Model::Model(std::string const & name) : is >> class_origin.y; is >> class_origin.z; //con_debug << " origin '" << class_origin << "'" << std::endl; - + + } else if (firstword == "\"_color\"") { + std::string tmp; + char c; + while ((linestream.get(c)) && (c != '"')); + while ((linestream.get(c)) && (c != '"')) + tmp += c; + std::istringstream is(tmp); + is >> class_color.r; + is >> class_color.g; + is >> class_color.b; + } else if (firstword == "\"angle\"") { std::string tmp; char c; @@ -180,6 +210,7 @@ Model::Model(std::string const & name) : std::istringstream is(tmp); is >> class_angle; //con_debug << " angle '" << class_angle << "'" << std::endl; + } else if (firstword == "(") { if ((level == 2) && (class_name == "worldspawn")) { //cout << " BRUSH PLANE" << std::endl; @@ -234,6 +265,12 @@ Model::~Model() delete(*eit); } model_engine.clear(); + + // delete all lights + for (std::list::iterator lit = model_light.begin(); lit != model_light.end(); lit++) { + delete (*lit); + } + model_light.clear(); } void Model::make_face(math::Plane3f *face, std::vector & planes) @@ -500,6 +537,11 @@ void Model::add_engine(Engine *engine) model_engine.push_back(engine); } +void Model::add_light(Light *light) +{ + model_light.push_back(light); +} + Model *Model::find(std::string const & name) { std::map::iterator it = registry.find(name); @@ -531,7 +573,9 @@ void Model::clear() void Model::list() { for (std::map::iterator mit = registry.begin(); mit != registry.end(); mit++) { - con_print << " " << (*mit).second->model_name << " " << (*mit).second->model_face.size() << " polys\n"; + con_print << " " << (*mit).second->model_name << " " << (*mit).second->model_face.size() << " polys " + << (*mit).second->model_engine.size() << " engines " + << (*mit).second->model_light.size() << " lights\n"; } con_print << registry.size() << " registered models" << std::endl; } -- cgit v1.2.3