Comment: | Convert entity to a class |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
4b002822f954056510cbb1f85d768778 |
User & Date: | js on 2025-03-20 16:04:35 |
Other Links: | manifest | tags |
2025-03-20
| ||
16:36 | Convert server_entity to a class check-in: 21584a40b6 user: js tags: trunk | |
16:04 | Convert entity to a class check-in: 4b002822f9 user: js tags: trunk | |
13:21 | Make more use of convenience methods check-in: 89fbd7a152 user: js tags: trunk | |
Modified src/Cube.mm from [fe88d055bb] to [91778984c2].
︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | + | createDirectoryAtIRI: [_userDataIRI IRIByAppendingPathComponent:@"savegames"] createParents:true]; if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | par) < 0) fatal(@"Unable to initialize SDL"); initEntities(); initPlayers(); log(@"net"); if (enet_initialize() < 0) fatal(@"Unable to initialise network module"); initclient(); |
︙ |
Added src/Entity.h version [6a40859f40].
Added src/Entity.m version [54155c553d].
Added src/PersistentEntity.h version [1383bfd2c4].
Added src/PersistentEntity.m version [2ab320312c].
Modified src/clientgame.mm from [bec4825c49] to [a964a181aa].
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 | + | // clientgame.cpp: core game related stuff #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "OFString+Cube.h" int nextmode = 0; // nextmode becomes gamemode after next map load VAR(gamemode, 1, 0, 0); void mode(int n) |
︙ |
Modified src/clients2c.mm from [1561f54e4a] to [84894b97fe].
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 | + | // client processing of the incoming network stream #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" extern int clientnum; extern bool c2sinit, senditemstoserver; extern OFString *toservermap; extern OFString *clientpassword; void |
︙ | |||
276 277 278 279 280 281 282 | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | - + | setspawn(getint(p), false); getint(p); break; case SV_ITEMSPAWN: { uint i = getint(p); setspawn(i, true); |
︙ | |||
324 325 326 327 328 329 330 | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | + - - + + + + + + | } break; } case SV_EDITENT: // coop edit of ent { uint i = getint(p); |
︙ |
Modified src/cube.h from [63027fcfcd] to [b293c88539].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | + | // 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" #define _MAXDEFSTR 260 @class Entity; @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; |
︙ | |||
72 73 74 75 76 77 78 | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | - - - - - - - - - - - - | MAPMODEL, // attr1 = angle, attr2 = idx MONSTER, // attr1 = angle, attr2 = monstertype CARROT, // attr1 = tag, attr2 = type JUMPPAD, // attr1 = zpush, attr2 = ypush, attr3 = xpush MAXENTTYPES }; |
︙ | |||
260 261 262 263 264 265 266 | 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | - + | extern int sfactor, ssize; // ssize = 2^sfactor extern int cubicsize, mipsize; // cubicsize = ssize^2 // special client ent that receives input and acts as camera extern DynamicEntity *player1; // all the other clients (in multiplayer) extern OFMutableArray *players; extern bool editmode; |
︙ |
Modified src/entities.mm from [c332d89e7c] to [e562f26211].
1 2 3 4 5 6 7 | 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 | + - + + + + + + + - + - - - + + | // entities.cpp: map entity related functions (pickup etc.) #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "MapModelInfo.h" |
︙ | |||
295 296 297 298 299 300 301 | 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 | - - + - + + - - - + + + + + - + + - + + - - + + - - - - + + + + + - + - + | } void checkitems() { if (editmode) return; |
Modified src/meson.build from [7a5be72f65] to [ded2471dd3].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | + + | executable('client', [ 'Alias.m', 'Client.mm', 'Command.mm', 'ConsoleLine.m', 'Cube.mm', 'DynamicEntity.mm', 'Entity.m', 'Identifier.m', 'KeyMapping.m', 'MD2.mm', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'OFString+Cube.mm', 'PersistentEntity.m', 'Projectile.m', 'ResolverResult.mm', 'ResolverThread.mm', 'ServerInfo.mm', 'Variable.mm', 'clients.mm', 'clientextras.mm', |
︙ |
Modified src/monster.mm from [d6e394fd76] to [7bb8f140a9].
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 | + | // monster.cpp: implements AI for single player monsters, currently client only #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" static OFMutableArray<DynamicEntity *> *monsters; static int nextmonster, spawnremain, numkilled, monstertotal, mtimestart; VARF(skill, 1, 3, 10, conoutf(@"skill is now %d", skill)); OFArray<DynamicEntity *> * |
︙ | |||
117 118 119 120 121 122 123 | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | - - - - - + + + + + + + + | monstertotal = 0; spawnremain = 0; if (m_dmsp) { nextmonster = mtimestart = lastmillis + 10000; monstertotal = spawnremain = gamemode < 0 ? skill * 10 : 0; } else if (m_classicsp) { mtimestart = lastmillis; |
︙ | |||
373 374 375 376 377 378 379 | 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 | - + - - + - + + - + + - + - + | spawnmonster(); } if (monstertotal && !spawnremain && numkilled == monstertotal) endsp(true); // equivalent of player entity touch, but only teleports are used |
︙ |
Modified src/physics.mm from [850bd490e8] to [c9005101f7].
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 | + | // 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 "Entity.h" #import "MapModelInfo.h" // collide with player or monster bool plcollide( DynamicEntity *d, DynamicEntity *o, float &headspace, float &hi, float &lo) { |
︙ | |||
54 55 56 57 58 59 60 | 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 | - + - - + + + | } return stest; } void mmcollide(DynamicEntity *d, float &hi, float &lo) // collide with a mapmodel { |
︙ |
Modified src/protos.h from [ca691ec5c9] to [79ed2ad413].
︙ | |||
117 118 119 120 121 122 123 | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | - + | extern void remip(block &b, int level = 0); extern void remipmore(block &b, int level = 0); extern int closestent(); extern int findentity(int type, int index = 0); extern void trigger(int tag, int type, bool savegame); extern void resettagareas(); extern void settagareas(); |
︙ | |||
223 224 225 226 227 228 229 | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | - + | extern void localdisconnect(); extern void localclienttoserver(struct _ENetPacket *); extern void serverslice(int seconds, unsigned int timeout); extern void putint(uchar *&p, int n); extern int getint(uchar *&p); extern void sendstring(OFString *t, uchar *&p); extern void startintermission(); |
︙ | |||
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | + | extern void monsterthink(); extern void monsterrender(); extern OFArray<DynamicEntity *> *getmonsters(); extern void monsterpain(DynamicEntity *m, int damage, DynamicEntity *d); extern void endsp(bool allkilled); // entities extern void initEntities(); extern void renderents(); extern void putitems(uchar *&p); extern void checkquad(int time); extern void checkitems(); extern void realpickup(int n, DynamicEntity *d); extern void renderentities(); extern void resetspawns(); extern void setspawn(uint i, bool on); extern void teleport(int n, DynamicEntity *d); extern void baseammo(int gun); // rndmap extern void perlinarea(block &b, int scale, int seed, int psize); |
Modified src/renderextras.mm from [0275a674d6] to [32dfc98d1d].
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 | + | // renderextras.cpp: misc gl render code and the HUD #include "cube.h" #import "DynamicEntity.h" #import "Entity.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); |
︙ | |||
171 172 173 174 175 176 177 178 | 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 | + - + + - - - + + + + - + | @"?", @"?", @"?", @"?", @"?", }; // show sparkly thingies for map entities in edit mode void |
︙ |
Modified src/savegamedemo.mm from [b5a43a0cf0] to [58839045b8].
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 | + | // 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" #import "Entity.h" #ifdef OF_BIG_ENDIAN static const int islittleendian = 0; #else static const int islittleendian = 1; #endif |
︙ | |||
105 106 107 108 109 110 111 | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | - - + + + | OFData *data = [player1 dataBySerializing]; gzputi(data.count); char map[_MAXDEFSTR] = { 0 }; memcpy(map, getclientmap().UTF8String, min(getclientmap().UTF8StringLength, _MAXDEFSTR - 1)); gzwrite(f, map, _MAXDEFSTR); gzputi(gamemode); |
︙ | |||
201 202 203 204 205 206 207 | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | - + - - - - - + + + + + + + | void loadgamerest() { if (demoplayback || !f) return; |
︙ |
Modified src/server.mm from [1804a617a4] to [69c5d759fc].
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 | 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 | + + - + - | // server.cpp: little more than enhanced multicaster // runs dedicated or as client coroutine #include "cube.h" #import "Client.h" #import "Entity.h" enum { ST_EMPTY, ST_LOCAL, ST_TCPIP }; static OFMutableArray<Client *> *clients; int maxclients = 8; static OFString *smapname; // server side version of "entity" type struct server_entity { bool spawned; int spawnsecs; }; vector<server_entity> sents; // true when map has changed and waiting for clients to send item bool notgotitems = true; int mode = 0; // hack: called from savegame code, only works in SP void |
︙ |
Modified src/world.mm from [2ac8b85a8f] to [ffa7840406].
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 | + | // world.cpp: core map management stuff #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" extern OFString *entnames[]; // lookup from map entities above to strings sqr *world = NULL; int sfactor, ssize, cubicsize, mipsize; header hdr; |
︙ | |||
49 50 51 52 53 54 55 | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | + + - + + + | { settag(0, 0); } // reset for editing or map saving void settagareas() { settag(0, 1); [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { |
︙ | |||
252 253 254 255 256 257 258 | 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 | + - - - + + + - - + - + + - - + + | } int closestent() // used for delent and edit mode ent display { if (noteditmode()) return -1; |
︙ | |||
315 316 317 318 319 320 321 | 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 | - + - - + + + + + + + + + + + - + + - + + + - + + - - - + + - + - - + + - + - + - - + + - - - + + + + - + | findtype(OFString *what) { loopi(MAXENTTYPES) if ([what isEqual:entnames[i]]) return i; conoutf(@"unknown entity type \"%@\"", what); return NOTUSED; } |
︙ | |||
470 471 472 473 474 475 476 | 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 | - - - - + + + + - + | if (copy) { loop(x, ssize / 2) loop(y, ssize / 2) { *S(x + ssize / 4, y + ssize / 4) = *SWS(oldworld, x, y, ssize / 2); } |
︙ |
Modified src/worldio.mm from [1dbc40dfe7] to [823b65f982].
1 2 3 4 5 6 7 8 9 10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | + + + + + + + + + | // worldio.cpp: loading & saving of maps and savegames #include "cube.h" #import "Entity.h" struct persistent_entity { short x, y, z; // cube aligned position short attr1; uchar type; // type is one of the above uchar attr2, attr3, attr4; }; void backup(OFString *name, OFString *backupname) { [OFFileManager.defaultManager removeItemAtPath:backupname]; [OFFileManager.defaultManager moveItemAtPath:name toPath:backupname]; } |
︙ | |||
169 170 171 172 173 174 175 | 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 | + - + + - + - - - + + + | gzopen([cgzname cStringWithEncoding:OFLocale.encoding], "wb9"); if (!f) { conoutf(@"could not write map to %@", cgzname); return; } hdr.version = MAPVERSION; hdr.numents = 0; for (Entity *e in ents) |
︙ | |||
269 270 271 272 273 274 275 | 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 | - + - - - - + + + + + + + + + + + + + + + | fatal(@"illegal map size"); if (hdr.version >= 4) { gzread(f, &hdr.waterlevel, sizeof(int) * 16); endianswap(&hdr.waterlevel, sizeof(int), 16); } else { hdr.waterlevel = -100000; } |
︙ |
Modified src/worldlight.mm from [05fab5d192] to [a6b73ab397].
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 | + + + - + - | // worldlight.cpp #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "PersistentEntity.h" extern bool hasoverbright; VAR(lightscale, 1, 4, 100); // done in realtime, needs to be fast void |
︙ | |||
117 118 119 120 121 122 123 | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | - + | y += stepy; l -= stepl; } } } void |
︙ | |||
171 172 173 174 175 176 177 | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | - + - - - | { loop(x, ssize) loop(y, ssize) { sqr *s = S(x, y); s->r = s->g = s->b = 10; } |
︙ | |||
232 233 234 235 236 237 238 | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | - - + + + + + + + | dlights = [[OFMutableData alloc] initWithItemSize:sizeof(block *)]; // backup area before rendering in dynlight block *copy = blockcopy(b); [dlights addItem:©]; |
︙ |