Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 30, 2009, 2:10:44 PM (15 years ago)
Author:
rgrieder
Message:

Merged resource branch back to the trunk. Changes:

  • Automated graphics loading by evaluating whether a GameState requires it
  • Using native Tcl library (x3n)

Windows users: Update your dependency package!

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/TclBind.cc

    r3318 r3370  
    3333#include <cpptcl/cpptcl.h>
    3434
     35#include "SpecialConfig.h"
    3536#include "util/Debug.h"
    3637#include "util/StringUtils.h"
    3738#include "CommandExecutor.h"
    3839#include "ConsoleCommand.h"
     40#include "Core.h"
    3941#include "TclThreadManager.h"
    4042
     
    4446    SetConsoleCommandShortcut(TclBind, bgerror);
    4547
    46     TclBind* TclBind::singletonRef_s = 0;
     48    TclBind* TclBind::singletonPtr_s = 0;
    4749
    4850    TclBind::TclBind(const std::string& datapath)
    4951    {
    50         assert(singletonRef_s == 0);
    51         singletonRef_s = this;
    5252        this->interpreter_ = 0;
    53         this->bSetTclLibPath_ = false;
     53        this->bSetTclDataPath_ = false;
    5454        this->setDataPath(datapath);
    5555    }
     
    5959        if (this->interpreter_)
    6060            delete this->interpreter_;
    61         singletonRef_s = 0;
    6261    }
    6362
     
    6564    {
    6665        // String has POSIX slashes
    67         this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/';
    68         this->bSetTclLibPath_ = true;
    69 
    70         this->createTclInterpreter();
    71     }
    72 
    73     void TclBind::createTclInterpreter()
    74     {
    75         if (this->bSetTclLibPath_ && !this->interpreter_)
    76         {
    77             this->interpreter_ = new Tcl::interpreter(this->tclLibPath_);
    78             this->interpreter_->def("orxonox::query", TclBind::tcl_query, Tcl::variadic());
    79             this->interpreter_->def("orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
     66        this->tclDataPath_ = datapath + "tcl" + '/';
     67        this->bSetTclDataPath_ = true;
     68
     69        this->initializeTclInterpreter();
     70    }
     71
     72    void TclBind::initializeTclInterpreter()
     73    {
     74        if (this->bSetTclDataPath_ && !this->interpreter_)
     75        {
     76            this->interpreter_ = this->createTclInterpreter();
     77
     78            this->interpreter_->def("::orxonox::query", TclBind::tcl_query, Tcl::variadic());
     79            this->interpreter_->def("::orxonox::crossquery", TclThreadManager::tcl_crossquery, Tcl::variadic());
    8080            this->interpreter_->def("execute", TclBind::tcl_execute, Tcl::variadic());
    81             this->interpreter_->def("orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
     81            this->interpreter_->def("::orxonox::crossexecute", TclThreadManager::tcl_crossexecute, Tcl::variadic());
    8282
    8383            try
    8484            {
    85                 this->interpreter_->eval("proc query args { orxonox::query [join $args] }");
    86                 this->interpreter_->eval("proc crossquery {id args} { orxonox::crossquery 0 $id [join $args] }");
    87                 this->interpreter_->eval("proc crossexecute {id args} { orxonox::crossquery 0 $id [join $args] }");
     85                this->interpreter_->eval("proc query        {args}    { ::orxonox::query $args }");
     86                this->interpreter_->eval("proc crossquery   {id args} { ::orxonox::crossquery 0 $id $args }");
     87                this->interpreter_->eval("proc crossexecute {id args} { ::orxonox::crossquery 0 $id $args }");
     88                this->interpreter_->eval("proc running      {}        { return 1 }");
    8889                this->interpreter_->eval("set id 0");
    89                 this->interpreter_->eval("rename exit tcl::exit; proc exit {} { execute exit }");
    90                 this->interpreter_->eval("redef_puts");
     90                this->interpreter_->eval("rename exit ::tcl::exit; proc exit {} { execute exit }");
    9191            }
    9292            catch (Tcl::tcl_error const &e)
     
    9494            catch (std::exception const &e)
    9595            {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl;   }
    96         }
    97     }
    98 
    99     void TclBind::createNewTclInterpreter()
    100     {
    101         if (this->interpreter_)
    102         {
    103             delete this->interpreter_;
    104             this->interpreter_ = 0;
    105         }
    106 
    107         this->createTclInterpreter();
     96            catch (...)
     97            {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl;   }
     98        }
     99    }
     100
     101    Tcl::interpreter* TclBind::createTclInterpreter()
     102    {
     103        Tcl::interpreter* interpreter = new Tcl::interpreter();
     104        std::string libpath = TclBind::getTclLibraryPath();
     105
     106        try
     107        {
     108            if (libpath != "")
     109                interpreter->eval("set tcl_library \"" + libpath + "\"");
     110
     111            Tcl_Init(interpreter->get());
     112
     113            interpreter->eval("source \"" + TclBind::getInstance().tclDataPath_ + "/init.tcl\"");
     114        }
     115        catch (Tcl::tcl_error const &e)
     116        {   COUT(1) << "Tcl error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
     117        catch (std::exception const &e)
     118        {   COUT(1) << "Error while creating Tcl-interpreter: " << e.what() << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
     119        catch (...)
     120        {   COUT(1) << "Error while creating Tcl-interpreter." << std::endl; COUT(1) << "Error: Tcl isn't properly initialized. Orxonox might possibly not work like that." << std::endl;   }
     121
     122        return interpreter;
     123    }
     124
     125    std::string TclBind::getTclLibraryPath()
     126    {
     127#ifdef DEPENDENCY_PACKAGE_ENABLE
     128        if (Core::isDevelopmentRun())
     129            return (std::string(ORXONOX_DEP_LIB_PATH) + "/tcl");
     130        else
     131            return (Core::getRootPathString() + "lib/tcl");
     132#else
     133        return "";
     134#endif
    108135    }
    109136
     
    142169            try
    143170            {
    144                 std::string output = TclBind::getInstance().interpreter_->eval(tclcode);
     171                std::string output = TclBind::getInstance().interpreter_->eval("uplevel #0 " + tclcode);
    145172                if (output != "")
    146173                {
Note: See TracChangeset for help on using the changeset viewer.