AGS: Fixing various type-cast warnings

From upstream 6c42c7331e96386721f28c92ec3cb4cd039e10cd
This commit is contained in:
Paul Gilbert 2022-04-25 20:06:19 -07:00
parent 5b291a5ef0
commit a633e9d72f
8 changed files with 19 additions and 18 deletions

View File

@ -398,8 +398,8 @@ void DrawingSurface_DrawPixel(ScriptDrawingSurface *sds, int x, int y) {
int DrawingSurface_GetPixel(ScriptDrawingSurface *sds, int x, int y) {
sds->PointToGameResolution(&x, &y);
Bitmap *ds = sds->StartDrawing();
unsigned int rawPixel = ds->GetPixel(x, y);
unsigned int maskColor = ds->GetMaskColor();
int rawPixel = ds->GetPixel(x, y);
int maskColor = ds->GetMaskColor();
int colDepth = ds->GetColorDepth();
if (rawPixel == maskColor) {

View File

@ -142,7 +142,7 @@ void GameState::UpdateViewports() {
}
_roomViewportZOrderChanged = false;
}
size_t vp_changed = (size_t)-1;
size_t vp_changed = SIZE_MAX;
for (size_t i = _roomViewportsSorted.size(); i-- > 0;) {
auto vp = _roomViewportsSorted[i];
if (vp->HasChangedSize() || vp->HasChangedPosition() || vp->HasChangedVisible()) {
@ -151,7 +151,7 @@ void GameState::UpdateViewports() {
vp->ClearChangedFlags();
}
}
if (vp_changed != (size_t)-1)
if (vp_changed != SIZE_MAX)
detect_roomviewport_overlaps(vp_changed);
for (auto cam : _roomCameras) {
if (cam->HasChangedSize() || cam->HasChangedPosition()) {

View File

@ -30,18 +30,19 @@
namespace AGS3 {
int StrGetCharAt(const char *strin, int posn) {
if ((posn < 0) || (posn >= (int)strlen(strin)))
if ((posn < 0) || (static_cast<size_t>(posn) >= strlen(strin)))
return 0;
return strin[posn];
}
void StrSetCharAt(char *strin, int posn, int nchar) {
if ((posn < 0) || (posn > (int)strlen(strin)) || (posn >= MAX_MAXSTRLEN))
size_t len = strlen(strin);
if ((posn < 0) || (static_cast<size_t>(posn) > len) || (posn >= MAX_MAXSTRLEN))
quit("!StrSetCharAt: tried to write past end of string");
if (posn == (int)strlen(strin))
strin[posn] = static_cast<char>(nchar);
if (static_cast<size_t>(posn) == len)
strin[posn + 1] = 0;
strin[posn] = nchar;
}
void _sc_strcat(char *s1, const char *s2) {

View File

@ -472,7 +472,7 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
_GP(play).bg_anim_delay = _GP(play).anim_background_speed;
// Fixup the frame index, in case the new room does not have enough background frames
if (_GP(play).bg_frame < 0 || _GP(play).bg_frame >= (int)_GP(thisroom).BgFrameCount)
if (_GP(play).bg_frame < 0 || static_cast<size_t>(_GP(play).bg_frame) >= _GP(thisroom).BgFrameCount)
_GP(play).bg_frame = 0;
// do the palette

View File

@ -514,7 +514,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
if (_G(displayed_room) >= 0) {
// Fixup the frame index, in case the restored room does not have enough background frames
if (_GP(play).bg_frame < 0 || _GP(play).bg_frame >= (int)_GP(thisroom).BgFrameCount)
if (_GP(play).bg_frame < 0 || static_cast<size_t>(_GP(play).bg_frame) >= (int)_GP(thisroom).BgFrameCount)
_GP(play).bg_frame = 0;
for (int i = 0; i < MAX_ROOM_BGFRAMES; ++i) {
@ -598,7 +598,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
}
update_directional_sound_vol();
adjust_fonts_for_render_mode(_GP(game).options[OPT_ANTIALIASFONTS]);
adjust_fonts_for_render_mode(_GP(game).options[OPT_ANTIALIASFONTS] != 0);
recreate_overlay_ddbs();

View File

@ -371,7 +371,7 @@ void override_config_ext(ConfigTree &cfg) {
void apply_config(const ConfigTree &cfg) {
{
_GP(usetup).audio_enabled = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_enabled);
_GP(usetup).audio_enabled = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_enabled) != 0;
_GP(usetup).audio_driver = INIreadstring(cfg, "sound", "driver");
// Legacy graphics settings has to be translated into new options;
@ -415,7 +415,7 @@ void apply_config(const ConfigTree &cfg) {
// This option is backwards (usevox is 0 if no_speech_pack)
_GP(usetup).no_speech_pack = INIreadint(cfg, "sound", "usespeech", 1) == 0;
_GP(usetup).clear_cache_on_room_change = INIreadint(cfg, "misc", "clear_cache_on_room_change", _GP(usetup).clear_cache_on_room_change);
_GP(usetup).clear_cache_on_room_change = INIreadint(cfg, "misc", "clear_cache_on_room_change", _GP(usetup).clear_cache_on_room_change) != 0;
_GP(usetup).user_data_dir = INIreadstring(cfg, "misc", "user_data_dir");
_GP(usetup).shared_data_dir = INIreadstring(cfg, "misc", "shared_data_dir");

View File

@ -1501,7 +1501,7 @@ bool ccInstance::ResolveScriptImports(const ccScript *scri) {
}
resolved_imports = new uint32_t[numimports];
int errors = 0, last_err_idx = 0;
size_t errors = 0, last_err_idx = 0;
for (int import_idx = 0; import_idx < scri->numimports; ++import_idx) {
if (scri->imports[import_idx] == nullptr) {
resolved_imports[import_idx] = UINT32_MAX;
@ -1626,7 +1626,7 @@ static void cc_error_fixups(const ccScript *scri, size_t pc, const char *fmt, ..
String displbuf = String::FromFormatV(fmt, ap);
va_end(ap);
const char *scname = scri->numSections > 0 ? scri->sectionNames[0] : "?";
if (pc == (size_t) -1) {
if (pc == SIZE_MAX) {
cc_error("in script %s: %s", scname, displbuf.GetCStr());
} else {
int line = DetermineScriptLine(scri->code, scri->codesize, pc);

View File

@ -45,7 +45,7 @@ uint8_t RuntimeScriptValue::ReadByte() const {
if (RValue->Type == kScValData) {
return *(uint8_t *)(RValue->GetPtrWithOffset() + this->IValue);
} else {
return RValue->IValue; // get RValue as int
return static_cast<uint8_t>(RValue->IValue);
}
} else if (this->Type == kScValStaticObject || this->Type == kScValStaticArray) {
return this->StcMgr->ReadInt8(this->Ptr, this->IValue);
@ -60,13 +60,13 @@ int16_t RuntimeScriptValue::ReadInt16() const {
if (RValue->Type == kScValData) {
return *(int16_t *)(RValue->GetPtrWithOffset() + this->IValue);
} else {
return RValue->IValue; // get RValue as int
return static_cast<uint16_t>(RValue->IValue);
}
} else if (this->Type == kScValGlobalVar) {
if (RValue->Type == kScValData) {
return Memory::ReadInt16LE(RValue->GetPtrWithOffset() + this->IValue);
} else {
return RValue->IValue; // get RValue as int
return static_cast<uint16_t>(RValue->IValue);
}
} else if (this->Type == kScValStaticObject || this->Type == kScValStaticArray) {
return this->StcMgr->ReadInt16(this->Ptr, this->IValue);