Fix various warnings that had piled up

This commit is contained in:
Tamás Bálint Misius 2023-05-12 18:02:23 +02:00
parent 9bd8bd2274
commit d8acdfb576
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
12 changed files with 29 additions and 30 deletions

View File

@ -1353,7 +1353,7 @@ void GameSave::readPSv(const std::vector<char> &dataVec)
if (p >= dataLength) if (p >= dataLength)
throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
auto j=data[p++]; auto j=data[p++];
if (j >= PT_NUM) { if (int(j) >= PT_NUM) { // not possible these days since PMAPBITS >= 8
j = PT_DUST;//throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); j = PT_DUST;//throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__));
} }
if (j) if (j)

View File

@ -123,7 +123,7 @@ void VideoBuffer::Resize(Vec2<int> size, bool resample)
void VideoBuffer::Resize(float factor, bool resample) void VideoBuffer::Resize(float factor, bool resample)
{ {
Resize(Vec2<int>(Size() * factor), resample); Resize(Vec2{ int(Size().X * factor), int(Size().Y * factor) }, resample);
} }
void VideoBuffer::ResizeToFit(Vec2<int> bound, bool resample) void VideoBuffer::ResizeToFit(Vec2<int> bound, bool resample)
@ -135,9 +135,9 @@ void VideoBuffer::ResizeToFit(Vec2<int> bound, bool resample)
return a / b + ((a % b) ? 1 : 0); return a / b + ((a % b) ? 1 : 0);
}; };
if (bound.X * size.Y < bound.Y * size.X) if (bound.X * size.Y < bound.Y * size.X)
size = { ceilDiv(size.X * bound.X, size.X), ceilDiv(size.Y * bound.X, size.X) }; size = { bound.X, ceilDiv(size.Y * bound.X, size.X) };
else else
size = { ceilDiv(size.X * bound.Y, size.Y), ceilDiv(size.Y * bound.Y, size.Y) }; size = { ceilDiv(size.X * bound.Y, size.Y), bound.Y };
} }
Resize(size, resample); Resize(size, resample);
} }
@ -165,7 +165,7 @@ std::vector<char> VideoBuffer::ToPPM() const
return format::PixelsToPPM(video); return format::PixelsToPPM(video);
} }
template class RasterDrawMethods<VideoBuffer>; template struct RasterDrawMethods<VideoBuffer>;
Graphics::Graphics() Graphics::Graphics()
{} {}
@ -483,7 +483,7 @@ std::vector<RGB<uint8_t>> Graphics::Gradient(std::vector<GradientStop> stops, in
auto &left = stops[stop]; auto &left = stops[stop];
auto &right = stops[stop + 1]; auto &right = stops[stop + 1];
auto f = (point - left.point) / (right.point - left.point); auto f = (point - left.point) / (right.point - left.point);
table[i] = left.color.Blend(right.color.WithAlpha(f * 0xFF)); table[i] = left.color.Blend(right.color.WithAlpha(uint8_t(f * 0xFF)));
} }
} }
return table; return table;

View File

@ -9,4 +9,4 @@ void Graphics::Finalise()
} }
template class RasterDrawMethods<Graphics>; template struct RasterDrawMethods<Graphics>;

View File

@ -9,9 +9,6 @@
#include "simulation/gravity/Gravity.h" #include "simulation/gravity/Gravity.h"
#include <cmath> #include <cmath>
constexpr auto VIDXRES = WINDOWW;
// constexpr auto VIDYRES = WINDOWH; // not actually used anywhere
std::unique_ptr<VideoBuffer> Renderer::WallIcon(int wallID, Vec2<int> size) std::unique_ptr<VideoBuffer> Renderer::WallIcon(int wallID, Vec2<int> size)
{ {
auto wtypes = LoadWalls(); auto wtypes = LoadWalls();
@ -1191,8 +1188,8 @@ int HeatToColour(float temp)
constexpr float min_temp = MIN_TEMP; constexpr float min_temp = MIN_TEMP;
constexpr float max_temp = MAX_TEMP; constexpr float max_temp = MAX_TEMP;
RGB<uint8_t> color = Renderer::heatTableAt(int((temp - min_temp) / (max_temp - min_temp) * 1024)); RGB<uint8_t> color = Renderer::heatTableAt(int((temp - min_temp) / (max_temp - min_temp) * 1024));
color.Red *= 0.7f; color.Red = uint8_t(color.Red * 0.7f);
color.Green *= 0.7f; color.Green = uint8_t(color.Green * 0.7f);
color.Blue *= 0.7f; color.Blue = uint8_t(color.Blue * 0.7f);
return color.Pack(); return color.Pack();
} }

View File

@ -472,4 +472,4 @@ Renderer::~Renderer()
delete[] graphicscache; delete[] graphicscache;
} }
template class RasterDrawMethods<Renderer>; template struct RasterDrawMethods<Renderer>;

View File

@ -572,7 +572,7 @@ bool GameController::TextEditing(String text)
bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
bool ret = commandInterface->HandleEvent(KeyPressEvent{ key, scan, repeat, shift, ctrl, alt }); bool ret = commandInterface->HandleEvent(KeyPressEvent{ { key, scan, repeat, shift, ctrl, alt } });
if (repeat) if (repeat)
return ret; return ret;
if (ret) if (ret)
@ -651,7 +651,7 @@ bool GameController::KeyPress(int key, int scan, bool repeat, bool shift, bool c
bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt) bool GameController::KeyRelease(int key, int scan, bool repeat, bool shift, bool ctrl, bool alt)
{ {
bool ret = commandInterface->HandleEvent(KeyReleaseEvent{ key, scan, repeat, shift, ctrl, alt }); bool ret = commandInterface->HandleEvent(KeyReleaseEvent{ { key, scan, repeat, shift, ctrl, alt } });
if (repeat) if (repeat)
return ret; return ret;
if (ret) if (ret)

View File

@ -181,7 +181,7 @@ void Engine::Draw()
if (frozen.fadeTicks <= maxFadeTicks) if (frozen.fadeTicks <= maxFadeTicks)
{ {
// from 0x00 at 0 to about 0x54 at 20 // from 0x00 at 0 to about 0x54 at 20
uint8_t alpha = (1 - std::pow(0.98, frozen.fadeTicks)) * 0xFF; auto alpha = uint8_t((1 - std::pow(0.98, frozen.fadeTicks)) * 0xFF);
g->BlendFilledRect(g->Size().OriginRect(), 0x000000_rgb .WithAlpha(alpha)); g->BlendFilledRect(g->Size().OriginRect(), 0x000000_rgb .WithAlpha(alpha));
} }
// If this is the last frame in the fade, save what the faded image looks like // If this is the last frame in the fade, save what the faded image looks like

View File

@ -151,7 +151,7 @@ private:
char buff[32]; char buff[32];
userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1)); userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
T *obj = ud->pT; T *obj = ud->pT;
sprintf(buff, "%p", obj); snprintf(buff, sizeof(buff), "%p", obj);
lua_pushfstring(L, "%s (%s)", T::className, buff); lua_pushfstring(L, "%s (%s)", T::className, buff);
return 1; return 1;
} }

View File

@ -1860,7 +1860,7 @@ int LuaScriptInterface::simulation_decoColor(lua_State * l)
return 1; return 1;
} }
else if (acount == 1) else if (acount == 1)
color = RGBA<uint8_t>::Unpack(luaL_optnumber(l, 1, 0xFFFF0000)); color = RGBA<uint8_t>::Unpack(pixel_rgba(luaL_optnumber(l, 1, 0xFFFF0000)));
else else
{ {
color.Red = std::clamp(luaL_optint(l, 1, 255), 0, 255); color.Red = std::clamp(luaL_optint(l, 1, 255), 0, 255);
@ -2277,7 +2277,7 @@ int LuaScriptInterface::simulation_brush(lua_State * l)
std::vector<ui::Point> points; std::vector<ui::Point> points;
std::copy(newBrush->begin(), newBrush->end(), std::back_inserter(points)); std::copy(newBrush->begin(), newBrush->end(), std::back_inserter(points));
lua_pushnumber(l, 0); // index lua_pushnumber(l, 0); // index
lua_pushnumber(l, points.size()); lua_pushnumber(l, int(points.size()));
auto points_ud = reinterpret_cast<ui::Point *>(lua_newuserdata(l, points.size() * sizeof(ui::Point))); auto points_ud = reinterpret_cast<ui::Point *>(lua_newuserdata(l, points.size() * sizeof(ui::Point)));
std::copy(points.begin(), points.end(), points_ud); std::copy(points.begin(), points.end(), points_ud);

View File

@ -765,7 +765,7 @@ bool Simulation::flood_water(int x, int y, int i)
else if (!eval_move(parts[i].type, x, y - 1, nullptr)) else if (!eval_move(parts[i].type, x, y - 1, nullptr))
continue; continue;
move(i, originalX, originalY, x, y - 1); move(i, originalX, originalY, float(x), float(y - 1));
return true; return true;
} }
@ -2287,7 +2287,7 @@ void Simulation::delete_part(int x, int y)//calls kill_part with the particle lo
void Simulation::UpdateParticles(int start, int end) void Simulation::UpdateParticles(int start, int end)
{ {
int i, j, x, y, t, nx, ny, r, surround_space, s, rt, nt; int i, j, x, y, t, r, surround_space, s, rt, nt;
float mv, dx, dy, nrx, nry, dp, ctemph, ctempl, gravtot; float mv, dx, dy, nrx, nry, dp, ctemph, ctempl, gravtot;
int fin_x, fin_y, clear_x, clear_y, stagnant; int fin_x, fin_y, clear_x, clear_y, stagnant;
float fin_xf, fin_yf, clear_xf, clear_yf; float fin_xf, fin_yf, clear_xf, clear_yf;
@ -2406,8 +2406,8 @@ void Simulation::UpdateParticles(int start, int end)
transitionOccurred = false; transitionOccurred = false;
j = surround_space = nt = 0;//if nt is greater than 1 after this, then there is a particle around the current particle, that is NOT the current particle's type, for water movement. j = surround_space = nt = 0;//if nt is greater than 1 after this, then there is a particle around the current particle, that is NOT the current particle's type, for water movement.
for (nx=-1; nx<2; nx++) for (auto nx=-1; nx<2; nx++)
for (ny=-1; ny<2; ny++) { for (auto ny=-1; ny<2; ny++) {
if (nx||ny) { if (nx||ny) {
surround[j] = r = pmap[y+ny][x+nx]; surround[j] = r = pmap[y+ny][x+nx];
j++; j++;
@ -2804,14 +2804,14 @@ void Simulation::UpdateParticles(int start, int end)
//spark updates from walls //spark updates from walls
if ((elements[t].Properties&PROP_CONDUCTS) || t==PT_SPRK) if ((elements[t].Properties&PROP_CONDUCTS) || t==PT_SPRK)
{ {
nx = x % CELL; auto nx = x % CELL;
if (nx == 0) if (nx == 0)
nx = x/CELL - 1; nx = x/CELL - 1;
else if (nx == CELL-1) else if (nx == CELL-1)
nx = x/CELL + 1; nx = x/CELL + 1;
else else
nx = x/CELL; nx = x/CELL;
ny = y % CELL; auto ny = y % CELL;
if (ny == 0) if (ny == 0)
ny = y/CELL - 1; ny = y/CELL - 1;
else if (ny == CELL-1) else if (ny == CELL-1)
@ -3300,6 +3300,7 @@ killed:
if (t==PT_GEL) if (t==PT_GEL)
rt = int(parts[i].tmp*0.20f+5.0f); rt = int(parts[i].tmp*0.20f+5.0f);
auto nx = -1, ny = -1;
for (j=clear_x+r; j>=0 && j>=clear_x-rt && j<clear_x+rt && j<XRES; j+=r) for (j=clear_x+r; j>=0 && j>=clear_x-rt && j<clear_x+rt && j<XRES; j+=r)
{ {
if ((TYP(pmap[fin_y][j])!=t || bmap[fin_y/CELL][j/CELL]) if ((TYP(pmap[fin_y][j])!=t || bmap[fin_y/CELL][j/CELL])
@ -3348,8 +3349,8 @@ killed:
// clear_xf, clear_yf is the last known position that the particle should almost certainly be able to move to // clear_xf, clear_yf is the last known position that the particle should almost certainly be able to move to
nxf = clear_xf; nxf = clear_xf;
nyf = clear_yf; nyf = clear_yf;
nx = clear_x; auto nx = clear_x;
ny = clear_y; auto ny = clear_y;
// Look for spaces to move horizontally (perpendicular to gravity direction), keep going until a space is found or the number of positions examined = rt // Look for spaces to move horizontally (perpendicular to gravity direction), keep going until a space is found or the number of positions examined = rt
for (j=0;j<rt;j++) for (j=0;j<rt;j++)
{ {

View File

@ -71,7 +71,7 @@ static int update(UPDATE_FUNC_ARGS)
} }
playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp]; playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp];
int tarx, tary; int tarx = 0, tary = 0;
parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man

View File

@ -49,7 +49,7 @@ void Element::Element_SING()
static int update(UPDATE_FUNC_ARGS) static int update(UPDATE_FUNC_ARGS)
{ {
int r, rx, ry, cry, crx, nb, spawncount; int r, rx, ry, cry, crx, spawncount;
int singularity = -parts[i].life; int singularity = -parts[i].life;
float angle, v; float angle, v;
@ -80,6 +80,7 @@ static int update(UPDATE_FUNC_ARGS)
spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*TPT_PI_FLT); spawncount = (spawncount>255) ? 3019 : int(std::pow((double)(spawncount/8), 2)*TPT_PI_FLT);
for (int j = 0;j < spawncount; j++) for (int j = 0;j < spawncount; j++)
{ {
auto nb = -1;
switch (sim->rng.gen() % 3) switch (sim->rng.gen() % 3)
{ {
case 0: case 0: