Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some warnings and general cleanup #248

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/engine/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2797,8 +2797,10 @@ void explodelist(const char *s, vector<char *> &elems, int limit)
void explodelist(const char *s, std::vector<std::string> &elems, int limit)
{
const char *start, *end;
while((limit < 0 || elems.size() < limit) && parselist(s, start, end))

while ((limit < 0 || elems.size() < static_cast<size_t>(limit)) && parselist(s, start, end)) {
elems.emplace_back(std::string(start, end-start));
}
}

char *indexlist(const char *s, int pos)
Expand Down
8 changes: 4 additions & 4 deletions src/engine/irc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,19 @@ ICOMMAND(0, ircbind, "ss", (const char *name, const char *s), {
ICOMMAND(0, ircpass, "ss", (const char *name, const char *s), {
ircnet *n = ircfind(name);
if(!n) { conoutf("no such ircnet: %s", name); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "current password is: %s", n->passkey && *n->passkey ? "<set>" : "<not set>"); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "current password is: %s", *n->passkey ? "<set>" : "<not set>"); return; }
TheAssassin marked this conversation as resolved.
Show resolved Hide resolved
copystring(n->passkey, s);
});
ICOMMAND(0, ircauthcommand, "ss", (const char *name, const char *s), {
ircnet *n = ircfind(name);
if(!n) { conoutf("no such ircnet: %s", name); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "current auth command is: %s", n->authcommand && *n->authcommand ? "<set>" : "<not set>"); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "current auth command is: %s", *n->authcommand ? "<set>" : "<not set>"); return; }
copystring(n->authcommand, s);
});
ICOMMAND(0, ircauth, "sss", (const char *name, const char *s, const char *t), {
ircnet *n = ircfind(name);
if(!n) { conoutf("no such ircnet: %s", name); return; }
if(!s || !*s || !t || !*t) { ircprintf(n, 4, NULL, "current auth details are: %s (%s)", n->authname, n->authpass && *n->authpass ? "<set>" : "<not set>"); return; }
if(!s || !*s || !t || !*t) { ircprintf(n, 4, NULL, "current auth details are: %s (%s)", n->authname, *n->authpass ? "<set>" : "<not set>"); return; }
copystring(n->authname, s);
copystring(n->authpass, t);
});
Expand Down Expand Up @@ -462,7 +462,7 @@ ICOMMAND(0, ircpasschan, "sss", (const char *name, const char *chan, const char
if(!n) { conoutf("no such ircnet: %s", name); return; }
ircchan *c = ircfindchan(n, chan);
if(!c) { ircprintf(n, 4, NULL, "no such channel: %s", chan); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "channel %s current password is: %s", c->name, c->passkey && *c->passkey ? "<set>" : "<not set>"); return; }
if(!s || !*s) { ircprintf(n, 4, NULL, "channel %s current password is: %s", c->name, *c->passkey ? "<set>" : "<not set>"); return; }
copystring(c->passkey, s);
});
ICOMMAND(0, ircrelaychan, "sss", (const char *name, const char *chan, const char *s), {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// main.cpp: initialisation & main loop
#include "engine.h"
#include <atomic>
#include <signal.h>

string caption = "";
Expand Down Expand Up @@ -115,7 +116,7 @@ void quit() // normal exit
exit(EXIT_SUCCESS);
}

volatile int errors = 0;
TheAssassin marked this conversation as resolved.
Show resolved Hide resolved
std::atomic<unsigned short> errors {0};
void fatal(const char *s, ...) // failure exit
{
if(++errors <= 2) // print up to one extra recursive error
Expand Down
4 changes: 2 additions & 2 deletions src/engine/md3.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct md3 : vertmodel, vertloader<md3>
f->seek(mesh_offset + mheader.ofs_triangles, SEEK_SET);
loopj(m.numtris)
{
md3triangle tri;
md3triangle tri{};
f->read(&tri, sizeof(md3triangle)); // read the triangles
lilswap(tri.vertexindices, 3);
loopk(3) m.tris[j].vert[k] = (ushort)tri.vertexindices[k];
Expand All @@ -109,7 +109,7 @@ struct md3 : vertmodel, vertloader<md3>
f->seek(mesh_offset + mheader.ofs_vertices, SEEK_SET);
loopj(numframes*m.numverts)
{
md3vertex v;
md3vertex v{};
f->read(&v, sizeof(md3vertex)); // read the vertices
lilswap(v.vertex, 4);

Expand Down
4 changes: 2 additions & 2 deletions src/engine/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void resetclipplanes()
clipcacheversion += 2;
if(!clipcacheversion)
{
memset(clipcache, 0, sizeof(clipcache));
*clipcache = {};
clipcacheversion = 2;
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ void resetshadowraycache(ShadowRayCache *cache)
cache->version++;
if(!cache->version)
{
memset(cache->clipcache, 0, sizeof(cache->clipcache));
*cache->clipcache = {};
cache->version = 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/rendertext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static const char *gettklp(const char *str)
return t->blist.search(str, type, "", "", " ", " ", 5);
}

#define defformatkey(dest, key) defformatbigstring((dest), "\fs\fa[\fS\fs\f[%d]%s\fS\fs\fa]\fS", textkeycolour, (key))
#define defformatkey(dest, key) defformatbigstring(dest, "\fs\fa[\fS\fs\f[%d]%s\fS\fs\fa]\fS", textkeycolour, key)

float key_widthf(const char *str)
{
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void visiblecubes(bool cull)
}
else
{
memset(vfcP, 0, sizeof(vfcP));
*vfcP = {};

vfcDfog = 1000000;
memset(vfcDnear, 0, sizeof(vfcDnear));
memset(vfcDfar, 0, sizeof(vfcDfar));
Expand Down Expand Up @@ -1338,11 +1339,10 @@ void renderzpass(renderstate &cur, vtxarray *va)
if(cur.vbuf!=va->vbuf) changevbuf(cur, RENDERPASS_Z, va);
if(!cur.depthmask) { cur.depthmask = true; glDepthMask(GL_TRUE); }
if(cur.colormask) { cur.colormask = false; glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); }
int firsttex = 0, numtris = va->tris;
int numtris = va->tris;
TheAssassin marked this conversation as resolved.
Show resolved Hide resolved
ushort *edata = va->edata;
if(cur.alphaing)
{
firsttex += va->texs + va->blends;
edata += 3*(va->tris + va->blendtris);
numtris = va->alphabacktris + va->alphafronttris;
xtravertsva += 3*numtris;
Expand Down
3 changes: 2 additions & 1 deletion src/engine/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// runs dedicated or as client coroutine

#include "engine.h"
#include <atomic>
#include <signal.h>

#ifdef WIN32
Expand Down Expand Up @@ -1884,7 +1885,7 @@ void shutdownsignal(int signum)
}

#ifdef STANDALONE
volatile int errors = 0;
std::atomic<unsigned short> errors {0};
void fatal(const char *s, ...) // failure exit
{
if(++errors <= 2) // print up to one extra recursive error
Expand Down
2 changes: 0 additions & 2 deletions src/engine/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,15 +2338,13 @@ static void texcombine(Slot &s, int index, Slot::Tex &t, bool forceload = false)
{
vector<char> key;
addname(key, s, t);
int texmask = 0;
if(!forceload) switch(t.type)
{
case TEX_DIFFUSE:
case TEX_NORMAL:
{
int i = findtextype(s, t.type==TEX_DIFFUSE ? (1<<TEX_SPEC) : (1<<TEX_DEPTH));
if(i<0) break;
texmask |= 1<<s.sts[i].type;
s.sts[i].combined = index;
addname(key, s, s.sts[i], true);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum {FIELDCOMMIT, FIELDABORT, FIELDEDIT, FIELDSHOW, FIELDKEY};
static int fieldmode = FIELDSHOW;
static bool fieldsactive = false;

FVAR(IDF_PERSIST, ui_scale, FVAR_NONZERO, 0.00055f, VAR_MAX);
FVAR(IDF_PERSIST, ui_scale, FVAR_NONZERO, 0.00055f, FVAR_MAX);
VAR(IDF_PERSIST, ui_size_skin, 0, 48, VAR_MAX); // 0 = texture size, otherwise = size in pixels for skin scaling
VAR(IDF_PERSIST, ui_size_slider, 1, 58, VAR_MAX);
VAR(IDF_PERSIST, ui_size_separator, 1, 6, VAR_MAX);
Expand Down
9 changes: 6 additions & 3 deletions src/game/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ namespace ai

int weappref(gameent *d)
{
if(d->loadweap.length()) return d->loadweap[0];
if (!d->loadweap.empty()) {
return d->loadweap.front();
}

return m_weapon(d->actortype, game::gamemode, game::mutators);
}

Expand Down Expand Up @@ -229,8 +232,8 @@ namespace ai
if((d->actortype = at) >= A_ENEMY) d->type = ENT_AI;
else
{
d->loadweap.shrink(0);
loopv(lweaps) d->loadweap.add(lweaps[i]);
d->loadweap.clear();
loopv(lweaps) d->loadweap.emplace_back(lweaps[i]);
}
d->setname(name);
d->spawnpoint = et;
Expand Down
6 changes: 3 additions & 3 deletions src/game/aiman.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace aiman
if(skill > m || skill < n) s = (m != n ? botrnd(ci, 2, m-n) + n + 1 : m);
ci->skill = clamp(s, 1, 101);
copystring(ci->name, AA(ci->actortype, vname), MAXNAMELEN);
ci->loadweap.shrink(0);
ci->loadweap.clear();
if(ci->actortype == A_BOT)
{
const char *list = ci->model ? G(botfemalenames) : G(botmalenames);
Expand All @@ -159,7 +159,7 @@ namespace aiman
}
}
ci->setvanity(ci->model ? G(botfemalevanities) : G(botmalevanities));
ci->loadweap.add(botrnd(ci, 8, W_LOADOUT)+W_OFFSET);
ci->loadweap.emplace_back(botrnd(ci, 8, W_LOADOUT)+W_OFFSET);
}
ci->state = CS_DEAD;
ci->team = type == A_BOT ? T_NEUTRAL : T_ENEMY;
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace aiman
else if(ci->aireinit >= 1)
{
if(ci->aireinit == 2) loopk(W_MAX) loopj(2) ci->weapshots[k][j].reset();
sendf(-1, 1, "ri6si3siv", N_INITAI, ci->clientnum, ci->ownernum, ci->actortype, ci->spawnpoint, ci->skill, ci->name, ci->team, ci->colour, ci->model, ci->vanity, ci->loadweap.length(), ci->loadweap.length(), ci->loadweap.getbuf());
sendf(-1, 1, "ri6si3siv", N_INITAI, ci->clientnum, ci->ownernum, ci->actortype, ci->spawnpoint, ci->skill, ci->name, ci->team, ci->colour, ci->model, ci->vanity, ci->loadweap.size(), ci->loadweap.size(), ci->loadweap.data());
if(ci->aireinit == 2)
{
waiting(ci, DROP_RESET);
Expand Down
42 changes: 26 additions & 16 deletions src/game/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ namespace client

void setloadweap(const char *list)
{
vector<int> items;
std::vector<int> items;
TheAssassin marked this conversation as resolved.
Show resolved Hide resolved
if(list && *list)
{
std::vector<std::string> chunk;
Expand All @@ -477,11 +477,18 @@ namespace client
items.emplace_back(v >= W_OFFSET && v < W_ITEM ? v : 0);
}
}
game::player1.loadweap.shrink(0);
loopv(items) if(game::player1.loadweap.find(items[i]) < 0)
{
game::player1.loadweap.add(items[i]);
if(game::player1.loadweap.length() >= W_LOADOUT) break;
game::player1.loadweap.clear();
for (const auto i : items) {
bool no_weap = std::none_of(game::player1.loadweap.begin(),
game::player1.loadweap.end(), [=](auto d) { return d == i; });

if (no_weap) {
game::player1.loadweap.emplace_back(i);

if (game::player1.loadweap.size() >= W_LOADOUT) {
break;
}
}
}
sendplayerinfo = true;
}
Expand All @@ -501,18 +508,21 @@ namespace client
items.emplace_back(v != 0 ? 1 : 0);
}
}
game::player1.randweap.shrink(0);
game::player1.randweap.clear();
loopv(items)
{
game::player1.randweap.add(items[i]);
if(game::player1.randweap.length() >= W_LOADOUT) break;
game::player1.randweap.emplace_back(items[i]);

if (game::player1.randweap.size() >= W_LOADOUT) {
break;
}
}
sendplayerinfo = true;
}
SVARF(IDF_PERSIST, playerrandweap, "", setrandweap(playerrandweap));

ICOMMAND(0, getrandweap, "i", (int *n), intret(game::player1.randweap.inrange(*n) ? game::player1.randweap[*n] : 1));
ICOMMAND(0, getloadweap, "i", (int *n), intret(game::player1.loadweap.inrange(*n) ? game::player1.loadweap[*n] : -1));
ICOMMAND(0, getrandweap, "i", (int *n), intret(inrange(game::player1.randweap, *n) ? game::player1.randweap[*n] : 1));
ICOMMAND(0, getloadweap, "i", (int *n), intret(inrange(game::player1.loadweap, *n) ? game::player1.loadweap[*n] : -1));
ICOMMAND(0, allowedweap, "i", (int *n), intret(isweap(*n) && m_check(W(*n, modes), W(*n, muts), game::gamemode, game::mutators) && !W(*n, disabled) ? 1 : 0));
ICOMMAND(0, hasloadweap, "bb", (int *g, int *m), intret(m_loadout(m_game(*g) ? *g : game::gamemode, *m >= 0 ? *m : game::mutators) ? 1 : 0));

Expand Down Expand Up @@ -722,7 +732,7 @@ namespace client
int getclientloadweap(int cn, int n)
{
gameent *d = game::getclient(cn);
return d ? (d->loadweap.inrange(n) ? d->loadweap[n] : 0) : -1;
return d ? (inrange(d->loadweap, n) ? d->loadweap[n] : 0) : -1;
}
ICOMMAND(0, getclientloadweap, "si", (char *who, int *n), intret(getclientloadweap(parsewho(who), *n)));

Expand Down Expand Up @@ -1668,9 +1678,9 @@ namespace client
putint(p, game::player1.colour);
putint(p, game::player1.model);
sendstring(game::player1.vanity, p);
putint(p, game::player1.loadweap.length());
putint(p, game::player1.loadweap.size());
loopv(game::player1.loadweap) putint(p, game::player1.loadweap[i]);
putint(p, game::player1.randweap.length());
putint(p, game::player1.randweap.size());
loopv(game::player1.randweap) putint(p, game::player1.randweap[i]);

string hash = "";
Expand Down Expand Up @@ -1802,9 +1812,9 @@ namespace client
putint(p, game::player1.model);
putint(p, game::player1.checkpointspawn);
sendstring(game::player1.vanity, p);
putint(p, game::player1.loadweap.length());
putint(p, game::player1.loadweap.size());
loopv(game::player1.loadweap) putint(p, game::player1.loadweap[i]);
putint(p, game::player1.randweap.length());
putint(p, game::player1.randweap.size());
loopv(game::player1.randweap) putint(p, game::player1.randweap[i]);
}
if(sendcrcinfo)
Expand Down
25 changes: 17 additions & 8 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,14 +700,23 @@ namespace game

bool tvmode(bool check, bool force)
{
if(!m_edit(gamemode) && (!check || !cameras.empty()))
{
if(!gs_playing(gamestate) && intermmode) return true;
else switch(player1.state)
{
case CS_SPECTATOR: if(specmode || (force && focus != &player1 && followmode && followaim())) return true; break;
case CS_WAITING: if((waitmode && (!player1.lastdeath || lastmillis-player1.lastdeath >= 500)) || (force && focus != &player1 && followmode && followaim())) return true; break;
default: break;
if (!m_edit(gamemode) && (!check || !cameras.empty())) {
if (!gs_playing(gamestate) && intermmode) {
return true;
} else switch(player1.state) {
case CS_SPECTATOR:
if (specmode || (force && focus != &player1 && followmode && followaim())) {
return true;
}
break;
case CS_WAITING:
if ((waitmode && (!player1.lastdeath || lastmillis-player1.lastdeath >= 500)) ||
(force && focus != &player1 && followmode && followaim())) {
return true;
}
break;
default:
break;
}
}
return false;
Expand Down
Loading