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

18
Source/loadsave.cpp

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

18
Source/monster.cpp

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

2
Source/monster.h

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

2
Source/msg.cpp

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

4
Source/portal.cpp

@ -112,9 +112,9 @@ bool PortalOnLevel(const Player &player)
void RemovePortalMissile(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) { 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; dFlags[missile.position.tile.x][missile.position.tile.y] &= ~DungeonFlag::Missile;
if (Portals[id].level != 0) if (Portals[id].level != 0)

21
Source/sync.cpp

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

Loading…
Cancel
Save