[Orxonox-commit 4610] r9281 - in code/branches/presentation2012merge: data/gui/scripts src/orxonox
landauf at orxonox.net
landauf at orxonox.net
Sat Jun 9 15:52:33 CEST 2012
Author: landauf
Date: 2012-06-09 15:51:51 +0200 (Sat, 09 Jun 2012)
New Revision: 9281
Removed:
code/branches/presentation2012merge/src/orxonox/ShipManager.cc
code/branches/presentation2012merge/src/orxonox/ShipManager.h
Modified:
code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua
code/branches/presentation2012merge/data/gui/scripts/SingleplayerMenu.lua
code/branches/presentation2012merge/src/orxonox/LevelInfo.cc
code/branches/presentation2012merge/src/orxonox/LevelInfo.h
Log:
small cleanup in ship selection:
- renamed some functions
- moved implementation of changeStartingShip() from header to source file
- removed ShipManager which doesn't seem to be used nor compiled (and it's just a copy of LevelManager anyway)
Modified: code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua
===================================================================
--- code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/data/gui/scripts/ShipSelectionMenu.lua 2012-06-09 13:51:51 UTC (rev 9281)
@@ -18,7 +18,7 @@
function P.createShipList() --generates list with tagged shipmodels
P.shipList = {}
for line in io.lines("../levels/templates/.shipmodels") do --checks if shipmodel is included in level file
- if selectedlevel:hasShip(string.lower(line)) then
+ if selectedlevel:hasStartingShip(string.lower(line)) then
P.shipList[#P.shipList+1] = string.lower(line)
end
end
@@ -31,7 +31,7 @@
local tabIndexes = {}
for k,v in pairs(P.shipList) do
--TODO: only add ship if is in the right filter tab
- --if tag == nil or v:hasShip(tag) then
+ --if tag == nil or v:hasStartingShip(tag) then
local item = CEGUI.createListboxTextItem(v)
item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
listbox:addItem(item)
@@ -106,7 +106,7 @@
function P.ShipSelectionStartButton_clicked(e)
if (selectedlevel ~= nil and P.ShipSelectionGetSelectedModel() ~= nil) then
- selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
+ selectedlevel:selectStartingShip(P.ShipSelectionGetSelectedModel())
orxonox.execute("startGame " .. "_temp.oxw")
hideAllMenuSheets()
else
Modified: code/branches/presentation2012merge/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/presentation2012merge/data/gui/scripts/SingleplayerMenu.lua 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/data/gui/scripts/SingleplayerMenu.lua 2012-06-09 13:51:51 UTC (rev 9281)
@@ -47,7 +47,6 @@
while index < size do
level = orxonox.LevelManager:getInstance():getAvailableLevelListItem(index)
if (level ~= nil and level:getXMLFilename() ~= "_temp.oxw") then
- --os.execute("echo " .. level:getXMLFilename() .." >> ~/outputorx")
local levelXMLFilename = level:getXMLFilename()
-- create an imageset for each screenshot
local imageName = level:getScreenshot()
Modified: code/branches/presentation2012merge/src/orxonox/LevelInfo.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/LevelInfo.cc 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/src/orxonox/LevelInfo.cc 2012-06-09 13:51:51 UTC (rev 9281)
@@ -41,7 +41,7 @@
{
// LevelInfoItem
-
+
//! The list of allowed tags.
/*static*/ std::set<std::string> LevelInfoItem::possibleTags_s = std::set<std::string>();
@@ -106,7 +106,7 @@
{
SubString substr = SubString(tags, ",", " "); // Split the string into tags.
const std::vector<std::string>& strings = substr.getAllStrings();
- for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
+ for (std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
this->addTag(*it, false);
this->tagsUpdated();
@@ -117,14 +117,14 @@
@param tags
A comma-seperated string of all the allowed ship models for the shipselection.
*/
- void LevelInfoItem::setShips(const std::string& ships)
+ void LevelInfoItem::setStartingShips(const std::string& ships)
{
SubString substr = SubString(ships, ",", " "); // Split the string into tags.
const std::vector<std::string>& strings = substr.getAllStrings();
for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
- this->addShip(*it, false);
+ this->addStartingShip(*it, false);
- this->shipsUpdated();
+ this->startingshipsUpdated();
}
/**
@@ -160,12 +160,12 @@
@return
Returns true if the ship was successfully added, if the ship was already present it returns false.
*/
- bool LevelInfoItem::addShip(const std::string& ship, bool update)
+ bool LevelInfoItem::addStartingShip(const std::string& ship, bool update)
{
- bool success = this->ships_.insert(ship).second;
+ bool success = this->startingShips_.insert(ship).second;
if(update && success)
- this->shipsUpdated();
-
+ this->startingshipsUpdated();
+
return success;
}
@@ -194,14 +194,14 @@
@brief
Updates the comma-seperated string of all ships, if the set of tags has changed.
*/
- void LevelInfoItem::shipsUpdated(void)
+ void LevelInfoItem::startingshipsUpdated(void)
{
std::stringstream stream;
std::set<std::string>::iterator temp;
- for(std::set<std::string>::iterator it = this->ships_.begin(); it != this->ships_.end(); )
+ for(std::set<std::string>::iterator it = this->startingShips_.begin(); it != this->startingShips_.end(); )
{
temp = it;
- if(++it == this->ships_.end()) // If this is the last ship we don't add a comma.
+ if(++it == this->startingShips_.end()) // If this is the last ship we don't add a comma.
stream << *temp;
else
stream << *temp << ", ";
@@ -209,6 +209,36 @@
this->startingShipsString_ = std::string(stream.str());
}
+
+ void LevelInfoItem::changeStartingShip(const std::string& model)
+ {
+ static std::string shipSelectionTag = "shipselection";
+ //HACK: Read Level XML File, find "shipselection", replace with ship model
+ std::string levelPath = "../levels/";
+ levelPath.append(this->getXMLFilename());
+ std::string tempPath = "../levels/";
+ tempPath.append("_temp.oxw");
+ orxout(user_status) << levelPath << endl;
+ orxout(user_status) << tempPath << endl;
+ std::ifstream myLevel (levelPath.c_str());
+ std::ofstream tempLevel (tempPath.c_str());
+ while(!myLevel.eof())
+ {
+ std::string buff;
+ std::getline(myLevel, buff);
+ std::string pawndesignString = "pawndesign=";
+ size_t found = buff.find(pawndesignString.append(shipSelectionTag));
+ if (found!= std::string::npos)
+ buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
+ tempLevel.write(buff.c_str(), buff.length());
+ tempLevel << std::endl;
+ }
+ myLevel.close();
+ tempLevel.close();
+ orxout(user_status) << "done" << endl;
+ }
+
+
// LevelInfo
CreateFactory(LevelInfo);
@@ -246,7 +276,7 @@
XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
XMLPortParam(LevelInfo, "screenshot", setScreenshot, getScreenshot, xmlelement, mode);
XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
- XMLPortParam(LevelInfo, "startingships", setShips, getShips, xmlelement, mode);
+ XMLPortParam(LevelInfo, "startingships", setStartingShips, getStartingShips, xmlelement, mode);
}
/**
@@ -262,7 +292,7 @@
info->setDescription(this->getDescription());
info->setScreenshot(this->getScreenshot());
info->setTags(this->getTags());
- info->setShips(this->getShips());
+ info->setStartingShips(this->getStartingShips());
return info;
}
Modified: code/branches/presentation2012merge/src/orxonox/LevelInfo.h
===================================================================
--- code/branches/presentation2012merge/src/orxonox/LevelInfo.h 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/src/orxonox/LevelInfo.h 2012-06-09 13:51:51 UTC (rev 9281)
@@ -117,27 +117,26 @@
*/
inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
- void setShips(const std::string& ships); //!< Set the starting ship models of the level
- bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
+ void setStartingShips(const std::string& ships); //!< Set the starting ship models of the level
+ bool addStartingShip(const std::string& ship, bool update = true); //!< Add a model to shipselection
/**
@brief Get the set of starting ship models the Level allows
@return Returns a comma-seperated string of all the allowed ship models for the shipselection.
*/
- inline const std::string& getShips(void) const
+ inline const std::string& getStartingShips(void) const
{ return this->startingShipsString_; }
/**
@brief Get whether the Level allows a specific starting ship model
@param ship The ship model for which is checked.
@return Returns true if the Level allows the input ship model
*/
- inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.end(); } // tolua_export
+ inline bool hasStartingShip(const std::string& ship) const { return this->startingShips_.find(ship) != this->startingShips_.end(); } // tolua_export
+ inline void selectStartingShip(const std::string& ship) { this->changeStartingShip(ship); } // tolua_export
/**
@brief Get the XML-filename of the Level.
@return Returns the XML-filename (including *.oxw extension) of the Level.
*/
-
inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
- inline void selectShip (const std::string& ship) { this->changeShip(ship); } // tolua_export
protected:
@@ -151,35 +150,9 @@
std::string xmlfilename_; //!< The XML-filename of the Level.
private:
-
- inline void changeShip (const std::string& model) {
- static std::string shipSelectionTag = "shipselection";
- //HACK: Read Level XML File, find "shipselection", replace with ship model
- std::string levelPath = "../levels/";
- levelPath.append(this->getXMLFilename());
- std::string tempPath = "../levels/";
- tempPath.append("_temp.oxw");
- orxout(user_status) << levelPath << endl;
- orxout(user_status) << tempPath << endl;
- std::ifstream myLevel (levelPath.c_str());
- std::ofstream tempLevel (tempPath.c_str());
- while(!myLevel.eof())
- {
- std::string buff;
- std::getline(myLevel, buff);
- std::string pawndesignString = "pawndesign=";
- size_t found = buff.find(pawndesignString.append(shipSelectionTag));
- if (found!= std::string::npos)
- buff = buff.substr(0, found + 11) + model + buff.substr(found+11+shipSelectionTag.length(), std::string::npos);
- tempLevel.write(buff.c_str(), buff.length());
- tempLevel << std::endl;
- }
- myLevel.close();
- tempLevel.close();
- orxout(user_status) << "done" << endl;
- }
+ void changeStartingShip (const std::string& model);
+ void startingshipsUpdated(void); //!< Updates the comma-seperated string of all possible starting ships.
void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
- void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
static void initializeTags(void); //!< Initialize the set of allowed tags.
/**
@brief Check whether an input tag is allowed.
@@ -197,7 +170,7 @@
std::string screenshot_; //!< The screenshot of the Level.
std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
- std::set<std::string> ships_; //!< The set of starting ship models the Level allows.
+ std::set<std::string> startingShips_; //!< The set of starting ship models the Level allows.
std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection.
}; // tolua_export
@@ -275,14 +248,15 @@
@brief Set the starting ship models of the level
@param A comma-seperated string of all the allowed ship models for the shipselection.
*/
- inline void setShips(const std::string& ships)
- { this->LevelInfoItem::setShips(ships); }
+ inline void setStartingShips(const std::string& ships)
+ { this->LevelInfoItem::setStartingShips(ships); }
/**
@brief Get the starting ship models of the level
@return Returns a comma-seperated string of all the allowed ship models for the shipselection.
*/
- inline const std::string& getShips(void) const
- { return this->LevelInfoItem::getShips(); }
+ inline const std::string& getStartingShips(void) const
+ { return this->LevelInfoItem::getStartingShips(); }
+
LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
};
Deleted: code/branches/presentation2012merge/src/orxonox/ShipManager.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/ShipManager.cc 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/src/orxonox/ShipManager.cc 2012-06-09 13:51:51 UTC (rev 9281)
@@ -1,201 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Matthias Hutter
- *
- */
-
-/**
- @file ShipManager.cc
- @brief Work-in Progress: Implementation of the ShipManager singleton.
- Should make SpaceShip info available to lua handlers.
-*/
-
-#include "LevelManager.h"
-
-#include <map>
-
-#include "util/ScopedSingletonManager.h"
-#include "core/ClassTreeMask.h"
-#include "core/CommandLineParser.h"
-#include "core/ConfigValueIncludes.h"
-#include "core/CoreIncludes.h"
-#include "core/Loader.h"
-#include "core/Resource.h"
-#include "core/XMLFile.h"
-#include "Level.h"
-#include "PlayerManager.h"
-
-namespace orxonox
-{
- SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
-
- ManageScopedSingleton(LevelManager, ScopeID::Root, false);
-
- /**
- @brief
- Constructor.
- */
- ShipManager::ShipManager()
- {
- RegisterRootObject(LevelManager);
- this->compileAvailableLevelList();
- this->nextIndex_ = 0;
- this->nextLevel_ = this->availableLevels_.begin();
- }
-
- ShipManager::~ShipManager()
- {
- // Delete all the Ship objects because the LevelManager created them
- std::set<SpaceShip*, LevelInfoCompare>::iterator it = availableLevels_.begin();
- for (; it != availableLevels_.end(); ++it)
- delete *it;
- }
-
-
- /**
- @brief
- Get the number of available Ships.
- @return
- Returns the number of available Ships.
- */
- unsigned int LevelManager::getNumberOfLevels(){ return this->availableLevels_.size(); }
-
- /**
- @brief
- Get the SpaceShip at the given index in the list of available Ships.
- The SpaceShips are sorted in alphabetical order accoridng to the name of the Ship.
- This method is most efficiently called with consecutive indices (or at least ascending indices).
- @param index
- The index of the item that should be returned.
- @return
- Returns a pointer to the SpaceShip at the given index.
- */
- SpaceShip* ShipManager::getAvailableShipListItem(unsigned int index)
- {
- if(index >= this->availableShips_.size())
- return NULL;
-
- // If this index directly follows the last we can optimize a lot.
- if(index == this->nextIndex_)
- {
- this->nextIndex_++;
- std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextShip_;
- this->nextLevel_++;
- return *it;
- }
- else
- {
- // If this index is bigger than the last, we can optimize a little.
- if(index < this->nextIndex_)
- {
- this->nextIndex_ = 0;
- this->nextShip_ = this->availableShips_.begin();
- }
-
- while(this->nextIndex_ != index)
- {
- this->nextIndex_++;
- this->nextShip_++;
- }
- this->nextIndex_++;
- std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextLevel_;
- this->nextLevel_++;
- return *it;
- }
- }
-
- /**
- @brief
- Compile the list of available Levels.
- Iterates over all *.oxw files, loads the LevelInfo objects in them and from that it creates the LevelInfoItems which are inserted in a list.
- */
- void ShipManager::compileAvailableShipList()
- {
- /*
- // We only want to load as little as possible
- ClassTreeMask mask;
- mask.exclude(Class(BaseObject));
- mask.include(Class(SpaceShip));
- SpaceShip* info = NULL;
- XMLFile file = XMLFile(ship);
- Loader::load(&file, mask, false, true);
- for(ObjectList<SpaceShip>::iterator item = ObjectList<SpaceShip>::begin(); item != ObjectList<SpaceShip>::end(); ++item)
- if(item->getXMLFilename() == *it)
- info = item->copy();
- Loader::unload(&file);
- */
-
- // Get all files matching the level criteria
- Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
-
- // We only want to load as little as possible
- ClassTreeMask mask;
- mask.exclude(Class(BaseObject));
- mask.include(Class(LevelInfo));
-
- // Iterate over all the found *.oxw files
- orxout(internal_info) << "Loading LevelInfos..." << endl;
- std::set<std::string> names;
- for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
- {
- // TODO: Replace with tag?
- if (it->find("old/") != 0 )
- {
- LevelInfoItem* info = NULL;
-
- // Load the LevelInfo object from the level file.
- XMLFile file = XMLFile(*it);
- Loader::load(&file, mask, false, true);
-
- // Find the LevelInfo object we've just loaded (if there was one)
- for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
- if(item->getXMLFilename() == *it)
- info = item->copy();
-
- // We don't need the loaded stuff anymore
- Loader::unload(&file);
-
- if(info == NULL)
- {
- // Create a default LevelInfoItem object that merely contains the name
- std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
- info = new LevelInfoItem(filenameWOExtension, *it);
- }
-
- // Warn about levels with the same name.
- if(!names.insert(info->getName()).second)
- orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with name '" << info->getName() << "' found!" << endl;
-
- // Warn about multiple items so that it gets fixed quickly
- if(availableLevels_.find(info) != availableLevels_.end())
- {
- orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with same name '" << info->getName() << "' and filename found! Exluding..." << endl;
- // Delete LevelInfoItem to avoid a dangling pointer
- delete info;
- }
- else
- this->availableLevels_.insert(info);
- }
- }
- }
-}
Deleted: code/branches/presentation2012merge/src/orxonox/ShipManager.h
===================================================================
--- code/branches/presentation2012merge/src/orxonox/ShipManager.h 2012-06-05 20:29:17 UTC (rev 9280)
+++ code/branches/presentation2012merge/src/orxonox/ShipManager.h 2012-06-09 13:51:51 UTC (rev 9281)
@@ -1,93 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Matthias Hutter
- */
-
-/**
- @file ShipManager.h
- @brief Definition of the ShipManager singleton.
- @ingroup Orxonox
-*/
-
-#ifndef _ShipManager_H__
-#define _ShipManager_H__
-
-#include "OrxonoxPrereqs.h"
-
-#include <cassert>
-#include <list>
-#include <map>
-#include <string>
-#include "worldentities/pawns/SpaceShip.h"
-
-#include "util/Singleton.h"
-#include "core/OrxonoxClass.h"
-
-// tolua_begin
-namespace orxonox
-{
-
- /**
- @author
- Matthias Hutter
-
- @ingroup Orxonox
- */
- class _OrxonoxExport ShipManager
- // tolua_end
- : public Singleton<ShipManager>, public OrxonoxClass
- { // tolua_export
- friend class Singleton<LevelManager>;
- public:
- ShipManager();
- virtual ~ShipManager();
-
- void setConfigValues(); //!< Set the config values for this object.
- // tolua_begin
- /**
- @brief Get the instance of the LevelManager.
- @return Returns the instance of the LevelManager.
- */
- static ShipManager& getInstance()
- { return Singleton<ShipManager>::getInstance(); }
- // tolua_end
-
- private:
- ShipManager(const ShipManager&);
-
-
- void compileAvailableLevelList(void); //!< Compile the list of available Levels.
- void updateAvailableLevelList(void); //!< Update the list of available Levels.
-
- std::list<Level*> levels_; //!< A list of all the Levels whose activity has been requested, in the order in which they will become active.
- std::set<LevelInfoItem*, LevelInfoCompare> availableLevels_; //!< The set of available Levels sorted alphabetically according to the name of the Level.
-
- // Helpers to allow fast access to the availableLevels list.
- unsigned int nextIndex_; //! The next expected index to be accessed.
- std::set<LevelInfoItem*, LevelInfoCompare>::iterator nextLevel_; //! The next expected Level to be accessed.
-
- static LevelManager* singletonPtr_s;
- }; // tolua_export
-} // tolua_export
-
-#endif /* _LevelManager_H__ */
More information about the Orxonox-commit
mailing list