Comment: | Convert dynent to a class |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
d2b3ff790fee10ef4150cdb17f1c979e |
User & Date: | js on 2025-03-09 18:57:42 |
Other Links: | manifest | tags |
2025-03-09
| ||
21:33 | Clean up serverbrowser.mm check-in: 4d3e209260 user: js tags: trunk | |
18:57 | Convert dynent to a class check-in: d2b3ff790f user: js tags: trunk | |
11:24 | Migrate projectile to a class check-in: d3b4b2d476 user: js tags: trunk | |
Modified src/Cube.mm from [909022edb6] to [874b037f55].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + | // main.cpp: initialisation & main loop #include "cube.h" #import "DynamicEntity.h" OF_APPLICATION_DELEGATE(Cube) VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100); VARP(minmillis, 0, 5, 1000); @implementation Cube |
︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | + + | [OFFileManager.defaultManager createDirectoryAtIRI:[_userDataIRI IRIByAppendingPathComponent:@"savegames"] createParents:true]; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) fatal(@"Unable to initialize SDL"); initPlayers(); log(@"net"); if (enet_initialize() < 0) fatal(@"Unable to initialise network module"); initclient(); // never returns if dedicated |
︙ | |||
208 209 210 211 212 213 214 | 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | - + - + - + | if (!demoplayback) serverslice((int)time(NULL), 0); static float fps = 30.0f; fps = (1000.0f / curtime + fps * 50) / 51; |
︙ |
Added src/DynamicEntity.h version [0a25294c06].
Added src/DynamicEntity.mm version [412962c92b].
Modified src/Projectile.h from [28cf35ad48] to [f3375dc858].
1 2 | 1 2 3 4 5 6 7 8 9 10 11 | - + - + | #import <ObjFW/ObjFW.h> |
Modified src/client.mm from [cdd53f348e] to [90c446262c].
1 2 3 4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | + + - - - - - - + + + + + + + + | // client.cpp, mostly network related client game code #include "cube.h" #import "DynamicEntity.h" |
︙ | |||
55 56 57 58 59 60 61 | 59 60 61 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 | + - - - + + + + + + + - - - + + + + + + - - + + | enet_peer_throttle_configure(clienthost->peers, throttle_interval * 1000, throttle_accel, throttle_decel); } void newname(OFString *name) { @autoreleasepool { |
︙ | |||
133 134 135 136 137 138 139 | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | - - + + | conoutf(@"disconnected"); clienthost = NULL; connecting = 0; connattempts = 0; disconnecting = 0; clientnum = -1; c2sinit = false; |
︙ | |||
164 165 166 167 168 169 170 | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | - + | disconnect(0, !disconnecting); } static OFString *ctext; void toserver(OFString *text) { |
︙ | |||
267 268 269 270 271 272 273 274 | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | + - + | if (clienthost) { enet_host_broadcast(clienthost, 0, (ENetPacket *)packet); enet_host_flush(clienthost); } else localclienttoserver((ENetPacket *)packet); } // send update to the server void |
︙ | |||
291 292 293 294 295 296 297 | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | - - - - - - - - - - + + + + + + + + - - - - + + + + - - - + + + - + - + - - - + + + | putint(p, SV_MAPCHANGE); sendstring(toservermap, p); toservermap = @""; putint(p, nextmode); } else { putint(p, SV_POS); putint(p, clientnum); |
︙ |
Modified src/clientextras.mm from [ccc9d61fe8] to [5e3b6ff5ad].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | + + + - + - + - + - - + + - + - + - + - + - + - + - + - + - + - - + + - - - - + + + + + + + + + - + - - - - - - + + + + + + - + + - + - - - - - + - - - - + + - - + + + + - + + + - + - + - - | // clientextras.cpp: stuff that didn't fit in client.cpp or clientgame.cpp :) #include "cube.h" #import "DynamicEntity.h" // render players & monsters // very messy ad-hoc handling of animation frames, should be made more // configurable // D D D D' D D D D' A A' P P' I I' // R, R' E L J J' int frame[] = { 178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0, 40, 1, 162, 162, 67, 168 }; int range[] = { 6, 6, 8, 28, 1, 1, 1, 1, 8, 19, 4, 18, 40, 1, 6, 15, 1, 1, 1, 1 }; void renderclient( |
︙ |
Modified src/clientgame.mm from [1b8431e6e6] to [5f10611541].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | + + + + + + + + - - + + + - + - - - - - - - + + + + + + + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - + + + - + - - + + - + - + - - - + + + + - - + - + - - - - - + + + + + - - - + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + + - + - + - - + + - - + + - - - + + + + - + - - - - - - - + + - + - - - - - - - - + + + + + + + + - - - + + + + - - + + | // clientgame.cpp: core game related stuff #include "cube.h" #import "DynamicEntity.h" int nextmode = 0; // nextmode becomes gamemode after next map load VAR(gamemode, 1, 0, 0); void mode(int n) { addmsg(1, 2, SV_GAMEMODE, nextmode = n); } COMMAND(mode, ARG_1INT) bool intermission = false; DynamicEntity *player1; // our client OFMutableArray *players; // other clients void initPlayers() { |
︙ | |||
258 259 260 261 262 263 264 | 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | - - - + + + - + + - + - - + - - + + - + - + - + - + - + - - + + - - - - - - + + + + + - - - + - - - - - - + + + + + + - + - + - - - - - - - - + + + + + + + + - + - - + + - + - + - - - - - + + + + + - + - + - + - + - + - - - + + + - - - + + + - + - - - - - - + + + + + - - + + - - + - + - + + + - - - + + + + + + + + + + + + + + + + | // connected to server gets2c(); // do this first, so we have most accurate // information when our player moves } otherplayers(); if (!demoplayback) { monsterthink(); |
︙ | |||
490 491 492 493 494 495 496 | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | - - + + + + | conoutf(@"coop sp not supported yet"); } sleepwait = 0; monsterclear(); projreset(); spawncycle = -1; spawnplayer(player1); |
︙ |
Modified src/clients2c.mm from [e5e63c92dd] to [ef18048f8b].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + + | // client processing of the incoming network stream #include "cube.h" #import "DynamicEntity.h" extern int clientnum; extern bool c2sinit, senditemstoserver; extern OFString *toservermap; extern OFString *clientpassword; void neterr(OFString *s) |
︙ | |||
28 29 30 31 32 33 34 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | - + - - - - - + + + + + - + + + - + + - + + - + - - + + + - + - - + | } // update the position of other clients in the game in our world // don't care if he's in the scenery or other players, // just don't overlap with our client void |
︙ | |||
100 101 102 103 104 105 106 | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | + - + - - + - - + + - - - - - - + + + + + - - + - - + + - - - + + + - - + + + + - + | } } if (getint(p) == 1) conoutf(@"server is FULL, disconnecting.."); break; } case SV_POS: { |
︙ | |||
169 170 171 172 173 174 175 | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | - - + + - - + - - - + + + - - + + + - + - - + + - + - - - + + + | stringWithFormat:@"nextmap_%@", getclientmap()]; OFString *map = getalias(nextmapalias); // look up map in the cycle changemap(map != nil ? map : getclientmap()); break; } |
︙ | |||
220 221 222 223 224 225 226 | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | - + - - + + + - + - + - + - - + + - + - + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - + | } case SV_DAMAGE: { int target = getint(p); int damage = getint(p); int ls = getint(p); if (target == clientnum) { |
︙ | |||
344 345 346 347 348 349 350 | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | - - + + - + | case SV_PING: getint(p); break; case SV_PONG: addmsg(0, 2, SV_CLIENTPING, |
︙ |
Modified src/cube.h from [4e3991eb16] to [3f59a3114f].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | + + | // one big bad include file for the whole engine... nasty! #import <ObjFW/ObjFW.h> #define gamma gamma__ #include <SDL2/SDL.h> #undef gamma #include "tools.h" @class DynamicEntity; @interface Cube: OFObject <OFApplicationDelegate> @property (class, readonly, nonatomic) Cube *sharedInstance; @property (readonly, nonatomic) SDL_Window *window; @property (readonly, nonatomic) OFIRI *gameDataIRI, *userDataIRI; @property (nonatomic) bool repeatsKeys; @property (nonatomic) int framesInMap; |
︙ | |||
124 125 126 127 128 129 130 | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - | GUN_FIREBALL, GUN_ICEBALL, GUN_SLIMEBALL, GUN_BITE, NUMGUNS }; |
︙ | |||
277 278 279 280 281 282 283 | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | - - - - - + + + + | // vertex array format struct vertex { float u, v, x, y, z; uchar r, g, b, a; }; |
︙ | |||
312 313 314 315 316 317 318 | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | - - - - - + + + + + + - - + + - - - + + + + - - - + + + + + - - - - - - + + + + + + - - - + | #define PIXELTAB (VIRTW / 12) #define PI (3.1415927f) #define PI2 (2 * PI) // simplistic vector ops #define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z) |
︙ | |||
366 367 368 369 370 371 372 | 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | - + | #define m_noitemsrail (gamemode <= 5) #define m_arena (gamemode >= 8) #define m_tarena (gamemode >= 10) #define m_teammode (gamemode & 1 && gamemode > 2) #define m_sp (gamemode < 0) #define m_dmsp (gamemode == -1) #define m_classicsp (gamemode == -2) |
︙ |
Modified src/editing.mm from [0154fefe79] to [ecc3874fd1].
1 2 3 4 5 6 7 8 9 10 11 12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | + + | // editing.cpp: most map editing commands go here, entity editing commands are // in world.cpp #include "cube.h" #import "DynamicEntity.h" bool editmode = false; // the current selection, used by almost all editing commands // invariant: all code assumes that these are kept inside MINBORD distance of // the edge of the map block sel; |
︙ | |||
48 49 50 51 52 53 54 | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | - + - + | sqr rtex; VAR(editing, 0, 0, 1); void toggleedit() { |
︙ | |||
146 147 148 149 150 151 152 | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | - + - - + + | ? (s->type == FHF ? s->floor - t->vdelta / 4.0f : (float)s->floor) : (s->type == CHF ? s->ceil + t->vdelta / 4.0f : (float)s->ceil); } void cursorupdate() // called every frame from hud { |
︙ | |||
318 319 320 321 322 323 324 | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | - + - + | p[0] = t; curedittex[i] = -1; } } } void |
︙ | |||
598 599 600 601 602 603 604 | 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | - + | } void newent(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) { EDITSEL; @autoreleasepool { |
︙ |
Modified src/entities.mm from [f745b5a428] to [0816ef168b].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 | + | // entities.cpp: map entity related functions (pickup etc.) #include "cube.h" #import "DynamicEntity.h" #import "MapModelInfo.h" vector<entity> ents; static OFString *entmdlnames[] = { @"shells", @"bullets", |
︙ | |||
118 119 120 121 122 123 124 | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | - + - - + + + - + - + - + - + - + - + - + - - + + - - + + - + - + + - - + + + - - + - - - + + - + - + - - - - + + - + - + + - - + + + + - - + - + - + - + - + - + - + - + - + - + | { 150, 150, S_ITEMARMOUR }, { 20000, 30000, S_ITEMPUP }, }; void baseammo(int gun) { |
︙ | |||
282 283 284 285 286 287 288 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | - - + + | case JUMPPAD: { static int lastjumppad = 0; if (lastmillis - lastjumppad < 300) break; lastjumppad = lastmillis; OFVector3D v = OFMakeVector3D((int)(char)ents[n].attr3 / 10.0f, (int)(char)ents[n].attr2 / 10.0f, ents[n].attr1 / 10.0f); |
︙ | |||
305 306 307 308 309 310 311 | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | - - + + - - + + | if (e.type == NOTUSED) continue; if (!ents[i].spawned && e.type != TELEPORT && e.type != JUMPPAD) continue; if (OUTBORD(e.x, e.y)) continue; OFVector3D v = OFMakeVector3D( |
︙ |
Modified src/meson.build from [2625064d57] to [d42ec0e39c].
1 2 3 4 5 6 7 8 9 10 11 12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + | executable('client', [ 'Alias.m', 'Command.mm', 'Cube.mm', 'DynamicEntity.mm', 'Identifier.m', 'KeyMapping.m', 'MD2.mm', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'Projectile.m', |
︙ |
Modified src/monster.mm from [3ac13a2932] to [d6e394fd76].
1 2 3 4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | + - - + + + - + + + - + - + + | // monster.cpp: implements AI for single player monsters, currently client only #include "cube.h" #import "DynamicEntity.h" |
︙ | |||
45 46 47 48 49 50 51 | 50 51 52 53 54 55 56 57 58 59 60 61 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | - + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - + - + - + - - + - + - | @"a hellpig", @"monster/hellpig" }, { GUN_ICEBALL, 12, 250, 1, 0, 10, 400, 6, 18, 18, S_PAINH, S_DEATHH, @"a knight", @"monster/knight" }, { GUN_SLIMEBALL, 15, 100, 1, 0, 200, 400, 2, 13, 10, S_PAIND, S_DEATHD, @"a goblin", @"monster/goblin" }, }; |
︙ | |||
160 161 162 163 164 165 166 | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | - + - - - + + + + - + - - - + + - + - + - - - - + + + + + - + - - - - + + + - - + + - - - - + + + + - - - + + + - - + + - - + + - - + + - - + + - + - + - - + - + - + + - + + - - - - - - + + + + + + + - - - - + + + + - - + + - - + - + - - + + - - - + + - - + - - + + + - - + - - + - + - - + + - - + - + - - + + - - - - + + + + - - + + + - - + + + + | y += dy / (float)steps; i++; } return i >= steps; } bool |
︙ | |||
366 367 368 369 370 371 372 | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | - - + + - + - - - + + - - - + + - - - + + + - - + + - - + + + - - - + + + | nextmonster = lastmillis + 1000; spawnmonster(); } if (monstertotal && !spawnremain && numkilled == monstertotal) endsp(true); |
Modified src/physics.mm from [cbd2b108e1] to [850bd490e8].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | + + - - + + - + - - - - - - - + + + + + + + - + - + - + | // physics.cpp: no physics books were hurt nor consulted in the construction of // this code. All physics computations and constants were invented on the fly // and simply tweaked until they "felt right", and have no basis in reality. // Collision detection is simplistic but very robust (uses discrete steps at // fixed fps). #include "cube.h" #import "DynamicEntity.h" #import "MapModelInfo.h" // collide with player or monster bool |
︙ | |||
50 51 52 53 54 55 56 | 52 53 54 55 56 57 58 59 60 61 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 110 111 112 113 114 | - + - - + + - + - + + - + - - - - - + + + + - - - + + + - - + - + | bs = 1 << mip; return cornertest(mip, x, y, dx, dy, bx, by, bs); } return stest; } void |
︙ | |||
152 153 154 155 156 157 158 | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | - + - + - - + - - + - + - - + + + - - + + + - + - + + + - + + + - - - + + + + + - - + - - - + + + + + - + | hi = ceil; if (floor > lo) lo = floor; if (floor < minfloor) return false; } |
︙ | |||
233 234 235 236 237 238 239 | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | - + - - + + - - + + - - - + + + - - + + - - + - + - - - - - + + + + + + - - + + - + - - - - - + + + + + + - + - - - - - + + + + + + - - - + + + - - - - + + + + + - - - - - - + + + + + + + + - - + - + - - - - + + + + - - + + - - - + + - + - + - - - + + - - + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + + + + + - + | } // main physics routine, moves a player/monster for a curtime step // moveres indicated the physics precision (which is lower for monsters and // multiplayer prediction) local is false for multiplayer prediction void |
Modified src/protos.h from [455fc77430] to [442aaeb8db].
︙ | |||
74 75 76 77 78 79 80 | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | - + + - - - + + + - - + + - + - + - + | extern void disconnect(int onlyclean = 0, int async = 0); extern void toserver(OFString *text); extern void addmsg(int rel, int num, int type, ...); extern bool multiplayer(); extern bool allowedittoggle(); extern void sendpackettoserv(void *packet); extern void gets2c(); |
︙ | |||
187 188 189 190 191 192 193 | 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | - + - - - + + + | extern void writemap(OFString *mname, int msize, uchar *mdata); extern OFData *readmap(OFString *mname); extern void loadgamerest(); extern void incomingdemodata(uchar *buf, int len, bool extras = false); extern void demoplaybackstep(); extern void stop(); extern void stopifrecording(); |
︙ | |||
233 234 235 236 237 238 239 | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | - - - + + + - - + + - + - + | OFString *smapname, int seconds, bool isfull); extern void servermsinit(OFString *master, OFString *sdesc, bool listen); extern void sendmaps(int n, OFString *mapname, int mapsize, uchar *mapdata); extern ENetPacket *recvmap(int n); // weapon extern void selectgun(int a = -1, int b = -1, int c = -1); |
Modified src/renderextras.mm from [4ee74611a3] to [3c937d7f40].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + + | // renderextras.cpp: misc gl render code and the HUD #include "cube.h" #import "DynamicEntity.h" void line(int x1, int y1, float z1, int x2, int y2, float z2) { glBegin(GL_POLYGON); glVertex3f((float)x1, z1, (float)y1); glVertex3f((float)x1, z1, y1 + 0.01f); glVertex3f((float)x2, z2, y2 + 0.01f); |
︙ | |||
325 326 327 328 329 330 331 | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | - + | void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) { readmatrices(); if (editmode) { if (cursordepth == 1.0f) |
︙ | |||
377 378 379 380 381 382 383 | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | - + - + - + | renderscores(); if (!rendermenu()) { glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, 1); glBegin(GL_QUADS); glColor3ub(255, 255, 255); if (crosshairfx) { |
︙ | |||
414 415 416 417 418 419 420 | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | - + - - - + + + - - + - + - - + + | draw_textf(@"wqd %d", 3200, 2460, 2, nquads); draw_textf(@"wvt %d", 3200, 2530, 2, curvert); draw_textf(@"evt %d", 3200, 2600, 2, xtraverts); } glPopMatrix(); |
︙ |
Modified src/rendergl.mm from [f024dcac09] to [6011a74a0d].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + + | // rendergl.cpp: core opengl rendering stuff #include "cube.h" #import "DynamicEntity.h" #ifdef DARWIN # define GL_COMBINE_EXT GL_COMBINE_ARB # define GL_COMBINE_RGB_EXT GL_COMBINE_RGB_ARB # define GL_SOURCE0_RBG_EXT GL_SOURCE0_RGB_ARB # define GL_SOURCE1_RBG_EXT GL_SOURCE1_RGB_ARB # define GL_RGB_SCALE_EXT GL_RGB_SCALE_ARB #endif |
︙ | |||
332 333 334 335 336 337 338 | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | - - - + + + - - - - + + + + - - - + + + - + - + - - - - - + + + + - - + - + - - + + - - + + | }) void transplayer() { glLoadIdentity(); |
︙ |
Modified src/rendermd2.mm from [26b0b7264d] to [21d4efdffc].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 | + | // rendermd2.cpp: loader code adapted from a nehe tutorial #include "cube.h" #import "DynamicEntity.h" #import "MD2.h" #import "MapModelInfo.h" static OFMutableDictionary<OFString *, MD2 *> *mdllookup = nil; static OFMutableArray<MD2 *> *mapmodels = nil; static const int FIRSTMDL = 20; |
︙ | |||
96 97 98 99 100 101 102 | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | - + | void rendermodel(OFString *mdl, int frame, int range, int tex, float rad, float x, float y, float z, float yaw, float pitch, bool teammate, float scale, float speed, int snap, int basetime) { MD2 *m = loadmodel(mdl); |
︙ |
Modified src/renderparticles.mm from [f46610835d] to [1d20594b8c].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + | // renderparticles.cpp #include "cube.h" #import "DynamicEntity.h" const int MAXPARTICLES = 10500; const int NUMPARTCUTOFF = 20; struct particle { OFVector3D o, d; int fade, type; int millis; |
︙ | |||
52 53 54 55 56 57 58 | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | - + | } void render_particles(int time) { if (demoplayback && demotracking) { OFVector3D nom = OFMakeVector3D(0, 0, 0); |
︙ |
Modified src/savegamedemo.mm from [518f13ae58] to [76a6b74abd].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | + + - + - + | // loading and saving of savegames & demos, dumps the spawn state of all // mapents, the full state of all dynents (monsters + player) #include "cube.h" #import "DynamicEntity.h" #ifdef OF_BIG_ENDIAN static const int islittleendian = 0; #else static const int islittleendian = 1; #endif |
︙ | |||
72 73 74 75 76 77 78 | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | - - + | gzputi(-1); gzclose(f); } f = NULL; demorecording = false; demoplayback = false; demoloading = false; |
︙ | |||
98 99 100 101 102 103 104 | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | + - - + + + + + - - - - - - + + + + + + + + + - - - + + + | if (!f) { conoutf(@"could not write %@", IRI.string); return; } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, islittleendian); gzputi(SAVEGAMEVERSION); OFData *data = [player1 dataBySerializing]; |
︙ | |||
159 160 161 162 163 164 165 | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | - + + | gzread(f, buf, 8); if (strncmp(buf, "CUBESAVE", 8)) goto out; if (gzgetc(f) != islittleendian) goto out; // not supporting save->load accross // incompatible architectures simpifies things // a LOT |
︙ | |||
214 215 216 217 218 219 220 | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | + + + - - + + + - - + + - - - - - - - - - + + + + + + + + + + - + - + + | { ents[i].spawned = gzgetc(f) != 0; if (ents[i].type == CARROT && !ents[i].spawned) trigger(ents[i].attr1, ents[i].attr2, true); } restoreserverstate(ents); OFMutableData *data = [OFMutableData dataWithCapacity:DynamicEntity.serializedSize]; [data increaseCountBy:DynamicEntity.serializedSize]; |
︙ | |||
283 284 285 286 287 288 289 | 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | - + + - - - - - - - - - + + + + + + + + + | starttime = lastmillis; ddamage = bdamage = 0; } } COMMAND(record, ARG_1STR) void |
︙ | |||
344 345 346 347 348 349 350 | 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | - + | COMMAND(demo, ARG_1STR) void stopreset() { conoutf(@"demo stopped (%d msec elapsed)", lastmillis - starttime); stop(); |
︙ | |||
372 373 374 375 376 377 378 | 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | - + - - - - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + + + - + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - - - - + + + - - + - - - + + + + - - - + + - - - - - + + + + + + + - - + + - - - + + + - + - - - - + + + + - - + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + | void startdemo() { democlientnum = gzgeti(); demoplayback = true; starttime = lastmillis; conoutf(@"now playing demo"); |
Modified src/sound.mm from [4f8b2c4c47] to [f6d08d4aed].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + + | // sound.cpp: uses fmod on windows and sdl_mixer on unix (both had problems on // the other platform) #include "cube.h" #import "DynamicEntity.h" // #ifndef _WIN32 // NOTE: fmod not being supported for the moment as it does // not allow stereo pan/vol updating during playback #define USE_MIXER // #endif VARP(soundvol, 0, 255, 255); |
︙ | |||
169 170 171 172 173 174 175 | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | - + + - + - - - - + + + - - | VAR(stereo, 0, 1, 1); static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; if (loc) { |
︙ |
Modified src/weapon.mm from [652afaa3f5] to [c57ce4ac4b].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 | + | // weapon.cpp: all shooting and effects code #include "cube.h" #import "DynamicEntity.h" #import "Projectile.h" static const int MONSTERDAMAGEFACTOR = 4; static const int SGRAYS = 20; static const float SGSPREAD = 2; static OFVector3D sg[SGRAYS]; |
︙ | |||
26 27 28 29 30 31 32 | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - - + + - + - + - + - + - + - + - + - + | void selectgun(int a, int b, int c) { if (a < -1 || b < -1 || c < -1 || a >= NUMGUNS || b >= NUMGUNS || c >= NUMGUNS) return; |
︙ | |||
81 82 83 84 85 86 87 | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | - + - + - - - + + + - - - - + + + + - - + + - + - + - + - - + + + - - + + + - + - + - + - + - - - + + + + + + - - + + - - - - - - + + + + + + + + + + - + - + - - + + - + - - + - - - - + + + - - - - + + + + + - + - + - + - + - - + + - + + - + - + - - + + - + - + - + - - + + - - + + - - - + + + - - + + - - - + + + - - - - + + + + - + - + - + - - - + + + - + - + + - + - - + - - - + + - - + + + - + | sg[i] = to; vadd(sg[i], r); } } // if lineseg hits entity bounding box bool |
Modified src/world.mm from [2ffb0794b1] to [1a4fc65de4].
1 2 3 4 5 6 7 8 9 10 11 12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | + + + + - + - | // world.cpp: core map management stuff #include "cube.h" #import "DynamicEntity.h" extern OFString *entnames[]; // lookup from map entities above to strings sqr *world = NULL; int sfactor, ssize, cubicsize, mipsize; header hdr; // set all cubes with "tag" to space, if tag is 0 then reset ALL tagged cubes // according to type void |
︙ | |||
259 260 261 262 263 264 265 | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | - + | float bdist = 99999; loopv(ents) { entity &e = ents[i]; if (e.type == NOTUSED) continue; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); |
︙ | |||
341 342 343 344 345 346 347 | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | - + | case MAPMODEL: e.attr4 = e.attr3; e.attr3 = e.attr2; case MONSTER: case TELEDEST: e.attr2 = (uchar)e.attr1; case PLAYERSTART: |
︙ |
Modified src/worldlight.mm from [ccc85287d7] to [9b1a521652].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + | // worldlight.cpp #include "cube.h" #import "DynamicEntity.h" extern bool hasoverbright; VAR(lightscale, 1, 4, 100); void lightray(float bx, float by, |
︙ | |||
197 198 199 200 201 202 203 | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | - + - + | blockpaste(*backup); free(backup); } } void dodynlight(const OFVector3D &vold, const OFVector3D &v, int reach, int strength, |
︙ |
Modified src/worldocull.mm from [fabee6f557] to [8d9314d707].
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | + + | // worldocull.cpp: occlusion map and occlusion test #include "cube.h" #import "DynamicEntity.h" #define NUMRAYS 512 float rdist[NUMRAYS]; bool ocull = true; float odist = 256; void |
︙ | |||
22 23 24 25 26 27 28 | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | - + - - + + | computeraytable(float vx, float vy) { if (!ocull) return; odist = getvar(@"fog") * 1.5f; |
︙ |
Modified src/worldrender.mm from [b1342f3226] to [f6cb50b391].
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | + + | // worldrender.cpp: goes through all cubes in top down quad tree fashion, // determines what has to be rendered and how (depending on neighbouring cubes), // then calls functions in rendercubes.cpp #include "cube.h" #import "DynamicEntity.h" void render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d1, sqr *d2, bool topleft) { if (SOLID(o) || o->type == SEMISOLID) { float c1 = s->floor; float c2 = s->floor; |
︙ | |||
131 132 133 134 135 136 137 | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | - + + - + - | int ry = vyy + lodbot; float fsize = (float)(1 << mip); for (int ox = x; ox < xs; ox++) { // first collect occlusion information for this block for (int oy = y; oy < ys; oy++) { SWS(w, ox, oy, sz)->occluded = |
︙ |