From 3b05838c823f3d8aad29f46d1439f28bdc974f10 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 14 Aug 2008 08:58:07 +0000 Subject: [PATCH] gcc 4.3 warning/bug fixes git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2320 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/bot/bot_waypoint.cpp | 8 ++++---- source/src/editing.cpp | 8 ++++---- source/src/entities.cpp | 15 ++++++++++----- source/src/md2.h | 4 ++-- source/src/physics.cpp | 13 ++++++++----- source/src/protocol.h | 2 +- source/src/server.cpp | 24 +++++++++++++++--------- source/src/sound.cpp | 2 +- source/src/tools.cpp | 4 ++-- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/source/src/bot/bot_waypoint.cpp b/source/src/bot/bot_waypoint.cpp index 41490679..428ce562 100644 --- a/source/src/bot/bot_waypoint.cpp +++ b/source/src/bot/bot_waypoint.cpp @@ -108,10 +108,10 @@ bool CWaypointClass::LoadWaypoints() { fread(&header, sizeof(header), 1, bfp); - header.szFileType[10] = 0; + memset(header.szFileType, 0, sizeof(header.szFileType)); if (strcmp(header.szFileType, "cube_bot") == 0) { - header.szMapName[31] = 0; + memset(header.szMapName, 0, sizeof(header.szMapName)); if (strcmp(header.szMapName, m_szMapName) == 0) { @@ -392,10 +392,10 @@ bool CWaypointClass::LoadWPExpFile() { fread(&header, sizeof(header), 1, bfp); - header.szFileType[10] = 0; + memset(header.szFileType, 0, sizeof(header.szFileType)); if (strcmp(header.szFileType, "cube_bot") == 0) { - header.szMapName[31] = 0; + memset(header.szMapName, 0, sizeof(header.szMapName)); if (strcmp(header.szMapName, m_szMapName) == 0) { diff --git a/source/src/editing.cpp b/source/src/editing.cpp index f3286407..39886122 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -167,9 +167,9 @@ void cursorupdate() // called every frame fr box(b, h1, h2, h3, h4); linestyle(GRID8, 0x40, 0x40, 0xFF); if(!(ix&GRIDM)) line(ix, iy, h1, ix, iy+1, h4); - if(!(ix+1&GRIDM)) line(ix+1, iy, h2, ix+1, iy+1, h3); + 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(!((iy+1)&GRIDM)) line(ix, iy+1, h4, ix+1, iy+1, h3); } if(!SOLID(s)) @@ -259,7 +259,7 @@ void tofronttex() // maintain most recentl void editdrag(bool isdown) { - if(dragging = isdown) + if((dragging = isdown)) { lastx = cx; lasty = cy; @@ -349,7 +349,7 @@ void edittypexy(int type, block &sel) void edittype(int type) { EDITSEL; - if(type==CORNER && (sel.xs!=sel.ys || sel.xs==3 || sel.xs>4 && sel.xs!=8 + 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; } edittypexy(type, sel); diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 11217183..12124dbf 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -28,12 +28,15 @@ void renderent(entity &e, const char *mdlname, float z, float yaw, int anim = AN void renderentities() { - if(editmode) loopv(ents) + if(editmode) { - entity &e = ents[i]; - if(e.type==NOTUSED) continue; - vec v(e.x, e.y, e.z); - particle_splash(2, 2, 40, v); + loopv(ents) + { + entity &e = ents[i]; + if(e.type==NOTUSED) continue; + vec v(e.x, e.y, e.z); + particle_splash(2, 2, 40, v); + } } loopv(ents) { @@ -188,12 +191,14 @@ void resetspawns() { loopv(ents) ents[i].spawned = false; if(m_noitemsnade || m_pistol) + { loopv(ents) { entity &e = ents[i]; 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; } diff --git a/source/src/md2.h b/source/src/md2.h index 9e164be3..aae83660 100644 --- a/source/src/md2.h +++ b/source/src/md2.h @@ -51,8 +51,8 @@ struct md2 : vertmodel for(int *command = glcommands; (*command)!=0;) { int numvertex = *command++; - bool isfan; - if(isfan = (numvertex<0)) numvertex = -numvertex; + bool isfan = numvertex<0; + if(isfan) numvertex = -numvertex; idxs.setsizenodelete(0); loopi(numvertex) { diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 610c1540..0f4a0f3a 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -160,10 +160,10 @@ bool collide(physent *d, bool spawn, float drop, float rise) case CORNER: { int bx = x, by = y, bs = 1; - if(x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs - || x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by - || x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by - || x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs) + if((x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs) + || (x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by) + || (x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by) + || (x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs)) return false; break; } @@ -470,7 +470,10 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) pl->pitchvel *= fric-3; pl->pitchvel /= fric; extern int recoiltest; - if(recoiltest) if(pl->pitchvel < 0.05f && pl->pitchvel > 0.001f) pl->pitchvel -= recoilbackfade/100.0f; // slide back + if(recoiltest) + { + if(pl->pitchvel < 0.05f && pl->pitchvel > 0.001f) pl->pitchvel -= recoilbackfade/100.0f; // slide back + } else if(pl->pitchvel < 0.05f && pl->pitchvel > 0.001f) pl->pitchvel -= ((playerent *)pl)->weaponsel->info.recoilbackfade/100.0f; // slide back if(pl->pitchvel) fixcamerarange(pl); // fix pitch if necessary } diff --git a/source/src/protocol.h b/source/src/protocol.h index 77b5f412..a0044546 100644 --- a/source/src/protocol.h +++ b/source/src/protocol.h @@ -87,6 +87,6 @@ enum #define m_teammode (gamemode==0 || gamemode==4 || gamemode==5 || gamemode==7 || gamemode==11) #define m_tarena (m_arena && m_teammode) #define m_botmode (gamemode==7 || gamemode == 8 || gamemode==12) -#define m_valid(mode) ((mode)>=0 && (mode)<=12 || (mode) == -3) +#define m_valid(mode) (((mode)>=0 && (mode)<=12) || (mode) == -3) #define m_mp(mode) (m_valid(mode) && (mode)!=7 && (mode)!=8 && (mode)!=12) #define m_demo (gamemode==-3) diff --git a/source/src/server.cpp b/source/src/server.cpp index 20ad8461..ce794a8d 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -411,15 +411,18 @@ int freeteam() savedscore *findscore(client &c, bool insert) { if(c.type!=ST_TCPIP) return NULL; - if(!insert) loopv(clients) + if(!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)) + loopv(clients) { - static savedscore curscore; - curscore.save(o.state); - return &curscore; + 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)) + { + static savedscore curscore; + curscore.save(o.state); + return &curscore; + } } } loopv(scores) @@ -1258,7 +1261,10 @@ void changeclientrole(int client, int role, char *pwd = NULL, bool force=false) if(force || role == CR_DEFAULT || (role == CR_ADMIN && pwd && pwd[0] && adminpasswd && !strcmp(adminpasswd, pwd))) { if(role == clients[client]->role) return; - if(role > CR_DEFAULT) loopv(clients) clients[i]->role = CR_DEFAULT; + if(role > CR_DEFAULT) + { + loopv(clients) clients[i]->role = CR_DEFAULT; + } clients[client]->role = role; sendserveropinfo(-1); logger->writeline(log::info,"[%s] set role of player %s to %s", clients[client]->hostname, clients[client]->name[0] ? clients[client]->name : "[unnamed]", role == CR_ADMIN ? "admin" : "normal player"); // flowtron : connecting players haven't got a name yet (connectadmin) @@ -2333,7 +2339,7 @@ void initserver(bool dedicated, int uprate, const char *sdesc, const char *ip, i if(dedicated) logger->open(); // log on ded servers only logger->writeline(log::info, "logging local AssaultCube server now.."); - if(isdedicated = dedicated) + if((isdedicated = dedicated)) { ENetAddress address = { ENET_HOST_ANY, serverport }; if(*ip && enet_address_set_host(&address, ip)<0) logger->writeline(log::warning, "server ip not resolved!"); diff --git a/source/src/sound.cpp b/source/src/sound.cpp index 2b86a07f..f05e9600 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -734,7 +734,7 @@ struct oggstream : sourceowner if(playing()) return true; this->looping = looping; if(!stream(bufferids[0]) || !stream(bufferids[1])) return false; - if(startmillis == endmillis == startfademillis == endfademillis == 0) setgain(1.0f); + if(!startmillis && !endmillis && !startfademillis && !endfademillis) setgain(1.0f); updategain(); src->queuebuffers(2, bufferids); diff --git a/source/src/tools.cpp b/source/src/tools.cpp index a41b14b2..ae68d95c 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -141,7 +141,7 @@ FILE *openfile(const char *filename, const char *mode) { const char *found = findfile(filename, mode); #ifndef STANDALONE - if(mode && mode[0]=='w' || mode[0]=='a') conoutf("writing to file: %s", found); + if(mode && (mode[0]=='w' || mode[0]=='a')) conoutf("writing to file: %s", found); #endif if(!found) return NULL; return fopen(found, mode); @@ -151,7 +151,7 @@ gzFile opengzfile(const char *filename, const char *mode) { const char *found = findfile(filename, mode); #ifndef STANDALONE - if(mode && mode[0]=='w' || mode[0]=='a') conoutf("writing to file: %s", found); + if(mode && (mode[0]=='w' || mode[0]=='a')) conoutf("writing to file: %s", found); #endif if(!found) return NULL; return gzopen(found, mode);