diff --git a/.gitignore b/.gitignore index 5d10137..ba672da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .vs/* +.vscode/* bin/* Ext/* +Ext* lib/* x64/* CMakeFiles/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 3914ba5..9dd531e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ INCLUDE (UtilityMacros) INCLUDE (Version) # Defines the project name -PROJECT (TrueReality-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR} VERSION ${TR_VERSION} LANGUAGES CXX) +PROJECT (TrueReality-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_YYMM} VERSION ${TR_VERSION} LANGUAGES CXX) # Sets up the install options INCLUDE (InstallMacros) @@ -61,6 +61,11 @@ CMAKE_DEPENDENT_OPTION (TR_APP "Enables the building of trApp library" ON "TR_CO # ***************************************************************************** # Sets Advanced options *********************************************************** # ***************************************************************************** +OPTION (TR_INSTALL_INTEGRATED_EXT "Sets the Ext folder to be integrated on Install into bin/lib/install folders of TR. \ +If OFF the folder will be copied unchanged as the whole Ext folder and the user will need to manually setup paths to the Ext resources." ON) +MARK_AS_ADVANCED (TR_INSTALL_INTEGRATED_EXT) +OPTION (TR_INSTALL_ENVIRONMENT_SCRIPTS "Install TR environment scripts into a System folder. You need Admin privleges for this." OFF) +MARK_AS_ADVANCED (TR_INSTALL_ENVIRONMENT_SCRIPTS) OPTION (TR_USE_DOUBLE_MATRIX "Set to OFF to build TR with float Matrix instead of double." ON) MARK_AS_ADVANCED (TR_USE_DOUBLE_MATRIX) OPTION (TR_USE_DOUBLE_VECTOR "Set to OFF to build TR with float Vector instead of double." ON) diff --git a/CMakeModules/FindGoogleTest.cmake b/CMakeModules/FindGoogleTest.cmake index 9230348..a06822d 100644 --- a/CMakeModules/FindGoogleTest.cmake +++ b/CMakeModules/FindGoogleTest.cmake @@ -88,6 +88,6 @@ IF (TR_BUILD_WITH_DEBUG) ENDIF () SET (${DEPENDENCY}_FOUND "NO") -IF (${DEPENDENCY}_INCLUDE_DIR) +IF ((${DEPENDENCY}_LIBRARY OR ${DEPENDENCY}_LIBRARY_DEBUG) AND ${DEPENDENCY}_INCLUDE_DIR) SET (${DEPENDENCY}_FOUND "YES") ENDIF () \ No newline at end of file diff --git a/CMakeModules/FindJsonCpp.cmake b/CMakeModules/FindJsonCpp.cmake index d6e473e..93e9d00 100644 --- a/CMakeModules/FindJsonCpp.cmake +++ b/CMakeModules/FindJsonCpp.cmake @@ -83,6 +83,6 @@ IF (TR_BUILD_WITH_DEBUG) ENDIF () SET (${DEPENDENCY}_FOUND "NO") -IF (${DEPENDENCY}_INCLUDE_DIR) +IF ((${DEPENDENCY}_LIBRARY OR ${DEPENDENCY}_LIBRARY_DEBUG) AND ${DEPENDENCY}_INCLUDE_DIR) SET (${DEPENDENCY}_FOUND "YES") ENDIF () diff --git a/CMakeModules/FindOSG.cmake b/CMakeModules/FindOSG.cmake index 48717fb..d818a46 100644 --- a/CMakeModules/FindOSG.cmake +++ b/CMakeModules/FindOSG.cmake @@ -209,7 +209,7 @@ IF (TR_BUILD_WITH_DEBUG) ENDIF () SET (${DEPENDENCY}_FOUND "NO") -IF (${DEPENDENCY}_LIBRARY AND ${DEPENDENCY}_INCLUDE_DIR) +IF ((${DEPENDENCY}_LIBRARY OR ${DEPENDENCY}_LIBRARY_DEBUG) AND ${DEPENDENCY}_INCLUDE_DIR) SET (${DEPENDENCY}_FOUND "YES") IF (${DEPENDENCY}_FIND_VERSION) diff --git a/CMakeModules/FindOpenThreads.cmake b/CMakeModules/FindOpenThreads.cmake index 30738da..4269f53 100644 --- a/CMakeModules/FindOpenThreads.cmake +++ b/CMakeModules/FindOpenThreads.cmake @@ -89,6 +89,6 @@ IF (TR_BUILD_WITH_DEBUG) ENDIF () SET (${DEPENDENCY}_FOUND "NO") -IF (${DEPENDENCY}_LIBRARY AND ${DEPENDENCY}_INCLUDE_DIR) +IF ((${DEPENDENCY}_LIBRARY OR ${DEPENDENCY}_LIBRARY_DEBUG) AND ${DEPENDENCY}_INCLUDE_DIR) SET (${DEPENDENCY}_FOUND "YES") ENDIF () \ No newline at end of file diff --git a/CMakeModules/InstallMacros.cmake b/CMakeModules/InstallMacros.cmake index d2caf23..ceaa378 100644 --- a/CMakeModules/InstallMacros.cmake +++ b/CMakeModules/InstallMacros.cmake @@ -29,7 +29,7 @@ SET (TR_HEADERS_INSTALLED "0" CACHE INTERNAL "System Use only: flag to show that # Sets up default Windows install folders # ***************************************************************************** -IF(WIN32 AND NOT PATH_IS_SET) +IF (WIN32 AND NOT PATH_IS_SET) IF (CMAKE_SIZEOF_VOID_P MATCHES "8") SET (CMAKE_INSTALL_PREFIX "C:/Program Files/${CMAKE_PROJECT_NAME}" CACHE STRING "Install Path" FORCE) ELSE () @@ -50,8 +50,12 @@ MACRO (TR_INSTALL_OPTIONS arg) IF (TR_EXT_INSTALLED EQUAL 0) INSTALL (CODE "MESSAGE(\"Installing the External Dependencies.\")") - IF(EXISTS "${CMAKE_SOURCE_DIR}/Ext") - INSTALL (DIRECTORY "${CMAKE_SOURCE_DIR}/Ext/" DESTINATION .) + IF (EXISTS "${CMAKE_SOURCE_DIR}/Ext") + IF (TR_INSTALL_INTEGRATED_EXT) + INSTALL (DIRECTORY "${CMAKE_SOURCE_DIR}/Ext/" DESTINATION .) + ELSE () + INSTALL (DIRECTORY "${CMAKE_SOURCE_DIR}/Ext" DESTINATION .) + ENDIF () SET (TR_EXT_INSTALLED "1" CACHE INTERNAL "System Use only: flag to show that the Ext folder was installed" FORCE) ELSE () INSTALL (CODE "MESSAGE(\"Ext folder is missing from ${CMAKE_SOURCE_DIR}\")") @@ -77,6 +81,19 @@ MACRO (TR_INSTALL_OPTIONS arg) ) ENDMACRO () +# ***************************************************************************** +# Configures the installation options for the environment scripts project ***** +# ***************************************************************************** +MACRO (TR_INSTALL_SCRIPT_FILES filesList) + IF (WIN32) + INSTALL (CODE "MESSAGE(\"Installing the Environment Scripts.\")") + INSTALL (FILES ${filesList} DESTINATION $ENV{windir}) + ELSEIF (UNIX) + INSTALL (CODE "MESSAGE(\"Installing the Environment Scripts.\")") + INSTALL (FILES ${filesList} DESTINATION /usr/local/bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + ENDIF () +ENDMACRO () + # ***************************************************************************** # Configures the build folder, making sure it has all the needed data files *** # ***************************************************************************** diff --git a/CMakeModules/PlatformConfiguration.cmake b/CMakeModules/PlatformConfiguration.cmake index 9301968..a75be8a 100644 --- a/CMakeModules/PlatformConfiguration.cmake +++ b/CMakeModules/PlatformConfiguration.cmake @@ -52,7 +52,7 @@ ELSE () ENDIF () # Sets the Debug and Release library naming formats, but not executables. -IF (TR_BUILD_VERSIONED_LIBRARIES) +IF (TR_BUILD_VERSIONED_LIBRARIES) IF (WIN32) SET (CMAKE_SHARED_LIBRARY_PREFIX ${TR_SO_PREFIX}) SET (CMAKE_STATIC_LIBRARY_PREFIX ${TR_SO_PREFIX}) @@ -62,7 +62,7 @@ IF (TR_BUILD_VERSIONED_LIBRARIES) ENDIF () ENDIF () -# Sets the postfix on libraries. +# Sets the postfix on libraries. SET (CMAKE_DEBUG_POSTFIX "-d" CACHE STRING "Set Debug library postfix" FORCE) SET (CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set Release library postfix" FORCE) SET (CMAKE_RELWITHDEBINFO_POSTFIX "-rd" CACHE STRING "Set RelWithDebInfo library postfix" FORCE) @@ -86,7 +86,7 @@ ENDIF () IF (UNIX) MESSAGE (STATUS "\nConfiguring for Unix") READ_GCC_VERSION() - SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-non-virtual-dtor -Wreturn-type") + SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-non-virtual-dtor -Wreturn-type -Werror") SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread") MESSAGE (STATUS "GCC Version: ${GCC_MAJOR}.${GCC_MINOR}") @@ -96,39 +96,37 @@ IF (UNIX) OPTION (CMAKE_VERBOSE_MAKEFILE "Users may enable the option in their local build tree to get more verbose output from Makefile builds and show each command line as it is launched." ON) OPTION (CMAKE_COLOR_MAKEFILE "When enabled, the generated Makefiles will produce colored output. Default is ON" ON) - IF (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR CMAKE_INSTALL_PREFIX STREQUAL "/usr/local/") - SET (CMAKE_INSTALL_PREFIX "/usr/local/${PROJECT_NAME}" CACHE STRING "TrueReality default install folder" FORCE) - ELSEIF (CMAKE_INSTALL_PREFIX STREQUAL "/opt" OR CMAKE_INSTALL_PREFIX STREQUAL "/opt/") - SET (CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}" CACHE STRING "TrueReality default install folder" FORCE) - ENDIF () + IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + SET (CMAKE_INSTALL_PREFIX "/usr/local/${PROJECT_NAME}" CACHE STRING "TrueReality default install folder" FORCE) + ENDIF () ENDIF () IF (WIN32) MESSAGE (STATUS "\nConfiguring for Windows") IF (MSVC_IDE) - - # Enables folder creation in VS projects. + + # Enables folder creation in VS projects. SET_PROPERTY (GLOBAL PROPERTY USE_FOLDERS ON) - + # Set all the initial CXX options - SET (CMAKE_CXX_FLAGS " /DWIN32 /D_WINDOWS /W3 /GR /EHsc /nologo") + SET (CMAKE_CXX_FLAGS " /DWIN32 /D_WINDOWS /W3 /WX /GR /EHsc /nologo") SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /std:c++17") #This is used because cmake 3.14.3 has a bug. Check later if it can be removed # Enable multi-core builds - OPTION (TR_BUILD_WITH_MP "Enables the /MP multi-processor compiler option for Visual Studio 2005 and above" ON) + OPTION (TR_BUILD_WITH_MP "Enables the /MP multi-processor compiler option for Visual Studio 2005 and above" ON) MARK_AS_ADVANCED (TR_BUILD_WITH_MP) IF (TR_BUILD_WITH_MP) SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") ENDIF () - + # Enable strict checking OPTION (TR_BUILD_WITH_STRICT "Enables the Option STRICT for VS compiler" ON) MARK_AS_ADVANCED (TR_BUILD_WITH_STRICT) IF (TR_BUILD_WITH_STRICT) SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTRICT") ENDIF () - + # Reduce the number of default headers included in a VS build OPTION (TR_BUILD_WITH_LEAN_AND_MEAN "Enables the option LEAN_AND_MEAN for VS compiler, to speed up compilation" ON) MARK_AS_ADVANCED (TR_BUILD_WITH_LEAN_AND_MEAN) @@ -138,7 +136,7 @@ IF (WIN32) #If we are using Boost IF (BoostLibs_FOUND) - #Sets temporary warning suppression flags. These should be revisited and rechecked at every VS version and Ext dependency change. + #Sets temporary warning suppression flags. These should be revisited and rechecked at every VS version and Ext dependency change. SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE") #Boost has a bug with using an old config file with VS2017 SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DBOOST_ALL_DYN_LINK") #Force only boost dynamic libraries to be used LINK_DIRECTORIES (${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS}) #Force all projects to have boost dirs as aditional library paths diff --git a/CMakeModules/UtilityMacros.cmake b/CMakeModules/UtilityMacros.cmake index a226a2b..f5319da 100644 --- a/CMakeModules/UtilityMacros.cmake +++ b/CMakeModules/UtilityMacros.cmake @@ -65,6 +65,11 @@ MACRO (ADD_TR_SUBFOLDERS) SET (TR_VERSION_UTIL_AVAILABLE "YES") ENDIF () + IF (TR_INSTALL_ENVIRONMENT_SCRIPTS) + ADD_SUBDIRECTORY (Scripts) + SET (TR_INSTALL_ENVIRONMENT_SCRIPTS_AVAILABLE "YES") + ENDIF () + # Examples folders MESSAGE (STATUS "Creating Selected Example Folders") diff --git a/Data/FindTR.cmake b/Data/FindTR.cmake index d4f3877..fd86942 100644 --- a/Data/FindTR.cmake +++ b/Data/FindTR.cmake @@ -166,14 +166,16 @@ TR_FIND_LIBRARY(UTIL trUtil) # Sets TR_FOUND flag if we have TR of the version the user asked for SET (${DEPENDENCY}_FOUND "NO") -IF (${DEPENDENCY}_APP_LIBRARY_FOUND AND ${DEPENDENCY}_BASE_LIBRARY_FOUND AND ${DEPENDENCY}_CORE_LIBRARY_FOUND AND ${DEPENDENCY}_MANAGER_LIBRARY_FOUND AND ${DEPENDENCY}_SG_LIBRARY_FOUND AND ${DEPENDENCY}_UTIL_LIBRARY_FOUND ) +IF ((${DEPENDENCY}_APP_LIBRARY_FOUND AND ${DEPENDENCY}_BASE_LIBRARY_FOUND AND ${DEPENDENCY}_CORE_LIBRARY_FOUND AND ${DEPENDENCY}_MANAGER_LIBRARY_FOUND AND ${DEPENDENCY}_SG_LIBRARY_FOUND AND ${DEPENDENCY}_UTIL_LIBRARY_FOUND) OR + (${DEPENDENCY}_APP_DEBUG_LIBRARY_FOUND AND ${DEPENDENCY}_BASE_DEBUG_LIBRARY_FOUND AND ${DEPENDENCY}_CORE_DEBUG_LIBRARY_FOUND AND ${DEPENDENCY}_MANAGER_DEBUG_LIBRARY_FOUND AND ${DEPENDENCY}_SG_DEBUG_LIBRARY_FOUND AND ${DEPENDENCY}_UTIL_DEBUG_LIBRARY_FOUND)) # All the library header folders should be in the same place, so we can just use the Core libraries path - SET(${DEPENDENCY}_INCLUDE_DIR ${${DEPENDENCY}_CORE_INCLUDE_DIR}) - - # Detect what version of True Reality was found, if any - SET (TR_VERSION_FILE "${${DEPENDENCY}_INCLUDE_DIR}/../Data/Config/Version.trver") - FILE (READ ${TR_VERSION_FILE} TR_VERSION_CONTENT) + IF (TR_BUILD_WITH_RELEASE) + SET(${DEPENDENCY}_INCLUDE_DIR ${${DEPENDENCY}_CORE_INCLUDE_DIR}) + ENDIF () + IF (TR_BUILD_WITH_DEBUG) + SET(${DEPENDENCY}_INCLUDE_DIR ${${DEPENDENCY}_CORE_DEBUG_INCLUDE_DIR}) + ENDIF () IF ("${TR_VERSION_CONTENT}" STREQUAL "") MESSAGE("Missing the version file") diff --git a/Examples/ActorModules/Application.cpp b/Examples/ActorModules/Application.cpp index 5f9fe22..b0e1cf6 100644 --- a/Examples/ActorModules/Application.cpp +++ b/Examples/ActorModules/Application.cpp @@ -1,54 +1,54 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Application.h" -#include "TestActor.h" -#include "TestDirector.h" - -#include -#include - -const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); - -////////////////////////////////////////////////////////////////////////// -Application::Application(const std::string& name) : BaseClass(name) -{ - //Create Test Actor 1 - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating Test Actor. " << std::endl; - mSysMan->RegisterActor(*new TestActor()); - - //Create Test Director - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating a Test Director. " << std::endl; - mSysMan->RegisterDirector(*new TestDirector(), trManager::DirectorPriority::NORMAL); -} - -////////////////////////////////////////////////////////////////////////// -const std::string& Application::GetType() const -{ - return CLASS_TYPE; -} - -////////////////////////////////////////////////////////////////////////// -Application::~Application() -{ -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Application.h" +#include "TestActor.h" +#include "TestDirector.h" + +#include +#include + +const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); + +////////////////////////////////////////////////////////////////////////// +Application::Application(const std::string& name) : BaseClass(name) +{ + //Create Test Actor 1 + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating Test Actor. " << std::endl; + mSysMan->RegisterActor(*new TestActor()); + + //Create Test Director + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating a Test Director. " << std::endl; + mSysMan->RegisterDirector(*new TestDirector(), trManager::DirectorPriority::NORMAL); +} + +////////////////////////////////////////////////////////////////////////// +const std::string& Application::GetType() const +{ + return CLASS_TYPE; +} + +////////////////////////////////////////////////////////////////////////// +Application::~Application() +{ +} diff --git a/Examples/ActorModules/Application.h b/Examples/ActorModules/Application.h index 4760b87..5cd7e02 100644 --- a/Examples/ActorModules/Application.h +++ b/Examples/ActorModules/Application.h @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -class Application : public trApp::AppBase -{ -public: - using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn Application::Application(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - Application(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& Application::GetType() const override; - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - -protected: - - /** - * @fn Application::~Application(); - * - * @brief Destructor. - */ - ~Application(); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +class Application : public trApp::AppBase +{ +public: + using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn Application::Application(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + Application(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& Application::GetType() const override; + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + +protected: + + /** + * @fn Application::~Application(); + * + * @brief Destructor. + */ + ~Application(); +}; + diff --git a/Examples/ActorModules/Main.cpp b/Examples/ActorModules/Main.cpp index 0afff4c..ee95c64 100644 --- a/Examples/ActorModules/Main.cpp +++ b/Examples/ActorModules/Main.cpp @@ -1,83 +1,83 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Utils.h" -#include "Application.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -/** -* Software's main function. -*/ -int main(int argc, char** argv) -{ - std::string logFileName; - std::string logLevel; - - //Parse command line arguments - ParseCmdLineArgs(argc, argv, logFileName, logLevel); - - //Creates the default folders in the User Data folder. - trUtil::PathUtils::CreateUserDataPathTree(); - - //Setup our Logging options - trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); - - try - { - //Show Logo - trUtil::Console::Logo(); - - //Create the App and System handlers - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating The App. " << std::endl; - trBase::SmrtPtr mApp = new Application(); - - //Start the App Loop - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Starting the Run Loop... " << std::endl; - mApp->Run(); - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Ending the Run Loop... " << std::endl; - - //Ending program - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cerr << "True Reality is now shutting down ... " << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); - LOG_A("True Reality is now shutting down ... "); - - } - catch (const trUtil::Exception& ex) - { - LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); - ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); - return -1; - } - return 0; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Utils.h" +#include "Application.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +/** +* Software's main function. +*/ +int main(int argc, char** argv) +{ + std::string logFileName; + std::string logLevel; + + //Parse command line arguments + ParseCmdLineArgs(argc, argv, logFileName, logLevel); + + //Creates the default folders in the User Data folder. + trUtil::PathUtils::CreateUserDataPathTree(); + + //Setup our Logging options + trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); + + try + { + //Show Logo + trUtil::Console::Logo(); + + //Create the App and System handlers + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating The App. " << std::endl; + trBase::SmrtPtr mApp = new Application(); + + //Start the App Loop + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Starting the Run Loop... " << std::endl; + mApp->Run(); + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Ending the Run Loop... " << std::endl; + + //Ending program + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cerr << "True Reality is now shutting down ... " << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); + LOG_A("True Reality is now shutting down ... "); + + } + catch (const trUtil::Exception& ex) + { + LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); + ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); + return -1; + } + return 0; } \ No newline at end of file diff --git a/Examples/ActorModules/MessageTest.cpp b/Examples/ActorModules/MessageTest.cpp index 2da7c45..299dc1c 100644 --- a/Examples/ActorModules/MessageTest.cpp +++ b/Examples/ActorModules/MessageTest.cpp @@ -1,41 +1,41 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "MessageTest.h" - -const trUtil::RefStr MessageTest::MESSAGE_TYPE("MessageTest"); - -////////////////////////////////////////////////////////////////////////// -MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) - : BaseClass(fromActorID, aboutActorID) -{ -} - -////////////////////////////////////////////////////////////////////////// -MessageTest::~MessageTest() -{ -} - -////////////////////////////////////////////////////////////////////////// -const std::string& MessageTest::GetMessageType() const -{ - return MESSAGE_TYPE; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "MessageTest.h" + +const trUtil::RefStr MessageTest::MESSAGE_TYPE("MessageTest"); + +////////////////////////////////////////////////////////////////////////// +MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) + : BaseClass(fromActorID, aboutActorID) +{ +} + +////////////////////////////////////////////////////////////////////////// +MessageTest::~MessageTest() +{ +} + +////////////////////////////////////////////////////////////////////////// +const std::string& MessageTest::GetMessageType() const +{ + return MESSAGE_TYPE; } \ No newline at end of file diff --git a/Examples/ActorModules/MessageTest.h b/Examples/ActorModules/MessageTest.h index 833fc16..04c85a8 100644 --- a/Examples/ActorModules/MessageTest.h +++ b/Examples/ActorModules/MessageTest.h @@ -1,69 +1,69 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include -#include -#include - -#include - -/** - * @class MessageTest - * - * @brief This is an exmple of a simple message that is passed between actors. - */ -class MessageTest : public trManager::MessageBase -{ -public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param aboutActorID Identifier for the about actor. - */ - MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - - /** - * @fn virtual const std::string& MessageTest::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - -protected: - - /** - * @fn MessageTest::~MessageTest(); - * - * @brief Destructor. - */ - ~MessageTest(); -}; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include +#include +#include + +#include + +/** + * @class MessageTest + * + * @brief This is an exmple of a simple message that is passed between actors. + */ +class MessageTest : public trManager::MessageBase +{ +public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param aboutActorID Identifier for the about actor. + */ + MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + + /** + * @fn virtual const std::string& MessageTest::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + +protected: + + /** + * @fn MessageTest::~MessageTest(); + * + * @brief Destructor. + */ + ~MessageTest(); +}; diff --git a/Examples/ActorModules/TestActor.cpp b/Examples/ActorModules/TestActor.cpp index 31e1e6d..c97650c 100644 --- a/Examples/ActorModules/TestActor.cpp +++ b/Examples/ActorModules/TestActor.cpp @@ -1,64 +1,64 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor.h" -#include "TestActorModule1.h" - -#include -#include -#include - -const trUtil::RefStr TestActor::CLASS_TYPE("TestActor"); - -////////////////////////////////////////////////////////////////////////// -TestActor::TestActor(const std::string& name) : BaseClass(name) -{ - //Add a new Actor Module to the Actor - AddActorModule(*new TestActorModule1()); - - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActor::~TestActor() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActor::BuildInvokables() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActor::OnTick(const trManager::MessageBase& msg) -{ - //Send the tick message to all actor Modules. - ActorModuleTick(msg); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor::OnAddedToSysMan() -{ - BaseClass::OnAddedToSysMan(); - - //Register for messages - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor.h" +#include "TestActorModule1.h" + +#include +#include +#include + +const trUtil::RefStr TestActor::CLASS_TYPE("TestActor"); + +////////////////////////////////////////////////////////////////////////// +TestActor::TestActor(const std::string& name) : BaseClass(name) +{ + //Add a new Actor Module to the Actor + AddActorModule(*new TestActorModule1()); + + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActor::~TestActor() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActor::BuildInvokables() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActor::OnTick(const trManager::MessageBase& msg) +{ + //Send the tick message to all actor Modules. + ActorModuleTick(msg); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor::OnAddedToSysMan() +{ + BaseClass::OnAddedToSysMan(); + + //Register for messages + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); } \ No newline at end of file diff --git a/Examples/ActorModules/TestActor.h b/Examples/ActorModules/TestActor.h index e580627..b82c60d 100644 --- a/Examples/ActorModules/TestActor.h +++ b/Examples/ActorModules/TestActor.h @@ -1,86 +1,86 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn TestActor::TestActor(const std::string name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActor::BuildInvokables(); - * - * @brief Registers the message invokables. - */ - virtual void BuildInvokables() override; - - /** - * @fn virtual void TestActor::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestActor::~TestActor(); - * - * @brief Destructor. - */ - ~TestActor(); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn TestActor::TestActor(const std::string name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActor::BuildInvokables(); + * + * @brief Registers the message invokables. + */ + virtual void BuildInvokables() override; + + /** + * @fn virtual void TestActor::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestActor::~TestActor(); + * + * @brief Destructor. + */ + ~TestActor(); +}; + diff --git a/Examples/ActorModules/TestActorModule1.cpp b/Examples/ActorModules/TestActorModule1.cpp index da8f639..6d24086 100644 --- a/Examples/ActorModules/TestActorModule1.cpp +++ b/Examples/ActorModules/TestActorModule1.cpp @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActorModule1.h" - -#include -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestActorModule1::CLASS_TYPE("TestActorModule1"); - -////////////////////////////////////////////////////////////////////////// -TestActorModule1::TestActorModule1(const std::string& name) : BaseClass(name) -{ - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActorModule1::~TestActorModule1() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule1::BuildInvokables() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule1::OnTick(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule1::OnAddedToSysMan() -{ +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActorModule1.h" + +#include +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestActorModule1::CLASS_TYPE("TestActorModule1"); + +////////////////////////////////////////////////////////////////////////// +TestActorModule1::TestActorModule1(const std::string& name) : BaseClass(name) +{ + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActorModule1::~TestActorModule1() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule1::BuildInvokables() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule1::OnTick(const trManager::MessageBase & /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule1::OnAddedToSysMan() +{ } \ No newline at end of file diff --git a/Examples/ActorModules/TestActorModule1.h b/Examples/ActorModules/TestActorModule1.h index 7ab7621..9f5b3e2 100644 --- a/Examples/ActorModules/TestActorModule1.h +++ b/Examples/ActorModules/TestActorModule1.h @@ -1,84 +1,84 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -class TestActorModule1 : public trManager::ActorModuleBase -{ -public: - using BaseClass = trManager::ActorModuleBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn TestActorModule1::TestActorModule1(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActorModule1(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActorModule1::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActorModule1::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActorModule1::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActorModule1::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestActorModule1::~TestActorModule1(); - * - * @brief Destructor. - */ - ~TestActorModule1(); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +class TestActorModule1 : public trManager::ActorModuleBase +{ +public: + using BaseClass = trManager::ActorModuleBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn TestActorModule1::TestActorModule1(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActorModule1(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActorModule1::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActorModule1::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActorModule1::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActorModule1::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestActorModule1::~TestActorModule1(); + * + * @brief Destructor. + */ + ~TestActorModule1(); +}; + diff --git a/Examples/ActorModules/TestActorModule2.cpp b/Examples/ActorModules/TestActorModule2.cpp index 663a70d..d0be086 100644 --- a/Examples/ActorModules/TestActorModule2.cpp +++ b/Examples/ActorModules/TestActorModule2.cpp @@ -1,83 +1,83 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActorModule2.h" -#include "MessageTest.h" - - -#include -#include -#include -#include -#include - -const trUtil::RefStr TestActorModule2::CLASS_TYPE("TestActorModule2"); -int TestActorModule2::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActorModule2::TestActorModule2(const std::string& name) : BaseClass(name) -{ - ++mInstCount; - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActorModule2::~TestActorModule2() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule2::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActorModule2::ON_MESSAGE_INVOKABLE, trUtil::MakeFunctor(&TestActorModule2::OnMessage, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule2::OnTick(const trManager::MessageBase& msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Received Tick Message " << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule2::OnMessage(const trManager::MessageBase& msg) -{ - if (msg.GetMessageType() == MessageTest::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Received MessageTest " << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestActorModule2::OnAddedToSysMan() -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Registering for MessageTest Message " << std::endl; - RegisterForMessage(MessageTest::MESSAGE_TYPE, TestActorModule2::ON_MESSAGE_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActorModule2::GetInstCount() -{ - return mInstCount; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActorModule2.h" +#include "MessageTest.h" + + +#include +#include +#include +#include +#include + +const trUtil::RefStr TestActorModule2::CLASS_TYPE("TestActorModule2"); +int TestActorModule2::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActorModule2::TestActorModule2(const std::string& name) : BaseClass(name) +{ + ++mInstCount; + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActorModule2::~TestActorModule2() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule2::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActorModule2::ON_MESSAGE_INVOKABLE, trUtil::MakeFunctor(&TestActorModule2::OnMessage, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule2::OnTick(const trManager::MessageBase& /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Received Tick Message " << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule2::OnMessage(const trManager::MessageBase& msg) +{ + if (msg.GetMessageType() == MessageTest::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Received MessageTest " << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestActorModule2::OnAddedToSysMan() +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Registering for MessageTest Message " << std::endl; + RegisterForMessage(MessageTest::MESSAGE_TYPE, TestActorModule2::ON_MESSAGE_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActorModule2::GetInstCount() +{ + return mInstCount; } \ No newline at end of file diff --git a/Examples/ActorModules/TestActorModule2.h b/Examples/ActorModules/TestActorModule2.h index 54a6016..aa60f05 100644 --- a/Examples/ActorModules/TestActorModule2.h +++ b/Examples/ActorModules/TestActorModule2.h @@ -1,108 +1,108 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -class TestActorModule2 : public trManager::ActorModuleBase -{ -public: - using BaseClass = trManager::ActorModuleBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 - - /** - * @fn TestActorModule2::TestActorModule2(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActorModule2(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActorModule2::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE; } - - /** - * @fn virtual void TestActorModule2::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActorModule2::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActorModule2::OnMessage(const trManager::MessageBase& msg); - * - * @brief Function that is used by the Systems Manager to deliver all messages to the Director. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg) override; - - /** - * @fn virtual void TestActorModule2::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActorModule2::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - -protected: - - /** - * @fn TestActorModule2::~TestActorModule2(); - * - * @brief Destructor. - */ - ~TestActorModule2(); - -private: - - static int mInstCount; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +class TestActorModule2 : public trManager::ActorModuleBase +{ +public: + using BaseClass = trManager::ActorModuleBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 + + /** + * @fn TestActorModule2::TestActorModule2(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActorModule2(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActorModule2::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE; } + + /** + * @fn virtual void TestActorModule2::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActorModule2::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActorModule2::OnMessage(const trManager::MessageBase& msg); + * + * @brief Function that is used by the Systems Manager to deliver all messages to the Director. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg) override; + + /** + * @fn virtual void TestActorModule2::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActorModule2::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + +protected: + + /** + * @fn TestActorModule2::~TestActorModule2(); + * + * @brief Destructor. + */ + ~TestActorModule2(); + +private: + + static int mInstCount; +}; + diff --git a/Examples/ActorModules/TestDirector.cpp b/Examples/ActorModules/TestDirector.cpp index ae4024b..90268a8 100644 --- a/Examples/ActorModules/TestDirector.cpp +++ b/Examples/ActorModules/TestDirector.cpp @@ -1,175 +1,175 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActorModule2.h" -#include "TestDirector.h" -#include "MessageTest.h" -#include "TestActor.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); - -////////////////////////////////////////////////////////////////////////// -TestDirector::TestDirector(const std::string& name) : BaseClass(name) -{ -} - -////////////////////////////////////////////////////////////////////////// -TestDirector::~TestDirector() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnMessage(const trManager::MessageBase& msg) -{ - if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Camera Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Post Frame Message " << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnTick(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; - - //Cast the message into what it is, and pass it to a handler - HandleTickMessage(msg); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) -{ - const trManager::MessageTick* msgPtr = static_cast(&msg); - - //Set the print out to be 10 decimal places long - std::cout << std::fixed; - std::cout << std::setprecision(10); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; - std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; - std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << GetName() << ": TestActorModule2 Instances: "; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << TestActorModule2::GetInstCount() << std::endl; - - if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) - { - trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); - SendMessage(*msg); - } - else if (msgPtr->GetFrameNumber() == NEW_ACTOR_MODULE_FRAME_NUMBER) - { - //Find all actors of the TestActor type - std::vector actor = mSysMan->FindActorsByType(TestActor::CLASS_TYPE); - - //Check if we found an actor - if (actor.size() > 0) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Adding TestActorModule2 to TestActor" << std::endl; - - //In this case we know we can only have one of TestActor types, so we use the first one and add a Module to it. - trManager::EntityBase* module = new TestActorModule2; - mActorsModuleId = module->GetUUID(); - mSysMan->RegisterActor(*static_cast(module)); - - //We know the vector is filled with classes of TestActor::CLASS_TYPE, so we can directly cast it without a check. - static_cast(actor[0])->AddActorModule(*module); - } - } - else if (msgPtr->GetFrameNumber() == KILL_ACTOR_MODULE_FRAME_NUMBER) - { - //Find all actors of the TestActor type - std::vector actor = mSysMan->FindActorsByType(TestActor::CLASS_TYPE); - - //Check if we found an actor - if (actor.size() > 0) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Removing TestActorModule2 from TestActor" << std::endl; - - //In this case we know we can only have one of TestActor types, so we use the first one and Remove a Module from it - mSysMan->UnregisterActor(mActorsModuleId); - - //We know the vector is filled with classes of TestActor::CLASS_TYPE, so we can directly cast it without a check. - static_cast(actor[0])->RemoveActorModule(mActorsModuleId); - } - } - - //Send out a Test Message - trBase::SmrtPtr msgTst = new MessageTest(&this->GetUUID(), &mActorsModuleId); - mSysMan->SendMessage(*msgTst); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActorModule2.h" +#include "TestDirector.h" +#include "MessageTest.h" +#include "TestActor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); + +////////////////////////////////////////////////////////////////////////// +TestDirector::TestDirector(const std::string& name) : BaseClass(name) +{ +} + +////////////////////////////////////////////////////////////////////////// +TestDirector::~TestDirector() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnMessage(const trManager::MessageBase& msg) +{ + if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Camera Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Post Frame Message " << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnTick(const trManager::MessageBase & msg) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; + + //Cast the message into what it is, and pass it to a handler + HandleTickMessage(msg); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) +{ + const trManager::MessageTick* msgPtr = static_cast(&msg); + + //Set the print out to be 10 decimal places long + std::cout << std::fixed; + std::cout << std::setprecision(10); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; + std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; + std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << GetName() << ": TestActorModule2 Instances: "; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << TestActorModule2::GetInstCount() << std::endl; + + if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) + { + trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); + SendMessage(*msg); + } + else if (msgPtr->GetFrameNumber() == NEW_ACTOR_MODULE_FRAME_NUMBER) + { + //Find all actors of the TestActor type + std::vector actor = mSysMan->FindActorsByType(TestActor::CLASS_TYPE); + + //Check if we found an actor + if (actor.size() > 0) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Adding TestActorModule2 to TestActor" << std::endl; + + //In this case we know we can only have one of TestActor types, so we use the first one and add a Module to it. + trManager::EntityBase* module = new TestActorModule2; + mActorsModuleId = module->GetUUID(); + mSysMan->RegisterActor(*static_cast(module)); + + //We know the vector is filled with classes of TestActor::CLASS_TYPE, so we can directly cast it without a check. + static_cast(actor[0])->AddActorModule(*module); + } + } + else if (msgPtr->GetFrameNumber() == KILL_ACTOR_MODULE_FRAME_NUMBER) + { + //Find all actors of the TestActor type + std::vector actor = mSysMan->FindActorsByType(TestActor::CLASS_TYPE); + + //Check if we found an actor + if (actor.size() > 0) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Removing TestActorModule2 from TestActor" << std::endl; + + //In this case we know we can only have one of TestActor types, so we use the first one and Remove a Module from it + mSysMan->UnregisterActor(mActorsModuleId); + + //We know the vector is filled with classes of TestActor::CLASS_TYPE, so we can directly cast it without a check. + static_cast(actor[0])->RemoveActorModule(mActorsModuleId); + } + } + + //Send out a Test Message + trBase::SmrtPtr msgTst = new MessageTest(&this->GetUUID(), &mActorsModuleId); + mSysMan->SendMessage(*msgTst); } \ No newline at end of file diff --git a/Examples/ActorModules/TestDirector.h b/Examples/ActorModules/TestDirector.h index 63685b8..1a74412 100644 --- a/Examples/ActorModules/TestDirector.h +++ b/Examples/ActorModules/TestDirector.h @@ -1,105 +1,105 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestDirector : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. - const static int NEW_ACTOR_MODULE_FRAME_NUMBER = 5; ///Number of frames when a new actor module is created. - const static int KILL_ACTOR_MODULE_FRAME_NUMBER = 20; ///Number of frames when the created actor module is removed. - - /** - * @fn TestDirector::TestDirector(const std::string name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestDirector::~TestDirector(); - * - * @brief Destructor. - */ - ~TestDirector(); - - /** - * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); - * - * @brief Handles the tick message. - * - * @param msg The message. - */ - virtual void HandleTickMessage(const trManager::MessageBase& msg); - -private: - - trBase::UniqueId mActorsModuleId; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestDirector : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. + const static int NEW_ACTOR_MODULE_FRAME_NUMBER = 5; ///Number of frames when a new actor module is created. + const static int KILL_ACTOR_MODULE_FRAME_NUMBER = 20; ///Number of frames when the created actor module is removed. + + /** + * @fn TestDirector::TestDirector(const std::string name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestDirector::~TestDirector(); + * + * @brief Destructor. + */ + ~TestDirector(); + + /** + * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); + * + * @brief Handles the tick message. + * + * @param msg The message. + */ + virtual void HandleTickMessage(const trManager::MessageBase& msg); + +private: + + trBase::UniqueId mActorsModuleId; +}; + diff --git a/Examples/ActorModules/Utils.cpp b/Examples/ActorModules/Utils.cpp index ef2716a..92525a0 100644 --- a/Examples/ActorModules/Utils.cpp +++ b/Examples/ActorModules/Utils.cpp @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - -#include -#include -#include - -/* -* Parses the command line variables that are passed in to the executable -*/ -void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) -{ - trUtil::ArgumentParser arguments(&argc, argv); - - arguments.SetApplicationName(PROGRAM_NAME); - - arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); - arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + - trUtil::Logging::LOG_INFO_STR + ", " + - trUtil::Logging::LOG_WARNING_STR + ", " + - trUtil::Logging::LOG_ERROR_STR + ""); - arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); - - if (arguments.Read("--help") == true || - arguments.Read("/help") == true || - arguments.Read("-h") == true || - arguments.Read("/h") == true || - arguments.Read("/?") == true) - { - arguments.Write(std::cout); - exit(0); - } - - arguments.Read("--logFileName", logFileName); - arguments.Read("--logLevel", logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + +#include +#include +#include + +/* +* Parses the command line variables that are passed in to the executable +*/ +void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) +{ + trUtil::ArgumentParser arguments(&argc, argv); + + arguments.SetApplicationName(PROGRAM_NAME); + + arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); + arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + + trUtil::Logging::LOG_INFO_STR + ", " + + trUtil::Logging::LOG_WARNING_STR + ", " + + trUtil::Logging::LOG_ERROR_STR + ""); + arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); + + if (arguments.Read("--help") == true || + arguments.Read("/help") == true || + arguments.Read("-h") == true || + arguments.Read("/h") == true || + arguments.Read("/?") == true) + { + arguments.Write(std::cout); + exit(0); + } + + arguments.Read("--logFileName", logFileName); + arguments.Read("--logLevel", logLevel); } \ No newline at end of file diff --git a/Examples/ActorModules/Utils.h b/Examples/ActorModules/Utils.h index 08dc40e..341e509 100644 --- a/Examples/ActorModules/Utils.h +++ b/Examples/ActorModules/Utils.h @@ -1,31 +1,31 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -static const std::string PROGRAM_NAME = "TrueReality"; -static const std::string EXE_NAME = "exampleActorModules"; - -/* -* Parses the command line variables that are passed in to the executable -*/ +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +static const std::string PROGRAM_NAME = "TrueReality"; +static const std::string EXE_NAME = "exampleActorModules"; + +/* +* Parses the command line variables that are passed in to the executable +*/ void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); \ No newline at end of file diff --git a/Examples/Actors/Application.cpp b/Examples/Actors/Application.cpp index b1d91e1..c573b32 100644 --- a/Examples/Actors/Application.cpp +++ b/Examples/Actors/Application.cpp @@ -1,54 +1,54 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Application.h" -#include "TestActor1.h" -#include "TestDirector.h" - -#include -#include - -const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); - -////////////////////////////////////////////////////////////////////////// -Application::Application(const std::string& name) : BaseClass(name) -{ - //Create Test Actor 1 - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating Test Actor 1. " << std::endl; - mSysMan->RegisterActor(*new TestActor1()); - - //Create Test Director - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating a Test Director. " << std::endl; - mSysMan->RegisterDirector(*new TestDirector(), trManager::DirectorPriority::NORMAL); -} - -////////////////////////////////////////////////////////////////////////// -const std::string& Application::GetType() const -{ - return CLASS_TYPE; -} - -////////////////////////////////////////////////////////////////////////// -Application::~Application() -{ -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Application.h" +#include "TestActor1.h" +#include "TestDirector.h" + +#include +#include + +const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); + +////////////////////////////////////////////////////////////////////////// +Application::Application(const std::string& name) : BaseClass(name) +{ + //Create Test Actor 1 + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating Test Actor 1. " << std::endl; + mSysMan->RegisterActor(*new TestActor1()); + + //Create Test Director + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating a Test Director. " << std::endl; + mSysMan->RegisterDirector(*new TestDirector(), trManager::DirectorPriority::NORMAL); +} + +////////////////////////////////////////////////////////////////////////// +const std::string& Application::GetType() const +{ + return CLASS_TYPE; +} + +////////////////////////////////////////////////////////////////////////// +Application::~Application() +{ +} diff --git a/Examples/Actors/Application.h b/Examples/Actors/Application.h index f09bb4d..9dcb367 100644 --- a/Examples/Actors/Application.h +++ b/Examples/Actors/Application.h @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -class Application : public trApp::AppBase -{ -public: - using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn Application::Application(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - Application(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& Application::GetType() const override; - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - -protected: - - /** - * @fn Application::~Application(); - * - * @brief Destructor. - */ - ~Application(); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +class Application : public trApp::AppBase +{ +public: + using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn Application::Application(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + Application(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& Application::GetType() const override; + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + +protected: + + /** + * @fn Application::~Application(); + * + * @brief Destructor. + */ + ~Application(); +}; + diff --git a/Examples/Actors/Main.cpp b/Examples/Actors/Main.cpp index 0afff4c..ee95c64 100644 --- a/Examples/Actors/Main.cpp +++ b/Examples/Actors/Main.cpp @@ -1,83 +1,83 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Utils.h" -#include "Application.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -/** -* Software's main function. -*/ -int main(int argc, char** argv) -{ - std::string logFileName; - std::string logLevel; - - //Parse command line arguments - ParseCmdLineArgs(argc, argv, logFileName, logLevel); - - //Creates the default folders in the User Data folder. - trUtil::PathUtils::CreateUserDataPathTree(); - - //Setup our Logging options - trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); - - try - { - //Show Logo - trUtil::Console::Logo(); - - //Create the App and System handlers - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating The App. " << std::endl; - trBase::SmrtPtr mApp = new Application(); - - //Start the App Loop - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Starting the Run Loop... " << std::endl; - mApp->Run(); - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Ending the Run Loop... " << std::endl; - - //Ending program - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cerr << "True Reality is now shutting down ... " << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); - LOG_A("True Reality is now shutting down ... "); - - } - catch (const trUtil::Exception& ex) - { - LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); - ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); - return -1; - } - return 0; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Utils.h" +#include "Application.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +/** +* Software's main function. +*/ +int main(int argc, char** argv) +{ + std::string logFileName; + std::string logLevel; + + //Parse command line arguments + ParseCmdLineArgs(argc, argv, logFileName, logLevel); + + //Creates the default folders in the User Data folder. + trUtil::PathUtils::CreateUserDataPathTree(); + + //Setup our Logging options + trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); + + try + { + //Show Logo + trUtil::Console::Logo(); + + //Create the App and System handlers + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating The App. " << std::endl; + trBase::SmrtPtr mApp = new Application(); + + //Start the App Loop + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Starting the Run Loop... " << std::endl; + mApp->Run(); + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Ending the Run Loop... " << std::endl; + + //Ending program + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cerr << "True Reality is now shutting down ... " << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); + LOG_A("True Reality is now shutting down ... "); + + } + catch (const trUtil::Exception& ex) + { + LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); + ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); + return -1; + } + return 0; } \ No newline at end of file diff --git a/Examples/Actors/MessageTest.cpp b/Examples/Actors/MessageTest.cpp index 0482730..193dfe1 100644 --- a/Examples/Actors/MessageTest.cpp +++ b/Examples/Actors/MessageTest.cpp @@ -1,41 +1,41 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "MessageTest.h" - -const trUtil::RefStr MessageTest::MESSAGE_TYPE("trManager::MessageTest"); - -////////////////////////////////////////////////////////////////////////// -MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) - : BaseClass(fromActorID, aboutActorID) -{ -} - -////////////////////////////////////////////////////////////////////////// -MessageTest::~MessageTest() -{ -} - -////////////////////////////////////////////////////////////////////////// -const std::string& MessageTest::GetMessageType() const -{ - return MESSAGE_TYPE; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "MessageTest.h" + +const trUtil::RefStr MessageTest::MESSAGE_TYPE("trManager::MessageTest"); + +////////////////////////////////////////////////////////////////////////// +MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) + : BaseClass(fromActorID, aboutActorID) +{ +} + +////////////////////////////////////////////////////////////////////////// +MessageTest::~MessageTest() +{ +} + +////////////////////////////////////////////////////////////////////////// +const std::string& MessageTest::GetMessageType() const +{ + return MESSAGE_TYPE; } \ No newline at end of file diff --git a/Examples/Actors/MessageTest.h b/Examples/Actors/MessageTest.h index db66a8a..bea5cd9 100644 --- a/Examples/Actors/MessageTest.h +++ b/Examples/Actors/MessageTest.h @@ -1,71 +1,71 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include -#include -#include - -#include - -/** - * @class MessageTest - * - * @brief This is an exmple of a simple message that is passed between actors. - */ -class MessageTest : public trManager::MessageBase -{ -public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param aboutActorID Identifier for the about actor. - */ - MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - - /** - * @fn virtual const std::string& MessageTest::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - -protected: - - /** - * @fn MessageTest::~MessageTest(); - * - * @brief Destructor. - */ - ~MessageTest(); - -private: -}; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include +#include +#include + +#include + +/** + * @class MessageTest + * + * @brief This is an exmple of a simple message that is passed between actors. + */ +class MessageTest : public trManager::MessageBase +{ +public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageTest::MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param aboutActorID Identifier for the about actor. + */ + MessageTest(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + + /** + * @fn virtual const std::string& MessageTest::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + +protected: + + /** + * @fn MessageTest::~MessageTest(); + * + * @brief Destructor. + */ + ~MessageTest(); + +private: +}; diff --git a/Examples/Actors/TestActor1.cpp b/Examples/Actors/TestActor1.cpp index 4e8b66e..6ff2621 100644 --- a/Examples/Actors/TestActor1.cpp +++ b/Examples/Actors/TestActor1.cpp @@ -1,131 +1,129 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor1.h" -#include "TestActor2.h" -#include "MessageTest.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//#include - -const trUtil::RefStr TestActor1::CLASS_TYPE("TestActor1"); - -const trUtil::RefStr TestActor1::ON_ENTITY_REGISTERED_INVOKABLE("OnEntityRegistered"); -const trUtil::RefStr TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE("OnEntityUnregistered"); - -/** - * @fn TestActor1::TestActor1(const std::string& name) - * - * @brief ///////////////////////////////////////////////////////////////////////. - * - * @param name The name. - */ -TestActor1::TestActor1(const std::string& name) : BaseClass(name) -{ - //NULL the actor ID - mActor2Id = new trBase::UniqueId(false); - - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActor1::~TestActor1() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_REGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityRegistered, this))); - AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityUnregistered, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnTick(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; - - //Cast the message into what it is, and pass it to a handler - HandleTickMessage(msg); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg) -{ - const trManager::MessageEntityRegistered* entMsg = static_cast(&msg); - - if (entMsg->GetEntityType() == TestActor2::CLASS_TYPE) - { - //Save the actors ID for later use - mActor2Id = entMsg->GetAboutActorID(); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Saved ID of TestActor2" << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnEntityUnregistered(const trManager::MessageBase & msg) -{ - const trManager::MessageEntityRegistered* msgPtr = static_cast(&msg); - - if (msgPtr->GetEntityType() == TestActor2::CLASS_TYPE) - { - //NULL the ID - mActor2Id = new trBase::UniqueId(false); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Forgot TestActor2 " << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnAddedToSysMan() -{ - BaseClass::OnAddedToSysMan(); - - //Register for messages - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); - RegisterForMessage(trManager::MessageEntityRegistered::MESSAGE_TYPE, ON_ENTITY_REGISTERED_INVOKABLE); - RegisterForMessage(trManager::MessageEntityUnregistered::MESSAGE_TYPE, ON_ENTITY_UNREGISTERED_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::HandleTickMessage(const trManager::MessageBase& msg) -{ - if (!mActor2Id.IsNull()) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Sending Test Message to TestActor2" << std::endl; - - SendMessage(*new MessageTest(&GetUUID(), &mActor2Id)); - } +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor1.h" +#include "TestActor2.h" +#include "MessageTest.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include + +const trUtil::RefStr TestActor1::CLASS_TYPE("TestActor1"); + +const trUtil::RefStr TestActor1::ON_ENTITY_REGISTERED_INVOKABLE("OnEntityRegistered"); +const trUtil::RefStr TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE("OnEntityUnregistered"); + +/** + * @fn TestActor1::TestActor1(const std::string& name) + * + * @brief ///////////////////////////////////////////////////////////////////////. + * + * @param name The name. + */ +TestActor1::TestActor1(const std::string& name) : BaseClass(name) +, mActor2Id(new trBase::UniqueId(false)) //NULL the actor ID +{ + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActor1::~TestActor1() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_REGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityRegistered, this))); + AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityUnregistered, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnTick(const trManager::MessageBase & msg) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; + + //Cast the message into what it is, and pass it to a handler + HandleTickMessage(msg); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg) +{ + const trManager::MessageEntityRegistered* entMsg = static_cast(&msg); + + if (entMsg->GetEntityType() == TestActor2::CLASS_TYPE) + { + //Save the actors ID for later use + mActor2Id = entMsg->GetAboutActorID(); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Saved ID of TestActor2" << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnEntityUnregistered(const trManager::MessageBase & msg) +{ + const trManager::MessageEntityRegistered* msgPtr = static_cast(&msg); + + if (msgPtr->GetEntityType() == TestActor2::CLASS_TYPE) + { + //NULL the ID + mActor2Id = new trBase::UniqueId(false); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Forgot TestActor2 " << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnAddedToSysMan() +{ + BaseClass::OnAddedToSysMan(); + + //Register for messages + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); + RegisterForMessage(trManager::MessageEntityRegistered::MESSAGE_TYPE, ON_ENTITY_REGISTERED_INVOKABLE); + RegisterForMessage(trManager::MessageEntityUnregistered::MESSAGE_TYPE, ON_ENTITY_UNREGISTERED_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::HandleTickMessage(const trManager::MessageBase& /*msg*/) +{ + if (!mActor2Id.IsNull()) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Sending Test Message to TestActor2" << std::endl; + + SendMessage(*new MessageTest(&GetUUID(), &mActor2Id)); + } } \ No newline at end of file diff --git a/Examples/Actors/TestActor1.h b/Examples/Actors/TestActor1.h index 7180498..e7ff1fa 100644 --- a/Examples/Actors/TestActor1.h +++ b/Examples/Actors/TestActor1.h @@ -1,120 +1,120 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor1 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_ENTITY_REGISTERED_INVOKABLE; /// Invokable for Entity Registered messages - const static trUtil::RefStr ON_ENTITY_UNREGISTERED_INVOKABLE; /// Invokable for Entity Registered messages - - /** - * @fn TestActor1::TestActor1(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor1(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor1::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActor1::BuildInvokables(); - * - * @brief Registers the message invokables. - */ - virtual void BuildInvokables() override; - - /** - * @fn virtual void TestActor1::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg); - * - * @brief Executes the reception of the Entity Registered Message. - * - * @param msg The message. - */ - virtual void OnEntityRegistered(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg); - * - * @brief Executes the reception of the Entity Unregistered Message. - * - * @param msg The message. - */ - virtual void OnEntityUnregistered(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestActor1::~TestActor1(); - * - * @brief Destructor. - */ - ~TestActor1(); - - /** - * @fn virtual void TestActor1::HandleTickMessage(const trManager::MessageBase& msg); - * - * @brief Handles the tick message. - * - * @param msg The message. - */ - virtual void HandleTickMessage(const trManager::MessageBase& msg); - -private: - - trBase::UniqueId mActor2Id; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor1 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_ENTITY_REGISTERED_INVOKABLE; /// Invokable for Entity Registered messages + const static trUtil::RefStr ON_ENTITY_UNREGISTERED_INVOKABLE; /// Invokable for Entity Registered messages + + /** + * @fn TestActor1::TestActor1(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor1(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor1::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActor1::BuildInvokables(); + * + * @brief Registers the message invokables. + */ + virtual void BuildInvokables() override; + + /** + * @fn virtual void TestActor1::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg); + * + * @brief Executes the reception of the Entity Registered Message. + * + * @param msg The message. + */ + virtual void OnEntityRegistered(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg); + * + * @brief Executes the reception of the Entity Unregistered Message. + * + * @param msg The message. + */ + virtual void OnEntityUnregistered(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestActor1::~TestActor1(); + * + * @brief Destructor. + */ + ~TestActor1(); + + /** + * @fn virtual void TestActor1::HandleTickMessage(const trManager::MessageBase& msg); + * + * @brief Handles the tick message. + * + * @param msg The message. + */ + virtual void HandleTickMessage(const trManager::MessageBase& msg); + +private: + + trBase::UniqueId mActor2Id; +}; + diff --git a/Examples/Actors/TestActor2.cpp b/Examples/Actors/TestActor2.cpp index 0ecb1d2..fcdcc57 100644 --- a/Examples/Actors/TestActor2.cpp +++ b/Examples/Actors/TestActor2.cpp @@ -1,83 +1,83 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor2.h" -#include "TestActor1.h" -#include "MessageTest.h" - -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestActor2::CLASS_TYPE("TestActor2"); - -const trUtil::RefStr TestActor2::ON_TEST_INVOKABLE("OnTest"); - -int TestActor2::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActor2::TestActor2(const std::string& name) : BaseClass(name) -{ - BuildInvokables(); - ++mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -TestActor2::~TestActor2() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor2::ON_TEST_INVOKABLE, trUtil::MakeFunctor(&TestActor2::OnTest, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnTick(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnTest(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Test Message from TestActor1 " << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); - RegisterForMessage(MessageTest::MESSAGE_TYPE, ON_TEST_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor2::GetInstCount() -{ - return mInstCount; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor2.h" +#include "TestActor1.h" +#include "MessageTest.h" + +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestActor2::CLASS_TYPE("TestActor2"); + +const trUtil::RefStr TestActor2::ON_TEST_INVOKABLE("OnTest"); + +int TestActor2::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActor2::TestActor2(const std::string& name) : BaseClass(name) +{ + BuildInvokables(); + ++mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +TestActor2::~TestActor2() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor2::ON_TEST_INVOKABLE, trUtil::MakeFunctor(&TestActor2::OnTest, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnTick(const trManager::MessageBase & /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnTest(const trManager::MessageBase & /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Test Message from TestActor1 " << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); + RegisterForMessage(MessageTest::MESSAGE_TYPE, ON_TEST_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor2::GetInstCount() +{ + return mInstCount; } \ No newline at end of file diff --git a/Examples/Actors/TestActor2.h b/Examples/Actors/TestActor2.h index 7811093..bbb0f66 100644 --- a/Examples/Actors/TestActor2.h +++ b/Examples/Actors/TestActor2.h @@ -1,108 +1,108 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor2 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_TEST_INVOKABLE; /// Invokable for Test messages - - /** - * @fn TestActor2::TestActor2(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor2(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor2::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActor2::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActor2::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor2::OnTest(const trManager::MessageBase& msg) virtual void OnAddedToSysMan() override; - * - * @brief Executes on Reception of the Test Message. - * - * @param msg The message. - */ - virtual void OnTest(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor2::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActor2::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - -protected: - - /** - * @fn TestActor2::~TestActor2(); - * - * @brief Destructor. - */ - ~TestActor2(); - - static int mInstCount; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor2 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_TEST_INVOKABLE; /// Invokable for Test messages + + /** + * @fn TestActor2::TestActor2(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor2(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor2::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActor2::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActor2::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor2::OnTest(const trManager::MessageBase& msg) virtual void OnAddedToSysMan() override; + * + * @brief Executes on Reception of the Test Message. + * + * @param msg The message. + */ + virtual void OnTest(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor2::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActor2::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + +protected: + + /** + * @fn TestActor2::~TestActor2(); + * + * @brief Destructor. + */ + ~TestActor2(); + + static int mInstCount; +}; + diff --git a/Examples/Actors/TestActor3.cpp b/Examples/Actors/TestActor3.cpp index c252569..6f0e39c 100644 --- a/Examples/Actors/TestActor3.cpp +++ b/Examples/Actors/TestActor3.cpp @@ -1,82 +1,82 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor3.h" -#include "TestActor2.h" -#include "MessageTest.h" - -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestActor3::CLASS_TYPE("TestActor3"); - -const trUtil::RefStr TestActor3::ON_TEST_ACTOR_2_INVOKABLE("OnTestActor2"); - -int TestActor3::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActor3::TestActor3(const std::string& name) : BaseClass(name) -{ - ++mInstCount; - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActor3::~TestActor3() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor3::ON_TEST_ACTOR_2_INVOKABLE, trUtil::MakeFunctor(&TestActor3::AboutTestActor2, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::OnTick(const trManager::MessageBase& msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::AboutTestActor2(const trManager::MessageBase& msg) -{ - std::cout << GetName() << ": Received Message Type " << msg.GetMessageType() << " about TestActor2"<< std::endl; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::OnAddedToSysMan() -{ - //Register for Tick Message - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor3::GetInstCount() -{ - return mInstCount; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor3.h" +#include "TestActor2.h" +#include "MessageTest.h" + +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestActor3::CLASS_TYPE("TestActor3"); + +const trUtil::RefStr TestActor3::ON_TEST_ACTOR_2_INVOKABLE("OnTestActor2"); + +int TestActor3::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActor3::TestActor3(const std::string& name) : BaseClass(name) +{ + ++mInstCount; + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActor3::~TestActor3() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor3::ON_TEST_ACTOR_2_INVOKABLE, trUtil::MakeFunctor(&TestActor3::AboutTestActor2, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::OnTick(const trManager::MessageBase& /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::AboutTestActor2(const trManager::MessageBase& msg) +{ + std::cout << GetName() << ": Received Message Type " << msg.GetMessageType() << " about TestActor2"<< std::endl; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::OnAddedToSysMan() +{ + //Register for Tick Message + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor3::GetInstCount() +{ + return mInstCount; } \ No newline at end of file diff --git a/Examples/Actors/TestActor3.h b/Examples/Actors/TestActor3.h index 2d9a29c..c5fa3f5 100644 --- a/Examples/Actors/TestActor3.h +++ b/Examples/Actors/TestActor3.h @@ -1,107 +1,107 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor3 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 - - /** - * @fn TestActor3::TestActor3(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor3(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor3::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE; } - - /** - * @fn virtual void TestActor3::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActor3::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor3::AboutTestActor2(const trManager::MessageBase& msg); - * - * @brief Handles intercepted messages that are going to TestActor2. - * - * @param msg The message. - */ - virtual void AboutTestActor2(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor3::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActor3::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); -protected: - - /** - * @fn TestActor3::~TestActor3(); - * - * @brief Destructor. - */ - ~TestActor3(); - - static int mInstCount; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor3 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 + + /** + * @fn TestActor3::TestActor3(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor3(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor3::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE; } + + /** + * @fn virtual void TestActor3::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActor3::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor3::AboutTestActor2(const trManager::MessageBase& msg); + * + * @brief Handles intercepted messages that are going to TestActor2. + * + * @param msg The message. + */ + virtual void AboutTestActor2(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor3::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActor3::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); +protected: + + /** + * @fn TestActor3::~TestActor3(); + * + * @brief Destructor. + */ + ~TestActor3(); + + static int mInstCount; +}; + diff --git a/Examples/Actors/TestDirector.cpp b/Examples/Actors/TestDirector.cpp index c2e3408..10cd4f2 100644 --- a/Examples/Actors/TestDirector.cpp +++ b/Examples/Actors/TestDirector.cpp @@ -1,242 +1,242 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestDirector.h" -#include "TestActor2.h" -#include "TestActor3.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); - -////////////////////////////////////////////////////////////////////////// -TestDirector::TestDirector(const std::string& name) : BaseClass(name) -{ -} - -////////////////////////////////////////////////////////////////////////// -TestDirector::~TestDirector() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnMessage(const trManager::MessageBase& msg) -{ - if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Camera Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Post Frame Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << GetName() << ": Received System Event Message: "; - - //Cast the message into what it is, and pass it to a handler - HandleSystemEvent(msg); - } - else if (msg.GetMessageType() == trManager::MessageEntityRegistered::MESSAGE_TYPE) - { - - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnTick(const trManager::MessageBase & msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; - - //Cast the message into what it is, and pass it to a handler - HandleTickMessage(msg); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg) -{ - const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); - - if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::EVENT_TRAVERSAL << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::POST_EVENT_TRAVERSAL << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::PRE_FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::CAMERA_SYNCH << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::FRAME_SYNCH << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::POST_FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::SHUTTING_DOWN) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << "Event Type " << trCore::SystemEvents::SHUTTING_DOWN << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::TIME_SCALE_CHANGED) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::TIME_SCALE_CHANGED << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) -{ - const trManager::MessageTick* msgPtr = static_cast(&msg); - - //Set the print out to be 10 decimal places long - std::cout << std::fixed; - std::cout << std::setprecision(10); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; - std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; - std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; - - std::cout << GetName() << ": TestActor2 Instances: "; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << TestActor2::GetInstCount() << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": TestActor3 Instances: "; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << TestActor3::GetInstCount() << std::endl; - if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) - { - trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); - SendMessage(*msg); - } - else if (msgPtr->GetFrameNumber() == NEW_ACTOR_FRAME_NUMBER) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Creating TestActor2" << std::endl; - - //Register a new actor - trBase::SmrtPtr actor = new TestActor2(); - mActorsId = actor->GetUUID(); //Save the actors ID for later use. - mSysMan->RegisterActor(*actor); - - } - else if (msgPtr->GetFrameNumber() == KILL_ACTOR_FRAME_NUMBER) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Marking TestActor2 for termination" << std::endl; - - //Unregister the actor - mSysMan->UnregisterActor(mActorsId); - } - else if (msgPtr->GetFrameNumber() == INTERCEPT_ACTOR_FRAME_NUMBER) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Creating TestActor3" << std::endl; - - //Register a new actor - trBase::SmrtPtr actor = new TestActor3(); - mSysMan->RegisterActor(*actor); - - //Make the actor listen to messages about another actor - mSysMan->RegisterForMessagesAboutEntity(*actor, mActorsId, TestActor3::ON_TEST_ACTOR_2_INVOKABLE); - std::cout << GetName() << ": " << actor->GetName() << ": Registered for Messages about TestActor2" << std::endl; - } - else if (msgPtr->GetFrameNumber() == KILL_INTERCEPT_ACTOR_FRAME_NUMBER) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cout << GetName() << ": Marking TestActor3 for termination" << std::endl; - - //Find actor of type TestActor3 (there should be only one this time) - std::vector testActors = mSysMan->FindActorsByType(TestActor3::CLASS_TYPE); - - //Unregister the actor - mSysMan->UnregisterActor(testActors[0]->GetUUID()); - } -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestDirector.h" +#include "TestActor2.h" +#include "TestActor3.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); + +////////////////////////////////////////////////////////////////////////// +TestDirector::TestDirector(const std::string& name) : BaseClass(name) +{ +} + +////////////////////////////////////////////////////////////////////////// +TestDirector::~TestDirector() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnMessage(const trManager::MessageBase& msg) +{ + if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Camera Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Post Frame Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << GetName() << ": Received System Event Message: "; + + //Cast the message into what it is, and pass it to a handler + HandleSystemEvent(msg); + } + else if (msg.GetMessageType() == trManager::MessageEntityRegistered::MESSAGE_TYPE) + { + + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnTick(const trManager::MessageBase & msg) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; + + //Cast the message into what it is, and pass it to a handler + HandleTickMessage(msg); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg) +{ + const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); + + if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::EVENT_TRAVERSAL << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::POST_EVENT_TRAVERSAL << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::PRE_FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::CAMERA_SYNCH << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::FRAME_SYNCH << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::POST_FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::SHUTTING_DOWN) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << "Event Type " << trCore::SystemEvents::SHUTTING_DOWN << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::TIME_SCALE_CHANGED) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::TIME_SCALE_CHANGED << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) +{ + const trManager::MessageTick* msgPtr = static_cast(&msg); + + //Set the print out to be 10 decimal places long + std::cout << std::fixed; + std::cout << std::setprecision(10); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; + std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; + std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; + + std::cout << GetName() << ": TestActor2 Instances: "; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << TestActor2::GetInstCount() << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": TestActor3 Instances: "; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << TestActor3::GetInstCount() << std::endl; + if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) + { + trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); + SendMessage(*msg); + } + else if (msgPtr->GetFrameNumber() == NEW_ACTOR_FRAME_NUMBER) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Creating TestActor2" << std::endl; + + //Register a new actor + trBase::SmrtPtr actor = new TestActor2(); + mActorsId = actor->GetUUID(); //Save the actors ID for later use. + mSysMan->RegisterActor(*actor); + + } + else if (msgPtr->GetFrameNumber() == KILL_ACTOR_FRAME_NUMBER) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Marking TestActor2 for termination" << std::endl; + + //Unregister the actor + mSysMan->UnregisterActor(mActorsId); + } + else if (msgPtr->GetFrameNumber() == INTERCEPT_ACTOR_FRAME_NUMBER) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Creating TestActor3" << std::endl; + + //Register a new actor + trBase::SmrtPtr actor = new TestActor3(); + mSysMan->RegisterActor(*actor); + + //Make the actor listen to messages about another actor + mSysMan->RegisterForMessagesAboutEntity(*actor, mActorsId, TestActor3::ON_TEST_ACTOR_2_INVOKABLE); + std::cout << GetName() << ": " << actor->GetName() << ": Registered for Messages about TestActor2" << std::endl; + } + else if (msgPtr->GetFrameNumber() == KILL_INTERCEPT_ACTOR_FRAME_NUMBER) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cout << GetName() << ": Marking TestActor3 for termination" << std::endl; + + //Find actor of type TestActor3 (there should be only one this time) + std::vector testActors = mSysMan->FindActorsByType(TestActor3::CLASS_TYPE); + + //Unregister the actor + mSysMan->UnregisterActor(testActors[0]->GetUUID()); + } +} + diff --git a/Examples/Actors/TestDirector.h b/Examples/Actors/TestDirector.h index f4aef5b..fb8e94d 100644 --- a/Examples/Actors/TestDirector.h +++ b/Examples/Actors/TestDirector.h @@ -1,116 +1,116 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestDirector : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. - const static int NEW_ACTOR_FRAME_NUMBER = 5; ///Number of frames when a new actor is created. - const static int INTERCEPT_ACTOR_FRAME_NUMBER = 10; ///Number of frames when the intercept actor is created. - const static int KILL_INTERCEPT_ACTOR_FRAME_NUMBER = 15;///Number of frames when the intercept actor is created. - const static int KILL_ACTOR_FRAME_NUMBER = 20; ///Number of frames when the created actor is removed. - - /** - * @fn TestDirector::TestDirector(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestDirector::~TestDirector(); - * - * @brief Destructor. - */ - ~TestDirector(); - - /** - * @fn virtual void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg); - * - * @brief Handles the system event described by msg. - * - * @param msg The message. - */ - virtual void HandleSystemEvent(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); - * - * @brief Handles the tick message. - * - * @param msg The message. - */ - virtual void HandleTickMessage(const trManager::MessageBase& msg); - -private: - - trBase::UniqueId mActorsId; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestDirector : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. + const static int NEW_ACTOR_FRAME_NUMBER = 5; ///Number of frames when a new actor is created. + const static int INTERCEPT_ACTOR_FRAME_NUMBER = 10; ///Number of frames when the intercept actor is created. + const static int KILL_INTERCEPT_ACTOR_FRAME_NUMBER = 15;///Number of frames when the intercept actor is created. + const static int KILL_ACTOR_FRAME_NUMBER = 20; ///Number of frames when the created actor is removed. + + /** + * @fn TestDirector::TestDirector(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestDirector::~TestDirector(); + * + * @brief Destructor. + */ + ~TestDirector(); + + /** + * @fn virtual void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg); + * + * @brief Handles the system event described by msg. + * + * @param msg The message. + */ + virtual void HandleSystemEvent(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); + * + * @brief Handles the tick message. + * + * @param msg The message. + */ + virtual void HandleTickMessage(const trManager::MessageBase& msg); + +private: + + trBase::UniqueId mActorsId; +}; + diff --git a/Examples/Actors/Utils.cpp b/Examples/Actors/Utils.cpp index 38a59f9..8af0ec1 100644 --- a/Examples/Actors/Utils.cpp +++ b/Examples/Actors/Utils.cpp @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - -#include -#include -#include - -/* -* Parses the command line variables that are passed in to the executable -*/ -void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) -{ - trUtil::ArgumentParser arguments(&argc, argv); - - arguments.SetApplicationName(PROGRAM_NAME); - - arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); - arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + - trUtil::Logging::LOG_INFO_STR + ", " + - trUtil::Logging::LOG_WARNING_STR + ", " + - trUtil::Logging::LOG_ERROR_STR + ""); - arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); - - if (arguments.Read("--help") == true || - arguments.Read("/help") == true || - arguments.Read("-h") == true || - arguments.Read("/h") == true || - arguments.Read("/?") == true) - { - arguments.Write(std::cout); - exit(0); - } - - arguments.Read("--logFileName", logFileName); - arguments.Read("--logLevel", logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + +#include +#include +#include + +/* +* Parses the command line variables that are passed in to the executable +*/ +void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) +{ + trUtil::ArgumentParser arguments(&argc, argv); + + arguments.SetApplicationName(PROGRAM_NAME); + + arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); + arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + + trUtil::Logging::LOG_INFO_STR + ", " + + trUtil::Logging::LOG_WARNING_STR + ", " + + trUtil::Logging::LOG_ERROR_STR + ""); + arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); + + if (arguments.Read("--help") == true || + arguments.Read("/help") == true || + arguments.Read("-h") == true || + arguments.Read("/h") == true || + arguments.Read("/?") == true) + { + arguments.Write(std::cout); + exit(0); + } + + arguments.Read("--logFileName", logFileName); + arguments.Read("--logLevel", logLevel); } \ No newline at end of file diff --git a/Examples/Actors/Utils.h b/Examples/Actors/Utils.h index a51a2ab..5cca858 100644 --- a/Examples/Actors/Utils.h +++ b/Examples/Actors/Utils.h @@ -1,38 +1,38 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -static const std::string PROGRAM_NAME = "TrueReality"; -static const std::string EXE_NAME = "exampleActors"; - -/** - * @fn void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); - * - * @brief Parses the command line variables that are passed in to the executable. - * - * @param [in,out] argc The argc. - * @param [in,out] argv If non-null, the argv. - * @param [in,out] logFileName Filename of the log file. - * @param [in,out] logLevel The log level. - */ +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +static const std::string PROGRAM_NAME = "TrueReality"; +static const std::string EXE_NAME = "exampleActors"; + +/** + * @fn void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); + * + * @brief Parses the command line variables that are passed in to the executable. + * + * @param [in,out] argc The argc. + * @param [in,out] argv If non-null, the argv. + * @param [in,out] logFileName Filename of the log file. + * @param [in,out] logLevel The log level. + */ void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); \ No newline at end of file diff --git a/Examples/Director/Application.cpp b/Examples/Director/Application.cpp index 9582eae..d1ba546 100644 --- a/Examples/Director/Application.cpp +++ b/Examples/Director/Application.cpp @@ -1,59 +1,59 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Application.h" -#include "TestDirector.h" -#include "TestDirector2.h" - -#include -#include - -const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); - -////////////////////////////////////////////////////////////////////////// -Application::Application(const std::string& name) : BaseClass(name) -{ - //Create the Test Director - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating the Test Director. " << std::endl; - trBase::SmrtPtr testDir = new TestDirector(); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Registering the Test Director. " << std::endl; - mSysMan->RegisterDirector(*testDir, trManager::DirectorPriority::NORMAL); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating and Registering the Test Director2. " << std::endl; - mSysMan->RegisterDirector(*new TestDirector2(), trManager::DirectorPriority::NORMAL); - - -} - -////////////////////////////////////////////////////////////////////////// -const std::string& Application::GetType() const -{ - return CLASS_TYPE; -} - -////////////////////////////////////////////////////////////////////////// -Application::~Application() -{ -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Application.h" +#include "TestDirector.h" +#include "TestDirector2.h" + +#include +#include + +const trUtil::RefStr Application::CLASS_TYPE = trUtil::RefStr("Application"); + +////////////////////////////////////////////////////////////////////////// +Application::Application(const std::string& name) : BaseClass(name) +{ + //Create the Test Director + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating the Test Director. " << std::endl; + trBase::SmrtPtr testDir = new TestDirector(); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Registering the Test Director. " << std::endl; + mSysMan->RegisterDirector(*testDir, trManager::DirectorPriority::NORMAL); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating and Registering the Test Director2. " << std::endl; + mSysMan->RegisterDirector(*new TestDirector2(), trManager::DirectorPriority::NORMAL); + + +} + +////////////////////////////////////////////////////////////////////////// +const std::string& Application::GetType() const +{ + return CLASS_TYPE; +} + +////////////////////////////////////////////////////////////////////////// +Application::~Application() +{ +} diff --git a/Examples/Director/Application.h b/Examples/Director/Application.h index 4760b87..5cd7e02 100644 --- a/Examples/Director/Application.h +++ b/Examples/Director/Application.h @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -class Application : public trApp::AppBase -{ -public: - using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn Application::Application(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - Application(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& Application::GetType() const override; - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - -protected: - - /** - * @fn Application::~Application(); - * - * @brief Destructor. - */ - ~Application(); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +class Application : public trApp::AppBase +{ +public: + using BaseClass = trApp::AppBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn Application::Application(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + Application(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& Application::GetType() const override; + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + +protected: + + /** + * @fn Application::~Application(); + * + * @brief Destructor. + */ + ~Application(); +}; + diff --git a/Examples/Director/Main.cpp b/Examples/Director/Main.cpp index a4987f2..e997996 100644 --- a/Examples/Director/Main.cpp +++ b/Examples/Director/Main.cpp @@ -1,90 +1,90 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "Utils.h" -#include "Application.h" -#include "TestDirector2.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -/** -* Software's main function. -*/ -int main(int argc, char** argv) -{ - std::string logFileName; - std::string logLevel; - - //Parse command line arguments - ParseCmdLineArgs(argc, argv, logFileName, logLevel); - - //Creates the default folders in the User Data folder. - trUtil::PathUtils::CreateUserDataPathTree(); - - //Setup our Logging options - trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); - - try - { - //Show Logo - trUtil::Console::Logo(); - - //Create the App and System handlers - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Creating The App. " << std::endl; - trBase::SmrtPtr mApp = new Application(); - - //Start the App Loop - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Starting the Run Loop... " << std::endl; - mApp->Run(); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); - std::cout << "TestDirector2 Instances: "; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << TestDirector2::GetInstCount() << std::endl; - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); - std::cerr << "Ending the Run Loop... " << std::endl; - - //Ending program - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cerr << "True Reality is now shutting down ... " << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); - LOG_A("True Reality is now shutting down ... "); - - } - catch (const trUtil::Exception& ex) - { - LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); - ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); - return -1; - } - return 0; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "Utils.h" +#include "Application.h" +#include "TestDirector2.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +/** +* Software's main function. +*/ +int main(int argc, char** argv) +{ + std::string logFileName; + std::string logLevel; + + //Parse command line arguments + ParseCmdLineArgs(argc, argv, logFileName, logLevel); + + //Creates the default folders in the User Data folder. + trUtil::PathUtils::CreateUserDataPathTree(); + + //Setup our Logging options + trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); + + try + { + //Show Logo + trUtil::Console::Logo(); + + //Create the App and System handlers + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Creating The App. " << std::endl; + trBase::SmrtPtr mApp = new Application(); + + //Start the App Loop + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Starting the Run Loop... " << std::endl; + mApp->Run(); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); + std::cout << "TestDirector2 Instances: "; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << TestDirector2::GetInstCount() << std::endl; + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_GREEN); + std::cerr << "Ending the Run Loop... " << std::endl; + + //Ending program + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cerr << "True Reality is now shutting down ... " << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); + LOG_A("True Reality is now shutting down ... "); + + } + catch (const trUtil::Exception& ex) + { + LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); + ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); + return -1; + } + return 0; } \ No newline at end of file diff --git a/Examples/Director/TestDirector.cpp b/Examples/Director/TestDirector.cpp index 4fbde48..3f009fd 100644 --- a/Examples/Director/TestDirector.cpp +++ b/Examples/Director/TestDirector.cpp @@ -1,198 +1,198 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestDirector.h" -#include "TestDirector2.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); - -////////////////////////////////////////////////////////////////////////// -TestDirector::TestDirector(const std::string& name) : BaseClass(name) -{ -} - -////////////////////////////////////////////////////////////////////////// -TestDirector::~TestDirector() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnMessage(const trManager::MessageBase& msg) -{ - if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Camera Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Synch Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Frame Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); - std::cout << GetName() << ": Received Post Frame Message " << std::endl; - } - else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << GetName() << ": Received System Event Message: "; - - HandleSystemEvent(msg); - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnTick(const trManager::MessageBase& msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Received Tick Message " << std::endl; - - HandleTickMessage(msg); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg) -{ - //Cast the message into its real type - const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); - - if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::EVENT_TRAVERSAL << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::POST_EVENT_TRAVERSAL << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::PRE_FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::CAMERA_SYNCH << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::FRAME_SYNCH << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::POST_FRAME << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::SHUTTING_DOWN) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << "Event Type " << trCore::SystemEvents::SHUTTING_DOWN << std::endl; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::TIME_SCALE_CHANGED) - { - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); - std::cout << "Event Type " << trCore::SystemEvents::TIME_SCALE_CHANGED << std::endl; - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) -{ - //Cast the message into its real type - const trManager::MessageTick* msgPtr = static_cast(&msg); - - - //Set the print out to be 10 decimal places long - std::cout << std::fixed; - std::cout << std::setprecision(10); - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); - std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; - std::cout << GetName() << ": Time Scale: " << msgPtr->GetTimeScale() << std::endl; - std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; - std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; - std::cout << GetName() << ": Real Time: " << msgPtr->GetRealTime() << std::endl; - std::cout << GetName() << ": Delta Real Time: " << msgPtr->GetDeltaRealTime() << std::endl; - - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); - std::cout << GetName() << ": TestDirector2 Instances: "; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cout << TestDirector2::GetInstCount() << std::endl; - - if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) - { - trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); - SendMessage(*msg); - } - else if (msgPtr->GetFrameNumber() == SPEED_FRAME_NUMBER) - { - trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SET_TIME_SCALE, 20.69); - SendMessage(*msg); - } +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestDirector.h" +#include "TestDirector2.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestDirector::CLASS_TYPE = trUtil::RefStr("TestDirector"); + +////////////////////////////////////////////////////////////////////////// +TestDirector::TestDirector(const std::string& name) : BaseClass(name) +{ +} + +////////////////////////////////////////////////////////////////////////// +TestDirector::~TestDirector() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnMessage(const trManager::MessageBase& msg) +{ + if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Event Post Traversal Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Camera Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Synch Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Frame Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_YELLOW); + std::cout << GetName() << ": Received Post Frame Message " << std::endl; + } + else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << GetName() << ": Received System Event Message: "; + + HandleSystemEvent(msg); + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnTick(const trManager::MessageBase& msg) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Received Tick Message " << std::endl; + + HandleTickMessage(msg); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg) +{ + //Cast the message into its real type + const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); + + if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::EVENT_TRAVERSAL << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::POST_EVENT_TRAVERSAL << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::PRE_FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::CAMERA_SYNCH << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::FRAME_SYNCH << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::POST_FRAME << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::SHUTTING_DOWN) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << "Event Type " << trCore::SystemEvents::SHUTTING_DOWN << std::endl; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::TIME_SCALE_CHANGED) + { + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_BLUE); + std::cout << "Event Type " << trCore::SystemEvents::TIME_SCALE_CHANGED << std::endl; + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector::HandleTickMessage(const trManager::MessageBase& msg) +{ + //Cast the message into its real type + const trManager::MessageTick* msgPtr = static_cast(&msg); + + + //Set the print out to be 10 decimal places long + std::cout << std::fixed; + std::cout << std::setprecision(10); + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_CYAN); + std::cout << GetName() << ": Frame #" << msgPtr->GetFrameNumber() << std::endl; + std::cout << GetName() << ": Time Scale: " << msgPtr->GetTimeScale() << std::endl; + std::cout << GetName() << ": Sim Time: " << msgPtr->GetSimTime() << std::endl; + std::cout << GetName() << ": Delta Sim Time: " << msgPtr->GetDeltaSimTime() << std::endl; + std::cout << GetName() << ": Real Time: " << msgPtr->GetRealTime() << std::endl; + std::cout << GetName() << ": Delta Real Time: " << msgPtr->GetDeltaRealTime() << std::endl; + + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); + std::cout << GetName() << ": TestDirector2 Instances: "; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cout << TestDirector2::GetInstCount() << std::endl; + + if (msgPtr->GetFrameNumber() == MAX_FRAME_NUMBER) + { + trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SHUT_DOWN); + SendMessage(*msg); + } + else if (msgPtr->GetFrameNumber() == SPEED_FRAME_NUMBER) + { + trBase::SmrtPtr msg = new trCore::MessageSystemControl(&this->GetUUID(), trCore::SystemControls::SET_TIME_SCALE, 20.69); + SendMessage(*msg); + } } \ No newline at end of file diff --git a/Examples/Director/TestDirector.h b/Examples/Director/TestDirector.h index 063b6a3..927b942 100644 --- a/Examples/Director/TestDirector.h +++ b/Examples/Director/TestDirector.h @@ -1,108 +1,108 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include - -#include - -class TestDirector : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. - const static int SPEED_FRAME_NUMBER = 5; ///Number of frames on which the TimeScale should be increased. - - /** - * @fn TestDirector::TestDirector(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - -protected: - - /** - * @fn TestDirector::~TestDirector(); - * - * @brief Destructor. - */ - ~TestDirector(); - - /** - * @fn virtual void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg); - * - * @brief Handles the system event described by msg. - * - * @param msg The message. - */ - virtual void HandleSystemEvent(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); - * - * @brief Handles the tick message. - * - * @param msg The message. - */ - virtual void HandleTickMessage(const trManager::MessageBase& msg); -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include + +#include + +class TestDirector : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static int MAX_FRAME_NUMBER = 25; ///Number of frames for the loop to run. + const static int SPEED_FRAME_NUMBER = 5; ///Number of frames on which the TimeScale should be increased. + + /** + * @fn TestDirector::TestDirector(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestDirector::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + +protected: + + /** + * @fn TestDirector::~TestDirector(); + * + * @brief Destructor. + */ + ~TestDirector(); + + /** + * @fn virtual void TestDirector::HandleSystemEvent(const trManager::MessageBase& msg); + * + * @brief Handles the system event described by msg. + * + * @param msg The message. + */ + virtual void HandleSystemEvent(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector::HandleTickMessage(const trManager::MessageBase& msg); + * + * @brief Handles the tick message. + * + * @param msg The message. + */ + virtual void HandleTickMessage(const trManager::MessageBase& msg); +}; + diff --git a/Examples/Director/TestDirector2.cpp b/Examples/Director/TestDirector2.cpp index 7fa29ff..23fb318 100644 --- a/Examples/Director/TestDirector2.cpp +++ b/Examples/Director/TestDirector2.cpp @@ -1,73 +1,73 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestDirector2.h" - -#include -#include - -const trUtil::RefStr TestDirector2::CLASS_TYPE = trUtil::RefStr("TestDirector2"); - -int TestDirector2::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestDirector2::TestDirector2(const std::string& name) : BaseClass(name) -{ - ++mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -TestDirector2::~TestDirector2() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector2::OnMessage(const trManager::MessageBase& msg) -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector2::OnTick(const trManager::MessageBase & msg) -{ - //Cast the message into what it is, and pass it to a handler - HandleTickMessage(static_cast(msg)); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector2::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector2::HandleTickMessage(const trManager::MessageBase& msg) -{ - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); - std::cout << GetName() << ": Got Tick Message" << std::endl; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector2::GetInstCount() -{ - return mInstCount; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestDirector2.h" + +#include +#include + +const trUtil::RefStr TestDirector2::CLASS_TYPE = trUtil::RefStr("TestDirector2"); + +int TestDirector2::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestDirector2::TestDirector2(const std::string& name) : BaseClass(name) +{ + ++mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +TestDirector2::~TestDirector2() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector2::OnMessage(const trManager::MessageBase& /*msg*/) +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector2::OnTick(const trManager::MessageBase & msg) +{ + //Cast the message into what it is, and pass it to a handler + HandleTickMessage(static_cast(msg)); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector2::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector2::HandleTickMessage(const trManager::MessageBase& /*msg*/) +{ + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::WHITE); + std::cout << GetName() << ": Got Tick Message" << std::endl; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector2::GetInstCount() +{ + return mInstCount; +} + diff --git a/Examples/Director/TestDirector2.h b/Examples/Director/TestDirector2.h index 8ab9eb4..b86f952 100644 --- a/Examples/Director/TestDirector2.h +++ b/Examples/Director/TestDirector2.h @@ -1,108 +1,108 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include - -#include - -class TestDirector2 : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn TestDirector2::TestDirector2(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector2(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector2::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestDirector2::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector2::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestDirector2::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestDirector2::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - -protected: - - static int mInstCount; - - /** - * @fn TestDirector2::~TestDirector2(); - * - * @brief Destructor. - */ - ~TestDirector2(); - - /** - * @fn virtual void TestDirector2::HandleTickMessage(const trManager::MessageBase& msg); - * - * @brief Handles the tick message. - * - * @param msg The message. - */ - virtual void HandleTickMessage(const trManager::MessageBase& msg); - -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include + +#include + +class TestDirector2 : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn TestDirector2::TestDirector2(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector2(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector2::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestDirector2::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector2::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestDirector2::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestDirector2::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + +protected: + + static int mInstCount; + + /** + * @fn TestDirector2::~TestDirector2(); + * + * @brief Destructor. + */ + ~TestDirector2(); + + /** + * @fn virtual void TestDirector2::HandleTickMessage(const trManager::MessageBase& msg); + * + * @brief Handles the tick message. + * + * @param msg The message. + */ + virtual void HandleTickMessage(const trManager::MessageBase& msg); + +}; + diff --git a/Examples/Director/Utils.cpp b/Examples/Director/Utils.cpp index 76ee161..3ffae87 100644 --- a/Examples/Director/Utils.cpp +++ b/Examples/Director/Utils.cpp @@ -1,59 +1,59 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - -#include -#include -#include -/* -* Parses the command line variables that are passed in to the executable -*/ -void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) -{ - trUtil::ArgumentParser arguments(&argc, argv); - - arguments.SetApplicationName(PROGRAM_NAME); - - arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); - arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + - trUtil::Logging::LOG_INFO_STR + ", " + - trUtil::Logging::LOG_WARNING_STR + ", " + - trUtil::Logging::LOG_ERROR_STR + ""); - arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); - - if (arguments.Read("--help") == true || - arguments.Read("/help") == true || - arguments.Read("-h") == true || - arguments.Read("/h") == true || - arguments.Read("/?") == true) - { - arguments.Write(std::cout); - exit(0); - } - - arguments.Read("--logFileName", logFileName); - arguments.Read("--logLevel", logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + +#include +#include +#include +/* +* Parses the command line variables that are passed in to the executable +*/ +void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) +{ + trUtil::ArgumentParser arguments(&argc, argv); + + arguments.SetApplicationName(PROGRAM_NAME); + + arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); + arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + + trUtil::Logging::LOG_INFO_STR + ", " + + trUtil::Logging::LOG_WARNING_STR + ", " + + trUtil::Logging::LOG_ERROR_STR + ""); + arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); + + if (arguments.Read("--help") == true || + arguments.Read("/help") == true || + arguments.Read("-h") == true || + arguments.Read("/h") == true || + arguments.Read("/?") == true) + { + arguments.Write(std::cout); + exit(0); + } + + arguments.Read("--logFileName", logFileName); + arguments.Read("--logLevel", logLevel); } \ No newline at end of file diff --git a/Examples/Director/Utils.h b/Examples/Director/Utils.h index 00d5a4f..b3fb05e 100644 --- a/Examples/Director/Utils.h +++ b/Examples/Director/Utils.h @@ -1,31 +1,31 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -static const std::string PROGRAM_NAME = "TrueReality"; -static const std::string EXE_NAME = "exampleDirector"; - -/* -* Parses the command line variables that are passed in to the executable -*/ +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +static const std::string PROGRAM_NAME = "TrueReality"; +static const std::string EXE_NAME = "exampleDirector"; + +/* +* Parses the command line variables that are passed in to the executable +*/ void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); \ No newline at end of file diff --git a/Examples/Json/Main.cpp b/Examples/Json/Main.cpp index b24ea97..742759b 100644 --- a/Examples/Json/Main.cpp +++ b/Examples/Json/Main.cpp @@ -1,170 +1,170 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/** -* Software's main function. -*/ -int main(int argc, char** argv) -{ - const static std::string CONFIG_FILE_NAME = "JsonExampleConf.json"; - std::string logFileName; - std::string logLevel; - - //Parse command line arguments - ParseCmdLineArgs(argc, argv, logFileName, logLevel); - - //Creates the default folders in the User Data folder. - trUtil::PathUtils::CreateUserDataPathTree(); - - //Setup our Logging options - trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); - - try - { - //Show Logo - trUtil::Console::Logo(); - - //Start program - std::cout << "Creating a JSON Document" << std::endl; - - trUtil::JSON::Object jsObject; - trUtil::JSON::Array jsArray; - - trUtil::JSON::File configFile(CONFIG_FILE_NAME); - - std::cout << "Inputing Data into Document" << std::endl; - - jsArray.AddInt(55); - jsArray.AddInt(3456); - jsArray.AddInt64(63752); - jsArray.AddNull(); //NULLs the value - jsArray.AddBool(true); - jsArray.AddString("StringValue"); - jsArray.AddDouble(45.6); - jsArray.AddUInt(4567); - jsArray.AddUInt64(12098); - jsArray.AddFloat(567.54f); - jsArray.SetComment("///This is the Array Comment"); - - std::cout << "JSON Array in RAM:\n" << std::endl; - jsArray.PrintJSONRoot(); - std::cout << std::endl; - - jsObject.SetInt("MyInt", 55); - jsObject.SetInt("MyInt2", 3456); - jsObject.SetInt64("MyInt64", 63752); - jsObject.SetNull("MyInt"); //NULLs the value - jsObject.SetBool("MyBool", true); - jsObject.SetString("MyString", "StringValue"); - jsObject.SetDouble("MyDouble", 45.6); - jsObject.SetUInt("MyUint", 4567); - jsObject.SetUInt64("MyUint64", 12098); - jsObject.SetFloat("MyFloat", 567.54f); - jsObject.SetArray("MyArray", jsArray); - jsObject.SetComment("This is the Object Comment"); - - std::cout << "JSON jsObject in RAM:\n" << std::endl; - jsObject.PrintJSONRoot(); - std::cout << std::endl; - - configFile.SetInt("MyInt", 55); - configFile.SetInt("MyInt2", 3456); - configFile.SetInt64("MyInt64", 63752); - configFile.SetNull("MyInt"); //NULLs the value - configFile.SetBool("MyBool", true); - configFile.SetString("MyString", "StringValue"); - configFile.SetDouble("MyDouble", 45.6); - configFile.SetUInt("MyUint", 4567); - configFile.SetUInt64("MyUint64", 12098); - configFile.SetFloat("MyFloat", 567.54f); - configFile.SetObject("MyObject", jsObject); - - std::cout << "JSON File in RAM:\n" << std::endl; - configFile.PrintJSONRoot(); - std::cout << std::endl; - - std::cout << "Writing out JSON File" << std::endl; - configFile.WriteToFile(); - std::cout << "Done Writing out JSON File" << std::endl; - - trUtil::JSON::File readFile(CONFIG_FILE_NAME); - std::cout << "\n\nReading JSON File" << std::endl; - readFile.ReadFromFile(); - - std::cout << "JSON File in RAM:\n" << std::endl; - readFile.PrintJSONRoot(); - - trUtil::JSON::Array jsArr = configFile.GetObject("MyObject").GetArray("MyArray"); - - std::cout << "\nJSON Array in RAM:\n" << std::endl; - jsArr.PrintJSONRoot(); - - std::cout << "\nPrinting the Array Comment: " << jsArr.GetComment() << std::endl; - - std::cout << "\nJSON Array Size: " << jsArr.Size() << std::endl; - std::cout << "\nIterating through JSON Array in RAM:\n" << std::endl; - for (int i = 0; i < jsArr.Size(); i++) - { - std::cout << jsArr[i] << std::endl; - } - - std::cout << "\nRemoving value 5 from the JSON Array:\n" << std::endl; - jsArr.RemoveIndex(5, new trUtil::JSON::Value); - - std::cout << "\nJSON Array in RAM:\n" << std::endl; - jsArr.PrintJSONRoot(); - - std::cout << "\nJSON Array Size: " << jsArr.Size() << std::endl; - - trUtil::JSON::Object jsObj = configFile.GetObject("MyObject"); - std::cout << "\nJSON Object in RAM:\n" << std::endl; - jsObj.PrintJSONRoot(); - - std::cout << "\nPrinting the Object Comment: " << jsObj.GetComment() << "\n\n" << std::endl; - - //Ending program - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); - std::cerr << "True Reality is now shutting down ... " << std::endl; - trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); - LOG_A("True Reality is now shutting down ... "); - } - catch (const trUtil::Exception& ex) - { - LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); - ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); - return -1; - } - return 0; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/** +* Software's main function. +*/ +int main(int argc, char** argv) +{ + const static std::string CONFIG_FILE_NAME = "JsonExampleConf.json"; + std::string logFileName; + std::string logLevel; + + //Parse command line arguments + ParseCmdLineArgs(argc, argv, logFileName, logLevel); + + //Creates the default folders in the User Data folder. + trUtil::PathUtils::CreateUserDataPathTree(); + + //Setup our Logging options + trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel); + + try + { + //Show Logo + trUtil::Console::Logo(); + + //Start program + std::cout << "Creating a JSON Document" << std::endl; + + trUtil::JSON::Object jsObject; + trUtil::JSON::Array jsArray; + + trUtil::JSON::File configFile(CONFIG_FILE_NAME); + + std::cout << "Inputing Data into Document" << std::endl; + + jsArray.AddInt(55); + jsArray.AddInt(3456); + jsArray.AddInt64(63752); + jsArray.AddNull(); //NULLs the value + jsArray.AddBool(true); + jsArray.AddString("StringValue"); + jsArray.AddDouble(45.6); + jsArray.AddUInt(4567); + jsArray.AddUInt64(12098); + jsArray.AddFloat(567.54f); + jsArray.SetComment("///This is the Array Comment"); + + std::cout << "JSON Array in RAM:\n" << std::endl; + jsArray.PrintJSONRoot(); + std::cout << std::endl; + + jsObject.SetInt("MyInt", 55); + jsObject.SetInt("MyInt2", 3456); + jsObject.SetInt64("MyInt64", 63752); + jsObject.SetNull("MyInt"); //NULLs the value + jsObject.SetBool("MyBool", true); + jsObject.SetString("MyString", "StringValue"); + jsObject.SetDouble("MyDouble", 45.6); + jsObject.SetUInt("MyUint", 4567); + jsObject.SetUInt64("MyUint64", 12098); + jsObject.SetFloat("MyFloat", 567.54f); + jsObject.SetArray("MyArray", jsArray); + jsObject.SetComment("This is the Object Comment"); + + std::cout << "JSON jsObject in RAM:\n" << std::endl; + jsObject.PrintJSONRoot(); + std::cout << std::endl; + + configFile.SetInt("MyInt", 55); + configFile.SetInt("MyInt2", 3456); + configFile.SetInt64("MyInt64", 63752); + configFile.SetNull("MyInt"); //NULLs the value + configFile.SetBool("MyBool", true); + configFile.SetString("MyString", "StringValue"); + configFile.SetDouble("MyDouble", 45.6); + configFile.SetUInt("MyUint", 4567); + configFile.SetUInt64("MyUint64", 12098); + configFile.SetFloat("MyFloat", 567.54f); + configFile.SetObject("MyObject", jsObject); + + std::cout << "JSON File in RAM:\n" << std::endl; + configFile.PrintJSONRoot(); + std::cout << std::endl; + + std::cout << "Writing out JSON File" << std::endl; + configFile.WriteToFile(); + std::cout << "Done Writing out JSON File" << std::endl; + + trUtil::JSON::File readFile(CONFIG_FILE_NAME); + std::cout << "\n\nReading JSON File" << std::endl; + readFile.ReadFromFile(); + + std::cout << "JSON File in RAM:\n" << std::endl; + readFile.PrintJSONRoot(); + + trUtil::JSON::Array jsArr = configFile.GetObject("MyObject").GetArray("MyArray"); + + std::cout << "\nJSON Array in RAM:\n" << std::endl; + jsArr.PrintJSONRoot(); + + std::cout << "\nPrinting the Array Comment: " << jsArr.GetComment() << std::endl; + + std::cout << "\nJSON Array Size: " << jsArr.Size() << std::endl; + std::cout << "\nIterating through JSON Array in RAM:\n" << std::endl; + for (int i = 0; i < jsArr.Size(); i++) + { + std::cout << jsArr[i] << std::endl; + } + + std::cout << "\nRemoving value 5 from the JSON Array:\n" << std::endl; + jsArr.RemoveIndex(5, new trUtil::JSON::Value); + + std::cout << "\nJSON Array in RAM:\n" << std::endl; + jsArr.PrintJSONRoot(); + + std::cout << "\nJSON Array Size: " << jsArr.Size() << std::endl; + + trUtil::JSON::Object jsObj = configFile.GetObject("MyObject"); + std::cout << "\nJSON Object in RAM:\n" << std::endl; + jsObj.PrintJSONRoot(); + + std::cout << "\nPrinting the Object Comment: " << jsObj.GetComment() << "\n\n" << std::endl; + + //Ending program + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::BRIGHT_RED); + std::cerr << "True Reality is now shutting down ... " << std::endl; + trUtil::Console::TextColor(trUtil::Console::TXT_COLOR::DEFAULT); + LOG_A("True Reality is now shutting down ... "); + } + catch (const trUtil::Exception& ex) + { + LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString()); + ex.LogException(trUtil::Logging::LogLevel::LOG_ERROR); + return -1; + } + return 0; } \ No newline at end of file diff --git a/Examples/Json/Utils.cpp b/Examples/Json/Utils.cpp index f536711..2032c7b 100644 --- a/Examples/Json/Utils.cpp +++ b/Examples/Json/Utils.cpp @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - -#include -#include -#include - -/* -* Parses the command line variables that are passed in to the executable -*/ -void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) -{ - trUtil::ArgumentParser arguments(&argc, argv); - - arguments.SetApplicationName(PROGRAM_NAME); - - arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); - arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + - trUtil::Logging::LOG_INFO_STR + ", " + - trUtil::Logging::LOG_WARNING_STR + ", " + - trUtil::Logging::LOG_ERROR_STR + ""); - arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); - - if (arguments.Read("--help") == true || - arguments.Read("/help") == true || - arguments.Read("-h") == true || - arguments.Read("/h") == true || - arguments.Read("/?") == true) - { - arguments.Write(std::cout); - exit(0); - } - - arguments.Read("--logFileName", logFileName); - arguments.Read("--logLevel", logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + +#include +#include +#include + +/* +* Parses the command line variables that are passed in to the executable +*/ +void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel) +{ + trUtil::ArgumentParser arguments(&argc, argv); + + arguments.SetApplicationName(PROGRAM_NAME); + + arguments.AddCommandLineOption("\n--logFileName ", "The name of the log file to use. Defaults to TrueRealityLog.html"); + arguments.AddCommandLineOption("\n--logLevel ", "Logging level to use. \nLevel options are: " + trUtil::Logging::LOG_DEBUG_STR + ", " + + trUtil::Logging::LOG_INFO_STR + ", " + + trUtil::Logging::LOG_WARNING_STR + ", " + + trUtil::Logging::LOG_ERROR_STR + ""); + arguments.AddCommandLineOption("\n--help, /help, -h, /h, /? ", "Show this help screen."); + + if (arguments.Read("--help") == true || + arguments.Read("/help") == true || + arguments.Read("-h") == true || + arguments.Read("/h") == true || + arguments.Read("/?") == true) + { + arguments.Write(std::cout); + exit(0); + } + + arguments.Read("--logFileName", logFileName); + arguments.Read("--logLevel", logLevel); } \ No newline at end of file diff --git a/Examples/Json/Utils.h b/Examples/Json/Utils.h index 6640f5e..27f513e 100644 --- a/Examples/Json/Utils.h +++ b/Examples/Json/Utils.h @@ -1,31 +1,31 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -static const std::string PROGRAM_NAME = "TrueReality"; -static const std::string EXE_NAME = "examplesJSON"; - -/* -* Parses the command line variables that are passed in to the executable -*/ +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +static const std::string PROGRAM_NAME = "TrueReality"; +static const std::string EXE_NAME = "examplesJSON"; + +/* +* Parses the command line variables that are passed in to the executable +*/ void ParseCmdLineArgs(int& argc, char** argv, std::string& logFileName, std::string& logLevel); \ No newline at end of file diff --git a/Scripts/CMakeLists.txt b/Scripts/CMakeLists.txt new file mode 100644 index 0000000..522d137 --- /dev/null +++ b/Scripts/CMakeLists.txt @@ -0,0 +1,71 @@ +# True Reality Open Source Game and Simulation Engine +# Copyright � 2019 Acid Rain Studios LLC +# +# This library is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 3.0 of the License, or (at your option) +# any later version. +# +# This library 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 Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# @author Maxim Serebrennik + +SET (FILE_NAME Scripts) + +# ***************************************************************************** +# Create Environment Scripts ************************************************** +# ***************************************************************************** +IF (WIN32) + MESSAGE (STATUS "Creating Windows Environment Scripts ***(Admin rights are needed to install scripts)***") + + # Configures the Build environment script + SET (PATH_TITLE "echo Setting up True Reality ${TR_VERSION} Build Environment") + SET (PATH_CMD "SET PATH=${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/include;%PATH%") + SET (PATH_TR_ROOT "SET TR_ROOT=${CMAKE_INSTALL_PREFIX}") + CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/${FILE_NAME}/EnvScript.in" "${PROJECT_BINARY_DIR}/${FILE_NAME}/trEnv-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_YYMM}.cmd" NEWLINE_STYLE LF) + + # Configures the RunTime environment script + SET (PATH_TITLE "echo Setting up True Reality ${TR_VERSION} Runtime Environment") + SET (PATH_CMD "SET PATH=${CMAKE_INSTALL_PREFIX}/bin;${CMAKE_INSTALL_PREFIX}/lib;%PATH%") + SET (PATH_TR_ROOT "SET TR_ROOT=${CMAKE_INSTALL_PREFIX}") + CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/${FILE_NAME}/EnvScript.in" "${PROJECT_BINARY_DIR}/${FILE_NAME}/trEnvRT-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_YYMM}.cmd" NEWLINE_STYLE LF) + +ELSEIF (UNIX) + MESSAGE (STATUS "Creating Linux Environment Scripts ***(Admin rights are needed to install scripts)***") + + # Configures the Build environment script + SET (PATH_TITLE "echo Setting up True Reality ${TR_VERSION} Subshell Build Environment") + SET (PATH_CMD "export PATH=${CMAKE_INSTALL_PREFIX}/bin:${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/include:$PATH") + SET (PATH_TR_ROOT "export TR_ROOT=${CMAKE_INSTALL_PREFIX}") + SET (LD_PATH_CMD "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$LD_LIBRARY_PATH") + CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/${FILE_NAME}/EnvScriptLinux.in" "${PROJECT_BINARY_DIR}/${FILE_NAME}/trEnv-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_YYMM}.sh" NEWLINE_STYLE LF) + + # Configures the RunTime environment script + SET (PATH_TITLE "echo Setting up True Reality ${TR_VERSION} Subshell Runtime Environment") + SET (PATH_CMD "export PATH=${CMAKE_INSTALL_PREFIX}/bin:${CMAKE_INSTALL_PREFIX}/lib:$PATH") + SET (PATH_TR_ROOT "export TR_ROOT=${CMAKE_INSTALL_PREFIX}") + SET (LD_PATH_CMD "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$LD_LIBRARY_PATH") + CONFIGURE_FILE ("${CMAKE_SOURCE_DIR}/${FILE_NAME}/EnvScriptLinux.in" "${PROJECT_BINARY_DIR}/${FILE_NAME}/trEnvRT-${TR_VERSION_MAJOR}.${TR_VERSION_MINOR}.${TR_VERSION_YYMM}.sh" NEWLINE_STYLE LF) +ENDIF () + +# Set the source paths +SET (SOURCE_PATH ${PROJECT_BINARY_DIR}/${FILE_NAME}) + +# Sets the sources using "GLOB" +FILE (GLOB PROJECT_SOURCES "${SOURCE_PATH}/trEnv*.*") + +# Generates the target for the project from sources +ADD_CUSTOM_TARGET (${FILE_NAME} SOURCES ${PROJECT_SOURCES}) + +# Place the project in a folder +SET_TARGET_PROPERTIES (${FILE_NAME} PROPERTIES FOLDER "ContentInstalls") + +# Sets Project Install options +TR_INSTALL_SCRIPT_FILES ("${PROJECT_SOURCES}") \ No newline at end of file diff --git a/Scripts/EnvScript.in b/Scripts/EnvScript.in new file mode 100644 index 0000000..fa8d149 --- /dev/null +++ b/Scripts/EnvScript.in @@ -0,0 +1,17 @@ +@echo off +echo. +${PATH_TITLE} + +echo %PSModulePath% | findstr %USERPROFILE% >NUL +IF %ERRORLEVEL% EQU 0 goto :ISPOWERSHELL + +echo Command Prompt detected ... +echo ... +${PATH_CMD} +${PATH_TR_ROOT} +echo Done! +GOTO :EOF + +:ISPOWERSHELL +echo ERROR: Power Shell Not Supported ... +echo Please use Command Prompt to run this script diff --git a/Scripts/EnvScriptLinux.in b/Scripts/EnvScriptLinux.in new file mode 100644 index 0000000..094a6f1 --- /dev/null +++ b/Scripts/EnvScriptLinux.in @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +${PATH_TITLE} +echo ... +${PATH_CMD} +${PATH_TR_ROOT} +${LD_PATH_CMD} +echo Done! +echo Type 'exit' to exit the subshell +exec bash \ No newline at end of file diff --git a/Tests/TrBase/MatrixTests.cpp b/Tests/TrBase/MatrixTests.cpp index bc28ec0..0cb4cf9 100644 --- a/Tests/TrBase/MatrixTests.cpp +++ b/Tests/TrBase/MatrixTests.cpp @@ -1,1622 +1,1622 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "MatrixTests.h" - -#include - -////////////////////////////////////////////////////////////////////////// -MatrixTests::MatrixTests() -{ -} - -////////////////////////////////////////////////////////////////////////// -MatrixTests::~MatrixTests() -{ -} - -/** - * @fn TEST_F(MatrixTests, Matrix) - * - * @brief Test of Matrix class definition, between Matrixf and Matrixd - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, Matrix) -{ -#ifdef TR_USE_DOUBLE_MATRIX - EXPECT_EQ(typeid(trBase::Matrix), typeid(trBase::Matrixd)); - EXPECT_NE(typeid(trBase::Matrix), typeid(trBase::Matrixf)); -#else - EXPECT_EQ(typeid(trBase::Matrix), typeid(trBase::Matrixf)); - EXPECT_NE(typeid(trBase::Matrix), typeid(trBase::Matrixd)); -#endif -} - -/** - * @fn TEST_F(MatrixTests, CreateMatrix) - * - * @brief Test the creation of a default Matrix. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CreateMatrix) -{ - // Create a new matrix using the default constructor - mTestMatrix = trBase::Matrix(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.0); - EXPECT_EQ(mTestMatrix(0, 1), 0.0); - EXPECT_EQ(mTestMatrix(0, 2), 0.0); - EXPECT_EQ(mTestMatrix(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 0.0); - EXPECT_EQ(mTestMatrix(1, 1), 1.0); - EXPECT_EQ(mTestMatrix(1, 2), 0.0); - EXPECT_EQ(mTestMatrix(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 0.0); - EXPECT_EQ(mTestMatrix(2, 1), 0.0); - EXPECT_EQ(mTestMatrix(2, 2), 1.0); - EXPECT_EQ(mTestMatrix(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0.0); - EXPECT_EQ(mTestMatrix(3, 1), 0.0); - EXPECT_EQ(mTestMatrix(3, 2), 0.0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - // Create a new matrix using the default constructor - mTestMatrixF1 = trBase::Matrixf(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF1(0, 0), 1.0); - EXPECT_EQ(mTestMatrixF1(0, 1), 0.0); - EXPECT_EQ(mTestMatrixF1(0, 2), 0.0); - EXPECT_EQ(mTestMatrixF1(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF1(1, 0), 0.0); - EXPECT_EQ(mTestMatrixF1(1, 1), 1.0); - EXPECT_EQ(mTestMatrixF1(1, 2), 0.0); - EXPECT_EQ(mTestMatrixF1(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF1(2, 0), 0.0); - EXPECT_EQ(mTestMatrixF1(2, 1), 0.0); - EXPECT_EQ(mTestMatrixF1(2, 2), 1.0); - EXPECT_EQ(mTestMatrixF1(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF1(3, 0), 0.0); - EXPECT_EQ(mTestMatrixF1(3, 1), 0.0); - EXPECT_EQ(mTestMatrixF1(3, 2), 0.0); - EXPECT_EQ(mTestMatrixF1(3, 3), 1.0); - - // Create a new matrix using the default constructor - mTestMatrixD1 = trBase::Matrixd(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); - EXPECT_EQ(mTestMatrixD1(0, 1), 0.0); - EXPECT_EQ(mTestMatrixD1(0, 2), 0.0); - EXPECT_EQ(mTestMatrixD1(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD1(1, 0), 0.0); - EXPECT_EQ(mTestMatrixD1(1, 1), 1.0); - EXPECT_EQ(mTestMatrixD1(1, 2), 0.0); - EXPECT_EQ(mTestMatrixD1(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD1(2, 0), 0.0); - EXPECT_EQ(mTestMatrixD1(2, 1), 0.0); - EXPECT_EQ(mTestMatrixD1(2, 2), 1.0); - EXPECT_EQ(mTestMatrixD1(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 0.0); - EXPECT_EQ(mTestMatrixD1(3, 1), 0.0); - EXPECT_EQ(mTestMatrixD1(3, 2), 0.0); - EXPECT_EQ(mTestMatrixD1(3, 3), 1.0); -} - -/** - * @fn TEST_F(MatrixTests, CreateMatrixFromNum) - * - * @brief Test the creation of a Matrix from raw input - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CreateMatrixFromNum) -{ - // Create a matrix - mTestMatrix = trBase::Matrix( 1.2, 1.3, 1.4, 0.5, - 1.6, 1.7, 1.8, 0.6, - 2.0, 2.1, 2.2, 0.7, - 2.4, 2.5, 2.6, 0.8); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.2); - EXPECT_EQ(mTestMatrix(0, 1), 1.3); - EXPECT_EQ(mTestMatrix(0, 2), 1.4); - EXPECT_EQ(mTestMatrix(0, 3), 0.5); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 1.6); - EXPECT_EQ(mTestMatrix(1, 1), 1.7); - EXPECT_EQ(mTestMatrix(1, 2), 1.8); - EXPECT_EQ(mTestMatrix(1, 3), 0.6); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 2.0); - EXPECT_EQ(mTestMatrix(2, 1), 2.1); - EXPECT_EQ(mTestMatrix(2, 2), 2.2); - EXPECT_EQ(mTestMatrix(2, 3), 0.7); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 2.4); - EXPECT_EQ(mTestMatrix(3, 1), 2.5); - EXPECT_EQ(mTestMatrix(3, 2), 2.6); - EXPECT_EQ(mTestMatrix(3, 3), 0.8); - - // Create a double matrix - mTestMatrixD1 = trBase::Matrixd(1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); - EXPECT_EQ(mTestMatrixD1(0, 1), 2.0); - EXPECT_EQ(mTestMatrixD1(0, 2), 3.0); - EXPECT_EQ(mTestMatrixD1(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD1(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD1(1, 1), 6.0); - EXPECT_EQ(mTestMatrixD1(1, 2), 7.0); - EXPECT_EQ(mTestMatrixD1(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD1(2, 0), 9.0); - EXPECT_EQ(mTestMatrixD1(2, 1), 8.0); - EXPECT_EQ(mTestMatrixD1(2, 2), 7.0); - EXPECT_EQ(mTestMatrixD1(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD1(3, 1), 4.0); - EXPECT_EQ(mTestMatrixD1(3, 2), 3.0); - EXPECT_EQ(mTestMatrixD1(3, 3), 2.0); - - // Create a float matrix - mTestMatrixF1 = trBase::Matrixf(9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0, - 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF1(0, 0), 9.0); - EXPECT_EQ(mTestMatrixF1(0, 1), 8.0); - EXPECT_EQ(mTestMatrixF1(0, 2), 7.0); - EXPECT_EQ(mTestMatrixF1(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF1(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF1(1, 1), 4.0); - EXPECT_EQ(mTestMatrixF1(1, 2), 3.0); - EXPECT_EQ(mTestMatrixF1(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF1(2, 0), 1.0); - EXPECT_EQ(mTestMatrixF1(2, 1), 2.0); - EXPECT_EQ(mTestMatrixF1(2, 2), 3.0); - EXPECT_EQ(mTestMatrixF1(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF1(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF1(3, 1), 6.0); - EXPECT_EQ(mTestMatrixF1(3, 2), 7.0); - EXPECT_EQ(mTestMatrixF1(3, 3), 8.0); -} - -/** - * @fn TEST_F(MatrixTests, CreateMatrixFromMatrix) - * - * @brief Test the creation of a Matrix from another Matrix - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CreateMatrixFromMatrix) -{ - // Create a float matrix - mTestMatrixF1 = trBase::Matrixf(9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0, - 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0); - - // Create a double matrix - mTestMatrixD1 = trBase::Matrixd(1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0); - - // Create a float matrix from float matrix - mTestMatrixF2 = trBase::Matrixf(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF2(0, 0), 9.0); - EXPECT_EQ(mTestMatrixF2(0, 1), 8.0); - EXPECT_EQ(mTestMatrixF2(0, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(1, 1), 4.0); - EXPECT_EQ(mTestMatrixF2(1, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF2(2, 0), 1.0); - EXPECT_EQ(mTestMatrixF2(2, 1), 2.0); - EXPECT_EQ(mTestMatrixF2(2, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(3, 1), 6.0); - EXPECT_EQ(mTestMatrixF2(3, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(3, 3), 8.0); - - // Create a float matrix from double matrix - mTestMatrixF2 = trBase::Matrixf(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF2(0, 0), 1.0); - EXPECT_EQ(mTestMatrixF2(0, 1), 2.0); - EXPECT_EQ(mTestMatrixF2(0, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(1, 1), 6.0); - EXPECT_EQ(mTestMatrixF2(1, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF2(2, 0), 9.0); - EXPECT_EQ(mTestMatrixF2(2, 1), 8.0); - EXPECT_EQ(mTestMatrixF2(2, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(3, 1), 4.0); - EXPECT_EQ(mTestMatrixF2(3, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(3, 3), 2.0); - - // Create a double matrix from float matrix - mTestMatrixD2 = trBase::Matrixd(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD2(0, 0), 9.0); - EXPECT_EQ(mTestMatrixD2(0, 1), 8.0); - EXPECT_EQ(mTestMatrixD2(0, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(1, 1), 4.0); - EXPECT_EQ(mTestMatrixD2(1, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD2(2, 0), 1.0); - EXPECT_EQ(mTestMatrixD2(2, 1), 2.0); - EXPECT_EQ(mTestMatrixD2(2, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(3, 1), 6.0); - EXPECT_EQ(mTestMatrixD2(3, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(3, 3), 8.0); - - // Create a double matrix from double matrix - mTestMatrixD2 = trBase::Matrixd(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD2(0, 0), 1.0); - EXPECT_EQ(mTestMatrixD2(0, 1), 2.0); - EXPECT_EQ(mTestMatrixD2(0, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(1, 1), 6.0); - EXPECT_EQ(mTestMatrixD2(1, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD2(2, 0), 9.0); - EXPECT_EQ(mTestMatrixD2(2, 1), 8.0); - EXPECT_EQ(mTestMatrixD2(2, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(3, 1), 4.0); - EXPECT_EQ(mTestMatrixD2(3, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(3, 3), 2.0); - - // Create a matrix from float matrix - mTestMatrix = trBase::Matrix(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 9.0); - EXPECT_EQ(mTestMatrix(0, 1), 8.0); - EXPECT_EQ(mTestMatrix(0, 2), 7.0); - EXPECT_EQ(mTestMatrix(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 5.0); - EXPECT_EQ(mTestMatrix(1, 1), 4.0); - EXPECT_EQ(mTestMatrix(1, 2), 3.0); - EXPECT_EQ(mTestMatrix(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 1.0); - EXPECT_EQ(mTestMatrix(2, 1), 2.0); - EXPECT_EQ(mTestMatrix(2, 2), 3.0); - EXPECT_EQ(mTestMatrix(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 5.0); - EXPECT_EQ(mTestMatrix(3, 1), 6.0); - EXPECT_EQ(mTestMatrix(3, 2), 7.0); - EXPECT_EQ(mTestMatrix(3, 3), 8.0); - - // Create a matrix from double matrix - mTestMatrix = trBase::Matrix(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.0); - EXPECT_EQ(mTestMatrix(0, 1), 2.0); - EXPECT_EQ(mTestMatrix(0, 2), 3.0); - EXPECT_EQ(mTestMatrix(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 5.0); - EXPECT_EQ(mTestMatrix(1, 1), 6.0); - EXPECT_EQ(mTestMatrix(1, 2), 7.0); - EXPECT_EQ(mTestMatrix(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 9.0); - EXPECT_EQ(mTestMatrix(2, 1), 8.0); - EXPECT_EQ(mTestMatrix(2, 2), 7.0); - EXPECT_EQ(mTestMatrix(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 5.0); - EXPECT_EQ(mTestMatrix(3, 1), 4.0); - EXPECT_EQ(mTestMatrix(3, 2), 3.0); - EXPECT_EQ(mTestMatrix(3, 3), 2.0); -} - -/** - * @fn TEST_F(MatrixTests, CreateMatrixFromArray) - * - * @brief Test the creation of a Matrix from an array - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CreateMatrixFromArray) -{ - // Create a new matrix - mTestMatrixF1 = trBase::Matrixf(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixF1(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixF1(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixF1(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixF1(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrixF1 = trBase::Matrixf(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixF1(0, 0), 2.1, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 2), 5.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 3), 4.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixF1(1, 0), 7.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 2), 8.9, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 3), 0.5, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixF1(2, 0), 5.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 1), 6.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 2), 7.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 3), 2.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixF1(3, 0), 4.5, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 1), 3.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 2), 2.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 3), 8.3, 1e-6); - - // Create a new matrix - mTestMatrixD1 = trBase::Matrixd(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixD1(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixD1(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixD1(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixD1(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrixD1 = trBase::Matrixd(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD1(0, 0), 2.1); - EXPECT_EQ(mTestMatrixD1(0, 1), 4.3); - EXPECT_EQ(mTestMatrixD1(0, 2), 5.6); - EXPECT_EQ(mTestMatrixD1(0, 3), 4.5); - - // Test the second row values - EXPECT_EQ(mTestMatrixD1(1, 0), 7.8); - EXPECT_EQ(mTestMatrixD1(1, 1), 8.7); - EXPECT_EQ(mTestMatrixD1(1, 2), 8.9); - EXPECT_EQ(mTestMatrixD1(1, 3), 0.5); - - // Test the third row values - EXPECT_EQ(mTestMatrixD1(2, 0), 5.6); - EXPECT_EQ(mTestMatrixD1(2, 1), 6.6); - EXPECT_EQ(mTestMatrixD1(2, 2), 7.3); - EXPECT_EQ(mTestMatrixD1(2, 3), 2.5); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 4.5); - EXPECT_EQ(mTestMatrixD1(3, 1), 3.3); - EXPECT_EQ(mTestMatrixD1(3, 2), 2.6); - EXPECT_EQ(mTestMatrixD1(3, 3), 8.3); - - // Create a new matrix - mTestMatrix = trBase::Matrix(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrix(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrix(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrix(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrix(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrix = trBase::Matrix(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 2.1); - EXPECT_EQ(mTestMatrix(0, 1), 4.3); - EXPECT_EQ(mTestMatrix(0, 2), 5.6); - EXPECT_EQ(mTestMatrix(0, 3), 4.5); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 7.8); - EXPECT_EQ(mTestMatrix(1, 1), 8.7); - EXPECT_EQ(mTestMatrix(1, 2), 8.9); - EXPECT_EQ(mTestMatrix(1, 3), 0.5); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 5.6); - EXPECT_EQ(mTestMatrix(2, 1), 6.6); - EXPECT_EQ(mTestMatrix(2, 2), 7.3); - EXPECT_EQ(mTestMatrix(2, 3), 2.5); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 4.5); - EXPECT_EQ(mTestMatrix(3, 1), 3.3); - EXPECT_EQ(mTestMatrix(3, 2), 2.6); - EXPECT_EQ(mTestMatrix(3, 3), 8.3); -} - -/** - * @fn TEST_F(MatrixTests, CreateMatrixFromQuat) - * - * @brief Test the creation of a Matrix from a quaternion. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CreateMatrixFromQuat) -{ - /* - q = (x, y, z, w) ---> - M = - (w*w + x*x - y*y - z*z) (2*x*y - 2*w*z) (2*x*z + 2*w*y) 0 - (2*x*y + 2*w*z) (w*w - x*x + y*y - z*z) (2*y*z - 2*w*x) 0 - (2*x*z - 2*w*y) (2*y*z + 2*w*x) (w*w - x*x - y*y + z*z) 0 - 0 0 0 1 - - L = length(q)^2 - True Reality & Open Scene Graph use normalized matrices for the conversion, therefore - all values in the matrix above (except M(4,4)) needs to be divided by L - https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation - http://www.mrelusive.com/publications/papers/SIMD-From-Quaternion-to-Matrix-and-Back.pdf - */ - - // Create a test quaternion - mTestQuat.Set(1.0, 0.0, 0.0, 0.0); - - // Create a matrix - mTestMatrix = trBase::Matrix(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.0); - EXPECT_EQ(mTestMatrix(0, 1), 0.0); - EXPECT_EQ(mTestMatrix(0, 2), 0.0); - EXPECT_EQ(mTestMatrix(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 0.0); - EXPECT_EQ(mTestMatrix(1, 1), -1.0); - EXPECT_EQ(mTestMatrix(1, 2), 0.0); - EXPECT_EQ(mTestMatrix(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 0.0); - EXPECT_EQ(mTestMatrix(2, 1), 0.0); - EXPECT_EQ(mTestMatrix(2, 2), -1.0); - EXPECT_EQ(mTestMatrix(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0.0); - EXPECT_EQ(mTestMatrix(3, 1), 0.0); - EXPECT_EQ(mTestMatrix(3, 2), 0.0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - // Create a test quaternion - mTestQuat.Set(0.0, 1.0, 0.0, 0.0); - - // Create a matrix - mTestMatrix = trBase::Matrix(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), -1.0); - EXPECT_EQ(mTestMatrix(0, 1), 0.0); - EXPECT_EQ(mTestMatrix(0, 2), 0.0); - EXPECT_EQ(mTestMatrix(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 0.0); - EXPECT_EQ(mTestMatrix(1, 1), 1.0); - EXPECT_EQ(mTestMatrix(1, 2), 0.0); - EXPECT_EQ(mTestMatrix(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 0.0); - EXPECT_EQ(mTestMatrix(2, 1), 0.0); - EXPECT_EQ(mTestMatrix(2, 2), -1.0); - EXPECT_EQ(mTestMatrix(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0.0); - EXPECT_EQ(mTestMatrix(3, 1), 0.0); - EXPECT_EQ(mTestMatrix(3, 2), 0.0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - // Create a test quaternion - mTestQuat.Set(0.0, 0.0, 1.0, 0.0); - - // Create a matrix - mTestMatrix = trBase::Matrix(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), -1.0); - EXPECT_EQ(mTestMatrix(0, 1), 0.0); - EXPECT_EQ(mTestMatrix(0, 2), 0.0); - EXPECT_EQ(mTestMatrix(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 0.0); - EXPECT_EQ(mTestMatrix(1, 1), -1.0); - EXPECT_EQ(mTestMatrix(1, 2), 0.0); - EXPECT_EQ(mTestMatrix(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 0.0); - EXPECT_EQ(mTestMatrix(2, 1), 0.0); - EXPECT_EQ(mTestMatrix(2, 2), 1.0); - EXPECT_EQ(mTestMatrix(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0.0); - EXPECT_EQ(mTestMatrix(3, 1), 0.0); - EXPECT_EQ(mTestMatrix(3, 2), 0.0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - - // Create a test quaternion - mTestQuat.Set(0.0, 0.0, 0.0, 1.0); - - // Create a matrix - mTestMatrix = trBase::Matrix(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.0); - EXPECT_EQ(mTestMatrix(0, 1), 0.0); - EXPECT_EQ(mTestMatrix(0, 2), 0.0); - EXPECT_EQ(mTestMatrix(0, 3), 0.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 0.0); - EXPECT_EQ(mTestMatrix(1, 1), 1.0); - EXPECT_EQ(mTestMatrix(1, 2), 0.0); - EXPECT_EQ(mTestMatrix(1, 3), 0.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 0.0); - EXPECT_EQ(mTestMatrix(2, 1), 0.0); - EXPECT_EQ(mTestMatrix(2, 2), 1.0); - EXPECT_EQ(mTestMatrix(2, 3), 0.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0.0); - EXPECT_EQ(mTestMatrix(3, 1), 0.0); - EXPECT_EQ(mTestMatrix(3, 2), 0.0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - - // Create a test quaternion - mTestQuat.Set(2.3, 3.4, 5.6, 7.8); - - // Create a matrix - mTestMatrix = trBase::Matrix(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrix(0, 0), 0.212838148, 1e-8); - EXPECT_NEAR(mTestMatrix(0, 1), 0.944520862, 1e-8); - EXPECT_NEAR(mTestMatrix(0, 2), -0.250160477, 1e-8); - EXPECT_EQ(mTestMatrix(0, 3), 0); - - // Test the second row values - EXPECT_NEAR(mTestMatrix(1, 0), -0.657679963, 1e-8); - EXPECT_NEAR(mTestMatrix(1, 1), 0.32783127, 1e-8); - EXPECT_NEAR(mTestMatrix(1, 2), 0.678221, 1e-8); - EXPECT_EQ(mTestMatrix(1, 3), 0); - - // Test the third row values - EXPECT_NEAR(mTestMatrix(2, 0), 0.72260431, 1e-8); - EXPECT_NEAR(mTestMatrix(2, 1), 0.020174232, 1e-8); - EXPECT_NEAR(mTestMatrix(2, 2), 0.690967446, 1e-8); - EXPECT_EQ(mTestMatrix(2, 3), 0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 0); - EXPECT_EQ(mTestMatrix(3, 1), 0); - EXPECT_EQ(mTestMatrix(3, 2), 0); - EXPECT_EQ(mTestMatrix(3, 3), 1.0); - - // Create a matrix - mTestMatrixF1 = trBase::Matrixf(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixF1(0, 0), 0.212838148, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 1), 0.944520862, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 2), -0.250160477, 1e-6); - EXPECT_EQ(mTestMatrixF1(0, 3), 0); - - // Test the second row values - EXPECT_NEAR(mTestMatrixF1(1, 0), -0.657679963, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 1), 0.32783127, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 2), 0.678221, 1e-6); - EXPECT_EQ(mTestMatrixF1(1, 3), 0); - - // Test the third row values - EXPECT_NEAR(mTestMatrixF1(2, 0), 0.72260431, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 1), 0.020174232, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 2), 0.690967446, 1e-6); - EXPECT_EQ(mTestMatrixF1(2, 3), 0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF1(3, 0), 0); - EXPECT_EQ(mTestMatrixF1(3, 1), 0); - EXPECT_EQ(mTestMatrixF1(3, 2), 0); - EXPECT_EQ(mTestMatrixF1(3, 3), 1.0); - - // Create a matrix - mTestMatrixD1 = trBase::Matrixd(mTestQuat); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixD1(0, 0), 0.212838148, 1e-8); - EXPECT_NEAR(mTestMatrixD1(0, 1), 0.944520862, 1e-8); - EXPECT_NEAR(mTestMatrixD1(0, 2), -0.250160477, 1e-8); - EXPECT_EQ(mTestMatrixD1(0, 3), 0); - - // Test the second row values - EXPECT_NEAR(mTestMatrixD1(1, 0), -0.657679963, 1e-8); - EXPECT_NEAR(mTestMatrixD1(1, 1), 0.32783127, 1e-8); - EXPECT_NEAR(mTestMatrixD1(1, 2), 0.678221, 1e-8); - EXPECT_EQ(mTestMatrixD1(1, 3), 0); - - // Test the third row values - EXPECT_NEAR(mTestMatrixD1(2, 0), 0.72260431, 1e-8); - EXPECT_NEAR(mTestMatrixD1(2, 1), 0.020174232, 1e-8); - EXPECT_NEAR(mTestMatrixD1(2, 2), 0.690967446, 1e-8); - EXPECT_EQ(mTestMatrixD1(2, 3), 0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 0); - EXPECT_EQ(mTestMatrixD1(3, 1), 0); - EXPECT_EQ(mTestMatrixD1(3, 2), 0); - EXPECT_EQ(mTestMatrixD1(3, 3), 1.0); -} - -/** - * @fn TEST_F(MatrixTests, GetOSGMatrix) - * - * @brief Test the method for returning an OSG matrix - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, GetOSGMatrix) -{ - // Create a new matrix - mTestMatrixF1 = trBase::Matrixf(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Get the OSG matrix - mTestMatOsgF = mTestMatrixF1.GetOSGMatrix(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatOsgF.valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatOsgF(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatOsgF(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatOsgF(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatOsgF(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatOsgF(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatOsgF(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatOsgF(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatOsgF(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatOsgF(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatOsgF(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatOsgF(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatOsgF(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatOsgF(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatOsgF(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatOsgF(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatOsgF(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrixD1 = trBase::Matrixd(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Get the OSG matrix - mTestMatOsgD = mTestMatrixD1.GetOSGMatrix(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatOsgD.valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatOsgD(0, 0), 2.1); - EXPECT_EQ(mTestMatOsgD(0, 1), 4.3); - EXPECT_EQ(mTestMatOsgD(0, 2), 5.6); - EXPECT_EQ(mTestMatOsgD(0, 3), 4.5); - - // Test the second row values - EXPECT_EQ(mTestMatOsgD(1, 0), 7.8); - EXPECT_EQ(mTestMatOsgD(1, 1), 8.7); - EXPECT_EQ(mTestMatOsgD(1, 2), 8.9); - EXPECT_EQ(mTestMatOsgD(1, 3), 0.5); - - // Test the third row values - EXPECT_EQ(mTestMatOsgD(2, 0), 5.6); - EXPECT_EQ(mTestMatOsgD(2, 1), 6.6); - EXPECT_EQ(mTestMatOsgD(2, 2), 7.3); - EXPECT_EQ(mTestMatOsgD(2, 3), 2.5); - - // Test the fourth row values - EXPECT_EQ(mTestMatOsgD(3, 0), 4.5); - EXPECT_EQ(mTestMatOsgD(3, 1), 3.3); - EXPECT_EQ(mTestMatOsgD(3, 2), 2.6); - EXPECT_EQ(mTestMatOsgD(3, 3), 8.3); - - // Create a new matrix - mTestMatrix = trBase::Matrix(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Get the OSG matrix - mTestMatOsg = mTestMatrix.GetOSGMatrix(); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatOsg.valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatOsg(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatOsg(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatOsg(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatOsg(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatOsg(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatOsg(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatOsg(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatOsg(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatOsg(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatOsg(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatOsg(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatOsg(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatOsg(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatOsg(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatOsg(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatOsg(3, 3), 0.1, 1e-6); -} - -/** - * @fn TEST_F(MatrixTests, CompareMatrix) - * - * @brief Test the method for comparing two matrices - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, CompareMatrix) -{ - // Test if the matrices are valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - EXPECT_EQ(mTestMatrixF2.Valid(), true); - - // Compare the matrices - EXPECT_EQ(mTestMatrixF1.Compare(mTestMatrixF2), 0); - - // Create a new matrix - mTestMatrixF1 = trBase::Matrixf(mArrayF); - - // Compare the matrices - EXPECT_EQ(mTestMatrixF1.Compare(mTestMatrixF2), 1); - EXPECT_EQ(mTestMatrixF2.Compare(mTestMatrixF1), -1); - - // Test if the matrices are valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - EXPECT_EQ(mTestMatrixD2.Valid(), true); - - // Compare the matrices - EXPECT_EQ(mTestMatrixD1.Compare(mTestMatrixD2), 0); - - // Create a new matrix - mTestMatrixD1 = trBase::Matrixd(mArrayD); - - // Compare the matrices - EXPECT_EQ(mTestMatrixD1.Compare(mTestMatrixD2), 1); - EXPECT_EQ(mTestMatrixD2.Compare(mTestMatrixD1), -1); - - // Test if the matrices are valid - EXPECT_EQ(mTestMatrix.Valid(), true); - EXPECT_EQ(mTestMatrix2.Valid(), true); - - // Compare the matrices - EXPECT_EQ(mTestMatrix.Compare(mTestMatrix2), 0); - - // Create a new matrix - mTestMatrix2 = trBase::Matrix(mArrayD); - - // Compare the matrices - EXPECT_EQ(mTestMatrix.Compare(mTestMatrix2), -1); - EXPECT_EQ(mTestMatrix2.Compare(mTestMatrix), 1); -} - -/** - * @fn TEST_F(MatrixTests, SetMatrixFromNum) - * - * @brief Test the setting of a Matrix from raw input - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, SetMatrixFromNum) -{ - // Set the matrix from input - mTestMatrix.Set(1.2, 1.3, 1.4, 0.5, - 1.6, 1.7, 1.8, 0.6, - 2.0, 2.1, 2.2, 0.7, - 2.4, 2.5, 2.6, 0.8); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.2); - EXPECT_EQ(mTestMatrix(0, 1), 1.3); - EXPECT_EQ(mTestMatrix(0, 2), 1.4); - EXPECT_EQ(mTestMatrix(0, 3), 0.5); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 1.6); - EXPECT_EQ(mTestMatrix(1, 1), 1.7); - EXPECT_EQ(mTestMatrix(1, 2), 1.8); - EXPECT_EQ(mTestMatrix(1, 3), 0.6); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 2.0); - EXPECT_EQ(mTestMatrix(2, 1), 2.1); - EXPECT_EQ(mTestMatrix(2, 2), 2.2); - EXPECT_EQ(mTestMatrix(2, 3), 0.7); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 2.4); - EXPECT_EQ(mTestMatrix(3, 1), 2.5); - EXPECT_EQ(mTestMatrix(3, 2), 2.6); - EXPECT_EQ(mTestMatrix(3, 3), 0.8); - - // Set the double matrix - mTestMatrixD1.Set(1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); - EXPECT_EQ(mTestMatrixD1(0, 1), 2.0); - EXPECT_EQ(mTestMatrixD1(0, 2), 3.0); - EXPECT_EQ(mTestMatrixD1(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD1(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD1(1, 1), 6.0); - EXPECT_EQ(mTestMatrixD1(1, 2), 7.0); - EXPECT_EQ(mTestMatrixD1(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD1(2, 0), 9.0); - EXPECT_EQ(mTestMatrixD1(2, 1), 8.0); - EXPECT_EQ(mTestMatrixD1(2, 2), 7.0); - EXPECT_EQ(mTestMatrixD1(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD1(3, 1), 4.0); - EXPECT_EQ(mTestMatrixD1(3, 2), 3.0); - EXPECT_EQ(mTestMatrixD1(3, 3), 2.0); - - // Set the float matrix - mTestMatrixF1.Set(9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0, - 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF1(0, 0), 9.0); - EXPECT_EQ(mTestMatrixF1(0, 1), 8.0); - EXPECT_EQ(mTestMatrixF1(0, 2), 7.0); - EXPECT_EQ(mTestMatrixF1(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF1(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF1(1, 1), 4.0); - EXPECT_EQ(mTestMatrixF1(1, 2), 3.0); - EXPECT_EQ(mTestMatrixF1(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF1(2, 0), 1.0); - EXPECT_EQ(mTestMatrixF1(2, 1), 2.0); - EXPECT_EQ(mTestMatrixF1(2, 2), 3.0); - EXPECT_EQ(mTestMatrixF1(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF1(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF1(3, 1), 6.0); - EXPECT_EQ(mTestMatrixF1(3, 2), 7.0); - EXPECT_EQ(mTestMatrixF1(3, 3), 8.0); -} - -/** - * @fn TEST_F(MatrixTests, SetMatrixFromMatrix) - * - * @brief Test the setting of a Matrix from another Matrix - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, SetMatrixFromMatrix) -{ - // Set a float matrix - mTestMatrixF1.Set(9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0, - 1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0); - - // Set a double matrix - mTestMatrixD1.Set(1.0, 2.0, 3.0, 4.0, - 5.0, 6.0, 7.0, 8.0, - 9.0, 8.0, 7.0, 6.0, - 5.0, 4.0, 3.0, 2.0); - - // Set a float matrix from float matrix - mTestMatrixF2.Set(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF2(0, 0), 9.0); - EXPECT_EQ(mTestMatrixF2(0, 1), 8.0); - EXPECT_EQ(mTestMatrixF2(0, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(1, 1), 4.0); - EXPECT_EQ(mTestMatrixF2(1, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF2(2, 0), 1.0); - EXPECT_EQ(mTestMatrixF2(2, 1), 2.0); - EXPECT_EQ(mTestMatrixF2(2, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(3, 1), 6.0); - EXPECT_EQ(mTestMatrixF2(3, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(3, 3), 8.0); - - // Set a float matrix from double matrix - mTestMatrixF2.Set(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixF2(0, 0), 1.0); - EXPECT_EQ(mTestMatrixF2(0, 1), 2.0); - EXPECT_EQ(mTestMatrixF2(0, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(1, 1), 6.0); - EXPECT_EQ(mTestMatrixF2(1, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixF2(2, 0), 9.0); - EXPECT_EQ(mTestMatrixF2(2, 1), 8.0); - EXPECT_EQ(mTestMatrixF2(2, 2), 7.0); - EXPECT_EQ(mTestMatrixF2(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixF2(3, 1), 4.0); - EXPECT_EQ(mTestMatrixF2(3, 2), 3.0); - EXPECT_EQ(mTestMatrixF2(3, 3), 2.0); - - // Set a double matrix from float matrix - mTestMatrixD2.Set(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD2(0, 0), 9.0); - EXPECT_EQ(mTestMatrixD2(0, 1), 8.0); - EXPECT_EQ(mTestMatrixD2(0, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(1, 1), 4.0); - EXPECT_EQ(mTestMatrixD2(1, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD2(2, 0), 1.0); - EXPECT_EQ(mTestMatrixD2(2, 1), 2.0); - EXPECT_EQ(mTestMatrixD2(2, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(3, 1), 6.0); - EXPECT_EQ(mTestMatrixD2(3, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(3, 3), 8.0); - - // Set a double matrix from double matrix - mTestMatrixD2.Set(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD2.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD2(0, 0), 1.0); - EXPECT_EQ(mTestMatrixD2(0, 1), 2.0); - EXPECT_EQ(mTestMatrixD2(0, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(1, 1), 6.0); - EXPECT_EQ(mTestMatrixD2(1, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrixD2(2, 0), 9.0); - EXPECT_EQ(mTestMatrixD2(2, 1), 8.0); - EXPECT_EQ(mTestMatrixD2(2, 2), 7.0); - EXPECT_EQ(mTestMatrixD2(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); - EXPECT_EQ(mTestMatrixD2(3, 1), 4.0); - EXPECT_EQ(mTestMatrixD2(3, 2), 3.0); - EXPECT_EQ(mTestMatrixD2(3, 3), 2.0); - - // Set a matrix from float matrix - mTestMatrix.Set(mTestMatrixF1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 9.0); - EXPECT_EQ(mTestMatrix(0, 1), 8.0); - EXPECT_EQ(mTestMatrix(0, 2), 7.0); - EXPECT_EQ(mTestMatrix(0, 3), 6.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 5.0); - EXPECT_EQ(mTestMatrix(1, 1), 4.0); - EXPECT_EQ(mTestMatrix(1, 2), 3.0); - EXPECT_EQ(mTestMatrix(1, 3), 2.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 1.0); - EXPECT_EQ(mTestMatrix(2, 1), 2.0); - EXPECT_EQ(mTestMatrix(2, 2), 3.0); - EXPECT_EQ(mTestMatrix(2, 3), 4.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 5.0); - EXPECT_EQ(mTestMatrix(3, 1), 6.0); - EXPECT_EQ(mTestMatrix(3, 2), 7.0); - EXPECT_EQ(mTestMatrix(3, 3), 8.0); - - // Set a matrix from double matrix - mTestMatrix.Set(mTestMatrixD1); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 1.0); - EXPECT_EQ(mTestMatrix(0, 1), 2.0); - EXPECT_EQ(mTestMatrix(0, 2), 3.0); - EXPECT_EQ(mTestMatrix(0, 3), 4.0); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 5.0); - EXPECT_EQ(mTestMatrix(1, 1), 6.0); - EXPECT_EQ(mTestMatrix(1, 2), 7.0); - EXPECT_EQ(mTestMatrix(1, 3), 8.0); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 9.0); - EXPECT_EQ(mTestMatrix(2, 1), 8.0); - EXPECT_EQ(mTestMatrix(2, 2), 7.0); - EXPECT_EQ(mTestMatrix(2, 3), 6.0); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 5.0); - EXPECT_EQ(mTestMatrix(3, 1), 4.0); - EXPECT_EQ(mTestMatrix(3, 2), 3.0); - EXPECT_EQ(mTestMatrix(3, 3), 2.0); -} - -/** - * @fn TEST_F(MatrixTests, SetMatrixFromArray) - * - * @brief Test the setting of a Matrix from an array - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, SetMatrixFromArray) -{ - // Create a new matrix - mTestMatrixF1.Set(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixF1(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixF1(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixF1(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixF1(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrixF1.Set(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixF1(0, 0), 2.1, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 2), 5.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(0, 3), 4.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixF1(1, 0), 7.8, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 2), 8.9, 1e-6); - EXPECT_NEAR(mTestMatrixF1(1, 3), 0.5, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixF1(2, 0), 5.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 1), 6.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 2), 7.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(2, 3), 2.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixF1(3, 0), 4.5, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 1), 3.3, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 2), 2.6, 1e-6); - EXPECT_NEAR(mTestMatrixF1(3, 3), 8.3, 1e-6); - - // Create a new matrix - mTestMatrixD1.Set(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrixD1(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrixD1(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrixD1(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrixD1(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrixD1(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrixD1(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrixD1(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrixD1(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrixD1.Set(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrixD1(0, 0), 2.1); - EXPECT_EQ(mTestMatrixD1(0, 1), 4.3); - EXPECT_EQ(mTestMatrixD1(0, 2), 5.6); - EXPECT_EQ(mTestMatrixD1(0, 3), 4.5); - - // Test the second row values - EXPECT_EQ(mTestMatrixD1(1, 0), 7.8); - EXPECT_EQ(mTestMatrixD1(1, 1), 8.7); - EXPECT_EQ(mTestMatrixD1(1, 2), 8.9); - EXPECT_EQ(mTestMatrixD1(1, 3), 0.5); - - // Test the third row values - EXPECT_EQ(mTestMatrixD1(2, 0), 5.6); - EXPECT_EQ(mTestMatrixD1(2, 1), 6.6); - EXPECT_EQ(mTestMatrixD1(2, 2), 7.3); - EXPECT_EQ(mTestMatrixD1(2, 3), 2.5); - - // Test the fourth row values - EXPECT_EQ(mTestMatrixD1(3, 0), 4.5); - EXPECT_EQ(mTestMatrixD1(3, 1), 3.3); - EXPECT_EQ(mTestMatrixD1(3, 2), 2.6); - EXPECT_EQ(mTestMatrixD1(3, 3), 8.3); - - // Create a new matrix - mTestMatrix.Set(mArrayF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_NEAR(mTestMatrix(0, 0), 3.2, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 1), 4.3, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 2), 5.4, 1e-6); - EXPECT_NEAR(mTestMatrix(0, 3), 6.5, 1e-6); - - // Test the second row values - EXPECT_NEAR(mTestMatrix(1, 0), 7.6, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 1), 8.7, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 2), 9.8, 1e-6); - EXPECT_NEAR(mTestMatrix(1, 3), 0.9, 1e-6); - - // Test the third row values - EXPECT_NEAR(mTestMatrix(2, 0), 0.8, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 1), 0.7, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 2), 0.6, 1e-6); - EXPECT_NEAR(mTestMatrix(2, 3), 0.5, 1e-6); - - // Test the fourth row values - EXPECT_NEAR(mTestMatrix(3, 0), 0.4, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 1), 0.3, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 2), 0.2, 1e-6); - EXPECT_NEAR(mTestMatrix(3, 3), 0.1, 1e-6); - - // Create a new matrix - mTestMatrix.Set(mArrayD); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrix.Valid(), true); - - // Test the first row values - EXPECT_EQ(mTestMatrix(0, 0), 2.1); - EXPECT_EQ(mTestMatrix(0, 1), 4.3); - EXPECT_EQ(mTestMatrix(0, 2), 5.6); - EXPECT_EQ(mTestMatrix(0, 3), 4.5); - - // Test the second row values - EXPECT_EQ(mTestMatrix(1, 0), 7.8); - EXPECT_EQ(mTestMatrix(1, 1), 8.7); - EXPECT_EQ(mTestMatrix(1, 2), 8.9); - EXPECT_EQ(mTestMatrix(1, 3), 0.5); - - // Test the third row values - EXPECT_EQ(mTestMatrix(2, 0), 5.6); - EXPECT_EQ(mTestMatrix(2, 1), 6.6); - EXPECT_EQ(mTestMatrix(2, 2), 7.3); - EXPECT_EQ(mTestMatrix(2, 3), 2.5); - - // Test the fourth row values - EXPECT_EQ(mTestMatrix(3, 0), 4.5); - EXPECT_EQ(mTestMatrix(3, 1), 3.3); - EXPECT_EQ(mTestMatrix(3, 2), 2.6); - EXPECT_EQ(mTestMatrix(3, 3), 8.3); -} - -/** - * @fn TEST_F(MatrixTests, GetPointer) - * - * @brief Test the method for returning a Matrix pointer - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(MatrixTests, GetPointer) -{ - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixF1.Valid(), true); - - // Test if the pointer is NULL - EXPECT_EQ(nullptr, mMatPtrF); - - // Get the float pointer holding the float matrix - mMatPtrF = mTestMatrixF1.Ptr(); - - // Test if the pointer is NULL - EXPECT_NE(nullptr, mMatPtrF); - - // Test if the matrix is valid - EXPECT_EQ(mTestMatrixD1.Valid(), true); - - // Test if the pointer is NULL - EXPECT_EQ(nullptr, mMatPtrD); - - // Get the double pointer holding the double matrix - mMatPtrD = mTestMatrixD1.Ptr(); - - // Test if the pointer is NULL - EXPECT_NE(nullptr, mMatPtrD); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "MatrixTests.h" + +#include + +////////////////////////////////////////////////////////////////////////// +MatrixTests::MatrixTests() +{ +} + +////////////////////////////////////////////////////////////////////////// +MatrixTests::~MatrixTests() +{ +} + +/** + * @fn TEST_F(MatrixTests, Matrix) + * + * @brief Test of Matrix class definition, between Matrixf and Matrixd + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, Matrix) +{ +#ifdef TR_USE_DOUBLE_MATRIX + EXPECT_EQ(typeid(trBase::Matrix), typeid(trBase::Matrixd)); + EXPECT_NE(typeid(trBase::Matrix), typeid(trBase::Matrixf)); +#else + EXPECT_EQ(typeid(trBase::Matrix), typeid(trBase::Matrixf)); + EXPECT_NE(typeid(trBase::Matrix), typeid(trBase::Matrixd)); +#endif +} + +/** + * @fn TEST_F(MatrixTests, CreateMatrix) + * + * @brief Test the creation of a default Matrix. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CreateMatrix) +{ + // Create a new matrix using the default constructor + mTestMatrix = trBase::Matrix(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.0); + EXPECT_EQ(mTestMatrix(0, 1), 0.0); + EXPECT_EQ(mTestMatrix(0, 2), 0.0); + EXPECT_EQ(mTestMatrix(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 0.0); + EXPECT_EQ(mTestMatrix(1, 1), 1.0); + EXPECT_EQ(mTestMatrix(1, 2), 0.0); + EXPECT_EQ(mTestMatrix(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 0.0); + EXPECT_EQ(mTestMatrix(2, 1), 0.0); + EXPECT_EQ(mTestMatrix(2, 2), 1.0); + EXPECT_EQ(mTestMatrix(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0.0); + EXPECT_EQ(mTestMatrix(3, 1), 0.0); + EXPECT_EQ(mTestMatrix(3, 2), 0.0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + // Create a new matrix using the default constructor + mTestMatrixF1 = trBase::Matrixf(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF1(0, 0), 1.0); + EXPECT_EQ(mTestMatrixF1(0, 1), 0.0); + EXPECT_EQ(mTestMatrixF1(0, 2), 0.0); + EXPECT_EQ(mTestMatrixF1(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF1(1, 0), 0.0); + EXPECT_EQ(mTestMatrixF1(1, 1), 1.0); + EXPECT_EQ(mTestMatrixF1(1, 2), 0.0); + EXPECT_EQ(mTestMatrixF1(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF1(2, 0), 0.0); + EXPECT_EQ(mTestMatrixF1(2, 1), 0.0); + EXPECT_EQ(mTestMatrixF1(2, 2), 1.0); + EXPECT_EQ(mTestMatrixF1(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF1(3, 0), 0.0); + EXPECT_EQ(mTestMatrixF1(3, 1), 0.0); + EXPECT_EQ(mTestMatrixF1(3, 2), 0.0); + EXPECT_EQ(mTestMatrixF1(3, 3), 1.0); + + // Create a new matrix using the default constructor + mTestMatrixD1 = trBase::Matrixd(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); + EXPECT_EQ(mTestMatrixD1(0, 1), 0.0); + EXPECT_EQ(mTestMatrixD1(0, 2), 0.0); + EXPECT_EQ(mTestMatrixD1(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD1(1, 0), 0.0); + EXPECT_EQ(mTestMatrixD1(1, 1), 1.0); + EXPECT_EQ(mTestMatrixD1(1, 2), 0.0); + EXPECT_EQ(mTestMatrixD1(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD1(2, 0), 0.0); + EXPECT_EQ(mTestMatrixD1(2, 1), 0.0); + EXPECT_EQ(mTestMatrixD1(2, 2), 1.0); + EXPECT_EQ(mTestMatrixD1(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 0.0); + EXPECT_EQ(mTestMatrixD1(3, 1), 0.0); + EXPECT_EQ(mTestMatrixD1(3, 2), 0.0); + EXPECT_EQ(mTestMatrixD1(3, 3), 1.0); +} + +/** + * @fn TEST_F(MatrixTests, CreateMatrixFromNum) + * + * @brief Test the creation of a Matrix from raw input + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CreateMatrixFromNum) +{ + // Create a matrix + mTestMatrix = trBase::Matrix( 1.2, 1.3, 1.4, 0.5, + 1.6, 1.7, 1.8, 0.6, + 2.0, 2.1, 2.2, 0.7, + 2.4, 2.5, 2.6, 0.8); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.2); + EXPECT_EQ(mTestMatrix(0, 1), 1.3); + EXPECT_EQ(mTestMatrix(0, 2), 1.4); + EXPECT_EQ(mTestMatrix(0, 3), 0.5); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 1.6); + EXPECT_EQ(mTestMatrix(1, 1), 1.7); + EXPECT_EQ(mTestMatrix(1, 2), 1.8); + EXPECT_EQ(mTestMatrix(1, 3), 0.6); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 2.0); + EXPECT_EQ(mTestMatrix(2, 1), 2.1); + EXPECT_EQ(mTestMatrix(2, 2), 2.2); + EXPECT_EQ(mTestMatrix(2, 3), 0.7); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 2.4); + EXPECT_EQ(mTestMatrix(3, 1), 2.5); + EXPECT_EQ(mTestMatrix(3, 2), 2.6); + EXPECT_EQ(mTestMatrix(3, 3), 0.8); + + // Create a double matrix + mTestMatrixD1 = trBase::Matrixd(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, + 9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); + EXPECT_EQ(mTestMatrixD1(0, 1), 2.0); + EXPECT_EQ(mTestMatrixD1(0, 2), 3.0); + EXPECT_EQ(mTestMatrixD1(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD1(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD1(1, 1), 6.0); + EXPECT_EQ(mTestMatrixD1(1, 2), 7.0); + EXPECT_EQ(mTestMatrixD1(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD1(2, 0), 9.0); + EXPECT_EQ(mTestMatrixD1(2, 1), 8.0); + EXPECT_EQ(mTestMatrixD1(2, 2), 7.0); + EXPECT_EQ(mTestMatrixD1(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD1(3, 1), 4.0); + EXPECT_EQ(mTestMatrixD1(3, 2), 3.0); + EXPECT_EQ(mTestMatrixD1(3, 3), 2.0); + + // Create a float matrix + mTestMatrixF1 = trBase::Matrixf(9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0, + 1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF1(0, 0), 9.0); + EXPECT_EQ(mTestMatrixF1(0, 1), 8.0); + EXPECT_EQ(mTestMatrixF1(0, 2), 7.0); + EXPECT_EQ(mTestMatrixF1(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF1(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF1(1, 1), 4.0); + EXPECT_EQ(mTestMatrixF1(1, 2), 3.0); + EXPECT_EQ(mTestMatrixF1(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF1(2, 0), 1.0); + EXPECT_EQ(mTestMatrixF1(2, 1), 2.0); + EXPECT_EQ(mTestMatrixF1(2, 2), 3.0); + EXPECT_EQ(mTestMatrixF1(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF1(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF1(3, 1), 6.0); + EXPECT_EQ(mTestMatrixF1(3, 2), 7.0); + EXPECT_EQ(mTestMatrixF1(3, 3), 8.0); +} + +/** + * @fn TEST_F(MatrixTests, CreateMatrixFromMatrix) + * + * @brief Test the creation of a Matrix from another Matrix + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CreateMatrixFromMatrix) +{ + // Create a float matrix + mTestMatrixF1 = trBase::Matrixf(9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0, + 1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0); + + // Create a double matrix + mTestMatrixD1 = trBase::Matrixd(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, + 9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0); + + // Create a float matrix from float matrix + mTestMatrixF2 = trBase::Matrixf(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF2(0, 0), 9.0); + EXPECT_EQ(mTestMatrixF2(0, 1), 8.0); + EXPECT_EQ(mTestMatrixF2(0, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(1, 1), 4.0); + EXPECT_EQ(mTestMatrixF2(1, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF2(2, 0), 1.0); + EXPECT_EQ(mTestMatrixF2(2, 1), 2.0); + EXPECT_EQ(mTestMatrixF2(2, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(3, 1), 6.0); + EXPECT_EQ(mTestMatrixF2(3, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(3, 3), 8.0); + + // Create a float matrix from double matrix + mTestMatrixF2 = trBase::Matrixf(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF2(0, 0), 1.0); + EXPECT_EQ(mTestMatrixF2(0, 1), 2.0); + EXPECT_EQ(mTestMatrixF2(0, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(1, 1), 6.0); + EXPECT_EQ(mTestMatrixF2(1, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF2(2, 0), 9.0); + EXPECT_EQ(mTestMatrixF2(2, 1), 8.0); + EXPECT_EQ(mTestMatrixF2(2, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(3, 1), 4.0); + EXPECT_EQ(mTestMatrixF2(3, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(3, 3), 2.0); + + // Create a double matrix from float matrix + mTestMatrixD2 = trBase::Matrixd(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD2(0, 0), 9.0); + EXPECT_EQ(mTestMatrixD2(0, 1), 8.0); + EXPECT_EQ(mTestMatrixD2(0, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(1, 1), 4.0); + EXPECT_EQ(mTestMatrixD2(1, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD2(2, 0), 1.0); + EXPECT_EQ(mTestMatrixD2(2, 1), 2.0); + EXPECT_EQ(mTestMatrixD2(2, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(3, 1), 6.0); + EXPECT_EQ(mTestMatrixD2(3, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(3, 3), 8.0); + + // Create a double matrix from double matrix + mTestMatrixD2 = trBase::Matrixd(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD2(0, 0), 1.0); + EXPECT_EQ(mTestMatrixD2(0, 1), 2.0); + EXPECT_EQ(mTestMatrixD2(0, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(1, 1), 6.0); + EXPECT_EQ(mTestMatrixD2(1, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD2(2, 0), 9.0); + EXPECT_EQ(mTestMatrixD2(2, 1), 8.0); + EXPECT_EQ(mTestMatrixD2(2, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(3, 1), 4.0); + EXPECT_EQ(mTestMatrixD2(3, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(3, 3), 2.0); + + // Create a matrix from float matrix + mTestMatrix = trBase::Matrix(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 9.0); + EXPECT_EQ(mTestMatrix(0, 1), 8.0); + EXPECT_EQ(mTestMatrix(0, 2), 7.0); + EXPECT_EQ(mTestMatrix(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 5.0); + EXPECT_EQ(mTestMatrix(1, 1), 4.0); + EXPECT_EQ(mTestMatrix(1, 2), 3.0); + EXPECT_EQ(mTestMatrix(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 1.0); + EXPECT_EQ(mTestMatrix(2, 1), 2.0); + EXPECT_EQ(mTestMatrix(2, 2), 3.0); + EXPECT_EQ(mTestMatrix(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 5.0); + EXPECT_EQ(mTestMatrix(3, 1), 6.0); + EXPECT_EQ(mTestMatrix(3, 2), 7.0); + EXPECT_EQ(mTestMatrix(3, 3), 8.0); + + // Create a matrix from double matrix + mTestMatrix = trBase::Matrix(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.0); + EXPECT_EQ(mTestMatrix(0, 1), 2.0); + EXPECT_EQ(mTestMatrix(0, 2), 3.0); + EXPECT_EQ(mTestMatrix(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 5.0); + EXPECT_EQ(mTestMatrix(1, 1), 6.0); + EXPECT_EQ(mTestMatrix(1, 2), 7.0); + EXPECT_EQ(mTestMatrix(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 9.0); + EXPECT_EQ(mTestMatrix(2, 1), 8.0); + EXPECT_EQ(mTestMatrix(2, 2), 7.0); + EXPECT_EQ(mTestMatrix(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 5.0); + EXPECT_EQ(mTestMatrix(3, 1), 4.0); + EXPECT_EQ(mTestMatrix(3, 2), 3.0); + EXPECT_EQ(mTestMatrix(3, 3), 2.0); +} + +/** + * @fn TEST_F(MatrixTests, CreateMatrixFromArray) + * + * @brief Test the creation of a Matrix from an array + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CreateMatrixFromArray) +{ + // Create a new matrix + mTestMatrixF1 = trBase::Matrixf(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixF1(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixF1(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixF1(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixF1(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrixF1 = trBase::Matrixf(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixF1(0, 0), 2.1, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 2), 5.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 3), 4.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixF1(1, 0), 7.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 2), 8.9, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 3), 0.5, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixF1(2, 0), 5.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 1), 6.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 2), 7.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 3), 2.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixF1(3, 0), 4.5, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 1), 3.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 2), 2.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 3), 8.3, 1e-6); + + // Create a new matrix + mTestMatrixD1 = trBase::Matrixd(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixD1(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixD1(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixD1(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixD1(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrixD1 = trBase::Matrixd(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD1(0, 0), 2.1); + EXPECT_EQ(mTestMatrixD1(0, 1), 4.3); + EXPECT_EQ(mTestMatrixD1(0, 2), 5.6); + EXPECT_EQ(mTestMatrixD1(0, 3), 4.5); + + // Test the second row values + EXPECT_EQ(mTestMatrixD1(1, 0), 7.8); + EXPECT_EQ(mTestMatrixD1(1, 1), 8.7); + EXPECT_EQ(mTestMatrixD1(1, 2), 8.9); + EXPECT_EQ(mTestMatrixD1(1, 3), 0.5); + + // Test the third row values + EXPECT_EQ(mTestMatrixD1(2, 0), 5.6); + EXPECT_EQ(mTestMatrixD1(2, 1), 6.6); + EXPECT_EQ(mTestMatrixD1(2, 2), 7.3); + EXPECT_EQ(mTestMatrixD1(2, 3), 2.5); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 4.5); + EXPECT_EQ(mTestMatrixD1(3, 1), 3.3); + EXPECT_EQ(mTestMatrixD1(3, 2), 2.6); + EXPECT_EQ(mTestMatrixD1(3, 3), 8.3); + + // Create a new matrix + mTestMatrix = trBase::Matrix(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrix(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrix(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrix(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrix(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrix = trBase::Matrix(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 2.1); + EXPECT_EQ(mTestMatrix(0, 1), 4.3); + EXPECT_EQ(mTestMatrix(0, 2), 5.6); + EXPECT_EQ(mTestMatrix(0, 3), 4.5); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 7.8); + EXPECT_EQ(mTestMatrix(1, 1), 8.7); + EXPECT_EQ(mTestMatrix(1, 2), 8.9); + EXPECT_EQ(mTestMatrix(1, 3), 0.5); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 5.6); + EXPECT_EQ(mTestMatrix(2, 1), 6.6); + EXPECT_EQ(mTestMatrix(2, 2), 7.3); + EXPECT_EQ(mTestMatrix(2, 3), 2.5); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 4.5); + EXPECT_EQ(mTestMatrix(3, 1), 3.3); + EXPECT_EQ(mTestMatrix(3, 2), 2.6); + EXPECT_EQ(mTestMatrix(3, 3), 8.3); +} + +/** + * @fn TEST_F(MatrixTests, CreateMatrixFromQuat) + * + * @brief Test the creation of a Matrix from a quaternion. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CreateMatrixFromQuat) +{ + /* + q = (x, y, z, w) ---> + M = + (w*w + x*x - y*y - z*z) (2*x*y - 2*w*z) (2*x*z + 2*w*y) 0 + (2*x*y + 2*w*z) (w*w - x*x + y*y - z*z) (2*y*z - 2*w*x) 0 + (2*x*z - 2*w*y) (2*y*z + 2*w*x) (w*w - x*x - y*y + z*z) 0 + 0 0 0 1 + + L = length(q)^2 + True Reality & Open Scene Graph use normalized matrices for the conversion, therefore + all values in the matrix above (except M(4,4)) needs to be divided by L + https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation + http://www.mrelusive.com/publications/papers/SIMD-From-Quaternion-to-Matrix-and-Back.pdf + */ + + // Create a test quaternion + mTestQuat.Set(1.0, 0.0, 0.0, 0.0); + + // Create a matrix + mTestMatrix = trBase::Matrix(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.0); + EXPECT_EQ(mTestMatrix(0, 1), 0.0); + EXPECT_EQ(mTestMatrix(0, 2), 0.0); + EXPECT_EQ(mTestMatrix(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 0.0); + EXPECT_EQ(mTestMatrix(1, 1), -1.0); + EXPECT_EQ(mTestMatrix(1, 2), 0.0); + EXPECT_EQ(mTestMatrix(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 0.0); + EXPECT_EQ(mTestMatrix(2, 1), 0.0); + EXPECT_EQ(mTestMatrix(2, 2), -1.0); + EXPECT_EQ(mTestMatrix(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0.0); + EXPECT_EQ(mTestMatrix(3, 1), 0.0); + EXPECT_EQ(mTestMatrix(3, 2), 0.0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + // Create a test quaternion + mTestQuat.Set(0.0, 1.0, 0.0, 0.0); + + // Create a matrix + mTestMatrix = trBase::Matrix(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), -1.0); + EXPECT_EQ(mTestMatrix(0, 1), 0.0); + EXPECT_EQ(mTestMatrix(0, 2), 0.0); + EXPECT_EQ(mTestMatrix(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 0.0); + EXPECT_EQ(mTestMatrix(1, 1), 1.0); + EXPECT_EQ(mTestMatrix(1, 2), 0.0); + EXPECT_EQ(mTestMatrix(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 0.0); + EXPECT_EQ(mTestMatrix(2, 1), 0.0); + EXPECT_EQ(mTestMatrix(2, 2), -1.0); + EXPECT_EQ(mTestMatrix(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0.0); + EXPECT_EQ(mTestMatrix(3, 1), 0.0); + EXPECT_EQ(mTestMatrix(3, 2), 0.0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + // Create a test quaternion + mTestQuat.Set(0.0, 0.0, 1.0, 0.0); + + // Create a matrix + mTestMatrix = trBase::Matrix(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), -1.0); + EXPECT_EQ(mTestMatrix(0, 1), 0.0); + EXPECT_EQ(mTestMatrix(0, 2), 0.0); + EXPECT_EQ(mTestMatrix(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 0.0); + EXPECT_EQ(mTestMatrix(1, 1), -1.0); + EXPECT_EQ(mTestMatrix(1, 2), 0.0); + EXPECT_EQ(mTestMatrix(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 0.0); + EXPECT_EQ(mTestMatrix(2, 1), 0.0); + EXPECT_EQ(mTestMatrix(2, 2), 1.0); + EXPECT_EQ(mTestMatrix(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0.0); + EXPECT_EQ(mTestMatrix(3, 1), 0.0); + EXPECT_EQ(mTestMatrix(3, 2), 0.0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + + // Create a test quaternion + mTestQuat.Set(0.0, 0.0, 0.0, 1.0); + + // Create a matrix + mTestMatrix = trBase::Matrix(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.0); + EXPECT_EQ(mTestMatrix(0, 1), 0.0); + EXPECT_EQ(mTestMatrix(0, 2), 0.0); + EXPECT_EQ(mTestMatrix(0, 3), 0.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 0.0); + EXPECT_EQ(mTestMatrix(1, 1), 1.0); + EXPECT_EQ(mTestMatrix(1, 2), 0.0); + EXPECT_EQ(mTestMatrix(1, 3), 0.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 0.0); + EXPECT_EQ(mTestMatrix(2, 1), 0.0); + EXPECT_EQ(mTestMatrix(2, 2), 1.0); + EXPECT_EQ(mTestMatrix(2, 3), 0.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0.0); + EXPECT_EQ(mTestMatrix(3, 1), 0.0); + EXPECT_EQ(mTestMatrix(3, 2), 0.0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + + // Create a test quaternion + mTestQuat.Set(2.3, 3.4, 5.6, 7.8); + + // Create a matrix + mTestMatrix = trBase::Matrix(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrix(0, 0), 0.212838148, 1e-8); + EXPECT_NEAR(mTestMatrix(0, 1), 0.944520862, 1e-8); + EXPECT_NEAR(mTestMatrix(0, 2), -0.250160477, 1e-8); + EXPECT_EQ(mTestMatrix(0, 3), 0); + + // Test the second row values + EXPECT_NEAR(mTestMatrix(1, 0), -0.657679963, 1e-8); + EXPECT_NEAR(mTestMatrix(1, 1), 0.32783127, 1e-8); + EXPECT_NEAR(mTestMatrix(1, 2), 0.678221, 1e-8); + EXPECT_EQ(mTestMatrix(1, 3), 0); + + // Test the third row values + EXPECT_NEAR(mTestMatrix(2, 0), 0.72260431, 1e-8); + EXPECT_NEAR(mTestMatrix(2, 1), 0.020174232, 1e-8); + EXPECT_NEAR(mTestMatrix(2, 2), 0.690967446, 1e-8); + EXPECT_EQ(mTestMatrix(2, 3), 0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 0); + EXPECT_EQ(mTestMatrix(3, 1), 0); + EXPECT_EQ(mTestMatrix(3, 2), 0); + EXPECT_EQ(mTestMatrix(3, 3), 1.0); + + // Create a matrix + mTestMatrixF1 = trBase::Matrixf(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixF1(0, 0), 0.212838148, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 1), 0.944520862, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 2), -0.250160477, 1e-6); + EXPECT_EQ(mTestMatrixF1(0, 3), 0); + + // Test the second row values + EXPECT_NEAR(mTestMatrixF1(1, 0), -0.657679963, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 1), 0.32783127, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 2), 0.678221, 1e-6); + EXPECT_EQ(mTestMatrixF1(1, 3), 0); + + // Test the third row values + EXPECT_NEAR(mTestMatrixF1(2, 0), 0.72260431, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 1), 0.020174232, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 2), 0.690967446, 1e-6); + EXPECT_EQ(mTestMatrixF1(2, 3), 0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF1(3, 0), 0); + EXPECT_EQ(mTestMatrixF1(3, 1), 0); + EXPECT_EQ(mTestMatrixF1(3, 2), 0); + EXPECT_EQ(mTestMatrixF1(3, 3), 1.0); + + // Create a matrix + mTestMatrixD1 = trBase::Matrixd(mTestQuat); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixD1(0, 0), 0.212838148, 1e-8); + EXPECT_NEAR(mTestMatrixD1(0, 1), 0.944520862, 1e-8); + EXPECT_NEAR(mTestMatrixD1(0, 2), -0.250160477, 1e-8); + EXPECT_EQ(mTestMatrixD1(0, 3), 0); + + // Test the second row values + EXPECT_NEAR(mTestMatrixD1(1, 0), -0.657679963, 1e-8); + EXPECT_NEAR(mTestMatrixD1(1, 1), 0.32783127, 1e-8); + EXPECT_NEAR(mTestMatrixD1(1, 2), 0.678221, 1e-8); + EXPECT_EQ(mTestMatrixD1(1, 3), 0); + + // Test the third row values + EXPECT_NEAR(mTestMatrixD1(2, 0), 0.72260431, 1e-8); + EXPECT_NEAR(mTestMatrixD1(2, 1), 0.020174232, 1e-8); + EXPECT_NEAR(mTestMatrixD1(2, 2), 0.690967446, 1e-8); + EXPECT_EQ(mTestMatrixD1(2, 3), 0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 0); + EXPECT_EQ(mTestMatrixD1(3, 1), 0); + EXPECT_EQ(mTestMatrixD1(3, 2), 0); + EXPECT_EQ(mTestMatrixD1(3, 3), 1.0); +} + +/** + * @fn TEST_F(MatrixTests, GetOSGMatrix) + * + * @brief Test the method for returning an OSG matrix + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, GetOSGMatrix) +{ + // Create a new matrix + mTestMatrixF1 = trBase::Matrixf(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Get the OSG matrix + mTestMatOsgF = mTestMatrixF1.GetOSGMatrix(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatOsgF.valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatOsgF(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatOsgF(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatOsgF(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatOsgF(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatOsgF(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatOsgF(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatOsgF(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatOsgF(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatOsgF(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatOsgF(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatOsgF(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatOsgF(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatOsgF(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatOsgF(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatOsgF(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatOsgF(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrixD1 = trBase::Matrixd(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Get the OSG matrix + mTestMatOsgD = mTestMatrixD1.GetOSGMatrix(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatOsgD.valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatOsgD(0, 0), 2.1); + EXPECT_EQ(mTestMatOsgD(0, 1), 4.3); + EXPECT_EQ(mTestMatOsgD(0, 2), 5.6); + EXPECT_EQ(mTestMatOsgD(0, 3), 4.5); + + // Test the second row values + EXPECT_EQ(mTestMatOsgD(1, 0), 7.8); + EXPECT_EQ(mTestMatOsgD(1, 1), 8.7); + EXPECT_EQ(mTestMatOsgD(1, 2), 8.9); + EXPECT_EQ(mTestMatOsgD(1, 3), 0.5); + + // Test the third row values + EXPECT_EQ(mTestMatOsgD(2, 0), 5.6); + EXPECT_EQ(mTestMatOsgD(2, 1), 6.6); + EXPECT_EQ(mTestMatOsgD(2, 2), 7.3); + EXPECT_EQ(mTestMatOsgD(2, 3), 2.5); + + // Test the fourth row values + EXPECT_EQ(mTestMatOsgD(3, 0), 4.5); + EXPECT_EQ(mTestMatOsgD(3, 1), 3.3); + EXPECT_EQ(mTestMatOsgD(3, 2), 2.6); + EXPECT_EQ(mTestMatOsgD(3, 3), 8.3); + + // Create a new matrix + mTestMatrix = trBase::Matrix(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Get the OSG matrix + mTestMatOsg = mTestMatrix.GetOSGMatrix(); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatOsg.valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatOsg(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatOsg(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatOsg(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatOsg(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatOsg(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatOsg(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatOsg(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatOsg(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatOsg(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatOsg(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatOsg(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatOsg(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatOsg(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatOsg(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatOsg(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatOsg(3, 3), 0.1, 1e-6); +} + +/** + * @fn TEST_F(MatrixTests, CompareMatrix) + * + * @brief Test the method for comparing two matrices + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, CompareMatrix) +{ + // Test if the matrices are valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + EXPECT_EQ(mTestMatrixF2.Valid(), true); + + // Compare the matrices + EXPECT_EQ(mTestMatrixF1.Compare(mTestMatrixF2), 0); + + // Create a new matrix + mTestMatrixF1 = trBase::Matrixf(mArrayF); + + // Compare the matrices + EXPECT_EQ(mTestMatrixF1.Compare(mTestMatrixF2), 1); + EXPECT_EQ(mTestMatrixF2.Compare(mTestMatrixF1), -1); + + // Test if the matrices are valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + EXPECT_EQ(mTestMatrixD2.Valid(), true); + + // Compare the matrices + EXPECT_EQ(mTestMatrixD1.Compare(mTestMatrixD2), 0); + + // Create a new matrix + mTestMatrixD1 = trBase::Matrixd(mArrayD); + + // Compare the matrices + EXPECT_EQ(mTestMatrixD1.Compare(mTestMatrixD2), 1); + EXPECT_EQ(mTestMatrixD2.Compare(mTestMatrixD1), -1); + + // Test if the matrices are valid + EXPECT_EQ(mTestMatrix.Valid(), true); + EXPECT_EQ(mTestMatrix2.Valid(), true); + + // Compare the matrices + EXPECT_EQ(mTestMatrix.Compare(mTestMatrix2), 0); + + // Create a new matrix + mTestMatrix2 = trBase::Matrix(mArrayD); + + // Compare the matrices + EXPECT_EQ(mTestMatrix.Compare(mTestMatrix2), -1); + EXPECT_EQ(mTestMatrix2.Compare(mTestMatrix), 1); +} + +/** + * @fn TEST_F(MatrixTests, SetMatrixFromNum) + * + * @brief Test the setting of a Matrix from raw input + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, SetMatrixFromNum) +{ + // Set the matrix from input + mTestMatrix.Set(1.2, 1.3, 1.4, 0.5, + 1.6, 1.7, 1.8, 0.6, + 2.0, 2.1, 2.2, 0.7, + 2.4, 2.5, 2.6, 0.8); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.2); + EXPECT_EQ(mTestMatrix(0, 1), 1.3); + EXPECT_EQ(mTestMatrix(0, 2), 1.4); + EXPECT_EQ(mTestMatrix(0, 3), 0.5); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 1.6); + EXPECT_EQ(mTestMatrix(1, 1), 1.7); + EXPECT_EQ(mTestMatrix(1, 2), 1.8); + EXPECT_EQ(mTestMatrix(1, 3), 0.6); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 2.0); + EXPECT_EQ(mTestMatrix(2, 1), 2.1); + EXPECT_EQ(mTestMatrix(2, 2), 2.2); + EXPECT_EQ(mTestMatrix(2, 3), 0.7); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 2.4); + EXPECT_EQ(mTestMatrix(3, 1), 2.5); + EXPECT_EQ(mTestMatrix(3, 2), 2.6); + EXPECT_EQ(mTestMatrix(3, 3), 0.8); + + // Set the double matrix + mTestMatrixD1.Set(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, + 9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD1(0, 0), 1.0); + EXPECT_EQ(mTestMatrixD1(0, 1), 2.0); + EXPECT_EQ(mTestMatrixD1(0, 2), 3.0); + EXPECT_EQ(mTestMatrixD1(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD1(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD1(1, 1), 6.0); + EXPECT_EQ(mTestMatrixD1(1, 2), 7.0); + EXPECT_EQ(mTestMatrixD1(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD1(2, 0), 9.0); + EXPECT_EQ(mTestMatrixD1(2, 1), 8.0); + EXPECT_EQ(mTestMatrixD1(2, 2), 7.0); + EXPECT_EQ(mTestMatrixD1(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD1(3, 1), 4.0); + EXPECT_EQ(mTestMatrixD1(3, 2), 3.0); + EXPECT_EQ(mTestMatrixD1(3, 3), 2.0); + + // Set the float matrix + mTestMatrixF1.Set(9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0, + 1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF1(0, 0), 9.0); + EXPECT_EQ(mTestMatrixF1(0, 1), 8.0); + EXPECT_EQ(mTestMatrixF1(0, 2), 7.0); + EXPECT_EQ(mTestMatrixF1(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF1(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF1(1, 1), 4.0); + EXPECT_EQ(mTestMatrixF1(1, 2), 3.0); + EXPECT_EQ(mTestMatrixF1(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF1(2, 0), 1.0); + EXPECT_EQ(mTestMatrixF1(2, 1), 2.0); + EXPECT_EQ(mTestMatrixF1(2, 2), 3.0); + EXPECT_EQ(mTestMatrixF1(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF1(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF1(3, 1), 6.0); + EXPECT_EQ(mTestMatrixF1(3, 2), 7.0); + EXPECT_EQ(mTestMatrixF1(3, 3), 8.0); +} + +/** + * @fn TEST_F(MatrixTests, SetMatrixFromMatrix) + * + * @brief Test the setting of a Matrix from another Matrix + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, SetMatrixFromMatrix) +{ + // Set a float matrix + mTestMatrixF1.Set(9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0, + 1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0); + + // Set a double matrix + mTestMatrixD1.Set(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, + 9.0, 8.0, 7.0, 6.0, + 5.0, 4.0, 3.0, 2.0); + + // Set a float matrix from float matrix + mTestMatrixF2.Set(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF2(0, 0), 9.0); + EXPECT_EQ(mTestMatrixF2(0, 1), 8.0); + EXPECT_EQ(mTestMatrixF2(0, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(1, 1), 4.0); + EXPECT_EQ(mTestMatrixF2(1, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF2(2, 0), 1.0); + EXPECT_EQ(mTestMatrixF2(2, 1), 2.0); + EXPECT_EQ(mTestMatrixF2(2, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(3, 1), 6.0); + EXPECT_EQ(mTestMatrixF2(3, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(3, 3), 8.0); + + // Set a float matrix from double matrix + mTestMatrixF2.Set(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixF2(0, 0), 1.0); + EXPECT_EQ(mTestMatrixF2(0, 1), 2.0); + EXPECT_EQ(mTestMatrixF2(0, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixF2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(1, 1), 6.0); + EXPECT_EQ(mTestMatrixF2(1, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixF2(2, 0), 9.0); + EXPECT_EQ(mTestMatrixF2(2, 1), 8.0); + EXPECT_EQ(mTestMatrixF2(2, 2), 7.0); + EXPECT_EQ(mTestMatrixF2(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixF2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixF2(3, 1), 4.0); + EXPECT_EQ(mTestMatrixF2(3, 2), 3.0); + EXPECT_EQ(mTestMatrixF2(3, 3), 2.0); + + // Set a double matrix from float matrix + mTestMatrixD2.Set(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD2(0, 0), 9.0); + EXPECT_EQ(mTestMatrixD2(0, 1), 8.0); + EXPECT_EQ(mTestMatrixD2(0, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(1, 1), 4.0); + EXPECT_EQ(mTestMatrixD2(1, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD2(2, 0), 1.0); + EXPECT_EQ(mTestMatrixD2(2, 1), 2.0); + EXPECT_EQ(mTestMatrixD2(2, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(3, 1), 6.0); + EXPECT_EQ(mTestMatrixD2(3, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(3, 3), 8.0); + + // Set a double matrix from double matrix + mTestMatrixD2.Set(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD2.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD2(0, 0), 1.0); + EXPECT_EQ(mTestMatrixD2(0, 1), 2.0); + EXPECT_EQ(mTestMatrixD2(0, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrixD2(1, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(1, 1), 6.0); + EXPECT_EQ(mTestMatrixD2(1, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrixD2(2, 0), 9.0); + EXPECT_EQ(mTestMatrixD2(2, 1), 8.0); + EXPECT_EQ(mTestMatrixD2(2, 2), 7.0); + EXPECT_EQ(mTestMatrixD2(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD2(3, 0), 5.0); + EXPECT_EQ(mTestMatrixD2(3, 1), 4.0); + EXPECT_EQ(mTestMatrixD2(3, 2), 3.0); + EXPECT_EQ(mTestMatrixD2(3, 3), 2.0); + + // Set a matrix from float matrix + mTestMatrix.Set(mTestMatrixF1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 9.0); + EXPECT_EQ(mTestMatrix(0, 1), 8.0); + EXPECT_EQ(mTestMatrix(0, 2), 7.0); + EXPECT_EQ(mTestMatrix(0, 3), 6.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 5.0); + EXPECT_EQ(mTestMatrix(1, 1), 4.0); + EXPECT_EQ(mTestMatrix(1, 2), 3.0); + EXPECT_EQ(mTestMatrix(1, 3), 2.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 1.0); + EXPECT_EQ(mTestMatrix(2, 1), 2.0); + EXPECT_EQ(mTestMatrix(2, 2), 3.0); + EXPECT_EQ(mTestMatrix(2, 3), 4.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 5.0); + EXPECT_EQ(mTestMatrix(3, 1), 6.0); + EXPECT_EQ(mTestMatrix(3, 2), 7.0); + EXPECT_EQ(mTestMatrix(3, 3), 8.0); + + // Set a matrix from double matrix + mTestMatrix.Set(mTestMatrixD1); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 1.0); + EXPECT_EQ(mTestMatrix(0, 1), 2.0); + EXPECT_EQ(mTestMatrix(0, 2), 3.0); + EXPECT_EQ(mTestMatrix(0, 3), 4.0); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 5.0); + EXPECT_EQ(mTestMatrix(1, 1), 6.0); + EXPECT_EQ(mTestMatrix(1, 2), 7.0); + EXPECT_EQ(mTestMatrix(1, 3), 8.0); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 9.0); + EXPECT_EQ(mTestMatrix(2, 1), 8.0); + EXPECT_EQ(mTestMatrix(2, 2), 7.0); + EXPECT_EQ(mTestMatrix(2, 3), 6.0); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 5.0); + EXPECT_EQ(mTestMatrix(3, 1), 4.0); + EXPECT_EQ(mTestMatrix(3, 2), 3.0); + EXPECT_EQ(mTestMatrix(3, 3), 2.0); +} + +/** + * @fn TEST_F(MatrixTests, SetMatrixFromArray) + * + * @brief Test the setting of a Matrix from an array + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, SetMatrixFromArray) +{ + // Create a new matrix + mTestMatrixF1.Set(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixF1(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixF1(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixF1(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixF1(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrixF1.Set(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixF1(0, 0), 2.1, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 2), 5.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(0, 3), 4.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixF1(1, 0), 7.8, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 2), 8.9, 1e-6); + EXPECT_NEAR(mTestMatrixF1(1, 3), 0.5, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixF1(2, 0), 5.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 1), 6.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 2), 7.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(2, 3), 2.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixF1(3, 0), 4.5, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 1), 3.3, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 2), 2.6, 1e-6); + EXPECT_NEAR(mTestMatrixF1(3, 3), 8.3, 1e-6); + + // Create a new matrix + mTestMatrixD1.Set(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrixD1(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrixD1(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrixD1(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrixD1(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrixD1(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrixD1(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrixD1(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrixD1(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrixD1.Set(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrixD1(0, 0), 2.1); + EXPECT_EQ(mTestMatrixD1(0, 1), 4.3); + EXPECT_EQ(mTestMatrixD1(0, 2), 5.6); + EXPECT_EQ(mTestMatrixD1(0, 3), 4.5); + + // Test the second row values + EXPECT_EQ(mTestMatrixD1(1, 0), 7.8); + EXPECT_EQ(mTestMatrixD1(1, 1), 8.7); + EXPECT_EQ(mTestMatrixD1(1, 2), 8.9); + EXPECT_EQ(mTestMatrixD1(1, 3), 0.5); + + // Test the third row values + EXPECT_EQ(mTestMatrixD1(2, 0), 5.6); + EXPECT_EQ(mTestMatrixD1(2, 1), 6.6); + EXPECT_EQ(mTestMatrixD1(2, 2), 7.3); + EXPECT_EQ(mTestMatrixD1(2, 3), 2.5); + + // Test the fourth row values + EXPECT_EQ(mTestMatrixD1(3, 0), 4.5); + EXPECT_EQ(mTestMatrixD1(3, 1), 3.3); + EXPECT_EQ(mTestMatrixD1(3, 2), 2.6); + EXPECT_EQ(mTestMatrixD1(3, 3), 8.3); + + // Create a new matrix + mTestMatrix.Set(mArrayF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_NEAR(mTestMatrix(0, 0), 3.2, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 1), 4.3, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 2), 5.4, 1e-6); + EXPECT_NEAR(mTestMatrix(0, 3), 6.5, 1e-6); + + // Test the second row values + EXPECT_NEAR(mTestMatrix(1, 0), 7.6, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 1), 8.7, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 2), 9.8, 1e-6); + EXPECT_NEAR(mTestMatrix(1, 3), 0.9, 1e-6); + + // Test the third row values + EXPECT_NEAR(mTestMatrix(2, 0), 0.8, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 1), 0.7, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 2), 0.6, 1e-6); + EXPECT_NEAR(mTestMatrix(2, 3), 0.5, 1e-6); + + // Test the fourth row values + EXPECT_NEAR(mTestMatrix(3, 0), 0.4, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 1), 0.3, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 2), 0.2, 1e-6); + EXPECT_NEAR(mTestMatrix(3, 3), 0.1, 1e-6); + + // Create a new matrix + mTestMatrix.Set(mArrayD); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrix.Valid(), true); + + // Test the first row values + EXPECT_EQ(mTestMatrix(0, 0), 2.1); + EXPECT_EQ(mTestMatrix(0, 1), 4.3); + EXPECT_EQ(mTestMatrix(0, 2), 5.6); + EXPECT_EQ(mTestMatrix(0, 3), 4.5); + + // Test the second row values + EXPECT_EQ(mTestMatrix(1, 0), 7.8); + EXPECT_EQ(mTestMatrix(1, 1), 8.7); + EXPECT_EQ(mTestMatrix(1, 2), 8.9); + EXPECT_EQ(mTestMatrix(1, 3), 0.5); + + // Test the third row values + EXPECT_EQ(mTestMatrix(2, 0), 5.6); + EXPECT_EQ(mTestMatrix(2, 1), 6.6); + EXPECT_EQ(mTestMatrix(2, 2), 7.3); + EXPECT_EQ(mTestMatrix(2, 3), 2.5); + + // Test the fourth row values + EXPECT_EQ(mTestMatrix(3, 0), 4.5); + EXPECT_EQ(mTestMatrix(3, 1), 3.3); + EXPECT_EQ(mTestMatrix(3, 2), 2.6); + EXPECT_EQ(mTestMatrix(3, 3), 8.3); +} + +/** + * @fn TEST_F(MatrixTests, GetPointer) + * + * @brief Test the method for returning a Matrix pointer + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(MatrixTests, GetPointer) +{ + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixF1.Valid(), true); + + // Test if the pointer is NULL + EXPECT_EQ(nullptr, mMatPtrF); + + // Get the float pointer holding the float matrix + mMatPtrF = mTestMatrixF1.Ptr(); + + // Test if the pointer is NULL + EXPECT_NE(nullptr, mMatPtrF); + + // Test if the matrix is valid + EXPECT_EQ(mTestMatrixD1.Valid(), true); + + // Test if the pointer is NULL + EXPECT_EQ(nullptr, mMatPtrD); + + // Get the double pointer holding the double matrix + mMatPtrD = mTestMatrixD1.Ptr(); + + // Test if the pointer is NULL + EXPECT_NE(nullptr, mMatPtrD); } \ No newline at end of file diff --git a/Tests/TrBase/MatrixTests.h b/Tests/TrBase/MatrixTests.h index 96f4299..79d705f 100644 --- a/Tests/TrBase/MatrixTests.h +++ b/Tests/TrBase/MatrixTests.h @@ -1,90 +1,90 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -/** - * @class MatrixTests - * - * @brief Sets up test environment for Matrix class tests - */ -class MatrixTests : public ::testing::Test -{ - -public: - - /** @brief The test matrices. */ - trBase::Matrix mTestMatrix; - trBase::Matrix mTestMatrix2; - trBase::Matrixd mTestMatrixD1; - trBase::Matrixd mTestMatrixD2; - trBase::Matrixf mTestMatrixF1; - trBase::Matrixf mTestMatrixF2; - - osg::Matrix mTestMatOsg; - osg::Matrixd mTestMatOsgD; - osg::Matrixf mTestMatOsgF; - - /** @brief The test arrays. */ - double mArrayD [16] = { 2.1, 4.3, 5.6, 4.5, - 7.8, 8.7, 8.9, 0.5, - 5.6, 6.6, 7.3, 2.5, - 4.5, 3.3, 2.6, 8.3 }; - float mArrayF [16] = { 3.2f, 4.3f, 5.4f, 6.5f, - 7.6f, 8.7f, 9.8f, 0.9f, - 0.8f, 0.7f, 0.6f, 0.5f, - 0.4f, 0.3f, 0.2f, 0.1f }; - - /** @brief The test quaternion. */ - trBase::Quat mTestQuat; - - /** @brief The test pointers. */ - double* mMatPtrD = nullptr; - float* mMatPtrF = nullptr; - - /** - * @fn public::MatrixTests(); - * - * @brief Default constructor. - */ - MatrixTests(); - - /** - * @fn public::~MatrixTests(); - * - * @brief Destructor. - */ - ~MatrixTests(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/** + * @class MatrixTests + * + * @brief Sets up test environment for Matrix class tests + */ +class MatrixTests : public ::testing::Test +{ + +public: + + /** @brief The test matrices. */ + trBase::Matrix mTestMatrix; + trBase::Matrix mTestMatrix2; + trBase::Matrixd mTestMatrixD1; + trBase::Matrixd mTestMatrixD2; + trBase::Matrixf mTestMatrixF1; + trBase::Matrixf mTestMatrixF2; + + osg::Matrix mTestMatOsg; + osg::Matrixd mTestMatOsgD; + osg::Matrixf mTestMatOsgF; + + /** @brief The test arrays. */ + double mArrayD [16] = { 2.1, 4.3, 5.6, 4.5, + 7.8, 8.7, 8.9, 0.5, + 5.6, 6.6, 7.3, 2.5, + 4.5, 3.3, 2.6, 8.3 }; + float mArrayF [16] = { 3.2f, 4.3f, 5.4f, 6.5f, + 7.6f, 8.7f, 9.8f, 0.9f, + 0.8f, 0.7f, 0.6f, 0.5f, + 0.4f, 0.3f, 0.2f, 0.1f }; + + /** @brief The test quaternion. */ + trBase::Quat mTestQuat; + + /** @brief The test pointers. */ + double* mMatPtrD = nullptr; + float* mMatPtrF = nullptr; + + /** + * @fn public::MatrixTests(); + * + * @brief Default constructor. + */ + MatrixTests(); + + /** + * @fn public::~MatrixTests(); + * + * @brief Destructor. + */ + ~MatrixTests(); }; \ No newline at end of file diff --git a/Tests/TrBase/QuatTests.cpp b/Tests/TrBase/QuatTests.cpp index 2062caf..5c8e9f1 100644 --- a/Tests/TrBase/QuatTests.cpp +++ b/Tests/TrBase/QuatTests.cpp @@ -1,401 +1,401 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "QuatTests.h" - -#include - -////////////////////////////////////////////////////////////////////////// -QuatTests::QuatTests() -{ -} - -////////////////////////////////////////////////////////////////////////// -QuatTests::~QuatTests() -{ -} - - -/** - * @fn TEST_F(MatrixTests, CreateMatrix) - * - * @brief Test the creation of a default Quaternion. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuaternion) -{ - mTestQuat = trBase::Quat(); - - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromQuat) - * - * @brief Test the creation of a Quaternion from a Quaternion - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromQuat) -{ - EXPECT_EQ(mQuat.X(), 0.635); - EXPECT_EQ(mQuat.Y(), 0.431); - EXPECT_EQ(mQuat.Z(), 0.390); - EXPECT_EQ(mQuat.W(), 0.508); - - mTestQuat = trBase::Quat(mQuat); - EXPECT_EQ(mTestQuat.X(), 0.635); - EXPECT_EQ(mTestQuat.Y(), 0.431); - EXPECT_EQ(mTestQuat.Z(), 0.390); - EXPECT_EQ(mTestQuat.W(), 0.508); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromOSGQuat) - * - * @brief Test the creation of a Quaternion from an OSG Quaternion - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromOSGQuat) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - EXPECT_EQ(mOsgQuat.x(), 0.635); - EXPECT_EQ(mOsgQuat.y(), 0.431); - EXPECT_EQ(mOsgQuat.z(), 0.390); - EXPECT_EQ(mOsgQuat.w(), 0.508); - - mTestQuat = trBase::Quat(mOsgQuat); - EXPECT_EQ(mTestQuat.X(), 0.635); - EXPECT_EQ(mTestQuat.Y(), 0.431); - EXPECT_EQ(mTestQuat.Z(), 0.390); - EXPECT_EQ(mTestQuat.W(), 0.508); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromDoubles) - * - * @brief Test the creation of a Quaternion from Doubles - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromDoubles) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(0.635, 0.431, 0.390, 0.508); - EXPECT_EQ(mTestQuat.X(), 0.635); - EXPECT_EQ(mTestQuat.Y(), 0.431); - EXPECT_EQ(mTestQuat.Z(), 0.390); - EXPECT_EQ(mTestQuat.W(), 0.508); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromFloats) - * - * @brief Test the creation of a Quaternion from Floats. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromFloats) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(0.635f, 0.431f, 0.390f, 0.508f); - EXPECT_NEAR(mTestQuat.X(), 0.635, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.431, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.390, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.508, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromVec4f) - * - * @brief Test the creation of a Quaternion from a Float Vector. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromVec4f) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(mTestQuatVecF); - EXPECT_NEAR(mTestQuat.X(), 0.635, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.431, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.390, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.508, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromVec4d) - * - * @brief Test the creation of a Quaternion from a Double Vector. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromVec4d) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(mTestQuatVecD); - EXPECT_EQ(mTestQuat.X(), 0.635); - EXPECT_EQ(mTestQuat.Y(), 0.431); - EXPECT_EQ(mTestQuat.Z(), 0.390); - EXPECT_EQ(mTestQuat.W(), 0.508); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) - * - * @brief Test the creation of a Quaternion from a Radian angle and a Float Axis. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mXVecF); - EXPECT_NEAR(mTestQuat.X(), 0.571227019423115823f, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mYVecF); - EXPECT_NEAR(mTestQuat.X(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.571227019423115823f, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mZVecF); - EXPECT_NEAR(mTestQuat.X(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.0f, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.571227019423115823f, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisD) - * - * @brief Test the creation of a Quaternion from a Radian angle and a Double Axis. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromAngleAndAxisD) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mXVecD); - EXPECT_EQ(mTestQuat.X(), 0.571227019423115823); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mYVecD); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.571227019423115823); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(1.216, mZVecD); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.571227019423115823); - EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) - * - * @brief Test the creation of a Quaternion from a Radian angles and a Float Axises. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesF) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(-0.436, mXVecF, 1.216, mYVecF, 1.955, mZVecF); - EXPECT_NEAR(mTestQuat.X(), -0.5616464971941317f, 1e-6); - EXPECT_NEAR(mTestQuat.Y(), 0.1646312318780489f, 1e-6); - EXPECT_NEAR(mTestQuat.Z(), 0.7334867735370875f, 1e-6); - EXPECT_NEAR(mTestQuat.W(), 0.345610941270718f, 1e-6); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - -/** - * @fn TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesD) - * - * @brief Test the creation of a Quaternion from a Radian angles and a Double Axises. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesD) -{ - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); - - mTestQuat = trBase::Quat(-0.436, mXVecD, 1.216, mYVecD, 1.955, mZVecD); - EXPECT_EQ(mTestQuat.X(), -0.5616464971941317); - EXPECT_EQ(mTestQuat.Y(), 0.1646312318780489); - EXPECT_EQ(mTestQuat.Z(), 0.7334867735370875); - EXPECT_EQ(mTestQuat.W(), 0.345610941270718); - - mTestQuat.Clear(); - EXPECT_EQ(mTestQuat.X(), 0.0); - EXPECT_EQ(mTestQuat.Y(), 0.0); - EXPECT_EQ(mTestQuat.Z(), 0.0); - EXPECT_EQ(mTestQuat.W(), 1.0); -} - - /** - trBase::Vec4d mTestQuatVec = trBase::Vec4d(0.635, 0.431, 0.390, 0.508); - trBase::Vec3d mTestRadVec = trBase::Vec3d(-0.436, 1.204, 2.094); - trBase::Vec3d mTestDegVec = trBase::Vec3d(-25.000, 69.000, 120.000); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "QuatTests.h" + +#include + +////////////////////////////////////////////////////////////////////////// +QuatTests::QuatTests() +{ +} + +////////////////////////////////////////////////////////////////////////// +QuatTests::~QuatTests() +{ +} + + +/** + * @fn TEST_F(MatrixTests, CreateMatrix) + * + * @brief Test the creation of a default Quaternion. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuaternion) +{ + mTestQuat = trBase::Quat(); + + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromQuat) + * + * @brief Test the creation of a Quaternion from a Quaternion + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromQuat) +{ + EXPECT_EQ(mQuat.X(), 0.635); + EXPECT_EQ(mQuat.Y(), 0.431); + EXPECT_EQ(mQuat.Z(), 0.390); + EXPECT_EQ(mQuat.W(), 0.508); + + mTestQuat = trBase::Quat(mQuat); + EXPECT_EQ(mTestQuat.X(), 0.635); + EXPECT_EQ(mTestQuat.Y(), 0.431); + EXPECT_EQ(mTestQuat.Z(), 0.390); + EXPECT_EQ(mTestQuat.W(), 0.508); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromOSGQuat) + * + * @brief Test the creation of a Quaternion from an OSG Quaternion + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromOSGQuat) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + EXPECT_EQ(mOsgQuat.x(), 0.635); + EXPECT_EQ(mOsgQuat.y(), 0.431); + EXPECT_EQ(mOsgQuat.z(), 0.390); + EXPECT_EQ(mOsgQuat.w(), 0.508); + + mTestQuat = trBase::Quat(mOsgQuat); + EXPECT_EQ(mTestQuat.X(), 0.635); + EXPECT_EQ(mTestQuat.Y(), 0.431); + EXPECT_EQ(mTestQuat.Z(), 0.390); + EXPECT_EQ(mTestQuat.W(), 0.508); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromDoubles) + * + * @brief Test the creation of a Quaternion from Doubles + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromDoubles) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(0.635, 0.431, 0.390, 0.508); + EXPECT_EQ(mTestQuat.X(), 0.635); + EXPECT_EQ(mTestQuat.Y(), 0.431); + EXPECT_EQ(mTestQuat.Z(), 0.390); + EXPECT_EQ(mTestQuat.W(), 0.508); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromFloats) + * + * @brief Test the creation of a Quaternion from Floats. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromFloats) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(0.635f, 0.431f, 0.390f, 0.508f); + EXPECT_NEAR(mTestQuat.X(), 0.635, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.431, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.390, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.508, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromVec4f) + * + * @brief Test the creation of a Quaternion from a Float Vector. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromVec4f) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(mTestQuatVecF); + EXPECT_NEAR(mTestQuat.X(), 0.635, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.431, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.390, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.508, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromVec4d) + * + * @brief Test the creation of a Quaternion from a Double Vector. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromVec4d) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(mTestQuatVecD); + EXPECT_EQ(mTestQuat.X(), 0.635); + EXPECT_EQ(mTestQuat.Y(), 0.431); + EXPECT_EQ(mTestQuat.Z(), 0.390); + EXPECT_EQ(mTestQuat.W(), 0.508); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) + * + * @brief Test the creation of a Quaternion from a Radian angle and a Float Axis. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mXVecF); + EXPECT_NEAR(mTestQuat.X(), 0.571227019423115823f, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mYVecF); + EXPECT_NEAR(mTestQuat.X(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.571227019423115823f, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mZVecF); + EXPECT_NEAR(mTestQuat.X(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.0f, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.571227019423115823f, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.820792112706368093f, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisD) + * + * @brief Test the creation of a Quaternion from a Radian angle and a Double Axis. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromAngleAndAxisD) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mXVecD); + EXPECT_EQ(mTestQuat.X(), 0.571227019423115823); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mYVecD); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.571227019423115823); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(1.216, mZVecD); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.571227019423115823); + EXPECT_EQ(mTestQuat.W(), 0.820792112706368093); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromAngleAndAxisF) + * + * @brief Test the creation of a Quaternion from a Radian angles and a Float Axises. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesF) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(-0.436, mXVecF, 1.216, mYVecF, 1.955, mZVecF); + EXPECT_NEAR(mTestQuat.X(), -0.5616464971941317f, 1e-6); + EXPECT_NEAR(mTestQuat.Y(), 0.1646312318780489f, 1e-6); + EXPECT_NEAR(mTestQuat.Z(), 0.7334867735370875f, 1e-6); + EXPECT_NEAR(mTestQuat.W(), 0.345610941270718f, 1e-6); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + +/** + * @fn TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesD) + * + * @brief Test the creation of a Quaternion from a Radian angles and a Double Axises. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(QuatTests, CreateQuatFromAnglesAndAxisesD) +{ + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); + + mTestQuat = trBase::Quat(-0.436, mXVecD, 1.216, mYVecD, 1.955, mZVecD); + EXPECT_EQ(mTestQuat.X(), -0.5616464971941317); + EXPECT_EQ(mTestQuat.Y(), 0.1646312318780489); + EXPECT_EQ(mTestQuat.Z(), 0.7334867735370875); + EXPECT_EQ(mTestQuat.W(), 0.345610941270718); + + mTestQuat.Clear(); + EXPECT_EQ(mTestQuat.X(), 0.0); + EXPECT_EQ(mTestQuat.Y(), 0.0); + EXPECT_EQ(mTestQuat.Z(), 0.0); + EXPECT_EQ(mTestQuat.W(), 1.0); +} + + /** + trBase::Vec4d mTestQuatVec = trBase::Vec4d(0.635, 0.431, 0.390, 0.508); + trBase::Vec3d mTestRadVec = trBase::Vec3d(-0.436, 1.204, 2.094); + trBase::Vec3d mTestDegVec = trBase::Vec3d(-25.000, 69.000, 120.000); */ \ No newline at end of file diff --git a/Tests/TrBase/QuatTests.h b/Tests/TrBase/QuatTests.h index a49db0c..c835c59 100644 --- a/Tests/TrBase/QuatTests.h +++ b/Tests/TrBase/QuatTests.h @@ -1,76 +1,76 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include - -/** - * @class QuatTests - * - * @brief Sets up test environment for Quaternion class tests. - */ -class QuatTests : public ::testing::Test -{ - -public: - - /** @brief The test quaternion. */ - trBase::Quat mTestQuat; - - // Quaternion values in quat, degrees and radians - trBase::Quat mQuat = trBase::Quat(0.635, 0.431, 0.390, 0.508); - osg::Quat mOsgQuat = osg::Quat(0.635, 0.431, 0.390, 0.508); - trBase::Vec4d mTestQuatVecD = trBase::Vec4d(0.635, 0.431, 0.390, 0.508); - trBase::Vec4f mTestQuatVecF = trBase::Vec4f(0.635f, 0.431f, 0.390f, 0.508f); - trBase::Vec3d mTestRadVec = trBase::Vec3d(-0.436, 1.204, 2.094); - trBase::Vec3d mTestDegVec = trBase::Vec3d(-25.000, 69.000, 120.000); - - trBase::Vec3d mXVecD = trBase::Vec3d(1.0, 0.0, 0.0); - trBase::Vec3d mYVecD = trBase::Vec3d(0.0, 1.0, 0.0); - trBase::Vec3d mZVecD = trBase::Vec3d(0.0, 0.0, 1.0); - - trBase::Vec3f mXVecF = trBase::Vec3f(1.0f, 0.0f, 0.0f); - trBase::Vec3f mYVecF = trBase::Vec3f(0.0f, 1.0f, 0.0f); - trBase::Vec3f mZVecF = trBase::Vec3f(0.0f, 0.0f, 1.0f); - - /** - * @fn public::QuatTests(); - * - * @brief Default constructor. - */ - QuatTests(); - - /** - * @fn public::~QuatTests(); - * - * @brief Destructor. - */ - ~QuatTests(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include + +/** + * @class QuatTests + * + * @brief Sets up test environment for Quaternion class tests. + */ +class QuatTests : public ::testing::Test +{ + +public: + + /** @brief The test quaternion. */ + trBase::Quat mTestQuat; + + // Quaternion values in quat, degrees and radians + trBase::Quat mQuat = trBase::Quat(0.635, 0.431, 0.390, 0.508); + osg::Quat mOsgQuat = osg::Quat(0.635, 0.431, 0.390, 0.508); + trBase::Vec4d mTestQuatVecD = trBase::Vec4d(0.635, 0.431, 0.390, 0.508); + trBase::Vec4f mTestQuatVecF = trBase::Vec4f(0.635f, 0.431f, 0.390f, 0.508f); + trBase::Vec3d mTestRadVec = trBase::Vec3d(-0.436, 1.204, 2.094); + trBase::Vec3d mTestDegVec = trBase::Vec3d(-25.000, 69.000, 120.000); + + trBase::Vec3d mXVecD = trBase::Vec3d(1.0, 0.0, 0.0); + trBase::Vec3d mYVecD = trBase::Vec3d(0.0, 1.0, 0.0); + trBase::Vec3d mZVecD = trBase::Vec3d(0.0, 0.0, 1.0); + + trBase::Vec3f mXVecF = trBase::Vec3f(1.0f, 0.0f, 0.0f); + trBase::Vec3f mYVecF = trBase::Vec3f(0.0f, 1.0f, 0.0f); + trBase::Vec3f mZVecF = trBase::Vec3f(0.0f, 0.0f, 1.0f); + + /** + * @fn public::QuatTests(); + * + * @brief Default constructor. + */ + QuatTests(); + + /** + * @fn public::~QuatTests(); + * + * @brief Destructor. + */ + ~QuatTests(); }; \ No newline at end of file diff --git a/Tests/TrBase/UniqueIdTests.cpp b/Tests/TrBase/UniqueIdTests.cpp index 3fe921d..9de87a5 100644 --- a/Tests/TrBase/UniqueIdTests.cpp +++ b/Tests/TrBase/UniqueIdTests.cpp @@ -30,14 +30,16 @@ const trUtil::RefStr UniqueIdTests::NULL_ID = trUtil::RefStr("00000000-0000-0000-0000-000000000000"); const trUtil::RefStr UniqueIdTests::TEST_ID = trUtil::RefStr("1020ac56-6732-6969-ffd0-fdabc4376cca"); +const trUtil::RefStr UniqueIdTests::TEST_ID2 = trUtil::RefStr("1ff0ac56-6732-1919-ffd0-fdaff4376cca"); ////////////////////////////////////////////////////////////////////////// UniqueIdTests::UniqueIdTests() +: mNullID(trBase::UniqueId(false)) +, mNewID1(trBase::UniqueId(NULL_ID)) +, mNewID2(trBase::UniqueId(TEST_ID)) +, mNewID3(trBase::UniqueId()) +, mNewID4(trBase::UniqueId(TEST_ID2)) { - mNullID = trBase::UniqueId(false); - mNewID1 = trBase::UniqueId(static_cast(NULL_ID)); - mNewID2 = trBase::UniqueId(static_cast(TEST_ID)); - mNewID3 = trBase::UniqueId(); } ////////////////////////////////////////////////////////////////////////// @@ -71,8 +73,8 @@ TEST_F(UniqueIdTests, ClassTypeTests) */ TEST_F(UniqueIdTests, ConstructorTests) { - trBase::UniqueId newID1(static_cast(NULL_ID)); - trBase::UniqueId newID2(static_cast(TEST_ID)); + trBase::UniqueId newID1(NULL_ID); + trBase::UniqueId newID2(TEST_ID); trBase::UniqueId newID3(true); trBase::UniqueId newID4(false); trBase::UniqueId newID5(mNewID2); @@ -147,6 +149,12 @@ TEST_F(UniqueIdTests, ComparisonTests) // Test the equality operator EXPECT_EQ(mNullID == mNewID1, true); + + // Tests the grater then operator + EXPECT_EQ(mNewID4 > mNewID2, true); + + // Tests the less then operator + EXPECT_EQ(mNewID4 < mNewID2, false); } /** diff --git a/Tests/TrBase/UniqueIdTests.h b/Tests/TrBase/UniqueIdTests.h index 1b0588f..82bca8d 100644 --- a/Tests/TrBase/UniqueIdTests.h +++ b/Tests/TrBase/UniqueIdTests.h @@ -38,11 +38,13 @@ class UniqueIdTests : public ::testing::Test const static trUtil::RefStr NULL_ID; const static trUtil::RefStr TEST_ID; + const static trUtil::RefStr TEST_ID2; trBase::UniqueId mNullID; trBase::UniqueId mNewID1; trBase::UniqueId mNewID2; trBase::UniqueId mNewID3; + trBase::UniqueId mNewID4; /** diff --git a/Tests/TrManager/ActorTests.cpp b/Tests/TrManager/ActorTests.cpp index afcb2b8..efece76 100644 --- a/Tests/TrManager/ActorTests.cpp +++ b/Tests/TrManager/ActorTests.cpp @@ -1,308 +1,304 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "ActorTests.h" - -#include "TestActor1.h" -#include "TestActor2.h" -#include "TestActor3.h" -#include "TestMessage.h" - -#include -#include -#include - -#include - - -////////////////////////////////////////////////////////////////////////// -ActorTests::ActorTests() -{ - //Create an instance of the System Manager - mSysMan = &trManager::SystemManager::GetInstance(); - - //Create and register the System Director - mSysDirector = new trCore::SystemDirector(); - - //We want the System Director to get and handle all messages before any other Director. - mSysMan->RegisterDirector(*mSysDirector, trManager::DirectorPriority::HIGHEST); - -} - -////////////////////////////////////////////////////////////////////////// -ActorTests::~ActorTests() -{ - //Create a System Control Shutdown message - trBase::SmrtPtr msg = new trCore::MessageSystemControl(NULL, trCore::SystemControls::SHUT_DOWN); - - //Send message - mSysMan->SendMessage(*msg); - - //Remove all Directors from the system - mSysMan->UnregisterAllDirectors(); - - //Advance System Manager one frame - mSysDirector->RunOnce(); -} - -/** - * @fn TEST_F(ActorTests, AddRemoveActors) - * - * @brief Tests the adding and removal of directors. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(ActorTests, AddRemoveActor) -{ - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor1::GetInstCount(), 0); - - //Add TestActor1 to the system - trBase::SmrtPtr actor = new TestActor1(); - EXPECT_EQ(mSysMan->RegisterActor(*actor), true); - - //We should have one instance of the actor - EXPECT_EQ(TestActor1::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //We should have one instance of the actor - EXPECT_EQ(TestActor1::GetInstCount(), 1); - - EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); - - //Release ownership of this pointer - actor.Release(); - - //We should have one instance of the actor - EXPECT_EQ(TestActor1::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor1::GetInstCount(), 0); -} - -/** - * @fn TEST_F(ActorTests, SendMessage) - * - * @brief Tests the sending of messages between actors. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(ActorTests, SendMessage) -{ - //Add TestActor1 to the system - trBase::SmrtPtr actor = new TestActor1(); - EXPECT_EQ(mSysMan->RegisterActor(*actor), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 0); - - //Add TestActor2 to the system - trBase::SmrtPtr actor2 = new TestActor2(); - EXPECT_EQ(mSysMan->RegisterActor(*actor2), true); - - //Make sure we have one instance of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check if Actor1 has received two ticks by now - EXPECT_EQ(actor->GetTickMsgNum(), 2); - - //No instances of the message should exist in the system yet - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - //Send a test message - EXPECT_EQ(actor->SendTestMessage(), true); - - //We should have one message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 1); - - //Check that we have no messages yet - EXPECT_EQ(actor2->GetTestMsgCount(), 0); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check that we have one message - EXPECT_EQ(actor2->GetTestMsgCount(), 1); - - //We should have no message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - //Send a test message - EXPECT_EQ(actor->SendTestMessage(), true); - - //We should have one message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - - //Check that we have one message - EXPECT_EQ(actor2->GetTestMsgCount(), 5); - - //We should have no message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - EXPECT_EQ(mSysMan->UnregisterActor(actor2->GetUUID()), true); - EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); - - //Release ownership of this pointer - actor2.Release(); - actor.Release(); - - //We should have one instance of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 1); - EXPECT_EQ(TestActor1::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 0); - EXPECT_EQ(TestActor1::GetInstCount(), 0); -} - -TEST_F(ActorTests, Listener) -{ - //Add TestActor1 to the system - trBase::SmrtPtr actor = new TestActor1(); - EXPECT_EQ(mSysMan->RegisterActor(*actor), true); - - //Add TestActor2 to the system - trBase::SmrtPtr actor2 = new TestActor2(); - EXPECT_EQ(mSysMan->RegisterActor(*actor2), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor3::GetInstCount(), 0); - - //Add TestActor3 to the system - trBase::SmrtPtr actor3 = new TestActor3(); - EXPECT_EQ(mSysMan->RegisterActor(*actor3), true); - - //Make the actor3 listen to messages about actor2 - mSysMan->RegisterForMessagesAboutEntity(*actor3, actor2->GetUUID(), TestActor3::ON_TEST_ACTOR_2_INVOKABLE); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor3::GetInstCount(), 1); - - //No instances of the message should exist in the system yet - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - //Send a test message - EXPECT_EQ(actor->SendTestMessage(), true); - - //We should have one message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 1); - - //Check that we have no messages yet - EXPECT_EQ(actor3->GetTestMsgCount(), 0); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check that we have one message - EXPECT_EQ(actor3->GetTestMsgCount(), 1); - - //We should have no message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - //Send a test message - EXPECT_EQ(actor->SendTestMessage(), true); - - //We should have one message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - EXPECT_EQ(actor->SendTestMessage(), true); - mSysDirector->RunOnce(); - - //Check that we have one message - EXPECT_EQ(actor3->GetTestMsgCount(), 5); - - //We should have no message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 0); - - //Unregister the actor - EXPECT_EQ(mSysMan->UnregisterActor(actor3->GetUUID()), true); - - //Release ownership of this pointer - actor3.Release(); - - //We should have one instance of the actor - EXPECT_EQ(TestActor3::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor3::GetInstCount(), 0); - - //Unregister the rest of the actors - EXPECT_EQ(mSysMan->UnregisterActor(actor2->GetUUID()), true); - EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); - - //Release ownership of this pointer - actor2.Release(); - actor.Release(); - - //We should have one instance of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 1); - EXPECT_EQ(TestActor1::GetInstCount(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Make sure we dont have any instances of the actor - EXPECT_EQ(TestActor2::GetInstCount(), 0); - EXPECT_EQ(TestActor1::GetInstCount(), 0); - - //We should have no message in the system - EXPECT_EQ(TestMessage::GetInstCount(), 0); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "ActorTests.h" + +#include "TestActor1.h" +#include "TestActor2.h" +#include "TestActor3.h" +#include "TestMessage.h" + +#include +#include +#include + +#include + + +////////////////////////////////////////////////////////////////////////// +ActorTests::ActorTests() +: mSysMan(&trManager::SystemManager::GetInstance()) //Create an instance of the System Manager +, mSysDirector(new trCore::SystemDirector()) //Create and register the System Director +{ + //We want the System Director to get and handle all messages before any other Director. + mSysMan->RegisterDirector(*mSysDirector, trManager::DirectorPriority::HIGHEST); + +} + +////////////////////////////////////////////////////////////////////////// +ActorTests::~ActorTests() +{ + //Create a System Control Shutdown message + trBase::SmrtPtr msg = new trCore::MessageSystemControl(NULL, trCore::SystemControls::SHUT_DOWN); + + //Send message + mSysMan->SendMessage(*msg); + + //Remove all Directors from the system + mSysMan->UnregisterAllDirectors(); + + //Advance System Manager one frame + mSysDirector->RunOnce(); +} + +/** + * @fn TEST_F(ActorTests, AddRemoveActors) + * + * @brief Tests the adding and removal of directors. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(ActorTests, AddRemoveActor) +{ + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor1::GetInstCount(), 0); + + //Add TestActor1 to the system + trBase::SmrtPtr actor = new TestActor1(); + EXPECT_EQ(mSysMan->RegisterActor(*actor), true); + + //We should have one instance of the actor + EXPECT_EQ(TestActor1::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //We should have one instance of the actor + EXPECT_EQ(TestActor1::GetInstCount(), 1); + + EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); + + //Release ownership of this pointer + actor.Release(); + + //We should have one instance of the actor + EXPECT_EQ(TestActor1::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor1::GetInstCount(), 0); +} + +/** + * @fn TEST_F(ActorTests, SendMessage) + * + * @brief Tests the sending of messages between actors. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(ActorTests, SendMessage) +{ + //Add TestActor1 to the system + trBase::SmrtPtr actor = new TestActor1(); + EXPECT_EQ(mSysMan->RegisterActor(*actor), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 0); + + //Add TestActor2 to the system + trBase::SmrtPtr actor2 = new TestActor2(); + EXPECT_EQ(mSysMan->RegisterActor(*actor2), true); + + //Make sure we have one instance of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check if Actor1 has received two ticks by now + EXPECT_EQ(actor->GetTickMsgNum(), 2); + + //No instances of the message should exist in the system yet + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + //Send a test message + EXPECT_EQ(actor->SendTestMessage(), true); + + //We should have one message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 1); + + //Check that we have no messages yet + EXPECT_EQ(actor2->GetTestMsgCount(), 0); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check that we have one message + EXPECT_EQ(actor2->GetTestMsgCount(), 1); + + //We should have no message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + //Send a test message + EXPECT_EQ(actor->SendTestMessage(), true); + + //We should have one message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + + //Check that we have one message + EXPECT_EQ(actor2->GetTestMsgCount(), 5); + + //We should have no message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + EXPECT_EQ(mSysMan->UnregisterActor(actor2->GetUUID()), true); + EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); + + //Release ownership of this pointer + actor2.Release(); + actor.Release(); + + //We should have one instance of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 1); + EXPECT_EQ(TestActor1::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 0); + EXPECT_EQ(TestActor1::GetInstCount(), 0); +} + +TEST_F(ActorTests, Listener) +{ + //Add TestActor1 to the system + trBase::SmrtPtr actor = new TestActor1(); + EXPECT_EQ(mSysMan->RegisterActor(*actor), true); + + //Add TestActor2 to the system + trBase::SmrtPtr actor2 = new TestActor2(); + EXPECT_EQ(mSysMan->RegisterActor(*actor2), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor3::GetInstCount(), 0); + + //Add TestActor3 to the system + trBase::SmrtPtr actor3 = new TestActor3(); + EXPECT_EQ(mSysMan->RegisterActor(*actor3), true); + + //Make the actor3 listen to messages about actor2 + mSysMan->RegisterForMessagesAboutEntity(*actor3, actor2->GetUUID(), TestActor3::ON_TEST_ACTOR_2_INVOKABLE); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor3::GetInstCount(), 1); + + //No instances of the message should exist in the system yet + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + //Send a test message + EXPECT_EQ(actor->SendTestMessage(), true); + + //We should have one message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 1); + + //Check that we have no messages yet + EXPECT_EQ(actor3->GetTestMsgCount(), 0); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check that we have one message + EXPECT_EQ(actor3->GetTestMsgCount(), 1); + + //We should have no message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + //Send a test message + EXPECT_EQ(actor->SendTestMessage(), true); + + //We should have one message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + EXPECT_EQ(actor->SendTestMessage(), true); + mSysDirector->RunOnce(); + + //Check that we have one message + EXPECT_EQ(actor3->GetTestMsgCount(), 5); + + //We should have no message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 0); + + //Unregister the actor + EXPECT_EQ(mSysMan->UnregisterActor(actor3->GetUUID()), true); + + //Release ownership of this pointer + actor3.Release(); + + //We should have one instance of the actor + EXPECT_EQ(TestActor3::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor3::GetInstCount(), 0); + + //Unregister the rest of the actors + EXPECT_EQ(mSysMan->UnregisterActor(actor2->GetUUID()), true); + EXPECT_EQ(mSysMan->UnregisterActor(actor->GetUUID()), true); + + //Release ownership of this pointer + actor2.Release(); + actor.Release(); + + //We should have one instance of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 1); + EXPECT_EQ(TestActor1::GetInstCount(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Make sure we dont have any instances of the actor + EXPECT_EQ(TestActor2::GetInstCount(), 0); + EXPECT_EQ(TestActor1::GetInstCount(), 0); + + //We should have no message in the system + EXPECT_EQ(TestMessage::GetInstCount(), 0); } \ No newline at end of file diff --git a/Tests/TrManager/ActorTests.h b/Tests/TrManager/ActorTests.h index 86e9a7e..87566d6 100644 --- a/Tests/TrManager/ActorTests.h +++ b/Tests/TrManager/ActorTests.h @@ -1,57 +1,57 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - - -/** - * @class ActorTests - * - * @brief Sets up the unit test environment for Actor classes. - */ -class ActorTests : public ::testing::Test -{ -public: - - /** @brief Manager pointer for system. */ - trBase::SmrtPtr mSysMan; - - /** @brief The system director pointer. */ - trBase::SmrtPtr mSysDirector; - - /** - * @fn public::ActorTests(); - * - * @brief Default constructor. - */ - ActorTests(); - - /** - * @fn public::~ActorTests(); - * - * @brief Destructor. - */ - ~ActorTests(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + + +/** + * @class ActorTests + * + * @brief Sets up the unit test environment for Actor classes. + */ +class ActorTests : public ::testing::Test +{ +public: + + /** @brief Manager pointer for system. */ + trBase::SmrtPtr mSysMan; + + /** @brief The system director pointer. */ + trBase::SmrtPtr mSysDirector; + + /** + * @fn public::ActorTests(); + * + * @brief Default constructor. + */ + ActorTests(); + + /** + * @fn public::~ActorTests(); + * + * @brief Destructor. + */ + ~ActorTests(); }; \ No newline at end of file diff --git a/Tests/TrManager/DirectorTests.cpp b/Tests/TrManager/DirectorTests.cpp index 22b4a49..56b2e2f 100644 --- a/Tests/TrManager/DirectorTests.cpp +++ b/Tests/TrManager/DirectorTests.cpp @@ -1,334 +1,329 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "DirectorTests.h" - -#include "TestDirector1.h" -#include "TestDirector2.h" - -#include - -#include -#include -#include - -#include - -////////////////////////////////////////////////////////////////////////// -DirectorTests::DirectorTests() -{ - //Create an instance of the System Manager - mSysMan = &trManager::SystemManager::GetInstance(); - - //Create and register the System Director - mSysDirector = new trCore::SystemDirector(); - - //We want the System Director to get and handle all messages before any other Director. - mSysMan->RegisterDirector(*mSysDirector, trManager::DirectorPriority::HIGHEST); - -} - -////////////////////////////////////////////////////////////////////////// -DirectorTests::~DirectorTests() -{ - //Create a System Control Shutdown message - trBase::SmrtPtr msg = new trCore::MessageSystemControl(NULL, trCore::SystemControls::SHUT_DOWN); - - //Send message - mSysMan->SendMessage(*msg); - - //Remove all Directors from the system - mSysMan->UnregisterAllDirectors(); - - //Advance System Manager one frame - mSysDirector->RunOnce(); -} - -/** - * @fn TEST_F(DirectorTest, AddRemoveDirector) - * - * @brief Tests the adding and removal of directors - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, AddRemoveDirector) -{ - //Make sure we have no instances of this director - EXPECT_EQ(TestDirector2::GetInstCount(), 0); - - //Add a Director to the system - trBase::SmrtPtr director = new TestDirector2(); - mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //We should have one director in the system of this type - EXPECT_EQ(TestDirector2::GetInstCount(), 1); - - //Unregister the director. - EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //We should have no director2 in the system of this type - EXPECT_EQ(TestDirector2::GetInstCount(), 0); -} - -/** - * @fn TEST_F(DirectorTest, TimeScale) - * - * @brief Tests the change of time scale. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, TimeScale) -{ - //Check that the time is running at normal rate - EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 1.0); - - //Send a message to change time scale - trBase::SmrtPtr msg = new trCore::MessageSystemControl(new trBase::UniqueId(), trCore::SystemControls::SET_TIME_SCALE, 20.69); - mSysMan->SendMessage(*msg); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check that the time scale has changed - EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 20.69); - - //Send a message to change time scale - msg = new trCore::MessageSystemControl(new trBase::UniqueId(), trCore::SystemControls::SET_TIME_SCALE, 1.0); - mSysMan->SendMessage(*msg); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check that the time is running at normal rate - EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 1.0); -} - -/** - * @fn TEST_F(DirectorTest, TickMessage) - * - * @brief Tests reception of the Tick message - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, TickMessage) -{ - //Add a Director to the system - trBase::SmrtPtr director = new TestDirector1(); - EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); - - //Check for the number of tick messages - EXPECT_EQ(director->GetTickMsgNumber(), 0); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check for the number of tick messages - EXPECT_EQ(director->GetTickMsgNumber(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check for the number of tick messages - EXPECT_EQ(director->GetTickMsgNumber(), 2); - - //Unregister the director. - EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); -} - -/** - * @fn TEST_F(DirectorTest, SystemEventMsg) - * - * @brief Tests the System Event Message and its content. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, SystemEventMsg) -{ - //Add a Director to the system - trBase::SmrtPtr director = new TestDirector1(); - EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 0); - EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 0); - EXPECT_EQ(director->GetPreFrameEventMsgNum(), 0); - EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 0); - EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 0); - EXPECT_EQ(director->GetFrameEventMsgNum(), 0); - EXPECT_EQ(director->GetPostFrameEventMsgNum(), 0); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 1); - EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 1); - EXPECT_EQ(director->GetPreFrameEventMsgNum(), 1); - EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 1); - EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 1); - EXPECT_EQ(director->GetFrameEventMsgNum(), 1); - EXPECT_EQ(director->GetPostFrameEventMsgNum(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - mSysDirector->RunOnce(); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 3); - EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 3); - EXPECT_EQ(director->GetPreFrameEventMsgNum(), 3); - EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 3); - EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 3); - EXPECT_EQ(director->GetFrameEventMsgNum(), 3); - EXPECT_EQ(director->GetPostFrameEventMsgNum(), 3); - - //Unregister the director. - EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); -} - -/** - * @fn TEST_F(DirectorTest, FrameEventMsg) - * - * @brief Tests the individual messages of the main frame loop - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, FrameEventMsg) -{ - //Add a Director to the system - trBase::SmrtPtr director = new TestDirector1(); - EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalMsgNum(), 0); - EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 0); - EXPECT_EQ(director->GetCameraSynchMsgNum(), 0); - EXPECT_EQ(director->GetFrameSynchMsgNum(), 0); - EXPECT_EQ(director->GetFrameMsgNum(), 0); - EXPECT_EQ(director->GetPostFrameMsgNum(), 0); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalMsgNum(), 1); - EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 1); - EXPECT_EQ(director->GetCameraSynchMsgNum(), 1); - EXPECT_EQ(director->GetFrameSynchMsgNum(), 1); - EXPECT_EQ(director->GetFrameMsgNum(), 1); - EXPECT_EQ(director->GetPostFrameMsgNum(), 1); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - mSysDirector->RunOnce(); - - //Check the number of frame events received. - EXPECT_EQ(director->GetEventTraversalMsgNum(), 3); - EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 3); - EXPECT_EQ(director->GetCameraSynchMsgNum(), 3); - EXPECT_EQ(director->GetFrameSynchMsgNum(), 3); - EXPECT_EQ(director->GetFrameMsgNum(), 3); - EXPECT_EQ(director->GetPostFrameMsgNum(), 3); - - //Unregister the director. - EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); -} - -/** - * @fn TEST_F(DirectorTest, SendReceiveMsg) - * - * @brief Test the sending and receiving of messages - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - */ -TEST_F(DirectorTests, SendReceiveMsg) -{ - //Add a Directors to the system - trBase::SmrtPtr director = new TestDirector1(); - EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); - trBase::SmrtPtr director2 = new TestDirector2(); - EXPECT_EQ(mSysMan->RegisterDirector(*director2, trManager::DirectorPriority::NORMAL), true); - - //Should have not received any messages yet - EXPECT_EQ(director->GetTestMessageNum(), 0); - - //Sends a test message - EXPECT_EQ(director2->SendTestMessage(), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //We should have one director in the system of this type - EXPECT_EQ(TestDirector2::GetInstCount(), 1); - - //Check how many messages we have - EXPECT_EQ(director->GetTestMessageNum(), 1); - - //Sends a test message - EXPECT_EQ(director2->SendTestMessage(), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check how many messages we have - EXPECT_EQ(director->GetTestMessageNum(), 2); - - //Sends a test message - EXPECT_EQ(director2->SendTestMessage(), true); - EXPECT_EQ(director2->SendTestMessage(), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //Check how many messages we have - EXPECT_EQ(director->GetTestMessageNum(), 4); - - //Unregister the director. - EXPECT_EQ(mSysMan->UnregisterDirector(*director2.Release()), true); - EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); - - //Advance System Manager one frame at a time - mSysDirector->RunOnce(); - - //We should have no director2 in the system of this type - EXPECT_EQ(TestDirector2::GetInstCount(), 0); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "DirectorTests.h" + +#include "TestDirector1.h" +#include "TestDirector2.h" + +#include + +#include +#include +#include + +#include + +////////////////////////////////////////////////////////////////////////// +DirectorTests::DirectorTests() +: mSysMan(&trManager::SystemManager::GetInstance()) //Create an instance of the System Manager +, mSysDirector(new trCore::SystemDirector()) //Create and register the System Director +{ + //We want the System Director to get and handle all messages before any other Director. + mSysMan->RegisterDirector(*mSysDirector, trManager::DirectorPriority::HIGHEST); +} + +////////////////////////////////////////////////////////////////////////// +DirectorTests::~DirectorTests() +{ + //Create a System Control Shutdown message + trBase::SmrtPtr msg = new trCore::MessageSystemControl(NULL, trCore::SystemControls::SHUT_DOWN); + + //Send message + mSysMan->SendMessage(*msg); + + //Remove all Directors from the system + mSysMan->UnregisterAllDirectors(); + + //Advance System Manager one frame + mSysDirector->RunOnce(); +} + +/** + * @fn TEST_F(DirectorTest, AddRemoveDirector) + * + * @brief Tests the adding and removal of directors + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, AddRemoveDirector) +{ + //Make sure we have no instances of this director + EXPECT_EQ(TestDirector2::GetInstCount(), 0); + + //Add a Director to the system + trBase::SmrtPtr director = new TestDirector2(); + mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //We should have one director in the system of this type + EXPECT_EQ(TestDirector2::GetInstCount(), 1); + + //Unregister the director. + EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //We should have no director2 in the system of this type + EXPECT_EQ(TestDirector2::GetInstCount(), 0); +} + +/** + * @fn TEST_F(DirectorTest, TimeScale) + * + * @brief Tests the change of time scale. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, TimeScale) +{ + //Check that the time is running at normal rate + EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 1.0); + + //Send a message to change time scale + trBase::SmrtPtr msg = new trCore::MessageSystemControl(new trBase::UniqueId(), trCore::SystemControls::SET_TIME_SCALE, 20.69); + mSysMan->SendMessage(*msg); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check that the time scale has changed + EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 20.69); + + //Send a message to change time scale + msg = new trCore::MessageSystemControl(new trBase::UniqueId(), trCore::SystemControls::SET_TIME_SCALE, 1.0); + mSysMan->SendMessage(*msg); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check that the time is running at normal rate + EXPECT_EQ(mSysDirector->GetTimeStructure().timeScale, 1.0); +} + +/** + * @fn TEST_F(DirectorTest, TickMessage) + * + * @brief Tests reception of the Tick message + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, TickMessage) +{ + //Add a Director to the system + trBase::SmrtPtr director = new TestDirector1(); + EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); + + //Check for the number of tick messages + EXPECT_EQ(director->GetTickMsgNumber(), 0); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check for the number of tick messages + EXPECT_EQ(director->GetTickMsgNumber(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check for the number of tick messages + EXPECT_EQ(director->GetTickMsgNumber(), 2); + + //Unregister the director. + EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); +} + +/** + * @fn TEST_F(DirectorTest, SystemEventMsg) + * + * @brief Tests the System Event Message and its content. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, SystemEventMsg) +{ + //Add a Director to the system + trBase::SmrtPtr director = new TestDirector1(); + EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 0); + EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 0); + EXPECT_EQ(director->GetPreFrameEventMsgNum(), 0); + EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 0); + EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 0); + EXPECT_EQ(director->GetFrameEventMsgNum(), 0); + EXPECT_EQ(director->GetPostFrameEventMsgNum(), 0); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 1); + EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 1); + EXPECT_EQ(director->GetPreFrameEventMsgNum(), 1); + EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 1); + EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 1); + EXPECT_EQ(director->GetFrameEventMsgNum(), 1); + EXPECT_EQ(director->GetPostFrameEventMsgNum(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + mSysDirector->RunOnce(); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalEventMsgNum(), 3); + EXPECT_EQ(director->GetPostEventTraversalEventMsgNum(), 3); + EXPECT_EQ(director->GetPreFrameEventMsgNum(), 3); + EXPECT_EQ(director->GetCameraSynchEventMsgNum(), 3); + EXPECT_EQ(director->GetFrameSynchEventMsgNum(), 3); + EXPECT_EQ(director->GetFrameEventMsgNum(), 3); + EXPECT_EQ(director->GetPostFrameEventMsgNum(), 3); + + //Unregister the director. + EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); +} + +/** + * @fn TEST_F(DirectorTest, FrameEventMsg) + * + * @brief Tests the individual messages of the main frame loop + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, FrameEventMsg) +{ + //Add a Director to the system + trBase::SmrtPtr director = new TestDirector1(); + EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalMsgNum(), 0); + EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 0); + EXPECT_EQ(director->GetCameraSynchMsgNum(), 0); + EXPECT_EQ(director->GetFrameSynchMsgNum(), 0); + EXPECT_EQ(director->GetFrameMsgNum(), 0); + EXPECT_EQ(director->GetPostFrameMsgNum(), 0); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalMsgNum(), 1); + EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 1); + EXPECT_EQ(director->GetCameraSynchMsgNum(), 1); + EXPECT_EQ(director->GetFrameSynchMsgNum(), 1); + EXPECT_EQ(director->GetFrameMsgNum(), 1); + EXPECT_EQ(director->GetPostFrameMsgNum(), 1); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + mSysDirector->RunOnce(); + + //Check the number of frame events received. + EXPECT_EQ(director->GetEventTraversalMsgNum(), 3); + EXPECT_EQ(director->GetPostEventTraversalMsgNum(), 3); + EXPECT_EQ(director->GetCameraSynchMsgNum(), 3); + EXPECT_EQ(director->GetFrameSynchMsgNum(), 3); + EXPECT_EQ(director->GetFrameMsgNum(), 3); + EXPECT_EQ(director->GetPostFrameMsgNum(), 3); + + //Unregister the director. + EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); +} + +/** + * @fn TEST_F(DirectorTest, SendReceiveMsg) + * + * @brief Test the sending and receiving of messages + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + */ +TEST_F(DirectorTests, SendReceiveMsg) +{ + //Add a Directors to the system + trBase::SmrtPtr director = new TestDirector1(); + EXPECT_EQ(mSysMan->RegisterDirector(*director, trManager::DirectorPriority::NORMAL), true); + trBase::SmrtPtr director2 = new TestDirector2(); + EXPECT_EQ(mSysMan->RegisterDirector(*director2, trManager::DirectorPriority::NORMAL), true); + + //Should have not received any messages yet + EXPECT_EQ(director->GetTestMessageNum(), 0); + + //Sends a test message + EXPECT_EQ(director2->SendTestMessage(), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //We should have one director in the system of this type + EXPECT_EQ(TestDirector2::GetInstCount(), 1); + + //Check how many messages we have + EXPECT_EQ(director->GetTestMessageNum(), 1); + + //Sends a test message + EXPECT_EQ(director2->SendTestMessage(), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check how many messages we have + EXPECT_EQ(director->GetTestMessageNum(), 2); + + //Sends a test message + EXPECT_EQ(director2->SendTestMessage(), true); + EXPECT_EQ(director2->SendTestMessage(), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //Check how many messages we have + EXPECT_EQ(director->GetTestMessageNum(), 4); + + //Unregister the director. + EXPECT_EQ(mSysMan->UnregisterDirector(*director2.Release()), true); + EXPECT_EQ(mSysMan->UnregisterDirector(*director.Release()), true); + + //Advance System Manager one frame at a time + mSysDirector->RunOnce(); + + //We should have no director2 in the system of this type + EXPECT_EQ(TestDirector2::GetInstCount(), 0); } \ No newline at end of file diff --git a/Tests/TrManager/DirectorTests.h b/Tests/TrManager/DirectorTests.h index d8b5154..862e239 100644 --- a/Tests/TrManager/DirectorTests.h +++ b/Tests/TrManager/DirectorTests.h @@ -1,56 +1,56 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include - -#include -#include -#include - -/** - * @class DirectorTests - * - * @brief Sets up the unit test environment for Director classes. - */ -class DirectorTests : public ::testing::Test -{ -public: - - /** @brief Manager pointer for system. */ - trBase::SmrtPtr mSysMan; - - /** @brief The system director pointer. */ - trBase::SmrtPtr mSysDirector; - - /** - * @fn public::DirectorTests(); - * - * @brief Default constructor. - */ - DirectorTests(); - - /** - * @fn public::~DirectorTests(); - * - * @brief Destructor. - */ - ~DirectorTests(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include + +#include +#include +#include + +/** + * @class DirectorTests + * + * @brief Sets up the unit test environment for Director classes. + */ +class DirectorTests : public ::testing::Test +{ +public: + + /** @brief Manager pointer for system. */ + trBase::SmrtPtr mSysMan; + + /** @brief The system director pointer. */ + trBase::SmrtPtr mSysDirector; + + /** + * @fn public::DirectorTests(); + * + * @brief Default constructor. + */ + DirectorTests(); + + /** + * @fn public::~DirectorTests(); + * + * @brief Destructor. + */ + ~DirectorTests(); }; \ No newline at end of file diff --git a/Tests/TrManager/TestActor1.cpp b/Tests/TrManager/TestActor1.cpp index 2275f5c..cbc3509 100644 --- a/Tests/TrManager/TestActor1.cpp +++ b/Tests/TrManager/TestActor1.cpp @@ -1,133 +1,131 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor1.h" -#include "TestActor2.h" -#include "TestMessage.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//#include - -const trUtil::RefStr TestActor1::CLASS_TYPE("TestActor1"); - -const trUtil::RefStr TestActor1::ON_ENTITY_REGISTERED_INVOKABLE("OnEntityRegistered"); -const trUtil::RefStr TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE("OnEntityUnregistered"); - -int TestActor1::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActor1::TestActor1(const std::string& name) : BaseClass(name) -{ - ++mInstCount; - - //NULL the actor ID - mActor2Id = new trBase::UniqueId(false); - - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestActor1::~TestActor1() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_REGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityRegistered, this))); - AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityUnregistered, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnTick(const trManager::MessageBase& msg) -{ - ++mTickMsgCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg) -{ - const trManager::MessageEntityRegistered* entMsg = static_cast(&msg); - - if (entMsg->GetEntityType() == TestActor2::CLASS_TYPE) - { - //Save the actors ID for later use - mActor2Id = entMsg->GetAboutActorID(); - } -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg) -{ - const trManager::MessageEntityRegistered* msgPtr = static_cast(&msg); - - if (msgPtr->GetEntityType() == TestActor2::CLASS_TYPE) - { - //NULL the ID - mActor2Id = new trBase::UniqueId(false); - } -} - -////////////////////////////////////////////////////////////////////////// -void TestActor1::OnAddedToSysMan() -{ - BaseClass::OnAddedToSysMan(); - - //Register for messages - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); - RegisterForMessage(trManager::MessageEntityRegistered::MESSAGE_TYPE, ON_ENTITY_REGISTERED_INVOKABLE); - RegisterForMessage(trManager::MessageEntityUnregistered::MESSAGE_TYPE, ON_ENTITY_UNREGISTERED_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor1::GetInstCount() -{ - return mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -bool TestActor1::SendTestMessage() -{ - if (!mActor2Id.IsNull()) - { - return SendMessage(*new TestMessage(&GetUUID(), &mActor2Id)); - } - else - { - return false; - } -} - -////////////////////////////////////////////////////////////////////////// -int TestActor1::GetTickMsgNum() -{ - return mTickMsgCount; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor1.h" +#include "TestActor2.h" +#include "TestMessage.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include + +const trUtil::RefStr TestActor1::CLASS_TYPE("TestActor1"); + +const trUtil::RefStr TestActor1::ON_ENTITY_REGISTERED_INVOKABLE("OnEntityRegistered"); +const trUtil::RefStr TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE("OnEntityUnregistered"); + +int TestActor1::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActor1::TestActor1(const std::string& name) : BaseClass(name) +, mActor2Id(new trBase::UniqueId(false)) //NULL the actor ID +{ + ++mInstCount; + + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestActor1::~TestActor1() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_REGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityRegistered, this))); + AddInvokable(*new trManager::Invokable(TestActor1::ON_ENTITY_UNREGISTERED_INVOKABLE, trUtil::MakeFunctor(&TestActor1::OnEntityUnregistered, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnTick(const trManager::MessageBase& /*msg*/) +{ + ++mTickMsgCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg) +{ + const trManager::MessageEntityRegistered* entMsg = static_cast(&msg); + + if (entMsg->GetEntityType() == TestActor2::CLASS_TYPE) + { + //Save the actors ID for later use + mActor2Id = entMsg->GetAboutActorID(); + } +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg) +{ + const trManager::MessageEntityRegistered* msgPtr = static_cast(&msg); + + if (msgPtr->GetEntityType() == TestActor2::CLASS_TYPE) + { + //NULL the ID + mActor2Id = new trBase::UniqueId(false); + } +} + +////////////////////////////////////////////////////////////////////////// +void TestActor1::OnAddedToSysMan() +{ + BaseClass::OnAddedToSysMan(); + + //Register for messages + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); + RegisterForMessage(trManager::MessageEntityRegistered::MESSAGE_TYPE, ON_ENTITY_REGISTERED_INVOKABLE); + RegisterForMessage(trManager::MessageEntityUnregistered::MESSAGE_TYPE, ON_ENTITY_UNREGISTERED_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor1::GetInstCount() +{ + return mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +bool TestActor1::SendTestMessage() +{ + if (!mActor2Id.IsNull()) + { + return SendMessage(*new TestMessage(&GetUUID(), &mActor2Id)); + } + else + { + return false; + } +} + +////////////////////////////////////////////////////////////////////////// +int TestActor1::GetTickMsgNum() +{ + return mTickMsgCount; +} diff --git a/Tests/TrManager/TestActor1.h b/Tests/TrManager/TestActor1.h index 09df7a6..bdbd22a 100644 --- a/Tests/TrManager/TestActor1.h +++ b/Tests/TrManager/TestActor1.h @@ -1,142 +1,142 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor1 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_ENTITY_REGISTERED_INVOKABLE; /// Invokable for Entity Registered messages - const static trUtil::RefStr ON_ENTITY_UNREGISTERED_INVOKABLE; /// Invokable for Entity Registered messages - - /** - * @fn TestActor1::TestActor1(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor1(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor1::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActor1::BuildInvokables(); - * - * @brief Registers the message invokables. - */ - virtual void BuildInvokables() override; - - /** - * @fn virtual void TestActor1::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg); - * - * @brief Executes the reception of the Entity Registered Message. - * - * @param msg The message. - */ - virtual void OnEntityRegistered(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg); - * - * @brief Executes the reception of the Entity Unregistered Message. - * - * @param msg The message. - */ - virtual void OnEntityUnregistered(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor1::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActor1::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - - /** - * @fn virtual bool TestActor1::SendTestMessage(); - * - * @brief Sends a test message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendTestMessage(); - - /** - * @fn virtual int TestActor1::GetTickMsgNum() protected: static int mInstCount; - * - * @brief Gets the number of tick messages this entity received so far. - * - * @return The tick message number. - */ - virtual int GetTickMsgNum(); - -protected: - - static int mInstCount; - - /** - * @fn TestActor1::~TestActor1(); - * - * @brief Destructor. - */ - ~TestActor1(); - -private: - - trBase::UniqueId mActor2Id; - int mTickMsgCount = 0; - -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor1 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_ENTITY_REGISTERED_INVOKABLE; /// Invokable for Entity Registered messages + const static trUtil::RefStr ON_ENTITY_UNREGISTERED_INVOKABLE; /// Invokable for Entity Registered messages + + /** + * @fn TestActor1::TestActor1(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor1(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor1::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActor1::BuildInvokables(); + * + * @brief Registers the message invokables. + */ + virtual void BuildInvokables() override; + + /** + * @fn virtual void TestActor1::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnEntityRegistered(const trManager::MessageBase& msg); + * + * @brief Executes the reception of the Entity Registered Message. + * + * @param msg The message. + */ + virtual void OnEntityRegistered(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnEntityUnregistered(const trManager::MessageBase& msg); + * + * @brief Executes the reception of the Entity Unregistered Message. + * + * @param msg The message. + */ + virtual void OnEntityUnregistered(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor1::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActor1::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + + /** + * @fn virtual bool TestActor1::SendTestMessage(); + * + * @brief Sends a test message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendTestMessage(); + + /** + * @fn virtual int TestActor1::GetTickMsgNum() protected: static int mInstCount; + * + * @brief Gets the number of tick messages this entity received so far. + * + * @return The tick message number. + */ + virtual int GetTickMsgNum(); + +protected: + + static int mInstCount; + + /** + * @fn TestActor1::~TestActor1(); + * + * @brief Destructor. + */ + ~TestActor1(); + +private: + + trBase::UniqueId mActor2Id; + int mTickMsgCount = 0; + +}; + diff --git a/Tests/TrManager/TestActor2.cpp b/Tests/TrManager/TestActor2.cpp index d961751..36f1256 100644 --- a/Tests/TrManager/TestActor2.cpp +++ b/Tests/TrManager/TestActor2.cpp @@ -1,84 +1,84 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor2.h" -#include "TestActor1.h" -#include "TestMessage.h" - -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestActor2::CLASS_TYPE("TestActor2"); - -const trUtil::RefStr TestActor2::ON_TEST_INVOKABLE("OnTest"); - -int TestActor2::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActor2::TestActor2(const std::string& name) : BaseClass(name) -{ - BuildInvokables(); - ++mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -TestActor2::~TestActor2() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor2::ON_TEST_INVOKABLE, trUtil::MakeFunctor(&TestActor2::OnTest, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnTick(const trManager::MessageBase& msg) -{} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnTest(const trManager::MessageBase & msg) -{ - ++mTestMsgCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor2::OnAddedToSysMan() -{ - RegisterForMessage(TestMessage::MESSAGE_TYPE, ON_TEST_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor2::GetInstCount() -{ - return mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -int TestActor2::GetTestMsgCount() -{ - return mTestMsgCount; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor2.h" +#include "TestActor1.h" +#include "TestMessage.h" + +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestActor2::CLASS_TYPE("TestActor2"); + +const trUtil::RefStr TestActor2::ON_TEST_INVOKABLE("OnTest"); + +int TestActor2::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActor2::TestActor2(const std::string& name) : BaseClass(name) +{ + BuildInvokables(); + ++mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +TestActor2::~TestActor2() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor2::ON_TEST_INVOKABLE, trUtil::MakeFunctor(&TestActor2::OnTest, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnTick(const trManager::MessageBase& /*msg*/) +{} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnTest(const trManager::MessageBase & /*msg*/) +{ + ++mTestMsgCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor2::OnAddedToSysMan() +{ + RegisterForMessage(TestMessage::MESSAGE_TYPE, ON_TEST_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor2::GetInstCount() +{ + return mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +int TestActor2::GetTestMsgCount() +{ + return mTestMsgCount; +} diff --git a/Tests/TrManager/TestActor2.h b/Tests/TrManager/TestActor2.h index 2cca4e3..9fc06bd 100644 --- a/Tests/TrManager/TestActor2.h +++ b/Tests/TrManager/TestActor2.h @@ -1,121 +1,121 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor2 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_TEST_INVOKABLE; /// Invokable for Test messages - - /** - * @fn TestActor2::TestActor2(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor2(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor2::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestActor2::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActor2::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor2::OnTest(const trManager::MessageBase& msg) virtual void OnAddedToSysMan() override; - * - * @brief Executes on Reception of the Test Message. - * - * @param msg The message. - */ - virtual void OnTest(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor2::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActor2::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - - /** - * @fn virtual int TestActor2::GetTestMsgCount(); - * - * @brief Gets the number of test messages that were received by this class. - * - * @return The test message count. - */ - virtual int GetTestMsgCount(); - -protected: - - /** - * @fn TestActor2::~TestActor2(); - * - * @brief Destructor. - */ - ~TestActor2(); - - static int mInstCount; - -private: - - int mTestMsgCount = 0; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor2 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_TEST_INVOKABLE; /// Invokable for Test messages + + /** + * @fn TestActor2::TestActor2(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor2(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor2::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestActor2::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActor2::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor2::OnTest(const trManager::MessageBase& msg) virtual void OnAddedToSysMan() override; + * + * @brief Executes on Reception of the Test Message. + * + * @param msg The message. + */ + virtual void OnTest(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor2::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActor2::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + + /** + * @fn virtual int TestActor2::GetTestMsgCount(); + * + * @brief Gets the number of test messages that were received by this class. + * + * @return The test message count. + */ + virtual int GetTestMsgCount(); + +protected: + + /** + * @fn TestActor2::~TestActor2(); + * + * @brief Destructor. + */ + ~TestActor2(); + + static int mInstCount; + +private: + + int mTestMsgCount = 0; +}; + diff --git a/Tests/TrManager/TestActor3.cpp b/Tests/TrManager/TestActor3.cpp index 15fb1b2..174ca47 100644 --- a/Tests/TrManager/TestActor3.cpp +++ b/Tests/TrManager/TestActor3.cpp @@ -1,86 +1,86 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestActor3.h" -#include "TestActor2.h" -#include "TestMessage.h" - -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestActor3::CLASS_TYPE("TestActor3"); - -const trUtil::RefStr TestActor3::ON_TEST_ACTOR_2_INVOKABLE("OnTestActor2"); - -int TestActor3::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestActor3::TestActor3(const std::string& name) : BaseClass(name) -{ - ++mInstCount; - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor3::GetTestMsgCount() -{ - return mTestMsgCount; -} - -////////////////////////////////////////////////////////////////////////// -TestActor3::~TestActor3() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestActor3::ON_TEST_ACTOR_2_INVOKABLE, trUtil::MakeFunctor(&TestActor3::AboutTestActor2, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::OnTick(const trManager::MessageBase& msg) -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::AboutTestActor2(const trManager::MessageBase& msg) -{ - ++mTestMsgCount; -} - -////////////////////////////////////////////////////////////////////////// -void TestActor3::OnAddedToSysMan() -{ - //Register for Tick Message - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -int TestActor3::GetInstCount() -{ - return mInstCount; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestActor3.h" +#include "TestActor2.h" +#include "TestMessage.h" + +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestActor3::CLASS_TYPE("TestActor3"); + +const trUtil::RefStr TestActor3::ON_TEST_ACTOR_2_INVOKABLE("OnTestActor2"); + +int TestActor3::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestActor3::TestActor3(const std::string& name) : BaseClass(name) +{ + ++mInstCount; + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor3::GetTestMsgCount() +{ + return mTestMsgCount; +} + +////////////////////////////////////////////////////////////////////////// +TestActor3::~TestActor3() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestActor3::ON_TEST_ACTOR_2_INVOKABLE, trUtil::MakeFunctor(&TestActor3::AboutTestActor2, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::OnTick(const trManager::MessageBase& /*msg*/) +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::AboutTestActor2(const trManager::MessageBase& /*msg*/) +{ + ++mTestMsgCount; +} + +////////////////////////////////////////////////////////////////////////// +void TestActor3::OnAddedToSysMan() +{ + //Register for Tick Message + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +int TestActor3::GetInstCount() +{ + return mInstCount; } \ No newline at end of file diff --git a/Tests/TrManager/TestActor3.h b/Tests/TrManager/TestActor3.h index d8035b8..9fb26da 100644 --- a/Tests/TrManager/TestActor3.h +++ b/Tests/TrManager/TestActor3.h @@ -1,119 +1,119 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestActor3 : public trManager::ActorBase -{ -public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 - - /** - * @fn TestActor3::TestActor3(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestActor3(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestActor3::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE; } - - /** - * @fn virtual void TestActor3::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void TestActor3::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor3::AboutTestActor2(const trManager::MessageBase& msg); - * - * @brief Handles intercepted messages that are going to TestActor2. - * - * @param msg The message. - */ - virtual void AboutTestActor2(const trManager::MessageBase& msg); - - /** - * @fn virtual void TestActor3::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn static int TestActor3::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - - /** - * @fn virtual int TestActor3::GetTestMsgCount(); - * - * @brief Gets the number of test messages that were received by this class. - * - * @return The test message count. - */ - virtual int GetTestMsgCount(); - -protected: - - /** - * @fn TestActor3::~TestActor3(); - * - * @brief Destructor. - */ - ~TestActor3(); - - static int mInstCount; - - int mTestMsgCount = 0; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestActor3 : public trManager::ActorBase +{ +public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_TEST_ACTOR_2_INVOKABLE; /// Invokable for messages going to TestActor2 + + /** + * @fn TestActor3::TestActor3(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestActor3(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestActor3::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE; } + + /** + * @fn virtual void TestActor3::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void TestActor3::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor3::AboutTestActor2(const trManager::MessageBase& msg); + * + * @brief Handles intercepted messages that are going to TestActor2. + * + * @param msg The message. + */ + virtual void AboutTestActor2(const trManager::MessageBase& msg); + + /** + * @fn virtual void TestActor3::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn static int TestActor3::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + + /** + * @fn virtual int TestActor3::GetTestMsgCount(); + * + * @brief Gets the number of test messages that were received by this class. + * + * @return The test message count. + */ + virtual int GetTestMsgCount(); + +protected: + + /** + * @fn TestActor3::~TestActor3(); + * + * @brief Destructor. + */ + ~TestActor3(); + + static int mInstCount; + + int mTestMsgCount = 0; +}; + diff --git a/Tests/TrManager/TestDirector1.cpp b/Tests/TrManager/TestDirector1.cpp index 7a0abcd..a85c8bb 100644 --- a/Tests/TrManager/TestDirector1.cpp +++ b/Tests/TrManager/TestDirector1.cpp @@ -1,242 +1,242 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestDirector1.h" -#include "TestDirector2.h" -#include "TestMessage.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -const trUtil::RefStr TestDirector1::CLASS_TYPE("TestDirector1"); - -const trUtil::RefStr TestDirector1::ON_TEST_MESSAGE_INVOKABLE = trUtil::RefStr("OnTestMessageInvokable"); - -////////////////////////////////////////////////////////////////////////// -TestDirector1::TestDirector1(const std::string& name) : BaseClass(name) -{ - BuildInvokables(); -} - -////////////////////////////////////////////////////////////////////////// -TestDirector1::~TestDirector1() -{ -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::BuildInvokables() -{ - AddInvokable(*new trManager::Invokable(TestDirector1::ON_TEST_MESSAGE_INVOKABLE, trUtil::MakeFunctor(&TestDirector1::OnTestMessage, this))); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::OnMessage(const trManager::MessageBase& msg) -{ - if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) - { - ++mEventTraversal; - } - else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) - { - ++mPostEventTraversal; - } - else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) - { - ++mCameraSynch; - } - else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) - { - ++mFrameSynch; - } - else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) - { - ++mFrame; - } - else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) - { - ++mPostFrame; - } - else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) - { - HandleSystemEvent(msg); - } -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::OnTick(const trManager::MessageBase &msg) -{ - ++mTickMsg; -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::OnAddedToSysMan() -{ - RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); - RegisterForMessage(TestMessage::MESSAGE_TYPE, ON_TEST_MESSAGE_INVOKABLE); -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::OnTestMessage(const trManager::MessageBase &msg) -{ - ++mTestMessage; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetTestMessageNum() -{ - return mTestMessage; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetTickMsgNumber() -{ - return mTickMsg; -} - -////////////////////////////////////////////////////////////////////////// -void TestDirector1::HandleSystemEvent(const trManager::MessageBase& msg) -{ - //Cast the message into its real type - const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); - - if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) - { - ++mEventTraversalEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) - { - ++mPostEventTraversalEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) - { - ++mPreFrameEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) - { - ++mCameraSynchEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) - { - ++mFrameSynchEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) - { - ++mFrameEvent; - } - else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) - { - ++mPostFrameEvent; - } -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetEventTraversalEventMsgNum() -{ - return mEventTraversalEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetPostEventTraversalEventMsgNum() -{ - return mPostEventTraversalEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetPreFrameEventMsgNum() -{ - return mPreFrameEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetCameraSynchEventMsgNum() -{ - return mCameraSynchEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetFrameSynchEventMsgNum() -{ - return mFrameSynchEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetFrameEventMsgNum() -{ - return mFrameEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetPostFrameEventMsgNum() -{ - return mPostFrameEvent; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetEventTraversalMsgNum() -{ - return mEventTraversal; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetPostEventTraversalMsgNum() -{ - return mPostEventTraversal; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetCameraSynchMsgNum() -{ - return mCameraSynch; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetFrameSynchMsgNum() -{ - return mFrameSynch; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetFrameMsgNum() -{ - return mFrame; -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector1::GetPostFrameMsgNum() -{ - return mPostFrame; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestDirector1.h" +#include "TestDirector2.h" +#include "TestMessage.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +const trUtil::RefStr TestDirector1::CLASS_TYPE("TestDirector1"); + +const trUtil::RefStr TestDirector1::ON_TEST_MESSAGE_INVOKABLE = trUtil::RefStr("OnTestMessageInvokable"); + +////////////////////////////////////////////////////////////////////////// +TestDirector1::TestDirector1(const std::string& name) : BaseClass(name) +{ + BuildInvokables(); +} + +////////////////////////////////////////////////////////////////////////// +TestDirector1::~TestDirector1() +{ +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::BuildInvokables() +{ + AddInvokable(*new trManager::Invokable(TestDirector1::ON_TEST_MESSAGE_INVOKABLE, trUtil::MakeFunctor(&TestDirector1::OnTestMessage, this))); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::OnMessage(const trManager::MessageBase& msg) +{ + if (msg.GetMessageType() == trCore::MessageEventTraversal::MESSAGE_TYPE) + { + ++mEventTraversal; + } + else if (msg.GetMessageType() == trCore::MessagePostEventTraversal::MESSAGE_TYPE) + { + ++mPostEventTraversal; + } + else if (msg.GetMessageType() == trCore::MessageCameraSynch::MESSAGE_TYPE) + { + ++mCameraSynch; + } + else if (msg.GetMessageType() == trCore::MessageFrameSynch::MESSAGE_TYPE) + { + ++mFrameSynch; + } + else if (msg.GetMessageType() == trCore::MessageFrame::MESSAGE_TYPE) + { + ++mFrame; + } + else if (msg.GetMessageType() == trCore::MessagePostFrame::MESSAGE_TYPE) + { + ++mPostFrame; + } + else if (msg.GetMessageType() == trCore::MessageSystemEvent::MESSAGE_TYPE) + { + HandleSystemEvent(msg); + } +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::OnTick(const trManager::MessageBase & /*msg*/) +{ + ++mTickMsg; +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::OnAddedToSysMan() +{ + RegisterForMessage(trManager::MessageTick::MESSAGE_TYPE, ON_TICK_INVOKABLE); + RegisterForMessage(TestMessage::MESSAGE_TYPE, ON_TEST_MESSAGE_INVOKABLE); +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::OnTestMessage(const trManager::MessageBase & /*msg*/) +{ + ++mTestMessage; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetTestMessageNum() +{ + return mTestMessage; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetTickMsgNumber() +{ + return mTickMsg; +} + +////////////////////////////////////////////////////////////////////////// +void TestDirector1::HandleSystemEvent(const trManager::MessageBase& msg) +{ + //Cast the message into its real type + const trCore::MessageSystemEvent* msgPtr = static_cast(&msg); + + if (msgPtr->GetSysEventType() == trCore::SystemEvents::EVENT_TRAVERSAL) + { + ++mEventTraversalEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_EVENT_TRAVERSAL) + { + ++mPostEventTraversalEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::PRE_FRAME) + { + ++mPreFrameEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::CAMERA_SYNCH) + { + ++mCameraSynchEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME_SYNCH) + { + ++mFrameSynchEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::FRAME) + { + ++mFrameEvent; + } + else if (msgPtr->GetSysEventType() == trCore::SystemEvents::POST_FRAME) + { + ++mPostFrameEvent; + } +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetEventTraversalEventMsgNum() +{ + return mEventTraversalEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetPostEventTraversalEventMsgNum() +{ + return mPostEventTraversalEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetPreFrameEventMsgNum() +{ + return mPreFrameEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetCameraSynchEventMsgNum() +{ + return mCameraSynchEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetFrameSynchEventMsgNum() +{ + return mFrameSynchEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetFrameEventMsgNum() +{ + return mFrameEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetPostFrameEventMsgNum() +{ + return mPostFrameEvent; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetEventTraversalMsgNum() +{ + return mEventTraversal; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetPostEventTraversalMsgNum() +{ + return mPostEventTraversal; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetCameraSynchMsgNum() +{ + return mCameraSynch; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetFrameSynchMsgNum() +{ + return mFrameSynch; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetFrameMsgNum() +{ + return mFrame; +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector1::GetPostFrameMsgNum() +{ + return mPostFrame; } \ No newline at end of file diff --git a/Tests/TrManager/TestDirector1.h b/Tests/TrManager/TestDirector1.h index e9de9d9..02f3252 100644 --- a/Tests/TrManager/TestDirector1.h +++ b/Tests/TrManager/TestDirector1.h @@ -1,272 +1,272 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -#include - -class TestDirector1 : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class. - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons. - - const static trUtil::RefStr ON_TEST_MESSAGE_INVOKABLE; - - /** - * @fn TestDirector1::TestDirector1(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector1(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector1::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual void TestDirector1::BuildInvokables() override; - * - * @brief Builds the invokables. - */ - virtual void BuildInvokables() override; - - /** - * @fn virtual void TestDirector1::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase &msg); - - /** - * @fn virtual void TestDirector1::OnTick(const trManager::MessageBase& msg); - * - * @brief Executes on Reception of the Tick Message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase &msg); - - /** - * @fn virtual void TestDirector1::OnAddedToSysMan() override; - * - * @brief Runs when the director is added to system manager. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn virtual void TestDirector1::OnTestMessage(const trManager::MessageBase& msg); - * - * @brief Executes the test message action. - * - * @param msg The message. - */ - virtual void OnTestMessage(const trManager::MessageBase &msg); - - /** - * @fn virtual int TestDirector1::GetTestMessageNum(); - * - * @brief Gets the number of received test messages. - * - * @return The test message number. - */ - virtual int GetTestMessageNum(); - - /** - * @fn virtual int TestDirector1::GetTickMsgNumber(); - * - * @brief Gets the number of messages this class received. - * - * - * @return The tick message number. - */ - virtual int GetTickMsgNumber(); - - /** - * @fn virtual int TestDirector1::GetEventTraversalEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The event traversal message number. - */ - virtual int GetEventTraversalEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetPostEventTraversalEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The post event traversal message number. - */ - virtual int GetPostEventTraversalEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetPreFrameEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The pre frame message number. - */ - virtual int GetPreFrameEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetCameraSynchEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The camera synchronise message number. - */ - virtual int GetCameraSynchEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetFrameSynchEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The frame synchronise message number. - */ - virtual int GetFrameSynchEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetFrameEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The frame message number. - */ - virtual int GetFrameEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetPostFrameEventMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The post frame message number. - */ - virtual int GetPostFrameEventMsgNum(); - - /** - * @fn virtual int TestDirector1::GetEventTraversalMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The event traversal message number. - */ - virtual int GetEventTraversalMsgNum(); - - /** - * @fn virtual int TestDirector1::GetPostEventTraversalMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The post event traversal message number. - */ - virtual int GetPostEventTraversalMsgNum(); - - /** - * @fn virtual int TestDirector1::GetCameraSynchMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The camera synchronise message number. - */ - virtual int GetCameraSynchMsgNum(); - - /** - * @fn virtual int TestDirector1::GetFrameSynchMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The frame synchronise message number. - */ - virtual int GetFrameSynchMsgNum(); - - /** - * @fn virtual int TestDirector1::GetFrameMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The frame message number. - */ - virtual int GetFrameMsgNum(); - - /** - * @fn virtual int TestDirector1::GetPostFrameMsgNum(); - * - * @brief Gets the number of messages this class received. - * - * @return The post frame message number. - */ - virtual int GetPostFrameMsgNum(); - -protected: - - /** - * @fn TestDirector1::~TestDirector1(); - * - * @brief Destructor. - */ - ~TestDirector1(); - - /** - * @fn virtual void TestDirector1::HandleSystemEvent(const trManager::MessageBase& msg); - * - * @brief Handles the system event described by msg. - * - * @param msg The message. - */ - virtual void HandleSystemEvent(const trManager::MessageBase& msg); - -private: - - int mTickMsg = 0; - - int mEventTraversalEvent = 0; - int mPostEventTraversalEvent = 0; - int mPreFrameEvent = 0; - int mCameraSynchEvent = 0; - int mFrameSynchEvent = 0; - int mFrameEvent = 0; - int mPostFrameEvent = 0; - - int mEventTraversal = 0; - int mPostEventTraversal = 0; - int mCameraSynch = 0; - int mFrameSynch = 0; - int mFrame = 0; - int mPostFrame = 0; - - int mTestMessage = 0; -}; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +#include + +class TestDirector1 : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class. + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons. + + const static trUtil::RefStr ON_TEST_MESSAGE_INVOKABLE; + + /** + * @fn TestDirector1::TestDirector1(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector1(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector1::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual void TestDirector1::BuildInvokables() override; + * + * @brief Builds the invokables. + */ + virtual void BuildInvokables() override; + + /** + * @fn virtual void TestDirector1::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase &msg); + + /** + * @fn virtual void TestDirector1::OnTick(const trManager::MessageBase& msg); + * + * @brief Executes on Reception of the Tick Message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase &msg); + + /** + * @fn virtual void TestDirector1::OnAddedToSysMan() override; + * + * @brief Runs when the director is added to system manager. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn virtual void TestDirector1::OnTestMessage(const trManager::MessageBase& msg); + * + * @brief Executes the test message action. + * + * @param msg The message. + */ + virtual void OnTestMessage(const trManager::MessageBase &msg); + + /** + * @fn virtual int TestDirector1::GetTestMessageNum(); + * + * @brief Gets the number of received test messages. + * + * @return The test message number. + */ + virtual int GetTestMessageNum(); + + /** + * @fn virtual int TestDirector1::GetTickMsgNumber(); + * + * @brief Gets the number of messages this class received. + * + * + * @return The tick message number. + */ + virtual int GetTickMsgNumber(); + + /** + * @fn virtual int TestDirector1::GetEventTraversalEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The event traversal message number. + */ + virtual int GetEventTraversalEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetPostEventTraversalEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The post event traversal message number. + */ + virtual int GetPostEventTraversalEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetPreFrameEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The pre frame message number. + */ + virtual int GetPreFrameEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetCameraSynchEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The camera synchronise message number. + */ + virtual int GetCameraSynchEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetFrameSynchEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The frame synchronise message number. + */ + virtual int GetFrameSynchEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetFrameEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The frame message number. + */ + virtual int GetFrameEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetPostFrameEventMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The post frame message number. + */ + virtual int GetPostFrameEventMsgNum(); + + /** + * @fn virtual int TestDirector1::GetEventTraversalMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The event traversal message number. + */ + virtual int GetEventTraversalMsgNum(); + + /** + * @fn virtual int TestDirector1::GetPostEventTraversalMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The post event traversal message number. + */ + virtual int GetPostEventTraversalMsgNum(); + + /** + * @fn virtual int TestDirector1::GetCameraSynchMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The camera synchronise message number. + */ + virtual int GetCameraSynchMsgNum(); + + /** + * @fn virtual int TestDirector1::GetFrameSynchMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The frame synchronise message number. + */ + virtual int GetFrameSynchMsgNum(); + + /** + * @fn virtual int TestDirector1::GetFrameMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The frame message number. + */ + virtual int GetFrameMsgNum(); + + /** + * @fn virtual int TestDirector1::GetPostFrameMsgNum(); + * + * @brief Gets the number of messages this class received. + * + * @return The post frame message number. + */ + virtual int GetPostFrameMsgNum(); + +protected: + + /** + * @fn TestDirector1::~TestDirector1(); + * + * @brief Destructor. + */ + ~TestDirector1(); + + /** + * @fn virtual void TestDirector1::HandleSystemEvent(const trManager::MessageBase& msg); + * + * @brief Handles the system event described by msg. + * + * @param msg The message. + */ + virtual void HandleSystemEvent(const trManager::MessageBase& msg); + +private: + + int mTickMsg = 0; + + int mEventTraversalEvent = 0; + int mPostEventTraversalEvent = 0; + int mPreFrameEvent = 0; + int mCameraSynchEvent = 0; + int mFrameSynchEvent = 0; + int mFrameEvent = 0; + int mPostFrameEvent = 0; + + int mEventTraversal = 0; + int mPostEventTraversal = 0; + int mCameraSynch = 0; + int mFrameSynch = 0; + int mFrame = 0; + int mPostFrame = 0; + + int mTestMessage = 0; +}; + diff --git a/Tests/TrManager/TestDirector2.cpp b/Tests/TrManager/TestDirector2.cpp index 6f499eb..1211fde 100644 --- a/Tests/TrManager/TestDirector2.cpp +++ b/Tests/TrManager/TestDirector2.cpp @@ -1,51 +1,51 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestDirector2.h" -#include "TestMessage.h" - -const trUtil::RefStr TestDirector2::CLASS_TYPE("TestDirector2"); - -int TestDirector2::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestDirector2::TestDirector2(const std::string& name) : BaseClass(name) -{ - ++mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -TestDirector2::~TestDirector2() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -bool TestDirector2::SendTestMessage() -{ - return SendMessage(*new TestMessage(&GetUUID(), nullptr)); -} - -////////////////////////////////////////////////////////////////////////// -int TestDirector2::GetInstCount() -{ - return mInstCount; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestDirector2.h" +#include "TestMessage.h" + +const trUtil::RefStr TestDirector2::CLASS_TYPE("TestDirector2"); + +int TestDirector2::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestDirector2::TestDirector2(const std::string& name) : BaseClass(name) +{ + ++mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +TestDirector2::~TestDirector2() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +bool TestDirector2::SendTestMessage() +{ + return SendMessage(*new TestMessage(&GetUUID(), nullptr)); +} + +////////////////////////////////////////////////////////////////////////// +int TestDirector2::GetInstCount() +{ + return mInstCount; } \ No newline at end of file diff --git a/Tests/TrManager/TestDirector2.h b/Tests/TrManager/TestDirector2.h index 0177a45..98888a6 100644 --- a/Tests/TrManager/TestDirector2.h +++ b/Tests/TrManager/TestDirector2.h @@ -1,81 +1,81 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include - -#include - -class TestDirector2 : public trManager::DirectorBase -{ -public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn TestDirector2::TestDirector2(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - TestDirector2(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& TestDirector2::GetType() const override - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - /** - * @fn virtual bool TestDirector2::SendTestMessage(); - * - * @brief Sends the test message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendTestMessage(); - - /** - * @fn static int TestDirector2::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - -protected: - - static int mInstCount; - - /** - * @fn TestDirector2::~TestDirector2(); - * - * @brief Destructor. - */ - ~TestDirector2(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include + +#include + +class TestDirector2 : public trManager::DirectorBase +{ +public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn TestDirector2::TestDirector2(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + TestDirector2(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& TestDirector2::GetType() const override + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + /** + * @fn virtual bool TestDirector2::SendTestMessage(); + * + * @brief Sends the test message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendTestMessage(); + + /** + * @fn static int TestDirector2::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + +protected: + + static int mInstCount; + + /** + * @fn TestDirector2::~TestDirector2(); + * + * @brief Destructor. + */ + ~TestDirector2(); }; \ No newline at end of file diff --git a/Tests/TrManager/TestMessage.cpp b/Tests/TrManager/TestMessage.cpp index ad1c1ce..8653138 100644 --- a/Tests/TrManager/TestMessage.cpp +++ b/Tests/TrManager/TestMessage.cpp @@ -1,51 +1,51 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#include "TestMessage.h" - -const trUtil::RefStr TestMessage::MESSAGE_TYPE("trManager::TestMessage"); - -int TestMessage::mInstCount = 0; - -////////////////////////////////////////////////////////////////////////// -TestMessage::TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) - : BaseClass(fromActorID, aboutActorID) -{ - ++mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -TestMessage::~TestMessage() -{ - --mInstCount; -} - -////////////////////////////////////////////////////////////////////////// -const std::string& TestMessage::GetMessageType() const -{ - return MESSAGE_TYPE; -} - -////////////////////////////////////////////////////////////////////////// -int TestMessage::GetInstCount() -{ - return mInstCount; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#include "TestMessage.h" + +const trUtil::RefStr TestMessage::MESSAGE_TYPE("trManager::TestMessage"); + +int TestMessage::mInstCount = 0; + +////////////////////////////////////////////////////////////////////////// +TestMessage::TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID) + : BaseClass(fromActorID, aboutActorID) +{ + ++mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +TestMessage::~TestMessage() +{ + --mInstCount; +} + +////////////////////////////////////////////////////////////////////////// +const std::string& TestMessage::GetMessageType() const +{ + return MESSAGE_TYPE; +} + +////////////////////////////////////////////////////////////////////////// +int TestMessage::GetInstCount() +{ + return mInstCount; +} diff --git a/Tests/TrManager/TestMessage.h b/Tests/TrManager/TestMessage.h index b9a198b..487cea5 100644 --- a/Tests/TrManager/TestMessage.h +++ b/Tests/TrManager/TestMessage.h @@ -1,80 +1,80 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include -#include -#include - -#include - -/** - * @class TestMessage - * - * @brief This is an example of a simple message that is passed between actors. - */ -class TestMessage : public trManager::MessageBase -{ -public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn TestMessage::TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param aboutActorID Identifier for the about actor. - */ - TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); - - /** - * @fn virtual const std::string& TestMessage::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn static int TestMessage::GetInstCount(); - * - * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. - * - * @return The instance count. - */ - static int GetInstCount(); - -protected: - - static int mInstCount; - - /** - * @fn TestMessage::~TestMessage(); - * - * @brief Destructor. - */ - ~TestMessage(); -}; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include +#include +#include + +#include + +/** + * @class TestMessage + * + * @brief This is an example of a simple message that is passed between actors. + */ +class TestMessage : public trManager::MessageBase +{ +public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn TestMessage::TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param aboutActorID Identifier for the about actor. + */ + TestMessage(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID); + + /** + * @fn virtual const std::string& TestMessage::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn static int TestMessage::GetInstCount(); + * + * @brief Gets instance count for this class type. Used for error checking, and Unit Testing. + * + * @return The instance count. + */ + static int GetInstCount(); + +protected: + + static int mInstCount; + + /** + * @fn TestMessage::~TestMessage(); + * + * @brief Destructor. + */ + ~TestMessage(); +}; diff --git a/Tests/TrUtil/LoggingTests.cpp b/Tests/TrUtil/LoggingTests.cpp index ccae6ab..48d4f92 100644 --- a/Tests/TrUtil/LoggingTests.cpp +++ b/Tests/TrUtil/LoggingTests.cpp @@ -21,9 +21,10 @@ #include "LoggingTests.h" +#include #include +#include #include -#include #include #include @@ -35,7 +36,7 @@ LoggingTests::LoggingTests() { mTstChar = "Log Char"; - // Creates the default folders in the User Data folder. + // Creates the default folders in the User Data folder. trUtil::PathUtils::CreateUserDataPathTree(); // Sets the log filename @@ -114,10 +115,10 @@ TEST_F(LoggingTests, LoggingLineTests) { LOG_D("Test Message") mTestData = *trUtil::Logging::Log::GetInstance().GetLastLogData(); - - // This Test is specific to the Line the LOG_D is located on in this file. + + // This Test is specific to the Line the LOG_D is located on in this file. // If the line changes due to code being added or removed, this test needs to be adjusted - EXPECT_EQ(mTestData.line, 115); + EXPECT_EQ(mTestData.line, 116); } /** @@ -153,7 +154,7 @@ TEST_F(LoggingTests, LoggingLevelTests) trUtil::Logging::Log::GetInstance().SetAllLogLevels(trUtil::Logging::LogLevel::LOG_DEBUG); LOG_D("Test Message5") mTestData = *trUtil::Logging::Log::GetInstance().GetLastLogData(); - EXPECT_EQ(mTestData.logLevel, trUtil::Logging::LogLevel::LOG_DEBUG); + EXPECT_EQ(mTestData.logLevel, trUtil::Logging::LogLevel::LOG_DEBUG); } /** @@ -183,5 +184,12 @@ TEST_F(LoggingTests, LoggingMethodTests) { LOG_A("Test Message") mTestData = *trUtil::Logging::Log::GetInstance().GetLastLogData(); + +#if defined (TR_WIN) EXPECT_EQ(mTestData.method, "LoggingTests_LoggingMethodTests_Test::TestBody"); +#elif defined(TR_LINUX) + EXPECT_EQ(mTestData.method, "TestBody"); +#else + EXPECT_EQ(mTestData.method, "TestBody"); //This needs to be tested +#endif } diff --git a/include/trApp/AppBase.h b/include/trApp/AppBase.h index e7caf46..4a8b1bd 100644 --- a/include/trApp/AppBase.h +++ b/include/trApp/AppBase.h @@ -1,94 +1,94 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include "Export.h" - -#include -#include -#include -#include -#include - -namespace trApp -{ - /** - * @class AppBase - * - * @brief An application base from which all other application classes should be derived. - */ - class TR_APP_EXPORT AppBase : public trBase::Base - { - public: - using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn AppBase::AppBase(const std::string& name = CLASS_TYPE); - * - * @brief Default constructor. - * - * @param name (Optional) The name of the class. - */ - AppBase(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& AppBase::GetType() const override; - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - - /** - * @fn virtual void AppBase::Run(); - * - * @brief Starts the application loop. - */ - virtual void Run(); - - /** - * @fn virtual void AppBase::Quit(); - * - * @brief Stops the application loop and exits the application. - */ - virtual void Quit(); - - protected: - - trBase::SmrtPtr mSysMan; - - /** - * @fn AppBase::~AppBase(); - * - * @brief Destructor. - */ - ~AppBase(); - - private: - - - trBase::SmrtPtr mSysDirector; - - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include "Export.h" + +#include +#include +#include +#include +#include + +namespace trApp +{ + /** + * @class AppBase + * + * @brief An application base from which all other application classes should be derived. + */ + class TR_APP_EXPORT AppBase : public trBase::Base + { + public: + using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn AppBase::AppBase(const std::string& name = CLASS_TYPE); + * + * @brief Default constructor. + * + * @param name (Optional) The name of the class. + */ + AppBase(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& AppBase::GetType() const override; + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + + /** + * @fn virtual void AppBase::Run(); + * + * @brief Starts the application loop. + */ + virtual void Run(); + + /** + * @fn virtual void AppBase::Quit(); + * + * @brief Stops the application loop and exits the application. + */ + virtual void Quit(); + + protected: + + trBase::SmrtPtr mSysMan; + + /** + * @fn AppBase::~AppBase(); + * + * @brief Destructor. + */ + ~AppBase(); + + private: + + + trBase::SmrtPtr mSysDirector; + + }; } \ No newline at end of file diff --git a/include/trApp/Export.h b/include/trApp/Export.h index 468e577..feb275b 100644 --- a/include/trApp/Export.h +++ b/include/trApp/Export.h @@ -1,35 +1,35 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) -# ifdef TR_APP_LIBRARY -# define TR_APP_EXPORT __declspec(dllexport) -# else -# define TR_APP_EXPORT __declspec(dllimport) -# endif -#else -# ifdef TR_APP_LIBRARY -# define TR_APP_EXPORT __attribute__ ((visibility("default"))) -# else -# define TR_APP_EXPORT -# endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef TR_APP_LIBRARY +# define TR_APP_EXPORT __declspec(dllexport) +# else +# define TR_APP_EXPORT __declspec(dllimport) +# endif +#else +# ifdef TR_APP_LIBRARY +# define TR_APP_EXPORT __attribute__ ((visibility("default"))) +# else +# define TR_APP_EXPORT +# endif #endif \ No newline at end of file diff --git a/include/trBase/Base.h b/include/trBase/Base.h index 2bd5031..a4a1199 100644 --- a/include/trBase/Base.h +++ b/include/trBase/Base.h @@ -1,125 +1,125 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include - -namespace trBase -{ - - /** - * This is a Base class that carries the Class name and Unique ID of all the derived classes. - */ - class TR_BASE_EXPORT Base : public trBase::SmrtClass - { - public: - - using BaseClass = trBase::SmrtClass; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn Base(const std::string& name = CLASS_TYPE); - * - * @brief ctor. - * - * @param name (Optional) The name. - */ - Base(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& Base::GetType() const override = 0; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override = 0; - - /** - * @fn virtual void Base::SetName(const std::string& name); - * - * @brief Sets this instances name. - * - * @param name The name. - */ - virtual void SetName(const std::string& name); - - /** - * @fn virtual const std::string& Base::GetName(); - * - * @brief Returns this instances name. - * - * @return The name. - */ - virtual const std::string& GetName(); - - /** - * @fn virtual const std::string& Base::GetName() const; - * - * @brief Returns this instances name. - * - * @return The name. - */ - virtual const std::string& GetName() const; - - /** - * @fn virtual void Base::SetUUID(const trBase::UniqueId& id); - * - * @brief Overwrites the default internal UUID with the passed in one. This should be done very - * carefully. - * - * @param id The identifier. - */ - virtual void SetUUID(const trBase::UniqueId& id); - - /** - * Returns the instances Universally Unique ID - */ - virtual const trBase::UniqueId& GetUUID(void); - - protected: - - /** - * @fn Base::~Base(); - * - * @brief Base destructor. Note, that it is protected so that classes cannot be deleted other - * than by being dereferenced and the reference count being zero (see trBase::SmrtClass), - * preventing the deletion of nodes which are still in use. This also means that Nodes - * cannot be created on stack i.e Node node will not compile, forcing all nodes to be - * created on the heap i.e Node* node = new Node(). - */ - ~Base(); - - private: - - trUtil::RefStr mName; - trBase::UniqueId mId; - - }; - -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include + +namespace trBase +{ + + /** + * This is a Base class that carries the Class name and Unique ID of all the derived classes. + */ + class TR_BASE_EXPORT Base : public trBase::SmrtClass + { + public: + + using BaseClass = trBase::SmrtClass; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn Base(const std::string& name = CLASS_TYPE); + * + * @brief ctor. + * + * @param name (Optional) The name. + */ + Base(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& Base::GetType() const override = 0; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override = 0; + + /** + * @fn virtual void Base::SetName(const std::string& name); + * + * @brief Sets this instances name. + * + * @param name The name. + */ + virtual void SetName(const std::string& name); + + /** + * @fn virtual const std::string& Base::GetName(); + * + * @brief Returns this instances name. + * + * @return The name. + */ + virtual const std::string& GetName(); + + /** + * @fn virtual const std::string& Base::GetName() const; + * + * @brief Returns this instances name. + * + * @return The name. + */ + virtual const std::string& GetName() const; + + /** + * @fn virtual void Base::SetUUID(const trBase::UniqueId& id); + * + * @brief Overwrites the default internal UUID with the passed in one. This should be done very + * carefully. + * + * @param id The identifier. + */ + virtual void SetUUID(const trBase::UniqueId& id); + + /** + * Returns the instances Universally Unique ID + */ + virtual const trBase::UniqueId& GetUUID(void); + + protected: + + /** + * @fn Base::~Base(); + * + * @brief Base destructor. Note, that it is protected so that classes cannot be deleted other + * than by being dereferenced and the reference count being zero (see trBase::SmrtClass), + * preventing the deletion of nodes which are still in use. This also means that Nodes + * cannot be created on stack i.e Node node will not compile, forcing all nodes to be + * created on the heap i.e Node* node = new Node(). + */ + ~Base(); + + private: + + trUtil::RefStr mName; + trBase::UniqueId mId; + + }; + +} + diff --git a/include/trBase/Export.h b/include/trBase/Export.h index 2c6e625..562a451 100644 --- a/include/trBase/Export.h +++ b/include/trBase/Export.h @@ -1,36 +1,36 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) -# ifdef TR_BASE_LIBRARY -# define TR_BASE_EXPORT __declspec(dllexport) -# else -# define TR_BASE_EXPORT __declspec(dllimport) -# endif -#else -# ifdef TR_BASE_LIBRARY -# define TR_BASE_EXPORT __attribute__ ((visibility("default"))) -# else -# define TR_BASE_EXPORT -# endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef TR_BASE_LIBRARY +# define TR_BASE_EXPORT __declspec(dllexport) +# else +# define TR_BASE_EXPORT __declspec(dllimport) +# endif +#else +# ifdef TR_BASE_LIBRARY +# define TR_BASE_EXPORT __attribute__ ((visibility("default"))) +# else +# define TR_BASE_EXPORT +# endif #endif \ No newline at end of file diff --git a/include/trBase/Matrix.h b/include/trBase/Matrix.h index d1825b3..b5011a9 100644 --- a/include/trBase/Matrix.h +++ b/include/trBase/Matrix.h @@ -1,38 +1,38 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -namespace trBase -{ -#ifdef TR_USE_DOUBLE_MATRIX - using Matrix = Matrixd; -// using RefMatrix = RefMatrixd; -#else - using Matrix = Matrixf; -// using RefMatrix = RefMatrixf; -#endif - -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +namespace trBase +{ +#ifdef TR_USE_DOUBLE_MATRIX + using Matrix = Matrixd; +// using RefMatrix = RefMatrixd; +#else + using Matrix = Matrixf; +// using RefMatrix = RefMatrixf; +#endif + +} + diff --git a/include/trBase/Matrixd.h b/include/trBase/Matrixd.h index 9ab0b5d..f96ebdf 100644 --- a/include/trBase/Matrixd.h +++ b/include/trBase/Matrixd.h @@ -1,1759 +1,1759 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - class Matrixf; - - /** - * A float Matrix class to be used for generic matrix operations. - */ - class TR_BASE_EXPORT Matrixd - { - public: - - using value_type = double; - - /** - * @fn Matrixd::Matrixd(); - * - * @brief ctor. - */ - Matrixd(); - - /** - * @fn Matrixd::Matrixd(const osg::Matrixd& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixd(const osg::Matrixd& mat); - - /** - * @fn Matrixd::Matrixd(const osg::Matrixf& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixd(const osg::Matrixf& mat); - - /** - * @fn Matrixd::Matrixd(const Matrixd& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixd(const Matrixd& mat); - - /** - * @fn Matrixd::Matrixd(const Matrixf& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixd(const Matrixf& mat); - - /** - * @fn explicit Matrixd::Matrixd(float const * const ptr); - * - * @brief ctor that takes a 4x4 array of floats and uses them as matrix input. - * - * @param ptr The pointer. - */ - explicit Matrixd(float const * const ptr); - - /** - * @fn explicit Matrixd::Matrixd(double const * const ptr); - * - * @brief ctor that takes a 4x4 array of double and uses them as matrix input. - * - * @param ptr The pointer. - */ - explicit Matrixd(double const * const ptr); - - /** - * @fn explicit Matrixd::Matrixd(const Quat& quat); - * - * @brief ctor that takes a quaternion and uses it as matrix input. - * - * @param quat The quaternion. - */ - explicit Matrixd(const Quat& quat); - - /** - * @fn Matrixd::Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); - * - * @brief ctor. - * - * @param a00 The [0][0] value of the matrix. - * @param a01 The [0][1] value of the matrix. - * @param a02 The [0][2] value of the matrix. - * @param a03 The [0][3] value of the matrix. - * @param a10 The [1][0] value of the matrix. - * @param a11 The [1][1] value of the matrix. - * @param a12 The [1][2] value of the matrix. - * @param a13 The [1][3] value of the matrix. - * @param a20 The [2][0] value of the matrix. - * @param a21 The [2][1] value of the matrix. - * @param a22 The [2][2] value of the matrix. - * @param a23 The [2][3] value of the matrix. - * @param a30 The [3][0] value of the matrix. - * @param a31 The [3][1] value of the matrix. - * @param a32 The [3][2] value of the matrix. - * @param a33 The [3][3] value of the matrix. - */ - Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, - value_type a10, value_type a11, value_type a12, value_type a13, - value_type a20, value_type a21, value_type a22, value_type a23, - value_type a30, value_type a31, value_type a32, value_type a33); - - /** - * @fn Matrixd::~Matrixd(); - * - * @brief dtor. - */ - ~Matrixd(); - - /** - * @fn osg::Matrixd& Matrixd::GetOSGMatrix(); - * - * @brief Returns a reference to the internal OSG Matrix. - * - * @return The osg matrix. - */ - osg::Matrixd& GetOSGMatrix(); - - /** - * @fn const osg::Matrixd& Matrixd::GetOSGMatrix() const; - * - * @brief Returns a reference to the internal OSG Matrix. - * - * @return The osg matrix. - */ - const osg::Matrixd& GetOSGMatrix() const; - - /** - * @fn int Matrixd::Compare(const Matrixd& m) const; - * - * @brief Compare the current Matrix to the passed in one. Returns -1, 0, or 1. - * - * @param m The constant matrixd& to compare to this object. - * - * @return Negative if 'm' is less than '', 0 if they are equal, or positive if it is greater. - */ - int Compare(const Matrixd& m) const; - - /** - * @fn bool Matrixd::Valid() const; - * - * @brief Returns true if the Matrix is not NaN. - * - * @return True if it succeeds, false if it fails. - */ - bool Valid() const; - - /** - * @fn bool Matrixd::IsNaN() const; - * - * @brief Returns true if the Matrix is NaN. - * - * @return True if nan, false if not. - */ - bool IsNaN() const; - - /** - * @fn void Matrixd::Set(const Matrixd& rhs); - * - * @brief Set the current Matrix from a passed in one. - * - * @param rhs The Right hand side to set. - */ - void Set(const Matrixd& rhs); - - /** - * @fn void Matrixd::Set(const Matrixf& rhs); - * - * @brief Set the current Matrix from a passed in one. - * - * @param rhs The Right hand side to set. - */ - void Set(const Matrixf& rhs); - - /** - * @fn void Matrixd::Set(float const * const ptr); - * - * @brief Set the current Matrix from a passed in values array. - * - * @param ptr The pointer. - */ - void Set(float const * const ptr); - - /** - * Set the current Matrix from a passed in values array. - */ - void Set(double const * const ptr); - - /** - * @fn void Matrixd::Set(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); - * - * @brief Set the current Matrix from a passed in values. - * - * @param a00 The [0][0] value of the matrix. - * @param a01 The [0][1] value of the matrix. - * @param a02 The [0][2] value of the matrix. - * @param a03 The [0][3] value of the matrix. - * @param a10 The [1][0] value of the matrix. - * @param a11 The [1][1] value of the matrix. - * @param a12 The [1][2] value of the matrix. - * @param a13 The [1][3] value of the matrix. - * @param a20 The [2][0] value of the matrix. - * @param a21 The [2][1] value of the matrix. - * @param a22 The [2][2] value of the matrix. - * @param a23 The [2][3] value of the matrix. - * @param a30 The [3][0] value of the matrix. - * @param a31 The [3][1] value of the matrix. - * @param a32 The [3][2] value of the matrix. - * @param a33 The [3][3] value of the matrix. - */ - void Set(value_type a00, value_type a01, value_type a02, value_type a03, - value_type a10, value_type a11, value_type a12, value_type a13, - value_type a20, value_type a21, value_type a22, value_type a23, - value_type a30, value_type a31, value_type a32, value_type a33); - - /** - * @fn value_type* Matrixd::Ptr(); - * - * @brief Pointer to the internal Matrix array. - * - * @return Null if it fails, else a pointer to a value_type. - */ - value_type* Ptr(); - - /** - * @fn const value_type* Matrixd::Ptr() const; - * - * @brief Pointer to the internal Matrix array. - * - * @return Null if it fails, else a pointer to a const value_type. - */ - const value_type* Ptr() const; - - /** - * @fn void Matrixd::MakeIdentity(); - * - * @brief Reset this matrix to be an Identity Matrix. - */ - void MakeIdentity(); - - /** - * @fn void Matrixd::MakeScale(const Vec3f& v); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param v The Vec3f to process. - */ - void MakeScale(const Vec3f& v); - - /** - * @fn void Matrixd::MakeScale(const Vec3d& v); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param v The Vec3d to process. - */ - void MakeScale(const Vec3d& v); - - /** - * @fn void Matrixd::MakeScale(value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeScale(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixd::MakeTranslate(const Vec3f& v); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param v The Vec3f to process. - */ - void MakeTranslate(const Vec3f& v); - - /** - * @fn void Matrixd::MakeTranslate(const Vec3d& v); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param v The Vec3d to process. - */ - void MakeTranslate(const Vec3d& v); - - /** - * @fn void Matrixd::MakeTranslate(value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeTranslate(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixd::MakeRotate(const Vec3f& from, const Vec3f& to); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param from Source for the. - * @param to to. - */ - void MakeRotate(const Vec3f& from, const Vec3f& to); - - /** - * @fn void Matrixd::MakeRotate(const Vec3d& from, const Vec3d& to); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param from Source for the. - * @param to to. - */ - void MakeRotate(const Vec3d& from, const Vec3d& to); - - /** - * @fn void Matrixd::MakeRotate(value_type angle, const Vec3f& axis); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param axis The axis. - */ - void MakeRotate(value_type angle, const Vec3f& axis); - - /** - * @fn void Matrixd::MakeRotate(value_type angle, const Vec3d& axis); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param axis The axis. - */ - void MakeRotate(value_type angle, const Vec3d& axis); - - /** - * @fn void Matrixd::MakeRotate(value_type angle, value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeRotate(value_type angle, value_type x, value_type y, value_type z); - - /** - * @fn void Matrixd::MakeRotate(const Quat& q); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param q The Quat to process. - */ - void MakeRotate(const Quat& q); - - /** - * @fn void Matrixd::MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @fn void Matrixd::MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * @fn void Matrixd::Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; - * - * @brief Decomposes the matrix into translation, rotation, scale and scale orientation. - * - * @param [in,out] translation The translation. - * @param [in,out] rotation The rotation. - * @param [in,out] scale The scale. - * @param [in,out] so The so. - */ - void Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; - - /** - * @fn void Matrixd::Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; - * - * @brief Decompose the matrix into translation, rotation, scale and scale orientation. - * - * @param [in,out] translation The translation. - * @param [in,out] rotation The rotation. - * @param [in,out] scale The scale. - * @param [in,out] so The so. - */ - void Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; - - /** - * @fn void Matrixd::MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Set to an orthographic projection. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn void Matrixd::MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Set to an orthographic projection. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn bool Matrixd::GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - * - * @brief Get the orthographic settings of the orthographic projection matrix. Note, if matrix - * is not an orthographic matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixd::GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - * - * @brief float version of getOrtho(..) - * Get the orthographic settings of the orthographic projection matrix. Note, if matrix - * is not an orthographic matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - - /** - * @fn void Matrixd::MakeOrtho2D(double left, double right, double bottom, double top); - * - * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - */ - void MakeOrtho2D(double left, double right, double bottom, double top); - - /** - * @fn void Matrixd::MakeOrtho2D(float left, float right, float bottom, float top); - * - * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - */ - void MakeOrtho2D(float left, float right, float bottom, float top); - - /** - * @fn void Matrixd::MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Set to a perspective projection. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn void Matrixd::MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Set to a perspective projection. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn bool Matrixd::GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - * - * @brief Get the frustum settings of a perspective projection matrix. Note, if matrix is not a - * perspective matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixd::GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - * - * @brief float version of getFrustum(..) - * Get the frustum settings of a perspective projection matrix. Note, if matrix is not a - * perspective matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - - /** - * @fn void Matrixd::MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); - * - * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. - * Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - */ - void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); - - /** - * @fn void Matrixd::MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); - * - * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. - * Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - */ - void MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); - - /** - * @fn bool Matrixd::GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; - * - * @brief Get the frustum settings of a symmetric perspective projection matrix. Return false - * if matrix is not a perspective matrix, where parameter values are undefined. Note, if - * matrix is not a symmetric perspective matrix then the shear will be lost. - * - * @param [in,out] fovy The fovy. - * @param [in,out] aspectRatio The aspect ratio. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixd::GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; - * - * @brief float version of getPerspective(..) - * Get the frustum settings of a symmetric perspective projection matrix. Return false - * if matrix is not a perspective matrix, where parameter values are undefined. Note, if - * matrix is not a symmetric perspective matrix then the shear will be lost. - * - * @param [in,out] fovy The fovy. - * @param [in,out] aspectRatio The aspect ratio. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; - - /** - * @fn void Matrixd::MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - * - * @brief Set the position and orientation to be a view matrix, using the same convention as - * gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - */ - void MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - - /** - * @fn void Matrixd::MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - * - * @brief Set the position and orientation to be a view matrix, using the same convention as - * gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - */ - void MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - - /** - * @fn void Matrixd::GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; - * - * @brief Get to the position and orientation of a modelview matrix, using the same convention - * as gluLookAt. - * - * @param [in,out] eye The eye. - * @param [in,out] center The center. - * @param [in,out] up The up. - * @param lookDistance (Optional) The look distance. - */ - void GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; - - /** - * @fn void Matrixd::GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; - * - * @brief Get to the position and orientation of a modelview matrix, using the same convention - * as gluLookAt. - * - * @param [in,out] eye The eye. - * @param [in,out] center The center. - * @param [in,out] up The up. - * @param lookDistance (Optional) The look distance. - */ - void GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; - - /** - * @fn bool Matrixd::Invert(const Matrixd& rhs); - * - * @brief Invert the matrix rhs, automatically select invert_4x3 or invert_4x4. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert(const Matrixd& rhs); - - /** - * @fn bool Matrixd::Invert_4x3(const Matrixd& rhs); - * - * @brief 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert_4x3(const Matrixd& rhs); - - /** - * @fn bool Matrixd::Invert_4x4(const Matrixd& rhs); - * - * @brief Full 4x4 matrix invert. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert_4x4(const Matrixd& rhs); - - /** - * @fn void Matrixd::OrthoNormalize(const Matrixd& rhs); - * - * @brief Ortho-normalize the 3x3 rotation & scale matrix. - * - * @param rhs The right hand side. - */ - void OrthoNormalize(const Matrixd& rhs); - - /** - * @fn void Matrixd::SetRotate(const Quat& q); - * - * @brief Applies the rotation to the matrix. - * - * @param q The Quat to process. - */ - void SetRotate(const Quat& q); - - /** - * @fn Quat Matrixd::GetRotate() const; - * - * @brief Get the matrix rotation as a Quat. Note that this function assumes a non-scaled - * matrix and will return incorrect results for scaled matrixces. Consider decompose() - * instead. - * - * @return The rotate. - */ - Quat GetRotate() const; - - /** - * @fn void Matrixd::SetTrans(value_type tx, value_type ty, value_type tz); - * - * @brief Sets the translation area of the matrix. - * - * @param tx The transmit. - * @param ty The ty. - * @param tz The tz. - */ - void SetTrans(value_type tx, value_type ty, value_type tz); - - /** - * @fn void Matrixd::SetTrans(const Vec3f& v); - * - * @brief Sets the translation area of the matrix. - * - * @param v The Vec3f to process. - */ - void SetTrans(const Vec3f& v); - - /** - * @fn void Matrixd::SetTrans(const Vec3d& v); - * - * @brief Sets the translation area of the matrix. - * - * @param v The Vec3d to process. - */ - void SetTrans(const Vec3d& v); - - /** - * @fn Vec3d Matrixd::GetTrans() const; - * - * @brief Returns the translation area of the matrix. - * - * @return The transaction. - */ - Vec3d GetTrans() const; - - /** - * @fn Vec3d Matrixd::GetScale() const; - * - * @brief Returns the matrix scale. - * - * @return The scale. - */ - Vec3d GetScale() const; - - /** - * @fn void Matrixd::SetScale(value_type x, value_type y, value_type z); - * - * @brief Sets the scale values of the matrix. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void SetScale(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixd::SetScale(const Vec3f& v); - * - * @brief Sets the scale values of the matrix. - * - * @param v The Vec3f to process. - */ - void SetScale(const Vec3f& v); - - /** - * @fn void Matrixd::SetScale(const Vec3d& v); - * - * @brief Sets the scale values of the matrix. - * - * @param v The Vec3d to process. - */ - void SetScale(const Vec3d& v); - - /** - * @fn Vec3f Matrixd::PreMult(const Vec3f& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - Vec3f PreMult(const Vec3f& v) const; - - /** - * @fn Vec3d Matrixd::PreMult(const Vec3d& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - Vec3d PreMult(const Vec3d& v) const; - - /** - * @fn Vec3f Matrixd::PostMult(const Vec3f& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - Vec3f PostMult(const Vec3f& v) const; - - /** - * @fn Vec3d Matrixd::PostMult(const Vec3d& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - Vec3d PostMult(const Vec3d& v) const; - - /** - * @fn Vec4f Matrixd::PreMult(const Vec4f& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec4f to process. - * - * @return A Vec4f. - */ - Vec4f PreMult(const Vec4f& v) const; - - /** - * @fn Vec4d Matrixd::PreMult(const Vec4d& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec4d to process. - * - * @return A Vec4d. - */ - Vec4d PreMult(const Vec4d& v) const; - - /** - * @fn Vec4f Matrixd::PostMult(const Vec4f& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec4f to process. - * - * @return A Vec4f. - */ - Vec4f PostMult(const Vec4f& v) const; - - /** - * @fn Vec4d Matrixd::PostMult(const Vec4d& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec4d to process. - * - * @return A Vec4d. - */ - Vec4d PostMult(const Vec4d& v) const; - - /** - * @fn void Matrixd::Mult(const Matrixd& m1, const Matrixd& m2); - * - * @brief Basic Matrixd multiplication, our workhorse methods. - * - * @param m1 The first Matrixd. - * @param m2 The second Matrixd. - */ - void Mult(const Matrixd& m1, const Matrixd& m2); - - /** - * @fn void Matrixd::PreMult(const Matrixd& m); - * - * @brief Basic Matrixd multiplication, our workhorse methods. - * - * @param m The Matrixd to process. - */ - void PreMult(const Matrixd& m); - - /** - * @fn void Matrixd::PostMult(const Matrixd& m); - * - * @brief Basic Matrixd multiplication, our workhorse methods. - * - * @param m The Matrixd to process. - */ - void PostMult(const Matrixd& m); - - /** - * @fn void Matrixd::PreMultTranslate(const Vec3d& v); - * - * @brief Optimized version of preMult(translate(v)); - * - * @param v The Vec3d to process. - */ - void PreMultTranslate(const Vec3d& v); - - /** - * @fn void Matrixd::PreMultTranslate(const Vec3f& v); - * - * @brief Optimized version of preMult(translate(v)); - * - * @param v The Vec3f to process. - */ - void PreMultTranslate(const Vec3f& v); - - /** - * @fn void Matrixd::PostMultTranslate(const Vec3d& v); - * - * @brief Optimized version of postMult(translate(v)); - * - * @param v The Vec3d to process. - */ - void PostMultTranslate(const Vec3d& v); - - /** - * @fn void Matrixd::PostMultTranslate(const Vec3f& v); - * - * @brief Optimized version of postMult(translate(v)); - * - * @param v The Vec3f to process. - */ - void PostMultTranslate(const Vec3f& v); - - /** - * @fn void Matrixd::PreMultScale(const Vec3d& v); - * - * @brief Optimized version of preMult(scale(v)); - * - * @param v The Vec3d to process. - */ - void PreMultScale(const Vec3d& v); - - /** - * @fn void Matrixd::PreMultScale(const Vec3f& v); - * - * @brief Optimized version of preMult(scale(v)); - * - * @param v The Vec3f to process. - */ - void PreMultScale(const Vec3f& v); - - /** - * @fn void Matrixd::PostMultScale(const Vec3d& v); - * - * @brief Optimized version of postMult(scale(v)); - * - * @param v The Vec3d to process. - */ - void PostMultScale(const Vec3d& v); - - /** - * @fn void Matrixd::PostMultScale(const Vec3f& v); - * - * @brief Optimized version of postMult(scale(v)); - * - * @param v The Vec3f to process. - */ - void PostMultScale(const Vec3f& v); - - /** - * @fn void Matrixd::PreMultRotate(const Quat& q); - * - * @brief Optimized version of preMult(rotate(q)); - * - * @param q The Quat to process. - */ - void PreMultRotate(const Quat& q); - - /** - * @fn void Matrixd::PostMultRotate(const Quat& q); - * - * @brief Optimized version of postMult(rotate(q)); - * - * @param q The Quat to process. - */ - void PostMultRotate(const Quat& q); - - /** - * @fn std::string Matrixd::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * @fn static Matrixd Matrixd::Identity(void); - * - * @brief Static method to create an Identity matrix. - * - * @return A Matrixd. - */ - static Matrixd Identity(void); - - /** - * @fn static Matrixd Matrixd::Scale(const Vec3f& sv); - * - * @brief Static method to create a Scale matrix. - * - * @param sv The sv. - * - * @return A Matrixd. - */ - static Matrixd Scale(const Vec3f& sv); - - /** - * @fn static Matrixd Matrixd::Scale(const Vec3d& sv); - * - * @brief Static method to create a Scale matrix. - * - * @param sv The sv. - * - * @return A Matrixd. - */ - static Matrixd Scale(const Vec3d& sv); - - /** - * @fn static Matrixd Matrixd::Scale(value_type sx, value_type sy, value_type sz); - * - * @brief Static method to create a Scale matrix. - * - * @param sx The sx. - * @param sy The sy. - * @param sz The size. - * - * @return A Matrixd. - */ - static Matrixd Scale(value_type sx, value_type sy, value_type sz); - - /** - * @fn static Matrixd Matrixd::Translate(const Vec3f& dv); - * - * @brief Static method to create a Translate matrix. - * - * @param dv The dv. - * - * @return A Matrixd. - */ - static Matrixd Translate(const Vec3f& dv); - - /** - * @fn static Matrixd Matrixd::Translate(const Vec3d& dv); - * - * @brief Static method to create a Translate matrix. - * - * @param dv The dv. - * - * @return A Matrixd. - */ - static Matrixd Translate(const Vec3d& dv); - - /** - * @fn static Matrixd Matrixd::Translate(value_type x, value_type y, value_type z); - * - * @brief Static method to create a Translate matrix. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - * - * @return A Matrixd. - */ - static Matrixd Translate(value_type x, value_type y, value_type z); - - /** - * @fn static Matrixd Matrixd::Rotate(const Vec3f& from, const Vec3f& to); - * - * @brief Static method to create a Rotational matrix. - * - * @param from Source for the. - * @param to to. - * - * @return A Matrixd. - */ - static Matrixd Rotate(const Vec3f& from, const Vec3f& to); - - /** - * @fn static Matrixd Matrixd::Rotate(const Vec3d& from, const Vec3d& to); - * - * @brief Static method to create a Rotational matrix. - * - * @param from Source for the. - * @param to to. - * - * @return A Matrixd. - */ - static Matrixd Rotate(const Vec3d& from, const Vec3d& to); - - /** - * @fn static Matrixd Matrixd::Rotate(value_type angle, value_type x, value_type y, value_type z); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - * - * @return A Matrixd. - */ - static Matrixd Rotate(value_type angle, value_type x, value_type y, value_type z); - - /** - * @fn static Matrixd Matrixd::Rotate(value_type angle, const Vec3f& axis); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param axis The axis. - * - * @return A Matrixd. - */ - static Matrixd Rotate(value_type angle, const Vec3f& axis); - - /** - * @fn static Matrixd Matrixd::Rotate(value_type angle, const Vec3d& axis); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param axis The axis. - * - * @return A Matrixd. - */ - static Matrixd Rotate(value_type angle, const Vec3d& axis); - - /** - * @fn static Matrixd Matrixd::Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - * - * @return A Matrixd. - */ - static Matrixd Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @fn static Matrixd Matrixd::Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - * - * @return A Matrixd. - */ - static Matrixd Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * @fn static Matrixd Matrixd::Rotate(const Quat& quat); - * - * @brief Static method to create a Rotational matrix. - * - * @param quat The quaternion. - * - * @return A Matrixd. - */ - static Matrixd Rotate(const Quat& quat); - - /** - * @fn static Matrixd Matrixd::Inverse(const Matrixd& matrix); - * - * @brief Static method to create an inverted matrix. - * - * @param matrix The matrix. - * - * @return A Matrixd. - */ - static Matrixd Inverse(const Matrixd& matrix); - - /** - * @fn static Matrixd Matrixd::OrthoNormal(const Matrixd& matrix); - * - * @brief Static method to create an Ortho Normalized matrix. - * - * @param matrix The matrix. - * - * @return A Matrixd. - */ - static Matrixd OrthoNormal(const Matrixd& matrix); - - /** - * @fn static Matrixd Matrixd::Ortho(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Create an orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Ortho(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn static Matrixd Matrixd::Ortho(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Create an orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Ortho(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn static Matrixd Matrixd::Ortho2D(double left, double right, double bottom, double top); - * - * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * - * @return A Matrixd. - */ - static Matrixd Ortho2D(double left, double right, double bottom, double top); - - /** - * @fn static Matrixd Matrixd::Ortho2D(float left, float right, float bottom, float top); - * - * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * - * @return A Matrixd. - */ - static Matrixd Ortho2D(float left, float right, float bottom, float top); - - /** - * @fn static Matrixd Matrixd::Frustum(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Create a perspective projection matrix. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Frustum(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn static Matrixd Matrixd::Frustum(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Create a perspective projection matrix. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Frustum(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn static Matrixd Matrixd::Perspective(float fovy, float aspectRatio, float zNear, float zFar); - * - * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further - * details. Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Perspective(float fovy, float aspectRatio, float zNear, float zFar); - - /** - * @fn static Matrixd Matrixd::Perspective(double fovy, double aspectRatio, double zNear, double zFar); - * - * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further - * details. Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixd. - */ - static Matrixd Perspective(double fovy, double aspectRatio, double zNear, double zFar); - - /** - * @fn static Matrixd Matrixd::LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - * - * @brief Create the position and orientation matrix as per a camera, using the same convention - * as gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - * - * @return A Matrixd. - */ - static Matrixd LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - - /** - * @fn static Matrixd Matrixd::LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - * - * @brief Create the position and orientation matrix as per a camera, using the same convention - * as gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - * - * @return A Matrixd. - */ - static Matrixd LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - - /** - * @fn static Vec3f Matrixd::Transform3x3(const Vec3f& v, const Matrixd& m); - * - * @brief Apply a 3x3 transform of v*M[0..2,0..2]. - * - * @param v The Vec3f to process. - * @param m The Matrixd to process. - * - * @return A Vec3f. - */ - static Vec3f Transform3x3(const Vec3f& v, const Matrixd& m); - - /** - * @fn static Vec3d Matrixd::Transform3x3(const Vec3d& v, const Matrixd& m); - * - * @brief Apply a 3x3 transform of v*M[0..2,0..2]. - * - * @param v The Vec3d to process. - * @param m The Matrixd to process. - * - * @return A Vec3d. - */ - static Vec3d Transform3x3(const Vec3d& v, const Matrixd& m); - - /** - * @fn static Vec3f Matrixd::Transform3x3(const Matrixd& m, const Vec3f& v); - * - * @brief Apply a 3x3 transform of M[0..2,0..2]*v. - * - * @param m The Matrixd to process. - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - static Vec3f Transform3x3(const Matrixd& m, const Vec3f& v); - - /** - * @fn static Vec3d Matrixd::Transform3x3(const Matrixd& m, const Vec3d& v); - * - * @brief Apply a 3x3 transform of M[0..2,0..2]*v. - * - * @param m The Matrixd to process. - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - static Vec3d Transform3x3(const Matrixd& m, const Vec3d& v); - - /** - * @fn Matrixd& Matrixd::operator= (const Matrixd& rhs); - * - * @brief Set operator. - * - * @param rhs The right hand side. - * - * @return A shallow copy of this object. - */ - Matrixd& operator = (const Matrixd& rhs); - - /** - * @fn Matrixd& Matrixd::operator= (const Matrixf& rhs); - * - * @brief Set operator. - * - * @param rhs The right hand side. - * - * @return A shallow copy of this object. - */ - Matrixd& operator = (const Matrixf& rhs); - - /** - * @fn bool Matrixd::operator> (const Matrixd& m) const; - * - * @brief Greater than by operator. - * - * @param m The Matrixd to process. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator > (const Matrixd& m) const; - - /** - * @fn bool Matrixd::operator< (const Matrixd& m) const; - * - * @brief Less than by operator. - * - * @param m The Matrixd to process. - * - * @return True if the first parameter is less than the second. - */ - bool operator < (const Matrixd& m) const; - - /** - * @fn bool Matrixd::operator== (const Matrixd& m) const; - * - * @brief Equality operator. - * - * @param m The Matrixd to process. - * - * @return True if the parameters are considered equivalent. - */ - bool operator == (const Matrixd& m) const; - - /** - * @fn bool Matrixd::operator!= (const Matrixd& m) const; - * - * @brief Inequality operator. - * - * @param m The Matrixd to process. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator != (const Matrixd& m) const; - - /** - * @fn Vec3f Matrixd::operator* (const Vec3f& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec3f to process. - * - * @return The result of the operation. - */ - Vec3f operator* (const Vec3f& v) const; - - /** - * @fn Vec3d Matrixd::operator* (const Vec3d& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec3d to process. - * - * @return The result of the operation. - */ - Vec3d operator* (const Vec3d& v) const; - - /** - * @fn Vec4f Matrixd::operator* (const Vec4f& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec4f to process. - * - * @return The result of the operation. - */ - Vec4f operator* (const Vec4f& v) const; - - /** - * @fn Vec4d Matrixd::operator* (const Vec4d& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec4d to process. - * - * @return The result of the operation. - */ - Vec4d operator* (const Vec4d& v) const; - - /** - * @fn void Matrixd::operator*= (const Matrixd& other); - * - * @brief Unary Multiply by a matrix. - * - * @param other The other. - */ - void operator *= (const Matrixd& other); - - /** - * @fn Matrixd Matrixd::operator* (const Matrixd &m) const; - * - * @brief Multiply by a matrix. - * - * @param m The Matrixd to process. - * - * @return The result of the operation. - */ - Matrixd operator * (const Matrixd &m) const; - - /** - * @fn Matrixd Matrixd::operator* (value_type rhs) const; - * - * @brief Multiply by scalar. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd operator * (value_type rhs) const; - - /** - * @fn Matrixd& Matrixd::operator*= (value_type rhs); - * - * @brief Unary multiply by scalar. More efficient than *. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd& operator *= (value_type rhs); - - /** - * @fn Matrixd Matrixd::operator/ (value_type rhs) const; - * - * @brief Divide by scalar. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd operator / (value_type rhs) const; - - /** - * @fn Matrixd& Matrixd::operator/= (value_type rhs); - * - * @brief Unary divide by scalar. More efficient than /. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd& operator /= (value_type rhs); - - /** - * @fn Matrixd Matrixd::operator+ (const Matrixd& rhs) const; - * - * @brief Binary vector add. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd operator + (const Matrixd& rhs) const; - - /** - * @fn Matrixd& Matrixd::operator+= (const Matrixd& rhs); - * - * @brief Unary vector add. More efficient than +. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd& operator += (const Matrixd& rhs); - - /** - * @fn Matrixd Matrixd::operator- (const Matrixd& rhs) const; - * - * @brief Binary vector subtract. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd operator - (const Matrixd& rhs) const; - - /** - * @fn Matrixd& Matrixd::operator-= (const Matrixd& rhs); - * - * @brief Unary vector subtract. More efficient than -. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixd& operator -= (const Matrixd& rhs); - - /** - * @fn value_type& Matrixd::operator()(int row, int col); - * - * @brief Returns a specific row and column value of the matrix. - * - * @param row The row. - * @param col The col. - * - * @return The result of the operation. - */ - value_type& operator ()(int row, int col); - - /** - * @fn value_type Matrixd::operator()(int row, int col) const; - * - * @brief Returns a specific row and column value of the matrix. - * - * @param row The row. - * @param col The col. - * - * @return The result of the operation. - */ - value_type operator ()(int row, int col) const; - - /** - * @fn operator osg::Matrixd () const; - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixd () const; - - /** - * @fn operator osg::Matrixd& (); - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixd& (); - - /** - * @fn operator const osg::Matrixd& () const; - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return A const. - */ - operator const osg::Matrixd& () const; - - /** - * @fn operator osg::Matrixd* (); - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixd* (); - - protected: - - osg::Matrixd mMatrix; - }; - - /** - * @brief Stream insertion operator. - * - * @return The stream string result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Matrixd& q); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + class Matrixf; + + /** + * A float Matrix class to be used for generic matrix operations. + */ + class TR_BASE_EXPORT Matrixd + { + public: + + using value_type = double; + + /** + * @fn Matrixd::Matrixd(); + * + * @brief ctor. + */ + Matrixd(); + + /** + * @fn Matrixd::Matrixd(const osg::Matrixd& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixd(const osg::Matrixd& mat); + + /** + * @fn Matrixd::Matrixd(const osg::Matrixf& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixd(const osg::Matrixf& mat); + + /** + * @fn Matrixd::Matrixd(const Matrixd& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixd(const Matrixd& mat); + + /** + * @fn Matrixd::Matrixd(const Matrixf& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixd(const Matrixf& mat); + + /** + * @fn explicit Matrixd::Matrixd(float const * const ptr); + * + * @brief ctor that takes a 4x4 array of floats and uses them as matrix input. + * + * @param ptr The pointer. + */ + explicit Matrixd(float const * const ptr); + + /** + * @fn explicit Matrixd::Matrixd(double const * const ptr); + * + * @brief ctor that takes a 4x4 array of double and uses them as matrix input. + * + * @param ptr The pointer. + */ + explicit Matrixd(double const * const ptr); + + /** + * @fn explicit Matrixd::Matrixd(const Quat& quat); + * + * @brief ctor that takes a quaternion and uses it as matrix input. + * + * @param quat The quaternion. + */ + explicit Matrixd(const Quat& quat); + + /** + * @fn Matrixd::Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); + * + * @brief ctor. + * + * @param a00 The [0][0] value of the matrix. + * @param a01 The [0][1] value of the matrix. + * @param a02 The [0][2] value of the matrix. + * @param a03 The [0][3] value of the matrix. + * @param a10 The [1][0] value of the matrix. + * @param a11 The [1][1] value of the matrix. + * @param a12 The [1][2] value of the matrix. + * @param a13 The [1][3] value of the matrix. + * @param a20 The [2][0] value of the matrix. + * @param a21 The [2][1] value of the matrix. + * @param a22 The [2][2] value of the matrix. + * @param a23 The [2][3] value of the matrix. + * @param a30 The [3][0] value of the matrix. + * @param a31 The [3][1] value of the matrix. + * @param a32 The [3][2] value of the matrix. + * @param a33 The [3][3] value of the matrix. + */ + Matrixd(value_type a00, value_type a01, value_type a02, value_type a03, + value_type a10, value_type a11, value_type a12, value_type a13, + value_type a20, value_type a21, value_type a22, value_type a23, + value_type a30, value_type a31, value_type a32, value_type a33); + + /** + * @fn Matrixd::~Matrixd(); + * + * @brief dtor. + */ + ~Matrixd(); + + /** + * @fn osg::Matrixd& Matrixd::GetOSGMatrix(); + * + * @brief Returns a reference to the internal OSG Matrix. + * + * @return The osg matrix. + */ + osg::Matrixd& GetOSGMatrix(); + + /** + * @fn const osg::Matrixd& Matrixd::GetOSGMatrix() const; + * + * @brief Returns a reference to the internal OSG Matrix. + * + * @return The osg matrix. + */ + const osg::Matrixd& GetOSGMatrix() const; + + /** + * @fn int Matrixd::Compare(const Matrixd& m) const; + * + * @brief Compare the current Matrix to the passed in one. Returns -1, 0, or 1. + * + * @param m The constant matrixd& to compare to this object. + * + * @return Negative if 'm' is less than '', 0 if they are equal, or positive if it is greater. + */ + int Compare(const Matrixd& m) const; + + /** + * @fn bool Matrixd::Valid() const; + * + * @brief Returns true if the Matrix is not NaN. + * + * @return True if it succeeds, false if it fails. + */ + bool Valid() const; + + /** + * @fn bool Matrixd::IsNaN() const; + * + * @brief Returns true if the Matrix is NaN. + * + * @return True if nan, false if not. + */ + bool IsNaN() const; + + /** + * @fn void Matrixd::Set(const Matrixd& rhs); + * + * @brief Set the current Matrix from a passed in one. + * + * @param rhs The Right hand side to set. + */ + void Set(const Matrixd& rhs); + + /** + * @fn void Matrixd::Set(const Matrixf& rhs); + * + * @brief Set the current Matrix from a passed in one. + * + * @param rhs The Right hand side to set. + */ + void Set(const Matrixf& rhs); + + /** + * @fn void Matrixd::Set(float const * const ptr); + * + * @brief Set the current Matrix from a passed in values array. + * + * @param ptr The pointer. + */ + void Set(float const * const ptr); + + /** + * Set the current Matrix from a passed in values array. + */ + void Set(double const * const ptr); + + /** + * @fn void Matrixd::Set(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); + * + * @brief Set the current Matrix from a passed in values. + * + * @param a00 The [0][0] value of the matrix. + * @param a01 The [0][1] value of the matrix. + * @param a02 The [0][2] value of the matrix. + * @param a03 The [0][3] value of the matrix. + * @param a10 The [1][0] value of the matrix. + * @param a11 The [1][1] value of the matrix. + * @param a12 The [1][2] value of the matrix. + * @param a13 The [1][3] value of the matrix. + * @param a20 The [2][0] value of the matrix. + * @param a21 The [2][1] value of the matrix. + * @param a22 The [2][2] value of the matrix. + * @param a23 The [2][3] value of the matrix. + * @param a30 The [3][0] value of the matrix. + * @param a31 The [3][1] value of the matrix. + * @param a32 The [3][2] value of the matrix. + * @param a33 The [3][3] value of the matrix. + */ + void Set(value_type a00, value_type a01, value_type a02, value_type a03, + value_type a10, value_type a11, value_type a12, value_type a13, + value_type a20, value_type a21, value_type a22, value_type a23, + value_type a30, value_type a31, value_type a32, value_type a33); + + /** + * @fn value_type* Matrixd::Ptr(); + * + * @brief Pointer to the internal Matrix array. + * + * @return Null if it fails, else a pointer to a value_type. + */ + value_type* Ptr(); + + /** + * @fn const value_type* Matrixd::Ptr() const; + * + * @brief Pointer to the internal Matrix array. + * + * @return Null if it fails, else a pointer to a const value_type. + */ + const value_type* Ptr() const; + + /** + * @fn void Matrixd::MakeIdentity(); + * + * @brief Reset this matrix to be an Identity Matrix. + */ + void MakeIdentity(); + + /** + * @fn void Matrixd::MakeScale(const Vec3f& v); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param v The Vec3f to process. + */ + void MakeScale(const Vec3f& v); + + /** + * @fn void Matrixd::MakeScale(const Vec3d& v); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param v The Vec3d to process. + */ + void MakeScale(const Vec3d& v); + + /** + * @fn void Matrixd::MakeScale(value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeScale(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixd::MakeTranslate(const Vec3f& v); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param v The Vec3f to process. + */ + void MakeTranslate(const Vec3f& v); + + /** + * @fn void Matrixd::MakeTranslate(const Vec3d& v); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param v The Vec3d to process. + */ + void MakeTranslate(const Vec3d& v); + + /** + * @fn void Matrixd::MakeTranslate(value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeTranslate(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixd::MakeRotate(const Vec3f& from, const Vec3f& to); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param from Source for the. + * @param to to. + */ + void MakeRotate(const Vec3f& from, const Vec3f& to); + + /** + * @fn void Matrixd::MakeRotate(const Vec3d& from, const Vec3d& to); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param from Source for the. + * @param to to. + */ + void MakeRotate(const Vec3d& from, const Vec3d& to); + + /** + * @fn void Matrixd::MakeRotate(value_type angle, const Vec3f& axis); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param axis The axis. + */ + void MakeRotate(value_type angle, const Vec3f& axis); + + /** + * @fn void Matrixd::MakeRotate(value_type angle, const Vec3d& axis); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param axis The axis. + */ + void MakeRotate(value_type angle, const Vec3d& axis); + + /** + * @fn void Matrixd::MakeRotate(value_type angle, value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeRotate(value_type angle, value_type x, value_type y, value_type z); + + /** + * @fn void Matrixd::MakeRotate(const Quat& q); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param q The Quat to process. + */ + void MakeRotate(const Quat& q); + + /** + * @fn void Matrixd::MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @fn void Matrixd::MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * @fn void Matrixd::Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; + * + * @brief Decomposes the matrix into translation, rotation, scale and scale orientation. + * + * @param [in,out] translation The translation. + * @param [in,out] rotation The rotation. + * @param [in,out] scale The scale. + * @param [in,out] so The so. + */ + void Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; + + /** + * @fn void Matrixd::Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; + * + * @brief Decompose the matrix into translation, rotation, scale and scale orientation. + * + * @param [in,out] translation The translation. + * @param [in,out] rotation The rotation. + * @param [in,out] scale The scale. + * @param [in,out] so The so. + */ + void Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; + + /** + * @fn void Matrixd::MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Set to an orthographic projection. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn void Matrixd::MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Set to an orthographic projection. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn bool Matrixd::GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + * + * @brief Get the orthographic settings of the orthographic projection matrix. Note, if matrix + * is not an orthographic matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixd::GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + * + * @brief float version of getOrtho(..) + * Get the orthographic settings of the orthographic projection matrix. Note, if matrix + * is not an orthographic matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + + /** + * @fn void Matrixd::MakeOrtho2D(double left, double right, double bottom, double top); + * + * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + */ + void MakeOrtho2D(double left, double right, double bottom, double top); + + /** + * @fn void Matrixd::MakeOrtho2D(float left, float right, float bottom, float top); + * + * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + */ + void MakeOrtho2D(float left, float right, float bottom, float top); + + /** + * @fn void Matrixd::MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Set to a perspective projection. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn void Matrixd::MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Set to a perspective projection. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn bool Matrixd::GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + * + * @brief Get the frustum settings of a perspective projection matrix. Note, if matrix is not a + * perspective matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixd::GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + * + * @brief float version of getFrustum(..) + * Get the frustum settings of a perspective projection matrix. Note, if matrix is not a + * perspective matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + + /** + * @fn void Matrixd::MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); + * + * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. + * Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + */ + void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); + + /** + * @fn void Matrixd::MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); + * + * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. + * Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + */ + void MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); + + /** + * @fn bool Matrixd::GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; + * + * @brief Get the frustum settings of a symmetric perspective projection matrix. Return false + * if matrix is not a perspective matrix, where parameter values are undefined. Note, if + * matrix is not a symmetric perspective matrix then the shear will be lost. + * + * @param [in,out] fovy The fovy. + * @param [in,out] aspectRatio The aspect ratio. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixd::GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; + * + * @brief float version of getPerspective(..) + * Get the frustum settings of a symmetric perspective projection matrix. Return false + * if matrix is not a perspective matrix, where parameter values are undefined. Note, if + * matrix is not a symmetric perspective matrix then the shear will be lost. + * + * @param [in,out] fovy The fovy. + * @param [in,out] aspectRatio The aspect ratio. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; + + /** + * @fn void Matrixd::MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + * + * @brief Set the position and orientation to be a view matrix, using the same convention as + * gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + */ + void MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + + /** + * @fn void Matrixd::MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + * + * @brief Set the position and orientation to be a view matrix, using the same convention as + * gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + */ + void MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + + /** + * @fn void Matrixd::GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; + * + * @brief Get to the position and orientation of a modelview matrix, using the same convention + * as gluLookAt. + * + * @param [in,out] eye The eye. + * @param [in,out] center The center. + * @param [in,out] up The up. + * @param lookDistance (Optional) The look distance. + */ + void GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; + + /** + * @fn void Matrixd::GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; + * + * @brief Get to the position and orientation of a modelview matrix, using the same convention + * as gluLookAt. + * + * @param [in,out] eye The eye. + * @param [in,out] center The center. + * @param [in,out] up The up. + * @param lookDistance (Optional) The look distance. + */ + void GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; + + /** + * @fn bool Matrixd::Invert(const Matrixd& rhs); + * + * @brief Invert the matrix rhs, automatically select invert_4x3 or invert_4x4. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert(const Matrixd& rhs); + + /** + * @fn bool Matrixd::Invert_4x3(const Matrixd& rhs); + * + * @brief 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert_4x3(const Matrixd& rhs); + + /** + * @fn bool Matrixd::Invert_4x4(const Matrixd& rhs); + * + * @brief Full 4x4 matrix invert. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert_4x4(const Matrixd& rhs); + + /** + * @fn void Matrixd::OrthoNormalize(const Matrixd& rhs); + * + * @brief Ortho-normalize the 3x3 rotation & scale matrix. + * + * @param rhs The right hand side. + */ + void OrthoNormalize(const Matrixd& rhs); + + /** + * @fn void Matrixd::SetRotate(const Quat& q); + * + * @brief Applies the rotation to the matrix. + * + * @param q The Quat to process. + */ + void SetRotate(const Quat& q); + + /** + * @fn Quat Matrixd::GetRotate() const; + * + * @brief Get the matrix rotation as a Quat. Note that this function assumes a non-scaled + * matrix and will return incorrect results for scaled matrixces. Consider decompose() + * instead. + * + * @return The rotate. + */ + Quat GetRotate() const; + + /** + * @fn void Matrixd::SetTrans(value_type tx, value_type ty, value_type tz); + * + * @brief Sets the translation area of the matrix. + * + * @param tx The transmit. + * @param ty The ty. + * @param tz The tz. + */ + void SetTrans(value_type tx, value_type ty, value_type tz); + + /** + * @fn void Matrixd::SetTrans(const Vec3f& v); + * + * @brief Sets the translation area of the matrix. + * + * @param v The Vec3f to process. + */ + void SetTrans(const Vec3f& v); + + /** + * @fn void Matrixd::SetTrans(const Vec3d& v); + * + * @brief Sets the translation area of the matrix. + * + * @param v The Vec3d to process. + */ + void SetTrans(const Vec3d& v); + + /** + * @fn Vec3d Matrixd::GetTrans() const; + * + * @brief Returns the translation area of the matrix. + * + * @return The transaction. + */ + Vec3d GetTrans() const; + + /** + * @fn Vec3d Matrixd::GetScale() const; + * + * @brief Returns the matrix scale. + * + * @return The scale. + */ + Vec3d GetScale() const; + + /** + * @fn void Matrixd::SetScale(value_type x, value_type y, value_type z); + * + * @brief Sets the scale values of the matrix. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void SetScale(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixd::SetScale(const Vec3f& v); + * + * @brief Sets the scale values of the matrix. + * + * @param v The Vec3f to process. + */ + void SetScale(const Vec3f& v); + + /** + * @fn void Matrixd::SetScale(const Vec3d& v); + * + * @brief Sets the scale values of the matrix. + * + * @param v The Vec3d to process. + */ + void SetScale(const Vec3d& v); + + /** + * @fn Vec3f Matrixd::PreMult(const Vec3f& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + Vec3f PreMult(const Vec3f& v) const; + + /** + * @fn Vec3d Matrixd::PreMult(const Vec3d& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + Vec3d PreMult(const Vec3d& v) const; + + /** + * @fn Vec3f Matrixd::PostMult(const Vec3f& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + Vec3f PostMult(const Vec3f& v) const; + + /** + * @fn Vec3d Matrixd::PostMult(const Vec3d& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + Vec3d PostMult(const Vec3d& v) const; + + /** + * @fn Vec4f Matrixd::PreMult(const Vec4f& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec4f to process. + * + * @return A Vec4f. + */ + Vec4f PreMult(const Vec4f& v) const; + + /** + * @fn Vec4d Matrixd::PreMult(const Vec4d& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec4d to process. + * + * @return A Vec4d. + */ + Vec4d PreMult(const Vec4d& v) const; + + /** + * @fn Vec4f Matrixd::PostMult(const Vec4f& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec4f to process. + * + * @return A Vec4f. + */ + Vec4f PostMult(const Vec4f& v) const; + + /** + * @fn Vec4d Matrixd::PostMult(const Vec4d& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec4d to process. + * + * @return A Vec4d. + */ + Vec4d PostMult(const Vec4d& v) const; + + /** + * @fn void Matrixd::Mult(const Matrixd& m1, const Matrixd& m2); + * + * @brief Basic Matrixd multiplication, our workhorse methods. + * + * @param m1 The first Matrixd. + * @param m2 The second Matrixd. + */ + void Mult(const Matrixd& m1, const Matrixd& m2); + + /** + * @fn void Matrixd::PreMult(const Matrixd& m); + * + * @brief Basic Matrixd multiplication, our workhorse methods. + * + * @param m The Matrixd to process. + */ + void PreMult(const Matrixd& m); + + /** + * @fn void Matrixd::PostMult(const Matrixd& m); + * + * @brief Basic Matrixd multiplication, our workhorse methods. + * + * @param m The Matrixd to process. + */ + void PostMult(const Matrixd& m); + + /** + * @fn void Matrixd::PreMultTranslate(const Vec3d& v); + * + * @brief Optimized version of preMult(translate(v)); + * + * @param v The Vec3d to process. + */ + void PreMultTranslate(const Vec3d& v); + + /** + * @fn void Matrixd::PreMultTranslate(const Vec3f& v); + * + * @brief Optimized version of preMult(translate(v)); + * + * @param v The Vec3f to process. + */ + void PreMultTranslate(const Vec3f& v); + + /** + * @fn void Matrixd::PostMultTranslate(const Vec3d& v); + * + * @brief Optimized version of postMult(translate(v)); + * + * @param v The Vec3d to process. + */ + void PostMultTranslate(const Vec3d& v); + + /** + * @fn void Matrixd::PostMultTranslate(const Vec3f& v); + * + * @brief Optimized version of postMult(translate(v)); + * + * @param v The Vec3f to process. + */ + void PostMultTranslate(const Vec3f& v); + + /** + * @fn void Matrixd::PreMultScale(const Vec3d& v); + * + * @brief Optimized version of preMult(scale(v)); + * + * @param v The Vec3d to process. + */ + void PreMultScale(const Vec3d& v); + + /** + * @fn void Matrixd::PreMultScale(const Vec3f& v); + * + * @brief Optimized version of preMult(scale(v)); + * + * @param v The Vec3f to process. + */ + void PreMultScale(const Vec3f& v); + + /** + * @fn void Matrixd::PostMultScale(const Vec3d& v); + * + * @brief Optimized version of postMult(scale(v)); + * + * @param v The Vec3d to process. + */ + void PostMultScale(const Vec3d& v); + + /** + * @fn void Matrixd::PostMultScale(const Vec3f& v); + * + * @brief Optimized version of postMult(scale(v)); + * + * @param v The Vec3f to process. + */ + void PostMultScale(const Vec3f& v); + + /** + * @fn void Matrixd::PreMultRotate(const Quat& q); + * + * @brief Optimized version of preMult(rotate(q)); + * + * @param q The Quat to process. + */ + void PreMultRotate(const Quat& q); + + /** + * @fn void Matrixd::PostMultRotate(const Quat& q); + * + * @brief Optimized version of postMult(rotate(q)); + * + * @param q The Quat to process. + */ + void PostMultRotate(const Quat& q); + + /** + * @fn std::string Matrixd::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * @fn static Matrixd Matrixd::Identity(void); + * + * @brief Static method to create an Identity matrix. + * + * @return A Matrixd. + */ + static Matrixd Identity(void); + + /** + * @fn static Matrixd Matrixd::Scale(const Vec3f& sv); + * + * @brief Static method to create a Scale matrix. + * + * @param sv The sv. + * + * @return A Matrixd. + */ + static Matrixd Scale(const Vec3f& sv); + + /** + * @fn static Matrixd Matrixd::Scale(const Vec3d& sv); + * + * @brief Static method to create a Scale matrix. + * + * @param sv The sv. + * + * @return A Matrixd. + */ + static Matrixd Scale(const Vec3d& sv); + + /** + * @fn static Matrixd Matrixd::Scale(value_type sx, value_type sy, value_type sz); + * + * @brief Static method to create a Scale matrix. + * + * @param sx The sx. + * @param sy The sy. + * @param sz The size. + * + * @return A Matrixd. + */ + static Matrixd Scale(value_type sx, value_type sy, value_type sz); + + /** + * @fn static Matrixd Matrixd::Translate(const Vec3f& dv); + * + * @brief Static method to create a Translate matrix. + * + * @param dv The dv. + * + * @return A Matrixd. + */ + static Matrixd Translate(const Vec3f& dv); + + /** + * @fn static Matrixd Matrixd::Translate(const Vec3d& dv); + * + * @brief Static method to create a Translate matrix. + * + * @param dv The dv. + * + * @return A Matrixd. + */ + static Matrixd Translate(const Vec3d& dv); + + /** + * @fn static Matrixd Matrixd::Translate(value_type x, value_type y, value_type z); + * + * @brief Static method to create a Translate matrix. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + * + * @return A Matrixd. + */ + static Matrixd Translate(value_type x, value_type y, value_type z); + + /** + * @fn static Matrixd Matrixd::Rotate(const Vec3f& from, const Vec3f& to); + * + * @brief Static method to create a Rotational matrix. + * + * @param from Source for the. + * @param to to. + * + * @return A Matrixd. + */ + static Matrixd Rotate(const Vec3f& from, const Vec3f& to); + + /** + * @fn static Matrixd Matrixd::Rotate(const Vec3d& from, const Vec3d& to); + * + * @brief Static method to create a Rotational matrix. + * + * @param from Source for the. + * @param to to. + * + * @return A Matrixd. + */ + static Matrixd Rotate(const Vec3d& from, const Vec3d& to); + + /** + * @fn static Matrixd Matrixd::Rotate(value_type angle, value_type x, value_type y, value_type z); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + * + * @return A Matrixd. + */ + static Matrixd Rotate(value_type angle, value_type x, value_type y, value_type z); + + /** + * @fn static Matrixd Matrixd::Rotate(value_type angle, const Vec3f& axis); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param axis The axis. + * + * @return A Matrixd. + */ + static Matrixd Rotate(value_type angle, const Vec3f& axis); + + /** + * @fn static Matrixd Matrixd::Rotate(value_type angle, const Vec3d& axis); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param axis The axis. + * + * @return A Matrixd. + */ + static Matrixd Rotate(value_type angle, const Vec3d& axis); + + /** + * @fn static Matrixd Matrixd::Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + * + * @return A Matrixd. + */ + static Matrixd Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @fn static Matrixd Matrixd::Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + * + * @return A Matrixd. + */ + static Matrixd Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * @fn static Matrixd Matrixd::Rotate(const Quat& quat); + * + * @brief Static method to create a Rotational matrix. + * + * @param quat The quaternion. + * + * @return A Matrixd. + */ + static Matrixd Rotate(const Quat& quat); + + /** + * @fn static Matrixd Matrixd::Inverse(const Matrixd& matrix); + * + * @brief Static method to create an inverted matrix. + * + * @param matrix The matrix. + * + * @return A Matrixd. + */ + static Matrixd Inverse(const Matrixd& matrix); + + /** + * @fn static Matrixd Matrixd::OrthoNormal(const Matrixd& matrix); + * + * @brief Static method to create an Ortho Normalized matrix. + * + * @param matrix The matrix. + * + * @return A Matrixd. + */ + static Matrixd OrthoNormal(const Matrixd& matrix); + + /** + * @fn static Matrixd Matrixd::Ortho(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Create an orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Ortho(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn static Matrixd Matrixd::Ortho(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Create an orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Ortho(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn static Matrixd Matrixd::Ortho2D(double left, double right, double bottom, double top); + * + * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * + * @return A Matrixd. + */ + static Matrixd Ortho2D(double left, double right, double bottom, double top); + + /** + * @fn static Matrixd Matrixd::Ortho2D(float left, float right, float bottom, float top); + * + * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * + * @return A Matrixd. + */ + static Matrixd Ortho2D(float left, float right, float bottom, float top); + + /** + * @fn static Matrixd Matrixd::Frustum(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Create a perspective projection matrix. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Frustum(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn static Matrixd Matrixd::Frustum(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Create a perspective projection matrix. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Frustum(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn static Matrixd Matrixd::Perspective(float fovy, float aspectRatio, float zNear, float zFar); + * + * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further + * details. Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Perspective(float fovy, float aspectRatio, float zNear, float zFar); + + /** + * @fn static Matrixd Matrixd::Perspective(double fovy, double aspectRatio, double zNear, double zFar); + * + * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further + * details. Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixd. + */ + static Matrixd Perspective(double fovy, double aspectRatio, double zNear, double zFar); + + /** + * @fn static Matrixd Matrixd::LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + * + * @brief Create the position and orientation matrix as per a camera, using the same convention + * as gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + * + * @return A Matrixd. + */ + static Matrixd LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + + /** + * @fn static Matrixd Matrixd::LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + * + * @brief Create the position and orientation matrix as per a camera, using the same convention + * as gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + * + * @return A Matrixd. + */ + static Matrixd LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + + /** + * @fn static Vec3f Matrixd::Transform3x3(const Vec3f& v, const Matrixd& m); + * + * @brief Apply a 3x3 transform of v*M[0..2,0..2]. + * + * @param v The Vec3f to process. + * @param m The Matrixd to process. + * + * @return A Vec3f. + */ + static Vec3f Transform3x3(const Vec3f& v, const Matrixd& m); + + /** + * @fn static Vec3d Matrixd::Transform3x3(const Vec3d& v, const Matrixd& m); + * + * @brief Apply a 3x3 transform of v*M[0..2,0..2]. + * + * @param v The Vec3d to process. + * @param m The Matrixd to process. + * + * @return A Vec3d. + */ + static Vec3d Transform3x3(const Vec3d& v, const Matrixd& m); + + /** + * @fn static Vec3f Matrixd::Transform3x3(const Matrixd& m, const Vec3f& v); + * + * @brief Apply a 3x3 transform of M[0..2,0..2]*v. + * + * @param m The Matrixd to process. + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + static Vec3f Transform3x3(const Matrixd& m, const Vec3f& v); + + /** + * @fn static Vec3d Matrixd::Transform3x3(const Matrixd& m, const Vec3d& v); + * + * @brief Apply a 3x3 transform of M[0..2,0..2]*v. + * + * @param m The Matrixd to process. + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + static Vec3d Transform3x3(const Matrixd& m, const Vec3d& v); + + /** + * @fn Matrixd& Matrixd::operator= (const Matrixd& rhs); + * + * @brief Set operator. + * + * @param rhs The right hand side. + * + * @return A shallow copy of this object. + */ + Matrixd& operator = (const Matrixd& rhs); + + /** + * @fn Matrixd& Matrixd::operator= (const Matrixf& rhs); + * + * @brief Set operator. + * + * @param rhs The right hand side. + * + * @return A shallow copy of this object. + */ + Matrixd& operator = (const Matrixf& rhs); + + /** + * @fn bool Matrixd::operator> (const Matrixd& m) const; + * + * @brief Greater than by operator. + * + * @param m The Matrixd to process. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator > (const Matrixd& m) const; + + /** + * @fn bool Matrixd::operator< (const Matrixd& m) const; + * + * @brief Less than by operator. + * + * @param m The Matrixd to process. + * + * @return True if the first parameter is less than the second. + */ + bool operator < (const Matrixd& m) const; + + /** + * @fn bool Matrixd::operator== (const Matrixd& m) const; + * + * @brief Equality operator. + * + * @param m The Matrixd to process. + * + * @return True if the parameters are considered equivalent. + */ + bool operator == (const Matrixd& m) const; + + /** + * @fn bool Matrixd::operator!= (const Matrixd& m) const; + * + * @brief Inequality operator. + * + * @param m The Matrixd to process. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator != (const Matrixd& m) const; + + /** + * @fn Vec3f Matrixd::operator* (const Vec3f& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec3f to process. + * + * @return The result of the operation. + */ + Vec3f operator* (const Vec3f& v) const; + + /** + * @fn Vec3d Matrixd::operator* (const Vec3d& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec3d to process. + * + * @return The result of the operation. + */ + Vec3d operator* (const Vec3d& v) const; + + /** + * @fn Vec4f Matrixd::operator* (const Vec4f& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec4f to process. + * + * @return The result of the operation. + */ + Vec4f operator* (const Vec4f& v) const; + + /** + * @fn Vec4d Matrixd::operator* (const Vec4d& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec4d to process. + * + * @return The result of the operation. + */ + Vec4d operator* (const Vec4d& v) const; + + /** + * @fn void Matrixd::operator*= (const Matrixd& other); + * + * @brief Unary Multiply by a matrix. + * + * @param other The other. + */ + void operator *= (const Matrixd& other); + + /** + * @fn Matrixd Matrixd::operator* (const Matrixd &m) const; + * + * @brief Multiply by a matrix. + * + * @param m The Matrixd to process. + * + * @return The result of the operation. + */ + Matrixd operator * (const Matrixd &m) const; + + /** + * @fn Matrixd Matrixd::operator* (value_type rhs) const; + * + * @brief Multiply by scalar. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd operator * (value_type rhs) const; + + /** + * @fn Matrixd& Matrixd::operator*= (value_type rhs); + * + * @brief Unary multiply by scalar. More efficient than *. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd& operator *= (value_type rhs); + + /** + * @fn Matrixd Matrixd::operator/ (value_type rhs) const; + * + * @brief Divide by scalar. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd operator / (value_type rhs) const; + + /** + * @fn Matrixd& Matrixd::operator/= (value_type rhs); + * + * @brief Unary divide by scalar. More efficient than /. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd& operator /= (value_type rhs); + + /** + * @fn Matrixd Matrixd::operator+ (const Matrixd& rhs) const; + * + * @brief Binary vector add. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd operator + (const Matrixd& rhs) const; + + /** + * @fn Matrixd& Matrixd::operator+= (const Matrixd& rhs); + * + * @brief Unary vector add. More efficient than +. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd& operator += (const Matrixd& rhs); + + /** + * @fn Matrixd Matrixd::operator- (const Matrixd& rhs) const; + * + * @brief Binary vector subtract. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd operator - (const Matrixd& rhs) const; + + /** + * @fn Matrixd& Matrixd::operator-= (const Matrixd& rhs); + * + * @brief Unary vector subtract. More efficient than -. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixd& operator -= (const Matrixd& rhs); + + /** + * @fn value_type& Matrixd::operator()(int row, int col); + * + * @brief Returns a specific row and column value of the matrix. + * + * @param row The row. + * @param col The col. + * + * @return The result of the operation. + */ + value_type& operator ()(int row, int col); + + /** + * @fn value_type Matrixd::operator()(int row, int col) const; + * + * @brief Returns a specific row and column value of the matrix. + * + * @param row The row. + * @param col The col. + * + * @return The result of the operation. + */ + value_type operator ()(int row, int col) const; + + /** + * @fn operator osg::Matrixd () const; + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixd () const; + + /** + * @fn operator osg::Matrixd& (); + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixd& (); + + /** + * @fn operator const osg::Matrixd& () const; + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return A const. + */ + operator const osg::Matrixd& () const; + + /** + * @fn operator osg::Matrixd* (); + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixd* (); + + protected: + + osg::Matrixd mMatrix; + }; + + /** + * @brief Stream insertion operator. + * + * @return The stream string result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Matrixd& q); } \ No newline at end of file diff --git a/include/trBase/Matrixf.h b/include/trBase/Matrixf.h index 043c52d..cfdfc6e 100644 --- a/include/trBase/Matrixf.h +++ b/include/trBase/Matrixf.h @@ -1,1762 +1,1762 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include -#include - -#include -#include - -namespace trBase -{ - class Matrixd; - - /** - * A float Matrix class to be used for generic matrix operations. - */ - class TR_BASE_EXPORT Matrixf - { - public: - - using value_type = float; - - /** - * ctor - */ - Matrixf(); - - /** - * @fn Matrixf::Matrixf(const osg::Matrixf& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixf(const osg::Matrixf& mat); - - /** - * @fn Matrixf::Matrixf(const osg::Matrixd& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixf(const osg::Matrixd& mat); - - /** - * @fn Matrixf::Matrixf(const Matrixf& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixf(const Matrixf& mat); - - /** - * @fn Matrixf::Matrixf(const Matrixd& mat); - * - * @brief ctor. - * - * @param mat The matrix. - */ - Matrixf(const Matrixd& mat); - - /** - * @fn explicit Matrixf::Matrixf(float const * const ptr); - * - * @brief ctor that takes a 4x4 array of floats and uses them as matrix input. - * - * @param ptr The pointer. - */ - explicit Matrixf(float const * const ptr); - - /** - * @fn explicit Matrixf::Matrixf(double const * const ptr); - * - * @brief ctor that takes a 4x4 array of double and uses them as matrix input. - * - * @param ptr The pointer. - */ - explicit Matrixf(double const * const ptr); - - /** - * @fn explicit Matrixf::Matrixf(const Quat& quat); - * - * @brief ctor that takes a quaternion and uses it as matrix input. - * - * @param quat The quaternion. - */ - explicit Matrixf(const Quat& quat); - - /** - * @fn Matrixf::Matrixf(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); - * - * @brief ctor. - * - * @param a00 The [0][0] value of the matrix. - * @param a01 The [0][1] value of the matrix. - * @param a02 The [0][2] value of the matrix. - * @param a03 The [0][3] value of the matrix. - * @param a10 The [1][0] value of the matrix. - * @param a11 The [1][1] value of the matrix. - * @param a12 The [1][2] value of the matrix. - * @param a13 The [1][3] value of the matrix. - * @param a20 The [2][0] value of the matrix. - * @param a21 The [2][1] value of the matrix. - * @param a22 The [2][2] value of the matrix. - * @param a23 The [2][3] value of the matrix. - * @param a30 The [3][0] value of the matrix. - * @param a31 The [3][1] value of the matrix. - * @param a32 The [3][2] value of the matrix. - * @param a33 The [3][3] value of the matrix. - */ - Matrixf(value_type a00, value_type a01, value_type a02, value_type a03, - value_type a10, value_type a11, value_type a12, value_type a13, - value_type a20, value_type a21, value_type a22, value_type a23, - value_type a30, value_type a31, value_type a32, value_type a33); - - /** - * @fn Matrixf::~Matrixf(); - * - * @brief dtor. - */ - ~Matrixf(); - - /** - * @fn osg::Matrixf& Matrixf::GetOSGMatrix(); - * - * @brief Returns a reference to the internal OSG Matrix. - * - * @return The osg matrix. - */ - osg::Matrixf& GetOSGMatrix(); - - /** - * @fn const osg::Matrixf& Matrixf::GetOSGMatrix() const; - * - * @brief Returns a reference to the internal OSG Matrix. - * - * @return The osg matrix. - */ - const osg::Matrixf& GetOSGMatrix() const; - - /** - * @fn int Matrixf::Compare(const Matrixf& m) const; - * - * @brief Compare the current Matrix to the passed in one. Returns -1, 0, or 1. - * - * @param m The constant matrixf& to compare to this object. - * - * @return Negative if 'm' is less than '', 0 if they are equal, or positive if it is greater. - */ - int Compare(const Matrixf& m) const; - - /** - * @fn bool Matrixf::Valid() const; - * - * @brief Returns true if the Matrix is not NaN. - * - * @return True if it succeeds, false if it fails. - */ - bool Valid() const; - - /** - * @fn bool Matrixf::IsNaN() const; - * - * @brief Returns true if the Matrix is NaN. - * - * @return True if nan, false if not. - */ - bool IsNaN() const; - - /** - * @fn void Matrixf::Set(const Matrixf& rhs); - * - * @brief Set the current Matrix from a passed in one. - * - * @param rhs The Right hand side to set. - */ - void Set(const Matrixf& rhs); - - /** - * @fn void Matrixf::Set(const Matrixd& rhs); - * - * @brief Set the current Matrix from a passed in one. - * - * @param rhs The Right hand side to set. - */ - void Set(const Matrixd& rhs); - - /** - * @fn void Matrixf::Set(float const * const ptr); - * - * @brief Set the current Matrix from a passed in values array. - * - * @param ptr The pointer. - */ - void Set(float const * const ptr); - - /** - * @fn void Matrixf::Set(double const * const ptr); - * - * @brief Set the current Matrix from a passed in values array. - * - * @param ptr The pointer. - */ - void Set(double const * const ptr); - - /** - * @fn void Matrixf::Set(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); - * - * @brief Set the current Matrix from a passed in values. - * - * @param a00 The [0][0] value of the matrix. - * @param a01 The [0][1] value of the matrix. - * @param a02 The [0][2] value of the matrix. - * @param a03 The [0][3] value of the matrix. - * @param a10 The [1][0] value of the matrix. - * @param a11 The [1][1] value of the matrix. - * @param a12 The [1][2] value of the matrix. - * @param a13 The [1][3] value of the matrix. - * @param a20 The [2][0] value of the matrix. - * @param a21 The [2][1] value of the matrix. - * @param a22 The [2][2] value of the matrix. - * @param a23 The [2][3] value of the matrix. - * @param a30 The [3][0] value of the matrix. - * @param a31 The [3][1] value of the matrix. - * @param a32 The [3][2] value of the matrix. - * @param a33 The [3][3] value of the matrix. - */ - void Set(value_type a00, value_type a01, value_type a02, value_type a03, - value_type a10, value_type a11, value_type a12, value_type a13, - value_type a20, value_type a21, value_type a22, value_type a23, - value_type a30, value_type a31, value_type a32, value_type a33); - - /** - * @fn value_type* Matrixf::Ptr(); - * - * @brief Pointer to the internal Matrix array. - * - * @return Null if it fails, else a pointer to a value_type. - */ - value_type* Ptr(); - - /** - * @fn const value_type* Matrixf::Ptr() const; - * - * @brief Pointer to the internal Matrix array. - * - * @return Null if it fails, else a pointer to a const value_type. - */ - const value_type* Ptr() const; - - /** - * @fn void Matrixf::MakeIdentity(); - * - * @brief Reset this matrix to be an Identity Matrix. - */ - void MakeIdentity(); - - /** - * @fn void Matrixf::MakeScale(const Vec3f& v); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param v The Vec3f to process. - */ - void MakeScale(const Vec3f& v); - - /** - * @fn void Matrixf::MakeScale(const Vec3d& v); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param v The Vec3d to process. - */ - void MakeScale(const Vec3d& v); - - /** - * @fn void Matrixf::MakeScale(value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a scale matrix of the passed in value. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeScale(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixf::MakeTranslate(const Vec3f& v); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param v The Vec3f to process. - */ - void MakeTranslate(const Vec3f& v); - - /** - * @fn void Matrixf::MakeTranslate(const Vec3d& v); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param v The Vec3d to process. - */ - void MakeTranslate(const Vec3d& v); - - /** - * @fn void Matrixf::MakeTranslate(value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a translation matrix of the passed in value. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeTranslate(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixf::MakeRotate(const Vec3f& from, const Vec3f& to); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param from Source for the. - * @param to to. - */ - void MakeRotate(const Vec3f& from, const Vec3f& to); - - /** - * @fn void Matrixf::MakeRotate(const Vec3d& from, const Vec3d& to); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param from Source for the. - * @param to to. - */ - void MakeRotate(const Vec3d& from, const Vec3d& to); - - /** - * @fn void Matrixf::MakeRotate(value_type angle, const Vec3f& axis); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param axis The axis. - */ - void MakeRotate(value_type angle, const Vec3f& axis); - - /** - * @fn void Matrixf::MakeRotate(value_type angle, const Vec3d& axis); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param axis The axis. - */ - void MakeRotate(value_type angle, const Vec3d& axis); - - /** - * @fn void Matrixf::MakeRotate(value_type angle, value_type x, value_type y, value_type z); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle The angle. - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void MakeRotate(value_type angle, value_type x, value_type y, value_type z); - - /** - * @fn void Matrixf::MakeRotate(const Quat& q); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param q The Quat to process. - */ - void MakeRotate(const Quat& q); - - /** - * @fn void Matrixf::MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @fn void Matrixf::MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - * - * @brief Reset this matrix to be a rotational matrix of the passed in value. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * @fn void Matrixf::Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; - * - * @brief Decomposes the matrix into translation, rotation, scale and scale orientation. - * - * @param [in,out] translation The translation. - * @param [in,out] rotation The rotation. - * @param [in,out] scale The scale. - * @param [in,out] so The so. - */ - void Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; - - /** - * @fn void Matrixf::Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; - * - * @brief Decompose the matrix into translation, rotation, scale and scale orientation. - * - * @param [in,out] translation The translation. - * @param [in,out] rotation The rotation. - * @param [in,out] scale The scale. - * @param [in,out] so The so. - */ - void Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; - - /** - * @fn void Matrixf::MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Set to an orthographic projection. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn void Matrixf::MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Set to an orthographic projection. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn bool Matrixf::GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - * - * @brief Get the orthographic settings of the orthographic projection matrix. Note, if matrix - * is not an orthographic matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixf::GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - * - * @brief float version of getOrtho(..) - * Get the orthographic settings of the orthographic projection matrix. Note, if matrix - * is not an orthographic matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - - /** - * @fn void Matrixf::MakeOrtho2D(double left, double right, double bottom, double top); - * - * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - */ - void MakeOrtho2D(double left, double right, double bottom, double top); - - /** - * @fn void Matrixf::MakeOrtho2D(float left, float right, float bottom, float top); - * - * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - */ - void MakeOrtho2D(float left, float right, float bottom, float top); - - /** - * @fn void Matrixf::MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Set to a perspective projection. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn void Matrixf::MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Set to a perspective projection. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - */ - void MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn bool Matrixf::GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - * - * @brief Get the frustum settings of a perspective projection matrix. Note, if matrix is not a - * perspective matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixf::GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - * - * @brief float version of getFrustum(..) - * Get the frustum settings of a perspective projection matrix. Note, if matrix is not a - * perspective matrix then invalid values will be returned. - * - * @param [in,out] left The left. - * @param [in,out] right The right. - * @param [in,out] bottom The bottom. - * @param [in,out] top The top. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; - - /** - * @fn void Matrixf::MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); - * - * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. - * Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - */ - void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); - - /** - * @fn void Matrixf::MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); - * - * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. - * Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - */ - void MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); - - /** - * @fn bool Matrixf::GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; - * - * @brief Get the frustum settings of a symmetric perspective projection matrix. Return false - * if matrix is not a perspective matrix, where parameter values are undefined. Note, if - * matrix is not a symmetric perspective matrix then the shear will be lost. - * - * @param [in,out] fovy The fovy. - * @param [in,out] aspectRatio The aspect ratio. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; - - /** - * @fn bool Matrixf::GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; - * - * @brief float version of getPerspective(..) - * Get the frustum settings of a symmetric perspective projection matrix. Return false - * if matrix is not a perspective matrix, where parameter values are undefined. Note, if - * matrix is not a symmetric perspective matrix then the shear will be lost. - * - * @param [in,out] fovy The fovy. - * @param [in,out] aspectRatio The aspect ratio. - * @param [in,out] zNear The near. - * @param [in,out] zFar The far. - * - * @return True if it succeeds, false if it fails. - */ - bool GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; - - /** - * @fn void Matrixf::MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - * - * @brief Set the position and orientation to be a view matrix, using the same convention as - * gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - */ - void MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - - /** - * @fn void Matrixf::MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - * - * @brief Set the position and orientation to be a view matrix, using the same convention as - * gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - */ - void MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - - /** - * @fn void Matrixf::GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; - * - * @brief Get to the position and orientation of a modelview matrix, using the same convention - * as gluLookAt. - * - * @param [in,out] eye The eye. - * @param [in,out] center The center. - * @param [in,out] up The up. - * @param lookDistance (Optional) The look distance. - */ - void GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; - - /** - * @fn void Matrixf::GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; - * - * @brief Get to the position and orientation of a modelview matrix, using the same convention - * as gluLookAt. - * - * @param [in,out] eye The eye. - * @param [in,out] center The center. - * @param [in,out] up The up. - * @param lookDistance (Optional) The look distance. - */ - void GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; - - /** - * @fn bool Matrixf::Invert(const Matrixf& rhs); - * - * @brief Invert the matrix rhs, automatically select invert_4x3 or invert_4x4. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert(const Matrixf& rhs); - - /** - * @fn bool Matrixf::Invert_4x3(const Matrixf& rhs); - * - * @brief 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert_4x3(const Matrixf& rhs); - - /** - * @fn bool Matrixf::Invert_4x4(const Matrixf& rhs); - * - * @brief Full 4x4 matrix invert. - * - * @param rhs The right hand side. - * - * @return True if it succeeds, false if it fails. - */ - bool Invert_4x4(const Matrixf& rhs); - - /** - * @fn void Matrixf::OrthoNormalize(const Matrixf& rhs); - * - * @brief Ortho-normalize the 3x3 rotation & scale matrix. - * - * @param rhs The right hand side. - */ - void OrthoNormalize(const Matrixf& rhs); - - /** - * @fn void Matrixf::SetRotate(const Quat& q); - * - * @brief Applies the rotation to the matrix. - * - * @param q The Quat to process. - */ - void SetRotate(const Quat& q); - - /** - * @fn Quat Matrixf::GetRotate() const; - * - * @brief Get the matrix rotation as a Quat. Note that this function assumes a non-scaled - * matrix and will return incorrect results for scaled matrixces. Consider decompose() - * instead. - * - * @return The rotate. - */ - Quat GetRotate() const; - - /** - * @fn void Matrixf::SetTrans(value_type tx, value_type ty, value_type tz); - * - * @brief Sets the translation area of the matrix. - * - * @param tx The transmit. - * @param ty The ty. - * @param tz The tz. - */ - void SetTrans(value_type tx, value_type ty, value_type tz); - - /** - * @fn void Matrixf::SetTrans(const Vec3f& v); - * - * @brief Sets the translation area of the matrix. - * - * @param v The Vec3f to process. - */ - void SetTrans(const Vec3f& v); - - /** - * @fn void Matrixf::SetTrans(const Vec3d& v); - * - * @brief Sets the translation area of the matrix. - * - * @param v The Vec3d to process. - */ - void SetTrans(const Vec3d& v); - - /** - * @fn Vec3d Matrixf::GetTrans() const; - * - * @brief Returns the translation area of the matrix. - * - * @return The transaction. - */ - Vec3d GetTrans() const; - - /** - * @fn Vec3d Matrixf::GetScale() const; - * - * @brief Returns the matrix scale. - * - * @return The scale. - */ - Vec3d GetScale() const; - - /** - * @fn void Matrixf::SetScale(value_type x, value_type y, value_type z); - * - * @brief Sets the scale values of the matrix. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - */ - void SetScale(value_type x, value_type y, value_type z); - - /** - * @fn void Matrixf::SetScale(const Vec3f& v); - * - * @brief Sets the scale values of the matrix. - * - * @param v The Vec3f to process. - */ - void SetScale(const Vec3f& v); - - /** - * @fn void Matrixf::SetScale(const Vec3d& v); - * - * @brief Sets the scale values of the matrix. - * - * @param v The Vec3d to process. - */ - void SetScale(const Vec3d& v); - - /** - * @fn Vec3f Matrixf::PreMult(const Vec3f& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - Vec3f PreMult(const Vec3f& v) const; - - /** - * @fn Vec3d Matrixf::PreMult(const Vec3d& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - Vec3d PreMult(const Vec3d& v) const; - - /** - * @fn Vec3f Matrixf::PostMult(const Vec3f& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - Vec3f PostMult(const Vec3f& v) const; - - /** - * @fn Vec3d Matrixf::PostMult(const Vec3d& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - Vec3d PostMult(const Vec3d& v) const; - - /** - * @fn Vec4f Matrixf::PreMult(const Vec4f& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec4f to process. - * - * @return A Vec4f. - */ - Vec4f PreMult(const Vec4f& v) const; - - /** - * @fn Vec4d Matrixf::PreMult(const Vec4d& v) const; - * - * @brief PreMultiply the matrix by the passed in vector. - * - * @param v The Vec4d to process. - * - * @return A Vec4d. - */ - Vec4d PreMult(const Vec4d& v) const; - - /** - * @fn Vec4f Matrixf::PostMult(const Vec4f& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec4f to process. - * - * @return A Vec4f. - */ - Vec4f PostMult(const Vec4f& v) const; - - /** - * @fn Vec4d Matrixf::PostMult(const Vec4d& v) const; - * - * @brief PostMultiply the matrix by the passed in vector. - * - * @param v The Vec4d to process. - * - * @return A Vec4d. - */ - Vec4d PostMult(const Vec4d& v) const; - - /** - * @fn void Matrixf::Mult(const Matrixf& m1, const Matrixf& m2); - * - * @brief Basic Matrixf multiplication, our workhorse methods. - * - * @param m1 The first Matrixf. - * @param m2 The second Matrixf. - */ - void Mult(const Matrixf& m1, const Matrixf& m2); - - /** - * @fn void Matrixf::PreMult(const Matrixf& m); - * - * @brief Basic Matrixf multiplication, our workhorse methods. - * - * @param m The Matrixf to process. - */ - void PreMult(const Matrixf& m); - - /** - * @fn void Matrixf::PostMult(const Matrixf& m); - * - * @brief Basic Matrixf multiplication, our workhorse methods. - * - * @param m The Matrixf to process. - */ - void PostMult(const Matrixf& m); - - /** - * @fn void Matrixf::PreMultTranslate(const Vec3d& v); - * - * @brief Optimized version of preMult(translate(v)); - * - * @param v The Vec3d to process. - */ - void PreMultTranslate(const Vec3d& v); - - /** - * @fn void Matrixf::PreMultTranslate(const Vec3f& v); - * - * @brief Optimized version of preMult(translate(v)); - * - * @param v The Vec3f to process. - */ - void PreMultTranslate(const Vec3f& v); - - /** - * @fn void Matrixf::PostMultTranslate(const Vec3d& v); - * - * @brief Optimized version of postMult(translate(v)); - * - * @param v The Vec3d to process. - */ - void PostMultTranslate(const Vec3d& v); - - /** - * @fn void Matrixf::PostMultTranslate(const Vec3f& v); - * - * @brief Optimized version of postMult(translate(v)); - * - * @param v The Vec3f to process. - */ - void PostMultTranslate(const Vec3f& v); - - /** - * @fn void Matrixf::PreMultScale(const Vec3d& v); - * - * @brief Optimized version of preMult(scale(v)); - * - * @param v The Vec3d to process. - */ - void PreMultScale(const Vec3d& v); - - /** - * @fn void Matrixf::PreMultScale(const Vec3f& v); - * - * @brief Optimized version of preMult(scale(v)); - * - * @param v The Vec3f to process. - */ - void PreMultScale(const Vec3f& v); - - /** - * @fn void Matrixf::PostMultScale(const Vec3d& v); - * - * @brief Optimized version of postMult(scale(v)); - * - * @param v The Vec3d to process. - */ - void PostMultScale(const Vec3d& v); - - /** - * @fn void Matrixf::PostMultScale(const Vec3f& v); - * - * @brief Optimized version of postMult(scale(v)); - * - * @param v The Vec3f to process. - */ - void PostMultScale(const Vec3f& v); - - /** - * @fn void Matrixf::PreMultRotate(const Quat& q); - * - * @brief Optimized version of preMult(rotate(q)); - * - * @param q The Quat to process. - */ - void PreMultRotate(const Quat& q); - - /** - * @fn void Matrixf::PostMultRotate(const Quat& q); - * - * @brief Optimized version of postMult(rotate(q)); - * - * @param q The Quat to process. - */ - void PostMultRotate(const Quat& q); - - /** - * @fn std::string Matrixf::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * @fn static Matrixf Matrixf::Identity(void); - * - * @brief Static method to create an Identity matrix. - * - * @return A Matrixf. - */ - static Matrixf Identity(void); - - /** - * @fn static Matrixf Matrixf::Scale(const Vec3f& sv); - * - * @brief Static method to create a Scale matrix. - * - * @param sv The sv. - * - * @return A Matrixf. - */ - static Matrixf Scale(const Vec3f& sv); - - /** - * @fn static Matrixf Matrixf::Scale(const Vec3d& sv); - * - * @brief Static method to create a Scale matrix. - * - * @param sv The sv. - * - * @return A Matrixf. - */ - static Matrixf Scale(const Vec3d& sv); - - /** - * @fn static Matrixf Matrixf::Scale(value_type sx, value_type sy, value_type sz); - * - * @brief Static method to create a Scale matrix. - * - * @param sx The sx. - * @param sy The sy. - * @param sz The size. - * - * @return A Matrixf. - */ - static Matrixf Scale(value_type sx, value_type sy, value_type sz); - - /** - * @fn static Matrixf Matrixf::Translate(const Vec3f& dv); - * - * @brief Static method to create a Translate matrix. - * - * @param dv The dv. - * - * @return A Matrixf. - */ - static Matrixf Translate(const Vec3f& dv); - - /** - * @fn static Matrixf Matrixf::Translate(const Vec3d& dv); - * - * @brief Static method to create a Translate matrix. - * - * @param dv The dv. - * - * @return A Matrixf. - */ - static Matrixf Translate(const Vec3d& dv); - - /** - * @fn static Matrixf Matrixf::Translate(value_type x, value_type y, value_type z); - * - * @brief Static method to create a Translate matrix. - * - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - * - * @return A Matrixf. - */ - static Matrixf Translate(value_type x, value_type y, value_type z); - - /** - * @fn static Matrixf Matrixf::Rotate(const Vec3f& from, const Vec3f& to); - * - * @brief Static method to create a Rotational matrix. - * - * @param from Source for the. - * @param to to. - * - * @return A Matrixf. - */ - static Matrixf Rotate(const Vec3f& from, const Vec3f& to); - - /** - * @fn static Matrixf Matrixf::Rotate(const Vec3d& from, const Vec3d& to); - * - * @brief Static method to create a Rotational matrix. - * - * @param from Source for the. - * @param to to. - * - * @return A Matrixf. - */ - static Matrixf Rotate(const Vec3d& from, const Vec3d& to); - - /** - * @fn static Matrixf Matrixf::Rotate(value_type angle, value_type x, value_type y, value_type z); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param x The value_type to process. - * @param y The value_type to process. - * @param z The value_type to process. - * - * @return A Matrixf. - */ - static Matrixf Rotate(value_type angle, value_type x, value_type y, value_type z); - - /** - * @fn static Matrixf Matrixf::Rotate(value_type angle, const Vec3f& axis); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param axis The axis. - * - * @return A Matrixf. - */ - static Matrixf Rotate(value_type angle, const Vec3f& axis); - - /** - * @fn static Matrixf Matrixf::Rotate(value_type angle, const Vec3d& axis); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle The angle. - * @param axis The axis. - * - * @return A Matrixf. - */ - static Matrixf Rotate(value_type angle, const Vec3d& axis); - - /** - * @fn static Matrixf Matrixf::Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - * - * @return A Matrixf. - */ - static Matrixf Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @fn static Matrixf Matrixf::Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - * - * @brief Static method to create a Rotational matrix. - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - * - * @return A Matrixf. - */ - static Matrixf Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * @fn static Matrixf Matrixf::Rotate(const Quat& quat); - * - * @brief Static method to create a Rotational matrix. - * - * @param quat The quaternion. - * - * @return A Matrixf. - */ - static Matrixf Rotate(const Quat& quat); - - /** - * @fn static Matrixf Matrixf::Inverse(const Matrixf& matrix); - * - * @brief Static method to create an inverted matrix. - * - * @param matrix The matrix. - * - * @return A Matrixf. - */ - static Matrixf Inverse(const Matrixf& matrix); - - /** - * @fn static Matrixf Matrixf::OrthoNormal(const Matrixf& matrix); - * - * @brief Static method to create an Ortho Normalized matrix. - * - * @param matrix The matrix. - * - * @return A Matrixf. - */ - static Matrixf OrthoNormal(const Matrixf& matrix); - - /** - * @fn static Matrixf Matrixf::Ortho(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Create an orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Ortho(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn static Matrixf Matrixf::Ortho(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Create an orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Ortho(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn static Matrixf Matrixf::Ortho2D(double left, double right, double bottom, double top); - * - * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * - * @return A Matrixf. - */ - static Matrixf Ortho2D(double left, double right, double bottom, double top); - - /** - * @fn static Matrixf Matrixf::Ortho2D(float left, float right, float bottom, float top); - * - * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * - * @return A Matrixf. - */ - static Matrixf Ortho2D(float left, float right, float bottom, float top); - - /** - * @fn static Matrixf Matrixf::Frustum(double left, double right, double bottom, double top, double zNear, double zFar); - * - * @brief Create a perspective projection matrix. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Frustum(double left, double right, double bottom, double top, double zNear, double zFar); - - /** - * @fn static Matrixf Matrixf::Frustum(float left, float right, float bottom, float top, float zNear, float zFar); - * - * @brief Create a perspective projection matrix. See glFrustum for further details. - * - * @param left The left. - * @param right The right. - * @param bottom The bottom. - * @param top The top. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Frustum(float left, float right, float bottom, float top, float zNear, float zFar); - - /** - * @fn static Matrixf Matrixf::Perspective(float fovy, float aspectRatio, float zNear, float zFar); - * - * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further - * details. Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Perspective(float fovy, float aspectRatio, float zNear, float zFar); - - /** - * @fn static Matrixf Matrixf::Perspective(double fovy, double aspectRatio, double zNear, double zFar); - * - * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further - * details. Aspect ratio is defined as width/height. - * - * @param fovy The fovy. - * @param aspectRatio The aspect ratio. - * @param zNear The near. - * @param zFar The far. - * - * @return A Matrixf. - */ - static Matrixf Perspective(double fovy, double aspectRatio, double zNear, double zFar); - - /** - * @fn static Matrixf Matrixf::LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - * - * @brief Create the position and orientation matrix as per a camera, using the same convention - * as gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - * - * @return A Matrixf. - */ - static Matrixf LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); - - /** - * @fn static Matrixf Matrixf::LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - * - * @brief Create the position and orientation matrix as per a camera, using the same convention - * as gluLookAt. - * - * @param eye The eye. - * @param center The center. - * @param up The up. - * - * @return A Matrixf. - */ - static Matrixf LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); - - /** - * @fn static Vec3f Matrixf::Transform3x3(const Vec3f& v, const Matrixf& m); - * - * @brief Apply a 3x3 transform of v*M[0..2,0..2]. - * - * @param v The Vec3f to process. - * @param m The Matrixf to process. - * - * @return A Vec3f. - */ - static Vec3f Transform3x3(const Vec3f& v, const Matrixf& m); - - /** - * @fn static Vec3d Matrixf::Transform3x3(const Vec3d& v, const Matrixf& m); - * - * @brief Apply a 3x3 transform of v*M[0..2,0..2]. - * - * @param v The Vec3d to process. - * @param m The Matrixf to process. - * - * @return A Vec3d. - */ - static Vec3d Transform3x3(const Vec3d& v, const Matrixf& m); - - /** - * @fn static Vec3f Matrixf::Transform3x3(const Matrixf& m, const Vec3f& v); - * - * @brief Apply a 3x3 transform of M[0..2,0..2]*v. - * - * @param m The Matrixf to process. - * @param v The Vec3f to process. - * - * @return A Vec3f. - */ - static Vec3f Transform3x3(const Matrixf& m, const Vec3f& v); - - /** - * @fn static Vec3d Matrixf::Transform3x3(const Matrixf& m, const Vec3d& v); - * - * @brief Apply a 3x3 transform of M[0..2,0..2]*v. - * - * @param m The Matrixf to process. - * @param v The Vec3d to process. - * - * @return A Vec3d. - */ - static Vec3d Transform3x3(const Matrixf& m, const Vec3d& v); - - /** - * @fn Matrixf& Matrixf::operator= (const Matrixf& rhs); - * - * @brief Set operator. - * - * @param rhs The right hand side. - * - * @return A shallow copy of this object. - */ - Matrixf& operator = (const Matrixf& rhs); - - /** - * @fn Matrixf& Matrixf::operator= (const Matrixd& rhs); - * - * @brief Set operator. - * - * @param rhs The right hand side. - * - * @return A shallow copy of this object. - */ - Matrixf& operator = (const Matrixd& rhs); - - /** - * @fn bool Matrixf::operator> (const Matrixf& m) const; - * - * @brief Greater than by operator. - * - * @param m The Matrixf to process. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator > (const Matrixf& m) const; - - /** - * @fn bool Matrixf::operator< (const Matrixf& m) const; - * - * @brief Less than by operator. - * - * @param m The Matrixf to process. - * - * @return True if the first parameter is less than the second. - */ - bool operator < (const Matrixf& m) const; - - /** - * @fn bool Matrixf::operator== (const Matrixf& m) const; - * - * @brief Equality operator. - * - * @param m The Matrixf to process. - * - * @return True if the parameters are considered equivalent. - */ - bool operator == (const Matrixf& m) const; - - /** - * @fn bool Matrixf::operator!= (const Matrixf& m) const; - * - * @brief Inequality operator. - * - * @param m The Matrixf to process. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator != (const Matrixf& m) const; - - /** - * @fn Vec3f Matrixf::operator* (const Vec3f& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec3f to process. - * - * @return The result of the operation. - */ - Vec3f operator* (const Vec3f& v) const; - - /** - * @fn Vec3d Matrixf::operator* (const Vec3d& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec3d to process. - * - * @return The result of the operation. - */ - Vec3d operator* (const Vec3d& v) const; - - /** - * @fn Vec4f Matrixf::operator* (const Vec4f& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec4f to process. - * - * @return The result of the operation. - */ - Vec4f operator* (const Vec4f& v) const; - - /** - * @fn Vec4d Matrixf::operator* (const Vec4d& v) const; - * - * @brief Multiply by vector. - * - * @param v The Vec4d to process. - * - * @return The result of the operation. - */ - Vec4d operator* (const Vec4d& v) const; - - /** - * @fn void Matrixf::operator*= (const Matrixf& other); - * - * @brief Unary Multiply by a matrix. - * - * @param other The other. - */ - void operator *= (const Matrixf& other); - - /** - * @fn Matrixf Matrixf::operator* (const Matrixf &m) const; - * - * @brief Multiply by a matrix. - * - * @param m The Matrixf to process. - * - * @return The result of the operation. - */ - Matrixf operator * (const Matrixf &m) const; - - /** - * @fn Matrixf Matrixf::operator* (value_type rhs) const; - * - * @brief Multiply by scalar. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf operator * (value_type rhs) const; - - /** - * @fn Matrixf& Matrixf::operator*= (value_type rhs); - * - * @brief Unary multiply by scalar. More efficient than *. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf& operator *= (value_type rhs); - - /** - * @fn Matrixf Matrixf::operator/ (value_type rhs) const; - * - * @brief Divide by scalar. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf operator / (value_type rhs) const; - - /** - * @fn Matrixf& Matrixf::operator/= (value_type rhs); - * - * @brief Unary divide by scalar. More efficient than /. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf& operator /= (value_type rhs); - - /** - * @fn Matrixf Matrixf::operator+ (const Matrixf& rhs) const; - * - * @brief Binary vector add. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf operator + (const Matrixf& rhs) const; - - /** - * @fn Matrixf& Matrixf::operator+= (const Matrixf& rhs); - * - * @brief Unary vector add. More efficient than +. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf& operator += (const Matrixf& rhs); - - /** - * @fn Matrixf Matrixf::operator- (const Matrixf& rhs) const; - * - * @brief Binary vector subtract. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf operator - (const Matrixf& rhs) const; - - /** - * @fn Matrixf& Matrixf::operator-= (const Matrixf& rhs); - * - * @brief Unary vector subtract. More efficient than -. - * - * @param rhs The right hand side. - * - * @return The result of the operation. - */ - Matrixf& operator -= (const Matrixf& rhs); - - /** - * @fn value_type& Matrixf::operator()(int row, int col); - * - * @brief Returns a specific row and column value of the matrix. - * - * @param row The row. - * @param col The col. - * - * @return The result of the operation. - */ - value_type& operator ()(int row, int col); - - /** - * @fn value_type Matrixf::operator()(int row, int col) const; - * - * @brief Returns a specific row and column value of the matrix. - * - * @param row The row. - * @param col The col. - * - * @return The result of the operation. - */ - value_type operator ()(int row, int col) const; - - /** - * @fn operator osg::Matrixf () const; - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixf () const; - - /** - * @fn operator osg::Matrixf& (); - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixf& (); - - /** - * @fn operator const osg::Matrixf& () const; - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return A const. - */ - operator const osg::Matrixf& () const; - - /** - * @fn operator osg::Matrixf* (); - * - * @brief Implicit conversion operator to OSG Matrix. - * - * @return The result of the operation. - */ - operator osg::Matrixf* (); - - protected: - - osg::Matrixf mMatrix; - }; - - /** - * @brief Stream insertion operator. - * - * @return The stream string result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Matrixf& q); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include +#include + +#include +#include + +namespace trBase +{ + class Matrixd; + + /** + * A float Matrix class to be used for generic matrix operations. + */ + class TR_BASE_EXPORT Matrixf + { + public: + + using value_type = float; + + /** + * ctor + */ + Matrixf(); + + /** + * @fn Matrixf::Matrixf(const osg::Matrixf& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixf(const osg::Matrixf& mat); + + /** + * @fn Matrixf::Matrixf(const osg::Matrixd& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixf(const osg::Matrixd& mat); + + /** + * @fn Matrixf::Matrixf(const Matrixf& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixf(const Matrixf& mat); + + /** + * @fn Matrixf::Matrixf(const Matrixd& mat); + * + * @brief ctor. + * + * @param mat The matrix. + */ + Matrixf(const Matrixd& mat); + + /** + * @fn explicit Matrixf::Matrixf(float const * const ptr); + * + * @brief ctor that takes a 4x4 array of floats and uses them as matrix input. + * + * @param ptr The pointer. + */ + explicit Matrixf(float const * const ptr); + + /** + * @fn explicit Matrixf::Matrixf(double const * const ptr); + * + * @brief ctor that takes a 4x4 array of double and uses them as matrix input. + * + * @param ptr The pointer. + */ + explicit Matrixf(double const * const ptr); + + /** + * @fn explicit Matrixf::Matrixf(const Quat& quat); + * + * @brief ctor that takes a quaternion and uses it as matrix input. + * + * @param quat The quaternion. + */ + explicit Matrixf(const Quat& quat); + + /** + * @fn Matrixf::Matrixf(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); + * + * @brief ctor. + * + * @param a00 The [0][0] value of the matrix. + * @param a01 The [0][1] value of the matrix. + * @param a02 The [0][2] value of the matrix. + * @param a03 The [0][3] value of the matrix. + * @param a10 The [1][0] value of the matrix. + * @param a11 The [1][1] value of the matrix. + * @param a12 The [1][2] value of the matrix. + * @param a13 The [1][3] value of the matrix. + * @param a20 The [2][0] value of the matrix. + * @param a21 The [2][1] value of the matrix. + * @param a22 The [2][2] value of the matrix. + * @param a23 The [2][3] value of the matrix. + * @param a30 The [3][0] value of the matrix. + * @param a31 The [3][1] value of the matrix. + * @param a32 The [3][2] value of the matrix. + * @param a33 The [3][3] value of the matrix. + */ + Matrixf(value_type a00, value_type a01, value_type a02, value_type a03, + value_type a10, value_type a11, value_type a12, value_type a13, + value_type a20, value_type a21, value_type a22, value_type a23, + value_type a30, value_type a31, value_type a32, value_type a33); + + /** + * @fn Matrixf::~Matrixf(); + * + * @brief dtor. + */ + ~Matrixf(); + + /** + * @fn osg::Matrixf& Matrixf::GetOSGMatrix(); + * + * @brief Returns a reference to the internal OSG Matrix. + * + * @return The osg matrix. + */ + osg::Matrixf& GetOSGMatrix(); + + /** + * @fn const osg::Matrixf& Matrixf::GetOSGMatrix() const; + * + * @brief Returns a reference to the internal OSG Matrix. + * + * @return The osg matrix. + */ + const osg::Matrixf& GetOSGMatrix() const; + + /** + * @fn int Matrixf::Compare(const Matrixf& m) const; + * + * @brief Compare the current Matrix to the passed in one. Returns -1, 0, or 1. + * + * @param m The constant matrixf& to compare to this object. + * + * @return Negative if 'm' is less than '', 0 if they are equal, or positive if it is greater. + */ + int Compare(const Matrixf& m) const; + + /** + * @fn bool Matrixf::Valid() const; + * + * @brief Returns true if the Matrix is not NaN. + * + * @return True if it succeeds, false if it fails. + */ + bool Valid() const; + + /** + * @fn bool Matrixf::IsNaN() const; + * + * @brief Returns true if the Matrix is NaN. + * + * @return True if nan, false if not. + */ + bool IsNaN() const; + + /** + * @fn void Matrixf::Set(const Matrixf& rhs); + * + * @brief Set the current Matrix from a passed in one. + * + * @param rhs The Right hand side to set. + */ + void Set(const Matrixf& rhs); + + /** + * @fn void Matrixf::Set(const Matrixd& rhs); + * + * @brief Set the current Matrix from a passed in one. + * + * @param rhs The Right hand side to set. + */ + void Set(const Matrixd& rhs); + + /** + * @fn void Matrixf::Set(float const * const ptr); + * + * @brief Set the current Matrix from a passed in values array. + * + * @param ptr The pointer. + */ + void Set(float const * const ptr); + + /** + * @fn void Matrixf::Set(double const * const ptr); + * + * @brief Set the current Matrix from a passed in values array. + * + * @param ptr The pointer. + */ + void Set(double const * const ptr); + + /** + * @fn void Matrixf::Set(value_type a00, value_type a01, value_type a02, value_type a03, value_type a10, value_type a11, value_type a12, value_type a13, value_type a20, value_type a21, value_type a22, value_type a23, value_type a30, value_type a31, value_type a32, value_type a33); + * + * @brief Set the current Matrix from a passed in values. + * + * @param a00 The [0][0] value of the matrix. + * @param a01 The [0][1] value of the matrix. + * @param a02 The [0][2] value of the matrix. + * @param a03 The [0][3] value of the matrix. + * @param a10 The [1][0] value of the matrix. + * @param a11 The [1][1] value of the matrix. + * @param a12 The [1][2] value of the matrix. + * @param a13 The [1][3] value of the matrix. + * @param a20 The [2][0] value of the matrix. + * @param a21 The [2][1] value of the matrix. + * @param a22 The [2][2] value of the matrix. + * @param a23 The [2][3] value of the matrix. + * @param a30 The [3][0] value of the matrix. + * @param a31 The [3][1] value of the matrix. + * @param a32 The [3][2] value of the matrix. + * @param a33 The [3][3] value of the matrix. + */ + void Set(value_type a00, value_type a01, value_type a02, value_type a03, + value_type a10, value_type a11, value_type a12, value_type a13, + value_type a20, value_type a21, value_type a22, value_type a23, + value_type a30, value_type a31, value_type a32, value_type a33); + + /** + * @fn value_type* Matrixf::Ptr(); + * + * @brief Pointer to the internal Matrix array. + * + * @return Null if it fails, else a pointer to a value_type. + */ + value_type* Ptr(); + + /** + * @fn const value_type* Matrixf::Ptr() const; + * + * @brief Pointer to the internal Matrix array. + * + * @return Null if it fails, else a pointer to a const value_type. + */ + const value_type* Ptr() const; + + /** + * @fn void Matrixf::MakeIdentity(); + * + * @brief Reset this matrix to be an Identity Matrix. + */ + void MakeIdentity(); + + /** + * @fn void Matrixf::MakeScale(const Vec3f& v); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param v The Vec3f to process. + */ + void MakeScale(const Vec3f& v); + + /** + * @fn void Matrixf::MakeScale(const Vec3d& v); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param v The Vec3d to process. + */ + void MakeScale(const Vec3d& v); + + /** + * @fn void Matrixf::MakeScale(value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a scale matrix of the passed in value. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeScale(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixf::MakeTranslate(const Vec3f& v); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param v The Vec3f to process. + */ + void MakeTranslate(const Vec3f& v); + + /** + * @fn void Matrixf::MakeTranslate(const Vec3d& v); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param v The Vec3d to process. + */ + void MakeTranslate(const Vec3d& v); + + /** + * @fn void Matrixf::MakeTranslate(value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a translation matrix of the passed in value. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeTranslate(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixf::MakeRotate(const Vec3f& from, const Vec3f& to); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param from Source for the. + * @param to to. + */ + void MakeRotate(const Vec3f& from, const Vec3f& to); + + /** + * @fn void Matrixf::MakeRotate(const Vec3d& from, const Vec3d& to); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param from Source for the. + * @param to to. + */ + void MakeRotate(const Vec3d& from, const Vec3d& to); + + /** + * @fn void Matrixf::MakeRotate(value_type angle, const Vec3f& axis); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param axis The axis. + */ + void MakeRotate(value_type angle, const Vec3f& axis); + + /** + * @fn void Matrixf::MakeRotate(value_type angle, const Vec3d& axis); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param axis The axis. + */ + void MakeRotate(value_type angle, const Vec3d& axis); + + /** + * @fn void Matrixf::MakeRotate(value_type angle, value_type x, value_type y, value_type z); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle The angle. + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void MakeRotate(value_type angle, value_type x, value_type y, value_type z); + + /** + * @fn void Matrixf::MakeRotate(const Quat& q); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param q The Quat to process. + */ + void MakeRotate(const Quat& q); + + /** + * @fn void Matrixf::MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @fn void Matrixf::MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + * + * @brief Reset this matrix to be a rotational matrix of the passed in value. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * @fn void Matrixf::Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; + * + * @brief Decomposes the matrix into translation, rotation, scale and scale orientation. + * + * @param [in,out] translation The translation. + * @param [in,out] rotation The rotation. + * @param [in,out] scale The scale. + * @param [in,out] so The so. + */ + void Decompose(Vec3f& translation, Quat& rotation, Vec3f& scale, Quat& so) const; + + /** + * @fn void Matrixf::Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; + * + * @brief Decompose the matrix into translation, rotation, scale and scale orientation. + * + * @param [in,out] translation The translation. + * @param [in,out] rotation The rotation. + * @param [in,out] scale The scale. + * @param [in,out] so The so. + */ + void Decompose(Vec3d& translation, Quat& rotation, Vec3d& scale, Quat& so) const; + + /** + * @fn void Matrixf::MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Set to an orthographic projection. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeOrtho(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn void Matrixf::MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Set to an orthographic projection. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeOrtho(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn bool Matrixf::GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + * + * @brief Get the orthographic settings of the orthographic projection matrix. Note, if matrix + * is not an orthographic matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetOrtho(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixf::GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + * + * @brief float version of getOrtho(..) + * Get the orthographic settings of the orthographic projection matrix. Note, if matrix + * is not an orthographic matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetOrtho(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + + /** + * @fn void Matrixf::MakeOrtho2D(double left, double right, double bottom, double top); + * + * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + */ + void MakeOrtho2D(double left, double right, double bottom, double top); + + /** + * @fn void Matrixf::MakeOrtho2D(float left, float right, float bottom, float top); + * + * @brief Set to a 2D orthographic projection. See glOrtho2D for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + */ + void MakeOrtho2D(float left, float right, float bottom, float top); + + /** + * @fn void Matrixf::MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Set to a perspective projection. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeFrustum(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn void Matrixf::MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Set to a perspective projection. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + */ + void MakeFrustum(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn bool Matrixf::GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + * + * @brief Get the frustum settings of a perspective projection matrix. Note, if matrix is not a + * perspective matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetFrustum(double& left, double& right, double& bottom, double& top, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixf::GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + * + * @brief float version of getFrustum(..) + * Get the frustum settings of a perspective projection matrix. Note, if matrix is not a + * perspective matrix then invalid values will be returned. + * + * @param [in,out] left The left. + * @param [in,out] right The right. + * @param [in,out] bottom The bottom. + * @param [in,out] top The top. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetFrustum(float& left, float& right, float& bottom, float& top, float& zNear, float& zFar) const; + + /** + * @fn void Matrixf::MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); + * + * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. + * Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + */ + void MakePerspective(double fovy, double aspectRatio, double zNear, double zFar); + + /** + * @fn void Matrixf::MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); + * + * @brief Set to a symmetrical perspective projection. See gluPerspective for further details. + * Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + */ + void MakePerspective(float fovy, float aspectRatio, float zNear, float zFar); + + /** + * @fn bool Matrixf::GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; + * + * @brief Get the frustum settings of a symmetric perspective projection matrix. Return false + * if matrix is not a perspective matrix, where parameter values are undefined. Note, if + * matrix is not a symmetric perspective matrix then the shear will be lost. + * + * @param [in,out] fovy The fovy. + * @param [in,out] aspectRatio The aspect ratio. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetPerspective(double& fovy, double& aspectRatio, double& zNear, double& zFar) const; + + /** + * @fn bool Matrixf::GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; + * + * @brief float version of getPerspective(..) + * Get the frustum settings of a symmetric perspective projection matrix. Return false + * if matrix is not a perspective matrix, where parameter values are undefined. Note, if + * matrix is not a symmetric perspective matrix then the shear will be lost. + * + * @param [in,out] fovy The fovy. + * @param [in,out] aspectRatio The aspect ratio. + * @param [in,out] zNear The near. + * @param [in,out] zFar The far. + * + * @return True if it succeeds, false if it fails. + */ + bool GetPerspective(float& fovy, float& aspectRatio, float& zNear, float& zFar) const; + + /** + * @fn void Matrixf::MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + * + * @brief Set the position and orientation to be a view matrix, using the same convention as + * gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + */ + void MakeLookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + + /** + * @fn void Matrixf::MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + * + * @brief Set the position and orientation to be a view matrix, using the same convention as + * gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + */ + void MakeLookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + + /** + * @fn void Matrixf::GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; + * + * @brief Get to the position and orientation of a modelview matrix, using the same convention + * as gluLookAt. + * + * @param [in,out] eye The eye. + * @param [in,out] center The center. + * @param [in,out] up The up. + * @param lookDistance (Optional) The look distance. + */ + void GetLookAt(Vec3f& eye, Vec3f& center, Vec3f& up, value_type lookDistance = 1.0f) const; + + /** + * @fn void Matrixf::GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; + * + * @brief Get to the position and orientation of a modelview matrix, using the same convention + * as gluLookAt. + * + * @param [in,out] eye The eye. + * @param [in,out] center The center. + * @param [in,out] up The up. + * @param lookDistance (Optional) The look distance. + */ + void GetLookAt(Vec3d& eye, Vec3d& center, Vec3d& up, value_type lookDistance = 1.0f) const; + + /** + * @fn bool Matrixf::Invert(const Matrixf& rhs); + * + * @brief Invert the matrix rhs, automatically select invert_4x3 or invert_4x4. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert(const Matrixf& rhs); + + /** + * @fn bool Matrixf::Invert_4x3(const Matrixf& rhs); + * + * @brief 4x3 matrix invert, not right hand column is assumed to be 0,0,0,1. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert_4x3(const Matrixf& rhs); + + /** + * @fn bool Matrixf::Invert_4x4(const Matrixf& rhs); + * + * @brief Full 4x4 matrix invert. + * + * @param rhs The right hand side. + * + * @return True if it succeeds, false if it fails. + */ + bool Invert_4x4(const Matrixf& rhs); + + /** + * @fn void Matrixf::OrthoNormalize(const Matrixf& rhs); + * + * @brief Ortho-normalize the 3x3 rotation & scale matrix. + * + * @param rhs The right hand side. + */ + void OrthoNormalize(const Matrixf& rhs); + + /** + * @fn void Matrixf::SetRotate(const Quat& q); + * + * @brief Applies the rotation to the matrix. + * + * @param q The Quat to process. + */ + void SetRotate(const Quat& q); + + /** + * @fn Quat Matrixf::GetRotate() const; + * + * @brief Get the matrix rotation as a Quat. Note that this function assumes a non-scaled + * matrix and will return incorrect results for scaled matrixces. Consider decompose() + * instead. + * + * @return The rotate. + */ + Quat GetRotate() const; + + /** + * @fn void Matrixf::SetTrans(value_type tx, value_type ty, value_type tz); + * + * @brief Sets the translation area of the matrix. + * + * @param tx The transmit. + * @param ty The ty. + * @param tz The tz. + */ + void SetTrans(value_type tx, value_type ty, value_type tz); + + /** + * @fn void Matrixf::SetTrans(const Vec3f& v); + * + * @brief Sets the translation area of the matrix. + * + * @param v The Vec3f to process. + */ + void SetTrans(const Vec3f& v); + + /** + * @fn void Matrixf::SetTrans(const Vec3d& v); + * + * @brief Sets the translation area of the matrix. + * + * @param v The Vec3d to process. + */ + void SetTrans(const Vec3d& v); + + /** + * @fn Vec3d Matrixf::GetTrans() const; + * + * @brief Returns the translation area of the matrix. + * + * @return The transaction. + */ + Vec3d GetTrans() const; + + /** + * @fn Vec3d Matrixf::GetScale() const; + * + * @brief Returns the matrix scale. + * + * @return The scale. + */ + Vec3d GetScale() const; + + /** + * @fn void Matrixf::SetScale(value_type x, value_type y, value_type z); + * + * @brief Sets the scale values of the matrix. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + */ + void SetScale(value_type x, value_type y, value_type z); + + /** + * @fn void Matrixf::SetScale(const Vec3f& v); + * + * @brief Sets the scale values of the matrix. + * + * @param v The Vec3f to process. + */ + void SetScale(const Vec3f& v); + + /** + * @fn void Matrixf::SetScale(const Vec3d& v); + * + * @brief Sets the scale values of the matrix. + * + * @param v The Vec3d to process. + */ + void SetScale(const Vec3d& v); + + /** + * @fn Vec3f Matrixf::PreMult(const Vec3f& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + Vec3f PreMult(const Vec3f& v) const; + + /** + * @fn Vec3d Matrixf::PreMult(const Vec3d& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + Vec3d PreMult(const Vec3d& v) const; + + /** + * @fn Vec3f Matrixf::PostMult(const Vec3f& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + Vec3f PostMult(const Vec3f& v) const; + + /** + * @fn Vec3d Matrixf::PostMult(const Vec3d& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + Vec3d PostMult(const Vec3d& v) const; + + /** + * @fn Vec4f Matrixf::PreMult(const Vec4f& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec4f to process. + * + * @return A Vec4f. + */ + Vec4f PreMult(const Vec4f& v) const; + + /** + * @fn Vec4d Matrixf::PreMult(const Vec4d& v) const; + * + * @brief PreMultiply the matrix by the passed in vector. + * + * @param v The Vec4d to process. + * + * @return A Vec4d. + */ + Vec4d PreMult(const Vec4d& v) const; + + /** + * @fn Vec4f Matrixf::PostMult(const Vec4f& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec4f to process. + * + * @return A Vec4f. + */ + Vec4f PostMult(const Vec4f& v) const; + + /** + * @fn Vec4d Matrixf::PostMult(const Vec4d& v) const; + * + * @brief PostMultiply the matrix by the passed in vector. + * + * @param v The Vec4d to process. + * + * @return A Vec4d. + */ + Vec4d PostMult(const Vec4d& v) const; + + /** + * @fn void Matrixf::Mult(const Matrixf& m1, const Matrixf& m2); + * + * @brief Basic Matrixf multiplication, our workhorse methods. + * + * @param m1 The first Matrixf. + * @param m2 The second Matrixf. + */ + void Mult(const Matrixf& m1, const Matrixf& m2); + + /** + * @fn void Matrixf::PreMult(const Matrixf& m); + * + * @brief Basic Matrixf multiplication, our workhorse methods. + * + * @param m The Matrixf to process. + */ + void PreMult(const Matrixf& m); + + /** + * @fn void Matrixf::PostMult(const Matrixf& m); + * + * @brief Basic Matrixf multiplication, our workhorse methods. + * + * @param m The Matrixf to process. + */ + void PostMult(const Matrixf& m); + + /** + * @fn void Matrixf::PreMultTranslate(const Vec3d& v); + * + * @brief Optimized version of preMult(translate(v)); + * + * @param v The Vec3d to process. + */ + void PreMultTranslate(const Vec3d& v); + + /** + * @fn void Matrixf::PreMultTranslate(const Vec3f& v); + * + * @brief Optimized version of preMult(translate(v)); + * + * @param v The Vec3f to process. + */ + void PreMultTranslate(const Vec3f& v); + + /** + * @fn void Matrixf::PostMultTranslate(const Vec3d& v); + * + * @brief Optimized version of postMult(translate(v)); + * + * @param v The Vec3d to process. + */ + void PostMultTranslate(const Vec3d& v); + + /** + * @fn void Matrixf::PostMultTranslate(const Vec3f& v); + * + * @brief Optimized version of postMult(translate(v)); + * + * @param v The Vec3f to process. + */ + void PostMultTranslate(const Vec3f& v); + + /** + * @fn void Matrixf::PreMultScale(const Vec3d& v); + * + * @brief Optimized version of preMult(scale(v)); + * + * @param v The Vec3d to process. + */ + void PreMultScale(const Vec3d& v); + + /** + * @fn void Matrixf::PreMultScale(const Vec3f& v); + * + * @brief Optimized version of preMult(scale(v)); + * + * @param v The Vec3f to process. + */ + void PreMultScale(const Vec3f& v); + + /** + * @fn void Matrixf::PostMultScale(const Vec3d& v); + * + * @brief Optimized version of postMult(scale(v)); + * + * @param v The Vec3d to process. + */ + void PostMultScale(const Vec3d& v); + + /** + * @fn void Matrixf::PostMultScale(const Vec3f& v); + * + * @brief Optimized version of postMult(scale(v)); + * + * @param v The Vec3f to process. + */ + void PostMultScale(const Vec3f& v); + + /** + * @fn void Matrixf::PreMultRotate(const Quat& q); + * + * @brief Optimized version of preMult(rotate(q)); + * + * @param q The Quat to process. + */ + void PreMultRotate(const Quat& q); + + /** + * @fn void Matrixf::PostMultRotate(const Quat& q); + * + * @brief Optimized version of postMult(rotate(q)); + * + * @param q The Quat to process. + */ + void PostMultRotate(const Quat& q); + + /** + * @fn std::string Matrixf::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * @fn static Matrixf Matrixf::Identity(void); + * + * @brief Static method to create an Identity matrix. + * + * @return A Matrixf. + */ + static Matrixf Identity(void); + + /** + * @fn static Matrixf Matrixf::Scale(const Vec3f& sv); + * + * @brief Static method to create a Scale matrix. + * + * @param sv The sv. + * + * @return A Matrixf. + */ + static Matrixf Scale(const Vec3f& sv); + + /** + * @fn static Matrixf Matrixf::Scale(const Vec3d& sv); + * + * @brief Static method to create a Scale matrix. + * + * @param sv The sv. + * + * @return A Matrixf. + */ + static Matrixf Scale(const Vec3d& sv); + + /** + * @fn static Matrixf Matrixf::Scale(value_type sx, value_type sy, value_type sz); + * + * @brief Static method to create a Scale matrix. + * + * @param sx The sx. + * @param sy The sy. + * @param sz The size. + * + * @return A Matrixf. + */ + static Matrixf Scale(value_type sx, value_type sy, value_type sz); + + /** + * @fn static Matrixf Matrixf::Translate(const Vec3f& dv); + * + * @brief Static method to create a Translate matrix. + * + * @param dv The dv. + * + * @return A Matrixf. + */ + static Matrixf Translate(const Vec3f& dv); + + /** + * @fn static Matrixf Matrixf::Translate(const Vec3d& dv); + * + * @brief Static method to create a Translate matrix. + * + * @param dv The dv. + * + * @return A Matrixf. + */ + static Matrixf Translate(const Vec3d& dv); + + /** + * @fn static Matrixf Matrixf::Translate(value_type x, value_type y, value_type z); + * + * @brief Static method to create a Translate matrix. + * + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + * + * @return A Matrixf. + */ + static Matrixf Translate(value_type x, value_type y, value_type z); + + /** + * @fn static Matrixf Matrixf::Rotate(const Vec3f& from, const Vec3f& to); + * + * @brief Static method to create a Rotational matrix. + * + * @param from Source for the. + * @param to to. + * + * @return A Matrixf. + */ + static Matrixf Rotate(const Vec3f& from, const Vec3f& to); + + /** + * @fn static Matrixf Matrixf::Rotate(const Vec3d& from, const Vec3d& to); + * + * @brief Static method to create a Rotational matrix. + * + * @param from Source for the. + * @param to to. + * + * @return A Matrixf. + */ + static Matrixf Rotate(const Vec3d& from, const Vec3d& to); + + /** + * @fn static Matrixf Matrixf::Rotate(value_type angle, value_type x, value_type y, value_type z); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param x The value_type to process. + * @param y The value_type to process. + * @param z The value_type to process. + * + * @return A Matrixf. + */ + static Matrixf Rotate(value_type angle, value_type x, value_type y, value_type z); + + /** + * @fn static Matrixf Matrixf::Rotate(value_type angle, const Vec3f& axis); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param axis The axis. + * + * @return A Matrixf. + */ + static Matrixf Rotate(value_type angle, const Vec3f& axis); + + /** + * @fn static Matrixf Matrixf::Rotate(value_type angle, const Vec3d& axis); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle The angle. + * @param axis The axis. + * + * @return A Matrixf. + */ + static Matrixf Rotate(value_type angle, const Vec3d& axis); + + /** + * @fn static Matrixf Matrixf::Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + * + * @return A Matrixf. + */ + static Matrixf Rotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @fn static Matrixf Matrixf::Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + * + * @brief Static method to create a Rotational matrix. + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + * + * @return A Matrixf. + */ + static Matrixf Rotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * @fn static Matrixf Matrixf::Rotate(const Quat& quat); + * + * @brief Static method to create a Rotational matrix. + * + * @param quat The quaternion. + * + * @return A Matrixf. + */ + static Matrixf Rotate(const Quat& quat); + + /** + * @fn static Matrixf Matrixf::Inverse(const Matrixf& matrix); + * + * @brief Static method to create an inverted matrix. + * + * @param matrix The matrix. + * + * @return A Matrixf. + */ + static Matrixf Inverse(const Matrixf& matrix); + + /** + * @fn static Matrixf Matrixf::OrthoNormal(const Matrixf& matrix); + * + * @brief Static method to create an Ortho Normalized matrix. + * + * @param matrix The matrix. + * + * @return A Matrixf. + */ + static Matrixf OrthoNormal(const Matrixf& matrix); + + /** + * @fn static Matrixf Matrixf::Ortho(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Create an orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Ortho(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn static Matrixf Matrixf::Ortho(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Create an orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Ortho(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn static Matrixf Matrixf::Ortho2D(double left, double right, double bottom, double top); + * + * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * + * @return A Matrixf. + */ + static Matrixf Ortho2D(double left, double right, double bottom, double top); + + /** + * @fn static Matrixf Matrixf::Ortho2D(float left, float right, float bottom, float top); + * + * @brief Create a 2D orthographic projection matrix. See glOrtho for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * + * @return A Matrixf. + */ + static Matrixf Ortho2D(float left, float right, float bottom, float top); + + /** + * @fn static Matrixf Matrixf::Frustum(double left, double right, double bottom, double top, double zNear, double zFar); + * + * @brief Create a perspective projection matrix. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Frustum(double left, double right, double bottom, double top, double zNear, double zFar); + + /** + * @fn static Matrixf Matrixf::Frustum(float left, float right, float bottom, float top, float zNear, float zFar); + * + * @brief Create a perspective projection matrix. See glFrustum for further details. + * + * @param left The left. + * @param right The right. + * @param bottom The bottom. + * @param top The top. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Frustum(float left, float right, float bottom, float top, float zNear, float zFar); + + /** + * @fn static Matrixf Matrixf::Perspective(float fovy, float aspectRatio, float zNear, float zFar); + * + * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further + * details. Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Perspective(float fovy, float aspectRatio, float zNear, float zFar); + + /** + * @fn static Matrixf Matrixf::Perspective(double fovy, double aspectRatio, double zNear, double zFar); + * + * @brief Create a symmetrical perspective projection matrix. See gluPerspective for further + * details. Aspect ratio is defined as width/height. + * + * @param fovy The fovy. + * @param aspectRatio The aspect ratio. + * @param zNear The near. + * @param zFar The far. + * + * @return A Matrixf. + */ + static Matrixf Perspective(double fovy, double aspectRatio, double zNear, double zFar); + + /** + * @fn static Matrixf Matrixf::LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + * + * @brief Create the position and orientation matrix as per a camera, using the same convention + * as gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + * + * @return A Matrixf. + */ + static Matrixf LookAt(const Vec3f& eye, const Vec3f& center, const Vec3f& up); + + /** + * @fn static Matrixf Matrixf::LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + * + * @brief Create the position and orientation matrix as per a camera, using the same convention + * as gluLookAt. + * + * @param eye The eye. + * @param center The center. + * @param up The up. + * + * @return A Matrixf. + */ + static Matrixf LookAt(const Vec3d& eye, const Vec3d& center, const Vec3d& up); + + /** + * @fn static Vec3f Matrixf::Transform3x3(const Vec3f& v, const Matrixf& m); + * + * @brief Apply a 3x3 transform of v*M[0..2,0..2]. + * + * @param v The Vec3f to process. + * @param m The Matrixf to process. + * + * @return A Vec3f. + */ + static Vec3f Transform3x3(const Vec3f& v, const Matrixf& m); + + /** + * @fn static Vec3d Matrixf::Transform3x3(const Vec3d& v, const Matrixf& m); + * + * @brief Apply a 3x3 transform of v*M[0..2,0..2]. + * + * @param v The Vec3d to process. + * @param m The Matrixf to process. + * + * @return A Vec3d. + */ + static Vec3d Transform3x3(const Vec3d& v, const Matrixf& m); + + /** + * @fn static Vec3f Matrixf::Transform3x3(const Matrixf& m, const Vec3f& v); + * + * @brief Apply a 3x3 transform of M[0..2,0..2]*v. + * + * @param m The Matrixf to process. + * @param v The Vec3f to process. + * + * @return A Vec3f. + */ + static Vec3f Transform3x3(const Matrixf& m, const Vec3f& v); + + /** + * @fn static Vec3d Matrixf::Transform3x3(const Matrixf& m, const Vec3d& v); + * + * @brief Apply a 3x3 transform of M[0..2,0..2]*v. + * + * @param m The Matrixf to process. + * @param v The Vec3d to process. + * + * @return A Vec3d. + */ + static Vec3d Transform3x3(const Matrixf& m, const Vec3d& v); + + /** + * @fn Matrixf& Matrixf::operator= (const Matrixf& rhs); + * + * @brief Set operator. + * + * @param rhs The right hand side. + * + * @return A shallow copy of this object. + */ + Matrixf& operator = (const Matrixf& rhs); + + /** + * @fn Matrixf& Matrixf::operator= (const Matrixd& rhs); + * + * @brief Set operator. + * + * @param rhs The right hand side. + * + * @return A shallow copy of this object. + */ + Matrixf& operator = (const Matrixd& rhs); + + /** + * @fn bool Matrixf::operator> (const Matrixf& m) const; + * + * @brief Greater than by operator. + * + * @param m The Matrixf to process. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator > (const Matrixf& m) const; + + /** + * @fn bool Matrixf::operator< (const Matrixf& m) const; + * + * @brief Less than by operator. + * + * @param m The Matrixf to process. + * + * @return True if the first parameter is less than the second. + */ + bool operator < (const Matrixf& m) const; + + /** + * @fn bool Matrixf::operator== (const Matrixf& m) const; + * + * @brief Equality operator. + * + * @param m The Matrixf to process. + * + * @return True if the parameters are considered equivalent. + */ + bool operator == (const Matrixf& m) const; + + /** + * @fn bool Matrixf::operator!= (const Matrixf& m) const; + * + * @brief Inequality operator. + * + * @param m The Matrixf to process. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator != (const Matrixf& m) const; + + /** + * @fn Vec3f Matrixf::operator* (const Vec3f& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec3f to process. + * + * @return The result of the operation. + */ + Vec3f operator* (const Vec3f& v) const; + + /** + * @fn Vec3d Matrixf::operator* (const Vec3d& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec3d to process. + * + * @return The result of the operation. + */ + Vec3d operator* (const Vec3d& v) const; + + /** + * @fn Vec4f Matrixf::operator* (const Vec4f& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec4f to process. + * + * @return The result of the operation. + */ + Vec4f operator* (const Vec4f& v) const; + + /** + * @fn Vec4d Matrixf::operator* (const Vec4d& v) const; + * + * @brief Multiply by vector. + * + * @param v The Vec4d to process. + * + * @return The result of the operation. + */ + Vec4d operator* (const Vec4d& v) const; + + /** + * @fn void Matrixf::operator*= (const Matrixf& other); + * + * @brief Unary Multiply by a matrix. + * + * @param other The other. + */ + void operator *= (const Matrixf& other); + + /** + * @fn Matrixf Matrixf::operator* (const Matrixf &m) const; + * + * @brief Multiply by a matrix. + * + * @param m The Matrixf to process. + * + * @return The result of the operation. + */ + Matrixf operator * (const Matrixf &m) const; + + /** + * @fn Matrixf Matrixf::operator* (value_type rhs) const; + * + * @brief Multiply by scalar. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf operator * (value_type rhs) const; + + /** + * @fn Matrixf& Matrixf::operator*= (value_type rhs); + * + * @brief Unary multiply by scalar. More efficient than *. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf& operator *= (value_type rhs); + + /** + * @fn Matrixf Matrixf::operator/ (value_type rhs) const; + * + * @brief Divide by scalar. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf operator / (value_type rhs) const; + + /** + * @fn Matrixf& Matrixf::operator/= (value_type rhs); + * + * @brief Unary divide by scalar. More efficient than /. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf& operator /= (value_type rhs); + + /** + * @fn Matrixf Matrixf::operator+ (const Matrixf& rhs) const; + * + * @brief Binary vector add. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf operator + (const Matrixf& rhs) const; + + /** + * @fn Matrixf& Matrixf::operator+= (const Matrixf& rhs); + * + * @brief Unary vector add. More efficient than +. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf& operator += (const Matrixf& rhs); + + /** + * @fn Matrixf Matrixf::operator- (const Matrixf& rhs) const; + * + * @brief Binary vector subtract. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf operator - (const Matrixf& rhs) const; + + /** + * @fn Matrixf& Matrixf::operator-= (const Matrixf& rhs); + * + * @brief Unary vector subtract. More efficient than -. + * + * @param rhs The right hand side. + * + * @return The result of the operation. + */ + Matrixf& operator -= (const Matrixf& rhs); + + /** + * @fn value_type& Matrixf::operator()(int row, int col); + * + * @brief Returns a specific row and column value of the matrix. + * + * @param row The row. + * @param col The col. + * + * @return The result of the operation. + */ + value_type& operator ()(int row, int col); + + /** + * @fn value_type Matrixf::operator()(int row, int col) const; + * + * @brief Returns a specific row and column value of the matrix. + * + * @param row The row. + * @param col The col. + * + * @return The result of the operation. + */ + value_type operator ()(int row, int col) const; + + /** + * @fn operator osg::Matrixf () const; + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixf () const; + + /** + * @fn operator osg::Matrixf& (); + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixf& (); + + /** + * @fn operator const osg::Matrixf& () const; + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return A const. + */ + operator const osg::Matrixf& () const; + + /** + * @fn operator osg::Matrixf* (); + * + * @brief Implicit conversion operator to OSG Matrix. + * + * @return The result of the operation. + */ + operator osg::Matrixf* (); + + protected: + + osg::Matrixf mMatrix; + }; + + /** + * @brief Stream insertion operator. + * + * @return The stream string result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Matrixf& q); } \ No newline at end of file diff --git a/include/trBase/NodeBase.h b/include/trBase/NodeBase.h index cd599a6..f3e3ad9 100644 --- a/include/trBase/NodeBase.h +++ b/include/trBase/NodeBase.h @@ -1,119 +1,119 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trBase -{ - - /** - * Base class for creating all the scenegraphs nodes. - * Internally it contains an OSG Node, that can be accessed by user if additional functionality is required. - */ - class TR_BASE_EXPORT NodeBase : public trBase::Base - { - public: - - using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * This is a set of bits (flags) that represent the Node. - * The default value is 0xffffffff (all bits set). - * - * The most common use of these is during traversal of the scene graph. - * - * For example, if a Node has a NodeMask value of 0x02 (only 2nd bit set) - * and the Camera has a CullMask of 0x4 (2nd bit not set) then during cull traversal, - * which takes it's TraversalMask from the Camera's CullMask, the node and any children - * would be ignored and thereby treated as "culled" and thus not rendered. - * Conversely, if the Camera CullMask were 0x3 (2nd bit set) then the node - * would be processed and child Nodes would be examined. - */ - using NodeMask = osg::Node::NodeMask; - - /** - * ctor - */ - NodeBase(const std::string name = CLASS_TYPE); - - /** - * Returns the class type - */ - virtual const std::string& GetType() const override; - - /** - * Sets this instances name - */ - virtual void SetName(const std::string& name); - - /** - * Returns a pointer to the internal OSG Node - */ - virtual osg::Node* AsOSGNode(); - - /** - * Returns a constant pointer to the internal OSG Node - */ - virtual const osg::Node* AsOSGNode() const; - - /** - * Returns the custom user data that could be stored in the class instance - * Note, that if the user did not set any data, a NULL will be returned - */ - virtual trBase::UserDataContainer* GetUserData(); - - /** - * Returns the custom user data that could be stored in the class instance - * Note, that if the user did not set any data, a NULL will be returned - */ - virtual const trBase::UserDataContainer* GetUserData() const; - - /** - * Sets the user data for the current instance - */ - virtual void SetUserData(trBase::UserDataContainer* data); - - protected: - - trBase::SmrtPtr mNode; - - /** - * dtor - */ - ~NodeBase(); - - private: - - trBase::SmrtPtr mUserData; - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trBase +{ + + /** + * Base class for creating all the scenegraphs nodes. + * Internally it contains an OSG Node, that can be accessed by user if additional functionality is required. + */ + class TR_BASE_EXPORT NodeBase : public trBase::Base + { + public: + + using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * This is a set of bits (flags) that represent the Node. + * The default value is 0xffffffff (all bits set). + * + * The most common use of these is during traversal of the scene graph. + * + * For example, if a Node has a NodeMask value of 0x02 (only 2nd bit set) + * and the Camera has a CullMask of 0x4 (2nd bit not set) then during cull traversal, + * which takes it's TraversalMask from the Camera's CullMask, the node and any children + * would be ignored and thereby treated as "culled" and thus not rendered. + * Conversely, if the Camera CullMask were 0x3 (2nd bit set) then the node + * would be processed and child Nodes would be examined. + */ + using NodeMask = osg::Node::NodeMask; + + /** + * ctor + */ + NodeBase(const std::string name = CLASS_TYPE); + + /** + * Returns the class type + */ + virtual const std::string& GetType() const override; + + /** + * Sets this instances name + */ + virtual void SetName(const std::string& name); + + /** + * Returns a pointer to the internal OSG Node + */ + virtual osg::Node* AsOSGNode(); + + /** + * Returns a constant pointer to the internal OSG Node + */ + virtual const osg::Node* AsOSGNode() const; + + /** + * Returns the custom user data that could be stored in the class instance + * Note, that if the user did not set any data, a NULL will be returned + */ + virtual trBase::UserDataContainer* GetUserData(); + + /** + * Returns the custom user data that could be stored in the class instance + * Note, that if the user did not set any data, a NULL will be returned + */ + virtual const trBase::UserDataContainer* GetUserData() const; + + /** + * Sets the user data for the current instance + */ + virtual void SetUserData(trBase::UserDataContainer* data); + + protected: + + trBase::SmrtPtr mNode; + + /** + * dtor + */ + ~NodeBase(); + + private: + + trBase::SmrtPtr mUserData; + }; +} + diff --git a/include/trBase/ObsrvrPtr.h b/include/trBase/ObsrvrPtr.h index 9be6ea7..e183f49 100644 --- a/include/trBase/ObsrvrPtr.h +++ b/include/trBase/ObsrvrPtr.h @@ -1,56 +1,56 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -namespace trBase -{ - /** - * An Observer Pointer. It holds a pointer to an object but does not own it, and does not delete it when destroyed. - * If the owner destroys the referenced pointer, the Observer Pointer is set to NULL - */ - template - class ObsrvrPtr : public osg::observer_ptr - { - public: - ObsrvrPtr() : osg::observer_ptr() - {} - - ObsrvrPtr(T* t) : osg::observer_ptr(t) - {} - - ObsrvrPtr(const osg::observer_ptr& rp) : osg::observer_ptr(rp) - {} - - /** - * Prints out the memory address of the held pointer - */ - friend inline std::ostream& operator<<(std::ostream& os, const ObsrvrPtr& rp) - { - os << rp.get(); - return os; - } - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +namespace trBase +{ + /** + * An Observer Pointer. It holds a pointer to an object but does not own it, and does not delete it when destroyed. + * If the owner destroys the referenced pointer, the Observer Pointer is set to NULL + */ + template + class ObsrvrPtr : public osg::observer_ptr + { + public: + ObsrvrPtr() : osg::observer_ptr() + {} + + ObsrvrPtr(T* t) : osg::observer_ptr(t) + {} + + ObsrvrPtr(const osg::observer_ptr& rp) : osg::observer_ptr(rp) + {} + + /** + * Prints out the memory address of the held pointer + */ + friend inline std::ostream& operator<<(std::ostream& os, const ObsrvrPtr& rp) + { + os << rp.get(); + return os; + } + }; } \ No newline at end of file diff --git a/include/trBase/Quat.h b/include/trBase/Quat.h index 907267b..af28a47 100644 --- a/include/trBase/Quat.h +++ b/include/trBase/Quat.h @@ -1,608 +1,608 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once -#include "Export.h" - -#include -#include -#include -#include - -#include - -#include -#include - -namespace trBase -{ - class Matrixd; - class Matrixf; - - /** - * @class Quat - * - * @brief Represents a quaternion, that is used for angular calculations and transformations. - */ - class TR_BASE_EXPORT Quat - { - public: - - using value_type = double; - - /** - * @brief Default constructor. - */ - Quat(); - - /** - * @brief Copy constructor. - * - * @param [in,out] q The Quat to process. - */ - Quat(const Quat& q); - - /** - * @brief Constructor. - * - * @param [in,out] q The osg::Quat to process. - */ - Quat(const osg::Quat& q); - - /** - * @brief Constructor. - * - * @param x The x to process. - * @param y The y to process. - * @param z The z to process. - * @param w The w to process. - */ - Quat(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Constructor. - * - * @param v The Vec4f to process. - */ - Quat(const Vec4f& v); - - /** - * @brief Constructor. - * - * @param v The Vec4d to process. - */ - Quat(const Vec4d& v); - - /** - * @brief Constructor. - * - * @param angle The angle. - * @param axis The axis. - */ - Quat(value_type angle, const Vec3f& axis); - - /** - * @brief Constructor. - * - * @param angle The angle. - * @param axis The axis. - */ - Quat(value_type angle, const Vec3d& axis); - - /** - * @brief Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. - * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - Quat(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @brief Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. - * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - Quat(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * Returns a reference to the internal OSG Quat. - */ - osg::Quat& GetOSGQuat(); - - /** - * Returns a reference to the internal OSG Quat. - */ - const osg::Quat& GetOSGQuat() const; - - /** - * @brief Converts this object to a vector 4. - * - * @return A Vec4d. - */ - Vec4d AsVec4() const; - - /** - * @brief Converts this object to a vector 3. - * - * @return A Vec3d. - */ - Vec3d AsVec3() const; - - /** - * @brief Sets the given q. - * - * @param [in,out] q The q to set. - */ - void Set(const Quat& q); - - /** - * @brief Sets the given q. - * - * @param [in,out] q The q to set. - */ - void Set(const osg::Quat& q); - - /** - * @brief Sets. - * - * @param x The x to process. - * @param y The y to process. - * @param z The z to process. - * @param w The w to process. - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Sets the given v. - * - * @param v The v to set. - */ - void Set(const Vec4f& v); - - /** - * @brief Sets the given v. - * - * @param v The v to set. - */ - void Set(const Vec4d& v); - - /** - * Sets the quaternion from the given matrix - */ - void Set(const Matrixf& matrix); - - /** - * Sets the quaternion from the given matrix - */ - void Set(const Matrixd& matrix); - - /** - * Sets the quaternion from the given matrix - */ - void Get(Matrixf& matrix) const; - - /** - * Sets the quaternion from the given matrix - */ - void Get(Matrixd& matrix) const; - - /** - * @brief Sets the given matrix. - * - * @param matrix The matrix to set. - */ - void Set(const osg::Matrixf& matrix); - - /** - * @brief Sets the given matrix. - * - * @param matrix The matrix to set. - */ - void Set(const osg::Matrixd& matrix); - - /** - * @brief Gets a the values of the internal matrix. - * - * @param [in,out] matrix The matrix to get. - */ - void Get(osg::Matrixf& matrix) const; - - /** - * @brief Gets a the values of the internal matrix. - * - * @param [in,out] matrix The matrix to get. - */ - void Get(osg::Matrixd& matrix) const; - - /** - * @brief return true if the Quat represents a zero rotation, and therefore can be ignored in - * computations. - * - * @return True if zero rotation, false if not. - */ - bool IsZeroRotation() const; - - /** - * @brief Length of the quaternion = sqrt( vec . vec ) - * - * @return A value_type. - */ - value_type Length() const; - - /** - * @brief (Length*Length) of the quaternion = vec . vec. - * - * @return A value_type. - */ - value_type Length2() const; - - /** - * @brief Conjugate. - * - * @return A Quat. - */ - trBase::Quat Conj() const; - - /** - * @brief Multiplicative inverse method: q^(-1) = q^* /(q.q^*) - * - * @return A const Quat. - */ - const trBase::Quat Inverse() const; - - /** - * @brief Set a quaternion which will perform a rotation of an angle around the axis given by - * the vector(x, y, z). - * - * @param angle The angle. - * @param x The x to process. - * @param y The y to process. - * @param z The z to process. - */ - void MakeRotate(value_type angle, value_type x, value_type y, value_type z); - - /** - * @brief Set a quaternion which will perform a rotation of an angle around the axis given by - * the vector(x, y, z). - * - * @param angle The angle. - * @param vec The vector. - */ - void MakeRotate(value_type angle, const Vec3f& vec); - - /** - * @brief Set a quaternion which will perform a rotation of an angle around the axis given by - * the vector(x, y, z). - * - * @param angle The angle. - * @param vec The vector. - */ - void MakeRotate(value_type angle, const Vec3d& vec); - - /** - * @brief Set a quaternion which will perform a rotation of an angles around three axes given by - * the vectors(x, y, z). - * Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. - * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); - - /** - * @brief Set a quaternion which will perform a rotation of an angles around three axes given by - * the vectors(x, y, z). - * Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. - * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) - * - * @param angle1 The first angle. - * @param axis1 The first axis. - * @param angle2 The second angle. - * @param axis2 The second axis. - * @param angle3 The third angle. - * @param axis3 The third axis. - */ - void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); - - /** - * @brief Make a rotation Quat which will rotate vec1 to vec2. Watch out for the two special - * cases when the vectors are co-incident or opposite in direction. - * This routine uses only fast geometric transforms, without costly acos/sin computations. - * It's exact, fast, and with less degenerate cases than the acos/sin method. - * - * For an explanation of the math used, you may see for example: - * http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf - * - * @param vec1 The first vector. - * @param vec2 The second vector. - */ - void MakeRotate(const Vec3f& vec1, const Vec3f& vec2); - - /** - * @brief Make a rotation Quat which will rotate vec1 to vec2. Watch out for the two special - * cases when the vectors are co-incident or opposite in direction. - * This routine uses only fast geometric transforms, without costly acos/sin computations. - * It's exact, fast, and with less degenerate cases than the acos/sin method. - * - * For an explanation of the math used, you may see for example: - * http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf - * - * @param vec1 The first vector. - * @param vec2 The second vector. - */ - void MakeRotate(const Vec3d& vec1, const Vec3d& vec2); - - /** - * @brief Return the angle and vector components represented by the quaternion. - * - * @param [in,out] angle The angle. - * @param [in,out] x The x to process. - * @param [in,out] y The y to process. - * @param [in,out] z The z to process. - */ - void GetRotate(value_type& angle, value_type& x, value_type& y, value_type& z) const; - - /** - * @brief Return the angle and vector represented by the quaternion. - * - * @param [in,out] angle The angle. - * @param [in,out] vec The vector. - */ - void GetRotate(value_type& angle, Vec3f& vec) const; - - /** - * @brief Return the angle and vector represented by the quaternion. - * - * @param [in,out] angle The angle. - * @param [in,out] vec The vector. - */ - void GetRotate(value_type& angle, Vec3d& vec) const; - - /** - * @fn void Quat::Clear(); - * - * @brief Clears this object to its blank/initial state. - */ - void Clear(); - - /** - * @brief Spherical Linear Interpolation. As t goes from 0 to 1, the Quat object goes from - * "from" to "to". - * - * @param t The value_type to process. - * @param from Source for the. - * @param to to. - */ - void Slerp(value_type t, const Quat& from, const Quat& to); - - /** - * Returns the X component of the quaternion/ - */ - value_type& X(); - - /** - * Returns the Y component of the quaternion/ - */ - value_type& Y(); - - /** - * Returns the Z component of the quaternion/ - */ - value_type& Z(); - - /** - * Returns the W component of the quaternion/ - */ - value_type& W(); - - /** - * Returns the X component of the quaternion/ - */ - value_type X() const; - - /** - * Returns the Y component of the quaternion/ - */ - value_type Y() const; - - /** - * Returns the Z component of the quaternion/ - */ - value_type Z() const; - - /** - * Returns the W component of the quaternion/ - */ - value_type W() const; - - /** - * Index operator - */ - value_type & operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - Quat& operator = (const Quat& v); - - /** - * Equals operator - */ - bool operator == (const Quat& v) const; - - /** - * Not equals operator - */ - bool operator != (const Quat& v) const; - - /** - * Less than operator - */ - bool operator < (const Quat& v) const; - - /** - * Greater than operator - */ - bool operator > (const Quat& v) const; - - /** - * Multiply by scalar - */ - const Quat operator * (value_type rhs) const; - - /** - * Rotate a vector by this quaternion. - */ - Vec3f operator* (const Vec3f& v) const; - - /** - * Rotate a vector by this quaternion. - */ - Vec3d operator* (const Vec3d& v) const; - - /** - * Unary multiply by scalar - */ - Quat& operator *= (value_type rhs); - - /** - * Binary multiply - */ - const Quat operator*(const Quat& rhs) const; - - /** - * Unary multiply - */ - Quat& operator*=(const Quat& rhs); - - /** - * Divide by scalar - */ - Quat operator / (value_type rhs) const; - - /** - * Unary divide by scalar - */ - Quat& operator /= (value_type rhs); - - /** - * Binary divide - */ - const Quat operator/(const Quat& denom) const; - - /** - * Unary divide - */ - Quat& operator/=(const Quat& denom); - - /** - * Binary addition - */ - const Quat operator + (const Quat& rhs) const; - - /** - * Unary addition - */ - Quat& operator += (const Quat& rhs); - - /** - * Binary subtraction - */ - const Quat operator - (const Quat& rhs) const; - - /** - * Unary subtraction - */ - Quat& operator -= (const Quat& rhs); - - /** - * Negation operator - returns the negative of the quaternion. - * Basically just calls operator - () on the Vec4 - */ - const Quat operator - () const; - - /** - * Implicit conversion operator to OSG Quaternion - */ - operator osg::Quat () const; - - /** - * Implicit conversion operator to OSG Quaternion - */ - operator osg::Quat& (); - - /** - * Implicit conversion operator to OSG Quaternion - */ - operator const osg::Quat& () const; - - /** - * Implicit conversion operator to OSG Quaternion - */ - operator osg::Quat* (); - - /** - * @fn std::string Quat::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - protected: - - osg::Quat mQuat; - }; - - /** - * @brief Stream insertion operator. - * - * @return The stream string result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Quat& q); -} - - - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once +#include "Export.h" + +#include +#include +#include +#include + +#include + +#include +#include + +namespace trBase +{ + class Matrixd; + class Matrixf; + + /** + * @class Quat + * + * @brief Represents a quaternion, that is used for angular calculations and transformations. + */ + class TR_BASE_EXPORT Quat + { + public: + + using value_type = double; + + /** + * @brief Default constructor. + */ + Quat(); + + /** + * @brief Copy constructor. + * + * @param [in,out] q The Quat to process. + */ + Quat(const Quat& q); + + /** + * @brief Constructor. + * + * @param [in,out] q The osg::Quat to process. + */ + Quat(const osg::Quat& q); + + /** + * @brief Constructor. + * + * @param x The x to process. + * @param y The y to process. + * @param z The z to process. + * @param w The w to process. + */ + Quat(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Constructor. + * + * @param v The Vec4f to process. + */ + Quat(const Vec4f& v); + + /** + * @brief Constructor. + * + * @param v The Vec4d to process. + */ + Quat(const Vec4d& v); + + /** + * @brief Constructor. + * + * @param angle The angle. + * @param axis The axis. + */ + Quat(value_type angle, const Vec3f& axis); + + /** + * @brief Constructor. + * + * @param angle The angle. + * @param axis The axis. + */ + Quat(value_type angle, const Vec3d& axis); + + /** + * @brief Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. + * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + Quat(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @brief Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. + * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + Quat(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * Returns a reference to the internal OSG Quat. + */ + osg::Quat& GetOSGQuat(); + + /** + * Returns a reference to the internal OSG Quat. + */ + const osg::Quat& GetOSGQuat() const; + + /** + * @brief Converts this object to a vector 4. + * + * @return A Vec4d. + */ + Vec4d AsVec4() const; + + /** + * @brief Converts this object to a vector 3. + * + * @return A Vec3d. + */ + Vec3d AsVec3() const; + + /** + * @brief Sets the given q. + * + * @param [in,out] q The q to set. + */ + void Set(const Quat& q); + + /** + * @brief Sets the given q. + * + * @param [in,out] q The q to set. + */ + void Set(const osg::Quat& q); + + /** + * @brief Sets. + * + * @param x The x to process. + * @param y The y to process. + * @param z The z to process. + * @param w The w to process. + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Sets the given v. + * + * @param v The v to set. + */ + void Set(const Vec4f& v); + + /** + * @brief Sets the given v. + * + * @param v The v to set. + */ + void Set(const Vec4d& v); + + /** + * Sets the quaternion from the given matrix + */ + void Set(const Matrixf& matrix); + + /** + * Sets the quaternion from the given matrix + */ + void Set(const Matrixd& matrix); + + /** + * Sets the quaternion from the given matrix + */ + void Get(Matrixf& matrix) const; + + /** + * Sets the quaternion from the given matrix + */ + void Get(Matrixd& matrix) const; + + /** + * @brief Sets the given matrix. + * + * @param matrix The matrix to set. + */ + void Set(const osg::Matrixf& matrix); + + /** + * @brief Sets the given matrix. + * + * @param matrix The matrix to set. + */ + void Set(const osg::Matrixd& matrix); + + /** + * @brief Gets a the values of the internal matrix. + * + * @param [in,out] matrix The matrix to get. + */ + void Get(osg::Matrixf& matrix) const; + + /** + * @brief Gets a the values of the internal matrix. + * + * @param [in,out] matrix The matrix to get. + */ + void Get(osg::Matrixd& matrix) const; + + /** + * @brief return true if the Quat represents a zero rotation, and therefore can be ignored in + * computations. + * + * @return True if zero rotation, false if not. + */ + bool IsZeroRotation() const; + + /** + * @brief Length of the quaternion = sqrt( vec . vec ) + * + * @return A value_type. + */ + value_type Length() const; + + /** + * @brief (Length*Length) of the quaternion = vec . vec. + * + * @return A value_type. + */ + value_type Length2() const; + + /** + * @brief Conjugate. + * + * @return A Quat. + */ + trBase::Quat Conj() const; + + /** + * @brief Multiplicative inverse method: q^(-1) = q^* /(q.q^*) + * + * @return A const Quat. + */ + const trBase::Quat Inverse() const; + + /** + * @brief Set a quaternion which will perform a rotation of an angle around the axis given by + * the vector(x, y, z). + * + * @param angle The angle. + * @param x The x to process. + * @param y The y to process. + * @param z The z to process. + */ + void MakeRotate(value_type angle, value_type x, value_type y, value_type z); + + /** + * @brief Set a quaternion which will perform a rotation of an angle around the axis given by + * the vector(x, y, z). + * + * @param angle The angle. + * @param vec The vector. + */ + void MakeRotate(value_type angle, const Vec3f& vec); + + /** + * @brief Set a quaternion which will perform a rotation of an angle around the axis given by + * the vector(x, y, z). + * + * @param angle The angle. + * @param vec The vector. + */ + void MakeRotate(value_type angle, const Vec3d& vec); + + /** + * @brief Set a quaternion which will perform a rotation of an angles around three axes given by + * the vectors(x, y, z). + * Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. + * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3f& axis1, value_type angle2, const Vec3f& axis2, value_type angle3, const Vec3f& axis3); + + /** + * @brief Set a quaternion which will perform a rotation of an angles around three axes given by + * the vectors(x, y, z). + * Creates a quaternion after making three individual quaternions, one for each angle and axis, and multiplying them together. + * Q = q(angle1, axis1)*q(angle2, axis2)*q(angle3, axis3) + * + * @param angle1 The first angle. + * @param axis1 The first axis. + * @param angle2 The second angle. + * @param axis2 The second axis. + * @param angle3 The third angle. + * @param axis3 The third axis. + */ + void MakeRotate(value_type angle1, const Vec3d& axis1, value_type angle2, const Vec3d& axis2, value_type angle3, const Vec3d& axis3); + + /** + * @brief Make a rotation Quat which will rotate vec1 to vec2. Watch out for the two special + * cases when the vectors are co-incident or opposite in direction. + * This routine uses only fast geometric transforms, without costly acos/sin computations. + * It's exact, fast, and with less degenerate cases than the acos/sin method. + * + * For an explanation of the math used, you may see for example: + * http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf + * + * @param vec1 The first vector. + * @param vec2 The second vector. + */ + void MakeRotate(const Vec3f& vec1, const Vec3f& vec2); + + /** + * @brief Make a rotation Quat which will rotate vec1 to vec2. Watch out for the two special + * cases when the vectors are co-incident or opposite in direction. + * This routine uses only fast geometric transforms, without costly acos/sin computations. + * It's exact, fast, and with less degenerate cases than the acos/sin method. + * + * For an explanation of the math used, you may see for example: + * http://logiciels.cnes.fr/MARMOTTES/marmottes-mathematique.pdf + * + * @param vec1 The first vector. + * @param vec2 The second vector. + */ + void MakeRotate(const Vec3d& vec1, const Vec3d& vec2); + + /** + * @brief Return the angle and vector components represented by the quaternion. + * + * @param [in,out] angle The angle. + * @param [in,out] x The x to process. + * @param [in,out] y The y to process. + * @param [in,out] z The z to process. + */ + void GetRotate(value_type& angle, value_type& x, value_type& y, value_type& z) const; + + /** + * @brief Return the angle and vector represented by the quaternion. + * + * @param [in,out] angle The angle. + * @param [in,out] vec The vector. + */ + void GetRotate(value_type& angle, Vec3f& vec) const; + + /** + * @brief Return the angle and vector represented by the quaternion. + * + * @param [in,out] angle The angle. + * @param [in,out] vec The vector. + */ + void GetRotate(value_type& angle, Vec3d& vec) const; + + /** + * @fn void Quat::Clear(); + * + * @brief Clears this object to its blank/initial state. + */ + void Clear(); + + /** + * @brief Spherical Linear Interpolation. As t goes from 0 to 1, the Quat object goes from + * "from" to "to". + * + * @param t The value_type to process. + * @param from Source for the. + * @param to to. + */ + void Slerp(value_type t, const Quat& from, const Quat& to); + + /** + * Returns the X component of the quaternion/ + */ + value_type& X(); + + /** + * Returns the Y component of the quaternion/ + */ + value_type& Y(); + + /** + * Returns the Z component of the quaternion/ + */ + value_type& Z(); + + /** + * Returns the W component of the quaternion/ + */ + value_type& W(); + + /** + * Returns the X component of the quaternion/ + */ + value_type X() const; + + /** + * Returns the Y component of the quaternion/ + */ + value_type Y() const; + + /** + * Returns the Z component of the quaternion/ + */ + value_type Z() const; + + /** + * Returns the W component of the quaternion/ + */ + value_type W() const; + + /** + * Index operator + */ + value_type & operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + Quat& operator = (const Quat& v); + + /** + * Equals operator + */ + bool operator == (const Quat& v) const; + + /** + * Not equals operator + */ + bool operator != (const Quat& v) const; + + /** + * Less than operator + */ + bool operator < (const Quat& v) const; + + /** + * Greater than operator + */ + bool operator > (const Quat& v) const; + + /** + * Multiply by scalar + */ + const Quat operator * (value_type rhs) const; + + /** + * Rotate a vector by this quaternion. + */ + Vec3f operator* (const Vec3f& v) const; + + /** + * Rotate a vector by this quaternion. + */ + Vec3d operator* (const Vec3d& v) const; + + /** + * Unary multiply by scalar + */ + Quat& operator *= (value_type rhs); + + /** + * Binary multiply + */ + const Quat operator*(const Quat& rhs) const; + + /** + * Unary multiply + */ + Quat& operator*=(const Quat& rhs); + + /** + * Divide by scalar + */ + Quat operator / (value_type rhs) const; + + /** + * Unary divide by scalar + */ + Quat& operator /= (value_type rhs); + + /** + * Binary divide + */ + const Quat operator/(const Quat& denom) const; + + /** + * Unary divide + */ + Quat& operator/=(const Quat& denom); + + /** + * Binary addition + */ + const Quat operator + (const Quat& rhs) const; + + /** + * Unary addition + */ + Quat& operator += (const Quat& rhs); + + /** + * Binary subtraction + */ + const Quat operator - (const Quat& rhs) const; + + /** + * Unary subtraction + */ + Quat& operator -= (const Quat& rhs); + + /** + * Negation operator - returns the negative of the quaternion. + * Basically just calls operator - () on the Vec4 + */ + const Quat operator - () const; + + /** + * Implicit conversion operator to OSG Quaternion + */ + operator osg::Quat () const; + + /** + * Implicit conversion operator to OSG Quaternion + */ + operator osg::Quat& (); + + /** + * Implicit conversion operator to OSG Quaternion + */ + operator const osg::Quat& () const; + + /** + * Implicit conversion operator to OSG Quaternion + */ + operator osg::Quat* (); + + /** + * @fn std::string Quat::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + protected: + + osg::Quat mQuat; + }; + + /** + * @brief Stream insertion operator. + * + * @return The stream string result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Quat& q); +} + + + + diff --git a/include/trBase/SmrtClass.h b/include/trBase/SmrtClass.h index bd5f6fe..fc3540d 100644 --- a/include/trBase/SmrtClass.h +++ b/include/trBase/SmrtClass.h @@ -1,167 +1,158 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include - -namespace trBase -{ - /** - * This class is part of the internal garbage collection system. Anything that inherits it can also use the - * smart pointer interface (trBase::SmrtPtr) - * - * It inherits osg::Referenced and uses the OSG garbage collection in its core - */ - class TR_BASE_EXPORT SmrtClass : public osg::Referenced - { - public: - - using BaseClass = osg::Referenced; /// Adds an easy and swappable access to the base class - - /** - * @fn SmrtClass::SmrtClass() : osg::Referenced() - * - * @brief Default constructor. - */ - SmrtClass() : osg::Referenced() - {} - - /** - * @fn explicit SmrtClass::SmrtClass(bool threadSafeRefUnref) : osg::Referenced(threadSafeRefUnref) - * - * @brief Constructor. - * - * @param threadSafeRefUnref True to thread safe reference unref. - */ - explicit SmrtClass(bool threadSafeRefUnref) : osg::Referenced(threadSafeRefUnref) - {} - - /** - * @fn SmrtClass::SmrtClass(const SmrtClass& inst) : osg::Referenced(inst) - * - * @brief Copy constructor. - * - * @param inst The instance. - */ - SmrtClass(const SmrtClass& inst) : osg::Referenced(inst) - {} - - /** - * @fn virtual void SmrtClass::SetThreadSafeRefUnref(bool threadSafe); - * - * @brief Set whether to use a mutex to ensure Ref() and UnRef() are thread safe. - * - * @param threadSafe True to thread safe. - */ - virtual void SetThreadSafeRefUnref(bool threadSafe); - - /** - * @fn virtual bool SmrtClass::GetThreadSafeRefUnref(); - * - * @brief Get whether a mutex is used to ensure Ref() and UnRef() are thread safe. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetThreadSafeRefUnref(); - - /** - * @fn OpenThreads::Mutex* SmrtClass::GetRefMutex() const; - * - * @brief Get the mutex used to ensure thread safety of Ref()/UnRef(). - * - * @return Null if it fails, else the reference mutex. - */ - OpenThreads::Mutex* GetRefMutex() const; - - /** - * @fn static OpenThreads::Mutex* SmrtClass::GetGlobalReferencedMutex(); - * - * @brief Get the optional global Referenced mutex, this can be shared between all - * trBase::SmrtClass. - * - * @return Null if it fails, else the global referenced mutex. - */ - static OpenThreads::Mutex* GetGlobalReferencedMutex(); - - /** - * @fn inline int SmrtClass::Ref() const; - * - * @brief Increment the reference count by one, indicating that this object has another pointer - * which is referencing it. - * - * @return An int. - */ - inline int Ref() const; - - /** - * @fn inline int SmrtClass::Unref() const; - * - * @brief Decrement the reference count by one, indicating that a pointer to this object is no - * longer referencing it. If the reference count goes to zero, it is assumed that this - * object is no longer referenced and is automatically deleted. - * - * @return An int. - */ - inline int Unref() const; - - /** - * @fn int SmrtClass::UnRefNoDelete() const; - * - * @brief Decrement the reference count by one, indicating that a pointer to this object is no - * longer referencing it. However, do not delete it, even if ref count goes to 0. - * Warning, UnRefNoDelete() should only be called if the user knows exactly who will be - * responsible for it, one should prefer UnRef() over UnRefNoDelete() as the latter can - * lead to memory leaks. - * - * @return An int. - */ - int UnRefNoDelete() const; - - /** - * @fn inline int SmrtClass::ReferenceCount() const; - * - * @brief Return the number of pointers currently referencing this object. - * - * @return An int. - */ - inline int ReferenceCount() const; - - /** - * @fn virtual const std::string& SmrtClass::GetType() const = 0; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const = 0; - - protected: - ~SmrtClass() - {} - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include + +namespace trBase +{ + /** + * This class is part of the internal garbage collection system. Anything that inherits it can also use the + * smart pointer interface (trBase::SmrtPtr) + * + * It inherits osg::Referenced and uses the OSG garbage collection in its core + */ + class TR_BASE_EXPORT SmrtClass : public osg::Referenced + { + public: + + using BaseClass = osg::Referenced; /// Adds an easy and swappable access to the base class + + /** + * @fn SmrtClass::SmrtClass() : osg::Referenced() + * + * @brief Default constructor. + */ + SmrtClass() : osg::Referenced() + {} + + /** + * @fn explicit SmrtClass::SmrtClass(bool threadSafeRefUnref) : osg::Referenced(threadSafeRefUnref) + * + * @brief Constructor. + * + * @param threadSafeRefUnref True to thread safe reference unref. + */ + explicit SmrtClass(bool threadSafeRefUnref) : osg::Referenced(threadSafeRefUnref) + {} + + /** + * @fn SmrtClass::SmrtClass(const SmrtClass& inst) : osg::Referenced(inst) + * + * @brief Copy constructor. + * + * @param inst The instance. + */ + SmrtClass(const SmrtClass& inst) : osg::Referenced(inst) + {} + + /** + * @fn virtual bool SmrtClass::GetThreadSafeRefUnref(); + * + * @brief Get whether a mutex is used to ensure Ref() and UnRef() are thread safe. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetThreadSafeRefUnref(); + + /** + * @fn OpenThreads::Mutex* SmrtClass::GetRefMutex() const; + * + * @brief Get the mutex used to ensure thread safety of Ref()/UnRef(). + * + * @return Null if it fails, else the reference mutex. + */ + OpenThreads::Mutex* GetRefMutex() const; + + /** + * @fn static OpenThreads::Mutex* SmrtClass::GetGlobalReferencedMutex(); + * + * @brief Get the optional global Referenced mutex, this can be shared between all + * trBase::SmrtClass. + * + * @return Null if it fails, else the global referenced mutex. + */ + static OpenThreads::Mutex* GetGlobalReferencedMutex(); + + /** + * @fn inline int SmrtClass::Ref() const; + * + * @brief Increment the reference count by one, indicating that this object has another pointer + * which is referencing it. + * + * @return An int. + */ + inline int Ref() const; + + /** + * @fn inline int SmrtClass::Unref() const; + * + * @brief Decrement the reference count by one, indicating that a pointer to this object is no + * longer referencing it. If the reference count goes to zero, it is assumed that this + * object is no longer referenced and is automatically deleted. + * + * @return An int. + */ + inline int Unref() const; + + /** + * @fn int SmrtClass::UnRefNoDelete() const; + * + * @brief Decrement the reference count by one, indicating that a pointer to this object is no + * longer referencing it. However, do not delete it, even if ref count goes to 0. + * Warning, UnRefNoDelete() should only be called if the user knows exactly who will be + * responsible for it, one should prefer UnRef() over UnRefNoDelete() as the latter can + * lead to memory leaks. + * + * @return An int. + */ + int UnRefNoDelete() const; + + /** + * @fn inline int SmrtClass::ReferenceCount() const; + * + * @brief Return the number of pointers currently referencing this object. + * + * @return An int. + */ + inline int ReferenceCount() const; + + /** + * @fn virtual const std::string& SmrtClass::GetType() const = 0; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const = 0; + + protected: + ~SmrtClass() + {} + }; +} + + diff --git a/include/trBase/SmrtPtr.h b/include/trBase/SmrtPtr.h index 83b5d20..701e8e8 100644 --- a/include/trBase/SmrtPtr.h +++ b/include/trBase/SmrtPtr.h @@ -1,231 +1,231 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include - -namespace trBase -{ - /** - * Smart pointer for handling referenced counted objects. - */ - template - class SmrtPtr - { - public: - - /** - * @fn SmrtPtr::SmrtPtr(); - * - * @brief Default constructor. - */ - SmrtPtr() { mOSGSmartPtr = nullptr; } - - /** - * @fn SmrtPtr::SmrtPtr(T* t); - * - * @brief Constructor. - * - * @param [in,out] t If non-null, the T to process. - */ - SmrtPtr(T* t) { mOSGSmartPtr = t;} - - - /** - * @fn SmrtPtr::SmrtPtr(const SmrtPtr& smPt); - * - * @brief Copy constructor. - * - * @param smPt The sm point. - */ - SmrtPtr(const SmrtPtr& smPt) { mOSGSmartPtr = smPt.Get(); } - - /** - * @fn T* SmrtPtr::Get() const; - * - * @brief Returns the stored internal pointer - * - * @return Null if it fails, else a pointer to a T. - */ - T* Get() const { return mOSGSmartPtr.get(); } - - /** - * @fn T* SmrtPtr::Release(); - * - * @brief Release the pointer from ownership by this SmrtPtr<>, decrementing the objects - * refenced count to prevent the object from being deleted even if the reference count - * goes to zero. When using Release() you are implicitly expecting other code to take - * over management of the object, otherwise a memory leak will result. - * - * @return Null if it fails, else a pointer to a T. - */ - T* Release() { return mOSGSmartPtr.release(); } - - /** - * @fn void SmrtPtr::Swap(SmrtPtr& sp); - * - * @brief Swaps the internal pointer of this and the passed in SmartPtr. - * - * @param [in,out] sp The smart ppointer. - */ - void Swap(SmrtPtr& sp) { mOSGSmartPtr.swap(sp); } - - /** - * @fn bool SmrtPtr::Valid() const; - * - * @brief Returns True if the smart pointer has a valid internal pointer set - * - * @return True if it succeeds, false if it fails. - */ - bool Valid() const { return mOSGSmartPtr.valid(); } - - /** - * @fn bool SmrtPtr::operator!() const; - * - * @brief Logical negation operator. - * - * @return The logical inverse of this value. - */ - bool operator ! () const { return mOSGSmartPtr.operator!(); } - - /** - * @fn T& SmrtPtr::operator*() const; - * - * @brief Dereferences the internal pointer - * - * @return The result of the operation. - */ - T& operator * () const { return mOSGSmartPtr.operator*(); } - - /** - * @fn T* SmrtPtr::operator->() const; - * - * @brief Access to the internal pointer - * - * @return The dereferenced object. - */ - T* operator -> () const { return mOSGSmartPtr.get(); } - - /** - * @fn operator SmrtPtr::T*() const; - * - * @brief Implicit conversion operator to a pointer. - * - * @return The internal pointer - */ - operator T* () const { return mOSGSmartPtr; } - - /** - * @fn operator osg::ref_ptr () const - * - * @brief Implicit conversion operator to OSG ref_ptr. - * - * @tparam T Generic type parameter. - * - * @return The OSG smart pointer - */ - operator osg::ref_ptr () const { return mOSGSmartPtr;} - - /** - * @fn operator osg::ref_ptr& () - * - * @brief Implicit conversion operator to OSG ref_ptr. - * - * @tparam T Generic type parameter. - * - * @return The OSG smart pointer - */ - operator osg::ref_ptr& () { return mOSGSmartPtr; } - - /** - * @fn operator const osg::ref_ptr& () const - * - * @brief Implicit conversion operator to OSG ref_ptr. - * - * @tparam T Generic type parameter. - * - * @return The OSG smart pointer - */ - operator const osg::ref_ptr& () const { return mOSGSmartPtr; } - - /** - * @fn operator osg::ref_ptr* () - * - * @brief Implicit conversion operator to OSG ref_ptr. - * - * @tparam T Generic type parameter. - * - * @return The OSG smart pointer - */ - operator osg::ref_ptr* () { return &mOSGSmartPtr; } - - /** - * @fn friend inline std::ostream& SmrtPtr::operator<<(std::ostream& ios, const SmrtPtr& smPt) - * - * @brief Prints out the memory address of the held pointer. - * - * @param [in,out] ios The ios. - * @param smPt The smart pointer. - * - * @return A streamed output - */ - friend inline std::ostream& operator<<(std::ostream& ios, const SmrtPtr& smPt) - { - ios << smPt.get(); - return ios; - } - - private: - - osg::ref_ptr mOSGSmartPtr; //Pointer to the internal OSG smart pointer - - }; -} - -namespace trUtil -{ - /** - * @brief Hash function for hashing trBase::SmrtPtr - */ - template struct hash > - { - size_t operator()(const trBase::SmrtPtr<_Key>& keyPtr) const - { - return size_t(keyPtr.Get()); - } - }; - - /** - * @brief Hash function for hashing osg::ref_ptr - */ - template struct hash > - { - size_t operator()(const trBase::SmrtPtr<_Key>& keyPtr) const - { - return size_t(keyPtr.Get()); - } - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include + +namespace trBase +{ + /** + * Smart pointer for handling referenced counted objects. + */ + template + class SmrtPtr + { + public: + + /** + * @fn SmrtPtr::SmrtPtr(); + * + * @brief Default constructor. + */ + SmrtPtr() { mOSGSmartPtr = nullptr; } + + /** + * @fn SmrtPtr::SmrtPtr(T* t); + * + * @brief Constructor. + * + * @param [in,out] t If non-null, the T to process. + */ + SmrtPtr(T* t) { mOSGSmartPtr = t;} + + + /** + * @fn SmrtPtr::SmrtPtr(const SmrtPtr& smPt); + * + * @brief Copy constructor. + * + * @param smPt The sm point. + */ + SmrtPtr(const SmrtPtr& smPt) { mOSGSmartPtr = smPt.Get(); } + + /** + * @fn T* SmrtPtr::Get() const; + * + * @brief Returns the stored internal pointer + * + * @return Null if it fails, else a pointer to a T. + */ + T* Get() const { return mOSGSmartPtr.get(); } + + /** + * @fn T* SmrtPtr::Release(); + * + * @brief Release the pointer from ownership by this SmrtPtr<>, decrementing the objects + * refenced count to prevent the object from being deleted even if the reference count + * goes to zero. When using Release() you are implicitly expecting other code to take + * over management of the object, otherwise a memory leak will result. + * + * @return Null if it fails, else a pointer to a T. + */ + T* Release() { return mOSGSmartPtr.release(); } + + /** + * @fn void SmrtPtr::Swap(SmrtPtr& sp); + * + * @brief Swaps the internal pointer of this and the passed in SmartPtr. + * + * @param [in,out] sp The smart ppointer. + */ + void Swap(SmrtPtr& sp) { mOSGSmartPtr.swap(sp); } + + /** + * @fn bool SmrtPtr::Valid() const; + * + * @brief Returns True if the smart pointer has a valid internal pointer set + * + * @return True if it succeeds, false if it fails. + */ + bool Valid() const { return mOSGSmartPtr.valid(); } + + /** + * @fn bool SmrtPtr::operator!() const; + * + * @brief Logical negation operator. + * + * @return The logical inverse of this value. + */ + bool operator ! () const { return mOSGSmartPtr.operator!(); } + + /** + * @fn T& SmrtPtr::operator*() const; + * + * @brief Dereferences the internal pointer + * + * @return The result of the operation. + */ + T& operator * () const { return mOSGSmartPtr.operator*(); } + + /** + * @fn T* SmrtPtr::operator->() const; + * + * @brief Access to the internal pointer + * + * @return The dereferenced object. + */ + T* operator -> () const { return mOSGSmartPtr.get(); } + + /** + * @fn operator SmrtPtr::T*() const; + * + * @brief Implicit conversion operator to a pointer. + * + * @return The internal pointer + */ + operator T* () const { return mOSGSmartPtr; } + + /** + * @fn operator osg::ref_ptr () const + * + * @brief Implicit conversion operator to OSG ref_ptr. + * + * @tparam T Generic type parameter. + * + * @return The OSG smart pointer + */ + operator osg::ref_ptr () const { return mOSGSmartPtr;} + + /** + * @fn operator osg::ref_ptr& () + * + * @brief Implicit conversion operator to OSG ref_ptr. + * + * @tparam T Generic type parameter. + * + * @return The OSG smart pointer + */ + operator osg::ref_ptr& () { return mOSGSmartPtr; } + + /** + * @fn operator const osg::ref_ptr& () const + * + * @brief Implicit conversion operator to OSG ref_ptr. + * + * @tparam T Generic type parameter. + * + * @return The OSG smart pointer + */ + operator const osg::ref_ptr& () const { return mOSGSmartPtr; } + + /** + * @fn operator osg::ref_ptr* () + * + * @brief Implicit conversion operator to OSG ref_ptr. + * + * @tparam T Generic type parameter. + * + * @return The OSG smart pointer + */ + operator osg::ref_ptr* () { return &mOSGSmartPtr; } + + /** + * @fn friend inline std::ostream& SmrtPtr::operator<<(std::ostream& ios, const SmrtPtr& smPt) + * + * @brief Prints out the memory address of the held pointer. + * + * @param [in,out] ios The ios. + * @param smPt The smart pointer. + * + * @return A streamed output + */ + friend inline std::ostream& operator<<(std::ostream& ios, const SmrtPtr& smPt) + { + ios << smPt.get(); + return ios; + } + + private: + + osg::ref_ptr mOSGSmartPtr; //Pointer to the internal OSG smart pointer + + }; +} + +namespace trUtil +{ + /** + * @brief Hash function for hashing trBase::SmrtPtr + */ + template struct hash > + { + size_t operator()(const trBase::SmrtPtr<_Key>& keyPtr) const + { + return size_t(keyPtr.Get()); + } + }; + + /** + * @brief Hash function for hashing osg::ref_ptr + */ + template struct hash > + { + size_t operator()(const trBase::SmrtPtr<_Key>& keyPtr) const + { + return size_t(keyPtr.Get()); + } + }; } \ No newline at end of file diff --git a/include/trBase/UniqueId.h b/include/trBase/UniqueId.h index d2c5c25..decd1f2 100644 --- a/include/trBase/UniqueId.h +++ b/include/trBase/UniqueId.h @@ -27,8 +27,6 @@ #include #include -#include - #include #include #include @@ -69,7 +67,7 @@ namespace trBase /** * dtor */ - virtual ~UniqueId() {} + virtual ~UniqueId(); /** * Returns the class type @@ -159,7 +157,7 @@ namespace trBase bool operator> (const UniqueId& id) const; protected: - bID::uuids::uuid mGUID; + implId* mGUIDPtr = nullptr; }; //////////////////////////////////////////////////// diff --git a/include/trBase/UniqueIdBoost.h b/include/trBase/UniqueIdBoost.h index 0a23085..0e35a46 100644 --- a/include/trBase/UniqueIdBoost.h +++ b/include/trBase/UniqueIdBoost.h @@ -1,34 +1,34 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -/* - * This is a helper header that is used to generate the needed boost UUID subset. - * The include headers here should not be resolved, and this header should not be - * included or used by anything except Boost BCP - */ - -#include -#include -#include -#include +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +/* + * This is a helper header that is used to generate the needed boost UUID subset. + * The include headers here should not be resolved, and this header should not be + * included or used by anything except Boost BCP + */ + +#include +#include +#include +#include #include \ No newline at end of file diff --git a/include/trBase/UserDataContainer.h b/include/trBase/UserDataContainer.h index a9c2b20..f08988e 100644 --- a/include/trBase/UserDataContainer.h +++ b/include/trBase/UserDataContainer.h @@ -1,155 +1,155 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include -#include - -#include -#include - -namespace trBase -{ - /** - * This class hold custom user data. - * Since all the objects in this class can be different, it is strongly encouraged to use - * the Description field to note what objects are stored in the instance. - */ - class TR_BASE_EXPORT UserDataContainer : public trBase::Base - { - public: - - using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * ctor - */ - UserDataContainer(const std::string name = CLASS_TYPE); - - /** - * Returns the class type - */ - virtual const std::string& GetType() const override; - - /** - * Returns the user data object - */ - virtual trBase::SmrtClass* GetUserDataContainer(); - - /** - * Returns the user data object - */ - virtual const trBase::SmrtClass* GetUserDataContainer() const; - - /** - * Sets the user data object - */ - virtual void SetUserDataContainer(trBase::SmrtClass* data); - - /** - * Returns a list of Description strings - */ - virtual std::vector GetDescriptionList(); - - /** - * Returns a list of Description strings - */ - virtual const std::vector GetDescriptionList() const; - - /** - * Returns the number of objects stored in the Description list - */ - virtual int GetDescriptionListCount(); - - /** - * Returns the specified description. Returns the first one if no index is specified - */ - virtual std::string GetDescription(int index = 0); - - /** - * Returns the specified description. Returns the first one if no index is specified - */ - virtual const std::string GetDescription(int index = 0) const; - - /** - * Adds a new description string to the list of descriptions - */ - virtual void AddDescription(std::string description); - - /** - * Set a new list of descriptions strings - */ - virtual void SetDescriptions(std::vector descriptions); - - /** - * Returns the list of all the user objects cast down to Base class. - */ - virtual std::vector> GetObjectList(); - - /** - * Returns the list of all the user objects cast down to Base class. - */ - virtual const std::vector> GetObjectList() const; - - /** - * Returns the number of objects stored in the Object list - */ - virtual int GetObjectListCount(); - - /** - * Returns the specified object. Returns the first one if no index is specified - */ - virtual trBase::SmrtPtr GetObject(int index = 0); - - /** - * Returns the specified object. Returns the first one if no index is specified - */ - virtual const trBase::SmrtPtr GetObject(int index = 0) const; - - /** - * Adds a new object to the object list - */ - virtual void AddObject(trBase::SmrtPtr obj); - - /** - * Set a new list of objects - */ - virtual void SetObjects(std::vector> objList); - - protected: - - trBase::SmrtPtr mUserDataContainer; - std::vector mDescriptionList; - std::vector> mObjectList; - - /** - * dtor - */ - ~UserDataContainer(); - }; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include +#include + +#include +#include + +namespace trBase +{ + /** + * This class hold custom user data. + * Since all the objects in this class can be different, it is strongly encouraged to use + * the Description field to note what objects are stored in the instance. + */ + class TR_BASE_EXPORT UserDataContainer : public trBase::Base + { + public: + + using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * ctor + */ + UserDataContainer(const std::string name = CLASS_TYPE); + + /** + * Returns the class type + */ + virtual const std::string& GetType() const override; + + /** + * Returns the user data object + */ + virtual trBase::SmrtClass* GetUserDataContainer(); + + /** + * Returns the user data object + */ + virtual const trBase::SmrtClass* GetUserDataContainer() const; + + /** + * Sets the user data object + */ + virtual void SetUserDataContainer(trBase::SmrtClass* data); + + /** + * Returns a list of Description strings + */ + virtual std::vector GetDescriptionList(); + + /** + * Returns a list of Description strings + */ + virtual const std::vector GetDescriptionList() const; + + /** + * Returns the number of objects stored in the Description list + */ + virtual int GetDescriptionListCount(); + + /** + * Returns the specified description. Returns the first one if no index is specified + */ + virtual std::string GetDescription(int index = 0); + + /** + * Returns the specified description. Returns the first one if no index is specified + */ + virtual const std::string GetDescription(int index = 0) const; + + /** + * Adds a new description string to the list of descriptions + */ + virtual void AddDescription(std::string description); + + /** + * Set a new list of descriptions strings + */ + virtual void SetDescriptions(std::vector descriptions); + + /** + * Returns the list of all the user objects cast down to Base class. + */ + virtual std::vector> GetObjectList(); + + /** + * Returns the list of all the user objects cast down to Base class. + */ + virtual const std::vector> GetObjectList() const; + + /** + * Returns the number of objects stored in the Object list + */ + virtual int GetObjectListCount(); + + /** + * Returns the specified object. Returns the first one if no index is specified + */ + virtual trBase::SmrtPtr GetObject(int index = 0); + + /** + * Returns the specified object. Returns the first one if no index is specified + */ + virtual const trBase::SmrtPtr GetObject(int index = 0) const; + + /** + * Adds a new object to the object list + */ + virtual void AddObject(trBase::SmrtPtr obj); + + /** + * Set a new list of objects + */ + virtual void SetObjects(std::vector> objList); + + protected: + + trBase::SmrtPtr mUserDataContainer; + std::vector mDescriptionList; + std::vector> mObjectList; + + /** + * dtor + */ + ~UserDataContainer(); + }; +} diff --git a/include/trBase/Vec2.h b/include/trBase/Vec2.h index 3064d9b..ecc543f 100644 --- a/include/trBase/Vec2.h +++ b/include/trBase/Vec2.h @@ -1,41 +1,41 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include -#include -#include - -namespace trBase -{ -#ifdef TR_USE_DOUBLE_VECTOR - /** - * General purpose 2D Vector - */ - using Vec2 = Vec2d; -#else - /** - * General purpose 2D Vector - */ - using Vec2 = Vec2f; -#endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include +#include +#include + +namespace trBase +{ +#ifdef TR_USE_DOUBLE_VECTOR + /** + * General purpose 2D Vector + */ + using Vec2 = Vec2d; +#else + /** + * General purpose 2D Vector + */ + using Vec2 = Vec2f; +#endif } \ No newline at end of file diff --git a/include/trBase/Vec2b.h b/include/trBase/Vec2b.h index 660bb1f..214dd45 100644 --- a/include/trBase/Vec2b.h +++ b/include/trBase/Vec2b.h @@ -1,289 +1,289 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D byte Vector - */ - class TR_BASE_EXPORT Vec2b - { - public: - - /** Data type of vector components.*/ - using value_type = signed char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2b(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2b(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2b(const osg::Vec2b &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2b& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2b& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2b Lerp(const Vec2b& from, const Vec2b& to, value_type alpha); - - /** - * @fn std::string Vec2b::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2b& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2b& v); - - /** - * Equality operator - */ - bool operator == (const Vec2b& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2b& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2b& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2b& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2b& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2b operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2b& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2b operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2b& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2b operator + (const Vec2b& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2b& operator += (const Vec2b& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2b operator - (const Vec2b& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2b& operator -= (const Vec2b& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2b operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2b() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2b& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2b& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2b* (); - - protected: - - osg::Vec2b mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2b& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2b ComponentMultiply(const Vec2b& lhs, const Vec2b& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2b ComponentDivide(const Vec2b& lhs, const Vec2b& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D byte Vector + */ + class TR_BASE_EXPORT Vec2b + { + public: + + /** Data type of vector components.*/ + using value_type = signed char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2b(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2b(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2b(const osg::Vec2b &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2b& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2b& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2b Lerp(const Vec2b& from, const Vec2b& to, value_type alpha); + + /** + * @fn std::string Vec2b::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2b& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2b& v); + + /** + * Equality operator + */ + bool operator == (const Vec2b& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2b& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2b& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2b& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2b& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2b operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2b& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2b operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2b& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2b operator + (const Vec2b& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2b& operator += (const Vec2b& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2b operator - (const Vec2b& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2b& operator -= (const Vec2b& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2b operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2b() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2b& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2b& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2b* (); + + protected: + + osg::Vec2b mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2b& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2b ComponentMultiply(const Vec2b& lhs, const Vec2b& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2b ComponentDivide(const Vec2b& lhs, const Vec2b& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2d.h b/include/trBase/Vec2d.h index 13e9ecb..159ed62 100644 --- a/include/trBase/Vec2d.h +++ b/include/trBase/Vec2d.h @@ -1,308 +1,308 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec2f; -} -/// @endcond - -namespace trBase -{ - class Vec2f; - - /** - * General purpose 2D double Vector - */ - class TR_BASE_EXPORT Vec2d - { - public: - - /** Data type of vector components.*/ - using value_type = double; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2d(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2d(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2d to process. - */ - Vec2d(const osg::Vec2d &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2f to process. - */ - Vec2d(const osg::Vec2f &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2d& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2d& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2d Lerp(const Vec2d& from, const Vec2d& to, value_type alpha); - - /** - * @fn std::string Vec2d::ToString(); - * - * @brief Convert this object into a string representation. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2d& v); - - /** - * Set operator - */ - void operator = (const Vec2f& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2d& v); - - /** - * Equality operator - */ - bool operator == (const Vec2d& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2d& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2d& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2d& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2d& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2d operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2d& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2d operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2d& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2d operator + (const Vec2d& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2d& operator += (const Vec2d& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2d operator - (const Vec2d& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2d& operator -= (const Vec2d& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2d operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2d () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2d& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2d& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2d* (); - - protected: - - osg::Vec2d mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2d& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2d ComponentMultiply(const Vec2d& lhs, const Vec2d& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2d ComponentDivide(const Vec2d& lhs, const Vec2d& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec2f; +} +/// @endcond + +namespace trBase +{ + class Vec2f; + + /** + * General purpose 2D double Vector + */ + class TR_BASE_EXPORT Vec2d + { + public: + + /** Data type of vector components.*/ + using value_type = double; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2d(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2d(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2d to process. + */ + Vec2d(const osg::Vec2d &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2f to process. + */ + Vec2d(const osg::Vec2f &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2d& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2d& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2d Lerp(const Vec2d& from, const Vec2d& to, value_type alpha); + + /** + * @fn std::string Vec2d::ToString(); + * + * @brief Convert this object into a string representation. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2d& v); + + /** + * Set operator + */ + void operator = (const Vec2f& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2d& v); + + /** + * Equality operator + */ + bool operator == (const Vec2d& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2d& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2d& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2d& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2d& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2d operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2d& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2d operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2d& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2d operator + (const Vec2d& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2d& operator += (const Vec2d& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2d operator - (const Vec2d& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2d& operator -= (const Vec2d& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2d operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2d () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2d& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2d& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2d* (); + + protected: + + osg::Vec2d mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2d& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2d ComponentMultiply(const Vec2d& lhs, const Vec2d& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2d ComponentDivide(const Vec2d& lhs, const Vec2d& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2f.h b/include/trBase/Vec2f.h index f888a49..8018d90 100644 --- a/include/trBase/Vec2f.h +++ b/include/trBase/Vec2f.h @@ -1,310 +1,310 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec2d; -} -/// @endcond - -namespace trBase -{ - class Vec2d; - - /** - * General purpose 2D float Vector - */ - class TR_BASE_EXPORT Vec2f - { - public: - - /** Data type of vector components.*/ - using value_type = float; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2f(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2f(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2f to process. - */ - Vec2f(const osg::Vec2f &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2d to process. - */ - Vec2f(const osg::Vec2d &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2f& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2f& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2f Lerp(const Vec2f& from, const Vec2f& to, value_type alpha); - - /** - * @fn std::string Vec2f::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2f& v); - - /** - * Set operator - */ - void operator = (const Vec2d& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2f& v); - - /** - * Equality operator - */ - bool operator == (const Vec2f& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2f& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2f& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2f& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2f& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2f operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2f& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2f operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2f& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2f operator + (const Vec2f& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2f& operator += (const Vec2f& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2f operator - (const Vec2f& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2f& operator -= (const Vec2f& rhs); - - /** - * Negation operator. Returns the negative of the Vector. - */ - const Vec2f operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2f() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2f& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2f& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2f* (); - - protected: - - osg::Vec2f mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2f& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2f ComponentMultiply(const Vec2f& lhs, const Vec2f& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2f ComponentDivide(const Vec2f& lhs, const Vec2f& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec2d; +} +/// @endcond + +namespace trBase +{ + class Vec2d; + + /** + * General purpose 2D float Vector + */ + class TR_BASE_EXPORT Vec2f + { + public: + + /** Data type of vector components.*/ + using value_type = float; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2f(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2f(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2f to process. + */ + Vec2f(const osg::Vec2f &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2d to process. + */ + Vec2f(const osg::Vec2d &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2f& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2f& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2f Lerp(const Vec2f& from, const Vec2f& to, value_type alpha); + + /** + * @fn std::string Vec2f::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2f& v); + + /** + * Set operator + */ + void operator = (const Vec2d& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2f& v); + + /** + * Equality operator + */ + bool operator == (const Vec2f& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2f& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2f& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2f& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2f& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2f operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2f& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2f operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2f& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2f operator + (const Vec2f& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2f& operator += (const Vec2f& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2f operator - (const Vec2f& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2f& operator -= (const Vec2f& rhs); + + /** + * Negation operator. Returns the negative of the Vector. + */ + const Vec2f operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2f() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2f& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2f& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2f* (); + + protected: + + osg::Vec2f mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2f& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2f ComponentMultiply(const Vec2f& lhs, const Vec2f& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2f ComponentDivide(const Vec2f& lhs, const Vec2f& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2i.h b/include/trBase/Vec2i.h index 96c3e2d..da9106d 100644 --- a/include/trBase/Vec2i.h +++ b/include/trBase/Vec2i.h @@ -1,289 +1,289 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D integer Vector - */ - class TR_BASE_EXPORT Vec2i - { - public: - - /** Data type of vector components.*/ - using value_type = int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2i(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2i(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2i(const osg::Vec2i &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2i& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2i& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2i Lerp(const Vec2i& from, const Vec2i& to, value_type alpha); - - /** - * @fn std::string Vec2i::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2i& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2i& v); - - /** - * Equality operator - */ - bool operator == (const Vec2i& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2i& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2i& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2i& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2i& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2i operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2i& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2i operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2i& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2i operator + (const Vec2i& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2i& operator += (const Vec2i& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2i operator - (const Vec2i& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2i& operator -= (const Vec2i& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2i operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2i() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2i& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2i& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2i* (); - - protected: - - osg::Vec2i mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2i& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2i ComponentMultiply(const Vec2i& lhs, const Vec2i& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2i ComponentDivide(const Vec2i& lhs, const Vec2i& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D integer Vector + */ + class TR_BASE_EXPORT Vec2i + { + public: + + /** Data type of vector components.*/ + using value_type = int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2i(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2i(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2i(const osg::Vec2i &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2i& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2i& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2i Lerp(const Vec2i& from, const Vec2i& to, value_type alpha); + + /** + * @fn std::string Vec2i::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2i& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2i& v); + + /** + * Equality operator + */ + bool operator == (const Vec2i& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2i& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2i& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2i& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2i& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2i operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2i& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2i operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2i& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2i operator + (const Vec2i& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2i& operator += (const Vec2i& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2i operator - (const Vec2i& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2i& operator -= (const Vec2i& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2i operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2i() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2i& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2i& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2i* (); + + protected: + + osg::Vec2i mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2i& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2i ComponentMultiply(const Vec2i& lhs, const Vec2i& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2i ComponentDivide(const Vec2i& lhs, const Vec2i& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2s.h b/include/trBase/Vec2s.h index 2fd9a64..70fa926 100644 --- a/include/trBase/Vec2s.h +++ b/include/trBase/Vec2s.h @@ -1,289 +1,289 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D short Vector - */ - class TR_BASE_EXPORT Vec2s - { - public: - - /** Data type of vector components.*/ - using value_type = short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2s(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2s(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2s(const osg::Vec2s &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2s& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2s& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2s Lerp(const Vec2s& from, const Vec2s& to, value_type alpha); - - /** - * @fn std::string Vec2s::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2s& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2s& v); - - /** - * Equality operator - */ - bool operator == (const Vec2s& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2s& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2s& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2s& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2s& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2s operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2s& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2s operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2s& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2s operator + (const Vec2s& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2s& operator += (const Vec2s& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2s operator - (const Vec2s& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2s& operator -= (const Vec2s& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2s operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2s() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2s& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2s& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2s* (); - - protected: - - osg::Vec2s mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2s& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2s ComponentMultiply(const Vec2s& lhs, const Vec2s& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2s ComponentDivide(const Vec2s& lhs, const Vec2s& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D short Vector + */ + class TR_BASE_EXPORT Vec2s + { + public: + + /** Data type of vector components.*/ + using value_type = short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2s(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2s(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2s(const osg::Vec2s &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2s& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2s& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2s Lerp(const Vec2s& from, const Vec2s& to, value_type alpha); + + /** + * @fn std::string Vec2s::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2s& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2s& v); + + /** + * Equality operator + */ + bool operator == (const Vec2s& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2s& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2s& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2s& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2s& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2s operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2s& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2s operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2s& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2s operator + (const Vec2s& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2s& operator += (const Vec2s& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2s operator - (const Vec2s& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2s& operator -= (const Vec2s& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2s operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2s() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2s& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2s& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2s* (); + + protected: + + osg::Vec2s mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2s& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2s ComponentMultiply(const Vec2s& lhs, const Vec2s& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2s ComponentDivide(const Vec2s& lhs, const Vec2s& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2ub.h b/include/trBase/Vec2ub.h index 5f5560c..d0d4cce 100644 --- a/include/trBase/Vec2ub.h +++ b/include/trBase/Vec2ub.h @@ -1,285 +1,285 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D unsigned byte Vector - */ - class TR_BASE_EXPORT Vec2ub - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2ub(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2ub(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2ub(const osg::Vec2ub &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2ub& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2ub& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2ub Lerp(const Vec2ub& from, const Vec2ub& to, value_type alpha); - - /** - * @brief Convert this object into a string representation. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2ub& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2ub& v); - - /** - * Equality operator - */ - bool operator == (const Vec2ub& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2ub& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2ub& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2ub& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2ub& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2ub operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2ub& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2ub operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2ub& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2ub operator + (const Vec2ub& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2ub& operator += (const Vec2ub& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2ub operator - (const Vec2ub& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2ub& operator -= (const Vec2ub& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2ub operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ub() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ub& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2ub& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ub* (); - - protected: - - osg::Vec2ub mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2ub& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2ub ComponentMultiply(const Vec2ub& lhs, const Vec2ub& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2ub ComponentDivide(const Vec2ub& lhs, const Vec2ub& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D unsigned byte Vector + */ + class TR_BASE_EXPORT Vec2ub + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2ub(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2ub(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2ub(const osg::Vec2ub &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2ub& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2ub& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2ub Lerp(const Vec2ub& from, const Vec2ub& to, value_type alpha); + + /** + * @brief Convert this object into a string representation. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2ub& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2ub& v); + + /** + * Equality operator + */ + bool operator == (const Vec2ub& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2ub& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2ub& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2ub& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2ub& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2ub operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2ub& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2ub operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2ub& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2ub operator + (const Vec2ub& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2ub& operator += (const Vec2ub& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2ub operator - (const Vec2ub& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2ub& operator -= (const Vec2ub& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2ub operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ub() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ub& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2ub& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ub* (); + + protected: + + osg::Vec2ub mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2ub& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2ub ComponentMultiply(const Vec2ub& lhs, const Vec2ub& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2ub ComponentDivide(const Vec2ub& lhs, const Vec2ub& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2ui.h b/include/trBase/Vec2ui.h index ec80518..8282ea4 100644 --- a/include/trBase/Vec2ui.h +++ b/include/trBase/Vec2ui.h @@ -1,285 +1,285 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D unsigned int Vector - */ - class TR_BASE_EXPORT Vec2ui - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2ui(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2ui(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2ui(const osg::Vec2ui &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2ui& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2ui& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2ui Lerp(const Vec2ui& from, const Vec2ui& to, value_type alpha); - - /** - * @brief Convert this object into a string representation. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2ui& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2ui& v); - - /** - * Equality operator - */ - bool operator == (const Vec2ui& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2ui& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2ui& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2ui& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2ui& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2ui operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2ui& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2ui operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2ui& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2ui operator + (const Vec2ui& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2ui& operator += (const Vec2ui& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2ui operator - (const Vec2ui& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2ui& operator -= (const Vec2ui& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2ui operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ui() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ui& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2ui& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2ui* (); - - protected: - - osg::Vec2ui mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2ui& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2ui ComponentMultiply(const Vec2ui& lhs, const Vec2ui& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2ui ComponentDivide(const Vec2ui& lhs, const Vec2ui& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D unsigned int Vector + */ + class TR_BASE_EXPORT Vec2ui + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2ui(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2ui(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2ui(const osg::Vec2ui &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2ui& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2ui& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2ui Lerp(const Vec2ui& from, const Vec2ui& to, value_type alpha); + + /** + * @brief Convert this object into a string representation. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2ui& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2ui& v); + + /** + * Equality operator + */ + bool operator == (const Vec2ui& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2ui& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2ui& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2ui& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2ui& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2ui operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2ui& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2ui operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2ui& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2ui operator + (const Vec2ui& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2ui& operator += (const Vec2ui& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2ui operator - (const Vec2ui& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2ui& operator -= (const Vec2ui& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2ui operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ui() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ui& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2ui& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2ui* (); + + protected: + + osg::Vec2ui mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2ui& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2ui ComponentMultiply(const Vec2ui& lhs, const Vec2ui& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2ui ComponentDivide(const Vec2ui& lhs, const Vec2ui& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec2us.h b/include/trBase/Vec2us.h index a66ba67..a1b6e91 100644 --- a/include/trBase/Vec2us.h +++ b/include/trBase/Vec2us.h @@ -1,285 +1,285 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 2D unsigned short Vector - */ - class TR_BASE_EXPORT Vec2us - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec2us(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - */ - Vec2us(value_type x, value_type y); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec2 to process. - */ - Vec2us(const osg::Vec2us &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec2us& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec2us& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec2us Lerp(const Vec2us& from, const Vec2us& to, value_type alpha); - - /** - * @brief Convert this object into a string representation. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec2us& v); - - /** - * Set operator - */ - void operator = (const osg::Vec2us& v); - - /** - * Equality operator - */ - bool operator == (const Vec2us& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec2us& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec2us& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec2us& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec2us& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec2us operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec2us& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec2us operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec2us& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec2us operator + (const Vec2us& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec2us& operator += (const Vec2us& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec2us operator - (const Vec2us& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec2us& operator -= (const Vec2us& rhs); - - /** - * Negation operator. Returns the negative of the Vec2d. - */ - const Vec2us operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2us() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2us& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec2us& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec2us* (); - - protected: - - osg::Vec2us mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2us& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec2us ComponentMultiply(const Vec2us& lhs, const Vec2us& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec2us ComponentDivide(const Vec2us& lhs, const Vec2us& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 2D unsigned short Vector + */ + class TR_BASE_EXPORT Vec2us + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec2us(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + */ + Vec2us(value_type x, value_type y); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec2 to process. + */ + Vec2us(const osg::Vec2us &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec2us& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec2us& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec2us Lerp(const Vec2us& from, const Vec2us& to, value_type alpha); + + /** + * @brief Convert this object into a string representation. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec2us& v); + + /** + * Set operator + */ + void operator = (const osg::Vec2us& v); + + /** + * Equality operator + */ + bool operator == (const Vec2us& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec2us& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec2us& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec2us& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec2us& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec2us operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec2us& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec2us operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec2us& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec2us operator + (const Vec2us& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec2us& operator += (const Vec2us& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec2us operator - (const Vec2us& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec2us& operator -= (const Vec2us& rhs); + + /** + * Negation operator. Returns the negative of the Vec2d. + */ + const Vec2us operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2us() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2us& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec2us& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec2us* (); + + protected: + + osg::Vec2us mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec2us& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec2us ComponentMultiply(const Vec2us& lhs, const Vec2us& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec2us ComponentDivide(const Vec2us& lhs, const Vec2us& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3.h b/include/trBase/Vec3.h index c2cdee2..07061b9 100644 --- a/include/trBase/Vec3.h +++ b/include/trBase/Vec3.h @@ -1,45 +1,45 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -namespace trBase -{ -#ifdef TR_USE_DOUBLE_VECTOR - /** - * General purpose 3D Vector - */ - using Vec3 = Vec3d; -#else - /** - * General purpose 3D Vector - */ - using Vec3 = Vec3f; -#endif - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +namespace trBase +{ +#ifdef TR_USE_DOUBLE_VECTOR + /** + * General purpose 3D Vector + */ + using Vec3 = Vec3d; +#else + /** + * General purpose 3D Vector + */ + using Vec3 = Vec3f; +#endif + + const Vec3 X_AXIS(1.0, 0.0, 0.0); const Vec3 Y_AXIS(0.0, 1.0, 0.0); - const Vec3 Z_AXIS(0.0, 0.0, 1.0); + const Vec3 Z_AXIS(0.0, 0.0, 1.0); } \ No newline at end of file diff --git a/include/trBase/Vec3b.h b/include/trBase/Vec3b.h index 9c11a8b..b85c9b2 100644 --- a/include/trBase/Vec3b.h +++ b/include/trBase/Vec3b.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D byte Vector - */ - class TR_BASE_EXPORT Vec3b - { - public: - - /** Data type of vector components.*/ - using value_type = signed char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3b(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3b(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3b to process. - */ - Vec3b(const osg::Vec3b &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3b& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3b& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3b& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3b Lerp(const Vec3b& from, const Vec3b& to, value_type alpha); - - /** - * @fn std::string Vec3b::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3b& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3b& v); - - /** - * Equality operator - */ - bool operator == (const Vec3b& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3b& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3b& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3b& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3b& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3b operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3b& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3b operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3b& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3b operator + (const Vec3b& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3b& operator += (const Vec3b& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3b operator - (const Vec3b& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3b& operator -= (const Vec3b& rhs); - - /** - * Negation operator. Returns the negative of the Vec3b. - */ - const Vec3b operator - () const; - - /** - * Cross product operator. - */ - const Vec3b operator ^ (const Vec3b& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3b() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3b& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3b& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3b* (); - - protected: - - osg::Vec3b mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3b& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3b ComponentMultiply(const Vec3b& lhs, const Vec3b& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3b ComponentDivide(const Vec3b& lhs, const Vec3b& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D byte Vector + */ + class TR_BASE_EXPORT Vec3b + { + public: + + /** Data type of vector components.*/ + using value_type = signed char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3b(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3b(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3b to process. + */ + Vec3b(const osg::Vec3b &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3b& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3b& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3b& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3b Lerp(const Vec3b& from, const Vec3b& to, value_type alpha); + + /** + * @fn std::string Vec3b::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3b& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3b& v); + + /** + * Equality operator + */ + bool operator == (const Vec3b& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3b& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3b& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3b& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3b& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3b operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3b& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3b operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3b& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3b operator + (const Vec3b& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3b& operator += (const Vec3b& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3b operator - (const Vec3b& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3b& operator -= (const Vec3b& rhs); + + /** + * Negation operator. Returns the negative of the Vec3b. + */ + const Vec3b operator - () const; + + /** + * Cross product operator. + */ + const Vec3b operator ^ (const Vec3b& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3b() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3b& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3b& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3b* (); + + protected: + + osg::Vec3b mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3b& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3b ComponentMultiply(const Vec3b& lhs, const Vec3b& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3b ComponentDivide(const Vec3b& lhs, const Vec3b& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3d.h b/include/trBase/Vec3d.h index 4a13229..f90339c 100644 --- a/include/trBase/Vec3d.h +++ b/include/trBase/Vec3d.h @@ -1,365 +1,365 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec3f; -} -/// @endcond - -namespace trBase -{ - class Vec3f; - - /** - * General purpose 3D double Vector - */ - class TR_BASE_EXPORT Vec3d - { - public: - - /** Data type of vector components.*/ - using value_type = double; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3d(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3d(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3d to process. - */ - Vec3d(const osg::Vec3d &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3f to process. - */ - Vec3d(const osg::Vec3f &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3d& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3d& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3d& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3d Lerp(const Vec3d& from, const Vec3d& to, value_type alpha); - - /** - * @fn std::string Vec3d::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3d& v); - - /** - * Set operator - */ - void operator = (const Vec3f& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3d& v); - - /** - * Equality operator - */ - bool operator == (const Vec3d& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3d& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3d& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3d& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3d& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3d operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3d& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3d operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3d& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3d operator + (const Vec3d& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3d& operator += (const Vec3d& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3d operator - (const Vec3d& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3d& operator -= (const Vec3d& rhs); - - /** - * Negation operator. Returns the negative of the Vec3d. - */ - const Vec3d operator - () const; - - /** - * Cross product operator. - */ - const Vec3d operator ^ (const Vec3d& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3d() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3d& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3d& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3d* (); - - protected: - - osg::Vec3d mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3d& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3d ComponentMultiply(const Vec3d& lhs, const Vec3d& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3d ComponentDivide(const Vec3d& lhs, const Vec3d& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec3f; +} +/// @endcond + +namespace trBase +{ + class Vec3f; + + /** + * General purpose 3D double Vector + */ + class TR_BASE_EXPORT Vec3d + { + public: + + /** Data type of vector components.*/ + using value_type = double; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3d(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3d(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3d to process. + */ + Vec3d(const osg::Vec3d &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3f to process. + */ + Vec3d(const osg::Vec3f &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3d& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3d& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3d& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3d Lerp(const Vec3d& from, const Vec3d& to, value_type alpha); + + /** + * @fn std::string Vec3d::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3d& v); + + /** + * Set operator + */ + void operator = (const Vec3f& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3d& v); + + /** + * Equality operator + */ + bool operator == (const Vec3d& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3d& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3d& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3d& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3d& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3d operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3d& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3d operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3d& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3d operator + (const Vec3d& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3d& operator += (const Vec3d& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3d operator - (const Vec3d& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3d& operator -= (const Vec3d& rhs); + + /** + * Negation operator. Returns the negative of the Vec3d. + */ + const Vec3d operator - () const; + + /** + * Cross product operator. + */ + const Vec3d operator ^ (const Vec3d& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3d() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3d& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3d& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3d* (); + + protected: + + osg::Vec3d mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3d& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3d ComponentMultiply(const Vec3d& lhs, const Vec3d& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3d ComponentDivide(const Vec3d& lhs, const Vec3d& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3f.h b/include/trBase/Vec3f.h index 2de9e4a..6d7e0b1 100644 --- a/include/trBase/Vec3f.h +++ b/include/trBase/Vec3f.h @@ -1,365 +1,365 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec3d; -} -/// @endcond - -namespace trBase -{ - class Vec3d; - - /** - * General purpose 3D float Vector - */ - class TR_BASE_EXPORT Vec3f - { - public: - - /** Data type of vector components.*/ - using value_type = float; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3f(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3f(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3f to process. - */ - Vec3f(const osg::Vec3f &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3d to process. - */ - Vec3f(const osg::Vec3d &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3f& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3f& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3f& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3f Lerp(const Vec3f& from, const Vec3f& to, value_type alpha); - - /** - * @fn std::string Vec3f::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3f& v); - - /** - * Set operator - */ - void operator = (const Vec3d& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3f& v); - - /** - * Equality operator - */ - bool operator == (const Vec3f& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3f& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3f& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3f& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3f& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3f operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3f& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3f operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3f& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3f operator + (const Vec3f& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3f& operator += (const Vec3f& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3f operator - (const Vec3f& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3f& operator -= (const Vec3f& rhs); - - /** - * Negation operator. Returns the negative of the Vec3f. - */ - const Vec3f operator - () const; - - /** - * Cross product operator. - */ - const Vec3f operator ^ (const Vec3f& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3f() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3f& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3f& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3f* (); - - protected: - - osg::Vec3f mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3f& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3f ComponentMultiply(const Vec3f& lhs, const Vec3f& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3f ComponentDivide(const Vec3f& lhs, const Vec3f& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec3d; +} +/// @endcond + +namespace trBase +{ + class Vec3d; + + /** + * General purpose 3D float Vector + */ + class TR_BASE_EXPORT Vec3f + { + public: + + /** Data type of vector components.*/ + using value_type = float; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3f(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3f(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3f to process. + */ + Vec3f(const osg::Vec3f &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3d to process. + */ + Vec3f(const osg::Vec3d &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3f& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3f& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3f& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3f Lerp(const Vec3f& from, const Vec3f& to, value_type alpha); + + /** + * @fn std::string Vec3f::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3f& v); + + /** + * Set operator + */ + void operator = (const Vec3d& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3f& v); + + /** + * Equality operator + */ + bool operator == (const Vec3f& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3f& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3f& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3f& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3f& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3f operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3f& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3f operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3f& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3f operator + (const Vec3f& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3f& operator += (const Vec3f& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3f operator - (const Vec3f& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3f& operator -= (const Vec3f& rhs); + + /** + * Negation operator. Returns the negative of the Vec3f. + */ + const Vec3f operator - () const; + + /** + * Cross product operator. + */ + const Vec3f operator ^ (const Vec3f& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3f() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3f& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3f& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3f* (); + + protected: + + osg::Vec3f mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3f& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3f ComponentMultiply(const Vec3f& lhs, const Vec3f& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3f ComponentDivide(const Vec3f& lhs, const Vec3f& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3i.h b/include/trBase/Vec3i.h index 0349295..3bb2fae 100644 --- a/include/trBase/Vec3i.h +++ b/include/trBase/Vec3i.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D integer Vector - */ - class TR_BASE_EXPORT Vec3i - { - public: - - /** Data type of vector components.*/ - using value_type = int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3i(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3i(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3i to process. - */ - Vec3i(const osg::Vec3i &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3i& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3i& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3i& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3i Lerp(const Vec3i& from, const Vec3i& to, value_type alpha); - - /** - * @fn std::string Vec3i::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3i& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3i& v); - - /** - * Equality operator - */ - bool operator == (const Vec3i& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3i& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3i& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3i& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3i& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3i operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3i& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3i operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3i& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3i operator + (const Vec3i& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3i& operator += (const Vec3i& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3i operator - (const Vec3i& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3i& operator -= (const Vec3i& rhs); - - /** - * Negation operator. Returns the negative of the Vec3i. - */ - const Vec3i operator - () const; - - /** - * Cross product operator. - */ - const Vec3i operator ^ (const Vec3i& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3i() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3i& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3i& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3i* (); - - protected: - - osg::Vec3i mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3i& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3i ComponentMultiply(const Vec3i& lhs, const Vec3i& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3i ComponentDivide(const Vec3i& lhs, const Vec3i& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D integer Vector + */ + class TR_BASE_EXPORT Vec3i + { + public: + + /** Data type of vector components.*/ + using value_type = int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3i(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3i(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3i to process. + */ + Vec3i(const osg::Vec3i &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3i& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3i& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3i& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3i Lerp(const Vec3i& from, const Vec3i& to, value_type alpha); + + /** + * @fn std::string Vec3i::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3i& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3i& v); + + /** + * Equality operator + */ + bool operator == (const Vec3i& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3i& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3i& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3i& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3i& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3i operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3i& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3i operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3i& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3i operator + (const Vec3i& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3i& operator += (const Vec3i& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3i operator - (const Vec3i& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3i& operator -= (const Vec3i& rhs); + + /** + * Negation operator. Returns the negative of the Vec3i. + */ + const Vec3i operator - () const; + + /** + * Cross product operator. + */ + const Vec3i operator ^ (const Vec3i& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3i() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3i& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3i& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3i* (); + + protected: + + osg::Vec3i mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3i& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3i ComponentMultiply(const Vec3i& lhs, const Vec3i& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3i ComponentDivide(const Vec3i& lhs, const Vec3i& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3s.h b/include/trBase/Vec3s.h index e8db137..eabbe94 100644 --- a/include/trBase/Vec3s.h +++ b/include/trBase/Vec3s.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D short Vector - */ - class TR_BASE_EXPORT Vec3s - { - public: - - /** Data type of vector components.*/ - using value_type = short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3s(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3s(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3s to process. - */ - Vec3s(const osg::Vec3s &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3s& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3s& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3s& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3s Lerp(const Vec3s& from, const Vec3s& to, value_type alpha); - - /** - * @fn std::string Vec3s::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3s& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3s& v); - - /** - * Equality operator - */ - bool operator == (const Vec3s& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3s& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3s& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3s& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3s& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3s operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3s& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3s operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3s& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3s operator + (const Vec3s& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3s& operator += (const Vec3s& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3s operator - (const Vec3s& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3s& operator -= (const Vec3s& rhs); - - /** - * Negation operator. Returns the negative of the Vec3s. - */ - const Vec3s operator - () const; - - /** - * Cross product operator. - */ - const Vec3s operator ^ (const Vec3s& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3s() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3s& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3s& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3s* (); - - protected: - - osg::Vec3s mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3s& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3s ComponentMultiply(const Vec3s& lhs, const Vec3s& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3s ComponentDivide(const Vec3s& lhs, const Vec3s& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D short Vector + */ + class TR_BASE_EXPORT Vec3s + { + public: + + /** Data type of vector components.*/ + using value_type = short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3s(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3s(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3s to process. + */ + Vec3s(const osg::Vec3s &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3s& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3s& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3s& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3s Lerp(const Vec3s& from, const Vec3s& to, value_type alpha); + + /** + * @fn std::string Vec3s::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3s& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3s& v); + + /** + * Equality operator + */ + bool operator == (const Vec3s& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3s& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3s& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3s& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3s& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3s operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3s& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3s operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3s& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3s operator + (const Vec3s& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3s& operator += (const Vec3s& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3s operator - (const Vec3s& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3s& operator -= (const Vec3s& rhs); + + /** + * Negation operator. Returns the negative of the Vec3s. + */ + const Vec3s operator - () const; + + /** + * Cross product operator. + */ + const Vec3s operator ^ (const Vec3s& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3s() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3s& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3s& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3s* (); + + protected: + + osg::Vec3s mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3s& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3s ComponentMultiply(const Vec3s& lhs, const Vec3s& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3s ComponentDivide(const Vec3s& lhs, const Vec3s& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3ub.h b/include/trBase/Vec3ub.h index e6da332..84cfb34 100644 --- a/include/trBase/Vec3ub.h +++ b/include/trBase/Vec3ub.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned byte Vector - */ - class TR_BASE_EXPORT Vec3ub - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3ub(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3ub(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3ub to process. - */ - Vec3ub(const osg::Vec3ub &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3ub& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3ub& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3ub& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3ub Lerp(const Vec3ub& from, const Vec3ub& to, value_type alpha); - - /** - * @fn std::string Vec3ub::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3ub& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3ub& v); - - /** - * Equality operator - */ - bool operator == (const Vec3ub& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3ub& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3ub& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3ub& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3ub& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3ub operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3ub& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3ub operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3ub& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3ub operator + (const Vec3ub& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3ub& operator += (const Vec3ub& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3ub operator - (const Vec3ub& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3ub& operator -= (const Vec3ub& rhs); - - /** - * Negation operator. Returns the negative of the Vec3ub. - */ - const Vec3ub operator - () const; - - /** - * Cross product operator. - */ - const Vec3ub operator ^ (const Vec3ub& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ub() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ub& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3ub& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ub* (); - - protected: - - osg::Vec3ub mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3ub& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3ub ComponentMultiply(const Vec3ub& lhs, const Vec3ub& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3ub ComponentDivide(const Vec3ub& lhs, const Vec3ub& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned byte Vector + */ + class TR_BASE_EXPORT Vec3ub + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3ub(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3ub(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3ub to process. + */ + Vec3ub(const osg::Vec3ub &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3ub& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3ub& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3ub& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3ub Lerp(const Vec3ub& from, const Vec3ub& to, value_type alpha); + + /** + * @fn std::string Vec3ub::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3ub& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3ub& v); + + /** + * Equality operator + */ + bool operator == (const Vec3ub& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3ub& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3ub& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3ub& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3ub& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3ub operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3ub& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3ub operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3ub& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3ub operator + (const Vec3ub& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3ub& operator += (const Vec3ub& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3ub operator - (const Vec3ub& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3ub& operator -= (const Vec3ub& rhs); + + /** + * Negation operator. Returns the negative of the Vec3ub. + */ + const Vec3ub operator - () const; + + /** + * Cross product operator. + */ + const Vec3ub operator ^ (const Vec3ub& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ub() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ub& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3ub& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ub* (); + + protected: + + osg::Vec3ub mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3ub& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3ub ComponentMultiply(const Vec3ub& lhs, const Vec3ub& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3ub ComponentDivide(const Vec3ub& lhs, const Vec3ub& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3ui.h b/include/trBase/Vec3ui.h index 76df174..833d068 100644 --- a/include/trBase/Vec3ui.h +++ b/include/trBase/Vec3ui.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned integer Vector - */ - class TR_BASE_EXPORT Vec3ui - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3ui(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3ui(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3ui to process. - */ - Vec3ui(const osg::Vec3ui &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3ui& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3ui& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3ui& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3ui Lerp(const Vec3ui& from, const Vec3ui& to, value_type alpha); - - /** - * @fn std::string Vec3ui::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3ui& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3ui& v); - - /** - * Equality operator - */ - bool operator == (const Vec3ui& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3ui& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3ui& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3ui& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3ui& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3ui operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3ui& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3ui operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3ui& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3ui operator + (const Vec3ui& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3ui& operator += (const Vec3ui& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3ui operator - (const Vec3ui& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3ui& operator -= (const Vec3ui& rhs); - - /** - * Negation operator. Returns the negative of the Vec3ui. - */ - const Vec3ui operator - () const; - - /** - * Cross product operator. - */ - const Vec3ui operator ^ (const Vec3ui& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ui() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ui& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3ui& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3ui* (); - - protected: - - osg::Vec3ui mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3ui& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3ui ComponentMultiply(const Vec3ui& lhs, const Vec3ui& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3ui ComponentDivide(const Vec3ui& lhs, const Vec3ui& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned integer Vector + */ + class TR_BASE_EXPORT Vec3ui + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3ui(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3ui(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3ui to process. + */ + Vec3ui(const osg::Vec3ui &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3ui& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3ui& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3ui& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3ui Lerp(const Vec3ui& from, const Vec3ui& to, value_type alpha); + + /** + * @fn std::string Vec3ui::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3ui& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3ui& v); + + /** + * Equality operator + */ + bool operator == (const Vec3ui& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3ui& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3ui& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3ui& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3ui& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3ui operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3ui& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3ui operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3ui& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3ui operator + (const Vec3ui& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3ui& operator += (const Vec3ui& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3ui operator - (const Vec3ui& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3ui& operator -= (const Vec3ui& rhs); + + /** + * Negation operator. Returns the negative of the Vec3ui. + */ + const Vec3ui operator - () const; + + /** + * Cross product operator. + */ + const Vec3ui operator ^ (const Vec3ui& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ui() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ui& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3ui& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3ui* (); + + protected: + + osg::Vec3ui mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3ui& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3ui ComponentMultiply(const Vec3ui& lhs, const Vec3ui& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3ui ComponentDivide(const Vec3ui& lhs, const Vec3ui& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec3us.h b/include/trBase/Vec3us.h index 1936212..2e3366a 100644 --- a/include/trBase/Vec3us.h +++ b/include/trBase/Vec3us.h @@ -1,344 +1,344 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned short Vector - */ - class TR_BASE_EXPORT Vec3us - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec3us(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - */ - Vec3us(value_type x, value_type y, value_type z); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec3us to process. - */ - Vec3us(const osg::Vec3us &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec3us& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec3us& v); - - /** - * Sets the initial values of the vector - */ - void SetRGB(value_type r, value_type g, value_type b); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec3us& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec3us Lerp(const Vec3us& from, const Vec3us& to, value_type alpha); - - /** - * @fn std::string Vec3us::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec3us& v); - - /** - * Set operator - */ - void operator = (const osg::Vec3us& v); - - /** - * Equality operator - */ - bool operator == (const Vec3us& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec3us& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec3us& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec3us& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec3us& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec3us operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec3us& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec3us operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec3us& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec3us operator + (const Vec3us& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec3us& operator += (const Vec3us& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec3us operator - (const Vec3us& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec3us& operator -= (const Vec3us& rhs); - - /** - * Negation operator. Returns the negative of the Vec3us. - */ - const Vec3us operator - () const; - - /** - * Cross product operator. - */ - const Vec3us operator ^ (const Vec3us& rhs) const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3us() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3us& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec3us& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec3us* (); - - protected: - - osg::Vec3us mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3us& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec3us ComponentMultiply(const Vec3us& lhs, const Vec3us& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec3us ComponentDivide(const Vec3us& lhs, const Vec3us& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned short Vector + */ + class TR_BASE_EXPORT Vec3us + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec3us(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + */ + Vec3us(value_type x, value_type y, value_type z); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec3us to process. + */ + Vec3us(const osg::Vec3us &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec3us& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec3us& v); + + /** + * Sets the initial values of the vector + */ + void SetRGB(value_type r, value_type g, value_type b); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec3us& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec3us Lerp(const Vec3us& from, const Vec3us& to, value_type alpha); + + /** + * @fn std::string Vec3us::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec3us& v); + + /** + * Set operator + */ + void operator = (const osg::Vec3us& v); + + /** + * Equality operator + */ + bool operator == (const Vec3us& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec3us& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec3us& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec3us& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec3us& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec3us operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec3us& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec3us operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec3us& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec3us operator + (const Vec3us& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec3us& operator += (const Vec3us& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec3us operator - (const Vec3us& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec3us& operator -= (const Vec3us& rhs); + + /** + * Negation operator. Returns the negative of the Vec3us. + */ + const Vec3us operator - () const; + + /** + * Cross product operator. + */ + const Vec3us operator ^ (const Vec3us& rhs) const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3us() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3us& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec3us& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec3us* (); + + protected: + + osg::Vec3us mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec3us& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec3us ComponentMultiply(const Vec3us& lhs, const Vec3us& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec3us ComponentDivide(const Vec3us& lhs, const Vec3us& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4.h b/include/trBase/Vec4.h index a4c4180..b6ebda0 100644 --- a/include/trBase/Vec4.h +++ b/include/trBase/Vec4.h @@ -1,40 +1,40 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include -#include -#include - -namespace trBase -{ -#ifdef TR_USE_DOUBLE_VECTOR - /** - * General purpose 4D Vector - */ - using Vec4 = Vec4d; -#else - /** - * General purpose 4D Vector - */ - using Vec4 = Vec4f; -#endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include +#include +#include + +namespace trBase +{ +#ifdef TR_USE_DOUBLE_VECTOR + /** + * General purpose 4D Vector + */ + using Vec4 = Vec4d; +#else + /** + * General purpose 4D Vector + */ + using Vec4 = Vec4f; +#endif } \ No newline at end of file diff --git a/include/trBase/Vec4b.h b/include/trBase/Vec4b.h index 526eb6d..15ba3d2 100644 --- a/include/trBase/Vec4b.h +++ b/include/trBase/Vec4b.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D byte Vector - */ - class TR_BASE_EXPORT Vec4b - { - public: - - /** Data type of vector components.*/ - using value_type = signed char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4b(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4b(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4b to process. - */ - Vec4b(const osg::Vec4b &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4b& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4b& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4b& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4b Lerp(const Vec4b& from, const Vec4b& to, value_type alpha); - - /** - * @fn std::string Vec4b::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4b& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4b& v); - - /** - * Equality operator - */ - bool operator == (const Vec4b& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4b& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4b& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4b& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4b& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4b operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4b& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4b operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4b& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4b operator + (const Vec4b& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4b& operator += (const Vec4b& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4b operator - (const Vec4b& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4b& operator -= (const Vec4b& rhs); - - /** - * Negation operator. Returns the negative of the Vec4b. - */ - const Vec4b operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4b() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4b& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4b& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4b* (); - - protected: - - osg::Vec4b mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4b& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4b ComponentMultiply(const Vec4b& lhs, const Vec4b& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4b ComponentDivide(const Vec4b& lhs, const Vec4b& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D byte Vector + */ + class TR_BASE_EXPORT Vec4b + { + public: + + /** Data type of vector components.*/ + using value_type = signed char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4b(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4b(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4b to process. + */ + Vec4b(const osg::Vec4b &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4b& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4b& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4b& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4b Lerp(const Vec4b& from, const Vec4b& to, value_type alpha); + + /** + * @fn std::string Vec4b::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4b& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4b& v); + + /** + * Equality operator + */ + bool operator == (const Vec4b& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4b& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4b& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4b& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4b& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4b operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4b& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4b operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4b& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4b operator + (const Vec4b& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4b& operator += (const Vec4b& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4b operator - (const Vec4b& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4b& operator -= (const Vec4b& rhs); + + /** + * Negation operator. Returns the negative of the Vec4b. + */ + const Vec4b operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4b() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4b& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4b& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4b* (); + + protected: + + osg::Vec4b mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4b& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4b ComponentMultiply(const Vec4b& lhs, const Vec4b& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4b ComponentDivide(const Vec4b& lhs, const Vec4b& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4d.h b/include/trBase/Vec4d.h index f89f51c..54e4b6d 100644 --- a/include/trBase/Vec4d.h +++ b/include/trBase/Vec4d.h @@ -1,382 +1,382 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec4f; -} -/// @endcond - -namespace trBase -{ - class Vec4f; - - /** - * General purpose 3D double Vector - */ - class TR_BASE_EXPORT Vec4d - { - public: - - /** Data type of vector components.*/ - using value_type = double; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4d(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4d(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4d to process. - */ - Vec4d(const osg::Vec4d &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4f to process. - */ - Vec4d(const osg::Vec4f &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4d& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4d& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4d& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4d Lerp(const Vec4d& from, const Vec4d& to, value_type alpha); - - /** - * @fn std::string Vec4d::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4d& v); - - /** - * Set operator - */ - void operator = (const Vec4f& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4d& v); - - /** - * Equality operator - */ - bool operator == (const Vec4d& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4d& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4d& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4d& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4d& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4d operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4d& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4d operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4d& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4d operator + (const Vec4d& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4d& operator += (const Vec4d& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4d operator - (const Vec4d& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4d& operator -= (const Vec4d& rhs); - - - /** - * Negation operator. Returns the negative of the Vec4d. - */ - const Vec4d operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4d() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4d& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4d& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4d* (); - - protected: - - osg::Vec4d mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4d& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4d ComponentMultiply(const Vec4d& lhs, const Vec4d& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4d ComponentDivide(const Vec4d& lhs, const Vec4d& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec4f; +} +/// @endcond + +namespace trBase +{ + class Vec4f; + + /** + * General purpose 3D double Vector + */ + class TR_BASE_EXPORT Vec4d + { + public: + + /** Data type of vector components.*/ + using value_type = double; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4d(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4d(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4d to process. + */ + Vec4d(const osg::Vec4d &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4f to process. + */ + Vec4d(const osg::Vec4f &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4d& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4d& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4d& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4d Lerp(const Vec4d& from, const Vec4d& to, value_type alpha); + + /** + * @fn std::string Vec4d::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4d& v); + + /** + * Set operator + */ + void operator = (const Vec4f& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4d& v); + + /** + * Equality operator + */ + bool operator == (const Vec4d& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4d& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4d& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4d& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4d& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4d operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4d& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4d operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4d& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4d operator + (const Vec4d& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4d& operator += (const Vec4d& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4d operator - (const Vec4d& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4d& operator -= (const Vec4d& rhs); + + + /** + * Negation operator. Returns the negative of the Vec4d. + */ + const Vec4d operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4d() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4d& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4d& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4d* (); + + protected: + + osg::Vec4d mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4d& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4d ComponentMultiply(const Vec4d& lhs, const Vec4d& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4d ComponentDivide(const Vec4d& lhs, const Vec4d& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4f.h b/include/trBase/Vec4f.h index 7a029c3..4803654 100644 --- a/include/trBase/Vec4f.h +++ b/include/trBase/Vec4f.h @@ -1,381 +1,381 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -namespace osg -{ - class Vec4d; -} -/// @endcond - -namespace trBase -{ - class Vec4d; - - /** - * General purpose 3D float Vector - */ - class TR_BASE_EXPORT Vec4f - { - public: - - /** Data type of vector components.*/ - using value_type = float; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4f(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4f(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4f to process. - */ - Vec4f(const osg::Vec4f &v); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4d to process. - */ - Vec4f(const osg::Vec4d &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4f& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4f& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4f& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4f Lerp(const Vec4f& from, const Vec4f& to, value_type alpha); - - /** - * @fn std::string Vec4f::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4f& v); - - /** - * Set operator - */ - void operator = (const Vec4d& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4f& v); - - /** - * Equality operator - */ - bool operator == (const Vec4f& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4f& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4f& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4f& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4f& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4f operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4f& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4f operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4f& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4f operator + (const Vec4f& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4f& operator += (const Vec4f& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4f operator - (const Vec4f& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4f& operator -= (const Vec4f& rhs); - - /** - * Negation operator. Returns the negative of the Vec4f. - */ - const Vec4f operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4f() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4f& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4f& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4f* (); - - protected: - - osg::Vec4f mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4f& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4f ComponentMultiply(const Vec4f& lhs, const Vec4f& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4f ComponentDivide(const Vec4f& lhs, const Vec4f& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +namespace osg +{ + class Vec4d; +} +/// @endcond + +namespace trBase +{ + class Vec4d; + + /** + * General purpose 3D float Vector + */ + class TR_BASE_EXPORT Vec4f + { + public: + + /** Data type of vector components.*/ + using value_type = float; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4f(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4f(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4f to process. + */ + Vec4f(const osg::Vec4f &v); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4d to process. + */ + Vec4f(const osg::Vec4d &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4f& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4f& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4f& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4f Lerp(const Vec4f& from, const Vec4f& to, value_type alpha); + + /** + * @fn std::string Vec4f::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4f& v); + + /** + * Set operator + */ + void operator = (const Vec4d& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4f& v); + + /** + * Equality operator + */ + bool operator == (const Vec4f& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4f& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4f& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4f& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4f& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4f operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4f& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4f operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4f& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4f operator + (const Vec4f& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4f& operator += (const Vec4f& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4f operator - (const Vec4f& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4f& operator -= (const Vec4f& rhs); + + /** + * Negation operator. Returns the negative of the Vec4f. + */ + const Vec4f operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4f() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4f& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4f& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4f* (); + + protected: + + osg::Vec4f mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4f& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4f ComponentMultiply(const Vec4f& lhs, const Vec4f& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4f ComponentDivide(const Vec4f& lhs, const Vec4f& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4i.h b/include/trBase/Vec4i.h index 3e46a31..c6c3baa 100644 --- a/include/trBase/Vec4i.h +++ b/include/trBase/Vec4i.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D integer Vector - */ - class TR_BASE_EXPORT Vec4i - { - public: - - /** Data type of vector components.*/ - using value_type = int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4i(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4i(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4i to process. - */ - Vec4i(const osg::Vec4i &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4i& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4i& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4i& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4i Lerp(const Vec4i& from, const Vec4i& to, value_type alpha); - - /** - * @fn std::string Vec4i::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4i& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4i& v); - - /** - * Equality operator - */ - bool operator == (const Vec4i& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4i& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4i& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4i& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4i& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4i operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4i& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4i operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4i& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4i operator + (const Vec4i& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4i& operator += (const Vec4i& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4i operator - (const Vec4i& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4i& operator -= (const Vec4i& rhs); - - /** - * Negation operator. Returns the negative of the Vec4i. - */ - const Vec4i operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4i() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4i& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4i& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4i* (); - - protected: - - osg::Vec4i mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4i& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4i ComponentMultiply(const Vec4i& lhs, const Vec4i& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4i ComponentDivide(const Vec4i& lhs, const Vec4i& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D integer Vector + */ + class TR_BASE_EXPORT Vec4i + { + public: + + /** Data type of vector components.*/ + using value_type = int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4i(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4i(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4i to process. + */ + Vec4i(const osg::Vec4i &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4i& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4i& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4i& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4i Lerp(const Vec4i& from, const Vec4i& to, value_type alpha); + + /** + * @fn std::string Vec4i::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4i& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4i& v); + + /** + * Equality operator + */ + bool operator == (const Vec4i& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4i& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4i& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4i& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4i& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4i operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4i& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4i operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4i& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4i operator + (const Vec4i& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4i& operator += (const Vec4i& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4i operator - (const Vec4i& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4i& operator -= (const Vec4i& rhs); + + /** + * Negation operator. Returns the negative of the Vec4i. + */ + const Vec4i operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4i() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4i& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4i& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4i* (); + + protected: + + osg::Vec4i mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4i& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4i ComponentMultiply(const Vec4i& lhs, const Vec4i& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4i ComponentDivide(const Vec4i& lhs, const Vec4i& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4s.h b/include/trBase/Vec4s.h index e6d4ddc..f7fc5ca 100644 --- a/include/trBase/Vec4s.h +++ b/include/trBase/Vec4s.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D short Vector - */ - class TR_BASE_EXPORT Vec4s - { - public: - - /** Data type of vector components.*/ - using value_type = short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4s(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4s(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4s to process. - */ - Vec4s(const osg::Vec4s &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4s& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4s& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4s& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4s Lerp(const Vec4s& from, const Vec4s& to, value_type alpha); - - /** - * @fn std::string Vec4s::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4s& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4s& v); - - /** - * Equality operator - */ - bool operator == (const Vec4s& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4s& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4s& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4s& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4s& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4s operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4s& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4s operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4s& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4s operator + (const Vec4s& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4s& operator += (const Vec4s& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4s operator - (const Vec4s& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4s& operator -= (const Vec4s& rhs); - - /** - * Negation operator. Returns the negative of the Vec4s. - */ - const Vec4s operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4s() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4s& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4s& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4s* (); - - protected: - - osg::Vec4s mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4s& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4s ComponentMultiply(const Vec4s& lhs, const Vec4s& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4s ComponentDivide(const Vec4s& lhs, const Vec4s& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D short Vector + */ + class TR_BASE_EXPORT Vec4s + { + public: + + /** Data type of vector components.*/ + using value_type = short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4s(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4s(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4s to process. + */ + Vec4s(const osg::Vec4s &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4s& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4s& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4s& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4s Lerp(const Vec4s& from, const Vec4s& to, value_type alpha); + + /** + * @fn std::string Vec4s::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4s& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4s& v); + + /** + * Equality operator + */ + bool operator == (const Vec4s& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4s& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4s& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4s& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4s& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4s operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4s& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4s operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4s& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4s operator + (const Vec4s& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4s& operator += (const Vec4s& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4s operator - (const Vec4s& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4s& operator -= (const Vec4s& rhs); + + /** + * Negation operator. Returns the negative of the Vec4s. + */ + const Vec4s operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4s() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4s& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4s& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4s* (); + + protected: + + osg::Vec4s mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4s& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4s ComponentMultiply(const Vec4s& lhs, const Vec4s& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4s ComponentDivide(const Vec4s& lhs, const Vec4s& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4ub.h b/include/trBase/Vec4ub.h index 5b9ebcf..393d02a 100644 --- a/include/trBase/Vec4ub.h +++ b/include/trBase/Vec4ub.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned byte Vector - */ - class TR_BASE_EXPORT Vec4ub - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned char; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4ub(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4ub(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4ub to process. - */ - Vec4ub(const osg::Vec4ub &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4ub& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4ub& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4ub& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4ub Lerp(const Vec4ub& from, const Vec4ub& to, value_type alpha); - - /** - * @fn std::string Vec4ub::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4ub& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4ub& v); - - /** - * Equality operator - */ - bool operator == (const Vec4ub& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4ub& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4ub& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4ub& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4ub& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4ub operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4ub& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4ub operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4ub& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4ub operator + (const Vec4ub& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4ub& operator += (const Vec4ub& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4ub operator - (const Vec4ub& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4ub& operator -= (const Vec4ub& rhs); - - /** - * Negation operator. Returns the negative of the Vec4ub. - */ - const Vec4ub operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ub() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ub& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4ub& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ub* (); - - protected: - - osg::Vec4ub mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4ub& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4ub ComponentMultiply(const Vec4ub& lhs, const Vec4ub& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4ub ComponentDivide(const Vec4ub& lhs, const Vec4ub& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned byte Vector + */ + class TR_BASE_EXPORT Vec4ub + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned char; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4ub(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4ub(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4ub to process. + */ + Vec4ub(const osg::Vec4ub &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4ub& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4ub& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4ub& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4ub Lerp(const Vec4ub& from, const Vec4ub& to, value_type alpha); + + /** + * @fn std::string Vec4ub::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4ub& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4ub& v); + + /** + * Equality operator + */ + bool operator == (const Vec4ub& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4ub& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4ub& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4ub& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4ub& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4ub operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4ub& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4ub operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4ub& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4ub operator + (const Vec4ub& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4ub& operator += (const Vec4ub& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4ub operator - (const Vec4ub& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4ub& operator -= (const Vec4ub& rhs); + + /** + * Negation operator. Returns the negative of the Vec4ub. + */ + const Vec4ub operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ub() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ub& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4ub& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ub* (); + + protected: + + osg::Vec4ub mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4ub& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4ub ComponentMultiply(const Vec4ub& lhs, const Vec4ub& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4ub ComponentDivide(const Vec4ub& lhs, const Vec4ub& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4ui.h b/include/trBase/Vec4ui.h index 28204f6..139bd40 100644 --- a/include/trBase/Vec4ui.h +++ b/include/trBase/Vec4ui.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned integer Vector - */ - class TR_BASE_EXPORT Vec4ui - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned int; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4ui(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4ui(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4ui to process. - */ - Vec4ui(const osg::Vec4ui &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4ui& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4ui& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4ui& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4ui Lerp(const Vec4ui& from, const Vec4ui& to, value_type alpha); - - /** - * @fn std::string Vec4ui::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4ui& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4ui& v); - - /** - * Equality operator - */ - bool operator == (const Vec4ui& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4ui& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4ui& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4ui& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4ui& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4ui operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4ui& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4ui operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4ui& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4ui operator + (const Vec4ui& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4ui& operator += (const Vec4ui& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4ui operator - (const Vec4ui& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4ui& operator -= (const Vec4ui& rhs); - - /** - * Negation operator. Returns the negative of the Vec4ui. - */ - const Vec4ui operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ui() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ui& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4ui& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4ui* (); - - protected: - - osg::Vec4ui mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4ui& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4ui ComponentMultiply(const Vec4ui& lhs, const Vec4ui& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4ui ComponentDivide(const Vec4ui& lhs, const Vec4ui& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned integer Vector + */ + class TR_BASE_EXPORT Vec4ui + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned int; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4ui(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4ui(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4ui to process. + */ + Vec4ui(const osg::Vec4ui &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4ui& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4ui& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4ui& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4ui Lerp(const Vec4ui& from, const Vec4ui& to, value_type alpha); + + /** + * @fn std::string Vec4ui::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4ui& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4ui& v); + + /** + * Equality operator + */ + bool operator == (const Vec4ui& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4ui& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4ui& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4ui& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4ui& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4ui operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4ui& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4ui operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4ui& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4ui operator + (const Vec4ui& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4ui& operator += (const Vec4ui& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4ui operator - (const Vec4ui& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4ui& operator -= (const Vec4ui& rhs); + + /** + * Negation operator. Returns the negative of the Vec4ui. + */ + const Vec4ui operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ui() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ui& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4ui& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4ui* (); + + protected: + + osg::Vec4ui mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4ui& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4ui ComponentMultiply(const Vec4ui& lhs, const Vec4ui& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4ui ComponentDivide(const Vec4ui& lhs, const Vec4ui& rhs); } \ No newline at end of file diff --git a/include/trBase/Vec4us.h b/include/trBase/Vec4us.h index 31f9582..ec49074 100644 --- a/include/trBase/Vec4us.h +++ b/include/trBase/Vec4us.h @@ -1,360 +1,360 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -#include -#include - -namespace trBase -{ - /** - * General purpose 3D unsigned short Vector - */ - class TR_BASE_EXPORT Vec4us - { - public: - - /** Data type of vector components.*/ - using value_type = unsigned short; - - const static int NUM_OF_COMPONENTS; - - /** - * @brief Default constructor. - */ - Vec4us(); - - /** - * @brief Constructor. - * - * @param x The x component of the vector. - * @param y The y component of the vector. - * @param z The z component of the vector. - * @param w The w component of the vector. - */ - Vec4us(value_type x, value_type y, value_type z, value_type w); - - /** - * @brief Copy Constructor from osg::Vec to trBase::Vec. - * - * @param v The osg::Vec4us to process. - */ - Vec4us(const osg::Vec4us &v); - - /** - * Returns the internal OSG vector. - */ - const osg::Vec4us& GetOSGVector() const; - - /** - * Length of the vector = sqrt( vec . vec ) - */ - value_type Length() const; - - /** - * Length squared of the vector = vec . vec - */ - value_type Length2() const; - - /** - * Normalize the vector so that it has length unity. - * Returns the previous length of the vector. - */ - value_type Normalize(); - - /** - * Returns the X component of the vector - */ - value_type& X(); - - /** - * Returns the Y component of the vector - */ - value_type& Y(); - - /** - * Returns the Z component of the vector - */ - value_type& Z(); - - /** - * Returns the W component of the vector - */ - value_type& W(); - - /** - * Returns the X component of the vector - */ - value_type X() const; - - /** - * Returns the Y component of the vector - */ - value_type Y() const; - - /** - * Returns the Z component of the vector - */ - value_type Z() const; - - /** - * Returns the W component of the vector - */ - value_type W() const; - - /** - * Returns the R component of the vector - */ - value_type& R(); - - /** - * Returns the G component of the vector - */ - value_type& G(); - - /** - * Returns the B component of the vector - */ - value_type& B(); - - /** - * Returns the A component of the vector - */ - value_type& A(); - - /** - * Returns the R component of the vector - */ - value_type R() const; - - /** - * Returns the G component of the vector - */ - value_type G() const; - - /** - * Returns the B component of the vector - */ - value_type B() const; - - /** - * Returns the A component of the vector - */ - value_type A() const; - - /** - * Sets the initial values of the vector - */ - void Set(value_type x, value_type y, value_type z, value_type w); - - /** - * Sets the initial values of the vector - */ - void Set(const Vec4us& v); - - /** - * Sets the initial values of the vector - */ - void SetRGBA(value_type r, value_type g, value_type b, value_type a); - - /** - * @brief Linear interpolation of this vector to a passed in vector. - * - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - */ - void Lerp(const Vec4us& to, value_type alpha); - - /** - * @brief Linear interpolation of two vectors. - * - * @param from The vector that we are interpolating from. - * @param to The vector that we are interpolating to. - * @param alpha Amount of change (0-1). - * - * @return An interpolated vector. - */ - Vec4us Lerp(const Vec4us& from, const Vec4us& to, value_type alpha); - - /** - * @fn std::string Vec4us::ToString(int precision = -1); - * - * @brief Convert this object into a string representation. - * - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - std::string ToString(int precision = -1); - - /** - * Pointer to the internal Vector array. - */ - value_type* Ptr(); - - /** - * Pointer to the internal Vector array. - */ - const value_type* Ptr() const; - - /** - * Index operator - */ - value_type& operator [] (int i); - - /** - * Index operator - */ - value_type operator [] (int i) const; - - /** - * Set operator - */ - void operator = (const Vec4us& v); - - /** - * Set operator - */ - void operator = (const osg::Vec4us& v); - - /** - * Equality operator - */ - bool operator == (const Vec4us& v) const; - - /** - * Inequality operator - */ - bool operator != (const Vec4us& v) const; - - /** - * Less than operator - */ - bool operator < (const Vec4us& v) const; - - /** - * Greater than operator - */ - bool operator > (const Vec4us& v) const; - - /** - * Dot product operator. - */ - value_type operator * (const Vec4us& rhs) const; - - /** - * Scalar multiplication operator. - */ - const Vec4us operator * (value_type rhs) const; - - /** - * Unary scalar multiplication operator. - */ - Vec4us& operator *= (value_type rhs); - - /** - * Divide by scalar operator. - */ - const Vec4us operator / (value_type rhs) const; - - /** - * Unary divide by scalar operator. - */ - Vec4us& operator /= (value_type rhs); - - /** - * Binary vector add operator. - */ - const Vec4us operator + (const Vec4us& rhs) const; - - /** - * Unary vector add operator. Slightly more efficient because it has - * no temporary intermediate objects. - */ - Vec4us& operator += (const Vec4us& rhs); - - /** - * Binary vector subtraction operator. - */ - const Vec4us operator - (const Vec4us& rhs) const; - - /** - * Unary vector subtraction operator. - */ - Vec4us& operator -= (const Vec4us& rhs); - - /** - * Negation operator. Returns the negative of the Vec4us. - */ - const Vec4us operator - () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4us() const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4us& (); - - /** - * Implicit conversion operator to OSG Vector - */ - operator const osg::Vec4us& () const; - - /** - * Implicit conversion operator to OSG Vector - */ - operator osg::Vec4us* (); - - protected: - - osg::Vec4us mVec; - }; - - /** - * @brief Stream insertion operator. - * - * @param [in,out] ios The ios. - * @param vec The vector. - * - * @return The shifted result. - */ - TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4us& vec); - - /** - * Multiply individual vector components. - */ - TR_BASE_EXPORT Vec4us ComponentMultiply(const Vec4us& lhs, const Vec4us& rhs); - - /** - * Divide rhs components by rhs vector components. - */ - TR_BASE_EXPORT Vec4us ComponentDivide(const Vec4us& lhs, const Vec4us& rhs); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +#include +#include + +namespace trBase +{ + /** + * General purpose 3D unsigned short Vector + */ + class TR_BASE_EXPORT Vec4us + { + public: + + /** Data type of vector components.*/ + using value_type = unsigned short; + + const static int NUM_OF_COMPONENTS; + + /** + * @brief Default constructor. + */ + Vec4us(); + + /** + * @brief Constructor. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @param z The z component of the vector. + * @param w The w component of the vector. + */ + Vec4us(value_type x, value_type y, value_type z, value_type w); + + /** + * @brief Copy Constructor from osg::Vec to trBase::Vec. + * + * @param v The osg::Vec4us to process. + */ + Vec4us(const osg::Vec4us &v); + + /** + * Returns the internal OSG vector. + */ + const osg::Vec4us& GetOSGVector() const; + + /** + * Length of the vector = sqrt( vec . vec ) + */ + value_type Length() const; + + /** + * Length squared of the vector = vec . vec + */ + value_type Length2() const; + + /** + * Normalize the vector so that it has length unity. + * Returns the previous length of the vector. + */ + value_type Normalize(); + + /** + * Returns the X component of the vector + */ + value_type& X(); + + /** + * Returns the Y component of the vector + */ + value_type& Y(); + + /** + * Returns the Z component of the vector + */ + value_type& Z(); + + /** + * Returns the W component of the vector + */ + value_type& W(); + + /** + * Returns the X component of the vector + */ + value_type X() const; + + /** + * Returns the Y component of the vector + */ + value_type Y() const; + + /** + * Returns the Z component of the vector + */ + value_type Z() const; + + /** + * Returns the W component of the vector + */ + value_type W() const; + + /** + * Returns the R component of the vector + */ + value_type& R(); + + /** + * Returns the G component of the vector + */ + value_type& G(); + + /** + * Returns the B component of the vector + */ + value_type& B(); + + /** + * Returns the A component of the vector + */ + value_type& A(); + + /** + * Returns the R component of the vector + */ + value_type R() const; + + /** + * Returns the G component of the vector + */ + value_type G() const; + + /** + * Returns the B component of the vector + */ + value_type B() const; + + /** + * Returns the A component of the vector + */ + value_type A() const; + + /** + * Sets the initial values of the vector + */ + void Set(value_type x, value_type y, value_type z, value_type w); + + /** + * Sets the initial values of the vector + */ + void Set(const Vec4us& v); + + /** + * Sets the initial values of the vector + */ + void SetRGBA(value_type r, value_type g, value_type b, value_type a); + + /** + * @brief Linear interpolation of this vector to a passed in vector. + * + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + */ + void Lerp(const Vec4us& to, value_type alpha); + + /** + * @brief Linear interpolation of two vectors. + * + * @param from The vector that we are interpolating from. + * @param to The vector that we are interpolating to. + * @param alpha Amount of change (0-1). + * + * @return An interpolated vector. + */ + Vec4us Lerp(const Vec4us& from, const Vec4us& to, value_type alpha); + + /** + * @fn std::string Vec4us::ToString(int precision = -1); + * + * @brief Convert this object into a string representation. + * + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + std::string ToString(int precision = -1); + + /** + * Pointer to the internal Vector array. + */ + value_type* Ptr(); + + /** + * Pointer to the internal Vector array. + */ + const value_type* Ptr() const; + + /** + * Index operator + */ + value_type& operator [] (int i); + + /** + * Index operator + */ + value_type operator [] (int i) const; + + /** + * Set operator + */ + void operator = (const Vec4us& v); + + /** + * Set operator + */ + void operator = (const osg::Vec4us& v); + + /** + * Equality operator + */ + bool operator == (const Vec4us& v) const; + + /** + * Inequality operator + */ + bool operator != (const Vec4us& v) const; + + /** + * Less than operator + */ + bool operator < (const Vec4us& v) const; + + /** + * Greater than operator + */ + bool operator > (const Vec4us& v) const; + + /** + * Dot product operator. + */ + value_type operator * (const Vec4us& rhs) const; + + /** + * Scalar multiplication operator. + */ + const Vec4us operator * (value_type rhs) const; + + /** + * Unary scalar multiplication operator. + */ + Vec4us& operator *= (value_type rhs); + + /** + * Divide by scalar operator. + */ + const Vec4us operator / (value_type rhs) const; + + /** + * Unary divide by scalar operator. + */ + Vec4us& operator /= (value_type rhs); + + /** + * Binary vector add operator. + */ + const Vec4us operator + (const Vec4us& rhs) const; + + /** + * Unary vector add operator. Slightly more efficient because it has + * no temporary intermediate objects. + */ + Vec4us& operator += (const Vec4us& rhs); + + /** + * Binary vector subtraction operator. + */ + const Vec4us operator - (const Vec4us& rhs) const; + + /** + * Unary vector subtraction operator. + */ + Vec4us& operator -= (const Vec4us& rhs); + + /** + * Negation operator. Returns the negative of the Vec4us. + */ + const Vec4us operator - () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4us() const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4us& (); + + /** + * Implicit conversion operator to OSG Vector + */ + operator const osg::Vec4us& () const; + + /** + * Implicit conversion operator to OSG Vector + */ + operator osg::Vec4us* (); + + protected: + + osg::Vec4us mVec; + }; + + /** + * @brief Stream insertion operator. + * + * @param [in,out] ios The ios. + * @param vec The vector. + * + * @return The shifted result. + */ + TR_BASE_EXPORT std::ostream& operator << (std::ostream& ios, const Vec4us& vec); + + /** + * Multiply individual vector components. + */ + TR_BASE_EXPORT Vec4us ComponentMultiply(const Vec4us& lhs, const Vec4us& rhs); + + /** + * Divide rhs components by rhs vector components. + */ + TR_BASE_EXPORT Vec4us ComponentDivide(const Vec4us& lhs, const Vec4us& rhs); } \ No newline at end of file diff --git a/include/trCore/Export.h b/include/trCore/Export.h index 26b4b60..6e62016 100644 --- a/include/trCore/Export.h +++ b/include/trCore/Export.h @@ -1,35 +1,35 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) -# ifdef TR_CORE_LIBRARY -# define TR_CORE_EXPORT __declspec(dllexport) -# else -# define TR_CORE_EXPORT __declspec(dllimport) -# endif -#else -# ifdef TR_CORE_LIBRARY -# define TR_CORE_EXPORT __attribute__ ((visibility("default"))) -# else -# define TR_CORE_EXPORT -# endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef TR_CORE_LIBRARY +# define TR_CORE_EXPORT __declspec(dllexport) +# else +# define TR_CORE_EXPORT __declspec(dllimport) +# endif +#else +# ifdef TR_CORE_LIBRARY +# define TR_CORE_EXPORT __attribute__ ((visibility("default"))) +# else +# define TR_CORE_EXPORT +# endif #endif \ No newline at end of file diff --git a/include/trCore/MessageCameraSynch.h b/include/trCore/MessageCameraSynch.h index 81e47ba..eb35189 100644 --- a/include/trCore/MessageCameraSynch.h +++ b/include/trCore/MessageCameraSynch.h @@ -1,77 +1,77 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessageCameraSynch - * - * @brief A message that is sent out on Camera Synchronization. - */ - class TR_CORE_EXPORT MessageCameraSynch : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageCameraSynch::MessageCameraSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessageCameraSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessageCameraSynch::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - protected: - - /** - * @fn MessageCameraSynch::~MessageCameraSynch(); - * - * @brief Destructor. - */ - ~MessageCameraSynch(); - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessageCameraSynch + * + * @brief A message that is sent out on Camera Synchronization. + */ + class TR_CORE_EXPORT MessageCameraSynch : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageCameraSynch::MessageCameraSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessageCameraSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessageCameraSynch::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + protected: + + /** + * @fn MessageCameraSynch::~MessageCameraSynch(); + * + * @brief Destructor. + */ + ~MessageCameraSynch(); + }; +} + + diff --git a/include/trCore/MessageEventTraversal.h b/include/trCore/MessageEventTraversal.h index a1a479c..bc0ba5d 100644 --- a/include/trCore/MessageEventTraversal.h +++ b/include/trCore/MessageEventTraversal.h @@ -1,77 +1,77 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessageEventTraversal - * - * @brief A message that is sent out on event traversal. - */ - class TR_CORE_EXPORT MessageEventTraversal : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageEventTraversal::MessageEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessageEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessageEventTraversal::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - protected: - - /** - * @fn MessageEventTraversal::~MessageEventTraversal(); - * - * @brief Destructor. - */ - ~MessageEventTraversal(); - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessageEventTraversal + * + * @brief A message that is sent out on event traversal. + */ + class TR_CORE_EXPORT MessageEventTraversal : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageEventTraversal::MessageEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessageEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessageEventTraversal::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + protected: + + /** + * @fn MessageEventTraversal::~MessageEventTraversal(); + * + * @brief Destructor. + */ + ~MessageEventTraversal(); + }; +} + + diff --git a/include/trCore/MessageFrame.h b/include/trCore/MessageFrame.h index 6c8a23d..829ca7c 100644 --- a/include/trCore/MessageFrame.h +++ b/include/trCore/MessageFrame.h @@ -1,77 +1,77 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessageFrame - * - * @brief A message that is sent out on Frame Event. - */ - class TR_CORE_EXPORT MessageFrame : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageFrame::MessageFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessageFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessageFrame::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - protected: - - /** - * @fn MessageFrame::~MessageFrame(); - * - * @brief Destructor. - */ - ~MessageFrame(); - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessageFrame + * + * @brief A message that is sent out on Frame Event. + */ + class TR_CORE_EXPORT MessageFrame : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageFrame::MessageFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessageFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessageFrame::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + protected: + + /** + * @fn MessageFrame::~MessageFrame(); + * + * @brief Destructor. + */ + ~MessageFrame(); + }; +} + + diff --git a/include/trCore/MessageFrameSynch.h b/include/trCore/MessageFrameSynch.h index 9762518..068adf2 100644 --- a/include/trCore/MessageFrameSynch.h +++ b/include/trCore/MessageFrameSynch.h @@ -1,78 +1,78 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessageFrameSynch - * - * @brief A message that is sent out on Frame Synchronization. - */ - class TR_CORE_EXPORT MessageFrameSynch : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageFrameSynch::MessageFrameSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessageFrameSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessageFrameSynch::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - - protected: - - /** - * @fn MessageFrameSynch::~MessageFrameSynch(); - * - * @brief Destructor. - */ - ~MessageFrameSynch(); - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessageFrameSynch + * + * @brief A message that is sent out on Frame Synchronization. + */ + class TR_CORE_EXPORT MessageFrameSynch : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageFrameSynch::MessageFrameSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessageFrameSynch(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessageFrameSynch::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + + protected: + + /** + * @fn MessageFrameSynch::~MessageFrameSynch(); + * + * @brief Destructor. + */ + ~MessageFrameSynch(); + }; +} + + diff --git a/include/trCore/MessagePostEventTraversal.h b/include/trCore/MessagePostEventTraversal.h index 65a9481..aa02740 100644 --- a/include/trCore/MessagePostEventTraversal.h +++ b/include/trCore/MessagePostEventTraversal.h @@ -1,78 +1,78 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessagePostEventTraversal - * - * @brief A message that is sent out on post event traversal. - */ - class TR_CORE_EXPORT MessagePostEventTraversal : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessagePostEventTraversal::MessagePostEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessagePostEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessagePostEventTraversal::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - - protected: - - /** - * @fn MessagePostEventTraversal::~MessagePostEventTraversal(); - * - * @brief Destructor. - */ - ~MessagePostEventTraversal(); - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessagePostEventTraversal + * + * @brief A message that is sent out on post event traversal. + */ + class TR_CORE_EXPORT MessagePostEventTraversal : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessagePostEventTraversal::MessagePostEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessagePostEventTraversal(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessagePostEventTraversal::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + + protected: + + /** + * @fn MessagePostEventTraversal::~MessagePostEventTraversal(); + * + * @brief Destructor. + */ + ~MessagePostEventTraversal(); + }; +} + + diff --git a/include/trCore/MessagePostFrame.h b/include/trCore/MessagePostFrame.h index a637e6d..a31970d 100644 --- a/include/trCore/MessagePostFrame.h +++ b/include/trCore/MessagePostFrame.h @@ -1,76 +1,76 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trCore -{ - /** - * @class MessagePostFrame - * - * @brief A message that is sent out on Frame Event. - */ - class TR_CORE_EXPORT MessagePostFrame : public trManager::MessageTick - { - public: - using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessagePostFrame::MessagePostFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessagePostFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessagePostFrame::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - - protected: - - /** - * @fn MessagePostFrame::~MessagePostFrame(); - * - * @brief Destructor. - */ - ~MessagePostFrame(); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trCore +{ + /** + * @class MessagePostFrame + * + * @brief A message that is sent out on Frame Event. + */ + class TR_CORE_EXPORT MessagePostFrame : public trManager::MessageTick + { + public: + using BaseClass = trManager::MessageTick; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessagePostFrame::MessagePostFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessagePostFrame(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessagePostFrame::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + + protected: + + /** + * @fn MessagePostFrame::~MessagePostFrame(); + * + * @brief Destructor. + */ + ~MessagePostFrame(); + }; } \ No newline at end of file diff --git a/include/trCore/MessageSystemControl.h b/include/trCore/MessageSystemControl.h index a844706..ddda10a 100644 --- a/include/trCore/MessageSystemControl.h +++ b/include/trCore/MessageSystemControl.h @@ -1,99 +1,99 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include - -namespace trCore -{ - /** - * @class MessageSystemControl - * - * @brief A message that lets the system know what state to enable and setup. - */ - class TR_CORE_EXPORT MessageSystemControl : public trManager::MessageBase - { - public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageSystemControl::MessageSystemControl(const trBase::UniqueId* fromActorID, const trCore::SystemControls &systemControl, double systemValue = 0); - * - * @brief Constructor. - * - * @param fromActorID Identifier for from actor. - * @param systemControl The system control. - * @param systemValue (Optional) The system value is used to pass data for specific - * Controls. Not all Controls need one. - */ - MessageSystemControl(const trBase::UniqueId* fromActorID, const trCore::SystemControls &systemControl, double systemValue = 0); - - /** - * @fn virtual const std::string& MessageSystemControl::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn virtual trCore::SystemControls& MessageSystemControl::GetSysControlType(); - * - * @brief Gets system control type. - * - * @return The system control type. - */ - virtual const trCore::SystemControls& GetSysControlType() const; - - /** - * @fn virtual double MessageSystemControl::GetSystemValue() const; - * - * @brief Gets system value. - * - * @return The system value. - */ - virtual double GetSystemValue() const; - - protected: - - /** - * @fn MessageSystemControl::~MessageSystemControl(); - * - * @brief Destructor. - */ - ~MessageSystemControl(); - - private: - - const trCore::SystemControls* mSystemControl; - double mSystemValue; - - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include + +namespace trCore +{ + /** + * @class MessageSystemControl + * + * @brief A message that lets the system know what state to enable and setup. + */ + class TR_CORE_EXPORT MessageSystemControl : public trManager::MessageBase + { + public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageSystemControl::MessageSystemControl(const trBase::UniqueId* fromActorID, const trCore::SystemControls &systemControl, double systemValue = 0); + * + * @brief Constructor. + * + * @param fromActorID Identifier for from actor. + * @param systemControl The system control. + * @param systemValue (Optional) The system value is used to pass data for specific + * Controls. Not all Controls need one. + */ + MessageSystemControl(const trBase::UniqueId* fromActorID, const trCore::SystemControls &systemControl, double systemValue = 0); + + /** + * @fn virtual const std::string& MessageSystemControl::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn virtual trCore::SystemControls& MessageSystemControl::GetSysControlType(); + * + * @brief Gets system control type. + * + * @return The system control type. + */ + virtual const trCore::SystemControls& GetSysControlType() const; + + /** + * @fn virtual double MessageSystemControl::GetSystemValue() const; + * + * @brief Gets system value. + * + * @return The system value. + */ + virtual double GetSystemValue() const; + + protected: + + /** + * @fn MessageSystemControl::~MessageSystemControl(); + * + * @brief Destructor. + */ + ~MessageSystemControl(); + + private: + + const trCore::SystemControls* mSystemControl; + double mSystemValue; + + }; +} + diff --git a/include/trCore/MessageSystemEvent.h b/include/trCore/MessageSystemEvent.h index 86a9b00..5cfb205 100644 --- a/include/trCore/MessageSystemEvent.h +++ b/include/trCore/MessageSystemEvent.h @@ -1,81 +1,81 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include - -namespace trCore -{ - class TR_CORE_EXPORT MessageSystemEvent : public trManager::MessageBase - { - public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageSystemEvent::MessageSystemEvent(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, trCore::SystemEvents &systemEvent); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor this message is being sent from. - * @param aboutActorID Id of the actor this message is being sent to, or is about. - * @param [in,out] systemEvent The system event type. - */ - MessageSystemEvent(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const trCore::SystemEvents &systemEvent); - - /** - * @fn virtual const std::string& MessageSystemEvent::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn virtual const trCore::SystemEvents& MessageSystemEvent::GetSysEventType() const; - * - * @brief Gets system event type. - * - * @return The system event type. - */ - virtual const trCore::SystemEvents& GetSysEventType() const; - - protected: - - /** - * @fn MessageSystemEvent::~MessageSystemEvent(); - * - * @brief Destructor. - */ - ~MessageSystemEvent(); - - private: - - const trCore::SystemEvents* mSystemEvent; - }; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include + +namespace trCore +{ + class TR_CORE_EXPORT MessageSystemEvent : public trManager::MessageBase + { + public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageSystemEvent::MessageSystemEvent(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, trCore::SystemEvents &systemEvent); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor this message is being sent from. + * @param aboutActorID Id of the actor this message is being sent to, or is about. + * @param [in,out] systemEvent The system event type. + */ + MessageSystemEvent(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const trCore::SystemEvents &systemEvent); + + /** + * @fn virtual const std::string& MessageSystemEvent::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn virtual const trCore::SystemEvents& MessageSystemEvent::GetSysEventType() const; + * + * @brief Gets system event type. + * + * @return The system event type. + */ + virtual const trCore::SystemEvents& GetSysEventType() const; + + protected: + + /** + * @fn MessageSystemEvent::~MessageSystemEvent(); + * + * @brief Destructor. + */ + ~MessageSystemEvent(); + + private: + + const trCore::SystemEvents* mSystemEvent; + }; +} diff --git a/include/trCore/SceneObjects/RingArray.h b/include/trCore/SceneObjects/RingArray.h index 8b14c1d..7b7cb60 100644 --- a/include/trCore/SceneObjects/RingArray.h +++ b/include/trCore/SceneObjects/RingArray.h @@ -1,195 +1,195 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include -#include -#include -#include - -/** - * @namespace trCore::SceneObjects - * - * @brief Namespace that contains controls for sample scene objects. - */ -namespace trCore::SceneObjects -{ - /** - * @class RingArray - * - * @brief A rotating ring array model. - * - * @author Maxim Serebrennik - */ - class TR_CORE_EXPORT RingArray : public osg::Group - { - public: - - const static std::string RING_1_FILE_NAME; - const static std::string RING_2_FILE_NAME; - const static std::string RING_3_FILE_NAME; - const static std::string RING_4_FILE_NAME; - - /** - * @fn RingArray::RingArray(); - * - * @brief Default constructor. - */ - RingArray(); - - /** - * @fn RingArray::RingArray(double angleCorrection); - * - * @brief Constructor. - * - * @param angleCorrection Changes the initial direction of the ring. Angle is in degrees. - */ - RingArray(double angleCorrection); - - /** - * @fn virtual void RingArray::Update(osg::Node* node, osg::NodeVisitor* nv, double deltaTime); - * - * @brief This function gets called by the RingArrayCallback. - * - * @param deltaTime The delta time between frames. - */ - virtual void Update(double deltaTime); - - protected: - - /** - * @fn RingArray::~RingArray(); - * - * @brief Destructor. - */ - ~RingArray(); - - /** - * @fn void RingArray::LoadModels(); - * - * @brief Loads the models and creates transform nodes for the model tree. - */ - void LoadModels(); - - /** - * @fn void RingArray::SetupModelTree(); - * - * @brief Sets up the model tree. - */ - void SetupModelTree(); - - /** - * @fn void RingArray::UpdateRing1Slide(double deltaTime); - * - * @brief Updates the ring 1 slide. - * - * @param deltaTime The delta time. - */ - void UpdateRing1Slide(double deltaTime); - - /** - * @fn void RingArray::UpdateRing2Angle(double deltaTime); - * - * @brief Updates the ring 2 angle. - * - * @param deltaTime The delta time. - */ - void UpdateRing2Angle(double deltaTime); - - /** - * @fn void RingArray::UpdateRing2Slide(double deltaTime); - * - * @brief Updates the ring 2 slide. - * - * @param deltaTime The delta time. - */ - void UpdateRing2Slide(double deltaTime); - - /** - * @fn void RingArray::UpdateRing3Angle(double deltaTime); - * - * @brief Updates the ring 3 angle. - * - * @param deltaTime The delta time. - */ - void UpdateRing3Angle(double deltaTime); - - /** - * @fn void RingArray::UpdateRing3Slide(double deltaTime); - * - * @brief Updates the ring 3 slide. - * - * @param deltaTime The delta time. - */ - void UpdateRing3Slide(double deltaTime); - - /** - * @fn void RingArray::UpdateRing4Angle(double deltaTime); - * - * @brief Updates the ring 4 angle. - * - * @param deltaTime The delta time. - */ - void UpdateRing4Angle(double deltaTime); - - private: - - const double MAX_RING_SPEED = 5.0; - const double RING_ACCEL = 0.1; - const double START_DELAY = 5.0; - - trBase::SmrtPtr mRing1; - trBase::SmrtPtr mRing1Slide; - double mRing1SlideSpeed = 0.0; - double mRing1SlideAngle = 0.0; - double mRing1SlideDelay = 0.0; - trBase::SmrtPtr mRing2; - trBase::SmrtPtr mRing2Rotation; - double mRing2RotationSpeed = 0.0; - double mRing2RotationAngle = 0.0; - double mRing2RotationDelay = 0.0; - trBase::SmrtPtr mRing2Slide; - double mRing2SlideSpeed = 0.0; - double mRing2SlideAngle = 0.0; - double mRing2SlideDelay = 0.0; - trBase::SmrtPtr mRing3; - trBase::SmrtPtr mRing3Rotation; - double mRing3RotationSpeed = 0.0; - double mRing3RotationAngle = 0.0; - double mRing3RotationDelay = 0.0; - trBase::SmrtPtr mRing3Slide; - double mRing3SlideSpeed = 0.0; - double mRing3SlideAngle = 0.0; - double mRing3SlideDelay = 0.0; - trBase::SmrtPtr mRing4; - trBase::SmrtPtr mRing4Rotation; - double mRing4RotationSpeed = 0.0; - double mRing4RotationAngle = 0.0; - double mRing4RotationDelay = 0.0; - - trBase::SmrtPtr mAngleCorrection; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include +#include +#include +#include + +/** + * @namespace trCore::SceneObjects + * + * @brief Namespace that contains controls for sample scene objects. + */ +namespace trCore::SceneObjects +{ + /** + * @class RingArray + * + * @brief A rotating ring array model. + * + * @author Maxim Serebrennik + */ + class TR_CORE_EXPORT RingArray : public osg::Group + { + public: + + const static std::string RING_1_FILE_NAME; + const static std::string RING_2_FILE_NAME; + const static std::string RING_3_FILE_NAME; + const static std::string RING_4_FILE_NAME; + + /** + * @fn RingArray::RingArray(); + * + * @brief Default constructor. + */ + RingArray(); + + /** + * @fn RingArray::RingArray(double angleCorrection); + * + * @brief Constructor. + * + * @param angleCorrection Changes the initial direction of the ring. Angle is in degrees. + */ + RingArray(double angleCorrection); + + /** + * @fn virtual void RingArray::Update(osg::Node* node, osg::NodeVisitor* nv, double deltaTime); + * + * @brief This function gets called by the RingArrayCallback. + * + * @param deltaTime The delta time between frames. + */ + virtual void Update(double deltaTime); + + protected: + + /** + * @fn RingArray::~RingArray(); + * + * @brief Destructor. + */ + ~RingArray(); + + /** + * @fn void RingArray::LoadModels(); + * + * @brief Loads the models and creates transform nodes for the model tree. + */ + void LoadModels(); + + /** + * @fn void RingArray::SetupModelTree(); + * + * @brief Sets up the model tree. + */ + void SetupModelTree(); + + /** + * @fn void RingArray::UpdateRing1Slide(double deltaTime); + * + * @brief Updates the ring 1 slide. + * + * @param deltaTime The delta time. + */ + void UpdateRing1Slide(double deltaTime); + + /** + * @fn void RingArray::UpdateRing2Angle(double deltaTime); + * + * @brief Updates the ring 2 angle. + * + * @param deltaTime The delta time. + */ + void UpdateRing2Angle(double deltaTime); + + /** + * @fn void RingArray::UpdateRing2Slide(double deltaTime); + * + * @brief Updates the ring 2 slide. + * + * @param deltaTime The delta time. + */ + void UpdateRing2Slide(double deltaTime); + + /** + * @fn void RingArray::UpdateRing3Angle(double deltaTime); + * + * @brief Updates the ring 3 angle. + * + * @param deltaTime The delta time. + */ + void UpdateRing3Angle(double deltaTime); + + /** + * @fn void RingArray::UpdateRing3Slide(double deltaTime); + * + * @brief Updates the ring 3 slide. + * + * @param deltaTime The delta time. + */ + void UpdateRing3Slide(double deltaTime); + + /** + * @fn void RingArray::UpdateRing4Angle(double deltaTime); + * + * @brief Updates the ring 4 angle. + * + * @param deltaTime The delta time. + */ + void UpdateRing4Angle(double deltaTime); + + private: + + const double MAX_RING_SPEED = 5.0; + const double RING_ACCEL = 0.1; + const double START_DELAY = 5.0; + + trBase::SmrtPtr mRing1; + trBase::SmrtPtr mRing1Slide; + double mRing1SlideSpeed = 0.0; + double mRing1SlideAngle = 0.0; + double mRing1SlideDelay = 0.0; + trBase::SmrtPtr mRing2; + trBase::SmrtPtr mRing2Rotation; + double mRing2RotationSpeed = 0.0; + double mRing2RotationAngle = 0.0; + double mRing2RotationDelay = 0.0; + trBase::SmrtPtr mRing2Slide; + double mRing2SlideSpeed = 0.0; + double mRing2SlideAngle = 0.0; + double mRing2SlideDelay = 0.0; + trBase::SmrtPtr mRing3; + trBase::SmrtPtr mRing3Rotation; + double mRing3RotationSpeed = 0.0; + double mRing3RotationAngle = 0.0; + double mRing3RotationDelay = 0.0; + trBase::SmrtPtr mRing3Slide; + double mRing3SlideSpeed = 0.0; + double mRing3SlideAngle = 0.0; + double mRing3SlideDelay = 0.0; + trBase::SmrtPtr mRing4; + trBase::SmrtPtr mRing4Rotation; + double mRing4RotationSpeed = 0.0; + double mRing4RotationAngle = 0.0; + double mRing4RotationDelay = 0.0; + + trBase::SmrtPtr mAngleCorrection; + }; } \ No newline at end of file diff --git a/include/trCore/SceneObjects/RingArrayCallback.h b/include/trCore/SceneObjects/RingArrayCallback.h index 32ab575..3b27649 100644 --- a/include/trCore/SceneObjects/RingArrayCallback.h +++ b/include/trCore/SceneObjects/RingArrayCallback.h @@ -1,78 +1,78 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include -#include - -/** - * @namespace trCore::SceneObjects - * - * @brief Namespace that contains controls for sample scene objects. - */ -namespace trCore::SceneObjects -{ - /** - * @class RingArrayCallback - * - * @brief A ring array callback that is used to rotate the ring array (RingArray.h) - * - * @author Maxim Serebrennik - */ - class TR_CORE_EXPORT RingArrayCallback : public osg::NodeCallback - { - public: - - /** - * @fn RingArrayCallback::RingArrayCallback(); - * - * @brief Default constructor. - */ - RingArrayCallback(); - - /** - * @fn RingArrayCallback::~RingArrayCallback(); - * - * @brief Destructor. - */ - ~RingArrayCallback(); - - /** - * @fn virtual void RingArrayCallback::operator()(osg::Node* nodePtr, osg::NodeVisitor* nvPtr) override; - * - * @brief Callback method called by the NodeVisitor when visiting a node. - * - * @param [in,out] nodePtr If non-null, the node. - * @param [in,out] nvPtr If non-null, the nv. - */ - virtual void operator()(osg::Node* nodePtr, osg::NodeVisitor* nvPtr) override; - - private: - - bool mFirstFrame = true; - trUtil::Timer mTimer; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include +#include + +/** + * @namespace trCore::SceneObjects + * + * @brief Namespace that contains controls for sample scene objects. + */ +namespace trCore::SceneObjects +{ + /** + * @class RingArrayCallback + * + * @brief A ring array callback that is used to rotate the ring array (RingArray.h) + * + * @author Maxim Serebrennik + */ + class TR_CORE_EXPORT RingArrayCallback : public osg::NodeCallback + { + public: + + /** + * @fn RingArrayCallback::RingArrayCallback(); + * + * @brief Default constructor. + */ + RingArrayCallback(); + + /** + * @fn RingArrayCallback::~RingArrayCallback(); + * + * @brief Destructor. + */ + ~RingArrayCallback(); + + /** + * @fn virtual void RingArrayCallback::operator()(osg::Node* nodePtr, osg::NodeVisitor* nvPtr) override; + * + * @brief Callback method called by the NodeVisitor when visiting a node. + * + * @param [in,out] nodePtr If non-null, the node. + * @param [in,out] nvPtr If non-null, the nv. + */ + virtual void operator()(osg::Node* nodePtr, osg::NodeVisitor* nvPtr) override; + + private: + + bool mFirstFrame = true; + trUtil::Timer mTimer; + }; } \ No newline at end of file diff --git a/include/trCore/SceneObjects/SkyBoxNode.h b/include/trCore/SceneObjects/SkyBoxNode.h index be287fe..5abedfa 100644 --- a/include/trCore/SceneObjects/SkyBoxNode.h +++ b/include/trCore/SceneObjects/SkyBoxNode.h @@ -17,33 +17,33 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include -#include -#include -#include - -namespace trCore::SceneObjects -{ - +*/ + +#pragma once + +#include + +#include + +#include +#include +#include +#include + +namespace trCore::SceneObjects +{ + /** - * @class SkyBoxNode + * @class SkyBoxNode * * @author Maxim Serebrennik * * @brief A sky box class that creates an object that is always positioned around the camera. * This class can load any geometry, box or dome... */ - class TR_CORE_EXPORT SkyBoxNode : public osg::Transform - { - public: + class TR_CORE_EXPORT SkyBoxNode : public osg::Transform + { + public: using BaseClass = osg::Transform; /// Adds an easy and swappable access to the base class @@ -52,7 +52,7 @@ namespace trCore::SceneObjects * * @brief Default constructor. */ - SkyBoxNode(); + SkyBoxNode(); /** * @fn virtual bool SkyBoxNode::computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; @@ -64,7 +64,7 @@ namespace trCore::SceneObjects * * @return True if it succeeds, false if it fails. */ - virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; + virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; /** * @fn virtual bool SkyBoxNode::computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; @@ -76,7 +76,7 @@ namespace trCore::SceneObjects * * @return True if it succeeds, false if it fails. */ - virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; + virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const override; /** * @fn bool SkyBoxNode::LoadFile(std::string fileName); @@ -87,9 +87,9 @@ namespace trCore::SceneObjects * * @return True if it succeeds, false if it fails. */ - bool LoadFile(std::string fileName); - - protected: + bool LoadFile(std::string fileName); + + protected: trBase::SmrtPtr mNode = nullptr; @@ -98,6 +98,6 @@ namespace trCore::SceneObjects * * @brief Destructor. */ - ~SkyBoxNode(); - }; + ~SkyBoxNode(); + }; } \ No newline at end of file diff --git a/include/trCore/SystemControls.h b/include/trCore/SystemControls.h index c8f64c9..c7ba993 100644 --- a/include/trCore/SystemControls.h +++ b/include/trCore/SystemControls.h @@ -1,73 +1,73 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include - -namespace trCore -{ - /** - * @class SystemControls - * - * @brief ENUM specifying various system control states. - */ - class TR_CORE_EXPORT SystemControls : public trUtil::EnumerationNumeric - { - DECLARE_ENUM(SystemControls) - public: - - /** @brief Pauses the system. */ - const static SystemControls PAUSE; - - /** @brief Unpauses the system. */ - const static SystemControls UNPAUSE; - - /** @brief Speeds up the system. */ - const static SystemControls SPEED_UP; - - /** @brief Slows down the system. */ - const static SystemControls SPEED_DOWN; - - /** - * @brief The set speed of the system. - * Needs to have a systemValue passed in with the MessageSystemControl for actual speed. - */ - const static SystemControls SET_TIME_SCALE; - - /** @brief Shuts down the system loop and exits the program. */ - const static SystemControls SHUT_DOWN; - - protected: - - /** - * @fn SystemControls::SystemControls(const std::string& name, unsigned int id); - * - * @brief Constructor. Protected to prevent creation of an instance. - * - * @param name The name. - * @param id The identifier. - */ - SystemControls(const std::string& name, unsigned int id); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include + +namespace trCore +{ + /** + * @class SystemControls + * + * @brief ENUM specifying various system control states. + */ + class TR_CORE_EXPORT SystemControls : public trUtil::EnumerationNumeric + { + DECLARE_ENUM(SystemControls) + public: + + /** @brief Pauses the system. */ + const static SystemControls PAUSE; + + /** @brief Unpauses the system. */ + const static SystemControls UNPAUSE; + + /** @brief Speeds up the system. */ + const static SystemControls SPEED_UP; + + /** @brief Slows down the system. */ + const static SystemControls SPEED_DOWN; + + /** + * @brief The set speed of the system. + * Needs to have a systemValue passed in with the MessageSystemControl for actual speed. + */ + const static SystemControls SET_TIME_SCALE; + + /** @brief Shuts down the system loop and exits the program. */ + const static SystemControls SHUT_DOWN; + + protected: + + /** + * @fn SystemControls::SystemControls(const std::string& name, unsigned int id); + * + * @brief Constructor. Protected to prevent creation of an instance. + * + * @param name The name. + * @param id The identifier. + */ + SystemControls(const std::string& name, unsigned int id); + }; } \ No newline at end of file diff --git a/include/trCore/SystemDirector.h b/include/trCore/SystemDirector.h index 12b2cdf..8adb538 100644 --- a/include/trCore/SystemDirector.h +++ b/include/trCore/SystemDirector.h @@ -1,238 +1,238 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include "Export.h" - -#include -#include -#include -#include -#include - -namespace trCore -{ - - /** - * @class SystemDirector - * - * @brief A System director. This Director does all the timing for TR. It controls the frame loop and keeps track of real and sim time. - */ - class TR_CORE_EXPORT SystemDirector : public trManager::DirectorBase - { - public: - using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static double MAX_TIME_SCALE; /// Hold the maximum time scale the system can use for positive and negaive time. - const static double MIN_TIME_SCALE; /// Hold the minimum time scale the system can use for positive and negaive time. - - /** - * @fn SystemDirector::SystemDirector(const std::string name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The instances name. - */ - SystemDirector(const std::string name = CLASS_TYPE); - - /** - * @fn virtual const std::string& SystemDirector::GetType() const override; - * - * @brief Gets the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - - /** - * @fn virtual void SystemDirector::OnMessage(const trManager::MessageBase& msg); - * - * @brief This function receives messages coming from the System Manager - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void SystemDirector::Run(); - * - * @brief Runs the systems game loop. - */ - virtual void Run(); - - /** - * @fn virtual void SystemDirector::RunOnce(); - * - * @brief Advanced the game loop by one frame. Used for testing. - */ - virtual void RunOnce(); - - /** - * @fn virtual bool SystemDirector::IsRunning(); - * - * @brief Query if this object is running. - * - * @return True if running, false if not. - */ - virtual bool IsRunning(); - - /** - * @fn virtual void SystemDirector::ShutDown(); - * - * @brief Shuts down this object and frees any resources it is using. - */ - virtual void ShutDown(); - - /** - * @fn trManager::TimingStructure SystemDirector::GetTimeStructure(); - * - * @brief Gets a copy of the internal time structure. - * - * @return The time structure. - */ - trManager::TimingStructure GetTimeStructure(); - - protected: - - /** - * @fn SystemDirector::~SystemDirector(); - * - * @brief Destructor. - */ - ~SystemDirector(); - - /** - * @fn virtual void SystemDirector::UpdateTiming(trManager::TimingStructure& timeStruct, double dt); - * - * @brief Updates the system timing incrementing it by dt. - * - * @param [in,out] timeStruct The time structure. - * @param dt The delta time between frames. - */ - virtual void UpdateTiming(trManager::TimingStructure& timeStruct, double dt); - - /** - * @fn virtual void SystemDirector::EventTraversal(const TimingStructure& timeStruct); - * - * @brief Event traversal event function. Sends out an EventTraversalEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void EventTraversal(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::PostEventTraversal(const TimingStructure& timeStruct); - * - * @brief Post event traversal event function. Sends out a PostEventTraversalEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void PostEventTraversal(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::PreFrame(const TimingStructure& timeStruct); - * - * @brief Pre frame event function. Sends out a PreFrameEvent Message. Sends out a Tick() - * Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void PreFrame(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::CameraSynch(const TimingStructure& timeStruct); - * - * @brief Camera synchronization event function. Sends out a CameraSynchEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void CameraSynch(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::FrameSynch(const TimingStructure& timeStruct); - * - * @brief Frame synchronization event function. Sends out a FrameSynchEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void FrameSynch(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::Frame(const TimingStructure& timeStruct); - * - * @brief Frame event function. Sends out FrameEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void Frame(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::PostFrame(const TimingStructure& timeStruct); - * - * @brief Post frame event function. Sends out PostFrameEvent Message. - * - * @param timeStruct The simulation time structure. - */ - virtual void PostFrame(const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual void SystemDirector::SetTimeScale(const double timeScale); - * - * @brief Sets the system time scale. - * - * @param timeScale The time scale. - */ - virtual void SetTimeScale(const double timeScale); - - /** - * @fn virtual void SystemDirector::IncrementTimeScale(); - * - * @brief Increment the system time scale. - */ - virtual void IncrementTimeScale(); - - /** - * @fn virtual void SystemDirector::DecrementTimeScale(); - * - * @brief Decrement the system time scale. - */ - virtual void DecrementTimeScale(); - - /** - * @fn virtual void SystemDirector::CheckForShutdown(); - * - * @brief Checks for a shutdown, and cleares the System Manager if in process. - */ - virtual void CheckForShutdown(); - - private: - - bool mIsRunning = false; - bool mIsShuttingDown = false; - bool mIsPaused = false; - trUtil::Timer mSystemTimer; - - trManager::TimingStructure mTimeStruct; - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include "Export.h" + +#include +#include +#include +#include +#include + +namespace trCore +{ + + /** + * @class SystemDirector + * + * @brief A System director. This Director does all the timing for TR. It controls the frame loop and keeps track of real and sim time. + */ + class TR_CORE_EXPORT SystemDirector : public trManager::DirectorBase + { + public: + using BaseClass = trManager::DirectorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static double MAX_TIME_SCALE; /// Hold the maximum time scale the system can use for positive and negaive time. + const static double MIN_TIME_SCALE; /// Hold the minimum time scale the system can use for positive and negaive time. + + /** + * @fn SystemDirector::SystemDirector(const std::string name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The instances name. + */ + SystemDirector(const std::string name = CLASS_TYPE); + + /** + * @fn virtual const std::string& SystemDirector::GetType() const override; + * + * @brief Gets the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + + /** + * @fn virtual void SystemDirector::OnMessage(const trManager::MessageBase& msg); + * + * @brief This function receives messages coming from the System Manager + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void SystemDirector::Run(); + * + * @brief Runs the systems game loop. + */ + virtual void Run(); + + /** + * @fn virtual void SystemDirector::RunOnce(); + * + * @brief Advanced the game loop by one frame. Used for testing. + */ + virtual void RunOnce(); + + /** + * @fn virtual bool SystemDirector::IsRunning(); + * + * @brief Query if this object is running. + * + * @return True if running, false if not. + */ + virtual bool IsRunning(); + + /** + * @fn virtual void SystemDirector::ShutDown(); + * + * @brief Shuts down this object and frees any resources it is using. + */ + virtual void ShutDown(); + + /** + * @fn trManager::TimingStructure SystemDirector::GetTimeStructure(); + * + * @brief Gets a copy of the internal time structure. + * + * @return The time structure. + */ + trManager::TimingStructure GetTimeStructure(); + + protected: + + /** + * @fn SystemDirector::~SystemDirector(); + * + * @brief Destructor. + */ + ~SystemDirector(); + + /** + * @fn virtual void SystemDirector::UpdateTiming(trManager::TimingStructure& timeStruct, double dt); + * + * @brief Updates the system timing incrementing it by dt. + * + * @param [in,out] timeStruct The time structure. + * @param dt The delta time between frames. + */ + virtual void UpdateTiming(trManager::TimingStructure& timeStruct, double dt); + + /** + * @fn virtual void SystemDirector::EventTraversal(const TimingStructure& timeStruct); + * + * @brief Event traversal event function. Sends out an EventTraversalEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void EventTraversal(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::PostEventTraversal(const TimingStructure& timeStruct); + * + * @brief Post event traversal event function. Sends out a PostEventTraversalEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void PostEventTraversal(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::PreFrame(const TimingStructure& timeStruct); + * + * @brief Pre frame event function. Sends out a PreFrameEvent Message. Sends out a Tick() + * Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void PreFrame(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::CameraSynch(const TimingStructure& timeStruct); + * + * @brief Camera synchronization event function. Sends out a CameraSynchEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void CameraSynch(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::FrameSynch(const TimingStructure& timeStruct); + * + * @brief Frame synchronization event function. Sends out a FrameSynchEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void FrameSynch(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::Frame(const TimingStructure& timeStruct); + * + * @brief Frame event function. Sends out FrameEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void Frame(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::PostFrame(const TimingStructure& timeStruct); + * + * @brief Post frame event function. Sends out PostFrameEvent Message. + * + * @param timeStruct The simulation time structure. + */ + virtual void PostFrame(const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual void SystemDirector::SetTimeScale(const double timeScale); + * + * @brief Sets the system time scale. + * + * @param timeScale The time scale. + */ + virtual void SetTimeScale(const double timeScale); + + /** + * @fn virtual void SystemDirector::IncrementTimeScale(); + * + * @brief Increment the system time scale. + */ + virtual void IncrementTimeScale(); + + /** + * @fn virtual void SystemDirector::DecrementTimeScale(); + * + * @brief Decrement the system time scale. + */ + virtual void DecrementTimeScale(); + + /** + * @fn virtual void SystemDirector::CheckForShutdown(); + * + * @brief Checks for a shutdown, and cleares the System Manager if in process. + */ + virtual void CheckForShutdown(); + + private: + + bool mIsRunning = false; + bool mIsShuttingDown = false; + bool mIsPaused = false; + trUtil::Timer mSystemTimer; + + trManager::TimingStructure mTimeStruct; + }; +} + diff --git a/include/trCore/SystemEvents.h b/include/trCore/SystemEvents.h index 0d8f0cb..312a0d5 100644 --- a/include/trCore/SystemEvents.h +++ b/include/trCore/SystemEvents.h @@ -1,84 +1,84 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include - -namespace trCore -{ - /** - * @class SystemEvents - * - * @brief Enum that specifies type of a system event - */ - class TR_CORE_EXPORT SystemEvents : public trUtil::EnumerationNumeric - { - DECLARE_ENUM(SystemEvents) - public: - - /** @brief The event traversal event. */ - const static SystemEvents EVENT_TRAVERSAL; - - /** @brief The post event traversal event. */ - const static SystemEvents POST_EVENT_TRAVERSAL; - - /** @brief The pre frame event. */ - const static SystemEvents PRE_FRAME; - - /** @brief The camera synchronization event. */ - const static SystemEvents CAMERA_SYNCH; - - /** @brief The frame synchronization event. */ - const static SystemEvents FRAME_SYNCH; - - /** @brief The frame event. */ - const static SystemEvents FRAME; - - /** @brief The post frame event. */ - const static SystemEvents POST_FRAME; - - /** @brief The paused event. */ - const static SystemEvents PAUSED; - - /** @brief The unpaused event. */ - const static SystemEvents UNPAUSED; - - /** @brief Indicates a change in the time scale. */ - const static SystemEvents TIME_SCALE_CHANGED; - - /** @brief Gets sent out when the system is shutting down. */ - const static SystemEvents SHUTTING_DOWN; - protected: - - /** - * @fn SystemEvents::SystemEvents(const std::string& name, unsigned int id); - * - * @brief Constructor, protected to prevent creation of an instance. - * - * @param name The name. - * @param id The identifier. - */ - SystemEvents(const std::string& name, unsigned int id); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include + +namespace trCore +{ + /** + * @class SystemEvents + * + * @brief Enum that specifies type of a system event + */ + class TR_CORE_EXPORT SystemEvents : public trUtil::EnumerationNumeric + { + DECLARE_ENUM(SystemEvents) + public: + + /** @brief The event traversal event. */ + const static SystemEvents EVENT_TRAVERSAL; + + /** @brief The post event traversal event. */ + const static SystemEvents POST_EVENT_TRAVERSAL; + + /** @brief The pre frame event. */ + const static SystemEvents PRE_FRAME; + + /** @brief The camera synchronization event. */ + const static SystemEvents CAMERA_SYNCH; + + /** @brief The frame synchronization event. */ + const static SystemEvents FRAME_SYNCH; + + /** @brief The frame event. */ + const static SystemEvents FRAME; + + /** @brief The post frame event. */ + const static SystemEvents POST_FRAME; + + /** @brief The paused event. */ + const static SystemEvents PAUSED; + + /** @brief The unpaused event. */ + const static SystemEvents UNPAUSED; + + /** @brief Indicates a change in the time scale. */ + const static SystemEvents TIME_SCALE_CHANGED; + + /** @brief Gets sent out when the system is shutting down. */ + const static SystemEvents SHUTTING_DOWN; + protected: + + /** + * @fn SystemEvents::SystemEvents(const std::string& name, unsigned int id); + * + * @brief Constructor, protected to prevent creation of an instance. + * + * @param name The name. + * @param id The identifier. + */ + SystemEvents(const std::string& name, unsigned int id); + }; } \ No newline at end of file diff --git a/include/trManager/ActorBase.h b/include/trManager/ActorBase.h index 2f08c61..574c3b9 100644 --- a/include/trManager/ActorBase.h +++ b/include/trManager/ActorBase.h @@ -1,257 +1,257 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include -#include - -namespace trManager -{ - /** - * @class ActorBase - * - * @brief A base class for all actors in the entity system. - */ - class TR_MANAGER_EXPORT ActorBase : public trManager::EntityBase - { - public: - - using BaseClass = trManager::EntityBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn ActorBase(const std::string& name = CLASS_TYPE); - * - * @brief ctor. - * - * @param name (Optional) The name. - */ - ActorBase(const std::string& name = CLASS_TYPE); - - /** - * Returns the class type - */ - virtual const std::string& GetType() const override = 0; - - /** - * @fn virtual void ActorBase::RegisterForMessage(const std::string& messageType, const std::string& invokableName); - * - * @brief Registers an actor for messages. - * - * @param [in,out] listeningActor The listening actor. - * - * @param messageType Type of the message. - * @param invokableName Name of the invokable. - */ - virtual void RegisterForMessage(const std::string& messageType, const std::string& invokableName); - - /** - * @fn virtual void ActorBase::UnRegisterFromMessage(const std::string& messageType); - * - * @brief Unregister an actor that is listening for a given message. - * - * @param [in,out] listeningActor The listening actor. - * - * @param messageType Type of the message. - */ - virtual void UnRegisterFromMessage(const std::string& messageType); - - /** - * @fn virtual void ActorBase::RegisterForMessagesAboutEntity(const trBase::UniqueId& aboutEntityId, const std::string& invokableName); - * - * @brief Registers for messages about a specific actor. - * - * @param aboutEntityId Identifier for the about entity. - * @param invokableName Name of the invokable. - */ - virtual void RegisterForMessagesAboutEntity(const trBase::UniqueId& aboutEntityId, const std::string& invokableName); - - /** - * @fn virtual void ActorBase::UnregisterFromMessagesAboutEntity(const trBase::UniqueId& aboutEntityId); - * - * @brief Unregisters from messages about a specific actor. - * - * @param aboutEntityId Identifier for the about entity. - */ - virtual void UnregisterFromMessagesAboutEntity(const trBase::UniqueId& aboutEntityId); - - /** - * @fn virtual void ActorBase::BuildInvokables(); - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables(); - - /** - * @fn virtual void ActorBase::OnTick(const trManager::MessageBase& msg) = 0; - * - * @brief Convenience function that will receive Tick Messages from the System Manager This - * does not happen automatically, each class needs to register for the message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg) = 0; - - /** - * @fn virtual void ActorBase::OnTickRemote(const trManager::MessageBase& msg); - * - * @brief Convenience function that will receive a Network Tick Message from the System Manager - * This does not happen automatically, each class needs to register for the message. - * - * @param msg The message. - */ - virtual void OnTickRemote(const trManager::MessageBase& msg); - - /** - * @fn virtual bool ActorBase::SendMessage(const trManager::MessageBase& message); - * - * @brief Send a message to an Actor, Actor Module, or a Director. - * - * @param message The message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendMessage(const trManager::MessageBase& message); - - /** - * @fn virtual bool ActorBase::SendNetworkMessage(const trManager::MessageBase& message); - * - * @brief Send a Network message to an Actor, Actor Module, or a Director. - * - * @param message The message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendNetworkMessage(const trManager::MessageBase& message); - - /** - * @fn virtual bool ActorBase::AddActorModule(trManager::EntityBase& actorModule); - * - * @brief Adds an Actor Module to the current Actor. NOTE: If this actor is never - * registered with the System Manager, you manually need to remove attached Actor Modules, or - * there could be a memory leak. Use RemoveAllActorModules() to remove all at once or - * RemoveActorModule(...) to remove them one at a time. - * - * @param [in,out] actorModule The actor module. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool AddActorModule(trManager::EntityBase& actorModule); - - /** - * @fn virtual bool ActorBase::RemoveActorModule(trManager::EntityBase& actorModule); - * - * @brief Removes the given Actor Module from the current Actor. - * - * @param [in,out] actorModule The actor module. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveActorModule(trManager::EntityBase& actorModule); - - /** - * @fn virtual bool ActorBase::RemoveActorModule(const trBase::UniqueId& id); - * - * @brief Removes the given Actor Module from the current Actor. - * - * @param id The identifier. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveActorModule(const trBase::UniqueId& id); - - /** - * @fn virtual bool ActorBase::RemoveAllActorModule(); - * - * @brief Removes all attached actor modules from this actor. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveAllActorModules(); - - /** - * @fn virtual trManager::EntityBase* ActorBase::FindActorModule(const trBase::UniqueId& id); - * - * @brief Finds and returns the Actor Module cast down to Entity. - * - * @param id The identifier. - * - * @return Null if it fails, else the found actor module. - */ - virtual trManager::EntityBase* FindActorModule(const trBase::UniqueId& id); - - /** - * @fn virtual void ActorBase::OnAddedToSysMan() override; - * - * @brief Called by the System Manager when EntityBase Registration is complete. - */ - virtual void OnAddedToSysMan() override; - - /** - * @fn virtual void ActorBase::OnRemovedFromSysMan() override; - * - * @brief Called by the System Manager after removing and Unregistering the EntityBase. - */ - virtual void OnRemovedFromSysMan() override; - - protected: - - /** - * @fn ActorBase::~ActorBase(); - * - * @brief dtor. - */ - ~ActorBase(); - - /** - * @fn virtual void ActorBase::ActorModuleTick(const trManager::MessageBase& tickMsg); - * - * @brief Sends the passed in message Tick Message to all attached Actor Modules. It is the - * developers responsibility to make sure you are passing a TickMessage and nothing else. - * - * @param tickMsg Message describing the tick. - */ - virtual void ActorModuleTick(const trManager::MessageBase& tickMsg); - - private: - - /** - * @using ActorModules = std::vector> - * - * @brief Defines an alias representing the actor modules. - */ - using ActorModules = std::vector>; - ActorModules mActorModules; //Actor Module Storage - - //Temp Storage for actor modules if this actor is disconnected and reconnected from and to System Manager. - ActorModules mActModReAttachStore; - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include +#include + +namespace trManager +{ + /** + * @class ActorBase + * + * @brief A base class for all actors in the entity system. + */ + class TR_MANAGER_EXPORT ActorBase : public trManager::EntityBase + { + public: + + using BaseClass = trManager::EntityBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn ActorBase(const std::string& name = CLASS_TYPE); + * + * @brief ctor. + * + * @param name (Optional) The name. + */ + ActorBase(const std::string& name = CLASS_TYPE); + + /** + * Returns the class type + */ + virtual const std::string& GetType() const override = 0; + + /** + * @fn virtual void ActorBase::RegisterForMessage(const std::string& messageType, const std::string& invokableName); + * + * @brief Registers an actor for messages. + * + * @param [in,out] listeningActor The listening actor. + * + * @param messageType Type of the message. + * @param invokableName Name of the invokable. + */ + virtual void RegisterForMessage(const std::string& messageType, const std::string& invokableName); + + /** + * @fn virtual void ActorBase::UnRegisterFromMessage(const std::string& messageType); + * + * @brief Unregister an actor that is listening for a given message. + * + * @param [in,out] listeningActor The listening actor. + * + * @param messageType Type of the message. + */ + virtual void UnRegisterFromMessage(const std::string& messageType); + + /** + * @fn virtual void ActorBase::RegisterForMessagesAboutEntity(const trBase::UniqueId& aboutEntityId, const std::string& invokableName); + * + * @brief Registers for messages about a specific actor. + * + * @param aboutEntityId Identifier for the about entity. + * @param invokableName Name of the invokable. + */ + virtual void RegisterForMessagesAboutEntity(const trBase::UniqueId& aboutEntityId, const std::string& invokableName); + + /** + * @fn virtual void ActorBase::UnregisterFromMessagesAboutEntity(const trBase::UniqueId& aboutEntityId); + * + * @brief Unregisters from messages about a specific actor. + * + * @param aboutEntityId Identifier for the about entity. + */ + virtual void UnregisterFromMessagesAboutEntity(const trBase::UniqueId& aboutEntityId); + + /** + * @fn virtual void ActorBase::BuildInvokables(); + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables(); + + /** + * @fn virtual void ActorBase::OnTick(const trManager::MessageBase& msg) = 0; + * + * @brief Convenience function that will receive Tick Messages from the System Manager This + * does not happen automatically, each class needs to register for the message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg) = 0; + + /** + * @fn virtual void ActorBase::OnTickRemote(const trManager::MessageBase& msg); + * + * @brief Convenience function that will receive a Network Tick Message from the System Manager + * This does not happen automatically, each class needs to register for the message. + * + * @param msg The message. + */ + virtual void OnTickRemote(const trManager::MessageBase& msg); + + /** + * @fn virtual bool ActorBase::SendMessage(const trManager::MessageBase& message); + * + * @brief Send a message to an Actor, Actor Module, or a Director. + * + * @param message The message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendMessage(const trManager::MessageBase& message); + + /** + * @fn virtual bool ActorBase::SendNetworkMessage(const trManager::MessageBase& message); + * + * @brief Send a Network message to an Actor, Actor Module, or a Director. + * + * @param message The message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendNetworkMessage(const trManager::MessageBase& message); + + /** + * @fn virtual bool ActorBase::AddActorModule(trManager::EntityBase& actorModule); + * + * @brief Adds an Actor Module to the current Actor. NOTE: If this actor is never + * registered with the System Manager, you manually need to remove attached Actor Modules, or + * there could be a memory leak. Use RemoveAllActorModules() to remove all at once or + * RemoveActorModule(...) to remove them one at a time. + * + * @param [in,out] actorModule The actor module. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool AddActorModule(trManager::EntityBase& actorModule); + + /** + * @fn virtual bool ActorBase::RemoveActorModule(trManager::EntityBase& actorModule); + * + * @brief Removes the given Actor Module from the current Actor. + * + * @param [in,out] actorModule The actor module. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveActorModule(trManager::EntityBase& actorModule); + + /** + * @fn virtual bool ActorBase::RemoveActorModule(const trBase::UniqueId& id); + * + * @brief Removes the given Actor Module from the current Actor. + * + * @param id The identifier. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveActorModule(const trBase::UniqueId& id); + + /** + * @fn virtual bool ActorBase::RemoveAllActorModule(); + * + * @brief Removes all attached actor modules from this actor. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveAllActorModules(); + + /** + * @fn virtual trManager::EntityBase* ActorBase::FindActorModule(const trBase::UniqueId& id); + * + * @brief Finds and returns the Actor Module cast down to Entity. + * + * @param id The identifier. + * + * @return Null if it fails, else the found actor module. + */ + virtual trManager::EntityBase* FindActorModule(const trBase::UniqueId& id); + + /** + * @fn virtual void ActorBase::OnAddedToSysMan() override; + * + * @brief Called by the System Manager when EntityBase Registration is complete. + */ + virtual void OnAddedToSysMan() override; + + /** + * @fn virtual void ActorBase::OnRemovedFromSysMan() override; + * + * @brief Called by the System Manager after removing and Unregistering the EntityBase. + */ + virtual void OnRemovedFromSysMan() override; + + protected: + + /** + * @fn ActorBase::~ActorBase(); + * + * @brief dtor. + */ + ~ActorBase(); + + /** + * @fn virtual void ActorBase::ActorModuleTick(const trManager::MessageBase& tickMsg); + * + * @brief Sends the passed in message Tick Message to all attached Actor Modules. It is the + * developers responsibility to make sure you are passing a TickMessage and nothing else. + * + * @param tickMsg Message describing the tick. + */ + virtual void ActorModuleTick(const trManager::MessageBase& tickMsg); + + private: + + /** + * @using ActorModules = std::vector> + * + * @brief Defines an alias representing the actor modules. + */ + using ActorModules = std::vector>; + ActorModules mActorModules; //Actor Module Storage + + //Temp Storage for actor modules if this actor is disconnected and reconnected from and to System Manager. + ActorModules mActModReAttachStore; + }; +} + diff --git a/include/trManager/ActorModuleBase.h b/include/trManager/ActorModuleBase.h index abb7083..2a66f7c 100644 --- a/include/trManager/ActorModuleBase.h +++ b/include/trManager/ActorModuleBase.h @@ -1,98 +1,98 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include - -namespace trManager -{ - /** - * @class ActorModuleBase - * - * @brief An actor module base class that will serve as a base for all actor modules. - * This class is used to extend the functionality of actors. While you can register - * this class for messages, that should be used sparingly, and all communication - * most likely should be done through the parent actor. - */ - class TR_MANAGER_EXPORT ActorModuleBase : public trManager::ActorBase - { - public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn ActorModuleBase(const std::string& name = CLASS_TYPE); - * - * @brief ctor. - * - * @param name (Optional) The name. - */ - ActorModuleBase(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& GetType() const override = 0; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override = 0; - - /** - * @fn virtual void OnTick(const trManager::MessageBase& msg); - * - * @brief Function that will receive Tick Messages from the System Manager. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void OnMessage(const trManager::MessageBase& msg); - * - * @brief Function that is used by the Systems Manager to deliver all messages to the Director. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void BuildInvokables() override; - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables() override; - - protected: - - /** - * @fn ~ActorModuleBase(); - * - * @brief dtor. - */ - ~ActorModuleBase(); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include + +namespace trManager +{ + /** + * @class ActorModuleBase + * + * @brief An actor module base class that will serve as a base for all actor modules. + * This class is used to extend the functionality of actors. While you can register + * this class for messages, that should be used sparingly, and all communication + * most likely should be done through the parent actor. + */ + class TR_MANAGER_EXPORT ActorModuleBase : public trManager::ActorBase + { + public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn ActorModuleBase(const std::string& name = CLASS_TYPE); + * + * @brief ctor. + * + * @param name (Optional) The name. + */ + ActorModuleBase(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& GetType() const override = 0; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override = 0; + + /** + * @fn virtual void OnTick(const trManager::MessageBase& msg); + * + * @brief Function that will receive Tick Messages from the System Manager. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void OnMessage(const trManager::MessageBase& msg); + * + * @brief Function that is used by the Systems Manager to deliver all messages to the Director. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void BuildInvokables() override; + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables() override; + + protected: + + /** + * @fn ~ActorModuleBase(); + * + * @brief dtor. + */ + ~ActorModuleBase(); + }; } \ No newline at end of file diff --git a/include/trManager/DirectorBase.h b/include/trManager/DirectorBase.h index a664cbd..473add6 100644 --- a/include/trManager/DirectorBase.h +++ b/include/trManager/DirectorBase.h @@ -1,132 +1,132 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -namespace trManager -{ - /** - * @class DirectorBase - * - * @brief A director base. Serves as the base class for all directors in the Entity System. A director should be used as - * a general manager for an overarching subsystem in the software. - */ - class TR_MANAGER_EXPORT DirectorBase : public trManager::ActorBase - { - public: - using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn DirectorBase(const std::string& name = CLASS_TYPE); - * - * @brief ctor. - * - * @param name (Optional) The name. - */ - DirectorBase(const std::string& name = CLASS_TYPE); - - /** - * @fn static bool DirectorBase::CompareComponentPriority(const trBase::SmrtPtr& first, const trBase::SmrtPtr& second); - * - * @brief Local function used to compare priorities of Directors. - * - * @param first The first. - * @param second The second. - * - * @return True if it succeeds, false if it fails. - */ - static bool CompareComponentPriority(const trBase::SmrtPtr& first, const trBase::SmrtPtr& second); - - /** - * @fn virtual const std::string& DirectorBase::GetType() const override = 0; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override = 0; - - /** - * @fn virtual void DirectorBase::OnTick(const trManager::MessageBase& msg); - * - * @brief Function that will receive Tick Messages from the System Manager. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase& msg); - - /** - * @fn virtual void DirectorBase::OnMessage(const trManager::MessageBase& msg); - * - * @brief Function that is used by the Systems Manager to deliver all messages to the Director. - * - * @param msg The message. - */ - virtual void OnMessage(const trManager::MessageBase& msg); - - /** - * @fn virtual void DirectorBase::BuildInvokables() override; - * - * @brief Builds the default invokables for this class. - */ - virtual void BuildInvokables() override; - - /** - * @fn virtual trManager::DirectorPriority& DirectorBase::GetDirectorPriority() const; - * - * @brief Returns the Directors message priority. - * - * @return The director priority. - */ - virtual trManager::DirectorPriority& GetDirectorPriority() const; - - /** - * @fn virtual void DirectorBase::SetDirectorPriority(trUtil::EnumerationPointer priority); - * - * @brief Sets the Directors message priority. This should only be used by the System Manager. - * - * @param priority The priority. - */ - virtual void SetDirectorPriority(trUtil::EnumerationPointer priority); - - protected: - - /** - * @fn DirectorBase::~DirectorBase(); - * - * @brief dtor. - */ - ~DirectorBase(); - - private: - - trUtil::EnumerationPointer mDirectorPriority; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +namespace trManager +{ + /** + * @class DirectorBase + * + * @brief A director base. Serves as the base class for all directors in the Entity System. A director should be used as + * a general manager for an overarching subsystem in the software. + */ + class TR_MANAGER_EXPORT DirectorBase : public trManager::ActorBase + { + public: + using BaseClass = trManager::ActorBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn DirectorBase(const std::string& name = CLASS_TYPE); + * + * @brief ctor. + * + * @param name (Optional) The name. + */ + DirectorBase(const std::string& name = CLASS_TYPE); + + /** + * @fn static bool DirectorBase::CompareComponentPriority(const trBase::SmrtPtr& first, const trBase::SmrtPtr& second); + * + * @brief Local function used to compare priorities of Directors. + * + * @param first The first. + * @param second The second. + * + * @return True if it succeeds, false if it fails. + */ + static bool CompareComponentPriority(const trBase::SmrtPtr& first, const trBase::SmrtPtr& second); + + /** + * @fn virtual const std::string& DirectorBase::GetType() const override = 0; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override = 0; + + /** + * @fn virtual void DirectorBase::OnTick(const trManager::MessageBase& msg); + * + * @brief Function that will receive Tick Messages from the System Manager. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase& msg); + + /** + * @fn virtual void DirectorBase::OnMessage(const trManager::MessageBase& msg); + * + * @brief Function that is used by the Systems Manager to deliver all messages to the Director. + * + * @param msg The message. + */ + virtual void OnMessage(const trManager::MessageBase& msg); + + /** + * @fn virtual void DirectorBase::BuildInvokables() override; + * + * @brief Builds the default invokables for this class. + */ + virtual void BuildInvokables() override; + + /** + * @fn virtual trManager::DirectorPriority& DirectorBase::GetDirectorPriority() const; + * + * @brief Returns the Directors message priority. + * + * @return The director priority. + */ + virtual trManager::DirectorPriority& GetDirectorPriority() const; + + /** + * @fn virtual void DirectorBase::SetDirectorPriority(trUtil::EnumerationPointer priority); + * + * @brief Sets the Directors message priority. This should only be used by the System Manager. + * + * @param priority The priority. + */ + virtual void SetDirectorPriority(trUtil::EnumerationPointer priority); + + protected: + + /** + * @fn DirectorBase::~DirectorBase(); + * + * @brief dtor. + */ + ~DirectorBase(); + + private: + + trUtil::EnumerationPointer mDirectorPriority; + }; } \ No newline at end of file diff --git a/include/trManager/DirectorPriority.h b/include/trManager/DirectorPriority.h index 3fa180b..2dbf9d6 100644 --- a/include/trManager/DirectorPriority.h +++ b/include/trManager/DirectorPriority.h @@ -1,74 +1,74 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include - -#include - -namespace trManager -{ - /** - * @class DirectorPriority - * - * @brief Sets the priority for a Director instance. The Directors with the higher priority - * will receive messages before the ones with the lower. - */ - class TR_MANAGER_EXPORT DirectorPriority : public trUtil::EnumerationNumeric - { - DECLARE_ENUM(DirectorPriority) - public: - - /** @brief Highest possible priority. Components with this priority will get messages first. */ - static DirectorPriority HIGHEST; - - /** - * @brief Higher priority. Components with this priority will get messages after HIGHEST, but - * before any others. - */ - static DirectorPriority HIGHER; - - /** - * @brief Normal priority. Components with this priority will get messages after any HIGHER - * priority, but before LOWER. - */ - static DirectorPriority NORMAL; - - /** - * @brief Lower priority. Components with this priority will get messages after any NORMAL or - * HIGHER priority, but before LOWEST. - */ - static DirectorPriority LOWER; - - /** @brief Lowest priority. Components with this priority will get messages after all others. */ - static DirectorPriority LOWEST; - - protected: - /** - * ctor - * Protected to prevent creation of an instance. - */ - DirectorPriority(const std::string& name, unsigned int id); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include + +#include + +namespace trManager +{ + /** + * @class DirectorPriority + * + * @brief Sets the priority for a Director instance. The Directors with the higher priority + * will receive messages before the ones with the lower. + */ + class TR_MANAGER_EXPORT DirectorPriority : public trUtil::EnumerationNumeric + { + DECLARE_ENUM(DirectorPriority) + public: + + /** @brief Highest possible priority. Components with this priority will get messages first. */ + static DirectorPriority HIGHEST; + + /** + * @brief Higher priority. Components with this priority will get messages after HIGHEST, but + * before any others. + */ + static DirectorPriority HIGHER; + + /** + * @brief Normal priority. Components with this priority will get messages after any HIGHER + * priority, but before LOWER. + */ + static DirectorPriority NORMAL; + + /** + * @brief Lower priority. Components with this priority will get messages after any NORMAL or + * HIGHER priority, but before LOWEST. + */ + static DirectorPriority LOWER; + + /** @brief Lowest priority. Components with this priority will get messages after all others. */ + static DirectorPriority LOWEST; + + protected: + /** + * ctor + * Protected to prevent creation of an instance. + */ + DirectorPriority(const std::string& name, unsigned int id); + }; } \ No newline at end of file diff --git a/include/trManager/EntityBase.h b/include/trManager/EntityBase.h index ee92b92..50cc147 100644 --- a/include/trManager/EntityBase.h +++ b/include/trManager/EntityBase.h @@ -1,364 +1,364 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace trManager -{ - class SystemManager; - - /** - * @class EntityBase - * - * @brief This serves as the base class for the Entity class and removes - * a circular dependency between Entity and System Manager. - */ - class TR_MANAGER_EXPORT EntityBase : public trBase::Base - { - public: - - using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - const static trUtil::RefStr ON_MESSAGE_INVOKABLE; /// Invokable for general messages - const static trUtil::RefStr ON_TICK_INVOKABLE; /// Invokable for Tick messages - const static trUtil::RefStr ON_TICK_REMOTE_INVOKABLE; /// Invokable for Tick Remote messages - - /** - * @fn EntityBase(const std::string& name = CLASS_TYPE); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - EntityBase(const std::string& name = CLASS_TYPE); - - /** - * @fn virtual const std::string& EntityBase::GetType() const override = 0; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override = 0; - - /** - * @fn const EntityType& EntityBase::GetEntityType(); - * - * @brief Returns the Entity Type, which is usually a Director, Actor, or an Actor module. - * - * @return The entity type. - */ - const EntityType& GetEntityType(); - - /** - * @fn virtual void EntityBase::SetSystemManager(trManager::SystemManager *sysMan); - * - * @brief This method is used by the System Manager to pass the Entity an instance if itself - * when it is registered. The user should not use this function. - * - * @param [in,out] sysMan If non-null, manager for system. - */ - virtual void SetSystemManager(trManager::SystemManager *sysMan); - - /** - * @fn virtual void EntityBase::OnAddedToSysMan() - * - * @brief Called by the System Manager when EntityBase Registration is complete. - */ - virtual void OnAddedToSysMan() {/*Meant for user to overwrite*/ }; - - /** - * @fn virtual void EntityBase::OnRemovedFromSysMan() - * - * @brief Called by the System Manager after removing and Unregistering the EntityBase. - */ - virtual void OnRemovedFromSysMan() {/*Meant for user to overwrite*/ }; - - /** - * @fn virtual const bool& EntityBase::IsRegistered(); - * - * @brief Returns True if the Instance is registered with a System Manager. - * - * @return A reference to a const bool. - */ - virtual const bool& IsRegistered(); - - /** - * @fn virtual void EntityBase::SetRegistration(bool isRegistered); - * - * @brief Is set to True by the System Manager when the class instance is registered with it. - * This function should not be called by the user. - * - * @param isRegistered True if this object is registered. - */ - virtual void SetRegistration(bool isRegistered); - - /** - * @fn virtual void EntityBase::AddInvokable(trManager::Invokable &newInvokable); - * - * @brief Adds an invokable that can receive a message. - * - * @param [in,out] newInvokable The new invokable. - */ - virtual void AddInvokable(trManager::Invokable &newInvokable); - - /** - * @fn virtual void EntityBase::RemoveInvokable(trManager::Invokable *invokable); - * - * @brief Removes the invokable that is passed in. - * - * @param [in,out] invokable If non-null, the invokable. - */ - virtual void RemoveInvokable(trManager::Invokable *invokable); - - /** - * @fn virtual void EntityBase::RemoveInvokable(const std::string &invokableName); - * - * @brief Removes the invokable described by invokableName. - * - * @param invokableName Name of the invokable. - */ - virtual void RemoveInvokable(const std::string &invokableName); - - /** - * @fn trManager::Invokable* EntityBase::GetInvokable(const std::string &name); - * - * @brief Gets a registered invokable. - * - * @param name The name. - * - * @return Null if it fails, else the invokable. - */ - trManager::Invokable* GetInvokable(const std::string &name); - - /** - * @fn void EntityBase::GetInvokables(std::vector &toFill); - * - * @brief Gets the list of invokables. - * - * @param [in,out] toFill [in,out] If non-null, to fill. - */ - void GetInvokables(std::vector &toFill); - - /** - * @fn void EntityBase::GetInvokables(std::vector &toFill) const; - * - * @brief Gets the invokables. - * - * @param toFill to fill. - */ - void GetInvokables(std::vector &toFill) const; - - /** - * @fn virtual void EntityBase::OnTick(const trManager::MessageBase &msg) = 0; - * - * @brief Convenience function that will receive Tick Messages from the System Manager This - * does not happen automatically, each class needs to register for the message. - * - * @param msg The message. - */ - virtual void OnTick(const trManager::MessageBase &msg) = 0; - - /** - * @fn virtual void EntityBase::OnTickRemote(const trManager::MessageBase &msg) = 0; - * - * @brief Convenience function that will receive a Network Tick Message from the System Manager - * This does not happen automatically, each class needs to register for the message. - * - * @param msg The message. - */ - virtual void OnTickRemote(const trManager::MessageBase &msg) = 0; - - /** - * @fn virtual bool EntityBase::AddChild(trManager::EntityBase &child); - * - * @brief Adds a child to this Entity. - * - * @param [in,out] child The child. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool AddChild(trManager::EntityBase &child); - - /** - * @fn virtual bool EntityBase::RemoveChild(trManager::EntityBase &child); - * - * @brief Removes the child from this Entity. - * - * @param [in,out] child The child. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveChild(trManager::EntityBase &child); - - /** - * @fn virtual bool EntityBase::RemoveAllChildren(); - * - * @brief Removes all of the entities children . - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveAllChildren(); - - /** - * @fn virtual std::vector>* EntityBase::GetChildren(); - * - * @brief Gets the children of this Entity. - * - * @return Null if it fails, else the children. - */ - virtual std::vector>* GetChildren(); - - /** - * @fn virtual const std::vector>* EntityBase::GetChildren() const; - * - * @brief Gets the children of this Entity. - * - * @return Null if it fails, else the children. - */ - virtual const std::vector>* GetChildren() const; - - /** - * @fn virtual const trManager::EntityBase* EntityBase::FindChild(const trBase::UniqueId& childId); - * - * @brief Finds a child of this Entity in the children list. - * - * @param childId Identifier for the child. - * - * @return Null if it fails, else the found child. - */ - virtual const trManager::EntityBase* FindChild(const trBase::UniqueId& childId); - - /** - * @fn virtual int EntityBase::GetNumOfChildren(); - * - * @brief Gets the children of this Entity has. - * - * @return The number of children. - */ - virtual int GetNumOfChildren(); - - /** - * @fn virtual void EntityBase::SetParent(trManager::EntityBase &parent); - * - * @brief Sets the hierarchal parent of this Entity. This is for system use only. - * Use AddChild() if you want to attach entities. - * - * @param [in,out] parent The parent. - */ - virtual void SetParent(trManager::EntityBase &parent); - - /** - * @fn virtual void EntityBase::ForgetParent() trManager::EntityBase* GetParent(); - * - * @brief Forgets the hierarchal parent of this Entiry. This is for system use only. - * Used Emancipate() if you want to disconnect your entity. - */ - virtual void ForgetParent(); - - /** - * @fn trManager::EntityBase* EntityBase::GetParent(); - * - * @brief Gets the parent of this hierarchal Entity. - * - * @return Null if it fails, else the parent. - */ - trManager::EntityBase* GetParent(); - - /** - * @fn const trManager::EntityBase* EntityBase::GetParent() const; - * - * @brief Gets the parent of this hierarchal Entity. - * - * @return Null if it fails, else the parent. - */ - const trManager::EntityBase* GetParent() const; - - /** - * @fn virtual void EntityBase::OnParentRemoved(trManager::EntityBase &parent); - * - * @brief Convenience function that will be called by the system when the Entities parent is - * removed. Overwrite to capture the event. - * - * @param [in,out] parent The parent. - */ - virtual void OnParentRemoved(trManager::EntityBase &parent); - - /** - * @fn virtual void EntityBase::OnParentSet(trManager::EntityBase &parent) virtual void Emancipate(); - * - * @brief Convenience function that will be called by the system when a new parent is added or - * set to the Entity. Overwrite to capture the event. - * - * @param [in,out] parent The parent. - */ - virtual void OnParentSet(trManager::EntityBase &parent); - - - /** - * @fn virtual void EntityBase::Emancipate(); - * - * @brief Removes the hierarchal parent of this Entity, and removes this Entity from the parent. - * - * @param [in,out] parent The parent. - */ - virtual void Emancipate(); - - /** - * @fn virtual bool EntityBase::RemoveFromHierarchy(); - * - * @brief Removes from this entity from the hierarchy tree attaching its children to its parent. - * Does nothing if this entity does not have a parent. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RemoveFromHierarchy(); - - protected: - - trBase::ObsrvrPtr mSysMan; - trUtil::EnumerationPointer mEntityType; - trUtil::HashMap> mInvokables; // - - ~EntityBase(); - - private: - - bool mIsRegistered = false; - std::vector> mChildren; - trBase::SmrtPtr mParent; - - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace trManager +{ + class SystemManager; + + /** + * @class EntityBase + * + * @brief This serves as the base class for the Entity class and removes + * a circular dependency between Entity and System Manager. + */ + class TR_MANAGER_EXPORT EntityBase : public trBase::Base + { + public: + + using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + const static trUtil::RefStr ON_MESSAGE_INVOKABLE; /// Invokable for general messages + const static trUtil::RefStr ON_TICK_INVOKABLE; /// Invokable for Tick messages + const static trUtil::RefStr ON_TICK_REMOTE_INVOKABLE; /// Invokable for Tick Remote messages + + /** + * @fn EntityBase(const std::string& name = CLASS_TYPE); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + EntityBase(const std::string& name = CLASS_TYPE); + + /** + * @fn virtual const std::string& EntityBase::GetType() const override = 0; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override = 0; + + /** + * @fn const EntityType& EntityBase::GetEntityType(); + * + * @brief Returns the Entity Type, which is usually a Director, Actor, or an Actor module. + * + * @return The entity type. + */ + const EntityType& GetEntityType(); + + /** + * @fn virtual void EntityBase::SetSystemManager(trManager::SystemManager *sysMan); + * + * @brief This method is used by the System Manager to pass the Entity an instance if itself + * when it is registered. The user should not use this function. + * + * @param [in,out] sysMan If non-null, manager for system. + */ + virtual void SetSystemManager(trManager::SystemManager *sysMan); + + /** + * @fn virtual void EntityBase::OnAddedToSysMan() + * + * @brief Called by the System Manager when EntityBase Registration is complete. + */ + virtual void OnAddedToSysMan() {/*Meant for user to overwrite*/ }; + + /** + * @fn virtual void EntityBase::OnRemovedFromSysMan() + * + * @brief Called by the System Manager after removing and Unregistering the EntityBase. + */ + virtual void OnRemovedFromSysMan() {/*Meant for user to overwrite*/ }; + + /** + * @fn virtual const bool& EntityBase::IsRegistered(); + * + * @brief Returns True if the Instance is registered with a System Manager. + * + * @return A reference to a const bool. + */ + virtual const bool& IsRegistered(); + + /** + * @fn virtual void EntityBase::SetRegistration(bool isRegistered); + * + * @brief Is set to True by the System Manager when the class instance is registered with it. + * This function should not be called by the user. + * + * @param isRegistered True if this object is registered. + */ + virtual void SetRegistration(bool isRegistered); + + /** + * @fn virtual void EntityBase::AddInvokable(trManager::Invokable &newInvokable); + * + * @brief Adds an invokable that can receive a message. + * + * @param [in,out] newInvokable The new invokable. + */ + virtual void AddInvokable(trManager::Invokable &newInvokable); + + /** + * @fn virtual void EntityBase::RemoveInvokable(trManager::Invokable *invokable); + * + * @brief Removes the invokable that is passed in. + * + * @param [in,out] invokable If non-null, the invokable. + */ + virtual void RemoveInvokable(trManager::Invokable *invokable); + + /** + * @fn virtual void EntityBase::RemoveInvokable(const std::string &invokableName); + * + * @brief Removes the invokable described by invokableName. + * + * @param invokableName Name of the invokable. + */ + virtual void RemoveInvokable(const std::string &invokableName); + + /** + * @fn trManager::Invokable* EntityBase::GetInvokable(const std::string &name); + * + * @brief Gets a registered invokable. + * + * @param name The name. + * + * @return Null if it fails, else the invokable. + */ + trManager::Invokable* GetInvokable(const std::string &name); + + /** + * @fn void EntityBase::GetInvokables(std::vector &toFill); + * + * @brief Gets the list of invokables. + * + * @param [in,out] toFill [in,out] If non-null, to fill. + */ + void GetInvokables(std::vector &toFill); + + /** + * @fn void EntityBase::GetInvokables(std::vector &toFill) const; + * + * @brief Gets the invokables. + * + * @param toFill to fill. + */ + void GetInvokables(std::vector &toFill) const; + + /** + * @fn virtual void EntityBase::OnTick(const trManager::MessageBase &msg) = 0; + * + * @brief Convenience function that will receive Tick Messages from the System Manager This + * does not happen automatically, each class needs to register for the message. + * + * @param msg The message. + */ + virtual void OnTick(const trManager::MessageBase &msg) = 0; + + /** + * @fn virtual void EntityBase::OnTickRemote(const trManager::MessageBase &msg) = 0; + * + * @brief Convenience function that will receive a Network Tick Message from the System Manager + * This does not happen automatically, each class needs to register for the message. + * + * @param msg The message. + */ + virtual void OnTickRemote(const trManager::MessageBase &msg) = 0; + + /** + * @fn virtual bool EntityBase::AddChild(trManager::EntityBase &child); + * + * @brief Adds a child to this Entity. + * + * @param [in,out] child The child. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool AddChild(trManager::EntityBase &child); + + /** + * @fn virtual bool EntityBase::RemoveChild(trManager::EntityBase &child); + * + * @brief Removes the child from this Entity. + * + * @param [in,out] child The child. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveChild(trManager::EntityBase &child); + + /** + * @fn virtual bool EntityBase::RemoveAllChildren(); + * + * @brief Removes all of the entities children . + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveAllChildren(); + + /** + * @fn virtual std::vector>* EntityBase::GetChildren(); + * + * @brief Gets the children of this Entity. + * + * @return Null if it fails, else the children. + */ + virtual std::vector>* GetChildren(); + + /** + * @fn virtual const std::vector>* EntityBase::GetChildren() const; + * + * @brief Gets the children of this Entity. + * + * @return Null if it fails, else the children. + */ + virtual const std::vector>* GetChildren() const; + + /** + * @fn virtual const trManager::EntityBase* EntityBase::FindChild(const trBase::UniqueId& childId); + * + * @brief Finds a child of this Entity in the children list. + * + * @param childId Identifier for the child. + * + * @return Null if it fails, else the found child. + */ + virtual const trManager::EntityBase* FindChild(const trBase::UniqueId& childId); + + /** + * @fn virtual int EntityBase::GetNumOfChildren(); + * + * @brief Gets the children of this Entity has. + * + * @return The number of children. + */ + virtual int GetNumOfChildren(); + + /** + * @fn virtual void EntityBase::SetParent(trManager::EntityBase &parent); + * + * @brief Sets the hierarchal parent of this Entity. This is for system use only. + * Use AddChild() if you want to attach entities. + * + * @param [in,out] parent The parent. + */ + virtual void SetParent(trManager::EntityBase &parent); + + /** + * @fn virtual void EntityBase::ForgetParent() trManager::EntityBase* GetParent(); + * + * @brief Forgets the hierarchal parent of this Entiry. This is for system use only. + * Used Emancipate() if you want to disconnect your entity. + */ + virtual void ForgetParent(); + + /** + * @fn trManager::EntityBase* EntityBase::GetParent(); + * + * @brief Gets the parent of this hierarchal Entity. + * + * @return Null if it fails, else the parent. + */ + trManager::EntityBase* GetParent(); + + /** + * @fn const trManager::EntityBase* EntityBase::GetParent() const; + * + * @brief Gets the parent of this hierarchal Entity. + * + * @return Null if it fails, else the parent. + */ + const trManager::EntityBase* GetParent() const; + + /** + * @fn virtual void EntityBase::OnParentRemoved(trManager::EntityBase &parent); + * + * @brief Convenience function that will be called by the system when the Entities parent is + * removed. Overwrite to capture the event. + * + * @param [in,out] parent The parent. + */ + virtual void OnParentRemoved(trManager::EntityBase &parent); + + /** + * @fn virtual void EntityBase::OnParentSet(trManager::EntityBase &parent) virtual void Emancipate(); + * + * @brief Convenience function that will be called by the system when a new parent is added or + * set to the Entity. Overwrite to capture the event. + * + * @param [in,out] parent The parent. + */ + virtual void OnParentSet(trManager::EntityBase &parent); + + + /** + * @fn virtual void EntityBase::Emancipate(); + * + * @brief Removes the hierarchal parent of this Entity, and removes this Entity from the parent. + * + * @param [in,out] parent The parent. + */ + virtual void Emancipate(); + + /** + * @fn virtual bool EntityBase::RemoveFromHierarchy(); + * + * @brief Removes from this entity from the hierarchy tree attaching its children to its parent. + * Does nothing if this entity does not have a parent. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RemoveFromHierarchy(); + + protected: + + trBase::ObsrvrPtr mSysMan; + trUtil::EnumerationPointer mEntityType; + trUtil::HashMap> mInvokables; // + + ~EntityBase(); + + private: + + bool mIsRegistered = false; + std::vector> mChildren; + trBase::SmrtPtr mParent; + + }; } \ No newline at end of file diff --git a/include/trManager/EntityType.h b/include/trManager/EntityType.h index 69cb74f..670ca92 100644 --- a/include/trManager/EntityType.h +++ b/include/trManager/EntityType.h @@ -1,58 +1,58 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include - -namespace trManager -{ - /** - * @class EntityType - * - * @brief A class that specifies what kind of entity an object is in the Entity System. - */ - class TR_MANAGER_EXPORT EntityType : public trUtil::EnumerationString - { - DECLARE_ENUM(EntityType) - - public: - static const EntityType ACTOR; - static const EntityType DIRECTOR; - static const EntityType ACTOR_MODULE; - static const EntityType INVALID; - - protected: - /*virtual*/ ~EntityType() {} - - private: - - EntityType(const std::string& name) : trUtil::EnumerationString(name) - { - AddInstance(this); - } - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include + +namespace trManager +{ + /** + * @class EntityType + * + * @brief A class that specifies what kind of entity an object is in the Entity System. + */ + class TR_MANAGER_EXPORT EntityType : public trUtil::EnumerationString + { + DECLARE_ENUM(EntityType) + + public: + static const EntityType ACTOR; + static const EntityType DIRECTOR; + static const EntityType ACTOR_MODULE; + static const EntityType INVALID; + + protected: + /*virtual*/ ~EntityType() {} + + private: + + EntityType(const std::string& name) : trUtil::EnumerationString(name) + { + AddInstance(this); + } + }; +} + diff --git a/include/trManager/Export.h b/include/trManager/Export.h index d35d531..4be9fb6 100644 --- a/include/trManager/Export.h +++ b/include/trManager/Export.h @@ -1,36 +1,36 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) -# ifdef TR_MANAGER_LIBRARY -# define TR_MANAGER_EXPORT __declspec(dllexport) -# else -# define TR_MANAGER_EXPORT __declspec(dllimport) -# endif -#else -# ifdef TR_MANAGER_LIBRARY -# define TR_MANAGER_EXPORT __attribute__ ((visibility("default"))) -# else -# define TR_MANAGER_EXPORT -# endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef TR_MANAGER_LIBRARY +# define TR_MANAGER_EXPORT __declspec(dllexport) +# else +# define TR_MANAGER_EXPORT __declspec(dllimport) +# endif +#else +# ifdef TR_MANAGER_LIBRARY +# define TR_MANAGER_EXPORT __attribute__ ((visibility("default"))) +# else +# define TR_MANAGER_EXPORT +# endif #endif \ No newline at end of file diff --git a/include/trManager/Invokable.h b/include/trManager/Invokable.h index 9255c09..6d1f9e8 100644 --- a/include/trManager/Invokable.h +++ b/include/trManager/Invokable.h @@ -1,130 +1,136 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author David Guthrie -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include - -namespace trManager -{ - class TR_MANAGER_EXPORT InvokableFunctorCallerBase : public trBase::SmrtClass - { - public: - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn virtual const std::string& InvokableFunctorCallerBase::GetType() const override - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE; } - - virtual void Call(const trManager::MessageBase& message) = 0; - }; - - template - class TR_MANAGER_EXPORT InvokableFunctorCaller : public InvokableFunctorCallerBase - { - public: - using InvokableFunc = trUtil::Functor; - - InvokableFunctorCaller(InvokableFunc func) - : mFunctor(func) - { - } - - virtual void Call(const trManager::MessageBase& message) - { - mFunctor(static_cast(message)); - } - private: - InvokableFunc mFunctor; - }; - - /** - * @class Invokable - * - * @brief An Invokable is a queriable method interface that can be added to a - * trManager::ActorBase - * Invoking the invokable requires a trManager::MessageBase as a parameter. The actual - * code is executed by calling a Functor that takes 1 parameter, the message, and - * returns nothing. The method must take a const Method reference. - * - * @sa trManager::MessageBase - */ - class TR_MANAGER_EXPORT Invokable : public trBase::SmrtClass - { - public: - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn virtual const std::string& Invokable::GetType() const override - * - * @brief Gets the type. - * - * @return The type. - */ - virtual const std::string& GetType() const override { return CLASS_TYPE;} - - using InvokableFunc = trUtil::Functor; - - template - Invokable(const std::string& name, trUtil::Functor toInvoke) - : mName(name) - , mCaller(new InvokableFunctorCaller(toInvoke)) - { - } - - /** - * @return the name of this invokable. - */ - const std::string& GetName() const { return mName; } - - /** - * Invoke this. - * @param message the message to invoke. - */ - void Invoke(const trManager::MessageBase& message); - protected: - ///referenced classes should always have protected destructor - virtual ~Invokable(); - private: - std::string mName; - - trBase::SmrtPtr mCaller; - - Invokable(const Invokable&) {} - Invokable& operator=(const Invokable&) { return *this; } - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author David Guthrie +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include + +namespace trManager +{ + class TR_MANAGER_EXPORT InvokableFunctorCallerBase : public trBase::SmrtClass + { + public: + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn virtual const std::string& InvokableFunctorCallerBase::GetType() const override + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE; } + + virtual void Call(const trManager::MessageBase& message) = 0; + }; + + template + class TR_MANAGER_EXPORT InvokableFunctorCaller : public InvokableFunctorCallerBase + { + public: + using InvokableFunc = trUtil::Functor; + + InvokableFunctorCaller(InvokableFunc func) + : mFunctor(func) + { + } + + virtual void Call(const trManager::MessageBase& message) + { + mFunctor(static_cast(message)); + } + private: + InvokableFunc mFunctor; + }; + + /** + * @class Invokable + * + * @brief An Invokable is a queriable method interface that can be added to a + * trManager::ActorBase + * Invoking the invokable requires a trManager::MessageBase as a parameter. The actual + * code is executed by calling a Functor that takes 1 parameter, the message, and + * returns nothing. The method must take a const Method reference. + * + * @sa trManager::MessageBase + */ + class TR_MANAGER_EXPORT Invokable : public trBase::SmrtClass + { + public: + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn virtual const std::string& Invokable::GetType() const override + * + * @brief Gets the type. + * + * @return The type. + */ + virtual const std::string& GetType() const override { return CLASS_TYPE;} + + using InvokableFunc = trUtil::Functor; + + template + Invokable(const std::string& name, trUtil::Functor toInvoke) + : mName(name) + , mCaller(new InvokableFunctorCaller(toInvoke)) + { + } + + /** + * @fn Invokable(const Invokable&) + * + * @brief Deleted copy constructor. + */ + Invokable(const Invokable&) = delete; + + /** + * @return the name of this invokable. + */ + const std::string& GetName() const { return mName; } + + /** + * Invoke this. + * @param message the message to invoke. + */ + void Invoke(const trManager::MessageBase& message); + protected: + ///referenced classes should always have protected destructor + virtual ~Invokable(); + private: + std::string mName; + + trBase::SmrtPtr mCaller; + + Invokable& operator=(const Invokable&) { return *this; } + }; +} + diff --git a/include/trManager/MessageBase.h b/include/trManager/MessageBase.h index a55f5c7..7ea8eed 100644 --- a/include/trManager/MessageBase.h +++ b/include/trManager/MessageBase.h @@ -1,137 +1,137 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include -#include -#include - -#include - -namespace trManager -{ - /** - * This is the base class for all the messages in TR. It is immutable, - * and all messages derived from it should keep that tradition. - */ - class TR_MANAGER_EXPORT MessageBase : public trBase::SmrtClass - { - public: - - using BaseClass = trBase::SmrtClass; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageBase::MessageBase(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID = NULL, const bool isDirect = false, const std::string &messageFilter = trUtil::StringUtils::STR_BLANK); - * - * @brief ctor. - * - * @param fromActorID Id of the actor this message is being sent from. - * @param aboutActorID (Optional) Id of the actor this message is being sent to, or is about. - * @param isDirect (Optional) If TRUE, this message will skip all the Directors. - * @param messageFilter (Optional) A custom filter for developer use. - */ - MessageBase(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID = NULL, const bool isDirect = false, const std::string &messageFilter = trUtil::StringUtils::STR_BLANK); - - bool operator==(const MessageBase& msg) const; - bool operator!=(const MessageBase& msg) const { return !(*this == msg); } - - /** - * @fn virtual const std::string& MessageBase::GetMessageType() const = 0; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const = 0; - - /** - * @fn virtual const trBase::UniqueId* MessageBase::GetFromActorID() const; - * - * @brief Returns the ID of the actor the message was sent from. The ID should never be empty. - * - * @return Null if it fails, else the data that was read from the actor identifier. - */ - virtual const trBase::UniqueId* GetFromActorID() const; - - /** - * @fn virtual const trBase::UniqueId* MessageBase::GetAboutActorID() const; - * - * @brief Returns the ID of the actor this message is about, or sent to. This ID can be empty - * if the message is not directed toward a specific Actor. - * - * @return Null if it fails, else the about actor identifier. - */ - virtual const trBase::UniqueId* GetAboutActorID() const; - - /** - * @fn virtual const bool& MessageBase::GetIsDirect() const; - * - * @brief Returns True if this message is a direct message and skips all Directors. - * - * @return The is direct. - */ - virtual const bool& GetIsDirect() const; - - /** - * @fn virtual const std::string& MessageBase::GetMessageFilter(); - * - * @brief Returns the custom Filter string. - * - * @return The message filter. - */ - virtual const std::string& GetMessageFilter(); - - protected: - - /** - * @fn MessageBase::~MessageBase(); - * - * @brief dtor. - */ - ~MessageBase(); - - /** - * @fn virtual const std::string& MessageBase::GetType() const override; - * - * @brief Returns the class type Made protected to hide it. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - - private: - - trBase::ObsrvrPtr mFromActorID, mAboutActorID; - bool mIsDirect; - const std::string *mMessageFilter; - trBase::UniqueId mId; - }; -} - - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include +#include +#include + +#include + +namespace trManager +{ + /** + * This is the base class for all the messages in TR. It is immutable, + * and all messages derived from it should keep that tradition. + */ + class TR_MANAGER_EXPORT MessageBase : public trBase::SmrtClass + { + public: + + using BaseClass = trBase::SmrtClass; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageBase::MessageBase(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID = NULL, const bool isDirect = false, const std::string &messageFilter = trUtil::StringUtils::STR_BLANK); + * + * @brief ctor. + * + * @param fromActorID Id of the actor this message is being sent from. + * @param aboutActorID (Optional) Id of the actor this message is being sent to, or is about. + * @param isDirect (Optional) If TRUE, this message will skip all the Directors. + * @param messageFilter (Optional) A custom filter for developer use. + */ + MessageBase(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID = NULL, const bool isDirect = false, const std::string &messageFilter = trUtil::StringUtils::STR_BLANK); + + bool operator==(const MessageBase& msg) const; + bool operator!=(const MessageBase& msg) const { return !(*this == msg); } + + /** + * @fn virtual const std::string& MessageBase::GetMessageType() const = 0; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const = 0; + + /** + * @fn virtual const trBase::UniqueId* MessageBase::GetFromActorID() const; + * + * @brief Returns the ID of the actor the message was sent from. The ID should never be empty. + * + * @return Null if it fails, else the data that was read from the actor identifier. + */ + virtual const trBase::UniqueId* GetFromActorID() const; + + /** + * @fn virtual const trBase::UniqueId* MessageBase::GetAboutActorID() const; + * + * @brief Returns the ID of the actor this message is about, or sent to. This ID can be empty + * if the message is not directed toward a specific Actor. + * + * @return Null if it fails, else the about actor identifier. + */ + virtual const trBase::UniqueId* GetAboutActorID() const; + + /** + * @fn virtual const bool& MessageBase::GetIsDirect() const; + * + * @brief Returns True if this message is a direct message and skips all Directors. + * + * @return The is direct. + */ + virtual const bool& GetIsDirect() const; + + /** + * @fn virtual const std::string& MessageBase::GetMessageFilter(); + * + * @brief Returns the custom Filter string. + * + * @return The message filter. + */ + virtual const std::string& GetMessageFilter(); + + protected: + + /** + * @fn MessageBase::~MessageBase(); + * + * @brief dtor. + */ + ~MessageBase(); + + /** + * @fn virtual const std::string& MessageBase::GetType() const override; + * + * @brief Returns the class type Made protected to hide it. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + + private: + + trBase::ObsrvrPtr mFromActorID, mAboutActorID; + bool mIsDirect; + const std::string *mMessageFilter; + trBase::UniqueId mId; + }; +} + + + diff --git a/include/trManager/MessageEntityRegistered.h b/include/trManager/MessageEntityRegistered.h index e55afa0..3186195 100644 --- a/include/trManager/MessageEntityRegistered.h +++ b/include/trManager/MessageEntityRegistered.h @@ -1,101 +1,101 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trManager -{ - /** - * @class MessageEntityRegistered - * - * @brief A message that is sent out when a new entity is registered with the System Manager. - */ - class TR_MANAGER_EXPORT MessageEntityRegistered : public trManager::MessageBase - { - public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageEntityRegistered::MessageEntityRegistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); - * - * @brief Constructor. - * - * @param fromActorID Identifier of the entity that is sending this message (usually System - * Manager) - * @param aboutActorID Identifier for the Entity that just registered. - * @param entityType Type of the registered entity. - * @param entityName Name of the registered entity. - */ - MessageEntityRegistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); - - /** - * @fn virtual const std::string& MessageEntityRegistered::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn virtual const std::string& MessageEntityRegistered::GetEntityType() const; - * - * @brief Gets entity type. - * - * @return The entity type. - */ - virtual const std::string& GetEntityType() const; - - /** - * @fn virtual const std::string& MessageEntityRegistered::GetEntityName() const; - * - * @brief Gets entity type. - * - * @return The entity type. - */ - virtual const std::string& GetEntityName() const; - - protected: - - /** - * @fn MessageEntityRegistered::~MessageEntityRegistered(); - * - * @brief Destructor. - */ - ~MessageEntityRegistered(); - - private: - - const std::string* mEntityTypePtr; - const std::string* mEntityNamePtr; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trManager +{ + /** + * @class MessageEntityRegistered + * + * @brief A message that is sent out when a new entity is registered with the System Manager. + */ + class TR_MANAGER_EXPORT MessageEntityRegistered : public trManager::MessageBase + { + public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageEntityRegistered::MessageEntityRegistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); + * + * @brief Constructor. + * + * @param fromActorID Identifier of the entity that is sending this message (usually System + * Manager) + * @param aboutActorID Identifier for the Entity that just registered. + * @param entityType Type of the registered entity. + * @param entityName Name of the registered entity. + */ + MessageEntityRegistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); + + /** + * @fn virtual const std::string& MessageEntityRegistered::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn virtual const std::string& MessageEntityRegistered::GetEntityType() const; + * + * @brief Gets entity type. + * + * @return The entity type. + */ + virtual const std::string& GetEntityType() const; + + /** + * @fn virtual const std::string& MessageEntityRegistered::GetEntityName() const; + * + * @brief Gets entity type. + * + * @return The entity type. + */ + virtual const std::string& GetEntityName() const; + + protected: + + /** + * @fn MessageEntityRegistered::~MessageEntityRegistered(); + * + * @brief Destructor. + */ + ~MessageEntityRegistered(); + + private: + + const std::string* mEntityTypePtr; + const std::string* mEntityNamePtr; + }; } \ No newline at end of file diff --git a/include/trManager/MessageEntityUnregistered.h b/include/trManager/MessageEntityUnregistered.h index 85709d4..471768d 100644 --- a/include/trManager/MessageEntityUnregistered.h +++ b/include/trManager/MessageEntityUnregistered.h @@ -1,101 +1,101 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trManager -{ - /** - * @class MessageEntityUnregistered - * - * @brief A message that is sent out when an entity is unregistered from the System Manager. - */ - class TR_MANAGER_EXPORT MessageEntityUnregistered : public trManager::MessageBase - { - public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageEntityUnregistered::MessageEntityUnregistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); - * - * @brief Constructor. - * - * @param fromActorID Identifier of the entity that is sending this message (usually System - * Manager) - * @param aboutActorID Identifier for the Entity that just unregistered. - * @param entityType Type of the registered entity. - * @param entityName Name of the registered entity. - */ - MessageEntityUnregistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); - - /** - * @fn virtual const std::string& MessageEntityUnregistered::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn virtual const std::string& MessageEntityUnregistered::GetEntityType() const; - * - * @brief Gets entity type. - * - * @return The entity type. - */ - virtual const std::string& GetEntityType() const; - - /** - * @fn virtual const std::string& MessageEntityUnregistered::GetEntityName() const; - * - * @brief Gets entity type. - * - * @return The entity type. - */ - virtual const std::string& GetEntityName() const; - - protected: - - /** - * @fn MessageEntityUnregistered::~MessageEntityUnregistered(); - * - * @brief Destructor. - */ - ~MessageEntityUnregistered(); - - private: - - const std::string* mEntityTypePtr; - const std::string* mEntityNamePtr; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trManager +{ + /** + * @class MessageEntityUnregistered + * + * @brief A message that is sent out when an entity is unregistered from the System Manager. + */ + class TR_MANAGER_EXPORT MessageEntityUnregistered : public trManager::MessageBase + { + public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageEntityUnregistered::MessageEntityUnregistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); + * + * @brief Constructor. + * + * @param fromActorID Identifier of the entity that is sending this message (usually System + * Manager) + * @param aboutActorID Identifier for the Entity that just unregistered. + * @param entityType Type of the registered entity. + * @param entityName Name of the registered entity. + */ + MessageEntityUnregistered(const trBase::UniqueId* fromActorID, const trBase::UniqueId* aboutActorID, const std::string* entityType, const std::string* entityName); + + /** + * @fn virtual const std::string& MessageEntityUnregistered::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn virtual const std::string& MessageEntityUnregistered::GetEntityType() const; + * + * @brief Gets entity type. + * + * @return The entity type. + */ + virtual const std::string& GetEntityType() const; + + /** + * @fn virtual const std::string& MessageEntityUnregistered::GetEntityName() const; + * + * @brief Gets entity type. + * + * @return The entity type. + */ + virtual const std::string& GetEntityName() const; + + protected: + + /** + * @fn MessageEntityUnregistered::~MessageEntityUnregistered(); + * + * @brief Destructor. + */ + ~MessageEntityUnregistered(); + + private: + + const std::string* mEntityTypePtr; + const std::string* mEntityNamePtr; + }; } \ No newline at end of file diff --git a/include/trManager/MessageTick.h b/include/trManager/MessageTick.h index 09d227c..f912a67 100644 --- a/include/trManager/MessageTick.h +++ b/include/trManager/MessageTick.h @@ -1,139 +1,139 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include - -#include - -namespace trManager -{ - /** - * @class MessageTick - * - * @brief This message carries all the inter-frame timing information. Register for this message to receive frame times. - */ - class TR_MANAGER_EXPORT MessageTick : public trManager::MessageBase - { - public: - using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons - - /** - * @fn MessageTick::MessageTick(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - * - * @brief Constructor. - * - * @param fromActorID Id of the actor that is sending the message. - * @param timeStruct The time structure. - */ - MessageTick(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); - - /** - * @fn virtual const std::string& MessageTick::GetMessageType() const override; - * - * @brief Returns the Message type. - * - * @return The message type. - */ - virtual const std::string& GetMessageType() const override; - - /** - * @fn const int& MessageTick::GetFrameNumber(void) const - * - * @brief Gets frame number. - * - * @return The frame number. - */ - const int& GetFrameNumber(void) const { return(*mFrameNumber); } - - /** - * @fn const double& MessageTick::GetDeltaSimTime(void) const - * - * @brief Access the DeltaSimTime. - * - * @return The delta simulation time. - */ - const double& GetDeltaSimTime(void) const { return(*mDeltaSimTime); } - - /** - * @fn const double& MessageTick::GetDeltaRealTime(void) const - * - * @brief Access the DeltaRealTime. - * - * @return The delta real time. - */ - const double& GetDeltaRealTime(void) const { return(*mDeltaRealTime); } - - /** - * @fn const double& MessageTick::GetSimTime(void) const - * - * @brief Access the SimTime. - * - * @return The simulation time. - */ - const double& GetSimTime(void) const { return(*mSimTime); } - - /** - * @fn const double& MessageTick::GetRealTime(void) const - * - * @brief Access the RealTime. - * - * @return The real time. - */ - const double& GetRealTime(void) const { return(*mRealTime); } - - /** - * @fn const double& MessageTick::GetTimeScale(void) const - * - * @brief Access the TimeScale. - * - * @return The time scale. - */ - const double& GetTimeScale(void) const { return(*mTimeScale); } - - protected: - - /** - * @fn MessageTick::~MessageTick(); - * - * @brief Destructor. - */ - ~MessageTick(); - - private: - - const int* mFrameNumber; //Holds the current frame number. - const double* mDeltaSimTime; //Scaled Time between frames in seconds. - const double* mDeltaRealTime; //Non-scaled Time between frames. - const double* mSimTime; //Scaled time of the current simulation run. - const double* mRealTime; //Non-scaled time of the current simulation run. - const double* mTimeScale; //Time scaler - - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include + +#include + +namespace trManager +{ + /** + * @class MessageTick + * + * @brief This message carries all the inter-frame timing information. Register for this message to receive frame times. + */ + class TR_MANAGER_EXPORT MessageTick : public trManager::MessageBase + { + public: + using BaseClass = trManager::MessageBase; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr MESSAGE_TYPE; /// Holds the class/message type name for efficient comparisons + + /** + * @fn MessageTick::MessageTick(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + * + * @brief Constructor. + * + * @param fromActorID Id of the actor that is sending the message. + * @param timeStruct The time structure. + */ + MessageTick(const trBase::UniqueId* fromActorID, const trManager::TimingStructure& timeStruct); + + /** + * @fn virtual const std::string& MessageTick::GetMessageType() const override; + * + * @brief Returns the Message type. + * + * @return The message type. + */ + virtual const std::string& GetMessageType() const override; + + /** + * @fn const int& MessageTick::GetFrameNumber(void) const + * + * @brief Gets frame number. + * + * @return The frame number. + */ + const int& GetFrameNumber(void) const { return(*mFrameNumber); } + + /** + * @fn const double& MessageTick::GetDeltaSimTime(void) const + * + * @brief Access the DeltaSimTime. + * + * @return The delta simulation time. + */ + const double& GetDeltaSimTime(void) const { return(*mDeltaSimTime); } + + /** + * @fn const double& MessageTick::GetDeltaRealTime(void) const + * + * @brief Access the DeltaRealTime. + * + * @return The delta real time. + */ + const double& GetDeltaRealTime(void) const { return(*mDeltaRealTime); } + + /** + * @fn const double& MessageTick::GetSimTime(void) const + * + * @brief Access the SimTime. + * + * @return The simulation time. + */ + const double& GetSimTime(void) const { return(*mSimTime); } + + /** + * @fn const double& MessageTick::GetRealTime(void) const + * + * @brief Access the RealTime. + * + * @return The real time. + */ + const double& GetRealTime(void) const { return(*mRealTime); } + + /** + * @fn const double& MessageTick::GetTimeScale(void) const + * + * @brief Access the TimeScale. + * + * @return The time scale. + */ + const double& GetTimeScale(void) const { return(*mTimeScale); } + + protected: + + /** + * @fn MessageTick::~MessageTick(); + * + * @brief Destructor. + */ + ~MessageTick(); + + private: + + const int* mFrameNumber; //Holds the current frame number. + const double* mDeltaSimTime; //Scaled Time between frames in seconds. + const double* mDeltaRealTime; //Non-scaled Time between frames. + const double* mSimTime; //Scaled time of the current simulation run. + const double* mRealTime; //Non-scaled time of the current simulation run. + const double* mTimeScale; //Time scaler + + }; } \ No newline at end of file diff --git a/include/trManager/SystemManager.h b/include/trManager/SystemManager.h index 3ad5c64..603f7e2 100644 --- a/include/trManager/SystemManager.h +++ b/include/trManager/SystemManager.h @@ -1,501 +1,501 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace trManager -{ - /** - * System Manager class is a singleton that is responsible for all message routing and basic - * operations between actors and directors throughout TR. - */ - class TR_MANAGER_EXPORT SystemManager : public trBase::Base - { - public: - - using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class - - const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons - - /** - * @fn static trManager::SystemManager& SystemManager::GetInstance(); - * - * @brief Returns the Instance of the System Manager Singleton. - * - * @return The instance. - */ - static trManager::SystemManager& GetInstance(); - - /** - * @fn virtual const std::string& SystemManager::GetType() const override; - * - * @brief Returns the class type. - * - * @return The type. - */ - virtual const std::string& GetType() const override; - - /** - * @fn virtual bool SystemManager::SendMessage(const trManager::MessageBase& message); - * - * @brief Send a message to an Actor, Actor Module, or a Director. - * - * @param message The message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendMessage(const trManager::MessageBase& message); - - /** - * @fn virtual bool SystemManager::SendNetworkMessage(const trManager::MessageBase& message); - * - * @brief Send a Network message to an Actor, Actor Module, or a Director. - * - * @param message The message. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool SendNetworkMessage(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::ProcessMessage(const trManager::MessageBase& message); - * - * @brief Immediately processes the passed in message. Usually used to manipulate the system - * flow. - * - * @param message The message. - */ - virtual void ProcessMessage(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::ProcessMessages(); - * - * @brief Sends out all the messages from the message queue. This is for system use only. - */ - virtual void ProcessMessages(); - - /** - * @fn virtual void SystemManager::ProcessNetworkMessages(); - * - * @brief Sends out all the network messages from the message queue. This is for system use - * only. - */ - virtual void ProcessNetworkMessages(); - - /** - * @fn virtual void SystemManager::RegisterForMessage(const std::string& messageType, EntityBase& listeningActor, const std::string& invokableName); - * - * @brief Registers an actor for messages. - * - * @param messageType Type of the message. - * @param [in,out] listeningActor The Listening actor that will receive the message. - * @param invokableName Name of the invokable that the message will be routed to. - */ - virtual void RegisterForMessage(const std::string& messageType, EntityBase& listeningActor, const std::string& invokableName); - - /** - * @fn virtual void SystemManager::UnregisterFromMessage(const std::string& messageType, EntityBase& listeningActor); - * - * @brief Unregister an actor that is listening for a given message. - * - * @param messageType Type of the message. - * @param [in,out] listeningActor The listening actor. - */ - virtual void UnregisterFromMessage(const std::string& messageType, EntityBase& listeningActor); - - /** - * @fn virtual void SystemManager::RegisterForMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId, const std::string& invokableName); - * - * @brief Registers for messages about a specific actor. - * - * @param [in,out] listeningEntity The Listening entity that will receive the message. - * @param aboutEntityId Identifier for the about entity. - * @param invokableName Name of the invokable. - */ - virtual void RegisterForMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId, const std::string& invokableName); - - /** - * @fn virtual void SystemManager::UnregisterFromMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId); - * - * @brief Unregisters from messages about a specific actor. - * - * @param [in,out] listeningEntity The listening entity. - * @param aboutEntityId Identifier for the about entity. - */ - virtual void UnregisterFromMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId); - - /** - * @fn virtual bool SystemManager::RegisterActor(trManager::EntityBase& actor); - * - * @brief Registers an Actor or Actor Module with the System Manager. - * - * @param [in,out] actor The actor. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RegisterActor(trManager::EntityBase& actor); - - /** - * @fn virtual bool SystemManager::UnregisterActor(trManager::EntityBase& actor); - * - * @brief Disconnects the actor from the System Manager. - * - * @param [in,out] actor The actor. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool UnregisterActor(trManager::EntityBase& actor); - - /** - * @fn virtual bool SystemManager::UnregisterActor(const trBase::UniqueId& id); - * - * @brief Disconnects the actor from the System Manager by using the actors ID. - * - * @param id The identifier. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool UnregisterActor(const trBase::UniqueId& id); - - /** - * @fn virtual bool SystemManager::UnregisterAllActors(); - * - * @brief Unregisters all actors from the System Manager. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool UnregisterAllActors(); - - /** - * @fn virtual trManager::EntityBase* SystemManager::FindActor(const trBase::UniqueId& id); - * - * @brief Searches for an actor or actor module with the given ID. - * - * @param id The unique identifier. - * - * @return Null if it fails, else the found actor. - */ - virtual trManager::EntityBase* FindActor(const trBase::UniqueId& id); - - /** - * @fn virtual std::vector SystemManager::FindActorsByType(const std::string& actorType); - * - * @brief Searches for all actors of a given type. WARNING: This functions is slow. - * - * @param actorType Type of the actor. - * - * @return Empty vector if it fails, else a vector of found actors. - */ - virtual std::vector FindActorsByType(const std::string& actorType); - - /** - * @fn virtual std::vector SystemManager::FindActorsByName(const std::string& actorName); - * - * @brief Searches for all actors by a given name. WARNING: This function is slow. - * - * @param actorName Name of the actor. - * - * @return Empty vector if it fails, else a vector of found actors. - */ - virtual std::vector FindActorsByName(const std::string& actorName); - - /** - * @fn virtual bool SystemManager::RegisterDirector(trManager::EntityBase& director, trManager::DirectorPriority& priority = trManager::DirectorPriority::NORMAL); - * - * @brief Adds a director to the list of components the system manager will communicate with. - * - * @exception trUtil::InvalidParameterException if the director lacks a unique name. - * - * @param [in,out] director The director to add. - * @param [in,out] priority (Optional) The priority of the director. This translates into - * the order of message delivery. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool RegisterDirector(trManager::EntityBase& director, trManager::DirectorPriority& priority = trManager::DirectorPriority::NORMAL); - - /** - * @fn virtual bool SystemManager::UnregisterDirector(trManager::EntityBase& director); - * - * @brief Disconnects the director from System Manager. - * - * @param [in,out] director The director. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool UnregisterDirector(trManager::EntityBase& director); - - /** - * @fn virtual bool SystemManager::UnregisterDirector(const trBase::UniqueId& id); - * - * @brief Disconnects the director from System Manager by using it's ID. - * - * @param id The identifier. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool UnregisterDirector(const trBase::UniqueId& id); - - /** - * @fn virtual void SystemManager::UnregisterAllDirectors(); - * - * @brief Unregisters all the directors from System Manager. - */ - virtual void UnregisterAllDirectors(); - - /** - * @fn virtual trManager::EntityBase* SystemManager::FindDirector(const trBase::UniqueId& id) const; - * - * @brief Finds and returns the director with the given ID. - * - * @param id The identifier. - * - * @return Null if it fails, else the found director. - */ - virtual trManager::EntityBase* FindDirector(const trBase::UniqueId& id) const; - - /** - * @fn virtual trManager::EntityBase* SystemManager::FindDirector(const std::string& name) const; - * - * @brief Finds and returns the director with the given Name. The Directors name is unique, so - * only one Director with the right name can exist. - * - * @param name The name. - * - * @return Null if it fails, else the found director. - */ - virtual trManager::EntityBase* FindDirector(const std::string& name) const; - - /** - * @fn virtual std::vector SystemManager::FindDirectors(const std::string& type) const; - * - * @brief Finds and returns all the Directors of a given type. WARNING: This function is slow. - * - * @param type The type. - * - * @return Null if it fails, else the found directors. - */ - virtual std::vector FindDirectors(const std::string& type) const; - - /** - * @fn virtual void SystemManager::RemoveMarkedEntities(); - * - * @brief Removes all entities that were marked to be unregistered. This is for system use only, - * and should not be called directly by the user. - * - * @return True if it succeeds, false if it fails. - */ - virtual void RemoveMarkedEntities(); - - /** - * @fn virtual void SystemManager::ShutDown(); - * - * @brief Shuts down the System Manager and unregisters all entities. - */ - virtual void ShutDown(); - - protected: - - /** - * @fn SystemManager::SystemManager(const std::string name = CLASS_TYPE); - * - * @brief Ctor. - * - * @param name (Optional) The name. - */ - SystemManager(const std::string name = CLASS_TYPE); - - /** - * @fn SystemManager::~SystemManager(); - * - * @brief Dtor. - */ - ~SystemManager(); - - /** - * @fn virtual void SystemManager::SendMessageToDirectors(const trManager::MessageBase& message); - * - * @brief Send the passed in message to all registered Directors. - * - * @param message The message. - */ - virtual void SendMessageToDirectors(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::SendMessageToActors(const trManager::MessageBase& message); - * - * @brief Sends the passed in message to appropriate actors. - * - * @param message The message. - */ - virtual void SendMessageToActors(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::SendMessageToListeners(const trManager::MessageBase& message); - * - * @brief Sends a message to entities that are listening for messages about other actors. - * - * @param message The message. - */ - virtual void SendMessageToListeners(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::SendGlobalyRegisteredMessage(const trManager::MessageBase& message); - * - * @brief Sends out a message to all entities who had a global registration for it. - * - * @param message The message. - */ - virtual void SendGlobalyRegisteredMessage(const trManager::MessageBase& message); - - /** - * @fn virtual void SystemManager::CallInvokable(const trManager::MessageBase& message, const std::string& invokableName, trManager::EntityBase& entity); - * - * @brief Utility function. Calls the passed in Invokable on the passed in EntityBase. - * - * @param message The message to pass to the Invokable. - * @param invokableName Name of the invokable. - * @param [in,out] entity The EntityBase on which to call the Invokable. - */ - virtual void CallInvokable(const trManager::MessageBase& message, const std::string& invokableName, trManager::EntityBase& entity); - - /** - * @fn virtual void SystemManager::UnregisterActorFromGlobalMessages(trManager::EntityBase& actor); - * - * @brief Unregisters the actor/actor module from all messages that have registrations. - * - * @param [in,out] actor The actor. - */ - virtual void UnregisterActorFromGlobalMessages(trManager::EntityBase& actor); - - /** - * @fn virtual void SystemManager::UnregisterDirectorFromGlobalMessages(trManager::EntityBase& director); - * - * @brief Unregisters the director from all messages that have registrations. - * - * @param [in,out] director The director. - */ - virtual void UnregisterDirectorFromGlobalMessages(trManager::EntityBase& director); - - /** - * @fn virtual void SystemManager::UnregisterEntityFromAboutMessages(trManager::EntityBase& listeningEntity); - * - * @brief Unregisters the entity from about messages about another actor. - * - * @param [in,out] listeningEntity The entity. - */ - virtual void UnregisterEntityFromAboutMessages(trManager::EntityBase& listeningEntity); - - private: - - static trBase::SmrtPtr mInstance; - std::queue> mMessageQueue; - std::queue> mNetworkMessageQueue; - - // Storage for all the registered Directors - using DirectorList = std::list>; //Needs to be a std::list so the directors can be priority sorted - using DirectorNameMap = trUtil::HashMap>; - using DirectorIDMap = trUtil::HashMap>; - DirectorList mDirectorList; - DirectorNameMap mDirectorNameMap; - DirectorIDMap mDirectorIDMap; - - //Message registration structures.. - using EntityInvokablePair = std::pair, std::string>; // - using MessageRegistrationVectorMap = trUtil::HashMap>; // - using UUIDRegistrationVectorMap = trUtil::HashMap>; // - using EntityInvokableMap = trUtil::HashMap, std::string>; // - using MessageRegistrationMap = trUtil::HashMap; //> - MessageRegistrationVectorMap mEntityGlobalMsgRegistrationMap; - MessageRegistrationMap mDirectorGlobalMsgRegistrationMap; - UUIDRegistrationVectorMap mListenerRegistrationMap; - - //Storage for all registered Actors and Actor Modules - using ActorList = std::vector>; - using ActorIDMap = trUtil::HashMap>; - ActorList mActorList; - ActorIDMap mActorIDMap; - - std::vector> mEntityDeleteList; //List of entities that will be deleted at the end of the frame - - /** - * @fn void SystemManager::RegisterMsgWithMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationVectorMap& messageMap); - * - * @brief Registers the message with a given message map. - * - * @param messageType Type of the message. - * @param [in,out] listeningEntity The listening entity. - * @param invokableName Name of the invokable. - * @param [in,out] messageMap The message map. - */ - void RegisterMsgWithMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationVectorMap& messageMap); - - /** - * @fn void SystemManager::UnregisterMsgFromMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationVectorMap& messageMap); - * - * @brief Un register message from a given message map. - * - * @param messageType Type of the message. - * @param [in,out] listeningEntity The listening entity. - * @param [in,out] messageMap The message map. - */ - void UnregisterMsgFromMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationVectorMap& messageMap); - - /** - * @fn void SystemManager::RegisterMsgWithMsgMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationMap& messageMap); - * - * @brief Registers the message with message map. - * - * @param messageType Type of the message. - * @param [in,out] listeningEntity The listening entity. - * @param invokableName Name of the invokable. - * @param [in,out] messageMap The message map. - */ - void RegisterMsgWithMsgMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationMap& messageMap); - - /** - * @fn void SystemManager::UnregisterMsgFromMsgMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationMap& messageMap); - * - * @brief Un register message from message map. - * - * @param messageType Type of the message. - * @param [in,out] listeningEntity The listening entity. - * @param [in,out] messageMap The message map. - */ - void UnregisterMsgFromMsgMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationMap& messageMap); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace trManager +{ + /** + * System Manager class is a singleton that is responsible for all message routing and basic + * operations between actors and directors throughout TR. + */ + class TR_MANAGER_EXPORT SystemManager : public trBase::Base + { + public: + + using BaseClass = trBase::Base; /// Adds an easy and swappable access to the base class + + const static trUtil::RefStr CLASS_TYPE; /// Holds the class type name for efficient comparisons + + /** + * @fn static trManager::SystemManager& SystemManager::GetInstance(); + * + * @brief Returns the Instance of the System Manager Singleton. + * + * @return The instance. + */ + static trManager::SystemManager& GetInstance(); + + /** + * @fn virtual const std::string& SystemManager::GetType() const override; + * + * @brief Returns the class type. + * + * @return The type. + */ + virtual const std::string& GetType() const override; + + /** + * @fn virtual bool SystemManager::SendMessage(const trManager::MessageBase& message); + * + * @brief Send a message to an Actor, Actor Module, or a Director. + * + * @param message The message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendMessage(const trManager::MessageBase& message); + + /** + * @fn virtual bool SystemManager::SendNetworkMessage(const trManager::MessageBase& message); + * + * @brief Send a Network message to an Actor, Actor Module, or a Director. + * + * @param message The message. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool SendNetworkMessage(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::ProcessMessage(const trManager::MessageBase& message); + * + * @brief Immediately processes the passed in message. Usually used to manipulate the system + * flow. + * + * @param message The message. + */ + virtual void ProcessMessage(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::ProcessMessages(); + * + * @brief Sends out all the messages from the message queue. This is for system use only. + */ + virtual void ProcessMessages(); + + /** + * @fn virtual void SystemManager::ProcessNetworkMessages(); + * + * @brief Sends out all the network messages from the message queue. This is for system use + * only. + */ + virtual void ProcessNetworkMessages(); + + /** + * @fn virtual void SystemManager::RegisterForMessage(const std::string& messageType, EntityBase& listeningActor, const std::string& invokableName); + * + * @brief Registers an actor for messages. + * + * @param messageType Type of the message. + * @param [in,out] listeningActor The Listening actor that will receive the message. + * @param invokableName Name of the invokable that the message will be routed to. + */ + virtual void RegisterForMessage(const std::string& messageType, EntityBase& listeningActor, const std::string& invokableName); + + /** + * @fn virtual void SystemManager::UnregisterFromMessage(const std::string& messageType, EntityBase& listeningActor); + * + * @brief Unregister an actor that is listening for a given message. + * + * @param messageType Type of the message. + * @param [in,out] listeningActor The listening actor. + */ + virtual void UnregisterFromMessage(const std::string& messageType, EntityBase& listeningActor); + + /** + * @fn virtual void SystemManager::RegisterForMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId, const std::string& invokableName); + * + * @brief Registers for messages about a specific actor. + * + * @param [in,out] listeningEntity The Listening entity that will receive the message. + * @param aboutEntityId Identifier for the about entity. + * @param invokableName Name of the invokable. + */ + virtual void RegisterForMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId, const std::string& invokableName); + + /** + * @fn virtual void SystemManager::UnregisterFromMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId); + * + * @brief Unregisters from messages about a specific actor. + * + * @param [in,out] listeningEntity The listening entity. + * @param aboutEntityId Identifier for the about entity. + */ + virtual void UnregisterFromMessagesAboutEntity(EntityBase& listeningEntity, const trBase::UniqueId& aboutEntityId); + + /** + * @fn virtual bool SystemManager::RegisterActor(trManager::EntityBase& actor); + * + * @brief Registers an Actor or Actor Module with the System Manager. + * + * @param [in,out] actor The actor. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RegisterActor(trManager::EntityBase& actor); + + /** + * @fn virtual bool SystemManager::UnregisterActor(trManager::EntityBase& actor); + * + * @brief Disconnects the actor from the System Manager. + * + * @param [in,out] actor The actor. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool UnregisterActor(trManager::EntityBase& actor); + + /** + * @fn virtual bool SystemManager::UnregisterActor(const trBase::UniqueId& id); + * + * @brief Disconnects the actor from the System Manager by using the actors ID. + * + * @param id The identifier. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool UnregisterActor(const trBase::UniqueId& id); + + /** + * @fn virtual bool SystemManager::UnregisterAllActors(); + * + * @brief Unregisters all actors from the System Manager. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool UnregisterAllActors(); + + /** + * @fn virtual trManager::EntityBase* SystemManager::FindActor(const trBase::UniqueId& id); + * + * @brief Searches for an actor or actor module with the given ID. + * + * @param id The unique identifier. + * + * @return Null if it fails, else the found actor. + */ + virtual trManager::EntityBase* FindActor(const trBase::UniqueId& id); + + /** + * @fn virtual std::vector SystemManager::FindActorsByType(const std::string& actorType); + * + * @brief Searches for all actors of a given type. WARNING: This functions is slow. + * + * @param actorType Type of the actor. + * + * @return Empty vector if it fails, else a vector of found actors. + */ + virtual std::vector FindActorsByType(const std::string& actorType); + + /** + * @fn virtual std::vector SystemManager::FindActorsByName(const std::string& actorName); + * + * @brief Searches for all actors by a given name. WARNING: This function is slow. + * + * @param actorName Name of the actor. + * + * @return Empty vector if it fails, else a vector of found actors. + */ + virtual std::vector FindActorsByName(const std::string& actorName); + + /** + * @fn virtual bool SystemManager::RegisterDirector(trManager::EntityBase& director, trManager::DirectorPriority& priority = trManager::DirectorPriority::NORMAL); + * + * @brief Adds a director to the list of components the system manager will communicate with. + * + * @exception trUtil::InvalidParameterException if the director lacks a unique name. + * + * @param [in,out] director The director to add. + * @param [in,out] priority (Optional) The priority of the director. This translates into + * the order of message delivery. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool RegisterDirector(trManager::EntityBase& director, trManager::DirectorPriority& priority = trManager::DirectorPriority::NORMAL); + + /** + * @fn virtual bool SystemManager::UnregisterDirector(trManager::EntityBase& director); + * + * @brief Disconnects the director from System Manager. + * + * @param [in,out] director The director. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool UnregisterDirector(trManager::EntityBase& director); + + /** + * @fn virtual bool SystemManager::UnregisterDirector(const trBase::UniqueId& id); + * + * @brief Disconnects the director from System Manager by using it's ID. + * + * @param id The identifier. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool UnregisterDirector(const trBase::UniqueId& id); + + /** + * @fn virtual void SystemManager::UnregisterAllDirectors(); + * + * @brief Unregisters all the directors from System Manager. + */ + virtual void UnregisterAllDirectors(); + + /** + * @fn virtual trManager::EntityBase* SystemManager::FindDirector(const trBase::UniqueId& id) const; + * + * @brief Finds and returns the director with the given ID. + * + * @param id The identifier. + * + * @return Null if it fails, else the found director. + */ + virtual trManager::EntityBase* FindDirector(const trBase::UniqueId& id) const; + + /** + * @fn virtual trManager::EntityBase* SystemManager::FindDirector(const std::string& name) const; + * + * @brief Finds and returns the director with the given Name. The Directors name is unique, so + * only one Director with the right name can exist. + * + * @param name The name. + * + * @return Null if it fails, else the found director. + */ + virtual trManager::EntityBase* FindDirector(const std::string& name) const; + + /** + * @fn virtual std::vector SystemManager::FindDirectors(const std::string& type) const; + * + * @brief Finds and returns all the Directors of a given type. WARNING: This function is slow. + * + * @param type The type. + * + * @return Null if it fails, else the found directors. + */ + virtual std::vector FindDirectors(const std::string& type) const; + + /** + * @fn virtual void SystemManager::RemoveMarkedEntities(); + * + * @brief Removes all entities that were marked to be unregistered. This is for system use only, + * and should not be called directly by the user. + * + * @return True if it succeeds, false if it fails. + */ + virtual void RemoveMarkedEntities(); + + /** + * @fn virtual void SystemManager::ShutDown(); + * + * @brief Shuts down the System Manager and unregisters all entities. + */ + virtual void ShutDown(); + + protected: + + /** + * @fn SystemManager::SystemManager(const std::string name = CLASS_TYPE); + * + * @brief Ctor. + * + * @param name (Optional) The name. + */ + SystemManager(const std::string name = CLASS_TYPE); + + /** + * @fn SystemManager::~SystemManager(); + * + * @brief Dtor. + */ + ~SystemManager(); + + /** + * @fn virtual void SystemManager::SendMessageToDirectors(const trManager::MessageBase& message); + * + * @brief Send the passed in message to all registered Directors. + * + * @param message The message. + */ + virtual void SendMessageToDirectors(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::SendMessageToActors(const trManager::MessageBase& message); + * + * @brief Sends the passed in message to appropriate actors. + * + * @param message The message. + */ + virtual void SendMessageToActors(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::SendMessageToListeners(const trManager::MessageBase& message); + * + * @brief Sends a message to entities that are listening for messages about other actors. + * + * @param message The message. + */ + virtual void SendMessageToListeners(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::SendGlobalyRegisteredMessage(const trManager::MessageBase& message); + * + * @brief Sends out a message to all entities who had a global registration for it. + * + * @param message The message. + */ + virtual void SendGlobalyRegisteredMessage(const trManager::MessageBase& message); + + /** + * @fn virtual void SystemManager::CallInvokable(const trManager::MessageBase& message, const std::string& invokableName, trManager::EntityBase& entity); + * + * @brief Utility function. Calls the passed in Invokable on the passed in EntityBase. + * + * @param message The message to pass to the Invokable. + * @param invokableName Name of the invokable. + * @param [in,out] entity The EntityBase on which to call the Invokable. + */ + virtual void CallInvokable(const trManager::MessageBase& message, const std::string& invokableName, trManager::EntityBase& entity); + + /** + * @fn virtual void SystemManager::UnregisterActorFromGlobalMessages(trManager::EntityBase& actor); + * + * @brief Unregisters the actor/actor module from all messages that have registrations. + * + * @param [in,out] actor The actor. + */ + virtual void UnregisterActorFromGlobalMessages(trManager::EntityBase& actor); + + /** + * @fn virtual void SystemManager::UnregisterDirectorFromGlobalMessages(trManager::EntityBase& director); + * + * @brief Unregisters the director from all messages that have registrations. + * + * @param [in,out] director The director. + */ + virtual void UnregisterDirectorFromGlobalMessages(trManager::EntityBase& director); + + /** + * @fn virtual void SystemManager::UnregisterEntityFromAboutMessages(trManager::EntityBase& listeningEntity); + * + * @brief Unregisters the entity from about messages about another actor. + * + * @param [in,out] listeningEntity The entity. + */ + virtual void UnregisterEntityFromAboutMessages(trManager::EntityBase& listeningEntity); + + private: + + static trBase::SmrtPtr mInstance; + std::queue> mMessageQueue; + std::queue> mNetworkMessageQueue; + + // Storage for all the registered Directors + using DirectorList = std::list>; //Needs to be a std::list so the directors can be priority sorted + using DirectorNameMap = trUtil::HashMap>; + using DirectorIDMap = trUtil::HashMap>; + DirectorList mDirectorList; + DirectorNameMap mDirectorNameMap; + DirectorIDMap mDirectorIDMap; + + //Message registration structures.. + using EntityInvokablePair = std::pair, std::string>; // + using MessageRegistrationVectorMap = trUtil::HashMap>; // + using UUIDRegistrationVectorMap = trUtil::HashMap>; // + using EntityInvokableMap = trUtil::HashMap, std::string>; // + using MessageRegistrationMap = trUtil::HashMap; //> + MessageRegistrationVectorMap mEntityGlobalMsgRegistrationMap; + MessageRegistrationMap mDirectorGlobalMsgRegistrationMap; + UUIDRegistrationVectorMap mListenerRegistrationMap; + + //Storage for all registered Actors and Actor Modules + using ActorList = std::vector>; + using ActorIDMap = trUtil::HashMap>; + ActorList mActorList; + ActorIDMap mActorIDMap; + + std::vector> mEntityDeleteList; //List of entities that will be deleted at the end of the frame + + /** + * @fn void SystemManager::RegisterMsgWithMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationVectorMap& messageMap); + * + * @brief Registers the message with a given message map. + * + * @param messageType Type of the message. + * @param [in,out] listeningEntity The listening entity. + * @param invokableName Name of the invokable. + * @param [in,out] messageMap The message map. + */ + void RegisterMsgWithMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationVectorMap& messageMap); + + /** + * @fn void SystemManager::UnregisterMsgFromMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationVectorMap& messageMap); + * + * @brief Un register message from a given message map. + * + * @param messageType Type of the message. + * @param [in,out] listeningEntity The listening entity. + * @param [in,out] messageMap The message map. + */ + void UnregisterMsgFromMsgVectorMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationVectorMap& messageMap); + + /** + * @fn void SystemManager::RegisterMsgWithMsgMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationMap& messageMap); + * + * @brief Registers the message with message map. + * + * @param messageType Type of the message. + * @param [in,out] listeningEntity The listening entity. + * @param invokableName Name of the invokable. + * @param [in,out] messageMap The message map. + */ + void RegisterMsgWithMsgMap(const std::string& messageType, EntityBase& listeningEntity, const std::string& invokableName, MessageRegistrationMap& messageMap); + + /** + * @fn void SystemManager::UnregisterMsgFromMsgMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationMap& messageMap); + * + * @brief Un register message from message map. + * + * @param messageType Type of the message. + * @param [in,out] listeningEntity The listening entity. + * @param [in,out] messageMap The message map. + */ + void UnregisterMsgFromMsgMap(const std::string& messageType, EntityBase& listeningEntity, MessageRegistrationMap& messageMap); + }; } \ No newline at end of file diff --git a/include/trManager/TimingStructure.h b/include/trManager/TimingStructure.h index 23d8350..793eb6b 100644 --- a/include/trManager/TimingStructure.h +++ b/include/trManager/TimingStructure.h @@ -1,45 +1,45 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -namespace trManager -{ - /** - * @struct TimingStructure - * - * @brief A timing structure for all sim loop variables. - */ - struct TR_MANAGER_EXPORT TimingStructure - { - int frameNumber = 0; //Holds the Frame number - - double deltaSimTime = 0.; //Scaled Time between frames in seconds. - double deltaRealTime = 0.; //Non-scaled Time between frames. - double simTime = 0.; //Scaled time of the current simulation run. - double realTime = 0.; //Non-scaled time of the current simulation run. - double timeScale = 1.; //Time scaler - }; -} - - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +namespace trManager +{ + /** + * @struct TimingStructure + * + * @brief A timing structure for all sim loop variables. + */ + struct TR_MANAGER_EXPORT TimingStructure + { + int frameNumber = 0; //Holds the Frame number + + double deltaSimTime = 0.; //Scaled Time between frames in seconds. + double deltaRealTime = 0.; //Non-scaled Time between frames. + double simTime = 0.; //Scaled time of the current simulation run. + double realTime = 0.; //Non-scaled time of the current simulation run. + double timeScale = 1.; //Time scaler + }; +} + + diff --git a/include/trUtil/ApplicationUsage.h b/include/trUtil/ApplicationUsage.h index 43c3b40..0cd5ea1 100644 --- a/include/trUtil/ApplicationUsage.h +++ b/include/trUtil/ApplicationUsage.h @@ -1,54 +1,54 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include -#include - - -/** - * @namespace trUtil - * - * @brief Namespace that holds various utility classes for the engine - */ -namespace trUtil -{ - /** - * @class ApplicationUsage - * - * @brief An application usage class for the argument parser. - */ - class TR_UTIL_EXPORT ApplicationUsage - { - public: - - /** @brief The message to command usage map. */ - using UsageMap = std::map; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include +#include + + +/** + * @namespace trUtil + * + * @brief Namespace that holds various utility classes for the engine + */ +namespace trUtil +{ + /** + * @class ApplicationUsage + * + * @brief An application usage class for the argument parser. + */ + class TR_UTIL_EXPORT ApplicationUsage + { + public: + + /** @brief The message to command usage map. */ + using UsageMap = std::map; + enum class Type { NO_HELP = osg::ApplicationUsage::NO_HELP, @@ -56,335 +56,335 @@ namespace trUtil ENVIRONMENTAL_VARIABLE = osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, KEYBOARD_MOUSE_BINDING = osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING, HELP_ALL = KEYBOARD_MOUSE_BINDING | ENVIRONMENTAL_VARIABLE | COMMAND_LINE_OPTION - }; - - /** - * @fn ApplicationUsage::ApplicationUsage(); - * - * @brief Default constructor. - */ - ApplicationUsage(); - - /** - * @fn ApplicationUsage::ApplicationUsage(osg::ApplicationUsage* applicationUsage); - * - * @brief Wraps an osg ApplicationUsage, and uses it as the internal class. - * - * @param [in,out] applicationUsage The application usage. - */ - ApplicationUsage(osg::ApplicationUsage* applicationUsage); - - /** - * @fn ApplicationUsage::ApplicationUsage(const std::string& commandLineUsage); - * - * @brief Default constructor. - * - * @param commandLineUsage The command line usage. - */ - ApplicationUsage(const std::string& commandLineUsage); - - /** - * @fn ApplicationUsage::~ApplicationUsage(); - * - * @brief Destructor. - */ - ~ApplicationUsage(); - - /** - * @fn void ApplicationUsage::SetApplicationName(const std::string& name); - * - * @brief Sets the Applications Name. It is used in Application description - * - * @param name The name. - */ + }; + + /** + * @fn ApplicationUsage::ApplicationUsage(); + * + * @brief Default constructor. + */ + ApplicationUsage(); + + /** + * @fn ApplicationUsage::ApplicationUsage(osg::ApplicationUsage* applicationUsage); + * + * @brief Wraps an osg ApplicationUsage, and uses it as the internal class. + * + * @param [in,out] applicationUsage The application usage. + */ + ApplicationUsage(osg::ApplicationUsage* applicationUsage); + + /** + * @fn ApplicationUsage::ApplicationUsage(const std::string& commandLineUsage); + * + * @brief Default constructor. + * + * @param commandLineUsage The command line usage. + */ + ApplicationUsage(const std::string& commandLineUsage); + + /** + * @fn ApplicationUsage::~ApplicationUsage(); + * + * @brief Destructor. + */ + ~ApplicationUsage(); + + /** + * @fn void ApplicationUsage::SetApplicationName(const std::string& name); + * + * @brief Sets the Applications Name. It is used in Application description + * + * @param name The name. + */ void SetApplicationName(const std::string& name); - - /** - * @fn const std::string& ApplicationUsage::GetApplicationName() const; - * - * @brief Gets the stored application name. - * - * @return The application name. - */ - const std::string& GetApplicationName() const; - - /** - * @fn void ApplicationUsage::SetDescription(const std::string& desc); - * - * @brief If non-empty, the Description is typically shown by the Help Handler as text on the - * Help display (which also lists keyboard abbreviations.) - * - * @param desc The description. - */ + + /** + * @fn const std::string& ApplicationUsage::GetApplicationName() const; + * + * @brief Gets the stored application name. + * + * @return The application name. + */ + const std::string& GetApplicationName() const; + + /** + * @fn void ApplicationUsage::SetDescription(const std::string& desc); + * + * @brief If non-empty, the Description is typically shown by the Help Handler as text on the + * Help display (which also lists keyboard abbreviations.) + * + * @param desc The description. + */ void SetDescription(const std::string& desc); - - /** - * @fn const std::string& ApplicationUsage::GetDescription() const; - * - * @brief Gets the description. - * - * @return The description. - */ - const std::string& GetDescription() const; - - /** - * @fn void ApplicationUsage::AddUsageExplanation(Type type, const std::string& option, const std::string& explanation); - * - * @brief Adds an usage explanation. - * - * @param type The type. - * @param option The option. - * @param explanation The explanation. - */ - void AddUsageExplanation(Type type, const std::string& option, const std::string& explanation); - - /** - * @fn void ApplicationUsage::SetCommandLineUsage(const std::string& explanation); - * - * @brief Sets command line usage. - * - * @param explanation The explanation. - */ + + /** + * @fn const std::string& ApplicationUsage::GetDescription() const; + * + * @brief Gets the description. + * + * @return The description. + */ + const std::string& GetDescription() const; + + /** + * @fn void ApplicationUsage::AddUsageExplanation(Type type, const std::string& option, const std::string& explanation); + * + * @brief Adds an usage explanation. + * + * @param type The type. + * @param option The option. + * @param explanation The explanation. + */ + void AddUsageExplanation(Type type, const std::string& option, const std::string& explanation); + + /** + * @fn void ApplicationUsage::SetCommandLineUsage(const std::string& explanation); + * + * @brief Sets command line usage. + * + * @param explanation The explanation. + */ void SetCommandLineUsage(const std::string& explanation); - - /** - * @fn const std::string& ApplicationUsage::GetCommandLineUsage() const; - * - * @brief Gets command line usage. - * - * @return The command line usage. - */ - const std::string& GetCommandLineUsage() const; - - /** - * @fn void ApplicationUsage::AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); - * - * @brief Adds a command line option. - * - * @param option The option. - * @param explanation The explanation. - * @param defaultValue (Optional) The default value. - */ - void AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); - - /** - * @fn void ApplicationUsage::SetCommandLineOptions(const UsageMap& usageMap); - * - * @brief Sets command line options. - * - * @param usageMap The usage map. - */ + + /** + * @fn const std::string& ApplicationUsage::GetCommandLineUsage() const; + * + * @brief Gets command line usage. + * + * @return The command line usage. + */ + const std::string& GetCommandLineUsage() const; + + /** + * @fn void ApplicationUsage::AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); + * + * @brief Adds a command line option. + * + * @param option The option. + * @param explanation The explanation. + * @param defaultValue (Optional) The default value. + */ + void AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); + + /** + * @fn void ApplicationUsage::SetCommandLineOptions(const UsageMap& usageMap); + * + * @brief Sets command line options. + * + * @param usageMap The usage map. + */ void SetCommandLineOptions(const UsageMap& usageMap); - - /** - * @fn const UsageMap& ApplicationUsage::GetCommandLineOptions() const; - * - * @brief Gets command line options. - * - * @return The command line options. - */ - const UsageMap& GetCommandLineOptions() const; - - /** - * @fn void ApplicationUsage::SetCommandLineOptionsDefaults(const UsageMap& usageMap); - * - * @brief Sets command line options defaults. - * - * @param usageMap The usage map. - */ + + /** + * @fn const UsageMap& ApplicationUsage::GetCommandLineOptions() const; + * + * @brief Gets command line options. + * + * @return The command line options. + */ + const UsageMap& GetCommandLineOptions() const; + + /** + * @fn void ApplicationUsage::SetCommandLineOptionsDefaults(const UsageMap& usageMap); + * + * @brief Sets command line options defaults. + * + * @param usageMap The usage map. + */ void SetCommandLineOptionsDefaults(const UsageMap& usageMap); - - /** - * @fn const UsageMap& ApplicationUsage::GetCommandLineOptionsDefaults() const; - * - * @brief Gets command line options defaults. - * - * @return The command line options defaults. - */ - const UsageMap& GetCommandLineOptionsDefaults() const; - - /** - * @fn void ApplicationUsage::AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); - * - * @brief Adds an environmental variable usage explanation. - * - * @param option The option. - * @param explanation The explanation. - * @param defaultValue (Optional) The default value. - */ - void AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); - - /** - * @fn void ApplicationUsage::SetEnvironmentalVariables(const UsageMap& usageMap); - * - * @brief Sets environmental variables usage. - * - * @param usageMap The usage map. - */ + + /** + * @fn const UsageMap& ApplicationUsage::GetCommandLineOptionsDefaults() const; + * + * @brief Gets command line options defaults. + * + * @return The command line options defaults. + */ + const UsageMap& GetCommandLineOptionsDefaults() const; + + /** + * @fn void ApplicationUsage::AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); + * + * @brief Adds an environmental variable usage explanation. + * + * @param option The option. + * @param explanation The explanation. + * @param defaultValue (Optional) The default value. + */ + void AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); + + /** + * @fn void ApplicationUsage::SetEnvironmentalVariables(const UsageMap& usageMap); + * + * @brief Sets environmental variables usage. + * + * @param usageMap The usage map. + */ void SetEnvironmentalVariables(const UsageMap& usageMap); - - /** - * @fn const UsageMap& ApplicationUsage::GetEnvironmentalVariables() const; - * - * @brief Gets environmental variables usage. - * - * @return The environmental variables. - */ - const UsageMap& GetEnvironmentalVariables() const; - - /** - * @fn void ApplicationUsage::SetEnvironmentalVariablesDefaults(const UsageMap& usageMap); - * - * @brief Sets environmental variables usage default usage map. - * - * @param usageMap The usage map. - */ + + /** + * @fn const UsageMap& ApplicationUsage::GetEnvironmentalVariables() const; + * + * @brief Gets environmental variables usage. + * + * @return The environmental variables. + */ + const UsageMap& GetEnvironmentalVariables() const; + + /** + * @fn void ApplicationUsage::SetEnvironmentalVariablesDefaults(const UsageMap& usageMap); + * + * @brief Sets environmental variables usage default usage map. + * + * @param usageMap The usage map. + */ void SetEnvironmentalVariablesDefaults(const UsageMap& usageMap); - - /** - * @fn const UsageMap& ApplicationUsage::GetEnvironmentalVariablesDefaults() const; - * - * @brief Gets environmental variables usage default usage map. - * - * @return The environmental variables defaults. - */ - const UsageMap& GetEnvironmentalVariablesDefaults() const; - - /** - * @fn void ApplicationUsage::AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param prefix The prefix. - * @param key The key. - * @param explanation The explanation. - */ + + /** + * @fn const UsageMap& ApplicationUsage::GetEnvironmentalVariablesDefaults() const; + * + * @brief Gets environmental variables usage default usage map. + * + * @return The environmental variables defaults. + */ + const UsageMap& GetEnvironmentalVariablesDefaults() const; + + /** + * @fn void ApplicationUsage::AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param prefix The prefix. + * @param key The key. + * @param explanation The explanation. + */ void AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); - - /** - * @fn void ApplicationUsage::AddKeyboardMouseBinding(int key, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param key The key. - * @param explanation The explanation. - */ + + /** + * @fn void ApplicationUsage::AddKeyboardMouseBinding(int key, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param key The key. + * @param explanation The explanation. + */ void AddKeyboardMouseBinding(int key, const std::string& explanation); - - /** - * @fn void ApplicationUsage::AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param option The option. - * @param explanation The explanation. - */ - void AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); - - /** - * @fn void ApplicationUsage::SetKeyboardMouseBindings(const UsageMap& usageMap); - * - * @brief Sets keyboard mouse bindings usage. - * - * @param usageMap The usage map. - */ + + /** + * @fn void ApplicationUsage::AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param option The option. + * @param explanation The explanation. + */ + void AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); + + /** + * @fn void ApplicationUsage::SetKeyboardMouseBindings(const UsageMap& usageMap); + * + * @brief Sets keyboard mouse bindings usage. + * + * @param usageMap The usage map. + */ void SetKeyboardMouseBindings(const UsageMap& usageMap); - - /** - * @fn const UsageMap& ApplicationUsage::GetKeyboardMouseBindings() const; - * - * @brief Gets keyboard mouse bindings usage. - * - * @return The keyboard mouse bindings. - */ - const UsageMap& GetKeyboardMouseBindings() const; - - /** - * @fn void ApplicationUsage::GetFormattedString(std::string& str, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); - * - * @brief Gets formatted string. - * - * @param [in,out] str The string. - * @param um The usage map. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - * @param ud (Optional) The usage map default. - */ - void GetFormattedString(std::string& str, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); - - /** - * @fn void ApplicationUsage::Write(std::ostream& output, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); - * - * @brief Writes out all the settings to the screen. - * - * @param [in,out] output The output stream. - * @param um The usage map. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - * @param ud (Optional) The ud. - */ + + /** + * @fn const UsageMap& ApplicationUsage::GetKeyboardMouseBindings() const; + * + * @brief Gets keyboard mouse bindings usage. + * + * @return The keyboard mouse bindings. + */ + const UsageMap& GetKeyboardMouseBindings() const; + + /** + * @fn void ApplicationUsage::GetFormattedString(std::string& str, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); + * + * @brief Gets formatted string. + * + * @param [in,out] str The string. + * @param um The usage map. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + * @param ud (Optional) The usage map default. + */ + void GetFormattedString(std::string& str, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); + + /** + * @fn void ApplicationUsage::Write(std::ostream& output, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); + * + * @brief Writes out all the settings to the screen. + * + * @param [in,out] output The output stream. + * @param um The usage map. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + * @param ud (Optional) The ud. + */ void Write(std::ostream& output, const UsageMap& um, unsigned int widthOfOutput = 80, bool showDefaults = false, const UsageMap& ud = UsageMap()); - - /** - * @fn void ApplicationUsage::Write(std::ostream& output, Type type = Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); - * - * @brief Writes. - * - * @param [in,out] output The output stream. - * @param type (Optional) The type. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - */ + + /** + * @fn void ApplicationUsage::Write(std::ostream& output, Type type = Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); + * + * @brief Writes. + * + * @param [in,out] output The output stream. + * @param type (Optional) The type. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + */ void Write(std::ostream& output, Type type = Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); - - /** - * @fn void ApplicationUsage::WriteEnvironmentSettings(std::ostream& output); - * - * @brief Writes out the environment settings. - * - * @param [in,out] output The output. - */ - void WriteEnvironmentSettings(std::ostream& output); - - /** - * @fn operator osg::ApplicationUsage& (); - * - * @brief Implicit conversion operator to OSG ApplicationUsage. - * - * @return The result of the operation. - */ - operator osg::ApplicationUsage& (); - - /** - * @fn operator const osg::ApplicationUsage& () const; - * - * @brief Implicit conversion operator to OSG ApplicationUsage. - * - * @return A const. - */ - operator const osg::ApplicationUsage& () const; - - /** - * @fn operator osg::ApplicationUsage* (); - * - * @brief Implicit conversion operator to OSG ApplicationUsage. - * - * @return The result of the operation. - */ - operator osg::ApplicationUsage* (); - - /** - * @fn operator osg::ApplicationUsage* (); - * - * @brief Implicit conversion operator to OSG ApplicationUsage. - * - * @return The result of the operation. - */ - operator const osg::ApplicationUsage* () const; - - protected: - osg::ref_ptr mAppUsage = nullptr; - }; -} - - + + /** + * @fn void ApplicationUsage::WriteEnvironmentSettings(std::ostream& output); + * + * @brief Writes out the environment settings. + * + * @param [in,out] output The output. + */ + void WriteEnvironmentSettings(std::ostream& output); + + /** + * @fn operator osg::ApplicationUsage& (); + * + * @brief Implicit conversion operator to OSG ApplicationUsage. + * + * @return The result of the operation. + */ + operator osg::ApplicationUsage& (); + + /** + * @fn operator const osg::ApplicationUsage& () const; + * + * @brief Implicit conversion operator to OSG ApplicationUsage. + * + * @return A const. + */ + operator const osg::ApplicationUsage& () const; + + /** + * @fn operator osg::ApplicationUsage* (); + * + * @brief Implicit conversion operator to OSG ApplicationUsage. + * + * @return The result of the operation. + */ + operator osg::ApplicationUsage* (); + + /** + * @fn operator osg::ApplicationUsage* (); + * + * @brief Implicit conversion operator to OSG ApplicationUsage. + * + * @return The result of the operation. + */ + operator const osg::ApplicationUsage* () const; + + protected: + osg::ref_ptr mAppUsage = nullptr; + }; +} + + diff --git a/include/trUtil/ArgumentParser.h b/include/trUtil/ArgumentParser.h index df961c6..2d51816 100644 --- a/include/trUtil/ArgumentParser.h +++ b/include/trUtil/ArgumentParser.h @@ -1,1032 +1,1032 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include -#include - -#include -#include - -/** - * @namespace trUtil - * - * @brief Namespace that holds various utility classes for the engine - */ -namespace trUtil -{ - /** - * @class ArgumentParser - * - * @brief A a command line argument parser class that helps to create, manage, and pass commands to other systems - */ - class TR_UTIL_EXPORT ArgumentParser - { - public: - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include +#include + +#include +#include + +/** + * @namespace trUtil + * + * @brief Namespace that holds various utility classes for the engine + */ +namespace trUtil +{ + /** + * @class ArgumentParser + * + * @brief A a command line argument parser class that helps to create, manage, and pass commands to other systems + */ + class TR_UTIL_EXPORT ArgumentParser + { + public: + enum class ErrorSeverity { BENIGN = osg::ArgumentParser::ErrorSeverity::BENIGN, CRITICAL = osg::ArgumentParser::ErrorSeverity::CRITICAL - }; - - using ErrorMessageMap = std::map; - + }; + + using ErrorMessageMap = std::map; + class TR_UTIL_EXPORT Parameter { public: - - /** - * @fn Parameter::Parameter(bool& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(bool& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(bool& value); - - /** - * @fn Parameter::Parameter(float& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(float& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(float& value); - - /** - * @fn Parameter::Parameter(double& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(double& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(double& value); - - /** - * @fn Parameter::Parameter(int& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(int& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(int& value); - - /** - * @fn Parameter::Parameter(unsigned int& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(unsigned int& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(unsigned int& value); - - /** - * @fn Parameter::Parameter(std::string& value); - * - * @brief Constructor. - * - * @param [in,out] value The value. - */ + + /** + * @fn Parameter::Parameter(std::string& value); + * + * @brief Constructor. + * + * @param [in,out] value The value. + */ Parameter(std::string& value); - - /** - * @fn Parameter::Parameter(const Parameter& param); - * - * @brief Copy constructor. - * - * @param param The parameter. - */ + + /** + * @fn Parameter::Parameter(const Parameter& param); + * + * @brief Copy constructor. + * + * @param param The parameter. + */ Parameter(const Parameter& param); - - /** - * @fn Parameter::~Parameter(); - * - * @brief Destructor. - */ + + /** + * @fn Parameter::~Parameter(); + * + * @brief Destructor. + */ ~Parameter(); - - /** - * @fn Parameter& Parameter::operator= (const Parameter& param); - * - * @brief Assignment operator. - * - * @param param The parameter. - * - * @return A shallow copy of this object. - */ + + /** + * @fn Parameter& Parameter::operator= (const Parameter& param); + * + * @brief Assignment operator. + * + * @param param The parameter. + * + * @return A shallow copy of this object. + */ Parameter& operator = (const Parameter& param); - - /** - * @fn bool Parameter::Valid(const char* str) const; - * - * @brief Checks if this parameter is Valid. - * - * @param str The string. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool Parameter::Valid(const char* str) const; + * + * @brief Checks if this parameter is Valid. + * + * @param str The string. + * + * @return True if it succeeds, false if it fails. + */ bool Valid(const char* str) const; - - /** - * @fn bool Parameter::Assign(const char* str); - * - * @brief Assigns the given string value to the parameter. - * - * @param str The string. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool Parameter::Assign(const char* str); + * + * @brief Assigns the given string value to the parameter. + * + * @param str The string. + * + * @return True if it succeeds, false if it fails. + */ bool Assign(const char* str); - - /** - * @fn operator osg::ArgumentParser::Parameter () const; - * - * @brief Cast that converts the given to a Parameter. - * - * @return The result of the operation. - */ + + /** + * @fn operator osg::ArgumentParser::Parameter () const; + * + * @brief Cast that converts the given to a Parameter. + * + * @return The result of the operation. + */ operator osg::ArgumentParser::Parameter() const; - - /** - * @fn operator osg::ArgumentParser::Parameter& (); - * - * @brief Cast that converts the given to a Parameter& - * - * @return The result of the operation. - */ + + /** + * @fn operator osg::ArgumentParser::Parameter& (); + * + * @brief Cast that converts the given to a Parameter& + * + * @return The result of the operation. + */ operator osg::ArgumentParser::Parameter& (); - - /** - * @fn operator const osg::ArgumentParser::Parameter& () const; - * - * @brief Gets the parameter& - * - * @return A const. - */ + + /** + * @fn operator const osg::ArgumentParser::Parameter& () const; + * + * @brief Gets the parameter& + * + * @return A const. + */ operator const osg::ArgumentParser::Parameter& () const; - - /** - * @fn operator osg::ArgumentParser::Parameter* (); - * - * @brief Parameter* casting operator. - * - * @return The result of the operation. - */ + + /** + * @fn operator osg::ArgumentParser::Parameter* (); + * + * @brief Parameter* casting operator. + * + * @return The result of the operation. + */ operator osg::ArgumentParser::Parameter* (); protected: osg::ArgumentParser::Parameter* mParam; - }; - - /** - * @fn ArgumentParser::ArgumentParser(int* argc, char **argv); - * - * @brief Default constructor that takes the argc and argv from the main function for command line parsing. - * - * @param [in,out] argc If non-null, the argc. - * @param [in,out] argv If non-null, the argv. - */ - ArgumentParser(int* argc, char **argv); - - /** - * @fn ArgumentParser::~ArgumentParser(); - * - * @brief Destructor. - */ + }; + + /** + * @fn ArgumentParser::ArgumentParser(int* argc, char **argv); + * + * @brief Default constructor that takes the argc and argv from the main function for command line parsing. + * + * @param [in,out] argc If non-null, the argc. + * @param [in,out] argv If non-null, the argv. + */ + ArgumentParser(int* argc, char **argv); + + /** + * @fn ArgumentParser::~ArgumentParser(); + * + * @brief Destructor. + */ ~ArgumentParser(); - - /** - * @fn osg::ArgumentParser& ArgumentParser::GetOSGArgumentParser(); - * - * @brief Gets internal osg argument parser. - * - * @return The osg argument parser. - */ + + /** + * @fn osg::ArgumentParser& ArgumentParser::GetOSGArgumentParser(); + * + * @brief Gets internal osg argument parser. + * + * @return The osg argument parser. + */ osg::ArgumentParser& GetOSGArgumentParser(); - - /** - * @fn const osg::ArgumentParser& ArgumentParser::GetOSGArgumentParser() const; - * - * @brief Gets the internal osg argument parser. - * - * @return The osg argument parser. - */ + + /** + * @fn const osg::ArgumentParser& ArgumentParser::GetOSGArgumentParser() const; + * + * @brief Gets the internal osg argument parser. + * + * @return The osg argument parser. + */ const osg::ArgumentParser& GetOSGArgumentParser() const; - - /** - * @fn bool ArgumentParser::IsOption(const char* str) const; - * - * @brief Return true if the specified string is an option in the form - * -option or --option. - * - * @param str The string. - * - * @return True if option, false if not. - */ - bool IsOption(const char* str) const; - - /** - * @fn bool ArgumentParser::IsString(const char* str) const; - * - * @brief Return true if string is non-NULL and not an option in the form - * -option or --option. - * - * @param str The string. - * - * @return True if string, false if not. - */ - bool IsString(const char* str) const; - - /** - * @fn bool ArgumentParser::IsNumber(const char* str) const; - * - * @brief Return true if specified parameter is a number. - * - * @param str The string. - * - * @return True if number, false if not. - */ + + /** + * @fn bool ArgumentParser::IsOption(const char* str) const; + * + * @brief Return true if the specified string is an option in the form + * -option or --option. + * + * @param str The string. + * + * @return True if option, false if not. + */ + bool IsOption(const char* str) const; + + /** + * @fn bool ArgumentParser::IsString(const char* str) const; + * + * @brief Return true if string is non-NULL and not an option in the form + * -option or --option. + * + * @param str The string. + * + * @return True if string, false if not. + */ + bool IsString(const char* str) const; + + /** + * @fn bool ArgumentParser::IsNumber(const char* str) const; + * + * @brief Return true if specified parameter is a number. + * + * @param str The string. + * + * @return True if number, false if not. + */ bool IsNumber(const char* str) const; - - /** - * @fn bool ArgumentParser::IsBool(const char* str) const; - * - * @brief Return true if specified parameter is a bool. - * - * @param str The string. - * - * @return True if bool, false if not. - */ - bool IsBool(const char* str) const; - - /** - * @fn void ArgumentParser::SetApplicationUsage(ApplicationUsage* usage); - * - * @brief Sets application usage. - * - * @param [in,out] usage If non-null, the usage. - */ + + /** + * @fn bool ArgumentParser::IsBool(const char* str) const; + * + * @brief Return true if specified parameter is a bool. + * + * @param str The string. + * + * @return True if bool, false if not. + */ + bool IsBool(const char* str) const; + + /** + * @fn void ArgumentParser::SetApplicationUsage(ApplicationUsage* usage); + * + * @brief Sets application usage. + * + * @param [in,out] usage If non-null, the usage. + */ void SetApplicationUsage(ApplicationUsage* usage); - - /** - * @fn ApplicationUsage* ArgumentParser::GetApplicationUsage(); - * - * @brief Gets application usage. - * - * @return Null if it fails, else a pointer to an ApplicationUsage. - */ + + /** + * @fn ApplicationUsage* ArgumentParser::GetApplicationUsage(); + * + * @brief Gets application usage. + * + * @return Null if it fails, else a pointer to an ApplicationUsage. + */ ApplicationUsage* GetApplicationUsage(); - - /** - * @fn const ApplicationUsage* ArgumentParser::GetApplicationUsage() const; - * - * @brief Gets application usage. - * - * @return Null if it fails, else the application usage. - */ - const ApplicationUsage* GetApplicationUsage() const; - - /** - * @fn int& ArgumentParser::GetArgc(); - * - * @brief Return the argument count. - * - * @return The argc. - */ + + /** + * @fn const ApplicationUsage* ArgumentParser::GetApplicationUsage() const; + * + * @brief Gets application usage. + * + * @return Null if it fails, else the application usage. + */ + const ApplicationUsage* GetApplicationUsage() const; + + /** + * @fn int& ArgumentParser::GetArgc(); + * + * @brief Return the argument count. + * + * @return The argc. + */ int& GetArgc(); - - /** - * @fn char** ArgumentParser::GetArgv(); - * - * @brief Return the argument array. - * - * @return Null if it fails, else the argv. - */ - char** GetArgv(); - - /** - * @fn std::string ArgumentParser::GetApplicationName() const; - * - * @brief Return the application name, as specified by argv[0]. - * - * @return The application name. - */ + + /** + * @fn char** ArgumentParser::GetArgv(); + * + * @brief Return the argument array. + * + * @return Null if it fails, else the argv. + */ + char** GetArgv(); + + /** + * @fn std::string ArgumentParser::GetApplicationName() const; + * + * @brief Return the application name, as specified by argv[0]. + * + * @return The application name. + */ std::string GetApplicationName() const; - - /** - * @fn int ArgumentParser::Find(const std::string& str) const; - * - * @brief Return the position of an occurrence of a string in the argument list. Return -1 if - * no string is found. - * - * @param str The string. - * - * @return An int. - */ + + /** + * @fn int ArgumentParser::Find(const std::string& str) const; + * + * @brief Return the position of an occurrence of a string in the argument list. Return -1 if + * no string is found. + * + * @param str The string. + * + * @return An int. + */ int Find(const std::string& str) const; - - /** - * @fn bool ArgumentParser::IsOption(int pos) const; - * - * @brief Return true if the specified parameter is an option in the form of - * -option or --option. - * - * @param pos The position. - * - * @return True if option, false if not. - */ + + /** + * @fn bool ArgumentParser::IsOption(int pos) const; + * + * @brief Return true if the specified parameter is an option in the form of + * -option or --option. + * + * @param pos The position. + * + * @return True if option, false if not. + */ bool IsOption(int pos) const; - - /** - * @fn bool ArgumentParser::IsString(int pos) const; - * - * @brief Return true if the specified parameter is a string not in the form of an option. - * - * @param pos The position. - * - * @return True if string, false if not. - */ - bool IsString(int pos) const; - - /** - * @fn bool ArgumentParser::IsNumber(int pos) const; - * - * @brief Return true if the specified parameter is a number. - * - * @param pos The position. - * - * @return True if number, false if not. - */ + + /** + * @fn bool ArgumentParser::IsString(int pos) const; + * + * @brief Return true if the specified parameter is a string not in the form of an option. + * + * @param pos The position. + * + * @return True if string, false if not. + */ + bool IsString(int pos) const; + + /** + * @fn bool ArgumentParser::IsNumber(int pos) const; + * + * @brief Return true if the specified parameter is a number. + * + * @param pos The position. + * + * @return True if number, false if not. + */ bool IsNumber(int pos) const; - - /** - * @fn bool ArgumentParser::ContainsOptions() const; - * - * @brief Query if this object contains options. - * - * @return True if it succeeds, false if it fails. - */ - bool ContainsOptions() const; - - /** - * @fn void ArgumentParser::Remove(int pos, int num = 1); - * - * @brief Remove one or more arguments from the argv argument list, and decrement the argc - * respectively. - * - * @param pos The position. - * @param num (Optional) Number of. - */ + + /** + * @fn bool ArgumentParser::ContainsOptions() const; + * + * @brief Query if this object contains options. + * + * @return True if it succeeds, false if it fails. + */ + bool ContainsOptions() const; + + /** + * @fn void ArgumentParser::Remove(int pos, int num = 1); + * + * @brief Remove one or more arguments from the argv argument list, and decrement the argc + * respectively. + * + * @param pos The position. + * @param num (Optional) Number of. + */ void Remove(int pos, int num = 1); - - /** - * @fn bool ArgumentParser::Match(int pos, const std::string& str) const; - * - * @brief Return true if the specified argument matches the given string. - * - * @param pos The position. - * @param str The string. - * - * @return True if it succeeds, false if it fails. - */ - bool Match(int pos, const std::string& str) const; - - /** - * @fn bool ArgumentParser::Read(const std::string& str); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Match(int pos, const std::string& str) const; + * + * @brief Return true if the specified argument matches the given string. + * + * @param pos The position. + * @param str The string. + * + * @return True if it succeeds, false if it fails. + */ + bool Match(int pos, const std::string& str) const; + + /** + * @fn bool ArgumentParser::Read(const std::string& str); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The value 6. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The value 6. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The value 6. - * @param value7 The value 7. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The value 6. + * @param value7 The value 7. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); - - /** - * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); - * - * @brief Search for an occurrence of a string in the argument list. If found, - * remove that occurrence and return true. Otherwise, return false. - * - * @param str The String to read. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The value 6. - * @param value7 The value 7. - * @param value8 The value 8. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); + * + * @brief Search for an occurrence of a string in the argument list. If found, + * remove that occurrence and return true. Otherwise, return false. + * + * @param str The String to read. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The value 6. + * @param value7 The value 7. + * @param value8 The value 8. + * + * @return True if it succeeds, false if it fails. + */ bool Read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The sixth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The sixth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The sixth value. - * @param value7 The seventh value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The sixth value. + * @param value7 The seventh value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7); - - /** - * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); - * - * @brief If the argument value at the specified position matches the given string, and - * subsequent parameters are also matched, then set the parameter values, remove the - * arguments from the list, and return true. Otherwise, return false. - * - * @param pos The position. - * @param str The string. - * @param value1 The first value. - * @param value2 The second value. - * @param value3 The third value. - * @param value4 The fourth value. - * @param value5 The fifth value. - * @param value6 The sixth value. - * @param value7 The seventh value. - * @param value8 The eighth value. - * - * @return True if it succeeds, false if it fails. - */ + + /** + * @fn bool ArgumentParser::Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); + * + * @brief If the argument value at the specified position matches the given string, and + * subsequent parameters are also matched, then set the parameter values, remove the + * arguments from the list, and return true. Otherwise, return false. + * + * @param pos The position. + * @param str The string. + * @param value1 The first value. + * @param value2 The second value. + * @param value3 The third value. + * @param value4 The fourth value. + * @param value5 The fifth value. + * @param value6 The sixth value. + * @param value7 The seventh value. + * @param value8 The eighth value. + * + * @return True if it succeeds, false if it fails. + */ bool Read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8); - - /** - * @fn bool ArgumentParser::Errors(ErrorSeverity severity = BENIGN) const; - * - * @brief Return the error flag, true if an error has occurred when reading arguments. - * - * @param severity (Optional) The severity. - * - * @return True if it succeeds, false if it fails. - */ - bool Errors(ErrorSeverity severity = ErrorSeverity::BENIGN) const; - - /** - * @fn void ArgumentParser::ReportError(const std::string& message, ErrorSeverity severity = ErrorSeverity::CRITICAL); - * - * @brief Report an error message by adding to the ErrorMessageMap. - * - * @param message The message. - * @param severity (Optional) The severity. - */ - void ReportError(const std::string& message, ErrorSeverity severity = ErrorSeverity::CRITICAL); - - /** - * @fn void ArgumentParser::ReportRemainingOptionsAsUnrecognized(ErrorSeverity severity = ErrorSeverity::BENIGN); - * - * @brief For each remaining option, report it as unrecognized. - * - * @param severity (Optional) The severity. - */ - void ReportRemainingOptionsAsUnrecognized(ErrorSeverity severity = ErrorSeverity::BENIGN); - - /** - * @fn void ArgumentParser::WriteErrorMessages(std::ostream& output, ErrorSeverity severity = ErrorSeverity::BENIGN); - * - * @brief Write error messages to the given ostream, if at or above the given severity. - * - * @param [in,out] output The output. - * @param severity (Optional) The severity. - */ - void WriteErrorMessages(std::ostream& output, ErrorSeverity severity = ErrorSeverity::BENIGN); - - /** - * @fn ApplicationUsage::Type ArgumentParser::ReadHelpType(); - * - * @brief This convenience method handles help requests on the command line. Return the type(s) - * of help requested. The return value of this function is suitable for passing into - * getApplicationUsage()->write(). If ApplicationUsage::NO_HELP is returned then no help - * commandline option was found on the command line. - * - * @return The help type. - */ - ApplicationUsage::Type ReadHelpType(); - - /** - * @fn void ArgumentParser::SetApplicationName(const std::string& name); - * - * @brief Sets the Applications Name. It is used in Application description. - * - * @param name The name. - */ - void SetApplicationName(const std::string& name); - - /** - * @fn void ArgumentParser::SetDescription(const std::string& desc); - * - * @brief If non-empty, the Description is typically shown by the Help Handler as text on the - * Help display (which also lists keyboard abbreviations.) - * - * @param desc The description. - */ - void SetDescription(const std::string& desc); - - /** - * @fn const std::string& ArgumentParser::GetDescription() const; - * - * @brief Gets the description. - * - * @return The description. - */ - const std::string& GetDescription() const; - - /** - * @fn void ArgumentParser::AddUsageExplanation(ApplicationUsage::Type type, const std::string& option, const std::string& explanation); - * - * @brief Adds an usage explanation. - * - * @param type The type. - * @param option The option. - * @param explanation The explanation. - */ - void AddUsageExplanation(ApplicationUsage::Type type, const std::string& option, const std::string& explanation); - - /** - * @fn void ArgumentParser::SetCommandLineUsage(const std::string& explanation); - * - * @brief Sets command line usage. - * - * @param explanation The explanation. - */ - void SetCommandLineUsage(const std::string& explanation); - - /** - * @fn const std::string& ArgumentParser::GetCommandLineUsage() const; - * - * @brief Gets command line usage. - * - * @return The command line usage. - */ - const std::string& GetCommandLineUsage() const; - - /** - * @fn void ArgumentParser::AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); - * - * @brief Adds a command line option. - * - * @param option The option. - * @param explanation The explanation. - * @param defaultValue (Optional) The default value. - */ - void AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); - - /** - * @fn void ArgumentParser::SetCommandLineOptions(const ApplicationUsage::UsageMap& usageMap); - * - * @brief Sets command line options. - * - * @param usageMap The usage map. - */ - void SetCommandLineOptions(const ApplicationUsage::UsageMap& usageMap); - - /** - * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetCommandLineOptions() const; - * - * @brief Gets command line options. - * - * @return The command line options. - */ - const ApplicationUsage::UsageMap& GetCommandLineOptions() const; - - /** - * @fn void ArgumentParser::SetCommandLineOptionsDefaults(const ApplicationUsage::UsageMap& usageMap); - * - * @brief Sets command line options defaults. - * - * @param usageMap The usage map. - */ - void SetCommandLineOptionsDefaults(const ApplicationUsage::UsageMap& usageMap); - - /** - * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetCommandLineOptionsDefaults() const; - * - * @brief Gets command line options defaults. - * - * @return The command line options defaults. - */ - const ApplicationUsage::UsageMap& GetCommandLineOptionsDefaults() const; - - /** - * @fn void ArgumentParser::AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); - * - * @brief Adds an environmental variable usage explanation. - * - * @param option The option. - * @param explanation The explanation. - * @param defaultValue (Optional) The default value. - */ - void AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); - - /** - * @fn void ArgumentParser::SetEnvironmentalVariables(const ApplicationUsage::UsageMap& usageMap); - * - * @brief Sets environmental variables usage. - * - * @param usageMap The usage map. - */ + + /** + * @fn bool ArgumentParser::Errors(ErrorSeverity severity = BENIGN) const; + * + * @brief Return the error flag, true if an error has occurred when reading arguments. + * + * @param severity (Optional) The severity. + * + * @return True if it succeeds, false if it fails. + */ + bool Errors(ErrorSeverity severity = ErrorSeverity::BENIGN) const; + + /** + * @fn void ArgumentParser::ReportError(const std::string& message, ErrorSeverity severity = ErrorSeverity::CRITICAL); + * + * @brief Report an error message by adding to the ErrorMessageMap. + * + * @param message The message. + * @param severity (Optional) The severity. + */ + void ReportError(const std::string& message, ErrorSeverity severity = ErrorSeverity::CRITICAL); + + /** + * @fn void ArgumentParser::ReportRemainingOptionsAsUnrecognized(ErrorSeverity severity = ErrorSeverity::BENIGN); + * + * @brief For each remaining option, report it as unrecognized. + * + * @param severity (Optional) The severity. + */ + void ReportRemainingOptionsAsUnrecognized(ErrorSeverity severity = ErrorSeverity::BENIGN); + + /** + * @fn void ArgumentParser::WriteErrorMessages(std::ostream& output, ErrorSeverity severity = ErrorSeverity::BENIGN); + * + * @brief Write error messages to the given ostream, if at or above the given severity. + * + * @param [in,out] output The output. + * @param severity (Optional) The severity. + */ + void WriteErrorMessages(std::ostream& output, ErrorSeverity severity = ErrorSeverity::BENIGN); + + /** + * @fn ApplicationUsage::Type ArgumentParser::ReadHelpType(); + * + * @brief This convenience method handles help requests on the command line. Return the type(s) + * of help requested. The return value of this function is suitable for passing into + * getApplicationUsage()->write(). If ApplicationUsage::NO_HELP is returned then no help + * commandline option was found on the command line. + * + * @return The help type. + */ + ApplicationUsage::Type ReadHelpType(); + + /** + * @fn void ArgumentParser::SetApplicationName(const std::string& name); + * + * @brief Sets the Applications Name. It is used in Application description. + * + * @param name The name. + */ + void SetApplicationName(const std::string& name); + + /** + * @fn void ArgumentParser::SetDescription(const std::string& desc); + * + * @brief If non-empty, the Description is typically shown by the Help Handler as text on the + * Help display (which also lists keyboard abbreviations.) + * + * @param desc The description. + */ + void SetDescription(const std::string& desc); + + /** + * @fn const std::string& ArgumentParser::GetDescription() const; + * + * @brief Gets the description. + * + * @return The description. + */ + const std::string& GetDescription() const; + + /** + * @fn void ArgumentParser::AddUsageExplanation(ApplicationUsage::Type type, const std::string& option, const std::string& explanation); + * + * @brief Adds an usage explanation. + * + * @param type The type. + * @param option The option. + * @param explanation The explanation. + */ + void AddUsageExplanation(ApplicationUsage::Type type, const std::string& option, const std::string& explanation); + + /** + * @fn void ArgumentParser::SetCommandLineUsage(const std::string& explanation); + * + * @brief Sets command line usage. + * + * @param explanation The explanation. + */ + void SetCommandLineUsage(const std::string& explanation); + + /** + * @fn const std::string& ArgumentParser::GetCommandLineUsage() const; + * + * @brief Gets command line usage. + * + * @return The command line usage. + */ + const std::string& GetCommandLineUsage() const; + + /** + * @fn void ArgumentParser::AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); + * + * @brief Adds a command line option. + * + * @param option The option. + * @param explanation The explanation. + * @param defaultValue (Optional) The default value. + */ + void AddCommandLineOption(const std::string& option, const std::string& explanation, const std::string &defaultValue = ""); + + /** + * @fn void ArgumentParser::SetCommandLineOptions(const ApplicationUsage::UsageMap& usageMap); + * + * @brief Sets command line options. + * + * @param usageMap The usage map. + */ + void SetCommandLineOptions(const ApplicationUsage::UsageMap& usageMap); + + /** + * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetCommandLineOptions() const; + * + * @brief Gets command line options. + * + * @return The command line options. + */ + const ApplicationUsage::UsageMap& GetCommandLineOptions() const; + + /** + * @fn void ArgumentParser::SetCommandLineOptionsDefaults(const ApplicationUsage::UsageMap& usageMap); + * + * @brief Sets command line options defaults. + * + * @param usageMap The usage map. + */ + void SetCommandLineOptionsDefaults(const ApplicationUsage::UsageMap& usageMap); + + /** + * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetCommandLineOptionsDefaults() const; + * + * @brief Gets command line options defaults. + * + * @return The command line options defaults. + */ + const ApplicationUsage::UsageMap& GetCommandLineOptionsDefaults() const; + + /** + * @fn void ArgumentParser::AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); + * + * @brief Adds an environmental variable usage explanation. + * + * @param option The option. + * @param explanation The explanation. + * @param defaultValue (Optional) The default value. + */ + void AddEnvironmentalVariable(const std::string& option, const std::string& explanation, const std::string& defaultValue = ""); + + /** + * @fn void ArgumentParser::SetEnvironmentalVariables(const ApplicationUsage::UsageMap& usageMap); + * + * @brief Sets environmental variables usage. + * + * @param usageMap The usage map. + */ void SetEnvironmentalVariables(const ApplicationUsage::UsageMap& usageMap); - - /** - * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetEnvironmentalVariables() const; - * - * @brief Gets environmental variables usage. - * - * @return The environmental variables. - */ - const ApplicationUsage::UsageMap& GetEnvironmentalVariables() const; - - /** - * @fn void ArgumentParser::SetEnvironmentalVariablesDefaults(const ApplicationUsage::UsageMap& usageMap); - * - * @brief Sets environmental variables usage default usage map. - * - * @param usageMap The usage map. - */ + + /** + * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetEnvironmentalVariables() const; + * + * @brief Gets environmental variables usage. + * + * @return The environmental variables. + */ + const ApplicationUsage::UsageMap& GetEnvironmentalVariables() const; + + /** + * @fn void ArgumentParser::SetEnvironmentalVariablesDefaults(const ApplicationUsage::UsageMap& usageMap); + * + * @brief Sets environmental variables usage default usage map. + * + * @param usageMap The usage map. + */ void SetEnvironmentalVariablesDefaults(const ApplicationUsage::UsageMap& usageMap); - - /** - * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetEnvironmentalVariablesDefaults() const; - * - * @brief Gets environmental variables usage default usage map. - * - * @return The environmental variables defaults. - */ - const ApplicationUsage::UsageMap& GetEnvironmentalVariablesDefaults() const; - - /** - * @fn void ArgumentParser::AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param prefix The prefix. - * @param key The key. - * @param explanation The explanation. - */ + + /** + * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetEnvironmentalVariablesDefaults() const; + * + * @brief Gets environmental variables usage default usage map. + * + * @return The environmental variables defaults. + */ + const ApplicationUsage::UsageMap& GetEnvironmentalVariablesDefaults() const; + + /** + * @fn void ArgumentParser::AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param prefix The prefix. + * @param key The key. + * @param explanation The explanation. + */ void AddKeyboardMouseBinding(const std::string& prefix, int key, const std::string& explanation); - - /** - * @fn void ApplicationUsage::AddKeyboardMouseBinding(int key, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param key The key. - * @param explanation The explanation. - */ - void AddKeyboardMouseBinding(int key, const std::string& explanation); - - /** - * @fn void ArgumentParser::AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); - * - * @brief Adds a keyboard mouse binding usage. - * - * @param option The option. - * @param explanation The explanation. - */ - void AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); - - /** - * @fn void ArgumentParser::SetKeyboardMouseBindings(const ApplicationUsage::UsageMap& usageMap); - * - * @brief Sets keyboard mouse bindings usage. - * - * @param usageMap The usage map. - */ - void SetKeyboardMouseBindings(const ApplicationUsage::UsageMap& usageMap); - - /** - * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetKeyboardMouseBindings() const; - * - * @brief Gets keyboard mouse bindings usage. - * - * @return The keyboard mouse bindings. - */ - const ApplicationUsage::UsageMap& GetKeyboardMouseBindings() const; - - /** - * @fn void ArgumentParser::GetFormattedString(std::string& str, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); - * - * @brief Gets formatted string. - * - * @param [in,out] str The string. - * @param usageMap The usage map. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - * @param usageMapDef (Optional) The usage map default. - */ - void GetFormattedString(std::string& str, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); - - /** - * @fn void ArgumentParser::Write(std::ostream& output, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); - * - * @brief Writes out all the settings to the screen. - * - * @param [in,out] output The output stream. - * @param usageMap The usage map. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - * @param usageMapDef (Optional) The ud. - */ + + /** + * @fn void ApplicationUsage::AddKeyboardMouseBinding(int key, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param key The key. + * @param explanation The explanation. + */ + void AddKeyboardMouseBinding(int key, const std::string& explanation); + + /** + * @fn void ArgumentParser::AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); + * + * @brief Adds a keyboard mouse binding usage. + * + * @param option The option. + * @param explanation The explanation. + */ + void AddKeyboardMouseBinding(const std::string& option, const std::string& explanation); + + /** + * @fn void ArgumentParser::SetKeyboardMouseBindings(const ApplicationUsage::UsageMap& usageMap); + * + * @brief Sets keyboard mouse bindings usage. + * + * @param usageMap The usage map. + */ + void SetKeyboardMouseBindings(const ApplicationUsage::UsageMap& usageMap); + + /** + * @fn const ApplicationUsage::UsageMap& ArgumentParser::GetKeyboardMouseBindings() const; + * + * @brief Gets keyboard mouse bindings usage. + * + * @return The keyboard mouse bindings. + */ + const ApplicationUsage::UsageMap& GetKeyboardMouseBindings() const; + + /** + * @fn void ArgumentParser::GetFormattedString(std::string& str, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); + * + * @brief Gets formatted string. + * + * @param [in,out] str The string. + * @param usageMap The usage map. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + * @param usageMapDef (Optional) The usage map default. + */ + void GetFormattedString(std::string& str, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); + + /** + * @fn void ArgumentParser::Write(std::ostream& output, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); + * + * @brief Writes out all the settings to the screen. + * + * @param [in,out] output The output stream. + * @param usageMap The usage map. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + * @param usageMapDef (Optional) The ud. + */ void Write(std::ostream& output, const ApplicationUsage::UsageMap& usageMap, unsigned int widthOfOutput = 80, bool showDefaults = false, const ApplicationUsage::UsageMap& usageMapDef = ApplicationUsage::UsageMap()); - - /** - * @fn void ArgumentParser::Write(std::ostream& output, ApplicationUsage::Type type = ApplicationUsage::Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); - * - * @brief Writes. - * - * @param [in,out] output The output stream. - * @param type (Optional) The type. - * @param widthOfOutput (Optional) Width of the output. - * @param showDefaults (Optional) True to show, false to hide the defaults. - */ + + /** + * @fn void ArgumentParser::Write(std::ostream& output, ApplicationUsage::Type type = ApplicationUsage::Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); + * + * @brief Writes. + * + * @param [in,out] output The output stream. + * @param type (Optional) The type. + * @param widthOfOutput (Optional) Width of the output. + * @param showDefaults (Optional) True to show, false to hide the defaults. + */ void Write(std::ostream& output, ApplicationUsage::Type type = ApplicationUsage::Type::COMMAND_LINE_OPTION, unsigned int widthOfOutput = 80, bool showDefaults = false); - - /** - * @fn void ArgumentParser::WriteEnvironmentSettings(std::ostream& output); - * - * @brief Writes out the environment settings. - * - * @param [in,out] output The output. - */ - void WriteEnvironmentSettings(std::ostream& output); - - protected: - - /** @brief The argument parser. */ - std::unique_ptr mArgParser; - std::unique_ptr mAppUsage; - }; + + /** + * @fn void ArgumentParser::WriteEnvironmentSettings(std::ostream& output); + * + * @brief Writes out the environment settings. + * + * @param [in,out] output The output. + */ + void WriteEnvironmentSettings(std::ostream& output); + + protected: + + /** @brief The argument parser. */ + std::unique_ptr mArgParser; + std::unique_ptr mAppUsage; + }; } \ No newline at end of file diff --git a/include/trUtil/Bits.h b/include/trUtil/Bits.h index a51925a..8f7e5e6 100644 --- a/include/trUtil/Bits.h +++ b/include/trUtil/Bits.h @@ -1,128 +1,128 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Erik Johnson 06/06/2006 -* -* Bits is a derivation from the Bits.h file of the CADKit project, Usul: -* @author Perry L. Miller IV -* http://cadkit.sourceforge.net/ -* -* @author Maxim Serebrennik -*/ -#pragma once -#include "Export.h" - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Bits -{ - /** - * @fn template < class N, class B > inline bool Has(N number, B bits) - * - * @brief See if the "bits" are in "number". - * @code - * unsigned int accum = 3; - * Bits::Has( accum, 1 ); //true - * Bits::Has( accum, 7 ); //false - * @endcode. - * - * @tparam N Type of the n. - * @tparam B Type of the b. - * @param number Number of. - * @param bits The bits. - * - * @return True if it succeeds, false if it fails. - */ - template < class N, class B > inline bool Has(N number, B bits) - { - return ((number & bits) == (static_cast(bits))); - } - - /** - * @fn template < class N, class B > inline N Add(N number, B bits) - * - * @brief Add the "bits" to "number". - * @code - * unsigned int accum = 1; - * accum = Bits::Add(accum, 7); //Has(accum, 1) and Has(accum, 7) == true - * @endcode. - * - * @tparam N Type of the n. - * @tparam B Type of the b. - * @param number Number of. - * @param bits The bits. - * - * @return A N. - */ - template < class N, class B > inline N Add(N number, B bits) - { - return (number | bits); - } - - /** - * @fn template < class N, class B > inline N Remove(N number, B bits) - * - * @brief Remove the "bits" from "number". - * @code - * unsigned int accum = 3; - * accum = Bits::Remove(accum, 2); //Has(accum,3) == false, Has(accum,1) == true - * @endcode. - * - * @tparam N Type of the n. - * @tparam B Type of the b. - * @param number Number of. - * @param bits The bits. - * - * @return A N. - */ - template < class N, class B > inline N Remove(N number, B bits) - { - return ((number & bits) ? (number ^ bits) : number); - } - - /** - * @fn template < class N, class B > inline N Toggle(N number, B bits) - * - * @brief Toggle the "bits" in "number". - * @code - * unsigned int accum = 3; - * unsigned int newBits; - * newBits = Bits::Toggle(accum, 1); //newBits = 2 - * newBits = Bits::Toggle(accum, 1); //newBits = 3 - * @endcode. - * - * @tparam N Type of the n. - * @tparam B Type of the b. - * @param number Number of. - * @param bits The bits. - * - * @return A N. - */ - template < class N, class B > inline N Toggle(N number, B bits) - { - return (number ^ bits); - } +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Erik Johnson 06/06/2006 +* +* Bits is a derivation from the Bits.h file of the CADKit project, Usul: +* @author Perry L. Miller IV +* http://cadkit.sourceforge.net/ +* +* @author Maxim Serebrennik +*/ +#pragma once +#include "Export.h" + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Bits +{ + /** + * @fn template < class N, class B > inline bool Has(N number, B bits) + * + * @brief See if the "bits" are in "number". + * @code + * unsigned int accum = 3; + * Bits::Has( accum, 1 ); //true + * Bits::Has( accum, 7 ); //false + * @endcode. + * + * @tparam N Type of the n. + * @tparam B Type of the b. + * @param number Number of. + * @param bits The bits. + * + * @return True if it succeeds, false if it fails. + */ + template < class N, class B > inline bool Has(N number, B bits) + { + return ((number & bits) == (static_cast(bits))); + } + + /** + * @fn template < class N, class B > inline N Add(N number, B bits) + * + * @brief Add the "bits" to "number". + * @code + * unsigned int accum = 1; + * accum = Bits::Add(accum, 7); //Has(accum, 1) and Has(accum, 7) == true + * @endcode. + * + * @tparam N Type of the n. + * @tparam B Type of the b. + * @param number Number of. + * @param bits The bits. + * + * @return A N. + */ + template < class N, class B > inline N Add(N number, B bits) + { + return (number | bits); + } + + /** + * @fn template < class N, class B > inline N Remove(N number, B bits) + * + * @brief Remove the "bits" from "number". + * @code + * unsigned int accum = 3; + * accum = Bits::Remove(accum, 2); //Has(accum,3) == false, Has(accum,1) == true + * @endcode. + * + * @tparam N Type of the n. + * @tparam B Type of the b. + * @param number Number of. + * @param bits The bits. + * + * @return A N. + */ + template < class N, class B > inline N Remove(N number, B bits) + { + return ((number & bits) ? (number ^ bits) : number); + } + + /** + * @fn template < class N, class B > inline N Toggle(N number, B bits) + * + * @brief Toggle the "bits" in "number". + * @code + * unsigned int accum = 3; + * unsigned int newBits; + * newBits = Bits::Toggle(accum, 1); //newBits = 2 + * newBits = Bits::Toggle(accum, 1); //newBits = 3 + * @endcode. + * + * @tparam N Type of the n. + * @tparam B Type of the b. + * @param number Number of. + * @param bits The bits. + * + * @return A N. + */ + template < class N, class B > inline N Toggle(N number, B bits) + { + return (number ^ bits); + } } \ No newline at end of file diff --git a/include/trUtil/Console/Logo.h b/include/trUtil/Console/Logo.h index 45658e1..12ad911 100644 --- a/include/trUtil/Console/Logo.h +++ b/include/trUtil/Console/Logo.h @@ -1,34 +1,34 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -namespace trUtil::Console -{ - - /** - * @fn void Logo(void); - * - * @brief Displays the True Reality Logo in the Consol Window. - */ - void TR_UTIL_EXPORT Logo(void); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +namespace trUtil::Console +{ + + /** + * @fn void Logo(void); + * + * @brief Displays the True Reality Logo in the Consol Window. + */ + void TR_UTIL_EXPORT Logo(void); } \ No newline at end of file diff --git a/include/trUtil/Console/TextColor.h b/include/trUtil/Console/TextColor.h index 2e0b5c1..c876aaf 100644 --- a/include/trUtil/Console/TextColor.h +++ b/include/trUtil/Console/TextColor.h @@ -1,78 +1,78 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Console -{ - /** - * @enum TXT_COLOR - * - * @brief Color Modes for the Console Window - * - * @author Maxim Serebrennik - */ - enum TR_UTIL_EXPORT TXT_COLOR - { - DEFAULT, - BRIGHT_RED, - RED, - BRIGHT_GREEN, - GREEN, - BRIGHT_BLUE, - BLUE, - BRIGHT_YELLOW, - YELLOW, - WHITE, - BRIGHT_CYAN, - CYAN, - BRIGHT_MAGENTA, - MAGENTA, - GRAY - }; - - /** - * @fn void TextColor(TXT_COLOR TextColor); - * - * @brief Changes Text color in the console window.... - * - * @author Maxim Serebrennik - * - * @param TextColor The text color. - */ - void TR_UTIL_EXPORT TextColor(TXT_COLOR TextColor); - - /** - * @fn void PrintAllColors(); - * - * @brief Prints an example of all available colors This is usually used for testing and - * development. - * - * @author Maxim Serebrennik - */ - void TR_UTIL_EXPORT PrintAllColors(); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Console +{ + /** + * @enum TXT_COLOR + * + * @brief Color Modes for the Console Window + * + * @author Maxim Serebrennik + */ + enum TR_UTIL_EXPORT TXT_COLOR + { + DEFAULT, + BRIGHT_RED, + RED, + BRIGHT_GREEN, + GREEN, + BRIGHT_BLUE, + BLUE, + BRIGHT_YELLOW, + YELLOW, + WHITE, + BRIGHT_CYAN, + CYAN, + BRIGHT_MAGENTA, + MAGENTA, + GRAY + }; + + /** + * @fn void TextColor(TXT_COLOR TextColor); + * + * @brief Changes Text color in the console window.... + * + * @author Maxim Serebrennik + * + * @param TextColor The text color. + */ + void TR_UTIL_EXPORT TextColor(TXT_COLOR TextColor); + + /** + * @fn void PrintAllColors(); + * + * @brief Prints an example of all available colors This is usually used for testing and + * development. + * + * @author Maxim Serebrennik + */ + void TR_UTIL_EXPORT PrintAllColors(); } \ No newline at end of file diff --git a/include/trUtil/DateTime.h b/include/trUtil/DateTime.h index 21cb569..8faf1a2 100644 --- a/include/trUtil/DateTime.h +++ b/include/trUtil/DateTime.h @@ -1,842 +1,842 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Bradley Anderegg -*/ -#pragma once - -#include "Export.h" - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @class TR_UTIL_EXPORT - * - * @brief A class that represents date time utility. - */ - class TR_UTIL_EXPORT DateTime - { - public: - - /** - * @class TR_UTIL_EXPORT - * - * @brief The TimeOrigin enumeration determines how the instance of DateTime should be - * interpreted. When passing a TimeOrigin into the constructor of DateTime it will - * automatically set the clock to that specific time. - */ - class TR_UTIL_EXPORT TimeOrigin : public trUtil::EnumerationString - { - DECLARE_ENUM(TimeOrigin) - - public: - /** @brief The local time. */ - static const TimeOrigin LOCAL_TIME; - /** @brief The GMT time. */ - static const TimeOrigin GMT_TIME; - - protected: - - /** - * @fn TimeOrigin::~TimeOrigin() - * - * @brief Destructor. - */ - /*virtual*/ ~TimeOrigin(){} - - private: - - /** - * @fn TimeOrigin::TimeOrigin(const std::string& name) : trUtil::EnumerationString(name) - * - * @brief Constructor. - * - * @param name The name. - */ - TimeOrigin(const std::string& name) : trUtil::EnumerationString(name) - { - AddInstance(this); - } - }; - - /** - * @class TR_UTIL_EXPORT - * - * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. - */ - class TR_UTIL_EXPORT TimeType : public trUtil::EnumerationString - { - DECLARE_ENUM(TimeType) - - public: - /** @brief The clock time. */ - static const TimeType CLOCK_TIME; - /** @brief The simulation time. */ - static const TimeType SIMULATION_TIME; - /** @brief The scenario time. */ - static const TimeType SCENARIO_TIME; - /** @brief The trip time. */ - static const TimeType TRIP_TIME; - /** @brief The time stamp. */ - static const TimeType TIME_STAMP; - /** @brief The time type other. */ - static const TimeType TIME_TYPE_OTHER; - - protected: - - /** - * @fn TimeType::~TimeType() - * - * @brief Destructor. - */ - /*virtual*/ ~TimeType(){} - - private: - - /** - * @fn TimeType::TimeType(const std::string& name) : trUtil::EnumerationString(name) - * - * @brief Constructor. - * - * @param name The name. - */ - TimeType(const std::string& name) : trUtil::EnumerationString(name) - { - AddInstance(this); - } - }; - - /** - * @class TR_UTIL_EXPORT - * - * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a - * string. This enumeration is used in conjunction with ToString(). - */ - class TR_UTIL_EXPORT TimeFormat : public trUtil::EnumerationString - { - DECLARE_ENUM(TimeFormat) - - public: - - /** @brief LOCAL_DATE_AND_TIME_FORMAT: 04/18/08 13:22:50. */ - static const TimeFormat LOCAL_DATE_AND_TIME_FORMAT; - - /** @brief LOCAL_DATE_FORMAT: 04/18/08. */ - static const TimeFormat LOCAL_DATE_FORMAT; - - /** @brief CLOCK_TIME_12_HOUR_FORMAT: 01:22:50 PM. */ - static const TimeFormat CLOCK_TIME_12_HOUR_FORMAT; - - /** @brief CLOCK_TIME_24_HOUR_FORMAT: 13:22:50. */ - static const TimeFormat CLOCK_TIME_24_HOUR_FORMAT; - - /** @brief LEXICAL_DATE_FORMAT: April 18, 2008. */ - static const TimeFormat LEXICAL_DATE_FORMAT; - - /** @brief CALENDAR_DATE_FORMAT: 2008-04-18. */ - static const TimeFormat CALENDAR_DATE_FORMAT; - - /** @brief ORDINAL_DATE_FORMAT: 2008-109. */ - static const TimeFormat ORDINAL_DATE_FORMAT; - - /** @brief WEEK_DATE_FORMAT: 2008-W15-5. */ - static const TimeFormat WEEK_DATE_FORMAT; - - /** @brief CALENDAR_DATE_AND_TIME_FORMAT: 2008-04-18T13:22:50-05:00. */ - static const TimeFormat CALENDAR_DATE_AND_TIME_FORMAT; - - protected: - - /** - * @fn TimeFormat::~TimeFormat() - * - * @brief Destructor. - */ - /*virtual*/ ~TimeFormat(){} - - private: - - /** - * @fn TimeFormat::TimeFormat(const std::string& name) : trUtil::EnumerationString(name) - * - * @brief Constructor. - * - * @param name The name. - */ - TimeFormat(const std::string& name) : trUtil::EnumerationString(name) - { - AddInstance(this); - } - }; - - public: - - /** - * @fn DateTime::DateTime(); - * - * @brief The default constructor just zeros. - */ - DateTime(); - - /** - * @fn DateTime::DateTime(const TimeOrigin& initAs); - * - * @brief This constructor takes a TimeOrigin and sets the time accordingly. - * - * @param initAs The init as. - */ - DateTime(const TimeOrigin& initAs); - - /** - * @fn DateTime::DateTime(time_t); - * - * @brief Create a DateTime using the c standard time_t struct. - * - * @param parameter1 The first parameter. - */ - DateTime(time_t); - - /** - * @fn DateTime::DateTime(const struct tm&); - * - * @brief Create a DateTime using the c standard struct tm. - * - * @param parameter1 The first parameter. - */ - DateTime(const struct tm&); - - /** - * @fn DateTime::DateTime(const DateTime&); - * - * @brief Copy constructor. - * - * @param parameter1 The first parameter. - */ - DateTime(const DateTime&); - - /** - * @fn DateTime& DateTime::operator=(const DateTime&); - * - * @brief Assignment operator. - * - * @param parameter1 The first parameter. - * - * @return A shallow copy of this object. - */ - DateTime& operator=(const DateTime&); - - /** - * @fn virtual DateTime::~DateTime(); - * - * @brief Destructor. - */ - virtual ~DateTime(); - - /** - * @fn static float DateTime::GetLocalGMTOffset(bool accountForDST = false); - * - * @brief Gets local GMT offset. - * - * @param accountForDST (Optional) True to account for destination. - * - * @return The local GMT offset. - */ - static float GetLocalGMTOffset(bool accountForDST = false); - - /** - * @fn void DateTime::SetToLocalTime(); - * - * @brief Changes time to be system local time. - */ - void SetToLocalTime(); - - /** - * @fn void DateTime::SetToGMTTime(); - * - * @brief Changes time to be GMT- or Greenwich Mean Time. - */ - void SetToGMTTime(); - - /** - * @fn void DateTime::IncrementClock(double seconds); - * - * @brief Increments the clock time by the number of seconds specified. The fractional part of - * the time is saved off and added in whole increments to support sub second times but - * getting time as a time_t or struct tm will not include fractional seconds. To get - * the fractional seconds use GetTime with a float for seconds or GetSecond(). - * - * @param seconds number of seconds to increase the clock by. - */ - void IncrementClock(double seconds); - - /** - * @fn void DateTime::AdjustTimeZone(float newGMTOffset); - * - * @brief Every date time has a GMT offset. This method allows one to set a new GMT offset, - * and then change the clock internally to match the newoffset. For example if the - * clock is in 12:00 AM Eastern Time (-5) Jan 5, 2009, setting the offset to west coast - * time (-8) would make the date time be 9:00 PM, Jan 4, 2009. - * - * @param newGMTOffset the offset in hours from GMT to change this to. - */ - void AdjustTimeZone(float newGMTOffset); - - /** - * @fn void DateTime::GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; - * - * @brief Gets the time internally stored using unsigned year, month, day, hour, minute, and - * seconds. The float second version will include the sub second time if - * IncrementClock() or SetSecond() was not rounded off. To get time modified by a - * GMTOffset use GetGMTTime(). - * - * @param [in,out] year the full year, not just since 1900 epoch. - * @param [in,out] month the month specified as 1-12. - * @param [in,out] day the day specified as 1-31. - * @param [in,out] hour hours since midnight 0-23. - * @param [in,out] min minutes after the hour 0-60. - * @param [in,out] sec seconds after the hour 0-61 (and extra second is added to support - * leap seconds) - */ - void GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; - - /** - * @fn void DateTime::GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; - * - * @brief Gets a time. - * - * @param [in,out] year The year. - * @param [in,out] month The month. - * @param [in,out] day The day. - * @param [in,out] hour The hour. - * @param [in,out] min The minimum. - * @param [in,out] sec The security. - */ - void GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; - - /** - * @fn void DateTime::GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; - * - * @brief Gets the time internally stored using unsigned year, month, day, hour, minute, and - * seconds. The float second version will include the sub second time if - * IncrementClock() or SetSecond() was not rounded off. The GMTOffset will be added - * into the current time to obtain the GMT Time. - * - * @param [in,out] year the full year, not just since 1900 epoch. - * @param [in,out] month the month specified as 1-12. - * @param [in,out] day the day specified as 1-31. - * @param [in,out] hour hours since midnight 0-23. - * @param [in,out] min minutes after the hour 0-60. - * @param [in,out] sec seconds after the hour 0-61 (and extra second is added to support - * leap seconds) - */ - void GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; - - /** - * @fn void DateTime::GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; - * - * @brief Gets GMT time. - * - * @param [in,out] year The year. - * @param [in,out] month The month. - * @param [in,out] day The day. - * @param [in,out] hour The hour. - * @param [in,out] min The minimum. - * @param [in,out] sec The security. - */ - void GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; - - /** - * @fn void DateTime::SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, float sec); - * - * @brief Sets the full time using year, month, day, hour, minute, and second. A float version - * is provided to support sub second times. - * - * @param year the full year, not just since 1900 epoch. - * @param month the month specified as 1-12. - * @param day the day specified as 1-31. - * @param hour hours since midnight 0-23. - * @param min minutes after the hour 0-60. - * @param sec seconds after the hour 0-61 (and extra second is added to support leap - * seconds) - */ - void SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, float sec); - - /** - * @fn void DateTime::SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, unsigned sec); - * - * @brief Sets a time. - * - * @param year The year. - * @param month The month. - * @param day The day. - * @param hour The hour. - * @param min The minimum. - * @param sec The security. - */ - void SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, unsigned sec); - - /** - * @fn time_t DateTime::GetTime() const; - * - * @brief Gets the time in the standard time_t format, specified as seconds elapsed since - * midnight, January 1, 1970 - * @note this format only includes whole seconds. - * - * @return The time. - */ - time_t GetTime() const; - - /** - * @fn time_t DateTime::GetGMTTime() const; - * - * @brief Gets the time in standard time_t format, the GMTOffset is added to the time before - * calculating time_t. - * - * @return The GMT time. - */ - time_t GetGMTTime() const; - - /** - * @fn void DateTime::SetTime(time_t); - * - * @brief Sets time in standard time_t format, specified as seconds elapsed since midnight, - * January 1, 1970. - * - * @param parameter1 The first parameter. - */ - void SetTime(time_t); - - /** - * @fn double DateTime::GetTimeInSeconds() const; - * - * @brief Returns the total clock time in seconds elapsed since midnight, January 1, 1970 This - * time includes fractional seconds. - * - * @return The time in seconds. - */ - double GetTimeInSeconds() const; - - /** - * @fn void DateTime::GetTime(tm&) const; - * - * @brief Fills a standard c struct tm with the time. - * - * @param [in,out] parameter1 The first parameter. - */ - void GetTime(tm&) const; - - /** - * @fn void DateTime::GetGMTTime(tm&) const; - * - * @brief Fills a standard c struct tm with the time but adds GMTOffset into time before struct - * tm is calculated. - * - * @param [in,out] parameter1 The first parameter. - */ - void GetGMTTime(tm&) const; - - /** - * @fn void DateTime::SetTime(const tm&); - * - * @brief Sets the time using the standard c struct tm. - * - * @param parameter1 The first parameter. - */ - void SetTime(const tm&); - - /** - * @fn void DateTime::SetGMTOffset(float hourOffset, bool dayLightSavings); - * - * @brief Sets the GMTOffset which is added to the time when getting GMT time,. - * - * @param hourOffset the number of hours to offset from GMT Time, the param is a float to - * support half hour time zones. - * @param dayLightSavings this flag is used to specify whether or not daylight savings is in - * effect setting this flag to true will add and extra hour to the - * GMTOffset. - */ - void SetGMTOffset(float hourOffset, bool dayLightSavings); - - /** - * @fn static float DateTime::CalcGMTOffset(tm& timeParts, bool factorLocalDayLightSavingsIntoGMTOffset); - * - * @brief Sets the GMTOffset using the systems local time this offset is added to the time when - * getting GMT time,. - * - * @param [in,out] timeParts the struct tm used to calculate the - * local timezone. - * @param factorLocalDayLightSavingsIntoGMTOffset this flag is used to specify whether - * or not daylight savings should be - * obtained from the system clock, - * setting true will increment the - * GMTOffset by one hour if your system - * is currently on daylight savings. - * - * @return The calculated GMT offset. - */ - static float CalcGMTOffset(tm& timeParts, bool factorLocalDayLightSavingsIntoGMTOffset); - - /** - * @fn void DateTime::SetGMTOffset(double lattitude, double longitude, bool dayLightSavings); - * - * @brief Calculates the GMTOffset using a lattitude and longitude, not 100% correct due to - * regional time zone boundaries but it works ok as an approximation. - * - * @param lattitude the geographical lattitude of origin. - * @param longitude the geographical longitude of origin. - * @param dayLightSavings this flag is used to specify whether or not daylight savings is in - * effect setting this flag to true will add and extra hour to the - * GMTOffset. - */ - void SetGMTOffset(double lattitude, double longitude, bool dayLightSavings); - - /** - * @fn float DateTime::GetGMTOffset() const; - * - * @brief Gets the GMTOffset, this will be 0 unless SetGMTOffset was called or SetToLocalTime() - * was called, or TimeOrigin::LOCAL_TIME was fed into the constructor. - * - * @return the current offset from Greenwich mean time. - */ - float GetGMTOffset() const; - - /** - * @fn float DateTime::GetTimeScale() const; - * - * @brief The TimeScale can be used to scale the time when incrementing the clock. The default - * value for TimeScale is 1.0. - * - * @return The time scale. - */ - float GetTimeScale() const; - - /** - * @fn void DateTime::SetTimeScale(float percentScaleInSeconds); - * - * @brief The TimeScale can be used to scale the time when incrementing the clock. The default - * value for TimeScale is 1.0. - * - * @param percentScaleInSeconds The percent scale in seconds. - */ - void SetTimeScale(float percentScaleInSeconds); - - /** - * @fn const TimeType& DateTime::GetTimeType() const; - * - * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. - * - * @return The time type. - */ - const TimeType& GetTimeType() const; - - /** - * @fn void DateTime::SetTimeType(const TimeType&); - * - * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. - * - * @param parameter1 The first parameter. - */ - void SetTimeType(const TimeType&); - - /** - * @fn const TimeOrigin& DateTime::GetTimeOrigin() const; - * - * @brief The TimeOrigin enumeration determines how the instance of DateTime should be - * interpreted. - * - * @return The time origin. - */ - const TimeOrigin& GetTimeOrigin() const; - - /** - * @fn void DateTime::SetTimeOrigin(const TimeOrigin&); - * - * @brief The TimeOrigin enumeration determines how the instance of DateTime should be - * interpreted. - * - * @param parameter1 The first parameter. - */ - void SetTimeOrigin(const TimeOrigin&); - - /** - * @fn const TimeFormat& DateTime::GetTimeFormat() const; - * - * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a - * string. Set the TimeFormat if you would like to use the ToString() without any - * arguments. - * - * @return The time format. - */ - const TimeFormat& GetTimeFormat() const; - - /** - * @fn void DateTime::SetTimeFormat(const TimeFormat&); - * - * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a - * string. Set the TimeFormat if you would like to use the ToString() without any - * arguments. - * - * @param parameter1 The first parameter. - */ - void SetTimeFormat(const TimeFormat&); - - /** - * @fn float DateTime::GetSecond() const; - * - * @brief Gets the second. - * - * @return The second. - */ - float GetSecond() const; - - /** - * @fn void DateTime::SetSecond(float sec); - * - * @brief Sets a second. - * - * @param sec The security. - */ - void SetSecond(float sec); - - /** - * @fn unsigned DateTime::GetMinute() const; - * - * @brief Gets the minute. - * - * @return The minute. - */ - unsigned GetMinute() const; - - /** - * @fn void DateTime::SetMinute(unsigned min); - * - * @brief Sets a minute. - * - * @param min The minimum. - */ - void SetMinute(unsigned min); - - /** - * @fn unsigned DateTime::GetHour() const; - * - * @brief Gets the hour. - * - * @return The hour. - */ - unsigned GetHour() const; - - /** - * @fn void DateTime::SetHour(unsigned hour); - * - * @brief Sets a hour. - * - * @param hour The hour. - */ - void SetHour(unsigned hour); - - /** - * @fn unsigned DateTime::GetDay() const; - * - * @brief Gets the day. - * - * @return The day. - */ - unsigned GetDay() const; - - /** - * @fn void DateTime::SetDay(unsigned day); - * - * @brief Sets a day. - * - * @param day The day. - */ - void SetDay(unsigned day); - - /** - * @fn unsigned DateTime::GetMonth() const; - * - * @brief Gets the month. - * - * @return The month. - */ - unsigned GetMonth() const; - - /** - * @fn void DateTime::SetMonth(unsigned month); - * - * @brief Sets a month. - * - * @param month The month. - */ - void SetMonth(unsigned month); - - /** - * @fn unsigned DateTime::GetYear() const; - * - * @brief Gets the year. - * - * @return The year. - */ - unsigned GetYear() const; - - /** - * @fn void DateTime::SetYear(unsigned year); - * - * @brief Sets a year. - * - * @param year The year. - */ - void SetYear(unsigned year); - - /** - * @fn std::string DateTime::ToString() const; - * - * @brief The no parameter version of ToString uses the internal TimeFormat, see the TimeFormat - * enumeration above. - * - * @return A std::string that represents this object. - */ - std::string ToString() const; - - /** - * @fn std::string DateTime::ToString(const TimeFormat&) const; - * - * @brief Converts the time to a string using a TimeFormat enumeration, see the TimeFormat - * enumeration above. - * - * @param parameter1 The first parameter. - * - * @return A std::string that represents this object. - */ - std::string ToString(const TimeFormat&) const; - - /** - * @fn static std::string DateTime::ToString(const DateTime&, const TimeFormat&); - * - * @brief A static version of ToString() for convenience, using the conversion operators a - * time_t or struct tm can be passed for the DateTime. - * - * @param parameter1 The first parameter. - * @param parameter2 The second parameter. - * - * @return A std::string that represents this object. - */ - static std::string ToString(const DateTime&, const TimeFormat&); - - /** - * @fn operator DateTime::time_t() const; - * - * @brief general purpose conversion operators. - * - * @return The result of the operation. - */ - operator time_t() const; - - /** - * @fn operator DateTime::tm() const; - * - * @brief Cast that converts the given to a tm. - * - * @return The result of the operation. - */ - operator tm() const; - - /** - * @fn operator std::string() const; - * - * @brief Cast that converts the given to a string. - * - * @return The result of the operation. - */ - operator std::string() const; - - //TODO- add operators - //DateTime& operator +=(const DateTime&); - //DateTime& operator -=(const DateTime&); - - //bool operator<(const DateTime&) const; - //bool operator>(const DateTime&) const; - - //std::ostream& operator >>(std::ostream&); - - private: - - /** - * @fn void DateTime::ResetToDefaultValues(); - * - * @brief Resets to default values. - */ - void ResetToDefaultValues(); - - /** - * @fn static void DateTime::GetGMTTime(time_t* t, tm& timeParts); - * - * @brief Gets GMT time. - * - * @param [in,out] t If non-null, the time_t to process. - * @param [in,out] timeParts The time parts. - */ - static void GetGMTTime(time_t* t, tm& timeParts); - - /** - * @fn static void DateTime::GetLocalTime(time_t* t, tm& timeParts); - * - * @brief Gets local time. - * - * @param [in,out] t If non-null, the time_t to process. - * @param [in,out] timeParts The time parts. - */ - static void GetLocalTime(time_t* t, tm& timeParts); - - - /** @brief The GMT offset. */ - float mGMTOffset; - /** @brief The time scale. */ - float mTimeScale; - /** @brief The fractional in seconds. */ - double mFractionalSeconds; - - /** - * @property unsigned mSeconds, mMinutes, mHours, mDays, mMonths, mYears - * - * @brief Store parts of time. - * - * @return The m years. - */ - unsigned mSeconds, mMinutes, mHours, mDays, mMonths, mYears; - - /** @brief The time origin. */ - const TimeOrigin* mTimeOrigin; - /** @brief Type of the time. */ - const TimeType* mTimeType; - /** @brief The string format. */ - const TimeFormat* mStringFormat; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Bradley Anderegg +*/ +#pragma once + +#include "Export.h" + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @class TR_UTIL_EXPORT + * + * @brief A class that represents date time utility. + */ + class TR_UTIL_EXPORT DateTime + { + public: + + /** + * @class TR_UTIL_EXPORT + * + * @brief The TimeOrigin enumeration determines how the instance of DateTime should be + * interpreted. When passing a TimeOrigin into the constructor of DateTime it will + * automatically set the clock to that specific time. + */ + class TR_UTIL_EXPORT TimeOrigin : public trUtil::EnumerationString + { + DECLARE_ENUM(TimeOrigin) + + public: + /** @brief The local time. */ + static const TimeOrigin LOCAL_TIME; + /** @brief The GMT time. */ + static const TimeOrigin GMT_TIME; + + protected: + + /** + * @fn TimeOrigin::~TimeOrigin() + * + * @brief Destructor. + */ + /*virtual*/ ~TimeOrigin(){} + + private: + + /** + * @fn TimeOrigin::TimeOrigin(const std::string& name) : trUtil::EnumerationString(name) + * + * @brief Constructor. + * + * @param name The name. + */ + TimeOrigin(const std::string& name) : trUtil::EnumerationString(name) + { + AddInstance(this); + } + }; + + /** + * @class TR_UTIL_EXPORT + * + * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. + */ + class TR_UTIL_EXPORT TimeType : public trUtil::EnumerationString + { + DECLARE_ENUM(TimeType) + + public: + /** @brief The clock time. */ + static const TimeType CLOCK_TIME; + /** @brief The simulation time. */ + static const TimeType SIMULATION_TIME; + /** @brief The scenario time. */ + static const TimeType SCENARIO_TIME; + /** @brief The trip time. */ + static const TimeType TRIP_TIME; + /** @brief The time stamp. */ + static const TimeType TIME_STAMP; + /** @brief The time type other. */ + static const TimeType TIME_TYPE_OTHER; + + protected: + + /** + * @fn TimeType::~TimeType() + * + * @brief Destructor. + */ + /*virtual*/ ~TimeType(){} + + private: + + /** + * @fn TimeType::TimeType(const std::string& name) : trUtil::EnumerationString(name) + * + * @brief Constructor. + * + * @param name The name. + */ + TimeType(const std::string& name) : trUtil::EnumerationString(name) + { + AddInstance(this); + } + }; + + /** + * @class TR_UTIL_EXPORT + * + * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a + * string. This enumeration is used in conjunction with ToString(). + */ + class TR_UTIL_EXPORT TimeFormat : public trUtil::EnumerationString + { + DECLARE_ENUM(TimeFormat) + + public: + + /** @brief LOCAL_DATE_AND_TIME_FORMAT: 04/18/08 13:22:50. */ + static const TimeFormat LOCAL_DATE_AND_TIME_FORMAT; + + /** @brief LOCAL_DATE_FORMAT: 04/18/08. */ + static const TimeFormat LOCAL_DATE_FORMAT; + + /** @brief CLOCK_TIME_12_HOUR_FORMAT: 01:22:50 PM. */ + static const TimeFormat CLOCK_TIME_12_HOUR_FORMAT; + + /** @brief CLOCK_TIME_24_HOUR_FORMAT: 13:22:50. */ + static const TimeFormat CLOCK_TIME_24_HOUR_FORMAT; + + /** @brief LEXICAL_DATE_FORMAT: April 18, 2008. */ + static const TimeFormat LEXICAL_DATE_FORMAT; + + /** @brief CALENDAR_DATE_FORMAT: 2008-04-18. */ + static const TimeFormat CALENDAR_DATE_FORMAT; + + /** @brief ORDINAL_DATE_FORMAT: 2008-109. */ + static const TimeFormat ORDINAL_DATE_FORMAT; + + /** @brief WEEK_DATE_FORMAT: 2008-W15-5. */ + static const TimeFormat WEEK_DATE_FORMAT; + + /** @brief CALENDAR_DATE_AND_TIME_FORMAT: 2008-04-18T13:22:50-05:00. */ + static const TimeFormat CALENDAR_DATE_AND_TIME_FORMAT; + + protected: + + /** + * @fn TimeFormat::~TimeFormat() + * + * @brief Destructor. + */ + /*virtual*/ ~TimeFormat(){} + + private: + + /** + * @fn TimeFormat::TimeFormat(const std::string& name) : trUtil::EnumerationString(name) + * + * @brief Constructor. + * + * @param name The name. + */ + TimeFormat(const std::string& name) : trUtil::EnumerationString(name) + { + AddInstance(this); + } + }; + + public: + + /** + * @fn DateTime::DateTime(); + * + * @brief The default constructor just zeros. + */ + DateTime(); + + /** + * @fn DateTime::DateTime(const TimeOrigin& initAs); + * + * @brief This constructor takes a TimeOrigin and sets the time accordingly. + * + * @param initAs The init as. + */ + DateTime(const TimeOrigin& initAs); + + /** + * @fn DateTime::DateTime(time_t); + * + * @brief Create a DateTime using the c standard time_t struct. + * + * @param parameter1 The first parameter. + */ + DateTime(time_t); + + /** + * @fn DateTime::DateTime(const struct tm&); + * + * @brief Create a DateTime using the c standard struct tm. + * + * @param parameter1 The first parameter. + */ + DateTime(const struct tm&); + + /** + * @fn DateTime::DateTime(const DateTime&); + * + * @brief Copy constructor. + * + * @param parameter1 The first parameter. + */ + DateTime(const DateTime&); + + /** + * @fn DateTime& DateTime::operator=(const DateTime&); + * + * @brief Assignment operator. + * + * @param parameter1 The first parameter. + * + * @return A shallow copy of this object. + */ + DateTime& operator=(const DateTime&); + + /** + * @fn virtual DateTime::~DateTime(); + * + * @brief Destructor. + */ + virtual ~DateTime(); + + /** + * @fn static float DateTime::GetLocalGMTOffset(bool accountForDST = false); + * + * @brief Gets local GMT offset. + * + * @param accountForDST (Optional) True to account for destination. + * + * @return The local GMT offset. + */ + static float GetLocalGMTOffset(bool accountForDST = false); + + /** + * @fn void DateTime::SetToLocalTime(); + * + * @brief Changes time to be system local time. + */ + void SetToLocalTime(); + + /** + * @fn void DateTime::SetToGMTTime(); + * + * @brief Changes time to be GMT- or Greenwich Mean Time. + */ + void SetToGMTTime(); + + /** + * @fn void DateTime::IncrementClock(double seconds); + * + * @brief Increments the clock time by the number of seconds specified. The fractional part of + * the time is saved off and added in whole increments to support sub second times but + * getting time as a time_t or struct tm will not include fractional seconds. To get + * the fractional seconds use GetTime with a float for seconds or GetSecond(). + * + * @param seconds number of seconds to increase the clock by. + */ + void IncrementClock(double seconds); + + /** + * @fn void DateTime::AdjustTimeZone(float newGMTOffset); + * + * @brief Every date time has a GMT offset. This method allows one to set a new GMT offset, + * and then change the clock internally to match the newoffset. For example if the + * clock is in 12:00 AM Eastern Time (-5) Jan 5, 2009, setting the offset to west coast + * time (-8) would make the date time be 9:00 PM, Jan 4, 2009. + * + * @param newGMTOffset the offset in hours from GMT to change this to. + */ + void AdjustTimeZone(float newGMTOffset); + + /** + * @fn void DateTime::GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; + * + * @brief Gets the time internally stored using unsigned year, month, day, hour, minute, and + * seconds. The float second version will include the sub second time if + * IncrementClock() or SetSecond() was not rounded off. To get time modified by a + * GMTOffset use GetGMTTime(). + * + * @param [in,out] year the full year, not just since 1900 epoch. + * @param [in,out] month the month specified as 1-12. + * @param [in,out] day the day specified as 1-31. + * @param [in,out] hour hours since midnight 0-23. + * @param [in,out] min minutes after the hour 0-60. + * @param [in,out] sec seconds after the hour 0-61 (and extra second is added to support + * leap seconds) + */ + void GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; + + /** + * @fn void DateTime::GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; + * + * @brief Gets a time. + * + * @param [in,out] year The year. + * @param [in,out] month The month. + * @param [in,out] day The day. + * @param [in,out] hour The hour. + * @param [in,out] min The minimum. + * @param [in,out] sec The security. + */ + void GetTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; + + /** + * @fn void DateTime::GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; + * + * @brief Gets the time internally stored using unsigned year, month, day, hour, minute, and + * seconds. The float second version will include the sub second time if + * IncrementClock() or SetSecond() was not rounded off. The GMTOffset will be added + * into the current time to obtain the GMT Time. + * + * @param [in,out] year the full year, not just since 1900 epoch. + * @param [in,out] month the month specified as 1-12. + * @param [in,out] day the day specified as 1-31. + * @param [in,out] hour hours since midnight 0-23. + * @param [in,out] min minutes after the hour 0-60. + * @param [in,out] sec seconds after the hour 0-61 (and extra second is added to support + * leap seconds) + */ + void GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, float& sec) const; + + /** + * @fn void DateTime::GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; + * + * @brief Gets GMT time. + * + * @param [in,out] year The year. + * @param [in,out] month The month. + * @param [in,out] day The day. + * @param [in,out] hour The hour. + * @param [in,out] min The minimum. + * @param [in,out] sec The security. + */ + void GetGMTTime(unsigned& year, unsigned& month, unsigned& day, unsigned& hour, unsigned& min, unsigned& sec) const; + + /** + * @fn void DateTime::SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, float sec); + * + * @brief Sets the full time using year, month, day, hour, minute, and second. A float version + * is provided to support sub second times. + * + * @param year the full year, not just since 1900 epoch. + * @param month the month specified as 1-12. + * @param day the day specified as 1-31. + * @param hour hours since midnight 0-23. + * @param min minutes after the hour 0-60. + * @param sec seconds after the hour 0-61 (and extra second is added to support leap + * seconds) + */ + void SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, float sec); + + /** + * @fn void DateTime::SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, unsigned sec); + * + * @brief Sets a time. + * + * @param year The year. + * @param month The month. + * @param day The day. + * @param hour The hour. + * @param min The minimum. + * @param sec The security. + */ + void SetTime(unsigned year, unsigned month, unsigned day, unsigned hour, unsigned min, unsigned sec); + + /** + * @fn time_t DateTime::GetTime() const; + * + * @brief Gets the time in the standard time_t format, specified as seconds elapsed since + * midnight, January 1, 1970 + * @note this format only includes whole seconds. + * + * @return The time. + */ + time_t GetTime() const; + + /** + * @fn time_t DateTime::GetGMTTime() const; + * + * @brief Gets the time in standard time_t format, the GMTOffset is added to the time before + * calculating time_t. + * + * @return The GMT time. + */ + time_t GetGMTTime() const; + + /** + * @fn void DateTime::SetTime(time_t); + * + * @brief Sets time in standard time_t format, specified as seconds elapsed since midnight, + * January 1, 1970. + * + * @param parameter1 The first parameter. + */ + void SetTime(time_t); + + /** + * @fn double DateTime::GetTimeInSeconds() const; + * + * @brief Returns the total clock time in seconds elapsed since midnight, January 1, 1970 This + * time includes fractional seconds. + * + * @return The time in seconds. + */ + double GetTimeInSeconds() const; + + /** + * @fn void DateTime::GetTime(tm&) const; + * + * @brief Fills a standard c struct tm with the time. + * + * @param [in,out] parameter1 The first parameter. + */ + void GetTime(tm&) const; + + /** + * @fn void DateTime::GetGMTTime(tm&) const; + * + * @brief Fills a standard c struct tm with the time but adds GMTOffset into time before struct + * tm is calculated. + * + * @param [in,out] parameter1 The first parameter. + */ + void GetGMTTime(tm&) const; + + /** + * @fn void DateTime::SetTime(const tm&); + * + * @brief Sets the time using the standard c struct tm. + * + * @param parameter1 The first parameter. + */ + void SetTime(const tm&); + + /** + * @fn void DateTime::SetGMTOffset(float hourOffset, bool dayLightSavings); + * + * @brief Sets the GMTOffset which is added to the time when getting GMT time,. + * + * @param hourOffset the number of hours to offset from GMT Time, the param is a float to + * support half hour time zones. + * @param dayLightSavings this flag is used to specify whether or not daylight savings is in + * effect setting this flag to true will add and extra hour to the + * GMTOffset. + */ + void SetGMTOffset(float hourOffset, bool dayLightSavings); + + /** + * @fn static float DateTime::CalcGMTOffset(tm& timeParts, bool factorLocalDayLightSavingsIntoGMTOffset); + * + * @brief Sets the GMTOffset using the systems local time this offset is added to the time when + * getting GMT time,. + * + * @param [in,out] timeParts the struct tm used to calculate the + * local timezone. + * @param factorLocalDayLightSavingsIntoGMTOffset this flag is used to specify whether + * or not daylight savings should be + * obtained from the system clock, + * setting true will increment the + * GMTOffset by one hour if your system + * is currently on daylight savings. + * + * @return The calculated GMT offset. + */ + static float CalcGMTOffset(tm& timeParts, bool factorLocalDayLightSavingsIntoGMTOffset); + + /** + * @fn void DateTime::SetGMTOffset(double lattitude, double longitude, bool dayLightSavings); + * + * @brief Calculates the GMTOffset using a lattitude and longitude, not 100% correct due to + * regional time zone boundaries but it works ok as an approximation. + * + * @param lattitude the geographical lattitude of origin. + * @param longitude the geographical longitude of origin. + * @param dayLightSavings this flag is used to specify whether or not daylight savings is in + * effect setting this flag to true will add and extra hour to the + * GMTOffset. + */ + void SetGMTOffset(double lattitude, double longitude, bool dayLightSavings); + + /** + * @fn float DateTime::GetGMTOffset() const; + * + * @brief Gets the GMTOffset, this will be 0 unless SetGMTOffset was called or SetToLocalTime() + * was called, or TimeOrigin::LOCAL_TIME was fed into the constructor. + * + * @return the current offset from Greenwich mean time. + */ + float GetGMTOffset() const; + + /** + * @fn float DateTime::GetTimeScale() const; + * + * @brief The TimeScale can be used to scale the time when incrementing the clock. The default + * value for TimeScale is 1.0. + * + * @return The time scale. + */ + float GetTimeScale() const; + + /** + * @fn void DateTime::SetTimeScale(float percentScaleInSeconds); + * + * @brief The TimeScale can be used to scale the time when incrementing the clock. The default + * value for TimeScale is 1.0. + * + * @param percentScaleInSeconds The percent scale in seconds. + */ + void SetTimeScale(float percentScaleInSeconds); + + /** + * @fn const TimeType& DateTime::GetTimeType() const; + * + * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. + * + * @return The time type. + */ + const TimeType& GetTimeType() const; + + /** + * @fn void DateTime::SetTimeType(const TimeType&); + * + * @brief The TimeType enumeration is used to identify the purpose of a DateTime instance. + * + * @param parameter1 The first parameter. + */ + void SetTimeType(const TimeType&); + + /** + * @fn const TimeOrigin& DateTime::GetTimeOrigin() const; + * + * @brief The TimeOrigin enumeration determines how the instance of DateTime should be + * interpreted. + * + * @return The time origin. + */ + const TimeOrigin& GetTimeOrigin() const; + + /** + * @fn void DateTime::SetTimeOrigin(const TimeOrigin&); + * + * @brief The TimeOrigin enumeration determines how the instance of DateTime should be + * interpreted. + * + * @param parameter1 The first parameter. + */ + void SetTimeOrigin(const TimeOrigin&); + + /** + * @fn const TimeFormat& DateTime::GetTimeFormat() const; + * + * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a + * string. Set the TimeFormat if you would like to use the ToString() without any + * arguments. + * + * @return The time format. + */ + const TimeFormat& GetTimeFormat() const; + + /** + * @fn void DateTime::SetTimeFormat(const TimeFormat&); + * + * @brief The TimeFormat enumeration is used to specify how to map a DateTime object to a + * string. Set the TimeFormat if you would like to use the ToString() without any + * arguments. + * + * @param parameter1 The first parameter. + */ + void SetTimeFormat(const TimeFormat&); + + /** + * @fn float DateTime::GetSecond() const; + * + * @brief Gets the second. + * + * @return The second. + */ + float GetSecond() const; + + /** + * @fn void DateTime::SetSecond(float sec); + * + * @brief Sets a second. + * + * @param sec The security. + */ + void SetSecond(float sec); + + /** + * @fn unsigned DateTime::GetMinute() const; + * + * @brief Gets the minute. + * + * @return The minute. + */ + unsigned GetMinute() const; + + /** + * @fn void DateTime::SetMinute(unsigned min); + * + * @brief Sets a minute. + * + * @param min The minimum. + */ + void SetMinute(unsigned min); + + /** + * @fn unsigned DateTime::GetHour() const; + * + * @brief Gets the hour. + * + * @return The hour. + */ + unsigned GetHour() const; + + /** + * @fn void DateTime::SetHour(unsigned hour); + * + * @brief Sets a hour. + * + * @param hour The hour. + */ + void SetHour(unsigned hour); + + /** + * @fn unsigned DateTime::GetDay() const; + * + * @brief Gets the day. + * + * @return The day. + */ + unsigned GetDay() const; + + /** + * @fn void DateTime::SetDay(unsigned day); + * + * @brief Sets a day. + * + * @param day The day. + */ + void SetDay(unsigned day); + + /** + * @fn unsigned DateTime::GetMonth() const; + * + * @brief Gets the month. + * + * @return The month. + */ + unsigned GetMonth() const; + + /** + * @fn void DateTime::SetMonth(unsigned month); + * + * @brief Sets a month. + * + * @param month The month. + */ + void SetMonth(unsigned month); + + /** + * @fn unsigned DateTime::GetYear() const; + * + * @brief Gets the year. + * + * @return The year. + */ + unsigned GetYear() const; + + /** + * @fn void DateTime::SetYear(unsigned year); + * + * @brief Sets a year. + * + * @param year The year. + */ + void SetYear(unsigned year); + + /** + * @fn std::string DateTime::ToString() const; + * + * @brief The no parameter version of ToString uses the internal TimeFormat, see the TimeFormat + * enumeration above. + * + * @return A std::string that represents this object. + */ + std::string ToString() const; + + /** + * @fn std::string DateTime::ToString(const TimeFormat&) const; + * + * @brief Converts the time to a string using a TimeFormat enumeration, see the TimeFormat + * enumeration above. + * + * @param parameter1 The first parameter. + * + * @return A std::string that represents this object. + */ + std::string ToString(const TimeFormat&) const; + + /** + * @fn static std::string DateTime::ToString(const DateTime&, const TimeFormat&); + * + * @brief A static version of ToString() for convenience, using the conversion operators a + * time_t or struct tm can be passed for the DateTime. + * + * @param parameter1 The first parameter. + * @param parameter2 The second parameter. + * + * @return A std::string that represents this object. + */ + static std::string ToString(const DateTime&, const TimeFormat&); + + /** + * @fn operator DateTime::time_t() const; + * + * @brief general purpose conversion operators. + * + * @return The result of the operation. + */ + operator time_t() const; + + /** + * @fn operator DateTime::tm() const; + * + * @brief Cast that converts the given to a tm. + * + * @return The result of the operation. + */ + operator tm() const; + + /** + * @fn operator std::string() const; + * + * @brief Cast that converts the given to a string. + * + * @return The result of the operation. + */ + operator std::string() const; + + //TODO- add operators + //DateTime& operator +=(const DateTime&); + //DateTime& operator -=(const DateTime&); + + //bool operator<(const DateTime&) const; + //bool operator>(const DateTime&) const; + + //std::ostream& operator >>(std::ostream&); + + private: + + /** + * @fn void DateTime::ResetToDefaultValues(); + * + * @brief Resets to default values. + */ + void ResetToDefaultValues(); + + /** + * @fn static void DateTime::GetGMTTime(time_t* t, tm& timeParts); + * + * @brief Gets GMT time. + * + * @param [in,out] t If non-null, the time_t to process. + * @param [in,out] timeParts The time parts. + */ + static void GetGMTTime(time_t* t, tm& timeParts); + + /** + * @fn static void DateTime::GetLocalTime(time_t* t, tm& timeParts); + * + * @brief Gets local time. + * + * @param [in,out] t If non-null, the time_t to process. + * @param [in,out] timeParts The time parts. + */ + static void GetLocalTime(time_t* t, tm& timeParts); + + + /** @brief The GMT offset. */ + float mGMTOffset; + /** @brief The time scale. */ + float mTimeScale; + /** @brief The fractional in seconds. */ + double mFractionalSeconds; + + /** + * @property unsigned mSeconds, mMinutes, mHours, mDays, mMonths, mYears + * + * @brief Store parts of time. + * + * @return The m years. + */ + unsigned mSeconds, mMinutes, mHours, mDays, mMonths, mYears; + + /** @brief The time origin. */ + const TimeOrigin* mTimeOrigin; + /** @brief Type of the time. */ + const TimeType* mTimeType; + /** @brief The string format. */ + const TimeFormat* mStringFormat; + }; } \ No newline at end of file diff --git a/include/trUtil/DefaultSettings.h b/include/trUtil/DefaultSettings.h index b27986b..e763bbb 100644 --- a/include/trUtil/DefaultSettings.h +++ b/include/trUtil/DefaultSettings.h @@ -1,72 +1,72 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::DefaultSettings -{ - /** - * @fn void SetDefaultSettings(dtABC::BaseABC& app); - * - * @brief Sets the default Scene, Camera, and Window Settings. - * - * @param [in,out] app The application. - */ - //void TR_UTIL_EXPORT SetDefaultSettings(dtABC::BaseABC& app); - - /** - * @fn void ParseMapNameArgument(int argc, char** argv, std::string &mapName); - * - * @brief Finds and returns the name of the map to be loaded from the command line. - * - * @param argc The argc. - * @param [in,out] argv If non-null, the argv. - * @param [in,out] mapName Name of the map. - */ - void TR_UTIL_EXPORT ParseMapNameArgument(int argc, char** argv, std::string &mapName); - - /** - * @fn void SetDefaultPaths(); - * - * @brief Sets engines default paths and project context. - */ - //void TR_UTIL_EXPORT SetDefaultPaths(); - - /** - * @fn void SetupLoggingOptions(const std::string& logFileName, const std::string& logLevel); - * - * @brief Sets up all the default logging options for the software. - * - * @return A TR_UTIL_EXPORT. - * - * @param logFileName Filename of the log file. - * @param logLevel The log level. - */ - void TR_UTIL_EXPORT SetupLoggingOptions(const std::string& logFileName, const std::string& logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::DefaultSettings +{ + /** + * @fn void SetDefaultSettings(dtABC::BaseABC& app); + * + * @brief Sets the default Scene, Camera, and Window Settings. + * + * @param [in,out] app The application. + */ + //void TR_UTIL_EXPORT SetDefaultSettings(dtABC::BaseABC& app); + + /** + * @fn void ParseMapNameArgument(int argc, char** argv, std::string &mapName); + * + * @brief Finds and returns the name of the map to be loaded from the command line. + * + * @param argc The argc. + * @param [in,out] argv If non-null, the argv. + * @param [in,out] mapName Name of the map. + */ + void TR_UTIL_EXPORT ParseMapNameArgument(int argc, char** argv, std::string &mapName); + + /** + * @fn void SetDefaultPaths(); + * + * @brief Sets engines default paths and project context. + */ + //void TR_UTIL_EXPORT SetDefaultPaths(); + + /** + * @fn void SetupLoggingOptions(const std::string& logFileName, const std::string& logLevel); + * + * @brief Sets up all the default logging options for the software. + * + * @return A TR_UTIL_EXPORT. + * + * @param logFileName Filename of the log file. + * @param logLevel The log level. + */ + void TR_UTIL_EXPORT SetupLoggingOptions(const std::string& logFileName, const std::string& logLevel); } \ No newline at end of file diff --git a/include/trUtil/EnumerationNumeric.h b/include/trUtil/EnumerationNumeric.h index 1aad9d9..fb51b7e 100644 --- a/include/trUtil/EnumerationNumeric.h +++ b/include/trUtil/EnumerationNumeric.h @@ -1,283 +1,283 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include "Export.h" - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @class EnumerationNumeric - * - * @brief This class represents a type-safe Enumeration pattern. It allows one to also - * enumerate an Enumeration thus looking up values in a list fashion. Unlike - * EnumerationString, EnumerationNumeric also stores an integer value with each Enum. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT EnumerationNumeric : public EnumerationString - { - public: - /** @brief / Adds an easy and swappable access to the base class. */ - using BaseClass = EnumerationString; - - /** - * @fn unsigned int EnumerationNumeric::GetID() const; - * - * @brief Returns the Numeric value of the Enum. - * - * @return The identifier. - */ - unsigned int GetID() const; - - /** - * @fn bool EnumerationNumeric::operator==(const unsigned int &id) const - * - * @brief Equality test for an EnumerationNumeric. This comparison option takes in an unsigned - * integer. Inlined because it's called frequently. - * - * @param id The identifier. - * - * @return True if the parameters are considered equivalent. - */ - bool operator==(const unsigned int &id) const - { - return (mID == id); - } - - /** - * @fn bool EnumerationNumeric::operator!=(const unsigned int &id) const - * - * @brief Inequality test for an EnumerationNumeric. This comparison option takes in an - * unsigned integer. Inlined because it's called frequently. - * - * @param id The identifier. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const unsigned int &id) const - { - return (mID != id); - } - - /** - * @fn bool EnumerationNumeric::operator>(const unsigned int &id) const - * - * @brief Greater than test for an EnumerationNumeric. This comparison option takes in an - * unsigned integer. Inlined because it's called frequently. - * - * @param id The identifier. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator>(const unsigned int &id) const - { - return (mID > id); - } - - /** - * @fn bool EnumerationNumeric::operator<(const unsigned int &id) const - * - * @brief Less than test for an EnumerationNumeric. This comparison option takes in an unsigned - * integer. Inlined because it's called frequently. - * - * @param id The identifier. - * - * @return True if the first parameter is less than the second. - */ - bool operator<(const unsigned int &id) const - { - return (mID < id); - } - - /** - * @fn bool EnumerationNumeric::operator>(const EnumerationNumeric &e) const - * - * @brief Greater than test for an EnumerationNumeric. This comparison option takes in an - * EnumerationNumeric. Inlined because it's called frequently. - * - * @param e The EnumerationNumeric to process. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator>(const EnumerationNumeric &e) const - { - return (mID > e.mID); - } - - /** - * @fn bool EnumerationNumeric::operator<(const EnumerationNumeric &e) const - * - * @brief Less than test for an EnumerationNumeric. This comparison option takes in an - * EnumerationNumeric. Inlined because it's called frequently. - * - * @param e The EnumerationNumeric to process. - * - * @return True if the first parameter is less than the second. - */ - bool operator<(const EnumerationNumeric &e) const - { - return (mID < e.mID); - } - - /** - * @fn bool EnumerationNumeric::operator==(const EnumerationNumeric &e) const - * - * @brief Equality test for an EnumerationNumeric. This comparison option takes in an - * EnumerationNumeric. Inlined because it's called frequently. - * - * @param e The EnumerationNumeric to process. - * - * @return True if the parameters are considered equivalent. - */ - bool operator==(const EnumerationNumeric &e) const - { - return (this == &e); - } - - /** - * @fn bool EnumerationNumeric::operator!=(const EnumerationNumeric &e) const - * - * @brief Inequality test for an EnumerationNumeric. This comparison option takes in an - * EnumerationNumeric. Inlined because it's called frequently. - * - * @param e The EnumerationNumeric to process. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const EnumerationNumeric &e) const - { - return (this != &e); - } - - /** - * @fn bool EnumerationNumeric::operator==(const std::string& rhs) const; - * - * @brief Overloaded string compare operator for the EnumerationNumeric. This will compare the - * string to this EnumerationNumeric getName() value. - * - * @param rhs . - * - * @return True if they are equal. - * @note - * Uses the STL string compare method implying that the rules for string equality are - * the same as they are for the STL string compare method. - */ - bool operator==(const std::string& rhs) const; - - /** - * @fn bool EnumerationNumeric::operator!=(const std::string& rhs) const; - * - * @brief Overloaded inequality test for this EnumerationNumeric's string value. - * - * @param rhs The right hand side. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const std::string& rhs) const; - - /** - * @fn bool EnumerationNumeric::operator<(const std::string& rhs) const; - * - * @brief Overloaded less than test for this EnumerationNumeric's string value. - * - * @param rhs The right hand side. - * - * @return True if the first parameter is less than the second. - */ - bool operator<(const std::string& rhs) const; - - /** - * @fn bool EnumerationNumeric::operator>(const std::string& rhs) const; - * - * @brief Overloaded greater than test for this EnumerationNumeric's string value. - * - * @param rhs The right hand side. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator>(const std::string& rhs) const; - - protected: - - /** - * @fn EnumerationNumeric::EnumerationNumeric(const std::string& name, unsigned int orderId); - * - * @brief ctor Protected to prevent creation of an instance. - * - * @param name The name. - * @param orderId Identifier for the order. - */ - EnumerationNumeric(const std::string& name, unsigned int orderId); - - /** - * @fn EnumerationNumeric::~EnumerationNumeric(); - * - * @brief dtor. - */ - ~EnumerationNumeric(); - - private: - /** @brief The identifier. */ - unsigned int mID; - - /** - * @fn EnumerationNumeric& EnumerationNumeric::operator=(const EnumerationNumeric&); - * - * @brief Private assignment operator to enforce EnumerationNumeric storage by reference. - * - * @param parameter1 The first parameter. - * - * @return A shallow copy of this object. - */ - EnumerationNumeric& operator=(const EnumerationNumeric&); - - /** - * @fn EnumerationNumeric::EnumerationNumeric(const EnumerationNumeric&); - * - * @brief Private copy constructor to enforce EnumerationNumeric storage by reference. - * - * @param parameter1 The first parameter. - */ - EnumerationNumeric(const EnumerationNumeric&); - }; - - /** - * @fn std::ostream& operator<<(std::ostream& os, const EnumerationString& e); - * - * @brief Helper method to print EnumerationNumeric to an output stream. - * - * @param [in,out] os The operating system. - * @param e The EnumerationString to process. - * - * @return The shifted result. - */ - TR_UTIL_EXPORT std::ostream& operator<<(std::ostream& os, const EnumerationString& e); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include "Export.h" + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @class EnumerationNumeric + * + * @brief This class represents a type-safe Enumeration pattern. It allows one to also + * enumerate an Enumeration thus looking up values in a list fashion. Unlike + * EnumerationString, EnumerationNumeric also stores an integer value with each Enum. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT EnumerationNumeric : public EnumerationString + { + public: + /** @brief / Adds an easy and swappable access to the base class. */ + using BaseClass = EnumerationString; + + /** + * @fn unsigned int EnumerationNumeric::GetID() const; + * + * @brief Returns the Numeric value of the Enum. + * + * @return The identifier. + */ + unsigned int GetID() const; + + /** + * @fn bool EnumerationNumeric::operator==(const unsigned int &id) const + * + * @brief Equality test for an EnumerationNumeric. This comparison option takes in an unsigned + * integer. Inlined because it's called frequently. + * + * @param id The identifier. + * + * @return True if the parameters are considered equivalent. + */ + bool operator==(const unsigned int &id) const + { + return (mID == id); + } + + /** + * @fn bool EnumerationNumeric::operator!=(const unsigned int &id) const + * + * @brief Inequality test for an EnumerationNumeric. This comparison option takes in an + * unsigned integer. Inlined because it's called frequently. + * + * @param id The identifier. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const unsigned int &id) const + { + return (mID != id); + } + + /** + * @fn bool EnumerationNumeric::operator>(const unsigned int &id) const + * + * @brief Greater than test for an EnumerationNumeric. This comparison option takes in an + * unsigned integer. Inlined because it's called frequently. + * + * @param id The identifier. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator>(const unsigned int &id) const + { + return (mID > id); + } + + /** + * @fn bool EnumerationNumeric::operator<(const unsigned int &id) const + * + * @brief Less than test for an EnumerationNumeric. This comparison option takes in an unsigned + * integer. Inlined because it's called frequently. + * + * @param id The identifier. + * + * @return True if the first parameter is less than the second. + */ + bool operator<(const unsigned int &id) const + { + return (mID < id); + } + + /** + * @fn bool EnumerationNumeric::operator>(const EnumerationNumeric &e) const + * + * @brief Greater than test for an EnumerationNumeric. This comparison option takes in an + * EnumerationNumeric. Inlined because it's called frequently. + * + * @param e The EnumerationNumeric to process. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator>(const EnumerationNumeric &e) const + { + return (mID > e.mID); + } + + /** + * @fn bool EnumerationNumeric::operator<(const EnumerationNumeric &e) const + * + * @brief Less than test for an EnumerationNumeric. This comparison option takes in an + * EnumerationNumeric. Inlined because it's called frequently. + * + * @param e The EnumerationNumeric to process. + * + * @return True if the first parameter is less than the second. + */ + bool operator<(const EnumerationNumeric &e) const + { + return (mID < e.mID); + } + + /** + * @fn bool EnumerationNumeric::operator==(const EnumerationNumeric &e) const + * + * @brief Equality test for an EnumerationNumeric. This comparison option takes in an + * EnumerationNumeric. Inlined because it's called frequently. + * + * @param e The EnumerationNumeric to process. + * + * @return True if the parameters are considered equivalent. + */ + bool operator==(const EnumerationNumeric &e) const + { + return (this == &e); + } + + /** + * @fn bool EnumerationNumeric::operator!=(const EnumerationNumeric &e) const + * + * @brief Inequality test for an EnumerationNumeric. This comparison option takes in an + * EnumerationNumeric. Inlined because it's called frequently. + * + * @param e The EnumerationNumeric to process. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const EnumerationNumeric &e) const + { + return (this != &e); + } + + /** + * @fn bool EnumerationNumeric::operator==(const std::string& rhs) const; + * + * @brief Overloaded string compare operator for the EnumerationNumeric. This will compare the + * string to this EnumerationNumeric getName() value. + * + * @param rhs . + * + * @return True if they are equal. + * @note + * Uses the STL string compare method implying that the rules for string equality are + * the same as they are for the STL string compare method. + */ + bool operator==(const std::string& rhs) const; + + /** + * @fn bool EnumerationNumeric::operator!=(const std::string& rhs) const; + * + * @brief Overloaded inequality test for this EnumerationNumeric's string value. + * + * @param rhs The right hand side. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const std::string& rhs) const; + + /** + * @fn bool EnumerationNumeric::operator<(const std::string& rhs) const; + * + * @brief Overloaded less than test for this EnumerationNumeric's string value. + * + * @param rhs The right hand side. + * + * @return True if the first parameter is less than the second. + */ + bool operator<(const std::string& rhs) const; + + /** + * @fn bool EnumerationNumeric::operator>(const std::string& rhs) const; + * + * @brief Overloaded greater than test for this EnumerationNumeric's string value. + * + * @param rhs The right hand side. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator>(const std::string& rhs) const; + + protected: + + /** + * @fn EnumerationNumeric::EnumerationNumeric(const std::string& name, unsigned int orderId); + * + * @brief ctor Protected to prevent creation of an instance. + * + * @param name The name. + * @param orderId Identifier for the order. + */ + EnumerationNumeric(const std::string& name, unsigned int orderId); + + /** + * @fn EnumerationNumeric::~EnumerationNumeric(); + * + * @brief dtor. + */ + ~EnumerationNumeric(); + + private: + /** @brief The identifier. */ + unsigned int mID; + + /** + * @fn EnumerationNumeric& EnumerationNumeric::operator=(const EnumerationNumeric&); + * + * @brief Private assignment operator to enforce EnumerationNumeric storage by reference. + * + * @param parameter1 The first parameter. + * + * @return A shallow copy of this object. + */ + EnumerationNumeric& operator=(const EnumerationNumeric&); + + /** + * @fn EnumerationNumeric::EnumerationNumeric(const EnumerationNumeric&); + * + * @brief Private copy constructor to enforce EnumerationNumeric storage by reference. + * + * @param parameter1 The first parameter. + */ + EnumerationNumeric(const EnumerationNumeric&); + }; + + /** + * @fn std::ostream& operator<<(std::ostream& os, const EnumerationString& e); + * + * @brief Helper method to print EnumerationNumeric to an output stream. + * + * @param [in,out] os The operating system. + * @param e The EnumerationString to process. + * + * @return The shifted result. + */ + TR_UTIL_EXPORT std::ostream& operator<<(std::ostream& os, const EnumerationString& e); } \ No newline at end of file diff --git a/include/trUtil/EnumerationString.h b/include/trUtil/EnumerationString.h index 9ad117e..91178aa 100644 --- a/include/trUtil/EnumerationString.h +++ b/include/trUtil/EnumerationString.h @@ -1,654 +1,654 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once - -#include "Export.h" - -#include - -#include -#include -#include - -/** - * @brief Disable visual C++ compiler warnings that seem to indicate the compiler is getting - * confused when compiling an EnumerationString. - */ -TR_DISABLE_WARNING_START_MSVC(4276) - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @class EnumerationString - * - * @brief This class represents a type-safe EnumerationString pattern. It allows one to also - * enumerate an EnumerationString thus looking up values in a list fashion. - */ - class TR_UTIL_EXPORT EnumerationString - { - public: - - /** - * @fn const std::string& EnumerationString::GetName() const - * - * @brief Inlined because it's called frequently. - * - * @return the string representation of this EnumerationString. - */ - const std::string& GetName() const - { - return mName; - } - - /** - * @fn bool EnumerationString::operator==(const EnumerationString& rhs) const - * - * @brief Equality test for an EnumerationString. Since EnumerationString objects are static, - * and only references to EnumerationStrings may be stored by the user, it is safe and - * efficient to compare EnumerationString objects based on their memory address. Inlined - * because it's called frequently. - * - * @param rhs The right hand side. - * - * @return True if the parameters are considered equivalent. - */ - bool operator==(const EnumerationString& rhs) const - { - return this == &rhs; - } - - /** - * @fn bool EnumerationString::operator!=(const EnumerationString& rhs) const - * - * @brief Inequality test for an EnumerationString. Inlined because it's called frequently. - * - * @param rhs The right hand side. - * - * @return True if the parameters are not considered equivalent. - * - * @sa operator== - */ - bool operator!=(const EnumerationString& rhs) const - { - return this != &rhs; - } - - /** - * @fn bool EnumerationString::operator==(const std::string& rhs) const; - * - * @brief Overloaded string compare operator for the EnumerationString. This will compare the - * string to this EnumerationStrings getName() value. - * - * @param rhs . - * - * @return True if they are equal. - * @note - * Uses the STL string compare method implying that the rules for string equality are - * the same as they are for the STL string compare method. - */ - bool operator==(const std::string& rhs) const; - - /** - * @fn bool EnumerationString::operator!=(const std::string& rhs) const; - * - * @brief Overloaded inequality test for this EnumerationString's string value. - * - * @param rhs The right hand side. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const std::string& rhs) const; - - /** - * @fn bool EnumerationString::operator<(const std::string& rhs) const; - * - * @brief Overloaded less than test for this EnumerationString's string value. - * - * @param rhs The right hand side. - * - * @return True if the first parameter is less than the second. - */ - bool operator<(const std::string& rhs) const; - - /** - * @fn bool EnumerationString::operator>(const std::string& rhs) const; - * - * @brief Overloaded greater than test for this EnumerationString's string value. - * - * @param rhs The right hand side. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator>(const std::string& rhs) const; - - /** - * @fn bool EnumerationString::operator<(const EnumerationString& rhs) const - * - * @brief Overloaded less than operator. This checks the memory addresses of the two - * EnumerationStrings. Inlined because it's called frequently. - * - * @param rhs The second EnumerationString to compare to this one. - * - * @return True if this EnumerationString is less than rhs. - * @note - * This method is supported by EnumerationStrings so they may be used as keys in STL - * containers. Since memory addresses are guaranteed to be unique this methods works - * fine. However, it really does not make sense to use this method of comparison in - * other circumstances. - */ - bool operator<(const EnumerationString& rhs) const - { - return this < &rhs; - } - protected: - - /** - * @fn virtual int EnumerationString::Compare(const std::string& nameString) const; - * - * @brief Virtual string compare method to used by the operators that take a string. This - * allows overriding the behavior in a subclass. It should work like - * std::string::compare. - * - * @param nameString The constant standard string& to compare to this object. - * - * @return Negative if 'nameString' is less than '', 0 if they are equal, or positive if it is - * greater. - */ - virtual int Compare(const std::string& nameString) const; - - /** - * @fn virtual EnumerationString::~EnumerationString(); - * - * @brief Private virtual destructor to get rid of compile warning. - */ - virtual ~EnumerationString(); - - /** - * @fn EnumerationString::EnumerationString(const std::string& name); - * - * @brief Construct the EnumerationString. - * @note - * When creating a new EnumerationString, the constructor of derived types must - * call addInstance(this) in order for EnumerationStrings to be enumerated. - * - * @param name The name. - */ - EnumerationString(const std::string& name); - private: - - /** - * @fn EnumerationString& EnumerationString::operator=(const EnumerationString&); - * - * @brief Private assignment operator to enforce EnumerationString storage by reference. - * - * @param parameter1 The first parameter. - * - * @return A shallow copy of this object. - */ - EnumerationString& operator=(const EnumerationString&); - - /** @brief String representation of the EnumerationString. */ - std::string mName; - - /** - * @fn EnumerationString::EnumerationString(const EnumerationString&); - * - * @brief Private copy constructor to enforce EnumerationString storage by reference. - * - * @param parameter1 The first parameter. - */ - EnumerationString(const EnumerationString&); - }; - - /** - * @fn std::ostream& operator<<(std::ostream& os, const EnumerationString& e); - * - * @brief Helper method to print EnumerationStrings to an output stream. - * - * @param [in,out] os The operating system. - * @param e The EnumerationString to process. - * - * @return The shifted result. - */ - TR_UTIL_EXPORT std::ostream& operator<<(std::ostream& os, const EnumerationString& e); - - ////////////////////////////////////////////////////// - -/** - * @def DECLARE_ENUM(EnumType); - * - * @brief Helper macros used to create the static data and methods needed to enumerate an - * EnumerationString. - * - * @param EnumType Type of the enum. - */ -#define DECLARE_ENUM(EnumType) \ -public: \ - using EnumerateListType = std::vector; \ - \ - static const EnumerateListType& EnumerateType() \ - { \ - return EnumType::mInstances; \ - } \ - \ - static const std::vector& Enumerate() \ - { \ - return EnumType::mGenericInstances; \ - } \ - \ - static EnumType* GetValueForName(const std::string& name); \ - \ -private: \ - static EnumerateListType mInstances; \ - static std::vector mGenericInstances; \ - static void AddInstance(EnumType* instance); \ -public: - -/** - * @def IMPLEMENT_ENUM(EnumType); - * - * @brief A macro that defines implement enum. - * - * @param EnumType Type of the enum. - */ -#define IMPLEMENT_ENUM(EnumType) \ - EnumType::EnumerateListType EnumType::mInstances; \ - std::vector EnumType::mGenericInstances; \ - void EnumType::AddInstance(EnumType* instance) \ - { \ - EnumType::mInstances.push_back(instance); \ - EnumType::mGenericInstances.push_back(instance); \ - } \ - EnumType* EnumType::GetValueForName(const std::string& name) \ - { \ - for (unsigned i = 0; i < mInstances.size(); ++i) \ - { \ - if ((*mInstances[i]) == name) \ - { \ - return mInstances[i]; \ - } \ - } \ - return nullptr; \ - } - - ////////////////////////////////////////////////////// - - /** - * @class EnumerationPointer - * - * @brief EnumerationString Pointer class holds a reference to a passed in Enumeration. This is - * a container class for TR Enumerations. - */ - template - class EnumerationPointer - { - public: - /** @brief Type of the element. */ - using element_type = T; - - /** - * @fn EnumerationPointer::EnumerationPointer() - * - * @brief A constructor that creates and empty pointer. - */ - EnumerationPointer() : mEnum(nullptr) - { - } - - /** - * @fn EnumerationPointer::EnumerationPointer(T* ptr) - * - * @brief A constructor that creates a pointer from a passed in EnumerationString. - * - * @param [in,out] ptr If non-null, the pointer. - */ - EnumerationPointer(T* ptr) : mEnum(ptr) - { - } - - /** - * @fn EnumerationPointer::EnumerationPointer(const EnumerationPointer& rp) - * - * @brief A constructor that creates a pointer from another EnumerationString Pointer. - * - * @param rp The rp. - */ - EnumerationPointer(const EnumerationPointer& rp) : mEnum(rp.mEnum) - { - } - - /** - * @fn template EnumerationPointer::EnumerationPointer(const EnumerationPointer& rp) - * - * @brief A templated pointer constructor that can create an EnumerationString pointer from an - * EnumerationString pointer of a different type. - * - * @tparam Other Type of the other. - * @param rp The rp. - */ - template EnumerationPointer(const EnumerationPointer& rp) : mEnum(rp.mEnum) - { - } - - /** - * @fn EnumerationPointer::~EnumerationPointer() - * - * @brief Destructor. - */ - ~EnumerationPointer() - { - mEnum = nullptr; - } - - /** - * @fn operator EnumerationPointer::T*() const - * - * @brief Pointer operator. - * - * @return The result of the operation. - */ - operator T*() const - { - return mEnum; - } - - /** - * @fn operator EnumerationPointer::T&() const - * - * @brief Reference Operator. - * - * @return The result of the operation. - */ - operator T&() const - { - return *mEnum; - } - - /** - * @fn EnumerationPointer& EnumerationPointer::operator=(const EnumerationPointer& rp) - * - * @brief Assignment by reference operator. - * - * @param rp The rp. - * - * @return A shallow copy of this object. - */ - EnumerationPointer& operator=(const EnumerationPointer& rp) - { - mEnum = rp.mEnum; - return *this; - } - - /** - * @fn template EnumerationPointer& EnumerationPointer::operator=(const EnumerationPointer& rp) - * - * @brief Assignment by reference operator. - * - * @tparam Other Type of the other. - * @param rp The rp. - * - * @return The result of the operation. - */ - template EnumerationPointer& operator=(const EnumerationPointer& rp) - { - /** @brief . */ - mEnum = rp.mEnum; - /** @brief this. */ - return *this; - } - - /** - * @fn inline EnumerationPointer& EnumerationPointer::operator=(T* ptr) - * - * @brief Assignment from a pointer operator. - * - * @param [in,out] ptr If non-null, the pointer. - * - * @return A shallow copy of this object. - */ - inline EnumerationPointer& operator=(T* ptr) - { - if (mEnum == ptr) return *this; - mEnum = ptr; - return *this; - } - - /** - * @fn inline EnumerationPointer& EnumerationPointer::operator=(T& enumRef) - * - * @brief Assignment from a reference operator. - * - * @param [in,out] enumRef The enum reference. - * - * @return A shallow copy of this object. - */ - inline EnumerationPointer& operator=(T& enumRef) - { - if (mEnum == &enumRef) return *this; - mEnum = &enumRef; - return *this; - } - - /** - * @fn bool EnumerationPointer::operator==(const EnumerationPointer& rp) const - * - * @brief Comparison between two EnumerationPointers. - * - * @param rp The rp. - * - * @return True if the parameters are considered equivalent. - */ - bool operator==(const EnumerationPointer& rp) const - { - return (mEnum == rp.mEnum); - } - - /** - * @fn bool EnumerationPointer::operator==(const T* ptr) const - * - * @brief Comparison between EnumerationPointers and a pointer. - * - * @param ptr The pointer. - * - * @return True if the parameters are considered equivalent. - */ - bool operator==(const T* ptr) const - { - return (mEnum == ptr); - } - - /** - * @fn friend bool EnumerationPointer::operator==(const T* ptr, const EnumerationPointer& rp) - * - * @brief Comparison between EnumerationPointer and a pointer. - * - * @param ptr The first instance to compare. - * @param rp The second instance to compare. - * - * @return True if the parameters are considered equivalent. - */ - friend bool operator==(const T* ptr, const EnumerationPointer& rp) - { - return (ptr == rp.mEnum); - } - - /** - * @fn bool EnumerationPointer::operator!=(const EnumerationPointer& rp) const - * - * @brief Comparison between two EnumerationPointers. - * - * @param rp The rp. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const EnumerationPointer& rp) const - { - return (mEnum != rp.mEnum); - } - - /** - * @fn bool EnumerationPointer::operator!=(const T* ptr) const - * - * @brief Comparison between EnumerationPointers and a pointer. - * - * @param ptr The pointer. - * - * @return True if the parameters are not considered equivalent. - */ - bool operator!=(const T* ptr) const - { - return (mEnum != ptr); - } - - /** - * @fn friend bool EnumerationPointer::operator!=(const T* ptr, const EnumerationPointer& rp) - * - * @brief Comparison between EnumerationPointer and a pointer. - * - * @param ptr The first instance to compare. - * @param rp The second instance to compare. - * - * @return True if the parameters are not considered equivalent. - */ - friend bool operator!=(const T* ptr, const EnumerationPointer& rp) - { - return (ptr != rp.mEnum); - } - - /** - * @fn bool EnumerationPointer::operator<(const EnumerationPointer& rp) const - * - * @brief Overloaded less than test for this EnumerationString pointers's string value. - * - * @param rp The rp. - * - * @return True if the first parameter is less than the second. - */ - bool operator<(const EnumerationPointer& rp) const - { - return (mEnum < rp.mEnum); - } - - /** - * @fn bool EnumerationPointer::operator>(const EnumerationPointer& rp) const - * - * @brief Overloaded greater than test for this EnumerationString pointers's string value. - * - * @param rp The rp. - * - * @return True if the first parameter is greater than to the second. - */ - bool operator>(const EnumerationPointer& rp) const - { - return (mEnum > rp.mEnum); - } - - /** - * @fn T& EnumerationPointer::operator*() const - * - * @brief Pointer operator that returns a reference. - * - * @return The result of the operation. - */ - T& operator*() const - { - return *mEnum; - } - - /** - * @fn T* EnumerationPointer::operator->() const - * - * @brief Pointer method access operator. - * - * @return The dereferenced object. - */ - T* operator->() const - { - return mEnum; - } - - /** - * @fn T* EnumerationPointer::get() const - * - * @brief Pointer access operator. - * - * @return Null if it fails, else a pointer to a T. - */ - T* get() const - { - return mEnum; - } - - /** - * @fn bool EnumerationPointer::operator!() const - * - * @brief The NOT operator. - * - * @return The logical inverse of this value. - */ - bool operator!() const - { - return mEnum == nullptr; - } // not required - - /** - * @fn bool EnumerationPointer::valid() const - * - * @brief Returns FALSE if the pointer is nullptr. - * - * @return True if it succeeds, false if it fails. - */ - bool valid() const - { - return mEnum != nullptr; - } - - /** - * @fn void EnumerationPointer::swap(EnumerationPointer& rp) - * - * @brief Swaps the internal object with the passed in. - * - * @param [in,out] rp The rp. - */ - void swap(EnumerationPointer& rp) - { - T* tmp = mEnum; - mEnum = rp.mEnum; - rp.mEnum = tmp; - } - private: - /** @brief The enum. */ - T* mEnum; - }; -} +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once + +#include "Export.h" + +#include + +#include +#include +#include + +/** + * @brief Disable visual C++ compiler warnings that seem to indicate the compiler is getting + * confused when compiling an EnumerationString. + */ +TR_DISABLE_WARNING_START_MSVC(4276) + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @class EnumerationString + * + * @brief This class represents a type-safe EnumerationString pattern. It allows one to also + * enumerate an EnumerationString thus looking up values in a list fashion. + */ + class TR_UTIL_EXPORT EnumerationString + { + public: + + /** + * @fn const std::string& EnumerationString::GetName() const + * + * @brief Inlined because it's called frequently. + * + * @return the string representation of this EnumerationString. + */ + const std::string& GetName() const + { + return mName; + } + + /** + * @fn bool EnumerationString::operator==(const EnumerationString& rhs) const + * + * @brief Equality test for an EnumerationString. Since EnumerationString objects are static, + * and only references to EnumerationStrings may be stored by the user, it is safe and + * efficient to compare EnumerationString objects based on their memory address. Inlined + * because it's called frequently. + * + * @param rhs The right hand side. + * + * @return True if the parameters are considered equivalent. + */ + bool operator==(const EnumerationString& rhs) const + { + return this == &rhs; + } + + /** + * @fn bool EnumerationString::operator!=(const EnumerationString& rhs) const + * + * @brief Inequality test for an EnumerationString. Inlined because it's called frequently. + * + * @param rhs The right hand side. + * + * @return True if the parameters are not considered equivalent. + * + * @sa operator== + */ + bool operator!=(const EnumerationString& rhs) const + { + return this != &rhs; + } + + /** + * @fn bool EnumerationString::operator==(const std::string& rhs) const; + * + * @brief Overloaded string compare operator for the EnumerationString. This will compare the + * string to this EnumerationStrings getName() value. + * + * @param rhs . + * + * @return True if they are equal. + * @note + * Uses the STL string compare method implying that the rules for string equality are + * the same as they are for the STL string compare method. + */ + bool operator==(const std::string& rhs) const; + + /** + * @fn bool EnumerationString::operator!=(const std::string& rhs) const; + * + * @brief Overloaded inequality test for this EnumerationString's string value. + * + * @param rhs The right hand side. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const std::string& rhs) const; + + /** + * @fn bool EnumerationString::operator<(const std::string& rhs) const; + * + * @brief Overloaded less than test for this EnumerationString's string value. + * + * @param rhs The right hand side. + * + * @return True if the first parameter is less than the second. + */ + bool operator<(const std::string& rhs) const; + + /** + * @fn bool EnumerationString::operator>(const std::string& rhs) const; + * + * @brief Overloaded greater than test for this EnumerationString's string value. + * + * @param rhs The right hand side. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator>(const std::string& rhs) const; + + /** + * @fn bool EnumerationString::operator<(const EnumerationString& rhs) const + * + * @brief Overloaded less than operator. This checks the memory addresses of the two + * EnumerationStrings. Inlined because it's called frequently. + * + * @param rhs The second EnumerationString to compare to this one. + * + * @return True if this EnumerationString is less than rhs. + * @note + * This method is supported by EnumerationStrings so they may be used as keys in STL + * containers. Since memory addresses are guaranteed to be unique this methods works + * fine. However, it really does not make sense to use this method of comparison in + * other circumstances. + */ + bool operator<(const EnumerationString& rhs) const + { + return this < &rhs; + } + protected: + + /** + * @fn virtual int EnumerationString::Compare(const std::string& nameString) const; + * + * @brief Virtual string compare method to used by the operators that take a string. This + * allows overriding the behavior in a subclass. It should work like + * std::string::compare. + * + * @param nameString The constant standard string& to compare to this object. + * + * @return Negative if 'nameString' is less than '', 0 if they are equal, or positive if it is + * greater. + */ + virtual int Compare(const std::string& nameString) const; + + /** + * @fn virtual EnumerationString::~EnumerationString(); + * + * @brief Private virtual destructor to get rid of compile warning. + */ + virtual ~EnumerationString(); + + /** + * @fn EnumerationString::EnumerationString(const std::string& name); + * + * @brief Construct the EnumerationString. + * @note + * When creating a new EnumerationString, the constructor of derived types must + * call addInstance(this) in order for EnumerationStrings to be enumerated. + * + * @param name The name. + */ + EnumerationString(const std::string& name); + private: + + /** + * @fn EnumerationString& EnumerationString::operator=(const EnumerationString&); + * + * @brief Private assignment operator to enforce EnumerationString storage by reference. + * + * @param parameter1 The first parameter. + * + * @return A shallow copy of this object. + */ + EnumerationString& operator=(const EnumerationString&); + + /** @brief String representation of the EnumerationString. */ + std::string mName; + + /** + * @fn EnumerationString::EnumerationString(const EnumerationString&); + * + * @brief Private copy constructor to enforce EnumerationString storage by reference. + * + * @param parameter1 The first parameter. + */ + EnumerationString(const EnumerationString&); + }; + + /** + * @fn std::ostream& operator<<(std::ostream& os, const EnumerationString& e); + * + * @brief Helper method to print EnumerationStrings to an output stream. + * + * @param [in,out] os The operating system. + * @param e The EnumerationString to process. + * + * @return The shifted result. + */ + TR_UTIL_EXPORT std::ostream& operator<<(std::ostream& os, const EnumerationString& e); + + ////////////////////////////////////////////////////// + +/** + * @def DECLARE_ENUM(EnumType); + * + * @brief Helper macros used to create the static data and methods needed to enumerate an + * EnumerationString. + * + * @param EnumType Type of the enum. + */ +#define DECLARE_ENUM(EnumType) \ +public: \ + using EnumerateListType = std::vector; \ + \ + static const EnumerateListType& EnumerateType() \ + { \ + return EnumType::mInstances; \ + } \ + \ + static const std::vector& Enumerate() \ + { \ + return EnumType::mGenericInstances; \ + } \ + \ + static EnumType* GetValueForName(const std::string& name); \ + \ +private: \ + static EnumerateListType mInstances; \ + static std::vector mGenericInstances; \ + static void AddInstance(EnumType* instance); \ +public: + +/** + * @def IMPLEMENT_ENUM(EnumType); + * + * @brief A macro that defines implement enum. + * + * @param EnumType Type of the enum. + */ +#define IMPLEMENT_ENUM(EnumType) \ + EnumType::EnumerateListType EnumType::mInstances; \ + std::vector EnumType::mGenericInstances; \ + void EnumType::AddInstance(EnumType* instance) \ + { \ + EnumType::mInstances.push_back(instance); \ + EnumType::mGenericInstances.push_back(instance); \ + } \ + EnumType* EnumType::GetValueForName(const std::string& name) \ + { \ + for (unsigned i = 0; i < mInstances.size(); ++i) \ + { \ + if ((*mInstances[i]) == name) \ + { \ + return mInstances[i]; \ + } \ + } \ + return nullptr; \ + } + + ////////////////////////////////////////////////////// + + /** + * @class EnumerationPointer + * + * @brief EnumerationString Pointer class holds a reference to a passed in Enumeration. This is + * a container class for TR Enumerations. + */ + template + class EnumerationPointer + { + public: + /** @brief Type of the element. */ + using element_type = T; + + /** + * @fn EnumerationPointer::EnumerationPointer() + * + * @brief A constructor that creates and empty pointer. + */ + EnumerationPointer() : mEnum(nullptr) + { + } + + /** + * @fn EnumerationPointer::EnumerationPointer(T* ptr) + * + * @brief A constructor that creates a pointer from a passed in EnumerationString. + * + * @param [in,out] ptr If non-null, the pointer. + */ + EnumerationPointer(T* ptr) : mEnum(ptr) + { + } + + /** + * @fn EnumerationPointer::EnumerationPointer(const EnumerationPointer& rp) + * + * @brief A constructor that creates a pointer from another EnumerationString Pointer. + * + * @param rp The rp. + */ + EnumerationPointer(const EnumerationPointer& rp) : mEnum(rp.mEnum) + { + } + + /** + * @fn template EnumerationPointer::EnumerationPointer(const EnumerationPointer& rp) + * + * @brief A templated pointer constructor that can create an EnumerationString pointer from an + * EnumerationString pointer of a different type. + * + * @tparam Other Type of the other. + * @param rp The rp. + */ + template EnumerationPointer(const EnumerationPointer& rp) : mEnum(rp.mEnum) + { + } + + /** + * @fn EnumerationPointer::~EnumerationPointer() + * + * @brief Destructor. + */ + ~EnumerationPointer() + { + mEnum = nullptr; + } + + /** + * @fn operator EnumerationPointer::T*() const + * + * @brief Pointer operator. + * + * @return The result of the operation. + */ + operator T*() const + { + return mEnum; + } + + /** + * @fn operator EnumerationPointer::T&() const + * + * @brief Reference Operator. + * + * @return The result of the operation. + */ + operator T&() const + { + return *mEnum; + } + + /** + * @fn EnumerationPointer& EnumerationPointer::operator=(const EnumerationPointer& rp) + * + * @brief Assignment by reference operator. + * + * @param rp The rp. + * + * @return A shallow copy of this object. + */ + EnumerationPointer& operator=(const EnumerationPointer& rp) + { + mEnum = rp.mEnum; + return *this; + } + + /** + * @fn template EnumerationPointer& EnumerationPointer::operator=(const EnumerationPointer& rp) + * + * @brief Assignment by reference operator. + * + * @tparam Other Type of the other. + * @param rp The rp. + * + * @return The result of the operation. + */ + template EnumerationPointer& operator=(const EnumerationPointer& rp) + { + /** @brief . */ + mEnum = rp.mEnum; + /** @brief this. */ + return *this; + } + + /** + * @fn inline EnumerationPointer& EnumerationPointer::operator=(T* ptr) + * + * @brief Assignment from a pointer operator. + * + * @param [in,out] ptr If non-null, the pointer. + * + * @return A shallow copy of this object. + */ + inline EnumerationPointer& operator=(T* ptr) + { + if (mEnum == ptr) return *this; + mEnum = ptr; + return *this; + } + + /** + * @fn inline EnumerationPointer& EnumerationPointer::operator=(T& enumRef) + * + * @brief Assignment from a reference operator. + * + * @param [in,out] enumRef The enum reference. + * + * @return A shallow copy of this object. + */ + inline EnumerationPointer& operator=(T& enumRef) + { + if (mEnum == &enumRef) return *this; + mEnum = &enumRef; + return *this; + } + + /** + * @fn bool EnumerationPointer::operator==(const EnumerationPointer& rp) const + * + * @brief Comparison between two EnumerationPointers. + * + * @param rp The rp. + * + * @return True if the parameters are considered equivalent. + */ + bool operator==(const EnumerationPointer& rp) const + { + return (mEnum == rp.mEnum); + } + + /** + * @fn bool EnumerationPointer::operator==(const T* ptr) const + * + * @brief Comparison between EnumerationPointers and a pointer. + * + * @param ptr The pointer. + * + * @return True if the parameters are considered equivalent. + */ + bool operator==(const T* ptr) const + { + return (mEnum == ptr); + } + + /** + * @fn friend bool EnumerationPointer::operator==(const T* ptr, const EnumerationPointer& rp) + * + * @brief Comparison between EnumerationPointer and a pointer. + * + * @param ptr The first instance to compare. + * @param rp The second instance to compare. + * + * @return True if the parameters are considered equivalent. + */ + friend bool operator==(const T* ptr, const EnumerationPointer& rp) + { + return (ptr == rp.mEnum); + } + + /** + * @fn bool EnumerationPointer::operator!=(const EnumerationPointer& rp) const + * + * @brief Comparison between two EnumerationPointers. + * + * @param rp The rp. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const EnumerationPointer& rp) const + { + return (mEnum != rp.mEnum); + } + + /** + * @fn bool EnumerationPointer::operator!=(const T* ptr) const + * + * @brief Comparison between EnumerationPointers and a pointer. + * + * @param ptr The pointer. + * + * @return True if the parameters are not considered equivalent. + */ + bool operator!=(const T* ptr) const + { + return (mEnum != ptr); + } + + /** + * @fn friend bool EnumerationPointer::operator!=(const T* ptr, const EnumerationPointer& rp) + * + * @brief Comparison between EnumerationPointer and a pointer. + * + * @param ptr The first instance to compare. + * @param rp The second instance to compare. + * + * @return True if the parameters are not considered equivalent. + */ + friend bool operator!=(const T* ptr, const EnumerationPointer& rp) + { + return (ptr != rp.mEnum); + } + + /** + * @fn bool EnumerationPointer::operator<(const EnumerationPointer& rp) const + * + * @brief Overloaded less than test for this EnumerationString pointers's string value. + * + * @param rp The rp. + * + * @return True if the first parameter is less than the second. + */ + bool operator<(const EnumerationPointer& rp) const + { + return (mEnum < rp.mEnum); + } + + /** + * @fn bool EnumerationPointer::operator>(const EnumerationPointer& rp) const + * + * @brief Overloaded greater than test for this EnumerationString pointers's string value. + * + * @param rp The rp. + * + * @return True if the first parameter is greater than to the second. + */ + bool operator>(const EnumerationPointer& rp) const + { + return (mEnum > rp.mEnum); + } + + /** + * @fn T& EnumerationPointer::operator*() const + * + * @brief Pointer operator that returns a reference. + * + * @return The result of the operation. + */ + T& operator*() const + { + return *mEnum; + } + + /** + * @fn T* EnumerationPointer::operator->() const + * + * @brief Pointer method access operator. + * + * @return The dereferenced object. + */ + T* operator->() const + { + return mEnum; + } + + /** + * @fn T* EnumerationPointer::get() const + * + * @brief Pointer access operator. + * + * @return Null if it fails, else a pointer to a T. + */ + T* get() const + { + return mEnum; + } + + /** + * @fn bool EnumerationPointer::operator!() const + * + * @brief The NOT operator. + * + * @return The logical inverse of this value. + */ + bool operator!() const + { + return mEnum == nullptr; + } // not required + + /** + * @fn bool EnumerationPointer::valid() const + * + * @brief Returns FALSE if the pointer is nullptr. + * + * @return True if it succeeds, false if it fails. + */ + bool valid() const + { + return mEnum != nullptr; + } + + /** + * @fn void EnumerationPointer::swap(EnumerationPointer& rp) + * + * @brief Swaps the internal object with the passed in. + * + * @param [in,out] rp The rp. + */ + void swap(EnumerationPointer& rp) + { + T* tmp = mEnum; + mEnum = rp.mEnum; + rp.mEnum = tmp; + } + private: + /** @brief The enum. */ + T* mEnum; + }; +} TR_DISABLE_WARNING_END \ No newline at end of file diff --git a/include/trUtil/EnvVariables.h b/include/trUtil/EnvVariables.h index 840f033..5e7f76c 100644 --- a/include/trUtil/EnvVariables.h +++ b/include/trUtil/EnvVariables.h @@ -1,100 +1,100 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @brief Disable warning for stl classes Needs to have dll-interface to be used by clients of - * class. - */ - TR_DISABLE_WARNING_START_MSVC(4251) - - /** - * @class EnvVariables - * - * @brief An environment variables. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT EnvVariables - { - public: - - /** @brief Environmental Variable that points to the Root folder of the engine. */ - const static std::string TR_ROOT; - - /** @brief Environmental Variable that points to the Library folders of the engine. */ - const static std::string TR_LIB; - - /** @brief Environmental Variable that points to the Binary folders of the engine. */ - const static std::string TR_BIN; - - /** @brief Environmental Variable that points to the Include folders of the engine. */ - const static std::string TR_INC; - - /** - * @brief Environmental Variable that points to the Data folder of the engine The Data folder - * should have general art and system content If this variable is not present the engine - * will search for the Data Folder in TR_ROOT. - */ - const static std::string TR_DATA; - - /** - * @brief Environmental Variable that points to the User Data folder of the engine The Data - * folder should have the log files and general art and user content If this variable is - * not present the engine will search for the User Data Folder in Users Home and - * MyDocuments directories. - */ - const static std::string TR_USER_DATA; - - /** - * @brief Environmental Variable that should be upended to the PATH variable, to give the - * engine access to its resources. - */ - const static std::string TR_PATH; - - /** @brief Environmental Variable holds the path of the custom Log folder. */ - const static std::string TR_LOG_PATH; - - protected: - - /** - * @fn EnvVariables::EnvVariables() - * - * @brief Default constructor. - */ - EnvVariables(){}; - }; - TR_DISABLE_WARNING_END -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @brief Disable warning for stl classes Needs to have dll-interface to be used by clients of + * class. + */ + TR_DISABLE_WARNING_START_MSVC(4251) + + /** + * @class EnvVariables + * + * @brief An environment variables. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT EnvVariables + { + public: + + /** @brief Environmental Variable that points to the Root folder of the engine. */ + const static std::string TR_ROOT; + + /** @brief Environmental Variable that points to the Library folders of the engine. */ + const static std::string TR_LIB; + + /** @brief Environmental Variable that points to the Binary folders of the engine. */ + const static std::string TR_BIN; + + /** @brief Environmental Variable that points to the Include folders of the engine. */ + const static std::string TR_INC; + + /** + * @brief Environmental Variable that points to the Data folder of the engine The Data folder + * should have general art and system content If this variable is not present the engine + * will search for the Data Folder in TR_ROOT. + */ + const static std::string TR_DATA; + + /** + * @brief Environmental Variable that points to the User Data folder of the engine The Data + * folder should have the log files and general art and user content If this variable is + * not present the engine will search for the User Data Folder in Users Home and + * MyDocuments directories. + */ + const static std::string TR_USER_DATA; + + /** + * @brief Environmental Variable that should be upended to the PATH variable, to give the + * engine access to its resources. + */ + const static std::string TR_PATH; + + /** @brief Environmental Variable holds the path of the custom Log folder. */ + const static std::string TR_LOG_PATH; + + protected: + + /** + * @fn EnvVariables::EnvVariables() + * + * @brief Default constructor. + */ + EnvVariables(){}; + }; + TR_DISABLE_WARNING_END +} + diff --git a/include/trUtil/Exception.h b/include/trUtil/Exception.h index 6b188c1..3bd243d 100644 --- a/include/trUtil/Exception.h +++ b/include/trUtil/Exception.h @@ -1,159 +1,159 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @class Exception - * - * @brief This is the exception class used throughout the engine. Users should derive and - * create concrete instances. - */ - class TR_UTIL_EXPORT Exception - { - public: - - /** - * @fn Exception::Exception(const std::string& message, const std::string& filename, unsigned int linenum); - * - * @brief Constructor - Initializes the exception and logs it. - * - * @param message - Message to display about the exception. - * @param filename - File the exception was thrown from. - * @param linenum - Line number in the file from which the exception was thrown. - */ - Exception(const std::string& message, const std::string& filename, unsigned int linenum); - - /** - * @fn virtual Exception::~Exception(); - * - * @brief Destructor. - */ - virtual ~Exception(); - - /** - * @fn const std::string& Exception::What() const; - * - * @brief The message to be displayed when this exception is thrown. - * - * @return A reference to a const std::string. - */ - const std::string& What() const; - - /** - * @fn const std::string& Exception::File() const; - * - * @brief The filename associated with this exception. - * - * @return A reference to a const std::string. - */ - const std::string& File() const; - - /** - * @fn unsigned int Exception::Line() const; - * - * @brief The line number associated with this exception. - * - * @return An int. - */ - unsigned int Line() const; - - /** - * @fn std::string Exception::ToString() const; - * - * @brief Converts this exception to a string. The string contains the reason, line number and - * file the exception was thrown from. - * - * @return The string version of this exception. - */ - std::string ToString() const; - - /** - * @fn void Exception::Print() const; - * - * @brief Prints the exception to the console. - */ - void Print() const; - - /** - * @fn void Exception::LogException(trUtil::Logging::LogLevel level = trUtil::Logging::LogLevel::LOG_ERROR) const; - * - * @brief Logs the exception to the default logger. - * - * @param level (Optional) The level/type of logging. - */ - void LogException(trUtil::Logging::LogLevel level = trUtil::Logging::LogLevel::LOG_ERROR) const; - - /** - * @fn void Exception::LogException(trUtil::Logging::LogLevel level, const std::string& loggerName) const; - * - * @brief Logs the exception to the following log level using the logger. - * - * @param level The level/type of logging. - * @param loggerName the name passed to "getInstance" of the Logger. - */ - void LogException(trUtil::Logging::LogLevel level, const std::string& loggerName) const; - - /** - * @fn void Exception::LogException(trUtil::Logging::LogLevel level, trUtil::Logging::Log& logger) const; - * - * @brief Logs the exception to the following log level using the given logger. - * - * @param level The level/type of logging. - * @param [in,out] logger the actual log instance used to log. - */ - void LogException(trUtil::Logging::LogLevel level, trUtil::Logging::Log& logger) const; - - private: - std::string mMessage, mFileName; - unsigned int mLineNum; - }; - - /** - * @fn std::ostream& operator<< (std::ostream& o, const Exception& ex); - * - * @brief Stream insertion operator. - * - * @param [in,out] o The std::ostream to process. - * @param ex The ex. - * - * @return The shifted result. - */ - TR_UTIL_EXPORT std::ostream& operator << (std::ostream& o, const Exception& ex); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @class Exception + * + * @brief This is the exception class used throughout the engine. Users should derive and + * create concrete instances. + */ + class TR_UTIL_EXPORT Exception + { + public: + + /** + * @fn Exception::Exception(const std::string& message, const std::string& filename, unsigned int linenum); + * + * @brief Constructor - Initializes the exception and logs it. + * + * @param message - Message to display about the exception. + * @param filename - File the exception was thrown from. + * @param linenum - Line number in the file from which the exception was thrown. + */ + Exception(const std::string& message, const std::string& filename, unsigned int linenum); + + /** + * @fn virtual Exception::~Exception(); + * + * @brief Destructor. + */ + virtual ~Exception(); + + /** + * @fn const std::string& Exception::What() const; + * + * @brief The message to be displayed when this exception is thrown. + * + * @return A reference to a const std::string. + */ + const std::string& What() const; + + /** + * @fn const std::string& Exception::File() const; + * + * @brief The filename associated with this exception. + * + * @return A reference to a const std::string. + */ + const std::string& File() const; + + /** + * @fn unsigned int Exception::Line() const; + * + * @brief The line number associated with this exception. + * + * @return An int. + */ + unsigned int Line() const; + + /** + * @fn std::string Exception::ToString() const; + * + * @brief Converts this exception to a string. The string contains the reason, line number and + * file the exception was thrown from. + * + * @return The string version of this exception. + */ + std::string ToString() const; + + /** + * @fn void Exception::Print() const; + * + * @brief Prints the exception to the console. + */ + void Print() const; + + /** + * @fn void Exception::LogException(trUtil::Logging::LogLevel level = trUtil::Logging::LogLevel::LOG_ERROR) const; + * + * @brief Logs the exception to the default logger. + * + * @param level (Optional) The level/type of logging. + */ + void LogException(trUtil::Logging::LogLevel level = trUtil::Logging::LogLevel::LOG_ERROR) const; + + /** + * @fn void Exception::LogException(trUtil::Logging::LogLevel level, const std::string& loggerName) const; + * + * @brief Logs the exception to the following log level using the logger. + * + * @param level The level/type of logging. + * @param loggerName the name passed to "getInstance" of the Logger. + */ + void LogException(trUtil::Logging::LogLevel level, const std::string& loggerName) const; + + /** + * @fn void Exception::LogException(trUtil::Logging::LogLevel level, trUtil::Logging::Log& logger) const; + * + * @brief Logs the exception to the following log level using the given logger. + * + * @param level The level/type of logging. + * @param [in,out] logger the actual log instance used to log. + */ + void LogException(trUtil::Logging::LogLevel level, trUtil::Logging::Log& logger) const; + + private: + std::string mMessage, mFileName; + unsigned int mLineNum; + }; + + /** + * @fn std::ostream& operator<< (std::ostream& o, const Exception& ex); + * + * @brief Stream insertion operator. + * + * @param [in,out] o The std::ostream to process. + * @param ex The ex. + * + * @return The shifted result. + */ + TR_UTIL_EXPORT std::ostream& operator << (std::ostream& o, const Exception& ex); } \ No newline at end of file diff --git a/include/trUtil/ExceptionInvalidParameter.cpp.h b/include/trUtil/ExceptionInvalidParameter.cpp.h index 8c81b81..06b2b35 100644 --- a/include/trUtil/ExceptionInvalidParameter.cpp.h +++ b/include/trUtil/ExceptionInvalidParameter.cpp.h @@ -1,60 +1,60 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include "Export.h" - -#include - -namespace trUtil -{ - /** - * @class ExceptionInvalidParameter - * - * @brief Exception used for methods invalid parameters. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT ExceptionInvalidParameter : public trUtil::Exception - { - public: - - /** - * @fn ExceptionInvalidParameter::ExceptionInvalidParameter(const std::string& message, const std::string& filename, unsigned int linenum); - * - * @brief Constructor. - * - * @param message The message. - * @param filename Filename of the file. - * @param linenum The linenum. - */ - ExceptionInvalidParameter(const std::string& message, const std::string& filename, unsigned int linenum); - - /** - * @fn virtual ExceptionInvalidParameter::~ExceptionInvalidParameter() - * - * @brief Destructor. - */ - virtual ~ExceptionInvalidParameter() {}; - }; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include "Export.h" + +#include + +namespace trUtil +{ + /** + * @class ExceptionInvalidParameter + * + * @brief Exception used for methods invalid parameters. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT ExceptionInvalidParameter : public trUtil::Exception + { + public: + + /** + * @fn ExceptionInvalidParameter::ExceptionInvalidParameter(const std::string& message, const std::string& filename, unsigned int linenum); + * + * @brief Constructor. + * + * @param message The message. + * @param filename Filename of the file. + * @param linenum The linenum. + */ + ExceptionInvalidParameter(const std::string& message, const std::string& filename, unsigned int linenum); + + /** + * @fn virtual ExceptionInvalidParameter::~ExceptionInvalidParameter() + * + * @brief Destructor. + */ + virtual ~ExceptionInvalidParameter() {}; + }; + } \ No newline at end of file diff --git a/include/trUtil/Export.h b/include/trUtil/Export.h index cda3d41..ae275f9 100644 --- a/include/trUtil/Export.h +++ b/include/trUtil/Export.h @@ -1,36 +1,36 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) -# ifdef TR_UTIL_LIBRARY -# define TR_UTIL_EXPORT __declspec(dllexport) -# else -# define TR_UTIL_EXPORT __declspec(dllimport) -# endif -#else -# ifdef TR_UTIL_LIBRARY -# define TR_UTIL_EXPORT __attribute__ ((visibility("default"))) -# else -# define TR_UTIL_EXPORT -# endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) +# ifdef TR_UTIL_LIBRARY +# define TR_UTIL_EXPORT __declspec(dllexport) +# else +# define TR_UTIL_EXPORT __declspec(dllimport) +# endif +#else +# ifdef TR_UTIL_LIBRARY +# define TR_UTIL_EXPORT __attribute__ ((visibility("default"))) +# else +# define TR_UTIL_EXPORT +# endif #endif \ No newline at end of file diff --git a/include/trUtil/FileUtils.h b/include/trUtil/FileUtils.h index d44bb66..7dfbc8f 100644 --- a/include/trUtil/FileUtils.h +++ b/include/trUtil/FileUtils.h @@ -1,747 +1,747 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include - -/// @cond DOXYGEN_SHOULD_SKIP_THIS -#if OPENSCENEGRAPH_MAJOR_VERSION < 3 -namespace osgDB -{ - class ArchiveExtended; -} -#else -namespace osgDB -{ - using ArchiveExtended = Archive; -} -#endif -/// @endcond - -namespace trUtil -{ - class Log; - - using DirectoryContents = std::vector; - using FileExtensionList = std::vector; - - /** - * @enum FileType - * - * @brief Values that represent file types. - */ - enum FileType - { - FILE_NOT_FOUND, - REGULAR_FILE, - DIRECTORY, - ARCHIVE - }; - - /** - * @struct FileInfo - * - * @brief struct holding information about a file. - */ - struct FileInfo - { - std::string fileName; ///< the file name with full path - std::string path; ///< the path to the file - std::string baseName; ///< the file name with extension - std::string extensionlessFileName; ///< the file name with extension - std::string extension; ///< the file extension - size_t size; ///< the size of the file in bytes. - time_t lastModified; ///< when the file was last modified. - FileType fileType; ///< The enum value specifying the type of file - bool isInArchive; ///< true if the specified file lives within an archive - - FileInfo() : size(0), lastModified(0), fileType(FILE_NOT_FOUND), isInArchive(false) {} - }; - - /** - * @class FileUtilIOException - * - * @brief Exception for signaling file utility i/o errors. - */ - class TR_UTIL_EXPORT FileUtilIOException : public trUtil::Exception - { - public: - FileUtilIOException(const std::string& message, const std::string& filename, unsigned int linenum); - virtual ~FileUtilIOException() {}; - }; - - /** - * @class FileNotFoundException - * - * @brief Exception for signalling file not found errors. - */ - class TR_UTIL_EXPORT FileNotFoundException : public trUtil::Exception - { - public: - FileNotFoundException(const std::string& message, const std::string& filename, unsigned int linenum); - virtual ~FileNotFoundException() {}; - }; - - /** - * @class FileUtils - * - * @brief Singleton class implementing basic file operations. - */ - class TR_UTIL_EXPORT FileUtils : public osg::Referenced - { - public: - static const char PATH_SEPARATOR; /// Character separating the parts of a file path. - - /** - * @fn static FileUtils& FileUtils::GetInstance() - * - * @brief Gets the instance. - * - * @return the single instance of this class. - */ - static FileUtils& GetInstance() - { - if (mInstance == NULL) - { - mInstance = new FileUtils(); - } - return *mInstance; - } - - /** - * @fn std::string FileUtils::RunCommand(const char* cmd); - * - * @brief Runs a command on the console, and returns the console printout in a form of a string. - * - * @param cmd The command. - * - * @return A std::string. - */ - std::string RunCommand(const char* cmd); - - /** - * @fn std::string FileUtils::RunCommand(const std::string cmd); - * - * @brief Runs a command on the console, and returns the console printout in a form of a string. - * - * @param cmd The command. - * - * @return A std::string. - */ - std::string RunCommand(const std::string cmd); - - /** - * @fn bool FileUtils::FileExists(const std::string& strFile, bool caseInsensitive = false) const; - * - * @brief Queries if a given file exists. - * - * @param strFile the path to the file to check. - * @param caseInsensitive (Optional) false for native, true for forced case insensitivity on - * platforms that normally are sensitive. - * - * @return true if the file exists. - */ - bool FileExists(const std::string& strFile, bool caseInsensitive = false) const; - - /** - * @fn void FileUtils::FileCopy(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; - * - * @brief Copys a file. - * - * @exception trUtil::FileNotFoundException if the source file is not found. - * @exception trUtil::IOException if an error occurs copying the data or bOverwrite - * was false and the - * destination file exists. - * - * @param strSrc The path to the source file. - * @param strDest The path to the destination file or directory. - * @param bOverwrite true if this call should overwrite the destination file if it exists. - */ - void FileCopy(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; - - /** - * @fn void FileUtils::FileMove(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; - * - * @brief Moves a file. This call will attempt to move the file without moving the data, but if - * it can't, the file will first be copied then the source file will be removed. - * - * @exception trUtil::FileNotFoundException if the source file is not found. - * @exception trUtil::IOException if an error occurs moving the data or bOverwrite - * was false and the - * destination file exists. - * - * @param strSrc The path to the source file. - * @param strDest The path to the destintion file or directory. - * @param bOverwrite true if this call should overwrite the destination file if it exists. - */ - void FileMove(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; - - /** - * @fn void FileUtils::FileDelete(const std::string& strFile) const; - * - * @brief Deletes the given file. - * - * @exception trUtil::IOException if an error occurs deleting the data. - * - * @param strFile the path to the file to delete. - */ - void FileDelete(const std::string& strFile) const; - - /** - * @struct FileInfo - * - * @brief Information about the file. - * - * @sa trUtil::FileInfo - * - * ### param caseInsensitive false for native behavior (default) or true to make it case - * insensitive on case sensitive systems. - * @note If the file is not found, the fileType value will be set - * to FILE_NOT_FOUND and all other values - * will be undefined. - * ### return the fileInfo struct for the given file. - */ - const struct FileInfo GetFileInfo(const std::string& strFile, bool caseInsensitive = false) const; - - /** - * @fn void FileUtils::CleanupFileString(std::string &strFileOrDir) const; - * - * @brief Ensure that the passed in string is fit for use as a file or dir string. In our case - * we want all separators to be the '/' character and we do not want a separator at the - * end. - * - * @param [in,out] strFileOrDir The string to cleanup. - * @note The original string passed in is changed. - */ - void CleanupFileString(std::string &strFileOrDir) const; - - /** - * @fn bool FileUtils::IsAbsolutePath(std::string strFileOrDir) const; - * - * @brief Query whether a given string is an absolute path or not. - * - * @param strFileOrDir The path to check. - * - * @return True if absolute, False if relative. - * @note This maybe a subjective determination, may need to add to this later. - */ - bool IsAbsolutePath(std::string strFileOrDir) const; - - /** - * @fn void FileUtils::MakeDirectoryEX(std::string strDir); - * - * @brief A more powerful version of the standard mkdir. This function will check to see if - * the directory exists first and only create if needed. Also, it will recursively - * create all subdirectories needed to create the final directory in the passed in - * string. - * - * @exception all the exceptions that MakeDirectory throws. - * - * @param strDir The directory to create. - * - * @sa ::MakeDirectory - */ - void MakeDirectoryEX(std::string strDir); - - /** - * @fn void FileUtils::ChangeDirectory(const std::string& path); - * - * @brief Changes the current directory to the one given in "path." This will clear the stack - * of directories that is set by pushDirectory and popDirectory. If this call fails, the - * stack will not be cleared. - * - * @sa popDirectory. - * - * @param path The path to the new directory. - * - * @sa pushDirectory - * - * @exception trUtil::FileNotFoundException if the path does not exist. - */ - void ChangeDirectory(const std::string& path); - - /** - * @fn const std::string& FileUtils::CurrentDirectory() const; - * - * @brief Current directory. - * - * @return the full path to the current directory. - */ - const std::string& CurrentDirectory() const; - - /** - * @fn void FileUtils::PushDirectory(const std::string& path); - * - * @brief Changes the current directory to the one given in "path" and adds the previous - * current directory to an internal stack so it can be returned to via popDirectory. If - * this call fails, the stack will not be changed. - * - * @exception trUtil::FileNameFoundException if the path does not exist. - * - * @param path The path to the new directory. - * - * @sa popDirectory - */ - void PushDirectory(const std::string& path); - - /** - * @fn void FileUtils::PopDirectory(); - * - * @brief sets the current directory to the last directory on the stack. - * - * @exception trUtil::FileNotFoundException if the previous directory no longer exists. - * - * @sa pushDirectory - */ - void PopDirectory(); - - /** - * @fn std::string FileUtils::GetAbsolutePath(const std::string& relativePath, bool removeFinalFile = false) const; - * - * @brief Converts a relative path to an absolute path. - * - * @exception trUtil::FileNotFoundException if the path does not exist. - * - * @param relativePath the relative path to convert to absolute. - * @param removeFinalFile (Optional) If this refers to a file, then remove the final file in - * the result. - * - * @return the absolute path. - */ - std::string GetAbsolutePath(const std::string& relativePath, bool removeFinalFile = false) const; - - /** - * @fn DirectoryContents FileUtils::DirGetFiles(const std::string& path, const FileExtensionList& extensions = FileExtensionList()) const; - * - * @brief Note: throws exceptions of type trUtil::Exception. - * - * @exception trUtil::FileNotFoundException if the path does not exist. - * @exception trUtil::IOException if the path is not an actual directory. - * - * @param path the path to the directory to list the contents of. - * @param extensions (Optional) Optional list of file extensions to filter on, including the - * "dot". (e.g., ".txt", ".xml") - * - * @return a vector of file names. - */ - DirectoryContents DirGetFiles(const std::string& path, const FileExtensionList& extensions = FileExtensionList()) const; - - /** - * @fn DirectoryContents FileUtils::DirGetSubs(const std::string& path) const; - * - * @brief Dir get subs. - * - * @exception trUtil::FileNotFoundException if the path does not exist. - * - * @param path the path to the directory to get the subdirectories for. - * - * @return a vector holding the list of subdirectories. - */ - DirectoryContents DirGetSubs(const std::string& path) const; - - /** - * @fn void FileUtils::DirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite, bool copyContentsOnly = false) const; - * - * @brief Copys an entire directory. If destPath exists, then a subdirectory will be created - * in destPath with the same name as srcPath unless copyContentsOnly is true, in which - * case the contents of srcPath will be copied into destPath. If destPath does not - * exist, destPath will be created if the parent exists and the contents of srcPath will - * be copied to destPath whether copyContentsOnly is true or false. - * - * @exception trUtil::FileNotFoundException if the source file is not found. - * @exception trUtil::IOException if an error occurs copying the data or bOverwrite - * was false and a - * destination file exists. - * - * @param srcPath the source directory to copy. - * @param destPath the destination directory. - * @param bOverwrite true if this call should overwrite the destination file if it - * exists. - * @param copyContentsOnly (Optional) true if the contents of srcPath should be copied into - * destPath rather than create a subdirectory. - */ - void DirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite, bool copyContentsOnly = false) const; - - /** - * @fn bool FileUtils::DirDelete(const std::string& strDir, bool bRecursive); - * - * @brief Deletes a directory. If bRecursive is true, the directory and all it's contents will - * be removed. If it's false, the call will fail unless the directory is empty. - * - * @exception trUtil::FileNotFoundException if the path does not exist. - * @exception trUtil::IOException if an error occurs deleteting the directory. - * - * @param strDir The path of the directory to delete. - * @param bRecursive true if the directory should be deleted recursively. - * - * @return true if successful or false if the directory is NOT empty and bRecursive is false. - */ - bool DirDelete(const std::string& strDir, bool bRecursive); - - /** - * @fn void FileUtils::MakeDirectory(const std::string& strDir) const; - * - * @brief creates a new directory from a path. - * - * @exception trUtil::FileNotFoundException if the parent path does not exist. - * @exception trUtil::IOException if an error occurs creating the directory. - * - * @param strDir the directory to create. - */ - void MakeDirectory(const std::string& strDir) const; - - /** - * @fn bool FileUtils::DirExists(const std::string& strDir, bool caseInsensitive = false) const; - * - * @brief Queries if a given dir exists. - * - * @param strDir The directory to check. - * @param caseInsensitive (Optional) false for native, true for forced case insensitivity on - * platforms that normally are sensitive. - * - * @return true if the path exists and is a directory. - */ - bool DirExists(const std::string& strDir, bool caseInsensitive = false) const; - - /** - * @fn std::string FileUtils::RelativePath(const std::string& absolutePath, const std::string& file) const; - * - * @brief Helper function that returns the relative path between absolutePath and file. - * - * @param absolutePath The absolute path to search. - * @param file The absolute path to the file. - * - * @return The relative path or empty string for failure - * @note This function assumes that directory separators are equal for both paths. - */ - std::string RelativePath(const std::string& absolutePath, const std::string& file) const; - - /** - * @fn void FileUtils::AbsoluteToRelative(const std::string &absPath, std::string& relPath); - * - * @brief Converts an absolute path to a relative path based on the current working directory. - * - * @param absPath the absolute path to process. - * @param [in,out] relPath output parameter that will contain the relative path. - */ - //void AbsoluteToRelative(const std::string &absPath, std::string& relPath); - - /** - * @fn bool FileUtils::IsSameFile(const std::string& file1, const std::string& file2) const; - * - * @brief It is possible for two different path strings to point at the same file on disk. - * (Things like relative paths and filesystem links make this possible). - * - * This function makes absolutely certain that the two files aren't the same by checking - * the inodes of the two files -- preventing things like having the FileUtils::FileCopy - * accidentally blow away a file by copying it onto itself. - * - * @param file1 -- Path to first file. - * @param file2 -- Path to second file. - * - * @return True if inodes match, false otherwise (if one or both files are inaccessible, returns - * false). - */ - bool IsSameFile(const std::string& file1, const std::string& file2) const; - - /** - * @fn static std::string FileUtils::ConcatPaths(const std::string& left, const std::string& right); - * - * @brief Concatenates two paths adding a path separator in between if necessary. - * - * @param left The left. - * @param right The right. - * - * @return A std::string. - */ - static std::string ConcatPaths(const std::string& left, const std::string& right); - - /** - * @fn osg::Object* FileUtils::ReadObject(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); - * - * @brief Reads an object. - * - * @param filename Filename of the file. - * @param [in,out] options (Optional) If non-null, options for controlling the operation. - * - * @return Null if it fails, else the object. - */ - osg::Object* ReadObject(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); - - /** - * @fn osg::Node* FileUtils::ReadNode(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); - * - * @brief Reads a node. - * - * @param filename Filename of the file. - * @param [in,out] options (Optional) If non-null, options for controlling the operation. - * - * @return Null if it fails, else the node. - */ - osg::Node* ReadNode(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); - - /** - * @fn osgDB::ArchiveExtended* FileUtils::FindArchive(const std::string& archiveFileName) const; - * - * @brief Used to search for archives by filename. - * - * @param archiveFileName Filename of the archive file. - * - * @return Null if it fails, else the found archive. - */ - osgDB::ArchiveExtended* FindArchive(const std::string& archiveFileName) const; - - private: - - /** @brief Size of the path buffer. */ - static const int PATH_BUFFER_SIZE = 1024; - - /** - * @fn FileUtils::FileUtils(); - * - * @brief Default constructor. - */ - FileUtils(); - - /** - * @fn virtual FileUtils::~FileUtils(); - * - * @brief Destructor. - */ - virtual ~FileUtils(); - - /** - * @fn void FileUtils::ChangeDirectoryInternal(const std::string& path); - * - * @brief Change directory internal. - * - * @param path Full pathname of the file. - */ - void ChangeDirectoryInternal(const std::string& path); - - /** - * @fn void FileUtils::InternalDirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite) const; - * - * @brief Internal dir copy. - * - * @param srcPath Full pathname of the source file. - * @param destPath Full pathname of the destination file. - * @param bOverwrite True to overwrite, false to preserve. - */ - void InternalDirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite) const; - - /** - * @fn void FileUtils::RecursDeleteDir(bool bRecursive); - * - * @brief Recurs delete dir. - * - * @param bRecursive True to process recursively, false to process locally only. - */ - void RecursDeleteDir(bool bRecursive); - - /** - * @fn bool FileUtils::SplitArchiveFilename(const std::string& fullFilename, std::string& archiveFilename, std::string& fileInArchive) const; - * - * @brief Splits a filename for a file within an archive into two parts, the archive filename - * and the actual - * filename relative to the archive root. - * - * @param fullFilename Filename of the full file. - * @param [in,out] archiveFilename Filename of the archive file. - * @param [in,out] fileInArchive The file in archive. - * - * @return True if it succeeds, false if it fails. - */ - bool SplitArchiveFilename(const std::string& fullFilename, std::string& archiveFilename, std::string& fileInArchive) const; - - /** - * @fn void FileUtils::DirGetFilesInArchive(const osgDB::ArchiveExtended& a, const std::string& path, DirectoryContents& result) const; - * - * @brief Internal function used to find files within an archive subdirectory. - * - * @param a The osgDB::ArchiveExtended to process. - * @param path Full pathname of the file. - * @param [in,out] result The result. - */ - void DirGetFilesInArchive(const osgDB::ArchiveExtended& a, const std::string& path, DirectoryContents& result) const; - - /** - * @fn FileType FileUtils::GetFileTypeForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; - * - * @brief Gets file type for file in archive. - * - * @param a The osgDB::ArchiveExtended to process. - * @param path Full pathname of the file. - * - * @return The file type for file in archive. - */ - FileType GetFileTypeForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; - - /** - * @fn FileInfo FileUtils::GetFileInfoForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; - * - * @brief Gets file information for file in archive. - * - * @param a The osgDB::ArchiveExtended to process. - * @param path Full pathname of the file. - * - * @return The file information for file in archive. - */ - FileInfo GetFileInfoForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; - - /** - * @fn FileType FileUtils::GetFileTypeFromOSGDBFileType(osgDB::FileType ft) const; - * - * @brief Gets file type from osgdb file type. - * - * @param ft The ft. - * - * @return The file type from osgdb file type. - */ - FileType GetFileTypeFromOSGDBFileType(osgDB::FileType ft) const; - - /** - * @fn bool FileUtils::ContainsArchiveExtension(const std::string& path) const; - * - * @brief Query if 'path' contains archive extension. - * - * @param path Full pathname of the file. - * - * @return True if it succeeds, false if it fails. - */ - bool ContainsArchiveExtension(const std::string& path) const; - - /** - * @fn std::string FileUtils::ArchiveRelativeToAbsolute(const std::string& relativeFile) const; - * - * @brief Archive relative to absolute. - * - * @param relativeFile The relative file. - * - * @return A std::string. - */ - std::string ArchiveRelativeToAbsolute(const std::string& relativeFile) const; - - /** - * @struct FileInfo - * - * @brief Information about the file. - */ - const struct FileInfo GetFileInfo_Internal(const std::string& strFile, bool caseInsensitive) const; - - /** - * @fn bool FileUtils::IsSameFile_Internal(const std::string& file1, const std::string& file2) const; - * - * @brief Query if 'file1' is same file internal. - * - * @param file1 The first file. - * @param file2 The second file. - * - * @return True if same file internal, false if not. - */ - bool IsSameFile_Internal(const std::string& file1, const std::string& file2) const; - - - static osg::ref_ptr mInstance; - - trUtil::Logging::Log* mLogger; - - std::string mCurrentDirectory; - std::vector mStackOfDirectories; - - }; - - /** - * @class DirectoryPush - * - * @brief Simple class to change directory where it automatically pop back out on destruction. - * To be used on the stack. - */ - class TR_UTIL_EXPORT DirectoryPush - { - public: - - /** - * @fn DirectoryPush::DirectoryPush(const std::string& dir); - * - * @brief Constructor. - * - * @param dir The dir. - */ - DirectoryPush(const std::string& dir); - - /** - * @fn DirectoryPush::~DirectoryPush(); - * - * @brief Destructor. - */ - ~DirectoryPush(); - - /** - * @fn bool DirectoryPush::GetSucceeded(); - * - * @brief Gets the succeeded. - * - * @return True if it succeeds, false if it fails. - */ - bool GetSucceeded(); - - /** - * @fn const std::string& DirectoryPush::GetError(); - * - * @brief Gets the error. - * - * @return The error. - */ - const std::string& GetError(); - private: - bool mSucceeded; - std::string mError; - }; - - /** - * @class IsPathSeparator - * - * @brief For tokenizing paths. - */ - class IsPathSeparator : public trUtil::UnaryFunction - { - public: - bool operator()(char c) const { return c == '/' || c == '\\' || c == FileUtils::PATH_SEPARATOR; } - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +/// @cond DOXYGEN_SHOULD_SKIP_THIS +#if OPENSCENEGRAPH_MAJOR_VERSION < 3 +namespace osgDB +{ + class ArchiveExtended; +} +#else +namespace osgDB +{ + using ArchiveExtended = Archive; +} +#endif +/// @endcond + +namespace trUtil +{ + class Log; + + using DirectoryContents = std::vector; + using FileExtensionList = std::vector; + + /** + * @enum FileType + * + * @brief Values that represent file types. + */ + enum FileType + { + FILE_NOT_FOUND, + REGULAR_FILE, + DIRECTORY, + ARCHIVE + }; + + /** + * @struct FileInfo + * + * @brief struct holding information about a file. + */ + struct FileInfo + { + std::string fileName; ///< the file name with full path + std::string path; ///< the path to the file + std::string baseName; ///< the file name with extension + std::string extensionlessFileName; ///< the file name with extension + std::string extension; ///< the file extension + size_t size; ///< the size of the file in bytes. + time_t lastModified; ///< when the file was last modified. + FileType fileType; ///< The enum value specifying the type of file + bool isInArchive; ///< true if the specified file lives within an archive + + FileInfo() : size(0), lastModified(0), fileType(FILE_NOT_FOUND), isInArchive(false) {} + }; + + /** + * @class FileUtilIOException + * + * @brief Exception for signaling file utility i/o errors. + */ + class TR_UTIL_EXPORT FileUtilIOException : public trUtil::Exception + { + public: + FileUtilIOException(const std::string& message, const std::string& filename, unsigned int linenum); + virtual ~FileUtilIOException() {}; + }; + + /** + * @class FileNotFoundException + * + * @brief Exception for signalling file not found errors. + */ + class TR_UTIL_EXPORT FileNotFoundException : public trUtil::Exception + { + public: + FileNotFoundException(const std::string& message, const std::string& filename, unsigned int linenum); + virtual ~FileNotFoundException() {}; + }; + + /** + * @class FileUtils + * + * @brief Singleton class implementing basic file operations. + */ + class TR_UTIL_EXPORT FileUtils : public osg::Referenced + { + public: + static const char PATH_SEPARATOR; /// Character separating the parts of a file path. + + /** + * @fn static FileUtils& FileUtils::GetInstance() + * + * @brief Gets the instance. + * + * @return the single instance of this class. + */ + static FileUtils& GetInstance() + { + if (mInstance == NULL) + { + mInstance = new FileUtils(); + } + return *mInstance; + } + + /** + * @fn std::string FileUtils::RunCommand(const char* cmd); + * + * @brief Runs a command on the console, and returns the console printout in a form of a string. + * + * @param cmd The command. + * + * @return A std::string. + */ + std::string RunCommand(const char* cmd); + + /** + * @fn std::string FileUtils::RunCommand(const std::string cmd); + * + * @brief Runs a command on the console, and returns the console printout in a form of a string. + * + * @param cmd The command. + * + * @return A std::string. + */ + std::string RunCommand(const std::string cmd); + + /** + * @fn bool FileUtils::FileExists(const std::string& strFile, bool caseInsensitive = false) const; + * + * @brief Queries if a given file exists. + * + * @param strFile the path to the file to check. + * @param caseInsensitive (Optional) false for native, true for forced case insensitivity on + * platforms that normally are sensitive. + * + * @return true if the file exists. + */ + bool FileExists(const std::string& strFile, bool caseInsensitive = false) const; + + /** + * @fn void FileUtils::FileCopy(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; + * + * @brief Copys a file. + * + * @exception trUtil::FileNotFoundException if the source file is not found. + * @exception trUtil::IOException if an error occurs copying the data or bOverwrite + * was false and the + * destination file exists. + * + * @param strSrc The path to the source file. + * @param strDest The path to the destination file or directory. + * @param bOverwrite true if this call should overwrite the destination file if it exists. + */ + void FileCopy(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; + + /** + * @fn void FileUtils::FileMove(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; + * + * @brief Moves a file. This call will attempt to move the file without moving the data, but if + * it can't, the file will first be copied then the source file will be removed. + * + * @exception trUtil::FileNotFoundException if the source file is not found. + * @exception trUtil::IOException if an error occurs moving the data or bOverwrite + * was false and the + * destination file exists. + * + * @param strSrc The path to the source file. + * @param strDest The path to the destintion file or directory. + * @param bOverwrite true if this call should overwrite the destination file if it exists. + */ + void FileMove(const std::string& strSrc, const std::string& strDest, bool bOverwrite) const; + + /** + * @fn void FileUtils::FileDelete(const std::string& strFile) const; + * + * @brief Deletes the given file. + * + * @exception trUtil::IOException if an error occurs deleting the data. + * + * @param strFile the path to the file to delete. + */ + void FileDelete(const std::string& strFile) const; + + /** + * @struct FileInfo + * + * @brief Information about the file. + * + * @sa trUtil::FileInfo + * + * ### param caseInsensitive false for native behavior (default) or true to make it case + * insensitive on case sensitive systems. + * @note If the file is not found, the fileType value will be set + * to FILE_NOT_FOUND and all other values + * will be undefined. + * ### return the fileInfo struct for the given file. + */ + const struct FileInfo GetFileInfo(const std::string& strFile, bool caseInsensitive = false) const; + + /** + * @fn void FileUtils::CleanupFileString(std::string &strFileOrDir) const; + * + * @brief Ensure that the passed in string is fit for use as a file or dir string. In our case + * we want all separators to be the '/' character and we do not want a separator at the + * end. + * + * @param [in,out] strFileOrDir The string to cleanup. + * @note The original string passed in is changed. + */ + void CleanupFileString(std::string &strFileOrDir) const; + + /** + * @fn bool FileUtils::IsAbsolutePath(std::string strFileOrDir) const; + * + * @brief Query whether a given string is an absolute path or not. + * + * @param strFileOrDir The path to check. + * + * @return True if absolute, False if relative. + * @note This maybe a subjective determination, may need to add to this later. + */ + bool IsAbsolutePath(std::string strFileOrDir) const; + + /** + * @fn void FileUtils::MakeDirectoryEX(std::string strDir); + * + * @brief A more powerful version of the standard mkdir. This function will check to see if + * the directory exists first and only create if needed. Also, it will recursively + * create all subdirectories needed to create the final directory in the passed in + * string. + * + * @exception all the exceptions that MakeDirectory throws. + * + * @param strDir The directory to create. + * + * @sa ::MakeDirectory + */ + void MakeDirectoryEX(std::string strDir); + + /** + * @fn void FileUtils::ChangeDirectory(const std::string& path); + * + * @brief Changes the current directory to the one given in "path." This will clear the stack + * of directories that is set by pushDirectory and popDirectory. If this call fails, the + * stack will not be cleared. + * + * @sa popDirectory. + * + * @param path The path to the new directory. + * + * @sa pushDirectory + * + * @exception trUtil::FileNotFoundException if the path does not exist. + */ + void ChangeDirectory(const std::string& path); + + /** + * @fn const std::string& FileUtils::CurrentDirectory() const; + * + * @brief Current directory. + * + * @return the full path to the current directory. + */ + const std::string& CurrentDirectory() const; + + /** + * @fn void FileUtils::PushDirectory(const std::string& path); + * + * @brief Changes the current directory to the one given in "path" and adds the previous + * current directory to an internal stack so it can be returned to via popDirectory. If + * this call fails, the stack will not be changed. + * + * @exception trUtil::FileNameFoundException if the path does not exist. + * + * @param path The path to the new directory. + * + * @sa popDirectory + */ + void PushDirectory(const std::string& path); + + /** + * @fn void FileUtils::PopDirectory(); + * + * @brief sets the current directory to the last directory on the stack. + * + * @exception trUtil::FileNotFoundException if the previous directory no longer exists. + * + * @sa pushDirectory + */ + void PopDirectory(); + + /** + * @fn std::string FileUtils::GetAbsolutePath(const std::string& relativePath, bool removeFinalFile = false) const; + * + * @brief Converts a relative path to an absolute path. + * + * @exception trUtil::FileNotFoundException if the path does not exist. + * + * @param relativePath the relative path to convert to absolute. + * @param removeFinalFile (Optional) If this refers to a file, then remove the final file in + * the result. + * + * @return the absolute path. + */ + std::string GetAbsolutePath(const std::string& relativePath, bool removeFinalFile = false) const; + + /** + * @fn DirectoryContents FileUtils::DirGetFiles(const std::string& path, const FileExtensionList& extensions = FileExtensionList()) const; + * + * @brief Note: throws exceptions of type trUtil::Exception. + * + * @exception trUtil::FileNotFoundException if the path does not exist. + * @exception trUtil::IOException if the path is not an actual directory. + * + * @param path the path to the directory to list the contents of. + * @param extensions (Optional) Optional list of file extensions to filter on, including the + * "dot". (e.g., ".txt", ".xml") + * + * @return a vector of file names. + */ + DirectoryContents DirGetFiles(const std::string& path, const FileExtensionList& extensions = FileExtensionList()) const; + + /** + * @fn DirectoryContents FileUtils::DirGetSubs(const std::string& path) const; + * + * @brief Dir get subs. + * + * @exception trUtil::FileNotFoundException if the path does not exist. + * + * @param path the path to the directory to get the subdirectories for. + * + * @return a vector holding the list of subdirectories. + */ + DirectoryContents DirGetSubs(const std::string& path) const; + + /** + * @fn void FileUtils::DirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite, bool copyContentsOnly = false) const; + * + * @brief Copys an entire directory. If destPath exists, then a subdirectory will be created + * in destPath with the same name as srcPath unless copyContentsOnly is true, in which + * case the contents of srcPath will be copied into destPath. If destPath does not + * exist, destPath will be created if the parent exists and the contents of srcPath will + * be copied to destPath whether copyContentsOnly is true or false. + * + * @exception trUtil::FileNotFoundException if the source file is not found. + * @exception trUtil::IOException if an error occurs copying the data or bOverwrite + * was false and a + * destination file exists. + * + * @param srcPath the source directory to copy. + * @param destPath the destination directory. + * @param bOverwrite true if this call should overwrite the destination file if it + * exists. + * @param copyContentsOnly (Optional) true if the contents of srcPath should be copied into + * destPath rather than create a subdirectory. + */ + void DirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite, bool copyContentsOnly = false) const; + + /** + * @fn bool FileUtils::DirDelete(const std::string& strDir, bool bRecursive); + * + * @brief Deletes a directory. If bRecursive is true, the directory and all it's contents will + * be removed. If it's false, the call will fail unless the directory is empty. + * + * @exception trUtil::FileNotFoundException if the path does not exist. + * @exception trUtil::IOException if an error occurs deleteting the directory. + * + * @param strDir The path of the directory to delete. + * @param bRecursive true if the directory should be deleted recursively. + * + * @return true if successful or false if the directory is NOT empty and bRecursive is false. + */ + bool DirDelete(const std::string& strDir, bool bRecursive); + + /** + * @fn void FileUtils::MakeDirectory(const std::string& strDir) const; + * + * @brief creates a new directory from a path. + * + * @exception trUtil::FileNotFoundException if the parent path does not exist. + * @exception trUtil::IOException if an error occurs creating the directory. + * + * @param strDir the directory to create. + */ + void MakeDirectory(const std::string& strDir) const; + + /** + * @fn bool FileUtils::DirExists(const std::string& strDir, bool caseInsensitive = false) const; + * + * @brief Queries if a given dir exists. + * + * @param strDir The directory to check. + * @param caseInsensitive (Optional) false for native, true for forced case insensitivity on + * platforms that normally are sensitive. + * + * @return true if the path exists and is a directory. + */ + bool DirExists(const std::string& strDir, bool caseInsensitive = false) const; + + /** + * @fn std::string FileUtils::RelativePath(const std::string& absolutePath, const std::string& file) const; + * + * @brief Helper function that returns the relative path between absolutePath and file. + * + * @param absolutePath The absolute path to search. + * @param file The absolute path to the file. + * + * @return The relative path or empty string for failure + * @note This function assumes that directory separators are equal for both paths. + */ + std::string RelativePath(const std::string& absolutePath, const std::string& file) const; + + /** + * @fn void FileUtils::AbsoluteToRelative(const std::string &absPath, std::string& relPath); + * + * @brief Converts an absolute path to a relative path based on the current working directory. + * + * @param absPath the absolute path to process. + * @param [in,out] relPath output parameter that will contain the relative path. + */ + //void AbsoluteToRelative(const std::string &absPath, std::string& relPath); + + /** + * @fn bool FileUtils::IsSameFile(const std::string& file1, const std::string& file2) const; + * + * @brief It is possible for two different path strings to point at the same file on disk. + * (Things like relative paths and filesystem links make this possible). + * + * This function makes absolutely certain that the two files aren't the same by checking + * the inodes of the two files -- preventing things like having the FileUtils::FileCopy + * accidentally blow away a file by copying it onto itself. + * + * @param file1 -- Path to first file. + * @param file2 -- Path to second file. + * + * @return True if inodes match, false otherwise (if one or both files are inaccessible, returns + * false). + */ + bool IsSameFile(const std::string& file1, const std::string& file2) const; + + /** + * @fn static std::string FileUtils::ConcatPaths(const std::string& left, const std::string& right); + * + * @brief Concatenates two paths adding a path separator in between if necessary. + * + * @param left The left. + * @param right The right. + * + * @return A std::string. + */ + static std::string ConcatPaths(const std::string& left, const std::string& right); + + /** + * @fn osg::Object* FileUtils::ReadObject(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); + * + * @brief Reads an object. + * + * @param filename Filename of the file. + * @param [in,out] options (Optional) If non-null, options for controlling the operation. + * + * @return Null if it fails, else the object. + */ + osg::Object* ReadObject(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); + + /** + * @fn osg::Node* FileUtils::ReadNode(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); + * + * @brief Reads a node. + * + * @param filename Filename of the file. + * @param [in,out] options (Optional) If non-null, options for controlling the operation. + * + * @return Null if it fails, else the node. + */ + osg::Node* ReadNode(const std::string& filename, osgDB::ReaderWriter::Options* options = NULL); + + /** + * @fn osgDB::ArchiveExtended* FileUtils::FindArchive(const std::string& archiveFileName) const; + * + * @brief Used to search for archives by filename. + * + * @param archiveFileName Filename of the archive file. + * + * @return Null if it fails, else the found archive. + */ + osgDB::ArchiveExtended* FindArchive(const std::string& archiveFileName) const; + + private: + + /** @brief Size of the path buffer. */ + static const int PATH_BUFFER_SIZE = 1024; + + /** + * @fn FileUtils::FileUtils(); + * + * @brief Default constructor. + */ + FileUtils(); + + /** + * @fn virtual FileUtils::~FileUtils(); + * + * @brief Destructor. + */ + virtual ~FileUtils(); + + /** + * @fn void FileUtils::ChangeDirectoryInternal(const std::string& path); + * + * @brief Change directory internal. + * + * @param path Full pathname of the file. + */ + void ChangeDirectoryInternal(const std::string& path); + + /** + * @fn void FileUtils::InternalDirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite) const; + * + * @brief Internal dir copy. + * + * @param srcPath Full pathname of the source file. + * @param destPath Full pathname of the destination file. + * @param bOverwrite True to overwrite, false to preserve. + */ + void InternalDirCopy(const std::string& srcPath, const std::string& destPath, bool bOverwrite) const; + + /** + * @fn void FileUtils::RecursDeleteDir(bool bRecursive); + * + * @brief Recurs delete dir. + * + * @param bRecursive True to process recursively, false to process locally only. + */ + void RecursDeleteDir(bool bRecursive); + + /** + * @fn bool FileUtils::SplitArchiveFilename(const std::string& fullFilename, std::string& archiveFilename, std::string& fileInArchive) const; + * + * @brief Splits a filename for a file within an archive into two parts, the archive filename + * and the actual + * filename relative to the archive root. + * + * @param fullFilename Filename of the full file. + * @param [in,out] archiveFilename Filename of the archive file. + * @param [in,out] fileInArchive The file in archive. + * + * @return True if it succeeds, false if it fails. + */ + bool SplitArchiveFilename(const std::string& fullFilename, std::string& archiveFilename, std::string& fileInArchive) const; + + /** + * @fn void FileUtils::DirGetFilesInArchive(const osgDB::ArchiveExtended& a, const std::string& path, DirectoryContents& result) const; + * + * @brief Internal function used to find files within an archive subdirectory. + * + * @param a The osgDB::ArchiveExtended to process. + * @param path Full pathname of the file. + * @param [in,out] result The result. + */ + void DirGetFilesInArchive(const osgDB::ArchiveExtended& a, const std::string& path, DirectoryContents& result) const; + + /** + * @fn FileType FileUtils::GetFileTypeForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; + * + * @brief Gets file type for file in archive. + * + * @param a The osgDB::ArchiveExtended to process. + * @param path Full pathname of the file. + * + * @return The file type for file in archive. + */ + FileType GetFileTypeForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; + + /** + * @fn FileInfo FileUtils::GetFileInfoForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; + * + * @brief Gets file information for file in archive. + * + * @param a The osgDB::ArchiveExtended to process. + * @param path Full pathname of the file. + * + * @return The file information for file in archive. + */ + FileInfo GetFileInfoForFileInArchive(const osgDB::ArchiveExtended& a, const std::string& path) const; + + /** + * @fn FileType FileUtils::GetFileTypeFromOSGDBFileType(osgDB::FileType ft) const; + * + * @brief Gets file type from osgdb file type. + * + * @param ft The ft. + * + * @return The file type from osgdb file type. + */ + FileType GetFileTypeFromOSGDBFileType(osgDB::FileType ft) const; + + /** + * @fn bool FileUtils::ContainsArchiveExtension(const std::string& path) const; + * + * @brief Query if 'path' contains archive extension. + * + * @param path Full pathname of the file. + * + * @return True if it succeeds, false if it fails. + */ + bool ContainsArchiveExtension(const std::string& path) const; + + /** + * @fn std::string FileUtils::ArchiveRelativeToAbsolute(const std::string& relativeFile) const; + * + * @brief Archive relative to absolute. + * + * @param relativeFile The relative file. + * + * @return A std::string. + */ + std::string ArchiveRelativeToAbsolute(const std::string& relativeFile) const; + + /** + * @struct FileInfo + * + * @brief Information about the file. + */ + const struct FileInfo GetFileInfo_Internal(const std::string& strFile, bool caseInsensitive) const; + + /** + * @fn bool FileUtils::IsSameFile_Internal(const std::string& file1, const std::string& file2) const; + * + * @brief Query if 'file1' is same file internal. + * + * @param file1 The first file. + * @param file2 The second file. + * + * @return True if same file internal, false if not. + */ + bool IsSameFile_Internal(const std::string& file1, const std::string& file2) const; + + + static osg::ref_ptr mInstance; + + trUtil::Logging::Log* mLogger; + + std::string mCurrentDirectory; + std::vector mStackOfDirectories; + + }; + + /** + * @class DirectoryPush + * + * @brief Simple class to change directory where it automatically pop back out on destruction. + * To be used on the stack. + */ + class TR_UTIL_EXPORT DirectoryPush + { + public: + + /** + * @fn DirectoryPush::DirectoryPush(const std::string& dir); + * + * @brief Constructor. + * + * @param dir The dir. + */ + DirectoryPush(const std::string& dir); + + /** + * @fn DirectoryPush::~DirectoryPush(); + * + * @brief Destructor. + */ + ~DirectoryPush(); + + /** + * @fn bool DirectoryPush::GetSucceeded(); + * + * @brief Gets the succeeded. + * + * @return True if it succeeds, false if it fails. + */ + bool GetSucceeded(); + + /** + * @fn const std::string& DirectoryPush::GetError(); + * + * @brief Gets the error. + * + * @return The error. + */ + const std::string& GetError(); + private: + bool mSucceeded; + std::string mError; + }; + + /** + * @class IsPathSeparator + * + * @brief For tokenizing paths. + */ + class IsPathSeparator : public trUtil::UnaryFunction + { + public: + bool operator()(char c) const { return c == '/' || c == '\\' || c == FileUtils::PATH_SEPARATOR; } + }; } \ No newline at end of file diff --git a/include/trUtil/FunCall.h b/include/trUtil/FunCall.h index 21c7154..92c1eab 100644 --- a/include/trUtil/FunCall.h +++ b/include/trUtil/FunCall.h @@ -1,479 +1,479 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * Generalized functor implementation. Concept inspired by Andrei Alexandrescu. - * Copyright Aleksei Trunov 2005 - * Use, copy, modify, distribute and sell it for free. - */ - - // Functor calls helpers - - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_0() Type of the typelist 0() - */ - template struct CallParms; - template <> - struct CallParms - { - using ParmsListType = trUtil::InstantiateH; - static inline ParmsListType Make() { return ParmsListType(); } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_1(P1) Type of the typelist 1( p 1) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1) - { - return ParmsListType(p1); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_2(P1 Type of the typelist 2( p 1. - * @tparam P2) Type of the 2) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2)); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_3(P1 Type of the typelist 3( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3) Type of the 3) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2, P3 p3) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2, - typename trUtil::TailAt::Result(p3))); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_4(P1 Type of the typelist 4( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4) Type of the 4) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2, - typename trUtil::TailAt::Result(p3, - typename trUtil::TailAt::Result(p4)))); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_5(P1 Type of the typelist 5( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5) Type of the 5) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2, - typename trUtil::TailAt::Result(p3, - typename trUtil::TailAt::Result(p4, - typename trUtil::TailAt::Result(p5))))); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_6(P1 Type of the typelist 6( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5 Type of the p 5. - * @tparam P6) Type of the 6) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2, - typename trUtil::TailAt::Result(p3, - typename trUtil::TailAt::Result(p4, - typename trUtil::TailAt::Result(p5, - typename trUtil::TailAt::Result(p6)))))); - } - }; - - /** - * @struct CallParms - * - * @brief A call parameters. - * - * @tparam TYPELIST_7(P1 Type of the typelist 7( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5 Type of the p 5. - * @tparam P6 Type of the p 6. - * @tparam P7) Type of the 7) - */ - template - struct CallParms - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) - { - return ParmsListType(p1, - typename trUtil::TailAt::Result(p2, - typename trUtil::TailAt::Result(p3, - typename trUtil::TailAt::Result(p4, - typename trUtil::TailAt::Result(p5, - typename trUtil::TailAt::Result(p6, - typename trUtil::TailAt::Result(p7))))))); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_0() Type of the typelist 0() - */ - template struct FunctorCall; - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH; - template static inline R Call(Fun const& fun, ParmsListType& /*parms*/) - { - return fun(); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& /*parms*/) - { - return ((*pobj).*memfun)(); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_1(P1) Type of the typelist 1( p 1) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun(trUtil::GetH<0>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)(trUtil::GetH<0>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_2(P1 Type of the typelist 2( p 1. - * @tparam P2) Type of the 2) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_3(P1 Type of the typelist 3( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3) Type of the 3) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder> ; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_4(P1 Type of the typelist 4( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4) Type of the 4) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_5(P1 Type of the typelist 5( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5) Type of the 5) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_6(P1 Type of the typelist 6( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5 Type of the p 5. - * @tparam P6) Type of the 6) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value, - trUtil::GetH<5>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value, - trUtil::GetH<5>(parms).value); - } - }; - - /** - * @struct FunctorCall - * - * @brief A functor call. - * - * @tparam CallType Type of the call type. - * @tparam R Type of the r. - * @tparam TYPELIST_7(P1 Type of the typelist 7( p 1. - * @tparam P2 Type of the p 2. - * @tparam P3 Type of the p 3. - * @tparam P4 Type of the p 4. - * @tparam P5 Type of the p 5. - * @tparam P6 Type of the p 6. - * @tparam P7) Type of the 7) - */ - template - struct FunctorCall - { - using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder> ; - template static inline R Call(Fun const& fun, ParmsListType& parms) - { - return fun( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value, - trUtil::GetH<5>(parms).value, - trUtil::GetH<6>(parms).value); - } - template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) - { - return ((*pobj).*memfun)( - trUtil::GetH<0>(parms).value, - trUtil::GetH<1>(parms).value, - trUtil::GetH<2>(parms).value, - trUtil::GetH<3>(parms).value, - trUtil::GetH<4>(parms).value, - trUtil::GetH<5>(parms).value, - trUtil::GetH<6>(parms).value); - } - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * Generalized functor implementation. Concept inspired by Andrei Alexandrescu. + * Copyright Aleksei Trunov 2005 + * Use, copy, modify, distribute and sell it for free. + */ + + // Functor calls helpers + + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_0() Type of the typelist 0() + */ + template struct CallParms; + template <> + struct CallParms + { + using ParmsListType = trUtil::InstantiateH; + static inline ParmsListType Make() { return ParmsListType(); } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_1(P1) Type of the typelist 1( p 1) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1) + { + return ParmsListType(p1); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_2(P1 Type of the typelist 2( p 1. + * @tparam P2) Type of the 2) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2)); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_3(P1 Type of the typelist 3( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3) Type of the 3) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2, P3 p3) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2, + typename trUtil::TailAt::Result(p3))); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_4(P1 Type of the typelist 4( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4) Type of the 4) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2, + typename trUtil::TailAt::Result(p3, + typename trUtil::TailAt::Result(p4)))); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_5(P1 Type of the typelist 5( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5) Type of the 5) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2, + typename trUtil::TailAt::Result(p3, + typename trUtil::TailAt::Result(p4, + typename trUtil::TailAt::Result(p5))))); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_6(P1 Type of the typelist 6( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5 Type of the p 5. + * @tparam P6) Type of the 6) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2, + typename trUtil::TailAt::Result(p3, + typename trUtil::TailAt::Result(p4, + typename trUtil::TailAt::Result(p5, + typename trUtil::TailAt::Result(p6)))))); + } + }; + + /** + * @struct CallParms + * + * @brief A call parameters. + * + * @tparam TYPELIST_7(P1 Type of the typelist 7( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5 Type of the p 5. + * @tparam P6 Type of the p 6. + * @tparam P7) Type of the 7) + */ + template + struct CallParms + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + static inline ParmsListType Make(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) + { + return ParmsListType(p1, + typename trUtil::TailAt::Result(p2, + typename trUtil::TailAt::Result(p3, + typename trUtil::TailAt::Result(p4, + typename trUtil::TailAt::Result(p5, + typename trUtil::TailAt::Result(p6, + typename trUtil::TailAt::Result(p7))))))); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_0() Type of the typelist 0() + */ + template struct FunctorCall; + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH; + template static inline R Call(Fun const& fun, ParmsListType& /*parms*/) + { + return fun(); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& /*parms*/) + { + return ((*pobj).*memfun)(); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_1(P1) Type of the typelist 1( p 1) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun(trUtil::GetH<0>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)(trUtil::GetH<0>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_2(P1 Type of the typelist 2( p 1. + * @tparam P2) Type of the 2) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_3(P1 Type of the typelist 3( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3) Type of the 3) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder> ; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_4(P1 Type of the typelist 4( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4) Type of the 4) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_5(P1 Type of the typelist 5( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5) Type of the 5) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_6(P1 Type of the typelist 6( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5 Type of the p 5. + * @tparam P6) Type of the 6) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder>; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value, + trUtil::GetH<5>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value, + trUtil::GetH<5>(parms).value); + } + }; + + /** + * @struct FunctorCall + * + * @brief A functor call. + * + * @tparam CallType Type of the call type. + * @tparam R Type of the r. + * @tparam TYPELIST_7(P1 Type of the typelist 7( p 1. + * @tparam P2 Type of the p 2. + * @tparam P3 Type of the p 3. + * @tparam P4 Type of the p 4. + * @tparam P5 Type of the p 5. + * @tparam P6 Type of the p 6. + * @tparam P7) Type of the 7) + */ + template + struct FunctorCall + { + using ParmsListType = trUtil::InstantiateH::Type, trUtil::TupleHolder> ; + template static inline R Call(Fun const& fun, ParmsListType& parms) + { + return fun( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value, + trUtil::GetH<5>(parms).value, + trUtil::GetH<6>(parms).value); + } + template static inline R Call(PObj const& pobj, CallType memfun, ParmsListType& parms) + { + return ((*pobj).*memfun)( + trUtil::GetH<0>(parms).value, + trUtil::GetH<1>(parms).value, + trUtil::GetH<2>(parms).value, + trUtil::GetH<3>(parms).value, + trUtil::GetH<4>(parms).value, + trUtil::GetH<5>(parms).value, + trUtil::GetH<6>(parms).value); + } + }; } \ No newline at end of file diff --git a/include/trUtil/FunTraits.h b/include/trUtil/FunTraits.h index 84356d0..1256103 100644 --- a/include/trUtil/FunTraits.h +++ b/include/trUtil/FunTraits.h @@ -1,1062 +1,1062 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -// Generalized functor implementation helpers. -// Copyright Aleksei Trunov 2005 -// Use, copy, modify, distribute and sell it for free. - - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @struct FunTraits - * - * @brief Function traits. - * - * @tparam T Generic type parameter. - */ - template struct FunTraits; - -#if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; -#else // #if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = NullType; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P6); - }; -#endif //#if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) - - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using TypeListType = NullType; - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using TypeListType = TYPELIST_1(P1); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using TypeListType = TYPELIST_2(P1, P2); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using TypeListType = TYPELIST_3(P1, P2, P3); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using TypeListType = TYPELIST_4(P1, P2, P3, P4); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); - }; - template - struct FunTraits - { - using ObjType = O; - using ResultType = R; - using Parm1 = P1; - using Parm2 = P2; - using Parm3 = P3; - using Parm4 = P4; - using Parm5 = P5; - using Parm6 = P6; - using Parm7 = P7; - using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); - }; - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +// Generalized functor implementation helpers. +// Copyright Aleksei Trunov 2005 +// Use, copy, modify, distribute and sell it for free. + + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @struct FunTraits + * + * @brief Function traits. + * + * @tparam T Generic type parameter. + */ + template struct FunTraits; + +#if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; +#else // #if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = NullType; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P6); + }; +#endif //#if (defined(_MSC_VER)) && (_MANAGED != 1) && (!defined (_WIN64)) + + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using TypeListType = NullType; + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using TypeListType = TYPELIST_1(P1); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using TypeListType = TYPELIST_2(P1, P2); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using TypeListType = TYPELIST_3(P1, P2, P3); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using TypeListType = TYPELIST_4(P1, P2, P3, P4); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using TypeListType = TYPELIST_5(P1, P2, P3, P4, P5); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using TypeListType = TYPELIST_6(P1, P2, P3, P4, P5, P6); + }; + template + struct FunTraits + { + using ObjType = O; + using ResultType = R; + using Parm1 = P1; + using Parm2 = P2; + using Parm3 = P3; + using Parm4 = P4; + using Parm5 = P5; + using Parm6 = P6; + using Parm7 = P7; + using TypeListType = TYPELIST_7(P1, P2, P3, P4, P5, P6, P7); + }; + } \ No newline at end of file diff --git a/include/trUtil/Functor.h b/include/trUtil/Functor.h index a784021..590d0ef 100644 --- a/include/trUtil/Functor.h +++ b/include/trUtil/Functor.h @@ -1,337 +1,337 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include -#include -#include - -#include -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - // Generalized functor implementation. Concept inspired by Andrei Alexandrescu. - // Copyright Aleksei Trunov 2005 - // Use, copy, modify, distribute and sell it for free. - // - // Generalized functor class template - - - /** - * @class Functor - * - * @brief A functor. - */ - template - class Functor - { - public: - using ResultType = R ; - using TypeListType = TList; - using ParmsListType = typename CallParms::ParmsListType; - - /** - * @fn Functor::Functor() - * - * @brief default construction, assignment and destruction. - */ - Functor() : vptr_(0) {} - - /** - * @fn Functor::~Functor() - * - * @brief Destructor. - */ - ~Functor() - { - if (vptr_) vptr_->destroy_(*this); - } - - /** - * @fn Functor::Functor(Functor const& src) - * - * @brief Copy constructor. - * - * @param src Source for the. - */ - Functor(Functor const& src) - { - vptr_ = src.vptr_ ? src.vptr_->clone_(src, *this) : NULL; - } - - /** - * @fn Functor& Functor::operator=(Functor const& src) - * - * @brief Assignment operator. - * - * @param src Source for the. - * - * @return A shallow copy of this object. - */ - Functor& operator=(Functor const& src) - { - if (this != &src) { - if (vptr_) vptr_->destroy_(*this); - vptr_ = src.vptr_ ? src.vptr_->clone_(src, *this) : NULL; - } - return *this; - } - - /** - * @fn bool Functor::operator!() const - * - * @brief is-empty selector. - * - * @return The logical inverse of this value. - */ - bool operator!() const { return vptr_ == NULL; } - - /** - * @fn bool Functor::valid() const - * - * @brief Valids this object. - * - * @return True if it succeeds, false if it fails. - */ - bool valid() const { return vptr_ != NULL; } - - /** - * @fn template explicit Functor::Functor(F const& fun) - * - * @brief ctor for static fns and arbitrary functors. - * - * @tparam F Type of the f. - * @param fun The fun. - */ - template explicit Functor(F const& fun) - { - using StoredType = FunctorImpl; - vptr_ = _init(fun); - } - - /** - * @fn template explicit Functor::Functor(P const& pobj, MF memfun) - * - * @brief ctor for member fns (note: raw ptrs and smart ptrs are equally welcome in pobj) - * - * @tparam P Type of the p. - * @tparam MF Type of the mf. - * @param pobj The pobj. - * @param memfun The memfun. - */ - template explicit Functor(P const& pobj, MF memfun) - { - using StoredType = MemberFnImpl; - vptr_ = _init(std::pair(pobj, memfun)); - } - // calls - using Parm1 = typename trUtil::TypeAtNonStrict::Result; - using Parm2 = typename trUtil::TypeAtNonStrict::Result; - using Parm3 = typename trUtil::TypeAtNonStrict::Result; - using Parm4 = typename trUtil::TypeAtNonStrict::Result; - using Parm5 = typename trUtil::TypeAtNonStrict::Result; - using Parm6 = typename trUtil::TypeAtNonStrict::Result; - using Parm7 = typename trUtil::TypeAtNonStrict::Result; -#define DoCall(parms) return vptr_->call_(*this, parms); - inline R operator()(ParmsListType const& parms) const { DoCall(parms) } - inline R operator()() const { DoCall(CallParms::Make()) } - inline R operator()(Parm1 p1) const { DoCall(CallParms::Make(p1)) } - inline R operator()(Parm1 p1, Parm2 p2) const { DoCall(CallParms::Make(p1, p2)) } - inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3) const { DoCall(CallParms::Make(p1, p2, p3)) } - inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4) const { DoCall(CallParms::Make(p1, p2, p3, p4)) } - inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5)) } - inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5, Parm6 p6) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5, p6)) } - inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5, Parm6 p6, Parm7 p7) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5, p6, p7)) } - private: - // copying/destruction and calls implementation - struct FunImplBase - { - struct VTable; - struct VTable - { - void(*destroy_)(Functor const&); - VTable* (*clone_)(Functor const&, Functor&); - R(*call_)(Functor const&, ParmsListType); - }; - // VTable vtbl_; // not needed here and actually wastes space! - }; - template - struct FunStorageImpl : public FunImplBase - { - V val_; - FunStorageImpl(V const& val) : val_(val) {} - static void Destroy(Functor const& src) { src.val_.template destroy(); } - static typename FunImplBase::VTable* Clone(Functor const& src, Functor& dest) - { - Derived const& this_ = src.val_.template get(); - return dest._init(this_.val_); - } - }; - template - struct FunctorImpl : public FunStorageImpl > - { - FunctorImpl(T const& val) : FunStorageImpl(val) {} - static R Call(Functor const& src, ParmsListType parms) - { - FunctorImpl const& this_ = src.val_.template get(); - return FunctorCall::Call(this_.val_, parms); - } - }; - template - struct MemberFnImpl : public FunStorageImpl, MemberFnImpl > - { - MemberFnImpl(std::pair const& val) : FunStorageImpl, MemberFnImpl>(val) {} - static R Call(Functor const& src, ParmsListType parms) - { - MemberFnImpl const& this_ = src.val_.template get(); - return FunctorCall::Call(this_.val_.first, this_.val_.second, parms); - } - }; - // initialization helper - template - typename FunImplBase::VTable* _init(V const& v) - { - val_.template init(v); - static typename FunImplBase::VTable vtbl = - { - &T::Destroy, - &T::Clone, - &T::Call, - }; - return &vtbl; - } - // typeless storage support - struct Typeless - { - template inline T* init1(T* v) { return new(getbuf()) T(v); } - template inline T* init(V const& v) { return new(getbuf()) T(v); } - template inline void destroy() const { (*reinterpret_cast(getbuf())).~T(); } - template inline T const& get() const { return *reinterpret_cast(getbuf()); } - template inline T& get() { return *reinterpret_cast(getbuf()); } - void* getbuf() { return &buffer_[0]; } - void const* getbuf() const { return &buffer_[0]; } - unsigned char buffer_[size]; - }; - template - struct ByValue - { - template inline static T* init(Typeless& val, V const& v) { return val.template init(v); } - inline static void destroy(Typeless const& val) { val.template destroy(); } - inline static T const& get(Typeless const& val) { return val.template get(); } - inline static T& get(Typeless& val) { return val.template get(); } - }; - template - struct NewAlloc - { - template inline static T* init(Typeless& val, V const& v) { return *val.template init(new T(v)); } - inline static void destroy(Typeless const& val) { delete val.template get(); } - inline static T const& get(Typeless const& val) { return *val.template get(); } - inline static T& get(Typeless& val) { return *val.template get(); } - }; - template - struct SelectStored - { - // TODO: it seems this is a good place to add alignment calculations - using Type = typename trUtil::Select, NewAlloc>::Result ; - }; - struct Stored - { - template inline T* init(V const& v) { return SelectStored::Type::init(val_, v); } - template inline void destroy() const { SelectStored::Type::destroy(val_); } - template inline T const& get() const { return SelectStored::Type::get(val_); } - template inline T& get() { return SelectStored::Type::get(val_); } - Typeless val_; - }; - Stored val_; - typename FunImplBase::VTable* vptr_; - }; - - // Helper functor creation functions - - - /** - * @fn MakeFunctor(CallType fun) - * - * @brief Constructor. - * - * @param fun The fun. - */ - template inline - Functor::ResultType, typename trUtil::FunTraits::TypeListType> - MakeFunctor(CallType fun) - { - return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(fun); - } - - /** - * @fn MakeFunctor(CallType memfun, PObj* const pobj) - * - * @brief Constructor. - * - * @param memfun The memfun. - * @param [in,out] pobj If non-null, the pobj. - */ - template inline - Functor::ResultType, typename trUtil::FunTraits::TypeListType> - MakeFunctor(CallType memfun, PObj* const pobj) - { - return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(pobj, memfun); - } - - /** - * @fn MakeFunctor(Fun const& fun) - * - * @brief Constructor. - * - * @param fun The fun. - */ - template inline - Functor::ResultType, typename trUtil::FunTraits::TypeListType> - MakeFunctor(Fun const& fun) - { - return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(fun); - } - - /** - * @fn MakeFunctor(CallType memfun, PObj& pobj) - * - * @brief Constructor. - * - * @param memfun The memfun. - * @param [in,out] pobj The pobj. - */ - template inline - Functor::ResultType, typename trUtil::FunTraits::TypeListType> - MakeFunctor(CallType memfun, PObj& pobj) - { - return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(&pobj, memfun); - } -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include +#include +#include + +#include +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + // Generalized functor implementation. Concept inspired by Andrei Alexandrescu. + // Copyright Aleksei Trunov 2005 + // Use, copy, modify, distribute and sell it for free. + // + // Generalized functor class template + + + /** + * @class Functor + * + * @brief A functor. + */ + template + class Functor + { + public: + using ResultType = R ; + using TypeListType = TList; + using ParmsListType = typename CallParms::ParmsListType; + + /** + * @fn Functor::Functor() + * + * @brief default construction, assignment and destruction. + */ + Functor() : vptr_(0) {} + + /** + * @fn Functor::~Functor() + * + * @brief Destructor. + */ + ~Functor() + { + if (vptr_) vptr_->destroy_(*this); + } + + /** + * @fn Functor::Functor(Functor const& src) + * + * @brief Copy constructor. + * + * @param src Source for the. + */ + Functor(Functor const& src) + { + vptr_ = src.vptr_ ? src.vptr_->clone_(src, *this) : NULL; + } + + /** + * @fn Functor& Functor::operator=(Functor const& src) + * + * @brief Assignment operator. + * + * @param src Source for the. + * + * @return A shallow copy of this object. + */ + Functor& operator=(Functor const& src) + { + if (this != &src) { + if (vptr_) vptr_->destroy_(*this); + vptr_ = src.vptr_ ? src.vptr_->clone_(src, *this) : NULL; + } + return *this; + } + + /** + * @fn bool Functor::operator!() const + * + * @brief is-empty selector. + * + * @return The logical inverse of this value. + */ + bool operator!() const { return vptr_ == NULL; } + + /** + * @fn bool Functor::valid() const + * + * @brief Valids this object. + * + * @return True if it succeeds, false if it fails. + */ + bool valid() const { return vptr_ != NULL; } + + /** + * @fn template explicit Functor::Functor(F const& fun) + * + * @brief ctor for static fns and arbitrary functors. + * + * @tparam F Type of the f. + * @param fun The fun. + */ + template explicit Functor(F const& fun) + { + using StoredType = FunctorImpl; + vptr_ = _init(fun); + } + + /** + * @fn template explicit Functor::Functor(P const& pobj, MF memfun) + * + * @brief ctor for member fns (note: raw ptrs and smart ptrs are equally welcome in pobj) + * + * @tparam P Type of the p. + * @tparam MF Type of the mf. + * @param pobj The pobj. + * @param memfun The memfun. + */ + template explicit Functor(P const& pobj, MF memfun) + { + using StoredType = MemberFnImpl; + vptr_ = _init(std::pair(pobj, memfun)); + } + // calls + using Parm1 = typename trUtil::TypeAtNonStrict::Result; + using Parm2 = typename trUtil::TypeAtNonStrict::Result; + using Parm3 = typename trUtil::TypeAtNonStrict::Result; + using Parm4 = typename trUtil::TypeAtNonStrict::Result; + using Parm5 = typename trUtil::TypeAtNonStrict::Result; + using Parm6 = typename trUtil::TypeAtNonStrict::Result; + using Parm7 = typename trUtil::TypeAtNonStrict::Result; +#define DoCall(parms) return vptr_->call_(*this, parms); + inline R operator()(ParmsListType const& parms) const { DoCall(parms) } + inline R operator()() const { DoCall(CallParms::Make()) } + inline R operator()(Parm1 p1) const { DoCall(CallParms::Make(p1)) } + inline R operator()(Parm1 p1, Parm2 p2) const { DoCall(CallParms::Make(p1, p2)) } + inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3) const { DoCall(CallParms::Make(p1, p2, p3)) } + inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4) const { DoCall(CallParms::Make(p1, p2, p3, p4)) } + inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5)) } + inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5, Parm6 p6) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5, p6)) } + inline R operator()(Parm1 p1, Parm2 p2, Parm3 p3, Parm4 p4, Parm5 p5, Parm6 p6, Parm7 p7) const { DoCall(CallParms::Make(p1, p2, p3, p4, p5, p6, p7)) } + private: + // copying/destruction and calls implementation + struct FunImplBase + { + struct VTable; + struct VTable + { + void(*destroy_)(Functor const&); + VTable* (*clone_)(Functor const&, Functor&); + R(*call_)(Functor const&, ParmsListType); + }; + // VTable vtbl_; // not needed here and actually wastes space! + }; + template + struct FunStorageImpl : public FunImplBase + { + V val_; + FunStorageImpl(V const& val) : val_(val) {} + static void Destroy(Functor const& src) { src.val_.template destroy(); } + static typename FunImplBase::VTable* Clone(Functor const& src, Functor& dest) + { + Derived const& this_ = src.val_.template get(); + return dest._init(this_.val_); + } + }; + template + struct FunctorImpl : public FunStorageImpl > + { + FunctorImpl(T const& val) : FunStorageImpl(val) {} + static R Call(Functor const& src, ParmsListType parms) + { + FunctorImpl const& this_ = src.val_.template get(); + return FunctorCall::Call(this_.val_, parms); + } + }; + template + struct MemberFnImpl : public FunStorageImpl, MemberFnImpl > + { + MemberFnImpl(std::pair const& val) : FunStorageImpl, MemberFnImpl>(val) {} + static R Call(Functor const& src, ParmsListType parms) + { + MemberFnImpl const& this_ = src.val_.template get(); + return FunctorCall::Call(this_.val_.first, this_.val_.second, parms); + } + }; + // initialization helper + template + typename FunImplBase::VTable* _init(V const& v) + { + val_.template init(v); + static typename FunImplBase::VTable vtbl = + { + &T::Destroy, + &T::Clone, + &T::Call, + }; + return &vtbl; + } + // typeless storage support + struct Typeless + { + template inline T* init1(T* v) { return new(getbuf()) T(v); } + template inline T* init(V const& v) { return new(getbuf()) T(v); } + template inline void destroy() const { (*reinterpret_cast(getbuf())).~T(); } + template inline T const& get() const { return *reinterpret_cast(getbuf()); } + template inline T& get() { return *reinterpret_cast(getbuf()); } + void* getbuf() { return &buffer_[0]; } + void const* getbuf() const { return &buffer_[0]; } + unsigned char buffer_[size]; + }; + template + struct ByValue + { + template inline static T* init(Typeless& val, V const& v) { return val.template init(v); } + inline static void destroy(Typeless const& val) { val.template destroy(); } + inline static T const& get(Typeless const& val) { return val.template get(); } + inline static T& get(Typeless& val) { return val.template get(); } + }; + template + struct NewAlloc + { + template inline static T* init(Typeless& val, V const& v) { return *val.template init(new T(v)); } + inline static void destroy(Typeless const& val) { delete val.template get(); } + inline static T const& get(Typeless const& val) { return *val.template get(); } + inline static T& get(Typeless& val) { return *val.template get(); } + }; + template + struct SelectStored + { + // TODO: it seems this is a good place to add alignment calculations + using Type = typename trUtil::Select, NewAlloc>::Result ; + }; + struct Stored + { + template inline T* init(V const& v) { return SelectStored::Type::init(val_, v); } + template inline void destroy() const { SelectStored::Type::destroy(val_); } + template inline T const& get() const { return SelectStored::Type::get(val_); } + template inline T& get() { return SelectStored::Type::get(val_); } + Typeless val_; + }; + Stored val_; + typename FunImplBase::VTable* vptr_; + }; + + // Helper functor creation functions + + + /** + * @fn MakeFunctor(CallType fun) + * + * @brief Constructor. + * + * @param fun The fun. + */ + template inline + Functor::ResultType, typename trUtil::FunTraits::TypeListType> + MakeFunctor(CallType fun) + { + return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(fun); + } + + /** + * @fn MakeFunctor(CallType memfun, PObj* const pobj) + * + * @brief Constructor. + * + * @param memfun The memfun. + * @param [in,out] pobj If non-null, the pobj. + */ + template inline + Functor::ResultType, typename trUtil::FunTraits::TypeListType> + MakeFunctor(CallType memfun, PObj* const pobj) + { + return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(pobj, memfun); + } + + /** + * @fn MakeFunctor(Fun const& fun) + * + * @brief Constructor. + * + * @param fun The fun. + */ + template inline + Functor::ResultType, typename trUtil::FunTraits::TypeListType> + MakeFunctor(Fun const& fun) + { + return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(fun); + } + + /** + * @fn MakeFunctor(CallType memfun, PObj& pobj) + * + * @brief Constructor. + * + * @param memfun The memfun. + * @param [in,out] pobj The pobj. + */ + template inline + Functor::ResultType, typename trUtil::FunTraits::TypeListType> + MakeFunctor(CallType memfun, PObj& pobj) + { + return trUtil::Functor::ResultType, typename trUtil::FunTraits::TypeListType>(&pobj, memfun); + } +} + diff --git a/include/trUtil/Hash.h b/include/trUtil/Hash.h index 2d529a7..18ddc96 100644 --- a/include/trUtil/Hash.h +++ b/include/trUtil/Hash.h @@ -1,248 +1,248 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - /** - * @struct hash - * - * @brief This Hash class and its implementations are taken from the libstdc++ hash_fun.h. - * - * @tparam _Key Type of the key. - */ - template struct hash; - - /** - * @struct hash<_Key*> - * - * @brief A hash. - * - * @tparam _Key Type of the key. - */ - template struct hash<_Key*> - { - size_t operator()(const _Key* keyPtr) const - { - return size_t(keyPtr); - } - }; - - /** - * @fn inline size_t __hash_string(const char* __s) - * - * @brief Hash string. - * - * @param __s The s. - * - * @return A size_t. - */ - inline size_t __hash_string(const char* __s) - { - unsigned long __h = 0; - for (; *__s; ++__s) - __h = 5 * __h + *__s; - return size_t(__h); - } - - /** - * @struct hash - * - * @brief A string>. - */ - template<> struct hash - { - size_t operator()(const std::string& string) const - { - return __hash_string(string.c_str()); - } - }; - - /** - * @struct hash - * - * @brief A string>. - */ - template<> struct hash - { - size_t operator()(const std::string& string) const - { - return __hash_string(string.c_str()); - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(const char* __s) const - { - return __hash_string(__s); - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(const char* __s) const - { - return __hash_string(__s); - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(char __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(unsigned char __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(unsigned char __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(short __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(unsigned short __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(int __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(unsigned int __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(long __x) const - { - return __x; - } - }; - - /** - * @struct hash - * - * @brief A hash. - */ - template<> struct hash - { - size_t operator()(unsigned long __x) const - { - return __x; - } - }; -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + /** + * @struct hash + * + * @brief This Hash class and its implementations are taken from the libstdc++ hash_fun.h. + * + * @tparam _Key Type of the key. + */ + template struct hash; + + /** + * @struct hash<_Key*> + * + * @brief A hash. + * + * @tparam _Key Type of the key. + */ + template struct hash<_Key*> + { + size_t operator()(const _Key* keyPtr) const + { + return size_t(keyPtr); + } + }; + + /** + * @fn inline size_t __hash_string(const char* __s) + * + * @brief Hash string. + * + * @param __s The s. + * + * @return A size_t. + */ + inline size_t __hash_string(const char* __s) + { + unsigned long __h = 0; + for (; *__s; ++__s) + __h = 5 * __h + *__s; + return size_t(__h); + } + + /** + * @struct hash + * + * @brief A string>. + */ + template<> struct hash + { + size_t operator()(const std::string& string) const + { + return __hash_string(string.c_str()); + } + }; + + /** + * @struct hash + * + * @brief A string>. + */ + template<> struct hash + { + size_t operator()(const std::string& string) const + { + return __hash_string(string.c_str()); + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(const char* __s) const + { + return __hash_string(__s); + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(const char* __s) const + { + return __hash_string(__s); + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(char __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(unsigned char __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(unsigned char __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(short __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(unsigned short __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(int __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(unsigned int __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(long __x) const + { + return __x; + } + }; + + /** + * @struct hash + * + * @brief A hash. + */ + template<> struct hash + { + size_t operator()(unsigned long __x) const + { + return __x; + } + }; +} + diff --git a/include/trUtil/HashMap.h b/include/trUtil/HashMap.h index 64c4391..c331577 100644 --- a/include/trUtil/HashMap.h +++ b/include/trUtil/HashMap.h @@ -1,121 +1,121 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -*/ -#pragma once - -#if defined( _LIBCPP_VERSION ) || (defined(_MSC_VER) && _MSC_VER >= 1700) || defined(__GNUG__) -# include -# define _UNORDERED_MAP -#elif defined(_MSC_VER) -# include -#else -# include -#endif - -#include - -namespace trUtil -{ - -#if defined(_MSC_VER) && ! defined(_UNORDERED_MAP) - template - struct HashCompare - { - size_t operator() (const _Key& k) const - { - _HashFcn h; - return h(k); - } - bool operator() (const _Key& k1, const _Key& k2) const - { - _LessKey l; - return l(k1, k2); - } - - enum - { // parameters for hash table - bucket_size = 4, // 0 < bucket_size - min_buckets = 8 - }; // min_buckets = 2 ^^ N, 0 < N - - }; -#else - template - struct HashEqual - { - bool operator() (const _Key& k1, const _Key& k2) const - { - _LessKey l; - return !l(k1, k2) && !l(k2, k1); - } - }; -#endif - - template, class _LessKey = std::less<_Key>, class _Alloc = std::allocator > > - class HashMap : public -#if defined(_UNORDERED_MAP) - std::unordered_map<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc > - { - public: - using BaseClass = std::unordered_map<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc>; -#elif defined(_MSC_VER) - stdext::hash_map<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc > - { - public: - using BaseClass = stdext::hash_map<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc>; -#else - std::map<_Key, _Tp, _LessKey, _Alloc > - { - public: - using BaseClass = std::map<_Key, _Tp, _LessKey, _Alloc>; -#endif - using typename BaseClass::iterator; - using typename BaseClass::const_iterator; - HashMap() {} - }; - - template, class _LessKey = std::less<_Key>, class _Alloc = std::allocator > > - class HashMultiMap : public -#if defined(_UNORDERED_MAP) - std::unordered_multimap<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc > - { - public: - using BaseClass = std::unordered_multimap<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc>; -#elif defined(_MSC_VER) - stdext::hash_multimap<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc > - { - public: - using BaseClass = stdext::hash_multimap<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc>; -#else - std::multimap<_Key, _Tp, _LessKey, _Alloc > - { - public: - using BaseClass = std::multimap<_Key, _Tp, _LessKey, _Alloc>; -#endif - using typename BaseClass::iterator; - using typename BaseClass::const_iterator; - HashMultiMap() {} - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +*/ +#pragma once + +#if defined( _LIBCPP_VERSION ) || (defined(_MSC_VER) && _MSC_VER >= 1700) || defined(__GNUG__) +# include +# define _UNORDERED_MAP +#elif defined(_MSC_VER) +# include +#else +# include +#endif + +#include + +namespace trUtil +{ + +#if defined(_MSC_VER) && ! defined(_UNORDERED_MAP) + template + struct HashCompare + { + size_t operator() (const _Key& k) const + { + _HashFcn h; + return h(k); + } + bool operator() (const _Key& k1, const _Key& k2) const + { + _LessKey l; + return l(k1, k2); + } + + enum + { // parameters for hash table + bucket_size = 4, // 0 < bucket_size + min_buckets = 8 + }; // min_buckets = 2 ^^ N, 0 < N + + }; +#else + template + struct HashEqual + { + bool operator() (const _Key& k1, const _Key& k2) const + { + _LessKey l; + return !l(k1, k2) && !l(k2, k1); + } + }; +#endif + + template, class _LessKey = std::less<_Key>, class _Alloc = std::allocator > > + class HashMap : public +#if defined(_UNORDERED_MAP) + std::unordered_map<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc > + { + public: + using BaseClass = std::unordered_map<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc>; +#elif defined(_MSC_VER) + stdext::hash_map<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc > + { + public: + using BaseClass = stdext::hash_map<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc>; +#else + std::map<_Key, _Tp, _LessKey, _Alloc > + { + public: + using BaseClass = std::map<_Key, _Tp, _LessKey, _Alloc>; +#endif + using typename BaseClass::iterator; + using typename BaseClass::const_iterator; + HashMap() {} + }; + + template, class _LessKey = std::less<_Key>, class _Alloc = std::allocator > > + class HashMultiMap : public +#if defined(_UNORDERED_MAP) + std::unordered_multimap<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc > + { + public: + using BaseClass = std::unordered_multimap<_Key, _Tp, _HashFcn, trUtil::HashEqual<_Key, _LessKey>, _Alloc>; +#elif defined(_MSC_VER) + stdext::hash_multimap<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc > + { + public: + using BaseClass = stdext::hash_multimap<_Key, _Tp, trUtil::HashCompare<_Key, _HashFcn, _LessKey>, _Alloc>; +#else + std::multimap<_Key, _Tp, _LessKey, _Alloc > + { + public: + using BaseClass = std::multimap<_Key, _Tp, _LessKey, _Alloc>; +#endif + using typename BaseClass::iterator; + using typename BaseClass::const_iterator; + HashMultiMap() {} + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/Array.h b/include/trUtil/JSON/Array.h index c90647a..0b9f646 100644 --- a/include/trUtil/JSON/Array.h +++ b/include/trUtil/JSON/Array.h @@ -1,535 +1,535 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - - -#include - -#include -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @class Array - * - * @brief A JSON array. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT Array : ArrayBase - { - public: - - /** - * @fn Array::Array(); - * - * @brief ctor. - */ - Array(); - - /** - * @fn Array::Array(const Value &Array); - * - * @brief ctor that takes a JSON Value of an Array type as input. - * - * @param Array The array. - */ - Array(const Value &Array); - - /** - * @fn Array::~Array(); - * - * @brief dtor. - */ - ~Array(); - - /** - * @fn Value Array::operator[](int index); - * - * @brief Access an array element (zero based index ). The return is by value, but the internal - * json object is stored by reference. - * - * @param index Zero-based index of the. - * - * @return The indexed value. - */ - Value operator[](int index); - - /* - * Adds a comment to the internal value - */ - - /** - * @fn void Array::SetComment(const std::string& comment); - * - * @brief Sets a comment. - * - * @param comment The comment. - */ - void SetComment(const std::string& comment); - - /** - * @fn bool Array::HasComment() const; - * - * @brief Checks if the internal value has a comment. - * - * @return True if comment, false if not. - */ - bool HasComment() const; - - /** - * @fn std::string Array::GetComment() const; - * - * @brief Returns the internal comment. - * - * @return The comment. - */ - std::string GetComment() const; - - /** - * @fn int Array::Size(); - * - * @brief Get the size of the array. - * - * @return An int. - */ - int Size(); - - /** - * @fn void Array::Resize(int newSize); - * - * @brief Change the size of the array to the new passed in size. - * - * @param newSize Size of the new. - */ - void Resize(int newSize); - - /** - * @fn void Array::Clear() override; - * - * @brief Clears the internal JSON Root node. - */ - void Clear() override; - - /** - * @fn bool Array::RemoveIndex(int index, Value *removedVal); - * - * @brief Removes a given element of the array. Passes back the removed value though the - * pointer and sets the return to TRUE. - * - * @param index Zero-based index of the. - * @param [in,out] removedVal If non-null, the removed value. - * - * @return True if it succeeds, false if it fails. - */ - bool RemoveIndex(int index, Value *removedVal); - - /** - * @fn virtual Value& Array::GetJSONRoot() override; - * - * @brief Returns a reference to the internal JSON Root node. - * - * @return The JSON root. - */ - virtual Value& GetJSONRoot() override; - - /** - * @fn virtual void Array::PrintJSONRoot() override; - * - * @brief Prints out to the screen the whole JSON Root content. - */ - virtual void PrintJSONRoot() override; - - /** - * @fn virtual bool Array::IsNull(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a NULL. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if null, false if not. - */ - virtual bool IsNull(int &index) const override; - - /** - * @fn virtual void Array::AddNull() override; - * - * @brief Add a NULL Value to the Array. - */ - virtual void AddNull() override; - - /** - * @fn virtual bool Array::IsBool(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a Boolean. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(int &index) const override; - - /** - * @fn virtual bool Array::GetBool(int &index) const override; - * - * @brief Returns the Boolean value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(int &index) const override; - - /** - * @fn virtual void Array::AddBool(const bool &value) override; - * - * @brief Adds a Boolean to the Array. - * - * @param value The value. - */ - virtual void AddBool(const bool &value) override; - - /** - * @fn virtual bool Array::IsTrue(int &index) const override; - * - * @brief Checks if the value stored at the specific index is True. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if true, false if not. - */ - virtual bool IsTrue(int &index) const override; - - /** - * @fn virtual bool Array::IsFalse(int &index) const override; - * - * @brief Checks if the value stored at the specific index is False. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if false, false if not. - */ - virtual bool IsFalse(int &index) const override; - - /** - * @fn virtual bool Array::IsNumber(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a Number. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(int &index) const override; - - /** - * @fn virtual bool Array::IsInt(int &index) const override; - * - * @brief Checks if the value stored at the specific index is an Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if int, false if not. - */ - virtual bool IsInt(int &index) const override; - - /** - * @fn virtual int Array::GetInt(int &index) const override; - * - * @brief Returns the Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The int. - */ - virtual int GetInt(int &index) const override; - - /** - * @fn virtual void Array::AddInt(const int &value) override; - * - * @brief Adds the Integer value to the Array. - * - * @param value The value. - */ - virtual void AddInt(const int &value) override; - - /** - * @fn virtual bool Array::IsDouble(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a Double. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(int &index) const override; - - /** - * @fn virtual double Array::GetDouble(int &index) const override; - * - * @brief Returns the Double value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The double. - */ - virtual double GetDouble(int &index) const override; - - /** - * @fn virtual void Array::AddDouble(const double &value) override; - * - * @brief Adds the Double value to the Array. - * - * @param value The value. - */ - virtual void AddDouble(const double &value) override; - - /** - * @fn virtual bool Array::IsUInt(int &index) const override; - * - * @brief Checks if the value stored at the specific index is an Unsigned Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(int &index) const override; - - /** - * @fn virtual unsigned int Array::GetUInt(int &index) const override; - * - * @brief Returns the Unsigned Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The u int. - */ - virtual unsigned int GetUInt(int &index) const override; - - /** - * @fn virtual void Array::AddUInt(const unsigned int &value) override; - * - * @brief Adds the Unsigned Integer value the Array. - * - * @param value The value. - */ - virtual void AddUInt(const unsigned int &value) override; - - /** - * @fn virtual bool Array::IsInt64(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a 64bit Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(int &index) const override; - - /** - * @fn virtual Int64 Array::GetInt64(int &index) const override; - * - * @brief Returns the 64bit Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The int 64. - */ - virtual Int64 GetInt64(int &index) const override; - - /** - * @fn virtual void Array::AddInt64(const Int64 &value) override; - * - * @brief Adds the 64bit Integer value to the Array. - * - * @param value The value. - */ - virtual void AddInt64(const Int64 &value) override; - - /** - * @fn virtual bool Array::IsUInt64(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a 64bit Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(int &index) const override; - - /** - * @fn virtual UInt64 Array::GetUInt64(int &index) const override; - * - * @brief Returns the 64bit Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(int &index) const override; - - /** - * @fn virtual void Array::AddUInt64(const UInt64 &value) override; - * - * @brief Adds the 64bit Integer value to the Array. - * - * @param value The value. - */ - virtual void AddUInt64(const UInt64 &value) override; - - /** - * @fn virtual bool Array::IsFloat(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a float. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(int &index) const override; - - /** - * @fn virtual float Array::GetFloat(int &index) const override; - * - * @brief Returns the float value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The float. - */ - virtual float GetFloat(int &index) const override; - - /** - * @fn virtual void Array::AddFloat(const float &value) override; - * - * @brief Adds the float value to the Array. - * - * @param value The value. - */ - virtual void AddFloat(const float &value) override; - - /** - * @fn virtual bool Array::IsString(int &index) const override; - * - * @brief Checks if the value stored at the specific index is a String. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if string, false if not. - */ - virtual bool IsString(int &index) const override; - - /** - * @fn virtual const std::string Array::GetString(int &index) const override; - * - * @brief Returns the String value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The string. - */ - virtual const std::string GetString(int &index) const override; - - /** - * @fn virtual void Array::AddString(const std::string &value) override; - * - * @brief Adds the String to the Array. - * - * @param value The value. - */ - virtual void AddString(const std::string &value) override; - - /** - * @fn virtual bool Array::IsArray(int &index) const override; - * - * @brief Checks if the value stored at the specific index is an Array. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if array, false if not. - */ - virtual bool IsArray(int &index) const override; - - /** - * @fn virtual Array Array::GetArray(int &index) const override; - * - * @brief Returns the Array value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The array. - */ - virtual Array GetArray(int &index) const override; - - /** - * @fn virtual void Array::AddArray(Array &Array) override; - * - * @brief Adds the Array to the Array. - * - * @param [in,out] Array The array. - */ - virtual void AddArray(Array &Array) override; - - /** - * @fn virtual bool Array::IsObject(int &index) const override; - * - * @brief Checks if the value stored at the specific index is an Object. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if object, false if not. - */ - virtual bool IsObject(int &index) const override; - - /** - * @fn virtual Object Array::GetObject(int &index) const override; - * - * @brief Returns the Object value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The object. - */ - virtual Object GetObject(int &index) const override; - - /** - * @fn virtual void Array::AddObject(Object &Object) override; - * - * @brief Adds the Object to the Array. - * - * @param [in,out] Object The object. - */ - virtual void AddObject(Object &Object) override; - - private: - /** @brief The root. */ - Value mRoot = Value(ValueType::ArrayValue); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + + +#include + +#include +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @class Array + * + * @brief A JSON array. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT Array : ArrayBase + { + public: + + /** + * @fn Array::Array(); + * + * @brief ctor. + */ + Array(); + + /** + * @fn Array::Array(const Value &Array); + * + * @brief ctor that takes a JSON Value of an Array type as input. + * + * @param Array The array. + */ + Array(const Value &Array); + + /** + * @fn Array::~Array(); + * + * @brief dtor. + */ + ~Array(); + + /** + * @fn Value Array::operator[](int index); + * + * @brief Access an array element (zero based index ). The return is by value, but the internal + * json object is stored by reference. + * + * @param index Zero-based index of the. + * + * @return The indexed value. + */ + Value operator[](int index); + + /* + * Adds a comment to the internal value + */ + + /** + * @fn void Array::SetComment(const std::string& comment); + * + * @brief Sets a comment. + * + * @param comment The comment. + */ + void SetComment(const std::string& comment); + + /** + * @fn bool Array::HasComment() const; + * + * @brief Checks if the internal value has a comment. + * + * @return True if comment, false if not. + */ + bool HasComment() const; + + /** + * @fn std::string Array::GetComment() const; + * + * @brief Returns the internal comment. + * + * @return The comment. + */ + std::string GetComment() const; + + /** + * @fn int Array::Size(); + * + * @brief Get the size of the array. + * + * @return An int. + */ + int Size(); + + /** + * @fn void Array::Resize(int newSize); + * + * @brief Change the size of the array to the new passed in size. + * + * @param newSize Size of the new. + */ + void Resize(int newSize); + + /** + * @fn void Array::Clear() override; + * + * @brief Clears the internal JSON Root node. + */ + void Clear() override; + + /** + * @fn bool Array::RemoveIndex(int index, Value *removedVal); + * + * @brief Removes a given element of the array. Passes back the removed value though the + * pointer and sets the return to TRUE. + * + * @param index Zero-based index of the. + * @param [in,out] removedVal If non-null, the removed value. + * + * @return True if it succeeds, false if it fails. + */ + bool RemoveIndex(int index, Value *removedVal); + + /** + * @fn virtual Value& Array::GetJSONRoot() override; + * + * @brief Returns a reference to the internal JSON Root node. + * + * @return The JSON root. + */ + virtual Value& GetJSONRoot() override; + + /** + * @fn virtual void Array::PrintJSONRoot() override; + * + * @brief Prints out to the screen the whole JSON Root content. + */ + virtual void PrintJSONRoot() override; + + /** + * @fn virtual bool Array::IsNull(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a NULL. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if null, false if not. + */ + virtual bool IsNull(int &index) const override; + + /** + * @fn virtual void Array::AddNull() override; + * + * @brief Add a NULL Value to the Array. + */ + virtual void AddNull() override; + + /** + * @fn virtual bool Array::IsBool(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a Boolean. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(int &index) const override; + + /** + * @fn virtual bool Array::GetBool(int &index) const override; + * + * @brief Returns the Boolean value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(int &index) const override; + + /** + * @fn virtual void Array::AddBool(const bool &value) override; + * + * @brief Adds a Boolean to the Array. + * + * @param value The value. + */ + virtual void AddBool(const bool &value) override; + + /** + * @fn virtual bool Array::IsTrue(int &index) const override; + * + * @brief Checks if the value stored at the specific index is True. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if true, false if not. + */ + virtual bool IsTrue(int &index) const override; + + /** + * @fn virtual bool Array::IsFalse(int &index) const override; + * + * @brief Checks if the value stored at the specific index is False. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if false, false if not. + */ + virtual bool IsFalse(int &index) const override; + + /** + * @fn virtual bool Array::IsNumber(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a Number. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(int &index) const override; + + /** + * @fn virtual bool Array::IsInt(int &index) const override; + * + * @brief Checks if the value stored at the specific index is an Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if int, false if not. + */ + virtual bool IsInt(int &index) const override; + + /** + * @fn virtual int Array::GetInt(int &index) const override; + * + * @brief Returns the Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The int. + */ + virtual int GetInt(int &index) const override; + + /** + * @fn virtual void Array::AddInt(const int &value) override; + * + * @brief Adds the Integer value to the Array. + * + * @param value The value. + */ + virtual void AddInt(const int &value) override; + + /** + * @fn virtual bool Array::IsDouble(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a Double. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(int &index) const override; + + /** + * @fn virtual double Array::GetDouble(int &index) const override; + * + * @brief Returns the Double value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The double. + */ + virtual double GetDouble(int &index) const override; + + /** + * @fn virtual void Array::AddDouble(const double &value) override; + * + * @brief Adds the Double value to the Array. + * + * @param value The value. + */ + virtual void AddDouble(const double &value) override; + + /** + * @fn virtual bool Array::IsUInt(int &index) const override; + * + * @brief Checks if the value stored at the specific index is an Unsigned Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(int &index) const override; + + /** + * @fn virtual unsigned int Array::GetUInt(int &index) const override; + * + * @brief Returns the Unsigned Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The u int. + */ + virtual unsigned int GetUInt(int &index) const override; + + /** + * @fn virtual void Array::AddUInt(const unsigned int &value) override; + * + * @brief Adds the Unsigned Integer value the Array. + * + * @param value The value. + */ + virtual void AddUInt(const unsigned int &value) override; + + /** + * @fn virtual bool Array::IsInt64(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a 64bit Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(int &index) const override; + + /** + * @fn virtual Int64 Array::GetInt64(int &index) const override; + * + * @brief Returns the 64bit Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The int 64. + */ + virtual Int64 GetInt64(int &index) const override; + + /** + * @fn virtual void Array::AddInt64(const Int64 &value) override; + * + * @brief Adds the 64bit Integer value to the Array. + * + * @param value The value. + */ + virtual void AddInt64(const Int64 &value) override; + + /** + * @fn virtual bool Array::IsUInt64(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a 64bit Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(int &index) const override; + + /** + * @fn virtual UInt64 Array::GetUInt64(int &index) const override; + * + * @brief Returns the 64bit Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(int &index) const override; + + /** + * @fn virtual void Array::AddUInt64(const UInt64 &value) override; + * + * @brief Adds the 64bit Integer value to the Array. + * + * @param value The value. + */ + virtual void AddUInt64(const UInt64 &value) override; + + /** + * @fn virtual bool Array::IsFloat(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a float. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(int &index) const override; + + /** + * @fn virtual float Array::GetFloat(int &index) const override; + * + * @brief Returns the float value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The float. + */ + virtual float GetFloat(int &index) const override; + + /** + * @fn virtual void Array::AddFloat(const float &value) override; + * + * @brief Adds the float value to the Array. + * + * @param value The value. + */ + virtual void AddFloat(const float &value) override; + + /** + * @fn virtual bool Array::IsString(int &index) const override; + * + * @brief Checks if the value stored at the specific index is a String. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if string, false if not. + */ + virtual bool IsString(int &index) const override; + + /** + * @fn virtual const std::string Array::GetString(int &index) const override; + * + * @brief Returns the String value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The string. + */ + virtual const std::string GetString(int &index) const override; + + /** + * @fn virtual void Array::AddString(const std::string &value) override; + * + * @brief Adds the String to the Array. + * + * @param value The value. + */ + virtual void AddString(const std::string &value) override; + + /** + * @fn virtual bool Array::IsArray(int &index) const override; + * + * @brief Checks if the value stored at the specific index is an Array. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if array, false if not. + */ + virtual bool IsArray(int &index) const override; + + /** + * @fn virtual Array Array::GetArray(int &index) const override; + * + * @brief Returns the Array value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The array. + */ + virtual Array GetArray(int &index) const override; + + /** + * @fn virtual void Array::AddArray(Array &Array) override; + * + * @brief Adds the Array to the Array. + * + * @param [in,out] Array The array. + */ + virtual void AddArray(Array &Array) override; + + /** + * @fn virtual bool Array::IsObject(int &index) const override; + * + * @brief Checks if the value stored at the specific index is an Object. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if object, false if not. + */ + virtual bool IsObject(int &index) const override; + + /** + * @fn virtual Object Array::GetObject(int &index) const override; + * + * @brief Returns the Object value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The object. + */ + virtual Object GetObject(int &index) const override; + + /** + * @fn virtual void Array::AddObject(Object &Object) override; + * + * @brief Adds the Object to the Array. + * + * @param [in,out] Object The object. + */ + virtual void AddObject(Object &Object) override; + + private: + /** @brief The root. */ + Value mRoot = Value(ValueType::ArrayValue); + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/ArrayBase.h b/include/trUtil/JSON/ArrayBase.h index 35f9b67..b6585a3 100644 --- a/include/trUtil/JSON/ArrayBase.h +++ b/include/trUtil/JSON/ArrayBase.h @@ -1,450 +1,450 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include - -#include -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @class Object - * - * @brief Forward declaration. - */ - class Object; - - /** - * @class Array - * - * @brief An array. - */ - class Array; - - /** - * @class ArrayBase - * - * @brief An array base. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT ArrayBase : osg::Referenced - { - - public: - - /** - * @fn virtual void ArrayBase::Clear() = 0; - * - * @brief Clears the internal JSON Root node. - */ - virtual void Clear() = 0; - - /** - * @fn virtual Value& ArrayBase::GetJSONRoot() = 0; - * - * @brief Returns a reference to the internal JSON Root node. - * - * @return The JSON root. - */ - virtual Value& GetJSONRoot() = 0; - - /** - * @fn virtual void ArrayBase::PrintJSONRoot() = 0; - * - * @brief Prints out to the screen the whole JSON Root content. - */ - virtual void PrintJSONRoot() = 0; - - /** - * @fn virtual bool ArrayBase::IsNull(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a NULL. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if null, false if not. - */ - virtual bool IsNull(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddNull() = 0; - * - * @brief Add a NULL Value to the Array. - */ - virtual void AddNull() = 0; - - /** - * @fn virtual bool ArrayBase::IsBool(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a Boolean. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(int &index) const = 0; - - /** - * @fn virtual bool ArrayBase::GetBool(int &index) const = 0; - * - * @brief Returns the Boolean value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddBool(const bool &value) = 0; - * - * @brief Adds a Boolean to the Array. - * - * @param value The value. - */ - virtual void AddBool(const bool &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsTrue(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is True. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if true, false if not. - */ - virtual bool IsTrue(int &index) const = 0; - - /** - * @fn virtual bool ArrayBase::IsFalse(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is False. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if false, false if not. - */ - virtual bool IsFalse(int &index) const = 0; - - /** - * @fn virtual bool ArrayBase::IsNumber(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a Number. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(int &index) const = 0; - - /** - * @fn virtual bool ArrayBase::IsInt(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is an Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if int, false if not. - */ - virtual bool IsInt(int &index) const = 0; - - /** - * @fn virtual int ArrayBase::GetInt(int &index) const = 0; - * - * @brief Returns the Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The int. - */ - virtual int GetInt(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddInt(const int &value) = 0; - * - * @brief Adds the Integer value to the Array. - * - * @param value The value. - */ - virtual void AddInt(const int &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsDouble(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a Double. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(int &index) const = 0; - - /** - * @fn virtual double ArrayBase::GetDouble(int &index) const = 0; - * - * @brief Returns the Double value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The double. - */ - virtual double GetDouble(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddDouble(const double &value) = 0; - * - * @brief Adds the Double value to the Array. - * - * @param value The value. - */ - virtual void AddDouble(const double &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsUInt(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is an Unsigned Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(int &index) const = 0; - - /** - * @fn virtual unsigned int ArrayBase::GetUInt(int &index) const = 0; - * - * @brief Returns the Unsigned Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The u int. - */ - virtual unsigned int GetUInt(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddUInt(const unsigned int &value) = 0; - * - * @brief Adds the Unsigned Integer value the Array. - * - * @param value The value. - */ - virtual void AddUInt(const unsigned int &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsInt64(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a 64bit Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(int &index) const = 0; - - /** - * @fn virtual Int64 ArrayBase::GetInt64(int &index) const = 0; - * - * @brief Returns the 64bit Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The int 64. - */ - virtual Int64 GetInt64(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddInt64(const Int64 &value) = 0; - * - * @brief Adds the 64bit Integer value to the Array. - * - * @param value The value. - */ - virtual void AddInt64(const Int64 &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsUInt64(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a 64bit Integer. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(int &index) const = 0; - - /** - * @fn virtual UInt64 ArrayBase::GetUInt64(int &index) const = 0; - * - * @brief Returns the 64bit Integer value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddUInt64(const UInt64 &value) = 0; - * - * @brief Adds the 64bit Integer value to the Array. - * - * @param value The value. - */ - virtual void AddUInt64(const UInt64 &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsFloat(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a float. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(int &index) const = 0; - - /** - * @fn virtual float ArrayBase::GetFloat(int &index) const = 0; - * - * @brief Returns the float value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The float. - */ - virtual float GetFloat(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddFloat(const float &value) = 0; - * - * @brief Adds the float value to the Array. - * - * @param value The value. - */ - virtual void AddFloat(const float &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsString(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is a String. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if string, false if not. - */ - virtual bool IsString(int &index) const = 0; - - /** - * @fn virtual const std::string ArrayBase::GetString(int &index) const = 0; - * - * @brief Returns the String value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The string. - */ - virtual const std::string GetString(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddString(const std::string &value) = 0; - * - * @brief Adds the String to the Array. - * - * @param value The value. - */ - virtual void AddString(const std::string &value) = 0; - - /** - * @fn virtual bool ArrayBase::IsArray(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is an Array. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if array, false if not. - */ - virtual bool IsArray(int &index) const = 0; - - /** - * @fn virtual Array ArrayBase::GetArray(int &index) const = 0; - * - * @brief Returns the Array value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The array. - */ - virtual Array GetArray(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddArray(Array &Array) = 0; - * - * @brief Adds the Array to the Array. - * - * @param [in,out] Array The array. - */ - virtual void AddArray(Array &Array) = 0; - - /** - * @fn virtual bool ArrayBase::IsObject(int &index) const = 0; - * - * @brief Checks if the value stored at the specific index is an Object. - * - * @param [in,out] index Zero-based index of the. - * - * @return True if object, false if not. - */ - virtual bool IsObject(int &index) const = 0; - - /** - * @fn virtual Object ArrayBase::GetObject(int &index) const = 0; - * - * @brief Returns the Object value stored at the given index. - * - * @param [in,out] index Zero-based index of the. - * - * @return The object. - */ - virtual Object GetObject(int &index) const = 0; - - /** - * @fn virtual void ArrayBase::AddObject(Object &Object) = 0; - * - * @brief Adds the Object to the Array. - * - * @param [in,out] Object The object. - */ - virtual void AddObject(Object &Object) = 0; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include + +#include +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @class Object + * + * @brief Forward declaration. + */ + class Object; + + /** + * @class Array + * + * @brief An array. + */ + class Array; + + /** + * @class ArrayBase + * + * @brief An array base. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT ArrayBase : osg::Referenced + { + + public: + + /** + * @fn virtual void ArrayBase::Clear() = 0; + * + * @brief Clears the internal JSON Root node. + */ + virtual void Clear() = 0; + + /** + * @fn virtual Value& ArrayBase::GetJSONRoot() = 0; + * + * @brief Returns a reference to the internal JSON Root node. + * + * @return The JSON root. + */ + virtual Value& GetJSONRoot() = 0; + + /** + * @fn virtual void ArrayBase::PrintJSONRoot() = 0; + * + * @brief Prints out to the screen the whole JSON Root content. + */ + virtual void PrintJSONRoot() = 0; + + /** + * @fn virtual bool ArrayBase::IsNull(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a NULL. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if null, false if not. + */ + virtual bool IsNull(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddNull() = 0; + * + * @brief Add a NULL Value to the Array. + */ + virtual void AddNull() = 0; + + /** + * @fn virtual bool ArrayBase::IsBool(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a Boolean. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(int &index) const = 0; + + /** + * @fn virtual bool ArrayBase::GetBool(int &index) const = 0; + * + * @brief Returns the Boolean value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddBool(const bool &value) = 0; + * + * @brief Adds a Boolean to the Array. + * + * @param value The value. + */ + virtual void AddBool(const bool &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsTrue(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is True. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if true, false if not. + */ + virtual bool IsTrue(int &index) const = 0; + + /** + * @fn virtual bool ArrayBase::IsFalse(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is False. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if false, false if not. + */ + virtual bool IsFalse(int &index) const = 0; + + /** + * @fn virtual bool ArrayBase::IsNumber(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a Number. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(int &index) const = 0; + + /** + * @fn virtual bool ArrayBase::IsInt(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is an Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if int, false if not. + */ + virtual bool IsInt(int &index) const = 0; + + /** + * @fn virtual int ArrayBase::GetInt(int &index) const = 0; + * + * @brief Returns the Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The int. + */ + virtual int GetInt(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddInt(const int &value) = 0; + * + * @brief Adds the Integer value to the Array. + * + * @param value The value. + */ + virtual void AddInt(const int &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsDouble(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a Double. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(int &index) const = 0; + + /** + * @fn virtual double ArrayBase::GetDouble(int &index) const = 0; + * + * @brief Returns the Double value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The double. + */ + virtual double GetDouble(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddDouble(const double &value) = 0; + * + * @brief Adds the Double value to the Array. + * + * @param value The value. + */ + virtual void AddDouble(const double &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsUInt(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is an Unsigned Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(int &index) const = 0; + + /** + * @fn virtual unsigned int ArrayBase::GetUInt(int &index) const = 0; + * + * @brief Returns the Unsigned Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The u int. + */ + virtual unsigned int GetUInt(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddUInt(const unsigned int &value) = 0; + * + * @brief Adds the Unsigned Integer value the Array. + * + * @param value The value. + */ + virtual void AddUInt(const unsigned int &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsInt64(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a 64bit Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(int &index) const = 0; + + /** + * @fn virtual Int64 ArrayBase::GetInt64(int &index) const = 0; + * + * @brief Returns the 64bit Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The int 64. + */ + virtual Int64 GetInt64(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddInt64(const Int64 &value) = 0; + * + * @brief Adds the 64bit Integer value to the Array. + * + * @param value The value. + */ + virtual void AddInt64(const Int64 &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsUInt64(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a 64bit Integer. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(int &index) const = 0; + + /** + * @fn virtual UInt64 ArrayBase::GetUInt64(int &index) const = 0; + * + * @brief Returns the 64bit Integer value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddUInt64(const UInt64 &value) = 0; + * + * @brief Adds the 64bit Integer value to the Array. + * + * @param value The value. + */ + virtual void AddUInt64(const UInt64 &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsFloat(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a float. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(int &index) const = 0; + + /** + * @fn virtual float ArrayBase::GetFloat(int &index) const = 0; + * + * @brief Returns the float value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The float. + */ + virtual float GetFloat(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddFloat(const float &value) = 0; + * + * @brief Adds the float value to the Array. + * + * @param value The value. + */ + virtual void AddFloat(const float &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsString(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is a String. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if string, false if not. + */ + virtual bool IsString(int &index) const = 0; + + /** + * @fn virtual const std::string ArrayBase::GetString(int &index) const = 0; + * + * @brief Returns the String value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The string. + */ + virtual const std::string GetString(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddString(const std::string &value) = 0; + * + * @brief Adds the String to the Array. + * + * @param value The value. + */ + virtual void AddString(const std::string &value) = 0; + + /** + * @fn virtual bool ArrayBase::IsArray(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is an Array. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if array, false if not. + */ + virtual bool IsArray(int &index) const = 0; + + /** + * @fn virtual Array ArrayBase::GetArray(int &index) const = 0; + * + * @brief Returns the Array value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The array. + */ + virtual Array GetArray(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddArray(Array &Array) = 0; + * + * @brief Adds the Array to the Array. + * + * @param [in,out] Array The array. + */ + virtual void AddArray(Array &Array) = 0; + + /** + * @fn virtual bool ArrayBase::IsObject(int &index) const = 0; + * + * @brief Checks if the value stored at the specific index is an Object. + * + * @param [in,out] index Zero-based index of the. + * + * @return True if object, false if not. + */ + virtual bool IsObject(int &index) const = 0; + + /** + * @fn virtual Object ArrayBase::GetObject(int &index) const = 0; + * + * @brief Returns the Object value stored at the given index. + * + * @param [in,out] index Zero-based index of the. + * + * @return The object. + */ + virtual Object GetObject(int &index) const = 0; + + /** + * @fn virtual void ArrayBase::AddObject(Object &Object) = 0; + * + * @brief Adds the Object to the Array. + * + * @param [in,out] Object The object. + */ + virtual void AddObject(Object &Object) = 0; + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/Base.h b/include/trUtil/JSON/Base.h index 70abb47..4df9851 100644 --- a/include/trUtil/JSON/Base.h +++ b/include/trUtil/JSON/Base.h @@ -1,473 +1,473 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include - -#include - -#include -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @class Object - * - * @brief Forward declaration. - */ - class Object; - - /** - * @class Array - * - * @brief An array. - */ - class Array; - - /** - * @class Base - * - * @brief The Base class for all the JSON classes - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT Base : osg::Referenced - { - - public: - - /** - * @fn virtual void Base::Clear() = 0; - * - * @brief Clears the internal JSON Root node. - */ - virtual void Clear() = 0; - - /** - * @fn virtual Value& Base::GetJSONRoot() = 0; - * - * @brief Returns a reference to the internal JSON Root node. - * - * @return The JSON root. - */ - virtual Value& GetJSONRoot() = 0; - - /** - * @fn virtual void Base::PrintJSONRoot() = 0; - * - * @brief Prints out to the screen the whole JSON Root content. - */ - virtual void PrintJSONRoot() = 0; - - /** - * @fn virtual bool Base::KeyPresent(const std::string &key) const = 0; - * - * @brief Checks if the JSON Root Node has an entry with a given key present. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool KeyPresent(const std::string &key) const = 0; - - /** - * @fn virtual bool Base::IsNull(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a NULL. - * - * @param key The key. - * - * @return True if null, false if not. - */ - virtual bool IsNull(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetNull(const std::string &key) = 0; - * - * @brief Sets the value stored at the specific key to NULL. - * - * @param key The key. - */ - virtual void SetNull(const std::string &key) = 0; - - /** - * @fn virtual bool Base::IsBool(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a Boolean. - * - * @param key The key. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(const std::string &key) const = 0; - - /** - * @fn virtual bool Base::GetBool(const std::string &key) const = 0; - * - * @brief Returns the Boolean value stored at the given key. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetBool(const std::string &key, const bool &value) = 0; - * - * @brief Sets the Boolean value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetBool(const std::string &key, const bool &value) = 0; - - /** - * @fn virtual bool Base::IsTrue(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is True. - * - * @param key The key. - * - * @return True if true, false if not. - */ - virtual bool IsTrue(const std::string &key) const = 0; - - /** - * @fn virtual bool Base::IsFalse(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is False. - * - * @param key The key. - * - * @return True if false, false if not. - */ - virtual bool IsFalse(const std::string &key) const = 0; - - /** - * @fn virtual bool Base::IsNumber(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a Number. - * - * @param key The key. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(const std::string &key) const = 0; - - /** - * @fn virtual bool Base::IsInt(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is an Integer. - * - * @param key The key. - * - * @return True if int, false if not. - */ - virtual bool IsInt(const std::string &key) const = 0; - - /** - * @fn virtual int Base::GetInt(const std::string &key) const = 0; - * - * @brief Returns the Integer value stored at the given key. - * - * @param key The key. - * - * @return The int. - */ - virtual int GetInt(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetInt(const std::string &key, const int &value) = 0; - * - * @brief Sets the Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt(const std::string &key, const int &value) = 0; - - /** - * @fn virtual bool Base::IsDouble(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a Double. - * - * @param key The key. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(const std::string &key) const = 0; - - /** - * @fn virtual double Base::GetDouble(const std::string &key) const = 0; - * - * @brief Returns the Double value stored at the given key. - * - * @param key The key. - * - * @return The double. - */ - virtual double GetDouble(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetDouble(const std::string &key, const double &value) = 0; - * - * @brief Sets the Double value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetDouble(const std::string &key, const double &value) = 0; - - /** - * @fn virtual bool Base::IsUInt(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is an Unsigned Integer. - * - * @param key The key. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(const std::string &key) const = 0; - - /** - * @fn virtual unsigned int Base::GetUInt(const std::string &key) const = 0; - * - * @brief Returns the Unsigned Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int. - */ - virtual unsigned int GetUInt(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetUInt(const std::string &key, const unsigned int &value) = 0; - * - * @brief Sets the Unsigned Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt(const std::string &key, const unsigned int &value) = 0; - - /** - * @fn virtual bool Base::IsInt64(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(const std::string &key) const = 0; - - /** - * @fn virtual Int64 Base::GetInt64(const std::string &key) const = 0; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The int 64. - */ - virtual Int64 GetInt64(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetInt64(const std::string &key, const Int64 &value) = 0; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt64(const std::string &key, const Int64 &value) = 0; - - /** - * @fn virtual bool Base::IsUInt64(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(const std::string &key) const = 0; - - /** - * @fn virtual UInt64 Base::GetUInt64(const std::string &key) const = 0; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetUInt64(const std::string &key, const UInt64 &value) = 0; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt64(const std::string &key, const UInt64 &value) = 0; - - /** - * @fn virtual bool Base::IsFloat(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a float. - * - * @param key The key. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(const std::string &key) const = 0; - - /** - * @fn virtual float Base::GetFloat(const std::string &key) const = 0; - * - * @brief Returns the float value stored at the given key. - * - * @param key The key. - * - * @return The float. - */ - virtual float GetFloat(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetFloat(const std::string &key, const float &value) = 0; - * - * @brief Sets the float value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetFloat(const std::string &key, const float &value) = 0; - - /** - * @fn virtual bool Base::IsString(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is a String. - * - * @param key The key. - * - * @return True if string, false if not. - */ - virtual bool IsString(const std::string &key) const = 0; - - /** - * @fn virtual const std::string Base::GetString(const std::string &key) const = 0; - * - * @brief Returns the String value stored at the given key. - * - * @param key The key. - * - * @return The string. - */ - virtual const std::string GetString(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetString(const std::string &key, const std::string &value) = 0; - * - * @brief Sets the String to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetString(const std::string &key, const std::string &value) = 0; - - /** - * @fn virtual bool Base::IsArray(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is an Array. - * - * @param key The key. - * - * @return True if array, false if not. - */ - virtual bool IsArray(const std::string &key) const = 0; - - /** - * @fn virtual Array Base::GetArray(const std::string &key) const = 0; - * - * @brief Returns the Array value stored at the given key. - * - * @param key The key. - * - * @return The array. - */ - virtual Array GetArray(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetArray(const std::string &key, Array &Array) = 0; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] Array The array. - */ - virtual void SetArray(const std::string &key, Array &Array) = 0; - - /** - * @fn virtual bool Base::IsObject(const std::string &key) const = 0; - * - * @brief Checks if the value stored at the specific key is an Object. - * - * @param key The key. - * - * @return True if object, false if not. - */ - virtual bool IsObject(const std::string &key) const = 0; - - /** - * @fn virtual Object Base::GetObject(const std::string &key) const = 0; - * - * @brief Returns the Object value stored at the given key. - * - * @param key The key. - * - * @return The object. - */ - virtual Object GetObject(const std::string &key) const = 0; - - /** - * @fn virtual void Base::SetObject(const std::string &key, Object &Object) = 0; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] Object The object. - */ - virtual void SetObject(const std::string &key, Object &Object) = 0; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include + +#include + +#include +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @class Object + * + * @brief Forward declaration. + */ + class Object; + + /** + * @class Array + * + * @brief An array. + */ + class Array; + + /** + * @class Base + * + * @brief The Base class for all the JSON classes + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT Base : osg::Referenced + { + + public: + + /** + * @fn virtual void Base::Clear() = 0; + * + * @brief Clears the internal JSON Root node. + */ + virtual void Clear() = 0; + + /** + * @fn virtual Value& Base::GetJSONRoot() = 0; + * + * @brief Returns a reference to the internal JSON Root node. + * + * @return The JSON root. + */ + virtual Value& GetJSONRoot() = 0; + + /** + * @fn virtual void Base::PrintJSONRoot() = 0; + * + * @brief Prints out to the screen the whole JSON Root content. + */ + virtual void PrintJSONRoot() = 0; + + /** + * @fn virtual bool Base::KeyPresent(const std::string &key) const = 0; + * + * @brief Checks if the JSON Root Node has an entry with a given key present. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool KeyPresent(const std::string &key) const = 0; + + /** + * @fn virtual bool Base::IsNull(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a NULL. + * + * @param key The key. + * + * @return True if null, false if not. + */ + virtual bool IsNull(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetNull(const std::string &key) = 0; + * + * @brief Sets the value stored at the specific key to NULL. + * + * @param key The key. + */ + virtual void SetNull(const std::string &key) = 0; + + /** + * @fn virtual bool Base::IsBool(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a Boolean. + * + * @param key The key. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(const std::string &key) const = 0; + + /** + * @fn virtual bool Base::GetBool(const std::string &key) const = 0; + * + * @brief Returns the Boolean value stored at the given key. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetBool(const std::string &key, const bool &value) = 0; + * + * @brief Sets the Boolean value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetBool(const std::string &key, const bool &value) = 0; + + /** + * @fn virtual bool Base::IsTrue(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is True. + * + * @param key The key. + * + * @return True if true, false if not. + */ + virtual bool IsTrue(const std::string &key) const = 0; + + /** + * @fn virtual bool Base::IsFalse(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is False. + * + * @param key The key. + * + * @return True if false, false if not. + */ + virtual bool IsFalse(const std::string &key) const = 0; + + /** + * @fn virtual bool Base::IsNumber(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a Number. + * + * @param key The key. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(const std::string &key) const = 0; + + /** + * @fn virtual bool Base::IsInt(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is an Integer. + * + * @param key The key. + * + * @return True if int, false if not. + */ + virtual bool IsInt(const std::string &key) const = 0; + + /** + * @fn virtual int Base::GetInt(const std::string &key) const = 0; + * + * @brief Returns the Integer value stored at the given key. + * + * @param key The key. + * + * @return The int. + */ + virtual int GetInt(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetInt(const std::string &key, const int &value) = 0; + * + * @brief Sets the Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt(const std::string &key, const int &value) = 0; + + /** + * @fn virtual bool Base::IsDouble(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a Double. + * + * @param key The key. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(const std::string &key) const = 0; + + /** + * @fn virtual double Base::GetDouble(const std::string &key) const = 0; + * + * @brief Returns the Double value stored at the given key. + * + * @param key The key. + * + * @return The double. + */ + virtual double GetDouble(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetDouble(const std::string &key, const double &value) = 0; + * + * @brief Sets the Double value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetDouble(const std::string &key, const double &value) = 0; + + /** + * @fn virtual bool Base::IsUInt(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is an Unsigned Integer. + * + * @param key The key. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(const std::string &key) const = 0; + + /** + * @fn virtual unsigned int Base::GetUInt(const std::string &key) const = 0; + * + * @brief Returns the Unsigned Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int. + */ + virtual unsigned int GetUInt(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetUInt(const std::string &key, const unsigned int &value) = 0; + * + * @brief Sets the Unsigned Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt(const std::string &key, const unsigned int &value) = 0; + + /** + * @fn virtual bool Base::IsInt64(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(const std::string &key) const = 0; + + /** + * @fn virtual Int64 Base::GetInt64(const std::string &key) const = 0; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The int 64. + */ + virtual Int64 GetInt64(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetInt64(const std::string &key, const Int64 &value) = 0; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt64(const std::string &key, const Int64 &value) = 0; + + /** + * @fn virtual bool Base::IsUInt64(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(const std::string &key) const = 0; + + /** + * @fn virtual UInt64 Base::GetUInt64(const std::string &key) const = 0; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetUInt64(const std::string &key, const UInt64 &value) = 0; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt64(const std::string &key, const UInt64 &value) = 0; + + /** + * @fn virtual bool Base::IsFloat(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a float. + * + * @param key The key. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(const std::string &key) const = 0; + + /** + * @fn virtual float Base::GetFloat(const std::string &key) const = 0; + * + * @brief Returns the float value stored at the given key. + * + * @param key The key. + * + * @return The float. + */ + virtual float GetFloat(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetFloat(const std::string &key, const float &value) = 0; + * + * @brief Sets the float value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetFloat(const std::string &key, const float &value) = 0; + + /** + * @fn virtual bool Base::IsString(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is a String. + * + * @param key The key. + * + * @return True if string, false if not. + */ + virtual bool IsString(const std::string &key) const = 0; + + /** + * @fn virtual const std::string Base::GetString(const std::string &key) const = 0; + * + * @brief Returns the String value stored at the given key. + * + * @param key The key. + * + * @return The string. + */ + virtual const std::string GetString(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetString(const std::string &key, const std::string &value) = 0; + * + * @brief Sets the String to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetString(const std::string &key, const std::string &value) = 0; + + /** + * @fn virtual bool Base::IsArray(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is an Array. + * + * @param key The key. + * + * @return True if array, false if not. + */ + virtual bool IsArray(const std::string &key) const = 0; + + /** + * @fn virtual Array Base::GetArray(const std::string &key) const = 0; + * + * @brief Returns the Array value stored at the given key. + * + * @param key The key. + * + * @return The array. + */ + virtual Array GetArray(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetArray(const std::string &key, Array &Array) = 0; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] Array The array. + */ + virtual void SetArray(const std::string &key, Array &Array) = 0; + + /** + * @fn virtual bool Base::IsObject(const std::string &key) const = 0; + * + * @brief Checks if the value stored at the specific key is an Object. + * + * @param key The key. + * + * @return True if object, false if not. + */ + virtual bool IsObject(const std::string &key) const = 0; + + /** + * @fn virtual Object Base::GetObject(const std::string &key) const = 0; + * + * @brief Returns the Object value stored at the given key. + * + * @param key The key. + * + * @return The object. + */ + virtual Object GetObject(const std::string &key) const = 0; + + /** + * @fn virtual void Base::SetObject(const std::string &key, Object &Object) = 0; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] Object The object. + */ + virtual void SetObject(const std::string &key, Object &Object) = 0; + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/File.h b/include/trUtil/JSON/File.h index 54d14ab..cfe50fb 100644 --- a/include/trUtil/JSON/File.h +++ b/include/trUtil/JSON/File.h @@ -1,580 +1,580 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @class File - * - * @brief A file. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT File : Base - { - public: - - /** @brief The default JSON file name. */ - const static std::string DEFAULT_JSON_FILE_NAME; - - /** - * @fn File::File(); - * - * @brief ctor. - */ - File(); - - /** - * @fn File::File(std::string fileName); - * - * @brief Constructor that takes in the file name. The user still needs to Open the file for - * reading or writing. - * - * @param fileName Filename of the file. - */ - File(std::string fileName); - - /** - * @fn File::~File(); - * - * @brief dtor. - */ - ~File(); - - /** - * @fn virtual bool File::ReadFromFile(std::string fileName); - * - * @brief Reads from a file and parses the JSON into a Root node. - * - * @param fileName Filename of the file. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool ReadFromFile(std::string fileName); - - /** - * @fn virtual bool File::ReadFromFile(); - * - * @brief Reads from a file and parses the JSON into a Root Node. Uses an internally set - * filename to determine what to open. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool ReadFromFile(); - - /** - * @fn virtual bool File::WriteToFile(std::string fileName); - * - * @brief Writes the internal Root Node to a JSON file. - * - * @param fileName Filename of the file. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool WriteToFile(std::string fileName); - - /** - * @fn virtual bool File::WriteToFile(); - * - * @brief Writes the Root Node to a JSON file. Uses an internally set filename to determine - * what to create. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool WriteToFile(); - - /** - * @fn virtual void File::SetFileName(std::string fileName); - * - * @brief Sets a new file name. If a file has been opened already, this will close it. - * - * @param fileName Filename of the file. - */ - virtual void SetFileName(std::string fileName); - - /** - * @fn virtual std::string File::GetFileName() const; - * - * @brief Returns the name of the current file. - * - * @return The file name. - */ - virtual std::string GetFileName() const; - - /** - * @fn virtual void File::SetFilePath(std::string newPath); - * - * @brief Sets the path of where the file will be read from or written to. By default the it - * sill be saved in the PathUtils::GetUserDataPath() + PathUtils::CONFIG_PATH folder. - * - * @param newPath Full pathname of the new file. - */ - virtual void SetFilePath(std::string newPath); - - /** - * @fn virtual std::string File::GetFilePath() const; - * - * @brief Returns the path of where the file is read or written to. - * - * @return The file path. - */ - virtual std::string GetFilePath() const; - - /** - * @fn virtual bool File::FileExists(); - * - * @brief Returns true if the file name and path exist on the HD. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool FileExists(); - - /** - * @fn void File::Clear() override; - * - * @brief Clears the internal JSON Root node. - */ - void Clear() override; - - /** - * @fn virtual Value& File::GetJSONRoot() override; - * - * @brief Returns a reference to the internal JSON Root node. - * - * @return The JSON root. - */ - virtual Value& GetJSONRoot() override; - - /** - * @fn virtual void File::PrintJSONRoot() override; - * - * @brief Prints out to the screen the whole JSON Root content. - */ - virtual void PrintJSONRoot() override; - - /** - * @fn virtual bool File::KeyPresent(const std::string &key) const override; - * - * @brief Checks if the JSON Root Node has an entry with a given key present. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool KeyPresent(const std::string &key) const override; - - /** - * @fn virtual bool File::IsNull(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a NULL. - * - * @param key The key. - * - * @return True if null, false if not. - */ - virtual bool IsNull(const std::string &key) const override; - - /** - * @fn virtual void File::SetNull(const std::string &key) override; - * - * @brief Sets the value stored at the specific key to NULL. - * - * @param key The key. - */ - virtual void SetNull(const std::string &key) override; - - /** - * @fn virtual bool File::IsBool(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Boolean. - * - * @param key The key. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(const std::string &key) const override; - - /** - * @fn virtual bool File::GetBool(const std::string &key) const override; - * - * @brief Returns the Boolean value stored at the given key. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(const std::string &key) const override; - - /** - * @fn virtual void File::SetBool(const std::string &key, const bool &value) override; - * - * @brief Sets the Boolean value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetBool(const std::string &key, const bool &value) override; - - /** - * @fn virtual bool File::IsTrue(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is True. - * - * @param key The key. - * - * @return True if true, false if not. - */ - virtual bool IsTrue(const std::string &key) const override; - - /** - * @fn virtual bool File::IsFalse(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is False. - * - * @param key The key. - * - * @return True if false, false if not. - */ - virtual bool IsFalse(const std::string &key) const override; - - /** - * @fn virtual bool File::IsNumber(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Number. - * - * @param key The key. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(const std::string &key) const override; - - /** - * @fn virtual bool File::IsInt(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Integer. - * - * @param key The key. - * - * @return True if int, false if not. - */ - virtual bool IsInt(const std::string &key) const override; - - /** - * @fn virtual int File::GetInt(const std::string &key) const override; - * - * @brief Returns the Integer value stored at the given key. - * - * @param key The key. - * - * @return The int. - */ - virtual int GetInt(const std::string &key) const override; - - /** - * @fn virtual void File::SetInt(const std::string &key, const int &value) override; - * - * @brief Sets the Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt(const std::string &key, const int &value) override; - - /** - * @fn virtual bool File::IsDouble(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Double. - * - * @param key The key. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(const std::string &key) const override; - - /** - * @fn virtual double File::GetDouble(const std::string &key) const override; - * - * @brief Returns the Double value stored at the given key. - * - * @param key The key. - * - * @return The double. - */ - virtual double GetDouble(const std::string &key) const override; - - /** - * @fn virtual void File::SetDouble(const std::string &key, const double &value) override; - * - * @brief Sets the Double value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetDouble(const std::string &key, const double &value) override; - - /** - * @fn virtual bool File::IsUInt(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Unsigned Integer. - * - * @param key The key. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(const std::string &key) const override; - - /** - * @fn virtual unsigned int File::GetUInt(const std::string &key) const override; - * - * @brief Returns the Unsigned Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int. - */ - virtual unsigned int GetUInt(const std::string &key) const override; - - /** - * @fn virtual void File::SetUInt(const std::string &key, const unsigned int &value) override; - * - * @brief Sets the Unsigned Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt(const std::string &key, const unsigned int &value) override; - - /** - * @fn virtual bool File::IsInt64(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(const std::string &key) const override; - - /** - * @fn virtual Int64 File::GetInt64(const std::string &key) const override; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The int 64. - */ - virtual Int64 GetInt64(const std::string &key) const override; - - /** - * @fn virtual void File::SetInt64(const std::string &key, const Int64 &value) override; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt64(const std::string &key, const Int64 &value) override; - - /** - * @fn virtual bool File::IsUInt64(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(const std::string &key) const override; - - /** - * @fn virtual UInt64 File::GetUInt64(const std::string &key) const override; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(const std::string &key) const override; - - /** - * @fn virtual void File::SetUInt64(const std::string &key, const UInt64 &value) override; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt64(const std::string &key, const UInt64 &value) override; - - /** - * @fn virtual bool File::IsFloat(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a float. - * - * @param key The key. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(const std::string &key) const override; - - /** - * @fn virtual float File::GetFloat(const std::string &key) const override; - * - * @brief Returns the float value stored at the given key. - * - * @param key The key. - * - * @return The float. - */ - virtual float GetFloat(const std::string &key) const override; - - /** - * @fn virtual void File::SetFloat(const std::string &key, const float &value) override; - * - * @brief Sets the float value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetFloat(const std::string &key, const float &value) override; - - /** - * @fn virtual bool File::IsString(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a String. - * - * @param key The key. - * - * @return True if string, false if not. - */ - virtual bool IsString(const std::string &key) const override; - - /** - * @fn virtual const std::string File::GetString(const std::string &key) const override; - * - * @brief Returns the String value stored at the given key. - * - * @param key The key. - * - * @return The string. - */ - virtual const std::string GetString(const std::string &key) const override; - - /** - * @fn virtual void File::SetString(const std::string &key, const std::string &value) override; - * - * @brief Sets the String to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetString(const std::string &key, const std::string &value) override; - - /** - * @fn virtual bool File::IsArray(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Array. - * - * @param key The key. - * - * @return True if array, false if not. - */ - virtual bool IsArray(const std::string &key) const override; - - /** - * @fn virtual Array File::GetArray(const std::string &key) const override; - * - * @brief Returns the Array value stored at the given key. - * - * @param key The key. - * - * @return The array. - */ - virtual Array GetArray(const std::string &key) const override; - - /** - * @fn virtual void File::SetArray(const std::string &key, Array &value) override; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetArray(const std::string &key, Array &value) override; - - /** - * @fn virtual bool File::IsObject(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Object. - * - * @param key The key. - * - * @return True if object, false if not. - */ - virtual bool IsObject(const std::string &key) const override; - - /** - * @fn virtual Object File::GetObject(const std::string &key) const override; - * - * @brief Returns the Object value stored at the given key. - * - * @param key The key. - * - * @return The object. - */ - virtual Object GetObject(const std::string &key) const override; - - /** - * @fn virtual void File::SetObject(const std::string &key, Object &value) override; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetObject(const std::string &key, Object &value) override; - - private: - /** @brief Filename of the file. */ - std::string mFileName; - /** @brief Full pathname of the file. */ - std::string mFilePath; - - /** @brief The root. */ - Value mRoot; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @class File + * + * @brief A file. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT File : Base + { + public: + + /** @brief The default JSON file name. */ + const static std::string DEFAULT_JSON_FILE_NAME; + + /** + * @fn File::File(); + * + * @brief ctor. + */ + File(); + + /** + * @fn File::File(std::string fileName); + * + * @brief Constructor that takes in the file name. The user still needs to Open the file for + * reading or writing. + * + * @param fileName Filename of the file. + */ + File(std::string fileName); + + /** + * @fn File::~File(); + * + * @brief dtor. + */ + ~File(); + + /** + * @fn virtual bool File::ReadFromFile(std::string fileName); + * + * @brief Reads from a file and parses the JSON into a Root node. + * + * @param fileName Filename of the file. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool ReadFromFile(std::string fileName); + + /** + * @fn virtual bool File::ReadFromFile(); + * + * @brief Reads from a file and parses the JSON into a Root Node. Uses an internally set + * filename to determine what to open. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool ReadFromFile(); + + /** + * @fn virtual bool File::WriteToFile(std::string fileName); + * + * @brief Writes the internal Root Node to a JSON file. + * + * @param fileName Filename of the file. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool WriteToFile(std::string fileName); + + /** + * @fn virtual bool File::WriteToFile(); + * + * @brief Writes the Root Node to a JSON file. Uses an internally set filename to determine + * what to create. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool WriteToFile(); + + /** + * @fn virtual void File::SetFileName(std::string fileName); + * + * @brief Sets a new file name. If a file has been opened already, this will close it. + * + * @param fileName Filename of the file. + */ + virtual void SetFileName(std::string fileName); + + /** + * @fn virtual std::string File::GetFileName() const; + * + * @brief Returns the name of the current file. + * + * @return The file name. + */ + virtual std::string GetFileName() const; + + /** + * @fn virtual void File::SetFilePath(std::string newPath); + * + * @brief Sets the path of where the file will be read from or written to. By default the it + * sill be saved in the PathUtils::GetUserDataPath() + PathUtils::CONFIG_PATH folder. + * + * @param newPath Full pathname of the new file. + */ + virtual void SetFilePath(std::string newPath); + + /** + * @fn virtual std::string File::GetFilePath() const; + * + * @brief Returns the path of where the file is read or written to. + * + * @return The file path. + */ + virtual std::string GetFilePath() const; + + /** + * @fn virtual bool File::FileExists(); + * + * @brief Returns true if the file name and path exist on the HD. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool FileExists(); + + /** + * @fn void File::Clear() override; + * + * @brief Clears the internal JSON Root node. + */ + void Clear() override; + + /** + * @fn virtual Value& File::GetJSONRoot() override; + * + * @brief Returns a reference to the internal JSON Root node. + * + * @return The JSON root. + */ + virtual Value& GetJSONRoot() override; + + /** + * @fn virtual void File::PrintJSONRoot() override; + * + * @brief Prints out to the screen the whole JSON Root content. + */ + virtual void PrintJSONRoot() override; + + /** + * @fn virtual bool File::KeyPresent(const std::string &key) const override; + * + * @brief Checks if the JSON Root Node has an entry with a given key present. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool KeyPresent(const std::string &key) const override; + + /** + * @fn virtual bool File::IsNull(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a NULL. + * + * @param key The key. + * + * @return True if null, false if not. + */ + virtual bool IsNull(const std::string &key) const override; + + /** + * @fn virtual void File::SetNull(const std::string &key) override; + * + * @brief Sets the value stored at the specific key to NULL. + * + * @param key The key. + */ + virtual void SetNull(const std::string &key) override; + + /** + * @fn virtual bool File::IsBool(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Boolean. + * + * @param key The key. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(const std::string &key) const override; + + /** + * @fn virtual bool File::GetBool(const std::string &key) const override; + * + * @brief Returns the Boolean value stored at the given key. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(const std::string &key) const override; + + /** + * @fn virtual void File::SetBool(const std::string &key, const bool &value) override; + * + * @brief Sets the Boolean value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetBool(const std::string &key, const bool &value) override; + + /** + * @fn virtual bool File::IsTrue(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is True. + * + * @param key The key. + * + * @return True if true, false if not. + */ + virtual bool IsTrue(const std::string &key) const override; + + /** + * @fn virtual bool File::IsFalse(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is False. + * + * @param key The key. + * + * @return True if false, false if not. + */ + virtual bool IsFalse(const std::string &key) const override; + + /** + * @fn virtual bool File::IsNumber(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Number. + * + * @param key The key. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(const std::string &key) const override; + + /** + * @fn virtual bool File::IsInt(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Integer. + * + * @param key The key. + * + * @return True if int, false if not. + */ + virtual bool IsInt(const std::string &key) const override; + + /** + * @fn virtual int File::GetInt(const std::string &key) const override; + * + * @brief Returns the Integer value stored at the given key. + * + * @param key The key. + * + * @return The int. + */ + virtual int GetInt(const std::string &key) const override; + + /** + * @fn virtual void File::SetInt(const std::string &key, const int &value) override; + * + * @brief Sets the Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt(const std::string &key, const int &value) override; + + /** + * @fn virtual bool File::IsDouble(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Double. + * + * @param key The key. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(const std::string &key) const override; + + /** + * @fn virtual double File::GetDouble(const std::string &key) const override; + * + * @brief Returns the Double value stored at the given key. + * + * @param key The key. + * + * @return The double. + */ + virtual double GetDouble(const std::string &key) const override; + + /** + * @fn virtual void File::SetDouble(const std::string &key, const double &value) override; + * + * @brief Sets the Double value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetDouble(const std::string &key, const double &value) override; + + /** + * @fn virtual bool File::IsUInt(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Unsigned Integer. + * + * @param key The key. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(const std::string &key) const override; + + /** + * @fn virtual unsigned int File::GetUInt(const std::string &key) const override; + * + * @brief Returns the Unsigned Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int. + */ + virtual unsigned int GetUInt(const std::string &key) const override; + + /** + * @fn virtual void File::SetUInt(const std::string &key, const unsigned int &value) override; + * + * @brief Sets the Unsigned Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt(const std::string &key, const unsigned int &value) override; + + /** + * @fn virtual bool File::IsInt64(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(const std::string &key) const override; + + /** + * @fn virtual Int64 File::GetInt64(const std::string &key) const override; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The int 64. + */ + virtual Int64 GetInt64(const std::string &key) const override; + + /** + * @fn virtual void File::SetInt64(const std::string &key, const Int64 &value) override; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt64(const std::string &key, const Int64 &value) override; + + /** + * @fn virtual bool File::IsUInt64(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(const std::string &key) const override; + + /** + * @fn virtual UInt64 File::GetUInt64(const std::string &key) const override; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(const std::string &key) const override; + + /** + * @fn virtual void File::SetUInt64(const std::string &key, const UInt64 &value) override; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt64(const std::string &key, const UInt64 &value) override; + + /** + * @fn virtual bool File::IsFloat(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a float. + * + * @param key The key. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(const std::string &key) const override; + + /** + * @fn virtual float File::GetFloat(const std::string &key) const override; + * + * @brief Returns the float value stored at the given key. + * + * @param key The key. + * + * @return The float. + */ + virtual float GetFloat(const std::string &key) const override; + + /** + * @fn virtual void File::SetFloat(const std::string &key, const float &value) override; + * + * @brief Sets the float value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetFloat(const std::string &key, const float &value) override; + + /** + * @fn virtual bool File::IsString(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a String. + * + * @param key The key. + * + * @return True if string, false if not. + */ + virtual bool IsString(const std::string &key) const override; + + /** + * @fn virtual const std::string File::GetString(const std::string &key) const override; + * + * @brief Returns the String value stored at the given key. + * + * @param key The key. + * + * @return The string. + */ + virtual const std::string GetString(const std::string &key) const override; + + /** + * @fn virtual void File::SetString(const std::string &key, const std::string &value) override; + * + * @brief Sets the String to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetString(const std::string &key, const std::string &value) override; + + /** + * @fn virtual bool File::IsArray(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Array. + * + * @param key The key. + * + * @return True if array, false if not. + */ + virtual bool IsArray(const std::string &key) const override; + + /** + * @fn virtual Array File::GetArray(const std::string &key) const override; + * + * @brief Returns the Array value stored at the given key. + * + * @param key The key. + * + * @return The array. + */ + virtual Array GetArray(const std::string &key) const override; + + /** + * @fn virtual void File::SetArray(const std::string &key, Array &value) override; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetArray(const std::string &key, Array &value) override; + + /** + * @fn virtual bool File::IsObject(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Object. + * + * @param key The key. + * + * @return True if object, false if not. + */ + virtual bool IsObject(const std::string &key) const override; + + /** + * @fn virtual Object File::GetObject(const std::string &key) const override; + * + * @brief Returns the Object value stored at the given key. + * + * @param key The key. + * + * @return The object. + */ + virtual Object GetObject(const std::string &key) const override; + + /** + * @fn virtual void File::SetObject(const std::string &key, Object &value) override; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetObject(const std::string &key, Object &value) override; + + private: + /** @brief Filename of the file. */ + std::string mFileName; + /** @brief Full pathname of the file. */ + std::string mFilePath; + + /** @brief The root. */ + Value mRoot; + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/Object.h b/include/trUtil/JSON/Object.h index d23a86b..b8267cf 100644 --- a/include/trUtil/JSON/Object.h +++ b/include/trUtil/JSON/Object.h @@ -1,524 +1,524 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - - -#include - -#include -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @class Object - * - * @brief A JSON object that is used to store - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT Object : Base - { - public: - - /** - * @fn Object::Object(); - * - * @brief ctor. - */ - Object(); - - /** - * @fn Object::Object(const Value &Object); - * - * @brief ctor that takes a JSON Value of Object type as input. - * - * @param Object The object. - */ - Object(const Value &Object); - - /** - * @fn Object::~Object(); - * - * @brief dtor. - */ - ~Object(); - - /** - * @fn const Value::Members Object::GetMemberNames() const; - * - * @brief Returns the value names contained in the object. - * - * @return The member names. - */ - const Value::Members GetMemberNames() const; - - /* - * Adds a comment to the internal value - */ - - /** - * @fn void Object::SetComment(const std::string& comment); - * - * @brief Sets a comment. - * - * @param comment The comment. - */ - void SetComment(const std::string& comment); - - /** - * @fn bool Object::HasComment() const; - * - * @brief Checks if the internal value has a comment. - * - * @return True if comment, false if not. - */ - bool HasComment() const; - - /** - * @fn std::string Object::GetComment() const; - * - * @brief Returns the internal comment. - * - * @return The comment. - */ - std::string GetComment() const; - - /** - * @fn void Object::Clear() override; - * - * @brief Clears the internal JSON Root node. - */ - void Clear() override; - - /** - * @fn virtual Value& Object::GetJSONRoot() override; - * - * @brief Returns a reference to the internal JSON Root node. - * - * @return The JSON root. - */ - virtual Value& GetJSONRoot() override; - - /** - * @fn virtual void Object::PrintJSONRoot() override; - * - * @brief Prints out to the screen the whole JSON Root content. - */ - virtual void PrintJSONRoot() override; - - /** - * @fn virtual bool Object::KeyPresent(const std::string &key) const override; - * - * @brief Checks if the JSON Root Node has an entry with a given key present. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool KeyPresent(const std::string &key) const override; - - /** - * @fn virtual bool Object::IsNull(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a NULL. - * - * @param key The key. - * - * @return True if null, false if not. - */ - virtual bool IsNull(const std::string &key) const override; - - /** - * @fn virtual void Object::SetNull(const std::string &key) override; - * - * @brief Sets the value stored at the specific key to NULL. - * - * @param key The key. - */ - virtual void SetNull(const std::string &key) override; - - /** - * @fn virtual bool Object::IsBool(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Boolean. - * - * @param key The key. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(const std::string &key) const override; - - /** - * @fn virtual bool Object::GetBool(const std::string &key) const override; - * - * @brief Returns the Boolean value stored at the given key. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(const std::string &key) const override; - - /** - * @fn virtual void Object::SetBool(const std::string &key, const bool &value) override; - * - * @brief Sets the Boolean value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetBool(const std::string &key, const bool &value) override; - - /** - * @fn virtual bool Object::IsTrue(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is True. - * - * @param key The key. - * - * @return True if true, false if not. - */ - virtual bool IsTrue(const std::string &key) const override; - - /** - * @fn virtual bool Object::IsFalse(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is False. - * - * @param key The key. - * - * @return True if false, false if not. - */ - virtual bool IsFalse(const std::string &key) const override; - - /** - * @fn virtual bool Object::IsNumber(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Number. - * - * @param key The key. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(const std::string &key) const override; - - /** - * @fn virtual bool Object::IsInt(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Integer. - * - * @param key The key. - * - * @return True if int, false if not. - */ - virtual bool IsInt(const std::string &key) const override; - - /** - * @fn virtual int Object::GetInt(const std::string &key) const override; - * - * @brief Returns the Integer value stored at the given key. - * - * @param key The key. - * - * @return The int. - */ - virtual int GetInt(const std::string &key) const override; - - /** - * @fn virtual void Object::SetInt(const std::string &key, const int &value) override; - * - * @brief Sets the Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt(const std::string &key, const int &value) override; - - /** - * @fn virtual bool Object::IsDouble(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a Double. - * - * @param key The key. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(const std::string &key) const override; - - /** - * @fn virtual double Object::GetDouble(const std::string &key) const override; - * - * @brief Returns the Double value stored at the given key. - * - * @param key The key. - * - * @return The double. - */ - virtual double GetDouble(const std::string &key) const override; - - /** - * @fn virtual void Object::SetDouble(const std::string &key, const double &value) override; - * - * @brief Sets the Double value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetDouble(const std::string &key, const double &value) override; - - /** - * @fn virtual bool Object::IsUInt(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Unsigned Integer. - * - * @param key The key. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(const std::string &key) const override; - - /** - * @fn virtual unsigned int Object::GetUInt(const std::string &key) const override; - * - * @brief Returns the Unsigned Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int. - */ - virtual unsigned int GetUInt(const std::string &key) const override; - - /** - * @fn virtual void Object::SetUInt(const std::string &key, const unsigned int &value) override; - * - * @brief Sets the Unsigned Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt(const std::string &key, const unsigned int &value) override; - - /** - * @fn virtual bool Object::IsInt64(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(const std::string &key) const override; - - /** - * @fn virtual Int64 Object::GetInt64(const std::string &key) const override; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The int 64. - */ - virtual Int64 GetInt64(const std::string &key) const override; - - /** - * @fn virtual void Object::SetInt64(const std::string &key, const Int64 &value) override; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt64(const std::string &key, const Int64 &value) override; - - /** - * @fn virtual bool Object::IsUInt64(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a 64bit Integer. - * - * @param key The key. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(const std::string &key) const override; - - /** - * @fn virtual UInt64 Object::GetUInt64(const std::string &key) const override; - * - * @brief Returns the 64bit Integer value stored at the given key. - * - * @param key The key. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(const std::string &key) const override; - - /** - * @fn virtual void Object::SetUInt64(const std::string &key, const UInt64 &value) override; - * - * @brief Sets the 64bit Integer value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt64(const std::string &key, const UInt64 &value) override; - - /** - * @fn virtual bool Object::IsFloat(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a float. - * - * @param key The key. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(const std::string &key) const override; - - /** - * @fn virtual float Object::GetFloat(const std::string &key) const override; - * - * @brief Returns the float value stored at the given key. - * - * @param key The key. - * - * @return The float. - */ - virtual float GetFloat(const std::string &key) const override; - - /** - * @fn virtual void Object::SetFloat(const std::string &key, const float &value) override; - * - * @brief Sets the float value to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetFloat(const std::string &key, const float &value) override; - - /** - * @fn virtual bool Object::IsString(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is a String. - * - * @param key The key. - * - * @return True if string, false if not. - */ - virtual bool IsString(const std::string &key) const override; - - /** - * @fn virtual const std::string Object::GetString(const std::string &key) const override; - * - * @brief Returns the String value stored at the given key. - * - * @param key The key. - * - * @return The string. - */ - virtual const std::string GetString(const std::string &key) const override; - - /** - * @fn virtual void Object::SetString(const std::string &key, const std::string &value) override; - * - * @brief Sets the String to be stored at the given key. - * - * @param key The key. - * @param value The value. - */ - virtual void SetString(const std::string &key, const std::string &value) override; - - /** - * @fn virtual bool Object::IsArray(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Array. - * - * @param key The key. - * - * @return True if array, false if not. - */ - virtual bool IsArray(const std::string &key) const override; - - /** - * @fn virtual Array Object::GetArray(const std::string &key) const override; - * - * @brief Returns the Array value stored at the given key. - * - * @param key The key. - * - * @return The array. - */ - virtual Array GetArray(const std::string &key) const override; - - /** - * @fn virtual void Object::SetArray(const std::string &key, Array &value) override; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetArray(const std::string &key, Array &value) override; - - /** - * @fn virtual bool Object::IsObject(const std::string &key) const override; - * - * @brief Checks if the value stored at the specific key is an Object. - * - * @param key The key. - * - * @return True if object, false if not. - */ - virtual bool IsObject(const std::string &key) const override; - - /** - * @fn virtual Object Object::GetObject(const std::string &key) const override; - * - * @brief Returns the Object value stored at the given key. - * - * @param key The key. - * - * @return The object. - */ - virtual Object GetObject(const std::string &key) const override; - - /** - * @fn virtual void Object::SetObject(const std::string &key, Object &value) override; - * - * @brief Sets the Array to be stored at the given key. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetObject(const std::string &key, Object &value) override; - - private: - /** @brief The root. */ - Value mRoot = Value(ValueType::ObjectValue); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + + +#include + +#include +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @class Object + * + * @brief A JSON object that is used to store + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT Object : Base + { + public: + + /** + * @fn Object::Object(); + * + * @brief ctor. + */ + Object(); + + /** + * @fn Object::Object(const Value &Object); + * + * @brief ctor that takes a JSON Value of Object type as input. + * + * @param Object The object. + */ + Object(const Value &Object); + + /** + * @fn Object::~Object(); + * + * @brief dtor. + */ + ~Object(); + + /** + * @fn const Value::Members Object::GetMemberNames() const; + * + * @brief Returns the value names contained in the object. + * + * @return The member names. + */ + const Value::Members GetMemberNames() const; + + /* + * Adds a comment to the internal value + */ + + /** + * @fn void Object::SetComment(const std::string& comment); + * + * @brief Sets a comment. + * + * @param comment The comment. + */ + void SetComment(const std::string& comment); + + /** + * @fn bool Object::HasComment() const; + * + * @brief Checks if the internal value has a comment. + * + * @return True if comment, false if not. + */ + bool HasComment() const; + + /** + * @fn std::string Object::GetComment() const; + * + * @brief Returns the internal comment. + * + * @return The comment. + */ + std::string GetComment() const; + + /** + * @fn void Object::Clear() override; + * + * @brief Clears the internal JSON Root node. + */ + void Clear() override; + + /** + * @fn virtual Value& Object::GetJSONRoot() override; + * + * @brief Returns a reference to the internal JSON Root node. + * + * @return The JSON root. + */ + virtual Value& GetJSONRoot() override; + + /** + * @fn virtual void Object::PrintJSONRoot() override; + * + * @brief Prints out to the screen the whole JSON Root content. + */ + virtual void PrintJSONRoot() override; + + /** + * @fn virtual bool Object::KeyPresent(const std::string &key) const override; + * + * @brief Checks if the JSON Root Node has an entry with a given key present. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool KeyPresent(const std::string &key) const override; + + /** + * @fn virtual bool Object::IsNull(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a NULL. + * + * @param key The key. + * + * @return True if null, false if not. + */ + virtual bool IsNull(const std::string &key) const override; + + /** + * @fn virtual void Object::SetNull(const std::string &key) override; + * + * @brief Sets the value stored at the specific key to NULL. + * + * @param key The key. + */ + virtual void SetNull(const std::string &key) override; + + /** + * @fn virtual bool Object::IsBool(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Boolean. + * + * @param key The key. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(const std::string &key) const override; + + /** + * @fn virtual bool Object::GetBool(const std::string &key) const override; + * + * @brief Returns the Boolean value stored at the given key. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(const std::string &key) const override; + + /** + * @fn virtual void Object::SetBool(const std::string &key, const bool &value) override; + * + * @brief Sets the Boolean value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetBool(const std::string &key, const bool &value) override; + + /** + * @fn virtual bool Object::IsTrue(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is True. + * + * @param key The key. + * + * @return True if true, false if not. + */ + virtual bool IsTrue(const std::string &key) const override; + + /** + * @fn virtual bool Object::IsFalse(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is False. + * + * @param key The key. + * + * @return True if false, false if not. + */ + virtual bool IsFalse(const std::string &key) const override; + + /** + * @fn virtual bool Object::IsNumber(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Number. + * + * @param key The key. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(const std::string &key) const override; + + /** + * @fn virtual bool Object::IsInt(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Integer. + * + * @param key The key. + * + * @return True if int, false if not. + */ + virtual bool IsInt(const std::string &key) const override; + + /** + * @fn virtual int Object::GetInt(const std::string &key) const override; + * + * @brief Returns the Integer value stored at the given key. + * + * @param key The key. + * + * @return The int. + */ + virtual int GetInt(const std::string &key) const override; + + /** + * @fn virtual void Object::SetInt(const std::string &key, const int &value) override; + * + * @brief Sets the Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt(const std::string &key, const int &value) override; + + /** + * @fn virtual bool Object::IsDouble(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a Double. + * + * @param key The key. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(const std::string &key) const override; + + /** + * @fn virtual double Object::GetDouble(const std::string &key) const override; + * + * @brief Returns the Double value stored at the given key. + * + * @param key The key. + * + * @return The double. + */ + virtual double GetDouble(const std::string &key) const override; + + /** + * @fn virtual void Object::SetDouble(const std::string &key, const double &value) override; + * + * @brief Sets the Double value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetDouble(const std::string &key, const double &value) override; + + /** + * @fn virtual bool Object::IsUInt(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Unsigned Integer. + * + * @param key The key. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(const std::string &key) const override; + + /** + * @fn virtual unsigned int Object::GetUInt(const std::string &key) const override; + * + * @brief Returns the Unsigned Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int. + */ + virtual unsigned int GetUInt(const std::string &key) const override; + + /** + * @fn virtual void Object::SetUInt(const std::string &key, const unsigned int &value) override; + * + * @brief Sets the Unsigned Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt(const std::string &key, const unsigned int &value) override; + + /** + * @fn virtual bool Object::IsInt64(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(const std::string &key) const override; + + /** + * @fn virtual Int64 Object::GetInt64(const std::string &key) const override; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The int 64. + */ + virtual Int64 GetInt64(const std::string &key) const override; + + /** + * @fn virtual void Object::SetInt64(const std::string &key, const Int64 &value) override; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt64(const std::string &key, const Int64 &value) override; + + /** + * @fn virtual bool Object::IsUInt64(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a 64bit Integer. + * + * @param key The key. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(const std::string &key) const override; + + /** + * @fn virtual UInt64 Object::GetUInt64(const std::string &key) const override; + * + * @brief Returns the 64bit Integer value stored at the given key. + * + * @param key The key. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(const std::string &key) const override; + + /** + * @fn virtual void Object::SetUInt64(const std::string &key, const UInt64 &value) override; + * + * @brief Sets the 64bit Integer value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt64(const std::string &key, const UInt64 &value) override; + + /** + * @fn virtual bool Object::IsFloat(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a float. + * + * @param key The key. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(const std::string &key) const override; + + /** + * @fn virtual float Object::GetFloat(const std::string &key) const override; + * + * @brief Returns the float value stored at the given key. + * + * @param key The key. + * + * @return The float. + */ + virtual float GetFloat(const std::string &key) const override; + + /** + * @fn virtual void Object::SetFloat(const std::string &key, const float &value) override; + * + * @brief Sets the float value to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetFloat(const std::string &key, const float &value) override; + + /** + * @fn virtual bool Object::IsString(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is a String. + * + * @param key The key. + * + * @return True if string, false if not. + */ + virtual bool IsString(const std::string &key) const override; + + /** + * @fn virtual const std::string Object::GetString(const std::string &key) const override; + * + * @brief Returns the String value stored at the given key. + * + * @param key The key. + * + * @return The string. + */ + virtual const std::string GetString(const std::string &key) const override; + + /** + * @fn virtual void Object::SetString(const std::string &key, const std::string &value) override; + * + * @brief Sets the String to be stored at the given key. + * + * @param key The key. + * @param value The value. + */ + virtual void SetString(const std::string &key, const std::string &value) override; + + /** + * @fn virtual bool Object::IsArray(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Array. + * + * @param key The key. + * + * @return True if array, false if not. + */ + virtual bool IsArray(const std::string &key) const override; + + /** + * @fn virtual Array Object::GetArray(const std::string &key) const override; + * + * @brief Returns the Array value stored at the given key. + * + * @param key The key. + * + * @return The array. + */ + virtual Array GetArray(const std::string &key) const override; + + /** + * @fn virtual void Object::SetArray(const std::string &key, Array &value) override; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetArray(const std::string &key, Array &value) override; + + /** + * @fn virtual bool Object::IsObject(const std::string &key) const override; + * + * @brief Checks if the value stored at the specific key is an Object. + * + * @param key The key. + * + * @return True if object, false if not. + */ + virtual bool IsObject(const std::string &key) const override; + + /** + * @fn virtual Object Object::GetObject(const std::string &key) const override; + * + * @brief Returns the Object value stored at the given key. + * + * @param key The key. + * + * @return The object. + */ + virtual Object GetObject(const std::string &key) const override; + + /** + * @fn virtual void Object::SetObject(const std::string &key, Object &value) override; + * + * @brief Sets the Array to be stored at the given key. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetObject(const std::string &key, Object &value) override; + + private: + /** @brief The root. */ + Value mRoot = Value(ValueType::ObjectValue); + }; } \ No newline at end of file diff --git a/include/trUtil/JSON/Value.h b/include/trUtil/JSON/Value.h index d0ff25b..8024292 100644 --- a/include/trUtil/JSON/Value.h +++ b/include/trUtil/JSON/Value.h @@ -1,1338 +1,1338 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -#include - -#include -#include -#include - -// Forward declarations to avoid including Json/valu.h -namespace Json -{ - /** - * @class Value - * - * @brief A value. - */ - class Value; -} - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::JSON -{ - /** - * @brief Forward declaration. - */ - class Array; - class Object; - - /** @brief The int. */ - using Int = int; - /** @brief The int. */ - using UInt = unsigned int; -#if defined(JSON_NO_INT64) - /** @brief The largest int. */ - using LargestInt = int; - /** @brief The largest u int. */ - using LargestUInt = unsigned int; -#else // if defined(JSON_NO_INT64) - // For Microsoft Visual use specific types as long long is not supported -#if defined(_MSC_VER) // Microsoft Visual Studio - /** @brief The fourth int 6. */ - using Int64 = __int64; - /** @brief The fourth u int 6. */ - using UInt64 = unsigned __int64; -#else // if defined(_MSC_VER) // Other platforms, use long long - /** @brief The fourth int 6. */ - using Int64 = int64_t; - /** @brief The fourth u int 6. */ - using UInt64 = uint64_t; -#endif // if defined(_MSC_VER) - /** @brief The largest int. */ - using LargestInt = Int64; - /** @brief The largest u int. */ - using LargestUInt = UInt64; -#endif // if defined(JSON_NO_INT64) - - /** - * @enum ValueType - * - * @brief Type of the value held by a Value object. - * - * @author Maxim Serebrennik - */ - enum ValueType - { - NullValue = 0, ///'null' value - IntValue = 1, ///signed integer value - UintValue = 2, ///unsigned integer value - RealValue = 3, ///double value - StringValue = 4, ///UTF-8 string value - BooleanValue = 5, ///bool value - ArrayValue = 6, ///array value (ordered list) - ObjectValue = 7 ///object value (collection of name/value pairs). - }; - - /** - * @class Value - * - * @brief Represents a JSON value. - * - * This class is a discriminated union wrapper that can represents a: - * - signed integer [range: Value::MinInt - Value::MaxInt] - * - unsigned integer (range: 0 - Value::MaxUInt) - * - double - * - UTF-8 string - * - boolean - * - 'null' - * - an ordered list of Value - * - collection of name/value pairs (javascript object) - * - * The type of the held value is represented by a #ValueType and can be obtained using - * Type(). - * - * Values of an #ObjectValue or #ArrayValue can be accessed using operator[]() - * methods. Non-const methods will automatically create the a #NullValue element if it - * does not exist. The sequence of an #ArrayValue will be automatically resized and - * initialized with - * #nNllValue. Resize() can be used to enlarge or truncate an #ArrayValue. - * - * The Get() methods can be used to obtain default value in the case the required - * element does not exist. - * - * It is possible to iterate over the list of a #ObjectValue values using the - * GetMemberNames() - * method. - * - * @note #Value string-length fit in size_t, but keys must be < 2^30. (The reason is - * an implementation detail.) A #CharReader will raise an exception if a bound is - * exceeded to avoid security holes in your app, but the Value API does *not* check - * bounds. That is the responsibility of the caller. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT Value - { - public: - - /** @brief The members. */ - using Members = std::vector; - - /** - * @fn Value::Value(Json::Value& value); - * - * @brief ctor. - * - * @param [in,out] value The value. - */ - Value(Json::Value& value); - - /** - * @fn Value::Value(ValueType type = NullValue); - * - * @brief ctor. - * - * @param type (Optional) The type. - */ - Value(ValueType type = NullValue); - - /** - * @fn Value::Value(Int value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(Int value); - - /** - * @fn Value::Value(UInt value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(UInt value); - - /** - * @fn Value::Value(Int64 value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(Int64 value); - - /** - * @fn Value::Value(UInt64 value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(UInt64 value); - - /** - * @fn Value::Value(double value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(double value); - - /** - * @fn Value::Value(const char* value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) - - /** - * @fn Value::Value(const char* begin, const char* end); - * - * @brief ctor. - * - * @param begin The begining value. - * @param end The end. - */ - Value(const char* begin, const char* end); ///< Copy all, incl zeroes. - - /** - * @fn Value::Value(const std::string& value); - * - * @brief ctor. - * - * @param value The value. - */ - Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too. - - /** - * @fn Value::Value(bool value); - * - * @brief ctor. - * - * @param value True to value. - */ - Value(bool value); - - /** - * @fn Value::Value(const Value& other); - * - * @brief ctor. - * - * @param other The other. - */ - Value(const Value& other); - - /** - * @fn Value::Value(Value&& other); - * - * @brief ctor Note: Can't implement due to - * 1. JsonCpp does not supply a move assignment operator. 2. JsonCpp does not have a - * move constructor that takes our JSON::Value type (obviously) - * and wrapping it to add one is not worth the effort. - * - * @param [in,out] other The other. - */ - //Value(Value&& other); - - /** - * @fn Value::~Value(); - * - * @brief dtor. - */ - ~Value(); - - /** - * @fn Json::Value& Value::GetJsonValue(); - * - * @brief Returns a reference to the internal Json::Value. - * - * @return The JSON value. - */ - Json::Value& GetJsonValue(); - - /** - * @fn const Json::Value& Value::GetJsonValue() const; - * - * @brief Returns a reference to the internal Json::Value. - * - * @return The JSON value. - */ - const Json::Value& GetJsonValue() const; - - /** - * @fn void Value::SetComment(const std::string& comment); - * - * @brief Adds a comment to the internal value. - * - * @param comment The comment. - */ - void SetComment(const std::string& comment); - - /** - * @fn bool Value::HasComment() const; - * - * @brief Checks if the internal value has a comment. - * - * @return True if comment, false if not. - */ - bool HasComment() const; - - /** - * @fn std::string Value::GetComment() const; - * - * @brief Returns the internal comment. - * - * @return The comment. - */ - std::string GetComment() const; - - /** - * @fn virtual void Value::Clear(); - * - * @brief Clears the internal JSON Root node. - */ - virtual void Clear(); - - /** - * @fn int Value::Size(); - * - * @brief Returns the size of the array. - * - * @return An int. - */ - int Size(); - - /** - * @fn void Value::Resize(int newSize); - * - * @brief Change the size of the array. - * - * @param newSize Size of the new. - */ - void Resize(int newSize); - - /** - * @fn bool Value::IsValidIndex(int index) const; - * - * @brief Return true if index < Size() - * - * @param index Zero-based index of the values position. - * - * @return True if valid index, false if not. - */ - bool IsValidIndex(int index) const; - - /** - * @fn bool Value::RemoveIndex(int index, Value *removedVal); - * - * @brief Remove the given Index value. - * - * @param index Zero-based index of the values position. - * @param [in,out] removedVal If non-null, the removed value. - * - * @return True if it succeeds, false if it fails. - */ - bool RemoveIndex(int index, Value *removedVal); - - /** - * @fn Value Value::Index(int index); - * - * @brief Returns the Value at the given index if this Value is an Array The return is by value, - * but the internal json object is stored by reference. - * - * @param index Zero-based index of the values position. - * - * @return A Value. - */ - Value Index(int index); - - /** - * @fn const Value::Members Value::GetMemberNames() const; - * - * @brief Returns the value names contained in the object. - * - * @return The member names. - */ - const Value::Members GetMemberNames() const; - - /** - * @fn bool Value::HasMember(const std::string& key) const; - * - * @brief Returns true if a member with the passed in key is present. - * - * @param key The key. - * - * @return True if member, false if not. - */ - bool HasMember(const std::string& key) const; - - /** - * @fn virtual bool Value::KeyPresent(const std::string &key) const; - * - * @brief Checks if the JSON Root Node has an entry with a given key present. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool KeyPresent(const std::string &key) const; - - /** - * @fn virtual bool Value::IsNull() const; - * - * @brief Checks if the value stored is a NULL. - * - * @return True if null, false if not. - */ - virtual bool IsNull() const; - - /** - * @fn virtual bool Value::IsNull(const int index) const; - * - * @brief Checks if the value stored is a NULL. - * - * @param index Zero-based index of the values position. - * - * @return True if null, false if not. - */ - virtual bool IsNull(const int index) const; - - /** - * @fn virtual bool Value::IsNull(const std::string& key) const; - * - * @brief Checks if the value stored is a NULL. - * - * @param key The key. - * - * @return True if null, false if not. - */ - virtual bool IsNull(const std::string& key) const; - - /** - * @fn virtual void Value::SetNull(const std::string& key) const; - * - * @brief Sets the NULL value in the Object. - * - * @param key The key. - */ - virtual void SetNull(const std::string& key) const; - - /** - * @fn virtual bool Value::IsEmpty() const; - * - * @brief Return true if empty array, empty object, or null, otherwise, false. - * - * @return True if empty, false if not. - */ - virtual bool IsEmpty() const; - - /** - * @fn virtual bool Value::IsEmpty(const int index) const; - * - * @brief Return true if empty array, empty object, or null, otherwise, false. - * - * @param index Zero-based index of the values position. - * - * @return True if empty, false if not. - */ - virtual bool IsEmpty(const int index) const; - - /** - * @fn virtual bool Value::IsEmpty(const std::string& key) const; - * - * @brief Return true if empty array, empty object, or null, otherwise, false. - * - * @param key The key. - * - * @return True if empty, false if not. - */ - virtual bool IsEmpty(const std::string& key) const; - - /** - * @fn virtual void Value::Append(const Value& val); - * - * @brief Add a value at the end of the array. - * - * @param val The Value to append. - */ - virtual void Append(const Value& val); - - /** - * @fn virtual bool Value::IsBool() const; - * - * @brief Checks if the value stored is a Boolean. - * - * @return True if bool, false if not. - */ - virtual bool IsBool() const; - - /** - * @fn virtual bool Value::IsBool(const int index) const; - * - * @brief Checks if the value stored is a Boolean. - * - * @param index Zero-based index of the values position. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(const int index) const; - - /** - * @fn virtual bool Value::IsBool(const std::string& key) const; - * - * @brief Checks if the value stored is a Boolean. - * - * @param key The key. - * - * @return True if bool, false if not. - */ - virtual bool IsBool(const std::string& key) const; - - /** - * @fn virtual bool Value::GetBool() const; - * - * @brief Returns the Boolean value. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool() const; - - /** - * @fn virtual bool Value::GetBool(const int index) const; - * - * @brief Returns the Boolean value. - * - * @param index Zero-based index of the values position. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(const int index) const; - - /** - * @fn virtual bool Value::GetBool(const std::string& key) const; - * - * @brief Returns the Boolean value. - * - * @param key The key. - * - * @return True if it succeeds, false if it fails. - */ - virtual bool GetBool(const std::string& key) const; - - /** - * @fn virtual void Value::SetBool(const std::string& key, bool value); - * - * @brief Sets the Boolean value in the Object. - * - * @param key The key. - * @param value True to value. - */ - virtual void SetBool(const std::string& key, bool value); - - /** - * @fn virtual bool Value::IsNumber() const; - * - * @brief Checks if the value stored is a Number. - * - * @return True if number, false if not. - */ - virtual bool IsNumber() const; - - /** - * @fn virtual bool Value::IsNumber(const int index) const; - * - * @brief Checks if the value stored is a Number. - * - * @param index Zero-based index of the values position. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(const int index) const; - - /** - * @fn virtual bool Value::IsNumber(const std::string& key) const; - * - * @brief Checks if the value stored is a Number. - * - * @param key The key. - * - * @return True if number, false if not. - */ - virtual bool IsNumber(const std::string& key) const; - - /** - * @fn virtual bool Value::IsInt() const; - * - * @brief Checks if the value stored is an Integer. - * - * @return True if int, false if not. - */ - virtual bool IsInt() const; - - /** - * @fn virtual bool Value::IsInt(const int index) const; - * - * @brief Checks if the value stored is an Integer. - * - * @param index Zero-based index of the values position. - * - * @return True if int, false if not. - */ - virtual bool IsInt(const int index) const; - - /** - * @fn virtual bool Value::IsInt(const std::string& key) const; - * - * @brief Checks if the value stored is an Integer. - * - * @param key The key. - * - * @return True if int, false if not. - */ - virtual bool IsInt(const std::string& key) const; - - /** - * @fn virtual int Value::GetInt() const; - * - * @brief Returns the Integer value. - * - * @return The int. - */ - virtual int GetInt() const; - - /** - * @fn virtual int Value::GetInt(const int index) const; - * - * @brief Returns the Integer value. - * - * @param index Zero-based index of the values position. - * - * @return The int. - */ - virtual int GetInt(const int index) const; - - /** - * @fn virtual int Value::GetInt(const std::string& key) const; - * - * @brief Returns the Integer value. - * - * @param key The key. - * - * @return The int. - */ - virtual int GetInt(const std::string& key) const; - - /** - * @fn virtual void Value::SetInt(const std::string& key, int value); - * - * @brief Sets the Integer value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt(const std::string& key, int value); - - /** - * @fn virtual bool Value::IsDouble() const; - * - * @brief Checks if the value stored is a Double. - * - * @return True if double, false if not. - */ - virtual bool IsDouble() const; - - /** - * @fn virtual bool Value::IsDouble(const int index) const; - * - * @brief Checks if the value stored is a Double. - * - * @param index Zero-based index of the values position. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(const int index) const; - - /** - * @fn virtual bool Value::IsDouble(const std::string& key) const; - * - * @brief Checks if the value stored is a Double. - * - * @param key The key. - * - * @return True if double, false if not. - */ - virtual bool IsDouble(const std::string& key) const; - - /** - * @fn virtual double Value::GetDouble() const; - * - * @brief Returns the Double value. - * - * @return The double. - */ - virtual double GetDouble() const; - - /** - * @fn virtual double Value::GetDouble(const int index) const; - * - * @brief Returns the Double value. - * - * @param index Zero-based index of the values position. - * - * @return The double. - */ - virtual double GetDouble(const int index) const; - - /** - * @fn virtual double Value::GetDouble(const std::string& key) const; - * - * @brief Returns the Double value. - * - * @param key The key. - * - * @return The double. - */ - virtual double GetDouble(const std::string& key) const; - - /** - * @fn virtual void Value::SetDouble(const std::string& key, double value); - * - * @brief Sets the Double value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetDouble(const std::string& key, double value); - - /** - * @fn virtual bool Value::IsUInt() const; - * - * @brief Checks if the value stored Unsigned Integer. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt() const; - - /** - * @fn virtual bool Value::IsUInt(const int index) const; - * - * @brief Checks if the value stored Unsigned Integer. - * - * @param index Zero-based index of the values position. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(const int index) const; - - /** - * @fn virtual bool Value::IsUInt(const std::string& key) const; - * - * @brief Checks if the value stored Unsigned Integer. - * - * @param key The key. - * - * @return True if u int, false if not. - */ - virtual bool IsUInt(const std::string& key) const; - - /** - * @fn virtual unsigned int Value::GetUInt() const; - * - * @brief Returns the Unsigned Integer value. - * - * @return The u int. - */ - virtual unsigned int GetUInt() const; - - /** - * @fn virtual unsigned int Value::GetUInt(const int index) const; - * - * @brief Returns the Unsigned Integer value. - * - * @param index Zero-based index of the values position. - * - * @return The u int. - */ - virtual unsigned int GetUInt(const int index) const; - - /** - * @fn virtual unsigned int Value::GetUInt(const std::string& key) const; - * - * @brief Returns the Unsigned Integer value. - * - * @param key The key. - * - * @return The u int. - */ - virtual unsigned int GetUInt(const std::string& key) const; - - /** - * @fn virtual void Value::SetUInt(const std::string& key, unsigned int value); - * - * @brief Sets the Unsigned Int value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt(const std::string& key, unsigned int value); - - /** - * @fn virtual bool Value::IsInt64() const; - * - * @brief Checks if the value stored is a 64bit Integer. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64() const; - - /** - * @fn virtual bool Value::IsInt64(const int index) const; - * - * @brief Checks if the value stored is a 64bit Integer. - * - * @param index Zero-based index of the values position. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(const int index) const; - - /** - * @fn virtual bool Value::IsInt64(const std::string& key) const; - * - * @brief Checks if the value stored is a 64bit Integer. - * - * @param key The key. - * - * @return True if int 64, false if not. - */ - virtual bool IsInt64(const std::string& key) const; - - /** - * @fn virtual Int64 Value::GetInt64() const; - * - * @brief Returns the 64bit Integer value. - * - * @return The int 64. - */ - virtual Int64 GetInt64() const; - - /** - * @fn virtual Int64 Value::GetInt64(const int index) const; - * - * @brief Returns the 64bit Integer value. - * - * @param index Zero-based index of the values position. - * - * @return The int 64. - */ - virtual Int64 GetInt64(const int index) const; - - /** - * @fn virtual Int64 Value::GetInt64(const std::string& key) const; - * - * @brief Returns the 64bit Integer value. - * - * @param key The key. - * - * @return The int 64. - */ - virtual Int64 GetInt64(const std::string& key) const; - - /** - * @fn virtual void Value::SetInt64(const std::string& key, Int64 value); - * - * @brief Sets the Int64 value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetInt64(const std::string& key, Int64 value); - - /** - * @fn virtual bool Value::IsUInt64() const; - * - * @brief Checks if the value stored is a 64bit Unsigned Integer. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64() const; - - /** - * @fn virtual bool Value::IsUInt64(const int index) const; - * - * @brief Checks if the value stored is a 64bit Unsigned Integer. - * - * @param index Zero-based index of the values position. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(const int index) const; - - /** - * @fn virtual bool Value::IsUInt64(const std::string& key) const; - * - * @brief Checks if the value stored is a 64bit Unsigned Integer. - * - * @param key The key. - * - * @return True if u int 64, false if not. - */ - virtual bool IsUInt64(const std::string& key) const; - - /** - * @fn virtual UInt64 Value::GetUInt64() const; - * - * @brief Returns the Unsigned 64bit Integer value. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64() const; - - /** - * @fn virtual UInt64 Value::GetUInt64(const int index) const; - * - * @brief Returns the Unsigned 64bit Integer value. - * - * @param index Zero-based index of the values position. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(const int index) const; - - /** - * @fn virtual UInt64 Value::GetUInt64(const std::string& key) const; - * - * @brief Returns the Unsigned 64bit Integer value. - * - * @param key The key. - * - * @return The u int 64. - */ - virtual UInt64 GetUInt64(const std::string& key) const; - - /** - * @fn virtual void Value::SetUInt64(const std::string& key, UInt64 value); - * - * @brief Sets the Unsigned Int64 value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetUInt64(const std::string& key, UInt64 value); - - /** - * @fn virtual bool Value::IsFloat() const; - * - * @brief Checks if the value stored is a float. - * - * @return True if float, false if not. - */ - virtual bool IsFloat() const; - - /** - * @fn virtual bool Value::IsFloat(const int index) const; - * - * @brief Checks if the value stored is a float. - * - * @param index Zero-based index of the values position. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(const int index) const; - - /** - * @fn virtual bool Value::IsFloat(const std::string& key) const; - * - * @brief Checks if the value stored is a float. - * - * @param key The key. - * - * @return True if float, false if not. - */ - virtual bool IsFloat(const std::string& key) const; - - /** - * @fn virtual float Value::GetFloat() const; - * - * @brief Returns the float value stored. - * - * @return The float. - */ - virtual float GetFloat() const; - - /** - * @fn virtual float Value::GetFloat(const int index) const; - * - * @brief Returns the float value stored. - * - * @param index Zero-based index of the values position. - * - * @return The float. - */ - virtual float GetFloat(const int index) const; - - /** - * @fn virtual float Value::GetFloat(const std::string& key) const; - * - * @brief Returns the float value stored. - * - * @param key The key. - * - * @return The float. - */ - virtual float GetFloat(const std::string& key) const; - - /** - * @fn virtual void Value::SetFloat(const std::string& key, float value); - * - * @brief Sets the Float value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetFloat(const std::string& key, float value); - - /** - * @fn virtual bool Value::IsString() const; - * - * @brief Checks if the value stored is a String. - * - * @return True if string, false if not. - */ - virtual bool IsString() const; - - /** - * @fn virtual bool Value::IsString(const int index) const; - * - * @brief Checks if the value stored is a String. - * - * @param index Zero-based index of the values position. - * - * @return True if string, false if not. - */ - virtual bool IsString(const int index) const; - - /** - * @fn virtual bool Value::IsString(const std::string& key) const; - * - * @brief Checks if the value stored is a String. - * - * @param key The key. - * - * @return True if string, false if not. - */ - virtual bool IsString(const std::string& key) const; - - /** - * @fn virtual const std::string Value::GetString() const; - * - * @brief Returns the String value stored. - * - * @return The string. - */ - virtual const std::string GetString() const; - - /** - * @fn virtual const std::string Value::GetString(const int index) const; - * - * @brief Returns the String value stored. - * - * @param index Zero-based index of the values position. - * - * @return The string. - */ - virtual const std::string GetString(const int index) const; - - /** - * @fn virtual const std::string Value::GetString(const std::string& key) const; - * - * @brief Returns the String value stored. - * - * @param key The key. - * - * @return The string. - */ - virtual const std::string GetString(const std::string& key) const; - - /** - * @fn virtual void Value::SetString(const std::string& key, const std::string& value); - * - * @brief Sets the String value in the Object. - * - * @param key The key. - * @param value The value. - */ - virtual void SetString(const std::string& key, const std::string& value); - - /** - * @fn virtual bool Value::IsArray() const; - * - * @brief Checks if the value stored is an Array. - * - * @return True if array, false if not. - */ - virtual bool IsArray() const; - - /** - * @fn virtual bool Value::IsArray(const int index) const; - * - * @brief Checks if the value stored is an Array. - * - * @param index Zero-based index of the values position. - * - * @return True if array, false if not. - */ - virtual bool IsArray(const int index) const; - - /** - * @fn virtual bool Value::IsArray(const std::string& key) const; - * - * @brief Checks if the value stored is an Array. - * - * @param key The key. - * - * @return True if array, false if not. - */ - virtual bool IsArray(const std::string& key) const; - - /** - * @fn virtual const Array Value::GetArray() const; - * - * @brief Returns the Array value stored. - * - * @return The array. - */ - virtual const Array GetArray() const; - - /** - * @fn virtual const Array Value::GetArray(const int index) const; - * - * @brief Returns the Array value stored. - * - * @param index Zero-based index of the values position. - * - * @return The array. - */ - virtual const Array GetArray(const int index) const; - - /** - * @fn virtual const Array Value::GetArray(const std::string& key) const; - * - * @brief Returns the Array value stored. - * - * @param key The key. - * - * @return The array. - */ - virtual const Array GetArray(const std::string& key) const; - - /** - * @fn virtual void Value::SetArray(const std::string& key, Array& value); - * - * @brief Sets the Array value in the Object. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetArray(const std::string& key, Array& value); - - /** - * @fn virtual bool Value::IsObject() const; - * - * @brief Checks if the value stored is an Object. - * - * @return True if object, false if not. - */ - virtual bool IsObject() const; - - /** - * @fn virtual bool Value::IsObject(const int index) const; - * - * @brief Checks if the value stored is an Object. - * - * @param index Zero-based index of the values position. - * - * @return True if object, false if not. - */ - virtual bool IsObject(const int index) const; - - /** - * @fn virtual bool Value::IsObject(const std::string& key) const; - * - * @brief Checks if the value stored is an Object. - * - * @param key The key. - * - * @return True if object, false if not. - */ - virtual bool IsObject(const std::string& key) const; - - /** - * @fn virtual const Object Value::GetObject() const; - * - * @brief Returns the Object value stored. - * - * @return The object. - */ - virtual const Object GetObject() const; - - /** - * @fn virtual const Object Value::GetObject(const int index) const; - * - * @brief Returns the Object value stored. - * - * @param index Zero-based index of the values position. - * - * @return The object. - */ - virtual const Object GetObject(const int index) const; - - /** - * @fn virtual const Object Value::GetObject(const std::string& key) const; - * - * @brief Returns the Object value stored. - * - * @param key The key. - * - * @return The object. - */ - virtual const Object GetObject(const std::string& key) const; - - /** - * @fn virtual void Value::SetObject(const std::string& key, Object& value); - * - * @brief Sets the Object value in the Object. - * - * @param key The key. - * @param [in,out] value The value. - */ - virtual void SetObject(const std::string& key, Object& value); - - /** - * @fn operator Json::Value() const; - * - * @brief Implicit conversion operator to Json::Value. - * - * @return The result of the operation. - */ - operator Json::Value() const; - - /** - * @fn operator Json::Value& (); - * - * @brief Implicit conversion operator to Json::Value. - * - * @return The result of the operation. - */ - operator Json::Value& (); - - /** - * @fn operator const Json::Value& () const; - * - * @brief Implicit conversion operator to Json::Value. - * - * @return A const. - */ - operator const Json::Value& () const; - - /** - * @fn operator Json::Value* (); - * - * @brief Implicit conversion operator to Json::Value. - * - * @return The result of the operation. - */ - operator Json::Value* (); - - ///// Access an array element (zero based index ). - ///// If the array contains less than index element, then null value are - ///// inserted - ///// in the array so that its size is index+1. - ///// (You may need to say 'value[0u]' to get your compiler to distinguish - ///// this from the operator[] which takes a string.) - //Value operator[](int index); - - ///// Access an array element (zero based index ) - ///// (You may need to say 'value[0u]' to get your compiler to distinguish - ///// this from the operator[] which takes a string.) - //const Value operator[](int index) const; - - ///// Access an object value by name, create a null member if it does not exist. - ///// \note Because of our implementation, keys are limited to 2^30 -1 chars. - ///// Exceeding that will cause an exception. - //Value operator[](const char* key); - - ///// Access an object value by name, returns null if there is no member with - ///// that name. - //const Value operator[](const char* key) const; - - ///// Access an object value by name, create a null member if it does not exist. - ///// \param key may contain embedded nulls. - //Value operator[](const std::string& key); - - /** - * @fn Value& Value::operator=(Value other); - * - * @brief // Access an object value by name, returns null if there is no member with // that - * name. //\param key may contain embedded nulls. //const Value operator[](const - * std::string& key) - * const; - * - * @param other The other. - * - * @return A shallow copy of this object. - */ - Value& operator=(Value other); - - protected: - - /** @brief True to clear internal value. */ - bool clearInternalVal = true; - /** @brief The value pointer. */ - Json::Value* mValuePtr = nullptr; - }; - - /** - * @fn TR_UTIL_EXPORT std::ostream& operator<<(std::ostream&, const Value& root); - * - * @brief OStream operator. - * - * @author Maxim Serebrennik - * - * @param [in,out] parameter1 The first parameter. - * @param root The root. - * - * @return The shifted result. - */ - TR_UTIL_EXPORT std::ostream& operator<<(std::ostream&, const Value& root); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ + +#pragma once + +#include + +#include +#include +#include + +// Forward declarations to avoid including Json/valu.h +namespace Json +{ + /** + * @class Value + * + * @brief A value. + */ + class Value; +} + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::JSON +{ + /** + * @brief Forward declaration. + */ + class Array; + class Object; + + /** @brief The int. */ + using Int = int; + /** @brief The int. */ + using UInt = unsigned int; +#if defined(JSON_NO_INT64) + /** @brief The largest int. */ + using LargestInt = int; + /** @brief The largest u int. */ + using LargestUInt = unsigned int; +#else // if defined(JSON_NO_INT64) + // For Microsoft Visual use specific types as long long is not supported +#if defined(_MSC_VER) // Microsoft Visual Studio + /** @brief The fourth int 6. */ + using Int64 = __int64; + /** @brief The fourth u int 6. */ + using UInt64 = unsigned __int64; +#else // if defined(_MSC_VER) // Other platforms, use long long + /** @brief The fourth int 6. */ + using Int64 = int64_t; + /** @brief The fourth u int 6. */ + using UInt64 = uint64_t; +#endif // if defined(_MSC_VER) + /** @brief The largest int. */ + using LargestInt = Int64; + /** @brief The largest u int. */ + using LargestUInt = UInt64; +#endif // if defined(JSON_NO_INT64) + + /** + * @enum ValueType + * + * @brief Type of the value held by a Value object. + * + * @author Maxim Serebrennik + */ + enum ValueType + { + NullValue = 0, ///'null' value + IntValue = 1, ///signed integer value + UintValue = 2, ///unsigned integer value + RealValue = 3, ///double value + StringValue = 4, ///UTF-8 string value + BooleanValue = 5, ///bool value + ArrayValue = 6, ///array value (ordered list) + ObjectValue = 7 ///object value (collection of name/value pairs). + }; + + /** + * @class Value + * + * @brief Represents a JSON value. + * + * This class is a discriminated union wrapper that can represents a: + * - signed integer [range: Value::MinInt - Value::MaxInt] + * - unsigned integer (range: 0 - Value::MaxUInt) + * - double + * - UTF-8 string + * - boolean + * - 'null' + * - an ordered list of Value + * - collection of name/value pairs (javascript object) + * + * The type of the held value is represented by a #ValueType and can be obtained using + * Type(). + * + * Values of an #ObjectValue or #ArrayValue can be accessed using operator[]() + * methods. Non-const methods will automatically create the a #NullValue element if it + * does not exist. The sequence of an #ArrayValue will be automatically resized and + * initialized with + * #nNllValue. Resize() can be used to enlarge or truncate an #ArrayValue. + * + * The Get() methods can be used to obtain default value in the case the required + * element does not exist. + * + * It is possible to iterate over the list of a #ObjectValue values using the + * GetMemberNames() + * method. + * + * @note #Value string-length fit in size_t, but keys must be < 2^30. (The reason is + * an implementation detail.) A #CharReader will raise an exception if a bound is + * exceeded to avoid security holes in your app, but the Value API does *not* check + * bounds. That is the responsibility of the caller. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT Value + { + public: + + /** @brief The members. */ + using Members = std::vector; + + /** + * @fn Value::Value(Json::Value& value); + * + * @brief ctor. + * + * @param [in,out] value The value. + */ + Value(Json::Value& value); + + /** + * @fn Value::Value(ValueType type = NullValue); + * + * @brief ctor. + * + * @param type (Optional) The type. + */ + Value(ValueType type = NullValue); + + /** + * @fn Value::Value(Int value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(Int value); + + /** + * @fn Value::Value(UInt value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(UInt value); + + /** + * @fn Value::Value(Int64 value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(Int64 value); + + /** + * @fn Value::Value(UInt64 value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(UInt64 value); + + /** + * @fn Value::Value(double value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(double value); + + /** + * @fn Value::Value(const char* value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.) + + /** + * @fn Value::Value(const char* begin, const char* end); + * + * @brief ctor. + * + * @param begin The begining value. + * @param end The end. + */ + Value(const char* begin, const char* end); ///< Copy all, incl zeroes. + + /** + * @fn Value::Value(const std::string& value); + * + * @brief ctor. + * + * @param value The value. + */ + Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too. + + /** + * @fn Value::Value(bool value); + * + * @brief ctor. + * + * @param value True to value. + */ + Value(bool value); + + /** + * @fn Value::Value(const Value& other); + * + * @brief ctor. + * + * @param other The other. + */ + Value(const Value& other); + + /** + * @fn Value::Value(Value&& other); + * + * @brief ctor Note: Can't implement due to + * 1. JsonCpp does not supply a move assignment operator. 2. JsonCpp does not have a + * move constructor that takes our JSON::Value type (obviously) + * and wrapping it to add one is not worth the effort. + * + * @param [in,out] other The other. + */ + //Value(Value&& other); + + /** + * @fn Value::~Value(); + * + * @brief dtor. + */ + ~Value(); + + /** + * @fn Json::Value& Value::GetJsonValue(); + * + * @brief Returns a reference to the internal Json::Value. + * + * @return The JSON value. + */ + Json::Value& GetJsonValue(); + + /** + * @fn const Json::Value& Value::GetJsonValue() const; + * + * @brief Returns a reference to the internal Json::Value. + * + * @return The JSON value. + */ + const Json::Value& GetJsonValue() const; + + /** + * @fn void Value::SetComment(const std::string& comment); + * + * @brief Adds a comment to the internal value. + * + * @param comment The comment. + */ + void SetComment(const std::string& comment); + + /** + * @fn bool Value::HasComment() const; + * + * @brief Checks if the internal value has a comment. + * + * @return True if comment, false if not. + */ + bool HasComment() const; + + /** + * @fn std::string Value::GetComment() const; + * + * @brief Returns the internal comment. + * + * @return The comment. + */ + std::string GetComment() const; + + /** + * @fn virtual void Value::Clear(); + * + * @brief Clears the internal JSON Root node. + */ + virtual void Clear(); + + /** + * @fn int Value::Size(); + * + * @brief Returns the size of the array. + * + * @return An int. + */ + int Size(); + + /** + * @fn void Value::Resize(int newSize); + * + * @brief Change the size of the array. + * + * @param newSize Size of the new. + */ + void Resize(int newSize); + + /** + * @fn bool Value::IsValidIndex(int index) const; + * + * @brief Return true if index < Size() + * + * @param index Zero-based index of the values position. + * + * @return True if valid index, false if not. + */ + bool IsValidIndex(int index) const; + + /** + * @fn bool Value::RemoveIndex(int index, Value *removedVal); + * + * @brief Remove the given Index value. + * + * @param index Zero-based index of the values position. + * @param [in,out] removedVal If non-null, the removed value. + * + * @return True if it succeeds, false if it fails. + */ + bool RemoveIndex(int index, Value *removedVal); + + /** + * @fn Value Value::Index(int index); + * + * @brief Returns the Value at the given index if this Value is an Array The return is by value, + * but the internal json object is stored by reference. + * + * @param index Zero-based index of the values position. + * + * @return A Value. + */ + Value Index(int index); + + /** + * @fn const Value::Members Value::GetMemberNames() const; + * + * @brief Returns the value names contained in the object. + * + * @return The member names. + */ + const Value::Members GetMemberNames() const; + + /** + * @fn bool Value::HasMember(const std::string& key) const; + * + * @brief Returns true if a member with the passed in key is present. + * + * @param key The key. + * + * @return True if member, false if not. + */ + bool HasMember(const std::string& key) const; + + /** + * @fn virtual bool Value::KeyPresent(const std::string &key) const; + * + * @brief Checks if the JSON Root Node has an entry with a given key present. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool KeyPresent(const std::string &key) const; + + /** + * @fn virtual bool Value::IsNull() const; + * + * @brief Checks if the value stored is a NULL. + * + * @return True if null, false if not. + */ + virtual bool IsNull() const; + + /** + * @fn virtual bool Value::IsNull(const int index) const; + * + * @brief Checks if the value stored is a NULL. + * + * @param index Zero-based index of the values position. + * + * @return True if null, false if not. + */ + virtual bool IsNull(const int index) const; + + /** + * @fn virtual bool Value::IsNull(const std::string& key) const; + * + * @brief Checks if the value stored is a NULL. + * + * @param key The key. + * + * @return True if null, false if not. + */ + virtual bool IsNull(const std::string& key) const; + + /** + * @fn virtual void Value::SetNull(const std::string& key) const; + * + * @brief Sets the NULL value in the Object. + * + * @param key The key. + */ + virtual void SetNull(const std::string& key) const; + + /** + * @fn virtual bool Value::IsEmpty() const; + * + * @brief Return true if empty array, empty object, or null, otherwise, false. + * + * @return True if empty, false if not. + */ + virtual bool IsEmpty() const; + + /** + * @fn virtual bool Value::IsEmpty(const int index) const; + * + * @brief Return true if empty array, empty object, or null, otherwise, false. + * + * @param index Zero-based index of the values position. + * + * @return True if empty, false if not. + */ + virtual bool IsEmpty(const int index) const; + + /** + * @fn virtual bool Value::IsEmpty(const std::string& key) const; + * + * @brief Return true if empty array, empty object, or null, otherwise, false. + * + * @param key The key. + * + * @return True if empty, false if not. + */ + virtual bool IsEmpty(const std::string& key) const; + + /** + * @fn virtual void Value::Append(const Value& val); + * + * @brief Add a value at the end of the array. + * + * @param val The Value to append. + */ + virtual void Append(const Value& val); + + /** + * @fn virtual bool Value::IsBool() const; + * + * @brief Checks if the value stored is a Boolean. + * + * @return True if bool, false if not. + */ + virtual bool IsBool() const; + + /** + * @fn virtual bool Value::IsBool(const int index) const; + * + * @brief Checks if the value stored is a Boolean. + * + * @param index Zero-based index of the values position. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(const int index) const; + + /** + * @fn virtual bool Value::IsBool(const std::string& key) const; + * + * @brief Checks if the value stored is a Boolean. + * + * @param key The key. + * + * @return True if bool, false if not. + */ + virtual bool IsBool(const std::string& key) const; + + /** + * @fn virtual bool Value::GetBool() const; + * + * @brief Returns the Boolean value. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool() const; + + /** + * @fn virtual bool Value::GetBool(const int index) const; + * + * @brief Returns the Boolean value. + * + * @param index Zero-based index of the values position. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(const int index) const; + + /** + * @fn virtual bool Value::GetBool(const std::string& key) const; + * + * @brief Returns the Boolean value. + * + * @param key The key. + * + * @return True if it succeeds, false if it fails. + */ + virtual bool GetBool(const std::string& key) const; + + /** + * @fn virtual void Value::SetBool(const std::string& key, bool value); + * + * @brief Sets the Boolean value in the Object. + * + * @param key The key. + * @param value True to value. + */ + virtual void SetBool(const std::string& key, bool value); + + /** + * @fn virtual bool Value::IsNumber() const; + * + * @brief Checks if the value stored is a Number. + * + * @return True if number, false if not. + */ + virtual bool IsNumber() const; + + /** + * @fn virtual bool Value::IsNumber(const int index) const; + * + * @brief Checks if the value stored is a Number. + * + * @param index Zero-based index of the values position. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(const int index) const; + + /** + * @fn virtual bool Value::IsNumber(const std::string& key) const; + * + * @brief Checks if the value stored is a Number. + * + * @param key The key. + * + * @return True if number, false if not. + */ + virtual bool IsNumber(const std::string& key) const; + + /** + * @fn virtual bool Value::IsInt() const; + * + * @brief Checks if the value stored is an Integer. + * + * @return True if int, false if not. + */ + virtual bool IsInt() const; + + /** + * @fn virtual bool Value::IsInt(const int index) const; + * + * @brief Checks if the value stored is an Integer. + * + * @param index Zero-based index of the values position. + * + * @return True if int, false if not. + */ + virtual bool IsInt(const int index) const; + + /** + * @fn virtual bool Value::IsInt(const std::string& key) const; + * + * @brief Checks if the value stored is an Integer. + * + * @param key The key. + * + * @return True if int, false if not. + */ + virtual bool IsInt(const std::string& key) const; + + /** + * @fn virtual int Value::GetInt() const; + * + * @brief Returns the Integer value. + * + * @return The int. + */ + virtual int GetInt() const; + + /** + * @fn virtual int Value::GetInt(const int index) const; + * + * @brief Returns the Integer value. + * + * @param index Zero-based index of the values position. + * + * @return The int. + */ + virtual int GetInt(const int index) const; + + /** + * @fn virtual int Value::GetInt(const std::string& key) const; + * + * @brief Returns the Integer value. + * + * @param key The key. + * + * @return The int. + */ + virtual int GetInt(const std::string& key) const; + + /** + * @fn virtual void Value::SetInt(const std::string& key, int value); + * + * @brief Sets the Integer value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt(const std::string& key, int value); + + /** + * @fn virtual bool Value::IsDouble() const; + * + * @brief Checks if the value stored is a Double. + * + * @return True if double, false if not. + */ + virtual bool IsDouble() const; + + /** + * @fn virtual bool Value::IsDouble(const int index) const; + * + * @brief Checks if the value stored is a Double. + * + * @param index Zero-based index of the values position. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(const int index) const; + + /** + * @fn virtual bool Value::IsDouble(const std::string& key) const; + * + * @brief Checks if the value stored is a Double. + * + * @param key The key. + * + * @return True if double, false if not. + */ + virtual bool IsDouble(const std::string& key) const; + + /** + * @fn virtual double Value::GetDouble() const; + * + * @brief Returns the Double value. + * + * @return The double. + */ + virtual double GetDouble() const; + + /** + * @fn virtual double Value::GetDouble(const int index) const; + * + * @brief Returns the Double value. + * + * @param index Zero-based index of the values position. + * + * @return The double. + */ + virtual double GetDouble(const int index) const; + + /** + * @fn virtual double Value::GetDouble(const std::string& key) const; + * + * @brief Returns the Double value. + * + * @param key The key. + * + * @return The double. + */ + virtual double GetDouble(const std::string& key) const; + + /** + * @fn virtual void Value::SetDouble(const std::string& key, double value); + * + * @brief Sets the Double value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetDouble(const std::string& key, double value); + + /** + * @fn virtual bool Value::IsUInt() const; + * + * @brief Checks if the value stored Unsigned Integer. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt() const; + + /** + * @fn virtual bool Value::IsUInt(const int index) const; + * + * @brief Checks if the value stored Unsigned Integer. + * + * @param index Zero-based index of the values position. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(const int index) const; + + /** + * @fn virtual bool Value::IsUInt(const std::string& key) const; + * + * @brief Checks if the value stored Unsigned Integer. + * + * @param key The key. + * + * @return True if u int, false if not. + */ + virtual bool IsUInt(const std::string& key) const; + + /** + * @fn virtual unsigned int Value::GetUInt() const; + * + * @brief Returns the Unsigned Integer value. + * + * @return The u int. + */ + virtual unsigned int GetUInt() const; + + /** + * @fn virtual unsigned int Value::GetUInt(const int index) const; + * + * @brief Returns the Unsigned Integer value. + * + * @param index Zero-based index of the values position. + * + * @return The u int. + */ + virtual unsigned int GetUInt(const int index) const; + + /** + * @fn virtual unsigned int Value::GetUInt(const std::string& key) const; + * + * @brief Returns the Unsigned Integer value. + * + * @param key The key. + * + * @return The u int. + */ + virtual unsigned int GetUInt(const std::string& key) const; + + /** + * @fn virtual void Value::SetUInt(const std::string& key, unsigned int value); + * + * @brief Sets the Unsigned Int value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt(const std::string& key, unsigned int value); + + /** + * @fn virtual bool Value::IsInt64() const; + * + * @brief Checks if the value stored is a 64bit Integer. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64() const; + + /** + * @fn virtual bool Value::IsInt64(const int index) const; + * + * @brief Checks if the value stored is a 64bit Integer. + * + * @param index Zero-based index of the values position. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(const int index) const; + + /** + * @fn virtual bool Value::IsInt64(const std::string& key) const; + * + * @brief Checks if the value stored is a 64bit Integer. + * + * @param key The key. + * + * @return True if int 64, false if not. + */ + virtual bool IsInt64(const std::string& key) const; + + /** + * @fn virtual Int64 Value::GetInt64() const; + * + * @brief Returns the 64bit Integer value. + * + * @return The int 64. + */ + virtual Int64 GetInt64() const; + + /** + * @fn virtual Int64 Value::GetInt64(const int index) const; + * + * @brief Returns the 64bit Integer value. + * + * @param index Zero-based index of the values position. + * + * @return The int 64. + */ + virtual Int64 GetInt64(const int index) const; + + /** + * @fn virtual Int64 Value::GetInt64(const std::string& key) const; + * + * @brief Returns the 64bit Integer value. + * + * @param key The key. + * + * @return The int 64. + */ + virtual Int64 GetInt64(const std::string& key) const; + + /** + * @fn virtual void Value::SetInt64(const std::string& key, Int64 value); + * + * @brief Sets the Int64 value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetInt64(const std::string& key, Int64 value); + + /** + * @fn virtual bool Value::IsUInt64() const; + * + * @brief Checks if the value stored is a 64bit Unsigned Integer. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64() const; + + /** + * @fn virtual bool Value::IsUInt64(const int index) const; + * + * @brief Checks if the value stored is a 64bit Unsigned Integer. + * + * @param index Zero-based index of the values position. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(const int index) const; + + /** + * @fn virtual bool Value::IsUInt64(const std::string& key) const; + * + * @brief Checks if the value stored is a 64bit Unsigned Integer. + * + * @param key The key. + * + * @return True if u int 64, false if not. + */ + virtual bool IsUInt64(const std::string& key) const; + + /** + * @fn virtual UInt64 Value::GetUInt64() const; + * + * @brief Returns the Unsigned 64bit Integer value. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64() const; + + /** + * @fn virtual UInt64 Value::GetUInt64(const int index) const; + * + * @brief Returns the Unsigned 64bit Integer value. + * + * @param index Zero-based index of the values position. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(const int index) const; + + /** + * @fn virtual UInt64 Value::GetUInt64(const std::string& key) const; + * + * @brief Returns the Unsigned 64bit Integer value. + * + * @param key The key. + * + * @return The u int 64. + */ + virtual UInt64 GetUInt64(const std::string& key) const; + + /** + * @fn virtual void Value::SetUInt64(const std::string& key, UInt64 value); + * + * @brief Sets the Unsigned Int64 value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetUInt64(const std::string& key, UInt64 value); + + /** + * @fn virtual bool Value::IsFloat() const; + * + * @brief Checks if the value stored is a float. + * + * @return True if float, false if not. + */ + virtual bool IsFloat() const; + + /** + * @fn virtual bool Value::IsFloat(const int index) const; + * + * @brief Checks if the value stored is a float. + * + * @param index Zero-based index of the values position. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(const int index) const; + + /** + * @fn virtual bool Value::IsFloat(const std::string& key) const; + * + * @brief Checks if the value stored is a float. + * + * @param key The key. + * + * @return True if float, false if not. + */ + virtual bool IsFloat(const std::string& key) const; + + /** + * @fn virtual float Value::GetFloat() const; + * + * @brief Returns the float value stored. + * + * @return The float. + */ + virtual float GetFloat() const; + + /** + * @fn virtual float Value::GetFloat(const int index) const; + * + * @brief Returns the float value stored. + * + * @param index Zero-based index of the values position. + * + * @return The float. + */ + virtual float GetFloat(const int index) const; + + /** + * @fn virtual float Value::GetFloat(const std::string& key) const; + * + * @brief Returns the float value stored. + * + * @param key The key. + * + * @return The float. + */ + virtual float GetFloat(const std::string& key) const; + + /** + * @fn virtual void Value::SetFloat(const std::string& key, float value); + * + * @brief Sets the Float value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetFloat(const std::string& key, float value); + + /** + * @fn virtual bool Value::IsString() const; + * + * @brief Checks if the value stored is a String. + * + * @return True if string, false if not. + */ + virtual bool IsString() const; + + /** + * @fn virtual bool Value::IsString(const int index) const; + * + * @brief Checks if the value stored is a String. + * + * @param index Zero-based index of the values position. + * + * @return True if string, false if not. + */ + virtual bool IsString(const int index) const; + + /** + * @fn virtual bool Value::IsString(const std::string& key) const; + * + * @brief Checks if the value stored is a String. + * + * @param key The key. + * + * @return True if string, false if not. + */ + virtual bool IsString(const std::string& key) const; + + /** + * @fn virtual const std::string Value::GetString() const; + * + * @brief Returns the String value stored. + * + * @return The string. + */ + virtual const std::string GetString() const; + + /** + * @fn virtual const std::string Value::GetString(const int index) const; + * + * @brief Returns the String value stored. + * + * @param index Zero-based index of the values position. + * + * @return The string. + */ + virtual const std::string GetString(const int index) const; + + /** + * @fn virtual const std::string Value::GetString(const std::string& key) const; + * + * @brief Returns the String value stored. + * + * @param key The key. + * + * @return The string. + */ + virtual const std::string GetString(const std::string& key) const; + + /** + * @fn virtual void Value::SetString(const std::string& key, const std::string& value); + * + * @brief Sets the String value in the Object. + * + * @param key The key. + * @param value The value. + */ + virtual void SetString(const std::string& key, const std::string& value); + + /** + * @fn virtual bool Value::IsArray() const; + * + * @brief Checks if the value stored is an Array. + * + * @return True if array, false if not. + */ + virtual bool IsArray() const; + + /** + * @fn virtual bool Value::IsArray(const int index) const; + * + * @brief Checks if the value stored is an Array. + * + * @param index Zero-based index of the values position. + * + * @return True if array, false if not. + */ + virtual bool IsArray(const int index) const; + + /** + * @fn virtual bool Value::IsArray(const std::string& key) const; + * + * @brief Checks if the value stored is an Array. + * + * @param key The key. + * + * @return True if array, false if not. + */ + virtual bool IsArray(const std::string& key) const; + + /** + * @fn virtual const Array Value::GetArray() const; + * + * @brief Returns the Array value stored. + * + * @return The array. + */ + virtual const Array GetArray() const; + + /** + * @fn virtual const Array Value::GetArray(const int index) const; + * + * @brief Returns the Array value stored. + * + * @param index Zero-based index of the values position. + * + * @return The array. + */ + virtual const Array GetArray(const int index) const; + + /** + * @fn virtual const Array Value::GetArray(const std::string& key) const; + * + * @brief Returns the Array value stored. + * + * @param key The key. + * + * @return The array. + */ + virtual const Array GetArray(const std::string& key) const; + + /** + * @fn virtual void Value::SetArray(const std::string& key, Array& value); + * + * @brief Sets the Array value in the Object. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetArray(const std::string& key, Array& value); + + /** + * @fn virtual bool Value::IsObject() const; + * + * @brief Checks if the value stored is an Object. + * + * @return True if object, false if not. + */ + virtual bool IsObject() const; + + /** + * @fn virtual bool Value::IsObject(const int index) const; + * + * @brief Checks if the value stored is an Object. + * + * @param index Zero-based index of the values position. + * + * @return True if object, false if not. + */ + virtual bool IsObject(const int index) const; + + /** + * @fn virtual bool Value::IsObject(const std::string& key) const; + * + * @brief Checks if the value stored is an Object. + * + * @param key The key. + * + * @return True if object, false if not. + */ + virtual bool IsObject(const std::string& key) const; + + /** + * @fn virtual const Object Value::GetObject() const; + * + * @brief Returns the Object value stored. + * + * @return The object. + */ + virtual const Object GetObject() const; + + /** + * @fn virtual const Object Value::GetObject(const int index) const; + * + * @brief Returns the Object value stored. + * + * @param index Zero-based index of the values position. + * + * @return The object. + */ + virtual const Object GetObject(const int index) const; + + /** + * @fn virtual const Object Value::GetObject(const std::string& key) const; + * + * @brief Returns the Object value stored. + * + * @param key The key. + * + * @return The object. + */ + virtual const Object GetObject(const std::string& key) const; + + /** + * @fn virtual void Value::SetObject(const std::string& key, Object& value); + * + * @brief Sets the Object value in the Object. + * + * @param key The key. + * @param [in,out] value The value. + */ + virtual void SetObject(const std::string& key, Object& value); + + /** + * @fn operator Json::Value() const; + * + * @brief Implicit conversion operator to Json::Value. + * + * @return The result of the operation. + */ + operator Json::Value() const; + + /** + * @fn operator Json::Value& (); + * + * @brief Implicit conversion operator to Json::Value. + * + * @return The result of the operation. + */ + operator Json::Value& (); + + /** + * @fn operator const Json::Value& () const; + * + * @brief Implicit conversion operator to Json::Value. + * + * @return A const. + */ + operator const Json::Value& () const; + + /** + * @fn operator Json::Value* (); + * + * @brief Implicit conversion operator to Json::Value. + * + * @return The result of the operation. + */ + operator Json::Value* (); + + ///// Access an array element (zero based index ). + ///// If the array contains less than index element, then null value are + ///// inserted + ///// in the array so that its size is index+1. + ///// (You may need to say 'value[0u]' to get your compiler to distinguish + ///// this from the operator[] which takes a string.) + //Value operator[](int index); + + ///// Access an array element (zero based index ) + ///// (You may need to say 'value[0u]' to get your compiler to distinguish + ///// this from the operator[] which takes a string.) + //const Value operator[](int index) const; + + ///// Access an object value by name, create a null member if it does not exist. + ///// \note Because of our implementation, keys are limited to 2^30 -1 chars. + ///// Exceeding that will cause an exception. + //Value operator[](const char* key); + + ///// Access an object value by name, returns null if there is no member with + ///// that name. + //const Value operator[](const char* key) const; + + ///// Access an object value by name, create a null member if it does not exist. + ///// \param key may contain embedded nulls. + //Value operator[](const std::string& key); + + /** + * @fn Value& Value::operator=(Value other); + * + * @brief // Access an object value by name, returns null if there is no member with // that + * name. //\param key may contain embedded nulls. //const Value operator[](const + * std::string& key) + * const; + * + * @param other The other. + * + * @return A shallow copy of this object. + */ + Value& operator=(Value other); + + protected: + + /** @brief True to clear internal value. */ + bool clearInternalVal = true; + /** @brief The value pointer. */ + Json::Value* mValuePtr = nullptr; + }; + + /** + * @fn TR_UTIL_EXPORT std::ostream& operator<<(std::ostream&, const Value& root); + * + * @brief OStream operator. + * + * @author Maxim Serebrennik + * + * @param [in,out] parameter1 The first parameter. + * @param root The root. + * + * @return The shifted result. + */ + TR_UTIL_EXPORT std::ostream& operator<<(std::ostream&, const Value& root); } \ No newline at end of file diff --git a/include/trUtil/Logging/Log.h b/include/trUtil/Logging/Log.h index e03f7c2..dfe0110 100644 --- a/include/trUtil/Logging/Log.h +++ b/include/trUtil/Logging/Log.h @@ -1,583 +1,583 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author Erik Johnson -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - - -namespace trUtil::Logging -{ - // Fwd declaration - class LogWriter; - class LogTimeProvider; - class LogManager; - class LogImpl; - -/** -* @def TR_LOG_SOURCE -* -* @brief Helps making logging a little easier. However, if printf style -* logging is desired, you cannot use this macro. -*/ -#define TR_LOG_SOURCE __FILE__, __FUNCTION__, __LINE__ - -/** -* @def LOG_FULL(level, name, msg) -* -* @brief Logging macro to make error recording esier. -* -* @param level - Level of Logging (ERROR, WARNING, etc) -* @param name - Name of the Log file. -* @param msg - Message to log. -*/ -#define LOG_FULL(level, name, msg) \ - {\ - trUtil::Logging::Log& logger = trUtil::Logging::Log::GetInstance(name); \ - if (logger.IsLevelEnabled(level)) \ - {\ - std::ostringstream st;\ - st << msg;\ - logger.LogMessage(TR_LOG_SOURCE, st.str(), level); \ - }\ - }\ - -/** -* @def LOGN_D(name, msg) -* -* @brief Log a DEBUG message. -* -* @param name - Log File Name. -* @param msg - Message to log. -*/ -#define LOGN_D(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_DEBUG, name, msg) - -/** -* @def LOGN_I(name, msg) -* -* @brief Log an INFO message. -* -* @param name - Log File Name. -* @param msg - Message to log. -*/ -#define LOGN_I(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_INFO, name, msg) - -/** -* @def LOGN_W(name, msg) -* -* @brief Log a WARNING message. -* -* @param name - Log File Name. -* @param msg - Message to log. -*/ -#define LOGN_W(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_WARNING, name, msg) - -/** -* @def LOGN_E(name, msg) -* -* @brief Log an ERROR message. -* -* @param name - Log File Name. -* @param msg - Message to log. -*/ -#define LOGN_E(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_ERROR, name, msg) - -/** -* @def LOGN_A(name, msg) -* -* @brief Log an ALWAYS message. -* -* @param name - Log File Name. -* @param msg - Message to log. -*/ -#define LOGN_A(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_ALWAYS, name, msg) - -/** -* @def LOG_D(msg) -* -* @brief Log a DEBUG message. -* -* @param msg - Message to log. -*/ -#define LOG_D(msg) LOGN_D(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) - -/** -* @def LOG_I(msg) -* -* @brief Log an INFO message. -* -* @param msg - Message to log. -*/ -#define LOG_I(msg) LOGN_I(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) - -/** -* @def LOG_W(msg) -* -* @brief Log a WARNING message. -* -* @param msg - Message to log. -*/ -#define LOG_W(msg) LOGN_W(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) - -/** -* @def LOG_E(msg) -* -* @brief Log an ERROR message. -* -* @param msg - Message to log. -*/ -#define LOG_E(msg) LOGN_E(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) - -/** -* @def LOG_A(msg) -* -* @brief Log an ALWAYS message. -* -* @param msg - Message to log. -*/ -#define LOG_A(msg) LOGN_A(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) - -/** -* @def LOG_PRINT_TEST -* -* @brief Prints out a message to the Logger with a test string for every log level Only the -* currently enabled log levels will be visible The Log messages will only go to the -* enabled Log Writers This would be used for testing and development. -*/ -#define LOG_PRINT_TEST \ - LOG_D("Test Message") \ - LOG_I("Test Message") \ - LOG_W("Test Message") \ - LOG_E("Test Message") \ - LOG_A("Test Message") - - /** - * @class Log - * - * @brief Log class which the engine uses for all of its logging needs. The log file is - * formatted using html tags, therefore, any browser should display the log without - * any problems. - */ - class TR_UTIL_EXPORT Log : public osg::Referenced - { - public: - - /** - * @struct LogTestData - * - * @brief A data structure that is used for Unit Tests - */ - struct LogTestData - { - trUtil::Logging::LogLevel logLevel; /** @brief Log level. */ - trUtil::DateTime time; /** @brief Time of message. */ - unsigned frameNumber; /** @brief The frame number. */ - std::string logName; /** @brief The name of the Log instance (could be empty) */ - std::string file; /** @brief The source file of the message. */ - std::string method; /** @brief The calling method of the message. */ - int line; /** @brief The line number of the source code of the message. */ - std::string msg; /** @brief The message itself. */ - }; - - static const std::string LOG_DEFAULT_NAME; - - /** - * @fn void Log::LogMessage(const std::string& cppFile, const std::string& method, int line, const std::string& msg, LogLevel logLevel) const; - * - * @brief Logs a time-stamped message. - * - * @param cppFile The source file name which generated this message. - * @param method The calling method which generated this message. - * @param line The source code line number. - * @param msg The message to display. - * @param logLevel Level of message being displayed. (error,warning,info, etc) - */ - void LogMessage(const std::string& cppFile, const std::string& method, int line, const std::string& msg, LogLevel logLevel) const; - - /** - * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, ...) const; - * - * @brief Little more sophisticated method for logging messages. Allows for - * an unlimited number of parameters in a C-style printf syntax. - * - * @param logLevel - Type of message being displayed. (error,warning,info) - * @param source - String identifier of the source of the message. - * @param line - the line number. - * @param msg - Printf - style format string. - * @note - * Max length of the string to be printed is 2048 characters. - * @param ... Variable arguments providing additional information. - */ - void LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, ...) const; - - /** - * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const std::string& msg) const; - * - * @brief Little more sophisticated method for logging messages. Allows for - * an unlimited number of parameters in a C-style printf syntax. - * - * @param logLevel - Type of message being displayed. (error,warning,info) - * @param source - String identifier of the source of the message. - * @param line - the line number. - * @param msg - std::string that has been formatted. - * @note - * Max length of the string to be printed is 2048 characters. - */ - void LogMessage(LogLevel logLevel, const std::string& source, int line, const std::string& msg) const; - - /** - * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, va_list list) const; - * - * @brief Logs a time-stamped message. Takes a variable-argument list - * (va_list) that was created with va_start. - * - * @param logLevel - Type of message being displayed. (error,warning,info) - * @param source - String identifier of the source of the message. - * @param line - line number or negative for unknown. - * @param msg - Printf - style format string. - * @param list - va_list created with va_start. - * @note - * Max length of the string to be printed is 2048 characters. - */ - void LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, va_list list) const; - - /** - * @fn void Log::LogMessage(LogLevel logLevel, const std::string &source, const char *msg, ...) const; - * - * @brief Little more sophisticated method for logging messages. Allows for - * an unlimited number of parameters in a C-style printf syntax. - * - * @param logLevel - Type of message being displayed. (error,warning,info) - * @param source - String identifier of the source of the message. - * @param msg - Printf - style format string. - * @note - * Max length of the string to be printed is 2048 characters. - * @param ... Variable arguments providing additional information. - */ - void LogMessage(LogLevel logLevel, const std::string &source, const char *msg, ...) const; - - /** - * @fn void Log::LogHorizRule(); - * - * @brief Inserts a horizontal rule into the log file. - */ - void LogHorizRule(); - - /** - * @fn bool Log::IsLevelEnabled(LogLevel logLevel) const; - * - * @brief Queries if a level is enabled. - * - * @param logLevel the type of message to query about. - * - * @return true if log messages of the given level will be sent to the log output. - */ - bool IsLevelEnabled(LogLevel logLevel) const; - - /** - * @fn void Log::SetLogLevel(LogLevel logLevel); - * - * @brief Sets the lowest level of logging that will be logged. If the level in set to Debug, - * all messages will be sent. If the level is set error, only errors will be sent. - * - * @param logLevel the new logging level. - */ - void SetLogLevel(LogLevel logLevel); - - /** - * @fn LogLevel Log::GetLogLevel() const; - * - * @brief Gets log level. - * - * @return the lowest level of logging that will be logged. - */ - LogLevel GetLogLevel() const; - - /** - * @fn static const std::string Log::GetLogLevelString(LogLevel logLevel); - * - * @brief Gets log level string. - * - * @param logLevel The log level. - * - * @return a string version of a LogLevel. - */ - static const std::string GetLogLevelString(LogLevel logLevel); - - /** - * @fn static LogLevel Log::GetLogLevelForString(const std::string& levelString); - * - * @brief Gets log level for string. - * - * @param levelString The level string. - * - * @return the LogLevel matching a string or WARNING if there is no match. - */ - static LogLevel GetLogLevelForString(const std::string& levelString); - - /** - * @fn static Log& Log::GetInstance(const std::string& name = Log::LOG_DEFAULT_NAME); - * - * @brief Retrieve singleton instance of the log class for a give string name. WARNING: If the - * log instance does not exist yet, it will be created, but the creation is not thread - * safe. If you intend to use a log instance in multithreaded code, which I hope you do, - * make sure to create the instance ahead of time by calling get instance. - * - * @param name (Optional) The logger name. - * - * @return The instance. - */ - static Log& GetInstance(const std::string& name = Log::LOG_DEFAULT_NAME); - - /** - * @fn static void Log::SetDefaultLogLevel(LogLevel newLevel); - * - * @brief Sets the default LogLevel for new logs. - * - * @param newLevel The new level. - */ - static void SetDefaultLogLevel(LogLevel newLevel); - - /** - * @fn static void Log::SetAllLogLevels(LogLevel newLevel); - * - * @brief Set the LogLevel for all existing Log instances. - * - * @param newLevel The new level. - * - * @sa SetLogLevel() - */ - static void SetAllLogLevels(LogLevel newLevel); - - /** - * @fn static void Log::SetLogTimeProvider(LogTimeProvider* ltp); - * - * @brief This sets a Log time source. This allows another part of the system to update and - * provide both a time and a frame number, as needed. Otherwise, the time will be set - * on the log data every time log is called. - * - * @param [in,out] ltp If non-null, the ltp. - */ - static void SetLogTimeProvider(LogTimeProvider* ltp); - - /** - * @fn void Log::AddWriter(LogWriter& writer); - * - * @brief Add an writer that receives all log messages via callback. The TO_WRITER - * OutputStreamOptions bit must be set in order for LogWriters to get triggered. - * - * @sa RemoveWriter() - * - * @param [in,out] writer The LogWriter to register. - * - * @sa SetOutputStreamBit() - */ - void AddWriter(LogWriter& writer); - - /** - * @fn void Log::RemoveWriter(LogWriter& writer); - * - * @brief Remove an existing LogWriter from the container. - * - * @param [in,out] writer The LogWriter to remove. - * - * @sa AddWriter() - */ - void RemoveWriter(LogWriter& writer); - - /** @brief The log writer container. */ - using LogWriterContainer = std::vector>; - - /** - * @fn const LogWriterContainer& Log::GetWriters() const; - * - * @brief Get all registered LogWriters that are registered to receive log messages. - * - * @return The container of LogWriters (could be empty) - */ - const LogWriterContainer& GetWriters() const; - - /** - * @fn LogWriterContainer& Log::GetWriters(); - * - * @brief Get all registered LogWriters that are registered to receive log messages. - * - * @return The container of LogWriters (could be empty) - */ - LogWriterContainer& GetWriters(); - - /** - * @enum OutputStreamOptions - * - * @brief Values that represent output stream options. - */ - enum OutputStreamOptions - { - NO_OUTPUT = 0x00000000, /* Log messages don't get written to any device*/ - TO_FILE = 0x00000001, /* Log messages get sent to the output file*/ - TO_CONSOLE = 0x00000002,/* Log messages get sent to the console*/ - TO_WRITER = 0x00000004,/* Log messages get sent to all registered writers*/ - STANDARD = TO_FILE | TO_CONSOLE | TO_WRITER /* The default setting*/ - }; - - /** - * @fn void Log::SetOutputStreamBit(unsigned int option); - * - * @brief Tell the Log where to send output messages. The supplied parameter is a - * bitwise combination of OutputStreamOptions. The default is STANDARD, which directs - * messages to both the console and the output file. For example, to tell the Log to - * output to the file and console: \code - * trUtil::Logging::Log::GetInstance().SetOutputStreamBit(trUtil::Logging::Log::TO_FILE - * | trUtil::Logging::Log::TO_CONSOLE); - * \endcode \param option A bitwise combination of options. - * - * @param option The option. - */ - void SetOutputStreamBit(unsigned int option); - - /** - * @fn static void Log::SetAllOutputStreamBits(unsigned int option); - * - * @brief The same as above, but it sets the bits on ALL active log instances. - * - * @param option The option. - */ - static void SetAllOutputStreamBits(unsigned int option); - - /** - * @fn unsigned int Log::GetOutputStreamBit() const; - * - * @brief Get the currently defined output stream options. - * - * @return The output stream bit. - */ - unsigned int GetOutputStreamBit() const; - - /** - * @fn const std::string& Log::GetName() const; - * - * @brief Returns the name of this logger. - * - * @return The name. - */ - const std::string& GetName() const; - - /** - * @fn LogManager& Log::GetLogManagerRef(); - * - * @brief Returns a reference to the internal Log Manager. - * - * @return The log manager reference. - */ - LogManager& GetLogManagerRef(); - - /** - * @fn void Log::SetTestMode(bool state); - * - * @brief Enables the use of unit test mode which enables capturing of certain data. - * - * @param state True to state. - */ - void SetTestMode(bool state); - - /** - * @fn LogTestData* Log::GetLastLogData() const; - * - * @brief Gets the last log data that was in the queue for testing. - * - * @return Null if it fails, else the last log data. - */ - LogTestData* GetLastLogData() const; - - protected: - - /** - * @fn Log::Log(const std::string& name); - * - * @brief Opens the log file and writes the html header information. All new logs are created - * with the global default log level. - * - * @param name The name. - */ - Log(const std::string& name); - - /** - * @fn Log::~Log(); - * - * @brief Writes any closing html tags and closes the log file. - */ - ~Log(); - - private: - LogImpl* mImpl; - - bool mTestingMode = false; - mutable LogTestData mLogTestData; - }; - - /** - * @class LoggingOff - * - * @brief Scoped variable to turn off logging (except for always) for a block of code. This is - * useful for testing, and for temporary disabling of logging in certain areas. - */ - class TR_UTIL_EXPORT LoggingOff - { - public: - - /** - * @fn LoggingOff::LoggingOff(const std::string& name = Log::LOG_DEFAULT_NAME); - * - * @brief Constructor. - * - * @param name (Optional) The name. - */ - LoggingOff(const std::string& name = Log::LOG_DEFAULT_NAME); - - /** - * @fn LoggingOff::~LoggingOff(); - * - * @brief Destructor. - */ - ~LoggingOff(); - private: - trUtil::Logging::Log& mLog; - LogLevel mOldLevel; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author Erik Johnson +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + + +namespace trUtil::Logging +{ + // Fwd declaration + class LogWriter; + class LogTimeProvider; + class LogManager; + class LogImpl; + +/** +* @def TR_LOG_SOURCE +* +* @brief Helps making logging a little easier. However, if printf style +* logging is desired, you cannot use this macro. +*/ +#define TR_LOG_SOURCE __FILE__, __FUNCTION__, __LINE__ + +/** +* @def LOG_FULL(level, name, msg) +* +* @brief Logging macro to make error recording esier. +* +* @param level - Level of Logging (ERROR, WARNING, etc) +* @param name - Name of the Log file. +* @param msg - Message to log. +*/ +#define LOG_FULL(level, name, msg) \ + {\ + trUtil::Logging::Log& logger = trUtil::Logging::Log::GetInstance(name); \ + if (logger.IsLevelEnabled(level)) \ + {\ + std::ostringstream st;\ + st << msg;\ + logger.LogMessage(TR_LOG_SOURCE, st.str(), level); \ + }\ + }\ + +/** +* @def LOGN_D(name, msg) +* +* @brief Log a DEBUG message. +* +* @param name - Log File Name. +* @param msg - Message to log. +*/ +#define LOGN_D(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_DEBUG, name, msg) + +/** +* @def LOGN_I(name, msg) +* +* @brief Log an INFO message. +* +* @param name - Log File Name. +* @param msg - Message to log. +*/ +#define LOGN_I(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_INFO, name, msg) + +/** +* @def LOGN_W(name, msg) +* +* @brief Log a WARNING message. +* +* @param name - Log File Name. +* @param msg - Message to log. +*/ +#define LOGN_W(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_WARNING, name, msg) + +/** +* @def LOGN_E(name, msg) +* +* @brief Log an ERROR message. +* +* @param name - Log File Name. +* @param msg - Message to log. +*/ +#define LOGN_E(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_ERROR, name, msg) + +/** +* @def LOGN_A(name, msg) +* +* @brief Log an ALWAYS message. +* +* @param name - Log File Name. +* @param msg - Message to log. +*/ +#define LOGN_A(name, msg) LOG_FULL(trUtil::Logging::LogLevel::LOG_ALWAYS, name, msg) + +/** +* @def LOG_D(msg) +* +* @brief Log a DEBUG message. +* +* @param msg - Message to log. +*/ +#define LOG_D(msg) LOGN_D(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) + +/** +* @def LOG_I(msg) +* +* @brief Log an INFO message. +* +* @param msg - Message to log. +*/ +#define LOG_I(msg) LOGN_I(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) + +/** +* @def LOG_W(msg) +* +* @brief Log a WARNING message. +* +* @param msg - Message to log. +*/ +#define LOG_W(msg) LOGN_W(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) + +/** +* @def LOG_E(msg) +* +* @brief Log an ERROR message. +* +* @param msg - Message to log. +*/ +#define LOG_E(msg) LOGN_E(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) + +/** +* @def LOG_A(msg) +* +* @brief Log an ALWAYS message. +* +* @param msg - Message to log. +*/ +#define LOG_A(msg) LOGN_A(trUtil::Logging::Log::LOG_DEFAULT_NAME, msg) + +/** +* @def LOG_PRINT_TEST +* +* @brief Prints out a message to the Logger with a test string for every log level Only the +* currently enabled log levels will be visible The Log messages will only go to the +* enabled Log Writers This would be used for testing and development. +*/ +#define LOG_PRINT_TEST \ + LOG_D("Test Message") \ + LOG_I("Test Message") \ + LOG_W("Test Message") \ + LOG_E("Test Message") \ + LOG_A("Test Message") + + /** + * @class Log + * + * @brief Log class which the engine uses for all of its logging needs. The log file is + * formatted using html tags, therefore, any browser should display the log without + * any problems. + */ + class TR_UTIL_EXPORT Log : public osg::Referenced + { + public: + + /** + * @struct LogTestData + * + * @brief A data structure that is used for Unit Tests + */ + struct LogTestData + { + trUtil::Logging::LogLevel logLevel; /** @brief Log level. */ + trUtil::DateTime time; /** @brief Time of message. */ + unsigned frameNumber; /** @brief The frame number. */ + std::string logName; /** @brief The name of the Log instance (could be empty) */ + std::string file; /** @brief The source file of the message. */ + std::string method; /** @brief The calling method of the message. */ + int line; /** @brief The line number of the source code of the message. */ + std::string msg; /** @brief The message itself. */ + }; + + static const std::string LOG_DEFAULT_NAME; + + /** + * @fn void Log::LogMessage(const std::string& cppFile, const std::string& method, int line, const std::string& msg, LogLevel logLevel) const; + * + * @brief Logs a time-stamped message. + * + * @param cppFile The source file name which generated this message. + * @param method The calling method which generated this message. + * @param line The source code line number. + * @param msg The message to display. + * @param logLevel Level of message being displayed. (error,warning,info, etc) + */ + void LogMessage(const std::string& cppFile, const std::string& method, int line, const std::string& msg, LogLevel logLevel) const; + + /** + * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, ...) const; + * + * @brief Little more sophisticated method for logging messages. Allows for + * an unlimited number of parameters in a C-style printf syntax. + * + * @param logLevel - Type of message being displayed. (error,warning,info) + * @param source - String identifier of the source of the message. + * @param line - the line number. + * @param msg - Printf - style format string. + * @note + * Max length of the string to be printed is 2048 characters. + * @param ... Variable arguments providing additional information. + */ + void LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, ...) const; + + /** + * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const std::string& msg) const; + * + * @brief Little more sophisticated method for logging messages. Allows for + * an unlimited number of parameters in a C-style printf syntax. + * + * @param logLevel - Type of message being displayed. (error,warning,info) + * @param source - String identifier of the source of the message. + * @param line - the line number. + * @param msg - std::string that has been formatted. + * @note + * Max length of the string to be printed is 2048 characters. + */ + void LogMessage(LogLevel logLevel, const std::string& source, int line, const std::string& msg) const; + + /** + * @fn void Log::LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, va_list list) const; + * + * @brief Logs a time-stamped message. Takes a variable-argument list + * (va_list) that was created with va_start. + * + * @param logLevel - Type of message being displayed. (error,warning,info) + * @param source - String identifier of the source of the message. + * @param line - line number or negative for unknown. + * @param msg - Printf - style format string. + * @param list - va_list created with va_start. + * @note + * Max length of the string to be printed is 2048 characters. + */ + void LogMessage(LogLevel logLevel, const std::string& source, int line, const char* msg, va_list list) const; + + /** + * @fn void Log::LogMessage(LogLevel logLevel, const std::string &source, const char *msg, ...) const; + * + * @brief Little more sophisticated method for logging messages. Allows for + * an unlimited number of parameters in a C-style printf syntax. + * + * @param logLevel - Type of message being displayed. (error,warning,info) + * @param source - String identifier of the source of the message. + * @param msg - Printf - style format string. + * @note + * Max length of the string to be printed is 2048 characters. + * @param ... Variable arguments providing additional information. + */ + void LogMessage(LogLevel logLevel, const std::string &source, const char *msg, ...) const; + + /** + * @fn void Log::LogHorizRule(); + * + * @brief Inserts a horizontal rule into the log file. + */ + void LogHorizRule(); + + /** + * @fn bool Log::IsLevelEnabled(LogLevel logLevel) const; + * + * @brief Queries if a level is enabled. + * + * @param logLevel the type of message to query about. + * + * @return true if log messages of the given level will be sent to the log output. + */ + bool IsLevelEnabled(LogLevel logLevel) const; + + /** + * @fn void Log::SetLogLevel(LogLevel logLevel); + * + * @brief Sets the lowest level of logging that will be logged. If the level in set to Debug, + * all messages will be sent. If the level is set error, only errors will be sent. + * + * @param logLevel the new logging level. + */ + void SetLogLevel(LogLevel logLevel); + + /** + * @fn LogLevel Log::GetLogLevel() const; + * + * @brief Gets log level. + * + * @return the lowest level of logging that will be logged. + */ + LogLevel GetLogLevel() const; + + /** + * @fn static const std::string Log::GetLogLevelString(LogLevel logLevel); + * + * @brief Gets log level string. + * + * @param logLevel The log level. + * + * @return a string version of a LogLevel. + */ + static const std::string GetLogLevelString(LogLevel logLevel); + + /** + * @fn static LogLevel Log::GetLogLevelForString(const std::string& levelString); + * + * @brief Gets log level for string. + * + * @param levelString The level string. + * + * @return the LogLevel matching a string or WARNING if there is no match. + */ + static LogLevel GetLogLevelForString(const std::string& levelString); + + /** + * @fn static Log& Log::GetInstance(const std::string& name = Log::LOG_DEFAULT_NAME); + * + * @brief Retrieve singleton instance of the log class for a give string name. WARNING: If the + * log instance does not exist yet, it will be created, but the creation is not thread + * safe. If you intend to use a log instance in multithreaded code, which I hope you do, + * make sure to create the instance ahead of time by calling get instance. + * + * @param name (Optional) The logger name. + * + * @return The instance. + */ + static Log& GetInstance(const std::string& name = Log::LOG_DEFAULT_NAME); + + /** + * @fn static void Log::SetDefaultLogLevel(LogLevel newLevel); + * + * @brief Sets the default LogLevel for new logs. + * + * @param newLevel The new level. + */ + static void SetDefaultLogLevel(LogLevel newLevel); + + /** + * @fn static void Log::SetAllLogLevels(LogLevel newLevel); + * + * @brief Set the LogLevel for all existing Log instances. + * + * @param newLevel The new level. + * + * @sa SetLogLevel() + */ + static void SetAllLogLevels(LogLevel newLevel); + + /** + * @fn static void Log::SetLogTimeProvider(LogTimeProvider* ltp); + * + * @brief This sets a Log time source. This allows another part of the system to update and + * provide both a time and a frame number, as needed. Otherwise, the time will be set + * on the log data every time log is called. + * + * @param [in,out] ltp If non-null, the ltp. + */ + static void SetLogTimeProvider(LogTimeProvider* ltp); + + /** + * @fn void Log::AddWriter(LogWriter& writer); + * + * @brief Add an writer that receives all log messages via callback. The TO_WRITER + * OutputStreamOptions bit must be set in order for LogWriters to get triggered. + * + * @sa RemoveWriter() + * + * @param [in,out] writer The LogWriter to register. + * + * @sa SetOutputStreamBit() + */ + void AddWriter(LogWriter& writer); + + /** + * @fn void Log::RemoveWriter(LogWriter& writer); + * + * @brief Remove an existing LogWriter from the container. + * + * @param [in,out] writer The LogWriter to remove. + * + * @sa AddWriter() + */ + void RemoveWriter(LogWriter& writer); + + /** @brief The log writer container. */ + using LogWriterContainer = std::vector>; + + /** + * @fn const LogWriterContainer& Log::GetWriters() const; + * + * @brief Get all registered LogWriters that are registered to receive log messages. + * + * @return The container of LogWriters (could be empty) + */ + const LogWriterContainer& GetWriters() const; + + /** + * @fn LogWriterContainer& Log::GetWriters(); + * + * @brief Get all registered LogWriters that are registered to receive log messages. + * + * @return The container of LogWriters (could be empty) + */ + LogWriterContainer& GetWriters(); + + /** + * @enum OutputStreamOptions + * + * @brief Values that represent output stream options. + */ + enum OutputStreamOptions + { + NO_OUTPUT = 0x00000000, /* Log messages don't get written to any device*/ + TO_FILE = 0x00000001, /* Log messages get sent to the output file*/ + TO_CONSOLE = 0x00000002,/* Log messages get sent to the console*/ + TO_WRITER = 0x00000004,/* Log messages get sent to all registered writers*/ + STANDARD = TO_FILE | TO_CONSOLE | TO_WRITER /* The default setting*/ + }; + + /** + * @fn void Log::SetOutputStreamBit(unsigned int option); + * + * @brief Tell the Log where to send output messages. The supplied parameter is a + * bitwise combination of OutputStreamOptions. The default is STANDARD, which directs + * messages to both the console and the output file. For example, to tell the Log to + * output to the file and console: \code + * trUtil::Logging::Log::GetInstance().SetOutputStreamBit(trUtil::Logging::Log::TO_FILE + * | trUtil::Logging::Log::TO_CONSOLE); + * \endcode \param option A bitwise combination of options. + * + * @param option The option. + */ + void SetOutputStreamBit(unsigned int option); + + /** + * @fn static void Log::SetAllOutputStreamBits(unsigned int option); + * + * @brief The same as above, but it sets the bits on ALL active log instances. + * + * @param option The option. + */ + static void SetAllOutputStreamBits(unsigned int option); + + /** + * @fn unsigned int Log::GetOutputStreamBit() const; + * + * @brief Get the currently defined output stream options. + * + * @return The output stream bit. + */ + unsigned int GetOutputStreamBit() const; + + /** + * @fn const std::string& Log::GetName() const; + * + * @brief Returns the name of this logger. + * + * @return The name. + */ + const std::string& GetName() const; + + /** + * @fn LogManager& Log::GetLogManagerRef(); + * + * @brief Returns a reference to the internal Log Manager. + * + * @return The log manager reference. + */ + LogManager& GetLogManagerRef(); + + /** + * @fn void Log::SetTestMode(bool state); + * + * @brief Enables the use of unit test mode which enables capturing of certain data. + * + * @param state True to state. + */ + void SetTestMode(bool state); + + /** + * @fn LogTestData* Log::GetLastLogData() const; + * + * @brief Gets the last log data that was in the queue for testing. + * + * @return Null if it fails, else the last log data. + */ + LogTestData* GetLastLogData() const; + + protected: + + /** + * @fn Log::Log(const std::string& name); + * + * @brief Opens the log file and writes the html header information. All new logs are created + * with the global default log level. + * + * @param name The name. + */ + Log(const std::string& name); + + /** + * @fn Log::~Log(); + * + * @brief Writes any closing html tags and closes the log file. + */ + ~Log(); + + private: + LogImpl* mImpl; + + bool mTestingMode = false; + mutable LogTestData mLogTestData; + }; + + /** + * @class LoggingOff + * + * @brief Scoped variable to turn off logging (except for always) for a block of code. This is + * useful for testing, and for temporary disabling of logging in certain areas. + */ + class TR_UTIL_EXPORT LoggingOff + { + public: + + /** + * @fn LoggingOff::LoggingOff(const std::string& name = Log::LOG_DEFAULT_NAME); + * + * @brief Constructor. + * + * @param name (Optional) The name. + */ + LoggingOff(const std::string& name = Log::LOG_DEFAULT_NAME); + + /** + * @fn LoggingOff::~LoggingOff(); + * + * @brief Destructor. + */ + ~LoggingOff(); + private: + trUtil::Logging::Log& mLog; + LogLevel mOldLevel; + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogFile.h b/include/trUtil/Logging/LogFile.h index 86d4e80..e3cc3f5 100644 --- a/include/trUtil/Logging/LogFile.h +++ b/include/trUtil/Logging/LogFile.h @@ -1,94 +1,94 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author Erik Johnson -* @author David Guthrie -* @author Maxim Serebrennik -*/ - -#pragma once -#include - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogFile - * - * @brief A log file. - */ - class TR_UTIL_EXPORT LogFile - { - public: - /** @brief Log file default name. */ - static const std::string LOG_FILE_DEFAULT_NAME; - - /** - * @fn static void LogFile::SetFileName(const std::string& name); - * - * @brief Change the name of the log file (defaults to "TrueRealityLog.html") - * - * @param name The name. - */ - static void SetFileName(const std::string& name); - - /** - * @fn static const std::string LogFile::GetFileName(); - * - * @brief Get the current filename of the log file. - * - * @return The file name. - */ - static const std::string GetFileName(); - - /** - * @fn static void LogFile::SetTitle(const std::string& title); - * - * @brief Change the title string used in HTML. - * - * @param title The title. - */ - static void SetTitle(const std::string& title); - - /** - * @fn static const std::string& LogFile::GetTitle(); - * - * @brief Get the current HTML title string. - * - * @return The title. - */ - static const std::string& GetTitle(); - private: - static std::string mLogFileName; - static std::string mTitle; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author Erik Johnson +* @author David Guthrie +* @author Maxim Serebrennik +*/ + +#pragma once +#include + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogFile + * + * @brief A log file. + */ + class TR_UTIL_EXPORT LogFile + { + public: + /** @brief Log file default name. */ + static const std::string LOG_FILE_DEFAULT_NAME; + + /** + * @fn static void LogFile::SetFileName(const std::string& name); + * + * @brief Change the name of the log file (defaults to "TrueRealityLog.html") + * + * @param name The name. + */ + static void SetFileName(const std::string& name); + + /** + * @fn static const std::string LogFile::GetFileName(); + * + * @brief Get the current filename of the log file. + * + * @return The file name. + */ + static const std::string GetFileName(); + + /** + * @fn static void LogFile::SetTitle(const std::string& title); + * + * @brief Change the title string used in HTML. + * + * @param title The title. + */ + static void SetTitle(const std::string& title); + + /** + * @fn static const std::string& LogFile::GetTitle(); + * + * @brief Get the current HTML title string. + * + * @return The title. + */ + static const std::string& GetTitle(); + private: + static std::string mLogFileName; + static std::string mTitle; + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogLevel.h b/include/trUtil/Logging/LogLevel.h index 5208aa4..bcc50d8 100644 --- a/include/trUtil/Logging/LogLevel.h +++ b/include/trUtil/Logging/LogLevel.h @@ -1,94 +1,94 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author Erik Johnson -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** @brief String value for DEBUG Logging level. */ - const static std::string LOG_DEBUG_STR("Debug"); - - /** @brief String value for INFO Logging level. */ - const static std::string LOG_INFO_STR("Info"); - - /** @brief String value for WARNING Logging level. */ - const static std::string LOG_WARNING_STR("Warning"); - - /** @brief String value for ERROR Logging level. */ - const static std::string LOG_ERROR_STR("Error"); - - /** @brief String value for ALWAYS Logging level. */ - const static std::string LOG_ALWAYS_STR("Always"); - - /** - * @enum LogLevel - * - * @brief Identifies the Logging level for an individual Logger and Log message. - */ - enum TR_UTIL_EXPORT LogLevel - { - LOG_DEBUG, - LOG_INFO, - LOG_WARNING, - LOG_ERROR, - LOG_ALWAYS - }; - - /** - * @fn LogLevel LogLevelFromString(const std::string& levelString); - * - * @brief Logs level from string. - * - * @param levelString The level string. - * - * @return the LogLevel matching a string or WARNING if there is no match. The values that are - * checked against are the LogLevel Strings: LOG_DEBUG_STR, LOG_INFO_STR, - * LOG_WARNING_STR, LOG_ERROR_STR, LOG_ALWAYS_STR. - */ - TR_UTIL_EXPORT LogLevel LogLevelFromString(const std::string& levelString); - - /** - * @fn const std::string& LogLevelToString(LogLevel logLevel); - * - * @brief Logs level to string. - * - * @param logLevel The log level. - * - * @return a string version of a LogLevel. LOG_WARNING_STR is returned if there is no match. - */ - const TR_UTIL_EXPORT std::string& LogLevelToString(LogLevel logLevel); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author Erik Johnson +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** @brief String value for DEBUG Logging level. */ + const static std::string LOG_DEBUG_STR("Debug"); + + /** @brief String value for INFO Logging level. */ + const static std::string LOG_INFO_STR("Info"); + + /** @brief String value for WARNING Logging level. */ + const static std::string LOG_WARNING_STR("Warning"); + + /** @brief String value for ERROR Logging level. */ + const static std::string LOG_ERROR_STR("Error"); + + /** @brief String value for ALWAYS Logging level. */ + const static std::string LOG_ALWAYS_STR("Always"); + + /** + * @enum LogLevel + * + * @brief Identifies the Logging level for an individual Logger and Log message. + */ + enum TR_UTIL_EXPORT LogLevel + { + LOG_DEBUG, + LOG_INFO, + LOG_WARNING, + LOG_ERROR, + LOG_ALWAYS + }; + + /** + * @fn LogLevel LogLevelFromString(const std::string& levelString); + * + * @brief Logs level from string. + * + * @param levelString The level string. + * + * @return the LogLevel matching a string or WARNING if there is no match. The values that are + * checked against are the LogLevel Strings: LOG_DEBUG_STR, LOG_INFO_STR, + * LOG_WARNING_STR, LOG_ERROR_STR, LOG_ALWAYS_STR. + */ + TR_UTIL_EXPORT LogLevel LogLevelFromString(const std::string& levelString); + + /** + * @fn const std::string& LogLevelToString(LogLevel logLevel); + * + * @brief Logs level to string. + * + * @param logLevel The log level. + * + * @return a string version of a LogLevel. LOG_WARNING_STR is returned if there is no match. + */ + const TR_UTIL_EXPORT std::string& LogLevelToString(LogLevel logLevel); } \ No newline at end of file diff --git a/include/trUtil/Logging/LogManager.h b/include/trUtil/Logging/LogManager.h index 86c46c7..3fc7ad1 100644 --- a/include/trUtil/Logging/LogManager.h +++ b/include/trUtil/Logging/LogManager.h @@ -1,208 +1,208 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Matthew W. Campbell -* @author Erik Johnson -* @author David Guthrie -* @author Maxim Serebrennik -*/ -#pragma once -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogManager - * - * @brief Manager for logs. - */ - class LogManager : public osg::Referenced - { - public: - - /** - * @fn LogManager::LogManager(); - * - * @brief Default constructor. - */ - LogManager(); - - /** - * @fn LogManager::~LogManager(); - * - * @brief Destructor. - */ - ~LogManager(); - - /** - * @fn bool LogManager::AddInstance(const std::string& name, Log* log); - * - * @brief Stores a new Log instance in the manager. - * - * @param name The name. - * @param [in,out] log If non-null, the log. - * - * @return True if it succeeds, false if it fails. - */ - bool AddInstance(const std::string& name, Log* log); - - /** - * @fn Log* LogManager::GetInstance(const std::string& name); - * - * @brief Retrieves a stored Log instance. - * - * @param name - name of the Log to retrieve. - * - * @return Null if it fails, else the instance. - */ - Log* GetInstance(const std::string& name); - - /** - * @fn void LogManager::SetAllLogLevels(const LogLevel& newLevel); - * - * @brief Set the Log Level for all active Loggers. - * - * @param newLevel The new level. - */ - void SetAllLogLevels(const LogLevel& newLevel); - - /** - * @fn void LogManager::SetAllOutputStreamBits(unsigned int option); - * - * @brief Set the OutputStreamOptions bits for all stored Loggers The bits correspond to: - * NO_OUTPUT = 0x00000000, /// Log messages don't get written to any device - * TO_FILE = 0x00000001, /// Log messages get sent to the output file - * TO_CONSOLE = 0x00000002,/// Log messages get sent to the console - * TO_WRITER = 0x00000004,/// Log messages get sent to all registered writers - * STANDARD = TO_FILE | TO_CONSOLE | TO_WRITER /// The default setting. - * - * @param option The option. - */ - void SetAllOutputStreamBits(unsigned int option); - - /** - * @fn bool LogManager::IsLogTimeProviderValid() const; - * - * @brief Check if the Log Time Provider is currently valid in this manager. - * - * @return True if the log time provider is valid, false if not. - */ - bool IsLogTimeProviderValid() const; - - /** - * @fn void LogManager::ReOpenFile(); - * - * @brief Reopens the log file. This is used if a file failed to open, or file name has changed. - */ - void ReOpenFile(); - - /** - * @fn void LogManager::LogHorizRule(); - * - * @brief Writes out a horizontal line to the Log File. - */ - void LogHorizRule(); - - /** - * @fn void LogManager::LogMessageToFile(const LogWriter::LogData& logData); - * - * @brief Write out a message to the Log file. - * - * @param logData Information describing the log. - */ - void LogMessageToFile(const LogWriter::LogData& logData); - - /** - * @fn void LogManager::LogMessageToConsole(const LogWriter::LogData& logData); - * - * @brief Write out a message to the screen console. - * - * @param logData Information describing the log. - */ - void LogMessageToConsole(const LogWriter::LogData& logData); - - /** - * @fn void LogManager::SetLogTimeProvider(LogTimeProvider* ltp); - * - * @brief This sets a Log time source. This allows another part of the system to update and - * provide both a time and a frame number, as needed. Otherwise, the time will be set - * on the log data every time log is called. - * - * @param [in,out] ltp If non-null, the ltp. - */ - void SetLogTimeProvider(LogTimeProvider* ltp); - - /** - * @fn unsigned int LogManager::GetFrameNumber(); - * - * @brief Returns the stored frame number. - * - * @return The frame number. - */ - unsigned int GetFrameNumber(); - - /** - * @fn const trUtil::DateTime& LogManager::GetDateTime(); - * - * @brief Returns the reference to the stored DateTime object. - * - * @return The date time. - */ - const trUtil::DateTime& GetDateTime(); - - /** - * @fn OpenThreads::Mutex& LogManager::GetMutex(); - * - * @brief Returns the reference to an internal OpenThreads Mutex. - * - * @return The mutex. - */ - OpenThreads::Mutex& GetMutex(); - - private: - trUtil::HashMap > mInstances; - - osg::ref_ptr mLogWriterFile; ///writes to file - osg::ref_ptr mLogWriterConsole; ///writes to console - osg::observer_ptr mLogTimeProviderAsRef; - LogTimeProvider* mLogTimeProvider; - OpenThreads::Mutex mMutex; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Matthew W. Campbell +* @author Erik Johnson +* @author David Guthrie +* @author Maxim Serebrennik +*/ +#pragma once +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogManager + * + * @brief Manager for logs. + */ + class LogManager : public osg::Referenced + { + public: + + /** + * @fn LogManager::LogManager(); + * + * @brief Default constructor. + */ + LogManager(); + + /** + * @fn LogManager::~LogManager(); + * + * @brief Destructor. + */ + ~LogManager(); + + /** + * @fn bool LogManager::AddInstance(const std::string& name, Log* log); + * + * @brief Stores a new Log instance in the manager. + * + * @param name The name. + * @param [in,out] log If non-null, the log. + * + * @return True if it succeeds, false if it fails. + */ + bool AddInstance(const std::string& name, Log* log); + + /** + * @fn Log* LogManager::GetInstance(const std::string& name); + * + * @brief Retrieves a stored Log instance. + * + * @param name - name of the Log to retrieve. + * + * @return Null if it fails, else the instance. + */ + Log* GetInstance(const std::string& name); + + /** + * @fn void LogManager::SetAllLogLevels(const LogLevel& newLevel); + * + * @brief Set the Log Level for all active Loggers. + * + * @param newLevel The new level. + */ + void SetAllLogLevels(const LogLevel& newLevel); + + /** + * @fn void LogManager::SetAllOutputStreamBits(unsigned int option); + * + * @brief Set the OutputStreamOptions bits for all stored Loggers The bits correspond to: + * NO_OUTPUT = 0x00000000, /// Log messages don't get written to any device + * TO_FILE = 0x00000001, /// Log messages get sent to the output file + * TO_CONSOLE = 0x00000002,/// Log messages get sent to the console + * TO_WRITER = 0x00000004,/// Log messages get sent to all registered writers + * STANDARD = TO_FILE | TO_CONSOLE | TO_WRITER /// The default setting. + * + * @param option The option. + */ + void SetAllOutputStreamBits(unsigned int option); + + /** + * @fn bool LogManager::IsLogTimeProviderValid() const; + * + * @brief Check if the Log Time Provider is currently valid in this manager. + * + * @return True if the log time provider is valid, false if not. + */ + bool IsLogTimeProviderValid() const; + + /** + * @fn void LogManager::ReOpenFile(); + * + * @brief Reopens the log file. This is used if a file failed to open, or file name has changed. + */ + void ReOpenFile(); + + /** + * @fn void LogManager::LogHorizRule(); + * + * @brief Writes out a horizontal line to the Log File. + */ + void LogHorizRule(); + + /** + * @fn void LogManager::LogMessageToFile(const LogWriter::LogData& logData); + * + * @brief Write out a message to the Log file. + * + * @param logData Information describing the log. + */ + void LogMessageToFile(const LogWriter::LogData& logData); + + /** + * @fn void LogManager::LogMessageToConsole(const LogWriter::LogData& logData); + * + * @brief Write out a message to the screen console. + * + * @param logData Information describing the log. + */ + void LogMessageToConsole(const LogWriter::LogData& logData); + + /** + * @fn void LogManager::SetLogTimeProvider(LogTimeProvider* ltp); + * + * @brief This sets a Log time source. This allows another part of the system to update and + * provide both a time and a frame number, as needed. Otherwise, the time will be set + * on the log data every time log is called. + * + * @param [in,out] ltp If non-null, the ltp. + */ + void SetLogTimeProvider(LogTimeProvider* ltp); + + /** + * @fn unsigned int LogManager::GetFrameNumber(); + * + * @brief Returns the stored frame number. + * + * @return The frame number. + */ + unsigned int GetFrameNumber(); + + /** + * @fn const trUtil::DateTime& LogManager::GetDateTime(); + * + * @brief Returns the reference to the stored DateTime object. + * + * @return The date time. + */ + const trUtil::DateTime& GetDateTime(); + + /** + * @fn OpenThreads::Mutex& LogManager::GetMutex(); + * + * @brief Returns the reference to an internal OpenThreads Mutex. + * + * @return The mutex. + */ + OpenThreads::Mutex& GetMutex(); + + private: + trUtil::HashMap > mInstances; + + osg::ref_ptr mLogWriterConsole; ///writes to console + osg::ref_ptr mLogWriterFile; ///writes to file + osg::observer_ptr mLogTimeProviderAsRef; + LogTimeProvider* mLogTimeProvider; + OpenThreads::Mutex mMutex; + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogTimeProvider.h b/include/trUtil/Logging/LogTimeProvider.h index b2a4ef8..6e753e9 100644 --- a/include/trUtil/Logging/LogTimeProvider.h +++ b/include/trUtil/Logging/LogTimeProvider.h @@ -1,92 +1,92 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -*/ -#pragma once - -#include - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogTimeProvider - * - * @brief Interface class get the time for the logger. - * There is probably no need to override this yourself. It is provided as a means for - * other parts of the system to provide the time. - * - * @note The Log time provided does not extend osg::Referenced so that it can be used - * easily as an interface on other referenced classes, but the log code assumes - * that a dynamic_cast to reference will succeed. - * - * @sa AsReferenced - */ - class TR_UTIL_EXPORT LogTimeProvider - { - public: - - /** - * @fn virtual LogTimeProvider::~LogTimeProvider() - * - * @brief Destructor. - */ - virtual ~LogTimeProvider() {} - - /** - * @fn virtual const trUtil::DateTime& LogTimeProvider::GetDateTime() = 0; - * - * @brief Gets date time. - * - * @return The date time. - */ - virtual const trUtil::DateTime& GetDateTime() = 0; - - /** - * @fn virtual unsigned LogTimeProvider::GetFrameNumber() = 0; - * - * @brief Gets frame number. - * - * @return The frame number. - */ - virtual unsigned GetFrameNumber() = 0; - - /** - * @fn virtual osg::Referenced* LogTimeProvider::AsReferenced() = 0; - * - * @brief Converts this object to a referenced. - * - * @return Null if it fails, else a pointer to an osg::Referenced. - */ - virtual osg::Referenced* AsReferenced() = 0; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +*/ +#pragma once + +#include + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogTimeProvider + * + * @brief Interface class get the time for the logger. + * There is probably no need to override this yourself. It is provided as a means for + * other parts of the system to provide the time. + * + * @note The Log time provided does not extend osg::Referenced so that it can be used + * easily as an interface on other referenced classes, but the log code assumes + * that a dynamic_cast to reference will succeed. + * + * @sa AsReferenced + */ + class TR_UTIL_EXPORT LogTimeProvider + { + public: + + /** + * @fn virtual LogTimeProvider::~LogTimeProvider() + * + * @brief Destructor. + */ + virtual ~LogTimeProvider() {} + + /** + * @fn virtual const trUtil::DateTime& LogTimeProvider::GetDateTime() = 0; + * + * @brief Gets date time. + * + * @return The date time. + */ + virtual const trUtil::DateTime& GetDateTime() = 0; + + /** + * @fn virtual unsigned LogTimeProvider::GetFrameNumber() = 0; + * + * @brief Gets frame number. + * + * @return The frame number. + */ + virtual unsigned GetFrameNumber() = 0; + + /** + * @fn virtual osg::Referenced* LogTimeProvider::AsReferenced() = 0; + * + * @brief Converts this object to a referenced. + * + * @return Null if it fails, else a pointer to an osg::Referenced. + */ + virtual osg::Referenced* AsReferenced() = 0; + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogWriter.h b/include/trUtil/Logging/LogWriter.h index b485394..c4fb0dd 100644 --- a/include/trUtil/Logging/LogWriter.h +++ b/include/trUtil/Logging/LogWriter.h @@ -1,101 +1,101 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Erik Johnson -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogWriter - * - * @brief Interface class to receive messages from the Log. Derive and implement - * the LogMessage() method to support custom handling of Log messages. - * - * @sa trUtil::Logging::Log::AddWriter() - */ - class TR_UTIL_EXPORT LogWriter : public osg::Referenced - { - public: - - /** - * @struct LogData - * - * @brief A log data. - */ - struct LogData - { - /** - * @fn LogData() : logLevel(trUtil::Logging::LogLevel::LOG_DEBUG) , frameNumber() , line() - * - * @brief Default constructor. - */ - LogData() - : logLevel(trUtil::Logging::LogLevel::LOG_DEBUG) - , frameNumber() - , line(){}; - - trUtil::Logging::LogLevel logLevel; /** @brief Log level. */ - trUtil::DateTime time; /** @brief Time of message. */ - unsigned frameNumber; /** @brief The frame number. */ - std::string logName; /** @brief The name of the Log instance (could be empty) */ - std::string file; /** @brief The source file of the message. */ - std::string method; /** @brief The calling method of the message. */ - int line; /** @brief The line number of the source code of the message. */ - std::string msg; /** @brief The message itself. */ - }; - - /** - * @fn virtual void LogWriter::LogMessage(const LogData& logData) = 0; - * - * @brief Logs a message. - * - * @param logData Information describing the log. - */ - virtual void LogMessage(const LogData& logData) = 0; - - protected: - - /** - * @fn virtual LogWriter::~LogWriter() - * - * @brief Destructor. - */ - virtual ~LogWriter() {} - - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Erik Johnson +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogWriter + * + * @brief Interface class to receive messages from the Log. Derive and implement + * the LogMessage() method to support custom handling of Log messages. + * + * @sa trUtil::Logging::Log::AddWriter() + */ + class TR_UTIL_EXPORT LogWriter : public osg::Referenced + { + public: + + /** + * @struct LogData + * + * @brief A log data. + */ + struct LogData + { + /** + * @fn LogData() : logLevel(trUtil::Logging::LogLevel::LOG_DEBUG) , frameNumber() , line() + * + * @brief Default constructor. + */ + LogData() + : logLevel(trUtil::Logging::LogLevel::LOG_DEBUG) + , frameNumber() + , line(){}; + + trUtil::Logging::LogLevel logLevel; /** @brief Log level. */ + trUtil::DateTime time; /** @brief Time of message. */ + unsigned frameNumber; /** @brief The frame number. */ + std::string logName; /** @brief The name of the Log instance (could be empty) */ + std::string file; /** @brief The source file of the message. */ + std::string method; /** @brief The calling method of the message. */ + int line; /** @brief The line number of the source code of the message. */ + std::string msg; /** @brief The message itself. */ + }; + + /** + * @fn virtual void LogWriter::LogMessage(const LogData& logData) = 0; + * + * @brief Logs a message. + * + * @param logData Information describing the log. + */ + virtual void LogMessage(const LogData& logData) = 0; + + protected: + + /** + * @fn virtual LogWriter::~LogWriter() + * + * @brief Destructor. + */ + virtual ~LogWriter() {} + + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogWriterConsole.h b/include/trUtil/Logging/LogWriterConsole.h index 7bd0bd9..31ef904 100644 --- a/include/trUtil/Logging/LogWriterConsole.h +++ b/include/trUtil/Logging/LogWriterConsole.h @@ -1,76 +1,76 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Erik Johnson -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogWriterConsole - * - * @brief Specialized LogWriter used to display Log messages in the console window. - * - * @sa Log::AddObserver() - */ - class TR_UTIL_EXPORT LogWriterConsole : public Logging::LogWriter - { - public: - - /** - * @fn LogWriterConsole::LogWriterConsole(); - * - * @brief Default constructor. - */ - LogWriterConsole(); - - /** - * @fn virtual void LogWriterConsole::LogMessage(const LogData& logData); - * - * @brief Logs a message. - * - * @param logData Information describing the log. - */ - virtual void LogMessage(const LogData& logData); - - protected: - - /** - * @fn virtual LogWriterConsole::~LogWriterConsole(); - * - * @brief Destructor. - */ - virtual ~LogWriterConsole(); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Erik Johnson +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogWriterConsole + * + * @brief Specialized LogWriter used to display Log messages in the console window. + * + * @sa Log::AddObserver() + */ + class TR_UTIL_EXPORT LogWriterConsole : public Logging::LogWriter + { + public: + + /** + * @fn LogWriterConsole::LogWriterConsole(); + * + * @brief Default constructor. + */ + LogWriterConsole(); + + /** + * @fn virtual void LogWriterConsole::LogMessage(const LogData& logData); + * + * @brief Logs a message. + * + * @param logData Information describing the log. + */ + virtual void LogMessage(const LogData& logData); + + protected: + + /** + * @fn virtual LogWriterConsole::~LogWriterConsole(); + * + * @brief Destructor. + */ + virtual ~LogWriterConsole(); + }; } \ No newline at end of file diff --git a/include/trUtil/Logging/LogWriterFile.h b/include/trUtil/Logging/LogWriterFile.h index fd82922..8f85315 100644 --- a/include/trUtil/Logging/LogWriterFile.h +++ b/include/trUtil/Logging/LogWriterFile.h @@ -1,119 +1,119 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author Erik Johnson -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -#include -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::Logging -{ - /** - * @class LogWriterFile - * - * @brief A specialized LogWriter class that outputs Log messages to a file. - */ - class TR_UTIL_EXPORT LogWriterFile : public Logging::LogWriter - { - public: - - /** - * @brief The folder path that is appended to the User Data folder - * (PathUtil::GetUserTCDataFolder()) - */ - const static std::string DEFAULT_LOG_FOLDER; - - /** - * @fn LogWriterFile::LogWriterFile(); - * - * @brief Default constructor. - */ - LogWriterFile(); - - /** - * @fn void LogWriterFile::OpenFile(); - * - * @brief Opens the file. - */ - void OpenFile(); - - /** - * @fn virtual void LogWriterFile::LogMessage(const LogData& logData); - * - * @brief Logs a message. - * - * @param logData Information describing the log. - */ - virtual void LogMessage(const LogData& logData); - - /** - * @fn void LogWriterFile::LogHorizRule(); - * - * @brief Logs horiz rule. - */ - void LogHorizRule(); - - /** - * @fn bool LogWriterFile::IsOpenFailed(); - * - * @brief Returns true if opening a file failed. - * - * @return True if open failed, false if not. - */ - bool IsOpenFailed(); - - /** - * @fn void LogWriterFile::ResetOpenFail(); - * - * @brief A utility function to reset the OpenFailed flag after a file failure. - */ - void ResetOpenFail(); - - protected: - - /** - * @fn virtual LogWriterFile::~LogWriterFile(); - * - * @brief Destructor. - */ - virtual ~LogWriterFile(); - - private: - std::ofstream mLogFile; - bool mOpenFailed; - void TimeTag(std::string prefix); - void EndFile(); - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author Erik Johnson +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +#include +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::Logging +{ + /** + * @class LogWriterFile + * + * @brief A specialized LogWriter class that outputs Log messages to a file. + */ + class TR_UTIL_EXPORT LogWriterFile : public Logging::LogWriter + { + public: + + /** + * @brief The folder path that is appended to the User Data folder + * (PathUtil::GetUserTCDataFolder()) + */ + const static std::string DEFAULT_LOG_FOLDER; + + /** + * @fn LogWriterFile::LogWriterFile(); + * + * @brief Default constructor. + */ + LogWriterFile(); + + /** + * @fn void LogWriterFile::OpenFile(); + * + * @brief Opens the file. + */ + void OpenFile(); + + /** + * @fn virtual void LogWriterFile::LogMessage(const LogData& logData); + * + * @brief Logs a message. + * + * @param logData Information describing the log. + */ + virtual void LogMessage(const LogData& logData); + + /** + * @fn void LogWriterFile::LogHorizRule(); + * + * @brief Logs horiz rule. + */ + void LogHorizRule(); + + /** + * @fn bool LogWriterFile::IsOpenFailed(); + * + * @brief Returns true if opening a file failed. + * + * @return True if open failed, false if not. + */ + bool IsOpenFailed(); + + /** + * @fn void LogWriterFile::ResetOpenFail(); + * + * @brief A utility function to reset the OpenFailed flag after a file failure. + */ + void ResetOpenFail(); + + protected: + + /** + * @fn virtual LogWriterFile::~LogWriterFile(); + * + * @brief Destructor. + */ + virtual ~LogWriterFile(); + + private: + std::ofstream mLogFile; + bool mOpenFailed; + void TimeTag(std::string prefix); + void EndFile(); + }; } \ No newline at end of file diff --git a/include/trUtil/Math.h b/include/trUtil/Math.h index 9625c49..44c85b2 100644 --- a/include/trUtil/Math.h +++ b/include/trUtil/Math.h @@ -1,195 +1,195 @@ -/* - * True Reality Open Source Game and Simulation Engine - * Copyright © 2019 Acid Rain Studios LLC - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3.0 of the License, or (at your option) - * any later version. - * - * This library 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 Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * @author Maxim Serebrennik - */ - -#pragma once - -#include - -#include - -namespace trUtil::Math -{ - /** @brief / pi. */ - static const double PI = osg::PI; - /** @brief / pi/2. */ - static const double PI_OVER_2 = osg::PI_2; - /** @brief / pi/4. */ - static const double PI_OVER_4 = osg::PI_4; - /** @brief / pi*2. */ - static const double TWO_PI = trUtil::Math::PI * 2.0; - /** @brief / pi*4. */ - static const double FOUR_PI = trUtil::Math::PI * 4.0; - /** @brief / pi^(1/2) */ - static const double SQRT_PI = 1.77245385090551602729816748334; - /** @brief / e. */ - static const double E = 2.7182818284590452354; - /** @brief / ln(2) */ - static const double LOG_OF_2 = osg::LN_2; - /** @brief / 1/ln(2) */ - static const double INV_LOG_OF_2 = osg::INVLN_2; - /** @brief 1/PI. */ - static const double ONE_OVER_PI = 1.0 / trUtil::Math::PI; - /** @brief PI/180. */ - static const double ONE80_OVER_PI = (180.0*ONE_OVER_PI); - - /** - * @fn inline void SinCos(double x, double& sinVal, double& cosVal) - * - * @brief Takes a Value X and outputs its Sin and Cos by reference. - * - * @param x The x coordinate. - * @param [in,out] sinVal The sine value. - * @param [in,out] cosVal The cosine value. - */ - inline void SinCos(double x, double& sinVal, double& cosVal) - { - sinVal = sin(x); - cosVal = cos(x); - } - - /** - * @fn inline void SinCos(float x, float& sinVal, float& cosVal) - * - * @brief Takes a Value X and outputs its Sin and Cos by reference. - * - * @param x The x coordinate. - * @param [in,out] sinVal The sine value. - * @param [in,out] cosVal The cosine value. - */ - inline void SinCos(float x, float& sinVal, float& cosVal) - { - sinVal = sin(x); - cosVal = cos(x); // Might benefit from trig identities - } - - /** - * @fn inline double Deg2Rad(double degree) - * - * @brief Takes Degrees and converts them to Radians. - * - * @param degree The degree. - * - * @return A double. - */ - inline double Deg2Rad(double degree) - { - return osg::DegreesToRadians(degree); - } - - /** - * @fn inline float Deg2Rad(float degree) - * - * @brief Takes Degrees and converts them to Radians. - * - * @param degree The degree. - * - * @return A float. - */ - inline float Deg2Rad(float degree) - { - return osg::DegreesToRadians(degree); - } - - /** - * @fn inline double Rad2Deg(double radian) - * - * @brief Takes Radians and converts them to Degrees. - * - * @param radian The radian. - * - * @return A double. - */ - inline double Rad2Deg(double radian) - { - return osg::RadiansToDegrees(radian); - } - - /** - * @fn inline float Rad2Deg(float radian) - * - * @brief Takes Radians and converts them to Degrees. - * - * @param radian The radian. - * - * @return A float. - */ - inline float Rad2Deg(float radian) - { - return osg::RadiansToDegrees(radian); - } - - /** - * @fn inline double CheckState(double state) - * - * @brief Checks if State is = to 0, less then 0 or greater, and outputs -1, 0, 1. - * - * @param state The state. - * - * @return A double. - */ - inline double CheckState(double state) - { - if (state == 0) - return 0; - else if (state < 0) - return -1; - else - return 1; - } - - /** - * @fn inline float CheckState(float state) - * - * @brief Checks if State is = to 0, less then 0 or greater, and outputs -1, 0, 1. - * - * @param state The state. - * - * @return A float. - */ - inline float CheckState(float state) - { - if (state == 0) - return 0; - else if (state < 0) - return -1; - else - return 1; - } - - /** - * @fn inline T Lerp(T from, T to, T alpha) - * - * @brief Linear Interpolation function. - * - * @tparam T Generic type parameter. - * - * @param from Start point from which to interpret. - * @param to End point to which to interpret. - * @param alpha The alpha (0-1) - * - * @return A T. - */ - template - inline T Lerp(T from, T to, T alpha) - { - return from + ((to - from) * alpha); - } +/* + * True Reality Open Source Game and Simulation Engine + * Copyright © 2019 Acid Rain Studios LLC + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3.0 of the License, or (at your option) + * any later version. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @author Maxim Serebrennik + */ + +#pragma once + +#include + +#include + +namespace trUtil::Math +{ + /** @brief / pi. */ + static const double PI = osg::PI; + /** @brief / pi/2. */ + static const double PI_OVER_2 = osg::PI_2; + /** @brief / pi/4. */ + static const double PI_OVER_4 = osg::PI_4; + /** @brief / pi*2. */ + static const double TWO_PI = trUtil::Math::PI * 2.0; + /** @brief / pi*4. */ + static const double FOUR_PI = trUtil::Math::PI * 4.0; + /** @brief / pi^(1/2) */ + static const double SQRT_PI = 1.77245385090551602729816748334; + /** @brief / e. */ + static const double E = 2.7182818284590452354; + /** @brief / ln(2) */ + static const double LOG_OF_2 = osg::LN_2; + /** @brief / 1/ln(2) */ + static const double INV_LOG_OF_2 = osg::INVLN_2; + /** @brief 1/PI. */ + static const double ONE_OVER_PI = 1.0 / trUtil::Math::PI; + /** @brief PI/180. */ + static const double ONE80_OVER_PI = (180.0*ONE_OVER_PI); + + /** + * @fn inline void SinCos(double x, double& sinVal, double& cosVal) + * + * @brief Takes a Value X and outputs its Sin and Cos by reference. + * + * @param x The x coordinate. + * @param [in,out] sinVal The sine value. + * @param [in,out] cosVal The cosine value. + */ + inline void SinCos(double x, double& sinVal, double& cosVal) + { + sinVal = sin(x); + cosVal = cos(x); + } + + /** + * @fn inline void SinCos(float x, float& sinVal, float& cosVal) + * + * @brief Takes a Value X and outputs its Sin and Cos by reference. + * + * @param x The x coordinate. + * @param [in,out] sinVal The sine value. + * @param [in,out] cosVal The cosine value. + */ + inline void SinCos(float x, float& sinVal, float& cosVal) + { + sinVal = sin(x); + cosVal = cos(x); // Might benefit from trig identities + } + + /** + * @fn inline double Deg2Rad(double degree) + * + * @brief Takes Degrees and converts them to Radians. + * + * @param degree The degree. + * + * @return A double. + */ + inline double Deg2Rad(double degree) + { + return osg::DegreesToRadians(degree); + } + + /** + * @fn inline float Deg2Rad(float degree) + * + * @brief Takes Degrees and converts them to Radians. + * + * @param degree The degree. + * + * @return A float. + */ + inline float Deg2Rad(float degree) + { + return osg::DegreesToRadians(degree); + } + + /** + * @fn inline double Rad2Deg(double radian) + * + * @brief Takes Radians and converts them to Degrees. + * + * @param radian The radian. + * + * @return A double. + */ + inline double Rad2Deg(double radian) + { + return osg::RadiansToDegrees(radian); + } + + /** + * @fn inline float Rad2Deg(float radian) + * + * @brief Takes Radians and converts them to Degrees. + * + * @param radian The radian. + * + * @return A float. + */ + inline float Rad2Deg(float radian) + { + return osg::RadiansToDegrees(radian); + } + + /** + * @fn inline double CheckState(double state) + * + * @brief Checks if State is = to 0, less then 0 or greater, and outputs -1, 0, 1. + * + * @param state The state. + * + * @return A double. + */ + inline double CheckState(double state) + { + if (state == 0) + return 0; + else if (state < 0) + return -1; + else + return 1; + } + + /** + * @fn inline float CheckState(float state) + * + * @brief Checks if State is = to 0, less then 0 or greater, and outputs -1, 0, 1. + * + * @param state The state. + * + * @return A float. + */ + inline float CheckState(float state) + { + if (state == 0) + return 0; + else if (state < 0) + return -1; + else + return 1; + } + + /** + * @fn inline T Lerp(T from, T to, T alpha) + * + * @brief Linear Interpolation function. + * + * @tparam T Generic type parameter. + * + * @param from Start point from which to interpret. + * @param to End point to which to interpret. + * @param alpha The alpha (0-1) + * + * @return A T. + */ + template + inline T Lerp(T from, T to, T alpha) + { + return from + ((to - from) * alpha); + } } \ No newline at end of file diff --git a/include/trUtil/PathUtils.h b/include/trUtil/PathUtils.h index ef98db6..46b6d23 100644 --- a/include/trUtil/PathUtils.h +++ b/include/trUtil/PathUtils.h @@ -1,444 +1,444 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -* @author John K. Grant -* @author William E. Johnson II -* @author Chris Osborn -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include -#include - - -namespace trUtil::PathUtils -{ -#ifdef TR_APPLE - const static std::string DEFAULT_TR_FOLDER("/TrueReality"); -#elif defined(TR_WIN) - const static std::string DEFAULT_TR_FOLDER("\\TrueReality"); -#else - const static std::string DEFAULT_TR_FOLDER("/.trueReality"); -#endif - const static std::string DATA_PATH_DEFAULT("/Data"); - const static std::string STATIC_MESHES_PATH("/StaticMeshes"); - const static std::string SKELETAL_MESHES_PATH("/SkeletalMeshes"); - const static std::string SOUNDS_PATH("/Sounds"); - const static std::string PARTICLES_PATH("/Particles"); - const static std::string TEXTURES_PATH("/Textures"); - const static std::string TERRAINS_PATH("/Terrains"); - const static std::string SHADERS_PATH("/Shaders"); - const static std::string GUI_PATH("/GUI"); - const static std::string CONFIG_PATH("/Config"); - - /** - * @fn TR_UTIL_EXPORT std::string GetUserHomeDirectory(); - * - * @brief Get the USER Home directory. - * - * @return The home directory. - */ - TR_UTIL_EXPORT std::string GetUserHomeDirectory(); - - /** - * @fn std::string GetUserDataPath(); - * - * @brief Get the folder where TR will save and store User data files It is MyDocuments on - * Windows and the same as GetHomeDirectory() - * on Linux and Apple If TR_USER_DATA Environmental variable is defined, it will return - * the path in TR_USER_DATA. - * - * @return The user data path. - */ - TR_UTIL_EXPORT std::string GetUserDataPath(); - - /** - * @fn std::string GetStaticMeshesPath(); - * - * @brief Gets static meshes path. - * - * @return The static meshes path. - */ - TR_UTIL_EXPORT std::string GetStaticMeshesPath(); - - /** - * @fn std::string GetSkeletalMeshesPath(); - * - * @brief Gets skeletal meshes path. - * - * @return The skeletal meshes path. - */ - TR_UTIL_EXPORT std::string GetSkeletalMeshesPath(); - - /** - * @fn std::string GetSoundsPath(); - * - * @brief Gets sounds path. - * - * @return The sounds path. - */ - TR_UTIL_EXPORT std::string GetSoundsPath(); - - /** - * @fn std::string GetParticlesPath(); - * - * @brief Gets particles path. - * - * @return The particles path. - */ - TR_UTIL_EXPORT std::string GetParticlesPath(); - - /** - * @fn std::string GetTexturesPath(); - * - * @brief Gets textures path. - * - * @return The textures path. - */ - TR_UTIL_EXPORT std::string GetTexturesPath(); - - /** - * @fn std::string GetTerrainsPath(); - * - * @brief Gets terrain path. - * - * @return The terrain path. - */ - TR_UTIL_EXPORT std::string GetTerrainsPath(); - - /** - * @fn std::string GetShadersPath(); - * - * @brief Gets shaders path. - * - * @return The shaders path. - */ - TR_UTIL_EXPORT std::string GetShadersPath(); - - /** - * @fn std::string GetGUIPath(); - * - * @brief Gets graphical user interface path. - * - * @return The graphical user interface path. - */ - TR_UTIL_EXPORT std::string GetGUIPath(); - - /** - * @fn std::string GetConfigPath(); - * - * @brief Gets configuration path. - * - * @return The configuration path. - */ - TR_UTIL_EXPORT std::string GetConfigPath(); - - /** - * @fn std::string GetUserStaticMeshesPath(); - * - * @brief Gets user static meshes path. - * - * @return The user static meshes path. - */ - TR_UTIL_EXPORT std::string GetUserStaticMeshesPath(); - - /** - * @fn std::string GetUserSkeletalMeshesPath(); - * - * @brief Gets user skeletal meshes path. - * - * @return The user skeletal meshes path. - */ - TR_UTIL_EXPORT std::string GetUserSkeletalMeshesPath(); - - /** - * @fn std::string GetUserSoundsPath(); - * - * @brief Gets user sounds path. - * - * @return The user sounds path. - */ - TR_UTIL_EXPORT std::string GetUserSoundsPath(); - - /** - * @fn std::string GetUserParticlesPath(); - * - * @brief Gets user particles path. - * - * @return The user particles path. - */ - TR_UTIL_EXPORT std::string GetUserParticlesPath(); - - /** - * @fn std::string GetUserTexturesPath(); - * - * @brief Gets user textures path. - * - * @return The user textures path. - */ - TR_UTIL_EXPORT std::string GetUserTexturesPath(); - - /** - * @fn std::string GetUserTerrainsPath(); - * - * @brief Gets user terrain path. - * - * @return The user terrain path. - */ - TR_UTIL_EXPORT std::string GetUserTerrainsPath(); - - /** - * @fn std::string GetUserShadersPath(); - * - * @brief Gets user shaders path. - * - * @return The user shaders path. - */ - TR_UTIL_EXPORT std::string GetUserShadersPath(); - - /** - * @fn std::string GetUserGUIPath(); - * - * @brief Gets user graphical user interface path. - * - * @return The user graphical user interface path. - */ - TR_UTIL_EXPORT std::string GetUserGUIPath(); - - /** - * @fn std::string GetUserConfigPath(); - * - * @brief Gets user configuration path. - * - * @return The user configuration path. - */ - TR_UTIL_EXPORT std::string GetUserConfigPath(); - - /** - * @fn std::string GetLogPath(); - * - * @brief Get the folder where TR will save and store the log files It is the same as - * GetUserDataPath() by default, unless the variable TR_LOG_PATH is set. - * - * @return The log path. - */ - TR_UTIL_EXPORT std::string GetLogPath(); - - /** - * @fn void SetDataFilePathList(const std::string& pathList); - * - * @brief Set the list of data file paths. - * - * @param pathList List of paths. - */ - TR_UTIL_EXPORT void SetDataFilePathList(const std::string& pathList); - - /** - * @fn std::string GetDataFilePathList(); - * - * @brief Get the list of data file paths. - * - * @return The data file path list. - */ - TR_UTIL_EXPORT std::string GetDataFilePathList(); - - /** - * @fn std::string GetDataPath(); - * - * @brief Get the TR Data file path. This comes directly from the environment variable - * "TR_DATA", if it wasn't overwritten by the user. If the environment variable is not - * set, TR_ROOT/Data directory will be returned. - * - * @todo need to decide how paths will be handled. We need to decide if TR_DATA is a list or a - * single item. - * - * @return The data path. - */ - TR_UTIL_EXPORT std::string GetDataPath(); - - /** - * @fn void SetDataPath(std::string& path); - * - * @brief Overwrites the Data path. If this is set, TR will ignore the TR_DATA variable and use - * the passed in value instead. - * - * @param [in,out] path Full pathname of the file. - */ - TR_UTIL_EXPORT void SetDataPath(std::string& path); - - /** - * @fn void CreateDataPathTree(); - * - * @brief Creates all the folders in the Data (TR_DATA) folder, that includes Maps, GUI, Shaders, - * StaticMeshes, etc etc. - */ - TR_UTIL_EXPORT void CreateDataPathTree(); - - /** - * @fn void CreateUserDataPathTree(); - * - * @brief Creates all the folders in the Data (TR_USER_DATA) folder, that includes Maps, GUI, - * Shaders, StaticMeshes, etc etc. - */ - TR_UTIL_EXPORT void CreateUserDataPathTree(); - - /** - * @fn void CreateDataPathTrees(); - * - * @brief Convenience function that calls CreateDataPathTree() and CreateUserDataPathTree(); - */ - TR_UTIL_EXPORT void CreateDataPathTrees(); - - /** - * @fn std::string GetRootPath(); - * - * @brief Get the root path to the engine (equivalent to the TR_ROOT environment) - * If the TR_ROOT environment is not set, the local directory will be returned. - * - * @return The root path. - */ - TR_UTIL_EXPORT std::string GetRootPath(); - - /** - * @fn std::string GetEnvironment(const std::string& env); - * - * @brief Convenience method to get the supplied environment variable. - * - * @param env The environment. - * - * @return The environment. - */ - TR_UTIL_EXPORT std::string GetEnvironment(const std::string& env); - - /** - * @fn bool IsEnvironment(const std::string& env); - * - * @brief Is the supplied environment variable defined? - * - * @param env The environment. - * - * @return True if environment, false if not. - */ - TR_UTIL_EXPORT bool IsEnvironment(const std::string& env); - - /** - * @fn void SetEnvironment(const std::string& name, const std::string& value); - * - * @brief Sets an environment variable. - * - * @param name the name of the variable to set. - * @param value the value of the environment variable to set. - */ - TR_UTIL_EXPORT void SetEnvironment(const std::string& name, const std::string& value); - - /** - * @fn std::string FindFile(const std::string& fileName); - * - * @brief Searches for a file in the list of paths found by calling GetDataFilePathList() - * - * @param fileName Can be a single filename or a path and file name relative to the current - * engines data path list. - * - * @return The full path to the file requested or empty string if it's not found. - */ - TR_UTIL_EXPORT std::string FindFile(const std::string& fileName); - - /** - * @fn std::string FindFile(const std::string& fileName, std::vector paths, bool caseInsensitive = true); - * - * @brief Searches a given path list for a file name. - * - * @param fileName Can be a single filename or a path and file name relative to the - * current engines data path list. - * @param paths the list of file paths to search. - * @param caseInsensitive (Optional) If the search should be case insensitive. This only works - * around case-sensitive file systems, it cannot not make a search fail - * if the case is wrong on a case insensitive one and one sets it to - * false. - * - * @return The found file. - */ - TR_UTIL_EXPORT std::string FindFile(const std::string& fileName, std::vector paths, bool caseInsensitive = true); - -#ifdef TR_APPLE - - /** - * @fn std::string GetBundleResourcesPath(); - * - * @brief Gets bundle resources path. - * - * @return the resource path inside the current application bundle. This is used internally, and - * this api is subject to change. - */ - std::string GetBundleResourcesPath(); - - /** - * @fn std::string GetBundlePlugInsPath(); - * - * @brief Gets bundle plug insert path. - * - * @return the plugins path inside the current application bundle. This is used internally, and - * this api is subject to change. - */ - std::string GetBundlePlugInsPath(); - - /** - * @fn std::string GetBundlePath(); - * - * @brief Gets bundle path. - * - * @return the application bundle path. This is used internally, and this api is subject to - * change. - */ - std::string GetBundlePath(); - - /** - * @fn void RemovePSNCommandLineOption(int& argc, char**& argv); - * - * @brief Removes the psn command line option. - * - * @param [in,out] argc The argc. - * @param [in,out] argv [in,out] If non-null, the argv. - */ - void RemovePSNCommandLineOption(int& argc, char**& argv); -#else - - /** - * @fn inline void RemovePSNCommandLineOption(int& argc, char**& argv) - * - * @brief Removes the psn command line option. - * - * @param [in,out] argc The argc. - * @param [in,out] argv [in,out] If non-null, the argv. - */ - inline void RemovePSNCommandLineOption(int& argc, char**& argv) {} -#endif -} - +/* +* True Reality Open Source Game and Simulation Engine +* Copyright � 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +* @author John K. Grant +* @author William E. Johnson II +* @author Chris Osborn +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include +#include + + +namespace trUtil::PathUtils +{ +#ifdef TR_APPLE + const static std::string DEFAULT_TR_FOLDER("/TrueReality"); +#elif defined(TR_WIN) + const static std::string DEFAULT_TR_FOLDER("\\TrueReality"); +#else + const static std::string DEFAULT_TR_FOLDER("/.trueReality"); +#endif + const static std::string DATA_PATH_DEFAULT("/Data"); + const static std::string STATIC_MESHES_PATH("/StaticMeshes"); + const static std::string SKELETAL_MESHES_PATH("/SkeletalMeshes"); + const static std::string SOUNDS_PATH("/Sounds"); + const static std::string PARTICLES_PATH("/Particles"); + const static std::string TEXTURES_PATH("/Textures"); + const static std::string TERRAINS_PATH("/Terrains"); + const static std::string SHADERS_PATH("/Shaders"); + const static std::string GUI_PATH("/GUI"); + const static std::string CONFIG_PATH("/Config"); + + /** + * @fn TR_UTIL_EXPORT std::string GetUserHomeDirectory(); + * + * @brief Get the USER Home directory. + * + * @return The home directory. + */ + TR_UTIL_EXPORT std::string GetUserHomeDirectory(); + + /** + * @fn std::string GetUserDataPath(); + * + * @brief Get the folder where TR will save and store User data files It is MyDocuments on + * Windows and the same as GetHomeDirectory() + * on Linux and Apple If TR_USER_DATA Environmental variable is defined, it will return + * the path in TR_USER_DATA. + * + * @return The user data path. + */ + TR_UTIL_EXPORT std::string GetUserDataPath(); + + /** + * @fn std::string GetStaticMeshesPath(); + * + * @brief Gets static meshes path. + * + * @return The static meshes path. + */ + TR_UTIL_EXPORT std::string GetStaticMeshesPath(); + + /** + * @fn std::string GetSkeletalMeshesPath(); + * + * @brief Gets skeletal meshes path. + * + * @return The skeletal meshes path. + */ + TR_UTIL_EXPORT std::string GetSkeletalMeshesPath(); + + /** + * @fn std::string GetSoundsPath(); + * + * @brief Gets sounds path. + * + * @return The sounds path. + */ + TR_UTIL_EXPORT std::string GetSoundsPath(); + + /** + * @fn std::string GetParticlesPath(); + * + * @brief Gets particles path. + * + * @return The particles path. + */ + TR_UTIL_EXPORT std::string GetParticlesPath(); + + /** + * @fn std::string GetTexturesPath(); + * + * @brief Gets textures path. + * + * @return The textures path. + */ + TR_UTIL_EXPORT std::string GetTexturesPath(); + + /** + * @fn std::string GetTerrainsPath(); + * + * @brief Gets terrain path. + * + * @return The terrain path. + */ + TR_UTIL_EXPORT std::string GetTerrainsPath(); + + /** + * @fn std::string GetShadersPath(); + * + * @brief Gets shaders path. + * + * @return The shaders path. + */ + TR_UTIL_EXPORT std::string GetShadersPath(); + + /** + * @fn std::string GetGUIPath(); + * + * @brief Gets graphical user interface path. + * + * @return The graphical user interface path. + */ + TR_UTIL_EXPORT std::string GetGUIPath(); + + /** + * @fn std::string GetConfigPath(); + * + * @brief Gets configuration path. + * + * @return The configuration path. + */ + TR_UTIL_EXPORT std::string GetConfigPath(); + + /** + * @fn std::string GetUserStaticMeshesPath(); + * + * @brief Gets user static meshes path. + * + * @return The user static meshes path. + */ + TR_UTIL_EXPORT std::string GetUserStaticMeshesPath(); + + /** + * @fn std::string GetUserSkeletalMeshesPath(); + * + * @brief Gets user skeletal meshes path. + * + * @return The user skeletal meshes path. + */ + TR_UTIL_EXPORT std::string GetUserSkeletalMeshesPath(); + + /** + * @fn std::string GetUserSoundsPath(); + * + * @brief Gets user sounds path. + * + * @return The user sounds path. + */ + TR_UTIL_EXPORT std::string GetUserSoundsPath(); + + /** + * @fn std::string GetUserParticlesPath(); + * + * @brief Gets user particles path. + * + * @return The user particles path. + */ + TR_UTIL_EXPORT std::string GetUserParticlesPath(); + + /** + * @fn std::string GetUserTexturesPath(); + * + * @brief Gets user textures path. + * + * @return The user textures path. + */ + TR_UTIL_EXPORT std::string GetUserTexturesPath(); + + /** + * @fn std::string GetUserTerrainsPath(); + * + * @brief Gets user terrain path. + * + * @return The user terrain path. + */ + TR_UTIL_EXPORT std::string GetUserTerrainsPath(); + + /** + * @fn std::string GetUserShadersPath(); + * + * @brief Gets user shaders path. + * + * @return The user shaders path. + */ + TR_UTIL_EXPORT std::string GetUserShadersPath(); + + /** + * @fn std::string GetUserGUIPath(); + * + * @brief Gets user graphical user interface path. + * + * @return The user graphical user interface path. + */ + TR_UTIL_EXPORT std::string GetUserGUIPath(); + + /** + * @fn std::string GetUserConfigPath(); + * + * @brief Gets user configuration path. + * + * @return The user configuration path. + */ + TR_UTIL_EXPORT std::string GetUserConfigPath(); + + /** + * @fn std::string GetLogPath(); + * + * @brief Get the folder where TR will save and store the log files It is the same as + * GetUserDataPath() by default, unless the variable TR_LOG_PATH is set. + * + * @return The log path. + */ + TR_UTIL_EXPORT std::string GetLogPath(); + + /** + * @fn void SetDataFilePathList(const std::string& pathList); + * + * @brief Set the list of data file paths. + * + * @param pathList List of paths. + */ + TR_UTIL_EXPORT void SetDataFilePathList(const std::string& pathList); + + /** + * @fn std::string GetDataFilePathList(); + * + * @brief Get the list of data file paths. + * + * @return The data file path list. + */ + TR_UTIL_EXPORT std::string GetDataFilePathList(); + + /** + * @fn std::string GetDataPath(); + * + * @brief Get the TR Data file path. This comes directly from the environment variable + * "TR_DATA", if it wasn't overwritten by the user. If the environment variable is not + * set, TR_ROOT/Data directory will be returned. + * + * @todo need to decide how paths will be handled. We need to decide if TR_DATA is a list or a + * single item. + * + * @return The data path. + */ + TR_UTIL_EXPORT std::string GetDataPath(); + + /** + * @fn void SetDataPath(std::string& path); + * + * @brief Overwrites the Data path. If this is set, TR will ignore the TR_DATA variable and use + * the passed in value instead. + * + * @param [in,out] path Full pathname of the file. + */ + TR_UTIL_EXPORT void SetDataPath(std::string& path); + + /** + * @fn void CreateDataPathTree(); + * + * @brief Creates all the folders in the Data (TR_DATA) folder, that includes Maps, GUI, Shaders, + * StaticMeshes, etc etc. + */ + TR_UTIL_EXPORT void CreateDataPathTree(); + + /** + * @fn void CreateUserDataPathTree(); + * + * @brief Creates all the folders in the Data (TR_USER_DATA) folder, that includes Maps, GUI, + * Shaders, StaticMeshes, etc etc. + */ + TR_UTIL_EXPORT void CreateUserDataPathTree(); + + /** + * @fn void CreateDataPathTrees(); + * + * @brief Convenience function that calls CreateDataPathTree() and CreateUserDataPathTree(); + */ + TR_UTIL_EXPORT void CreateDataPathTrees(); + + /** + * @fn std::string GetRootPath(); + * + * @brief Get the root path to the engine (equivalent to the TR_ROOT environment) + * If the TR_ROOT environment is not set, the local directory will be returned. + * + * @return The root path. + */ + TR_UTIL_EXPORT std::string GetRootPath(); + + /** + * @fn std::string GetEnvironment(const std::string& env); + * + * @brief Convenience method to get the supplied environment variable. + * + * @param env The environment. + * + * @return The environment. + */ + TR_UTIL_EXPORT std::string GetEnvironment(const std::string& env); + + /** + * @fn bool IsEnvironment(const std::string& env); + * + * @brief Is the supplied environment variable defined? + * + * @param env The environment. + * + * @return True if environment, false if not. + */ + TR_UTIL_EXPORT bool IsEnvironment(const std::string& env); + + /** + * @fn void SetEnvironment(const std::string& name, const std::string& value); + * + * @brief Sets an environment variable. + * + * @param name the name of the variable to set. + * @param value the value of the environment variable to set. + */ + TR_UTIL_EXPORT void SetEnvironment(const std::string& name, const std::string& value); + + /** + * @fn std::string FindFile(const std::string& fileName); + * + * @brief Searches for a file in the list of paths found by calling GetDataFilePathList() + * + * @param fileName Can be a single filename or a path and file name relative to the current + * engines data path list. + * + * @return The full path to the file requested or empty string if it's not found. + */ + TR_UTIL_EXPORT std::string FindFile(const std::string& fileName); + + /** + * @fn std::string FindFile(const std::string& fileName, std::vector paths, bool caseInsensitive = true); + * + * @brief Searches a given path list for a file name. + * + * @param fileName Can be a single filename or a path and file name relative to the + * current engines data path list. + * @param paths the list of file paths to search. + * @param caseInsensitive (Optional) If the search should be case insensitive. This only works + * around case-sensitive file systems, it cannot not make a search fail + * if the case is wrong on a case insensitive one and one sets it to + * false. + * + * @return The found file. + */ + TR_UTIL_EXPORT std::string FindFile(const std::string& fileName, std::vector paths, bool caseInsensitive = true); + +#ifdef TR_APPLE + + /** + * @fn std::string GetBundleResourcesPath(); + * + * @brief Gets bundle resources path. + * + * @return the resource path inside the current application bundle. This is used internally, and + * this api is subject to change. + */ + std::string GetBundleResourcesPath(); + + /** + * @fn std::string GetBundlePlugInsPath(); + * + * @brief Gets bundle plug insert path. + * + * @return the plugins path inside the current application bundle. This is used internally, and + * this api is subject to change. + */ + std::string GetBundlePlugInsPath(); + + /** + * @fn std::string GetBundlePath(); + * + * @brief Gets bundle path. + * + * @return the application bundle path. This is used internally, and this api is subject to + * change. + */ + std::string GetBundlePath(); + + /** + * @fn void RemovePSNCommandLineOption(int& argc, char**& argv); + * + * @brief Removes the psn command line option. + * + * @param [in,out] argc The argc. + * @param [in,out] argv [in,out] If non-null, the argv. + */ + void RemovePSNCommandLineOption(int& argc, char**& argv); +#else + + /** + * @fn inline void RemovePSNCommandLineOption(int& argc, char**& argv) + * + * @brief Removes the psn command line option. + * + * @param [in,out] argc The argc. + * @param [in,out] argv [in,out] If non-null, the argv. + */ + inline void RemovePSNCommandLineOption(int& /*argc*/, char**& /*argv*/) {} +#endif +} + diff --git a/include/trUtil/PlatformMacros.h b/include/trUtil/PlatformMacros.h index 2bec11a..f9aeaf7 100644 --- a/include/trUtil/PlatformMacros.h +++ b/include/trUtil/PlatformMacros.h @@ -1,72 +1,72 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - - -namespace trUtil -{ - /** - * @enum BuildType - * - * @brief An Enum that represent build types. This enum should be used instead of using #ifdef - * statements to test if TR is in Debug or Release build. - * - * @author Maxim Serebrennik. - */ - enum class TR_UTIL_EXPORT BuildType - { - DEBUG, - RELEASE, - REL_WITH_DEB_INFO, - OTHER - }; - -///Defines TR Build Types -#ifdef _DEBUG - const BuildType TR_BUILD_TYPE = BuildType::DEBUG; -#else - const BuildType TR_BUILD_TYPE = BuildType::RELEASE; -#endif - -/// OS Defines -#if defined (WIN32) || defined (_WIN32) || defined (__WIN32__) - #define TR_WIN - #if _MSC_VER < 1900 - #ifndef snprintf - #define snprintf _snprintf - #endif - #ifndef stricmp - #define stricmp _stricmp - #endif - #endif - -#elif defined(__APPLE__) - #define TR_APPLE -#else - #define TR_LINUX -#endif +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + + +namespace trUtil +{ + /** + * @enum BuildType + * + * @brief An Enum that represent build types. This enum should be used instead of using #ifdef + * statements to test if TR is in Debug or Release build. + * + * @author Maxim Serebrennik. + */ + enum class TR_UTIL_EXPORT BuildType + { + DEBUG, + RELEASE, + REL_WITH_DEB_INFO, + OTHER + }; + +///Defines TR Build Types +#ifdef _DEBUG + const BuildType TR_BUILD_TYPE = BuildType::DEBUG; +#else + const BuildType TR_BUILD_TYPE = BuildType::RELEASE; +#endif + +/// OS Defines +#if defined (WIN32) || defined (_WIN32) || defined (__WIN32__) + #define TR_WIN + #if _MSC_VER < 1900 + #ifndef snprintf + #define snprintf _snprintf + #endif + #ifndef stricmp + #define stricmp _stricmp + #endif + #endif + +#elif defined(__APPLE__) + #define TR_APPLE +#else + #define TR_LINUX +#endif } \ No newline at end of file diff --git a/include/trUtil/RefStr.h b/include/trUtil/RefStr.h index e61dabb..58a2cf5 100644 --- a/include/trUtil/RefStr.h +++ b/include/trUtil/RefStr.h @@ -1,6 +1,6 @@ /* * True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC +* Copyright � 2019 Acid Rain Studios LLC * * The Base of this class has been adopted from the Delta3D engine * @@ -103,15 +103,6 @@ namespace trUtil */ operator const std::string&() const { return *mString; } - /** - * @fn operator const RefStr::char*() const - * - * @brief Implicit conversion operator from RefStr to const char*. - * - * @return A const. - */ - operator const char*() const { return mString->c_str(); } - /** * @fn trUtil::RefStr& RefStr::operator=(const std::string& value); * diff --git a/include/trUtil/StringUtils.h b/include/trUtil/StringUtils.h index 89772f1..2126672 100644 --- a/include/trUtil/StringUtils.h +++ b/include/trUtil/StringUtils.h @@ -1,439 +1,439 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Class Inspired by the Delta3D Engine -* http://delta3dengine.org/ -* -* @author David Guthrie -* @author John K. Grant -* @author William E. Johnson II -* @author Chris Osborn -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include -#include - -#include -#include -#include -#include -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil::StringUtils -{ - class IsSpace; - - /** @brief Constant value for a blank String. */ - static const std::string STR_BLANK(""); - - /** - * @class StringTokenizer - * - * @brief The predicate should evaluate to true when applied to a separator. - */ - template - class StringTokenizer - { - public: - - /** - * @fn static void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn = Pred()); - * - * @brief The predicate should evaluate to true when applied to a separator. - * - * @param [in,out] tokens The tokens. - * @param stringToParse The string to parse. - * @param predFxn (Optional) The predicate fxn. - */ - static void tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn = Pred()); - - /** - * @fn static void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const std::string& delimiter); - * - * @brief The predicate should evaluate to true when applied to a separator. - * - * @param [in,out] tokens The tokens. - * @param stringToParse The string to parse. - * @param delimiter The predicate fxn. - */ - static void tokenize(std::vector& tokens, const std::string& stringToParse, const std::string& delimiter); - }; - - /** - * @fn inline void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn) - * - * @brief The predicate should evaluate to true when applied to a separator. - * - * @tparam Pred Type of the predicate. - * @param [in,out] tokens The tokens. - * @param stringToParse The string to parse. - * @param predFxn The predicate fxn. - */ - template - inline void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn) - { - //First clear the results std::vector - tokens.clear(); - std::string::const_iterator it = stringToParse.begin(); - std::string::const_iterator itTokenEnd = stringToParse.begin(); - while (it != stringToParse.end()) - { - //Eat separators - if (predFxn(*it)) - { - it++; - } - else - { - //Find next token - itTokenEnd = std::find_if(it, stringToParse.end(), predFxn); - //Append token to result - if (it < itTokenEnd) - { - tokens.push_back(std::string(it, itTokenEnd)); - } - it = itTokenEnd; - } - } - } - - /** - * @class IsSpace - * - * @brief A functor which tests if a character is whitespace. This "predicate" needed to - * have 'state', the locale member. - */ - class TR_UTIL_EXPORT IsSpace : public trUtil::UnaryFunction - { - TR_DISABLE_WARNING_START_MSVC(4251) - public: - static const std::string DEFAULT_LOCALE_NAME; - IsSpace(const std::locale& loc = std::locale(DEFAULT_LOCALE_NAME.c_str())) : mLocale(loc) {} - - const std::locale& GetLocale() const { return mLocale; } - bool operator()(char c) const { return std::isspace(c, mLocale); } - TR_DISABLE_WARNING_END - private: - std::locale mLocale; - }; - - /** - * @class IsSlash - * - * @brief Determines if the current character is a forward slash. - */ - class IsSlash : public trUtil::UnaryFunction - { - public: - bool operator()(char c) const { return c == '/'; } - }; - - /** - * @class IsDelimeter - * - * @brief Generic string delimeter check function class. Based on the character passed to the - * constructor, this class will check for that character. - */ - class IsDelimeter : public trUtil::UnaryFunction - { - public: - IsDelimeter(char delim) : mDelimeter(delim) { } - bool operator()(char c) const { return c == mDelimeter; } - private: - char mDelimeter; - }; - - /** - * @fn const std::string& Trim(std::string& toTrim); - * - * @brief Trims whitespace off the front and end of a string. - * - * @param [in,out] toTrim the string to trim. - * - * @return A reference to a const std::string. - */ - TR_UTIL_EXPORT const std::string& Trim(std::string& toTrim); - - /** - * @fn int StrCompare(const std::string& one, const std::string& two, bool caseSensitive = true); - * - * @brief Compares strings like strcmp or stricmp or strcasecmp. - * - * @param one the first string to compare. - * @param two the string to compare one to. - * @param caseSensitive (Optional) optional parameter to specify case sensitivity, which - * defaults to on. - * - * @return 0 for equal, negative for one less that two, and positive for one > two. - */ - TR_UTIL_EXPORT int StrCompare(const std::string& one, const std::string& two, bool caseSensitive = true); - - /** - * @fn void ToLowerCase(std::string& str); - * - * @brief Converts the whole string to lower case. - * - * @param [in,out] str The string. - */ - TR_UTIL_EXPORT void ToLowerCase(std::string& str); - - /** - * @fn std::string ToLowerCase(const std::string& str); - * - * @brief Converts the whole string to lower case, slower version. - * - * @param str The string. - * - * @return Str as a std::string. - */ - TR_UTIL_EXPORT std::string ToLowerCase(const std::string& str); - - /** - * @fn void ToUpperCase(std::string& str); - * - * @brief Converts the whole string to upper case. - * - * @param [in,out] str The string. - */ - TR_UTIL_EXPORT void ToUpperCase(std::string& str); - - /** - * @fn std::string ToUpperCase(const std::string& str); - * - * @brief Converts the whole string to upper case, slower version. - * - * @param str The string. - * - * @return Str as a std::string. - */ - TR_UTIL_EXPORT std::string ToUpperCase(const std::string& str); - - /** - * @struct StrCompareFunc - * - * @brief A functor for using std::find or whatever that will compare two strings case - * sensitive or insensitive. - */ - struct StrCompareFunc - { - /** - * @fn StrCompareFunc(const std::string& mainString, bool caseSensitive = true) - * - * @brief Constructor. - * - * @param mainString The main string. - * @param caseSensitive (Optional) True to case sensitive. - */ - StrCompareFunc(const std::string& mainString, bool caseSensitive = true) - : mString(mainString) - , mCaseSensitive(caseSensitive) - { - } - - bool operator() (const std::string& toCompare) - { - return StrCompare(toCompare, mString, mCaseSensitive) == 0; - } - - const std::string& mString; - bool mCaseSensitive; - }; - - /** - * @fn bool ParseVec(const std::string& value, VecType& vec, unsigned size, unsigned numberPrecision = 16) - * - * @brief A templated function for taking any of the osg vector types and reading the data from - * a string. If the string is empty or "NULL" it will set the vector to all 0s. It - * expects the data to be the proper number floating point values. The function will - * fail if there are not enough values. - * - * @param value the string data. - * @param [in,out] vec the vector to fill. - * @param size the length of the vector since the osg types have no way to - * query that. - * @param numberPrecision (Optional) This value indicates how much precision the - * numbers will contain when read from the string. - * (setprecision on std::istream) - * - * @return true if reading the data was successful or false if not. - */ - template - bool ParseVec(const std::string& value, VecType& vec, unsigned size, unsigned numberPrecision = 16) - { - bool result = true; - unsigned int i; - - if (value.empty() || value == "NULL") - { - for (i = 0; i < size; ++i) - { - vec[i] = 0.0; - } - } - else - { - std::istringstream iss(value); - iss.precision(numberPrecision); - for (i = 0; i < size && !iss.eof(); ++i) - { - iss >> vec[i]; - } - - //did we run out of data? - if (i < size) - result = false; - } - - return result; - } - - /** - * @fn std::string ToString(const T& t, int precision = -1) - * - * @brief A utility function to convert a basic type into a string. Use template argument T for - * the type you'd like to convert. - * - * @param t the instance of the type to converted. - * - * Typical use: - * @code - * float num = 5.67f; - * std::string mynum = StringUtils::ToString( num ); - * @endcode. - * @param precision (Optional) The precision. - * - * @return A std::string that represents this object. - */ - template - std::string ToString(const T& t, int precision = -1) - { - std::ostringstream ss; - if (precision > 0) - { - ss.precision(precision); - } - ss << t; - return ss.str(); - } - - - /** - * @fn T FromString(const std::string& u) - * - * @brief Converts a string to a specified type. - * - * @param u string to be converted to the specified template argument type. - * - * @return the type that you specify as the template argument. - * - * Typical use: - * @code - * std::string mystring("0"); - * float myfloat = StringUtils::FromString<float>( mystring ); - * @endcode. - */ - template - T FromString(const std::string& u) - { - T result = T(); - std::istringstream is; - is.str(u); - is >> result; - return result; - } - - - /** - * @fn bool FromString(const std::string& u); - * - * @brief Special exception for bool where things like "True", "TRUE", and "true" should be - * accepted. - * - * @tparam bool Type of the bool. - * @param u The std::string to process. - * - * @return True if it succeeds, false if it fails. - */ - template<> - bool TR_UTIL_EXPORT FromString(const std::string& u); - - /** - * @fn bool Match(const char* wildCards, const char* str); - * - * @brief Matches. - * - * @param wildCards The wild cards. - * @param str The string. - * - * @return True if it succeeds, false if it fails. - */ - bool TR_UTIL_EXPORT Match(const char* wildCards, const char* str); - - /** - * @fn void MakeIndexString(unsigned index, std::string& toFill, unsigned paddedLength = 4); - * - * @brief Makes index string. - * - * @return a string with text as an int value padded to the size specified. - * - * @param index Zero-based index of the. - * @param [in,out] toFill to fill. - * @param paddedLength (Optional) Length of the padded. - */ - void TR_UTIL_EXPORT MakeIndexString(unsigned index, std::string& toFill, unsigned paddedLength = 4); - - /** - * @fn bool TakeToken(std::string& data, std::string& outToken, char openChar, char closeChar); - * - * @brief Reads the next token fromm the given string data. This will also remove the token - * from the data string and return you the token (with the open and close characters - * removed). The beginning of the data string must always begin with an opening - * character or this will cause problems. - * - * @param [in] data The string data. - * @param [out] outToken The first token from the string data. - * @param [in] openChar The character that starts the token. - * @param [in] closeChar The character that ends the token. - * - * @return true if a token was found. - */ - bool TR_UTIL_EXPORT TakeToken(std::string& data, std::string& outToken, char openChar, char closeChar); - - /** - * @fn void FindAndReplace(std::string& modifiedString, const std::string& findWhat, const std::string& replaceWith); - * - * @brief Finds all instances of the findWhat string in the string modifiedString and replaces - * them with the replaceWith string. - * - * @param [out] modifiedString The string we are modifying. - * @param [in] findWhat The string we want to remove from modifiedString. - * @param [in] replaceWith The string we want to put in modifiedString. - */ - void TR_UTIL_EXPORT FindAndReplace(std::string& modifiedString, const std::string& findWhat, const std::string& replaceWith); +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* The Base of this class has been adopted from the Delta3D engine +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Class Inspired by the Delta3D Engine +* http://delta3dengine.org/ +* +* @author David Guthrie +* @author John K. Grant +* @author William E. Johnson II +* @author Chris Osborn +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include +#include + +#include +#include +#include +#include +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil::StringUtils +{ + class IsSpace; + + /** @brief Constant value for a blank String. */ + static const std::string STR_BLANK(""); + + /** + * @class StringTokenizer + * + * @brief The predicate should evaluate to true when applied to a separator. + */ + template + class StringTokenizer + { + public: + + /** + * @fn static void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn = Pred()); + * + * @brief The predicate should evaluate to true when applied to a separator. + * + * @param [in,out] tokens The tokens. + * @param stringToParse The string to parse. + * @param predFxn (Optional) The predicate fxn. + */ + static void tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn = Pred()); + + /** + * @fn static void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const std::string& delimiter); + * + * @brief The predicate should evaluate to true when applied to a separator. + * + * @param [in,out] tokens The tokens. + * @param stringToParse The string to parse. + * @param delimiter The predicate fxn. + */ + static void tokenize(std::vector& tokens, const std::string& stringToParse, const std::string& delimiter); + }; + + /** + * @fn inline void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn) + * + * @brief The predicate should evaluate to true when applied to a separator. + * + * @tparam Pred Type of the predicate. + * @param [in,out] tokens The tokens. + * @param stringToParse The string to parse. + * @param predFxn The predicate fxn. + */ + template + inline void StringTokenizer::tokenize(std::vector& tokens, const std::string& stringToParse, const Pred& predFxn) + { + //First clear the results std::vector + tokens.clear(); + std::string::const_iterator it = stringToParse.begin(); + std::string::const_iterator itTokenEnd = stringToParse.begin(); + while (it != stringToParse.end()) + { + //Eat separators + if (predFxn(*it)) + { + it++; + } + else + { + //Find next token + itTokenEnd = std::find_if(it, stringToParse.end(), predFxn); + //Append token to result + if (it < itTokenEnd) + { + tokens.push_back(std::string(it, itTokenEnd)); + } + it = itTokenEnd; + } + } + } + + /** + * @class IsSpace + * + * @brief A functor which tests if a character is whitespace. This "predicate" needed to + * have 'state', the locale member. + */ + class TR_UTIL_EXPORT IsSpace : public trUtil::UnaryFunction + { + TR_DISABLE_WARNING_START_MSVC(4251) + public: + static const std::string DEFAULT_LOCALE_NAME; + IsSpace(const std::locale& loc = std::locale(DEFAULT_LOCALE_NAME.c_str())) : mLocale(loc) {} + + const std::locale& GetLocale() const { return mLocale; } + bool operator()(char c) const { return std::isspace(c, mLocale); } + TR_DISABLE_WARNING_END + private: + std::locale mLocale; + }; + + /** + * @class IsSlash + * + * @brief Determines if the current character is a forward slash. + */ + class IsSlash : public trUtil::UnaryFunction + { + public: + bool operator()(char c) const { return c == '/'; } + }; + + /** + * @class IsDelimeter + * + * @brief Generic string delimeter check function class. Based on the character passed to the + * constructor, this class will check for that character. + */ + class IsDelimeter : public trUtil::UnaryFunction + { + public: + IsDelimeter(char delim) : mDelimeter(delim) { } + bool operator()(char c) const { return c == mDelimeter; } + private: + char mDelimeter; + }; + + /** + * @fn const std::string& Trim(std::string& toTrim); + * + * @brief Trims whitespace off the front and end of a string. + * + * @param [in,out] toTrim the string to trim. + * + * @return A reference to a const std::string. + */ + TR_UTIL_EXPORT const std::string& Trim(std::string& toTrim); + + /** + * @fn int StrCompare(const std::string& one, const std::string& two, bool caseSensitive = true); + * + * @brief Compares strings like strcmp or stricmp or strcasecmp. + * + * @param one the first string to compare. + * @param two the string to compare one to. + * @param caseSensitive (Optional) optional parameter to specify case sensitivity, which + * defaults to on. + * + * @return 0 for equal, negative for one less that two, and positive for one > two. + */ + TR_UTIL_EXPORT int StrCompare(const std::string& one, const std::string& two, bool caseSensitive = true); + + /** + * @fn void ToLowerCase(std::string& str); + * + * @brief Converts the whole string to lower case. + * + * @param [in,out] str The string. + */ + TR_UTIL_EXPORT void ToLowerCase(std::string& str); + + /** + * @fn std::string ToLowerCase(const std::string& str); + * + * @brief Converts the whole string to lower case, slower version. + * + * @param str The string. + * + * @return Str as a std::string. + */ + TR_UTIL_EXPORT std::string ToLowerCase(const std::string& str); + + /** + * @fn void ToUpperCase(std::string& str); + * + * @brief Converts the whole string to upper case. + * + * @param [in,out] str The string. + */ + TR_UTIL_EXPORT void ToUpperCase(std::string& str); + + /** + * @fn std::string ToUpperCase(const std::string& str); + * + * @brief Converts the whole string to upper case, slower version. + * + * @param str The string. + * + * @return Str as a std::string. + */ + TR_UTIL_EXPORT std::string ToUpperCase(const std::string& str); + + /** + * @struct StrCompareFunc + * + * @brief A functor for using std::find or whatever that will compare two strings case + * sensitive or insensitive. + */ + struct StrCompareFunc + { + /** + * @fn StrCompareFunc(const std::string& mainString, bool caseSensitive = true) + * + * @brief Constructor. + * + * @param mainString The main string. + * @param caseSensitive (Optional) True to case sensitive. + */ + StrCompareFunc(const std::string& mainString, bool caseSensitive = true) + : mString(mainString) + , mCaseSensitive(caseSensitive) + { + } + + bool operator() (const std::string& toCompare) + { + return StrCompare(toCompare, mString, mCaseSensitive) == 0; + } + + const std::string& mString; + bool mCaseSensitive; + }; + + /** + * @fn bool ParseVec(const std::string& value, VecType& vec, unsigned size, unsigned numberPrecision = 16) + * + * @brief A templated function for taking any of the osg vector types and reading the data from + * a string. If the string is empty or "NULL" it will set the vector to all 0s. It + * expects the data to be the proper number floating point values. The function will + * fail if there are not enough values. + * + * @param value the string data. + * @param [in,out] vec the vector to fill. + * @param size the length of the vector since the osg types have no way to + * query that. + * @param numberPrecision (Optional) This value indicates how much precision the + * numbers will contain when read from the string. + * (setprecision on std::istream) + * + * @return true if reading the data was successful or false if not. + */ + template + bool ParseVec(const std::string& value, VecType& vec, unsigned size, unsigned numberPrecision = 16) + { + bool result = true; + unsigned int i; + + if (value.empty() || value == "NULL") + { + for (i = 0; i < size; ++i) + { + vec[i] = 0.0; + } + } + else + { + std::istringstream iss(value); + iss.precision(numberPrecision); + for (i = 0; i < size && !iss.eof(); ++i) + { + iss >> vec[i]; + } + + //did we run out of data? + if (i < size) + result = false; + } + + return result; + } + + /** + * @fn std::string ToString(const T& t, int precision = -1) + * + * @brief A utility function to convert a basic type into a string. Use template argument T for + * the type you'd like to convert. + * + * @param t the instance of the type to converted. + * + * Typical use: + * @code + * float num = 5.67f; + * std::string mynum = StringUtils::ToString( num ); + * @endcode. + * @param precision (Optional) The precision. + * + * @return A std::string that represents this object. + */ + template + std::string ToString(const T& t, int precision = -1) + { + std::ostringstream ss; + if (precision > 0) + { + ss.precision(precision); + } + ss << t; + return ss.str(); + } + + + /** + * @fn T FromString(const std::string& u) + * + * @brief Converts a string to a specified type. + * + * @param u string to be converted to the specified template argument type. + * + * @return the type that you specify as the template argument. + * + * Typical use: + * @code + * std::string mystring("0"); + * float myfloat = StringUtils::FromString<float>( mystring ); + * @endcode. + */ + template + T FromString(const std::string& u) + { + T result = T(); + std::istringstream is; + is.str(u); + is >> result; + return result; + } + + + /** + * @fn bool FromString(const std::string& u); + * + * @brief Special exception for bool where things like "True", "TRUE", and "true" should be + * accepted. + * + * @tparam bool Type of the bool. + * @param u The std::string to process. + * + * @return True if it succeeds, false if it fails. + */ + template<> + bool TR_UTIL_EXPORT FromString(const std::string& u); + + /** + * @fn bool Match(const char* wildCards, const char* str); + * + * @brief Matches. + * + * @param wildCards The wild cards. + * @param str The string. + * + * @return True if it succeeds, false if it fails. + */ + bool TR_UTIL_EXPORT Match(const char* wildCards, const char* str); + + /** + * @fn void MakeIndexString(unsigned index, std::string& toFill, unsigned paddedLength = 4); + * + * @brief Makes index string. + * + * @return a string with text as an int value padded to the size specified. + * + * @param index Zero-based index of the. + * @param [in,out] toFill to fill. + * @param paddedLength (Optional) Length of the padded. + */ + void TR_UTIL_EXPORT MakeIndexString(unsigned index, std::string& toFill, unsigned paddedLength = 4); + + /** + * @fn bool TakeToken(std::string& data, std::string& outToken, char openChar, char closeChar); + * + * @brief Reads the next token fromm the given string data. This will also remove the token + * from the data string and return you the token (with the open and close characters + * removed). The beginning of the data string must always begin with an opening + * character or this will cause problems. + * + * @param [in] data The string data. + * @param [out] outToken The first token from the string data. + * @param [in] openChar The character that starts the token. + * @param [in] closeChar The character that ends the token. + * + * @return true if a token was found. + */ + bool TR_UTIL_EXPORT TakeToken(std::string& data, std::string& outToken, char openChar, char closeChar); + + /** + * @fn void FindAndReplace(std::string& modifiedString, const std::string& findWhat, const std::string& replaceWith); + * + * @brief Finds all instances of the findWhat string in the string modifiedString and replaces + * them with the replaceWith string. + * + * @param [out] modifiedString The string we are modifying. + * @param [in] findWhat The string we want to remove from modifiedString. + * @param [in] replaceWith The string we want to put in modifiedString. + */ + void TR_UTIL_EXPORT FindAndReplace(std::string& modifiedString, const std::string& findWhat, const std::string& replaceWith); } \ No newline at end of file diff --git a/include/trUtil/Timer.h b/include/trUtil/Timer.h index e92c899..d58cb6b 100644 --- a/include/trUtil/Timer.h +++ b/include/trUtil/Timer.h @@ -1,240 +1,240 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ -#pragma once - -#include - -#include - -#include - -/** - * @namespace trUtil - * - * @brief . - */ -namespace trUtil -{ - -#if defined(TR_WIN) - /** @brief 64bit Integer to hold the Timers time ticks. */ - using TimeTicks = unsigned __int64; -#else - /** @brief 64bit Integer to hold the Timers time ticks. */ - using TimeTicks = unsigned long long; -#endif - - /** - * @fn void AppSleep(unsigned int milliseconds); - * - * @brief Puts the current application thread to sleep for a given number of milliseconds. - * - * @return A TR_UTIL_EXPORT. - * - * @param milliseconds The milliseconds. - * - * @author Maxim Serebrennik - */ - void TR_UTIL_EXPORT AppSleep(unsigned int milliseconds); - - /** - * @class Timer - * - * @brief Timer class is used for measuring elapsed time or time between two points. - * - * @author Maxim Serebrennik - */ - class TR_UTIL_EXPORT Timer - { - public: - - /** - * @fn Timer::Timer(); - * - * @brief Default constructor. - */ - Timer(); - - /** - * @fn Timer::~Timer(); - * - * @brief Destructor. - */ - ~Timer(); - - /** - * @fn static const Timer* Timer::Instance(); - * - * @brief Creates and returns a global timer. This allows the user to use the timer class as a - * singleton. It can still be declared locally though, without the use of Instance() - * - * @return Null if it fails, else a pointer to a const Timer. - */ - static const Timer* Instance(); - - /** - * @fn TimeTicks Timer::Tick() - * - * @brief Get the timers tick value. - * - * @return The TimeTicks. - */ - TimeTicks Tick() - { - mOldTicks = mNewTicks; - mNewTicks = (mTimer.tick() + mCustomTicks); - return mNewTicks; - } - - /** - * @fn void Timer::SetStartTick() - * - * @brief Set the start tick. - */ - void SetStartTick() { mTimer.setStartTick(); } - - /** - * @fn void Timer::SetStartTick(TimeTicks t); - * - * @brief Set the start tick to a custom value. - * - * @param t The TimeTicks to process. - */ - void SetStartTick(TimeTicks t); - - /** - * @fn TimeTicks Timer::GetStartTick() const - * - * @brief Get the value of the start tick. - * - * @return The start tick. - */ - TimeTicks GetStartTick() const { return mTimer.getStartTick(); } - - /** - * @fn double Timer::DeltaSec(TimeTicks t1, TimeTicks t2) const - * - * @brief Get the time in seconds between timer ticks t1 and t2. - * - * @param t1 The first TimeTicks. - * @param t2 The second TimeTicks. - * - * @return A double. - */ - double DeltaSec(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_s(t1, t2); } - - /** - * @fn double Timer::DeltaMil(TimeTicks t1, TimeTicks t2) const - * - * @brief Get the time in milliseconds between timer ticks t1 and t2. - * - * @param t1 The first TimeTicks. - * @param t2 The second TimeTicks. - * - * @return A double. - */ - double DeltaMil(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_m(t1, t2); } - - /** - * @fn double Timer::DeltaMicro(TimeTicks t1, TimeTicks t2) const - * - * @brief Get the time in microseconds between timer ticks t1 and t2. - * - * @param t1 The first TimeTicks. - * @param t2 The second TimeTicks. - * - * @return A double. - */ - double DeltaMicro(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_u(t1, t2); } - - /** - * @fn double Timer::DeltaNano(TimeTicks t1, TimeTicks t2) const - * - * @brief Get the time in nanoseconds between timer ticks t1 and t2. - * - * @param t1 The first TimeTicks. - * @param t2 The second TimeTicks. - * - * @return A double. - */ - double DeltaNano(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_n(t1, t2); } - - /** - * @fn double Timer::ElapsedSeconds() const - * - * @brief Get elapsed time in seconds. - * - * @return A double. - */ - double ElapsedSeconds() const { return mTimer.time_s(); } - - /** - * @fn double Timer::ElapsedMilliseconds() const - * - * @brief Get elapsed time in milliseconds. - * - * @return A double. - */ - double ElapsedMilliseconds() const { return mTimer.time_m(); } - - /** - * @fn double Timer::ElapsedMicroseconds() const - * - * @brief Get elapsed time in microseconds. - * - * @return A double. - */ - double ElapsedMicroseconds() const { return mTimer.time_u(); } - - /** - * @fn double Timer::ElapsedNanoseconds() const - * - * @brief Get elapsed time in nanoseconds. - * - * @return A double. - */ - double ElapsedNanoseconds() const { return mTimer.time_n(); } - - /** - * @fn double Timer::GetSecondsPerCPUTick() const - * - * @brief Get the number of seconds per CPU tick. - * - * @return The seconds per CPU tick. - */ - double GetSecondsPerCPUTick() const { return mTimer.getSecondsPerTick(); } - - /** - * @fn double Timer::GetSecondsPerTick() const - * - * @brief Get the number of seconds per tick. - * - * @return The seconds per tick. - */ - double GetSecondsPerTick() const { return (double)(mNewTicks - mOldTicks)*GetSecondsPerCPUTick(); } - - private: - osg::Timer mTimer; - TimeTicks mOldTicks = 0; - TimeTicks mNewTicks = 0; - TimeTicks mCustomTicks = 0; - }; +/* +* True Reality Open Source Game and Simulation Engine +* Copyright © 2019 Acid Rain Studios LLC +* +* This library is free software; you can redistribute it and/or modify it under +* the terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; either version 3.0 of the License, or (at your option) +* any later version. +* +* This library 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 Lesser General Public License for more +* details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this library; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* @author Maxim Serebrennik +*/ +#pragma once + +#include + +#include + +#include + +/** + * @namespace trUtil + * + * @brief . + */ +namespace trUtil +{ + +#if defined(TR_WIN) + /** @brief 64bit Integer to hold the Timers time ticks. */ + using TimeTicks = unsigned __int64; +#else + /** @brief 64bit Integer to hold the Timers time ticks. */ + using TimeTicks = unsigned long long; +#endif + + /** + * @fn void AppSleep(unsigned int milliseconds); + * + * @brief Puts the current application thread to sleep for a given number of milliseconds. + * + * @return A TR_UTIL_EXPORT. + * + * @param milliseconds The milliseconds. + * + * @author Maxim Serebrennik + */ + void TR_UTIL_EXPORT AppSleep(unsigned int milliseconds); + + /** + * @class Timer + * + * @brief Timer class is used for measuring elapsed time or time between two points. + * + * @author Maxim Serebrennik + */ + class TR_UTIL_EXPORT Timer + { + public: + + /** + * @fn Timer::Timer(); + * + * @brief Default constructor. + */ + Timer(); + + /** + * @fn Timer::~Timer(); + * + * @brief Destructor. + */ + ~Timer(); + + /** + * @fn static const Timer* Timer::Instance(); + * + * @brief Creates and returns a global timer. This allows the user to use the timer class as a + * singleton. It can still be declared locally though, without the use of Instance() + * + * @return Null if it fails, else a pointer to a const Timer. + */ + static const Timer* Instance(); + + /** + * @fn TimeTicks Timer::Tick() + * + * @brief Get the timers tick value. + * + * @return The TimeTicks. + */ + TimeTicks Tick() + { + mOldTicks = mNewTicks; + mNewTicks = (mTimer.tick() + mCustomTicks); + return mNewTicks; + } + + /** + * @fn void Timer::SetStartTick() + * + * @brief Set the start tick. + */ + void SetStartTick() { mTimer.setStartTick(); } + + /** + * @fn void Timer::SetStartTick(TimeTicks t); + * + * @brief Set the start tick to a custom value. + * + * @param t The TimeTicks to process. + */ + void SetStartTick(TimeTicks t); + + /** + * @fn TimeTicks Timer::GetStartTick() const + * + * @brief Get the value of the start tick. + * + * @return The start tick. + */ + TimeTicks GetStartTick() const { return mTimer.getStartTick(); } + + /** + * @fn double Timer::DeltaSec(TimeTicks t1, TimeTicks t2) const + * + * @brief Get the time in seconds between timer ticks t1 and t2. + * + * @param t1 The first TimeTicks. + * @param t2 The second TimeTicks. + * + * @return A double. + */ + double DeltaSec(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_s(t1, t2); } + + /** + * @fn double Timer::DeltaMil(TimeTicks t1, TimeTicks t2) const + * + * @brief Get the time in milliseconds between timer ticks t1 and t2. + * + * @param t1 The first TimeTicks. + * @param t2 The second TimeTicks. + * + * @return A double. + */ + double DeltaMil(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_m(t1, t2); } + + /** + * @fn double Timer::DeltaMicro(TimeTicks t1, TimeTicks t2) const + * + * @brief Get the time in microseconds between timer ticks t1 and t2. + * + * @param t1 The first TimeTicks. + * @param t2 The second TimeTicks. + * + * @return A double. + */ + double DeltaMicro(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_u(t1, t2); } + + /** + * @fn double Timer::DeltaNano(TimeTicks t1, TimeTicks t2) const + * + * @brief Get the time in nanoseconds between timer ticks t1 and t2. + * + * @param t1 The first TimeTicks. + * @param t2 The second TimeTicks. + * + * @return A double. + */ + double DeltaNano(TimeTicks t1, TimeTicks t2) const { return mTimer.delta_n(t1, t2); } + + /** + * @fn double Timer::ElapsedSeconds() const + * + * @brief Get elapsed time in seconds. + * + * @return A double. + */ + double ElapsedSeconds() const { return mTimer.time_s(); } + + /** + * @fn double Timer::ElapsedMilliseconds() const + * + * @brief Get elapsed time in milliseconds. + * + * @return A double. + */ + double ElapsedMilliseconds() const { return mTimer.time_m(); } + + /** + * @fn double Timer::ElapsedMicroseconds() const + * + * @brief Get elapsed time in microseconds. + * + * @return A double. + */ + double ElapsedMicroseconds() const { return mTimer.time_u(); } + + /** + * @fn double Timer::ElapsedNanoseconds() const + * + * @brief Get elapsed time in nanoseconds. + * + * @return A double. + */ + double ElapsedNanoseconds() const { return mTimer.time_n(); } + + /** + * @fn double Timer::GetSecondsPerCPUTick() const + * + * @brief Get the number of seconds per CPU tick. + * + * @return The seconds per CPU tick. + */ + double GetSecondsPerCPUTick() const { return mTimer.getSecondsPerTick(); } + + /** + * @fn double Timer::GetSecondsPerTick() const + * + * @brief Get the number of seconds per tick. + * + * @return The seconds per tick. + */ + double GetSecondsPerTick() const { return (double)(mNewTicks - mOldTicks)*GetSecondsPerCPUTick(); } + + private: + osg::Timer mTimer; + TimeTicks mOldTicks = 0; + TimeTicks mNewTicks = 0; + TimeTicks mCustomTicks = 0; + }; } \ No newline at end of file diff --git a/include/trUtil/TypeList.h b/include/trUtil/TypeList.h index 3c0a7f3..cbd1dc6 100644 --- a/include/trUtil/TypeList.h +++ b/include/trUtil/TypeList.h @@ -1,252 +1,252 @@ -/* -* True Reality Open Source Game and Simulation Engine -* Copyright © 2019 Acid Rain Studios LLC -* -* The Base of this class has been adopted from the Delta3D engine -* -* This library is free software; you can redistribute it and/or modify it under -* the terms of the GNU Lesser General Public License as published by the Free -* Software Foundation; either version 3.0 of the License, or (at your option) -* any later version. -* -* This library 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 Lesser General Public License for more -* details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with this library; if not, write to the Free Software Foundation, Inc., -* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* @author Maxim Serebrennik -*/ - -#pragma once - -namespace trUtil -{ - /* - * This file contains small collection of generic programming templates etc - * gathered from various sources (Loki library is the main one). Some of them - * has been modified, others have remained intact. - * Copyright Aleksei Trunov 2005 - * Use, copy, modify, distribute and sell it for free. - */ - - template - struct Select - { - using Result = T; - }; - template - struct Select - { - using Result = U; - }; - - template struct Int2Type { enum { value = v }; }; - - template struct IsIntType { enum { value = false }; }; - template struct IsIntType, i> { enum { value = true }; }; - template struct NotIntType { enum { value = !IsIntType::value }; }; - - /** - * @class NullType - * - * @brief A null type class. - */ - class NullType {}; - struct EmptyType {}; - - /** - * @struct TypeList - * - * @brief List of types structure. - * - * @tparam T Generic type parameter. - * @tparam U Generic type parameter. - */ - template - struct TypeList - { - using Head = T; - using Tail = U; - }; - - template < - class T1 = NullType - , class T2 = NullType - , class T3 = NullType - , class T4 = NullType - , class T5 = NullType - , class T6 = NullType - , class T7 = NullType - , class T8 = NullType - > struct CreateTL - { - using Type = TypeList::Type>; - }; - template<> struct CreateTL - { - using Type = NullType; - }; - - template < - int i1 = -1 - , int i2 = -1 - , int i3 = -1 - , int i4 = -1 - , int i5 = -1 - , int i6 = -1 - , int i7 = -1 - , int i8 = -1 - > struct CreateIdsTL - { - using Type = TypeList, typename CreateIdsTL::Type>; - }; - template <> struct CreateIdsTL<-1, -1, -1, -1, -1, -1, -1, -1> { using Type = NullType; }; - - template struct IdsFromTL - { - using Type = TypeList, typename IdsFromTL::Type>; - }; - template struct IdsFromTL { using Type = NullType; }; - - template - struct AppendTL - { - using Type = TypeList::Type>; - }; - template - struct AppendTL - { - using Type = TypeList; - }; - -/** - * @brief Macros that define various lists of Class types. - */ -#define TYPELIST_0() trUtil::NullType -#define TYPELIST_1(T1) trUtil::TypeList -#define TYPELIST_2(T1, T2) trUtil::TypeList -#define TYPELIST_3(T1, T2, T3) trUtil::TypeList -#define TYPELIST_4(T1, T2, T3, T4) trUtil::TypeList -#define TYPELIST_5(T1, T2, T3, T4, T5) trUtil::TypeList -#define TYPELIST_6(T1, T2, T3, T4, T5, T6) trUtil::TypeList -#define TYPELIST_7(T1, T2, T3, T4, T5, T6, T7) trUtil::TypeList -#define TYPELIST_8(T1, T2, T3, T4, T5, T6, T7, T8) trUtil::TypeList - - template struct Length; - template <> struct Length - { - enum { value = 0 }; - }; - template - struct Length< TypeList > - { - enum { value = 1 + Length::value }; - }; - - template struct TypeAt; - template - struct TypeAt< TypeList, 0 > - { - using Result = T; - }; - template - struct TypeAt< TypeList, i > - { - using Result = typename TypeAt::Result; - }; - - template - struct TypeAtNonStrict - { - using Result = DefType; - }; - template - struct TypeAtNonStrict< TypeList, 0, DefType > - { - using Result = T; - }; - template - struct TypeAtNonStrict< TypeList, i, DefType > - { - using Result = typename TypeAtNonStrict::Result; - }; - - // Tuples-related - - template struct TupleHolder - { - using Type = T; - using StoredType = T; - StoredType value; - TupleHolder() {} - TupleHolder(Type t) : value(t) {} - TupleHolder& operator=(TupleHolder const& v) { value = v.value; } - }; - - template class Holder, unsigned int i = 0> struct InstantiateH; - template class Holder, unsigned int i> - struct InstantiateH, Holder, i> - : public Holder::Head, i> - , public InstantiateH::Tail, Holder, i + 1> - { - enum { ordern = i }; - using LeftBase = Holder::Head, i>; - using RightBase = InstantiateH::Tail, Holder, i + 1>; - InstantiateH(typename TypeList::Head h, RightBase const& t) : LeftBase(h), RightBase(t) {} - InstantiateH(typename TypeList::Head h, NullType) : LeftBase(h) {} - InstantiateH(typename TypeList::Head h) : LeftBase(h) {} - InstantiateH() {} - }; - template