Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/ConfigValueIncludes.h @ 1438

Last change on this file since 1438 was 1324, checked in by landauf, 17 years ago

Added a command-history to the console. you can scroll through all previously entered commands by pressing [up] key.
The history is stored in orxonox.ini in the section [Shell]. You can configure the maximal amount of stored commands (default: 100).
This allows you to use the history after orxonox was restarted.
The history uses a cyclic vector (with the configured size), meaning the newest command will overwrite the oldest entry (if the maximal size was reached).

additionally I fixed some bugs in ConfigValueContainer and added a mod-function to Math.h, that does basically the same as %, but without returning a negative value in case of a negative input.

-1 % 10 = -1
-11 % 10 = -1

mod(-1, 10) = 9
mod(-11, 10) = 9

File size: 4.9 KB
RevLine 
[1030]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
[1056]3 *                    > www.orxonox.net <
[1030]4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file ConfigValueIncludes.h
31    @brief Definition of macros for config-values.
32*/
33
34#ifndef _ConfigValueIncludes_H__
35#define _ConfigValueIncludes_H__
36
[1062]37#include "CorePrereqs.h"
38
[1030]39#include "Identifier.h"
40#include "ConfigValueContainer.h"
41#include "ConfigFileManager.h"
42
43
44/**
45    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
46    @param varname The name of the variable
47    @param defvalue The default-value of the variable
48*/
49#define SetConfigValue(varname, defvalue) \
50    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
51    if (!container##varname) \
52    { \
53        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
54        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
55    } \
56    container##varname->getValue(&varname)
57
58/**
59    @brief Assigns the vector-values, defined in the config-file, to the vector (or the default-value, if there are no entries in the file).
60    @param varname The name of the std::vector
61    @param defvalue The default-value
62*/
63#define SetConfigValueVector(varname, defvalue) \
64    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
65    if (!container##varname) \
66    { \
67        std::vector<MultiTypeMath> temp; \
68        for (unsigned int i = 0; i < defvalue.size(); i++) \
69            temp.push_back(MultiTypeMath(defvalue[i])); \
70        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
[1324]71        container##varname->setVectorType(varname); \
[1030]72        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
73    } \
74    container##varname->getValue(&varname)
75
76/**
77    @brief Sets the variable and the config-file entry back to the previously defined default-value.
78    @param varname The name of the variable
79*/
80#define ResetConfigValue(varname) \
81    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
82    if (container##varname##reset) \
83    { \
84        container##varname##reset->reset(); \
85        container##varname##reset->getValue(&varname); \
86    } \
87    else \
[1031]88    { \
[1033]89        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
[1031]90    }
[1030]91
92/**
[1033]93    @brief Modifies a config-value by using a modifier and some arguments.
94    @param varname The name of the config-value
95    @param modifier The name of the modifier: set, tset, add, remove, reset, update
96*/
97#define ModifyConfigValue(varname, modifier, ...) \
98    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
99    if (container##varname##modify##modifier) \
100    { \
101        container##varname##modify##modifier->modifier(__VA_ARGS__); \
102        container##varname##modify##modifier->getValue(&varname); \
103    } \
104    else \
105    { \
106        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
107    }
108
109/**
[1030]110    @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).
111    @param varname The name of the key-variable
112*/
113#define SetKeybind(keyname) \
114    orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
115    if (!container##keyname) \
116    { \
117        container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
118        this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
119    } \
120    container##keyname->getValue(&varname)
121
122#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.