diff --git a/.gitignore b/.gitignore index 02b4d67e..13bfb19f 100644 --- a/.gitignore +++ b/.gitignore @@ -69,4 +69,7 @@ Build/ intermediate/ Engine/Workspace submodules -Engine/.vs \ No newline at end of file +Engine/.vs +/Engine/vcpkg_installed +/.vs +/out diff --git a/.gitmodules b/.gitmodules index 310a9665..9a7bb0ff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,3 @@ -[submodule "submodules/FX11"] - path = submodules/FX11 - url = https://github.com/Microsoft/FX11 -[submodule "submodules/DXTK"] - path = submodules/DXTK - url = https://github.com/Microsoft/DirectXTK -[submodule "submodules/imgui"] - path = submodules/imgui - url = https://github.com/ocornut/imgui.git -[submodule "submodules/SOL2"] - path = submodules/SOL2 - url = https://github.com/ThePhD/sol2 [submodule "submodules/SelfLogger"] path = submodules/SelfLogger url = https://github.com/DecisionSolver/SelfLogger diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..86f1caf6 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.21) + +project(DS) + +add_compile_definitions( + DEBUG + _ENABLE_EXTENDED_ALIGNED_STORAGE + SOL_STRINGS_ARE_NUMBERS + WIN32_LEAN_AND_MEAN + _WIN32_WINNT=0x0601 + _WIN7_PLATFORM_UPDATE + WIN32 + XINPUT_USE_9_1_0 + IMGUI_DISABLE_OBSOLETE_FUNCTIONS + ZLIB_WINAPI + PX_PHYSX_STATIC_LIB + PX_PHYSX_GPU_STATIC + ASIO_STANDALONE + ASIO_HAS_IOCP + _WIN32_WINDOWS + ASIO_HAS_BOOST_DATE_TIME + _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS + _LIB + IMGUI_DEFINE_MATH_OPERATORS + CRYPTOPP_ENABLE_NAMESPACE_WEAK + RENDER_SYSTEM_DIRECTX_11 + without_multiplayer + +) +add_subdirectory(Engine/Common) +add_subdirectory(submodules) +add_subdirectory(Engine) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..3a57620f --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,59 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "windows-base", + "description": "Target Windows with the Visual Studio development environment.", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "C:/Users/HackMan/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake", + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-debug", + "displayName": "x64 Debug", + "description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)", + "inherits": "windows-base", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } + }, + { + "name": "x64-release", + "displayName": "x64 Release", + "description": "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)", + "inherits": "x64-debug", + "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } + }, + { + "name": "x86-debug", + "displayName": "x86 Debug", + "description": "Target Windows (32-bit) with the Visual Studio development environment. (Debug)", + "inherits": "windows-base", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } + }, + { + "name": "x86-release", + "displayName": "x86 Release", + "description": "Target Windows (32-bit) with the Visual Studio development environment. (RelWithDebInfo)", + "inherits": "x86-debug", + "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } + } + ] +} \ No newline at end of file diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt new file mode 100644 index 00000000..95a817ee --- /dev/null +++ b/Engine/CMakeLists.txt @@ -0,0 +1,10 @@ +set(CMAKE_CXX_STANDARD 17) + +add_subdirectory(Core) + +add_executable(Launcher) +target_link_libraries(Launcher + #ProjectSystem + Core +) + diff --git a/Engine/CMakePresets.json b/Engine/CMakePresets.json new file mode 100644 index 00000000..d63b921e --- /dev/null +++ b/Engine/CMakePresets.json @@ -0,0 +1,97 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "base-ninja", + "hidden": true, + "displayName": "Base Config", + "description": "Sets Ninja Multi-Config generator, compilers, x64 architecture, build and install directory, debug build type", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/Solutions/${presetName}", + "warnings": { "dev": false }, + "errors": { "dev": false }, + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "C:/Users/HackMan/source/repos/vcpkg/scripts/buildsystems/vcpkg.cmake", + "OPTION_RUNTIME_CVAR_OVERRIDES": "ON", + "OPTION_REMOTE_CONSOLE": "ON", + "OPTION_DX_RENDERER": "ON", + "OPTION_VK_RENDERER": "OFF", + "OPTION_BUILD_DOCS": "ON", + "USE_STEAM": "OFF", + "OPTION_DEDICATED_SERVER": "OFF", + + "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/Tools/CMake/toolchain/windows/WindowsPC-MSVC.cmake", + "VCPKG_TARGET_TRIPLET": "x64-windows", + "VCPKG_INSTALLER": "ON", + "DOWNLOAD_VCPKG": "ON", + "VCPKG_ROOT": { + "value": "${sourceDir}/vcpkg", + "type": "FILEPATH" + }, + + "ADD_PACKAGE_DEP_MODE": "OFF", + + "CMAKE_CONFIGURATION_TYPES": "Release;Debug;Profile" + }, + "environment": { + "solutionDir": "${sourceDir}/Solutions" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "hostOS": [ "Windows" ] + } + } + } + ], + "buildPresets": [ + { + "name": "windows-ninja-debug", + "configurePreset": "windows-ninja", + "configuration": "Debug" + }, + { + "name": "windows-ninja-release", + "configurePreset": "windows-ninja", + "configuration": "Release" + }, + { + "name": "vs2022-msvc-debug", + "configurePreset": "vs2022-msvc", + "configuration": "Debug" + }, + { + "name": "vs2022-msvc-release", + "configurePreset": "vs2022-msvc", + "configuration": "Release" + }, + { + "name": "vs2022-clang-debug", + "configurePreset": "vs2022-clang", + "configuration": "Debug" + }, + { + "name": "vs2022-clang-release", + "configurePreset": "vs2022-clang", + "configuration": "Release" + }, + { + "name": "vs2019-msvc-debug", + "configurePreset": "vs2019-msvc", + "configuration": "Debug" + }, + { + "name": "vs2019-msvc-release", + "configurePreset": "vs2019-msvc", + "configuration": "Release" + } + ] +} \ No newline at end of file diff --git a/Engine/CMakeUserPresets.json b/Engine/CMakeUserPresets.json new file mode 100644 index 00000000..4069ce9f --- /dev/null +++ b/Engine/CMakeUserPresets.json @@ -0,0 +1,39 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "ninja", + "inherits": "base-ninja", + "displayName": "Windows x64 Ninja Multi-Config", + "cacheVariables": { + "CMAKE_SYSTEM_VERSION": "10", + //"OPTION_SANDBOX": "ON", + "OPTION_STATIC_LINKING": "ON", + "OPTION_STATIC_LINKING_WITH_GAME_AS_DLL": "ON", + + "QT_SDK_ROOT": "C:", + "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/Tools/CMake/toolchain/windows/WindowsPC-MSVC.cmake", + "USE_MSVC": "ON" + + //"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/Tools/CMake/toolchain/windows/WindowsPC-Clang.cmake" + } + } + ], + "buildPresets": [ + { + "name": "ninja-debug", + "configurePreset": "ninja", + "configuration": "Debug" + }, + { + "name": "ninja-release", + "configurePreset": "ninja", + "configuration": "Release" + } + ] +} \ No newline at end of file diff --git a/Engine/Core/Audio System/Audio.h b/Engine/Common/AudioSystem/Audio.h similarity index 100% rename from Engine/Core/Audio System/Audio.h rename to Engine/Common/AudioSystem/Audio.h diff --git a/Engine/Core/Audio System/WASAPICapture.h b/Engine/Common/AudioSystem/WASAPICapture.h similarity index 100% rename from Engine/Core/Audio System/WASAPICapture.h rename to Engine/Common/AudioSystem/WASAPICapture.h diff --git a/Engine/Common/CMakeLists.txt b/Engine/Common/CMakeLists.txt new file mode 100644 index 00000000..1e62c830 --- /dev/null +++ b/Engine/Common/CMakeLists.txt @@ -0,0 +1,73 @@ +add_library(CoreInterface INTERFACE) + +find_package(assimp CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE assimp::assimp) + +find_package(Boost COMPONENTS system filesystem REQUIRED) +target_link_libraries(CoreInterface INTERFACE Boost::boost Boost::filesystem) + +find_package(directxtk CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE Microsoft::DirectXTK) + +find_package(dxsdk-d3dx CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE Microsoft::D3DX9 Microsoft::D3DX10 Microsoft::D3DX11) + +find_package(effects11 CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE Microsoft::Effects11) + +find_package(Lua REQUIRED) +target_include_directories(CoreInterface INTERFACE ${LUA_INCLUDE_DIR}) +target_link_libraries(CoreInterface INTERFACE ${LUA_LIBRARIES}) + +find_package(imgui CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE imgui::imgui) + +find_package(tinyxml2 CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE tinyxml2::tinyxml2) + +find_package(sol2 CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE sol2::sol2) + +find_package(nlohmann_json CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE nlohmann_json::nlohmann_json) + +find_package(dxut CONFIG REQUIRED) +target_link_libraries(CoreInterface INTERFACE Microsoft::DXUT Microsoft::DXUTOpt) + +target_link_libraries(CoreInterface INTERFACE Winmm) +target_link_libraries(CoreInterface INTERFACE SelfLogger) + +target_precompile_headers(CoreInterface + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/../Core/pch.h +) + +target_include_directories(CoreInterface + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../Core/Include +) + +add_compile_definitions( + DEBUG + _ENABLE_EXTENDED_ALIGNED_STORAGE + SOL_STRINGS_ARE_NUMBERS + WIN32_LEAN_AND_MEAN + _WIN32_WINNT=0x0601 + _WIN7_PLATFORM_UPDATE + WIN32 + XINPUT_USE_9_1_0 + IMGUI_DISABLE_OBSOLETE_FUNCTIONS + ZLIB_WINAPI + PX_PHYSX_STATIC_LIB + PX_PHYSX_GPU_STATIC + ASIO_STANDALONE + ASIO_HAS_IOCP + _WIN32_WINDOWS + ASIO_HAS_BOOST_DATE_TIME + _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS + _LIB + IMGUI_DEFINE_MATH_OPERATORS + CRYPTOPP_ENABLE_NAMESPACE_WEAK + RENDER_SYSTEM_DIRECTX_11 + without_multiplayer +) diff --git a/Engine/Core/Engine.h b/Engine/Common/Engine.h similarity index 98% rename from Engine/Core/Engine.h rename to Engine/Common/Engine.h index 357c5f4b..c23000c7 100644 --- a/Engine/Core/Engine.h +++ b/Engine/Common/Engine.h @@ -1,11 +1,10 @@ #pragma once #if !defined(__ENGINE_H__) #define __ENGINE_H__ -#include "pch.h" -#include -#include -#include +#include +#include +#include #include "../resource.h" #include "Timer.h" diff --git a/Engine/Common/FileSystem/FileWatcher/FileWatcher.h b/Engine/Common/FileSystem/FileWatcher/FileWatcher.h new file mode 100644 index 00000000..ca4163b9 --- /dev/null +++ b/Engine/Common/FileSystem/FileWatcher/FileWatcher.h @@ -0,0 +1,147 @@ +/** + Main header for the FileWatcher class. Declares all implementation + classes to reduce compilation overhead. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef _FW_FILEWATCHER_H_ +#define _FW_FILEWATCHER_H_ +#pragma once + +#include +#include + +namespace FW +{ + /// Type for a string + typedef std::string String; + + /// Type for a watch id + typedef unsigned long WatchID; + + // forward declarations + class FileWatcherImpl; + class FileWatchListener; + + /// Base exception class + /// @class Exception + class Exception : public std::runtime_error + { + public: + Exception(const std::string& message) + : std::runtime_error(message) + {} + }; + + /// Exception thrown when a file is not found. + /// @class FileNotFoundException + class FileNotFoundException : public Exception + { + public: + FileNotFoundException() + : Exception("File not found") + {} + + FileNotFoundException(const String& filename) + : Exception("File not found (" + std::string(filename.begin(), filename.end()) + ")") + {} + }; + + /// Actions to listen for. Rename will send two events, one for + /// the deletion of the old file, and one for the creation of the + /// new file. + namespace Actions + { + enum Action + { + /// Sent when a file is created or renamed + Add = 1, + /// Sent when a file is deleted or renamed + Delete = 2, + /// Sent when a file is modified + Modified = 4 + }; + }; + typedef Actions::Action Action; + + /// Listens to files and directories and dispatches events + /// to notify the parent program of the changes. + /// @class FileWatcher + class FileWatcher + { + public: + /// + /// + FileWatcher(); + + /// + /// + virtual ~FileWatcher(); + + /// Add a directory watch. Same as the other addWatch, but doesn't have recursive option. + /// For backwards compatibility. + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher); + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + private: + /// The implementation + FileWatcherImpl* mImpl; + + };//end FileWatcher + + + /// Basic interface for listening for file events. + /// @class FileWatchListener + class FileWatchListener + { + public: + FileWatchListener() {} + virtual ~FileWatchListener() {} + + /// Handles the action file action + /// @param watchid The watch id for the directory + /// @param dir The directory + /// @param filename The filename that was accessed (not full path) + /// @param action Action that was performed + virtual void handleFileAction(WatchID watchid, const String& dir, const String& filename, Action action) = 0; + + };//class FileWatchListener + +};//namespace FW + +#endif//_FW_FILEWATCHER_H_ diff --git a/Engine/Common/FileSystem/FileWatcher/FileWatcherImpl.h b/Engine/Common/FileSystem/FileWatcher/FileWatcherImpl.h new file mode 100644 index 00000000..082665c9 --- /dev/null +++ b/Engine/Common/FileSystem/FileWatcher/FileWatcherImpl.h @@ -0,0 +1,79 @@ +/** + Basic interface for the FileWatcher backend. + + @author James Wynn + @date 5/11/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +#ifndef _FW_FILEWATCHERIMPL_H_ +#define _FW_FILEWATCHERIMPL_H_ +#pragma once + +#include "FileWatcher.h" + +#define FILEWATCHER_PLATFORM_WIN32 1 +#define FILEWATCHER_PLATFORM_LINUX 2 +#define FILEWATCHER_PLATFORM_KQUEUE 3 + +#if defined(_WIN32) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_WIN32 +#elif defined(__APPLE_CC__) || defined(BSD) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_KQUEUE +#elif defined(__linux__) +# define FILEWATCHER_PLATFORM FILEWATCHER_PLATFORM_LINUX +#endif + +namespace FW +{ + struct WatchStruct; + + class FileWatcherImpl + { + public: + /// + /// + FileWatcherImpl() {} + + /// + /// + virtual ~FileWatcherImpl() {} + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + virtual WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive) = 0; + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + virtual void removeWatch(const String& directory) = 0; + + /// Remove a directory watch. This is a map lookup O(logn). + virtual void removeWatch(WatchID watchid) = 0; + + /// Updates the watcher. Must be called often. + virtual void update() = 0; + + /// Handles the action + virtual void handleAction(WatchStruct* watch, const String& filename, unsigned long action) = 0; + + };//end FileWatcherImpl +};//namespace FW + +#endif//_FW_FILEWATCHERIMPL_H_ diff --git a/Engine/Common/FileSystem/FileWatcher/FileWatcherLinux.h b/Engine/Common/FileSystem/FileWatcher/FileWatcherLinux.h new file mode 100644 index 00000000..f77b9c41 --- /dev/null +++ b/Engine/Common/FileSystem/FileWatcher/FileWatcherLinux.h @@ -0,0 +1,91 @@ +/** + Implementation header file for Linux based on inotify. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +#ifndef _FW_FILEWATCHERLINUX_H_ +#define _FW_FILEWATCHERLINUX_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_LINUX + +#include +#include + +namespace FW +{ + /// Implementation for Linux based on inotify. + /// @class FileWatcherLinux + class FileWatcherLinux : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherLinux(); + + /// + /// + virtual ~FileWatcherLinux(); + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The last watchid + WatchID mLastWatchID; + /// inotify file descriptor + int mFD; + /// time out data + struct timeval mTimeOut; + /// File descriptor set + fd_set mDescriptorSet; + + };//end FileWatcherLinux + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_LINUX + +#endif//_FW_FILEWATCHERLINUX_H_ diff --git a/Engine/Common/FileSystem/FileWatcher/FileWatcherOSX.h b/Engine/Common/FileSystem/FileWatcher/FileWatcherOSX.h new file mode 100644 index 00000000..6e31c5ad --- /dev/null +++ b/Engine/Common/FileSystem/FileWatcher/FileWatcherOSX.h @@ -0,0 +1,89 @@ +/** + Implementation header file for OSX based on KEvent. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +#ifndef _FW_FILEWATCHEROSX_H_ +#define _FW_FILEWATCHEROSX_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_KQUEUE + +#include +#include + +namespace FW +{ + /// Implementation for OSX based on kqueue. + /// @class FileWatcherOSX + class FileWatcherOSX : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherOSX(); + + /// + /// + virtual ~FileWatcherOSX(); + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The descriptor for the kqueue + int mDescriptor; + /// time out data + struct timespec mTimeOut; + /// WatchID allocator + int mLastWatchID; + + };//end FileWatcherOSX + +};//namespace FW + +#endif//__APPLE_CC__ + +#endif//_FW_FILEWATCHEROSX_H_ diff --git a/Engine/Common/FileSystem/FileWatcher/FileWatcherWin32.h b/Engine/Common/FileSystem/FileWatcher/FileWatcherWin32.h new file mode 100644 index 00000000..4a349fc3 --- /dev/null +++ b/Engine/Common/FileSystem/FileWatcher/FileWatcherWin32.h @@ -0,0 +1,85 @@ +/** + Implementation for Windows. Uses ReadDirectoryChangesW to watch for + file system changes. + + @author James Wynn + @date 4/15/2009 + + Copyright (c) 2009 James Wynn (james@jameswynn.com) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +#ifndef _FW_FILEWATCHERWIN32_H_ +#define _FW_FILEWATCHERWIN32_H_ +#pragma once + +#include "FileWatcherImpl.h" + +#if FILEWATCHER_PLATFORM == FILEWATCHER_PLATFORM_WIN32 + +#include + +namespace FW +{ + /// Implementation for Win32 based on ReadDirectoryChangesW. + /// @class FileWatcherWin32 + class FileWatcherWin32 : public FileWatcherImpl + { + public: + /// type for a map from WatchID to WatchStruct pointer + typedef std::map WatchMap; + + public: + /// + /// + FileWatcherWin32(); + + /// + /// + virtual ~FileWatcherWin32(); + + /// Add a directory watch + /// @exception FileNotFoundException Thrown when the requested directory does not exist + WatchID addWatch(const String& directory, FileWatchListener* watcher, bool recursive); + + /// Remove a directory watch. This is a brute force lazy search O(nlogn). + void removeWatch(const String& directory); + + /// Remove a directory watch. This is a map lookup O(logn). + void removeWatch(WatchID watchid); + + /// Updates the watcher. Must be called often. + void update(); + + /// Handles the action + void handleAction(WatchStruct* watch, const String& filename, unsigned long action); + + private: + /// Map of WatchID to WatchStruct pointers + WatchMap mWatches; + /// The last watchid + WatchID mLastWatchID; + + };//end FileWatcherWin32 + +};//namespace FW + +#endif//FILEWATCHER_PLATFORM_WIN32 + +#endif//_FW_FILEWATCHERWIN32_H_ diff --git a/Engine/Common/FileSystem/File_system.h b/Engine/Common/FileSystem/File_system.h new file mode 100644 index 00000000..789b5507 --- /dev/null +++ b/Engine/Common/FileSystem/File_system.h @@ -0,0 +1,381 @@ +/** + * \file File_system.h. + * + * \brief Declares the file system class + */ + +#pragma once +#if !defined(__FILE_SYSTEM_H__) +#define __FILE_SYSTEM_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace boost::algorithm; + +#include + +#include + +using namespace std; +using namespace boost::filesystem; +using namespace boost::iostreams; + +/** + * \enum _TypeOfFile + * + * \brief Values that represent type of files + */ + +enum _TypeOfFile { MODELS = 1, TEXTURES, LEVELS, DIALOGS, SOUNDS, SHADERS, UIS, SCRIPTS, FONTS, PROJECT, NONE }; + +/** + * \class File_system + * + * \brief A file system. + * + * \author PBAX + * \date 25.02.2020 + */ + +class Level; +class File_system +{ +#if defined (DS_Engine) +private: + class UpdateListener: public FW::FileWatchListener + { + public: + UpdateListener() {} + void handleFileAction(FW::WatchID watchid, const FW::String& dir, const FW::String& filename, + FW::Action action); + }; + UpdateListener listener; + FW::FileWatcher fileWatcher; +#endif + +public: + /** \brief The work dir */ + path WorkDir; + static path WorkDirSources; + /** \brief The Project For SDK */ + + /** + * \struct AllFile + * + * \brief Struct Of Files. + * + * \author PBAX + * \date 25.02.2020 + */ + + struct File + { + File() {} + File(const path &new_Path, const path &new_Ext, const path &new_File, const size_t &new_Size, + const _TypeOfFile &new_TypeOfFile, bool if_HasTextures = false, const std::string &hash = {}): + Path(new_Path), Ext(new_Ext), FName(new_File), + Size(new_Size), TypeOfFile(new_TypeOfFile), HasTextures(if_HasTextures), + Hash(hash) {} + + // Full Path To Required File + path Path = {}, Ext = {}, FName = {}; + + bool HasTextures = false; + + size_t Size = 0; + + std::string Hash = {}; + + _TypeOfFile TypeOfFile = _TypeOfFile::NONE; + }; + vector, path/*IDPath*/>> + Models, + Textures, + Levels, + Dialogs, + Sounds, + Shaders, + Uis, + Scripts, + Fonts, + None; +public: + void Update(); + + /** + * \fn File_system::File_system(); + * + * \brief Default Ctor Which Scan Files And Get Main Path + * + * \author PBAX + * \date 25.02.2020 + */ + + File_system(); + ~File_system() {} + + /** + * \fn void File_system::ScanFiles(); + * + * \brief Scan Files And Add To Engine + * + * \author PBAX + * \date 25.02.2020 + */ + + void ScanFiles(); + + /** + * \fn void File_system::RescanFilesByType(const _TypeOfFile &T); + * + * \brief Rescan Files By Type + * + * \author PBAX + * \date 25.02.2020 + * + * \param T A _TypeOfFile to process. + */ + + void RescanFilesByType(const _TypeOfFile &T); + + /** + * \fn shared_ptr File_system::GetFile(path File); + * + * \brief Gets a file + * + * \author PBAX + * \date 25.02.2020 + * + * \param File The file. + * + * \returns The file. + */ + + shared_ptr GetFile(path File); + + /** + * \fn shared_ptr File_system::AddFile(path File, + pair>> &ListTextures = pair>>()); + * + * \brief Adds a file + * + * \author PBAX + * \date 25.02.2020 + * + * \param File The file. + * + * \returns A shared_ptr<AllFile::File> + */ + +#if defined (DS_Engine) + shared_ptr AddFile(path File, pair>> &ListTextures); +#else + shared_ptr AddFile(path File); +#endif + + // Arg "File" Need To Have fullpath! + shared_ptr OnlyAddFile(const path &File); + + /** + * \fn vector, path>> File_system::GetFileByType(const _TypeOfFile &T); + * + * \brief Get File By Type + * + * \author PBAX + * \date 25.02.2020 + * + * \param T A _TypeOfFile to process. + * + * \returns The file by type. + */ + + vector, path>> GetFileByType(const _TypeOfFile &T); + + /** + * \fn vector File_system::getFilesInFolderW(path Folder); + * + * \brief Get Massive Files In Resource Folder + * + * \author PBAX + * \date 29.02.2020 + * + * \param Folder Pathname of the folder. boost::path + * + * \returns Massive Files Of Needed Folder. + */ + + vector getFilesInFolder(const path &Folder); + + /** + * \fn vector File_system::getFilesInFolder(const path &Folder, bool Recursive = false, bool onlyFile = false); + * + * \brief Get Massive Files In Resource Folder + * + * \author PBAX + * \date 29.02.2020 + * + * \param Folder Pathname of the folder. boost::path + * \param Recursive (Optional) True to process recursively, false to process locally only. + * \param onlyFile (Optional) True to only file. + * + * \returns Massive Files Of Needed Folder. + */ + + vector getFilesInFolder(const path &Folder, bool Recursive = false, bool onlyFile = false); + + /** + * \fn string File_system::getDataFromFile(const string &File, const string &start = ""); + * + * \brief Get Data (In String) From File + * + * \author PBAX + * \date 29.02.2020 + * + * \param File Needed File. + * \param start (Optional) The start. + * \param end (Optional) The end. + * + * \returns String Data File. + * + * ### param LineByline True to line byline. + */ + + string getDataFromFile(const string &File, const string &start = ""); + + /** + * \fn vector File_system::getDataFromFileVector(const string &File, bool LineByline); + * + * \brief Get Data (In Massive String) From File + * + * \author PBAX + * \date 29.02.2020 + * + * \param File Needed File. + * \param LineByline True To Read Line By Line. + * + * \returns Massive Strings File. + */ + + vector getDataFromFileVector(const string &File, bool LineByline); + + /** + * \fn bool File_system::ReadFileMemory(const LPCSTR &filename, size_t &FileSize, vector &FilePtr); + * + * \brief Reads file memory + * + * \author PBAX + * \date 29.02.2020 + * + * \param filename Filename of the file. Ansi + * \param [in,out] FileSize If non-null, size of the file. + * \param [in,out] FilePtr If non-null, the file pointer. + * + * \returns True if it succeeds, false if it fails. + */ + + static bool ReadFileMemory(const LPCSTR &filename, size_t &FileSize, vector &FilePtr); + + /** + * \fn _TypeOfFile File_system::GetTypeFileByExt(const path &File); + * + * \brief Constructor + * + * \author PBAX + * \date 29.02.2020 + * + * \param File The file. + */ + + _TypeOfFile GetTypeFileByExt(const path &File); + + /** + * \fn shared_ptr File_system::GetFileByPath(const path &File); + * + * \brief Gets file by path + * + * \author PBAX + * \date 29.02.2020 + * + * \param File The file. + * + * \returns The file by path. + */ + + shared_ptr GetFileByPath(const path &File); + + // Checking If Given Hash Has In File System And FileName Exists And Has The Same Hash! + // Returns Found File By Hash + std::pair> IsSame(const std::string &FileName, std::string &Hash); + + /** + * \fn auto static File_system::GetCurrentPath() + * + * \brief Gets current path + * + * \author PBAX + * \date 29.02.2020 + * + * \returns The current path. + */ + + string GetCurrentPath() { return WorkDir.generic_string() + ((WorkDir.generic_string().back() == '/') ? "" : "/"); } + + /** + * \fn string File_system::getPathFromType(const _TypeOfFile &T); + * + * \brief Gets path from type + * + * \author PBAX + * \date 29.02.2020 + * + * \param T A _TypeOfFile to process. + * + * \returns The path from type. + */ + + static string getPathFromType(const _TypeOfFile &T); + + /** + * \fn void File_system::CreateProject(const std::string &Name) + * + * \brief Create Project + * + * \author PBAX + * \date 29.02.2020 + * + * \param Name The Current In DB Table. + */ + + boost::property_tree::ptree LoadSettingsFile(); + void SaveSettings(const vector> &ToFile); + + const string getWorkDirSource() { return WorkDirSources.generic_string(); } + + const std::string SetPathFTP(); + const std::string GetFTPPath(); + + void SetupLogs(); + + /** + * \fn shared_ptr File_system::Find(path File); + * + * \brief Searches for the first match for the given path + * + * \author PBAX + * \date 25.02.2020 + * + * \param File The file. + * + * \returns A shared_ptr; + */ + + shared_ptr Find(const path &File, bool AlsoAddFile = true); +}; +#endif // !__FILE_SYSTEM_H__ diff --git a/Engine/Common/Include/Timer.cpp b/Engine/Common/Include/Timer.cpp new file mode 100644 index 00000000..0989caf2 --- /dev/null +++ b/Engine/Common/Include/Timer.cpp @@ -0,0 +1,175 @@ +#include "..\pch.h" +#include "Timer.h" +#include +#include + +std::atomic_bool m_threadExit{ false }; +class Engine; +extern shared_ptr Application; +#include "Engine.h" + +void Timer::Tick(function update) +{ + setFunc(update); + + m_thread = thread([&]() + { + while (m_running) + { + // Query the current time. + LARGE_INTEGER currentTime; + + QueryPerformanceCounter(¤tTime); + + UINT64 timeDelta = currentTime.QuadPart - m_qpcLastTime.QuadPart; + + m_qpcLastTime = currentTime; + m_qpcSecondCounter += timeDelta; + + // Clamp excessively large time deltas (e.g. after paused in the debugger). + if (timeDelta > m_qpcMaxDelta) + { + timeDelta = m_qpcMaxDelta; + } + + // Convert QPC units into a canonical tick format. This cannot overflow due to the previous clamp. + timeDelta *= TicksPerSecond; + timeDelta /= m_qpcFrequency.QuadPart; + + UINT32 lastFrameCount = m_frameCount; + + if (m_isFixedTimeStep) + { + // Fixed timestep update logic + + // If the app is running very close to the target elapsed time (within 1/4 of a millisecond) just clamp + // the clock to exactly match the target value. This prevents tiny and irrelevant errors + // from accumulating over time. Without this clamping, a game that requested a 60 fps + // fixed update, running with vsync enabled on a 59.94 NTSC display, would eventually + // accumulate enough tiny errors that it would drop a frame. It is better to just round + // small deviations down to zero to leave things running smoothly. + + if (abs(static_cast(timeDelta - m_targetElapsedTicks)) < TicksPerSecond / 4000) + timeDelta = m_targetElapsedTicks; + + m_leftOverTicks += timeDelta; + + while (m_leftOverTicks >= m_targetElapsedTicks) + { + m_elapsedTicks = m_targetElapsedTicks; + m_totalTicks += m_targetElapsedTicks; + m_leftOverTicks -= m_targetElapsedTicks; + m_frameCount++; + + if (Application && Application->getThreadState() != Engine::ThreadStatus::_Quit) + { + m_running = m_func(); + if (!m_running) + break; + } + else + break; + } + + //if (!SkipDial) + // if (m_targetElapsedTicks == 0 || + // m_targetElapsedTicks >= m_qpcMaxDelta || + // m_leftOverTicks >= m_qpcMaxDelta) + // { + // OutputDebugStringA("Maybe Endless Loop?\n"); + // int Btn = MessageBoxA(0, "Maybe Endless Loop?\nTry to skip it?", "Warning", + // MB_CANCELTRYCONTINUE | MB_ICONWARNING | MB_DEFBUTTON2); + // switch (Btn) + // { + // case IDCONTINUE: + // return; + // case IDTRYAGAIN: + // // Check For Stuck In SetFixedTimer + // SetFixedTimeStep(false); + // SetTargetElapsedSeconds(0.f); + // m_targetElapsedTicks = 0; + // ResetElapsedTime(); + // break; + // case IDCANCEL: + // SkipDial = true; + // break; + // } + // } + } + else + { + // Variable timestep update logic. + m_elapsedTicks = timeDelta; + m_totalTicks += timeDelta; + m_leftOverTicks = 0; + m_frameCount++; + + if (Application && Application->getThreadState() != Engine::ThreadStatus::_Quit) + { + m_running = m_func(); + if (!m_running) + break; + } + else + break; + } + + // Track the current framerate. + if (m_frameCount != lastFrameCount) + m_framesThisSecond++; + + if (m_qpcSecondCounter >= static_cast(m_qpcFrequency.QuadPart)) + { + m_framesPerSecond = m_framesThisSecond; + m_framesThisSecond = 0; + m_qpcSecondCounter %= m_qpcFrequency.QuadPart; + } + } + + m_threadExit = true; +// cv.notify_one(); + }); + m_thread.detach(); +} + +Timer *Timer::setFunc(function func) +{ + if (!m_func.operator bool()) + m_func = func; + return this; +} + +void Timer::SetTargetElapsedTicks(UINT64 targetElapsed) +{ + if (targetElapsed == 0 || targetElapsed <= 0) + { + SkipDial = false; + return; + } + else + m_targetElapsedTicks = targetElapsed; +} + +void Timer::SetTargetElapsedSeconds(float targetElapsed) +{ + if (targetElapsed == 0 || targetElapsed <= 0) + { + SkipDial = false; + return; + } + else + m_targetElapsedTicks = SecondsToTicks(targetElapsed); +} + +void Timer::ResetElapsedTime() +{ + QueryPerformanceCounter(&m_qpcLastTime); + + m_leftOverTicks = 0; + m_framesPerSecond = 0; + m_framesThisSecond = 0; + m_qpcSecondCounter = 0; + + stop(); + Tick(m_func); +} diff --git a/Engine/Common/Include/Timer.h b/Engine/Common/Include/Timer.h new file mode 100644 index 00000000..fe1ea3e5 --- /dev/null +++ b/Engine/Common/Include/Timer.h @@ -0,0 +1,143 @@ +/* + COPYRIGHT © 2018 Ringo Hoffmann (zekro Development) + READ BEFORE USING: https://zekro.de/policy +*/ + +#pragma once +#include "..\pch.h" +#include + +/** + * Create asynchronous timers which execute specified + * functions in set time interval. + * + * @param func Function which sould be executed + * @param interval Interval of time in which function will be executed + * (in milliseconds) + */ +class Timer +{ +public: + Timer(std::function func) { m_func = func; } + Timer(): + m_elapsedTicks(0), + m_totalTicks(0), + m_leftOverTicks(0), + m_frameCount(0), + m_framesPerSecond(0), + m_framesThisSecond(0), + m_qpcSecondCounter(0), + m_isFixedTimeStep(false), + m_targetElapsedTicks(TicksPerSecond / 60) + { + QueryPerformanceFrequency(&m_qpcFrequency); + QueryPerformanceCounter(&m_qpcLastTime); + + // Initialize max delta to 1/10 of a second. + m_qpcMaxDelta = m_qpcFrequency.QuadPart / 1; + } + ~Timer() { stop(); } + + /* + * Stopping the timer and destroys the thread. + */ + void stop() + { + m_running = false; + m_func = nullptr; + } + + /* + * Check if timer is running. + * + * @returns boolean is running + */ + bool isRunning() { return m_running; } + + bool IsThreadEnd() { return m_thread.joinable(); } + + /* + * Set the method of the timer after + * initializing the timer instance. + * + * @returns boolean is running + * @return Timer reference of this + */ + Timer *setFunc(std::function func); + + // Get elapsed time since the previous Update call. + UINT64 GetElapsedTicks() const { return m_elapsedTicks; } + float GetElapsedSeconds() const { return TicksToSeconds(m_elapsedTicks); } + + // Get total time since the start of the program. + UINT64 GetTotalTicks() const { return m_totalTicks; } + float GetTotalSeconds() const { return TicksToSeconds(m_totalTicks); } + + // Get total number of updates since start of the program. + UINT32 GetFrameCount() const { return m_frameCount; } + + // Get the current framerate. + UINT32 GetFramesPerSecond() const { return m_framesPerSecond; } + + // Set whether to use fixed or variable timestep mode. + void SetFixedTimeStep(bool isFixedTimestep) { m_isFixedTimeStep = isFixedTimestep; } + + bool GetIsFixedTimeStep() { return m_isFixedTimeStep; } + + // Set how often to call Update when in fixed timestep mode. + void SetTargetElapsedTicks(UINT64 targetElapsed); + void SetTargetElapsedSeconds(float targetElapsed); + + // Integer format represents time using 10,000,000 ticks per second. + static const UINT64 TicksPerSecond = 10000000; + + static float TicksToSeconds(UINT64 ticks) { return static_cast(ticks) / TicksPerSecond; } + static UINT64 SecondsToTicks(float seconds) { return static_cast(seconds * TicksPerSecond); } + + // After an intentional timing discontinuity (for instance a blocking IO operation) + // call this to avoid having the fixed timestep logic attempt a set of catch-up + // Update calls. + + void ResetElapsedTime(); + + // Update timer state, calling the specified Update function the appropriate number of times. + void Tick(std::function update); + + void BeginTime() { begin = chrono::high_resolution_clock::now(); } + + void EndTime() { end = chrono::high_resolution_clock::now(); } + chrono::duration GetResultTime() { return end - begin; } + + bool IsNotFunc() { return !m_func.operator bool(); } +private: + // Source timing data uses QPC units. + LARGE_INTEGER m_qpcFrequency; + LARGE_INTEGER m_qpcLastTime; + UINT64 m_qpcMaxDelta; + + // Derived timing data uses a canonical tick format. + UINT64 m_elapsedTicks; + UINT64 m_totalTicks; + UINT64 m_leftOverTicks; + + // Members for tracking the framerate. + UINT32 m_frameCount; + UINT32 m_framesPerSecond; + UINT32 m_framesThisSecond; + UINT64 m_qpcSecondCounter; + + // Function to be executed fater interval + std::function m_func; + + // Thread timer is running into + std::thread m_thread; + // Status if timer is running + bool m_running = true; + + // Members for configuring fixed timestep mode. + bool m_isFixedTimeStep, SkipDial = false; + UINT64 m_targetElapsedTicks; + + chrono::time_point begin, end; + condition_variable wait; +}; \ No newline at end of file diff --git a/Engine/Common/Include/X3DAudio.h b/Engine/Common/Include/X3DAudio.h new file mode 100644 index 00000000..7eab922f --- /dev/null +++ b/Engine/Common/Include/X3DAudio.h @@ -0,0 +1,277 @@ +/*-========================================================================-_ + | - X3DAUDIO - | + | Copyright (c) Microsoft Corporation. All rights reserved. | + |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| + |PROJECT: X3DAudio MODEL: Unmanaged User-mode | + |VERSION: 1.7 EXCEPT: No Exceptions | + |CLASS: N / A MINREQ: WinXP, Xbox360 | + |BASE: N / A DIALECT: MSC++ 14.00 | + |>------------------------------------------------------------------------<| + | DUTY: Cross-platform stand-alone 3D audio math library | + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ + NOTES: + 1. USE THE DEBUG DLL TO ENABLE PARAMETER VALIDATION VIA ASSERTS! + Here's how: + Copy X3DAudioDX_X.dll to where your application exists. + The debug DLL can be found under %WINDIR%\system32. + Rename X3DAudioDX_X.dll to X3DAudioX_X.dll to use the debug version. + + Only parameters required by DSP settings being calculated as + stipulated by the calculation control flags are validated. + + 2. Definition of terms: + LFE: Low Frequency Effect -- always omnidirectional. + LPF: Low Pass Filter, divided into two classifications: + Direct -- Applied to the direct signal path, + used for obstruction/occlusion effects. + Reverb -- Applied to the reverb signal path, + used for occlusion effects only. + + 3. Volume level is expressed as a linear amplitude scaler: + 1.0f represents no attenuation applied to the original signal, + 0.5f denotes an attenuation of 6dB, and 0.0f results in silence. + Amplification (volume > 1.0f) is also allowed, and is not clamped. + + LPF values range from 1.0f representing all frequencies pass through, + to 0.0f which results in silence as all frequencies are filtered out. + + 4. X3DAudio uses a left-handed Cartesian coordinate system with values + on the x-axis increasing from left to right, on the y-axis from + bottom to top, and on the z-axis from near to far. + Azimuths are measured clockwise from a given reference direction. + + Distance measurement is with respect to user-defined world units. + Applications may provide coordinates using any system of measure + as all non-normalized calculations are scale invariant, with such + operations natively occurring in user-defined world unit space. + Metric constants are supplied only as a convenience. + Distance is calculated using the Euclidean norm formula. + + 5. Only real values are permissible with functions using 32-bit + float parameters -- NAN and infinite values are not accepted. + All computation occurs in 32-bit precision mode. */ + +#pragma once +//---------------------------------------------------// +#include // general windows types +#if defined(_XBOX) + #include +#endif +#include // for D3DVECTOR + +// Xbox360 speaker geometry configuration, used with X3DAudioInitialize +#if defined(_XBOX) + #define SPEAKER_XBOX SPEAKER_5POINT1 +#endif + + +// size of instance handle in bytes +#define X3DAUDIO_HANDLE_BYTESIZE 20 + +// float math constants +#define X3DAUDIO_PI 3.141592654f +#define X3DAUDIO_2PI 6.283185307f + +// speed of sound in meters per second for dry air at approximately 20C, used with X3DAudioInitialize +#define X3DAUDIO_SPEED_OF_SOUND 343.5f + +// calculation control flags, used with X3DAudioCalculate +#define X3DAUDIO_CALCULATE_MATRIX 0x00000001 // enable matrix coefficient table calculation +#define X3DAUDIO_CALCULATE_DELAY 0x00000002 // enable delay time array calculation (stereo final mix only) +#define X3DAUDIO_CALCULATE_LPF_DIRECT 0x00000004 // enable LPF direct-path coefficient calculation +#define X3DAUDIO_CALCULATE_LPF_REVERB 0x00000008 // enable LPF reverb-path coefficient calculation +#define X3DAUDIO_CALCULATE_REVERB 0x00000010 // enable reverb send level calculation +#define X3DAUDIO_CALCULATE_DOPPLER 0x00000020 // enable doppler shift factor calculation +#define X3DAUDIO_CALCULATE_EMITTER_ANGLE 0x00000040 // enable emitter-to-listener interior angle calculation + +#define X3DAUDIO_CALCULATE_ZEROCENTER 0x00010000 // do not position to front center speaker, signal positioned to remaining speakers instead, front center destination channel will be zero in returned matrix coefficient table, valid only for matrix calculations with final mix formats that have a front center channel +#define X3DAUDIO_CALCULATE_REDIRECT_TO_LFE 0x00020000 // apply equal mix of all source channels to LFE destination channel, valid only for matrix calculations with sources that have no LFE channel and final mix formats that have an LFE channel + + +//-----------------------------------------------------// +#pragma pack(push, 1) // set packing alignment to ensure consistency across arbitrary build environments + + +// primitive types +typedef float FLOAT32; // 32-bit IEEE float +typedef D3DVECTOR X3DAUDIO_VECTOR; // float 3D vector + +// instance handle of precalculated constants +typedef BYTE X3DAUDIO_HANDLE[X3DAUDIO_HANDLE_BYTESIZE]; + + +// Distance curve point: +// Defines a DSP setting at a given normalized distance. +typedef struct X3DAUDIO_DISTANCE_CURVE_POINT +{ + FLOAT32 Distance; // normalized distance, must be within [0.0f, 1.0f] + FLOAT32 DSPSetting; // DSP setting +} X3DAUDIO_DISTANCE_CURVE_POINT, *LPX3DAUDIO_DISTANCE_CURVE_POINT; + +// Distance curve: +// A piecewise curve made up of linear segments used to +// define DSP behaviour with respect to normalized distance. +// +// Note that curve point distances are normalized within [0.0f, 1.0f]. +// X3DAUDIO_EMITTER.CurveDistanceScaler must be used to scale the +// normalized distances to user-defined world units. +// For distances beyond CurveDistanceScaler * 1.0f, +// pPoints[PointCount-1].DSPSetting is used as the DSP setting. +// +// All distance curve spans must be such that: +// pPoints[k-1].DSPSetting + ((pPoints[k].DSPSetting-pPoints[k-1].DSPSetting) / (pPoints[k].Distance-pPoints[k-1].Distance)) * (pPoints[k].Distance-pPoints[k-1].Distance) != NAN or infinite values +// For all points in the distance curve where 1 <= k < PointCount. +typedef struct X3DAUDIO_DISTANCE_CURVE +{ + X3DAUDIO_DISTANCE_CURVE_POINT* pPoints; // distance curve point array, must have at least PointCount elements with no duplicates and be sorted in ascending order with respect to Distance + UINT32 PointCount; // number of distance curve points, must be >= 2 as all distance curves must have at least two endpoints, defining DSP settings at 0.0f and 1.0f normalized distance +} X3DAUDIO_DISTANCE_CURVE, *LPX3DAUDIO_DISTANCE_CURVE; +static const X3DAUDIO_DISTANCE_CURVE_POINT X3DAudioDefault_LinearCurvePoints[2] = { 0.0f, 1.0f, 1.0f, 0.0f }; +static const X3DAUDIO_DISTANCE_CURVE X3DAudioDefault_LinearCurve = { (X3DAUDIO_DISTANCE_CURVE_POINT*)&X3DAudioDefault_LinearCurvePoints[0], 2 }; + +// Cone: +// Specifies directionality for a listener or single-channel emitter by +// modifying DSP behaviour with respect to its front orientation. +// This is modeled using two sound cones: an inner cone and an outer cone. +// On/within the inner cone, DSP settings are scaled by the inner values. +// On/beyond the outer cone, DSP settings are scaled by the outer values. +// If on both the cones, DSP settings are scaled by the inner values only. +// Between the two cones, the scaler is linearly interpolated between the +// inner and outer values. Set both cone angles to 0 or X3DAUDIO_2PI for +// omnidirectionality using only the outer or inner values respectively. +typedef struct X3DAUDIO_CONE +{ + FLOAT32 InnerAngle; // inner cone angle in radians, must be within [0.0f, X3DAUDIO_2PI] + FLOAT32 OuterAngle; // outer cone angle in radians, must be within [InnerAngle, X3DAUDIO_2PI] + + FLOAT32 InnerVolume; // volume level scaler on/within inner cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used + FLOAT32 OuterVolume; // volume level scaler on/beyond outer cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used + FLOAT32 InnerLPF; // LPF (both direct and reverb paths) coefficient subtrahend on/within inner cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used + FLOAT32 OuterLPF; // LPF (both direct and reverb paths) coefficient subtrahend on/beyond outer cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used + FLOAT32 InnerReverb; // reverb send level scaler on/within inner cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used + FLOAT32 OuterReverb; // reverb send level scaler on/beyond outer cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used +} X3DAUDIO_CONE, *LPX3DAUDIO_CONE; +static const X3DAUDIO_CONE X3DAudioDefault_DirectionalCone = { X3DAUDIO_PI/2, X3DAUDIO_PI, 1.0f, 0.708f, 0.0f, 0.25f, 0.708f, 1.0f }; + + +// Listener: +// Defines a point of 3D audio reception. +// +// The cone is directed by the listener's front orientation. +typedef struct X3DAUDIO_LISTENER +{ + X3DAUDIO_VECTOR OrientFront; // orientation of front direction, used only for matrix and delay calculations or listeners with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used + X3DAUDIO_VECTOR OrientTop; // orientation of top direction, used only for matrix and delay calculations, must be orthonormal with OrientFront when used + + X3DAUDIO_VECTOR Position; // position in user-defined world units, does not affect Velocity + X3DAUDIO_VECTOR Velocity; // velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position + + X3DAUDIO_CONE* pCone; // sound cone, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality +} X3DAUDIO_LISTENER, *LPX3DAUDIO_LISTENER; + +// Emitter: +// Defines a 3D audio source, divided into two classifications: +// +// Single-point -- For use with single-channel sounds. +// Positioned at the emitter base, i.e. the channel radius +// and azimuth are ignored if the number of channels == 1. +// +// May be omnidirectional or directional using a cone. +// The cone originates from the emitter base position, +// and is directed by the emitter's front orientation. +// +// Multi-point -- For use with multi-channel sounds. +// Each non-LFE channel is positioned using an +// azimuth along the channel radius with respect to the +// front orientation vector in the plane orthogonal to the +// top orientation vector. An azimuth of X3DAUDIO_2PI +// specifies a channel is an LFE. Such channels are +// positioned at the emitter base and are calculated +// with respect to pLFECurve only, never pVolumeCurve. +// +// Multi-point emitters are always omnidirectional, +// i.e. the cone is ignored if the number of channels > 1. +// +// Note that many properties are shared among all channel points, +// locking certain behaviour with respect to the emitter base position. +// For example, doppler shift is always calculated with respect to the +// emitter base position and so is constant for all its channel points. +// Distance curve calculations are also with respect to the emitter base +// position, with the curves being calculated independently of each other. +// For instance, volume and LFE calculations do not affect one another. +typedef struct X3DAUDIO_EMITTER +{ + X3DAUDIO_CONE* pCone; // sound cone, used only with single-channel emitters for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality + X3DAUDIO_VECTOR OrientFront; // orientation of front direction, used only for emitter angle calculations or with multi-channel emitters for matrix calculations or single-channel emitters with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used + X3DAUDIO_VECTOR OrientTop; // orientation of top direction, used only with multi-channel emitters for matrix calculations, must be orthonormal with OrientFront when used + + X3DAUDIO_VECTOR Position; // position in user-defined world units, does not affect Velocity + X3DAUDIO_VECTOR Velocity; // velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position + + FLOAT32 InnerRadius; // inner radius, must be within [0.0f, FLT_MAX] + FLOAT32 InnerRadiusAngle; // inner radius angle, must be within [0.0f, X3DAUDIO_PI/4.0) + + UINT32 ChannelCount; // number of sound channels, must be > 0 + FLOAT32 ChannelRadius; // channel radius, used only with multi-channel emitters for matrix calculations, must be >= 0.0f when used + FLOAT32* pChannelAzimuths; // channel azimuth array, used only with multi-channel emitters for matrix calculations, contains positions of each channel expressed in radians along the channel radius with respect to the front orientation vector in the plane orthogonal to the top orientation vector, or X3DAUDIO_2PI to specify an LFE channel, must have at least ChannelCount elements, all within [0.0f, X3DAUDIO_2PI] when used + + X3DAUDIO_DISTANCE_CURVE* pVolumeCurve; // volume level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation + X3DAUDIO_DISTANCE_CURVE* pLFECurve; // LFE level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation + X3DAUDIO_DISTANCE_CURVE* pLPFDirectCurve; // LPF direct-path coefficient distance curve, used only for LPF direct-path calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.75f] + X3DAUDIO_DISTANCE_CURVE* pLPFReverbCurve; // LPF reverb-path coefficient distance curve, used only for LPF reverb-path calculations, NULL specifies the default curve: [0.0f,0.75f], [1.0f,0.75f] + X3DAUDIO_DISTANCE_CURVE* pReverbCurve; // reverb send level distance curve, used only for reverb calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.0f] + + FLOAT32 CurveDistanceScaler; // curve distance scaler, used to scale normalized distance curves to user-defined world units and/or exaggerate their effect, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, must be within [FLT_MIN, FLT_MAX] when used + FLOAT32 DopplerScaler; // doppler shift scaler, used to exaggerate doppler shift effect, used only for doppler calculations, must be within [0.0f, FLT_MAX] when used +} X3DAUDIO_EMITTER, *LPX3DAUDIO_EMITTER; + + +// DSP settings: +// Receives results from a call to X3DAudioCalculate to be sent +// to the low-level audio rendering API for 3D signal processing. +// +// The user is responsible for allocating the matrix coefficient table, +// delay time array, and initializing the channel counts when used. +typedef struct X3DAUDIO_DSP_SETTINGS +{ + FLOAT32* pMatrixCoefficients; // [inout] matrix coefficient table, receives an array representing the volume level used to send from source channel S to destination channel D, stored as pMatrixCoefficients[SrcChannelCount * D + S], must have at least SrcChannelCount*DstChannelCount elements + FLOAT32* pDelayTimes; // [inout] delay time array, receives delays for each destination channel in milliseconds, must have at least DstChannelCount elements (stereo final mix only) + UINT32 SrcChannelCount; // [in] number of source channels, must equal number of channels in respective emitter + UINT32 DstChannelCount; // [in] number of destination channels, must equal number of channels of the final mix + + FLOAT32 LPFDirectCoefficient; // [out] LPF direct-path coefficient + FLOAT32 LPFReverbCoefficient; // [out] LPF reverb-path coefficient + FLOAT32 ReverbLevel; // [out] reverb send level + FLOAT32 DopplerFactor; // [out] doppler shift factor, scales resampler ratio for doppler shift effect, where the effective frequency = DopplerFactor * original frequency + FLOAT32 EmitterToListenerAngle; // [out] emitter-to-listener interior angle, expressed in radians with respect to the emitter's front orientation + + FLOAT32 EmitterToListenerDistance; // [out] distance in user-defined world units from the emitter base to listener position, always calculated + FLOAT32 EmitterVelocityComponent; // [out] component of emitter velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler + FLOAT32 ListenerVelocityComponent; // [out] component of listener velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler +} X3DAUDIO_DSP_SETTINGS, *LPX3DAUDIO_DSP_SETTINGS; + + +//-------------------------------------------------------------// +// function storage-class attribute and calltype +#if defined(_XBOX) || defined(X3DAUDIOSTATIC) + #define X3DAUDIO_API_(type) EXTERN_C type STDAPIVCALLTYPE +#else + #if defined(X3DEXPORT) + #define X3DAUDIO_API_(type) EXTERN_C __declspec(dllexport) type STDAPIVCALLTYPE + #else + #define X3DAUDIO_API_(type) EXTERN_C __declspec(dllimport) type STDAPIVCALLTYPE + #endif +#endif +#define X3DAUDIO_IMP_(type) type STDMETHODVCALLTYPE + + +//-------------------------------------------------------// +// initializes instance handle +X3DAUDIO_API_(void) X3DAudioInitialize (UINT32 SpeakerChannelMask, FLOAT32 SpeedOfSound, __out X3DAUDIO_HANDLE Instance); + +// calculates DSP settings with respect to 3D parameters +X3DAUDIO_API_(void) X3DAudioCalculate (__in const X3DAUDIO_HANDLE Instance, __in const X3DAUDIO_LISTENER* pListener, __in const X3DAUDIO_EMITTER* pEmitter, UINT32 Flags, __inout X3DAUDIO_DSP_SETTINGS* pDSPSettings); + + +#pragma pack(pop) // revert packing alignment +//---------------------------------<-EOF->----------------------------------// diff --git a/Engine/Common/Include/audiodefs.h b/Engine/Common/Include/audiodefs.h new file mode 100644 index 00000000..99b96958 --- /dev/null +++ b/Engine/Common/Include/audiodefs.h @@ -0,0 +1,172 @@ +/*************************************************************************** + * + * Copyright (c) Microsoft Corporation. All rights reserved. + * + * File: audiodefs.h + * Content: Basic constants and data types for audio work. + * + * Remarks: This header file defines all of the audio format constants and + * structures required for XAudio2 and XACT work. Providing these + * in a single location avoids certain dependency problems in the + * legacy audio headers (mmreg.h, mmsystem.h, ksmedia.h). + * + * NOTE: Including the legacy headers after this one may cause a + * compilation error, because they define some of the same types + * defined here without preprocessor guards to avoid multiple + * definitions. If a source file needs one of the old headers, + * it must include it before including audiodefs.h. + * + ***************************************************************************/ + +#ifndef __AUDIODEFS_INCLUDED__ +#define __AUDIODEFS_INCLUDED__ + +#include // For WORD, DWORD, etc. + +#pragma pack(push, 1) // Pack structures to 1-byte boundaries + + +/************************************************************************** + * + * WAVEFORMATEX: Base structure for many audio formats. Format-specific + * extensions can be defined for particular formats by using a non-zero + * cbSize value and adding extra fields to the end of this structure. + * + ***************************************************************************/ + +#ifndef _WAVEFORMATEX_ + + #define _WAVEFORMATEX_ + typedef struct tWAVEFORMATEX + { + WORD wFormatTag; // Integer identifier of the format + WORD nChannels; // Number of audio channels + DWORD nSamplesPerSec; // Audio sample rate + DWORD nAvgBytesPerSec; // Bytes per second (possibly approximate) + WORD nBlockAlign; // Size in bytes of a sample block (all channels) + WORD wBitsPerSample; // Size in bits of a single per-channel sample + WORD cbSize; // Bytes of extra data appended to this struct + } WAVEFORMATEX; + +#endif + +// Defining pointer types outside of the #if block to make sure they are +// defined even if mmreg.h or mmsystem.h is #included before this file + +typedef WAVEFORMATEX *PWAVEFORMATEX, *NPWAVEFORMATEX, *LPWAVEFORMATEX; +typedef const WAVEFORMATEX *PCWAVEFORMATEX, *LPCWAVEFORMATEX; + + +/************************************************************************** + * + * WAVEFORMATEXTENSIBLE: Extended version of WAVEFORMATEX that should be + * used as a basis for all new audio formats. The format tag is replaced + * with a GUID, allowing new formats to be defined without registering a + * format tag with Microsoft. There are also new fields that can be used + * to specify the spatial positions for each channel and the bit packing + * used for wide samples (e.g. 24-bit PCM samples in 32-bit containers). + * + ***************************************************************************/ + +#ifndef _WAVEFORMATEXTENSIBLE_ + + #define _WAVEFORMATEXTENSIBLE_ + typedef struct + { + WAVEFORMATEX Format; // Base WAVEFORMATEX data + union + { + WORD wValidBitsPerSample; // Valid bits in each sample container + WORD wSamplesPerBlock; // Samples per block of audio data; valid + // if wBitsPerSample=0 (but rarely used). + WORD wReserved; // Zero if neither case above applies. + } Samples; + DWORD dwChannelMask; // Positions of the audio channels + GUID SubFormat; // Format identifier GUID + } WAVEFORMATEXTENSIBLE; + +#endif + +typedef WAVEFORMATEXTENSIBLE *PWAVEFORMATEXTENSIBLE, *LPWAVEFORMATEXTENSIBLE; +typedef const WAVEFORMATEXTENSIBLE *PCWAVEFORMATEXTENSIBLE, *LPCWAVEFORMATEXTENSIBLE; + + + +/************************************************************************** + * + * Define the most common wave format tags used in WAVEFORMATEX formats. + * + ***************************************************************************/ + +#ifndef WAVE_FORMAT_PCM // Pulse Code Modulation + + // If WAVE_FORMAT_PCM is not defined, we need to define some legacy types + // for compatibility with the Windows mmreg.h / mmsystem.h header files. + + // Old general format structure (information common to all formats) + typedef struct waveformat_tag + { + WORD wFormatTag; + WORD nChannels; + DWORD nSamplesPerSec; + DWORD nAvgBytesPerSec; + WORD nBlockAlign; + } WAVEFORMAT, *PWAVEFORMAT, NEAR *NPWAVEFORMAT, FAR *LPWAVEFORMAT; + + // Specific format structure for PCM data + typedef struct pcmwaveformat_tag + { + WAVEFORMAT wf; + WORD wBitsPerSample; + } PCMWAVEFORMAT, *PPCMWAVEFORMAT, NEAR *NPPCMWAVEFORMAT, FAR *LPPCMWAVEFORMAT; + + #define WAVE_FORMAT_PCM 0x0001 + +#endif + +// Other frequently used format tags + +#ifndef WAVE_FORMAT_UNKNOWN + #define WAVE_FORMAT_UNKNOWN 0x0000 // Unknown or invalid format tag +#endif + +#ifndef WAVE_FORMAT_IEEE_FLOAT + #define WAVE_FORMAT_IEEE_FLOAT 0x0003 // 32-bit floating-point +#endif + +#ifndef WAVE_FORMAT_MPEGLAYER3 + #define WAVE_FORMAT_MPEGLAYER3 0x0055 // ISO/MPEG Layer3 +#endif + +#ifndef WAVE_FORMAT_DOLBY_AC3_SPDIF + #define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092 // Dolby Audio Codec 3 over S/PDIF +#endif + +#ifndef WAVE_FORMAT_WMAUDIO2 + #define WAVE_FORMAT_WMAUDIO2 0x0161 // Windows Media Audio +#endif + +#ifndef WAVE_FORMAT_WMAUDIO3 + #define WAVE_FORMAT_WMAUDIO3 0x0162 // Windows Media Audio Pro +#endif + +#ifndef WAVE_FORMAT_WMASPDIF + #define WAVE_FORMAT_WMASPDIF 0x0164 // Windows Media Audio over S/PDIF +#endif + +#ifndef WAVE_FORMAT_EXTENSIBLE + #define WAVE_FORMAT_EXTENSIBLE 0xFFFE // All WAVEFORMATEXTENSIBLE formats +#endif + + +/************************************************************************** + * + * Define the most common wave format GUIDs used in WAVEFORMATEXTENSIBLE + * formats. Note that including the Windows ksmedia.h header after this + * one will cause build problems; this cannot be avoided, since ksmedia.h + * defines these macros without preprocessor guards. + * + ***************************************************************************/ +#pragma pack(pop) + +#endif // #ifndef __AUDIODEFS_INCLUDED__ diff --git a/Engine/Common/Include/comdecl.h b/Engine/Common/Include/comdecl.h new file mode 100644 index 00000000..2ae9a961 --- /dev/null +++ b/Engine/Common/Include/comdecl.h @@ -0,0 +1,59 @@ +// comdecl.h: Macros to facilitate COM interface and GUID declarations. +// Copyright (c) Microsoft Corporation. All rights reserved. + +#ifndef _COMDECL_H_ +#define _COMDECL_H_ + +#ifndef _XBOX + #include // For standard COM interface macros +#else + #pragma warning(push) + #pragma warning(disable:4061) + #include // Required by xobjbase.h + #include // Special definitions for Xbox build + #pragma warning(pop) +#endif + +// The DEFINE_CLSID() and DEFINE_IID() macros defined below allow COM GUIDs to +// be declared and defined in such a way that clients can obtain the GUIDs using +// either the __uuidof() extension or the old-style CLSID_Foo / IID_IFoo names. +// If using the latter approach, the client can also choose whether to get the +// GUID definitions by defining the INITGUID preprocessor constant or by linking +// to a GUID library. This works in either C or C++. + +#ifdef __cplusplus + + #define DECLSPEC_UUID_WRAPPER(x) __declspec(uuid(#x)) + #ifdef INITGUID + + #define DEFINE_CLSID(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + class DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) className; \ + EXTERN_C const GUID DECLSPEC_SELECTANY CLSID_##className = __uuidof(className) + + #define DEFINE_IID(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + interface DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) interfaceName; \ + EXTERN_C const GUID DECLSPEC_SELECTANY IID_##interfaceName = __uuidof(interfaceName) + + #else // INITGUID + + #define DEFINE_CLSID(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + class DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) className; \ + EXTERN_C const GUID CLSID_##className + + #define DEFINE_IID(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + interface DECLSPEC_UUID_WRAPPER(l##-##w1##-##w2##-##b1##b2##-##b3##b4##b5##b6##b7##b8) interfaceName; \ + EXTERN_C const GUID IID_##interfaceName + + #endif // INITGUID + +#else // __cplusplus + + #define DEFINE_CLSID(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + DEFINE_GUID(CLSID_##className, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8) + + #define DEFINE_IID(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + DEFINE_GUID(IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8) + +#endif // __cplusplus + +#endif // #ifndef _COMDECL_H_ diff --git a/Engine/Common/MultiplayerSystem/Multiplayer.cpp b/Engine/Common/MultiplayerSystem/Multiplayer.cpp new file mode 100644 index 00000000..c3386865 --- /dev/null +++ b/Engine/Common/MultiplayerSystem/Multiplayer.cpp @@ -0,0 +1,681 @@ +#include "Multiplayer.h" + +class Engine; +extern shared_ptr Application; +#include "Engine.h" +#include "UISystem/Console/Console.h" +#include "UISystem/Console/CCommands.h" + +#include "UISystem/UI.h" +#include "Audio System/Audio.h" +#include "ProjectManager/FileSystem/File_system.h" + +extern shared_ptr ui; +extern shared_ptr