From 14ea3d9d037175d4d5326ac9c83fe69ddcd0d9c4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 8 Oct 2012 19:58:08 +0000 Subject: added zone flags, renamed Entity::flag_is_set() to Entity::has_flag() --- src/client/mapwidget.cc | 2 +- src/client/mapwindow.cc | 4 ++-- src/client/targets.cc | 4 ++-- src/core/entity.cc | 6 +++--- src/core/entity.h | 23 ++++++++++++++++------- src/core/gameserver.cc | 2 +- src/core/zone.h | 29 +++++++++++++++++++++++++++++ src/game/base/game.cc | 2 +- src/game/base/savegame.cc | 2 +- src/render/draw.cc | 12 ++++++------ 10 files changed, 62 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/client/mapwidget.cc b/src/client/mapwidget.cc index 44ec32a..0a4ec72 100644 --- a/src/client/mapwidget.cc +++ b/src/client/mapwidget.cc @@ -144,7 +144,7 @@ void MapWidget::draw() if (draw_icon) { if (entity->type() == core::Entity::Globe) { - if (entity->flag_is_set(core::Entity::Bright)) { + if (entity->has_flag(core::Entity::Bright)) { if (texture_current != texture_bright) { gl::end(); texture_current = render::Textures::bind(texture_bright); diff --git a/src/client/mapwindow.cc b/src/client/mapwindow.cc index 1c429dd..e6bc5bb 100644 --- a/src/client/mapwindow.cc +++ b/src/client/mapwindow.cc @@ -236,11 +236,11 @@ void MapWindow::show_entity_info(const core::Entity *entity) mapwindow_modelview->set_colors(globe->color(), globe->color_second()); mapwindow_modelview->set_globetexturename( globe->texturename(), - globe->flag_is_set(core::Entity::Bright), + globe->has_flag(core::Entity::Bright), globe->coronaname() ); mapwindow_modelview->set_zoom(2.5f); - if (globe->flag_is_set(core::Entity::Bright)) { + if (globe->has_flag(core::Entity::Bright)) { mapwindow_modelview->set_radius(0.5f); } else { mapwindow_modelview->set_radius(1.0f); diff --git a/src/client/targets.cc b/src/client/targets.cc index eff1512..9137739 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -46,7 +46,7 @@ bool is_valid_map_target(const core::Entity *entity) return false; } else if (entity == core::localcontrol()) { return false; - } else if (entity->flag_is_set(core::Entity::ShowOnMap)) { + } else if (entity->has_flag(core::Entity::ShowOnMap)) { return true; } else if (entity == core::localplayer()->mission_target()) { return true; @@ -61,7 +61,7 @@ bool is_valid_hud_target(const core::Entity *entity) return false; } else if (entity == core::localcontrol()) { return false; - } else if (entity->flag_is_set(core::Entity::ShowOnMap)) { + } else if (entity->has_flag(core::Entity::ShowOnMap)) { return true; } else if (entity == core::localplayer()->mission_target()) { return true; diff --git a/src/core/entity.cc b/src/core/entity.cc index 3094208..7bb5278 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -550,7 +550,7 @@ void Entity::frame(const unsigned long elapsed) void Entity::reset() { - if (!radius() || flag_is_set(NonSolid)) { + if (!radius() || has_flag(NonSolid)) { return; } @@ -695,7 +695,7 @@ void EntityDynamic::set_state(int state) void EntityDynamic::reset() { - if (!radius() || flag_is_set(NonSolid)) { + if (!radius() || has_flag(NonSolid)) { return; } @@ -1169,7 +1169,7 @@ void EntityControlable::set_zone(Zone *zone) void EntityControlable::reset() { - if (!radius() || flag_is_set(NonSolid)) { + if (!radius() || has_flag(NonSolid)) { return; } diff --git a/src/core/entity.h b/src/core/entity.h index 07a3bec..19e47bc 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -44,7 +44,12 @@ class Entity : public Label public: /** * @brief entity flags - */ + * NonSolid will exclude the entity from the bullet physics world + * Bright is used by EntityGlobe, where a bright sphere is a light source + * Dockable means the entity can be docked by a player + * ShowOnMap will make the entity appear on the map + * KeepAlive is used by EntityDynamic and marks the entity as deletable in the keepalive run + * */ enum Flags {NonSolid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16, KeepAlive = 32}; /// Entity type constants @@ -94,7 +99,7 @@ public: } /// returns true of a flag is set - inline const bool flag_is_set(const Flags flag) const { + inline const bool has_flag(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } @@ -321,14 +326,18 @@ public: entity_axis.assign(axis); } - /// set flag + /** + * @brief set flag + * */ inline void set_flag(Flags flag) { - entity_flags |= flag; + entity_flags |= (unsigned int) flag; } - /// unset flag + /** + * @brief unset flag + * */ inline void unset_flag(Flags flag) { - entity_flags &= ~flag; + entity_flags &= ~((unsigned int) flag); } /** @@ -684,7 +693,7 @@ public: } /// returns true if the specified control flag is set - inline bool control_flag_is_set(ControlFlags flag) const { + inline bool control_has_flag(ControlFlags flag) const { return ((flag && entity_control_flags) == flag); } diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index f9cc061..579f65d 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -641,7 +641,7 @@ void GameServer::frame(const unsigned long timestamp) for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { Entity *entity = (*it).second; Zone *zone = entity->zone(); - if (zone && entity->flag_is_set(Entity::KeepAlive)) { + if (zone && entity->has_flag(Entity::KeepAlive)) { if (zone->keepalive_run() && zone->keepalive_box().inside(entity->location())) { entity->set_keepalive(this->timestamp()); diff --git a/src/core/zone.h b/src/core/zone.h index 644620d..22440c4 100644 --- a/src/core/zone.h +++ b/src/core/zone.h @@ -76,6 +76,8 @@ public: } /* ---- Zone class ----------------------------------------- */ + + enum Flags { Hidden = 1 }; /** * @brief create a new zone @@ -103,6 +105,18 @@ public: inline unsigned int id() const { return zone_id; } + + /// zone flags + inline const unsigned int flags() const { + return zone_flags; + } + + /** + * @brief returns true if a specified flag is set + * */ + inline const bool has_flag(const Flags flag) const { + return ((zone_flags & (unsigned int) flag) == (unsigned int) flag); + } /// ambient light color inline math::Color const & ambient_color() { @@ -144,6 +158,20 @@ public: Entity *search_entity(const std::string & label); /* ---- mutators ------------------------------------------- */ + + /** + * @brief set flag + * */ + inline void set_flag(Flags flag) { + zone_flags |= (unsigned int) flag; + } + + /** + * @brief unset flag + * */ + inline void unset_flag(Flags flag) { + zone_flags &= ~((unsigned int) flag); + } /** * @brief set the skybox name @@ -244,6 +272,7 @@ public: private: unsigned int zone_id; + unsigned int zone_flags; std::string zone_sky; math::Color zone_ambient_color; diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 3fbcbb0..93145f7 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -1532,7 +1532,7 @@ bool Game::validate_zone(core::Zone *zone) JumpGate *jumpgate = static_cast(entity); jumpgate->validate(); } else { - if (entity->flag_is_set(core::Entity::Dockable)) { + if (entity->has_flag(core::Entity::Dockable)) { generate_entity_menus(entity); } } diff --git a/src/game/base/savegame.cc b/src/game/base/savegame.cc index b6955e2..702dd49 100644 --- a/src/game/base/savegame.cc +++ b/src/game/base/savegame.cc @@ -128,7 +128,7 @@ void SaveGame::load_game(core::Player *player, filesystem::IniFile & inifile) continue; } - if (!spawn_entity->flag_is_set(core::Entity::Dockable)) { + if (!spawn_entity->has_flag(core::Entity::Dockable)) { inifile.unknown_error("spawn '" + str + "' is not dockable"); continue; } diff --git a/src/render/draw.cc b/src/render/draw.cc index fbc499f..88a08b9 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -110,9 +110,9 @@ void pass_prepare(float seconds) } // add zone lights - if (globe->flag_is_set(core::Entity::Bright)) { + if (globe->has_flag(core::Entity::Bright)) { Light *zone_light = new Light(globe->location(), globe->color()); - zone_light->set_attenuation(0.0005f, 0.0005f, 0.0f); + zone_light->set_attenuation(2.0f, 0.0f, 0.0f); lightenv_zone.add(zone_light); } @@ -292,7 +292,7 @@ void draw_pass_globes() gl::push(); gl::translate(location); - if (globe->flag_is_set(core::Entity::Bright)) { + if (globe->has_flag(core::Entity::Bright)) { gl::disable(GL_LIGHTING); if (globe->corona_id()) { // draw globe corona @@ -322,7 +322,7 @@ void draw_pass_globes() gl::disable(GL_TEXTURE_2D); } - if (globe->flag_is_set(core::Entity::Bright)) { + if (globe->has_flag(core::Entity::Bright)) { gl::enable(GL_LIGHTING); } @@ -500,7 +500,7 @@ void draw_pass_default() gl::translate(entity->location()); gl::multmatrix(entity->axis()); - if (entity->flag_is_set(core::Entity::Bright)) { + if (entity->has_flag(core::Entity::Bright)) { gl::disable(GL_LIGHTING); } @@ -524,7 +524,7 @@ void draw_pass_default() break; } - if (entity->flag_is_set(core::Entity::Bright)) { + if (entity->has_flag(core::Entity::Bright)) { gl::enable(GL_LIGHTING); } -- cgit v1.2.3