Comment: | Convert player into a class |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
5b7b7d2fc5af4d512db195c4fbfb2aff |
User & Date: | js on 2025-03-24 22:14:24 |
Other Links: | manifest | tags |
2025-03-25
| ||
23:03 | Add forgotten files check-in: 489bb6c39a user: js tags: trunk | |
2025-03-24
| ||
22:14 | Convert player into a class check-in: 5b7b7d2fc5 user: js tags: trunk | |
21:11 | Work around conflicting declaration of gamma check-in: 7c3936be15 user: js tags: trunk | |
Modified src/Cube.m from [3b4164e066] to [8c59576626].
1 2 3 4 5 | // main.cpp: initialisation & main loop #include "cube.h" #import "Command.h" | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | // main.cpp: initialisation & main loop #include "cube.h" #import "Command.h" #import "Player.h" OF_APPLICATION_DELEGATE(Cube) VARF(gamespeed, 10, 100, 1000, if (multiplayer()) gamespeed = 100); VARP(minmillis, 0, 5, 1000); @implementation Cube |
︙ | ︙ | |||
211 212 213 214 215 216 217 218 219 220 221 222 223 224 | } OFDate *past = [OFDate date]; int ignore = 5; for (;;) { @autoreleasepool { [OFRunLoop.mainRunLoop runUntilDate:past]; int millis = SDL_GetTicks() * gamespeed / 100; if (millis - lastmillis > 200) lastmillis = millis - 200; else if (millis - lastmillis < 1) lastmillis = millis - 1; if (millis - lastmillis < minmillis) | > > | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | } OFDate *past = [OFDate date]; int ignore = 5; for (;;) { @autoreleasepool { [OFRunLoop.mainRunLoop runUntilDate:past]; Player *player1 = Player.player1; int millis = SDL_GetTicks() * gamespeed / 100; if (millis - lastmillis > 200) lastmillis = millis - 200; else if (millis - lastmillis < 1) lastmillis = millis - 1; if (millis - lastmillis < minmillis) |
︙ | ︙ |
Modified src/DynamicEntity.h from [39b63673d9] to [b25cdd250b].
︙ | ︙ | |||
17 18 19 20 21 22 23 | // see input code @property (nonatomic) bool k_left, k_right, k_up, k_down; // used for fake gravity @property (nonatomic) int timeInAir; // bounding box size @property (nonatomic) float radius, eyeHeight, aboveEye; @property (nonatomic) int lastUpdate, lag, ping; | < < < | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // see input code @property (nonatomic) bool k_left, k_right, k_up, k_down; // used for fake gravity @property (nonatomic) int timeInAir; // bounding box size @property (nonatomic) float radius, eyeHeight, aboveEye; @property (nonatomic) int lastUpdate, lag, ping; // one of CS_* below @property (nonatomic) int state; @property (nonatomic) int health, armour, armourType, quadMillis; @property (nonatomic) int gunSelect, gunWait; @property (nonatomic) int lastAction, lastAttackGun, lastMove; @property (readonly, nonatomic) int *ammo; @property (nonatomic) bool attacking; // used by physics to signal ai @property (nonatomic) bool blocked, moving; @property (copy, nonatomic) OFString *name; + (instancetype)entity; - (OFData *)dataBySerializing; - (void)setFromSerializedData:(OFData *)data; - (void)resetMovement; // reset player state not persistent accross spawns - (void)resetToSpawnState; |
︙ | ︙ |
Modified src/DynamicEntity.m from [03f91e70ff] to [7a1598ea36].
1 2 3 4 5 6 7 8 9 10 11 12 | #import "DynamicEntity.h" #include "cube.h" #import "Monster.h" struct dynent { OFVector3D origin, velocity; float yaw, pitch, roll; float maxSpeed; bool outsideMap; bool inWater; | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | #import "DynamicEntity.h" #include "cube.h" #import "Monster.h" #import "Player.h" struct dynent { OFVector3D origin, velocity; float yaw, pitch, roll; float maxSpeed; bool outsideMap; bool inWater; |
︙ | ︙ | |||
54 55 56 57 58 59 60 | _yaw = 270; _maxSpeed = 22; _radius = 1.1f; _eyeHeight = 3.2f; _aboveEye = 0.7f; _lastUpdate = lastmillis; | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | _yaw = 270; _maxSpeed = 22; _radius = 1.1f; _eyeHeight = 3.2f; _aboveEye = 0.7f; _lastUpdate = lastmillis; _name = @""; _state = CS_ALIVE; [self resetToSpawnState]; return self; } |
︙ | ︙ | |||
94 95 96 97 98 99 100 | copy->_timeInAir = _timeInAir; copy->_radius = _radius; copy->_eyeHeight = _eyeHeight; copy->_aboveEye = _aboveEye; copy->_lastUpdate = _lastUpdate; copy->_lag = _lag; copy->_ping = _ping; | < < < | 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 | copy->_timeInAir = _timeInAir; copy->_radius = _radius; copy->_eyeHeight = _eyeHeight; copy->_aboveEye = _aboveEye; copy->_lastUpdate = _lastUpdate; copy->_lag = _lag; copy->_ping = _ping; copy->_state = _state; copy->_health = _health; copy->_armour = _armour; copy->_armourType = _armourType; copy->_quadMillis = _quadMillis; copy->_gunSelect = _gunSelect; copy->_gunWait = _gunWait; copy->_lastAction = _lastAction; copy->_lastAttackGun = _lastAttackGun; copy->_lastMove = _lastMove; copy->_attacking = _attacking; for (size_t i = 0; i < NUMGUNS; i++) copy->_ammo[i] = _ammo[i]; copy->_blocked = _blocked; copy->_moving = _moving; copy->_name = [_name copy]; return copy; } - (OFData *)dataBySerializing { // This is frighteningly *TERRIBLE*, but the format used by existing |
︙ | ︙ | |||
146 147 148 149 150 151 152 | .timeInAir = _timeInAir, .radius = _radius, .eyeHeight = _eyeHeight, .aboveEye = _aboveEye, .lastUpdate = _lastUpdate, .lag = _lag, .ping = _ping, | < < > > > > > > > > > > > > > < < < < < < | 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 | .timeInAir = _timeInAir, .radius = _radius, .eyeHeight = _eyeHeight, .aboveEye = _aboveEye, .lastUpdate = _lastUpdate, .lag = _lag, .ping = _ping, .state = _state, .health = _health, .armour = _armour, .armourType = _armourType, .quadMillis = _quadMillis, .gunSelect = _gunSelect, .gunWait = _gunWait, .lastAction = _lastAction, .lastAttackGun = _lastAttackGun, .lastMove = _lastMove, .attacking = _attacking, .blocked = _blocked, .moving = _moving }; for (int i = 0; i < NUMGUNS; i++) data.ammo[i] = _ammo[i]; memcpy(data.name, _name.UTF8String, min(_name.UTF8StringLength, 259)); if ([self isKindOfClass:Player.class]) { Player *player = (Player *)self; data.lifeSequence = player.lifeSequence, data.frags = player.frags; memcpy(data.team, player.team.UTF8String, min(player.team.UTF8StringLength, 259)); } if ([self isKindOfClass:Monster.class]) { Monster *monster = (Monster *)self; data.monsterState = monster.monsterState; data.monsterType = monster.monsterType; data.targetYaw = monster.targetYaw; data.trigger = monster.trigger; data.attackTarget = monster.attackTarget; data.anger = monster.anger; } return [OFData dataWithItems:&data count:sizeof(data)]; } - (void)setFromSerializedData:(OFData *)data { struct dynent d; |
︙ | ︙ | |||
213 214 215 216 217 218 219 | _timeInAir = d.timeInAir; _radius = d.radius; _eyeHeight = d.eyeHeight; _aboveEye = d.aboveEye; _lastUpdate = d.lastUpdate; _lag = d.lag; _ping = d.ping; | < | > > > > > > > > > < < < | 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 | _timeInAir = d.timeInAir; _radius = d.radius; _eyeHeight = d.eyeHeight; _aboveEye = d.aboveEye; _lastUpdate = d.lastUpdate; _lag = d.lag; _ping = d.ping; _state = d.state; _health = d.health; _armour = d.armour; _armourType = d.armourType; _quadMillis = d.quadMillis; _gunSelect = d.gunSelect; _gunWait = d.gunWait; _lastAction = d.lastAction; _lastAttackGun = d.lastAttackGun; _lastMove = d.lastMove; _attacking = d.attacking; for (int i = 0; i < NUMGUNS; i++) _ammo[i] = d.ammo[i]; _blocked = d.blocked; _moving = d.moving; _name = [[OFString alloc] initWithUTF8String:d.name]; if ([self isKindOfClass:Player.class]) { Player *player = (Player *)self; player.lifeSequence = d.lifeSequence; player.frags = d.frags; player.team = @(d.team); } if ([self isKindOfClass:Monster.class]) { Monster *monster = (Monster *)self; monster.monsterState = d.monsterState; monster.monsterType = d.monsterType; monster.targetYaw = d.targetYaw; monster.trigger = d.trigger; monster.attackTarget = d.attackTarget; monster.anger = d.anger; } } - (void)resetMovement { _k_left = false; _k_right = false; _k_up = false; |
︙ | ︙ |
Modified src/Monster.m from [9674185459] to [0a9cae30d2].
1 2 3 4 5 6 | // monster.cpp: implements AI for single player monsters, currently client only #import "Monster.h" #include "cube.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // monster.cpp: implements AI for single player monsters, currently client only #import "Monster.h" #include "cube.h" #import "Entity.h" #import "Player.h" static OFMutableArray<Monster *> *monsters; static int nextmonster, spawnremain, numkilled, monstertotal, mtimestart; @implementation Monster + (void)initialize { |
︙ | ︙ | |||
97 98 99 100 101 102 103 | if (state != M_SLEEP) spawnplayer(self); self.trigger = lastmillis + trigger; self.targetYaw = self.yaw = (float)yaw; self.move = move; | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | if (state != M_SLEEP) spawnplayer(self); self.trigger = lastmillis + trigger; self.targetYaw = self.yaw = (float)yaw; self.move = move; self.enemy = Player.player1; self.gunSelect = t->gun; self.maxSpeed = (float)t->speed; self.health = t->health; self.armour = 0; for (size_t i = 0; i < NUMGUNS; i++) self.ammo[i] = 10000; |
︙ | ︙ | |||
252 253 254 255 256 257 258 | self.yaw -= 360.0f; } // main AI thinking routine, called every frame for every monster - (void)performAction { if (self.enemy.state == CS_DEAD) { | | | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | self.yaw -= 360.0f; } // main AI thinking routine, called every frame for every monster - (void)performAction { if (self.enemy.state == CS_DEAD) { self.enemy = Player.player1; self.anger = 0; } [self normalizeWithAngle:self.targetYaw]; // slowly turn monster towards his target if (self.targetYaw > self.yaw) { self.yaw += curtime * 0.5f; if (self.targetYaw < self.yaw) |
︙ | ︙ | |||
413 414 415 416 417 418 419 | n:monstertypes[self.monsterType].pain r:200]; if ((self.health -= damage) <= 0) { self.state = CS_DEAD; self.lastAction = lastmillis; numkilled++; | | | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | n:monstertypes[self.monsterType].pain r:200]; if ((self.health -= damage) <= 0) { self.state = CS_DEAD; self.lastAction = lastmillis; numkilled++; Player.player1.frags = numkilled; OFVector3D loc = self.origin; playsound(monstertypes[self.monsterType].diesound, &loc); int remain = monstertotal - numkilled; if (remain > 0 && remain <= 5) conoutf(@"only %d monster(s) remaining", remain); } else { OFVector3D loc = self.origin; |
︙ | ︙ |
Modified src/clientextras.m from [b510debdf2] to [44fbd161d9].
1 2 3 4 5 | // clientextras.cpp: stuff that didn't fit in client.cpp or clientgame.cpp :) #include "cube.h" #import "Command.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // clientextras.cpp: stuff that didn't fit in client.cpp or clientgame.cpp :) #include "cube.h" #import "Command.h" #import "Monster.h" #import "Player.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' |
︙ | ︙ | |||
86 87 88 89 90 91 92 | void renderclients() { [players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) { if (player != [OFNull null] && (!demoplayback || i != democlientnum)) renderclient(player, | | | | | 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 | void renderclients() { [players enumerateObjectsUsingBlock:^(id player, size_t i, bool *stop) { if (player != [OFNull null] && (!demoplayback || i != democlientnum)) renderclient(player, isteam(Player.player1.team, [player team]), @"monster/ogro", false, 1.0f); }]; } // creation of scoreboard pseudo-menu bool scoreson = false; void showscores(bool on) { scoreson = on; menuset(((int)on) - 1); } static OFMutableArray<OFString *> *scoreLines; static void renderscore(Player *d) { OFString *lag = [OFString stringWithFormat:@"%d", d.lag]; OFString *name = [OFString stringWithFormat:@"(%@)", d.name]; OFString *line = [OFString stringWithFormat:@"%d\t%@\t%d\t%@\t%@", d.frags, (d.state == CS_LAGGED ? @"LAG" : lag), d.ping, d.team, (d.state == CS_DEAD ? name : d.name)]; |
︙ | ︙ | |||
127 128 129 130 131 132 133 | } #define maxTeams 4 static OFString *teamName[maxTeams]; static int teamScore[maxTeams]; static size_t teamsUsed; | | | | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | } #define maxTeams 4 static OFString *teamName[maxTeams]; static int teamScore[maxTeams]; static size_t teamsUsed; static void addteamscore(Player *d) { for (size_t i = 0; i < teamsUsed; i++) { if ([teamName[i] isEqual:d.team]) { teamScore[i] += d.frags; return; } } |
︙ | ︙ | |||
151 152 153 154 155 156 157 | void renderscores() { if (!scoreson) return; [scoreLines removeAllObjects]; if (!demoplayback) | | | | | | | | 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 | void renderscores() { if (!scoreson) return; [scoreLines removeAllObjects]; if (!demoplayback) renderscore(Player.player1); for (Player *player in players) if ([player isKindOfClass:Player.class]) renderscore(player); sortmenu(); if (m_teammode) { teamsUsed = 0; for (Player *player in players) if ([player isKindOfClass:Player.class]) addteamscore(player); if (!demoplayback) addteamscore(Player.player1); OFMutableString *teamScores = [OFMutableString string]; for (size_t j = 0; j < teamsUsed; j++) [teamScores appendFormat:@"[ %@: %d ]", teamName[j], teamScore[j]]; menumanual(0, scoreLines.count, @""); menumanual(0, scoreLines.count + 1, teamScores); } |
︙ | ︙ |
Modified src/clientgame.m from [12fef2cf63] to [d1273c7a21].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // clientgame.cpp: core game related stuff #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Entity.h" #import "Monster.h" #import "OFString+Cube.h" int nextmode = 0; // nextmode becomes gamemode after next map load VAR(gamemode, 1, 0, 0); COMMAND(mode, ARG_1INT, ^(int n) { addmsg(1, 2, SV_GAMEMODE, nextmode = n); }) bool intermission = false; | > < < | < | | 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 | // clientgame.cpp: core game related stuff #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Entity.h" #import "Monster.h" #import "OFString+Cube.h" #import "Player.h" int nextmode = 0; // nextmode becomes gamemode after next map load VAR(gamemode, 1, 0, 0); COMMAND(mode, ARG_1INT, ^(int n) { addmsg(1, 2, SV_GAMEMODE, nextmode = n); }) bool intermission = false; OFMutableArray *players; // other clients void initPlayers() { players = [[OFMutableArray alloc] init]; } VARP(sensitivity, 0, 10, 10000); VARP(sensitivityscale, 1, 1, 10000); VARP(invmouse, 0, 0, 1); int lastmillis = 0; int curtime = 10; OFString *clientmap; OFString * getclientmap() { return clientmap; } void respawnself() { spawnplayer(Player.player1); showscores(false); } static void arenacount(Player *d, int *alive, int *dead, OFString **lastteam, bool *oneteam) { if (d.state != CS_DEAD) { (*alive)++; if (![*lastteam isEqual:d.team]) *oneteam = false; *lastteam = d.team; } else |
︙ | ︙ | |||
78 79 80 81 82 83 84 | int alive = 0, dead = 0; OFString *lastteam = nil; bool oneteam = true; for (id player in players) if (player != [OFNull null]) arenacount( player, &alive, &dead, &lastteam, &oneteam); | | | > | | | | | | | | | | | | | | | | 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 | int alive = 0, dead = 0; OFString *lastteam = nil; bool oneteam = true; for (id player in players) if (player != [OFNull null]) arenacount( player, &alive, &dead, &lastteam, &oneteam); arenacount(Player.player1, &alive, &dead, &lastteam, &oneteam); if (dead > 0 && (alive <= 1 || (m_teammode && oneteam))) { conoutf( @"arena round is over! next round in 5 seconds..."); if (alive) conoutf( @"team %s is last man standing", lastteam); else conoutf(@"everyone died!"); arenarespawnwait = lastmillis + 5000; arenadetectwait = lastmillis + 10000; Player.player1.roll = 0; } } } extern int democlientnum; void otherplayers() { [players enumerateObjectsUsingBlock:^(Player *player, size_t i, bool *stop) { if ([player isKindOfClass:Player.class]) return; const int lagtime = lastmillis - player.lastUpdate; if (lagtime > 1000 && player.state == CS_ALIVE) { player.state = CS_LAGGED; return; } if (lagtime && player.state != CS_DEAD && (!demoplayback || i != democlientnum)) // use physics to extrapolate player position moveplayer(player, 2, false); }]; } void respawn() { if (Player.player1.state == CS_DEAD) { Player.player1.attacking = false; if (m_arena) { conoutf(@"waiting for new round to start..."); return; } if (m_sp) { nextmode = gamemode; changemap(clientmap); |
︙ | ︙ | |||
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 | } physicsframe(); checkquad(curtime); 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]; if (player1.state == CS_DEAD) { if (lastmillis - player1.lastAction < 2000) { player1.move = player1.strafe = 0; moveplayer(player1, 10, false); } else if (!m_arena && !m_sp && lastmillis - player1.lastAction > 10000) respawn(); } else if (!intermission) { moveplayer(player1, 20, true); checkitems(); } // do this last, to reduce the effective frame lag c2sinfo(player1); } } lastmillis = millis; } | > > > | 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 | } physicsframe(); checkquad(curtime); if (m_arena) arenarespawn(); moveprojectiles((float)curtime); demoplaybackstep(); Player *player1 = Player.player1; 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]; if (player1.state == CS_DEAD) { if (lastmillis - player1.lastAction < 2000) { player1.move = player1.strafe = 0; moveplayer(player1, 10, false); } else if (!m_arena && !m_sp && lastmillis - player1.lastAction > 10000) respawn(); } else if (!intermission) { moveplayer(player1, 20, true); checkitems(); } // do this last, to reduce the effective frame lag c2sinfo(player1); } } lastmillis = millis; } |
︙ | ︙ | |||
209 210 211 212 213 214 215 | } int spawncycle = -1; int fixspawn = 2; // place at random spawn. also used by monsters! void | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | } int spawncycle = -1; int fixspawn = 2; // place at random spawn. also used by monsters! void spawnplayer(Player *d) { int r = fixspawn-- > 0 ? 4 : rnd(10) + 1; for (int i = 0; i < r; i++) spawncycle = findentity(PLAYERSTART, spawncycle + 1); if (spawncycle != -1) { d.origin = OFMakeVector3D( ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z); |
︙ | ︙ | |||
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | d.state = CS_ALIVE; } // movement input code #define dir(name, v, d, s, os) \ COMMAND(name, ARG_DOWN, ^(bool isDown) { \ player1.s = isDown; \ player1.v = isDown ? d : (player1.os ? -(d) : 0); \ player1.lastMove = lastmillis; \ }) dir(backward, move, -1, k_down, k_up); dir(forward, move, 1, k_up, k_down); dir(left, strafe, 1, k_left, k_right); dir(right, strafe, -1, k_right, k_left); COMMAND(attack, ARG_DOWN, ^(bool on) { if (intermission) return; if (editmode) editdrag(on); | > | | > > > | | | | 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 | d.state = CS_ALIVE; } // movement input code #define dir(name, v, d, s, os) \ COMMAND(name, ARG_DOWN, ^(bool isDown) { \ Player *player1 = Player.player1; \ player1.s = isDown; \ player1.v = isDown ? d : (player1.os ? -(d) : 0); \ player1.lastMove = lastmillis; \ }) dir(backward, move, -1, k_down, k_up); dir(forward, move, 1, k_up, k_down); dir(left, strafe, 1, k_left, k_right); dir(right, strafe, -1, k_right, k_left); COMMAND(attack, ARG_DOWN, ^(bool on) { if (intermission) return; if (editmode) editdrag(on); else if ((Player.player1.attacking = on)) respawn(); }) COMMAND(jump, ARG_DOWN, ^(bool on) { if (!intermission && (Player.player1.jumpNext = on)) respawn(); }) COMMAND(showscores, ARG_DOWN, ^(bool isDown) { showscores(isDown); }) void fixplayer1range() { const float MAXPITCH = 90.0f; Player *player1 = Player.player1; if (player1.pitch > MAXPITCH) player1.pitch = MAXPITCH; if (player1.pitch < -MAXPITCH) player1.pitch = -MAXPITCH; while (player1.yaw < 0.0f) player1.yaw += 360.0f; while (player1.yaw >= 360.0f) player1.yaw -= 360.0f; } void mousemove(int dx, int dy) { Player *player1 = Player.player1; if (player1.state == CS_DEAD || intermission) return; const float SENSF = 33.0f; // try match quake sens player1.yaw += (dx / SENSF) * (sensitivity / (float)sensitivityscale); player1.pitch -= (dy / SENSF) * (sensitivity / (float)sensitivityscale) * (invmouse ? -1 : 1); fixplayer1range(); } // damage arriving from the network, monsters, yourself, all ends up here. void selfdamage(int damage, int actor, DynamicEntity *act) { Player *player1 = Player.player1; if (player1.state != CS_ALIVE || editmode || intermission) return; damageblend(damage); demoblend(damage); // let armour absorb when possible int ad = damage * (player1.armourType + 1) * 20 / 100; if (ad > Player.player1.armour) ad = Player.player1.armour; player1.armour -= ad; damage -= ad; float droll = damage / 0.5f; player1.roll += player1.roll > 0 ? droll : (player1.roll < 0 ? -droll : (rnd(2) ? droll : -droll)); // give player a kick depending // on amount of damage if ((player1.health -= damage) <= 0) { if (actor == -2) { conoutf(@"you got killed by %@!", act.name); } else if (actor == -1) { actor = getclientnum(); conoutf(@"you suicided!"); addmsg(1, 2, SV_FRAGS, --player1.frags); } else { Player *a = getclient(actor); if (a != nil) { if (isteam(a.team, player1.team)) conoutf(@"you got fragged by a " @"teammate (%@)", a.name); else conoutf( |
︙ | ︙ | |||
347 348 349 350 351 352 353 | } void timeupdate(int timeremain) { if (!timeremain) { intermission = true; | | | | | 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 | } void timeupdate(int timeremain) { if (!timeremain) { intermission = true; Player.player1.attacking = false; conoutf(@"intermission:"); conoutf(@"game has ended!"); showscores(true); } else { conoutf(@"time remaining: %d minutes", timeremain); } } Player * getclient(int cn) // ensure valid entity { if (cn < 0 || cn >= MAXCLIENTS) { neterr(@"clientnum"); return nil; } while (cn >= players.count) [players addObject:[OFNull null]]; id player = players[cn]; if (player == [OFNull null]) { player = [Player player]; players[cn] = player; } return player; } void |
︙ | ︙ | |||
404 405 406 407 408 409 410 | gamemode = 0; conoutf(@"coop sp not supported yet"); } sleepwait = 0; [Monster resetAll]; projreset(); spawncycle = -1; | | | | 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | gamemode = 0; conoutf(@"coop sp not supported yet"); } sleepwait = 0; [Monster resetAll]; projreset(); spawncycle = -1; spawnplayer(Player.player1); Player.player1.frags = 0; for (id player in players) if (player != [OFNull null]) [player setFrags:0]; resetspawns(); clientmap = name; if (editmode) toggleedit(); |
︙ | ︙ |
Modified src/clients.m from [d14310e680] to [b2ad70bf79].
1 2 3 4 5 | // client.cpp, mostly network related client game code #include "cube.h" #import "Command.h" | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | // client.cpp, mostly network related client game code #include "cube.h" #import "Command.h" #import "Player.h" static ENetHost *clienthost = NULL; static int connecting = 0; static int connattempts = 0; static int disconnecting = 0; // our client id in the game int clientnum = -1; |
︙ | ︙ | |||
65 66 67 68 69 70 71 | newname(OFString *name) { c2sinit = false; if (name.length > 16) name = [name substringToIndex:16]; | | | | | | 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 | newname(OFString *name) { c2sinit = false; if (name.length > 16) name = [name substringToIndex:16]; Player.player1.name = name; } COMMAND(name, ARG_1STR, ^(OFString *name) { newname(name); }) static void newteam(OFString *name) { c2sinit = false; if (name.length > 5) name = [name substringToIndex:5]; Player.player1.team = name; } COMMAND(team, ARG_1STR, ^(OFString *name) { newteam(name); }) void writeclientinfo(OFStream *stream) { [stream writeFormat:@"name \"%@\"\nteam \"%@\"\n", Player.player1.name, Player.player1.team]; } void connects(OFString *servername) { disconnect(true, false); // reset state addserver(servername); |
︙ | ︙ | |||
145 146 147 148 149 150 151 | conoutf(@"disconnected"); clienthost = NULL; connecting = 0; connattempts = 0; disconnecting = 0; clientnum = -1; c2sinit = false; | | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | conoutf(@"disconnected"); clienthost = NULL; connecting = 0; connattempts = 0; disconnecting = 0; clientnum = -1; c2sinit = false; Player.player1.lifeSequence = 0; [players removeAllObjects]; localdisconnect(); if (!onlyclean) { stop(); localconnect(); |
︙ | ︙ | |||
176 177 178 179 180 181 182 | disconnect(0, !disconnecting); } static OFString *ctext; void toserver(OFString *text) { | | | 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) { conoutf(@"%@:\f %@", Player.player1.name, text); ctext = text; } COMMAND(echo, ARG_VARI, ^(OFString *text) { conoutf(@"%@", text); }) COMMAND(say, ARG_VARI, ^(OFString *text) { |
︙ | ︙ | |||
277 278 279 280 281 282 283 | enet_host_flush(clienthost); } else localclienttoserver((ENetPacket *)packet); } // send update to the server void | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | enet_host_flush(clienthost); } else localclienttoserver((ENetPacket *)packet); } // send update to the server void c2sinfo(Player *d) { if (clientnum < 0) return; // we haven't had a welcome message from the server yet if (lastmillis - lastupdate < 40) return; // don't update faster than 25fps ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, 0); unsigned char *start = packet->data; |
︙ | ︙ | |||
338 339 340 341 342 343 344 | ctext = @""; } // tell other clients who I am if (!c2sinit) { packet->flags = ENET_PACKET_FLAG_RELIABLE; c2sinit = true; putint(&p, SV_INITC2S); | | | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | ctext = @""; } // tell other clients who I am if (!c2sinit) { packet->flags = ENET_PACKET_FLAG_RELIABLE; c2sinit = true; putint(&p, SV_INITC2S); sendstring(Player.player1.name, &p); sendstring(Player.player1.team, &p); putint(&p, Player.player1.lifeSequence); } for (OFData *msg in messages) { // send messages collected during the previous frames if (*(int *)[msg itemAtIndex:1]) packet->flags = ENET_PACKET_FLAG_RELIABLE; for (int i = 0; i < *(int *)[msg itemAtIndex:0]; i++) putint(&p, *(int *)[msg itemAtIndex:i + 2]); |
︙ | ︙ |
Modified src/clients2c.m from [be4039eb8e] to [ffe8228e75].
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; |
︙ | ︙ |
Modified src/cube.h from [9e15fb9815] to [40ed8384d1].
1 2 3 4 5 6 7 8 9 10 11 | // one big bad include file for the whole engine... nasty! #import <ObjFW/ObjFW.h> #include <SDL2/SDL.h> #include "tools.h" #define _MAXDEFSTR 260 @class Entity; | > | | 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> #include <SDL2/SDL.h> #include "tools.h" #define _MAXDEFSTR 260 @class DynamicEntity; @class Entity; @class Player; @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; |
︙ | ︙ | |||
252 253 254 255 256 257 258 | extern "C" { #endif // map data, the mips are sequential 2D arrays in memory extern struct sqr *world, *wmip[]; extern struct header hdr; // current map header extern int sfactor, ssize; // ssize = 2^sfactor extern int cubicsize, mipsize; // cubicsize = ssize^2 | < < | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | extern "C" { #endif // map data, the mips are sequential 2D arrays in memory extern struct sqr *world, *wmip[]; extern struct header hdr; // current map header extern int sfactor, ssize; // ssize = 2^sfactor extern int cubicsize, mipsize; // cubicsize = ssize^2 // all the other clients (in multiplayer) extern OFMutableArray *players; extern bool editmode; extern OFMutableArray<Entity *> *ents; // map entities extern OFVector3D worldpos; // current target of the crosshair in the world extern int lastmillis; // last time extern int curtime; // current frame time |
︙ | ︙ |
Modified src/editing.m from [696569b661] to [7c6be4eed6].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // editing.cpp: most map editing commands go here, entity editing commands are // in world.cpp #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Monster.h" #import "OFString+Cube.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 | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // editing.cpp: most map editing commands go here, entity editing commands are // in world.cpp #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Monster.h" #import "OFString+Cube.h" #import "Player.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 |
︙ | ︙ | |||
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | static struct sqr rtex; VAR(editing, 0, 0, 1); void toggleedit() { if (player1.state == CS_DEAD) return; // do not allow dead players to edit to avoid state // confusion if (!editmode && !allowedittoggle()) return; // not in most multiplayer modes if (!(editmode = !editmode)) { settagareas(); // reset triggers to allow quick playtesting | > | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | static struct sqr rtex; VAR(editing, 0, 0, 1); void toggleedit() { Player *player1 = Player.player1; if (player1.state == CS_DEAD) return; // do not allow dead players to edit to avoid state // confusion if (!editmode && !allowedittoggle()) return; // not in most multiplayer modes if (!(editmode = !editmode)) { settagareas(); // reset triggers to allow quick playtesting |
︙ | ︙ | |||
153 154 155 156 157 158 159 160 161 162 163 164 165 166 | ? (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 { flrceil = ((int)(player1.pitch >= 0)) * 2; volatile float x = worldpos.x; // volatile needed to prevent msvc7 optimizer bug? volatile float y = worldpos.y; volatile float z = worldpos.z; | > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | ? (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 { Player *player1 = Player.player1; flrceil = ((int)(player1.pitch >= 0)) * 2; volatile float x = worldpos.x; // volatile needed to prevent msvc7 optimizer bug? volatile float y = worldpos.y; volatile float z = worldpos.z; |
︙ | ︙ | |||
622 623 624 625 626 627 628 | loopselxy(s->tag = tag); }) COMMAND(newent, ARG_5STR, ^(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) { EDITSEL; | | | 625 626 627 628 629 630 631 632 633 634 635 | loopselxy(s->tag = tag); }) COMMAND(newent, ARG_5STR, ^(OFString *what, OFString *a1, OFString *a2, OFString *a3, OFString *a4) { EDITSEL; newentity(sel.x, sel.y, (int)Player.player1.origin.z, what, [a1 cube_intValueWithBase:0], [a2 cube_intValueWithBase:0], [a3 cube_intValueWithBase:0], [a4 cube_intValueWithBase:0]); }) |
Modified src/entities.m from [fe7c9a5680] to [e376d54115].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // entities.cpp: map entity related functions (pickup etc.) #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "MapModelInfo.h" OFMutableArray<Entity *> *ents; static OFString *entmdlnames[] = { @"shells", @"bullets", @"rockets", | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // entities.cpp: map entity related functions (pickup etc.) #include "cube.h" #import "DynamicEntity.h" #import "Entity.h" #import "MapModelInfo.h" #import "Player.h" OFMutableArray<Entity *> *ents; static OFString *entmdlnames[] = { @"shells", @"bullets", @"rockets", |
︙ | ︙ | |||
124 125 126 127 128 129 130 | { 150, 150, S_ITEMARMOUR }, { 20000, 30000, S_ITEMPUP }, }; void baseammo(int gun) { | | | | 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 | { 150, 150, S_ITEMARMOUR }, { 20000, 30000, S_ITEMPUP }, }; void baseammo(int gun) { Player.player1.ammo[gun] = itemstats[gun - 1].add * 2; } // these two functions are called when the server acknowledges that you really // picked up the item (in multiplayer someone may grab it before you). static int radditem(int i, int v) { struct itemstat *is = &itemstats[ents[i].type - I_SHELLS]; ents[i].spawned = false; v += is->add; if (v > is->max) v = is->max; playsoundc(is->sound); return v; } void realpickup(int n, Player *d) { switch (ents[n].type) { case I_SHELLS: d.ammo[1] = radditem(n, d.ammo[1]); break; case I_BULLETS: d.ammo[2] = radditem(n, d.ammo[2]); |
︙ | ︙ | |||
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 | 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); player1.velocity = OFAddVectors3D( OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0), v); playsoundc(S_JUMPPAD); break; } } } void checkitems() { if (editmode) return; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; | > > > | 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 | 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); Player *player1 = Player.player1; player1.velocity = OFAddVectors3D( OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0), v); playsoundc(S_JUMPPAD); break; } } } void checkitems() { Player *player1 = Player.player1; if (editmode) return; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; |
︙ | ︙ | |||
327 328 329 330 331 332 333 334 335 336 337 338 339 340 | pickup(i, player1); }]; } void checkquad(int time) { if (player1.quadMillis && (player1.quadMillis -= time) < 0) { player1.quadMillis = 0; playsoundc(S_PUPOUT); conoutf(@"quad damage is over"); } } | > > | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | pickup(i, player1); }]; } void checkquad(int time) { Player *player1 = Player.player1; if (player1.quadMillis && (player1.quadMillis -= time) < 0) { player1.quadMillis = 0; playsoundc(S_PUPOUT); conoutf(@"quad damage is over"); } } |
︙ | ︙ |
Modified src/menus.m from [d14babe2b3] to [c38d6c5a56].
1 2 3 4 5 6 7 | // menus.cpp: ingame menu system (also used for scores and serverlist) #include "cube.h" #import "Menu.h" #import "Command.h" | < > | | 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 | // menus.cpp: ingame menu system (also used for scores and serverlist) #include "cube.h" #import "Menu.h" #import "Command.h" #import "MenuItem.h" #import "Player.h" static OFMutableArray<OFNumber *> *menuStack; static OFMutableArray<Menu *> *menus; static int vmenu = -1; void menuset(int menu) { if ((vmenu = menu) >= 1) [Player.player1 resetMovement]; if (vmenu == 1) menus[1].menusel = 0; } COMMAND(showmenu, ARG_1STR, ^(OFString *name) { int i = 0; for (Menu *menu in menus) { |
︙ | ︙ |
Modified src/meson.build from [7b26dc3ecb] to [427dbc46b4].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 'KeyMapping.m', 'MD2.m', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'Monster.m', 'OFString+Cube.m', 'Projectile.m', 'ResolverResult.m', 'ResolverThread.m', 'ServerEntity.m', 'ServerInfo.m', 'Variable.m', 'clients.m', | > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 'KeyMapping.m', 'MD2.m', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'Monster.m', 'OFString+Cube.m', 'Player.m', 'Projectile.m', 'ResolverResult.m', 'ResolverThread.m', 'ServerEntity.m', 'ServerInfo.m', 'Variable.m', 'clients.m', |
︙ | ︙ |
Modified src/physics.m from [5a011dd2ea] to [7410504650].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // 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" #import "Monster.h" // collide with player or monster static bool plcollide( DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo) { if (o.state != CS_ALIVE) | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // 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" #import "Monster.h" #import "Player.h" // collide with player or monster static bool plcollide( DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo) { if (o.state != CS_ALIVE) |
︙ | ︙ | |||
175 176 177 178 179 180 181 | for (id player in players) { if (player == [OFNull null] || player == d) continue; if (!plcollide(d, player, &headspace, &hi, &lo)) return false; } | | | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | for (id player in players) { if (player == [OFNull null] || player == d) continue; if (!plcollide(d, player, &headspace, &hi, &lo)) return false; } if (d != Player.player1) if (!plcollide(d, Player.player1, &headspace, &hi, &lo)) return false; // this loop can be a performance bottleneck with many monster on a slow // cpu, should replace with a blockmap but seems mostly fast enough for (Monster *monster in Monster.monsters) if (!vreject(d.origin, monster.origin, 7.0f) && d != monster && !plcollide(d, monster, &headspace, &hi, &lo)) |
︙ | ︙ |
Modified src/protos.h from [e6df6c1853] to [056cf22e2e].
︙ | ︙ | |||
78 79 80 81 82 83 84 | extern void disconnect(bool onlyclean, bool async); 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(); | | | | 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 | extern void disconnect(bool onlyclean, bool async); 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(); extern void c2sinfo(Player *d); extern void neterr(OFString *s); extern void initclientnet(); extern bool netmapstart(); extern int getclientnum(); extern void changemapserv(OFString *name, int mode); extern void writeclientinfo(OFStream *stream); // clientgame extern void initPlayers(); extern void mousemove(int dx, int dy); extern void updateworld(int millis); extern void startmap(OFString *name); extern void changemap(OFString *name); extern void initclient(); extern void spawnplayer(DynamicEntity *d); extern void selfdamage(int damage, int actor, DynamicEntity *act); extern OFString *getclientmap(); extern OFString *modestr(int n); extern Player *getclient(int cn); extern void setclient(int cn, id client); extern void timeupdate(int timeremain); extern void fixplayer1range(); // clientextras extern void renderclients(); extern void renderclient( |
︙ | ︙ | |||
251 252 253 254 255 256 257 | // entities extern void initEntities(); extern void renderents(); extern void putitems(unsigned char **p); extern void checkquad(int time); extern void checkitems(); | | | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | // entities extern void initEntities(); extern void renderents(); extern void putitems(unsigned char **p); extern void checkquad(int time); extern void checkitems(); extern void realpickup(int n, Player *d); extern void renderentities(); extern void resetspawns(); extern void setspawn(size_t i, bool on); extern void teleport(int n, DynamicEntity *d); extern void baseammo(int gun); // rndmap extern void perlinarea(const struct block *b, int scale, int seed, int psize); #ifdef __cplusplus } #endif |
Modified src/renderextras.m from [ace19c9caa] to [429e6fcead].
1 2 3 4 5 | // renderextras.cpp: misc gl render code and the HUD #include "cube.h" #import "Command.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // renderextras.cpp: misc gl render code and the HUD #include "cube.h" #import "Command.h" #import "Entity.h" #import "Player.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); |
︙ | ︙ | |||
323 324 325 326 327 328 329 330 331 332 333 334 335 336 | VAR(hidestats, 0, 0, 1); VARP(crosshairfx, 0, 1, 1); void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) { readmatrices(); if (editmode) { if (cursordepth == 1.0f) worldpos = player1.origin; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); cursorupdate(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | > > | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | VAR(hidestats, 0, 0, 1); VARP(crosshairfx, 0, 1, 1); void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) { Player *player1 = Player.player1; readmatrices(); if (editmode) { if (cursordepth == 1.0f) worldpos = player1.origin; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); cursorupdate(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); |
︙ | ︙ |
Modified src/rendergl.m from [27faa2c25f] to [6b51df5263].
1 2 3 4 5 6 7 | // rendergl.cpp: core opengl rendering stuff #define gamma math_gamma #include "cube.h" #import "Command.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // rendergl.cpp: core opengl rendering stuff #define gamma math_gamma #include "cube.h" #import "Command.h" #import "Monster.h" #import "OFString+Cube.h" #import "Player.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 |
︙ | ︙ | |||
341 342 343 344 345 346 347 348 349 350 351 352 353 354 | conoutf(@"sdl: %s", SDL_GetError()); } }) void transplayer() { glLoadIdentity(); glRotated(player1.roll, 0.0, 0.0, 1.0); glRotated(player1.pitch, -1.0, 0.0, 0.0); glRotated(player1.yaw, 0.0, 1.0, 0.0); glTranslated(-player1.origin.x, | > > | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | conoutf(@"sdl: %s", SDL_GetError()); } }) void transplayer() { Player *player1 = Player.player1; glLoadIdentity(); glRotated(player1.roll, 0.0, 0.0, 1.0); glRotated(player1.pitch, -1.0, 0.0, 0.0); glRotated(player1.yaw, 0.0, 1.0, 0.0); glTranslated(-player1.origin.x, |
︙ | ︙ | |||
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | OFString *hudgunnames[] = { @"hudguns/fist", @"hudguns/shotg", @"hudguns/chaing", @"hudguns/rocket", @"hudguns/rifle" }; void drawhudmodel(int start, int end, float speed, int base) { rendermodel(hudgunnames[player1.gunSelect], start, end, 0, 1.0f, OFMakeVector3D( player1.origin.x, player1.origin.z, player1.origin.y), player1.yaw + 90, player1.pitch, false, 1.0f, speed, 0, base); } void drawhudgun(float fovy, float aspect, int farplane) { if (!hudgun /*|| !player1.gunSelect*/) return; glEnable(GL_CULL_FACE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); | > > > > | 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 | OFString *hudgunnames[] = { @"hudguns/fist", @"hudguns/shotg", @"hudguns/chaing", @"hudguns/rocket", @"hudguns/rifle" }; void drawhudmodel(int start, int end, float speed, int base) { Player *player1 = Player.player1; rendermodel(hudgunnames[player1.gunSelect], start, end, 0, 1.0f, OFMakeVector3D( player1.origin.x, player1.origin.z, player1.origin.y), player1.yaw + 90, player1.pitch, false, 1.0f, speed, 0, base); } void drawhudgun(float fovy, float aspect, int farplane) { Player *player1 = Player.player1; if (!hudgun /*|| !player1.gunSelect*/) return; glEnable(GL_CULL_FACE); glMatrixMode(GL_PROJECTION); glLoadIdentity(); |
︙ | ︙ | |||
406 407 408 409 410 411 412 413 414 415 416 417 418 419 | glDisable(GL_CULL_FACE); } void gl_drawframe(int w, int h, float curfps) { float hf = hdr.waterlevel - 0.3f; float fovy = (float)fov * h / w; float aspect = w / (float)h; bool underwater = (player1.origin.z < hf); glFogi(GL_FOG_START, (fog + 64) / 8); glFogi(GL_FOG_END, fog); | > | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | glDisable(GL_CULL_FACE); } void gl_drawframe(int w, int h, float curfps) { Player *player1 = Player.player1; float hf = hdr.waterlevel - 0.3f; float fovy = (float)fov * h / w; float aspect = w / (float)h; bool underwater = (player1.origin.z < hf); glFogi(GL_FOG_START, (fog + 64) / 8); glFogi(GL_FOG_END, fog); |
︙ | ︙ |
Modified src/rendermd2.m from [7b42d00ad3] to [c6c4c06ab4].
1 2 3 4 5 | // rendermd2.cpp: loader code adapted from a nehe tutorial #include "cube.h" #import "Command.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // rendermd2.cpp: loader code adapted from a nehe tutorial #include "cube.h" #import "Command.h" #import "MD2.h" #import "MapModelInfo.h" #import "OFString+Cube.h" #import "Player.h" static OFMutableDictionary<OFString *, MD2 *> *mdllookup = nil; static OFMutableArray<MD2 *> *mapmodels = nil; static const int FIRSTMDL = 20; void |
︙ | ︙ | |||
86 87 88 89 90 91 92 | void rendermodel(OFString *mdl, int frame, int range, int tex, float rad, OFVector3D position, float yaw, float pitch, bool teammate, float scale, float speed, int snap, int basetime) { MD2 *m = loadmodel(mdl); | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | void rendermodel(OFString *mdl, int frame, int range, int tex, float rad, OFVector3D position, float yaw, float pitch, bool teammate, float scale, float speed, int snap, int basetime) { MD2 *m = loadmodel(mdl); if (isoccluded(Player.player1.origin.x, Player.player1.origin.y, position.x - rad, position.z - rad, rad * 2)) return; delayedload(m); int xs, ys; glBindTexture(GL_TEXTURE_2D, tex ? lookuptexture(tex, &xs, &ys) : FIRSTMDL + m.mdlnum); |
︙ | ︙ |
Modified src/renderparticles.m from [c7ff826e5c] to [7fffcaae48].
1 2 3 4 | // renderparticles.cpp #include "cube.h" | | | 1 2 3 4 5 6 7 8 9 10 11 12 | // renderparticles.cpp #include "cube.h" #import "Player.h" #define MAXPARTICLES 10500 const int NUMPARTCUTOFF = 20; struct particle { OFVector3D o, d; int fade, type; int millis; |
︙ | ︙ | |||
52 53 54 55 56 57 58 | up = u; } void render_particles(int time) { if (demoplayback && demotracking) | | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | up = u; } void render_particles(int time) { if (demoplayback && demotracking) newparticle(Player.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 { |
︙ | ︙ |
Modified src/savegamedemo.m from [b93241b086] to [822ad5d4d5].
1 2 3 4 5 6 | // 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 "Command.h" | < > | | 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 | // 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 "Command.h" #import "Entity.h" #import "Monster.h" #import "Player.h" #ifdef OF_BIG_ENDIAN static const int islittleendian = 0; #else static const int islittleendian = 1; #endif static gzFile f = NULL; bool demorecording = false; bool demoplayback = false; bool demoloading = false; static OFMutableArray<Player *> *playerhistory; int democlientnum = 0; extern void startdemo(); static void gzput(int i) { |
︙ | ︙ | |||
101 102 103 104 105 106 107 | if (!f) { conoutf(@"could not write %@", IRI.string); return; } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, islittleendian); gzputi(SAVEGAMEVERSION); | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | if (!f) { conoutf(@"could not write %@", IRI.string); return; } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, islittleendian); gzputi(SAVEGAMEVERSION); OFData *data = [Player.player1 dataBySerializing]; gzputi(data.count); char map[_MAXDEFSTR] = { 0 }; memcpy(map, getclientmap().UTF8String, min(getclientmap().UTF8StringLength, _MAXDEFSTR - 1)); gzwrite(f, map, _MAXDEFSTR); gzputi(gamemode); gzputi(ents.count); |
︙ | ︙ | |||
215 216 217 218 219 220 221 | restoreserverstate(ents); OFMutableData *data = [OFMutableData dataWithCapacity:DynamicEntity.serializedSize]; [data increaseCountBy:DynamicEntity.serializedSize]; gzread(f, data.mutableItems, data.count); | | | | | | 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 | restoreserverstate(ents); OFMutableData *data = [OFMutableData dataWithCapacity:DynamicEntity.serializedSize]; [data increaseCountBy:DynamicEntity.serializedSize]; gzread(f, data.mutableItems, data.count); [Player.player1 setFromSerializedData:data]; Player.player1.lastAction = lastmillis; int nmonsters = gzgeti(); OFArray<Monster *> *monsters = Monster.monsters; if (nmonsters != monsters.count) return loadgameout(); for (Monster *monster in monsters) { gzread(f, data.mutableItems, data.count); [monster setFromSerializedData:data]; // lazy, could save id of enemy instead monster.enemy = Player.player1; // also lazy, but no real noticable effect on game monster.lastAction = monster.trigger = lastmillis + 500; if (monster.state == CS_DEAD) monster.lastAction = 0; } [Monster restoreAll]; int nplayers = gzgeti(); for (int i = 0; i < nplayers; i++) { if (!gzget()) { Player *d = getclient(i); assert(d); gzread(f, data.mutableItems, data.count); [d setFromSerializedData:data]; } } conoutf(@"savegame restored"); |
︙ | ︙ | |||
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | { bdamage = damage; } void incomingdemodata(unsigned char *buf, int len, bool extras) { if (!demorecording) return; gzputi(lastmillis - starttime); gzputi(len); gzwrite(f, buf, len); gzput(extras); if (extras) { gzput(player1.gunSelect); gzput(player1.lastAttackGun); | > > > | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | { bdamage = damage; } void incomingdemodata(unsigned char *buf, int len, bool extras) { Player *player1 = Player.player1; if (!demorecording) return; gzputi(lastmillis - starttime); gzputi(len); gzwrite(f, buf, len); gzput(extras); if (extras) { gzput(player1.gunSelect); gzput(player1.lastAttackGun); |
︙ | ︙ | |||
366 367 368 369 370 371 372 | void startdemo() { democlientnum = gzgeti(); demoplayback = true; starttime = lastmillis; conoutf(@"now playing demo"); | | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | void startdemo() { democlientnum = gzgeti(); demoplayback = true; starttime = lastmillis; conoutf(@"now playing demo"); setclient(democlientnum, [Player.player1 copy]); readdemotime(); } VAR(demodelaymsec, 0, 120, 500); // spline interpolation #define catmulrom(z, a, b, c, s, dest) \ |
︙ | ︙ | |||
417 418 419 420 421 422 423 | stopreset(); return; } unsigned char buf[MAXTRANS]; gzread(f, buf, len); localservertoclient(buf, len); // update game state | | | 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | stopreset(); return; } unsigned char buf[MAXTRANS]; gzread(f, buf, len); localservertoclient(buf, len); // update game state Player *target = players[democlientnum]; assert(target); int extras; // read additional client side state not present in normal // network stream if ((extras = gzget())) { target.gunSelect = gzget(); |
︙ | ︙ | |||
448 449 450 451 452 453 454 | // FIXME: set more client state here } // insert latest copy of player into history if (extras && (playerhistory.count == 0 || playerhistory.lastObject.lastUpdate != playbacktime)) { | | | 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | // FIXME: set more client state here } // insert latest copy of player into history if (extras && (playerhistory.count == 0 || playerhistory.lastObject.lastUpdate != playbacktime)) { Player *d = [target copy]; d.lastUpdate = playbacktime; if (playerhistory == nil) playerhistory = [[OFMutableArray alloc] init]; [playerhistory addObject:d]; |
︙ | ︙ | |||
471 472 473 474 475 476 477 | return; int itime = lastmillis - demodelaymsec; // find 2 positions in history that surround interpolation time point size_t count = playerhistory.count; for (ssize_t i = count - 1; i >= 0; i--) { if (playerhistory[i].lastUpdate < itime) { | | | | | | | | | < | | | | | 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 | return; int itime = lastmillis - demodelaymsec; // find 2 positions in history that surround interpolation time point size_t count = playerhistory.count; for (ssize_t i = count - 1; i >= 0; i--) { if (playerhistory[i].lastUpdate < itime) { Player *a = playerhistory[i]; Player *b = a; if (i + 1 < playerhistory.count) b = playerhistory[i + 1]; Player.player1 = b; // interpolate pos & angles if (a != b) { DynamicEntity *c = b; if (i + 2 < playerhistory.count) c = playerhistory[i + 2]; DynamicEntity *z = a; if (i - 1 >= 0) z = playerhistory[i - 1]; // if(a==z || b==c) // printf("* %d\n", lastmillis); float bf = (itime - a.lastUpdate) / (float)(b.lastUpdate - a.lastUpdate); fixwrap(a, b); fixwrap(c, b); fixwrap(z, b); float dist = OFDistanceOfVectors3D(c.origin, z.origin); // if teleport or spawn, don't interpolate if (dist < 16) { catmulrom(z.origin, a.origin, b.origin, c.origin, bf, b.origin); OFVector3D vz = OFMakeVector3D( z.yaw, z.pitch, z.roll); OFVector3D va = OFMakeVector3D( a.yaw, a.pitch, a.roll); OFVector3D vb = OFMakeVector3D( b.yaw, b.pitch, b.roll); OFVector3D vc = OFMakeVector3D( c.yaw, c.pitch, c.roll); OFVector3D vp1 = OFMakeVector3D( b.yaw, b.pitch, b.roll); catmulrom(vz, va, vb, vc, bf, vp1); z.yaw = vz.x; z.pitch = vz.y; z.roll = vz.z; a.yaw = va.x; a.pitch = va.y; a.roll = va.z; b.yaw = vb.x; b.pitch = vb.y; b.roll = vb.z; c.yaw = vc.x; c.pitch = vc.y; c.roll = vc.z; b.yaw = vp1.x; b.pitch = vp1.y; b.roll = vp1.z; } fixplayer1range(); } break; } } // if(player1->state!=CS_DEAD) showscores(false); |
︙ | ︙ |
Modified src/sound.m from [93eb0a5b3c] to [432ff899cb].
1 2 3 | #include "cube.h" #import "Command.h" | | | 1 2 3 4 5 6 7 8 9 10 11 | #include "cube.h" #import "Command.h" #import "Player.h" #include <SDL_mixer.h> VARP(soundvol, 0, 255, 255); VARP(musicvol, 0, 128, 255); bool nosound = false; |
︙ | ︙ | |||
109 110 111 112 113 114 115 | static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; if (loc) { | | | | | 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 | static void updatechanvol(int chan, const OFVector3D *loc) { int vol = soundvol, pan = 255 / 2; if (loc) { OFVector3D origin = Player.player1.origin; float dist = OFDistanceOfVectors3D(origin, *loc); OFVector3D v = OFSubtractVectors3D(origin, *loc); // simple mono distance attenuation vol -= (int)(dist * 3 * soundvol / 255); if (stereo && (v.x != 0 || v.y != 0)) { // relative angle of sound along X-Y axis float yaw = -atan2(v.x, v.y) - Player.player1.yaw * (PI / 180.0f); // range is from 0 (left) to 255 (right) pan = (int)(255.9f * (0.5 * sin(yaw) + 0.5f)); } } vol = (vol * MAXVOL) / 255; Mix_Volume(chan, vol); |
︙ | ︙ |
Modified src/weapon.m from [d5d4aa755b] to [48ff54c543].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // weapon.cpp: all shooting and effects code #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Monster.h" #import "OFString+Cube.h" #import "Projectile.h" static const int MONSTERDAMAGEFACTOR = 4; #define SGRAYS 20 static const float SGSPREAD = 2; static OFVector3D sg[SGRAYS]; | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // weapon.cpp: all shooting and effects code #include "cube.h" #import "Command.h" #import "DynamicEntity.h" #import "Monster.h" #import "OFString+Cube.h" #import "Player.h" #import "Projectile.h" static const int MONSTERDAMAGEFACTOR = 4; #define SGRAYS 20 static const float SGSPREAD = 2; static OFVector3D sg[SGRAYS]; |
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | void selectgun(int a, int b, int c) { if (a < -1 || b < -1 || c < -1 || a >= NUMGUNS || b >= NUMGUNS || c >= NUMGUNS) return; int s = player1.gunSelect; if (a >= 0 && s != a && player1.ammo[a]) s = a; else if (b >= 0 && s != b && player1.ammo[b]) s = b; else if (c >= 0 && s != c && player1.ammo[c]) s = c; | > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | void selectgun(int a, int b, int c) { if (a < -1 || b < -1 || c < -1 || a >= NUMGUNS || b >= NUMGUNS || c >= NUMGUNS) return; Player *player1 = Player.player1; int s = player1.gunSelect; if (a >= 0 && s != a && player1.ammo[a]) s = a; else if (b >= 0 && s != b && player1.ammo[b]) s = b; else if (c >= 0 && s != c && player1.ammo[c]) s = c; |
︙ | ︙ | |||
108 109 110 111 112 113 114 | OFString * playerincrosshair() { if (demoplayback) return NULL; | > | | < | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | OFString * playerincrosshair() { if (demoplayback) return NULL; OFVector3D o = Player.player1.origin; for (Player *player in players) { if (![Player isKindOfClass:Player.class]) continue; if (intersect(player, o, worldpos)) return [player name]; } return nil; } |
︙ | ︙ | |||
158 159 160 161 162 163 164 | } } static void hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at) { OFVector3D o = d.origin; | | | | | > | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | } } static void hit(int target, int damage, __kindof DynamicEntity *d, DynamicEntity *at) { OFVector3D o = d.origin; if (d == Player.player1) selfdamage(damage, (at == Player.player1) ? -1 : -2, at); else if ([d isKindOfClass:Monster.class]) [d incurDamage:damage fromEntity:at]; else if ([d isKindOfClass:Player.class]) { addmsg(1, 4, SV_DAMAGE, target, damage, ((Player *)d).lifeSequence); playsound(S_PAIN1 + rnd(5), &o); } particle_splash(3, damage, 1000, o); demodamage(damage, o); } const float RL_RADIUS = 5; |
︙ | ︙ | |||
215 216 217 218 219 220 221 | playsound(S_RLHIT, &v); newsphere(v, RL_RADIUS, 0); dodynlight(vold, v, 0, 0, p.owner); if (!p.local) return; | | | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | playsound(S_RLHIT, &v); newsphere(v, RL_RADIUS, 0); dodynlight(vold, v, 0, 0, p.owner); if (!p.local) return; radialeffect(Player.player1, v, -1, qdam, p.owner); [players enumerateObjectsUsingBlock:^( id player, size_t i, bool *stop) { if (i == notthisplayer) return; if (player == [OFNull null]) |
︙ | ︙ | |||
275 276 277 278 279 280 281 | v = OFMultiplyVector3D(v, time / dtime); v = OFAddVectors3D(v, po); if (p.local) { for (id player in players) if (player != [OFNull null]) projdamage(player, p, v, i, -1, qdam); | | | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | v = OFMultiplyVector3D(v, time / dtime); v = OFAddVectors3D(v, po); if (p.local) { for (id player in players) if (player != [OFNull null]) projdamage(player, p, v, i, -1, qdam); if (p.owner != Player.player1) projdamage(Player.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) { |
︙ | ︙ | |||
306 307 308 309 310 311 312 | } // create visual effect from a shot void shootv(int gun, OFVector3D from, OFVector3D to, DynamicEntity *d, bool local) { OFVector3D loc = d.origin; | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | } // 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 == Player.player1) ? NULL : &loc); int pspeed = 25; switch (gun) { case GUN_FIST: break; case GUN_SG: { for (int i = 0; i < SGRAYS; i++) |
︙ | ︙ | |||
434 435 436 437 438 439 440 | }]; for (Monster *monster in Monster.monsters) if (monster != d) raydamage(monster, from, to, d, -2); if ([d isKindOfClass:Monster.class]) | | | 438 439 440 441 442 443 444 445 446 | }]; for (Monster *monster in Monster.monsters) if (monster != d) raydamage(monster, from, to, d, -2); if ([d isKindOfClass:Monster.class]) raydamage(Player.player1, from, to, d, -1); } |
Modified src/world.m from [c2453dcf9a] to [1c22ea0614].
1 2 3 4 5 | // world.cpp: core map management stuff #include "cube.h" #import "Command.h" | < > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // world.cpp: core map management stuff #include "cube.h" #import "Command.h" #import "Entity.h" #import "Monster.h" #import "Player.h" extern OFString *entnames[]; // lookup from map entities above to strings struct sqr *world = NULL; int sfactor, ssize, cubicsize, mipsize; struct header hdr; |
︙ | ︙ | |||
294 295 296 297 298 299 300 | __block int best; __block float bdist = 99999; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); | | | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | __block int best; __block float bdist = 99999; [ents enumerateObjectsUsingBlock:^(Entity *e, size_t i, bool *stop) { if (e.type == NOTUSED) return; OFVector3D v = OFMakeVector3D(e.x, e.y, e.z); float dist = OFDistanceOfVectors3D(v, Player.player1.origin); if (dist < bdist) { best = i; bdist = dist; } }]; return (bdist == 99999 ? -1 : best); |
︙ | ︙ | |||
379 380 381 382 383 384 385 | case MAPMODEL: e.attr4 = e.attr3; e.attr3 = e.attr2; case MONSTER: case TELEDEST: e.attr2 = (unsigned char)e.attr1; case PLAYERSTART: | | | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | case MAPMODEL: e.attr4 = e.attr3; e.attr3 = e.attr2; case MONSTER: case TELEDEST: e.attr2 = (unsigned char)e.attr1; case PLAYERSTART: e.attr1 = (int)Player.player1.yaw; break; } addmsg(1, 10, SV_EDITENT, ents.count, type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4); [ents addObject:e]; |
︙ | ︙ |
Modified src/worldocull.m from [80938b4118] to [201c3dd9c9].
1 2 3 4 5 | // worldocull.cpp: occlusion map and occlusion test #include "cube.h" #import "Command.h" | | > > | 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 | // worldocull.cpp: occlusion map and occlusion test #include "cube.h" #import "Command.h" #import "Player.h" #define NUMRAYS 512 float rdist[NUMRAYS]; bool ocull = true; float odist = 256; COMMAND(toggleocull, ARG_NONE, ^{ ocull = !ocull; }) // constructs occlusion map: cast rays in all directions on the 2d plane and // record distance. done exactly once per frame. void computeraytable(float vx, float vy) { Player *player1 = Player.player1; if (!ocull) return; odist = getvar(@"fog") * 1.5f; float apitch = (float)fabs(player1.pitch); float af = getvar(@"fov") / 2 + apitch / 1.5f + 3; |
︙ | ︙ |
Modified src/worldrender.m from [ae30288fea] to [60ed27f341].
1 2 3 4 5 6 | // 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" | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // 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 "Player.h" void render_wall(struct sqr *o, struct sqr *s, int x1, int y1, int x2, int y2, int mip, struct sqr *d1, struct sqr *d2, bool topleft) { if (SOLID(o) || o->type == SEMISOLID) { float c1 = s->floor; |
︙ | ︙ | |||
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | vxx - lodleft; // these mark the rect inside the current rest that // we want to render using a lower mip level int ly = vyy - lodtop; int rx = vxx + lodright; 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 = isoccluded(player1.origin.x, player1.origin.y, (float)(ox << mip), (float)(oy << mip), fsize); } | > | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | vxx - lodleft; // these mark the rect inside the current rest that // we want to render using a lower mip level int ly = vyy - lodtop; int rx = vxx + lodright; int ry = vyy + lodbot; float fsize = (float)(1 << mip); Player *player1 = Player.player1; 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 = isoccluded(player1.origin.x, player1.origin.y, (float)(ox << mip), (float)(oy << mip), fsize); } |
︙ | ︙ |