Overview
Comment: | Avoid pointless pointers
Passing OFVector3D by reference is annoying and is worse at passing via registers. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
304230c1e18fc15a2e66b01bbc1727d1 |
User & Date: | js on 2025-03-23 21:52:54 |
Other Links: | manifest | tags |
Context
2025-03-23
| ||
22:14 | Fix wrong argument order for calculating distance check-in: 75095b4f6e user: js tags: trunk | |
21:52 | Avoid pointless pointers check-in: 304230c1e1 user: js tags: trunk | |
21:31 | Remove vdist check-in: 6259424802 user: js tags: trunk | |
Changes
Modified src/Monster.m from [f00a1d74b4] to [df6f0d84fe].
︙ | ︙ | |||
329 330 331 332 333 334 335 | case M_AIMING: // this state is the delay between wanting to shoot and actually // firing if (self.trigger < lastmillis) { self.lastAction = 0; self.attacking = true; | | < | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | case M_AIMING: // this state is the delay between wanting to shoot and actually // firing if (self.trigger < lastmillis) { self.lastAction = 0; self.attacking = true; shoot(self, self.attackTarget); [self transitionWithState:M_ATTACKING moving:0 n:600 r:0]; } break; |
︙ | ︙ |
Modified src/clientgame.m from [3ae039157a] to [12fef2cf63].
︙ | ︙ | |||
159 160 161 162 163 164 165 | if (m_arena) arenarespawn(); moveprojectiles((float)curtime); demoplaybackstep(); if (!demoplayback) { if (getclientnum() >= 0) // only shoot when connected to server | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | if (m_arena) arenarespawn(); moveprojectiles((float)curtime); demoplaybackstep(); if (!demoplayback) { if (getclientnum() >= 0) // only shoot when connected to server shoot(player1, worldpos); // do this first, so we have most accurate information // when our player moves gets2c(); } otherplayers(); if (!demoplayback) { [Monster thinkAll]; |
︙ | ︙ |
Modified src/clients2c.m from [15c84f7e82] to [be4039eb8e].
︙ | ︙ | |||
217 218 219 220 221 222 223 | s.x = getint(&p) / DMF; s.y = getint(&p) / DMF; s.z = getint(&p) / DMF; e.x = getint(&p) / DMF; e.y = getint(&p) / DMF; e.z = getint(&p) / DMF; if (gun == GUN_SG) | | | | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | s.x = getint(&p) / DMF; s.y = getint(&p) / DMF; s.z = getint(&p) / DMF; e.x = getint(&p) / DMF; e.y = getint(&p) / DMF; e.z = getint(&p) / DMF; if (gun == GUN_SG) createrays(s, e); shootv(gun, s, e, d, false); break; } case SV_DAMAGE: { int target = getint(&p); int damage = getint(&p); int ls = getint(&p); |
︙ | ︙ |
Modified src/protos.h from [6ea87debb4] to [e6df6c1853].
︙ | ︙ | |||
124 125 126 127 128 129 130 | extern void resettagareas(); extern void settagareas(); extern Entity *newentity( int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4); // worldlight extern void calclight(); | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | extern void resettagareas(); extern void settagareas(); extern Entity *newentity( int x, int y, int z, OFString *what, int v1, int v2, int v3, int v4); // worldlight extern void calclight(); extern void dodynlight(OFVector3D vold, OFVector3D v, int reach, int strength, DynamicEntity *owner); extern void cleardlights(); extern struct block *blockcopy(const struct block *b); extern void blockpaste(const struct block *b); // worldrender extern void render_world(float vx, float vy, float vh, int yaw, int pitch, float widef, int w, int h); |
︙ | ︙ | |||
165 166 167 168 169 170 171 | extern void pruneundos(int maxremain); // renderextras extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void box(const struct block *b, float z1, float z2, float z3, float z4); extern void dot(int x, int y, float z); extern void linestyle(float width, int r, int g, int b); | | | | | < | | 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 | extern void pruneundos(int maxremain); // renderextras extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void box(const struct block *b, float z1, float z2, float z3, float z4); extern void dot(int x, int y, float z); extern void linestyle(float width, int r, int g, int b); extern void newsphere(OFVector3D o, float max, int type); extern void renderspheres(int time); extern void gl_drawhud( int w, int h, int curfps, int nquads, int curvert, bool underwater); extern void readdepth(int w, int h); extern void blendbox(int x1, int y1, int x2, int y2, bool border); extern void damageblend(int n); // renderparticles extern void setorient(OFVector3D r, OFVector3D u); extern void particle_splash(int type, int num, int fade, OFVector3D p); extern void particle_trail(int type, int fade, OFVector3D from, OFVector3D to); extern void render_particles(int time); // worldio extern void save_world(OFString *fname); extern void load_world(OFString *mname); extern void writemap(OFString *mname, int msize, unsigned char *mdata); extern OFData *readmap(OFString *mname); extern void loadgamerest(); extern void incomingdemodata(unsigned char *buf, int len, bool extras); extern void demoplaybackstep(); extern void stop(); extern void stopifrecording(); extern void demodamage(int damage, OFVector3D o); extern void demoblend(int damage); // physics extern void moveplayer(DynamicEntity *pl, int moveres, bool local); extern bool collide(DynamicEntity *d, bool spawn, float drop, float rise); extern void entinmap(DynamicEntity *d); extern void setentphysics(int mml, int mmr); |
︙ | ︙ | |||
237 238 239 240 241 242 243 | extern void servermsinit(OFString *master, OFString *sdesc, bool listen); extern void sendmaps( int n, OFString *mapname, int mapsize, unsigned char *mapdata); extern ENetPacket *recvmap(int n); // weapon extern void selectgun(int a, int b, int c); | | | | | | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | extern void servermsinit(OFString *master, OFString *sdesc, bool listen); extern void sendmaps( int n, OFString *mapname, int mapsize, unsigned char *mapdata); extern ENetPacket *recvmap(int n); // weapon extern void selectgun(int a, int b, int c); extern void shoot(DynamicEntity *d, OFVector3D to); extern void shootv( int gun, OFVector3D from, OFVector3D to, DynamicEntity *d, bool local); extern void createrays(OFVector3D from, OFVector3D to); extern void moveprojectiles(float time); extern void projreset(); extern OFString *playerincrosshair(); extern int reloadtime(int gun); // entities extern void initEntities(); |
︙ | ︙ |
Modified src/renderextras.m from [e6c4962238] to [ace19c9caa].
︙ | ︙ | |||
89 90 91 92 93 94 95 | int type; struct sphere *next; }; static struct sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL; bool sinit = false; void | | | | 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 | int type; struct sphere *next; }; static struct sphere spheres[MAXSPHERES], *slist = NULL, *sempty = NULL; bool sinit = false; void newsphere(OFVector3D o, float max, int type) { if (!sinit) { for (int i = 0; i < MAXSPHERES; i++) { spheres[i].next = sempty; sempty = &spheres[i]; } sinit = true; } if (sempty) { struct sphere *p = sempty; sempty = p->next; p->o = o; p->max = max; p->size = 1; p->type = type; p->next = slist; slist = p; } } |
︙ | ︙ | |||
185 186 187 188 189 190 191 | if (!editmode) return; for (Entity *e in ents) { if (e.type == NOTUSED) continue; | < | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | if (!editmode) return; for (Entity *e in ents) { if (e.type == NOTUSED) continue; particle_splash(2, 2, 40, OFMakeVector3D(e.x, e.y, e.z)); } int e = closestent(); if (e >= 0) { Entity *c = ents[e]; closeent = [OFString stringWithFormat:@"closest entity = %@ (%d, %d, " |
︙ | ︙ | |||
268 269 270 271 272 273 274 | gluUnProject(w / 2, h / 2, depthcorrect(cursordepth), mm, pm, viewport, &worldx, &worldz, &worldy); worldpos.x = (float)worldx; worldpos.y = (float)worldy; worldpos.z = (float)worldz; OFVector3D r = OFMakeVector3D(mm[0], mm[4], mm[8]); OFVector3D u = OFMakeVector3D(mm[1], mm[5], mm[9]); | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | gluUnProject(w / 2, h / 2, depthcorrect(cursordepth), mm, pm, viewport, &worldx, &worldz, &worldy); worldpos.x = (float)worldx; worldpos.y = (float)worldy; worldpos.z = (float)worldz; OFVector3D r = OFMakeVector3D(mm[0], mm[4], mm[8]); OFVector3D u = OFMakeVector3D(mm[1], mm[5], mm[9]); setorient(r, u); } void drawicon(float tx, float ty, int x, int y) { glBindTexture(GL_TEXTURE_2D, 5); glBegin(GL_QUADS); |
︙ | ︙ |
Modified src/renderparticles.m from [dcdd211b54] to [41bd950ef0].
︙ | ︙ | |||
14 15 16 17 18 19 20 | }; struct particle particles[MAXPARTICLES], *parlist = NULL, *parempty = NULL; bool parinit = false; VARP(maxparticles, 100, 2000, MAXPARTICLES - 500); static void | | | | | | | | < < | < > | 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 | }; struct particle particles[MAXPARTICLES], *parlist = NULL, *parempty = NULL; bool parinit = false; VARP(maxparticles, 100, 2000, MAXPARTICLES - 500); static void newparticle(OFVector3D o, OFVector3D d, int fade, int type) { if (!parinit) { for (int i = 0; i < MAXPARTICLES; i++) { particles[i].next = parempty; parempty = &particles[i]; } parinit = true; } if (parempty) { struct particle *p = parempty; parempty = p->next; p->o = o; p->d = d; p->fade = fade; p->type = type; p->millis = lastmillis; p->next = parlist; parlist = p; } } VAR(demotracking, 0, 0, 1); VARP(particlesize, 20, 100, 500); OFVector3D right, up; void setorient(OFVector3D r, OFVector3D u) { right = r; up = u; } void render_particles(int time) { if (demoplayback && demotracking) newparticle( player1.origin, OFMakeVector3D(0, 0, 0), 100000000, 8); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); glDisable(GL_FOG); struct parttype { |
︙ | ︙ | |||
130 131 132 133 134 135 136 | glEnable(GL_FOG); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } void | | | | | | < | | | 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 | glEnable(GL_FOG); glDisable(GL_BLEND); glDepthMask(GL_TRUE); } void particle_splash(int type, int num, int fade, OFVector3D p) { for (int i = 0; i < num; i++) { const int radius = type == 5 ? 50 : 150; int x, y, z; do { x = rnd(radius * 2) - radius; y = rnd(radius * 2) - radius; z = rnd(radius * 2) - radius; } while (x * x + y * y + z * z > radius * radius); OFVector3D d = OFMakeVector3D(x, y, z); newparticle(p, d, rnd(fade * 3), type); } } void particle_trail(int type, int fade, OFVector3D s, OFVector3D e) { float d = OFDistanceOfVectors3D(s, e); OFVector3D v = OFSubtractVectors3D(s, e); v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f)); for (int i = 0; i < ((int)d * 2); i++) { s = OFAddVectors3D(s, v); OFVector3D d = OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5); newparticle(s, d, rnd(fade) + fade, type); } } |
Modified src/savegamedemo.m from [e40f20042f] to [16ee4d908b].
︙ | ︙ | |||
281 282 283 284 285 286 287 | conoutf(@"started recording demo to %@", IRI.string); demorecording = true; starttime = lastmillis; ddamage = bdamage = 0; })) void | | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | conoutf(@"started recording demo to %@", IRI.string); demorecording = true; starttime = lastmillis; ddamage = bdamage = 0; })) void demodamage(int damage, OFVector3D o) { ddamage = damage; dorig = o; } void demoblend(int damage) { bdamage = damage; } |
︙ | ︙ | |||
439 440 441 442 443 444 445 | target.ammo[i] = gzget(); target.state = gzget(); target.lastMove = playbacktime; if ((bdamage = gzgeti())) damageblend(bdamage); if ((ddamage = gzgeti())) { gzgetv(&dorig); | | | 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | target.ammo[i] = gzget(); target.state = gzget(); target.lastMove = playbacktime; if ((bdamage = gzgeti())) damageblend(bdamage); if ((ddamage = gzgeti())) { gzgetv(&dorig); particle_splash(3, ddamage, 1000, dorig); } // FIXME: set more client state here } // insert latest copy of player into history if (extras && (playerhistory.count == 0 || |
︙ | ︙ |
Modified src/weapon.m from [51629f2c3a] to [7fa0099398].
︙ | ︙ | |||
67 68 69 70 71 72 73 | selectgun((a1.length > 0 ? a1.cube_intValue : -1), (a2.length > 0 ? a2.cube_intValue : -1), (a3.length > 0 ? a3.cube_intValue : -1)); }) // create random spread of rays for the shotgun void | | | | | < < | | > | < | | < | | | | | | | | | | | | | | | | 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 | selectgun((a1.length > 0 ? a1.cube_intValue : -1), (a2.length > 0 ? a2.cube_intValue : -1), (a3.length > 0 ? a3.cube_intValue : -1)); }) // create random spread of rays for the shotgun void createrays(OFVector3D from, OFVector3D to) { float dist = OFDistanceOfVectors3D(from, to); float f = dist * SGSPREAD / 1000; for (int i = 0; i < SGRAYS; i++) #define RNDD (rnd(101) - 50) * f sg[i] = OFAddVectors3D(to, OFMakeVector3D(RNDD, RNDD, RNDD)); } // if lineseg hits entity bounding box static bool intersect(DynamicEntity *d, OFVector3D from, OFVector3D to) { OFVector3D v = OFSubtractVectors3D(to, from); OFVector3D w = OFSubtractVectors3D(d.origin, from); float c1 = OFDotProductOfVectors3D(w, v); OFVector3D p; if (c1 <= 0) p = from; else { float c2 = OFDotProductOfVectors3D(v, v); if (c2 <= c1) p = to; else { v = OFMultiplyVector3D(v, c1 / c2); p = OFAddVectors3D(v, from); } } return (p.x <= d.origin.x + d.radius && p.x >= d.origin.x - d.radius && p.y <= d.origin.y + d.radius && p.y >= d.origin.y - d.radius && p.z <= d.origin.z + d.aboveEye && p.z >= d.origin.z - d.eyeHeight); } OFString * playerincrosshair() { if (demoplayback) return NULL; for (id player in players) { if (player == [OFNull null]) continue; OFVector3D o = player1.origin; if (intersect(player, o, worldpos)) return [player name]; } return nil; } #define MAXPROJ 100 static Projectile *projs[MAXPROJ]; void projreset() { for (size_t i = 0; i < MAXPROJ; i++) projs[i].inuse = false; } void newprojectile(OFVector3D from, OFVector3D to, float speed, bool local, DynamicEntity *owner, int gun) { for (size_t i = 0; i < MAXPROJ; i++) { Projectile *p = projs[i]; if (p == nil) projs[i] = p = [Projectile projectile]; if (p.inuse) continue; p.inuse = true; p.o = from; p.to = to; p.speed = speed; p.local = local; p.owner = owner; p.gun = gun; return; } } static void hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at) { OFVector3D o = d.origin; if (d == player1) selfdamage(damage, at == player1 ? -1 : -2, at); else if ([d isKindOfClass:Monster.class]) [d incurDamage:damage fromEntity:at]; else { addmsg(1, 4, SV_DAMAGE, target, damage, d.lifeSequence); playsound(S_PAIN1 + rnd(5), &o); } particle_splash(3, damage, 1000, o); demodamage(damage, o); } const float RL_RADIUS = 5; const float RL_DAMRAD = 7; // hack static void radialeffect( DynamicEntity *o, OFVector3D v, int cn, int qdam, DynamicEntity *at) { if (o.state != CS_ALIVE) return; OFVector3D origin = o.origin; float dist = OFDistanceOfVectors3D(v, origin); OFVector3D temp = OFSubtractVectors3D(v, origin); dist -= 2; // account for eye distance imprecision if (dist < RL_DAMRAD) { if (dist < 0) dist = 0; int damage = (int)(qdam * (1 - (dist / RL_DAMRAD))); hit(cn, damage, o, at); temp = OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800); o.velocity = OFAddVectors3D(o.velocity, temp); } } static void splash(Projectile *p, OFVector3D v, OFVector3D vold, int notthisplayer, int notthismonster, int qdam) { particle_splash(0, 50, 300, v); p.inuse = false; if (p.gun != GUN_RL) { playsound(S_FEXPLODE, &v); // no push? } else { playsound(S_RLHIT, &v); newsphere(v, RL_RADIUS, 0); dodynlight(vold, v, 0, 0, p.owner); if (!p.local) return; radialeffect(player1, v, -1, qdam, p.owner); |
︙ | ︙ | |||
241 242 243 244 245 246 247 | if (i != notthismonster) radialeffect(monster, v, i, qdam, p.owner); }]; } } static inline void | | | | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | if (i != notthismonster) radialeffect(monster, v, i, qdam, p.owner); }]; } } static inline void projdamage( DynamicEntity *o, Projectile *p, OFVector3D v, int i, int im, int qdam) { if (o.state != CS_ALIVE) return; OFVector3D po = p.o; if (intersect(o, po, v)) { splash(p, v, po, i, im, qdam); hit(i, qdam, o, p.owner); } } void moveprojectiles(float time) { |
︙ | ︙ | |||
277 278 279 280 281 282 283 | if (time > dtime) dtime = time; v = OFMultiplyVector3D(v, time / dtime); v = OFAddVectors3D(v, p.o); if (p.local) { for (id player in players) if (player != [OFNull null]) | | | | < < | | | | | < | | | 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 | if (time > dtime) dtime = time; v = OFMultiplyVector3D(v, time / dtime); v = OFAddVectors3D(v, p.o); if (p.local) { for (id player in players) if (player != [OFNull null]) projdamage(player, p, v, i, -1, qdam); if (p.owner != player1) projdamage(player1, p, v, -1, -1, qdam); for (Monster *monster in Monster.monsters) if (!vreject(monster.origin, v, 10.0f) && monster != p.owner) projdamage(monster, p, v, -1, i, qdam); } if (p.inuse) { if (time == dtime) splash(p, v, p.o, -1, -1, qdam); else { if (p.gun == GUN_RL) { dodynlight(p.o, v, 0, 255, p.owner); particle_splash(5, 2, 200, v); } else { particle_splash(1, 1, 200, v); particle_splash( guns[p.gun].part, 1, 1, v); } } } p.o = v; } } // create visual effect from a shot void shootv(int gun, OFVector3D from, OFVector3D to, DynamicEntity *d, bool local) { OFVector3D loc = d.origin; playsound(guns[gun].sound, d == player1 ? NULL : &loc); int pspeed = 25; switch (gun) { case GUN_FIST: break; case GUN_SG: { for (int i = 0; i < SGRAYS; i++) particle_splash(0, 5, 200, sg[i]); break; } case GUN_CG: particle_splash(0, 100, 250, to); // particle_trail(1, 10, from, to); break; |
︙ | ︙ | |||
349 350 351 352 353 354 355 | particle_trail(1, 500, from, to); break; } } void hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, | | | | | | | | | | | | | | | 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 | particle_trail(1, 500, from, to); break; } } void hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at, OFVector3D from, OFVector3D to) { hit(target, damage, d, at); float dist = OFDistanceOfVectors3D(from, to); OFVector3D v = OFSubtractVectors3D(from, to); v = OFMultiplyVector3D(v, damage / dist / 50); d.velocity = OFAddVectors3D(d.velocity, v); } void raydamage( DynamicEntity *o, OFVector3D from, OFVector3D to, DynamicEntity *d, int i) { if (o.state != CS_ALIVE) return; int qdam = guns[d.gunSelect].damage; if (d.quadMillis) qdam *= 4; if ([d isKindOfClass:Monster.class]) qdam /= MONSTERDAMAGEFACTOR; if (d.gunSelect == GUN_SG) { int damage = 0; for (int r = 0; r < SGRAYS; r++) if (intersect(o, from, sg[r])) damage += qdam; if (damage) hitpush(i, damage, o, d, from, to); } else if (intersect(o, from, to)) hitpush(i, qdam, o, d, from, to); } void shoot(DynamicEntity *d, OFVector3D targ) { int attacktime = lastmillis - d.lastAction; if (attacktime < d.gunWait) return; d.gunWait = 0; if (!d.attacking) return; d.lastAction = lastmillis; d.lastAttackGun = d.gunSelect; if (!d.ammo[d.gunSelect]) { playsoundc(S_NOAMMO); d.gunWait = 250; d.lastAttackGun = -1; return; } if (d.gunSelect) d.ammo[d.gunSelect]--; OFVector3D from = d.origin; OFVector3D to = targ; from.z -= 0.2f; // below eye float dist = OFDistanceOfVectors3D(from, to); OFVector3D unitv = OFSubtractVectors3D(from, to); unitv = OFMultiplyVector3D(unitv, 1.0f / dist); OFVector3D kickback = OFMultiplyVector3D(unitv, guns[d.gunSelect].kickamount * -0.01f); d.velocity = OFAddVectors3D(d.velocity, kickback); if (d.pitch < 80.0f) d.pitch += guns[d.gunSelect].kickamount * 0.05f; if (d.gunSelect == GUN_FIST || d.gunSelect == GUN_BITE) { unitv = OFMultiplyVector3D(unitv, 3); // punch range to = OFAddVectors3D(from, unitv); } if (d.gunSelect == GUN_SG) createrays(from, to); if (d.quadMillis && attacktime > 200) playsoundc(S_ITEMPUP); shootv(d.gunSelect, from, to, d, true); if (![d isKindOfClass:Monster.class]) addmsg(1, 8, SV_SHOT, d.gunSelect, (int)(from.x * DMF), (int)(from.y * DMF), (int)(from.z * DMF), (int)(to.x * DMF), (int)(to.y * DMF), (int)(to.z * DMF)); d.gunWait = guns[d.gunSelect].attackdelay; if (guns[d.gunSelect].projspeed) return; [players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) { if (player != [OFNull null]) raydamage(player, from, to, d, i); }]; for (Monster *monster in Monster.monsters) if (monster != d) raydamage(monster, from, to, d, -2); if ([d isKindOfClass:Monster.class]) raydamage(player1, from, to, d, -1); } |
Modified src/worldlight.m from [38933acc1f] to [230a66c274].
︙ | ︙ | |||
195 196 197 198 199 200 201 | [dlights removeLastItem]; blockpaste(backup); OFFreeMemory(backup); } } void | | | | | | | | | 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 | [dlights removeLastItem]; blockpaste(backup); OFFreeMemory(backup); } } void dodynlight(OFVector3D vold, OFVector3D v, int reach, int strength, DynamicEntity *owner) { if (!reach) reach = dynlight; if ([owner isKindOfClass:Monster.class]) reach = reach / 2; if (!reach) return; if (v.x < 0 || v.y < 0 || v.x > ssize || v.y > ssize) return; int creach = reach + 16; // dependant on lightray random offsets! struct block b = { (int)v.x - creach, (int)v.y - creach, creach * 2 + 1, creach * 2 + 1 }; if (b.x < 1) b.x = 1; if (b.y < 1) b.y = 1; if (b.xs + b.x > ssize - 2) b.xs = ssize - 2 - b.x; if (b.ys + b.y > ssize - 2) b.ys = ssize - 2 - b.y; if (dlights == nil) dlights = [[OFMutableData alloc] initWithItemSize:sizeof(struct block *)]; // backup area before rendering in dynlight struct block *copy = blockcopy(&b); [dlights addItem:©]; Entity *l = [Entity entity]; l.x = v.x; l.y = v.y; l.z = v.z; l.attr1 = reach; l.type = LIGHT; l.attr2 = strength; calclightsource(l); postlightarea(&b); } |
︙ | ︙ |