Index: /code/trunk/cmake/CompilerConfigGCC.cmake
===================================================================
--- /code/trunk/cmake/CompilerConfigGCC.cmake	(revision 8728)
+++ /code/trunk/cmake/CompilerConfigGCC.cmake	(revision 8729)
@@ -43,4 +43,11 @@
 IF(_compare_result GREATER -1)
   SET(PCH_COMPILER_SUPPORT TRUE)
+ENDIF()
+
+# __COUNTER__ macro was only added in GCC 4.3
+# It might be required to make full build units work
+COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.3.0" _compare_result)
+IF(_compare_result GREATER -1)
+  SET(HAVE_COUNTER_MACRO TRUE)
 ENDIF()
 
Index: /code/trunk/cmake/CompilerConfigMSVC.cmake
===================================================================
--- /code/trunk/cmake/CompilerConfigMSVC.cmake	(revision 8728)
+++ /code/trunk/cmake/CompilerConfigMSVC.cmake	(revision 8729)
@@ -33,4 +33,8 @@
 # Orxonox only supports MSVC 8 and above, which gets asserted above
 SET(PCH_COMPILER_SUPPORT TRUE)
+
+# __COUNTER__ macro has been around since VS 2005
+# It might be required to make full build units work
+SET(HAVE_COUNTER_MACRO TRUE)
 
 
Index: /code/trunk/cmake/tools/BuildUnits.cmake
===================================================================
--- /code/trunk/cmake/tools/BuildUnits.cmake	(revision 8729)
+++ /code/trunk/cmake/tools/BuildUnits.cmake	(revision 8729)
@@ -0,0 +1,146 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        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
+ #
+
+FUNCTION(GENERATE_BUILD_UNITS _target_name _all_files_var)
+  SET(_source_files)
+  SET(_total_file_count 0)
+
+  # Count the number of actual C++ source files
+  FOREACH(_file ${${_all_files_var}})
+    # Only look at C++ source files
+    IF(_file MATCHES "\\.(cpp|cc|cxx)$")
+      # Some files might be marked as not to compile at all
+      GET_SOURCE_FILE_PROPERTY(_skip1 ${_file} HEADER_FILE_ONLY)
+      GET_SOURCE_FILE_PROPERTY(_skip2 ${_file} EXCLUDE_FROM_BUILD_UNITS)
+      IF(NOT _skip1 AND NOT _skip2)
+        GET_SOURCE_FILE_PROPERTY(_size ${_file} BUILD_UNIT_SIZE)
+        IF(NOT _size)
+          SET(_size 1)
+        ENDIF()
+        # Append file AND size to the list (like storing an std::pair)
+        LIST(APPEND _source_files ${_file} ${_size})
+        MATH(EXPR _total_file_count "${_total_file_count} + ${_size}")
+        # Don't compile
+        SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE)
+      ENDIF()
+    ENDIF()
+  ENDFOREACH(_file)
+
+  # Get number of build units we have to make. The default is NR_OF_BUILD_UNITS
+  # However we can specify different values in a config file
+  SET(_config ${BUILD_UNITS_CONFIG_${NR_OF_BUILD_UNITS}_THREADS})
+  SET(_nr_of_units)
+  IF(_config)
+    LIST(FIND _config ${_target_name} _index)
+    IF(NOT _index EQUAL -1)
+      # Nr of build units is the next element in the list (we assume it exists)
+      MATH(EXPR _index "${_index} + 1")
+      LIST(GET _config ${_index} _nr_of_units)
+    ENDIF()
+  ENDIF()
+  IF(NOT _nr_of_units)
+    # Use default as specified (e.g. "full4" --> 4) or 1 for externals
+    IF(_arg_ORXONOX_EXTERNAL)
+      SET(_nr_of_units 1)
+    ELSE()
+      SET(_nr_of_units ${NR_OF_BUILD_UNITS})
+    ENDIF()
+  ENDIF()
+
+  # Disable precompiled header files for targets with two or less build units
+  IF(_nr_of_units LESS 3)
+    SET(PCH_DISABLE_${_target_name} TRUE PARENT_SCOPE)
+  ENDIF()
+
+  SET(_remaining_files ${_total_file_count})
+  SET(_remaining_units ${_nr_of_units})
+  SET(_unit_nr 1)
+  # Loop counts back from ${_nr_of_units} to 1
+  FOREACH(_remaining_units RANGE ${_nr_of_units} 1 -1)
+    # Use integer division to get the current build unit size
+    MATH(EXPR _aimed_size "${_remaining_files} / ${_remaining_units}")
+
+    SET(_current_size 0)
+    SET(_current_unit)
+
+    SET(_file_index 0)
+    LIST(LENGTH _source_files _list_size)
+    WHILE(${_file_index} LESS ${_list_size} AND NOT ${_current_size} EQUAL ${_aimed_size})
+      # _source_files stores pairs of values (file followed by its size)
+      MATH(EXPR _size_index "${_file_index} + 1")
+      LIST(GET _source_files ${_file_index} _file)
+      LIST(GET _source_files ${_size_index} _size)
+
+      MATH(EXPR _new_size "${_current_size} + ${_size}")
+      IF(${_new_size} GREATER ${_aimed_size})
+        # Try next file in list (jump 2 because pairs are stored)
+        MATH(EXPR _file_index "${_file_index} + 2")
+      ELSE()
+        SET(_current_size ${_new_size})
+        LIST(APPEND _current_unit ${_file})
+        # Remove from _source_files list
+        LIST(REMOVE_AT _source_files ${_file_index} ${_size_index})
+        MATH(EXPR _list_size "${_list_size} - 2")
+      ENDIF()
+    ENDWHILE()
+
+    # Finalise
+    LIST(LENGTH _current_unit _nr_of_included_files)
+    IF(_nr_of_included_files EQUAL 1)
+      # If unit consists of one file, we can compile it the old fashioned way
+      SET_SOURCE_FILES_PROPERTIES(${_current_unit} PROPERTIES HEADER_FILE_ONLY FALSE)
+    ELSEIF(_nr_of_included_files GREATER 1)
+      # Assemble unit by writing some #include statements
+      SET(_include_string)
+      FOREACH(_file ${_current_unit})
+        SET(_include_string "${_include_string}#include \"${_file}\"\n")
+      ENDFOREACH(_file)
+
+      # Generate the filename
+      IF(NOT _nr_of_units EQUAL 1)
+        SET(_suffix ${_unit_nr})
+      ENDIF()
+      SET(_unit_file ${CMAKE_CURRENT_BINARY_DIR}/${_target_name}BuildUnit${_suffix}.cc)
+      # Only write if content has changed (avoids recompile)
+      IF(EXISTS ${_unit_file})
+        FILE(READ ${_unit_file} _file_include_string)
+      ENDIF()
+      IF(NOT _include_string STREQUAL "${_file_include_string}")
+        FILE(WRITE ${_unit_file} "${_include_string}")
+      ENDIF()
+
+      LIST(APPEND _build_units ${_unit_file})
+
+      # Increase file name counter
+      MATH(EXPR _unit_nr "${_unit_nr} + 1")
+    ENDIF()
+
+    # Compute remaining files
+    MATH(EXPR _remaining_files "${_remaining_files} - ${_current_size}")
+  ENDFOREACH(_remaining_units)
+
+  # Add units to list of source files (function, not macro --> parent scope)
+  # Do this ONCE because parent scope changes will NOT be visible here
+  SET(${_all_files_var} ${${_all_files_var}} ${_build_units} PARENT_SCOPE)
+
+ENDFUNCTION(GENERATE_BUILD_UNITS)
Index: /code/trunk/cmake/tools/GenerateToluaBindings.cmake
===================================================================
--- /code/trunk/cmake/tools/GenerateToluaBindings.cmake	(revision 8728)
+++ /code/trunk/cmake/tools/GenerateToluaBindings.cmake	(revision 8729)
@@ -49,16 +49,21 @@
   SET(_tolua_pkgfile "${CMAKE_CURRENT_BINARY_DIR}/tolua.pkg")
   SET(_tolua_cxxfile "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.cc")
-  SET(_tolua_hfile   "${CMAKE_BINARY_DIR}/src/toluabind/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.h")
+  #SET(_tolua_hfile   "${CMAKE_BINARY_DIR}/src/toluabind/${CMAKE_CFG_INTDIR}/ToluaBind${_tolua_package}.h")
 
   SET(${_target_source_files}
     ${${_target_source_files}}
     ${_tolua_cxxfile}
-    ${_tolua_hfile}
     PARENT_SCOPE
   )
 
-  # Disable annoying GCC warnings
   IF(CMAKE_COMPILER_IS_GNU)
+    # Disable annoying GCC warnings
     SET_SOURCE_FILES_PROPERTIES(${_tolua_cxxfile} PROPERTIES COMPILE_FLAGS "-w")
+  ENDIF()
+
+  IF(MSVC)
+    # Including the file in a build unit is impossible because CMAKE_CFG_INTDIR
+    # exands to an expression that the compiler doesn't understand
+    SET_SOURCE_FILES_PROPERTIES(${_tolua_cxxfile} PROPERTIES EXCLUDE_FROM_BUILD_UNITS TRUE)
   ENDIF()
 
@@ -70,11 +75,16 @@
   ENDFOREACH(_tolua_inputfile)
 
+  IF(TOLUA_PARSER_HOOK_SCRIPT)
+    # Hook scripts may contain functions that act as Tolua hooks
+    SET(_hook_script -L "${TOLUA_PARSER_HOOK_SCRIPT}")
+  ENDIF()
+
   ADD_CUSTOM_COMMAND(
-    OUTPUT ${_tolua_cxxfile} ${_tolua_hfile}
+    OUTPUT ${_tolua_cxxfile}
     COMMAND toluaapp_orxonox -n ${_tolua_package}
                              -w ${CMAKE_CURRENT_SOURCE_DIR}
                              -o ${_tolua_cxxfile}
-                             -H ${_tolua_hfile}
                              -s ${TOLUA_PARSER_SOURCE}
+                                ${_hook_script}
                                 ${_tolua_pkgfile}
     DEPENDS           ${TOLUA_PARSER_DEPENDENCIES}
Index: /code/trunk/cmake/tools/SourceFileUtilities.cmake
===================================================================
--- /code/trunk/cmake/tools/SourceFileUtilities.cmake	(revision 8728)
+++ /code/trunk/cmake/tools/SourceFileUtilities.cmake	(revision 8729)
@@ -25,8 +25,8 @@
  #                             adds the current directory.
  #                             Also compiles multiple source files into a single
- #                             one by including them
- #                             Use COMPILATION_[BEGIN|END] in
+ #                             translation unit (faster)
+ #                             Use [END_]BUILD_UNIT in
  #                             [ADD|SET]_SOURCE_FILES and specify the name of
- #                             the new source file after COMPILATION_BEGIN
+ #                             the new source file after BUILD_UNIT
  #    GET_ALL_HEADER_FILES   - Finds all header files recursively.
  #    GENERATE_SOURCE_GROUPS - Set Visual Studio source groups.
@@ -36,5 +36,5 @@
   SET(_source_files)
   FOREACH(_file ${ARGN})
-    IF(_file MATCHES "^(COMPILATION_BEGIN|COMPILATION_END)$")
+    IF(_file MATCHES "^(BUILD_UNIT|END_BUILD_UNIT)$")
       # Append keywords verbatim
       LIST(APPEND _source_files ${_file})
Index: /code/trunk/cmake/tools/TargetUtilities.cmake
===================================================================
--- /code/trunk/cmake/tools/TargetUtilities.cmake	(revision 8728)
+++ /code/trunk/cmake/tools/TargetUtilities.cmake	(revision 8729)
@@ -40,4 +40,5 @@
  #      NO_INSTALL:        Do not install the target at all
  #      NO_VERSION:        Prevents adding any version to a target
+ #      NO_BUILD_UNITS:    Disables automatic (full) build units
  #
  #    Lists:
@@ -54,4 +55,7 @@
  #      PCH_EXCLUDE:       Source files to be excluded from PCH support
  #      OUTPUT_NAME:       If you want a different name than the target name
+ #      EXCLUDE_FROM_BUILD_UNITS: Specifies files that are not put into
+ #                         automatic (full) build units. They can still
+ #                         explicitely be included in a BUILD_UNIT (partial)
  #  Note:
  #    This function also installs the target!
@@ -62,4 +66,5 @@
  #
 
+INCLUDE(BuildUnits)
 INCLUDE(CMakeDependentOption)
 INCLUDE(CapitaliseName)
@@ -87,44 +92,52 @@
   SET(_switches   FIND_HEADER_FILES  EXCLUDE_FROM_ALL  ORXONOX_EXTERNAL
                   NO_DLL_INTERFACE   NO_SOURCE_GROUPS  PCH_NO_DEFAULT 
-                  NO_INSTALL         NO_VERSION        ${_additional_switches})
+                  NO_INSTALL         NO_VERSION        NO_BUILD_UNITS
+                  ${_additional_switches})
   SET(_list_names LINK_LIBRARIES     VERSION           SOURCE_FILES
                   DEFINE_SYMBOL      TOLUA_FILES       PCH_FILE
                   PCH_EXCLUDE        OUTPUT_NAME       LINK_LIBS_LINUX
-                  LINK_LIBS_WIN32    LINK_LIBS_APPLE   LINK_LIBS_UNIX)
+                  LINK_LIBS_WIN32    LINK_LIBS_APPLE   LINK_LIBS_UNIX
+                  EXCLUDE_FROM_BUILD_UNITS)
 
   PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN})
 
-  # Process source files with support for compilations
+  # Process source files with support for build units
   # Note: All file paths are relative to the root source directory, even the
-  #       name of the compilation file.
+  #       name of the build unit.
   SET(_${_target_name}_source_files)
-  SET(_get_compilation_file FALSE)
-  SET(_add_to_compilation FALSE)
+  SET(_get_build_unit_file FALSE)
+  SET(_add_to_build_unit FALSE)
   FOREACH(_file ${_arg_SOURCE_FILES})
-    IF(_file STREQUAL "COMPILATION_BEGIN")
-      # Next file is the name of the compilation
-      SET(_get_compilation_file TRUE)
-    ELSEIF(_file STREQUAL "COMPILATION_END")
-      IF(NOT _compilation_file)
-        MESSAGE(FATAL_ERROR "No name provided for source file compilation")
-      ENDIF()
-      IF(NOT DISABLE_COMPILATIONS)
-        IF(NOT _compilation_include_string)
-          MESSAGE(STATUS "Warning: Empty source file compilation!")
-        ENDIF()
-        IF(EXISTS ${_compilation_file})
-          FILE(READ ${_compilation_file} _include_string_file)
-        ENDIF()
-        IF(NOT _compilation_include_string STREQUAL "${_include_string_file}")
-          FILE(WRITE ${_compilation_file} "${_compilation_include_string}")
-        ENDIF()
-        LIST(APPEND _${_target_name}_source_files ${_compilation_file})
-      ENDIF()
-      SET(_add_to_compilation FALSE)
-    ELSEIF(_get_compilation_file)
-      SET(_compilation_file ${CMAKE_BINARY_DIR}/${_file})
-      SET(_get_compilation_file FALSE)
-      SET(_add_to_compilation TRUE)
-      SET(_compilation_include_string)
+    IF(_file STREQUAL "BUILD_UNIT")
+      # Next file is the name of the build unit
+      SET(_get_build_unit_file TRUE)
+    ELSEIF(_file STREQUAL "END_BUILD_UNIT")
+      IF(NOT _build_unit_file)
+        MESSAGE(FATAL_ERROR "No name provided for build unit")
+      ENDIF()
+      IF(ENABLE_BUILD_UNITS)
+        IF(NOT _build_unit_include_string)
+          MESSAGE(STATUS "Warning: Empty build unit!")
+        ENDIF()
+        IF(EXISTS ${_build_unit_file})
+          FILE(READ ${_build_unit_file} _include_string_file)
+        ENDIF()
+        IF(NOT _build_unit_include_string STREQUAL "${_include_string_file}")
+          FILE(WRITE ${_build_unit_file} "${_build_unit_include_string}")
+        ENDIF()
+        LIST(APPEND _${_target_name}_source_files ${_build_unit_file})
+        LIST(APPEND _${_target_name}_build_units ${_build_unit_file})
+        # Store the number of files included. May be used for full build units.
+        SET_SOURCE_FILES_PROPERTIES(${_build_unit_file}
+          PROPERTIES BUILD_UNIT_SIZE "${_build_unit_count}")
+      ENDIF()
+      SET(_add_to_build_unit FALSE)
+    ELSEIF(_get_build_unit_file)
+      # Note: ${_file} is relative to the binary directory
+      SET(_build_unit_file ${CMAKE_BINARY_DIR}/${_file})
+      SET(_get_build_unit_file FALSE)
+      SET(_add_to_build_unit TRUE)
+      SET(_build_unit_include_string)
+      SET(_build_unit_count "0")
     ELSE()
       # Default, add source file
@@ -146,8 +159,9 @@
       LIST(APPEND _${_target_name}_source_files ${_file})
 
-      # Handle compilations
-      IF(_add_to_compilation AND NOT DISABLE_COMPILATIONS)
+      # Handle build units
+      IF(_add_to_build_unit AND ENABLE_BUILD_UNITS)
         IF(_file MATCHES "\\.(c|cc|cpp|cxx)$")
-          SET(_compilation_include_string "${_compilation_include_string}#include \"${_file}\"\n")
+          SET(_build_unit_include_string "${_build_unit_include_string}#include \"${_file}\"\n")
+          MATH(EXPR _build_unit_count "1 + ${_build_unit_count}")
         ENDIF()
         # Don't compile these files, even if they are source files
@@ -183,4 +197,18 @@
   ENDIF()
 
+  # Mark files to be excluded from build units
+  IF(_arg_EXCLUDE_FROM_BUILD_UNITS)
+    SET_SOURCE_FILES_PROPERTIES(${_arg_EXCLUDE_FROM_BUILD_UNITS}
+      PROPERTIES EXCLUDE_FROM_BUILD_UNITS TRUE)
+  ENDIF()
+
+  # Full build units
+  IF(ENABLE_BUILD_UNITS AND NOT _arg_NO_BUILD_UNITS)
+    # Use full build units even in partial mode for externals
+    IF(ENABLE_BUILD_UNITS MATCHES "full" OR _arg_ORXONOX_EXTERNAL)
+      GENERATE_BUILD_UNITS(${_target_name} _${_target_name}_files)
+    ENDIF()
+  ENDIF()
+
   # First part (pre target) of precompiled header files
   IF(PCH_COMPILER_SUPPORT AND _arg_PCH_FILE)
@@ -196,5 +224,5 @@
     MARK_AS_ADVANCED(PCH_ENABLE_${_target_name_upper})
 
-    IF(PCH_ENABLE_${_target_name_upper})
+    IF(PCH_ENABLE_${_target_name_upper} AND NOT PCH_DISABLE_${_target_name})
       PRECOMPILED_HEADER_FILES_PRE_TARGET(${_target_name} ${_arg_PCH_FILE} _${_target_name}_files EXCLUDE ${_arg_PCH_EXCLUDE})
     ENDIF()
@@ -344,5 +372,5 @@
 
   # Second part of precompiled header files
-  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE)
+  IF(PCH_COMPILER_SUPPORT AND PCH_ENABLE_${_target_name_upper} AND _arg_PCH_FILE AND NOT PCH_DISABLE_${_target_name})
     PRECOMPILED_HEADER_FILES_POST_TARGET(${_target_name} ${_arg_PCH_FILE})
   ENDIF()
Index: /code/trunk/data/gui/scripts/ChatBox-inputonly.lua
===================================================================
--- /code/trunk/data/gui/scripts/ChatBox-inputonly.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/ChatBox-inputonly.lua	(revision 8729)
@@ -1,5 +1,5 @@
 -- ChatBox-inputonly.lua
 
-local P = createMenuSheet("ChatBox-inputonly", true, TriBool.True, TriBool.Dontcare, false)
+local P = createMenuSheet("ChatBox-inputonly", true, tribool(true), tribool(dontcare), false)
 return P
 
Index: /code/trunk/data/gui/scripts/ChatBox.lua
===================================================================
--- /code/trunk/data/gui/scripts/ChatBox.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/ChatBox.lua	(revision 8729)
@@ -1,5 +1,5 @@
 -- ChatBox.lua
 
-local P = createMenuSheet("ChatBox", true, TriBool.True, TriBool.Dontcare, false)
+local P = createMenuSheet("ChatBox", true, tribool(true), tribool(dontcare), false)
 
 function P.ChatBoxCloseButton_clicked(e)
Index: /code/trunk/data/gui/scripts/MenuSheet.lua
===================================================================
--- /code/trunk/data/gui/scripts/MenuSheet.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/MenuSheet.lua	(revision 8729)
@@ -11,10 +11,10 @@
 -- Parameters:
 -- Except for _name, you can provide nil. Then the default value will be used.
--- For _tShowCusor and _tUseKeyboard you can specify TriBool.Dontcare if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
+-- For _tShowCusor and _tUseKeyboard you can specify tribool(dontcare) if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
 function P.new(_name, _bHidePrevious, _tShowCursor, _tUseKeyboard, _bBlockJoyStick)
     local newSheet = GUISheet.new(_name)
     newSheet.bHidePrevious  = handleDefArg(_bHidePrevious,  true)
-    newSheet.tShowCursor    = handleDefArg(_tShowCusor,     TriBool.True)
-    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.True)
+    newSheet.tShowCursor    = handleDefArg(_tShowCusor,     tribool(true))
+    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   tribool(true))
     newSheet.bBlockJoyStick = handleDefArg(_bBlockJoyStick, false)
 
Index: /code/trunk/data/gui/scripts/MiscConfigMenu.lua
===================================================================
--- /code/trunk/data/gui/scripts/MiscConfigMenu.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/MiscConfigMenu.lua	(revision 8729)
@@ -1,5 +1,5 @@
 -- MiscConfigMenu.lua
 
-local P = createMenuSheet("MiscConfigMenu", true, TriBool.True, TriBool.True)
+local P = createMenuSheet("MiscConfigMenu", true, tribool(true), tribool(true))
 
 P.commandList = {}
Index: /code/trunk/data/gui/scripts/NotificationLayer.lua
===================================================================
--- /code/trunk/data/gui/scripts/NotificationLayer.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/NotificationLayer.lua	(revision 8729)
@@ -1,5 +1,5 @@
 -- NotificationLayer.lua
 
-local P = createMenuSheet("NotificationLayer", true, TriBool.True, TriBool.True)
+local P = createMenuSheet("NotificationLayer", true, tribool(true), tribool(true))
 
 P.queueList = {}
Index: /code/trunk/data/gui/scripts/SheetManager.lua
===================================================================
--- /code/trunk/data/gui/scripts/SheetManager.lua	(revision 8728)
+++ /code/trunk/data/gui/scripts/SheetManager.lua	(revision 8729)
@@ -81,5 +81,5 @@
 
     if bNoInput == true then
-        menuSheet.tShowCursor = TriBool.Dontcare
+        menuSheet.tShowCursor = tribool(dontcare)
     end
 
@@ -110,8 +110,8 @@
     end
 
-    -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
-    if menuSheet.tShowCursor == TriBool.True then
+    -- Only change cursor situation if menuSheet.tShowCursor ~= tribool(dontcare)
+    if menuSheet.tShowCursor == tribool(true) then
         showCursor()
-    elseif menuSheet.tShowCursor == TriBool.False then
+    elseif menuSheet.tShowCursor == tribool(false) then
         hideCursor()
     end
@@ -186,9 +186,9 @@
     -- CURSOR SHOWING
     local i = activeMenuSheets.size
-    -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
-    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do
+    -- Find top most sheet that doesn't have tShowCusor == tribool(dontcare)
+    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == tribool(dontcare) do
         i = i - 1
     end
-    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then
+    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == tribool(true) then
         showCursor()
     else
@@ -256,13 +256,13 @@
 function windowResized(e)
     for name, sheet in pairs(loadedSheets) do
-        if orxonox.GraphicsManager:getInstance():isFullScreen() or sheet.tShowCursor == TriBool.False then
-            inputMgr:setMouseExclusive(sheet.inputState, TriBool.True)
+        if orxonox.GraphicsManager:getInstance():isFullScreen() or sheet.tShowCursor == tribool(false) then
+            inputMgr:setMouseExclusive(sheet.inputState, tribool(true))
         else
-            inputMgr:setMouseExclusive(sheet.inputState, TriBool.False)
+            inputMgr:setMouseExclusive(sheet.inputState, tribool(false))
         end
     end
     local sheetTuple = activeMenuSheets[activeMenuSheets.size]
     if sheetTuple then
-        if orxonox.GraphicsManager:getInstance():isFullScreen() and sheetTuple.sheet.tShowCursor ~= TriBool.False then
+        if orxonox.GraphicsManager:getInstance():isFullScreen() and sheetTuple.sheet.tShowCursor ~= tribool(false) then
             showCursor()
         else
Index: /code/trunk/data/lua/Tools.lua
===================================================================
--- /code/trunk/data/lua/Tools.lua	(revision 8728)
+++ /code/trunk/data/lua/Tools.lua	(revision 8729)
@@ -16,9 +16,5 @@
 end
 
--- Short forms for TriBool
-TriBool =
-{
-    True     = orxonox.TriBool.True,
-    False    = orxonox.TriBool.False,
-    Dontcare = orxonox.TriBool.Dontcare
-}
+-- Shortcuts for tribool
+tribool  = orxonox.tribool
+dontcare = orxonox.dontcare_keyword_t()
Index: /code/trunk/src/BuildUnitsConfigGCC.cmake
===================================================================
--- /code/trunk/src/BuildUnitsConfigGCC.cmake	(revision 8729)
+++ /code/trunk/src/BuildUnitsConfigGCC.cmake	(revision 8729)
@@ -0,0 +1,74 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        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
+ #  Description:
+ #    Configures the number of build units per library
+ #
+
+SET(BUILD_UNITS_CONFIG_1_THREADS
+  util              1
+  core              2
+  network           1
+  tools             1
+  orxonox           8
+  designtools       1
+  notifications     1
+  objects           2
+  overlays          2
+  pickup            2
+  pong              1
+  questsystem       1
+  weapons           1
+)
+
+SET(BUILD_UNITS_CONFIG_2_THREADS ${BUILD_UNITS_CONFIG_1_THREADS})
+
+SET(BUILD_UNITS_CONFIG_4_THREADS
+  util              1
+  core              4
+  network           2
+  tools             2
+  orxonox           8
+  designtools       1
+  notifications     1
+  objects           2
+  overlays          2
+  pickup            1
+  pong              1
+  questsystem       1
+  weapons           1
+)
+
+SET(BUILD_UNITS_CONFIG_8_THREADS
+  util              2
+  core              8
+  network           5
+  tools             3
+  orxonox           8
+  designtools       1
+  notifications     1
+  objects           3
+  overlays          3
+  pickup            2
+  pong              1
+  questsystem       3
+  weapons           3
+)
Index: /code/trunk/src/BuildUnitsConfigMSVC.cmake
===================================================================
--- /code/trunk/src/BuildUnitsConfigMSVC.cmake	(revision 8729)
+++ /code/trunk/src/BuildUnitsConfigMSVC.cmake	(revision 8729)
@@ -0,0 +1,88 @@
+ #
+ #             ORXONOX - the hottest 3D action shooter ever to exist
+ #                             > www.orxonox.net <
+ #
+ #        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
+ #  Description:
+ #    Configures the number of build units per library
+ #
+
+SET(BUILD_UNITS_CONFIG_1_THREADS
+  util              1
+  core              1
+  network           1
+  tools             1
+  orxonox           2 # Avoids running out of symbol adresses (fix with /bigobj)
+  designtools       1
+  notifications     1
+  objects           1
+  overlays          1
+  pickup            1
+  pong              1
+  questsystem       1
+  weapons           1
+)
+
+SET(BUILD_UNITS_CONFIG_2_THREADS
+  util              1
+  core              2
+  network           1
+  tools             1
+  orxonox           2
+  designtools       1
+  notifications     1
+  objects           2
+  overlays          1
+  pickup            1
+  pong              1
+  questsystem       1
+  weapons           1
+)
+
+SET(BUILD_UNITS_CONFIG_4_THREADS
+  util              2
+  core              4
+  network           2
+  tools             2
+  orxonox           4
+  designtools       1
+  notifications     1
+  objects           2
+  overlays          2
+  pickup            1
+  pong              1
+  questsystem       2
+  weapons           2
+)
+
+SET(BUILD_UNITS_CONFIG_8_THREADS
+  util              2
+  core              8
+  network           5
+  tools             3
+  orxonox           8
+  designtools       1
+  notifications     1
+  objects           3
+  overlays          3
+  pickup            2
+  pong              1
+  questsystem       3
+  weapons           3
+)
Index: /code/trunk/src/CMakeLists.txt
===================================================================
--- /code/trunk/src/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/CMakeLists.txt	(revision 8729)
@@ -65,8 +65,4 @@
       REMOVE_LINKER_FLAGS("-INCREMENTAL:YES" Debug)
       ADD_LINKER_FLAGS   ("-INCREMENTAL:NO"  Debug)
-    ENDIF()
-    IF(NOT DISABLE_COMPILATIONS)
-      # Compilations seem to generate 'memory leaks' with static variables
-      MESSAGE("Warning: You should disable Compilations when using VLD!")
     ENDIF()
   ENDIF()
@@ -149,10 +145,7 @@
 ################### Tolua Bind ##################
 
-# Create directory because the tolua application doesn't work otherwise
-IF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
-  FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
-ENDIF()
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/toluabind/${CMAKE_CFG_INTDIR})
+# Add hook script to the lua code that generates the bindings
+SET(TOLUA_PARSER_HOOK_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/libraries/core/ToluaInterfaceHook.lua)
+SET(TOLUA_PARSER_DEPENDENCIES ${TOLUA_PARSER_DEPENDENCIES} ${TOLUA_PARSER_HOOK_SCRIPT})
 
 ################ Sub Directories ################
Index: /code/trunk/src/OrxonoxConfig.cmake
===================================================================
--- /code/trunk/src/OrxonoxConfig.cmake	(revision 8728)
+++ /code/trunk/src/OrxonoxConfig.cmake	(revision 8729)
@@ -34,6 +34,31 @@
 ENDIF()
 
-# Global switch to disable multiple file compilations
-OPTION(DISABLE_COMPILATIONS "Global multi-file compilation switch" FALSE)
+# Global option to steer building muliple files as a single one
+# off/false: Turn off completely
+# partial:   Only combine files explicitly specified with BUILD_UNIT
+# full##:    Use ## source files per orxonox library and use manual build units
+#            for external dependencies. Example: full8 will in general use 8
+#            source files per library, but more specifically tries to occupy
+#            8 CPU threads.
+#            This is configured manually in BuildUnitsConfig.cmake
+SET(ENABLE_BUILD_UNITS "partial" CACHE STRING "Enables building multiple source files as one.")
+IF(ENABLE_BUILD_UNITS)
+  IF(NOT "${ENABLE_BUILD_UNITS}" STREQUAL "partial")
+    STRING(REGEX REPLACE "^full([1-9][0-9]?)$" "\\1" _nr_of_units "${ENABLE_BUILD_UNITS}")
+    IF("${_nr_of_units}" STREQUAL "${ENABLE_BUILD_UNITS}") # Regex match failed
+      MESSAGE(FATAL_ERROR "Unrecognised option for ENABLE_BUILD_UNITS: ${ENABLE_BUILD_UNITS}")
+    ELSE()
+      SET(NR_OF_BUILD_UNITS ${_nr_of_units})
+      IF(NOT HAVE_COUNTER_MACRO)
+        MESSAGE(WARNING "Your compiler doesn't support the __COUNTER__ macro. Full build units might not work!")
+      ENDIF()
+    ENDIF()
+  ENDIF()
+  IF(CMAKE_COMPILER_IS_GNU)
+    INCLUDE(BuildUnitsConfigGCC.cmake)
+  ELSEIF(MSVC)
+    INCLUDE(BuildUnitsConfigMSVC.cmake)
+  ENDIF()
+ENDIF()
 
 # Use WinMain() or main()?
Index: /code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt	(revision 8729)
@@ -1,5 +1,3 @@
 ADD_SOURCE_FILES(BULLET_FILES
-
-COMPILATION_BEGIN BulletCollisionCompilation.cpp
 
 	BroadphaseCollision/btAxisSweep3.cpp
@@ -84,12 +82,9 @@
 	NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
 	NarrowPhaseCollision/btPersistentManifold.cpp
+	NarrowPhaseCollision/btPolyhedralContactClipping.cpp
 	NarrowPhaseCollision/btRaycastCallback.cpp
 	NarrowPhaseCollision/btSubSimplexConvexCast.cpp
 	NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
 
-COMPILATION_END
-
-    # Raises compiler errors when compiled inside the compilation
-	NarrowPhaseCollision/btPolyhedralContactClipping.cpp
 
 	# Headers
Index: /code/trunk/src/external/bullet/BulletDynamics/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/bullet/BulletDynamics/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/bullet/BulletDynamics/CMakeLists.txt	(revision 8729)
@@ -1,5 +1,3 @@
 ADD_SOURCE_FILES(BULLET_FILES
-
-COMPILATION_BEGIN BulletDynamicsCompilation.cpp
 
 	Character/btKinematicCharacterController.cpp
@@ -25,6 +23,4 @@
 	Vehicle/btRaycastVehicle.cpp
 	Vehicle/btWheelInfo.cpp
-
-COMPILATION_END
 
 	# Headers
Index: /code/trunk/src/external/bullet/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/bullet/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/bullet/CMakeLists.txt	(revision 8729)
@@ -32,4 +32,6 @@
   VERSION
     2.78
+  EXCLUDE_FROM_BUILD_UNITS
+    BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp
   SOURCE_FILES
     ${BULLET_FILES}
Index: /code/trunk/src/external/bullet/LinearMath/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/bullet/LinearMath/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/bullet/LinearMath/CMakeLists.txt	(revision 8729)
@@ -1,12 +1,10 @@
 ADD_SOURCE_FILES(BULLET_FILES
 
-COMPILATION_BEGIN BulletLinearMathCompilation.cpp
 	btAlignedAllocator.cpp
 	btConvexHull.cpp
-    btConvexHullComputer.cpp
+	btConvexHullComputer.cpp
 	btGeometryUtil.cpp
 	btQuickprof.cpp
 	btSerializer.cpp
-COMPILATION_END
 
 	# Headers
@@ -15,5 +13,5 @@
 	btAlignedObjectArray.h
 	btConvexHull.h
-    btConvexHullComputer.h
+	btConvexHullComputer.h
 	btDefaultMotionState.h
 	btGeometryUtil.h
Index: /code/trunk/src/external/enet/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/enet/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/enet/CMakeLists.txt	(revision 8729)
@@ -29,5 +29,4 @@
     win32.h
 
-COMPILATION_BEGIN ENetCompilation.c
     callbacks.c
     compress.c
@@ -39,5 +38,4 @@
     unix.c
     win32.c
-COMPILATION_END
 )
 
Index: /code/trunk/src/external/ogreceguirenderer/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/ogreceguirenderer/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/ogreceguirenderer/CMakeLists.txt	(revision 8729)
@@ -23,9 +23,7 @@
   OgreCEGUITexture.h
 
-COMPILATION_BEGIN OgreCEGUIRendererCompilation.cpp
   OgreCEGUIRenderer.cpp
   OgreCEGUIResourceProvider.cpp
   OgreCEGUITexture.cpp
-COMPILATION_END
 )
 
Index: /code/trunk/src/external/ois/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/ois/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/ois/CMakeLists.txt	(revision 8729)
@@ -35,5 +35,4 @@
   OISPrereqs.h
 
-#COMPILATION_BEGIN OISCompilation.cpp
   OISEffect.cpp
   OISException.cpp
@@ -43,6 +42,6 @@
   OISKeyboard.cpp
   OISObject.cpp
-#COMPILATION_END
 )
+
 IF(WIN32)
   ADD_SUBDIRECTORY(win32)
@@ -56,4 +55,9 @@
 IF(MINGW)
   INCLUDE_DIRECTORIES(${WMI_INCLUDE_DIR})
+ENDIF()
+
+# Apple has problems with OIS and build units
+IF(APPLE)
+  SET(USE_BUILD_UNITS NO_BUILD_UNITS)
 ENDIF()
 
@@ -72,4 +76,5 @@
   LINK_LIBS_LINUX
     X11
+  ${USE_BUILD_UNITS}
   SOURCE_FILES
     ${OIS_FILES}
Index: /code/trunk/src/external/ois/linux/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/ois/linux/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/ois/linux/CMakeLists.txt	(revision 8729)
@@ -8,5 +8,4 @@
   LinuxPrereqs.h
 
-COMPILATION_BEGIN OISLinuxCompilation.cpp
   EventHelpers.cpp
   LinuxForceFeedback.cpp
@@ -15,4 +14,3 @@
   LinuxKeyboard.cpp
   LinuxMouse.cpp
-COMPILATION_END
 )
Index: /code/trunk/src/external/ois/mac/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/ois/mac/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/ois/mac/CMakeLists.txt	(revision 8729)
@@ -8,5 +8,4 @@
   MacPrereqs.h
 
-#COMPILATION_BEGIN OISMacCompilation.cpp
   MacHelpers.cpp
   MacHIDManager.cpp
@@ -15,4 +14,3 @@
   MacKeyboard.cpp
   MacMouse.cpp
-#COMPILATION_END
 )
Index: /code/trunk/src/external/ois/win32/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/ois/win32/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/ois/win32/CMakeLists.txt	(revision 8729)
@@ -7,5 +7,4 @@
   Win32Prereqs.h
 
-COMPILATION_BEGIN OISWin32Compilation.cpp
   Win32ForceFeedback.cpp
   Win32InputManager.cpp
@@ -13,4 +12,3 @@
   Win32KeyBoard.cpp
   Win32Mouse.cpp
-COMPILATION_END
 )
Index: /code/trunk/src/external/tinyxml/CMakeLists.txt
===================================================================
--- /code/trunk/src/external/tinyxml/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/external/tinyxml/CMakeLists.txt	(revision 8729)
@@ -24,5 +24,4 @@
   tinyxml.h
 
-COMPILATION_BEGIN TicppCompilation.cpp
   ticpp.cpp
   tinystr.cpp
@@ -30,5 +29,4 @@
   tinyxmlerror.cpp
   tinyxmlparser.cpp
-COMPILATION_END
 )
 
Index: /code/trunk/src/external/tolua/lua/basic.lua
===================================================================
--- /code/trunk/src/external/tolua/lua/basic.lua	(revision 8728)
+++ /code/trunk/src/external/tolua/lua/basic.lua	(revision 8729)
@@ -354,3 +354,5 @@
 end
 
-
+-- called after all the required C++ includes have been written
+function post_include_hook(package_name)
+end
Index: /code/trunk/src/external/tolua/lua/package.lua
===================================================================
--- /code/trunk/src/external/tolua/lua/package.lua	(revision 8728)
+++ /code/trunk/src/external/tolua/lua/package.lua	(revision 8729)
@@ -135,4 +135,6 @@
         i = i+1
     end
+
+    post_include_hook(self.name)
 
     output('\n')
Index: /code/trunk/src/libraries/core/CMakeLists.txt
===================================================================
--- /code/trunk/src/libraries/core/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/libraries/core/CMakeLists.txt	(revision 8729)
@@ -19,7 +19,9 @@
 
 SET_SOURCE_FILES(CORE_SRC_FILES
+
+#BUILD_UNIT CoreStableBuildUnit.cc
+  ClassTreeMask.cc
   CommandLineParser.cc
   ConfigValueContainer.cc
-  Core.cc
   DynLib.cc
   DynLibManager.cc
@@ -28,43 +30,40 @@
   GameMode.cc
   GameState.cc
-  GraphicsManager.cc
-  GUIManager.cc
+  Identifier.cc
   Language.cc
+  Loader.cc
   LuaState.cc
+  MetaObjectList.cc
+  Namespace.cc
+  NamespaceNode.cc
   ObjectListBase.cc
   OrxonoxClass.cc
-  Resource.cc
-
-  # hierarchy
-  Identifier.cc
-  MetaObjectList.cc
-
-  # level
-  BaseObject.cc
-  ClassTreeMask.cc
-  Loader.cc
-  Namespace.cc
-  NamespaceNode.cc
   Template.cc
-  XMLPort.cc
-
-COMPILATION_BEGIN ListenerCompilation.cc
   ViewportEventListener.cc
   WindowEventListener.cc
   XMLNameListener.cc
-COMPILATION_END
+  XMLPort.cc
+#END_BUILD_UNIT
 
-COMPILATION_BEGIN FilesystemCompilation.cc
+  BaseObject.cc
+  Core.cc
+
+BUILD_UNIT OgreBuildUnit.cc
+  GraphicsManager.cc
+  GUIManager.cc
+  Resource.cc
+END_BUILD_UNIT
+
+BUILD_UNIT FilesystemBuildUnit.cc
   command/ArgumentCompletionFunctions.cc
   ConfigFileManager.cc
   PathConfig.cc
-COMPILATION_END
+END_BUILD_UNIT
 
-  # multithreading
-  ThreadPool.cc
-COMPILATION_BEGIN ThreadCompilation.cc
+BUILD_UNIT ThreadBuildUnit.cc
   command/TclThreadManager.cc
   Thread.cc
-COMPILATION_END
+  ThreadPool.cc
+END_BUILD_UNIT
 )
 
Index: /code/trunk/src/libraries/core/CommandLineParser.cc
===================================================================
--- /code/trunk/src/libraries/core/CommandLineParser.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/CommandLineParser.cc	(revision 8729)
@@ -41,6 +41,4 @@
 namespace orxonox
 {
-    SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
-
     /**
     @brief
@@ -50,8 +48,6 @@
         so that you can have simple command line switches.
     */
-    void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
-    {
-        if (bParsingFile && this->bCommandLineOnly_)
-            ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
+    void CommandLineArgument::parse(const std::string& value)
+    {
         if (value_.getType() == MT_Type::Bool)
         {
@@ -116,19 +112,19 @@
     }
 
-    /**
-    @brief
-        Reads the command line parses the values of each argument.
-        It is then stored in the corresponding CommandLineArgument.
+    /** Parses the command line string for arguments and stores these.
     @note
         The reason that you have to provide the string to be parsed as
-        space separted list is because of argc and argv. If you only have
+        space separated list is because of argc and argv. If you only have
         a whole string, simply use getAllStrings() of SubString.
-    @param arguments
-        Vector of space separated strings.
-    @param bParsingFile
-        Parsing a file or the command line itself
-    */
-    void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
-    {
+    @param cmdLine
+        Command line string WITHOUT the execution path.
+    */
+    void CommandLineParser::_parse(const std::string& cmdLine)
+    {
+        std::vector<std::string> arguments;
+        SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
+        for (unsigned i = 0; i < tokens.size(); ++i)
+            arguments.push_back(tokens[i]);
+
         try
         {
@@ -177,5 +173,5 @@
                             if (!name.empty())
                             {
-                                checkFullArgument(name, value, bParsingFile);
+                                checkFullArgument(name, value);
                                 name.clear();
                                 assert(shortcut.empty());
@@ -183,5 +179,5 @@
                             else if (!shortcut.empty())
                             {
-                                checkShortcut(shortcut, value, bParsingFile);
+                                checkShortcut(shortcut, value);
                                 shortcut.clear();
                                 assert(name.empty());
@@ -222,10 +218,10 @@
             if (!name.empty())
             {
-                checkFullArgument(name, value, bParsingFile);
+                checkFullArgument(name, value);
                 assert(shortcut.empty());
             }
             else if (!shortcut.empty())
             {
-                checkShortcut(shortcut, value, bParsingFile);
+                checkShortcut(shortcut, value);
                 assert(name.empty());
             }
@@ -233,5 +229,5 @@
         catch (const ArgumentException& ex)
         {
-            COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
+            COUT(0) << "Could not parse command line: " << ex.what() << std::endl;
             COUT(0) << CommandLineParser::getUsageInformation() << std::endl;
             throw GeneralException("");
@@ -249,5 +245,5 @@
         Parsing a file or the command line itself
     */
-    void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
+    void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value)
     {
         std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
@@ -255,5 +251,5 @@
             ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
 
-        it->second->parse(value, bParsingFile);
+        it->second->parse(value);
     }
 
@@ -268,5 +264,5 @@
         Parsing a file or the command line itself
     */
-    void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
+    void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value)
     {
         std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
@@ -274,5 +270,5 @@
             ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
 
-        it->second->parse(value, bParsingFile);
+        it->second->parse(value);
     }
 
@@ -342,51 +338,3 @@
         }
     }
-
-    /**
-    @brief
-        Parses only the command line for CommandLineArguments.
-    */
-    void CommandLineParser::_parseCommandLine(const std::string& cmdLine)
-    {
-        std::vector<std::string> args;
-        SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
-        for (unsigned i = 0; i < tokens.size(); ++i)
-            args.push_back(tokens[i]);
-        this->_parse(args, false);
-    }
-
-    /**
-    @brief
-        Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
-    */
-    void CommandLineParser::_parseFile()
-    {
-        const std::string& filename = CommandLineParser::getValue("optionsFile").getString();
-
-        // look for additional arguments in given file or start.ini as default
-        // They will not overwrite the arguments given directly
-        std::ifstream file;
-        file.open((PathConfig::getConfigPathString() + filename).c_str());
-        std::vector<std::string> args;
-        if (file)
-        {
-            while (!file.eof())
-            {
-                std::string line;
-                std::getline(file, line);
-                line = removeTrailingWhitespaces(line);
-                //if (!(line[0] == '#' || line[0] == '%'))
-                //{
-                SubString tokens(line, " ", " ", false, '\\', true, '"', true, '\0', '\0', false, '#');
-                for (unsigned i = 0; i < tokens.size(); ++i)
-                    if (tokens[i][0] != '#')
-                        args.push_back(tokens[i]);
-                //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
-                //}
-            }
-            file.close();
-        }
-
-        _parse(args, true);
-    }
 }
Index: /code/trunk/src/libraries/core/CommandLineParser.h
===================================================================
--- /code/trunk/src/libraries/core/CommandLineParser.h	(revision 8728)
+++ /code/trunk/src/libraries/core/CommandLineParser.h	(revision 8729)
@@ -51,15 +51,8 @@
 #define SetCommandLineArgument(name, defaultValue) \
     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, defaultValue, false)
-#define SetCommandLineOnlyArgument(name, defaultValue) \
-    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, defaultValue, true)
+    = orxonox::CommandLineParser::addArgument(#name, defaultValue)
 #define SetCommandLineSwitch(name) \
     orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, false, false)
-#define SetCommandLineOnlySwitch(name) \
-    orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \
-    = orxonox::CommandLineParser::addArgument(#name, false, true)
-
+    = orxonox::CommandLineParser::addArgument(#name, false)
 
 namespace orxonox
@@ -106,16 +99,15 @@
 
         //! Returns the actual value of the argument. Can be equal to default value.
-        MultiType getValue() const { return value_; }
+        const MultiType& getValue() const { return value_; }
         //! Returns the given default value as type T.
-        MultiType getDefaultValue() const { return defaultValue_; }
+        const MultiType& getDefaultValue() const { return defaultValue_; }
 
     private:
         //! Constructor initialises both value_ and defaultValue_ with defaultValue.
-        CommandLineArgument(const std::string& name, const MultiType& defaultValue, bool bCommandLineOnly)
+        CommandLineArgument(const std::string& name, const MultiType& defaultValue)
             : bHasDefaultValue_(true)
             , name_(name)
             , value_(defaultValue)
             , defaultValue_(defaultValue)
-            , bCommandLineOnly_(bCommandLineOnly)
         { }
 
@@ -125,5 +117,5 @@
 
         //! Parses the value string of a command line argument.
-        void parse(const std::string& value, bool bParsingFile);
+        void parse(const std::string& value);
 
         //! Tells whether the value has been changed by the command line.
@@ -137,5 +129,4 @@
         MultiType   value_;            //!< The actual value
         MultiType   defaultValue_;     //!< Default value. Should not be changed.
-        bool        bCommandLineOnly_; //!< Whether you cannot specify the value in a text file
     };
 
@@ -155,6 +146,6 @@
 
         //! Parse redirection to internal member method.
-        static void parseCommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }
-        static void parseFile() { _getInstance()._parseFile(); }
+        static void parse(const std::string& cmdLine)
+        { _getInstance()._parse(cmdLine); }
 
         static std::string getUsageInformation();
@@ -165,8 +156,8 @@
         static void getValue(const std::string& name, T* value)
         { *value = (T)(getArgument(name)->getValue()); }
-        static MultiType getValue(const std::string& name)
+        static const MultiType& getValue(const std::string& name)
         { return getArgument(name)->getValue(); }
         template <class T>
-        static CommandLineArgument& addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly);
+        static CommandLineArgument& addArgument(const std::string& name, T defaultValue);
 
         static bool existsArgument(const std::string& name)
@@ -189,9 +180,7 @@
         static CommandLineParser& _getInstance();
 
-        void _parseCommandLine(const std::string& cmdLine);
-        void _parseFile();
-        void _parse(const std::vector<std::string>& arguments, bool bParsingFile);
-        void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile);
-        void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile);
+        void _parse(const std::string& cmdLine);
+        void checkFullArgument(const std::string& name, const std::string& value);
+        void checkShortcut(const std::string& shortcut, const std::string& value);
 
         /**
@@ -222,9 +211,7 @@
     @param defaultValue
         Default value that is used when argument was not given.
-    @param bCommandLineOnly
-        Parsing a file or the command line itself
     */
     template <class T>
-    CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue, bool bCommandLineOnly)
+    CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue)
     {
         OrxAssert(!_getInstance().existsArgument(name),
@@ -234,5 +221,5 @@
             << "Please use SetCommandLineSwitch and adjust your argument: " << name);
 
-        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue, bCommandLineOnly));
+        return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue));
     }
 }
Index: /code/trunk/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- /code/trunk/src/libraries/core/ConfigValueIncludes.h	(revision 8728)
+++ /code/trunk/src/libraries/core/ConfigValueIncludes.h	(revision 8729)
@@ -255,3 +255,18 @@
     ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
 
+/** Modifies a runtime configurable value by using a modifier and some arguments.
+    If the container for the value doesn't yet exist, a warning is displayed.
+    Also, the @a variable argument will be modified and set to the current value.
+@param variable
+    Pointer to the variable where the value should be written to
+@param entryName
+    Name of the entry in the ini file (e.g. [MySection] myValue)
+@param modifier
+    On of these functions: set, tset, add, remove, reset, update
+@param ...
+    Arguments for the modifier function
+*/
+#define ModifyConfigValueExternal(variable, entryName, modifier, ...) \
+    ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)
+
 #endif /* _ConfigValueIncludes_H__ */
Index: /code/trunk/src/libraries/core/Core.cc
===================================================================
--- /code/trunk/src/libraries/core/Core.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/Core.cc	(revision 8729)
@@ -69,4 +69,5 @@
 #include "Language.h"
 #include "LuaState.h"
+#include "ObjectList.h"
 #include "command/ConsoleCommand.h"
 #include "command/IOConsole.h"
@@ -131,5 +132,5 @@
 
         // Parse command line arguments AFTER the modules have been loaded (static code!)
-        CommandLineParser::parseCommandLine(cmdLine);
+        CommandLineParser::parse(cmdLine);
 
         // Set configurable paths like log, config and media
@@ -143,7 +144,4 @@
         // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used
         OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString());
-
-        // Parse additional options file now that we know its path
-        CommandLineParser::parseFile();
 
 #ifdef ORXONOX_PLATFORM_WINDOWS
@@ -168,4 +166,6 @@
         RegisterRootObject(Core);
         this->setConfigValues();
+        // Rewrite the log file with the correct log levels
+        OutputHandler::getInstance().rewriteLogFile();
 
 #if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
@@ -230,18 +230,23 @@
     }
 
+    namespace DefaultLevelLogFile
+    {
+        const OutputLevel::Value Dev  = OutputLevel::Debug;
+        const OutputLevel::Value User = OutputLevel::Info;
+    }
+
     //! Function to collect the SetConfigValue-macro calls.
     void Core::setConfigValues()
     {
-#ifdef ORXONOX_RELEASE
-        const unsigned int defaultLevelLogFile = 3;
-#else
-        const unsigned int defaultLevelLogFile = 4;
-#endif
-        SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile)
-            .description("The maximum level of debug output shown in the log file");
-        OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
+        // Choose the default level according to the path Orxonox was started (build directory or not)
+        OutputLevel::Value defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
+
+        SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel)
+            .description("The maximum level of debug output written to the log file");
+        OutputHandler::getInstance().setSoftDebugLevel("LogFile", debugLevelLogFile_);
 
         SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
-            .description("Developer mode. If not set, hides some things from the user to not confuse him.");
+            .description("Developer mode. If not set, hides some things from the user to not confuse him.")
+            .callback(this, &Core::devModeChanged);
         SetConfigValue(language_, Language::getInstance().defaultLanguage_)
             .description("The language of the in game text")
@@ -258,4 +263,37 @@
     }
 
+    /** Callback function for changes in the dev mode that affect debug levels.
+        The function behaves according to these rules:
+        - 'normal' mode is defined based on where the program was launched: if
+          the launch path was the build directory, development mode \c on is
+          normal, otherwise normal means development mode \c off.
+        - Debug levels should not be hard configured (\c config instead of
+          \c tconfig) in non 'normal' mode to avoid strange behaviour.
+        - Changing the development mode from 'normal' to the other state will
+          immediately change the debug levels to predefined values which can be
+          reconfigured with \c tconfig.
+    @note
+        The debug levels for the IOConsole and the InGameConsole can be found
+        in the Shell class. The same rules apply.
+    */
+    void Core::devModeChanged()
+    {
+        bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun());
+        if (isNormal)
+        {
+            ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update);
+        }
+        else
+        {
+            OutputLevel::Value level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User);
+            ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level);
+        }
+
+        // Inform listeners
+        ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin();
+        for (; it != ObjectList<DevModeListener>::end(); ++it)
+            it->devModeChanged(bDevMode_);
+    }
+
     //! Callback function if the language has changed.
     void Core::languageChanged()
@@ -440,3 +478,9 @@
         ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL)));
     }
+
+
+    DevModeListener::DevModeListener()
+    {
+        RegisterRootObject(DevModeListener);
+    }
 }
Index: /code/trunk/src/libraries/core/Core.h
===================================================================
--- /code/trunk/src/libraries/core/Core.h	(revision 8728)
+++ /code/trunk/src/libraries/core/Core.h	(revision 8729)
@@ -45,6 +45,4 @@
 
 #include <string>
-#include <loki/ScopeGuard.h>
-
 #include "util/DestructionHelper.h"
 #include "util/Singleton.h"
@@ -53,4 +51,13 @@
 namespace orxonox
 {
+    //! Informs about changes in the Development Mode.
+    class DevModeListener : virtual public OrxonoxClass
+    {
+    public:
+        DevModeListener();
+        virtual ~DevModeListener() {}
+        virtual void devModeChanged(bool value) = 0;
+    };
+
     /**
     @brief
@@ -101,4 +108,5 @@
             Core(const Core&); //!< Don't use (undefined symbol)
 
+            void devModeChanged();
             void languageChanged();
             void initRandomNumberGenerator();
@@ -128,5 +136,5 @@
 
             bool                      bGraphicsLoaded_;
-            int                       softDebugLevelLogFile_;      //!< The debug level for the log file (belongs to OutputHandler)
+            int                       debugLevelLogFile_;          //!< The debug level for the log file (belongs to OutputHandler)
             std::string               language_;                   //!< The language
             bool                      bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called
Index: /code/trunk/src/libraries/core/CoreIncludes.h
===================================================================
--- /code/trunk/src/libraries/core/CoreIncludes.h	(revision 8728)
+++ /code/trunk/src/libraries/core/CoreIncludes.h	(revision 8729)
@@ -80,5 +80,4 @@
 #include "util/Debug.h"
 #include "Identifier.h"
-#include "SubclassIdentifier.h"
 #include "ClassFactory.h"
 #include "ObjectList.h"
Index: /code/trunk/src/libraries/core/EventIncludes.h
===================================================================
--- /code/trunk/src/libraries/core/EventIncludes.h	(revision 8728)
+++ /code/trunk/src/libraries/core/EventIncludes.h	(revision 8729)
@@ -37,4 +37,6 @@
 
 #include "CorePrereqs.h"
+
+#include "Event.h"
 #include "XMLPort.h"
 #include "command/Executor.h"
Index: /code/trunk/src/libraries/core/GUIManager.cc
===================================================================
--- /code/trunk/src/libraries/core/GUIManager.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/GUIManager.cc	(revision 8729)
@@ -490,5 +490,5 @@
     }
 
-    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);
@@ -506,22 +506,22 @@
 #ifdef ORXONOX_PLATFORM_APPLE
         // There is no non exclusive mode on OS X yet
-        state->setMouseExclusive(TriBool::True);
-#else
-        if (showCursor == TriBool::Dontcare)
-            state->setMouseExclusive(TriBool::Dontcare);
-        else if (GraphicsManager::getInstance().isFullScreen() || showCursor == TriBool::False)
-            state->setMouseExclusive(TriBool::True);
+        state->setMouseExclusive(true);
+#else
+        if (showCursor == dontcare)
+            state->setMouseExclusive(dontcare);
+        else if (GraphicsManager::getInstance().isFullScreen() || showCursor == false)
+            state->setMouseExclusive(true);
         else
-            state->setMouseExclusive(TriBool::False);
-#endif
-
-        if (showCursor == TriBool::True)
+            state->setMouseExclusive(false);
+#endif
+
+        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);
 
@@ -717,4 +717,12 @@
     }
 
+    /** Helper method to get the developer's mode without having to export Core.h.
+    @see Core::inDevMode
+    */
+    /*static*/ bool GUIManager::inDevMode()
+    {
+         return Core::getInstance().inDevMode();
+    }
+
     /**
         @brief Callback of window event listener, called if the window is resized. Sets the display size of CEGUI.
Index: /code/trunk/src/libraries/core/GUIManager.h
===================================================================
--- /code/trunk/src/libraries/core/GUIManager.h	(revision 8728)
+++ /code/trunk/src/libraries/core/GUIManager.h	(revision 8729)
@@ -39,5 +39,4 @@
 
 #include <map>
-#include <set>
 #include <string>
 #include <CEGUIForwardRefs.h>
@@ -47,15 +46,9 @@
 #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 "Core.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
@@ -66,4 +59,18 @@
 { // tolua_export
     class PlayerInfo; // Forward declaration
+
+    // Acquaint Tolua with tribool
+    /* tolua_begin
+    struct dontcare_keyword_t
+    {
+        dontcare_keyword_t();
+    };
+    class tribool
+    {
+        tribool(bool value);
+        tribool(dontcare_keyword_t);
+        bool operator==(tribool);
+    };
+    tolua_end */
 
     /**
@@ -104,12 +111,8 @@
         void setBackgroundImage(const std::string& image);
 
-        /**
-        @brief Helper method to get the developer's mode without having to export Core.h.
-        @see Core::inDevMode
-        */
-        static bool inDevMode(void) { return Core::getInstance().inDevMode(); } // tolua_export
+        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 = tribool(true), tribool useKeyboard = tribool(true), bool bBlockJoyStick = false); // tolua_export
         LuaState* getLuaState(void)
             { return this->luaState_; }
Index: /code/trunk/src/libraries/core/Game.cc
===================================================================
--- /code/trunk/src/libraries/core/Game.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/Game.cc	(revision 8729)
@@ -109,5 +109,5 @@
 
         // Do this after the Core creation!
-        ClassIdentifier<Game>::getIdentifier("Game")->initialiseObject(this, "Game", true);
+        RegisterRootObject(Game);
         this->setConfigValues();
 
Index: /code/trunk/src/libraries/core/LuaState.cc
===================================================================
--- /code/trunk/src/libraries/core/LuaState.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/LuaState.cc	(revision 8729)
@@ -40,16 +40,9 @@
 #include "util/Exception.h"
 #include "Resource.h"
-#include "ToluaBindCore.h"
 #include "command/IOConsole.h"
 
 namespace orxonox
 {
-    LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;
-    std::vector<LuaState*> LuaState::instances_s;
-
     const std::string LuaState::ERROR_HANDLER_NAME = "errorHandler";
-
-    // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems
-    DeclareToluaInterface(Core);
 
     LuaState::LuaState()
@@ -277,7 +270,19 @@
     }
 
+    /*static*/ LuaState::ToluaInterfaceMap& LuaState::getToluaInterfaces()
+    {
+        static ToluaInterfaceMap p;
+        return p;
+    }
+
+    /*static*/ std::vector<LuaState*>& LuaState::getInstances()
+    {
+        static std::vector<LuaState*> p;
+        return p;
+    }
+
     /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name)
     {
-        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
         {
             if (it->first == name || it->second == function)
@@ -287,8 +292,8 @@
             }
         }
-        toluaInterfaces_s[name] = function;
+        getToluaInterfaces()[name] = function;
 
         // Open interface in all LuaStates
-        for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)
+        for (std::vector<LuaState*>::const_iterator it = getInstances().begin(); it != getInstances().end(); ++it)
             (*function)((*it)->luaState_);
 
@@ -299,6 +304,6 @@
     /*static*/ bool LuaState::removeToluaInterface(const std::string& name)
     {
-        ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);
-        if (it == toluaInterfaces_s.end())
+        ToluaInterfaceMap::iterator it = getToluaInterfaces().find(name);
+        if (it == getToluaInterfaces().end())
         {
             COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl;
@@ -307,5 +312,5 @@
 
         // Close interface in all LuaStates
-        for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)
+        for (std::vector<LuaState*>::const_iterator itState = getInstances().begin(); itState != getInstances().end(); ++itState)
         {
             lua_pushnil((*itState)->luaState_);
@@ -314,5 +319,5 @@
 
         // Remove entry
-        toluaInterfaces_s.erase(it);
+        getToluaInterfaces().erase(it);
 
         // Return dummy bool
@@ -322,5 +327,5 @@
     /*static*/ void LuaState::openToluaInterfaces(lua_State* state)
     {
-        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
             (*it->second)(state);
     }
@@ -328,5 +333,5 @@
     /*static*/ void LuaState::closeToluaInterfaces(lua_State* state)
     {
-        for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)
+        for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it)
         {
             lua_pushnil(state);
Index: /code/trunk/src/libraries/core/LuaState.h
===================================================================
--- /code/trunk/src/libraries/core/LuaState.h	(revision 8728)
+++ /code/trunk/src/libraries/core/LuaState.h	(revision 8729)
@@ -48,7 +48,4 @@
 #include <vector>
 #include <boost/shared_ptr.hpp>
-#include <loki/ScopeGuard.h>
-
-#include "ToluaInterface.h"
 
 namespace orxonox // tolua_export
@@ -121,7 +118,25 @@
 
         typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap;
-        static ToluaInterfaceMap toluaInterfaces_s;
-        static std::vector<LuaState*> instances_s;
+        static ToluaInterfaceMap& getToluaInterfaces();
+        static std::vector<LuaState*>& getInstances();
     }; // tolua_export
+
+
+    //! Helper class that registers/unregisters tolua bindings
+    class ToluaBindingsHelper
+    {
+    public:
+        ToluaBindingsHelper(int (*function)(lua_State*), const std::string& libraryName)
+            : libraryName_(libraryName)
+        {
+            LuaState::addToluaInterface(function, libraryName_);
+        }
+        ~ToluaBindingsHelper()
+        {
+            LuaState::removeToluaInterface(libraryName_);
+        }
+    private:
+        std::string libraryName_;
+    };
 } // tolua_export
 
Index: /code/trunk/src/libraries/core/ObjectListBase.h
===================================================================
--- /code/trunk/src/libraries/core/ObjectListBase.h	(revision 8728)
+++ /code/trunk/src/libraries/core/ObjectListBase.h	(revision 8729)
@@ -41,7 +41,5 @@
 
 #include "CorePrereqs.h"
-
 #include <vector>
-#include "OrxonoxClass.h"
 
 namespace orxonox
Index: /code/trunk/src/libraries/core/OrxonoxClass.h
===================================================================
--- /code/trunk/src/libraries/core/OrxonoxClass.h	(revision 8728)
+++ /code/trunk/src/libraries/core/OrxonoxClass.h	(revision 8729)
@@ -45,8 +45,8 @@
 
 #include "CorePrereqs.h"
-#include "Super.h"
 
 #include <set>
 #include <vector>
+#include "Super.h"
 
 /**
Index: /code/trunk/src/libraries/core/PathConfig.cc
===================================================================
--- /code/trunk/src/libraries/core/PathConfig.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/PathConfig.cc	(revision 8729)
@@ -74,5 +74,5 @@
 
     SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
-    SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
+    SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
 
     PathConfig::PathConfig()
Index: /code/trunk/src/libraries/core/Super.h
===================================================================
--- /code/trunk/src/libraries/core/Super.h	(revision 8728)
+++ /code/trunk/src/libraries/core/Super.h	(revision 8729)
@@ -73,7 +73,5 @@
 
 #include "CorePrereqs.h"
-
 #include "util/Debug.h"
-#include "Event.h"
 
 ///////////////////////
Index: de/trunk/src/libraries/core/ToluaInterface.h
===================================================================
--- /code/trunk/src/libraries/core/ToluaInterface.h	(revision 8728)
+++ 	(revision )
@@ -1,47 +1,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 Lua
-@brief
-    This is required because tolua would parse this macro in LuaState.h and fail
-*/
-
-#ifndef _ToluaInterface_H__
-#define _ToluaInterface_H__
-
-#include "CorePrereqs.h"
-#include <boost/preprocessor/cat.hpp>
-
-// Macro for declaring a tolua interface of a library/module
-#define DeclareToluaInterface(libraryName) \
-    static bool BOOST_PP_CAT(bDummy##libraryName, __UNIQUE_NUMBER__) = orxonox::LuaState::addToluaInterface(&tolua_##libraryName##_open, #libraryName); \
-    static Loki::ScopeGuardImpl1<bool (*)(const std::string&), std::string> BOOST_PP_CAT(dummy##libraryName, __UNIQUE_NUMBER__)(&orxonox::LuaState::removeToluaInterface, #libraryName)
-
-#endif /* _ToluaInterface_H__ */
Index: /code/trunk/src/libraries/core/ToluaInterfaceHook.lua
===================================================================
--- /code/trunk/src/libraries/core/ToluaInterfaceHook.lua	(revision 8729)
+++ /code/trunk/src/libraries/core/ToluaInterfaceHook.lua	(revision 8729)
@@ -0,0 +1,30 @@
+--
+--             ORXONOX - the hottest 3D action shooter ever to exist
+--                             > www.orxonox.net <
+--
+--        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
+--
+
+-- Writes the static initialiser that registers the package open() function
+function post_include_hook(package_name)
+    output('\n')
+    output('#include "core/LuaState.h"\n')
+    output('int tolua_'..package_name..'_open(lua_State* tolua_S);\n')
+    output('static orxonox::ToluaBindingsHelper initialiser(&tolua_'..package_name..'_open, "'..package_name..'");')
+end
Index: /code/trunk/src/libraries/core/ViewportEventListener.h
===================================================================
--- /code/trunk/src/libraries/core/ViewportEventListener.h	(revision 8728)
+++ /code/trunk/src/libraries/core/ViewportEventListener.h	(revision 8729)
@@ -30,7 +30,7 @@
 #define _ViewportEventListener_H__
 
+#include "CorePrereqs.h"
+
 #include "util/OgreForwardRefs.h"
-
-#include "CorePrereqs.h"
 #include "OrxonoxClass.h"
 
Index: /code/trunk/src/libraries/core/command/Functor.h
===================================================================
--- /code/trunk/src/libraries/core/command/Functor.h	(revision 8728)
+++ /code/trunk/src/libraries/core/command/Functor.h	(revision 8729)
@@ -114,7 +114,7 @@
 #define _Functor_H__
 
+#include "core/CorePrereqs.h"
+
 #include <typeinfo>
-
-#include "core/CorePrereqs.h"
 
 #include "util/Debug.h"
Index: /code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
===================================================================
--- /code/trunk/src/libraries/core/command/IOConsolePOSIX.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/command/IOConsolePOSIX.cc	(revision 8729)
@@ -236,24 +236,24 @@
     void IOConsole::printOutputLine(const std::string& text, Shell::LineType type)
     {
-/*
         // Colour line
         switch (type)
         {
-        case Shell::None:    this->cout_ << "\033[37m"; break;
         case Shell::Error:   this->cout_ << "\033[91m"; break;
-        case Shell::Warning: this->cout_ << "\033[31m"; break;
-        case Shell::Info:    this->cout_ << "\033[34m"; break;
-        case Shell::Debug:   this->cout_ << "\033[36m"; break;
-        case Shell::Verbose: this->cout_ << "\033[35m"; break;
-        case Shell::Ultra:   this->cout_ << "\033[37m"; break;
+        case Shell::Warning: this->cout_ << "\033[93m"; break;
+        case Shell::Info:    this->cout_ << "\033[90m"; break;
+        case Shell::Debug:   this->cout_ << "\033[90m"; break;
+        case Shell::Verbose: this->cout_ << "\033[90m"; break;
+        case Shell::Ultra:   this->cout_ << "\033[90m"; break;
+        case Shell::Command: this->cout_ << "\033[36m"; break;
+        case Shell::Hint:    this->cout_ << "\033[33m"; break;
+        case Shell::TDebug:  this->cout_ << "\033[95m"; break;
         default: break;
         }
-*/
 
         // Print output line
         this->cout_ << text;
 
-        // Reset colour to white
-//        this->cout_ << "\033[37m";
+        // Reset colour atributes
+        this->cout_ << "\033[0m";
     }
 
Index: /code/trunk/src/libraries/core/command/IOConsoleWindows.cc
===================================================================
--- /code/trunk/src/libraries/core/command/IOConsoleWindows.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/command/IOConsoleWindows.cc	(revision 8729)
@@ -208,4 +208,5 @@
         case Shell::Command: colour =                        FOREGROUND_GREEN                  | FOREGROUND_BLUE; break;
         case Shell::Hint:    colour =                        FOREGROUND_GREEN | FOREGROUND_RED                  ; break;
+        case Shell::TDebug:  colour = FOREGROUND_INTENSITY                    | FOREGROUND_RED | FOREGROUND_BLUE; break;
         default:             colour =                        FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; break;
         }
Index: /code/trunk/src/libraries/core/command/IOConsoleWindows.h
===================================================================
--- /code/trunk/src/libraries/core/command/IOConsoleWindows.h	(revision 8728)
+++ /code/trunk/src/libraries/core/command/IOConsoleWindows.h	(revision 8729)
@@ -39,5 +39,4 @@
 #include <sstream>
 #include <string>
-#include <vector>
 #include "util/Singleton.h"
 #include "Shell.h"
Index: /code/trunk/src/libraries/core/command/Shell.cc
===================================================================
--- /code/trunk/src/libraries/core/command/Shell.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/command/Shell.cc	(revision 8729)
@@ -34,4 +34,5 @@
 #include "Shell.h"
 
+#include "util/Math.h"
 #include "util/OutputHandler.h"
 #include "util/StringUtils.h"
@@ -40,4 +41,6 @@
 #include "core/ConfigFileManager.h"
 #include "core/ConfigValueIncludes.h"
+#include "core/PathConfig.h"
+#include "core/input/InputBuffer.h"
 #include "CommandExecutor.h"
 #include "ConsoleCommand.h"
@@ -84,8 +87,8 @@
 
         // Get the previous output and add it to the Shell
-        for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
-            it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
-        {
-            if (it->first <= this->getSoftDebugLevel())
+        OutputHandler::OutputVector::const_iterator it = OutputHandler::getInstance().getOutput().begin();
+        for (;it != OutputHandler::getInstance().getOutput().end(); ++it)
+        {
+            if (it->first <= debugLevel_)
             {
                 this->outputBuffer_ << it->second;
@@ -96,4 +99,5 @@
         // Register the shell as output listener
         OutputHandler::getInstance().registerOutputListener(this);
+        OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
     }
 
@@ -105,4 +109,10 @@
         OutputHandler::getInstance().unregisterOutputListener(this);
         this->inputBuffer_->destroy();
+    }
+
+    namespace DefaultLogLevel
+    {
+        const OutputLevel::Value Dev  = OutputLevel::Info;
+        const OutputLevel::Value User = OutputLevel::Error;
     }
 
@@ -119,12 +129,9 @@
         SetConfigValue(cacheSize_s, 32);
 
-#ifdef ORXONOX_RELEASE
-        const unsigned int defaultLevel = 1;
-#else
-        const unsigned int defaultLevel = 3;
-#endif
-        SetConfigValueExternal(softDebugLevel_, "OutputHandler", "softDebugLevel" + this->consoleName_, defaultLevel)
-            .description("The maximal level of debug output shown in the Shell");
-        this->setSoftDebugLevel(this->softDebugLevel_);
+        // Choose the default level according to the path Orxonox was started (build directory or not)
+        OutputLevel::Value defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+        SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel)
+            .description("The maximum level of debug output shown in the " + consoleName_);
+        OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_);
     }
 
@@ -150,4 +157,21 @@
             this->commandHistory_.erase(this->commandHistory_.begin() + index);
             ModifyConfigValue(commandHistory_, remove, index);
+        }
+    }
+
+    /** Called upon changes in the development mode (by Core)
+        Behaviour details see Core::devModeChanged.
+    */
+    void Shell::devModeChanged(bool value)
+    {
+        bool isNormal = (value == PathConfig::buildDirectoryRun());
+        if (isNormal)
+        {
+            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update);
+        }
+        else
+        {
+            OutputLevel::Value level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+            ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level);
         }
     }
@@ -215,4 +239,16 @@
     }
 
+    /// Returns the current position of the cursor in the input buffer.
+    unsigned int Shell::getCursorPosition() const
+    {
+        return this->inputBuffer_->getCursorPosition();
+    }
+
+    /// Returns the current content of the input buffer (the text which was entered by the user)
+    const std::string& Shell::getInput() const
+    {
+        return this->inputBuffer_->get();
+    }
+
     /**
         @brief Sends output to the internal output buffer.
Index: /code/trunk/src/libraries/core/command/Shell.h
===================================================================
--- /code/trunk/src/libraries/core/command/Shell.h	(revision 8728)
+++ /code/trunk/src/libraries/core/command/Shell.h	(revision 8729)
@@ -49,6 +49,6 @@
 
 #include "util/OutputHandler.h"
+#include "core/Core.h"
 #include "core/OrxonoxClass.h"
-#include "core/input/InputBuffer.h"
 
 namespace orxonox
@@ -85,5 +85,5 @@
         Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole.
     */
-    class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener
+    class _CoreExport Shell : public OutputListener, public DevModeListener
     {
         public:
@@ -91,4 +91,5 @@
             enum LineType
             {
+                TDebug  = OutputLevel::TDebug,
                 None    = OutputLevel::None,
                 Warning = OutputLevel::Warning,
@@ -118,11 +119,7 @@
 
             void setCursorPosition(unsigned int cursor);
-            /// Returns the current position of the cursor in the input buffer.
-            inline unsigned int getCursorPosition() const
-                { return this->inputBuffer_->getCursorPosition(); }
-
-            /// Returns the current content of the input buffer (the text which was entered by the user)
-            inline const std::string& getInput() const
-                { return this->inputBuffer_->get(); }
+            unsigned int getCursorPosition() const;
+
+            const std::string& getInput() const;
 
             typedef std::list<std::pair<std::string, LineType> > LineList;
@@ -146,4 +143,7 @@
         private:
             Shell(const Shell& other);
+
+            // DevModeListener
+            void devModeChanged(bool value);
 
             void addToHistory(const std::string& command);
@@ -197,5 +197,5 @@
             unsigned int              historyOffset_;       ///< The command history is a circular buffer, this variable defines the current write-offset
             std::vector<std::string>  commandHistory_;      ///< The history of commands that were entered by the user
-            int                       softDebugLevel_;      ///< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output)
+            int                       debugLevel_;          //!< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output)
             static unsigned int       cacheSize_s;          ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is no OrxonoxClass
     };
Index: /code/trunk/src/libraries/core/input/InputHandler.h
===================================================================
--- /code/trunk/src/libraries/core/input/InputHandler.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputHandler.h	(revision 8729)
@@ -31,8 +31,17 @@
 
 #include "InputPrereqs.h"
-#include "util/Math.h"
 
 namespace orxonox
 {
+    /// A Vector class containing two integers @a x and @a y.
+    class IntVector2
+    {
+    public:
+        IntVector2() : x(0), y(0) { }
+        IntVector2(int _x, int _y) : x(_x), y(_y) { }
+        int x;
+        int y;
+    };
+
     namespace ButtonEvent
     {
Index: /code/trunk/src/libraries/core/input/InputManager.cc
===================================================================
--- /code/trunk/src/libraries/core/input/InputManager.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputManager.cc	(revision 8729)
@@ -94,5 +94,5 @@
         , oisInputManager_(0)
         , devices_(2)
-        , exclusiveMouse_(TriBool::False)
+        , exclusiveMouse_(false)
         , emptyState_(0)
         , calibratorCallbackHandler_(0)
@@ -108,5 +108,5 @@
 
         if (GraphicsManager::getInstance().isFullScreen())
-            exclusiveMouse_ = TriBool::True;
+            exclusiveMouse_ = true;
         this->loadDevices();
 
@@ -161,5 +161,5 @@
         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.)
@@ -174,5 +174,5 @@
         paramList.insert(StringPair("XAutoRepeatOn", "true"));
 
-        if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
+        if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
         {
             if (CommandLineParser::getValue("keyboard_no_grab").getBool())
@@ -447,13 +447,14 @@
 
         // 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)
-        {
-            exclusiveMouse_ = requestedMode;
+        if (requestedMode != dontcare && exclusiveMouse_ != requestedMode)
+        {
+            assert(requestedMode != dontcare);
+            exclusiveMouse_ = (requestedMode == true);
             if (!GraphicsManager::getInstance().isFullScreen())
                 this->reloadInternal();
@@ -644,5 +645,5 @@
     }
 
-    bool InputManager::setMouseExclusive(const std::string& name, TriBool::Value value)
+    bool InputManager::setMouseExclusive(const std::string& name, tribool value)
     {
         if (name == "empty")
Index: /code/trunk/src/libraries/core/input/InputManager.h
===================================================================
--- /code/trunk/src/libraries/core/input/InputManager.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputManager.h	(revision 8729)
@@ -33,5 +33,4 @@
 
 #include <map>
-#include <set>
 #include <string>
 #include <vector>
@@ -39,5 +38,5 @@
 
 #include "util/Singleton.h"
-#include "util/TriBool.h"
+#include "util/tribool.h"
 #include "core/WindowEventListener.h"
 
@@ -169,5 +168,5 @@
             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
 
         //-------------------------------
@@ -215,5 +214,5 @@
         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
Index: /code/trunk/src/libraries/core/input/InputPrereqs.h
===================================================================
--- /code/trunk/src/libraries/core/input/InputPrereqs.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputPrereqs.h	(revision 8729)
@@ -41,5 +41,4 @@
 #include <ois/OISKeyboard.h>
 #include <ois/OISMouse.h>
-#include <ois/OISJoyStick.h>
 #include "util/OrxEnum.h"
 
Index: /code/trunk/src/libraries/core/input/InputState.cc
===================================================================
--- /code/trunk/src/libraries/core/input/InputState.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputState.cc	(revision 8729)
@@ -37,5 +37,5 @@
         , bAlwaysGetsInput_(bAlwaysGetsInput)
         , bTransparent_(bTransparent)
-        , exclusiveMouse_(TriBool::Dontcare)
+        , exclusiveMouse_(dontcare)
         , bExpired_(true)
         , handlers_(2)
Index: /code/trunk/src/libraries/core/input/InputState.h
===================================================================
--- /code/trunk/src/libraries/core/input/InputState.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/InputState.h	(revision 8729)
@@ -38,5 +38,5 @@
 #include <boost/bind.hpp>
 
-#include "util/TriBool.h"
+#include "util/tribool.h"
 #include "InputHandler.h"
 #include "InputManager.h"
@@ -112,6 +112,6 @@
         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!)
@@ -166,5 +166,5 @@
         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()
Index: /code/trunk/src/libraries/core/input/JoyStick.h
===================================================================
--- /code/trunk/src/libraries/core/input/JoyStick.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/JoyStick.h	(revision 8729)
@@ -34,4 +34,5 @@
 #include <string>
 #include <vector>
+#include <ois/OISJoyStick.h>
 #include "InputDevice.h"
 
Index: /code/trunk/src/libraries/core/input/JoyStickQuantityListener.h
===================================================================
--- /code/trunk/src/libraries/core/input/JoyStickQuantityListener.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/JoyStickQuantityListener.h	(revision 8729)
@@ -36,4 +36,6 @@
 
 #include "InputPrereqs.h"
+
+#include <vector>
 #include "core/OrxonoxClass.h"
 
Index: /code/trunk/src/libraries/core/input/KeyBinderManager.h
===================================================================
--- /code/trunk/src/libraries/core/input/KeyBinderManager.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/KeyBinderManager.h	(revision 8729)
@@ -34,5 +34,4 @@
 #include <map>
 #include <string>
-#include <boost/shared_ptr.hpp>
 
 #include "util/Singleton.h"
Index: /code/trunk/src/libraries/core/input/KeyDetector.h
===================================================================
--- /code/trunk/src/libraries/core/input/KeyDetector.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/KeyDetector.h	(revision 8729)
@@ -32,5 +32,4 @@
 #include "InputPrereqs.h"
 
-#include <boost/shared_ptr.hpp>
 #include "util/Singleton.h"
 #include "KeyBinder.h"
Index: /code/trunk/src/libraries/core/input/Keyboard.h
===================================================================
--- /code/trunk/src/libraries/core/input/Keyboard.h	(revision 8728)
+++ /code/trunk/src/libraries/core/input/Keyboard.h	(revision 8729)
@@ -31,6 +31,4 @@
 
 #include "InputPrereqs.h"
-
-#include "InputHandler.h"
 #include "InputDevice.h"
 
Index: /code/trunk/src/libraries/core/input/Mouse.cc
===================================================================
--- /code/trunk/src/libraries/core/input/Mouse.cc	(revision 8728)
+++ /code/trunk/src/libraries/core/input/Mouse.cc	(revision 8729)
@@ -37,4 +37,5 @@
 // include this as last, X11 seems to define some macros...
 #include <ois/linux/LinuxMouse.h>
+#undef Success
 #endif
 
Index: /code/trunk/src/libraries/network/WANDiscoverable.h
===================================================================
--- /code/trunk/src/libraries/network/WANDiscoverable.h	(revision 8728)
+++ /code/trunk/src/libraries/network/WANDiscoverable.h	(revision 8729)
@@ -28,5 +28,5 @@
 
 #include "NetworkPrereqs.h"
-// #include "core/OrxonoxClass.h"
+#include "core/OrxonoxClass.h"
 #include "core/CoreIncludes.h"
 #include "MasterServerComm.h"
Index: /code/trunk/src/libraries/network/packet/CMakeLists.txt
===================================================================
--- /code/trunk/src/libraries/network/packet/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/libraries/network/packet/CMakeLists.txt	(revision 8729)
@@ -1,4 +1,5 @@
 ADD_SOURCE_FILES(NETWORK_SRC_FILES
-COMPILATION_BEGIN PacketCompilation.cc
+
+BUILD_UNIT PacketBuildUnit.cc
   Acknowledgement.cc
   Chat.cc
@@ -10,5 +11,6 @@
   Packet.cc
   Welcome.cc
-COMPILATION_END
+END_BUILD_UNIT
+
   ServerInformation.cc
 )
Index: /code/trunk/src/libraries/tools/CMakeLists.txt
===================================================================
--- /code/trunk/src/libraries/tools/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/libraries/tools/CMakeLists.txt	(revision 8729)
@@ -1,10 +1,13 @@
 SET_SOURCE_FILES(TOOLS_SRC_FILES
-COMPILATION_BEGIN ResourceCompilation.cc
+
+BUILD_UNIT ResourceBuildUnit.cc
   ResourceCollection.cc
   ResourceLocation.cc
-COMPILATION_END
+END_BUILD_UNIT
+
   TextureGenerator.cc
   Timer.cc
-COMPILATION_BEGIN OgreCompilation.cc
+
+BUILD_UNIT OgreBuildUnit.cc
   BillboardSet.cc
   DynamicLines.cc
@@ -13,6 +16,7 @@
   ParticleInterface.cc
   Shader.cc
-COMPILATION_END
+END_BUILD_UNIT
 )
+
 #ADD_SUBDIRECTORY(bsp)
 ADD_SUBDIRECTORY(interfaces)
Index: /code/trunk/src/libraries/tools/Shader.h
===================================================================
--- /code/trunk/src/libraries/tools/Shader.h	(revision 8728)
+++ /code/trunk/src/libraries/tools/Shader.h	(revision 8729)
@@ -32,12 +32,9 @@
 #include "tools/ToolsPrereqs.h"
 
-#include <map>
+#include <list>
 #include <string>
-#include <vector>
-
 #include <OgreCompositorInstance.h>
 
 #include "util/MultiType.h"
-#include "util/OgreForwardRefs.h"
 #include "core/ViewportEventListener.h"
 
Index: /code/trunk/src/libraries/tools/Timer.cc
===================================================================
--- /code/trunk/src/libraries/tools/Timer.cc	(revision 8728)
+++ /code/trunk/src/libraries/tools/Timer.cc	(revision 8729)
@@ -42,4 +42,5 @@
 #include "core/command/ConsoleCommand.h"
 #include "core/command/CommandExecutor.h"
+#include "core/command/Executor.h"
 #include "core/command/Functor.h"
 #include "tools/interfaces/TimeFactorListener.h"
@@ -175,4 +176,24 @@
     {
         return TimeFactorListener::getTimeFactor();
+    }
+
+    /**
+        @brief Initializes and starts the timer, which will call an executor after some time.
+        @param interval         The timer-interval in seconds
+        @param bLoop            If true, the executor gets called every @a interval seconds
+        @param executor         The executor that will be called
+        @param bKillAfterCall   If true, the timer will be deleted after the executor was called
+    */
+    void Timer::setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall)
+    {
+        this->setInterval(interval);
+        this->bLoop_ = bLoop;
+        this->executor_ = executor;
+        this->bActive_ = true;
+
+        this->time_ = this->interval_;
+        this->bKillAfterCall_ = bKillAfterCall;
+
+        executor->getFunctor()->setSafeMode(true);
     }
 
Index: /code/trunk/src/libraries/tools/Timer.h
===================================================================
--- /code/trunk/src/libraries/tools/Timer.h	(revision 8728)
+++ /code/trunk/src/libraries/tools/Timer.h	(revision 8729)
@@ -80,5 +80,5 @@
 
 #include "core/OrxonoxClass.h"
-#include "core/command/Executor.h"
+#include "core/command/ExecutorPtr.h"
 
 namespace orxonox
@@ -109,23 +109,5 @@
             Timer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
 
-            /**
-                @brief Initializes and starts the timer, which will call an executor after some time.
-                @param interval         The timer-interval in seconds
-                @param bLoop            If true, the executor gets called every @a interval seconds
-                @param executor         The executor that will be called
-                @param bKillAfterCall   If true, the timer will be deleted after the executor was called
-            */
-            void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false)
-            {
-                this->setInterval(interval);
-                this->bLoop_ = bLoop;
-                this->executor_ = executor;
-                this->bActive_ = true;
-
-                this->time_ = this->interval_;
-                this->bKillAfterCall_ = bKillAfterCall;
-
-                executor->getFunctor()->setSafeMode(true);
-            }
+            void setTimer(float interval, bool bLoop, const ExecutorPtr& executor, bool bKillAfterCall = false);
 
             void run();
Index: /code/trunk/src/libraries/util/CMakeLists.txt
===================================================================
--- /code/trunk/src/libraries/util/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/libraries/util/CMakeLists.txt	(revision 8729)
@@ -19,5 +19,6 @@
 
 SET_SOURCE_FILES(UTIL_SRC_FILES
-COMPILATION_BEGIN StableCompilation.cc
+
+BUILD_UNIT StableBuildUnit.cc
   Clipboard.cc
   Clock.cc
@@ -32,5 +33,5 @@
   SmallObjectAllocator.cc
   SubString.cc
-COMPILATION_END
+END_BUILD_UNIT
 
   MultiType.cc
@@ -40,11 +41,4 @@
   StringUtils.cc
 )
-
-IF(MSVC)
-  # Simply using #pragma warning(disable:4244) doesn't really disable it
-  # if the warning occurs in a template in another file
-  # Hence promote it manually to a higher warning level (4)
-  SET_SOURCE_FILES_PROPERTIES(MultiType.cc PROPERTIES COMPILE_FLAGS "-w44244")
-ENDIF()
 
 ORXONOX_ADD_LIBRARY(util
Index: /code/trunk/src/libraries/util/Convert.h
===================================================================
--- /code/trunk/src/libraries/util/Convert.h	(revision 8728)
+++ /code/trunk/src/libraries/util/Convert.h	(revision 8729)
@@ -133,4 +133,10 @@
 #include "ImplicitConversion.h"
 
+// disable warnings about possible loss of data
+#ifdef ORXONOX_COMPILER_MSVC
+#  pragma warning(push)
+#  pragma warning(disable:4244)
+#endif
+
 namespace orxonox
 {
@@ -471,3 +477,8 @@
 }
 
+// Reinstate warnings
+#ifdef ORXONOX_COMPILER_MSVC
+#  pragma warning(pop)
+#endif
+
 #endif /* _Convert_H__ */
Index: /code/trunk/src/libraries/util/Debug.h
===================================================================
--- /code/trunk/src/libraries/util/Debug.h	(revision 8728)
+++ /code/trunk/src/libraries/util/Debug.h	(revision 8729)
@@ -83,6 +83,4 @@
 #ifdef ORXONOX_RELEASE
     const int hardDebugLevel = OutputLevel::Verbose;
-#elif defined(NDEBUG)
-    const int hardDebugLevel = OutputLevel::Verbose;
 #else
     //! Maximum level for debug output that should be even processed at run time
@@ -125,3 +123,9 @@
             orxonox::OutputHandler::getOutStream(level)
 
+/** Logs debug output: You can use DOUT exactly like @c std::cout.
+    Use this macro to produce temporary debug output that will be removed later on.
+    The console output shall have a special colour if available.
+*/
+#define DOUT orxonox::OutputHandler::getOutStream(-1) << "+++ "
+
 #endif /* _Util_Debug_H__ */
Index: /code/trunk/src/libraries/util/Math.h
===================================================================
--- /code/trunk/src/libraries/util/Math.h	(revision 8728)
+++ /code/trunk/src/libraries/util/Math.h	(revision 8729)
@@ -299,29 +299,4 @@
 
     _UtilExport unsigned long getUniqueNumber();
-
-    /**
-        @brief A Vector class containing two integers @a x and @a y.
-    */
-    class IntVector2
-    {
-    public:
-        IntVector2() : x(0), y(0) { }
-        IntVector2(int _x, int _y) : x(_x), y(_y) { }
-        int x;
-        int y;
-    };
-
-    /**
-        @brief A Vector class containing three integers @a x, @a y, and @a z.
-    */
-    class IntVector3
-    {
-    public:
-        IntVector3() : x(0), y(0), z(0) { }
-        IntVector3(int _x, int _y, int _z) : x(_x), y(_y), z(_z) { }
-        int x;
-        int y;
-        int z;
-    };
 }
 
Index: /code/trunk/src/libraries/util/OutputHandler.cc
===================================================================
--- /code/trunk/src/libraries/util/OutputHandler.cc	(revision 8728)
+++ /code/trunk/src/libraries/util/OutputHandler.cc	(revision 8729)
@@ -69,5 +69,5 @@
         */
         LogFileWriter()
-            : OutputListener(OutputHandler::logFileOutputListenerName_s)
+            : OutputListener("LogFile")
         {
             // Get path for a temporary file
@@ -85,9 +85,10 @@
             timeinfo = localtime(&rawtime);
 
-            this->logFile_.open(this->logFilename_.c_str(), std::fstream::out);
-            this->logFile_ << "Started log on " << asctime(timeinfo) << std::endl;
-            this->logFile_.flush();
-
-            this->outputStream_ = &this->logFile_;
+            this->openFile();
+            if (this->logFile_.is_open())
+            {
+                this->logFile_ << "Started log on " << asctime(timeinfo) << std::endl;
+                this->logFile_.flush();
+            }
         }
 
@@ -95,6 +96,9 @@
         ~LogFileWriter()
         {
-            this->logFile_ << "Closed log" << std::endl;
-            this->logFile_.close();
+            if (this->logFile_.is_open())
+            {
+                this->logFile_ << "Closed log" << std::endl;
+                this->logFile_.close();
+            }
         }
 
@@ -102,16 +106,36 @@
         void setLogPath(const std::string& path)
         {
-            this->logFile_.close();
-            // Read old file into a buffer
-            std::ifstream old(this->logFilename_.c_str());
+            if (this->logFile_.is_open())
+                this->logFile_.close();
+
+            // Open the new file
             this->logFilename_ = path + logFileBaseName_g;
-            // Open the new file and feed it the content of the old one
+            this->openFile();
+        }
+
+        //! Erases the log file
+        void clearFile()
+        {
+            if (this->logFile_.is_open())
+            {
+                this->logFile_.close();
+                this->openFile();
+            }
+        }
+
+    private:
+        void openFile()
+        {
             this->logFile_.open(this->logFilename_.c_str(), std::fstream::out);
-            this->logFile_ << old.rdbuf();
-            this->logFile_.flush();
-            old.close();
-        }
-
-    private:
+
+            if (this->logFile_.is_open())
+                this->outputStream_ = &this->logFile_;
+            else
+            {
+                COUT(2) << "Warning: Failed to open log file. File logging disabled." << std::endl;
+                this->outputStream_ = NULL;
+            }
+        }
+
         std::ofstream logFile_;     //!< File handle for the log file
         std::string   logFilename_; //!< Filename of the log file
@@ -133,5 +157,5 @@
         //! Only assigns the output stream with std::cout
         ConsoleWriter()
-            : OutputListener("consoleLog")
+            : OutputListener("Console")
         {
             this->outputStream_ = &std::cout;
@@ -147,7 +171,8 @@
         OutputListener that writes all the output piece by piece to an array
         associated with the corresponding output level.
+        Used as buffer until all output devices have been initialised.
     @note
-        Only output below or equal to the current soft debug level is written
-        to minimise huge arrays for the normal run.
+        At some point, OutputHandler::disableMemoryLog() has to be called in
+        order to avoid large memory footprints of this class.
     */
     class MemoryLogWriter : public OutputListener
@@ -156,8 +181,4 @@
         friend class OutputHandler;
 
-        /**
-        @brief
-            Sets the right soft debug level and registers itself
-        */
         MemoryLogWriter()
             : OutputListener("memoryLog")
@@ -166,5 +187,5 @@
         }
 
-        //! Pushed the just written output to the internal array
+        //! Push the just written output to the internal array
         void outputChanged(int level)
         {
@@ -180,6 +201,6 @@
 
     private:
-        std::ostringstream                        buffer_; //!< Stream object used to process the output
-        std::vector<std::pair<int, std::string> > output_; //!< Vector containing ALL output
+        std::ostringstream          buffer_; //!< Stream object used to process the output
+        OutputHandler::OutputVector output_; //!< Vector containing ALL output
     };
 
@@ -188,6 +209,5 @@
     ///// OutputHandler /////
     /////////////////////////
-    const std::string OutputHandler::logFileOutputListenerName_s = "logFile";
-          int         OutputHandler::softDebugLevel_s = hardDebugLevel;
+    int OutputHandler::softDebugLevel_s = hardDebugLevel;
 
     //! Creates the LogFileWriter and the MemoryLogWriter
@@ -195,25 +215,28 @@
         : outputLevel_(OutputLevel::Verbose)
     {
+        // Note: These levels only concern startup before orxonox.ini is read.
 #ifdef ORXONOX_RELEASE
-        const OutputLevel::Value defaultLevelConsole = OutputLevel::Error;
-        const OutputLevel::Value defaultLevelLogFile = OutputLevel::Info;
+        const OutputLevel::Value initialLevelConsole = OutputLevel::Error;
 #else
-        const OutputLevel::Value defaultLevelConsole = OutputLevel::Info;
-        const OutputLevel::Value defaultLevelLogFile = OutputLevel::Debug;
+        const OutputLevel::Value initialLevelConsole = OutputLevel::Info;
 #endif
+        // Use high log level because we rewrite the log file anyway with the
+        // correct level. But if Orxonox were to crash before that, we might be
+        // grateful to have a high debug level, esp. for releases.
+        const OutputLevel::Value intialLevelLogFile = OutputLevel::Debug;
 
         this->logFile_ = new LogFileWriter();
         // Use default level until we get the configValue from the Core
-        this->logFile_->softDebugLevel_ = defaultLevelLogFile;
+        this->logFile_->softDebugLevel_ = intialLevelLogFile;
         this->registerOutputListener(this->logFile_);
 
         this->consoleWriter_ = new ConsoleWriter();
-        this->consoleWriter_->softDebugLevel_ = defaultLevelConsole;
+        this->consoleWriter_->softDebugLevel_ = initialLevelConsole;
         this->registerOutputListener(this->consoleWriter_);
 
-        this->output_ = new MemoryLogWriter();
-        // We capture as much input as the listener with the highest level
-        this->output_->softDebugLevel_ = getSoftDebugLevel();
-        this->registerOutputListener(this->output_);
+        this->memoryBuffer_ = new MemoryLogWriter();
+        // Write everything, e.g. use hardDebugLevel
+        this->memoryBuffer_->softDebugLevel_ = hardDebugLevel;
+        this->registerOutputListener(this->memoryBuffer_);
     }
 
@@ -223,5 +246,5 @@
         delete this->logFile_;
         delete this->consoleWriter_;
-        delete this->output_;
+        delete this->memoryBuffer_; // Might already be NULL
     }
 
@@ -234,5 +257,5 @@
     void OutputHandler::registerOutputListener(OutputListener* listener)
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == listener->name_)
@@ -243,11 +266,18 @@
         }
         this->listeners_.push_back(listener);
-        // Update global soft debug level
-        this->setSoftDebugLevel(listener->getOutputListenerName(), listener->getSoftDebugLevel());
+        this->updateGlobalDebugLevel();
     }
 
     void OutputHandler::unregisterOutputListener(OutputListener* listener)
     {
-        this->listeners_.remove(listener);
+        for (std::vector<OutputListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        {
+            if ((*it)->name_ == listener->name_)
+            {
+                this->listeners_.erase(it);
+                break;
+            }
+        }
+        this->updateGlobalDebugLevel();
     }
 
@@ -255,4 +285,20 @@
     {
         this->logFile_->setLogPath(path);
+        this->rewriteLogFile();
+    }
+
+    void OutputHandler::rewriteLogFile()
+    {
+        logFile_->clearFile();
+
+        if (logFile_->outputStream_ == NULL)
+            return;
+
+        for (OutputVector::const_iterator it = this->getOutput().begin(); it != this->getOutput().end(); ++it)
+        {
+            if (it->first <= logFile_->softDebugLevel_)
+                (*logFile_->outputStream_) << it->second;
+        }
+        logFile_->outputStream_->flush();
     }
 
@@ -267,17 +313,19 @@
     }
 
-    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const
-    {
-        return this->output_->output_.begin();
-    }
-
-    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorEnd() const
-    {
-        return this->output_->output_.end();
+    void OutputHandler::disableMemoryLog()
+    {
+        this->unregisterOutputListener(this->memoryBuffer_);
+        // Only clear the buffer so we can still reference the vector
+        this->memoryBuffer_->output_.clear();
+    }
+
+    const OutputHandler::OutputVector& OutputHandler::getOutput() const
+    {
+        return this->memoryBuffer_->output_;
     }
 
     int OutputHandler::getSoftDebugLevel(const std::string& name) const
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == name)
@@ -289,13 +337,19 @@
     void OutputHandler::setSoftDebugLevel(const std::string& name, int level)
     {
-        int globalSoftDebugLevel = -1;
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if ((*it)->name_ == name)
                 (*it)->softDebugLevel_ = level;
-            if ((*it)->softDebugLevel_ > globalSoftDebugLevel)
-                globalSoftDebugLevel = (*it)->softDebugLevel_;
-        }
-        // Update global soft debug level
+        }
+        this->updateGlobalDebugLevel();
+    }
+
+    void OutputHandler::updateGlobalDebugLevel()
+    {
+        int globalSoftDebugLevel = -1;
+        std::vector<OutputListener*>::const_iterator it = this->listeners_.begin();
+        for (; it != this->listeners_.end(); ++it)
+            globalSoftDebugLevel = std::max(globalSoftDebugLevel, (*it)->softDebugLevel_);
+
         OutputHandler::softDebugLevel_s = globalSoftDebugLevel;
     }
Index: /code/trunk/src/libraries/util/OutputHandler.h
===================================================================
--- /code/trunk/src/libraries/util/OutputHandler.h	(revision 8728)
+++ /code/trunk/src/libraries/util/OutputHandler.h	(revision 8729)
@@ -39,5 +39,4 @@
 #include "UtilPrereqs.h"
 
-#include <list>
 #include <ostream>
 #include <string>
@@ -63,4 +62,5 @@
         enum Value
         {
+            TDebug  = -1,
             None    = 0,
             Error   = 1,
@@ -103,9 +103,7 @@
                 { return OutputHandler::getInstance().setOutputLevel(level); }
 
-            typedef std::vector<std::pair<int, std::string> >::const_iterator OutputVectorIterator;
-            //! Returns an iterator to the beginning of the all-output vector
-            OutputVectorIterator getOutputVectorBegin() const;
-            //! Returns an iterator to the end of the all-output vector
-            OutputVectorIterator getOutputVectorEnd() const;
+            typedef std::vector<std::pair<int, std::string> > OutputVector;
+            //! Returns all output written so far (empty if disableMemoryLog() was called)
+            const OutputVector& getOutput() const;
 
             //! Writes to all output devices
@@ -136,8 +134,15 @@
             //! Set the log path once the program has been properly initialised
             void setLogPath(const std::string& path);
+            /** Rewrites the log file (completely respects the current debug level).
+                Once disableMemoryLog() has been called, this function will do nothing.
+            */
+            void rewriteLogFile();
+
             //! Disables the std::cout stream for output
             void disableCout();
             //! Enables the std::cout stream for output (startup behaviour)
             void enableCout();
+            //! Stop writing to the memory buffer (call this as soon as possible to minimise memory usage)
+            void disableMemoryLog();
 
             //! Sets the level of the incoming output and returns the OutputHandler
@@ -213,7 +218,4 @@
             inline operator int() const { return 0; }
 
-            //! Name of the OutputListener that writes to the log file
-            static const std::string logFileOutputListenerName_s;
-
         private:
             OutputHandler();
@@ -221,10 +223,13 @@
             OutputHandler(const OutputHandler& rhs);      //!< Copy-constructor: Unused and undefined
 
-            std::list<OutputListener*> listeners_;        //!< Array with all registered output listeners
-            int                        outputLevel_;      //!< The level of the incoming output
-            LogFileWriter*             logFile_;          //!< Listener that writes to the log file
-            ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
-            MemoryLogWriter*           output_;           //!< Listener that Stores ALL output below the current soft debug level
-            static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
+            /// Evaluates the maximum global log level
+            void updateGlobalDebugLevel();
+
+            std::vector<OutputListener*> listeners_;        //!< Array with all registered output listeners
+            int                          outputLevel_;      //!< The level of the incoming output
+            LogFileWriter*               logFile_;          //!< Writes output to the log file
+            ConsoleWriter*               consoleWriter_;    //!< Writes to std::cout (can be disabled)
+            MemoryLogWriter*             memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
+            static int                   softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
     };
 
@@ -251,12 +256,4 @@
         //! Returns the name of this output listener
         const std::string& getOutputListenerName() const { return this->name_; }
-        //! Returns the soft debug level of the listener
-        int getSoftDebugLevel() const { return this->softDebugLevel_; }
-        //! Sets the soft debug level of the listener
-        void setSoftDebugLevel(int level)
-        {
-            this->softDebugLevel_ = level;
-            OutputHandler::getInstance().setSoftDebugLevel(this->name_, level);
-        }
 
     protected:
@@ -271,5 +268,5 @@
     inline OutputHandler& OutputHandler::output(const T& output)
     {
-        for (std::list<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
+        for (std::vector<OutputListener*>::const_iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)
         {
             if (this->outputLevel_ <= (*it)->softDebugLevel_ && (*it)->outputStream_ != NULL)
Index: de/trunk/src/libraries/util/TriBool.h
===================================================================
--- /code/trunk/src/libraries/util/TriBool.h	(revision 8728)
+++ 	(revision )
@@ -1,59 +1,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__ */
Index: /code/trunk/src/libraries/util/UtilPrereqs.h
===================================================================
--- /code/trunk/src/libraries/util/UtilPrereqs.h	(revision 8728)
+++ /code/trunk/src/libraries/util/UtilPrereqs.h	(revision 8729)
@@ -87,6 +87,4 @@
     class Exception;
     class ExprParser;
-    class IntVector2;
-    class IntVector3;
     class MultiType;
     class OutputHandler;
Index: /code/trunk/src/libraries/util/tribool.h
===================================================================
--- /code/trunk/src/libraries/util/tribool.h	(revision 8729)
+++ /code/trunk/src/libraries/util/tribool.h	(revision 8729)
@@ -0,0 +1,138 @@
+// 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 {
+
+/**
+ * INTERNAL ONLY
+ * The type of the 'dontcare' keyword.
+ */
+struct dontcare_keyword_t { };
+
+/**
+ * \brief Keyword for the dontcare tribool value
+ */
+const dontcare_keyword_t dontcare = dontcare_keyword_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) {}
+
+  /**
+   * \brief Compare tribools for equality
+   *
+   * \returns the result of comparing two tribool values.
+   * \throws nothrow
+   */
+  inline bool operator==(tribool y)
+  {
+    return (this->value == y.value);
+  }
+
+  /**
+   * \overload
+   */
+  inline bool operator==(bool y) { return (*this) == tribool(y); }
+
+  /**
+   * \overload
+   */
+  inline bool operator==(dontcare_keyword_t)
+  { return tribool(dontcare) == (*this); }
+
+  /**
+   * \brief Compare tribools for inequality
+   *
+   * \returns the result of comparing two tribool values for inequality.
+   * \throws nothrow
+   */
+  inline bool operator!=(tribool y)
+  {
+    return !((*this) == y);
+  }
+
+  /**
+   * \overload
+   */
+  inline bool operator!=(bool y) { return (*this) != tribool(y); }
+
+  /**
+   * \overload
+   */
+  inline bool operator!=(dontcare_keyword_t)
+  { return (*this) != tribool(dontcare); }
+
+  /**
+   * 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;
+};
+
+/**
+ * \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!=(bool x, tribool y) { return tribool(x) != y; }
+
+/**
+ * \overload
+ */
+inline bool operator!=(dontcare_keyword_t, tribool x)
+{ return tribool(dontcare) != x; }
+
+} // end namespace orxonox
+
+#endif // ORXONOX_TRIBOOL_H
+
Index: /code/trunk/src/modules/docking/Dock.cc
===================================================================
--- /code/trunk/src/modules/docking/Dock.cc	(revision 8728)
+++ /code/trunk/src/modules/docking/Dock.cc	(revision 8729)
@@ -44,11 +44,6 @@
 #include "worldentities/pawns/Pawn.h"
 
-#include "ToluaBindDocking.h"
-
 namespace orxonox
 {
-    // Register tolua_open function when loading the library
-    DeclareToluaInterface(Docking);
-
     CreateFactory(Dock);
 
Index: /code/trunk/src/modules/notifications/NotificationQueueCEGUI.cc
===================================================================
--- /code/trunk/src/modules/notifications/NotificationQueueCEGUI.cc	(revision 8728)
+++ /code/trunk/src/modules/notifications/NotificationQueueCEGUI.cc	(revision 8729)
@@ -43,13 +43,8 @@
 #include "util/Convert.h"
 
-#include "ToluaBindNotifications.h"
-
 namespace orxonox
 {
 
     CreateFactory(NotificationQueueCEGUI);
-
-    // Register tolua_open function when loading the library.
-    DeclareToluaInterface(Notifications);
 
     /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer");
Index: /code/trunk/src/modules/objects/eventsystem/EventFilter.cc
===================================================================
--- /code/trunk/src/modules/objects/eventsystem/EventFilter.cc	(revision 8728)
+++ /code/trunk/src/modules/objects/eventsystem/EventFilter.cc	(revision 8729)
@@ -30,4 +30,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/Event.h"
 #include "core/XMLPort.h"
 #include "EventName.h"
Index: /code/trunk/src/modules/objects/eventsystem/EventListener.cc
===================================================================
--- /code/trunk/src/modules/objects/eventsystem/EventListener.cc	(revision 8728)
+++ /code/trunk/src/modules/objects/eventsystem/EventListener.cc	(revision 8729)
@@ -30,4 +30,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/Event.h"
 #include "core/XMLPort.h"
 
Index: /code/trunk/src/modules/overlays/hud/GametypeFadingMessage.h
===================================================================
--- /code/trunk/src/modules/overlays/hud/GametypeFadingMessage.h	(revision 8728)
+++ /code/trunk/src/modules/overlays/hud/GametypeFadingMessage.h	(revision 8729)
@@ -27,6 +27,6 @@
  */
 
-#ifndef _GametypeInfoMessage_H__
-#define _GametypeInfoMessage_H__
+#ifndef _GametypeFadingMessage_H__
+#define _GametypeFadingMessage_H__
 
 #include "overlays/OverlaysPrereqs.h"
Index: /code/trunk/src/modules/pickup/PickupCollectionIdentifier.h
===================================================================
--- /code/trunk/src/modules/pickup/PickupCollectionIdentifier.h	(revision 8728)
+++ /code/trunk/src/modules/pickup/PickupCollectionIdentifier.h	(revision 8729)
@@ -34,5 +34,5 @@
 
 #ifndef _PickupCollectionIdentifier_H__
-#define _PickupCollectionIdentifier_H_
+#define _PickupCollectionIdentifier_H__
 
 #include "PickupPrereqs.h"
@@ -75,3 +75,3 @@
 }
 
-#endif // _PickupCollectionIdentifier_H_
+#endif // _PickupCollectionIdentifier_H__
Index: /code/trunk/src/modules/pickup/PickupManager.cc
===================================================================
--- /code/trunk/src/modules/pickup/PickupManager.cc	(revision 8728)
+++ /code/trunk/src/modules/pickup/PickupManager.cc	(revision 8729)
@@ -49,11 +49,6 @@
 #include "PickupRepresentation.h"
 
-#include "ToluaBindPickup.h"
-
 namespace orxonox
 {
-    // Register tolua_open function when loading the library
-    DeclareToluaInterface(Pickup);
-
     ManageScopedSingleton(PickupManager, ScopeID::Root, false);
 
Index: /code/trunk/src/modules/pong/CMakeLists.txt
===================================================================
--- /code/trunk/src/modules/pong/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/modules/pong/CMakeLists.txt	(revision 8729)
@@ -1,4 +1,4 @@
 SET_SOURCE_FILES(PONG_SRC_FILES
-COMPILATION_BEGIN PongCompilation.cc
+BUILD_UNIT PongBuildUnit.cc
   Pong.cc
   PongAI.cc
@@ -8,5 +8,5 @@
   PongCenterpoint.cc
   PongScore.cc
-COMPILATION_END
+END_BUILD_UNIT
 )
 
Index: /code/trunk/src/modules/pong/PongAI.cc
===================================================================
--- /code/trunk/src/modules/pong/PongAI.cc	(revision 8728)
+++ /code/trunk/src/modules/pong/PongAI.cc	(revision 8729)
@@ -36,4 +36,5 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
+#include "core/command/Executor.h"
 #include "tools/Timer.h"
 
Index: /code/trunk/src/modules/questsystem/QuestManager.cc
===================================================================
--- /code/trunk/src/modules/questsystem/QuestManager.cc	(revision 8728)
+++ /code/trunk/src/modules/questsystem/QuestManager.cc	(revision 8729)
@@ -47,11 +47,6 @@
 #include "QuestItem.h"
 
-#include "ToluaBindQuestsystem.h"
-
 namespace orxonox
 {
-    // Register tolua_open function when loading the library
-    DeclareToluaInterface(Questsystem);
-
     ManageScopedSingleton(QuestManager, ScopeID::Root, false);
 
Index: /code/trunk/src/modules/weapons/munitions/ReplenishingMunition.cc
===================================================================
--- /code/trunk/src/modules/weapons/munitions/ReplenishingMunition.cc	(revision 8728)
+++ /code/trunk/src/modules/weapons/munitions/ReplenishingMunition.cc	(revision 8729)
@@ -28,5 +28,7 @@
 
 #include "ReplenishingMunition.h"
+
 #include "core/CoreIncludes.h"
+#include "core/command/Executor.h"
 
 namespace orxonox
Index: /code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc
===================================================================
--- /code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc	(revision 8728)
+++ /code/trunk/src/modules/weapons/projectiles/LightningGunProjectile.cc	(revision 8729)
@@ -31,4 +31,5 @@
 #include "util/Convert.h"
 #include "core/CoreIncludes.h"
+#include "core/command/Executor.h"
 
 namespace orxonox
Index: /code/trunk/src/orxonox/CMakeLists.txt
===================================================================
--- /code/trunk/src/orxonox/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/orxonox/CMakeLists.txt	(revision 8729)
@@ -35,8 +35,9 @@
   ChatInputHandler.cc
 #  Test.cc
-COMPILATION_BEGIN SceneCompilation.cc
+
+BUILD_UNIT SceneBuildUnit.cc
   CameraManager.cc
   Scene.cc
-COMPILATION_END
+END_BUILD_UNIT
 )
 
Index: /code/trunk/src/orxonox/Main.cc
===================================================================
--- /code/trunk/src/orxonox/Main.cc	(revision 8728)
+++ /code/trunk/src/orxonox/Main.cc	(revision 8729)
@@ -39,9 +39,4 @@
 #include "core/Game.h"
 #include "core/LuaState.h"
-#include "ToluaBindOrxonox.h"
-#include "ToluaBindNetwork.h"
-
-DeclareToluaInterface(Orxonox);
-DeclareToluaInterface(Network);
 
 namespace orxonox
Index: /code/trunk/src/orxonox/controllers/AIController.cc
===================================================================
--- /code/trunk/src/orxonox/controllers/AIController.cc	(revision 8728)
+++ /code/trunk/src/orxonox/controllers/AIController.cc	(revision 8729)
@@ -37,5 +37,5 @@
 namespace orxonox
 {
-    static const float ACTION_INTERVAL = 1.0f;
+    const float AIController::ACTION_INTERVAL = 1.0f;
 
     CreateFactory(AIController);
Index: /code/trunk/src/orxonox/controllers/AIController.h
===================================================================
--- /code/trunk/src/orxonox/controllers/AIController.h	(revision 8728)
+++ /code/trunk/src/orxonox/controllers/AIController.h	(revision 8729)
@@ -50,4 +50,6 @@
 
         private:
+            static const float ACTION_INTERVAL;
+
             Timer actionTimer_;
     };
Index: /code/trunk/src/orxonox/controllers/DroneController.cc
===================================================================
--- /code/trunk/src/orxonox/controllers/DroneController.cc	(revision 8728)
+++ /code/trunk/src/orxonox/controllers/DroneController.cc	(revision 8729)
@@ -43,5 +43,5 @@
     CreateFactory(DroneController);
 
-    static const float ACTION_INTERVAL = 1.0f;
+    const float DroneController::ACTION_INTERVAL = 1.0f;
 
     DroneController::DroneController(BaseObject* creator) : ArtificialController(creator)
Index: /code/trunk/src/orxonox/controllers/DroneController.h
===================================================================
--- /code/trunk/src/orxonox/controllers/DroneController.h	(revision 8728)
+++ /code/trunk/src/orxonox/controllers/DroneController.h	(revision 8729)
@@ -69,4 +69,6 @@
 
         private:
+            static const float ACTION_INTERVAL;
+
             Timer actionTimer_;
             WeakPtr<Pawn> owner_;
Index: /code/trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- /code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 8728)
+++ /code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 8729)
@@ -77,10 +77,10 @@
         {
             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());
 
Index: /code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
===================================================================
--- /code/trunk/src/orxonox/gametypes/Dynamicmatch.cc	(revision 8728)
+++ /code/trunk/src/orxonox/gametypes/Dynamicmatch.cc	(revision 8729)
@@ -48,4 +48,5 @@
 #include "util/Convert.h"
 #include "core/CoreIncludes.h"
+#include "core/command/Executor.h"
 #include "network/Host.h"
 #include "infos/PlayerInfo.h"
Index: /code/trunk/src/orxonox/graphics/CMakeLists.txt
===================================================================
--- /code/trunk/src/orxonox/graphics/CMakeLists.txt	(revision 8728)
+++ /code/trunk/src/orxonox/graphics/CMakeLists.txt	(revision 8729)
@@ -9,8 +9,9 @@
   ParticleEmitter.cc
   ParticleSpawner.cc
-COMPILATION_BEGIN GraphicsCompilation.cc
+
+BUILD_UNIT GraphicsBuildUnit.cc
   Backlight.cc
   Camera.cc
   Light.cc
-COMPILATION_END
+END_BUILD_UNIT
 )
Index: /code/trunk/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- /code/trunk/src/orxonox/overlays/InGameConsole.cc	(revision 8728)
+++ /code/trunk/src/orxonox/overlays/InGameConsole.cc	(revision 8729)
@@ -91,4 +91,8 @@
         this->setConfigValues();
         this->initialise();
+
+        // Output buffering is not anymore needed. Not the best solution to do
+        // this here, but there isn't much of another way.
+        OutputHandler::getInstance().disableMemoryLog();
     }
 
@@ -586,4 +590,7 @@
                           colourBottom = ColourValue(0.90f, 0.90f, 0.90f, 1.00f); break;
 
+        case Shell::TDebug:  colourTop = ColourValue(0.90f, 0.00f, 0.90f, 1.00f);
+                          colourBottom = ColourValue(1.00f, 0.00f, 1.00f, 1.00f); break;
+
         default:             colourTop = ColourValue(0.90f, 0.90f, 0.90f, 1.00f);
                           colourBottom = ColourValue(1.00f, 1.00f, 1.00f, 1.00f); break;
Index: /code/trunk/src/orxonox/sound/BaseSound.cc
===================================================================
--- /code/trunk/src/orxonox/sound/BaseSound.cc	(revision 8728)
+++ /code/trunk/src/orxonox/sound/BaseSound.cc	(revision 8729)
@@ -61,5 +61,6 @@
     BaseSound::~BaseSound()
     {
-        this->stop();
+        if (this->state_ != Stopped)
+            this->stop();
         // Release buffer
         if (this->soundBuffer_ != NULL)
Index: /code/trunk/src/orxonox/weaponsystem/Munition.cc
===================================================================
--- /code/trunk/src/orxonox/weaponsystem/Munition.cc	(revision 8728)
+++ /code/trunk/src/orxonox/weaponsystem/Munition.cc	(revision 8729)
@@ -29,5 +29,7 @@
 
 #include "Munition.h"
+
 #include "core/CoreIncludes.h"
+#include "core/command/Executor.h"
 
 namespace orxonox
Index: /code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
===================================================================
--- /code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc	(revision 8728)
+++ /code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc	(revision 8729)
@@ -30,4 +30,5 @@
 
 #include "core/CoreIncludes.h"
+#include "core/SubclassIdentifier.h"
 #include "worldentities/pawns/Pawn.h"
 
