### OpenRW Configuration File Example Source: https://github.com/rwengine/openrw/wiki/Configuration This is an example of the 'openrw.ini' configuration file used by OpenRW. It specifies game settings such as data path, language, input preferences, and window dimensions. ```ini [game] ; Game data path path=/opt/games/Grand Theft Auto 3/ ; Game language language=american [input] ; Invert mouse-look camera Y invert_y=0 [window] ; Size of the window width=800 height=600 ; Start in fullscreen fullscreen=0 ``` -------------------------------- ### Install Dependencies on OpenBSD Source: https://github.com/rwengine/openrw/wiki/Building Installs dependencies for OpenRW on OpenBSD using pkg_add. ```bash pkg_add cmake ffmpeg glm bullet sdl2 gcc-4.9 ``` -------------------------------- ### Install Dependencies on Fedora Source: https://github.com/rwengine/openrw/wiki/Building Installs development packages for OpenRW on Fedora using dnf. ```bash # dnf install cmake libGL-devel openal-soft-devel ffmpeg-devel bullet-devel glm-devel SDL2-devel boost-devel ``` -------------------------------- ### Install Dependencies on Ubuntu Source: https://github.com/rwengine/openrw/wiki/Building Installs necessary development libraries for building OpenRW on Ubuntu using apt. ```bash # apt install libbullet-dev libsdl2-dev libavcodec-dev libavformat-dev libglm-dev libopenal-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-program-options-dev ``` -------------------------------- ### Conan Dependency Installation Source: https://github.com/rwengine/openrw/wiki/Building Downloads and installs OpenRW dependencies using Conan after setting up the build environment. ```bash $ conan remote add bintray https://api.bintray.com/conan/bincrafters/public-conan $ conan install .. -s arch=x86_64 ``` -------------------------------- ### Apply Options and Install Shared Library (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwengine/CMakeLists.txt Applies custom build options (CORE, COVERAGE) to the 'rwengine' target and sets up installation rules for shared libraries if BUILD_SHARED_LIBS is enabled. ```cmake openrw_target_apply_options(TARGET rwengine CORE COVERAGE ) if(BUILD_SHARED_LIBS) install(TARGETS rwengine ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Install Dependencies on macOS Source: https://github.com/rwengine/openrw/wiki/Building Installs required build dependencies for OpenRW on macOS using Homebrew. ```bash brew install cmake bullet glm ffmpeg sdl2 boost ``` -------------------------------- ### Install Dependencies on MinGW/MSYS2 Source: https://github.com/rwengine/openrw/wiki/Building Installs MinGW-w64 packages for the toolchain and OpenRW dependencies on Windows using pacman within an MSYS2 shell. ```bash pacman -Syu pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-openal mingw-w64-x86_64-bullet mingw-w64-x86_64-glm mingw-w64-x86_64-ffmpeg mingw-w64-x86_64-SDL2 mingw-w64-x86_64-boost ``` -------------------------------- ### CMake: Installation and Packaging Source: https://github.com/rwengine/openrw/blob/main/CMakeLists.txt Configures the installation process by copying the license file to the documentation directory and the build directory for CI purposes. It also includes CMake's CPack module for packaging the build artifacts. ```cmake # Copy the license to the install directory install(FILES COPYING DESTINATION "${CMAKE_INSTALL_DOCDIR}" ) # Copy the license to the build directory (for CI) file(COPY COPYING DESTINATION "${PROJECT_BINARY_DIR}" ) include(CMakeCPack.cmake) if(TEST_COVERAGE) coverage_collect() endif() ``` -------------------------------- ### Install Dependencies on Arch Linux Source: https://github.com/rwengine/openrw/wiki/Building Installs required packages for building OpenRW on Arch Linux using pacman. ```bash # pacman -S bullet glm ffmpeg sdl2 boost ``` -------------------------------- ### Install Dependencies on Gentoo Linux Source: https://github.com/rwengine/openrw/wiki/Building Installs dependencies for OpenRW on Gentoo Linux using emerge, with specific USE flags for SDL2. ```bash # emerge -a sci-physics/bullet media-libs/glm media-video/ffmpeg media-libs/libsdl2 dev-libs/boost ``` -------------------------------- ### Apply Options to rwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Applies build options like CORE, COVERAGE, INSTALL, and INSTALL_PDB to the 'rwgame' executable target. ```cmake openrw_target_apply_options( TARGET rwgame CORE COVERAGE INSTALL INSTALL_PDB ) ``` -------------------------------- ### CMake: Project Setup and Dependency Finding Source: https://github.com/rwengine/openrw/blob/main/CMakeLists.txt Initializes the CMake project, sets the minimum required version, and includes necessary modules for project configuration. It then proceeds to find and link various external libraries required for the build, such as Boost, SDL2, OpenGL, OpenAL, Bullet, GLM, FFmpeg, and Freetype. ```cmake cmake_minimum_required(VERSION 3.8...3.28) project(OpenRW) include(GNUInstallDirs) # Read the configuration arguments include("${PROJECT_SOURCE_DIR}/cmake_options.cmake") list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules") # Include git hash in source include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC GIT_SHA1) message(STATUS "Building ${CMAKE_PROJECT_NAME} GIT SHA1: ${GIT_SHA1}") include(WrapTargets) if(USE_CONAN) if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake") message(STATUS "Using conan 'cmake_multi' generator") include("${CMAKE_BINARY_DIR}/conanbuildinfo_multi.cmake") else() message(STATUS "Using conan 'cmake' generator") include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") endif() conan_basic_setup(TARGETS NO_OUTPUT_DIRS) rwdep_wrap_conan_targets() else() if(POLICY CMP0167) cmake_policy(SET CMP0167 NEW) endif() find_package(Boost REQUIRED) find_package(Boost COMPONENTS program_options system REQUIRED) if(BUILD_TESTS) find_package(Boost COMPONENTS unit_test_framework REQUIRED) endif() if(BUILD_TOOLS) find_package(Freetype REQUIRED) endif() # Do not link to SDL2main library set(SDL2_BUILDING_LIBRARY TRUE) find_package(OpenAL REQUIRED) find_package(Bullet REQUIRED) find_package(GLM REQUIRED) find_package(FFmpeg REQUIRED) find_package(SDL2 REQUIRED) rwdep_wrap_find_packages() endif() set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) if(CHECK_CLANGTIDY) find_package(ClangTidy REQUIRED) endif() if(CHECK_IWYU) find_package(IncludeWhatYouUse REQUIRED) endif() # Create a rw_interface TARGET that holds all compiler options include("${PROJECT_SOURCE_DIR}/cmake_configure.cmake") ``` -------------------------------- ### Applying Custom Build Options with openrw_target_apply_options Source: https://github.com/rwengine/openrw/blob/main/rwviewer/CMakeLists.txt Applies a set of predefined build options to the 'rwviewer' target using a custom macro 'openrw_target_apply_options'. The options include CORE, COVERAGE, and installation-related settings like INSTALL and INSTALL_PDB. ```cmake openrw_target_apply_options( TARGET rwviewer CORE COVERAGE INSTALL INSTALL_PDB ) ``` -------------------------------- ### Install Conan Package Manager Source: https://github.com/rwengine/openrw/wiki/Building Installs the Conan package manager using pip, which is used for managing OpenRW dependencies. ```bash $ python -m pip install --user conan ``` -------------------------------- ### Install rwcore Shared Library (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Installs the 'rwcore' target as a shared library (if BUILD_SHARED_LIBS is enabled) to the appropriate installation directories for archives and libraries. ```cmake if(BUILD_SHARED_LIBS) install(TARGETS rwcore ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) endif() ``` -------------------------------- ### Install CMake on MinGW/MSYS2 Source: https://github.com/rwengine/openrw/wiki/Building Installs CMake for the MinGW-w64 environment on Windows if not already present. ```bash pacman -S mingw-w64-x86_64-cmake ``` -------------------------------- ### Extract CD Data with unshield (Linux) Source: https://github.com/rwengine/openrw/wiki/Preparing-the-game-data Extracts game data from the CD version of GTA3 using the 'unshield' tool on Linux. This command extracts files from 'data1.cab', automatically utilizing 'data1.hdr' and 'data2.cab'. The extracted game files are typically found in the 'App_Executables' folder. ```bash unshield x data1.cab ``` -------------------------------- ### Applying Build Options and Test Execution Logic (CMake) Source: https://github.com/rwengine/openrw/blob/main/tests/CMakeLists.txt This CMake snippet applies build options like CORE, COVERAGE, INSTALL, and INSTALL_PDB to the 'rwtests' target. It then conditionally sets up test execution, either running all tests individually or as a single suite. ```cmake openrw_target_apply_options( TARGET rwtests CORE COVERAGE INSTALL INSTALL_PDB ) if(SEPARATE_TEST_SUITES) foreach(TEST ${TESTS}) add_test( NAME "${TEST}" COMMAND "$" "-t" "${TEST}Tests" ) set_tests_properties("${TEST}" PROPERTIES TIMEOUT 300 ) endforeach() else() add_test(NAME UnitTests COMMAND "$" ) set_tests_properties(UnitTests PROPERTIES TIMEOUT 300 ) endif() if(TEST_DATA) add_test(NAME DataTests COMMAND "$" "--run_test=@data-test" ) endif() ``` -------------------------------- ### CMake Conditional Example Source: https://github.com/rwengine/openrw/wiki/Coding-Conventions An example demonstrating the use of conditional statements in CMake, including variable declaration and message output. ```cmake set(SOME_VAR FALSE) if(NOT SOME_VAR) message("SOME_VAR false") else() message("SOME_VAR not false") endif() ``` -------------------------------- ### Create RWENGINE Library and Link Dependencies (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwengine/CMakeLists.txt Defines the 'rwengine' library and links it to various external libraries including core, physics, audio, math, and graphics dependencies. Conditional linking for profiling is also shown. ```cmake add_library(rwengine ${RWENGINE_SOURCES} ) target_link_libraries(rwengine PUBLIC rwcore bullet::bullet ffmpeg::ffmpeg glm::glm OpenAL::OpenAL ) if (ENABLE_PROFILING) target_link_libraries(rwengine PUBLIC microprofile::microprofile ) endif() ``` -------------------------------- ### Build OpenRW with MinGW/MSYS Source: https://github.com/rwengine/openrw/wiki/Building This snippet demonstrates how to build the OpenRW project using MinGW and MSYS Makefiles. It involves creating a build directory, navigating into it, configuring the build with CMake, and then executing the make command. ```bash mkdir build cd build cmake .. -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release make ``` -------------------------------- ### Link Libraries for librwgame (Core) Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Links 'librwgame' to several libraries including 'openrw::interface', 'rwengine', 'Boost::program_options', and 'SDL2::SDL2'. These are essential dependencies for the game library's functionality. ```cmake target_link_libraries(librwgame PUBLIC openrw::interface rwengine Boost::program_options SDL2::SDL2 ) ``` -------------------------------- ### Configure File for GitSHA1 Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Configures a file named GitSHA1.cpp from a template GitSHA1.cpp.in, replacing placeholders with build information. ```cmake configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" @ONLY) ``` -------------------------------- ### Clone OpenRW Repository with Submodules Source: https://github.com/rwengine/openrw/wiki/Building Clones the OpenRW source code repository using Git, ensuring that all submodules are also downloaded. ```bash git clone --recursive https://github.com/rwengine/openrw.git openrw ``` -------------------------------- ### Linking Libraries to the 'rwviewer' Target Source: https://github.com/rwengine/openrw/blob/main/rwviewer/CMakeLists.txt Specifies the libraries that the 'rwviewer' executable depends on. It links against the custom 'rwengine' library and the Qt5 OpenGL and Qt5 Widgets modules, making them available for use within the application. ```cmake target_link_libraries(rwviewer PRIVATE rwengine Qt5::OpenGL Qt5::Widgets ) ``` -------------------------------- ### Build OpenRW with Conan Source: https://github.com/rwengine/openrw/wiki/Building Builds OpenRW using CMake, with Conan handling dependency management and specifying Release build type. ```bash mkdir build cd build conan install .. -s arch=x86_64 -s build_type=Release cmake .. -DUSE_CONAN=ON -DCMAKE_BUILD_TYPE=Release cmake --build . ``` -------------------------------- ### CMake Basic Settings and Module Loading Source: https://github.com/rwengine/openrw/blob/main/rwviewer/CMakeLists.txt Configures CMake's automatic handling of Qt's meta-object system and includes the current directory for header files. It then finds and requires the Qt5 OpenGL and Qt5 Widgets modules, which are essential for the GUI application. ```cmake set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5OpenGL REQUIRED) find_package(Qt5Widgets REQUIRED) ``` -------------------------------- ### Set Compiler for OpenBSD Source: https://github.com/rwengine/openrw/wiki/Building Configures the build process on OpenBSD to use egcc and eg++ by setting environment variables. ```bash export CC=egcc CXX=eg++ ``` -------------------------------- ### Set Include Directories for RWENGINE (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwengine/CMakeLists.txt Configures the include paths for the 'rwengine' target, allowing source files to find headers within the project's source directory. ```cmake target_include_directories(rwengine PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src" ) ``` -------------------------------- ### Add Static Library: librwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Defines a static library named 'librwgame' and lists all its source files. This includes game logic, rendering, input handling, and state management components. ```cmake add_library(librwgame STATIC GitSHA1.h "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" RWConfig.inc RWConfig.hpp RWConfig.cpp GameBase.hpp GameBase.cpp RWGame.hpp RWGame.cpp GameWindow.hpp GameWindow.cpp RWImGui.cpp RWImGui.hpp HUDDrawer.hpp HUDDrawer.cpp MenuSystem.hpp MenuSystem.cpp GameInput.hpp GameInput.cpp game.hpp WindowIcon.hpp StateManager.hpp StateManager.cpp State.hpp State.cpp states/LoadingState.hpp states/LoadingState.cpp states/IngameState.hpp states/IngameState.cpp states/PauseState.hpp states/PauseState.cpp states/MenuState.hpp states/MenuState.cpp states/DebugState.hpp states/DebugState.cpp states/BenchmarkState.hpp states/BenchmarkState.cpp ) ``` -------------------------------- ### Defining the 'rwviewer' Executable and its Source Files Source: https://github.com/rwengine/openrw/blob/main/rwviewer/CMakeLists.txt Defines the main executable target 'rwviewer' and lists all its C++ source and header files. The files are organized into different directories representing different parts of the viewer's functionality. ```cmake add_executable(rwviewer main.cpp ViewerWindow.hpp ViewerWindow.cpp models/AnimationListModel.hpp models/AnimationListModel.cpp models/ObjectListModel.hpp models/ObjectListModel.cpp models/DFFFramesTreeModel.hpp models/DFFFramesTreeModel.cpp models/IMGArchiveModel.hpp models/IMGArchiveModel.cpp models/ItemListModel.hpp models/ItemListModel.cpp models/TextModel.hpp models/TextModel.cpp views/ObjectViewer.hpp views/ObjectViewer.cpp views/ModelViewer.hpp views/ModelViewer.cpp views/TextViewer.hpp views/TextViewer.cpp views/WorldViewer.hpp views/WorldViewer.cpp views/ViewerInterface.hpp views/ViewerInterface.cpp QOpenGLContextWrapper.hpp QOpenGLContextWrapper.cpp ViewerWidget.hpp ViewerWidget.cpp widgets/AnimationListWidget.hpp widgets/AnimationListWidget.cpp widgets/ItemListWidget.hpp widgets/ItemListWidget.cpp widgets/ModelFramesWidget.hpp widgets/ModelFramesWidget.cpp ) ``` -------------------------------- ### Build OpenRW (Most Platforms) Source: https://github.com/rwengine/openrw/wiki/Building Compiles the OpenRW project using CMake, specifying a Release build type. ```bash mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . # For toolchains like Visual Studio and Xcode: cmake --build . --config Release ``` -------------------------------- ### Add ImGui Library and Configuration Source: https://github.com/rwengine/openrw/blob/main/external/imgui/CMakeLists.txt Defines the ImGui library target, specifying its source files, include directories, and compile definitions. It also creates an alias for easier referencing. ```cmake add_library(imgui EXCLUDE_FROM_ALL rw_imconfig.h imgui/imgui.h imgui/imgui.cpp imgui/imgui_demo.cpp imgui/imgui_draw.cpp imgui/imgui_internal.h imgui/imgui_widgets.cpp imgui/imstb_rectpack.h imgui/imstb_textedit.h imgui/imstb_truetype.h ) target_include_directories(imgui SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/imgui" ) target_compile_definitions(imgui PUBLIC IMGUI_USER_CONFIG="${CMAKE_CURRENT_SOURCE_DIR}/rw_imconfig.h" ) target_link_libraries(imgui PUBLIC openrw::checks ) add_library(imgui::core ALIAS imgui) openrw_target_apply_options( TARGET imgui ) ``` -------------------------------- ### Apply Options to librwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Applies build options like CORE and COVERAGE to the 'librwgame' target using a custom CMake function 'openrw_target_apply_options'. ```cmake openrw_target_apply_options( TARGET librwgame CORE COVERAGE ) ``` -------------------------------- ### Define rwcore Library (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Defines the 'rwcore' library using CMake's add_library command, listing all source files and headers. This includes GL-related files, core rw files, platform-specific files, data structures, font handling, and loaders. ```cmake add_library(rwcore # GL stuff is only here temporarily, hoping to move it back to rwengine gl/gl_core_3_3.c gl/gl_core_3_3.h gl/DrawBuffer.hpp gl/DrawBuffer.cpp gl/GeometryBuffer.hpp gl/GeometryBuffer.cpp gl/TextureData.hpp gl/TextureData.cpp rw/abort.cpp rw/casts.hpp rw/forward.hpp rw/types.hpp rw/debug.hpp platform/FileHandle.hpp platform/FileIndex.hpp platform/FileIndex.cpp data/Clump.hpp data/Clump.cpp fonts/FontMap.cpp fonts/FontMap.hpp fonts/FontMapGta3.cpp fonts/FontMapGta3.hpp fonts/GameTexts.cpp fonts/GameTexts.hpp fonts/Unicode.cpp fonts/Unicode.hpp loaders/LoaderIMG.hpp loaders/LoaderIMG.cpp loaders/RWBinaryStream.hpp loaders/LoaderDFF.hpp loaders/LoaderDFF.cpp loaders/LoaderSDT.hpp loaders/LoaderSDT.cpp loaders/LoaderTXD.hpp loaders/LoaderTXD.cpp ) ``` -------------------------------- ### Apply Build Options to rwcore (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Applies specific build options to the 'rwcore' target using a custom CMake function 'openrw_target_apply_options'. It enables CORE and COVERAGE, with exceptions for specific GL files. ```cmake openrw_target_apply_options(TARGET rwcore CORE COVERAGE COVERAGE_EXCEPT gl/gl_core_3_3.c gl/gl_core_3_3.h ) ``` -------------------------------- ### Create Visual Studio 2017 Solution with Conan Source: https://github.com/rwengine/openrw/wiki/Building This snippet shows how to generate a Visual Studio 2017 solution for OpenRW using a Python script and Conan. It requires Python and CMake to be in the system's PATH. The script takes the desired Visual Studio version, architecture, and output path as arguments. ```python python scripts/conan/create_vs_solution.py -v 2017 -a x64 "%SOLPATH%" ``` -------------------------------- ### Add ImGui SDL/OpenGL3 Backend Source: https://github.com/rwengine/openrw/blob/main/external/imgui/CMakeLists.txt Configures the ImGui backend for SDL and OpenGL3, including its source files, include paths, and dependencies on ImGui core and SDL2. It also sets a custom OpenGL loader path. ```cmake add_library(imgui_sdl_gl3 EXCLUDE_FROM_ALL imgui/examples/imgui_impl_opengl3.h imgui/examples/imgui_impl_opengl3.cpp imgui/examples/imgui_impl_sdl.h imgui/examples/imgui_impl_sdl.cpp ) target_include_directories(imgui_sdl_gl3 SYSTEM PUBLIC "${CMAKE_CURRENT_LIST_DIR}/imgui/examples" ) target_link_libraries(imgui_sdl_gl3 PUBLIC imgui::core SDL2::SDL2 ) # FIXME: extract gl loader to target + add property to get header target_compile_definitions(imgui_sdl_gl3 PRIVATE "IMGUI_IMPL_OPENGL_LOADER_CUSTOM=\"${OpenRW_SOURCE_DIR}/rwcore/gl/gl_core_3_3.h\"" ) add_library(imgui::sdl_gl3 ALIAS imgui_sdl_gl3) openrw_target_apply_options( TARGET imgui_sdl_gl3 ) ``` -------------------------------- ### Conditional Qt Configuration using Conan Source: https://github.com/rwengine/openrw/blob/main/rwviewer/CMakeLists.txt This block conditionally configures Qt settings if the 'USE_CONAN' variable is true. It sets the Qt5 root directory using a Conan-provided variable and generates a 'qt.conf' file from a template. ```cmake if(USE_CONAN) set(QT5_ROOT "${CONAN_QT_ROOT}") configure_file(qt.conf.in qt.conf) endif() ``` -------------------------------- ### Set Compile Definitions for librwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Defines the 'RW_IMGUI' preprocessor macro for the 'librwgame' target, likely enabling ImGui integration within the game library. ```cmake target_compile_definitions(librwgame PUBLIC RW_IMGUI ) ``` -------------------------------- ### CMake Build Options for OpenRW Source: https://github.com/rwengine/openrw/wiki/Building This section details how to use CMake to configure various build options for OpenRW. Options like BUILD_TESTS, BUILD_VIEWER, ENABLE_SANITIZERS, ENABLE_PROFILING, and TEST_COVERAGE can be enabled or disabled by appending them to the CMake command line with the -D flag. ```bash cmake .. -DBUILD_TESTS=ON ``` ```bash cmake .. -DBUILD_VIEWER=ON ``` ```bash cmake .. -DENABLE_SANITIZERS=ON ``` ```bash cmake .. -DENABLE_PROFILING=ON ``` ```bash cmake .. -DTEST_COVERAGE=ON ``` -------------------------------- ### Configuring Include Directories and Libraries (CMake) Source: https://github.com/rwengine/openrw/blob/main/tests/CMakeLists.txt This CMake code configures the include paths for the 'rwtests' executable and links it against necessary libraries, including the Boost unit testing framework and the project's 'librwgame'. ```cmake target_include_directories(rwtests PRIVATE "${PROJECT_SOURCE_DIR}/tests" "${PROJECT_SOURCE_DIR}/rwgame" ) target_link_libraries(rwtests PRIVATE Boost::unit_test_framework librwgame ) ``` -------------------------------- ### Link Libraries for librwgame (ImGui) Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Links 'librwgame' to 'imgui::sdl_gl3', specifying the ImGui library dependency for SDL and OpenGL 3. ```cmake target_link_libraries(librwgame PUBLIC imgui::sdl_gl3 ) ``` -------------------------------- ### CMake: Subdirectory and Build Configuration Source: https://github.com/rwengine/openrw/blob/main/CMakeLists.txt Manages the inclusion of subdirectories for different project components like 'external', 'rwcore', 'rwengine', and 'rwgame'. It conditionally adds subdirectories for 'rwviewer', 'tests', and 'rwtools' based on build flags. ```cmake add_subdirectory(external) add_subdirectory(rwcore) add_subdirectory(rwengine) add_subdirectory(rwgame) if(BUILD_VIEWER) add_subdirectory(rwviewer) endif() if(BUILD_TESTS) enable_testing() add_subdirectory(tests) endif() if(BUILD_TOOLS) add_subdirectory(rwtools) endif() ``` -------------------------------- ### Define RWENGINE Sources (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwengine/CMakeLists.txt Lists all source files (.cpp and .hpp) that will be compiled as part of the rwengine library. This is a common pattern in CMake for organizing project files. ```cmake set(RWENGINE_SOURCES src/ai/AIGraph.cpp src/ai/AIGraph.hpp src/ai/AIGraphNode.cpp src/ai/AIGraphNode.hpp src/ai/CharacterController.cpp src/ai/CharacterController.hpp src/ai/DefaultAIController.cpp src/ai/DefaultAIController.hpp src/ai/PlayerController.cpp src/ai/PlayerController.hpp src/ai/TrafficDirector.cpp src/ai/TrafficDirector.hpp src/audio/alCheck.cpp src/audio/alCheck.hpp src/audio/SfxParameters.cpp src/audio/SfxParameters.hpp src/audio/Sound.cpp src/audio/Sound.hpp src/audio/SoundBuffer.cpp src/audio/SoundBuffer.hpp src/audio/SoundBufferStreamed.cpp src/audio/SoundBufferStreamed.hpp src/audio/SoundManager.cpp src/audio/SoundManager.hpp src/audio/SoundSource.cpp src/audio/SoundSource.hpp src/core/Logger.cpp src/core/Logger.hpp src/core/Profiler.cpp src/core/Profiler.hpp src/data/AnimGroup.cpp src/data/AnimGroup.hpp src/data/Chase.cpp src/data/Chase.hpp src/data/CollisionModel.hpp src/data/CutsceneData.cpp src/data/CutsceneData.hpp src/data/InstanceData.hpp src/data/ModelData.cpp src/data/ModelData.hpp src/data/PathData.hpp src/data/PedData.cpp src/data/PedData.hpp src/data/VehicleGenerator.hpp src/data/WeaponData.hpp src/data/Weather.cpp src/data/Weather.hpp src/data/ZoneData.cpp src/data/ZoneData.hpp src/dynamics/CollisionInstance.cpp src/dynamics/CollisionInstance.hpp src/dynamics/HitTest.cpp src/dynamics/HitTest.hpp src/dynamics/RaycastCallbacks.hpp src/engine/Animator.cpp src/engine/Animator.hpp src/engine/GameData.cpp src/engine/GameData.hpp src/engine/GameInputState.hpp src/engine/GameState.cpp src/engine/GameState.hpp src/engine/GameWorld.cpp src/engine/GameWorld.hpp src/engine/Garage.cpp src/engine/Garage.hpp src/engine/Payphone.cpp src/engine/Payphone.hpp src/engine/SaveGame.cpp src/engine/SaveGame.hpp src/engine/ScreenText.cpp src/engine/ScreenText.hpp src/items/Weapon.cpp src/items/Weapon.hpp src/loaders/GenericDATLoader.cpp src/loaders/GenericDATLoader.hpp src/loaders/LoaderCOL.cpp src/loaders/LoaderCOL.hpp src/loaders/LoaderCutsceneDAT.cpp src/loaders/LoaderCutsceneDAT.hpp src/loaders/LoaderGXT.cpp src/loaders/LoaderGXT.hpp src/loaders/LoaderIDE.cpp src/loaders/LoaderIDE.hpp src/loaders/LoaderIFP.cpp src/loaders/LoaderIFP.hpp src/loaders/LoaderIPL.cpp src/loaders/LoaderIPL.hpp src/loaders/WeatherLoader.cpp src/loaders/WeatherLoader.hpp src/objects/CharacterObject.cpp src/objects/CharacterObject.hpp src/objects/CutsceneObject.cpp src/objects/CutsceneObject.hpp src/objects/GameObject.cpp src/objects/GameObject.hpp src/objects/InstanceObject.cpp src/objects/InstanceObject.hpp src/objects/ObjectTypes.hpp src/objects/PickupObject.cpp src/objects/PickupObject.hpp src/objects/ProjectileObject.cpp src/objects/ProjectileObject.hpp src/objects/VehicleInfo.hpp src/objects/VehicleObject.cpp src/objects/VehicleObject.hpp src/render/DebugDraw.cpp src/render/DebugDraw.hpp src/render/GameRenderer.cpp src/render/GameRenderer.hpp src/render/GameShaders.hpp src/render/MapRenderer.cpp src/render/MapRenderer.hpp src/render/ObjectRenderer.cpp src/render/ObjectRenderer.hpp src/render/OpenGLRenderer.cpp src/render/OpenGLRenderer.hpp src/render/TextRenderer.cpp src/render/TextRenderer.hpp src/render/ViewCamera.hpp src/render/ViewFrustum.cpp src/render/ViewFrustum.hpp src/render/VisualFX.cpp src/render/VisualFX.hpp src/render/WaterRenderer.cpp src/render/WaterRenderer.hpp src/script/SCMFile.cpp src/script/SCMFile.hpp src/script/ScriptFunctions.cpp src/script/ScriptFunctions.hpp src/script/ScriptMachine.cpp src/script/ScriptMachine.hpp src/script/ScriptModule.cpp src/script/ScriptModule.hpp src/script/ScriptTypes.cpp src/script/ScriptTypes.hpp src/script/modules/GTA3Module.cpp src/script/modules/GTA3Module.hpp src/script/modules/GTA3ModuleImpl.inl ) ``` -------------------------------- ### Update Git Submodules Source: https://github.com/rwengine/openrw/wiki/Building Initializes and updates Git submodules for OpenRW if the initial recursive clone fails or if submodules need to be refreshed. ```bash cd ./openrw git submodule init git submodule update ``` -------------------------------- ### Set Target Properties for librwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Sets the output name to 'rwgame' and the prefix to 'lib' for the 'librwgame' target, defining how the library file will be named. ```cmake set_target_properties(librwgame PROPERTIES OUTPUT_NAME "rwgame" PREFIX "lib" ) ``` -------------------------------- ### Set Include Directories (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Configures the include directories for the 'rwcore' target, making the current source directory publicly accessible for includes. ```cmake target_include_directories(rwcore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" ) ``` -------------------------------- ### Add Executable: rwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Defines the main game executable target 'rwgame' with 'main.cpp' as its primary source file. ```cmake add_executable(rwgame main.cpp ) ``` -------------------------------- ### Defining Test Executable and Sources (CMake) Source: https://github.com/rwengine/openrw/blob/main/tests/CMakeLists.txt This snippet defines the main executable 'rwtests' and lists its source files. It dynamically adds test-specific source files based on a predefined list of tests. ```cmake set(TESTS Animation Archive AudioLoading Buoyancy Character Chase Config Cutscene Data FileIndex GameData GameWorld Garage HitTest Input Items Lifetime LoaderDFF LoaderIDE LoaderIPL Logger Menu Object Payphone Pickup Renderer RWBStream SaveGame ScriptMachine State StringEncoding Sound Text TrafficDirector Vehicle ViewCamera VisualFX Weapon World ZoneData ) set(TEST_SOURCES main.cpp test_Globals.cpp test_Globals.hpp ) foreach(TEST ${TESTS}) list(APPEND TEST_SOURCES "test_${TEST}.cpp") endforeach() add_executable(rwtests ${TEST_SOURCES} ) ``` -------------------------------- ### Set Include Directories for librwgame Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Adds the current source directory to the public include directories for 'librwgame', allowing it to find header files within its own source tree. ```cmake target_include_directories(librwgame PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}" ) ``` -------------------------------- ### Link Executable rwgame to Library Source: https://github.com/rwengine/openrw/blob/main/rwgame/CMakeLists.txt Links the 'rwgame' executable to the 'librwgame' static library, making the game library's functionality available to the main executable. ```cmake target_link_libraries(rwgame PRIVATE librwgame ) ``` -------------------------------- ### C++ Input State Logic in OpenRW Source: https://github.com/rwengine/openrw/wiki/Tasks This C++ code snippet describes the logic for handling game input using a controller state. It checks for button presses by comparing the current and previous frame states and manages analog input ranges. The system abstracts user input mappings and allows access to raw keyboard and mouse states. ```c++ /* * For reference this is how GTA’s input system works in general: The game keeps two internal controllers (CPad) resembling PS2 pads that can be updated from physical game pads. They store the state of the last and the current frame. `!oldstate.button && newstate.button` is used to find pressed buttons. The analogs are in range -127 to 127. * Keyboard and mouse are mapped to these CPads depending on player mode (on foot, in vehicle, etc.). All subsystems that require input query the controller state on update. Functions are used to abstract the user’s mapping. Raw keyboard and mouse states are available as well (e.g. for PC-specific controls). The event handler updates a temporary state from the events, CPad::Update and related functions then copy the new state to the old state and the temporary state to the new state. */ // Example of checking for a pressed button: // !oldstate.button && newstate.button // Example of analog input range: // -127 to 127 ``` -------------------------------- ### Enable Script Debugging in OpenRW Source: https://github.com/rwengine/openrw/wiki/Development Configure OpenRW to trace script execution by enabling the script debug option. This prints each opcode, its thread, program counter, flags, and arguments. Output can be filtered by thread using an environment variable. ```Shell ENABLE_SCRIPT_DEBUG=1 OPENRW_DEBUG_THREAD= ``` -------------------------------- ### Link Libraries for rwcore (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Specifies the libraries that the 'rwcore' target depends on. It links Boost, glm, and 'openrw::interface' publicly, and OpenGL::GL privately. ```cmake target_link_libraries(rwcore PUBLIC Boost::boost glm::glm openrw::interface PRIVATE OpenGL::GL ) ``` -------------------------------- ### Link Microprofile with Dependencies Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Links the microprofile library with required external libraries. It finds the Threads package and links against Threads::Threads and openrw::checks. ```cmake find_package(Threads REQUIRED) target_link_libraries(microprofile PUBLIC Threads::Threads openrw::checks ) ``` -------------------------------- ### Force Software Rendering with Mesa Source: https://github.com/rwengine/openrw/wiki/FAQ This command forces the use of software rendering for OpenGL when using Mesa drivers. This can be a workaround if hardware acceleration does not meet the required OpenGL version for OpenRW. ```shell LIBGL_ALWAYS_SOFTWARE=1 ``` -------------------------------- ### Define Microprofile Library Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Adds the microprofile library as a static library to the CMake build system. It includes the necessary header and source files for the microprofile functionality. ```cmake add_library(microprofile STATIC microprofile/microprofile.h microprofile/microprofile_html.h microprofile/microprofile.cpp ) ``` -------------------------------- ### Add Windows Platform Sources (CMake) Source: https://github.com/rwengine/openrw/blob/main/rwcore/CMakeLists.txt Conditionally adds Windows-specific source files ('RWWindows.hpp', 'RWWindows.cpp') to the 'rwcore' target when building on a Windows platform (WIN32). ```cmake if(WIN32) target_sources(rwcore PRIVATE platform/RWWindows.hpp platform/RWWindows.cpp ) endif() ``` -------------------------------- ### Apply OpenRW Target Options Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Applies custom options defined by the openrw_target_apply_options macro to the microprofile target. This could include compiler flags or other project-specific settings. ```cmake openrw_target_apply_options( TARGET microprofile ) ``` -------------------------------- ### Set Microprofile Include Directories Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Specifies the include directories for the microprofile library. This allows the compiler to find header files located within the microprofile source directory. ```cmake target_include_directories(microprofile PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/microprofile" ) ``` -------------------------------- ### Load GTA III Saves in OpenRW Source: https://github.com/rwengine/openrw/wiki/Development OpenRW can load save files created with GTA III. Use the -l or --load command-line switch followed by the path to the .b save file to load a specific game state for debugging or development. ```Shell openrw --load /path/to/your/savefile.b ``` -------------------------------- ### Set Microprofile Target Properties Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Configures properties for the microprofile target. It disables C++ extensions and sets the C++ standard to C++11. ```cmake set_target_properties(microprofile PROPERTIES CXX_EXTENSIONS OFF CXX_STANDARD 11 ) ``` -------------------------------- ### Set Microprofile Compile Definitions Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Defines preprocessor macros for the microprofile library during compilation. Here, MICROPROFILE_GPU_TIMERS is set to 0, likely disabling GPU timing features. ```cmake target_compile_definitions(microprofile PUBLIC MICROPROFILE_GPU_TIMERS=0 ) ``` -------------------------------- ### Git Branch Update and Rebase Source: https://github.com/rwengine/openrw/wiki/Coding-Conventions Commands to update a local Git branch with changes from the upstream repository and resolve merge conflicts using rebase. ```git git remote add upstream https://github.com/rwengine/openrw git fetch upstream git rebase upstream/master git add -A git rebase --continue ``` -------------------------------- ### Create Microprofile Alias Target Source: https://github.com/rwengine/openrw/blob/main/external/microprofile/CMakeLists.txt Creates an alias target for the microprofile library. This allows referencing the library simply as 'microprofile::microprofile' throughout the CMake project. ```cmake add_library(microprofile::microprofile ALIAS microprofile) ``` -------------------------------- ### Override Mesa OpenGL Version Source: https://github.com/rwengine/openrw/wiki/FAQ This snippet demonstrates how to override the reported OpenGL version and GLSL version for Mesa drivers to potentially enable OpenRW compatibility. It addresses issues where the system reports an older OpenGL version than required. ```shell MESA_GL_VERSION_OVERRIDE=3.3 MESA_GLSL_VERSION_OVERRIDE=330 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.