From 04e335e76f081e52e4640c825fa0654dbf5400d1 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 11 Jan 2022 13:00:42 +0300 Subject: [PATCH 01/59] [linux] add CI for Linux, dxvk_native, safeclib and 1st version for storm_platform.h --- .github/workflows/ci_linux.yml | 43 ++++++++++++++++++++ CMakeLists.txt | 50 ++++++++++++++++++++++++ cmake/StormSetup.cmake | 12 +++++- conanfile.py | 13 +++++- src/CMakeLists.txt | 1 + src/apps/engine/CMakeLists.txt | 12 ++++-- src/libs/common/CMakeLists.txt | 6 ++- src/libs/common/include/attributes.h | 1 + src/libs/common/include/storm_platform.h | 27 +++++++++++++ src/libs/renderer/CMakeLists.txt | 6 ++- src/libs/util/CMakeLists.txt | 1 + src/libs/xinterface/CMakeLists.txt | 9 ++++- 12 files changed, 172 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci_linux.yml create mode 100644 src/libs/common/include/storm_platform.h diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml new file mode 100644 index 000000000..d80cd146d --- /dev/null +++ b/.github/workflows/ci_linux.yml @@ -0,0 +1,43 @@ +name: CI Linux + +on: + push: + paths-ignore: + - 'docs/**' + - 'tools/**' + - '*.md' + pull_request: + paths-ignore: + - 'docs/**' + - 'tools/**' + - '*.md' + +jobs: + build-linux: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + configuration: [Debug] + name: 'build-linux [${{ matrix.configuration}}]' + steps: + - uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: Install libs + run: sudo apt update && sudo apt install meson libvulkan-dev glslang-tools libsdl2-dev libgl-dev libegl-dev + - name: Install Conan + run: pip install conan + - name: Configure with cmake + run: | + export CC=clang-11 + export CXX=clang++-11 + ${CXX} --version + mkdir build && cd build + cmake .. -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.configuration}} + - name: Build dependencies + run: ninja dependencies + working-directory: build + - name: Build project + run: ninja + working-directory: build diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a32fa666..56b4add2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,56 @@ conan_cmake_run(CONANFILE conanfile.py steam=${STORM_ENABLE_STEAM} ) +if (NOT WIN32) + message("Using DXVK-native for D3D9 API") + + include(ExternalProject) + ExternalProject_Add(dxvk-native + GIT_REPOSITORY https://github.com/Joshua-Ashton/dxvk-native + GIT_TAG origin/master + GIT_SHALLOW ON + BUILD_ALWAYS OFF + CONFIGURE_HANDLED_BY_BUILD ON + CONFIGURE_COMMAND CC=gcc-10 && CXX=g++-10 && meson ../dxvk-native + BUILD_COMMAND ninja + INSTALL_COMMAND "" + ) + ExternalProject_Get_property(dxvk-native SOURCE_DIR BINARY_DIR) + set(DXVK_NATIVE_INCLUDE_DIRS + "${SOURCE_DIR}/include/native/directx" + "${SOURCE_DIR}/include/native/windows" + ) + set(DXVK_NATIVE_D3D9_LIB ${BINARY_DIR}/src/d3d9/libdxvk_d3d9.so) + include_directories("${DXVK_NATIVE_INCLUDE_DIRS}") + ADD_CUSTOM_TARGET(dependencies ALL DEPENDS dxvk-native) + +# message("Using safeclib for str*_s functions") + +# include(ProcessorCount) +# ProcessorCount(N) +# if (N EQUAL 0) +# set(N 1) +# endif() + +# ExternalProject_Add(safeclib +# GIT_REPOSITORY https://github.com/rurban/safeclib +# GIT_TAG v02092020 +# GIT_SHALLOW ON +# BUILD_ALWAYS OFF +# CONFIGURE_HANDLED_BY_BUILD ON +# CONFIGURE_COMMAND ./build-aux/autogen.sh && ./configure --enable-strmax=0x8000 --enable-shared=no --disable-doc +# BUILD_COMMAND make -j${N} +# BUILD_IN_SOURCE ON +# INSTALL_COMMAND "" +# ) +# ExternalProject_Get_property(safeclib SOURCE_DIR BINARY_DIR) +# set(SAFECLIB_INCLUDE_DIR "${SOURCE_DIR}/include") +# set(SAFECLIB_LIB ${SOURCE_DIR}/src/.libs/libsafec-3.6.0.a) +# include_directories("${SAFECLIB_INCLUDE_DIR}") + +# ADD_CUSTOM_TARGET(dependencies ALL DEPENDS dxvk-native safeclib) +endif() + ### Define library ALIASes for use without CONAN_PKG:: prefix foreach (conan_target ${CONAN_TARGETS}) string(REPLACE "CONAN_PKG::" "" unprefixed_target ${conan_target}) diff --git a/cmake/StormSetup.cmake b/cmake/StormSetup.cmake index 9b5fabe98..f214ccbad 100644 --- a/cmake/StormSetup.cmake +++ b/cmake/StormSetup.cmake @@ -222,6 +222,9 @@ macro(STORM_SETUP) ${_SETUP_DEPENDENCIES}) if(${_SETUP_TYPE} STREQUAL "executable") + if(NOT WIN32) + list(APPEND target_link_flags "-Wl,--whole-archive") + endif() foreach(dep ${_SETUP_DEPENDENCIES}) if(TARGET ${dep}) get_property( @@ -231,10 +234,17 @@ macro(STORM_SETUP) SET) if(is_storm_module) # TODO: make it portable? (at least for gcc it is --whole-archive) - list(APPEND target_link_flags "/WHOLEARCHIVE:${dep}") + if (WIN32) + list(APPEND target_link_flags "/WHOLEARCHIVE:${dep}") + else() + list(APPEND target_link_flags "${CMAKE_BINARY_DIR}/lib/lib${dep}.a") + endif() endif() endif() endforeach() + if(NOT WIN32) + list(APPEND target_link_flags "-Wl,--no-whole-archive") + endif() endif() endif() diff --git a/conanfile.py b/conanfile.py index 1b92b6105..419920af2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -16,7 +16,7 @@ class StormEngine(ConanFile): # dependencies used in deploy binaries # conan-center - requires = ["zlib/1.2.11", "spdlog/1.9.2", "7zip/19.00", "fast_float/3.4.0", "sdl/2.0.18", "mimalloc/2.0.3", + requires = ["zlib/1.2.11", "spdlog/1.9.2", "fast_float/3.4.0", "sdl/2.0.18", "mimalloc/2.0.3", # storm.jfrog.io "sentry-native/0.4.13@storm/patched", "directx/9.0@storm/prebuilt", "fmod/2.02.05@storm/prebuilt"] # aux dependencies (e.g. for tests) @@ -24,6 +24,12 @@ class StormEngine(ConanFile): # optional dependencies def requirements(self): + if self.settings.os == "Windows": + # conan-center + self.requires("7zip/19.00") + else: + # conan-center + self.requires("libsafec/3.6.0") if self.options.steam: self.requires("steamworks/1.5.1@storm/prebuilt") @@ -32,11 +38,14 @@ def requirements(self): default_options = { "sdl2:sdl2main": False, "sentry-native:backend": "crashpad", - "sentry-native:transport": "winhttp", "mimalloc:shared": True, "mimalloc:override": True } + def configure(self): + if self.settings.os == "Windows": + self.default_options["sentry-native:transport"] = "winhttp" + def imports(self): self.__dest = str(self.options.output_directory) + "/" + getenv("CONAN_IMPORT_PATH", "bin") self.__install_folder("/src/techniques", "/resource/techniques") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0031d4e7..e7c3f27be 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ if (MSVC) add_link_options("$<$:/OPT:ICF>") # Perform identical COMDAT folding, needs to be explicitly specified with /DEBUG add_link_options("$<$:/LTCG>") # Enable link-time code generation else() + add_definitions(-D_GLIBCXX_USE_TBB_PAR_BACKEND=0) # Don't use tbb add_compile_options(-std=c++20) # Verbose output diff --git a/src/apps/engine/CMakeLists.txt b/src/apps/engine/CMakeLists.txt index 950ec7d5c..96fe87823 100644 --- a/src/apps/engine/CMakeLists.txt +++ b/src/apps/engine/CMakeLists.txt @@ -6,6 +6,14 @@ else() set(MIMALLOC_DEP "$,${CONAN_LIB_DIRS_MIMALLOC_RELEASE}/libmimalloc.so,${CONAN_LIB_DIRS_MIMALLOC_DEBUG}/libmimalloc-debug.so>") endif() +if (WIN32) +set(SYSTEM_DEPS + "comctl32" + "dbghelp" + "winhttp" +) +endif() + STORM_SETUP( TARGET_NAME engine TYPE executable @@ -69,7 +77,5 @@ STORM_SETUP( zlib # system - comctl32 - dbghelp - winhttp + ${SYSTEM_DEPS} ) \ No newline at end of file diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt index 12c51bffb..f7326056b 100644 --- a/src/libs/common/CMakeLists.txt +++ b/src/libs/common/CMakeLists.txt @@ -1,5 +1,9 @@ +if (NOT WIN32) +set(SYSTEM_DEPS "libsafec") +endif() + STORM_SETUP( TARGET_NAME common TYPE library - DEPENDENCIES shared_headers util spdlog directx + DEPENDENCIES shared_headers util spdlog directx ${SYSTEM_DEPS} ) \ No newline at end of file diff --git a/src/libs/common/include/attributes.h b/src/libs/common/include/attributes.h index 53dab9a0b..093a743d6 100644 --- a/src/libs/common/include/attributes.h +++ b/src/libs/common/include/attributes.h @@ -6,6 +6,7 @@ #include "storm_assert.h" #include "storm/string_compare.hpp" +#include "storm_platform.h" class VSTRING_CODEC { diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h new file mode 100644 index 000000000..86c3294f5 --- /dev/null +++ b/src/libs/common/include/storm_platform.h @@ -0,0 +1,27 @@ +#ifndef _WIN32 + +#include "safe_str_lib.h" + +// workaround for safeclib +//#undef sprintf_s(dest, dmax, ...) +//#define sprintf_s(dest, dmax, fmt, ...) _sprintf_s_chk(dest, dmax, BOS(dest), fmt, __VA_ARGS__) + +template inline int sprintf_s(char (&buffer)[size], const char *format, ...) +{ + va_list args; + va_start(args, format); + int result = vsnprintf(buffer, size, format, args); + va_end(args); + return result; +} + +/* +template +int sprintf_s( + char (&buffer)[size], + const char *format [, + argument] ... +); +*/ + +#endif diff --git a/src/libs/renderer/CMakeLists.txt b/src/libs/renderer/CMakeLists.txt index 4e78c3138..1bb425f8d 100644 --- a/src/libs/renderer/CMakeLists.txt +++ b/src/libs/renderer/CMakeLists.txt @@ -1,5 +1,9 @@ +if (WIN32) +set(SYSTEM_DEPS "legacy_stdio_definitions") +endif() + STORM_SETUP( TARGET_NAME renderer TYPE storm_module - DEPENDENCIES common util legacy_stdio_definitions + DEPENDENCIES common util ${SYSTEM_DEPS} ) \ No newline at end of file diff --git a/src/libs/util/CMakeLists.txt b/src/libs/util/CMakeLists.txt index 942c304db..7eee0353f 100644 --- a/src/libs/util/CMakeLists.txt +++ b/src/libs/util/CMakeLists.txt @@ -1,5 +1,6 @@ STORM_SETUP( TARGET_NAME util TYPE library + DEPENDENCIES sdl TEST_DEPENDENCIES catch2 ) \ No newline at end of file diff --git a/src/libs/xinterface/CMakeLists.txt b/src/libs/xinterface/CMakeLists.txt index e7519b958..0b3e6a26c 100644 --- a/src/libs/xinterface/CMakeLists.txt +++ b/src/libs/xinterface/CMakeLists.txt @@ -1,6 +1,13 @@ +if (WIN32) +set(SYSTEM_DEPS + "ddraw" + "amstrmid" +) +endif() + STORM_SETUP( TARGET_NAME xinterface TYPE storm_module - DEPENDENCIES common ddraw amstrmid util + DEPENDENCIES common util ${SYSTEM_DEPS} TEST_DEPENDENCIES catch2 ) \ No newline at end of file From 8630e43d6fe7e9e8dc1f9cf0239bb84fdcb013c6 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 11 Jan 2022 14:40:15 +0300 Subject: [PATCH 02/59] [linux] fix build for matrix.h and rands.h --- src/libs/common/include/matrix.h | 6 ++++++ src/libs/common/include/rands.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/libs/common/include/matrix.h b/src/libs/common/include/matrix.h index b60ccdc58..09d0585d1 100644 --- a/src/libs/common/include/matrix.h +++ b/src/libs/common/include/matrix.h @@ -4,7 +4,9 @@ #include "c_vector.h" #include +#ifdef _WIN32 #include +#endif //============================================================================================ @@ -159,7 +161,9 @@ class CMatrix void BuildMirrorMatrix(float Nx, float Ny, float Nz, float D); // D3D extends (return (D3DXMATRIX *)pointer) +#ifdef _WIN32 operator D3DXMATRIX *() const; +#endif operator D3DMATRIX *() const; operator const float *() const; }; @@ -870,11 +874,13 @@ inline void CMatrix::BuildMirrorMatrix(float Nx, float Ny, float Nz, float D) m[3][3] = 1.0f; } +#ifdef _WIN32 // D3D extends (return (D3DXMATRIX *)pointer) inline CMatrix::operator D3DXMATRIX *() const { return ((D3DXMATRIX *)matrix); }; +#endif // D3D extends (return (D3DMATRIX *)pointer) inline CMatrix::operator D3DMATRIX *() const diff --git a/src/libs/common/include/rands.h b/src/libs/common/include/rands.h index efc07ac81..db224816e 100644 --- a/src/libs/common/include/rands.h +++ b/src/libs/common/include/rands.h @@ -1,6 +1,7 @@ #pragma once #include +#include // returns random float inline float rand(float r) From 4da3569756d7dac6bc66f34072ab2ef7ae880a08 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 11 Jan 2022 18:28:35 +0300 Subject: [PATCH 03/59] [linux] replace D3DXQUATERNION and D3DXMATRIX --- src/libs/animation/src/animation_imp.cpp | 20 +++++--- .../animation/src/animation_service_imp.cpp | 2 +- src/libs/animation/src/bone.cpp | 28 ++++++----- src/libs/animation/src/bone.h | 17 +++---- .../battle_interface/src/log_and_action.cpp | 2 +- .../src/sea/ship_info_images.cpp | 2 +- .../battle_interface/src/sea/ship_pointer.cpp | 2 +- src/libs/common/include/dx9render.h | 3 +- src/libs/common/include/math3d/matrix.h | 9 ++-- src/libs/common/include/math3d/quaternion.h | 1 - src/libs/common/include/matrix.h | 22 ++++++++ src/libs/mast/src/mast.cpp | 2 +- src/libs/renderer/src/s_device.cpp | 2 +- src/libs/rigging/src/flag.cpp | 5 +- src/libs/rigging/src/flag.h | 2 +- src/libs/rigging/src/rope.cpp | 2 +- src/libs/rigging/src/sail.cpp | 8 +-- src/libs/rigging/src/vant.cpp | 2 +- src/libs/sea/src/env_map.cpp | 50 ++++--------------- src/libs/weather/src/rain.cpp | 2 +- src/libs/weather/src/sky.cpp | 24 ++++----- .../xinterface/src/back_scene/back_scene.cpp | 4 +- 22 files changed, 103 insertions(+), 108 deletions(-) diff --git a/src/libs/animation/src/animation_imp.cpp b/src/libs/animation/src/animation_imp.cpp index 01e1160bf..d230f6869 100644 --- a/src/libs/animation/src/animation_imp.cpp +++ b/src/libs/animation/src/animation_imp.cpp @@ -266,12 +266,14 @@ void AnimationImp::BuildAnimationMatrices() for (int32_t j = 0; j < nbones; j++) { auto &bn = aniInfo->GetBone(j); + Matrix tmpMtx; CMatrix inmtx; - D3DXQUATERNION qt0, qt1, qt; + Quaternion qt0, qt1, qt; bn.BlendFrame(f0, ki0, qt0); bn.BlendFrame(f1, ki1, qt1); - D3DXQuaternionSlerp(&qt, &qt0, &qt1, kBlend); - D3DXMatrixRotationQuaternion(inmtx, &qt); + qt.SLerp(qt0, qt1, kBlend); + qt.GetMatrix(tmpMtx); + inmtx = tmpMtx; inmtx.Pos() = bn.pos0; if (j == 0) { @@ -308,10 +310,12 @@ void AnimationImp::BuildAnimationMatrices() for (int32_t j = 0; j < nbones; j++) { auto &bn = aniInfo->GetBone(j); + Matrix tmpMtx; CMatrix inmtx; - D3DXQUATERNION qt; + Quaternion qt; bn.BlendFrame(f, ki, qt); - D3DXMatrixRotationQuaternion(inmtx, &qt); + qt.GetMatrix(tmpMtx); + inmtx = tmpMtx; inmtx.Pos() = bn.pos0; if (j == 0) inmtx.Pos() = bn.pos[f] + ki * (bn.pos[f + 1] - bn.pos[f]); @@ -344,10 +348,12 @@ void AnimationImp::BuildAnimationMatrices() for (int32_t j = 0; j < nbones; j++) { auto &bn = aniInfo->GetBone(j); + Matrix tmpMtx; CMatrix inmtx; - D3DXQUATERNION qt; + Quaternion qt; bn.BlendFrame(f, ki, qt); - D3DXMatrixRotationQuaternion(inmtx, &qt); + qt.GetMatrix(tmpMtx); + inmtx = tmpMtx; inmtx.Pos() = bn.pos0; if (j == 0) inmtx.Pos() = bn.pos[f] + ki * (bn.pos[f + 1] - bn.pos[f]); diff --git a/src/libs/animation/src/animation_service_imp.cpp b/src/libs/animation/src/animation_service_imp.cpp index 1d1ea9e40..be173719b 100644 --- a/src/libs/animation/src/animation_service_imp.cpp +++ b/src/libs/animation/src/animation_service_imp.cpp @@ -571,7 +571,7 @@ bool AnimationServiceImp::LoadAN(const char *fname, AnimationInfo *info) delete[] vrt; // Angles - auto *ang = new D3DXQUATERNION[header.nFrames]; + auto *ang = new Quaternion[header.nFrames]; for (int32_t i = 0; i < header.nJoints; i++) { if (!fio->_ReadFile(fileS, ang, header.nFrames * sizeof(*ang))) diff --git a/src/libs/animation/src/bone.cpp b/src/libs/animation/src/bone.cpp index 1bfc67f3b..af77c6e5c 100644 --- a/src/libs/animation/src/bone.cpp +++ b/src/libs/animation/src/bone.cpp @@ -49,7 +49,7 @@ void Bone::SetNumFrames(int32_t num, CVECTOR &sPos, bool isRoot) ang = new COMP_QUATERNION[num]; memset(ang, 0, numFrames * sizeof(ang[0])); #else - ang = new D3DXQUATERNION[num]; + ang = new Quaternion[num]; memset(ang, 0, numFrames * sizeof(ang[0])); #endif @@ -79,7 +79,7 @@ void Bone::SetPositions(const CVECTOR *pArray, int32_t numPos) //------------------------------------- // Set animation angles -void Bone::SetAngles(const D3DXQUATERNION *aArray, int32_t numAng) +void Bone::SetAngles(const Quaternion *aArray, int32_t numAng) { Assert(numAng == numFrames); Assert(aArray); @@ -101,7 +101,7 @@ void Bone::SetAngles(const D3DXQUATERNION *aArray, int32_t numAng) } } -inline void Bone::GetFrame(int32_t f, D3DXQUATERNION &qt) +inline void Bone::GetFrame(int32_t f, Quaternion &qt) { qt.x = sinf((ang[f].x * (1.0f / 32767.0f)) * PI * 0.5f); qt.y = sinf((ang[f].y * (1.0f / 32767.0f)) * PI * 0.5f); @@ -116,7 +116,7 @@ inline void Bone::GetFrame(int32_t f, D3DXQUATERNION &qt) //------------------------------------- // Set animation angles -void Bone::SetAngles(const D3DXQUATERNION *aArray, int32_t numAng) +void Bone::SetAngles(const Quaternion *aArray, int32_t numAng) { Assert(numAng == numFrames); Assert(aArray); @@ -124,7 +124,7 @@ void Bone::SetAngles(const D3DXQUATERNION *aArray, int32_t numAng) memcpy(ang, aArray, numFrames * sizeof(*ang)); } -inline void Bone::GetFrame(int32_t f, D3DXQUATERNION &qt) +inline void Bone::GetFrame(int32_t f, Quaternion &qt) { qt = ang[f]; } @@ -156,10 +156,12 @@ void Bone::BuildStartMatrix() { if (numFrames == 0 || !ang) return; - const CMatrix inmtx; - D3DXQUATERNION a; + Matrix tmpInmtx; + CMatrix inmtx; + Quaternion a; GetFrame(0, a); - D3DXMatrixRotationQuaternion(inmtx, &a); + a.GetMatrix(tmpInmtx); + inmtx = tmpInmtx; inmtx.Pos() = pos0; if (parent) start.EqMultiply(inmtx, parent->start); @@ -172,7 +174,7 @@ void Bone::BuildStartMatrix() // -------------------------------------------------------------------------------------------- // Add animation frames -void Bone::BlendFrame(int32_t frame, float kBlend, D3DXQUATERNION &res) +void Bone::BlendFrame(int32_t frame, float kBlend, Quaternion &res) { if (numFrames <= 0) return; @@ -183,14 +185,14 @@ void Bone::BlendFrame(int32_t frame, float kBlend, D3DXQUATERNION &res) GetFrame(numFrames - 1, res); return; } - D3DXQUATERNION q0, q1; + Quaternion q0, q1; GetFrame(f0, q0); GetFrame(f1, q1); if (kBlend < 0.0f) kBlend = 0.0f; if (kBlend > 1.0f) kBlend = 1.0f; - D3DXQuaternionSlerp(&res, &q0, &q1, kBlend); + res.SLerp(q0, q1, kBlend); } // Create a matrix for the resulting position @@ -198,7 +200,9 @@ void Bone::BuildMatrix() { // Turns // matrix = a.BuildMatrix(); - D3DXMatrixRotationQuaternion(matrix, &a); + Matrix tmpMtx; + a.GetMatrix(tmpMtx); + matrix = tmpMtx; matrix.Pos() = p; // Multiply by the parent matrix if (parent) diff --git a/src/libs/animation/src/bone.h b/src/libs/animation/src/bone.h index 18e362e63..c86a5b993 100644 --- a/src/libs/animation/src/bone.h +++ b/src/libs/animation/src/bone.h @@ -13,9 +13,8 @@ //============================================================================================ #include "matrix.h" +#include "math3d/quaternion.h" #include "defines.h" - -#include //============================================================================================ #define ANI_COMPRESS_ENABLE @@ -47,7 +46,7 @@ class Bone // Set animation positions void SetPositions(const CVECTOR *pArray, int32_t numPos); // Set animation angles - void SetAngles(const D3DXQUATERNION *aArray, int32_t numAng); + void SetAngles(const Quaternion *aArray, int32_t numAng); // Initialize start matrix void BuildStartMatrix(); @@ -56,14 +55,14 @@ class Bone // -------------------------------------------------------------------------------------------- public: // Add animation frames - void BlendFrame(int32_t frame, float kBlend, D3DXQUATERNION &res); + void BlendFrame(int32_t frame, float kBlend, Quaternion &res); // void BlendFrame(float frame); // Create a matrix for the resulting position void BuildMatrix(); // Create matrix for frame 0 // void BuildMatrixZero(); // Get position matrix - CMatrix &Matrix(); + CMatrix &GetMatrix(); // Get the starting position matrix CMatrix &StartMatrix(); @@ -71,7 +70,7 @@ class Bone // Encapsulation // -------------------------------------------------------------------------------------------- private: - void GetFrame(int32_t f, D3DXQUATERNION &qt); + void GetFrame(int32_t f, Quaternion &qt); float Clamp(float v, const char *str); // Linear position interpolation float LerpPos(float a, float b, float k); @@ -84,7 +83,7 @@ class Bone #ifdef ANI_COMPRESS_ENABLE COMP_QUATERNION *ang; // Compressed angles of animation frames #else - D3DXQUATERNION *ang; // Animation frame angles + Quaternion *ang; // Animation frame angles #endif CVECTOR *pos; // Animation frame positions @@ -92,7 +91,7 @@ class Bone CVECTOR pos0; // Bone position if there are no animation frame positions CVECTOR p; // Bone position in local coordinates - D3DXQUATERNION a; // Bone rotation angles in local coordinates + Quaternion a; // Bone rotation angles in local coordinates CMatrix matrix; // Bone position matrix CMatrix start; // Frame 0 matrix }; @@ -108,7 +107,7 @@ inline void Bone::SetParent(Bone *parentBone) } // Get position matrix -inline CMatrix &Bone::Matrix() +inline CMatrix &Bone::GetMatrix() { return matrix; } diff --git a/src/libs/battle_interface/src/log_and_action.cpp b/src/libs/battle_interface/src/log_and_action.cpp index 6c25fb8a9..3bdcd5568 100644 --- a/src/libs/battle_interface/src/log_and_action.cpp +++ b/src/libs/battle_interface/src/log_and_action.cpp @@ -233,7 +233,7 @@ void ILogAndActions::Realize(uint32_t delta_time) if (m_bShowActiveCommand) { CMatrix matw; - rs->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)&matw); + rs->SetTransform(D3DTS_WORLD, matw); // show icon if ((m_idIconTexture != -1L) && m_bThatRealAction) { diff --git a/src/libs/battle_interface/src/sea/ship_info_images.cpp b/src/libs/battle_interface/src/sea/ship_info_images.cpp index 8bfba761d..461da4142 100644 --- a/src/libs/battle_interface/src/sea/ship_info_images.cpp +++ b/src/libs/battle_interface/src/sea/ship_info_images.cpp @@ -41,7 +41,7 @@ void ShipInfoImages::Draw() return; CMatrix matw; - pRS->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)&matw); + pRS->SetTransform(D3DTS_WORLD, matw); if (m_idRelationTexture != -1) { diff --git a/src/libs/battle_interface/src/sea/ship_pointer.cpp b/src/libs/battle_interface/src/sea/ship_pointer.cpp index 89831fac0..b313267d1 100644 --- a/src/libs/battle_interface/src/sea/ship_pointer.cpp +++ b/src/libs/battle_interface/src/sea/ship_pointer.cpp @@ -90,7 +90,7 @@ void SHIPPOINTER::Realize(uint32_t delta_time) const return; CMatrix matw; - rs->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)&matw); + rs->SetTransform(D3DTS_WORLD, matw); if (m_bFriend) rs->TextureSet(0, m_idFriendTex); diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 895e6057b..3c3c7b4b7 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -2,7 +2,6 @@ #include #include -#include #include "entity.h" #include "matrix.h" @@ -267,7 +266,9 @@ class VDX9RENDER : public SERVICE virtual HRESULT SetFVF(uint32_t handle) = 0; virtual HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) = 0; virtual HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) = 0; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect virtual ID3DXEffect *GetEffectPointer(const char *techniqueName) = 0; +#endif // D3D Render Target/Begin/End/Clear virtual HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) = 0; diff --git a/src/libs/common/include/math3d/matrix.h b/src/libs/common/include/math3d/matrix.h index a59e103de..4b0d5c99c 100644 --- a/src/libs/common/include/math3d/matrix.h +++ b/src/libs/common/include/math3d/matrix.h @@ -8,11 +8,10 @@ #include "plane.h" #include "vector4.h" +#include //============================================================================================ -struct D3DXMATRIX; - #pragma pack(push, 1) //============================================================================================ @@ -238,7 +237,7 @@ class Matrix float &operator()(int32_t i, int32_t j); // Get a pointer to a D3D matrix - operator D3DXMATRIX *() const; + operator D3DMATRIX *() const; // Get a vector for calculating the X component Vector4 GetVectorX() const; @@ -1479,9 +1478,9 @@ inline float &Matrix::operator()(int32_t i, int32_t j) } // Get a pointer to a D3D matrix -inline Matrix::operator D3DXMATRIX *() const +inline Matrix::operator D3DMATRIX *() const { - return ((D3DXMATRIX *)matrix); + return ((D3DMATRIX *)matrix); } // Get a vector for calculating the X component diff --git a/src/libs/common/include/math3d/quaternion.h b/src/libs/common/include/math3d/quaternion.h index 52e8d2136..a3be0d49e 100644 --- a/src/libs/common/include/math3d/quaternion.h +++ b/src/libs/common/include/math3d/quaternion.h @@ -11,7 +11,6 @@ //============================================================================================ -struct D3DXQUATERNION; #pragma pack(push, 1) //============================================================================================ diff --git a/src/libs/common/include/matrix.h b/src/libs/common/include/matrix.h index 09d0585d1..acef474a8 100644 --- a/src/libs/common/include/matrix.h +++ b/src/libs/common/include/matrix.h @@ -3,6 +3,7 @@ #include #include "c_vector.h" +#include "math3d/matrix.h" #include #ifdef _WIN32 #include @@ -99,6 +100,7 @@ class CMatrix // Equal void operator=(const CMatrix &matrix); + void operator=(const Matrix &matrix); // Multiply void operator*=(CMatrix &matrix); @@ -405,6 +407,26 @@ inline void CMatrix::operator=(const CMatrix &matrix) }*/ } +inline void CMatrix::operator=(const Matrix &matrix) +{ + this->matrix[0] = matrix.matrix[0]; + this->matrix[1] = matrix.matrix[1]; + this->matrix[2] = matrix.matrix[2]; + this->matrix[3] = matrix.matrix[3]; + this->matrix[4] = matrix.matrix[4]; + this->matrix[5] = matrix.matrix[5]; + this->matrix[6] = matrix.matrix[6]; + this->matrix[7] = matrix.matrix[7]; + this->matrix[8] = matrix.matrix[8]; + this->matrix[9] = matrix.matrix[9]; + this->matrix[10] = matrix.matrix[10]; + this->matrix[11] = matrix.matrix[11]; + this->matrix[12] = matrix.matrix[12]; + this->matrix[13] = matrix.matrix[13]; + this->matrix[14] = matrix.matrix[14]; + this->matrix[15] = matrix.matrix[15]; +} + // Multiply inline void CMatrix::operator*=(CMatrix &matrix) { diff --git a/src/libs/mast/src/mast.cpp b/src/libs/mast/src/mast.cpp index 2d11ed8f3..7701eaa1e 100644 --- a/src/libs/mast/src/mast.cpp +++ b/src/libs/mast/src/mast.cpp @@ -150,7 +150,7 @@ void MAST::Realize(uint32_t Delta_Time) CMatrix mtx; mtx.SetIdentity(); - RenderService->SetTransform(D3DTS_WORLD,(D3DXMATRIX*)&mtx); + RenderService->SetTransform(D3DTS_WORLD, mtx); struct LINEVERTEX { diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index dc12c0fe2..66a16450a 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -2147,7 +2147,7 @@ bool DX9RENDER::SetPerspective(float perspective, float fAspectRatio) const float h = 1.0f / tanf(fov_vert * 0.5f); const float Q = far_plane / (far_plane - near_plane); - D3DXMATRIX mtx; + D3DMATRIX mtx; PZERO(&mtx, sizeof(mtx)); mtx._11 = w; diff --git a/src/libs/rigging/src/flag.cpp b/src/libs/rigging/src/flag.cpp index 11522887d..125ace144 100644 --- a/src/libs/rigging/src/flag.cpp +++ b/src/libs/rigging/src/flag.cpp @@ -127,7 +127,7 @@ void FLAG::Realize(uint32_t Delta_Time) uint32_t ambient; RenderService->GetRenderState(D3DRS_AMBIENT, &ambient); RenderService->SetRenderState(D3DRS_TEXTUREFACTOR, ambient); - RenderService->SetTransform(D3DTS_WORLD, &rootMatrix); + RenderService->SetTransform(D3DTS_WORLD, rootMatrix); // draw nature flag if (nVert != 0 && nIndx != 0) @@ -653,8 +653,7 @@ void FLAG::FirstRun() { SetAll(); - ZERO(rootMatrix); - rootMatrix._11 = rootMatrix._22 = rootMatrix._33 = rootMatrix._44 = 1.f; + rootMatrix.SetIdentity(); } if (nVert) diff --git a/src/libs/rigging/src/flag.h b/src/libs/rigging/src/flag.h index 1f8845b38..63d1f5d35 100644 --- a/src/libs/rigging/src/flag.h +++ b/src/libs/rigging/src/flag.h @@ -158,7 +158,7 @@ class FLAG : public Entity FLAGLXVERTEX *vertBuf; uint16_t *indxBuf; - D3DXMATRIX rootMatrix; + CMatrix rootMatrix; int32_t vBuf, iBuf; uint32_t nVert, nIndx; diff --git a/src/libs/rigging/src/rope.cpp b/src/libs/rigging/src/rope.cpp index bb92448ea..9e9f24d65 100644 --- a/src/libs/rigging/src/rope.cpp +++ b/src/libs/rigging/src/rope.cpp @@ -162,7 +162,7 @@ void ROPE::Realize(uint32_t Delta_Time) { static_cast(EntityManager::GetEntityPointer(gdata[i].shipEI)) ->SetLightAndFog(true); - RenderService->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)gdata[i].pMatWorld); + RenderService->SetTransform(D3DTS_WORLD, *gdata[i].pMatWorld); RenderService->TextureSet(0, texl); RenderService->SetMaterial(mat); diff --git a/src/libs/rigging/src/sail.cpp b/src/libs/rigging/src/sail.cpp index dcf485d75..9d400030b 100644 --- a/src/libs/rigging/src/sail.cpp +++ b/src/libs/rigging/src/sail.cpp @@ -538,8 +538,8 @@ void SAIL::Realize(uint32_t Delta_Time) RenderService->SetMaterial(mat); RenderService->TextureSet(2, texl); CMatrix matv, matp, matc; - RenderService->GetTransform(D3DTS_VIEW, (D3DXMATRIX *)&matv); - RenderService->GetTransform(D3DTS_PROJECTION, (D3DXMATRIX *)&matp); + RenderService->GetTransform(D3DTS_VIEW, matv); + RenderService->GetTransform(D3DTS_PROJECTION, matp); matc = matv * matp; if constexpr (false) // Delta_Time==0 ) { @@ -555,7 +555,7 @@ void SAIL::Realize(uint32_t Delta_Time) if (slist[i]->bFreeSail) continue; // if(gdata[slist[i]->HostNum].bDeleted) continue; - RenderService->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)slist[i]->pMatWorld); + RenderService->SetTransform(D3DTS_WORLD, *slist[i]->pMatWorld); RenderService->TextureSet(0, slist[i]->surfaceTex); if (slist[i]->m_bIsGerald) { @@ -594,7 +594,7 @@ void SAIL::Realize(uint32_t Delta_Time) { i = gdata[j].sailIdx[idx]; // if(gdata[slist[i]->HostNum].bDeleted) continue; - RenderService->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)slist[i]->pMatWorld); + RenderService->SetTransform(D3DTS_WORLD, *slist[i]->pMatWorld); RenderService->TextureSet(0, slist[i]->surfaceTex); if (slist[i]->m_bIsGerald) { diff --git a/src/libs/rigging/src/vant.cpp b/src/libs/rigging/src/vant.cpp index 680bfaa75..86895fedd 100644 --- a/src/libs/rigging/src/vant.cpp +++ b/src/libs/rigging/src/vant.cpp @@ -129,7 +129,7 @@ void VANT_BASE::Realize(uint32_t Delta_Time) static_cast(EntityManager::GetEntityPointer(gdata[gn].shipEI))->SetLightAndFog(true); static_cast(EntityManager::GetEntityPointer(gdata[gn].shipEI))->SetLights(); - RenderService->SetTransform(D3DTS_WORLD, (D3DXMATRIX *)gdata[gn].pMatWorld); + RenderService->SetTransform(D3DTS_WORLD, *gdata[gn].pMatWorld); RenderService->DrawBuffer(vBuf, sizeof(VANTVERTEX), iBuf, 0, nVert, gdata[gn].sIndx, gdata[gn].nIndx); static_cast(EntityManager::GetEntityPointer(gdata[gn].shipEI))->UnSetLights(); diff --git a/src/libs/sea/src/env_map.cpp b/src/libs/sea/src/env_map.cpp index 1864ff19e..3e33072be 100644 --- a/src/libs/sea/src/env_map.cpp +++ b/src/libs/sea/src/env_map.cpp @@ -5,6 +5,7 @@ #include "shared/messages.h" #include "shared/layers.h" +#include "math3d/plane.h" void SEA::EnvMap_GetSideMatrix(D3DCUBEMAP_FACES Face, CMatrix &mView) { @@ -53,36 +54,19 @@ bool SEA::SunRoad_Render2() auto PlaneHeight = 0.5f; - D3DXPLANE plane; - const D3DXVECTOR3 point(0, PlaneHeight, 0), normal(0, 1, 0); - D3DXPlaneFromPointNormal(&plane, &point, &normal); + const Vector point(0, PlaneHeight, 0), normal(0, 1, 0); + auto mPlane = Plane(normal, point); - D3DXMATRIX matReflect; - D3DXMatrixReflect(&matReflect, &plane); + CMatrix Invertor; + Invertor.BuildMirrorMatrix(mPlane.N.x, mPlane.N.y, mPlane.N.z, mPlane.D); auto mView = rs->GetView(); - auto mViewNew = mView; - CMatrix Invertor; - memcpy(Invertor.m, matReflect.m, sizeof(float) * 16); mViewNew = Invertor * mViewNew; rs->SetView(mViewNew); - auto _mWorld = CMatrix(); - auto _mView = rs->GetView(); - auto _mProj = rs->GetProjection(); - auto _mWorldView = _mWorld * _mView; - auto _mWorldViewProj = _mWorldView * _mProj; - - D3DXMATRIX mInv; - memcpy(mInv.m, _mWorldViewProj.m, sizeof(float) * 16); - D3DXMatrixInverse(&mInv, nullptr, &mInv); - D3DXMatrixTranspose(&mInv, &mInv); - D3DXPlaneTransform(&plane, &plane, &mInv); - rs->SetClipPlane(0, (FLOAT *)&plane); - uint32_t Colors[6] = {0xd934c8, 0x2FFF1F, 0x0000FF, 0xFF00, 0xb28e11, 0x0}; // for (uint32_t i=0; i<6; i++) { @@ -147,35 +131,19 @@ bool SEA::EnvMap_Render2() auto PlaneHeight = 0.5f; - D3DXPLANE plane; - const D3DXVECTOR3 point(0, PlaneHeight, 0), normal(0, 1, 0); - D3DXPlaneFromPointNormal(&plane, &point, &normal); + const Vector point(0, PlaneHeight, 0), normal(0, 1, 0); + auto mPlane = Plane(normal, point); - D3DXMATRIX matReflect; - D3DXMatrixReflect(&matReflect, &plane); + CMatrix Invertor; + Invertor.BuildMirrorMatrix(mPlane.N.x, mPlane.N.y, mPlane.N.z, mPlane.D); auto mView = rs->GetView(); - CMatrix mViewNew = mView; - CMatrix Invertor; - memcpy(Invertor.m, matReflect.m, sizeof(float) * 16); mViewNew = Invertor * mViewNew; rs->SetView(mViewNew); - auto _mWorld = CMatrix(); - CMatrix _mView = rs->GetView(); - CMatrix _mProj = rs->GetProjection(); - CMatrix _mWorldView = _mWorld * _mView; - CMatrix _mWorldViewProj = _mWorldView * _mProj; - - D3DXMATRIX mInv; - memcpy(mInv.m, _mWorldViewProj.m, sizeof(float) * 16); - D3DXMatrixInverse(&mInv, nullptr, &mInv); - D3DXMatrixTranspose(&mInv, &mInv); - D3DXPlaneTransform(&plane, &plane, &mInv); - rs->SetClipPlane(0, (FLOAT *)&plane); // rs->SetEffect("FlatSeaReverseCull"); // Event("SeaReflection"); diff --git a/src/libs/weather/src/rain.cpp b/src/libs/weather/src/rain.cpp index 1327bf790..b624684d5 100644 --- a/src/libs/weather/src/rain.cpp +++ b/src/libs/weather/src/rain.cpp @@ -223,7 +223,7 @@ void RAIN::RealizeDrops(uint32_t Delta_Time) static auto dwShipName = MakeHashValue("SHIP"); CMatrix mView; - rs->GetTransform(D3DTS_VIEW, (D3DXMATRIX *)&mView); + rs->GetTransform(D3DTS_VIEW, mView); mView.Transposition(); float fFov; diff --git a/src/libs/weather/src/sky.cpp b/src/libs/weather/src/sky.cpp index abc6172fc..83be80bab 100644 --- a/src/libs/weather/src/sky.cpp +++ b/src/libs/weather/src/sky.cpp @@ -326,17 +326,15 @@ void SKY::Realize(uint32_t Delta_Time) float fFov; CVECTOR vPos, vAng; - D3DXMATRIX pMatWorld, pMatTranslate, pMatRotate; + CMatrix pMatWorld, pMatTranslate, pMatRotate; pRS->GetCamera(vPos, vAng, fFov); - D3DXMatrixIdentity(&pMatWorld); - - D3DXMatrixTranslation(&pMatTranslate, vPos.x, vPos.y / 6.0f, vPos.z); - D3DXMatrixMultiply(&pMatWorld, &pMatWorld, &pMatTranslate); - D3DXMatrixRotationY(&pMatRotate, fAngleY + fSkyAngle); - D3DXMatrixMultiply(&pMatWorld, &pMatRotate, &pMatWorld); - pRS->SetTransform(D3DTS_WORLD, &pMatWorld); + pMatTranslate.BuildPosition(vPos.x, vPos.y / 6.0f, vPos.z); + pMatWorld = pMatWorld * pMatTranslate; + pMatRotate.BuildRotateY(fAngleY + fSkyAngle); + pMatWorld = pMatRotate * pMatWorld; + pRS->SetTransform(D3DTS_WORLD, pMatWorld); if (aSkyDirArray.size() > 1) { @@ -381,7 +379,7 @@ void SKY::Realize(uint32_t Delta_Time) if (pSunGlow) static_cast(pSunGlow)->DrawSunMoon(); - pRS->SetTransform(D3DTS_WORLD, &pMatWorld); + pRS->SetTransform(D3DTS_WORLD, pMatWorld); if (pRS->TechniqueExecuteStart(sTechSkyBlendAlpha.c_str())) do { @@ -419,10 +417,10 @@ void SKY::Realize(uint32_t Delta_Time) } while (pRS->TechniqueExecuteNext()); } - D3DXMatrixIdentity(&pMatWorld); - D3DXMatrixTranslation(&pMatTranslate, vPos.x, vPos.y / 6.0f, vPos.z); - D3DXMatrixMultiply(&pMatWorld, &pMatWorld, &pMatTranslate); - pRS->SetTransform(D3DTS_WORLD, &pMatWorld); + pMatWorld.SetIdentity(); + pMatTranslate.BuildPosition(vPos.x, vPos.y / 6.0f, vPos.z); + pMatWorld = pMatWorld * pMatTranslate; + pRS->SetTransform(D3DTS_WORLD, pMatWorld); pRS->DrawBuffer(iFogVertsID, sizeof(FOGVERTEX), iFogIndexID, 0, kFogVertsNum, 0, kFogTrgsNum / 3, sTechSkyFog.c_str()); } diff --git a/src/libs/xinterface/src/back_scene/back_scene.cpp b/src/libs/xinterface/src/back_scene/back_scene.cpp index 4f837ad4f..0818bc1a7 100644 --- a/src/libs/xinterface/src/back_scene/back_scene.cpp +++ b/src/libs/xinterface/src/back_scene/back_scene.cpp @@ -628,14 +628,14 @@ int32_t InterfaceBackScene::CheckMousePos(float fX, float fY) float fRelY = 2.f * fY / fH - 1.f; CMatrix mtxProj; - m_pRS->GetTransform(D3DTS_PROJECTION, (D3DXMATRIX *)&mtxProj); + m_pRS->GetTransform(D3DTS_PROJECTION, mtxProj); CVECTOR v; v.x = fRelX / mtxProj.m[0][0]; v.y = -fRelY / mtxProj.m[1][1]; v.z = 1.0f; CMatrix mtxView; - m_pRS->GetTransform(D3DTS_VIEW, (D3DXMATRIX *)&mtxView); + m_pRS->GetTransform(D3DTS_VIEW, mtxView); CVECTOR vDir; mtxView.MulToInvNorm(v, vDir); mtxView.Transposition(); From 733256930d99726a982d792f1f9228c36546d3e3 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 11 Jan 2022 20:59:48 +0300 Subject: [PATCH 04/59] [linux] use custom sprintf_s instead of safeclib --- CMakeLists.txt | 26 ------------------------ src/libs/common/include/storm_platform.h | 22 +++++++++----------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 56b4add2e..91242ec8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,32 +58,6 @@ if (NOT WIN32) set(DXVK_NATIVE_D3D9_LIB ${BINARY_DIR}/src/d3d9/libdxvk_d3d9.so) include_directories("${DXVK_NATIVE_INCLUDE_DIRS}") ADD_CUSTOM_TARGET(dependencies ALL DEPENDS dxvk-native) - -# message("Using safeclib for str*_s functions") - -# include(ProcessorCount) -# ProcessorCount(N) -# if (N EQUAL 0) -# set(N 1) -# endif() - -# ExternalProject_Add(safeclib -# GIT_REPOSITORY https://github.com/rurban/safeclib -# GIT_TAG v02092020 -# GIT_SHALLOW ON -# BUILD_ALWAYS OFF -# CONFIGURE_HANDLED_BY_BUILD ON -# CONFIGURE_COMMAND ./build-aux/autogen.sh && ./configure --enable-strmax=0x8000 --enable-shared=no --disable-doc -# BUILD_COMMAND make -j${N} -# BUILD_IN_SOURCE ON -# INSTALL_COMMAND "" -# ) -# ExternalProject_Get_property(safeclib SOURCE_DIR BINARY_DIR) -# set(SAFECLIB_INCLUDE_DIR "${SOURCE_DIR}/include") -# set(SAFECLIB_LIB ${SOURCE_DIR}/src/.libs/libsafec-3.6.0.a) -# include_directories("${SAFECLIB_INCLUDE_DIR}") - -# ADD_CUSTOM_TARGET(dependencies ALL DEPENDS dxvk-native safeclib) endif() ### Define library ALIASes for use without CONAN_PKG:: prefix diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index 86c3294f5..9817803a3 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -1,10 +1,8 @@ #ifndef _WIN32 #include "safe_str_lib.h" - -// workaround for safeclib -//#undef sprintf_s(dest, dmax, ...) -//#define sprintf_s(dest, dmax, fmt, ...) _sprintf_s_chk(dest, dmax, BOS(dest), fmt, __VA_ARGS__) +// use custom sprintf_s instead of safeclib +#undef sprintf_s template inline int sprintf_s(char (&buffer)[size], const char *format, ...) { @@ -15,13 +13,13 @@ template inline int sprintf_s(char (&buffer)[size], const char *fo return result; } -/* -template -int sprintf_s( - char (&buffer)[size], - const char *format [, - argument] ... -); -*/ +inline int sprintf_s(char *buffer, size_t size, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int result = vsnprintf(buffer, size, format, ap); + va_end(ap); + return result; +} #endif From b394d9487fabe7839856f4938048ee3d120dde88 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Fri, 14 Jan 2022 00:57:44 +0300 Subject: [PATCH 05/59] [linux] FIX_LINUX s_debug.h --- src/apps/engine/src/compiler.cpp | 22 ++++++++++++++++++++++ src/apps/engine/src/main.cpp | 6 ++++++ src/apps/engine/src/s_dbg_breaktable.cpp | 2 ++ src/apps/engine/src/s_dbg_sourceview.cpp | 2 ++ src/apps/engine/src/s_dbg_watcherlist.cpp | 2 ++ src/apps/engine/src/s_debug.cpp | 2 ++ src/apps/engine/src/tm_list.cpp | 2 ++ src/libs/animation/src/action_info.cpp | 1 + 8 files changed, 39 insertions(+) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index f2faccb29..a3219e92b 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -5,7 +5,11 @@ #include +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_debug.h" +#else +#include "core.h" +#endif #include "logging.hpp" #include "script_cache.h" #include "storm_assert.h" @@ -133,7 +137,9 @@ void COMPILER::SetProgramDirectory(const char *dir_name) strcpy_s(ProgramDirectory, len, dir_name); strcat_s(ProgramDirectory, len, "\\"); } +#ifdef _WIN32 // FIX_LINUX s_debug.h CDebug->SetProgramDirectory(dir_name); +#endif } // load file into memory @@ -327,8 +333,10 @@ void COMPILER::SetError(const char *data_PTR, ...) logError_->error(ErrorBuffer); +#ifdef _WIN32 // FIX_LINUX s_debug.h if (bBreakOnError) CDebug->SetTraceMode(TMODE_MAKESTEP); +#endif } void COMPILER::SetWarning(const char *data_PTR, ...) @@ -391,11 +399,13 @@ void COMPILER::LoadPreprocess() // else bScriptTrace = true; } +#ifdef _WIN32 // FIX_LINUX s_debug.h auto ini = fio->OpenIniFile(PROJECT_NAME); if (ini) { bBreakOnError = (ini->GetInt("options", "break_on_error", 0) == 1); } +#endif } bool COMPILER::CreateProgram(const char *file_name) @@ -616,7 +626,9 @@ VDATA *COMPILER::ProcessEvent(const char *event_name) bEventsBreak = false; uint32_t nTimeOnEvent = GetTickCount(); +#ifdef _WIN32 // FIX_LINUX s_debug.h current_debug_mode = CDebug->GetTraceMode(); +#endif pVD = nullptr; if (event_name == nullptr) @@ -689,8 +701,10 @@ VDATA *COMPILER::ProcessEvent(const char *event_name) pRun_fi = nullptr; +#ifdef _WIN32 // FIX_LINUX s_debug.h if (current_debug_mode == TMODE_CONTINUE) CDebug->SetTraceMode(TMODE_CONTINUE); +#endif // SetFocus(core_internal.App_Hwnd); // VANO CHANGES RDTSC_E(dwRDTSC); @@ -3619,7 +3633,9 @@ bool COMPILER::BC_CallFunction(uint32_t func_code, uint32_t &ip, DATA *&pVResult mem_pfi = pRun_fi; mem_codebase = pRunCodeBase; +#ifdef _WIN32 // FIX_LINUX s_debug.h nDebugEnterMode = CDebug->GetTraceMode(); +#endif uint64_t nTicks; if (call_fi.segment_id == INTERNAL_SEGMENT_ID) { @@ -3670,10 +3686,12 @@ bool COMPILER::BC_CallFunction(uint32_t func_code, uint32_t &ip, DATA *&pVResult core_internal.Trace("Invalid func_code = %u for AddTime", func_code); } } +#ifdef _WIN32 // FIX_LINUX s_debug.h if (nDebugEnterMode == TMODE_MAKESTEP) { CDebug->SetTraceMode(TMODE_MAKESTEP); } +#endif if (pVResult) { @@ -4230,6 +4248,7 @@ bool COMPILER::BC_Execute(uint32_t function_code, DATA *&pVReturnResult, const c break; if (bDebugExpressionRun) break; +#ifdef _WIN32 // FIX_LINUX s_debug.h memcpy(&nDebugTraceLineCode, &pCodeBase[ip], sizeof(uint32_t)); if (bTraceMode) { @@ -4279,6 +4298,7 @@ bool COMPILER::BC_Execute(uint32_t function_code, DATA *&pVReturnResult, const c } } } +#endif break; case DEBUG_FILE_NAME: @@ -7959,5 +7979,7 @@ void COMPILER::FormatDialog(char *file_name) void STRING_CODEC::VariableChanged() { +#ifdef _WIN32 // FIX_LINUX s_debug.h CDebug->SetTraceMode(TMODE_MAKESTEP); +#endif } diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index 766ecd454..dc4604047 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -12,7 +12,11 @@ #include "os_window.hpp" #include "steam_api_impl.hpp" #include "file_service.h" +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_debug.h" +#else +#include "core.h" +#endif #include "v_sound_service.h" #include "storm/fs.h" #include "watermark.hpp" @@ -178,9 +182,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, core_internal.Init(); // Init script debugger +#ifdef _WIN32 // FIX_LINUX s_debug.h S_DEBUG debug; debug.Init(); CDebug = &debug; +#endif // Read config auto ini = fio->OpenIniFile(fs::ENGINE_INI_FILE_NAME); diff --git a/src/apps/engine/src/s_dbg_breaktable.cpp b/src/apps/engine/src/s_dbg_breaktable.cpp index 5f7d9a5c6..05cbe91c6 100644 --- a/src/apps/engine/src/s_dbg_breaktable.cpp +++ b/src/apps/engine/src/s_dbg_breaktable.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_dbg_breaktable.h" #include "file_service.h" @@ -195,3 +196,4 @@ bool BREAKPOINTS_TABLE::Find(const char *filename, uint32_t line) } return false; } +#endif diff --git a/src/apps/engine/src/s_dbg_sourceview.cpp b/src/apps/engine/src/s_dbg_sourceview.cpp index 246e04ff9..0652d26c3 100644 --- a/src/apps/engine/src/s_dbg_sourceview.cpp +++ b/src/apps/engine/src/s_dbg_sourceview.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_dbg_sourceview.h" #include "core_impl.h" #include "data.h" @@ -1346,3 +1347,4 @@ void SOURCE_VIEW::FindNext() } } } +#endif diff --git a/src/apps/engine/src/s_dbg_watcherlist.cpp b/src/apps/engine/src/s_dbg_watcherlist.cpp index d5bbb10a6..01e95a500 100644 --- a/src/apps/engine/src/s_dbg_watcherlist.cpp +++ b/src/apps/engine/src/s_dbg_watcherlist.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_dbg_watcherlist.h" #include "s_debug.h" @@ -194,3 +195,4 @@ void WATCHER_LIST::ProcessMessage(uint64_t iMsg, uint64_t wParam, uint64_t lPara break; }*/ } +#endif diff --git a/src/apps/engine/src/s_debug.cpp b/src/apps/engine/src/s_debug.cpp index 34bfe65ad..4b4b88638 100644 --- a/src/apps/engine/src/s_debug.cpp +++ b/src/apps/engine/src/s_debug.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_debug.h" #include "compiler.h" #include "core_impl.h" @@ -963,3 +964,4 @@ void S_DEBUG::OpenNewFile() CDebug->Add2RecentFiles(buffer); } } +#endif diff --git a/src/apps/engine/src/tm_list.cpp b/src/apps/engine/src/tm_list.cpp index 4fc2785cf..4654f344d 100644 --- a/src/apps/engine/src/tm_list.cpp +++ b/src/apps/engine/src/tm_list.cpp @@ -1,3 +1,4 @@ +#ifdef _WIN32 // FIX_LINUX s_debug.h #include "tm_list.h" #include "defines.h" @@ -429,3 +430,4 @@ char *TM_LIST::GetCharID() { return CharID; } +#endif diff --git a/src/libs/animation/src/action_info.cpp b/src/libs/animation/src/action_info.cpp index 41153a200..033b79d21 100644 --- a/src/libs/animation/src/action_info.cpp +++ b/src/libs/animation/src/action_info.cpp @@ -11,6 +11,7 @@ #include "action_info.h" #include "storm_assert.h" #include "storm/string_compare.hpp" +#include "storm_platform.h" // ============================================================================================ // Construction, destruction From 3112fbf048b4957a9a2fa26454ec250bb80e158c Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 15 Jan 2022 12:37:22 +0300 Subject: [PATCH 06/59] [linux] use custom strcpy_s instead of safeclib --- src/libs/common/include/storm_platform.h | 38 +++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index 9817803a3..a1a072eae 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -1,7 +1,43 @@ #ifndef _WIN32 #include "safe_str_lib.h" -// use custom sprintf_s instead of safeclib + +// use custom strcpy_s instead of safeclib: #define strcpy_s(dest, dmax, src) +#undef strcpy_s + +inline int strcpy_s(char *dest, size_t size, const char *src) +{ + if (!dest) + return EINVAL; + + if (0 == size) + { + dest[0] = '\0'; + return ERANGE; + } + + if (!src) + { + dest[0] = '\0'; + return EINVAL; + } + + size_t i; + for (i = 0; i < size; i++) + { + if ((dest[i] = src[i]) == '\0') + return 0; + } + dest[0] = '\0'; + return ERANGE; +} + +template inline int strcpy_s(char (&dest)[size], const char *src) +{ + return strcpy_s(dest, size, src); +} + +// use custom sprintf_s instead of safeclib: #define sprintf_s(dest, dmax, ...) #undef sprintf_s template inline int sprintf_s(char (&buffer)[size], const char *format, ...) From 08c5c996e0da93493255950489dd7445efea246b Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 15 Jan 2022 12:38:17 +0300 Subject: [PATCH 07/59] [linux] fix for building dxvk with PATCH_COMMAND --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91242ec8f..b2a17c1ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,13 +40,15 @@ if (NOT WIN32) message("Using DXVK-native for D3D9 API") include(ExternalProject) + #PATCH_COMMAND for ubuntu: https://bugs.launchpad.net/ubuntu/+source/libsdl2-ttf/+bug/1872023 ExternalProject_Add(dxvk-native GIT_REPOSITORY https://github.com/Joshua-Ashton/dxvk-native - GIT_TAG origin/master + GIT_TAG a2dc99c407340432d4ba5bfa29efa685c27942ea + PATCH_COMMAND sed -i "s+directx')+directx', '/usr/include/SDL2')+g" meson.build GIT_SHALLOW ON BUILD_ALWAYS OFF CONFIGURE_HANDLED_BY_BUILD ON - CONFIGURE_COMMAND CC=gcc-10 && CXX=g++-10 && meson ../dxvk-native + CONFIGURE_COMMAND meson ../dxvk-native BUILD_COMMAND ninja INSTALL_COMMAND "" ) From fb77858909f15aae0375aee3bf0e3e9243d8d04c Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sat, 15 Jan 2022 12:44:48 +0300 Subject: [PATCH 08/59] [linux] FIX_LINUX __debugbreak --- src/apps/engine/src/compiler.cpp | 2 ++ src/apps/engine/src/token.cpp | 2 ++ src/libs/animation/src/animation_imp.cpp | 2 ++ src/libs/common/include/storm_assert.h | 2 ++ src/libs/island/src/map_zipper.cpp | 2 ++ src/libs/location/src/character.cpp | 2 ++ src/libs/renderer/src/s_device.cpp | 10 ++++++++++ src/libs/xinterface/src/back_scene/back_scene.cpp | 2 ++ 8 files changed, 24 insertions(+) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index a3219e92b..19eb548fc 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -3899,7 +3899,9 @@ bool COMPILER::BC_Execute(uint32_t function_code, DATA *&pVReturnResult, const c switch (Token_type) { case ARGS_NUM: +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#endif break; case STACK_COMPARE: pV = SStack.Read(); diff --git a/src/apps/engine/src/token.cpp b/src/apps/engine/src/token.cpp index 0b48923f8..f1708f225 100644 --- a/src/apps/engine/src/token.cpp +++ b/src/apps/engine/src/token.cpp @@ -503,7 +503,9 @@ S_TOKEN_TYPE TOKEN::Get(bool bKeepData) const auto stt = ProcessToken(Program, bKeepData); if (stt == HOLD_COMPILATION) { +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#endif // stt == HOLD_COMPILATION; } return stt; diff --git a/src/libs/animation/src/animation_imp.cpp b/src/libs/animation/src/animation_imp.cpp index d230f6869..5976b2536 100644 --- a/src/libs/animation/src/animation_imp.cpp +++ b/src/libs/animation/src/animation_imp.cpp @@ -374,7 +374,9 @@ void AnimationImp::BuildAnimationMatrices() else { core.Trace("AnimationImp::BuildAnimationMatrices -> Not support mode"); +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#endif /*_asm int 3;*/ // float frame = 0.0f; // for(int32_t j = 0; j < nbones; j++) diff --git a/src/libs/common/include/storm_assert.h b/src/libs/common/include/storm_assert.h index 7ea67bc4f..f047c524b 100644 --- a/src/libs/common/include/storm_assert.h +++ b/src/libs/common/include/storm_assert.h @@ -1,7 +1,9 @@ #pragma once #include +#ifdef _WIN32 // FIX_LINUX __debugbreak #define EX_OFF +#endif inline void __Storm_Assert__(bool expression, const char *file, int32_t line, const char *str) { diff --git a/src/libs/island/src/map_zipper.cpp b/src/libs/island/src/map_zipper.cpp index 32d33ffd6..3d9c42527 100644 --- a/src/libs/island/src/map_zipper.cpp +++ b/src/libs/island/src/map_zipper.cpp @@ -72,12 +72,14 @@ void MapZipper::DoZip(uint8_t *pSrc, uint32_t _dwSizeX) dwNumRealBlocks = dwRealIndex; pRealData = static_cast(realloc(pRealData, dwRealIndex * dwBlockSize * dwBlockSize)); +#ifdef _WIN32 // FIX_LINUX __debugbreak for (y = 0; y < _dwSizeX; y++) for (x = 0; x < _dwSizeX; x++) { if (Get(x, y) != pSrc[x + y * _dwSizeX]) __debugbreak(); } +#endif } uint8_t MapZipper::Get(uint32_t dwX, uint32_t dwY) diff --git a/src/libs/location/src/character.cpp b/src/libs/location/src/character.cpp index 70090f84c..9fa7fee7b 100644 --- a/src/libs/location/src/character.cpp +++ b/src/libs/location/src/character.cpp @@ -3469,6 +3469,7 @@ uint32_t Character::zExMessage(MESSAGE &message) if (storm::iEquals(msg, "CheckID")) { #ifdef _DEBUG +#ifdef _WIN32 // FIX_LINUX __debugbreak const std::string &msg = message.String(); if (AttributesPointer) { @@ -3483,6 +3484,7 @@ uint32_t Character::zExMessage(MESSAGE &message) } if (strcmp(msg.c_str(), characterID) != 0) __debugbreak(); +#endif #endif return 1; } diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 66a16450a..68cb04ef4 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -2575,12 +2575,20 @@ void DX9RENDER::LostRender() if (VertexBuffers[b].buff) { if (VertexBuffers[b].buff->Release() > 0) +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#else + do { __asm__ volatile ("int $3"); } while(0); +#endif } if (IndexBuffers[b].buff) { if (IndexBuffers[b].buff->Release() > 0) +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#else + do { __asm__ volatile ("int $3"); } while(0); +#endif } } @@ -3622,7 +3630,9 @@ HRESULT DX9RENDER::Release(IUnknown *pObject) { if (*(void **)pObject == nullptr) { +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#endif } else { diff --git a/src/libs/xinterface/src/back_scene/back_scene.cpp b/src/libs/xinterface/src/back_scene/back_scene.cpp index 0818bc1a7..944b46c64 100644 --- a/src/libs/xinterface/src/back_scene/back_scene.cpp +++ b/src/libs/xinterface/src/back_scene/back_scene.cpp @@ -33,7 +33,9 @@ void InterfaceBackScene::LightParam::UpdateParams(float fTime) if (jjj > 10000) { core.Trace("jjj: %f, %f", fColorTimer, fColorPeriod); +#ifdef _WIN32 // FIX_LINUX __debugbreak __debugbreak(); +#endif } } const auto fPer = fColorPeriod + fAddPeriod; From 4f41ef41fde7e9e65cdda476af9856e7bb177af8 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 05:03:12 +0300 Subject: [PATCH 09/59] [linux] replace LOWORD --- src/libs/island/src/foam.cpp | 2 +- src/libs/location/src/location_camera.cpp | 2 +- src/libs/sea_cameras/src/free_camera.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/island/src/foam.cpp b/src/libs/island/src/foam.cpp index eb238a70b..e28b04085 100644 --- a/src/libs/island/src/foam.cpp +++ b/src/libs/island/src/foam.cpp @@ -53,7 +53,7 @@ bool CoastFoam::Init() void CoastFoam::Execute(uint32_t Delta_Time) { - bEditMode = (bCanEdit) ? LOWORD(core.Controls->GetDebugKeyState(VK_NUMLOCK)) != 0 : false; + bEditMode = (bCanEdit) ? (core.Controls->GetDebugKeyState(VK_NUMLOCK) & 1) : false; auto fDeltaTime = static_cast(Delta_Time) * 0.001f; } diff --git a/src/libs/location/src/location_camera.cpp b/src/libs/location/src/location_camera.cpp index 753ea19dd..43c64d8c1 100644 --- a/src/libs/location/src/location_camera.cpp +++ b/src/libs/location/src/location_camera.cpp @@ -562,7 +562,7 @@ void LocationCamera::ExecuteTopos(float dltTime) // Free flying camera execution void LocationCamera::ExecuteFree(float dltTime) { - if (LOWORD(GetKeyState(VK_NUMLOCK)) != 0) + if (GetKeyState(VK_NUMLOCK) & 1) return; const auto pi = 3.14159265359f; diff --git a/src/libs/sea_cameras/src/free_camera.cpp b/src/libs/sea_cameras/src/free_camera.cpp index 257034496..d7cd79a97 100644 --- a/src/libs/sea_cameras/src/free_camera.cpp +++ b/src/libs/sea_cameras/src/free_camera.cpp @@ -87,7 +87,7 @@ void FREE_CAMERA::Move(uint32_t DeltaTime) { if (!isActive()) return; - if (LOWORD(GetKeyState(VK_NUMLOCK)) != 0) + if (GetKeyState(VK_NUMLOCK) & 1) return; // POINT pnt; From 6390a41a1c04fe3f65294c9a50aa4882e5420ff9 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 05:11:21 +0300 Subject: [PATCH 10/59] [linux] revert single FIX_LINUX ID3DXEffect --- src/libs/common/include/dx9render.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 3c3c7b4b7..52fe5eda2 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -266,9 +266,7 @@ class VDX9RENDER : public SERVICE virtual HRESULT SetFVF(uint32_t handle) = 0; virtual HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) = 0; virtual HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) = 0; -#ifdef _WIN32 // FIX_LINUX ID3DXEffect virtual ID3DXEffect *GetEffectPointer(const char *techniqueName) = 0; -#endif // D3D Render Target/Begin/End/Clear virtual HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) = 0; From 53ddb04b91ff1e9f68ab2bff313921e3241d6fe3 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 05:46:24 +0300 Subject: [PATCH 11/59] [linux] FIX_LINUX ID3DXEffect --- src/libs/common/include/dx9render.h | 2 ++ src/libs/location/src/grass.cpp | 13 +++++++++++++ src/libs/location/src/grass.h | 6 ++++++ src/libs/renderer/src/effects.cpp | 12 ++++++++++++ src/libs/renderer/src/effects.h | 8 ++++++++ src/libs/renderer/src/s_device.cpp | 2 ++ src/libs/renderer/src/s_device.h | 2 ++ 7 files changed, 45 insertions(+) diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 52fe5eda2..3c3c7b4b7 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -266,7 +266,9 @@ class VDX9RENDER : public SERVICE virtual HRESULT SetFVF(uint32_t handle) = 0; virtual HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) = 0; virtual HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) = 0; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect virtual ID3DXEffect *GetEffectPointer(const char *techniqueName) = 0; +#endif // D3D Render Target/Begin/End/Clear virtual HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) = 0; diff --git a/src/libs/location/src/grass.cpp b/src/libs/location/src/grass.cpp index 9f30ae0cc..387ed31e0 100644 --- a/src/libs/location/src/grass.cpp +++ b/src/libs/location/src/grass.cpp @@ -139,6 +139,7 @@ bool Grass::Init() } rs->UnLockIndexBuffer(ib); +#ifdef _WIN32 // FIX_LINUX ID3DXEffect // Constants static const auto pi2 = 2.0f * 3.141592653f; for (size_t i = 0; i < 16; i++) @@ -149,6 +150,7 @@ bool Grass::Init() // Uv table aUV[i] = {static_cast(i & 3) * (1.0f / 4.0f), static_cast((i >> 2) & 3) * (1.0f / 4.0f)}; } +#endif return true; } @@ -377,8 +379,13 @@ void Grass::Execute(uint32_t delta_time) void Grass::Realize(uint32_t delta_time) { +#ifdef _WIN32 // FIX_LINUX ID3DXEffect if (quality == rq_off || fx_ == nullptr) return; +#else + if (quality == rq_off) + return; +#endif rs->SetTransform(D3DTS_WORLD, CMatrix()); // Remove textures rs->TextureSet(0, -1); @@ -516,6 +523,7 @@ void Grass::Realize(uint32_t delta_time) lColor = 0.3f; } +#ifdef _WIN32 // FIX_LINUX ID3DXEffect // recalculate the parameters of the angles for (int32_t i = 0; i < 16; i++) { @@ -525,6 +533,7 @@ void Grass::Realize(uint32_t delta_time) if (aAngles[i].z > 1.0f) aAngles[i].z = 1.0f; } +#endif // matrix CMatrix view, prj; @@ -557,6 +566,7 @@ void Grass::Realize(uint32_t delta_time) rs->TextureSet(0, texture); rs->TextureSet(1, texture); // set constants +#ifdef _WIN32 // FIX_LINUX ID3DXEffect fx_->SetMatrix(hgVP_, cmtx); fx_->SetValue(haAngles_, &aAngles[0], sizeof(D3DXVECTOR3) * 16); fx_->SetValue(haUV_, &aUV[0], sizeof(D3DXVECTOR2) * 16); @@ -566,6 +576,7 @@ void Grass::Realize(uint32_t delta_time) fx_->SetFloat(hkLitWF_, kLitWF); fx_->SetFloat(hfDataScale_, m_fDataScale); fx_->SetValue(haSize_, D3DXVECTOR2(m_fMaxWidth, m_fMaxHeight), sizeof(D3DXVECTOR2)); +#endif // Camera position on the map int32_t camx = static_cast((pos.x / m_fDataScale - startX) / GRASS_BLK_DST); @@ -986,6 +997,7 @@ void Grass::CreateVertexDeclaration() const rs->CreateVertexDeclaration(VertexElements, &vertexDecl_); } +#ifdef _WIN32 // FIX_LINUX ID3DXEffect fx_ = rs->GetEffectPointer("Grass"); if (fx_ != nullptr) { @@ -999,4 +1011,5 @@ void Grass::CreateVertexDeclaration() const hfDataScale_ = fx_->GetParameterByName(nullptr, "fDataScale"); haSize_ = fx_->GetParameterByName(nullptr, "aSize"); } +#endif } diff --git a/src/libs/location/src/grass.h b/src/libs/location/src/grass.h index 5511c7b81..531b994a0 100644 --- a/src/libs/location/src/grass.h +++ b/src/libs/location/src/grass.h @@ -25,6 +25,7 @@ class Character; class Grass : public Entity { +#ifdef _WIN32 // FIX_LINUX ID3DXEffect static inline ID3DXEffect *fx_; static inline IDirect3DVertexDeclaration9 *vertexDecl_; static inline D3DXHANDLE hgVP_; @@ -36,6 +37,9 @@ class Grass : public Entity static inline D3DXHANDLE hlColor_; static inline D3DXHANDLE hfDataScale_; static inline D3DXHANDLE haSize_; +#else + static inline IDirect3DVertexDeclaration9 *vertexDecl_; +#endif #pragma pack(push, 1) @@ -207,8 +211,10 @@ class Grass : public Entity float windAng; int32_t initForce; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect D3DXVECTOR3 aAngles[16]; D3DXVECTOR2 aUV[16]; +#endif char textureName[64]; diff --git a/src/libs/renderer/src/effects.cpp b/src/libs/renderer/src/effects.cpp index 975e47f7b..d65d2d4e0 100644 --- a/src/libs/renderer/src/effects.cpp +++ b/src/libs/renderer/src/effects.cpp @@ -35,6 +35,7 @@ void Effects::setDevice(IDirect3DDevice9 *device) void Effects::compile(const char *fxPath) { debugMsg_ = fxPath; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect ID3DXEffect *fx; ID3DXBuffer *errors = nullptr; std::wstring _fxPath = utf8::ConvertUtf8ToWide(fxPath); @@ -73,12 +74,15 @@ void Effects::compile(const char *fxPath) CHECKD3DERR(fx->FindNextValidTechnique(technique, &technique)); } +#endif // ID3DXEffect } void Effects::release() { +#ifdef _WIN32 // FIX_LINUX ID3DXEffect for (auto *fx : effects_) fx->Release(); +#endif effects_.clear(); techniques_.clear(); currentTechnique_ = nullptr; @@ -100,6 +104,7 @@ bool Effects::begin(const std::string &techniqueName) } currentTechnique_ = &technique->second; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect auto *fx = currentTechnique_->fx; CHECKD3DERR(fx->SetTechnique(currentTechnique_->handle)); @@ -114,10 +119,14 @@ bool Effects::begin(const std::string &techniqueName) currentPass_ = 0; CHECKD3DERR(fx->BeginPass(currentPass_++)); return true; +#else + return false; +#endif } bool Effects::next() { +#ifdef _WIN32 // FIX_LINUX ID3DXEffect if (currentTechnique_) { debugMsg_ = currentTechnique_->desc.Name; @@ -133,9 +142,11 @@ bool Effects::next() CHECKD3DERR(fx->End()); currentTechnique_ = nullptr; } +#endif return false; } +#ifdef _WIN32 // FIX_LINUX ID3DXEffect ID3DXEffect *Effects::getEffectPointer(const std::string &techniqueName) { // transform to lowercase to be compliant with the original code @@ -146,3 +157,4 @@ ID3DXEffect *Effects::getEffectPointer(const std::string &techniqueName) const auto technique = techniques_.find(name_in_lowercase); return technique != techniques_.end() ? technique->second.fx : nullptr; } +#endif diff --git a/src/libs/renderer/src/effects.h b/src/libs/renderer/src/effects.h index c7843213b..db9fd716f 100644 --- a/src/libs/renderer/src/effects.h +++ b/src/libs/renderer/src/effects.h @@ -2,7 +2,9 @@ #include #include +#ifdef _WIN32 // FIX_LINUX ID3DXEffect #include +#endif #include #include @@ -11,6 +13,7 @@ class Effects final private: struct Technique { +#ifdef _WIN32 // FIX_LINUX ID3DXEffect Technique(ID3DXEffect *fx, D3DXHANDLE handle, D3DXTECHNIQUE_DESC desc) : fx(fx), handle(handle), desc(desc) { } @@ -18,11 +21,14 @@ class Effects final ID3DXEffect *fx; D3DXHANDLE handle; D3DXTECHNIQUE_DESC desc; +#endif }; IDirect3DDevice9 *device_; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect std::vector effects_; +#endif std::unordered_map techniques_; const Technique *currentTechnique_; @@ -50,6 +56,8 @@ class Effects final bool begin(const std::string &techniqueName); // Execute next technique bool next(); +#ifdef _WIN32 // FIX_LINUX ID3DXEffect // Get effect pointer by technique name ID3DXEffect *getEffectPointer(const std::string &techniqueName); +#endif }; diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 68cb04ef4..b85a569b6 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -3760,10 +3760,12 @@ HRESULT DX9RENDER::GetPixelShader(IDirect3DPixelShader9 **ppShader) return CHECKD3DERR(d3d9->GetPixelShader(ppShader)); } +#ifdef _WIN32 // FIX_LINUX ID3DXEffect ID3DXEffect *DX9RENDER::GetEffectPointer(const char *techniqueName) { return effects_.getEffectPointer(techniqueName); } +#endif HRESULT DX9RENDER::SetTexture(uint32_t Stage, IDirect3DBaseTexture9 *pTexture) { diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index 3ce9e7ed4..57b14e1a6 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -304,7 +304,9 @@ class DX9RENDER : public VDX9RENDER HRESULT SetFVF(uint32_t handle) override; HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) override; HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) override; +#ifdef _WIN32 // FIX_LINUX ID3DXEffect ID3DXEffect *GetEffectPointer(const char *techniqueName) override; +#endif // D3D Render Target/Begin/End/Clear HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) override; From 305d1968f7359fc91cf35e3fc73f98e14d06c44f Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 05:57:29 +0300 Subject: [PATCH 12/59] [linux] FIX_LINUX _flushall --- src/libs/island/src/foam.cpp | 2 ++ src/libs/renderer/src/screenshot.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/libs/island/src/foam.cpp b/src/libs/island/src/foam.cpp index e28b04085..1da41df3a 100644 --- a/src/libs/island/src/foam.cpp +++ b/src/libs/island/src/foam.cpp @@ -815,7 +815,9 @@ void CoastFoam::Save() pI->WriteString(cSection, cKey, cTemp); } } +#ifdef _WIN32 // FIX_LINUX _flushall _flushall(); +#endif } void CoastFoam::clear() diff --git a/src/libs/renderer/src/screenshot.cpp b/src/libs/renderer/src/screenshot.cpp index 2a7506aaf..5cfb87861 100644 --- a/src/libs/renderer/src/screenshot.cpp +++ b/src/libs/renderer/src/screenshot.cpp @@ -47,7 +47,9 @@ void DX9RENDER::SaveCaptureBuffers() iCaptureFrameIndex = fi + dwCaptureBuffersReady + 1; +#ifdef _WIN32 // FIX_LINUX _flushall _flushall(); +#endif dwCaptureBuffersReady = 0; } From 21847a9bda194a9c0899410cae4b33f8b5fb6ece Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 06:46:50 +0300 Subject: [PATCH 13/59] [linux] FIX_LINUX DirectXMath --- src/libs/model/src/model.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/model/src/model.cpp b/src/libs/model/src/model.cpp index 0ec25c5f6..f6d502efb 100644 --- a/src/libs/model/src/model.cpp +++ b/src/libs/model/src/model.cpp @@ -4,7 +4,9 @@ #include "modelr.h" #include "shared/messages.h" +#ifdef _WIN32 // FIX_LINUX DirectXMath #include +#endif CREATE_CLASS(MODELR) @@ -79,6 +81,7 @@ void *VBTransform(void *vb, int32_t startVrt, int32_t nVerts, int32_t totVerts) // Inverse blending coefficient const auto wNeg = 1.0f - vrt.weight; +#ifdef _WIN32 // FIX_LINUX DirectXMath #ifdef __AVX__ // apparently, _mm256_set1_ps seems to be better using msvc with lat=~7+1*2+4+1*5+5+7+1*2==24 vs ~7+1*2+4+1*5+1+3+1*2==32 for _mm256_broadcast_ss // TODO: check clang listings @@ -117,6 +120,7 @@ void *VBTransform(void *vb, int32_t startVrt, int32_t nVerts, int32_t totVerts) // Normal XMStoreFloat3(reinterpret_cast(&dstVrt.nrm), XMVector3Transform(XMLoadFloat3(reinterpret_cast(&vrt.nrm)), xmmtx)); +#endif // _WIN32 DirectXMath // Rest dstVrt.color = vrt.color; From c3ba6d3e00562d69acfd793d793224041da168b1 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 07:01:05 +0300 Subject: [PATCH 14/59] [linux] add explicit constructors for MovingLight, FindCharacter and CharacterEx --- src/libs/location/src/lights.h | 7 ++++++- src/libs/location/src/supervisor.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libs/location/src/lights.h b/src/libs/location/src/lights.h index af1f223d2..631923e1a 100644 --- a/src/libs/location/src/lights.h +++ b/src/libs/location/src/lights.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include "collide.h" @@ -59,6 +58,12 @@ class Lights : public Entity { int32_t id; int32_t light; + + MovingLight(int32_t id, int32_t light) + { + this->id = id; + this->light = light; + } }; struct Vertex diff --git a/src/libs/location/src/supervisor.h b/src/libs/location/src/supervisor.h index eb8fdc691..879f2d5e1 100644 --- a/src/libs/location/src/supervisor.h +++ b/src/libs/location/src/supervisor.h @@ -32,12 +32,27 @@ class Supervisor Character *c; // The character we were looking for float dx, dy, dz; // Vector from the character to us float d2; // The square of the distance to the character in xz + + FindCharacter(Character *c, float dx, float dy, float dz, float d2) + { + this->c = c; + this->dx = dx; + this->dy = dy; + this->dz = dz; + this->d2 = d2; + } }; struct CharacterEx { Character *c; float lastTime; + + CharacterEx(Character *c, float lastTime) + { + this->c = c; + this->lastTime = lastTime; + } }; // -------------------------------------------------------------------------------------------- From 64c8c4833c2a4c735ad7dd02aefdde512f7969ce Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 07:35:08 +0300 Subject: [PATCH 15/59] [linux] wrap and FIX_LINUX DxErr.h --- src/libs/lighter/src/l_geometry.cpp | 4 ++++ src/libs/renderer/src/effects.cpp | 7 +++++++ src/libs/renderer/src/s_device.cpp | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/libs/lighter/src/l_geometry.cpp b/src/libs/lighter/src/l_geometry.cpp index 523768792..800e1f57a 100644 --- a/src/libs/lighter/src/l_geometry.cpp +++ b/src/libs/lighter/src/l_geometry.cpp @@ -12,7 +12,11 @@ #include "entity.h" #include "core.h" +#ifdef _WIN32 #include +#else +#include +#endif // ============================================================================================ // Construction, destruction diff --git a/src/libs/renderer/src/effects.cpp b/src/libs/renderer/src/effects.cpp index d65d2d4e0..f59373d7d 100644 --- a/src/libs/renderer/src/effects.cpp +++ b/src/libs/renderer/src/effects.cpp @@ -1,7 +1,9 @@ #include "effects.h" #include "core.h" +#ifdef _WIN32 // FIX_LINUX DxErr.h #include +#endif #include #define CHECKD3DERR(expr) ErrorHandler(expr, __FILE__, __LINE__, __func__, #expr) @@ -10,8 +12,13 @@ inline bool Effects::ErrorHandler(HRESULT hr, const char *file, unsigned line, c { if (hr != D3D_OK && hr != S_FALSE) { +#ifdef _WIN32 // FIX_LINUX DxErr.h core.Trace("[%s:%s:%d] %s: %s (%s) (%.*s)", file, func, line, DXGetErrorString(hr), DXGetErrorDescription(hr), expr, debugMsg_.size(), debugMsg_.data()); +#else + core.Trace("[%s:%s:%d] (%s) (%.*s)", file, func, line, + expr, debugMsg_.size(), debugMsg_.data()); +#endif return true; } diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index b85a569b6..091b70c90 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -11,8 +11,12 @@ #include -#include +#ifdef _WIN32 +#include // FIX_LINUX DxErr.h #include +#else +#include +#endif CREATE_SERVICE(DX9RENDER) @@ -376,7 +380,11 @@ inline bool ErrorHandler(HRESULT hr, const char *file, unsigned line, const char { if (hr != D3D_OK) { +#ifdef _WIN32 // FIX_LINUX DxErr.h core.Trace("[%s:%s:%d] %s: %s (%s)", file, func, line, DXGetErrorStringA(hr), DXGetErrorDescriptionA(hr), expr); +#else + core.Trace("[%s:%s:%d] (%s)", file, func, line, expr); +#endif return true; } From b2447ea84e883763d07d6f23e2a7899f6e84ff9c Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 07:51:09 +0300 Subject: [PATCH 16/59] [linux] FIX_LINUX HBITMAP --- src/libs/renderer/src/s_device.cpp | 4 ++++ src/libs/renderer/src/s_device.h | 2 ++ src/libs/renderer/src/screenshot.cpp | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 091b70c90..9f04d20d9 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -710,10 +710,14 @@ DX9RENDER::~DX9RENDER() if (bPreparedCapture) { +#ifndef _WIN32 // FIX_LINUX HBITMAP STORM_DELETE(lpbi); +#endif ReleaseDC(static_cast(core.GetAppHWND()), hDesktopDC); DeleteDC(hCaptureDC); +#ifndef _WIN32 // FIX_LINUX HBITMAP DeleteObject(hCaptureBitmap); +#endif } for (const auto &buffer : aCaptureBuffers) delete buffer; diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index 57b14e1a6..044059953 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -489,8 +489,10 @@ class DX9RENDER : public VDX9RENDER // VideoCapture section HDC hDesktopDC, hCaptureDC; +#ifdef _WIN32 // FIX_LINUX HBITMAP HBITMAP hCaptureBitmap; LPBITMAPINFO lpbi; +#endif int32_t iCaptureFrameIndex; bool bPreparedCapture; bool bVideoCapture; diff --git a/src/libs/renderer/src/screenshot.cpp b/src/libs/renderer/src/screenshot.cpp index 5cfb87861..1f3eb8e86 100644 --- a/src/libs/renderer/src/screenshot.cpp +++ b/src/libs/renderer/src/screenshot.cpp @@ -6,6 +6,7 @@ void DX9RENDER::PrepareCapture() { +#ifdef _WIN32 // FIX_LINUX HBITMAP hDesktopDC = GetDC(static_cast(core.GetAppHWND())); hCaptureDC = CreateCompatibleDC(hDesktopDC); hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, screen_size.x, screen_size.y); @@ -18,6 +19,7 @@ void DX9RENDER::PrepareCapture() GetDIBits(hCaptureDC, hCaptureBitmap, 0, screen_size.y, nullptr, lpbi, DIB_RGB_COLORS); bPreparedCapture = true; +#endif } void DX9RENDER::SaveCaptureBuffers() @@ -68,6 +70,7 @@ bool DX9RENDER::MakeCapture() Beep(5000, 150); } +#ifdef _WIN32 // FIX_LINUX HBITMAP auto *const OldBmp = static_cast(SelectObject(hCaptureDC, hCaptureBitmap)); BitBlt(hCaptureDC, 0, 0, screen_size.x, screen_size.y, hDesktopDC, 0, 0, SRCCOPY); SelectObject(hCaptureDC, OldBmp); @@ -75,4 +78,7 @@ bool DX9RENDER::MakeCapture() DIB_RGB_COLORS); dwCaptureBuffersReady++; return true; +#else + return false; +#endif } From 74f392640add20b3e172393d5fcfcb249495b3b5 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 09:01:03 +0300 Subject: [PATCH 17/59] [linux] replace GetKeyState and GetAsyncKeyState with core functions --- src/libs/ball_splash/src/ball_splash.cpp | 2 +- src/libs/geometry/src/geometry.cpp | 2 +- src/libs/lighter/src/lighter.cpp | 4 +-- src/libs/lighter/src/window.cpp | 35 +++++++++--------- src/libs/location/src/location_camera.cpp | 2 +- src/libs/location/src/player.cpp | 2 +- src/libs/model/src/model.cpp | 4 +-- src/libs/sailors/src/sailors_editor.cpp | 14 ++++---- src/libs/sailors/src/sailors_menu.cpp | 36 +++++++++---------- src/libs/sea/src/sea.cpp | 4 +-- src/libs/sea_cameras/src/free_camera.cpp | 14 ++++---- src/libs/sea_creatures/src/sharks.cpp | 4 +-- src/libs/shadow/src/shadow.cpp | 2 +- src/libs/sink_effect/src/sink_effect.cpp | 2 +- src/libs/touch/src/touch.cpp | 4 +-- src/libs/worldmap/src/wdm_cloud.cpp | 3 +- src/libs/xinterface/src/nodes/xi_util.cpp | 2 +- .../src/string_service/str_service.cpp | 6 ++-- 18 files changed, 72 insertions(+), 70 deletions(-) diff --git a/src/libs/ball_splash/src/ball_splash.cpp b/src/libs/ball_splash/src/ball_splash.cpp index bed7dc76e..442b68d89 100644 --- a/src/libs/ball_splash/src/ball_splash.cpp +++ b/src/libs/ball_splash/src/ball_splash.cpp @@ -115,7 +115,7 @@ void BALLSPLASH::Realize(uint32_t _dTime) RDTSC_E(ticks); /* - if ((GetKeyState('Z') & 0x8000) != 0) + if ((core.Controls->GetDebugKeyState('Z') & 0x8000) != 0) { renderer->Print(0, 150, "splash: all = %d, count = %d", ticks/1000, TSplash::processCount); if (TSplash::processCount) diff --git a/src/libs/geometry/src/geometry.cpp b/src/libs/geometry/src/geometry.cpp index 925f6a7af..286c7f2f6 100644 --- a/src/libs/geometry/src/geometry.cpp +++ b/src/libs/geometry/src/geometry.cpp @@ -313,7 +313,7 @@ void GEOM_SERVICE_R::SetMaterial(const GEOS::MATERIAL &mt) RenderService->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); RenderService->SetTextureStageState(2, D3DTSS_ALPHAARG1, D3DTA_CURRENT); // block for Sea Dogs: Return Of the legend <-- - /*if(GetAsyncKeyState(0xc0)<0) + /*if(core.Controls->GetDebugAsyncKeyState(0xc0)<0) { //RenderService->TextureSet(0, 0); RenderService->SetTextureStageState(0, D3DSAMP_COLOROPP_MAGFILTER, D3DTEXF_POINT); diff --git a/src/libs/lighter/src/lighter.cpp b/src/libs/lighter/src/lighter.cpp index e995db7e5..88f52f2f5 100644 --- a/src/libs/lighter/src/lighter.cpp +++ b/src/libs/lighter/src/lighter.cpp @@ -89,7 +89,7 @@ void Lighter::Execute(uint32_t delta_time) } if (waitChange <= 0.0f) { - if (GetAsyncKeyState(VK_NUMPAD0) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD0) < 0) { waitChange = 0.5f; if (isInited) @@ -166,7 +166,7 @@ void Lighter::PreparingData() void Lighter::Realize(uint32_t delta_time) { - if (GetAsyncKeyState(VK_DECIMAL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_DECIMAL) < 0) { window.isNoPrepared = !isInited; geometry.DrawNormals(rs); diff --git a/src/libs/lighter/src/window.cpp b/src/libs/lighter/src/window.cpp index 97e81eec6..3d20a2750 100644 --- a/src/libs/lighter/src/window.cpp +++ b/src/libs/lighter/src/window.cpp @@ -308,7 +308,7 @@ void Window::Draw(float dltTime) { if (cursy >= y - 50.0f && cursy <= y + 50.0f) { - if (GetAsyncKeyState(VK_LBUTTON) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_LBUTTON) < 0) isSuccessful = 0.0f; } } @@ -324,7 +324,7 @@ void Window::Draw(float dltTime) { if (cursy >= y - 50.0f && cursy <= y + 50.0f) { - if (GetAsyncKeyState(VK_LBUTTON) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_LBUTTON) < 0) isFailed = 0.0f; } } @@ -332,57 +332,58 @@ void Window::Draw(float dltTime) // Drawing the interface if (!isVisible) return; - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) { - if (GetAsyncKeyState(VK_SUBTRACT) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_SUBTRACT) < 0) { x = sw * 0.5f; y = sh * 0.5f; DrawLRect(x - 230.0f, y - 50.0f, x + 230.0f, y + 50.0f, bkgColor, frmColor); Print(textColor, x - 200.0f, x + 200.0f, y - fontHeight * 0.5f, 1.0f, true, ver); } - else if (GetAsyncKeyState(VK_ADD) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_ADD) < 0) { selected = 0; } - else if (GetAsyncKeyState(VK_NUMPAD1) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD1) < 0) { selected = 1; } - else if (GetAsyncKeyState(VK_NUMPAD2) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD2) < 0) { selected = 2; } - else if (GetAsyncKeyState(VK_NUMPAD3) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD3) < 0) { selected = 3; } - else if (GetAsyncKeyState(VK_NUMPAD4) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD4) < 0) { selected = 4; } - else if (GetAsyncKeyState(VK_NUMPAD5) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD5) < 0) { selected = 5; } - else if (GetAsyncKeyState(VK_NUMPAD6) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD6) < 0) { selected = 6; } - else if (GetAsyncKeyState(VK_NUMPAD7) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD7) < 0) { selected = 7; } - else if (GetAsyncKeyState(VK_NUMPAD8) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD8) < 0) { selected = 8; } - else if (GetAsyncKeyState(VK_NUMPAD9) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_NUMPAD9) < 0) { selected = 9; } } - isMouseDown = !isLockCtrl && isSuccessful <= 0.0f && isFailed <= 0.0f && (GetAsyncKeyState(VK_LBUTTON) < 0); + isMouseDown = !isLockCtrl && isSuccessful <= 0.0f && isFailed <= 0.0f && + (core.Controls->GetDebugAsyncKeyState(VK_LBUTTON) < 0); if (!isMouseDown) slidID = -1; if (!isActiveMouseState) @@ -597,7 +598,7 @@ void Window::Draw(float dltTime) cl = 0xff000000; if (isMouseDown) { - if (GetAsyncKeyState(VK_SHIFT) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_SHIFT) < 0) listPos -= 3.0f; else listPos -= 1.0f; @@ -615,7 +616,7 @@ void Window::Draw(float dltTime) cl = 0xff000000; if (isMouseDown) { - if (GetAsyncKeyState(VK_SHIFT) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_SHIFT) < 0) listPos += 3.0f; else listPos += 1.0f; diff --git a/src/libs/location/src/location_camera.cpp b/src/libs/location/src/location_camera.cpp index 43c64d8c1..bfbd92ac6 100644 --- a/src/libs/location/src/location_camera.cpp +++ b/src/libs/location/src/location_camera.cpp @@ -562,7 +562,7 @@ void LocationCamera::ExecuteTopos(float dltTime) // Free flying camera execution void LocationCamera::ExecuteFree(float dltTime) { - if (GetKeyState(VK_NUMLOCK) & 1) + if (core.Controls->GetDebugKeyState(VK_NUMLOCK) & 1) return; const auto pi = 3.14159265359f; diff --git a/src/libs/location/src/player.cpp b/src/libs/location/src/player.cpp index 68b3fe6e8..45592a1d6 100644 --- a/src/libs/location/src/player.cpp +++ b/src/libs/location/src/player.cpp @@ -105,7 +105,7 @@ void Player::Move(float dltTime) } /* - if(GetAsyncKeyState(VK_SPACE) < 0) + if(core.Controls->GetDebugAsyncKeyState(VK_SPACE) < 0) { impulse.y += 5.0f; impulse.y *= 2; diff --git a/src/libs/model/src/model.cpp b/src/libs/model/src/model.cpp index f6d502efb..41b8bd9d7 100644 --- a/src/libs/model/src/model.cpp +++ b/src/libs/model/src/model.cpp @@ -510,8 +510,8 @@ float MODELR::Trace(const CVECTOR &src, const CVECTOR &dst) // hierarchy test if (dist2ray2 > dlmn * root->radius * root->radius) return 2.0f; - // if(GetAsyncKeyState(0xC0)>=0) return 2.0f; - // if(GetAsyncKeyState(VK_SHIFT)<0 && dist2ray2 > dlmn*root->radius*root->radius) return 2.0f; + // if(core.Controls->GetDebugAsyncKeyState(0xC0)>=0) return 2.0f; + // if(core.Controls->GetDebugAsyncKeyState(VK_SHIFT)<0 && dist2ray2 > dlmn*root->radius*root->radius) return 2.0f; // get bones bones = &ani->GetAnimationMatrix(0); diff --git a/src/libs/sailors/src/sailors_editor.cpp b/src/libs/sailors/src/sailors_editor.cpp index 25782acd2..4f2111031 100644 --- a/src/libs/sailors/src/sailors_editor.cpp +++ b/src/libs/sailors/src/sailors_editor.cpp @@ -66,7 +66,7 @@ void SailorsEditor::Execute(uint32_t dltTime) SetCamera(dltTime); menu.OnKeyPress(menu.sailrs->shipWalk[0].sailorsPoints); - if (GetAsyncKeyState(VK_ESCAPE) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_ESCAPE) < 0) ExitProcess(0); }; @@ -103,33 +103,33 @@ void SailorsEditor::SetCamera(uint32_t &dltTime) pos = mtx * cameraPos; float speed = 0; - if (GetAsyncKeyState(VK_LBUTTON) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_LBUTTON) < 0) speed = -0.1f; - if (GetAsyncKeyState(VK_RBUTTON) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_RBUTTON) < 0) speed = 0.1f; cameraPos.y += speed * (dltTime / 10.0f); rs->SetCamera(cameraTo + pos, cameraTo, CVECTOR(0.0f, 1.0f, 0.0f)); - if (GetAsyncKeyState(0x57) < 0) + if (core.Controls->GetDebugAsyncKeyState(0x57) < 0) { cameraTo.x -= sin(cameraAng.y) * dltTime / 50.0f; cameraTo.z -= cos(cameraAng.y) * dltTime / 50.0f; } - if (GetAsyncKeyState(0x53) < 0) + if (core.Controls->GetDebugAsyncKeyState(0x53) < 0) { cameraTo.x += sin(cameraAng.y) * dltTime / 50.0f; cameraTo.z += cos(cameraAng.y) * dltTime / 50.0f; } - if (GetAsyncKeyState(0x41) < 0) + if (core.Controls->GetDebugAsyncKeyState(0x41) < 0) { cameraTo.x += sin(cameraAng.y + PI / 2) * dltTime / 50.0f; cameraTo.z += cos(cameraAng.y + PI / 2) * dltTime / 50.0f; } - if (GetAsyncKeyState(0x44) < 0) + if (core.Controls->GetDebugAsyncKeyState(0x44) < 0) { cameraTo.x -= sin(cameraAng.y + PI / 2) * dltTime / 50.0f; cameraTo.z -= cos(cameraAng.y + PI / 2) * dltTime / 50.0f; diff --git a/src/libs/sailors/src/sailors_menu.cpp b/src/libs/sailors/src/sailors_menu.cpp index 6bf1bdf8f..9934d9862 100644 --- a/src/libs/sailors/src/sailors_menu.cpp +++ b/src/libs/sailors/src/sailors_menu.cpp @@ -551,42 +551,42 @@ void Menu::OnKeyPress(SailorsPoints &sailorsPoints) key = 0; shiftKey = 0; - if (GetAsyncKeyState(VK_UP) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_UP) < 0) key = VK_UP; - else if (GetAsyncKeyState(VK_DOWN) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_DOWN) < 0) key = VK_DOWN; - else if (GetAsyncKeyState(VK_LEFT) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_LEFT) < 0) key = VK_LEFT; - else if (GetAsyncKeyState(VK_RIGHT) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_RIGHT) < 0) key = VK_RIGHT; - else if (GetAsyncKeyState(VK_RETURN) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_RETURN) < 0) key = VK_RETURN; - else if (GetAsyncKeyState(VK_INSERT) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_INSERT) < 0) key = VK_INSERT; - else if (GetAsyncKeyState(VK_DELETE) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_DELETE) < 0) key = VK_DELETE; - else if (GetAsyncKeyState(VK_SPACE) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_SPACE) < 0) key = VK_SPACE; - else if (GetAsyncKeyState(VK_F1) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F1) < 0) key = VK_F1; - else if (GetAsyncKeyState(VK_F2) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F2) < 0) key = VK_F2; - else if (GetAsyncKeyState(VK_F3) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F3) < 0) key = VK_F3; - else if (GetAsyncKeyState(VK_F5) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F5) < 0) key = VK_F5; - else if (GetAsyncKeyState(VK_F6) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F6) < 0) key = VK_F6; - else if (GetAsyncKeyState(VK_F9) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F9) < 0) key = VK_F9; - else if (GetAsyncKeyState(VK_F4) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F4) < 0) key = VK_F4; - else if (GetAsyncKeyState(VK_F10) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F10) < 0) key = VK_F10; - else if (GetAsyncKeyState(VK_F11) < 0) + else if (core.Controls->GetDebugAsyncKeyState(VK_F11) < 0) key = VK_F11; - if (GetAsyncKeyState(VK_LSHIFT) < 0 || GetAsyncKeyState(VK_RSHIFT) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_LSHIFT) < 0 || core.Controls->GetDebugAsyncKeyState(VK_RSHIFT) < 0) shiftKey = 1; else shiftKey = 0; diff --git a/src/libs/sea/src/sea.cpp b/src/libs/sea/src/sea.cpp index bb0d21d29..ed13d3ae7 100644 --- a/src/libs/sea/src/sea.cpp +++ b/src/libs/sea/src/sea.cpp @@ -972,7 +972,7 @@ void SEA::PrepareIndicesForBlock(uint32_t dwBlockIndex) const bool bTestedUp = pB->iY1 == pB2->iY2; const bool bTestedDown = pB->iY2 == pB2->iY1; - // if (!(GetAsyncKeyState('5')<0)) + // if (!(core.Controls->GetDebugAsyncKeyState('5')<0)) if (bTestedUp || bTestedDown) { const int32_t iAddSrc = pB2->iIStart + ((bTestedUp) ? (pB2->iSize0 + 1) * pB2->iSize0 : 0); @@ -1003,7 +1003,7 @@ void SEA::PrepareIndicesForBlock(uint32_t dwBlockIndex) // Test Left & Right const bool bTestedLeft = pB->iX1 == pB2->iX2; const bool bTestedRight = pB->iX2 == pB2->iX1; - // if ((GetAsyncKeyState('6')<0)) + // if ((core.Controls->GetDebugAsyncKeyState('6')<0)) if (bTestedLeft || bTestedRight) { const int32_t iAddSrc = pB2->iIStart + ((bTestedLeft) ? (pB2->iSize0) : 0); diff --git a/src/libs/sea_cameras/src/free_camera.cpp b/src/libs/sea_cameras/src/free_camera.cpp index d7cd79a97..cbb5be17d 100644 --- a/src/libs/sea_cameras/src/free_camera.cpp +++ b/src/libs/sea_cameras/src/free_camera.cpp @@ -87,7 +87,7 @@ void FREE_CAMERA::Move(uint32_t DeltaTime) { if (!isActive()) return; - if (GetKeyState(VK_NUMLOCK) & 1) + if (core.Controls->GetDebugKeyState(VK_NUMLOCK) & 1) return; // POINT pnt; @@ -115,9 +115,9 @@ void FREE_CAMERA::Move(uint32_t DeltaTime) float s2 = sinf(vAng.z); float speed = 5.0f * 0.001f * static_cast(DeltaTime); - if (GetAsyncKeyState(VK_SHIFT)) + if (core.Controls->GetDebugAsyncKeyState(VK_SHIFT)) speed *= 4.0f; - if (GetAsyncKeyState(VK_CONTROL)) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL)) speed *= 8.0f; core.Controls->GetControlState("FreeCamera_Forward", cs); @@ -127,10 +127,10 @@ void FREE_CAMERA::Move(uint32_t DeltaTime) if (cs.state == CST_ACTIVE) vPos -= speed * CVECTOR(s0 * c1, -s1, c0 * c1); - /*if (GetAsyncKeyState(VK_LBUTTON)) vPos += speed*CVECTOR(s0*c1, -s1, c0*c1); - if (GetAsyncKeyState(VK_RBUTTON)) vPos -= speed*CVECTOR(s0*c1, -s1, c0*c1); - if(GetAsyncKeyState('I')) vPos += speed*CVECTOR(0.0f, 0.1f , 0.0f); - if(GetAsyncKeyState('K')) vPos += speed*CVECTOR(0.0f, -0.1f, 0.0f);*/ + /*if (core.Controls->GetDebugAsyncKeyState(VK_LBUTTON)) vPos += speed*CVECTOR(s0*c1, -s1, c0*c1); + if (core.Controls->GetDebugAsyncKeyState(VK_RBUTTON)) vPos -= speed*CVECTOR(s0*c1, -s1, c0*c1); + if(core.Controls->GetDebugAsyncKeyState('I')) vPos += speed*CVECTOR(0.0f, 0.1f , 0.0f); + if(core.Controls->GetDebugAsyncKeyState('K')) vPos += speed*CVECTOR(0.0f, -0.1f, 0.0f);*/ // vPos = CVECTOR(0.0f, 20.0f, 0.0f); diff --git a/src/libs/sea_creatures/src/sharks.cpp b/src/libs/sea_creatures/src/sharks.cpp index a3c0ea507..c39168de2 100644 --- a/src/libs/sea_creatures/src/sharks.cpp +++ b/src/libs/sea_creatures/src/sharks.cpp @@ -352,9 +352,9 @@ inline void Sharks::Shark::Coordination(float cam_x, float cam_z, float dltTime, // Matrix update mdl->mtx.BuildMatrix(angs, rpos); /* - if(GetAsyncKeyState('Z') >= 0) + if(core.Controls->GetDebugAsyncKeyState('Z') >= 0) { - if(GetAsyncKeyState('X') < 0) rpos.y += 30.0f; + if(core.Controls->GetDebugAsyncKeyState('X') < 0) rpos.y += 30.0f; mdl->mtx.BuildMatrix(angs, rpos); }else{ mdl->mtx.BuildMatrix(angs, pos + CVECTOR(0.0f, 30.0f, 0.0f)); diff --git a/src/libs/shadow/src/shadow.cpp b/src/libs/shadow/src/shadow.cpp index 62c5c9fbd..182505cb1 100644 --- a/src/libs/shadow/src/shadow.cpp +++ b/src/libs/shadow/src/shadow.cpp @@ -242,7 +242,7 @@ void Shadow::Realize(uint32_t Delta_Time) shading = std::max(0.2f, std::max(minVal, std::min(shading, 1.0f))); shading *= (blendValue >> 24) / 255.0f; - // if(GetAsyncKeyState(0xc0)<0) + // if(core.Controls->GetDebugAsyncKeyState(0xc0)<0) { float dist = sqrtf(~(cen - camPos)); if (dist > farBlend) // too far diff --git a/src/libs/sink_effect/src/sink_effect.cpp b/src/libs/sink_effect/src/sink_effect.cpp index d73fb1224..529dc7f1e 100644 --- a/src/libs/sink_effect/src/sink_effect.cpp +++ b/src/libs/sink_effect/src/sink_effect.cpp @@ -91,7 +91,7 @@ void SINKEFFECT::Execute(uint32_t _dTime) { // GUARD(SINKEFFECT::Execute) /* - if (GetAsyncKeyState('X')) + if (core.Controls->GetDebugAsyncKeyState('X')) { if (renderer && sea) { diff --git a/src/libs/touch/src/touch.cpp b/src/libs/touch/src/touch.cpp index 91a72ee83..6cb6f303f 100644 --- a/src/libs/touch/src/touch.cpp +++ b/src/libs/touch/src/touch.cpp @@ -116,8 +116,8 @@ void TOUCH::Execute(uint32_t dwCoreDeltaTime) FakeTouch(); // just push out the ships that are still in each other - // if (GetAsyncKeyState('5')) fScale -= 0.1f; - // if (GetAsyncKeyState('6')) fScale += 0.1f; + // if (core.Controls->GetDebugAsyncKeyState('5')) fScale -= 0.1f; + // if (core.Controls->GetDebugAsyncKeyState('6')) fScale += 0.1f; RDTSC_E(dwRdtsc); } diff --git a/src/libs/worldmap/src/wdm_cloud.cpp b/src/libs/worldmap/src/wdm_cloud.cpp index a1a1e9b45..24b253531 100644 --- a/src/libs/worldmap/src/wdm_cloud.cpp +++ b/src/libs/worldmap/src/wdm_cloud.cpp @@ -11,6 +11,7 @@ #include "wdm_cloud.h" #include "wdm_objects.h" #include "defines.h" +#include "core.h" #define WdmStormCloudHeight 40.0f #define WdmStormSizeMin 40.0f @@ -63,7 +64,7 @@ void WdmCloud::Update(float dltTime) if (dltTime > 1.0f) dltTime = 1.0f; - if (GetKeyState(VK_NUMLOCK) != 0) + if (core.Controls->GetDebugKeyState(VK_NUMLOCK) != 0) { dltTime = 0.0f; } diff --git a/src/libs/xinterface/src/nodes/xi_util.cpp b/src/libs/xinterface/src/nodes/xi_util.cpp index 5526e708f..9e3f394d3 100644 --- a/src/libs/xinterface/src/nodes/xi_util.cpp +++ b/src/libs/xinterface/src/nodes/xi_util.cpp @@ -59,7 +59,7 @@ char CXI_UTILS::GetKeyInput() if (pThis->keys[n].nAsyncKeyCode < 0) continue; - if (GetAsyncKeyState(pThis->keys[n].nAsyncKeyCode) < 0) + if (core.Controls->GetDebugAsyncKeyState(pThis->keys[n].nAsyncKeyCode) < 0) { pThis->m_bIsKeyPressed = true; diff --git a/src/libs/xinterface/src/string_service/str_service.cpp b/src/libs/xinterface/src/string_service/str_service.cpp index 255992def..4c6990e30 100644 --- a/src/libs/xinterface/src/string_service/str_service.cpp +++ b/src/libs/xinterface/src/string_service/str_service.cpp @@ -1482,15 +1482,15 @@ uint32_t _IsKeyPressed(VS_STACK *pS) { if (storm::iEquals(strKeyName, "shift")) { - bIsPressed = (GetAsyncKeyState(VK_SHIFT) < 0); + bIsPressed = (core.Controls->GetDebugAsyncKeyState(VK_SHIFT) < 0); } else if (storm::iEquals(strKeyName, "control")) { - bIsPressed = (GetAsyncKeyState(VK_CONTROL) < 0); + bIsPressed = (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0); } else if (storm::iEquals(strKeyName, "alt")) { - bIsPressed = (GetAsyncKeyState(VK_MENU) < 0); + bIsPressed = (core.Controls->GetDebugAsyncKeyState(VK_MENU) < 0); } } // set return data From 723113b69f9d71e78e3ecea96504ac706326ff59 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 09:06:10 +0300 Subject: [PATCH 18/59] [linux] replace GetAsyncKeyState with core functions part 2 --- src/apps/engine/src/s_dbg_sourceview.cpp | 13 +++++++------ src/apps/engine/src/tm_list.cpp | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/apps/engine/src/s_dbg_sourceview.cpp b/src/apps/engine/src/s_dbg_sourceview.cpp index 0652d26c3..6a4f08678 100644 --- a/src/apps/engine/src/s_dbg_sourceview.cpp +++ b/src/apps/engine/src/s_dbg_sourceview.cpp @@ -63,30 +63,31 @@ LRESULT CALLBACK SourceViewWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM l switch (static_cast(wParam)) { case VK_HOME: - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) CDebug->SourceView->SetActiveLine(0); break; case VK_END: - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) CDebug->SourceView->SetActiveLine(CDebug->SourceView->nLinesNum - 1); break; case 'G': break; case 'F': - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) CDebug->SourceView->FindModal(); break; case 'O': - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) CDebug->OpenNewFile(); break; case VK_F2: - if (GetAsyncKeyState(VK_CONTROL) < 0 && GetAsyncKeyState(VK_SHIFT) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0 && + core.Controls->GetDebugAsyncKeyState(VK_SHIFT) < 0) { CDebug->SourceView->ClearAllBookmarks(); break; } - if (GetAsyncKeyState(VK_CONTROL) < 0) + if (core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) { CDebug->SourceView->ToogleBookmark(); break; diff --git a/src/apps/engine/src/tm_list.cpp b/src/apps/engine/src/tm_list.cpp index 4654f344d..e0b3baa1e 100644 --- a/src/apps/engine/src/tm_list.cpp +++ b/src/apps/engine/src/tm_list.cpp @@ -321,7 +321,7 @@ void TM_LIST::ProcessMessageBase(uint64_t iMsg, uint64_t wParam, uint64_t lParam vKey = ((LPNMLVKEYDOWN)lParam)->wVKey; if (vKey == VK_F4) StartEditSelectedItem(); - if (vKey == 'O' && GetAsyncKeyState(VK_CONTROL) < 0) + if (vKey == 'O' && core.Controls->GetDebugAsyncKeyState(VK_CONTROL) < 0) CDebug->OpenNewFile(); if (vKey == VK_F10) { From 7a33d698da312a631c6836ea9490dfd8659a3938 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 09:31:07 +0300 Subject: [PATCH 19/59] [linux] FIX_LINUX ExitProcess --- src/libs/sailors/src/sailors_editor.cpp | 4 ++++ src/libs/sea/src/sea.h | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/libs/sailors/src/sailors_editor.cpp b/src/libs/sailors/src/sailors_editor.cpp index 4f2111031..71fec107f 100644 --- a/src/libs/sailors/src/sailors_editor.cpp +++ b/src/libs/sailors/src/sailors_editor.cpp @@ -67,7 +67,11 @@ void SailorsEditor::Execute(uint32_t dltTime) menu.OnKeyPress(menu.sailrs->shipWalk[0].sailorsPoints); if (core.Controls->GetDebugAsyncKeyState(VK_ESCAPE) < 0) +#ifdef _WIN32 // FIX_LINUX ExitProcess ExitProcess(0); +#else + exit(0); +#endif }; void SailorsEditor::Realize(uint32_t dltTime) diff --git a/src/libs/sea/src/sea.h b/src/libs/sea/src/sea.h index 7b8b9928f..7ab2a754a 100644 --- a/src/libs/sea/src/sea.h +++ b/src/libs/sea/src/sea.h @@ -39,6 +39,26 @@ class SEA : public SEA_BASE bool bInProgress, bDone; + SeaBlock(int32_t iX1, int32_t iX2, int32_t iY1, int32_t iY2, int32_t iSize0, int32_t iTX, int32_t iTY, + int32_t iSize, int32_t iLOD, int32_t iIStart, int32_t iIFirst, int32_t iILast, bool bInProgress, + bool bDone) + { + this->iX1 = iX1; + this->iX2 = iX2; + this->iY1 = iY1; + this->iY2 = iY2; + this->iSize0 = iSize0; + this->iTX = iTX; + this->iTY = iTY; + this->iSize = iSize; + this->iLOD = iLOD; + this->iIStart = iIStart; + this->iIFirst = iIFirst; + this->iILast = iILast; + this->bInProgress = bInProgress; + this->bDone = bDone; + } + static bool QSort(const SeaBlock &b1, const SeaBlock &b2) { return (b1.iLOD > b2.iLOD); From fb23a36c89a65ae64f07a026685d4a62caa8180e Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 09:35:48 +0300 Subject: [PATCH 20/59] [linux] FIX_LINUX RDTSC_* --- src/libs/common/include/defines.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/common/include/defines.h b/src/libs/common/include/defines.h index fc6a20e0d..29883bd2e 100644 --- a/src/libs/common/include/defines.h +++ b/src/libs/common/include/defines.h @@ -75,6 +75,7 @@ constexpr float PIm2 = (PI * 2.0f); constexpr float PId2 = (PI / 2.0f); constexpr float PId4 = (PI / 4.0f); +#ifdef _WIN32 // FIX_LINUX RDTSC_* #define RDTSC_B(x) \ { \ LARGE_INTEGER li; \ @@ -87,9 +88,10 @@ constexpr float PId4 = (PI / 4.0f); QueryPerformanceCounter(&li); \ x = li.QuadPart - x; \ } - -//#define RDTSC_B(x) { x = __rdtsc(); } -//#define RDTSC_E(x) { x = __rdtsc() - x; } +#else +#define RDTSC_B(x) { x = __rdtsc(); } +#define RDTSC_E(x) { x = __rdtsc() - x; } +#endif // Defines #ifdef RGB From 64c0348280c58474b240696071d5cb42c9c53847 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 10:08:08 +0300 Subject: [PATCH 21/59] [linux] FIX_LINUX Screenshot, HBITMAP, ReleaseDC, D3DXCreateTextureFromFileA FIX_LINUX D3DXLoadSurfaceFromSurface, D3DXCreateTextureFromFileInMemoryEx --- src/libs/renderer/src/s_device.cpp | 30 ++++++++++++++++++++++++------ src/libs/renderer/src/s_device.h | 3 +++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 9f04d20d9..c1f7b029e 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -35,6 +35,7 @@ namespace { constexpr auto kKeyTakeScreenshot = "TakeScreenshot"; +#ifdef _WIN32 // FIX_LINUX Screenshot D3DXIMAGE_FILEFORMAT GetScreenshotFormat(const std::string &fmt) { if (fmt == "bmp") @@ -76,6 +77,7 @@ namespace return D3DXIFF_FORCE_DWORD; } +#endif void InvokeEntitiesLostRender() { @@ -510,12 +512,14 @@ bool DX9RENDER::Init() screenshotExt = str; std::ranges::transform(screenshotExt, screenshotExt.begin(), [](const unsigned char c) { return std::tolower(c); }); +#ifdef _WIN32 // FIX_LINUX Screenshot screenshotFormat = GetScreenshotFormat(str); if (screenshotFormat == D3DXIFF_FORCE_DWORD) { screenshotExt = "jpg"; screenshotFormat = D3DXIFF_JPG; } +#endif bShowFps = ini->GetInt(nullptr, "show_fps", 0) == 1; bShowExInfo = ini->GetInt(nullptr, "show_exinfo", 0) == 1; @@ -710,12 +714,10 @@ DX9RENDER::~DX9RENDER() if (bPreparedCapture) { -#ifndef _WIN32 // FIX_LINUX HBITMAP +#ifdef _WIN32 // FIX_LINUX HBITMAP // FIX_LINUX ReleaseDC STORM_DELETE(lpbi); -#endif ReleaseDC(static_cast(core.GetAppHWND()), hDesktopDC); DeleteDC(hCaptureDC); -#ifndef _WIN32 // FIX_LINUX HBITMAP DeleteObject(hCaptureBitmap); #endif } @@ -1317,9 +1319,11 @@ bool DX9RENDER::DX9EndScene() if (bSafeRendering) { +#ifdef _WIN32 // FIX_LINUX ReleaseDC const HDC dc = GetDC(hwnd); SetPixel(dc, 0, 0, 0); ReleaseDC(hwnd, dc); +#endif } return true; @@ -1823,6 +1827,7 @@ bool DX9RENDER::TextureLoad(int32_t t) bool DX9RENDER::TextureLoadUsingD3DX(const char* path, int32_t t) { +#ifdef _WIN32 // FIX_LINUX D3DXCreateTextureFromFileA // TODO: reimplement the whole thing in a tidy way IDirect3DTexture9 *pTex; if(CHECKD3DERR(D3DXCreateTextureFromFileA(d3d9, path, &pTex))) @@ -1843,6 +1848,9 @@ bool DX9RENDER::TextureLoadUsingD3DX(const char* path, int32_t t) Textures[t].loaded = true; return true; +#else + return false; +#endif } IDirect3DBaseTexture9 *DX9RENDER::GetBaseTexture(int32_t iTexture) @@ -3313,7 +3321,11 @@ void DX9RENDER::MakeScreenShot() return; } +#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface if (CHECKD3DERR(D3DXLoadSurfaceFromSurface(surface, NULL, NULL, renderTarget, NULL, NULL, D3DX_DEFAULT, 0))) +#else + if (FAILED(d3d9->UpdateSurface(renderTarget, nullptr, surface, nullptr))) +#endif { surface->Release(); renderTarget->Release(); @@ -3329,7 +3341,9 @@ void DX9RENDER::MakeScreenShot() screenshot_path.replace_filename(screenshot_base_filename + "_" + std::to_string(i)); screenshot_path.replace_extension(screenshotExt); } +#ifdef _WIN32 // FIX_LINUX Screenshot D3DXSaveSurfaceToFile(screenshot_path.c_str(), screenshotFormat, surface, nullptr, nullptr); +#endif surface->Release(); renderTarget->Release(); @@ -3824,10 +3838,12 @@ HRESULT DX9RENDER::GetSurfaceLevel(IDirect3DTexture9 *ppTexture, UINT Level, IDi HRESULT DX9RENDER::UpdateSurface(IDirect3DSurface9 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface9 *pDestinationSurface, CONST POINT *pDestPointsArray) { +#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface return CHECKD3DERR(D3DXLoadSurfaceFromSurface(pDestinationSurface, nullptr, nullptr, pSourceSurface, nullptr, - nullptr, - D3DX_DEFAULT, 0)); - //return CHECKD3DERR(d3d9->UpdateSurface(pSourceSurface, pSourceRectsArray, pDestinationSurface, pDestPointsArray)); + nullptr, D3DX_DEFAULT, 0)); +#else + return CHECKD3DERR(d3d9->UpdateSurface(pSourceSurface, pSourceRectsArray, pDestinationSurface, pDestPointsArray)); +#endif } HRESULT DX9RENDER::StretchRect(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect, @@ -4502,9 +4518,11 @@ IDirect3DBaseTexture9 *DX9RENDER::CreateTextureFromFileInMemory(const char *pFil IDirect3DTexture9 *pTexture = nullptr; auto *pTga = (TGA_H *)pFile; const D3DFORMAT d3dFormat = (pTga->bpp == 16) ? D3DFMT_DXT1 : D3DFMT_DXT3; +#ifdef _WIN32 // FIX_LINUX D3DXCreateTextureFromFileInMemoryEx D3DXCreateTextureFromFileInMemoryEx(static_cast(GetD3DDevice()), pFile, dwSize, D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, d3dFormat, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, nullptr, nullptr, &pTexture); +#endif return pTexture; } diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index 044059953..fdfcf5298 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -6,6 +6,7 @@ #include "defines.h" #include "dx9render.h" #include "v_module_api.h" +#include "storm_platform.h" #include "d3d9types.h" #include "script_libriary.h" @@ -597,7 +598,9 @@ class DX9RENDER : public VDX9RENDER std::stack stRenderTarget; +#ifdef _WIN32 // FIX_LINUX Screenshot D3DXIMAGE_FILEFORMAT screenshotFormat; +#endif std::string screenshotExt; bool TextureLoad(int32_t texid); From 8c10c751bb3b7ebd1b67034a78ac8861be82e0ed Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 10:09:35 +0300 Subject: [PATCH 22/59] [linux] FIX_LINUX ID3DXEffect part 2 --- src/libs/renderer/src/effects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/renderer/src/effects.cpp b/src/libs/renderer/src/effects.cpp index f59373d7d..2c2219417 100644 --- a/src/libs/renderer/src/effects.cpp +++ b/src/libs/renderer/src/effects.cpp @@ -89,8 +89,8 @@ void Effects::release() #ifdef _WIN32 // FIX_LINUX ID3DXEffect for (auto *fx : effects_) fx->Release(); -#endif effects_.clear(); +#endif techniques_.clear(); currentTechnique_ = nullptr; } From 5496a79299c2f80e25e3c65c7ac585b7176575c0 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 10:29:21 +0300 Subject: [PATCH 23/59] [linux] replace MSVC _strupr and _strlwr with custom toupr and tolwr --- src/apps/engine/src/token.cpp | 2 +- src/libs/common/include/defines.h | 19 +++++++++++++++++++ src/libs/renderer/src/s_device.cpp | 11 +++++++---- src/libs/ship/src/ship_lights.cpp | 2 +- src/libs/weather/src/stars.cpp | 4 ++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/apps/engine/src/token.cpp b/src/apps/engine/src/token.cpp index f1708f225..df9ebf387 100644 --- a/src/apps/engine/src/token.cpp +++ b/src/apps/engine/src/token.cpp @@ -366,7 +366,7 @@ void TOKEN::LowCase() { if (pTokenData[0] == 0) return; - _strlwr(pTokenData); + tolwr(pTokenData); } const char *TOKEN::GetData() diff --git a/src/libs/common/include/defines.h b/src/libs/common/include/defines.h index 29883bd2e..fb84cde42 100644 --- a/src/libs/common/include/defines.h +++ b/src/libs/common/include/defines.h @@ -4,6 +4,7 @@ #include "math3d.h" #include #include +#include namespace TOREMOVE { @@ -75,6 +76,24 @@ constexpr float PIm2 = (PI * 2.0f); constexpr float PId2 = (PI / 2.0f); constexpr float PId4 = (PI / 4.0f); +inline void toupr(char *str) +{ + while (*str != '\0') + { + *str = toupper(*str); + str++; + } +} + +inline void tolwr(char *str) +{ + while (*str != '\0') + { + *str = tolower(*str); + str++; + } +} + #ifdef _WIN32 // FIX_LINUX RDTSC_* #define RDTSC_B(x) \ { \ diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index c1f7b029e..0c1edfda2 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -1418,7 +1418,7 @@ int32_t DX9RENDER::TextureCreate(const char *fname) _fname[strlen(_fname) - 3] = 0; } - _strupr(_fname); + toupr(_fname); const uint32_t hf = hash_string(_fname); @@ -2997,7 +2997,8 @@ int32_t DX9RENDER::LoadFont(const char *fontName) strncpy_s(sDup, fontName, sizeof(sDup) - 1); sDup[sizeof(sDup) - 1] = 0; } - fontName = _strupr(sDup); + toupr(sDup); + fontName = sDup; const uint32_t hashVal = hash_string(fontName); int32_t i; @@ -3048,7 +3049,8 @@ bool DX9RENDER::UnloadFont(const char *fontName) strncpy_s(sDup, fontName, sizeof(sDup) - 1); sDup[sizeof(sDup) - 1] = 0; } - fontName = _strupr(sDup); + toupr(sDup); + fontName = sDup; const uint32_t hashVal = hash_string(fontName); for (int i = 0; i < nFontQuantity; i++) @@ -3101,7 +3103,8 @@ bool DX9RENDER::SetCurFont(const char *fontName) strncpy_s(sDup, fontName, sizeof(sDup) - 1); sDup[sizeof(sDup) - 1] = 0; } - fontName = _strupr(sDup); + toupr(sDup); + fontName = sDup; const uint32_t hashVal = hash_string(fontName); for (int i = 0; i < nFontQuantity; i++) diff --git a/src/libs/ship/src/ship_lights.cpp b/src/libs/ship/src/ship_lights.cpp index 8b266d990..7e49cc126 100644 --- a/src/libs/ship/src/ship_lights.cpp +++ b/src/libs/ship/src/ship_lights.cpp @@ -182,7 +182,7 @@ void ShipLights::AddFlare(VAI_OBJBASE *pObject, bool bLight, MODEL *pModel, cons if (!label.name) return; strcpy_s(str, label.name); - _strlwr(str); + tolwr(str); aLights.push_back(ShipLight{}); ShipLight *pL = &aLights.back(); diff --git a/src/libs/weather/src/stars.cpp b/src/libs/weather/src/stars.cpp index af29aa298..6e5ddf555 100644 --- a/src/libs/weather/src/stars.cpp +++ b/src/libs/weather/src/stars.cpp @@ -72,9 +72,9 @@ void Astronomy::STARS::Init(ATTRIBUTES *pAP) char str[2]; str[0] = pAS->GetThisName()[0]; str[1] = 0; - _strupr(str); + toupr(str); Spectr[str[0]] = pAS->GetAttributeAsDword(); - _strlwr(str); + tolwr(str); Spectr[str[0]] = pAS->GetAttributeAsDword(); } } From f57eee0bd69be47098fe1c2921906aaafc2b0b74 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 10:46:02 +0300 Subject: [PATCH 24/59] [linux] FIX_LINUX ddraw.h and amstream.h --- .../xinterface/src/aviplayer/aviplayer.cpp | 18 ++++++++++++++++++ src/libs/xinterface/src/aviplayer/aviplayer.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/libs/xinterface/src/aviplayer/aviplayer.cpp b/src/libs/xinterface/src/aviplayer/aviplayer.cpp index a68801a3a..4926a4987 100644 --- a/src/libs/xinterface/src/aviplayer/aviplayer.cpp +++ b/src/libs/xinterface/src/aviplayer/aviplayer.cpp @@ -29,6 +29,7 @@ CAviPlayer::CAviPlayer() m_bContinue = true; m_bShowVideo = true; +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h pDD = nullptr; pPrimarySurface = nullptr; pVideoSurface = nullptr; @@ -36,6 +37,7 @@ CAviPlayer::CAviPlayer() pPrimaryVidStream = nullptr; pDDStream = nullptr; pSample = nullptr; +#endif pTmpRenderTarget = nullptr; pTex = nullptr; @@ -76,8 +78,10 @@ void CAviPlayer::Execute(uint32_t delta_time) { if (m_bContinue == false) { +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h if (pAMStream != nullptr) pAMStream->SetState(STREAMSTATE_STOP); +#endif CleanupInterfaces(); core.Event("ievntEndVideo"); } @@ -87,6 +91,7 @@ void CAviPlayer::Realize(uint32_t delta_time) { //~!~ // rs->BeginScene(); +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h int i; HRESULT hr; DDSURFACEDESC ddsd; @@ -147,6 +152,9 @@ void CAviPlayer::Realize(uint32_t delta_time) { m_bContinue = false; } +#else + m_bContinue = false; +#endif } uint64_t CAviPlayer::ProcessMessage(MESSAGE &message) @@ -176,6 +184,7 @@ uint64_t CAviPlayer::ProcessMessage(MESSAGE &message) bool CAviPlayer::PlayMedia(const char *fileName) { +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h auto hr = S_OK; DDSURFACEDESC ddsd; @@ -297,12 +306,16 @@ bool CAviPlayer::PlayMedia(const char *fileName) } return true; +#else + return false; +#endif } bool CAviPlayer::GetInterfaces() { HRESULT hr = S_OK; +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h // Initialize COM if (FAILED(hr = CoInitialize(NULL))) return false; @@ -348,10 +361,14 @@ bool CAviPlayer::GetInterfaces() } return true; +#else + return false; +#endif } void CAviPlayer::CleanupInterfaces() { +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h IRELEASE(pSample); IRELEASE(pDDStream); IRELEASE(pPrimaryVidStream); @@ -369,6 +386,7 @@ void CAviPlayer::CleanupInterfaces() if (m_bMakeUninitializeDD) CoUninitialize(); +#endif m_bMakeUninitializeDD = false; } diff --git a/src/libs/xinterface/src/aviplayer/aviplayer.h b/src/libs/xinterface/src/aviplayer/aviplayer.h index 2703dfa3d..ed740e8d3 100644 --- a/src/libs/xinterface/src/aviplayer/aviplayer.h +++ b/src/libs/xinterface/src/aviplayer/aviplayer.h @@ -1,8 +1,10 @@ #pragma once #include "../base_video.h" +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h #include #include +#endif #define XI_AVIVIDEO_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2) @@ -56,6 +58,7 @@ class CAviPlayer : public xiBaseVideo protected: bool m_bContinue; +#ifdef _WIN32 // FIX_LINUX ddraw.h and amstream.h IDirectDraw *pDD; IDirectDrawSurface *pPrimarySurface; IDirectDrawSurface *pVideoSurface; @@ -64,6 +67,7 @@ class CAviPlayer : public xiBaseVideo IMediaStream *pPrimaryVidStream; IDirectDrawMediaStream *pDDStream; IDirectDrawStreamSample *pSample; +#endif POINT dstPnt; RECT lockRect; From d3de3f5571b05431dd67efcbd249f312b32dc485 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 13:48:57 +0300 Subject: [PATCH 25/59] replace GetLocalTime with std::localtime --- src/apps/engine/src/core_impl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apps/engine/src/core_impl.cpp b/src/apps/engine/src/core_impl.cpp index 93576a294..d08aa14b6 100644 --- a/src/apps/engine/src/core_impl.cpp +++ b/src/apps/engine/src/core_impl.cpp @@ -137,19 +137,19 @@ bool CoreImpl::Run() if (pVCTime) pVCTime->Set(static_cast(GetRDeltaTime())); - SYSTEMTIME st; - GetLocalTime(&st); + auto tt = std::time(nullptr); + auto local_tm = *std::localtime(&tt); auto *pVYear = static_cast(core_internal.GetScriptVariable("iRealYear")); auto *pVMonth = static_cast(core_internal.GetScriptVariable("iRealMonth")); auto *pVDay = static_cast(core_internal.GetScriptVariable("iRealDay")); if (pVYear) - pVYear->Set(static_cast(st.wYear)); + pVYear->Set(local_tm.tm_year + 1900); if (pVMonth) - pVMonth->Set(static_cast(st.wMonth)); + pVMonth->Set(local_tm.tm_mon + 1); // tm_mon belongs [0, 11] if (pVDay) - pVDay->Set(static_cast(st.wDay)); + pVDay->Set(local_tm.tm_mday); if (Controls && Controls->GetDebugAsyncKeyState('R') < 0) Timer.Delta_Time *= 10; From 816cd9d7c79850d84cdf9ffd97a5555f62ee83b1 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 16:53:48 +0300 Subject: [PATCH 26/59] [linux] FIX_LINUX s_debug.h part 2 --- src/apps/engine/src/compiler.cpp | 2 +- src/apps/engine/src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index 19eb548fc..3cdecab53 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -8,7 +8,7 @@ #ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_debug.h" #else -#include "core.h" +#include "core_impl.h" #endif #include "logging.hpp" #include "script_cache.h" diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index dc4604047..5038c2818 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -15,7 +15,7 @@ #ifdef _WIN32 // FIX_LINUX s_debug.h #include "s_debug.h" #else -#include "core.h" +#include "core_impl.h" #endif #include "v_sound_service.h" #include "storm/fs.h" From 66c258617b6d2f663fa7b35e2757c178e084768a Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 16:55:49 +0300 Subject: [PATCH 27/59] replace _strdup with strdup --- src/apps/engine/src/compiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index 3cdecab53..d4ab67725 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -830,7 +830,7 @@ bool COMPILER::BC_LoadSegment(const char *file_name) // const auto len = strlen(file_name) + 1; // SegmentTable[index].name = new char[len]; // memcpy(SegmentTable[index].name, file_name, len); - SegmentTable[index].name = _strdup(file_name); + SegmentTable[index].name = strdup(file_name); SegmentTable[index].id = id; SegmentTable[index].bUnload = false; SegmentTable[index].pData = nullptr; From dc316a5dc16577701ab3b910ebb754e4a49c397e Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:01:00 +0300 Subject: [PATCH 28/59] replace _splitpath with std::filesystem::path --- src/apps/engine/src/compiler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index d4ab67725..8b2f89b11 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -1909,7 +1909,8 @@ bool COMPILER::Compile(SEGMENT_DESC &Segment, char *pInternalCode, uint32_t pInt uint32_t dwR; if (bWriteCodeFile) { - _splitpath(Segment.name.c_str(), nullptr, nullptr, file_name, nullptr); + auto fName = std::filesystem::path(Segment.name.c_str()).filename().string(); + strcpy_s(file_name, fName.c_str()); strcat_s(file_name, ".b"); std::wstring FileNameW = utf8::ConvertUtf8ToWide(file_name); auto fileS = fio->_CreateFile(file_name, std::ios::binary | std::ios::out); From b541af07243e052aa637aea9bee1c00b7fd4240c Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:02:48 +0300 Subject: [PATCH 29/59] replace __try + __except with try + catch --- src/apps/engine/src/compiler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index 8b2f89b11..551c0de87 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -6468,11 +6468,11 @@ void COMPILER::SaveVariable(DATA *pV, bool bdim) break; case VAR_AREFERENCE: pString = nullptr; - __try + try { pA = TraceARoot(pV->AttributesClass, pString); } - __except (EXCEPTION_EXECUTE_HANDLER) + catch (...) { SetError("Save - ARef to non existing attributes branch"); WriteVDword(0xffffffff); From bb8d69e07de6a630ea4e8364eb450e226a61c328 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:15:39 +0300 Subject: [PATCH 30/59] [linux] FIX_LINUX Cursor --- src/apps/engine/src/core_impl.cpp | 2 ++ src/apps/engine/src/main.cpp | 2 ++ src/libs/xinterface/src/xinterface.cpp | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/apps/engine/src/core_impl.cpp b/src/apps/engine/src/core_impl.cpp index d08aa14b6..01c2d2751 100644 --- a/src/apps/engine/src/core_impl.cpp +++ b/src/apps/engine/src/core_impl.cpp @@ -287,8 +287,10 @@ void CoreImpl::ProcessEngineIniFile() if (iScriptVersion != ENGINE_SCRIPT_VERSION) { +#ifdef _WIN32 // FIX_LINUX Cursor ShowCursor(true); MessageBoxA(nullptr, "Wrong script version", "Error", MB_OK); +#endif Compiler->ExitProgram(); } } diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index 5038c2818..01da1a20c 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -269,7 +269,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, core_internal.Event("ExitApplication", nullptr); core_internal.CleanUp(); core_internal.ReleaseBase(); +#ifdef _WIN32 // FIX_LINUX Cursor ClipCursor(nullptr); +#endif SDL_Quit(); return EXIT_SUCCESS; diff --git a/src/libs/xinterface/src/xinterface.cpp b/src/libs/xinterface/src/xinterface.cpp index 303b5a272..19ac6e255 100644 --- a/src/libs/xinterface/src/xinterface.cpp +++ b/src/libs/xinterface/src/xinterface.cpp @@ -1133,9 +1133,11 @@ void XINTERFACE::LoadIni() m_idTex = pRenderService->TextureCreate(param2); // RECT Screen_Rect; // GetWindowRect(core.GetAppHWND(), &Screen_Rect); +#ifdef _WIN32 // FIX_LINUX Cursor lock_x = Screen_Rect.left + (Screen_Rect.right - Screen_Rect.left) / 2; lock_y = Screen_Rect.top + (Screen_Rect.bottom - Screen_Rect.top) / 2; SetCursorPos(lock_x, lock_y); +#endif fXMousePos = static_cast(dwScreenWidth / 2); fYMousePos = static_cast(dwScreenHeight / 2); for (int i = 0; i < 4; i++) @@ -1144,7 +1146,9 @@ void XINTERFACE::LoadIni() vMouse[2].tu = vMouse[3].tu = 1.f; vMouse[0].tv = vMouse[2].tv = 0.f; vMouse[1].tv = vMouse[3].tv = 1.f; +#ifdef _WIN32 // FIX_LINUX Cursor ShowCursor(false); +#endif // set blind parameters m_fBlindSpeed = ini->GetFloat(section, "BlindTime", 1.f); From 38024909474d43a5d42a7e09ed890a0f3fb5e2b2 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:20:52 +0300 Subject: [PATCH 31/59] [linux] FIX_LINUX HINSTANCE --- src/apps/engine/src/core_impl.cpp | 2 ++ src/apps/engine/src/core_impl.h | 4 ++++ src/apps/engine/src/main.cpp | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/apps/engine/src/core_impl.cpp b/src/apps/engine/src/core_impl.cpp index 01c2d2751..0101514cc 100644 --- a/src/apps/engine/src/core_impl.cpp +++ b/src/apps/engine/src/core_impl.cpp @@ -326,10 +326,12 @@ void* CoreImpl::GetAppHWND() return App_Hwnd; } +#ifdef _WIN32 // FIX_LINUX HINSTANCE HINSTANCE CoreImpl::GetAppInstance() { return hInstance; } +#endif void CoreImpl::SetTimeScale(float _scale) { diff --git a/src/apps/engine/src/core_impl.h b/src/apps/engine/src/core_impl.h index 55ba82481..63db3690e 100644 --- a/src/apps/engine/src/core_impl.h +++ b/src/apps/engine/src/core_impl.h @@ -62,7 +62,9 @@ class CoreImpl : public Core void Exit(); // return application handle void* GetAppHWND() override; +#ifdef _WIN32 // FIX_LINUX HINSTANCE HINSTANCE GetAppInstance(); +#endif // set time scale; affect on std entity functions DeltaTime parameter void SetTimeScale(float _scale) override; // write message to system log file @@ -150,7 +152,9 @@ class CoreImpl : public Core SERVICES_LIST Services_List; // list for subsequent calls RunStart/RunEnd service functions +#ifdef _WIN32 // FIX_LINUX HINSTANCE HINSTANCE hInstance{}; +#endif char *State_file_name; diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index 01da1a20c..ab98b4034 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -125,7 +125,11 @@ void HandleWindowEvent(const storm::OSWindow::Event &event) } } +#ifdef _WIN32 // FIX_LINUX HINSTANCE int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) +#else +int main(int argc, char *argv[]) +#endif { // Prevent multiple instances if (!CreateEventA(nullptr, false, false, "Global\\FBBD2286-A9F1-4303-B60C-743C3D7AA7BE") || From 3b4b7640afd85d1c5f89d27d5b0b2e967d997501 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:23:41 +0300 Subject: [PATCH 32/59] [linux] FIX_LINUX CreateEventA --- src/apps/engine/src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index ab98b4034..a9f3ba60a 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -132,8 +132,12 @@ int main(int argc, char *argv[]) #endif { // Prevent multiple instances +#ifdef _WIN32 // FIX_LINUX CreateEventA if (!CreateEventA(nullptr, false, false, "Global\\FBBD2286-A9F1-4303-B60C-743C3D7AA7BE") || GetLastError() == ERROR_ALREADY_EXISTS) +#else + if (false) +#endif { MessageBoxA(nullptr, "Another instance is already running!", "Error", MB_ICONERROR); return EXIT_SUCCESS; From 0d6776fc60e71007180d19a7a65c6c14f188e2de Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 17:54:16 +0300 Subject: [PATCH 33/59] [linux] replace MessageBoxA with SDL_ShowSimpleMessageBox --- src/apps/engine/src/core_impl.cpp | 3 ++- src/apps/engine/src/main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/apps/engine/src/core_impl.cpp b/src/apps/engine/src/core_impl.cpp index 0101514cc..378560466 100644 --- a/src/apps/engine/src/core_impl.cpp +++ b/src/apps/engine/src/core_impl.cpp @@ -8,6 +8,7 @@ #include #include "storm/string_compare.hpp" +#include namespace storm { @@ -289,8 +290,8 @@ void CoreImpl::ProcessEngineIniFile() { #ifdef _WIN32 // FIX_LINUX Cursor ShowCursor(true); - MessageBoxA(nullptr, "Wrong script version", "Error", MB_OK); #endif + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Wrong script version", nullptr); Compiler->ExitProgram(); } } diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index a9f3ba60a..afd737ed3 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) if (false) #endif { - MessageBoxA(nullptr, "Another instance is already running!", "Error", MB_ICONERROR); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Another instance is already running!", nullptr); return EXIT_SUCCESS; } mi_register_output(mimalloc_fun, nullptr); @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) #endif if (!lifecycleDiagnosticsGuard) { - MessageBoxA(nullptr, "Unable to initialize lifecycle service!", "Warning", MB_ICONWARNING); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning", "Unable to initialize lifecycle service!", nullptr); } else { From 41094c3277a2d74534983bba420d5bb59f7a7b47 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 18:16:05 +0300 Subject: [PATCH 34/59] [linux] FIX_LINUX VirtualKey --- src/libs/common/include/controls.h | 12 ++++++++++++ src/libs/xinterface/src/nodes/xi_util.cpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/libs/common/include/controls.h b/src/libs/common/include/controls.h index 7c21c40e0..37adfe37b 100644 --- a/src/libs/common/include/controls.h +++ b/src/libs/common/include/controls.h @@ -194,17 +194,29 @@ class CONTROLS virtual short GetDebugAsyncKeyState(int vk) { +#ifdef _WIN32 // FIX_LINUX VirtualKey return GetAsyncKeyState(vk); +#else + return 0; +#endif } virtual short GetDebugKeyState(int vk) { +#ifdef _WIN32 // FIX_LINUX VirtualKey return GetKeyState(vk); +#else + return 0; +#endif } virtual bool IsKeyPressed(int vk) { +#ifdef _WIN32 // FIX_LINUX VirtualKey return GetKeyState(vk) < 0; +#else + return false; +#endif } // Get the keystroke buffer per frame (taking into account the language) diff --git a/src/libs/xinterface/src/nodes/xi_util.cpp b/src/libs/xinterface/src/nodes/xi_util.cpp index 9e3f394d3..dfef022e0 100644 --- a/src/libs/xinterface/src/nodes/xi_util.cpp +++ b/src/libs/xinterface/src/nodes/xi_util.cpp @@ -106,12 +106,14 @@ char CXI_UTILS::GetKeyInput() uint8_t pKBState[256]; uint16_t pcTmp[16]; // in general, need 2 characters (the rest just in case) +#ifdef _WIN32 // FIX_LINUX VirtualKey GetKeyboardState(pKBState); if (ToAscii(n, MapVirtualKey(n, 0), pKBState, pcTmp, 0) == 1) { cRetVal = static_cast(pcTmp[0]); return cRetVal; } +#endif } cRetVal = 0; } From 2030d59f13c171045308f2cc12464fef8935e858 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:28:57 +0300 Subject: [PATCH 35/59] remove unused struct tSoundDriverDescriptor, FILETIME ft_old, _cdecl and constexpr --- src/libs/ball_splash/src/ball_splash.h | 2 +- src/libs/common/include/entity_manager.h | 2 +- src/libs/common/include/entity_state.h | 2 +- src/libs/rigging/src/rope.cpp | 2 -- src/libs/sound_service/include/v_sound_service.h | 7 ------- 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/libs/ball_splash/src/ball_splash.h b/src/libs/ball_splash/src/ball_splash.h index 886fe21b9..84cb58536 100644 --- a/src/libs/ball_splash/src/ball_splash.h +++ b/src/libs/ball_splash/src/ball_splash.h @@ -22,7 +22,7 @@ class BALLSPLASH : public Entity virtual void Realize(uint32_t dTime); virtual void Execute(uint32_t dTime); - void BALLSPLASH::ProcessStage(Stage stage, uint32_t delta) override + void ProcessStage(Stage stage, uint32_t delta) override { switch (stage) { diff --git a/src/libs/common/include/entity_manager.h b/src/libs/common/include/entity_manager.h index fdc362f36..ebdcc2043 100644 --- a/src/libs/common/include/entity_manager.h +++ b/src/libs/common/include/entity_manager.h @@ -347,7 +347,7 @@ class EntityManager final } /* this is (temporary) workaround solution */ - static constexpr AllEntIterators GetEntityIdIterators() + static AllEntIterators GetEntityIdIterators() { return std::pair{std::begin(entities_.first), std::begin(entities_.first) + entities_.second}; } diff --git a/src/libs/common/include/entity_state.h b/src/libs/common/include/entity_state.h index 9de874a96..42bdfca20 100644 --- a/src/libs/common/include/entity_state.h +++ b/src/libs/common/include/entity_state.h @@ -8,7 +8,7 @@ class ENTITY_STATE_GEN public: virtual ~ENTITY_STATE_GEN() = default; - virtual void _cdecl SetState(const char *Format, ...) = 0; + virtual void SetState(const char *Format, ...) = 0; }; class ENTITY_STATE diff --git a/src/libs/rigging/src/rope.cpp b/src/libs/rigging/src/rope.cpp index 9e9f24d65..cd3ffa05d 100644 --- a/src/libs/rigging/src/rope.cpp +++ b/src/libs/rigging/src/rope.cpp @@ -93,8 +93,6 @@ bool ROPE::LoadState(ENTITY_STATE *state) return true; } -FILETIME ft_old; - void ROPE::Execute(uint32_t Delta_Time) { uint64_t rtm; diff --git a/src/libs/sound_service/include/v_sound_service.h b/src/libs/sound_service/include/v_sound_service.h index df528c2d5..632be47b7 100644 --- a/src/libs/sound_service/include/v_sound_service.h +++ b/src/libs/sound_service/include/v_sound_service.h @@ -10,13 +10,6 @@ // DEFINES & TYPES /////////////////////////////////////////////////////////////////// -using tSoundDriverDescriptor = struct -{ - LPGUID guid; - char description[COMMON_STRING_LENGTH]; - char driverName[COMMON_STRING_LENGTH]; -}; - using TSD_ID = int32_t; using tSoundStatistics = struct From 37fbc3268601151c6757fc324d4858013aa14009 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:34:56 +0300 Subject: [PATCH 36/59] avoid error: non-const lvalue reference to type 'va_list' (aka '__builtin_va_list') cannot bind to a value of unrelated type '__va_list_tag *' --- src/libs/common/include/message.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/common/include/message.h b/src/libs/common/include/message.h index 3180d14da..92fe28e3e 100644 --- a/src/libs/common/include/message.h +++ b/src/libs/common/include/message.h @@ -185,7 +185,7 @@ class MESSAGE final } private: - static storm::MessageParam GetParamValue(const char c, va_list &args) + static storm::MessageParam GetParamValue(const char c, va_list args) { switch (c) { From d1251468a45943590e1a488010dbcf318328fa64 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:38:07 +0300 Subject: [PATCH 37/59] [linux] FIX_LINUX WideCharToMultiByte + MultiByteToWideChar --- src/libs/common/include/utf8.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libs/common/include/utf8.h b/src/libs/common/include/utf8.h index ce6cd49d6..c90256f6a 100644 --- a/src/libs/common/include/utf8.h +++ b/src/libs/common/include/utf8.h @@ -28,18 +28,30 @@ struct u8_char inline std::string ConvertWideToUtf8(const std::wstring &wstr) { +#ifdef _WIN32 // FIX_LINUX WideCharToMultiByte int count = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), static_cast(wstr.length()), NULL, 0, NULL, NULL); std::string str(count, 0); WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, &str[0], count, NULL, NULL); return str; +#else + auto ws = wstr.c_str(); + int count = wcslen(ws); + return std::string(ws, ws + count); +#endif } inline std::wstring ConvertUtf8ToWide(const std::string &str) { +#ifdef _WIN32 // FIX_LINUX MultiByteToWideChar int count = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast(str.length()), NULL, 0); std::wstring wstr(count, 0); MultiByteToWideChar(CP_UTF8, 0, str.c_str(), static_cast(str.length()), &wstr[0], count); return wstr; +#else + wchar_t *buf = new wchar_t[str.size()]; + size_t num_chars = std::mbstowcs(buf, str.c_str(), str.size()); + return std::wstring(buf, num_chars); +#endif } /* is c the start of a utf8 sequence? */ From a671b3bee46ffb522482facd720ff87f74b00eec Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:43:39 +0300 Subject: [PATCH 38/59] [linux] FIX_LINUX sentry_options --- src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp b/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp index c5c32b976..d9600a4d4 100644 --- a/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp +++ b/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp @@ -13,10 +13,12 @@ #include "watermark.hpp" #ifdef _UNICODE +#ifdef _WIN32 // FIX_LINUX sentry_options #include #define sentry_options_set_database_path sentry_options_set_database_pathw #define sentry_options_set_handler_path sentry_options_set_handler_pathw #define sentry_options_add_attachment sentry_options_add_attachmentw +#endif #else #include #define _T(x) x @@ -161,6 +163,7 @@ LifecycleDiagnosticsService::Guard LifecycleDiagnosticsService::initialize(const if (!initialized_) { +#ifdef _WIN32 // FIX_LINUX sentry_options // TODO: make this crossplatform auto *options = sentry_options_new(); sentry_options_set_dsn(options, "https://1798a1bcfb654cbd8ce157b381964525@o572138.ingest.sentry.io/5721165"); @@ -172,6 +175,7 @@ LifecycleDiagnosticsService::Guard LifecycleDiagnosticsService::initialize(const sentry_options_set_system_crash_reporter_enabled(options, enableCrashReports); initialized_ = sentry_init(options) == 0; +#endif } return Guard(*this); @@ -183,7 +187,9 @@ void LifecycleDiagnosticsService::terminate() const if (initialized_) { +#ifdef _WIN32 // FIX_LINUX sentry_options sentry_close(); +#endif } } From 7bd9060b9936f5e4280bf708ebde3e1a73e6d878 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:47:42 +0300 Subject: [PATCH 39/59] [linux] FIX_LINUX Beep --- src/libs/renderer/src/screenshot.cpp | 4 ++++ src/libs/ship/src/ship_utils.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/libs/renderer/src/screenshot.cpp b/src/libs/renderer/src/screenshot.cpp index 1f3eb8e86..c05caf6d9 100644 --- a/src/libs/renderer/src/screenshot.cpp +++ b/src/libs/renderer/src/screenshot.cpp @@ -65,9 +65,13 @@ bool DX9RENDER::MakeCapture() if (dwCaptureBuffersReady >= aCaptureBuffers.size()) { +#ifdef _WIN32 // FIX_LINUX Beep Beep(1000, 150); SaveCaptureBuffers(); Beep(5000, 150); +#else + SaveCaptureBuffers(); +#endif } #ifdef _WIN32 // FIX_LINUX HBITMAP diff --git a/src/libs/ship/src/ship_utils.cpp b/src/libs/ship/src/ship_utils.cpp index 7f51f092e..164fa0c73 100644 --- a/src/libs/ship/src/ship_utils.cpp +++ b/src/libs/ship/src/ship_utils.cpp @@ -43,7 +43,9 @@ BOOL SHIP::BuildContour(CVECTOR *vContour, int32_t &iNumVContour) { core.Trace("SHIP: Up trace error, ship %s", GetAShip()->GetAttribute("Name")); bDefaultContour = true; +#ifdef _WIN32 // FIX_LINUX Beep Beep(1000, 200); +#endif } // Assert(fRes<=1.0f); @@ -57,7 +59,9 @@ BOOL SHIP::BuildContour(CVECTOR *vContour, int32_t &iNumVContour) { core.Trace("SHIP: Down trace error, ship %s", GetAShip()->GetAttribute("Name")); bDefaultContour = true; +#ifdef _WIN32 // FIX_LINUX Beep Beep(1000, 200); +#endif } // Assert(fRes<=1.0f); From f114a8c3feca6f0f00e039b7b505170fd208b91b Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Sun, 16 Jan 2022 23:50:59 +0300 Subject: [PATCH 40/59] [linux] FIX_LINUX 7za.exe --- src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp b/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp index d9600a4d4..f9e87639d 100644 --- a/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp +++ b/src/libs/diagnostics/src/lifecycle_diagnostics_service.cpp @@ -43,12 +43,14 @@ auto &getLogsArchive() return logsArchive; } +#ifdef _WIN32 // FIX_LINUX 7za.exe auto assembleArchiveCmd() { constexpr auto archiverBin = "7za.exe"; return _T("call \"") + (getExecutableDir() / archiverBin).native() + _T("\" a \"\\\\?\\") + getLogsArchive().native() + _T("\" \"\\\\?\\") + fs::GetLogsPath().native() + _T("\""); } +#endif } @@ -236,8 +238,10 @@ sentry_value_t LifecycleDiagnosticsService::beforeCrash(const sentry_value_t eve // terminate logging self->loggingService_->terminate(); +#ifdef _WIN32 // FIX_LINUX 7za.exe // archive logs for sentry backend _tsystem(assembleArchiveCmd().c_str()); +#endif return event; } From 5e2b42aa1756700cfcb4a00e383482311f2ca210 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:12:14 +0300 Subject: [PATCH 41/59] [linux] use inline wrapper for strcat_s, strcpy_s, strncpy_s --- src/libs/common/include/storm_platform.h | 56 ++++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index a1a072eae..3ff2439a6 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -2,45 +2,45 @@ #include "safe_str_lib.h" -// use custom strcpy_s instead of safeclib: #define strcpy_s(dest, dmax, src) -#undef strcpy_s +// use inline wrapper for strcat_s from safeclib instead of #define strcat_s +#undef strcat_s +inline errno_t strcat_s(char *restrict dest, rsize_t size, const char *restrict src) +{ + return _strcat_s_chk(dest, size, src, BOS(dest)); +} -inline int strcpy_s(char *dest, size_t size, const char *src) +template inline errno_t strcat_s(char (&dest)[size], const char *src) { - if (!dest) - return EINVAL; + return strcat_s(dest, size, src); +} - if (0 == size) - { - dest[0] = '\0'; - return ERANGE; - } +// use inline wrapper for strcpy_s from safeclib instead of #define strcpy_s +#undef strcpy_s +inline errno_t strcpy_s(char *restrict dest, rsize_t size, const char *restrict src) +{ + return _strcpy_s_chk(dest, size, src, BOS(dest)); +} - if (!src) - { - dest[0] = '\0'; - return EINVAL; - } +template inline errno_t strcpy_s(char (&dest)[size], const char *src) +{ + return strcpy_s(dest, size, src); +} - size_t i; - for (i = 0; i < size; i++) - { - if ((dest[i] = src[i]) == '\0') - return 0; - } - dest[0] = '\0'; - return ERANGE; +// use inline wrapper for strncpy_s from safeclib instead of #define strncpy_s +#undef strncpy_s +inline errno_t strncpy_s(char *restrict dest, rsize_t size, const char *restrict src, rsize_t count) +{ + return _strncpy_s_chk(dest, size, src, count, BOS(dest), BOS(src)); } -template inline int strcpy_s(char (&dest)[size], const char *src) +template inline errno_t strncpy_s(char (&dest)[size], const char *src, rsize_t count) { - return strcpy_s(dest, size, src); + return strncpy_s(dest, size, src, count); } // use custom sprintf_s instead of safeclib: #define sprintf_s(dest, dmax, ...) #undef sprintf_s - -template inline int sprintf_s(char (&buffer)[size], const char *format, ...) +template inline int sprintf_s(char (&buffer)[size], const char *format, ...) { va_list args; va_start(args, format); @@ -49,7 +49,7 @@ template inline int sprintf_s(char (&buffer)[size], const char *fo return result; } -inline int sprintf_s(char *buffer, size_t size, const char *format, ...) +inline int sprintf_s(char *buffer, rsize_t size, const char *format, ...) { va_list ap; va_start(ap, format); From 5095b1ca002e48d6435354f3beb4fbad5e9f869c Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:18:20 +0300 Subject: [PATCH 42/59] [linux] add convert_path_sep, defines for MAX_* and MAKELONG add platform includes --- src/libs/common/include/storm_platform.h | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index 3ff2439a6..0c20fadf3 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -1,6 +1,31 @@ -#ifndef _WIN32 +#pragma once +#ifdef _WIN32 +inline const char *convert_path_sep(const char *cPath) +{ + return cPath; +} +#else + +#include #include "safe_str_lib.h" +#undef EXTERN // fix for token.h:72:5: error: expected identifier EXTERN, + +#define MAX_PATH PATH_MAX +#define _MAX_FNAME NAME_MAX +#define MAKELONG(low, high) ((int32_t)(((uint16_t)(low)) | (((uint32_t)((uint16_t)(high))) << 16))) + +inline char *convert_path_sep(const char *cPath) +{ + const auto len = strlen(cPath) + 1; + auto newPath = new char[len]; + strcpy(newPath, cPath); + + while (char *sep = strchr(newPath, '\\')) + *sep = '/'; + + return newPath; +} // use inline wrapper for strcat_s from safeclib instead of #define strcat_s #undef strcat_s From a282692cca133e5d3004c9342ee6ccbe733ce5f7 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:21:26 +0300 Subject: [PATCH 43/59] [linux] temporary add winuser.h from Wine for VK_* defines --- src/libs/common/include/linux/winuser.h | 1401 ++++++++++++++++++++++ src/libs/common/include/storm_platform.h | 1 + 2 files changed, 1402 insertions(+) create mode 100644 src/libs/common/include/linux/winuser.h diff --git a/src/libs/common/include/linux/winuser.h b/src/libs/common/include/linux/winuser.h new file mode 100644 index 000000000..fd984a917 --- /dev/null +++ b/src/libs/common/include/linux/winuser.h @@ -0,0 +1,1401 @@ +/* + * Copyright (C) the Wine project + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* Macro to deal with LP64 <=> LLP64 differences in numeric constants with 'l' modifier */ +#ifndef __MSABI_LONG +# if defined(_MSC_VER) || defined(__MINGW32__) || defined(__CYGWIN__) +# define __MSABI_LONG(x) x ## l +# else +# define __MSABI_LONG(x) x +# endif +#endif + +#ifdef RC_INVOKED +# define MAKEINTRESOURCE(i) i +#endif + + +#define RT_MANIFEST MAKEINTRESOURCE(24) +#define CREATEPROCESS_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(1) +#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(2) +#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(3) +#define MINIMUM_RESERVED_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(1) +#define MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID MAKEINTRESOURCE(16) + + +/*** ShowWindow() codes ***/ +#define SW_HIDE 0 +#define SW_SHOWNORMAL 1 +#define SW_NORMAL SW_SHOWNORMAL +#define SW_SHOWMINIMIZED 2 +#define SW_SHOWMAXIMIZED 3 +#define SW_MAXIMIZE SW_SHOWMAXIMIZED +#define SW_SHOWNOACTIVATE 4 +#define SW_SHOW 5 +#define SW_MINIMIZE 6 +#define SW_SHOWMINNOACTIVE 7 +#define SW_SHOWNA 8 +#define SW_RESTORE 9 +#define SW_SHOWDEFAULT 10 +#define SW_FORCEMINIMIZE 11 +#define SW_MAX 11 +#define SW_NORMALNA 0xCC /* Undocumented. Flag in MinMaximize */ + +/* Obsolete ShowWindow() codes for compatibility */ +#define HIDE_WINDOW SW_HIDE +#define SHOW_OPENWINDOW SW_SHOWNORMAL +#define SHOW_ICONWINDOW SW_SHOWMINIMIZED +#define SHOW_FULLSCREEN SW_SHOWMAXIMIZED +#define SHOW_OPENNOACTIVATE SW_SHOWNOACTIVATE + +/* WM_SHOWWINDOW lParam codes */ +#define SW_PARENTCLOSING 1 +#define SW_OTHERZOOM 2 +#define SW_PARENTOPENING 3 +#define SW_OTHERUNZOOM 4 + + +/*** Virtual key codes ***/ +#define VK_LBUTTON 0x01 +#define VK_RBUTTON 0x02 +#define VK_CANCEL 0x03 +#define VK_MBUTTON 0x04 +#define VK_XBUTTON1 0x05 +#define VK_XBUTTON2 0x06 +/* 0x07 Undefined */ +#define VK_BACK 0x08 +#define VK_TAB 0x09 +/* 0x0A-0x0B Undefined */ +#define VK_CLEAR 0x0C +#define VK_RETURN 0x0D +/* 0x0E-0x0F Undefined */ +#define VK_SHIFT 0x10 +#define VK_CONTROL 0x11 +#define VK_MENU 0x12 +#define VK_PAUSE 0x13 +#define VK_CAPITAL 0x14 + +#define VK_KANA 0x15 +#define VK_HANGEUL VK_KANA +#define VK_HANGUL VK_KANA +/* 0x16 Undefined */ +#define VK_JUNJA 0x17 +#define VK_FINAL 0x18 +#define VK_HANJA 0x19 +#define VK_KANJI VK_HANJA + +/* 0x1A Undefined */ +#define VK_ESCAPE 0x1B + +#define VK_CONVERT 0x1C +#define VK_NONCONVERT 0x1D +#define VK_ACCEPT 0x1E +#define VK_MODECHANGE 0x1F + +#define VK_SPACE 0x20 +#define VK_PRIOR 0x21 +#define VK_NEXT 0x22 +#define VK_END 0x23 +#define VK_HOME 0x24 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 +#define VK_SELECT 0x29 +#define VK_PRINT 0x2A /* OEM specific in Windows 3.1 SDK */ +#define VK_EXECUTE 0x2B +#define VK_SNAPSHOT 0x2C +#define VK_INSERT 0x2D +#define VK_DELETE 0x2E +#define VK_HELP 0x2F +/* VK_0 - VK-9 0x30-0x39 Use ASCII instead */ +/* 0x3A-0x40 Undefined */ +/* VK_A - VK_Z 0x41-0x5A Use ASCII instead */ +#define VK_LWIN 0x5B +#define VK_RWIN 0x5C +#define VK_APPS 0x5D +/* 0x5E Unassigned */ +#define VK_SLEEP 0x5F +#define VK_NUMPAD0 0x60 +#define VK_NUMPAD1 0x61 +#define VK_NUMPAD2 0x62 +#define VK_NUMPAD3 0x63 +#define VK_NUMPAD4 0x64 +#define VK_NUMPAD5 0x65 +#define VK_NUMPAD6 0x66 +#define VK_NUMPAD7 0x67 +#define VK_NUMPAD8 0x68 +#define VK_NUMPAD9 0x69 +#define VK_MULTIPLY 0x6A +#define VK_ADD 0x6B +#define VK_SEPARATOR 0x6C +#define VK_SUBTRACT 0x6D +#define VK_DECIMAL 0x6E +#define VK_DIVIDE 0x6F +#define VK_F1 0x70 +#define VK_F2 0x71 +#define VK_F3 0x72 +#define VK_F4 0x73 +#define VK_F5 0x74 +#define VK_F6 0x75 +#define VK_F7 0x76 +#define VK_F8 0x77 +#define VK_F9 0x78 +#define VK_F10 0x79 +#define VK_F11 0x7A +#define VK_F12 0x7B +#define VK_F13 0x7C +#define VK_F14 0x7D +#define VK_F15 0x7E +#define VK_F16 0x7F +#define VK_F17 0x80 +#define VK_F18 0x81 +#define VK_F19 0x82 +#define VK_F20 0x83 +#define VK_F21 0x84 +#define VK_F22 0x85 +#define VK_F23 0x86 +#define VK_F24 0x87 +#define VK_NAVIGATION_VIEW 0x88 +#define VK_NAVIGATION_MENU 0x89 +#define VK_NAVIGATION_UP 0x8A +#define VK_NAVIGATION_DOWN 0x8B +#define VK_NAVIGATION_LEFT 0x8C +#define VK_NAVIGATION_RIGHT 0x8D +#define VK_NAVIGATION_ACCEPT 0x8E +#define VK_NAVIGATION_CANCEL 0x8F +#define VK_NUMLOCK 0x90 +#define VK_SCROLL 0x91 +#define VK_OEM_NEC_EQUAL 0x92 +#define VK_OEM_FJ_JISHO 0x92 +#define VK_OEM_FJ_MASSHOU 0x93 +#define VK_OEM_FJ_TOUROKU 0x94 +#define VK_OEM_FJ_LOYA 0x95 +#define VK_OEM_FJ_ROYA 0x96 +/* 0x97-0x9F Unassigned */ +/* + * differencing between right and left shift/control/alt key. + * Used only by GetAsyncKeyState() and GetKeyState(). + */ +#define VK_LSHIFT 0xA0 +#define VK_RSHIFT 0xA1 +#define VK_LCONTROL 0xA2 +#define VK_RCONTROL 0xA3 +#define VK_LMENU 0xA4 +#define VK_RMENU 0xA5 + +#define VK_BROWSER_BACK 0xA6 +#define VK_BROWSER_FORWARD 0xA7 +#define VK_BROWSER_REFRESH 0xA8 +#define VK_BROWSER_STOP 0xA9 +#define VK_BROWSER_SEARCH 0xAA +#define VK_BROWSER_FAVORITES 0xAB +#define VK_BROWSER_HOME 0xAC +#define VK_VOLUME_MUTE 0xAD +#define VK_VOLUME_DOWN 0xAE +#define VK_VOLUME_UP 0xAF +#define VK_MEDIA_NEXT_TRACK 0xB0 +#define VK_MEDIA_PREV_TRACK 0xB1 +#define VK_MEDIA_STOP 0xB2 +#define VK_MEDIA_PLAY_PAUSE 0xB3 +#define VK_LAUNCH_MAIL 0xB4 +#define VK_LAUNCH_MEDIA_SELECT 0xB5 +#define VK_LAUNCH_APP1 0xB6 +#define VK_LAUNCH_APP2 0xB7 + +/* 0xB8-0xB9 Unassigned */ +#define VK_OEM_1 0xBA +#define VK_OEM_PLUS 0xBB +#define VK_OEM_COMMA 0xBC +#define VK_OEM_MINUS 0xBD +#define VK_OEM_PERIOD 0xBE +#define VK_OEM_2 0xBF +#define VK_OEM_3 0xC0 +/* 0xC1-0xC2 Unassigned */ +#define VK_GAMEPAD_A 0xC3 +#define VK_GAMEPAD_B 0xC4 +#define VK_GAMEPAD_X 0xC5 +#define VK_GAMEPAD_Y 0xC6 +#define VK_GAMEPAD_RIGHT_SHOULDER 0xC7 +#define VK_GAMEPAD_LEFT_SHOULDER 0xC8 +#define VK_GAMEPAD_LEFT_TRIGGER 0xC9 +#define VK_GAMEPAD_RIGHT_TRIGGER 0xCA +#define VK_GAMEPAD_DPAD_UP 0xCB +#define VK_GAMEPAD_DPAD_DOWN 0xCC +#define VK_GAMEPAD_DPAD_LEFT 0xCD +#define VK_GAMEPAD_DPAD_RIGHT 0xCE +#define VK_GAMEPAD_MENU 0xCF +#define VK_GAMEPAD_VIEW 0xD0 +#define VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON 0xD1 +#define VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON 0xD2 +#define VK_GAMEPAD_LEFT_THUMBSTICK_UP 0xD3 +#define VK_GAMEPAD_LEFT_THUMBSTICK_DOWN 0xD4 +#define VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT 0xD5 +#define VK_GAMEPAD_LEFT_THUMBSTICK_LEFT 0xD6 +#define VK_GAMEPAD_RIGHT_THUMBSTICK_UP 0xD7 +#define VK_GAMEPAD_RIGHT_THUMBSTICK_DOWN 0xD8 +#define VK_GAMEPAD_RIGHT_THUMBSTICK_RIGHT 0xD9 +#define VK_GAMEPAD_RIGHT_THUMBSTICK_LEFT 0xDA +#define VK_OEM_4 0xDB +#define VK_OEM_5 0xDC +#define VK_OEM_6 0xDD +#define VK_OEM_7 0xDE +#define VK_OEM_8 0xDF +/* 0xE0 OEM specific */ +#define VK_OEM_AX 0xE1 /* "AX" key on Japanese AX keyboard */ +#define VK_OEM_102 0xE2 /* "<>" or "\|" on RT 102-key keyboard */ +#define VK_ICO_HELP 0xE3 /* Help key on ICO */ +#define VK_ICO_00 0xE4 /* 00 key on ICO */ +#define VK_PROCESSKEY 0xE5 +#define VK_ICO_CLEAR 0xE6 + +#define VK_PACKET 0xE7 +/* 0xE8 Unassigned */ + +#define VK_OEM_RESET 0xE9 +#define VK_OEM_JUMP 0xEA +#define VK_OEM_PA1 0xEB +#define VK_OEM_PA2 0xEC +#define VK_OEM_PA3 0xED +#define VK_OEM_WSCTRL 0xEE +#define VK_OEM_CUSEL 0xEF +#define VK_OEM_ATTN 0xF0 +#define VK_OEM_FINISH 0xF1 +#define VK_OEM_COPY 0xF2 +#define VK_OEM_AUTO 0xF3 +#define VK_OEM_ENLW 0xF4 +#define VK_OEM_BACKTAB 0xF5 +#define VK_ATTN 0xF6 +#define VK_CRSEL 0xF7 +#define VK_EXSEL 0xF8 +#define VK_EREOF 0xF9 +#define VK_PLAY 0xFA +#define VK_ZOOM 0xFB +#define VK_NONAME 0xFC +#define VK_PA1 0xFD +#define VK_OEM_CLEAR 0xFE +/* 0xFF Unassigned */ + + +/*** Messages ***/ +#ifndef NOWINMESSAGES +#define WM_NULL 0x0000 +#define WM_CREATE 0x0001 +#define WM_DESTROY 0x0002 +#define WM_MOVE 0x0003 +#define WM_SIZEWAIT 0x0004 /* DDK / Win16 */ +#define WM_SIZE 0x0005 +#define WM_ACTIVATE 0x0006 + +/* WM_ACTIVATE wParam values */ +#define WA_INACTIVE 0 +#define WA_ACTIVE 1 +#define WA_CLICKACTIVE 2 + +#define WM_SETFOCUS 0x0007 +#define WM_KILLFOCUS 0x0008 +#define WM_SETVISIBLE 0x0009 /* DDK / Win16 */ +#define WM_ENABLE 0x000a +#define WM_SETREDRAW 0x000b +#define WM_SETTEXT 0x000c +#define WM_GETTEXT 0x000d +#define WM_GETTEXTLENGTH 0x000e +#define WM_PAINT 0x000f +#define WM_CLOSE 0x0010 +#define WM_QUERYENDSESSION 0x0011 +#define WM_QUIT 0x0012 +#define WM_QUERYOPEN 0x0013 +#define WM_ERASEBKGND 0x0014 +#define WM_SYSCOLORCHANGE 0x0015 +#define WM_ENDSESSION 0x0016 +#define WM_SYSTEMERROR 0x0017 /* DDK / Win16 */ +#define WM_SHOWWINDOW 0x0018 +#define WM_CTLCOLOR 0x0019 /* Added from windowsx.h */ +#define WM_WININICHANGE 0x001a +#define WM_SETTINGCHANGE WM_WININICHANGE +#define WM_DEVMODECHANGE 0x001b +#define WM_ACTIVATEAPP 0x001c +#define WM_FONTCHANGE 0x001d +#define WM_TIMECHANGE 0x001e +#define WM_CANCELMODE 0x001f +#define WM_SETCURSOR 0x0020 +#define WM_MOUSEACTIVATE 0x0021 +#define WM_CHILDACTIVATE 0x0022 +#define WM_QUEUESYNC 0x0023 +#define WM_GETMINMAXINFO 0x0024 + +#define WM_PAINTICON 0x0026 +#define WM_ICONERASEBKGND 0x0027 +#define WM_NEXTDLGCTL 0x0028 +#define WM_ALTTABACTIVE 0x0029 /* DDK / Win16 */ +#define WM_SPOOLERSTATUS 0x002a +#define WM_DRAWITEM 0x002b +#define WM_MEASUREITEM 0x002c +#define WM_DELETEITEM 0x002d +#define WM_VKEYTOITEM 0x002e +#define WM_CHARTOITEM 0x002f +#define WM_SETFONT 0x0030 +#define WM_GETFONT 0x0031 +#define WM_SETHOTKEY 0x0032 +#define WM_GETHOTKEY 0x0033 +#define WM_FILESYSCHANGE 0x0034 /* DDK / Win16 */ +#define WM_ISACTIVEICON 0x0035 /* DDK / Win16 */ +#define WM_QUERYPARKICON 0x0036 /* Undocumented */ +#define WM_QUERYDRAGICON 0x0037 +#define WM_QUERYSAVESTATE 0x0038 /* Undocumented */ +#define WM_COMPAREITEM 0x0039 +#define WM_TESTING 0x003a /* DDK / Win16 */ + +#define WM_GETOBJECT 0x003d + +#define WM_ACTIVATESHELLWINDOW 0x003e /* FIXME: Wine-only */ + +#define WM_COMPACTING 0x0041 + +#define WM_COMMNOTIFY 0x0044 +#define WM_WINDOWPOSCHANGING 0x0046 +#define WM_WINDOWPOSCHANGED 0x0047 + +#define WM_POWER 0x0048 + +/* For WM_POWER */ +#define PWR_OK 1 +#define PWR_FAIL (-1) +#define PWR_SUSPENDREQUEST 1 +#define PWR_SUSPENDRESUME 2 +#define PWR_CRITICALRESUME 3 + +/* Win32 4.0 messages */ +#define WM_COPYDATA 0x004a +#define WM_CANCELJOURNAL 0x004b +#define WM_KEYF1 0x004d /* DDK / Win16 */ +#define WM_NOTIFY 0x004e +#define WM_INPUTLANGCHANGEREQUEST 0x0050 +#define WM_INPUTLANGCHANGE 0x0051 +#define WM_TCARD 0x0052 +#define WM_HELP 0x0053 +#define WM_USERCHANGED 0x0054 +#define WM_NOTIFYFORMAT 0x0055 + +/* WM_NOTIFYFORMAT commands and return values */ +#define NFR_ANSI 1 +#define NFR_UNICODE 2 +#define NF_QUERY 3 +#define NF_REQUERY 4 + +#define WM_CONTEXTMENU 0x007b +#define WM_STYLECHANGING 0x007c +#define WM_STYLECHANGED 0x007d +#define WM_DISPLAYCHANGE 0x007e +#define WM_GETICON 0x007f +#define WM_SETICON 0x0080 + +/* Non-client system messages */ +#define WM_NCCREATE 0x0081 +#define WM_NCDESTROY 0x0082 +#define WM_NCCALCSIZE 0x0083 +#define WM_NCHITTEST 0x0084 +#define WM_NCPAINT 0x0085 +#define WM_NCACTIVATE 0x0086 + +#define WM_GETDLGCODE 0x0087 +#define WM_SYNCPAINT 0x0088 +#define WM_SYNCTASK 0x0089 /* DDK / Win16 */ + +/* Non-client mouse messages */ +#define WM_NCMOUSEMOVE 0x00a0 +#define WM_NCLBUTTONDOWN 0x00a1 +#define WM_NCLBUTTONUP 0x00a2 +#define WM_NCLBUTTONDBLCLK 0x00a3 +#define WM_NCRBUTTONDOWN 0x00a4 +#define WM_NCRBUTTONUP 0x00a5 +#define WM_NCRBUTTONDBLCLK 0x00a6 +#define WM_NCMBUTTONDOWN 0x00a7 +#define WM_NCMBUTTONUP 0x00a8 +#define WM_NCMBUTTONDBLCLK 0x00a9 + +#define WM_NCXBUTTONDOWN 0x00ab +#define WM_NCXBUTTONUP 0x00ac +#define WM_NCXBUTTONDBLCLK 0x00ad + +/* Raw input */ +#define WM_INPUT_DEVICE_CHANGE 0x00fe +#define WM_INPUT 0x00ff + +/* Keyboard messages */ +#define WM_KEYFIRST 0x0100 +#define WM_KEYDOWN WM_KEYFIRST +#define WM_KEYUP 0x0101 +#define WM_CHAR 0x0102 +#define WM_DEADCHAR 0x0103 +#define WM_SYSKEYDOWN 0x0104 +#define WM_SYSKEYUP 0x0105 +#define WM_SYSCHAR 0x0106 +#define WM_SYSDEADCHAR 0x0107 +#define WM_UNICHAR 0x0109 +#define WM_KEYLAST WM_UNICHAR + +#define UNICODE_NOCHAR 0xffff + +/* Win32 4.0 messages for IME */ +#define WM_IME_STARTCOMPOSITION 0x010d +#define WM_IME_ENDCOMPOSITION 0x010e +#define WM_IME_COMPOSITION 0x010f +#define WM_IME_KEYLAST 0x010f + +#define WM_INITDIALOG 0x0110 +#define WM_COMMAND 0x0111 +#define WM_SYSCOMMAND 0x0112 +#define WM_TIMER 0x0113 + +/* Scroll messages */ +#define WM_HSCROLL 0x0114 +#define WM_VSCROLL 0x0115 + +/* Menu messages */ +#define WM_INITMENU 0x0116 +#define WM_INITMENUPOPUP 0x0117 +#define WM_GESTURE 0x0119 +#define WM_GESTURENOTIFY 0x011A + +#define WM_MENUSELECT 0x011F +#define WM_MENUCHAR 0x0120 +#define WM_ENTERIDLE 0x0121 + +#define WM_MENURBUTTONUP 0x0122 +#define WM_MENUDRAG 0x0123 +#define WM_MENUGETOBJECT 0x0124 +#define WM_UNINITMENUPOPUP 0x0125 +#define WM_MENUCOMMAND 0x0126 + +#define WM_CHANGEUISTATE 0x0127 +#define WM_UPDATEUISTATE 0x0128 +#define WM_QUERYUISTATE 0x0129 + +/* UI flags for WM_*UISTATE */ +/* for low-order word of wparam */ +#define UIS_SET 1 +#define UIS_CLEAR 2 +#define UIS_INITIALIZE 3 +/* for hi-order word of wparam */ +#define UISF_HIDEFOCUS 0x1 +#define UISF_HIDEACCEL 0x2 +#define UISF_ACTIVE 0x4 + +#define WM_LBTRACKPOINT 0x0131 /* DDK / Win16 */ + +/* Win32 CTLCOLOR messages */ +#define WM_CTLCOLORMSGBOX 0x0132 +#define WM_CTLCOLOREDIT 0x0133 +#define WM_CTLCOLORLISTBOX 0x0134 +#define WM_CTLCOLORBTN 0x0135 +#define WM_CTLCOLORDLG 0x0136 +#define WM_CTLCOLORSCROLLBAR 0x0137 +#define WM_CTLCOLORSTATIC 0x0138 + +#define MN_GETHMENU 0x01E1 + +/* Mouse messages */ +#define WM_MOUSEFIRST 0x0200 +#define WM_MOUSEMOVE WM_MOUSEFIRST +#define WM_LBUTTONDOWN 0x0201 +#define WM_LBUTTONUP 0x0202 +#define WM_LBUTTONDBLCLK 0x0203 +#define WM_RBUTTONDOWN 0x0204 +#define WM_RBUTTONUP 0x0205 +#define WM_RBUTTONDBLCLK 0x0206 +#define WM_MBUTTONDOWN 0x0207 +#define WM_MBUTTONUP 0x0208 +#define WM_MBUTTONDBLCLK 0x0209 +#define WM_MOUSEWHEEL 0x020A +#define WM_XBUTTONDOWN 0x020B +#define WM_XBUTTONUP 0x020C +#define WM_XBUTTONDBLCLK 0x020D +#define WM_MOUSEHWHEEL 0x020E +#define WM_MOUSELAST WM_MOUSEHWHEEL + +/* Macros for the mouse messages */ +#define WHEEL_DELTA 120 +#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam)) +#define WHEEL_PAGESCROLL (UINT_MAX) + +#define GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam)) +#define GET_NCHITTEST_WPARAM(wParam) ((short)LOWORD(wParam)) +#define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam)) +#define XBUTTON1 0x0001 +#define XBUTTON2 0x0002 + +#define WM_PARENTNOTIFY 0x0210 +#define WM_ENTERMENULOOP 0x0211 +#define WM_EXITMENULOOP 0x0212 +#define WM_NEXTMENU 0x0213 + +/* Win32 4.0 messages */ +#define WM_SIZING 0x0214 +#define WM_CAPTURECHANGED 0x0215 +#define WM_MOVING 0x0216 +#define WM_POWERBROADCAST 0x0218 +#define WM_DEVICECHANGE 0x0219 +/* MDI messages */ +#define WM_MDICREATE 0x0220 +#define WM_MDIDESTROY 0x0221 +#define WM_MDIACTIVATE 0x0222 +#define WM_MDIRESTORE 0x0223 +#define WM_MDINEXT 0x0224 +#define WM_MDIMAXIMIZE 0x0225 +#define WM_MDITILE 0x0226 +#define WM_MDICASCADE 0x0227 +#define WM_MDIICONARRANGE 0x0228 +#define WM_MDIGETACTIVE 0x0229 + +/* D&D messages */ +#define WM_DROPOBJECT 0x022A /* DDK / Win16 */ +#define WM_QUERYDROPOBJECT 0x022B /* DDK / Win16 */ +#define WM_BEGINDRAG 0x022C /* DDK / Win16 */ +#define WM_DRAGLOOP 0x022D /* DDK / Win16 */ +#define WM_DRAGSELECT 0x022E /* DDK / Win16 */ +#define WM_DRAGMOVE 0x022F /* DDK / Win16 */ + +#define WM_MDISETMENU 0x0230 +#define WM_ENTERSIZEMOVE 0x0231 +#define WM_EXITSIZEMOVE 0x0232 +#define WM_DROPFILES 0x0233 +#define WM_MDIREFRESHMENU 0x0234 + +#define WM_POINTERDEVICECHANGE 0x0238 +#define WM_POINTERDEVICEINRANGE 0x0239 +#define WM_POINTERDEVICEOUTOFRANGE 0x023a + +#define WM_TOUCH 0x0240 +#define WM_NCPOINTERUPDATE 0x0241 +#define WM_NCPOINTERDOWN 0x0242 +#define WM_NCPOINTERUP 0x0243 +#define WM_POINTERUPDATE 0x0245 +#define WM_POINTERDOWN 0x0246 +#define WM_POINTERUP 0x0247 +#define WM_POINTERENTER 0x0249 +#define WM_POINTERLEAVE 0x024a +#define WM_POINTERACTIVATE 0x024b +#define WM_POINTERCAPTURECHANGED 0x024c +#define WM_TOUCHHITTESTING 0x024d +#define WM_POINTERWHEEL 0x024e +#define WM_POINTERHWHEEL 0x024f +#define DM_POINTERHITTEST 0x0250 +#define WM_POINTERROUTEDTO 0x0251 +#define WM_POINTERROUTEDAWAY 0x0252 +#define WM_POINTERROUTEDRELEASED 0x0253 + +/* Win32 4.0 messages for IME */ +#define WM_IME_SETCONTEXT 0x0281 +#define WM_IME_NOTIFY 0x0282 +#define WM_IME_CONTROL 0x0283 +#define WM_IME_COMPOSITIONFULL 0x0284 +#define WM_IME_SELECT 0x0285 +#define WM_IME_CHAR 0x0286 +/* Win32 5.0 messages for IME */ +#define WM_IME_REQUEST 0x0288 + +/* Win32 4.0 messages for IME */ +#define WM_IME_KEYDOWN 0x0290 +#define WM_IME_KEYUP 0x0291 + +#define WM_NCMOUSEHOVER 0x02A0 +#define WM_MOUSEHOVER 0x02A1 +#define WM_MOUSELEAVE 0x02A3 +#define WM_NCMOUSELEAVE 0x02A2 + +#define WM_WTSSESSION_CHANGE 0x02B1 + +#define WM_TABLET_FIRST 0x02c0 +#define WM_TABLET_LAST 0x02df + +#define WM_DPICHANGED 0x02e0 +#define WM_DPICHANGED_BEFOREPARENT 0x02e2 +#define WM_DPICHANGED_AFTERPARENT 0x02e3 +#define WM_GETDPISCALEDSIZE 0x02e4 + +/* Clipboard command messages */ +#define WM_CUT 0x0300 +#define WM_COPY 0x0301 +#define WM_PASTE 0x0302 +#define WM_CLEAR 0x0303 +#define WM_UNDO 0x0304 + +/* Clipboard owner messages */ +#define WM_RENDERFORMAT 0x0305 +#define WM_RENDERALLFORMATS 0x0306 +#define WM_DESTROYCLIPBOARD 0x0307 + +/* Clipboard viewer messages */ +#define WM_DRAWCLIPBOARD 0x0308 +#define WM_PAINTCLIPBOARD 0x0309 +#define WM_VSCROLLCLIPBOARD 0x030A +#define WM_SIZECLIPBOARD 0x030B +#define WM_ASKCBFORMATNAME 0x030C +#define WM_CHANGECBCHAIN 0x030D +#define WM_HSCROLLCLIPBOARD 0x030E + +#define WM_QUERYNEWPALETTE 0x030F +#define WM_PALETTEISCHANGING 0x0310 +#define WM_PALETTECHANGED 0x0311 +#define WM_HOTKEY 0x0312 + +#define WM_PRINT 0x0317 +#define WM_PRINTCLIENT 0x0318 +#define WM_APPCOMMAND 0x0319 +#define WM_THEMECHANGED 0x031A +#define WM_CLIPBOARDUPDATE 0x031D + +#define WM_DWMCOMPOSITIONCHANGED 0x031E +#define WM_DWMNCRENDERINGCHANGED 0x031F +#define WM_DWMCOLORIZATIONCOLORCHANGED 0x0320 +#define WM_DWMWINDOWMAXIMIZEDCHANGE 0x0321 +#define WM_DWMSENDICONICTHUMBNAIL 0x0323 +#define WM_DWMSENDICONICLIVEPREVIEWBITMAP 0x0326 + +#define WM_GETTITLEBARINFOEX 0x033F + +#define WM_HANDHELDFIRST 0x0358 +#define WM_HANDHELDLAST 0x035F + +#define WM_AFXFIRST 0x0360 +#define WM_AFXLAST 0x037F + +#define WM_PENWINFIRST 0x0380 +#define WM_PENWINLAST 0x038F + +#define WM_USER 0x0400 + +#define WM_APP 0x8000 + + +/* wParam for WM_SIZING message */ +#define WMSZ_LEFT 1 +#define WMSZ_RIGHT 2 +#define WMSZ_TOP 3 +#define WMSZ_TOPLEFT 4 +#define WMSZ_TOPRIGHT 5 +#define WMSZ_BOTTOM 6 +#define WMSZ_BOTTOMLEFT 7 +#define WMSZ_BOTTOMRIGHT 8 + +/* WM_NCHITTEST return codes */ +#define HTERROR (-2) +#define HTTRANSPARENT (-1) +#define HTNOWHERE 0 +#define HTCLIENT 1 +#define HTCAPTION 2 +#define HTSYSMENU 3 +#define HTSIZE 4 +#define HTGROWBOX HTSIZE +#define HTMENU 5 +#define HTHSCROLL 6 +#define HTVSCROLL 7 +#define HTMINBUTTON 8 +#define HTREDUCE HTMINBUTTON +#define HTMAXBUTTON 9 +#define HTZOOM HTMAXBUTTON +#define HTLEFT 10 +#define HTSIZEFIRST HTLEFT +#define HTRIGHT 11 +#define HTTOP 12 +#define HTTOPLEFT 13 +#define HTTOPRIGHT 14 +#define HTBOTTOM 15 +#define HTBOTTOMLEFT 16 +#define HTBOTTOMRIGHT 17 +#define HTSIZELAST HTBOTTOMRIGHT +#define HTBORDER 18 +#define HTOBJECT 19 +#define HTCLOSE 20 +#define HTHELP 21 + +/* SendMessageTimeout flags */ +#define SMTO_NORMAL 0x0000 +#define SMTO_BLOCK 0x0001 +#define SMTO_ABORTIFHUNG 0x0002 +#define SMTO_NOTIMEOUTIFNOTHUNG 0x0008 +#define SMTO_ERRORONEXIT 0x0020 + +/* WM_MOUSEACTIVATE return values */ +#define MA_ACTIVATE 1 +#define MA_ACTIVATEANDEAT 2 +#define MA_NOACTIVATE 3 +#define MA_NOACTIVATEANDEAT 4 + +/* WM_GETICON/WM_SETICON params values */ +#define ICON_SMALL 0 +#define ICON_BIG 1 +#define ICON_SMALL2 2 + +/* WM_SIZE message wParam values */ +#define SIZE_RESTORED 0 +#define SIZE_MINIMIZED 1 +#define SIZE_MAXIMIZED 2 +#define SIZE_MAXSHOW 3 +#define SIZE_MAXHIDE 4 +#define SIZENORMAL SIZE_RESTORED +#define SIZEICONIC SIZE_MINIMIZED +#define SIZEFULLSCREEN SIZE_MAXIMIZED +#define SIZEZOOMSHOW SIZE_MAXSHOW +#define SIZEZOOMHIDE SIZE_MAXHIDE + +/* WM_NCCALCSIZE return flags */ +#define WVR_ALIGNTOP 0x0010 +#define WVR_ALIGNLEFT 0x0020 +#define WVR_ALIGNBOTTOM 0x0040 +#define WVR_ALIGNRIGHT 0x0080 +#define WVR_HREDRAW 0x0100 +#define WVR_VREDRAW 0x0200 +#define WVR_REDRAW (WVR_HREDRAW | WVR_VREDRAW) +#define WVR_VALIDRECTS 0x0400 + +/* Key status flags for mouse events */ +#ifndef NOKEYSTATES +#define MK_LBUTTON 0x0001 +#define MK_RBUTTON 0x0002 +#define MK_SHIFT 0x0004 +#define MK_CONTROL 0x0008 +#define MK_MBUTTON 0x0010 +#define MK_XBUTTON1 0x0020 +#define MK_XBUTTON2 0x0040 +#endif /* NOKEYSTATES */ + +#ifndef NOTRACKMOUSEEVENT +#define TME_HOVER 0x00000001 +#define TME_LEAVE 0x00000002 +#define TME_NONCLIENT 0x00000010 +#define TME_QUERY 0x40000000 +#define TME_CANCEL 0x80000000 +#define HOVER_DEFAULT 0xFFFFFFFF +#endif /* NOTRACKMOUSEEVENT */ + +#endif /* NOWINMESSAGES */ + + +/*** Window Styles ***/ +#ifndef NOWINSTYLES +#define WS_OVERLAPPED __MSABI_LONG(0x00000000) +#define WS_POPUP __MSABI_LONG(0x80000000) +#define WS_CHILD __MSABI_LONG(0x40000000) +#define WS_MINIMIZE __MSABI_LONG(0x20000000) +#define WS_VISIBLE __MSABI_LONG(0x10000000) +#define WS_DISABLED __MSABI_LONG(0x08000000) +#define WS_CLIPSIBLINGS __MSABI_LONG(0x04000000) +#define WS_CLIPCHILDREN __MSABI_LONG(0x02000000) +#define WS_MAXIMIZE __MSABI_LONG(0x01000000) +#define WS_BORDER __MSABI_LONG(0x00800000) +#define WS_DLGFRAME __MSABI_LONG(0x00400000) +#define WS_VSCROLL __MSABI_LONG(0x00200000) +#define WS_HSCROLL __MSABI_LONG(0x00100000) +#define WS_SYSMENU __MSABI_LONG(0x00080000) +#define WS_THICKFRAME __MSABI_LONG(0x00040000) +#define WS_GROUP __MSABI_LONG(0x00020000) +#define WS_TABSTOP __MSABI_LONG(0x00010000) +#define WS_MINIMIZEBOX __MSABI_LONG(0x00020000) +#define WS_MAXIMIZEBOX __MSABI_LONG(0x00010000) +#define WS_CAPTION (WS_BORDER | WS_DLGFRAME) +#define WS_TILED WS_OVERLAPPED +#define WS_ICONIC WS_MINIMIZE +#define WS_SIZEBOX WS_THICKFRAME +#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME| WS_MINIMIZEBOX | WS_MAXIMIZEBOX) +#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU) +#define WS_CHILDWINDOW WS_CHILD +#define WS_TILEDWINDOW WS_OVERLAPPEDWINDOW +#endif /* NOWINSTYLES */ + + +/*** Window extended styles ***/ +#ifndef NOWINSTYLES +#define WS_EX_DLGMODALFRAME __MSABI_LONG(0x00000001) +#define WS_EX_DRAGDETECT __MSABI_LONG(0x00000002) /* Undocumented */ +#define WS_EX_NOPARENTNOTIFY __MSABI_LONG(0x00000004) +#define WS_EX_TOPMOST __MSABI_LONG(0x00000008) +#define WS_EX_ACCEPTFILES __MSABI_LONG(0x00000010) +#define WS_EX_TRANSPARENT __MSABI_LONG(0x00000020) +#define WS_EX_MDICHILD __MSABI_LONG(0x00000040) +#define WS_EX_TOOLWINDOW __MSABI_LONG(0x00000080) +#define WS_EX_WINDOWEDGE __MSABI_LONG(0x00000100) +#define WS_EX_CLIENTEDGE __MSABI_LONG(0x00000200) +#define WS_EX_CONTEXTHELP __MSABI_LONG(0x00000400) +#define WS_EX_RIGHT __MSABI_LONG(0x00001000) +#define WS_EX_LEFT __MSABI_LONG(0x00000000) +#define WS_EX_RTLREADING __MSABI_LONG(0x00002000) +#define WS_EX_LTRREADING __MSABI_LONG(0x00000000) +#define WS_EX_LEFTSCROLLBAR __MSABI_LONG(0x00004000) +#define WS_EX_RIGHTSCROLLBAR __MSABI_LONG(0x00000000) +#define WS_EX_CONTROLPARENT __MSABI_LONG(0x00010000) +#define WS_EX_STATICEDGE __MSABI_LONG(0x00020000) +#define WS_EX_APPWINDOW __MSABI_LONG(0x00040000) +#define WS_EX_LAYERED __MSABI_LONG(0x00080000) +#define WS_EX_NOINHERITLAYOUT __MSABI_LONG(0x00100000) +#define WS_EX_NOREDIRECTIONBITMAP __MSABI_LONG(0x00200000) +#define WS_EX_LAYOUTRTL __MSABI_LONG(0x00400000) +#define WS_EX_COMPOSITED __MSABI_LONG(0x02000000) +#define WS_EX_NOACTIVATE __MSABI_LONG(0x08000000) + +#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) +#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) +#endif /* NOWINSTYLES */ + + +/*** Class styles ***/ +#ifndef NOWINSTYLES +#define CS_VREDRAW 0x00000001 +#define CS_HREDRAW 0x00000002 +#define CS_KEYCVTWINDOW 0x00000004 /* DDK / Win16 */ +#define CS_DBLCLKS 0x00000008 +#define CS_OWNDC 0x00000020 +#define CS_CLASSDC 0x00000040 +#define CS_PARENTDC 0x00000080 +#define CS_NOKEYCVT 0x00000100 /* DDK / Win16 */ +#define CS_NOCLOSE 0x00000200 +#define CS_SAVEBITS 0x00000800 +#define CS_BYTEALIGNCLIENT 0x00001000 +#define CS_BYTEALIGNWINDOW 0x00002000 +#define CS_GLOBALCLASS 0x00004000 +#define CS_IME 0x00010000 +#define CS_DROPSHADOW 0x00020000 +#endif /* NOWINSTYLES */ + + +/*** Predefined Clipboard Formats ***/ +#ifndef NOCLIPBOARD +#define CF_TEXT 1 +#define CF_BITMAP 2 +#define CF_METAFILEPICT 3 +#define CF_SYLK 4 +#define CF_DIF 5 +#define CF_TIFF 6 +#define CF_OEMTEXT 7 +#define CF_DIB 8 +#define CF_PALETTE 9 +#define CF_PENDATA 10 +#define CF_RIFF 11 +#define CF_WAVE 12 +#define CF_UNICODETEXT 13 +#define CF_ENHMETAFILE 14 +#define CF_HDROP 15 +#define CF_LOCALE 16 +#define CF_DIBV5 17 +#define CF_MAX 18 + +#define CF_OWNERDISPLAY 0x0080 +#define CF_DSPTEXT 0x0081 +#define CF_DSPBITMAP 0x0082 +#define CF_DSPMETAFILEPICT 0x0083 +#define CF_DSPENHMETAFILE 0x008E + +/* "Private" formats don't get GlobalFree()'d */ +#define CF_PRIVATEFIRST 0x0200 +#define CF_PRIVATELAST 0x02FF + +/* "GDIOBJ" formats do get DeleteObject()'d */ +#define CF_GDIOBJFIRST 0x0300 +#define CF_GDIOBJLAST 0x03FF +#endif /* NOCLIPBOARD */ + + +/*** Menu flags ***/ +#ifndef NOMENUS +#define MF_INSERT __MSABI_LONG(0x00000000) +#define MF_CHANGE __MSABI_LONG(0x00000080) +#define MF_APPEND __MSABI_LONG(0x00000100) +#define MF_DELETE __MSABI_LONG(0x00000200) +#define MF_REMOVE __MSABI_LONG(0x00001000) +#define MF_END __MSABI_LONG(0x00000080) + +#define MF_ENABLED __MSABI_LONG(0x00000000) +#define MF_GRAYED __MSABI_LONG(0x00000001) +#define MF_DISABLED __MSABI_LONG(0x00000002) +#define MF_STRING __MSABI_LONG(0x00000000) +#define MF_BITMAP __MSABI_LONG(0x00000004) +#define MF_UNCHECKED __MSABI_LONG(0x00000000) +#define MF_CHECKED __MSABI_LONG(0x00000008) +#define MF_POPUP __MSABI_LONG(0x00000010) +#define MF_MENUBARBREAK __MSABI_LONG(0x00000020) +#define MF_MENUBREAK __MSABI_LONG(0x00000040) +#define MF_UNHILITE __MSABI_LONG(0x00000000) +#define MF_HILITE __MSABI_LONG(0x00000080) +#define MF_OWNERDRAW __MSABI_LONG(0x00000100) +#define MF_USECHECKBITMAPS __MSABI_LONG(0x00000200) +#define MF_BYCOMMAND __MSABI_LONG(0x00000000) +#define MF_BYPOSITION __MSABI_LONG(0x00000400) +#define MF_SEPARATOR __MSABI_LONG(0x00000800) +#define MF_DEFAULT __MSABI_LONG(0x00001000) +#define MF_SYSMENU __MSABI_LONG(0x00002000) +#define MF_HELP __MSABI_LONG(0x00004000) +#define MF_RIGHTJUSTIFY __MSABI_LONG(0x00004000) +#define MF_MOUSESELECT __MSABI_LONG(0x00008000) + +/* Flags for extended menu item types */ +#define MFT_STRING MF_STRING +#define MFT_BITMAP MF_BITMAP +#define MFT_MENUBARBREAK MF_MENUBARBREAK +#define MFT_MENUBREAK MF_MENUBREAK +#define MFT_OWNERDRAW MF_OWNERDRAW +#define MFT_RADIOCHECK __MSABI_LONG(0x00000200) +#define MFT_SEPARATOR MF_SEPARATOR +#define MFT_RIGHTORDER __MSABI_LONG(0x00002000) +#define MFT_RIGHTJUSTIFY MF_RIGHTJUSTIFY + +/* Flags for extended menu item states */ +#define MFS_GRAYED __MSABI_LONG(0x00000003) +#define MFS_DISABLED MFS_GRAYED +#define MFS_CHECKED MF_CHECKED +#define MFS_HILITE MF_HILITE +#define MFS_ENABLED MF_ENABLED +#define MFS_UNCHECKED MF_UNCHECKED +#define MFS_UNHILITE MF_UNHILITE +#define MFS_DEFAULT MF_DEFAULT + +/* DDK / Win16 defines */ +#define MFS_MASK __MSABI_LONG(0x0000108B) +#define MFS_HOTTRACKDRAWN __MSABI_LONG(0x10000000) +#define MFS_CACHEDBMP __MSABI_LONG(0x20000000) +#define MFS_BOTTOMGAPDROP __MSABI_LONG(0x40000000) +#define MFS_TOPGAPDROP __MSABI_LONG(0x80000000) +#define MFS_GAPDROP (MFS_BOTTOMGAPDROP | MFS_TOPGAPDROP) +#endif /* NOMENUS */ + + +/*** WM_SYSCOMMAND parameters ***/ +#ifndef NOSYSCOMMANDS +/* At least HP-UX defines it in /usr/include/sys/signal.h */ +# ifdef SC_SIZE +# undef SC_SIZE +# endif +#define SC_SIZE 0xf000 +#define SC_MOVE 0xf010 +#define SC_MINIMIZE 0xf020 +#define SC_MAXIMIZE 0xf030 +#define SC_NEXTWINDOW 0xf040 +#define SC_PREVWINDOW 0xf050 +#define SC_CLOSE 0xf060 +#define SC_VSCROLL 0xf070 +#define SC_HSCROLL 0xf080 +#define SC_MOUSEMENU 0xf090 +#define SC_KEYMENU 0xf100 +#define SC_ARRANGE 0xf110 +#define SC_RESTORE 0xf120 +#define SC_TASKLIST 0xf130 +#define SC_SCREENSAVE 0xf140 +#define SC_HOTKEY 0xf150 + +/* Win32 4.0 */ +#define SC_DEFAULT 0xf160 +#define SC_MONITORPOWER 0xf170 +#define SC_CONTEXTHELP 0xf180 +#define SC_SEPARATOR 0xf00f + +#define GET_SC_WPARAM(wParam) ((int)wParam & 0xfff0) +#define SCF_ISSECURE 0x0001 + +/* Obsolete names */ +#define SC_ICON SC_MINIMIZE +#define SC_ZOOM SC_MAXIMIZE +#endif /* NOSYSCOMMANDS */ + + +/*** OEM Resource Ordinal Numbers ***/ +#ifdef OEMRESOURCE +#define OBM_RDRVERT 32559 +#define OBM_RDRHORZ 32660 +#define OBM_RDR2DIM 32661 +#define OBM_TRTYPE 32732 /* FIXME: Wine-only */ +#define OBM_LFARROWI 32734 +#define OBM_RGARROWI 32735 +#define OBM_DNARROWI 32736 +#define OBM_UPARROWI 32737 +#define OBM_COMBO 32738 +#define OBM_MNARROW 32739 +#define OBM_LFARROWD 32740 +#define OBM_RGARROWD 32741 +#define OBM_DNARROWD 32742 +#define OBM_UPARROWD 32743 +#define OBM_RESTORED 32744 +#define OBM_ZOOMD 32745 +#define OBM_REDUCED 32746 +#define OBM_RESTORE 32747 +#define OBM_ZOOM 32748 +#define OBM_REDUCE 32749 +#define OBM_LFARROW 32750 +#define OBM_RGARROW 32751 +#define OBM_DNARROW 32752 +#define OBM_UPARROW 32753 +#define OBM_CLOSE 32754 +#define OBM_OLD_RESTORE 32755 +#define OBM_OLD_ZOOM 32756 +#define OBM_OLD_REDUCE 32757 +#define OBM_BTNCORNERS 32758 +#define OBM_CHECKBOXES 32759 +#define OBM_CHECK 32760 +#define OBM_BTSIZE 32761 +#define OBM_OLD_LFARROW 32762 +#define OBM_OLD_RGARROW 32763 +#define OBM_OLD_DNARROW 32764 +#define OBM_OLD_UPARROW 32765 +#define OBM_SIZE 32766 +#define OBM_OLD_CLOSE 32767 + +#define OCR_NORMAL 32512 +#define OCR_IBEAM 32513 +#define OCR_WAIT 32514 +#define OCR_CROSS 32515 +#define OCR_UP 32516 +#define OCR_PEN 32631 +#define OCR_SIZE 32640 +#define OCR_ICON 32641 +#define OCR_SIZENWSE 32642 +#define OCR_SIZENESW 32643 +#define OCR_SIZEWE 32644 +#define OCR_SIZENS 32645 +#define OCR_SIZEALL 32646 +#define OCR_ICOCUR 32647 +#define OCR_NO 32648 +#define OCR_HAND 32649 +#define OCR_APPSTARTING 32650 +#define OCR_HELP 32651 /* DDK / Win16 */ +#define OCR_RDRVERT 32652 /* DDK / Win16 */ +#define OCR_RDRHORZ 32653 /* DDK / Win16 */ +#define OCR_RDR2DIM 32654 /* DDK / Win16 */ +#define OCR_RDRNORTH 32655 /* DDK / Win16 */ +#define OCR_RDRSOUTH 32656 /* DDK / Win16 */ +#define OCR_RDRWEST 32657 /* DDK / Win16 */ +#define OCR_RDREAST 32658 /* DDK / Win16 */ +#define OCR_RDRNORTHWEST 32659 /* DDK / Win16 */ +#define OCR_RDRNORTHEAST 32660 /* DDK / Win16 */ +#define OCR_RDRSOUTHWEST 32661 /* DDK / Win16 */ +#define OCR_RDRSOUTHEAST 32662 /* DDK / Win16 */ + +#define OIC_SAMPLE 32512 +#define OIC_HAND 32513 +#define OIC_ERROR OIC_HAND +#define OIC_QUES 32514 +#define OIC_BANG 32515 +#define OIC_WARNING OIC_BANG +#define OIC_NOTE 32516 +#define OIC_INFORMATION OIC_NOTE +#define OIC_WINLOGO 32517 +#define OIC_SHIELD 32518 +#endif /* OEMRESOURCE */ + + +/*** Predefined resources ***/ +#ifndef NOICONS +#define IDI_APPLICATION MAKEINTRESOURCE(32512) +#define IDI_HAND MAKEINTRESOURCE(32513) +#define IDI_QUESTION MAKEINTRESOURCE(32514) +#define IDI_EXCLAMATION MAKEINTRESOURCE(32515) +#define IDI_ASTERISK MAKEINTRESOURCE(32516) +#define IDI_WINLOGO MAKEINTRESOURCE(32517) +#define IDI_SHIELD MAKEINTRESOURCE(32518) + +#define IDI_WARNING IDI_EXCLAMATION +#define IDI_ERROR IDI_HAND +#define IDI_INFORMATION IDI_ASTERISK +#endif /* NOICONS */ + + +/*** Standard dialog button IDs ***/ +#define IDOK 1 +#define IDCANCEL 2 +#define IDABORT 3 +#define IDRETRY 4 +#define IDIGNORE 5 +#define IDYES 6 +#define IDNO 7 +#define IDCLOSE 8 +#define IDHELP 9 +#define IDTRYAGAIN 10 +#define IDCONTINUE 11 +#ifndef IDTIMEOUT +#define IDTIMEOUT 32000 +#endif + + +/*** Edit control styles ***/ +#ifndef NOWINSTYLES +#define ES_LEFT __MSABI_LONG(0x00000000) +#define ES_CENTER __MSABI_LONG(0x00000001) +#define ES_RIGHT __MSABI_LONG(0x00000002) +#define ES_MULTILINE __MSABI_LONG(0x00000004) +#define ES_UPPERCASE __MSABI_LONG(0x00000008) +#define ES_LOWERCASE __MSABI_LONG(0x00000010) +#define ES_PASSWORD __MSABI_LONG(0x00000020) +#define ES_AUTOVSCROLL __MSABI_LONG(0x00000040) +#define ES_AUTOHSCROLL __MSABI_LONG(0x00000080) +#define ES_NOHIDESEL __MSABI_LONG(0x00000100) +#define ES_COMBO __MSABI_LONG(0x00000200) /* Undocumented. Parent is a combobox */ +#define ES_OEMCONVERT __MSABI_LONG(0x00000400) +#define ES_READONLY __MSABI_LONG(0x00000800) +#define ES_WANTRETURN __MSABI_LONG(0x00001000) +#define ES_NUMBER __MSABI_LONG(0x00002000) +#endif /* NOWINSTYLES */ + + +/*** Edit control messages ***/ +#ifndef NOWINMESSAGES +#define EM_GETSEL 0x00b0 +#define EM_SETSEL 0x00b1 +#define EM_GETRECT 0x00b2 +#define EM_SETRECT 0x00b3 +#define EM_SETRECTNP 0x00b4 +#define EM_SCROLL 0x00b5 +#define EM_LINESCROLL 0x00b6 +#define EM_SCROLLCARET 0x00b7 +#define EM_GETMODIFY 0x00b8 +#define EM_SETMODIFY 0x00b9 +#define EM_GETLINECOUNT 0x00ba +#define EM_LINEINDEX 0x00bb +#define EM_SETHANDLE 0x00bc +#define EM_GETHANDLE 0x00bd +#define EM_GETTHUMB 0x00be +/* Unassigned 0x00bf and 0x00c0 */ +#define EM_LINELENGTH 0x00c1 +#define EM_REPLACESEL 0x00c2 +#define EM_SETFONT 0x00c3 /* DDK / Win16 */ +#define EM_GETLINE 0x00c4 +#define EM_LIMITTEXT 0x00c5 +#define EM_SETLIMITTEXT EM_LIMITTEXT +#define EM_CANUNDO 0x00c6 +#define EM_UNDO 0x00c7 +#define EM_FMTLINES 0x00c8 +#define EM_LINEFROMCHAR 0x00c9 +#define EM_SETWORDBREAK 0x00ca /* DDK / Win16 */ +#define EM_SETTABSTOPS 0x00cb +#define EM_SETPASSWORDCHAR 0x00cc +#define EM_EMPTYUNDOBUFFER 0x00cd +#define EM_GETFIRSTVISIBLELINE 0x00ce +#define EM_SETREADONLY 0x00cf +#define EM_SETWORDBREAKPROC 0x00d0 +#define EM_GETWORDBREAKPROC 0x00d1 +#define EM_GETPASSWORDCHAR 0x00d2 +#define EM_SETMARGINS 0x00d3 +#define EM_GETMARGINS 0x00d4 +#define EM_GETLIMITTEXT 0x00d5 +#define EM_POSFROMCHAR 0x00d6 +#define EM_CHARFROMPOS 0x00d7 +#define EM_SETIMESTATUS 0x00d8 +#define EM_GETIMESTATUS 0x00d9 +#endif /* NOWINMESSAGES */ + + +/*** Button control styles ***/ +#define BS_PUSHBUTTON __MSABI_LONG(0x00000000) +#define BS_DEFPUSHBUTTON __MSABI_LONG(0x00000001) +#define BS_CHECKBOX __MSABI_LONG(0x00000002) +#define BS_AUTOCHECKBOX __MSABI_LONG(0x00000003) +#define BS_RADIOBUTTON __MSABI_LONG(0x00000004) +#define BS_3STATE __MSABI_LONG(0x00000005) +#define BS_AUTO3STATE __MSABI_LONG(0x00000006) +#define BS_GROUPBOX __MSABI_LONG(0x00000007) +#define BS_USERBUTTON __MSABI_LONG(0x00000008) +#define BS_AUTORADIOBUTTON __MSABI_LONG(0x00000009) +#define BS_PUSHBOX __MSABI_LONG(0x0000000A) +#define BS_OWNERDRAW __MSABI_LONG(0x0000000B) +#define BS_TYPEMASK __MSABI_LONG(0x0000000F) +#define BS_LEFTTEXT __MSABI_LONG(0x00000020) +#define BS_RIGHTBUTTON BS_LEFTTEXT + +#define BS_TEXT __MSABI_LONG(0x00000000) +#define BS_ICON __MSABI_LONG(0x00000040) +#define BS_BITMAP __MSABI_LONG(0x00000080) +#define BS_LEFT __MSABI_LONG(0x00000100) +#define BS_RIGHT __MSABI_LONG(0x00000200) +#define BS_CENTER __MSABI_LONG(0x00000300) +#define BS_TOP __MSABI_LONG(0x00000400) +#define BS_BOTTOM __MSABI_LONG(0x00000800) +#define BS_VCENTER __MSABI_LONG(0x00000C00) +#define BS_PUSHLIKE __MSABI_LONG(0x00001000) +#define BS_MULTILINE __MSABI_LONG(0x00002000) +#define BS_NOTIFY __MSABI_LONG(0x00004000) +#define BS_FLAT __MSABI_LONG(0x00008000) + + +/*** Button notification codes ***/ +#define BN_CLICKED 0 +#define BN_PAINT 1 +#define BN_HILITE 2 +#define BN_PUSHED BN_HILITE +#define BN_UNHILITE 3 +#define BN_UNPUSHED BN_UNHILITE +#define BN_DISABLE 4 +#define BN_DOUBLECLICKED 5 +#define BN_DBLCLK BN_DOUBLECLICKED +#define BN_SETFOCUS 6 +#define BN_KILLFOCUS 7 + + +/*** Win32 button control messages ***/ +#define BM_GETCHECK 0x00f0 +#define BM_SETCHECK 0x00f1 +#define BM_GETSTATE 0x00f2 +#define BM_SETSTATE 0x00f3 +#define BM_SETSTYLE 0x00f4 +#define BM_CLICK 0x00f5 +#define BM_GETIMAGE 0x00f6 +#define BM_SETIMAGE 0x00f7 +#define BM_SETDONTCLICK 0x00f8 + +/* Button states */ +#define BST_UNCHECKED 0x0000 +#define BST_CHECKED 0x0001 +#define BST_INDETERMINATE 0x0002 +#define BST_PUSHED 0x0004 +#define BST_FOCUS 0x0008 + +/*** Static Control Styles ***/ +#define SS_LEFT __MSABI_LONG(0x00000000) +#define SS_CENTER __MSABI_LONG(0x00000001) +#define SS_RIGHT __MSABI_LONG(0x00000002) +#define SS_ICON __MSABI_LONG(0x00000003) +#define SS_BLACKRECT __MSABI_LONG(0x00000004) +#define SS_GRAYRECT __MSABI_LONG(0x00000005) +#define SS_WHITERECT __MSABI_LONG(0x00000006) +#define SS_BLACKFRAME __MSABI_LONG(0x00000007) +#define SS_GRAYFRAME __MSABI_LONG(0x00000008) +#define SS_WHITEFRAME __MSABI_LONG(0x00000009) +#define SS_USERITEM __MSABI_LONG(0x0000000A) +#define SS_SIMPLE __MSABI_LONG(0x0000000B) +#define SS_LEFTNOWORDWRAP __MSABI_LONG(0x0000000C) +#define SS_OWNERDRAW __MSABI_LONG(0x0000000D) +#define SS_BITMAP __MSABI_LONG(0x0000000E) +#define SS_ENHMETAFILE __MSABI_LONG(0x0000000F) +#define SS_ETCHEDHORZ __MSABI_LONG(0x00000010) +#define SS_ETCHEDVERT __MSABI_LONG(0x00000011) +#define SS_ETCHEDFRAME __MSABI_LONG(0x00000012) +#define SS_TYPEMASK __MSABI_LONG(0x0000001F) + +#define SS_REALSIZECONTROL __MSABI_LONG(0x00000040) +#define SS_NOPREFIX __MSABI_LONG(0x00000080) +#define SS_NOTIFY __MSABI_LONG(0x00000100) +#define SS_CENTERIMAGE __MSABI_LONG(0x00000200) +#define SS_RIGHTJUST __MSABI_LONG(0x00000400) +#define SS_REALSIZEIMAGE __MSABI_LONG(0x00000800) +#define SS_SUNKEN __MSABI_LONG(0x00001000) +#define SS_EDITCONTROL __MSABI_LONG(0x00002000) +#define SS_ENDELLIPSIS __MSABI_LONG(0x00004000) +#define SS_PATHELLIPSIS __MSABI_LONG(0x00008000) +#define SS_WORDELLIPSIS __MSABI_LONG(0x0000C000) +#define SS_ELLIPSISMASK SS_WORDELLIPSIS + + +/*** Dialog styles ***/ +#define DS_ABSALIGN __MSABI_LONG(0x00000001) +#define DS_SYSMODAL __MSABI_LONG(0x00000002) +#define DS_3DLOOK __MSABI_LONG(0x00000004) /* win95 */ +#define DS_FIXEDSYS __MSABI_LONG(0x00000008) /* win95 */ +#define DS_NOFAILCREATE __MSABI_LONG(0x00000010) /* win95 */ +#define DS_LOCALEDIT __MSABI_LONG(0x00000020) +#define DS_SETFONT __MSABI_LONG(0x00000040) +#define DS_MODALFRAME __MSABI_LONG(0x00000080) +#define DS_NOIDLEMSG __MSABI_LONG(0x00000100) +#define DS_SETFOREGROUND __MSABI_LONG(0x00000200) /* win95 */ +#define DS_CONTROL __MSABI_LONG(0x00000400) /* win95 */ +#define DS_CENTER __MSABI_LONG(0x00000800) /* win95 */ +#define DS_CENTERMOUSE __MSABI_LONG(0x00001000) /* win95 */ +#define DS_CONTEXTHELP __MSABI_LONG(0x00002000) /* win95 */ +#define DS_USEPIXELS __MSABI_LONG(0x00008000) +#define DS_SHELLFONT (DS_SETFONT | DS_FIXEDSYS) + + +/*** Listbox styles ***/ +#ifndef NOWINSTYLES +#define LBS_NOTIFY __MSABI_LONG(0x00000001) +#define LBS_SORT __MSABI_LONG(0x00000002) +#define LBS_NOREDRAW __MSABI_LONG(0x00000004) +#define LBS_MULTIPLESEL __MSABI_LONG(0x00000008) +#define LBS_OWNERDRAWFIXED __MSABI_LONG(0x00000010) +#define LBS_OWNERDRAWVARIABLE __MSABI_LONG(0x00000020) +#define LBS_HASSTRINGS __MSABI_LONG(0x00000040) +#define LBS_USETABSTOPS __MSABI_LONG(0x00000080) +#define LBS_NOINTEGRALHEIGHT __MSABI_LONG(0x00000100) +#define LBS_MULTICOLUMN __MSABI_LONG(0x00000200) +#define LBS_WANTKEYBOARDINPUT __MSABI_LONG(0x00000400) +#define LBS_EXTENDEDSEL __MSABI_LONG(0x00000800) +#define LBS_DISABLENOSCROLL __MSABI_LONG(0x00001000) +#define LBS_NODATA __MSABI_LONG(0x00002000) +#define LBS_NOSEL __MSABI_LONG(0x00004000) +#define LBS_COMBOBOX __MSABI_LONG(0x00008000) +#define LBS_STANDARD (LBS_NOTIFY | LBS_SORT | WS_VSCROLL | WS_BORDER) +#endif /* NOWINSTYLES */ + +/*** Combo box styles ***/ +#ifndef NOWINSTYLES +#define CBS_SIMPLE __MSABI_LONG(0x00000001) +#define CBS_DROPDOWN __MSABI_LONG(0x00000002) +#define CBS_DROPDOWNLIST __MSABI_LONG(0x00000003) +#define CBS_OWNERDRAWFIXED __MSABI_LONG(0x00000010) +#define CBS_OWNERDRAWVARIABLE __MSABI_LONG(0x00000020) +#define CBS_AUTOHSCROLL __MSABI_LONG(0x00000040) +#define CBS_OEMCONVERT __MSABI_LONG(0x00000080) +#define CBS_SORT __MSABI_LONG(0x00000100) +#define CBS_HASSTRINGS __MSABI_LONG(0x00000200) +#define CBS_NOINTEGRALHEIGHT __MSABI_LONG(0x00000400) +#define CBS_DISABLENOSCROLL __MSABI_LONG(0x00000800) + +#define CBS_UPPERCASE __MSABI_LONG(0x00002000) +#define CBS_LOWERCASE __MSABI_LONG(0x00004000) +#endif /* NOWINSTYLES */ + + +/*** Scrollbar styles ***/ +#ifndef NOWINSTYLES +#define SBS_HORZ __MSABI_LONG(0x00000000) +#define SBS_VERT __MSABI_LONG(0x00000001) +#define SBS_TOPALIGN __MSABI_LONG(0x00000002) +#define SBS_LEFTALIGN __MSABI_LONG(0x00000002) +#define SBS_BOTTOMALIGN __MSABI_LONG(0x00000004) +#define SBS_RIGHTALIGN __MSABI_LONG(0x00000004) +#define SBS_SIZEBOXTOPLEFTALIGN __MSABI_LONG(0x00000002) +#define SBS_SIZEBOXBOTTOMRIGHTALIGN __MSABI_LONG(0x00000004) +#define SBS_SIZEBOX __MSABI_LONG(0x00000008) +#define SBS_SIZEGRIP __MSABI_LONG(0x00000010) +#endif /* NOWINSTYLES */ + +/*** WinHelp commands ***/ +#define HELP_CONTEXT __MSABI_LONG(0x00000001) +#define HELP_QUIT __MSABI_LONG(0x00000002) +#define HELP_INDEX __MSABI_LONG(0x00000003) +#define HELP_CONTENTS HELP_INDEX +#define HELP_HELPONHELP __MSABI_LONG(0x00000004) +#define HELP_SETINDEX __MSABI_LONG(0x00000005) +#define HELP_SETCONTENTS HELP_SETINDEX +#define HELP_CONTEXTPOPUP __MSABI_LONG(0x00000008) +#define HELP_FORCEFILE __MSABI_LONG(0x00000009) +#define HELP_KEY __MSABI_LONG(0x00000101) +#define HELP_COMMAND __MSABI_LONG(0x00000102) +#define HELP_PARTIALKEY __MSABI_LONG(0x00000105) +#define HELP_MULTIKEY __MSABI_LONG(0x00000201) +#define HELP_SETWINPOS __MSABI_LONG(0x00000203) + +#define HELP_CONTEXTMENU 0x000a +#define HELP_FINDER 0x000b +#define HELP_WM_HELP 0x000c +#define HELP_SETPOPUP_POS 0x000d +#define HELP_TCARD_DATA 0x0010 +#define HELP_TCARD_OTHER_CALLER 0x0011 +#define HELP_TCARD 0x8000 + +#define IDH_NO_HELP 28440 +#define IDH_MISSING_CONTEXT 28441 +#define IDH_GENERIC_HELP_BUTTON 28442 +#define IDH_OK 28443 +#define IDH_CANCEL 28444 +#define IDH_HELP 28445 diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index 0c20fadf3..2193df477 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -8,6 +8,7 @@ inline const char *convert_path_sep(const char *cPath) #include +#include "linux/winuser.h" #include "safe_str_lib.h" #undef EXTERN // fix for token.h:72:5: error: expected identifier EXTERN, From 651c21271641eddadabf4a020a68a6eaf44b8230 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:27:06 +0300 Subject: [PATCH 44/59] [linux] FIX_LINUX SHGetKnownFolderPath --- src/libs/util/include/storm/fs.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/util/include/storm/fs.h b/src/libs/util/include/storm/fs.h index d1927f48c..5cd0d2b4a 100644 --- a/src/libs/util/include/storm/fs.h +++ b/src/libs/util/include/storm/fs.h @@ -2,7 +2,11 @@ #include +#ifdef _WIN32 // FIX_LINUX SHGetKnownFolderPath #include +#else +#include +#endif /* Filesystem proxy */ namespace fs @@ -14,11 +18,17 @@ inline path GetStashPath() static path path; if (path.empty()) { +#ifdef _WIN32 // FIX_LINUX SHGetKnownFolderPath wchar_t *str = nullptr; SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, &str); path = str; path = path / "My Games" / "Sea Dogs"; CoTaskMemFree(str); +#else + char *pref_path = nullptr; + pref_path = SDL_GetPrefPath("Akella", "Sea Dogs"); + path = pref_path; +#endif } return path; } From 66cac4a16de69ea7bd2bfdc086bbc3437d691d87 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:30:07 +0300 Subject: [PATCH 45/59] [linux] add window flag and fix OSHandle for DXVK-Native --- src/libs/window/src/sdl_window.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/window/src/sdl_window.cpp b/src/libs/window/src/sdl_window.cpp index 16b929e61..9f2df1503 100644 --- a/src/libs/window/src/sdl_window.cpp +++ b/src/libs/window/src/sdl_window.cpp @@ -7,9 +7,12 @@ namespace storm { SDLWindow::SDLWindow(int width, int height, bool fullscreen) : fullscreen_(fullscreen) { + uint32_t flags = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | SDL_WINDOW_HIDDEN; +#ifndef _WIN32 // DXVK-Native + flags |= SDL_WINDOW_VULKAN; +#endif window_ = std::unique_ptr>( - SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, - (fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | SDL_WINDOW_HIDDEN), + SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags), [](SDL_Window *w) { SDL_DestroyWindow(w); }); sdlID_ = SDL_GetWindowID(window_.get()); @@ -99,10 +102,15 @@ void *SDLWindow::OSHandle() if (!window_) return nullptr; +#ifdef _WIN32 SDL_SysWMinfo info; SDL_VERSION(&info.version); SDL_GetWindowWMInfo(window_.get(), &info); return info.info.win.window; +#else + // dxvk-native uses HWND as SDL2 window handle, so this is allowed + return window_.get(); +#endif } SDL_Window *SDLWindow::SDLHandle() From e847046441f3cde31912453785852ec07bf0cc91 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:37:26 +0300 Subject: [PATCH 46/59] [linux] FIX_LINUX D3DXLoadSurfaceFromSurface part 2 --- src/libs/xinterface/src/scr_shoter/scr_shoter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp index b9fc24f8c..e42e87307 100644 --- a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp +++ b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp @@ -222,8 +222,11 @@ bool SCRSHOTER::MakeScreenShot() IDirect3DSurface9 *pSurf1 = nullptr, *pSurf2 = nullptr; rs->GetSurfaceLevel(texture_, 0, &pSurf1); rs->GetSurfaceLevel(pScrShotTex, 0, &pSurf2); - // rs->UpdateSurface(pSurf2,null,0,pSurf1,null); +#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface hr = D3DXLoadSurfaceFromSurface(pSurf1, nullptr, nullptr, pSurf2, nullptr, nullptr, D3DX_DEFAULT, 0); +#else + hr = rs->UpdateSurface(pSurf2, nullptr, 0, pSurf1, nullptr); +#endif if (pSurf1) rs->Release(pSurf1); if (pSurf2) From 71b7b653453888a9038fceed0e7750ca2fd7226a Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 00:40:51 +0300 Subject: [PATCH 47/59] [linux] FIX_LINUX GetWindowRect --- src/libs/xinterface/src/xinterface.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/xinterface/src/xinterface.cpp b/src/libs/xinterface/src/xinterface.cpp index 19ac6e255..fdf61d331 100644 --- a/src/libs/xinterface/src/xinterface.cpp +++ b/src/libs/xinterface/src/xinterface.cpp @@ -1068,13 +1068,22 @@ void XINTERFACE::LoadIni() if (!ini) throw std::runtime_error("ini file not found!"); +#ifdef _WIN32 // FIX_LINUX GetWindowRect RECT Screen_Rect; GetWindowRect(static_cast(core.GetAppHWND()), &Screen_Rect); +#else + int sdlScreenWidth, sdlScreenHeight; + SDL_GetWindowSize(reinterpret_cast(core.GetAppHWND()), &sdlScreenWidth, &sdlScreenHeight); +#endif fScale = 1.0f; const auto screenSize = core.GetScreenSize(); dwScreenHeight = screenSize.height; +#ifdef _WIN32 // FIX_LINUX GetWindowRect dwScreenWidth = (Screen_Rect.right - Screen_Rect.left) * dwScreenHeight / (Screen_Rect.bottom - Screen_Rect.top); +#else + dwScreenWidth = sdlScreenWidth * dwScreenHeight / sdlScreenHeight; +#endif if (dwScreenWidth < screenSize.width) dwScreenWidth = screenSize.width; GlobalScreenRect.top = 0; From 4f717afc7beeeb7fc957fc1ff7bbaa40c321fcd8 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 01:12:31 +0300 Subject: [PATCH 48/59] [linux] fix includes for Linux --- src/apps/engine/src/data.cpp | 4 +++- src/libs/animation/src/animation_info.cpp | 1 + src/libs/animation/src/animation_service_imp.cpp | 1 + src/libs/common/include/v_module_api.h | 1 + src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp | 2 ++ src/libs/input/include/input.hpp | 2 ++ src/libs/input/src/sdl_input.hpp | 2 ++ src/libs/particles/src/manager/particle_manager.cpp | 1 + src/libs/particles/src/system/data_source/data_string.cpp | 1 + src/libs/renderer/src/effects.h | 1 + src/libs/renderer/src/screenshot.cpp | 4 ++++ src/libs/sailors/src/sailors_way_points.cpp | 1 - src/libs/touch/src/touch.cpp | 1 - src/libs/xinterface/src/xinterface.cpp | 4 ++-- 14 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/apps/engine/src/data.cpp b/src/apps/engine/src/data.cpp index 3507f49bf..2947f6ec7 100644 --- a/src/apps/engine/src/data.cpp +++ b/src/apps/engine/src/data.cpp @@ -1,6 +1,8 @@ #include "data.h" -#include "core_impl.h" +#include + +#include "core_impl.h" #include "storm/string_compare.hpp" #include diff --git a/src/libs/animation/src/animation_info.cpp b/src/libs/animation/src/animation_info.cpp index d9b8cb4f7..2c80f906a 100644 --- a/src/libs/animation/src/animation_info.cpp +++ b/src/libs/animation/src/animation_info.cpp @@ -11,6 +11,7 @@ #include "animation_info.h" #include "storm/string_compare.hpp" +#include "storm_platform.h" // ============================================================================================ // Construction, destruction diff --git a/src/libs/animation/src/animation_service_imp.cpp b/src/libs/animation/src/animation_service_imp.cpp index be173719b..03845aaf0 100644 --- a/src/libs/animation/src/animation_service_imp.cpp +++ b/src/libs/animation/src/animation_service_imp.cpp @@ -15,6 +15,7 @@ #include "animation_imp.h" #include "an_file.h" #include "v_file_service.h" +#include "storm_platform.h" CREATE_SERVICE(AnimationServiceImp) diff --git a/src/libs/common/include/v_module_api.h b/src/libs/common/include/v_module_api.h index 5d8624168..a48001351 100644 --- a/src/libs/common/include/v_module_api.h +++ b/src/libs/common/include/v_module_api.h @@ -1,5 +1,6 @@ #pragma once #include +#include /* TODO: REMOVE THIS.... */ constexpr uint32_t MakeHashValue(const char *string) diff --git a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp index 4b8ac7175..9c1902ab1 100644 --- a/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp +++ b/src/libs/diagnostics/src/spdlog_sinks/syncable_sink.cpp @@ -10,6 +10,8 @@ #include #include +#else +#include #endif #include diff --git a/src/libs/input/include/input.hpp b/src/libs/input/include/input.hpp index 022472c89..abbe7f50e 100644 --- a/src/libs/input/include/input.hpp +++ b/src/libs/input/include/input.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include namespace storm { diff --git a/src/libs/input/src/sdl_input.hpp b/src/libs/input/src/sdl_input.hpp index b3c6bf39e..5728d2030 100644 --- a/src/libs/input/src/sdl_input.hpp +++ b/src/libs/input/src/sdl_input.hpp @@ -4,6 +4,8 @@ #include #include +#include "storm_platform.h" + namespace storm { class SDLInput : public Input diff --git a/src/libs/particles/src/manager/particle_manager.cpp b/src/libs/particles/src/manager/particle_manager.cpp index aa33b4d7d..14e28fe96 100644 --- a/src/libs/particles/src/manager/particle_manager.cpp +++ b/src/libs/particles/src/manager/particle_manager.cpp @@ -13,6 +13,7 @@ #include "defines.h" #include +#include uint32_t GraphRead = 0; diff --git a/src/libs/particles/src/system/data_source/data_string.cpp b/src/libs/particles/src/system/data_source/data_string.cpp index f003f3ab6..78008d9de 100644 --- a/src/libs/particles/src/system/data_source/data_string.cpp +++ b/src/libs/particles/src/system/data_source/data_string.cpp @@ -1,5 +1,6 @@ #include "data_string.h" #include "v_module_api.h" +#include "storm_platform.h" // constructor / destructor DataString::DataString() diff --git a/src/libs/renderer/src/effects.h b/src/libs/renderer/src/effects.h index db9fd716f..3b5dd91e4 100644 --- a/src/libs/renderer/src/effects.h +++ b/src/libs/renderer/src/effects.h @@ -7,6 +7,7 @@ #endif #include #include +#include class Effects final { diff --git a/src/libs/renderer/src/screenshot.cpp b/src/libs/renderer/src/screenshot.cpp index c05caf6d9..f536939e9 100644 --- a/src/libs/renderer/src/screenshot.cpp +++ b/src/libs/renderer/src/screenshot.cpp @@ -1,4 +1,8 @@ +#ifdef _WIN32 #include +#else +#include +#endif #include "core.h" #include "s_device.h" diff --git a/src/libs/sailors/src/sailors_way_points.cpp b/src/libs/sailors/src/sailors_way_points.cpp index a3d2c5211..931d5fcab 100644 --- a/src/libs/sailors/src/sailors_way_points.cpp +++ b/src/libs/sailors/src/sailors_way_points.cpp @@ -1,5 +1,4 @@ #include "sailors_way_points.h" -#include #include "core.h" diff --git a/src/libs/touch/src/touch.cpp b/src/libs/touch/src/touch.cpp index 6cb6f303f..2258add80 100644 --- a/src/libs/touch/src/touch.cpp +++ b/src/libs/touch/src/touch.cpp @@ -1,5 +1,4 @@ #include "touch.h" -#include #include "core.h" diff --git a/src/libs/xinterface/src/xinterface.cpp b/src/libs/xinterface/src/xinterface.cpp index fdf61d331..c604290db 100644 --- a/src/libs/xinterface/src/xinterface.cpp +++ b/src/libs/xinterface/src/xinterface.cpp @@ -1,5 +1,7 @@ #include "storm/xinterface/options_parser.hpp" +#include + #include "xinterface.h" #include "back_scene/back_scene.h" #include "help_chooser/help_chooser.h" @@ -10,8 +12,6 @@ #include "xservice.h" #include -#include - #define CHECK_FILE_NAME "PiratesReadme.txt" #define TT_TITLE_OFFSET 4 From 899f4da1b405ae2ae01fc0ff840f818a9dfbac05 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 08:12:22 +0300 Subject: [PATCH 49/59] [linux] fix includes for Linux --- src/libs/input/src/sdl_input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/input/src/sdl_input.cpp b/src/libs/input/src/sdl_input.cpp index bec4ffaa5..2267633a3 100644 --- a/src/libs/input/src/sdl_input.cpp +++ b/src/libs/input/src/sdl_input.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include namespace storm From 8b407c4c83edbfb6d2acb229dc20c41d3565b7d3 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 08:15:18 +0300 Subject: [PATCH 50/59] fix dependencies for input and fix linking on Linux --- src/libs/input/CMakeLists.txt | 2 +- src/libs/renderer/CMakeLists.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/input/CMakeLists.txt b/src/libs/input/CMakeLists.txt index c32599805..877cd4b4b 100644 --- a/src/libs/input/CMakeLists.txt +++ b/src/libs/input/CMakeLists.txt @@ -1,5 +1,5 @@ STORM_SETUP( TARGET_NAME input TYPE library - DEPENDENCIES sdl + DEPENDENCIES common sdl ) \ No newline at end of file diff --git a/src/libs/renderer/CMakeLists.txt b/src/libs/renderer/CMakeLists.txt index 1bb425f8d..19ca16217 100644 --- a/src/libs/renderer/CMakeLists.txt +++ b/src/libs/renderer/CMakeLists.txt @@ -1,5 +1,7 @@ if (WIN32) set(SYSTEM_DEPS "legacy_stdio_definitions") +else() +set(SYSTEM_DEPS "${DXVK_NATIVE_D3D9_LIB}") endif() STORM_SETUP( From 5ee01fbbf42b55291066799afd19c1b6d0777ae4 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 10:31:58 +0300 Subject: [PATCH 51/59] Revert "avoid error: non-const lvalue reference to type 'va_list' (aka '__builtin_va_list') cannot bind to a value of unrelated type '__va_list_tag *'" This reverts commit eab2884a5c02fe7b261e61159c8d76fbf72eb542. --- src/libs/common/include/message.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/common/include/message.h b/src/libs/common/include/message.h index 92fe28e3e..3180d14da 100644 --- a/src/libs/common/include/message.h +++ b/src/libs/common/include/message.h @@ -185,7 +185,7 @@ class MESSAGE final } private: - static storm::MessageParam GetParamValue(const char c, va_list args) + static storm::MessageParam GetParamValue(const char c, va_list &args) { switch (c) { From d90a2fe610d20f22ad0ac57763aba0b7a985e00d Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 11:58:14 +0300 Subject: [PATCH 52/59] [linux] FIX_LINUX GetTickCount --- src/apps/engine/src/compiler.cpp | 10 ++++++++++ src/apps/engine/src/main.cpp | 11 +++++++++++ src/libs/renderer/src/s_device.cpp | 15 +++++++++++++++ src/libs/renderer/src/s_device.h | 4 ++++ src/libs/sea_creatures/src/sharks.cpp | 8 ++++++++ 5 files changed, 48 insertions(+) diff --git a/src/apps/engine/src/compiler.cpp b/src/apps/engine/src/compiler.cpp index 551c0de87..b07fe6497 100644 --- a/src/apps/engine/src/compiler.cpp +++ b/src/apps/engine/src/compiler.cpp @@ -625,7 +625,11 @@ VDATA *COMPILER::ProcessEvent(const char *event_name) bEventsBreak = false; +#ifdef _WIN32 // FIX_LINUX GetTickCount uint32_t nTimeOnEvent = GetTickCount(); +#else + auto nStartEventTime = std::chrono::system_clock::now(); +#endif #ifdef _WIN32 // FIX_LINUX s_debug.h current_debug_mode = CDebug->GetTraceMode(); #endif @@ -695,9 +699,15 @@ VDATA *COMPILER::ProcessEvent(const char *event_name) break; } +#ifdef _WIN32 // FIX_LINUX GetTickCount nTimeOnEvent = GetTickCount() - nTimeOnEvent; nRuntimeTicks += nTimeOnEvent; +#else + std::chrono::duration nTimeOnEvent = std::chrono::system_clock::now() - nStartEventTime; + + nRuntimeTicks += static_cast(nTimeOnEvent.count()); +#endif pRun_fi = nullptr; diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index afd737ed3..35a3a342d 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -240,7 +240,11 @@ int main(int argc, char *argv[]) core_internal.InitBase(); // Message loop +#ifdef _WIN32 // FIX_LINUX GetTickCount auto dwOldTime = GetTickCount(); +#else + auto dwOldTime = std::chrono::system_clock::now(); +#endif isRunning = true; while (isRunning) @@ -253,9 +257,16 @@ int main(int argc, char *argv[]) if (dwMaxFPS) { const auto dwMS = 1000u / dwMaxFPS; +#ifdef _WIN32 // FIX_LINUX GetTickCount const auto dwNewTime = GetTickCount(); if (dwNewTime - dwOldTime < dwMS) continue; +#else + const auto dwNewTime = std::chrono::system_clock::now(); + const std::chrono::duration passedTime = dwNewTime - dwOldTime; + if (static_cast(passedTime.count()) < dwMS) + continue; +#endif dwOldTime = dwNewTime; } diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 0c1edfda2..415b19562 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -465,7 +465,11 @@ DX9RENDER::DX9RENDER() back0Texture = -1; progressSafeCounter = 0; isInPViewProcess = false; +#ifdef _WIN32 // FIX_LINUX GetTickCount progressUpdateTime = 0; +#else + progressUpdateTime = std::chrono::system_clock::now(); +#endif progressFramesPosX = 0.85f; progressFramesPosY = 0.8f; progressFramesWidth = 64; @@ -4235,7 +4239,11 @@ void DX9RENDER::StartProgressView() progressTipsTexture = TextureCreate(progressTipsImage); isInPViewProcess = false; } +#ifdef _WIN32 // FIX_LINUX GetTickCount progressUpdateTime = GetTickCount() - 1000; +#else + progressUpdateTime = std::chrono::system_clock::now() - std::chrono::milliseconds(1000); +#endif } void DX9RENDER::ProgressView() @@ -4246,9 +4254,16 @@ void DX9RENDER::ProgressView() if (isInPViewProcess) return; // Analyzing time +#ifdef _WIN32 // FIX_LINUX GetTickCount const uint32_t time = GetTickCount(); if (abs(static_cast(progressUpdateTime - time)) < 50) return; +#else + const auto time = std::chrono::system_clock::now(); + const std::chrono::duration passedTime = progressUpdateTime - time; + if (abs(passedTime.count()) < 50) + return; +#endif progressUpdateTime = time; isInPViewProcess = true; progressSafeCounter = 0; diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index fdfcf5298..ee96ae2ed 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -366,7 +366,11 @@ class DX9RENDER : public VDX9RENDER int32_t loadFrame; int32_t progressSafeCounter; bool isInPViewProcess; +#ifdef _WIN32 // FIX_LINUX GetTickCount uint32_t progressUpdateTime; +#else + std::chrono::time_point progressUpdateTime; +#endif float progressFramesPosX; float progressFramesPosY; float progressFramesWidth; diff --git a/src/libs/sea_creatures/src/sharks.cpp b/src/libs/sea_creatures/src/sharks.cpp index c39168de2..b090462df 100644 --- a/src/libs/sea_creatures/src/sharks.cpp +++ b/src/libs/sea_creatures/src/sharks.cpp @@ -511,7 +511,11 @@ Sharks::Sharks() : sea(0), island(0), indeces{}, vrt{} { rs = nullptr; camPos = 0.0f; +#ifdef _WIN32 // FIX_LINUX GetTickCount numShakes = 3 + (GetTickCount() & 3); +#else + numShakes = 3 + (std::time(nullptr) & 3); +#endif trackTx = -1; periscope.time = -1.0; waitPTime = -1.0f; @@ -570,7 +574,11 @@ bool Sharks::Init() const auto day = root->GetAttributeAsDword("day"); if (day == 7) { +#ifdef _WIN32 // FIX_LINUX GetTickCount if ((GetTickCount() & 7) == 5) +#else + if ((std::time(nullptr) & 7) == 5) +#endif { waitPTime = 60.0f + rand() * 500.0f / RAND_MAX; } From a9a4a6e35ee54c2bf5fd03df5ab0d3ee09dd0d59 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Mon, 17 Jan 2022 12:51:09 +0300 Subject: [PATCH 53/59] [linux] add convert_path_sep to file_service.cpp and s_device.cpp --- src/apps/engine/src/file_service.cpp | 18 +++++++++--------- src/libs/renderer/src/s_device.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/apps/engine/src/file_service.cpp b/src/apps/engine/src/file_service.cpp index dd962a3d2..27ade92cf 100644 --- a/src/apps/engine/src/file_service.cpp +++ b/src/apps/engine/src/file_service.cpp @@ -41,7 +41,7 @@ FILE_SERVICE::~FILE_SERVICE() std::fstream FILE_SERVICE::_CreateFile(const char *filename, std::ios::openmode mode) { - const auto path = filename ? std::filesystem::u8path(filename) : std::filesystem::path(); + const auto path = filename ? std::filesystem::u8path(convert_path_sep(filename)) : std::filesystem::path(); std::fstream fileS(path, mode); return fileS; } @@ -58,7 +58,7 @@ void FILE_SERVICE::_SetFilePointer(std::fstream &fileS, std::streamoff off, std: bool FILE_SERVICE::_DeleteFile(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(filename); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); return std::filesystem::remove(path); } @@ -94,7 +94,7 @@ bool FILE_SERVICE::_ReadFile(std::fstream &fileS, void *s, std::streamsize count bool FILE_SERVICE::_FileOrDirectoryExists(const char *p) { - std::filesystem::path path = std::filesystem::u8path(p); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(p)); auto ec = std::error_code{}; bool result = std::filesystem::exists(path, ec); if (ec) @@ -133,7 +133,7 @@ std::vector FILE_SERVICE::_GetFsPathsByMask(const char *s } else { - srcPath = std::filesystem::u8path(sourcePath); + srcPath = std::filesystem::u8path(convert_path_sep(sourcePath)); } std::filesystem::path curPath; @@ -179,7 +179,7 @@ std::time_t FILE_SERVICE::_ToTimeT(std::filesystem::file_time_type tp) std::filesystem::file_time_type FILE_SERVICE::_GetLastWriteTime(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(filename); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); return std::filesystem::last_write_time(path); } @@ -203,25 +203,25 @@ std::string FILE_SERVICE::_GetExecutableDirectory() std::uintmax_t FILE_SERVICE::_GetFileSize(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(filename); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); return std::filesystem::file_size(path); } void FILE_SERVICE::_SetCurrentDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(pathName); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); std::filesystem::current_path(path); } bool FILE_SERVICE::_CreateDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(pathName); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); return std::filesystem::create_directories(path); } std::uintmax_t FILE_SERVICE::_RemoveDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(pathName); + std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); return std::filesystem::remove_all(path); } diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 415b19562..0d7d40edb 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -1376,7 +1376,7 @@ int32_t DX9RENDER::TextureCreate(const char *fname) return -1L; } - std::filesystem::path path = fname; + std::filesystem::path path = convert_path_sep(fname); std::string pathStr = path.extension().string(); if (storm::iEquals(pathStr, ".tx")) path.replace_extension(); From 62bf562f7158f6d1beaa45cd5b01311dbe07c93b Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Thu, 20 Jan 2022 15:54:04 +0300 Subject: [PATCH 54/59] [linux] fix includes for Linux part 2 --- src/libs/sea_ai/src/ai_ship_cannon_controller.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp index dfb0f5e0f..dd067a160 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp @@ -1,3 +1,5 @@ +#include + #include "ai_balls.h" #include "ai_ship.h" #include "inlines.h" From ceb1f3565d304fce5e59165a3950bbba89f7bbcf Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Thu, 20 Jan 2022 17:02:33 +0300 Subject: [PATCH 55/59] [linux] add explicit constructors for RS_LINE and tr_vertex --- src/libs/common/include/dx9render.h | 9 +++++++++ src/libs/sea_ai/src/ai_ship_cannon_controller.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 3c3c7b4b7..43cbe05a0 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -46,6 +46,15 @@ struct RS_LINE { CVECTOR vPos; uint32_t dwColor; + + RS_LINE() + { + } + RS_LINE(CVECTOR vPos, uint32_t dwColor) + { + this->vPos = vPos; + this->dwColor = dwColor; + } }; struct RS_SPRITE diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp index dd067a160..858a79c36 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp @@ -635,6 +635,12 @@ void AIShipCannonController::Realize(float fDeltaTime) { CVECTOR vPos; uint32_t dwColor; + + tr_vertex(CVECTOR vPos, uint32_t dwColor) + { + this->vPos = vPos; + this->dwColor = dwColor; + } }; static std::vector Verts; From 3b739567795e6e8aea2f3bbd8952bf99894f73a3 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Thu, 20 Jan 2022 17:36:47 +0300 Subject: [PATCH 56/59] [linux] add explicit constructors for FunctionLocalVariablem, Function, EventHandler and Define --- src/apps/engine/src/script_cache.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/apps/engine/src/script_cache.h b/src/apps/engine/src/script_cache.h index 778a130df..dfd4b2423 100644 --- a/src/apps/engine/src/script_cache.h +++ b/src/apps/engine/src/script_cache.h @@ -14,6 +14,12 @@ struct FunctionLocalVariable { LocalVarInfo info; bool is_extern; + + FunctionLocalVariable(LocalVarInfo info, bool is_extern) + { + this->info = info; + this->is_extern = is_extern; + } }; struct Function @@ -21,12 +27,24 @@ struct Function FuncInfo info; std::vector arguments; std::vector local_variables; + + Function(FuncInfo info, std::vector arguments) + { + this->info = info; + this->arguments = arguments; + } }; struct EventHandler { std::string event_name; std::string function_name; + + EventHandler(std::string event_name, std::string function_name) + { + this->event_name = event_name; + this->function_name = function_name; + } }; struct Define @@ -34,6 +52,13 @@ struct Define std::string name; uint32_t type; uintptr_t value; + + Define(std::string name, uint32_t type, uintptr_t value) + { + this->name = name; + this->type = type; + this->value = value; + } }; class Reader final From 36832288b5011046db681c50c44e4ee6c6edf35d Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Thu, 20 Jan 2022 19:37:37 +0300 Subject: [PATCH 57/59] [linux] fix explicit constructors for structs --- src/apps/engine/src/script_cache.h | 14 ++++---------- src/libs/common/include/dx9render.h | 4 +--- src/libs/location/src/lights.h | 4 +--- src/libs/location/src/supervisor.h | 10 ++-------- src/libs/sea_ai/src/ai_ship_cannon_controller.cpp | 4 +--- 5 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/apps/engine/src/script_cache.h b/src/apps/engine/src/script_cache.h index dfd4b2423..b5e312832 100644 --- a/src/apps/engine/src/script_cache.h +++ b/src/apps/engine/src/script_cache.h @@ -15,10 +15,8 @@ struct FunctionLocalVariable LocalVarInfo info; bool is_extern; - FunctionLocalVariable(LocalVarInfo info, bool is_extern) + FunctionLocalVariable(LocalVarInfo info, bool is_extern) : info(std::move(info)), is_extern(std::move(is_extern)) { - this->info = info; - this->is_extern = is_extern; } }; @@ -29,9 +27,8 @@ struct Function std::vector local_variables; Function(FuncInfo info, std::vector arguments) + : info(std::move(info)), arguments(std::move(arguments)) { - this->info = info; - this->arguments = arguments; } }; @@ -41,9 +38,8 @@ struct EventHandler std::string function_name; EventHandler(std::string event_name, std::string function_name) + : event_name(std::move(event_name)), function_name(std::move(function_name)) { - this->event_name = event_name; - this->function_name = function_name; } }; @@ -54,10 +50,8 @@ struct Define uintptr_t value; Define(std::string name, uint32_t type, uintptr_t value) + : name(std::move(name)), type(std::move(type)), value(std::move(value)) { - this->name = name; - this->type = type; - this->value = value; } }; diff --git a/src/libs/common/include/dx9render.h b/src/libs/common/include/dx9render.h index 43cbe05a0..1bdc802db 100644 --- a/src/libs/common/include/dx9render.h +++ b/src/libs/common/include/dx9render.h @@ -50,10 +50,8 @@ struct RS_LINE RS_LINE() { } - RS_LINE(CVECTOR vPos, uint32_t dwColor) + RS_LINE(CVECTOR vPos, uint32_t dwColor) : vPos(std::move(vPos)), dwColor(std::move(dwColor)) { - this->vPos = vPos; - this->dwColor = dwColor; } }; diff --git a/src/libs/location/src/lights.h b/src/libs/location/src/lights.h index 631923e1a..ee97e58ab 100644 --- a/src/libs/location/src/lights.h +++ b/src/libs/location/src/lights.h @@ -59,10 +59,8 @@ class Lights : public Entity int32_t id; int32_t light; - MovingLight(int32_t id, int32_t light) + MovingLight(int32_t id, int32_t light) : id(std::move(id)), light(std::move(light)) { - this->id = id; - this->light = light; } }; diff --git a/src/libs/location/src/supervisor.h b/src/libs/location/src/supervisor.h index 879f2d5e1..db2c22b01 100644 --- a/src/libs/location/src/supervisor.h +++ b/src/libs/location/src/supervisor.h @@ -34,12 +34,8 @@ class Supervisor float d2; // The square of the distance to the character in xz FindCharacter(Character *c, float dx, float dy, float dz, float d2) + : c(std::move(c)), dx(std::move(dx)), dy(std::move(dy)), dz(std::move(dz)), d2(std::move(d2)) { - this->c = c; - this->dx = dx; - this->dy = dy; - this->dz = dz; - this->d2 = d2; } }; @@ -48,10 +44,8 @@ class Supervisor Character *c; float lastTime; - CharacterEx(Character *c, float lastTime) + CharacterEx(Character *c, float lastTime) : c(std::move(c)), lastTime(std::move(lastTime)) { - this->c = c; - this->lastTime = lastTime; } }; diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp index 858a79c36..61d34229c 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp @@ -636,10 +636,8 @@ void AIShipCannonController::Realize(float fDeltaTime) CVECTOR vPos; uint32_t dwColor; - tr_vertex(CVECTOR vPos, uint32_t dwColor) + tr_vertex(CVECTOR vPos, uint32_t dwColor) : vPos(std::move(vPos)), dwColor(std::move(dwColor)) { - this->vPos = vPos; - this->dwColor = dwColor; } }; From d1c56c408b0294d9e27d2a1eb158a704a4d33034 Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 15 Mar 2022 08:11:41 +0300 Subject: [PATCH 58/59] [linux] add D3DXLoadSurfaceFromSurface implementation from WINE --- src/libs/common/include/storm_d3dx9.h | 20 + src/libs/common/include/storm_platform.h | 1 + src/libs/renderer/src/s_device.cpp | 9 +- src/libs/renderer/src/storm_d3dx9.cpp | 990 ++++++++++++++++++ .../xinterface/src/scr_shoter/scr_shoter.cpp | 5 +- 5 files changed, 1013 insertions(+), 12 deletions(-) create mode 100644 src/libs/common/include/storm_d3dx9.h create mode 100644 src/libs/renderer/src/storm_d3dx9.cpp diff --git a/src/libs/common/include/storm_d3dx9.h b/src/libs/common/include/storm_d3dx9.h new file mode 100644 index 000000000..1f9fd8d13 --- /dev/null +++ b/src/libs/common/include/storm_d3dx9.h @@ -0,0 +1,20 @@ +#pragma once +#ifndef _WIN32 + +#include +#include + +#define D3DX_DEFAULT ((UINT)-1) + +// Textures Methods + +HRESULT D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, + const PALETTEENTRY *dst_palette, const RECT *dst_rect, const void *src_memory, + D3DFORMAT src_format, UINT src_pitch, const PALETTEENTRY *src_palette, const RECT *src_rect, + DWORD filter, D3DCOLOR color_key); + +HRESULT D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface, + const PALETTEENTRY *dst_palette, const RECT *dst_rect, IDirect3DSurface9 *src_surface, + const PALETTEENTRY *src_palette, const RECT *src_rect, DWORD filter, D3DCOLOR color_key); + +#endif diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index 2193df477..aab7d8119 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -8,6 +8,7 @@ inline const char *convert_path_sep(const char *cPath) #include +#include "storm_d3dx9.h" #include "linux/winuser.h" #include "safe_str_lib.h" #undef EXTERN // fix for token.h:72:5: error: expected identifier EXTERN, diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index 0d7d40edb..d0ebf95b0 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -3328,11 +3328,7 @@ void DX9RENDER::MakeScreenShot() return; } -#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface if (CHECKD3DERR(D3DXLoadSurfaceFromSurface(surface, NULL, NULL, renderTarget, NULL, NULL, D3DX_DEFAULT, 0))) -#else - if (FAILED(d3d9->UpdateSurface(renderTarget, nullptr, surface, nullptr))) -#endif { surface->Release(); renderTarget->Release(); @@ -3845,12 +3841,9 @@ HRESULT DX9RENDER::GetSurfaceLevel(IDirect3DTexture9 *ppTexture, UINT Level, IDi HRESULT DX9RENDER::UpdateSurface(IDirect3DSurface9 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, IDirect3DSurface9 *pDestinationSurface, CONST POINT *pDestPointsArray) { -#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface return CHECKD3DERR(D3DXLoadSurfaceFromSurface(pDestinationSurface, nullptr, nullptr, pSourceSurface, nullptr, nullptr, D3DX_DEFAULT, 0)); -#else - return CHECKD3DERR(d3d9->UpdateSurface(pSourceSurface, pSourceRectsArray, pDestinationSurface, pDestPointsArray)); -#endif + //return CHECKD3DERR(d3d9->UpdateSurface(pSourceSurface, pSourceRectsArray, pDestinationSurface, pDestPointsArray)); } HRESULT DX9RENDER::StretchRect(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect, diff --git a/src/libs/renderer/src/storm_d3dx9.cpp b/src/libs/renderer/src/storm_d3dx9.cpp new file mode 100644 index 000000000..085971e11 --- /dev/null +++ b/src/libs/renderer/src/storm_d3dx9.cpp @@ -0,0 +1,990 @@ +#ifndef _WIN32 + +#include "storm_d3dx9.h" + +#define WARN(...) fprintf(stdout, __VA_ARGS__) + +///////////////////////// Parts from WINE source code for d3dx9 licensed under GPLv2 ///////////////////////// + +#define D3DX_FILTER_NONE 0x00000001 +#define D3DX_FILTER_POINT 0x00000002 +#define D3DX_FILTER_LINEAR 0x00000003 +#define D3DX_FILTER_TRIANGLE 0x00000004 +#define D3DX_FILTER_DITHER 0x00080000 + +#define D3DXERR_INVALIDDATA 0x88760b59 + +struct vec4 +{ + float x, y, z, w; +}; + +struct volume +{ + UINT width; + UINT height; + UINT depth; +}; + +enum format_type { + FORMAT_ARGB, /* unsigned */ + FORMAT_ARGBF16,/* float 16 */ + FORMAT_ARGBF, /* float */ + FORMAT_DXT, + FORMAT_INDEX, + FORMAT_UNKNOWN +}; + +struct pixel_format_desc { + D3DFORMAT format; + BYTE bits[4]; + BYTE shift[4]; + UINT bytes_per_pixel; + UINT block_width; + UINT block_height; + UINT block_byte_count; + enum format_type type; + void (*from_rgba)(const struct vec4 *src, struct vec4 *dst); + void (*to_rgba)(const struct vec4 *src, struct vec4 *dst, const PALETTEENTRY *palette); +}; + +/************************************************************ + * pixel format table providing info about number of bytes per pixel, + * number of bits per channel and format type. + * + * Call get_format_info to request information about a specific format. + */ +static const struct pixel_format_desc formats[] = +{ + /* format bpc shifts bpp blocks type from_rgba to_rgba */ + {D3DFMT_R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 3, 1, 1, 3, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A8R8G8B8, { 8, 8, 8, 8}, {24, 16, 8, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_X8R8G8B8, { 0, 8, 8, 8}, { 0, 16, 8, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A8B8G8R8, { 8, 8, 8, 8}, {24, 0, 8, 16}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_X8B8G8R8, { 0, 8, 8, 8}, { 0, 0, 8, 16}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_R5G6B5, { 0, 5, 6, 5}, { 0, 11, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_X1R5G5B5, { 0, 5, 5, 5}, { 0, 10, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A1R5G5B5, { 1, 5, 5, 5}, {15, 10, 5, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_R3G3B2, { 0, 3, 3, 2}, { 0, 5, 2, 0}, 1, 1, 1, 1, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A8R3G3B2, { 8, 3, 3, 2}, { 8, 5, 2, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A4R4G4B4, { 4, 4, 4, 4}, {12, 8, 4, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_X4R4G4B4, { 0, 4, 4, 4}, { 0, 8, 4, 0}, 2, 1, 1, 2, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A2R10G10B10, { 2, 10, 10, 10}, {30, 20, 10, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A2B10G10R10, { 2, 10, 10, 10}, {30, 0, 10, 20}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A16B16G16R16, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_G16R16, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, FORMAT_ARGB, NULL, NULL }, + {D3DFMT_A8, { 8, 0, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, NULL, NULL }, + //{D3DFMT_A8L8, { 8, 8, 0, 0}, { 8, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGB, la_from_rgba, la_to_rgba}, + //{D3DFMT_A4L4, { 4, 4, 0, 0}, { 4, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, la_from_rgba, la_to_rgba}, + //{D3DFMT_L8, { 0, 8, 0, 0}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_ARGB, la_from_rgba, la_to_rgba}, + //{D3DFMT_L16, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGB, la_from_rgba, la_to_rgba}, + {D3DFMT_DXT1, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 8, FORMAT_DXT, NULL, NULL }, + {D3DFMT_DXT2, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, + {D3DFMT_DXT3, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, + {D3DFMT_DXT4, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, + {D3DFMT_DXT5, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 1, 4, 4, 16, FORMAT_DXT, NULL, NULL }, + {D3DFMT_R16F, { 0, 16, 0, 0}, { 0, 0, 0, 0}, 2, 1, 1, 2, FORMAT_ARGBF16, NULL, NULL }, + {D3DFMT_G16R16F, { 0, 16, 16, 0}, { 0, 0, 16, 0}, 4, 1, 1, 4, FORMAT_ARGBF16, NULL, NULL }, + {D3DFMT_A16B16G16R16F, {16, 16, 16, 16}, {48, 0, 16, 32}, 8, 1, 1, 8, FORMAT_ARGBF16, NULL, NULL }, + {D3DFMT_R32F, { 0, 32, 0, 0}, { 0, 0, 0, 0}, 4, 1, 1, 4, FORMAT_ARGBF, NULL, NULL }, + {D3DFMT_G32R32F, { 0, 32, 32, 0}, { 0, 0, 32, 0}, 8, 1, 1, 8, FORMAT_ARGBF, NULL, NULL }, + {D3DFMT_A32B32G32R32F, {32, 32, 32, 32}, {96, 0, 32, 64}, 16, 1, 1, 16, FORMAT_ARGBF, NULL, NULL }, + //{D3DFMT_P8, { 8, 8, 8, 8}, { 0, 0, 0, 0}, 1, 1, 1, 1, FORMAT_INDEX, NULL, index_to_rgba}, + /* marks last element */ + {D3DFMT_UNKNOWN, { 0, 0, 0, 0}, { 0, 0, 0, 0}, 0, 1, 1, 0, FORMAT_UNKNOWN, NULL, NULL }, +}; + +/************************************************************ + * get_format_info + * + * Returns information about the specified format. + * If the format is unsupported, it's filled with the D3DFMT_UNKNOWN desc. + * + * PARAMS + * format [I] format whose description is queried + * + */ +const struct pixel_format_desc *get_format_info(D3DFORMAT format) +{ + unsigned int i = 0; + while(formats[i].format != format && formats[i].format != D3DFMT_UNKNOWN) i++; + if (formats[i].format == D3DFMT_UNKNOWN) { + WARN("Unknown format %#x.\n", format); + } + return &formats[i]; +} + +static inline BOOL SetRect(RECT *rect, INT left, INT top, INT right, INT bottom) +{ + if (!rect) return FALSE; + rect->left = left; + rect->right = right; + rect->top = top; + rect->bottom = bottom; + return TRUE; +} + +HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock, + IDirect3DSurface9 **temp_surface, bool write) +{ + unsigned int width, height; + IDirect3DDevice9 *device; + D3DSURFACE_DESC desc; + DWORD lock_flag; + HRESULT hr; + + lock_flag = write ? 0 : D3DLOCK_READONLY; + *temp_surface = NULL; + if (FAILED(hr = IDirect3DSurface9_LockRect(surface, lock, surface_rect, lock_flag))) + { + IDirect3DSurface9_GetDevice(surface, &device); + IDirect3DSurface9_GetDesc(surface, &desc); + + if (surface_rect) + { + width = surface_rect->right - surface_rect->left; + height = surface_rect->bottom - surface_rect->top; + } + else + { + width = desc.Width; + height = desc.Height; + } + + hr = write ? IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, + desc.Format, D3DPOOL_SYSTEMMEM, temp_surface, NULL) + : IDirect3DDevice9_CreateRenderTarget(device, width, height, + desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, temp_surface, NULL); + if (FAILED(hr)) + { + WARN("Failed to create temporary surface, surface %p, format %#x," + " usage %#x, pool %#x, write %#x, width %u, height %u.\n", + surface, desc.Format, desc.Usage, desc.Pool, write, width, height); + IDirect3DDevice9_Release(device); + return hr; + } + + if (write || SUCCEEDED(hr = IDirect3DDevice9_StretchRect(device, surface, surface_rect, + *temp_surface, NULL, D3DTEXF_NONE))) + hr = IDirect3DSurface9_LockRect(*temp_surface, lock, NULL, lock_flag); + + IDirect3DDevice9_Release(device); + if (FAILED(hr)) + { + WARN("Failed to lock surface %p, write %#x, usage %#x, pool %#x.\n", + surface, write, desc.Usage, desc.Pool); + IDirect3DSurface9_Release(*temp_surface); + *temp_surface = NULL; + return hr; + } + } + return hr; +} + +HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, + IDirect3DSurface9 *temp_surface, bool update) +{ + IDirect3DDevice9 *device; + POINT surface_point; + HRESULT hr; + + if (!temp_surface) + { + hr = IDirect3DSurface9_UnlockRect(surface); + return hr; + } + + hr = IDirect3DSurface9_UnlockRect(temp_surface); + if (update) + { + if (surface_rect) + { + surface_point.x = surface_rect->left; + surface_point.y = surface_rect->top; + } + else + { + surface_point.x = 0; + surface_point.y = 0; + } + IDirect3DSurface9_GetDevice(surface, &device); + if (FAILED(hr = IDirect3DDevice9_UpdateSurface(device, temp_surface, NULL, surface, &surface_point))) + WARN("Updating surface failed, hr %#x, surface %p, temp_surface %p.\n", + hr, surface, temp_surface); + IDirect3DDevice9_Release(device); + } + IDirect3DSurface9_Release(temp_surface); + return hr; +} + +/************************************************************ + * copy_pixels + * + * Copies the source buffer to the destination buffer. + * Works for any pixel format. + * The source and the destination must be block-aligned. + */ +void copy_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, + BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, const struct volume *size, + const struct pixel_format_desc *format) +{ + UINT row, slice; + BYTE *dst_addr; + const BYTE *src_addr; + UINT row_block_count = (size->width + format->block_width - 1) / format->block_width; + UINT row_count = (size->height + format->block_height - 1) / format->block_height; + + for (slice = 0; slice < size->depth; slice++) + { + src_addr = src + slice * src_slice_pitch; + dst_addr = dst + slice * dst_slice_pitch; + + for (row = 0; row < row_count; row++) + { + memcpy(dst_addr, src_addr, row_block_count * format->block_byte_count); + src_addr += src_row_pitch; + dst_addr += dst_row_pitch; + } + } +} + +static inline bool is_conversion_from_supported(const struct pixel_format_desc *format) +{ + if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16 + || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT) + return TRUE; + return !!format->to_rgba; +} + +static inline bool is_conversion_to_supported(const struct pixel_format_desc *format) +{ + if (format->type == FORMAT_ARGB || format->type == FORMAT_ARGBF16 + || format->type == FORMAT_ARGBF || format->type == FORMAT_DXT) + return TRUE; + return !!format->from_rgba; +} + +/************************************************************ + * helper functions for D3DXLoadSurfaceFromMemory + */ +struct argb_conversion_info +{ + const struct pixel_format_desc *srcformat; + const struct pixel_format_desc *destformat; + DWORD srcshift[4], destshift[4]; + DWORD srcmask[4], destmask[4]; + BOOL process_channel[4]; + DWORD channelmask; +}; + +#ifndef NOMINMAX +#define NOMINMAX +#undef min +#undef max +#endif + +inline int min(int x,int y){ return x < y ? x : y; } +inline float min(float x,float y){ return x < y ? x : y; } +inline double min(double x,double y){ return x < y ? x : y; } + +inline int max(int x,int y){ return x > y ? x : y; } +inline float max(float x,float y){ return x > y ? x : y; } +inline double max(double x,double y){ return x > y ? x : y; } + +static void init_argb_conversion_info(const struct pixel_format_desc *srcformat, const struct pixel_format_desc *destformat, struct argb_conversion_info *info) +{ + UINT i; + //ZeroMemory(info->process_channel, 4 * sizeof(BOOL)); + memset(info->process_channel, 0, 4 * sizeof(bool)); + info->channelmask = 0; + + info->srcformat = srcformat; + info->destformat = destformat; + + for(i = 0;i < 4;i++) { + /* srcshift is used to extract the _relevant_ components */ + info->srcshift[i] = srcformat->shift[i] + max( srcformat->bits[i] - destformat->bits[i], 0); + + /* destshift is used to move the components to the correct position */ + info->destshift[i] = destformat->shift[i] + max(destformat->bits[i] - srcformat->bits[i], 0); + + info->srcmask[i] = ((1 << srcformat->bits[i]) - 1) << srcformat->shift[i]; + info->destmask[i] = ((1 << destformat->bits[i]) - 1) << destformat->shift[i]; + + /* channelmask specifies bits which aren't used in the source format but in the destination one */ + if(destformat->bits[i]) { + if(srcformat->bits[i]) info->process_channel[i] = TRUE; + else info->channelmask |= info->destmask[i]; + } + } +} + +/************************************************************ + * get_relevant_argb_components + * + * Extracts the relevant components from the source color and + * drops the less significant bits if they aren't used by the destination format. + */ +static void get_relevant_argb_components(const struct argb_conversion_info *info, const BYTE *col, DWORD *out) +{ + unsigned int i, j; + unsigned int component, mask; + + for (i = 0; i < 4; ++i) + { + if (!info->process_channel[i]) + continue; + + component = 0; + mask = info->srcmask[i]; + for (j = 0; j < 4 && mask; ++j) + { + if (info->srcshift[i] < j * 8) + component |= (col[j] & mask) << (j * 8 - info->srcshift[i]); + else + component |= (col[j] & mask) >> (info->srcshift[i] - j * 8); + mask >>= 8; + } + out[i] = component; + } +} + +/************************************************************ + * make_argb_color + * + * Recombines the output of get_relevant_argb_components and converts + * it to the destination format. + */ +static DWORD make_argb_color(const struct argb_conversion_info *info, const DWORD *in) +{ + UINT i; + DWORD val = 0; + + for(i = 0;i < 4;i++) { + if(info->process_channel[i]) { + /* necessary to make sure that e.g. an X4R4G4B4 white maps to an R8G8B8 white instead of 0xf0f0f0 */ + signed int shift; + for(shift = info->destshift[i]; shift > info->destformat->shift[i]; shift -= info->srcformat->bits[i]) val |= in[i] << shift; + val |= (in[i] >> (info->destformat->shift[i] - shift)) << info->destformat->shift[i]; + } + } + val |= info->channelmask; /* new channels are set to their maximal value */ + return val; +} + +/* It doesn't work for components bigger than 32 bits (or somewhat smaller but unaligned). */ +static void format_to_vec4(const struct pixel_format_desc *format, const BYTE *src, struct vec4 *dst) +{ + DWORD mask, tmp; + unsigned int c; + + for (c = 0; c < 4; ++c) + { + static const unsigned int component_offsets[4] = {3, 0, 1, 2}; + float *dst_component = (float *)dst + component_offsets[c]; + + if (format->bits[c]) + { + mask = ~0u >> (32 - format->bits[c]); + + memcpy(&tmp, src + format->shift[c] / 8, + min(sizeof(DWORD), (format->shift[c] % 8 + format->bits[c] + 7) / 8)); + + if (format->type == FORMAT_ARGBF16) + WARN("Unimplemented for FORMAT_ARGBF16"); + //*dst_component = float_16_to_32(tmp); + else if (format->type == FORMAT_ARGBF) + *dst_component = *(float *)&tmp; + else + *dst_component = (float)((tmp >> format->shift[c] % 8) & mask) / mask; + } + else + *dst_component = 1.0f; + } +} + +/* It doesn't work for components bigger than 32 bits. */ +static void format_from_vec4(const struct pixel_format_desc *format, const struct vec4 *src, BYTE *dst) +{ + DWORD v, mask32; + unsigned int c, i; + + memset(dst, 0, format->bytes_per_pixel); + + for (c = 0; c < 4; ++c) + { + static const unsigned int component_offsets[4] = {3, 0, 1, 2}; + const float src_component = *((const float *)src + component_offsets[c]); + + if (!format->bits[c]) + continue; + + mask32 = ~0u >> (32 - format->bits[c]); + + if (format->type == FORMAT_ARGBF16) + WARN("Unimplemented for FORMAT_ARGBF16"); + //v = float_32_to_16(src_component); + else if (format->type == FORMAT_ARGBF) + v = *(DWORD *)&src_component; + else + v = (DWORD)(src_component * ((1 << format->bits[c]) - 1) + 0.5f); + + for (i = format->shift[c] / 8 * 8; i < format->shift[c] + format->bits[c]; i += 8) + { + BYTE mask, byte; + + if (format->shift[c] > i) + { + mask = mask32 << (format->shift[c] - i); + byte = (v << (format->shift[c] - i)) & mask; + } + else + { + mask = mask32 >> (i - format->shift[c]); + byte = (v >> (i - format->shift[c])) & mask; + } + dst[i / 8] |= byte; + } + } +} + +/************************************************************ + * convert_argb_pixels + * + * Copies the source buffer to the destination buffer, performing + * any necessary format conversion and color keying. + * Pixels outsize the source rect are blacked out. + */ +void convert_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, + const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, + const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, + const PALETTEENTRY *palette) +{ + struct argb_conversion_info conv_info, ck_conv_info; + const struct pixel_format_desc *ck_format = NULL; + DWORD channels[4]; + UINT min_width, min_height, min_depth; + UINT x, y, z; + + memset(channels, 0, sizeof(channels)); + init_argb_conversion_info(src_format, dst_format, &conv_info); + + min_width = std::min(src_size->width, dst_size->width); + min_height = std::min(src_size->height, dst_size->height); + min_depth = std::min(src_size->depth, dst_size->depth); + + if (color_key) + { + /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */ + ck_format = get_format_info(D3DFMT_A8R8G8B8); + init_argb_conversion_info(src_format, ck_format, &ck_conv_info); + } + + for (z = 0; z < min_depth; z++) { + const BYTE *src_slice_ptr = src + z * src_slice_pitch; + BYTE *dst_slice_ptr = dst + z * dst_slice_pitch; + + for (y = 0; y < min_height; y++) { + const BYTE *src_ptr = src_slice_ptr + y * src_row_pitch; + BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch; + + for (x = 0; x < min_width; x++) { + if (!src_format->to_rgba && !dst_format->from_rgba + && src_format->type == dst_format->type + && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) + { + DWORD val; + + get_relevant_argb_components(&conv_info, src_ptr, channels); + val = make_argb_color(&conv_info, channels); + + if (color_key) + { + DWORD ck_pixel; + + get_relevant_argb_components(&ck_conv_info, src_ptr, channels); + ck_pixel = make_argb_color(&ck_conv_info, channels); + if (ck_pixel == color_key) + val &= ~conv_info.destmask[0]; + } + if (dst_format->format == D3DFMT_Q8W8V8U8) { + WARN("Unimplemented for D3DFMT_Q8W8V8U8"); + //val = from_rgba_qwvu(val); + } + memcpy(dst_ptr, &val, dst_format->bytes_per_pixel); + } + else + { + struct vec4 color, tmp; + + format_to_vec4(src_format, src_ptr, &color); + if (src_format->to_rgba) + src_format->to_rgba(&color, &tmp, palette); + else + tmp = color; + + if (ck_format) + { + DWORD ck_pixel; + + format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel); + if (ck_pixel == color_key) + tmp.w = 0.0f; + } + + if (dst_format->from_rgba) + dst_format->from_rgba(&tmp, &color); + else + color = tmp; + + format_from_vec4(dst_format, &color, dst_ptr); + } + + src_ptr += src_format->bytes_per_pixel; + dst_ptr += dst_format->bytes_per_pixel; + } + + if (src_size->width < dst_size->width) /* black out remaining pixels */ + memset(dst_ptr, 0, dst_format->bytes_per_pixel * (dst_size->width - src_size->width)); + } + + if (src_size->height < dst_size->height) /* black out remaining pixels */ + memset(dst + src_size->height * dst_row_pitch, 0, dst_row_pitch * (dst_size->height - src_size->height)); + } + if (src_size->depth < dst_size->depth) /* black out remaining pixels */ + memset(dst + src_size->depth * dst_slice_pitch, 0, dst_slice_pitch * (dst_size->depth - src_size->depth)); +} + +/************************************************************ + * point_filter_argb_pixels + * + * Copies the source buffer to the destination buffer, performing + * any necessary format conversion, color keying and stretching + * using a point filter. + */ +void point_filter_argb_pixels(const BYTE *src, UINT src_row_pitch, UINT src_slice_pitch, const struct volume *src_size, + const struct pixel_format_desc *src_format, BYTE *dst, UINT dst_row_pitch, UINT dst_slice_pitch, + const struct volume *dst_size, const struct pixel_format_desc *dst_format, D3DCOLOR color_key, + const PALETTEENTRY *palette) +{ + struct argb_conversion_info conv_info, ck_conv_info; + const struct pixel_format_desc *ck_format = NULL; + DWORD channels[4]; + UINT x, y, z; + + memset(channels, 0, sizeof(channels)); + init_argb_conversion_info(src_format, dst_format, &conv_info); + + if (color_key) + { + /* Color keys are always represented in D3DFMT_A8R8G8B8 format. */ + ck_format = get_format_info(D3DFMT_A8R8G8B8); + init_argb_conversion_info(src_format, ck_format, &ck_conv_info); + } + + for (z = 0; z < dst_size->depth; z++) + { + BYTE *dst_slice_ptr = dst + z * dst_slice_pitch; + const BYTE *src_slice_ptr = src + src_slice_pitch * (z * src_size->depth / dst_size->depth); + + for (y = 0; y < dst_size->height; y++) + { + BYTE *dst_ptr = dst_slice_ptr + y * dst_row_pitch; + const BYTE *src_row_ptr = src_slice_ptr + src_row_pitch * (y * src_size->height / dst_size->height); + + for (x = 0; x < dst_size->width; x++) + { + const BYTE *src_ptr = src_row_ptr + (x * src_size->width / dst_size->width) * src_format->bytes_per_pixel; + + if (!src_format->to_rgba && !dst_format->from_rgba + && src_format->type == dst_format->type + && src_format->bytes_per_pixel <= 4 && dst_format->bytes_per_pixel <= 4) + { + DWORD val; + + get_relevant_argb_components(&conv_info, src_ptr, channels); + val = make_argb_color(&conv_info, channels); + + if (color_key) + { + DWORD ck_pixel; + + get_relevant_argb_components(&ck_conv_info, src_ptr, channels); + ck_pixel = make_argb_color(&ck_conv_info, channels); + if (ck_pixel == color_key) + val &= ~conv_info.destmask[0]; + } + memcpy(dst_ptr, &val, dst_format->bytes_per_pixel); + } + else + { + struct vec4 color, tmp; + + format_to_vec4(src_format, src_ptr, &color); + if (src_format->to_rgba) + src_format->to_rgba(&color, &tmp, palette); + else + tmp = color; + + if (ck_format) + { + DWORD ck_pixel; + + format_from_vec4(ck_format, &tmp, (BYTE *)&ck_pixel); + if (ck_pixel == color_key) + tmp.w = 0.0f; + } + + if (dst_format->from_rgba) + dst_format->from_rgba(&tmp, &color); + else + color = tmp; + + format_from_vec4(dst_format, &color, dst_ptr); + } + + dst_ptr += dst_format->bytes_per_pixel; + } + } + } +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +/************************************************************ + * WINE doc: + * D3DXLoadSurfaceFromMemory + * + * Loads data from a given memory chunk into a surface, + * applying any of the specified filters. + * + * PARAMS + * pDestSurface [I] pointer to the surface + * pDestPalette [I] palette to use + * pDestRect [I] to be filled area of the surface + * pSrcMemory [I] pointer to the source data + * SrcFormat [I] format of the source pixel data + * SrcPitch [I] number of bytes in a row + * pSrcPalette [I] palette used in the source image + * pSrcRect [I] area of the source data to load + * dwFilter [I] filter to apply on stretching + * Colorkey [I] colorkey + * + * RETURNS + * Success: D3D_OK, if we successfully load the pixel data into our surface or + * if pSrcMemory is NULL but the other parameters are valid + * Failure: D3DERR_INVALIDCALL, if pDestSurface, SrcPitch or pSrcRect is NULL or + * if SrcFormat is an invalid format (other than D3DFMT_UNKNOWN) or + * if DestRect is invalid + * D3DXERR_INVALIDDATA, if we fail to lock pDestSurface + * E_FAIL, if SrcFormat is D3DFMT_UNKNOWN or the dimensions of pSrcRect are invalid + * + * NOTES + * pSrcRect specifies the dimensions of the source data; + * negative values for pSrcRect are allowed as we're only looking at the width and height anyway. + * + */ +HRESULT D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, + const PALETTEENTRY *dst_palette, const RECT *dst_rect, const void *src_memory, + D3DFORMAT src_format, UINT src_pitch, const PALETTEENTRY *src_palette, const RECT *src_rect, + DWORD filter, D3DCOLOR color_key) +{ + const struct pixel_format_desc *srcformatdesc, *destformatdesc; + struct volume src_size, dst_size, dst_size_aligned; + RECT dst_rect_temp, dst_rect_aligned; + IDirect3DSurface9 *surface; + D3DSURFACE_DESC surfdesc; + D3DLOCKED_RECT lockrect; + HRESULT hr; + + if (!dst_surface || !src_memory || !src_rect) + { + return D3DERR_INVALIDCALL; + } + if (src_format == D3DFMT_UNKNOWN + || src_rect->left >= src_rect->right + || src_rect->top >= src_rect->bottom) + { + return E_FAIL; + } + + srcformatdesc = get_format_info(src_format); + if (srcformatdesc->type == FORMAT_UNKNOWN) + { + WARN("Unsupported format %#x.\n", src_format); + return E_NOTIMPL; + } + + src_size.width = src_rect->right - src_rect->left; + src_size.height = src_rect->bottom - src_rect->top; + src_size.depth = 1; + + IDirect3DSurface9_GetDesc(dst_surface, &surfdesc); + destformatdesc = get_format_info(surfdesc.Format); + if (!dst_rect) + { + dst_rect = &dst_rect_temp; + dst_rect_temp.left = 0; + dst_rect_temp.top = 0; + dst_rect_temp.right = surfdesc.Width; + dst_rect_temp.bottom = surfdesc.Height; + } + else + { + if (dst_rect->left > dst_rect->right || dst_rect->right > surfdesc.Width + || dst_rect->top > dst_rect->bottom || dst_rect->bottom > surfdesc.Height + || dst_rect->left < 0 || dst_rect->top < 0) + { + WARN("Invalid dst_rect specified.\n"); + return D3DERR_INVALIDCALL; + } + if (dst_rect->left == dst_rect->right || dst_rect->top == dst_rect->bottom) + { + WARN("Empty dst_rect specified.\n"); + return D3D_OK; + } + } + + dst_rect_aligned = *dst_rect; + if (dst_rect_aligned.left & (destformatdesc->block_width - 1)) + dst_rect_aligned.left = dst_rect_aligned.left & ~(destformatdesc->block_width - 1); + if (dst_rect_aligned.top & (destformatdesc->block_height - 1)) + dst_rect_aligned.top = dst_rect_aligned.top & ~(destformatdesc->block_height - 1); + if (dst_rect_aligned.right & (destformatdesc->block_width - 1) && dst_rect_aligned.right != surfdesc.Width) + dst_rect_aligned.right = std::min((dst_rect_aligned.right + destformatdesc->block_width - 1) + & ~(destformatdesc->block_width - 1), surfdesc.Width); + if (dst_rect_aligned.bottom & (destformatdesc->block_height - 1) && dst_rect_aligned.bottom != surfdesc.Height) + dst_rect_aligned.bottom = std::min((dst_rect_aligned.bottom + destformatdesc->block_height - 1) + & ~(destformatdesc->block_height - 1), surfdesc.Height); + + dst_size.width = dst_rect->right - dst_rect->left; + dst_size.height = dst_rect->bottom - dst_rect->top; + dst_size.depth = 1; + dst_size_aligned.width = dst_rect_aligned.right - dst_rect_aligned.left; + dst_size_aligned.height = dst_rect_aligned.bottom - dst_rect_aligned.top; + dst_size_aligned.depth = 1; + + if (filter == D3DX_DEFAULT) + filter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER; + + if (FAILED(hr = lock_surface(dst_surface, &dst_rect_aligned, &lockrect, &surface, TRUE))) + return hr; + + src_memory = (BYTE *)src_memory + src_rect->top / srcformatdesc->block_height * src_pitch + + src_rect->left / srcformatdesc->block_width * srcformatdesc->block_byte_count; + + if (src_format == surfdesc.Format + && dst_size.width == src_size.width + && dst_size.height == src_size.height + && color_key == 0 + && !(src_rect->left & (srcformatdesc->block_width - 1)) + && !(src_rect->top & (srcformatdesc->block_height - 1)) + && !(dst_rect->left & (destformatdesc->block_width - 1)) + && !(dst_rect->top & (destformatdesc->block_height - 1))) + { + copy_pixels(static_cast(src_memory), src_pitch, 0, static_cast(lockrect.pBits), + lockrect.Pitch, 0, &src_size, srcformatdesc); + } + else /* Stretching or format conversion. */ + { + const struct pixel_format_desc *dst_format; + unsigned int dst_pitch; + BYTE *dst_mem; + + if (!is_conversion_from_supported(srcformatdesc) + || !is_conversion_to_supported(destformatdesc)) + { + WARN("Unsupported format conversion %#x -> %#x.\n", src_format, surfdesc.Format); + unlock_surface(dst_surface, &dst_rect_aligned, surface, FALSE); + return E_NOTIMPL; + } + + if (srcformatdesc->type == FORMAT_DXT || destformatdesc->type == FORMAT_DXT) + { + WARN("Src/Dst FORMAT_DXT unsupported\n"); + return E_NOTIMPL; + } + else + { + dst_mem = static_cast(lockrect.pBits); + dst_pitch = lockrect.Pitch; + dst_format = destformatdesc; + } + + if ((filter & 0xf) == D3DX_FILTER_NONE || destformatdesc->format == D3DFMT_Q8W8V8U8) + { + convert_argb_pixels(static_cast(src_memory), src_pitch, 0, &src_size, srcformatdesc, + dst_mem, dst_pitch, 0, &dst_size, dst_format, color_key, src_palette); + } + else /* if ((filter & 0xf) == D3DX_FILTER_POINT) */ + { + if ((filter & 0xf) != D3DX_FILTER_POINT) { + WARN("Unhandled filter %#x.\n", filter); + } + + /* Always apply a point filter until D3DX_FILTER_LINEAR, + * D3DX_FILTER_TRIANGLE and D3DX_FILTER_BOX are implemented. */ + point_filter_argb_pixels(static_cast(src_memory), src_pitch, 0, &src_size, srcformatdesc, + dst_mem, dst_pitch, 0, &dst_size, dst_format, color_key, src_palette); + } + } + + return unlock_surface(dst_surface, &dst_rect_aligned, surface, TRUE); +} + +/************************************************************ + * WINE doc: + * D3DXLoadSurfaceFromSurface + * + * Copies the contents from one surface to another, performing any required + * format conversion, resizing or filtering. + * + * PARAMS + * pDestSurface [I] pointer to the destination surface + * pDestPalette [I] palette to use + * pDestRect [I] to be filled area of the surface + * pSrcSurface [I] pointer to the source surface + * pSrcPalette [I] palette used for the source surface + * pSrcRect [I] area of the source data to load + * dwFilter [I] filter to apply on resizing + * Colorkey [I] any ARGB value or 0 to disable color-keying + * + * RETURNS + * Success: D3D_OK + * Failure: D3DERR_INVALIDCALL, if pDestSurface or pSrcSurface is NULL + * D3DXERR_INVALIDDATA, if one of the surfaces is not lockable + * + */ +HRESULT D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface, + const PALETTEENTRY *dst_palette, const RECT *dst_rect, IDirect3DSurface9 *src_surface, + const PALETTEENTRY *src_palette, const RECT *src_rect, DWORD filter, D3DCOLOR color_key) +{ + const struct pixel_format_desc *src_format_desc, *dst_format_desc; + D3DSURFACE_DESC src_desc, dst_desc; + struct volume src_size, dst_size; + IDirect3DSurface9 *temp_surface; + D3DTEXTUREFILTERTYPE d3d_filter; + IDirect3DDevice9 *device; + D3DLOCKED_RECT lock; + RECT dst_rect_temp; + HRESULT hr; + RECT s; + + /* + TRACE("dst_surface %p, dst_palette %p, dst_rect %s, src_surface %p, " + "src_palette %p, src_rect %s, filter %#x, color_key 0x%08x.\n", + dst_surface, dst_palette, wine_dbgstr_rect(dst_rect), src_surface, + src_palette, wine_dbgstr_rect(src_rect), filter, color_key); + */ + + if (!dst_surface || !src_surface) + return D3DERR_INVALIDCALL; + + IDirect3DSurface9_GetDesc(src_surface, &src_desc); + src_format_desc = get_format_info(src_desc.Format); + if (!src_rect) + { + SetRect(&s, 0, 0, src_desc.Width, src_desc.Height); + src_rect = &s; + } + else if (src_rect->left == src_rect->right || src_rect->top == src_rect->bottom) + { + WARN("Empty src_rect specified.\n"); + return filter == D3DX_FILTER_NONE ? D3D_OK : E_FAIL; + } + else if (src_rect->left > src_rect->right || src_rect->right > src_desc.Width + || src_rect->left < 0 || src_rect->left > src_desc.Width + || src_rect->top > src_rect->bottom || src_rect->bottom > src_desc.Height + || src_rect->top < 0 || src_rect->top > src_desc.Height) + { + WARN("Invalid src_rect specified.\n"); + return D3DERR_INVALIDCALL; + } + + src_size.width = src_rect->right - src_rect->left; + src_size.height = src_rect->bottom - src_rect->top; + src_size.depth = 1; + + IDirect3DSurface9_GetDesc(dst_surface, &dst_desc); + dst_format_desc = get_format_info(dst_desc.Format); + if (!dst_rect) + { + SetRect(&dst_rect_temp, 0, 0, dst_desc.Width, dst_desc.Height); + dst_rect = &dst_rect_temp; + } + else if (dst_rect->left == dst_rect->right || dst_rect->top == dst_rect->bottom) + { + WARN("Empty dst_rect specified.\n"); + return filter == D3DX_FILTER_NONE ? D3D_OK : E_FAIL; + } + else if (dst_rect->left > dst_rect->right || dst_rect->right > dst_desc.Width + || dst_rect->left < 0 || dst_rect->left > dst_desc.Width + || dst_rect->top > dst_rect->bottom || dst_rect->bottom > dst_desc.Height + || dst_rect->top < 0 || dst_rect->top > dst_desc.Height) + { + WARN("Invalid dst_rect specified.\n"); + return D3DERR_INVALIDCALL; + } + + dst_size.width = dst_rect->right - dst_rect->left; + dst_size.height = dst_rect->bottom - dst_rect->top; + dst_size.depth = 1; + + if (!dst_palette && !src_palette && !color_key) + { + if (src_desc.Format == dst_desc.Format + && dst_size.width == src_size.width + && dst_size.height == src_size.height + && color_key == 0 + && !(src_rect->left & (src_format_desc->block_width - 1)) + && !(src_rect->top & (src_format_desc->block_height - 1)) + && !(dst_rect->left & (dst_format_desc->block_width - 1)) + && !(dst_rect->top & (dst_format_desc->block_height - 1))) + { + d3d_filter = D3DTEXF_NONE; + } + else + { + switch (filter) + { + case D3DX_FILTER_NONE: + d3d_filter = D3DTEXF_NONE; + break; + + case D3DX_FILTER_POINT: + d3d_filter = D3DTEXF_POINT; + break; + + case D3DX_FILTER_LINEAR: + d3d_filter = D3DTEXF_LINEAR; + break; + + default: + d3d_filter = D3DTEXF_FORCE_DWORD; + break; + } + } + + if (d3d_filter != D3DTEXF_FORCE_DWORD) + { + IDirect3DSurface9_GetDevice(src_surface, &device); + hr = IDirect3DDevice9_StretchRect(device, src_surface, src_rect, dst_surface, dst_rect, d3d_filter); + IDirect3DDevice9_Release(device); + if (SUCCEEDED(hr)) + return D3D_OK; + } + } + + if (FAILED(lock_surface(src_surface, NULL, &lock, &temp_surface, FALSE))) + return D3DXERR_INVALIDDATA; + + hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, lock.pBits, + src_desc.Format, lock.Pitch, src_palette, src_rect, filter, color_key); + + if (FAILED(unlock_surface(src_surface, NULL, temp_surface, FALSE))) + return D3DXERR_INVALIDDATA; + + return hr; +} + +#endif diff --git a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp index e42e87307..b9fc24f8c 100644 --- a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp +++ b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp @@ -222,11 +222,8 @@ bool SCRSHOTER::MakeScreenShot() IDirect3DSurface9 *pSurf1 = nullptr, *pSurf2 = nullptr; rs->GetSurfaceLevel(texture_, 0, &pSurf1); rs->GetSurfaceLevel(pScrShotTex, 0, &pSurf2); -#ifdef _WIN32 // FIX_LINUX D3DXLoadSurfaceFromSurface + // rs->UpdateSurface(pSurf2,null,0,pSurf1,null); hr = D3DXLoadSurfaceFromSurface(pSurf1, nullptr, nullptr, pSurf2, nullptr, nullptr, D3DX_DEFAULT, 0); -#else - hr = rs->UpdateSurface(pSurf2, nullptr, 0, pSurf1, nullptr); -#endif if (pSurf1) rs->Release(pSurf1); if (pSurf2) From 0bfae099ba1af032f4f040bd3dfb8db8197230ae Mon Sep 17 00:00:00 2001 From: Aleksey Komarov Date: Tue, 15 Mar 2022 17:50:03 +0300 Subject: [PATCH 59/59] [linux] first version for resource paths handling on linux Based on this file (GPLv3): https://github.com/KD-lab-Open-Source/Perimeter/blob/d131aa26dce1db187416718610baa09d53c65de8/Source/XTool/XUTIL/XUTIL.CPP --- src/apps/engine/src/file_service.cpp | 127 +++++++++++++++++++++-- src/apps/engine/src/file_service.h | 8 ++ src/libs/common/include/storm_platform.h | 8 +- src/libs/common/include/v_file_service.h | 4 + src/libs/renderer/src/s_device.cpp | 2 +- 5 files changed, 138 insertions(+), 11 deletions(-) diff --git a/src/apps/engine/src/file_service.cpp b/src/apps/engine/src/file_service.cpp index 27ade92cf..486d78960 100644 --- a/src/apps/engine/src/file_service.cpp +++ b/src/apps/engine/src/file_service.cpp @@ -32,6 +32,8 @@ FILE_SERVICE::FILE_SERVICE() Max_File_Index = 0; for (uint32_t n = 0; n < _MAX_OPEN_INI_FILES; n++) OpenFiles[n] = nullptr; + if (ResourcePathsFirstScan) + ScanResourcePaths(); } FILE_SERVICE::~FILE_SERVICE() @@ -41,7 +43,7 @@ FILE_SERVICE::~FILE_SERVICE() std::fstream FILE_SERVICE::_CreateFile(const char *filename, std::ios::openmode mode) { - const auto path = filename ? std::filesystem::u8path(convert_path_sep(filename)) : std::filesystem::path(); + const auto path = filename ? std::filesystem::u8path(ConvertPathResource(filename)) : std::filesystem::path(); std::fstream fileS(path, mode); return fileS; } @@ -58,7 +60,7 @@ void FILE_SERVICE::_SetFilePointer(std::fstream &fileS, std::streamoff off, std: bool FILE_SERVICE::_DeleteFile(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(filename)); return std::filesystem::remove(path); } @@ -94,7 +96,7 @@ bool FILE_SERVICE::_ReadFile(std::fstream &fileS, void *s, std::streamsize count bool FILE_SERVICE::_FileOrDirectoryExists(const char *p) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(p)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(p)); auto ec = std::error_code{}; bool result = std::filesystem::exists(path, ec); if (ec) @@ -133,7 +135,7 @@ std::vector FILE_SERVICE::_GetFsPathsByMask(const char *s } else { - srcPath = std::filesystem::u8path(convert_path_sep(sourcePath)); + srcPath = std::filesystem::u8path(ConvertPathResource(sourcePath)); } std::filesystem::path curPath; @@ -179,7 +181,7 @@ std::time_t FILE_SERVICE::_ToTimeT(std::filesystem::file_time_type tp) std::filesystem::file_time_type FILE_SERVICE::_GetLastWriteTime(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(filename)); return std::filesystem::last_write_time(path); } @@ -203,25 +205,25 @@ std::string FILE_SERVICE::_GetExecutableDirectory() std::uintmax_t FILE_SERVICE::_GetFileSize(const char *filename) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(filename)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(filename)); return std::filesystem::file_size(path); } void FILE_SERVICE::_SetCurrentDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(pathName)); std::filesystem::current_path(path); } bool FILE_SERVICE::_CreateDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(pathName)); return std::filesystem::create_directories(path); } std::uintmax_t FILE_SERVICE::_RemoveDirectory(const char *pathName) { - std::filesystem::path path = std::filesystem::u8path(convert_path_sep(pathName)); + std::filesystem::path path = std::filesystem::u8path(ConvertPathResource(pathName)); return std::filesystem::remove_all(path); } @@ -358,6 +360,113 @@ bool FILE_SERVICE::LoadFile(const char *file_name, char **ppBuffer, uint32_t *dw return true; } +//------------------------------------------------------------------------------------------------ +// Resource paths +// + +static bool starts_with(const std::string &str, const std::string &prefix) +{ + return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix); +} + +static bool ends_with(const std::string &str, const std::string &suffix) +{ + return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); +} + +void terminate_with_char(std::string &buffer, const char chr) +{ + // Check if already has + if (!buffer.empty() && buffer[buffer.length() - 1] != chr) + { + // Append to end and store + buffer += chr; + } +} + +std::string get_dir_iterator_path(const std::filesystem::path &path) +{ + std::string path_str = path.string(); + size_t pos = path_str.find(std::string(".") + PATH_SEP); + if (pos != std::string::npos && pos == 0) + { + path_str.erase(0, 2); + } + return path_str; +} + +void string_replace(std::string &input, const char *find, const char *paste) +{ + size_t pos = 0; + while (true) + { + pos = input.find(find, pos); + if (pos >= input.size()) + break; + input.replace(pos, strlen(find), paste); + pos += strlen(paste); + } +} + +std::string convert_path(const char *path) +{ + std::string conv; + size_t size = strlen(path); + for (int i = 0; i < size; ++i) + { + conv.push_back(path[i] == WRONG_PATH_SEP ? PATH_SEP : path[i]); + } + return conv; +} + +void FILE_SERVICE::ScanResourcePaths() +{ + if (ResourcePathsFirstScan) + { + // Seems like if static code calls us we need to do this manually to avoid any bugs + ResourcePaths = std::unordered_map(); + } + ResourcePaths.clear(); + for (const auto &entry : std::filesystem::recursive_directory_iterator(".")) + { + if (entry.is_regular_file() || entry.is_directory()) + { + std::string path = get_dir_iterator_path(entry.path()); + std::string path_lwr = convert_path(path.c_str()); + tolwr(path_lwr.data()); + if (starts_with(path_lwr, "program") || starts_with(path_lwr, "resource") || ends_with(path_lwr, ".ini")) + { + ResourcePaths[path_lwr] = path; + if (entry.is_directory()) + { + terminate_with_char(path_lwr, PATH_SEP); + ResourcePaths[path_lwr] = path; + } + } + } + } + ResourcePathsFirstScan = false; +} + +std::string FILE_SERVICE::ConvertPathResource(const char *path) +{ + if (ResourcePathsFirstScan) + { + ScanResourcePaths(); + } + std::string conv = convert_path(path); + tolwr(conv.data()); + if (starts_with(conv, "./")) + { + string_replace(conv, "./", ""); + } + std::string result = ResourcePaths[conv]; + if (result.empty()) + return conv; + else + return result; +} + //================================================================================================= INIFILE_T::~INIFILE_T() diff --git a/src/apps/engine/src/file_service.h b/src/apps/engine/src/file_service.h index 989ee4543..065bb31c5 100644 --- a/src/apps/engine/src/file_service.h +++ b/src/apps/engine/src/file_service.h @@ -3,6 +3,7 @@ #include "ifs.h" #include "v_file_service.h" #include +#include #define _MAX_OPEN_INI_FILES 1024 @@ -85,6 +86,9 @@ class FILE_SERVICE : public VFILE_SERVICE IFS *OpenFiles[_MAX_OPEN_INI_FILES]; uint32_t Files_Num; uint32_t Max_File_Index; + // Resource paths + bool ResourcePathsFirstScan = true; // Since some code may call this statically, we use a flag to know if this is the first time + std::unordered_map ResourcePaths; public: FILE_SERVICE(); @@ -116,4 +120,8 @@ class FILE_SERVICE : public VFILE_SERVICE std::unique_ptr OpenIniFile(const char *file_name) override; void RefDec(INIFILE *ini_obj); void FlushIniFiles(); + + // Resource paths + void ScanResourcePaths() override; + std::string ConvertPathResource(const char *path) override; }; diff --git a/src/libs/common/include/storm_platform.h b/src/libs/common/include/storm_platform.h index aab7d8119..5486c3ee6 100644 --- a/src/libs/common/include/storm_platform.h +++ b/src/libs/common/include/storm_platform.h @@ -1,10 +1,14 @@ #pragma once #ifdef _WIN32 + +#define PATH_SEP '\\' +#define WRONG_PATH_SEP '/' inline const char *convert_path_sep(const char *cPath) { return cPath; } -#else + +#else // NOT _WIN32 #include @@ -17,6 +21,8 @@ inline const char *convert_path_sep(const char *cPath) #define _MAX_FNAME NAME_MAX #define MAKELONG(low, high) ((int32_t)(((uint16_t)(low)) | (((uint32_t)((uint16_t)(high))) << 16))) +#define PATH_SEP '/' +#define WRONG_PATH_SEP '\\' inline char *convert_path_sep(const char *cPath) { const auto len = strlen(cPath) + 1; diff --git a/src/libs/common/include/v_file_service.h b/src/libs/common/include/v_file_service.h index e5ae0ff0d..046284473 100644 --- a/src/libs/common/include/v_file_service.h +++ b/src/libs/common/include/v_file_service.h @@ -43,6 +43,10 @@ class VFILE_SERVICE // ini files section virtual std::unique_ptr CreateIniFile(const char *file_name, bool fail_if_exist) = 0; virtual std::unique_ptr OpenIniFile(const char *file_name) = 0; + + // Resource paths + virtual void ScanResourcePaths() = 0; + virtual std::string ConvertPathResource(const char *path) = 0; }; //------------------------------------------------------------------------------------------------ diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index d0ebf95b0..40bd45d38 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -1376,7 +1376,7 @@ int32_t DX9RENDER::TextureCreate(const char *fname) return -1L; } - std::filesystem::path path = convert_path_sep(fname); + std::filesystem::path path = fio->ConvertPathResource(fname); std::string pathStr = path.extension().string(); if (storm::iEquals(pathStr, ".tx")) path.replace_extension();