├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── media └── banner.png ├── src ├── cleanup.bat └── sdhlt │ ├── Makefile │ ├── common │ ├── TimeCounter.h │ ├── anorms.h │ ├── blockmem.cpp │ ├── blockmem.h │ ├── boundingbox.h │ ├── bspfile.cpp │ ├── bspfile.h │ ├── cmdlib.cpp │ ├── cmdlib.h │ ├── cmdlinecfg.cpp │ ├── cmdlinecfg.h │ ├── filelib.cpp │ ├── filelib.h │ ├── hlassert.h │ ├── log.cpp │ ├── log.h │ ├── mathlib.cpp │ ├── mathlib.h │ ├── mathtypes.h │ ├── messages.cpp │ ├── messages.h │ ├── resourcelock.cpp │ ├── resourcelock.h │ ├── scriplib.cpp │ ├── scriplib.h │ ├── stringlib.h │ ├── studio.h │ ├── threads.cpp │ ├── threads.h │ ├── win32fix.h │ ├── winding.cpp │ └── winding.h │ ├── sdHLBSP │ ├── brink.cpp │ ├── bsp5.h │ ├── merge.cpp │ ├── outside.cpp │ ├── portals.cpp │ ├── qbsp.cpp │ ├── sdHLBSP.vcproj │ ├── sdHLBSP.vcxproj │ ├── sdHLBSP.vcxproj.filters │ ├── solidbsp.cpp │ ├── surfaces.cpp │ ├── tjunc.cpp │ └── writebsp.cpp │ ├── sdHLCSG │ ├── ansitoutf8.cpp │ ├── brush.cpp │ ├── brushunion.cpp │ ├── csg.h │ ├── hullfile.cpp │ ├── map.cpp │ ├── netvis_in_vis.cpp │ ├── properties.cpp │ ├── qcsg.cpp │ ├── sdHLCSG.vcproj │ ├── sdHLCSG.vcxproj │ ├── sdHLCSG.vcxproj.filters │ ├── textures.cpp │ ├── wadcfg.cpp │ ├── wadpath.cpp │ └── wadpath.h │ ├── sdHLRAD │ ├── compress.cpp │ ├── compress.h │ ├── lerp.cpp │ ├── lightmap.cpp │ ├── list.h │ ├── loadtextures.cpp │ ├── mathutil.cpp │ ├── meshdesc.cpp │ ├── meshdesc.h │ ├── meshtrace.cpp │ ├── meshtrace.h │ ├── nomatrix.cpp │ ├── progmesh.cpp │ ├── qrad.cpp │ ├── qrad.h │ ├── qradutil.cpp │ ├── sdHLRAD.vcproj │ ├── sdHLRAD.vcxproj │ ├── sdHLRAD.vcxproj.filters │ ├── sparse.cpp │ ├── stringlib.cpp │ ├── studio.cpp │ ├── trace.cpp │ ├── transfers.cpp │ ├── transparency.cpp │ ├── vismatrix.cpp │ └── vismatrixutil.cpp │ ├── sdHLVIS │ ├── flow.cpp │ ├── sdHLVIS.vcproj │ ├── sdHLVIS.vcxproj │ ├── sdHLVIS.vcxproj.filters │ ├── vis.cpp │ ├── vis.h │ ├── zones.cpp │ └── zones.h │ ├── sdRIPENT │ ├── ripent.cpp │ ├── ripent.h │ ├── sdRIPENT.vcproj │ ├── sdRIPENT.vcxproj │ └── sdRIPENT.vcxproj.filters │ ├── sdhlt.sln │ └── template │ ├── BaseMath.h │ ├── EndianMath.h │ ├── ReferenceArray.h │ ├── ReferenceCounter.h │ ├── ReferenceObject.h │ ├── ReferencePtr.h │ └── basictypes.h └── tools ├── lights.rad ├── sdhlt.fgd ├── sdhlt.wad ├── settings.txt └── wad.cfg /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. 2 | # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml 3 | name: CMake on multiple platforms 4 | 5 | on: 6 | push: 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ${{ matrix.os }} 12 | 13 | strategy: 14 | # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. 15 | fail-fast: false 16 | 17 | # Set up a matrix to run the following 3 configurations: 18 | # 1. 19 | # 2. 20 | # 3. 21 | # 22 | # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. 23 | matrix: 24 | os: [ubuntu-latest, windows-latest] 25 | build_type: [Release] 26 | c_compiler: [gcc, cl] 27 | include: 28 | - os: windows-latest 29 | c_compiler: cl 30 | cpp_compiler: cl 31 | - os: ubuntu-latest 32 | c_compiler: gcc 33 | cpp_compiler: g++ 34 | exclude: 35 | - os: windows-latest 36 | c_compiler: gcc 37 | - os: ubuntu-latest 38 | c_compiler: cl 39 | 40 | steps: 41 | - uses: actions/checkout@v3 42 | 43 | - name: Set reusable strings 44 | # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. 45 | id: strings 46 | shell: bash 47 | run: | 48 | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" 49 | 50 | - name: Configure CMake 51 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 52 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 53 | run: > 54 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 55 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 56 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 57 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 58 | -S ${{ github.workspace }} 59 | 60 | - name: Build 61 | # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 62 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} 63 | 64 | - name: Test 65 | working-directory: ${{ steps.strings.outputs.build-output-dir }} 66 | # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). 67 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 68 | run: ctest --build-config ${{ matrix.build_type }} 69 | 70 | - name: Archiving 71 | # Default Build Artifact zipper does not retain file permission. 72 | run: 7z a SDHLT-${{ matrix.os }}-${{ matrix.c_compiler }}.zip tools 73 | 74 | - name: Upload a Build Artifact 75 | uses: actions/upload-artifact@v4.3.1 76 | with: 77 | name: SDHLT-${{ matrix.os }}-${{ matrix.c_compiler }} 78 | path: SDHLT-${{ matrix.os }}-${{ matrix.c_compiler }}.zip 79 | 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | *.obj 50 | *.exe 51 | *.tlog 52 | *.pdb 53 | *.mdl 54 | *.sdf 55 | *.opendb 56 | *.db 57 | *.suo 58 | *.log 59 | *.idb 60 | *.ilk 61 | *.user 62 | *.bmp 63 | *.iobj 64 | *.ipdb 65 | *.ipch 66 | *.res 67 | *.exp 68 | *.lastcodeanalysissucceeded 69 | *.nativecodeanalysis.all.xml 70 | *.nativecodeanalysis.xml 71 | *.aps 72 | *.bsc 73 | *.sbr 74 | *.db-wal 75 | *db-shm 76 | 77 | /src/sdhlt/.vs/ 78 | 79 | /src/sdhlt/sdHLBSP/Release/ 80 | /src/sdhlt/sdHLBSP/Release_x64/ 81 | 82 | /src/sdhlt/sdHLCSG/Release/ 83 | /src/sdhlt/sdHLCSG/Release_x64/ 84 | 85 | /src/sdhlt/sdHLRAD/Release/ 86 | /src/sdhlt/sdHLRAD/Release_x64/ 87 | 88 | /src/sdhlt/sdHLVIS/Release/ 89 | /src/sdhlt/sdHLVIS/Release_x64/ 90 | 91 | /src/sdhlt/sdRIPENT/Release/ 92 | /src/sdhlt/sdRIPENT/Release_x64/ 93 | 94 | /build/ 95 | /tools/* 96 | !/tools/*.fgd 97 | !/tools/*.wad 98 | !/tools/*.txt 99 | !/tools/lights.rad 100 | !/tools/wad.cfg 101 | 102 | *.zip 103 | 104 | /build*/ 105 | .vs/SDHLT/v17/.wsuo 106 | .vs/SDHLT/v17/DocumentLayout.json 107 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.2.0] - Jul 11 2024 8 | ### Changed 9 | - Add studiomodel shadows with 3 shadow modes and `-nostudioshadow` 10 | - Add *info_portal* and *info_leaf* 11 | - Add *info_minlights* and `%` texture flag 12 | - Add `-pre25`, increase `-limiter` default to `255` 13 | - Increase `-bounce` to min `12` if using `-expert` 14 | - Enable `-wadautodetect` by default 15 | - Reformatted texture-related logging to look like resgen 16 | - Add CMake config and Makefile 17 | 18 | ### Fixed 19 | - Potential buffer overrun in `PushWadPath` 20 | 21 | ## [1.1.2] - Sep 09 2022 22 | ### Changed 23 | - Reasons for skipping portal file optimisation process are more detailed 24 | 25 | ### Fixed 26 | - Fatal errors replaced with generic log messages when skipping optimisation of portal file 27 | 28 | ## [1.1.1] - Aug 27 2022 29 | ### Changed 30 | - Portal file optimisation process more streamlined. Separate .prt file is no longer created, instead the same one is optimised after VIS compilation 31 | - Automatic embedding of tool texture WAD file is hard-coded again due to lazy mappers 32 | - -chart parameter now enabled by default 33 | 34 | ### Fixed 35 | - Bug with -worldextent CSG parameter, where the default map size was +/-2048 36 | 37 | ## [1.1.0] - Jul 04 2020 38 | ### Added 39 | - -worldextent CSG parameter. Extends map geometry limits beyond +/-32768 40 | - Optimised portal file workflow for J.A.C.K, allowing import of .prt file into the editor directly after BSP compilation 41 | - Higher resolution image textures to tool texture WAD file 42 | 43 | ## 1.0.0 - Mar 09 2020 44 | ### Added 45 | - BEVELHINT tool texture, which acts like SOLIDHINT and BEVEL. Eliminates unnecessary face subdivision and bevels clipnodes at the same time 46 | - SPLITFACE tool texture. Brushes with this texture will subdivide faces they touch along their edges 47 | - !cur_ tool textures, which act like CONTENTWATER and func_pushable with a speed of 2048 units/s 48 | ### Changed 49 | - Automatic embedding of tool texture WAD file can now be controlled in settings.txt 50 | 51 | [1.1.2]: https://github.com/seedee/SDHLT/compare/v1.1.1...v1.1.2 52 | [1.1.1]: https://github.com/seedee/SDHLT/compare/v1.1.0...v1.1.1 53 | [1.1.0]: https://github.com/seedee/SDHLT/releases/tag/v1.1.0 54 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #================================ 2 | # SDHLT 3 | #================================ 4 | 5 | cmake_minimum_required(VERSION 3.20) 6 | 7 | project(sdhlt 8 | DESCRIPTION "seedee's Half-Life Compilation Tools" 9 | LANGUAGES CXX 10 | ) 11 | 12 | message("${CMAKE_PROJECT_NAME} > Starting configuration for ${CMAKE_PROJECT_DESCRIPTION}") 13 | 14 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tools) 15 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tools) 16 | 17 | #================ 18 | # Configuration 19 | #================ 20 | 21 | set(SDHLT_PREFIX "sd" CACHE STRING "Executable prefix.") 22 | set(SDHLT_GAME_PREFIX "HL" CACHE STRING "Executable game prefix.") 23 | 24 | message("${CMAKE_PROJECT_NAME} > Tools will use prefix \"${SDHLT_PREFIX}${SDHLT_GAME_PREFIX}\"") 25 | 26 | set(SDHLT_DIR ${CMAKE_SOURCE_DIR}/src/sdhlt) 27 | 28 | #================ 29 | # Common 30 | #================ 31 | 32 | set(COMMON_DIR ${SDHLT_DIR}/common) 33 | set(TEMPLATE_DIR ${SDHLT_DIR}/template) 34 | 35 | set(COMMON_SOURCES 36 | ${COMMON_DIR}/blockmem.cpp 37 | ${COMMON_DIR}/bspfile.cpp 38 | ${COMMON_DIR}/cmdlib.cpp 39 | ${COMMON_DIR}/cmdlinecfg.cpp 40 | ${COMMON_DIR}/filelib.cpp 41 | ${COMMON_DIR}/log.cpp 42 | ${COMMON_DIR}/mathlib.cpp 43 | ${COMMON_DIR}/messages.cpp 44 | ${COMMON_DIR}/scriplib.cpp 45 | ${COMMON_DIR}/threads.cpp 46 | ${COMMON_DIR}/winding.cpp 47 | ) 48 | 49 | set(COMMON_HEADERS 50 | ${TEMPLATE_DIR}/basictypes.h 51 | ${COMMON_DIR}/blockmem.h 52 | ${COMMON_DIR}/boundingbox.h 53 | ${COMMON_DIR}/bspfile.h 54 | ${COMMON_DIR}/cmdlib.h 55 | ${COMMON_DIR}/cmdlinecfg.h 56 | ${COMMON_DIR}/filelib.h 57 | ${COMMON_DIR}/hlassert.h 58 | ${COMMON_DIR}/log.h 59 | ${COMMON_DIR}/mathlib.h 60 | ${COMMON_DIR}/mathtypes.h 61 | ${COMMON_DIR}/messages.h 62 | ${COMMON_DIR}/scriplib.h 63 | ${COMMON_DIR}/threads.h 64 | ${COMMON_DIR}/win32fix.h 65 | ${COMMON_DIR}/winding.h 66 | ) 67 | 68 | #================ 69 | # BSP 70 | #================ 71 | 72 | set(BSP_DIR ${SDHLT_DIR}/sdHLBSP) 73 | 74 | set(BSP_SOURCES 75 | ${COMMON_SOURCES} 76 | ${BSP_DIR}/brink.cpp 77 | ${BSP_DIR}/merge.cpp 78 | ${BSP_DIR}/outside.cpp 79 | ${BSP_DIR}/portals.cpp 80 | ${BSP_DIR}/qbsp.cpp 81 | ${BSP_DIR}/solidbsp.cpp 82 | ${BSP_DIR}/surfaces.cpp 83 | ${BSP_DIR}/tjunc.cpp 84 | ${BSP_DIR}/writebsp.cpp 85 | ) 86 | 87 | set(BSP_HEADERS 88 | ${COMMON_HEADERS} 89 | ${BSP_DIR}/bsp5.h 90 | ) 91 | 92 | #================ 93 | # CSG 94 | #================ 95 | 96 | set(CSG_DIR ${SDHLT_DIR}/sdHLCSG) 97 | 98 | set(CSG_SOURCES 99 | ${COMMON_SOURCES} 100 | ${CSG_DIR}/ansitoutf8.cpp 101 | ${CSG_DIR}/brush.cpp 102 | ${CSG_DIR}/brushunion.cpp 103 | ${CSG_DIR}/hullfile.cpp 104 | ${CSG_DIR}/map.cpp 105 | ${CSG_DIR}/properties.cpp 106 | ${CSG_DIR}/qcsg.cpp 107 | ${CSG_DIR}/textures.cpp 108 | ${CSG_DIR}/wadcfg.cpp 109 | ${CSG_DIR}/wadpath.cpp 110 | ) 111 | 112 | set(CSG_HEADERS 113 | ${COMMON_HEADERS} 114 | ${CSG_DIR}/csg.h 115 | ${CSG_DIR}/wadpath.h 116 | ) 117 | 118 | #================ 119 | # RAD 120 | #================ 121 | 122 | set(RAD_DIR ${SDHLT_DIR}/sdHLRAD) 123 | 124 | set(RAD_SOURCES 125 | ${COMMON_SOURCES} 126 | ${RAD_DIR}/compress.cpp 127 | ${RAD_DIR}/lerp.cpp 128 | ${RAD_DIR}/lightmap.cpp 129 | ${RAD_DIR}/loadtextures.cpp 130 | ${RAD_DIR}/mathutil.cpp 131 | ${RAD_DIR}/meshdesc.cpp 132 | ${RAD_DIR}/meshtrace.cpp 133 | ${RAD_DIR}/nomatrix.cpp 134 | ${RAD_DIR}/progmesh.cpp 135 | ${RAD_DIR}/qrad.cpp 136 | ${RAD_DIR}/qradutil.cpp 137 | ${RAD_DIR}/sparse.cpp 138 | ${RAD_DIR}/stringlib.cpp 139 | ${RAD_DIR}/studio.cpp 140 | ${RAD_DIR}/trace.cpp 141 | ${RAD_DIR}/transfers.cpp 142 | ${RAD_DIR}/transparency.cpp 143 | ${RAD_DIR}/vismatrix.cpp 144 | ${RAD_DIR}/vismatrixutil.cpp 145 | ) 146 | 147 | set(RAD_HEADERS 148 | ${COMMON_HEADERS} 149 | ${COMMON_DIR}/anorms.h 150 | ${RAD_DIR}/compress.h 151 | ${RAD_DIR}/list.h 152 | ${RAD_DIR}/meshdesc.h 153 | ${RAD_DIR}/meshtrace.h 154 | ${RAD_DIR}/qrad.h 155 | ) 156 | 157 | #================ 158 | # VIS 159 | #================ 160 | 161 | set(VIS_DIR ${SDHLT_DIR}/sdHLVIS) 162 | 163 | set(VIS_SOURCES 164 | ${COMMON_SOURCES} 165 | ${VIS_DIR}/flow.cpp 166 | ${VIS_DIR}/vis.cpp 167 | ${VIS_DIR}/zones.cpp 168 | ) 169 | 170 | set(VIS_HEADERS 171 | ${COMMON_HEADERS} 172 | ${VIS_DIR}/vis.h 173 | ${VIS_DIR}/zones.h 174 | ) 175 | 176 | #================ 177 | # RIPENT 178 | #================ 179 | 180 | set(RIPENT_DIR ${SDHLT_DIR}/sdRIPENT) 181 | 182 | set(RIPENT_SOURCES 183 | ${COMMON_SOURCES} 184 | ${RIPENT_DIR}/ripent.cpp 185 | ) 186 | 187 | set(RIPENT_HEADERS 188 | ${COMMON_HEADERS} 189 | ${RIPENT_DIR}/ripent.h 190 | ) 191 | 192 | #================ 193 | # Include 194 | #================ 195 | 196 | include_directories( 197 | ${SDHLT_DIR}/common 198 | ${SDHLT_DIR}/template 199 | ) 200 | 201 | #================ 202 | # System config 203 | #================ 204 | 205 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 206 | add_compile_options( 207 | -Wall 208 | -O2 209 | -fno-strict-aliasing 210 | -pthread 211 | -pipe 212 | ) 213 | add_compile_definitions( 214 | VERSION_LINUX 215 | SYSTEM_POSIX 216 | STDC_HEADERS 217 | HAVE_FCNTL_H 218 | HAVE_PTHREAD_H 219 | HAVE_STDDEF_H 220 | HAVE_SYS_RESOURCE_H 221 | HAVE_SYS_STAT_H 222 | HAVE_SYS_TIME_H 223 | HAVE_UNISTD_H 224 | ) 225 | message("${CMAKE_PROJECT_NAME} > Configuring for ${CMAKE_SYSTEM_NAME}") 226 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows") 227 | option(SDHLT_64BIT "Flag targets as 64-bit." ON) 228 | if (SDHLT_64BIT) 229 | add_compile_definitions(VERSION_64BIT) 230 | else() 231 | add_compile_definitions(VERSION_32BIT) 232 | endif() 233 | add_compile_definitions( 234 | SYSTEM_WIN32 235 | STDC_HEADERS 236 | ) 237 | message("${CMAKE_PROJECT_NAME} > Configuring for ${CMAKE_SYSTEM_NAME}") 238 | else() 239 | add_compile_definitions(VERSION_OTHER) 240 | message("${CMAKE_PROJECT_NAME} > WARNING: Unknown system \"${CMAKE_SYSTEM_NAME}\"") 241 | endif() 242 | 243 | #================ 244 | # Targets 245 | #================ 246 | 247 | add_executable(BSP ${BSP_SOURCES} ${BSP_HEADERS}) 248 | add_executable(CSG ${CSG_SOURCES} ${CSG_HEADERS}) 249 | add_executable(RAD ${RAD_SOURCES} ${RAD_HEADERS}) 250 | add_executable(VIS ${VIS_SOURCES} ${VIS_HEADERS}) 251 | add_executable(RIPENT ${RIPENT_SOURCES} ${RIPENT_HEADERS}) 252 | 253 | set_target_properties(BSP CSG RAD VIS 254 | PROPERTIES 255 | PREFIX ${SDHLT_PREFIX}${SDHLT_GAME_PREFIX} 256 | ) 257 | set_target_properties(RIPENT 258 | PROPERTIES 259 | PREFIX ${SDHLT_PREFIX} 260 | ) 261 | 262 | target_compile_definitions(BSP PRIVATE SDHLBSP DOUBLEVEC_T) 263 | target_compile_definitions(CSG PRIVATE SDHLCSG DOUBLEVEC_T) 264 | target_compile_definitions(RAD PRIVATE SDHLRAD) 265 | target_compile_definitions(VIS PRIVATE SDHLVIS) 266 | target_compile_definitions(RIPENT PRIVATE SDRIPENT) 267 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Banner](media/banner.png) 2 | 3 | Half-Life engine map compile tools, based on Vluzacn's ZHLT v34 with code contributions from various contributors. Based on Valve's version, modified with permission. 4 | 5 | New features include shadows from studiomodels, new entities, additional tool textures, ability to extend world size limits, portal file optimisation for J.A.C.K. map editor and minor algorithm optimization. 6 | 7 | ## How to install 8 | 9 | 1. Open the configuration dialog of your map editor or batch compiler. 10 | 2. Set CSG, BSP, VIS, RAD tool paths to *sdHLCSG.exe*, *sdHLBSP.exe*, *sdHLVIS.exe*, *sdHLRAD.exe*, use the *_x64.exe* editions if running on 64-bit. 11 | 3. Add *sdhlt.wad* into your wad list. This is required to compile maps. 12 | 4. Add *sdhlt.fgd* into your fgd list. 13 | 14 | The main benefit of the 64-bit version is no memory allocation failures, because the 64-bit tools have access to more than 2GB of system memory. 15 | 16 | ## Features 17 | 18 | ### Studiomodel shadows 19 | 20 | Entities with a `model` keyvalue, such as *env_sprite* or *cycler_sprite*, support the use of `zhlt_studioshadow 1` to flag the studiomodel as opaque to lighting. Additionally, `zhlt_shadowmode n` is used to control the shadow tracing mode. 21 | The default `1` will trace for each triangle and supports transparent textures. 22 | Setting `2` doesn't support transparency, but it traces the planes bbox for each triangle, the slowest but usually higher quality for some models. 23 | Setting `0` disables tracing and uses the mesh bbox instead. 24 | 25 | To implement these into your own fgd file for SmartEdit, use the template at the top of *sdhlt.fgd*. If the new shadow covers the origin and makes it too dark, set a custom `light_origin` on the entity or move the mesh origin point externally. 26 | 27 | ### Entities 28 | 29 | - *info_portal* and *info_leaf* ared used to create a portal from the leaf the *info_portal* is inside, to the selected leaf the *info_leaf* is inside. Forces target leaf to be visible from the current one, making all entities visible. 30 | - *info_minlights* used to set minlights for textures, works on world geometry too. Works similarly to `_minlight` but per-texture. 31 | 32 | ### Textures 33 | 34 | - Support for `%` texture flag, sets the minlight for this texture. **%texname** alone is equivalent to `_minlight 1.0`, while **%`#`texname** where **`#`** is an integer in a range of `0-255`. 35 | - **BEVELHINT** texture, which acts like **SOLIDHINT** and **BEVEL**. Eliminates unnecessary face subdivision and bevels clipnodes at the same time. Useful on complex shapes such as terrain, spiral staircase clipping, etc. 36 | - **SPLITFACE** texture. Brushes with this texture will subdivide faces they touch along their edges, similarly to `zhlt_chopdown`. 37 | - **cur_tool** textures, which act like **CONTENTWATER** and *func_pushable* with a speed of `2048 units/s` in -Y. This texture is always fullbright. 38 | 39 | ### Compile parameters 40 | 41 | - `-pre25` RAD parameter overrides light clipping threshold limiter to `188`. Use this when creating maps for the legacy pre-25th anniversary engine without worrying about other parameters. 42 | - `-extra` RAD parameter now sets `-bounce 12` for a higher quality of lighting simulation. 43 | - `-worldextent n` CSG parameter. Extends map geometry limits beyond `+/-32768`. 44 | - Portal file reformatting for J.A.C.K. map editor, allows for importing the prt file into the editor directly after VIS. Use `-nofixprt` VIS parameter to disable. 45 | - `-nowadautodetect` CSG parameter. Wadautodetect is now true by default regardless of settings. 46 | - `-nostudioshadow` RAD parameter to ignore `zhlt_studioshadow` on studiomodels. 47 | 48 | ## Planned 49 | - **BLOCKLIGHT** texture, cast shadows without generating faces or cliphulls. 50 | - Optimization for `BuildFacelights` and `LeafThread` 51 | - Res file creation for servers 52 | - Split concerns into their own libraries instead of repeating infrastructure and util code 53 | - Full tool texture documentation 54 | -------------------------------------------------------------------------------- /media/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seedee/SDHLT/9b94e4fd1c4392802e1a01256596ea69894afc49/media/banner.png -------------------------------------------------------------------------------- /src/cleanup.bat: -------------------------------------------------------------------------------- 1 | ::This script is used to delete any Release folders that are created after compilation 2 | 3 | rmdir /s /q sdhlt\sdHLBSP\Release\ 4 | rmdir /s /q sdhlt\sdHLBSP\Release_x64\ 5 | 6 | rmdir /s /q sdhlt\sdHLCSG\Release\ 7 | rmdir /s /q sdhlt\sdHLCSG\Release_x64\ 8 | 9 | rmdir /s /q sdhlt\sdHLRAD\Release\ 10 | rmdir /s /q sdhlt\sdHLRAD\Release_x64\ 11 | 12 | rmdir /s /q sdhlt\sdHLVIS\Release\ 13 | rmdir /s /q sdhlt\sdHLVIS\Release_x64\ 14 | 15 | rmdir /s /q sdhlt\sdRIPENT\Release\ 16 | rmdir /s /q sdhlt\sdRIPENT\Release_x64\ -------------------------------------------------------------------------------- /src/sdhlt/common/TimeCounter.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMECOUNTER_H__ 2 | #define TIMECOUNTER_H__ 3 | 4 | #if _MSC_VER >= 1000 5 | #pragma once 6 | #endif 7 | 8 | #include "cmdlib.h" 9 | 10 | class TimeCounter 11 | { 12 | public: 13 | void start() 14 | { 15 | starttime = I_FloatTime(); 16 | } 17 | 18 | void stop() 19 | { 20 | double stop = I_FloatTime(); 21 | accum += stop - starttime; 22 | } 23 | 24 | double getTotal() const 25 | { 26 | return accum; 27 | } 28 | 29 | void reset() 30 | { 31 | memset(this, 0, sizeof(*this)); 32 | } 33 | 34 | // Construction 35 | public: 36 | TimeCounter() 37 | { 38 | reset(); 39 | } 40 | // Default Destructor ok 41 | // Default Copy Constructor ok 42 | // Default Copy Operator ok 43 | 44 | protected: 45 | double starttime; 46 | double accum; 47 | }; 48 | 49 | #endif//TIMECOUNTER_H__ -------------------------------------------------------------------------------- /src/sdhlt/common/blockmem.cpp: -------------------------------------------------------------------------------- 1 | 2 | /// ********* WIN32 ********** 3 | 4 | #ifdef SYSTEM_WIN32 5 | #define WIN32_LEAN_AND_MEAN 6 | #include 7 | #include 8 | #include "cmdlib.h" 9 | #include "messages.h" 10 | #include "log.h" 11 | #include "hlassert.h" 12 | #include "blockmem.h" 13 | 14 | // ===================================================================================== 15 | // AllocBlock 16 | // ===================================================================================== 17 | void* AllocBlock(const unsigned long size) 18 | { 19 | void* pointer; 20 | HANDLE h; 21 | 22 | if (!size) 23 | { 24 | Warning("Attempting to allocate 0 bytes"); 25 | } 26 | 27 | h = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, size); 28 | 29 | hlassume (h != NULL, assume_NoMemory); 30 | 31 | if (h) 32 | { 33 | pointer = GlobalLock(h); 34 | } 35 | else 36 | { 37 | return NULL; 38 | } 39 | 40 | return pointer; 41 | } 42 | 43 | // ===================================================================================== 44 | // FreeBlock 45 | // ===================================================================================== 46 | bool FreeBlock(void* pointer) 47 | { 48 | HANDLE h; 49 | 50 | if (!pointer) 51 | { 52 | Warning("Freeing a null pointer"); 53 | } 54 | 55 | h = GlobalHandle(pointer); 56 | 57 | if (h) 58 | { 59 | GlobalUnlock(h); 60 | GlobalFree(h); 61 | return true; 62 | } 63 | else 64 | { 65 | Warning("Could not translate pointer into handle"); 66 | return false; 67 | } 68 | } 69 | 70 | #ifdef CHECK_HEAP 71 | // ===================================================================================== 72 | // HeapCheck 73 | // ===================================================================================== 74 | void HeapCheck() 75 | { 76 | if (_heapchk() != _HEAPOK) 77 | hlassert(false); 78 | } 79 | #endif 80 | 81 | // ===================================================================================== 82 | // AllocBlock 83 | // ===================================================================================== 84 | // HeapAlloc/HeapFree is thread safe by default 85 | void* Alloc(const unsigned long size) 86 | { 87 | HeapCheck(); 88 | return calloc(1, size); 89 | } 90 | 91 | // ===================================================================================== 92 | // AllocBlock 93 | // ===================================================================================== 94 | bool Free(void* pointer) 95 | { 96 | HeapCheck(); 97 | free(pointer); 98 | return true; 99 | } 100 | 101 | #endif /// ********* WIN32 ********** 102 | 103 | 104 | 105 | 106 | /// ********* POSIX ********** 107 | 108 | #ifdef SYSTEM_POSIX 109 | #ifdef HAVE_CONFIG_H 110 | #include "config.h" 111 | #endif 112 | #ifdef STDC_HEADERS 113 | #include 114 | #endif 115 | #include "cmdlib.h" 116 | #include "messages.h" 117 | #include "log.h" 118 | 119 | // ===================================================================================== 120 | // AllocBlock 121 | // ===================================================================================== 122 | void* AllocBlock(const unsigned long size) 123 | { 124 | if (!size) 125 | { 126 | Warning("Attempting to allocate 0 bytes"); 127 | } 128 | return calloc(1, size); 129 | } 130 | 131 | // ===================================================================================== 132 | // FreeBlock 133 | // ===================================================================================== 134 | bool FreeBlock(void* pointer) 135 | { 136 | if (!pointer) 137 | { 138 | Warning("Freeing a null pointer"); 139 | } 140 | free(pointer); 141 | return true; 142 | } 143 | 144 | // ===================================================================================== 145 | // Alloc 146 | // ===================================================================================== 147 | void* Alloc(const unsigned long size) 148 | { 149 | return AllocBlock(size); 150 | } 151 | 152 | // ===================================================================================== 153 | // Free 154 | // ===================================================================================== 155 | bool Free(void* pointer) 156 | { 157 | return FreeBlock(pointer); 158 | } 159 | 160 | #endif /// ********* POSIX ********** 161 | -------------------------------------------------------------------------------- /src/sdhlt/common/blockmem.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCKMEM_H__ 2 | #define BLOCKMEM_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | extern void* AllocBlock(unsigned long size); 10 | extern bool FreeBlock(void* pointer); 11 | 12 | extern void* Alloc(unsigned long size); 13 | extern bool Free(void* pointer); 14 | 15 | #if defined(CHECK_HEAP) 16 | extern void HeapCheck(); 17 | #else 18 | #define HeapCheck() 19 | #endif 20 | 21 | #endif // BLOCKMEM_H__ 22 | -------------------------------------------------------------------------------- /src/sdhlt/common/boundingbox.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | // AJM: 6 | #pragma warning(disable: 4305) // truncation from 'const double' to 'float' 7 | 8 | 9 | #ifndef BOUNDINGBOX_H__ 10 | #define BOUNDINGBOX_H__ 11 | #include "cmdlib.h" //--vluzacn 12 | 13 | #if _MSC_VER >= 1000 14 | #pragma once 15 | #endif 16 | 17 | class BoundingBox 18 | { 19 | public: 20 | typedef enum 21 | { 22 | eDisjoint, // neither boxes touch 23 | eUnion, // this box intersects with the other box 24 | eSubset, // this box is inside the other box 25 | eSuperset // this box is completly envelops the other box 26 | } eBoundingState; 27 | 28 | // Tests if other box is completely outside of this box 29 | bool testDisjoint(const BoundingBox& other) const 30 | { 31 | if ((m_Mins[0] > other.m_Maxs[0] + ON_EPSILON) || 32 | (m_Mins[1] > other.m_Maxs[1] + ON_EPSILON) || 33 | (m_Mins[2] > other.m_Maxs[2] + ON_EPSILON) || 34 | (m_Maxs[0] < other.m_Mins[0] - ON_EPSILON) || 35 | (m_Maxs[1] < other.m_Mins[1] - ON_EPSILON) || 36 | (m_Maxs[2] < other.m_Mins[2] - ON_EPSILON)) 37 | { 38 | return true; 39 | } 40 | return false; 41 | } 42 | // returns true if this box is completely inside other box 43 | bool testSubset(const BoundingBox& other) const 44 | { 45 | if ( 46 | (m_Mins[0] >= other.m_Mins[0]) && 47 | (m_Maxs[0] <= other.m_Maxs[0]) && 48 | (m_Mins[1] >= other.m_Mins[1]) && 49 | (m_Maxs[1] <= other.m_Maxs[1]) && 50 | (m_Mins[2] >= other.m_Mins[2]) && 51 | (m_Maxs[2] <= other.m_Maxs[2]) 52 | ) 53 | { 54 | return true; 55 | } 56 | return false; 57 | } 58 | // returns true if this box contains the other box completely 59 | bool testSuperset(const BoundingBox& other) const 60 | { 61 | return other.testSubset(*this); 62 | } 63 | // returns true if this box partially intersects the other box 64 | bool testUnion(const BoundingBox& other) const 65 | { 66 | BoundingBox tmpBox; 67 | tmpBox.m_Mins[0] = qmax(m_Mins[0], other.m_Mins[0]); 68 | tmpBox.m_Mins[1] = qmax(m_Mins[1], other.m_Mins[1]); 69 | tmpBox.m_Mins[2] = qmax(m_Mins[2], other.m_Mins[2]); 70 | tmpBox.m_Maxs[0] = qmin(m_Maxs[0], other.m_Maxs[0]); 71 | tmpBox.m_Maxs[1] = qmin(m_Maxs[1], other.m_Maxs[1]); 72 | tmpBox.m_Maxs[2] = qmin(m_Maxs[2], other.m_Maxs[2]); 73 | 74 | if ((tmpBox.m_Mins[0] > tmpBox.m_Maxs[0]) || 75 | (tmpBox.m_Mins[1] > tmpBox.m_Maxs[1]) || 76 | (tmpBox.m_Mins[2] > tmpBox.m_Maxs[2])) 77 | { 78 | return false; 79 | } 80 | return true; 81 | } 82 | eBoundingState test(const BoundingBox& other) const 83 | { 84 | eBoundingState rval; 85 | if (testDisjoint(other)) 86 | { 87 | rval = eDisjoint; 88 | } 89 | else if (testSubset(other)) 90 | { 91 | rval = eSubset; 92 | } 93 | else if (testSuperset(other)) 94 | { 95 | rval = eSuperset; 96 | } 97 | else 98 | { 99 | rval = eUnion; 100 | } 101 | return rval; 102 | } 103 | 104 | void set(const vec3_t mins, const vec3_t maxs) 105 | { 106 | VectorCopy(mins, m_Mins); 107 | VectorCopy(maxs, m_Maxs); 108 | } 109 | void reset() 110 | { 111 | VectorFill(m_Mins, 999999999.999); 112 | VectorFill(m_Maxs, -999999999.999); 113 | } 114 | void add(const vec3_t point) 115 | { 116 | m_Mins[0] = qmin(m_Mins[0], point[0]); 117 | m_Maxs[0] = qmax(m_Maxs[0], point[0]); 118 | m_Mins[1] = qmin(m_Mins[1], point[1]); 119 | m_Maxs[1] = qmax(m_Maxs[1], point[1]); 120 | m_Mins[2] = qmin(m_Mins[2], point[2]); 121 | m_Maxs[2] = qmax(m_Maxs[2], point[2]); 122 | } 123 | void add(const BoundingBox& other) 124 | { 125 | add(other.m_Mins); 126 | add(other.m_Maxs); 127 | } 128 | 129 | public: 130 | // BoundingBox(const BoundingBox& other) // Default copy constructor ok 131 | // BoundingBox& operator=(const BoundingBox& other); // Default copy operator ok 132 | BoundingBox() 133 | { 134 | reset(); 135 | } 136 | BoundingBox(const vec3_t& mins, const vec3_t& maxs) 137 | { 138 | VectorCopy(mins, m_Mins); 139 | VectorCopy(maxs, m_Maxs); 140 | } 141 | ~BoundingBox() {} 142 | 143 | public: 144 | // Bounding box 145 | vec3_t m_Mins; 146 | vec3_t m_Maxs; 147 | }; 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /src/sdhlt/common/cmdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef CMDLIB_H__ 2 | #define CMDLIB_H__ 3 | 4 | #if _MSC_VER >= 1000 5 | #pragma once 6 | #endif 7 | 8 | //#define MODIFICATIONS_STRING "Submit detailed bug reports to (zoner@gearboxsoftware.com)\n" 9 | //#define MODIFICATIONS_STRING "Submit detailed bug reports to (merlinis@bigpond.net.au)\n" 10 | //#define MODIFICATIONS_STRING "Submit detailed bug reports to (amckern@yahoo.com)\n" 11 | //#define MODIFICATIONS_STRING "Submit detailed bug reports to (vluzacn@163.com)\n" //--vluzacn 12 | #define MODIFICATIONS_STRING "Submit detailed bug reports to (github.com/seedee/SDHLT/issues)\n" 13 | 14 | #ifdef _DEBUG 15 | #define ZHLT_VERSIONSTRING "v3.4 dbg" 16 | #else 17 | #define ZHLT_VERSIONSTRING "v3.4" 18 | #endif 19 | 20 | #define HACK_VERSIONSTRING "VL34" //--vluzacn 21 | 22 | #define SDHLT_VERSIONSTRING "v1.2.0" 23 | 24 | #if !defined (SDHLCSG) && !defined (SDHLBSP) && !defined (SDHLVIS) && !defined (SDHLRAD) && !defined (SDRIPENT) //seedee 25 | #error "You must define one of these in the settings of each project: SDHLCSG, SDHLBSP, SDHLVIS, SDHLRAD, SDRIPENT. The most likely cause is that you didn't load the project from the .sln file." 26 | #endif 27 | #if !defined (VERSION_32BIT) && !defined (VERSION_64BIT) && !defined (VERSION_LINUX) && !defined (VERSION_OTHER) //--vluzacn 28 | #error "You must define one of these in the settings of each project: VERSION_32BIT, VERSION_64BIT, VERSION_LINUX, VERSION_OTHER. The most likely cause is that you didn't load the project from the .sln file." 29 | #endif 30 | 31 | #ifdef VERSION_32BIT 32 | #define PLATFORM_VERSIONSTRING "32-bit" 33 | #define PLATFORM_CAN_CALC_EXTENT 34 | #endif 35 | #ifdef VERSION_64BIT 36 | #define PLATFORM_VERSIONSTRING "64-bit" 37 | #define PLATFORM_CAN_CALC_EXTENT 38 | #endif 39 | #ifdef VERSION_LINUX 40 | #define PLATFORM_VERSIONSTRING "linux" 41 | #define PLATFORM_CAN_CALC_EXTENT 42 | #endif 43 | #ifdef VERSION_OTHER 44 | #define PLATFORM_VERSIONSTRING "???" 45 | #endif 46 | 47 | //===================================================================== 48 | // AJM: Different features of the tools can be undefined here 49 | // these are not officially beta tested, but seem to work okay 50 | 51 | // ZHLT_* features are spread across more than one tool. Hence, changing 52 | // one of these settings probably means recompiling the whole set 53 | 54 | #ifdef SYSTEM_WIN32 55 | #define RIPENT_PAUSE //--vluzacn 56 | #endif 57 | 58 | // tool specific settings below only mean a recompile of the tool affected 59 | 60 | #ifdef SYSTEM_WIN32 61 | #define HLCSG_GAMETEXTMESSAGE_UTF8 //--vluzacn 62 | #endif 63 | 64 | //===================================================================== 65 | 66 | #if _MSC_VER <1400 67 | #define strcpy_s strcpy //--vluzacn 68 | #define sprintf_s sprintf //--vluzacn 69 | #endif 70 | #if _MSC_VER >= 1400 71 | #pragma warning(disable: 4996) 72 | #endif 73 | 74 | #ifdef __MINGW32__ 75 | #include 76 | #endif 77 | 78 | #ifdef HAVE_CONFIG_H 79 | #include "config.h" 80 | #endif 81 | 82 | #if 0 //--vluzacn 83 | // AJM: gnu compiler fix 84 | #ifdef __GNUC__ 85 | #define _alloca __builtin_alloca 86 | #define alloca __builtin_alloca 87 | #endif 88 | #endif 89 | 90 | #include "win32fix.h" 91 | #include "mathtypes.h" 92 | 93 | #ifdef SYSTEM_WIN32 94 | #pragma warning(disable: 4127) // conditional expression is constant 95 | #pragma warning(disable: 4115) // named type definition in parentheses 96 | #pragma warning(disable: 4244) // conversion from 'type' to type', possible loss of data 97 | // AJM 98 | #pragma warning(disable: 4786) // identifier was truncated to '255' characters in the browser information 99 | #pragma warning(disable: 4305) // truncation from 'const double' to 'float' 100 | #pragma warning(disable: 4800) // forcing value to bool 'true' or 'false' (performance warning) 101 | #endif 102 | 103 | 104 | #ifdef STDC_HEADERS 105 | #include 106 | #include 107 | #include 108 | #include 109 | #include 110 | #include 111 | #include 112 | #include 113 | #endif 114 | 115 | #include //--vluzacn 116 | 117 | #ifdef HAVE_SYS_TIME_H 118 | #include 119 | #endif 120 | #ifdef HAVE_UNISTD_H 121 | #include 122 | #endif 123 | 124 | #ifdef ZHLT_NETVIS 125 | #include "c2cpp.h" 126 | #endif 127 | 128 | #ifdef SYSTEM_WIN32 129 | #define SYSTEM_SLASH_CHAR '\\' 130 | #define SYSTEM_SLASH_STR "\\" 131 | #endif 132 | #ifdef SYSTEM_POSIX 133 | #define SYSTEM_SLASH_CHAR '/' 134 | #define SYSTEM_SLASH_STR "/" 135 | #endif 136 | 137 | // the dec offsetof macro doesn't work very well... 138 | #define myoffsetof(type,identifier) ((size_t)&((type*)0)->identifier) 139 | #define sizeofElement(type,identifier) (sizeof((type*)0)->identifier) 140 | 141 | #ifdef SYSTEM_POSIX 142 | extern char* strupr(char* string); 143 | extern char* strlwr(char* string); 144 | #endif 145 | extern const char* stristr(const char* const string, const char* const substring); 146 | extern bool CDECL FORMAT_PRINTF(3,4) safe_snprintf(char* const dest, const size_t count, const char* const args, ...); 147 | extern bool safe_strncpy(char* const dest, const char* const src, const size_t count); 148 | extern bool safe_strncat(char* const dest, const char* const src, const size_t count); 149 | extern bool TerminatedString(const char* buffer, const int size); 150 | 151 | extern char* FlipSlashes(char* string); 152 | 153 | extern double I_FloatTime(); 154 | 155 | extern int CheckParm(char* check); 156 | 157 | extern void DefaultExtension(char* path, const char* extension); 158 | extern void DefaultPath(char* path, char* basepath); 159 | extern void StripFilename(char* path); 160 | extern void StripExtension(char* path); 161 | 162 | extern void ExtractFile(const char* const path, char* dest); 163 | extern void ExtractFilePath(const char* const path, char* dest); 164 | extern void ExtractFileBase(const char* const path, char* dest); 165 | extern void ExtractFileExtension(const char* const path, char* dest); 166 | 167 | extern short BigShort(short l); 168 | extern short LittleShort(short l); 169 | extern int BigLong(int l); 170 | extern int LittleLong(int l); 171 | extern float BigFloat(float l); 172 | extern float LittleFloat(float l); 173 | 174 | #endif //CMDLIB_H__ 175 | -------------------------------------------------------------------------------- /src/sdhlt/common/cmdlinecfg.h: -------------------------------------------------------------------------------- 1 | #ifndef CMDLINECFG_H__ 2 | #define CMDLINECFG_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | extern void ParseParamFile (const int argc, char ** const argv, int &argcnew, char **&argvnew); 5 | #endif 6 | -------------------------------------------------------------------------------- /src/sdhlt/common/filelib.cpp: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #ifdef SYSTEM_WIN32 6 | #include 7 | #include 8 | #include 9 | #endif 10 | 11 | #ifdef SYSTEM_POSIX 12 | #ifdef HAVE_SYS_STAT_H 13 | #include 14 | #endif 15 | 16 | #ifdef HAVE_FCNTL_H 17 | #include 18 | #endif 19 | 20 | #ifdef HAVE_UNISTD_H 21 | #include 22 | #endif 23 | #endif 24 | 25 | #include "cmdlib.h" 26 | #include "messages.h" 27 | #include "log.h" 28 | #include "mathtypes.h" 29 | #include "mathlib.h" 30 | #include "blockmem.h" 31 | 32 | /* 33 | * ============== 34 | * getfiletime 35 | * ============== 36 | */ 37 | 38 | time_t getfiletime(const char* const filename) 39 | { 40 | time_t filetime = 0; 41 | struct stat filestat; 42 | 43 | if (stat(filename, &filestat) == 0) 44 | filetime = qmax(filestat.st_mtime, filestat.st_ctime); 45 | 46 | return filetime; 47 | } 48 | 49 | /* 50 | * ============== 51 | * getfilesize 52 | * ============== 53 | */ 54 | long getfilesize(const char* const filename) 55 | { 56 | long size = 0; 57 | struct stat filestat; 58 | 59 | if (stat(filename, &filestat) == 0) 60 | size = filestat.st_size; 61 | 62 | return size; 63 | } 64 | 65 | /* 66 | * ============== 67 | * getfiledata 68 | * ============== 69 | */ 70 | long getfiledata(const char* const filename, char* buffer, const int buffersize) 71 | { 72 | long size = 0; 73 | int handle; 74 | time_t start, end; 75 | 76 | time(&start); 77 | 78 | if ((handle = _open(filename, O_RDONLY)) != -1) 79 | { 80 | int bytesread; 81 | 82 | Log("%-20s Restoring [%-13s - ", "BuildVisMatrix:", filename); 83 | while ((bytesread = _read(handle, buffer, qmin(32 * 1024, buffersize - size))) > 0) 84 | { 85 | size += bytesread; 86 | buffer += bytesread; 87 | } 88 | _close(handle); 89 | time(&end); 90 | Log("%10.3fMB] (%li)\n", size / (1024.0 * 1024.0), end - start); 91 | } 92 | 93 | if (buffersize != size) 94 | { 95 | Warning("Invalid file [%s] found. File will be rebuilt!\n", filename); 96 | _unlink(filename); 97 | } 98 | 99 | return size; 100 | } 101 | 102 | /* 103 | * ================ 104 | * filelength 105 | * ================ 106 | */ 107 | int q_filelength(FILE* f) 108 | { 109 | int pos; 110 | int end; 111 | 112 | pos = ftell(f); 113 | fseek(f, 0, SEEK_END); 114 | end = ftell(f); 115 | fseek(f, pos, SEEK_SET); 116 | 117 | return end; 118 | } 119 | 120 | /* 121 | * ================ 122 | * exists 123 | * ================ 124 | */ 125 | bool q_exists(const char* const filename) 126 | { 127 | FILE* f; 128 | 129 | f = fopen(filename, "rb"); 130 | 131 | if (!f) 132 | { 133 | IfDebug(Developer(DEVELOPER_LEVEL_SPAM, "Checking for existance of file %s (failed)\n", filename)); 134 | return false; 135 | } 136 | else 137 | { 138 | fclose(f); 139 | IfDebug(Developer(DEVELOPER_LEVEL_SPAM, "Checking for existance of file %s (success)\n", filename)); 140 | return true; 141 | } 142 | } 143 | 144 | 145 | 146 | 147 | FILE* SafeOpenWrite(const char* const filename) 148 | { 149 | FILE* f; 150 | 151 | f = fopen(filename, "wb"); 152 | 153 | if (!f) 154 | Error("Error opening %s: %s", filename, strerror(errno)); 155 | 156 | return f; 157 | } 158 | 159 | FILE* SafeOpenRead(const char* const filename) 160 | { 161 | FILE* f; 162 | 163 | f = fopen(filename, "rb"); 164 | 165 | if (!f) 166 | Error("Error opening %s: %s", filename, strerror(errno)); 167 | 168 | return f; 169 | } 170 | 171 | void SafeRead(FILE* f, void* buffer, int count) 172 | { 173 | if (fread(buffer, 1, count, f) != (size_t) count) 174 | Error("File read failure"); 175 | } 176 | 177 | void SafeWrite(FILE* f, const void* const buffer, int count) 178 | { 179 | if (fwrite(buffer, 1, count, f) != (size_t) count) 180 | Error("File write failure"); //Error("File read failure"); //--vluzacn 181 | } 182 | 183 | /* 184 | * ============== 185 | * LoadFile 186 | * ============== 187 | */ 188 | int LoadFile(const char* const filename, char** bufferptr) 189 | { 190 | FILE* f; 191 | int length; 192 | char* buffer; 193 | 194 | f = SafeOpenRead(filename); 195 | length = q_filelength(f); 196 | buffer = (char*)Alloc(length + 1); 197 | SafeRead(f, buffer, length); 198 | fclose(f); 199 | 200 | *bufferptr = buffer; 201 | return length; 202 | } 203 | 204 | /* 205 | * ============== 206 | * SaveFile 207 | * ============== 208 | */ 209 | void SaveFile(const char* const filename, const void* const buffer, int count) 210 | { 211 | FILE* f; 212 | 213 | f = SafeOpenWrite(filename); 214 | SafeWrite(f, buffer, count); 215 | fclose(f); 216 | } 217 | 218 | -------------------------------------------------------------------------------- /src/sdhlt/common/filelib.h: -------------------------------------------------------------------------------- 1 | #ifndef FILELIB_H__ 2 | #define FILELIB_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | extern time_t getfiletime(const char* const filename); 10 | extern long getfilesize(const char* const filename); 11 | extern long getfiledata(const char* const filename, char* buffer, const int buffersize); 12 | extern bool q_exists(const char* const filename); 13 | extern int q_filelength(FILE* f); 14 | 15 | extern FILE* SafeOpenWrite(const char* const filename); 16 | extern FILE* SafeOpenRead(const char* const filename); 17 | extern void SafeRead(FILE* f, void* buffer, int count); 18 | extern void SafeWrite(FILE* f, const void* const buffer, int count); 19 | 20 | extern int LoadFile(const char* const filename, char** bufferptr); 21 | extern void SaveFile(const char* const filename, const void* const buffer, int count); 22 | 23 | #endif //**/ FILELIB_H__ 24 | -------------------------------------------------------------------------------- /src/sdhlt/common/hlassert.h: -------------------------------------------------------------------------------- 1 | #ifndef HLASSERT_H__ 2 | #define HLASSERT_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #ifdef SYSTEM_WIN32 10 | #ifdef _DEBUG 11 | 12 | #include "log.h" 13 | 14 | #define assume(exp, message) {if (!(exp)) {Log("\n***** ERROR *****\nAssume '%s' failed\n at %s:%d\n %s\n\n", #exp, __FILE__, __LINE__, message); __asm{int 3} }} 15 | #define hlassert(exp) assume(exp, "") 16 | 17 | #else // _DEBUG 18 | 19 | #define assume(exp, message) {if (!(exp)) {Error("\nAssume '%s' failed\n at %s:%d\n %s\n\n", #exp, __FILE__, __LINE__, message);}} 20 | #define hlassert(exp) 21 | 22 | #endif // _DEBUG 23 | #endif // SYSTEM_WIN32 24 | 25 | #ifdef SYSTEM_POSIX 26 | #ifdef _DEBUG 27 | 28 | #include "log.h" 29 | 30 | #define assume(exp, message) {if (!(exp)) {Log("\n***** ERROR *****\nAssume '%s' failed\n at %s:%d\n %s\n\n", #exp, __FILE__, __LINE__, message); exit(-1); }} 31 | #define hlassert(exp) assume(exp, "") 32 | 33 | #else // _DEBUG 34 | 35 | #define assume(exp, message) {if (!(exp)) {Error("\nAssume '%s' failed\n at %s:%d\n %s\n\n", #exp, __FILE__, __LINE__, message);}} //#define assume(exp, message) {if (!(exp)) {Error("\nAssume '%s' failed\n\n", #exp, __FILE__, __LINE__, message);}} //--vluzacn 36 | #define hlassert(exp) 37 | 38 | #endif // _DEBUG 39 | #endif // SYSTEM_POSIX 40 | 41 | #endif // SYSTEM_POSIX HLASSERT_H__ 42 | -------------------------------------------------------------------------------- /src/sdhlt/common/log.h: -------------------------------------------------------------------------------- 1 | #ifndef LOG_H__ 2 | #define LOG_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #include "mathtypes.h" 10 | #include "messages.h" 11 | 12 | typedef enum 13 | { 14 | DEVELOPER_LEVEL_ALWAYS, 15 | DEVELOPER_LEVEL_ERROR, 16 | DEVELOPER_LEVEL_WARNING, 17 | DEVELOPER_LEVEL_MESSAGE, 18 | DEVELOPER_LEVEL_FLUFF, 19 | DEVELOPER_LEVEL_SPAM, 20 | DEVELOPER_LEVEL_MEGASPAM 21 | } 22 | developer_level_t; 23 | 24 | // 25 | // log.c globals 26 | // 27 | 28 | extern char* g_Program; 29 | extern char g_Mapname[_MAX_PATH]; 30 | extern char g_Wadpath[_MAX_PATH]; //seedee 31 | 32 | #define DEFAULT_DEVELOPER DEVELOPER_LEVEL_ALWAYS 33 | #define DEFAULT_VERBOSE false 34 | #define DEFAULT_LOG true 35 | 36 | extern developer_level_t g_developer; 37 | extern bool g_verbose; 38 | extern bool g_log; 39 | extern unsigned long g_clientid; // Client id of this program 40 | extern unsigned long g_nextclientid; // Client id of next client to spawn from this server 41 | 42 | // 43 | // log.c Functions 44 | // 45 | 46 | extern void ResetTmpFiles(); 47 | extern void ResetLog(); 48 | extern void ResetErrorLog(); 49 | extern void CheckForErrorLog(); 50 | 51 | extern void CDECL OpenLog(int clientid); 52 | extern void CDECL CloseLog(); 53 | extern void WriteLog(const char* const message); 54 | 55 | extern void CheckFatal(); 56 | 57 | extern void CDECL FORMAT_PRINTF(2,3) Developer(developer_level_t level, const char* const message, ...); 58 | 59 | #ifdef _DEBUG 60 | #define IfDebug(x) (x) 61 | #else 62 | #define IfDebug(x) 63 | #endif 64 | 65 | extern const char * Localize (const char *s); 66 | extern void LoadLangFile (const char *name, const char *programpath); 67 | extern int InitConsole(int argc, char **argv); 68 | extern void CDECL FORMAT_PRINTF(1,2) PrintConsole(const char* const message, ...); 69 | extern void CDECL FORMAT_PRINTF(1,2) Verbose(const char* const message, ...); 70 | extern void CDECL FORMAT_PRINTF(1,2) Log(const char* const message, ...); 71 | extern void CDECL FORMAT_PRINTF(1,2) Error(const char* const error, ...); 72 | extern void CDECL FORMAT_PRINTF(2,3) Fatal(assume_msgs msgid, const char* const error, ...); 73 | extern void CDECL FORMAT_PRINTF(1,2) Warning(const char* const warning, ...); 74 | 75 | extern void CDECL FORMAT_PRINTF(1,2) PrintOnce(const char* const message, ...); 76 | 77 | extern void LogStart(const int argc, char** argv); 78 | extern void LogEnd(); 79 | extern void Banner(); 80 | 81 | extern void LogTimeElapsed(float elapsed_time); 82 | 83 | // Should be in hlassert.h, but well so what 84 | extern void hlassume(bool exp, assume_msgs msgid); 85 | 86 | #endif // Should be in hlassert.h, but well so what LOG_H__ 87 | -------------------------------------------------------------------------------- /src/sdhlt/common/mathlib.cpp: -------------------------------------------------------------------------------- 1 | #include "cmdlib.h" 2 | #include "messages.h" 3 | #include "log.h" 4 | #include "hlassert.h" 5 | #include "mathtypes.h" 6 | #include "mathlib.h" 7 | #include "win32fix.h" 8 | 9 | const vec3_t vec3_origin = { 0, 0, 0 }; 10 | 11 | #define IA 16807 12 | #define IM 2147483647 13 | #define IQ 127773 14 | #define IR 2836 15 | #define NTAB 32 16 | #define NDIV (1+(IM-1)/NTAB) 17 | #define MAX_RANDOM_RANGE 0x7FFFFFFFUL 18 | 19 | // fran1 -- return a random floating-point number on the interval [0,1) 20 | // 21 | #define AM (1.0/IM) 22 | #define EPS 1.2e-7 23 | #define RNMX (1.0-EPS) 24 | 25 | static int m_idum = 0; 26 | static int m_iy = 0; 27 | static int m_iv[NTAB]; 28 | 29 | static int GenerateRandomNumber( void ) 30 | { 31 | int j, k; 32 | 33 | if( m_idum <= 0 || !m_iy ) 34 | { 35 | if( -(m_idum) < 1 ) 36 | m_idum = 1; 37 | else m_idum = -(m_idum); 38 | 39 | for( j = NTAB + 7; j >= 0; j-- ) 40 | { 41 | k = (m_idum) / IQ; 42 | m_idum = IA * (m_idum - k * IQ) - IR * k; 43 | 44 | if( m_idum < 0 ) 45 | m_idum += IM; 46 | 47 | if( j < NTAB ) 48 | m_iv[j] = m_idum; 49 | } 50 | 51 | m_iy = m_iv[0]; 52 | } 53 | 54 | k = (m_idum) / IQ; 55 | m_idum = IA * (m_idum - k * IQ) - IR * k; 56 | 57 | if( m_idum < 0 ) 58 | m_idum += IM; 59 | j = m_iy / NDIV; 60 | 61 | // We're seeing some strange memory corruption in the contents of s_pUniformStream. 62 | // Perhaps it's being caused by something writing past the end of this array? 63 | // Bounds-check in release to see if that's the case. 64 | if( j >= NTAB || j < 0 ) 65 | { 66 | Warning( "GenerateRandomNumber had an array overrun: tried to write to element %d of 0..31.\n", j ); 67 | j = ( j % NTAB ) & 0x7fffffff; 68 | } 69 | 70 | m_iy = m_iv[j]; 71 | m_iv[j] = m_idum; 72 | 73 | return m_iy; 74 | } 75 | 76 | float RandomFloat( float flLow, float flHigh ) 77 | { 78 | // float in [0,1) 79 | float fl = AM * GenerateRandomNumber(); 80 | if( fl > RNMX ) fl = RNMX; 81 | 82 | return (fl * ( flHigh - flLow ) ) + flLow; // float in [low,high) 83 | } 84 | 85 | vec_t ColorNormalize (const vec3_t in, vec3_t out) 86 | { 87 | float max, scale; 88 | 89 | max = in[0]; 90 | if (in[1] > max) 91 | max = in[1]; 92 | if (in[2] > max) 93 | max = in[2]; 94 | 95 | if (max == 0) 96 | return 0; 97 | 98 | scale = 255.0 / max; 99 | 100 | VectorScale (in, scale, out); 101 | 102 | return max; 103 | } 104 | 105 | unsigned short FloatToHalf( float v ) 106 | { 107 | unsigned int i = *((unsigned int *)&v); 108 | unsigned int e = (i >> 23) & 0x00ff; 109 | unsigned int m = i & 0x007fffff; 110 | unsigned short h; 111 | 112 | if( e <= 127 - 15 ) 113 | h = ((m | 0x00800000) >> (127 - 14 - e)) >> 13; 114 | else h = (i >> 13) & 0x3fff; 115 | 116 | h |= (i >> 16) & 0xc000; 117 | 118 | return h; 119 | } 120 | 121 | float HalfToFloat( unsigned short h ) 122 | { 123 | unsigned int f = (h << 16) & 0x80000000; 124 | unsigned int em = h & 0x7fff; 125 | 126 | if( em > 0x03ff ) 127 | { 128 | f |= (em << 13) + ((127 - 15) << 23); 129 | } 130 | else 131 | { 132 | unsigned int m = em & 0x03ff; 133 | 134 | if( m != 0 ) 135 | { 136 | unsigned int e = (em >> 10) & 0x1f; 137 | 138 | while(( m & 0x0400 ) == 0 ) 139 | { 140 | m <<= 1; 141 | e--; 142 | } 143 | 144 | m &= 0x3ff; 145 | f |= ((e + (127 - 14)) << 23) | (m << 13); 146 | } 147 | } 148 | 149 | return *((float *)&f); 150 | } -------------------------------------------------------------------------------- /src/sdhlt/common/mathlib.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHLIB_H__ 2 | #define MATHLIB_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #ifdef HAVE_CONFIG_H 10 | #include "config.h" 11 | #endif 12 | 13 | #ifdef STDC_HEADERS 14 | #include 15 | #include 16 | #endif 17 | 18 | #if !defined(qmax) 19 | #define qmax(a,b) (((a) > (b)) ? (a) : (b)) // changed 'max' to 'qmax'. --vluzacn 20 | #endif 21 | 22 | #if !defined(qmin) 23 | #define qmin(a,b) (((a) < (b)) ? (a) : (b)) // changed 'min' to 'qmin'. --vluzacn 24 | #endif 25 | 26 | #define Q_PI 3.14159265358979323846 27 | 28 | extern const vec3_t vec3_origin; 29 | 30 | // HLCSG_HLBSP_DOUBLEPLANE: We could use smaller epsilon for hlcsg and hlbsp (hlcsg and hlbsp use double as vec_t), which will totally eliminate all epsilon errors. But we choose this big epsilon to tolerate the imprecision caused by Hammer. Basically, this is a balance between precision and flexibility. 31 | #define NORMAL_EPSILON 0.00001 32 | #define ON_EPSILON 0.04 // we should ensure that (float)BOGUS_RANGE < (float)(BOGUA_RANGE + 0.2 * ON_EPSILON) 33 | #define EQUAL_EPSILON 0.004 34 | 35 | 36 | // 37 | // Vector Math 38 | // 39 | 40 | 41 | #define DotProduct(x,y) ( (x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2]) 42 | #define CrossProduct(a, b, dest) \ 43 | { \ 44 | (dest)[0] = (a)[1] * (b)[2] - (a)[2] * (b)[1]; \ 45 | (dest)[1] = (a)[2] * (b)[0] - (a)[0] * (b)[2]; \ 46 | (dest)[2] = (a)[0] * (b)[1] - (a)[1] * (b)[0]; \ 47 | } 48 | 49 | #define VectorMidpoint(a,b,c) { (c)[0]=((a)[0]+(b)[0])/2; (c)[1]=((a)[1]+(b)[1])/2; (c)[2]=((a)[2]+(b)[2])/2; } 50 | 51 | #define VectorFill(a,b) { (a)[0]=(b); (a)[1]=(b); (a)[2]=(b);} 52 | #define VectorAvg(a) ( ( (a)[0] + (a)[1] + (a)[2] ) / 3 ) 53 | 54 | #define VectorSubtract(a,b,c) { (c)[0]=(a)[0]-(b)[0]; (c)[1]=(a)[1]-(b)[1]; (c)[2]=(a)[2]-(b)[2]; } 55 | #define VectorAdd(a,b,c) { (c)[0]=(a)[0]+(b)[0]; (c)[1]=(a)[1]+(b)[1]; (c)[2]=(a)[2]+(b)[2]; } 56 | #define VectorMultiply(a,b,c) { (c)[0]=(a)[0]*(b)[0]; (c)[1]=(a)[1]*(b)[1]; (c)[2]=(a)[2]*(b)[2]; } 57 | #define VectorDivide(a,b,c) { (c)[0]=(a)[0]/(b)[0]; (c)[1]=(a)[1]/(b)[1]; (c)[2]=(a)[2]/(b)[2]; } 58 | 59 | #define VectorSubtractVec(a,b,c) { (c)[0]=(a)[0]-(b); (c)[1]=(a)[1]-(b); (c)[2]=(a)[2]-(b); } 60 | #define VectorAddVec(a,b,c) { (c)[0]=(a)[0]+(b); (c)[1]=(a)[1]+(b); (c)[2]=(a)[2]+(b); } 61 | #define VecSubtractVector(a,b,c) { (c)[0]=(a)-(b)[0]; (c)[1]=(a)-(b)[1]; (c)[2]=(a)-(b)[2]; } 62 | #define VecAddVector(a,b,c) { (c)[0]=(a)+(b)[0]; (c)[1]=(a)[(b)[1]; (c)[2]=(a)+(b)[2]; } 63 | 64 | #define VectorMultiplyVec(a,b,c) { (c)[0]=(a)[0]*(b);(c)[1]=(a)[1]*(b);(c)[2]=(a)[2]*(b); } 65 | #define VectorDivideVec(a,b,c) { (c)[0]=(a)[0]/(b);(c)[1]=(a)[1]/(b);(c)[2]=(a)[2]/(b); } 66 | 67 | #define VectorScale(a,b,c) { (c)[0]=(a)[0]*(b);(c)[1]=(a)[1]*(b);(c)[2]=(a)[2]*(b); } 68 | 69 | #define VectorCopy(a,b) { (b)[0]=(a)[0]; (b)[1]=(a)[1]; (b)[2]=(a)[2]; } 70 | #define VectorClear(a) { (a)[0] = (a)[1] = (a)[2] = 0.0; } 71 | 72 | #define VectorMaximum(a) ( qmax( (a)[0], qmax( (a)[1], (a)[2] ) ) ) 73 | #define VectorMinimum(a) ( qmin( (a)[0], qmin( (a)[1], (a)[2] ) ) ) 74 | 75 | #define VectorInverse(a) \ 76 | { \ 77 | (a)[0] = -((a)[0]); \ 78 | (a)[1] = -((a)[1]); \ 79 | (a)[2] = -((a)[2]); \ 80 | } 81 | #define VectorRound(a) floor((a) + 0.5) 82 | #define VectorMA(a, scale, b, dest) \ 83 | { \ 84 | (dest)[0] = (a)[0] + (scale) * (b)[0]; \ 85 | (dest)[1] = (a)[1] + (scale) * (b)[1]; \ 86 | (dest)[2] = (a)[2] + (scale) * (b)[2]; \ 87 | } 88 | #define VectorLength(a) sqrt((double) ((double)((a)[0] * (a)[0]) + (double)( (a)[1] * (a)[1]) + (double)( (a)[2] * (a)[2])) ) 89 | #define VectorCompareMinimum(a,b,c) { (c)[0] = qmin((a)[0], (b)[0]); (c)[1] = qmin((a)[1], (b)[1]); (c)[2] = qmin((a)[2], (b)[2]); } 90 | #define VectorCompareMaximum(a,b,c) { (c)[0] = qmax((a)[0], (b)[0]); (c)[1] = qmax((a)[1], (b)[1]); (c)[2] = qmax((a)[2], (b)[2]); } 91 | 92 | inline vec_t VectorNormalize(vec3_t v) 93 | { 94 | double length; 95 | 96 | length = DotProduct(v, v); 97 | length = sqrt(length); 98 | if (length < NORMAL_EPSILON) 99 | { 100 | VectorClear(v); 101 | return 0.0; 102 | } 103 | 104 | v[0] /= length; 105 | v[1] /= length; 106 | v[2] /= length; 107 | 108 | return length; 109 | } 110 | 111 | inline bool VectorCompare(const vec3_t v1, const vec3_t v2) 112 | { 113 | int i; 114 | 115 | for (i = 0; i < 3; i++) 116 | { 117 | if (fabs(v1[i] - v2[i]) > EQUAL_EPSILON) 118 | { 119 | return false; 120 | } 121 | } 122 | return true; 123 | } 124 | 125 | 126 | // 127 | // Portable bit rotation 128 | // 129 | 130 | 131 | #ifdef SYSTEM_POSIX 132 | #undef rotl 133 | #undef rotr 134 | 135 | inline unsigned int rotl(unsigned value, unsigned int amt) 136 | { 137 | unsigned t1, t2; 138 | 139 | t1 = value >> ((sizeof(unsigned) * CHAR_BIT) - amt); 140 | 141 | t2 = value << amt; 142 | return (t1 | t2); 143 | } 144 | 145 | inline unsigned int rotr(unsigned value, unsigned int amt) 146 | { 147 | unsigned t1, t2; 148 | 149 | t1 = value << ((sizeof(unsigned) * CHAR_BIT) - amt); 150 | 151 | t2 = value >> amt; 152 | return (t1 | t2); 153 | } 154 | #endif 155 | 156 | 157 | // 158 | // Misc 159 | // 160 | 161 | 162 | inline bool isPointFinite(const vec_t* p) 163 | { 164 | if (finite(p[0]) && finite(p[1]) && finite(p[2])) 165 | { 166 | return true; 167 | } 168 | return false; 169 | } 170 | 171 | 172 | // 173 | // Planetype Math 174 | // 175 | 176 | 177 | typedef enum 178 | { 179 | plane_x = 0, 180 | plane_y, 181 | plane_z, 182 | plane_anyx, 183 | plane_anyy, 184 | plane_anyz 185 | } 186 | planetypes; 187 | 188 | #define last_axial plane_z 189 | #define DIR_EPSILON 0.0001 190 | 191 | inline planetypes PlaneTypeForNormal(vec3_t normal) 192 | { 193 | vec_t ax, ay, az; 194 | 195 | ax = fabs(normal[0]); 196 | ay = fabs(normal[1]); 197 | az = fabs(normal[2]); 198 | if (ax > 1.0 - DIR_EPSILON && ay < DIR_EPSILON && az < DIR_EPSILON) 199 | { 200 | return plane_x; 201 | } 202 | 203 | if (ay > 1.0 - DIR_EPSILON && az < DIR_EPSILON && ax < DIR_EPSILON) 204 | { 205 | return plane_y; 206 | } 207 | 208 | if (az > 1.0 - DIR_EPSILON && ax < DIR_EPSILON && ay < DIR_EPSILON) 209 | { 210 | return plane_z; 211 | } 212 | 213 | if ((ax >= ay) && (ax >= az)) 214 | { 215 | return plane_anyx; 216 | } 217 | if ((ay >= ax) && (ay >= az)) 218 | { 219 | return plane_anyy; 220 | } 221 | return plane_anyz; 222 | } 223 | unsigned short FloatToHalf(float v); 224 | float HalfToFloat(unsigned short h); 225 | #endif //MATHLIB_H__ 226 | -------------------------------------------------------------------------------- /src/sdhlt/common/mathtypes.h: -------------------------------------------------------------------------------- 1 | #ifndef MATHTYPES_H__ 2 | #define MATHTYPES_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | typedef unsigned char byte; 10 | 11 | #ifdef DOUBLEVEC_T 12 | typedef double vec_t; 13 | #else 14 | typedef float vec_t; 15 | #endif 16 | typedef vec_t vec3_t[3]; // x,y,z 17 | 18 | #endif //MATHTYPES_H__ 19 | -------------------------------------------------------------------------------- /src/sdhlt/common/messages.h: -------------------------------------------------------------------------------- 1 | #ifndef MESSAGES_H__ 2 | #define MESSAGES_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | typedef struct 10 | { 11 | const char* title; 12 | const char* text; 13 | const char* howto; 14 | } 15 | MessageTable_t; 16 | 17 | typedef enum 18 | { 19 | assume_first = 0, 20 | 21 | // generic 22 | assume_NoMemory, 23 | assume_ValidPointer, 24 | assume_BadWorkcount, 25 | 26 | // qcsg 27 | assume_MISSING_BRACKET_IN_TEXTUREDEF, 28 | assume_PLANE_WITH_NO_NORMAL, 29 | assume_BRUSH_WITH_COPLANAR_FACES, 30 | assume_BRUSH_OUTSIDE_WORLD, 31 | assume_MIXED_FACE_CONTENTS, 32 | assume_BRUSH_NOT_ALLOWED_IN_WORLD, 33 | assume_BRUSH_NOT_ALLOWED_IN_ENTITY, 34 | assume_NO_VISIBILE_BRUSHES, 35 | assume_ONLY_ORIGIN, 36 | assume_COULD_NOT_FIND_WAD, 37 | assume_MAX_TRIANGLES, 38 | assume_MAX_SWITCHED_LIGHTS, 39 | assume_MAX_TEXFILES, 40 | 41 | // qbsp 42 | assume_LEAK, 43 | assume_MAX_LEAF_FACES, 44 | assume_MAX_WEDGES, 45 | assume_MAX_WVERTS, 46 | assume_MAX_SUPERFACEEDGES, 47 | assume_EmptySolid, 48 | 49 | // vis 50 | assume_LEAF_PORTAL_SAW_INTO_LEAF, 51 | assume_MAX_PORTALS_ON_LEAF, 52 | assume_VALID_NETVIS_STATE, 53 | 54 | // qrad 55 | assume_MAX_TEXLIGHTS, 56 | assume_MAX_PATCHES, 57 | assume_TransferError, 58 | assume_BadSurfaceExtents, 59 | assume_MalformedTextureFace, 60 | assume_NoLights, 61 | assume_BadLightType, 62 | assume_MAX_SINGLEMAP, 63 | 64 | // common 65 | assume_THREAD_ERROR, 66 | assume_MAX_MAP_PLANES, 67 | assume_MAX_MAP_TEXTURES, 68 | assume_MAX_MAP_MIPTEX, 69 | assume_MAX_MAP_TEXINFO, 70 | assume_MAX_MAP_SIDES, 71 | assume_MAX_MAP_BRUSHES, 72 | assume_MAX_MAP_ENTITIES, 73 | assume_MAX_ENGINE_ENTITIES, 74 | assume_MAX_MAP_MODELS, 75 | assume_MAX_MAP_VERTS, 76 | assume_MAX_MAP_EDGES, 77 | assume_MAX_MAP_CLIPNODES, 78 | assume_MAX_MAP_MARKSURFACES, 79 | assume_MAX_MAP_FACES, 80 | assume_MAX_MAP_SURFEDGES, 81 | assume_MAX_MAP_NODES, 82 | assume_COMPRESSVIS_OVERFLOW, 83 | assume_DECOMPRESSVIS_OVERFLOW, 84 | assume_MAX_MAP_LEAFS, 85 | // AJM: added in 86 | assume_TOOL_CANCEL, 87 | assume_GENERIC, 88 | // KGP: added 89 | assume_MAX_MAP_LIGHTING, 90 | assume_MAX_INTERNAL_MAP_PLANES, 91 | assume_COULD_NOT_LOCATE_WAD, 92 | assume_NO_EXTENT_FILE, 93 | 94 | assume_last 95 | } 96 | assume_msgs; 97 | 98 | extern const MessageTable_t* GetAssume(assume_msgs id); 99 | 100 | #endif // commonc MESSAGES_H__ 101 | -------------------------------------------------------------------------------- /src/sdhlt/common/resourcelock.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SYSTEM_WIN32 2 | #define WIN32_LEAN_AND_MEAN 3 | #include 4 | #endif 5 | 6 | #include "cmdlib.h" 7 | #include "messages.h" 8 | #include "log.h" 9 | #include "blockmem.h" 10 | 11 | #include "resourcelock.h" 12 | 13 | #ifdef SYSTEM_WIN32 14 | 15 | typedef struct 16 | { 17 | HANDLE Mutex; 18 | } 19 | ResourceLock_t; 20 | 21 | void* CreateResourceLock(int LockNumber) 22 | { 23 | char lockname[_MAX_PATH]; 24 | char mapname[_MAX_PATH]; 25 | ResourceLock_t* lock = (ResourceLock_t*)Alloc(sizeof(ResourceLock_t)); 26 | 27 | ExtractFile(g_Mapname, mapname); 28 | safe_snprintf(lockname, _MAX_PATH, "%d%s", LockNumber, mapname); 29 | 30 | lock->Mutex = CreateMutex(NULL, FALSE, lockname); 31 | 32 | if (lock->Mutex == NULL) 33 | { 34 | LPVOID lpMsgBuf; 35 | 36 | Log("lock->Mutex is NULL! [%s]", lockname); 37 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 38 | FORMAT_MESSAGE_FROM_SYSTEM | 39 | FORMAT_MESSAGE_IGNORE_INSERTS, 40 | NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) & lpMsgBuf, 0, NULL); 41 | Error((LPCTSTR)lpMsgBuf); 42 | } 43 | 44 | WaitForSingleObject(lock->Mutex, INFINITE); 45 | 46 | return lock; 47 | } 48 | 49 | void ReleaseResourceLock(void** lock) 50 | { 51 | ResourceLock_t* lockTmp = (ResourceLock_t*)*lock; 52 | 53 | if (!ReleaseMutex(lockTmp->Mutex)) 54 | { 55 | Error("Failed to release mutex"); 56 | } 57 | Free(lockTmp); 58 | *lock = NULL; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/sdhlt/common/resourcelock.h: -------------------------------------------------------------------------------- 1 | #ifndef RESOURCELOCK_H__ 2 | #define RESOURCELOCK_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | extern void* CreateResourceLock(int LockNumber); 10 | extern void ReleaseResourceLock(void** lock); 11 | 12 | #endif // RESOURCE_LOCK_H__ 13 | -------------------------------------------------------------------------------- /src/sdhlt/common/scriplib.h: -------------------------------------------------------------------------------- 1 | #ifndef SCRIPLIB_H__ 2 | #define SCRIPLIB_H__ 3 | 4 | #if _MSC_VER >= 1000 5 | #pragma once 6 | #endif 7 | 8 | #include "cmdlib.h" 9 | 10 | #define MAXTOKEN 4096 11 | 12 | extern char g_token[MAXTOKEN]; 13 | extern char g_TXcommand; // global for Quark maps texture alignment hack 14 | 15 | extern void LoadScriptFile(const char* const filename); 16 | extern void ParseFromMemory(char* buffer, int size); 17 | 18 | extern bool GetToken(bool crossline); 19 | extern void UnGetToken(); 20 | extern bool TokenAvailable(); 21 | 22 | #define MAX_WAD_PATHS 42 23 | extern char g_szWadPaths[MAX_WAD_PATHS][_MAX_PATH]; 24 | extern int g_iNumWadPaths; 25 | 26 | #endif //**/ SCRIPLIB_H__ 27 | -------------------------------------------------------------------------------- /src/sdhlt/common/stringlib.h: -------------------------------------------------------------------------------- 1 | //======================================================================= 2 | // Copyright (C) XashXT Group 2011 3 | // stringlib.h - safety string routines 4 | //======================================================================= 5 | #ifndef STRINGLIB_H 6 | #define STRINGLIB_H 7 | 8 | #include 9 | #include 10 | 11 | extern void Q_strnupr( const char *in, char *out, size_t size_out ); 12 | extern void Q_strnlwr( const char *in, char *out, size_t size_out ); 13 | extern bool Q_isdigit( const char *str ); 14 | extern int Q_strlen( const char *string ); 15 | extern char Q_toupper( const char in ); 16 | extern char Q_tolower( const char in ); 17 | extern size_t Q_strncat( char *dst, const char *src, size_t size ); 18 | extern size_t Q_strncpy( char *dst, const char *src, size_t size ); 19 | extern char *copystring( const char *s ); // don't forget release memory after use 20 | #define freestring( a ) (delete [](a)) 21 | char *Q_strchr( const char *s, char c ); 22 | char *Q_strrchr( const char *s, char c ); 23 | int Q_strnicmp( const char *s1, const char *s2, int n ); 24 | int Q_strncmp( const char *s1, const char *s2, int n ); 25 | char *Q_strstr( const char *string, const char *string2 ); 26 | char *Q_stristr( const char *string, const char *string2 ); 27 | int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list args ); 28 | int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ); 29 | int Q_sprintf( char *buffer, const char *format, ... ); 30 | char *Q_pretifymem( float value, int digitsafterdecimal ); 31 | void _Q_timestring( int seconds, char *msg, size_t size ); 32 | char *va( const char *format, ... ); 33 | void Q_getwd( char *out, size_t len ); 34 | 35 | #define Q_strupr( in, out ) Q_strnupr( in, out, 99999 ) 36 | #define Q_strlwr( int, out ) Q_strnlwr( in, out, 99999 ) 37 | #define Q_strcat( dst, src ) Q_strncat( dst, src, 99999 ) 38 | #define Q_strcpy( dst, src ) Q_strncpy( dst, src, 99999 ) 39 | #define Q_stricmp( s1, s2 ) Q_strnicmp( s1, s2, 99999 ) 40 | #define Q_strcmp( s1, s2 ) Q_strncmp( s1, s2, 99999 ) 41 | #define Q_vsprintf( buffer, format, args ) Q_vsnprintf( buffer, 99999, format, args ) 42 | #define Q_memprint( val) Q_pretifymem( val, 2 ) 43 | #define Q_timestring( a, b ) _Q_timestring( a, b, sizeof( b )) 44 | 45 | char *COM_ParseFile( char *data, char *token ); 46 | 47 | #endif//STRINGLIB_H -------------------------------------------------------------------------------- /src/sdhlt/common/threads.h: -------------------------------------------------------------------------------- 1 | #ifndef THREADS_H__ 2 | #define THREADS_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #define MAX_THREADS 64 10 | 11 | typedef enum 12 | { 13 | eThreadPriorityLow = -1, 14 | eThreadPriorityNormal, 15 | eThreadPriorityHigh 16 | } 17 | q_threadpriority; 18 | 19 | typedef void (*q_threadfunction) (int); 20 | 21 | #ifdef SYSTEM_WIN32 22 | #define DEFAULT_NUMTHREADS -1 23 | #endif 24 | #ifdef SYSTEM_POSIX 25 | #define DEFAULT_NUMTHREADS 1 26 | #endif 27 | 28 | #define DEFAULT_THREAD_PRIORITY eThreadPriorityNormal 29 | 30 | extern int g_numthreads; 31 | extern q_threadpriority g_threadpriority; 32 | 33 | extern void ThreadSetPriority(q_threadpriority type); 34 | extern void ThreadSetDefault(); 35 | extern int GetThreadWork(); 36 | extern void ThreadLock(); 37 | extern void ThreadUnlock(); 38 | 39 | extern void RunThreadsOnIndividual(int workcnt, bool showpacifier, q_threadfunction); 40 | extern void RunThreadsOn(int workcnt, bool showpacifier, q_threadfunction); 41 | 42 | #ifdef ZHLT_NETVIS 43 | extern void threads_InitCrit(); 44 | extern void threads_UninitCrit(); 45 | #endif 46 | 47 | #define NamedRunThreadsOn(n,p,f) { Log("%s\n", Localize(#f ":")); RunThreadsOn(n,p,f); } 48 | #define NamedRunThreadsOnIndividual(n,p,f) { Log("%s\n", Localize(#f ":")); RunThreadsOnIndividual(n,p,f); } 49 | 50 | #endif //**/ THREADS_H__ 51 | -------------------------------------------------------------------------------- /src/sdhlt/common/win32fix.h: -------------------------------------------------------------------------------- 1 | #ifndef WIN32FIX_H__ 2 | #define WIN32FIX_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #include 10 | 11 | ///////////////////////////// 12 | #ifdef SYSTEM_WIN32 13 | 14 | #define alloca _alloca 15 | 16 | #define strncasecmp _strnicmp 17 | #define strcasecmp _stricmp 18 | 19 | #if _MSC_VER < 1400 // AdamR: Ignore this definition in Visual Studio 2005 and later 20 | #define snprintf _snprintf 21 | #define vsnprintf _vsnprintf 22 | #endif 23 | 24 | #define finite _finite 25 | 26 | #define rotl _rotl 27 | #define rotr _rotr 28 | 29 | #undef STDCALL 30 | #undef FASTCALL 31 | #undef CDECL 32 | 33 | #define STDCALL __stdcall 34 | #define FASTCALL __fastcall 35 | #define CDECL __cdecl 36 | 37 | #define INLINE __inline 38 | 39 | #define FORCEINLINE __forceinline //--vluzacn 40 | #define FORMAT_PRINTF(STRING_INDEX,FIRST_TO_CHECK) //--vluzacn 41 | 42 | #endif 43 | ///////////////////////////// 44 | 45 | ///////////////////////////// 46 | #ifdef SYSTEM_POSIX 47 | #define _MAX_PATH 4096 48 | #define _MAX_DRIVE 4096 49 | #define _MAX_DIR 4096 50 | #define _MAX_FNAME 4096 51 | #define _MAX_EXT 4096 52 | 53 | #define STDCALL 54 | #define FASTCALL 55 | #define CDECL 56 | 57 | #define INLINE inline 58 | 59 | #define _strdup strdup //--vluzacn 60 | #define _strupr strupr //--vluzacn 61 | #define _strlwr strlwr //--vluzacn 62 | #define _open open //--vluzacn 63 | #define _read read //--vluzacn 64 | #define _close close //--vluzacn 65 | #define _unlink unlink //--vluzacn 66 | 67 | #define FORCEINLINE __inline__ __attribute__((always_inline)) //--vluzacn 68 | #define FORMAT_PRINTF(STRING_INDEX,FIRST_TO_CHECK) __attribute__((format (printf, STRING_INDEX, FIRST_TO_CHECK))) //--vluzacn 69 | 70 | #endif 71 | ///////////////////////////// 72 | 73 | #endif ///////////////////////////// WIN32FIX_H__ 74 | -------------------------------------------------------------------------------- /src/sdhlt/common/winding.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDING_H__ 2 | #define WINDING_H__ 3 | #include "cmdlib.h" //--vluzacn 4 | 5 | #if _MSC_VER >= 1000 6 | #pragma once 7 | #endif 8 | 9 | #include "basictypes.h" 10 | #include "mathtypes.h" 11 | #include "win32fix.h" 12 | #include "mathlib.h" 13 | #include "bspfile.h" 14 | #include "boundingbox.h" 15 | 16 | #define MAX_POINTS_ON_WINDING 128 17 | // TODO: FIX THIS STUPID SHIT (MAX_POINTS_ON_WINDING) 18 | 19 | #define BASE_WINDING_DISTANCE 9000 20 | 21 | #define SIDE_FRONT 0 22 | #define SIDE_ON 2 23 | #define SIDE_BACK 1 24 | #define SIDE_CROSS -2 25 | 26 | #ifdef SDHLBSP //seedee 27 | #ifndef DOUBLEVEC_T 28 | #error you must add -dDOUBLEVEC_T to the project! 29 | #endif 30 | #define dplane_t plane_t 31 | #define g_dplanes g_mapplanes 32 | typedef struct 33 | { 34 | vec3_t normal; 35 | vec3_t unused_origin; 36 | vec_t dist; 37 | planetypes type; 38 | } dplane_t; 39 | extern dplane_t g_dplanes[MAX_INTERNAL_MAP_PLANES]; 40 | #endif 41 | class Winding 42 | { 43 | public: 44 | // General Functions 45 | void Print() const; 46 | void getPlane(dplane_t& plane) const; 47 | void getPlane(vec3_t& normal, vec_t& dist) const; 48 | vec_t getArea() const; 49 | void getBounds(BoundingBox& bounds) const; 50 | void getBounds(vec3_t& mins, vec3_t& maxs) const; 51 | void getCenter(vec3_t& center) const; 52 | Winding* Copy() const; 53 | void Check( 54 | vec_t epsilon = ON_EPSILON 55 | ) const; // Developer check for validity 56 | bool Valid() const; // Runtime/user/normal check for validity 57 | void addPoint(const vec3_t newpoint); 58 | void insertPoint(const vec3_t newpoint, const unsigned int offset); 59 | 60 | // Specialized Functions 61 | void RemoveColinearPoints( 62 | vec_t epsilon = ON_EPSILON 63 | ); 64 | bool Clip(const dplane_t& split, bool keepon 65 | , vec_t epsilon = ON_EPSILON 66 | ); // For hlbsp 67 | void Clip(const dplane_t& split, Winding** front, Winding** back 68 | , vec_t epsilon = ON_EPSILON 69 | ); 70 | void Clip(const vec3_t normal, const vec_t dist, Winding** front, Winding** back 71 | , vec_t epsilon = ON_EPSILON 72 | ); 73 | bool Chop(const vec3_t normal, const vec_t dist 74 | , vec_t epsilon = ON_EPSILON 75 | ); 76 | void Divide(const dplane_t& split, Winding** front, Winding** back 77 | , vec_t epsilon = ON_EPSILON 78 | ); 79 | int WindingOnPlaneSide(const vec3_t normal, const vec_t dist 80 | , vec_t epsilon = ON_EPSILON 81 | ); 82 | void CopyPoints(vec3_t *points, int &numpoints); 83 | 84 | void initFromPoints(vec3_t *points, UINT32 numpoints); 85 | void Reset(void); // Resets the structure 86 | 87 | protected: 88 | void resize(UINT32 newsize); 89 | 90 | public: 91 | // Construction 92 | Winding(); // Do nothing :) 93 | Winding(vec3_t *points, UINT32 numpoints); // Create from raw points 94 | Winding(const dface_t& face 95 | , vec_t epsilon = ON_EPSILON 96 | ); 97 | Winding(const dplane_t& face); 98 | Winding(const vec3_t normal, const vec_t dist); 99 | Winding(UINT32 points); 100 | Winding(const Winding& other); 101 | virtual ~Winding(); 102 | Winding& operator=(const Winding& other); 103 | 104 | // Misc 105 | private: 106 | void initFromPlane(const vec3_t normal, const vec_t dist); 107 | 108 | public: 109 | // Data 110 | UINT32 m_NumPoints; 111 | vec3_t* m_Points; 112 | protected: 113 | UINT32 m_MaxPoints; 114 | }; 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLBSP/merge.cpp: -------------------------------------------------------------------------------- 1 | #include "bsp5.h" 2 | 3 | // TryMerge 4 | // MergeFaceToList 5 | // FreeMergeListScraps 6 | // MergePlaneFaces 7 | // MergeAll 8 | 9 | #define CONTINUOUS_EPSILON ON_EPSILON 10 | 11 | // ===================================================================================== 12 | // TryMerge 13 | // If two polygons share a common edge and the edges that meet at the 14 | // common points are both inside the other polygons, merge them 15 | // Returns NULL if the faces couldn't be merged, or the new face. 16 | // The originals will NOT be freed. 17 | // ===================================================================================== 18 | static face_t* TryMerge(face_t* f1, face_t* f2) 19 | { 20 | vec_t* p1; 21 | vec_t* p2; 22 | vec_t* p3; 23 | vec_t* p4; 24 | vec_t* back; 25 | face_t* newf; 26 | int i; 27 | int j; 28 | int k; 29 | int l; 30 | vec3_t normal; 31 | vec3_t delta; 32 | vec3_t planenormal; 33 | vec_t dot; 34 | dplane_t* plane; 35 | bool keep1; 36 | bool keep2; 37 | 38 | if (f1->numpoints == -1 || f2->numpoints == -1) 39 | { 40 | return NULL; 41 | } 42 | if (f1->texturenum != f2->texturenum) 43 | { 44 | return NULL; 45 | } 46 | if (f1->contents != f2->contents) 47 | { 48 | return NULL; 49 | } 50 | if (f1->planenum != f2->planenum) 51 | { 52 | return NULL; 53 | } 54 | if (f1->facestyle != f2->facestyle) 55 | { 56 | return NULL; 57 | } 58 | if (f1->detaillevel != f2->detaillevel) 59 | { 60 | return NULL; 61 | } 62 | 63 | // 64 | // find a common edge 65 | // 66 | p1 = p2 = NULL; // shut up the compiler 67 | j = 0; 68 | 69 | for (i = 0; i < f1->numpoints; i++) 70 | { 71 | p1 = f1->pts[i]; 72 | p2 = f1->pts[(i + 1) % f1->numpoints]; 73 | for (j = 0; j < f2->numpoints; j++) 74 | { 75 | p3 = f2->pts[j]; 76 | p4 = f2->pts[(j + 1) % f2->numpoints]; 77 | for (k = 0; k < 3; k++) 78 | { 79 | if (fabs(p1[k] - p4[k]) > ON_EPSILON) 80 | { 81 | break; 82 | } 83 | if (fabs(p2[k] - p3[k]) > ON_EPSILON) 84 | { 85 | break; 86 | } 87 | } 88 | if (k == 3) 89 | { 90 | break; 91 | } 92 | } 93 | if (j < f2->numpoints) 94 | { 95 | break; 96 | } 97 | } 98 | 99 | if (i == f1->numpoints) 100 | { 101 | return NULL; // no matching edges 102 | } 103 | 104 | // 105 | // check slope of connected lines 106 | // if the slopes are colinear, the point can be removed 107 | // 108 | plane = &g_dplanes[f1->planenum]; 109 | VectorCopy(plane->normal, planenormal); 110 | 111 | back = f1->pts[(i + f1->numpoints - 1) % f1->numpoints]; 112 | VectorSubtract(p1, back, delta); 113 | CrossProduct(planenormal, delta, normal); 114 | VectorNormalize(normal); 115 | 116 | back = f2->pts[(j + 2) % f2->numpoints]; 117 | VectorSubtract(back, p1, delta); 118 | dot = DotProduct(delta, normal); 119 | if (dot > CONTINUOUS_EPSILON) 120 | { 121 | return NULL; // not a convex polygon 122 | } 123 | keep1 = dot < -CONTINUOUS_EPSILON; 124 | 125 | back = f1->pts[(i + 2) % f1->numpoints]; 126 | VectorSubtract(back, p2, delta); 127 | CrossProduct(planenormal, delta, normal); 128 | VectorNormalize(normal); 129 | 130 | back = f2->pts[(j + f2->numpoints - 1) % f2->numpoints]; 131 | VectorSubtract(back, p2, delta); 132 | dot = DotProduct(delta, normal); 133 | if (dot > CONTINUOUS_EPSILON) 134 | { 135 | return NULL; // not a convex polygon 136 | } 137 | keep2 = dot < -CONTINUOUS_EPSILON; 138 | 139 | // 140 | // build the new polygon 141 | // 142 | if (f1->numpoints + f2->numpoints > MAXEDGES) 143 | { 144 | // Error ("TryMerge: too many edges!"); 145 | return NULL; 146 | } 147 | 148 | newf = NewFaceFromFace(f1); 149 | 150 | // copy first polygon 151 | for (k = (i + 1) % f1->numpoints; k != i; k = (k + 1) % f1->numpoints) 152 | { 153 | if (k == (i + 1) % f1->numpoints && !keep2) 154 | { 155 | continue; 156 | } 157 | 158 | VectorCopy(f1->pts[k], newf->pts[newf->numpoints]); 159 | newf->numpoints++; 160 | } 161 | 162 | // copy second polygon 163 | for (l = (j + 1) % f2->numpoints; l != j; l = (l + 1) % f2->numpoints) 164 | { 165 | if (l == (j + 1) % f2->numpoints && !keep1) 166 | { 167 | continue; 168 | } 169 | VectorCopy(f2->pts[l], newf->pts[newf->numpoints]); 170 | newf->numpoints++; 171 | } 172 | 173 | return newf; 174 | } 175 | 176 | // ===================================================================================== 177 | // MergeFaceToList 178 | // ===================================================================================== 179 | static face_t* MergeFaceToList(face_t* face, face_t* list) 180 | { 181 | face_t* newf; 182 | face_t* f; 183 | 184 | for (f = list; f; f = f->next) 185 | { 186 | //CheckColinear (f); 187 | newf = TryMerge(face, f); 188 | if (!newf) 189 | { 190 | continue; 191 | } 192 | FreeFace(face); 193 | f->numpoints = -1; // merged out 194 | return MergeFaceToList(newf, list); 195 | } 196 | 197 | // didn't merge, so add at start 198 | face->next = list; 199 | return face; 200 | } 201 | 202 | // ===================================================================================== 203 | // FreeMergeListScraps 204 | // ===================================================================================== 205 | static face_t* FreeMergeListScraps(face_t* merged) 206 | { 207 | face_t* head; 208 | face_t* next; 209 | 210 | head = NULL; 211 | for (; merged; merged = next) 212 | { 213 | next = merged->next; 214 | if (merged->numpoints == -1) 215 | { 216 | FreeFace(merged); 217 | } 218 | else 219 | { 220 | merged->next = head; 221 | head = merged; 222 | } 223 | } 224 | 225 | return head; 226 | } 227 | 228 | // ===================================================================================== 229 | // MergePlaneFaces 230 | // ===================================================================================== 231 | void MergePlaneFaces(surface_t* plane) 232 | { 233 | face_t* f1; 234 | face_t* next; 235 | face_t* merged; 236 | 237 | merged = NULL; 238 | 239 | for (f1 = plane->faces; f1; f1 = next) 240 | { 241 | next = f1->next; 242 | merged = MergeFaceToList(f1, merged); 243 | } 244 | 245 | // chain all of the non-empty faces to the plane 246 | plane->faces = FreeMergeListScraps(merged); 247 | } 248 | 249 | // ===================================================================================== 250 | // MergeAll 251 | // ===================================================================================== 252 | void MergeAll(surface_t* surfhead) 253 | { 254 | surface_t* surf; 255 | int mergefaces; 256 | face_t* f; 257 | 258 | Verbose("---- MergeAll ----\n"); 259 | 260 | mergefaces = 0; 261 | for (surf = surfhead; surf; surf = surf->next) 262 | { 263 | MergePlaneFaces(surf); 264 | for (f = surf->faces; f; f = f->next) 265 | { 266 | mergefaces++; 267 | } 268 | } 269 | 270 | Verbose("%i mergefaces\n", mergefaces); 271 | } 272 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLBSP/sdHLBSP.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {34a14629-6c37-476f-ba39-948b5dced614} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90 7 | 8 | 9 | {46b3a3bf-b611-48da-acfe-72baee07a4a2} 10 | 11 | 12 | {787e705b-96d4-4178-b5d0-07e4b95ccb7c} 13 | h;hpp;hxx;hm;inl;fi;fd 14 | 15 | 16 | {47e82a67-8aea-4014-84d1-7495aceb84c2} 17 | ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe 18 | 19 | 20 | 21 | 22 | Source Files\common 23 | 24 | 25 | Source Files\common 26 | 27 | 28 | Source Files\common 29 | 30 | 31 | Source Files\common 32 | 33 | 34 | Source Files\common 35 | 36 | 37 | Source Files\common 38 | 39 | 40 | Source Files\common 41 | 42 | 43 | Source Files\common 44 | 45 | 46 | Source Files\common 47 | 48 | 49 | Source Files\common 50 | 51 | 52 | Source Files\common 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/ansitoutf8.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "csg.h" 3 | 4 | #ifdef HLCSG_GAMETEXTMESSAGE_UTF8 5 | #define WIN32_LEAN_AND_MEAN 6 | #include 7 | 8 | char * ANSItoUTF8 (const char *string) 9 | { 10 | int len; 11 | char *utf8; 12 | wchar_t *unicode; 13 | len = MultiByteToWideChar (CP_ACP, 0, string, -1, NULL, 0); 14 | unicode = (wchar_t *)calloc (len+1, sizeof(wchar_t)); 15 | MultiByteToWideChar (CP_ACP, 0, string, -1, unicode, len); 16 | len = WideCharToMultiByte (CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL); 17 | utf8 = (char *)calloc (len+1, sizeof(char)); 18 | WideCharToMultiByte (CP_UTF8, 0, unicode, -1, utf8, len, NULL, NULL); 19 | free (unicode); 20 | return utf8; 21 | } 22 | #endif 23 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/hullfile.cpp: -------------------------------------------------------------------------------- 1 | #include "csg.h" 2 | 3 | vec3_t g_hull_size[NUM_HULLS][2] = 4 | { 5 | {// 0x0x0 6 | {0, 0, 0}, {0, 0, 0} 7 | } 8 | , 9 | {// 32x32x72 10 | {-16, -16, -36}, {16, 16, 36} 11 | } 12 | , 13 | {// 64x64x64 14 | {-32, -32, -32}, {32, 32, 32} 15 | } 16 | , 17 | {// 32x32x36 18 | {-16, -16, -18}, {16, 16, 18} 19 | } 20 | }; 21 | 22 | void LoadHullfile(const char* filename) 23 | { 24 | if (filename == NULL) 25 | { 26 | return; 27 | } 28 | 29 | if (q_exists(filename)) 30 | { 31 | Log("Loading hull definitions from '%s'\n", filename); 32 | } 33 | else 34 | { 35 | Error("Could not find hull definition file '%s'\n", filename); 36 | return; 37 | } 38 | 39 | float x1,y1,z1; 40 | float x2,y2,z2; 41 | char magic; 42 | 43 | FILE* file = fopen(filename, "r"); 44 | 45 | int count; 46 | int i; 47 | 48 | magic = (char)fgetc(file); 49 | rewind(file); 50 | 51 | if(magic == '(') 52 | { // Test for old-style hull-file 53 | 54 | for (i=0; i < NUM_HULLS; i++) 55 | { 56 | count = fscanf(file, "( %f %f %f ) ( %f %f %f )\n", &x1, &y1, &z1, &x2, &y2, &z2); 57 | if (count != 6) 58 | { 59 | Error("Could not parse old hull definition file '%s' (%d, %d)\n", filename, i, count); 60 | } 61 | 62 | g_hull_size[i][0][0] = x1; 63 | g_hull_size[i][0][1] = y1; 64 | g_hull_size[i][0][2] = z1; 65 | 66 | g_hull_size[i][1][0] = x2; 67 | g_hull_size[i][1][1] = y2; 68 | g_hull_size[i][1][2] = z2; 69 | 70 | } 71 | 72 | } 73 | else 74 | { 75 | // Skip hull 0 (visibile polygons) 76 | for (i=1; i 6 | #include 7 | using namespace std; 8 | 9 | set< string > g_invisible_items; 10 | 11 | void properties_initialize(const char* filename) 12 | { 13 | if (filename == NULL) 14 | { return; } 15 | 16 | if (q_exists(filename)) 17 | { Log("Loading null entity list from '%s'\n", filename); } 18 | else 19 | { 20 | Error("Could not find null entity list file '%s'\n", filename); 21 | return; 22 | } 23 | 24 | ifstream file(filename,ios::in); 25 | if(!file) 26 | { 27 | file.close(); 28 | return; 29 | } 30 | 31 | 32 | //begin reading list of items 33 | char line[MAX_VAL]; //MAX_VALUE //vluzacn 34 | memset(line,0,sizeof(char)*4096); 35 | while(!file.eof()) 36 | { 37 | string str; 38 | getline(file,str); 39 | { //--vluzacn 40 | char *s = strdup (str.c_str ()); 41 | int i; 42 | for (i = 0; s[i] != '\0'; i++) 43 | { 44 | if (s[i] == '\n' || s[i] == '\r') 45 | { 46 | s[i] = '\0'; 47 | } 48 | } 49 | str.assign (s); 50 | free (s); 51 | } 52 | if(str.size() < 1) 53 | { continue; } 54 | g_invisible_items.insert(str); 55 | } 56 | file.close(); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/sdHLCSG.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {9711f31f-2bf7-4a75-bcac-07a3d63cde1a} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90 7 | 8 | 9 | {5de8d4ab-7f83-4409-9b7a-72d405820b95} 10 | 11 | 12 | {8844422d-8c81-4887-b6b4-330edaccfdbe} 13 | h;hpp;hxx;hm;inl;fi;fd 14 | 15 | 16 | 17 | 18 | Source Files\common 19 | 20 | 21 | Source Files\common 22 | 23 | 24 | Source Files\common 25 | 26 | 27 | Source Files\common 28 | 29 | 30 | Source Files\common 31 | 32 | 33 | Source Files\common 34 | 35 | 36 | Source Files\common 37 | 38 | 39 | Source Files\common 40 | 41 | 42 | Source Files\common 43 | 44 | 45 | Source Files\common 46 | 47 | 48 | Source Files\common 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | 82 | 83 | Header Files 84 | 85 | 86 | Header Files 87 | 88 | 89 | Header Files 90 | 91 | 92 | Header Files 93 | 94 | 95 | Header Files 96 | 97 | 98 | Header Files 99 | 100 | 101 | Header Files 102 | 103 | 104 | Header Files 105 | 106 | 107 | Header Files 108 | 109 | 110 | Header Files 111 | 112 | 113 | Header Files 114 | 115 | 116 | Header Files 117 | 118 | 119 | Header Files 120 | 121 | 122 | Header Files 123 | 124 | 125 | Header Files 126 | 127 | 128 | Header Files 129 | 130 | 131 | Header Files 132 | 133 | 134 | Header Files 135 | 136 | 137 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/wadcfg.cpp: -------------------------------------------------------------------------------- 1 | // AJM: ADDED THIS ENTIRE FILE IN 2 | 3 | #include "csg.h" 4 | void LoadWadconfig (const char *filename, const char *configname) 5 | { 6 | char filenameOnly[_MAX_PATH]; 7 | size_t filenameLength = strlen(filename); 8 | strncpy(filenameOnly, filename, filenameLength); 9 | filenameOnly[filenameLength] = '\0'; //Null terminate 10 | auto pos = std::string(filenameOnly).find_last_of("/\\"); 11 | 12 | if (pos != std::string::npos) // Copy everything after the last slash to the beginning of filenameOnly 13 | { 14 | std::string temp(filenameOnly + pos + 1); 15 | strncpy(filenameOnly, temp.c_str(), _MAX_PATH); 16 | filenameOnly[temp.size()] = '\0'; 17 | } 18 | Log("Loading wadconfig %s from '%s'\n", configname, filenameOnly); 19 | Log("--------------------------------------\n"); 20 | int wadconfigsFound = 0; 21 | int wadPathsFound = 0; 22 | int filesize; 23 | char *file; 24 | filesize = LoadFile(filename, &file); //Load file and store it's size 25 | ParseFromMemory (file, filesize); //Parse contents from memory 26 | 27 | while (GetToken (true)) //Loop through file 28 | { 29 | bool skip = true; //Skip until the -wadconfig configname is found 30 | 31 | if (!strcasecmp (g_token, configname)) //If we find configname line 32 | { 33 | skip = false; 34 | wadconfigsFound++; 35 | } 36 | if (!GetToken (true) || strcasecmp(g_token, "{")) //If next line is not an opening bracket 37 | { 38 | Error ("Parsing %s (missing '{' opening bracket in '%s' config)\n", filenameOnly, configname); 39 | } 40 | while (1) //Loop through content of braces 41 | { 42 | if (!GetToken (true)) 43 | { 44 | Error("Parsing '%s': unexpected EOF in '%s'\n", filenameOnly, configname); 45 | } 46 | if (!strcasecmp (g_token, "}")) //If we find closing bracket 47 | { 48 | break; 49 | } 50 | if (skip) 51 | { 52 | continue; 53 | } 54 | bool include = false; 55 | if (!strcasecmp (g_token, "include")) 56 | { 57 | Log("[include] "); 58 | include = true; 59 | 60 | if (!GetToken (true)) 61 | { 62 | Error ("Parsing '%s': unexpected EOF in '%s'\n", filenameOnly, configname); 63 | } 64 | } 65 | Log ("%s\n", g_token); 66 | if (g_iNumWadPaths >= MAX_WADPATHS) 67 | { 68 | Error ("Parsing '%s': too many wad files (%i/%i) in '%s'\n", filenameOnly, configname, g_iNumWadPaths, MAX_WADPATHS); 69 | } 70 | wadPathsFound++; 71 | PushWadPath (g_token, !include); 72 | } 73 | } 74 | Log("- %d wadpaths found in %s\n", wadPathsFound, configname); 75 | Log("--------------------------------------\n\n"); 76 | 77 | if (wadconfigsFound < 1) 78 | { 79 | Error ("Couldn't find wad config %s in '%s'\n", configname, filenameOnly); 80 | } 81 | if (wadconfigsFound > 1) 82 | { 83 | Error("Found more than one wad config %s in '%s'\n", configname, filenameOnly); 84 | } 85 | free (file); // should not be freed because it is still being used as script buffer 86 | //Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", configname, wadPathsFound, wadPathsFound > 1 ? "s" : ""); 87 | } 88 | void LoadWadcfgfile (const char *filename) 89 | { 90 | Log ("Loading %s\n", filename); 91 | Log ("------------\n"); 92 | int wadPathsCount = 0; 93 | int wadFileSize; 94 | char *wadFile; 95 | wadFileSize = LoadFile (filename, &wadFile); 96 | ParseFromMemory (wadFile, wadFileSize); 97 | while (GetToken (true)) //Loop through file 98 | { 99 | bool include = false; 100 | if (!strcasecmp (g_token, "include")) //If line starts with include (or contains?) 101 | { 102 | Log ("include "); 103 | include = true; 104 | if (!GetToken (true)) 105 | { 106 | Error ("parsing '%s': unexpected end of file.", filename); 107 | } 108 | } 109 | Log ("\"%s\"\n", g_token); 110 | if (g_iNumWadPaths >= MAX_WADPATHS) 111 | { 112 | Error ("parsing '%s': too many wad files.", filename); 113 | } 114 | wadPathsCount++; 115 | PushWadPath (g_token, !include); 116 | } 117 | free (wadFile); // should not be freed because it is still being used as script buffer 118 | //Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", filename, count, count > 1 ? "s" : ""); 119 | } 120 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/wadpath.cpp: -------------------------------------------------------------------------------- 1 | // AJM: added this file in 2 | 3 | #include "csg.h" 4 | 5 | wadpath_t* g_pWadPaths[MAX_WADPATHS]; 6 | int g_iNumWadPaths = 0; 7 | 8 | 9 | // ===================================================================================== 10 | // PushWadPath 11 | // adds a wadpath into the wadpaths list, without duplicates 12 | // ===================================================================================== 13 | void PushWadPath(const char* const path, bool inuse) 14 | { 15 | wadpath_t* currentWad; 16 | hlassume (g_iNumWadPaths < MAX_WADPATHS, assume_MAX_TEXFILES); 17 | currentWad = (wadpath_t*)malloc(sizeof(wadpath_t)); 18 | safe_strncpy(currentWad->path, path, _MAX_PATH); //Copy path into currentWad->path 19 | currentWad->usedbymap = inuse; 20 | currentWad->usedtextures = 0; //Updated later in autowad procedures 21 | currentWad->totaltextures = 0; //Updated later to reflect total 22 | 23 | if (g_iNumWadPaths < MAX_WADPATHS) //Fix buffer overrun //seedee 24 | { 25 | g_pWadPaths[g_iNumWadPaths] = currentWad; 26 | g_iNumWadPaths++; 27 | } 28 | else 29 | { 30 | free(currentWad); 31 | Error("PushWadPath: too many wadpaths (i%/i%)", g_iNumWadPaths, MAX_WADPATHS); 32 | } 33 | 34 | #ifdef _DEBUG 35 | Log("[dbg] PushWadPath: %i (%s)\n", g_iNumWadPaths, path); 36 | #endif 37 | } 38 | 39 | 40 | // ===================================================================================== 41 | // FreeWadPaths 42 | // ===================================================================================== 43 | void FreeWadPaths() 44 | { 45 | int i; 46 | wadpath_t* current; 47 | 48 | for (i = 0; i < g_iNumWadPaths; i++) 49 | { 50 | current = g_pWadPaths[i]; 51 | free(current); 52 | } 53 | } 54 | 55 | // ===================================================================================== 56 | // GetUsedWads 57 | // parse the "wad" keyvalue into wadpath_t structs 58 | // ===================================================================================== 59 | void GetUsedWads() 60 | { 61 | const char* pszWadPaths; 62 | char szTmp[_MAX_PATH]; 63 | int i, j; 64 | pszWadPaths = ValueForKey(&g_entities[0], "wad"); 65 | 66 | for (i = 0; ; ) //Loop through wadpaths 67 | { 68 | for (j = i; pszWadPaths[j] != '\0'; j++) //Find end of wadpath (semicolon) 69 | { 70 | if (pszWadPaths[j] == ';') 71 | { 72 | break; 73 | } 74 | } 75 | if (j - i > 0) //If wadpath is not empty 76 | { 77 | int length = qmin (j - i, _MAX_PATH - 1); //Get length of wadpath 78 | memcpy (szTmp, &pszWadPaths[i], length); 79 | szTmp[length] = '\0'; //Null terminate 80 | 81 | if (g_iNumWadPaths >= MAX_WADPATHS) 82 | { 83 | Error ("Too many wad files (%d/%d)\n", g_iNumWadPaths, MAX_WADPATHS); 84 | } 85 | PushWadPath (szTmp, true); //Add wadpath to list 86 | } 87 | if (pszWadPaths[j] == '\0') //Break if end of wadpaths 88 | { 89 | break; 90 | } 91 | i = j + 1; 92 | } 93 | } -------------------------------------------------------------------------------- /src/sdhlt/sdHLCSG/wadpath.h: -------------------------------------------------------------------------------- 1 | // AJM: added file in 2 | #ifndef WADPATH_H__ 3 | #define WADPATH_H__ 4 | #include "cmdlib.h" //--vluzacn 5 | 6 | #define MAX_WADPATHS 128 // arbitrary 7 | 8 | typedef struct 9 | { 10 | char path[_MAX_PATH]; 11 | bool usedbymap; // does this map requrie this wad to be included in the bsp? 12 | int usedtextures; // number of textures in this wad the map actually uses 13 | int totaltextures; // total textures in this wad 14 | } wadpath_t; // !!! the above two are VERY DIFFERENT. ie (usedtextures == 0) != (usedbymap == false) 15 | 16 | extern wadpath_t* g_pWadPaths[MAX_WADPATHS]; 17 | extern int g_iNumWadPaths; 18 | 19 | 20 | extern void PushWadPath(const char* const path, bool inuse); 21 | extern void FreeWadPaths(); 22 | extern void GetUsedWads(); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/compress.cpp: -------------------------------------------------------------------------------- 1 | #include "cmdlib.h" 2 | #include "compress.h" 3 | #include "log.h" 4 | #include 5 | #include 6 | #include 7 | 8 | const size_t unused_size = 3u; // located at the end of a block 9 | 10 | const char *(float_type_string[float_type_count]) = 11 | { 12 | "32bit", 13 | "16bit", 14 | "8bit" 15 | }; 16 | 17 | const size_t float_size[float_type_count] = 18 | { 19 | 4u, 20 | 2u, 21 | 1u 22 | }; 23 | 24 | const char *(vector_type_string[vector_type_count]) = 25 | { 26 | "96bit", 27 | "48bit", 28 | "32bit", 29 | "24bit" 30 | }; 31 | 32 | const size_t vector_size[vector_type_count] = 33 | { 34 | 12u, 35 | 6u, 36 | 4u, 37 | 3u 38 | }; 39 | 40 | void fail () 41 | { 42 | Error ("Compatability test failed. Please disable HLRAD_TRANSFERDATA_COMPRESS in cmdlib.h and recompile ZHLT."); 43 | } 44 | 45 | void compress_compatability_test () 46 | { 47 | unsigned char *v = (unsigned char *)malloc (16u); 48 | memset (v, 0, 16u); 49 | if (sizeof(char) !=1 || sizeof(unsigned int) != 4 || sizeof(float) != 4) 50 | fail (); 51 | *(float *)(v+1) = 0.123f; 52 | if (*(unsigned int *)v != 4226247936u || *(unsigned int *)(v+1) != 1039918957u) 53 | fail (); 54 | *(float *)(v+1) = -58; 55 | if (*(unsigned int *)v != 1744830464u || *(unsigned int *)(v+1) != 3261595648u) 56 | fail (); 57 | float f[5] = {0.123f, 1.f, 0.f, 0.123f, 0.f}; 58 | memset (v, ~0, 16u); 59 | vector_compress (VECTOR24, v, &f[0], &f[1], &f[2]); 60 | float_compress (FLOAT16, v+6, &f[3]); 61 | float_compress (FLOAT16, v+4, &f[4]); 62 | if (((unsigned int *)v)[0] != 4286318595u || ((unsigned int *)v)[1] != 3753771008u) 63 | fail (); 64 | float_decompress (FLOAT16, v+6, &f[3]); 65 | float_decompress (FLOAT16, v+4, &f[4]); 66 | vector_decompress (VECTOR24, v, &f[0], &f[1], &f[2]); 67 | float ans[5] = {0.109375f,1.015625f,0.015625f,0.123001f,0.000000f}; 68 | int i; 69 | for (i=0; i<5; ++i) 70 | if (f[i]-ans[i] > 0.00001f || f[i]-ans[i] < -0.00001f) 71 | fail (); 72 | free (v); 73 | } -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/compress.h: -------------------------------------------------------------------------------- 1 | #include "cmdlib.h" //--vluzacn 2 | 3 | 4 | #ifdef WORDS_BIGENDIAN 5 | #error 6 | #endif 7 | 8 | extern void compress_compatability_test (void); 9 | 10 | extern const size_t unused_size; // located at the end of a block 11 | 12 | typedef enum 13 | { 14 | FLOAT32 = 0, 15 | FLOAT16, 16 | FLOAT8, 17 | float_type_count 18 | } 19 | float_type; 20 | 21 | extern const char *float_type_string[]; 22 | 23 | extern const size_t float_size[]; 24 | 25 | typedef enum 26 | { 27 | VECTOR96 = 0, 28 | VECTOR48, 29 | VECTOR32, 30 | VECTOR24, 31 | vector_type_count 32 | } 33 | vector_type; 34 | 35 | extern const char *vector_type_string[]; 36 | 37 | extern const size_t vector_size[]; 38 | 39 | inline unsigned int bitget 40 | (unsigned int i, unsigned int start, unsigned int end) 41 | { 42 | return (i & ~(~0u << end)) >> start; 43 | } 44 | 45 | inline unsigned int bitput 46 | (unsigned int i, unsigned int start, unsigned int end) 47 | { 48 | return i << start; 49 | } 50 | 51 | inline unsigned int bitclr 52 | (unsigned int i, unsigned int start, unsigned int end) 53 | { 54 | return i & (~(~0u << start) | (~0u << end)); 55 | } 56 | 57 | inline unsigned int float_iswrong 58 | (unsigned int i) 59 | { 60 | return i >= 0x7F800000u; 61 | } 62 | 63 | inline unsigned int float_istoobig 64 | (unsigned int i) 65 | { 66 | return i >= 0x40000000u; 67 | } 68 | 69 | inline unsigned int float_istoosmall 70 | (unsigned int i) 71 | { 72 | return i < 0x30800000u; 73 | } 74 | 75 | inline void float_compress 76 | (float_type t, void *s, const float *f) 77 | { 78 | unsigned int *m = (unsigned int *)s; 79 | const unsigned int *p = (const unsigned int *)f; 80 | switch (t) 81 | { 82 | case FLOAT32: 83 | m[0] = *p; 84 | break; 85 | case FLOAT16: 86 | m[0] = bitclr (m[0], 0, 16); 87 | if (float_iswrong (*p)) 88 | ; 89 | else if (float_istoobig (*p)) 90 | m[0] |= bitget (~0u, 0, 16); 91 | else if (float_istoosmall (*p)) 92 | ; 93 | else 94 | m[0] |= bitget (*p, 12, 28); 95 | break; 96 | case FLOAT8: 97 | m[0] = bitclr (m[0], 0, 8); 98 | if (float_iswrong (*p)) 99 | ; 100 | else if (float_istoobig (*p)) 101 | m[0] |= bitget (~0u, 0, 8); 102 | else if (float_istoosmall (*p)) 103 | ; 104 | else 105 | m[0] |= bitget (*p, 20, 28); 106 | break; 107 | default: 108 | ; 109 | } 110 | } 111 | 112 | inline void float_decompress 113 | (float_type t, const void *s, float *f) 114 | { 115 | const unsigned int *m = (const unsigned int *)s; 116 | unsigned int *p = (unsigned int *)f; 117 | switch (t) 118 | { 119 | case FLOAT32: 120 | *p = m[0]; 121 | break; 122 | case FLOAT16: 123 | if (bitget (m[0], 0, 16) == 0) 124 | *p = 0; 125 | else 126 | *p 127 | = bitput (1, 11, 12) 128 | | bitput (bitget (m[0], 0, 16), 12, 28) 129 | | bitput (3, 28, 32) 130 | ; 131 | break; 132 | case FLOAT8: 133 | if (bitget (m[0], 0, 8) == 0) 134 | *p = 0; 135 | else 136 | *p 137 | = bitput (1, 19, 20) 138 | | bitput (bitget (m[0], 0, 8), 20, 28) 139 | | bitput (3, 28, 32) 140 | ; 141 | break; 142 | default: 143 | ; 144 | } 145 | } 146 | 147 | inline void vector_compress 148 | (vector_type t, void *s, const float *f1, const float *f2, const float *f3) 149 | { 150 | unsigned int *m = (unsigned int *)s; 151 | const unsigned int *p1 = (const unsigned int *)f1; 152 | const unsigned int *p2 = (const unsigned int *)f2; 153 | const unsigned int *p3 = (const unsigned int *)f3; 154 | unsigned int max, i1, i2, i3; 155 | switch (t) 156 | { 157 | case VECTOR96: 158 | m[0] = *p1; 159 | m[1] = *p2; 160 | m[2] = *p3; 161 | break; 162 | case VECTOR48: 163 | if (float_iswrong (*p1) || float_iswrong (*p2) || float_iswrong (*p3)) 164 | break; 165 | m[0] = 0, m[1] = bitclr (m[1], 0, 16); 166 | if (float_istoobig (*p1)) 167 | m[0] |= bitget (~0u, 0, 16); 168 | else if (float_istoosmall (*p1)) 169 | ; 170 | else 171 | m[0] |= bitget (*p1, 12, 28); 172 | if (float_istoobig (*p2)) 173 | m[0] |= bitput (bitget (~0u, 0, 16), 16, 32); 174 | else if (float_istoosmall (*p2)) 175 | ; 176 | else 177 | m[0] |= bitput (bitget (*p2, 12, 28), 16, 32); 178 | if (float_istoobig (*p3)) 179 | m[1] |= bitget (~0u, 0, 16); 180 | else if (float_istoosmall (*p3)) 181 | ; 182 | else 183 | m[1] |= bitget (*p3, 12, 28); 184 | break; 185 | case VECTOR32: 186 | case VECTOR24: 187 | if (float_iswrong (*p1) || float_iswrong (*p2) || float_iswrong (*p3)) 188 | { 189 | max = i1 = i2 = i3 = 0; 190 | } 191 | else 192 | { 193 | max = *p1>*p2? (*p1>*p3? *p1: *p3): (*p2>*p3? *p2: *p3); 194 | max = float_istoobig (max)? 0x7F : float_istoosmall (max)? 0x60 : bitget (max, 23, 31); 195 | i1 = float_istoobig (*p1)? ~0u : (bitget (*p1, 0, 23) | bitput (1, 23, 24)) >> (1 + max - bitget (*p1, 23, 31)); 196 | i2 = float_istoobig (*p2)? ~0u : (bitget (*p2, 0, 23) | bitput (1, 23, 24)) >> (1 + max - bitget (*p2, 23, 31)); 197 | i3 = float_istoobig (*p3)? ~0u : (bitget (*p3, 0, 23) | bitput (1, 23, 24)) >> (1 + max - bitget (*p3, 23, 31)); 198 | } 199 | if (t == VECTOR32) 200 | m[0] = 0 201 | | bitput (bitget (i1, 14, 23), 0, 9) 202 | | bitput (bitget (i2, 14, 23), 9, 18) 203 | | bitput (bitget (i3, 14, 23), 18, 27) 204 | | bitput (bitget (max, 0, 5), 27, 32) 205 | ; 206 | else 207 | m[0] = bitclr (m[0], 0, 24) 208 | | bitput (bitget (i1, 17, 23), 0, 6) 209 | | bitput (bitget (i2, 17, 23), 6, 12) 210 | | bitput (bitget (i3, 17, 23), 12, 18) 211 | | bitput (bitget (max, 0, 5), 18, 23) 212 | ; 213 | break; 214 | default: 215 | ; 216 | } 217 | } 218 | 219 | inline void vector_decompress 220 | (vector_type t, const void *s, float *f1, float *f2, float *f3) 221 | { 222 | const unsigned int *m = (const unsigned int *)s; 223 | unsigned int *p1 = (unsigned int *)f1; 224 | unsigned int *p2 = (unsigned int *)f2; 225 | unsigned int *p3 = (unsigned int *)f3; 226 | switch (t) 227 | { 228 | case VECTOR96: 229 | *p1 = m[0]; 230 | *p2 = m[1]; 231 | *p3 = m[2]; 232 | break; 233 | case VECTOR48: 234 | if (bitget (m[0], 0, 16) == 0) 235 | *p1 = 0; 236 | else 237 | *p1 238 | = bitput (1, 11, 12) 239 | | bitput (bitget (m[0], 0, 16), 12, 28) 240 | | bitput (3, 28, 32) 241 | ; 242 | if (bitget (m[0], 16, 32) == 0) 243 | *p2 = 0; 244 | else 245 | *p2 246 | = bitput (1, 11, 12) 247 | | bitput (bitget (m[0], 16, 32), 12, 28) 248 | | bitput (3, 28, 32) 249 | ; 250 | if (bitget (m[1], 0, 16) == 0) 251 | *p3 = 0; 252 | else 253 | *p3 254 | = bitput (1, 11, 12) 255 | | bitput (bitget (m[1], 0, 16), 12, 28) 256 | | bitput (3, 28, 32) 257 | ; 258 | break; 259 | case VECTOR32: case VECTOR24: 260 | float f; 261 | if (t == VECTOR32) 262 | { 263 | *p1 264 | = bitput (1, 13, 14) 265 | | bitput (bitget (m[0], 0, 9), 14, 23) 266 | | bitput (bitget (m[0], 27, 32), 23, 28) 267 | | bitput (3, 28, 32) 268 | ; 269 | *p2 270 | = bitput (1, 13, 14) 271 | | bitput (bitget (m[0], 9, 18), 14, 23) 272 | | bitput (bitget (m[0], 27, 32), 23, 28) 273 | | bitput (3, 28, 32) 274 | ; 275 | *p3 276 | = bitput (1, 13, 14) 277 | | bitput (bitget (m[0], 18, 27), 14, 23) 278 | | bitput (bitget (m[0], 27, 32), 23, 28) 279 | | bitput (3, 28, 32) 280 | ; 281 | *((unsigned int *)&f) 282 | = bitput (bitget (m[0], 27, 32), 23, 28) 283 | | bitput (3, 28, 32) 284 | ; 285 | } 286 | else 287 | { 288 | *p1 289 | = bitput (1, 16, 17) 290 | | bitput (bitget (m[0], 0, 6), 17, 23) 291 | | bitput (bitget (m[0], 18, 23), 23, 28) 292 | | bitput (3, 28, 32) 293 | ; 294 | *p2 295 | = bitput (1, 16, 17) 296 | | bitput (bitget (m[0], 6, 12), 17, 23) 297 | | bitput (bitget (m[0], 18, 23), 23, 28) 298 | | bitput (3, 28, 32) 299 | ; 300 | *p3 301 | = bitput (1, 16, 17) 302 | | bitput (bitget (m[0], 12, 18), 17, 23) 303 | | bitput (bitget (m[0], 18, 23), 23, 28) 304 | | bitput (3, 28, 32) 305 | ; 306 | *((unsigned int *)&f) 307 | = bitput (bitget (m[0], 18, 23), 23, 28) 308 | | bitput (3, 28, 32) 309 | ; 310 | } 311 | *f1 = (*f1-f) * 2.f; 312 | *f2 = (*f2-f) * 2.f; 313 | *f3 = (*f3-f) * 2.f; 314 | break; 315 | default: 316 | ; 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * A generic template list class. 3 | * Fairly typical of the list example you would 4 | * find in any c++ book. 5 | */ 6 | //used by progmesh //seedee 7 | #ifndef GENERIC_LIST_H 8 | #define GENERIC_LIST_H 9 | 10 | #include 11 | #include 12 | 13 | template class List 14 | { 15 | public: 16 | List( int s = 0 ); 17 | ~List(); 18 | void allocate( int s ); 19 | void SetSize( int s ); 20 | void Pack(); 21 | void Add( Type ); 22 | void AddUnique( Type ); 23 | int Contains( Type ); 24 | void Remove( Type ); 25 | void DelIndex( int i ); 26 | Type* element; 27 | int num; 28 | int array_size; 29 | Type &operator[]( int i ) { assert( i >= 0 && i < num ); return element[i]; } 30 | }; 31 | 32 | template 33 | List :: List( int s ) 34 | { 35 | num = 0; 36 | array_size = 0; 37 | element = NULL; 38 | if( s ) 39 | { 40 | allocate( s ); 41 | } 42 | } 43 | 44 | template 45 | List :: ~List() 46 | { 47 | delete element; 48 | } 49 | 50 | template 51 | void List :: allocate( int s ) 52 | { 53 | assert( s > 0 ); 54 | assert( s >= num ); 55 | Type *old = element; 56 | array_size = s; 57 | element = new Type[array_size]; 58 | assert( element ); 59 | 60 | for( int i = 0; i < num; i++ ) 61 | { 62 | element[i] = old[i]; 63 | } 64 | 65 | if( old ) delete old; 66 | } 67 | template 68 | void List :: SetSize( int s ) 69 | { 70 | if( s == 0 ) 71 | { 72 | if( element ) 73 | delete element; 74 | } 75 | else 76 | { 77 | allocate( s ); 78 | } 79 | 80 | num = s; 81 | } 82 | template 83 | void List :: Pack() 84 | { 85 | allocate( num ); 86 | } 87 | 88 | template 89 | void List :: Add( Type t ) 90 | { 91 | assert( num <= array_size ); 92 | 93 | if( num == array_size ) 94 | { 95 | allocate(( array_size ) ? array_size * 2 : 16 ); 96 | } 97 | 98 | element[num++] = t; 99 | } 100 | 101 | template 102 | int List :: Contains( Type t ) 103 | { 104 | int count = 0; 105 | 106 | for( int i = 0; i < num; i++ ) 107 | { 108 | if( element[i] == t ) 109 | count++; 110 | } 111 | 112 | return count; 113 | } 114 | 115 | template 116 | void List :: AddUnique( Type t ) 117 | { 118 | if( !Contains( t )) 119 | Add( t ); 120 | } 121 | 122 | template 123 | void List :: DelIndex( int i ) 124 | { 125 | assert( i < num ); 126 | num--; 127 | 128 | while( i < num ) 129 | { 130 | element[i] = element[i+1]; 131 | i++; 132 | } 133 | } 134 | 135 | template 136 | void List :: Remove( Type t ) 137 | { 138 | int i; 139 | 140 | for( i = 0; i < num; i++ ) 141 | { 142 | if( element[i] == t ) 143 | { 144 | break; 145 | } 146 | } 147 | 148 | DelIndex( i ); 149 | 150 | for( i = 0; i < num; i++ ) 151 | { 152 | assert( element[i] != t ); 153 | } 154 | } 155 | 156 | #endif//GENERIC_LIST_H -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/meshdesc.h: -------------------------------------------------------------------------------- 1 | /* 2 | meshdesc.h - cached mesh for tracing custom objects 3 | Copyright (C) 2012 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef MESHDESC_H 17 | #define MESHDESC_H 18 | 19 | #include "studio.h" 20 | #include "list.h" // simple container 21 | 22 | #define AREA_NODES 32 23 | #define AREA_DEPTH 4 24 | 25 | #define MAX_FACET_PLANES 32 26 | #define MAX_PLANES 524288 // unsigned short limit 27 | #define PLANE_HASHES (MAX_PLANES>>2) 28 | 29 | #define PLANE_NORMAL_EPSILON 0.00001f 30 | #define PLANE_DIST_EPSILON 0.04f 31 | 32 | // compute methods 33 | #define SHADOW_FAST 0 34 | #define SHADOW_NORMAL 1 35 | #define SHADOW_SLOW 2 36 | 37 | #ifndef M_PI 38 | #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h 39 | #endif 40 | 41 | typedef unsigned short word; 42 | typedef unsigned int uint; 43 | typedef vec_t vec4_t[4]; // x,y,z,w 44 | typedef vec_t matrix3x4[3][4]; 45 | 46 | #define Q_rint( x ) ((x) < 0 ? ((int)((x)-0.5f)) : ((int)((x)+0.5f))) 47 | #ifndef __MSC_VER 48 | #define _inline inline 49 | #endif 50 | 51 | typedef struct mplane_s 52 | { 53 | vec3_t normal; 54 | float dist; 55 | byte type; // for fast side tests 56 | byte signbits; // signx + (signy<<1) + (signz<<1) 57 | byte pad[2]; 58 | } mplane_t; 59 | 60 | typedef struct hashplane_s 61 | { 62 | mplane_t pl; 63 | struct hashplane_s *hash; 64 | } hashplane_t; 65 | 66 | typedef struct link_s 67 | { 68 | struct link_s *prev, *next; 69 | } link_t; 70 | 71 | typedef struct areanode_s 72 | { 73 | int axis; // -1 = leaf node 74 | float dist; 75 | struct areanode_s *children[2]; 76 | link_t facets; 77 | } areanode_t; 78 | 79 | typedef struct mvert_s 80 | { 81 | vec3_t point; 82 | float st[2]; // for alpha-texture test 83 | } mvert_t; 84 | 85 | typedef struct 86 | { 87 | link_t area; // linked to a division node or leaf 88 | mstudiotexture_t *texture; // valid for alpha-testing surfaces 89 | mvert_t triangle[3]; // store triangle points 90 | vec3_t mins, maxs; // an individual size of each facet 91 | vec3_t edge1, edge2; // new trace stuff 92 | byte numplanes; // because numplanes for each facet can't exceeds MAX_FACET_PLANES! 93 | uint *indices; // a indexes into mesh plane pool 94 | } mfacet_t; 95 | 96 | typedef struct 97 | { 98 | int trace_mode; // trace method 99 | vec3_t mins, maxs; 100 | uint numfacets; 101 | uint numplanes; 102 | mfacet_t *facets; 103 | mplane_t *planes; // shared plane pool 104 | } mmesh_t; 105 | 106 | class triset 107 | { 108 | public: 109 | int v[3]; // indices to vertex list 110 | }; 111 | 112 | class vector 113 | { 114 | public: 115 | inline vector( float X = 0.0f, float Y = 0.0f, float Z = 0.0f ){ x = X; y = Y; z = Z; }; 116 | inline vector( const float *rgfl ) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; } 117 | inline vector( float rgfl[3]) { x = rgfl[0]; y = rgfl[1]; z = rgfl[2]; } 118 | inline vector( const vector& v ) { x = v.x; y = v.y; z = v.z; } 119 | operator const float *() const { return &x; } 120 | operator float *() { return &x; } 121 | float x, y, z; 122 | }; 123 | 124 | class CMeshDesc 125 | { 126 | private: 127 | mmesh_t m_mesh; 128 | const char *m_debugName; // just for debug purpoces 129 | areanode_t areanodes[AREA_NODES]; // AABB tree for speedup trace test 130 | int numareanodes; 131 | bool has_tree; // build AABB tree 132 | int m_iTotalPlanes; // just for stats 133 | int m_iNumTris; // if > 0 we are in build mode 134 | size_t mesh_size; // mesh total size 135 | 136 | // used only while mesh is contsructed 137 | mfacet_t *facets; 138 | hashplane_t **planehash; 139 | hashplane_t *planepool; 140 | public: 141 | CMeshDesc(); 142 | ~CMeshDesc(); 143 | 144 | // mesh construction 145 | bool InitMeshBuild( const char *debug_name, int numTrinagles ); 146 | bool AddMeshTrinagle( const mvert_t triangle[3], mstudiotexture_t *tex = NULL ); 147 | bool FinishMeshBuild( void ); 148 | void FreeMeshBuild( void ); 149 | void FreeMesh( void ); 150 | 151 | // local mathlib 152 | void AngleMatrix( const vec3_t angles, const vec3_t origin, const vec3_t scale, float (*matrix)[4] ); 153 | void ConcatTransforms( float in1[3][4], float in2[3][4], float out[3][4] ); 154 | void QuaternionMatrix( vec4_t quat, const vec3_t origin, float (*matrix)[4] ); 155 | void VectorTransform( const vec3_t in1, float in2[3][4], vec3_t out ); 156 | void AngleQuaternion( const vec3_t angles, vec4_t quat ); 157 | 158 | // studio models processing 159 | void StudioCalcBoneQuaterion( mstudiobone_t *pbone, mstudioanim_t *panim, vec4_t q ); 160 | void StudioCalcBonePosition( mstudiobone_t *pbone, mstudioanim_t *panim, vec3_t pos ); 161 | bool StudioConstructMesh( struct model_s *pModel ); 162 | 163 | // linked list operations 164 | void InsertLinkBefore( link_t *l, link_t *before ); 165 | void RemoveLink( link_t *l ); 166 | void ClearLink( link_t *l ); 167 | 168 | // AABB tree contsruction 169 | areanode_t *CreateAreaNode( int depth, const vec3_t mins, const vec3_t maxs ); 170 | void RelinkFacet( mfacet_t *facet ); 171 | _inline areanode_t *GetHeadNode( void ) { return (has_tree) ? &areanodes[0] : NULL; } 172 | 173 | // plane cache 174 | uint AddPlaneToPool( const mplane_t *pl ); 175 | bool PlaneFromPoints( const mvert_t triangle[3], mplane_t *plane ); 176 | bool ComparePlanes( const mplane_t *plane, const vec3_t normal, float dist ); 177 | bool PlaneEqual( const mplane_t *p0, const mplane_t *p1 ); 178 | void CategorizePlane( mplane_t *plane ); 179 | void SnapPlaneToGrid( mplane_t *plane ); 180 | void SnapVectorToGrid( vec3_t normal ); 181 | 182 | // check for cache 183 | _inline mmesh_t *GetMesh() { return &m_mesh; } 184 | 185 | void ClearBounds( vec3_t mins, vec3_t maxs ) 186 | { 187 | // make bogus range 188 | mins[0] = mins[1] = mins[2] = 999999.0f; 189 | maxs[0] = maxs[1] = maxs[2] = -999999.0f; 190 | } 191 | 192 | void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) 193 | { 194 | for( int i = 0; i < 3; i++ ) 195 | { 196 | if( v[i] < mins[i] ) mins[i] = v[i]; 197 | if( v[i] > maxs[i] ) maxs[i] = v[i]; 198 | } 199 | } 200 | 201 | bool Intersect( const vec3_t trace_mins, const vec3_t trace_maxs ) 202 | { 203 | if( m_mesh.mins[0] > trace_maxs[0] || m_mesh.mins[1] > trace_maxs[1] || m_mesh.mins[2] > trace_maxs[2] ) 204 | return false; 205 | if( m_mesh.maxs[0] < trace_mins[0] || m_mesh.maxs[1] < trace_mins[1] || m_mesh.maxs[2] < trace_mins[2] ) 206 | return false; 207 | return true; 208 | } 209 | }; 210 | 211 | // simplification 212 | void ProgressiveMesh( List &vert, List &tri, List &map, List &permutation ); 213 | void PermuteVertices( List &permutation, List &vert, List &tris ); 214 | int MapVertex( int a, int mx, List &map ); 215 | 216 | // collision description 217 | typedef struct model_s 218 | { 219 | char name[64]; // model name 220 | vec3_t origin; 221 | vec3_t angles; 222 | vec3_t scale; // scale X-Form 223 | int body; // sets by level-designer 224 | int skin; // e.g. various alpha-textures 225 | int trace_mode; // 0 - ultra fast, 1 - med, 2 - slow 226 | 227 | void *extradata; // model 228 | void *anims; // studio animations 229 | 230 | CMeshDesc mesh; // cform 231 | } model_t; 232 | 233 | #endif//MESHDESC_H -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/meshtrace.h: -------------------------------------------------------------------------------- 1 | /* 2 | trace.h - trace triangle meshes 3 | Copyright (C) 2012 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef TRACEMESH_H 17 | #define TRACEMESH_H 18 | 19 | #include "meshdesc.h" 20 | 21 | #define FRAC_EPSILON (1.0f / 32.0f) 22 | #define BARY_EPSILON 0.01f 23 | #define ASLF_EPSILON 0.0001f 24 | #define COPLANAR_EPSILON 0.25f 25 | #define NEAR_SHADOW_EPSILON 1.5f 26 | #define SELF_SHADOW_EPSILON 0.5f 27 | 28 | #define STRUCT_FROM_LINK( l, t, m ) ((t *)((byte *)l - (int)(long int)&(((t *)0)->m))) 29 | #define FACET_FROM_AREA( l ) STRUCT_FROM_LINK( l, mfacet_t, area ) 30 | #define bound( min, num, max ) ((num) >= (min) ? ((num) < (max) ? (num) : (max)) : (min)) 31 | 32 | class TraceMesh 33 | { 34 | private: 35 | vec3_t m_vecStart, m_vecEnd; 36 | vec3_t m_vecStartMins, m_vecEndMins; 37 | vec3_t m_vecStartMaxs, m_vecEndMaxs; 38 | vec3_t m_vecAbsMins, m_vecAbsMaxs; 39 | vec3_t m_vecTraceDirection;// ray direction 40 | float m_flTraceDistance; 41 | bool m_bHitTriangle; // now we hit triangle 42 | areanode_t *areanodes; // AABB for static meshes 43 | mmesh_t *mesh; // mesh to trace 44 | int checkcount; // debug 45 | void *m_extradata; // pointer to model extradata 46 | 47 | void ClearBounds( vec3_t mins, vec3_t maxs ) 48 | { 49 | // make bogus range 50 | mins[0] = mins[1] = mins[2] = 999999.0f; 51 | maxs[0] = maxs[1] = maxs[2] = -999999.0f; 52 | } 53 | 54 | void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) 55 | { 56 | for( int i = 0; i < 3; i++ ) 57 | { 58 | if( v[i] < mins[i] ) mins[i] = v[i]; 59 | if( v[i] > maxs[i] ) maxs[i] = v[i]; 60 | } 61 | } 62 | 63 | bool BoundsIntersect( const vec3_t mins1, const vec3_t maxs1, const vec3_t mins2, const vec3_t maxs2 ) 64 | { 65 | if( mins1[0] > maxs2[0] || mins1[1] > maxs2[1] || mins1[2] > maxs2[2] ) 66 | return false; 67 | if( maxs1[0] < mins2[0] || maxs1[1] < mins2[1] || maxs1[2] < mins2[2] ) 68 | return false; 69 | return true; 70 | } 71 | public: 72 | TraceMesh() { mesh = NULL; } 73 | ~TraceMesh() {} 74 | 75 | // trace stuff 76 | void SetTraceMesh( mmesh_t *cached_mesh, areanode_t *tree ) { mesh = cached_mesh; areanodes = tree; } 77 | void SetupTrace( const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end ); 78 | void SetTraceModExtradata( void *data ) { m_extradata = data; } 79 | bool ClipRayToBox( const vec3_t mins, const vec3_t maxs ); 80 | bool ClipRayToTriangle( const mfacet_t *facet ); // obsolete 81 | bool ClipRayToFacet( const mfacet_t *facet ); 82 | bool ClipRayToFace( const mfacet_t *facet ); // ripped out from q3map2 83 | void ClipToLinks( areanode_t *node ); 84 | bool DoTrace( void ); 85 | }; 86 | 87 | #endif//TRACEMESH_H -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/nomatrix.cpp: -------------------------------------------------------------------------------- 1 | #include "qrad.h" 2 | 3 | // ===================================================================================== 4 | // CheckVisBit 5 | // ===================================================================================== 6 | static bool CheckVisBitNoVismatrix(unsigned patchnum1, unsigned patchnum2 7 | , vec3_t &transparency_out 8 | , unsigned int & 9 | ) 10 | // patchnum1=receiver, patchnum2=emitter. //HLRAD_CheckVisBitNoVismatrix_NOSWAP 11 | { 12 | 13 | if (patchnum1 > g_num_patches) 14 | { 15 | Warning("in CheckVisBit(), patchnum1 > num_patches"); 16 | } 17 | if (patchnum2 > g_num_patches) 18 | { 19 | Warning("in CheckVisBit(), patchnum2 > num_patches"); 20 | } 21 | 22 | patch_t* patch = &g_patches[patchnum1]; 23 | patch_t* patch2 = &g_patches[patchnum2]; 24 | 25 | VectorFill(transparency_out, 1.0); 26 | 27 | // if emitter is behind that face plane, skip all patches 28 | 29 | if (patch2) 30 | { 31 | const dplane_t* plane2 = getPlaneFromFaceNumber(patch2->faceNumber); 32 | 33 | if (DotProduct (patch->origin, plane2->normal) > PatchPlaneDist (patch2) + ON_EPSILON - patch->emitter_range) 34 | { 35 | // we need to do a real test 36 | 37 | const dplane_t* plane = getPlaneFromFaceNumber(patch->faceNumber); 38 | 39 | vec3_t transparency = {1.0,1.0,1.0}; 40 | int opaquestyle = -1; 41 | 42 | // check vis between patch and patch2 43 | // if v2 is not behind light plane 44 | // && v2 is visible from v1 45 | vec3_t origin1, origin2; 46 | vec3_t delta; 47 | vec_t dist; 48 | VectorSubtract (patch->origin, patch2->origin, delta); 49 | dist = VectorLength (delta); 50 | if (dist < patch2->emitter_range - ON_EPSILON) 51 | { 52 | GetAlternateOrigin (patch->origin, plane->normal, patch2, origin2); 53 | } 54 | else 55 | { 56 | VectorCopy (patch2->origin, origin2); 57 | } 58 | if (DotProduct (origin2, plane->normal) <= PatchPlaneDist (patch) + MINIMUM_PATCH_DISTANCE) 59 | { 60 | return false; 61 | } 62 | if (dist < patch->emitter_range - ON_EPSILON) 63 | { 64 | GetAlternateOrigin (patch2->origin, plane2->normal, patch, origin1); 65 | } 66 | else 67 | { 68 | VectorCopy (patch->origin, origin1); 69 | } 70 | if (DotProduct (origin1, plane2->normal) <= PatchPlaneDist (patch2) + MINIMUM_PATCH_DISTANCE) 71 | { 72 | return false; 73 | } 74 | if (TestLine( 75 | origin1, origin2 76 | ) != CONTENTS_EMPTY) 77 | { 78 | return false; 79 | } 80 | if (TestSegmentAgainstOpaqueList( 81 | origin1, origin2 82 | , transparency 83 | , opaquestyle 84 | )) 85 | { 86 | return false; 87 | } 88 | 89 | { 90 | if (opaquestyle != -1) 91 | { 92 | AddStyleToStyleArray (patchnum1, patchnum2, opaquestyle); 93 | } 94 | if(g_customshadow_with_bouncelight) 95 | { 96 | VectorCopy(transparency, transparency_out); 97 | } 98 | return true; 99 | } 100 | } 101 | } 102 | 103 | return false; 104 | } 105 | bool CheckVisBitBackwards(unsigned receiver, unsigned emitter, const vec3_t &backorigin, const vec3_t &backnormal 106 | , vec3_t &transparency_out 107 | ) 108 | { 109 | patch_t* patch = &g_patches[receiver]; 110 | patch_t* emitpatch = &g_patches[emitter]; 111 | 112 | VectorFill(transparency_out, 1.0); 113 | 114 | if (emitpatch) 115 | { 116 | const dplane_t* emitplane = getPlaneFromFaceNumber(emitpatch->faceNumber); 117 | 118 | if (DotProduct(backorigin, emitplane->normal) > (PatchPlaneDist(emitpatch) + MINIMUM_PATCH_DISTANCE)) 119 | { 120 | 121 | vec3_t transparency = {1.0,1.0,1.0}; 122 | int opaquestyle = -1; 123 | 124 | vec3_t emitorigin; 125 | vec3_t delta; 126 | vec_t dist; 127 | VectorSubtract (backorigin, emitpatch->origin, delta); 128 | dist = VectorLength (delta); 129 | if (dist < emitpatch->emitter_range - ON_EPSILON) 130 | { 131 | GetAlternateOrigin (backorigin, backnormal, emitpatch, emitorigin); 132 | } 133 | else 134 | { 135 | VectorCopy (emitpatch->origin, emitorigin); 136 | } 137 | if (DotProduct (emitorigin, backnormal) <= DotProduct (backorigin, backnormal) + MINIMUM_PATCH_DISTANCE) 138 | { 139 | return false; 140 | } 141 | if (TestLine( 142 | backorigin, emitorigin 143 | ) != CONTENTS_EMPTY) 144 | { 145 | return false; 146 | } 147 | if (TestSegmentAgainstOpaqueList( 148 | backorigin, emitorigin 149 | , transparency 150 | , opaquestyle 151 | )) 152 | { 153 | return false; 154 | } 155 | 156 | { 157 | if (opaquestyle != -1) 158 | { 159 | AddStyleToStyleArray (receiver, emitter, opaquestyle); 160 | } 161 | if(g_customshadow_with_bouncelight) 162 | { 163 | VectorCopy(transparency, transparency_out); 164 | } 165 | return true; 166 | } 167 | } 168 | } 169 | 170 | return false; 171 | } 172 | 173 | // 174 | // end old vismat.c 175 | //////////////////////////// 176 | 177 | void MakeScalesNoVismatrix() 178 | { 179 | char transferfile[_MAX_PATH]; 180 | 181 | hlassume(g_num_patches < MAX_PATCHES, assume_MAX_PATCHES); 182 | 183 | safe_snprintf(transferfile, _MAX_PATH, "%s.inc", g_Mapname); 184 | 185 | if (!g_incremental || !readtransfers(transferfile, g_num_patches)) 186 | { 187 | g_CheckVisBit = CheckVisBitNoVismatrix; 188 | if(g_rgb_transfers) 189 | {NamedRunThreadsOn(g_num_patches, g_estimate, MakeRGBScales);} 190 | else 191 | {NamedRunThreadsOn(g_num_patches, g_estimate, MakeScales);} 192 | 193 | if (g_incremental) 194 | { 195 | writetransfers(transferfile, g_num_patches); 196 | } 197 | else 198 | { 199 | unlink(transferfile); 200 | } 201 | DumpTransfersMemoryUsage(); 202 | CreateFinalStyleArrays ("dynamic shadow array"); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/sdHLRAD.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {a0cf76ae-75aa-499a-b918-b2a6557e35d7} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90 7 | 8 | 9 | {4848509b-0f96-431d-a338-8ad8791f845b} 10 | 11 | 12 | {a32bc9fa-c773-4831-bbb7-b1e2b7aadf9f} 13 | h;hpp;hxx;hm;inl;fi;fd 14 | 15 | 16 | {115941c5-3fdd-402d-bbb3-96f9eef34328} 17 | ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe 18 | 19 | 20 | 21 | 22 | Source Files\common 23 | 24 | 25 | Source Files\common 26 | 27 | 28 | Source Files\common 29 | 30 | 31 | Source Files\common 32 | 33 | 34 | Source Files\common 35 | 36 | 37 | Source Files\common 38 | 39 | 40 | Source Files\common 41 | 42 | 43 | Source Files\common 44 | 45 | 46 | Source Files\common 47 | 48 | 49 | Source Files\common 50 | 51 | 52 | Source Files\common 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | Source Files 71 | 72 | 73 | Source Files 74 | 75 | 76 | Source Files 77 | 78 | 79 | Source Files 80 | 81 | 82 | Source Files 83 | 84 | 85 | Source Files 86 | 87 | 88 | Source Files 89 | 90 | 91 | Source Files 92 | 93 | 94 | Source Files 95 | 96 | 97 | Source Files 98 | 99 | 100 | Source Files 101 | 102 | 103 | Source Files 104 | 105 | 106 | Source Files 107 | 108 | 109 | Source Files 110 | 111 | 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | Header Files 127 | 128 | 129 | Header Files 130 | 131 | 132 | Header Files 133 | 134 | 135 | Header Files 136 | 137 | 138 | Header Files 139 | 140 | 141 | Header Files 142 | 143 | 144 | Header Files 145 | 146 | 147 | Header Files 148 | 149 | 150 | Header Files 151 | 152 | 153 | Header Files 154 | 155 | 156 | Header Files 157 | 158 | 159 | Header Files 160 | 161 | 162 | Header Files 163 | 164 | 165 | Header Files 166 | 167 | 168 | Header Files 169 | 170 | 171 | Header Files 172 | 173 | 174 | Header Files 175 | 176 | 177 | Header Files 178 | 179 | 180 | Header Files 181 | 182 | 183 | Header Files 184 | 185 | 186 | Header Files 187 | 188 | 189 | Header Files 190 | 191 | 192 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/studio.cpp: -------------------------------------------------------------------------------- 1 | #include "qrad.h" 2 | #include "meshtrace.h" 3 | #include "filelib.h" 4 | #include "stringlib.h" 5 | 6 | #define MAX_MODELS 1024 7 | 8 | model_t models[MAX_MODELS]; 9 | int num_models; 10 | 11 | void LoadStudioModel( const char *modelname, const vec3_t origin, const vec3_t angles, const vec3_t scale, int body, int skin, int trace_mode ) 12 | { 13 | if( num_models >= MAX_MODELS ) 14 | { 15 | Developer( DEVELOPER_LEVEL_ERROR, "LoadStudioModel: MAX_MODELS exceeded\n" ); 16 | return; 17 | } 18 | model_t *m = &models[num_models]; 19 | sprintf(m->name, "%s%s", g_Wadpath, modelname); 20 | FlipSlashes(m->name); 21 | 22 | if (!q_exists(m->name)) 23 | { 24 | Warning("LoadStudioModel: couldn't load %s\n", m->name); 25 | return; 26 | } 27 | LoadFile(m->name, (char**)&m->extradata); 28 | 29 | studiohdr_t *phdr = (studiohdr_t *)m->extradata; 30 | 31 | // well the textures place in separate file (very stupid case) 32 | if( phdr->numtextures == 0 ) 33 | { 34 | char texname[128], texpath[128]; 35 | byte *texdata, *moddata; 36 | studiohdr_t *thdr, *newhdr; 37 | safe_strncpy(texname, modelname, 128); 38 | StripExtension(texname); 39 | 40 | sprintf(texpath, "%s%sT.mdl", g_Wadpath, texname); 41 | FlipSlashes(texpath); 42 | 43 | LoadFile(texpath, (char**)&texdata); 44 | moddata = (byte *)m->extradata; 45 | phdr = (studiohdr_t *)moddata; 46 | 47 | thdr = (studiohdr_t *)texdata; 48 | 49 | // merge textures with main model buffer 50 | m->extradata = malloc( phdr->length + thdr->length - sizeof( studiohdr_t )); // we don't need two headers 51 | memcpy( m->extradata, moddata, phdr->length ); 52 | memcpy( (byte *)m->extradata + phdr->length, texdata + sizeof( studiohdr_t ), thdr->length - sizeof( studiohdr_t )); 53 | 54 | // merge header 55 | newhdr = (studiohdr_t *)m->extradata; 56 | 57 | newhdr->numskinfamilies = thdr->numskinfamilies; 58 | newhdr->numtextures = thdr->numtextures; 59 | newhdr->numskinref = thdr->numskinref; 60 | newhdr->textureindex = phdr->length; 61 | newhdr->skinindex = newhdr->textureindex + ( newhdr->numtextures * sizeof( mstudiotexture_t )); 62 | newhdr->texturedataindex = newhdr->skinindex + (newhdr->numskinfamilies * newhdr->numskinref * sizeof( short )); 63 | newhdr->length = phdr->length + thdr->length - sizeof( studiohdr_t ); 64 | 65 | // and finally merge datapointers for textures 66 | for( int i = 0; i < newhdr->numtextures; i++ ) 67 | { 68 | mstudiotexture_t *ptexture = (mstudiotexture_t *)(((byte *)newhdr) + newhdr->textureindex); 69 | ptexture[i].index += ( phdr->length - sizeof( studiohdr_t )); 70 | // printf( "Texture %i [%s]\n", i, ptexture[i].name ); 71 | // now we can replace offsets with real pointers 72 | // ptexture[i].pixels = (byte *)newhdr + ptexture[i].index; 73 | } 74 | 75 | free( moddata ); 76 | free( texdata ); 77 | } 78 | else 79 | { 80 | #if 0 81 | for( int i = 0; i < phdr->numtextures; i++ ) 82 | { 83 | mstudiotexture_t *ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); 84 | // now we can replace offsets with real pointers 85 | ptexture[i].pixels = (byte *)phdr + ptexture[i].index; 86 | } 87 | #endif 88 | } 89 | 90 | VectorCopy( origin, m->origin ); 91 | VectorCopy( angles, m->angles ); 92 | VectorCopy( scale, m->scale ); 93 | 94 | m->trace_mode = trace_mode; 95 | 96 | m->body = body; 97 | m->skin = skin; 98 | 99 | m->mesh.StudioConstructMesh( m ); 100 | 101 | num_models++; 102 | } 103 | 104 | // ===================================================================================== 105 | // LoadStudioModels 106 | // ===================================================================================== 107 | void LoadStudioModels( void ) 108 | { 109 | memset( models, 0, sizeof( models )); 110 | num_models = 0; 111 | 112 | if( !g_studioshadow ) return; 113 | 114 | for( int i = 0; i < g_numentities; i++ ) 115 | { 116 | const char *name, *model; 117 | vec3_t origin, angles; 118 | 119 | entity_t* e = &g_entities[i]; 120 | name = ValueForKey( e, "classname" ); 121 | 122 | if( !Q_stricmp( name, "env_static" )) 123 | { 124 | int spawnflags = IntForKey( e, "spawnflags" ); 125 | if( spawnflags & 4 ) continue; // shadow disabled 126 | 127 | model = ValueForKey( e, "model" ); 128 | 129 | if( !model || !*model ) 130 | { 131 | Developer( DEVELOPER_LEVEL_WARNING, "env_static has empty model field\n" ); 132 | continue; 133 | } 134 | } 135 | else if( IntForKey( e, "zhlt_studioshadow" )) 136 | { 137 | model = ValueForKey( e, "model" ); 138 | 139 | if( !model || !*model ) 140 | continue; 141 | } 142 | else 143 | { 144 | continue; 145 | } 146 | 147 | GetVectorForKey( e, "origin", origin ); 148 | GetVectorForKey( e, "angles", angles ); 149 | 150 | angles[0] = -angles[0]; // Stupid quake bug workaround 151 | int trace_mode = SHADOW_NORMAL; // default mode 152 | 153 | // make sure what field is present 154 | if( strcmp( ValueForKey( e, "zhlt_shadowmode" ), "" )) 155 | trace_mode = IntForKey( e, "zhlt_shadowmode" ); 156 | 157 | int body = IntForKey( e, "body" ); 158 | int skin = IntForKey( e, "skin" ); 159 | 160 | float scale = FloatForKey( e, "scale" ); 161 | vec3_t xform; 162 | 163 | GetVectorForKey( e, "xform", xform ); 164 | 165 | if( VectorCompare( xform, vec3_origin )) 166 | VectorFill( xform, scale ); 167 | 168 | // check xform values 169 | if( xform[0] < 0.01f ) xform[0] = 1.0f; 170 | if( xform[1] < 0.01f ) xform[1] = 1.0f; 171 | if( xform[2] < 0.01f ) xform[2] = 1.0f; 172 | if( xform[0] > 16.0f ) xform[0] = 16.0f; 173 | if( xform[1] > 16.0f ) xform[1] = 16.0f; 174 | if( xform[2] > 16.0f ) xform[2] = 16.0f; 175 | 176 | LoadStudioModel( model, origin, angles, xform, body, skin, trace_mode ); 177 | } 178 | 179 | Log( "%i opaque studio models\n", num_models ); 180 | } 181 | 182 | void FreeStudioModels( void ) 183 | { 184 | for( int i = 0; i < num_models; i++ ) 185 | { 186 | model_t *m = &models[i]; 187 | 188 | // first, delete the mesh 189 | m->mesh.FreeMesh(); 190 | 191 | // unload the model 192 | Free( m->extradata ); 193 | } 194 | 195 | memset( models, 0, sizeof( models )); 196 | num_models = 0; 197 | } 198 | 199 | void MoveBounds( const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, vec3_t outmins, vec3_t outmaxs ) 200 | { 201 | for( int i = 0; i < 3; i++ ) 202 | { 203 | if( end[i] > start[i] ) 204 | { 205 | outmins[i] = start[i] + mins[i] - 1.0f; 206 | outmaxs[i] = end[i] + maxs[i] + 1.0f; 207 | } 208 | else 209 | { 210 | outmins[i] = end[i] + mins[i] - 1.0f; 211 | outmaxs[i] = start[i] + maxs[i] + 1.0f; 212 | } 213 | } 214 | } 215 | 216 | bool TestSegmentAgainstStudioList( const vec_t* p1, const vec_t* p2 ) 217 | { 218 | if( !num_models ) return false; // easy out 219 | 220 | vec3_t trace_mins, trace_maxs; 221 | 222 | MoveBounds( p1, vec3_origin, vec3_origin, p2, trace_mins, trace_maxs ); 223 | 224 | for( int i = 0; i < num_models; i++ ) 225 | { 226 | model_t *m = &models[i]; 227 | 228 | mmesh_t *pMesh = m->mesh.GetMesh(); 229 | areanode_t *pHeadNode = m->mesh.GetHeadNode(); 230 | 231 | if( !pMesh || !m->mesh.Intersect( trace_mins, trace_maxs )) 232 | continue; // bad model or not intersect with trace 233 | 234 | TraceMesh trm; // a name like Doom3 :-) 235 | 236 | trm.SetTraceModExtradata( m->extradata ); 237 | trm.SetTraceMesh( pMesh, pHeadNode ); 238 | trm.SetupTrace( p1, vec3_origin, vec3_origin, p2 ); 239 | 240 | if( trm.DoTrace()) 241 | return true; // we hit studio model 242 | } 243 | 244 | return false; 245 | } 246 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLRAD/transfers.cpp: -------------------------------------------------------------------------------- 1 | #include "qrad.h" 2 | 3 | #ifdef SYSTEM_WIN32 4 | #include 5 | #include 6 | #include "win32fix.h" 7 | #endif 8 | 9 | #ifdef HAVE_SYS_STAT_H 10 | #include 11 | #endif 12 | 13 | /* 14 | * ============= 15 | * writetransfers 16 | * ============= 17 | */ 18 | 19 | void writetransfers(const char* const transferfile, const long total_patches) 20 | { 21 | FILE *file; 22 | 23 | file = fopen(transferfile, "w+b"); 24 | if (file != NULL) 25 | { 26 | unsigned amtwritten; 27 | patch_t* patch; 28 | 29 | Log("Writing transfers file [%s]\n", transferfile); 30 | 31 | amtwritten = fwrite(&total_patches, sizeof(total_patches), 1, file); 32 | if (amtwritten != 1) 33 | { 34 | goto FailedWrite; 35 | } 36 | 37 | long patchcount = total_patches; 38 | for (patch = g_patches; patchcount-- > 0; patch++) 39 | { 40 | amtwritten = fwrite(&patch->iIndex, sizeof(patch->iIndex), 1, file); 41 | if (amtwritten != 1) 42 | { 43 | goto FailedWrite; 44 | } 45 | 46 | if (patch->iIndex) 47 | { 48 | amtwritten = fwrite(patch->tIndex, sizeof(transfer_index_t), patch->iIndex, file); 49 | if (amtwritten != patch->iIndex) 50 | { 51 | goto FailedWrite; 52 | } 53 | } 54 | 55 | amtwritten = fwrite(&patch->iData, sizeof(patch->iData), 1, file); 56 | if (amtwritten != 1) 57 | { 58 | goto FailedWrite; 59 | } 60 | if (patch->iData) 61 | { 62 | if(g_rgb_transfers) 63 | { 64 | amtwritten = fwrite(patch->tRGBData, vector_size[g_rgbtransfer_compress_type], patch->iData, file); 65 | } 66 | else 67 | { 68 | amtwritten = fwrite(patch->tData, float_size[g_transfer_compress_type], patch->iData, file); 69 | } 70 | if (amtwritten != patch->iData) 71 | { 72 | goto FailedWrite; 73 | } 74 | } 75 | } 76 | 77 | fclose(file); 78 | } 79 | else 80 | { 81 | Error("Failed to open incremenetal file [%s] for writing\n", transferfile); 82 | } 83 | return; 84 | 85 | FailedWrite: 86 | fclose(file); 87 | unlink(transferfile); 88 | //Warning("Failed to generate incremental file [%s] (probably ran out of disk space)\n"); 89 | Warning("Failed to generate incremental file [%s] (probably ran out of disk space)\n", transferfile); //--vluzacn 90 | } 91 | 92 | /* 93 | * ============= 94 | * readtransfers 95 | * ============= 96 | */ 97 | 98 | bool readtransfers(const char* const transferfile, const long numpatches) 99 | { 100 | FILE* file; 101 | long total_patches; 102 | 103 | file = fopen(transferfile, "rb"); 104 | if (file != NULL) 105 | { 106 | unsigned amtread; 107 | patch_t* patch; 108 | 109 | Log("Reading transfers file [%s]\n", transferfile); 110 | 111 | amtread = fread(&total_patches, sizeof(total_patches), 1, file); 112 | if (amtread != 1) 113 | { 114 | goto FailedRead; 115 | } 116 | if (total_patches != numpatches) 117 | { 118 | goto FailedRead; 119 | } 120 | 121 | long patchcount = total_patches; 122 | for (patch = g_patches; patchcount-- > 0; patch++) 123 | { 124 | amtread = fread(&patch->iIndex, sizeof(patch->iIndex), 1, file); 125 | if (amtread != 1) 126 | { 127 | goto FailedRead; 128 | } 129 | if (patch->iIndex) 130 | { 131 | patch->tIndex = (transfer_index_t*)AllocBlock(patch->iIndex * sizeof(transfer_index_t *)); 132 | hlassume(patch->tIndex != NULL, assume_NoMemory); 133 | amtread = fread(patch->tIndex, sizeof(transfer_index_t), patch->iIndex, file); 134 | if (amtread != patch->iIndex) 135 | { 136 | goto FailedRead; 137 | } 138 | } 139 | 140 | amtread = fread(&patch->iData, sizeof(patch->iData), 1, file); 141 | if (amtread != 1) 142 | { 143 | goto FailedRead; 144 | } 145 | if (patch->iData) 146 | { 147 | if(g_rgb_transfers) 148 | { 149 | patch->tRGBData = (rgb_transfer_data_t*)AllocBlock(patch->iData * vector_size[g_rgbtransfer_compress_type] + unused_size); 150 | hlassume(patch->tRGBData != NULL, assume_NoMemory); 151 | amtread = fread(patch->tRGBData, vector_size[g_rgbtransfer_compress_type], patch->iData, file); 152 | } 153 | else 154 | { 155 | patch->tData = (transfer_data_t*)AllocBlock(patch->iData * float_size[g_transfer_compress_type] + unused_size); 156 | hlassume(patch->tData != NULL, assume_NoMemory); 157 | amtread = fread(patch->tData, float_size[g_transfer_compress_type], patch->iData, file); 158 | } 159 | if (amtread != patch->iData) 160 | { 161 | goto FailedRead; 162 | } 163 | } 164 | } 165 | 166 | fclose(file); 167 | //Warning("Finished reading transfers file [%s] %d\n", transferfile); 168 | Warning("Finished reading transfers file [%s]\n", transferfile); //--vluzacn 169 | return true; 170 | } 171 | Warning("Failed to open transfers file [%s]\n", transferfile); 172 | return false; 173 | 174 | FailedRead: 175 | { 176 | unsigned x; 177 | patch_t* patch = g_patches; 178 | 179 | for (x = 0; x < g_num_patches; x++, patch++) 180 | { 181 | FreeBlock(patch->tData); 182 | FreeBlock(patch->tIndex); 183 | patch->iData = 0; 184 | patch->iIndex = 0; 185 | patch->tData = NULL; 186 | patch->tIndex = NULL; 187 | } 188 | } 189 | fclose(file); 190 | unlink(transferfile); 191 | return false; 192 | } 193 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLVIS/sdHLVIS.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {fa63ca73-d52e-4403-b61e-78b2094b9a49} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90 7 | 8 | 9 | {03feec92-a451-440f-9819-099c78f94bd4} 10 | 11 | 12 | {ae1a5973-32d3-4d83-bbd9-44b2d416ca7a} 13 | h;hpp;hxx;hm;inl;fi;fd 14 | 15 | 16 | {a270be60-5229-4d76-aded-9b909ed08a6c} 17 | ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe 18 | 19 | 20 | 21 | 22 | Source Files\common 23 | 24 | 25 | Source Files\common 26 | 27 | 28 | Source Files\common 29 | 30 | 31 | Source Files\common 32 | 33 | 34 | Source Files\common 35 | 36 | 37 | Source Files\common 38 | 39 | 40 | Source Files\common 41 | 42 | 43 | Source Files\common 44 | 45 | 46 | Source Files\common 47 | 48 | 49 | Source Files\common 50 | 51 | 52 | Source Files\common 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLVIS/vis.h: -------------------------------------------------------------------------------- 1 | #ifndef HLVIS_H__ 2 | #define HLVIS_H__ 3 | 4 | #if _MSC_VER >= 1000 5 | #pragma once 6 | #endif 7 | 8 | #include "cmdlib.h" 9 | #include "messages.h" 10 | #include "win32fix.h" 11 | #include "log.h" 12 | #include "hlassert.h" 13 | #include "mathlib.h" 14 | #include "bspfile.h" 15 | #include "threads.h" 16 | #include "filelib.h" 17 | 18 | #include "zones.h" 19 | #include "cmdlinecfg.h" 20 | 21 | #include 22 | #include 23 | 24 | #define DEFAULT_MAXDISTANCE_RANGE 0 25 | 26 | 27 | #define DEFAULT_FULLVIS false 28 | #define DEFAULT_NOFIXPRT false 29 | #define DEFAULT_CHART true //seedee 30 | #define DEFAULT_INFO true 31 | #ifdef SYSTEM_WIN32 32 | #define DEFAULT_ESTIMATE false 33 | #endif 34 | #ifdef SYSTEM_POSIX 35 | #define DEFAULT_ESTIMATE true 36 | #endif 37 | #define DEFAULT_FASTVIS false 38 | #define DEFAULT_NETVIS_PORT 21212 39 | #define DEFAULT_NETVIS_RATE 60 40 | 41 | #define MAX_PORTALS 32768 42 | 43 | //#define USE_CHECK_STACK 44 | #define RVIS_LEVEL_1 45 | #define RVIS_LEVEL_2 46 | 47 | #define PORTALFILE "PRT1" // WTF? 48 | 49 | #define MAX_POINTS_ON_FIXED_WINDING 32 50 | 51 | typedef struct 52 | { 53 | bool original; // don't free, it's part of the portal 54 | int numpoints; 55 | vec3_t points[MAX_POINTS_ON_FIXED_WINDING]; 56 | } winding_t; 57 | 58 | typedef struct 59 | { 60 | vec3_t normal; 61 | float dist; 62 | } plane_t; 63 | 64 | typedef enum 65 | { 66 | stat_none, 67 | stat_working, 68 | stat_done 69 | } vstatus_t; 70 | 71 | typedef struct 72 | { 73 | plane_t plane; // normal pointing into neighbor 74 | int leaf; // neighbor 75 | winding_t* winding; 76 | vstatus_t status; 77 | byte* visbits; 78 | byte* mightsee; 79 | unsigned nummightsee; 80 | int numcansee; 81 | #ifdef ZHLT_NETVIS 82 | int fromclient; // which client did this come from 83 | #endif 84 | UINT32 zone; // Which zone is this portal a member of 85 | } portal_t; 86 | 87 | typedef struct seperating_plane_s 88 | { 89 | struct seperating_plane_s* next; 90 | plane_t plane; // from portal is on positive side 91 | } sep_t; 92 | 93 | typedef struct passage_s 94 | { 95 | struct passage_s* next; 96 | int from, to; // leaf numbers 97 | sep_t* planes; 98 | } passage_t; 99 | 100 | #define MAX_PORTALS_ON_LEAF 256 101 | typedef struct leaf_s 102 | { 103 | unsigned numportals; 104 | passage_t* passages; 105 | portal_t* portals[MAX_PORTALS_ON_LEAF]; 106 | } leaf_t; 107 | 108 | typedef struct pstack_s 109 | { 110 | byte mightsee[MAX_MAP_LEAFS / 8]; // bit string 111 | #ifdef USE_CHECK_STACK 112 | struct pstack_s* next; 113 | #endif 114 | struct pstack_s* head; 115 | 116 | leaf_t* leaf; 117 | portal_t* portal; // portal exiting 118 | winding_t* source; 119 | winding_t* pass; 120 | 121 | winding_t windings[3]; // source, pass, temp in any order 122 | char freewindings[3]; 123 | 124 | const plane_t* portalplane; 125 | 126 | #ifdef RVIS_LEVEL_2 127 | int clipPlaneCount; 128 | plane_t* clipPlane; 129 | #endif 130 | } pstack_t; 131 | 132 | typedef struct 133 | { 134 | byte* leafvis; // bit string 135 | // byte fullportal[MAX_PORTALS/8]; // bit string 136 | portal_t* base; 137 | pstack_t pstack_head; 138 | } threaddata_t; 139 | 140 | 141 | extern bool g_fastvis; 142 | extern bool g_fullvis; 143 | 144 | extern int g_numportals; 145 | extern unsigned g_portalleafs; 146 | 147 | extern unsigned int g_maxdistance; 148 | //extern bool g_postcompile; 149 | 150 | // This allows the current leaf to have portal to selected leaf. 151 | // TODO: vector for target so it can do a lot. Though doing the entity won't be as simple. 152 | // That means we need to parse string and what not. 153 | // For the time being, ONE target is good enough. 154 | #define MAX_ROOM_NEIGHBOR 16 155 | typedef struct 156 | { 157 | int visleafnum; 158 | int target_visleafnum; 159 | // Traversal of neighbors being affected. 160 | int neighbor; 161 | } 162 | room_t; 163 | extern const int g_room_max; 164 | extern room_t g_room[]; 165 | extern int g_room_count; 166 | extern std::unordered_map leaf_flow_add_exclude; 167 | 168 | typedef struct 169 | { 170 | vec3_t origin; 171 | int visleafnum; 172 | int reverse; 173 | } 174 | overview_t; 175 | extern const int g_overview_max; 176 | extern overview_t g_overview[]; 177 | extern int g_overview_count; 178 | 179 | typedef struct 180 | { 181 | bool isoverviewpoint; 182 | bool isskyboxpoint; 183 | // For info_portal 184 | std::vector additional_leaves; 185 | int neighbor; 186 | } 187 | leafinfo_t; 188 | extern leafinfo_t *g_leafinfos; 189 | 190 | extern portal_t*g_portals; 191 | extern leaf_t* g_leafs; 192 | 193 | 194 | extern byte* g_uncompressed; 195 | extern unsigned g_bitbytes; 196 | extern unsigned g_bitlongs; 197 | 198 | extern volatile int g_vislocalpercent; 199 | 200 | extern Zones* g_Zones; 201 | 202 | extern void BasePortalVis(int threadnum); 203 | 204 | 205 | extern void MaxDistVis(int threadnum); 206 | //extern void PostMaxDistVis(int threadnum); 207 | 208 | extern void PortalFlow(portal_t* p); 209 | extern void CalcAmbientSounds(); 210 | 211 | #ifdef ZHLT_NETVIS 212 | #include "packet.h" 213 | #include "c2cpp.h" 214 | #include "NetvisSession.h" 215 | #endif 216 | 217 | #endif // byte fullportal[MAX_PORTALS/8]; // bit string HLVIS_H__ 218 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLVIS/zones.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #include "vis.h" 6 | 7 | 8 | void Zones::set(UINT32 zone, const BoundingBox& bounds) 9 | { 10 | if (zone < m_ZoneCount) 11 | { 12 | m_ZoneBounds[zone] = bounds; 13 | } 14 | } 15 | 16 | UINT32 Zones::getZoneFromBounds(const BoundingBox& bounds) 17 | { 18 | UINT32 x; 19 | for (x=0; xnumedges); 51 | 52 | for (i = 0; i < f->numedges; i++) 53 | { 54 | se = g_dsurfedges[f->firstedge + i]; 55 | if (se < 0) 56 | { 57 | v = g_dedges[-se].v[1]; 58 | } 59 | else 60 | { 61 | v = g_dedges[se].v[0]; 62 | } 63 | 64 | dv = &g_dvertexes[v]; 65 | VectorCopy(dv->point, w->m_Points[i]); 66 | } 67 | 68 | return w; 69 | } 70 | 71 | Zones* MakeZones(void) 72 | { 73 | UINT32 x; 74 | UINT32 func_vis_count = 0; 75 | 76 | ParseEntities(); 77 | 78 | // Note: we arent looping through entities because we only care if it has a winding/bounding box 79 | 80 | // First count the number of func_vis's 81 | for (x=0; xepairs; keyvalue; keyvalue = keyvalue->next) 119 | { 120 | UINT32 other_id = atoi(keyvalue->key); 121 | if (other_id) 122 | { 123 | zones->flag(func_vis_id, other_id); 124 | } 125 | } 126 | } 127 | 128 | { 129 | UINT32 j; 130 | BoundingBox bounds; 131 | dface_t* f = g_dfaces + mod->firstface; 132 | 133 | for (j = 0; j < mod->numfaces; j++, f++) 134 | { 135 | Winding* w = WindingFromFace(f); 136 | UINT32 k; 137 | 138 | for (k = 0; k < w->m_NumPoints; k++) 139 | { 140 | bounds.add(w->m_Points[k]); 141 | } 142 | delete w; 143 | } 144 | 145 | zones->set(func_vis_id, bounds); 146 | 147 | Log("Adding zone %u : mins(%4.3f %4.3f %4.3f) maxs(%4.3f %4.3f %4.3f)\n", func_vis_id, 148 | bounds.m_Mins[0],bounds.m_Mins[1],bounds.m_Mins[2], 149 | bounds.m_Maxs[0],bounds.m_Maxs[1],bounds.m_Maxs[2]); 150 | } 151 | } 152 | } 153 | 154 | return zones; 155 | } 156 | -------------------------------------------------------------------------------- /src/sdhlt/sdHLVIS/zones.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #ifndef ZONING_H__ 6 | #define ZONING_H__ 7 | 8 | #if _MSC_VER >= 1000 9 | #pragma once 10 | #endif 11 | 12 | #include "basictypes.h" 13 | #include "winding.h" 14 | #include "boundingbox.h" 15 | 16 | 17 | // Simple class of visibily flags and zone id's. No concept of location is in this class 18 | class Zones 19 | { 20 | public: 21 | inline void flag(UINT32 src, UINT32 dst) 22 | { 23 | if ((src < m_ZoneCount) && (dst < m_ZoneCount)) 24 | { 25 | m_ZonePtrs[src][dst] = true; 26 | m_ZonePtrs[dst][src] = true; 27 | } 28 | } 29 | inline bool check(UINT32 zone1, UINT32 zone2) 30 | { 31 | if ((zone1 < m_ZoneCount) && (zone2 < m_ZoneCount)) 32 | { 33 | return m_ZonePtrs[zone1][zone2]; 34 | } 35 | return false; 36 | } 37 | 38 | void set(UINT32 zone, const BoundingBox& bounds); 39 | UINT32 getZoneFromBounds(const BoundingBox& bounds); 40 | UINT32 getZoneFromWinding(const Winding& winding); 41 | 42 | public: 43 | Zones(UINT32 ZoneCount) 44 | { 45 | m_ZoneCount = ZoneCount + 1; // Zone 0 is used for all points outside all nodes 46 | m_ZoneVisMatrix = new bool[m_ZoneCount * m_ZoneCount]; 47 | memset(m_ZoneVisMatrix, 0, sizeof(bool) * m_ZoneCount * m_ZoneCount); 48 | m_ZonePtrs = new bool*[m_ZoneCount]; 49 | m_ZoneBounds = new BoundingBox[m_ZoneCount]; 50 | 51 | UINT32 x; 52 | bool* dstPtr = m_ZoneVisMatrix; 53 | bool** srcPtr = m_ZonePtrs; 54 | for (x=0; x 2 | 3 | 4 | 5 | {8c07a06a-b602-4153-9eb4-32a39074ef20} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat 7 | 8 | 9 | {3566b363-ed7d-4789-9fac-9f56a2570beb} 10 | 11 | 12 | {98aaae27-89e6-48db-838f-0216e11f3dec} 13 | h;hpp;hxx;hm;inl 14 | 15 | 16 | {d271b46d-7d17-44c9-a9aa-1f497e487ea7} 17 | ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 18 | 19 | 20 | 21 | 22 | Source Files\common 23 | 24 | 25 | Source Files\common 26 | 27 | 28 | Source Files\common 29 | 30 | 31 | Source Files\common 32 | 33 | 34 | Source Files\common 35 | 36 | 37 | Source Files\common 38 | 39 | 40 | Source Files\common 41 | 42 | 43 | Source Files\common 44 | 45 | 46 | Source Files\common 47 | 48 | 49 | Source Files\common 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files\common 56 | 57 | 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/sdhlt/sdhlt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32819.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdHLBSP", "sdHLBSP\sdHLBSP.vcxproj", "{E75CEB5E-EBAE-1E7D-A626-81604E140A5F}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdHLCSG", "sdHLCSG\sdHLCSG.vcxproj", "{505681C2-3E57-300B-D330-46DD50C147D2}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdHLRAD", "sdHLRAD\sdHLRAD.vcxproj", "{3B5F6C9B-1238-1ECF-14D8-01E4C3AB0EE1}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdHLVIS", "sdHLVIS\sdHLVIS.vcxproj", "{76051CAC-5741-AF85-0C95-3A214F58D9AD}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdRIPENT", "sdRIPENT\sdRIPENT.vcxproj", "{B057E5AD-13AF-2277-D7E0-2A7A16A9340F}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Release|Win32 = Release|Win32 19 | Release|x64 = Release|x64 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {E75CEB5E-EBAE-1E7D-A626-81604E140A5F}.Release|Win32.ActiveCfg = Release|Win32 23 | {E75CEB5E-EBAE-1E7D-A626-81604E140A5F}.Release|Win32.Build.0 = Release|Win32 24 | {E75CEB5E-EBAE-1E7D-A626-81604E140A5F}.Release|x64.ActiveCfg = Release|x64 25 | {E75CEB5E-EBAE-1E7D-A626-81604E140A5F}.Release|x64.Build.0 = Release|x64 26 | {505681C2-3E57-300B-D330-46DD50C147D2}.Release|Win32.ActiveCfg = Release|Win32 27 | {505681C2-3E57-300B-D330-46DD50C147D2}.Release|Win32.Build.0 = Release|Win32 28 | {505681C2-3E57-300B-D330-46DD50C147D2}.Release|x64.ActiveCfg = Release|x64 29 | {505681C2-3E57-300B-D330-46DD50C147D2}.Release|x64.Build.0 = Release|x64 30 | {3B5F6C9B-1238-1ECF-14D8-01E4C3AB0EE1}.Release|Win32.ActiveCfg = Release|Win32 31 | {3B5F6C9B-1238-1ECF-14D8-01E4C3AB0EE1}.Release|Win32.Build.0 = Release|Win32 32 | {3B5F6C9B-1238-1ECF-14D8-01E4C3AB0EE1}.Release|x64.ActiveCfg = Release|x64 33 | {3B5F6C9B-1238-1ECF-14D8-01E4C3AB0EE1}.Release|x64.Build.0 = Release|x64 34 | {76051CAC-5741-AF85-0C95-3A214F58D9AD}.Release|Win32.ActiveCfg = Release|Win32 35 | {76051CAC-5741-AF85-0C95-3A214F58D9AD}.Release|Win32.Build.0 = Release|Win32 36 | {76051CAC-5741-AF85-0C95-3A214F58D9AD}.Release|x64.ActiveCfg = Release|x64 37 | {76051CAC-5741-AF85-0C95-3A214F58D9AD}.Release|x64.Build.0 = Release|x64 38 | {B057E5AD-13AF-2277-D7E0-2A7A16A9340F}.Release|Win32.ActiveCfg = Release|Win32 39 | {B057E5AD-13AF-2277-D7E0-2A7A16A9340F}.Release|Win32.Build.0 = Release|Win32 40 | {B057E5AD-13AF-2277-D7E0-2A7A16A9340F}.Release|x64.ActiveCfg = Release|x64 41 | {B057E5AD-13AF-2277-D7E0-2A7A16A9340F}.Release|x64.Build.0 = Release|x64 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {9690CA90-BBAE-433F-8FBC-2738D808EC72} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /src/sdhlt/template/BaseMath.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #ifndef BASEMATH_H__ 6 | #define BASEMATH_H__ 7 | 8 | #if _MSC_VER >= 1000 9 | #pragma once 10 | #endif // _MSC_VER >= 1000 11 | 12 | #if defined(_WIN32) && !defined(FASTCALL) 13 | #define FASTCALL __fastcall 14 | #endif 15 | 16 | // 17 | // MIN/MAX/AVG functions, work best with basic types 18 | // 19 | 20 | template < typename T > 21 | inline T FASTCALL MIN(const T a, const T b) 22 | { 23 | return ((a < b) ? a : b); 24 | } 25 | 26 | template < typename T > 27 | inline T FASTCALL MIN(const T a, const T b, const T c) 28 | { 29 | return (MIN(MIN(a, b), c)); 30 | } 31 | 32 | template < typename T > 33 | inline T FASTCALL MAX(const T a, const T b) 34 | { 35 | return ((a > b) ? a : b); 36 | } 37 | 38 | template < typename T > 39 | inline T FASTCALL MAX(const T a, const T b, const T c) 40 | { 41 | return (MAX(MAX(a, b), c)); 42 | } 43 | 44 | template < typename T > 45 | inline T FASTCALL AVG(const T a, const T b) 46 | { 47 | return ((a + b) / 2); 48 | } 49 | 50 | // 51 | // MIN/MAX/AVG functions, work best with user-defined types 52 | // (hopefully the compiler will choose the right one in most cases 53 | // 54 | 55 | 56 | template < typename T > 57 | inline T FASTCALL MIN(const T& a, const T& b) 58 | { 59 | return ((a < b) ? a : b); 60 | } 61 | 62 | template < typename T > 63 | inline T FASTCALL MIN(const T& a, const T& b, const T& c) 64 | { 65 | return (MIN(MIN(a, b), c)); 66 | } 67 | 68 | template < typename T > 69 | inline T FASTCALL MAX(const T& a, const T& b) 70 | { 71 | return ((a > b) ? a : b); 72 | } 73 | 74 | template < typename T > 75 | inline T FASTCALL MAX(const T& a, const T& b, const T& c) 76 | { 77 | return (MAX(MAX(a, b), c)); 78 | } 79 | 80 | template < typename T > 81 | inline T FASTCALL AVG(const T& a, const T& b) 82 | { 83 | return ((a + b) / 2); 84 | } 85 | 86 | 87 | // 88 | // Generic Array Operations 89 | // 90 | 91 | template < typename T > 92 | inline T FASTCALL MIN(const T* array, const int size) 93 | { 94 | assert(size); 95 | T val = array[0]; 96 | 97 | for (int i = 1; i < size; i++) 98 | { 99 | if (val > array[i]) 100 | { 101 | val = array[i]; 102 | } 103 | } 104 | return val; 105 | } 106 | 107 | template < typename T > 108 | inline T FASTCALL MAX(const T* array, const int size) 109 | { 110 | assert(size); 111 | T val = array[0]; 112 | 113 | for (int i = 1; i < size; i++) 114 | { 115 | if (val < array[i]) 116 | { 117 | val = array[i]; 118 | } 119 | } 120 | return val; 121 | } 122 | 123 | template < typename T > 124 | inline T FASTCALL AVG(const T* array, const int size) 125 | { 126 | assert(size); 127 | T sum = array[0]; 128 | 129 | for (int i = 1; i < size; i++) 130 | { 131 | sum += array[i]; 132 | } 133 | return sum / num; 134 | } 135 | 136 | template < typename T > 137 | inline T FASTCALL SUM(const T* array, const int size) 138 | { 139 | assert(size); 140 | T sum = array[0]; 141 | 142 | for (int i = 1; i < size; i++) 143 | { 144 | sum += array[i]; 145 | } 146 | return sum; 147 | } 148 | 149 | 150 | // Uses one temp to swap, works best with user-defined types or doubles/long doubles 151 | template < typename T > 152 | inline void FASTCALL SWAP(T& a, T& b) 153 | { 154 | T temp = a; 155 | 156 | a = b; 157 | b = temp; 158 | } 159 | 160 | 161 | // XOR math to swap (no temps), works with integral types very well 162 | template < typename T > 163 | inline void FASTCALL XOR_SWAP(T& a, T& b) 164 | { 165 | a ^= b; 166 | b ^= a; 167 | a ^= b; 168 | } 169 | 170 | 171 | // Uses two temps to swap, works very well with built-in types on pipelined CPUs 172 | template < typename T > 173 | inline void FASTCALL PIPE_SWAP(T& a, T& b) 174 | { 175 | T tmpA = a; 176 | T tmpB = b; 177 | 178 | b = tmpA; 179 | a = tmpB; 180 | } 181 | 182 | 183 | #endif // BASEMATH_H__ 184 | -------------------------------------------------------------------------------- /src/sdhlt/template/EndianMath.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #ifndef ENDIAN_H__ 6 | #define ENDIAN_H__ 7 | 8 | #if _MSC_VER > 1000 9 | #pragma once 10 | #endif // _MSC_VER > 1000 11 | 12 | #include "basictypes.h" 13 | #include "BaseMath.h" 14 | 15 | class Endian 16 | { 17 | public: 18 | inline static INT16 FASTCALL Flip(const INT16 x) 19 | { 20 | INT16 a = (x >> 8) & 0x000FF; 21 | INT16 b = (x << 8) & 0x0FF00; 22 | INT16 rval = (a | b); 23 | return rval; 24 | } 25 | 26 | inline static UINT16 FASTCALL Flip(const UINT16 x) 27 | { 28 | UINT16 a = (x >> 8) & 0x000FF; 29 | UINT16 b = (x << 8) & 0x0FF00; 30 | UINT16 rval = (a | b); 31 | return rval; 32 | } 33 | 34 | inline static INT32 FASTCALL Flip(const INT32 x) 35 | { 36 | INT32 a = (x >> 24) & 0x0000000FF; 37 | INT32 b = (x >> 8) & 0x00000FF00; 38 | INT32 c = (x << 8) & 0x000FF0000; 39 | INT32 d = (x << 24) & 0x0FF000000; 40 | INT32 rval = (a | b | c | d); 41 | return rval; 42 | } 43 | 44 | inline static UINT32 FASTCALL Flip(const UINT32 x) 45 | { 46 | INT32 a = (x >> 24) & 0x0000000FF; 47 | INT32 b = (x >> 8) & 0x00000FF00; 48 | INT32 c = (x << 8) & 0x000FF0000; 49 | INT32 d = (x << 24) & 0x0FF000000; 50 | INT32 rval = (a | b | c | d); 51 | return rval; 52 | } 53 | #if 0 54 | inline static INT64 FASTCALL Flip(const INT64 x) 55 | { 56 | INT64 a = (x >> 56) & 0x000000000000000FF; 57 | INT64 b = (x >> 40) & 0x0000000000000FF00; 58 | INT64 c = (x >> 24) & 0x00000000000FF0000; 59 | INT64 d = (x >> 8 ) & 0x000000000FF000000; 60 | INT64 e = (x << 8 ) & 0x0000000FF00000000; 61 | INT64 f = (x << 24) & 0x00000FF0000000000; 62 | INT64 g = (x << 40) & 0x000FF000000000000; 63 | INT64 h = (x << 56) & 0x0FF00000000000000; 64 | INT64 rval = (a | b | c | d | e | f | g | h); 65 | return rval; 66 | } 67 | 68 | inline static UINT64 FASTCALL Flip(const UINT64 x) 69 | { 70 | UINT64 a = (x >> 56) & 0x000000000000000FF; 71 | UINT64 b = (x >> 40) & 0x0000000000000FF00; 72 | UINT64 c = (x >> 24) & 0x00000000000FF0000; 73 | UINT64 d = (x >> 8 ) & 0x000000000FF000000; 74 | UINT64 e = (x << 8 ) & 0x0000000FF00000000; 75 | UINT64 f = (x << 24) & 0x00000FF0000000000; 76 | UINT64 g = (x << 40) & 0x000FF000000000000; 77 | UINT64 h = (x << 56) & 0x0FF00000000000000; 78 | UINT64 rval = (a | b | c | d | e | f | g | h); 79 | return rval; 80 | } 81 | #endif 82 | inline static float FASTCALL Flip(const float x) 83 | { 84 | union floatflipper 85 | { 86 | struct _x_t 87 | { 88 | BYTE _v[4]; 89 | } _x; 90 | float _f; 91 | }; 92 | 93 | floatflipper tmp; 94 | tmp._f = x; 95 | SWAP(tmp._x._v[0], tmp._x._v[3]); 96 | SWAP(tmp._x._v[1], tmp._x._v[2]); 97 | return tmp._f; 98 | } 99 | 100 | inline static double FASTCALL Flip(const double x) 101 | { 102 | union floatflipper 103 | { 104 | struct _x_t 105 | { 106 | BYTE _v[8]; 107 | } _x; 108 | double _d; 109 | }; 110 | 111 | floatflipper tmp; 112 | tmp._d = x; 113 | SWAP(tmp._x._v[0], tmp._x._v[7]); 114 | SWAP(tmp._x._v[1], tmp._x._v[6]); 115 | SWAP(tmp._x._v[2], tmp._x._v[5]); 116 | SWAP(tmp._x._v[3], tmp._x._v[4]); 117 | return tmp._d; 118 | } 119 | 120 | inline static void FlipArray(unsigned size, INT16* x) 121 | { 122 | for (unsigned i=0 ; i 1000 9 | #pragma once 10 | #endif // _MSC_VER > 1000 11 | 12 | #ifdef WIN32 13 | #define WIN32_LEAN_AND_MEAN 14 | #include "windows.h" 15 | #endif 16 | #include "assert.h" 17 | #include "limits.h" 18 | 19 | #include "ReferenceCounter.h" 20 | 21 | /*! 22 | \author Sean Cavanaugh 23 | \email sean@dimensionalrift.com 24 | \cvsauthor $Author: sean $ 25 | \date $Date: 2000/09/11 20:28:24 $ 26 | \version $Revision: 1.1 $ 27 | \brief ReferenceArray is exactly the same as ReferencePtr, except it expects 28 | the objects pointing to it to be allocated with new[] instead (and thusly 29 | the object is deleted with delete[] when the reference count hits zero) 30 | Additionally it provides a [] operator which returns a refernece to the 31 | item in the list. No bounds checking is performed. 32 | 33 | Arrays of basic data types (char, int, float, etc) should use ReferencePtr, 34 | as delete[] is not required for them. ReferencePtr can also handle void types 35 | as a template parameter. 36 | */ 37 | template 38 | class ReferenceArrayBlock 39 | { 40 | public: 41 | DATA_T* pData; // User defined data block 42 | mutable ReferenceCounter ReferenceCount; 43 | }; 44 | 45 | 46 | template 47 | class ReferenceArray 48 | { 49 | public: 50 | // Construction 51 | ReferenceArray(); 52 | ReferenceArray(DATA_T* other); 53 | ReferenceArray(const ReferenceArray& other); 54 | virtual ~ReferenceArray(); 55 | 56 | // Assignment 57 | ReferenceArray& operator=(const ReferenceArray& other); 58 | ReferenceArray& operator=(DATA_T* other); 59 | 60 | // Dereferencing 61 | operator DATA_T*() const {return m_pData->pData;} 62 | DATA_T& operator[](unsigned int offset) const {return m_pData->pData[offset];} 63 | DATA_T& operator[](int offset) const {return m_pData->pData[offset];} 64 | 65 | protected: 66 | // Internal methods 67 | void Alloc(); // Allocate the m_pData 68 | void Release(); // Releases a reference count (possibly freeing memory) 69 | 70 | protected: 71 | // Member data 72 | ReferenceArrayBlock* m_pData; 73 | }; 74 | 75 | 76 | template 77 | ReferenceArray::ReferenceArray() 78 | { 79 | Alloc(); 80 | } 81 | 82 | template 83 | ReferenceArray::ReferenceArray(DATA_T* other) 84 | { 85 | Alloc(); 86 | m_pData->pData = other; 87 | m_pData->ReferenceCount = 1; 88 | } 89 | 90 | template 91 | ReferenceArray::ReferenceArray(const ReferenceArray& other) 92 | { 93 | m_pData = other.m_pData; 94 | m_pData->ReferenceCount++; 95 | } 96 | 97 | template 98 | ReferenceArray::~ReferenceArray() 99 | { 100 | Release(); 101 | } 102 | 103 | template 104 | ReferenceArray& ReferenceArray::operator=(const ReferenceArray& other) 105 | { 106 | if (m_pData != other.m_pData) 107 | { 108 | Release(); 109 | m_pData = other.m_pData; 110 | m_pData->ReferenceCount++; 111 | } 112 | return *this; 113 | } 114 | 115 | template 116 | ReferenceArray& ReferenceArray::operator=(DATA_T* other) 117 | { 118 | if (m_pData->ReferenceCount.dec() <= 0) 119 | { 120 | delete[] m_pData->pData; 121 | m_pData->pData = other; 122 | m_pData->ReferenceCount = 1; 123 | } 124 | else 125 | { 126 | Alloc(); 127 | m_pData->pData = other; 128 | } 129 | return *this; 130 | } 131 | 132 | template 133 | void ReferenceArray::Alloc() 134 | { 135 | m_pData = new ReferenceArrayBlock; 136 | m_pData->ReferenceCount = 1; 137 | m_pData->pData = NULL; 138 | } 139 | 140 | template 141 | void ReferenceArray::Release() 142 | { 143 | assert(m_pData != NULL); 144 | if (m_pData->ReferenceCount.dec() <= 0) 145 | { 146 | delete[] m_pData->pData; 147 | m_pData->pData = NULL; 148 | delete m_pData; 149 | m_pData = NULL; 150 | } 151 | } 152 | 153 | #endif // !defined(AFX_ReferenceArray_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_) 154 | -------------------------------------------------------------------------------- /src/sdhlt/template/ReferenceCounter.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #ifndef ReferenceCounter_H__ 6 | #define ReferenceCounter_H__ 7 | 8 | #if _MSC_VER > 1000 9 | #pragma once 10 | #endif // _MSC_VER > 1000 11 | 12 | #ifdef _WIN32 13 | #define WIN32_LEAN_AND_MEAN 14 | #include 15 | #endif 16 | 17 | #ifdef HAVE_SYS_ATOMIC_H 18 | #include 19 | #endif 20 | 21 | #ifdef HAVE_ASM_ATOMIC_H 22 | #include 23 | #endif 24 | 25 | /*! 26 | \author Sean Cavanaugh 27 | \email sean@dimensionalrift.com 28 | \cvsauthor $Author: sean $ 29 | \date $Date: 2000/09/11 20:28:24 $ 30 | \version $Revision: 1.1 $ 31 | \brief ReferenceCounter abstracts a reference counted integer with proper thread safe access 32 | The interface is not platform specific in any way, except the protected data 33 | is platform specific, as well as the implementation details 34 | */ 35 | 36 | class ReferenceCounter 37 | { 38 | // Construction 39 | public: 40 | ReferenceCounter(); 41 | ReferenceCounter(int InitialValue); 42 | virtual ~ReferenceCounter() {} // Should optimize to nothing except in the derived-class case 43 | ReferenceCounter(const ReferenceCounter& other) {copy(other);} 44 | ReferenceCounter& operator=(const ReferenceCounter& other) {copy(other); return *this;} 45 | 46 | public: 47 | // User functions 48 | inline int add(int amt);// increment the value by amt, returns the ORIGINAL value 49 | inline int sub(int amt);// increment the value by amt, returns the ORIGINAL value 50 | inline int inc();// increment the value, returns the NEW value 51 | inline int dec();// decrement the value, returns the NEW value 52 | inline int read() const;// read the current value 53 | inline void write(int newvalue);// change the counter to a new value blindly 54 | inline int swap(int newvalue);// change the counter to a new value, and return the ORIGINAL value 55 | 56 | // Convenient Operators 57 | int operator++() {return inc();} 58 | int operator--() {return dec();} 59 | int operator++(int) {return inc() - 1;} 60 | int operator--(int) {return dec() + 1;} 61 | int operator+=(int amt) {return add(amt) + amt;} 62 | int operator-=(int amt) {return sub(amt) - amt;} 63 | int operator=(int value) {write(value); return value;} 64 | operator int() const {return read();} 65 | 66 | // Internal Methods 67 | protected: 68 | inline void copy(const ReferenceCounter& other); 69 | 70 | // Data 71 | protected: 72 | #ifdef SINGLE_THREADED 73 | int m_atom; 74 | #else //SINGLE_THREADED 75 | 76 | #ifdef _WIN32 77 | long m_atom; 78 | #endif 79 | #ifdef HAVE_ATOMIC 80 | atomic_t m_atom; 81 | #endif 82 | 83 | #endif//SINGLE_THREADED 84 | }; 85 | 86 | 87 | #ifdef SINGLE_THREADED 88 | inline ReferenceCounter::ReferenceCounter() 89 | { 90 | m_atom = 0; 91 | } 92 | inline ReferenceCounter::ReferenceCounter(int InitialValue) 93 | { 94 | m_atom = InitialValue; 95 | } 96 | inline int ReferenceCounter::add(int amt) 97 | { 98 | m_atom += amt; 99 | return m_atom; 100 | } 101 | inline int ReferenceCounter::sub(int amt) 102 | { 103 | m_atom -= amt; 104 | return m_atom; 105 | } 106 | inline int ReferenceCounter::inc() 107 | { 108 | m_atom++; 109 | return m_atom; 110 | } 111 | inline int ReferenceCounter::dec() 112 | { 113 | m_atom--; 114 | return m_atom; 115 | } 116 | inline int ReferenceCounter::swap(int newvalue) 117 | { 118 | int rval = m_atom; 119 | m_atom = newvalue; 120 | return rval; 121 | } 122 | inline void ReferenceCounter::write(int newvalue) 123 | { 124 | m_atom = newvalue; 125 | } 126 | inline int ReferenceCounter::read() const 127 | { 128 | return m_atom; 129 | } 130 | inline void ReferenceCounter::copy(const ReferenceCounter& other) 131 | { 132 | m_atom = other.m_atom; 133 | } 134 | #else // SINGLE_THREADED 135 | 136 | #ifdef _WIN32 137 | inline ReferenceCounter::ReferenceCounter() 138 | { 139 | m_atom = 0; 140 | } 141 | inline ReferenceCounter::ReferenceCounter(int InitialValue) 142 | { 143 | m_atom = InitialValue; 144 | } 145 | inline int ReferenceCounter::add(int amt) 146 | { 147 | return InterlockedExchangeAdd(&m_atom, amt); 148 | } 149 | inline int ReferenceCounter::sub(int amt) 150 | { 151 | return InterlockedExchangeAdd(&m_atom, -amt); 152 | } 153 | inline int ReferenceCounter::inc() 154 | { 155 | return InterlockedIncrement(&m_atom); 156 | } 157 | inline int ReferenceCounter::dec() 158 | { 159 | return InterlockedDecrement(&m_atom); 160 | } 161 | inline int ReferenceCounter::swap(int newvalue) 162 | { 163 | return InterlockedExchange(&m_atom, newvalue); 164 | } 165 | inline void ReferenceCounter::write(int newvalue) 166 | { 167 | InterlockedExchange(&m_atom, newvalue); 168 | } 169 | inline int ReferenceCounter::read() const 170 | { 171 | return m_atom; 172 | } 173 | inline void ReferenceCounter::copy(const ReferenceCounter& other) 174 | { 175 | m_atom = other.m_atom; 176 | } 177 | #endif//_WIN32 178 | 179 | #ifdef HAVE_ATOMIC 180 | inline ReferenceCounter::ReferenceCounter() 181 | { 182 | m_atom.counter = 0; 183 | } 184 | inline ReferenceCounter::ReferenceCounter(int InitialValue) 185 | { 186 | m_atom.counter = InitialValue; 187 | } 188 | inline int ReferenceCounter::add(int amt) 189 | { 190 | int rval = atomic_read(&m_atom); 191 | atomic_add(amt, &m_atom); 192 | return rval; 193 | } 194 | inline int ReferenceCounter::sub(int amt) 195 | { 196 | int rval = atomic_read(&m_atom); 197 | atomic_sub(amt, &m_atom); 198 | return rval; 199 | } 200 | inline int ReferenceCounter::inc() 201 | { 202 | int rval = atomic_read(&m_atom); 203 | atomic_inc(&m_atom); 204 | return rval + 1; 205 | } 206 | inline int ReferenceCounter::dec() 207 | { 208 | int rval = atomic_read(&m_atom); 209 | atomic_dec(&m_atom); 210 | return rval - 1; 211 | } 212 | inline int ReferenceCounter::swap(int newvalue) 213 | { 214 | int rval = atomic_read(&m_atom); 215 | atomic_set(&m_atom, newvalue); 216 | return rval; 217 | } 218 | inline void ReferenceCounter::write(int newvalue) 219 | { 220 | atomic_set(&m_atom, newvalue); 221 | } 222 | inline int ReferenceCounter::read() const 223 | { 224 | return atomic_read(&m_atom); 225 | } 226 | inline void ReferenceCounter::copy(const ReferenceCounter& other) 227 | { 228 | m_atom.counter = other.read(); 229 | } 230 | #endif//HAVE_ATOMIC 231 | #endif//SINGLE_THREADED 232 | 233 | #endif//ReferenceCounter_H__ 234 | -------------------------------------------------------------------------------- /src/sdhlt/template/ReferenceObject.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #if !defined(AFX_REFERENCEOBJECT_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_) 6 | #define AFX_REFERENCEOBJECT_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_ 7 | 8 | #if _MSC_VER > 1000 9 | #pragma once 10 | #endif // _MSC_VER > 1000 11 | 12 | #ifdef WIN32 13 | #define WIN32_LEAN_AND_MEAN 14 | #include "windows.h" 15 | #endif 16 | #include "assert.h" 17 | #include "limits.h" 18 | 19 | #include "ReferenceCounter.h" 20 | 21 | template 22 | class ReferenceObjectBlock 23 | { 24 | public: 25 | DATA_T* pData; // User defined data block 26 | mutable ReferenceCounter ReferenceCount; 27 | unsigned int AllocLength; // Current size of array, in T sized units. if AllocLength = 0, pData is const and needs CopyOnWrite 28 | HEADER_T Header; // User defined header block (must be safe to copy with operator=) 29 | }; 30 | 31 | 32 | 33 | /*! 34 | \author Sean Cavanaugh 35 | \email sean@dimensionalrift.com 36 | \cvsauthor $Author: sean $ 37 | \date $Date: 2000/09/11 20:28:24 $ 38 | \version $Revision: 1.1 $ 39 | \brief ReferenceObject is a template class designed to be used a base class for pass-by-reference objects, to that things such as returning objects up the stack efficiently are possible. 40 | \bug EVERY non const function needs its very first operation to be CopyForWrite() 41 | \bug EVERY derived class should define its operator=() to call the ReferenceObject base class version (notice this operator is protected,) 42 | \bug HEADER_T will probably need an operator=() defined for all but the most trivial types 43 | \bug Store objects or simple data types, NO POINTERS (use ReferencePtrObject for that) (they will leak like mad) 44 | 45 | */ 46 | 47 | 48 | 49 | template 50 | class ReferenceObject 51 | { 52 | public: 53 | ReferenceObject(); 54 | ReferenceObject(unsigned int size); 55 | ReferenceObject(const ReferenceObject& other); 56 | virtual ~ReferenceObject(); 57 | 58 | public: 59 | HEADER_T& getHeader(); 60 | DATA_T* getData(); 61 | 62 | ReferenceObject& operator=(const ReferenceObject& other); 63 | 64 | protected: 65 | void AllocBlock(unsigned int size); // Allocate Header+Data Block (size in T units) 66 | void AllocHeader(); // Allocate Header Block 67 | void AllocData(unsigned int size); // Alocate Data Block (size in T units) 68 | 69 | virtual void Release(); // Releases a reference count (possibly freeing memory) 70 | virtual void InitHeader(); // User defined Header Initialization function 71 | virtual void FreeHeader(); // User defined Header destructor function 72 | virtual void CopyForWrite(); // Make unique copy for writing, must first instruction in all non const-functions in derived classes 73 | virtual void CopyForWrite(unsigned int size); // same as CopyForWrite() except takes a resize parameter 74 | 75 | ReferenceObjectBlock* m_pData; 76 | }; 77 | 78 | 79 | template 80 | ReferenceObject::ReferenceObject() 81 | { 82 | m_pData = NULL; 83 | AllocHeader(); 84 | InitHeader(); 85 | } 86 | 87 | template 88 | ReferenceObject::ReferenceObject(unsigned int size) 89 | { 90 | m_pData = NULL; 91 | AllocBlock(size); 92 | } 93 | 94 | template 95 | ReferenceObject::ReferenceObject(const ReferenceObject& other) 96 | { 97 | m_pData = other.m_pData; 98 | m_pData->ReferenceCount++; 99 | } 100 | 101 | template 102 | ReferenceObject::~ReferenceObject() 103 | { 104 | Release(); 105 | } 106 | 107 | template 108 | ReferenceObject& ReferenceObject::operator=(const ReferenceObject& other) 109 | { 110 | if (m_pData != other.m_pData) 111 | { 112 | Release(); 113 | m_pData = other.m_pData; 114 | m_pData->ReferenceCount++; 115 | } 116 | return *this; 117 | } 118 | 119 | template 120 | void ReferenceObject::Release() 121 | { 122 | assert(m_pData != NULL); 123 | if (m_pData->ReferenceCount.dec() <= 0) 124 | { 125 | FreeHeader(); 126 | delete[] m_pData->pData; 127 | delete m_pData; 128 | m_pData = NULL; 129 | } 130 | } 131 | 132 | template 133 | void ReferenceObject::AllocBlock(unsigned int size) 134 | { 135 | AllocHeader(); 136 | AllocData(size); 137 | InitHeader(); // Initialize user defined header 138 | } 139 | 140 | template 141 | void ReferenceObject::AllocHeader() 142 | { 143 | m_pData = new ReferenceObjectBlock; 144 | 145 | m_pData->ReferenceCount = 1; 146 | m_pData->pData = NULL; 147 | m_pData->AllocLength = 0; 148 | } 149 | 150 | template 151 | void ReferenceObject::AllocData(unsigned int size) 152 | { 153 | assert(m_pData != NULL); 154 | assert((size * sizeof(DATA_T)) < INT_MAX); 155 | 156 | if (size) 157 | { 158 | m_pData->pData = new DATA_T[size]; 159 | } 160 | else 161 | { 162 | m_pData->pData = NULL; 163 | } 164 | m_pData->AllocLength = size; 165 | } 166 | 167 | template 168 | void ReferenceObject::InitHeader() 169 | { 170 | // NOTE: Derive this function to initialize the Header object(s) 171 | } 172 | 173 | template 174 | void ReferenceObject::FreeHeader() 175 | { 176 | // NOTE: Derive this function to clean up the Header object(s) 177 | } 178 | 179 | template 180 | void ReferenceObject::CopyForWrite() 181 | { 182 | CopyForWrite(m_pData->AllocLength); 183 | } 184 | 185 | template 186 | void ReferenceObject::CopyForWrite(unsigned int size) 187 | { 188 | unsigned int oldsize = m_pData->AllocLength; 189 | 190 | if (size) 191 | { 192 | if ((m_pData->ReferenceCount > 1) || (size != oldsize)) 193 | { 194 | ReferenceObjectBlock* pTmp = m_pData; 195 | AllocBlock(size); 196 | m_pData->Header = pTmp->Header; 197 | unsigned int sizetocopy = min(size,oldsize); 198 | // memcpy(m_pData->pData, pTmp->pData, min(size,oldsize) * sizeof(DATA_T)); // memcpy not safe for objects 199 | for (unsigned int x=0;xpData[x] = pTmp->pData[x]; 202 | } 203 | if (pTmp->ReferenceCount.dec() <= 0) 204 | { 205 | delete[] pTmp->pData; 206 | delete pTmp; 207 | } 208 | } 209 | } 210 | else // Replace reference to a null object (since size is zero) 211 | { 212 | Release(); 213 | AllocHeader(); 214 | InitHeader(); 215 | } 216 | } 217 | 218 | template 219 | HEADER_T& ReferenceObject::getHeader() 220 | { 221 | CopyForWrite(); 222 | return m_pData->Header; 223 | } 224 | 225 | template 226 | DATA_T* ReferenceObject::getData() 227 | { 228 | CopyForWrite(); 229 | return m_pData->pData; 230 | } 231 | 232 | #endif // !defined(AFX_REFERENCEOBJECT_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_) 233 | -------------------------------------------------------------------------------- /src/sdhlt/template/ReferencePtr.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #if !defined(AFX_ReferencePtr_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_) 6 | #define AFX_ReferencePtr_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_ 7 | 8 | #if _MSC_VER > 1000 9 | #pragma once 10 | #endif // _MSC_VER > 1000 11 | 12 | #ifdef WIN32 13 | #define WIN32_LEAN_AND_MEAN 14 | #include "windows.h" 15 | #endif 16 | #include "assert.h" 17 | #include "limits.h" 18 | 19 | #ifdef SYSTEM_POSIX 20 | #ifdef HAVE_STDDEF_H 21 | // For NULL 22 | #include 23 | #endif 24 | #endif 25 | 26 | #include "ReferenceCounter.h" 27 | 28 | /*! 29 | \author Sean Cavanaugh 30 | \email sean@dimensionalrift.com 31 | \cvsauthor $Author: sean $ 32 | \date $Date: 2000/09/11 20:28:24 $ 33 | \version $Revision: 1.1 $ 34 | \brief ReferencePtr is a simplified ReferencePtr, primiarily for use with reference counted pointers. 35 | Its purpose is solely for simplified garbage collection, and not any kind of advanced 36 | copy on write functionality. Passing a normal pointer to this class effectively starts 37 | its reference count at one and should not be manually deleted. (But it may be referenced 38 | as long as you know the object still exists in some scope somewhere) 39 | */ 40 | template 41 | class ReferencePtrBlock 42 | { 43 | public: 44 | DATA_T* pData; // User defined data block 45 | mutable ReferenceCounter ReferenceCount; 46 | }; 47 | 48 | 49 | template 50 | class ReferencePtr 51 | { 52 | public: 53 | // Construction 54 | ReferencePtr(); 55 | ReferencePtr(DATA_T* other); 56 | ReferencePtr(const ReferencePtr& other); 57 | virtual ~ReferencePtr(); 58 | 59 | // Assignment 60 | ReferencePtr& operator=(const ReferencePtr& other); 61 | ReferencePtr& operator=(DATA_T* other); 62 | 63 | // Dereferencing 64 | operator DATA_T*() const {return m_pData->pData;} 65 | DATA_T* operator->() const {return m_pData->pData;} 66 | 67 | protected: 68 | // Internal methods 69 | void Alloc(); // Allocate the m_pData 70 | void Release(); // Releases a reference count (possibly freeing memory) 71 | 72 | protected: 73 | // Member data 74 | ReferencePtrBlock* m_pData; 75 | }; 76 | 77 | 78 | template 79 | ReferencePtr::ReferencePtr() 80 | { 81 | Alloc(); 82 | } 83 | 84 | template 85 | ReferencePtr::ReferencePtr(DATA_T* other) 86 | { 87 | Alloc(); 88 | m_pData->pData = other; 89 | m_pData->ReferenceCount = 1; 90 | } 91 | 92 | template 93 | ReferencePtr::ReferencePtr(const ReferencePtr& other) 94 | { 95 | m_pData = other.m_pData; 96 | m_pData->ReferenceCount++; 97 | } 98 | 99 | template 100 | ReferencePtr::~ReferencePtr() 101 | { 102 | Release(); 103 | } 104 | 105 | template 106 | ReferencePtr& ReferencePtr::operator=(const ReferencePtr& other) 107 | { 108 | if (m_pData != other.m_pData) 109 | { 110 | Release(); 111 | m_pData = other.m_pData; 112 | m_pData->ReferenceCount++; 113 | } 114 | return *this; 115 | } 116 | 117 | template 118 | ReferencePtr& ReferencePtr::operator=(DATA_T* other) 119 | { 120 | if (m_pData->ReferenceCount.dec() <= 0) 121 | { 122 | delete m_pData->pData; 123 | m_pData->pData = other; 124 | m_pData->ReferenceCount = 1; 125 | } 126 | else 127 | { 128 | Alloc(); 129 | m_pData->pData = other; 130 | } 131 | return *this; 132 | } 133 | 134 | template 135 | void ReferencePtr::Alloc() 136 | { 137 | m_pData = new ReferencePtrBlock; 138 | m_pData->ReferenceCount = 1; 139 | m_pData->pData = NULL; 140 | } 141 | 142 | template 143 | void ReferencePtr::Release() 144 | { 145 | assert(m_pData != NULL); 146 | if (m_pData->ReferenceCount.dec() <= 0) 147 | { 148 | delete m_pData->pData; 149 | m_pData->pData = NULL; 150 | delete m_pData; 151 | m_pData = NULL; 152 | } 153 | } 154 | 155 | #endif // !defined(AFX_ReferencePtr_H__BAEBCE9D_CD68_40AF_8A54_B23A0D14E807__INCLUDED_) 156 | -------------------------------------------------------------------------------- /src/sdhlt/template/basictypes.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2000 Sean Cavanaugh 2 | // This file is licensed under the terms of the Lesser GNU Public License 3 | // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt) 4 | 5 | #if 0 // linux fix --vluzacn 6 | // AJM GNU 7 | #ifdef __GNUC__ 8 | #define __int64 long long 9 | #endif 10 | #endif 11 | 12 | #ifndef BASICTYPES_H__ 13 | #define BASICTYPES_H__ 14 | 15 | #if _MSC_VER > 1000 16 | #pragma once 17 | #endif /* _MSC_VER > 1000 */ 18 | 19 | #if defined(_WIN32) || defined(SYSTEM_WIN32) 20 | 21 | #undef CHAR 22 | #undef BYTE 23 | #undef INT 24 | #undef UINT 25 | #undef INT8 26 | #undef UINT8 27 | #undef INT16 28 | #undef UINT16 29 | #undef INT32 30 | #undef UINT32 31 | #undef INT64 32 | #undef UINT64 33 | typedef char CHAR; 34 | typedef unsigned char BYTE; 35 | typedef signed int INT; 36 | typedef unsigned int UINT; 37 | typedef signed char INT8; 38 | typedef unsigned char UINT8; 39 | typedef signed short INT16; 40 | typedef unsigned short UINT16; 41 | typedef signed int INT32; 42 | typedef unsigned int UINT32; 43 | typedef signed __int64 INT64; 44 | typedef unsigned __int64 UINT64; 45 | 46 | #endif /* SYSTEM_WIN32 */ 47 | 48 | #ifdef SYSTEM_POSIX 49 | 50 | #undef CHAR 51 | #undef BYTE 52 | #undef INT 53 | #undef UINT 54 | #undef INT8 55 | #undef UINT8 56 | #undef INT16 57 | #undef UINT16 58 | #undef INT32 59 | #undef UINT32 60 | #undef INT64 61 | #undef UINT64 62 | typedef char CHAR; 63 | typedef unsigned char BYTE; 64 | typedef signed int INT; 65 | typedef unsigned int UINT; 66 | typedef signed char INT8; 67 | typedef unsigned char UINT8; 68 | typedef signed short INT16; 69 | typedef unsigned short UINT16; 70 | typedef signed int INT32; 71 | typedef unsigned int UINT32; 72 | /* typedef __int64 INT64; */ 73 | /* typedef unsigned __int64 UINT64; */ 74 | 75 | #endif /* SYSTEM_POSIX */ 76 | 77 | #endif /* BASICTYPES_H__ */ 78 | -------------------------------------------------------------------------------- /tools/lights.rad: -------------------------------------------------------------------------------- 1 | //+0~GENERIC65 255 255 255 750 2 | //+0~GENERIC85 255 255 255 20000 3 | //+0~GENERIC86 255 255 255 10000 4 | //+0~GENERIC86B 255 255 255 20000 5 | //+0~GENERIC86R 255 255 255 60000 6 | //GENERIC87A 255 255 255 1000 7 | //GENERIC88A 255 255 255 1000 8 | //GENERIC89A 255 255 255 1000 9 | //GENERIC90A 255 255 255 1000 10 | //GENERIC105 255 255 255 1000 11 | //GENERIC106 255 255 255 1000 12 | //GENERIC107 255 255 255 1000 13 | //GEN_VEND1 255 255 255 1000 14 | //EMERGLIGHT 255 255 255 50000 15 | //+0~FIFTS_LGHT01 255 255 255 4000 16 | //+0~FIFTIES_LGT2 255 255 255 5000 17 | //+0~FIFTS_LGHT4 255 255 255 4000 18 | //+0~LIGHT1 255 255 255 3000 19 | //+0~LIGHT3A 255 255 255 10000 20 | //+0~LIGHT4A 255 255 255 11000 21 | //+0~LIGHT5A 255 255 255 10000 22 | //+0~LIGHT6A 255 255 255 25000 23 | //+0~TNNL_LGT1 255 255 255 10000 24 | //+0~TNNL_LGT2 255 255 255 12000 25 | //+0~TNNL_LGT3 255 255 255 17000 26 | //+0~TNNL_LGT4 255 255 255 10000 27 | //+0LAB1_W6D 255 255 255 4000 28 | //+0LAB1_W6 255 255 255 8800 29 | //+0LAB1_W7 255 255 255 4000 30 | //SKKYLITE 255 255 255 1000 31 | //+0~DRKMTLS1 255 255 255 6000 32 | //+0~DRKMTLGT1 255 255 255 6000 33 | //+0~DRKMTLS2 255 255 255 30000 34 | //+0~DRKMTLS2C 255 255 255 50000 35 | //+0DRKMTL_SCRN 255 255 255 10000 36 | //~LAB_CRT9A 255 255 255 100 37 | //~LAB_CRT9B 255 255 255 100 38 | //~LAB_CRT9C 255 255 255 100 39 | //~LIGHT3A 255 255 255 3000 40 | //~LIGHT3B 255 255 255 2000 41 | //~LIGHT3C 255 255 255 2500 42 | //~LIGHT3E 255 255 255 6000 43 | //C1A3C_MAP 255 255 255 100 44 | //FIFTIES_MON1B 255 255 255 30 45 | //+0~LAB_CRT8 255 255 255 100 46 | //ELEV2_CIEL 255 255 255 800 47 | //YELLOW 255 255 255 2000 48 | //RED 255 255 255 1000 49 | -------------------------------------------------------------------------------- /tools/sdhlt.wad: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seedee/SDHLT/9b94e4fd1c4392802e1a01256596ea69894afc49/tools/sdhlt.wad -------------------------------------------------------------------------------- /tools/settings.txt: -------------------------------------------------------------------------------- 1 | 2 | // This file is loaded each time the compiler start. It can modify the command line parameters. 3 | // This file can be used to alter default parameters without changing the binaries. 4 | 5 | 6 | // How does this file work : 7 | // Basically, it directly modifies the command line when the program starts. 8 | // The command line is treated as a sequence of parameters. 9 | // For example, the command line 10 | // tools\hlrad.exe "My Maps\mymap" -extra -texchop 64 11 | // is converted into 5 parameters: 12 | // "" (the first parameter will always be replaced by the program name) 13 | // "My Maps\mymap" 14 | // "-extra" 15 | // "-texchop" 16 | // "64" 17 | // . 18 | // This file is composed of commands. Each word that begins with '#' is a command. Some commands can be followed with a sequence of parameters (denote as A B C). 19 | // If a parameter has space in itself, it should be quoted by '"'. 20 | // List of commands: 21 | // #ifdef A B C If there is a sequence of parameters in the command line that matches A B C, execute the following commands till an '#else' or '#endif'. 22 | // #ifndef A B C If there is not a sequence of parameters in the command line that matches A B C, execute the following commands till an '#else' or '#endif'. 23 | // #else If previous commands has been skipped, execute the following commands till an '#else' or '#endif'. 24 | // #define A B C Add parameters A B C to the end of the command line. 25 | // #undef A B C Remove any sequence of patamenters in the command line that matches A B C. 26 | // Special kinds of parameter: 27 | // First character is '*' Match any parameter that ends with certain word. 28 | // Last character is '*' Match any parameter that begins with certain word. 29 | 30 | 31 | 32 | // List of frequently used parameters: 33 | // 34 | // Shared: 35 | // -low 36 | // -estimate 37 | // -chart 38 | // 39 | // HLCSG: 40 | // -onlyents 41 | // -wadautodetect 42 | // -nowadtextures 43 | // -wadinclude # 44 | // -wadcfgfile # 45 | // 46 | // HLBSP: 47 | // -maxnodesize # 48 | // 49 | // HLVIS: 50 | // -fast 51 | // -full 52 | // 53 | // HLRAD: 54 | // -limiter # 55 | // -fast 56 | // -extra 57 | // -blur # 58 | // -smooth # 59 | // -smooth2 # 60 | // -texreflectscale # 61 | // -chop # 62 | // -texchop # 63 | // -drawoverload 64 | // -gamma # 65 | // -minlight # 66 | // 67 | // RIPENT: 68 | // -export 69 | // -import 70 | // -parse 71 | // -textureexport 72 | // -textureimport 73 | // -textureparse 74 | 75 | 76 | 77 | #ifndef // CSG\BSP\VIS\RAD 78 | #ifndef -high 79 | #ifndef -low 80 | #define -low 81 | #endif 82 | #endif 83 | #ifndef -console 0 84 | //#define -estimate 85 | #endif 86 | #endif 87 | 88 | #ifdef // CSG 89 | #ifndef -wadautodetect 90 | #define -wadautodetect 91 | #endif 92 | #endif 93 | 94 | #ifdef // BSP 95 | #ifndef -chart 96 | #define -chart 97 | #endif 98 | #endif 99 | 100 | #ifdef // VIS 101 | #ifndef -full 102 | //#define -full 103 | #endif 104 | #endif 105 | 106 | #ifdef // RAD 107 | #ifdef -sparse 108 | #undef -sparse 109 | #define -vismatrix sparse 110 | #endif 111 | #ifdef -nomatrix 112 | #undef -nomatrix 113 | #define -vismatrix off 114 | #endif 115 | #endif 116 | 117 | #ifdef // RIPENT 118 | #endif 119 | 120 | -------------------------------------------------------------------------------- /tools/wad.cfg: -------------------------------------------------------------------------------- 1 | // GAME TEXTURE WAD CONFIGURATION FILE for SDHLT 2 | 3 | // use this file to set the different .wad files to be written into 4 | // the .bsp file by CSG regardless of the .wad files you might have 5 | // configured in Worldcraft. 6 | 7 | // if you want to use the configurations in this file, you MUST 8 | // specify the apropriate configuration with the 9 | // -wadconfig configration_name 10 | // parameter on CSG. otherwise, the wadfile paths in the mapfile 11 | // will be used. 12 | 13 | // if you DO specify a configuration, the wadfile paths specified 14 | // in the map file will be ignored. basically, its either this file 15 | // or the map file, not a mixture of both. 16 | 17 | // if you want to wadinclude a specific file, you may do so using 18 | // the "include" prefix. the valve configuration below has an 19 | // example commented out. all 3 examples in this file are perfectly 20 | // valid, use whichever method you are comfortable with. 21 | 22 | // make sure you change these paths to the real path to your 23 | // Half-Life directory. note, the syntax of this file has changed 24 | // significantly since version 1.4 25 | 26 | // "include" will act like -wadinclude 27 | //include "C:\Program Files (x86)\Steam\steamapps\common\Half-Life\valve\mywad.wad" 28 | 29 | valve 30 | { 31 | //C:\Sierra\Half-Life\valve\halflife.wad 32 | //C:\Sierra\Half-Life\valve\liquids.wad 33 | //C:\Sierra\Half-Life\valve\xeno.wad 34 | //C:\Sierra\Half-Life\valve\decals.wad 35 | //C:\Sierra\Half-Life\valve\mywad.wad 36 | //"C:\Program Files (x86)\Half-Life\valve\halflife.wad" 37 | //"C:\Program Files (x86)\Half-Life\valve\liquids.wad" 38 | //"C:\Program Files (x86)\Half-Life\valve\xeno.wad" 39 | //"C:\Program Files (x86)\Half-Life\valve\decals.wad" 40 | //"C:\Program Files (x86)\Half-Life\valve\mywad.wad" 41 | "C:\Program Files (x86)\Steam\steamapps\common\Half-Life\valve\halflife.wad" 42 | } 43 | 44 | tfc 45 | { 46 | // standard half-life wads 47 | c:\Sierra\Half-Life\valve\halflife.wad c:\Sierra\Half-Life\valve\liquids.wad 48 | c:\Sierra\Half-Life\valve\decals.wad c:\Sierra\Half-Life\valve\xeno.wad 49 | 50 | // tfc specific wads 51 | c:\Sierra\Half-Life\tfc\tfc.wad c:\Sierra\Half-Life\tfc\tfc2.wad 52 | } 53 | 54 | cs 55 | { 56 | // counter-strike specific wads 57 | c:\Sierra\Half-Life\cstrike\n0th1ng.wad 58 | c:\Sierra\Half-Life\cstrike\cstrike.wad 59 | 60 | // standard half-life wads 61 | c:\Sierra\Half-Life\valve\halflife.wad 62 | c:\Sierra\Half-Life\valve\liquids.wad 63 | c:\Sierra\Half-Life\valve\xeno.wad 64 | c:\Sierra\Half-Life\valve\decals.wad 65 | } 66 | --------------------------------------------------------------------------------