Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/orxonox/objects/Tickable.cc @ 1342

Last change on this file since 1342 was 1001, checked in by landauf, 17 years ago

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 ;)

File size: 734 bytes
Line 
1#include "core/CoreIncludes.h"
2#include "core/ConsoleCommand.h"
3#include "Tickable.h"
4
5namespace orxonox
6{
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
24    /**
25        @brief Constructor: Registers the object in the Tickable-list
26    */
27    Tickable::Tickable()
28    {
29        RegisterRootObject(Tickable);
30    }
31}
Note: See TracBrowser for help on using the repository browser.