├── BlenderSrc ├── SpyroE5.blend ├── omni.bmp ├── omni_opened.blend └── spyro1024.bmp ├── Map ├── Map.sln ├── Map.vcxproj ├── RotMatrix.cpp ├── mainForm.cpp ├── mainForm.h ├── mainForm.resx ├── omni │ ├── FACES.bin │ ├── FPXYZ.bin │ ├── cindex.bin │ ├── clist.bin │ ├── faces_in_leafs.bin │ ├── fil_idx.bin │ ├── kdtree.bin │ ├── pvs.bin │ ├── pvs_idx.bin │ ├── texture.bin │ ├── texture.c32 │ ├── texture32c.bmp │ ├── textures.bmp │ └── world.obj ├── render.cpp ├── render.h ├── render2d.cpp ├── render3d.cpp ├── renderinit.cpp ├── rendermove.cpp ├── renderutils.cpp ├── renderutils.h └── spyro │ ├── FACES.bin │ ├── FPXYZ.bin │ ├── cindex.bin │ ├── clist.bin │ ├── faces_in_leafs.bin │ ├── fil_idx.bin │ ├── kdtree.bin │ ├── pvs.bin │ ├── pvs_idx.bin │ ├── texture.bin │ ├── texture32c.bmp │ ├── textures.bmp │ └── world.obj ├── README.md ├── SDDDE ├── .vscode │ ├── amiga.json │ ├── c_cpp_properties.json │ ├── launch.json │ └── tasks.json ├── Makefile ├── asm │ ├── c2p.s │ ├── fmap.s │ ├── navigate.s │ ├── render_utils.s │ └── tmap.s ├── font.c ├── logtab.c ├── main.c ├── omni │ ├── FACES.bin │ ├── FPXYZ.bin │ ├── cindex.bin │ ├── clist.bin │ ├── faces_in_leafs.bin │ ├── fil_idx.bin │ ├── kdtree.bin │ ├── pvs.bin │ ├── pvs_idx.bin │ ├── texture.bin │ └── texture.c32 ├── render.h ├── render.s ├── spyro │ ├── FACES.bin │ ├── FPXYZ.bin │ ├── cindex.bin │ ├── clist.bin │ ├── faces_in_leafs.bin │ ├── fil_idx.bin │ ├── kdtree.bin │ ├── pvs.bin │ ├── pvs_idx.bin │ └── texture.bin └── support │ ├── gcc8_a_support.s │ ├── gcc8_c_support.c │ └── gcc8_c_support.h ├── SplitMap ├── SplitMap.cpp ├── SplitMap.sln ├── SplitMap.vcxproj ├── clipper.cpp ├── clipper.hpp └── render.h └── target ├── a.mingw.exe └── omni ├── FACES.bin ├── FPXYZ.bin ├── cindex.bin ├── clist.bin ├── faces_in_leafs.bin ├── fil_idx.bin ├── kdtree.bin ├── pvs.bin ├── pvs_idx.bin ├── texture.bin └── texture.c32 /BlenderSrc/SpyroE5.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/BlenderSrc/SpyroE5.blend -------------------------------------------------------------------------------- /BlenderSrc/omni.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/BlenderSrc/omni.bmp -------------------------------------------------------------------------------- /BlenderSrc/omni_opened.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/BlenderSrc/omni_opened.blend -------------------------------------------------------------------------------- /BlenderSrc/spyro1024.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/BlenderSrc/spyro1024.bmp -------------------------------------------------------------------------------- /Map/Map.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32002.261 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Map", "Map.vcxproj", "{15781CEA-6207-4321-A8BC-703708118CDE}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {15781CEA-6207-4321-A8BC-703708118CDE}.Debug|x64.ActiveCfg = Debug|x64 17 | {15781CEA-6207-4321-A8BC-703708118CDE}.Debug|x64.Build.0 = Debug|x64 18 | {15781CEA-6207-4321-A8BC-703708118CDE}.Debug|x86.ActiveCfg = Debug|Win32 19 | {15781CEA-6207-4321-A8BC-703708118CDE}.Debug|x86.Build.0 = Debug|Win32 20 | {15781CEA-6207-4321-A8BC-703708118CDE}.Release|x64.ActiveCfg = Release|x64 21 | {15781CEA-6207-4321-A8BC-703708118CDE}.Release|x64.Build.0 = Release|x64 22 | {15781CEA-6207-4321-A8BC-703708118CDE}.Release|x86.ActiveCfg = Release|Win32 23 | {15781CEA-6207-4321-A8BC-703708118CDE}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {030B15D3-EBD2-49F7-A1EA-CB946B9B1113} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Map/Map.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | {15781CEA-6207-4321-A8BC-703708118CDE} 24 | v4.7.2 25 | ManagedCProj 26 | Map 27 | 10.0 28 | 29 | 30 | 31 | Application 32 | true 33 | v142 34 | true 35 | Unicode 36 | 37 | 38 | Application 39 | false 40 | v142 41 | true 42 | Unicode 43 | 44 | 45 | Application 46 | true 47 | v142 48 | true 49 | Unicode 50 | 51 | 52 | Application 53 | false 54 | v142 55 | true 56 | Unicode 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Level3 80 | WIN32;_DEBUG;%(PreprocessorDefinitions) 81 | stdcpp17 82 | 83 | 84 | 85 | User32.lib %(AdditionalOptions) 86 | 87 | 88 | 89 | 90 | Level3 91 | _DEBUG;%(PreprocessorDefinitions) 92 | stdcpp17 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | Level3 101 | WIN32;NDEBUG;%(PreprocessorDefinitions) 102 | stdcpp17 103 | 104 | 105 | 106 | User32.lib %(AdditionalOptions) 107 | 108 | 109 | 110 | 111 | Level3 112 | NDEBUG;%(PreprocessorDefinitions) 113 | stdcpp17 114 | 115 | 116 | Ws2_32.lib 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | CppForm 139 | 140 | 141 | 142 | 143 | 144 | 145 | mainForm.h 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /Map/RotMatrix.cpp: -------------------------------------------------------------------------------- 1 | #include "render.h" 2 | 3 | #if 0 4 | void MulMatrixFIXP32(FIXP32* a, FIXP32* b) 5 | { 6 | FIXP32 t0,t1,t2; 7 | t0 = a[0] * b[0] + a[1] * b[3] + a[2] * b[6]; 8 | t1 = a[0] * b[1] + a[1] * b[4] + a[2] * b[7]; 9 | t2 = a[0] * b[2] + a[1] * b[5] + a[2] * b[8]; 10 | a[0] = t0>>14; a[1] = t1>>14; a[2] = t2>>14; 11 | t0 = a[3] * b[0] + a[4] * b[3] + a[5] * b[6]; 12 | t1 = a[3] * b[1] + a[4] * b[4] + a[5] * b[7]; 13 | t2 = a[3] * b[2] + a[4] * b[5] + a[5] * b[8]; 14 | a[3] = t0>>14; a[4] = t1>>14; a[5] = t2>>14; 15 | t0 = a[6] * b[0] + a[7] * b[3] + a[8] * b[6]; 16 | t1 = a[6] * b[1] + a[7] * b[4] + a[8] * b[7]; 17 | t2 = a[6] * b[2] + a[7] * b[5] + a[8] * b[8]; 18 | a[6] = t0>>14; a[7] = t1>>14; a[8] = t2>>14; 19 | } 20 | #endif 21 | 22 | FIXP32 RMTXp[9]= 23 | { 24 | #if 0 25 | 0x3FFF,0,0, 26 | 0,0x3FFF,0, 27 | 0,0,0x3FFF 28 | #else 29 | 0,0,0x4000, 30 | 0,0x4000,0, 31 | 0,0,0x4000, 32 | #endif 33 | }; 34 | 35 | FIXP32 RMTX[9]= 36 | { 37 | 0x3FFF,0,0, 38 | 0,0x3FFF,0, 39 | 0,0,0x3FFF 40 | }; 41 | 42 | FIXP32 BMATRIX[256 * 3 * 3]; 43 | 44 | #define BM_BITS (7) 45 | 46 | void ConstructBMATRIX(FIXP32* m) 47 | { 48 | FIXP32 cc[3]; 49 | cc[0] = CamX; 50 | cc[1] = CamY; 51 | cc[2] = CamZ; 52 | FIXP32* D = BMATRIX; 53 | for (int j = 0; j < 3; j++) 54 | { 55 | FIXP32 Z; 56 | FIXP32 dZ; 57 | FIXP32 X; 58 | FIXP32 dX; 59 | FIXP32 Y; 60 | FIXP32 dY; 61 | 62 | D += 3 * (128 - (1UL << BM_BITS)); 63 | 64 | //X 65 | dX = m[0]; 66 | X = dX >> 1; 67 | X -= dX << BM_BITS; 68 | X -= (dX * cc[j]) >> 9; 69 | //Y 70 | dY = m[1] * 160 / 100; 71 | Y = dY >> 1; 72 | Y -= dY << BM_BITS; 73 | Y -= (dY * cc[j]) >> 9; 74 | //Z 75 | dZ = m[2]; 76 | Z = dZ >> 1; 77 | Z -= dZ << BM_BITS; 78 | Z -= (dZ * cc[j]) >> 9; 79 | Z += 14189 / 3; 80 | // 81 | for (int i = 0; i < (2<> 1; 112 | v1 += dv1 >> 1; 113 | v2 += dv2 >> 1; 114 | v0 -= (CamX * dv0) >> 9; 115 | v1 -= (CamX * dv1) >> 9; 116 | v2 -= (CamX * dv2) >> 9; 117 | i = 256; 118 | do 119 | { 120 | *d++ = v0; v0 += dv0; 121 | *d++ = v1; v1 += dv1; 122 | *d++ = v2; v2 += dv2; 123 | } while (--i); 124 | //Координата Y 125 | //Тут мы учтем, что Y у нас надо увеличить на пропорции экрана, чтобы правильно обрезать 126 | v0 = -(dv0 = RMTX[3]) << 7; 127 | v1 = -(dv1 = RMTX[4] * 160 / 100) << 7; 128 | v2 = -(dv2 = RMTX[5]) << 7; 129 | v0 += dv0 >> 1; 130 | v1 += dv1 >> 1; 131 | v2 += dv2 >> 1; 132 | v0 -= (CamY * dv0) >> 9; 133 | v1 -= (CamY * dv1) >> 9; 134 | v2 -= (CamY * dv2) >> 9; 135 | i = 256; 136 | do 137 | { 138 | *d++ = v0; v0 += dv0; 139 | *d++ = v1; v1 += dv1; 140 | *d++ = v2; v2 += dv2; 141 | } while (--i); 142 | //Координата Z, тут мы сразу прибавим R 143 | v0 = -(dv0 = RMTX[6]) << 7; 144 | v1 = -(dv1 = RMTX[7] * 160 / 100) << 7; 145 | v2 = -(dv2 = RMTX[8]) << 7; 146 | v0 += dv0 >> 1; 147 | v1 += dv1 >> 1; 148 | v2 += dv2 >> 1; 149 | v0 -= (CamZ * dv0) >> 9; 150 | v1 -= (CamZ * dv1) >> 9; 151 | v2 -= (CamZ * dv2) >> 9; 152 | v2 += 14189; //sqrt(3)/2*16384 153 | i = 256; 154 | do 155 | { 156 | *d++ = v0; v0 += dv0; 157 | *d++ = v1; v1 += dv1; 158 | *d++ = v2; v2 += dv2; 159 | } while (--i); 160 | } 161 | 162 | #if 0 163 | //Считаем матрицу поворота 164 | void PrepareRotMatrix(float YAW, float PITCH, float ROLL) 165 | { 166 | //Уже суммарный вариант, но оси не те 167 | float Sx, Sy, Sz, Cx, Cy, Cz; 168 | Sx = sinf(FM_PI * 2.0f * PITCH); 169 | Cx = cosf(FM_PI * 2.0f * PITCH); 170 | Sy = sinf(FM_PI * 2.0f * YAW); 171 | Cy = cosf(FM_PI * 2.0f * YAW); 172 | Sz = sinf(FM_PI * 2.0f * ROLL); 173 | Cz = cosf(FM_PI * 2.0f * ROLL); 174 | RotMatrix[0] = Cy * Cz; 175 | RotMatrix[1] = -Cy * Sz; 176 | RotMatrix[2] = Sy; 177 | RotMatrix[3] = Cz * Sx * Sy + Cx * Sz; 178 | RotMatrix[4] = Cx * Cz - Sx * Sy * Sz; 179 | RotMatrix[5] = -Cy * Sx; 180 | RotMatrix[6] = -Cx * Cz * Sy + Sx * Sz; 181 | RotMatrix[7] = Cz * Sx + Cx * Sy * Sz; 182 | RotMatrix[8] = Cx * Cy; 183 | UpdateRMTX(); 184 | } 185 | 186 | 187 | void PrepareRotMatrixFIXP32(FIXP32 *m, float YAW, float PITCH, float ROLL) 188 | { 189 | //Уже суммарный вариант, но оси не те 190 | float Sx, Sy, Sz, Cx, Cy, Cz; 191 | float RotMatrix[9]; 192 | Sx = sinf(FM_PI * 2.0f * PITCH); 193 | Cx = cosf(FM_PI * 2.0f * PITCH); 194 | Sy = sinf(FM_PI * 2.0f * YAW); 195 | Cy = cosf(FM_PI * 2.0f * YAW); 196 | Sz = sinf(FM_PI * 2.0f * ROLL); 197 | Cz = cosf(FM_PI * 2.0f * ROLL); 198 | RotMatrix[0] = Cy * Cz; 199 | RotMatrix[1] = -Cy * Sz; 200 | RotMatrix[2] = Sy; 201 | RotMatrix[3] = Cz * Sx * Sy + Cx * Sz; 202 | RotMatrix[4] = Cx * Cz - Sx * Sy * Sz; 203 | RotMatrix[5] = -Cy * Sx; 204 | RotMatrix[6] = -Cx * Cz * Sy + Sx * Sz; 205 | RotMatrix[7] = Cz * Sx + Cx * Sy * Sz; 206 | RotMatrix[8] = Cx * Cy; 207 | for (int i = 0; i < 9; i++) 208 | { 209 | m[i] = (FIXP32)(RotMatrix[i] * 16384.0f/* + 0.5f*/); //Два защитных бита 210 | } 211 | } 212 | #endif 213 | 214 | FIXP32 mtx_error; 215 | 216 | #if 0 217 | static void RotateAndNormalizeMatrix(float * RotMatrix, float YAW, float PITCH, float ROLL) 218 | { 219 | float um[9]; 220 | //Проворот 221 | um[0] = 1.0f; 222 | um[1] = 0.0f; 223 | um[2] = 0.0f; 224 | um[3] = 0.0f; 225 | um[4] = 1.0f; 226 | um[5] = 0.0f; 227 | um[6] = 0.0f; 228 | um[7] = 0.0f; 229 | um[8] = 1.0f; 230 | float rm[9]; 231 | float s, c; 232 | //Поворот по крену, вокруг оси Z 233 | s = sinf(FM_PI * 2.0f * ROLL); 234 | c = cosf(FM_PI * 2.0f * ROLL); 235 | rm[0] = c; rm[1] = -s; rm[2] = 0; 236 | rm[3] = s; rm[4] = c; rm[5] = 0; 237 | rm[6] = 0; rm[7] = 0; rm[8] = 1; 238 | MulMatrix(um, rm); 239 | //Поворот по питчу, вокруг оси X 240 | s = sinf(FM_PI * 2.0f * PITCH); 241 | c = cosf(FM_PI * 2.0f * PITCH); 242 | rm[0] = 1; rm[1] = 0; rm[2] = 0; 243 | rm[3] = 0; rm[4] = c; rm[5] = s; 244 | rm[6] = 0; rm[7] = -s; rm[8] = c; 245 | MulMatrix(um, rm); 246 | //Поворот по курсу, вокруг оси Y 247 | s = sinf(FM_PI * 2.0f * -YAW); 248 | c = cosf(FM_PI * 2.0f * -YAW); 249 | rm[0] = c; rm[1] = 0; rm[2] = -s; 250 | rm[3] = 0; rm[4] = 1; rm[5] = 0; 251 | rm[6] = s; rm[7] = 0; rm[8] = c; 252 | MulMatrix(um, rm); 253 | //Обновляем матрицу поворота 254 | MulMatrix(RotMatrix, um); 255 | //Нормализация матрицы 256 | float r; 257 | //Сначала исправляем ошибки неортогональности осей x и y 258 | r = RotMatrix[0] * RotMatrix[3] + RotMatrix[1] * RotMatrix[4] + RotMatrix[2] * RotMatrix[5]; 259 | mtx_error = r; 260 | r = (-r) / 2.0f; 261 | um[0] = RotMatrix[0]; 262 | um[1] = RotMatrix[1]; 263 | um[2] = RotMatrix[2]; 264 | RotMatrix[0] += RotMatrix[3] * r; RotMatrix[1] += RotMatrix[4] * r; RotMatrix[2] += RotMatrix[5] * r; 265 | RotMatrix[3] += um[0] * r; RotMatrix[4] += um[1] * r; RotMatrix[5] += um[2] * r; 266 | //Ось z считаем как векторное произведенние осей x и y 267 | RotMatrix[6] = RotMatrix[1] * RotMatrix[5] - RotMatrix[2] * RotMatrix[4]; 268 | RotMatrix[7] = RotMatrix[2] * RotMatrix[3] - RotMatrix[0] * RotMatrix[5]; 269 | RotMatrix[8] = RotMatrix[0] * RotMatrix[4] - RotMatrix[1] * RotMatrix[3]; 270 | //Теперь каждую ось мы нормализуем, ибо ее длина должна быть равна 1 271 | r = RotMatrix[0] * RotMatrix[0] + RotMatrix[1] * RotMatrix[1] + RotMatrix[2] * RotMatrix[2]; 272 | mtx_error += r; 273 | r = 1.5f - r / 2.0f; 274 | RotMatrix[0] *= r; RotMatrix[1] *= r; RotMatrix[2] *= r; 275 | r = RotMatrix[3] * RotMatrix[3] + RotMatrix[4] * RotMatrix[4] + RotMatrix[5] * RotMatrix[5]; 276 | mtx_error += r; 277 | r = 1.5f - r / 2.0f; 278 | RotMatrix[3] *= r; RotMatrix[4] *= r; RotMatrix[5] *= r; 279 | r = RotMatrix[6] * RotMatrix[6] + RotMatrix[7] * RotMatrix[7] + RotMatrix[8] * RotMatrix[8]; 280 | mtx_error += r; 281 | r = 1.5f - r / 2.0f; 282 | RotMatrix[6] *= r; RotMatrix[7] *= r; RotMatrix[8] *= r; 283 | } 284 | 285 | void UpdateRotMatrix(float YAW, float PITCH, float ROLL) 286 | { 287 | RotateAndNormalizeMatrix(RotMatrix, YAW, PITCH, ROLL); 288 | UpdateRMTX(); 289 | UpdateIMTX(); 290 | } 291 | 292 | void UpdateRotMatrixP(float YAW, float PITCH, float ROLL) 293 | { 294 | RotateAndNormalizeMatrix(RotMatrixP, YAW, PITCH, ROLL); 295 | UpdateRMTXp(); 296 | } 297 | #endif 298 | 299 | void RotateMTX(FIXP32* RM, FIXP32 YAW, FIXP32 PITCH, FIXP32 ROLL) 300 | { 301 | if (YAW > 0x3FFF) YAW = 0x3FFF; 302 | if (YAW < -0x3FFF) YAW = -0x3FFF; 303 | if (PITCH > 0x3FFF) PITCH = 0x3FFF; 304 | if (PITCH < -0x3FFF) PITCH = -0x3FFF; 305 | if (ROLL > 0x3FFF) ROLL = 0x3FFF; 306 | if (ROLL < -0x3FFF) ROLL = -0x3FFF; 307 | #if 0 308 | FIXP32 um[9]; 309 | um[0] = 0x4000; 310 | um[1] = -ROLL; 311 | um[2] = YAW; 312 | um[3] = ROLL; 313 | um[4] = 0x4000; 314 | um[5] = PITCH; 315 | um[6] = -YAW; 316 | um[7] = -PITCH; 317 | um[8] = 0x4000; 318 | MulMatrixFIXP32(RM, um); 319 | #endif 320 | 321 | #if 1 322 | FIXP32 t0, t1, t2; 323 | 324 | t0 = RM[0]; 325 | t1 = RM[1]; 326 | t2 = RM[2]; 327 | RM[0] += (t1 * ROLL - t2 * YAW) >> 14; 328 | RM[1] += (-t0 * ROLL - t2 * PITCH) >> 14; 329 | RM[2] += (t0 * YAW + t1 * PITCH) >> 14; 330 | 331 | RM += 3; 332 | 333 | t0 = RM[0]; 334 | t1 = RM[1]; 335 | t2 = RM[2]; 336 | RM[0] += (t1 * ROLL - t2 * YAW) >> 14; 337 | RM[1] += (-t0 * ROLL - t2 * PITCH) >> 14; 338 | RM[2] += (t0 * YAW + t1 * PITCH) >> 14; 339 | #else 340 | UFIXP16* PY = SQRtab + YAW; 341 | UFIXP16* MY = SQRtab - YAW; 342 | UFIXP16* PR = SQRtab + ROLL; 343 | UFIXP16* MR = SQRtab - ROLL; 344 | UFIXP16* PP = SQRtab + PITCH; 345 | UFIXP16* MP = SQRtab - PITCH; 346 | 347 | FIXP32 t0, t1, t2; 348 | t0 = RM[0]; 349 | t1 = RM[1]; 350 | t2 = RM[2]; 351 | RM[0] += PR[t1] - MR[t1] + MY[t2] - PY[t2]; // RM[1] * ROLL - RM[2] * YAW; 352 | RM[1] += MR[t0] - PR[t0] + MP[t2] - PP[t2]; // -RM[0] * ROLL - RM[2] * PITCH; 353 | RM[2] += PY[t0] - MY[t0] + PP[t1] - MP[t1]; // RM[0] * YAW + RM[1] * PITCH; 354 | 355 | RM += 3; 356 | 357 | t0 = RM[0]; 358 | t1 = RM[1]; 359 | t2 = RM[2]; 360 | 361 | RM[0] += PR[t1] - MR[t1] + MY[t2] - PY[t2]; // RM[1] * ROLL - RM[2] * YAW; 362 | RM[1] += MR[t0] - PR[t0] + MP[t2] - PP[t2]; // -RM[0] * ROLL - RM[2] * PITCH; 363 | RM[2] += PY[t0] - MY[t0] + PP[t1] - MP[t1]; // RM[0] * YAW + RM[1] * PITCH; 364 | 365 | #endif 366 | } 367 | 368 | void NormalizeMTX(FIXP32* RM) 369 | { 370 | //Нормализация матрицы 371 | FIXP32 r; 372 | FIXP32 um[3]; 373 | //Сначала исправляем ошибки неортогональности осей x и y 374 | r = RM[0] * RM[3] + RM[1] * RM[4] + RM[2] * RM[5]; 375 | r >>= 14; 376 | mtx_error = r; 377 | r = (-r) / 2; 378 | um[0] = RM[0]; 379 | um[1] = RM[1]; 380 | um[2] = RM[2]; 381 | RM[0] += RM[3] * r >> 14; RM[1] += RM[4] * r >> 14; RM[2] += RM[5] * r >> 14; 382 | RM[3] += um[0] * r >> 14; RM[4] += um[1] * r >> 14; RM[5] += um[2] * r >> 14; 383 | 384 | //Теперь каждую ось мы нормализуем, ибо ее длина должна быть равна 1 385 | r = RM[0] * RM[0] + RM[1] * RM[1] + RM[2] * RM[2]; 386 | r >>= 14; 387 | mtx_error += r; 388 | r = 16384 * 3 / 2 - r / 2; 389 | RM[0] = RM[0] * r >> 14; 390 | RM[1] = RM[1] * r >> 14; 391 | RM[2] = RM[2] * r >> 14; 392 | // 393 | r = RM[3] * RM[3] + RM[4] * RM[4] + RM[5] * RM[5]; 394 | r >>= 14; 395 | mtx_error += r; 396 | r = 16384 * 3 / 2 - r / 2; 397 | RM[3] = RM[3] * r >> 14; 398 | RM[4] = RM[4] * r >> 14; 399 | RM[5] = RM[5] * r >> 14; 400 | // 401 | //Ось z считаем как векторное произведенние осей x и y 402 | RM[6] = (RM[1] * RM[5] - RM[2] * RM[4]) >> 14; 403 | RM[7] = (RM[2] * RM[3] - RM[0] * RM[5]) >> 14; 404 | RM[8] = (RM[0] * RM[4] - RM[1] * RM[3]) >> 14; 405 | #if 0 406 | r = RM[6] * RM[6] + RM[7] * RM[7] + RM[8] * RM[8]; 407 | r >>= 14; 408 | mtx_error += r; 409 | r = 16384 * 3 / 2 - r / 2; 410 | RM[6] = RM[6] * r >> 14; 411 | RM[7] = RM[7] * r >> 14; 412 | RM[8] = RM[8] * r >> 14; 413 | #endif 414 | //Сатурация 415 | #if 0 416 | for (int i = 0; i < 9; i++) 417 | { 418 | r = RM[i]; 419 | if (r > 0x3FFF) r = 0x3FFF; 420 | else if (r < -0x3FFF) r = -0x3FFF; 421 | } 422 | #endif 423 | } 424 | 425 | -------------------------------------------------------------------------------- /Map/mainForm.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include "mainForm.h" 5 | #include 6 | #include "render.h" 7 | #include "renderutils.h" 8 | 9 | using namespace E3D; 10 | 11 | [System::STAThread] 12 | int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { 13 | RenderAllocMemory(); 14 | InitRender2D(); 15 | InitRender3D(); 16 | //LoadSpyro(); 17 | #ifndef NO_PLAYER 18 | CreatePlayerSprite(); 19 | #endif 20 | LoadOmni(); 21 | Application::EnableVisualStyles(); 22 | Application::SetCompatibleTextRenderingDefault(false); 23 | Application::Run(gcnew mainForm); 24 | return 0; 25 | } 26 | 27 | 28 | 29 | FIXP32 CamDX, CamDY, CamDZ; 30 | 31 | void mainForm::PrintCEdistances(void) 32 | { 33 | char str[1024]; 34 | DebugCEdistances(str); 35 | lblCEdistances->Text = gcnew String(str); 36 | } 37 | 38 | #define RAD2G (57.29577951f) 39 | 40 | int VisibleCubeDirection; 41 | int LastCubeDirection; 42 | 43 | FIXP32 dROLL2; 44 | 45 | void mainForm::PrintPosition(void) 46 | { 47 | char str[1024]; 48 | float pitch, roll, yaw; 49 | 50 | pitch = -asinf(RMTXp[5]/16384.0f) * RAD2G; 51 | roll = atan2f((float)RMTXp[3], (float)RMTXp[4]) * RAD2G; 52 | yaw = atan2f((float)RMTXp[6], (float)RMTXp[8]) * RAD2G; 53 | char* s = str; 54 | s += sprintf(s,"pitch=%f\n", pitch); 55 | s += sprintf(s,"roll=%f\n", roll); 56 | s += sprintf(s, "yaw=%f\n", yaw); 57 | #if 0 58 | if (pitch > 45.0f) 59 | { 60 | VisibleCubeDirection = 4; 61 | } 62 | else if (pitch < -45.0f) 63 | { 64 | VisibleCubeDirection = 5; 65 | } 66 | else if (yaw > -45.0f && yaw <= 45.0f) 67 | { 68 | VisibleCubeDirection = 1; 69 | } 70 | else if (yaw > 45.0f && yaw <= 135.0f) 71 | { 72 | VisibleCubeDirection = 0; 73 | } 74 | else if (yaw > -135.0f && yaw <= -45.0f) 75 | { 76 | VisibleCubeDirection = 2; 77 | } 78 | else 79 | { 80 | VisibleCubeDirection = 3; 81 | } 82 | s += sprintf(s, "vcd=%d, lcd=%d\n", VisibleCubeDirection, LastCubeDirection); 83 | #endif 84 | *s = 0; 85 | FIXP32 r; 86 | r = RMTXp[3]; 87 | //if (RMTXp[4] < 0) r = -r; 88 | r >>= 4; 89 | if (r > 0x100) r = 0x100; else if (r < -0x100) r = -0x100; 90 | //if (r<10 && r>-10) r = 0; 91 | dROLL2 = -r; 92 | //dROLL2 = -roll / 10000.0f; 93 | lblPosition->Text = gcnew String(str); 94 | } 95 | 96 | FIXP32 dROLL = 0; 97 | 98 | int mouse_moved; 99 | 100 | FIXP32 PSpeedY; 101 | 102 | static int AccumulatedMDX; 103 | static int AccumulatedMDY; 104 | 105 | #pragma optimize("t",on) 106 | void mainForm::TimerProc(void) 107 | { 108 | //RotateMTX(RMTXp, x * 32, y * 32, -x * 8); 109 | FIXP32 s, c; 110 | s = 0; 111 | c = 0; 112 | #if 0 113 | static float a; 114 | if (1/*!mouse_moved*/) 115 | { 116 | s = (FIXP32)(sinf(a/* + 1.57f / 2.0f*/) * 150.f); 117 | c = (FIXP32)(cosf(a * 2.0f) * 150.f); 118 | 119 | a = a + .1f; if (a > M_PI * 2.0f) a -= M_PI * 2.0f; 120 | 121 | } 122 | else 123 | { 124 | mouse_moved = 0; 125 | } 126 | #endif 127 | 128 | #ifdef NO_PLAYER 129 | RotateMTX(RMTXp, AccumulatedMDX * 32 + s, AccumulatedMDY * 32 + c, dROLL + (dROLL==0?dROLL2:0) - AccumulatedMDX * 8); 130 | #else 131 | RotateMTX(RMTXp, AccumulatedMDX * 32, 0, dROLL2); 132 | #endif 133 | AccumulatedMDX = 0; 134 | AccumulatedMDY = 0; 135 | NormalizeMTX(RMTXp); 136 | #ifdef NO_PLAYER 137 | memcpy(RMTX, RMTXp, sizeof(RMTX)); 138 | #else 139 | RotateMTX(RMTX, 0, -(RMTX[5] - 10000) >> 1, -RMTX[3] >> 1); 140 | FIXP32 d; 141 | d = (CamX - PlayerX) * RMTX[0] + 142 | (CamY - PlayerY) * RMTX[3] + 143 | (CamZ - PlayerZ) * RMTX[6]; 144 | //RotateMTX(RMTX, -d >> 12, -(RMTX[5] - 0x2000) >> 3, -RMTX[3] >> 3); 145 | RotateMTX(RMTX, -d >> 12, 0, 0); 146 | NormalizeMTX(RMTX); 147 | //UpdateRotMatrix(-d/10000.0f, -(RotMatrix[5]-0.5f)/10.0f, -RotMatrix[3]/10.0f); 148 | #endif 149 | #ifdef NO_PLAYER 150 | MovePlayer(CamDX, CamDY, CamDZ); 151 | UpdateIMTX(); 152 | #else 153 | MovePlayer(CamDX, CamDY+PSpeedY, CamDZ); 154 | //PSpeedY += Player_G; 155 | #endif 156 | { 157 | int x = 0; 158 | do 159 | { 160 | //memset(ChunkScreenR + x * 128, 0, 128); 161 | memset(ChunkScreenR + x * 128 + 0, 0x15, 14); 162 | memset(ChunkScreenR + x * 128 + 14, 0, 100); 163 | memset(ChunkScreenR + x * 128 + 114, 0x15, 14); 164 | } while ((++x) < 10); 165 | do 166 | { 167 | memset(ChunkScreenR + x * 128 + 0, 0, 14); 168 | memset(ChunkScreenR + x * 128 + 14, SKY_COLOR2, 100); 169 | memset(ChunkScreenR + x * 128 + 114, 0, 14); 170 | } while ((++x) < 170); 171 | do 172 | { 173 | //memset(ChunkScreenR + x * 128, 0, 128); 174 | memset(ChunkScreenR + x * 128 + 0, 0x15, 14); 175 | memset(ChunkScreenR + x * 128 + 14, 0, 100); 176 | memset(ChunkScreenR + x * 128 + 114, 0x15, 14); 177 | } while ((++x) < 180); 178 | } 179 | #if 0 180 | for (int y = 0; y < 14; y++) 181 | { 182 | for (int x = 0; x < 13*8; x++) 183 | { 184 | int c = x >> 3; 185 | int gc = c; 186 | static int green_t[16] = 187 | { 188 | #if 1 189 | 0,16,32,4, 190 | 20,36,8,24, 191 | 40,12,28,44, 192 | 60,60,60,60 193 | #else 194 | 0,16,16,4, 195 | 20,/*32,*/36,8,24, 196 | 40,12,28,44, 197 | 60,60,60,60 198 | #endif 199 | }; 200 | gc = green_t[c]; 201 | ChunkScreenR[y + (x + 10) * 128] = gc; 202 | } 203 | } 204 | #endif 205 | //memset(ChunkScreenR, 22, sizeof(ChunkScreenR)); 206 | ProcessWorld(); 207 | //Convert chunky screen; 208 | System::Drawing::Imaging::BitmapData^ bdata; 209 | bdata = ScreenBitmap->LockBits( 210 | System::Drawing::Rectangle(0, 0, ScreenBitmap->Width, ScreenBitmap->Height), 211 | System::Drawing::Imaging::ImageLockMode::ReadWrite, 212 | ScreenBitmap->PixelFormat); 213 | BitmapArray = bdata->Scan0; 214 | C2P((uint32_t*)(BitmapArray.ToPointer())); 215 | ScreenBitmap->UnlockBits(bdata); 216 | pictureBox1->Image = ScreenBitmap; 217 | PrintCEdistances(); 218 | PrintPosition(); 219 | } 220 | 221 | void mainForm::SetLockMouse(int lock) 222 | { 223 | if (lock) 224 | { 225 | if (!LockMouse) 226 | { 227 | LockMouse = 1; 228 | ShowCursor(0); 229 | ResetMouse(); 230 | } 231 | } 232 | else 233 | { 234 | if (LockMouse) 235 | { 236 | LockMouse = 0; 237 | ShowCursor(1); 238 | } 239 | } 240 | } 241 | 242 | void JumpToCubeCenter(void) 243 | { 244 | } 245 | 246 | #define CAM_STEP (25) 247 | 248 | void mainForm::ProcessKeyPress(int ch, int f, int _shift, int _ctrl, int _alt) 249 | { 250 | switch (ch) 251 | { 252 | case 'W': 253 | if (f) 254 | CamDZ = CAM_STEP; 255 | else if (CamDZ>0) 256 | CamDZ = 0; 257 | break; 258 | case 'S': 259 | if (f && _ctrl) 260 | { 261 | //Square split 262 | break; 263 | } 264 | if (f) 265 | CamDZ = -CAM_STEP; 266 | else if (CamDZ<0) 267 | CamDZ = 0; 268 | break; 269 | case 'A': 270 | if (f) 271 | CamDX = -CAM_STEP; 272 | else if (CamDX<0) 273 | CamDX = 0; 274 | break; 275 | case 'D': 276 | if (_ctrl) 277 | { 278 | if (f) DumpRequest = 1; 279 | break; 280 | } 281 | if (f) 282 | CamDX = CAM_STEP; 283 | else if (CamDX>0) 284 | CamDX = 0; 285 | break; 286 | case 'Z': 287 | if (f) 288 | CamDY = -CAM_STEP; 289 | else if (CamDY < 0) 290 | CamDY = 0; 291 | break; 292 | case 'X': 293 | if (f) 294 | CamDY = CAM_STEP; 295 | else if (CamDY > 0) 296 | CamDY = 0; 297 | break; 298 | case 'Q': 299 | if (f) 300 | dROLL = -1024; 301 | else if (dROLL<0) 302 | dROLL = 0; 303 | break; 304 | case 'E': 305 | if (f) 306 | dROLL = 1024; 307 | else if (dROLL>0) 308 | dROLL = 0; 309 | break; 310 | case 'C': 311 | if (f) 312 | { 313 | JumpToCubeCenter(); 314 | } 315 | break; 316 | case 0x1B: 317 | SetLockMouse(0); 318 | break; 319 | case 'I': 320 | if (f) 321 | { 322 | display_wires ^= 1; 323 | } 324 | break; 325 | case 'U': 326 | if (f) 327 | { 328 | test_mode ^= 1; 329 | } 330 | break; 331 | case 'Y': 332 | if (f) 333 | { 334 | test_mode2 ^= 1; 335 | } 336 | break; 337 | #if 0 338 | case 0x25: //Left 339 | if (f) StepRootCube(0, _ctrl); 340 | break; 341 | case 0x26: //Up 342 | if (f) StepRootCube(1, _ctrl); 343 | break; 344 | case 0x27: //Right 345 | if (f) StepRootCube(2, _ctrl); 346 | break; 347 | case 0x28: //Down 348 | if (f) StepRootCube(3, _ctrl); 349 | break; 350 | case 'N': 351 | if (f) StepRootCube(4, _ctrl); 352 | break; 353 | case 'M': 354 | if (f) StepRootCube(5, _ctrl); 355 | break; 356 | case 'L': 357 | if (f) LinkRootCubeWithNearest(); 358 | break; 359 | case 'P': 360 | if (f) 361 | { 362 | StepRootCube(VisibleCubeDirection, _ctrl); 363 | JumpToCubeCenter(); 364 | } 365 | break; 366 | case 'F': 367 | if (f && _ctrl) 368 | { 369 | while (!RootCube->tfaces[0]) 370 | { 371 | CUBE* c; 372 | c = RootCube; 373 | if (c->MX > 0x4000) break; 374 | if (c->MX < -0x4000) break; 375 | if (c->MY > 0x0000) break; 376 | if (c->MY < -0x2000) break; 377 | if (c->MZ > 0x4000) break; 378 | if (c->MZ < -0x4000) break; 379 | StepRootCube(VisibleCubeDirection, 1); 380 | JumpToCubeCenter(); 381 | LinkRootCubeWithNearest(); 382 | } 383 | } 384 | break; 385 | case 'J': 386 | RootCube = FindNearestCube(CamX, CamY, CamZ); 387 | break; 388 | #endif 389 | } 390 | } 391 | 392 | static uint8_t mouse_fuse = 1; 393 | 394 | void mainForm::ProcessMouse(int x, int y, int buttons) 395 | { 396 | char str[256]; 397 | char* s = str; 398 | s += sprintf(s, "%04d %04d", x, y); 399 | *s = 0; 400 | int dx, dy; 401 | static int old_x, old_y; 402 | dx = x - old_x; 403 | dy = y - old_y; 404 | old_x = x; 405 | old_y = y; 406 | lblMouse->Text = gcnew String(str); 407 | if (!LockMouse) return; 408 | x -= pictureBox1->Width / 2; 409 | y -= pictureBox1->Height / 2; 410 | if (x != 0 || y != 0) mouse_moved = 1; 411 | if (mouse_fuse) 412 | { 413 | mouse_fuse = 0; 414 | } 415 | else 416 | { 417 | AccumulatedMDX += x; 418 | AccumulatedMDY += y; 419 | } 420 | if (x != 0 || y != 0) 421 | { 422 | Point p; 423 | p.X = 0; 424 | p.Y = 0; 425 | p = pictureBox1->PointToScreen(p); 426 | SetCursorPos(p.X + pictureBox1->Width / 2, p.Y + pictureBox1->Height / 2); 427 | } 428 | } 429 | 430 | void mainForm::ResetMouse(void) 431 | { 432 | Point p; 433 | p.X = 0; 434 | p.Y = 0; 435 | p = pictureBox1->PointToScreen(p); 436 | mouse_fuse = 1; 437 | SetCursorPos(p.X + pictureBox1->Width / 2, p.Y + pictureBox1->Height / 2); 438 | } 439 | 440 | void mainForm::FlyByWheel(int move) 441 | { 442 | MovePlayer(0, 0, move / 1); 443 | } 444 | -------------------------------------------------------------------------------- /Map/mainForm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "render.h" 5 | #include "renderutils.h" 6 | 7 | namespace E3D { 8 | 9 | using namespace System; 10 | using namespace System::ComponentModel; 11 | using namespace System::Collections; 12 | using namespace System::Windows::Forms; 13 | using namespace System::Data; 14 | using namespace System::Drawing; 15 | 16 | /// 17 | /// Summary for mainForm 18 | /// 19 | public ref class mainForm : public System::Windows::Forms::Form 20 | { 21 | public: 22 | mainForm(void) 23 | { 24 | InitializeComponent(); 25 | // 26 | //TODO: Add the constructor code here 27 | // 28 | ScreenBitmap = gcnew Bitmap(180*4, 128*4); 29 | PrintCEdistances(); 30 | this->MouseWheel += gcnew System::Windows::Forms::MouseEventHandler(this, &E3D::mainForm::OnMouseWheel); 31 | } 32 | 33 | protected: 34 | /// 35 | /// Clean up any resources being used. 36 | /// 37 | ~mainForm() 38 | { 39 | if (components) 40 | { 41 | delete components; 42 | } 43 | delete ScreenBitmap; 44 | } 45 | 46 | private: 47 | /// 48 | /// Required designer variable. 49 | /// 50 | 51 | Bitmap^ ScreenBitmap; 52 | IntPtr BitmapArray; 53 | void PrintCEdistances(void); 54 | void ProcessMouse(int x, int y, int buttons); 55 | void ResetMouse(void); 56 | void FlyByWheel(int move); 57 | void PrintPosition(void); 58 | int LockMouse; 59 | void SetLockMouse(int lock); 60 | int mouse_buttons; 61 | 62 | 63 | private: System::Windows::Forms::Timer^ timer1; 64 | private: System::Windows::Forms::PictureBox^ pictureBox1; 65 | private: System::ComponentModel::IContainer^ components; 66 | 67 | private: System::Windows::Forms::Label^ lblCEdistances; 68 | private: System::Windows::Forms::Label^ lblMouse; 69 | private: System::Windows::Forms::Label^ lblPosition; 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | #pragma region Windows Form Designer generated code 98 | /// 99 | /// Required method for Designer support - do not modify 100 | /// the contents of this method with the code editor. 101 | /// 102 | void InitializeComponent(void) 103 | { 104 | this->components = (gcnew System::ComponentModel::Container()); 105 | this->timer1 = (gcnew System::Windows::Forms::Timer(this->components)); 106 | this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox()); 107 | this->lblCEdistances = (gcnew System::Windows::Forms::Label()); 108 | this->lblMouse = (gcnew System::Windows::Forms::Label()); 109 | this->lblPosition = (gcnew System::Windows::Forms::Label()); 110 | (cli::safe_cast(this->pictureBox1))->BeginInit(); 111 | this->SuspendLayout(); 112 | // 113 | // timer1 114 | // 115 | this->timer1->Enabled = true; 116 | this->timer1->Interval = 20; 117 | this->timer1->Tick += gcnew System::EventHandler(this, &mainForm::timer1_Tick); 118 | // 119 | // pictureBox1 120 | // 121 | this->pictureBox1->Location = System::Drawing::Point(7, 12); 122 | this->pictureBox1->Margin = System::Windows::Forms::Padding(4); 123 | this->pictureBox1->Name = L"pictureBox1"; 124 | this->pictureBox1->Size = System::Drawing::Size(1440, 1024); 125 | this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::CenterImage; 126 | this->pictureBox1->TabIndex = 5; 127 | this->pictureBox1->TabStop = false; 128 | this->pictureBox1->Click += gcnew System::EventHandler(this, &mainForm::pictureBox1_Click); 129 | this->pictureBox1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &mainForm::pictureBox1_MouseDown); 130 | this->pictureBox1->MouseEnter += gcnew System::EventHandler(this, &mainForm::pictureBox1_MouseEnter); 131 | this->pictureBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &mainForm::mainForm_MouseMove); 132 | this->pictureBox1->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &mainForm::pictureBox1_MouseUp); 133 | // 134 | // lblCEdistances 135 | // 136 | this->lblCEdistances->AutoSize = true; 137 | this->lblCEdistances->Location = System::Drawing::Point(24, 1075); 138 | this->lblCEdistances->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 139 | this->lblCEdistances->MinimumSize = System::Drawing::Size(300, 200); 140 | this->lblCEdistances->Name = L"lblCEdistances"; 141 | this->lblCEdistances->Size = System::Drawing::Size(300, 200); 142 | this->lblCEdistances->TabIndex = 7; 143 | this->lblCEdistances->Text = L"..."; 144 | // 145 | // lblMouse 146 | // 147 | this->lblMouse->AutoSize = true; 148 | this->lblMouse->Location = System::Drawing::Point(1378, 1064); 149 | this->lblMouse->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 150 | this->lblMouse->MinimumSize = System::Drawing::Size(300, 50); 151 | this->lblMouse->Name = L"lblMouse"; 152 | this->lblMouse->Size = System::Drawing::Size(300, 50); 153 | this->lblMouse->TabIndex = 8; 154 | this->lblMouse->Text = L"...."; 155 | // 156 | // lblPosition 157 | // 158 | this->lblPosition->AutoSize = true; 159 | this->lblPosition->Location = System::Drawing::Point(939, 1075); 160 | this->lblPosition->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); 161 | this->lblPosition->Name = L"lblPosition"; 162 | this->lblPosition->Size = System::Drawing::Size(123, 25); 163 | this->lblPosition->TabIndex = 9; 164 | this->lblPosition->Text = L"...position..."; 165 | // 166 | // mainForm 167 | // 168 | this->AutoScaleDimensions = System::Drawing::SizeF(12, 25); 169 | this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; 170 | this->AutoSize = true; 171 | this->ClientSize = System::Drawing::Size(1970, 1464); 172 | this->Controls->Add(this->lblPosition); 173 | this->Controls->Add(this->lblMouse); 174 | this->Controls->Add(this->lblCEdistances); 175 | this->Controls->Add(this->pictureBox1); 176 | this->KeyPreview = true; 177 | this->Margin = System::Windows::Forms::Padding(4); 178 | this->Name = L"mainForm"; 179 | this->Padding = System::Windows::Forms::Padding(20, 19, 20, 19); 180 | this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; 181 | this->Text = L"mainForm"; 182 | this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &mainForm::mainForm_KeyDown); 183 | this->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &mainForm::mainForm_KeyPress); 184 | this->KeyUp += gcnew System::Windows::Forms::KeyEventHandler(this, &mainForm::mainForm_KeyUp); 185 | (cli::safe_cast(this->pictureBox1))->EndInit(); 186 | this->ResumeLayout(false); 187 | this->PerformLayout(); 188 | 189 | } 190 | #pragma endregion 191 | private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) 192 | { 193 | TimerProc(); 194 | } 195 | private: System::Void sbPitch_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) 196 | { 197 | } 198 | private: System::Void sbYaw_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) 199 | { 200 | } 201 | private: void TimerProc(void); 202 | private: void ProcessKeyPress(int ch, int f, int _shift, int _ctrl, int _alt); 203 | 204 | private: System::Void mainForm_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) 205 | { 206 | //ProcessKeyPress(e->KeyChar); 207 | } 208 | private: System::Void mainForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) 209 | { 210 | 211 | ProcessKeyPress(e->KeyValue,1,e->Shift,e->Control,e->Alt); 212 | } 213 | private: System::Void mainForm_KeyUp(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) 214 | { 215 | ProcessKeyPress(e->KeyValue, 0,e->Shift,e->Control,e->Alt); 216 | } 217 | private: System::Void mainForm_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) 218 | { 219 | ProcessMouse(e->X, e->Y, mouse_buttons); 220 | } 221 | 222 | private: System::Void pictureBox1_MouseEnter(System::Object^ sender, System::EventArgs^ e) 223 | { 224 | ResetMouse(); 225 | } 226 | private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) 227 | { 228 | if (mouse_buttons & 1) 229 | { 230 | SetLockMouse(!LockMouse); 231 | } 232 | else if (mouse_buttons & 2) 233 | { 234 | //SelectFaceIn3D(); 235 | } 236 | } 237 | private: System::Void OnMouseWheel(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) 238 | { 239 | int move = e->Delta; 240 | FlyByWheel(move); 241 | } 242 | private: System::Void pictureBox1_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) 243 | { 244 | switch (e->Button) 245 | { 246 | case System::Windows::Forms::MouseButtons::Left: 247 | mouse_buttons |= 1; 248 | break; 249 | case System::Windows::Forms::MouseButtons::Right: 250 | mouse_buttons |= 2; 251 | break; 252 | } 253 | } 254 | private: System::Void pictureBox1_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) 255 | { 256 | switch (e->Button) 257 | { 258 | case System::Windows::Forms::MouseButtons::Left: 259 | mouse_buttons &= ~1; 260 | break; 261 | case System::Windows::Forms::MouseButtons::Right: 262 | mouse_buttons &= ~2; 263 | break; 264 | } 265 | } 266 | 267 | }; 268 | } 269 | -------------------------------------------------------------------------------- /Map/mainForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /Map/omni/FACES.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/FACES.bin -------------------------------------------------------------------------------- /Map/omni/FPXYZ.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/FPXYZ.bin -------------------------------------------------------------------------------- /Map/omni/cindex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/cindex.bin -------------------------------------------------------------------------------- /Map/omni/clist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/clist.bin -------------------------------------------------------------------------------- /Map/omni/faces_in_leafs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/faces_in_leafs.bin -------------------------------------------------------------------------------- /Map/omni/fil_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/fil_idx.bin -------------------------------------------------------------------------------- /Map/omni/kdtree.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/kdtree.bin -------------------------------------------------------------------------------- /Map/omni/pvs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/pvs.bin -------------------------------------------------------------------------------- /Map/omni/pvs_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/pvs_idx.bin -------------------------------------------------------------------------------- /Map/omni/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/texture.bin -------------------------------------------------------------------------------- /Map/omni/texture.c32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/texture.c32 -------------------------------------------------------------------------------- /Map/omni/texture32c.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/texture32c.bmp -------------------------------------------------------------------------------- /Map/omni/textures.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/omni/textures.bmp -------------------------------------------------------------------------------- /Map/render.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDER_H 2 | #define RENDER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #define _USE_MATH_DEFINES 9 | #include 10 | 11 | #define NO_PLAYER 12 | 13 | #define FADE_TO_BLACK 14 | 15 | #define TRAPEZOID_ENABLE_ROUNDING 16 | 17 | #define ZAVG_SQUARE 18 | 19 | #define TSL_Z_THR (0x0480) 20 | 21 | //#define TILE32 22 | 23 | //#define CMODE256 24 | 25 | //Use 32 colors with pallette 26 | #define CMODE_PAL32 27 | 28 | extern uint32_t TPALLETTE[32]; 29 | 30 | typedef uint32_t UFIXP32; 31 | typedef int32_t FIXP32; 32 | typedef uint16_t UFIXP16; 33 | typedef int16_t FIXP16; 34 | 35 | typedef int64_t FIXP64; 36 | typedef uint64_t UFIXP64; 37 | 38 | #define MAX_COLORS 64 39 | 40 | #define SCOORD_NOT_VALID (1) 41 | #define EDGE_DIVIDED (2) 42 | #define TSL_FLAG_NEAR (4) 43 | #define TSL_FLAG_DIVIDE (8) 44 | 45 | typedef struct 46 | { 47 | uint32_t seq; 48 | FIXP32 X; //World X, 24.8 49 | FIXP32 Y; //World Y, 24.8 50 | FIXP32 Z; //World Z, 24.8 51 | FIXP16 x; //Rotated x, 8.8 52 | FIXP16 y; //Rotated y, 8.8 53 | FIXP16 z; //Rotated z. 8.8 54 | UFIXP16 sx; //Projected and displaced x 8.8 55 | UFIXP16 sy; //Projected and displaced y 8.8 56 | uint16_t flags; 57 | }FPXYZ; 58 | 59 | typedef struct 60 | { 61 | uint32_t seq; 62 | FIXP32 X; //World X, 24.8 63 | FIXP32 Y; //World Y, 24.8 64 | FIXP32 Z; //World Z, 24.8 65 | UFIXP16 sx; //Projected and displaced x 8.8 66 | UFIXP16 sy; //Projected and displaced y 8.8 67 | FIXP16 x; //Rotated x, 8.8 68 | FIXP16 y; //Rotated y, 8.8 69 | FIXP16 z; //Rotated z. 8.8 70 | uint16_t flags; 71 | }FPXYZ_TARGET; 72 | 73 | typedef struct 74 | { 75 | FPXYZ* p; 76 | UFIXP16 U; 77 | UFIXP16 V; 78 | }TVERTEX; 79 | 80 | #pragma warning( push ) 81 | //#pragma warning( disable : 4200 ) 82 | struct TFACE; 83 | 84 | typedef struct TFACE 85 | { 86 | struct TFACE* next; 87 | uint16_t flags; 88 | //Коэффициенты плоскости, но в формате 2.14 (как матрица поворота, для умножения через таблицу) 89 | FIXP16 A14; 90 | FIXP16 B14; 91 | FIXP16 C14; 92 | FIXP32 MX; //Центр грани 93 | FIXP32 MY; 94 | FIXP32 MZ; 95 | FIXP16 avg_z; 96 | uint16_t avg_color; 97 | uint8_t* T; //Указатель на текстуру 98 | FIXP32 A; //Пока пусть полежат, а вообще их походу можно выбросить 99 | FIXP32 B; 100 | FIXP32 C; 101 | FIXP32 D; 102 | uint32_t id; //Тоже пусть полежит 103 | uint32_t seq; //Пока пусть лежит, потом может нужно будет выбросить 104 | TVERTEX vertexes[1]; //Тут сложены все вертексы 105 | }TFACE; 106 | 107 | typedef struct 108 | { 109 | uint32_t p; 110 | UFIXP16 V; 111 | UFIXP16 U; 112 | }TVERTEX_TARGET; 113 | 114 | typedef struct TFACE_TARGET 115 | { 116 | uint32_t next; 117 | uint32_t seq; 118 | uint16_t flags; 119 | //Коэффициенты плоскости, но в формате 2.14 (как матрица поворота, для умножения через таблицу) 120 | FIXP16 A14; 121 | FIXP16 B14; 122 | FIXP16 C14; 123 | FIXP32 MX; //Центр грани 124 | FIXP32 MY; 125 | FIXP32 MZ; 126 | FIXP16 avg_z; 127 | uint16_t avg_color; 128 | uint32_t T; //Указатель на текстуру 129 | TVERTEX_TARGET vertexes[64]; //Тут сложены все вертексы 130 | }TFACE_TARGET; 131 | 132 | #pragma warning( pop ) 133 | 134 | typedef struct RVERTEX 135 | { 136 | struct RVERTEX* next; 137 | struct RVERTEX* prev; 138 | UFIXP16 sx; 139 | UFIXP16 sy; 140 | UFIXP16 U; 141 | UFIXP16 V; 142 | FIXP16 x; 143 | FIXP16 y; 144 | FIXP16 z; 145 | uint16_t flags; 146 | }RVERTEX; 147 | 148 | typedef struct RFACE 149 | { 150 | RVERTEX* vertex; 151 | uint32_t T; 152 | FIXP32 xmax; 153 | struct RFACE* next; 154 | }RFACE; 155 | 156 | extern FIXP32 IMATRIX[256 * 3 * 3]; 157 | 158 | 159 | #if 1 160 | #define YDISP_FP ((64<<8)) 161 | #define XDISP_FP ((90<<8)) 162 | 163 | #define SCREEN_LEFT (10) 164 | #define SCREEN_RIGHT (169) 165 | #define SCREEN_BOTTOM (14) 166 | #define SCREEN_TOP (113) 167 | #else 168 | #define YDISP_FP ((50<<8)) 169 | #define XDISP_FP ((80<<8)) 170 | 171 | #define SCREEN_LEFT (0) 172 | #define SCREEN_RIGHT (159) 173 | #define SCREEN_BOTTOM (0) 174 | #define SCREEN_TOP (99) 175 | #endif 176 | 177 | #define SCR_L8 (SCREEN_LEFT<<8) 178 | #define SCR_R8 (((SCREEN_RIGHT+1)<<8)-1) 179 | #define SCR_B8 (SCREEN_BOTTOM<<8) 180 | #define SCR_T8 (((SCREEN_TOP+1)<<8)-1) 181 | 182 | #define MIN_Z8 ((1<<8)/10) 183 | 184 | #define MAX_DISTANCE (0x3DFFUL) 185 | 186 | #ifdef NO_PLAYER 187 | #define MIN_D_WALK (256/2) 188 | #else 189 | #define MIN_D_WALK (256/4) 190 | #endif 191 | 192 | #define CamDisp_X (0) 193 | #define CamDisp_Y (-512) 194 | #define CamDisp_Z (-512) 195 | 196 | 197 | 198 | //3D part 199 | void RotateMTX(FIXP32 *m, FIXP32 YAW, FIXP32 PITCH, FIXP32 ROLL); 200 | void NormalizeMTX(FIXP32* m); 201 | extern FIXP32 RMTX[9]; 202 | extern FIXP32 RMTXp[9]; 203 | //extern float RotMatrix[9]; 204 | //extern float RotMatrixP[9]; 205 | //void UpdateRMTX(void); 206 | //void UpdateRMTXp(void); 207 | void UpdateIMTX(void); 208 | 209 | //============= rendinit.cpp ====================== 210 | void RenderAllocMemory(void); 211 | int ComputeABCD(TFACE* face); 212 | extern uint8_t Texture[65536*4]; 213 | 214 | void LoadSpyro(void); 215 | void LoadTR(void); 216 | void LoadOmni(void); 217 | 218 | FIXP32 fast_sqrt64(FIXP64 v); 219 | 220 | TFACE* GetAllFacesFromPool(void); 221 | 222 | TFACE* GetFaceByOffset(uint32_t ofs); 223 | 224 | extern FIXP32 Scene_max_X; 225 | extern FIXP32 Scene_min_X; 226 | extern FIXP32 Scene_max_Y; 227 | extern FIXP32 Scene_min_Y; 228 | extern FIXP32 Scene_max_Z; 229 | extern FIXP32 Scene_min_Z; 230 | 231 | #ifdef CMODE_PAL32 232 | #define SKY_COLOR2 (0UL) 233 | #else 234 | #define SKY_COLOR2 (22UL) 235 | #endif 236 | //#define SKY_COLOR (0x2BUL) 237 | #define SKY_COLOR (0) 238 | 239 | extern TFACE* PlayerSprite; 240 | void CreatePlayerSprite(void); 241 | 242 | //============= render2d.cpp ======================= 243 | 244 | //2D part 245 | void InitRender2D(void); 246 | void C2P(uint32_t* d); 247 | void DrawLine(FIXP32 x1, FIXP32 y1, FIXP32 x2, FIXP32 y2, uint16_t color); 248 | extern uint8_t ChunkScreenR[128 * 180]; 249 | 250 | //============== render3d.cpp ====================== 251 | 252 | extern int display_wires; 253 | 254 | void InitRender3D(void); 255 | 256 | void FinishRenderSlices(void); 257 | void InitRenderSlices(void); 258 | 259 | typedef union 260 | { 261 | RVERTEX v; 262 | RFACE f; 263 | }R_DATA; 264 | 265 | #define R_DATA_TOTAL_SZ (1024) 266 | 267 | extern R_DATA* RDataPool[R_DATA_TOTAL_SZ]; 268 | 269 | //#define R_DATA_THR_force_draw (RDataPool+64) 270 | #define R_DATA_THR_faces (RDataPool+670) 271 | #define R_DATA_THR_near_faces (RDataPool+105) 272 | //#define R_DATA_THR_clip (R_DATA_THR_faces+128) 273 | #define R_DATA_THR_max_faces (980) 274 | #define R_DATA_THR_error (RDataPool+R_DATA_THR_max_faces) 275 | 276 | R_DATA** tmap_prepare(RFACE* f, R_DATA** pool); 277 | R_DATA** fmap_prepare(RFACE* f, R_DATA **pool); 278 | 279 | //============== render.cpp ======================== 280 | 281 | extern FILE* f_render_log; 282 | 283 | #define RDBG(...) do{if (f_render_log) fprintf(f_render_log,__VA_ARGS__);}while(0) 284 | #define RFLUSH() do{if (f_render_log) fflush(f_render_log);}while(0) 285 | 286 | extern uint32_t FrameCounter; 287 | 288 | void InitFrustumClipper(void); 289 | void ProcessWorld(void); 290 | 291 | void DrawFaceLines(RVERTEX* v, uint8_t color); 292 | 293 | extern uint16_t _LOGtab[32768]; 294 | #define LOGtab (_LOGtab+16384) 295 | extern uint16_t EXPtab[65536]; 296 | #define LOG5_8 (0xF528-2) 297 | 298 | #define MIN_SQR (-0x8000) 299 | #define MAX_SQR (+0x8000) 300 | extern UFIXP16 _SQRtab[MAX_SQR - MIN_SQR]; 301 | #define SQRtab (_SQRtab-MIN_SQR) 302 | 303 | extern FIXP32 CamX; 304 | extern FIXP32 CamY; 305 | extern FIXP32 CamZ; 306 | 307 | extern FIXP32 PlayerX; 308 | extern FIXP32 PlayerY; 309 | extern FIXP32 PlayerZ; 310 | 311 | #define Player_G (3) 312 | #define Player_J (-40) 313 | 314 | extern FIXP32 PSpeedY; 315 | 316 | #define MUL(A,B) (SQRtab[(A)+(B)]-SQRtab[(A)-(B)]) 317 | 318 | extern uint8_t DumpRequest; 319 | 320 | void DrawFaceEdges(RVERTEX* _v, uint8_t color); 321 | 322 | //================================= rendermove.cpp ======================================= 323 | 324 | //Печать отладочной информации 325 | void DebugCEdistances(char *str); 326 | //Перемещаем камеру 327 | void MovePlayer(FIXP32 dX, FIXP32 dY, FIXP32 dZ); 328 | 329 | //========================================================================================= 330 | extern int test_mode; 331 | extern int test_mode2; 332 | 333 | extern int traveled_cubes; 334 | extern int prepared_cubes; 335 | extern int prepared_points; 336 | extern int prepared_vertexes; 337 | extern int prepared_faces_stage1; 338 | extern int prepared_faces_stage2; 339 | extern int prepared_faces_stage3; 340 | extern int processed_faces; 341 | extern int send_to_render_faces; 342 | extern int dropped_in_render_faces; 343 | 344 | //=============================== kd-tree ====================================== 345 | typedef struct 346 | { 347 | uint16_t next_index; 348 | uint8_t axis; 349 | int8_t split; 350 | }KDTREE_NODE; 351 | 352 | typedef struct 353 | { 354 | union 355 | { 356 | uint32_t face_id; 357 | uint32_t face_offset; 358 | }; 359 | }KDTREE_FACE_NODE; 360 | 361 | typedef struct 362 | { 363 | int8_t K; 364 | int8_t J; 365 | int8_t I; 366 | uint8_t dummy; 367 | uint32_t kdtf_offset; 368 | }KDTREE_LEAF; 369 | 370 | typedef struct 371 | { 372 | FIXP32* I; 373 | FIXP32* J; 374 | FIXP32* K; 375 | KDTREE_FACE_NODE* FaceList; 376 | }KDTREE_BIG_LEAF; 377 | 378 | extern FIXP32 BMATRIX[256 * 3 * 3]; 379 | extern KDTREE_BIG_LEAF* kd_tree_big_leafs; 380 | 381 | extern KDTREE_NODE* kd_tree; 382 | extern KDTREE_FACE_NODE* kd_tree_faces; 383 | extern KDTREE_LEAF *kd_tree_leafs; 384 | 385 | extern uint32_t* pvs_index; 386 | extern uint8_t* packed_pvs; 387 | 388 | extern uint32_t* collision_index; 389 | extern uint32_t* collision_list; 390 | 391 | void LoadKDtree(void); 392 | 393 | KDTREE_NODE* FindKDtreeNode(FIXP32 X, FIXP32 Y, FIXP32 Z); 394 | 395 | #endif -------------------------------------------------------------------------------- /Map/render2d.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include "stdio.h" 3 | #include "render.h" 4 | 5 | //uint8_t ChunkScreen[SCRWIDTH * SCRHEIGHT]; 6 | 7 | uint8_t ChunkScreenR[128 * 180]; 8 | 9 | uint32_t PALLETTE[MAX_COLORS]; 10 | void InitRender2D(void) 11 | { 12 | //FILE* f = fopen("pal64.gpl", "wt"); 13 | //fprintf(f, "GIMP Palette\nName : palette64\n#\n"); 14 | for (int i = 0; i < MAX_COLORS; i++) 15 | { 16 | uint32_t color = 0xFF000000; 17 | #if 1 18 | if (i & 0x20) color |= 0x00AA0000; 19 | if (i & 0x10) color |= 0x00550000; 20 | if (i & 0x08) color |= 0x0000AA00; 21 | if (i & 0x04) color |= 0x00005500; 22 | if (i & 0x02) color |= 0x000000AA; 23 | if (i & 0x01) color |= 0x00000055; 24 | #else 25 | color |= (i << 18) | (i << 10) | (i << 2); 26 | #endif 27 | PALLETTE[i] = color; 28 | //fprintf(f, "%d %d %d\n", (color >> 16) & 0xFF, (color >> 8) & 0xFF, (color >> 0) & 0xFF); 29 | } 30 | //fclose(f); 31 | } 32 | 33 | static void Plot(FIXP32 x, FIXP32 y, uint16_t color) 34 | { 35 | if (y < 0) return; 36 | if (y > 127) return; 37 | if (x < 0) return; 38 | if (x > 179) return; 39 | if (color & 0xFF00) 40 | ChunkScreenR[y + x * 128] ^= color & 0xFF; 41 | else 42 | ChunkScreenR[y + x * 128] = color & 0xFF; 43 | } 44 | 45 | //Рисуем простую линию (на входе 24.8 уже в экранных координатах) 46 | void DrawLine(FIXP32 x1, FIXP32 y1, FIXP32 x2, FIXP32 y2, uint16_t color) 47 | { 48 | int dx,dy; 49 | x1 >>= 8; 50 | x2 >>= 8; 51 | y1 >>= 8; 52 | y2 >>= 8; 53 | dx = x2 - x1; 54 | dy = y2 - y1; 55 | int adx, ady; 56 | if (dx > 0) adx = dx; else adx = -dx; 57 | if (dy > 0) ady = dy; else ady = -dy; 58 | if (adx > ady) 59 | { 60 | //One pixel step by X 61 | if (adx) 62 | { 63 | dy <<= 8; 64 | y1 <<= 8; 65 | dy /= adx; 66 | while (x2 > x1) 67 | { 68 | int y = y1 >> 8; 69 | Plot(x1,y,color); 70 | y1 += dy; 71 | x1++; 72 | } 73 | while (x2 < x1) 74 | { 75 | int y = y1 >> 8; 76 | Plot(x1, y, color); 77 | y1 += dy; 78 | x1--; 79 | } 80 | } 81 | } 82 | else 83 | { 84 | //One pixel step by Y 85 | if (ady) 86 | { 87 | dx <<= 8; 88 | x1 <<= 8; 89 | dx /= ady; 90 | while (y2 > y1) 91 | { 92 | int x = x1 >> 8; 93 | Plot(x, y1, color); 94 | x1 += dx; 95 | y1++; 96 | } 97 | while (y2 < y1) 98 | { 99 | int x = x1 >> 8; 100 | Plot(x, y1, color); 101 | x1 += dx; 102 | y1--; 103 | } 104 | } 105 | } 106 | } 107 | 108 | #if 0 109 | void DrawXorLine(FIXP32 x1, FIXP32 y1, FIXP32 x2, FIXP32 y2, uint8_t color) 110 | { 111 | int dx, dy; 112 | x1 >>= 8; 113 | x2 >>= 8; 114 | y1 >>= 8; 115 | y2 >>= 8; 116 | dx = x2 - x1; 117 | dy = y2 - y1; 118 | int adx, ady; 119 | if (dx > 0) adx = dx; else adx = -dx; 120 | if (dy > 0) ady = dy; else ady = -dy; 121 | if (adx > ady) 122 | { 123 | //One pixel step by X 124 | if (adx) 125 | { 126 | dy <<= 8; 127 | y1 <<= 8; 128 | dy /= adx; 129 | while (x2 > x1) 130 | { 131 | int y = y1 >> 8; 132 | ChunkScreenR[y + x1 * 128] ^= color; 133 | y1 += dy; 134 | x1++; 135 | } 136 | while (x2 < x1) 137 | { 138 | int y = y1 >> 8; 139 | ChunkScreenR[y + x1 * 128] ^= color; 140 | y1 += dy; 141 | x1--; 142 | } 143 | } 144 | } 145 | else 146 | { 147 | //One pixel step by Y 148 | if (ady) 149 | { 150 | dx <<= 8; 151 | x1 <<= 8; 152 | dx /= ady; 153 | while (y2 > y1) 154 | { 155 | int x = x1 >> 8; 156 | ChunkScreenR[y1 + x * 128] ^= color; 157 | x1 += dx; 158 | y1++; 159 | } 160 | while (y2 < y1) 161 | { 162 | int x = x1 >> 8; 163 | ChunkScreenR[y1 + x * 128] ^= color; 164 | x1 += dx; 165 | y1--; 166 | } 167 | } 168 | } 169 | } 170 | #endif 171 | 172 | uint32_t TPALLETTE[32]; 173 | 174 | void C2P(uint32_t *d) 175 | { 176 | uint8_t* ss = ChunkScreenR;// +128 * SCREEN_LEFT + SCREEN_TOP; 177 | for (int y = 0; y < 128*4-1; y++) 178 | { 179 | uint8_t *s = ss; 180 | uint32_t prev_pix = 0xFF000000; 181 | #ifdef CMODE256 182 | for (int x = 0; x < 180*4;) 183 | #else 184 | for (int x = 0; x < 180 * 4;) 185 | #endif 186 | { 187 | //ScreenBitmap->SetPixel(x, y, Color::FromArgb(PALLETTE[*s])); 188 | //d[x + y * 180 * 4] = c; 189 | #ifdef CMODE256 190 | uint32_t c = s[(y >> 2) + (x >> 2) * 128]; 191 | uint32_t c1 = (c >> 6) & 3; 192 | uint32_t c2 = (c >> 4) & 3; 193 | uint32_t c3 = (c >> 2) & 3; 194 | uint32_t c4 = (c >> 0) & 3; 195 | if (c2 == 2 && c3 == 0) c2 = 1; 196 | 197 | c1 *= 0x550000; 198 | c2 *= 0x5500; 199 | c3 *= 0x5500; 200 | c4 *= 0x55; 201 | if (y & 2) x++; 202 | prev_pix = (prev_pix & 0xFF00FFFF) | c1; 203 | d[x + y * 180 * 4] = prev_pix; x++; 204 | prev_pix = (prev_pix & 0xFFFF00FF) | c2; 205 | d[x + y * 180 * 4] = prev_pix; x++; 206 | prev_pix = (prev_pix & 0xFFFF00FF) | c3; 207 | d[x + y * 180 * 4] = prev_pix; x++; 208 | prev_pix = (prev_pix & 0xFFFFFF00) | c4; 209 | d[x + y * 180 * 4] = prev_pix; x++; 210 | if (y & 2) x--; 211 | #else 212 | #ifdef CMODE_PAL32 213 | uint32_t c = TPALLETTE[s[(y >> 2) + (x >> 2) * 128]]; 214 | c |= 0xFF000000; 215 | #else 216 | uint32_t c = PALLETTE[s[(y >> 2) + (x >> 2) * 128]]; 217 | #endif 218 | #if 0 219 | prev_pix = (prev_pix & 0xFF00FFFF) | (c & 0x00FF0000); 220 | d[x + y * 180 * 4] = prev_pix; x++; 221 | prev_pix = (prev_pix & 0xFFFF00FF) | (c & 0x0000FF00); 222 | d[x + y * 180 * 4] = prev_pix; x++; 223 | prev_pix = (prev_pix & 0xFFFFFF00) | (c & 0x000000FF); 224 | d[x + y * 180 * 4] = prev_pix; x++; 225 | prev_pix = (prev_pix & 0xFFFFFF00) | (c & 0x000000FF); 226 | d[x + y * 180 * 4] = prev_pix; x++; 227 | #else 228 | #if 0 229 | if (y & 2) 230 | { 231 | uint32_t c2 = PALLETTE[s[(y >> 2) - 1 + (x >> 2) * 128]]; 232 | c &= 0xAAAAAAAA; 233 | c2 >>= 1; 234 | c2 &= 0x55555555; 235 | c |= c2; 236 | } 237 | #endif 238 | #if 0 239 | if (y & 2) 240 | { 241 | c &= 0xFEFEFEFE; 242 | c >>= 1; 243 | c |= 0x80000000; 244 | } 245 | #endif 246 | d[x + y * 180 * 4] = c; x++; 247 | d[x + y * 180 * 4] = c; x++; 248 | d[x + y * 180 * 4] = c; x++; 249 | d[x + y * 180 * 4] = c; x++; 250 | #endif 251 | #endif 252 | //if ((x & 3) == 3) s++; 253 | } 254 | //if ((y & 3) == 3) ss += SCRWIDTH; 255 | } 256 | } 257 | 258 | -------------------------------------------------------------------------------- /Map/rendermove.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | #include 3 | #include "render.h" 4 | #include "renderutils.h" 5 | 6 | //Где находится камера, 24.8 7 | FIXP32 CamX=0; 8 | FIXP32 CamY=0; 9 | FIXP32 CamZ=0; 10 | 11 | FIXP32 PlayerX = 0; 12 | FIXP32 PlayerY = 0; 13 | FIXP32 PlayerZ = 0; 14 | 15 | static FILE* flog; 16 | 17 | #define DBG(...) do{if (flog) {fprintf(flog,__VA_ARGS__); fflush(flog);}}while(0) 18 | 19 | static void DBGF(TFACE* f) 20 | { 21 | if (!flog) return; 22 | if (f->T) 23 | { 24 | fprintf(flog, "FACE_%d", f->id); 25 | } 26 | else 27 | fprintf(flog, "VFACE_%d", f->id); 28 | //fprintf(flog, "_[%.2f %.2f %.2f %.2f]", f->A / 65536.0, f->B / 65536.0, f->C / 65536.0, f->D / 256.0); 29 | fprintf(flog, "_[%.3f %.3f %.3f]", -f->MX / 80.0, -f->MZ / 80.0, -f->MY / 80.0); 30 | /*fprintf(flog, "("); 31 | for (VERTEX* v = f->v; v; v = v->next) 32 | { 33 | //fprintf(flog, "%d", v->point->id); 34 | //if (v->next) fprintf(flog, ","); 35 | fprintf(flog, "[%.3f %.3f %.3f]", -v->point->X / 80.0, -v->point->Z / 80.0, -v->point->Y / 80.0); 36 | } 37 | fprintf(flog, ")");*/ 38 | fflush(flog); 39 | } 40 | 41 | #if 0 42 | FIXP32 ComputeDistanceToFace(FACE* face, FIXP32 X, FIXP32 Y, FIXP32 Z) 43 | { 44 | FIXP64 s; 45 | s = (FIXP64)X * face->A; 46 | s += (FIXP64)Y * face->B; 47 | s += (FIXP64)Z * face->C; //40.24 48 | s >>= 16; //24.8 49 | return (FIXP32)s + face->D; 50 | } 51 | #endif 52 | 53 | void DebugCEdistances(char *str) 54 | { 55 | char* s = str; 56 | s += sprintf(s, "%08X %08X %08X \n", CamX, CamY, CamZ); 57 | s += sprintf(s, "%.2f %.2f %.2f\n", (double)CamX / 80.0, (double)CamY / 80.0, (double)CamZ / 80.0); 58 | #if 0 59 | s += sprintf(s, "%d %d %d Cube%d\n", CamX, CamY, CamZ, CurrentCube->id); 60 | CUBE* cube = CurrentCube; 61 | int i = 0; 62 | for (FACE *f=cube->f; f; f=f->next, i++) 63 | { 64 | float d; 65 | d = ComputeDistanceToFace(f, CamX, CamY, CamZ) / 256.0f; 66 | s += sprintf(s, "%c%d=%f\n", f->portal_to_cube ? 'P' : 'F', i, d); 67 | if (i > 4) 68 | { 69 | s += sprintf(s, "....\n"); 70 | break; 71 | } 72 | } 73 | #endif 74 | extern FIXP32 mtx_error; 75 | s += sprintf(s, "mtx_error=%f\n", mtx_error / 16384.0f); 76 | 77 | s += sprintf(s, "TC=%d PC=%d PP=%d PV=%d PF1=%d PF2=%d PF3=%d PF=%d SF=%d DF=%d\n", 78 | traveled_cubes, 79 | prepared_cubes, 80 | prepared_points, 81 | prepared_vertexes, 82 | prepared_faces_stage1, 83 | prepared_faces_stage2, 84 | prepared_faces_stage3, 85 | processed_faces, 86 | send_to_render_faces, 87 | dropped_in_render_faces 88 | ); 89 | extern int max_pool_used; 90 | s += sprintf(s, "max_pool_used=%03d\n", max_pool_used); 91 | *s = 0; 92 | } 93 | 94 | static FIXP32 isqrt(FIXP32 v) 95 | { 96 | return (FIXP32)sqrt((double)v); 97 | } 98 | 99 | static inline FIXP32 ComputeVectorMagnitude(FIXP32 x, FIXP32 y, FIXP32 z) 100 | { 101 | if (x < 0) x = -x; 102 | if (y < 0) y = -y; 103 | if (z < 0) z = -z; 104 | FIXP32 min, max; 105 | if (x < y) 106 | { 107 | min = x; 108 | max = y; 109 | } 110 | else 111 | { 112 | min = y; 113 | max = x; 114 | } 115 | FIXP32 a; 116 | a = max + (min >> 1); 117 | if (z < a) 118 | { 119 | min = z; 120 | max = a; 121 | } 122 | else 123 | { 124 | min = a; 125 | max = z; 126 | } 127 | a = max + (min >> 1); 128 | return a; 129 | } 130 | 131 | uint32_t* collision_index; 132 | uint32_t* collision_list; 133 | 134 | static TFACE* collided_face; 135 | 136 | #if 0 137 | FIXP32 SD2leaf(FIXP32 X, FIXP32 Y, FIXP32 Z) 138 | { 139 | DBG("*** SD2leaf ***\n"); 140 | collided_face = NULL; 141 | KDTREE_NODE* node = FindKDtreeNode(X, Y, Z); 142 | uint32_t index = (uint32_t)(node - kd_tree); 143 | uint32_t* p = (uint32_t*)((size_t)collision_list + collision_index[index]); 144 | FIXP32 min_d; 145 | min_d = INT32_MAX; 146 | while ((index = *p++) != 0) 147 | { 148 | TFACE* face; 149 | face = GetFaceByOffset(index - 1); 150 | DBGF(face); DBG("\n"); 151 | FIXP32 x, y, z; 152 | FPXYZ* p; 153 | TVERTEX* v = face->vertexes; 154 | p = v->p; 155 | FIXP32 xa, xp, ya, yp, za, zp; 156 | FIXP32 d; 157 | xp = X - p->X; 158 | yp = Y - p->Y; 159 | zp = Z - p->Z; 160 | //Сразу чекнем сторону 161 | d = xp * face->A14 + yp * face->B14 + zp * face->C14; 162 | d >>= 14; 163 | if (d < 0) continue; 164 | if (d > MIN_D_WALK * 2) 165 | continue; 166 | DBG("\tTest with d=%d\n", d); 167 | do 168 | { 169 | FPXYZ* pp; 170 | pp = p; 171 | xa = p->X; 172 | ya = p->Y; 173 | za = p->Z; 174 | v++; 175 | p = v->p; 176 | if (!p) 177 | { 178 | v = face->vertexes; 179 | p = v->p; 180 | v = NULL; 181 | } 182 | xa -= p->X; 183 | ya -= p->Y; 184 | za -= p->Z; 185 | 186 | xp += xa; 187 | yp += ya; 188 | zp += za; 189 | 190 | x = ya * face->C14 - za * face->B14; 191 | y = za * face->A14 - xa * face->C14; 192 | z = xa * face->B14 - ya * face->A14; 193 | 194 | x >>= 16; 195 | y >>= 16; 196 | z >>= 16; 197 | 198 | if ((x * xp + y * yp + z * zp) < 0) 199 | { 200 | //Теперь считаем проекцию вектора p на вектор а 201 | DBG("\t...Camera outside...\n"); 202 | FIXP32 w; 203 | w = xa * xa + ya * ya + za * za; 204 | w >>= 15; 205 | if (!w) 206 | // continue; //Кстати, при вменяемой геометри мы сюда никогда не попадем 207 | goto L1; 208 | FIXP32 h; 209 | h = xp * xa + yp * ya + zp * za; 210 | if (h < 0) h = 0; 211 | h /= w; 212 | if (h > 0x7FFF) 213 | { 214 | L1: 215 | h = 0x7FFF; 216 | } 217 | xa = (xa * h) >> 15; 218 | ya = (ya * h) >> 15; 219 | za = (za * h) >> 15; 220 | xa -= xp; 221 | ya -= yp; 222 | za -= zp; 223 | //d = ComputeVectorMagnitude(xa, ya, za); 224 | d = xa * xa + ya * ya + za * za; 225 | goto L_brk; 226 | } 227 | //DBG("\t...Camera inside...\n"); 228 | } while (v); 229 | //d = xp * face->A14 + yp * face->B14 + zp * face->C14; 230 | d = d * d; 231 | L_brk: 232 | //DBG("d=%08X\n", d); 233 | if (d < min_d) 234 | { 235 | min_d = d; 236 | DBG("\tNew min_d = %08X\n", min_d); 237 | collided_face = face; 238 | } 239 | ; 240 | } 241 | return min_d; 242 | } 243 | #else 244 | FIXP32 SD2leaf(FIXP32 X, FIXP32 Y, FIXP32 Z) 245 | { 246 | DBG("*** SD2leaf ***\n"); 247 | collided_face = NULL; 248 | KDTREE_NODE* node = FindKDtreeNode(X, Y, Z); 249 | uint32_t index = (uint32_t)(node - kd_tree); 250 | uint32_t* p = (uint32_t*)((size_t)collision_list + collision_index[index]); 251 | FIXP32 min_d; 252 | min_d = INT32_MAX; 253 | while ((index = *p++) != 0) 254 | { 255 | TFACE* face; 256 | face = GetFaceByOffset(index - 1); 257 | DBGF(face); DBG("\n"); 258 | FIXP32 x, y, z; 259 | FPXYZ* p; 260 | TVERTEX* v = face->vertexes; 261 | p = v->p; 262 | FIXP32 xa, xp, ya, yp, za, zp; 263 | FIXP32 d; 264 | xp = X - p->X; 265 | yp = Y - p->Y; 266 | zp = Z - p->Z; 267 | //Сразу чекнем сторону 268 | d = xp * face->A14 + yp * face->B14 + zp * face->C14; 269 | d >>= 14; 270 | DBG("\tDistance to face %d\n", d); 271 | if (d < 0) continue; 272 | if (d >= MIN_D_WALK * 2) 273 | continue; //Next face 274 | d = d * d; 275 | do 276 | { 277 | FPXYZ* pp; 278 | pp = p; 279 | xa = p->X; 280 | ya = p->Y; 281 | za = p->Z; 282 | v++; 283 | p = v->p; 284 | if (!p) 285 | { 286 | v = face->vertexes; 287 | p = v->p; 288 | v = NULL; 289 | } 290 | xa -= p->X; 291 | ya -= p->Y; 292 | za -= p->Z; 293 | 294 | xp += xa; 295 | yp += ya; 296 | zp += za; 297 | 298 | x = ya * face->C14 - za * face->B14; 299 | y = za * face->A14 - xa * face->C14; 300 | z = xa * face->B14 - ya * face->A14; 301 | 302 | x >>= 14; 303 | y >>= 14; 304 | z >>= 14; 305 | 306 | FIXP32 d2; 307 | 308 | if ((d2 = x * xp + y * yp + z * zp) < 0) 309 | { 310 | FIXP32 R; 311 | R = x * x + y * y + z * z; 312 | d2 = (FIXP64)d2 * d2 / R; 313 | DBG("\t\t...Camera outside (d2=%d, R=%d)...\n", isqrt(d2), isqrt(R)); 314 | d += d2; 315 | goto L_brk; 316 | } 317 | } while (v); 318 | L_brk: 319 | if (d < min_d) 320 | { 321 | min_d = d; 322 | DBG("\tNew min_d = %08X\n", min_d); 323 | collided_face = face; 324 | } 325 | ; 326 | } 327 | return min_d; 328 | } 329 | #endif 330 | 331 | static inline FIXP32 AsrDecay(FIXP32 v) 332 | { 333 | if (v > 0) 334 | { 335 | v >>= 1; 336 | } 337 | else 338 | { 339 | v = -((-v) >> 1); 340 | } 341 | return v; 342 | } 343 | 344 | //Перемещаем игрока, а следом за ним - камеру 345 | void MovePlayer(FIXP32 dX, FIXP32 dY, FIXP32 dZ) 346 | { 347 | FIXP32 X, Y, Z; 348 | FIXP32 dx, dy, dz; 349 | 350 | static FIXP32 Vx, Vy, Vz; 351 | 352 | dx = MUL(dX, RMTXp[0]) + MUL(dY, RMTXp[1]) + MUL(dZ, RMTXp[2]); 353 | dy = MUL(dX, RMTXp[3]) + MUL(dY, RMTXp[4]) + MUL(dZ, RMTXp[5]); 354 | dz = MUL(dX, RMTXp[6]) + MUL(dY, RMTXp[7]) + MUL(dZ, RMTXp[8]); 355 | 356 | dx += (Vx = AsrDecay(Vx)); 357 | dy += (Vy = AsrDecay(Vy)); 358 | dz += (Vz = AsrDecay(Vz)); 359 | 360 | X = PlayerX + dx; 361 | Y = PlayerY + dy; 362 | Z = PlayerZ + dz; 363 | 364 | static FIXP32 last_d; 365 | 366 | if (!kd_tree) 367 | { 368 | PlayerX = X; 369 | PlayerY = Y; 370 | PlayerZ = Z; 371 | return; 372 | } 373 | 374 | #if 1 375 | if (X <= Scene_min_X) 376 | return; 377 | if (X >= Scene_max_X) 378 | return; 379 | if (Y <= Scene_min_Y) 380 | return; 381 | if (Y >= Scene_max_Y) 382 | return; 383 | if (Z <= Scene_min_Z) 384 | return; 385 | if (Z >= Scene_max_Z) 386 | return; 387 | #endif 388 | 389 | flog = fopen("movecam.log", "wt"); 390 | FIXP32 min_d; 391 | min_d = SD2leaf(X, Y, Z); 392 | if (min_d >= MIN_D_WALK * MIN_D_WALK) 393 | { 394 | 395 | } 396 | else 397 | { 398 | X = PlayerX; 399 | Y = PlayerY; 400 | Z = PlayerZ; 401 | do 402 | { 403 | dx = AsrDecay(dx); 404 | dy = AsrDecay(dy); 405 | dz = AsrDecay(dz); 406 | min_d = (last_d + min_d + 1) / 2; 407 | } while (min_d < MIN_D_WALK * MIN_D_WALK); 408 | X += dx; 409 | Y += dy; 410 | Z += dz; 411 | TFACE* f; 412 | f = collided_face; 413 | //Vx = f->A14 >> 8; 414 | //Vy = f->B14 >> 8; 415 | //Vz = f->C14 >> 8; 416 | 417 | #if 0 418 | TFACE* f; 419 | f = collided_face; 420 | FIXP32 t; 421 | t = dx * f->A14 + dy * f->B14 + dz * f->C14; 422 | t >>= 14; 423 | if (t > 0) 424 | { 425 | //goto L_err; 426 | //break; 427 | X += (f->A14 >> 9); 428 | Y += (f->B14 >> 9); 429 | Z += (f->C14 >> 9); 430 | } 431 | else 432 | { 433 | FIXP32 a, b, c; 434 | a = f->A14 * t; 435 | b = f->B14 * t; 436 | c = f->C14 * t; 437 | a >>= 14; 438 | b >>= 14; 439 | c >>= 14; 440 | a = dx - a; 441 | b = dy - b; 442 | c = dz - c; 443 | X += a; 444 | Y += b; 445 | Z += c; 446 | } 447 | #endif 448 | } 449 | PlayerX = X; 450 | PlayerY = Y; 451 | PlayerZ = Z; 452 | last_d = min_d; 453 | //L_err: 454 | if (flog) fclose(flog); 455 | flog = NULL; 456 | //Теперь корректируем положение и матрицу камеры 457 | #ifdef NO_PLAYER 458 | CamX = PlayerX; 459 | CamY = PlayerY; 460 | CamZ = PlayerZ; 461 | #else 462 | //Камера должна быть сзади и выше игрока 463 | X = MUL(CamDisp_X, RMTXp[0]) + MUL(CamDisp_Y, RMTXp[1]) + MUL(CamDisp_Z, RMTXp[2]) + PlayerX; 464 | Y = MUL(CamDisp_X, RMTXp[3]) + MUL(CamDisp_Y, RMTXp[4]) + MUL(CamDisp_Z, RMTXp[5]) + PlayerY; 465 | Z = MUL(CamDisp_X, RMTXp[6]) + MUL(CamDisp_Y, RMTXp[7]) + MUL(CamDisp_Z, RMTXp[8]) + PlayerZ; 466 | 467 | CamX -= (CamX - X) >> 4; 468 | CamY -= (CamY - Y) >> 4; 469 | CamZ -= (CamZ - Z) >> 4; 470 | #endif 471 | } 472 | -------------------------------------------------------------------------------- /Map/renderutils.cpp: -------------------------------------------------------------------------------- 1 | #include "renderutils.h" 2 | 3 | -------------------------------------------------------------------------------- /Map/renderutils.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDERUTILS_H 2 | #define RENDERUTILS_H 3 | 4 | #include "render.h" 5 | 6 | 7 | #endif -------------------------------------------------------------------------------- /Map/spyro/FACES.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/FACES.bin -------------------------------------------------------------------------------- /Map/spyro/FPXYZ.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/FPXYZ.bin -------------------------------------------------------------------------------- /Map/spyro/cindex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/cindex.bin -------------------------------------------------------------------------------- /Map/spyro/clist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/clist.bin -------------------------------------------------------------------------------- /Map/spyro/faces_in_leafs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/faces_in_leafs.bin -------------------------------------------------------------------------------- /Map/spyro/fil_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/fil_idx.bin -------------------------------------------------------------------------------- /Map/spyro/kdtree.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/kdtree.bin -------------------------------------------------------------------------------- /Map/spyro/pvs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/pvs.bin -------------------------------------------------------------------------------- /Map/spyro/pvs_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/pvs_idx.bin -------------------------------------------------------------------------------- /Map/spyro/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/texture.bin -------------------------------------------------------------------------------- /Map/spyro/texture32c.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/texture32c.bmp -------------------------------------------------------------------------------- /Map/spyro/textures.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/Map/spyro/textures.bmp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SDDDE 2 | Small 3D engine for Amiga A1200 3 | (C) 2023 by Rst7/CBSIE 4 | 5 | You can find here: 6 | 7 | /Map - PC version of the engine (built with MSVS, C++ and WinForms). Also used for data conversion PC=>Amiga 8 | 9 | /SplitMap - kd-tree and PVS generator 10 | 11 | /SDDDE - Amiga version (built with https://github.com/BartmanAbyss/vscode-amiga-debug) 12 | 13 | /target - Compiled binary for Amiga with converted data 14 | -------------------------------------------------------------------------------- /SDDDE/.vscode/amiga.json: -------------------------------------------------------------------------------- 1 | { 2 | "includePath": [ "${workspaceFolder}/**" ], 3 | "defines": [ ], 4 | "shrinkler": { 5 | "fast": "-h -o -1", 6 | "slow": "-h -f dff180 -9" 7 | } 8 | } -------------------------------------------------------------------------------- /SDDDE/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Amiga", 5 | "configurationProvider": "BartmanAbyss.amiga-debug" 6 | } 7 | ], 8 | "version": 4 9 | } -------------------------------------------------------------------------------- /SDDDE/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "amiga", 6 | "request": "launch", 7 | "preLaunchTask": "compile", 8 | "name": "Amiga 1200", 9 | "config": "A1200", 10 | //"fastmem": "4M", 11 | "program": "${workspaceFolder}/a.mingw", 12 | "kickstart": "D:/ZX/KICK31.rom", 13 | "internalConsoleOptions": "openOnSessionStart" 14 | }/*, 15 | { 16 | "type": "amiga", 17 | "request": "launch", 18 | "preLaunchTask": "compile", 19 | "name": "Amiga 4000", 20 | "config": "A4000", 21 | "program": "${workspaceFolder}/a.mingw", 22 | "kickstart": "D:/ZX/KICK31.rom", 23 | "internalConsoleOptions": "openOnSessionStart" 24 | }*/ 25 | ] 26 | } -------------------------------------------------------------------------------- /SDDDE/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "compile", 8 | "type": "shell", 9 | "command": "${command:amiga.bin-path}\\gnumake.exe", 10 | "args": [ 11 | "-j4", 12 | ], 13 | "options": { 14 | "cwd": "${workspaceRoot}", 15 | "env": { 16 | "PATH": "${command:amiga.bin-path}\\opt\\bin;${command:amiga.bin-path}" 17 | } 18 | }, 19 | "problemMatcher": [ 20 | { 21 | "base": "$gcc", 22 | "fileLocation": "absolute" 23 | } 24 | ], 25 | "presentation": { 26 | "echo": true, 27 | "reveal": "silent", 28 | "focus": false, 29 | "panel": "shared", 30 | "showReuseMessage": false, 31 | "clear": true 32 | }, 33 | "group": { 34 | "kind": "build", 35 | "isDefault": true 36 | } 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /SDDDE/Makefile: -------------------------------------------------------------------------------- 1 | # to generate assembler listing with LTO, add to LDFLAGS: -Wa,-adhln=$@.listing,--listing-rhs-width=200 2 | # for better annotations add -dA -dP 3 | # to generate assembler source with LTO, add to LDFLAGS: -save-temps=cwd 4 | 5 | forward-to-backward = $(subst /,\,$1) 6 | 7 | subdirs := $(wildcard */) 8 | VPATH = $(subdirs) 9 | cpp_sources := $(wildcard *.cpp) $(wildcard $(addsuffix *.cpp,$(subdirs))) 10 | cpp_objects := $(addprefix obj/,$(patsubst %.cpp,%.o,$(notdir $(cpp_sources)))) 11 | c_sources := $(wildcard *.c) $(wildcard $(addsuffix *.c,$(subdirs))) 12 | c_objects := $(addprefix obj/,$(patsubst %.c,%.o,$(notdir $(c_sources)))) 13 | s_sources := support/gcc8_a_support.s asm/render_utils.s asm/tmap.s asm/fmap.s asm/navigate.s asm/c2p.s 14 | s_objects := $(addprefix obj/,$(patsubst %.s,%.o,$(notdir $(s_sources)))) 15 | objects := $(cpp_objects) $(c_objects) $(s_objects) 16 | 17 | # https://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile/4038459 18 | # http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html 19 | 20 | OUT = a.mingw 21 | CC = m68k-amiga-elf-gcc 22 | 23 | #CCFLAGS = -g -MP -MMD -m68020 -Ofast -nostdlib -Wextra -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions -fno-unroll-loops 24 | CCFLAGS = -g -MP -MMD -m68020 -O2 -nostdlib -Wextra -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -fno-exceptions -fno-unroll-loops -fno-tree-vectorize -fno-builtin -fno-function-cse 25 | #CCFLAGS = -S -fverbose-asm -MP -MMD -g -c -m68020 -Ofast -nostdlib -Wno-unused-function -Wno-volatile-register-var -fomit-frame-pointer -fno-tree-loop-distribution -flto -fwhole-program -fno-exceptions 26 | CPPFLAGS= $(CCFLAGS) -fno-rtti -fcoroutines -fno-use-cxa-atexit 27 | ASFLAGS = -Wa,-g,--register-prefix-optional 28 | LDFLAGS = -Wl,--emit-relocs,-Ttext=0,-Map=$(OUT).map 29 | # -Wa,-adhln=$@.listing,--listing-rhs-width=200 -dA -dP 30 | 31 | all: $(OUT).exe 32 | 33 | $(OUT).exe: $(OUT).elf 34 | $(info Elf2Hunk $(OUT).exe) 35 | @elf2hunk $(OUT).elf $(OUT).exe -s 36 | 37 | $(OUT).elf: $(objects) 38 | $(info Linking a.mingw.elf) 39 | @$(CC) $(CCFLAGS) $(LDFLAGS) $(objects) -o $@ 40 | @m68k-amiga-elf-objdump --disassemble --no-show-raw-ins --visualize-jumps -S $@ >$(OUT).s 41 | 42 | clean: 43 | $(info Cleaning...) 44 | @del /q obj $(OUT).* 2>nul || rmdir obj 2>nul || ver>nul 45 | 46 | -include $(objects:.o=.d) 47 | 48 | $(cpp_objects) : obj/%.o : %.cpp 49 | @if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@)) 50 | $(info Compiling $<) 51 | @$(CC) $(CPPFLAGS) -c -o $@ $(CURDIR)/$< 52 | 53 | $(c_objects) : obj/%.o : %.c 54 | @if not exist "$(call forward-to-backward,$(dir $@))" mkdir $(call forward-to-backward,$(dir $@)) 55 | $(info Compiling $<) 56 | @$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$< 57 | 58 | $(s_objects): obj/%.o : %.s render.s 59 | $(info Assembling $<) 60 | @$(CC) $(CCFLAGS) $(ASFLAGS) -c -o $@ $(CURDIR)/$< 61 | -------------------------------------------------------------------------------- /SDDDE/asm/c2p.s: -------------------------------------------------------------------------------- 1 | .include "render.s" 2 | 3 | .text 4 | .align 4 5 | .globl C2P 6 | .type C2P, @function 7 | C2P: 8 | | 9 | | a6 - custom 10 | | a0 - chunky screen 11 | | a1 - c2p buffer 12 | | a2 - planar screen 13 | | a3 - c2p buffer + 40 14 | | a4 - planar screen + 80 15 | | d6 - mask 0F0F0F0F 16 | | d5 - mask 55555555 17 | move.l #0x0F0F0F0F,d6 18 | move.l #0x55555555,d5 19 | move.l #0xDFF000,a6 20 | | 21 | 444: 22 | btst.b #6,0x002(a6) | Blitter wait 23 | bne.s 444b 24 | | 25 | move.w #0xFFFF,0x044(a6) | BLTAFWM 26 | move.w #0xFFFF,0x046(a6) | BLTALWM 27 | | Now we can start stage 0 (by blitter) 28 | move.w #0,0x066(a6) | BLTDMOD=0 29 | move.l a1,0x054(a6) | BLTDPT=c2p buffer 30 | move.w #200-2,0x062(a6) | BLTBMOD=200-2 31 | move.w #200-2,0x060(a6) | BLTCMOD=200-2 32 | move.l a0,0x048(a6) | BLTCPT=chunky screen (A0A1A2A3B0B1B2B3) 33 | lea 8000(a0),a0 34 | move.l a0,0x04C(a6) | BLTBPT=chunky screen+4000 (C0C1C2C3D0D1D2D3) 35 | move.w #0x3333,0x074(a6) | BLTADAT=0x3333, select B when 1 36 | move.w #0x07CA,0x040(a6) | BLTCON0= USEB USEC USED term=AB + ~AC 37 | move.w #0x2000,0x042(a6) | BLTCON1= BSH=2 38 | move.w #(40<<6)+1,0x058(a6) | run blitter, H=40 W=1 39 | | 40 | lea 40(a1),a3 41 | lea 80(a2),a4 42 | | Stage 1 43 | moveq #100-1-1,d3 44 | 2: 45 | | start next blit 46 | lea 2-8000(a0),a0 47 | 444: 48 | btst.b #6,0x002(a6) | Blitter wait 49 | bne.s 444b 50 | move.l a0,0x048(a6) | BLTCPT=chunky screen (A0A1A2A3B0B1B2B3) 51 | lea 8000(a0),a0 52 | move.l a0,0x04C(a6) | BLTBPT=chunky screen+8000 (C0C1C2C3D0D1D2D3) 53 | move.w #(40<<6)+1,0x058(a6) | run blitter, H=40 W=1 54 | | do one line by CPU 55 | moveq #10-1,d4 56 | 1: 57 | move.l (a3)+,d1 | d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 58 | move.l d1,d7 | d7 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 59 | lsr.l #4,d7 | d7 = ........e7e6e5e4 e3e2e1e0f7f6f5f4 f3f2f1f0g7g6g5g4 g3g2g1g0h7h6h5h4 60 | move.l (a1)+,d0 | d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0 61 | eor.l d0,d7 | d7 = mask0 ^ mask1 still dirty 62 | and.l d6,d7 | d7 = mask 63 | eor.l d7,d0 | d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4 64 | move.l d0,(a2)+ 65 | lsl.l #4,d7 | d7 = mask << 4 66 | eor.l d7,d1 | d1 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0 67 | move.l d1,(a4)+ 68 | dbra d4,1b 69 | | now one line complete 70 | lea 80-40(a1),a1 71 | lea 80-40(a3),a3 72 | lea 200-40(a2),a2 | next planar line 73 | lea 200-40(a4),a4 74 | dbra d3,2b 75 | | last line without blitter pass 76 | moveq #10-1,d4 77 | 444: 78 | btst.b #6,0x002(a6) | Blitter wait 79 | bne.s 444b 80 | 1: 81 | move.l (a3)+,d1 | d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 82 | move.l d1,d7 | d7 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 83 | lsr.l #4,d7 | d7 = ........e7e6e5e4 e3e2e1e0f7f6f5f4 f3f2f1f0g7g6g5g4 g3g2g1g0h7h6h5h4 84 | move.l (a1)+,d0 | d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0 85 | eor.l d0,d7 | d7 = mask0 ^ mask1 still dirty 86 | and.l d6,d7 | d7 = mask 87 | eor.l d7,d0 | d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4 88 | move.l d0,(a2)+ 89 | lsl.l #4,d7 | d7 = mask << 4 90 | eor.l d7,d1 | d1 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0 91 | move.l d1,(a4)+ 92 | dbra d4,1b 93 | | Stage 2, executed in reverse direction 94 | lea 40-2(a1),a1 | last word of c2p buffer 95 | move.l a1,0x054(a6) | BLTDPT=c2p buffer 96 | lea 7800(a0),a0 | last word of chunky screen 97 | move.l a0,0x048(a6) | BLTCPT=chunky screen+8000+7998 (C0C1C2C3D0D1D2D3) 98 | lea -8000(a0),a0 99 | move.l a0,0x04C(a6) | BLTBPT=chunky screen+7998 (A0A1A2A3B0B1B2B3) 100 | move.w #0xCCCC,0x074(a6) | BLTADAT=0xCCCC, select B when 1 101 | move.w #0x2002,0x042(a6) | BLTCON1= BSH=2 + DESC 102 | move.w #(40<<6)+1,0x058(a6) | run blitter, H=40 W=1 103 | lea -78(a1),a1 | last line of c2p buffer 104 | lea 40(a1),a3 | 105 | | Stage 3 106 | moveq #100-1-1,d3 107 | 2: 108 | | start next blit 109 | lea 8000-2(a0),a0 110 | 444: 111 | btst.b #6,0x002(a6) | Blitter wait 112 | bne.s 444b 113 | move.l a0,0x048(a6) | BLTCPT=chunky screen+8000+7998 (C0C1C2C3D0D1D2D3) 114 | lea -8000(a0),a0 115 | move.l a0,0x04C(a6) | BLTBPT=chunky screen+7998 (A0A1A2A3B0B1B2B3) 116 | move.w #(40<<6)+1,0x058(a6) | run blitter, H=40 W=1 117 | | do one line by CPU 118 | moveq #10-1,d4 119 | 1: 120 | move.l (a3)+,d1 | d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 121 | move.l d1,d7 | d7 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 122 | lsr.l #4,d7 | d7 = ........e7e6e5e4 e3e2e1e0f7f6f5f4 f3f2f1f0g7g6g5g4 g3g2g1g0h7h6h5h4 123 | move.l (a1)+,d0 | d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0 124 | eor.l d0,d7 | d7 = mask0 ^ mask1 still dirty 125 | and.l d6,d7 | d7 = mask 126 | eor.l d7,d0 | d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4 127 | move.l d0,(a2)+ 128 | lsl.l #4,d7 | d7 = mask << 4 129 | eor.l d7,d1 | d1 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0 130 | move.l d1,(a4)+ 131 | dbra d4,1b 132 | | now one line complete 133 | lea -80-40(a1),a1 | prev line in C2Pbuffer 134 | lea -80-40(a3),a3 135 | lea -200-40(a2),a2 | prev planar line 136 | lea -200-40(a4),a4 137 | dbra d3,2b 138 | | last line without blitter pass 139 | moveq #10-1,d4 140 | 444: 141 | btst.b #6,0x002(a6) | Blitter wait 142 | bne.s 444b 143 | 1: 144 | move.l (a3)+,d1 | d1 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 145 | move.l d1,d7 | d7 = e7e6e5e4e3e2e1e0 f7f6f5f4f3f2f1f0 g7g6g5g4g3g2g1g0 h7h6h5h4h3h2h1h0 146 | lsr.l #4,d7 | d7 = ........e7e6e5e4 e3e2e1e0f7f6f5f4 f3f2f1f0g7g6g5g4 g3g2g1g0h7h6h5h4 147 | move.l (a1)+,d0 | d0 = a7a6a5a4a3a2a1a0 b7b6b5b4b3b2b1b0 c7c6c5c4c3c2c1c0 d7d6d5d4d3d2d1d0 148 | eor.l d0,d7 | d7 = mask0 ^ mask1 still dirty 149 | and.l d6,d7 | d7 = mask 150 | eor.l d7,d0 | d0 = a7a6a5a4e7e6e5e4 b7b6b5b4f7f6f5f4 c7c6c5c4g7g6g5g4 d7d6d5d4h7h6h5h4 151 | move.l d0,(a2)+ 152 | lsl.l #4,d7 | d7 = mask << 4 153 | eor.l d7,d1 | d1 = a3a2a1a0e3e2e1e0 b3b2b1b0f3f2f1f0 c3c2c1c0g3g2g1g0 d3d2d1d0h3h2h1h0 154 | move.l d1,(a4)+ 155 | dbra d4,1b 156 | | 157 | | Stage 4 - convert ABCDEFGH to AACCEEGG and BBDDFFHH 158 | | 159 | | a2 - bpl2 160 | | a4 - bpl0 161 | lea 40(a2),a2 | a2 = bpl1 162 | | 163 | | Prepare blitter conversion to AACCEEGG 164 | | 165 | move.w #200-40,0x066(a6) | BLTDMOD 166 | move.l a4,0x054(a6) | BLTDPT = bit0 167 | move.w #200-40,0x062(a6) | BLTBMOD 168 | move.w #200-40,0x060(a6) | BLTCMOD 169 | move.l a2,0x048(a6) | BLTCPT=bpl1 170 | move.l a2,0x04C(a6) | BLTBPT=bpl1 171 | move.w #0x5555,0x074(a6) | BLTADAT=0x5555, select B when 1 172 | move.w #0x1000,0x042(a6) | BLTCON1= BSH=1 173 | move.w #(100<<6)+20,0x058(a6) | run blitter, H=100 W=20 174 | | 175 | | Prepare CPU conversion to BBDDFFHH 176 | | 177 | moveq #100-1,d4 178 | 2: 179 | moveq #10-1,d3 180 | move.l a2,a3 181 | move.l (a2)+,d0 182 | 1: 183 | and.l d5,d0 | 0B0D0F0H 184 | move.l d0,d1 185 | add.l d1,d1 | B0D0F0H0 186 | add.l d0,d1 | BBDDFFHH 187 | move.l (a2)+,d0 188 | move.l d1,(a3)+ 189 | dbra d3,1b 190 | lea 200-44(a2),a2 | next planar line 191 | dbra d4,2b 192 | 193 | rts -------------------------------------------------------------------------------- /SDDDE/asm/fmap.s: -------------------------------------------------------------------------------- 1 | .include "render.s" 2 | 3 | 4 | .extern frameCounter 5 | .text 6 | 7 | .align 4 8 | | 9 | fculling_qhead: 10 | dc.l 0 11 | .extern RDataPool_top 12 | 13 | fmap_exit2: 14 | move.l fmap_LINK_REGISTER,a0 15 | jmp (a0) 16 | .align 4 17 | fmap: 18 | 19 | |a7 - RVERTEX pool 20 | |a0 - rface 21 | |a1 - fout 22 | |a2 - vs1 / &vs1->U 23 | |a3 - vs2 / &vs2->U 24 | |a4 - &newv->U 25 | |a6 - vlast 26 | |d0 - t1 27 | |d1 - t2 28 | |d2 - scratch 29 | |d3 - scratch 30 | |d5 - planes count 31 | |d7 - save t2 32 | | 33 | Profile 14,d0 34 | lea fculling_qhead-RFACE.next(pc),a1 |point fout to head pointer 35 | bra.s fculling_faces_loop 36 | .align 4 37 | fculling_faces_loop_end: 38 | clr.l RFACE.next(a1) 39 | move.l fculling_qhead(pc),a0 40 | tst.l a0 41 | beq.s fmap_exit2 42 | bra.w fmap_prepare 43 | .align 4 44 | fculling_accept_face: 45 | move.l a0,RFACE.next(a1) 46 | move.l a0,a1 | fout=rface 47 | fculling_next_face: 48 | move.l RFACE.next(a0),a0 49 | tst.l a0 50 | beq.s fculling_faces_loop_end 51 | fculling_faces_loop: 52 | tst.b RFACE.flagsL(a0) |check only low 8 bits 53 | beq.s fculling_accept_face 54 | move.l RFACE.vertex(a0),a6 | 55 | move.l RVERTEX.vp(a6),a6 |vlast=rface->vertex->prev 56 | moveq #5*3,d5 57 | fculling_planes_loop: 58 | move.l a6,a3 |vs2=vlast 59 | sub.l a2,a2 |vs1=NULL 60 | bra.s fculling_loop 61 | fculling_prep_t1: 62 | move.w d1,d7 63 | move.l a3,a2 |vs1=vs2 64 | move.l RFACE.vertex(a0),a3 |vs2=rfacce->vertex 65 | move.l a0,a6 |vlast=(RVERTEX*)rface 66 | fculling_loop: 67 | move.w RVERTEX.z(a3),d1 68 | cmpi.w #3*3,d5 69 | bcc.s fculling_t2_no58 70 | | .extern section_table_58 71 | | move.w section_table_58(pc,d1.w*2),d1 72 | move.w d1,d2 73 | lsr.w #2,d2 74 | add.w d2,d1 75 | addq.w #1,d1 76 | lsr.w #1,d1 77 | fculling_t2_no58: 78 | jmp fculling_t2_0-6(pc,d5*2) 79 | fculling_t2_0: 80 | sub.w RVERTEX.y(a3),d1 81 | bra.s fculling_t2_ok 82 | fculling_t2_1: 83 | add.w RVERTEX.y(a3),d1 84 | bra.s fculling_t2_ok 85 | fculling_t2_2: 86 | sub.w RVERTEX.x(a3),d1 87 | bra.s fculling_t2_ok 88 | fculling_t2_3: 89 | add.w RVERTEX.x(a3),d1 90 | bra.s fculling_t2_ok 91 | fculling_t2_4: 92 | subi.w #51,d1 93 | fculling_t2_ok: 94 | tst.l a2 95 | beq.s fculling_prep_t1 96 | move.w d7,d0 97 | | 98 | move.w d1,d7 |save t2, coz if t2>=0 then ADD_VERTEX(vd,vs2) 99 | move.w d0,d2 100 | eor.w d1,d2 101 | bpl.s no_fculling 102 | | Allocate RVERTEX 103 | move.l (a7)+,a4 | Get vertex from pool 104 | moveq #5-1,d3 105 | move.w d3,RVERTEX.flagH(a4) | set "no scoords" flag and clear low flags 106 | moveq #RVERTEX.U,d2 107 | add.l d2,a2 108 | add.l d2,a3 109 | add.l d2,a4 110 | tst.w d7 111 | bmi.s fculling_no_rv 112 | exg d0,d1 113 | exg a2,a3 114 | fculling_no_rv: 115 | sub.w d0,d1 116 | neg.w d1 | t2=t1-t2 117 | swap d0 118 | clr.w d0 119 | | ext.l d1 120 | | add.l d1,d0 121 | lsr.l #1,d0 | t1<<=15 122 | divu.w d1,d0 | t1=(t1+(t2>>1))/t2| 123 | fculling_param_loop: 124 | move.w (a3)+,d1 125 | move.w (a2)+,d2 126 | sub.w d2,d1 | d = vs2->U - vs1->U| 127 | muls.w d0,d1 | d = (d*t+0x4000)>>15| 128 | add.l d1,d1 129 | swap d1 130 | | bpl.s fculling_no_round2 131 | | addq.w #1,d1 132 | |fculling_no_round2: 133 | add.w d1,d2 134 | move.w d2,(a4)+ | newv->U = vs1->U + P[d] - M[d]| 135 | dbra d3,fculling_param_loop 136 | tst.w d7 137 | bmi.s fculling_no_rv2 138 | exg a2,a3 139 | fculling_no_rv2: 140 | moveq #-RVERTEX.flagH,d2 141 | add.l d2,a3 | restore vs2 base 142 | add.l d2,a4 | restore newv 143 | | ADD_VERTEX(vd,newv)| 144 | move.l a4,RVERTEX.vn(a6) | last->vn=newv 145 | move.l a4,a6 | last=newv 146 | no_fculling: 147 | tst.w d7 148 | bmi.s fculling_no_add_vs2 149 | move.l a3,RVERTEX.vn(a6) | last->vn=vs2 150 | move.l a3,a6 | last=vs2 151 | dc.w 0x0C40 | opcode cmpi.w #xxxx,d0 152 | fculling_no_add_vs2: 153 | move.l a3,-(a7) | Save vs2 to pool 154 | move.l a3,a2 | vs1=vs2 155 | move.l RVERTEX.vn(a3),a3 156 | tst.l a3 157 | bne.w fculling_loop 158 | | 159 | cmp.l a6,a0 160 | beq.s fculling_skip_face | if vlast==(RVERTEX*)f - skip face 161 | clr.l RVERTEX.vn(a6) | last->next=NULL 162 | subq.l #3,d5 163 | bne.w fculling_planes_loop 164 | move.l RFACE.vertex(a0),a3 165 | move.l a6,RVERTEX.vp(a3) | rface->vertex->prev=last 166 | bra.w fculling_accept_face 167 | fculling_skip_face: 168 | move.l a0,-(a7) | return face to pool 169 | bra.w fculling_next_face 170 | .align 4 171 | fmap_prepare: 172 | |A0 - RFACE* 173 | |A1 - tv 174 | |A2 - bv 175 | |A3 - xmax 176 | |A4 - x 177 | |A5 - color 178 | |A6 - *xtab 179 | |A7 - *D 180 | |D0 - tx 181 | |D1 - bx 182 | |D2 - scratch 183 | |D3 - scratch 184 | |D4 - ty 185 | |D5 - dty 186 | |D6 - by 187 | |D7 - dby 188 | Profile 15,d0 189 | move.l a0,a2 190 | | Считаем экранные координаты, если они еще не готовы 191 | | + Ищем самый верхний элемент (и самый нижний) 192 | | + Полностью заполняем prev 193 | move.l #_LOGtab+32768,a5 194 | move.l #EXPtab+65536,a6 195 | bra.s fmap_prep_loop 196 | fmap_scoord_not_ok: 197 | movem.w RVERTEX.x(a1),d4-d6 198 | move.w (a5,d6.w*2),d6 |log(z) 199 | move.w (a5,d4.w*2),d4 |log(x) 200 | beq.s fmap_no_clip_xz |log(x)==0 201 | sub.w d6,d4 202 | bcs.s fmap_no_clip_xz |log(x) 1) 271 | dc.w (0x8000+(h_count>>1))/h_count 272 | .else 273 | dc.w 0x7FFF 274 | .endif 275 | .set h_count,h_count-1 276 | .endm 277 | 278 | Inv_table: 279 | .rept 256 280 | inverse8 281 | .endr 282 | fmap_load_t: 283 | clr.l d4 284 | fmap_loop_load_t: 285 | move.w RVERTEX.sy(a1),d4 | Грузим начальную точку 286 | move.w d0,d2 | w=tx 287 | cmp.w a3,d0 | if (tx>=xmax) stop 288 | bcc.s fmap_loop_load_t_stop 289 | move.l RVERTEX.vp(a1),a1 | tv = tv->pv 290 | move.b RVERTEX.sx(a1),d0 | tx = tv->sx >> 8 291 | cmp.w a4,d0 | while(tx=xmax) stop 313 | bcc.s fmap_loop_load_b_stop 314 | move.l RVERTEX.vn(a2),a2 | tv = tv->pv 315 | move.b RVERTEX.sx(a2),d0 | tx = tv->sx >> 8 316 | cmp.w a4,d0 | while(txx 337 | move.l #0xDEADBEEF,a6 338 | .globl Xtab_patch2 339 | Xtab_patch2 = .-4 340 | lea (a6,d0.w*4),a6 | xtab+Xmin*4 341 | move.l d0,a4 | xmin 342 | move.w d0,d2 | bx=tx 343 | swap d0 344 | move.w d2,d0 345 | fmap_loop: 346 | addq.l #1,a4 | x++ 347 | cmp.w a4,d0 | if (tx> 8) - t 365 | swap d3 366 | sub.w d2,d3 | h=h-t 367 | bls.s fmap_nextline | if (h > 0) 368 | subq.w #1,d3 369 | btst #0,d2 370 | bne.s fmap_no_y_swap 371 | ror.w #8,d1 372 | fmap_no_y_swap: 373 | add.w d2,d2 374 | add.w d2,a7 | D+=t*2 375 | move.w d1,d2 376 | lsr.w #8,d2 377 | fmap_inner_loop: 378 | move.b d2,(a7)+ 379 | dbra d3,fmap_inner_loop1 380 | bra.s fmap_nextline 381 | fmap_inner_loop1: 382 | move.b d1,(a7)+ 383 | dbra d3,fmap_inner_loop 384 | fmap_nextline: 385 | add.l d5,d4 386 | add.l d7,d6 387 | cmp.l a3,a4 388 | bcs.s fmap_loop 389 | fmap_stop: 390 | move.l (a0),a0 391 | tst.l a0 392 | bne.s fmap_face_loop 393 | |fmap_end_of_loop: 394 | | ....return to prev level.... 395 | move.l RDataPool_top,a7 396 | |fmap_exit: 397 | move.l fmap_LINK_REGISTER,a0 398 | jmp (a0) 399 | .align 4 400 | fmap_LINK_REGISTER: 401 | ds.l 1 402 | 403 | |======================================================================================= 404 | | 405 | | Filled render 406 | | 407 | |======================================================================================= 408 | 409 | .align 4 410 | .globl RenderF 411 | .type RenderF,@function 412 | .extern sort_q2 413 | 414 | RenderF_qhead: 415 | dc.l 0 416 | |d4 - dith 417 | |d5 - vroot 418 | |d7 - counter 419 | |a0 - vlast 420 | |a1 - ftail 421 | |a2 - face 422 | |a3 - f 423 | |a4 - tv 424 | |a5 - p 425 | |a6 - v 426 | |a7 - pool 427 | RenderF: 428 | movem.l d2-d7/a2-a6,-(a7) 429 | move.l #RenderF_ret_from_fmap,fmap_LINK_REGISTER 430 | move.l a7,RenderF_save_a7 431 | move.l RDataPool_top,a7 432 | lea RenderF_qhead-RFACE.next(pc),a1 |point ftail to head pointer 433 | moveq #32-TRender_thr-1,d7 434 | RenderF_q_loop: 435 | move.l #sort_q2+TRender_thr*4,a2 436 | move.l (a2,d7.w*4),a2 437 | tst.l a2 438 | beq.s RenderF_q_empty 439 | move.w RenderF_dith+TRender_thr*2(pc,d7.w*2),d4 440 | RenderF_f_loop: 441 | move.l (a7)+,a3 442 | move.w TFACE.flags(a2),d0 443 | swap d0 444 | move.w TFACE.avg_c(a2),d0 445 | or.w d4,d0 446 | move.l d0,RFACE.flagsH(a3) 447 | move.l a3,a0 | vlast=(RVERTEX*)f 448 | lea TFACE.vertexes(a2),a4 | tv=face->vertexes 449 | move.l (a4)+,a5 | 450 | RenderF_v_loop: 451 | move.l (a7)+,a6 | alloc RVERTEX 452 | move.l FPXYZ.z(a5),RVERTEX.z(a6) | copy z, flags 453 | move.l FPXYZ.x(a5),RVERTEX.x(a6) | copy x, y 454 | move.l FPXYZ.sx(a5),RVERTEX.sx(a6) | copy sx, sy 455 | | move.l (a4)+,RVERTEX.U(a6) | copy U,V 456 | addq.l #4,a4 | skip U,V 457 | move.l a6,RVERTEX.vn(a0) | vlast->next=v 458 | move.l a6,a0 | vlast = v 459 | move.l (a4)+,a5 | while((p=tv->p)!=NULL) 460 | tst.l a5 461 | bne.s RenderF_v_loop 462 | clr.l RVERTEX.vn(a0) | vlast->next=NULL 463 | move.l RFACE.vertex(a3),a6 464 | move.l a0,RVERTEX.vp(a6) | f->vertex->prev=vlast 465 | | add rface to queue 466 | move.l a3,RFACE.next(a1) | ftail->next=f 467 | move.l a3,a1 | ftail=f 468 | | Test output queue overflow 469 | cmp.l #R_DATA_THR_faces,a7 470 | bcc.s RenderF_X 471 | | 472 | 2: 473 | move.l TFACE.next(a2),a2 474 | tst.l a2 475 | bne.s RenderF_f_loop 476 | RenderF_q_empty: 477 | dbra d7,RenderF_q_loop 478 | | Complete, run cleanup 479 | clr.l RFACE.next(a1) |ftail->next=NULL 480 | Profile 24,d0 481 | move.l #RenderF_ret_from_fmap2,fmap_LINK_REGISTER 482 | move.l RenderF_qhead(pc),a0 483 | tst.l a0 484 | bne.w fmap 485 | RenderF_ret_from_fmap2: 486 | move.l a7,RDataPool_top 487 | move.l RenderF_save_a7,a7 488 | movem.l (a7)+,d2-d7/a2-a6 489 | rts 490 | | 491 | RenderF_X: 492 | clr.l RFACE.next(a1) |ftail->next=NULL 493 | movem.l d4/d7/a2,RenderF_regsave 494 | move.l RenderF_qhead(pc),a0 495 | tst.l a0 496 | bne.w fmap 497 | RenderF_ret_from_fmap: 498 | Profile 9,d0 499 | movem.l RenderF_regsave(pc),d4/d7/a2 500 | lea RenderF_qhead-RFACE.next(pc),a1 |point ftail to head pointer 501 | bra.w 2b 502 | | 503 | .align 4 504 | RenderF_regsave: 505 | ds.l 3 506 | RenderF_save_a7: 507 | ds.l 1 508 | RenderF_dith: 509 | dc.w 0x0000,0x0000,0x0000,0x0000 | 0...3 510 | dc.w 0x0000,0x0000,0x0000,0x0000 | 4...7 511 | dc.w 0x0000,0x0000,0x0000,0x0000 | 8...11 512 | dc.w 0x0100,0x0100,0x0100,0x0100 | 12...15 513 | dc.w 0x0200,0x0200,0x0200,0x0200 | 16...19 514 | dc.w 0x0300,0x0300,0x0300,0x0300 | 20...23 515 | dc.w 0x0300,0x0300,0x0300,0x0300 | 24...27 516 | dc.w 0x0300,0x0300,0x0300,0x0300 | 28...31 517 | -------------------------------------------------------------------------------- /SDDDE/asm/navigate.s: -------------------------------------------------------------------------------- 1 | .include "render.s" 2 | 3 | .text 4 | .align 4 5 | .globl SD2leaf 6 | .type SD2leaf, @function 7 | | 8 | | d0 - X 9 | | d1 - Y 10 | | d2 - Z 11 | | a0 - kd_tree 12 | | a1 - collision_index 13 | SD2leaf: 14 | move.w #0x800,0xDFF180 15 | movem.l d0-d6/a2-a6,-(a7) 16 | move.l a1,a2 17 | jsr FindKDtreeNode_asm 18 | sub.l a1,a0 | node-base 19 | add.l a0,a2 20 | move.l (a2),a6 21 | moveq #-1,d7 22 | move.l (a6)+,a0 23 | tst.l a0 24 | beq.w SD2leaf_end 25 | | a0 - TFACE *f 26 | SD2leaf_face_loop: 27 | | a3,a4,a5 - CamX...CamZ 28 | movem.l (a7),a3-a5 | load CamX, CamY, CamZ from stack 29 | | a1 - TVERTEX *v 30 | | a2 = FPXYZ *p 31 | lea TFACE.vertexes(a0),a1 32 | | lea ([a0],TFACE.vertexes),a1 33 | move.l (a1),a2 | p = v->p; 34 | | a3,a4,a5 - xp,yp,zp 35 | addq.l #FPXYZ.X,a2 36 | | xp = X - p->X; 37 | sub.l (a2)+,a3 38 | | yp = Y - p->Y; 39 | sub.l (a2)+,a4 40 | | zp = Z - p->Z; 41 | sub.l (a2),a5 42 | | 43 | | Test distance to face 44 | | 45 | movem.l TFACE.flags(a0),d0/d1 |d0=...A14 d1=B14C14 46 | move.l a3,d4 47 | muls.w d0,d4 48 | move.l a5,d0 49 | muls.w d1,d0 50 | add.l d0,d4 51 | swap d1 52 | move.l a4,d0 53 | muls.w d1,d0 54 | add.l d0,d4 55 | bmi.w SDIleaf_next_face 56 | moveq #15,d3 57 | lsr.l d3,d4 58 | cmp.w #256/2+64,d4 | MIN_D_WALK * 2 59 | bcc.w SDIleaf_next_face 60 | move.l d4,-(a7) 61 | | 62 | | d4,d5,d6 - xa, ya, za 63 | | 64 | SD2leaf_vertex_loop: 65 | movem.l -8(a2),d4-d6 | xa = p->X; ya = p->Y; za = p->Z; 66 | addq.l #TVERTEXsz,a1 | v++; 67 | move.l (a1),a2 | p = v->p; 68 | tst.l a2 | if (!p) 69 | bne.s 1f | { 70 | lea TFACE.vertexes(a0),a1 | v = f->vertexes; 71 | move.l (a1),a2 | p = v->p; 72 | sub.l a1,a1 | v = NULL; 73 | 1: | } 74 | addq.l #FPXYZ.X,a2 75 | sub.l (a2)+,d4 | xa -= p->X; 76 | add.l d4,a3 | xp+=xa 77 | sub.l (a2)+,d5 | ya -= p->Y; 78 | add.l d5,a4 | yp+=ya 79 | sub.l (a2),d6 | za -= p->Z; 80 | add.l d6,a5 | zp+=za 81 | | x = MUL(ya, f->C14) - MUL(za, f->B14); 82 | | y = MUL(za, f->A14) - MUL(xa, f->C14); 83 | | z = MUL(xa, f->B14) - MUL(ya, f->A14); 84 | movem.l TFACE.flags(a0),d0/d3 |d0=...A14 d3=B14C14 85 | move.w d0,d1 86 | muls.w d6,d1 |d1=za*A14 87 | muls.w d5,d0 |d0=ya*A14 88 | move.w d3,d2 89 | muls.w d4,d2 |d2=xa*C14 90 | sub.l d2,d1 |d1=y 91 | swap d3 92 | move.w d3,d2 93 | muls.w d4,d2 |d2=xa*B14 94 | sub.l d0,d2 |d2=z 95 | move.w d3,d0 96 | muls.w d6,d0 |d0=za*B14 97 | swap d3 98 | muls.w d5,d3 |d3=ya*C14 99 | sub.l d0,d3 |d3=x 100 | swap d1 101 | swap d2 102 | swap d3 103 | | if ((x * xp + y * yp + z * zp) >= 0) 104 | move.l a4,d0 105 | muls.w d0,d1 106 | move.l a5,d0 107 | muls.w d0,d2 108 | move.l a3,d0 109 | muls.w d0,d3 110 | add.l d3,d1 111 | add.l d2,d1 112 | bpl.s 2f | next vertex 113 | | Test distance to edge 114 | moveq #15,d3 115 | | w = xa * xa + ya * ya + za * za; 116 | move.l d4,d0 117 | muls.w d0,d0 118 | move.l d5,d1 119 | muls.w d1,d1 120 | move.l d6,d2 121 | muls.w d2,d2 122 | add.l d1,d0 123 | add.l d2,d0 124 | | w >>= 15; 125 | lsr.l d3,d0 126 | | if (!w) continue; 127 | beq.s 1f | w!=0 always if correct mesh (no points with distance==0) 128 | | h = xp * xa + yp * ya + zp * za; 129 | move.l a3,d1 130 | muls.w d4,d1 131 | move.l a4,d2 132 | muls.w d5,d2 133 | add.l d2,d1 134 | move.l a5,d2 135 | muls.w d6,d2 136 | add.l d2,d1 137 | | if (h<0) h=0 138 | bpl.s 4f 139 | moveq #0,d1 140 | 4: 141 | | h /= w; 142 | divu.w d0,d1 143 | | if (h <= 0x7FFF) { 144 | bvs.s 1f | overflow mean h>0xFFFF 145 | bmi.s 1f | minus mean h>0x7FFF 146 | | xa = (xa*h)>>15; 147 | | ya = (ya*h)>>15; 148 | | za = (za*h)>>15; 149 | muls.w d1,d4 150 | muls.w d1,d5 151 | muls.w d1,d6 152 | asr.l d3,d4 153 | asr.l d3,d5 154 | asr.l d3,d6 | } 155 | 1: 156 | sub.l a3,d4 | xa-=xp 157 | sub.l a4,d5 | ya-=yp 158 | sub.l a5,d6 | za-=yp 159 | | h = xa * xa + ya * ya + za * za; 160 | muls.w d4,d4 161 | muls.w d5,d5 162 | muls.w d6,d6 163 | add.l d5,d4 164 | add.l d6,d4 165 | | if (h < dmin) dmin = h; 166 | bra.s 3f 167 | | next vertex 168 | 2: 169 | | } while (v); 170 | tst.l a1 171 | bne.w SD2leaf_vertex_loop 172 | move.l (a7),d4 173 | muls.w d4,d4 174 | 3: 175 | cmp.l d4,d7 176 | bcs.s 1f 177 | move.l d4,d7 178 | 1: 179 | addq.l #4,a7 180 | SDIleaf_next_face: 181 | move.l (a6)+,a0 182 | tst.l a0 183 | bne.w SD2leaf_face_loop 184 | SD2leaf_end: 185 | movem.l (a7)+,d0-d6/a2-a6 186 | move.w #0x000,0xDFF180 187 | rts 188 | 189 | 190 | .align 4 191 | .globl TestPlayerMove_asm 192 | .type TestPlayerMove_asm, @function 193 | TestPlayerMove_asm: 194 | movem.l d3-d6,-(a7) 195 | | Rotate dx,dy,dz 196 | movem.w CAMERA.RMTX+0*6(a2),d3-d5 197 | muls.w d0,d3 198 | muls.w d1,d4 199 | muls.w d2,d5 200 | add.l d4,d3 201 | add.l d5,d3 202 | movem.w CAMERA.RMTX+1*6(a2),d4-d6 203 | muls.w d0,d4 204 | muls.w d1,d5 205 | muls.w d2,d6 206 | add.l d5,d4 207 | add.l d6,d4 208 | movem.w CAMERA.RMTX+2*6(a2),d5-d7 209 | muls.w d0,d5 210 | muls.w d1,d6 211 | muls.w d2,d7 212 | add.l d6,d5 213 | add.l d7,d5 214 | | 215 | bfexts d3{2:16},d0 216 | bfexts d4{2:16},d1 217 | bfexts d5{2:16},d2 218 | add.l d0,d0 219 | add.l d1,d1 220 | add.l d2,d2 221 | | Compute X,Y,Z 222 | add.l CAMERA.X(a2),d0 223 | add.l CAMERA.Y(a2),d1 224 | add.l CAMERA.Z(a2),d2 225 | bsr.w SD2leaf 226 | movem.l (a7)+,d3-d6 227 | rts 228 | -------------------------------------------------------------------------------- /SDDDE/asm/render_utils.s: -------------------------------------------------------------------------------- 1 | .include "render.s" 2 | 3 | .text 4 | .align 4 5 | .globl ClearChunkyScreen 6 | .type ClearChunkyScreen, @function 7 | ClearChunkyScreen: 8 | move.l 4(a7),a0 9 | move.w #16000/4-1,d0 10 | move.l #0x3C3C3C3C,d1 | R=1 G=1 B=2 11 | 1: 12 | move.l d1,(a0)+ 13 | dbra d0,1b 14 | rts 15 | 16 | .align 4 17 | .globl ZeroChunkyScreen 18 | .type ZeroChunkyScreen, @function 19 | ZeroChunkyScreen: 20 | move.l 4(a7),a0 21 | movem.l d0-d7/a2-a6,-(a7) 22 | moveq.l #40,d0 23 | move.w #16000/40-1,d1 24 | moveq.l #0,d2 25 | moveq.l #0,d3 26 | moveq.l #0,d4 27 | moveq.l #0,d5 28 | moveq.l #0,d6 29 | moveq.l #0,d7 30 | move.l d7,a2 31 | move.l d7,a3 32 | move.l d7,a4 33 | move.l d7,a5 34 | 1: 35 | movem.l d2-d7/a2-a5,(a0) 36 | add.l d0,a0 37 | dbra d1,1b 38 | movem.l (a7)+,d0-d7/a2-a6 39 | rts 40 | 41 | .align 4 42 | .globl CopyChunkFromC2P 43 | .type CopyChunkFromC2P, @function 44 | CopyChunkFromC2P: 45 | movem.l d0-d7/a2-a6,-(a7) 46 | moveq #40,d0 47 | move.w #4*100-1,d1 48 | 1: 49 | movem.l (a1)+,d2-d7/a2-a5 50 | movem.l d2-d7/a2-a5,(a0) 51 | add.l d0,a0 52 | dbra d1,1b 53 | movem.l (a7)+,d0-d7/a2-a6 54 | rts 55 | 56 | .align 4 57 | .globl XtabCorrect_ys 58 | .type XtabCorrect_ys, @function 59 | XtabCorrect_ys: 60 | sub.w #30*2,a0 61 | rts 62 | 63 | .align 4 64 | .globl RICOUNTER 65 | .type RICOUNTER, @function 66 | RICOUNTER: 67 | move.l #0xbfd800,a0 68 | move.b 0x200(a0),d0 69 | swap d0 70 | move.b 0x100(a0),d0 71 | lsl.w #8,d0 72 | move.b (a0),d0 73 | lsl.l #8,d0 74 | rts 75 | 76 | .align 4 77 | .globl PrepareSortFaces 78 | .type PrepareSortFaces, @function 79 | PrepareSortFaces: 80 | lea sort_q1(pc),a0 81 | lea sort_q2(pc),a1 82 | moveq #32-1,d0 83 | moveq #0,d1 84 | 1: 85 | move.l d1,(a0)+ 86 | move.l d1,(a1)+ 87 | dbra d0,1b 88 | rts 89 | 90 | .align 4 91 | .globl RotateMTXasm 92 | .type RotateMTXasm, @function 93 | RotateMTXasm: 94 | |A0 - RM 95 | |D0 - YAW 96 | |D1 - PITCH 97 | |D2 - ROLL 98 | |D3 - t0 99 | |D4 - t1 100 | |A1 - t2 101 | |D5,D6 - scratch 102 | |D7 - counter 103 | moveq.l #1,d7 104 | move.l #0x8000,a2 105 | RotateMTXloop: 106 | movem.w (a0),d3-d4/a1 107 | | RM[0] = t0 + FNORM(FMUL(t1,ROLL) - FMUL(t2,YAW)); 108 | move.w d4,d5 109 | muls.w d2,d5 110 | move.w a1,d6 111 | muls.w d0,d6 112 | sub.l d6,d5 113 | add.l d5,d5 114 | add.l a2,d5 115 | swap d5 116 | add.w d3,d5 117 | move.w d5,(a0)+ 118 | | RM[1] = t1 - FNORM(FMUL(t0,ROLL) + FMUL(t2,PITCH)); 119 | move.w d3,d5 120 | muls.w d2,d5 121 | move.w a1,d6 122 | muls.w d1,d6 123 | add.l d6,d5 124 | add.l d5,d5 125 | add.l a2,d5 126 | swap d5 127 | move.w d4,d6 |save t1 128 | sub.w d5,d4 129 | move.w d4,(a0)+ 130 | | RM[2] = t2 + FNORM(FMUL(t0,YAW) + FMUL(t1,PITCH)); 131 | muls.w d0,d3 132 | muls.w d1,d6 133 | add.l d3,d6 134 | add.l d6,d6 135 | add.l a2,d6 136 | swap d6 137 | add.w a1,d6 138 | move.w d6,(a0)+ 139 | dbra d7,RotateMTXloop 140 | rts 141 | | 142 | .align 4 143 | .globl NormalizeMTXasm 144 | .type NormalizeMTXasm, @function 145 | NormalizeMTXasm: 146 | |A0 - RM 147 | |D0 - RM[0] 148 | |D1 - RM[1] 149 | |D2 - RM[2] 150 | |D3 - RM[3] 151 | |D4 - RM[4] 152 | |D5 - RM[5] 153 | |D6 - scratch 154 | |D7 - scratch 155 | |A1 - scratch 156 | move.l #0x8000,a2 157 | move.l #0x2000,a3 158 | movem.w (a0),d0-d5 159 | | r = RM[0] * RM[3] + RM[1] * RM[4] + RM[2] * RM[5]; 160 | move.w d0,d6 161 | muls.w d3,d6 162 | move.w d1,d7 163 | muls.w d4,d7 164 | add.l d7,d6 165 | move.w d2,d7 166 | muls.w d5,d7 167 | add.l d7,d6 168 | | r = -r; 169 | neg.l d6 170 | | r>>=15; 171 | add.l d6,d6 172 | add.l a2,d6 173 | swap d6 |d6=r 174 | moveq #14,d7 175 | | RM[0] += RM[3] * r >> 14; 176 | | RM[3] += RM[0] * r >> 14; 177 | move.w d0,a1 178 | muls.w d6,d0 179 | add.l a3,d0 180 | asr.l d7,d0 181 | add.w d3,d0 182 | muls.w d6,d3 183 | add.l a3,d3 184 | asr.l d7,d3 185 | add.w a1,d3 | Now d0 - RM[3], d3 - RM[0] 186 | | RM[1] += RM[4] * r >> 14; 187 | | RM[4] += RM[1] * r >> 14; 188 | move.w d1,a1 189 | muls.w d6,d1 190 | add.l a3,d1 191 | asr.l d7,d1 192 | add.w d4,d1 193 | muls.w d6,d4 194 | add.l a3,d4 195 | asr.l d7,d4 196 | add.w a1,d4 | Now d1 - RM[4], d4 - RM[1] 197 | | RM[2] += RM[5] * r >> 14; 198 | | RM[5] += RM[2] * r >> 14; 199 | move.w d2,a1 200 | muls.w d6,d2 201 | add.l a3,d2 202 | asr.l d7,d2 203 | add.w d5,d2 204 | muls.w d6,d5 205 | add.l a3,d5 206 | asr.l d7,d5 207 | add.w a1,d5 | Now d2 - RM[5], d5 - RM[2] 208 | |D0 - RM[3] 209 | |D1 - RM[4] 210 | |D2 - RM[5] 211 | |D3 - RM[0] 212 | |D4 - RM[1] 213 | |D5 - RM[2] 214 | | r = RM[0] * RM[0] + RM[1] * RM[1] + RM[2] * RM[2]; 215 | move.w d3,d6 216 | muls.w d3,d6 217 | move.w d4,d7 218 | muls.w d4,d7 219 | add.l d7,d6 220 | move.w d5,d7 221 | muls.w d5,d7 222 | add.l d7,d6 223 | | r>>=14; 224 | | r = 16384 * 3 / 2 - r / 2; 225 | add.l d6,d6 226 | add.l a2,d6 227 | swap d6 228 | move.w #16384*3/2,d7 229 | sub.w d6,d7 230 | moveq #14,d6 231 | | RM[0] = RM[0] * r >> 14; 232 | muls.w d7,d3 233 | add.l a3,d3 234 | asr.l d6,d3 235 | move.w d3,(a0)+ 236 | | RM[1] = RM[1] * r >> 14; 237 | muls.w d7,d4 238 | add.l a3,d4 239 | asr.l d6,d4 240 | move.w d4,(a0)+ 241 | | RM[2] = RM[2] * r >> 14; 242 | muls.w d7,d5 243 | add.l a3,d5 244 | asr.l d6,d5 245 | move.w d5,(a0)+ 246 | | r = RM[3] * RM[3] + RM[4] * RM[4] + RM[5] * RM[5]; 247 | move.w d0,d6 248 | muls.w d0,d6 249 | move.w d1,d7 250 | muls.w d1,d7 251 | add.l d7,d6 252 | move.w d2,d7 253 | muls.w d2,d7 254 | add.l d7,d6 255 | | r>>=14; 256 | | r = 16384 * 3 / 2 - r / 2; 257 | add.l d6,d6 258 | add.l a2,d6 259 | swap d6 260 | move.w #16384*3/2,d7 261 | sub.w d6,d7 262 | moveq #14,d6 263 | | RM[3] = RM[3] * r >> 14; 264 | muls.w d7,d0 265 | add.l a3,d0 266 | asr.l d6,d0 267 | move.w d0,(a0)+ 268 | | RM[4] = RM[4] * r >> 14; 269 | muls.w d7,d1 270 | add.l a3,d1 271 | asr.l d6,d1 272 | move.w d1,(a0)+ 273 | | RM[5] = RM[5] * r >> 14; 274 | muls.w d7,d2 275 | add.l a3,d2 276 | asr.l d6,d2 277 | move.w d2,(a0)+ 278 | | RM[6] = (RM[1] * RM[5] - RM[2] * RM[4]) >> 14; 279 | move.w d4,d6 280 | muls.w d2,d6 281 | move.w d5,d7 282 | muls.w d1,d7 283 | sub.l d7,d6 284 | moveq #14,d7 285 | add.l a3,d6 286 | asr.l d7,d6 287 | move.w d6,(a0)+ 288 | | RM[7] = (RM[2] * RM[3] - RM[0] * RM[5]) >> 14; 289 | move.w d5,d6 290 | muls.w d0,d6 291 | move.w d3,d7 292 | muls.w d2,d7 293 | sub.l d7,d6 294 | moveq #14,d7 295 | add.l a3,d6 296 | asr.l d7,d6 297 | move.w d6,(a0)+ 298 | | RM[8] = (RM[0] * RM[4] - RM[1] * RM[3]) >> 14; 299 | muls.w d1,d3 300 | muls.w d0,d4 301 | sub.l d4,d3 302 | add.l a3,d3 303 | asr.l d7,d3 304 | move.w d3,(a0)+ 305 | rts 306 | 307 | .align 4 308 | .globl ConstructBMATRIX_asm 309 | .type ConstructBMATRIX_asm, @function 310 | BMD_VAL = 1048576/3 311 | 312 | |D0 - scratch 313 | |D1 - coord 314 | |D2:D3 - X and dX 315 | |D5:D4 - Y and dY 316 | |D7:D6 - Z and dZ 317 | |A0 - *D 318 | |A1 - *matrix 319 | |A2 - *camera_pos 320 | |A3 - scratch 321 | |A4 - counter 322 | bm_sz_bits = 4 323 | ConstructBMATRIX_asm: 324 | lea (a0,12*(128-(1<> 1; 333 | move.l d3,d2 334 | asr.l #1,d2 335 | | X -= dX << 7; 336 | move.l d3,d0 337 | lsl.l #bm_sz_bits,d0 338 | sub.l d0,d2 339 | | X -= (dX * cc[j]) >> 9; 340 | move.l d3,d0 341 | muls.w d1,d0 342 | asr.l #2,d0 343 | asr.l #8,d0 344 | sub.l d0,d2 345 | | Y 346 | move.w 4(a1),d5 347 | muls.w #410,d5 348 | asr.l #8,d5 349 | move.l d5,d4 350 | asr.l #1,d4 351 | move.l d5,d0 352 | lsl.l #bm_sz_bits,d0 353 | sub.l d0,d4 354 | move.l d5,d0 355 | muls.w d1,d0 356 | asr.l #2,d0 357 | asr.l #8,d0 358 | sub.l d0,d4 359 | | Z 360 | move.w 10(a1),a3 361 | move.l a3,d7 362 | move.l d7,d6 363 | asr.l #1,d6 364 | move.l d7,d0 365 | lsl.l #bm_sz_bits,d0 366 | sub.l d0,d6 367 | muls.w d7,d1 368 | asr.l #2,d1 369 | asr.l #8,d1 370 | sub.l d1,d6 371 | add.l #14189 / 3,d6 372 | | 373 | move.w #(2<=MIN_Z8 724 | moveq #0,d2 |z=0 725 | moveq #1,d3 |flag=XYZF_SCOORD_NOT_VALID 726 | min_z8_ok: 727 | move.w d0,FPXYZ.x(a0) 728 | move.l #_LOGtab+32768,a1 729 | move.l #EXPtab+65536,a2 730 | move.w d1,FPXYZ.y(a0) 731 | move.w (a1,d2.w*2),d2 |log(z) 732 | move.l d7,FPXYZ.seq(a0) | update seq 733 | move.w (a1,d0.w*2),d0 |log(x) 734 | beq.s no_clip_xz |log(x)==0 735 | sub.w d2,d0 736 | bcs.s no_clip_xz |log(x)bbbb 830 | cmp.l d4,d1 | llllbbbb - LLLLBBBB, BBBB<=bbbb 831 | bcs.s skip_face | exit if LLLL>llll 832 | cmp.w d2,d5 | TTTT-tttt 833 | bcs.s skip_face | exit if TTTT=tttt 835 | bcs.s skip_face | exit if RRRR 2 | 3 | const UBYTE font[2048]= 4 | { 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 10 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 11 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 13 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 22 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00, 39 | 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 40 | 0x00, 0x24, 0x7E, 0x24, 0x24, 0x7E, 0x24, 0x00, 41 | 0x00, 0x18, 0x3E, 0x58, 0x3C, 0x1A, 0x7C, 0x18, 42 | 0x00, 0x62, 0x64, 0x08, 0x10, 0x26, 0x46, 0x00, 43 | 0x00, 0x10, 0x28, 0x10, 0x2A, 0x66, 0x3A, 0x00, 44 | 0x00, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x00, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x00, 46 | 0x00, 0x30, 0x18, 0x18, 0x18, 0x18, 0x30, 0x00, 47 | 0x00, 0x00, 0x24, 0x18, 0x7E, 0x18, 0x24, 0x00, 48 | 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 50 | 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 52 | 0x00, 0x00, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x00, 53 | 0x00, 0x3C, 0x66, 0x6E, 0x76, 0x66, 0x3C, 0x00, 54 | 0x00, 0x18, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, 55 | 0x00, 0x3C, 0x66, 0x06, 0x3C, 0x60, 0x7E, 0x00, 56 | 0x00, 0x3C, 0x66, 0x0C, 0x06, 0x66, 0x3C, 0x00, 57 | 0x00, 0x0C, 0x1C, 0x2C, 0x4C, 0x7E, 0x0C, 0x00, 58 | 0x00, 0x7E, 0x60, 0x7C, 0x06, 0x66, 0x3C, 0x00, 59 | 0x00, 0x3C, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0x00, 60 | 0x00, 0x7E, 0x66, 0x0C, 0x18, 0x18, 0x18, 0x00, 61 | 0x00, 0x3C, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0x00, 62 | 0x00, 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x3C, 0x00, 63 | 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 64 | 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x30, 65 | 0x00, 0x00, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x00, 66 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x3E, 0x00, 0x00, 67 | 0x00, 0x00, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x00, 68 | 0x00, 0x3C, 0x66, 0x0C, 0x18, 0x00, 0x18, 0x00, 69 | 0x00, 0x3C, 0x4A, 0x56, 0x5E, 0x40, 0x3C, 0x00, 70 | 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00, 71 | 0x00, 0x7C, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00, 72 | 0x00, 0x3C, 0x66, 0x60, 0x60, 0x66, 0x3C, 0x00, 73 | 0x00, 0x78, 0x6C, 0x66, 0x66, 0x6C, 0x78, 0x00, 74 | 0x00, 0x7E, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00, 75 | 0x00, 0x7E, 0x60, 0x7C, 0x60, 0x60, 0x60, 0x00, 76 | 0x00, 0x3C, 0x66, 0x60, 0x6E, 0x66, 0x3C, 0x00, 77 | 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 78 | 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00, 79 | 0x00, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00, 80 | 0x00, 0x66, 0x6C, 0x78, 0x78, 0x6C, 0x66, 0x00, 81 | 0x00, 0x60, 0x60, 0x60, 0x60, 0x66, 0x7E, 0x00, 82 | 0x00, 0x42, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x00, 83 | 0x00, 0x46, 0x66, 0x76, 0x6E, 0x66, 0x62, 0x00, 84 | 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 85 | 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x00, 86 | 0x00, 0x3C, 0x66, 0x66, 0x76, 0x6E, 0x3C, 0x04, 87 | 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0x00, 88 | 0x00, 0x3C, 0x60, 0x3C, 0x06, 0x66, 0x3C, 0x00, 89 | 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 90 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 91 | 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, 92 | 0x00, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x24, 0x00, 93 | 0x00, 0x66, 0x3C, 0x18, 0x18, 0x3C, 0x66, 0x00, 94 | 0x00, 0x42, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, 95 | 0x00, 0x7E, 0x4E, 0x1C, 0x38, 0x72, 0x7E, 0x00, 96 | 0x00, 0x1E, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00, 97 | 0x00, 0x00, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x00, 98 | 0x00, 0x78, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, 99 | 0x00, 0x18, 0x3C, 0x5A, 0x18, 0x18, 0x18, 0x00, 100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 101 | 0x00, 0x1C, 0x36, 0x30, 0x78, 0x30, 0x7E, 0x00, 102 | 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E, 0x00, 103 | 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 104 | 0x00, 0x00, 0x3C, 0x64, 0x60, 0x64, 0x3C, 0x00, 105 | 0x00, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3E, 0x00, 106 | 0x00, 0x00, 0x3C, 0x66, 0x7C, 0x60, 0x3E, 0x00, 107 | 0x00, 0x1C, 0x30, 0x38, 0x30, 0x30, 0x30, 0x00, 108 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x3C, 109 | 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x66, 0x00, 110 | 0x00, 0x18, 0x00, 0x38, 0x18, 0x18, 0x3C, 0x00, 111 | 0x00, 0x0C, 0x00, 0x0C, 0x0C, 0x0C, 0x2C, 0x18, 112 | 0x00, 0x60, 0x6C, 0x78, 0x78, 0x6C, 0x66, 0x00, 113 | 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0x1C, 0x00, 114 | 0x00, 0x00, 0x74, 0x7E, 0x6A, 0x6A, 0x6A, 0x00, 115 | 0x00, 0x00, 0x78, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 116 | 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, 117 | 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 118 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x06, 0x07, 119 | 0x00, 0x00, 0x1C, 0x30, 0x30, 0x30, 0x30, 0x00, 120 | 0x00, 0x00, 0x38, 0x60, 0x38, 0x0C, 0x78, 0x00, 121 | 0x00, 0x18, 0x3C, 0x18, 0x18, 0x18, 0x0C, 0x00, 122 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 123 | 0x00, 0x00, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x00, 124 | 0x00, 0x00, 0x66, 0x66, 0x7E, 0x7E, 0x24, 0x00, 125 | 0x00, 0x00, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x00, 126 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x3C, 127 | 0x00, 0x00, 0x7E, 0x4C, 0x18, 0x32, 0x7E, 0x00, 128 | 0x00, 0x1E, 0x18, 0x30, 0x18, 0x18, 0x1E, 0x00, 129 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 130 | 0x00, 0x78, 0x18, 0x0C, 0x18, 0x18, 0x78, 0x00, 131 | 0x00, 0x26, 0x7C, 0x48, 0x00, 0x00, 0x00, 0x00, 132 | 0x3C, 0x42, 0x9D, 0xB1, 0xB1, 0x9D, 0x42, 0x3C, 133 | 0x00, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00, 134 | 0x00, 0x7E, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 135 | 0x00, 0x7C, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00, 136 | 0x00, 0x7E, 0x66, 0x60, 0x60, 0x60, 0x60, 0x00, 137 | 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0xFF, 0xC3, 138 | 0x00, 0x7E, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00, 139 | 0x00, 0xDB, 0x5A, 0x3C, 0x3C, 0x5A, 0xDB, 0x00, 140 | 0x00, 0x3C, 0x66, 0x0C, 0x06, 0x66, 0x3C, 0x00, 141 | 0x00, 0x62, 0x66, 0x6E, 0x76, 0x66, 0x46, 0x00, 142 | 0x08, 0x6A, 0x66, 0x6E, 0x76, 0x66, 0x46, 0x00, 143 | 0x00, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x66, 0x00, 144 | 0x00, 0x3E, 0x66, 0x66, 0x66, 0x66, 0xC6, 0x00, 145 | 0x00, 0x42, 0x66, 0x7E, 0x7E, 0x66, 0x66, 0x00, 146 | 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, 147 | 0x00, 0x3C, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, 148 | 0x00, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 149 | 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x00, 150 | 0x00, 0x3C, 0x66, 0x60, 0x60, 0x66, 0x3C, 0x00, 151 | 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 152 | 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x3C, 0x00, 153 | 0x00, 0x7E, 0xDB, 0xDB, 0xDB, 0x7E, 0x18, 0x00, 154 | 0x00, 0x66, 0x7E, 0x18, 0x18, 0x7E, 0x66, 0x00, 155 | 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFE, 0x06, 156 | 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x00, 157 | 0x00, 0xC6, 0xD6, 0xD6, 0xD6, 0xD6, 0xFE, 0x00, 158 | 0x00, 0xC6, 0xD6, 0xD6, 0xD6, 0xD6, 0xFF, 0x01, 159 | 0x00, 0xE0, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 160 | 0x00, 0xC6, 0xC6, 0xF6, 0xDA, 0xDA, 0xF6, 0x00, 161 | 0x00, 0x60, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 162 | 0x00, 0x3C, 0x66, 0x1E, 0x06, 0x66, 0x3C, 0x00, 163 | 0x00, 0xDC, 0xB6, 0xF6, 0xB6, 0xB6, 0xDC, 0x00, 164 | 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x00, 165 | 0x00, 0x00, 0x3C, 0x06, 0x3E, 0x66, 0x3E, 0x00, 166 | 0x00, 0x00, 0x7C, 0x60, 0x7C, 0x66, 0x7C, 0x00, 167 | 0x00, 0x00, 0x7C, 0x66, 0x7C, 0x66, 0x7C, 0x00, 168 | 0x00, 0x00, 0x7C, 0x64, 0x60, 0x60, 0x60, 0x00, 169 | 0x00, 0x00, 0x3C, 0x6C, 0x6C, 0x6C, 0xFE, 0x82, 170 | 0x00, 0x00, 0x3C, 0x66, 0x7E, 0x60, 0x3E, 0x00, 171 | 0x00, 0x00, 0xDB, 0x5A, 0x3C, 0x5A, 0xDB, 0x00, 172 | 0x00, 0x00, 0x3C, 0x66, 0x0C, 0x66, 0x3C, 0x00, 173 | 0x00, 0x00, 0x66, 0x66, 0x6E, 0x76, 0x66, 0x00, 174 | 0x18, 0x10, 0x66, 0x66, 0x6E, 0x76, 0x66, 0x00, 175 | 0x00, 0x00, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x00, 176 | 0x00, 0x00, 0x1E, 0x36, 0x36, 0x36, 0x66, 0x00, 177 | 0x00, 0x00, 0xC6, 0xEE, 0xFE, 0xD6, 0xC6, 0x00, 178 | 0x00, 0x00, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00, 179 | 0x00, 0x00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x00, 180 | 0x00, 0x00, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x00, 181 | 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 182 | 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 183 | 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 0xCC, 0x33, 184 | 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 185 | 0x10, 0x10, 0x10, 0x10, 0xF0, 0x10, 0x10, 0x10, 186 | 0x10, 0x10, 0xF0, 0x10, 0x10, 0xF0, 0x10, 0x10, 187 | 0x24, 0x24, 0x24, 0x24, 0xE4, 0x24, 0x24, 0x24, 188 | 0x00, 0x00, 0x00, 0x00, 0xFC, 0x24, 0x24, 0x24, 189 | 0x00, 0x00, 0xF0, 0x10, 0x10, 0xF0, 0x10, 0x10, 190 | 0x24, 0x24, 0xE4, 0x04, 0x04, 0xE4, 0x24, 0x24, 191 | 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 192 | 0x00, 0x00, 0xFC, 0x04, 0x04, 0xE4, 0x24, 0x24, 193 | 0x24, 0x24, 0xE4, 0x04, 0x04, 0xFC, 0x00, 0x00, 194 | 0x24, 0x24, 0x24, 0x24, 0xFC, 0x00, 0x00, 0x00, 195 | 0x10, 0x10, 0xF0, 0x10, 0x10, 0xF0, 0x00, 0x00, 196 | 0x00, 0x00, 0x00, 0x00, 0xF0, 0x10, 0x10, 0x10, 197 | 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 198 | 0x10, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x00, 0x00, 199 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x10, 0x10, 0x10, 200 | 0x10, 0x10, 0x10, 0x10, 0x1F, 0x10, 0x10, 0x10, 201 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 202 | 0x10, 0x10, 0x10, 0x10, 0xFF, 0x10, 0x10, 0x10, 203 | 0x00, 0x00, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x10, 204 | 0x24, 0x24, 0x24, 0x24, 0x27, 0x24, 0x24, 0x24, 205 | 0x24, 0x24, 0x27, 0x20, 0x20, 0x3F, 0x00, 0x00, 206 | 0x00, 0x00, 0x3F, 0x20, 0x20, 0x27, 0x24, 0x24, 207 | 0x24, 0x24, 0xE7, 0x00, 0x00, 0xFF, 0x00, 0x00, 208 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xE7, 0x24, 0x24, 209 | 0x24, 0x24, 0x27, 0x20, 0x20, 0x27, 0x24, 0x24, 210 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 211 | 0x24, 0x24, 0xE7, 0x00, 0x00, 0xE7, 0x24, 0x24, 212 | 0x10, 0x10, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 213 | 0x24, 0x24, 0x24, 0x24, 0xFF, 0x00, 0x00, 0x00, 214 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x10, 0x10, 215 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0x24, 0x24, 0x24, 216 | 0x24, 0x24, 0x24, 0x24, 0x3F, 0x00, 0x00, 0x00, 217 | 0x10, 0x10, 0x1F, 0x10, 0x10, 0x1F, 0x00, 0x00, 218 | 0x00, 0x00, 0x1F, 0x10, 0x10, 0x1F, 0x10, 0x10, 219 | 0x00, 0x00, 0x00, 0x00, 0x3F, 0x24, 0x24, 0x24, 220 | 0x24, 0x24, 0x24, 0x24, 0xFF, 0x24, 0x24, 0x24, 221 | 0x10, 0x10, 0xFF, 0x10, 0x10, 0xFF, 0x10, 0x10, 222 | 0x10, 0x10, 0x10, 0x10, 0xF0, 0x00, 0x00, 0x00, 223 | 0x00, 0x00, 0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 224 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 225 | 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 226 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 227 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 228 | 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 229 | 0x00, 0x00, 0x7C, 0x66, 0x66, 0x7C, 0x60, 0x00, 230 | 0x00, 0x00, 0x3C, 0x66, 0x60, 0x66, 0x3C, 0x00, 231 | 0x00, 0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, 232 | 0x00, 0x00, 0x66, 0x66, 0x3E, 0x06, 0x3C, 0x00, 233 | 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x18, 0x00, 234 | 0x00, 0x00, 0x66, 0x7E, 0x18, 0x7E, 0x66, 0x00, 235 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x7F, 0x03, 236 | 0x00, 0x00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x00, 237 | 0x00, 0x00, 0xC6, 0xD6, 0xD6, 0xD6, 0xFE, 0x00, 238 | 0x00, 0x00, 0xC6, 0xD6, 0xD6, 0xD6, 0xFF, 0x01, 239 | 0x00, 0x00, 0xE0, 0x7C, 0x66, 0x66, 0x7C, 0x00, 240 | 0x00, 0x00, 0xC6, 0xF6, 0xDA, 0xDA, 0xF6, 0x00, 241 | 0x00, 0x00, 0x60, 0x7C, 0x66, 0x66, 0x7C, 0x00, 242 | 0x00, 0x00, 0x7C, 0x46, 0x1E, 0x46, 0x7C, 0x00, 243 | 0x00, 0x00, 0xDC, 0xB6, 0xF6, 0xB6, 0xDC, 0x00, 244 | 0x00, 0x00, 0x3E, 0x66, 0x66, 0x3E, 0x66, 0x00, 245 | 0x24, 0x7E, 0x60, 0x7C, 0x60, 0x60, 0x7E, 0x00, 246 | 0x00, 0x24, 0x3C, 0x66, 0x7E, 0x60, 0x3E, 0x00, 247 | 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x00, 248 | 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x00, 249 | 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x00, 250 | 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x00, 251 | 0x00, 0x00, 0x08, 0x0C, 0x7E, 0x0C, 0x08, 0x00, 252 | 0x00, 0x00, 0x10, 0x30, 0x7E, 0x30, 0x10, 0x00, 253 | 0x00, 0x10, 0x38, 0x7C, 0x10, 0x10, 0x10, 0x00, 254 | 0x00, 0x10, 0x10, 0x10, 0x7C, 0x38, 0x10, 0x00, 255 | 0x00, 0x00, 0x10, 0x00, 0x7C, 0x00, 0x10, 0x00, 256 | 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x7C, 0x00, 257 | 0x00, 0x9E, 0xDE, 0xF8, 0xF8, 0xD8, 0xD8, 0x00, 258 | 0x00, 0x00, 0x44, 0x38, 0x28, 0x38, 0x44, 0x00, 259 | 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 260 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 261 | }; 262 | -------------------------------------------------------------------------------- /SDDDE/omni/FACES.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/FACES.bin -------------------------------------------------------------------------------- /SDDDE/omni/FPXYZ.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/FPXYZ.bin -------------------------------------------------------------------------------- /SDDDE/omni/cindex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/cindex.bin -------------------------------------------------------------------------------- /SDDDE/omni/clist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/clist.bin -------------------------------------------------------------------------------- /SDDDE/omni/faces_in_leafs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/faces_in_leafs.bin -------------------------------------------------------------------------------- /SDDDE/omni/fil_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/fil_idx.bin -------------------------------------------------------------------------------- /SDDDE/omni/kdtree.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/kdtree.bin -------------------------------------------------------------------------------- /SDDDE/omni/pvs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/pvs.bin -------------------------------------------------------------------------------- /SDDDE/omni/pvs_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/pvs_idx.bin -------------------------------------------------------------------------------- /SDDDE/omni/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/texture.bin -------------------------------------------------------------------------------- /SDDDE/omni/texture.c32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/omni/texture.c32 -------------------------------------------------------------------------------- /SDDDE/render.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDER_H 2 | #define RENDER_H 3 | 4 | #define ALIGN4 __attribute__ ((aligned (16))) 5 | 6 | typedef ULONG UFIXP32; 7 | typedef LONG FIXP32; 8 | typedef USHORT UFIXP16; 9 | typedef SHORT FIXP16; 10 | typedef unsigned long long UFIXP64; 11 | typedef signed long long FIXP64; 12 | 13 | typedef struct 14 | { 15 | FIXP32 X; 16 | FIXP32 Y; 17 | FIXP32 Z; 18 | FIXP16 RMTX[9]; 19 | FIXP16 dummy; 20 | }CAMERA ALIGN4; 21 | 22 | typedef struct 23 | { 24 | SHORT next_index; 25 | UBYTE axis; 26 | BYTE split; 27 | }KDTREE_NODE; 28 | 29 | typedef struct 30 | { 31 | ULONG seq; 32 | FIXP32 X; //World X, 24.8 33 | FIXP32 Y; //World Y, 24.8 34 | FIXP32 Z; //World Z, 24.8 35 | UFIXP16 sx; //Projected and displaced x 8.8 36 | UFIXP16 sy; //Projected and displaced y 8.8 37 | FIXP16 x; //Rotated x, 8.8 38 | FIXP16 y; //Rotated y, 8.8 39 | FIXP16 z; //Rotated z. 8.8 40 | USHORT flags; 41 | }FPXYZ; 42 | 43 | typedef struct 44 | { 45 | FPXYZ* p; 46 | UFIXP16 U; 47 | UFIXP16 V; 48 | }TVERTEX; 49 | 50 | typedef struct TFACE 51 | { 52 | struct TFACE* next; 53 | ULONG seq; 54 | USHORT flags; 55 | //Коэффициенты плоскости, но в формате 2.14 (как матрица поворота, для умножения через таблицу) 56 | FIXP16 A14; 57 | FIXP16 B14; 58 | FIXP16 C14; 59 | FIXP32 MX; //Центр грани 60 | FIXP32 MY; 61 | FIXP32 MZ; 62 | UFIXP16 avg_z; 63 | USHORT avg_color; 64 | ULONG T; //Указатель на текстуру 65 | TVERTEX vertexes[]; //Тут сложены все вертексы 66 | }TFACE; 67 | 68 | typedef struct 69 | { 70 | union 71 | { 72 | ULONG face_id; 73 | TFACE *face; 74 | }; 75 | }KDTREE_FACE_NODE; 76 | 77 | typedef struct 78 | { 79 | BYTE K; 80 | BYTE J; 81 | BYTE I; 82 | BYTE dummy; 83 | ULONG kdtf_offset; 84 | }KDTREE_LEAF_DISK; 85 | 86 | typedef struct 87 | { 88 | FIXP32* I; 89 | FIXP32* J; 90 | FIXP32* K; 91 | KDTREE_FACE_NODE* FaceList; 92 | }KDTREE_LEAF; 93 | 94 | 95 | typedef struct 96 | { 97 | union 98 | { 99 | ULONG face_id; 100 | TFACE *face; 101 | }; 102 | }COLLISION_ITEM; 103 | 104 | typedef struct 105 | { 106 | union 107 | { 108 | ULONG offset; 109 | COLLISION_ITEM *list; 110 | }; 111 | }COLLISION_LEAF; 112 | 113 | 114 | typedef struct RVERTEX 115 | { 116 | struct RVERTEX *next; 117 | struct RVERTEX *prev; 118 | UFIXP16 sx; 119 | UFIXP16 sy; 120 | UFIXP16 U; 121 | UFIXP16 V; 122 | FIXP16 x; 123 | FIXP16 y; 124 | FIXP16 z; 125 | USHORT flags; 126 | }RVERTEX; 127 | 128 | typedef struct RFACE 129 | { 130 | RVERTEX *v; 131 | ULONG T; 132 | ULONG xmax; //Computed by tmap, or used as flags 133 | struct RFACE *next; 134 | }RFACE; 135 | 136 | typedef union 137 | { 138 | RVERTEX v; 139 | RFACE f; 140 | }R_DATA; 141 | 142 | #define R_DATA_TOTAL_SZ (1024) 143 | extern R_DATA* RDataPool[R_DATA_TOTAL_SZ]; 144 | extern R_DATA** RDataPool_top; 145 | 146 | extern ULONG *TRAPEZOIDS_POINTER; 147 | extern ULONG *SLICES_POINTER; 148 | extern ULONG SLICES_BUFFER[]; 149 | extern ULONG TRAPEZOIDS[]; 150 | 151 | extern USHORT _LOGtab[32768]; 152 | extern USHORT EXPtab[65536]; 153 | #define LOGtab (_LOGtab+16384) 154 | #define LOG5_8 (0xF528-2) 155 | 156 | #define MIN_SQR (-0x8000) 157 | #define MAX_SQR (+0x8000) 158 | extern UFIXP16 _SQRtab[MAX_SQR - MIN_SQR]; 159 | #define SQRtab (_SQRtab-MIN_SQR) 160 | #define MUL(A,B) (SQRtab[(A)+(B)]-SQRtab[(A)-(B)]) 161 | 162 | #define MIN_D_WALK (256/2) 163 | 164 | typedef struct 165 | { 166 | USHORT stage; 167 | USHORT scanline; 168 | }PROFILER_DATA; 169 | 170 | typedef struct 171 | { 172 | UBYTE B; 173 | UBYTE G; 174 | UBYTE R; 175 | UBYTE dummy; 176 | }RGBPAL; 177 | 178 | #endif -------------------------------------------------------------------------------- /SDDDE/render.s: -------------------------------------------------------------------------------- 1 | LOG5_8 = (0xF528-2) 2 | YDISP_FP = ((50<<8)) 3 | XDISP_FP = ((80<<8)) 4 | 5 | .extern _LOGtab 6 | .extern EXPtab 7 | | 8 | CAMERA.X = 0 9 | CAMERA.Y = 4 10 | CAMERA.Z = 8 11 | CAMERA.RMTX = 12 12 | | 13 | RVERTEX.vn = 0 14 | RVERTEX.vp = 4 15 | RVERTEX.sx = 8 16 | RVERTEX.sy = 10 17 | RVERTEX.U = 12 18 | RVERTEX.V = 14 19 | RVERTEX.x = 16 20 | RVERTEX.y = 18 21 | RVERTEX.z = 20 22 | RVERTEX.flagH = 22 23 | RVERTEX.flagL = 23 24 | RVERTEX_sz = 24 25 | | 26 | RFACE.vertex = 0 27 | RFACE.T = 4 28 | RFACE.xmax = 8 29 | RFACE.flagsH = 8 30 | RFACE.flagsL = 9 31 | RFACE.next = 12 32 | 33 | .extern ProfilerStartScanline 34 | .extern ProfilerWP 35 | .macro Profile stage,reg 36 | move.w #\stage,([ProfilerWP]) 37 | move.b 0xbfda00,\reg 38 | move.b 0xbfd900,\reg 39 | lsl.w #8,\reg 40 | move.b 0xbfd800,\reg 41 | sub.w ProfilerStartScanline,\reg 42 | move.w \reg,([ProfilerWP],2) 43 | addq.l #4,ProfilerWP 44 | .endm 45 | 46 | TFACE.next = 0 47 | TFACE.seq = 4 48 | TFACE.flags = 8 49 | TFACE.A14 = 10 50 | TFACE.B14 = 12 51 | TFACE.C14 = 14 52 | TFACE.MX = 16 53 | TFACE.MY = 20 54 | TFACE.MZ = 24 55 | TFACE.avg_z = 28 56 | TFACE.avg_c = 30 57 | TFACE.T = 32 58 | TFACE.vertexes = 36 59 | 60 | TVERTEX.p = 0 61 | TVERTEX.U = 4 62 | TVERTEX.V = 6 63 | TVERTEXsz = 8 64 | 65 | FPXYZ.seq = 0 66 | FPXYZ.X = 4 67 | FPXYZ.Y = 8 68 | FPXYZ.Z = 12 69 | FPXYZ.sx = 16 70 | FPXYZ.sy = 18 71 | FPXYZ.x = 20 72 | FPXYZ.y = 22 73 | FPXYZ.z = 24 74 | FPXYZ.flags = 26 75 | 76 | enable_distance_test = 0 77 | enable_backface_test = 1 78 | 79 | enable_trapezoids_round = 0 80 | 81 | .extern RDataPool 82 | R_DATA_THR_faces = RDataPool+670*4 83 | R_DATA_THR_near_faces = RDataPool+105*4 84 | 85 | TRender_thr = 8 86 | 87 | TSL_z_thr = 0x480 | Z threshold for tesselation 88 | 89 | rearrange_tmap_innerloop = 0 90 | 91 | tmap_16bit = 1 92 | -------------------------------------------------------------------------------- /SDDDE/spyro/FACES.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/FACES.bin -------------------------------------------------------------------------------- /SDDDE/spyro/FPXYZ.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/FPXYZ.bin -------------------------------------------------------------------------------- /SDDDE/spyro/cindex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/cindex.bin -------------------------------------------------------------------------------- /SDDDE/spyro/clist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/clist.bin -------------------------------------------------------------------------------- /SDDDE/spyro/faces_in_leafs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/faces_in_leafs.bin -------------------------------------------------------------------------------- /SDDDE/spyro/fil_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/fil_idx.bin -------------------------------------------------------------------------------- /SDDDE/spyro/kdtree.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/kdtree.bin -------------------------------------------------------------------------------- /SDDDE/spyro/pvs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/pvs.bin -------------------------------------------------------------------------------- /SDDDE/spyro/pvs_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/pvs_idx.bin -------------------------------------------------------------------------------- /SDDDE/spyro/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SDDDE/spyro/texture.bin -------------------------------------------------------------------------------- /SDDDE/support/gcc8_a_support.s: -------------------------------------------------------------------------------- 1 | .cfi_sections .debug_frame 2 | .text 3 | .type __mulsi3, function 4 | .globl __mulsi3 5 | __mulsi3: 6 | .cfi_startproc 7 | movew sp@(4), d0 /* x0 -> d0 */ 8 | muluw sp@(10), d0 /* x0*y1 */ 9 | movew sp@(6), d1 /* x1 -> d1 */ 10 | muluw sp@(8), d1 /* x1*y0 */ 11 | addw d1, d0 12 | swap d0 13 | clrw d0 14 | movew sp@(6), d1 /* x1 -> d1 */ 15 | muluw sp@(10), d1 /* x1*y1 */ 16 | addl d1, d0 17 | rts 18 | .cfi_endproc 19 | .size __mulsi3, .-__mulsi3 20 | 21 | .text 22 | .type __udivsi3, function 23 | .globl __udivsi3 24 | __udivsi3: 25 | .cfi_startproc 26 | movel d2, sp@- 27 | .cfi_adjust_cfa_offset 4 28 | movel sp@(12), d1 /* d1 = divisor */ 29 | movel sp@(8), d0 /* d0 = dividend */ 30 | 31 | cmpl #0x10000, d1 /* divisor >= 2 ^ 16 ? */ 32 | jcc 3f /* then try next algorithm */ 33 | movel d0, d2 34 | clrw d2 35 | swap d2 36 | divu d1, d2 /* high quotient in lower word */ 37 | movew d2, d0 /* save high quotient */ 38 | swap d0 39 | movew sp@(10), d2 /* get low dividend + high rest */ 40 | divu d1, d2 /* low quotient */ 41 | movew d2, d0 42 | jra 6f 43 | 44 | 3: movel d1, d2 /* use d2 as divisor backup */ 45 | 4: lsrl #1, d1 /* shift divisor */ 46 | lsrl #1, d0 /* shift dividend */ 47 | cmpl #0x10000, d1 /* still divisor >= 2 ^ 16 ? */ 48 | jcc 4b 49 | divu d1, d0 /* now we have 16-bit divisor */ 50 | andl #0xffff, d0 /* mask out divisor, ignore remainder */ 51 | 52 | /* Multiply the 16-bit tentative quotient with the 32-bit divisor. Because of 53 | the operand ranges, this might give a 33-bit product. If this product is 54 | greater than the dividend, the tentative quotient was too large. */ 55 | movel d2, d1 56 | mulu d0, d1 /* low part, 32 bits */ 57 | swap d2 58 | mulu d0, d2 /* high part, at most 17 bits */ 59 | swap d2 /* align high part with low part */ 60 | tstw d2 /* high part 17 bits? */ 61 | jne 5f /* if 17 bits, quotient was too large */ 62 | addl d2, d1 /* add parts */ 63 | jcs 5f /* if sum is 33 bits, quotient was too large */ 64 | cmpl sp@(8), d1 /* compare the sum with the dividend */ 65 | jls 6f /* if sum > dividend, quotient was too large */ 66 | 5: subql #1, d0 /* adjust quotient */ 67 | 68 | 6: movel sp@+, d2 69 | .cfi_adjust_cfa_offset -4 70 | rts 71 | .cfi_endproc 72 | .size __udivsi3, .-__udivsi3 73 | 74 | .text 75 | .type __divsi3, function 76 | .globl __divsi3 77 | __divsi3: 78 | .cfi_startproc 79 | movel d2, sp@- 80 | .cfi_adjust_cfa_offset 4 81 | 82 | moveq #1, d2 /* sign of result stored in d2 (=1 or =-1) */ 83 | movel sp@(12), d1 /* d1 = divisor */ 84 | jpl 1f 85 | negl d1 86 | negb d2 /* change sign because divisor <0 */ 87 | 1: movel sp@(8), d0 /* d0 = dividend */ 88 | jpl 2f 89 | negl d0 90 | negb d2 91 | 92 | 2: movel d1, sp@- 93 | .cfi_adjust_cfa_offset 4 94 | movel d0, sp@- 95 | .cfi_adjust_cfa_offset 4 96 | jbsr __udivsi3 /* divide abs(dividend) by abs(divisor) */ 97 | addql #8, sp 98 | .cfi_adjust_cfa_offset -8 99 | 100 | tstb d2 101 | jpl 3f 102 | negl d0 103 | 104 | 3: movel sp@+, d2 105 | .cfi_adjust_cfa_offset -4 106 | rts 107 | .cfi_endproc 108 | .size __divsi3, .-__divsi3 109 | 110 | .text 111 | .type __modsi3, function 112 | .globl __modsi3 113 | __modsi3: 114 | .cfi_startproc 115 | movel sp@(8), d1 /* d1 = divisor */ 116 | movel sp@(4), d0 /* d0 = dividend */ 117 | movel d1, sp@- 118 | .cfi_adjust_cfa_offset 4 119 | movel d0, sp@- 120 | .cfi_adjust_cfa_offset 4 121 | jbsr __divsi3 122 | addql #8, sp 123 | .cfi_adjust_cfa_offset -8 124 | movel sp@(8), d1 /* d1 = divisor */ 125 | movel d1, sp@- 126 | .cfi_adjust_cfa_offset 4 127 | movel d0, sp@- 128 | .cfi_adjust_cfa_offset 4 129 | jbsr __mulsi3 /* d0 = (a/b)*b */ 130 | addql #8, sp 131 | .cfi_adjust_cfa_offset -8 132 | movel sp@(4), d1 /* d1 = dividend */ 133 | subl d0, d1 /* d1 = a - (a/b)*b */ 134 | movel d1, d0 135 | rts 136 | .cfi_endproc 137 | .size __modsi3, .-__modsi3 138 | 139 | .text 140 | .type __umodsi3, function 141 | .globl __umodsi3 142 | __umodsi3: 143 | .cfi_startproc 144 | movel sp@(8), d1 /* d1 = divisor */ 145 | movel sp@(4), d0 /* d0 = dividend */ 146 | movel d1, sp@- 147 | .cfi_adjust_cfa_offset 4 148 | movel d0, sp@- 149 | .cfi_adjust_cfa_offset 4 150 | jbsr __udivsi3 151 | addql #8, sp 152 | .cfi_adjust_cfa_offset -8 153 | movel sp@(8), d1 /* d1 = divisor */ 154 | movel d1, sp@- 155 | .cfi_adjust_cfa_offset 4 156 | movel d0, sp@- 157 | .cfi_adjust_cfa_offset 4 158 | jbsr __mulsi3 /* d0 = (a/b)*b */ 159 | addql #8, sp 160 | .cfi_adjust_cfa_offset -8 161 | movel sp@(4), d1 /* d1 = dividend */ 162 | subl d0, d1 /* d1 = a - (a/b)*b */ 163 | movel d1, d0 164 | rts 165 | .cfi_endproc 166 | .size __umodsi3, .-__umodsi3 167 | 168 | /* 169 | .text 170 | .type KPutCharX, function 171 | .globl KPutCharX 172 | 173 | KPutCharX: 174 | .cfi_startproc 175 | move.l a6, -(sp) 176 | .cfi_adjust_cfa_offset 4 177 | move.l 4.w, a6 178 | jsr -0x204(a6) 179 | move.l (sp)+, a6 180 | .cfi_adjust_cfa_offset -4 181 | rts 182 | .cfi_endproc 183 | .size KPutCharX, .-KPutCharX 184 | 185 | .text 186 | .type PutChar, function 187 | .globl PutChar 188 | 189 | PutChar: 190 | .cfi_startproc 191 | move.b d0, (a3)+ 192 | rts 193 | .cfi_endproc 194 | .size PutChar, .-PutChar 195 | */ 196 | -------------------------------------------------------------------------------- /SDDDE/support/gcc8_c_support.c: -------------------------------------------------------------------------------- 1 | #include "gcc8_c_support.h" 2 | #include 3 | #include 4 | 5 | extern struct ExecBase* SysBase; 6 | 7 | static char stdout_buf[128]; 8 | static ULONG stdout_buf_pos; 9 | 10 | void flush_stdout(void) 11 | { 12 | Write(Output(),stdout_buf,stdout_buf_pos); 13 | stdout_buf_pos=0; 14 | } 15 | 16 | void putchar(void) 17 | { 18 | register volatile int c __asm("d0"); 19 | if (!c) return; 20 | if (c==10) 21 | { 22 | stdout_buf[stdout_buf_pos++]=13; 23 | if (stdout_buf_pos==sizeof(stdout_buf)) flush_stdout(); 24 | } 25 | stdout_buf[stdout_buf_pos++]=c; 26 | if (stdout_buf_pos==sizeof(stdout_buf)) flush_stdout(); 27 | } 28 | 29 | unsigned long strlen(const char* s) { 30 | unsigned long t=0; 31 | while(*s++) 32 | t++; 33 | return t; 34 | } 35 | 36 | //__attribute__((optimize("no-tree-loop-distribute-patterns"))) 37 | void* memset(void *dest, int val, unsigned long len) { 38 | unsigned char *ptr = (unsigned char *)dest; 39 | while(len-- > 0) 40 | *ptr++ = val; 41 | return dest; 42 | } 43 | 44 | //__attribute__((optimize("no-tree-loop-distribute-patterns"))) 45 | void* memcpy(void *dest, const void *src, unsigned long len) { 46 | char *d = (char *)dest; 47 | const char *s = (const char *)src; 48 | while(len--) 49 | *d++ = *s++; 50 | return dest; 51 | } 52 | 53 | //__attribute__((optimize("no-tree-loop-distribute-patterns"))) 54 | void* memmove(void *dest, const void *src, unsigned long len) { 55 | char *d = dest; 56 | const char *s = src; 57 | if (d < s) { 58 | while (len--) 59 | *d++ = *s++; 60 | } else { 61 | const char *lasts = s + (len - 1); 62 | char *lastd = d + (len - 1); 63 | while (len--) 64 | *lastd-- = *lasts--; 65 | } 66 | return dest; 67 | } 68 | 69 | #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ 70 | static int isspace(int _C) 71 | { 72 | return (_C >= '\x09' && _C <= '\x0d') || _C == ' '; 73 | } 74 | 75 | static int isdigit(int _C) 76 | { 77 | return _C >= '0' && _C <= '9'; 78 | } 79 | static int islower(int _C) 80 | { 81 | return _C >= 'a' && _C <= 'z'; 82 | } 83 | 84 | static int isupper(int _C) 85 | { 86 | return _C >= 'A' && _C <= 'Z'; 87 | } 88 | 89 | static int isalpha(int _C) 90 | { 91 | return islower(_C) || isupper(_C); 92 | } 93 | 94 | 95 | 96 | unsigned long 97 | strtoul(const char *nptr, char **endptr, register int base) 98 | { 99 | register const char *s = nptr; 100 | register unsigned long acc; 101 | register int c; 102 | register unsigned long cutoff; 103 | register int neg = 0, any, cutlim; 104 | /* 105 | * See strtol for comments as to the logic used. 106 | */ 107 | do { 108 | c = *s++; 109 | } while (isspace(c)); 110 | if (c == '-') { 111 | neg = 1; 112 | c = *s++; 113 | } else if (c == '+') 114 | c = *s++; 115 | if ((base == 0 || base == 16) && 116 | c == '0' && (*s == 'x' || *s == 'X')) { 117 | c = s[1]; 118 | s += 2; 119 | base = 16; 120 | } 121 | if (base == 0) 122 | base = c == '0' ? 8 : 10; 123 | cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; 124 | cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; 125 | for (acc = 0, any = 0;; c = *s++) { 126 | if (isdigit(c)) 127 | c -= '0'; 128 | else if (isalpha(c)) 129 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 130 | else 131 | break; 132 | if (c >= base) 133 | break; 134 | if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 135 | any = -1; 136 | else { 137 | any = 1; 138 | acc *= base; 139 | acc += c; 140 | } 141 | } 142 | if (any < 0) { 143 | acc = ULONG_MAX; 144 | // errno = ERANGE; 145 | } else if (neg) 146 | acc = -acc; 147 | if (endptr != 0) 148 | *endptr = (char *) (any ? s - 1 : nptr); 149 | return (acc); 150 | } 151 | 152 | 153 | #if 0 154 | // vbcc 155 | typedef unsigned char *va_list; 156 | #define va_start(ap, lastarg) ((ap)=(va_list)(&lastarg+1)) 157 | 158 | void KPutCharX(); 159 | void PutChar(); 160 | 161 | __attribute__((noinline)) __attribute__((optimize("O1"))) 162 | void KPrintF(const char* fmt, ...) { 163 | va_list vl; 164 | va_start(vl, fmt); 165 | long(*UaeDbgLog)(long mode, const char* string) = (long(*)(long, const char*))0xf0ff60; 166 | if(*((UWORD *)UaeDbgLog) == 0x4eb9 || *((UWORD *)UaeDbgLog) == 0xa00e) { 167 | char temp[128]; 168 | RawDoFmt((CONST_STRPTR)fmt, vl, PutChar, temp); 169 | UaeDbgLog(86, temp); 170 | } else { 171 | RawDoFmt((CONST_STRPTR)fmt, vl, KPutCharX, 0); 172 | } 173 | } 174 | #endif 175 | 176 | int main(); 177 | 178 | extern void (*__preinit_array_start[])() __attribute__((weak)); 179 | extern void (*__preinit_array_end[])() __attribute__((weak)); 180 | extern void (*__init_array_start[])() __attribute__((weak)); 181 | extern void (*__init_array_end[])() __attribute__((weak)); 182 | extern void (*__fini_array_start[])() __attribute__((weak)); 183 | extern void (*__fini_array_end[])() __attribute__((weak)); 184 | 185 | __attribute__((used)) __attribute__((section(".text.unlikely"))) void _start() { 186 | // initialize globals, ctors etc. 187 | unsigned long count; 188 | unsigned long i; 189 | 190 | count = __preinit_array_end - __preinit_array_start; 191 | for (i = 0; i < count; i++) 192 | __preinit_array_start[i](); 193 | 194 | count = __init_array_end - __init_array_start; 195 | for (i = 0; i < count; i++) 196 | __init_array_start[i](); 197 | 198 | main(); 199 | 200 | // call dtors 201 | count = __fini_array_end - __fini_array_start; 202 | for (i = count; i > 0; i--) 203 | __fini_array_start[i - 1](); 204 | } 205 | 206 | #if 0 207 | 208 | void warpmode(int on) { // bool 209 | long(*UaeConf)(long mode, int index, const char* param, int param_len, char* outbuf, int outbuf_len); 210 | UaeConf = (long(*)(long, int, const char*, int, char*, int))0xf0ff60; 211 | if(*((UWORD *)UaeConf) == 0x4eb9 || *((UWORD *)UaeConf) == 0xa00e) { 212 | char outbuf; 213 | UaeConf(82, -1, on ? "warp true" : "warp false", 0, &outbuf, 1); 214 | UaeConf(82, -1, on ? "cpu_speed max" : "cpu_speed real", 0, &outbuf, 1); 215 | UaeConf(82, -1, on ? "cpu_cycle_exact false" : "cpu_cycle_exact true", 0, &outbuf, 1); 216 | UaeConf(82, -1, on ? "cpu_memory_cycle_exact false" : "cpu_memory_cycle_exact true", 0, &outbuf, 1); 217 | UaeConf(82, -1, on ? "blitter_cycle_exact false" : "blitter_cycle_exact true", 0, &outbuf, 1); 218 | } 219 | } 220 | 221 | static void debug_cmd(unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4) { 222 | long(*UaeLib)(unsigned int arg0, unsigned int arg1, unsigned int arg2, unsigned int arg3, unsigned int arg4); 223 | UaeLib = (long(*)(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int))0xf0ff60; 224 | if(*((UWORD *)UaeLib) == 0x4eb9 || *((UWORD *)UaeLib) == 0xa00e) { 225 | UaeLib(88, arg1, arg2, arg3, arg4); 226 | } 227 | } 228 | 229 | enum barto_cmd { 230 | barto_cmd_clear, 231 | barto_cmd_rect, 232 | barto_cmd_filled_rect, 233 | barto_cmd_text, 234 | barto_cmd_register_resource, 235 | barto_cmd_set_idle, 236 | barto_cmd_unregister_resource, 237 | }; 238 | 239 | enum debug_resource_type { 240 | debug_resource_type_bitmap, 241 | debug_resource_type_palette, 242 | debug_resource_type_copperlist, 243 | }; 244 | 245 | struct debug_resource { 246 | unsigned int address; // can't use void* because WinUAE is 64-bit 247 | unsigned int size; 248 | char name[32]; 249 | unsigned short /*enum debug_resource_type*/ type; 250 | unsigned short /*enum debug_resource_flags*/ flags; 251 | 252 | union { 253 | struct bitmap { 254 | short width; 255 | short height; 256 | short numPlanes; 257 | } bitmap; 258 | struct palette { 259 | short numEntries; 260 | } palette; 261 | }; 262 | }; 263 | 264 | // debug overlay 265 | void debug_clear() { 266 | debug_cmd(barto_cmd_clear, 0, 0, 0); 267 | } 268 | 269 | void debug_rect(short left, short top, short right, short bottom, unsigned int color) { 270 | debug_cmd(barto_cmd_rect, (((unsigned int)left) << 16) | ((unsigned int)top), (((unsigned int)right) << 16) | ((unsigned int)bottom), color); 271 | } 272 | 273 | void debug_filled_rect(short left, short top, short right, short bottom, unsigned int color) { 274 | debug_cmd(barto_cmd_filled_rect, (((unsigned int)left) << 16) | ((unsigned int)top), (((unsigned int)right) << 16) | ((unsigned int)bottom), color); 275 | } 276 | 277 | void debug_text(short left, short top, const char* text, unsigned int color) { 278 | debug_cmd(barto_cmd_text, (((unsigned int)left) << 16) | ((unsigned int)top), (unsigned int)text, color); 279 | } 280 | 281 | // profiler 282 | void debug_start_idle() { 283 | debug_cmd(barto_cmd_set_idle, 1, 0, 0); 284 | } 285 | 286 | void debug_stop_idle() { 287 | debug_cmd(barto_cmd_set_idle, 0, 0, 0); 288 | } 289 | 290 | // gfx debugger 291 | static void my_strncpy(char* destination, const char* source, unsigned long num) { 292 | while(*source && --num > 0) 293 | *destination++ = *source++; 294 | *destination = '\0'; 295 | } 296 | 297 | void debug_register_bitmap(const void* addr, const char* name, short width, short height, short numPlanes, unsigned short flags) { 298 | struct debug_resource resource = { 299 | .address = (unsigned int)addr, 300 | .size = width / 8 * height * numPlanes, 301 | .type = debug_resource_type_bitmap, 302 | .flags = flags, 303 | .bitmap = { width, height, numPlanes } 304 | }; 305 | 306 | if (flags & debug_resource_bitmap_masked) 307 | resource.size *= 2; 308 | 309 | my_strncpy(resource.name, name, sizeof(resource.name)); 310 | debug_cmd(barto_cmd_register_resource, (unsigned int)&resource, 0, 0); 311 | } 312 | 313 | void debug_register_palette(const void* addr, const char* name, short numEntries, unsigned short flags) { 314 | struct debug_resource resource = { 315 | .address = (unsigned int)addr, 316 | .size = numEntries * 2, 317 | .type = debug_resource_type_palette, 318 | .flags = flags, 319 | .palette = { numEntries } 320 | }; 321 | my_strncpy(resource.name, name, sizeof(resource.name)); 322 | debug_cmd(barto_cmd_register_resource, (unsigned int)&resource, 0, 0); 323 | } 324 | 325 | void debug_register_copperlist(const void* addr, const char* name, unsigned int size, unsigned short flags) { 326 | struct debug_resource resource = { 327 | .address = (unsigned int)addr, 328 | .size = size, 329 | .type = debug_resource_type_copperlist, 330 | .flags = flags, 331 | }; 332 | my_strncpy(resource.name, name, sizeof(resource.name)); 333 | debug_cmd(barto_cmd_register_resource, (unsigned int)&resource, 0, 0); 334 | } 335 | 336 | void debug_unregister(const void* addr) { 337 | debug_cmd(barto_cmd_unregister_resource, (unsigned int)addr, 0, 0); 338 | } 339 | 340 | #endif -------------------------------------------------------------------------------- /SDDDE/support/gcc8_c_support.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #define offsetof(st, m) __builtin_offsetof(st, m) 8 | 9 | // VSCode's IntelliSense doesn't know about 68000 registers, so suppress warnings 10 | #ifndef __INTELLISENSE__ 11 | #define ASM __asm 12 | #else 13 | #define ASM(...) 14 | #endif 15 | 16 | void *memcpy (void *, const void *, unsigned long); 17 | void *memset (void *, int, unsigned long); 18 | void *memmove (void *, const void *, unsigned long); 19 | unsigned long strlen (const char *); 20 | 21 | unsigned long 22 | strtoul(const char *nptr, char **endptr, register int base); 23 | 24 | 25 | void warpmode(int on); // bool on/off 26 | void KPrintF(const char* fmt, ...); // output to debugger 27 | 28 | // WinUAE debug overlay, coordinates are PAL-based (0,0)-(768,576) 29 | void debug_clear(); 30 | void debug_rect(short left, short top, short right, short bottom, unsigned int color); 31 | void debug_filled_rect(short left, short top, short right, short bottom, unsigned int color); 32 | void debug_text(short left, short top, const char* text, unsigned int color); 33 | 34 | // profiler 35 | void debug_start_idle(); 36 | void debug_stop_idle(); 37 | 38 | // Graphics debugger 39 | enum debug_resource_flags { 40 | debug_resource_bitmap_interleaved = 1 << 0, 41 | debug_resource_bitmap_masked = 1 << 1, 42 | debug_resource_bitmap_ham = 1 << 2, 43 | }; 44 | 45 | void debug_register_bitmap(const void* addr, const char* name, short width, short height, short numPlanes, unsigned short flags); 46 | void debug_register_palette(const void* addr, const char* name, short numEntries, unsigned short flags); 47 | void debug_register_copperlist(const void* addr, const char* name, unsigned int size, unsigned short flags); 48 | void debug_unregister(const void* addr); 49 | 50 | #define INCBIN(name, file) INCBIN_SECTION(name, file, ".rodata", "") 51 | #define INCBIN_CHIP(name, file) INCBIN_SECTION(name, file, ".INCBIN.MEMF_CHIP", "aw") 52 | #define INCBIN_SECTION(name, file, section, flags) \ 53 | __asm__(".pushsection " #section ", " #flags "\n" \ 54 | ".global incbin_" #name "_start\n" \ 55 | ".type incbin_" #name "_start, @object\n" \ 56 | ".balign 2\n" \ 57 | "incbin_" #name "_start:\n" \ 58 | ".incbin \"" file "\"\n" \ 59 | \ 60 | ".global incbin_" #name "_end\n" \ 61 | ".type incbin_" #name "_end, @object\n" \ 62 | ".size incbin_" #name "_start, incbin_" #name "_end - incbin_" #name "_start\n" \ 63 | ".balign 1\n" \ 64 | "incbin_" #name "_end:\n" \ 65 | ".byte 0\n" \ 66 | ".popsection\n" \ 67 | ); \ 68 | extern const __attribute__((aligned(2))) char incbin_ ## name ## _start[1024*1024]; \ 69 | extern const void* incbin_ ## name ## _end;\ 70 | const void* name = &incbin_ ## name ## _start; 71 | 72 | inline unsigned int muluw(unsigned short a, unsigned short b) { 73 | asm("muluw %1,%0":"+d"(a): "mid"(b): "cc"); 74 | return a; 75 | } 76 | inline int mulsw(short a, short b) { 77 | asm("mulsw %1,%0":"+d"(a): "mid"(b): "cc"); 78 | return a; 79 | } 80 | inline unsigned short divuw(unsigned int a, unsigned short b) { 81 | asm("divuw %1,%0":"+d"(a): "mid"(b): "cc"); 82 | return a; 83 | } 84 | inline short divsw(int a, short b) { 85 | asm("divsw %1,%0":"+d"(a): "mid"(b): "cc"); 86 | return a; 87 | } 88 | 89 | #ifdef __cplusplus 90 | } // extern "C" 91 | #endif 92 | -------------------------------------------------------------------------------- /SplitMap/SplitMap.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.32407.337 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SplitMap", "SplitMap.vcxproj", "{2DDA1AB6-279D-49AA-A91E-990D631C9F24}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Debug|x64.ActiveCfg = Debug|x64 17 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Debug|x64.Build.0 = Debug|x64 18 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Debug|x86.ActiveCfg = Debug|Win32 19 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Debug|x86.Build.0 = Debug|Win32 20 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Release|x64.ActiveCfg = Release|x64 21 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Release|x64.Build.0 = Release|x64 22 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Release|x86.ActiveCfg = Release|Win32 23 | {2DDA1AB6-279D-49AA-A91E-990D631C9F24}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1C4D759B-88B9-4954-82DC-C99352B6E5E6} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SplitMap/SplitMap.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {2dda1ab6-279d-49aa-a91e-990d631c9f24} 25 | SplitMap 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | 87 | Level3 88 | true 89 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 90 | true 91 | Disabled 92 | Default 93 | 94 | 95 | Console 96 | true 97 | 98 | 99 | 100 | 101 | Level3 102 | true 103 | true 104 | true 105 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 106 | true 107 | 108 | 109 | Console 110 | true 111 | true 112 | true 113 | 114 | 115 | 116 | 117 | Level3 118 | true 119 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | true 121 | Disabled 122 | Default 123 | 124 | 125 | Console 126 | true 127 | 128 | 129 | 130 | 131 | Level3 132 | true 133 | true 134 | true 135 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 136 | true 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /SplitMap/clipper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/SplitMap/clipper.cpp -------------------------------------------------------------------------------- /SplitMap/clipper.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * * 3 | * Author : Angus Johnson * 4 | * Version : 6.4.2 * 5 | * Date : 27 February 2017 * 6 | * Website : http://www.angusj.com * 7 | * Copyright : Angus Johnson 2010-2017 * 8 | * * 9 | * License: * 10 | * Use, modification & distribution is subject to Boost Software License Ver 1. * 11 | * http://www.boost.org/LICENSE_1_0.txt * 12 | * * 13 | * Attributions: * 14 | * The code in this library is an extension of Bala Vatti's clipping algorithm: * 15 | * "A generic solution to polygon clipping" * 16 | * Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. * 17 | * http://portal.acm.org/citation.cfm?id=129906 * 18 | * * 19 | * Computer graphics and geometric modeling: implementation and algorithms * 20 | * By Max K. Agoston * 21 | * Springer; 1 edition (January 4, 2005) * 22 | * http://books.google.com/books?q=vatti+clipping+agoston * 23 | * * 24 | * See also: * 25 | * "Polygon Offsetting by Computing Winding Numbers" * 26 | * Paper no. DETC2005-85513 pp. 565-575 * 27 | * ASME 2005 International Design Engineering Technical Conferences * 28 | * and Computers and Information in Engineering Conference (IDETC/CIE2005) * 29 | * September 24-28, 2005 , Long Beach, California, USA * 30 | * http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf * 31 | * * 32 | *******************************************************************************/ 33 | 34 | #ifndef clipper_hpp 35 | #define clipper_hpp 36 | 37 | #define CLIPPER_VERSION "6.4.2" 38 | 39 | //use_int32: When enabled 32bit ints are used instead of 64bit ints. This 40 | //improve performance but coordinate values are limited to the range +/- 46340 41 | //#define use_int32 42 | 43 | //use_xyz: adds a Z member to IntPoint. Adds a minor cost to perfomance. 44 | //#define use_xyz 45 | 46 | //use_lines: Enables line clipping. Adds a very minor cost to performance. 47 | #define use_lines 48 | 49 | //use_deprecated: Enables temporary support for the obsolete functions 50 | //#define use_deprecated 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | namespace ClipperLib { 63 | 64 | enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor }; 65 | enum PolyType { ptSubject, ptClip }; 66 | //By far the most widely used winding rules for polygon filling are 67 | //EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32) 68 | //Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL) 69 | //see http://glprogramming.com/red/chapter11.html 70 | enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; 71 | 72 | #ifdef use_int32 73 | typedef int cInt; 74 | static cInt const loRange = 0x7FFF; 75 | static cInt const hiRange = 0x7FFF; 76 | #else 77 | typedef signed long long cInt; 78 | static cInt const loRange = 0x3FFFFFFF; 79 | static cInt const hiRange = 0x3FFFFFFFFFFFFFFFLL; 80 | typedef signed long long long64; //used by Int128 class 81 | typedef unsigned long long ulong64; 82 | 83 | #endif 84 | 85 | struct IntPoint { 86 | cInt X; 87 | cInt Y; 88 | #ifdef use_xyz 89 | cInt Z; 90 | IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {}; 91 | #else 92 | IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {}; 93 | #endif 94 | 95 | friend inline bool operator== (const IntPoint& a, const IntPoint& b) 96 | { 97 | return a.X == b.X && a.Y == b.Y; 98 | } 99 | friend inline bool operator!= (const IntPoint& a, const IntPoint& b) 100 | { 101 | return a.X != b.X || a.Y != b.Y; 102 | } 103 | }; 104 | //------------------------------------------------------------------------------ 105 | 106 | typedef std::vector< IntPoint > Path; 107 | typedef std::vector< Path > Paths; 108 | 109 | inline Path& operator <<(Path& poly, const IntPoint& p) {poly.push_back(p); return poly;} 110 | inline Paths& operator <<(Paths& polys, const Path& p) {polys.push_back(p); return polys;} 111 | 112 | std::ostream& operator <<(std::ostream &s, const IntPoint &p); 113 | std::ostream& operator <<(std::ostream &s, const Path &p); 114 | std::ostream& operator <<(std::ostream &s, const Paths &p); 115 | 116 | struct DoublePoint 117 | { 118 | double X; 119 | double Y; 120 | DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} 121 | DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {} 122 | }; 123 | //------------------------------------------------------------------------------ 124 | 125 | #ifdef use_xyz 126 | typedef void (*ZFillCallback)(IntPoint& e1bot, IntPoint& e1top, IntPoint& e2bot, IntPoint& e2top, IntPoint& pt); 127 | #endif 128 | 129 | enum InitOptions {ioReverseSolution = 1, ioStrictlySimple = 2, ioPreserveCollinear = 4}; 130 | enum JoinType {jtSquare, jtRound, jtMiter}; 131 | enum EndType {etClosedPolygon, etClosedLine, etOpenButt, etOpenSquare, etOpenRound}; 132 | 133 | class PolyNode; 134 | typedef std::vector< PolyNode* > PolyNodes; 135 | 136 | class PolyNode 137 | { 138 | public: 139 | PolyNode(); 140 | virtual ~PolyNode(){}; 141 | Path Contour; 142 | PolyNodes Childs; 143 | PolyNode* Parent; 144 | PolyNode* GetNext() const; 145 | bool IsHole() const; 146 | bool IsOpen() const; 147 | int ChildCount() const; 148 | private: 149 | //PolyNode& operator =(PolyNode& other); 150 | unsigned Index; //node index in Parent.Childs 151 | bool m_IsOpen; 152 | JoinType m_jointype; 153 | EndType m_endtype; 154 | PolyNode* GetNextSiblingUp() const; 155 | void AddChild(PolyNode& child); 156 | friend class Clipper; //to access Index 157 | friend class ClipperOffset; 158 | }; 159 | 160 | class PolyTree: public PolyNode 161 | { 162 | public: 163 | ~PolyTree(){ Clear(); }; 164 | PolyNode* GetFirst() const; 165 | void Clear(); 166 | int Total() const; 167 | private: 168 | //PolyTree& operator =(PolyTree& other); 169 | PolyNodes AllNodes; 170 | friend class Clipper; //to access AllNodes 171 | }; 172 | 173 | bool Orientation(const Path &poly); 174 | double Area(const Path &poly); 175 | int PointInPolygon(const IntPoint &pt, const Path &path); 176 | 177 | void SimplifyPolygon(const Path &in_poly, Paths &out_polys, PolyFillType fillType = pftEvenOdd); 178 | void SimplifyPolygons(const Paths &in_polys, Paths &out_polys, PolyFillType fillType = pftEvenOdd); 179 | void SimplifyPolygons(Paths &polys, PolyFillType fillType = pftEvenOdd); 180 | 181 | void CleanPolygon(const Path& in_poly, Path& out_poly, double distance = 1.415); 182 | void CleanPolygon(Path& poly, double distance = 1.415); 183 | void CleanPolygons(const Paths& in_polys, Paths& out_polys, double distance = 1.415); 184 | void CleanPolygons(Paths& polys, double distance = 1.415); 185 | 186 | void MinkowskiSum(const Path& pattern, const Path& path, Paths& solution, bool pathIsClosed); 187 | void MinkowskiSum(const Path& pattern, const Paths& paths, Paths& solution, bool pathIsClosed); 188 | void MinkowskiDiff(const Path& poly1, const Path& poly2, Paths& solution); 189 | 190 | void PolyTreeToPaths(const PolyTree& polytree, Paths& paths); 191 | void ClosedPathsFromPolyTree(const PolyTree& polytree, Paths& paths); 192 | void OpenPathsFromPolyTree(PolyTree& polytree, Paths& paths); 193 | 194 | void ReversePath(Path& p); 195 | void ReversePaths(Paths& p); 196 | 197 | struct IntRect { cInt left; cInt top; cInt right; cInt bottom; }; 198 | 199 | //enums that are used internally ... 200 | enum EdgeSide { esLeft = 1, esRight = 2}; 201 | 202 | //forward declarations (for stuff used internally) ... 203 | struct TEdge; 204 | struct IntersectNode; 205 | struct LocalMinimum; 206 | struct OutPt; 207 | struct OutRec; 208 | struct Join; 209 | 210 | typedef std::vector < OutRec* > PolyOutList; 211 | typedef std::vector < TEdge* > EdgeList; 212 | typedef std::vector < Join* > JoinList; 213 | typedef std::vector < IntersectNode* > IntersectList; 214 | 215 | //------------------------------------------------------------------------------ 216 | 217 | //ClipperBase is the ancestor to the Clipper class. It should not be 218 | //instantiated directly. This class simply abstracts the conversion of sets of 219 | //polygon coordinates into edge objects that are stored in a LocalMinima list. 220 | class ClipperBase 221 | { 222 | public: 223 | ClipperBase(); 224 | virtual ~ClipperBase(); 225 | virtual bool AddPath(const Path &pg, PolyType PolyTyp, bool Closed); 226 | bool AddPaths(const Paths &ppg, PolyType PolyTyp, bool Closed); 227 | virtual void Clear(); 228 | IntRect GetBounds(); 229 | bool PreserveCollinear() {return m_PreserveCollinear;}; 230 | void PreserveCollinear(bool value) {m_PreserveCollinear = value;}; 231 | protected: 232 | void DisposeLocalMinimaList(); 233 | TEdge* AddBoundsToLML(TEdge *e, bool IsClosed); 234 | virtual void Reset(); 235 | TEdge* ProcessBound(TEdge* E, bool IsClockwise); 236 | void InsertScanbeam(const cInt Y); 237 | bool PopScanbeam(cInt &Y); 238 | bool LocalMinimaPending(); 239 | bool PopLocalMinima(cInt Y, const LocalMinimum *&locMin); 240 | OutRec* CreateOutRec(); 241 | void DisposeAllOutRecs(); 242 | void DisposeOutRec(PolyOutList::size_type index); 243 | void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2); 244 | void DeleteFromAEL(TEdge *e); 245 | void UpdateEdgeIntoAEL(TEdge *&e); 246 | 247 | typedef std::vector MinimaList; 248 | MinimaList::iterator m_CurrentLM; 249 | MinimaList m_MinimaList; 250 | 251 | bool m_UseFullRange; 252 | EdgeList m_edges; 253 | bool m_PreserveCollinear; 254 | bool m_HasOpenPaths; 255 | PolyOutList m_PolyOuts; 256 | TEdge *m_ActiveEdges; 257 | 258 | typedef std::priority_queue ScanbeamList; 259 | ScanbeamList m_Scanbeam; 260 | }; 261 | //------------------------------------------------------------------------------ 262 | 263 | class Clipper : public virtual ClipperBase 264 | { 265 | public: 266 | Clipper(int initOptions = 0); 267 | bool Execute(ClipType clipType, 268 | Paths &solution, 269 | PolyFillType fillType = pftEvenOdd); 270 | bool Execute(ClipType clipType, 271 | Paths &solution, 272 | PolyFillType subjFillType, 273 | PolyFillType clipFillType); 274 | bool Execute(ClipType clipType, 275 | PolyTree &polytree, 276 | PolyFillType fillType = pftEvenOdd); 277 | bool Execute(ClipType clipType, 278 | PolyTree &polytree, 279 | PolyFillType subjFillType, 280 | PolyFillType clipFillType); 281 | bool ReverseSolution() { return m_ReverseOutput; }; 282 | void ReverseSolution(bool value) {m_ReverseOutput = value;}; 283 | bool StrictlySimple() {return m_StrictSimple;}; 284 | void StrictlySimple(bool value) {m_StrictSimple = value;}; 285 | //set the callback function for z value filling on intersections (otherwise Z is 0) 286 | #ifdef use_xyz 287 | void ZFillFunction(ZFillCallback zFillFunc); 288 | #endif 289 | protected: 290 | virtual bool ExecuteInternal(); 291 | private: 292 | JoinList m_Joins; 293 | JoinList m_GhostJoins; 294 | IntersectList m_IntersectList; 295 | ClipType m_ClipType; 296 | typedef std::list MaximaList; 297 | MaximaList m_Maxima; 298 | TEdge *m_SortedEdges; 299 | bool m_ExecuteLocked; 300 | PolyFillType m_ClipFillType; 301 | PolyFillType m_SubjFillType; 302 | bool m_ReverseOutput; 303 | bool m_UsingPolyTree; 304 | bool m_StrictSimple; 305 | #ifdef use_xyz 306 | ZFillCallback m_ZFill; //custom callback 307 | #endif 308 | void SetWindingCount(TEdge& edge); 309 | bool IsEvenOddFillType(const TEdge& edge) const; 310 | bool IsEvenOddAltFillType(const TEdge& edge) const; 311 | void InsertLocalMinimaIntoAEL(const cInt botY); 312 | void InsertEdgeIntoAEL(TEdge *edge, TEdge* startEdge); 313 | void AddEdgeToSEL(TEdge *edge); 314 | bool PopEdgeFromSEL(TEdge *&edge); 315 | void CopyAELToSEL(); 316 | void DeleteFromSEL(TEdge *e); 317 | void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2); 318 | bool IsContributing(const TEdge& edge) const; 319 | bool IsTopHorz(const cInt XPos); 320 | void DoMaxima(TEdge *e); 321 | void ProcessHorizontals(); 322 | void ProcessHorizontal(TEdge *horzEdge); 323 | void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); 324 | OutPt* AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); 325 | OutRec* GetOutRec(int idx); 326 | void AppendPolygon(TEdge *e1, TEdge *e2); 327 | void IntersectEdges(TEdge *e1, TEdge *e2, IntPoint &pt); 328 | OutPt* AddOutPt(TEdge *e, const IntPoint &pt); 329 | OutPt* GetLastOutPt(TEdge *e); 330 | bool ProcessIntersections(const cInt topY); 331 | void BuildIntersectList(const cInt topY); 332 | void ProcessIntersectList(); 333 | void ProcessEdgesAtTopOfScanbeam(const cInt topY); 334 | void BuildResult(Paths& polys); 335 | void BuildResult2(PolyTree& polytree); 336 | void SetHoleState(TEdge *e, OutRec *outrec); 337 | void DisposeIntersectNodes(); 338 | bool FixupIntersectionOrder(); 339 | void FixupOutPolygon(OutRec &outrec); 340 | void FixupOutPolyline(OutRec &outrec); 341 | bool IsHole(TEdge *e); 342 | bool FindOwnerFromSplitRecs(OutRec &outRec, OutRec *&currOrfl); 343 | void FixHoleLinkage(OutRec &outrec); 344 | void AddJoin(OutPt *op1, OutPt *op2, const IntPoint offPt); 345 | void ClearJoins(); 346 | void ClearGhostJoins(); 347 | void AddGhostJoin(OutPt *op, const IntPoint offPt); 348 | bool JoinPoints(Join *j, OutRec* outRec1, OutRec* outRec2); 349 | void JoinCommonEdges(); 350 | void DoSimplePolygons(); 351 | void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec); 352 | void FixupFirstLefts2(OutRec* InnerOutRec, OutRec* OuterOutRec); 353 | void FixupFirstLefts3(OutRec* OldOutRec, OutRec* NewOutRec); 354 | #ifdef use_xyz 355 | void SetZ(IntPoint& pt, TEdge& e1, TEdge& e2); 356 | #endif 357 | }; 358 | //------------------------------------------------------------------------------ 359 | 360 | class ClipperOffset 361 | { 362 | public: 363 | ClipperOffset(double miterLimit = 2.0, double roundPrecision = 0.25); 364 | ~ClipperOffset(); 365 | void AddPath(const Path& path, JoinType joinType, EndType endType); 366 | void AddPaths(const Paths& paths, JoinType joinType, EndType endType); 367 | void Execute(Paths& solution, double delta); 368 | void Execute(PolyTree& solution, double delta); 369 | void Clear(); 370 | double MiterLimit; 371 | double ArcTolerance; 372 | private: 373 | Paths m_destPolys; 374 | Path m_srcPoly; 375 | Path m_destPoly; 376 | std::vector m_normals; 377 | double m_delta, m_sinA, m_sin, m_cos; 378 | double m_miterLim, m_StepsPerRad; 379 | IntPoint m_lowest; 380 | PolyNode m_polyNodes; 381 | 382 | void FixOrientations(); 383 | void DoOffset(double delta); 384 | void OffsetPoint(int j, int& k, JoinType jointype); 385 | void DoSquare(int j, int k); 386 | void DoMiter(int j, int k, double r); 387 | void DoRound(int j, int k); 388 | }; 389 | //------------------------------------------------------------------------------ 390 | 391 | class clipperException : public std::exception 392 | { 393 | public: 394 | clipperException(const char* description): m_descr(description) {} 395 | virtual ~clipperException() throw() {} 396 | virtual const char* what() const throw() {return m_descr.c_str();} 397 | private: 398 | std::string m_descr; 399 | }; 400 | //------------------------------------------------------------------------------ 401 | 402 | } //ClipperLib namespace 403 | 404 | #endif //clipper_hpp 405 | 406 | 407 | -------------------------------------------------------------------------------- /SplitMap/render.h: -------------------------------------------------------------------------------- 1 | #ifndef RENDER_H 2 | #define RENDER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #define _USE_MATH_DEFINES 9 | #include 10 | 11 | #define XYZF_SCOORD_NOT_VALID (1) 12 | 13 | #define XYZF_HULLQ (2) 14 | 15 | #define XYZF_ALLOCATED (4) 16 | 17 | struct VERTEX; 18 | struct FACE; 19 | 20 | typedef struct FACES_BY_POINT 21 | { 22 | struct FACES_BY_POINT* next; 23 | struct FACE* face; 24 | struct VERTEX* v; 25 | }FACES_BY_POINT; 26 | 27 | typedef struct FPXYZ 28 | { 29 | double X; //World X, 24.8 30 | double Y; //World Y, 24.8 31 | double Z; //World Z, 24.8 32 | uint32_t flags; 33 | uint32_t id; 34 | struct FPXYZ* next; 35 | FACES_BY_POINT* FbyP; //Faces that use this point (for hull compute) 36 | }FPXYZ; 37 | 38 | #define VERTEXF_SCOORD_NOT_VALID (1) 39 | 40 | //#define VERTEXF_ALREADY_TESTED (1) 41 | #define VERTEXF_ALREADY_IN_Q (2) 42 | 43 | typedef struct VERTEX 44 | { 45 | struct VERTEX* next; //Следующая вершина (для обхода) 46 | struct VERTEX* prev; //Предыдущая вершина (для обхода) 47 | //FPXYZ* point; //Указатель на исходную точку 48 | int point_id; //Пригодится для обратного преобразования 49 | int TVn; 50 | double X; 51 | double Y; 52 | double Z; 53 | double U; 54 | double V; 55 | double x; 56 | double y; 57 | double z; 58 | double sx; 59 | double sy; 60 | //Владелец 61 | struct FACE* face; 62 | uint32_t flags; 63 | }VERTEX; 64 | 65 | typedef struct RVERTEX 66 | { 67 | struct RVERTEX* next; 68 | struct RVERTEX* prev; 69 | double sx; 70 | double sy; 71 | double x; 72 | double y; 73 | double z; 74 | uint16_t flags; 75 | }RVERTEX; 76 | 77 | 78 | //Необходимо рисовать с полноценным рендером 79 | #define FACEF_FULL_RENDER (1) 80 | 81 | #define FACEF_ALREADY_IN_Q (16) 82 | #define FACEF_DROPPED (32) 83 | 84 | #define FACEF_DUMPED (64) 85 | 86 | struct CUBE; 87 | 88 | typedef struct FACE 89 | { 90 | uint32_t id; 91 | struct FACE* next; 92 | struct FACE* next2; 93 | struct FACE* next_tri; 94 | uint16_t flags; 95 | VERTEX *v; 96 | int T; 97 | struct CUBE *portal_to_cube; 98 | //Коэффициенты уравнения плоскости. Кстати, A..C - заодно и вектор нормали 99 | double A; //16.16 100 | double B; 101 | double C; 102 | double D; //24.8 103 | //Для простоты, сразу посчитаем среднюю точку грани для вычисления хуллов 104 | double MX; 105 | double MY; 106 | double MZ; 107 | double R; //Радиус сферы, в которой лежит грань. Чтобы точно не проверять дальние на пересечение 108 | struct FACE* parent_face; 109 | //struct CUBE* parent_cube; //Куб-родитель 110 | //struct FACE* paired_portal; //Парный портал 111 | int seq; 112 | int side_hit; 113 | int32_t avg_z; 114 | uint16_t leaf_idx[16]; 115 | int leaf_cnt; 116 | int N; //Количество вертексов, чтобы быстре принимать решение, бить ли квады на треугольники 117 | }FACE; 118 | 119 | typedef struct FACEQ 120 | { 121 | struct FACEQ* next; 122 | FACE* f; 123 | }FACEQ; 124 | 125 | /* 126 | typedef struct 127 | { 128 | double x; 129 | double y; 130 | double z; 131 | }VEC3; 132 | */ 133 | 134 | typedef double VEC3[3]; 135 | 136 | typedef struct PVS 137 | { 138 | struct PVS* next; 139 | CUBE* c; 140 | FACE* f; 141 | }PVS; 142 | 143 | //============= rendinit.cpp ====================== 144 | void RenderAllocMemory(void); 145 | int ComputeABCD(FACE* face); 146 | FACE* AllocFace(void); 147 | void FreeFace(FACE* face); 148 | VERTEX* AllocVertex(); 149 | VERTEX* CreateVertex(double X, double Y, double Z, double U, double V); 150 | void CreateWorld(void); 151 | void CreateWorldFromFile(void); 152 | 153 | void LoadObj(void); 154 | 155 | //Эти две функции мы используем в разбиении граней при рендере с учетом перспективы 156 | VERTEX* CreateVertexFast(double X, double Y, double Z, double U, double V); 157 | void DestroyVertexFast(VERTEX* v); 158 | 159 | #endif -------------------------------------------------------------------------------- /target/a.mingw.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/a.mingw.exe -------------------------------------------------------------------------------- /target/omni/FACES.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/FACES.bin -------------------------------------------------------------------------------- /target/omni/FPXYZ.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/FPXYZ.bin -------------------------------------------------------------------------------- /target/omni/cindex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/cindex.bin -------------------------------------------------------------------------------- /target/omni/clist.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/clist.bin -------------------------------------------------------------------------------- /target/omni/faces_in_leafs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/faces_in_leafs.bin -------------------------------------------------------------------------------- /target/omni/fil_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/fil_idx.bin -------------------------------------------------------------------------------- /target/omni/kdtree.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/kdtree.bin -------------------------------------------------------------------------------- /target/omni/pvs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/pvs.bin -------------------------------------------------------------------------------- /target/omni/pvs_idx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/pvs_idx.bin -------------------------------------------------------------------------------- /target/omni/texture.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/texture.bin -------------------------------------------------------------------------------- /target/omni/texture.c32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rst7CBSIE/SDDDE/4b5514bd35fcf19025aa74306e866a6b05d6f3cd/target/omni/texture.c32 --------------------------------------------------------------------------------