From 18dc1f6d0e044e5e4b1f3a40fcc65e532ec2e765 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 28 Sep 2013 12:13:29 +0000 Subject: Cleanup of the material API: split flags into flags and colortype. --- src/model/asefile.cc | 2 +- src/model/mapfile.cc | 16 +++++----- src/model/material.cc | 85 +++++++++++++++++++++++++++++---------------------- src/model/material.h | 22 +++++++++++-- 4 files changed, 76 insertions(+), 49 deletions(-) (limited to 'src/model') diff --git a/src/model/asefile.cc b/src/model/asefile.cc index 320d4b7..608dac3 100644 --- a/src/model/asefile.cc +++ b/src/model/asefile.cc @@ -583,7 +583,7 @@ bool ASEFile::read_geom(std::istream &is) size_t submaterial_index = (*smit).first; Material *material = (*smit).second; - if ((material->flags() & Material::Ignore) != Material::Ignore ) { + if (!material->ignore_is_set()) { // load GEOMOBJECT triangles with matching material into the fragment Fragment *fragment = new Fragment(Fragment::Triangles, material); diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 359efe7..d4632e2 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -397,7 +397,7 @@ bool MapFile::read_patchdef() } // ignore materials with the 'Ignore' flag set - if ((material->flags() & Material::Ignore) == Material::Ignore) { + if (material->ignore_is_set()) { return true; } @@ -527,7 +527,7 @@ bool MapFile::read_patchdef() for (size_t i = 0; i < subdivide_u; i++) { for (size_t j = 0; j < subdivide_v; j++) { - if ((material->flags() & Material::Clip) == Material::Clip) { + if (material->flag_is_set(Material::FlagClip)) { // if the current material is clip, the patch needs to be converted to triangles if (map_load_clip) { @@ -754,7 +754,7 @@ void MapFile::make_brushface(Face *face) using math::Vector3f; // ignore materials with the 'Ignore' flag set - if ((face->material()->flags() & Material::Ignore) == Material::Ignore) { + if (face->material()->ignore_is_set()) { return; } @@ -954,7 +954,7 @@ void MapFile::make_brushface(Face *face) primitives = (*mit).second; } - if ((face->material()->flags() & Material::Origin)) { + if (face->material()->origin_is_set()) { // add vertices to the origin list for (std::vector::iterator it = vl.begin(); it != vl.end(); ++it) { class_origin_vertices.push_back(new math::Vector3f((*(*it) * SCALE))); @@ -972,7 +972,7 @@ void MapFile::make_brushface(Face *face) face_normal.normalize(); // clip faces have to be triangulated and can not be split into quads - if (!(face->material()->flags() & Material::Clip)) { + if (!face->material()->flag_is_set(Material::FlagClip)) { // split polygon into quads while (vl.size() > 3) { @@ -987,7 +987,7 @@ void MapFile::make_brushface(Face *face) Quad *quad = new Quad(*(*vn2) * SCALE, *(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail()); primitives->add_quad(quad); - if (face->material()->flags() & Material::Texture) { + if (face->material()->flag_is_set(Material::FlagTexture)) { quad->t0().assign(map_texture_coords(face, *(*vn2))); quad->t1().assign(map_texture_coords(face, *(*vn1))); quad->t2().assign(map_texture_coords(face, *(*vn))); @@ -1011,7 +1011,7 @@ void MapFile::make_brushface(Face *face) Triangle * triangle = new Triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail()); primitives->add_triangle(triangle); - if (face->material()->flags() & Material::Texture) { + if (face->material()->flag_is_set(Material::FlagTexture)) { triangle->t0().assign(map_texture_coords(face, *(*vn1))); triangle->t1().assign(map_texture_coords(face, *(*vn))); triangle->t2().assign(map_texture_coords(face, *(*v0))); @@ -1245,7 +1245,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t // store triangles if (primitives->triangles().size()) { - if ((primitives->material()->flags() & Material::Clip) == Material::Clip) { + if (primitives->material()->flag_is_set(Material::FlagClip)) { if (map_load_clip) { // clip materials are loaded into the CollisionMesh diff --git a/src/model/material.cc b/src/model/material.cc index ff9a257..5a99489 100644 --- a/src/model/material.cc +++ b/src/model/material.cc @@ -26,6 +26,7 @@ Material::Material(const std::string &name) : { aux::to_lowercase(material_name); material_flags = 0; + material_colortype = ColorMaterial; material_texture_id = 0; } @@ -37,43 +38,47 @@ Material::~Material() void Material::print() { con_print << name() << std::endl; - con_print << " color: " << material_color.r << " " << material_color.g << " " << material_color.b << " " << material_color.a << std::endl; - con_print << " flags: " << flags() << " "; - if (flags() == None) { + + con_print << " material color: " << material_color.r << " " << material_color.g << " " << material_color.b << " " << material_color.a << std::endl; + switch (colortype()) { + case ColorMaterial: + break; + case ColorPrimary: + con_print << " color type " << "entity primary" << std::endl; + break; + case ColorSecondary: + con_print << " color type " << "entity secondary" << std::endl; + break; + case ColorTertiary: + con_print << " color type " << "entity tertiary" << std::endl; + break; + case ColorEngine: + con_print << " color type " << "entity engine" << std::endl; + break; + } + con_print << " flags: " << flags() << " "; + if (flags() == FlagNone) { con_print << "none"; } else { - if ((flags() & Tertiary) == Tertiary) { - con_print << "entitythird "; - - } else if (flags() & Secondary) { - con_print << "entitysecond "; - - } else if (flags() & Primary) { - con_print << "entity "; - } - - if (flags() & Bright) { + if (flags() & FlagBright) { con_print << "bright "; } - if (flags() & Engine) { - con_print << "engine "; - } - if (flags() & Environment) { + if (flags() & FlagEnvironment) { con_print << "environment "; } - if (flags() & Texture) { + if (flags() & FlagTexture) { con_print << "texture "; } - if (flags() & Ignore) { + if (flags() & FlagIgnore) { con_print << "ignore "; } - if (flags() & Clip) { + if (flags() & FlagClip) { con_print << "clip "; } - if (flags() & Origin) { + if (flags() & FlagOrigin) { con_print << "origin "; } - if (flags() & Decal) { + if (flags() & FlagDecal) { con_print << "decal "; } } @@ -99,13 +104,13 @@ void Material::set_specular(const math::Color &color) void Material::set_texture(const std::string &texture) { if (texture.size()) { - set_flags(Texture); + set_flags(FlagTexture); material_texture.assign(texture); if (material_loaderfunc) { material_loaderfunc(this); } } else { - unset_flags(Texture); + unset_flags(FlagTexture); material_texture.clear(); material_texture_id = 0; } @@ -126,6 +131,11 @@ void Material::set_size(const math::Vector2f &size) material_size.assign(size); } +void Material::set_colortype(ColorType colortype) +{ + material_colortype = colortype; +} + void Material::init() { con_print << "^BInitializing materials..." << std::endl; @@ -249,25 +259,26 @@ void Material::load_shader(const std::string &shadername) material->set_specular(math::Color(r, g, b, a)); } } else if (firstword.compare("engine") == 0) { - material->set_flags(Engine); - } else if (firstword.compare("bright") == 0) { - material->set_flags(Bright); - } else if (firstword.compare("environment") == 0) { - material->set_flags(Environment); + material->set_colortype(ColorEngine); } else if (firstword.compare("entity") == 0) { - material->set_flags(Primary); + material->set_colortype(ColorPrimary); } else if (firstword.compare("entitysecond") == 0) { - material->set_flags(Secondary); + material->set_colortype(ColorSecondary); } else if (firstword.compare("entitythird") == 0) { - material->set_flags(Tertiary); + material->set_colortype(ColorTertiary); + + } else if (firstword.compare("bright") == 0) { + material->set_flags(FlagBright); + } else if (firstword.compare("environment") == 0) { + material->set_flags(FlagEnvironment); } else if (firstword.compare("ignore") == 0) { - material->set_flags(Ignore); + material->set_flags(FlagIgnore); } else if (firstword.compare("clip") == 0) { - material->set_flags(Clip); + material->set_flags(FlagClip); } else if (firstword.compare("origin") == 0) { - material->set_flags(Origin); + material->set_flags(FlagOrigin); } else if (firstword.compare("decal") == 0) { - material->set_flags(Decal); + material->set_flags(FlagDecal); } else if (firstword.compare("qer_editorimage") == 0) { // keyword qer_editorimage is ignored continue; diff --git a/src/model/material.h b/src/model/material.h index 2c66aae..6c332e2 100644 --- a/src/model/material.h +++ b/src/model/material.h @@ -23,8 +23,11 @@ public: /// function pointer type for local functions typedef void(* LoaderFuncPtr)(Material *); + /// color types + enum ColorType {ColorMaterial = 0, ColorPrimary = 1, ColorSecondary = 2, ColorTertiary = 3, ColorEngine = 4 }; + /// surface flags - enum SurfaceFlags { None = 0, Primary = 1, Secondary = 2, Tertiary = 3, Bright = 4, Engine = 8, Environment = 16, Texture = 32, Ignore = 64, Clip = 128, Origin = 256, Decal = 512 }; + enum SurfaceFlags { FlagNone = 0, FlagBright = 1,FlagEnvironment = 2, FlagTexture = 4, FlagIgnore = 8, FlagClip = 16, FlagOrigin = 32, FlagDecal = 64 }; /// type definition for the material registry typedef std::map Registry; @@ -52,6 +55,10 @@ public: inline const unsigned int flags() const { return material_flags; } + + inline const ColorType colortype() const { + return material_colortype; + } inline const std::string &texture() const { return material_texture; @@ -80,7 +87,7 @@ public: * @see flags() * */ inline bool ignore_is_set() const { - return (flag_is_set(Ignore)); + return (flag_is_set(FlagIgnore)); } /** @@ -88,13 +95,15 @@ public: * @see flags() * */ inline bool origin_is_set() const { - return (flag_is_set(Origin)); + return (flag_is_set(FlagOrigin)); } /* ---- mutators ------------------------------------------- */ void set_color(const math::Color &color); + void set_specular(const math::Color &specular); + /** * @brief set the material texture name */ @@ -114,6 +123,12 @@ public: * @brief set the material texture size */ void set_size(const math::Vector2f &size); + + /** + * @brief set the color type + * */ + void set_colortype(ColorType colortype); + inline void set_flags(SurfaceFlags flags) { material_flags |= flags; @@ -164,6 +179,7 @@ private: math::Color material_color; math::Color material_specular; unsigned int material_flags; + ColorType material_colortype; std::string material_texture; size_t material_texture_id; -- cgit v1.2.3