├── .clang-format ├── .github └── workflows │ └── win-build.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── MatrixGame ├── CFG │ ├── README.txt │ ├── robots │ │ ├── data.txt │ │ └── iface.txt │ └── robots_rename_to_use.dat ├── CMakeLists.txt ├── MatrixGame.ico ├── MatrixGame.rc ├── Rangers.ttf ├── Resource.h ├── small.ico └── src │ ├── Common.hpp │ ├── DevConsole.cpp │ ├── DevConsole.hpp │ ├── Effects │ ├── MatrixEffect.cpp │ ├── MatrixEffect.hpp │ ├── MatrixEffectBigBoom.cpp │ ├── MatrixEffectBigBoom.hpp │ ├── MatrixEffectBillboard.cpp │ ├── MatrixEffectBillboard.hpp │ ├── MatrixEffectDust.cpp │ ├── MatrixEffectDust.hpp │ ├── MatrixEffectElevatorField.cpp │ ├── MatrixEffectElevatorField.hpp │ ├── MatrixEffectExplosion.cpp │ ├── MatrixEffectExplosion.hpp │ ├── MatrixEffectFirePlasma.cpp │ ├── MatrixEffectFirePlasma.hpp │ ├── MatrixEffectFlame.cpp │ ├── MatrixEffectFlame.hpp │ ├── MatrixEffectKonus.cpp │ ├── MatrixEffectKonus.hpp │ ├── MatrixEffectLandscapeSpot.cpp │ ├── MatrixEffectLandscapeSpot.hpp │ ├── MatrixEffectLightening.cpp │ ├── MatrixEffectLightening.hpp │ ├── MatrixEffectMoveTo.cpp │ ├── MatrixEffectMoveTo.hpp │ ├── MatrixEffectMovingObject.cpp │ ├── MatrixEffectMovingObject.hpp │ ├── MatrixEffectPath.cpp │ ├── MatrixEffectPath.hpp │ ├── MatrixEffectPointLight.cpp │ ├── MatrixEffectPointLight.hpp │ ├── MatrixEffectRepair.cpp │ ├── MatrixEffectRepair.hpp │ ├── MatrixEffectSelection.cpp │ ├── MatrixEffectSelection.hpp │ ├── MatrixEffectShleif.cpp │ ├── MatrixEffectShleif.hpp │ ├── MatrixEffectSmokeAndFire.cpp │ ├── MatrixEffectSmokeAndFire.hpp │ ├── MatrixEffectWeapon.cpp │ ├── MatrixEffectWeapon.hpp │ ├── MatrixEffectZahvat.cpp │ └── MatrixEffectZahvat.hpp │ ├── Interface │ ├── CAnimation.cpp │ ├── CAnimation.h │ ├── CConstructor.cpp │ ├── CConstructor.h │ ├── CCounter.cpp │ ├── CCounter.h │ ├── CHistory.cpp │ ├── CHistory.h │ ├── CIFaceButton.cpp │ ├── CIFaceButton.h │ ├── CIFaceElement.cpp │ ├── CIFaceElement.h │ ├── CIFaceImage.cpp │ ├── CIFaceImage.h │ ├── CIFaceMenu.cpp │ ├── CIFaceMenu.h │ ├── CIFaceStatic.cpp │ ├── CIFaceStatic.h │ ├── CInterface.cpp │ ├── CInterface.h │ ├── Interface.h │ ├── MatrixHint.cpp │ └── MatrixHint.hpp │ ├── Logic │ ├── MatrixAIGroup.cpp │ ├── MatrixAIGroup.h │ ├── MatrixEnvironment.cpp │ ├── MatrixEnvironment.h │ ├── MatrixLogicSlot.cpp │ ├── MatrixLogicSlot.h │ ├── MatrixRoadNetwork.cpp │ ├── MatrixRoadNetwork.hpp │ ├── MatrixRule.cpp │ ├── MatrixRule.h │ ├── MatrixState.cpp │ ├── MatrixState.h │ ├── MatrixTactics.cpp │ └── MatrixTactics.h │ ├── MatrixCamera.cpp │ ├── MatrixCamera.hpp │ ├── MatrixConfig.cpp │ ├── MatrixConfig.hpp │ ├── MatrixCursor.cpp │ ├── MatrixCursor.hpp │ ├── MatrixDebugInfo.cpp │ ├── MatrixDebugInfo.hpp │ ├── MatrixFlyer.cpp │ ├── MatrixFlyer.hpp │ ├── MatrixFormGame.cpp │ ├── MatrixFormGame.hpp │ ├── MatrixGame.cpp │ ├── MatrixGame.h │ ├── MatrixGameDll.cpp │ ├── MatrixGameDll.hpp │ ├── MatrixGamePathUtils.cpp │ ├── MatrixGamePathUtils.hpp │ ├── MatrixInstantDraw.cpp │ ├── MatrixInstantDraw.hpp │ ├── MatrixLoadProgress.cpp │ ├── MatrixLoadProgress.hpp │ ├── MatrixLogic.cpp │ ├── MatrixLogic.hpp │ ├── MatrixMap.cpp │ ├── MatrixMap.hpp │ ├── MatrixMapGroup.cpp │ ├── MatrixMapGroup.hpp │ ├── MatrixMapPrepare.cpp │ ├── MatrixMapStatic.cpp │ ├── MatrixMapStatic.hpp │ ├── MatrixMapTexture.cpp │ ├── MatrixMapTexture.hpp │ ├── MatrixMapTrace.cpp │ ├── MatrixMinimap.cpp │ ├── MatrixMinimap.hpp │ ├── MatrixMultiSelection.cpp │ ├── MatrixMultiSelection.hpp │ ├── MatrixObject.cpp │ ├── MatrixObject.hpp │ ├── MatrixObjectBuilding.cpp │ ├── MatrixObjectBuilding.hpp │ ├── MatrixObjectCannon.cpp │ ├── MatrixObjectCannon.hpp │ ├── MatrixObjectRobot.cpp │ ├── MatrixObjectRobot.hpp │ ├── MatrixProgressBar.cpp │ ├── MatrixProgressBar.hpp │ ├── MatrixRenderPipeline.cpp │ ├── MatrixRenderPipeline.hpp │ ├── MatrixRobot.cpp │ ├── MatrixRobot.hpp │ ├── MatrixSampleStateManager.cpp │ ├── MatrixSampleStateManager.hpp │ ├── MatrixShadowManager.cpp │ ├── MatrixShadowManager.hpp │ ├── MatrixSide.cpp │ ├── MatrixSide.hpp │ ├── MatrixSkinManager.cpp │ ├── MatrixSkinManager.hpp │ ├── MatrixSoundManager.cpp │ ├── MatrixSoundManager.hpp │ ├── MatrixTerSurface.cpp │ ├── MatrixTerSurface.hpp │ ├── MatrixTransition.cpp │ ├── MatrixTransition.hpp │ ├── MatrixVisiCalc.cpp │ ├── MatrixWater.cpp │ ├── MatrixWater.hpp │ ├── StringConstants.hpp │ ├── Text │ ├── Font.cpp │ ├── Font.hpp │ ├── Parser.cpp │ ├── Parser.hpp │ ├── Render.cpp │ └── Render.hpp │ ├── cheats.cpp │ ├── cheats.hpp │ ├── input.cpp │ └── input.hpp ├── MatrixLib ├── 3G │ ├── 3g.cpp │ ├── 3g.hpp │ ├── BigIB.hpp │ ├── BigVB.hpp │ ├── CBillboard.cpp │ ├── CBillboard.hpp │ ├── CCamera.hpp │ ├── CCoordSystem.hpp │ ├── CVertexBuffer.hpp │ ├── CWorld.hpp │ ├── CWorldObject.hpp │ ├── Cache.cpp │ ├── Cache.hpp │ ├── D3DControl.hpp │ ├── DeviceState.cpp │ ├── DeviceState.hpp │ ├── Form.cpp │ ├── Form.hpp │ ├── Helper.cpp │ ├── Helper.hpp │ ├── Math3D.cpp │ ├── Math3D.hpp │ ├── SVertex.hpp │ ├── ShadowProj.cpp │ ├── ShadowProj.hpp │ ├── ShadowStencil.cpp │ ├── ShadowStencil.hpp │ ├── Texture.cpp │ ├── Texture.hpp │ ├── VectorObject.cpp │ └── VectorObject.hpp ├── Base │ ├── BaseDef.hpp │ ├── CBlockPar.cpp │ ├── CBlockPar.hpp │ ├── CBuf.cpp │ ├── CBuf.hpp │ ├── CException.cpp │ ├── CException.hpp │ ├── CFile.cpp │ ├── CFile.hpp │ ├── CHeap.cpp │ ├── CHeap.hpp │ ├── CList.cpp │ ├── CList.hpp │ ├── CMain.cpp │ ├── CMain.hpp │ ├── CRC32.cpp │ ├── CRC32.hpp │ ├── CReminder.cpp │ ├── CReminder.hpp │ ├── CStorage.cpp │ ├── CStorage.hpp │ ├── Mem.hpp │ ├── Pack.cpp │ ├── Pack.hpp │ ├── Registry.cpp │ ├── Registry.hpp │ ├── Tracer.cpp │ ├── Tracer.hpp │ ├── fps_counter.hpp │ ├── preallocated_list.hpp │ ├── random.cpp │ ├── random.hpp │ ├── stupid_logger.hpp │ └── utils.hpp ├── Bitmap │ ├── CBitmap.cpp │ ├── CBitmap.hpp │ ├── FilePNG.cpp │ └── FilePNG.hpp └── CMakeLists.txt ├── README.md ├── ThirdParty └── CMakeLists.txt ├── cmake ├── FindDIRECTX9.cmake ├── ToolClangFormat.cmake └── linux-toolchain.cmake └── docs ├── CROSS_COMPILATION.md └── image.png /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | AllowShortBlocksOnASingleLine: Empty 3 | AllowShortCaseLabelsOnASingleLine: 'false' 4 | BasedOnStyle: Chromium 5 | BinPackArguments: 'true' 6 | BinPackParameters: 'true' 7 | BreakBeforeBraces: Custom 8 | BraceWrapping: 9 | AfterEnum: 'false' 10 | BeforeCatch: 'true' 11 | BeforeElse: 'true' 12 | BeforeWhile: 'true' 13 | AccessModifierOffset: '-4' 14 | AlignConsecutiveMacros: 'true' 15 | AlignEscapedNewlines: Left 16 | BreakInheritanceList: BeforeColon 17 | ColumnLimit: '120' 18 | CompactNamespaces: 'false' 19 | ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' 20 | ConstructorInitializerIndentWidth: '2' 21 | ContinuationIndentWidth: '8' 22 | FixNamespaceComments: 'true' 23 | IncludeBlocks: Preserve 24 | IndentWidth: '4' 25 | PointerAlignment: Right 26 | ReflowComments: 'true' 27 | SortIncludes: 'false' 28 | SpacesBeforeTrailingComments: '2' 29 | TabWidth: '4' 30 | 31 | ... 32 | -------------------------------------------------------------------------------- /.github/workflows/win-build.yml: -------------------------------------------------------------------------------- 1 | name: Auto-build 2 | 3 | on: 4 | push: 5 | branches: [ "refactoring", "TEST" ] 6 | pull_request: 7 | branches: [ "refactoring" ] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | jobs: 13 | msvc: 14 | name: Build with MSVC 15 | runs-on: windows-latest 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: Get DXSDK 19 | run: | 20 | DXDIR=$TEMP/DXDIR 21 | curl -L https://download.microsoft.com/download/a/e/7/ae743f1f-632b-4809-87a9-aa1bb3458e31/DXSDK_Jun10.exe -o _DX2010_.exe 22 | 7z x _DX2010_.exe DXSDK/Include -o_DX2010_ 23 | 7z x _DX2010_.exe DXSDK/Lib/x86 -o_DX2010_ 24 | mkdir $DXDIR 25 | mv _DX2010_/DXSDK/* $DXDIR 26 | rm -fR _DX*_ _DX*_.exe 27 | echo "DXSDK_DIR=$DXDIR" >> $GITHUB_ENV 28 | shell: bash 29 | - name: Compile with MSVC 30 | run: | 31 | cmake -A Win32 . -B build_msvc 32 | cmake --build build_msvc --config Release 33 | shell: bash 34 | - name: Store artifacts 35 | uses: actions/upload-artifact@v4 36 | with: 37 | name: dll_msvc 38 | path: | 39 | ${{ github.workspace }}/build_msvc/MatrixGame/Release/MatrixGame.dll 40 | 41 | gcc: 42 | name: Build with GCC 43 | runs-on: windows-latest 44 | steps: 45 | - uses: actions/checkout@v4 46 | - name: Get MinGW 47 | run: | 48 | MINGW_DIR=$TEMP/mingw 49 | curl -L https://github.com/brechtsanders/winlibs_mingw/releases/download/13.1.0-16.0.2-11.0.0-ucrt-r1/winlibs-i686-mcf-dwarf-gcc-13.1.0-mingw-w64ucrt-11.0.0-r1.7z -o mingw.7z 50 | 7z x mingw.7z -o$MINGW_DIR 51 | rm mingw.7z 52 | echo "PATH=$MINGW_DIR/mingw32/bin:$PATH" >> $GITHUB_ENV 53 | shell: bash 54 | - name: Get Ninja 55 | run: | 56 | NINJA_DIR=$TEMP/ninja 57 | curl -L https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip -o ninja.zip 58 | unzip ninja.zip -d $NINJA_DIR 59 | rm ninja.zip 60 | echo "PATH=$NINJA_DIR:$PATH" >> $GITHUB_ENV 61 | shell: bash 62 | - name: Compile with GCC 63 | run: | 64 | # ninja wants cmd.exe to be in the path 65 | export PATH=/c/Windows/System32:$PATH 66 | cmake . -G "Ninja" -B build_gcc 67 | cmake --build build_gcc --config Release 68 | shell: bash 69 | - name: Store artifacts 70 | uses: actions/upload-artifact@v4 71 | with: 72 | name: dll_gcc 73 | path: | 74 | ${{ github.workspace }}/build_gcc/MatrixGame/MatrixGame.dll -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build*/ 2 | bin/ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | set(CMAKE_CXX_STANDARD 20) 4 | set(CMAKE_CONFIGURATION_TYPES Release Debug) 5 | 6 | project(MatrixGame) 7 | 8 | if(NOT CMAKE_BUILD_TYPE) 9 | set(CMAKE_BUILD_TYPE Release) 10 | endif() 11 | 12 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") 13 | 14 | option(MATRIXGAME_BUILD_DLL "Build dll instead of exe" TRUE) 15 | option(MATRIXGAME_CHEATS "Enable cheats" TRUE) 16 | 17 | find_package(DIRECTX9 REQUIRED) 18 | if(MSVC) 19 | if(NOT DIRECTX9_FOUND) 20 | message(FATAL_ERROR "Could not find DirectX SDK") 21 | endif() 22 | include_directories(AFTER ${DIRECTX9_INCLUDE_DIRS}) 23 | endif() 24 | 25 | include(ThirdParty/CMakeLists.txt) 26 | 27 | list(APPEND COMPILE_DEFINITIONS MATRIXGAME_EXPORTS $<$:ASSERT_OFF>) 28 | 29 | if(MSVC) 30 | set(COMPILE_OPTIONS 31 | $<$:/Zi /W3 /O2 /Ob2 /Oi /Ot /Oy /GF /EHsc /GS- /Gy-> 32 | $<$:/Zi /W3 /Od /GF /Gm- /RTCc /RTC1> 33 | ) 34 | set(LINK_OPTIONS 35 | /SUBSYSTEM:WINDOWS /DYNAMICBASE:NO /MACHINE:X86 36 | $<$:/INCREMENTAL:NO /OPT:REF /OPT:ICF> 37 | $<$:/INCREMENTAL /DEBUG> 38 | ) 39 | 40 | list(APPEND COMPILE_DEFINITIONS $<$:_CRT_SECURE_NO_WARNINGS> _AFX_NO_DEBUG_CRT NOMINMAX) 41 | 42 | # TODO: is deprecated since C++17. in future we should 43 | # use std::string everywhere and not cast string <-> wstring. 44 | # till then - here is a hotfix to suppress warnings 45 | list(APPEND COMPILE_DEFINITIONS _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) 46 | else() 47 | list(APPEND COMPILE_DEFINITIONS $<$:_DEBUG>) 48 | 49 | # All the warnings below are potential bugs. 50 | # -Wno-... options should be fixed and removed. 51 | list(APPEND COMPILE_OPTIONS 52 | $<$:-Os> 53 | -ftrivial-auto-var-init=zero 54 | 55 | -Wall 56 | -Wextra 57 | -Wpedantic 58 | -Werror 59 | 60 | -Wno-unknown-pragmas 61 | -Wno-reorder 62 | -Wno-sign-compare 63 | -Wno-unused-function 64 | -Wno-unused-variable 65 | -Wno-class-memaccess 66 | -Wno-parentheses 67 | -Wno-switch 68 | -Wno-strict-aliasing 69 | -Wno-empty-body 70 | -Wno-pedantic 71 | -Wno-uninitialized 72 | ) 73 | 74 | set(LINK_OPTIONS 75 | $<$:-static -s> 76 | ) 77 | endif() 78 | 79 | add_subdirectory(MatrixLib) 80 | add_subdirectory(MatrixGame) 81 | 82 | install( 83 | TARGETS MatrixGame 84 | CONFIGURATIONS Release 85 | RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin 86 | LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin 87 | ) 88 | install( 89 | TARGETS MatrixGame 90 | CONFIGURATIONS Debug 91 | RUNTIME DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin/Debug 92 | LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin/Debug 93 | ) 94 | 95 | if(MSVC) 96 | install( 97 | FILES $ 98 | CONFIGURATIONS Debug 99 | DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/bin/Debug 100 | ) 101 | endif() 102 | -------------------------------------------------------------------------------- /MatrixGame/CFG/README.txt: -------------------------------------------------------------------------------- 1 | This "CFG/" directory's structure: 2 | 3 | "./robots/iface.txt" 4 | "./robots/data.txt" 5 | "./robots_rename_to_use.dat" 6 | 7 | ===================================================== EXE ===================================================== 8 | 9 | This "CFG/" directory should reside in the same folder as the final "MatrixGame.exe" if you build for .EXE 10 | 11 | The "robots_rename_to_use.dat" is a compressed BlockPar database file which consists of 12 | "./robots/iface.txt" and "./robots/data.txt" configuration files and is optional for .EXE 13 | 14 | If the game cannot find "./robots.dat" it will use "./robots/iface.txt" and "./robots/data.txt" instead. 15 | Therefore, if you want to use the .dat file instead of the .txt files you would need to rename it: 16 | 17 | "./robots_rename_to_use.dat" -> "./robots.dat" 18 | 19 | Alternatively the "robots.dat" file can be taken from "$(SPACE_RANGERS_DIR)/CFG/$(LANG)/robots.dat". 20 | 21 | But it is better to use .txt files because you can tweak them easily. 22 | 23 | ===================================================== DLL ===================================================== 24 | 25 | If you build for .DLL to use with Space Rangers 2 then only "robots.dat" file can be used! 26 | 27 | And it should already be present at "$(SPACE_RANGERS_DIR)/CFG/$(LANG)/robots.dat" 28 | 29 | If you want to build a new "robots.dat" file using modified ".txt" config files you can do so using "BUILDCFG" 30 | console command inside of DEBUG .EXE version developer in-game console (press "~" to open). 31 | 32 | =============================================================================================================== 33 | 34 | TODO: allow usage of .txt config files when building for .DLL 35 | -------------------------------------------------------------------------------- /MatrixGame/CFG/robots/data.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/CFG/robots/data.txt -------------------------------------------------------------------------------- /MatrixGame/CFG/robots/iface.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/CFG/robots/iface.txt -------------------------------------------------------------------------------- /MatrixGame/CFG/robots_rename_to_use.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/CFG/robots_rename_to_use.dat -------------------------------------------------------------------------------- /MatrixGame/MatrixGame.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/MatrixGame.ico -------------------------------------------------------------------------------- /MatrixGame/Rangers.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/Rangers.ttf -------------------------------------------------------------------------------- /MatrixGame/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by MatrixGame.rc 4 | // 5 | #define IDC_MYICON 2 6 | #define IDD_MATRIXGAME_DIALOG 102 7 | #define IDS_APP_TITLE 103 8 | #define IDM_ABOUT 104 9 | #define IDM_EXIT 105 10 | #define IDI_MATRIXGAME 107 11 | #define IDI_SMALL 108 12 | #define IDC_MATRIXGAME 109 13 | #define IDR_MAINFRAME 128 14 | #define IDC_STATIC -1 15 | 16 | #define IDF_RANGERS_FONT 1234 17 | 18 | // Next default values for new objects 19 | // 20 | #ifdef APSTUDIO_INVOKED 21 | #ifndef APSTUDIO_READONLY_SYMBOLS 22 | #define _APS_NO_MFC 1 23 | #define _APS_NEXT_RESOURCE_VALUE 129 24 | #define _APS_NEXT_COMMAND_VALUE 32771 25 | #define _APS_NEXT_CONTROL_VALUE 1000 26 | #define _APS_NEXT_SYMED_VALUE 110 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /MatrixGame/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/MatrixGame/small.ico -------------------------------------------------------------------------------- /MatrixGame/src/DevConsole.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef DEV_CONSOLE_INCLUDE 7 | #define DEV_CONSOLE_INCLUDE 8 | 9 | typedef void (*CMD_HANDLER)(const std::wstring& cmd, const std::wstring& params); 10 | 11 | struct SCmdItem 12 | { 13 | const wchar *cmd; 14 | CMD_HANDLER handler; 15 | }; 16 | 17 | #define DCON_ACTIVE SETBIT(0) 18 | #define DCON_CURSOR SETBIT(1) 19 | #define DCON_SHIFT SETBIT(2) 20 | 21 | #define DEV_CONSOLE_CURSOR_FLASH_PERIOD 300 22 | 23 | class CDevConsole : public CMain { 24 | DWORD m_Flags; 25 | 26 | static SCmdItem m_Commands[]; 27 | 28 | std::wstring m_Text; 29 | int m_CurPos; 30 | 31 | int m_NextTime; 32 | int m_Time; 33 | 34 | public: 35 | CDevConsole(void); 36 | ~CDevConsole(); 37 | 38 | bool IsActive(void) const { return FLAG(m_Flags, DCON_ACTIVE); } 39 | void SetActive(bool active); 40 | 41 | void ShowHelp(void); 42 | 43 | void Takt(int ms); 44 | void Keyboard(uint8_t vk, bool down); 45 | }; 46 | 47 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectBigBoom.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // big boom 9 | 10 | #define BB_FVF (D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE3(0)) 11 | struct SBBVertex { 12 | D3DXVECTOR3 p; // Vertex position 13 | // float tu, tv; // Vertex texture coordinates 14 | float x, y, z; 15 | }; 16 | 17 | //#define BB_PASS_CNT 2 18 | //#define BB_TRI_CNT 216 19 | //#define BB_PTS_CNT 173 20 | 21 | #define BB_PASS_CNT 3 22 | #define BB_TRI_CNT 1296 23 | #define BB_PTS_CNT 1037 24 | 25 | class CMatrixEffectBigBoom : public CMatrixEffect { 26 | protected: 27 | DWORD m_Color; // diffuse color 28 | float m_TTL; 29 | float m_Radius; 30 | 31 | float m_k1, m_k2, m_k3; 32 | 33 | float _m_TTL; 34 | 35 | DWORD m_User; 36 | FIRE_END_HANDLER m_Handler; 37 | DWORD m_hitmask; 38 | CMatrixMapStatic *m_skip; 39 | 40 | SEffectHandler m_Light; 41 | 42 | D3DXMATRIX m_Mat; 43 | D3DXMATRIX m_TMat; 44 | 45 | static D3D_VB m_VB; 46 | static D3D_IB m_IB; 47 | static CTextureManaged *m_Tex; 48 | static int m_VB_ref; 49 | 50 | CMatrixEffectBigBoom(const D3DXVECTOR3 &pos, float radius, float ttl, DWORD hitmask, CMatrixMapStatic *skip, 51 | DWORD user, FIRE_END_HANDLER handler, DWORD light); 52 | virtual ~CMatrixEffectBigBoom(); 53 | 54 | static bool PrepareDX(void); 55 | static void StaticInit(void) { 56 | m_VB = NULL; 57 | m_IB = NULL; 58 | m_Tex = NULL; 59 | m_VB_ref = 0; 60 | } 61 | 62 | static void MarkAllBuffersNoNeed(void) { 63 | if (m_VB) 64 | DESTROY_VB(m_VB); 65 | if (m_IB) 66 | DESTROY_IB(m_IB); 67 | } 68 | 69 | public: 70 | friend class CMatrixEffect; 71 | static bool BoomEnum(const D3DXVECTOR3 ¢er, CMatrixMapStatic *ms, uintptr_t user); 72 | static bool BoomEnumNaklon(const D3DXVECTOR3 ¢er, CMatrixMapStatic *ms, uintptr_t user); 73 | 74 | const D3DXVECTOR3 &GetPos(void) const { return *(D3DXVECTOR3 *)&m_Mat._41; } 75 | 76 | virtual void BeforeDraw(void); 77 | virtual void Draw(void) const override; 78 | virtual void Takt(float step); 79 | virtual void Release(void); 80 | 81 | virtual int Priority(void) { return 1000; } 82 | }; 83 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectDust.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include 7 | 8 | #include "MatrixEffect.hpp" 9 | #include "../MatrixMap.hpp" 10 | #include 11 | 12 | #include "MatrixEffectDust.hpp" 13 | 14 | #define DUST_R1 5 15 | #define DUST_R1_VAR 3 16 | #define DUST_R2 25 17 | #define DUST_R2_VAR 7 18 | #define DUST_C1 0x4F888888 19 | #define DUST_C2 0x00777777 20 | #define DUST_SPEED_K 1.5f 21 | 22 | CMatrixEffectDust::CMatrixEffectDust(const D3DXVECTOR2 &pos, const D3DXVECTOR2 &adddir, float ttl) 23 | : CMatrixEffect(), m_TTL(ttl), m_AddSpeed(adddir) { 24 | DTRACE(); 25 | m_EffectType = EFFECT_DUST; 26 | 27 | for (int i = 0; i < DUST_BILLS_CNT; ++i) { 28 | D3DXVECTOR2 dir(FSRND(1), FSRND(1)); 29 | D3DXVec2Normalize(m_Dirs + i, &dir); 30 | new(&m_BBoards[i]) 31 | CMatrixEffectBillboard( 32 | D3DXVECTOR3(pos.x, pos.y, 0), 33 | DUST_R1 + FSRND(DUST_R1_VAR), 34 | DUST_R2 + FSRND(DUST_R2_VAR), 35 | DUST_C1, 36 | DUST_C2, 37 | ttl, 38 | 0.0f, 39 | TEXTURE_PATH_DUST, 40 | D3DXVECTOR3(m_Dirs[i].x, m_Dirs[i].y, 0), 41 | NULL); 42 | 43 | m_BBoards[i].m_Intense = false; 44 | m_Dirs[i] *= DUST_SPEED_K; 45 | } 46 | } 47 | CMatrixEffectDust::~CMatrixEffectDust() { 48 | DTRACE(); 49 | } 50 | 51 | void CMatrixEffectDust::BeforeDraw(void) { 52 | DTRACE(); 53 | 54 | if (FLAG(m_before_draw_done, BDDF_DUST)) 55 | return; 56 | 57 | m_BBoards[0].BeforeDraw(); 58 | 59 | SETFLAG(m_before_draw_done, BDDF_DUST); 60 | 61 | // for (int i=0; iGetZ(m_BBoards[i].m_Mat._41, m_BBoards[i].m_Mat._42) + 0.1f; 83 | 84 | m_Dirs[i] *= mul; 85 | m_BBoards[i].m_TTL -= time; 86 | if (m_BBoards[i].m_TTL < 0) 87 | m_BBoards[i].m_TTL = 0.0f; 88 | if (m_BBoards[i].m_TTL == 0.0f) { 89 | ++bz; 90 | } 91 | else { 92 | m_BBoards[i].UpdateData(); 93 | } 94 | } 95 | if (bz == DUST_BILLS_CNT) { 96 | #ifdef _DEBUG 97 | g_MatrixMap->SubEffect(DEBUG_CALL_INFO, this); 98 | #else 99 | g_MatrixMap->SubEffect(this); 100 | #endif 101 | } 102 | } 103 | void CMatrixEffectDust::Release(void) { 104 | DTRACE(); 105 | SetDIP(); 106 | HDelete(CMatrixEffectDust, this, m_Heap); 107 | } 108 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectDust.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "MatrixEffectBillboard.hpp" 9 | 10 | #define DUST_BILLS_CNT 5 11 | 12 | class CMatrixEffectDust : public CMatrixEffect { 13 | CMatrixEffectBillboard m_BBoards[DUST_BILLS_CNT]; 14 | D3DXVECTOR2 m_Dirs[DUST_BILLS_CNT]; 15 | D3DXVECTOR2 m_AddSpeed; 16 | float m_TTL; 17 | 18 | CMatrixEffectDust(const D3DXVECTOR2 &pos, const D3DXVECTOR2 &adddir, float ttl); 19 | virtual ~CMatrixEffectDust(); 20 | 21 | public: 22 | friend class CMatrixEffect; 23 | 24 | virtual void BeforeDraw(void); 25 | virtual void Draw(void) const override; 26 | virtual void Takt(float step); 27 | virtual void Release(void); 28 | 29 | virtual int Priority(void) { return 0; }; 30 | }; 31 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectElevatorField.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #define ELEVATORFIELD_CNT 7 9 | #define ELEVATORFIELD_BB_CNT 300 10 | #define ELEVATORFIELD_SPAWN_PERIOD 10 11 | #define ELEVATORFIELD_BB_SIZE 3 12 | 13 | struct SElevatorFieldBBoard { 14 | // CBillboard bb; 15 | CBillboardLine bb; 16 | int kord; 17 | float t; 18 | float dt; 19 | }; 20 | 21 | class CMatrixEffectElevatorField : public CMatrixEffect { 22 | CTrajectory m_Kords[ELEVATORFIELD_CNT]; 23 | 24 | int m_BBCnt[ELEVATORFIELD_CNT]; 25 | SElevatorFieldBBoard m_BBoards[ELEVATORFIELD_BB_CNT]; 26 | int m_AllBBCnt; 27 | 28 | D3DXMATRIX m_Rot; 29 | float m_Angle; 30 | D3DXVECTOR3 m_Pos; 31 | D3DXVECTOR3 m_Dir; 32 | 33 | CMatrixEffectElevatorField(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1, float radius, const D3DXVECTOR3 &fwd); 34 | virtual ~CMatrixEffectElevatorField(); 35 | 36 | float m_NextTime; 37 | float m_Time; 38 | 39 | DWORD m_Sound; 40 | 41 | public: 42 | DWORD m_Activated; 43 | 44 | friend class CMatrixEffect; 45 | 46 | void UpdateData(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1, float r, const D3DXVECTOR3 &fwd); 47 | 48 | virtual void BeforeDraw(void); 49 | virtual void Draw(void) const override; 50 | virtual void Takt(float step); 51 | virtual void Release(void); 52 | 53 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 54 | }; 55 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectFirePlasma.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // fireplasma 9 | 10 | #define FIRE_PLASMA_W 3 11 | #define FIRE_PLASMA_L 7 12 | 13 | class CMatrixEffectFirePlasma : public CMatrixEffect { 14 | DWORD m_UserData; 15 | FIRE_END_HANDLER m_Handler; 16 | DWORD m_HitMask; 17 | CMatrixMapStatic *m_Skip; 18 | 19 | float m_Speed; 20 | float m_Prevdist; 21 | D3DXVECTOR3 m_Pos; 22 | D3DXVECTOR3 m_Dir; 23 | D3DXVECTOR3 m_End; 24 | 25 | SEffectHandler m_Light; 26 | 27 | CBillboardLine m_BBLine; 28 | CBillboard m_BB1; 29 | CBillboard m_BB2; 30 | CBillboard m_BB3; 31 | CBillboard m_BB4; 32 | 33 | CMatrixEffectFirePlasma(const D3DXVECTOR3 &start, const D3DXVECTOR3 &end, float speed, DWORD hitmask, 34 | CMatrixMapStatic *skip, FIRE_END_HANDLER handler, DWORD user); 35 | virtual ~CMatrixEffectFirePlasma(); 36 | 37 | public: 38 | friend class CMatrixEffect; 39 | friend class CPolygon; 40 | 41 | virtual void BeforeDraw(void) {} 42 | virtual void Draw(void) const override; 43 | virtual void Takt(float step); 44 | virtual void Release(void); 45 | 46 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 47 | }; 48 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectFlame.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // flame for flamethrower 9 | 10 | #define FLAME_NUM_BILLS 10 11 | 12 | #define FLAME_SCALE_FACTOR 3.6f // 2.16f 13 | //#define FLAME_DIST_FACTOR 0.3f 14 | #define FLAME_DIR_SPEED 0.36f 15 | 16 | #define FLAME_TIME_SEEK_PERIOD 20 17 | 18 | struct SFlameBill { 19 | CBillboard m_Flame; 20 | float m_Sign; 21 | ~SFlameBill() { m_Flame.Release(); } 22 | }; 23 | 24 | class CMatrixEffectFlame; 25 | 26 | class CFlamePuff : public CMain { 27 | CMatrixEffectFlame *m_Owner; 28 | 29 | SEffectHandler m_Light; 30 | 31 | float m_Alpha; 32 | int m_CurAlpha; 33 | 34 | SFlameBill m_Flames[FLAME_NUM_BILLS]; 35 | 36 | float m_Time; 37 | float m_NextSmokeTime; 38 | float m_NextSeekTime; 39 | 40 | D3DXVECTOR3 m_Pos; 41 | D3DXVECTOR3 m_Dir; 42 | D3DXVECTOR3 m_Speed; 43 | 44 | float m_Scale; 45 | 46 | CBillboardLine *m_Shleif; 47 | DWORD m_Break; 48 | 49 | CFlamePuff *m_Next; 50 | CFlamePuff *m_Prev; 51 | 52 | CFlamePuff(CMatrixEffectFlame *owner, const D3DXVECTOR3 &start, const D3DXVECTOR3 &dir, const D3DXVECTOR3 &speed); 53 | ~CFlamePuff(); 54 | 55 | public: 56 | friend class CMatrixEffectFlame; 57 | 58 | void Draw(void) const; 59 | void Takt(float step); 60 | void Release(void); 61 | }; 62 | 63 | class CMatrixEffectWeapon; 64 | 65 | class CMatrixEffectFlame : public CMatrixEffect { 66 | CFlamePuff *m_First; 67 | CFlamePuff *m_Last; 68 | 69 | CFlamePuff *m_Stream; 70 | 71 | DWORD m_User; 72 | FIRE_END_HANDLER m_Handler; 73 | DWORD m_hitmask; 74 | CMatrixMapStatic *m_skip; 75 | 76 | float m_TTL; 77 | float _m_TTL; 78 | 79 | SEffectHandler m_Smokes; 80 | 81 | CMatrixEffectFlame(float ttl, DWORD hitmask, CMatrixMapStatic *skip, DWORD user, FIRE_END_HANDLER handler); 82 | virtual ~CMatrixEffectFlame(); 83 | 84 | void CreateSmoke(const D3DXVECTOR3 &pos); 85 | 86 | public: 87 | friend class CMatrixEffect; 88 | friend class CFlamePuff; 89 | 90 | virtual void BeforeDraw(void); 91 | virtual void Draw(void) const override; 92 | virtual void Takt(float step); 93 | virtual void Release(void); 94 | 95 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 96 | 97 | void AddPuff(const D3DXVECTOR3 &start, const D3DXVECTOR3 &dir, const D3DXVECTOR3 &speed); 98 | void SubPuff(CFlamePuff *puf); 99 | void Break(void) { m_Stream = NULL; }; 100 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectKonus.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // konus 9 | 10 | #define KONUS_FVF (D3DFVF_XYZ | D3DFVF_TEX1) 11 | struct SKonusVertex { 12 | D3DXVECTOR3 p; // Vertex position 13 | float tu, tv; // Vertex texture coordinates 14 | }; 15 | 16 | #define KONUS_NUM_SECTORS 7 17 | 18 | class CMatrixEffectKonus : public CMatrixEffect { 19 | protected: 20 | CTextureManaged *m_Tex; 21 | DWORD m_Color; // diffuse color 22 | float m_TTL; 23 | float m_Radius; 24 | float m_Height; 25 | float m_Angle; 26 | DWORD m_Intense; 27 | 28 | float _m_TTL; 29 | 30 | D3DXVECTOR3 m_Pos; 31 | D3DXVECTOR3 m_Dir; 32 | D3DXMATRIX m_Mat; 33 | 34 | static D3D_VB m_VB; 35 | static int m_VB_ref; 36 | 37 | CMatrixEffectKonus(const D3DXVECTOR3 &start, const D3DXVECTOR3 &dir, float radius, float height, float angle, 38 | float ttl, bool intense, CTextureManaged *tex); 39 | virtual ~CMatrixEffectKonus(); 40 | 41 | void UpdateMatrix(void); 42 | 43 | static bool PrepareDX(void); 44 | static void StaticInit(void) { 45 | m_VB = NULL; 46 | m_VB_ref = 0; 47 | } 48 | 49 | static void MarkAllBuffersNoNeed(void) { 50 | if (IS_VB(m_VB)) { 51 | DESTROY_VB(m_VB); 52 | } 53 | } 54 | 55 | public: 56 | friend class CMatrixEffect; 57 | friend class CVolcano; 58 | 59 | virtual void BeforeDraw(void) { 60 | DTRACE(); 61 | PrepareDX(); 62 | m_Tex->Preload(); 63 | }; 64 | virtual void Draw(void) const override; 65 | virtual void Takt(float step); 66 | virtual void Release(void); 67 | 68 | virtual int Priority(void) { return 10; }; 69 | 70 | void Modify(const D3DXVECTOR3 &pos, const D3DXVECTOR3 &dir) { 71 | DTRACE(); 72 | m_Pos = pos; 73 | m_Dir = dir; 74 | UpdateMatrix(); 75 | } 76 | void Modify(const D3DXVECTOR3 &pos, const D3DXVECTOR3 &dir, float radius, float height, float angle) { 77 | DTRACE(); 78 | m_Pos = pos; 79 | m_Dir = dir; 80 | m_Radius = radius; 81 | m_Height = height; 82 | m_Angle = angle; 83 | UpdateMatrix(); 84 | } 85 | }; 86 | 87 | class CMatrixEffectKonusSplash : public CMatrixEffectKonus { 88 | float m_HeightInit; 89 | float m_RadiusInit; 90 | D3DXVECTOR3 m_PosInit; 91 | 92 | public: 93 | CMatrixEffectKonusSplash(const D3DXVECTOR3 &start, const D3DXVECTOR3 &dir, float radius, float height, float angle, 94 | float ttl, bool intense, CTextureManaged *tex) 95 | : CMatrixEffectKonus(start, dir, radius, height, angle, ttl, intense, tex), m_HeightInit(height), 96 | m_RadiusInit(radius), m_PosInit(start) { 97 | m_EffectType = EFFECT_SPLASH; 98 | DTRACE(); 99 | Takt(0); 100 | } 101 | virtual void Takt(float step); 102 | 103 | virtual int Priority(void) { return 0; }; 104 | }; 105 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectLandscapeSpot.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | class CMatrixEffectLandscapeSpot; 9 | 10 | void SpotTaktConstant(CMatrixEffectLandscapeSpot *spot, float takt); 11 | void SpotTaktAlways(CMatrixEffectLandscapeSpot *spot, float takt); 12 | void SpotTaktPlasmaHit(CMatrixEffectLandscapeSpot *spot, float takt); 13 | void SpotTaktMoveTo(CMatrixEffectLandscapeSpot *spot, float takt); 14 | void SpotTaktPointlight(CMatrixEffectLandscapeSpot *spot, float takt); 15 | void SpotTaktVoronka(CMatrixEffectLandscapeSpot *spot, float takt); 16 | 17 | #define LANDSCAPESPOT_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1) 18 | typedef struct { 19 | D3DXVECTOR3 p; // Vertex position 20 | DWORD color; // Vertex color 21 | float tu, tv; // Vertex texture coordinates 22 | } SLandscapeSpotVertex; 23 | 24 | #define SPOT_ALTITUDE (0.7f) 25 | #define SPOT_SIZE (5.0f) 26 | 27 | class CMatrixEffectLandscapeSpot : public CMatrixEffect { 28 | static CMatrixEffectLandscapeSpot *m_First; 29 | static CMatrixEffectLandscapeSpot *m_Last; 30 | 31 | CMatrixEffectLandscapeSpot *m_Next; 32 | CMatrixEffectLandscapeSpot *m_Prev; 33 | 34 | D3D_VB m_VB; 35 | D3D_IB m_IB; 36 | 37 | float m_DX; 38 | float m_DY; 39 | 40 | SSpotProperties *m_Props; 41 | CTextureManaged *m_Texture; 42 | 43 | float m_LifeTime; 44 | 45 | int m_CntVerts; 46 | int m_CntTris; 47 | 48 | BYTE *m_IndsPre; 49 | BYTE *m_VertsPre; 50 | 51 | DWORD m_Color; 52 | 53 | void BuildLand(const D3DXVECTOR2 &pos, float angle, float scalex, float scaley, float addz, bool scale_by_normal); 54 | 55 | CMatrixEffectLandscapeSpot(const D3DXVECTOR2 &pos, float angle, float scale, ESpotType type = SPOT_CONSTANT); 56 | virtual ~CMatrixEffectLandscapeSpot(); 57 | void DrawActual(void) const; 58 | 59 | #ifdef _DEBUG 60 | const char *_file; 61 | int _line; 62 | #endif 63 | 64 | bool PrepareDX(void); 65 | static void StaticInit(void) { 66 | m_First = NULL; 67 | m_Last = NULL; 68 | } 69 | 70 | static void MarkAllBuffersNoNeed(void); 71 | 72 | public: 73 | friend class CMatrixEffect; 74 | friend void SpotTaktConstant(CMatrixEffectLandscapeSpot *spot, float takt); 75 | friend void SpotTaktAlways(CMatrixEffectLandscapeSpot *spot, float takt); 76 | friend void SpotTaktPlasmaHit(CMatrixEffectLandscapeSpot *spot, float takt); 77 | friend void SpotTaktMoveTo(CMatrixEffectLandscapeSpot *spot, float takt); 78 | friend void SpotTaktPointlight(CMatrixEffectLandscapeSpot *spot, float takt); 79 | friend void SpotTaktVoronka(CMatrixEffectLandscapeSpot *spot, float takt); 80 | 81 | virtual void BeforeDraw(void) { 82 | DTRACE(); 83 | PrepareDX(); 84 | m_Texture->Preload(); 85 | }; 86 | virtual void Draw(void) const override {}; 87 | virtual void Takt(float step); 88 | virtual void Release(void); 89 | 90 | #ifdef _DEBUG 91 | void BeforeRelease(const char *file, int line) { 92 | _file = file; 93 | _line = line; 94 | }; 95 | #endif 96 | 97 | virtual int Priority(void); 98 | 99 | static void DrawAll(void); 100 | 101 | void SetColor(DWORD color) { m_Color = color; } 102 | DWORD GetColor(void) const { return m_Color; } 103 | 104 | #ifdef DEAD_CLASS_SPY_ENABLE 105 | int DCS_UnderSpy(void) const { return sizeof(CMatrixEffectLandscapeSpot); } 106 | #endif 107 | }; 108 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectLightening.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // lightening 9 | 10 | #define LIGHTENING_SEGMENT_LENGTH 30 11 | #define LIGHTENING_WIDTH 10 12 | 13 | #define SHORTED_SEGMENT_LENGTH 5 14 | #define SHORTED_WIDTH 5 15 | 16 | class CMatrixEffectLightening : public CMatrixEffect { 17 | D3DXVECTOR3 m_Pos0; 18 | D3DXVECTOR3 m_Pos1; 19 | D3DXVECTOR3 m_Dir; 20 | 21 | CMatrixEffectLightening(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1, float ttl, float dispers, float width, 22 | DWORD color, bool bp = true); 23 | virtual ~CMatrixEffectLightening(); 24 | 25 | CBillboardLine *m_BL; 26 | int m_BL_cnt; 27 | 28 | CBillboard *m_End0; 29 | 30 | float m_SegLen; 31 | 32 | virtual void UpdateData(void); 33 | 34 | float m_TTL; 35 | 36 | float m_Dispersion; 37 | float m_Width; 38 | DWORD m_Color; 39 | 40 | D3DXVECTOR3 m_Perp; 41 | 42 | public: 43 | friend class CMatrixEffect; 44 | friend class CMatrixEffectShorted; 45 | 46 | virtual void BeforeDraw(void); 47 | virtual void Draw(void) const override; 48 | virtual void Takt(float step); 49 | virtual void Release(void); 50 | 51 | virtual int Priority(void) { return 10; }; 52 | 53 | void SetPos(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1); 54 | }; 55 | 56 | class CMatrixEffectShorted : public CMatrixEffectLightening { 57 | CMatrixEffectShorted(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1, float ttl, DWORD color); 58 | 59 | float m_Len; 60 | float _m_BL_cnt; 61 | float _m_TTL; 62 | 63 | virtual void UpdateData(void); 64 | 65 | public: 66 | friend class CMatrixEffect; 67 | 68 | virtual int Priority(void) { return 1; }; 69 | 70 | void SetPos(const D3DXVECTOR3 &pos0, const D3DXVECTOR3 &pos1); 71 | }; 72 | 73 | typedef CMatrixEffectShorted *PCMatrixEffectShorted; -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectMoveTo.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixEffect.hpp" 7 | #include "../MatrixMap.hpp" 8 | 9 | #include "MatrixEffectMoveTo.hpp" 10 | #include "MatrixEffectBillboard.hpp" 11 | 12 | #define MOVETO_TTL 400 13 | #define MOVETO_S 2 14 | #define MOVETO_R 20 15 | #define MOVETO_Z 10 16 | 17 | void SPointMoveTo::Init(CMatrixEffectMoveto *host, int i) { 18 | D3DXMatrixScaling(&m, MOVETO_S, MOVETO_S, MOVETO_S); 19 | 20 | Change(host, i, 1); 21 | } 22 | 23 | void SPointMoveTo::Change(CMatrixEffectMoveto *host, int i, float k) { 24 | float a = M_PI_MUL((i & (~1)) * INVERT(3.0)); 25 | 26 | float s, c, d, z; 27 | 28 | d = MOVETO_R * 0.3f * (float)sin(M_PI_MUL(k)); 29 | z = (float)sin(M_PI_MUL(k / 2.0f)); 30 | SET_SIGN_FLOAT(d, i & 1); 31 | 32 | SinCos(a, &s, &c); 33 | m._41 = MOVETO_R * s * k + d * c; 34 | m._42 = MOVETO_R * c * k - d * s; 35 | 36 | *(D3DXVECTOR2 *)&m._41 += *(D3DXVECTOR2 *)&host->m_Pos; 37 | 38 | float lz = g_MatrixMap->GetZ(m._41, m._42); 39 | if (lz < host->m_Pos.z) 40 | lz = host->m_Pos.z; 41 | 42 | m._43 = lz + MOVETO_Z * z; 43 | } 44 | 45 | void SPointMoveTo::Draw(const CMatrixEffectMoveto *host) const { 46 | CMatrixEffectBillboard::Draw(m, 0xFFFFFFFF, host->m_Tex, false); 47 | } 48 | 49 | CTextureManaged *CMatrixEffectMoveto::m_Tex; 50 | int CMatrixEffectMoveto::m_RefCnt; 51 | 52 | CMatrixEffectMoveto::CMatrixEffectMoveto(const D3DXVECTOR3 &pos) : CMatrixEffect(), m_Pos(pos) { 53 | m_EffectType = EFFECT_MOVETO; 54 | 55 | m_TTL = MOVETO_TTL; 56 | for (int i = 0; i < 6; ++i) { 57 | m_Pts[i].Init(this, i); 58 | } 59 | 60 | if (m_RefCnt == 0) { 61 | m_Tex = (CTextureManaged *)g_Cache->Get(CacheClass::TextureManaged, TEXTURE_PATH_MOVETO); 62 | m_Tex->RefInc(); 63 | } 64 | ++m_RefCnt; 65 | 66 | CMatrixEffectBillboard::CreateGeometry(); 67 | 68 | ELIST_ADD(EFFECT_MOVETO); 69 | } 70 | 71 | CMatrixEffectMoveto::~CMatrixEffectMoveto() { 72 | ELIST_DEL(EFFECT_MOVETO); 73 | 74 | if ((--m_RefCnt) <= 0) { 75 | m_Tex->RefDecUnload(); 76 | m_Tex = NULL; 77 | } 78 | CMatrixEffectBillboard::ReleaseGeometry(); 79 | } 80 | 81 | void CMatrixEffectMoveto::Takt(float step) { 82 | DTRACE(); 83 | m_TTL -= step; 84 | if (m_TTL < 0) { 85 | #ifdef _DEBUG 86 | g_MatrixMap->SubEffect(DEBUG_CALL_INFO, this); 87 | #else 88 | g_MatrixMap->SubEffect(this); 89 | #endif 90 | return; 91 | } 92 | 93 | float k = m_TTL * INVERT(MOVETO_TTL); 94 | for (int i = 0; i < 6; ++i) { 95 | m_Pts[i].Change(this, i, k); 96 | } 97 | } 98 | 99 | void CMatrixEffectMoveto::Draw(void) const 100 | { 101 | DTRACE(); 102 | 103 | if (!IS_VB(CMatrixEffectBillboard::m_VB)) 104 | return; 105 | 106 | for (int i = 0; i < 6; ++i) { 107 | m_Pts[i].Draw(this); 108 | } 109 | } 110 | 111 | void CMatrixEffectMoveto::Release(void) { 112 | DTRACE(); 113 | SetDIP(); 114 | HDelete(CMatrixEffectMoveto, this, m_Heap); 115 | } 116 | 117 | void CMatrixEffectMoveto::BeforeDraw(void) { 118 | CMatrixEffectBillboard::PrepareDX(); 119 | m_Tex->Preload(); 120 | } 121 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectMoveTo.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_EFFECT_MOVETO_INCLUDE 7 | #define MATRIX_EFFECT_MOVETO_INCLUDE 8 | 9 | class CMatrixEffectMoveto; 10 | struct SPointMoveTo { 11 | D3DXMATRIX m; 12 | 13 | void Init(CMatrixEffectMoveto *host, int i); 14 | void Change(CMatrixEffectMoveto *host, int i, float k); 15 | void Draw(const CMatrixEffectMoveto *host) const; 16 | }; 17 | 18 | class CMatrixEffectMoveto : public CMatrixEffect { 19 | D3DXVECTOR3 m_Pos; 20 | 21 | SPointMoveTo m_Pts[6]; 22 | float m_TTL; 23 | 24 | static CTextureManaged *m_Tex; 25 | static int m_RefCnt; 26 | 27 | CMatrixEffectMoveto(const D3DXVECTOR3 ¢er); 28 | virtual ~CMatrixEffectMoveto(); 29 | 30 | static void StaticInit(void) { 31 | m_Tex = NULL; 32 | m_RefCnt = 0; 33 | } 34 | 35 | public: 36 | friend class CMatrixEffect; 37 | friend struct SPointMoveTo; 38 | 39 | virtual void BeforeDraw(void); 40 | virtual void Draw(void) const override; 41 | virtual void Takt(float); 42 | virtual void Release(void); 43 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 44 | }; 45 | 46 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectPath.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // path 9 | #define PATH_DOT_DISTANCE 6 10 | #define PATH_DOT_SPEED 0.007f 11 | #define PATH_DOT_RATE 500 12 | #define PATH_SIZE 1.5f 13 | #define PATH_COLOR 0xFFFFFF10 14 | #define PATH_HIDE_DISTANCE 30 15 | 16 | //___________________________________________________________________________________________________ 17 | ///////////////////////////////////////////////////////////////////////////////////////////////////// 18 | 19 | struct SPathDot { 20 | SPathDot *next; 21 | SPathDot *prev; 22 | 23 | CBillboard dot; 24 | float pos; 25 | }; 26 | 27 | class CMatrixEffectPath : public CMatrixEffect { 28 | DWORD m_Kill; 29 | 30 | CBuf m_Points; 31 | CBuf m_Dirs; 32 | CBuf m_Lens; 33 | 34 | int m_DotsCnt; 35 | int m_DotsMax; 36 | SPathDot *m_Dots; 37 | 38 | int m_Cnt; 39 | float m_Len; 40 | float _m_Len; 41 | 42 | // float m_Time; 43 | float m_Takt; 44 | float m_NextTakt; 45 | 46 | SPathDot *m_First; 47 | SPathDot *m_Last; 48 | 49 | float m_Angle; 50 | float m_Barier; 51 | 52 | CMatrixEffectPath(const D3DXVECTOR3 *pos, int cnt); 53 | virtual ~CMatrixEffectPath(); 54 | 55 | void UpdateData(void); 56 | 57 | public: 58 | friend class CMatrixEffect; 59 | 60 | void GetPos(D3DXVECTOR3 *out, float t); 61 | void AddPos(const D3DXVECTOR3 &pos); 62 | 63 | virtual void BeforeDraw(void); 64 | virtual void Draw(void) const override; 65 | virtual void Takt(float step); 66 | virtual void Release(void); 67 | 68 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 69 | 70 | void Kill(void) { m_Kill = true; } 71 | }; 72 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectRepair.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_EFFECT_REPAIR_INCLUDE 7 | #define MATRIX_EFFECT_REPAIR_INCLUDE 8 | 9 | #include "MatrixEffect.hpp" 10 | #include "../MatrixMapStatic.hpp" 11 | 12 | #define REPAIR_BB_CNT 50 13 | 14 | struct SRepairBBoard { 15 | CBillboardLine bb; 16 | float t; 17 | float dt; 18 | }; 19 | 20 | class CMatrixEffectRepair : public CMatrixEffect { 21 | CTrajectory m_Kord; 22 | CTrajectory m_KordOnTarget; 23 | 24 | SRepairBBoard m_BBoards[REPAIR_BB_CNT]; 25 | int m_BBCnt; 26 | 27 | CMatrixEffectRepair(const D3DXVECTOR3 &pos, const D3DXVECTOR3 &dir, float seekradius, CMatrixMapStatic *skip); 28 | virtual ~CMatrixEffectRepair(); 29 | 30 | SObjectCore *m_Target; 31 | CMatrixMapStatic *m_Skip; 32 | 33 | D3DXVECTOR3 m_Pos; 34 | D3DXVECTOR3 m_Dir; 35 | 36 | float m_OffTargetAmp; 37 | 38 | float m_ChangeTime; 39 | float m_SeekRadius; 40 | float m_NextSeekTime; 41 | float m_NextSpawnTime; 42 | float m_Time; 43 | 44 | public: 45 | friend class CMatrixEffect; 46 | 47 | void UpdateData(const D3DXVECTOR3 &pos, const D3DXVECTOR3 &dir) { 48 | DTRACE(); 49 | m_Pos = pos; 50 | m_Dir = dir; 51 | Takt(0); 52 | } 53 | 54 | CMatrixMapStatic *GetTarget(void); 55 | 56 | virtual void BeforeDraw(void); 57 | virtual void Draw(void) const override; 58 | virtual void Takt(float step); 59 | virtual void Release(void); 60 | 61 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectSelection.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | // selection 9 | #define SEL_COLOR_CHANGE_TIME 200 10 | #define SEL_SPEED 0.1f 11 | #define SEL_BLUR_CNT 1 12 | #define SEL_SIZE 1.5f 13 | #define SEL_PP_DIST 5.5f 14 | 15 | //___________________________________________________________________________________________________ 16 | ///////////////////////////////////////////////////////////////////////////////////////////////////// 17 | 18 | struct SSelPoint { 19 | CBillboard m_Blur[SEL_BLUR_CNT]; 20 | D3DXVECTOR3 m_Pos[SEL_BLUR_CNT]; 21 | // D3DXVECTOR3 m_Pos; 22 | 23 | ~SSelPoint() { 24 | for (int i = 0; i < SEL_BLUR_CNT; ++i) 25 | m_Blur[i].Release(); 26 | } 27 | }; 28 | 29 | class CMatrixEffectSelection : public CMatrixEffect { 30 | D3DXVECTOR3 m_Pos; 31 | float m_Radius; 32 | float m_InitRadius; 33 | 34 | DWORD m_Color_current; 35 | DWORD m_ColorTo; // to 36 | DWORD m_ColorFrom; // from 37 | float m_ColorTime; 38 | 39 | SSelPoint *m_Points; 40 | int m_SelCnt; 41 | 42 | CMatrixEffectSelection(const D3DXVECTOR3 &pos, float r, DWORD color); 43 | virtual ~CMatrixEffectSelection(); 44 | 45 | void UpdatePositions(void); 46 | 47 | public: 48 | friend class CMatrixEffect; 49 | 50 | virtual void BeforeDraw(void); 51 | virtual void Draw(void) const override; 52 | virtual void Takt(float step); 53 | virtual void Release(void); 54 | 55 | virtual int Priority(void) { return MAX_EFFECT_PRIORITY; }; 56 | 57 | void SetPos(const D3DXVECTOR3 &pos) { 58 | m_Pos = pos; 59 | UpdatePositions(); 60 | } 61 | void SetRadius(float r) { m_Radius = r; } 62 | 63 | void Kill(void) { SETFLAG(m_Flags, SELF_KIP); } 64 | 65 | void SetColor(DWORD color) { 66 | m_ColorFrom = m_Color_current; 67 | m_ColorTo = color; 68 | m_ColorTime = SEL_COLOR_CHANGE_TIME; 69 | } 70 | 71 | void SetAlpha(BYTE a) { 72 | m_ColorFrom = m_Color_current; 73 | m_ColorTo = (m_Color_current & 0x00FFFFFF) | (a << 24); 74 | m_ColorTime = SEL_COLOR_CHANGE_TIME; 75 | } 76 | }; 77 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectShleif.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_EFFECT_SHLEIF 7 | #define MATRIX_EFFECT_SHLEIF 8 | 9 | #define SHLEIF_MAX_SMOKES 64 10 | #define SHLEIF_TTL 2000 11 | 12 | #include "MatrixEffect.hpp" 13 | 14 | class CMatrixEffectShleif : public CMatrixEffect { 15 | SEffectHandler *m_Smokes; 16 | int m_SmokesCnt; 17 | 18 | CMatrixEffectShleif(void); 19 | virtual ~CMatrixEffectShleif(); 20 | 21 | float m_TTL; 22 | 23 | public: 24 | friend class CMatrixEffect; 25 | 26 | virtual void BeforeDraw(void); 27 | virtual void Draw(void) const override; 28 | virtual void Takt(float); 29 | virtual void Release(void); 30 | virtual int Priority(void) { return 30; }; 31 | 32 | void AddSmoke(const D3DXVECTOR3 &pos, float ttl, float puffttl, float spawntime, DWORD color, bool intense, 33 | float speed); 34 | void AddFire(const D3DXVECTOR3 &pos, float ttl, float puffttl, float spawntime, float dispfactor, bool intense, 35 | float speed); 36 | 37 | // void AddFlame(const D3DXVECTOR3 &start, const D3DXVECTOR3 &dir, const D3DXVECTOR3 &speed, float ttl, DWORD 38 | // hitmask, CMatrixMapStatic * skip, DWORD user, FIRE_END_HANDLER handler); 39 | 40 | void SetTTL(float ttl) { m_TTL = ttl; } 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /MatrixGame/src/Effects/MatrixEffectZahvat.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixEffectZahvat.hpp" 7 | #include "StringConstants.hpp" 8 | 9 | #include 10 | #include 11 | 12 | #define ZAHVAT_SPOT_SIZE 6 13 | #define ZAHVAT_SPOT_GRAY1 0x00ffffff 14 | #define ZAHVAT_SPOT_GRAY2 0xf0808080 15 | #define ZAHVAT_FLASH_PERIOD 3000 16 | 17 | CMatrixEffectZahvat::CMatrixEffectZahvat(const D3DXVECTOR3 &pos, float radius, float angle, int cnt) 18 | : CMatrixEffect(), m_Count(cnt) { 19 | DTRACE(); 20 | m_EffectType = EFFECT_ZAHVAT; 21 | 22 | m_BBoards = (CMatrixEffectBillboard *)HAlloc(sizeof(CMatrixEffectBillboard) * cnt, m_Heap); 23 | 24 | float da = float(2 * M_PI / double(cnt)); 25 | float s, c; 26 | 27 | for (int i = 0; i < m_Count; ++i) { 28 | SinCos(angle, &s, &c); 29 | new(&m_BBoards[i]) CMatrixEffectBillboard( 30 | pos + D3DXVECTOR3(c * radius, s * radius, 0), ZAHVAT_SPOT_SIZE, ZAHVAT_SPOT_SIZE, ZAHVAT_SPOT_GRAY1, 31 | ZAHVAT_SPOT_GRAY2, ZAHVAT_FLASH_PERIOD, 0, TEXTURE_PATH_ZAHVAT, D3DXVECTOR3(1, 0, 0)); 32 | m_BBoards[i].m_Intense = false; 33 | angle += da; 34 | } 35 | 36 | UpdateData(0, 0); 37 | } 38 | CMatrixEffectZahvat::~CMatrixEffectZahvat() { 39 | DTRACE(); 40 | for (int i = 0; i < m_Count; ++i) 41 | m_BBoards[i].~CMatrixEffectBillboard(); 42 | HFree(m_BBoards, m_Heap); 43 | } 44 | 45 | void CMatrixEffectZahvat::UpdateData(DWORD color, int count) { 46 | DTRACE(); 47 | ASSERT(count <= m_Count); 48 | int count1 = m_Count - count; 49 | int i = 0; 50 | while (count-- > 0) { 51 | m_BBoards[i++].SetColor(color, ZAHVAT_SPOT_GRAY2); 52 | } 53 | while (count1-- > 0) { 54 | m_BBoards[i++].SetColor(ZAHVAT_SPOT_GRAY1, ZAHVAT_SPOT_GRAY2); 55 | } 56 | } 57 | 58 | void CMatrixEffectZahvat::BeforeDraw(void) { 59 | DTRACE(); 60 | 61 | if (m_Count > 0) 62 | m_BBoards[0].BeforeDraw(); 63 | } 64 | 65 | void CMatrixEffectZahvat::Draw() const 66 | { 67 | DTRACE(); 68 | 69 | for (int i = 0; i < m_Count; ++i) 70 | m_BBoards[i].Draw(); 71 | } 72 | 73 | void CMatrixEffectZahvat::Takt(float) { 74 | DTRACE(); 75 | // for (int i=0;i 7 | 8 | #include "CAnimation.h" 9 | #include "CIFaceStatic.h" 10 | #include "CIFaceElement.h" 11 | #include "Interface.h" 12 | 13 | CAnimation::CAnimation(int frames, int period) { 14 | DTRACE(); 15 | m_FramesBuffer = (CIFaceStatic *)HAlloc(sizeof(CIFaceStatic) * frames, g_MatrixHeap); 16 | for (int i = 0; i < frames; i++) { 17 | new(&m_FramesBuffer[i]) CIFaceStatic(); 18 | } 19 | m_Frames = frames; 20 | m_Period = period; 21 | m_FramesLoaded = 0; 22 | m_CurrentFrame = 0; 23 | m_TimePass = 0; 24 | } 25 | 26 | CAnimation::~CAnimation() { 27 | DTRACE(); 28 | if (m_FramesBuffer) { 29 | for (int i = 0; i < m_Frames; i++) { 30 | m_FramesBuffer[i].CIFaceStatic::~CIFaceStatic(); 31 | } 32 | HFree(m_FramesBuffer, g_MatrixHeap); 33 | } 34 | } 35 | 36 | void CAnimation::LogicTakt(int ms) { 37 | DTRACE(); 38 | m_TimePass += ms; 39 | if (m_TimePass >= m_Period) { 40 | m_TimePass = 0; 41 | 42 | m_CurrentFrame++; 43 | if (m_CurrentFrame > m_Frames - 1) { 44 | m_CurrentFrame = 0; 45 | } 46 | } 47 | } 48 | 49 | bool CAnimation::LoadNextFrame(SFrame *frame) { 50 | DTRACE(); 51 | if (m_FramesLoaded == m_Frames) { 52 | return true; 53 | } 54 | 55 | CIFaceStatic *st = m_FramesBuffer + m_FramesLoaded; 56 | // st->m_strName = frame->name; 57 | st->m_xPos = frame->pos_x; 58 | st->m_yPos = frame->pos_y; 59 | st->m_zPos = frame->pos_z; 60 | st->m_xSize = frame->width; 61 | st->m_ySize = frame->height; 62 | st->m_DefState = IFACE_NORMAL; 63 | 64 | st->SetStateImage(IFACE_NORMAL, frame->tex, frame->tex_pos_x, frame->tex_pos_y, frame->tex_width, 65 | frame->tex_height); 66 | 67 | st->ElementGeomInit((void *)st); 68 | 69 | D3DXVECTOR3 dp(st->m_xPos + frame->ipos_x, st->m_yPos + frame->ipos_y, st->m_zPos); 70 | 71 | int nC = 0; 72 | while (st->m_StateImages[nC].Set && nC < MAX_STATES) { 73 | for (int i = 0; i < 4; i++) { 74 | st->m_StateImages[nC].m_Geom[i].p.x += dp.x; 75 | st->m_StateImages[nC].m_Geom[i].p.y += dp.y; 76 | st->m_StateImages[nC].m_Geom[i].p.z += dp.z; 77 | st->m_PosElInX = dp.x; 78 | st->m_PosElInY = dp.y; 79 | } 80 | nC++; 81 | } 82 | 83 | m_FramesLoaded++; 84 | return false; 85 | } 86 | 87 | CIFaceElement *CAnimation::GetCurrentFrame() { 88 | return (CIFaceElement *)m_FramesBuffer + m_CurrentFrame; 89 | } 90 | 91 | void CAnimation::RecalcPos(const float &ix, const float &iy) { 92 | DTRACE(); 93 | 94 | for (int i = 0; i < m_FramesLoaded; i++) { 95 | CIFaceElement *pElement = (CIFaceElement *)(m_FramesBuffer + i); 96 | int nC; 97 | for (nC = 0; nC < MAX_STATES; nC++) { 98 | if (pElement->m_StateImages[nC].Set) { 99 | pElement->m_StateImages[nC].m_Geom[0].p = D3DXVECTOR4(0, pElement->m_ySize, 0, 1); 100 | pElement->m_StateImages[nC].m_Geom[1].p = D3DXVECTOR4(0, 0, 0, 1); 101 | pElement->m_StateImages[nC].m_Geom[2].p = D3DXVECTOR4(pElement->m_xSize, pElement->m_ySize, 0, 1); 102 | pElement->m_StateImages[nC].m_Geom[3].p = D3DXVECTOR4(pElement->m_xSize, 0, 0, 1); 103 | } 104 | } 105 | 106 | D3DXVECTOR3 dp(pElement->m_xPos + ix, pElement->m_yPos + iy, pElement->m_zPos); 107 | 108 | nC = 0; 109 | while (pElement->m_StateImages[nC].Set && nC < MAX_STATES) { 110 | for (int i = 0; i < 4; i++) { 111 | pElement->m_StateImages[nC].m_Geom[i].p.x += dp.x; 112 | pElement->m_StateImages[nC].m_Geom[i].p.y += dp.y; 113 | pElement->m_StateImages[nC].m_Geom[i].p.z += dp.z; 114 | pElement->m_PosElInX = dp.x; 115 | pElement->m_PosElInY = dp.y; 116 | } 117 | nC++; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CAnimation.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | class CIFaceStatic; 7 | class CIFaceElement; 8 | 9 | #include "Texture.hpp" 10 | 11 | struct SFrame { 12 | float pos_x; 13 | float pos_y; 14 | float pos_z; 15 | 16 | float width; 17 | float height; 18 | 19 | float tex_width; 20 | float tex_height; 21 | float tex_pos_x; 22 | float tex_pos_y; 23 | 24 | // CWStr name; 25 | CTextureManaged *tex; 26 | float ipos_x; 27 | float ipos_y; 28 | }; 29 | 30 | class CAnimation : public CMain { 31 | int m_Period; 32 | int m_Frames; 33 | int m_CurrentFrame; 34 | int m_FramesLoaded; 35 | int m_TimePass; 36 | 37 | CIFaceStatic *m_FramesBuffer; 38 | 39 | public: 40 | int GetFramesTotal() { return m_Frames; } 41 | int GetFramesLoaded() { return m_FramesLoaded; } 42 | int GetCurrentFrameNum() { return m_CurrentFrame; } 43 | CIFaceElement *GetCurrentFrame(); 44 | 45 | void LogicTakt(int ms); 46 | bool LoadNextFrame(SFrame *frame); 47 | 48 | void RecalcPos(const float &ix, const float &y); 49 | 50 | CAnimation(int frames, int period); 51 | ~CAnimation(); 52 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CCounter.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CIFaceElement.h" 7 | #include "CCounter.h" 8 | #include "../MatrixSide.hpp" 9 | #include "CConstructor.h" 10 | #include "CInterface.h" 11 | 12 | CIFaceCounter::CIFaceCounter() { 13 | m_Counter = 1; 14 | ZeroMemory(m_CounterImage, sizeof(m_CounterImage)); 15 | m_ButtonDown = NULL; 16 | m_ButtonUp = NULL; 17 | } 18 | 19 | CIFaceCounter::~CIFaceCounter() {} 20 | 21 | void CIFaceCounter::ManageButtons() { 22 | if ((m_Counter == UP_LIMIT) && m_ButtonUp) { 23 | m_ButtonUp->SetState(IFACE_DISABLED); 24 | } 25 | else if (m_ButtonUp) { 26 | m_ButtonUp->SetState(IFACE_NORMAL); 27 | } 28 | 29 | if (m_Counter == DOWN_LIMIT && m_ButtonDown) { 30 | m_ButtonDown->SetState(IFACE_DISABLED); 31 | } 32 | else if (m_ButtonDown) { 33 | m_ButtonDown->SetState(IFACE_NORMAL); 34 | } 35 | } 36 | 37 | void CIFaceCounter::MulRes() { 38 | g_IFaceList->CreateSummPrice(m_Counter); 39 | // CMatrixSideUnit* ps = g_MatrixMap->GetPlayerSide(); 40 | // SPrice price; 41 | // ps->m_ConstructPanel->m_Configs[ps->m_ConstructPanel->m_CurrentConfig].CalcConfigPrice(&price); 42 | // for(int i = 0; i < MAX_RESOURCES; i++){ 43 | // ps->m_ConstructPanel->m_Configs[ps->m_ConstructPanel->m_CurrentConfig].m_TotalPrice.m_Resources[i] = 44 | // price.m_Resources[i] * m_Counter; 45 | //} 46 | } 47 | 48 | void CIFaceCounter::DivRes() { 49 | g_IFaceList->CreateSummPrice(m_Counter); 50 | 51 | // CMatrixSideUnit* ps = g_MatrixMap->GetPlayerSide(); 52 | // SPrice price; 53 | // ps->m_ConstructPanel->m_Configs[ps->m_ConstructPanel->m_CurrentConfig].CalcConfigPrice(&price); 54 | // for(int i = 0; i < MAX_RESOURCES; i++){ 55 | // ps->m_ConstructPanel->m_Configs[ps->m_ConstructPanel->m_CurrentConfig].m_TotalPrice.m_Resources[i] = 56 | // price.m_Resources[i] * m_Counter; 57 | //} 58 | } 59 | 60 | void CIFaceCounter::CheckUp() { 61 | // check for robot_summ * m_Counter <= player_res 62 | 63 | CMatrixSideUnit *ps = g_MatrixMap->GetPlayerSide(); 64 | // SPrice price; 65 | // ps->m_ConstructPanel->m_Configs[ps->m_ConstructPanel->m_CurrentConfig].CalcConfigPrice(&price); 66 | int resources[MAX_RESOURCES]; 67 | int res[MAX_RESOURCES], res2[MAX_RESOURCES]; 68 | 69 | ps->m_Constructor->GetConstructionPrice(resources); 70 | 71 | for (int i = 0; i < MAX_RESOURCES; i++) { 72 | res[i] = resources[i] * (m_Counter + 1); 73 | res2[i] = resources[i] * (m_Counter); 74 | } 75 | if (!ps->IsEnoughResources(res2)) { 76 | if (m_ButtonUp) 77 | m_ButtonUp->SetState(IFACE_DISABLED); 78 | if (m_ButtonDown) 79 | m_ButtonUp->SetState(IFACE_DISABLED); 80 | m_Counter = 0; 81 | } 82 | if (!ps->IsEnoughResources(res) || 83 | (ps->GetSideRobots() + ps->GetRobotsInStack() + m_Counter >= ps->GetMaxSideRobots())) { 84 | if (m_ButtonUp) 85 | m_ButtonUp->SetState(IFACE_DISABLED); 86 | } 87 | 88 | if (ps->m_ActiveObject && ps->m_ActiveObject->IsBuilding() && ps->m_ActiveObject->IsBase()) { 89 | CMatrixBuilding *base = (CMatrixBuilding *)ps->m_ActiveObject; 90 | // 91 | if ((base->m_BS.GetItemsCnt() + m_Counter + 1) > 6 /*max stack items*/) { 92 | if (m_ButtonUp) 93 | m_ButtonUp->SetState(IFACE_DISABLED); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CCounter.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #define COUNTER_IMAGES 7 7 | #define UP_LIMIT 6 8 | #define DOWN_LIMIT 1 9 | 10 | class CIFaceElement; 11 | 12 | class CIFaceCounter : public CMain { 13 | int m_Counter; 14 | CIFaceElement *m_CounterImage[COUNTER_IMAGES]; 15 | CIFaceElement *m_ButtonUp, *m_ButtonDown; 16 | 17 | void MulRes(); 18 | void DivRes(); 19 | 20 | public: 21 | int GetCounter() { return m_Counter; } 22 | CIFaceElement *GetImage() { return m_CounterImage[m_Counter]; } 23 | void SetImage(int i, CIFaceElement *image) { m_CounterImage[i] = image; } 24 | CIFaceElement *GetZeroImage() { return m_CounterImage[0]; } 25 | int Inc() { 26 | if (++m_Counter > UP_LIMIT) 27 | m_Counter = UP_LIMIT; 28 | return m_Counter; 29 | } 30 | int Dec() { 31 | if (--m_Counter < DOWN_LIMIT) 32 | m_Counter = DOWN_LIMIT; 33 | return m_Counter; 34 | } 35 | 36 | void SetButtonDown(CIFaceElement *button) { m_ButtonDown = button; } 37 | void SetButtonUp(CIFaceElement *button) { m_ButtonUp = button; } 38 | void ManageButtons(); 39 | 40 | void CheckUp(); 41 | void Reset() { 42 | m_Counter = DOWN_LIMIT; 43 | ManageButtons(); 44 | } 45 | void __stdcall Up(void*) { 46 | Inc(); 47 | ManageButtons(); 48 | MulRes(); 49 | CheckUp(); 50 | } 51 | void __stdcall Down(void*) { 52 | Dec(); 53 | ManageButtons(); 54 | DivRes(); 55 | CheckUp(); 56 | } 57 | 58 | void Disable() { 59 | if (m_ButtonDown) 60 | m_ButtonDown->SetState(IFACE_DISABLED); 61 | if (m_ButtonUp) 62 | m_ButtonUp->SetState(IFACE_DISABLED); 63 | m_Counter = 0; 64 | } 65 | void Enable() { 66 | if (m_ButtonDown) 67 | m_ButtonDown->SetState(IFACE_NORMAL); 68 | if (m_ButtonUp) 69 | m_ButtonUp->SetState(IFACE_NORMAL); 70 | Reset(); 71 | CheckUp(); 72 | } 73 | 74 | CIFaceCounter(); 75 | ~CIFaceCounter(); 76 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CHistory.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CHistory.h" 7 | #include "../MatrixGame.h" 8 | #include "../MatrixMap.hpp" 9 | 10 | CHistory *g_ConfigHistory; 11 | 12 | CHistory::CHistory() { 13 | m_FirstConfig = NULL; 14 | m_LastConfig = NULL; 15 | m_CurrentConfig = NULL; 16 | } 17 | 18 | CHistory::~CHistory() { 19 | SRobotConfig *cfgs = m_FirstConfig; 20 | 21 | while (cfgs) { 22 | SRobotConfig *next = cfgs->m_NextConfig; 23 | HDelete(SRobotConfig, cfgs, g_MatrixHeap); 24 | cfgs = next; 25 | } 26 | m_FirstConfig = NULL; 27 | m_LastConfig = NULL; 28 | } 29 | 30 | void CHistory::AddConfig(SRobotConfig *config) { 31 | DTRACE(); 32 | DelConfig(config); 33 | SRobotConfig *new_cfg = HNew(g_MatrixHeap) SRobotConfig; 34 | memcpy(new_cfg, config, sizeof(SRobotConfig)); 35 | m_CurrentConfig = new_cfg; 36 | LIST_ADD(new_cfg, m_FirstConfig, m_LastConfig, m_PrevConfig, m_NextConfig); 37 | } 38 | 39 | void CHistory::DelConfig(SRobotConfig *config) { 40 | DTRACE(); 41 | SRobotConfig *confs = m_FirstConfig; 42 | while (confs) { 43 | bool gotcha = false; 44 | if (confs->m_Head.m_nKind == config->m_Head.m_nKind && confs->m_Chassis.m_nKind == config->m_Chassis.m_nKind && 45 | confs->m_Hull.m_Unit.m_nKind == config->m_Hull.m_Unit.m_nKind) { 46 | gotcha = true; 47 | } 48 | 49 | if (gotcha) { 50 | for (int i = 0; i < MAX_WEAPON_CNT; i++) { 51 | if (confs->m_Weapon[i].m_nKind != config->m_Weapon[i].m_nKind) { 52 | gotcha = false; 53 | break; 54 | } 55 | } 56 | } 57 | 58 | if (gotcha) { 59 | SRobotConfig *next = confs->m_NextConfig; 60 | LIST_DEL(confs, m_FirstConfig, m_LastConfig, m_PrevConfig, m_NextConfig); 61 | HDelete(SRobotConfig, confs, g_MatrixHeap); 62 | confs = next; 63 | continue; 64 | } 65 | confs = confs->m_NextConfig; 66 | } 67 | } 68 | 69 | void CHistory::LoadCurrentConfigToConstructor() { 70 | DTRACE(); 71 | if (m_CurrentConfig) { 72 | CMatrixSideUnit *ps = g_MatrixMap->GetPlayerSide(); 73 | ps->m_Constructor->SuperDjeans(MRT_HEAD, m_CurrentConfig->m_Head.m_nKind, 0, true); 74 | ps->m_Constructor->SuperDjeans(MRT_ARMOR, m_CurrentConfig->m_Hull.m_Unit.m_nKind, 0, true); 75 | for (int i = 0; i < MAX_WEAPON_CNT; i++) { 76 | if (m_CurrentConfig->m_Weapon[i].m_nKind) 77 | ps->m_Constructor->SuperDjeans(MRT_WEAPON, m_CurrentConfig->m_Weapon[i].m_nKind, i, true); 78 | } 79 | ps->m_Constructor->SuperDjeans(MRT_CHASSIS, m_CurrentConfig->m_Chassis.m_nKind, 0, true); 80 | } 81 | } 82 | 83 | void __stdcall CHistory::PrevConfig(void*) { 84 | DTRACE(); 85 | if (m_CurrentConfig && m_CurrentConfig->m_PrevConfig) { 86 | m_CurrentConfig = m_CurrentConfig->m_PrevConfig; 87 | LoadCurrentConfigToConstructor(); 88 | } 89 | } 90 | 91 | void __stdcall CHistory::NextConfig(void*) { 92 | DTRACE(); 93 | if (m_CurrentConfig && m_CurrentConfig->m_NextConfig) { 94 | m_CurrentConfig = m_CurrentConfig->m_NextConfig; 95 | LoadCurrentConfigToConstructor(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CHistory.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CConstructor.h" 7 | 8 | class CHistory : public CMain { 9 | SRobotConfig *m_CurrentConfig; 10 | 11 | void LoadCurrentConfigToConstructor(); 12 | void DelConfig(SRobotConfig *config); 13 | void FindConfig(SRobotConfig *config); 14 | 15 | public: 16 | SRobotConfig *m_FirstConfig; 17 | SRobotConfig *m_LastConfig; 18 | 19 | void AddConfig(SRobotConfig *config); 20 | void __stdcall PrevConfig(void *object); 21 | void __stdcall NextConfig(void *object); 22 | 23 | bool IsNext() { 24 | if (m_CurrentConfig && m_CurrentConfig->m_NextConfig) 25 | return true; 26 | else 27 | return false; 28 | } 29 | bool IsPrev() { 30 | if (m_CurrentConfig && m_CurrentConfig->m_PrevConfig) 31 | return true; 32 | else 33 | return false; 34 | } 35 | 36 | CHistory(); 37 | ~CHistory(); 38 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceButton.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "Interface.h" 7 | #include "CIFaceElement.h" 8 | 9 | ////////////////////////////////////////////////// 10 | // Button Class 11 | class CIFaceButton : public CIFaceElement { 12 | public: 13 | bool OnMouseMove(CPoint); 14 | void OnMouseLBUp(); 15 | bool OnMouseLBDown(); 16 | bool OnMouseRBDown(); 17 | 18 | CIFaceButton(); 19 | ~CIFaceButton(); 20 | }; 21 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceElement.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #include "Interface.h" 11 | #include "../MatrixMap.hpp" 12 | #include "../MatrixObject.hpp" 13 | #include "../MatrixRobot.hpp" 14 | 15 | class CAnimation; 16 | 17 | ////////////////////////////////////////////////// 18 | // Interface Element Class 19 | 20 | #define IFEF_VISIBLE SETBIT(0) 21 | #define IFEF_CLEARRECT SETBIT(1) 22 | 23 | struct SElementHint { 24 | std::wstring HintTemplate; 25 | int timer; 26 | int x; 27 | int y; 28 | SElementHint() : HintTemplate{} { 29 | timer = 0; 30 | x = 0; 31 | y = 0; 32 | } 33 | }; 34 | 35 | struct SAction { 36 | std::function m_function; 37 | }; 38 | 39 | #define FSET(act, pBut, pObj, src) \ 40 | { \ 41 | auto obj = pObj; \ 42 | auto func = &src; \ 43 | pBut->m_Actions[act].m_function = [obj, func](void* param) { (*obj.*func)(param); }; \ 44 | } 45 | 46 | class CIFaceElement : public CMain { 47 | DWORD m_Flags; 48 | 49 | public: 50 | CRect m_ClearRect; // rect for clearing Z buffer 51 | SElementHint m_Hint; 52 | CAnimation *m_Animation; 53 | byte m_VisibleAlpha; 54 | SStateImages m_StateImages[MAX_STATES]; 55 | std::wstring m_strName; 56 | float m_Param1; 57 | float m_Param2; 58 | int m_iParam; 59 | int m_nId; 60 | int m_nGroup; 61 | 62 | IFaceElementType m_Type; 63 | float m_xPos, m_yPos, m_zPos, m_xSize, m_ySize, m_PosElInX, m_PosElInY; 64 | CIFaceElement *m_NextElement, *m_PrevElement; 65 | 66 | SAction m_Actions[MAX_ACTIONS]; 67 | 68 | IFaceElementState m_CurState; 69 | IFaceElementState m_DefState; 70 | 71 | void Action(EActions action); 72 | // CSound m_StateSounds;//MAX_STATES 73 | // bool SetStateSound(IFaceElementState State, CSound Sound); 74 | 75 | IFaceElementState GetState(); 76 | bool SetState(IFaceElementState State); 77 | bool SetStateImage(IFaceElementState State, CTextureManaged *pImage, float x, float y, float width, float height); 78 | LPDIRECT3DTEXTURE9 GetStateImage(IFaceElementState State); 79 | 80 | bool GetVisibility(void) const { return FLAG(m_Flags, IFEF_VISIBLE); } 81 | void SetVisibility(bool visible); 82 | 83 | bool HasClearRect(void) const { return FLAG(m_Flags, IFEF_CLEARRECT); } 84 | void SetClearRect(void) { SETFLAG(m_Flags, IFEF_CLEARRECT); } 85 | 86 | bool ElementCatch(CPoint); 87 | bool ElementAlpha(CPoint mouse); 88 | 89 | virtual void CheckGroupReset(CIFaceElement *, CIFaceElement *); 90 | virtual void ElementGeomInit(void *pObj, bool full_size = false); 91 | virtual bool OnMouseMove(CPoint) { return false; } 92 | virtual void OnMouseLBUp() {} 93 | virtual bool OnMouseLBDown() { return false; } 94 | virtual bool OnMouseRBDown() { return false; } 95 | virtual void BeforeRender(void); 96 | virtual void Render(BYTE m_VisibleAlpha); 97 | virtual void Reset(); 98 | void LogicTakt(int ms); 99 | 100 | void RecalcPos(const float &x, const float &y, bool ichanged = true); 101 | 102 | // void GenerateClearRect(void); 103 | 104 | CIFaceElement(); 105 | ~CIFaceElement(); 106 | }; 107 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceImage.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CIFaceImage.h" 7 | 8 | CIFaceImage::CIFaceImage() { 9 | m_Image = NULL; 10 | m_PrevImage = NULL; 11 | m_NextImage = NULL; 12 | m_xTexPos = 0; 13 | m_yTexPos = 0; 14 | m_TexWidth = 0; 15 | m_TexHeight = 0; 16 | m_Width = 0; 17 | m_Height = 0; 18 | m_strName = L""; 19 | m_Type = IFACE_IMAGE; 20 | } 21 | 22 | CIFaceImage::~CIFaceImage() {} 23 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceImage.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "Interface.h" 7 | #include "CIFaceElement.h" 8 | 9 | //////////////////////////////////////////////////////// 10 | // Image container class 11 | 12 | class CIFaceImage : public CMain { 13 | public: 14 | CTextureManaged *m_Image; 15 | std::wstring m_strName; 16 | float m_xTexPos; 17 | float m_yTexPos; 18 | float m_TexWidth; 19 | float m_TexHeight; 20 | float m_Width; 21 | float m_Height; 22 | IFaceElementType m_Type; 23 | CIFaceImage *m_PrevImage, *m_NextImage; 24 | 25 | CIFaceImage(); 26 | ~CIFaceImage(); 27 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceMenu.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "Texture.hpp" 9 | 10 | class CInterface; 11 | class CIFaceStatic; 12 | class CIFaceElement; 13 | class CIFaceImage; 14 | struct SRobotConfig; 15 | enum ERobotUnitType : unsigned int; 16 | enum ERobotUnitKind : unsigned int; 17 | 18 | #define UNIT_HEIGHT 19 19 | #define TOPLEFT_HEIGHT 18 20 | #define TOPLEFT_WIDTH 13 21 | #define TOPRIGHT_HEIGHT 18 22 | #define TOPRIGHT_WIDTH 18 23 | #define BOTTOMLEFT_HEIGHT 22 24 | #define BOTTOMLEFT_WIDTH 14 25 | #define BOTTOMRIGHT_HEIGHT 21 26 | #define BOTTOMRIGHT_WIDTH 13 27 | #define TOPLINE_HEIGHT 18 28 | #define TOPLINE_WIDTH 1 29 | #define BOTTOMLINE_HEIGHT 22 30 | #define BOTTOMLINE_WIDTH 1 31 | #define RIGHTLINE_HEIGHT 1 32 | #define RIGHTLINE_WIDTH 18 33 | #define LEFTLINE_HEIGHT 1 34 | #define LEFTLINE_WIDTH 13 35 | #define CURSIK_WIDTH 7 36 | #define LEFT_SPACE 7 37 | 38 | #define DEFAULT_LABELS_COLOR 0xFFF6c000 39 | #define NERES_LABELS_COLOR 0xFFFF4319 40 | #define SELECTED_LABELS_COLOR 0xFFFFFFFF 41 | 42 | #define _ENGLISH_BUILD 43 | 44 | #ifdef _ENGLISH_BUILD 45 | #define WEAPON_MENU_WIDTH 95 46 | #define HULL_MENU_WIDTH 60 47 | #define HEAD_MENU_WIDTH 45 48 | #define CHASSIS_MENU_WIDTH 60 49 | #else 50 | #define WEAPON_MENU_WIDTH 70 51 | #define HULL_MENU_WIDTH 90 52 | #define HEAD_MENU_WIDTH 100 53 | #define CHASSIS_MENU_WIDTH 90 54 | #endif 55 | 56 | enum EMenuParent { 57 | MENU_PARENT_UNDEF = 0, 58 | MENU_PARENT_PILON1 = 1, 59 | MENU_PARENT_PILON2 = 2, 60 | MENU_PARENT_PILON3 = 3, 61 | MENU_PARENT_PILON4 = 4, 62 | MENU_PARENT_PILON5 = 5, 63 | MENU_PARENT_HEAD = 6, 64 | MENU_PARENT_HULL = 7, 65 | MENU_PARENT_CHASSIS = 8, 66 | }; 67 | struct SMenuItemText { 68 | std::wstring text; 69 | DWORD color; 70 | SMenuItemText(void*) : text{} { color = DEFAULT_LABELS_COLOR; } 71 | }; 72 | 73 | inline int GetIndexFromTK(ERobotUnitType type, ERobotUnitKind kind); 74 | 75 | class CIFaceMenu : public CMain { 76 | float m_Width; 77 | float m_Height; 78 | int m_ElementsNum; 79 | 80 | bool m_Visible; 81 | 82 | CIFaceStatic *m_Ramka; 83 | CIFaceStatic *m_Selector; 84 | CIFaceStatic *m_Cursor; 85 | CIFaceImage *m_CursikImage; 86 | 87 | CTextureManaged *m_RamTex; 88 | 89 | int m_CurMenuPos; 90 | EMenuParent m_InterfaceParent; 91 | 92 | CIFaceElement *m_Caller; 93 | 94 | SRobotConfig *m_RobotConfig; 95 | 96 | public: 97 | static CInterface *m_MenuGraphics; 98 | static bool LoadMenuGraphics(CBlockPar &bp); 99 | void CreateMenu(EMenuParent parent, int elements, int width, int x, int y, CIFaceElement *caller, 100 | SMenuItemText *labels = NULL, DWORD color = 0); 101 | 102 | void SetSelectorPos(const float &x, const float &y, int pos); 103 | bool Selector() { return m_Selector != NULL; } 104 | CIFaceStatic *GetRamka() { return m_Ramka; } 105 | 106 | EMenuParent GetMenuParent() { return m_InterfaceParent; } 107 | 108 | void OnMenuItemPress(); 109 | void CalcSelectedItem(bool set); 110 | 111 | void ResetMenu(bool canceled); 112 | 113 | CIFaceMenu(); 114 | ~CIFaceMenu(); 115 | }; 116 | 117 | extern CIFaceMenu *g_PopupMenu; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceStatic.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CIFaceStatic.h" 7 | #include "CIFaceMenu.h" 8 | #include "CInterface.h" 9 | #include "MatrixHint.hpp" 10 | 11 | CIFaceStatic::CIFaceStatic() { 12 | m_Type = IFACE_STATIC; 13 | m_xPos = m_yPos = m_zPos = m_xSize = m_ySize = 0; 14 | m_NextElement = m_PrevElement = NULL; 15 | m_CurState = IFACE_NORMAL; 16 | } 17 | 18 | CIFaceStatic::~CIFaceStatic() {} 19 | 20 | bool CIFaceStatic::OnMouseMove(CPoint mouse) { 21 | if (ElementCatch(mouse)) { 22 | if (g_IFaceList->m_CurrentHint == NULL && m_Hint.HintTemplate != L"") { 23 | if (g_IFaceList->CheckShowHintLogic(m_strName)) { 24 | g_IFaceList->AddHintReplacements(m_strName); 25 | CMatrixHint *hint = CMatrixHint::Build(m_Hint.HintTemplate, m_strName.c_str()); 26 | int x = Float2Int(m_PosElInX) + m_Hint.x; 27 | int y = Float2Int(m_PosElInY) + m_Hint.y; 28 | g_IFaceList->CorrectCoordinates(g_ScreenX, g_ScreenY, x, y, hint->m_Width, hint->m_Height, m_strName); 29 | hint->Show(x, y); 30 | g_IFaceList->m_CurrentHint = hint; 31 | g_IFaceList->m_CurrentHintControlName = m_strName; 32 | } 33 | } 34 | if (ElementAlpha(mouse)) 35 | return TRUE; 36 | } 37 | else { 38 | if (g_IFaceList->m_CurrentHint && g_IFaceList->m_CurrentHintControlName == m_strName) { 39 | g_IFaceList->m_CurrentHint->Release(); 40 | g_IFaceList->m_CurrentHint = NULL; 41 | g_IFaceList->m_CurrentHintControlName = L""; 42 | } 43 | return FALSE; 44 | } 45 | return false; 46 | } 47 | 48 | bool CIFaceStatic::OnMouseLBDown() { 49 | Action(ON_PRESS); 50 | return FALSE; 51 | } 52 | 53 | void CIFaceStatic::OnMouseLBUp() { 54 | Action(ON_UN_PRESS); 55 | } 56 | 57 | bool CIFaceStatic::OnMouseRBDown() { 58 | // CPoint mouse = g_MatrixMap->m_Cursor.GetPos(); 59 | // if(ElementCatch(mouse) && ElementAlpha(mouse)){ 60 | // return true; 61 | // }else{ 62 | // return false; 63 | // } 64 | return false; 65 | } 66 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/CIFaceStatic.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "Interface.h" 7 | #include "CIFaceElement.h" 8 | 9 | //////////////////////////////////////////////////////// 10 | // Static Image Class 11 | 12 | class CIFaceStatic : public CIFaceElement { 13 | public: 14 | bool OnMouseLBDown(); 15 | void OnMouseLBUp(); 16 | bool OnMouseMove(CPoint); 17 | bool OnMouseRBDown(); 18 | 19 | CIFaceStatic(); 20 | ~CIFaceStatic(); 21 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Interface/Interface.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #define MAX_STATES 5 9 | #define MAX_ACTIONS 4 10 | 11 | #include "../MatrixInstantDraw.hpp" 12 | 13 | enum IFaceElementType { 14 | IFACE_UNDEF = -1, 15 | IFACE_STATIC = 0, 16 | IFACE_ANIMATION = 1, 17 | IFACE_PUSH_BUTTON = 2, 18 | IFACE_ANIMATED_BUTTON = 3, 19 | IFACE_CHECK_BUTTON = 4, 20 | IFACE_DYNAMIC_STATIC = 5, 21 | IFACE_IMAGE = 6, 22 | IFACE_CHECK_BUTTON_SPECIAL = 7, 23 | IFACE_CHECK_PUSH_BUTTON = 8, 24 | 25 | IFaceElementType_FORCE_DWORD = 0x7FFFFFFF 26 | }; 27 | 28 | enum IFaceElementState { 29 | IFACE_NORMAL = 0, 30 | IFACE_FOCUSED = 1, 31 | IFACE_PRESSED = 2, 32 | IFACE_DISABLED = 3, 33 | IFACE_PRESSED_UNFOCUSED = 4, 34 | 35 | IFaceElementState_FORCE_DWORD = 0x7FFFFFFF 36 | }; 37 | 38 | enum EIFaceLabel { 39 | IFACE_STATIC_LABEL = 0, 40 | IFACE_DYNAMIC_LABEL = 1, 41 | IFACE_STATE_STATIC_LABEL = 2, 42 | 43 | EIFaceLabel_FORCE_DWORD = 0x7FFFFFFF 44 | }; 45 | 46 | enum EActions { 47 | ON_PRESS = 0, 48 | ON_UN_PRESS = 1, 49 | ON_FOCUS = 2, 50 | ON_UN_FOCUS = 3, 51 | 52 | EActions_FORCE_DWORD = 0x7FFFFFFF 53 | }; 54 | 55 | struct SStateImages { 56 | CTextureManaged *pImage; 57 | SVert_V4_UV m_Geom[4]; 58 | float xTexPos; 59 | float yTexPos; 60 | float TexWidth; 61 | float TexHeight; 62 | 63 | int m_x; 64 | int m_y; 65 | int m_boundX; 66 | int m_boundY; 67 | int m_xAlign; 68 | int m_yAlign; 69 | int m_Perenos; 70 | int m_SmeX; 71 | int m_SmeY; 72 | CRect m_ClipRect; 73 | std::wstring m_Caption; 74 | std::wstring m_Font; 75 | DWORD m_Color; 76 | 77 | DWORD Set; // This is boolean var. Used DWORD becouse align! 78 | 79 | void SetStateText(bool copy); 80 | void SetStateLabelParams(int x, int y, int bound_x, int bound_y, int xAlign, int yAlign, int perenos, int smeX, 81 | int smeY, CRect clipRect, std::wstring t, std::wstring font, DWORD color); 82 | 83 | SStateImages() : m_Caption{}, m_Font{} { 84 | xTexPos = yTexPos = TexWidth = TexHeight = 0; 85 | m_x = m_y = m_boundX = m_boundY = m_xAlign = m_yAlign = m_Perenos = m_SmeX = m_SmeY = 0; 86 | m_Color = 0; 87 | pImage = NULL; 88 | ZeroMemory(m_Geom, sizeof(m_Geom)); 89 | ZeroMemory(&m_ClipRect, sizeof(CRect)); 90 | Set = false; 91 | } 92 | }; 93 | 94 | ///////////////////////////////////////////////// 95 | extern IDirect3DDevice9 *g_D3DD; 96 | extern CHeap *g_MatrixHeap; 97 | extern CCache *g_Cache; 98 | //////////////////////////////////////////////// 99 | -------------------------------------------------------------------------------- /MatrixGame/src/Interface/MatrixHint.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #define HINT_Z 0.0000f 9 | 10 | #include "MatrixGame.h" 11 | #include "Texture.hpp" 12 | #include "CBitmap.hpp" 13 | 14 | struct SHintBitmap { 15 | CBitmap bmp; 16 | std::wstring name; 17 | }; 18 | 19 | enum EHintElementModificator { 20 | HEM_TAB_5 = 5, 21 | HEM_TAB_10 = 10, 22 | HEM_TAB_15 = 15, 23 | HEM_TAB_20 = 20, 24 | HEM_TAB_25 = 25, 25 | HEM_TAB_30 = 30, 26 | HEM_TAB_35 = 35, 27 | HEM_TAB_40 = 40, 28 | HEM_TAB_LARGEST = 1000, // last value 29 | 30 | HEM_CENTER_RIGHT_5 = 1005, 31 | HEM_CENTER_RIGHT_30 = 1030, 32 | HEM_CENTER_RIGHT_LARGEST = 2000, // last value 33 | 34 | HEM_CENTER_LEFT_5 = 2005, 35 | HEM_CENTER_LEFT_30 = 2030, 36 | HEM_CENTER_LEFT_LARGEST = 3000, // last value 37 | 38 | HEM_COPY, // next bitmap will be copied instead of merged 39 | HEM_BITMAP, 40 | HEM_CENTER, 41 | HEM_LAST_ON_LINE, 42 | HEM_COORD, // next bitmap with specified coords 43 | HEM_DOWN, // just down 44 | HEM_RIGHT, // just right 45 | HEM_LAST, 46 | 47 | EHintElementModificator_FORCE_DWORD = 0x7FFFFFFF 48 | }; 49 | 50 | struct SHintElement { 51 | union { 52 | CBitmap *bmp; 53 | struct { 54 | signed short x, y; 55 | }; 56 | }; 57 | EHintElementModificator hem; 58 | }; 59 | 60 | class CMatrixHint : public CMain 61 | { 62 | std::wstring m_SoundIn; 63 | std::wstring m_SoundOut; 64 | 65 | DWORD m_Flags; 66 | CTextureManaged *m_Texture; 67 | 68 | std::vector m_CopyPos; 69 | 70 | CMatrixHint(CTextureManaged *tex, int w, int h, const std::wstring &si, const std::wstring &so); 71 | ~CMatrixHint(); 72 | 73 | public: 74 | int m_PosX; 75 | int m_PosY; 76 | int m_Width; 77 | int m_Height; 78 | 79 | static void StaticInit(void) { 80 | } 81 | 82 | static void PreloadBitmaps(void); 83 | 84 | static CMatrixHint *Build(int border, const std::wstring &soundin, const std::wstring &soundout, SHintElement *elems, 85 | CRect *otstup = nullptr); 86 | static CMatrixHint *Build(const std::wstring &templatename, const wchar *baserepl = nullptr); 87 | static CMatrixHint *Build(const std::wstring &str, CBlockPar *repl, const wchar *baserepl = nullptr); 88 | void Release(void) { 89 | SetVisible(false); 90 | HDelete(CMatrixHint, this, g_MatrixHeap); 91 | } 92 | 93 | void SoundIn(void) const; 94 | void SoundOut(void) const; 95 | 96 | bool IsVisible(void) const { return m_Flags != 0; } 97 | void SetVisible(bool flag) { 98 | if ((m_Flags != 0) != flag) { 99 | if (flag) { 100 | SoundIn(); 101 | } 102 | else { 103 | SoundOut(); 104 | } 105 | } 106 | m_Flags = flag; 107 | } 108 | 109 | void Show(int x, int y) { 110 | m_PosX = x; 111 | m_PosY = y; 112 | SetVisible(true); 113 | } 114 | 115 | int GetCopyPosCnt(void) const { return m_CopyPos.size(); } 116 | const CPoint &GetCopyPos(int i) const { return m_CopyPos[i]; } 117 | 118 | void DrawNow(void); 119 | static void DrawAll(void); 120 | static void ClearAll(void); 121 | }; -------------------------------------------------------------------------------- /MatrixGame/src/Logic/MatrixLogicSlot.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixLogicSlot.h" 7 | #include "MatrixState.h" 8 | #include "../MatrixMap.hpp" 9 | #include "../MatrixRobot.hpp" 10 | 11 | // CMatrixLogicSlot::~CMatrixLogicSlot() 12 | //{ 13 | // DTRACE(); 14 | // 15 | // CMatrixState *State = m_FirstState; 16 | // while(State != NULL){ 17 | // if(State->m_NextState) 18 | // State = State->m_NextState; 19 | // else { 20 | // HDelete(CMatrixState, State, g_MatrixHeap); 21 | // State = NULL; 22 | // m_FirstState = NULL; 23 | // m_LastState = NULL; 24 | // 25 | // } 26 | // 27 | // if(State) 28 | // HDelete(CMatrixState, State->m_PrevState, g_MatrixHeap); 29 | // } 30 | // 31 | // CLogicSlotRobot *bot = m_FirstRobot; 32 | // 33 | // while(bot){ 34 | // if(bot->m_NextRobot) 35 | // bot = bot->m_NextRobot; 36 | // else { 37 | // HDelete(CLogicSlotRobot, bot, g_MatrixHeap); 38 | // bot = NULL; 39 | // m_FirstRobot = bot; 40 | // m_LastRobot = bot; 41 | // 42 | // } 43 | // 44 | // if(bot) 45 | // HDelete(CLogicSlotRobot, bot->m_PrevRobot, g_MatrixHeap); 46 | // } 47 | // 48 | //} 49 | // 50 | // void CMatrixLogicSlot::Load(CBlockPar &bp) 51 | //{ 52 | // CWStr filename; 53 | // //filename.Add(L"#LO_"); 54 | // //filename.Add(GetName()); 55 | // //filename.Add(L"_"); 56 | // //filename.Add(((CMatrixTactics*)GetParent())->GetName()); 57 | // //filename.Add(L".txt"); 58 | // //bp.SaveInTextFile(filename); 59 | // 60 | // m_Cells.m_MinCells = bp.ParNE(L"MinCells").GetInt(); 61 | // m_Cells.m_MaxCells = bp.ParNE(L"MaxCells").GetInt(); 62 | // 63 | // CWStr DefStateName(L""); 64 | // DefStateName = bp.ParGetNE(L"DefState"); 65 | // 66 | // // 67 | // int states_cnt = bp.BlockCount(); 68 | // for(int cnt = 0; cnt < states_cnt; cnt++){ 69 | // CWStr blockname = bp.BlockGetName(cnt); 70 | // CMatrixState *state = HNew(g_MatrixHeap) CMatrixState(); 71 | // state->SetName(blockname); 72 | // state->SetParent(this); 73 | // if(blockname == DefStateName){ 74 | // m_ActiveState = state; 75 | // } 76 | // state->Load(*bp.BlockGet(cnt)); 77 | // LIST_ADD(state, m_FirstState, m_LastState, m_PrevState, m_NextState); 78 | // } 79 | //} 80 | // 81 | // void CMatrixLogicSlot::RemoveLogicRobotFromList(CMatrixRobotAI* robot) 82 | //{ 83 | // CLogicSlotRobot* ls_robot = m_FirstRobot; 84 | // while(ls_robot){ 85 | // if(ls_robot->GetLogicRobot() == robot){ 86 | // /*robot->BreakAllOrders();*/ 87 | // LIST_DEL(ls_robot, m_FirstRobot, m_LastRobot, m_PrevRobot, m_NextRobot); 88 | // HDelete(CLogicSlotRobot, ls_robot, g_MatrixHeap); 89 | // m_RobotsCnt--; 90 | // return; 91 | // } 92 | // ls_robot = ls_robot->m_NextRobot; 93 | // } 94 | //} 95 | // 96 | // void CMatrixLogicSlot::AddLogicRobotToList(CMatrixRobotAI* robot) 97 | //{ 98 | // CLogicSlotRobot* ls_robot = HNew(g_MatrixHeap) CLogicSlotRobot; 99 | // ls_robot->SetLogicRobot(robot); 100 | // LIST_ADD(ls_robot, m_FirstRobot, m_LastRobot, m_PrevRobot, m_NextRobot); 101 | // m_RobotsCnt++; 102 | //} 103 | // 104 | // bool CMatrixLogicSlot::FindRobot(CMatrixRobotAI* robot) 105 | //{ 106 | // CLogicSlotRobot *bots = m_FirstRobot; 107 | // 108 | // while(bots){ 109 | // if(bots->GetLogicRobot() == robot) 110 | // return true; 111 | // bots = bots->m_NextRobot; 112 | // } 113 | // 114 | // return false; 115 | //} 116 | // 117 | -------------------------------------------------------------------------------- /MatrixGame/src/Logic/MatrixLogicSlot.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "MatrixTactics.h" 9 | #include "CMain.hpp" 10 | 11 | class CMatrixState; 12 | class CMatrixRobotAI; 13 | class CMatrixRule; 14 | 15 | typedef struct _c { 16 | int m_MinCells; 17 | int m_MaxCells; 18 | _c() { 19 | m_MinCells = 0; 20 | m_MaxCells = 0; 21 | } 22 | } Cells; 23 | 24 | class CLogicSlotRobot : public CMain { 25 | CMatrixRobotAI *m_Robot; 26 | CMatrixRule *m_Rule; 27 | 28 | public: 29 | CLogicSlotRobot *m_NextRobot; 30 | CLogicSlotRobot *m_PrevRobot; 31 | 32 | void SetLogicRobot(CMatrixRobotAI *robot) { m_Robot = robot; } 33 | CMatrixRobotAI *GetLogicRobot() { return m_Robot; } 34 | 35 | void SetRule(CMatrixRule *rule) { m_Rule = rule; } 36 | CMatrixRule *GetRule() { return m_Rule; } 37 | 38 | CLogicSlotRobot() { 39 | m_NextRobot = nullptr; 40 | m_PrevRobot = nullptr; 41 | m_Rule = nullptr; 42 | } 43 | ~CLogicSlotRobot() {} 44 | }; 45 | 46 | // class CMatrixLogicSlot : public CBaseTactics 47 | //{ 48 | // CMatrixState* m_ActiveState; 49 | // Cells m_Cells; 50 | // int m_RobotsCnt; 51 | // public: 52 | // CLogicSlotRobot* m_FirstRobot; 53 | // CLogicSlotRobot* m_LastRobot; 54 | // 55 | // CMatrixState* m_FirstState; 56 | // CMatrixState* m_LastState; 57 | // 58 | // CMatrixLogicSlot* m_PrevSlot; 59 | // CMatrixLogicSlot* m_NextSlot; 60 | // 61 | // void Reset() { m_RobotsCnt = 0; } 62 | // 63 | // void SetActiveState(CMatrixState* state) { if(state) m_ActiveState = state; 64 | // } CMatrixState* GetActiveState() { return m_ActiveState; } 65 | // 66 | // Cells GetCellsCnt() { return m_Cells; } 67 | // void Load(CBlockPar &bp); 68 | // 69 | // int GetLogicRobotsCnt() { return m_RobotsCnt; } 70 | // 71 | // 72 | // void RemoveLogicRobotFromList(CMatrixRobotAI* robot); 73 | // void AddLogicRobotToList(CMatrixRobotAI* robot); 74 | // bool FindRobot(CMatrixRobotAI* robot); 75 | // 76 | // CMatrixLogicSlot() 77 | // { 78 | // m_ActiveState = NULL; 79 | // m_FirstState = NULL; 80 | // m_LastState = NULL; 81 | // m_PrevSlot = NULL; 82 | // m_NextSlot = NULL; 83 | // m_FirstRobot = NULL; 84 | // m_LastRobot = NULL; 85 | // m_RobotsCnt = 0; 86 | // } 87 | // ~CMatrixLogicSlot(); 88 | //}; -------------------------------------------------------------------------------- /MatrixGame/src/Logic/MatrixRule.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "MatrixTactics.h" 9 | 10 | #include 11 | 12 | class CMatrixRobotAI; 13 | class CMatrixLogicSlot; 14 | class CMatrixState; 15 | class CMatrixBuilding; 16 | class CMatrixMapStatic; 17 | 18 | #define ENEMY_UNDEF 0 19 | #define ENEMY_ANY 1 20 | #define ENEMY_NEAREST 2 21 | #define ENEMY_DANGEROUS 4 22 | #define ENEMY_STRONGEST 8 23 | #define ENEMY_MAXHEALTH 16 24 | #define ENEMY_MINHEALTH 32 25 | #define ENEMY_NONE 64 26 | 27 | #define MOVETO_UNDEF 0 28 | #define MOVETO_ANY 1 29 | #define MOVETO_PROTECTED 2 30 | #define MOVETO_NEAR_ENTRY 4 31 | #define MOVETO_FAR_ENTRY 8 32 | #define MOVETO_BLOCK_ENTRY 16 33 | #define MOVETO_TARGETZONE 32 34 | #define MOVETO_MAINGROUP 64 35 | #define MOVETO_AROUNDENEMY 128 36 | #define MOVETO_FAR_MANEUVER 256 37 | #define MOVETO_NEAR_MANEUVER 512 38 | #define MOVETO_REGION 1024 39 | 40 | #define TARGETZONE_R 150 41 | #define TARGETZONE_MINR 80 42 | #define GROUPZONE_R 200 43 | #define AROUNDENEMY_PERIOD 1 44 | #define AROUNDENEMY_R 300 45 | #define AROUNDENEMY_MINR 70 46 | 47 | typedef enum { 48 | CHANGE_UNDEF, 49 | CHANGE, 50 | NOT_CHANGE, 51 | } ChangeEnemy; 52 | 53 | typedef enum { 54 | ATTACK_UNDEF, 55 | ATTACK, 56 | NOT_ATTACK, 57 | } AttackEnemy; 58 | 59 | typedef enum { PURSUE_UNDEF, PURSUE, NOT_PURSUE } PursueEnemy; 60 | 61 | typedef enum { FLEE_UNDEF, FLEE, NOT_FLEE } FleeFromEnemy; 62 | 63 | typedef enum { EXIT_UNDEF, EXIT, NOT_EXIT } ExitFromTactics; 64 | 65 | typedef enum { CAPTURE_UNDEF, CAPTURE, NOT_CAPTURE } CaptureTarget; 66 | 67 | typedef enum { POSITION_UNDEF, POSITION_NEAREST_TO_TARGET } Position; 68 | 69 | typedef struct _cond { 70 | uint32_t m_EnemySpoted; 71 | CMatrixLogicSlot *m_DestroyedSlot; 72 | Position m_Position; 73 | _cond() { 74 | m_EnemySpoted = ENEMY_UNDEF; 75 | m_DestroyedSlot = nullptr; 76 | m_Position = POSITION_UNDEF; 77 | } 78 | } Condition; 79 | 80 | typedef struct _act { 81 | uint32_t m_MoveTo; 82 | uint32_t m_Patrol; 83 | ChangeEnemy m_ChangeEnemy; 84 | AttackEnemy m_AttackEnemy; 85 | PursueEnemy m_PursueEnemy; 86 | FleeFromEnemy m_FleeFromEnemy; 87 | CMatrixState *m_GoTo; 88 | ExitFromTactics m_Exit; 89 | CaptureTarget m_Capture; 90 | _act() { 91 | m_MoveTo = MOVETO_UNDEF; 92 | m_Patrol = MOVETO_UNDEF; 93 | m_ChangeEnemy = CHANGE_UNDEF; 94 | m_AttackEnemy = ATTACK_UNDEF; 95 | m_PursueEnemy = PURSUE_UNDEF; 96 | m_FleeFromEnemy = FLEE_UNDEF; 97 | m_GoTo = nullptr; 98 | m_Exit = EXIT_UNDEF; 99 | m_Capture = CAPTURE_UNDEF; 100 | } 101 | } Action; 102 | 103 | // class CMatrixRule : public CBaseTactics 104 | //{ 105 | // CMatrixMapStatic* m_ContextEnemy; 106 | // public: 107 | // int m_AroundPeriod; 108 | // CMatrixRule* m_PrevRule; 109 | // CMatrixRule* m_NextRule; 110 | // 111 | // Condition m_Condition; 112 | // Action m_Action; 113 | // 114 | // bool If(CMatrixRobotAI *robot, CMatrixGroup* group); 115 | // void Do(CMatrixRobotAI *robot, CMatrixGroup* group); 116 | // 117 | // //Actions 118 | // 119 | // void Load(CBlockPar &bp); 120 | // void LogicTakt(); 121 | // 122 | // CMatrixRule() 123 | // { 124 | // m_PrevRule = nullptr; 125 | // m_NextRule = nullptr; 126 | // m_ContextEnemy = nullptr; 127 | // 128 | // m_AroundPeriod = AROUNDENEMY_PERIOD + 10; 129 | // } 130 | // ~CMatrixRule(); 131 | //}; -------------------------------------------------------------------------------- /MatrixGame/src/Logic/MatrixState.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixState.h" 7 | #include "MatrixRule.h" 8 | #include "../MatrixMap.hpp" 9 | #include "MatrixLogicSlot.h" 10 | 11 | // CMatrixState::~CMatrixState() 12 | //{ 13 | // DTRACE(); 14 | // CMatrixRule *Rule = m_FirstRule; 15 | // 16 | // while(Rule != NULL){ 17 | // if(Rule->m_NextRule) 18 | // Rule = Rule->m_NextRule; 19 | // else { 20 | // HDelete(CMatrixRule, Rule, g_MatrixHeap); 21 | // Rule = NULL; 22 | // m_FirstRule = NULL; 23 | // m_LastRule = NULL; 24 | // 25 | // } 26 | // 27 | // if(Rule) 28 | // HDelete(CMatrixRule, Rule->m_PrevRule, g_MatrixHeap); 29 | // } 30 | //} 31 | // 32 | // void CMatrixState::Load(CBlockPar &bp) 33 | //{ 34 | // CWStr filename; 35 | // //filename.Add(L"#ST_"); 36 | // //filename.Add(GetName()); 37 | // //filename.Add(L"_"); 38 | // //filename.Add(((CMatrixLogicSlot*)GetParent())->GetName()); 39 | // //filename.Add(L"_"); 40 | // //filename.Add(((CMatrixTactics*)((CMatrixLogicSlot*)GetParent())->GetParent())->GetName()); 41 | // //filename.Add(L".txt"); 42 | // //bp.SaveInTextFile(filename); 43 | // 44 | // // 45 | // int rules_cnt = bp.BlockCount(); 46 | // for(int cnt = 0; cnt < rules_cnt; cnt++){ 47 | // CMatrixRule *rule = HNew(g_MatrixHeap) CMatrixRule(); 48 | // rule->SetName(bp.BlockGetName(cnt)); 49 | // rule->SetParent(this); 50 | // rule->Load(*bp.BlockGet(cnt)); 51 | // LIST_ADD(rule, m_FirstRule, m_LastRule, m_PrevRule, m_NextRule); 52 | // } 53 | //} -------------------------------------------------------------------------------- /MatrixGame/src/Logic/MatrixState.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "MatrixTactics.h" 9 | 10 | // class CMatrixRule; 11 | // 12 | // class CMatrixState : public CBaseTactics 13 | //{ 14 | // CMatrixLogicSlot* m_ParentSlot; 15 | // public: 16 | // //список правил 17 | // CMatrixRule* m_FirstRule; 18 | // CMatrixRule* m_LastRule; 19 | // 20 | // CMatrixState* m_PrevState; 21 | // CMatrixState* m_NextState; 22 | // 23 | // void Load(CBlockPar &bp); 24 | // 25 | // CMatrixState() 26 | // { 27 | // m_FirstRule = NULL; 28 | // m_LastRule = NULL; 29 | // m_PrevState = NULL; 30 | // m_NextState = NULL; 31 | // m_ParentSlot = NULL; 32 | // } 33 | // ~CMatrixState(); 34 | //}; -------------------------------------------------------------------------------- /MatrixGame/src/MatrixCursor.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixMap.hpp" 7 | 8 | #define CURSOR_VISIBLE 1 9 | #define CURSOR_REVERSEANIM 2 10 | 11 | class CMatrixCursor : public CMain { 12 | DWORD m_CursorFlags; 13 | CPoint m_Pos; 14 | CPoint m_HotSpot; 15 | std::wstring m_CurCursor; 16 | CTextureManaged *m_CursorTexture; 17 | int m_CursorSize; 18 | HICON *m_CursorIcons; 19 | HCURSOR m_OldCursor; 20 | int m_FramesCnt; 21 | int m_FrameInc; 22 | int m_Frame; 23 | int m_NextCursorTime; 24 | int m_CursorTimePeriod; 25 | int m_CursorInTexLine; 26 | float m_TexSizeXInversed, m_TexSizeYInversed; 27 | float m_u0, m_v0, m_u1, m_v1; 28 | void CalcUV(void); 29 | 30 | int m_Time; 31 | 32 | public: 33 | CMatrixCursor(void) { 34 | memset(this, 0, sizeof(CMatrixCursor)); 35 | m_OldCursor = SetCursor(NULL); 36 | } 37 | ~CMatrixCursor(void) { Clear(); } 38 | 39 | void Draw(void) const; 40 | 41 | void Select(const std::wstring& name); 42 | void Takt(int ms); 43 | void Clear(void); 44 | void SetVisible(bool flag); 45 | 46 | const CPoint &GetPos(void) const { return m_Pos; } 47 | int GetPosX(void) const { return m_Pos.x; } 48 | int GetPosY(void) const { return m_Pos.y; } 49 | void SetPos(const CPoint &pos) { SetPos(pos.x, pos.y); } 50 | void SetPos(int xx, int yy) { 51 | m_Pos.x = xx; 52 | m_Pos.y = yy; 53 | } 54 | }; 55 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixDebugInfo.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "BaseDef.hpp" 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #define DI_DRAWFPS SETBIT(0) 16 | #define DI_VISOBJ SETBIT(1) 17 | #define DI_TMEM SETBIT(2) 18 | #define DI_TARGETCOORD SETBIT(3) 19 | #define DI_SIDEINFO SETBIT(4) 20 | #define DI_ACTIVESOUNDS SETBIT(5) 21 | #define DI_FRUSTUMCENTER SETBIT(6) 22 | 23 | struct SDIItem { 24 | std::wstring key; 25 | std::wstring val; 26 | int ttl; 27 | int bttl; 28 | }; 29 | 30 | class CMatrixDebugInfo 31 | { 32 | std::vector m_Items; 33 | ID3DXFont* m_Font; 34 | 35 | CPoint m_Pos; 36 | 37 | public: 38 | CMatrixDebugInfo(); 39 | ~CMatrixDebugInfo(); 40 | 41 | void Draw(); 42 | void Takt(int ms); 43 | 44 | void SetStartPos(const CPoint& pos); 45 | 46 | void T(const wchar_t* key, const wchar_t* val, int ttl = 3000, int bttl = 0, bool add = false); 47 | 48 | void OnLostDevice(); 49 | void OnResetDevice(); 50 | }; -------------------------------------------------------------------------------- /MatrixGame/src/MatrixFormGame.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "Form.hpp" 9 | 10 | #include 11 | 12 | #define MOUSE_BORDER 4 13 | 14 | /** 15 | * @brief The form(high-level window) which holds the game. 16 | */ 17 | class CFormMatrixGame : public CForm { 18 | private: 19 | float m_LastWorldX, m_LastWorldY; 20 | int m_Action; 21 | 22 | public: 23 | CFormMatrixGame(void); 24 | ~CFormMatrixGame(); 25 | 26 | virtual void Enter(void); 27 | virtual void Leave(void); 28 | 29 | /** 30 | * @brief Processes the frame effectively redrawing everything on the game containing window. 31 | */ 32 | virtual void Draw(void); 33 | 34 | /** 35 | * @brief Processes logical frame of the game containing window. 36 | * 37 | * Triggers g_MatrixMap->Takt(step); 38 | * 39 | * @param step number of milliseconds since last frame (delta time) 40 | * 41 | * TODO: consider renaming russian "Takt" to something consistent like "Update"(Unity) or "Process"(Godot). 42 | * also consider renaming step to delta everywhere. 43 | */ 44 | virtual void Takt(int step); 45 | 46 | /** 47 | * @brief Game's window mouse movement handler 48 | * 49 | * Executed when mouse is moved. 50 | */ 51 | virtual void MouseMove(int x, int y); 52 | 53 | /** 54 | * @brief Game's window mouse button press handler. 55 | * 56 | * Executed when mouse button is pressed. 57 | * 58 | * @param status ButtonStatus: button is either released, pressed down, double clicked or scrolled if it's wheel. 59 | * @param key Virtual key, see VK_ in "Winuser.h" 60 | * @param x Cursor X position 61 | * @param y Cursor Y position 62 | */ 63 | virtual void MouseKey(ButtonStatus status, int key, int x, int y); 64 | 65 | /** 66 | * @brief Game's window key press handler. 67 | * 68 | * Updates the buttons pressed bitmap record (see input.cpp) and does immediate logic due to key presses (such as 69 | * types in Dev console, etc.). 70 | * 71 | * Called as a response to a button being pressed originating from the Windows message queue and L3GWndProc. 72 | * 73 | * This function gets called before the frame it is going to affect. 74 | * 75 | * @param down Is key down? 76 | * @param vk Virtual key, see VK_ in "Winuser.h" 77 | */ 78 | virtual void Keyboard(bool down, uint8_t vk); 79 | virtual void SystemEvent(ESysEvent se); 80 | }; 81 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixGame.h: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "MatrixGameDll.hpp" 9 | 10 | #include "CHeap.hpp" 11 | #include "CBlockPar.hpp" 12 | 13 | class CFormMatrixGame; 14 | class CMatrixMapLogic; 15 | class CIFaceList; 16 | class CRenderPipeline; 17 | class CLoadProgress; 18 | class CHistory; 19 | struct SMenuItemText; 20 | 21 | extern Base::CHeap *g_MatrixHeap; 22 | extern Base::CBlockPar *g_MatrixData; 23 | extern CMatrixMapLogic *g_MatrixMap; 24 | extern CIFaceList *g_IFaceList; 25 | extern CRenderPipeline *g_Render; 26 | extern CLoadProgress *g_LoadProgress; 27 | extern SMenuItemText *g_PopupHead; 28 | extern SMenuItemText *g_PopupWeaponNormal; 29 | extern SMenuItemText *g_PopupWeaponExtern; 30 | extern SMenuItemText *g_PopupHull; 31 | extern SMenuItemText *g_PopupChassis; 32 | extern CHistory *g_ConfigHistory; 33 | 34 | /** 35 | * @brief Stateless class, which only holds functions, but no data responsive for game engine operation: start, run, 36 | * end. 37 | * 38 | * TODO: It is similar to a "static class" or a namespace. Consider bringing it to a more logical form, maybe rename, 39 | * maybe move global variables inside as members. 40 | */ 41 | class CGame { 42 | public: 43 | CGame() = delete; 44 | ~CGame() = delete; 45 | 46 | /** 47 | * @brief Initializes the game engine. 48 | * 49 | * Initializes statics, loads .pkg and .dat files, initializes 3D rendering engine, 50 | * initializes rendering pipeline, loads map, applies video settings, loads interface. 51 | * 52 | * BUILD_EXE environment variable determines whether to initialize as a standalone executable or as DLL. 53 | * 54 | * @param inst Windows process handle. 55 | * @param wnd Windows' window handle. Basically an id to the window to draw. 56 | * @param map Requested map name to play. The file is either located inside the .pkg file or at "Matrix/Map/" 57 | * and could be something like "desert1_3e.cmap" 58 | * @param seed u32 seed for PRNG. 59 | * @param provided_settings Optional pointer to SRobotsSettings structure object. If not specified the settings will be autogenerated. 60 | * @param lang Specify only for DLL: it is usually "rus" or "eng". 61 | * @param txt_start Optional: Text displayed at the start of the map. 62 | * @param txt_win Optional: Text displayed at the end of the map, if you win. 63 | * @param txt_loss Optional: Text displayed at the end of the map, if you lose. 64 | * @param planet Optional: Planet name. 65 | */ 66 | static void Init( 67 | HINSTANCE hInstance, 68 | HWND wnd, 69 | const wchar *map = nullptr, 70 | uint32_t seed = 0, 71 | const SRobotsSettings *provided_settings = nullptr, 72 | const wchar *lang = nullptr, 73 | const wchar *txt_start = nullptr, 74 | const wchar *txt_win = nullptr, 75 | const wchar *txt_loss = nullptr, 76 | const wchar *planet = nullptr 77 | ); 78 | static void Deinit(); 79 | static void SafeFree(); 80 | 81 | /** 82 | * @brief An envelope over L3GRun() function to account for DLL multiple windows form change. 83 | * 84 | * @param formGame The form(i.e. Window) of the game. 85 | */ 86 | static void RunGameLoop(CFormMatrixGame *formGame); 87 | static void SaveResult(SRobotGameState *state); 88 | 89 | private: 90 | static void ApplyVideoParams(SRobotsSettings &settings); 91 | }; 92 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixGameDll.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixGameDll.hpp" 7 | #include "MatrixFormGame.hpp" 8 | #include "MatrixGame.h" 9 | #include "3g.hpp" 10 | 11 | #include 12 | #include 13 | 14 | SMGDRobotInterface g_RobotInterface; 15 | SMGDRangersInterface *g_RangersInterface = nullptr; 16 | int g_ExitState = 0; 17 | 18 | long __stdcall ExceptionHandler(PEXCEPTION_POINTERS) { 19 | return EXCEPTION_EXECUTE_HANDLER; 20 | } 21 | 22 | BOOL APIENTRY DllMain( 23 | [[maybe_unused]] HANDLE hModule, 24 | DWORD ul_reason_for_call, 25 | [[maybe_unused]] LPVOID lpReserved) 26 | { 27 | SetUnhandledExceptionFilter(ExceptionHandler); 28 | switch (ul_reason_for_call) { 29 | case DLL_PROCESS_ATTACH: 30 | case DLL_THREAD_ATTACH: 31 | case DLL_THREAD_DETACH: 32 | case DLL_PROCESS_DETACH: 33 | break; 34 | } 35 | return TRUE; 36 | } 37 | 38 | void __stdcall Init(SMGDRangersInterface *ri) { 39 | g_RangersInterface = ri; 40 | } 41 | 42 | void __stdcall Deinit() { 43 | g_RangersInterface = NULL; 44 | } 45 | 46 | int __stdcall Support() { 47 | // g_D3D = Direct3DCreate9(D3D_SDK_VERSION); 48 | g_D3D = Direct3DCreate9(31); 49 | 50 | if (g_D3D == NULL) 51 | return SUPE_DIRECTX; 52 | 53 | D3DCAPS9 caps; 54 | if (D3D_OK != g_D3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps)) { 55 | g_D3D->Release(); 56 | g_D3D = NULL; 57 | return SUPE_DIRECTX; 58 | } 59 | 60 | if (caps.MaxSimultaneousTextures < 2) 61 | return SUPE_VIDEOHARDWARE; 62 | 63 | if (caps.MaxTextureWidth < 2048) 64 | return SUPE_VIDEOHARDWARE; 65 | if (caps.MaxTextureHeight < 2048) 66 | return SUPE_VIDEOHARDWARE; 67 | 68 | if (caps.MaxStreams == 0) 69 | return SUPE_VIDEODRIVER; 70 | g_D3D->Release(); 71 | g_D3D = NULL; 72 | return SUPE_OK; 73 | } 74 | 75 | int __stdcall Run(HINSTANCE hinst, HWND hwnd, wchar *map, SRobotsSettings *settings, wchar *lang, wchar *txt_start, 76 | wchar *txt_win, wchar *txt_loss, wchar *planet, SRobotGameState *rgs) { 77 | uint32_t seed = (unsigned)time(nullptr); 78 | 79 | CGame::Init(hinst, hwnd, map, seed, settings, lang, txt_start, txt_win, txt_loss, planet); 80 | 81 | CFormMatrixGame formgame; 82 | 83 | CGame::RunGameLoop(&formgame); 84 | 85 | CGame::SaveResult(rgs); 86 | CGame::SafeFree(); 87 | 88 | ClipCursor(nullptr); 89 | 90 | if (FLAG(g_Flags, GFLAG_EXITLOOP)) 91 | return g_ExitState; 92 | else 93 | return 0; 94 | } 95 | 96 | MATRIXGAMEDLL_API SMGDRobotInterface *__cdecl GetRobotInterface(void) { 97 | ZeroMemory(&g_RobotInterface, sizeof(SMGDRobotInterface)); 98 | g_RobotInterface.m_Init = &Init; 99 | g_RobotInterface.m_Deinit = &Deinit; 100 | g_RobotInterface.m_Support = &Support; 101 | g_RobotInterface.m_Run = &Run; 102 | return &g_RobotInterface; 103 | } 104 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixGamePathUtils.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixGamePathUtils.hpp" 7 | #include "windows.h" 8 | #include 9 | #include 10 | 11 | std::wstring PathToOutputFiles(const wchar_t *dest) 12 | { 13 | std::wstring path{}; 14 | 15 | if (path.empty()) { 16 | ITEMIDLIST *pidl; 17 | 18 | HRESULT hRes = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl); 19 | if (hRes == NOERROR) { 20 | wchar_t lpPath[MAX_PATH]; 21 | SHGetPathFromIDListW(pidl, lpPath); 22 | 23 | path = utils::format(L"%ls\\SpaceRangersHD", lpPath); 24 | CreateDirectoryW(path.c_str(), NULL); 25 | path += L"\\"; 26 | path += dest; 27 | } 28 | else { 29 | path = utils::format(L".\\%ls", dest); 30 | } 31 | } 32 | 33 | return path; 34 | } 35 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixGamePathUtils.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | std::wstring PathToOutputFiles(const wchar_t *dest); 11 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixInstantDraw.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_INSTANT_DRAW_INCLUDE 7 | #define MATRIX_INSTANT_DRAW_INCLUDE 8 | 9 | #include "D3DControl.hpp" 10 | 11 | struct SVertBase {}; 12 | 13 | struct SVert_V3_C_UV : public SVertBase { 14 | D3DXVECTOR3 p; 15 | DWORD color; 16 | float tu, tv; 17 | }; 18 | 19 | struct SVert_V4_UV : public SVertBase { 20 | D3DXVECTOR4 p; 21 | float tu, tv; 22 | }; 23 | 24 | struct SVert_V4_C : public SVertBase { 25 | D3DXVECTOR4 p; 26 | DWORD col; 27 | }; 28 | 29 | struct SVert_V4 : public SVertBase { 30 | D3DXVECTOR4 p; 31 | }; 32 | 33 | enum E_FVF { 34 | IDFVF_V3_C_UV, 35 | IDFVF_V4_UV, 36 | IDFVF_V4_C, 37 | IDFVF_V4, 38 | 39 | IDFVF_CNT 40 | }; 41 | 42 | struct SOneSet { 43 | void *accum; 44 | int accumcntalloc; 45 | int accumcnt; 46 | CBaseTexture *tex; 47 | DWORD tf; 48 | DWORD tf_used; 49 | }; 50 | 51 | struct SFVF_VB { 52 | DWORD fvf; 53 | int stride; 54 | int statistic; 55 | int statistic_max_tex; 56 | int cursize; // size of currently allocated VB 57 | D3D_VB vb; 58 | SOneSet *sets; 59 | int sets_cnt; 60 | int sets_alloc; 61 | int disp; 62 | }; 63 | 64 | class CInstDraw : public CMain { 65 | static SFVF_VB m_FVFs[IDFVF_CNT]; 66 | static E_FVF m_Current; 67 | static D3D_IB m_IB; 68 | static int m_IB_Count; 69 | 70 | public: 71 | static void StaticInit(void) { 72 | memset(m_FVFs, 0, sizeof(m_FVFs)); 73 | m_FVFs[IDFVF_V3_C_UV].fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1; 74 | m_FVFs[IDFVF_V3_C_UV].stride = sizeof(SVert_V3_C_UV); 75 | 76 | m_FVFs[IDFVF_V4_UV].fvf = D3DFVF_XYZRHW | D3DFVF_TEX1; 77 | m_FVFs[IDFVF_V4_UV].stride = sizeof(SVert_V4_UV); 78 | 79 | m_FVFs[IDFVF_V4_C].fvf = D3DFVF_XYZRHW | D3DFVF_DIFFUSE; 80 | m_FVFs[IDFVF_V4_C].stride = sizeof(SVert_V4_C); 81 | 82 | m_FVFs[IDFVF_V4].fvf = D3DFVF_XYZRHW; 83 | m_FVFs[IDFVF_V4].stride = sizeof(SVert_V4); 84 | 85 | m_IB = NULL; 86 | m_IB_Count = 0; 87 | 88 | #ifdef _DEBUG 89 | m_Current = IDFVF_CNT; 90 | #endif 91 | } 92 | 93 | static void DrawFrameBegin(void); 94 | static void BeginDraw(E_FVF fvf); 95 | static void AddVerts(void *v, CBaseTexture *tex); // add 4 verts 96 | static void AddVerts(void *v, CBaseTexture *tex, DWORD tf); // add 4 verts 97 | static void ActualDraw(void); 98 | 99 | static void MarkAllBuffersNoNeed(void); 100 | 101 | static void ClearAll(void); 102 | }; 103 | 104 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixLoadProgress.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "MatrixLoadProgress.hpp" 7 | #include "MatrixGameDll.hpp" 8 | #include "Math3D.hpp" 9 | 10 | static SLoadProcessProps lp_props[] = { 11 | {L"Preloading robots", 70}, 12 | {L"Loading map", 300}, 13 | {L"Preparing objects", 150}, 14 | {L"Preparing Interface", 30}, 15 | 16 | }; 17 | 18 | CLoadProgress::CLoadProgress(void) { 19 | m_CurLoadProcess = -1; 20 | const int n = sizeof(lp_props) / sizeof(SLoadProcessProps); 21 | m_fullsize = 0; 22 | for (int i = 0; i < n; ++i) { 23 | m_fullsize += lp_props[i].len; 24 | } 25 | 26 | m_cursizedone = 0; 27 | m_fullsize1 = 1.0f / float(m_fullsize); 28 | 29 | m_lastacc = 0; 30 | } 31 | 32 | void CLoadProgress::SetCurLP(int lp) { 33 | if (m_CurLoadProcess >= 0) { 34 | m_cursizedone += lp_props[m_CurLoadProcess].len; 35 | }; 36 | m_CurLoadProcess = lp; 37 | 38 | #ifdef _DEBUG 39 | OutputDebugStringW(utils::format(L"\n%ls", lp_props[lp].description).c_str()); 40 | #endif 41 | } 42 | void CLoadProgress::SetCurLPPos(int i) { 43 | float k = m_fullsize1 * (m_cursizedone + ((m_cur_lp_size1 * float(i)) * lp_props[m_CurLoadProcess].len)); 44 | 45 | int ac = Float2Int(k * LPACCURACY); 46 | if (ac > m_lastacc) { 47 | if (g_RangersInterface) 48 | g_RangersInterface->m_ProgressBar(float(ac) / LPACCURACY); 49 | 50 | #ifdef _DEBUG 51 | OutputDebugStringW(utils::format(L"\n%d", ac).c_str()); 52 | #endif 53 | 54 | m_lastacc = ac; 55 | } 56 | } -------------------------------------------------------------------------------- /MatrixGame/src/MatrixLoadProgress.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_LOAD_PROGRESS_INCLUDE 7 | #define MATRIX_LOAD_PROGRESS_INCLUDE 8 | 9 | #include "CMain.hpp" 10 | 11 | #define LPACCURACY 100 12 | 13 | #define LP_PRELOADROBOTS 0 14 | #define LP_LOADINGMAP 1 15 | #define LP_PREPARINGOBJECTS 2 16 | #define LP_PREPARININTERFACE 3 17 | 18 | struct SLoadProcessProps { 19 | const wchar_t *description; 20 | int len; 21 | }; 22 | 23 | class CLoadProgress : public CMain { 24 | int m_CurLoadProcess; 25 | int m_fullsize; 26 | float m_fullsize1; 27 | int m_cursizedone; 28 | int m_cur_lp_size; 29 | float m_cur_lp_size1; 30 | 31 | int m_lastacc; 32 | 33 | public: 34 | CLoadProgress(void); 35 | ~CLoadProgress(void) {} 36 | 37 | void SetCurLP(int lp); 38 | void InitCurLP(int sz) { 39 | m_cur_lp_size = sz; 40 | m_cur_lp_size1 = 1.0f / float(sz); 41 | }; 42 | void SetCurLPPos(int i); 43 | }; 44 | 45 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixMapTexture.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include 7 | 8 | #include "MatrixMapTexture.hpp" 9 | #include "MatrixMap.hpp" 10 | #include "MatrixLoadProgress.hpp" 11 | #include "MatrixTerSurface.hpp" 12 | 13 | CBottomTextureUnion *CBottomTextureUnion::m_Textures; 14 | int CBottomTextureUnion::m_TexturesCount; 15 | 16 | // static void FreeBottomTextureUnionHandler(DWORD, DWORD user) 17 | //{ 18 | // DTRACE(); 19 | // CBottomTextureUnion * t= (CBottomTextureUnion *)user; 20 | // t->Unload(); 21 | //} 22 | 23 | void CBottomTextureUnion::MakeFromBitmap(const CBitmap &bm) { 24 | m_Texture = CACHE_CREATE_TEXTUREMANAGED(); 25 | // m_Texture->LoadFromBitmap(bm, D3DFMT_DXT1, 6); 26 | m_Texture->LoadFromBitmap(bm, D3DFMT_DXT1, 6); 27 | } 28 | 29 | CBottomTextureUnion::~CBottomTextureUnion(void) { 30 | DTRACE(); 31 | if (m_Texture) 32 | CCache::Destroy(m_Texture); 33 | } 34 | 35 | void CBottomTextureUnion::Init(int n) { 36 | Clear(); 37 | m_TexturesCount = n; 38 | m_Textures = (CBottomTextureUnion *)HAlloc(sizeof(CBottomTextureUnion) * n, g_MatrixHeap); 39 | for (int i = 0; i < n; ++i) { 40 | new(&m_Textures[i]) CBottomTextureUnion(); 41 | } 42 | } 43 | 44 | void CBottomTextureUnion::Clear(void) { 45 | if (m_Textures) { 46 | for (int i = 0; i < m_TexturesCount; ++i) { 47 | m_Textures[i].~CBottomTextureUnion(); 48 | } 49 | HFree(m_Textures, g_MatrixHeap); 50 | m_Textures = NULL; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixMapTexture.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_MAP_TEXTURE 7 | #define MATRIX_MAP_TEXTURE 8 | 9 | #include "Texture.hpp" 10 | 11 | class CBottomTextureUnion : public CMain { 12 | CTextureManaged *m_Texture; 13 | 14 | static CBottomTextureUnion *m_Textures; 15 | static int m_TexturesCount; 16 | 17 | public: 18 | // DWORD m_ID; 19 | 20 | CBottomTextureUnion(void) : m_Texture(NULL) {} 21 | ~CBottomTextureUnion(); 22 | 23 | static void StaticInit(void) { 24 | m_Textures = NULL; 25 | m_TexturesCount = 0; 26 | } 27 | 28 | void MakeFromBitmap(const CBitmap &bm); 29 | 30 | void Unload(void) { 31 | DTRACE(); 32 | m_Texture->Unload(); 33 | // m_ID = REMINDER_EMPTY; 34 | } 35 | 36 | void Prepare(void) { m_Texture->Preload(); } 37 | CTextureManaged *GetTexture(void) { return m_Texture; }; 38 | 39 | static void Init(int n); 40 | static void Clear(void); 41 | static CBottomTextureUnion &Get(int i) { return m_Textures[i]; } 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixMultiSelection.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_MULTI_SELECTION 7 | #define MATRIX_MULTI_SELECTION 8 | 9 | #include "StringConstants.hpp" 10 | 11 | #include "3g.hpp" 12 | 13 | #include 14 | 15 | class CMatrixMapStatic; 16 | 17 | typedef void (*SELECT_ENUM)(CMatrixMapStatic *ms, uintptr_t param); 18 | 19 | #define MS_DIP_TIME 50 20 | 21 | #define MS_FLAG_DIP SETBIT(0) 22 | #define MS_FLAG_ROBOTS SETBIT(1) 23 | #define MS_FLAG_BUILDINGS SETBIT(2) 24 | 25 | #define MULTISEL_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1) 26 | struct SMultiSelVertex { 27 | D3DXVECTOR4 p; 28 | float u, v; 29 | }; 30 | 31 | class CMultiSelection : public CMain { 32 | static CMultiSelection *m_First; 33 | static CMultiSelection *m_Last; 34 | CMultiSelection *m_Next; 35 | CMultiSelection *m_Prev; 36 | 37 | Base::CPoint m_LT; 38 | Base::CPoint m_RB; 39 | 40 | DWORD m_Flags; 41 | 42 | int m_TimeBeforeDip; 43 | 44 | std::vector m_SelItems; 45 | 46 | static int m_Time; 47 | 48 | // CTextureManaged *m_Tex; 49 | 50 | CMultiSelection(const Base::CPoint &pos); 51 | ~CMultiSelection() { 52 | if (CMultiSelection::m_GameSelection == this) 53 | CMultiSelection::m_GameSelection = NULL; 54 | 55 | LIST_DEL(this, m_First, m_Last, m_Prev, m_Next); 56 | }; 57 | 58 | void Draw(void); 59 | 60 | bool DrawPass1(void); 61 | void DrawPass2(void); 62 | void DrawPassEnd(void); 63 | 64 | void RemoveSelItems() { 65 | RESETFLAG(m_Flags, MS_FLAG_BUILDINGS); 66 | RESETFLAG(m_Flags, MS_FLAG_ROBOTS); 67 | 68 | m_SelItems.clear(); 69 | } 70 | 71 | public: 72 | static CMultiSelection *m_GameSelection; 73 | 74 | static void StaticInit(void) { 75 | m_First = NULL; 76 | m_Last = NULL; 77 | m_Time = 0; 78 | m_GameSelection = NULL; 79 | // m_FirstItem = NULL; 80 | // m_LastItem = NULL; 81 | } 82 | 83 | static bool DrawAllPass1Begin(void) { 84 | bool ret = false; 85 | CMultiSelection *f = m_First; 86 | while (f) { 87 | ret |= f->DrawPass1(); 88 | f = f->m_Next; 89 | } 90 | return ret; 91 | } 92 | static void DrawAllPass2Begin(void) { 93 | CMultiSelection *f = m_First; 94 | while (f) { 95 | f->DrawPass2(); 96 | f = f->m_Next; 97 | } 98 | } 99 | 100 | static void DrawAllPassEnd(void) { 101 | CMultiSelection *f = m_First; 102 | while (f) { 103 | f->DrawPassEnd(); 104 | f = f->m_Next; 105 | } 106 | } 107 | 108 | static void DrawAll() { 109 | ASSERT_DX(g_D3DD->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE)); 110 | ASSERT_DX(g_D3DD->SetRenderState(D3DRS_ZWRITEENABLE, FALSE)); 111 | g_D3DD->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); 112 | 113 | CMultiSelection *f = m_First; 114 | while (f) { 115 | // this izvrat required because Draw method can delete object itself 116 | CMultiSelection *next = f->m_Next; 117 | f->Draw(); 118 | f = next; 119 | } 120 | 121 | ASSERT_DX(g_D3DD->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE)); 122 | ASSERT_DX(g_D3DD->SetRenderState(D3DRS_ZWRITEENABLE, TRUE)); 123 | g_D3DD->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); 124 | } 125 | 126 | static CMultiSelection *Begin(const Base::CPoint &pos); 127 | 128 | void Update(const Base::CPoint &pos) { m_RB = pos; } 129 | void Update(const Base::CPoint &pos, DWORD mask, SELECT_ENUM callback, DWORD param); 130 | void End(bool add_to_selection = true); 131 | 132 | static void AddTime(int ms) { m_Time += ms; } 133 | 134 | bool FindItem(const CMatrixMapStatic *o); 135 | void Remove(const CMatrixMapStatic *o); 136 | }; 137 | 138 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixProgressBar.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef PROGRESS_BAR_INCLUDE 7 | #define PROGRESS_BAR_INCLUDE 8 | 9 | #include "Texture.hpp" 10 | #include "MatrixProgressBar.hpp" 11 | 12 | #define PB_BUILDING_WIDTH 200 13 | #define PB_ROBOT_WIDTH 70 14 | #define PB_CANNON_WIDTH 100 15 | #define PB_FLYER_WIDTH 100 16 | #define PB_SPECIAL_WIDTH 50 17 | //#define PB_BUILDING_HEIGHT 8 18 | 19 | #define PB_COLOR_0 0x00FF0000 20 | #define PB_COLOR_1 0x00FFFF00 21 | #define PB_COLOR_2 0x0000FF00 22 | 23 | #define PB_Z 0 24 | 25 | struct SPBPos { 26 | DWORD present; 27 | float m_X; 28 | float m_Y; 29 | float m_Width; 30 | }; 31 | 32 | enum EPBCoord { 33 | PBC_ORIGINAL = 0, 34 | PBC_CLONE1, 35 | PBC_CLONE2, 36 | 37 | }; 38 | 39 | class CMatrixProgressBar : public CMain { 40 | static CMatrixProgressBar *m_First; 41 | static CMatrixProgressBar *m_Last; 42 | static CMatrixProgressBar *m_FirstClones; 43 | static CMatrixProgressBar *m_LastClones; 44 | static CTextureManaged *m_Tex; 45 | 46 | CMatrixProgressBar *m_Prev; 47 | CMatrixProgressBar *m_Next; 48 | 49 | SPBPos *m_Coord; 50 | int m_CoordCount; 51 | 52 | float m_Pos; 53 | 54 | #ifdef _DEBUG 55 | int counter; 56 | #endif 57 | 58 | void DrawClones(bool pbd); 59 | void Draw(bool pbd); 60 | void Draw(SPBPos *pos, bool pbd); 61 | 62 | public: 63 | CMatrixProgressBar(void); 64 | ~CMatrixProgressBar(); 65 | 66 | void Modify(float x, float y, float width, /* float height, */ float pos) { 67 | Modify(x, y); 68 | m_Coord->m_Width = (float)floor(width); /* m_Height = floor(height); */ 69 | m_Pos = pos; 70 | }; 71 | void Modify(float x, float y, float pos) { 72 | Modify(x, y); 73 | m_Pos = pos; 74 | }; 75 | void Modify(float x, float y) { 76 | m_Coord->m_X = (float)floor(x) + 0.5f; 77 | m_Coord->m_Y = (float)floor(y) + 0.5f; 78 | }; 79 | void Modify(float pos) { m_Pos = pos; }; 80 | 81 | void CreateClone(EPBCoord pbc, float x, float y, float width); 82 | void KillClone(EPBCoord pbc); 83 | bool ClonePresent(EPBCoord pbc) const { return (m_CoordCount > pbc) && (m_Coord[pbc].present != 0); }; 84 | 85 | static void BeforeDrawAll(void) { m_Tex->Preload(); } 86 | 87 | static void DrawAll(void); 88 | static void DrawAllClones(void); 89 | 90 | static void StaticInit(void) { 91 | m_First = NULL; 92 | m_Last = NULL; 93 | m_FirstClones = NULL; 94 | m_LastClones = NULL; 95 | m_Tex = NULL; 96 | } 97 | }; 98 | 99 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixRenderPipeline.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_RENDER_PIPELINE_INCLUDE 7 | #define MATRIX_RENDER_PIPELINE_INCLUDE 8 | 9 | #include "MatrixMapTexture.hpp" 10 | #include "MatrixMapGroup.hpp" 11 | #include "MatrixMapStatic.hpp" 12 | #include "MatrixTerSurface.hpp" 13 | 14 | typedef void (*WATER_SETUP)(CTextureManaged *tex, CTextureManaged *refl, int pass); 15 | typedef void (*SETUP_CLEAR)(void); 16 | 17 | // typedef void (*TERRAIN_TEX_SETUP)(CMatrixMapTextureFinal *tex, int pass); 18 | // typedef void (*TERRAIN_SETUP)(int pass); 19 | 20 | typedef void (*TERSURF_TEX_SETUP)(CTextureManaged *tex, CTextureManaged *gloss, int pass); 21 | typedef void (*TERSURF_SETUP)(int pass, bool wrapy); 22 | 23 | typedef void (*TERBOT_TEX_SETUP)(int tex, int pass); 24 | typedef void (*TERBOT_SETUP)(int pass); 25 | 26 | class CRenderPipeline : public CMain { 27 | public: 28 | // IDirect3DVertexShader9 *m_CubeMapShader; 29 | // IDirect3DVertexDeclaration9 *m_VertexDecl; 30 | 31 | // IDirect3DCubeTexture9 *m_CubeTex; 32 | 33 | CRenderPipeline(void); 34 | ~CRenderPipeline(void); 35 | 36 | void SetupTerrains(bool macro); 37 | 38 | // water 39 | int m_WaterPassSolid; // passes count 40 | int m_WaterPassAlpha; 41 | WATER_SETUP m_WaterSolid; 42 | WATER_SETUP m_WaterAlpha; 43 | SETUP_CLEAR m_WaterClearSolid; 44 | SETUP_CLEAR m_WaterClearAlpha; 45 | 46 | // terain 47 | // TERRAIN_SETUP m_Ter[TERRAIN_RENDER_TYPES_CNT]; // prepare stages 48 | // TERRAIN_TEX_SETUP m_TerTex[TERRAIN_RENDER_TYPES_CNT]; // prepare textures 49 | // int m_TerPass[TERRAIN_RENDER_TYPES_CNT]; 50 | // SETUP_CLEAR m_TerClear[TERRAIN_RENDER_TYPES_CNT]; 51 | 52 | // terain surfaces 53 | TERSURF_SETUP m_TerSurf[SURF_TYPES_COUNT]; // prepare stages 54 | TERSURF_TEX_SETUP m_TerSurfTex[SURF_TYPES_COUNT]; // prepare textures 55 | int m_TerSurfPass[SURF_TYPES_COUNT]; 56 | SETUP_CLEAR m_TerSurfClear[SURF_TYPES_COUNT]; 57 | 58 | // terain bottom 59 | TERBOT_SETUP m_TerBot[2]; // prepare stages 60 | TERBOT_TEX_SETUP m_TerBotTex[2]; // prepare textures 61 | int m_TerBotPass[2]; 62 | SETUP_CLEAR m_TerBotClear[2]; 63 | 64 | // objects 65 | // OBJECT_SETUP_TEX m_ObjTex[OBJ_RENDER_TYPES_CNT]; 66 | // OBJECT_SETUP_STAGES m_ObjStages[OBJ_RENDER_TYPES_CNT]; 67 | // SETUP_CLEAR m_ObjClear; 68 | }; 69 | 70 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixSampleStateManager.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include 7 | #include "d3d9types.h" 8 | #include "MatrixSampleStateManager.hpp" 9 | #include "MatrixGameDll.hpp" 10 | #include "3g.hpp" 11 | 12 | CMatrixSampleStateManager::CMatrixSampleStateManager(void) {} 13 | 14 | CMatrixSampleStateManager::~CMatrixSampleStateManager(void) {} 15 | 16 | void CMatrixSampleStateManager::ApplySettings(SRobotsSettings *set) { 17 | m_AFDegree = g_D3DDCaps.MaxAnisotropy < set->m_AFDegree ? g_D3DDCaps.MaxAnisotropy : set->m_AFDegree; 18 | } 19 | 20 | HRESULT CMatrixSampleStateManager::SetState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value) { 21 | if (EligibleForAnisotropy(type) && (m_AFDegree) && (value == D3DTEXF_LINEAR)) { 22 | HRESULT hr; 23 | hr = g_D3DD->SetSamplerState(sampler, type, D3DTEXF_ANISOTROPIC); 24 | if (D3D_OK != hr) 25 | return hr; 26 | return g_D3DD->SetSamplerState(sampler, D3DSAMP_MAXANISOTROPY, m_AFDegree); 27 | } 28 | return g_D3DD->SetSamplerState(sampler, type, value); 29 | } 30 | 31 | bool CMatrixSampleStateManager::EligibleForAnisotropy(D3DSAMPLERSTATETYPE type) { 32 | return (type == D3DSAMP_MIPFILTER) || (type == D3DSAMP_MAGFILTER) || (type == D3DSAMP_MINFILTER); 33 | } 34 | 35 | CMatrixSampleStateManager g_Sampler; -------------------------------------------------------------------------------- /MatrixGame/src/MatrixSampleStateManager.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_SAMPLER_INCLUDE 7 | #define MATRIX_SAMPLER_INCLUDE 8 | 9 | struct SRobotsSettings; 10 | 11 | class CMatrixSampleStateManager { 12 | public: 13 | int m_AFDegree; 14 | 15 | void ApplySettings(SRobotsSettings *set); 16 | HRESULT SetState(DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD value); 17 | 18 | CMatrixSampleStateManager(void); 19 | ~CMatrixSampleStateManager(void); 20 | 21 | private: 22 | bool EligibleForAnisotropy(D3DSAMPLERSTATETYPE type); 23 | }; 24 | 25 | extern CMatrixSampleStateManager g_Sampler; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixShadowManager.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | class CMatrixMapObject; 9 | 10 | class CMatrixShadowProj : public CVOShadowProj { 11 | int m_DrawFrame; 12 | CMatrixMapStatic *m_Owner; 13 | 14 | public: 15 | bool AlreadyDraw(void); 16 | BYTE *ReadGeometry(BYTE *raw); 17 | 18 | CMatrixMapStatic *GetOwner(void) { return m_Owner; } 19 | 20 | CMatrixShadowProj(CHeap *heap, CMatrixMapStatic *owner) : CVOShadowProj(heap), m_DrawFrame(-1), m_Owner(owner) {} 21 | ~CMatrixShadowProj(); 22 | }; 23 | 24 | class CMatrixShadowCliper : public CVOShadowCliper { 25 | CVOShadowProj *m_Shadowproj; 26 | D3DXMATRIX m_World; 27 | 28 | public: 29 | CMatrixShadowCliper(CVOShadowProj *sp) : m_Shadowproj(sp), CVOShadowCliper(){}; 30 | virtual ~CMatrixShadowCliper(void){}; 31 | 32 | D3DXMATRIX *WorldMatrix(void) { return &m_World; } 33 | 34 | virtual void Render(void); 35 | virtual void BeforeRender(void); 36 | }; 37 | 38 | void ShadowProjBuildGeom(CVOShadowProj &sp, CVectorObjectAnim &obj, int noframe, const D3DXMATRIX &objma, 39 | const D3DXMATRIX &iobjma, D3DXVECTOR3 &light, int mapradius, bool join_to_group); 40 | void ShadowProjBuildGeomList(CVOShadowProj &sp, int cnt, CVectorObjectAnim **obj, const int *noframe, 41 | const D3DXMATRIX *wm, const D3DXMATRIX &objma, const D3DXMATRIX &iobjma, 42 | D3DXVECTOR3 &light, int mapradius, bool join_to_group); 43 | 44 | void ShadowProjBuildTexture(CMatrixMapObject *mo, CVOShadowProj &sp, CVectorObjectAnim &obj, int noframe, 45 | const D3DXMATRIX &iobjma, int texsize, bool doclip); 46 | void ShadowProjBuildTexture(CVOShadowProj &sp, CVectorObjectAnim &obj, int noframe, const D3DXMATRIX &iobjma, 47 | D3DXVECTOR3 &light, int texsize, bool doclip); 48 | void ShadowProjBuildTextureList(CVOShadowProj &sp, int cnt, CVectorObjectAnim **obj, CTexture *tex, int *noframe, 49 | D3DXMATRIX *wm, const D3DXMATRIX &objma, const D3DXMATRIX &iobjma, D3DXVECTOR3 &light, 50 | int texsize); 51 | 52 | void ShadowProjBuildFull(CVOShadowProj &sp, CVectorObjectAnim &obj, int noframe, const D3DXMATRIX &objma, 53 | const D3DXMATRIX &iobjma, D3DXVECTOR3 &light, int mapradius, int texsize, bool doclip, 54 | bool render_texture, bool join_to_group); 55 | void ShadowProjBuildFullList(CVOShadowProj &sp, int cnt, CVectorObjectAnim **obj, CTexture *tex, int *noframe, 56 | D3DXMATRIX *wm, const D3DXMATRIX &objma, const D3DXMATRIX &iobjma, D3DXVECTOR3 &light, 57 | int mapradius, int texsize /*,wchar * texid*/, bool join_to_group); 58 | -------------------------------------------------------------------------------- /MatrixGame/src/MatrixSkinManager.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_SKIN_MANAGER 7 | #define MATRIX_SKIN_MANAGER 8 | 9 | #include "VectorObject.hpp" 10 | 11 | enum GSParam { 12 | GSP_SIDE, 13 | GSP_ORDINAL, 14 | GSP_SIDE_NOALPHA, 15 | 16 | GSP_COUNT 17 | }; 18 | 19 | struct SMatrixSkin : public SSkin { 20 | CTextureManaged *m_Tex; // if NULL, default texturing 21 | CTextureManaged *m_TexGloss; 22 | CTextureManaged *m_TexMask; 23 | CTextureManaged *m_TexBack; 24 | float m_tu, m_tv, m_dtu, m_dtv; 25 | 26 | bool operator==(const SMatrixSkin &sk) const { 27 | return m_Tex == sk.m_Tex && m_TexGloss == sk.m_TexGloss && m_TexMask == sk.m_TexMask && 28 | m_TexBack == sk.m_TexBack && m_dtu == sk.m_dtu && m_dtv == sk.m_dtv; // && 29 | // m_SetupClear == sk.m_SetupClear && 30 | // m_SetupStages == sk.m_SetupStages && 31 | // m_SetupTex == sk.m_SetupTex && 32 | // m_SetupTexShadow == sk.m_SetupTexShadow; 33 | } 34 | 35 | void Prepare(GSParam gsp); 36 | 37 | void Prepare6Side(void); 38 | void Prepare6SideNA(void); 39 | void Prepare6Ordinal(void); 40 | 41 | void Prepare4Side(void); 42 | void Prepare4SideNA(void); 43 | void Prepare4Ordinal(void); 44 | 45 | void Prepare3Side(void); 46 | void Prepare3SideNA(void); 47 | void Prepare3Ordinal(void); 48 | 49 | void Prepare2Side(void); 50 | void Prepare2SideNA(void); 51 | void Prepare2Ordinal(void); 52 | }; 53 | 54 | typedef SMatrixSkin *PSMatrixSkin; 55 | typedef PSMatrixSkin *PPSMatrixSkin; 56 | 57 | class CSkinManager : public CMain { 58 | static PPSMatrixSkin m_Skins[GSP_COUNT]; 59 | static int m_SkinsCount[GSP_COUNT]; 60 | 61 | public: 62 | static void StaticInit(void) { 63 | m_Skins[GSP_SIDE] = NULL; 64 | m_SkinsCount[GSP_SIDE] = 0; 65 | m_Skins[GSP_SIDE_NOALPHA] = NULL; 66 | m_SkinsCount[GSP_SIDE_NOALPHA] = 0; 67 | m_Skins[GSP_ORDINAL] = NULL; 68 | m_SkinsCount[GSP_ORDINAL] = 0; 69 | } 70 | 71 | static const SSkin *GetSkin(const wchar *tex, DWORD param); 72 | 73 | static void Clear(void); 74 | static void Takt(float cms); 75 | }; 76 | 77 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixTransition.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef MATRIX_TRANSITION_INCLUDE 7 | #define MATRIX_TRANSITION_INCLUDE 8 | 9 | #include "MatrixInstantDraw.hpp" 10 | 11 | /** 12 | * @brief Probably the loading screen. 13 | */ 14 | class CTransition : public CMain { 15 | struct SGeom { 16 | D3DXVECTOR2 pos; 17 | D3DXVECTOR2 dir; 18 | SVert_V4_UV verts[4]; 19 | }; 20 | 21 | CTextureManaged *m_Tex; 22 | SGeom *m_Geom; 23 | int m_GeomCnt; 24 | 25 | int m_ScreenX; 26 | int m_ScreenY; 27 | 28 | public: 29 | CTransition(void) : CMain(), m_Tex(NULL), m_Geom(NULL), m_GeomCnt(0) {} 30 | ~CTransition() { Clear(); } 31 | 32 | void Clear(void); 33 | void BuildTexture(void); 34 | void RenderToPrimaryScreen(void); 35 | void Render(void); 36 | void Takt(int ms); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /MatrixGame/src/MatrixWater.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "Common.hpp" 9 | #include "D3DControl.hpp" 10 | 11 | #define INSHORE_FVF (D3DFVF_XYZ | D3DFVF_TEX1) 12 | struct SInshoreVertex { 13 | D3DXVECTOR3 p; 14 | float tu, tv; 15 | }; 16 | 17 | #define INSHORE_SPEED (0.0005f) 18 | 19 | #define INSHOREWAVES_CNT 7 20 | struct SInshorewave { 21 | static CTextureManaged *m_Tex; 22 | static D3D_VB m_VB; 23 | static int m_VB_ref; 24 | 25 | static void Create(int i, const D3DXVECTOR2 &pos, const D3DXVECTOR2 &dir, SInshorewave &iw); 26 | 27 | static void DrawBegin(void); 28 | static void DrawEnd(void); 29 | 30 | static void StaticInit(void) { 31 | m_Tex = NULL; 32 | m_VB = NULL; 33 | m_VB_ref = 0; 34 | } 35 | 36 | static bool PrepareVB(void); 37 | static void MarkAllBuffersNoNeed(void) { 38 | if (m_VB) 39 | DESTROY_VB(m_VB); 40 | }; 41 | 42 | void Release(void); 43 | void Draw(void); 44 | 45 | int m_Index; 46 | 47 | D3DXVECTOR2 pos; 48 | D3DXVECTOR2 dir; 49 | float len; 50 | float t; 51 | float speed; 52 | float scale; 53 | }; 54 | 55 | //#define MATRIX_WATER_VERTEX_FORMAT (D3DFVF_XYZ|D3DFVF_NORMAL/*|D3DFVF_DIFFUSE*/|D3DFVF_TEX3) 56 | #define MATRIX_WATER_VERTEX_FORMAT (D3DFVF_XYZ | D3DFVF_NORMAL /*|D3DFVF_DIFFUSE*/ | D3DFVF_TEX2) 57 | //#define MATRIX_WATER_VERTEX_FORMAT (D3DFVF_XYZ) 58 | struct SMatrixMapWaterVertex { 59 | D3DXVECTOR3 v; 60 | D3DXVECTOR3 n; 61 | float au, av; 62 | float tu, tv; 63 | // float mu,mv; 64 | }; 65 | 66 | class CMatrixWater : public CMain { 67 | float h[WATER_SIZE * WATER_SIZE]; 68 | float r[WATER_SIZE * WATER_SIZE]; 69 | int f[WATER_SIZE * WATER_SIZE]; 70 | 71 | int m_angle; 72 | int m_next_time; 73 | 74 | public: 75 | D3D_VB m_VB; 76 | D3D_IB m_IB; 77 | CTextureManaged *m_WaterTex1; 78 | CTextureManaged *m_WaterTex2; 79 | 80 | CMatrixWater(void); 81 | ~CMatrixWater(); 82 | 83 | void Clear(void); 84 | void Init(void); 85 | 86 | bool IsReadyForDraw(void) const { return IS_VB(m_VB); } 87 | 88 | void BeforeDraw(void); 89 | void Draw(const D3DXMATRIX &m); 90 | 91 | void Takt(int step); 92 | void FillVB(int k); 93 | }; 94 | -------------------------------------------------------------------------------- /MatrixGame/src/Text/Font.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace { 11 | 12 | LPD3DXFONT loadFont(IDirect3DDevice9* device, std::wstring_view name, size_t size) 13 | { 14 | LPD3DXFONT font{nullptr}; 15 | if (S_OK != D3DXCreateFontW(device, size, 0, FW_NORMAL, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 16 | DEFAULT_PITCH, name.data(), &font)) 17 | { 18 | lgr.error("Failed to load font: {}")(utils::from_wstring(name)); 19 | } 20 | return font; 21 | }; 22 | 23 | void prepareRangersFont() 24 | { 25 | HMODULE module = GetModuleHandle(nullptr); 26 | if (!module) 27 | { 28 | lgr.error("Failed to get module handle"); 29 | return; 30 | } 31 | 32 | HRSRC fontResource = FindResource(module, MAKEINTRESOURCE(IDF_RANGERS_FONT), RT_FONT); 33 | if (!fontResource) 34 | { 35 | lgr.error("Failed to find font resource"); 36 | return; 37 | } 38 | 39 | HGLOBAL loadedFont = LoadResource(module, fontResource); 40 | if (!loadedFont) 41 | { 42 | lgr.error("Failed to load font resource"); 43 | return; 44 | } 45 | 46 | LPVOID lockedRes = LockResource(loadedFont); 47 | if (!lockedRes) 48 | { 49 | lgr.error("Failed to lock font resource"); 50 | return; 51 | } 52 | 53 | DWORD resSize = SizeofResource(module, fontResource); 54 | if (!resSize) 55 | { 56 | lgr.error("Failed to get font resource size"); 57 | return; 58 | } 59 | 60 | DWORD numFonts = 0; 61 | HANDLE font = AddFontMemResourceEx(lockedRes, resSize, nullptr, &numFonts); 62 | if (!font) 63 | { 64 | lgr.error("Failed to add font"); 65 | return; 66 | } 67 | }; 68 | 69 | } // namespace 70 | 71 | namespace Text { 72 | 73 | Font::Font(LPD3DXFONT font) 74 | : m_font{font} 75 | { 76 | } 77 | 78 | Font::~Font() 79 | { 80 | if (m_font) 81 | { 82 | m_font->Release(); 83 | } 84 | } 85 | 86 | LPD3DXFONT Font::operator -> () const 87 | { 88 | return m_font; 89 | } 90 | 91 | Font::operator bool () const 92 | { 93 | return !(m_font == nullptr); 94 | } 95 | 96 | size_t Font::GetHeight() const 97 | { 98 | D3DXFONT_DESCW desc; 99 | m_font->GetDescW(&desc); 100 | return desc.Height; 101 | } 102 | 103 | size_t Font::GetSpaceWidth() const 104 | { 105 | SIZE size{}; 106 | GetTextExtentPoint32W(m_font->GetDC(), L" ", 1, &size); 107 | return size.cx; 108 | } 109 | 110 | size_t Font::CalcTextWidth(std::wstring_view text) const 111 | { 112 | const DWORD format = DT_CALCRECT | DT_NOCLIP | DT_SINGLELINE; 113 | RECT rect{0,0,0,0}; 114 | m_font->DrawTextW(NULL, text.data(), text.length(), &rect, format, 0); 115 | return rect.right; 116 | } 117 | 118 | Font& GetFont(IDirect3DDevice9* device, std::wstring_view font_name) 119 | { 120 | static auto m_fonts = [&]{ 121 | prepareRangersFont(); 122 | 123 | std::map fonts; 124 | fonts.emplace(L"Font.1Normal", loadFont(device, L"Verdana", 13)); 125 | fonts.emplace(L"Font.2Mini", loadFont(device, L"Verdana", 12)); 126 | fonts.emplace(L"Font.2Small", loadFont(device, L"Verdana", 13)); 127 | fonts.emplace(L"Font.2Normal", loadFont(device, L"Verdana", 14)); 128 | fonts.emplace(L"Font.2Ranger", loadFont(device, L"Rangers", 10)); 129 | return fonts; 130 | }(); 131 | 132 | if (!m_fonts.contains(font_name)) 133 | { 134 | throw std::runtime_error("Unknown font: " + utils::from_wstring(font_name)); 135 | } 136 | 137 | return m_fonts.at(font_name); 138 | } 139 | 140 | } // namespace Text -------------------------------------------------------------------------------- /MatrixGame/src/Text/Font.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace Text { 8 | 9 | class Font 10 | { 11 | public: 12 | // no copy, no move 13 | Font(const Font&) = delete; 14 | Font(Font&&) = delete; 15 | Font& operator = (const Font&) = delete; 16 | Font& operator = (Font&&) = delete; 17 | 18 | Font(LPD3DXFONT font); 19 | 20 | ~Font(); 21 | 22 | LPD3DXFONT operator -> () const; 23 | 24 | explicit operator bool () const; 25 | 26 | size_t GetHeight() const; 27 | 28 | size_t GetSpaceWidth() const; 29 | 30 | size_t CalcTextWidth(std::wstring_view text) const; 31 | 32 | private: 33 | LPD3DXFONT m_font{nullptr}; 34 | }; 35 | 36 | Font& GetFont(IDirect3DDevice9* device, std::wstring_view font_name); 37 | 38 | } // namespace Text 39 | -------------------------------------------------------------------------------- /MatrixGame/src/Text/Parser.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Text { 10 | 11 | constexpr std::wstring_view COLOR_TAG_START{L""}; 13 | 14 | bool icase_starts_with(std::wstring_view text, std::wstring_view prefix); 15 | size_t icase_find(std::wstring_view text, std::wstring_view prefix); 16 | 17 | struct Token 18 | { 19 | std::wstring_view text; 20 | uint32_t color{0}; 21 | size_t width{0}; 22 | }; 23 | 24 | std::vector parse_tokens(std::wstring_view str, Font& font); 25 | size_t calc_lines(const std::vector& text, Font& font, const RECT &rect); 26 | 27 | } // namespace Text -------------------------------------------------------------------------------- /MatrixGame/src/Text/Render.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace Text { 8 | 9 | void Render( 10 | std::wstring_view text, 11 | std::wstring_view font, 12 | uint32_t color, 13 | int sizex, 14 | int sizey, 15 | int alignx, 16 | int aligny, 17 | int wordwrap, 18 | int smex, 19 | int smy, 20 | const Base::CRect& clipr, 21 | CBitmap& dst); 22 | 23 | } // namespace Text -------------------------------------------------------------------------------- /MatrixGame/src/cheats.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Cheats 6 | { 7 | public: 8 | static bool processInput(uint8_t vk); 9 | }; -------------------------------------------------------------------------------- /MatrixGame/src/input.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | extern CMatrixConfig g_Config; 8 | 9 | namespace Input { 10 | 11 | static std::bitset<256> down_keys; 12 | 13 | void onKeyDown(uint8_t vk) 14 | { 15 | down_keys.set(vk); 16 | } 17 | 18 | void onKeyUp(uint8_t vk) 19 | { 20 | down_keys.reset(vk); 21 | } 22 | 23 | bool isVKeyPressed(uint8_t vk) 24 | { 25 | return down_keys.test(vk); 26 | } 27 | 28 | bool isKeyPressed(EKeyAction ka) 29 | { 30 | return isVKeyPressed(g_Config.m_KeyActions[ka]); 31 | } 32 | 33 | } // namespace Input -------------------------------------------------------------------------------- /MatrixLib/3G/CCamera.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CCAMERA_H 7 | #define CCAMERA_H 8 | 9 | #include "d3dx9.h" 10 | #include "CCoordSystem.hpp" 11 | 12 | // camera 13 | class CCamera : public CWorldObject { 14 | D3DXVECTOR3 _pos; 15 | D3DXQUATERNION _rot; 16 | 17 | D3DXMATRIX _view; 18 | D3DXMATRIX _proj; 19 | 20 | public: 21 | CCamera(CCoordSystem *cs) : CWorldObject(cs) {} 22 | 23 | virtual void Render(void) { 24 | // SetTransform 25 | } 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/CVertexBuffer.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CVERTEXBUFFER_H 7 | #define CVERTEXBUFFER_H 8 | 9 | #include "d3dx9.h" 10 | #include "CCoordSystem.hpp" 11 | #include "SVertex.hpp" 12 | 13 | class CVertexBuffer : public CWorldObject { 14 | int _vsize; // one vertex size 15 | int _count_verts; // количество вершин в буфере 16 | IDirect3DVertexBuffer9 *_buffer; 17 | 18 | public: 19 | CVertexBuffer(CCoordSystem *cs, int vertex_size) 20 | : CWorldObject(cs), _vsize(vertex_size), _buffer(0), _count_verts(0) {} 21 | 22 | void CreateBuffer(int count_verts) { 23 | _count_verts = count_verts; 24 | if (_buffer) 25 | _buffer->Release(); 26 | 27 | g_D3DD->CreateVertexBuffer(count_verts * _vsize, D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY, 28 | D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, D3DPOOL_DEFAULT, &_buffer, 0); 29 | } 30 | 31 | void *Lock(void) { 32 | void *out; 33 | ASSERT_DX(_buffer->Lock(0, 0, &out, 0)); 34 | return out; 35 | } 36 | 37 | void Unlock(void) { ASSERT_DX(_buffer->Unlock()); } 38 | 39 | virtual void Render(void) {} 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/CWorld.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CWORLD_H 7 | #define CWORLD_H 8 | 9 | #include "d3dx9.h" 10 | #include "CWorldObject.hpp" 11 | #include "CCoordSystem.hpp" 12 | #include "CCamera.hpp" 13 | #include "CVertexBuffer.hpp" 14 | 15 | // world 16 | class CWorld : public CWorldObject { 17 | CCamera *_ccamera; // current camera 18 | 19 | CWorldObject *_list; 20 | 21 | public: 22 | CWorld(CCoordSystem *cs) : CWorldObject(cs) {} 23 | 24 | virtual void Render(void) { 25 | // SetTransform 26 | } 27 | 28 | void Add(CWorldObject *wo) { _list->ListAdd(wo); } 29 | 30 | void SetCam(CCamera *cam) { _ccamera = cam; } 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/CWorldObject.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CWORLDOBJECT_H 7 | #define CWORLDOBJECT_H 8 | 9 | #include "d3dx9.h" 10 | 11 | #include "../Base/CList.hpp" 12 | 13 | class CCoordSystem; 14 | 15 | class CWorldObject : public CMain, public CListInterface { 16 | CCoordSystem *_owner; // координатная система - владелец 17 | 18 | public: 19 | CWorldObject(CCoordSystem *cs) : _owner(cs) {} 20 | 21 | virtual void Render(void) = 0; 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/Cache.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "CMain.hpp" 9 | #include "CHeap.hpp" 10 | #include "CBuf.hpp" 11 | 12 | #include 13 | 14 | class CCache; 15 | 16 | enum class CacheClass 17 | { 18 | Unknown = 0, 19 | Texture, 20 | TextureManaged, 21 | VO 22 | }; 23 | 24 | class CCacheData 25 | { 26 | public: 27 | CCache *m_Cache{nullptr}; 28 | #ifdef _DEBUG 29 | const char *d_file; 30 | int d_line; 31 | #endif 32 | 33 | CacheClass m_Type{CacheClass::Unknown}; 34 | std::wstring m_Name{}; 35 | 36 | int m_Ref{0}; // Кол-во ссылок на эти данные. (Для временных данных) 37 | 38 | public: 39 | CCacheData(void) = default; 40 | virtual ~CCacheData() = default; 41 | 42 | void RefInc(void) { m_Ref++; } 43 | void RefDec(void) { 44 | m_Ref--; 45 | ASSERT(m_Ref >= 0); 46 | } 47 | int Ref(void) { return m_Ref; } 48 | bool RefDecUnload(void) { 49 | m_Ref--; 50 | if (m_Ref <= 0) { 51 | Unload(); 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | void Prepare(void); 58 | 59 | void LoadFromFile(CBuf &buf, const wchar *exts = NULL); 60 | 61 | virtual bool IsLoaded(void) = 0; 62 | virtual void Unload(void) = 0; 63 | virtual void Load(void) = 0; 64 | }; 65 | 66 | class CCache 67 | { 68 | public: 69 | std::list _data; 70 | 71 | public: 72 | CCache() = default; 73 | ~CCache() = default; 74 | 75 | #ifdef _DEBUG 76 | static void Dump(void); 77 | #endif 78 | 79 | void Add(CCacheData *cd); 80 | void Delete(CCacheData *cd); 81 | void Up(CCacheData *cd); 82 | 83 | void PreLoad(void); 84 | 85 | CCacheData *Find(CacheClass cc, const std::wstring_view name); 86 | CCacheData *Get(CacheClass cc, const std::wstring_view name); 87 | #ifdef _DEBUG 88 | static CCacheData *Create(CacheClass cc, const char *file, int line); 89 | #else 90 | static CCacheData *Create(CacheClass cc); 91 | #endif 92 | static void Destroy(CCacheData *cd); 93 | 94 | void Clear(void); 95 | }; 96 | 97 | #ifdef _DEBUG 98 | #define CACHE_CREATE_VO() (CVectorObject *)CCache::Create(CacheClass::VO, __FILE__, __LINE__) 99 | #define CACHE_CREATE_TEXTURE() (CTexture *)CCache::Create(CacheClass::Texture, __FILE__, __LINE__) 100 | #define CACHE_CREATE_TEXTUREMANAGED() (CTextureManaged *)CCache::Create(CacheClass::TextureManaged, __FILE__, __LINE__) 101 | #else 102 | #define CACHE_CREATE_VO() (CVectorObject *)CCache::Create(CacheClass::VO) 103 | #define CACHE_CREATE_TEXTURE() (CTexture *)CCache::Create(CacheClass::Texture) 104 | #define CACHE_CREATE_TEXTUREMANAGED() (CTextureManaged *)CCache::Create(CacheClass::TextureManaged) 105 | #endif 106 | 107 | extern CCache *g_Cache; 108 | extern CHeap *g_CacheHeap; 109 | extern const wchar *CacheExtsTex; 110 | 111 | void CacheInit(void); 112 | void CacheDeinit(void); 113 | 114 | void CacheReplaceFileExt(std::wstring &outname, const std::wstring_view mname, const std::wstring_view ext); 115 | void CacheReplaceFileNameAndExt(std::wstring &outname, const std::wstring_view mname, const std::wstring_view replname); 116 | -------------------------------------------------------------------------------- /MatrixLib/3G/DeviceState.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef _DEVICE_STATE_INCLUDE 7 | #define _DEVICE_STATE_INCLUDE 8 | 9 | #define DEVSTATE_ALL (-1) 10 | #define DEVSTATE_RENDERSTATES SETBIT(0) 11 | #define DEVSTATE_SAMPLERSTATES SETBIT(1) 12 | #define DEVSTATE_LIGHTS SETBIT(2) 13 | #define DEVSTATE_MATERIAL SETBIT(3) 14 | 15 | #define RS_COUNT 103 16 | #define SS_COUNT 13 17 | #define LI_COUNT 8 18 | 19 | class CDeviceState : public CMain { 20 | IDirect3DDevice9 *m_Device; 21 | 22 | DWORD m_RenderStates[RS_COUNT]; 23 | DWORD m_SamplerStates[SS_COUNT * 8]; 24 | BOOL m_LightsEnabled[LI_COUNT]; 25 | D3DLIGHT9 m_Lights[LI_COUNT]; 26 | D3DMATERIAL9 m_Material; 27 | 28 | public: 29 | CDeviceState(IDirect3DDevice9 *dev) : m_Device(dev) {} 30 | 31 | void StoreState(DWORD states = DEVSTATE_ALL); 32 | void RestoreState(DWORD states = DEVSTATE_ALL); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/Form.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "Form.hpp" 7 | #include "BaseDef.hpp" 8 | #include "Tracer.hpp" 9 | 10 | CForm *g_FormFirst; 11 | CForm *g_FormLast; 12 | CForm *g_FormCur; 13 | 14 | //////////////////////////////////////////////////////////////////////////////// 15 | //////////////////////////////////////////////////////////////////////////////// 16 | //////////////////////////////////////////////////////////////////////////////// 17 | CForm::CForm() : Base::CMain(), m_Name() { 18 | DTRACE(); 19 | 20 | m_FormPrev = NULL; 21 | m_FormNext = NULL; 22 | 23 | LIST_ADD(this, g_FormFirst, g_FormLast, m_FormPrev, m_FormNext); 24 | } 25 | 26 | CForm::~CForm() { 27 | DTRACE(); 28 | 29 | LIST_DEL(this, g_FormFirst, g_FormLast, m_FormPrev, m_FormNext); 30 | } 31 | 32 | void CForm::StaticInit(void) { 33 | g_FormFirst = NULL; 34 | g_FormLast = NULL; 35 | g_FormCur = NULL; 36 | } 37 | 38 | //////////////////////////////////////////////////////////////////////////////// 39 | //////////////////////////////////////////////////////////////////////////////// 40 | //////////////////////////////////////////////////////////////////////////////// 41 | 42 | void FormChange(CForm *form) { 43 | DTRACE(); 44 | 45 | if (g_FormCur) { 46 | g_FormCur->Leave(); 47 | } 48 | g_FormCur = form; 49 | if (g_FormCur) 50 | g_FormCur->Enter(); 51 | } 52 | -------------------------------------------------------------------------------- /MatrixLib/3G/Form.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include "CMain.hpp" 12 | 13 | enum ButtonStatus { 14 | B_DOWN, 15 | B_UP, 16 | B_DOUBLE, 17 | 18 | B_WHEEL 19 | }; 20 | 21 | enum ESysEvent { 22 | SYSEV_DEACTIVATING, 23 | SYSEV_ACTIVATED, 24 | }; 25 | 26 | /** 27 | * @brief Probably represents an abstract logical Window. 28 | * 29 | * Is double-linked chained (i.e. it's an element of all other Forms Linked List.) 30 | * 31 | * Yet it seems like its ability to have multiple forms is never used, 32 | * or it could be used inside of Map Editor, source code of which is not available. 33 | */ 34 | class CForm : public Base::CMain { 35 | private: 36 | CForm *m_FormPrev; 37 | CForm *m_FormNext; 38 | 39 | protected: 40 | std::wstring m_Name; // Нужно всегда задавать имя для дочерних классов 41 | 42 | public: 43 | static void StaticInit(void); 44 | 45 | CForm(void); 46 | ~CForm(); 47 | 48 | virtual void Enter(void) = 0; 49 | virtual void Leave(void) = 0; 50 | 51 | /** 52 | * @brief Execute draw logic for this window? 53 | */ 54 | virtual void Draw(void) = 0; 55 | 56 | /** 57 | * @brief Execute logic frame for this window? 58 | */ 59 | virtual void Takt(int delta_ms) = 0; 60 | 61 | virtual void MouseMove(int x, int y) = 0; 62 | virtual void MouseKey(ButtonStatus status, int key, int x, int y) = 0; 63 | 64 | virtual void Keyboard(bool, uint8_t) = 0; 65 | 66 | virtual void SystemEvent(ESysEvent se) = 0; 67 | }; 68 | 69 | extern CForm *g_FormFirst; 70 | extern CForm *g_FormLast; 71 | extern CForm *g_FormCur; 72 | 73 | void FormChange(CForm *form); 74 | -------------------------------------------------------------------------------- /MatrixLib/3G/Helper.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef HELPER_INCLUDE 7 | #define HELPER_INCLUDE 8 | 9 | #include 10 | #include 11 | 12 | #include "CMain.hpp" 13 | 14 | #include "d3d9.h" 15 | #include "d3dx9tex.h" 16 | 17 | // Класс для отображения дебуг информации в 3D 18 | 19 | #if (defined _DEBUG) && !(defined _RELDEBUG) 20 | 21 | #define HelperVertexFormat (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1) 22 | struct SHelperVertex { 23 | D3DXVECTOR3 v; 24 | D3DXVECTOR3 n; 25 | DWORD defcol; 26 | float tu, tv; 27 | }; 28 | 29 | class CHelper : public Base::CMain { 30 | static CHelper *m_First; 31 | static CHelper *m_Last; 32 | 33 | CHelper(int del_after_cnt_draw = 0, int group = 0); 34 | ~CHelper(); 35 | 36 | CHelper *m_Prev; 37 | CHelper *m_Next; 38 | CHelper *m_Parent; 39 | 40 | D3DXMATRIX m_Matrix; 41 | 42 | int m_DeleteAfterCntDraw; 43 | int m_Group; 44 | 45 | D3DPRIMITIVETYPE m_Type; 46 | int m_CntPrimitive; 47 | int m_CntVertex; 48 | int m_CntIndex; 49 | SHelperVertex *m_Vertex; 50 | uint16_t *m_Index; 51 | 52 | void SetMatrixPos(const D3DXVECTOR3 &pos) { 53 | m_Matrix._41 = pos.x; 54 | m_Matrix._42 = pos.y; 55 | m_Matrix._43 = pos.z; 56 | } 57 | 58 | public: 59 | static void StaticInit(void); 60 | static CHelper *Create(int del_after_cnt_draw = 0, int group = 0); 61 | static void Destroy(CHelper *he); 62 | static void ClearAll(void); 63 | static void DrawAll(void); 64 | static void AfterDraw_r(CHelper *del); 65 | static void AfterDraw(void); 66 | static void DestroyByGroup(int group); 67 | 68 | static void DrawBegin(void); 69 | static void DrawEnd(void); 70 | 71 | CHelper *Prev(void) { return m_Prev; } 72 | CHelper *Next(void) { return m_Next; } 73 | 74 | int DeleteAfterCntDraw(void) { return m_DeleteAfterCntDraw; } 75 | void DeleteAfterCntDraw(int zn) { m_DeleteAfterCntDraw = zn; } 76 | CHelper *Parent(void) { return m_Parent; } 77 | void Parent(CHelper *parent) { m_Parent = parent; } 78 | int Group(void) { return m_Group; } 79 | void Group(int zn) { m_Group = zn; } 80 | 81 | D3DXMATRIX *Matrix(void) { return &m_Matrix; } 82 | 83 | void Clear(void); 84 | void Line(const D3DXVECTOR3 &start, const D3DXVECTOR3 &end, DWORD color1 = 0xffffffff, DWORD color2 = 0xffffffff); 85 | void BoundBox(const D3DXVECTOR3 &mins, const D3DXVECTOR3 &maxs, DWORD color = 0xffffffff); 86 | SHelperVertex *Lines(int cnt); // cnt-кол-во линий. (точек=cnt*2) 87 | SHelperVertex *LineStrip(int cnt); // cnt-кол-во линий. (точек=cnt*2-2) 88 | void Sphere(const D3DXVECTOR3 &pos, float radius, int cnt_rings, DWORD color); 89 | void Cone(D3DXVECTOR3 vFrom, D3DXVECTOR3 vTo, float rFrom, float rTo, DWORD colorFrom, DWORD colorTo, int seg_cnt); 90 | void ConeUpdate(D3DXVECTOR3 vFrom, D3DXVECTOR3 vTo, float rFrom, float rTo, DWORD colorFrom, DWORD colorTo); 91 | 92 | void Triangle(const D3DXVECTOR3 &p0, const D3DXVECTOR3 &p1, const D3DXVECTOR3 &p2, DWORD color); 93 | 94 | void Draw(void); 95 | }; 96 | 97 | #endif 98 | 99 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/SVertex.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CVERTEX_H 7 | #define CVERTEX_H 8 | 9 | #include "d3dx9.h" 10 | 11 | struct SVertex { 12 | D3DXVECTOR3 v; 13 | D3DXVECTOR3 n; 14 | float tu, tv; 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/ShadowProj.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "ShadowProj.hpp" 7 | 8 | CBigVB *CVOShadowProj::m_VB; 9 | CBigIB *CVOShadowProj::m_IB; 10 | 11 | //////////////////////////////////////////////////////////////////////////////// 12 | //////////////////////////////////////////////////////////////////////////////// 13 | //////////////////////////////////////////////////////////////////////////////// 14 | CVOShadowProj::CVOShadowProj(CHeap *heap) : CMain(), m_Heap(heap) { 15 | DTRACE(); 16 | 17 | // m_Strips = (SVOShadowProjStrip *)HAlloc(sizeof(SVOShadowProjStrip) * 16, heap); 18 | // m_StripsCnt = 0; 19 | // m_StripsMax = 16; 20 | 21 | m_VertCnt = 0; 22 | m_TriCnt = 0; 23 | 24 | m_Tex = NULL; 25 | if (m_VB == NULL) { 26 | m_VB = CBigVB::NewBigVB(m_Heap); 27 | m_IB = CBigIB::NewBigIB(m_Heap); 28 | } 29 | 30 | m_preVB.verts = NULL; 31 | m_preIB.inds = NULL; 32 | 33 | m_DX = 0; 34 | m_DY = 0; 35 | } 36 | 37 | CVOShadowProj::~CVOShadowProj() { 38 | DTRACE(); 39 | 40 | // HFree(m_Strips, m_Heap); 41 | 42 | if (m_preVB.verts) { 43 | if (m_IB->DelSource(&m_preIB)) { 44 | CBigIB::DestroyBigIB(m_IB); 45 | m_IB = NULL; 46 | } 47 | 48 | if (m_VB->DelSource(&m_preVB)) { 49 | CBigVB::DestroyBigVB(m_VB); 50 | m_VB = NULL; 51 | } 52 | HFree(m_preVB.verts, m_Heap); 53 | // HFree(m_preIB.inds, m_Heap); // do not free this mem, because it is in verts 54 | } 55 | 56 | if (m_Tex) { 57 | m_Tex->RefDec(); 58 | if (m_Tex->Ref() <= 0) { 59 | CCache::Destroy(m_Tex); 60 | } 61 | } 62 | } 63 | 64 | void CVOShadowProj::DestroyTexture(void) { 65 | DTRACE(); 66 | 67 | if (m_Tex) { 68 | m_Tex->RefDec(); 69 | if (m_Tex->Ref() <= 0) { 70 | CCache::Destroy(m_Tex); 71 | } 72 | m_Tex = NULL; 73 | } 74 | } 75 | 76 | void CVOShadowProj::Prepare(float dx, float dy, SVOShadowProjVertex *verts, int vertscnt, WORD *idxs, int idxscnt) { 77 | DTRACE(); 78 | 79 | if (vertscnt <= 0) { 80 | m_Tex = NULL; 81 | m_VertCnt = 0; 82 | m_TriCnt = 0; 83 | m_preVB.verts = 0; 84 | m_preIB.inds = 0; 85 | 86 | return; 87 | } 88 | m_DX = dx; 89 | m_DY = dy; 90 | 91 | m_VertCnt = vertscnt; 92 | m_TriCnt = idxscnt - 2; 93 | 94 | m_preVB.size = vertscnt * sizeof(SVOShadowProjVertex); 95 | m_preIB.size = idxscnt * sizeof(WORD); 96 | 97 | if (m_preVB.verts) 98 | HFree(m_preVB.verts, m_Heap); 99 | 100 | m_preVB.verts = (SVOShadowProjVertex *)HAlloc(m_preVB.size + m_preIB.size, m_Heap); 101 | memcpy(m_preVB.verts, verts, m_preVB.size); 102 | m_VB->AddSource(&m_preVB); 103 | 104 | m_preIB.inds = (WORD *)(((BYTE *)m_preVB.verts) + m_preVB.size); 105 | memcpy(m_preIB.inds, idxs, m_preIB.size); 106 | m_IB->AddSource(&m_preIB); 107 | } 108 | 109 | void CVOShadowProj::RenderMin(void) { 110 | DTRACE(); 111 | 112 | int vbase = m_preVB.Select(m_VB); 113 | if (vbase < 0) 114 | return; 115 | int ibase = m_preIB.Select(m_IB); 116 | if (ibase < 0) 117 | return; 118 | 119 | ASSERT_DX(g_D3DD->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, vbase, 0, m_VertCnt, ibase, m_TriCnt)); 120 | 121 | // for (int i = 0; iDrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, vbase, m_Strips[i].minidx, m_Strips[i].vcnt, 124 | // m_Strips[i].index + ibase, m_Strips[i].tricnt)); 125 | //} 126 | } 127 | -------------------------------------------------------------------------------- /MatrixLib/3G/ShadowProj.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef SHADOW_PROJ_INCLUDE 7 | #define SHADOW_PROJ_INCLUDE 8 | 9 | #include "Cache.hpp" 10 | #include "D3DControl.hpp" 11 | #include "BigVB.hpp" 12 | #include "BigIB.hpp" 13 | 14 | struct SVOShadowProjVertex { 15 | D3DXVECTOR3 v; 16 | float tu, tv; 17 | 18 | static const DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1; 19 | }; 20 | 21 | class CVOShadowCliper : public CMain { 22 | public: 23 | CVOShadowCliper(){}; 24 | ~CVOShadowCliper(void){}; 25 | 26 | virtual void BeforeRender(void) = 0; 27 | virtual void Render(void) = 0; 28 | }; 29 | 30 | class CVOShadowProj : public CMain { 31 | CBaseTexture *m_Tex; // it can be CTexture or CTextureManaged 32 | 33 | protected: 34 | static CBigVB *m_VB; 35 | static CBigIB *m_IB; 36 | CHeap *m_Heap; 37 | SBigVBSource m_preVB; 38 | SBigIBSource m_preIB; 39 | float m_DX, m_DY; 40 | int m_TriCnt; 41 | int m_VertCnt; 42 | 43 | public: 44 | static void StaticInit(void) { 45 | m_IB = NULL; 46 | m_VB = NULL; 47 | } 48 | static void MarkAllBuffersNoNeed(void) { 49 | if (m_VB) 50 | m_VB->ReleaseBuffers(); 51 | if (m_IB) 52 | m_IB->ReleaseBuffers(); 53 | } 54 | 55 | CVOShadowProj(CHeap *heap); 56 | ~CVOShadowProj(void); 57 | 58 | static void BeforeRenderAll(void) { 59 | if (m_IB) 60 | m_IB->BeforeDraw(); 61 | if (m_VB) 62 | m_VB->BeforeDraw(); 63 | ASSERT_DX(g_D3DD->SetFVF(SVOShadowProjVertex::FVF)); 64 | } 65 | 66 | CBaseTexture *GetTexture(void) { return m_Tex; } 67 | void SetTexture(CBaseTexture *tex) { m_Tex = tex; } 68 | bool IsProjected(void) const { return m_preVB.verts != NULL; } 69 | void DX_Prepare(void) { 70 | m_preVB.Prepare(m_VB); 71 | m_preIB.Prepare(m_IB); 72 | }; 73 | void DX_Free(void) { 74 | m_preVB.MarkNoNeed(m_VB); 75 | m_preIB.MarkNoNeed(m_IB); 76 | } 77 | 78 | float GetDX(void) const { return m_DX; } 79 | float GetDY(void) const { return m_DY; } 80 | 81 | void DestroyTexture(void); 82 | 83 | void Prepare(float dx, float dy, SVOShadowProjVertex *verts, int vertscnt, WORD *idxs, int idxscnt); 84 | void BeforeRender(void) { 85 | if (m_Tex) { 86 | if (m_Tex->IsTextureManaged()) { 87 | ((CTextureManaged *)m_Tex)->Preload(); 88 | } 89 | else { 90 | ((CTexture *)m_Tex)->Preload(); 91 | } 92 | } 93 | DX_Prepare(); 94 | } 95 | void RenderMin(void); 96 | void Render(void) { 97 | DTRACE(); 98 | #ifdef _DEBUG 99 | if (!m_Tex) 100 | ERROR_S(L"Oops, texture is NULL in shadow rendering."); 101 | #else 102 | if (!m_Tex) 103 | return; // just return 104 | #endif 105 | 106 | if (m_Tex->IsTextureManaged()) { 107 | g_D3DD->SetTexture(0, ((CTextureManaged *)m_Tex)->Tex()); 108 | } 109 | else { 110 | g_D3DD->SetTexture(0, ((CTexture *)m_Tex)->Tex()); 111 | } 112 | RenderMin(); 113 | } 114 | void RenderCustom(IDirect3DTexture9 *tex) { 115 | DTRACE(); 116 | g_D3DD->SetTexture(0, tex); 117 | RenderMin(); 118 | } 119 | }; 120 | 121 | struct SProjData { 122 | D3DXVECTOR3 vpos, vx, vy, vz; 123 | }; 124 | 125 | #endif -------------------------------------------------------------------------------- /MatrixLib/3G/ShadowStencil.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef SHADOW_STENCIL_INCLUDE 7 | #define SHADOW_STENCIL_INCLUDE 8 | 9 | #include "VectorObject.hpp" 10 | 11 | #include 12 | 13 | using SVOShadowStencilVertex = D3DXVECTOR3; 14 | 15 | class CVOShadowStencil 16 | { 17 | DWORD m_DirtyDX; 18 | D3D_VB m_VB; 19 | D3D_IB m_IB; 20 | 21 | int m_IBSize; // in bytes 22 | int m_VBSize; 23 | 24 | static CVOShadowStencil *m_First; 25 | static CVOShadowStencil *m_Last; 26 | 27 | CVOShadowStencil *m_Prev; 28 | CVOShadowStencil *m_Next; 29 | 30 | CVectorObject *m_vo; 31 | 32 | int m_FrameFor; 33 | 34 | struct SSSFrameData { 35 | std::vector m_preVerts; 36 | std::vector m_preInds; 37 | 38 | SVONormal m_light; 39 | float m_len; 40 | }; 41 | 42 | std::vector m_Frames; 43 | int m_FramesCnt; 44 | 45 | public: 46 | static void StaticInit(void) 47 | { 48 | m_First = NULL; 49 | m_Last = NULL; 50 | } 51 | static void BeforeRenderAll(void); 52 | 53 | static void MarkAllBuffersNoNeed(void); 54 | 55 | CVOShadowStencil(); 56 | ~CVOShadowStencil(); 57 | 58 | bool IsReady(void) const { return !m_Frames.empty(); } 59 | void DX_Prepare(void); 60 | void DX_Free(void) { 61 | if (IS_VB(m_VB)) 62 | DESTROY_VB(m_VB); 63 | if (IS_VB(m_IB)) 64 | DESTROY_VB(m_IB); 65 | 66 | m_DirtyDX = true; 67 | } 68 | 69 | void Build(CVectorObject &obj, int frame, const D3DXVECTOR3 &vLight, float len, bool invert); 70 | 71 | void BeforeRender(void) { DX_Prepare(); } 72 | void Render(const D3DXMATRIX &objma); 73 | }; 74 | 75 | #endif -------------------------------------------------------------------------------- /MatrixLib/Base/CBuf.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CBuf.hpp" 7 | #include "CException.hpp" 8 | #include "Mem.hpp" 9 | #include "CFile.hpp" 10 | 11 | namespace Base { 12 | 13 | void CBuf::Clear() { 14 | m_Buf.clear(); 15 | m_Pointer = 0; 16 | } 17 | 18 | void CBuf::Len(size_t zn) 19 | { 20 | if (zn == 0) { 21 | Clear(); 22 | return; 23 | } 24 | m_Buf.resize(zn); 25 | 26 | if (m_Pointer > m_Buf.size()) 27 | m_Pointer = m_Buf.size(); 28 | } 29 | 30 | size_t CBuf::StrLen(void) { 31 | size_t len = 0; 32 | for (size_t i = m_Pointer; i < m_Buf.size(); i++, len++) { 33 | if (*(char *)(m_Buf.data() + i) == 0) 34 | return len; 35 | } 36 | return 0; 37 | } 38 | 39 | size_t CBuf::WStrLen(void) { 40 | size_t len = 0; 41 | for (size_t i = m_Pointer; i + 1 < m_Buf.size(); i += 2, len++) { 42 | if (*(wchar *)(m_Buf.data() + i) == 0) 43 | return len; 44 | } 45 | return 0; 46 | } 47 | 48 | size_t CBuf::StrTextLen(void) { 49 | size_t len = 0; 50 | for (size_t i = m_Pointer; i < m_Buf.size(); i++, len++) { 51 | char ch = *(char *)(m_Buf.data() + i); 52 | if (ch == 0 || ch == 0x0d || ch == 0x0a) 53 | return len; 54 | } 55 | return len; 56 | } 57 | 58 | size_t CBuf::WStrTextLen(void) { 59 | size_t len = 0; 60 | for (size_t i = m_Pointer; i + 1 < m_Buf.size(); i += 2, len++) { 61 | wchar ch = *(wchar *)(m_Buf.data() + i); 62 | if (ch == 0 || ch == 0x0d || ch == 0x0a) 63 | return len; 64 | } 65 | return len; 66 | } 67 | 68 | void CBuf::LoadFromFile(const std::wstring &filename) 69 | { 70 | Clear(); 71 | CFile file(filename.c_str(), filename.length()); 72 | file.OpenRead(); 73 | Len(file.Size()); 74 | file.Read(m_Buf.data(), m_Buf.size()); 75 | file.Close(); 76 | } 77 | 78 | void CBuf::SaveInFile(const std::wstring &filename) const 79 | { 80 | CFile file(filename.c_str(), filename.length()); 81 | file.Create(); 82 | file.Write(const_cast(m_Buf.data()), m_Buf.size()); 83 | file.Close(); 84 | } 85 | 86 | } // namespace Base -------------------------------------------------------------------------------- /MatrixLib/Base/CException.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CException.hpp" 7 | #include 8 | 9 | #include "Tracer.hpp" 10 | 11 | #include 12 | 13 | namespace Base { 14 | 15 | CException::CException(const char *file, int line) 16 | : m_File{file} 17 | , m_Line{line} 18 | , call_trace{generate_trace_text()} 19 | { 20 | } 21 | 22 | std::wstring CException::Info() const 23 | { 24 | return 25 | utils::format( 26 | L"%lsFile=%ls\nLine=%d\n", 27 | utils::to_wstring(call_trace).c_str(), 28 | utils::to_wstring(m_File).c_str(), 29 | m_Line); 30 | } 31 | 32 | CExceptionStr::CExceptionStr( 33 | const char *file, 34 | int line, 35 | const wchar_t *str, 36 | const wchar_t *str2) 37 | : CException(file, line) 38 | { 39 | m_str = str; 40 | m_str += str2; 41 | } 42 | 43 | std::wstring CExceptionStr::Info() const 44 | { 45 | return CException::Info() + L"Text: " + m_str.c_str(); 46 | } 47 | 48 | } // namespace Base 49 | -------------------------------------------------------------------------------- /MatrixLib/Base/CException.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | #include "BaseDef.hpp" 10 | 11 | namespace Base { 12 | 13 | #define ERROR_E throw Base::CException(__FILE__, __LINE__) 14 | #define ERROR_S(s) throw Base::CExceptionStr(__FILE__, __LINE__, s) 15 | #define ERROR_S2(s, s2) throw Base::CExceptionStr(__FILE__, __LINE__, s, s2) 16 | 17 | #ifdef ASSERT_OFF 18 | #define ASSERT(zn) 19 | #else 20 | #ifdef _TRACE 21 | #define ASSERT(zn) \ 22 | { \ 23 | if ((zn) == 0) \ 24 | ERROR_E; \ 25 | } 26 | #else 27 | #define ASSERT(zn) \ 28 | { \ 29 | if ((zn) == 0) \ 30 | debugbreak(); \ 31 | } 32 | #endif 33 | #endif 34 | 35 | // lint -e1712 36 | class CException 37 | { 38 | const char *m_File; 39 | int m_Line; 40 | 41 | std::string call_trace; 42 | 43 | public: 44 | CException(const char *file, int line); 45 | 46 | virtual ~CException() = default; 47 | 48 | virtual std::wstring Info(void) const; 49 | }; 50 | 51 | class BASE_API CExceptionStr : public CException 52 | { 53 | std::wstring m_str; 54 | 55 | public: 56 | CExceptionStr(const char *file, int line, const wchar *str, const wchar *str2 = NULL); 57 | 58 | CExceptionStr(const char *file, int line, const std::wstring& str) 59 | :CExceptionStr(file, line, str.c_str()) 60 | {} 61 | 62 | virtual std::wstring Info(void) const; 63 | }; 64 | // lint +e1712 65 | } // namespace Base 66 | -------------------------------------------------------------------------------- /MatrixLib/Base/CFile.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "CMain.hpp" 9 | 10 | #include 11 | #include 12 | 13 | namespace Base { 14 | 15 | #ifndef MAXEXP_EXPORTS 16 | class CPackCollection; 17 | #endif 18 | 19 | typedef void (*ENUM_FILES)(const std::wstring &name, DWORD user); 20 | 21 | class BASE_API CFile : public CMain { 22 | #ifndef MAXEXP_EXPORTS 23 | static CPackCollection *m_Packs; 24 | static int m_PacksRef; 25 | 26 | DWORD m_PackHandle; 27 | #endif 28 | 29 | HANDLE m_Handle; // Handle файла 30 | std::wstring m_FileName; // Имя файла 31 | int m_Open; // Кол-во вызовов Open 32 | 33 | public: 34 | CFile(); 35 | CFile(const std::wstring &filename); 36 | CFile(const wchar *filename); 37 | CFile(const wchar *filename, int len); 38 | ~CFile(); 39 | 40 | static void StaticInit(void) { 41 | #ifndef MAXEXP_EXPORTS 42 | m_Packs = NULL; 43 | m_PacksRef = 0; 44 | #endif 45 | } 46 | 47 | #ifndef MAXEXP_EXPORTS 48 | static void AddPackFile(const wchar *name); 49 | static void OpenPackFiles(void); 50 | static void ReleasePackFiles(void); 51 | #endif 52 | 53 | static void FindFiles(const std::wstring &folderfrom, const wchar *files, ENUM_FILES ef, DWORD user); 54 | 55 | void Clear(void); 56 | 57 | void Init(const wchar *filename, int len); 58 | void Init(const wchar *filename) { Init(filename, std::wcslen(filename)); } 59 | void Init(const std::wstring &filename) { Init(filename.c_str(), filename.length()); } 60 | 61 | bool IsOpen(void) { return m_Open > 0; } 62 | 63 | void Open(DWORD shareMode = 0); // FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE 64 | void OpenRead(DWORD shareMode = FILE_SHARE_READ); // FILE_SHARE_DELETE FILE_SHARE_READ FILE_SHARE_WRITE 65 | bool OpenReadNE(DWORD shareMode = FILE_SHARE_READ); 66 | void Create(DWORD shareMode = 0); 67 | bool CreateNE(DWORD shareMode = 0); 68 | 69 | void Close(void); 70 | 71 | DWORD Size(void) const; 72 | __int64 SizeFull(void) const; 73 | 74 | __int64 PointerFull(void) const; 75 | void PointerFull(__int64 zn, int from = FILE_BEGIN) const; // FILE_BEGIN FILE_CURRENT FILE_END 76 | 77 | DWORD Pointer(void) const; 78 | void Pointer(DWORD zn, int from = FILE_BEGIN) const; // FILE_BEGIN FILE_CURRENT FILE_END 79 | 80 | void Read(void *buf, DWORD kolbyte); 81 | void Write(void *buf, DWORD kolbyte); 82 | 83 | static bool FileExist(std::wstring &outname, const wchar *mname, const wchar *exts = NULL, bool withpar = false); 84 | }; 85 | 86 | } // namespace Base -------------------------------------------------------------------------------- /MatrixLib/Base/CList.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CList.hpp" 7 | 8 | //===========================================================================// 9 | // G L O B A L F U N C T I O N S 10 | 11 | void CList ::Add( 12 | 13 | CList *head) throw() { 14 | CList *p; 15 | 16 | p = this->m_prev; 17 | 18 | this->m_prev = head->m_prev; 19 | 20 | p->m_next = head; 21 | 22 | head->m_prev = p; 23 | } 24 | 25 | //---------------------------------------------------------------------------// 26 | 27 | CList *CList ::Sub( 28 | 29 | CList *item) throw() { 30 | CList *head; 31 | CList *n; 32 | CList *p; 33 | 34 | head = this; 35 | n = item->m_next; 36 | p = item->m_prev; 37 | 38 | if (head != item) { 39 | p->m_next = n; 40 | } 41 | else { 42 | head = n; 43 | } 44 | 45 | if (n != 0) { 46 | n->m_prev = p; 47 | } 48 | else { 49 | if (head != 0) { 50 | head->m_prev = p; 51 | } 52 | } 53 | 54 | item->Init(); 55 | 56 | return head; 57 | } 58 | 59 | //---------------------------------------------------------------------------// 60 | 61 | void CList ::Split( 62 | 63 | CList *item) throw() { 64 | CList *p; 65 | 66 | p = item->m_prev; 67 | item->m_prev = this->m_prev; 68 | this->m_prev = p; 69 | p->m_next = 0; 70 | } 71 | 72 | //---------------------------------------------------------------------------// 73 | 74 | CList *CList ::Insert( 75 | 76 | CList *head, CList *to_item) throw() { 77 | CList *p; 78 | 79 | if (to_item == 0) { 80 | this->Add(head); 81 | return this; 82 | } 83 | 84 | p = head->m_prev; 85 | p->m_next = to_item; 86 | head->m_prev = to_item->m_prev; 87 | to_item->m_prev = p; 88 | 89 | if (to_item == this) { 90 | return head; 91 | } 92 | 93 | return this; 94 | } 95 | 96 | //---------------------------------------------------------------------------// 97 | 98 | CList *CList ::Move( 99 | 100 | CList *item, CList *to_item) throw() { 101 | CList *head; 102 | 103 | head = this->Sub(item); 104 | if (head != 0) { 105 | return head->Insert(item, to_item); 106 | } 107 | 108 | return item; 109 | } 110 | -------------------------------------------------------------------------------- /MatrixLib/Base/CList.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #ifndef CLIST_HPP 7 | #define CLIST_HPP 8 | 9 | class CList { 10 | protected: 11 | //-------------------------------------------------------// 12 | // D A T A 13 | 14 | CList *m_next; 15 | CList *m_prev; 16 | 17 | //-------------------------------------------------------// 18 | // M E T H O D S 19 | 20 | inline void Init(void) throw() { 21 | this->m_next = 0; 22 | this->m_prev = this; 23 | } 24 | 25 | //-------------------------------------------------------// 26 | 27 | inline CList(void) throw() { this->Init(); } 28 | 29 | //-------------------------------------------------------// 30 | 31 | inline ~CList(void) throw() {} 32 | 33 | //-------------------------------------------------------// 34 | 35 | void Add(CList *head) throw(); 36 | 37 | CList *Sub(CList *item) throw(); 38 | 39 | void Split(CList *item) throw(); 40 | 41 | CList *Insert(CList *head, CList *to_item) throw(); 42 | 43 | CList *Move(CList *item, CList *to_item) throw(); 44 | }; 45 | 46 | //-------------------------------------------------------// 47 | 48 | template 49 | class CListInterface : public CList { 50 | public: 51 | //-------------------------------------------------------// 52 | 53 | inline T *GetNext(void) const throw() { return static_cast(this->m_next); } 54 | 55 | //-------------------------------------------------------// 56 | 57 | inline T *GetPrev(void) const throw() { return static_cast(this->m_prev); } 58 | 59 | //-------------------------------------------------------// 60 | 61 | inline CListInterface(void) throw() : CList() {} 62 | 63 | //-------------------------------------------------------// 64 | 65 | inline ~CListInterface(void) throw() {} 66 | 67 | //-------------------------------------------------------// 68 | 69 | inline void ListAdd(T *head) throw() { this->Add(head); } 70 | 71 | //-------------------------------------------------------// 72 | 73 | inline T *ListSub(T *item) throw() { return static_cast(this->sub(item)); } 74 | 75 | //-------------------------------------------------------// 76 | 77 | inline void ListSplit(T *item) throw() { this->Split(item); } 78 | 79 | //-------------------------------------------------------// 80 | 81 | inline T *ListInsert(T *head, T *to_item) throw() { return static_cast(this->Insert(item, to_item)); } 82 | 83 | //-------------------------------------------------------// 84 | 85 | inline T *ListMove(T *item, T *to_item) throw() { return static_cast(this->Move(item, to_item)); } 86 | 87 | //-------------------------------------------------------// 88 | 89 | void ListFree(void) throw() { 90 | T *head; 91 | T *item; 92 | 93 | head = static_cast(this); 94 | 95 | do { 96 | item = head->GetNext(); 97 | 98 | delete head; 99 | 100 | head = item; 101 | } 102 | while (head != NULL); 103 | } 104 | }; 105 | 106 | #endif // #ifndef CLIST_HPP // 107 | -------------------------------------------------------------------------------- /MatrixLib/Base/CMain.cpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #include "CMain.hpp" 7 | 8 | #include "CFile.hpp" 9 | 10 | #include "CReminder.hpp" 11 | #include "Tracer.hpp" 12 | 13 | namespace Base { 14 | 15 | #ifdef DEAD_CLASS_SPY_ENABLE 16 | 17 | #define SEMETERY_SIZE 100000 18 | #define SEMETERY_HEAP_SIZE 1000000 19 | 20 | struct DCS_SDeadMem { 21 | const CMain *ptr_was; 22 | int size; 23 | int id; 24 | }; 25 | 26 | struct DCS_SDeadMemBody { 27 | int id; 28 | int size; 29 | }; 30 | 31 | static int DCS_get_id(void) { 32 | static int last_id; 33 | return last_id++; 34 | } 35 | BYTE DCS_semetery_heap[SEMETERY_HEAP_SIZE]; 36 | DCS_SDeadMem DCS_semetery[SEMETERY_SIZE]; 37 | 38 | int DCS_semetery_cnt = 0; 39 | int DCS_semetery_heap_size = 0; 40 | 41 | static int DCS_find_by_id(int id, BYTE **ptr) { 42 | DCS_SDeadMemBody *b = (DCS_SDeadMemBody *)&DCS_semetery_heap; 43 | 44 | while (id != b->id) { 45 | b = (DCS_SDeadMemBody *)(((BYTE *)b) + b->size); 46 | } 47 | 48 | *ptr = (BYTE *)b; 49 | return b->size; 50 | } 51 | static void DCS_remove_by_id(int id) { 52 | BYTE *ptr; 53 | int sz = DCS_find_by_id(id, &ptr); 54 | 55 | memcpy(ptr, ptr + sz, DCS_semetery_heap_size - sz); 56 | DCS_semetery_heap_size -= sz; 57 | } 58 | 59 | static void DCS_remove_first(void) { 60 | if (DCS_semetery_cnt == 0) 61 | return; 62 | DCS_remove_by_id(DCS_semetery[0].id); 63 | memcpy(DCS_semetery, DCS_semetery + 1, (SEMETERY_SIZE - 1) * sizeof(DCS_SDeadMem)); 64 | --DCS_semetery_cnt; 65 | } 66 | 67 | void CMain::DCS_ClassDead(int szc) const { 68 | int sz = sizeof(DCS_SDeadMemBody) + szc; 69 | if (sz > SEMETERY_HEAP_SIZE) 70 | return; 71 | 72 | if (DCS_semetery_cnt >= SEMETERY_SIZE) { 73 | DCS_remove_first(); 74 | } 75 | 76 | while ((DCS_semetery_heap_size + sz) > SEMETERY_HEAP_SIZE) { 77 | DCS_remove_first(); 78 | } 79 | 80 | DCS_semetery[DCS_semetery_cnt].id = DCS_get_id(); 81 | DCS_semetery[DCS_semetery_cnt].ptr_was = this; 82 | DCS_semetery[DCS_semetery_cnt].size = sz; 83 | 84 | DCS_SDeadMemBody body; 85 | body.id = DCS_semetery[DCS_semetery_cnt].id; 86 | body.size = sz; 87 | 88 | memcpy(DCS_semetery_heap + DCS_semetery_heap_size, &body, sizeof(DCS_SDeadMemBody)); 89 | memcpy(DCS_semetery_heap + DCS_semetery_heap_size + sizeof(DCS_SDeadMemBody), this, sz - sizeof(DCS_SDeadMemBody)); 90 | DCS_semetery_heap_size += sz; 91 | ++DCS_semetery_cnt; 92 | } 93 | CMain *CMain::DCS_GetDeadBody(void) const { 94 | for (int i = 0; i < DCS_semetery_cnt; ++i) { 95 | if (DCS_semetery[i].ptr_was == this) { 96 | BYTE *ptr; 97 | int sz = DCS_find_by_id(DCS_semetery[i].id, &ptr); 98 | return (CMain *)(ptr + sizeof(DCS_SDeadMemBody)); 99 | } 100 | } 101 | 102 | return NULL; 103 | } 104 | void CMain::DCS_Reincarnation(void) const { 105 | for (int i = 0; i < DCS_semetery_cnt; ++i) { 106 | if (DCS_semetery[i].ptr_was == this) { 107 | int id = DCS_semetery[i].id; 108 | DCS_remove_by_id(id); 109 | 110 | memcpy(DCS_semetery + i, DCS_semetery + i + 1, (DCS_semetery_cnt - i - 1) * sizeof(DCS_SDeadMem)); 111 | --DCS_semetery_cnt; 112 | return; 113 | } 114 | } 115 | } 116 | #endif 117 | 118 | void CMain::BaseInit(void) { 119 | CFile::StaticInit(); 120 | 121 | #ifndef MAXEXP_EXPORTS 122 | SRemindCore::StaticInit(); 123 | #endif 124 | 125 | #ifdef MEM_SPY_ENABLE 126 | CHeap::StaticInit(); 127 | #endif 128 | #ifdef _DEBUG 129 | CDText::StaticInit(); 130 | #endif 131 | #if defined _DEBUG || defined _TRACE 132 | CDebugTracer::StaticInit(); 133 | #endif 134 | } 135 | 136 | void CMain::BaseDeInit(void) { 137 | #ifdef MEM_SPY_ENABLE 138 | CHeap::StaticDeInit(); 139 | #endif 140 | } 141 | 142 | } // namespace Base 143 | -------------------------------------------------------------------------------- /MatrixLib/Base/CMain.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "BaseDef.hpp" 9 | 10 | #ifdef _DEBUG 11 | //#define DEAD_CLASS_SPY_ENABLE 12 | #endif 13 | 14 | namespace Base { 15 | 16 | class BASE_API CMain { 17 | public: 18 | CMain() {} 19 | ~CMain() {} 20 | 21 | #ifdef DEAD_CLASS_SPY_ENABLE 22 | // virtual int DCS_UnderSpy(void) const {return 0;} 23 | void DCS_ClassDead(int sz) const; 24 | CMain *DCS_GetDeadBody(void) const; 25 | void DCS_Reincarnation(void) const; 26 | 27 | #define DCS_INCONSTRUCTOR() \ 28 | { DCS_Reincarnation(); } 29 | #define DCS_INDESTRUCTOR() \ 30 | { \ 31 | int sz = DCS_UnderSpy(); \ 32 | if (sz > 0) { \ 33 | DCS_ClassDead(sz); \ 34 | } \ 35 | } 36 | 37 | #else 38 | #define DCS_INCONSTRUCTOR() 39 | #define DCS_INDESTRUCTOR() 40 | #endif 41 | 42 | static void BaseInit(void); 43 | static void BaseDeInit(void); 44 | }; 45 | 46 | } // namespace Base 47 | -------------------------------------------------------------------------------- /MatrixLib/Base/CRC32.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "BaseDef.hpp" 9 | 10 | namespace Base { 11 | 12 | dword CalcCRC32(const void *buf, int len); 13 | dword CalcCRC32_Begin(const void *buf, int len); 14 | dword CalcCRC32_Buf(dword crc, const void *buf, int len); 15 | dword CalcCRC32_End(dword crc); 16 | 17 | } // namespace Base 18 | -------------------------------------------------------------------------------- /MatrixLib/Base/Mem.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | inline void memcopy_back_dword(void *tgt, const void *src, 11 | uint32_t size) // same as blk_copy, but copying by sizeof(uint) bytes 12 | { 13 | uint32_t *uitgt = ((uint32_t *)tgt) + size - 1; 14 | const uint32_t *uisrc = ((const uint32_t *)src) + size - 1; 15 | while (size) { 16 | *uitgt-- = *uisrc--; 17 | size--; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /MatrixLib/Base/Registry.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "BaseDef.hpp" 9 | 10 | #include 11 | #include 12 | 13 | namespace Base { 14 | 15 | void Reg_GetString(HKEY pkey, const wchar_t *path, const wchar_t *name, const std::wstring &str); 16 | std::wstring Reg_GetString(HKEY pkey, const wchar_t *path, const wchar_t *name, const wchar_t *defaultstr); 17 | void Reg_SetString(HKEY pkey, const wchar_t *path, const wchar_t *name, const wchar_t *str); 18 | 19 | } // namespace Base 20 | -------------------------------------------------------------------------------- /MatrixLib/Base/fps_counter.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template 5 | class fps_counter 6 | { 7 | public: 8 | using clock = std::chrono::high_resolution_clock; 9 | 10 | void operator ++ (int) 11 | { 12 | clock::time_point tp = clock::now(); 13 | 14 | if (_full) 15 | { 16 | ++_left %= _size; 17 | } 18 | 19 | while (_left != _right && _values[_left] < tp - period) 20 | { 21 | ++_left %= _size; 22 | _full = false; 23 | } 24 | 25 | _values[_right] = tp; 26 | 27 | ++_right %= _size; 28 | 29 | _full = _right == _left; 30 | } 31 | 32 | size_t count() 33 | { 34 | std::make_signed_t fps = _right - _left + _full * _size; 35 | return (fps >= 0) ? fps : _size + fps; 36 | } 37 | 38 | void clear() 39 | { 40 | _left = _right = 0; 41 | } 42 | 43 | private: 44 | static constexpr clock::duration period = std::chrono::seconds(1); 45 | 46 | std::array _values; 47 | size_t _left{0}; 48 | size_t _right{0}; 49 | bool _full{false}; 50 | }; -------------------------------------------------------------------------------- /MatrixLib/Base/preallocated_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class preallocated_list 7 | { 8 | struct node 9 | { 10 | const Item* value; 11 | size_t next = SIZE_MAX; // SIZE_MAX (-1) means "no next" 12 | }; 13 | 14 | std::vector pool; 15 | size_t head = SIZE_MAX; 16 | size_t tail = SIZE_MAX; 17 | 18 | public: 19 | class iterator { 20 | friend class preallocated_list; 21 | 22 | const preallocated_list* list; 23 | size_t current; 24 | 25 | public: 26 | // all the usings are here to make std::find_if happy 27 | using iterator_category = std::forward_iterator_tag; 28 | using value_type = Item; 29 | using difference_type = std::ptrdiff_t; 30 | using pointer = const Item*; 31 | using reference = const Item&; 32 | 33 | iterator(const preallocated_list* list, size_t start) 34 | : list(list), current(start) 35 | { 36 | } 37 | 38 | const Item* operator*() const 39 | { 40 | return list->pool[current].value; 41 | } 42 | 43 | iterator& operator++() 44 | { 45 | current = list->pool[current].next; 46 | return *this; 47 | } 48 | 49 | const iterator next() const 50 | { 51 | return {list, list->pool[current].next}; 52 | } 53 | 54 | bool operator == (const iterator& that) const 55 | { 56 | return this->list == that.list && this->current == that.current; 57 | } 58 | 59 | bool operator != (const iterator& that) const 60 | { 61 | return !(*this == that); 62 | } 63 | 64 | operator bool () const 65 | { 66 | return current != SIZE_MAX; 67 | } 68 | }; 69 | 70 | iterator begin() const { return iterator(this, head); } 71 | iterator end() const { return iterator(this, SIZE_MAX); } 72 | 73 | bool insert(iterator it, const Item* value) 74 | { 75 | size_t index = allocate_node(value); 76 | 77 | if (!it) // insert at head if iterator is invalid 78 | { 79 | pool[index].next = head; 80 | head = index; 81 | if (tail == SIZE_MAX) tail = head; 82 | return true; 83 | } 84 | 85 | // insert after the iterator's current position 86 | pool[index].next = pool[it.current].next; 87 | pool[it.current].next = index; 88 | 89 | if (pool[index].next == SIZE_MAX) 90 | { 91 | tail = index; // Update tail if inserted at end 92 | } 93 | 94 | return true; 95 | } 96 | 97 | bool empty() const 98 | { 99 | return head == SIZE_MAX; 100 | } 101 | 102 | void clear() 103 | { 104 | pool.clear(); 105 | head = tail = SIZE_MAX; 106 | } 107 | 108 | size_t size() const 109 | { 110 | return pool.size(); 111 | } 112 | 113 | private: 114 | size_t allocate_node(const Item* item) 115 | { 116 | pool.push_back({item, SIZE_MAX}); 117 | return pool.size() - 1; 118 | } 119 | }; -------------------------------------------------------------------------------- /MatrixLib/Base/random.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace random 4 | { 5 | 6 | void seed(unsigned int val) 7 | { 8 | srand(val); 9 | } 10 | 11 | int Rnd() 12 | { 13 | return rand(); 14 | } 15 | 16 | double RndFloat() 17 | { 18 | return float(Rnd()) / float(2147483647 - 2); 19 | } 20 | 21 | int Rnd(int zmin, int zmax) 22 | { 23 | if (zmin <= zmax) 24 | return zmin + (Rnd() % (zmax - zmin + 1)); 25 | else 26 | return zmax + (Rnd() % (zmin - zmax + 1)); 27 | } 28 | 29 | double RndFloat(double zmin, double zmax) 30 | { 31 | return zmin + RndFloat() * (zmax - zmin); 32 | } 33 | 34 | } // namespace random 35 | 36 | double RND(int from, int to) 37 | { 38 | return ((double)random::Rnd() * (1.0 / (RAND_MAX)) * (fabs(double((to) - (from)))) + (from)); 39 | } 40 | 41 | float FRND(int x) 42 | { 43 | return ((float)(RND(0, (x)))); 44 | } 45 | 46 | float FSRND(int x) 47 | { 48 | return (FRND(2.0f * (x)) - float(x)); 49 | } 50 | 51 | int IRND(int n) 52 | { 53 | return static_cast(std::round(RND(0, double(n) - 0.55))); 54 | } -------------------------------------------------------------------------------- /MatrixLib/Base/random.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace random 4 | { 5 | 6 | void seed(unsigned int val); 7 | 8 | int Rnd(); 9 | double RndFloat(); 10 | int Rnd(int zmin, int zmax); 11 | double RndFloat(double zmin, double zmax); 12 | 13 | } // namespace random 14 | 15 | double RND(int from, int to); 16 | float FRND(int x); 17 | float FSRND(int x); 18 | int IRND(int n); -------------------------------------------------------------------------------- /MatrixLib/Base/utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace utils { 11 | 12 | template 13 | inline std::string format(const char* format, Args... args) 14 | { 15 | // TODO: replace with std::format/fmt::format 16 | char buf[10240]; 17 | if (std::snprintf(buf, sizeof(buf), format, args...) < 0) 18 | { 19 | throw std::runtime_error("snprintf() failed"); 20 | } 21 | return std::string{buf}; 22 | } 23 | 24 | template 25 | inline std::wstring format(const wchar_t* format, Args... args) 26 | { 27 | // TODO: replace with std::format/fmt::format 28 | wchar_t buf[10240]; 29 | if (std::swprintf(buf, sizeof(buf), format, args...) < 0) 30 | { 31 | throw std::runtime_error("swprintf() failed"); 32 | } 33 | return std::wstring{buf}; 34 | } 35 | 36 | inline std::string from_wstring(std::wstring_view wstr) 37 | { 38 | std::wstring_convert> converter; 39 | return converter.to_bytes(std::wstring{wstr}); 40 | } 41 | 42 | inline std::wstring to_wstring(std::string_view str) 43 | { 44 | std::wstring_convert> converter; 45 | return converter.from_bytes(std::string{str}); 46 | } 47 | 48 | // TODO: replace with string::starts_with from C++20 49 | inline bool starts_with(const std::wstring& src, const std::wstring& sub) 50 | { 51 | return (src.find(sub) == 0); 52 | } 53 | 54 | inline void to_lower(std::wstring& str, size_t offset = 0) 55 | { 56 | for (size_t i = offset; i < str.length(); ++i) 57 | { 58 | str[i] = towlower(str[i]); 59 | } 60 | } 61 | 62 | inline std::wstring trim(const std::wstring& str) 63 | { 64 | std::wstring tmp{str}; 65 | tmp.erase(0, tmp.find_first_not_of(L" \t\r\n")); 66 | tmp.erase(tmp.find_last_not_of(L" \t\r\n") + 1); 67 | return tmp; 68 | } 69 | 70 | inline std::wstring& replace(std::wstring& str, const std::wstring& from, const std::wstring& to) 71 | { 72 | size_t tlen = str.length(); 73 | if (tlen < 1 || tlen < from.length()) 74 | { 75 | return str; 76 | } 77 | 78 | size_t offset = 0; 79 | while (true) 80 | { 81 | offset = str.find(from, offset); 82 | if (offset == std::wstring::npos) 83 | { 84 | break; 85 | } 86 | str.replace(offset, from.length(), to); 87 | offset += to.length(); 88 | } 89 | 90 | return str; 91 | } 92 | 93 | } // namespace utils -------------------------------------------------------------------------------- /MatrixLib/Bitmap/CBitmap.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include "BaseDef.hpp" 9 | #include "CBuf.hpp" 10 | 11 | #include 12 | #include 13 | 14 | class CBitmap 15 | { 16 | private: 17 | Base::CPoint m_Pos; // Смещение изображения 18 | Base::CPoint m_Size; // Размер изображения 19 | 20 | int m_Format; // BMF_* 21 | int m_BytePP; // Байт на пиксель 22 | int m_BitPP; // Бит на пиксель 23 | uint32_t m_MColor[4]; // Маска для каждой компоненты цвета 24 | 25 | void *m_Data; // Изображение 26 | int m_Pitch; // Байт на одну строку 27 | bool m_DataExt; // True - внешние данные 28 | 29 | void *m_AddData[4]; // Дополнительные данные к изображению 30 | bool m_AddDataExt[4]; // True - Дополнительные данные во внешнем буфере 31 | int m_AddDataVal[4]; // 32 | 33 | public: 34 | CBitmap(); 35 | ~CBitmap(); 36 | 37 | int Format() const { return m_Format; } 38 | int SizeX() const { return m_Size.x; } 39 | int SizeY() const { return m_Size.y; } 40 | const Base::CPoint &Size() const { return m_Size; } 41 | int BytePP() const { return m_BytePP; } 42 | int BitPP() { return m_BitPP; } 43 | uint8_t* Data() const { return (uint8_t*)m_Data; } 44 | int Pitch() const { return m_Pitch; } 45 | uint32_t ColorMask(int index) const { return m_MColor[index]; } 46 | 47 | void CreateRGB(int lenx, int leny); 48 | void CreateRGBA(int lenx, int leny, int pitch = 0, void* data = nullptr); 49 | 50 | void Copy(const Base::CPoint &pdes, const Base::CPoint &size, const CBitmap &bmsou, const Base::CPoint &spsou); 51 | 52 | void Tile(const Base::CPoint &pdes, const Base::CPoint &desize, const CBitmap &bmsou, const Base::CPoint &spsou, 53 | const Base::CPoint &szsou); 54 | 55 | void Fill(const Base::CPoint &pdes, const Base::CPoint &size, uint32_t color); 56 | 57 | void Make2xSmaller(); 58 | void Make2xSmaller(const Base::CPoint &left_up_corner, const Base::CPoint &size, CBitmap &des_bitmap) const; 59 | 60 | void MergeByMask(const Base::CPoint &pdes, const Base::CPoint &size, const CBitmap &bm1, const Base::CPoint &sp1, 61 | const CBitmap &bm2, const Base::CPoint &sp2, const CBitmap &mask, const Base::CPoint &spm); 62 | void SwapByte(const Base::CPoint &pos, const Base::CPoint &size, int n1, int n2); 63 | 64 | void MergeWithAlpha(const Base::CPoint &pdes, const Base::CPoint &size, const CBitmap &bmsou, 65 | const Base::CPoint &spsou); 66 | 67 | void SaveInBMP(const std::wstring_view filename) const; 68 | void SaveInDDSUncompressed(Base::CBuf &buf) const; 69 | bool SaveInPNG(const std::wstring_view filename); 70 | bool LoadFromPNG(const std::wstring_view filename); 71 | bool LoadFromPNG(void *buf, int buflen); 72 | 73 | protected: 74 | void FlipY(); 75 | void Create16(int lenx, int leny); 76 | 77 | private: 78 | void Clear(); 79 | void AllocData(); 80 | void CreatePalate(int lenx, int leny, int palcnt); 81 | void CreateGrayscale(int lenx, int leny); 82 | 83 | void SaveInBMP(Base::CBuf &buf) const; 84 | bool SaveInPNG(Base::CBuf &buf); 85 | int SaveInPNG(void *buf, int buflen); 86 | }; 87 | 88 | class WinBitmap : public CBitmap 89 | { 90 | public: 91 | WinBitmap() = default; 92 | 93 | ~WinBitmap() 94 | { 95 | Clear(); 96 | } 97 | void Clear(); 98 | void Init(); 99 | void Save(bool save16as32 = false); 100 | HBITMAP GetHandle() { return m_handle; } 101 | HDC GetDC() { return m_dc; } 102 | void SetHandle(HBITMAP bm) { m_handle = bm; } 103 | void SetDC(HDC hdc) { m_dc = hdc; } 104 | 105 | private: 106 | HBITMAP m_handle{nullptr}; // Windows-кий bitmap 107 | HDC m_dc{nullptr}; // Context windows-кого bitmap-а 108 | }; -------------------------------------------------------------------------------- /MatrixLib/Bitmap/FilePNG.hpp: -------------------------------------------------------------------------------- 1 | // MatrixGame - SR2 Planetary battles engine 2 | // Copyright (C) 2012, Elemental Games, Katauri Interactive, CHK-Games 3 | // Licensed under GPLv2 or any later version 4 | // Refer to the LICENSE file included 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace FilePNG 11 | { 12 | 13 | // format: 1-gray 2-rgb 3-rgba 4-palate 14 | uintptr_t ReadStart_Buf(void *soubuf, uint32_t soubuflen, uint32_t *lenx, uint32_t *leny, uint32_t *countcolor, uint32_t *format); 15 | uint32_t Read(uintptr_t id, void *buf, uint32_t lenline, uint32_t *arraycolor); 16 | 17 | // Возвращает полный размер файла. Если больше bufoutlen то нужно вызвать повторно. При ошибке 0 18 | int Write(void *bufout, int bufoutlen, void *buf, uint32_t ll, uint32_t lx, uint32_t ly, uint32_t bytepp, 19 | int rgb_to_bgr); 20 | 21 | } // namespace FilePNG -------------------------------------------------------------------------------- /MatrixLib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(MatrixLib STATIC) 2 | 3 | set(3G_SOURCES 4 | 3G/3g.cpp 5 | 3G/Cache.cpp 6 | 3G/CBillboard.cpp 7 | 3G/DeviceState.cpp 8 | 3G/Form.cpp 9 | 3G/Helper.cpp 10 | 3G/Math3D.cpp 11 | 3G/ShadowProj.cpp 12 | 3G/ShadowStencil.cpp 13 | 3G/Texture.cpp 14 | 3G/VectorObject.cpp 15 | ) 16 | set(3G_HEADERS 17 | 3G/3g.hpp 18 | 3G/BigIB.hpp 19 | 3G/BigVB.hpp 20 | 3G/Cache.hpp 21 | 3G/CBillboard.hpp 22 | 3G/D3DControl.hpp 23 | 3G/DeviceState.hpp 24 | 3G/Form.hpp 25 | 3G/Helper.hpp 26 | 3G/Math3D.hpp 27 | 3G/ShadowProj.hpp 28 | 3G/ShadowStencil.hpp 29 | 3G/Texture.hpp 30 | 3G/VectorObject.hpp 31 | ) 32 | 33 | set(BASE_SOURCES 34 | Base/CBlockPar.cpp 35 | Base/CBuf.cpp 36 | Base/CException.cpp 37 | Base/CFile.cpp 38 | Base/CHeap.cpp 39 | Base/CMain.cpp 40 | Base/CRC32.cpp 41 | Base/CReminder.cpp 42 | Base/CStorage.cpp 43 | Base/Pack.cpp 44 | Base/Registry.cpp 45 | Base/Tracer.cpp 46 | Base/random.cpp 47 | ) 48 | set(BASE_HEADERS 49 | Base/BaseDef.hpp 50 | Base/CBlockPar.hpp 51 | Base/CBuf.hpp 52 | Base/CException.hpp 53 | Base/CFile.hpp 54 | Base/CHeap.hpp 55 | Base/CMain.hpp 56 | Base/CRC32.hpp 57 | Base/CReminder.hpp 58 | Base/CStorage.hpp 59 | Base/Mem.hpp 60 | Base/Pack.hpp 61 | Base/Registry.hpp 62 | Base/Tracer.hpp 63 | ) 64 | 65 | set(BITMAP_SOURCES 66 | Bitmap/CBitmap.cpp 67 | Bitmap/FilePNG.cpp 68 | ) 69 | set(BITMAP_HEADERS 70 | Bitmap/CBitmap.hpp 71 | Bitmap/FilePNG.hpp 72 | ) 73 | 74 | # TODO: remove unused files and replace set with globs 75 | # file(GLOB 3G_SOURCES 3G/*.cpp) 76 | # file(GLOB 3G_HEADERS 3G/*.hpp 3G/*.pch) 77 | 78 | # file(GLOB BASE_SOURCES Base/*.cpp) 79 | # file(GLOB BASE_HEADERS Base/*.hpp Base/*.pch) 80 | 81 | # file(GLOB BITMAP_SOURCES Bitmap/*.cpp) 82 | # file(GLOB BITMAP_HEADERS Bitmap/*.hpp Bitmap/*.pch) 83 | 84 | target_sources( 85 | MatrixLib 86 | PRIVATE 87 | ${3G_SOURCES} ${3G_HEADERS} 88 | ${BASE_SOURCES} ${BASE_HEADERS} 89 | ${BITMAP_SOURCES} ${BITMAP_HEADERS} 90 | ) 91 | 92 | target_include_directories( 93 | MatrixLib 94 | PUBLIC 95 | 3G 96 | Base 97 | Bitmap 98 | ) 99 | 100 | target_link_libraries( 101 | MatrixLib 102 | PUBLIC 103 | LIBPNG 104 | ${DIRECTX9_LIBRARIES} 105 | ) 106 | 107 | if(MSVC) 108 | source_group("3G\\Source Files" FILES ${3G_SOURCES}) 109 | source_group("3G\\Header Files" FILES ${3G_HEADERS}) 110 | source_group("Base\\Source Files" FILES ${BASE_SOURCES}) 111 | source_group("Base\\Header Files" FILES ${BASE_HEADERS}) 112 | source_group("Bitmap\\Source Files" FILES ${BITMAP_SOURCES}) 113 | source_group("Bitmap\\Header Files" FILES ${BITMAP_HEADERS}) 114 | else() 115 | list(APPEND COMPILE_DEFINITIONS $<$:_DEBUG>) 116 | endif() 117 | 118 | target_compile_options(MatrixLib PRIVATE ${COMPILE_OPTIONS}) 119 | target_compile_definitions(MatrixLib PRIVATE ${COMPILE_DEFINITIONS} _ALLOW_RTCc_IN_STL) 120 | target_link_options(MatrixLib PUBLIC "$<$:-SAFESEH:NO>") -------------------------------------------------------------------------------- /ThirdParty/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | cmake_policy(SET CMP0097 NEW) # skip updating submodules 4 | 5 | # Only define TOOLCHAIN_ARGS if CMAKE_TOOLCHAIN_FILE is set. Needed for linux cross compilation. 6 | if(DEFINED CMAKE_TOOLCHAIN_FILE) 7 | set(TOOLCHAIN_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_POLICY_VERSION_MINIMUM=3.5") 8 | else() 9 | set(TOOLCHAIN_ARGS "") 10 | endif() 11 | 12 | ExternalProject_Add(zlib-external 13 | GIT_REPOSITORY https://github.com/madler/zlib 14 | GIT_TAG v1.2.11 15 | GIT_SUBMODULES "" 16 | UPDATE_DISCONNECTED false 17 | PREFIX zlib 18 | CMAKE_ARGS 19 | ${TOOLCHAIN_ARGS} 20 | -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/zlib 21 | -DBUILD_SHARED_LIBS=False 22 | INSTALL_COMMAND 23 | ${CMAKE_COMMAND} 24 | --build . 25 | --target install 26 | --config Release 27 | ) 28 | 29 | add_library(ZLIB INTERFACE) 30 | target_include_directories(ZLIB INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/zlib/include) 31 | target_link_directories(ZLIB INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/zlib/lib) 32 | target_link_libraries(ZLIB INTERFACE zlibstatic) 33 | add_dependencies(ZLIB zlib-external) 34 | 35 | if(MSVC) 36 | set(ZLIB_STATIC_FILENAME zlibstatic.lib) 37 | else() 38 | set(ZLIB_STATIC_FILENAME libzlibstatic.a) 39 | endif() 40 | 41 | #=============================================================================== 42 | 43 | ExternalProject_Add(libpng-external 44 | GIT_REPOSITORY https://github.com/glennrp/libpng 45 | GIT_TAG v1.6.37 46 | GIT_SUBMODULES "" 47 | UPDATE_DISCONNECTED false 48 | PREFIX libpng 49 | DEPENDS zlib-external 50 | CMAKE_ARGS 51 | ${TOOLCHAIN_ARGS} 52 | -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/libpng 53 | -DPNG_SHARED=Off # don't build shared libs 54 | -DPNG_TESTS=Off # don't build tests 55 | -DPNG_BUILD_ZLIB=Off # use custom zlib 56 | -DZLIB_INCLUDE_DIR=${CMAKE_CURRENT_BINARY_DIR}/zlib/include 57 | -DZLIB_LIBRARY=${CMAKE_CURRENT_BINARY_DIR}/zlib/lib/${ZLIB_STATIC_FILENAME} 58 | INSTALL_COMMAND 59 | ${CMAKE_COMMAND} 60 | --build . 61 | --target install 62 | --config Release 63 | ) 64 | 65 | add_library(LIBPNG INTERFACE) 66 | target_include_directories(LIBPNG INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libpng/include) 67 | target_link_directories(LIBPNG INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/libpng/lib) 68 | if(MSVC) 69 | target_link_libraries(LIBPNG INTERFACE libpng16_static ZLIB) 70 | else() 71 | target_link_libraries(LIBPNG INTERFACE png ZLIB) 72 | endif() 73 | add_dependencies(LIBPNG libpng-external) 74 | -------------------------------------------------------------------------------- /cmake/FindDIRECTX9.cmake: -------------------------------------------------------------------------------- 1 | # - Find DirectX SDK installation 2 | # Find the DirectX 9 includes and library 3 | # This module defines 4 | # DIRECTX9_INCLUDE_DIRS, where to find d3d9.h, etc. 5 | # DIRECTX9_LIBRARIES, libraries to link against to use DirectX. 6 | # DIRECTX9_FOUND, If false, do not try to use DirectX. 7 | # DIRECTX9_ROOT_DIR, directory where DirectX was installed. 8 | 9 | # SDK download link: 10 | # https://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe 11 | 12 | if(MSVC) 13 | set(DIRECTX9_INCLUDE_PATHS 14 | "$ENV{DXSDK_DIR}/Include" 15 | "$ENV{DIRECTX_ROOT}/Include" 16 | "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Include" 17 | "C:/Program Files/Microsoft DirectX SDK (June 2010)/Include" 18 | ) 19 | find_path(DIRECTX9_INCLUDE_DIRS d3dx9.h ${DIRECTX9_INCLUDE_PATHS} NO_DEFAULT_PATH) 20 | 21 | get_filename_component(DIRECTX9_ROOT_DIR "${DIRECTX9_INCLUDE_DIRS}/.." ABSOLUTE) 22 | 23 | set(DIRECTX9_LIBRARY_PATHS "${DIRECTX9_ROOT_DIR}/Lib/x86" "${DIRECTX9_ROOT_DIR}/Lib") 24 | 25 | find_library(DIRECTX9_D3D9_LIBRARY d3d9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH) 26 | find_library(DIRECTX9_D3DX9_LIBRARY d3dx9 ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH) 27 | find_library(DIRECTX9_DXERR_LIBRARY DxErr ${DIRECTX9_LIBRARY_PATHS} NO_DEFAULT_PATH) 28 | set(DIRECTX9_LIBRARIES ${DIRECTX9_D3D9_LIBRARY} ${DIRECTX9_D3DX9_LIBRARY} ${DIRECTX9_DXERR_LIBRARY}) 29 | 30 | # handle the QUIETLY and REQUIRED arguments and set DIRECTX9_FOUND to TRUE if all listed variables are TRUE 31 | include(FindPackageHandleStandardArgs) 32 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(DIRECTX9 DEFAULT_MSG DIRECTX9_ROOT_DIR DIRECTX9_LIBRARIES DIRECTX9_INCLUDE_DIRS) 33 | mark_as_advanced(DIRECTX9_INCLUDE_DIRS DIRECTX9_D3D9_LIBRARY DIRECTX9_D3DX9_LIBRARY DIRECTX9_DXERR_LIBRARY) 34 | else() 35 | message(STATUS "Skipping DirectX SDK search as the used compiler does not require it") 36 | set(DIRECTX9_LIBRARIES d3d9 d3dx9 dxerr9 d3dcompiler) 37 | endif() 38 | -------------------------------------------------------------------------------- /cmake/ToolClangFormat.cmake: -------------------------------------------------------------------------------- 1 | # Additional targets to perform clang-format 2 | # Get all project files 3 | file(GLOB_RECURSE 4 | ALL_CXX_SOURCE_FILES 5 | *.[chi]pp *.[chi]xx *.cc *.hh *.ii *.[CHI] 6 | ) 7 | 8 | # Adding clang-format target if executable is found 9 | find_program(CLANG_FORMAT "clang-format") 10 | if(CLANG_FORMAT) 11 | add_custom_target( 12 | clang-format 13 | COMMAND ${CLANG_FORMAT} 14 | -i 15 | -style=file 16 | ${ALL_CXX_SOURCE_FILES} 17 | ) 18 | endif() -------------------------------------------------------------------------------- /cmake/linux-toolchain.cmake: -------------------------------------------------------------------------------- 1 | # Cross-compiling to Windows: 2 | set(CMAKE_SYSTEM_NAME Windows) 3 | set(CMAKE_SYSTEM_VERSION 1) 4 | 5 | # i686 for 32-bit 6 | set(CMAKE_SYSTEM_PROCESSOR i686) 7 | 8 | # MinGW-w64 cross-compilers: 9 | set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) 10 | set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) 11 | 12 | set(CMAKE_AR i686-w64-mingw32-ar CACHE FILEPATH "" FORCE) 13 | set(CMAKE_RANLIB i686-w64-mingw32-ranlib CACHE FILEPATH "" FORCE) 14 | 15 | # DirectX 9 library should be present here: 16 | set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) 17 | 18 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # host programs (like cmake-run) stay on Linux 19 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # libraries ONLY from the Windows sysroot 20 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # headers ONLY from the Windows sysroot 21 | -------------------------------------------------------------------------------- /docs/CROSS_COMPILATION.md: -------------------------------------------------------------------------------- 1 | # Cross-compiling MatrixGame on Linux 2 | 3 | You can cross-compile the game on Linux for Windows and then launch it using wine! 4 | 5 | You can also debug it! 6 | 7 | The problems are: 8 | - There is no text in the game (if you run standalone game on Linux). 9 | - There is no pretty prints inside debugger (you would need to compile the gdb with python enabled). 10 | 11 | ### Install dependencies 12 | 13 | - Arch Linux: `sudo pacman -S cmake ninja` 14 | 15 | ### Install cross-compiler 16 | 17 | There is a linux compiler which can target Windows, install it: 18 | 19 | - Arch Linux: `sudo pacman -S mingw-w64-gcc mingw-w64-headers mingw-w64-winpthreads mingw-w64-binutils mingw-w64-crt` 20 | 21 | ### Configure CMake project 22 | 23 | Specify the toolchain file when configuring: 24 | 25 | `cmake -B build -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="cmake/linux-toolchain.cmake"` 26 | 27 | If you are using GUI cmake click "custom toolchain file" and choose `cmake/linux-toolchain.cmake` 28 | 29 | ### Building 30 | 31 | `cmake --build build` 32 | 33 | Or if you are using CLion IDE you can open the `./build` directory as project and then you'll be able to build/run by pressing "Build/Run/Debug". The IDE will take care of running the game using `wine` under the hood. 34 | 35 | ### Running 36 | 37 | If you don't have the CLion IDE you can run the game with 38 | 39 | `wine MatrixGame.exe` 40 | 41 | You may be required to bring some libraries to to directory with the game: 42 | - `libgcc_s_dw2-1.dll` 43 | - `libstdc++-6.dll` 44 | - `libwinpthread-1.dll` 45 | 46 | If it is the case you can copy them from `/usr/i686-w64-mingw32/bin/`. 47 | 48 | ## Debugging on linux 49 | 50 | It's not easy but possible! 51 | 52 | Since the game can only be built for Windows it can only be run under `wine` on Linux. 53 | 54 | Therefore, there are 2 ways to debug: 55 | 56 | - Run PE (.exe) windows debugger(gdb) under `wine` alongside the game (which is also run under `wine`). 57 | - Using an ELF linux cross-debugger(runs on Linux, understands only Windows) and then run the game using `gdb-server.exe` under `wine` and try to connect. (**untested**) 58 | 59 | The only way I tested (and it worked) was to use `/usr/i686-w64-mingw32/bin/gdb.exe` as the debugger of choice in CLion IDE. 60 | 61 | ### Download Windows debugger 62 | 63 | - Arch linux: `yay -S mingw-w64-gdb` 64 | 65 | Select the `/usr/i686-w64-mingw32/bin/gdb.exe` as the debugger of choice inside CLion. 66 | 67 | Set up a breakpoint inside IDE and press "Debug". 68 | 69 | The only problem is that the `gdb.exe` which comes from `mingw-w64-gdb` package on AUR was built without python support so it lacks good display of std templates, such as `std::wstring`. 70 | 71 | If you want good printing you would need to compile the debugger yourself with python enabled option! -------------------------------------------------------------------------------- /docs/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vladislavrv/MatrixGame/218115a72fa9c5d43269f4ca84a8596a0bcb82f1/docs/image.png --------------------------------------------------------------------------------