Browse Source

Fix a few -Wsign-compare warnings

pull/6932/head
Gleb Mazovetskiy 2 years ago
parent
commit
25c1c5b372
  1. 4
      Source/lighting.cpp
  2. 18
      Source/loadsave.cpp
  3. 18
      Source/monster.cpp
  4. 2
      Source/monster.h
  5. 2
      Source/msg.cpp
  6. 4
      Source/portal.cpp
  7. 21
      Source/sync.cpp

4
Source/lighting.cpp

@ -362,7 +362,7 @@ void MakeLightTable()
} else if (IsAnyOf(leveltype, DTYPE_NEST, DTYPE_CRYPT)) {
// Make the lava fully bright
for (auto &lightTable : LightTables)
std::iota(lightTable.begin(), lightTable.begin() + 16, 0);
std::iota(lightTable.begin(), lightTable.begin() + 16, uint8_t { 0 });
LightTables[15][0] = 0;
std::fill_n(LightTables[15].begin() + 1, 15, 1);
}
@ -438,7 +438,7 @@ void InitLighting()
DisableLighting = false;
#endif
std::iota(ActiveLights.begin(), ActiveLights.end(), 0);
std::iota(ActiveLights.begin(), ActiveLights.end(), uint8_t { 0 });
VisionActive = {};
TransList = {};
}

18
Source/loadsave.cpp

@ -1002,7 +1002,7 @@ void LoadDroppedItems(LoadHelper &file, size_t savedItemCount)
file.Skip<uint8_t>(MAXITEMS * 2);
// Reset ActiveItems, the Items array will be populated from the start
std::iota(ActiveItems, ActiveItems + MAXITEMS, 0);
std::iota(ActiveItems, ActiveItems + MAXITEMS, uint8_t { 0 });
ActiveItemCount = 0;
// Clear dItem so we can populate valid drop locations
memset(dItem, 0, sizeof(dItem));
@ -2171,8 +2171,8 @@ void LoadGame(bool firstflag)
// skip ahead for vanilla save compatibility (Related to bugfix where MonsterKillCounts[MaxMonsters] was changed to MonsterKillCounts[NUM_MTYPES]
file.Skip(4 * (MaxMonsters - NUM_MTYPES));
if (leveltype != DTYPE_TOWN) {
for (int &monsterId : ActiveMonsters)
monsterId = file.NextBE<int32_t>();
for (unsigned &monsterId : ActiveMonsters)
monsterId = file.NextBE<uint32_t>();
for (size_t i = 0; i < ActiveMonsterCount; i++)
LoadMonster(&file, Monsters[ActiveMonsters[i]]);
for (size_t i = 0; i < ActiveMonsterCount; i++)
@ -2435,8 +2435,8 @@ void SaveGameData(SaveWriter &saveWriter)
file.Skip(4 * (MaxMonsters - NUM_MTYPES));
if (leveltype != DTYPE_TOWN) {
for (int monsterId : ActiveMonsters)
file.WriteBE<int32_t>(monsterId);
for (unsigned monsterId : ActiveMonsters)
file.WriteBE<uint32_t>(monsterId);
for (size_t i = 0; i < ActiveMonsterCount; i++)
SaveMonster(&file, Monsters[ActiveMonsters[i]]);
// Write ActiveMissiles
@ -2572,8 +2572,8 @@ void SaveLevel(SaveWriter &saveWriter)
file.WriteBE<int32_t>(ActiveObjectCount);
if (leveltype != DTYPE_TOWN) {
for (int monsterId : ActiveMonsters)
file.WriteBE<int32_t>(monsterId);
for (unsigned monsterId : ActiveMonsters)
file.WriteBE<uint32_t>(monsterId);
for (size_t i = 0; i < ActiveMonsterCount; i++)
SaveMonster(&file, Monsters[ActiveMonsters[i]]);
for (int objectId : ActiveObjects)
@ -2646,8 +2646,8 @@ void LoadLevel()
ActiveObjectCount = file.NextBE<int32_t>();
if (leveltype != DTYPE_TOWN) {
for (int &monsterId : ActiveMonsters)
monsterId = file.NextBE<int32_t>();
for (unsigned &monsterId : ActiveMonsters)
monsterId = file.NextBE<uint32_t>();
for (size_t i = 0; i < ActiveMonsterCount; i++) {
Monster &monster = Monsters[ActiveMonsters[i]];
LoadMonster(&file, monster);

18
Source/monster.cpp

@ -11,6 +11,7 @@
#include <algorithm>
#include <array>
#include <numeric>
#include <string_view>
#include <fmt/core.h>
@ -57,7 +58,7 @@ namespace devilution {
CMonster LevelMonsterTypes[MaxLvlMTypes];
size_t LevelMonsterTypeCount;
Monster Monsters[MaxMonsters];
int ActiveMonsters[MaxMonsters];
unsigned ActiveMonsters[MaxMonsters];
size_t ActiveMonsterCount;
/** Tracks the total number of monsters killed per monster_id. */
int MonsterKillCounts[NUM_MTYPES];
@ -631,7 +632,7 @@ void UpdateEnemy(Monster &monster)
}
}
for (size_t i = 0; i < ActiveMonsterCount; i++) {
const int monsterId = ActiveMonsters[i];
const unsigned monsterId = ActiveMonsters[i];
Monster &otherMonster = Monsters[monsterId];
if (&otherMonster == &monster)
continue;
@ -659,7 +660,7 @@ void UpdateEnemy(Monster &monster)
|| ((sameroom || !bestsameroom) && dist < bestDist)
|| (menemy == -1)) {
monster.flags |= MFLAG_TARGETS_MONSTER;
menemy = monsterId;
menemy = static_cast<int>(monsterId);
target = otherMonster.position.future;
bestDist = dist;
bestsameroom = sameroom;
@ -3143,8 +3144,8 @@ void EnsureMonsterIndexIsActive(size_t monsterId)
continue;
if (index < ActiveMonsterCount)
return; // monster is already active
int oldId = ActiveMonsters[ActiveMonsterCount];
ActiveMonsters[ActiveMonsterCount] = static_cast<int>(monsterId);
const unsigned oldId = ActiveMonsters[ActiveMonsterCount];
ActiveMonsters[ActiveMonsterCount] = static_cast<unsigned>(monsterId);
ActiveMonsters[index] = oldId;
ActiveMonsterCount += 1;
}
@ -3292,10 +3293,7 @@ void InitLevelMonsters()
ActiveMonsterCount = 0;
totalmonsters = MaxMonsters;
for (size_t i = 0; i < MaxMonsters; i++) {
ActiveMonsters[i] = static_cast<int>(i);
}
std::iota(std::begin(ActiveMonsters), std::end(ActiveMonsters), 0u);
uniquetrans = 0;
}
@ -4081,7 +4079,7 @@ void DeleteMonsterList()
for (size_t i = MAX_PLRS; i < ActiveMonsterCount;) {
if (Monsters[ActiveMonsters[i]].isInvalid) {
if (pcursmonst == ActiveMonsters[i]) // Unselect monster if player highlighted it
if (pcursmonst == static_cast<int>(ActiveMonsters[i])) // Unselect monster if player highlighted it
pcursmonst = -1;
DeleteMonster(i);
} else {

2
Source/monster.h

@ -474,7 +474,7 @@ struct Monster { // note: missing field _mAFNum
extern size_t LevelMonsterTypeCount;
extern Monster Monsters[MaxMonsters];
extern int ActiveMonsters[MaxMonsters];
extern unsigned ActiveMonsters[MaxMonsters];
extern size_t ActiveMonsterCount;
extern int MonsterKillCounts[NUM_MTYPES];
extern bool sgbSaveSoundOn;

2
Source/msg.cpp

@ -757,7 +757,7 @@ void DeltaLeaveSync(uint8_t bLevel)
DLevel &deltaLevel = GetDeltaLevel(bLevel);
for (size_t i = 0; i < ActiveMonsterCount; i++) {
int ma = ActiveMonsters[i];
const unsigned ma = ActiveMonsters[i];
auto &monster = Monsters[ma];
if (monster.hitPoints == 0)
continue;

4
Source/portal.cpp

@ -112,9 +112,9 @@ bool PortalOnLevel(const Player &player)
void RemovePortalMissile(const Player &player)
{
size_t id = player.getId();
const size_t id = player.getId();
Missiles.remove_if([id](Missile &missile) {
if (missile._mitype == MissileID::TownPortal && missile._misource == id) {
if (missile._mitype == MissileID::TownPortal && missile._misource == static_cast<int>(id)) {
dFlags[missile.position.tile.x][missile.position.tile.y] &= ~DungeonFlag::Missile;
if (Portals[id].level != 0)

21
Source/sync.cpp

@ -3,9 +3,10 @@
*
* Implementation of functionality for syncing game state with other players.
*/
#include <climits>
#include <cstdint>
#include <limits>
#include "levels/gendung.h"
#include "lighting.h"
#include "monster.h"
@ -24,7 +25,7 @@ int sgnSyncPInv;
void SyncOneMonster()
{
for (size_t i = 0; i < ActiveMonsterCount; i++) {
int m = ActiveMonsters[i];
const unsigned m = ActiveMonsters[i];
auto &monster = Monsters[m];
sgnMonsterPriority[m] = MyPlayer->position.tile.ManhattanDistance(monster.position.tile);
if (monster.activeForTicks == 0) {
@ -52,18 +53,18 @@ void SyncMonsterPos(TSyncMonster &monsterSync, int ndx)
bool SyncMonsterActive(TSyncMonster &monsterSync)
{
int ndx = -1;
unsigned ndx = std::numeric_limits<unsigned>::max();
uint32_t lru = 0xFFFFFFFF;
for (size_t i = 0; i < ActiveMonsterCount; i++) {
int m = ActiveMonsters[i];
const unsigned m = ActiveMonsters[i];
if (sgnMonsterPriority[m] < lru && sgwLRU[m] < 0xFFFE) {
lru = sgnMonsterPriority[m];
ndx = ActiveMonsters[i];
}
}
if (ndx == -1) {
if (ndx == std::numeric_limits<unsigned>::max()) {
return false;
}
@ -73,14 +74,14 @@ bool SyncMonsterActive(TSyncMonster &monsterSync)
bool SyncMonsterActive2(TSyncMonster &monsterSync)
{
int ndx = -1;
unsigned ndx = std::numeric_limits<unsigned>::max();
uint32_t lru = 0xFFFE;
for (size_t i = 0; i < ActiveMonsterCount; i++) {
if (sgnMonsters >= ActiveMonsterCount) {
sgnMonsters = 0;
}
int m = ActiveMonsters[sgnMonsters];
const unsigned m = ActiveMonsters[sgnMonsters];
if (sgwLRU[m] < lru) {
lru = sgwLRU[m];
ndx = ActiveMonsters[sgnMonsters];
@ -88,7 +89,7 @@ bool SyncMonsterActive2(TSyncMonster &monsterSync)
sgnMonsters++;
}
if (ndx == -1) {
if (ndx == std::numeric_limits<unsigned>::max()) {
return false;
}
@ -184,7 +185,7 @@ void SyncMonster(bool isOwner, const TSyncMonster &monsterSync)
M_ClearSquares(monster);
monster.occupyTile(monster.position.tile, false);
Walk(monster, md);
monster.activeForTicks = UINT8_MAX;
monster.activeForTicks = std::numeric_limits<uint8_t>::max();
}
}
} else if (dMonster[position.x][position.y] == 0) {
@ -196,7 +197,7 @@ void SyncMonster(bool isOwner, const TSyncMonster &monsterSync)
decode_enemy(monster, enemyId);
Direction md = GetDirection(position, monster.enemyPosition);
M_StartStand(monster, md);
monster.activeForTicks = UINT8_MAX;
monster.activeForTicks = std::numeric_limits<uint8_t>::max();
}
decode_enemy(monster, enemyId);

Loading…
Cancel
Save