Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 17, 2009, 4:37:10 PM (15 years ago)
Author:
rgrieder
Message:
  • Implemented file management via resource manager and loading of resource locations via XML. Changes made:
    • SoundManager loads via memory stream rather than via file
    • Loader uses LuaState::includeFile() to load an XML file and passes the lua tag remover function to its LuaState.
    • ConfigFileManager still loads with hard paths because the files are required before Ogre gets created
  • Renamed LuaBind to LuaState, deSingletonised it and added new features:
    • doFile(), doString(), includeFile(), includeString() where include will preparse the string with a function provided with LuaState::setIncludeParser
    • Moved lua tags replace function to Loader (since it's actually an XML related task)
    • Using data_path/lua/LuaInitScript.lua to provide the following functions
      • logMessage(level, message)
      • doFile, dofile, include (all working with relative paths but within the same resource group)
  • Modified Script class to work with LuaState and fixed its XML Loader
  • Adjusted all level and include files (both "include" and "dofile" lua commands)
Location:
code/branches/resource2/src/orxonox/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/resource2/src/orxonox/objects/Level.cc

    r5653 r5654  
    5353        this->registerVariables();
    5454        this->xmlfilename_ = this->getFilename();
    55 
    56         if (this->xmlfilename_.length() >= Core::getDataPathString().length())
    57             this->xmlfilename_ = this->xmlfilename_.substr(Core::getDataPathString().length());
    5855    }
    5956
  • code/branches/resource2/src/orxonox/objects/Script.cc

    r3196 r5654  
    2929#include "Script.h"
    3030
    31 #include <tinyxml/ticpp.h>
    3231#include "core/CoreIncludes.h"
    33 #include "core/LuaBind.h"
     32#include "core/LuaState.h"
     33#include "core/XMLPort.h"
    3434
    3535namespace orxonox
    3636{
    37   CreateFactory(Script);
     37    CreateFactory(Script);
    3838
    39   Script::Script(BaseObject* creator) : BaseObject(creator)
    40   {
    41     RegisterObject(Script);
     39    Script::Script(BaseObject* creator) : BaseObject(creator)
     40    {
     41        RegisterObject(Script);
    4242
    43     code_ = "";
    44   }
     43        // Get a new LuaState
     44        luaState_ = new LuaState();
     45    }
    4546
    46   Script::~Script()
    47   {
    48   }
     47    Script::~Script()
     48    {
     49        if (this->isInitialized())
     50            delete luaState_;
     51    }
    4952
    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);
    5856
    59     code_ = xmlelement.GetText(false);
    60   }
     57        XMLPortParam(Script, "code", setCode, getCode, xmlelement, mode);
     58    }
    6159
    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    }
    6864}
  • code/branches/resource2/src/orxonox/objects/Script.h

    r3196 r5654  
    3737namespace orxonox
    3838{
    39   class _OrxonoxExport Script : public BaseObject
    40   {
     39    class _OrxonoxExport Script : public BaseObject
     40    {
    4141    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_; }
    4649
    4750    private:
    48       std::string code_;
    49   };
     51        std::string code_;
     52        LuaState* luaState_;
     53    };
    5054}
    5155
Note: See TracChangeset for help on using the changeset viewer.