[Orxonox-commit 4004] r8678 - in code/branches/unity_build/src: libraries/core libraries/core/input libraries/util orxonox/gamestates
rgrieder at orxonox.net
rgrieder at orxonox.net
Mon May 30 02:38:34 CEST 2011
Author: rgrieder
Date: 2011-05-30 02:38:34 +0200 (Mon, 30 May 2011)
New Revision: 8678
Added:
code/branches/unity_build/src/libraries/util/tribool.h
Removed:
code/branches/unity_build/src/libraries/util/TriBool.h
Modified:
code/branches/unity_build/src/libraries/core/GUIManager.cc
code/branches/unity_build/src/libraries/core/GUIManager.h
code/branches/unity_build/src/libraries/core/input/InputManager.cc
code/branches/unity_build/src/libraries/core/input/InputManager.h
code/branches/unity_build/src/libraries/core/input/InputState.cc
code/branches/unity_build/src/libraries/core/input/InputState.h
code/branches/unity_build/src/orxonox/gamestates/GSLevel.cc
Log:
Replaced TriBool with a modified version of boost::tribool. The main reason was that 'True' and 'False' had to be replaced because of macro collisions.
So why not use the real true and false with a third state? That's what boost tribool did, so I changed that implementation to fit our needs and change its behavior.
It's also safer to use because it avoids unwanted implicit conversions.
Modified: code/branches/unity_build/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/GUIManager.cc 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/GUIManager.cc 2011-05-30 00:38:34 UTC (rev 8678)
@@ -418,7 +418,7 @@
GUIManager::hideGUI(name);
}
- const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showCursor, TriBool::Value useKeyboard, bool bBlockJoyStick)
+ const std::string& GUIManager::createInputState(const std::string& name, tribool showCursor, tribool useKeyboard, bool bBlockJoyStick)
{
InputState* state = InputManager::getInstance().createInputState(name);
if (!state)
@@ -434,24 +434,24 @@
#ifdef ORXONOX_PLATFORM_APPLE
// There is no non exclusive mode on OS X yet
- state->setMouseExclusive(TriBool::True);
+ state->setMouseExclusive(true);
#else
- if (showCursor == TriBool::Dontcare)
- state->setMouseExclusive(TriBool::Dontcare);
- else if (GraphicsManager::getInstance().isFullScreen() || showCursor == TriBool::False)
- state->setMouseExclusive(TriBool::True);
+ if (showCursor == dontcare)
+ state->setMouseExclusive(dontcare);
+ else if (GraphicsManager::getInstance().isFullScreen() || showCursor == false)
+ state->setMouseExclusive(true);
else
- state->setMouseExclusive(TriBool::False);
+ state->setMouseExclusive(false);
#endif
- if (showCursor == TriBool::True)
+ if (showCursor == true)
state->setMouseHandler(this);
- else if (showCursor == TriBool::False)
+ else if (showCursor == false)
state->setMouseHandler(&InputHandler::EMPTY);
- if (useKeyboard == TriBool::True)
+ if (useKeyboard == true)
state->setKeyHandler(this);
- else if (useKeyboard == TriBool::False)
+ else if (useKeyboard == false)
state->setKeyHandler(&InputHandler::EMPTY);
if (bBlockJoyStick)
Modified: code/branches/unity_build/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/unity_build/src/libraries/core/GUIManager.h 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/GUIManager.h 2011-05-30 00:38:34 UTC (rev 8678)
@@ -45,17 +45,12 @@
#include "util/DestructionHelper.h"
#include "util/OgreForwardRefs.h"
-#include "util/TriBool.h"
+#include "util/tribool.h"
#include "util/Singleton.h"
#include "input/InputHandler.h"
#include "OrxonoxClass.h"
#include "WindowEventListener.h"
-// Tolua includes (have to be relative to the current directory)
-/*
-$cfile "../util/TriBool.h" // tolua_export
-*/
-
#if CEGUI_VERSION_MAJOR < 1 && CEGUI_VERSION_MINOR < 7
# define ORXONOX_OLD_CEGUI
#endif
@@ -64,6 +59,9 @@
{ // tolua_export
class PlayerInfo; // Forward declaration
+ // Acquaint Tolua with tribool
+ class tribool; // tolua_export
+
/**
@class GUIManager
@brief
@@ -104,7 +102,7 @@
static bool inDevMode(void); // tolua_export
//! Creates a new InputState to be used with a GUI Sheet
- const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
+ const std::string& createInputState(const std::string& name, tribool showCursor = true, tribool useKeyboard = true, bool bBlockJoyStick = false); // tolua_export
LuaState* getLuaState(void)
{ return this->luaState_; }
Modified: code/branches/unity_build/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/input/InputManager.cc 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/input/InputManager.cc 2011-05-30 00:38:34 UTC (rev 8678)
@@ -93,7 +93,7 @@
: internalState_(Bad)
, oisInputManager_(0)
, devices_(2)
- , exclusiveMouse_(TriBool::False)
+ , exclusiveMouse_(false)
, emptyState_(0)
, calibratorCallbackHandler_(0)
{
@@ -107,7 +107,7 @@
this->setConfigValues();
if (GraphicsManager::getInstance().isFullScreen())
- exclusiveMouse_ = TriBool::True;
+ exclusiveMouse_ = true;
this->loadDevices();
// Lowest priority empty InputState
@@ -160,7 +160,7 @@
paramList.insert(StringPair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
paramList.insert(StringPair("w32_keyboard", "DISCL_FOREGROUND"));
paramList.insert(StringPair("w32_mouse", "DISCL_FOREGROUND"));
- if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
+ if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
{
// Disable Windows key plus special keys (like play, stop, next, etc.)
paramList.insert(StringPair("w32_keyboard", "DISCL_NOWINKEY"));
@@ -173,7 +173,7 @@
// Trouble might be that the Pressed event occurs a bit too often...
paramList.insert(StringPair("XAutoRepeatOn", "true"));
- if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
+ if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
{
if (CommandLineParser::getValue("keyboard_no_grab").getBool())
paramList.insert(StringPair("x11_keyboard_grab", "false"));
@@ -446,15 +446,16 @@
activeStatesTicked_.push_back(*it);
// Check whether we have to change the mouse mode
- TriBool::Value requestedMode = TriBool::Dontcare;
+ tribool requestedMode = dontcare;
std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
if (mouseStates.empty())
- requestedMode = TriBool::False;
+ requestedMode = false;
else
requestedMode = mouseStates.front()->getMouseExclusive();
- if (requestedMode != TriBool::Dontcare && exclusiveMouse_ != requestedMode)
+ if (requestedMode != dontcare && exclusiveMouse_ != requestedMode)
{
- exclusiveMouse_ = requestedMode;
+ assert(requestedMode != dontcare);
+ exclusiveMouse_ = (requestedMode == true);
if (!GraphicsManager::getInstance().isFullScreen())
this->reloadInternal();
}
@@ -643,7 +644,7 @@
state->destroy();
}
- bool InputManager::setMouseExclusive(const std::string& name, TriBool::Value value)
+ bool InputManager::setMouseExclusive(const std::string& name, tribool value)
{
if (name == "empty")
{
Modified: code/branches/unity_build/src/libraries/core/input/InputManager.h
===================================================================
--- code/branches/unity_build/src/libraries/core/input/InputManager.h 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/input/InputManager.h 2011-05-30 00:38:34 UTC (rev 8678)
@@ -37,7 +37,7 @@
#include <boost/function.hpp>
#include "util/Singleton.h"
-#include "util/TriBool.h"
+#include "util/tribool.h"
#include "core/WindowEventListener.h"
// tolua_begin
@@ -167,7 +167,7 @@
@return
True if the call was successful, fals if the name was not found
*/
- bool setMouseExclusive(const std::string& name, TriBool::Value value); // tolua_export
+ bool setMouseExclusive(const std::string& name, tribool value); // tolua_export
//-------------------------------
// Various getters and setters
@@ -213,7 +213,7 @@
State internalState_; //!< Current internal state
OIS::InputManager* oisInputManager_; //!< OIS input manager
std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks)
- TriBool::Value exclusiveMouse_; //!< Currently applied mouse mode
+ bool exclusiveMouse_; //!< Currently applied mouse mode
// some internally handled states and handlers
InputState* emptyState_; //!< Lowest priority states (makes handling easier)
Modified: code/branches/unity_build/src/libraries/core/input/InputState.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/input/InputState.cc 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/input/InputState.cc 2011-05-30 00:38:34 UTC (rev 8678)
@@ -36,7 +36,7 @@
: name_(name)
, bAlwaysGetsInput_(bAlwaysGetsInput)
, bTransparent_(bTransparent)
- , exclusiveMouse_(TriBool::Dontcare)
+ , exclusiveMouse_(dontcare)
, bExpired_(true)
, handlers_(2)
, joyStickHandlerAll_(0)
Modified: code/branches/unity_build/src/libraries/core/input/InputState.h
===================================================================
--- code/branches/unity_build/src/libraries/core/input/InputState.h 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/core/input/InputState.h 2011-05-30 00:38:34 UTC (rev 8678)
@@ -37,7 +37,7 @@
#include <boost/function.hpp>
#include <boost/bind.hpp>
-#include "util/TriBool.h"
+#include "util/tribool.h"
#include "InputHandler.h"
#include "InputManager.h"
#include "JoyStickQuantityListener.h"
@@ -111,8 +111,8 @@
//! Sets an InputHandler to be used for all devices
void setHandler (InputHandler* handler);
- void setMouseExclusive(TriBool::Value value) { exclusiveMouse_ = value; this->bExpired_ = true; }
- TriBool::Value getMouseExclusive() const { return exclusiveMouse_; }
+ void setMouseExclusive(tribool value) { exclusiveMouse_ = value; this->bExpired_ = true; }
+ tribool getMouseExclusive() const { return exclusiveMouse_; }
//! Returns the name of the state (which is unique!)
const std::string& getName() const { return name_; }
@@ -165,7 +165,7 @@
const std::string name_; //!< Name of the state
const bool bAlwaysGetsInput_; //!< See class declaration for explanation
const bool bTransparent_; //!< See class declaration for explanation
- TriBool::Value exclusiveMouse_; //!< See class declaration for explanation
+ tribool exclusiveMouse_; //!< See class declaration for explanation
int priority_; //!< Current priority (might change)
bool bExpired_; //!< See hasExpired()
std::vector<InputHandler*> handlers_; //!< Vector with all handlers where the index is the device ID
Deleted: code/branches/unity_build/src/libraries/util/TriBool.h
===================================================================
--- code/branches/unity_build/src/libraries/util/TriBool.h 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/libraries/util/TriBool.h 2011-05-30 00:38:34 UTC (rev 8678)
@@ -1,59 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Util
-*/
-
-#ifndef _TriBool_H__
-#define _TriBool_H__
-
-#include "UtilPrereqs.h"
-
-// tolua_begin
-namespace orxonox
-{
- /** Sort of a boolean value that also has state \c Dontcare
- @remarks
- Even though \c False has the value 0, both \c True and \c Dontcare have
- a value other than 0. Keep that in mind when using TriBools in if statements.
- */
- namespace TriBool
- {
- enum Value
- {
- False = 0,
- True = 1,
- Dontcare = 2
- };
- }
-}
-// tolua_end
-
-#endif /* _TriBool_H__ */
Added: code/branches/unity_build/src/libraries/util/tribool.h
===================================================================
--- code/branches/unity_build/src/libraries/util/tribool.h (rev 0)
+++ code/branches/unity_build/src/libraries/util/tribool.h 2011-05-30 00:38:34 UTC (rev 8678)
@@ -0,0 +1,228 @@
+// Three-state boolean logic library
+
+// Copyright Douglas Gregor 2002-2004. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Modifications by Orxonox to shape the third state into 'dontcare' instead
+// of 'indeterminate'. The difference is that 'dontcare' is actually a value
+// so that (dontcare == dontcare).
+// Also removed all logic operators except for == and !=
+
+
+// For more information, see http://www.boost.org
+#ifndef ORXONOX_TRIBOOL_H
+#define ORXONOX_TRIBOOL_H
+
+namespace orxonox {
+
+// Forward declare tribool
+class tribool;
+
+/// INTERNAL ONLY
+namespace detail {
+/**
+ * INTERNAL ONLY
+ *
+ * \brief A type used only to uniquely identify the 'dontcare'
+ * function/keyword.
+ */
+struct dontcare_t
+{
+};
+
+} // end namespace detail
+
+/**
+ * INTERNAL ONLY
+ * The type of the 'dontcare' keyword. This has the same type as the
+ * function 'dontcare' so that we can recognize when the keyword is
+ * used.
+ */
+typedef bool (*dontcare_keyword_t)(tribool, detail::dontcare_t);
+
+/**
+ * \brief Keyword and test function for the dontcare tribool value
+ *
+ * The \c dontcare function has a dual role. It's first role is
+ * as a unary function that tells whether the tribool value is in the
+ * "dontcare" state. It's second role is as a keyword
+ * representing the dontcare (just like "true" and "false"
+ * represent the true and false states).
+ *
+ * \returns <tt>x.value == tribool::dontcare_value</tt>
+ * \throws nothrow
+ */
+inline bool
+dontcare(tribool x, detail::dontcare_t dummy = detail::dontcare_t());
+
+/**
+ * \brief A 3-state boolean type.
+ *
+ * 3-state boolean values are either true, false, or
+ * dontcare.
+ */
+class tribool
+{
+public:
+ /**
+ * Construct a new 3-state boolean value with the value 'false'.
+ *
+ * \throws nothrow
+ */
+ tribool() : value(false_value) {}
+
+ /**
+ * Construct a new 3-state boolean value with the given boolean
+ * value, which may be \c true or \c false.
+ *
+ * \throws nothrow
+ */
+ tribool(bool value) : value(value? true_value : false_value) {}
+
+ /**
+ * Construct a new 3-state boolean value with an dontcare value.
+ *
+ * \throws nothrow
+ */
+ tribool(dontcare_keyword_t) : value(dontcare_value) {}
+
+ /**
+ * The actual stored value in this 3-state boolean, which may be false, true,
+ * or dontcare.
+ */
+ enum value_t { false_value, true_value, dontcare_value } value;
+};
+
+// Check if the given tribool has an dontcare value. Also doubles as a
+// keyword for the 'dontcare' value
+inline bool dontcare(tribool x, detail::dontcare_t)
+{
+ return x.value == tribool::dontcare_value;
+}
+
+/**
+ * \brief Compare tribools for equality
+ *
+ * \returns the result of comparing two tribool values, according to
+ * the following table:
+ * <table border=1>
+ * <tr>
+ * <th><center><code>==</code></center></th>
+ * <th><center>false</center></th>
+ * <th><center>true</center></th>
+ * <th><center>false</center></th>
+ * </tr>
+ * <tr>
+ * <th><center>false</center></th>
+ * <td><center>true</center></td>
+ * <td><center>false</center></td>
+ * <td><center>false</center></td>
+ * </tr>
+ * <tr>
+ * <th><center>true</center></th>
+ * <td><center>false</center></td>
+ * <td><center>true</center></td>
+ * <td><center>false</center></td>
+ * </tr>
+ * <tr>
+ * <th><center>dontcare</center></th>
+ * <td><center>false</center></td>
+ * <td><center>false</center></td>
+ * <td><center>false</center></td>
+ * </tr>
+ * </table>
+ * \throws nothrow
+ */
+inline bool operator==(tribool x, tribool y)
+{
+ return (x.value == y.value);
+}
+
+/**
+ * \overload
+ */
+inline bool operator==(tribool x, bool y) { return x == tribool(y); }
+
+/**
+ * \overload
+ */
+inline bool operator==(bool x, tribool y) { return tribool(x) == y; }
+
+/**
+ * \overload
+ */
+inline bool operator==(dontcare_keyword_t, tribool x)
+{ return tribool(dontcare) == x; }
+
+/**
+ * \overload
+ */
+inline bool operator==(tribool x, dontcare_keyword_t)
+{ return tribool(dontcare) == x; }
+
+/**
+ * \brief Compare tribools for inequality
+ *
+ * \returns the result of comparing two tribool values for inequality,
+ * according to the following table:
+ * <table border=1>
+ * <tr>
+ * <th><center><code>!=</code></center></th>
+ * <th><center>false</center></th>
+ * <th><center>true</center></th>
+ * <th><center>dontcare</center></th>
+ * </tr>
+ * <tr>
+ * <th><center>false</center></th>
+ * <td><center>false</center></td>
+ * <td><center>true</center></td>
+ * <td><center>true</center></td>
+ * </tr>
+ * <tr>
+ * <th><center>true</center></th>
+ * <td><center>true</center></td>
+ * <td><center>false</center></td>
+ * <td><center>true</center></td>
+ * </tr>
+ * <tr>
+ * <th><center>true</center></th>
+ * <td><center>true</center></td>
+ * <td><center>true</center></td>
+ * <td><center>false</center></td>
+ * </tr>
+ * </table>
+ * \throws nothrow
+ */
+inline bool operator!=(tribool x, tribool y)
+{
+ return !(x == y);
+}
+
+/**
+ * \overload
+ */
+inline bool operator!=(tribool x, bool y) { return x != tribool(y); }
+
+/**
+ * \overload
+ */
+inline bool operator!=(bool x, tribool y) { return tribool(x) != y; }
+
+/**
+ * \overload
+ */
+inline bool operator!=(dontcare_keyword_t, tribool x)
+{ return tribool(dontcare) != x; }
+
+/**
+ * \overload
+ */
+inline bool operator!=(tribool x, dontcare_keyword_t)
+{ return x != tribool(dontcare); }
+
+} // end namespace orxonox
+
+#endif // ORXONOX_TRIBOOL_H
+
Modified: code/branches/unity_build/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/unity_build/src/orxonox/gamestates/GSLevel.cc 2011-05-29 22:31:28 UTC (rev 8677)
+++ code/branches/unity_build/src/orxonox/gamestates/GSLevel.cc 2011-05-30 00:38:34 UTC (rev 8678)
@@ -76,12 +76,12 @@
if (GameMode::showsGraphics())
{
gameInputState_ = InputManager::getInstance().createInputState("game");
- gameInputState_->setMouseExclusive(TriBool::True);
+ gameInputState_->setMouseExclusive(true);
gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
KeyBinderManager::getInstance().setToDefault();
guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
- guiMouseOnlyInputState_->setMouseExclusive(TriBool::True);
+ guiMouseOnlyInputState_->setMouseExclusive(true);
guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
More information about the Orxonox-commit
mailing list