Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 8, 2008, 1:51:25 AM (17 years ago)
Author:
landauf
Message:

ok, be aware, here comes a big one. people with weak nerves should probably better look away or take some serious drugs.
this update includes partial and explicit class template specialization, partial and explicit specialized template function overloading, template meta programming and a simple typecast.
yeah right, a typecast. but let me explain the whole story from the beginning.

it all started with a simple problem: i had a double in a MultiType and wanted a float, but i always got 0. what was the problem? the conversion 'MultiType to anyting' was handled by the Converter class in util/Convert.h and the Converter was specialized for strings, multitypes, vectors and so on, but not for int, float, bool, …
so i've first wanted to implement a typecast as default, but this was a bad idea because it doesn't work for almost every generic type.
implementing an explicit specialization for every possible pair of primitives (did you ever happened to use an unsigned short? or a long double? no? ignorants :D) would have been a simple but ugly solution.
but there were other problems: if there's a rule to convert a string into anything and another rule to convert anything into an int - what happens if you want to convert a string into an int? compiler error! …ambiguous partial template specialization.
so i've spent days and nights to find a solution. this is my 5th try or so and i'm still really unsure if it works, but it's the first version i want to commit to have at least a backup.
if you're interested in looking at the code you better wait until i've cleaned up the whole thing, it's a real mess. and i want to do further tests, but now i'm tired. good night ;)

Location:
code/branches/core2/src/orxonox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core2/src/orxonox/OrxonoxStableHeaders.h

    r871 r1001  
    8383
    8484#include "util/Math.h"
    85 #include "util/Convert.h"
    8685#include "util/Sleep.h"
    8786#include "util/String2Number.h"
  • code/branches/core2/src/orxonox/core/CommandExecutor.cc

    r994 r1001  
    297297    }
    298298
    299     bool CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
     299    Executor& CommandExecutor::addConsoleCommandShortcut(ExecutorStatic* executor)
    300300    {
    301301        CommandExecutor::getInstance().consoleCommandShortcuts_[executor->getName()] = executor;
    302302        CommandExecutor::getInstance().consoleCommandShortcuts_LC_[getLowercase(executor->getName())] = executor;
    303         return true;
     303        return (*executor);
    304304    }
    305305
  • code/branches/core2/src/orxonox/core/CommandExecutor.h

    r994 r1001  
    139139            static CommandEvaluation evaluate(const std::string& command);
    140140
    141             static bool addConsoleCommandShortcut(ExecutorStatic* executor);
     141            static Executor& addConsoleCommandShortcut(ExecutorStatic* executor);
    142142            static ExecutorStatic* getConsoleCommandShortcut(const std::string& name);
    143143            static ExecutorStatic* getLowercaseConsoleCommandShortcut(const std::string& name);
  • code/branches/core2/src/orxonox/core/ConsoleCommand.h

    r993 r1001  
    5050
    5151#define ConsoleCommandShortcutGeneric(fakevariable, executor) \
    52     bool fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
     52    Executor& fakevariable = CommandExecutor::addConsoleCommandShortcut((ExecutorStatic*)executor)
    5353
    5454
  • code/branches/core2/src/orxonox/core/Functor.h

    r967 r1001  
    325325            void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \
    326326            { \
     327                std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl; \
     328                std::cout << param1 << std::endl; \
     329                std::cout << this->getTypenameParam(0) << std::endl; \
    327330                FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \
     331                std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" << std::endl; \
    328332            } \
    329333    \
  • code/branches/core2/src/orxonox/objects/Tickable.cc

    r871 r1001  
    11#include "core/CoreIncludes.h"
     2#include "core/ConsoleCommand.h"
    23#include "Tickable.h"
    34
    45namespace orxonox
    56{
     7    ConsoleCommandShortcutExtern(slomo, AccessLevel::Offline).setDefaultValue(0, 1.0);
     8    ConsoleCommandShortcutExtern(setTimeFactor, AccessLevel::Offline).setDefaultValue(0, 1.0);
     9
     10    static float timefactor = 1.0;
     11    void slomo(float factor)
     12    {
     13        setTimeFactor(factor);
     14    }
     15    void setTimeFactor(float factor)
     16    {
     17        timefactor = factor;
     18    }
     19    float getTimeFactor()
     20    {
     21        return timefactor;
     22    }
     23
    624    /**
    725        @brief Constructor: Registers the object in the Tickable-list
  • code/branches/core2/src/orxonox/objects/Tickable.h

    r871 r1001  
    5050    class TickFrameListener; // Forward declaration
    5151
     52    void slomo(float factor);
     53    void setTimeFactor(float factor = 1.0);
     54    float getTimeFactor();
     55
    5256    //! The Tickable interface provides a tick(dt) function, that gets called every frame.
    5357    class _OrxonoxExport Tickable : virtual public OrxonoxClass
     
    7175            bool frameStarted(const Ogre::FrameEvent &evt)
    7276            {
     77                float dt = evt.timeSinceLastFrame * getTimeFactor();
    7378                // Iterate through all Tickables and call their tick(dt) function
    7479                for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; )
    75                     (it++)->tick(evt.timeSinceLastFrame);
     80                    (it++)->tick(dt);
    7681
    7782                return FrameListener::frameStarted(evt);
  • code/branches/core2/src/orxonox/tools/Timer.h

    r995 r1001  
    6363#include "OrxonoxPrereqs.h"
    6464#include "core/CorePrereqs.h"
     65#include "../objects/Tickable.h"
    6566
    6667namespace orxonox
     
    200201            bool frameStarted(const Ogre::FrameEvent &evt)
    201202            {
     203                float dt = evt.timeSinceLastFrame * getTimeFactor();
    202204                // Iterate through all Timers
    203205                for (Iterator<TimerBase> it = ObjectList<TimerBase>::start(); it; )
     
    206208                    {
    207209                        // If active: Decrease the timer by the duration of the last frame
    208                         it->time_ -= evt.timeSinceLastFrame;
     210                        it->time_ -= dt;
    209211
    210212                        if (it->time_ <= 0)
Note: See TracChangeset for help on using the changeset viewer.