From b296653ae483d28d404d123e7c0cb5a89e263d9a Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sat, 31 Mar 2007 23:44:27 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@869 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/client.cpp | 102 ++++++------ source/src/clientextras.cpp | 38 ++--- source/src/clientgame.cpp | 172 ++++++++++---------- source/src/clients2c.cpp | 108 ++++++------- source/src/command.cpp | 112 ++++++------- source/src/console.cpp | 84 +++++----- source/src/editing.cpp | 106 ++++++------- source/src/entities.cpp | 86 +++++----- source/src/entity.h | 37 +++-- source/src/geom.h | 36 ++--- source/src/hudgun.cpp | 24 +-- source/src/main.cpp | 60 +++---- source/src/md2.h | 52 +++--- source/src/md3.h | 42 ++--- source/src/menus.cpp | 44 +++--- source/src/model.h | 14 +- source/src/physics.cpp | 78 ++++----- source/src/rendercubes.cpp | 68 ++++---- source/src/renderextras.cpp | 108 ++++++------- source/src/rendergl.cpp | 72 ++++----- source/src/rendermodel.cpp | 46 +++--- source/src/renderparticles.cpp | 28 ++-- source/src/rendertext.cpp | 34 ++-- source/src/rndmap.cpp | 4 +- source/src/savegamedemo.cpp | 94 +++++------ source/src/server.cpp | 278 ++++++++++++++++----------------- source/src/serverbrowser.cpp | 80 +++++----- source/src/serverms.cpp | 36 ++--- source/src/serverutil.cpp | 36 ++--- source/src/sound.cpp | 48 +++--- source/src/tools.h | 148 +++++++++--------- source/src/tristrip.h | 87 +++++------ source/src/vertmodel.h | 102 ++++++------ source/src/weapon.cpp | 150 +++++++++--------- source/src/world.cpp | 98 ++++++------ source/src/worldio.cpp | 84 +++++----- source/src/worldlight.cpp | 42 ++--- source/src/worldocull.cpp | 42 ++--- source/src/worldrender.cpp | 62 ++++---- 39 files changed, 1473 insertions(+), 1469 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index cc6392e9..b986cd7e 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -9,27 +9,27 @@ int connmillis = 0, connattempts = 0, discmillis = 0; int clientnum = -1; // our client id in the game bool c2sinit = false; // whether we need to tell the other clients our stats -int getclientnum() { return clientnum; }; +int getclientnum() { return clientnum; } bool multiplayer() { // check not correct on listen server? if(curpeer) conoutf("operation not available in multiplayer"); return curpeer!=NULL; -}; +} bool allowedittoggle() { bool allow = !curpeer || gamemode==1; if(!allow) conoutf("editing in multiplayer requires coopedit mode (1)"); return allow; -}; +} void setrate(int rate) { if(!curpeer) return; enet_host_bandwidth_limit(clienthost, rate, rate); -}; +} VARF(rate, 0, 0, 25000, setrate(rate)); @@ -44,7 +44,7 @@ void throttle() if(!curpeer) return; ASSERT(ENET_PEER_PACKET_THROTTLE_SCALE==32); enet_peer_throttle_configure(curpeer, throttle_interval*1000, throttle_accel, throttle_decel); -}; +} void newname(char *name) { @@ -54,7 +54,7 @@ void newname(char *name) s_strncpy(player1->name, name, MAXNAMELEN+1); } else conoutf("your name is: %s", player1->name); -}; +} int smallerteam() { @@ -63,7 +63,7 @@ int smallerteam() teamsize[team_int(player1->team)]++; if(teamsize[0] == teamsize[1]) return -1; return teamsize[0] < teamsize[1] ? 0 : 1; -}; +} void changeteam(int team) // force team and respawn { @@ -71,7 +71,7 @@ void changeteam(int team) // force team and respawn if(m_ctf) tryflagdrop(NULL); s_strncpy(player1->team, team_string(team), MAXTEAMLEN+1); deathstate(player1); -}; +} void newteam(char *name) { @@ -80,7 +80,7 @@ void newteam(char *name) if(m_teammode) { if(!strcmp(name, player1->team)) return; // same team - if(!team_valid(name)) { conoutf("\f3\"%s\" is not a valid team name (try CLA or RVSF)", name); return; }; + if(!team_valid(name)) { conoutf("\f3\"%s\" is not a valid team name (try CLA or RVSF)", name); return; } bool checkteamsize = autoteambalance && players.length() >= 1 && !m_botmode; int freeteam = smallerteam(); @@ -92,16 +92,16 @@ void newteam(char *name) { conoutf("\f3the %s team is already full", name); return; - }; + } changeteam(team); } else changeteam(checkteamsize ? (uint)freeteam : rnd(2)); // random assignement - }; + } } else conoutf("your team is: %s", player1->team); -}; +} -void newskin(int skin) { player1->nextskin = skin; }; +void newskin(int skin) { player1->nextskin = skin; } COMMANDN(team, newteam, ARG_1STR); COMMANDN(name, newname, ARG_1STR); @@ -117,7 +117,7 @@ void abortconnect() if(curpeer) return; enet_host_destroy(clienthost); clienthost = NULL; -}; +} void connects(char *servername, char *password) { @@ -125,7 +125,7 @@ void connects(char *servername, char *password) { conoutf("aborting connection attempt"); abortconnect(); - }; + } s_strcpy(clientpassword, password ? password : ""); @@ -140,13 +140,13 @@ void connects(char *servername, char *password) { conoutf("\f3could not resolve server %s", servername); return; - }; + } } else { conoutf("attempting to connect over LAN"); address.host = ENET_HOST_BROADCAST; - }; + } if(!clienthost) clienthost = enet_host_create(NULL, 2, rate, rate); @@ -158,12 +158,12 @@ void connects(char *servername, char *password) connattempts = 0; } else conoutf("\f3could not connect to server"); -}; +} void lanconnect() { connects(0); -}; +} void disconnect(int onlyclean, int async) { @@ -175,17 +175,17 @@ void disconnect(int onlyclean, int async) enet_peer_disconnect(curpeer, DISC_NONE); enet_host_flush(clienthost); discmillis = lastmillis; - }; + } if(curpeer->state!=ENET_PEER_STATE_DISCONNECTED) { if(async) return; enet_peer_reset(curpeer); - }; + } curpeer = NULL; discmillis = 0; conoutf("disconnected"); cleanup = true; - }; + } if(cleanup) { stop(); @@ -196,14 +196,14 @@ void disconnect(int onlyclean, int async) if(m_botmode) BotManager.EndMap(); loopv(players) zapplayer(players[i]); localdisconnect(); - }; + } if(!connpeer && clienthost) { enet_host_destroy(clienthost); clienthost = NULL; - }; + } if(!onlyclean) localconnect(); -}; +} void trydisconnect() { @@ -212,18 +212,18 @@ void trydisconnect() conoutf("aborting connection attempt"); abortconnect(); return; - }; + } if(!curpeer) { conoutf("not connected"); return; - }; + } conoutf("attempting to disconnect..."); disconnect(0, !discmillis); -}; +} -void toserver(char *text) { conoutf("%s:\f0 %s", player1->name, text); addmsg(SV_TEXT, "rs", text); }; -void echo(char *text) { conoutf("%s", text); }; +void toserver(char *text) { conoutf("%s:\f0 %s", player1->name, text); addmsg(SV_TEXT, "rs", text); } +void echo(char *text) { conoutf("%s", text); } COMMAND(echo, ARG_VARI); COMMANDN(say, toserver, ARG_VARI); @@ -256,18 +256,18 @@ void addmsg(int type, const char *fmt, ...) loopi(n) putint(p, va_arg(args, int)); numi += n; break; - }; + } case 's': sendstring(va_arg(args, const char *), p); nums++; break; - }; + } va_end(args); - }; + } int num = nums?0:numi; - if(num!=msgsizelookup(type)) { s_sprintfd(s)("inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); fatal(s); }; + if(num!=msgsizelookup(type)) { s_sprintfd(s)("inconsistant msg size for %d (%d != %d)", type, num, msgsizelookup(type)); fatal(s); } int len = p.length(); messages.add(len&0xFF); messages.add((len>>8)|(reliable ? 0x80 : 0)); loopi(len) messages.add(buf[i]); -}; +} int lastupdate = 0, lastping = 0; bool senditemstoserver = false; // after a map change, since server doesn't have map data @@ -278,7 +278,7 @@ void initclientnet() { newname("unnamed"); changeteam(rnd(2)); -}; +} void sendpackettoserv(int chan, ENetPacket *packet) { @@ -289,7 +289,7 @@ void sendpackettoserv(int chan, ENetPacket *packet) void c2skeepalive() { if(clienthost) enet_host_service(clienthost, NULL, 0); -}; +} extern string masterpwd; @@ -329,7 +329,7 @@ void c2sinfo(dynent *d) // send update to the server putint(p, SV_PWD); sendstring(clientpassword, p); clientpassword[0] = 0; - }; + } if(!c2sinit) // tell other clients who I am { packet->flags = ENET_PACKET_FLAG_RELIABLE; @@ -339,14 +339,14 @@ void c2sinfo(dynent *d) // send update to the server sendstring(player1->team, p); putint(p, player1->skin); putint(p, player1->lifesequence); - }; + } if(gun_changed) { packet->flags = ENET_PACKET_FLAG_RELIABLE; putint(p, SV_WEAPCHANGE); putint(p, player1->gunselect); gun_changed = false; - }; + } if(senditemstoserver) { packet->flags = ENET_PACKET_FLAG_RELIABLE; @@ -355,7 +355,7 @@ void c2sinfo(dynent *d) // send update to the server putint(p, -1); senditemstoserver = false; serveriteminitdone = true; - }; + } int i = 0; while(i < messages.length()) // send messages collected during the previous frames { @@ -364,26 +364,26 @@ void c2sinfo(dynent *d) // send update to the server if(messages[i+1]&0x80) packet->flags = ENET_PACKET_FLAG_RELIABLE; p.put(&messages[i+2], len); i += 2 + len; - }; + } messages.remove(0, i); if(lastmillis-lastping>250) { putint(p, SV_PING); putint(p, lastmillis); lastping = lastmillis; - }; + } if(!p.length()) enet_packet_destroy(packet); else { enet_packet_resize(packet, p.length()); incomingdemodata(42, p.buf, p.length()); sendpackettoserv(1, packet); - }; - }; + } + } if(clienthost) enet_host_flush(clienthost); lastupdate = lastmillis; if(serveriteminitdone) loadgamerest(); // hack -}; +} void gets2c() // get updates from the server { @@ -399,8 +399,8 @@ void gets2c() // get updates from the server conoutf("\f3could not connect to server"); abortconnect(); return; - }; - }; + } + } while(clienthost!=NULL && enet_host_service(clienthost, &event, 0)>0) switch(event.type) { @@ -432,10 +432,10 @@ void gets2c() // get updates from the server { if(!discmillis || event.data) conoutf("\f3server network error, disconnecting (%s) ...", disc_reasons[event.data]); disconnect(); - }; + } return; default: break; - }; -}; + } +} diff --git a/source/src/clientextras.cpp b/source/src/clientextras.cpp index 0f641f47..58837e0f 100644 --- a/source/src/clientextras.cpp +++ b/source/src/clientextras.cpp @@ -26,8 +26,8 @@ void renderclient(playerent *d, char *mdlname, char *vwepname, int tex) { t -= (r+10)*100; mz -= t*t/10000000000.0f*t; - }; - }; + } + } //if(mz<-1000) return; } else if(d->state==CS_EDITING) { anim = ANIM_JUMP|ANIM_END; } @@ -37,9 +37,9 @@ void renderclient(playerent *d, char *mdlname, char *vwepname, int tex) else if(d->gunselect==d->lastattackgun && lastmillis-d->lastaction<300) { anim = ANIM_ATTACK; speed = 300.0f/8; basetime = d->lastaction; } else if(!d->move && !d->strafe) { anim = ANIM_IDLE|ANIM_LOOP; } - else { anim = ANIM_RUN|ANIM_LOOP; speed = 1860/d->maxspeed; }; + else { anim = ANIM_RUN|ANIM_LOOP; speed = 1860/d->maxspeed; } rendermodel(mdlname, anim, tex, 1.5f, d->o.x, mz, d->o.y, d->yaw+90, d->pitch/4, speed, basetime, d, vwepname); -}; +} extern int democlientnum; @@ -53,7 +53,7 @@ void renderplayer(playerent *d) if(d->gunselect>=0 && d->gunselectgunselect]); else vwep[0] = 0; renderclient(d, "playermodels", vwep[0] ? vwep : NULL, -textureload(skin)->id); -}; +} void renderclients() { @@ -61,10 +61,10 @@ void renderclients() loopv(players) if((d = players[i]) && (!demoplayback || i!=democlientnum)) { renderplayer(d); - }; + } if(player1->state==CS_DEAD) renderplayer(player1); -}; +} // creation of scoreboard pseudo-menu @@ -73,7 +73,7 @@ void *scoremenu = NULL, *ctfmenu = NULL; void showscores(bool on) { menuset(on ? (m_ctf ? ctfmenu : scoremenu) : NULL); -}; +} struct sline { string s; }; vector scorelines; @@ -85,14 +85,14 @@ void renderscore(void *menu, playerent *d, int cn) if(m_ctf) s_sprintf(scorelines.add().s)("%d\t%d\t%s\t%d\t%s\t%s%s\t%d", d->flagscore, d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, d->team, d->ismaster ? "\f0" : "", d->state==CS_DEAD ? name : d->name, cn); else s_sprintf(scorelines.add().s)("%d\t%s\t%d\t%s\t%s%s\t%d", d->frags, d->state==CS_LAGGED ? "LAG" : lag, d->ping, m_teammode ? d->team : "", d->ismaster ? "\f0" : "", d->state==CS_DEAD ? name : d->name, cn); menumanual(menu, scorelines.length()-1, scorelines.last().s); -}; +} struct teamscore { char *team; int score, flagscore; - teamscore() {}; - teamscore(char *s, int n, int f = 0) : team(s), score(n), flagscore(f) {}; + teamscore() {} + teamscore(char *s, int n, int f = 0) : team(s), score(n), flagscore(f) {} }; static int teamscorecmp(const teamscore *x, const teamscore *y) @@ -102,7 +102,7 @@ static int teamscorecmp(const teamscore *x, const teamscore *y) if(x->score > y->score) return -1; if(x->score < y->score) return 1; return 0; -}; +} vector teamscores; @@ -114,9 +114,9 @@ void addteamscore(playerent *d) teamscores[i].score += d->frags; if(m_ctf) teamscores[i].flagscore += d->flagscore; return; - }; + } teamscores.add(teamscore(d->team, d->frags, m_ctf ? d->flagscore : 0)); -}; +} void renderscores() { @@ -141,10 +141,10 @@ void renderscores() if(m_ctf) s_sprintf(s)("[ %s: %d flags %d frags ]", teamscores[i].team, teamscores[i].flagscore, teamscores[i].score); else s_sprintf(s)("[ %s: %d ]", teamscores[i].team, teamscores[i].score); s_strcat(teamline, s); - }; + } menumanual(menu, scorelines.length(), teamline); - }; -}; + } +} // sendmap/getmap commands, should be replaced by more intuitive map downloading @@ -154,7 +154,7 @@ void sendmap(char *mapname) { save_world(mapname); changemap(mapname); - }; + } mapname = getclientmap(); int mapsize; uchar *mapdata = readmap(mapname, &mapsize); @@ -170,7 +170,7 @@ void sendmap(char *mapname) delete[] mapdata; enet_packet_destroy(packet); return; - }; + } p.put(mapdata, mapsize); delete[] mapdata; enet_packet_resize(packet, p.length()); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index e90be0e3..0e4dfce5 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -11,7 +11,7 @@ flaginfo flaginfos[2]; void mode(int n) { if(m_mp(n) || !multiplayer()) addmsg(SV_GAMEMODE, "ri", nextmode = n); -}; +} COMMAND(mode, ARG_1INT); bool intermission = false; @@ -30,7 +30,7 @@ string clientmap; extern int framesinmap; -char *getclientmap() { return clientmap; }; +char *getclientmap() { return clientmap; } extern bool c2sinit; extern int dblend; @@ -41,7 +41,7 @@ void setskin(playerent *pl, uint skin) if(pl == player1) c2sinit=false; const int maxskin[2] = { 3, 5 }; pl->skin = skin % (maxskin[team_int(pl->team)]+1); -}; +} extern void throw_nade(playerent *d, const vec &vel, bounceent *p); @@ -56,7 +56,7 @@ void deathstate(playerent *pl) pl->strafe = 0; dblend = 0; if(pl == player1 && pl->inhandnade) throw_nade(pl, vec(0,0,0), pl->inhandnade); -}; +} void spawnstate(playerent *d) // reset player state not persistent accross spawns { @@ -67,10 +67,10 @@ void spawnstate(playerent *d) // reset player state not persistent gun_changed = true; if(player1->skin!=player1->nextskin) setskin(player1, player1->nextskin); setscope(false); - }; + } equip(d); if(m_osok) d->health = 1; -}; +} playerent *newplayerent() // create a new blank player { @@ -79,7 +79,7 @@ playerent *newplayerent() // create a new blank player setskin(d, rnd(6)); spawnstate(d); return d; -}; +} botent *newbotent() // create a new blank player { @@ -91,19 +91,19 @@ botent *newbotent() // create a new blank player { players[i] = d; return d; - }; + } if(players.length()==getclientnum()) players.add(NULL); players.add(d); return d; -}; +} void freebotent(botent *d) { loopv(players) if(players[i]==d) { DELETEP(players[i]); - }; -}; + } +} @@ -111,19 +111,19 @@ void respawnself() { spawnplayer(player1); showscores(false); -}; +} void respawn() { if(player1->state==CS_DEAD && lastmillis>player1->lastaction+(m_ctf ? 5000 : 2000)) { player1->attacking = false; - if(m_arena) { conoutf("waiting for new round to start..."); return; }; + if(m_arena) { conoutf("waiting for new round to start..."); return; } respawnself(); weaponswitch(player1->primary); player1->lastaction -= WEAPONCHANGE_TIME/2; - }; -}; + } +} void arenacount(playerent *d, int &alive, int &dead, char *&lastteam, char *&lastname, bool &oneteam) { @@ -137,8 +137,8 @@ void arenacount(playerent *d, int &alive, int &dead, char *&lastteam, char *&las else { dead++; - }; -}; + } +} bool arenajoin = false; int arenarespawnwait = 0; @@ -153,7 +153,7 @@ void arenarespawn() if(player1->state!=CS_DEAD) arenajoin = false; else loopv(players) if(players[i]) arenajoin = false; if(arenajoin) return; - }; + } if(arenarespawnwait) { @@ -166,7 +166,7 @@ void arenarespawn() if(m_botmode) BotManager.RespawnBots(); //End add by Rick clearbounceents(); - }; + } } else if(arenadetectwait==0 || arenadetectwaitroll = 0; - }; - }; -}; + } + } +} void checkakimbo() @@ -208,12 +208,12 @@ void checkakimbo() if(player1->gunselect==GUN_PISTOL) weaponswitch(GUN_PISTOL); playsoundc(S_PUPOUT); } -}; +} void zapplayer(playerent *&d) { DELETEP(d); -}; +} extern int democlientnum; @@ -229,8 +229,8 @@ void otherplayers() } else if(!lagtime || intermission) continue; if(!demoplayback || i!=democlientnum) moveplayer(players[i], 2, false); // use physics to extrapolate player position - }; -}; + } +} struct scriptsleep { int wait; char *cmd; }; vector sleeps; @@ -240,7 +240,7 @@ void addsleep(char *msec, char *cmd) scriptsleep &s = sleeps.add(); s.wait = atoi(msec)+lastmillis; s.cmd = newstring(cmd); -}; +} COMMANDN(sleep, addsleep, ARG_2STR); @@ -253,8 +253,8 @@ void updateworld(int curtime, int lastmillis) // main game update loop execute(sleeps[i].cmd); delete[] sleeps[i].cmd; sleeps.remove(i--); - }; - }; + } + } physicsframe(); checkakimbo(); checkweaponswitch(); @@ -266,7 +266,7 @@ void updateworld(int curtime, int lastmillis) // main game update loop { if(getclientnum()>=0) shoot(player1, worldpos); // only shoot when connected to server gets2c(); // do this first, so we have most accurate information when our player moves - }; + } mbounceents(); otherplayers(); if(!demoplayback) @@ -283,16 +283,16 @@ void updateworld(int curtime, int lastmillis) // main game update loop { player1->move = player1->strafe = 0; moveplayer(player1, 10, false); - }; + } } else if(!intermission) { moveplayer(player1, 20, true); checkitems(player1); - }; + } c2sinfo(player1); // do this last, to reduce the effective frame lag - }; -}; + } +} void entinmap(physent *d) // brute force but effective way to find a free spawn spot in the map { @@ -305,10 +305,10 @@ void entinmap(physent *d) // brute force but effective way to find a free spa if(collide(d, true, 0, 0)) return; d->o.x -= dx; d->o.y -= dy; - }; + } conoutf("can't find entity spawn spot! (%d, %d)", d->o.x, d->o.y); // leave ent at original pos, possibly stuck -}; +} #define SECURESPAWNDIST 15 @@ -325,10 +325,10 @@ float nearestenemy(vec place, char *team) if(!other || isteam(team, other->team)) continue; float dist = place.dist(other->o); if(dist < nearestenemydist || nearestenemydist == -1) nearestenemydist = dist; - }; + } if(nearestenemydist >= SECURESPAWNDIST || nearestenemydist == -1) return -2; else return nearestenemydist; -}; +} int findplayerstart(playerent *d) { @@ -347,12 +347,12 @@ int findplayerstart(playerent *d) if(spawncycle < 0 || spawncycle >= ents.length()) continue; float dist = nearestenemy(vec(ents[spawncycle].x, ents[spawncycle].y, ents[spawncycle].z), d->team); if(dist == -2 || (bestdist != -2 && dist > bestdist) || bestent == -1) { bestent = spawncycle; bestdist = dist; } - }; + } return bestent; - }; + } return spawncycle; -}; +} void spawnplayer(playerent *d) // place at random spawn { @@ -370,16 +370,16 @@ void spawnplayer(playerent *d) // place at random spawn { d->o.x = d->o.y = (float)ssize/2; d->o.z = 4; - }; + } entinmap(d); spawnstate(d); d->state = CS_ALIVE; -}; +} // movement input code -#define dir(name,v,d,s,os) void name(bool isdown) { player1->s = isdown; player1->v = isdown ? d : (player1->os ? -(d) : 0); player1->lastmove = lastmillis; }; +#define dir(name,v,d,s,os) void name(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); @@ -392,7 +392,7 @@ void attack(bool on) if(editmode) editdrag(on); else if(player1->state==CS_DEAD) respawn(); else player1->attacking = on; -}; +} void jumpn(bool on) { @@ -402,7 +402,7 @@ void jumpn(bool on) if(on) respawn(); } else player1->jumpnext = on; -}; +} COMMAND(backward, ARG_DOWN); COMMAND(forward, ARG_DOWN); @@ -419,7 +419,7 @@ void fixcamerarange(physent *cam) if(cam->pitch<-MAXPITCH) cam->pitch = -MAXPITCH; while(cam->yaw<0.0f) cam->yaw += 360.0f; while(cam->yaw>=360.0f) cam->yaw -= 360.0f; -}; +} void mousemove(int dx, int dy) { @@ -432,10 +432,10 @@ void mousemove(int dx, int dy) { player1->yaw = camera1->yaw; player1->pitch = camera1->pitch; - }; -}; + } +} -void showteamkill() { player1->lastteamkill = lastmillis; }; +void showteamkill() { player1->lastteamkill = lastmillis; } // damage arriving from the network, monsters, yourself, all ends up here. @@ -447,7 +447,7 @@ void selfdamage(int damage, int actor, playerent *act, bool gib, playerent *pl) { damageblend(damage); demoblend(damage); - }; + } int ad = damage*30/100; // let armour absorb when possible if(ad>pl->armour) ad = pl->armour; pl->armour -= ad; @@ -474,7 +474,7 @@ void selfdamage(int damage, int actor, playerent *act, bool gib, playerent *pl) { act->frags += gib ? 2 : 1; conoutf("\f2%s %s %s", act==player1 ? "you" : act->name, death, pl->name); - }; + } } else if(act==pl) { @@ -486,14 +486,14 @@ void selfdamage(int damage, int actor, playerent *act, bool gib, playerent *pl) { if(isteam(act->team, player1->team)) conoutf("\f2you got %s by a teammate (%s)", death, act->name); else conoutf("\f2you got %s by %s", death, act->name); - }; + } if(pl==player1) { showscores(true); setscope(false); addmsg(gib ? SV_GIBDIED : SV_DIED, "ri", actor); if(m_ctf) tryflagdrop(act && isteam(act->team, player1->team)); - }; + } deathstate(pl); pl->lifesequence++; playsound(S_DIE1+rnd(2), pl!=player1 ? &pl->o : NULL); @@ -504,8 +504,8 @@ void selfdamage(int damage, int actor, playerent *act, bool gib, playerent *pl) else { playsound(S_PAIN6, pl!=player1 ? &pl->o : NULL); - }; -}; + } +} void timeupdate(int timeremain) { @@ -521,8 +521,8 @@ void timeupdate(int timeremain) else { conoutf("time remaining: %d minutes", timeremain); - }; -}; + } +} playerent *newclient(int cn) // ensure valid entity { @@ -530,21 +530,21 @@ playerent *newclient(int cn) // ensure valid entity { neterr("clientnum"); return NULL; - }; + } while(cn>=players.length()) players.add(NULL); return players[cn] ? players[cn] : (players[cn] = newplayerent()); -}; +} playerent *getclient(int cn) // ensure valid entity { return players.inrange(cn) ? players[cn] : NULL; -}; +} void initclient() { clientmap[0] = 0; initclientnet(); -}; +} entity flagdummies[2]; // in case the map does not provide flags @@ -559,7 +559,7 @@ void preparectf(bool cleanonly=false) if(e.type==CTF_FLAG) { e.spawned = true; - if(e.attr2>2) { conoutf("\f3invalid ctf-flag entity (%i)", i); e.attr2 = 0; }; + if(e.attr2>2) { conoutf("\f3invalid ctf-flag entity (%i)", i); e.attr2 = 0; } flaginfo &f = flaginfos[e.attr2]; f.team = e.attr2; f.flag = &e; @@ -567,16 +567,16 @@ void preparectf(bool cleanonly=false) f.originalpos.x = (float) e.x; f.originalpos.y = (float) e.y; f.originalpos.z = (float) e.z; - }; - }; - }; -}; + } + } + } +} extern void kickallbots(void); void startmap(char *name) // called just after a map load { - //if(netmapstart()) { gamemode = 0;}; //needs fixed to switch modes? + //if(netmapstart()) { gamemode = 0;} //needs fixed to switch modes? netmapstart(); //should work //monsterclear(); // Added by Rick @@ -602,7 +602,7 @@ void startmap(char *name) // called just after a map load intermission = false; if(*clientmap) conoutf("game mode is \"%s\"", modestr(gamemode)); clearbounceents(); -}; +} COMMANDN(map, changemap, ARG_1STR); @@ -611,7 +611,7 @@ void suicide() if(player1->state==CS_DEAD) return; selfdamage(1000, -1, player1); demodamage(1000, player1->o); -}; +} COMMAND(suicide, ARG_NONE); @@ -630,21 +630,21 @@ void flagmsg(int flag, int action) if(f.actor==player1) conoutf("\f2you got the enemy flag"); else conoutf("\f2%s got %s flag", f.actor->name, (own ? "your": "the enemy")); break; - }; + } case SV_FLAGDROP: { playsound(S_FLAGDROP); if(f.actor==player1) conoutf("you lost the flag"); else conoutf("\f2%s lost %s flag", f.actor->name, (own ? "your" : "the enemy")); break; - }; + } case SV_FLAGRETURN: { playsound(S_FLAGRETURN); if(f.actor==player1) conoutf("you returned your flag"); else conoutf("\f2%s returned %s flag", f.actor->name, (own ? "your" : "the enemy")); break; - }; + } case SV_FLAGSCORE: { playsound(S_FLAGSCORE); @@ -655,16 +655,16 @@ void flagmsg(int flag, int action) } else conoutf("\f2%s scored for %s team", f.actor->name, (own ? "the enemy" : "your")); break; - }; + } case SV_FLAGRESET: { playsound(S_FLAGRETURN); conoutf("the server reset the flag"); break; - }; + } default: break; - }; -}; + } +} // server administration @@ -679,19 +679,19 @@ void setmaster(char *claim, char *password) else addmsg(SV_SETMASTERLOGIN, "ris", c, password); } else addmsg(SV_SETMASTER, "ri", c); -}; +} void mastercommand(int cmd, int a) // one of MCMD_* { if(player1->ismaster) addmsg(SV_MASTERCMD, "rii", cmd, a); else conoutf("\f3you have to be master to perform this action"); -}; +} -void kick(int player) { mastercommand(MCMD_KICK, player); }; -void ban(int player) { mastercommand(MCMD_BAN, player); }; -void removebans() { mastercommand(MCMD_REMBANS, 0); }; -void autoteam(int enable) { mastercommand(MCMD_AUTOTEAM, enable); }; -void mastermode(int mode) { mastercommand(MCMD_MASTERMODE, mode); }; +void kick(int player) { mastercommand(MCMD_KICK, player); } +void ban(int player) { mastercommand(MCMD_BAN, player); } +void removebans() { mastercommand(MCMD_REMBANS, 0); } +void autoteam(int enable) { mastercommand(MCMD_AUTOTEAM, enable); } +void mastermode(int mode) { mastercommand(MCMD_MASTERMODE, mode); } COMMAND(setmaster, ARG_2STR); COMMAND(kick, ARG_1INT); @@ -716,9 +716,9 @@ void showmastermenu(int m) // 0=kick, 1=ban string &s = mlines.add().cmd; s_sprintf(s)("%s %d", m == MCMD_KICK ? "kick" : "ban", i); menumanual(menu, item++, players[i]->name, s); - }; + } menuset(menu); -}; +} COMMAND(showmastermenu, ARG_1INT); diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 30611a1c..f059d952 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -10,18 +10,18 @@ void neterr(char *s) { conoutf("\f3illegal network message (%s)", s); disconnect(); -}; +} void changemapserv(char *name, int mode) // forced map change from the server { gamemode = mode; load_world(name); -}; +} void changemap(char *name) // request map change, server may ignore { addmsg(SV_MAPCHANGE, "rsi", name, nextmode); -}; +} // update the position of other clients in the game in our world // don't care if he's in the scenery or other players, @@ -39,14 +39,14 @@ void updatepos(playerent *d) { if(fxo.y += dy<0 ? r-fy : -(r-fy); // push aside else d->o.x += dx<0 ? r-fx : -(r-fx); - }; + } int lagtime = lastmillis-d->lastupdate; if(lagtime) { d->plag = (d->plag*5+lagtime)/6; d->lastupdate = lastmillis; - }; -}; + } +} extern void trydisconnect(); @@ -90,13 +90,13 @@ void parsepositions(ucharbuf &p) d->onladder = f&1; if(!demoplayback) updatepos(d); break; - }; + } default: neterr("type"); return; - }; -}; + } +} void parsemessages(int cn, playerent *d, ucharbuf &p) { @@ -114,13 +114,13 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) conoutf("you are using a different game protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot); disconnect(); return; - }; + } clientnum = mycn; // we are now fully connected joining = getint(p); if(getint(p) > 0) conoutf("INFO: this server is password protected"); if(joining<0 && getclientmap()[0]) changemap(getclientmap()); // we are the first client on this server, set map break; - }; + } case SV_CLIENT: { @@ -128,7 +128,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) ucharbuf q = p.subbuf(len); parsemessages(cn, getclient(cn), q); break; - }; + } case SV_SOUND: playsound(getint(p), d ? &d->o : NULL); @@ -148,17 +148,17 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) deathstate(player1); showscores(true); arenajoin = true; - }; + } mapchanged = true; break; case SV_ITEMLIST: { int n; - if(mapchanged) { senditemstoserver = false; resetspawns(); }; + if(mapchanged) { senditemstoserver = false; resetspawns(); } while((n = getint(p))!=-1) if(mapchanged) setspawn(n, true); break; - }; + } case SV_MAPRELOAD: // server requests next map { @@ -167,7 +167,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) char *map = getalias(nextmapalias); // look up map in the cycle changemap(map ? map : getclientmap()); break; - }; + } case SV_INITC2S: // another client either connected or changed name/team { @@ -184,7 +184,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) c2sinit = false; // send new players my info again conoutf("connected: %s", &text); gun_changed = true; - }; + } s_strncpy(d->name, text, MAXNAMELEN+1); getstring(text, p); s_strncpy(d->team, text, MAXTEAMLEN+1); @@ -195,9 +195,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { flaginfo &f = flaginfos[i]; if(!f.actor) f.actor = getclient(f.actor_cn); - }; + } break; - }; + } case SV_CDIS: { @@ -207,7 +207,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) if(d->name[0]) conoutf("player %s disconnected", d->name); zapplayer(players[cn]); break; - }; + } case SV_SHOT: { @@ -225,7 +225,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) d->lastattackgun = gun; shootv(gun, s, e, d, false, getint(p)); break; - }; + } case SV_GIBDAMAGE: gib = true; case SV_DAMAGE: @@ -242,11 +242,11 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { playsound(S_PAIN1+rnd(5), &victim->o); victim->lastpain = lastmillis; - }; - }; + } + } gib = false; break; - }; + } case SV_GIBDIED: gib = true; @@ -277,7 +277,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { frags = gib ? 2 : 1; conoutf("\f2you %s %s", death, d->name); - }; + } addmsg(SV_FRAGS, "ri", player1->frags += frags); if(gib) addgib(d); } @@ -294,16 +294,16 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) else { conoutf("\f2%s %s %s", a->name, death, d->name); - }; + } if(gib) addgib(d); - }; - }; + } + } playsound(S_DIE1+rnd(2), &d->o); if(act && act->gunselect == GUN_SNIPER && gib) playsound(S_HEADSHOT); if(!c2si) d->lifesequence++; gib = false; break; - }; + } case SV_FRAGS: if(!d) return; @@ -318,9 +318,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { d->frags = frags; d->flagscore = flags; - }; + } break; - }; + } case SV_ITEMPICKUP: setspawn(getint(p), false); @@ -332,7 +332,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) uint i = getint(p); setspawn(i, true); break; - }; + } case SV_ITEMACC: // server acknowledges that I picked up this item realpickup(getint(p), player1); @@ -357,9 +357,9 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_EDITS: edittypexy(v, b); break; case SV_EDITD: setvdeltaxy(v, b); break; case SV_EDITE: editequalisexy(v!=0, b); break; - }; + } break; - }; + } case SV_EDITENT: // coop edit of ent { @@ -377,7 +377,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) ents[i].spawned = false; if(ents[i].type==LIGHT || to==LIGHT) calclight(); break; - }; + } case SV_PONG: addmsg(SV_CLIENTPING, "i", player1->ping = (player1->ping*5+lastmillis-getint(p))/6); @@ -405,19 +405,19 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { p.forceoverread(); break; - }; + } writemap(text, mapsize, &p.buf[p.len]); p.len += mapsize; changemapserv(text, gamemode); break; - }; + } case SV_WEAPCHANGE: { if(!d) return; d->gunselect = getint(p); break; - }; + } case SV_SERVMSG: getstring(text, p); @@ -438,7 +438,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { flagstolen(flag, action, getint(p)); break; - }; + } case CTFF_DROPPED: { short x = (ushort) (getint(p)/DMF); @@ -446,24 +446,24 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) short z = (ushort) (getint(p)/DMF); flagdropped(flag, action, x, y, z); break; - }; + } case CTFF_INBASE: { int actor = -1; if(action == SV_FLAGRETURN) actor = getint(p); flaginbase(flag, action, actor); break; - }; - }; + } + } break; - }; + } case SV_FLAGS: { if(!d) return; d->flagscore = getint(p); break; - }; + } case SV_MASTERINFO: { @@ -478,10 +478,10 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) { pl->ismaster = true; conoutf("%s claimed master status", pl == player1 ? "you" : pl->name); - }; - }; + } + } break; - }; + } case SV_MASTERCMD: { @@ -507,16 +507,16 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) autoteambalance = arg == 1; if(!joining) conoutf("autoteam is %s", autoteambalance ? "enabled" : "disabled"); break; - }; + } break; - }; + } case SV_FORCETEAM: { changeteam(getint(p)); if(!m_arena || joining<=1) spawnplayer(player1); break; - }; + } /* demo recording compat */ case SV_PING: @@ -526,8 +526,8 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) default: neterr("type"); return; - }; -}; + } +} void localservertoclient(int chan, uchar *buf, int len) // processes any updates from the server { @@ -544,5 +544,5 @@ void localservertoclient(int chan, uchar *buf, int len) // processes any updat extern int democlientnum; parsemessages(democlientnum, getclient(democlientnum), p); break; - }; -}; + } +} diff --git a/source/src/command.cpp b/source/src/command.cpp index 34675401..3c7e8a5c 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -17,8 +17,8 @@ struct ident bool persist; }; -void itoa(char *s, int i) { s_sprintf(s)("%d", i); }; -char *exchangestr(char *o, char *n) { delete[] o; return newstring(n); }; +void itoa(char *s, int i) { s_sprintf(s)("%d", i); } +char *exchangestr(char *o, char *n) { delete[] o; return newstring(n); } hashtable *idents = NULL; // contains ALL vars/commands/aliases @@ -40,7 +40,7 @@ void alias(char *name, char *action) if(b->persist!=persistidents) b->persist = persistidents; } else conoutf("cannot redefine builtin %s with an alias", name); -}; +} COMMAND(alias, ARG_2STR); @@ -52,17 +52,17 @@ int variable(char *name, int min, int cur, int max, int *storage, void (*fun)(), ident v = { ID_VAR, name, min, max, storage, fun, 0, 0, 0, persist }; idents->access(name, &v); return cur; -}; +} -void setvar(char *name, int i) { *idents->access(name)->storage = i; }; -int getvar(char *name) { return *idents->access(name)->storage; }; -bool identexists(char *name) { return idents->access(name)!=NULL; }; +void setvar(char *name, int i) { *idents->access(name)->storage = i; } +int getvar(char *name) { return *idents->access(name)->storage; } +bool identexists(char *name) { return idents->access(name)!=NULL; } char *getalias(char *name) { ident *i = idents->access(name); return i && i->type==ID_ALIAS ? i->action : NULL; -}; +} bool addcommand(char *name, void (*fun)(), int narg) { @@ -70,7 +70,7 @@ bool addcommand(char *name, void (*fun)(), int narg) ident c = { ID_COMMAND, name, 0, 0, 0, fun, narg, 0, 0, false }; idents->access(name, &c); return false; -}; +} char *parseexp(char *&p, int right) // parse any nested set of () or [] { @@ -81,17 +81,17 @@ char *parseexp(char *&p, int right) // parse any nested set of () or int c = *p++; if(c==left) brak++; else if(c==right) brak--; - else if(!c) { p--; conoutf("missing \"%c\"", right); return NULL; }; - }; + else if(!c) { p--; conoutf("missing \"%c\"", right); return NULL; } + } char *s = newstring(word, p-word-1); if(left=='(') { string t; itoa(t, execute(s)); // evaluate () exps directly, and substitute result s = exchangestr(s, t); - }; + } return s; -}; +} char *parseword(char *&p) // parse single argument, including expressions { @@ -105,14 +105,14 @@ char *parseword(char *&p) // parse single argument, includ char *s = newstring(word, p-word); if(*p=='\"') p++; return s; - }; + } if(*p=='(') return parseexp(p, ')'); if(*p=='[') return parseexp(p, ']'); char *word = p; p += strcspn(p, "; \t\r\n\0"); if(p-word==0) return NULL; return newstring(word, p-word); -}; +} char *lookup(char *n) // find value of ident referenced with $ in exp { @@ -121,10 +121,10 @@ char *lookup(char *n) // find value of ident reference { case ID_VAR: string t; itoa(t, *(id->storage)); return exchangestr(n, t); case ID_ALIAS: return exchangestr(n, id->action); - }; + } conoutf("unknown alias lookup: %s", n+1); return n; -}; +} int execute(char *p) // all evaluation happens here, recursively { @@ -139,10 +139,10 @@ int execute(char *p) // all evaluation happens here, w[i] = ""; if(i>numargs) continue; char *s = parseword(p); // parse and evaluate exps - if(!s) { numargs = i; s = ""; }; + if(!s) { numargs = i; s = ""; } if(*s=='$') s = lookup(s); // substitute variables w[i] = s; - }; + } p += strcspn(p, ";\n\0"); cont = *p++!=0; // more statements if this isn't the end of the string @@ -187,12 +187,12 @@ int execute(char *p) // all evaluation happens here, strcat(r, w[i]); // make string-list out of all arguments if(i==numargs-1) break; strcat(r, " "); - }; + } ((void (__cdecl *)(char *))id->fun)(r); delete[] r; break; - }; - }; + } + } break; case ID_VAR: // game defined variabled @@ -208,7 +208,7 @@ int execute(char *p) // all evaluation happens here, } *id->storage = i1; if(id->fun) ((void (__cdecl *)())id->fun)(); // call trigger function if available - }; + } break; case ID_ALIAS: // alias, also used as functions and (global) variables @@ -216,24 +216,24 @@ int execute(char *p) // all evaluation happens here, { s_sprintfd(t)("arg%d", i); // set any arguments as (global) arg values so functions can access them alias(t, w[i]); - }; + } char *wasexecuting = id->executing; id->executing = id->action; val = execute(id->action); if(id->executing!=id->action && id->executing!=wasexecuting) delete[] id->executing; id->executing = wasexecuting; break; - }; + } loopj(numargs) delete[] w[j]; - }; + } return val; -}; +} // tab-completion of all idents int completesize = 0, completeidx = 0; -void resetcomplete() { completesize = 0; }; +void resetcomplete() { completesize = 0; } void complete(char *s) { @@ -243,20 +243,20 @@ void complete(char *s) s_strcpy(t, s); s_strcpy(s, "/"); s_strcat(s, t); - }; + } if(!s[1]) return; - if(!completesize) { completesize = (int)strlen(s)-1; completeidx = 0; }; + if(!completesize) { completesize = (int)strlen(s)-1; completeidx = 0; } int idx = 0; enumerate(*idents, ident, id, if(strncmp(id.name, s+1, completesize)==0 && idx++==completeidx) { s_strcpy(s, "/"); s_strcat(s, id.name); - }; + } ); completeidx++; if(completeidx>=idx) completeidx = 0; -}; +} bool execfile(char *cfgfile) { @@ -267,29 +267,29 @@ bool execfile(char *cfgfile) execute(buf); delete[] buf; return true; -}; +} void exec(char *cfgfile) { if(!execfile(cfgfile)) conoutf("could not read \"%s\"", cfgfile); -}; +} // below the commands that implement a small imperative language. thanks to the semantics of // () and [] expressions, any control construct can be defined trivially. -void intset(char *name, int v) { string b; itoa(b, v); alias(name, b); }; +void intset(char *name, int v) { string b; itoa(b, v); alias(name, b); } -void ifthen(char *cond, char *thenp, char *elsep) { execute(cond[0]!='0' ? thenp : elsep); }; -void loopa(char *times, char *body) { int t = atoi(times); loopi(t) { intset("i", i); execute(body); }; }; -void whilea(char *cond, char *body) { while(execute(cond)) execute(body); }; // can't get any simpler than this :) +void ifthen(char *cond, char *thenp, char *elsep) { execute(cond[0]!='0' ? thenp : elsep); } +void loopa(char *times, char *body) { int t = atoi(times); loopi(t) { intset("i", i); execute(body); } } +void whilea(char *cond, char *body) { while(execute(cond)) execute(body); } // can't get any simpler than this :) -void concat(char *s) { alias("s", s); }; +void concat(char *s) { alias("s", s); } void concatword(char *s) { for(char *a = s, *b = s; (*a = *b); b++) if(*a!=' ') a++; concat(s); -}; +} int listlen(char *a) { @@ -297,7 +297,7 @@ int listlen(char *a) int n = 0; while(*a) if(*a++==' ') n++; return n+1; -}; +} void at(char *s, char *pos) { @@ -306,10 +306,10 @@ void at(char *s, char *pos) { s += strcspn(s, " \0"); s += strspn(s, " "); - }; + } s[strcspn(s, " \0")] = 0; concat(s); -}; +} COMMANDN(loop, loopa, ARG_2STR); COMMANDN(while, whilea, ARG_2STR); @@ -320,18 +320,18 @@ COMMAND(concatword, ARG_VARI); COMMAND(at, ARG_2STR); COMMAND(listlen, ARG_1EST); -int add(int a, int b) { return a+b; }; COMMANDN(+, add, ARG_2EXP); -int mul(int a, int b) { return a*b; }; COMMANDN(*, mul, ARG_2EXP); -int sub(int a, int b) { return a-b; }; COMMANDN(-, sub, ARG_2EXP); -int divi(int a, int b) { return b ? a/b : 0; }; COMMANDN(div, divi, ARG_2EXP); -int mod(int a, int b) { return b ? a%b : 0; }; COMMAND(mod, ARG_2EXP); -int equal(int a, int b) { return (int)(a==b); }; COMMANDN(=, equal, ARG_2EXP); -int lt(int a, int b) { return (int)(ab); }; COMMANDN(>, gt, ARG_2EXP); +int add(int a, int b) { return a+b; } COMMANDN(+, add, ARG_2EXP); +int mul(int a, int b) { return a*b; } COMMANDN(*, mul, ARG_2EXP); +int sub(int a, int b) { return a-b; } COMMANDN(-, sub, ARG_2EXP); +int divi(int a, int b) { return b ? a/b : 0; } COMMANDN(div, divi, ARG_2EXP); +int mod(int a, int b) { return b ? a%b : 0; } COMMAND(mod, ARG_2EXP); +int equal(int a, int b) { return (int)(a==b); } COMMANDN(=, equal, ARG_2EXP); +int lt(int a, int b) { return (int)(ab); } COMMANDN(>, gt, ARG_2EXP); -int strcmpa(char *a, char *b) { return strcmp(a,b)==0; }; COMMANDN(strcmp, strcmpa, ARG_2EST); +int strcmpa(char *a, char *b) { return strcmp(a,b)==0; } COMMANDN(strcmp, strcmpa, ARG_2EST); -int rndn(int a) { return a>0 ? rnd(a) : 0; }; COMMANDN(rnd, rndn, ARG_1EXP); +int rndn(int a) { return a>0 ? rnd(a) : 0; } COMMANDN(rnd, rndn, ARG_1EXP); void writecfg() { @@ -348,7 +348,7 @@ void writecfg() if(id.type==ID_VAR && id.persist) { fprintf(f, "%s %d\n", id.name, *id.storage); - }; + } ); fprintf(f, "\n"); writebinds(f); @@ -357,11 +357,11 @@ void writecfg() if(id.type==ID_ALIAS && id.persist && id.action[0]) { fprintf(f, "alias \"%s\" [%s]\n", id.name, id.action); - }; + } ); fprintf(f, "\n"); fclose(f); -}; +} COMMAND(writecfg, ARG_NONE); diff --git a/source/src/console.cpp b/source/src/console.cpp index bf46dfda..4cda04f9 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -17,7 +17,7 @@ void setconskip(int n) { conskip += n; if(conskip<0) conskip = 0; -}; +} COMMANDN(conskip, setconskip, ARG_1INT); @@ -37,8 +37,8 @@ void conline(const char *sf, bool highlight) // add a line to the console else { s_strcpy(cl.cref, sf); - }; -}; + } +} void conoutf(const char *s, ...) { @@ -54,11 +54,11 @@ void conoutf(const char *s, ...) s_strncpy(t, s, visible+1); conline(t, n++!=0); s += visible; - }; -}; + } +} bool fullconsole = false; -void toggleconsole() { fullconsole = !fullconsole; }; +void toggleconsole() { fullconsole = !fullconsole; } COMMAND(toggleconsole, ARG_NONE); void rendercommand(int x, int y) @@ -67,7 +67,7 @@ void rendercommand(int x, int y) int offset = text_width(s, commandpos>=0 ? commandpos+2 : -1); blendbox(x+offset, y, x+offset+char_width(commandpos>=0 ? commandbuf[commandpos] : '_'), y+FONTH, true); draw_text(s, x, y); -}; +} void renderconsole() // render buffer taking into account time & scrolling { @@ -87,10 +87,10 @@ void renderconsole() // render buffer taking into { refs[nd++] = conlines[i].cref; if(nd==ndraw) break; - }; + } loopj(nd) draw_text(refs[j], FONTH/3, (FONTH*5/4)*(nd-j-1)+FONTH/3); - }; -}; + } +} // keymap is defined externally in keymap.cfg @@ -99,7 +99,7 @@ struct keym int code; char *name, *action; - ~keym() { DELETEA(name); DELETEA(action); }; + ~keym() { DELETEA(name); DELETEA(action); } }; vector keyms; @@ -112,7 +112,7 @@ void keymap(char *code, char *key, char *action) km.code = atoi(code); km.name = newstring(key); km.action = newstring(action); -}; +} COMMAND(keymap, ARG_3STR); @@ -125,9 +125,9 @@ void bindkey(char *key, char *action) if(!keypressed || keyaction!=km.action) delete[] km.action; km.action = newstring(action); return; - }; + } conoutf("unknown key \"%s\"", key); -}; +} COMMANDN(bind, bindkey, ARG_2STR); @@ -145,12 +145,12 @@ char *addreleaseaction(char *s) ra.key = keypressed; ra.action = newstring(s); return keypressed->name; -}; +} void onrelease(char *s) { addreleaseaction(s); -}; +} COMMAND(onrelease, ARG_1STR); @@ -162,9 +162,9 @@ void saycommand(char *init) // turns input to the comman if(!init) init = ""; s_strcpy(commandbuf, init); commandpos = -1; -}; +} -void mapmsg(char *s) { s_strncpy(hdr.maptitle, s, 128); }; +void mapmsg(char *s) { s_strncpy(hdr.maptitle, s, 128); } COMMAND(saycommand, ARG_VARI); COMMAND(mapmsg, ARG_1STR); @@ -202,10 +202,10 @@ void pasteconsole() commandbuf[commandlen] = '\n'; if(commandlen + 1 < _MAXDEFSTR && cbend < &cb[cbsize]) ++commandlen; commandbuf[commandlen] = '\0'; - }; + } XFree(cb); #endif -}; +} cvector vhistory; int histpos = 0; @@ -218,8 +218,8 @@ void history(int n) rec = true; execute(vhistory[vhistory.length()-n-1]); rec = false; - }; -}; + } +} COMMAND(history, ARG_1INT); @@ -243,7 +243,7 @@ void keypress(int code, bool isdown, int cooked) resetcomplete(); if(commandpos>=len-1) commandpos = -1; break; - }; + } case SDLK_BACKSPACE: { @@ -254,7 +254,7 @@ void keypress(int code, bool isdown, int cooked) if(commandpos>0) commandpos--; else if(!commandpos && len<=1) commandpos = -1; break; - }; + } case SDLK_LEFT: if(commandpos>0) commandpos--; @@ -279,7 +279,7 @@ void keypress(int code, bool isdown, int cooked) break; case SDLK_v: - if(SDL_GetModState()&(KMOD_LCTRL|KMOD_RCTRL)) { pasteconsole(); return; }; + if(SDL_GetModState()&(KMOD_LCTRL|KMOD_RCTRL)) { pasteconsole(); return; } default: resetcomplete(); @@ -293,12 +293,12 @@ void keypress(int code, bool isdown, int cooked) { memmove(&commandbuf[commandpos+1], &commandbuf[commandpos], len - commandpos); commandbuf[commandpos++] = cooked; - }; + } commandbuf[len+1] = '\0'; - }; - }; + } + } - }; + } } else { @@ -309,18 +309,18 @@ void keypress(int code, bool isdown, int cooked) if(vhistory.empty() || strcmp(vhistory.last(), commandbuf)) { vhistory.add(newstring(commandbuf)); // cap this? - }; + } histpos = vhistory.length(); if(commandbuf[0]=='/') execute(commandbuf); else toserver(commandbuf); - }; + } saycommand(NULL); } else if(code==SDLK_ESCAPE) { saycommand(NULL); - }; - }; + } + } } else if(!menukey(code, isdown)) // keystrokes go to menu { @@ -335,8 +335,8 @@ void keypress(int code, bool isdown, int cooked) if(!isdown) execute(ra.action); delete[] ra.action; releaseactions.remove(i--); - }; - }; + } + } if(isdown) { keyaction = k.action; @@ -344,22 +344,22 @@ void keypress(int code, bool isdown, int cooked) execute(keyaction); keypressed = NULL; if(keyaction!=k.action) delete[] keyaction; - }; + } break; - }; - }; -}; + } + } +} char *getcurcommand() { return saycommandon ? commandbuf : NULL; -}; +} void writebinds(FILE *f) { loopv(keyms) { if(*keyms[i].action) fprintf(f, "bind \"%s\" [%s]\n", keyms[i].name, keyms[i].action); - }; -}; + } +} diff --git a/source/src/editing.cpp b/source/src/editing.cpp index daed9dfd..0484ffd6 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -18,7 +18,7 @@ block sel = int selh = 0; bool selset = false; -#define loopselxy(b) { makeundo(); loop(x,sel.xs) loop(y,sel.ys) { sqr *s = S(sel.x+x, sel.y+y); b; }; remip(sel); } +#define loopselxy(b) { makeundo(); loop(x,sel.xs) loop(y,sel.ys) { sqr *s = S(sel.x+x, sel.y+y); b; } remip(sel); } int cx, cy, ch; @@ -48,11 +48,11 @@ void toggleedit() //put call to clear/restart gamemode projreset(); player1->attacking = false; - }; + } keyrepeat(editmode); selset = false; editing = editmode; -}; +} COMMANDN(edittoggle, toggleedit, ARG_NONE); @@ -63,20 +63,20 @@ void correctsel() // ensures above invaria if(sel.xs+sel.x>bsize) sel.xs = bsize-sel.x; if(sel.ys+sel.y>bsize) sel.ys = bsize-sel.y; if(sel.xs<=0 || sel.ys<=0) selset = false; -}; +} bool noteditmode() { correctsel(); if(!editmode) conoutf("this function is only allowed in edit mode"); return !editmode; -}; +} bool noselection() { if(!selset) conoutf("no selection"); return !selset; -}; +} #define EDITSEL if(noteditmode() || noselection()) return; #define EDITSELMP if(noteditmode() || noselection() || multiplayer()) return; @@ -88,7 +88,7 @@ void selectpos(int x, int y, int xs, int ys) sel = s; selh = 0; correctsel(); -}; +} void makesel() { @@ -97,7 +97,7 @@ void makesel() selh = max(lasth,ch); correctsel(); if(selset) rtex = *S(sel.x, sel.y); -}; +} VAR(flrceil,0,0,2); @@ -127,7 +127,7 @@ void cursorupdate() // called every frame fr cy = (int)y; if(OUTBORD(cx, cy)) return; - }; + } if(dragging) makesel(); @@ -159,7 +159,7 @@ void cursorupdate() // called every frame fr if(!(ix+1&GRIDM)) line(ix+1, iy, h2, ix+1, iy+1, h3); if(!(iy&GRIDM)) line(ix, iy, h1, ix+1, iy, h2); if(!(iy+1&GRIDM)) line(ix, iy+1, h4, ix+1, iy+1, h3); - }; + } if(!SOLID(s)) { @@ -170,14 +170,14 @@ void cursorupdate() // called every frame fr linestyle(GRIDS, 0xFF, 0x00, 0x00); dot(cx, cy, ih); ch = (int)ih; - }; + } if(selset) { linestyle(GRIDS, 0xFF, 0x40, 0x40); box(sel, (float)selh, (float)selh, (float)selh, (float)selh); - }; -}; + } +} vector undos; // unlimited undo VAR(undomegs, 0, 1, 10); // bounded by n megs @@ -189,23 +189,23 @@ void pruneundos(int maxremain) // bound memory { t += undos[i]->xs*undos[i]->ys*sizeof(sqr); if(t>maxremain) delete undos.remove(i); - }; -}; + } +} void makeundo() { undos.add(blockcopy(sel)); pruneundos(undomegs<<20); -}; +} void editundo() { EDITMP; - if(undos.empty()) { conoutf("nothing more to undo"); return; }; + if(undos.empty()) { conoutf("nothing more to undo"); return; } block *p = undos.pop(); blockpaste(*p); freeblock(p); -}; +} block *copybuf = NULL; @@ -214,21 +214,21 @@ void copy() EDITSELMP; freeblock(copybuf); copybuf = blockcopy(sel); -}; +} void paste() { EDITMP; - if(!copybuf) { conoutf("nothing to paste"); return; }; + if(!copybuf) { conoutf("nothing to paste"); return; } sel.xs = copybuf->xs; sel.ys = copybuf->ys; correctsel(); - if(!selset || sel.xs!=copybuf->xs || sel.ys!=copybuf->ys) { conoutf("incorrect selection"); return; }; + if(!selset || sel.xs!=copybuf->xs || sel.ys!=copybuf->ys) { conoutf("incorrect selection"); return; } makeundo(); copybuf->x = sel.x; copybuf->y = sel.y; blockpaste(*copybuf); -}; +} void tofronttex() // maintain most recently used of the texture lists when applying texture { @@ -242,9 +242,9 @@ void tofronttex() // maintain most recentl for(int a = c-1; a>=0; a--) p[a+1] = p[a]; p[0] = t; curedittex[i] = -1; - }; - }; -}; + } + } +} void editdrag(bool isdown) { @@ -255,9 +255,9 @@ void editdrag(bool isdown) lasth = ch; selset = false; tofronttex(); - }; + } makesel(); -}; +} // the core editing function. all the *xy functions perform the core operations // and are also called directly from the network, the function below it is strictly @@ -275,7 +275,7 @@ void editheightxy(bool isfloor, int amount, block &sel) s->ceil += amount; if(s->ceil<=s->floor) s->ceil = s->floor+1; }); -}; +} void editheight(int flr, int amount) { @@ -283,7 +283,7 @@ void editheight(int flr, int amount) bool isfloor = flr==0; editheightxy(isfloor, amount, sel); addmsg(SV_EDITH, "ri6", sel.x, sel.y, sel.xs, sel.ys, isfloor, amount); -}; +} COMMAND(editheight, ARG_2INT); @@ -296,13 +296,13 @@ void edittexxy(int type, int t, block &sel) case 2: s->ctex = t; break; case 3: s->utex = t; break; }); -}; +} void edittex(int type, int dir) { EDITSEL; if(type<0 || type>3) return; - if(type!=lasttype) { tofronttex(); lasttype = type; }; + if(type!=lasttype) { tofronttex(); lasttype = type; } int atype = type==3 ? 1 : type; int i = curedittex[atype]; i = i<0 ? 0 : i+dir; @@ -310,7 +310,7 @@ void edittex(int type, int dir) int t = lasttex = hdr.texlists[atype][i]; edittexxy(type, t, sel); addmsg(SV_EDITT, "ri6", sel.x, sel.y, sel.xs, sel.ys, type, t); -}; +} void replace() { @@ -324,30 +324,30 @@ void replace() case 1: if(s->wtex == rtex.wtex) s->wtex = lasttex; break; case 2: if(s->ctex == rtex.ctex) s->ctex = lasttex; break; case 3: if(s->utex == rtex.utex) s->utex = lasttex; break; - }; - }; + } + } block b = { 0, 0, ssize, ssize }; remip(b); -}; +} void edittypexy(int type, block &sel) { loopselxy(s->type = type); -}; +} void edittype(int type) { EDITSEL; if(type==CORNER && (sel.xs!=sel.ys || sel.xs==3 || sel.xs>4 && sel.xs!=8 || sel.x&~-sel.xs || sel.y&~-sel.ys)) - { conoutf("corner selection must be power of 2 aligned"); return; }; + { conoutf("corner selection must be power of 2 aligned"); return; } edittypexy(type, sel); addmsg(SV_EDITS, "ri5", sel.x, sel.y, sel.xs, sel.ys, type); -}; +} -void heightfield(int t) { edittype(t==0 ? FHF : CHF); }; -void solid(int t) { edittype(t==0 ? SPACE : SOLID); }; -void corner() { edittype(CORNER); }; +void heightfield(int t) { edittype(t==0 ? FHF : CHF); } +void solid(int t) { edittype(t==0 ? SPACE : SOLID); } +void corner() { edittype(CORNER); } COMMAND(heightfield, ARG_1INT); COMMAND(solid, ARG_1INT); @@ -366,7 +366,7 @@ void editequalisexy(bool isfloor, block &sel) if(isfloor) s->floor = low; else s->ceil = hi; if(s->floor>=s->ceil) s->floor = s->ceil-1; }); -}; +} void equalize(int flr) { @@ -374,7 +374,7 @@ void equalize(int flr) EDITSEL; editequalisexy(isfloor, sel); addmsg(SV_EDITE, "ri5", sel.x, sel.y, sel.xs, sel.ys, isfloor); -}; +} COMMAND(equalize, ARG_1INT); @@ -382,14 +382,14 @@ void setvdeltaxy(int delta, block &sel) { loopselxy(s->vdelta = max(s->vdelta+delta, 0)); remipmore(sel); -}; +} void setvdelta(int delta) { EDITSEL; setvdeltaxy(delta, sel); addmsg(SV_EDITD, "ri5", sel.x, sel.y, sel.xs, sel.ys, delta); -}; +} const int MAXARCHVERT = 50; int archverts[MAXARCHVERT][MAXARCHVERT]; @@ -401,10 +401,10 @@ void archvertex(int span, int vert, int delta) { archvinit = true; loop(s,MAXARCHVERT) loop(v,MAXARCHVERT) archverts[s][v] = 0; - }; + } if(span>=MAXARCHVERT || vert>=MAXARCHVERT || span<0 || vert<0) return; archverts[span][vert] = delta; -}; +} void arch(int sidedelta, int _a) { @@ -418,7 +418,7 @@ void arch(int sidedelta, int _a) ? (archverts[sel.xs-1][x] + (y==0 || y==sel.ys-1 ? sidedelta : 0)) : (archverts[sel.ys-1][y] + (x==0 || x==sel.xs-1 ? sidedelta : 0))); remipmore(sel); -}; +} void slope(int xd, int yd) { @@ -430,7 +430,7 @@ void slope(int xd, int yd) sel.ys++; loopselxy(s->vdelta = xd*x+yd*y+off); remipmore(sel); -}; +} void perlin(int scale, int seed, int psize) { @@ -446,27 +446,27 @@ void perlin(int scale, int seed, int psize) remipmore(sel); sel.xs--; sel.ys--; -}; +} VARF(fullbright, 0, 0, 1, if(fullbright) { if(noteditmode()) return; loopi(mipsize) world[i].r = world[i].g = world[i].b = 176; - }; + } ); void edittag(int tag) { EDITSELMP; loopselxy(s->tag = tag); -}; +} void newent(char *what, char *a1, char *a2, char *a3, char *a4) { EDITSEL; newentity(sel.x, sel.y, (int)camera1->o.z, what, ATOI(a1), ATOI(a2), ATOI(a3), ATOI(a4)); -}; +} COMMANDN(select, selectpos, ARG_4INT); COMMAND(edittag, ARG_1INT); diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 6f839ba7..cb79ab46 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -15,7 +15,7 @@ int triggertime = 0; void renderent(entity &e, char *mdlname, float z, float yaw, int anim = ANIM_MAPMODEL|ANIM_LOOP, int basetime = 0, float speed = 10.0f) { rendermodel(mdlname, anim, 0, 1.1f, e.x, z+S(e.x, e.y)->floor, e.y, yaw, 0, speed, basetime); -}; +} extern void newparticle(vec &o, vec &d, int fade, int type, int tex = -1); @@ -24,7 +24,7 @@ int triggeranim(entity &e) int anim = ANIM_TRIGGER; if(!triggertime) anim |= e.spawned ? ANIM_START : ANIM_END; return anim; -}; +} void renderentities() { @@ -51,7 +51,7 @@ void renderentities() { s_sprintfd(path)("pickups/flags/%s", team_string(e.attr2)); rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 4, e.x, f.state==CTFF_INBASE ? (float)S(e.x, e.y)->floor : e.z, e.y, (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); - }; + } } else { @@ -76,10 +76,10 @@ void renderentities() case 4: renderent(e, "switch2", 3, (float)e.attr3*90, triggeranim(e), triggertime); break; case 5: renderent(e, "switch1", -0.15f, (float)e.attr3*90, triggeranim(e), triggertime); break; - }; - }; - }; -}; + } + } + } +} itemstat itemstats[] = { @@ -95,7 +95,7 @@ itemstat itemstats[] = {16, 0, 72, S_ITEMPUP}, //powerup }; -void baseammo(int gun, playerent *d) { d->ammo[gun] = itemstats[gun].add*2; }; +void baseammo(int gun, playerent *d) { d->ammo[gun] = itemstats[gun].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). @@ -108,7 +108,7 @@ void equipitem(playerent *d, int i, int &v, int t) if(v>is.max) v = is.max; if(d==player1) playsoundc(is.sound); else playsound(is.sound, &d->o); -}; +} void realpickup(int n, playerent *d) { @@ -136,8 +136,8 @@ void realpickup(int n, playerent *d) equipitem(d, n, d->ammo[1], 9); if(d==player1) weaponswitch(GUN_PISTOL); break; - }; -}; + } +} // these functions are called when the client touches the item @@ -148,8 +148,8 @@ void additem(playerent *d, int i, int &v, int spawnsec, int t) if(d->type==ENT_PLAYER) addmsg(SV_ITEMPICKUP, "rii", i, spawnsec); else if(d->type==ENT_BOT && serverpickup(i, spawnsec, -1)) realpickup(i, d); ents[i].spawned = false; - }; -}; + } +} void pickup(int n, playerent *d) { @@ -201,11 +201,11 @@ void pickup(int n, playerent *d) else if(f.state == CTFF_INBASE && of.state == CTFF_STOLEN && of.actor == d && of.ack) flagscore(); } else flagpickup(); - }; + } break; - }; - }; -}; + } + } +} void checkitems(playerent *d) { @@ -223,14 +223,14 @@ void checkitems(playerent *d) float dist2 = d->o.z - (S(e.x, e.y)->floor+d->eyeheight); if(dist1<1.5f && dist2floor+d->eyeheight); if(d->o.dist(v)<2.5f) pickup(i, d); - }; -}; + } +} void putitems(ucharbuf &p) // puts items in network stream and also spawns them locally { @@ -240,8 +240,8 @@ void putitems(ucharbuf &p) // puts items in network stream and also s else if(m_pistol && ents[i].type==I_AMMO) continue; putint(p, i); ents[i].spawned = true; - }; -}; + } +} void resetspawns() { @@ -253,8 +253,8 @@ void resetspawns() if(m_noitemsnade && e.type == I_CLIPS) e.type = I_GRENADE; else if(m_pistol && e.type==I_AMMO) e.type = I_CLIPS; } -}; -void setspawn(int i, bool on) { if(ents.inrange(i)) ents[i].spawned = on; }; +} +void setspawn(int i, bool on) { if(ents.inrange(i)) ents[i].spawned = on; } void equip(playerent *d) { @@ -272,21 +272,21 @@ void equip(playerent *d) { d->ammo[GUN_PISTOL] = itemstats[GUN_PISTOL].max-magsize(GUN_PISTOL); d->mag[GUN_PISTOL] = magsize(GUN_PISTOL); - }; + } if(!m_noprimary) { d->ammo[d->primary] = itemstats[d->primary].start-magsize(d->primary); d->mag[d->primary] = magsize(d->primary); - }; + } if (d->hasarmour) { if(gamemode==m_arena) d->armour = 100; - }; + } d->gunselect = d->primary; -}; +} void item(int num) { @@ -302,8 +302,8 @@ void item(int num) default: conoutf("sorry, you can't use that item yet"); break; - }; -}; + } +} COMMAND(item,ARG_1INT); @@ -331,8 +331,8 @@ bool intersect(entity *e, vec &from, vec &to, vec *end) // if lineseg hits entit v.mul(f); v.add(from); p = &v; - }; - }; + } + } if (p->x <= e->x+mmi.rad && p->x >= e->x-mmi.rad @@ -345,7 +345,7 @@ bool intersect(entity *e, vec &from, vec &to, vec *end) // if lineseg hits entit return true; } return false; -}; +} // End add by Ricks // flag ent actions done by the local player @@ -359,7 +359,7 @@ void flagpickup() f.actor_cn = getclientnum(); f.ack = false; addmsg(SV_FLAGPICKUP, "ri", f.team); -}; +} void tryflagdrop(bool reset) { @@ -370,8 +370,8 @@ void tryflagdrop(bool reset) f.state = CTFF_DROPPED; f.ack = false; addmsg(reset ? SV_FLAGRESET : SV_FLAGDROP, "ri", f.team); - }; -}; + } +} void flagreturn() { @@ -379,14 +379,14 @@ void flagreturn() f.flag->spawned = false; f.ack = false; addmsg(SV_FLAGRETURN, "ri", f.team); -}; +} void flagscore() { flaginfo &f = flaginfos[team_opposite(team_int(player1->team))]; f.ack = false; addmsg(SV_FLAGSCORE, "ri", f.team); -}; +} // flag ent actions from the net @@ -400,7 +400,7 @@ void flagstolen(int flag, int action, int act) f.flag->spawned = false; f.ack = true; flagmsg(flag, action); -}; +} void flagdropped(int flag, int action, short x, short y, short z) { @@ -414,7 +414,7 @@ void flagdropped(int flag, int action, short x, short y, short z) { if(floor < hdr.waterlevel) z = hdr.waterlevel; // avoid dropping into water else z = (short) floor; - }; + } f.flag->x = x; f.flag->y = y; @@ -422,18 +422,18 @@ void flagdropped(int flag, int action, short x, short y, short z) f.flag->spawned = true; f.ack = true; flagmsg(flag, action); -}; +} void flaginbase(int flag, int action, int act) { flaginfo &f = flaginfos[flag]; playerent *actor = act == getclientnum() ? player1 : getclient(act); - if(actor) { f.actor = actor; f.actor_cn = act; }; + if(actor) { f.actor = actor; f.actor_cn = act; } f.flag->x = (ushort) f.originalpos.x; f.flag->y = (ushort) f.originalpos.y; f.flag->z = (ushort) f.originalpos.z; f.flag->spawned = true; f.ack = true; flagmsg(flag, action); -}; +} diff --git a/source/src/entity.h b/source/src/entity.h index 6a29ab07..e7a93cec 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -63,7 +63,7 @@ struct physent state(CS_ALIVE), type(ENT_PLAYER) { reset(); - }; + } void reset() { @@ -71,7 +71,7 @@ struct physent move = strafe = 0; timeinair = 0; onfloor = onladder = inwater = jumpnext = false; - }; + } }; struct dynent : physent // animated ent @@ -86,15 +86,15 @@ struct dynent : physent // animated ent { k_left = k_right = k_up = k_down = jumpnext = false; move = strafe = 0; - }; + } void reset() { physent::reset(); stopmoving(); - }; + } - dynent() { reset(); loopi(2) { lastanimswitchtime[i] = -1; lastmodel[i] = NULL; }; }; + dynent() { reset(); loopi(2) { lastanimswitchtime[i] = -1; lastmodel[i] = NULL; } } }; #define MAXNAMELEN 15 @@ -109,32 +109,37 @@ struct poshist int nextupdate, curpos, numpos; vec pos[POSHIST_SIZE]; - poshist() : nextupdate(0) { reset(); }; - const int size() const { return numpos; }; + poshist() : nextupdate(0) { reset(); } + + const int size() const { return numpos; } + void reset() { curpos = 0; numpos = 0; - }; + } + void addpos(const vec &o) { pos[curpos] = o; curpos++; if(curpos>=POSHIST_SIZE) curpos = 0; if(numpos= 4.0f) addpos(o); nextupdate = lastmillis + 100; - }; + } }; struct playerent : dynent @@ -172,7 +177,7 @@ struct playerent : dynent { name[0] = team[0] = 0; respawn(); - }; + } void respawn() { @@ -189,7 +194,7 @@ struct playerent : dynent weaponchanging = false; akimbo = 0; loopi(NUMGUNS) ammo[i] = mag[i] = 0; - }; + } }; class CBot; @@ -207,7 +212,7 @@ struct botent : playerent // End add float targetyaw; // monster wants to look in this direction - botent() : pBot(NULL), enemy(NULL) { type = ENT_BOT; }; + botent() : pBot(NULL), enemy(NULL) { type = ENT_BOT; } }; // Moved from server.cpp by Rick @@ -229,7 +234,7 @@ struct flaginfo vec originalpos; int state; // one of CTFF_* bool ack; - flaginfo() : flag(0), actor(0), state(CTFF_INBASE), ack(false) {}; + flaginfo() : flag(0), actor(0), state(CTFF_INBASE), ack(false) {} }; enum { NADE_ACTIVATED = 1, NADE_THROWED, GIB}; @@ -247,7 +252,7 @@ struct bounceent : physent // nades, gibs radius = 0.2f; eyeheight = 0.3f; aboveeye = 0.0f; - }; + } }; #define NADE_IN_HAND (player1->gunselect==GUN_GRENADE && player1->inhandnade) diff --git a/source/src/geom.h b/source/src/geom.h index 9b5910ea..f5f95065 100644 --- a/source/src/geom.h +++ b/source/src/geom.h @@ -6,33 +6,33 @@ struct vec float v[3]; }; - vec() {}; - vec(float a, float b, float c) : x(a), y(b), z(c) {}; - vec(float *v) : x(v[0]), y(v[1]), z(v[2]) {}; + vec() {} + vec(float a, float b, float c) : x(a), y(b), z(c) {} + vec(float *v) : x(v[0]), y(v[1]), z(v[2]) {} - float &operator[](int i) { return v[i]; }; - float operator[](int i) const { return v[i]; }; + float &operator[](int i) { return v[i]; } + float operator[](int i) const { return v[i]; } bool operator==(const vec &o) const { return x == o.x && y == o.y && z == o.z; } bool operator!=(const vec &o) const { return x != o.x || y != o.y || z != o.z; } - vec &mul(float f) { x *= f; y *= f; z *= f; return *this; }; - vec &div(float f) { x /= f; y /= f; z /= f; return *this; }; - vec &add(float f) { x += f; y += f; z += f; return *this; }; - vec &sub(float f) { x -= f; y -= f; z -= f; return *this; }; + vec &mul(float f) { x *= f; y *= f; z *= f; return *this; } + vec &div(float f) { x /= f; y /= f; z /= f; return *this; } + vec &add(float f) { x += f; y += f; z += f; return *this; } + vec &sub(float f) { x -= f; y -= f; z -= f; return *this; } - vec &add(const vec &o) { x += o.x; y += o.y; z += o.z; return *this; }; - vec &sub(const vec &o) { x -= o.x; y -= o.y; z -= o.z; return *this; }; + vec &add(const vec &o) { x += o.x; y += o.y; z += o.z; return *this; } + vec &sub(const vec &o) { x -= o.x; y -= o.y; z -= o.z; return *this; } - float squaredlen() const { return x*x + y*y + z*z; }; - float dot(const vec &o) const { return x*o.x + y*o.y + z*o.z; }; + float squaredlen() const { return x*x + y*y + z*z; } + float dot(const vec &o) const { return x*o.x + y*o.y + z*o.z; } - float magnitude() const { return sqrtf(squaredlen()); }; - vec &normalize() { div(magnitude()); return *this; }; + float magnitude() const { return sqrtf(squaredlen()); } + vec &normalize() { div(magnitude()); return *this; } - float dist(const vec &e) const { vec t; return dist(e, t); }; - float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); }; + float dist(const vec &e) const { vec t; return dist(e, t); } + float dist(const vec &e, vec &t) const { t = *this; t.sub(e); return t.magnitude(); } - bool reject(const vec &o, float max) { return x>o.x+max || xo.y+max || yo.x+max || xo.y+max || y 100.0f) percent_done = 100.0f; // f(x) = -sin(x-1.5)^3 kick = -sinf(pow((1.5f/100.0f*percent_done)-1.5f,3)); - }; + } if(player1->lastaction && player1->lastattackgun==player1->gunselect) { if(NADE_THROWING && timedifflastactiongunselect!=GUN_KNIFE && player1->gunselect!=GUN_GRENADE ? ANIM_LOOP : 0); - }; + } if(player1->gunselect!=GUN_GRENADE && player1->gunselect!=GUN_KNIFE) { k_rot = kick_rot(player1->gunselect)*kick; k_back = kick_back(player1->gunselect)*kick/10; - }; + } float swayspeed = (float) (sinf((float)lastmillis/swayspeeddiv))/(swaymovediv/10.0f); float swayupspeed = (float) (sinf((float)lastmillis/swayupspeeddiv-90))/(swayupmovediv/10.0f); @@ -91,8 +91,8 @@ struct weaponmove pos.x = player1->o.x-base.x*k_back+sway.x; pos.y = player1->o.y-base.y*k_back+sway.y; pos.z = player1->o.z-base.z*k_back+sway.z; - }; - }; + } + } }; void renderhudgun(int gun, int lastaction, int index = 0) @@ -109,9 +109,9 @@ void renderhudgun(int gun, int lastaction, int index = 0) { lastanim[index] = wm.anim|(gun<<16); lastswitch[index] = lastmillis; - }; + } rendermodel(path, wm.anim|(index ? ANIM_MIRROR : 0), 0, 0, wm.pos.x, wm.pos.z, wm.pos.y, player1->yaw + 90, player1->pitch+wm.k_rot, 40.0f, lastswitch[index], NULL, NULL, 1.28f); -}; +} void renderhudgun() { @@ -123,8 +123,8 @@ void renderhudgun() else { renderhudgun(player1->gunselect, player1->lastaction); - }; -}; + } +} void preload_hudguns() { @@ -132,6 +132,6 @@ void preload_hudguns() { s_sprintfd(path)("weapons/%s", hudgunnames[i]); loadmodel(path); - }; -}; + } +} diff --git a/source/src/main.cpp b/source/src/main.cpp index 28c20196..96b8ae8d 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -19,9 +19,9 @@ void cleanup(char *msg) // single program exit point; #else printf(msg); #endif - }; + } SDL_Quit(); -}; +} void quit() // normal exit { @@ -29,14 +29,14 @@ void quit() // normal exit writecfg(); cleanup(NULL); exit(EXIT_SUCCESS); -}; +} void fatal(char *s, char *o) // failure exit { s_sprintfd(msg)("%s%s (%s)\n", s, o, SDL_GetError()); cleanup(msg); exit(EXIT_FAILURE); -}; +} int scr_w = 640; int scr_h = 480; @@ -56,14 +56,14 @@ void screenshot() char *dest = (char *)temp->pixels+temp->pitch*idx; memcpy(dest, (char *)image->pixels+image->pitch*(scr_h-1-idx), 3*scr_w); endianswap(dest, 3, scr_w); - }; + } s_sprintfd(buf)("screenshots/screenshot_%d.bmp", lastmillis); SDL_SaveBMP(temp, path(buf)); SDL_FreeSurface(temp); - }; + } SDL_FreeSurface(image); - }; -}; + } +} COMMAND(screenshot, ARG_NONE); COMMAND(quit, ARG_NONE); @@ -76,7 +76,7 @@ static void bar(float bar, int w, int o, float r, float g, float b) glVertex2f(bar*(w*3-2*side)+side, o*FONTH); glVertex2f(bar*(w*3-2*side)+side, (o+2)*FONTH); glVertex2f(side, (o+2)*FONTH); -}; +} void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2, const char *text2) // also used during loading { @@ -99,13 +99,13 @@ void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2, { bar(1, w, 1, 0.1f, 0.1f, 0.1f); bar(bar1, w, 1, 0.2f, 0.2f, 0.2f); - }; + } if(bar2>0) { bar(1, w, 3, 0.1f, 0.1f, 0.1f); bar(bar2, w, 3, 0.2f, 0.2f, 0.2f); - }; + } glEnd(); @@ -124,7 +124,7 @@ void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2, glEnable(GL_DEPTH_TEST); SDL_GL_SwapBuffers(); -}; +} SDL_Surface *screen = NULL; @@ -143,8 +143,8 @@ void setfullscreen(bool enable) SDL_WM_ToggleFullScreen(screen); SDL_WM_GrabInput((screen->flags&SDL_FULLSCREEN) ? SDL_GRAB_ON : SDL_GRAB_OFF); #endif - }; -}; + } +} void screenres(int w, int h, int bpp = 0) { @@ -158,7 +158,7 @@ void screenres(int w, int h, int bpp = 0) screen = surf; glViewport(0, 0, w, h); #endif -}; +} COMMAND(screenres, ARG_3INT); @@ -176,14 +176,14 @@ void limitfps(int &millis, int curmillis) { ++delay; fpserror -= maxfps; - }; + } if(delay > 0) { SDL_Delay(delay); millis += delay; - }; - }; -}; + } + } +} int lowfps = 30, highfps = 40; @@ -192,7 +192,7 @@ void fpsrange(int low, int high) if(low>high || low<1) return; lowfps = low; highfps = high; -}; +} COMMAND(fpsrange, ARG_2INT); @@ -200,7 +200,7 @@ void keyrepeat(bool on) { SDL_EnableKeyRepeat(on ? SDL_DEFAULT_REPEAT_DELAY : 0, SDL_DEFAULT_REPEAT_INTERVAL); -}; +} VARF(gamespeed, 10, 100, 1000, if(multiplayer()) gamespeed = 100); @@ -236,7 +236,7 @@ int main(int argc, char **argv) default: conoutf("unknown commandline option"); } else conoutf("unknown commandline argument"); - }; + } #ifdef _DEBUG par = SDL_INIT_NOPARACHUTE; @@ -264,7 +264,7 @@ int main(int argc, char **argv) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa); - }; + } int resize = SDL_RESIZABLE; #if defined(WIN32) || defined(__APPLE__) resize = 0; @@ -384,7 +384,7 @@ int main(int argc, char **argv) break; case SDL_MOUSEMOTION: - if(ignore) { ignore--; break; }; + if(ignore) { ignore--; break; } if(!(screen->flags&SDL_FULLSCREEN) && grabmouse) { #ifdef __APPLE__ @@ -392,7 +392,7 @@ int main(int argc, char **argv) #endif if(event.motion.x == scr_w / 2 && event.motion.y == scr_h / 2) break; SDL_WarpMouse(scr_w / 2, scr_h / 2); - }; + } #ifndef WIN32 if((screen->flags&SDL_FULLSCREEN) || grabmouse) #endif @@ -406,23 +406,23 @@ int main(int argc, char **argv) lasttype = event.type; lastbut = event.button.button; break; - }; - }; + } + } #ifdef _DEBUG if(millis>lastflush+60000) { fflush(stdout); lastflush = millis; } #endif - }; + } quit(); return EXIT_SUCCESS; -}; +} void loadcrosshair(char *c) { s_sprintfd(p)("packages/misc/crosshairs/%s", c); crosshair = textureload(p); -}; +} COMMAND(loadcrosshair, ARG_1STR); diff --git a/source/src/md2.h b/source/src/md2.h index 6e9747ce..8c7707dd 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -5,12 +5,12 @@ md2 *loadingmd2 = 0; static inline bool htcmp(const vertmodel::tcvert &x, const vertmodel::tcvert &y) { return x.u==y.u && x.v==y.v && x.index==y.index; -}; +} static inline uint hthash(const vertmodel::tcvert &x) { return x.index; -}; +} struct md2 : vertmodel { @@ -38,9 +38,9 @@ struct md2 : vertmodel char name[16]; }; - md2(const char *name) : vertmodel(name) {}; + md2(const char *name) : vertmodel(name) {} - int type() { return MDL_MD2; }; + int type() { return MDL_MD2; } struct md2part : part { @@ -66,9 +66,9 @@ struct md2 : vertmodel idx = &tchash[tckey]; *idx = tcverts.length(); tcverts.add(tckey); - }; + } idxs.add(*idx); - }; + } loopi(numvertex-2) { tri &t = tris.add(); @@ -79,9 +79,9 @@ struct md2 : vertmodel t.vert[2] = idxs[i+2]; } else loopk(3) t.vert[k] = idxs[i&1 && k ? i+(1-(k-1))+1 : i+k]; - }; - }; - }; + } + } + } bool load(char *filename) { @@ -97,7 +97,7 @@ struct md2 : vertmodel { fclose(file); return false; - }; + } numframes = header.numframes; @@ -140,14 +140,14 @@ struct md2 : vertmodel *curvert++ = vec(v.vertex[0]*frame.scale[0]+frame.translate[0], v.vertex[2]*frame.scale[2]+frame.translate[2], -(v.vertex[1]*frame.scale[1]+frame.translate[1])); - }; + } frame_offset += header.framesize; - }; + } fclose(file); return loaded = true; - }; + } void getdefaultanim(animstate &as, int anim, int varseed, float speed) { @@ -163,17 +163,17 @@ struct md2 : vertmodel as.frame = 0; as.range = 1; return; - }; + } int n = animfr[anim]; if(anim==ANIM_PAIN || anim==ANIM_DEATH || anim==ANIM_LYING_DEAD) n += varseed%3; as.frame = frame[n]; as.range = range[n]; - }; + } void begingenshadow() { glRotatef(180, 0, -1, 0); - }; + } }; void render(int anim, int varseed, float speed, int basetime, float x, float y, float z, float yaw, float pitch, dynent *d, model *vwepmdl, float scale) @@ -193,14 +193,14 @@ struct md2 : vertmodel ((md2 *)vwepmdl)->parts[0]->index = parts.length(); vwepmdl->setskin(); vwepmdl->render(anim, varseed, speed, basetime, x, y, z, yaw, pitch, d, NULL, scale); - }; - }; + } + } void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw, model *vwepmdl) { parts[0]->rendershadow(anim, varseed, speed, basetime, o, rad, yaw); if(vwepmdl) ((md2 *)vwepmdl)->parts[0]->rendershadow(anim, varseed, speed, basetime, o, rad, yaw); - }; + } bool load() { @@ -214,8 +214,8 @@ struct md2 : vertmodel if(!mdl.load(path(name1))) { s_sprintf(name1)("packages/models/%s/tris.md2", pname); // try md2 in parent folder (vert sharing) - if(!mdl.load(path(name1))) { delete[] pname; return false; }; - }; + if(!mdl.load(path(name1))) { delete[] pname; return false; } + } Texture *skin; loadskin(loadname, pname, skin, this); loopv(mdl.meshes) mdl.meshes[i]->skin = skin; @@ -226,22 +226,22 @@ struct md2 : vertmodel { s_sprintf(name3)("packages/models/%s/md2.cfg", pname); execfile(name3); - }; + } delete[] pname; loadingmd2 = 0; loopv(parts) parts[i]->scaleverts(scale/16.0f, vec(translate.x, translate.z, -translate.y)); return loaded = true; - }; + } }; void md2anim(char *anim, char *frame, char *range, char *s) { - if(!loadingmd2 || loadingmd2->parts.empty()) { conoutf("not loading an md2"); return; }; + if(!loadingmd2 || loadingmd2->parts.empty()) { conoutf("not loading an md2"); return; } int num = findanim(anim); - if(num<0) { conoutf("could not find animation %s", anim); return; }; + if(num<0) { conoutf("could not find animation %s", anim); return; } float speed = s[0] ? atof(s) : 100.0f; loadingmd2->parts.last()->setanim(num, atoi(frame), atoi(range), speed); -}; +} COMMAND(md2anim, ARG_4STR); diff --git a/source/src/md3.h b/source/src/md3.h index 6bdd86be..cbc5e7ab 100644 --- a/source/src/md3.h +++ b/source/src/md3.h @@ -43,9 +43,9 @@ struct md3meshheader struct md3 : vertmodel { - md3(const char *name) : vertmodel(name) {}; + md3(const char *name) : vertmodel(name) {} - int type() { return MDL_MD3; }; + int type() { return MDL_MD3; } struct md3part : part { @@ -63,7 +63,7 @@ struct md3 : vertmodel fclose(f); conoutf("md3: corrupted header"); return false; - }; + } numframes = header.numframes; numtags = header.numtags; @@ -80,10 +80,10 @@ struct md3 : vertmodel if(tag.name[0] && iparts[0]; if(link(vwep, "tag_weapon")) vwep->index = parts.length(); - }; + } glPushMatrix(); glTranslatef(x, y, z); @@ -165,7 +165,7 @@ struct md3 : vertmodel if(anim&ANIM_MIRROR || scale!=1) glScalef(anim&ANIM_MIRROR ? -scale : scale, scale, scale); parts[0]->render(anim, varseed, speed, basetime, d); glPopMatrix(); - }; + } bool load() { @@ -200,11 +200,11 @@ struct md3 : vertmodel loadskin(loadname, pname, skin, this); loopv(mdl.meshes) mdl.meshes[i]->skin = skin; if(skin==crosshair) conoutf("could not load model skin for %s", name1); - }; + } loopv(parts) parts[i]->scaleverts(scale/16.0f, vec(translate.x, translate.y, translate.z)); return loaded = true; - }; + } }; void md3load(char *model) @@ -216,7 +216,7 @@ void md3load(char *model) mdl.model = loadingmd3; mdl.index = loadingmd3->parts.length()-1; if(!mdl.load(path(filename))) conoutf("could not load %s", filename); // ignore failure -}; +} void md3skin(char *objname, char *skin) { @@ -230,9 +230,9 @@ void md3skin(char *objname, char *skin) { s_sprintfd(spath)("%s/%s", md3dir, skin); m.skin = textureload(spath); - }; - }; -}; + } + } +} void md3anim(char *anim, char *startframe, char *range, char *s) { @@ -241,7 +241,7 @@ void md3anim(char *anim, char *startframe, char *range, char *s) int num = findanim(anim); if(num<0) { conoutf("could not find animation %s", anim); return; }; loadingmd3->parts.last()->setanim(num, atoi(startframe), atoi(range), speed); -}; +} void md3link(char *parentno, char *childno, char *tagname) { @@ -249,7 +249,7 @@ void md3link(char *parentno, char *childno, char *tagname) int parent = atoi(parentno), child = atoi(childno); if(max(parent, child) >= loadingmd3->parts.length() || min(parent, child) < 0) { conoutf("no models loaded to link"); return; }; if(!loadingmd3->parts[parent]->link(loadingmd3->parts[child], tagname)) conoutf("could not link model %s", loadingmd3->loadname); -}; +} COMMAND(md3load, ARG_1STR); COMMAND(md3skin, ARG_3STR); diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 1bea40c9..710316b2 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -29,7 +29,7 @@ void menuset(void *m) if(!curmenu) return; if(curmenu->allowinput) player1->stopmoving(); else curmenu->menusel = 0; -}; +} void showmenu(char *name) { @@ -37,11 +37,11 @@ void showmenu(char *name) { curmenu = NULL; return; - }; + } gmenu *m = menus.access(name); if(!m) return; menuset(m); -}; +} int menucompare(mitem *a, mitem *b) { @@ -50,11 +50,11 @@ int menucompare(mitem *a, mitem *b) if(x>y) return -1; if(xw) w = x; - }; + } int tw = text_width(title); if(tw>w) w = tw; int step = FONTH/4*5; @@ -84,19 +84,19 @@ bool rendermenu() { int bh = y+m.menusel*step; blendbox(x-FONTH, bh-10, x+w+FONTH, bh+FONTH+10, false); - }; + } loopj(mdisp) { draw_text(m.items[j].text, x, y); y += step; - }; + } if(!m.hastitle) text_endcolumns(); return true; -}; +} void rendermenumdl() { - if(!curmenu) { menustack.setsize(0); return; }; + if(!curmenu) { menustack.setsize(0); return; } gmenu &m = *curmenu; if(!m.mdl) return; @@ -123,7 +123,7 @@ void rendermenumdl() { s_sprintfd(skin)("packages/models/%s.jpg", m.mdl); tex = -textureload(skin)->id; - }; + } rendermodel(isplayermodel ? (char *)"playermodels" : m.mdl, m.anim, tex, 0, pos.x, pos.z, pos.y, yaw, 0, 100, 0, NULL, isplayermodel ? (char*)"weapons/subgun/world" : NULL, m.scale ? m.scale/25.0f : 1.0f); glPopMatrix(); @@ -141,12 +141,12 @@ void *addmenu(char *name, bool allowinput, bool hastitle, void (__cdecl *refresh menu.refreshfunc = refreshfunc; lastmenu = &menu; return &menu; -}; +} void newmenu(char *name) { addmenu(name); -}; +} void menumanual(void *menu, int n, char *text, char *action) { @@ -162,7 +162,7 @@ void sortmenu(void *menu, int start, int num) { gmenu &m = *(gmenu *)menu; m.items.sort(menucompare, start, num); -}; +} void menuitem(char *text, char *action, char *hoveraction) { @@ -172,7 +172,7 @@ void menuitem(char *text, char *action, char *hoveraction) mi.text = newstring(text); mi.action = action[0] ? newstring(action) : mi.text; mi.hoveraction = hoveraction[0] ? newstring(hoveraction) : NULL; -}; +} void menumdl(char *mdl, char *anim, char *rotspeed, char *scale) { @@ -182,7 +182,7 @@ void menumdl(char *mdl, char *anim, char *rotspeed, char *scale) menu.anim = findanim(anim)|ANIM_LOOP; menu.rotspeed = max(0, min(atoi(rotspeed), 100)); menu.scale = max(0, min(atoi(scale), 100)); -}; +} void chmenumdl(char *menu, char *mdl, char *anim, char *rotspeed, char *scale) { @@ -193,7 +193,7 @@ void chmenumdl(char *menu, char *mdl, char *anim, char *rotspeed, char *scale) m.anim = findanim(anim)|ANIM_LOOP; m.rotspeed = max(0, min(atoi(rotspeed), 100)); m.scale = max(0, min(atoi(scale), 100)); -}; +} COMMAND(menuitem, ARG_3STR); @@ -226,18 +226,18 @@ bool menukey(int code, bool isdown) curmenu->menusel = menusel; char *haction = curmenu->items[menusel].hoveraction; if(menusel != oldmenusel && haction) execute(haction); - }; + } } else { if(code==SDLK_RETURN || code==-1 || code==-2) { - if(menusel<0 || menusel >= curmenu->items.length()) { menuset(NULL); return true; }; + if(menusel<0 || menusel >= curmenu->items.length()) { menuset(NULL); return true; } char *action = curmenu->items[menusel].action; menustack.add(curmenu); menuset(NULL); if(action) execute(action); - }; - }; + } + } return true; -}; +} diff --git a/source/src/model.h b/source/src/model.h index 67163f66..692e6a52 100644 --- a/source/src/model.h +++ b/source/src/model.h @@ -13,10 +13,10 @@ struct animstate // used for animation blending o { int anim, frame, range, basetime; float speed; - animstate() : anim(0), frame(0), range(0), basetime(0), speed(100.0f) { }; + animstate() : anim(0), frame(0), range(0), basetime(0), speed(100.0f) { } - bool operator==(const animstate &o) const { return frame==o.frame && range==o.range && basetime==o.basetime && speed==o.speed; }; - bool operator!=(const animstate &o) const { return frame!=o.frame || range!=o.range || basetime!=o.basetime || speed!=o.speed; }; + bool operator==(const animstate &o) const { return frame==o.frame && range==o.range && basetime==o.basetime && speed==o.speed; } + bool operator!=(const animstate &o) const { return frame!=o.frame || range!=o.range || basetime!=o.basetime || speed!=o.speed; } }; enum { MDL_MD2 = 1, MDL_MD3 }; @@ -28,16 +28,16 @@ struct model float scale; vec translate; - model() : scale(1), translate(0, 0, 0) {}; - virtual ~model() {}; + model() : scale(1), translate(0, 0, 0) {} + virtual ~model() {} virtual void render(int anim, int varseed, float speed, int basetime, float x, float y, float z, float yaw, float pitch, dynent *d, model *vwepmdl = NULL, float scale = 1.0f) = 0; virtual void setskin(int tex = 0) = 0; virtual bool load() = 0; virtual char *name() = 0; virtual int type() = 0; - virtual void genshadows(float height, float rad) {}; - virtual void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw, model *vwepmdl = NULL) {}; + virtual void genshadows(float height, float rad) {} + virtual void rendershadow(int anim, int varseed, float speed, int basetime, const vec &o, float rad, float yaw, model *vwepmdl = NULL) {} }; struct mapmodelinfo { int rad, h, zoff; string name; model *m; }; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 893cec83..bfd53274 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -17,9 +17,9 @@ bool plcollide(physent *d, physent *o, float &headspace, float &hi, float &lo) if(fabs(o->o.z-d->o.z)aboveeye+d->eyeheight) return false; headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; if(headspace<0) headspace = 10; - }; + } return true; -}; +} bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs) // recursively collide with a mipmapped corner cube { @@ -35,9 +35,9 @@ bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs by = y<floor+mmi.zoff+e.attr3); if(d->o.z-d->eyeheightlo) lo = mmz+mmi.h; - }; - }; -}; + } + } +} // all collision happens here // spawn is a dirty side effect used in spawning @@ -93,7 +93,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) || x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs) return false; break; - }; + } case FHF: // FIXME: too simplistic collision with slopes, makes it feels like tiny stairs floor -= (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; @@ -102,10 +102,10 @@ bool collide(physent *d, bool spawn, float drop, float rise) case CHF: ceil += (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; - }; + } if(ceillo) lo = floor; - }; + } if(hi-lo < d->eyeheight+d->aboveeye) return false; @@ -117,7 +117,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) playerent *o = players[i]; if(!o || o==d || (o==player1 && d->type==ENT_CAMERA)) continue; if(!plcollide(d, o, headspace, hi, lo)) return false; - }; + } if(d!=player1) if(!plcollide(d, player1, headspace, hi, lo)) return false; headspace -= 0.01f; @@ -144,7 +144,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) else { d->o.z -= min(min(drop, spacetop), headspace); // gravity - }; + } const float spacebottom = hi-(d->o.z+d->aboveeye); if(spacebottom<0) @@ -152,10 +152,10 @@ bool collide(physent *d, bool spawn, float drop, float rise) if(spacebottom<-0.1) return false; // hack alert! d->o.z = hi-d->aboveeye; // glue to ceiling d->vel.z = 0; // cancel out jumping velocity - }; + } d->onfloor = d->o.z-d->eyeheight-lo<0.01f; - }; + } return true; } @@ -193,7 +193,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) const float gravity = 9.81f/1000.0f*bounce->maxspeed; const float heightvel = (gravity)*pow(speed, 2.0f); bounce->vel.z -= heightvel; - }; + } d = bounce->vel; d.mul(speed); @@ -216,7 +216,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) d.x *= (float)cosf(RAD*(pl->pitch)); d.y *= (float)cosf(RAD*(pl->pitch)); d.z = (float)(move*sinf(RAD*(pl->pitch))); - }; + } d.x += (float)(pl->strafe*cosf(RAD*(pl->yaw-180))); d.y += (float)(pl->strafe*sinf(RAD*(pl->yaw-180))); @@ -243,7 +243,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) { if(((playerent *)pl)->k_up) pl->vel.z = climbspeed; else if(((playerent *)pl)->k_down) pl->vel.z = -climbspeed; - }; + } pl->timeinair = 0; } else @@ -254,7 +254,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) { pl->jumpnext = false; pl->vel.z = 2.0f; //1.7f; // physics impulse upwards - if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel + if(water) { pl->vel.x /= 8; pl->vel.y /= 8; } // dampen velocity change even harder, gives correct water feel if(local) playsoundc(S_JUMP); else if(pl->type==ENT_BOT) playsound(S_JUMP, &pl->o); // Added by Rick } @@ -263,18 +263,18 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) else { pl->timeinair += curtime; - }; - }; - }; + } + } + } const float gravity = 20.0f; float dropf = (gravity-1)+pl->timeinair/15.0f; // incorrect, but works fine - if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water - if(pl->onladder) { dropf = 0; pl->timeinair = 0; }; + if(water) { dropf = 5; pl->timeinair = 0; } // float slowly down in water + if(pl->onladder) { dropf = 0; pl->timeinair = 0; } drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs - }; + } if(!floating) loopi(moveres) // discrete steps collision detection & sliding { @@ -293,7 +293,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) d.x = 0; if(pl->type==ENT_BOUNCE) { pl->vel.x = -pl->vel.x; pl->vel.mul(0.7f); } continue; - }; + } pl->o.x += f*d.x; // still stuck, try x axis pl->o.y -= f*d.y; @@ -302,7 +302,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) d.y = 0; if(pl->type==ENT_BOUNCE) { pl->vel.y = -pl->vel.y; pl->vel.mul(0.7f); } continue; - }; + } pl->o.y += f*d.y; // try just dropping down pl->o.x -= f*d.x; @@ -311,11 +311,11 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) { d.y = d.x = 0; continue; - }; + } pl->o.z -= f*d.z; if(pl->type==ENT_BOUNCE) { pl->vel.z = -pl->vel.z; pl->vel.mul(0.5f); } break; - }; + } if(pl->type==ENT_CAMERA) return; else if(pl->type!=ENT_BOUNCE) @@ -330,8 +330,8 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) pl->roll += pl->strafe*curtime/-30.0f; if(pl->roll>maxroll) pl->roll = (float)maxroll; if(pl->roll<-maxroll) pl->roll = (float)-maxroll; - }; - }; + } + } // play sounds on water transitions if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } @@ -340,7 +340,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) // Added by Rick: Easy hack to store previous locations of all players/monsters/bots if(pl->type==ENT_PLAYER || pl->type==ENT_BOT) ((playerent *)pl)->history.update(pl->o, lastmillis); // End add -}; +} VARP(minframetime, 5, 10, 20); @@ -357,13 +357,13 @@ void physicsframe() // optimally schedule physics frames inside the gra else { physicsrepeat = 1; - }; -}; + } +} void moveplayer(physent *p, int moveres, bool local) { loopi(physicsrepeat) moveplayer(p, moveres, local, min(curtime, minframetime)); -}; +} vector bounceents; @@ -390,12 +390,12 @@ void mbounceents() delete p; bounceents.remove(i); i--; - }; - }; -}; + } + } +} void clearbounceents() { - loopv(bounceents) if(bounceents[i]) { delete bounceents[i]; bounceents.remove(i); }; -}; + loopv(bounceents) if(bounceents[i]) { delete bounceents[i]; bounceents.remove(i); } +} diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index f0592c58..c2ee97e9 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -10,7 +10,7 @@ void setarraypointers() glVertexPointer(3, GL_FLOAT, sizeof(vertex), &buf->x); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), &buf->r); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &buf->u); -}; +} // generating the actual vertices is done dynamically every frame and sits at the // leaves of all these functions, and are part of the cpu bottleneck on really slow @@ -21,7 +21,7 @@ void setarraypointers() v.u = t1; v.v = t2; \ v.x = (float)(v1); v.y = (float)(v2); v.z = (float)(v3); \ v.r = ls->r; v.g = ls->g; v.b = ls->b; v.a = 255; \ -}; +} int nquads; const float TEXTURESCALE = 32.0f; @@ -31,8 +31,8 @@ int ol3r, ol3g, ol3b, ol4r, ol4g, ol4b; int firstindex; bool showm = false; -void showmip() { showm = !showm; }; -void mipstats(int a, int b, int c) { if(showm) conoutf("1x1/2x2/4x4: %d / %d / %d", a, b, c); }; +void showmip() { showm = !showm; } +void mipstats(int a, int b, int c) { if(showm) conoutf("1x1/2x2/4x4: %d / %d / %d", a, b, c); } COMMAND(showmip, ARG_NONE); @@ -44,19 +44,19 @@ VAR(mergestrips, 0, 1, 1); if(mergestrips) switch(len) { \ case 3: type = GL_TRIANGLES; break; \ case 4: type = GL_QUADS; swap(vertex, verts.last(), verts[verts.length()-2]); break; \ - }; \ + } \ addstrip(type, striptex, firstindex, len); \ floorstrip = deltastrip = false; \ - }; + } -void finishstrips() { stripend(); }; +void finishstrips() { stripend(); } sqr sbright, sdark; VARP(lighterror,1,8,100); void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3, sqr *l4, bool isceil) // floor/ceil quads { - if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; }; + if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; } int sx, sy; lookuptexture(wtex, sx, sy); @@ -86,7 +86,7 @@ void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr { vert(x, h, y, l1, xo, yo); vert(x+size, h, y, l2, xo+xs, yo); - }; + } ol3r = l1->r; ol3g = l1->g; ol3b = l1->b; @@ -114,8 +114,8 @@ void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr ol4r = p4[0]; ol4g = p4[1]; ol4b = p4[2]; - }; - }; + } + } if(isceil) { @@ -126,15 +126,15 @@ void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr { vert(x, h, y+size, l4, xo, yo+ys); vert(x+size, h, y+size, l3, xo+xs, yo+ys); - }; + } oy = y; nquads++; -}; +} void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, float h3, float h4, sqr *l1, sqr *l2, sqr *l3, sqr *l4, bool isceil) // floor/ceil quads on a slope { - if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; }; + if(showm) { l3 = l1 = &sbright; l4 = l2 = &sdark; } int sx, sy; lookuptexture(wtex, sx, sy); @@ -163,14 +163,14 @@ void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, floa { vert(x, h1, y, l1, xo, yo); vert(x+size, h2, y, l2, xo+xs, yo); - }; + } ol3r = l1->r; ol3g = l1->g; ol3b = l1->b; ol4r = l2->r; ol4g = l2->g; ol4b = l2->b; - }; + } if(isceil) { @@ -181,11 +181,11 @@ void render_flatdelta(int wtex, int x, int y, int size, float h1, float h2, floa { vert(x, h4, y+size, l4, xo, yo+ys); vert(x+size, h3, y+size, l3, xo+xs, yo+ys); - }; + } oy = y; nquads++; -}; +} void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3, sqr *l1, sqr *l2, sqr *l3) // floor/ceil tris on a corner cube { @@ -210,7 +210,7 @@ void render_2tris(sqr *h, sqr *s, int x1, int y1, int x2, int y2, int x3, int y3 vert(x1, h->ceil, y1, l1, xf*x1, yf*y1); addstrip(mergestrips ? GL_TRIANGLES : GL_TRIANGLE_STRIP, h->ctex, verts.length()-3, 3); nquads++; -}; +} void render_tris(int x, int y, int size, bool topleft, sqr *h1, sqr *h2, sqr *s, sqr *t, sqr *u, sqr *v) @@ -224,13 +224,13 @@ void render_tris(int x, int y, int size, bool topleft, { if(h1) render_2tris(h1, s, x, y, x+size, y, x, y+size, s, t, u); if(h2) render_2tris(h2, s, x+size, y, x+size, y+size, x, y+size, t, u, v); - }; -}; + } +} void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil2, int x1, int y1, int x2, int y2, int size, sqr *l1, sqr *l2, bool flip) // wall quads { stripend(); - if(showm) { l1 = &sbright; l2 = &sdark; }; + if(showm) { l1 = &sbright; l2 = &sdark; } int sx, sy; lookuptexture(wtex, sx, sy); @@ -254,10 +254,10 @@ void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil if(mergestrips) vert(x2, floor2, y2, l2, xo+xs, -floor2*yf); vert(x1, floor1, y1, l1, xo, -floor1*yf); if(!mergestrips) vert(x2, floor2, y2, l2, xo+xs, -floor2*yf); - }; + } addstrip(mergestrips ? GL_QUADS : GL_TRIANGLE_STRIP, wtex, verts.length()-4, 4); nquads++; -}; +} int wx1, wy1, wx2, wy2; @@ -268,10 +268,10 @@ inline void vertw(int v1, float v2, int v3, float t1, float t2, float t) { glTexCoord2f(t1, t2); glVertex3f((float)v1, v2-sinf(v1*v3*0.1+t)*0.2f, (float)v3); -}; +} -inline float dx(float x) { return x+sinf(x*2+lastmillis/1000.0f)*0.04f; }; -inline float dy(float x) { return x+sinf(x*2+lastmillis/900.0f+PI/5)*0.05f; }; +inline float dx(float x) { return x+sinf(x*2+lastmillis/1000.0f)*0.04f; } +inline float dy(float x) { return x+sinf(x*2+lastmillis/900.0f+PI/5)*0.05f; } // renders water for bounding rect area that contains water... simple but very inefficient @@ -308,18 +308,18 @@ int renderwater(float hf) { vertw(xx, hf, yy, dx(xo), dy(yo), t1); vertw(xx+watersubdiv, hf, yy, dx(xo+xs), dy(yo), t1); - }; + } vertw(xx, hf, yy+watersubdiv, dx(xo), dy(yo+ys), t1); vertw(xx+watersubdiv, hf, yy+watersubdiv, dx(xo+xs), dy(yo+ys), t1); - }; + } glEnd(); - }; + } glDisable(GL_BLEND); glDepthMask(GL_TRUE); return nquads; -}; +} void addwaterquad(int x, int y, int size) // update bounding rect that contains water { @@ -338,8 +338,8 @@ void addwaterquad(int x, int y, int size) // update bounding rect that con if(ywx2) wx2 = x2; if(y2>wy2) wy2 = y2; - }; -}; + } +} void resetcubes() { @@ -350,6 +350,6 @@ void resetcubes() nquads = 0; sbright.r = sbright.g = sbright.b = 255; sdark.r = sdark.g = sdark.b = 0; -}; +} diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 528e9b12..c7e04ebb 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -11,13 +11,13 @@ void line(int x1, int y1, float z1, int x2, int y2, float z2) glVertex3f((float)x2, z2, (float)y2); glEnd(); xtraverts += 4; -}; +} void linestyle(float width, int r, int g, int b) { glLineWidth(width); glColor3ub(r,g,b); -}; +} void box(block &b, float z1, float z2, float z3, float z4) { @@ -28,7 +28,7 @@ void box(block &b, float z1, float z2, float z3, float z4) glVertex3f((float)b.x, z4, (float)b.y+b.ys); glEnd(); xtraverts += 4; -}; +} void dot(int x, int y, float z) { @@ -40,7 +40,7 @@ void dot(int x, int y, float z) glVertex3f(x-DOF, (float)z, y+DOF); glEnd(); xtraverts += 4; -}; +} void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) { @@ -100,7 +100,7 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) glTexCoord2f(0, 1); glVertex2i(x1, y2); glEnd(); xtraverts += 4; - }; + } glDisable(GL_BLEND); if(tex>=0) glDisable(GL_TEXTURE_2D); @@ -116,7 +116,7 @@ void blendbox(int x1, int y1, int x2, int y2, bool border, int tex) glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); -}; +} const int MAXSPHERES = 50; struct sphere { vec o; float size, max; int type; sphere *next; }; @@ -131,9 +131,9 @@ void newsphere(vec &o, float max, int type) { spheres[i].next = sempty; sempty = &spheres[i]; - }; + } sinit = true; - }; + } if(sempty) { sphere *p = sempty; @@ -144,8 +144,8 @@ void newsphere(vec &o, float max, int type) p->type = type; p->next = slist; slist = p; - }; -}; + } +} void renderspheres(int time) { @@ -183,12 +183,12 @@ void renderspheres(int time) { p->size += time/100.0f; pp = &p->next; - }; - }; + } + } glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} string closeent; char *entnames[] = @@ -210,14 +210,14 @@ void renderents() // show sparkly thingies for map entities in edit mode if(e.type==NOTUSED) continue; vec v(e.x, e.y, e.z); particle_splash(2, 2, 40, v); - }; + } int e = closestent(); if(e>=0) { entity &c = ents[e]; s_sprintf(closeent)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, getvar("selxs"), getvar("selys")); - }; -}; + } +} float cursordepth = 0.9f; GLint viewport[4]; @@ -231,14 +231,14 @@ void readmatrices() glGetDoublev(GL_PROJECTION_MATRIX, pm); camright = vec(float(mm[0]), float(mm[4]), float(mm[8])); camup = vec(float(mm[1]), float(mm[5]), float(mm[9])); -}; +} // stupid function to cater for stupid ATI linux drivers that return incorrect depth values float depthcorrect(float d) { return (d<=1/256.0f) ? d*256 : d; -}; +} // find out the 3d target of the crosshair in the world easily and very acurately. // sadly many very old cards and drivers appear to fuck up on glReadPixels() and give false @@ -254,7 +254,7 @@ void readdepth(int w, int h, vec &pos) pos.x = (float)worldx; pos.y = (float)worldy; pos.z = (float)worldz; -}; +} void drawicon(float tx, float ty, int x, int y, Texture *tex = NULL, float scaling = 1/3.0f) // EDIT: AH { @@ -263,7 +263,7 @@ void drawicon(float tx, float ty, int x, int y, Texture *tex = NULL, float scali static Texture *itemstex = NULL; if(!itemstex) itemstex = textureload("packages/misc/items.png"); tex = itemstex; - }; + } glBindTexture(GL_TEXTURE_2D, tex->id); glBegin(GL_QUADS); tx /= 192; @@ -276,7 +276,7 @@ void drawicon(float tx, float ty, int x, int y, Texture *tex = NULL, float scali glTexCoord2f(tx, ty+o); glVertex2i(x, y+s); glEnd(); xtraverts += 4; -}; +} void invertperspective() { @@ -291,12 +291,12 @@ void invertperspective() inv[3*4+3] = pm[2*4+2]/pm[3*4+2]; glLoadMatrixd(inv); -}; +} VARP(crosshairsize, 0, 15, 50); int dblend = 0; -void damageblend(int n) { dblend += n; }; +void damageblend(int n) { dblend += n; } VARP(hidestats, 0, 1, 1); VARP(crosshairfx, 0, 1, 1); @@ -310,7 +310,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); cursorupdate(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - }; + } glDisable(GL_DEPTH_TEST); invertperspective(); @@ -333,7 +333,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glDepthMask(GL_TRUE); dblend -= min(1, curtime/3); if(dblend<0) dblend = 0; - }; + } glEnable(GL_TEXTURE_2D); @@ -378,16 +378,16 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat { if(player1->health<=25) glColor3ub(255,0,0); else if(player1->health<=50) glColor3ub(255,128,0); - }; - }; + } + } float chsize = (float)crosshairsize * (player1->gunselect==GUN_ASSAULT && player1->shots > 3 ? 1.4f : 1.0f) * (teammate_in_xhair ? 2.0f : 1.0f); glTexCoord2i(0, 0); glVertex2f(VIRTW/2 - chsize, VIRTH/2 - chsize); glTexCoord2i(1, 0); glVertex2f(VIRTW/2 + chsize, VIRTH/2 - chsize); glTexCoord2i(1, 1); glVertex2f(VIRTW/2 + chsize, VIRTH/2 + chsize); glTexCoord2i(0, 1); glVertex2f(VIRTW/2 - chsize, VIRTH/2 + chsize); glEnd(); - }; - }; + } + } if(getcurcommand()) rendercommand(20, 1570); else if(closeent[0]) draw_text(closeent, 20, 1570); @@ -409,7 +409,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat draw_textf("wqd %d", 3200, 2460, nquads); draw_textf("wvt %d", 3200, 2530, curvert); draw_textf("evt %d", 3200, 2600, xtraverts); - }; + } glPopMatrix(); @@ -425,7 +425,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(player1->gunselect!=GUN_GRENADE) sprintf(gunstats,"%i/%i",player1->mag[player1->gunselect],player1->ammo[player1->gunselect]); else sprintf(gunstats,"%i",player1->mag[player1->gunselect]); draw_text(gunstats, 690, 827); - }; + } glPopMatrix(); if(didteamkill) @@ -434,7 +434,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glOrtho(0, VIRTW/3, VIRTH/3, 0, -1, 1); draw_text("\f3you killed a teammate", VIRTW/3/40, VIRTH/3/2); glPopMatrix(); - }; + } #define ctf_scl 0.75 if(m_ctf) @@ -464,8 +464,8 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glEnable(GL_BLEND); drawicon((float)(team_opposite(team_int(player1->team))*128*ctf_scl),(float)(128*ctf_scl), 1065, VIRTH/2/3*2, flagtex, 1.0/2.0); glPopMatrix(); - }; - }; + } + } glPushMatrix(); glOrtho(0, VIRTW, VIRTH, 0, -1, 1); @@ -484,7 +484,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(player1->armour) drawicon((float)(128), 0, 620, 1650); int g = player1->gunselect; int r = 64; - if(g>2) { g -= 3; r = 128; }; + if(g>2) { g -= 3; r = 128; } if(!player1->mag[player1->gunselect] && player1->gunselect != GUN_KNIFE && player1->gunselect != GUN_GRENADE) { @@ -496,14 +496,14 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat { if (player1->gunselect==GUN_GRENADE) drawicon(0, 0, 1220, 1650); else drawicon((float)(g*64), (float)r, 1220, 1650); - }; + } glPopMatrix(); - }; + } glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); -}; +} #define MAXSHOTLINES 100 struct shotline @@ -514,7 +514,7 @@ struct shotline }; shotline shotlines[MAXSHOTLINES]; -void shotlinereset() { loopi(MAXSHOTLINES) shotlines[i].inuse = false; }; +void shotlinereset() { loopi(MAXSHOTLINES) shotlines[i].inuse = false; } void addshotline(dynent *d, vec &from, vec &to) { @@ -538,8 +538,8 @@ void addshotline(dynent *d, vec &from, vec &to) s->to.mul(dist/10*-(10-start-2)).add(to); s->millis = lastmillis; return; - }; -}; + } +} void rendershotlines() { @@ -563,12 +563,12 @@ void rendershotlines() glColor4f(1.0f, 1.0f, 0.7f, 0.5f); glBegin(GL_LINES); - }; + } ++lines; glVertex3f(s->from.x, s->from.z, s->from.y); glVertex3f(s->to.x, s->to.z, s->to.y); - }; + } if(lines) { glEnd(); @@ -579,8 +579,8 @@ void rendershotlines() glEnable(GL_TEXTURE_2D); glPopMatrix(); - }; -}; + } +} void renderbounceents() { @@ -606,14 +606,14 @@ void renderbounceents() { t -= p->timetolife-2000; z -= t*t/4000000000.0f*t; - }; + } break; - }; - }; + } + } path(model); rendermodel(model, ANIM_MAPMODEL|ANIM_LOOP, 0, 1.1f, p->o.x, z, p->o.y, p->yaw, p->pitch, 10.0f); - }; -}; + } +} VARP(gibnum, 0, 6, 1000); VARP(gibttl, 0, 5000, 15000); @@ -648,8 +648,8 @@ void addgib(playerent *d) p->vel.y = cosf(RAD*angle)*rnd(1000)/1000.0f; p->vel.z = rnd(1000)/1000.0f; p->vel.mul(gibspeed/100.0f); - }; -}; + } +} // fixme void gibtest() { playerent t = *player1; t.o.x = worldpos.x; t.o.y = worldpos.y; addgib(&t); } @@ -680,9 +680,9 @@ void loadingscreen() glEnd(); SDL_GL_SwapBuffers(); - }; + } glDisable(GL_TEXTURE_2D); glPopMatrix(); -}; +} diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 8f43f12e..ba914def 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -62,14 +62,14 @@ void gl_init(int w, int h, int bpp, int depth, int fsaa) if(fsaa) glEnable(GL_MULTISAMPLE); camera1 = player1; -}; +} Texture *crosshair = NULL; hashtable textures; void cleangl() { -}; +} void createtexture(int tnum, int w, int h, void *pixels, int clamp, GLenum format) { @@ -82,28 +82,28 @@ void createtexture(int tnum, int w, int h, void *pixels, int clamp, GLenum forma glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int tw = w, th = h; - if(maxtexsize) while(tw>maxtexsize || th>maxtexsize) { tw /= 2; th /= 2; }; + if(maxtexsize) while(tw>maxtexsize || th>maxtexsize) { tw /= 2; th /= 2; } if(tw!=w) { if(gluScaleImage(format, w, h, GL_UNSIGNED_BYTE, pixels, tw, th, GL_UNSIGNED_BYTE, pixels)) { tw = w; th = h; - }; - }; + } + } if(gluBuild2DMipmaps(GL_TEXTURE_2D, format, tw, th, format, GL_UNSIGNED_BYTE, pixels)) fatal("could not build mipmaps"); -}; +} GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) { SDL_Surface *s = IMG_Load(texname); - if(!s) { conoutf("couldn't load texture %s", texname); return 0; }; + if(!s) { conoutf("couldn't load texture %s", texname); return 0; } if(s->format->BitsPerPixel!=24 && s->format->BitsPerPixel!=32) { SDL_FreeSurface(s); conoutf("texture must be 24bpp or 32bpp: %s", texname); return 0; - }; + } GLuint tnum; glGenTextures(1, &tnum); createtexture(tnum, s->w, s->h, s->pixels, clamp, s->format->BitsPerPixel==24 ? GL_RGB : GL_RGBA); @@ -111,7 +111,7 @@ GLuint loadsurface(const char *texname, int &xs, int &ys, int clamp) ys = s->h; SDL_FreeSurface(s); return tnum; -}; +} // management of texture slots // each texture slot can have multople texture frames, of which currently only the first is used @@ -134,7 +134,7 @@ Texture *textureload(const char *name, int clamp) t->ys = ys; t->id = id; return t; -}; +} struct Slot { @@ -142,10 +142,10 @@ struct Slot Texture *tex; bool loaded; }; - + vector slots; -void texturereset() { slots.setsizenodelete(0); }; +void texturereset() { slots.setsizenodelete(0); } void texture(char *aframe, char *name) { @@ -154,7 +154,7 @@ void texture(char *aframe, char *name) path(s.name); s.tex = NULL; s.loaded = false; -}; +} COMMAND(texturereset, ARG_NONE); COMMAND(texture, ARG_2STR); @@ -170,14 +170,14 @@ int lookuptexture(int tex, int &xs, int &ys) s_sprintfd(pname)("packages/textures/%s", s.name); s.tex = textureload(pname); s.loaded = true; - }; + } if(s.tex) t = s.tex; - }; + } xs = t->xs; ys = t->ys; return t->id; -}; +} void setupworld() { @@ -192,8 +192,8 @@ void setupworld() glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); - }; -}; + } +} struct strip { int type, start, num; }; @@ -215,7 +215,7 @@ void renderstripssky() glBindTexture(GL_TEXTURE_2D, lookuptexture(DEFAULT_SKY, xs, ys)); loopv(skystrips) glDrawArrays(skystrips[i].type, skystrips[i].start, skystrips[i].num); skystrips.setsizenodelete(0); -}; +} void renderstrips() { @@ -226,11 +226,11 @@ void renderstrips() glBindTexture(GL_TEXTURE_2D, lookuptexture(sb.tex, xs, ys)); loopv(sb.strips) glDrawArrays(sb.strips[i].type, sb.strips[i].start, sb.strips[i].num); sb.strips.setsizenodelete(0); - }; + } renderedtexs = 0; -}; +} -void overbright(float amount) { if(hasoverbright) glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, amount ); }; +void overbright(float amount) { if(hasoverbright) glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, amount ); } void addstrip(int type, int tex, int start, int n) { @@ -244,9 +244,9 @@ void addstrip(int type, int tex, int start, int n) { sb = &stripbatches[renderedtex[tex] = renderedtexs++]; sb->tex = tex; - }; + } strips = &sb->strips; - }; + } if(type!=GL_TRIANGLE_STRIP && !strips->empty()) { strip &last = strips->last(); @@ -254,13 +254,13 @@ void addstrip(int type, int tex, int start, int n) { last.num += n; return; - }; - }; + } + } strip &s = strips->add(); s.type = type; s.start = start; s.num = n; -}; +} VARFP(gamma, 30, 100, 300, { @@ -269,7 +269,7 @@ VARFP(gamma, 30, 100, 300, { conoutf("Could not set gamma (card/driver doesn't support it?)"); conoutf("sdl: %s", SDL_GetError()); - }; + } }); physent *camera1 = NULL; @@ -295,8 +295,8 @@ void recomputecamera() camera1 = &deathcam; loopi(10) moveplayer(camera1, 10, true, 50); - }; -}; + } +} void transplayer() { @@ -307,7 +307,7 @@ void transplayer() glRotatef(camera1->yaw, 0, 1, 0); glTranslatef(-camera1->o.x, -camera1->o.z, -camera1->o.y); -}; +} VARP(fov, 90, 100, 120); @@ -318,7 +318,7 @@ VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF); VARP(hudgun,0,1,1); -char *hudgunnames[] = { "knife", "pistol", "shotgun", "subgun", "sniper", "assault", "grenade"}; +char *hudgunnames[] = { "knife", "pistol", "shotgun", "subgun", "sniper", "assault", "grenade" }; void drawhudgun(int w, int h, float aspect, int farplane) { @@ -340,7 +340,7 @@ void drawhudgun(int w, int h, float aspect, int farplane) glMatrixMode(GL_MODELVIEW); glDisable(GL_CULL_FACE); -}; +} bool outsidemap(physent *pl) { @@ -349,7 +349,7 @@ bool outsidemap(physent *pl) return SOLID(s) || pl->o.z < s->floor - (s->type==FHF ? s->vdelta/4 : 0) || pl->o.z > s->ceil + (s->type==CHF ? s->vdelta/4 : 0); -}; +} void gl_drawframe(int w, int h, float changelod, float curfps) { @@ -372,7 +372,7 @@ void gl_drawframe(int w, int h, float changelod, float curfps) aspect += sinf(lastmillis/1000.0f+PI)*0.1f; glFogi(GL_FOG_START, 0); glFogi(GL_FOG_END, (fog+96)/8); - }; + } glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT); @@ -456,4 +456,4 @@ void gl_drawframe(int w, int h, float changelod, float curfps) glEnable(GL_CULL_FACE); glEnable(GL_FOG); -}; +} diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index 33fec4fd..c7d6f98e 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -18,7 +18,7 @@ void mdlscale(int percent) if(percent>0) scale = percent/100.0f; else if(percent<0) scale = 0.0f; loadingmodel->scale = scale; -}; +} COMMAND(mdlscale, ARG_1INT); @@ -26,7 +26,7 @@ void mdltrans(char *x, char *y, char *z) { checkmdl; loadingmodel->translate = vec(atof(x), atof(y), atof(z)); -}; +} COMMAND(mdltrans, ARG_3STR); @@ -39,11 +39,11 @@ void mapmodel(char *rad, char *h, char *zoff, char *snap, char *name) mmi.h = atoi(h); mmi.zoff = atoi(zoff); s_sprintf(mmi.name)("mapmodels/%s", name); -}; +} -void mapmodelreset() { mapmodels.setsize(0); }; +void mapmodelreset() { mapmodels.setsize(0); } -mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }; +mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; } COMMAND(mapmodel, ARG_5STR); COMMAND(mapmodelreset, ARG_NONE); @@ -58,7 +58,7 @@ model *loadmodel(const char *name, int i) mapmodelinfo &mmi = mapmodels[i]; if(mmi.m) return mmi.m; name = mmi.name; - }; + } model **mm = mdllookup.access(name); model *m; if(mm) m = *mm; @@ -76,14 +76,14 @@ model *loadmodel(const char *name, int i) delete m; loadingmodel = NULL; return NULL; - }; - }; + } + } loadingmodel = NULL; mdllookup.access(m->name(), &m); - }; + } if(mapmodels.inrange(i) && !mapmodels[i].m) mapmodels[i].m = m; return m; -}; +} VARP(dynshadow, 0, 40, 100); @@ -104,7 +104,7 @@ void rendermodel(char *mdl, int anim, int tex, float rad, float x, float y, floa { vwep = loadmodel(vwepmdl); if(vwep->type()!=m->type()) vwep = NULL; - }; + } if(!OUTBORD(ix, iy)) { @@ -124,8 +124,8 @@ void rendermodel(char *mdl, int anim, int tex, float rad, float x, float y, floa center.z += 0.1f; glColor4f(1, 1, 1, dynshadow/100.0f); m->rendershadow(anim, varseed, speed, basetime, center, radius, yaw, vwep); - }; - }; + } + } glColor3fv(&light.x); m->setskin(tex); @@ -133,14 +133,14 @@ void rendermodel(char *mdl, int anim, int tex, float rad, float x, float y, floa if(anim&ANIM_MIRROR) glCullFace(GL_BACK); m->render(anim, varseed, speed, basetime, x, y, z, yaw, pitch, d, vwep, scale); if(anim&ANIM_MIRROR) glCullFace(GL_FRONT); -}; +} int findanim(const char *name) { const char *names[] = { "idle", "run", "attack", "pain", "jump", "land", "flipoff", "salute", "taunt", "wave", "point", "crouch idle", "crouch walk", "crouch attack", "crouch pain", "crouch death", "death", "lying dead", "flag", "gun idle", "gun shoot", "gun reload", "gun throw", "mapmodel", "trigger", "all" }; loopi(sizeof(names)/sizeof(names[0])) if(!strcmp(name, names[i])) return i; return -1; -}; +} void loadskin(const char *dir, const char *altdir, Texture *&skin, model *m) // model skin sharing { @@ -156,10 +156,10 @@ void loadskin(const char *dir, const char *altdir, Texture *&skin, model *m) // { strcpy(path+strlen(path)-3, "png"); ifnoload return; - }; - }; - }; -}; + } + } + } +} void preload_playermodels() { @@ -170,8 +170,8 @@ void preload_playermodels() s_sprintfd(vwep)("weapons/%s/world", hudgunnames[i]); model *vwepmdl = loadmodel(vwep); if(dynshadow && vwepmdl) vwepmdl->genshadows(8.0f, 4.0f); - }; -}; + } +} void preload_mapmodels() { @@ -182,6 +182,6 @@ void preload_mapmodels() if(e.type!=MAPMODEL || !mapmodels.inrange(e.attr2)) continue; if(!loadmodel(NULL, e.attr2)) continue; if(e.attr4) lookuptexture(e.attr4, xs, ys); - }; -}; + } +} diff --git a/source/src/renderparticles.cpp b/source/src/renderparticles.cpp index c276fc64..9edc1c81 100644 --- a/source/src/renderparticles.cpp +++ b/source/src/renderparticles.cpp @@ -18,9 +18,9 @@ void newparticle(vec &o, vec &d, int fade, int type, int tex = -1) { particles[i].next = parempty; parempty = &particles[i]; - }; + } parinit = true; - }; + } if(parempty) { particle *p = parempty; @@ -33,8 +33,8 @@ void newparticle(vec &o, vec &d, int fade, int type, int tex = -1) p->next = parlist; p->tex = tex; parlist = p; - }; -}; + } +} VAR(demotracking, 0, 0, 1); VAR(particlesize, 20, 100, 500); @@ -45,7 +45,7 @@ void render_particles(int time) { vec nom(0, 0, 0); newparticle(player1->o, nom, 100000000, 4); - }; + } if(!parlist) return; @@ -87,11 +87,11 @@ void render_particles(int time) if(lastpt) glEnd(); glBindTexture(GL_TEXTURE_2D, parttex[pt.tex]->id); glBegin(GL_QUADS); - }; + } if(!lastpt || pt.r!=lastpt->r || pt.g!=lastpt->g || pt.b!=lastpt->b) glColor3f(pt.r, pt.g, pt.b); lastpt = &pt; - }; + } float sz = pt.sz*particlesize/100.0f; // perf varray? @@ -114,15 +114,15 @@ void render_particles(int time) a.mul(time/20000.0f); p->o.add(a); pp = &p->next; - }; - }; + } + } if(lastpt) glEnd(); glEnable(GL_FOG); glDisable(GL_BLEND); glDepthMask(GL_TRUE); -}; +} void particle_splash(int type, int num, int fade, vec &p) { @@ -139,8 +139,8 @@ void particle_splash(int type, int num, int fade, vec &p) while(x*x+y*y+z*z>radius*radius); vec d((float)x, (float)y, (float)z); newparticle(p, d, rnd(fade*3), type); - }; -}; + } +} void particle_trail(int type, int fade, vec &s, vec &e) { @@ -153,5 +153,5 @@ void particle_trail(int type, int fade, vec &s, vec &e) p.add(v); vec d((float)(rnd(11)-5), (float)(rnd(11)-5), (float)(rnd(11)-5)); newparticle(p, d, rnd(fade)+fade, type); - }; -}; + } +} diff --git a/source/src/rendertext.cpp b/source/src/rendertext.cpp index 0e181f36..a63f234d 100644 --- a/source/src/rendertext.cpp +++ b/source/src/rendertext.cpp @@ -109,21 +109,21 @@ int char_width(int c, int x) c -= 33; int in_width = char_coords[c][2] - char_coords[c][0]; x += in_width + 1; - }; + } return x; -}; +} static vector *columns = NULL; void text_startcolumns() { if(!columns) columns = new vector; -}; +} void text_endcolumns() { DELETEP(columns); -}; +} int text_width(const char *str, int limit) { @@ -144,14 +144,14 @@ int text_width(const char *str, int limit) x = max(x, (*columns)[col]); (*columns)[col] = x; col++; - }; + } break; default: x = char_width(str[i], x); break; - }; - }; + } + } return x; } @@ -164,19 +164,19 @@ int text_visible(const char *str, int max) { i += 2; continue; - }; + } x = char_width(str[i], x); if(x > max) return i; ++i; - }; + } return i; -}; +} void draw_textf(const char *fstr, int left, int top, ...) { s_sprintfdlv(str, top, fstr); draw_text(str, left, top); -}; +} void draw_text(const char *str, int left, int top) { @@ -209,12 +209,12 @@ void draw_text(const char *str, int left, int top) case '2': glColor3ub(255,192,64); i++; continue; // yellow: gameplay action messages, only actions done by players case '3': glColor3ub(255,64,64); i++; continue; // red: important errors default: continue; // white: everything else - }; + } case ' ': x += FONTH/2; continue; - }; + } c -= 33; if(c<0 || c>=95) continue; @@ -236,8 +236,8 @@ void draw_text(const char *str, int left, int top) xtraverts += 4; x += in_width + 1; - }; -}; + } +} // also Don's code, so goes in here too :) @@ -251,8 +251,8 @@ void loadsky(char *basename) s_sprintfd(name)("packages/%s_%s.jpg", basename, side[i]); sky[i] = textureload(name, 3); if(!sky[i]) conoutf("could not load sky texture: %s", name); - }; -}; + } +} COMMAND(loadsky, ARG_1STR); diff --git a/source/src/rndmap.cpp b/source/src/rndmap.cpp index 6dd695ee..7da5d011 100644 --- a/source/src/rndmap.cpp +++ b/source/src/rndmap.cpp @@ -64,7 +64,7 @@ void perlinarea(block &b, int scale, int seed, int psize) if(!SOLID(s) && x!=b.x+b.xs && y!=b.y+b.ys) s->type = FHF; s->vdelta = (int)(perlinnoise_2D(x/((float)scale)+seed, y/((float)scale)+seed, 1000, 0.01f)*50+25); if(s->vdelta>128) s->vdelta = 0; - }; -}; + } +} diff --git a/source/src/savegamedemo.cpp b/source/src/savegamedemo.cpp index 9e1d3f64..c2d68aa4 100644 --- a/source/src/savegamedemo.cpp +++ b/source/src/savegamedemo.cpp @@ -11,14 +11,14 @@ int democlientnum = 0; void startdemo(); -void gzput(int i) { gzputc(f, i); }; -void gzputi(int i) { gzwrite(f, &i, sizeof(int)); }; -void gzputv(vec &v) { gzwrite(f, &v, sizeof(vec)); }; +void gzput(int i) { gzputc(f, i); } +void gzputi(int i) { gzwrite(f, &i, sizeof(int)); } +void gzputv(vec &v) { gzwrite(f, &v, sizeof(vec)); } -void gzcheck(int a, int b) { if(a!=b) fatal("savegame file corrupt (short)"); }; -int gzget() { char c = gzgetc(f); return c; }; -int gzgeti() { int i; gzcheck(gzread(f, &i, sizeof(int)), sizeof(int)); return i; }; -void gzgetv(vec &v) { gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec)); }; +void gzcheck(int a, int b) { if(a!=b) fatal("savegame file corrupt (short)"); } +int gzget() { char c = gzgetc(f); return c; } +int gzgeti() { int i; gzcheck(gzread(f, &i, sizeof(int)), sizeof(int)); return i; } +void gzgetv(vec &v) { gzcheck(gzread(f, &v, sizeof(vec)), sizeof(vec)); } void stop() { @@ -26,22 +26,22 @@ void stop() { if(demorecording) gzputi(-1); gzclose(f); - }; + } f = NULL; demorecording = false; demoplayback = false; demoloading = false; loopv(playerhistory) zapplayer(playerhistory[i]); playerhistory.setsize(0); -}; +} -void stopifrecording() { if(demorecording) stop(); }; +void stopifrecording() { if(demorecording) stop(); } void savestate(char *fn) { stop(); f = gzopen(fn, "wb9"); - if(!f) { conoutf("could not write %s", fn); return; }; + if(!f) { conoutf("could not write %s", fn); return; } gzwrite(f, (void *)"CUBESAVE", 8); gzputc(f, SDL_BYTEORDER==SDL_LIL_ENDIAN ? 1 : 0); gzputi(SAVEGAMEVERSION); @@ -56,21 +56,21 @@ void savestate(char *fn) { gzput(players[i]==NULL); gzwrite(f, players[i], sizeof(playerent)); - }; -}; + } +} void savegame(char *name) { conoutf("can only save classic sp games"); return; -}; +} void loadstate(char *fn) { stop(); if(multiplayer()) return; f = gzopen(fn, "rb9"); - if(!f) { conoutf("could not open %s", fn); return; }; + if(!f) { conoutf("could not open %s", fn); return; } string buf; gzread(f, buf, 8); @@ -85,19 +85,19 @@ void loadstate(char *fn) out: conoutf("aborting: savegame/demo from a different version of cube or cpu architecture"); stop(); -}; +} void loadgame(char *name) { s_sprintfd(fn)("savegames/%s.csgz", name); loadstate(fn); -}; +} void loadgameout() { stop(); conoutf("loadgame incomplete: savegame from a different version of this map"); -}; +} void loadgamerest() { @@ -108,7 +108,7 @@ void loadgamerest() { ents[i].spawned = gzgetc(f)!=0; if(ents[i].type==CARROT && !ents[i].spawned) trigger(ents[i].attr1, ents[i].attr2, true); - }; + } restoreserverstate(ents); gzread(f, player1, sizeof(playerent)); @@ -120,11 +120,11 @@ void loadgamerest() playerent *d = getclient(i); ASSERT(d); gzread(f, d, sizeof(playerent)); - }; + } conoutf("savegame restored"); if(demoloading) startdemo(); else stop(); -}; +} // demo functions @@ -144,10 +144,10 @@ void record(char *name) demorecording = true; starttime = lastmillis; ddamage = bdamage = 0; -}; +} -void demodamage(int damage, vec &o) { ddamage = damage; dorig = o; }; -void demoblend(int damage) { bdamage = damage; }; +void demodamage(int damage, vec &o) { ddamage = damage; dorig = o; } +void demoblend(int damage) { bdamage = damage; } void incomingdemodata(int chan, uchar *buf, int len, bool extras) { @@ -173,17 +173,17 @@ void incomingdemodata(int chan, uchar *buf, int len, bool extras) gzputi(bdamage); bdamage = 0; gzputi(ddamage); - if(ddamage) { gzputv(dorig); ddamage = 0; }; + if(ddamage) { gzputv(dorig); ddamage = 0; } // FIXME: add all other client state which is not send through the network - }; -}; + } +} void demo(char *name) { s_sprintfd(fn)("demos/%s.cdgz", name); loadstate(fn); demoloading = true; -}; +} void stopreset() { @@ -191,10 +191,10 @@ void stopreset() stop(); loopv(players) zapplayer(players[i]); disconnect(0, 0); -}; +} VAR(demoplaybackspeed, 10, 100, 1000); -int scaletime(int t) { return (int)(t*(100.0f/demoplaybackspeed))+starttime; }; +int scaletime(int t) { return (int)(t*(100.0f/demoplaybackspeed))+starttime; } void readdemotime() { @@ -202,9 +202,9 @@ void readdemotime() { stopreset(); return; - }; + } playbacktime = scaletime(playbacktime); -}; +} void startdemo() { @@ -216,7 +216,7 @@ void startdemo() ASSERT(d); *d = *player1; readdemotime(); -}; +} VAR(demodelaymsec, 0, 120, 500); @@ -230,13 +230,13 @@ void catmulrom(vec &z, vec &a, vec &b, vec &c, float s, vec &dest) // spline in dest.add(vec(b).mul(-2*s3 + 3*s2)); dest.add(vec(b).sub(z).mul(0.5f).mul(s3 - 2*s2 + s)); dest.add(vec(c).sub(a).mul(0.5f).mul(s3 - s2)); -}; +} void fixwrap(dynent *a, dynent *b) { while(b->yaw-a->yaw>180) a->yaw += 360; while(b->yaw-a->yaw<-180) a->yaw -= 360; -}; +} void demoplaybackstep() { @@ -248,7 +248,7 @@ void demoplaybackstep() conoutf("error: huge packet during demo play (%d)", len); stopreset(); return; - }; + } int chan = gzget(); uchar buf[MAXTRANS]; gzread(f, buf, len); @@ -273,9 +273,9 @@ void demoplaybackstep() target->state = gzget(); target->lastmove = playbacktime; if((bdamage = gzgeti())) damageblend(bdamage); - if((ddamage = gzgeti())) { gzgetv(dorig); particle_splash(3, ddamage, 1000, dorig); }; + 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.empty() || playerhistory.last()->lastupdate!=playbacktime)) @@ -288,11 +288,11 @@ void demoplaybackstep() { zapplayer(playerhistory[0]); playerhistory.remove(0); - }; - }; + } + } readdemotime(); - }; + } if(demoplayback) { @@ -318,16 +318,16 @@ void demoplaybackstep() { catmulrom(z->o, a->o, b->o, c->o, bf, player1->o); catmulrom(*(vec *)&z->yaw, *(vec *)&a->yaw, *(vec *)&b->yaw, *(vec *)&c->yaw, bf, *(vec *)&player1->yaw); - }; + } fixcamerarange(player1); - }; + } break; - }; + } //if(player1->state!=CS_DEAD) showscores(false); - }; -}; + } +} -void stopn() { if(demoplayback) stopreset(); else stop(); conoutf("demo stopped"); }; +void stopn() { if(demoplayback) stopreset(); else stop(); conoutf("demo stopped"); } COMMAND(record, ARG_1STR); diff --git a/source/src/server.cpp b/source/src/server.cpp index 0e50dddb..ba6d32a3 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -18,8 +18,8 @@ struct clientscore void reset() { frags = flags = 0; - }; -}; + } +}; struct savedscore : clientscore { @@ -51,7 +51,7 @@ struct client // server side version of "dynent" type position.setsizenodelete(0); messages.setsizenodelete(0); ismaster = isauthed = false; - }; + } }; vector clients; @@ -76,10 +76,10 @@ void cleanworldstate(ENetPacket *packet) { delete ws; worldstates.remove(i); - }; + } break; - }; -}; + } +} int bsend = 0, brec = 0, laststatus = 0, lastsec = 0; @@ -92,13 +92,13 @@ void sendpacket(int n, int chan, ENetPacket *packet) enet_peer_send(clients[n]->peer, chan, packet); bsend += (int)packet->dataLength; break; - }; + } case ST_LOCAL: localservertoclient(chan, packet->data, (int)packet->dataLength); break; - }; -}; + } +} static bool reliablemessages = false; @@ -115,7 +115,7 @@ bool buildworldstate() { pkt[i].posoff = ws.positions.length(); loopvj(c.position) ws.positions.add(c.position[j]); - }; + } if(c.messages.empty()) pkt[i].msgoff = -1; else { @@ -127,11 +127,11 @@ bool buildworldstate() ws.messages.addbuf(p); loopvj(c.messages) ws.messages.add(c.messages[j]); pkt[i].msglen = ws.messages.length()-pkt[i].msgoff; - }; - }; + } + } int psize = ws.positions.length(), msize = ws.messages.length(); - loopi(psize) { uchar c = ws.positions[i]; ws.positions.add(c); }; - loopi(msize) { uchar c = ws.messages[i]; ws.messages.add(c); }; + loopi(psize) { uchar c = ws.positions[i]; ws.positions.add(c); } + loopi(msize) { uchar c = ws.messages[i]; ws.messages.add(c); } ws.uses = 0; loopv(clients) { @@ -145,8 +145,8 @@ bool buildworldstate() ENET_PACKET_FLAG_NO_ALLOCATE); sendpacket(c.clientnum, 0, packet); if(!packet->referenceCount) enet_packet_destroy(packet); - else { ++ws.uses; packet->freeCallback = cleanworldstate; }; - }; + else { ++ws.uses; packet->freeCallback = cleanworldstate; } + } c.position.setsizenodelete(0); if(msize && (pkt[i].msgoff<0 || msize-pkt[i].msglen>0)) @@ -156,10 +156,10 @@ bool buildworldstate() (reliablemessages ? ENET_PACKET_FLAG_RELIABLE : 0) | ENET_PACKET_FLAG_NO_ALLOCATE); sendpacket(c.clientnum, 1, packet); if(!packet->referenceCount) enet_packet_destroy(packet); - else { ++ws.uses; packet->freeCallback = cleanworldstate; }; - }; + else { ++ws.uses; packet->freeCallback = cleanworldstate; } + } c.messages.setsizenodelete(0); - }; + } reliablemessages = false; if(!ws.uses) { @@ -170,8 +170,8 @@ bool buildworldstate() { worldstates.add(&ws); return true; - }; -}; + } +} int maxclients = DEFAULTCLIENTS; string smapname; @@ -183,14 +183,14 @@ int numclients() int num = 0; loopv(clients) if(clients[i]->type!=ST_EMPTY) num++; return num; -}; +} void zapclient(int c) { if(!clients.inrange(c)) return; clients[c]->type = ST_EMPTY; clients[c]->ismaster = clients[c]->isauthed = false; -}; +} int freeteam() { @@ -198,7 +198,7 @@ int freeteam() loopv(clients) if(clients[i]->type!=ST_EMPTY) teamsize[team_int(clients[i]->team)]++; if(teamsize[0] == teamsize[1]) return rnd(2); return teamsize[0] < teamsize[1] ? 0 : 1; -}; +} clientscore *findscore(client &c, bool insert) { @@ -208,28 +208,28 @@ clientscore *findscore(client &c, bool insert) client &o = *clients[i]; if(o.type!=ST_TCPIP) continue; if(o.clientnum!=c.clientnum && o.peer->address.host==c.peer->address.host && !strcmp(o.name, c.name)) return &o.score; - }; + } loopv(scores) { savedscore &sc = scores[i]; if(!strcmp(sc.name, c.name) && sc.ip==c.peer->address.host) return ≻ - }; + } if(!insert) return NULL; savedscore &sc = scores.add(); sc.reset(); s_strcpy(sc.name, c.name); sc.ip = c.peer->address.host; return ≻ -}; +} void resetscores() { loopv(clients) if(clients[i]->type==ST_TCPIP) { clients[i]->score.reset(); - }; + } scores.setsize(0); -}; +} vector sents; @@ -245,8 +245,8 @@ void restoreserverstate(vector &ents) // hack: called from savegame co { sents[i].spawned = ents[i].spawned; sents[i].spawnsecs = 0; - }; -}; + } +} int interm = 0, minremain = 0, mapend = 0; bool mapreload = false, autoteam = true; @@ -262,7 +262,7 @@ void multicast(ENetPacket *packet, int sender, int chan); void sendf(int cn, int chan, const char *format, ...) { bool reliable = false; - if(*format=='r') { reliable = true; ++format; }; + if(*format=='r') { reliable = true; ++format; } ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, reliable ? ENET_PACKET_FLAG_RELIABLE : 0); ucharbuf p(packet->data, packet->dataLength); va_list args; @@ -274,20 +274,20 @@ void sendf(int cn, int chan, const char *format, ...) int n = isdigit(*format) ? *format++-'0' : 1; loopi(n) putint(p, va_arg(args, int)); break; - }; + } case 's': sendstring(va_arg(args, const char *), p); break; - }; + } va_end(args); enet_packet_resize(packet, p.length()); if(cn<0) multicast(packet, -1, chan); else sendpacket(cn, chan, packet); if(packet->referenceCount==0) enet_packet_destroy(packet); -}; +} void sendservmsg(char *msg, int client=-1) { sendf(client, 1, "ris", SV_SERVMSG, msg); -}; +} struct sflaginfo { @@ -312,7 +312,7 @@ void sendflaginfo(int flag, int action, int cn = -1) if(cn<0) multicast(packet, -1, 1); else sendpacket(cn, 1, packet); if(packet->referenceCount==0) enet_packet_destroy(packet); -}; +} void flagaction(int flag, int action, int sender) { @@ -327,39 +327,39 @@ void flagaction(int flag, int action, int sender) f.state = CTFF_STOLEN; f.actor_cn = sender; break; - }; + } case SV_FLAGDROP: { if(f.state!=CTFF_STOLEN || (sender != -1 && f.actor_cn != sender)) return; f.state = CTFF_DROPPED; loopi(3) f.pos[i] = clients[sender]->pos[i]; break; - }; + } case SV_FLAGRETURN: { if(f.state!=CTFF_DROPPED) return; f.state = CTFF_INBASE; f.actor_cn = sender; break; - }; + } case SV_FLAGRESET: { if(sender != -1 && f.actor_cn != sender) return; f.state = CTFF_INBASE; break; - }; + } case SV_FLAGSCORE: { if(f.state != CTFF_STOLEN) return; f.state = CTFF_INBASE; break; - }; + } default: return; - }; + } f.lastupdate = lastsec; sendflaginfo(flag, action); -}; +} void ctfreset() { @@ -368,8 +368,8 @@ void ctfreset() sflaginfos[i].actor_cn = 0; sflaginfos[i].state = CTFF_INBASE; sflaginfos[i].lastupdate = -1; - }; -}; + } +} char *disc_reasons[] = { "normal", "end of packet", "client num", "kicked by master", "banned by master", "tag type", "connection refused due to ban", "wrong password", "failed master login", "server FULL - maxclients", "server mastermode is \"private\"" }; @@ -386,9 +386,9 @@ void disconnect_client(int n, int reason = -1) if(reason>=0) enet_peer_disconnect(c.peer, reason); zapclient(n); sendf(-1, 1, "rii", SV_CDIS, n); -}; +} -void resetitems() { sents.setsize(0); notgotitems = true; }; +void resetitems() { sents.setsize(0); notgotitems = true; } bool serverpickup(uint i, int sec, int sender) // server side item pickup, acknowledge first client that gets it { @@ -399,9 +399,9 @@ bool serverpickup(uint i, int sec, int sender) // server side item picku sents[i].spawnsecs = sec; if(sender>=0) sendf(sender, 1, "rii", SV_ITEMACC, i); return true; - }; + } return false; -}; +} struct configset { @@ -437,11 +437,11 @@ void readscfg(char *cfg) s_strncpy(line, l, len+1); char *d = line; int n = 0; - while((p = strstr(d, ":")) != NULL) { d = p+1; n++; }; + while((p = strstr(d, ":")) != NULL) { d = p+1; n++; } if(n!=3) memset(l, ' ', len+1); - if(lastline) { l[len+1] = 0; break; }; + if(lastline) { l[len+1] = 0; break; } l += len+1; - }; + } configset c; int argc = 0; @@ -454,22 +454,22 @@ void readscfg(char *cfg) if(++argc==4) { int numspaces; - for(numspaces = 0; argv[0][numspaces]==' '; numspaces++){}; // ingore space crap + for(numspaces = 0; argv[0][numspaces]==' '; numspaces++){} // ingore space crap strcpy(c.mapname, argv[0]+numspaces); c.mode = atoi(argv[1]); c.time = atoi(argv[2]); c.vote = atoi(argv[3]) > 0; configsets.add(c); argc = 0; - }; + } p = strtok(NULL, ":\n\0"); - }; -}; + } +} void resetvotes() { loopv(clients) clients[i]->mapvote[0] = 0; -}; +} void shuffleteams() { @@ -481,8 +481,8 @@ void shuffleteams() if(teamsize[team] > numplayers/2) team = team_opposite(team); sendf(i, 1, "rii", SV_FORCETEAM, team); teamsize[team]++; - }; -}; + } +} void resetmap(const char *newname, int newmode, int newtime = -1, bool notify = true) { @@ -501,7 +501,7 @@ void resetmap(const char *newname, int newmode, int newtime = -1, bool notify = ctfreset(); if(notify) sendf(-1, 1, "risi", SV_MAPCHANGE, smapname, smode); if(m_teammode && !lastteammode) shuffleteams(); -}; +} void nextcfgset(bool notify = true) // load next maprotation set { @@ -510,7 +510,7 @@ void nextcfgset(bool notify = true) // load next maprotation set configset &c = configsets[curcfgset]; resetmap(c.mapname, c.mode, c.time, notify); -}; +} bool vote(char *map, int reqmode, int sender) { @@ -521,7 +521,7 @@ bool vote(char *map, int reqmode, int sender) s_sprintfd(msg)("%s voted, but voting is currently disabled", clients[sender]->name); sendservmsg(msg); return false; - }; + } s_strcpy(clients[sender]->mapvote, map); clients[sender]->modevote = reqmode; @@ -530,7 +530,7 @@ bool vote(char *map, int reqmode, int sender) { if(clients[i]->mapvote[0]) { if(strcmp(clients[i]->mapvote, map)==0 && clients[i]->modevote==reqmode) yes++; else no++; } else no++; - }; + } if(yes==1 && no==0) return true; // single player s_sprintfd(msg)("%s suggests mode \"%s\" on map %s (set map to vote)", clients[sender]->name, modestr(reqmode), map); sendservmsg(msg); @@ -538,7 +538,7 @@ bool vote(char *map, int reqmode, int sender) sendservmsg("vote passed"); resetvotes(); return true; -}; +} struct ban { @@ -555,22 +555,22 @@ bool isbanned(int cn) loopv(bans) { ban &b = bans[i]; - if(b.secs < lastsec) { bans.remove(i--); }; - if(b.address.host == c.peer->address.host) { return true; }; - }; + if(b.secs < lastsec) { bans.remove(i--); } + if(b.address.host == c.peer->address.host) { return true; } + } return false; -}; +} int master() { loopv(clients) if(clients[i]->type!=ST_EMPTY && clients[i]->ismaster) return i; return -1; -}; +} void sendmasterinfo(int receiver) { sendf(receiver, 1, "rii", SV_MASTERINFO, master()); -}; +} void setmaster(int client, bool claim, char *pwd = NULL) { @@ -586,8 +586,8 @@ void setmaster(int client, bool claim, char *pwd = NULL) else if(pwd && pwd[0]) { disconnect_client(client, DISC_MLOGINFAIL); // avoid brute-force - }; -}; + } +} void mastercmd(int sender, int cmd, int a) { @@ -599,7 +599,7 @@ void mastercmd(int sender, int cmd, int a) if(!valid_client(a)) return; disconnect_client(a, DISC_MKICK); break; - }; + } case MCMD_BAN: { if(!valid_client(a)) return; @@ -607,27 +607,27 @@ void mastercmd(int sender, int cmd, int a) bans.add(b); disconnect_client(a, DISC_MBAN); break; - }; + } case MCMD_REMBANS: { if(bans.length()) bans.setsize(0); break; - }; + } case MCMD_MASTERMODE: { if(a < 0 || a >= MM_NUM) return; mastermode = a; break; - }; + } case MCMD_AUTOTEAM: { if(a < 0 || a > 1) return; if((autoteam = a == 1) == true && m_teammode) shuffleteams(); break; - }; - }; + } + } sendf(-1, 1, "riii", SV_MASTERCMD, cmd, a); -}; +} int checktype(int type, client *cl) { @@ -639,7 +639,7 @@ int checktype(int type, client *cl) static int servtypes[] = { SV_INITS2C, SV_MAPRELOAD, SV_SERVMSG, SV_ITEMACC, SV_ITEMSPAWN, SV_TIMEUP, SV_CDIS, SV_PONG, SV_RESUME, SV_FLAGINFO, SV_CLIENT }; if(cl) loopi(sizeof(servtypes)/sizeof(int)) if(type == servtypes[i]) return -1; return type; -}; +} // server side processing of updates: does very little and most state is tracked client only // could be extended to move more gameplay to server (at expense of lag) @@ -661,9 +661,9 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 getstring(text, p); if(!strcmp(text, serverpassword)) cl->isauthed = true; else disconnect_client(sender, DISC_WRONGPW); - }; + } if(!cl->isauthed) return; - }; + } if(packet->flags&ENET_PACKET_FLAG_RELIABLE) reliablemessages = true; @@ -694,15 +694,15 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 { cl->score = *sc; sendf(-1, 1, "ri4", SV_RESUME, sender, sc->frags, sc->flags); - }; - }; + } + } getstring(text, p); s_strncpy(cl->team, text, MAXTEAMLEN+1); getint(p); getint(p); QUEUE_MSG; break; - }; + } case SV_MAPCHANGE: { @@ -712,7 +712,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 if(smapname[0] && !mapreload && !vote(text, reqmode, sender)) return; resetmap(text, reqmode); break; - }; + } case SV_ITEMLIST: { @@ -722,11 +722,11 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 server_entity se = { false, 0 }; while(sents.length()<=n) sents.add(se); sents[n].spawned = true; - }; + } notgotitems = false; QUEUE_MSG; break; - }; + } case SV_ITEMPICKUP: { @@ -734,7 +734,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 serverpickup(n, getint(p), sender); QUEUE_MSG; break; - }; + } case SV_PING: sendf(sender, 1, "ii", SV_PONG, getint(p)); @@ -750,7 +750,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 conoutf("ERROR: invalid client (msg %i)", type); #endif return; - }; + } loopi(3) clients[cn]->pos[i] = getuint(p); getuint(p); loopi(6) getint(p); @@ -758,9 +758,9 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 { cl->position.setsizenodelete(0); while(curmsgposition.add(p.buf[curmsg++]); - }; + } break; - }; + } case SV_SENDMAP: { @@ -770,11 +770,11 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 { p.forceoverread(); break; - }; + } sendmaps(sender, text, mapsize, &p.buf[p.len]); p.len += mapsize; break; - }; + } case SV_RECVMAP: { @@ -782,7 +782,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 if(mappacket) sendpacket(sender, 2, mappacket); else sendservmsg("no map to get", sender); break; - }; + } case SV_FLAGPICKUP: case SV_FLAGDROP: @@ -792,13 +792,13 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 { flagaction(getint(p), type, sender); break; - }; + } case SV_SETMASTER: { setmaster(sender, getint(p) != 0); break; - }; + } case SV_SETMASTERLOGIN: { @@ -806,7 +806,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 getstring(text, p); setmaster(sender, claim, text); break; - }; + } case SV_MASTERCMD: { @@ -814,7 +814,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 int arg = getint(p); mastercmd(sender, cmd, arg); break; - }; + } case SV_FRAGS: cl->score.frags = getint(p); @@ -829,15 +829,15 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 default: { int size = msgsizelookup(type); - if(size==-1) { if(sender>=0) disconnect_client(sender, DISC_TAGT); return; }; + if(size==-1) { if(sender>=0) disconnect_client(sender, DISC_TAGT); return; } loopi(size-1) getint(p); QUEUE_MSG; break; - }; - }; + } + } if(p.overread() && sender>=0) disconnect_client(sender, DISC_EOP); -}; +} void send_welcome(int n) { @@ -860,8 +860,8 @@ void send_welcome(int n) putint(p, SV_ITEMLIST); loopv(sents) if(sents[i].spawned) putint(p, i); putint(p, -1); - }; - }; + } + } if(clients[n]->type == ST_TCPIP && master() != -1) sendmasterinfo(n); loopv(clients) { @@ -872,19 +872,19 @@ void send_welcome(int n) putint(p, c.clientnum); putint(p, c.score.frags); putint(p, c.score.flags); - }; + } if(autoteam) { putint(p, SV_FORCETEAM); putint(p, freeteam()); - }; + } putint(p, SV_MASTERCMD); putint(p, MCMD_AUTOTEAM); putint(p, autoteam); enet_packet_resize(packet, p.length()); sendpacket(n, 1, packet); if(smapname[0] && m_ctf) loopi(2) sendflaginfo(i, -1, n); -}; +} void multicast(ENetPacket *packet, int sender, int chan) { @@ -892,28 +892,28 @@ void multicast(ENetPacket *packet, int sender, int chan) { if(i==sender) continue; sendpacket(i, chan, packet); - }; -}; + } +} void localclienttoserver(int chan, ENetPacket *packet) { process(packet, 0, chan); if(!packet->referenceCount) enet_packet_destroy(packet); -}; +} client &addclient() { client *c = NULL; - loopv(clients) if(clients[i]->type==ST_EMPTY) { c = clients[i]; break; }; + loopv(clients) if(clients[i]->type==ST_EMPTY) { c = clients[i]; break; } if(!c) { c = new client; c->clientnum = clients.length(); clients.add(c); - }; + } c->reset(); return *c; -}; +} void checkintermission() { @@ -921,11 +921,11 @@ void checkintermission() { interm = lastsec+10; mapend = lastsec+1000; - }; + } sendf(-1, 1, "rii", SV_TIMEUP, minremain--); -}; +} -/*void startintermission() { minremain = 0; checkintermission(); };*/ +/*void startintermission() { minremain = 0; checkintermission(); }*/ void resetserverifempty() { @@ -934,14 +934,14 @@ void resetserverifempty() resetmap("", 0, 10, false); mastermode = MM_OPEN; autoteam = true; -}; +} int refuseconnect(int i) { if(mastermode == MM_PRIVATE) return DISC_MASTERMODE; if(valid_client(i) && isbanned(i)) return DISC_BANREFUSE; return DISC_NONE; -}; +} void sendworldstate() { @@ -952,7 +952,7 @@ void sendworldstate() bool flush = buildworldstate(); lastsend += curtime - (curtime%40); if(flush) enet_host_flush(serverhost); -}; +} void serverslice(int seconds, unsigned int timeout) // main server update, called from cube main loop in sp, or dedicated server loop { @@ -963,14 +963,14 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal sents[i].spawnsecs = 0; sents[i].spawned = true; sendf(-1, 1, "rii", SV_ITEMSPAWN, i); - }; - }; + } + } if(m_ctf) loopi(2) { sflaginfo &f = sflaginfos[i]; if(f.state==CTFF_DROPPED && seconds-f.lastupdate>30) flagaction(i, SV_FLAGRESET, -1); - }; + } lastsec = seconds; @@ -988,8 +988,8 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal sendf(i, 1, "rii", SV_MAPRELOAD, 0); // ask a client to trigger map reload mapreload = true; break; - }; - }; + } + } resetserverifempty(); @@ -1009,7 +1009,7 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal #endif } bsend = brec = 0; - }; + } ENetEvent event; if(enet_host_service(serverhost, &event, timeout) > 0) @@ -1029,7 +1029,7 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal if(nonlocalclientsreferenceCount==0) enet_packet_destroy(event.packet); break; - }; + } case ENET_EVENT_TYPE_DISCONNECT: { @@ -1046,24 +1046,24 @@ void serverslice(int seconds, unsigned int timeout) // main server update, cal if(!valid_client(cn)) break; disconnect_client(cn); break; - }; + } default: break; - }; - }; + } + } sendworldstate(); -}; +} void cleanupserver() { if(serverhost) enet_host_destroy(serverhost); -}; +} void localdisconnect() { loopv(clients) if(clients[i]->type==ST_LOCAL) zapclient(i); -}; +} void localconnect() { @@ -1071,7 +1071,7 @@ void localconnect() c.type = ST_LOCAL; s_strcpy(c.hostname, "local"); send_welcome(c.clientnum); -}; +} void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, char *passwd, int maxcl, char *maprot, char *masterpwd) // EDIT: AH { @@ -1089,7 +1089,7 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, if(!maprot || !maprot[0]) maprot = newstring("config/maprot.cfg"); readscfg(path(maprot)); if(masterpwd && masterpwd[0]) masterpasswd = masterpwd; - }; + } resetserverifempty(); @@ -1102,5 +1102,5 @@ void initserver(bool dedicated, int uprate, char *sdesc, char *ip, char *master, atexit(cleanupserver); atexit(enet_deinitialize); for(;;) serverslice(/*enet_time_get_sec()*/time(NULL), 5); - }; -}; + } +} diff --git a/source/src/serverbrowser.cpp b/source/src/serverbrowser.cpp index d05254f0..0d1bf7cf 100644 --- a/source/src/serverbrowser.cpp +++ b/source/src/serverbrowser.cpp @@ -17,7 +17,7 @@ struct resolverresult { const char *query; ENetAddress address; -}; +}; vector resolverthreads; vector resolverqueries; @@ -56,11 +56,11 @@ int resolverloop(void * data) rt->query = NULL; rt->starttime = 0; SDL_CondSignal(resultcond); - }; + } SDL_UnlockMutex(resolvermutex); - }; + } return 0; -}; +} void resolverinit() { @@ -75,9 +75,9 @@ void resolverinit() rt.query = NULL; rt.starttime = 0; rt.thread = SDL_CreateThread(resolverloop, &rt); - }; + } SDL_UnlockMutex(resolvermutex); -}; +} void resolverstop(resolverthread &rt) { @@ -88,11 +88,11 @@ void resolverstop(resolverthread &rt) SDL_KillThread(rt.thread); #endif rt.thread = SDL_CreateThread(resolverloop, &rt); - }; + } rt.query = NULL; rt.starttime = 0; SDL_UnlockMutex(resolvermutex); -}; +} void resolverclear() { @@ -105,9 +105,9 @@ void resolverclear() { resolverthread &rt = resolverthreads[i]; resolverstop(rt); - }; + } SDL_UnlockMutex(resolvermutex); -}; +} void resolverquery(const char *name) { @@ -117,7 +117,7 @@ void resolverquery(const char *name) resolverqueries.add(name); SDL_CondSignal(querycond); SDL_UnlockMutex(resolvermutex); -}; +} bool resolvercheck(const char **name, ENetAddress *address) { @@ -138,11 +138,11 @@ bool resolvercheck(const char **name, ENetAddress *address) resolverstop(rt); *name = rt.query; resolved = true; - }; - }; + } + } SDL_UnlockMutex(resolvermutex); return resolved; -}; +} bool resolverwait(const char *name, ENetAddress *address) { @@ -165,7 +165,7 @@ bool resolverwait(const char *name, ENetAddress *address) resolverresults.remove(i); resolved = true; break; - }; + } if(resolved) break; timeout = SDL_GetTicks() - starttime; @@ -174,21 +174,21 @@ bool resolverwait(const char *name, ENetAddress *address) while(SDL_PollEvent(&event)) { if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) timeout = RESOLVERLIMIT + 1; - }; + } if(timeout > RESOLVERLIMIT) break; - }; + } if(!resolved && timeout > RESOLVERLIMIT) { loopv(resolverthreads) { resolverthread &rt = resolverthreads[i]; - if(rt.query == name) { resolverstop(rt); break; }; - }; - }; + if(rt.query == name) { resolverstop(rt); break; } + } + } SDL_UnlockMutex(resolvermutex); return resolved; -}; +} struct serverinfo { @@ -207,7 +207,7 @@ vector servers; ENetSocket pingsock = ENET_SOCKET_NULL; int lastinfo = 0; -char *getservername(int n) { return servers[n].name; }; +char *getservername(int n) { return servers[n].name; } void addserver(char *servername) { @@ -226,7 +226,7 @@ void addserver(char *servername) si.resolved = UNRESOLVED; si.address.host = ENET_HOST_ANY; si.address.port = CUBE_SERVINFO_PORT; -}; +} void pingservers() { @@ -241,9 +241,9 @@ void pingservers() buf.data = ping; buf.dataLength = p.length(); enet_socket_send(pingsock, &si.address, &buf, 1); - }; + } lastinfo = lastmillis; -}; +} void checkresolver() { @@ -254,10 +254,10 @@ void checkresolver() if(si.resolved == RESOLVED) continue; if(si.address.host == ENET_HOST_ANY) { - if(si.resolved == UNRESOLVED) { si.resolved = RESOLVING; resolverquery(si.name); }; + if(si.resolved == UNRESOLVED) { si.resolved = RESOLVING; resolverquery(si.name); } resolving++; - }; - }; + } + } if(!resolving) return; const char *name = NULL; @@ -309,15 +309,15 @@ void checkpings() s_strcpy(si.sdesc, text); si.maxclients = getint(p); break; - }; - }; - }; -}; + } + } + } +} int sicompare(const serverinfo *a, const serverinfo *b) { return a->ping>b->ping ? 1 : (a->pingping ? -1 : strcmp(a->name, b->name)); -}; +} void *servmenu = NULL; @@ -344,8 +344,8 @@ void refreshservers() s_sprintf(si.cmd)("connect %s", si.name); menumanual(servmenu, i, si.full, si.cmd); if(!--maxmenu) return; - }; -}; + } +} void servermenu() { @@ -353,12 +353,12 @@ void servermenu() { pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL); resolverinit(); - }; + } resolverclear(); loopv(servers) resolverquery(servers[i].name); refreshservers(); menuset(servmenu); -}; +} void updatefrommaster() { @@ -371,9 +371,9 @@ void updatefrommaster() loopv(servers) delete[] servers[i].name; servers.setsize(0); execute((char *)reply); - }; + } servermenu(); -}; +} COMMAND(addserver, ARG_1STR); COMMAND(servermenu, ARG_NONE); @@ -386,4 +386,4 @@ void writeservercfg() fprintf(f, "// servers connected to are added here automatically\n\n"); loopvrev(servers) fprintf(f, "addserver %s\n", servers[i].name); fclose(f); -}; +} diff --git a/source/src/serverms.cpp b/source/src/serverms.cpp index 8e2aada0..860a4a90 100644 --- a/source/src/serverms.cpp +++ b/source/src/serverms.cpp @@ -6,7 +6,7 @@ bool resolverwait(const char *name, ENetAddress *address) { return enet_address_set_host(address, name) >= 0; -}; +} #endif ENetSocket mssock = ENET_SOCKET_NULL; @@ -17,28 +17,28 @@ void httpgetsend(ENetAddress &ad, char *hostname, char *req, char *ref, char *ag { enet_socket_destroy(mssock); mssock = ENET_SOCKET_NULL; - }; + } if(ad.host==ENET_HOST_ANY) { printf("looking up %s...\n", hostname); if(!resolverwait(hostname, &ad)) return; - }; + } mssock = enet_socket_create(ENET_SOCKET_TYPE_STREAM, NULL); - if(mssock==ENET_SOCKET_NULL) { printf("could not open socket\n"); return; }; + if(mssock==ENET_SOCKET_NULL) { printf("could not open socket\n"); return; } if(enet_socket_connect(mssock, &ad)<0) { printf("could not connect\n"); enet_socket_destroy(mssock); mssock = ENET_SOCKET_NULL; return; - }; + } ENetBuffer buf; s_sprintfd(httpget)("GET %s HTTP/1.0\nHost: %s\nReferer: %s\nUser-Agent: %s\n\n", req, hostname, ref, agent); buf.data = httpget; buf.dataLength = strlen((char *)buf.data); printf("sending request to %s...\n", hostname); enet_socket_send(mssock, NULL, &buf, 1); -}; +} void httpgetrecieve(ENetBuffer &buf) { @@ -52,19 +52,19 @@ void httpgetrecieve(ENetBuffer &buf) enet_socket_destroy(mssock); mssock = ENET_SOCKET_NULL; return; - }; + } buf.data = ((char *)buf.data)+len; ((char*)buf.data)[0] = 0; buf.dataLength -= len; - }; -}; + } +} uchar *stripheader(uchar *b) { char *s = strstr((char *)b, "\n\r\n"); if(!s) s = strstr((char *)b, "\n\n"); return s ? (uchar *)s : b; -}; +} ENetAddress masterserver = { ENET_HOST_ANY, 80 }; int updmaster = 0; @@ -83,15 +83,15 @@ void updatemasterserver(int seconds) masterb.data = masterrep; masterb.dataLength = MAXTRANS-1; updmaster = seconds+60*60; - }; -}; + } +} void checkmasterreply() { bool busy = mssock!=ENET_SOCKET_NULL; httpgetrecieve(masterb); if(busy && mssock==ENET_SOCKET_NULL) printf("masterserver reply: %s\n", stripheader(masterrep)); -}; +} uchar *retrieveservers(uchar *buf, int buflen) { @@ -103,7 +103,7 @@ uchar *retrieveservers(uchar *buf, int buflen) eb.dataLength = buflen-1; while(mssock!=ENET_SOCKET_NULL) httpgetrecieve(eb); return stripheader(buf); -}; +} ENetSocket pongsock = ENET_SOCKET_NULL; string serverdesc; @@ -135,8 +135,8 @@ void serverms(int mode, int numplayers, int minremain, char *smapname, int secon putint(p, maxclients); buf.dataLength = len + p.length(); enet_socket_send(pongsock, &addr, &buf, 1); - }; -}; + } +} void servermsinit(const char *master, char *sdesc, bool listen) { @@ -151,5 +151,5 @@ void servermsinit(const char *master, char *sdesc, bool listen) ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT }; pongsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, &address); if(pongsock == ENET_SOCKET_NULL) fatal("could not create server info socket\n"); - }; -}; + } +} diff --git a/source/src/serverutil.cpp b/source/src/serverutil.cpp index 85d1e643..3d9776b8 100644 --- a/source/src/serverutil.cpp +++ b/source/src/serverutil.cpp @@ -8,8 +8,8 @@ void putint(ucharbuf &p, int n) { if(n<128 && n>-127) p.put(n); else if(n<0x8000 && n>=-0x8000) { p.put(0x80); p.put(n); p.put(n>>8); } - else { p.put(0x81); p.put(n); p.put(n>>8); p.put(n>>16); p.put(n>>24); }; -}; + else { p.put(0x81); p.put(n); p.put(n>>8); p.put(n>>16); p.put(n>>24); } +} int getint(ucharbuf &p) { @@ -17,7 +17,7 @@ int getint(ucharbuf &p) if(c==-128) { int n = p.get(); n |= char(p.get())<<8; return n; } else if(c==-127) { int n = p.get(); n |= p.get()<<8; n |= p.get()<<16; return n|(p.get()<<24); } else return c; -}; +} // much smaller encoding for unsigned integers up to 28 bits, but can handle signed void putuint(ucharbuf &p, int n) @@ -40,8 +40,8 @@ void putuint(ucharbuf &p, int n) p.put(0x80 | (n & 0x7F)); p.put(0x80 | ((n >> 7) & 0x7F)); p.put(n >> 14); - }; -}; + } +} int getuint(ucharbuf &p) { @@ -52,27 +52,27 @@ int getuint(ucharbuf &p) if(n & (1<<14)) n += (p.get() << 14) - (1<<14); if(n & (1<<21)) n += (p.get() << 21) - (1<<21); if(n & (1<<28)) n |= 0xF0000000; - }; + } return n; -}; +} void sendstring(const char *t, ucharbuf &p) { while(*t) putint(p, *t++); putint(p, 0); -}; +} void getstring(char *text, ucharbuf &p, int len) { char *t = text; do { - if(t>=&text[len]) { text[len-1] = 0; return; }; - if(!p.remaining()) { *t = 0; return; }; + if(t>=&text[len]) { text[len-1] = 0; return; } + if(!p.remaining()) { *t = 0; return; } *t = getint(p); } while(*t++); -}; +} const char *modenames[] = { @@ -81,7 +81,7 @@ const char *modenames[] = "one shot, one kill", "team one shot, one kill", "bot one shot, one skill" }; -const char *modestr(int n) { return (n>=0 && (size_t)n < sizeof(modenames)/sizeof(modenames[0])) ? modenames[n] : "unknown"; }; +const char *modestr(int n) { return (n>=0 && (size_t)n < sizeof(modenames)/sizeof(modenames[0])) ? modenames[n] : "unknown"; } char msgsizesl[] = // size inclusive message token, 0 for variable or not-checked sizes { @@ -105,7 +105,7 @@ char msgsizelookup(int msg) { for(char *p = msgsizesl; *p>=0; p += 2) if(*p==msg) return p[1]; return -1; -}; +} // sending of maps between clients @@ -138,8 +138,8 @@ ENetPacket *recvmap(int n) #ifdef STANDALONE -void localservertoclient(int chan, uchar *buf, int len) {}; -void fatal(char *s, char *o) { cleanupserver(); printf("fatal: %s\n", s); exit(EXIT_FAILURE); }; +void localservertoclient(int chan, uchar *buf, int len) {} +void fatal(char *s, char *o) { cleanupserver(); printf("fatal: %s\n", s); exit(EXIT_FAILURE); } int main(int argc, char **argv) // EDIT: AH { @@ -160,13 +160,13 @@ int main(int argc, char **argv) // EDIT: AH case 'r': maprot = a; break; case 'x' : masterpwd = a; break; // EDIT: AH default: printf("WARNING: unknown commandline option\n"); - }; - }; + } + } if(enet_initialize()<0) fatal("Unable to initialise network module"); initserver(true, uprate, sdesc, ip, master, passwd, maxcl, maprot, masterpwd); return EXIT_SUCCESS; -}; +} #endif diff --git a/source/src/sound.cpp b/source/src/sound.cpp index cb78703b..486f2f2d 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -56,15 +56,15 @@ void stopsound() FMUSIC_FreeSong(mod); #endif mod = NULL; - }; + } if(stream) { #ifndef USE_MIXER FSOUND_Stream_Close(stream); #endif stream = NULL; - }; -}; + } +} VAR(soundbufferlen, 128, 1024, 4096); @@ -76,7 +76,7 @@ void initsound() { conoutf("sound init failed (SDL_mixer): %s", (size_t)Mix_GetError()); return; - }; + } Mix_AllocateChannels(MAXCHAN); #else if(FSOUND_GetVersion()=0) { FSOUND_SetVolume(chan, (musicvol*MAXVOL)/255); FSOUND_SetPaused(chan, false); }; + if(chan>=0) { FSOUND_SetVolume(chan, (musicvol*MAXVOL)/255); FSOUND_SetPaused(chan, false); } } #endif else { conoutf("could not play music: %s", sn); - }; + } - }; -}; + } +} COMMAND(music, ARG_1STR); @@ -139,7 +139,7 @@ int registersound(char *name) snames.add(newstring(name)); samples.add(NULL); return samples.length()-1; -}; +} COMMAND(registersound, ARG_1EST); @@ -152,7 +152,7 @@ void cleansound() #else FSOUND_Close(); #endif -}; +} VAR(stereo, 0, 1, 1); @@ -169,8 +169,8 @@ void updatechanvol(int chan, vec *loc) { float yaw = -atan2f(v.x, v.y) - camera1->yaw*RAD; // relative angle of sound along X-Y axis pan = int(255.9f*(0.5f*sinf(yaw)+0.5f)); // range is from 0 (left) to 255 (right) - }; - }; + } + } vol = (vol*MAXVOL)/255; #ifdef USE_MIXER Mix_Volume(chan, vol); @@ -179,14 +179,14 @@ void updatechanvol(int chan, vec *loc) FSOUND_SetVolume(chan, vol); FSOUND_SetPan(chan, pan); #endif -}; +} void newsoundloc(int chan, vec *loc) { ASSERT(chan>=0 && chan5) return; // avoid bursts of sounds with heavy packetloss and in sp - if(n<0 || n>=samples.length()) { conoutf("unregistered sound: %d", n); return; }; + if(n<0 || n>=samples.length()) { conoutf("unregistered sound: %d", n); return; } if(!samples[n]) { @@ -228,8 +228,8 @@ void playsound(int n, vec *loc) samples[n] = FSOUND_Sample_Load(n, path(buf), FSOUND_LOOP_OFF, 0, 0); #endif - if(!samples[n]) { conoutf("failed to load sample: %s", buf); return; }; - }; + if(!samples[n]) { conoutf("failed to load sample: %s", buf); return; } + } #ifdef USE_MIXER int chan = Mix_PlayChannel(-1, samples[n], 0); @@ -242,7 +242,7 @@ void playsound(int n, vec *loc) #ifndef USE_MIXER FSOUND_SetPaused(chan, false); #endif -}; +} -void sound(int n) { playsound(n, NULL); }; +void sound(int n) { playsound(n, NULL); } COMMAND(sound, ARG_1INT); diff --git a/source/src/tools.h b/source/src/tools.h index bb791c10..087a970a 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -14,12 +14,12 @@ typedef unsigned int uint; #ifdef _DEBUG #ifdef __GNUC__ -#define ASSERT(c) if(!(c)) { asm("int $3"); }; +#define ASSERT(c) if(!(c)) { asm("int $3"); } #else -#define ASSERT(c) if(!(c)) { __asm int 3 }; +#define ASSERT(c) if(!(c)) { __asm int 3 } #endif #else -#define ASSERT(c) if(c) {}; +#define ASSERT(c) if(c) {} #endif #define swap(t,a,b) { t m=a; a=b; b=m; } @@ -40,8 +40,8 @@ typedef unsigned int uint; #define loopl(m) loop(l,m) -#define DELETEP(p) if(p) { delete p; p = 0; }; -#define DELETEA(p) if(p) { delete[] p; p = 0; }; +#define DELETEP(p) if(p) { delete p; p = 0; } +#define DELETEA(p) if(p) { delete[] p; p = 0; } #define PI (3.1415927f) #define PI2 (2*PI) @@ -73,16 +73,16 @@ typedef unsigned int uint; #define _MAXDEFSTR 260 typedef char string[_MAXDEFSTR]; -inline void formatstring(char *d, const char *fmt, va_list v) { _vsnprintf(d, _MAXDEFSTR, fmt, v); d[_MAXDEFSTR-1] = 0; }; -inline char *s_strncpy(char *d, const char *s, size_t m) { strncpy(d,s,m); d[m-1] = 0; return d; }; -inline char *s_strcpy(char *d, const char *s) { return s_strncpy(d,s,_MAXDEFSTR); }; -inline char *s_strcat(char *d, const char *s) { size_t n = strlen(d); return s_strncpy(d+n,s,_MAXDEFSTR-n); }; +inline void formatstring(char *d, const char *fmt, va_list v) { _vsnprintf(d, _MAXDEFSTR, fmt, v); d[_MAXDEFSTR-1] = 0; } +inline char *s_strncpy(char *d, const char *s, size_t m) { strncpy(d,s,m); d[m-1] = 0; return d; } +inline char *s_strcpy(char *d, const char *s) { return s_strncpy(d,s,_MAXDEFSTR); } +inline char *s_strcat(char *d, const char *s) { size_t n = strlen(d); return s_strncpy(d+n,s,_MAXDEFSTR-n); } struct s_sprintf_f { char *d; - s_sprintf_f(char *str): d(str) {}; + s_sprintf_f(char *str): d(str) {} void operator()(const char* fmt, ...) { va_list v; @@ -98,7 +98,7 @@ struct s_sprintf_f #define s_sprintfdv(d,fmt) s_sprintfdlv(d,fmt,fmt) -template void _swap(T &a, T &b) { T t = a; a = b; b = t; }; +template void _swap(T &a, T &b) { T t = a; a = b; b = t; } @@ -128,7 +128,7 @@ struct databuf uchar flags; template - databuf(T *buf, U maxlen) : buf(buf), len(0), maxlen((int)maxlen), flags(0) {}; + databuf(T *buf, U maxlen) : buf(buf), len(0), maxlen((int)maxlen), flags(0) {} const T &get() { @@ -136,38 +136,38 @@ struct databuf if(len charbuf; @@ -184,68 +184,68 @@ template struct vector alen = 8; buf = (T *)new uchar[alen*sizeof(T)]; ulen = 0; - }; + } vector(const vector &v) { alen = v.length(); buf = (T *)new uchar[alen*sizeof(T)]; ulen = 0; *this = v; - }; + } - ~vector() { setsize(0); delete[] (uchar *)buf; }; + ~vector() { setsize(0); delete[] (uchar *)buf; } vector &operator=(const vector &v) { setsize(0); loopv(v) add(v[i]); return *this; - }; + } T &add(const T &x) { if(ulen==alen) vrealloc(); new (&buf[ulen]) T(x); return buf[ulen++]; - }; + } T &add() { if(ulen==alen) vrealloc(); new (&buf[ulen]) T; return buf[ulen++]; - }; + } T &dup() { if(ulen==alen) vrealloc(); new (&buf[ulen]) T(buf[ulen-1]); return buf[ulen++]; - }; + } - bool inrange(size_t i) const { return i=0 && i=0 && i=0 && i= 0 && i=0 && i= 0 && ii) drop(); }; - void setsizenodelete(int i) { ASSERT(i<=ulen); ulen = i; }; + void setsize(int i) { ASSERT(i<=ulen); while(ulen>i) drop(); } + void setsizenodelete(int i) { ASSERT(i<=ulen); ulen = i; } - void deletecontentsp() { while(!empty()) delete pop(); }; - void deletecontentsa() { while(!empty()) delete[] pop(); }; + void deletecontentsp() { while(!empty()) delete pop(); } + void deletecontentsa() { while(!empty()) delete[] pop(); } - T *getbuf() { return buf; }; - const T *getbuf() const { return buf; }; + T *getbuf() { return buf; } + const T *getbuf() const { return buf; } template - void sort(int (__cdecl *cf)(ST *, ST *), int i = 0, int n = -1) { qsort(&buf[i], n<0?ulen:n, sizeof(T), (int (__cdecl *)(const void *,const void *))cf); }; + void sort(int (__cdecl *cf)(ST *, ST *), int i = 0, int n = -1) { qsort(&buf[i], n<0?ulen:n, sizeof(T), (int (__cdecl *)(const void *,const void *))cf); } void *_realloc(void *p, int oldsize, int newsize) { @@ -253,30 +253,30 @@ template struct vector memcpy(np, p, newsize>oldsize ? oldsize : newsize); delete[] (uchar *)p; return np; - }; + } void vrealloc() { int olen = alen; buf = (T *)_realloc(buf, olen*sizeof(T), (alen *= 2)*sizeof(T)); - }; + } databuf reserve(int sz) { while(alen-ulen(&buf[ulen], sz); - }; + } void addbuf(const databuf &p) { ulen += p.length(); - }; + } void remove(int i, int n) { for(int p = i+n; p struct vector for(int p = i+1; p struct vector void removeobj(const T &o) { loopi(ulen) if(buf[i]==o) remove(i--); - }; + } void replacewithlast(const T &o) { @@ -303,9 +303,9 @@ template struct vector loopi(ulen-1) if(buf[i]==o) { buf[i] = buf[ulen-1]; - }; + } ulen--; - }; + } T &insert(int i, const T &e) { @@ -313,7 +313,7 @@ template struct vector for(int p = ulen-1; p>i; p--) buf[p] = buf[p-1]; buf[i] = e; return buf[i]; - }; + } }; typedef vector cvector; @@ -325,32 +325,32 @@ static inline uint hthash(const char *key) uint h = 5381; for(int i = 0, k; (k = key[i]); i++) h = ((h<<5)+h)^k; // bernstein k=33 xor return h; -}; +} static inline bool htcmp(const char *x, const char *y) { return !strcmp(x, y); -}; +} static inline uint hthash(int key) { return key; -}; +} static inline bool htcmp(int x, int y) { return x==y; -}; +} static inline uint hthash(uint key) { return key; -}; +} static inline bool htcmp(uint x, uint y) { return x==y; -}; +} template struct hashtable { @@ -361,7 +361,7 @@ template struct hashtable enum { CHUNKSIZE = 16 }; - struct chain { T data; K key; chain *next; }; + struct chain { T data; K key; chain *next; }; struct chainchunk { chain chunks[CHUNKSIZE]; chainchunk *next; }; int size; @@ -380,12 +380,12 @@ template struct hashtable lastchunk = NULL; table = new chain *[size]; loopi(size) table[i] = NULL; - }; + } ~hashtable() { DELETEA(table); - }; + } chain *insert(const K &key, uint h) { @@ -402,7 +402,7 @@ template struct hashtable table[h] = c; numelems++; return c; - }; + } chain *find(const K &key, bool doinsert) { @@ -413,7 +413,7 @@ template struct hashtable } if(doinsert) return insert(key, h); return NULL; - }; + } T *access(const K &key, const T *data = NULL) { @@ -421,12 +421,12 @@ template struct hashtable if(data) c->data = *data; if(c) return &c->data; return NULL; - }; + } T &operator[](const K &key) { return find(key, true)->data; - }; + } void clear() { @@ -437,9 +437,9 @@ template struct hashtable { next = c->next; delete c; - };*/ + }*/ table[i] = NULL; - }; + } numelems = 0; chunkremain = 0; for(chainchunk *chunk; lastchunk; lastchunk = chunk) @@ -447,16 +447,16 @@ template struct hashtable chunk = lastchunk->next; delete lastchunk; } - }; + } }; #define enumeratekt(ht,k,e,t,f,b) loopi((ht).size) for(hashtable::chain *enumc = (ht).table[i]; enumc; enumc = enumc->next) { hashtable::const_key &e = enumc->key; t &f = enumc->data; b; } #define enumerate(ht,t,e,b) loopi((ht).size) for((ht).enumc = (ht).table[i]; (ht).enumc; (ht).enumc = (ht).enumc->next) { t &e = (ht).enumc->data; b; } -inline char *newstring(size_t l) { return new char[l+1]; }; -inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); }; -inline char *newstring(const char *s) { return newstring(s, strlen(s)); }; -inline char *newstringbuf(const char *s) { return newstring(s, _MAXDEFSTR-1); }; +inline char *newstring(size_t l) { return new char[l+1]; } +inline char *newstring(const char *s, size_t l) { return s_strncpy(newstring(l), s, l+1); } +inline char *newstring(const char *s) { return newstring(s, strlen(s)); } +inline char *newstringbuf(const char *s) { return newstring(s, _MAXDEFSTR-1); } #endif diff --git a/source/src/tristrip.h b/source/src/tristrip.h index 75a6d3e4..64c15e8d 100644 --- a/source/src/tristrip.h +++ b/source/src/tristrip.h @@ -26,23 +26,23 @@ struct tristrip loopi(3) { if(n[i]==neighbor) return false; - else if(n[i]==old) { n[i] = neighbor; return true; }; - }; + else if(n[i]==old) { n[i] = neighbor; return true; } + } if(dbgts && old==UNUSED) conoutf("excessive links"); return false; - }; + } void unlink(ushort neighbor, ushort unused = UNUSED) { loopi(3) if(n[i]==neighbor) n[i] = unused; - }; + } - int numlinks() const { int num = 0; loopi(3) if(n[i] triangles; @@ -59,21 +59,21 @@ struct tristrip { tri.v[j] = *triidxs++; tri.n[j] = UNUSED; - }; + } if(tri.v[0]==tri.v[1] || tri.v[1]==tri.v[2] || tri.v[2]==tri.v[0]) { if(dbgts) conoutf("degenerate triangle"); triangles.drop(); - }; - }; - }; + } + } + } struct edge { ushort from, to; - edge() {}; - edge(ushort from, ushort to) : from(min(from, to)), to(max(from, to)) {}; + edge() {} + edge(ushort from, ushort to) : from(min(from, to)), to(max(from, to)) {} void link(ushort tri) { @@ -83,7 +83,7 @@ struct tristrip from = tri; } else to = tri; - }; + } }; void findconnectivity() @@ -109,13 +109,13 @@ struct tristrip { if(dbgts) conoutf("failed linkage 2: %d -> %d", *owner, i); tri.unlink(*owner); - }; - }; - }; + } + } + } loopi(4) connectivity[i].setsizenodelete(0); loopv(triangles) connectivity[triangles[i].numlinks()].add(i); if(dbgts) conoutf("no connections: %d", connectivity[0].length()); - }; + } void removeconnectivity(ushort i) { @@ -125,21 +125,21 @@ struct tristrip triangle &neighbor = triangles[tri.n[j]]; int conn = neighbor.numlinks(); bool linked = false; - loopk(3) if(neighbor.n[k]==i) { linked = true; neighbor.n[k] = REMOVED; break; }; + loopk(3) if(neighbor.n[k]==i) { linked = true; neighbor.n[k] = REMOVED; break; } if(linked) { connectivity[conn].replacewithlast(tri.n[j]); connectivity[conn-1].add(tri.n[j]); - }; - }; + } + } removenodes(i); - }; + } bool remaining() const { loopi(4) if(!connectivity[i].empty()) return true; return false; - }; + } ushort leastconnected() { @@ -148,9 +148,9 @@ struct tristrip ushort least = connectivity[i].pop(); removeconnectivity(least); return least; - }; + } return UNUSED; - }; + } int findedge(const triangle &from, const triangle &to, ushort v = UNUSED) { @@ -159,12 +159,12 @@ struct tristrip if(from.v[i]==to.v[j] && from.v[i]!=v) return i; } return -1; - }; + } void removenodes(int i) { loopj(3) nodes[triangles[i].v[j]]--; - }; + } ushort nexttriangle(triangle &tri, bool &nextswap, ushort v1 = UNUSED, ushort v2 = UNUSED) { @@ -186,17 +186,17 @@ struct tristrip else score += nodes[v1] > nodes[v2] ? 1 : -1; if(!tsswap && swap) continue; score += swap ? 1 : -1; - }; - if(score < nextscore) { next = tri.n[i]; nextswap = swap; nextscore = score; }; - }; + } + if(score < nextscore) { next = tri.n[i]; nextswap = swap; nextscore = score; } + } if(next!=UNUSED) { tri.unlink(next, REMOVED); connectivity[triangles[next].numlinks()].replacewithlast(next); removeconnectivity(next); - }; + } return next; - }; + } void buildstrip(vector &strip, bool reverse = false) { @@ -209,7 +209,7 @@ struct tristrip { loopi(3) strip.add(first.v[reverse && i>=1 ? 3-i : i]); return; - }; + } int from = findedge(first, triangles[cur]), to = findedge(first, triangles[cur], first.v[from]); if(from+1!=to) swap(int, from, to); @@ -228,8 +228,8 @@ struct tristrip strip.add(v); if(!doswap) v2 = v1; v1 = v; - }; - }; + } + } void buildstrips(vector &strips, bool prims = true, bool degen = false) { @@ -247,24 +247,23 @@ struct tristrip { loopv(strip) singles.add(strip[i]); continue; - }; + } if(!strips.empty()) { if(degen) { strips.dup(); strips.add(strip[0]); } else strips.add(RESTART); - }; + } loopv(strip) strips.add(strip[i]); - }; + } if(prims && !singles.empty()) { strips.add(LIST); loopv(singles) strips.add(singles[i]); - }; + } if(dbgts) conoutf("strips = %d, tris = %d, inds = %d, merges = %d", numstrips, numtris, numtris + numstrips*2, (degen ? 2 : 1)*(numstrips-1)); - }; - + } }; -static inline uint hthash(const tristrip::edge &x) { return x.from^x.to; }; -static inline bool htcmp(const tristrip::edge &x, const tristrip::edge &y) { return x.from==y.from && x.to==y.to; }; +static inline uint hthash(const tristrip::edge &x) { return x.from^x.to; } +static inline bool htcmp(const tristrip::edge &x, const tristrip::edge &y) { return x.from==y.from && x.to==y.to; } diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h index f785b909..860599e2 100644 --- a/source/src/vertmodel.h +++ b/source/src/vertmodel.h @@ -23,13 +23,13 @@ struct vertmodel : model { fr1 = min(fr1, as.range-1)+as.frame; fr2 = min(fr1+1, as.frame+as.range-1); - }; + } if(as.anim&ANIM_REVERSE) { fr1 = (as.frame+as.range-1)-(fr1-as.frame); fr2 = (as.frame+as.range-1)-(fr2-as.frame); - }; - }; + } + } }; struct tcvert { float u, v; ushort index; }; @@ -52,7 +52,7 @@ struct vertmodel : model GLuint statlist; int statlen; - mesh() : name(0), verts(0), tcverts(0), tris(0), skin(crosshair), tex(0), dynbuf(0), dynidx(0), dynframe(-1), statlist(0) {}; + mesh() : name(0), verts(0), tcverts(0), tris(0), skin(crosshair), tex(0), dynbuf(0), dynidx(0), dynframe(-1), statlist(0) {} ~mesh() { @@ -63,7 +63,7 @@ struct vertmodel : model if(statlist) glDeleteLists(statlist, 1); DELETEA(dynidx); DELETEA(dynbuf); - }; + } void gendyn() { @@ -75,7 +75,7 @@ struct vertmodel : model dynidx = new ushort[idxs.length()]; memcpy(dynidx, idxs.getbuf(), idxs.length()*sizeof(ushort)); dynlen = idxs.length(); - }; + } void gendynverts(anpos &cur, anpos *prev, float ai_t) { @@ -108,11 +108,11 @@ struct vertmodel : model else { v = vec(ip_v(vert, x, cur.t), ip_v(vert, y, cur.t), ip_v(vert, z, cur.t)); - }; + } #undef ip #undef ip_v - }; - }; + } + } void render(animstate &as, anpos &cur, anpos *prev, float ai_t) { @@ -125,9 +125,9 @@ struct vertmodel : model { int xs, ys; id = lookuptexture(tex, xs, ys); - }; + } glBindTexture(GL_TEXTURE_2D, id); - }; + } bool isstat = as.frame==0 && as.range==1; if(isstat && statlist) @@ -147,21 +147,21 @@ struct vertmodel : model if(j) glEnd(); glBegin(index==tristrip::LIST ? GL_TRIANGLES : GL_TRIANGLE_STRIP); if(index>=tristrip::RESTART) continue; - }; + } tcvert &tc = tcverts[index]; if(!(as.anim&ANIM_NOSKIN)) glTexCoord2f(tc.u, tc.v); glVertex3fv(&dynbuf[tc.index].x); - }; + } glEnd(); if(isstat) { glEndList(); glCallList(statlist); statlen = dynlen; - }; + } xtraverts += dynlen; - }; - }; + } + } }; struct animinfo @@ -176,8 +176,8 @@ struct vertmodel : model vec pos; float transform[3][3]; - tag() : name(NULL) {}; - ~tag() { DELETEA(name); }; + tag() : name(NULL) {} + ~tag() { DELETEA(name); } }; struct part @@ -192,7 +192,7 @@ struct vertmodel : model int numtags; GLuint *shadows; - part() : loaded(false), anims(NULL), links(NULL), tags(NULL), numtags(0), shadows(NULL) {}; + part() : loaded(false), anims(NULL), links(NULL), tags(NULL), numtags(0), shadows(NULL) {} virtual ~part() { meshes.deletecontentsp(); @@ -201,7 +201,7 @@ struct vertmodel : model DELETEA(tags); if(shadows) glDeleteTextures(numframes, shadows); DELETEA(shadows); - }; + } bool link(part *link, const char *tag) { @@ -209,9 +209,9 @@ struct vertmodel : model { links[i] = link; return true; - }; + } return false; - }; + } void scaleverts(const float scale, const vec &translate) { @@ -223,27 +223,27 @@ struct vertmodel : model vec &v = m.verts[j]; if(!index) v.add(translate); v.mul(scale); - }; - }; + } + } loopi(numframes*numtags) { vec &v = tags[i].pos; if(!index) v.add(translate); v.mul(scale); - }; - }; + } + } void gendyn() { loopv(meshes) meshes[i]->gendyn(); - }; + } virtual void getdefaultanim(animstate &as, int anim, int varseed, float speed) { as.frame = 0; as.range = 1; as.speed = speed; - }; + } bool calcanimstate(int anim, int varseed, float speed, int basetime, dynent *d, animstate &as) { @@ -270,20 +270,20 @@ struct vertmodel : model as.frame = 0; as.range = 1; as.speed = speed; - }; + } } else getdefaultanim(as, anim&ANIM_INDEX, varseed, speed); if(anim&(ANIM_START|ANIM_END)) { if(anim&ANIM_END) as.frame += as.range-1; as.range = 1; - }; + } if(as.frame+as.range>numframes) { if(as.frame>=numframes) return false; as.range = numframes-as.frame; - }; + } if(d && index<2) { @@ -297,11 +297,11 @@ struct vertmodel : model if(lastmillis-d->lastanimswitchtime[index]>animationinterpolationtime/2) d->prev[index] = d->current[index]; d->current[index] = as; d->lastanimswitchtime[index] = lastmillis; - }; + } d->lastmodel[index] = this; - }; + } return true; - }; + } void render(int anim, int varseed, float speed, int basetime, dynent *d) { @@ -320,7 +320,7 @@ struct vertmodel : model { prev.setframes(d->prev[index]); ai_t = (lastmillis-d->lastanimswitchtime[index])/(float)animationinterpolationtime; - }; + } loopv(meshes) meshes[i]->render(as, cur, doai ? &prev : NULL, ai_t); @@ -348,7 +348,7 @@ struct vertmodel : model loopj(3) matrix[4 + j] = ip(tag1->transform[1][j], tag2->transform[1][j], cur.t); loopj(3) matrix[8 + j] = ip(tag1->transform[2][j], tag2->transform[2][j], cur.t); loopj(3) matrix[12 + j] = ip(tag1->pos[j], tag2->pos[j], cur.t); // position - }; + } #undef ip_ai_tag #undef ip matrix[3] = matrix[7] = matrix[11] = 0.0f; @@ -357,8 +357,8 @@ struct vertmodel : model glMultMatrixf(matrix); link->render(anim, varseed, speed, basetime, d); glPopMatrix(); - }; - }; + } + } void setanim(int num, int frame, int range, float speed) { @@ -366,21 +366,21 @@ struct vertmodel : model { conoutf("invalid frame %d, range %d in model %s", frame, range, model->loadname); return; - }; + } if(!anims) anims = new vector[NUMANIMS]; animinfo &ai = anims[num].add(); ai.frame = frame; ai.range = range; ai.speed = speed; - }; + } virtual void begingenshadow() { - }; + } virtual void endgenshadow() { - }; + } void genshadow(int aasize, int frame) { @@ -401,7 +401,7 @@ struct vertmodel : model if(aasize > 1<link(link, tag)) return true; return false; - }; + } void setskin(int tex) { if(parts.length()!=1 || parts[0]->meshes.length()!=1) return; mesh &m = *parts[0]->meshes[0]; m.tex = tex; - }; + } void genshadows(float height, float rad) { loopv(parts) parts[i]->genshadows(height, rad); - }; + } }; diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 7e0b02db..1188cf88 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -40,8 +40,8 @@ void checkweaponswitch() (player1->akimbo && !player1->akimbomillis && player1->gunselect==GUN_PISTOL)) player1->akimbo = !player1->akimbo; player1->gunselect = player1->nextweapon; - }; -}; + } +} void weaponswitch(int gun) { @@ -50,7 +50,7 @@ void weaponswitch(int gun) player1->lastaction = player1->akimbolastaction[0] = player1->akimbolastaction[1] = lastmillis; player1->nextweapon = gun; playsound(S_GUNCHANGE); -}; +} void weapon(int gun) { @@ -65,7 +65,7 @@ void weapon(int gun) setscope(false); weaponswitch(gun); -}; +} void shiftweapon(int s) { @@ -74,12 +74,12 @@ void shiftweapon(int s) int trygun = player1->gunselect + s + (s < 0 ? -i : i); if((trygun %= NUMGUNS) < 0) trygun += NUMGUNS; weapon(trygun); - }; -}; + } +} -int currentprimary() { return player1->primary; }; -int curweapon() { return player1->gunselect; }; -int magcontent(int gun) { if(gun > 0 && gun < NUMGUNS) return player1->mag[gun]; else return -1;}; +int currentprimary() { return player1->primary; } +int curweapon() { return player1->gunselect; } +int magcontent(int gun) { if(gun > 0 && gun < NUMGUNS) return player1->mag[gun]; else return -1;} COMMAND(weapon, ARG_1INT); COMMAND(shiftweapon, ARG_1INT); @@ -132,16 +132,16 @@ void reload(playerent *d) if(has_akimbo(d)) playsoundc(S_RAKIMBO); else if(d->type==ENT_BOT) playsound(guns[d->gunselect].reload, &d->o); else playsoundc(guns[d->gunselect].reload); -}; +} -void selfreload() { reload(player1); }; +void selfreload() { reload(player1); } COMMANDN(reload, selfreload, ARG_NONE); -int reloadtime(int gun) { return guns[gun].reloadtime; }; -int attackdelay(int gun) { return guns[gun].attackdelay; }; -int magsize(int gun) { return guns[gun].magsize; }; -int kick_rot(int gun) { return guns[gun].mdl_kick_rot; }; -int kick_back(int gun) { return guns[gun].mdl_kick_back; }; +int reloadtime(int gun) { return guns[gun].reloadtime; } +int attackdelay(int gun) { return guns[gun].attackdelay; } +int magsize(int gun) { return guns[gun].magsize; } +int kick_rot(int gun) { return guns[gun].mdl_kick_rot; } +int kick_back(int gun) { return guns[gun].mdl_kick_back; } void createrays(vec &from, vec &to) // create random spread of rays for the shotgun { @@ -153,8 +153,8 @@ void createrays(vec &from, vec &to) // create random spread of rays sg[i] = to; sg[i].add(r); #undef RNDD - }; -}; + } +} bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits entity bounding box { @@ -173,8 +173,8 @@ bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits ent float f = c1/c2; v.mul(f).add(from); p = &v; - }; - }; + } + } return p->x <= d->o.x+d->radius && p->x >= d->o.x-d->radius @@ -182,7 +182,7 @@ bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits ent && p->y >= d->o.y-d->radius && p->z <= d->o.z+d->aboveeye && p->z >= d->o.z-d->eyeheight; -}; +} playerent *intersectclosest(vec &from, vec &to, int &n, playerent *at) { @@ -193,7 +193,7 @@ playerent *intersectclosest(vec &from, vec &to, int &n, playerent *at) best = player1; bestdist = at->o.dist(player1->o); n = getclientnum(); - }; + } loopv(players) { playerent *o = players[i]; @@ -205,23 +205,23 @@ playerent *intersectclosest(vec &from, vec &to, int &n, playerent *at) best = o; bestdist = dist; n = i; - }; - }; + } + } return best; -}; +} playerent *playerincrosshair() { if(demoplayback) return NULL; int n; return intersectclosest(player1->o, worldpos, n, player1); -}; +} const int MAXPROJ = 100; struct projectile { vec o, to; float speed; playerent *owner; int gun; bool inuse, local; }; projectile projs[MAXPROJ]; -void projreset() { loopi(MAXPROJ) projs[i].inuse = false; }; +void projreset() { loopi(MAXPROJ) projs[i].inuse = false; } void newprojectile(vec &from, vec &to, float speed, bool local, playerent *owner, int gun) { @@ -237,8 +237,8 @@ void newprojectile(vec &from, vec &to, float speed, bool local, playerent *owner p->owner = owner; p->gun = gun; return; - }; -}; + } +} void hit(int target, int damage, playerent *d, playerent *at, bool gib=false) { @@ -248,10 +248,10 @@ void hit(int target, int damage, playerent *d, playerent *at, bool gib=false) { addmsg(gib ? SV_GIBDAMAGE : SV_DAMAGE, "ri3", target, damage, d->lifesequence); playsound(S_PAIN1+rnd(5), &d->o); - }; + } particle_splash(3, damage, 1000, d->o); demodamage(damage, d->o); -}; +} const float RL_RADIUS = 7; const float RL_DAMRAD = 10; // hack @@ -268,8 +268,8 @@ void radialeffect(playerent *o, vec &v, int cn, int qdam, playerent *at) int damage = (int)(qdam*(1-(dist/RL_DAMRAD))); hit(cn, damage, o, at, true); o->vel.add(temp.mul((RL_DAMRAD-dist)*damage/800)); - }; -}; + } +} void splash(projectile *p, vec &v, vec &vold, int notthisplayer, int qdam) { @@ -293,9 +293,9 @@ void splash(projectile *p, vec &v, vec &vold, int notthisplayer, int qdam) playerent *o = players[i]; if(!o) continue; radialeffect(o, v, i, qdam, p->owner); - }; - }; -}; + } + } +} inline void projdamage(playerent *o, projectile *p, vec &v, int i, int qdam) { @@ -304,8 +304,8 @@ inline void projdamage(playerent *o, projectile *p, vec &v, int i, int qdam) { splash(p, v, p->o, i, qdam); hit(i, qdam, o, p->owner, true); //fixme - }; -}; + } +} void moveprojectiles(float time) { @@ -327,26 +327,26 @@ void moveprojectiles(float time) playerent *o = players[i]; if(!o) continue; projdamage(o, p, v, i, qdam); - }; + } if(p->owner!=player1) projdamage(player1, p, v, -1, qdam); - }; + } if(p->inuse) { if(time==dtime) splash(p, v, p->o, -1, qdam); else { if(p->gun==GUN_GRENADE) { 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); }; + else { particle_splash(1, 1, 200, v); particle_splash(guns[p->gun].part, 1, 1, v); } // Added by Rick traceresult_s tr; TraceLine(p->o, v, p->owner, true, &tr); if (tr.collided) splash(p, v, p->o, -1, qdam); // End add - }; - }; + } + } p->o = v; - }; -}; + } +} void throw_nade(playerent *d, const vec &vel, bounceent *p) { @@ -368,8 +368,8 @@ void throw_nade(playerent *d, const vec &vel, bounceent *p) { player1->lastaction = lastmillis; addmsg(SV_SHOT, "ri8", d->gunselect, (int)(d->o.x*DMF), (int)(d->o.y*DMF), (int)(d->o.z*DMF), (int)(vel.x*DMF), (int)(vel.y*DMF), (int)(vel.z*DMF), lastmillis-p->millis); - }; -}; + } +} void throw_nade(playerent *d, bounceent *p) { @@ -380,7 +380,7 @@ void throw_nade(playerent *d, bounceent *p) vel.mul(1.5f); throw_nade(d, vel, p); -}; +} // fixme VAR(grenadespeed, 0, 27, 100); @@ -400,7 +400,7 @@ bounceent *new_nade(playerent *d, int millis = 0) d->thrownademillis = 0; playsound(S_GRENADEPULL, (d==player1 ? NULL : &d->o)); return p; -}; +} void explode_nade(bounceent *i) { @@ -408,7 +408,7 @@ void explode_nade(bounceent *i) if(i->bouncestate != NADE_THROWED) throw_nade(i->owner, vec(0,0,0), i); playsound(S_FEXPLODE, &i->o); newprojectile(i->o, i->o, 1, i->owner==player1, i->owner, GUN_GRENADE); -}; +} void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademillis) // create visual effect from a shot { @@ -422,7 +422,7 @@ void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademilli { loopi(SGRAYS) particle_splash(0, 5, 200, sg[i]); break; - }; + } case GUN_PISTOL: case GUN_SUBGUN: @@ -431,7 +431,7 @@ void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademilli addshotline(d, from, to); particle_splash(0, 5, 250, to); break; - }; + } case GUN_GRENADE: { @@ -439,9 +439,9 @@ void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademilli { bounceent *p = new_nade(d, nademillis); throw_nade(d, to, p); - }; + } break; - }; + } case GUN_SNIPER: { @@ -449,9 +449,9 @@ void shootv(int gun, vec &from, vec &to, playerent *d, bool local, int nademilli particle_splash(0, 50, 200, to); particle_trail(1, 500, from, to); break; - }; - }; -}; + } + } +} void hitpush(int target, int damage, playerent *d, playerent *at, vec &from, vec &to, bool gib = false) { @@ -460,12 +460,12 @@ void hitpush(int target, int damage, playerent *d, playerent *at, vec &from, vec float dist = to.dist(from, v); v.mul(damage/dist/50); d->vel.add(v); -}; +} void shorten(vec &from, vec &to, vec &target) { target.sub(from).normalize().mul(from.dist(to)).add(from); -}; +} const float HEADSIZE = 0.8f; vec hitpos; @@ -495,10 +495,10 @@ void raydamage(vec &from, vec &to, playerent *d) shorten(from, o->o, sg[r]); } else raysleft = true; - }; + } if(damage) hitpush(i, damage, o, d, from, to); if(!raysleft) break; - }; + } } else if((o = intersectclosest(from, to, i, d))) { @@ -510,12 +510,12 @@ void raydamage(vec &from, vec &to, playerent *d) { gdam *= 3; gib = true; - }; + } hitpush(i, gdam, o, d, from, to, gib); shorten(from, o->o, to); - }; -}; + } +} void spreadandrecoil(vec &from, vec &to, playerent *d) { @@ -536,13 +536,13 @@ void spreadandrecoil(vec &from, vec &to, playerent *d) if(d->shots > 3) spd = 70; rcl += (rnd(8)*-0.01f); - }; + } if((d->gunselect==GUN_SNIPER) /*&& (d->vel.x<.25f && d->vel.y<.25f)*/ && scoped) { spd = 1; rcl = rcl / 3; - }; + } if(d->gunselect!=GUN_SHOTGUN) //no spread on shotgun { @@ -550,13 +550,13 @@ void spreadandrecoil(vec &from, vec &to, playerent *d) vec r(RNDD, RNDD, RNDD); to.add(r); #undef RNDD - }; + } //increase pitch for recoil d->vel.add(vec(unitv).mul(rcl/dist)); if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; -}; +} bool hasammo(playerent *d) // bot mod { @@ -593,7 +593,7 @@ void shoot(playerent *d, vec &targ) d->nextweapon = d->mag[GUN_GRENADE] ? GUN_GRENADE : d->primary; d->thrownademillis = 0; d->lastaction = lastmillis-1-WEAPONCHANGE_TIME/2; - }; + } if(d->weaponchanging || attacktimegunwait) return; d->gunwait = 0; @@ -618,11 +618,11 @@ void shoot(playerent *d, vec &targ) d->gunwait = 0; d->reloading = false; - if(!d->attacking) { d->shots = 0; return; }; + if(!d->attacking) { d->shots = 0; return; } d->lastaction = lastmillis; d->lastattackgun = d->gunselect; - if(d->gunselect!=GUN_KNIFE && !hasammo(d)) { d->shots = 0; return; }; + if(d->gunselect!=GUN_KNIFE && !hasammo(d)) { d->shots = 0; return; } if(guns[d->gunselect].isauto) d->shots++; else d->attacking = false; @@ -632,11 +632,11 @@ void shoot(playerent *d, vec &targ) d->attacking = true; //make akimbo auto d->akimbolastaction[akimboside?1:0] = lastmillis; akimboside = !akimboside; - }; + } if(d->gunselect!=GUN_KNIFE) d->mag[d->gunselect]--; from.z -= 0.2f; // below eye - }; + } spreadandrecoil(from,to,d); vec unitv; @@ -648,7 +648,7 @@ void shoot(playerent *d, vec &targ) unitv.mul(3); // punch range to = from; to.add(unitv); - }; + } if(d->gunselect==GUN_SHOTGUN) createrays(from, to); if(has_akimbo(d)) d->gunwait = guns[d->gunselect].attackdelay / 2; //make akimbo pistols shoot twice as fast as normal pistol @@ -662,4 +662,4 @@ void shoot(playerent *d, vec &targ) if(guns[d->gunselect].projspeed || d->gunselect==GUN_GRENADE) return; raydamage(from, to, d); -}; +} diff --git a/source/src/world.cpp b/source/src/world.cpp index e319dc8e..cb390b0c 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -26,27 +26,27 @@ void settag(int tag, int type) // set all cubes with "tag" to space, if else { s->type = type ? SOLID : SPACE; - }; + } if(x>maxx) maxx = x; if(y>maxy) maxy = y; if(x>level; int vs = ssize>>(level+1); block s = b; - if(s.x&1) { s.x--; s.xs++; }; - if(s.y&1) { s.y--; s.ys++; }; + if(s.x&1) { s.x--; s.xs++; } + if(s.y&1) { s.y--; s.ys++; } s.xs = (s.xs+1)&~1; s.ys = (s.ys+1)&~1; for(int x = s.x; xtype==FHF) fh -= o[i]->vdelta/4+2; // crap hack, needed for rendering large mips next to hfs if(o[i]->type==CHF) ch += o[i]->vdelta/4+2; // FIXME: needs to somehow take into account middle vertices on higher mips - }; + } if(fhceil) ceil = ch; - }; + } r->floor = floor; r->ceil = ceil; - }; + } if(r->type==CORNER) goto mip; // special case: don't ever split even if textures etc are different r->defer = 1; if(SOLID(r)) @@ -119,7 +119,7 @@ void remip(block &b, int level) loopi(3) { if(o[i]->wtex!=o[3]->wtex) goto c; // on an all solid cube, only thing that needs to be equal for a perfect mip is the wall texture - }; + } } else { @@ -135,7 +135,7 @@ void remip(block &b, int level) || abs(o[i+1]->b-o[0]->b)>lighterr || o[i]->utex!=o[3]->utex || o[i]->wtex!=o[3]->wtex) goto c; - }; + } if(r->type==CHF || r->type==FHF) // can make a perfect mip out of a hf if slopes lie on one line { if(o[0]->vdelta-o[1]->vdelta != o[1]->vdelta-SWS(w,x+2,y,ws)->vdelta @@ -143,19 +143,19 @@ void remip(block &b, int level) || o[0]->vdelta-o[3]->vdelta != o[3]->vdelta-SWS(w,x,y+2,ws)->vdelta || o[3]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+2,y+1,ws)->vdelta || o[1]->vdelta-o[2]->vdelta != o[2]->vdelta-SWS(w,x+1,y+2,ws)->vdelta) goto c; - }; - }; - { loopi(4) if(o[i]->defer) goto c; }; // if any of the constituents is not perfect, then this one isn't either + } + } + { loopi(4) if(o[i]->defer) goto c; } // if any of the constituents is not perfect, then this one isn't either mip: r->defer = 0; c:; - }; + } s.x /= 2; s.y /= 2; s.xs /= 2; s.ys /= 2; remip(s, level+1); -}; +} void remipmore(block &b, int level) { @@ -165,7 +165,7 @@ void remipmore(block &b, int level) if(bb.xsyaw; break; - }; + } addmsg(SV_EDITENT, "ri9", ents.length(), type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4); ents.add(*((entity *)&e)); // unsafe! if(type==LIGHT) calclight(); return &ents.last(); -}; +} void clearents(char *name) { @@ -254,9 +254,9 @@ void clearents(char *name) { entity &e = ents[i]; if(e.type==type) e.type = NOTUSED; - }; + } if(type==LIGHT) calclight(); -}; +} COMMAND(clearents, ARG_1STR); @@ -265,7 +265,7 @@ void scalecomp(uchar &c, int intens) int n = c*intens/100; if(n>255) n = 255; c = n; -}; +} void scalelights(int f, int intens) { @@ -281,10 +281,10 @@ void scalelights(int f, int intens) scalecomp(e.attr2, intens); scalecomp(e.attr3, intens); scalecomp(e.attr4, intens); - }; - }; + } + } calclight(); -}; +} COMMAND(scalelights, ARG_2INT); @@ -293,14 +293,14 @@ int findentity(int type, int index) for(int i = index; i>(i*2); }; -}; + loopi(LARGEST_FACTOR*2) { wmip[i] = w; w += cubicsize>>(i*2); } +} void empty_world(int factor, bool force) // main empty world creation routine, if passed factor -1 will enlarge old world by 1 { @@ -321,7 +321,7 @@ void empty_world(int factor, bool force) // main empty world creation routine pruneundos(); sqr *oldworld = world; bool copy = false; - if(oldworld && factor<0) { factor = sfactor+1; copy = true; }; + if(oldworld && factor<0) { factor = sfactor+1; copy = true; } if(factorLARGEST_FACTOR) factor = LARGEST_FACTOR; setupworld(factor); @@ -338,7 +338,7 @@ void empty_world(int factor, bool force) // main empty world creation routine s->ceil = 16; s->vdelta = 0; s->defer = 0; - }; + } strncpy(hdr.head, "ACMP", 4); hdr.version = MAPVERSION; @@ -350,12 +350,12 @@ void empty_world(int factor, bool force) // main empty world creation routine loop(x,ssize/2) loop(y,ssize/2) { *S(x+ssize/4, y+ssize/4) = *SWS(oldworld, x, y, ssize/2); - }; + } loopv(ents) { ents[i].x += ssize/4; ents[i].y += ssize/4; - }; + } } else { @@ -366,7 +366,7 @@ void empty_world(int factor, bool force) // main empty world creation routine ents.setsize(0); block b = { 8, 8, ssize-16, ssize-16 }; edittypexy(SPACE, b); - }; + } calclight(); startmap(""); @@ -376,11 +376,11 @@ void empty_world(int factor, bool force) // main empty world creation routine toggleedit(); execfile("config/default_map_settings.cfg"); execute("fullbright 1"); - }; -}; + } +} -void mapenlarge() { empty_world(-1, false); }; -void newmap(int i) { empty_world(i, false); }; +void mapenlarge() { empty_world(-1, false); } +void newmap(int i) { empty_world(i, false); } COMMAND(mapenlarge, ARG_NONE); COMMAND(newmap, ARG_1INT); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 9fdfbbb0..03ceda5e 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -6,7 +6,7 @@ void backup(char *name, char *backupname) { remove(backupname); rename(name, backupname); -}; +} string cgzname, bakname, pcfname, mcfname; @@ -23,7 +23,7 @@ void setnames(char *name) { s_strcpy(pakname, "maps"); s_strcpy(mapname, name); - }; + } s_sprintf(cgzname)("packages/%s/%s.cgz", pakname, mapname); s_sprintf(bakname)("packages/%s/%s_%d.BAK", pakname, mapname, lastmillis); s_sprintf(pcfname)("packages/%s/package.cfg", pakname); @@ -31,7 +31,7 @@ void setnames(char *name) path(cgzname); path(bakname); -}; +} // the optimize routines below are here to reduce the detrimental effects of messy mapping by // setting certain properties (vdeltas and textures) to neighbouring values wherever there is no @@ -39,7 +39,7 @@ void setnames(char *name) // the reason it is done on save is to reduce the amount spend in the mipmapper (as that is done // in realtime). -inline bool nhf(sqr *s) { return s->type!=FHF && s->type!=CHF; }; +inline bool nhf(sqr *s) { return s->type!=FHF && s->type!=CHF; } void voptimize() // reset vdeltas on non-hf cubes { @@ -48,8 +48,8 @@ void voptimize() // reset vdeltas on non-hf cubes sqr *s = S(x, y); if(x && y) { if(nhf(s) && nhf(S(x-1, y)) && nhf(S(x-1, y-1)) && nhf(S(x, y-1))) s->vdelta = 0; } else s->vdelta = 0; - }; -}; + } +} void topt(sqr *s, bool &wf, bool &uf, int &wt, int &ut) { @@ -68,17 +68,17 @@ void topt(sqr *s, bool &wf, bool &uf, int &wt, int &ut) wt = s->wtex; ut = s->utex; return; - }; + } } else { loopi(4) if(!SOLID(o[i])) { - if(o[i]->floorfloor) { wt = s->wtex; wf = false; }; - if(o[i]->ceil>s->ceil) { ut = s->utex; uf = false; }; - }; - }; -}; + if(o[i]->floorfloor) { wt = s->wtex; wf = false; } + if(o[i]->ceil>s->ceil) { ut = s->utex; uf = false; } + } + } +} void toptimize() // FIXME: only does 2x2, make atleast for 4x4 also { @@ -96,9 +96,9 @@ void toptimize() // FIXME: only does 2x2, make atleast for 4x4 also { if(wf[i]) s[i]->wtex = wt; if(uf[i]) s[i]->utex = ut; - }; - }; -}; + } + } +} // these two are used by getmap/sendmap.. transfers compressed maps directly @@ -107,7 +107,7 @@ void writemap(char *mname, int msize, uchar *mdata) setnames(mname); backup(cgzname, bakname); FILE *f = fopen(cgzname, "wb"); - if(!f) { conoutf("could not write map to %s", cgzname); return; }; + if(!f) { conoutf("could not write map to %s", cgzname); return; } fwrite(mdata, 1, msize, f); fclose(f); conoutf("wrote map %s as file %s", mname, cgzname); @@ -117,7 +117,7 @@ uchar *readmap(char *mname, int *msize) { setnames(mname); uchar *mdata = (uchar *)loadfile(cgzname, msize); - if(!mdata) { conoutf("could not read map %s", cgzname); return NULL; }; + if(!mdata) { conoutf("could not read map %s", cgzname); return NULL; } return mdata; } @@ -134,7 +134,7 @@ void save_world(char *mname) setnames(mname); backup(cgzname, bakname); gzFile f = gzopen(cgzname, "wb9"); - if(!f) { conoutf("could not write map to %s", cgzname); return; }; + if(!f) { conoutf("could not write map to %s", cgzname); return; } hdr.version = MAPVERSION; hdr.numents = 0; loopv(ents) if(ents[i].type!=NOTUSED) hdr.numents++; @@ -149,11 +149,11 @@ void save_world(char *mname) entity tmp = ents[i]; endianswap(&tmp, sizeof(short), 4); gzwrite(f, &tmp, sizeof(persistent_entity)); - }; - }; + } + } sqr *t = NULL; int sc = 0; - #define spurge while(sc) { gzputc(f, 255); if(sc>255) { gzputc(f, 255); sc -= 255; } else { gzputc(f, sc); sc = 0; } }; + #define spurge while(sc) { gzputc(f, 255); if(sc>255) { gzputc(f, 255); sc -= 255; } else { gzputc(f, sc); sc = 0; } } loopk(cubicsize) { sqr *s = &world[k]; @@ -176,7 +176,7 @@ void save_world(char *mname) gzputc(f, s->type); gzputc(f, s->wtex); gzputc(f, s->vdelta); - }; + } } else { @@ -196,15 +196,15 @@ void save_world(char *mname) gzputc(f, s->vdelta); gzputc(f, s->utex); gzputc(f, s->tag); - }; - }; + } + } t = s; - }; + } spurge; gzclose(f); conoutf("wrote map file %s", cgzname); settagareas(); -}; +} extern void preparectf(bool cleanonly = false); @@ -216,7 +216,7 @@ void load_world(char *mname) // still supports all map formats that have pruneundos(); setnames(mname); gzFile f = gzopen(cgzname, "rb9"); - if(!f) { conoutf("could not read map %s", cgzname); return; }; + if(!f) { conoutf("could not read map %s", cgzname); return; } loadingscreen(); gzread(f, &hdr, sizeof(header)-sizeof(int)*16); endianswap(&hdr.version, sizeof(int), 4); @@ -231,7 +231,7 @@ void load_world(char *mname) // still supports all map formats that have else { hdr.waterlevel = -100000; - }; + } ents.setsize(0); loopi(hdr.numents) { @@ -243,7 +243,7 @@ void load_world(char *mname) // still supports all map formats that have { if(!e.attr2) e.attr2 = 255; // needed for MAPVERSION<=2 if(e.attr1>32) e.attr1 = 32; // 12_03 and below - }; + } if (hdr.versionr = s->g = s->b = gzgetc(f); gzgetc(f); break; - }; + } case SOLID: { s->type = SOLID; s->wtex = gzgetc(f); s->vdelta = gzgetc(f); - if(hdr.version<=2) { gzgetc(f); gzgetc(f); }; + if(hdr.version<=2) { gzgetc(f); gzgetc(f); } s->ftex = DEFAULT_FLOOR; s->ctex = DEFAULT_CEIL; s->utex = s->wtex; @@ -321,14 +321,14 @@ void load_world(char *mname) // still supports all map formats that have s->floor = 0; s->ceil = 16; break; - }; + } default: { if(type<0 || type>=MAXTYPE) { s_sprintfd(t)("%d @ %d", type, k); fatal("while reading map: type out of range: ", t); - }; + } s->type = type; s->floor = gzgetc(f); s->ceil = gzgetc(f); @@ -336,18 +336,18 @@ void load_world(char *mname) // still supports all map formats that have s->wtex = gzgetc(f); s->ftex = gzgetc(f); s->ctex = gzgetc(f); - if(hdr.version<=2) { gzgetc(f); gzgetc(f); }; + if(hdr.version<=2) { gzgetc(f); gzgetc(f); } s->vdelta = gzgetc(f); s->utex = (hdr.version>=2) ? gzgetc(f) : s->wtex; s->tag = (hdr.version>=5) ? gzgetc(f) : 0; s->type = type; - }; - }; + } + } s->defer = 0; t = s; texuse[s->wtex] = 1; if(!SOLID(s)) texuse[s->utex] = texuse[s->ftex] = texuse[s->ctex] = 1; - }; + } gzclose(f); c2skeepalive(); calclight(); @@ -359,7 +359,7 @@ void load_world(char *mname) // still supports all map formats that have { s_sprintfd(aliasname)("level_trigger_%d", l); // can this be done smarter? if(identexists(aliasname)) alias(aliasname, ""); - }; + } execfile("config/default_map_settings.cfg"); execfile(pcfname); execfile(mcfname); @@ -369,7 +369,7 @@ void load_world(char *mname) // still supports all map formats that have c2skeepalive(); preload_mapmodels(); c2skeepalive(); -}; +} COMMANDN(savemap, save_world, ARG_1STR); diff --git a/source/src/worldlight.cpp b/source/src/worldlight.cpp index ba16ddc5..4b0f2174 100644 --- a/source/src/worldlight.cpp +++ b/source/src/worldlight.cpp @@ -64,7 +64,7 @@ void lightray(float bx, float by, persistent_entity &light) // done in realt stepl -= 25; stepg -= 25; stepb -= 25; - }; + } } else // white light, special optimized version { @@ -84,8 +84,8 @@ void lightray(float bx, float by, persistent_entity &light) // done in realt y += stepy; l -= stepl; stepl -= 25; - }; - }; + } + } } else // the old (white) light code, here for the few people with old video cards that don't support overbright { @@ -98,10 +98,10 @@ void lightray(float bx, float by, persistent_entity &light) // done in realt x += stepx; y += stepy; l -= stepl; - }; - }; + } + } -}; +} void calclightsource(persistent_entity &l) { @@ -115,11 +115,11 @@ void calclightsource(persistent_entity &l) const float s = 0.8f; - for(float sx2 = (float)sx; sx2<=ex; sx2+=s*2) { lightray(sx2, (float)sy, l); lightray(sx2, (float)ey, l); }; - for(float sy2 = sy+s; sy2<=ey-s; sy2+=s*2) { lightray((float)sx, sy2, l); lightray((float)ex, sy2, l); }; + for(float sx2 = (float)sx; sx2<=ex; sx2+=s*2) { lightray(sx2, (float)sy, l); lightray(sx2, (float)ey, l); } + for(float sy2 = sy+s; sy2<=ey-s; sy2+=s*2) { lightray((float)sx, sy2, l); lightray((float)ex, sy2, l); } rndtime(); -}; +} void postlightarea(block &a) // median filter, smooths out random noise in light and makes it more mipable { @@ -133,10 +133,10 @@ void postlightarea(block &a) // median filter, smooths out random noise in li median(r); median(g); median(b); - }; + } remip(a); -}; +} void calclight() { @@ -144,18 +144,18 @@ void calclight() { sqr *s = S(x,y); s->r = s->g = s->b = 10; - }; + } loopv(ents) { entity &e = ents[i]; if(e.type==LIGHT) calclightsource(e); - }; + } block b = { 1, 1, ssize-2, ssize-2 }; postlightarea(b); setvar("fullbright", 0); -}; +} VARP(dynlight, 0, 16, 32); @@ -168,8 +168,8 @@ void cleardlights() block *backup = dlights.pop(); blockpaste(*backup); freeblock(backup); - }; -}; + } +} void dodynlight(vec &vold, vec &v, int reach, int strength, dynent *owner) { @@ -189,7 +189,7 @@ void dodynlight(vec &vold, vec &v, int reach, int strength, dynent *owner) persistent_entity l = { (int)v.x, (int)v.y, (int)v.z, reach, LIGHT, strength, 0, 0 }; calclightsource(l); postlightarea(b); -}; +} // utility functions also used by editing code @@ -200,17 +200,17 @@ block *blockcopy(block &s) sqr *q = (sqr *)(b+1); for(int x = s.x; x1 && ray<3) { dx = -(ray-2); dy = 1; } else if(ray>=3 && ray<5) { dx = -1; dy = -(ray-4); } else if(ray>=5 && ray<7) { dx = ray-6; dy = -1; } - else { dx = 1; dy = ray>4 ? ray-8 : ray; }; + else { dx = 1; dy = ray>4 ? ray-8 : ray; } float sx = vx; float sy = vy; for(;;) @@ -52,21 +52,21 @@ void computeraytable(float vx, float vy) { rdist[i] = (float)(fabs(sx-vx)+fabs(sy-vy)); break; - }; - }; + } + } } else { rdist[i] = 2; - }; - }; -}; + } + } +} // test occlusion for a cube... one of the most computationally expensive functions in the engine // as its done for every cube and entity, but its effect is more than worth it! -inline float ca(float x, float y) { return x>y ? y/x : 2-x/y; }; -inline float ma(float x, float y) { return x==0 ? (y>0 ? 2 : -2) : y/x; }; +inline float ca(float x, float y) { return x>y ? y/x : 2-x/y; } +inline float ma(float x, float y) { return x==0 ? (y>0 ? 2 : -2) : y/x; } int isoccluded(float vx, float vy, float cx, float cy, float csize) // v = viewer, c = cube to test { @@ -98,30 +98,30 @@ int isoccluded(float vx, float vy, float cx, float cy, float csize) // v = v { if(cy<=vy) // AD { - if(cy+csizefloor; float c2 = s->floor; - if(s->type==FHF) { c1 -= d1->vdelta/4.0f; c2 -= d2->vdelta/4.0f; }; + if(s->type==FHF) { c1 -= d1->vdelta/4.0f; c2 -= d2->vdelta/4.0f; } float f1 = s->ceil; float f2 = s->ceil; - if(s->type==CHF) { f1 += d1->vdelta/4.0f; f2 += d2->vdelta/4.0f; }; + if(s->type==CHF) { f1 += d1->vdelta/4.0f; f2 += d2->vdelta/4.0f; } //if(f1-c1<=0 && f2-c2<=0) return; render_square(o->wtex, c1, c2, f1, f2, x1<floor; float f2 = s->floor; @@ -34,7 +34,7 @@ void render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d } if(f1>=c1 && f2>=c2) goto skip; render_square(o->wtex, f1, f2, c1, c2, x1<ceil; @@ -53,8 +53,8 @@ void render_wall(sqr *o, sqr *s, int x1, int y1, int x2, int y2, int mip, sqr *d } if(c1<=f1 && c2<=f2) return; render_square(o->utex, f1, f2, c1, c2, x1<type) { case SEMISOLID: if(issemi(mip, x+x2, y+y2, x1, y1, x2, y2)) return true; case CORNER: case SOLID: break; default: return true; - }; + } return false; -}; +} bool render_floor, render_ceil; @@ -118,7 +118,7 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, for(int ox = x; oxoccluded = isoccluded(camera1->o.x, camera1->o.y, (float)(ox<>mip; int pvy = (int)vy>>mip; @@ -126,7 +126,7 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, { //SWS(w,vxx,vyy,sz)->occluded = 0; SWS(w, pvx, pvy, sz)->occluded = 0; // player cell never occluded - }; + } #define df(x) s->floor-(x->vdelta/4.0f) #define dc(x) s->ceil+(x->vdelta/4.0f) @@ -151,14 +151,14 @@ void render_seg_new(float vx, float vy, float vh, int mip, int x, int y, int xs, while(yydefer && !next->occluded) yy++; // collect 2xN rect of lower mip render_seg_new(vx, vy, vh, mip-1, xx*2, start*2, xx*2+2, yy*2+2); continue; - }; + } stats[mip]++; LOOPD if((s->type==SPACE || s->type==FHF) && s->ceil>=vh && render_ceil) render_flat(s->ctex, xx<ceil, s, t, u, v, true); if(s->type==CHF) //if(s->ceil>=vh) render_flatdelta(s->ctex, xx<ftex, xx<floor, s, t, u, v, false); if(s->floortype==FHF) { render_flatdelta(s->ftex, xx<floor-s->vdelta/4.0fceil-z->floor < t->ceil-t->floor) { if(wv) { render_wall(h1 = s, h2 = v, xx+1, yy, xx, yy+1, mip, t, v, false); topleft = false; } - else { render_wall(h1 = s, h2 = w, xx, yy, xx+1, yy+1, mip, s, u, false); }; + else { render_wall(h1 = s, h2 = w, xx, yy, xx+1, yy+1, mip, s, u, false); } } else { if(wv) { render_wall(h2 = s, h1 = v, xx+1, yy+1, xx, yy, mip, u, s, false); } - else { render_wall(h2 = s, h1 = w, xx, yy+1, xx+1, yy, mip, v, t, false); topleft = false; }; - }; - }; + else { render_wall(h2 = s, h1 = w, xx, yy+1, xx+1, yy, mip, v, t, false); topleft = false; } + } + } render_tris(xx<type!=CORNER) && (v->type!=SEMISOLID || issemi(mip, xx, yy+1, 0, 0, 1, 0))) render_wall(s, v, xx, yy+1, xx+1, yy+1, mip, v, u, true); - }; - }}; + } + }} -}; +} void distlod(int &low, int &high, int angle, float widef) { @@ -246,7 +246,7 @@ void distlod(int &low, int &high, int angle, float widef) high = (int)(angle/f); if(lowMAX_LOD) lod = MAX_LOD; @@ -285,12 +285,12 @@ void render_world(float vx, float vy, float vh, float changelod, int yaw, int pi { lodtop = lod; distlod(lodright, lodleft, yaw<=45 ? yaw+45 : yaw-315, widef); - }; + } float hyfov = fov*h/w/2; render_floor = pitch>MAX_MIP, ssize>>MAX_MIP); mipstats(stats[0], stats[1], stats[2]); -}; +}