Differences From Artifact [be4039eb8e]:
- File
src/clients2c.m
— part of check-in
[304230c1e1]
at
2025-03-23 21:52:54
on branch trunk
— Avoid pointless pointers
Passing OFVector3D by reference is annoying and is worse at passing via registers. (user: js, size: 9143) [annotate] [blame] [check-ins using]
To Artifact [ffe8228e75]:
- File src/clients2c.m — part of check-in [5b7b7d2fc5] at 2025-03-24 22:14:24 on branch trunk — Convert player into a class (user: js, size: 9323) [annotate] [blame] [check-ins using]
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 | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // client processing of the incoming network stream #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "Player.h" extern int clientnum; extern bool c2sinit, senditemstoserver; extern OFString *toservermap; extern OFString *clientpassword; void |
︙ | ︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | // 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 updatepos(DynamicEntity *d) { const float r = player1.radius + d.radius; const float dx = player1.origin.x - d.origin.x; const float dy = player1.origin.y - d.origin.y; const float dz = player1.origin.z - d.origin.z; const float rz = player1.aboveEye + d.eyeHeight; const float fx = (float)fabs(dx), fy = (float)fabs(dy), fz = (float)fabs(dz); | > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // 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 updatepos(DynamicEntity *d) { Player *player1 = Player.player1; const float r = player1.radius + d.radius; const float dx = player1.origin.x - d.origin.x; const float dy = player1.origin.y - d.origin.y; const float dz = player1.origin.z - d.origin.z; const float rz = player1.aboveEye + d.eyeHeight; const float fx = (float)fabs(dx), fy = (float)fabs(dy), fz = (float)fabs(dz); |
︙ | ︙ | |||
178 179 180 181 182 183 184 185 | getalias(nextmapalias); // look up map in the cycle changemap(map != nil ? map : getclientmap()); break; } // another client either connected or changed name/team case SV_INITC2S: { sgetstr(); | > | | | | | | | 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 | getalias(nextmapalias); // look up map in the cycle changemap(map != nil ? map : getclientmap()); break; } // another client either connected or changed name/team case SV_INITC2S: { Player *d_ = (Player *)d; sgetstr(); if (d_.name.length > 0) { // already connected if (![d_.name isEqual:@(text)]) conoutf(@"%@ is now known as %s", d_.name, text); } else { // new client // send new players my info again c2sinit = false; conoutf(@"connected: %s", text); } d_.name = @(text); sgetstr(); d_.team = @(text); d_.lifeSequence = getint(&p); break; } case SV_CDIS: cn = getint(&p); if ((d = getclient(cn)) == nil) break; |
︙ | ︙ | |||
227 228 229 230 231 232 233 | } case SV_DAMAGE: { int target = getint(&p); int damage = getint(&p); int ls = getint(&p); if (target == clientnum) { | | > | | | | | | | | | | 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) { if (ls == Player.player1.lifeSequence) selfdamage(damage, cn, d); } else { OFVector3D loc = getclient(target).origin; playsound(S_PAIN1 + rnd(5), &loc); } break; } case SV_DIED: { Player *d_ = (Player *)d; int actor = getint(&p); if (actor == cn) { conoutf(@"%@ suicided", d_.name); } else if (actor == clientnum) { int frags; if (isteam(Player.player1.team, d_.team)) { frags = -1; conoutf(@"you fragged a teammate (%@)", d_.name); } else { frags = 1; conoutf(@"you fragged %@", d_.name); } addmsg(1, 2, SV_FRAGS, (Player.player1.frags += frags)); } else { Player *a = getclient(actor); if (a != nil) { if (isteam(a.team, d.name)) conoutf(@"%@ fragged his " @"teammate (%@)", a.name, d.name); else conoutf(@"%@ fragged %@", a.name, d.name); } } OFVector3D loc = d_.origin; playsound(S_DIE1 + rnd(2), &loc); d_.lifeSequence++; break; } case SV_FRAGS: [players[cn] setFrags:getint(&p)]; break; |
︙ | ︙ | |||
291 292 293 294 295 296 297 | OFVector3D v = OFMakeVector3D(ents[i].x, ents[i].y, ents[i].z); playsound(S_ITEMSPAWN, &v); break; } // server acknowledges that I picked up this item case SV_ITEMACC: | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | OFVector3D v = OFMakeVector3D(ents[i].x, ents[i].y, ents[i].z); playsound(S_ITEMSPAWN, &v); break; } // server acknowledges that I picked up this item case SV_ITEMACC: realpickup(getint(&p), Player.player1); break; case SV_EDITH: // coop editing messages, should be extended to // include all possible editing ops case SV_EDITT: case SV_EDITS: case SV_EDITD: |
︙ | ︙ | |||
357 358 359 360 361 362 363 | case SV_PING: getint(&p); break; case SV_PONG: addmsg(0, 2, SV_CLIENTPING, | | | | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | case SV_PING: getint(&p); break; case SV_PONG: addmsg(0, 2, SV_CLIENTPING, Player.player1.ping = (Player.player1.ping * 5 + lastmillis - getint(&p)) / 6); break; case SV_CLIENTPING: [players[cn] setPing:getint(&p)]; break; |
︙ | ︙ |