From: <geo...@us...> - 2012-11-24 02:45:48
|
Revision: 5456 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=5456&view=rev Author: geoffthemedio Date: 2012-11-24 02:45:42 +0000 (Sat, 24 Nov 2012) Log Message: ----------- -Added UniverseObject::ObjectType function, overridden by derived classes, that returns an enum indicating the type of the object. -Attempt to speed species effect target set calculation by checking the result of ObjectType before dynamic_casting the object pointer. Modified Paths: -------------- trunk/FreeOrion/universe/Building.cpp trunk/FreeOrion/universe/Building.h trunk/FreeOrion/universe/Field.cpp trunk/FreeOrion/universe/Field.h trunk/FreeOrion/universe/Fleet.cpp trunk/FreeOrion/universe/Fleet.h trunk/FreeOrion/universe/Planet.cpp trunk/FreeOrion/universe/Planet.h trunk/FreeOrion/universe/Ship.cpp trunk/FreeOrion/universe/Ship.h trunk/FreeOrion/universe/System.cpp trunk/FreeOrion/universe/System.h trunk/FreeOrion/universe/Universe.cpp trunk/FreeOrion/universe/UniverseObject.cpp trunk/FreeOrion/universe/UniverseObject.h Modified: trunk/FreeOrion/universe/Building.cpp =================================================================== --- trunk/FreeOrion/universe/Building.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Building.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -105,6 +105,9 @@ const std::string& Building::TypeName() const { return UserString("BUILDING"); } +UniverseObjectType Building::ObjectType() const +{ return OBJ_BUILDING; } + std::string Building::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/Building.h =================================================================== --- trunk/FreeOrion/universe/Building.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Building.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -37,6 +37,7 @@ virtual bool HasTag(const std::string& name) const; ///< returns true iff this object has the tag with the indicated \a name virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; virtual std::string Dump() const; const std::string& BuildingTypeName() const { return m_building_type; }; ///< returns the name of the BuildingType object for this building Modified: trunk/FreeOrion/universe/Field.cpp =================================================================== --- trunk/FreeOrion/universe/Field.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Field.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -113,6 +113,9 @@ const std::string& Field::TypeName() const { return UserString("FIELD"); } +UniverseObjectType Field::ObjectType() const +{ return OBJ_FIELD; } + std::string Field::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/Field.h =================================================================== --- trunk/FreeOrion/universe/Field.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Field.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -18,9 +18,12 @@ virtual std::vector<std::string> Tags() const; ///< returns all tags this object has virtual bool HasTag(const std::string& name) const; ///< returns true iff this object has the tag with the indicated \a name + virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; + virtual std::string Dump() const; + const std::string& FieldTypeName() const { return m_type_name; } - virtual std::string Dump() const; virtual UniverseObject* Accept(const UniverseObjectVisitor& visitor) const; bool InField(const UniverseObject* obj) const; Modified: trunk/FreeOrion/universe/Fleet.cpp =================================================================== --- trunk/FreeOrion/universe/Fleet.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Fleet.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -114,6 +114,9 @@ const std::string& Fleet::TypeName() const { return UserString("FLEET"); } +UniverseObjectType Fleet::ObjectType() const +{ return OBJ_FLEET; } + std::string Fleet::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/Fleet.h =================================================================== --- trunk/FreeOrion/universe/Fleet.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Fleet.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -47,6 +47,7 @@ /** \name Accessors */ //@{ virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; virtual std::string Dump() const; const_iterator begin() const { return m_ships.begin(); } ///< returns the begin const_iterator for the ships in the fleet Modified: trunk/FreeOrion/universe/Planet.cpp =================================================================== --- trunk/FreeOrion/universe/Planet.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Planet.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -182,6 +182,9 @@ const std::string& Planet::TypeName() const { return UserString("PLANET"); } +UniverseObjectType Planet::ObjectType() const +{ return OBJ_PLANET; } + std::string Planet::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/Planet.h =================================================================== --- trunk/FreeOrion/universe/Planet.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Planet.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -93,6 +93,7 @@ virtual bool HasTag(const std::string& name) const; ///< returns true iff this object has the tag with the indicated \a name virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; virtual std::string Dump() const; PlanetType Type() const { return m_type; } Modified: trunk/FreeOrion/universe/Ship.cpp =================================================================== --- trunk/FreeOrion/universe/Ship.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Ship.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -225,6 +225,9 @@ const std::string& Ship::TypeName() const { return UserString("SHIP"); } +UniverseObjectType Ship::ObjectType() const +{ return OBJ_SHIP; } + std::string Ship::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/Ship.h =================================================================== --- trunk/FreeOrion/universe/Ship.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Ship.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -32,6 +32,8 @@ virtual bool HasTag(const std::string& name) const; ///< returns true iff this object has the tag with the indicated \a name virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; + virtual std::string Dump() const; const ShipDesign* Design() const; ///< returns the design of the ship, containing engine type, weapons, etc. int DesignID() const { return m_design_id; } ///< returns the design id of the ship @@ -39,7 +41,6 @@ int ProducedByEmpireID() const { return m_produced_by_empire_id; } ///< returns the empire ID of the empire that produced this ship virtual const std::string& PublicName(int empire_id) const; - virtual std::string Dump() const; bool IsMonster() const; bool IsArmed() const; Modified: trunk/FreeOrion/universe/System.cpp =================================================================== --- trunk/FreeOrion/universe/System.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/System.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -140,6 +140,9 @@ const std::string& System::TypeName() const { return UserString("SYSTEM"); } +UniverseObjectType System::ObjectType() const +{ return OBJ_SYSTEM; } + std::string System::Dump() const { std::stringstream os; os << UniverseObject::Dump(); Modified: trunk/FreeOrion/universe/System.h =================================================================== --- trunk/FreeOrion/universe/System.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/System.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -59,6 +59,7 @@ /** \name Accessors */ //@{ virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; virtual std::string Dump() const; /** returns the name to display for players for this system. While all Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/Universe.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -1104,12 +1104,16 @@ Logger().debugStream() << "Universe::GetEffectsAndTargets for SPECIES"; type_timer.restart(); for (ObjectMap::const_iterator it = m_objects.const_begin(); it != m_objects.const_end(); ++it) { - const PopCenter* pc = dynamic_cast<const PopCenter*>(it->second); + const PopCenter* pc = 0; + if (it->second->ObjectType() == OBJ_PLANET) // TODO: handle non-planet popcenters if added in future + pc = dynamic_cast<const PopCenter*>(it->second); const Ship* ship = 0; - if (!pc) { + if (!pc && it->second->ObjectType() == OBJ_SHIP) { ship = dynamic_cast<const Ship*>(it->second); if (!ship) continue; } + if (!pc && !ship) + continue; const std::string& species_name = (pc ? pc->SpeciesName() : ship->SpeciesName()); //Logger().debugStream() << "... ... PopCenter species: " << species_name; if (species_name.empty()) @@ -1206,7 +1210,7 @@ // 5) EffectsGroups from Ship Hull and Ship Parts if (GetOptionsDB().Get<bool>("verbose-logging")) - Logger().debugStream() << "Universe::GetEffectsAndTargets for SHIPS"; + Logger().debugStream() << "Universe::GetEffectsAndTargets for SHIPS hulls and parts"; type_timer.restart(); std::vector<Ship*> ships = m_objects.FindObjects<Ship>(); for (std::vector<Ship*>::const_iterator ship_it = ships.begin(); ship_it != ships.end(); ++ship_it) { Modified: trunk/FreeOrion/universe/UniverseObject.cpp =================================================================== --- trunk/FreeOrion/universe/UniverseObject.cpp 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/UniverseObject.cpp 2012-11-24 02:45:42 UTC (rev 5456) @@ -174,6 +174,9 @@ const std::string& UniverseObject::TypeName() const { return UserString("UNIVERSEOBJECT"); } +UniverseObjectType UniverseObject::ObjectType() const +{ return INVALID_UNIVERSE_OBJECT_TYPE; } + std::string UniverseObject::Dump() const { const System* system = GetSystem(this->SystemID()); Modified: trunk/FreeOrion/universe/UniverseObject.h =================================================================== --- trunk/FreeOrion/universe/UniverseObject.h 2012-11-24 00:04:11 UTC (rev 5455) +++ trunk/FreeOrion/universe/UniverseObject.h 2012-11-24 02:45:42 UTC (rev 5456) @@ -80,6 +80,7 @@ virtual bool HasTag(const std::string& name) const; ///< returns true iff this object has the tag with the indicated \a name virtual const std::string& TypeName() const; ///< returns user-readable string indicating the type of UniverseObject this is + virtual UniverseObjectType ObjectType() const; virtual std::string Dump() const; ///< outputs textual description of object to logger virtual std::vector<int> FindObjectIDs() const; ///< returns ids of objects contained within this object |