[Scummvm-git-logs] scummvm master -> 78312259b79edeabc44cfadb4ffbfcdf7c5f700d
dreammaster
noreply at scummvm.org
Sun Apr 24 23:03:27 UTC 2022
This automated email contains information about 12 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f27e782b23 AGS: Use constant to setup "no view" in RoomObjects instead of -1
6b1c43f90b AGS: Do explicit type cast in FileReadRawChar and FileWriteRawChar
d83c6bb947 AGS: In route_finder fixed local vars overriding each other names
a1a0323d28 AGS: Removed few redundant function args
8d261dd92f AGS: Corrected naimng style of RoomObject::NO_VIEW constant
4cab476394 AGS: in String use constant NoIndex instead of nps
14cffd13e7 AGS: Use String::NoIndex instead of -1 where necessary
9533c0e028 AGS: Made script module index an unsigned value
608389c4c5 AGS: made SystemImports index an unsigned value
043f80a237 AGS: Avoid using global "game" in game_init because it's possible
67628b9c6a AGS: Suppress endless "unused param" warnings in script api
78312259b7 AGS: Typecast warning fixes in (de)compression functions
Commit: f27e782b2305b0aa3cdd3a0d01bd1884ad7dbaa5
https://github.com/scummvm/scummvm/commit/f27e782b2305b0aa3cdd3a0d01bd1884ad7dbaa5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:01-07:00
Commit Message:
AGS: Use constant to setup "no view" in RoomObjects instead of -1
>From upstream a1f74944a7e3c058deb8b12680c5b9aba19dee5a
Changed paths:
engines/ags/engine/ac/global_object.cpp
engines/ags/engine/ac/object.cpp
engines/ags/engine/ac/room.cpp
engines/ags/engine/ac/room_object.cpp
engines/ags/engine/ac/room_object.h
diff --git a/engines/ags/engine/ac/global_object.cpp b/engines/ags/engine/ac/global_object.cpp
index f6d4f3e11ce..9dc4f51174f 100644
--- a/engines/ags/engine/ac/global_object.cpp
+++ b/engines/ags/engine/ac/global_object.cpp
@@ -71,7 +71,7 @@ int GetObjectIDAtRoom(int roomx, int roomy) {
int isflipped = 0;
int spWidth = game_to_data_coord(_G(objs)[aa].get_width());
int spHeight = game_to_data_coord(_G(objs)[aa].get_height());
- if (_G(objs)[aa].view != (uint16_t)-1)
+ if (_G(objs)[aa].view != RoomObject::NO_VIEW)
isflipped = _GP(views)[_G(objs)[aa].view].loops[_G(objs)[aa].loop].frames[_G(objs)[aa].frame].flags & VFLG_FLIPSPRITE;
Bitmap *theImage = GetObjectImage(aa, &isflipped);
@@ -221,7 +221,7 @@ void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, in
}
if (!is_valid_object(obn))
quit("!AnimateObject: invalid object number specified");
- if (_G(objs)[obn].view == (uint16_t)-1)
+ if (_G(objs)[obn].view == RoomObject::NO_VIEW)
quit("!AnimateObject: object has not been assigned a view");
if (loopn < 0 || loopn >= _GP(views)[_G(objs)[obn].view].numLoops)
quit("!AnimateObject: invalid loop number specified");
@@ -344,7 +344,7 @@ void SetObjectGraphic(int obn, int slott) {
_G(objs)[obn].cycling = 0;
_G(objs)[obn].frame = 0;
_G(objs)[obn].loop = 0;
- _G(objs)[obn].view = (uint16_t)-1;
+ _G(objs)[obn].view = RoomObject::NO_VIEW;
}
int GetObjectGraphic(int obn) {
diff --git a/engines/ags/engine/ac/object.cpp b/engines/ags/engine/ac/object.cpp
index a9a84a12d5c..2d638d79fdc 100644
--- a/engines/ags/engine/ac/object.cpp
+++ b/engines/ags/engine/ac/object.cpp
@@ -169,19 +169,19 @@ void Object_SetVisible(ScriptObject *objj, int onoroff) {
}
int Object_GetView(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == (uint16_t)-1)
+ if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
return 0;
return _G(objs)[objj->id].view + 1;
}
int Object_GetLoop(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == (uint16_t)-1)
+ if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
return 0;
return _G(objs)[objj->id].loop;
}
int Object_GetFrame(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == (uint16_t)-1)
+ if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
return 0;
return _G(objs)[objj->id].frame;
}
diff --git a/engines/ags/engine/ac/room.cpp b/engines/ags/engine/ac/room.cpp
index 41358f576ac..c0c7c165b25 100644
--- a/engines/ags/engine/ac/room.cpp
+++ b/engines/ags/engine/ac/room.cpp
@@ -569,7 +569,7 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
_G(croom)->obj[cc].y = _GP(thisroom).Objects[cc].Y;
_G(croom)->obj[cc].num = Math::InRangeOrDef<uint16_t>(_GP(thisroom).Objects[cc].Sprite, 0);
_G(croom)->obj[cc].on = _GP(thisroom).Objects[cc].IsOn;
- _G(croom)->obj[cc].view = (uint16) - 1;
+ _G(croom)->obj[cc].view = RoomObject::NO_VIEW;
_G(croom)->obj[cc].loop = 0;
_G(croom)->obj[cc].frame = 0;
_G(croom)->obj[cc].wait = 0;
diff --git a/engines/ags/engine/ac/room_object.cpp b/engines/ags/engine/ac/room_object.cpp
index 89ba5239262..9e3d7792798 100644
--- a/engines/ags/engine/ac/room_object.cpp
+++ b/engines/ags/engine/ac/room_object.cpp
@@ -78,7 +78,7 @@ void RoomObject::UpdateCyclingView(int ref_id) {
do_movelist_move(&moving, &x, &y);
}
if (cycling == 0) return;
- if (view == (uint16_t)-1) return;
+ if (view == RoomObject::NO_VIEW) return;
if (wait > 0) {
wait--; return;
}
diff --git a/engines/ags/engine/ac/room_object.h b/engines/ags/engine/ac/room_object.h
index 8cd18bf1f72..a2944567337 100644
--- a/engines/ags/engine/ac/room_object.h
+++ b/engines/ags/engine/ac/room_object.h
@@ -46,6 +46,8 @@ using namespace AGS; // FIXME later
// keep that in mind if extending this struct, and dont change existing fields
// unless you plan on adjusting plugin API as well.
struct RoomObject {
+ static const uint16_t NO_VIEW = UINT16_MAX;
+
int x, y;
int transparent; // current transparency setting
short tint_r, tint_g; // specific object tint
Commit: 6b1c43f90b3102baaa1ac2db6ed66faa5f156974
https://github.com/scummvm/scummvm/commit/6b1c43f90b3102baaa1ac2db6ed66faa5f156974
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:02-07:00
Commit Message:
AGS: Do explicit type cast in FileReadRawChar and FileWriteRawChar
>From upstream e3eb59bd4d72148a762ac93d0df36a56e101f257
Changed paths:
engines/ags/engine/ac/global_file.cpp
diff --git a/engines/ags/engine/ac/global_file.cpp b/engines/ags/engine/ac/global_file.cpp
index b68ec717a64..7344368f600 100644
--- a/engines/ags/engine/ac/global_file.cpp
+++ b/engines/ags/engine/ac/global_file.cpp
@@ -185,9 +185,9 @@ int FileReadInt(int32_t handle) {
int8 FileReadRawChar(int32_t handle) {
Stream *in = get_valid_file_stream_from_handle(handle, "FileReadRawChar");
- if (in->EOS())
- return -1;
- return in->ReadInt8();
+ return static_cast<uint8_t>(in->ReadByte());
+ // NOTE: this function has incorrect return value for historical reasons;
+ // we keep this strictly for backwards compatibility with old scripts
}
int FileReadRawInt(int32_t handle) {
@@ -202,7 +202,7 @@ void FileWriteRawChar(int32_t handle, int chartoWrite) {
if ((chartoWrite < 0) || (chartoWrite > 255))
debug_script_warn("!FileWriteRawChar: can only write values 0-255");
- out->WriteInt8(chartoWrite);
+ out->WriteByte(static_cast<uint8_t>(chartoWrite));
}
} // namespace AGS3
Commit: d83c6bb947bf16d130b2010d2bbc282476cab9be
https://github.com/scummvm/scummvm/commit/d83c6bb947bf16d130b2010d2bbc282476cab9be
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:02-07:00
Commit Message:
AGS: In route_finder fixed local vars overriding each other names
>From upstream 02543b871783e88cb76418d6adad37ae3db10e89
Changed paths:
engines/ags/engine/ac/route_finder_jps.cpp
diff --git a/engines/ags/engine/ac/route_finder_jps.cpp b/engines/ags/engine/ac/route_finder_jps.cpp
index b2fc9a9ad05..185829a137a 100644
--- a/engines/ags/engine/ac/route_finder_jps.cpp
+++ b/engines/ags/engine/ac/route_finder_jps.cpp
@@ -339,10 +339,12 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
if (!TraceLine(sx, sy, ex, ey, &opath))
return NAV_STRAIGHT;
- NodeInfo &nodeInfo = mapNodes[sy * mapWidth + sx];
- nodeInfo.dist = 0;
- nodeInfo.frameId = frameId;
- nodeInfo.prev = -1;
+ {
+ NodeInfo &node = mapNodes[sy * mapWidth + sx];
+ node.dist = 0;
+ node.frameId = frameId;
+ node.prev = -1;
+ }
closest = 0x7fffffff;
cnode = PackSquare(sx, sy);
@@ -360,13 +362,15 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
int x, y;
UnpackSquare(e.index, x, y);
- int vdx = x - ex;
- int vdy = y - ey;
- int edist = ClosestDist(vdx, vdy);
+ {
+ int edx = x - ex;
+ int edy = y - ey;
+ int edist = ClosestDist(edx, edy);
- if (edist < closest) {
- closest = edist;
- cnode = e.index;
+ if (edist < closest) {
+ closest = edist;
+ cnode = e.index;
+ }
}
if (x == ex && y == ey) {
@@ -374,15 +378,18 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
break;
}
- const NodeInfo &node = mapNodes[y * mapWidth + x];
+ float dist;
+ int prev;
- float dist = node.dist * DIST_SCALE_UNPACK;
+ {
+ const NodeInfo &node = mapNodes[y * mapWidth + x];
+ dist = node.dist * DIST_SCALE_UNPACK;
+ prev = node.prev;
+ }
int pneig[8];
int ncount = 0;
- int prev = node.prev;
-
if (prev < 0) {
for (int ny = y - 1; ny <= y + 1; ny++) {
if ((unsigned)ny >= (unsigned)mapHeight)
@@ -444,11 +451,11 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
AddPruned(pneig, ncount, x + dx, y + dy);
if (!Passable(x - dx, y) &&
- (nodiag || Reachable(x, y, x - dx, y + dy)))
+ (nodiag || Reachable(x, y, x - dx, y + dy)))
AddPruned(pneig, ncount, x - dx, y + dy);
if (!Passable(x, y - dy) &&
- (nodiag || Reachable(x, y, x + dx, y - dy)))
+ (nodiag || Reachable(x, y, x + dx, y - dy)))
AddPruned(pneig, ncount, x + dx, y - dy);
}
}
@@ -492,9 +499,9 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
UnpackSquare(succ[ni], nx, ny);
assert(Walkable(nx, ny));
- NodeInfo &mapNode = mapNodes[ny * mapWidth + nx];
+ NodeInfo &node = mapNodes[ny * mapWidth + nx];
- float ndist = mapNode.frameId != frameId ? INFINITY : mapNode.dist * DIST_SCALE_UNPACK;
+ float ndist = node.frameId != frameId ? INFINITY : node.dist * DIST_SCALE_UNPACK;
float dx = (float)(nx - x);
float dy = (float)(ny - y);
@@ -515,9 +522,9 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
if (ecost > 65535.0f)
continue;
- mapNode.dist = (unsigned short)(ecost + 0.5f);
- mapNode.frameId = frameId;
- mapNode.prev = PackSquare(x, y);
+ node.dist = (unsigned short)(ecost + 0.5f);
+ node.frameId = frameId;
+ node.prev = PackSquare(x, y);
pq.push(Entry(ecost + heur, PackSquare(nx, ny)));
}
}
@@ -576,7 +583,7 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
}
if (ex < 0 || ex >= mapWidth || ey < 0 || ey >= mapHeight ||
- mapNodes[ey * mapWidth + ex].frameId != frameId) {
+ mapNodes[ey * mapWidth + ex].frameId != frameId) {
// path not found
return NAV_UNREACHABLE;
}
@@ -610,7 +617,7 @@ Navigation::NavResult Navigation::Navigate(int sx, int sy, int ex, int ey, std::
}
Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey,
- std::vector<int> &opath, std::vector<int> &ncpath) {
+ std::vector<int> &opath, std::vector<int> &ncpath) {
ncpath.clear();
NavResult res = Navigate(sx, sy, ex, ey, opath);
@@ -624,9 +631,6 @@ Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey
return res;
}
- int fx = sx;
- int fy = sy;
-
fpath.clear();
ncpathIndex.clear();
@@ -641,7 +645,7 @@ Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey
rayPath.reserve(opath.size());
orayPath.reserve(opath.size());
- for (int i = 1; i < (int)opath.size(); i++) {
+ for (int i = 1, fx = sx, fy = sy; i < (int)opath.size(); i++) {
// trying to optimize path
int tx, ty;
UnpackSquare(opath[i], tx, ty);
@@ -689,6 +693,7 @@ Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey
// validate cpath
for (int i = 0; i < (int)ncpath.size() - 1; i++) {
+ int fx, fy;
int tx, ty;
UnpackSquare(ncpath[i], fx, fy);
UnpackSquare(ncpath[i + 1], tx, ty);
@@ -749,6 +754,7 @@ Navigation::NavResult Navigation::NavigateRefined(int sx, int sy, int ex, int ey
opath.push_back(ncpath[0]);
for (int i = 1; i < (int)ncpath.size(); i++) {
+ int fx, fy;
int tx, ty;
UnpackSquare(ncpath[i - 1], fx, fy);
Commit: a1a0323d28dd54be947448ce38d40f0bfc826750
https://github.com/scummvm/scummvm/commit/a1a0323d28dd54be947448ce38d40f0bfc826750
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:03-07:00
Commit Message:
AGS: Removed few redundant function args
>From upstream 4c80a7fb3afdfd8d7b82f16b7aeac5418565f608
Changed paths:
engines/ags/engine/ac/character.cpp
engines/ags/engine/ac/dialog.cpp
engines/ags/engine/ac/display.cpp
engines/ags/engine/ac/display.h
engines/ags/engine/ac/draw.cpp
engines/ags/engine/ac/file.cpp
diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index e6bf1325384..2e76806895a 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -2351,7 +2351,7 @@ void _displayspeech(const char *texx, int aschar, int xx, int yy, int widd, int
Bitmap *closeupface = nullptr;
// TODO: we always call _display_at later which may also start voice-over;
// find out if this may be refactored and voice started only in one place.
- try_auto_play_speech(texx, texx, aschar, true);
+ try_auto_play_speech(texx, texx, aschar);
if (_GP(game).options[OPT_SPEECHTYPE] == 3)
remove_screen_overlay(OVER_COMPLETE);
diff --git a/engines/ags/engine/ac/dialog.cpp b/engines/ags/engine/ac/dialog.cpp
index 0d317c807c2..11f68acb45f 100644
--- a/engines/ags/engine/ac/dialog.cpp
+++ b/engines/ags/engine/ac/dialog.cpp
@@ -166,7 +166,7 @@ void get_dialog_script_parameters(unsigned char *&script, unsigned short *param1
}
}
-int run_dialog_script(DialogTopic *dtpp, int dialogID, int offse, int optionIndex) {
+int run_dialog_script(int dialogID, int offse, int optionIndex) {
_G(said_speech_line) = 0;
int result = RUN_DIALOG_STAY;
@@ -1066,7 +1066,7 @@ void do_conversation(int dlgnum) {
DialogTopic *dtop = &_G(dialog)[dlgnum];
// run the startup script
- int tocar = run_dialog_script(dtop, dlgnum, dtop->startupentrypoint, 0);
+ int tocar = run_dialog_script(dlgnum, dtop->startupentrypoint, 0);
if ((tocar == RUN_DIALOG_STOP_DIALOG) ||
(tocar == RUN_DIALOG_GOTO_PREVIOUS)) {
// 'stop' or 'goto-previous' from first startup script
@@ -1085,7 +1085,7 @@ void do_conversation(int dlgnum) {
if (dlgnum != dlgnum_was) {
// dialog topic changed, so play the startup
// script for the new topic
- tocar = run_dialog_script(dtop, dlgnum, dtop->startupentrypoint, 0);
+ tocar = run_dialog_script(dlgnum, dtop->startupentrypoint, 0);
dlgnum_was = dlgnum;
if (tocar == RUN_DIALOG_GOTO_PREVIOUS) {
if (numPrevTopics < 1) {
@@ -1124,7 +1124,7 @@ void do_conversation(int dlgnum) {
set_mouse_cursor(CURS_ARROW);
}
} else if (chose >= 0) {
- tocar = run_dialog_script(dtop, dlgnum, dtop->entrypoints[chose], chose + 1);
+ tocar = run_dialog_script(dlgnum, dtop->entrypoints[chose], chose + 1);
} else {
tocar = RUN_DIALOG_STOP_DIALOG;
}
diff --git a/engines/ags/engine/ac/display.cpp b/engines/ags/engine/ac/display.cpp
index 7961649ea13..7c2e3726a9e 100644
--- a/engines/ags/engine/ac/display.cpp
+++ b/engines/ags/engine/ac/display.cpp
@@ -367,7 +367,7 @@ void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int a
EndSkippingUntilCharStops();
- if (try_auto_play_speech(text, text, _GP(play).narrator_speech, true)) {// TODO: is there any need for this flag?
+ if (try_auto_play_speech(text, text, _GP(play).narrator_speech)) {
need_stop_speech = true;
}
_display_main(xx, yy, wii, text, disp_type, usingfont, asspch, isThought, allowShrink, overlayPositionFixed);
@@ -376,7 +376,7 @@ void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int a
stop_voice_speech();
}
-bool try_auto_play_speech(const char *text, const char *&replace_text, int charid, bool blocking) {
+bool try_auto_play_speech(const char *text, const char *&replace_text, int charid) {
const char *src = text;
if (src[0] != '&')
return false;
diff --git a/engines/ags/engine/ac/display.h b/engines/ags/engine/ac/display.h
index bfba7456311..b5d5151a9ae 100644
--- a/engines/ags/engine/ac/display.h
+++ b/engines/ags/engine/ac/display.h
@@ -43,7 +43,7 @@ void _display_at(int xx, int yy, int wii, const char *text, int disp_type, int a
// will assign replacement string, which will be blank string if game is in "voice-only" mode
// and clip was started, or string cleaned from voice-over tags which is safe to display on screen.
// Returns whether voice-over clip was started successfully.
-bool try_auto_play_speech(const char *text, const char *&replace_text, int charid, bool blocking);
+bool try_auto_play_speech(const char *text, const char *&replace_text, int charid);
bool ShouldAntiAliasText();
// Calculates meaningful length of the displayed text
int GetTextDisplayLength(const char *text);
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 2956681710b..bce6d50b5aa 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -1859,7 +1859,7 @@ void draw_preroom_background() {
// ds and roomcam_surface may be the same bitmap.
// no_transform flag tells to copy dirty regions on roomcam_surface without any coordinate conversion
// whatsoever.
-PBitmap draw_room_background(Viewport *view, const SpriteTransform &room_trans) {
+PBitmap draw_room_background(Viewport *view) {
_G(our_eip) = 31;
// For the sake of software renderer, if there is any kind of camera transform required
@@ -2113,7 +2113,7 @@ static void construct_room_view() {
_G(gfxDriver)->DrawSprite(0, 0, _G(roomBackgroundBmp));
} else {
// room background is drawn by dirty rects system
- PBitmap bg_surface = draw_room_background(viewport.get(), room_trans);
+ PBitmap bg_surface = draw_room_background(viewport.get());
_G(gfxDriver)->BeginSpriteBatch(view_rc, room_trans, Point(), kFlip_None, bg_surface);
}
}
diff --git a/engines/ags/engine/ac/file.cpp b/engines/ags/engine/ac/file.cpp
index 9dd6b1716f8..1367f6dda27 100644
--- a/engines/ags/engine/ac/file.cpp
+++ b/engines/ags/engine/ac/file.cpp
@@ -533,7 +533,8 @@ String find_assetlib(const String &filename) {
return "";
}
-AssetPath get_audio_clip_assetpath(int bundling_type, const String &filename) {
+AssetPath get_audio_clip_assetpath(int /*bundling_type*/, const String &filename) {
+ // NOTE: bundling_type is ignored now
return AssetPath(filename, "audio");
}
Commit: 8d261dd92fdc6d10b6285e761c61948f049d68f2
https://github.com/scummvm/scummvm/commit/8d261dd92fdc6d10b6285e761c61948f049d68f2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:03-07:00
Commit Message:
AGS: Corrected naimng style of RoomObject::NO_VIEW constant
>From upstream ff544cda911ab036be44171a1b97b8a52e943758
Changed paths:
engines/ags/engine/ac/global_object.cpp
engines/ags/engine/ac/object.cpp
engines/ags/engine/ac/room.cpp
engines/ags/engine/ac/room_object.cpp
engines/ags/engine/ac/room_object.h
diff --git a/engines/ags/engine/ac/global_object.cpp b/engines/ags/engine/ac/global_object.cpp
index 9dc4f51174f..163155bc423 100644
--- a/engines/ags/engine/ac/global_object.cpp
+++ b/engines/ags/engine/ac/global_object.cpp
@@ -71,7 +71,7 @@ int GetObjectIDAtRoom(int roomx, int roomy) {
int isflipped = 0;
int spWidth = game_to_data_coord(_G(objs)[aa].get_width());
int spHeight = game_to_data_coord(_G(objs)[aa].get_height());
- if (_G(objs)[aa].view != RoomObject::NO_VIEW)
+ if (_G(objs)[aa].view != RoomObject::NoView)
isflipped = _GP(views)[_G(objs)[aa].view].loops[_G(objs)[aa].loop].frames[_G(objs)[aa].frame].flags & VFLG_FLIPSPRITE;
Bitmap *theImage = GetObjectImage(aa, &isflipped);
@@ -221,7 +221,7 @@ void AnimateObjectImpl(int obn, int loopn, int spdd, int rept, int direction, in
}
if (!is_valid_object(obn))
quit("!AnimateObject: invalid object number specified");
- if (_G(objs)[obn].view == RoomObject::NO_VIEW)
+ if (_G(objs)[obn].view == RoomObject::NoView)
quit("!AnimateObject: object has not been assigned a view");
if (loopn < 0 || loopn >= _GP(views)[_G(objs)[obn].view].numLoops)
quit("!AnimateObject: invalid loop number specified");
@@ -344,7 +344,7 @@ void SetObjectGraphic(int obn, int slott) {
_G(objs)[obn].cycling = 0;
_G(objs)[obn].frame = 0;
_G(objs)[obn].loop = 0;
- _G(objs)[obn].view = RoomObject::NO_VIEW;
+ _G(objs)[obn].view = RoomObject::NoView;
}
int GetObjectGraphic(int obn) {
diff --git a/engines/ags/engine/ac/object.cpp b/engines/ags/engine/ac/object.cpp
index 2d638d79fdc..953de11aea3 100644
--- a/engines/ags/engine/ac/object.cpp
+++ b/engines/ags/engine/ac/object.cpp
@@ -169,19 +169,19 @@ void Object_SetVisible(ScriptObject *objj, int onoroff) {
}
int Object_GetView(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
+ if (_G(objs)[objj->id].view == RoomObject::NoView)
return 0;
return _G(objs)[objj->id].view + 1;
}
int Object_GetLoop(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
+ if (_G(objs)[objj->id].view == RoomObject::NoView)
return 0;
return _G(objs)[objj->id].loop;
}
int Object_GetFrame(ScriptObject *objj) {
- if (_G(objs)[objj->id].view == RoomObject::NO_VIEW)
+ if (_G(objs)[objj->id].view == RoomObject::NoView)
return 0;
return _G(objs)[objj->id].frame;
}
diff --git a/engines/ags/engine/ac/room.cpp b/engines/ags/engine/ac/room.cpp
index c0c7c165b25..d97542b11bd 100644
--- a/engines/ags/engine/ac/room.cpp
+++ b/engines/ags/engine/ac/room.cpp
@@ -569,7 +569,7 @@ void load_new_room(int newnum, CharacterInfo *forchar) {
_G(croom)->obj[cc].y = _GP(thisroom).Objects[cc].Y;
_G(croom)->obj[cc].num = Math::InRangeOrDef<uint16_t>(_GP(thisroom).Objects[cc].Sprite, 0);
_G(croom)->obj[cc].on = _GP(thisroom).Objects[cc].IsOn;
- _G(croom)->obj[cc].view = RoomObject::NO_VIEW;
+ _G(croom)->obj[cc].view = RoomObject::NoView;
_G(croom)->obj[cc].loop = 0;
_G(croom)->obj[cc].frame = 0;
_G(croom)->obj[cc].wait = 0;
diff --git a/engines/ags/engine/ac/room_object.cpp b/engines/ags/engine/ac/room_object.cpp
index 9e3d7792798..e4785288ce4 100644
--- a/engines/ags/engine/ac/room_object.cpp
+++ b/engines/ags/engine/ac/room_object.cpp
@@ -78,7 +78,7 @@ void RoomObject::UpdateCyclingView(int ref_id) {
do_movelist_move(&moving, &x, &y);
}
if (cycling == 0) return;
- if (view == RoomObject::NO_VIEW) return;
+ if (view == RoomObject::NoView) return;
if (wait > 0) {
wait--; return;
}
diff --git a/engines/ags/engine/ac/room_object.h b/engines/ags/engine/ac/room_object.h
index a2944567337..ab77382dffe 100644
--- a/engines/ags/engine/ac/room_object.h
+++ b/engines/ags/engine/ac/room_object.h
@@ -46,7 +46,7 @@ using namespace AGS; // FIXME later
// keep that in mind if extending this struct, and dont change existing fields
// unless you plan on adjusting plugin API as well.
struct RoomObject {
- static const uint16_t NO_VIEW = UINT16_MAX;
+ static const uint16_t NoView = UINT16_MAX;
int x, y;
int transparent; // current transparency setting
Commit: 4cab47639410048e12a49f8ce7cb558cf39f64c2
https://github.com/scummvm/scummvm/commit/4cab47639410048e12a49f8ce7cb558cf39f64c2
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:04-07:00
Commit Message:
AGS: in String use constant NoIndex instead of nps
>From upstream aca0285937f96002b76d61f4c1cc6f3a11242c2c
Changed paths:
engines/ags/engine/ac/listbox.cpp
engines/ags/engine/main/main.cpp
engines/ags/engine/media/audio/sound.cpp
engines/ags/shared/util/string.cpp
engines/ags/shared/util/string.h
engines/ags/shared/util/string_utils.cpp
diff --git a/engines/ags/engine/ac/listbox.cpp b/engines/ags/engine/ac/listbox.cpp
index 651f01a770d..3b708c6f78c 100644
--- a/engines/ags/engine/ac/listbox.cpp
+++ b/engines/ags/engine/ac/listbox.cpp
@@ -66,7 +66,7 @@ void ListBox_Clear(GUIListBox *listbox) {
static void FillSaveList(std::set<String> &files, const String &filePattern) {
size_t wildcard = filePattern.FindChar('*');
- assert(wildcard != String::npos);
+ assert(wildcard != String::NoIndex);
Common::String prefix(filePattern.GetCStr(), wildcard);
Common::StringArray matches = g_system->getSavefileManager()->listSavefiles(filePattern);
diff --git a/engines/ags/engine/main/main.cpp b/engines/ags/engine/main/main.cpp
index 960aa9cf5cb..6f6661fabe4 100644
--- a/engines/ags/engine/main/main.cpp
+++ b/engines/ags/engine/main/main.cpp
@@ -283,7 +283,7 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
} else if (ags_strnicmp(arg, "--log-", 6) == 0 && arg[6] != 0) {
String logarg = arg + 6;
size_t split_at = logarg.FindChar('=');
- if (split_at != String::npos)
+ if (split_at != String::NoIndex)
cfg["log"][logarg.Left(split_at)] = logarg.Mid(split_at + 1);
else
cfg["log"][logarg] = "";
diff --git a/engines/ags/engine/media/audio/sound.cpp b/engines/ags/engine/media/audio/sound.cpp
index 1a1c680d5c9..ad53a2d4469 100644
--- a/engines/ags/engine/media/audio/sound.cpp
+++ b/engines/ags/engine/media/audio/sound.cpp
@@ -99,7 +99,7 @@ SOUNDCLIP *my_load_mod(const AssetPath &asset_name, bool loop) {
if (data) {
// determine the file extension
size_t lastDot = asset_name.Filter.FindCharReverse('.');
- if (lastDot == AGS::Shared::String::npos || lastDot == asset_name.Filter.GetLength() - 1) {
+ if (lastDot == AGS::Shared::String::NoIndex || lastDot == asset_name.Filter.GetLength() - 1) {
delete data;
return nullptr;
}
diff --git a/engines/ags/shared/util/string.cpp b/engines/ags/shared/util/string.cpp
index 23770530aff..e4f8ce64188 100644
--- a/engines/ags/shared/util/string.cpp
+++ b/engines/ags/shared/util/string.cpp
@@ -163,36 +163,36 @@ int String::CompareNoCase(const char *cstr) const {
int String::CompareLeft(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
- return strncmp(_cstr, cstr, count != npos ? count : strlen(cstr));
+ return strncmp(_cstr, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareLeftNoCase(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
- return ags_strnicmp(_cstr, cstr, count != npos ? count : strlen(cstr));
+ return ags_strnicmp(_cstr, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareMid(const char *cstr, size_t from, size_t count) const {
cstr = cstr ? cstr : "";
from = Math::Min(from, _len);
- return strncmp(_cstr + from, cstr, count != npos ? count : strlen(cstr));
+ return strncmp(_cstr + from, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareMidNoCase(const char *cstr, size_t from, size_t count) const {
cstr = cstr ? cstr : "";
from = Math::Min(from, _len);
- return ags_strnicmp(_cstr + from, cstr, count != npos ? count : strlen(cstr));
+ return ags_strnicmp(_cstr + from, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareRight(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
- count = count != npos ? count : strlen(cstr);
+ count = count != NoIndex ? count : strlen(cstr);
size_t off = Math::Min(_len, count);
return strncmp(_cstr + _len - off, cstr, count);
}
int String::CompareRightNoCase(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
- count = count != npos ? count : strlen(cstr);
+ count = count != NoIndex ? count : strlen(cstr);
size_t off = Math::Min(_len, count);
return ags_strnicmp(_cstr + _len - off, cstr, count);
}
@@ -200,14 +200,14 @@ int String::CompareRightNoCase(const char *cstr, size_t count) const {
size_t String::FindChar(char c, size_t from) const {
if (c && from < _len) {
const char *found_cstr = strchr(_cstr + from, c);
- return found_cstr ? found_cstr - _cstr : npos;
+ return found_cstr ? found_cstr - _cstr : NoIndex;
}
- return npos;
+ return NoIndex;
}
size_t String::FindCharReverse(char c, size_t from) const {
if ((_len == 0) || !c) {
- return npos;
+ return NoIndex;
}
from = Math::Min(from, _len - 1);
@@ -218,15 +218,15 @@ size_t String::FindCharReverse(char c, size_t from) const {
}
seek_ptr--;
}
- return npos;
+ return NoIndex;
}
size_t String::FindString(const char *cstr, size_t from) const {
if (cstr && from < _len) {
const char *found_cstr = strstr(_cstr + from, cstr);
- return found_cstr ? found_cstr - _cstr : npos;
+ return found_cstr ? found_cstr - _cstr : NoIndex;
}
- return npos;
+ return NoIndex;
}
bool String::FindSection(char separator, size_t first, size_t last, bool exclude_first_sep, bool exclude_last_sep,
@@ -241,10 +241,10 @@ bool String::FindSection(char separator, size_t first, size_t last, bool exclude
size_t this_field = 0;
size_t slice_from = 0;
size_t slice_to = _len;
- size_t slice_at = npos;
+ size_t slice_at = NoIndex;
do {
slice_at = FindChar(separator, slice_at + 1);
- if (slice_at == npos)
+ if (slice_at == NoIndex)
slice_at = _len;
// found where previous field ends
if (this_field == last) {
@@ -344,7 +344,7 @@ String String::Right(size_t count) const {
String String::LeftSection(char separator, bool exclude_separator) const {
if ((_len != 0) && separator) {
size_t slice_at = FindChar(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
slice_at = exclude_separator ? slice_at : slice_at + 1;
return Left(slice_at);
}
@@ -355,7 +355,7 @@ String String::LeftSection(char separator, bool exclude_separator) const {
String String::RightSection(char separator, bool exclude_separator) const {
if ((_len != 0) && separator) {
size_t slice_at = FindCharReverse(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
size_t count = exclude_separator ? _len - slice_at - 1 : _len - slice_at;
return Right(count);
}
@@ -508,7 +508,7 @@ void String::ClipRight(size_t count) {
void String::ClipLeftSection(char separator, bool include_separator) {
if ((_len != 0) && separator) {
size_t slice_at = FindChar(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
ClipLeft(include_separator ? slice_at + 1 : slice_at);
} else
Empty();
@@ -518,7 +518,7 @@ void String::ClipLeftSection(char separator, bool include_separator) {
void String::ClipRightSection(char separator, bool include_separator) {
if ((_len != 0) && separator) {
size_t slice_at = FindCharReverse(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
ClipRight(include_separator ? _len - slice_at : _len - slice_at - 1);
} else
Empty();
@@ -855,7 +855,7 @@ void String::TruncateToRight(size_t count) {
void String::TruncateToLeftSection(char separator, bool exclude_separator) {
if ((_len != 0) && separator) {
size_t slice_at = FindChar(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
TruncateToLeft(exclude_separator ? slice_at : slice_at + 1);
}
}
@@ -864,7 +864,7 @@ void String::TruncateToLeftSection(char separator, bool exclude_separator) {
void String::TruncateToRightSection(char separator, bool exclude_separator) {
if ((_len != 0) && separator) {
size_t slice_at = FindCharReverse(separator);
- if (slice_at != npos) {
+ if (slice_at != NoIndex) {
TruncateToRight(exclude_separator ? _len - slice_at - 1 : _len - slice_at);
}
}
diff --git a/engines/ags/shared/util/string.h b/engines/ags/shared/util/string.h
index c216506f08c..726597f1d98 100644
--- a/engines/ags/shared/util/string.h
+++ b/engines/ags/shared/util/string.h
@@ -58,7 +58,7 @@ class Stream;
class String {
public:
- static const size_t npos = (size_t)-1;
+ static const size_t NoIndex = (size_t)-1;
// Standard constructor: intialize empty string
String();
@@ -139,29 +139,29 @@ public:
int CompareNoCase(const char *cstr) const;
// Compares the leftmost part of this string with given string
int CompareLeft(const String &str, size_t count = -1) const {
- return CompareLeft(str._cstr, count != npos ? count : str._len);
+ return CompareLeft(str._cstr, count != NoIndex ? count : str._len);
}
int CompareLeft(const char *cstr, size_t count = -1) const;
int CompareLeftNoCase(const String &str, size_t count = -1) const {
- return CompareLeftNoCase(str._cstr, count != npos ? count : str._len);
+ return CompareLeftNoCase(str._cstr, count != NoIndex ? count : str._len);
}
int CompareLeftNoCase(const char *cstr, size_t count = -1) const;
// Compares any part of this string with given string
int CompareMid(const String &str, size_t from, size_t count = -1) const {
- return CompareMid(str._cstr, from, count != npos ? count : str._len);
+ return CompareMid(str._cstr, from, count != NoIndex ? count : str._len);
}
int CompareMid(const char *cstr, size_t from, size_t count = -1) const;
int CompareMidNoCase(const String &str, size_t from, size_t count = -1) const {
- return CompareMidNoCase(str._cstr, from, count != npos ? count : str._len);
+ return CompareMidNoCase(str._cstr, from, count != NoIndex ? count : str._len);
}
int CompareMidNoCase(const char *cstr, size_t from, size_t count = -1) const;
// Compares the rightmost part of this string with given C-string
int CompareRight(const String &str, size_t count = -1) const {
- return CompareRight(str._cstr, count != npos ? count : str._len);
+ return CompareRight(str._cstr, count != NoIndex ? count : str._len);
}
int CompareRight(const char *cstr, size_t count = -1) const;
int CompareRightNoCase(const String &str, size_t count = -1) const {
- return CompareRightNoCase(str._cstr, count != npos ? count : str._len);
+ return CompareRightNoCase(str._cstr, count != NoIndex ? count : str._len);
}
int CompareRightNoCase(const char *cstr, size_t count = -1) const;
// Convenience aliases for Compare functions
diff --git a/engines/ags/shared/util/string_utils.cpp b/engines/ags/shared/util/string_utils.cpp
index 66bbc07f7bd..8f698826fb2 100644
--- a/engines/ags/shared/util/string_utils.cpp
+++ b/engines/ags/shared/util/string_utils.cpp
@@ -63,7 +63,7 @@ StrUtil::ConversionError StrUtil::StringToInt(const String &s, int &val, int def
String StrUtil::Unescape(const String &s) {
size_t at = s.FindChar('\\');
- if (at == String::npos)
+ if (at == String::NoIndex)
return s; // no unescaping necessary, return original string
char *buf = new char[s.GetLength()];
strncpy(buf, s.GetCStr(), at);
Commit: 14cffd13e77584081b0137c4ceede0f8406c5edd
https://github.com/scummvm/scummvm/commit/14cffd13e77584081b0137c4ceede0f8406c5edd
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:04-07:00
Commit Message:
AGS: Use String::NoIndex instead of -1 where necessary
>From upstream 56275cb1f58f630082f3f51ab8e2c0ab5b021b16
Changed paths:
engines/ags/engine/ac/dynamic_sprite.cpp
engines/ags/engine/ac/gui.cpp
engines/ags/engine/main/config.cpp
engines/ags/engine/script/system_imports.cpp
engines/ags/shared/util/path.cpp
diff --git a/engines/ags/engine/ac/dynamic_sprite.cpp b/engines/ags/engine/ac/dynamic_sprite.cpp
index f64067144d7..208c11ad1c8 100644
--- a/engines/ags/engine/ac/dynamic_sprite.cpp
+++ b/engines/ags/engine/ac/dynamic_sprite.cpp
@@ -271,7 +271,7 @@ int DynamicSprite_SaveToFile(ScriptDynamicSprite *sds, const char *namm) {
quit("!DynamicSprite.SaveToFile: sprite has been deleted");
auto filename = String(namm);
- if (filename.FindChar('.') == (size_t)-1)
+ if (filename.FindChar('.') == String::NoIndex)
filename.Append(".bmp");
ResolvedPath rp;
diff --git a/engines/ags/engine/ac/gui.cpp b/engines/ags/engine/ac/gui.cpp
index a27f9cbd514..9fd3dc3e7e8 100644
--- a/engines/ags/engine/ac/gui.cpp
+++ b/engines/ags/engine/ac/gui.cpp
@@ -332,7 +332,7 @@ void process_interface_click(int ifce, int btn, int mbut) {
(!theObj->EventHandlers[0].IsEmpty()) &&
(!_G(gameinst)->GetSymbolAddress(theObj->EventHandlers[0].GetCStr()).IsNull())) {
// control-specific event handler
- if (theObj->GetEventArgs(0).FindChar(',') != Common::String::npos) {
+ if (theObj->GetEventArgs(0).FindChar(',') != String::NoIndex) {
RuntimeScriptValue params[]{ RuntimeScriptValue().SetDynamicObject(theObj, &_GP(ccDynamicGUIObject)),
RuntimeScriptValue().SetInt32(mbut) };
QueueScriptFunction(kScInstGame, theObj->EventHandlers[0].GetCStr(), 2, params);
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index a95d9b9d2b6..64337db734b 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -113,7 +113,8 @@ WindowSetup parse_window_mode(const String &option, bool as_windowed, WindowSetu
if (at == 0) { // try parse as a scale (xN)
int scale = StrUtil::StringToInt(option.Mid(1));
if (scale > 0) return WindowSetup(scale, exp_wmode);
- } else if (at != (size_t)(-1)) { // else try parse as a "width x height"
+ } else if (at != String::NoIndex) {
+ // else try parse as a "width x height"
Size sz = Size(StrUtil::StringToInt(option.Mid(0, at)),
StrUtil::StringToInt(option.Mid(at + 1)));
if (!sz.IsNull()) return WindowSetup(sz, exp_wmode);
diff --git a/engines/ags/engine/script/system_imports.cpp b/engines/ags/engine/script/system_imports.cpp
index e979d903c11..fa3bf4a9ce1 100644
--- a/engines/ags/engine/script/system_imports.cpp
+++ b/engines/ags/engine/script/system_imports.cpp
@@ -93,7 +93,7 @@ int SystemImports::get_index_of(const String &name) {
if (name.GetLength() > 3) {
size_t c = name.FindCharReverse('^');
- if (c != (size_t)-1 && (c == name.GetLength() - 2 || c == name.GetLength() - 3)) {
+ if (c != String::NoIndex && (c == name.GetLength() - 2 || c == name.GetLength() - 3)) {
// Function with number of prametrs on the end
// attempt to find it without the param count
return get_index_of(name.Left(c));
diff --git a/engines/ags/shared/util/path.cpp b/engines/ags/shared/util/path.cpp
index 341ea15c60e..e29aaf606f6 100644
--- a/engines/ags/shared/util/path.cpp
+++ b/engines/ags/shared/util/path.cpp
@@ -96,7 +96,7 @@ String GetDirectoryPath(const String &path) {
String dir = path;
FixupPath(dir);
size_t slash_at = dir.FindCharReverse('/');
- if (slash_at != (size_t)-1) {
+ if (slash_at != String::NoIndex) {
dir.ClipMid(slash_at + 1);
return dir;
}
Commit: 9533c0e028986ff570855b01d19d6b3476d08042
https://github.com/scummvm/scummvm/commit/9533c0e028986ff570855b01d19d6b3476d08042
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:04-07:00
Commit Message:
AGS: Made script module index an unsigned value
>From upstream bd4e65677eb0319ff746e519ee40016000a4f4f9
Changed paths:
engines/ags/engine/ac/event.cpp
engines/ags/engine/ac/game.cpp
engines/ags/engine/game/game_init.cpp
engines/ags/engine/game/savegame.cpp
engines/ags/engine/game/savegame_components.cpp
engines/ags/engine/game/savegame_v321.cpp
engines/ags/engine/script/script.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/event.cpp b/engines/ags/engine/ac/event.cpp
index 9252e5e5bb3..8cf12552866 100644
--- a/engines/ags/engine/ac/event.cpp
+++ b/engines/ags/engine/ac/event.cpp
@@ -69,8 +69,8 @@ int run_claimable_event(const char *tsname, bool includeRoom, int numParams, con
}
// run script modules
- for (int kk = 0; kk < _G(numScriptModules); kk++) {
- toret = RunScriptFunction(_GP(moduleInst)[kk], tsname, numParams, params);
+ for (auto &module_inst : _GP(moduleInst)) {
+ toret = RunScriptFunction(module_inst, tsname, numParams, params);
if (_G(eventClaimed) == EVENT_CLAIMED) {
_G(eventClaimed) = eventClaimedOldValue;
diff --git a/engines/ags/engine/ac/game.cpp b/engines/ags/engine/ac/game.cpp
index 8d3bbf20136..c8929dd276b 100644
--- a/engines/ags/engine/ac/game.cpp
+++ b/engines/ags/engine/ac/game.cpp
@@ -393,7 +393,7 @@ void unload_game_file() {
_GP(dialogScriptsScript).reset();
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
delete _GP(moduleInstFork)[i];
delete _GP(moduleInst)[i];
_GP(scriptModules)[i].reset();
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 7670891971f..08021c6621d 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -329,8 +329,8 @@ void AllocScriptModules() {
_GP(runDialogOptionKeyPressHandlerFunc).moduleHasFunction.resize(_G(numScriptModules), true);
_GP(runDialogOptionTextInputHandlerFunc).moduleHasFunction.resize(_G(numScriptModules), true);
_GP(runDialogOptionRepExecFunc).moduleHasFunction.resize(_G(numScriptModules), true);
- for (int i = 0; i < _G(numScriptModules); ++i) {
- _GP(moduleRepExecAddr)[i].Invalidate();
+ for (auto &val : _GP(moduleRepExecAddr)) {
+ val.Invalidate();
}
}
diff --git a/engines/ags/engine/game/savegame.cpp b/engines/ags/engine/game/savegame.cpp
index 850bc0a45e2..8f2fade20ad 100644
--- a/engines/ags/engine/game/savegame.cpp
+++ b/engines/ags/engine/game/savegame.cpp
@@ -355,7 +355,7 @@ void DoBeforeRestore(PreservedParams &pp) {
_G(gameinstFork) = nullptr;
_G(gameinst) = nullptr;
pp.ScMdDataSize.resize(_G(numScriptModules));
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
pp.ScMdDataSize[i] = _GP(moduleInst)[i]->globaldatasize;
delete _GP(moduleInstFork)[i];
delete _GP(moduleInst)[i];
@@ -467,7 +467,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
Math::Min((size_t)_G(gameinst)->globaldatasize, r_data.GlobalScript.Len));
// restore the script module data
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
if (r_data.ScriptModules[i].Data.get())
memcpy(_GP(moduleInst)[i]->globaldata, r_data.ScriptModules[i].Data.get(),
Math::Min((size_t)_GP(moduleInst)[i]->globaldatasize, r_data.ScriptModules[i].Len));
diff --git a/engines/ags/engine/game/savegame_components.cpp b/engines/ags/engine/game/savegame_components.cpp
index fb8f2f66648..c4180323ce5 100644
--- a/engines/ags/engine/game/savegame_components.cpp
+++ b/engines/ags/engine/game/savegame_components.cpp
@@ -815,7 +815,7 @@ HSaveError WriteScriptModules(Stream *out) {
out->Write(_G(gameinst)->globaldata, data_len);
// write the script modules data segments
out->WriteInt32(_G(numScriptModules));
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
data_len = _GP(moduleInst)[i]->globaldatasize;
out->WriteInt32(data_len);
if (data_len > 0)
@@ -837,7 +837,7 @@ HSaveError ReadScriptModules(Stream *in, int32_t cmp_ver, const PreservedParams
if (!AssertGameContent(err, in->ReadInt32(), _G(numScriptModules), "Script Modules"))
return err;
r_data.ScriptModules.resize(_G(numScriptModules));
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
data_len = in->ReadInt32();
if (!AssertGameObjectContent(err, data_len, pp.ScMdDataSize[i], "script module data", "module", i))
return err;
diff --git a/engines/ags/engine/game/savegame_v321.cpp b/engines/ags/engine/game/savegame_v321.cpp
index 6631ca7264d..86ec036b97d 100644
--- a/engines/ags/engine/game/savegame_v321.cpp
+++ b/engines/ags/engine/game/savegame_v321.cpp
@@ -100,7 +100,7 @@ static HSaveError restore_game_scripts(Stream *in, const PreservedParams &pp, Re
return new SavegameError(kSvgErr_GameContentAssertion, "Mismatching number of script modules.");
}
r_data.ScriptModules.resize(_G(numScriptModules));
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
int module_size = in->ReadInt32();
if (pp.ScMdDataSize[i] != module_size) {
return new SavegameError(kSvgErr_GameContentAssertion, String::FromFormat("Mismatching size of script module data, module %d.", i));
diff --git a/engines/ags/engine/script/script.cpp b/engines/ags/engine/script/script.cpp
index 0523e189682..fc6c700e85f 100644
--- a/engines/ags/engine/script/script.cpp
+++ b/engines/ags/engine/script/script.cpp
@@ -90,8 +90,8 @@ void run_function_on_non_blocking_thread(NonBlockingScriptFunction *funcToRun) {
// run modules
// modules need a forkedinst for this to work
- for (int kk = 0; kk < _G(numScriptModules); kk++) {
- funcToRun->moduleHasFunction[kk] = DoRunScriptFuncCantBlock(_GP(moduleInstFork)[kk], funcToRun, funcToRun->moduleHasFunction[kk]);
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
+ funcToRun->moduleHasFunction[i] = DoRunScriptFuncCantBlock(_GP(moduleInstFork)[i], funcToRun, funcToRun->moduleHasFunction[i]);
if (room_changes_was != _GP(play).room_changes)
return;
@@ -205,11 +205,11 @@ int create_global_script() {
ccSetOption(SCOPT_AUTOIMPORT, 1);
std::vector<ccInstance *> instances_for_resolving;
- for (int kk = 0; kk < _G(numScriptModules); kk++) {
- _GP(moduleInst)[kk] = ccInstance::CreateFromScript(_GP(scriptModules)[kk]);
- if (_GP(moduleInst)[kk] == nullptr)
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
+ _GP(moduleInst)[i] = ccInstance::CreateFromScript(_GP(scriptModules)[i]);
+ if (_GP(moduleInst)[i] == nullptr)
return kscript_create_error;
- instances_for_resolving.push_back(_GP(moduleInst)[kk]);
+ instances_for_resolving.push_back(_GP(moduleInst)[i]);
}
_G(gameinst) = ccInstance::CreateFromScript(_GP(gamescript));
@@ -235,7 +235,7 @@ int create_global_script() {
// Create the forks for 'repeatedly_execute_always' after resolving
// because they copy their respective originals including the resolve information
- for (int module_idx = 0; module_idx < _G(numScriptModules); module_idx++) {
+ for (size_t module_idx = 0; module_idx < _G(numScriptModules); module_idx++) {
_GP(moduleInstFork)[module_idx] = _GP(moduleInst)[module_idx]->Fork();
if (_GP(moduleInstFork)[module_idx] == nullptr)
return kscript_create_error;
@@ -395,7 +395,7 @@ int RunScriptFunction(ccInstance *sci, const char *tsname, size_t numParam, cons
}
void RunScriptFunctionInModules(const char *tsname, size_t param_count, const RuntimeScriptValue *params) {
- for (int i = 0; i < _G(numScriptModules); ++i)
+ for (size_t i = 0; i < _G(numScriptModules); ++i)
RunScriptFunction(_GP(moduleInst)[i], tsname, param_count, params);
RunScriptFunction(_G(gameinst), tsname, param_count, params);
}
@@ -417,7 +417,7 @@ int RunScriptFunctionInRoom(const char *tsname, size_t param_count, const Runtim
static int RunUnclaimableEvent(const char *tsname) {
const int room_changes_was = _GP(play).room_changes;
const int restore_game_count_was = _G(gameHasBeenRestored);
- for (int i = 0; i < _G(numScriptModules); ++i) {
+ for (size_t i = 0; i < _G(numScriptModules); ++i) {
if (!_GP(moduleRepExecAddr)[i].IsNull())
RunScriptFunction(_GP(moduleInst)[i], tsname);
// Break on room change or save restoration
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 53319d6df42..851eabc07ea 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -1271,7 +1271,7 @@ public:
std::vector<ccInstance *> *_moduleInst;
std::vector<ccInstance *> *_moduleInstFork;
std::vector<RuntimeScriptValue> *_moduleRepExecAddr;
- int _numScriptModules = 0;
+ size_t _numScriptModules = 0;
// TODO: find out if these extra arrays are really necessary. This may be remains from the
// time when the symbol import table was holding raw pointers to char array.
Commit: 608389c4c51c4a1b87abf0633e69321ac959bb6d
https://github.com/scummvm/scummvm/commit/608389c4c51c4a1b87abf0633e69321ac959bb6d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:05-07:00
Commit Message:
AGS: made SystemImports index an unsigned value
>From upstream 30b8f4016c815f01b49398ddb697b454f1565218
Changed paths:
engines/ags/engine/script/cc_instance.cpp
engines/ags/engine/script/cc_instance.h
engines/ags/engine/script/runtime_script_value.cpp
engines/ags/engine/script/runtime_script_value.h
engines/ags/engine/script/script_runtime.cpp
engines/ags/engine/script/system_imports.cpp
engines/ags/engine/script/system_imports.h
engines/ags/shared/core/types.h
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 3bbbc52606d..2283e12c2a1 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -483,7 +483,7 @@ int ccInstance::Run(int32_t curpc) {
codeOp.Args[i].SetStringLiteral(&codeInst->strings[0] + codeInst->code[pc_at]);
break;
case FIXUP_IMPORT: {
- const ScriptImport *import = _GP(simp).getByIndex((int32_t)codeInst->code[pc_at]);
+ const ScriptImport *import = _GP(simp).getByIndex(static_cast<uint32_t>(codeInst->code[pc_at]));
if (import) {
codeOp.Args[i] = import->Value;
} else {
@@ -1500,16 +1500,16 @@ bool ccInstance::ResolveScriptImports(const ccScript *scri) {
return true;
}
- resolved_imports = new int[numimports];
+ resolved_imports = new uint32_t[numimports];
int 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] = -1;
+ resolved_imports[import_idx] = UINT32_MAX;
continue;
}
resolved_imports[import_idx] = _GP(simp).get_index_of(scri->imports[import_idx]);
- if (resolved_imports[import_idx] < 0) {
+ if (resolved_imports[import_idx] == UINT32_MAX) {
Debug::Printf(kDbgMsg_Error, "unresolved import '%s' in '%s'", scri->imports[import_idx], scri->numSections > 0 ? scri->sectionNames[0] : "<unknown>");
errors++;
last_err_idx = import_idx;
@@ -1660,7 +1660,7 @@ bool ccInstance::CreateRuntimeCodeFixups(const ccScript *scri) {
case FIXUP_IMPORT:
break; // do nothing yet
default:
- cc_error_fixups(scri, (size_t)-1, "unknown fixup type: %d (fixup num %d)", scri->fixuptypes[i], i);
+ cc_error_fixups(scri, UINT32_MAX, "unknown fixup type: %d (fixup num %d)", scri->fixuptypes[i], i);
return false;
}
}
@@ -1673,8 +1673,8 @@ bool ccInstance::ResolveImportFixups(const ccScript *scri) {
if (scri->fixuptypes[fixup_idx] != FIXUP_IMPORT)
continue;
- int32_t const fixup = scri->fixups[fixup_idx];
- int const import_index = resolved_imports[code[fixup]];
+ uint32_t const fixup = scri->fixups[fixup_idx];
+ uint32_t const import_index = resolved_imports[code[fixup]];
ScriptImport const *import = _GP(simp).getByIndex(import_index);
if (!import) {
cc_error_fixups(scri, fixup, "cannot resolve import (bytecode pos %d, key %d)", fixup, import_index);
diff --git a/engines/ags/engine/script/cc_instance.h b/engines/ags/engine/script/cc_instance.h
index 3e8c24d6980..e7f005691e0 100644
--- a/engines/ags/engine/script/cc_instance.h
+++ b/engines/ags/engine/script/cc_instance.h
@@ -138,7 +138,7 @@ public:
ccInstance *callStackCodeInst[MAX_CALL_STACK];
// array of real import indexes used in script
- int *resolved_imports;
+ uint32_t *resolved_imports;
int numimports;
char *code_fixups;
diff --git a/engines/ags/engine/script/runtime_script_value.cpp b/engines/ags/engine/script/runtime_script_value.cpp
index faedf2d4ce1..98e800672c2 100644
--- a/engines/ags/engine/script/runtime_script_value.cpp
+++ b/engines/ags/engine/script/runtime_script_value.cpp
@@ -40,7 +40,7 @@ using namespace AGS::Shared;
// TODO: use endian-agnostic method to access global vars
-uint8_t RuntimeScriptValue::ReadByte() {
+uint8_t RuntimeScriptValue::ReadByte() const {
if (this->Type == kScValStackPtr || this->Type == kScValGlobalVar) {
if (RValue->Type == kScValData) {
return *(uint8_t *)(RValue->GetPtrWithOffset() + this->IValue);
@@ -55,7 +55,7 @@ uint8_t RuntimeScriptValue::ReadByte() {
return *((uint8_t *)this->GetPtrWithOffset());
}
-int16_t RuntimeScriptValue::ReadInt16() {
+int16_t RuntimeScriptValue::ReadInt16() const {
if (this->Type == kScValStackPtr) {
if (RValue->Type == kScValData) {
return *(int16_t *)(RValue->GetPtrWithOffset() + this->IValue);
@@ -76,7 +76,7 @@ int16_t RuntimeScriptValue::ReadInt16() {
return *((int16_t *)this->GetPtrWithOffset());
}
-int32_t RuntimeScriptValue::ReadInt32() {
+int32_t RuntimeScriptValue::ReadInt32() const {
if (this->Type == kScValStackPtr) {
if (RValue->Type == kScValData) {
return *(int32_t *)(RValue->GetPtrWithOffset() + this->IValue);
diff --git a/engines/ags/engine/script/runtime_script_value.h b/engines/ags/engine/script/runtime_script_value.h
index 377f5d2fb31..c0d898a034a 100644
--- a/engines/ags/engine/script/runtime_script_value.h
+++ b/engines/ags/engine/script/runtime_script_value.h
@@ -301,7 +301,7 @@ public:
return RuntimeScriptValue().SetInt32AsBool(!GetAsBool());
}
- inline bool operator ==(const RuntimeScriptValue &rval) {
+ inline bool operator ==(const RuntimeScriptValue &rval) const {
if (rval.Type == kScValPluginFunction) {
assert(!rval.methodName.empty());
return (Type == kScValPluginFunction) && (rval.methodName == methodName);
@@ -309,14 +309,14 @@ public:
return ((intptr_t)Ptr + (intptr_t)IValue) == ((intptr_t)rval.Ptr + (intptr_t)rval.IValue);
}
- inline bool operator !=(const RuntimeScriptValue &rval) {
+ inline bool operator !=(const RuntimeScriptValue &rval) const {
return !(*this == rval);
}
// FIXME: find out all certain cases when we are reading a pointer and store it
// as 32-bit value here. There should be a solution to distinct these cases and
// store value differently, otherwise it won't work for 64-bit build.
- inline RuntimeScriptValue ReadValue() {
+ inline RuntimeScriptValue ReadValue() const {
RuntimeScriptValue rval;
switch (this->Type) {
case kScValStackPtr: {
@@ -359,9 +359,9 @@ public:
// Helper functions for reading or writing values from/to
// object, referenced by this Runtime Value.
// Copy implementation depends on value type.
- uint8_t ReadByte();
- int16_t ReadInt16();
- int32_t ReadInt32();
+ uint8_t ReadByte() const;
+ int16_t ReadInt16() const;
+ int32_t ReadInt32() const;
bool WriteByte(uint8_t val);
bool WriteInt16(int16_t val);
bool WriteInt32(int32_t val);
diff --git a/engines/ags/engine/script/script_runtime.cpp b/engines/ags/engine/script/script_runtime.cpp
index e971a992887..8fb0541ac75 100644
--- a/engines/ags/engine/script/script_runtime.cpp
+++ b/engines/ags/engine/script/script_runtime.cpp
@@ -49,31 +49,31 @@ namespace AGS3 {
// static const char ccRunnerCopyright[] = "ScriptExecuter32 v" SCOM_VERSIONSTR " (c) 2001 Chris Jones";
bool ccAddExternalStaticFunction(const String &name, ScriptAPIFunction *pfn) {
- return _GP(simp).add(name, RuntimeScriptValue().SetStaticFunction(pfn), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetStaticFunction(pfn), nullptr) != UINT32_MAX;
}
bool ccAddExternalPluginFunction(const String &name, Plugins::ScriptContainer *instance) {
- return _GP(simp).add(name, RuntimeScriptValue().SetPluginMethod(instance, name), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetPluginMethod(instance, name), nullptr) != UINT32_MAX;
}
bool ccAddExternalStaticObject(const String &name, void *ptr, ICCStaticObject *manager) {
- return _GP(simp).add(name, RuntimeScriptValue().SetStaticObject(ptr, manager), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetStaticObject(ptr, manager), nullptr) != UINT32_MAX;
}
bool ccAddExternalStaticArray(const String &name, void *ptr, StaticArray *array_mgr) {
- return _GP(simp).add(name, RuntimeScriptValue().SetStaticArray(ptr, array_mgr), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetStaticArray(ptr, array_mgr), nullptr) != UINT32_MAX;
}
bool ccAddExternalDynamicObject(const String &name, void *ptr, ICCDynamicObject *manager) {
- return _GP(simp).add(name, RuntimeScriptValue().SetDynamicObject(ptr, manager), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetDynamicObject(ptr, manager), nullptr) != UINT32_MAX;
}
bool ccAddExternalObjectFunction(const String &name, ScriptAPIObjectFunction *pfn) {
- return _GP(simp).add(name, RuntimeScriptValue().SetObjectFunction(pfn), nullptr) == 0;
+ return _GP(simp).add(name, RuntimeScriptValue().SetObjectFunction(pfn), nullptr) != UINT32_MAX;
}
bool ccAddExternalScriptSymbol(const String &name, const RuntimeScriptValue &prval, ccInstance *inst) {
- return _GP(simp).add(name, prval, inst) == 0;
+ return _GP(simp).add(name, prval, inst) != UINT32_MAX;
}
void ccRemoveExternalSymbol(const String &name) {
diff --git a/engines/ags/engine/script/system_imports.cpp b/engines/ags/engine/script/system_imports.cpp
index fa3bf4a9ce1..a4e992e7c6f 100644
--- a/engines/ags/engine/script/system_imports.cpp
+++ b/engines/ags/engine/script/system_imports.cpp
@@ -23,18 +23,16 @@
namespace AGS3 {
-extern void quit(const char *);
-
-int SystemImports::add(const String &name, const RuntimeScriptValue &value, ccInstance *anotherscr) {
- int ixof;
-
- if ((ixof = get_index_of(name)) >= 0) {
+uint32_t SystemImports::add(const String &name, const RuntimeScriptValue &value, ccInstance *anotherscr) {
+ uint32_t ixof = get_index_of(name);
+ // Check if symbol already exists
+ if (ixof != UINT32_MAX) {
// Only allow override if not a script-exported function
if (anotherscr == nullptr) {
imports[ixof].Value = value;
imports[ixof].InstancePtr = anotherscr;
}
- return 0;
+ return ixof;
}
ixof = imports.size();
@@ -46,17 +44,17 @@ int SystemImports::add(const String &name, const RuntimeScriptValue &value, ccIn
}
btree[name] = ixof;
- if (ixof == (int)imports.size())
+ if (ixof == imports.size())
imports.push_back(ScriptImport());
- imports[ixof].Name = name; // TODO: rather make a string copy here for safety reasons
+ imports[ixof].Name = name;
imports[ixof].Value = value;
imports[ixof].InstancePtr = anotherscr;
- return 0;
+ return ixof;
}
void SystemImports::remove(const String &name) {
- int idx = get_index_of(name);
- if (idx < 0)
+ uint32_t idx = get_index_of(name);
+ if (idx == UINT32_MAX)
return;
btree.erase(imports[idx].Name);
imports[idx].Name = nullptr;
@@ -65,21 +63,21 @@ void SystemImports::remove(const String &name) {
}
const ScriptImport *SystemImports::getByName(const String &name) {
- int o = get_index_of(name);
- if (o < 0)
+ uint32_t o = get_index_of(name);
+ if (o == UINT32_MAX)
return nullptr;
return &imports[o];
}
-const ScriptImport *SystemImports::getByIndex(int index) {
- if ((size_t)index >= imports.size())
+const ScriptImport *SystemImports::getByIndex(uint32_t index) {
+ if (index >= imports.size())
return nullptr;
return &imports[index];
}
-int SystemImports::get_index_of(const String &name) {
+uint32_t SystemImports::get_index_of(const String &name) {
IndexMap::const_iterator it = btree.find(name);
if (it != btree.end())
return it->_value;
@@ -99,14 +97,13 @@ int SystemImports::get_index_of(const String &name) {
return get_index_of(name.Left(c));
}
}
-
- return -1;
+ return UINT32_MAX;
}
String SystemImports::findName(const RuntimeScriptValue &value) {
- for (size_t i = 0; i < imports.size(); ++i) {
- if (imports[i].Value == value) {
- return imports[i].Name;
+ for (const auto &import : imports) {
+ if (import.Value == value) {
+ return import.Name;
}
}
return String();
@@ -117,15 +114,15 @@ void SystemImports::RemoveScriptExports(ccInstance *inst) {
return;
}
- for (size_t i = 0; i < imports.size(); ++i) {
- if (imports[i].Name == nullptr)
+ for (auto &import : imports) {
+ if (import.Name == nullptr)
continue;
- if (imports[i].InstancePtr == inst) {
- btree.erase(imports[i].Name);
- imports[i].Name = nullptr;
- imports[i].Value.Invalidate();
- imports[i].InstancePtr = nullptr;
+ if (import.InstancePtr == inst) {
+ btree.erase(import.Name);
+ import.Name = nullptr;
+ import.Value.Invalidate();
+ import.InstancePtr = nullptr;
}
}
}
diff --git a/engines/ags/engine/script/system_imports.h b/engines/ags/engine/script/system_imports.h
index 5d9e5eea6ce..742808d8162 100644
--- a/engines/ags/engine/script/system_imports.h
+++ b/engines/ags/engine/script/system_imports.h
@@ -46,17 +46,17 @@ struct SystemImports {
private:
// Note we can't use a hash-map here, because we sometimes need to search
// by partial keys.
- typedef std::map<String, int> IndexMap;
+ typedef std::map<String, uint32_t> IndexMap;
std::vector<ScriptImport> imports;
IndexMap btree;
public:
- int add(const String &name, const RuntimeScriptValue &value, ccInstance *inst);
+ uint32_t add(const String &name, const RuntimeScriptValue &value, ccInstance *inst);
void remove(const String &name);
const ScriptImport *getByName(const String &name);
- int get_index_of(const String &name);
- const ScriptImport *getByIndex(int index);
+ uint32_t get_index_of(const String &name);
+ const ScriptImport *getByIndex(uint32_t index);
String findName(const RuntimeScriptValue &value);
void RemoveScriptExports(ccInstance *inst);
void clear();
diff --git a/engines/ags/shared/core/types.h b/engines/ags/shared/core/types.h
index 3c36d03d2cf..8408e1ad504 100644
--- a/engines/ags/shared/core/types.h
+++ b/engines/ags/shared/core/types.h
@@ -76,6 +76,7 @@ typedef int64 intptr_t;
#undef INT32_MAX
#undef INT_MIN
#undef INT_MAX
+#undef UINT32_MAX
#undef UINT_MAX
#undef SIZE_MAX
#define INT16_MIN -32768
@@ -87,6 +88,7 @@ typedef int64 intptr_t;
#define INT_MAX 2147483647
#define UINT_MAX 0xffffffff
#define SIZE_MAX 0xffffffff
+#define UINT32_MAX 0xffffffff
#undef TRUE
#undef FALSE
Commit: 043f80a2375574083435997808ffe120dc958e5e
https://github.com/scummvm/scummvm/commit/043f80a2375574083435997808ffe120dc958e5e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:05-07:00
Commit Message:
AGS: Avoid using global "game" in game_init because it's possible
>From upstream 4041a18e7c1744aa59773da19de40b51bdc78a49
Changed paths:
engines/ags/engine/game/game_init.cpp
diff --git a/engines/ags/engine/game/game_init.cpp b/engines/ags/engine/game/game_init.cpp
index 08021c6621d..c8f1e4d1d8e 100644
--- a/engines/ags/engine/game/game_init.cpp
+++ b/engines/ags/engine/game/game_init.cpp
@@ -71,7 +71,7 @@ String GetGameInitErrorText(GameInitErrorType err) {
case kGameInitErr_NoError:
return "No error.";
case kGameInitErr_NoFonts:
- return "No fonts specified to be used in this _GP(game).";
+ return "No fonts specified to be used in this game.";
case kGameInitErr_TooManyAudioTypes:
return "Too many audio types for this engine to handle.";
case kGameInitErr_EntityInitFail:
@@ -89,57 +89,57 @@ String GetGameInitErrorText(GameInitErrorType err) {
}
// Initializes audio channels and clips and registers them in the script system
-void InitAndRegisterAudioObjects() {
- for (int i = 0; i < _GP(game).numGameChannels; ++i) {
+void InitAndRegisterAudioObjects(GameSetupStruct &game) {
+ for (int i = 0; i < game.numGameChannels; ++i) {
_G(scrAudioChannel)[i].id = i;
ccRegisterManagedObject(&_G(scrAudioChannel)[i], &_GP(ccDynamicAudio));
}
- for (size_t i = 0; i < _GP(game).audioClips.size(); ++i) {
+ for (size_t i = 0; i < game.audioClips.size(); ++i) {
// Note that as of 3.5.0 data format the clip IDs are still restricted
// to actual item index in array, so we don't make any difference
// between game versions, for now.
- _GP(game).audioClips[i].id = i;
- ccRegisterManagedObject(&_GP(game).audioClips[i], &_GP(ccDynamicAudioClip));
- ccAddExternalDynamicObject(_GP(game).audioClips[i].scriptName, &_GP(game).audioClips[i], &_GP(ccDynamicAudioClip));
+ game.audioClips[i].id = i;
+ ccRegisterManagedObject(&game.audioClips[i], &_GP(ccDynamicAudioClip));
+ ccAddExternalDynamicObject(game.audioClips[i].scriptName, &game.audioClips[i], &_GP(ccDynamicAudioClip));
}
}
// Initializes characters and registers them in the script system
-void InitAndRegisterCharacters() {
- _GP(characterScriptObjNames).resize(_GP(game).numcharacters);
- for (int i = 0; i < _GP(game).numcharacters; ++i) {
- _GP(game).chars[i].walking = 0;
- _GP(game).chars[i].animating = 0;
- _GP(game).chars[i].pic_xoffs = 0;
- _GP(game).chars[i].pic_yoffs = 0;
- _GP(game).chars[i].blinkinterval = 140;
- _GP(game).chars[i].blinktimer = _GP(game).chars[i].blinkinterval;
- _GP(game).chars[i].index_id = i;
- _GP(game).chars[i].blocking_width = 0;
- _GP(game).chars[i].blocking_height = 0;
- _GP(game).chars[i].prevroom = -1;
- _GP(game).chars[i].loop = 0;
- _GP(game).chars[i].frame = 0;
- _GP(game).chars[i].walkwait = -1;
- ccRegisterManagedObject(&_GP(game).chars[i], &_GP(ccDynamicCharacter));
+void InitAndRegisterCharacters(GameSetupStruct &game) {
+ _GP(characterScriptObjNames).resize(game.numcharacters);
+ for (int i = 0; i < game.numcharacters; ++i) {
+ game.chars[i].walking = 0;
+ game.chars[i].animating = 0;
+ game.chars[i].pic_xoffs = 0;
+ game.chars[i].pic_yoffs = 0;
+ game.chars[i].blinkinterval = 140;
+ game.chars[i].blinktimer = game.chars[i].blinkinterval;
+ game.chars[i].index_id = i;
+ game.chars[i].blocking_width = 0;
+ game.chars[i].blocking_height = 0;
+ game.chars[i].prevroom = -1;
+ game.chars[i].loop = 0;
+ game.chars[i].frame = 0;
+ game.chars[i].walkwait = -1;
+ ccRegisterManagedObject(&game.chars[i], &_GP(ccDynamicCharacter));
// export the character's script object
- _GP(characterScriptObjNames)[i] = _GP(game).chars[i].scrname;
- ccAddExternalDynamicObject(_GP(characterScriptObjNames)[i], &_GP(game).chars[i], &_GP(ccDynamicCharacter));
+ _GP(characterScriptObjNames)[i] = game.chars[i].scrname;
+ ccAddExternalDynamicObject(_GP(characterScriptObjNames)[i], &game.chars[i], &_GP(ccDynamicCharacter));
}
}
// Initializes dialog and registers them in the script system
-void InitAndRegisterDialogs() {
- _G(scrDialog) = new ScriptDialog[_GP(game).numdialog];
- for (int i = 0; i < _GP(game).numdialog; ++i) {
+void InitAndRegisterDialogs(GameSetupStruct &game) {
+ _G(scrDialog) = new ScriptDialog[game.numdialog];
+ for (int i = 0; i < game.numdialog; ++i) {
_G(scrDialog)[i].id = i;
_G(scrDialog)[i].reserved = 0;
ccRegisterManagedObject(&_G(scrDialog)[i], &_GP(ccDynamicDialog));
- if (!_GP(game).dialogScriptNames[i].IsEmpty())
- ccAddExternalDynamicObject(_GP(game).dialogScriptNames[i], &_G(scrDialog)[i], &_GP(ccDynamicDialog));
+ if (!game.dialogScriptNames[i].IsEmpty())
+ ccAddExternalDynamicObject(game.dialogScriptNames[i], &_G(scrDialog)[i], &_GP(ccDynamicDialog));
}
}
@@ -154,14 +154,14 @@ void InitAndRegisterDialogOptions() {
}
// Initializes gui and registers them in the script system
-HError InitAndRegisterGUI() {
- _G(scrGui) = (ScriptGUI *)malloc(sizeof(ScriptGUI) * _GP(game).numgui);
- for (int i = 0; i < _GP(game).numgui; ++i) {
+HError InitAndRegisterGUI(GameSetupStruct &game) {
+ _G(scrGui) = (ScriptGUI *)malloc(sizeof(ScriptGUI) * game.numgui);
+ for (int i = 0; i < game.numgui; ++i) {
_G(scrGui)[i].id = -1;
}
- _GP(guiScriptObjNames).resize(_GP(game).numgui);
- for (int i = 0; i < _GP(game).numgui; ++i) {
+ _GP(guiScriptObjNames).resize(game.numgui);
+ for (int i = 0; i < game.numgui; ++i) {
// link controls to their parent guis
HError err = _GP(guis)[i].RebuildArray();
if (!err)
@@ -179,14 +179,14 @@ HError InitAndRegisterGUI() {
}
// Initializes inventory items and registers them in the script system
-void InitAndRegisterInvItems() {
+void InitAndRegisterInvItems(GameSetupStruct &game) {
for (int i = 0; i < MAX_INV; ++i) {
_G(scrInv)[i].id = i;
_G(scrInv)[i].reserved = 0;
ccRegisterManagedObject(&_G(scrInv)[i], &_GP(ccDynamicInv));
- if (!_GP(game).invScriptNames[i].IsEmpty())
- ccAddExternalDynamicObject(_GP(game).invScriptNames[i], &_G(scrInv)[i], &_GP(ccDynamicInv));
+ if (!game.invScriptNames[i].IsEmpty())
+ ccAddExternalDynamicObject(game.invScriptNames[i], &_G(scrInv)[i], &_GP(ccDynamicInv));
}
}
@@ -216,7 +216,7 @@ void InitAndRegisterRegions() {
}
// Registers static entity arrays in the script system
-void RegisterStaticArrays() {
+void RegisterStaticArrays(GameSetupStruct &game) {
_GP(StaticCharacterArray).Create(&_GP(ccDynamicCharacter), sizeof(CharacterInfo), sizeof(CharacterInfo));
_GP(StaticObjectArray).Create(&_GP(ccDynamicObject), sizeof(ScriptObject), sizeof(ScriptObject));
_GP(StaticGUIArray).Create(&_GP(ccDynamicGUI), sizeof(ScriptGUI), sizeof(ScriptGUI));
@@ -225,7 +225,7 @@ void RegisterStaticArrays() {
_GP(StaticInventoryArray).Create(&_GP(ccDynamicInv), sizeof(ScriptInvItem), sizeof(ScriptInvItem));
_GP(StaticDialogArray).Create(&_GP(ccDynamicDialog), sizeof(ScriptDialog), sizeof(ScriptDialog));
- ccAddExternalStaticArray("character", &_GP(game).chars[0], &_GP(StaticCharacterArray));
+ ccAddExternalStaticArray("character", &game.chars[0], &_GP(StaticCharacterArray));
ccAddExternalStaticArray("object", &_G(scrObj)[0], &_GP(StaticObjectArray));
ccAddExternalStaticArray("gui", &_G(scrGui)[0], &_GP(StaticGUIArray));
ccAddExternalStaticArray("hotspot", &_G(scrHotspot)[0], &_GP(StaticHotspotArray));
@@ -235,24 +235,24 @@ void RegisterStaticArrays() {
}
// Initializes various game entities and registers them in the script system
-HError InitAndRegisterGameEntities() {
- InitAndRegisterAudioObjects();
- InitAndRegisterCharacters();
- InitAndRegisterDialogs();
+HError InitAndRegisterGameEntities(GameSetupStruct &game) {
+ InitAndRegisterAudioObjects(game);
+ InitAndRegisterCharacters(game);
+ InitAndRegisterDialogs(game);
InitAndRegisterDialogOptions();
- HError err = InitAndRegisterGUI();
+ HError err = InitAndRegisterGUI(game);
if (!err)
return err;
- InitAndRegisterInvItems();
+ InitAndRegisterInvItems(game);
InitAndRegisterHotspots();
InitAndRegisterRegions();
InitAndRegisterRoomObjects();
_GP(play).CreatePrimaryViewportAndCamera();
- RegisterStaticArrays();
+ RegisterStaticArrays(game);
- setup_player_character(_GP(game).playercharacter);
+ setup_player_character(game.playercharacter);
if (_G(loaded_game_file_version) >= kGameVersion_270)
ccAddExternalStaticObject("player", &_G(sc_PlayerCharPtr), &_GP(GlobalStaticManager));
return HError::None();
@@ -379,7 +379,7 @@ HGameInitError InitGameState(const LoadedGameEntities &ents, GameDataVersion dat
else
game.numGameChannels = MAX_GAME_CHANNELS;
- HError err = InitAndRegisterGameEntities();
+ HError err = InitAndRegisterGameEntities(game);
if (!err)
return new GameInitError(kGameInitErr_EntityInitFail, err);
LoadFonts(game, data_ver);
Commit: 67628b9c6aa15392f18f9c896dcac13ee96ce32d
https://github.com/scummvm/scummvm/commit/67628b9c6aa15392f18f9c896dcac13ee96ce32d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:05-07:00
Commit Message:
AGS: Suppress endless "unused param" warnings in script api
>From upstream b4a5ec72c059bc3c65e89a45a8b1218068a2015a
Changed paths:
engines/ags/engine/ac/character.cpp
engines/ags/engine/ac/drawing_surface.cpp
engines/ags/engine/ac/global_api.cpp
engines/ags/engine/ac/hotspot.cpp
engines/ags/engine/ac/region.cpp
engines/ags/engine/ac/speech.cpp
engines/ags/engine/script/script_api.h
diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index 2e76806895a..77d60940bd7 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -3546,7 +3546,7 @@ void ScPl_Character_Think(CharacterInfo *chaa, const char *texx, ...) {
Character_Think(chaa, scsf_buffer);
}
-void RegisterCharacterAPI(ScriptAPIVersion base_api, ScriptAPIVersion compat_api) {
+void RegisterCharacterAPI(ScriptAPIVersion base_api, ScriptAPIVersion /* compat_api */) {
ccAddExternalObjectFunction("Character::AddInventory^2", Sc_Character_AddInventory);
ccAddExternalObjectFunction("Character::AddWaypoint^2", Sc_Character_AddWaypoint);
ccAddExternalObjectFunction("Character::Animate^5", Sc_Character_Animate);
diff --git a/engines/ags/engine/ac/drawing_surface.cpp b/engines/ags/engine/ac/drawing_surface.cpp
index edf05cc3c5b..2ba4883f5a8 100644
--- a/engines/ags/engine/ac/drawing_surface.cpp
+++ b/engines/ags/engine/ac/drawing_surface.cpp
@@ -550,7 +550,7 @@ RuntimeScriptValue Sc_DrawingSurface_GetWidth(void *self, const RuntimeScriptVal
//
//=============================================================================
-void RegisterDrawingSurfaceAPI(ScriptAPIVersion base_api, ScriptAPIVersion compat_api) {
+void RegisterDrawingSurfaceAPI(ScriptAPIVersion base_api, ScriptAPIVersion /*compat_api */) {
ccAddExternalObjectFunction("DrawingSurface::Clear^1", Sc_DrawingSurface_Clear);
ccAddExternalObjectFunction("DrawingSurface::CreateCopy^0", Sc_DrawingSurface_CreateCopy);
ccAddExternalObjectFunction("DrawingSurface::DrawCircle^3", Sc_DrawingSurface_DrawCircle);
diff --git a/engines/ags/engine/ac/global_api.cpp b/engines/ags/engine/ac/global_api.cpp
index 0a9faace09a..bf48cd21a51 100644
--- a/engines/ags/engine/ac/global_api.cpp
+++ b/engines/ags/engine/ac/global_api.cpp
@@ -717,11 +717,13 @@ RuntimeScriptValue Sc_GetWalkableAreaAtScreen(const RuntimeScriptValue *params,
}
RuntimeScriptValue Sc_GetDrawingSurfaceForWalkableArea(const RuntimeScriptValue *params, int32_t param_count) {
+ (void)params; (void)param_count;
ScriptDrawingSurface *ret_obj = Room_GetDrawingSurfaceForMask(kRoomAreaWalkable);
return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj);
}
RuntimeScriptValue Sc_GetDrawingSurfaceForWalkbehind(const RuntimeScriptValue *params, int32_t param_count) {
+ (void)params; (void)param_count;
ScriptDrawingSurface *ret_obj = Room_GetDrawingSurfaceForMask(kRoomAreaWalkBehind);
return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj);
}
diff --git a/engines/ags/engine/ac/hotspot.cpp b/engines/ags/engine/ac/hotspot.cpp
index 1e1f155c3ff..9a50a308081 100644
--- a/engines/ags/engine/ac/hotspot.cpp
+++ b/engines/ags/engine/ac/hotspot.cpp
@@ -147,6 +147,7 @@ RuntimeScriptValue Sc_GetHotspotAtScreen(const RuntimeScriptValue *params, int32
}
RuntimeScriptValue Sc_Hotspot_GetDrawingSurface(const RuntimeScriptValue *params, int32_t param_count) {
+ (void)params; (void)param_count;
ScriptDrawingSurface *ret_obj = Room_GetDrawingSurfaceForMask(kRoomAreaHotspot);
return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj);
}
diff --git a/engines/ags/engine/ac/region.cpp b/engines/ags/engine/ac/region.cpp
index f4cc92bb1d7..4de875483ee 100644
--- a/engines/ags/engine/ac/region.cpp
+++ b/engines/ags/engine/ac/region.cpp
@@ -140,6 +140,7 @@ RuntimeScriptValue Sc_GetRegionAtScreen(const RuntimeScriptValue *params, int32_
}
RuntimeScriptValue Sc_Region_GetDrawingSurface(const RuntimeScriptValue *params, int32_t param_count) {
+ (void)params; (void)param_count;
ScriptDrawingSurface *ret_obj = Room_GetDrawingSurfaceForMask(kRoomAreaRegion);
return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj);
}
diff --git a/engines/ags/engine/ac/speech.cpp b/engines/ags/engine/ac/speech.cpp
index 1d491b09561..17efec2e829 100644
--- a/engines/ags/engine/ac/speech.cpp
+++ b/engines/ags/engine/ac/speech.cpp
@@ -266,7 +266,7 @@ RuntimeScriptValue Sc_Speech_GetPortraitOverlay(const RuntimeScriptValue *params
extern RuntimeScriptValue Sc_SetVoiceMode(const RuntimeScriptValue *params, int32_t param_count);
-void RegisterSpeechAPI(ScriptAPIVersion base_api, ScriptAPIVersion compat_api) {
+void RegisterSpeechAPI(ScriptAPIVersion base_api, ScriptAPIVersion /*compat_api*/) {
ccAddExternalStaticFunction("Speech::get_AnimationStopTimeMargin", Sc_Speech_GetAnimationStopTimeMargin);
ccAddExternalStaticFunction("Speech::set_AnimationStopTimeMargin", Sc_Speech_SetAnimationStopTimeMargin);
ccAddExternalStaticFunction("Speech::get_CustomPortraitPlacement", Sc_Speech_GetCustomPortraitPlacement);
diff --git a/engines/ags/engine/script/script_api.h b/engines/ags/engine/script/script_api.h
index 0c49950028f..3670c05ee36 100644
--- a/engines/ags/engine/script/script_api.h
+++ b/engines/ags/engine/script/script_api.h
@@ -58,21 +58,26 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return ScriptSprintf(buffer, buf_length, format, nullptr, 0, &arg_ptr);
}
-// Helper macros for script functions
+// Helper macros for script functions;
+// asserting for internal mistakes; supressing "unused param" warnings
#define ASSERT_SELF(METHOD) \
- assert((self != NULL) && "Object pointer is null in call to API function")
+ (void)params; (void)param_count; \
+ assert((self != NULL) && "Object pointer is null in call to API function")
#define ASSERT_PARAM_COUNT(FUNCTION, X) \
- assert((params != NULL && param_count >= X) && "Not enough parameters in call to API function")
+ (void)params; (void)param_count; \
+ assert((params != NULL && param_count >= X) && "Not enough parameters in call to API function")
#define ASSERT_VARIABLE_VALUE(VARIABLE) \
- assert((params != NULL && param_count >= 1) && "Not enough parameters to set API property")
+ (void)params; (void)param_count; \
+ assert((params != NULL && param_count >= 1) && "Not enough parameters to set API property")
#define ASSERT_OBJ_PARAM_COUNT(METHOD, X) \
- ASSERT_SELF(METHOD); \
- ASSERT_PARAM_COUNT(METHOD, X)
+ ASSERT_SELF(METHOD); \
+ ASSERT_PARAM_COUNT(METHOD, X)
//-----------------------------------------------------------------------------
// Get/set variables
#define API_VARGET_INT(VARIABLE) \
+ (void)params; (void)param_count; \
return RuntimeScriptValue().SetInt32(VARIABLE)
#define API_VARSET_PINT(VARIABLE) \
@@ -123,6 +128,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
//
#define API_SCALL_VOID(FUNCTION) \
+ (void)params; (void)param_count; \
FUNCTION(); \
return RuntimeScriptValue((int32_t)0)
@@ -212,6 +218,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return RuntimeScriptValue((int32_t)0)
#define API_SCALL_INT(FUNCTION) \
+ (void)params; (void)param_count; \
return RuntimeScriptValue().SetInt32(FUNCTION())
#define API_SCALL_INT_PINT(FUNCTION) \
@@ -263,6 +270,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return RuntimeScriptValue().SetInt32(FUNCTION(params[0].IValue, (P1CLASS*)params[1].Ptr))
#define API_SCALL_FLOAT(FUNCTION) \
+ (void)params; (void)param_count; \
return RuntimeScriptValue().SetFloat(FUNCTION())
#define API_SCALL_FLOAT_PINT(FUNCTION) \
@@ -278,6 +286,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return RuntimeScriptValue().SetFloat(FUNCTION(params[0].FValue, params[1].FValue))
#define API_SCALL_BOOL(FUNCTION) \
+ (void)params; (void)param_count; \
return RuntimeScriptValue().SetInt32AsBool(FUNCTION())
#define API_SCALL_BOOL_POBJ(FUNCTION, P1CLASS) \
@@ -297,6 +306,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return RuntimeScriptValue().SetInt32AsBool(FUNCTION((P1CLASS*)params[0].Ptr, (P2CLASS*)params[1].Ptr))
#define API_SCALL_OBJ(RET_CLASS, RET_MGR, FUNCTION) \
+ (void)params; (void)param_count; \
return RuntimeScriptValue().SetDynamicObject((void*)(RET_CLASS*)FUNCTION(), &RET_MGR)
#define API_CONST_SCALL_OBJ(RET_CLASS, RET_MGR, FUNCTION) \
@@ -335,6 +345,7 @@ inline const char *ScriptVSprintf(char *buffer, size_t buf_length, const char *f
return RuntimeScriptValue().SetDynamicObject(const_cast<void *>((const void *)(RET_CLASS*)FUNCTION((P1CLASS*)params[0].Ptr)), &RET_MGR)
#define API_SCALL_OBJAUTO(RET_CLASS, FUNCTION) \
+ (void)params; (void)param_count; \
RET_CLASS* ret_obj = FUNCTION(); \
return RuntimeScriptValue().SetDynamicObject(ret_obj, ret_obj)
Commit: 78312259b79edeabc44cfadb4ffbfcdf7c5f700d
https://github.com/scummvm/scummvm/commit/78312259b79edeabc44cfadb4ffbfcdf7c5f700d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-24T16:00:06-07:00
Commit Message:
AGS: Typecast warning fixes in (de)compression functions
>From upstream ba8dae7788e764516d07511b00b36f904131b327
Changed paths:
engines/ags/globals.h
engines/ags/shared/util/compress.cpp
engines/ags/shared/util/lzw.cpp
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 851eabc07ea..4454d35150b 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -1053,7 +1053,7 @@ public:
* @{
*/
- char *_lzbuffer = nullptr;
+ uint8_t *_lzbuffer = nullptr;
int *_node = nullptr;
int _pos = 0;
size_t _outbytes = 0, _maxsize = 0, _putbytes = 0;
diff --git a/engines/ags/shared/util/compress.cpp b/engines/ags/shared/util/compress.cpp
index a123fa88c0b..13f3394c343 100644
--- a/engines/ags/shared/util/compress.cpp
+++ b/engines/ags/shared/util/compress.cpp
@@ -42,14 +42,14 @@ static void cpackbitl(const uint8_t *line, size_t size, Stream *out) {
size_t cnt = 0; // bytes encoded
while (cnt < size) {
- // note that the algorithm below requires signed operations
- int i = cnt;
+ // IMPORTANT: the algorithm below requires signed operations
+ int i = static_cast<int32_t>(cnt);
int j = i + 1;
int jmax = i + 126;
- if ((size_t)jmax >= size)
+ if (static_cast<uint32_t>(jmax) >= size)
jmax = size - 1;
- if (i == (int)size - 1) { //................last byte alone
+ if (static_cast<uint32_t>(i) == size - 1) { //......last byte alone
out->WriteInt8(0);
out->WriteInt8(line[i]);
cnt++;
@@ -78,14 +78,14 @@ static void cpackbitl16(const uint16_t *line, size_t size, Stream *out) {
size_t cnt = 0; // bytes encoded
while (cnt < size) {
- // note that the algorithm below requires signed operations
+ // IMPORTANT: the algorithm below requires signed operations
int i = cnt;
int j = i + 1;
int jmax = i + 126;
- if ((size_t)jmax >= size)
+ if (static_cast<uint32_t>(jmax) >= size)
jmax = size - 1;
- if (i == (int)size - 1) { //................last byte alone
+ if (static_cast<uint32_t>(i) == size - 1) { //......last byte alone
out->WriteInt8(0);
out->WriteInt16(line[i]);
cnt++;
@@ -114,14 +114,14 @@ static void cpackbitl32(const uint32_t *line, size_t size, Stream *out) {
size_t cnt = 0; // bytes encoded
while (cnt < size) {
- // note that the algorithm below requires signed operations
+ // IMPORTANT: the algorithm below requires signed operations
int i = cnt;
int j = i + 1;
int jmax = i + 126;
- if ((size_t)jmax >= size)
+ if (static_cast<uint32_t>(jmax) >= size)
jmax = size - 1;
- if (i == (int)size - 1) { //................last byte alone
+ if (static_cast<uint32_t>(i) == size - 1) { //......last byte alone
out->WriteInt8(0);
out->WriteInt32(line[i]);
cnt++;
diff --git a/engines/ags/shared/util/lzw.cpp b/engines/ags/shared/util/lzw.cpp
index 41714a9446e..5ba42212a31 100644
--- a/engines/ags/shared/util/lzw.cpp
+++ b/engines/ags/shared/util/lzw.cpp
@@ -61,7 +61,7 @@ int insert(int i, int run) {
k = l = 1;
match = THRESHOLD - 1;
- p = &root[(unsigned char)_G(lzbuffer)[i]];
+ p = &root[_G(lzbuffer)[i]];
lson[i] = rson[i] = NIL;
while ((j = *p) != NIL) {
for (n = min(k, l); n < run && (c = (_G(lzbuffer)[j + n] - _G(lzbuffer)[i + n])) == 0; n++);
@@ -125,9 +125,9 @@ void _delete(int z) {
bool lzwcompress(Stream *lzw_in, Stream *out) {
int ch, i, run, len, match, size, mask;
- char buf[17];
+ uint8_t buf[17];
- _G(lzbuffer) = (char *)malloc(N + F + (N + 1 + N + N + 256) * sizeof(int)); // 28.5 k !
+ _G(lzbuffer) = (uint8_t *)malloc(N + F + (N + 1 + N + N + 256) * sizeof(int)); // 28.5 k !
if (_G(lzbuffer) == nullptr) {
return false;
}
@@ -144,7 +144,7 @@ bool lzwcompress(Stream *lzw_in, Stream *out) {
i = N - F - F;
for (len = 0; len < F && (ch = lzw_in->ReadByte()) != -1; len++) {
- _G(lzbuffer)[i + F] = ch;
+ _G(lzbuffer)[i + F] = static_cast<uint8_t>(ch);
i = (i + 1) & (N - 1);
}
@@ -154,10 +154,10 @@ bool lzwcompress(Stream *lzw_in, Stream *out) {
ch = lzw_in->ReadByte();
if (i >= N - F) {
_delete(i + F - N);
- _G(lzbuffer)[i + F] = _G(lzbuffer)[i + F - N] = ch;
+ _G(lzbuffer)[i + F] = _G(lzbuffer)[i + F - N] = static_cast<uint8_t>(ch);
} else {
_delete(i + F);
- _G(lzbuffer)[i + F] = ch;
+ _G(lzbuffer)[i + F] = static_cast<uint8_t>(ch);
}
match = insert(i, run);
@@ -170,7 +170,7 @@ bool lzwcompress(Stream *lzw_in, Stream *out) {
if (match >= THRESHOLD) {
buf[0] |= mask;
// possible fix: change int* to short* ??
- *(short *)(buf + size) = ((match - 3) << 12) | ((i - _G(pos) - 1) & (N - 1));
+ *(short *)(buf + size) = static_cast<short>(((match - 3) << 12) | ((i - _G(pos) - 1) & (N - 1)));
size += 2;
len -= match;
} else {
@@ -197,7 +197,7 @@ bool lzwcompress(Stream *lzw_in, Stream *out) {
return true;
}
-void myputc(int ccc, Stream *out) {
+inline void myputc(uint8_t ccc, Stream *out) {
if (_G(maxsize) > 0) {
_G(putbytes)++;
if (_G(putbytes) > _G(maxsize))
More information about the Scummvm-git-logs
mailing list