[Scummvm-git-logs] scummvm master -> d2f3f2319b14fce4b614fe18060445593081c5d5
dreammaster
noreply at scummvm.org
Thu Apr 28 04:26:36 UTC 2022
This automated email contains information about 10 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
ae0609ae51 AGS: in the new key input mode, only update key state once a frame
1ba7d8435f AGS: Scale debug overlays when necessary
8f01b30061 AGS: Reactored ScriptOverlay, removed duplicate offset variables
8ecb108f93 AGS: Rename ScriptOverlay's member to better reflect its purpose
7b0bfee7cc AGS: Renamed and moved INIread/write functions for proper org&style
23a2e8c709 AGS: More config parse helpers: reading boolean ints, min-max range
68e5184afa AGS: Replaced some (v)sprintfs with sNprintf counterparts
d6cf666e42 AGS: Fixed StrUtil::StringToFloat()
72f8cbd0dc AGS: fixed few more warnings
d2f3f2319b AGS: Updated build version (3.6.0.22)
Commit: ae0609ae51e308df7425b1c364cb011748924f84
https://github.com/scummvm/scummvm/commit/ae0609ae51e308df7425b1c364cb011748924f84
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T19:31:40-07:00
Commit Message:
AGS: in the new key input mode, only update key state once a frame
>From upstream 8c456d2e4b3c9e24f883522b59b4c73d422e4c28
Not sure if this will actually do so, since there may be other places
in the ScummVM event handler where event polling may be done.
Changed paths:
engines/ags/engine/ac/sys_events.cpp
engines/ags/events.cpp
engines/ags/events.h
diff --git a/engines/ags/engine/ac/sys_events.cpp b/engines/ags/engine/ac/sys_events.cpp
index 38ffc2549ed..38ded9e6300 100644
--- a/engines/ags/engine/ac/sys_events.cpp
+++ b/engines/ags/engine/ac/sys_events.cpp
@@ -79,7 +79,7 @@ Common::Event ags_get_next_keyevent() {
}
int ags_iskeydown(eAGSKeyCode ags_key) {
- return ::AGS::g_events->isKeyPressed(ags_key);
+ return ::AGS::g_events->isKeyPressed(ags_key, _GP(game).options[OPT_KEYHANDLEAPI] == 0);
}
void ags_simulate_keypress(eAGSKeyCode ags_key) {
diff --git a/engines/ags/events.cpp b/engines/ags/events.cpp
index c76b4d5b582..1b03fac3441 100644
--- a/engines/ags/events.cpp
+++ b/engines/ags/events.cpp
@@ -157,8 +157,9 @@ void EventsManager::updateKeys(const Common::Event &event, bool isDown) {
_keys[event.kbd.keycode] = isDown;
}
-bool EventsManager::isKeyPressed(AGS3::eAGSKeyCode key) {
- pollEvents();
+bool EventsManager::isKeyPressed(AGS3::eAGSKeyCode key, bool poll) {
+ if (poll)
+ pollEvents();
Common::KeyCode kc[3];
if (!ags_key_to_scancode(key, kc))
diff --git a/engines/ags/events.h b/engines/ags/events.h
index c1de5f2a1e9..2ee363c3de3 100644
--- a/engines/ags/events.h
+++ b/engines/ags/events.h
@@ -105,7 +105,7 @@ public:
/**
* Returns true if a given key is pressed
*/
- bool isKeyPressed(AGS3::eAGSKeyCode key);
+ bool isKeyPressed(AGS3::eAGSKeyCode key, bool poll = true);
void clearEvents() {
_pendingEvents.clear();
Commit: 1ba7d8435f71a64e89e7c06a37c1d69a65362ca9
https://github.com/scummvm/scummvm/commit/1ba7d8435f71a64e89e7c06a37c1d69a65362ca9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:25:25-07:00
Commit Message:
AGS: Scale debug overlays when necessary
>From upstream cbbf2a0f8344fa4a5f7d91de927636c208bc446d
Changed paths:
engines/ags/engine/ac/draw.cpp
engines/ags/globals.cpp
engines/ags/globals.h
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index bce6d50b5aa..24be7797cb4 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -385,11 +385,11 @@ void dispose_game_drawdata() {
}
static void dispose_debug_room_drawdata() {
+ _GP(debugRoomMaskBmp).reset();
if (_G(debugRoomMaskDDB) != nullptr)
_G(gfxDriver)->DestroyDDB(_G(debugRoomMaskDDB));
_G(debugRoomMaskDDB) = nullptr;
- delete _G(debugMoveListBmp);
- _G(debugMoveListBmp) = nullptr;
+ _GP(debugMoveListBmp).reset();
if (_G(debugMoveListDDB) != nullptr)
_G(gfxDriver)->DestroyDDB(_G(debugMoveListDDB));
_G(debugMoveListDDB) = nullptr;
@@ -2286,17 +2286,29 @@ void debug_draw_room_mask(RoomAreaMask mask) {
if (mask == kRoomAreaNone)
return;
- Bitmap *mask_bmp;
+ Bitmap *bmp;
switch (mask) {
- case kRoomAreaHotspot: mask_bmp = _GP(thisroom).HotspotMask.get(); break;
- case kRoomAreaWalkBehind: mask_bmp = _GP(thisroom).WalkBehindMask.get(); break;
- case kRoomAreaWalkable: mask_bmp = prepare_walkable_areas(-1); break;
- case kRoomAreaRegion: mask_bmp = _GP(thisroom).RegionMask.get(); break;
+ case kRoomAreaHotspot: bmp = _GP(thisroom).HotspotMask.get(); break;
+ case kRoomAreaWalkBehind: bmp = _GP(thisroom).WalkBehindMask.get(); break;
+ case kRoomAreaWalkable: bmp = prepare_walkable_areas(-1); break;
+ case kRoomAreaRegion: bmp = _GP(thisroom).RegionMask.get(); break;
default: return;
}
- _G(debugRoomMaskDDB) = recycle_ddb_bitmap(_G(debugRoomMaskDDB), mask_bmp, false, true);
+ // Software mode scaling
+ // note we don't use transparency in software mode - may be slow in hi-res games
+ if (!_G(gfxDriver)->HasAcceleratedTransform() &&
+ (mask != kRoomAreaWalkBehind) &&
+ (bmp->GetSize() != Size(_GP(thisroom).Width, _GP(thisroom).Height))) {
+ _GP(debugRoomMaskBmp).reset(recycle_bitmap(_GP(debugRoomMaskBmp).release(),
+ bmp->GetColorDepth(), _GP(thisroom).Width, _GP(thisroom).Height));
+ _GP(debugRoomMaskBmp)->StretchBlt(bmp, RectWH(0, 0, _GP(thisroom).Width, _GP(thisroom).Height));
+ bmp = _GP(debugRoomMaskBmp).get();
+ }
+
+ _G(debugRoomMaskDDB) = recycle_ddb_bitmap(_G(debugRoomMaskDDB), bmp, false, true);
_G(debugRoomMaskDDB)->SetTransparency(150);
+ _G(debugRoomMaskDDB)->SetStretch(_GP(thisroom).Width, _GP(thisroom).Height);
}
void debug_draw_movelist(int charnum) {
@@ -2305,13 +2317,27 @@ void debug_draw_movelist(int charnum) {
void update_room_debug() {
if (_G(debugRoomMask) == kRoomAreaWalkable) {
- Bitmap *mask_bmp = prepare_walkable_areas(-1);
- _G(debugRoomMaskDDB) = recycle_ddb_bitmap(_G(debugRoomMaskDDB), mask_bmp, false, true);
+ Bitmap *bmp = prepare_walkable_areas(-1);
+ // Software mode scaling
+ if (!_G(gfxDriver)->HasAcceleratedTransform() && (_GP(thisroom).MaskResolution > 1)) {
+ _GP(debugRoomMaskBmp).reset(recycle_bitmap(_GP(debugRoomMaskBmp).release(),
+ bmp->GetColorDepth(), _GP(thisroom).Width, _GP(thisroom).Height));
+ _GP(debugRoomMaskBmp)->StretchBlt(bmp, RectWH(0, 0, _GP(thisroom).Width, _GP(thisroom).Height));
+ bmp = _GP(debugRoomMaskBmp).get();
+ }
+ _G(debugRoomMaskDDB) = recycle_ddb_bitmap(_G(debugRoomMaskDDB), bmp, false, true);
_G(debugRoomMaskDDB)->SetTransparency(150);
+ _G(debugRoomMaskDDB)->SetStretch(_GP(thisroom).Width, _GP(thisroom).Height);
}
if (_G(debugMoveListChar) >= 0) {
- _G(debugMoveListBmp) = recycle_bitmap(_G(debugMoveListBmp), _GP(game).GetColorDepth(),
- _GP(thisroom).WalkAreaMask->GetWidth(), _GP(thisroom).WalkAreaMask->GetHeight(), true);
+ const int mult = _G(gfxDriver)->HasAcceleratedTransform() ? _GP(thisroom).MaskResolution : 1;
+ if (_G(gfxDriver)->HasAcceleratedTransform())
+ _GP(debugMoveListBmp).reset(recycle_bitmap(_GP(debugMoveListBmp).release(), _GP(game).GetColorDepth(),
+ _GP(thisroom).WalkAreaMask->GetWidth(), _GP(thisroom).WalkAreaMask->GetHeight(), true));
+ else
+ _GP(debugMoveListBmp).reset(recycle_bitmap(_GP(debugMoveListBmp).release(), _GP(game).GetColorDepth(),
+ _GP(thisroom).Width, _GP(thisroom).Height, true));
+
if (_GP(game).chars[_G(debugMoveListChar)].walking > 0) {
int mlsnum = _GP(game).chars[_G(debugMoveListChar)].walking;
if (_GP(game).chars[_G(debugMoveListChar)].walking >= TURNING_AROUND)
@@ -2322,11 +2348,13 @@ void update_room_debug() {
short srcy = short(cmls.pos[i] & 0x00ffff);
short targetx = short((cmls.pos[i + 1] >> 16) & 0x00ffff);
short targety = short(cmls.pos[i + 1] & 0x00ffff);
- _G(debugMoveListBmp)->DrawLine(Line(srcx, srcy, targetx, targety), MakeColor(i + 1));
+ _GP(debugMoveListBmp)->DrawLine(Line(srcx / mult, srcy / mult, targetx / mult, targety / mult),
+ MakeColor(i + 1));
}
}
- _G(debugMoveListDDB) = recycle_ddb_bitmap(_G(debugMoveListDDB), _G(debugMoveListBmp), false, false);
+ _G(debugMoveListDDB) = recycle_ddb_bitmap(_G(debugMoveListDDB), _GP(debugMoveListBmp).get(), false, false);
_G(debugMoveListDDB)->SetTransparency(150);
+ _G(debugMoveListDDB)->SetStretch(_GP(thisroom).Width, _GP(thisroom).Height);
}
}
diff --git a/engines/ags/globals.cpp b/engines/ags/globals.cpp
index 35e7c677a21..6fc0a768aae 100644
--- a/engines/ags/globals.cpp
+++ b/engines/ags/globals.cpp
@@ -180,6 +180,8 @@ Globals::Globals() {
_actspswbcache = new std::vector<CachedActSpsData>();
_guibg = new std::vector<Shared::Bitmap *>();
_guibgbmp = new std::vector<Engine::IDriverDependantBitmap *>();
+ _debugRoomMaskBmp = new std::unique_ptr<Shared::Bitmap>();
+ _debugMoveListBmp = new std::unique_ptr<Shared::Bitmap>();
_maincoltable = new COLOR_MAP();
_palette = new color[256];
@@ -430,6 +432,8 @@ Globals::~Globals() {
delete _actspswbcache;
delete _guibg;
delete _guibgbmp;
+ delete _debugRoomMaskBmp;
+ delete _debugMoveListBmp;
delete[] _dynamicallyCreatedSurfaces;
delete[] _palette;
delete _maincoltable;
diff --git a/engines/ags/globals.h b/engines/ags/globals.h
index 4454d35150b..0ed35ac23b5 100644
--- a/engines/ags/globals.h
+++ b/engines/ags/globals.h
@@ -589,9 +589,10 @@ public:
std::vector<Engine::IDriverDependantBitmap *> *_guibgbmp;
// For debugging room masks
RoomAreaMask _debugRoomMask = kRoomAreaNone;
+ std::unique_ptr<Shared::Bitmap> *_debugRoomMaskBmp;
Engine::IDriverDependantBitmap *_debugRoomMaskDDB = nullptr;
int _debugMoveListChar = -1;
- Shared::Bitmap *_debugMoveListBmp = nullptr;
+ std::unique_ptr<Shared::Bitmap> *_debugMoveListBmp;
Engine::IDriverDependantBitmap *_debugMoveListDDB = nullptr;
bool _current_background_is_dirty = false;
Commit: 8f01b3006148e4a6287b7ce820cffbf95818a97a
https://github.com/scummvm/scummvm/commit/8f01b3006148e4a6287b7ce820cffbf95818a97a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:25:30-07:00
Commit Message:
AGS: Reactored ScriptOverlay, removed duplicate offset variables
>From upstream 634d6e20a1d2249de3125774491ff00959294dc8
Changed paths:
engines/ags/engine/ac/character.cpp
engines/ags/engine/ac/dynobj/script_overlay.cpp
engines/ags/engine/ac/dynobj/script_overlay.h
engines/ags/engine/ac/overlay.cpp
engines/ags/engine/ac/screen_overlay.cpp
engines/ags/engine/ac/screen_overlay.h
diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index 77d60940bd7..05051a4f1de 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -701,17 +701,13 @@ void Character_SayAt(CharacterInfo *chaa, int x, int y, int width, const char *t
}
ScriptOverlay *Character_SayBackground(CharacterInfo *chaa, const char *texx) {
-
int ovltype = DisplaySpeechBackground(chaa->index_id, texx);
int ovri = find_overlay_of_type(ovltype);
if (ovri < 0)
quit("!SayBackground internal error: no overlay");
ScriptOverlay *scOver = create_scriptobj_for_overlay(_GP(screenover)[ovri]);
- scOver->borderHeight = 0;
- scOver->borderWidth = 0;
- scOver->isBackgroundSpeech = 1;
-
+ scOver->isBackgroundSpeech = true;
return scOver;
}
diff --git a/engines/ags/engine/ac/dynobj/script_overlay.cpp b/engines/ags/engine/ac/dynobj/script_overlay.cpp
index 524e5e24b49..02bea1feb83 100644
--- a/engines/ags/engine/ac/dynobj/script_overlay.cpp
+++ b/engines/ags/engine/ac/dynobj/script_overlay.cpp
@@ -62,15 +62,15 @@ size_t ScriptOverlay::CalcSerializeSize() {
void ScriptOverlay::Serialize(const char *address, Stream *out) {
out->WriteInt32(overlayId);
- out->WriteInt32(borderWidth);
- out->WriteInt32(borderHeight);
+ out->WriteInt32(0); // unused (was text window x padding)
+ out->WriteInt32(0); // unused (was text window y padding)
out->WriteInt32(isBackgroundSpeech);
}
void ScriptOverlay::Unserialize(int index, Stream *in, size_t data_sz) {
overlayId = in->ReadInt32();
- borderWidth = in->ReadInt32();
- borderHeight = in->ReadInt32();
+ in->ReadInt32(); // unused (was text window x padding)
+ in->ReadInt32(); // unused (was text window y padding)
isBackgroundSpeech = in->ReadInt32();
ccRegisterUnserializedObject(index, this, this);
}
@@ -85,12 +85,4 @@ void ScriptOverlay::Remove() {
overlayId = -1;
}
-
-ScriptOverlay::ScriptOverlay() {
- overlayId = -1;
- borderWidth = 0;
- borderHeight = 0;
- isBackgroundSpeech = 0;
-}
-
} // namespace AGS3
diff --git a/engines/ags/engine/ac/dynobj/script_overlay.h b/engines/ags/engine/ac/dynobj/script_overlay.h
index 00e735e2114..f9fe6cba3e0 100644
--- a/engines/ags/engine/ac/dynobj/script_overlay.h
+++ b/engines/ags/engine/ac/dynobj/script_overlay.h
@@ -27,16 +27,16 @@
namespace AGS3 {
struct ScriptOverlay final : AGSCCDynamicObject {
- int overlayId;
- int borderWidth;
- int borderHeight;
- int isBackgroundSpeech;
+ int overlayId = -1;
+ // TODO: this flag is needed to mark an overlay which lifetime is managed
+ // by the engine; this may be solved with engine owning an object ref instead
+ bool isBackgroundSpeech = false;
int Dispose(const char *address, bool force) override;
const char *GetType() override;
void Unserialize(int index, AGS::Shared::Stream *in, size_t data_sz) override;
void Remove();
- ScriptOverlay();
+ ScriptOverlay() = default;
protected:
// Calculate and return required space for serialization, in bytes
diff --git a/engines/ags/engine/ac/overlay.cpp b/engines/ags/engine/ac/overlay.cpp
index 034a79cb32d..56be8424ffc 100644
--- a/engines/ags/engine/ac/overlay.cpp
+++ b/engines/ags/engine/ac/overlay.cpp
@@ -54,8 +54,8 @@ void Overlay_SetText(ScriptOverlay *scover, int wii, int fontid, int text_color,
int ovri = find_overlay_of_type(scover->overlayId);
if (ovri < 0)
quit("!Overlay.SetText: invalid overlay ID specified");
- int xx = game_to_data_coord(_GP(screenover)[ovri].x) - scover->borderWidth;
- int yy = game_to_data_coord(_GP(screenover)[ovri].y) - scover->borderHeight;
+ int xx = game_to_data_coord(_GP(screenover)[ovri].x);
+ int yy = game_to_data_coord(_GP(screenover)[ovri].y);
RemoveOverlay(scover->overlayId);
const int disp_type = scover->overlayId;
@@ -131,8 +131,6 @@ int Overlay_GetValid(ScriptOverlay *scover) {
ScriptOverlay *Overlay_CreateGraphical(int x, int y, int slot, int transparent) {
ScriptOverlay *sco = new ScriptOverlay();
sco->overlayId = CreateGraphicOverlay(x, y, slot, transparent);
- sco->borderHeight = 0;
- sco->borderWidth = 0;
sco->isBackgroundSpeech = 0;
ccRegisterManagedObject(sco, sco);
@@ -146,10 +144,6 @@ ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colo
width = data_to_game_coord(width);
sco->overlayId = CreateTextOverlayCore(x, y, width, font, colour, text, DISPLAYTEXT_NORMALOVERLAY, 0);
-
- int ovri = find_overlay_of_type(sco->overlayId);
- sco->borderWidth = game_to_data_coord(_GP(screenover)[ovri].x - x);
- sco->borderHeight = game_to_data_coord(_GP(screenover)[ovri].y - y);
sco->isBackgroundSpeech = 0;
ccRegisterManagedObject(sco, sco);
@@ -285,8 +279,8 @@ size_t add_screen_overlay(int x, int y, int type, Shared::Bitmap *piccy, int pic
over.bmp = _G(gfxDriver)->CreateDDBFromBitmap(piccy, alphaChannel);
over.x = x;
over.y = y;
- over._offsetX = pic_offx;
- over._offsetY = pic_offy;
+ over.offsetX = pic_offx;
+ over.offsetY = pic_offy;
// by default draw speech and portraits over GUI, and the rest under GUI
over.zorder = (type == OVER_TEXTMSG || type == OVER_PICTURE || type == OVER_TEXTSPEECH) ?
INT_MAX : INT_MIN;
@@ -341,8 +335,8 @@ void get_overlay_position(const ScreenOverlay &over, int *x, int *y) {
} else {
// Note: the internal offset is only needed when x,y coordinates are specified
// and only in the case where the overlay is using a GUI. See issue #1098
- tdxp = over.x + over._offsetX;
- tdyp = over.y + over._offsetY;
+ tdxp = over.x + over.offsetX;
+ tdyp = over.y + over.offsetY;
if (!over.positionRelativeToScreen) {
Point tdxy = _GP(play).RoomToScreen(tdxp, tdyp);
diff --git a/engines/ags/engine/ac/screen_overlay.cpp b/engines/ags/engine/ac/screen_overlay.cpp
index 546610e854e..2074bf78e37 100644
--- a/engines/ags/engine/ac/screen_overlay.cpp
+++ b/engines/ags/engine/ac/screen_overlay.cpp
@@ -42,8 +42,8 @@ void ScreenOverlay::ReadFromFile(Stream *in, int32_t cmp_ver) {
hasAlphaChannel = in->ReadBool();
positionRelativeToScreen = in->ReadBool();
if (cmp_ver >= 1) {
- _offsetX = in->ReadInt32();
- _offsetY = in->ReadInt32();
+ offsetX = in->ReadInt32();
+ offsetY = in->ReadInt32();
}
if (cmp_ver >= 2) {
zorder = in->ReadInt32();
@@ -66,8 +66,8 @@ void ScreenOverlay::WriteToFile(Stream *out) const {
out->WriteBool(hasAlphaChannel);
out->WriteBool(positionRelativeToScreen);
// since cmp_ver = 1
- out->WriteInt32(_offsetX);
- out->WriteInt32(_offsetY);
+ out->WriteInt32(offsetX);
+ out->WriteInt32(offsetY);
// since cmp_ver = 2
out->WriteInt32(zorder);
out->WriteInt32(transparency);
diff --git a/engines/ags/engine/ac/screen_overlay.h b/engines/ags/engine/ac/screen_overlay.h
index c40a0c8d2b2..bb1ac1beb1b 100644
--- a/engines/ags/engine/ac/screen_overlay.h
+++ b/engines/ags/engine/ac/screen_overlay.h
@@ -42,18 +42,21 @@ class IDriverDependantBitmap;
using namespace AGS; // FIXME later
-
struct ScreenOverlay {
Engine::IDriverDependantBitmap *bmp = nullptr;
Shared::Bitmap *pic = nullptr;
bool hasAlphaChannel = false;
- int type = 0, x = 0, y = 0, timeout = 0;
+ int type = 0, timeout = 0;
+ // Note that x,y are overlay's properties, that define its position in script;
+ // but real drawn position is x + offsetX, y + offsetY;
+ int x = 0, y = 0;
+ // Border/padding offset for the tiled text windows
+ int offsetX = 0, offsetY = 0;
int bgSpeechForChar = 0;
int associatedOverlayHandle = 0;
int zorder = INT_MIN;
bool positionRelativeToScreen = false;
bool hasSerializedBitmap = false;
- int _offsetX = 0, _offsetY = 0;
int transparency = 0;
void ReadFromFile(Shared::Stream *in, int32_t cmp_ver);
Commit: 8ecb108f93d3a2b1f6d359a745300cd3c2f1791b
https://github.com/scummvm/scummvm/commit/8ecb108f93d3a2b1f6d359a745300cd3c2f1791b
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:25:30-07:00
Commit Message:
AGS: Rename ScriptOverlay's member to better reflect its purpose
>From upstream 55a0b521c2f7c269ec4d9f41b4fd7f43d2a85af0
Changed paths:
engines/ags/engine/ac/character.cpp
engines/ags/engine/ac/dynobj/script_overlay.cpp
engines/ags/engine/ac/dynobj/script_overlay.h
engines/ags/engine/ac/overlay.cpp
engines/ags/engine/ac/screen_overlay.h
diff --git a/engines/ags/engine/ac/character.cpp b/engines/ags/engine/ac/character.cpp
index 05051a4f1de..cf854d17eaf 100644
--- a/engines/ags/engine/ac/character.cpp
+++ b/engines/ags/engine/ac/character.cpp
@@ -707,7 +707,7 @@ ScriptOverlay *Character_SayBackground(CharacterInfo *chaa, const char *texx) {
quit("!SayBackground internal error: no overlay");
ScriptOverlay *scOver = create_scriptobj_for_overlay(_GP(screenover)[ovri]);
- scOver->isBackgroundSpeech = true;
+ scOver->hasInternalRef = true; // keep at least until internal timeout
return scOver;
}
diff --git a/engines/ags/engine/ac/dynobj/script_overlay.cpp b/engines/ags/engine/ac/dynobj/script_overlay.cpp
index 02bea1feb83..83d3619b4e5 100644
--- a/engines/ags/engine/ac/dynobj/script_overlay.cpp
+++ b/engines/ags/engine/ac/dynobj/script_overlay.cpp
@@ -44,7 +44,7 @@ int ScriptOverlay::Dispose(const char *address, bool force) {
// if this is being removed voluntarily (ie. pointer out of
// scope) then remove the associateed overlay
// Otherwise, it's a Restre Game or something so don't
- if ((!force) && (!isBackgroundSpeech) && (Overlay_GetValid(this))) {
+ if ((!force) && (!hasInternalRef) && (Overlay_GetValid(this))) {
Remove();
}
@@ -64,14 +64,14 @@ void ScriptOverlay::Serialize(const char *address, Stream *out) {
out->WriteInt32(overlayId);
out->WriteInt32(0); // unused (was text window x padding)
out->WriteInt32(0); // unused (was text window y padding)
- out->WriteInt32(isBackgroundSpeech);
+ out->WriteInt32(hasInternalRef);
}
void ScriptOverlay::Unserialize(int index, Stream *in, size_t data_sz) {
overlayId = in->ReadInt32();
in->ReadInt32(); // unused (was text window x padding)
in->ReadInt32(); // unused (was text window y padding)
- isBackgroundSpeech = in->ReadInt32();
+ hasInternalRef = in->ReadInt32();
ccRegisterUnserializedObject(index, this, this);
}
diff --git a/engines/ags/engine/ac/dynobj/script_overlay.h b/engines/ags/engine/ac/dynobj/script_overlay.h
index f9fe6cba3e0..b9af4f29cb6 100644
--- a/engines/ags/engine/ac/dynobj/script_overlay.h
+++ b/engines/ags/engine/ac/dynobj/script_overlay.h
@@ -19,8 +19,8 @@
*
*/
-#ifndef AGS_ENGINE_AC_DYNOBJ_SCRIPTOVERLAY_H
-#define AGS_ENGINE_AC_DYNOBJ_SCRIPTOVERLAY_H
+#ifndef AGS_ENGINE_AC_DYNOBJ_SCRIPT_OVERLAY_H
+#define AGS_ENGINE_AC_DYNOBJ_SCRIPT_OVERLAY_H
#include "ags/engine/ac/dynobj/cc_ags_dynamic_object.h"
@@ -30,7 +30,7 @@ struct ScriptOverlay final : AGSCCDynamicObject {
int overlayId = -1;
// TODO: this flag is needed to mark an overlay which lifetime is managed
// by the engine; this may be solved with engine owning an object ref instead
- bool isBackgroundSpeech = false;
+ bool hasInternalRef = false;
int Dispose(const char *address, bool force) override;
const char *GetType() override;
diff --git a/engines/ags/engine/ac/overlay.cpp b/engines/ags/engine/ac/overlay.cpp
index 56be8424ffc..60563c34a98 100644
--- a/engines/ags/engine/ac/overlay.cpp
+++ b/engines/ags/engine/ac/overlay.cpp
@@ -131,8 +131,6 @@ int Overlay_GetValid(ScriptOverlay *scover) {
ScriptOverlay *Overlay_CreateGraphical(int x, int y, int slot, int transparent) {
ScriptOverlay *sco = new ScriptOverlay();
sco->overlayId = CreateGraphicOverlay(x, y, slot, transparent);
- sco->isBackgroundSpeech = 0;
-
ccRegisterManagedObject(sco, sco);
return sco;
}
@@ -144,8 +142,6 @@ ScriptOverlay *Overlay_CreateTextual(int x, int y, int width, int font, int colo
width = data_to_game_coord(width);
sco->overlayId = CreateTextOverlayCore(x, y, width, font, colour, text, DISPLAYTEXT_NORMALOVERLAY, 0);
- sco->isBackgroundSpeech = 0;
-
ccRegisterManagedObject(sco, sco);
return sco;
}
diff --git a/engines/ags/engine/ac/screen_overlay.h b/engines/ags/engine/ac/screen_overlay.h
index bb1ac1beb1b..31b90384c4f 100644
--- a/engines/ags/engine/ac/screen_overlay.h
+++ b/engines/ags/engine/ac/screen_overlay.h
@@ -52,7 +52,7 @@ struct ScreenOverlay {
int x = 0, y = 0;
// Border/padding offset for the tiled text windows
int offsetX = 0, offsetY = 0;
- int bgSpeechForChar = 0;
+ int bgSpeechForChar = -1;
int associatedOverlayHandle = 0;
int zorder = INT_MIN;
bool positionRelativeToScreen = false;
Commit: 7b0bfee7ccac1a48ad49dbdbe598a8769fcf0e53
https://github.com/scummvm/scummvm/commit/7b0bfee7ccac1a48ad49dbdbe598a8769fcf0e53
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:25:31-07:00
Commit Message:
AGS: Renamed and moved INIread/write functions for proper org&style
>From upstream 18398a7d695e81575218380e1bba28010c239fdc
Changed paths:
engines/ags/engine/debugging/debug.cpp
engines/ags/engine/main/config.cpp
engines/ags/engine/main/config.h
engines/ags/engine/main/engine.cpp
engines/ags/engine/main/main.cpp
engines/ags/shared/font/ttf_font_renderer.cpp
engines/ags/shared/util/ini_util.cpp
engines/ags/shared/util/ini_util.h
engines/ags/shared/util/string_utils.cpp
engines/ags/shared/util/string_utils.h
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index 2d65dc600f1..fc058331375 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -153,7 +153,7 @@ typedef std::pair<CommonDebugGroup, MessageType> DbgGroupOption;
void apply_log_config(const ConfigTree &cfg, const String &log_id,
bool def_enabled,
std::initializer_list<DbgGroupOption> def_opts) {
- String value = INIreadstring(cfg, "log", log_id);
+ String value = CfgReadString(cfg, "log", log_id);
if (value.IsEmpty() && !def_enabled)
return;
@@ -161,7 +161,7 @@ void apply_log_config(const ConfigTree &cfg, const String &log_id,
auto dbgout = _GP(DbgMgr).GetOutput(log_id);
const bool was_created_earlier = dbgout != nullptr;
if (!dbgout) {
- String path = INIreadstring(cfg, "log", String::FromFormat("%s-path", log_id.GetCStr()));
+ String path = CfgReadString(cfg, "log", String::FromFormat("%s-path", log_id.GetCStr()));
dbgout = create_log_output(log_id, path);
if (!dbgout)
return; // unknown output type
@@ -215,7 +215,7 @@ void init_debug(const ConfigTree &cfg, bool stderr_only) {
void apply_debug_config(const ConfigTree &cfg) {
apply_log_config(cfg, OutputSystemID, /* defaults */ true, { DbgGroupOption(kDbgGroup_Main, kDbgMsg_Info) });
- bool legacy_log_enabled = INIreadint(cfg, "misc", "log", 0) != 0;
+ bool legacy_log_enabled = CfgReadInt(cfg, "misc", "log", 0) != 0;
apply_log_config(cfg, OutputFileID,
/* defaults */
legacy_log_enabled, {
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index cbe16cfcdc8..df8b0985352 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -51,49 +51,6 @@ using namespace AGS::Engine;
// Filename of the default config file, the one found in the game installation
const char *DefaultConfigFileName = "acsetup.cfg";
-bool INIreaditem(const ConfigTree &cfg, const String §n, const String &item, String &value) {
- ConfigNode sec_it = cfg.find(sectn);
- if (sec_it != cfg.end()) {
- StrStrOIter item_it = sec_it->_value.find(item);
- if (item_it != sec_it->_value.end()) {
- value = item_it->_value;
- return true;
- }
- }
- return false;
-}
-
-int INIreadint(const ConfigTree &cfg, const String §n, const String &item, int def_value) {
- String str;
- if (!INIreaditem(cfg, sectn, item, str))
- return def_value;
-
- return atoi(str.GetCStr());
-}
-
-float INIreadfloat(const ConfigTree &cfg, const String §n, const String &item, float def_value) {
- String str;
- if (!INIreaditem(cfg, sectn, item, str))
- return def_value;
-
- return atof(str.GetCStr());
-}
-
-String INIreadstring(const ConfigTree &cfg, const String §n, const String &item, const String &def_value) {
- String str;
- if (!INIreaditem(cfg, sectn, item, str))
- return def_value;
- return str;
-}
-
-void INIwriteint(ConfigTree &cfg, const String §n, const String &item, int value) {
- cfg[sectn][item] = StrUtil::IntToString(value);
-}
-
-void INIwritestring(ConfigTree &cfg, const String §n, const String &item, const String &value) {
- cfg[sectn][item] = value;
-}
-
WindowSetup parse_window_mode(const String &option, bool as_windowed, WindowSetup def_value) {
// "full_window" option means pseudo fullscreen ("borderless fullscreen window")
if (!as_windowed && (option.CompareNoCase("full_window") == 0))
@@ -232,19 +189,19 @@ void config_defaults() {
static void read_legacy_graphics_config(const ConfigTree &cfg) {
// Pre-3.* game resolution setup
- int default_res = INIreadint(cfg, "misc", "defaultres", 0);
- int screen_res = INIreadint(cfg, "misc", "screenres", 0);
+ int default_res = CfgReadInt(cfg, "misc", "defaultres", 0);
+ int screen_res = CfgReadInt(cfg, "misc", "screenres", 0);
if ((default_res == kGameResolution_320x200 ||
default_res == kGameResolution_320x240) && screen_res > 0) {
_GP(usetup).override_upscale = true; // run low-res game in high-res mode
}
- _GP(usetup).Screen.Windowed = INIreadint(cfg, "misc", "windowed") > 0;
- _GP(usetup).Screen.DriverID = INIreadstring(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
+ _GP(usetup).Screen.Windowed = CfgReadInt(cfg, "misc", "windowed") > 0;
+ _GP(usetup).Screen.DriverID = CfgReadString(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
// Window setup: style and size definition, game frame style
{
- String legacy_filter = INIreadstring(cfg, "misc", "gfxfilter");
+ String legacy_filter = CfgReadString(cfg, "misc", "gfxfilter");
if (!legacy_filter.IsEmpty()) {
// Legacy scaling config is applied only to windowed setting
int scale_factor = 0;
@@ -256,14 +213,14 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
// AGS 3.2.1 and 3.3.0 aspect ratio preferences for fullscreen
if (!_GP(usetup).Screen.Windowed) {
bool allow_borders =
- (INIreadint(cfg, "misc", "sideborders") > 0 || INIreadint(cfg, "misc", "forceletterbox") > 0 ||
- INIreadint(cfg, "misc", "prefer_sideborders") > 0 || INIreadint(cfg, "misc", "prefer_letterbox") > 0);
+ (CfgReadInt(cfg, "misc", "sideborders") > 0 || CfgReadInt(cfg, "misc", "forceletterbox") > 0 ||
+ CfgReadInt(cfg, "misc", "prefer_sideborders") > 0 || CfgReadInt(cfg, "misc", "prefer_letterbox") > 0);
_GP(usetup).Screen.FsGameFrame = allow_borders ? kFrame_Proportional : kFrame_Stretch;
}
}
// AGS 3.4.0 - 3.4.1-rc uniform scaling option
- String uniform_frame_scale = INIreadstring(cfg, "graphics", "game_scale");
+ String uniform_frame_scale = CfgReadString(cfg, "graphics", "game_scale");
if (!uniform_frame_scale.IsEmpty()) {
int src_scale = 1;
FrameScaleDef frame = parse_legacy_scaling_option(uniform_frame_scale, src_scale);
@@ -272,16 +229,16 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
}
// AGS 3.5.* gfx mode with screen definition
- const bool is_windowed = INIreadint(cfg, "graphics", "windowed") != 0;
+ const bool is_windowed = CfgReadInt(cfg, "graphics", "windowed") != 0;
WindowSetup &ws = is_windowed ? _GP(usetup).Screen.WinSetup : _GP(usetup).Screen.FsSetup;
const WindowMode wm = is_windowed ? kWnd_Windowed : kWnd_Fullscreen;
- ScreenSizeDefinition scr_def = parse_legacy_screendef(INIreadstring(cfg, "graphics", "screen_def"));
+ ScreenSizeDefinition scr_def = parse_legacy_screendef(CfgReadString(cfg, "graphics", "screen_def"));
switch (scr_def) {
case kScreenDef_Explicit:
{
Size sz(
- INIreadint(cfg, "graphics", "screen_width"),
- INIreadint(cfg, "graphics", "screen_height"));
+ CfgReadInt(cfg, "graphics", "screen_width"),
+ CfgReadInt(cfg, "graphics", "screen_height"));
ws = WindowSetup(sz, wm);
}
break;
@@ -289,8 +246,8 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
{
int src_scale;
is_windowed ?
- parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win"), src_scale) :
- parse_legacy_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs"), src_scale);
+ parse_legacy_scaling_option(CfgReadString(cfg, "graphics", "game_scale_win"), src_scale) :
+ parse_legacy_scaling_option(CfgReadString(cfg, "graphics", "game_scale_fs"), src_scale);
ws = WindowSetup(src_scale, wm);
}
break;
@@ -302,14 +259,14 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
}
}
- _GP(usetup).Screen.Params.RefreshRate = INIreadint(cfg, "misc", "refresh");
+ _GP(usetup).Screen.Params.RefreshRate = CfgReadInt(cfg, "misc", "refresh");
}
void override_config_ext(ConfigTree &cfg) {
// Mobile ports always run in fullscreen mode
#if AGS_PLATFORM_OS_ANDROID || AGS_PLATFORM_OS_IOS
- INIwriteint(cfg, "graphics", "windowed", 0);
+ CfgWriteInt(cfg, "graphics", "windowed", 0);
#endif
// psp_gfx_renderer - rendering mode
@@ -317,11 +274,11 @@ void override_config_ext(ConfigTree &cfg) {
// * 1 - hardware, render to screen
// * 2 - hardware, render to texture
if (_G(psp_gfx_renderer) == 0) {
- INIwritestring(cfg, "graphics", "driver", "Software");
- INIwriteint(cfg, "graphics", "render_at_screenres", 1);
+ CfgWriteString(cfg, "graphics", "driver", "Software");
+ CfgWriteInt(cfg, "graphics", "render_at_screenres", 1);
} else {
- INIwritestring(cfg, "graphics", "driver", "OGL");
- INIwriteint(cfg, "graphics", "render_at_screenres", _G(psp_gfx_renderer) == 1);
+ CfgWriteString(cfg, "graphics", "driver", "OGL");
+ CfgWriteInt(cfg, "graphics", "render_at_screenres", _G(psp_gfx_renderer) == 1);
}
// psp_gfx_scaling - scaling style:
@@ -329,118 +286,118 @@ void override_config_ext(ConfigTree &cfg) {
// * 1 - stretch and preserve aspect ratio
// * 2 - stretch to whole screen
if (_G(psp_gfx_scaling) == 0)
- INIwritestring(cfg, "graphics", "game_scale_fs", "1");
+ CfgWriteString(cfg, "graphics", "game_scale_fs", "1");
else if (_G(psp_gfx_scaling) == 1)
- INIwritestring(cfg, "graphics", "game_scale_fs", "proportional");
+ CfgWriteString(cfg, "graphics", "game_scale_fs", "proportional");
else
- INIwritestring(cfg, "graphics", "game_scale_fs", "stretch");
+ CfgWriteString(cfg, "graphics", "game_scale_fs", "stretch");
// psp_gfx_smoothing - scaling filter:
// * 0 - nearest-neighbour
// * 1 - linear
if (_G(psp_gfx_smoothing) == 0)
- INIwritestring(cfg, "graphics", "filter", "StdScale");
+ CfgWriteString(cfg, "graphics", "filter", "StdScale");
else
- INIwritestring(cfg, "graphics", "filter", "Linear");
+ CfgWriteString(cfg, "graphics", "filter", "Linear");
// psp_gfx_super_sampling - enable super sampling
// * 0 - x1
// * 1 - x2
if (_G(psp_gfx_renderer) == 2)
- INIwriteint(cfg, "graphics", "supersampling", _G(psp_gfx_super_sampling) + 1);
+ CfgWriteInt(cfg, "graphics", "supersampling", _G(psp_gfx_super_sampling) + 1);
else
- INIwriteint(cfg, "graphics", "supersampling", 0);
+ CfgWriteInt(cfg, "graphics", "supersampling", 0);
// psp_gfx_rotation - scaling style:
// * 0 - unlocked, let the user rotate as wished.
// * 1 - portrait
// * 2 - landscape
- INIwriteint(cfg, "graphics", "rotation", _G(psp_rotation));
+ CfgWriteInt(cfg, "graphics", "rotation", _G(psp_rotation));
#if AGS_PLATFORM_OS_ANDROID
// config_mouse_control_mode - enable relative mouse mode
// * 1 - relative mouse touch controls
// * 0 - direct touch mouse control
- INIwriteint(cfg, "mouse", "control_enabled", config_mouse_control_mode);
+ CfgWriteInt(cfg, "mouse", "control_enabled", config_mouse_control_mode);
#endif
- INIwriteint(cfg, "misc", "antialias", _G(psp_gfx_smooth_sprites) != 0);
- INIwritestring(cfg, "language", "translation", _G(psp_translation));
- INIwriteint(cfg, "misc", "clear_cache_on_room_change", _G(psp_clear_cache_on_room_change) != 0);
+ CfgWriteInt(cfg, "misc", "antialias", _G(psp_gfx_smooth_sprites) != 0);
+ CfgWriteString(cfg, "language", "translation", _G(psp_translation));
+ CfgWriteInt(cfg, "misc", "clear_cache_on_room_change", _G(psp_clear_cache_on_room_change) != 0);
}
void apply_config(const ConfigTree &cfg) {
{
- _GP(usetup).audio_enabled = INIreadint(cfg, "sound", "enabled", _GP(usetup).audio_enabled) != 0;
- _GP(usetup).audio_driver = INIreadstring(cfg, "sound", "driver");
+ _GP(usetup).audio_enabled = CfgReadInt(cfg, "sound", "enabled", _GP(usetup).audio_enabled) != 0;
+ _GP(usetup).audio_driver = CfgReadString(cfg, "sound", "driver");
// Legacy graphics settings has to be translated into new options;
// they must be read first, to let newer options override them, if ones are present
read_legacy_graphics_config(cfg);
// Graphics mode
- _GP(usetup).Screen.DriverID = INIreadstring(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
- _GP(usetup).Screen.Windowed = INIreadint(cfg, "graphics", "windowed", _GP(usetup).Screen.Windowed ? 1 : 0) > 0;
+ _GP(usetup).Screen.DriverID = CfgReadString(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
+ _GP(usetup).Screen.Windowed = CfgReadInt(cfg, "graphics", "windowed", _GP(usetup).Screen.Windowed ? 1 : 0) > 0;
_GP(usetup).Screen.FsSetup =
- parse_window_mode(INIreadstring(cfg, "graphics", "fullscreen", "default"), false, _GP(usetup).Screen.FsSetup);
+ parse_window_mode(CfgReadString(cfg, "graphics", "fullscreen", "default"), false, _GP(usetup).Screen.FsSetup);
_GP(usetup).Screen.WinSetup =
- parse_window_mode(INIreadstring(cfg, "graphics", "window", "default"), true, _GP(usetup).Screen.WinSetup);
+ parse_window_mode(CfgReadString(cfg, "graphics", "window", "default"), true, _GP(usetup).Screen.WinSetup);
// TODO: move to config overrides (replace values during config load)
#if AGS_PLATFORM_OS_MACOS
_GP(usetup).Screen.Filter.ID = "none";
#else
- _GP(usetup).Screen.Filter.ID = INIreadstring(cfg, "graphics", "filter", "StdScale");
+ _GP(usetup).Screen.Filter.ID = CfgReadString(cfg, "graphics", "filter", "StdScale");
_GP(usetup).Screen.FsGameFrame =
- parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_fs", "proportional"), _GP(usetup).Screen.FsGameFrame);
+ parse_scaling_option(CfgReadString(cfg, "graphics", "game_scale_fs", "proportional"), _GP(usetup).Screen.FsGameFrame);
_GP(usetup).Screen.WinGameFrame =
- parse_scaling_option(INIreadstring(cfg, "graphics", "game_scale_win", "round"), _GP(usetup).Screen.WinGameFrame);
+ parse_scaling_option(CfgReadString(cfg, "graphics", "game_scale_win", "round"), _GP(usetup).Screen.WinGameFrame);
#endif
- _GP(usetup).Screen.Params.RefreshRate = INIreadint(cfg, "graphics", "refresh");
- _GP(usetup).Screen.Params.VSync = INIreadint(cfg, "graphics", "vsync") > 0;
- _GP(usetup).RenderAtScreenRes = INIreadint(cfg, "graphics", "render_at_screenres") > 0;
- _GP(usetup).Supersampling = INIreadint(cfg, "graphics", "supersampling", 1);
- _GP(usetup).software_render_driver = INIreadstring(cfg, "graphics", "software_driver");
+ _GP(usetup).Screen.Params.RefreshRate = CfgReadInt(cfg, "graphics", "refresh");
+ _GP(usetup).Screen.Params.VSync = CfgReadInt(cfg, "graphics", "vsync") > 0;
+ _GP(usetup).RenderAtScreenRes = CfgReadInt(cfg, "graphics", "render_at_screenres") > 0;
+ _GP(usetup).Supersampling = CfgReadInt(cfg, "graphics", "supersampling", 1);
+ _GP(usetup).software_render_driver = CfgReadString(cfg, "graphics", "software_driver");
#ifdef TODO
- _GP(usetup).rotation = (ScreenRotation)INIreadint(cfg, "graphics", "rotation", _GP(usetup).rotation);
- String rotation_str = INIreadstring(cfg, "graphics", "rotation", "unlocked");
+ _GP(usetup).rotation = (ScreenRotation)CfgReadInt(cfg, "graphics", "rotation", _GP(usetup).rotation);
+ String rotation_str = CfgReadString(cfg, "graphics", "rotation", "unlocked");
_GP(usetup).rotation = StrUtil::ParseEnum<ScreenRotation>(
rotation_str, CstrArr<kNumScreenRotationOptions>{ "unlocked", "portrait", "landscape" },
_GP(usetup).rotation);
#endif
- _GP(usetup).enable_antialiasing = INIreadint(cfg, "misc", "antialias") > 0;
+ _GP(usetup).enable_antialiasing = CfgReadInt(cfg, "misc", "antialias") > 0;
// This option is backwards (usevox is 0 if no_speech_pack)
- _GP(usetup).no_speech_pack = INIreadint(cfg, "sound", "usespeech", 1) == 0;
+ _GP(usetup).no_speech_pack = CfgReadInt(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) != 0;
- _GP(usetup).user_data_dir = INIreadstring(cfg, "misc", "user_data_dir");
- _GP(usetup).shared_data_dir = INIreadstring(cfg, "misc", "shared_data_dir");
+ _GP(usetup).clear_cache_on_room_change = CfgReadInt(cfg, "misc", "clear_cache_on_room_change", _GP(usetup).clear_cache_on_room_change) != 0;
+ _GP(usetup).user_data_dir = CfgReadString(cfg, "misc", "user_data_dir");
+ _GP(usetup).shared_data_dir = CfgReadString(cfg, "misc", "shared_data_dir");
- _GP(usetup).translation = INIreadstring(cfg, "language", "translation");
+ _GP(usetup).translation = CfgReadString(cfg, "language", "translation");
- int cache_size_kb = INIreadint(cfg, "misc", "cachemax", DEFAULTCACHESIZE_KB);
+ int cache_size_kb = CfgReadInt(cfg, "misc", "cachemax", DEFAULTCACHESIZE_KB);
if (cache_size_kb > 0)
_GP(spriteset).SetMaxCacheSize((size_t)cache_size_kb * 1024);
- _GP(usetup).mouse_auto_lock = INIreadint(cfg, "mouse", "auto_lock") > 0;
+ _GP(usetup).mouse_auto_lock = CfgReadInt(cfg, "mouse", "auto_lock") > 0;
- _GP(usetup).mouse_speed = INIreadfloat(cfg, "mouse", "speed", 1.f);
+ _GP(usetup).mouse_speed = CfgReadFloat(cfg, "mouse", "speed", 1.f);
if (_GP(usetup).mouse_speed <= 0.f)
_GP(usetup).mouse_speed = 1.f;
const char *mouse_ctrl_options[kNumMouseCtrlOptions] = { "never", "fullscreen", "always" };
- String mouse_str = INIreadstring(cfg, "mouse", "control_when", "fullscreen");
+ String mouse_str = CfgReadString(cfg, "mouse", "control_when", "fullscreen");
for (int i = 0; i < kNumMouseCtrlOptions; ++i) {
if (mouse_str.CompareNoCase(mouse_ctrl_options[i]) == 0) {
_GP(usetup).mouse_ctrl_when = (MouseControlWhen)i;
break;
}
}
- _GP(usetup).mouse_ctrl_enabled = INIreadint(cfg, "mouse", "control_enabled", _GP(usetup).mouse_ctrl_enabled) > 0;
+ _GP(usetup).mouse_ctrl_enabled = CfgReadInt(cfg, "mouse", "control_enabled", _GP(usetup).mouse_ctrl_enabled) > 0;
const char *mouse_speed_options[kNumMouseSpeedDefs] = { "absolute", "current_display" };
- mouse_str = INIreadstring(cfg, "mouse", "speed_def", "current_display");
+ mouse_str = CfgReadString(cfg, "mouse", "speed_def", "current_display");
for (int i = 0; i < kNumMouseSpeedDefs; ++i) {
if (mouse_str.CompareNoCase(mouse_speed_options[i]) == 0) {
_GP(usetup).mouse_speed_def = (MouseSpeedDef)i;
@@ -448,8 +405,8 @@ void apply_config(const ConfigTree &cfg) {
}
}
- _GP(usetup).override_multitasking = INIreadint(cfg, "override", "multitasking", -1);
- String override_os = INIreadstring(cfg, "override", "os");
+ _GP(usetup).override_multitasking = CfgReadInt(cfg, "override", "multitasking", -1);
+ String override_os = CfgReadString(cfg, "override", "os");
_GP(usetup).override_script_os = -1;
if (override_os.CompareNoCase("dos") == 0) {
_GP(usetup).override_script_os = eOS_DOS;
@@ -460,7 +417,7 @@ void apply_config(const ConfigTree &cfg) {
} else if (override_os.CompareNoCase("mac") == 0) {
_GP(usetup).override_script_os = eOS_Mac;
}
- _GP(usetup).override_upscale = INIreadint(cfg, "override", "upscale", _GP(usetup).override_upscale) > 0;
+ _GP(usetup).override_upscale = CfgReadInt(cfg, "override", "upscale", _GP(usetup).override_upscale) > 0;
}
// Apply logging configuration
diff --git a/engines/ags/engine/main/config.h b/engines/ags/engine/main/config.h
index 1df535cfff0..29f48cf42da 100644
--- a/engines/ags/engine/main/config.h
+++ b/engines/ags/engine/main/config.h
@@ -52,13 +52,6 @@ String make_scaling_option(FrameScaleDef scale_def);
uint32_t convert_scaling_to_fp(int scale_factor);
int convert_fp_to_scaling(uint32_t scaling);
-bool INIreaditem(const ConfigTree &cfg, const String §n, const String &item, String &value);
-int INIreadint(const ConfigTree &cfg, const String §n, const String &item, int def_value = 0);
-float INIreadfloat(const ConfigTree &cfg, const String §n, const String &item, float def_value = 0.f);
-String INIreadstring(const ConfigTree &cfg, const String §n, const String &item, const String &def_value = "");
-void INIwriteint(ConfigTree &cfg, const String §n, const String &item, int value);
-void INIwritestring(ConfigTree &cfg, const String §n, const String &item, const String &value);
-
} // namespace AGS3
#endif
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index 0941335660e..effc54c2ae1 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -183,7 +183,7 @@ static String find_game_data_in_config(const String &path) {
ConfigTree cfg;
String def_cfg_file = Path::ConcatPaths(path, DefaultConfigFileName);
if (IniUtil::Read(def_cfg_file, cfg)) {
- String data_file = INIreadstring(cfg, "misc", "datafile");
+ String data_file = CfgReadString(cfg, "misc", "datafile");
Debug::Printf("Found game config: %s", def_cfg_file.GetCStr());
Debug::Printf(" Cfg: data file: %s", data_file.GetCStr());
// Only accept if it's a relative path
@@ -945,9 +945,9 @@ void engine_read_config(ConfigTree &cfg) {
// Handle directive to search for the user config inside the custom directory;
// this option may come either from command line or default/global config.
if (_GP(usetup).user_conf_dir.IsEmpty())
- _GP(usetup).user_conf_dir = INIreadstring(cfg, "misc", "user_conf_dir");
+ _GP(usetup).user_conf_dir = CfgReadString(cfg, "misc", "user_conf_dir");
if (_GP(usetup).user_conf_dir.IsEmpty()) // also try deprecated option
- _GP(usetup).user_conf_dir = INIreadint(cfg, "misc", "localuserconf") != 0 ? "." : "";
+ _GP(usetup).user_conf_dir = CfgReadInt(cfg, "misc", "localuserconf") != 0 ? "." : "";
// Test if the file is writeable, if it is then both engine and setup
// applications may actually use it fully as a user config, otherwise
// fallback to default behavior.
@@ -965,7 +965,7 @@ void engine_read_config(ConfigTree &cfg) {
// Handle directive to search for the user config inside the game directory;
// this option may come either from command line or default/global config.
- _GP(usetup).local_user_conf |= INIreadint(cfg, "misc", "localuserconf", 0) != 0;
+ _GP(usetup).local_user_conf |= CfgReadInt(cfg, "misc", "localuserconf", 0) != 0;
if (_GP(usetup).local_user_conf) { // Test if the file is writeable, if it is then both engine and setup
// applications may actually use it fully as a user config, otherwise
// fallback to default behavior.
diff --git a/engines/ags/engine/main/main.cpp b/engines/ags/engine/main/main.cpp
index 6f6661fabe4..3f8099c0ac6 100644
--- a/engines/ags/engine/main/main.cpp
+++ b/engines/ags/engine/main/main.cpp
@@ -236,7 +236,7 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
_GP(play).takeover_from[49] = 0;
ee += 2;
} else if (ags_stricmp(arg, "--clear-cache-on-room-change") == 0) {
- INIwritestring(cfg, "misc", "clear_cache_on_room_change", "1");
+ CfgWriteString(cfg, "misc", "clear_cache_on_room_change", "1");
} else if (ags_strnicmp(arg, "--tell", 6) == 0) {
if (arg[6] == 0)
_G(tellInfoKeys).insert(String("all"));
@@ -255,19 +255,19 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
else if (ags_stricmp(arg, "--fullscreen") == 0)
cfg["graphics"]["windowed"] = "0";
else if ((ags_stricmp(arg, "--gfxdriver") == 0) && (argc > ee + 1)) {
- INIwritestring(cfg, "graphics", "driver", argv[++ee]);
+ CfgWriteString(cfg, "graphics", "driver", argv[++ee]);
} else if ((ags_stricmp(arg, "--gfxfilter") == 0) && (argc > ee + 1)) {
// NOTE: we make an assumption here that if user provides scaling factor,
// this factor means to be applied to windowed mode only.
- INIwritestring(cfg, "graphics", "filter", argv[++ee]);
+ CfgWriteString(cfg, "graphics", "filter", argv[++ee]);
if (argc > ee + 1 && argv[ee + 1][0] != '-')
- INIwritestring(cfg, "graphics", "game_scale_win", argv[++ee]);
+ CfgWriteString(cfg, "graphics", "game_scale_win", argv[++ee]);
else
- INIwritestring(cfg, "graphics", "game_scale_win", "max_round");
+ CfgWriteString(cfg, "graphics", "game_scale_win", "max_round");
} else if ((ags_stricmp(arg, "--translation") == 0) && (argc > ee + 1)) {
- INIwritestring(cfg, "language", "translation", argv[++ee]);
+ CfgWriteString(cfg, "language", "translation", argv[++ee]);
} else if (ags_stricmp(arg, "--no-translation") == 0) {
- INIwritestring(cfg, "language", "translation", "");
+ CfgWriteString(cfg, "language", "translation", "");
} else if (ags_stricmp(arg, "--fps") == 0) _G(display_fps) = kFPS_Forced;
else if (ags_stricmp(arg, "--test") == 0) _G(debug_flags) |= DBG_DEBUGMODE;
else if (ags_stricmp(arg, "--noiface") == 0) _G(debug_flags) |= DBG_NOIFACE;
@@ -279,7 +279,7 @@ int main_process_cmdline(ConfigTree &cfg, int argc, const char *argv[]) {
else if (ags_stricmp(arg, "--noscript") == 0) _G(debug_flags) |= DBG_NOSCRIPT;
else if (ags_stricmp(arg, "--novideo") == 0) _G(debug_flags) |= DBG_NOVIDEO;
else if (ags_stricmp(arg, "--rotation") == 0 && (argc > ee + 1)) {
- INIwritestring(cfg, "graphics", "rotation", argv[++ee]);
+ CfgWriteString(cfg, "graphics", "rotation", argv[++ee]);
} else if (ags_strnicmp(arg, "--log-", 6) == 0 && arg[6] != 0) {
String logarg = arg + 6;
size_t split_at = logarg.FindChar('=');
diff --git a/engines/ags/shared/font/ttf_font_renderer.cpp b/engines/ags/shared/font/ttf_font_renderer.cpp
index 4cdb29cb00e..f953735da90 100644
--- a/engines/ags/shared/font/ttf_font_renderer.cpp
+++ b/engines/ags/shared/font/ttf_font_renderer.cpp
@@ -47,7 +47,7 @@ void TTFFontRenderer::AdjustYCoordinateForFont(int *ycoord, int /*fontNumber*/)
ycoord[0]--;
}
-void TTFFontRenderer::EnsureTextValidForFont(char */*text*/, int /*fontNumber*/) {
+void TTFFontRenderer::EnsureTextValidForFont(char * /*text*/, int /*fontNumber*/) {
// do nothing, TTF can handle all characters
}
@@ -55,7 +55,7 @@ int TTFFontRenderer::GetTextWidth(const char *text, int fontNumber) {
return alfont_text_length(_fontData[fontNumber].AlFont, text);
}
-int TTFFontRenderer::GetTextHeight(const char */*text*/, int fontNumber) {
+int TTFFontRenderer::GetTextHeight(const char * /*text*/, int fontNumber) {
return alfont_get_font_real_height(_fontData[fontNumber].AlFont);
}
diff --git a/engines/ags/shared/util/ini_util.cpp b/engines/ags/shared/util/ini_util.cpp
index c55813b4c15..c270d675c56 100644
--- a/engines/ags/shared/util/ini_util.cpp
+++ b/engines/ags/shared/util/ini_util.cpp
@@ -24,13 +24,79 @@
#include "ags/shared/util/ini_util.h"
#include "ags/shared/util/ini_file.h"
#include "ags/shared/util/stream.h"
+#include "ags/shared/util/string_utils.h"
#include "ags/shared/util/text_stream_writer.h"
namespace AGS3 {
namespace AGS {
namespace Shared {
+//-----------------------------------------------------------------------------
+// ConfigReader
+//-----------------------------------------------------------------------------
+
+bool CfgReadItem(const ConfigTree &cfg, const String §n, const String &item, String &value) {
+ const auto sec_it = cfg.find(sectn);
+ if (sec_it != cfg.end()) {
+ const auto item_it = sec_it->_value.find(item);
+ if (item_it != sec_it->_value.end()) {
+ value = item_it->_value;
+ return true;
+ }
+ }
+ return false;
+}
+
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def_value) {
+ String str;
+ if (!CfgReadItem(cfg, sectn, item, str))
+ return def_value;
+ return StrUtil::StringToInt(str, def_value);
+}
+
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def_value) {
+ String str;
+ if (!CfgReadItem(cfg, sectn, item, str))
+ return def_value;
+ return StrUtil::StringToFloat(str, def_value);
+}
+
+String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def_value) {
+ String str;
+ if (!CfgReadItem(cfg, sectn, item, str))
+ return def_value;
+ return str;
+}
+
+//-----------------------------------------------------------------------------
+// ConfigWriter
+//-----------------------------------------------------------------------------
+
+void CfgWriteInt(ConfigTree &cfg, const String §n, const String &item, int value) {
+ cfg[sectn][item].Format("%d", value);
+}
+
+void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value) {
+ cfg[sectn][item].Format("%f", value);
+}
+
+void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value, unsigned precision) {
+ char fmt[10];
+ snprintf(fmt, sizeof(fmt), "%%0.%df", precision);
+ cfg[sectn][item].Format(fmt, value);
+}
+
+void CfgWriteString(ConfigTree &cfg, const String §n, const String &item, const String &value) {
+ cfg[sectn][item] = value;
+}
+
+//-----------------------------------------------------------------------------
+// IniUtil
+//-----------------------------------------------------------------------------
+
typedef std::unique_ptr<Stream> UStream;
+typedef StringOrderMap::const_iterator StrStrOIter;
+typedef ConfigTree::const_iterator ConfigNode;
typedef IniFile::SectionIterator SectionIterator;
typedef IniFile::ConstSectionIterator CSectionIterator;
typedef IniFile::ItemIterator ItemIterator;
diff --git a/engines/ags/shared/util/ini_util.h b/engines/ags/shared/util/ini_util.h
index 914228115af..5b25d3437a8 100644
--- a/engines/ags/shared/util/ini_util.h
+++ b/engines/ags/shared/util/ini_util.h
@@ -37,11 +37,25 @@ namespace AGS {
namespace Shared {
typedef std::map<String, String> StringOrderMap;
-typedef StringOrderMap::const_iterator StrStrOIter;
-
typedef std::map<String, StringOrderMap> ConfigTree;
-typedef ConfigTree::const_iterator ConfigNode;
+//
+// Helper functions for parsing values in a ConfigTree
+bool CfgReadItem(const ConfigTree &cfg, const String §n, const String &item, String &value);
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def_value = 0);
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def_value = 0.f);
+String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def_value = "");
+//
+// Helper functions for writing values into a ConfigTree
+void CfgWriteInt(ConfigTree &cfg, const String §n, const String &item, int value);
+void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value);
+void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value, unsigned precision);
+void CfgWriteString(ConfigTree &cfg, const String §n, const String &item, const String &value);
+
+
+class IniFile;
+
+// Utility functions that exchange data between ConfigTree and INI file.
namespace IniUtil {
// Parse the contents of given file as INI format and insert values
diff --git a/engines/ags/shared/util/string_utils.cpp b/engines/ags/shared/util/string_utils.cpp
index 8f698826fb2..3ce4cc04d46 100644
--- a/engines/ags/shared/util/string_utils.cpp
+++ b/engines/ags/shared/util/string_utils.cpp
@@ -61,6 +61,14 @@ StrUtil::ConversionError StrUtil::StringToInt(const String &s, int &val, int def
return StrUtil::kNoError;
}
+float StrUtil::StringToFloat(const String &s, float def_val) {
+ if (!s.GetCStr())
+ return def_val;
+ char *stop_ptr;
+ int val = strtof(s.GetCStr(), &stop_ptr);
+ return (stop_ptr == s.GetCStr() + s.GetLength()) ? val : def_val;
+}
+
String StrUtil::Unescape(const String &s) {
size_t at = s.FindChar('\\');
if (at == String::NoIndex)
diff --git a/engines/ags/shared/util/string_utils.h b/engines/ags/shared/util/string_utils.h
index 623961a77ed..fb9ac1d144f 100644
--- a/engines/ags/shared/util/string_utils.h
+++ b/engines/ags/shared/util/string_utils.h
@@ -56,6 +56,9 @@ int StringToInt(const String &s, int def_val = 0);
// of range; the 'val' variable will be set with resulting integer, or
// def_val on failure
ConversionError StringToInt(const String &s, int &val, int def_val);
+// Tries to convert whole string into float value;
+// returns def_val on failure
+float StringToFloat(const String &s, float def_val = 0.f);
// A simple unescape string implementation, unescapes '\\x' into '\x'.
String Unescape(const String &s);
Commit: 23a2e8c709f1723798da7b453d1f23cc522ec4bf
https://github.com/scummvm/scummvm/commit/23a2e8c709f1723798da7b453d1f23cc522ec4bf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:38:38-07:00
Commit Message:
AGS: More config parse helpers: reading boolean ints, min-max range
>From upstream 9737cabb8e7562122f8c471793bd994685d72bfe
Changed paths:
engines/ags/engine/debugging/debug.cpp
engines/ags/engine/main/config.cpp
engines/ags/engine/main/engine.cpp
engines/ags/shared/util/ini_util.cpp
engines/ags/shared/util/ini_util.h
diff --git a/engines/ags/engine/debugging/debug.cpp b/engines/ags/engine/debugging/debug.cpp
index fc058331375..05f14fd2583 100644
--- a/engines/ags/engine/debugging/debug.cpp
+++ b/engines/ags/engine/debugging/debug.cpp
@@ -215,7 +215,7 @@ void init_debug(const ConfigTree &cfg, bool stderr_only) {
void apply_debug_config(const ConfigTree &cfg) {
apply_log_config(cfg, OutputSystemID, /* defaults */ true, { DbgGroupOption(kDbgGroup_Main, kDbgMsg_Info) });
- bool legacy_log_enabled = CfgReadInt(cfg, "misc", "log", 0) != 0;
+ bool legacy_log_enabled = CfgReadBoolInt(cfg, "misc", "log", false);
apply_log_config(cfg, OutputFileID,
/* defaults */
legacy_log_enabled, {
diff --git a/engines/ags/engine/main/config.cpp b/engines/ags/engine/main/config.cpp
index df8b0985352..9f136028fb3 100644
--- a/engines/ags/engine/main/config.cpp
+++ b/engines/ags/engine/main/config.cpp
@@ -196,7 +196,7 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
_GP(usetup).override_upscale = true; // run low-res game in high-res mode
}
- _GP(usetup).Screen.Windowed = CfgReadInt(cfg, "misc", "windowed") > 0;
+ _GP(usetup).Screen.Windowed = CfgReadBoolInt(cfg, "misc", "windowed");
_GP(usetup).Screen.DriverID = CfgReadString(cfg, "misc", "gfxdriver", _GP(usetup).Screen.DriverID);
// Window setup: style and size definition, game frame style
@@ -213,8 +213,8 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
// AGS 3.2.1 and 3.3.0 aspect ratio preferences for fullscreen
if (!_GP(usetup).Screen.Windowed) {
bool allow_borders =
- (CfgReadInt(cfg, "misc", "sideborders") > 0 || CfgReadInt(cfg, "misc", "forceletterbox") > 0 ||
- CfgReadInt(cfg, "misc", "prefer_sideborders") > 0 || CfgReadInt(cfg, "misc", "prefer_letterbox") > 0);
+ (CfgReadBoolInt(cfg, "misc", "sideborders") || CfgReadBoolInt(cfg, "misc", "forceletterbox") ||
+ CfgReadBoolInt(cfg, "misc", "prefer_sideborders") || CfgReadBoolInt(cfg, "misc", "prefer_letterbox"));
_GP(usetup).Screen.FsGameFrame = allow_borders ? kFrame_Proportional : kFrame_Stretch;
}
}
@@ -229,7 +229,7 @@ static void read_legacy_graphics_config(const ConfigTree &cfg) {
}
// AGS 3.5.* gfx mode with screen definition
- const bool is_windowed = CfgReadInt(cfg, "graphics", "windowed") != 0;
+ const bool is_windowed = CfgReadBoolInt(cfg, "graphics", "windowed");
WindowSetup &ws = is_windowed ? _GP(usetup).Screen.WinSetup : _GP(usetup).Screen.FsSetup;
const WindowMode wm = is_windowed ? kWnd_Windowed : kWnd_Fullscreen;
ScreenSizeDefinition scr_def = parse_legacy_screendef(CfgReadString(cfg, "graphics", "screen_def"));
@@ -328,7 +328,7 @@ void override_config_ext(ConfigTree &cfg) {
void apply_config(const ConfigTree &cfg) {
{
- _GP(usetup).audio_enabled = CfgReadInt(cfg, "sound", "enabled", _GP(usetup).audio_enabled) != 0;
+ _GP(usetup).audio_enabled = CfgReadBoolInt(cfg, "sound", "enabled", _GP(usetup).audio_enabled);
_GP(usetup).audio_driver = CfgReadString(cfg, "sound", "driver");
// Legacy graphics settings has to be translated into new options;
@@ -337,7 +337,7 @@ void apply_config(const ConfigTree &cfg) {
// Graphics mode
_GP(usetup).Screen.DriverID = CfgReadString(cfg, "graphics", "driver", _GP(usetup).Screen.DriverID);
- _GP(usetup).Screen.Windowed = CfgReadInt(cfg, "graphics", "windowed", _GP(usetup).Screen.Windowed ? 1 : 0) > 0;
+ _GP(usetup).Screen.Windowed = CfgReadBoolInt(cfg, "graphics", "windowed", _GP(usetup).Screen.Windowed);
_GP(usetup).Screen.FsSetup =
parse_window_mode(CfgReadString(cfg, "graphics", "fullscreen", "default"), false, _GP(usetup).Screen.FsSetup);
_GP(usetup).Screen.WinSetup =
@@ -355,8 +355,8 @@ void apply_config(const ConfigTree &cfg) {
#endif
_GP(usetup).Screen.Params.RefreshRate = CfgReadInt(cfg, "graphics", "refresh");
- _GP(usetup).Screen.Params.VSync = CfgReadInt(cfg, "graphics", "vsync") > 0;
- _GP(usetup).RenderAtScreenRes = CfgReadInt(cfg, "graphics", "render_at_screenres") > 0;
+ _GP(usetup).Screen.Params.VSync = CfgReadBoolInt(cfg, "graphics", "vsync");
+ _GP(usetup).RenderAtScreenRes = CfgReadBoolInt(cfg, "graphics", "render_at_screenres");
_GP(usetup).Supersampling = CfgReadInt(cfg, "graphics", "supersampling", 1);
_GP(usetup).software_render_driver = CfgReadString(cfg, "graphics", "software_driver");
@@ -367,12 +367,12 @@ void apply_config(const ConfigTree &cfg) {
rotation_str, CstrArr<kNumScreenRotationOptions>{ "unlocked", "portrait", "landscape" },
_GP(usetup).rotation);
#endif
- _GP(usetup).enable_antialiasing = CfgReadInt(cfg, "misc", "antialias") > 0;
+ _GP(usetup).enable_antialiasing = CfgReadBoolInt(cfg, "misc", "antialias");
// This option is backwards (usevox is 0 if no_speech_pack)
- _GP(usetup).no_speech_pack = CfgReadInt(cfg, "sound", "usespeech", 1) == 0;
+ _GP(usetup).no_speech_pack = !CfgReadBoolInt(cfg, "sound", "usespeech", true);
- _GP(usetup).clear_cache_on_room_change = CfgReadInt(cfg, "misc", "clear_cache_on_room_change", _GP(usetup).clear_cache_on_room_change) != 0;
+ _GP(usetup).clear_cache_on_room_change = CfgReadBoolInt(cfg, "misc", "clear_cache_on_room_change", _GP(usetup).clear_cache_on_room_change);
_GP(usetup).user_data_dir = CfgReadString(cfg, "misc", "user_data_dir");
_GP(usetup).shared_data_dir = CfgReadString(cfg, "misc", "shared_data_dir");
@@ -382,7 +382,7 @@ void apply_config(const ConfigTree &cfg) {
if (cache_size_kb > 0)
_GP(spriteset).SetMaxCacheSize((size_t)cache_size_kb * 1024);
- _GP(usetup).mouse_auto_lock = CfgReadInt(cfg, "mouse", "auto_lock") > 0;
+ _GP(usetup).mouse_auto_lock = CfgReadBoolInt(cfg, "mouse", "auto_lock");
_GP(usetup).mouse_speed = CfgReadFloat(cfg, "mouse", "speed", 1.f);
if (_GP(usetup).mouse_speed <= 0.f)
@@ -395,7 +395,7 @@ void apply_config(const ConfigTree &cfg) {
break;
}
}
- _GP(usetup).mouse_ctrl_enabled = CfgReadInt(cfg, "mouse", "control_enabled", _GP(usetup).mouse_ctrl_enabled) > 0;
+ _GP(usetup).mouse_ctrl_enabled = CfgReadBoolInt(cfg, "mouse", "control_enabled", _GP(usetup).mouse_ctrl_enabled);
const char *mouse_speed_options[kNumMouseSpeedDefs] = { "absolute", "current_display" };
mouse_str = CfgReadString(cfg, "mouse", "speed_def", "current_display");
for (int i = 0; i < kNumMouseSpeedDefs; ++i) {
@@ -417,7 +417,7 @@ void apply_config(const ConfigTree &cfg) {
} else if (override_os.CompareNoCase("mac") == 0) {
_GP(usetup).override_script_os = eOS_Mac;
}
- _GP(usetup).override_upscale = CfgReadInt(cfg, "override", "upscale", _GP(usetup).override_upscale) > 0;
+ _GP(usetup).override_upscale = CfgReadBoolInt(cfg, "override", "upscale", _GP(usetup).override_upscale);
}
// Apply logging configuration
diff --git a/engines/ags/engine/main/engine.cpp b/engines/ags/engine/main/engine.cpp
index effc54c2ae1..fb716eb89fd 100644
--- a/engines/ags/engine/main/engine.cpp
+++ b/engines/ags/engine/main/engine.cpp
@@ -947,7 +947,7 @@ void engine_read_config(ConfigTree &cfg) {
if (_GP(usetup).user_conf_dir.IsEmpty())
_GP(usetup).user_conf_dir = CfgReadString(cfg, "misc", "user_conf_dir");
if (_GP(usetup).user_conf_dir.IsEmpty()) // also try deprecated option
- _GP(usetup).user_conf_dir = CfgReadInt(cfg, "misc", "localuserconf") != 0 ? "." : "";
+ _GP(usetup).user_conf_dir = CfgReadBoolInt(cfg, "misc", "localuserconf") ? "." : "";
// Test if the file is writeable, if it is then both engine and setup
// applications may actually use it fully as a user config, otherwise
// fallback to default behavior.
diff --git a/engines/ags/shared/util/ini_util.cpp b/engines/ags/shared/util/ini_util.cpp
index c270d675c56..7584f2649e1 100644
--- a/engines/ags/shared/util/ini_util.cpp
+++ b/engines/ags/shared/util/ini_util.cpp
@@ -47,24 +47,38 @@ bool CfgReadItem(const ConfigTree &cfg, const String §n, const String &item,
return false;
}
-int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def_value) {
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def) {
String str;
if (!CfgReadItem(cfg, sectn, item, str))
- return def_value;
- return StrUtil::StringToInt(str, def_value);
+ return def;
+ return StrUtil::StringToInt(str, def);
}
-float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def_value) {
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int min, int max, int def) {
+ int val = CfgReadInt(cfg, sectn, item, def);
+ if ((val < min) || (val > max))
+ return def;
+ return val;
+}
+
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def) {
String str;
if (!CfgReadItem(cfg, sectn, item, str))
- return def_value;
- return StrUtil::StringToFloat(str, def_value);
+ return def;
+ return StrUtil::StringToFloat(str, def);
+}
+
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float min, float max, float def) {
+ float val = CfgReadFloat(cfg, sectn, item, def);
+ if ((val < min) || (val > max))
+ return def;
+ return val;
}
-String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def_value) {
+String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def) {
String str;
if (!CfgReadItem(cfg, sectn, item, str))
- return def_value;
+ return def;
return str;
}
diff --git a/engines/ags/shared/util/ini_util.h b/engines/ags/shared/util/ini_util.h
index 5b25d3437a8..6e4ca6b71f0 100644
--- a/engines/ags/shared/util/ini_util.h
+++ b/engines/ags/shared/util/ini_util.h
@@ -42,12 +42,20 @@ typedef std::map<String, StringOrderMap> ConfigTree;
//
// Helper functions for parsing values in a ConfigTree
bool CfgReadItem(const ConfigTree &cfg, const String §n, const String &item, String &value);
-int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def_value = 0);
-float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def_value = 0.f);
-String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def_value = "");
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int def = 0);
+int CfgReadInt(const ConfigTree &cfg, const String §n, const String &item, int min, int max, int def = 0);
+inline bool CfgReadBoolInt(const ConfigTree &cfg, const String §n, const String &item, bool def = false) {
+ return CfgReadInt(cfg, sectn, item, 0, 1, def) != 0;
+}
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float def = 0.f);
+float CfgReadFloat(const ConfigTree &cfg, const String §n, const String &item, float min, float max, float def = 0.f);
+String CfgReadString(const ConfigTree &cfg, const String §n, const String &item, const String &def = "");
//
// Helper functions for writing values into a ConfigTree
void CfgWriteInt(ConfigTree &cfg, const String §n, const String &item, int value);
+inline void CfgWriteBoolInt(ConfigTree &cfg, const String §n, const String &item, bool value) {
+ CfgWriteInt(cfg, sectn, item, static_cast<int>(value));
+}
void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value);
void CfgWriteFloat(ConfigTree &cfg, const String §n, const String &item, float value, unsigned precision);
void CfgWriteString(ConfigTree &cfg, const String §n, const String &item, const String &value);
Commit: 68e5184afa808f895effad82b759a674a69eec0d
https://github.com/scummvm/scummvm/commit/68e5184afa808f895effad82b759a674a69eec0d
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:51:30-07:00
Commit Message:
AGS: Replaced some (v)sprintfs with sNprintf counterparts
>From upstream a34bd392249f87a152dc470d90c67a7d193a28d8
Changed paths:
engines/ags/engine/ac/dialog.cpp
engines/ags/engine/ac/draw.cpp
engines/ags/engine/ac/global_debug.cpp
engines/ags/engine/ac/global_display.cpp
engines/ags/engine/ac/parser.cpp
engines/ags/engine/gui/gui_dialog.cpp
engines/ags/engine/main/quit.cpp
engines/ags/engine/script/cc_instance.cpp
engines/ags/shared/font/fonts.cpp
engines/ags/shared/util/text_stream_writer.cpp
engines/ags/shared/util/text_stream_writer.h
diff --git a/engines/ags/engine/ac/dialog.cpp b/engines/ags/engine/ac/dialog.cpp
index 0c56a31c041..8028019d7e6 100644
--- a/engines/ags/engine/ac/dialog.cpp
+++ b/engines/ags/engine/ac/dialog.cpp
@@ -171,10 +171,10 @@ int run_dialog_script(int dialogID, int offse, int optionIndex) {
int result = RUN_DIALOG_STAY;
if (_G(dialogScriptsInst)) {
- char funcName[100];
- sprintf(funcName, "_run_dialog%d", dialogID);
+ char func_name[100];
+ snprintf(func_name, sizeof(func_name), "_run_dialog%d", dialogID);
RuntimeScriptValue params[]{ optionIndex };
- RunScriptFunction(_G(dialogScriptsInst), funcName, 1, params);
+ RunScriptFunction(_G(dialogScriptsInst), func_name, 1, params);
result = _G(dialogScriptsInst)->returnValue;
} else {
// old dialog format
@@ -342,7 +342,7 @@ int write_dialog_options(Bitmap *ds, bool ds_has_alpha, int dlgxp, int curyp, in
if (_GP(game).dialog_bullet > 0)
actualpicwid = _GP(game).SpriteInfos[_GP(game).dialog_bullet].Width + 3;
- sprintf(tempbfr, "%d.", ww + 1);
+ snprintf(tempbfr, sizeof(tempbfr), "%d.", ww + 1);
wouttext_outline(ds, dlgxp + actualpicwid, curyp, usingfont, text_color, tempbfr);
}
for (size_t cc = 0; cc < _GP(Lines).Count(); cc++) {
diff --git a/engines/ags/engine/ac/draw.cpp b/engines/ags/engine/ac/draw.cpp
index 24be7797cb4..3f55aca36f8 100644
--- a/engines/ags/engine/ac/draw.cpp
+++ b/engines/ags/engine/ac/draw.cpp
@@ -1906,9 +1906,9 @@ void draw_fps(const Rect &viewport) {
char base_buffer[20];
if (!isTimerFpsMaxed()) {
- sprintf(base_buffer, "%d", _G(frames_per_second));
+ snprintf(base_buffer, sizeof(base_buffer), "%d", _G(frames_per_second));
} else {
- sprintf(base_buffer, "unlimited");
+ snprintf(base_buffer, sizeof(base_buffer), "unlimited");
}
char fps_buffer[60];
@@ -1921,7 +1921,7 @@ void draw_fps(const Rect &viewport) {
wouttext_outline(fpsDisplay, 1, 1, font, text_color, fps_buffer);
char loop_buffer[60];
- sprintf(loop_buffer, "Loop %u", _G(loopcounter));
+ snprintf(loop_buffer, sizeof(loop_buffer), "Loop %u", _G(loopcounter));
wouttext_outline(fpsDisplay, viewport.GetWidth() / 2, 1, font, text_color, loop_buffer);
if (ddb)
diff --git a/engines/ags/engine/ac/global_debug.cpp b/engines/ags/engine/ac/global_debug.cpp
index 1e3c6fe0d7d..f36e3b2ec90 100644
--- a/engines/ags/engine/ac/global_debug.cpp
+++ b/engines/ags/engine/ac/global_debug.cpp
@@ -116,7 +116,7 @@ void script_debug(int cmdd, int dataa) {
int goToRoom = -1;
if (_GP(game).roomCount == 0) {
char inroomtex[80];
- sprintf(inroomtex, "!Enter new room: (in room %d)", _G(displayed_room));
+ snprintf(inroomtex, sizeof(inroomtex), "!Enter new room: (in room %d)", _G(displayed_room));
setup_for_dialog();
goToRoom = enternumberwindow(inroomtex);
restore_after_dialog();
diff --git a/engines/ags/engine/ac/global_display.cpp b/engines/ags/engine/ac/global_display.cpp
index 1cad75d7aef..20ff4dfa14c 100644
--- a/engines/ags/engine/ac/global_display.cpp
+++ b/engines/ags/engine/ac/global_display.cpp
@@ -19,8 +19,6 @@
*
*/
-//include <cstdio>
-//include <stdarg.h>
#include "ags/shared/ac/common.h"
#include "ags/engine/ac/character.h"
#include "ags/engine/ac/display.h"
@@ -49,7 +47,7 @@ void Display(const char *texx, ...) {
char displbuf[STD_BUFFER_SIZE];
va_list ap;
va_start(ap, texx);
- vsprintf(displbuf, get_translation(texx), ap);
+ vsnprintf(displbuf, sizeof(displbuf), get_translation(texx), ap);
va_end(ap);
DisplayAtY(-1, displbuf);
}
diff --git a/engines/ags/engine/ac/parser.cpp b/engines/ags/engine/ac/parser.cpp
index 27e9779ced7..53a4f212bb8 100644
--- a/engines/ags/engine/ac/parser.cpp
+++ b/engines/ags/engine/ac/parser.cpp
@@ -19,8 +19,6 @@
*
*/
-//include <cctype> //isalnum()
-//include <cstdio>
#include "ags/shared/ac/common.h"
#include "ags/shared/ac/game_setup_struct.h"
#include "ags/engine/ac/game_state.h"
@@ -116,7 +114,7 @@ int FindMatchingMultiWordWord(char *thisword, const char **text) {
while (tempptr[0] == ' ') tempptr++;
char chbuffer[2];
while (is_valid_word_char(tempptr[0])) {
- sprintf(chbuffer, "%c", tempptr[0]);
+ snprintf(chbuffer, sizeof(chbuffer), "%c", tempptr[0]);
strcat(tempword, chbuffer);
tempptr++;
}
diff --git a/engines/ags/engine/gui/gui_dialog.cpp b/engines/ags/engine/gui/gui_dialog.cpp
index 761c6f3981e..5339ef9a479 100644
--- a/engines/ags/engine/gui/gui_dialog.cpp
+++ b/engines/ags/engine/gui/gui_dialog.cpp
@@ -391,7 +391,7 @@ int roomSelectorWindow(int currentRoom, int numRooms,
} else if (mes.code == CM_SELCHANGE) {
int cursel = CSCISendControlMessage(ctrllist, CLB_GETCURSEL, 0, 0);
if (cursel >= 0) {
- sprintf(_G(buffer2), "%d", roomNumbers[cursel]);
+ snprintf(_G(buffer2), sizeof(_G(buffer2)), "%d", roomNumbers[cursel]);
CSCISendControlMessage(ctrltbox, CTB_SETTEXT, 0, &_G(buffer2)[0]);
}
}
diff --git a/engines/ags/engine/main/quit.cpp b/engines/ags/engine/main/quit.cpp
index bed47df7001..3d61ba31d62 100644
--- a/engines/ags/engine/main/quit.cpp
+++ b/engines/ags/engine/main/quit.cpp
@@ -138,7 +138,7 @@ void quit_message_on_exit(const String &qmsg, String &alertis, QuitReason qreaso
// successful exit or user abort displays no messages
if ((qreason & (kQuitKind_NormalExit | kQuit_UserAbort)) == 0 && !_G(handledErrorInEditor)) {
// Display the message (at this point the window still exists)
- sprintf(_G(pexbuf), "%s\n", qmsg.GetCStr());
+ snprintf(_G(pexbuf), sizeof(_G(pexbuf)), "%s\n", qmsg.GetCStr());
alertis.Append(_G(pexbuf));
_G(platform)->DisplayAlert("%s", alertis.GetCStr());
}
diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 4cce579e337..83924c519fc 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -1240,7 +1240,7 @@ void ccInstance::GetScriptPosition(ScriptPosition &script_pos) {
RuntimeScriptValue ccInstance::GetSymbolAddress(const char *symname) {
int k;
char altName[200];
- sprintf(altName, "%s$", symname);
+ snprintf(altName, sizeof(altName), "%s$", symname);
RuntimeScriptValue rval_null;
for (k = 0; k < instanceof->numexports; k++) {
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 096074995d6..600aa7c3b22 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -427,7 +427,7 @@ void wgtprintf(Shared::Bitmap *ds, int xxx, int yyy, size_t fontNumber, color_t
va_list ap;
va_start(ap, fmt);
- vsprintf(tbuffer, fmt, ap);
+ vsnprintf(tbuffer, sizeof(tbuffer), fmt, ap);
va_end(ap);
wouttextxy(ds, xxx, yyy, fontNumber, text_color, tbuffer);
}
diff --git a/engines/ags/shared/util/text_stream_writer.cpp b/engines/ags/shared/util/text_stream_writer.cpp
index b4c1ecc4eec..770c32fef4b 100644
--- a/engines/ags/shared/util/text_stream_writer.cpp
+++ b/engines/ags/shared/util/text_stream_writer.cpp
@@ -77,14 +77,9 @@ void TextStreamWriter::WriteLine(const String &str) {
void TextStreamWriter::WriteFormat(const char *fmt, ...) {
va_list argptr;
va_start(argptr, fmt);
- int need_length = vsnprintf(nullptr, 0, fmt, argptr);
- va_start(argptr, fmt); // Reset argptr
- char *buffer = new char[need_length + 1];
- vsprintf(buffer, fmt, argptr);
+ _buf.FormatV(fmt, argptr);
va_end(argptr);
-
- _stream->Write(buffer, need_length);
- delete[] buffer;
+ _stream->Write(_buf.GetCStr(), _buf.GetLength());
}
void TextStreamWriter::WriteLineBreak() {
diff --git a/engines/ags/shared/util/text_stream_writer.h b/engines/ags/shared/util/text_stream_writer.h
index 4482a37ad6a..008b2fdeb83 100644
--- a/engines/ags/shared/util/text_stream_writer.h
+++ b/engines/ags/shared/util/text_stream_writer.h
@@ -61,6 +61,7 @@ public:
private:
Stream *_stream;
+ String _buf; // formatting string buffer
};
} // namespace Shared
Commit: d6cf666e428e0cf8552d58eff81cc18495f176f9
https://github.com/scummvm/scummvm/commit/d6cf666e428e0cf8552d58eff81cc18495f176f9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:52:45-07:00
Commit Message:
AGS: Fixed StrUtil::StringToFloat()
>From upstream 6942e5dde0cbc82e7870d7652c3f49095f4c641b
Changed paths:
engines/ags/shared/util/string_utils.cpp
diff --git a/engines/ags/shared/util/string_utils.cpp b/engines/ags/shared/util/string_utils.cpp
index 3ce4cc04d46..353e2579f9e 100644
--- a/engines/ags/shared/util/string_utils.cpp
+++ b/engines/ags/shared/util/string_utils.cpp
@@ -65,7 +65,7 @@ float StrUtil::StringToFloat(const String &s, float def_val) {
if (!s.GetCStr())
return def_val;
char *stop_ptr;
- int val = strtof(s.GetCStr(), &stop_ptr);
+ float val = strtof(s.GetCStr(), &stop_ptr);
return (stop_ptr == s.GetCStr() + s.GetLength()) ? val : def_val;
}
Commit: 72f8cbd0dc2fe2e442491a6bbcf28d60169557ca
https://github.com/scummvm/scummvm/commit/72f8cbd0dc2fe2e442491a6bbcf28d60169557ca
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:56:17-07:00
Commit Message:
AGS: fixed few more warnings
>From upstream 9de3edd60f1eb3244f6bd3f25d688b75b82a4776
Changed paths:
engines/ags/engine/ac/dynobj/script_overlay.cpp
diff --git a/engines/ags/engine/ac/dynobj/script_overlay.cpp b/engines/ags/engine/ac/dynobj/script_overlay.cpp
index 83d3619b4e5..879cb35f1ba 100644
--- a/engines/ags/engine/ac/dynobj/script_overlay.cpp
+++ b/engines/ags/engine/ac/dynobj/script_overlay.cpp
@@ -71,7 +71,7 @@ void ScriptOverlay::Unserialize(int index, Stream *in, size_t data_sz) {
overlayId = in->ReadInt32();
in->ReadInt32(); // unused (was text window x padding)
in->ReadInt32(); // unused (was text window y padding)
- hasInternalRef = in->ReadInt32();
+ hasInternalRef = in->ReadInt32() != 0;
ccRegisterUnserializedObject(index, this, this);
}
Commit: d2f3f2319b14fce4b614fe18060445593081c5d5
https://github.com/scummvm/scummvm/commit/d2f3f2319b14fce4b614fe18060445593081c5d5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2022-04-27T20:58:50-07:00
Commit Message:
AGS: Updated build version (3.6.0.22)
>From upstream 5688d924532961af446ba3052039e2da6924b726
Changed paths:
engines/ags/shared/core/def_version.h
diff --git a/engines/ags/shared/core/def_version.h b/engines/ags/shared/core/def_version.h
index 96952c2be58..838d76323eb 100644
--- a/engines/ags/shared/core/def_version.h
+++ b/engines/ags/shared/core/def_version.h
@@ -22,9 +22,9 @@
#ifndef AGS_SHARED_CORE_DEFVERSION_H
#define AGS_SHARED_CORE_DEFVERSION_H
-#define ACI_VERSION_STR "3.6.0.21"
+#define ACI_VERSION_STR "3.6.0.22"
#if defined (RC_INVOKED) // for MSVC resource compiler
-#define ACI_VERSION_MSRC_DEF 3.6.0.21
+#define ACI_VERSION_MSRC_DEF 3.6.0.22
#endif
#define SPECIAL_VERSION ""
More information about the Scummvm-git-logs
mailing list