Changeset 5654
- Timestamp:
- Aug 17, 2009, 4:37:10 PM (15 years ago)
- Files:
-
- 2 added
- 2 deleted
- 42 edited
- 2 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource2/data/levels/empty_level.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/stats.oxo")3 include(" overlay/hudtemplates3.oxo")2 include("stats.oxo") 3 include("hudtemplates3.oxo") 4 4 ?> 5 5 6 6 <?lua 7 include(" levels/templates/spaceship_assff.oxt")8 include(" levels/templates/spaceship_pirate.oxt")7 include("templates/spaceship_assff.oxt") 8 include("templates/spaceship_pirate.oxt") 9 9 ?> 10 10 -
code/branches/resource2/data/levels/gametype_asteroids.oxw
r5556 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 -
code/branches/resource2/data/levels/gametype_underattack.oxw
r5572 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" overlay/underattackhud.oxo")5 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("underattackhud.oxo") 5 include("templates/spaceship_assff.oxt") 6 6 ?> 7 7 -
code/branches/resource2/data/levels/old/CuboidSpaceStation.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")2 include("hudtemplates3.oxo") 3 3 ?> 4 4 5 5 <?lua 6 include(" levels/templates/spaceship_assff.oxt")6 include("templates/spaceship_assff.oxt") 7 7 ?> 8 8 … … 20 20 <!--------------------------------------------------------------------------------------------------------------------------------------------------------------------------> 21 21 <?lua 22 dofile(" ../../media/levels/includes/CuboidSpaceStation.lua")22 dofile("includes/CuboidSpaceStation.lua") 23 23 ?> 24 24 -
code/branches/resource2/data/levels/old/physicstest2.oxw
r5528 r5654 1 1 <?lua 2 include(" levels/old/spaceshiptemplates_physics.oxw")2 include("spaceshiptemplates_physics.oxw") 3 3 ?> 4 4 <?lua 5 include(" overlay/hudtemplates3.oxo")5 include("hudtemplates3.oxo") 6 6 ?> 7 7 -
code/branches/resource2/data/levels/old/planettest.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")2 include("hudtemplates3.oxo") 3 3 ?> 4 4 5 5 <?lua 6 include(" levels/templates/spaceship_assff.oxt")6 include("templates/spaceship_assff.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/levels/old/presentation_physics.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 math.randomseed(344) 6 6 ?> -
code/branches/resource2/data/levels/old/princessaeryn.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 7 7 <?lua 8 dofile(" ../../media/levels/includes/CuboidSpaceStation.lua")8 dofile("includes/CuboidSpaceStation.lua") 9 9 ?> 10 10 -
code/branches/resource2/data/levels/old/questsystem.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 -
code/branches/resource2/data/levels/old/sample4.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")2 include("hudtemplates3.oxo") 3 3 ?> 4 4 5 5 <?lua 6 include(" levels/templates/spaceship_assff.oxt")6 include("templates/spaceship_assff.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/levels/pickuptest.oxw
r5529 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 -
code/branches/resource2/data/levels/presentation.oxw
r5537 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 -
code/branches/resource2/data/levels/presentation09.oxw
r5565 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")5 include(" levels/templates/spaceship_H2.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 include("templates/spaceship_H2.oxt") 6 6 ?> 7 7 -
code/branches/resource2/data/levels/presentation09b.oxw
r5575 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")5 include(" levels/templates/spaceship_H2.oxt")6 include(" levels/templates/spaceship_pirate.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 include("templates/spaceship_H2.oxt") 6 include("templates/spaceship_pirate.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/levels/presentation_dm.oxw
r5550 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")5 include(" levels/templates/spaceship_H2.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 include("templates/spaceship_H2.oxt") 6 6 ?> 7 7 -
code/branches/resource2/data/levels/presentation_pong.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" overlay/ponghud.oxo")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("ponghud.oxo") 5 5 ?> 6 6 … … 91 91 92 92 <?lua 93 dofile(" ../../media/levels/includes/CuboidSpaceStation.lua")93 dofile("includes/CuboidSpaceStation.lua") 94 94 ?> 95 95 -
code/branches/resource2/data/levels/teambasematchlevel.oxw
r5572 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" overlay/teambasematchhud.oxo")5 include(" levels/templates/spaceship_assff.oxt")6 include(" levels/templates/spaceship_pirate.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("teambasematchhud.oxo") 5 include("templates/spaceship_assff.oxt") 6 include("templates/spaceship_pirate.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/levels/teamdeathmatch.oxw
r5534 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")5 include(" levels/templates/spaceship_H2.oxt")6 include(" levels/templates/spaceship_pirate.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 include("templates/spaceship_H2.oxt") 6 include("templates/spaceship_pirate.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/levels/templates/spaceship_H2.oxt
r5573 r5654 23 23 24 24 <?lua 25 include(" levels/includes/weaponsettings_H2.oxi")25 include("includes/weaponsettings_H2.oxi") 26 26 ?> 27 27 -
code/branches/resource2/data/levels/templates/spaceship_assff.oxt
r5550 r5654 35 35 </collisionShapes> 36 36 <?lua 37 include(" levels/includes/weaponsettings3.oxi")37 include("includes/weaponsettings3.oxi") 38 38 ?> 39 39 </SpaceShip> -
code/branches/resource2/data/levels/templates/spaceship_pirate.oxt
r5528 r5654 38 38 39 39 <?lua 40 include(" levels/includes/weaponsettings_pirate.oxi")40 include("includes/weaponsettings_pirate.oxi") 41 41 ?> 42 42 </SpaceShip> -
code/branches/resource2/data/levels/tutorial.oxw
r5528 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 5 ?> 6 6 -
code/branches/resource2/data/levels/waypoints.oxw
r5560 r5654 1 1 <?lua 2 include(" overlay/hudtemplates3.oxo")3 include(" overlay/stats.oxo")4 include(" levels/templates/spaceship_assff.oxt")5 include(" levels/templates/spaceship_H2.oxt")6 include(" levels/templates/spaceship_pirate.oxt")2 include("hudtemplates3.oxo") 3 include("stats.oxo") 4 include("templates/spaceship_assff.oxt") 5 include("templates/spaceship_H2.oxt") 6 include("templates/spaceship_pirate.oxt") 7 7 ?> 8 8 -
code/branches/resource2/data/resources.oxr
r5644 r5654 1 <ResourceGroup name = "General" > 2 <ResourceLocation path = overlay /> 3 <ResourceLocation path = particle /> 4 <ResourceLocation path = defaultConfig /> 5 <ResourceLocation path = levels /> 6 <ResourceLocation path = tcl /> 7 <ResourceLocation 8 path = test.zip 9 archive = Zip 10 recursive = true 11 /> 12 </ResourceGroup> 13 14 <ResourceGroup name = "GUI" > 15 <ResourceLocation path = gui/configs /> 16 <ResourceLocation path = gui/layouts /> 17 <ResourceLocation path = gui/schemas /> 18 <ResourceLocation path = gui/scripts /> 19 </ResourceGroup> 1 <ResourceCollection resourceGroup = "General" > 2 <ResourceLocation path = "levels" /> 3 <ResourceLocation path = "lua" /> 4 <ResourceLocation path = "overlay" /> 5 <ResourceLocation path = "tcl" /> 6 </ResourceCollection> -
code/branches/resource2/data/resources_graphics.oxr
r5646 r5654 1 <ResourceGroup name = "General" > 2 <ResourceLocation path = overlay /> 3 <ResourceLocation path = particle /> 4 <ResourceLocation path = defaultConfig /> 5 <ResourceLocation path = levels /> 6 <ResourceLocation path = tcl /> 7 <ResourceLocation 8 path = test.zip 9 archive = Zip 10 recursive = true 11 /> 12 </ResourceGroup> 1 <ResourceCollection resourceGroup = "General" > 2 <ResourceLocation path = "particle" /> 3 </ResourceCollection> 13 4 14 <Resource Group name= "GUI" >15 <ResourceLocation path = gui/configs/>16 <ResourceLocation path = gui/layouts/>17 <ResourceLocation path = gui/schemas/>18 <ResourceLocation path = gui/scripts/>19 </Resource Group>5 <ResourceCollection resourceGroup = "GUI" > 6 <ResourceLocation path = "gui/configs" /> 7 <ResourceLocation path = "gui/layouts" /> 8 <ResourceLocation path = "gui/schemes" /> 9 <ResourceLocation path = "gui/scripts" /> 10 </ResourceCollection> -
code/branches/resource2/src/core/CMakeLists.txt
r5653 r5654 30 30 GUIManager.cc 31 31 Language.cc 32 Lua Bind.cc32 LuaState.cc 33 33 ObjectListBase.cc 34 34 OrxonoxClass.cc … … 76 76 TOLUA_FILES 77 77 CommandExecutor.h 78 LuaBind.h 78 Loader.h 79 LuaState.h 79 80 DEFINE_SYMBOL 80 81 "CORE_SHARED_BUILD" -
code/branches/resource2/src/core/Core.cc
r5645 r5654 74 74 #include "Identifier.h" 75 75 #include "Language.h" 76 #include "Lua Bind.h"76 #include "LuaState.h" 77 77 #include "Shell.h" 78 78 #include "TclBind.h" 79 79 #include "TclThreadManager.h" 80 #include "ToluaBindCore.h" 80 81 #include "input/InputManager.h" 81 82 … … 266 267 setThreadAffinity(static_cast<unsigned int>(limitToCPU)); 267 268 #endif 269 // Add tolua interface 270 LuaState::addToluaInterface(&tolua_Core_open, "Core"); 268 271 269 272 // Manage ini files and set the default settings file (usually orxonox.ini) … … 275 278 this->languageInstance_.reset(new Language()); 276 279 280 // creates the class hierarchy for all classes with factories 281 Factory::createClassHierarchy(); 282 277 283 // Do this soon after the ConfigFileManager has been created to open up the 278 284 // possibility to configure everything below here 279 285 this->configuration_->initialise(); 280 286 281 // Create the lua interface282 this-> luaBind_.reset(new LuaBind());287 // Load OGRE excluding the renderer and the render window 288 this->graphicsManager_.reset(new GraphicsManager(false)); 283 289 284 290 // initialise Tcl … … 288 294 // create a shell 289 295 this->shell_.reset(new Shell()); 290 291 // creates the class hierarchy for all classes with factories292 Factory::createClassHierarchy();293 294 // Load OGRE excluding the renderer and the render window295 this->graphicsManager_.reset(new GraphicsManager(false));296 296 } 297 297 298 298 /** 299 299 @brief 300 All destruction code is handled by scoped_ptrs and S impleScopeGuards.300 All destruction code is handled by scoped_ptrs and ScopeGuards. 301 301 */ 302 302 Core::~Core() … … 561 561 COUT(1) << "Running from the build tree." << std::endl; 562 562 Core::bDevRun_ = true; 563 configuration_->dataPath_ = specialConfig::dataDevDirectory;563 configuration_->dataPath_ = specialConfig::dataDevDirectory; 564 564 configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory; 565 565 configuration_->configPath_ = specialConfig::configDevDirectory; … … 579 579 580 580 // Using paths relative to the install prefix, complete them 581 configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;581 configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath; 582 582 configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath; 583 583 configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath; -
code/branches/resource2/src/core/Core.h
r5651 r5654 129 129 scoped_ptr<Language> languageInstance_; 130 130 scoped_ptr<CoreConfiguration> configuration_; 131 scoped_ptr<LuaBind> luaBind_;132 131 scoped_ptr<TclBind> tclBind_; 133 132 scoped_ptr<TclThreadManager> tclThreadManager_; -
code/branches/resource2/src/core/CorePrereqs.h
r5653 r5654 133 133 class LanguageEntry; 134 134 class Loader; 135 class Lua Bind;135 class LuaState; 136 136 class MetaObjectList; 137 137 class MetaObjectListElement; -
code/branches/resource2/src/core/GUIManager.cc
r5645 r5654 59 59 #include "Core.h" 60 60 #include "Clock.h" 61 #include "Lua Bind.h"61 #include "LuaState.h" 62 62 63 63 namespace orxonox … … 132 132 133 133 // do this after 'new CEGUI::Sytem' because that creates the lua state in the first place 134 Lua Bind::getInstance().openToluaInterfaces(this->luaState_);134 LuaState::openToluaInterfaces(this->luaState_); 135 135 136 136 // initialise the basic lua code … … 157 157 { 158 158 // destroy our own tolua interfaces 159 Lua Bind::getInstance().closeToluaInterfaces(this->luaState_);159 LuaState::closeToluaInterfaces(this->luaState_); 160 160 } 161 161 -
code/branches/resource2/src/core/GraphicsManager.cc
r5641 r5654 45 45 #include <OgreRenderWindow.h> 46 46 #include <OgreRenderSystem.h> 47 #include <OgreResourceGroupManager.h> 47 48 #include <OgreViewport.h> 48 49 #include <OgreWindowEventUtilities.h> … … 59 60 #include "Game.h" 60 61 #include "GameMode.h" 62 #include "Loader.h" 61 63 #include "WindowEventListener.h" 64 #include "XMLFile.h" 62 65 63 66 namespace orxonox … … 96 99 this->loadOgrePlugins(); 97 100 101 // At first, add the root paths of the data directories as resource locations 102 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getDataPathString(), "FileSystem", "dataRoot", false); 103 // Load resources 104 resources_.reset(new XMLFile("resources.oxr", "dataRoot")); 105 Loader::open(resources_.get()); 106 107 // Only for development runs 108 if (Core::isDevelopmentRun()) 109 { 110 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(Core::getExternalDataPathString(), "FileSystem", "externalDataRoot", false); 111 extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot")); 112 Loader::open(extResources_.get()); 113 } 114 98 115 if (bLoadRenderer) 99 116 { 100 117 // Reads the ogre config and creates the render window 101 this-> loadRenderer();118 this->upgradeToGraphics(); 102 119 } 103 120 } … … 109 126 GraphicsManager::~GraphicsManager() 110 127 { 128 // TODO: Destroy the console command 111 129 } 112 130 … … 137 155 void GraphicsManager::upgradeToGraphics() 138 156 { 139 if (renderWindow_ == NULL) 140 { 141 this->loadRenderer(); 142 } 157 if (renderWindow_ != NULL) 158 return; 159 160 this->loadRenderer(); 161 162 // RESOURCE MANAGEMENT 163 164 // Load graphical resources 165 resourcesGraphics_.reset(new XMLFile("resources_graphics.oxr", "dataRoot")); 166 Loader::open(resourcesGraphics_.get()); 167 168 // Consider external data folder for dev runs 169 if (Core::isDevelopmentRun()) 170 { 171 extResourcesGraphics_.reset(new XMLFile("resources_graphics.oxr", "externalDataRoot")); 172 Loader::open(extResourcesGraphics_.get()); 173 } 174 175 // Initialise all resources 176 // Note: You can only do this once! Ogre will check whether a resource group has 177 // already been initialised. If you need to load resources later, you will have to 178 // choose another resource group. 179 Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); 143 180 } 144 181 -
code/branches/resource2/src/core/GraphicsManager.h
r5651 r5654 43 43 #include <OgreLog.h> 44 44 #include <boost/scoped_ptr.hpp> 45 #include <boost/shared_ptr.hpp> 45 46 46 47 #include "util/Singleton.h" … … 87 88 void printScreen(); 88 89 89 private:90 90 scoped_ptr<OgreWindowEventListener> ogreWindowEventListener_; //!< Pimpl to hide OgreWindowUtilities.h 91 91 scoped_ptr<Ogre::LogManager> ogreLogger_; … … 93 93 Ogre::RenderWindow* renderWindow_; //!< the one and only render window 94 94 Ogre::Viewport* viewport_; //!< default full size viewport 95 96 // XML files for the resources 97 shared_ptr<XMLFile> resources_; //!< XML with resource locations 98 shared_ptr<XMLFile> extResources_; //!< XML with resource locations in the external path (only for dev runs) 99 shared_ptr<XMLFile> resourcesGraphics_; //!< XML with resource locations (with renderer) 100 shared_ptr<XMLFile> extResourcesGraphics_; //!< XML with resource locations in the external path (only for dev runs) (with renderer) 95 101 96 102 // config values -
code/branches/resource2/src/core/Loader.cc
r3370 r5654 29 29 #include "Loader.h" 30 30 31 #include <sstream> 31 32 #include <tinyxml/ticpp.h> 33 #include <boost/scoped_ptr.hpp> 32 34 33 35 #include "util/Debug.h" 34 36 #include "util/Exception.h" 37 #include "util/StringUtils.h" 35 38 #include "BaseObject.h" 36 39 #include "Iterator.h" 37 40 #include "ObjectList.h" 38 #include "Lua Bind.h"41 #include "LuaState.h" 39 42 #include "Namespace.h" 43 #include "Resource.h" 40 44 #include "XMLFile.h" 41 45 … … 118 122 Loader::currentMask_s = file->getMask() * mask; 119 123 120 // let Lua work this out:121 LuaBind& lua = LuaBind::getInstance();122 lua .clearLuaOutput();123 lua .loadFile(file->getFilename(), true);124 lua.run();124 // Use the LuaState to replace the XML tags (calls our function) 125 scoped_ptr<LuaState> luaState(new LuaState()); 126 luaState->setIncludeParser(&Loader::replaceLuaTags); 127 luaState->includeFile(file->getFilename(), file->getResourceGroup(), false); 128 //luaState->doString(luaInput); 125 129 126 130 try … … 129 133 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 130 134 131 //ticpp::Document xmlfile(file->getFilename()); 132 //xmlfile.LoadFile(); 133 //ticpp::Element myelement(*Script::getFileString()); 134 ticpp::Document xmlfile; 135 //xmlfile.ToDocument(); 136 xmlfile.Parse(lua.getLuaOutput(), true); 135 ticpp::Document xmlfile(file->getFilename()); 136 xmlfile.Parse(luaState->getOutput().str(), true); 137 137 138 138 ticpp::Element rootElement; … … 208 208 return Loader::load(file, mask); 209 209 } 210 211 std::string Loader::replaceLuaTags(const std::string& text) 212 { 213 // chreate map with all Lua tags 214 std::map<size_t, bool> luaTags; 215 { 216 size_t pos = 0; 217 while ((pos = text.find("<?lua", pos)) != std::string::npos) 218 luaTags[pos++] = true; 219 } 220 { 221 size_t pos = 0; 222 while ((pos = text.find("?>", pos)) != std::string::npos) 223 luaTags[pos++] = false; 224 } 225 226 // erase all tags from the map that are between two quotes 227 { 228 std::map<size_t, bool>::iterator it = luaTags.begin(); 229 std::map<size_t, bool>::iterator it2 = it; 230 bool bBetweenQuotes = false; 231 size_t pos = 0; 232 while ((pos = getNextQuote(text, pos)) != std::string::npos) 233 { 234 while ((it != luaTags.end()) && (it->first < pos)) 235 { 236 if (bBetweenQuotes) 237 { 238 it2++; 239 if(it->second && !(it2->second) && it2->first < pos) 240 it = ++it2; 241 else 242 luaTags.erase(it++); 243 } 244 else 245 ++it; 246 } 247 bBetweenQuotes = !bBetweenQuotes; 248 pos++; 249 } 250 } 251 252 // check whether on every opening <?lua tag a closing ?> tag follows 253 { 254 bool expectedValue = true; 255 for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it) 256 { 257 if (it->second == expectedValue) 258 expectedValue = !expectedValue; 259 else 260 { 261 expectedValue = false; 262 break; 263 } 264 } 265 if (!expectedValue) 266 { 267 COUT(2) << "Warning: Error in level file" << std::endl; 268 // todo: errorhandling 269 return ""; 270 } 271 } 272 273 // Use a stringstream object to speed up the parsing 274 std::ostringstream output; 275 276 // cut the original string into pieces and put them together with print() instead of lua tags 277 { 278 std::map<size_t, bool>::iterator it = luaTags.begin(); 279 bool bInPrintFunction = true; 280 size_t start = 0; 281 size_t end = 0; 282 283 do 284 { 285 if (it != luaTags.end()) 286 end = (*(it++)).first; 287 else 288 end = std::string::npos; 289 290 unsigned int equalSignCounter = 0; 291 292 if (bInPrintFunction) 293 { 294 // count ['='[ and ]'='] and replace tags with print([[ and ]]) 295 std::string temp = text.substr(start, end - start); 296 { 297 size_t pos = 0; 298 while ((pos = temp.find('[', pos)) != std::string::npos) 299 { 300 unsigned int tempCounter = 1; 301 size_t tempPos = pos++; 302 while(temp[++tempPos] == '=') 303 { 304 tempCounter++; 305 } 306 if(temp[tempPos] != '[') 307 { 308 tempCounter = 0; 309 } 310 else if(tempCounter == 0) 311 { 312 tempCounter = 1; 313 } 314 if (tempCounter > equalSignCounter) 315 equalSignCounter = tempCounter; 316 } 317 } 318 { 319 size_t pos = 0; 320 while ((pos = temp.find(']', pos)) != std::string::npos) 321 { 322 unsigned int tempCounter = 1; 323 size_t tempPos = pos++; 324 while(temp[++tempPos] == '=') 325 { 326 tempCounter++; 327 } 328 if(temp[tempPos] != ']') 329 { 330 tempCounter = 0; 331 } 332 else if(tempCounter == 0) 333 { 334 tempCounter = 1; 335 } 336 if (tempCounter > equalSignCounter) 337 equalSignCounter = tempCounter; 338 } 339 } 340 std::string equalSigns = ""; 341 for(unsigned int i = 0; i < equalSignCounter; i++) 342 { 343 equalSigns += "="; 344 } 345 output << "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])"; 346 start = end + 5; 347 } 348 else 349 { 350 output << text.substr(start, end - start); 351 start = end + 2; 352 } 353 354 bInPrintFunction = !bInPrintFunction; 355 } 356 while (end != std::string::npos); 357 } 358 359 return output.str(); 360 } 210 361 } -
code/branches/resource2/src/core/Loader.h
r3370 r5654 55 55 static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 56 56 57 static std::string replaceLuaTags(const std::string& text); 58 57 59 static ClassTreeMask currentMask_s; 58 60 -
code/branches/resource2/src/core/LuaState.cc
r5645 r5654 22 22 * Author: 23 23 * Benjamin Knecht 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 27 28 */ 28 29 29 #include "LuaBind.h" 30 31 #include <fstream> 32 #include <map> 30 #include "LuaState.h" 31 32 #include <tolua/tolua++.h> 33 33 extern "C" { 34 #include <lua.h> 34 35 #include <lualib.h> 35 36 } 36 #include <tolua/tolua++.h>37 #include <boost/filesystem.hpp>38 37 39 38 #include "util/Debug.h" 40 #include "util/StringUtils.h"41 39 #include "Core.h" 40 #include "Resource.h" 42 41 43 42 namespace orxonox 44 43 { 45 LuaBind* LuaBind::singletonPtr_s = NULL; 46 47 LuaBind::LuaBind() 48 { 49 this->includePath_ = Core::getDataPathString(); 50 51 luaState_ = lua_open(); 52 luaSource_ = ""; 44 LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s; 45 std::vector<LuaState*> LuaState::instances_s; 46 47 LuaState::LuaState() 48 : bIsRunning_(false) 49 , includeParseFunction_(NULL) 50 { 51 // Create new lua state and configure it 52 luaState_ = lua_open(); 53 53 #if LUA_VERSION_NUM == 501 54 luaL_openlibs(luaState_);54 luaL_openlibs(luaState_); 55 55 #else 56 luaopen_base(luaState_);57 luaopen_string(luaState_);58 luaopen_table(luaState_);59 luaopen_math(luaState_);60 luaopen_io(luaState_);61 luaopen_debug(luaState_);56 luaopen_base(luaState_); 57 luaopen_string(luaState_); 58 luaopen_table(luaState_); 59 luaopen_math(luaState_); 60 luaopen_io(luaState_); 61 luaopen_debug(luaState_); 62 62 #endif 63 63 64 // Open all available tolua interfaces 65 this->openToluaInterfaces(luaState_); 66 67 output_ = ""; 68 isRunning_ = false; 69 } 70 71 LuaBind::~LuaBind() 72 { 73 this->closeToluaInterfaces(luaState_); 74 }; 75 76 void LuaBind::luaPrint(const std::string& str) 77 { 78 output_ += str; 79 // COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl; 80 COUT(5) << str; 81 } 82 83 /** 84 @brief Loads the specified file line by line 85 @param filename The filename of the file 86 @param luaTags if true, the loaded file gets stripped off luaTags 87 */ 88 void LuaBind::loadFile(const std::string& filename, bool luaTags) 89 { 90 boost::filesystem::path filepath(filename); 91 92 output_ = ""; 93 std::ifstream file; 94 file.open(filepath.string().c_str(), std::fstream::in); 95 96 if (!file.is_open()) 97 { 98 // some error msg 99 } 100 101 std::string levelString = ""; 102 103 while (file.good() && !file.eof()) 104 { 105 std::string line; 106 std::getline(file, line); 107 levelString += line; 108 levelString += "\n"; 109 } 110 111 file.close(); 112 //std::string output; 113 114 if (luaTags) 115 luaSource_ = replaceLuaTags(levelString); 116 else 117 luaSource_ = levelString; 118 COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl; 119 } 120 121 void LuaBind::loadString(const std::string& code) 122 { 123 luaSource_ = code; 124 output_ = ""; 125 } 126 64 // Open all available tolua interfaces 65 this->openToluaInterfaces(luaState_); 66 67 // Create dummy file info 68 sourceFileInfo_.reset(new ResourceInfo()); 69 sourceFileInfo_->group = "General"; 70 sourceFileInfo_->size = 0; 71 72 // Push this pointer 73 tolua_pushusertype(luaState_, static_cast<void*>(this), "orxonox::LuaState"); 74 lua_setglobal(luaState_, "luaState"); 75 76 // Parse init script 77 // Note: We have to use a hard coded path because the script is required for the resource loading 78 this->doString("dofile(\"" + Core::getDataPathString() + "lua/LuaStateInit.lua\")"); 79 } 80 81 LuaState::~LuaState() 82 { 83 lua_close(luaState_); 84 } 85 86 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 87 { 88 shared_ptr<ResourceInfo> sourceInfo; 89 if (resourceGroup != "NoResourceGroupProvided") 90 sourceInfo = Resource::getInfo(filename, resourceGroup); 91 92 // Continue search if not explicitely forbidden 93 if (bSearchOtherPaths && sourceInfo == NULL) 94 { 95 // Call might be relative to the file currently being processed 96 sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group); 97 if (sourceInfo == NULL) 98 { 99 // Maybe find something in the same group but in the root path 100 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group); 101 } 102 } 103 return sourceInfo; 104 } 105 106 void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 107 { 108 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 109 if (sourceInfo != NULL) 110 this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 111 else 112 COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '" 113 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 114 } 115 116 void LuaState::includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo) 117 { 118 // Parse string with provided include parser (otherwise don't preparse at all) 119 std::string luaInput; 120 if (includeParseFunction_ != NULL) 121 luaInput = (*includeParseFunction_)(code); 122 else 123 luaInput = code; 124 125 this->doString(luaInput, sourceFileInfo); 126 } 127 128 void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 129 { 130 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 131 if (sourceInfo != NULL) 132 this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 133 else 134 COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '" 135 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 136 } 137 138 void LuaState::doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo) 139 { 140 // Save the oold source file info 141 shared_ptr<ResourceInfo> oldSourceFileInfo = sourceFileInfo_; 142 // Only override if sourceFileInfo provides useful information 143 if (sourceFileInfo != NULL) 144 sourceFileInfo_ = sourceFileInfo; 145 146 //if (!bIsRunning_) 147 //{ 148 // bIsRunning_ = true; 149 150 int error = 0; 127 151 #if LUA_VERSION_NUM != 501 128 const char * LuaBind::lua_Chunkreader(lua_State *L, void *data, size_t *size) 129 { 130 LoadS* ls = static_cast<LoadS*>(data); 131 if (ls->size == 0) return NULL; 132 *size = ls->size; 133 ls->size = 0; 134 return ls->s; 135 } 152 LoadS ls; 153 ls.s = code.c_str(); 154 ls.size = code.size(); 155 error = lua_load(luaState_, &orxonox::LuaState::lua_Chunkreader, &ls, code.c_str()); 156 #else 157 error = luaL_loadstring(luaState_, code.c_str()); 136 158 #endif 137 void LuaBind::run() 138 { 139 if (!isRunning_) 140 { 141 isRunning_ = true; 142 int error = 0; 143 std::string init = 144 "local scr = orxonox.LuaBind:getInstance()\n \ 145 local debug = print\n \ 146 print = function(s)\n \ 147 scr:luaPrint(s)\n \ 148 end\n \ 149 include = function(f)\n \ 150 file = assert(io.open(\"" + this->includePath_ + "\"..\"/\"..f))\n \ 151 content = file:read(\"*a\")\n \ 152 file:close()\n \ 153 source = scr:replaceLuaTags(content)\n \ 154 assert(loadstring(source))()\n \ 155 end\n"; 156 init += luaSource_; 157 #if LUA_VERSION_NUM == 501 158 error = luaL_loadstring(luaState_, init.c_str()); 159 #else 160 LoadS ls; 161 ls.s = init.c_str(); 162 ls.size = init.size(); 163 error = lua_load(luaState_, &orxonox::LuaBind::lua_Chunkreader, &ls, init.c_str()); 164 #endif 165 if (error == 0) 166 { 167 error = lua_pcall(luaState_, 0, 0, 0); 168 } 169 if (error != 0) 170 { 171 COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl; 172 } 173 isRunning_ = false; 174 } 175 else 176 { 177 COUT(2) << "Warning: Lua's run is called while running!" << std::endl; 178 } 179 } 180 181 std::string LuaBind::replaceLuaTags(const std::string& text) 182 { 183 // chreate map with all Lua tags 184 std::map<size_t, bool> luaTags; 185 { 186 size_t pos = 0; 187 while ((pos = text.find("<?lua", pos)) != std::string::npos) 188 luaTags[pos++] = true; 189 } 190 { 191 size_t pos = 0; 192 while ((pos = text.find("?>", pos)) != std::string::npos) 193 luaTags[pos++] = false; 194 } 195 196 // erase all tags from the map that are between two quotes 197 { 198 std::map<size_t, bool>::iterator it = luaTags.begin(); 199 std::map<size_t, bool>::iterator it2 = it; 200 bool bBetweenQuotes = false; 201 size_t pos = 0; 202 while ((pos = getNextQuote(text, pos)) != std::string::npos) 203 { 204 while ((it != luaTags.end()) && (it->first < pos)) 205 { 206 if (bBetweenQuotes) { 207 it2++; 208 if(it->second && !(it2->second) && it2->first < pos) 209 it = ++it2; 210 else 211 luaTags.erase(it++); 212 } 213 else 214 ++it; 215 } 216 bBetweenQuotes = !bBetweenQuotes; 217 pos++; 218 } 219 } 220 221 // check whether on every opening <?lua tag a closing ?> tag follows 222 { 223 bool expectedValue = true; 224 for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it) 225 { 226 if (it->second == expectedValue) 227 expectedValue = !expectedValue; 228 else 229 { 230 expectedValue = false; 231 break; 232 } 233 } 234 if (!expectedValue) { 235 COUT(2) << "Warning: Error in level file" << std::endl; 236 // todo: errorhandling 237 return ""; 238 } 239 } 240 241 // cut the original string into pieces and put them together with print() instead of lua tags 242 std::string output; 243 { 244 std::map<size_t, bool>::iterator it = luaTags.begin(); 245 bool bInPrintFunction = true; 246 size_t start = 0; 247 size_t end = 0; 248 249 do 250 { 251 if (it != luaTags.end()) 252 end = (*(it++)).first; 253 else 254 end = std::string::npos; 255 256 unsigned int equalSignCounter = 0; 257 258 if (bInPrintFunction) 259 { 260 // count ['='[ and ]'='] and replace tags with print([[ and ]]) 261 std::string temp = text.substr(start, end - start); 262 { 263 size_t pos = 0; 264 while ((pos = temp.find('[', pos)) != std::string::npos) 159 160 // execute the chunk 161 if (error == 0) 162 error = lua_pcall(luaState_, 0, 0, 0); 163 if (error != 0) 164 { 165 std::string origin; 166 if (sourceFileInfo != NULL) 167 origin = " originating from " + sourceFileInfo_->filename; 168 COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl; 169 } 170 171 // bIsRunning_ = false; 172 //} 173 //else 174 //{ 175 // COUT(2) << "Warning: LuaState do function called while running!" << std::endl; 176 //} 177 178 // Load the old info again 179 sourceFileInfo_ = oldSourceFileInfo; 180 } 181 182 void LuaState::luaPrint(const std::string& str) 183 { 184 output_ << str; 185 } 186 187 void LuaState::luaLog(unsigned int level, const std::string& message) 188 { 189 OutputHandler::getOutStream().setOutputLevel(level) << message << std::endl; 190 } 191 192 #if LUA_VERSION_NUM != 501 193 const char * LuaState::lua_Chunkreader(lua_State *L, void *data, size_t *size) 194 { 195 LoadS* ls = static_cast<LoadS*>(data); 196 if (ls->size == 0) 197 return NULL; 198 *size = ls->size; 199 ls->size = 0; 200 return ls->s; 201 } 202 #endif 203 204 /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name) 205 { 206 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it) 207 { 208 if (it->first == name || it->second == function) 265 209 { 266 unsigned int tempCounter = 1; 267 size_t tempPos = pos++; 268 while(temp[++tempPos] == '=') { 269 tempCounter++; 270 } 271 if(temp[tempPos] != '[') { 272 tempCounter = 0; 273 } 274 else if(tempCounter == 0) { 275 tempCounter = 1; 276 } 277 if (tempCounter > equalSignCounter) 278 equalSignCounter = tempCounter; 210 COUT(2) << "Warning: Trying to add a Tolua interface with the same name or function." << std::endl; 211 return true; 279 212 } 280 } 281 { 282 size_t pos = 0; 283 while ((pos = temp.find(']', pos)) != std::string::npos) 284 { 285 unsigned int tempCounter = 1; 286 size_t tempPos = pos++; 287 while(temp[++tempPos] == '=') { 288 tempCounter++; 289 } 290 if(temp[tempPos] != ']') { 291 tempCounter = 0; 292 } 293 else if(tempCounter == 0) { 294 tempCounter = 1; 295 } 296 if (tempCounter > equalSignCounter) 297 equalSignCounter = tempCounter; 298 } 299 } 300 std::string equalSigns = ""; 301 for(unsigned int i = 0; i < equalSignCounter; i++) { 302 equalSigns += "="; 303 } 304 output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])"; 305 start = end + 5; 306 } 307 else 308 { 309 output += text.substr(start, end - start); 310 start = end + 2; 311 } 312 313 bInPrintFunction = !bInPrintFunction; 314 } 315 while (end != std::string::npos); 316 } 317 318 return output; 319 } 320 321 void LuaBind::addToluaInterface(int (*function)(lua_State*), const std::string& name) 322 { 323 toluaInterfaces_.push_back(std::make_pair(name, function)); 324 // Apply changes to our own lua state as well 325 (*function)(luaState_); 326 } 327 328 void LuaBind::openToluaInterfaces(lua_State* state) 329 { 330 for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i) 331 (*toluaInterfaces_[i].second)(state); 332 } 333 334 void LuaBind::closeToluaInterfaces(lua_State* state) 335 { 336 for (unsigned int i = 0; i < toluaInterfaces_.size(); ++i) 337 { 338 lua_pushnil(state); 339 lua_setglobal(state, toluaInterfaces_[i].first.c_str()); 340 } 341 } 342 213 } 214 toluaInterfaces_s[name] = function; 215 216 // Open interface in all LuaStates 217 for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it) 218 (*function)((*it)->luaState_); 219 220 // Return dummy bool 221 return true; 222 } 223 224 /*static*/ bool LuaState::removeToluaInterface(const std::string& name) 225 { 226 ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name); 227 if (it == toluaInterfaces_s.end()) 228 { 229 COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl; 230 return true; 231 } 232 233 // Close interface in all LuaStates 234 for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState) 235 { 236 lua_pushnil((*itState)->luaState_); 237 lua_setglobal((*itState)->luaState_, it->first.c_str()); 238 } 239 240 // Remove entry 241 toluaInterfaces_s.erase(it); 242 243 // Return dummy bool 244 return true; 245 } 246 247 /*static*/ void LuaState::openToluaInterfaces(lua_State* state) 248 { 249 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it) 250 (*it->second)(state); 251 } 252 253 /*static*/ void LuaState::closeToluaInterfaces(lua_State* state) 254 { 255 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it) 256 { 257 lua_pushnil(state); 258 lua_setglobal(state, it->first.c_str()); 259 } 260 } 343 261 } -
code/branches/resource2/src/core/LuaState.h
r5645 r5654 22 22 * Author: 23 23 * Benjamin Knecht 24 * Reto Grieder 24 25 * Co-authors: 25 26 * ... … … 27 28 */ 28 29 29 /** 30 @file 31 @brief Representation of an interface to lua 32 @author Benjamin Knecht <beni_at_orxonox.net> 33 */ 34 35 #ifndef _LuaBind_H__ 36 #define _LuaBind_H__ 30 #ifndef _LuaState_H__ 31 #define _LuaState_H__ 37 32 38 33 #include "CorePrereqs.h" 39 34 40 #include <cassert> 35 #include <map> 36 #include <sstream> 41 37 #include <string> 42 38 #include <vector> 43 extern "C" { 44 #include <lua.h> 45 } 39 #include <boost/shared_ptr.hpp> 46 40 47 #include "util/S ingleton.h"41 #include "util/ScopeGuard.h" 48 42 49 43 // tolua_begin 50 44 namespace orxonox 51 45 { 52 class _CoreExport LuaBind : public Singleton<LuaBind> 53 { 46 /** 47 @brief 48 Representation of an interface to lua 49 */ 50 class _CoreExport LuaState 51 { 54 52 // tolua_end 55 friend class Singleton<LuaBind>; 53 public: 54 LuaState(); 55 ~LuaState(); 56 56 57 struct LoadS { 58 const char *s; 59 size_t size; 60 }; 57 void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 58 void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 61 59 62 public: 63 LuaBind(); 64 ~LuaBind(); 60 void includeFile(const std::string& filename, const std::string& resourceGroup = "Genreal", bool bSearchOtherPaths = true); // tolua_export 61 void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 65 62 66 static LuaBind& getInstance() { return Singleton<LuaBind>::getInstance(); } // tolua_export 63 void luaPrint(const std::string& str); // tolua_export 64 void luaLog(unsigned int level, const std::string& message); // tolua_export 67 65 68 void loadFile(const std::string& filename, bool luaTags); 69 void loadString(const std::string& code); 70 //void init(lua_State *state_); 71 //void xmlToLua(); 72 void run(); 73 void luaPrint(const std::string& str); // tolua_export 66 const std::stringstream& getOutput() const { return output_; } 67 void clearOutput() { output_.clear(); } // tolua_export 68 69 void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; } 70 lua_State* getInternalLuaState() { return luaState_; } 71 72 static bool addToluaInterface(int (*function)(lua_State*), const std::string& name); 73 static bool removeToluaInterface(const std::string& name); 74 static void openToluaInterfaces(lua_State* state); 75 static void closeToluaInterfaces(lua_State* state); 76 77 private: 78 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths); 74 79 75 80 #if LUA_VERSION_NUM != 501 76 static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size); 81 struct LoadS 82 { 83 const char* s; 84 size_t size; 85 }; 86 87 static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size); 77 88 #endif 78 89 79 inline lua_State* getLuaState() { return luaState_; }; 80 inline const std::string& getLuaOutput() { return output_; }; 81 //inline std::string* getFileString() { return &fileString_; }; 82 inline void clearLuaOutput() { output_ = ""; } 90 std::stringstream output_; 91 lua_State* luaState_; 92 bool bIsRunning_; 93 shared_ptr<ResourceInfo> sourceFileInfo_; 94 std::string (*includeParseFunction_)(const std::string&); 83 95 84 std::string replaceLuaTags(const std::string& text); // tolua_export 96 typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap; 97 static ToluaInterfaceMap toluaInterfaces_s; 98 static std::vector<LuaState*> instances_s; 99 }; // tolua_export 100 } // tolua_export 85 101 86 inline void setIncludePath(const std::string& includepath) 87 { this->includePath_ = includepath; } 88 89 void addToluaInterface(int (*function)(lua_State*), const std::string& name); 90 void openToluaInterfaces(lua_State* state); 91 void closeToluaInterfaces(lua_State* state); 92 93 private: 94 static LuaBind* singletonPtr_s; 95 96 std::string luaSource_; 97 std::string output_; 98 lua_State* luaState_; 99 bool isRunning_; 100 std::string includePath_; 101 std::vector<std::pair<std::string, int (*)(lua_State *L)> > toluaInterfaces_; 102 103 }; // tolua_export 104 } // tolua_export 105 #endif /* _LuaBind_H__ */ 102 #endif /* _LuaState_H__ */ -
code/branches/resource2/src/orxonox/gamestates/GSGraphics.cc
r5645 r5654 96 96 // load debug overlay 97 97 COUT(3) << "Loading Debug Overlay..." << std::endl; 98 this->debugOverlay_ = new XMLFile( Core::getDataPathString() + "overlay/debug.oxo");98 this->debugOverlay_ = new XMLFile("debug.oxo"); 99 99 Loader::open(debugOverlay_); 100 100 -
code/branches/resource2/src/orxonox/gamestates/GSLevel.cc
r5645 r5654 246 246 // call the loader 247 247 COUT(0) << "Loading level..." << std::endl; 248 startFile_s = new XMLFile( Core::getDataPathString() + "levels" + '/' +LevelManager::getInstance().getDefaultLevel());248 startFile_s = new XMLFile(LevelManager::getInstance().getDefaultLevel()); 249 249 Loader::open(startFile_s); 250 250 } -
code/branches/resource2/src/orxonox/gamestates/GSRoot.cc
r3370 r5654 33 33 #include "core/Game.h" 34 34 #include "core/GameMode.h" 35 #include "core/Lua Bind.h"35 #include "core/LuaState.h" 36 36 #include "network/NetworkFunction.h" 37 #include "ToluaBindCore.h"38 37 #include "ToluaBindOrxonox.h" 39 38 #include "tools/Timer.h" … … 56 55 57 56 // Tell LuaBind about all tolua interfaces 58 LuaBind::getInstance().addToluaInterface(&tolua_Core_open, "Core"); 59 LuaBind::getInstance().addToluaInterface(&tolua_Orxonox_open, "Orxonox"); 57 LuaState::addToluaInterface(&tolua_Orxonox_open, "Orxonox"); 60 58 } 61 59 … … 86 84 } 87 85 88 // create the globalLevelManager86 // create the LevelManager 89 87 this->levelManager_ = new LevelManager(); 90 88 } -
code/branches/resource2/src/orxonox/objects/Level.cc
r5653 r5654 53 53 this->registerVariables(); 54 54 this->xmlfilename_ = this->getFilename(); 55 56 if (this->xmlfilename_.length() >= Core::getDataPathString().length())57 this->xmlfilename_ = this->xmlfilename_.substr(Core::getDataPathString().length());58 55 } 59 56 -
code/branches/resource2/src/orxonox/objects/Script.cc
r3196 r5654 29 29 #include "Script.h" 30 30 31 #include <tinyxml/ticpp.h>32 31 #include "core/CoreIncludes.h" 33 #include "core/LuaBind.h" 32 #include "core/LuaState.h" 33 #include "core/XMLPort.h" 34 34 35 35 namespace orxonox 36 36 { 37 CreateFactory(Script);37 CreateFactory(Script); 38 38 39 Script::Script(BaseObject* creator) : BaseObject(creator)40 {41 RegisterObject(Script);39 Script::Script(BaseObject* creator) : BaseObject(creator) 40 { 41 RegisterObject(Script); 42 42 43 code_ = ""; 44 } 43 // Get a new LuaState 44 luaState_ = new LuaState(); 45 } 45 46 46 Script::~Script() 47 { 48 } 47 Script::~Script() 48 { 49 if (this->isInitialized()) 50 delete luaState_; 51 } 49 52 50 /** 51 @brief XML loading and saving. 52 @param xmlelement The XML-element 53 @param loading Loading (true) or saving (false) 54 */ 55 void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode) 56 { 57 BaseObject::XMLPort(xmlelement, mode); 53 void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode) 54 { 55 BaseObject::XMLPort(xmlelement, mode); 58 56 59 code_ = xmlelement.GetText(false);60 }57 XMLPortParam(Script, "code", setCode, getCode, xmlelement, mode); 58 } 61 59 62 void Script::execute() 63 { 64 LuaBind& lua = LuaBind::getInstance(); 65 lua.loadString(this->code_); 66 lua.run(); 67 } 60 void Script::execute() 61 { 62 luaState_->doString(code_); 63 } 68 64 } -
code/branches/resource2/src/orxonox/objects/Script.h
r3196 r5654 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport Script : public BaseObject40 {39 class _OrxonoxExport Script : public BaseObject 40 { 41 41 public: 42 Script(BaseObject* creator); 43 ~Script(); 44 void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 void execute(); 42 Script(BaseObject* creator); 43 ~Script(); 44 void XMLPort(Element& xmlelement, XMLPort::Mode mode); 45 void execute(); 46 47 void setCode(const std::string& code) { code_ = code; } 48 const std::string& getCode() const { return code_; } 46 49 47 50 private: 48 std::string code_; 49 }; 51 std::string code_; 52 LuaState* luaState_; 53 }; 50 54 } 51 55 -
code/branches/resource2/src/orxonox/sound/SoundBase.cc
r5645 r5654 36 36 #include "util/Math.h" 37 37 #include "core/Core.h" 38 #include "core/Resource.h" 38 39 #include "orxonox/objects/worldentities/WorldEntity.h" 39 40 #include "SoundManager.h" … … 134 135 } 135 136 136 bool SoundBase::loadFile(std::string filename) { 137 filename = Core::getDataPathString() + "/audio/" + filename; 138 137 bool SoundBase::loadFile(const std::string& filename) { 139 138 if(!SoundManager::getInstance().isSoundAvailable()) 140 139 { … … 144 143 145 144 COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl; 146 this->buffer_ = alutCreateBufferFromFile(filename.c_str()); 145 // Get DataStream from the resources 146 shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(filename); 147 if (fileInfo == NULL) { 148 COUT(2) << "Warning: Sound file '" << filename << "' not found" << std::endl; 149 return false; 150 } 151 DataStreamPtr stream = Resource::open(filename); 152 // Read everything into a temporary buffer 153 char* buffer = new char[fileInfo->size]; 154 stream->read(buffer, fileInfo->size); 155 156 this->buffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size); 157 delete[] buffer; 158 147 159 if(this->buffer_ == AL_NONE) { 148 160 COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl; -
code/branches/resource2/src/orxonox/sound/SoundBase.h
r3196 r5654 55 55 bool isStopped(); 56 56 57 bool loadFile( std::stringfilename);57 bool loadFile(const std::string& filename); 58 58 59 59 private: -
data/branches/media_stripped/resources.oxr
r5644 r5654 1 <ResourceGroup name = "General" > 2 <ResourceLocation path = overlay /> 3 <ResourceLocation path = particle /> 4 <ResourceLocation path = defaultConfig /> 5 <ResourceLocation path = levels /> 6 <ResourceLocation path = tcl /> 7 <ResourceLocation 8 path = test.zip 9 archive = Zip 10 recursive = true 11 /> 12 </ResourceGroup> 1 <ResourceCollection resourceGroup = "General" > 2 </ResourceCollection> 13 3 14 <ResourceGroup name = "GUI" > 15 <ResourceLocation path = gui/configs /> 16 <ResourceLocation path = gui/layouts /> 17 <ResourceLocation path = gui/schemas /> 18 <ResourceLocation path = gui/scripts /> 19 </ResourceGroup> 4 <ResourceCollection resourceGroup = "GUI" > 5 </ResourceCollection> -
data/branches/media_stripped/resources_graphics.oxr
r5645 r5654 1 <ResourceGroup name = "General" > 2 <ResourceLocation path = overlay /> 3 <ResourceLocation path = particle /> 4 <ResourceLocation path = defaultConfig /> 5 <ResourceLocation path = levels /> 6 <ResourceLocation path = tcl /> 7 <ResourceLocation 8 path = test.zip 9 archive = Zip 10 recursive = true 11 /> 12 </ResourceGroup> 1 <ResourceCollection resourceGroup = "General" > 2 <ResourceLocation path = "audio" /> 3 <ResourceLocation path = "fonts" /> 4 <ResourceLocation path = "materials/programs" /> 5 <ResourceLocation path = "materials/scripts" /> 6 <ResourceLocation path = "materials/textures" /> 7 <ResourceLocation path = "models" /> 8 <ResourceLocation path = "gui/fonts" /> 9 <ResourceLocation path = "packs/cubemap.zip" archiveType = "Zip" /> 10 <ResourceLocation path = "packs/skybox.zip" archiveType = "Zip" /> 11 </ResourceCollection> 13 12 14 <ResourceGroup name = "GUI" > 15 <ResourceLocation path = gui/configs /> 16 <ResourceLocation path = gui/layouts /> 17 <ResourceLocation path = gui/schemas /> 18 <ResourceLocation path = gui/scripts /> 19 </ResourceGroup> 13 <ResourceCollection resourceGroup = "GUI" > 14 <ResourceLocation path = "gui/fonts" /> 15 <ResourceLocation path = "gui/imagesets" /> 16 <ResourceLocation path = "gui/looknfeel" /> 17 </ResourceCollection>
Note: See TracChangeset
for help on using the changeset viewer.