Commit Graph
217 Commits
Author SHA1 Message Date
D G Turner 298c54bcc1 AGS: Fix Various Signed vs. Unsigned Comparison GCC Compiler Warnings
These are emitted if -Wsign-compare is passed to GCC.
2024-11-05 22:54:04 +00:00
Le Philousophe 55fe1525ac AGS: Fix int vs int32 discrepancies 2024-10-31 08:53:43 +01:00
Walter Agazzi dcf9cfd880 AGS: Move drawstate to globals 2024-10-30 18:07:42 +02:00
Walter Agazzi cf3fcb8073 AGS: Move DrawFPS to globals 2024-10-30 18:07:42 +02:00
Walter Agazzi 3e57cad5de AGS: Engine: fixed CopyScreenIntoBitmap not applying filter when resizing
From upstream f1bca5eaa7ba2f2eb1363e7198a6f9fcf3518d8d
2024-10-30 18:07:42 +02:00
Walter Agazzi d05eeb5dc2 AGS: Engine: get rid of the room object sorting hack, use same rules for all
The sorting of the room objects + walkbehinds used some old hack, which behavior
dependent on a "walkbehind method" setting. But this setting is now deprecated
(and software renderer does not make walk-behinds a separate object).

Instead use a custom "sprite entry id" tag to help with sorting objects with equal zorder
(baseline). This lets to use same sorting algorithm for everything.
Walk-behinds should always be sorted back in case of equal zorder, so they receive
id = INT32_MIN.
From upstream 3b195eba0aaba9765e4dbfe427a0ba980fc3a1f6
2024-10-30 18:07:42 +02:00
Walter Agazzi b9879cb9c4 AGS: Engine: made FPS overlay react on font changes and abnormal fonts
From upstream 39649ad98e749a9f14909444df7d827305aa0039
2024-10-30 18:07:42 +02:00
Walter Agazzi a5831a36a3 AGS: Engine: only alloc sprite notifiers for dynamic sprites + add comment
From upstream d1e10c554662108b2b2f0fa89dce4eb3a5526e69
and ee554032fe2183170df7c577f829dac1706e144e
2024-10-30 18:07:42 +02:00
Walter Agazzi 92809e3114 AGS: Engine: rewrote dynamic sprite to texture notification mechanism
The previous attempt, using a boolean spritemodified array, proved to be having logical
loopholes. In simple words, because spritemodified flag was resetting each draw pass, it won't
affect objects that are temporarily not visible, and they failed to reupdate when becoming
visible again. This affected Software renderer.

Texture-based renderers have a different problem, where they fail to recognize when an old
sprite was deleted and a completely new dynamic sprite created accidentally with the same ID.
The cause was simply that the check for this was done inside sync_object_texture(), but
sync_object_texture itself was not called unless draw() function thought that object had
changed. So there has to be a check outside too...

Here I decided to reimplement notification mechanism, and use it for both types of renderers,
for the sake of more straightforward code logic. (Although, strictly speaking, texture-based
renderers could check their texture's "ref id" instead.)

The idea of a new implementation is this:
1. There's a map of "control blocks" per each active sprite (that is - sprite that was drawn as a
part of object). The "control block" is simply a integer with a sprite ID in it, allocated and
wrapped by shared_ptr.
2. When the ObjectTexture syncs its texture with a new sprite, the control block is retrieved (or
new created), and from now on it may be shared among multiple objects which display same
sprite.
3. When the sprite gets either updated or deleted two things happen: the previous control
block is assigned an "invalid value", serving as a marker, and then it is removed from the map,
left only if referenced by any ObjectTexture.
4. When checking whether texture needs to be re-synced we test the control block too, to see
if it was invalidated. In such case this tells us to call sync_object_texture() again.

NOTE that dynamic sprites that do not appear on screen, and are only used for drawing on
another surface, do not allocate control blocks, nor notify anything.

From upstream ab2dd5846075a73e3a3415c45c37fe6b37805964
2024-10-30 18:07:42 +02:00
Walter Agazzi 81130f543a AGS: Engine: fixed software renderer closing with textual overlay on screen
From upstream 466acb5ec274f4cef5f809a304c81e7922f95051
2024-10-30 18:07:42 +02:00
Walter Agazzi 38d23b5159 AGS: Engine: fixed spritemodified array not init after RunAGSGame()
From upstream ea108e9a01306641ec36128cb1ef5492766f2c32
2024-10-30 18:07:42 +02:00
Walter Agazzi 7af9888de2 AGS: Engine: rewrote dynamic sprite change notification method
Previous existing method ran through virtually all the game objects that may reference a sprite, and
checked each one of them. Those who did reference the modified dynamic sprite were marked for
update and/or had their draw caches cleared.
Furthermore, for safety reasons, the Graphic properties of these objects were reset to 0.

This process was slow under two conditions:
- if there are alot of objects (especially overlays which may be created at runtime in large quantities);
- if there are alot of temporary dynamic sprites created and deleted per game frame (for example,
when drawing something complicated).

The new method:
1. We no longer reset object properties, this turned to be a bad design. There's another safety fix done
in the SpriteCache, which returns a placeholder sprite for any invalid sprite ID. This should make things
simpler and faster.
2. For the texture-based renderers, it turned out that updating the shared texture entries was enough
to make objects using them redraw. So for these renderers we don't need to reset any more caches.
3. For software renderer, introduced a GameState::spritemodified vector of bools. Whenever a sprite is
modified or deleted, engine sets a corresponding flag in this vector, and that triggers an update at the
next draw pass for all the objects that still reference that sprite.

GUI PROBLEM: because GUIs rendering is still different from other objects, even in texture render
mode, they are still marked for update the old way.
This should be addressed separately in the future.
From upstream 0b84a21cfb486e3a9fa03e6c2b354750742ed3fd
and 3f70782761a698a69d31af77833c05bf38eb7394
2024-10-30 18:07:42 +02:00
Walter Agazzi dc30f4e2a8 AGS: Engine: Overlay uses ObjTexture similar to object and chars
+ fix free_dynamic_sprite in previous commit

From upstream 84432448725c77fbd3448a8d9c92e7e44e07a217
2024-10-30 18:07:42 +02:00
Walter Agazzi 2d2755f491 AGS; Engine: changed ScreenOverlay to store owned images as dynamic sprites
From upstream 4728d57086b7eedf112796da011f3c7b0dd3ad30
2024-10-30 18:07:42 +02:00
Walter Agazzi 1464a7e306 AGS: Engine: for software mode fixed removed overlay cache not invalidated
This is less of an issue in 3.6.1 (as opposed to 3.6.0), where overlays keep their
 container indexes if anything is removed in the middle; but still is meant to
  dispose remaining data.
From upstream 61afb63adbd3de77e7d23c40f1f5600bc58e9599
2024-10-30 18:07:42 +02:00
Walter Agazzi 5d58384af2 AGS: remove "supersampling" setting, as not entirely supported
This setting comes from the original mobile port of AGS, but it's not clear whether it was
useful. More importantly, there are issues with this:
1. It was never implemented in another hardware accelerated driver (Direct3D), being
exclusive to OpenGL.
2. It was never added to standard setup, so not very visible.
3. It's not clear whether it was working properly all this time. There were multiple changes to graphic renderers, and some of them may assume that rendering at "native resolution" is done at exactly, well, native resolution.
2024-10-30 18:07:42 +02:00
Walter Agazzi 7a0876b6b0 AGS: Engine: in CopyScreenIntoBitmap support src rect for legacy letterbox
Partially From upstream 6c028465648be5afe20eef34f0e5d0955329d3dd
2024-10-30 18:07:42 +02:00
Walter Agazzi 00fc3c38c3 AGS: Engine: narrow down sprite batch filtering for fade-out
This corrects recent b26c892
From upstream debccfe4a445df8bb16c7a16387c810adffcef10
2024-10-30 18:07:42 +02:00
Walter Agazzi 58dfedf323 AGS: Engine: hide mouse cursor and engine overlay when fading-out
From upstream b26c8920894a0622f8640ce6cbfe369f75c08422
2024-10-30 18:07:42 +02:00
Walter Agazzi 49af109669 AGS: Engine: implemented a method of skipping sprite batches on screenshot
This is meant to skip certain groups of sprites when taking a "screenshot",
 for instance when preparing a frozen game screen for the room transition
  (fade-out etc).
Think of hiding mouse cursor and engine overlay (fps counter etc).
Partially from upstream b0cd961483dcee8ffff7543c429fcd3272b413d5
2024-10-30 18:07:42 +02:00
Walter Agazzi 3cf3531d4f AGS: Engine: fixed Software render crashes if rendering in game_start script
The easiest way to replicate the problem is to call Display() in "game_start" script function.
From upstream 1a712f7a69105ec7730eb45d8bc483e95ec0af27
2024-10-30 18:07:42 +02:00
Walter Agazzi 00de3853ed AGS: Engine: fix backwards compatible Overlay z-sorting in creation order
Prior to introduction of explicit Overlay.ZOrder property, overlays were not sorted at all, and were
 drawn in the order of their storage in container, which coincidentally matched their order of creation.
 After Overlay.ZOrder was added, and overlays are sorted among GUIs using qsort, there's a potential
 issue of their drawing order being undefined (if two overlays have matching or unassigned ZOrder).
 This became a real issue after modification of the overlays internal storage, which was done for
 performance reasons.

The change introduces a global incrementing counter that assigns a "creation index" to Overlays, and
is used as a second factor during sorting, similar to how GUIs use their ID property.

From upstream 278dbc40e91a56a3728a567abb8620cc917729cb
2024-10-30 18:07:42 +02:00
Walter Agazzi 822842d038 AGS: Engine, Common: refactor guard using set_our_eip
Remove naked our_eip usages
From upstream 9f4371ab8c2fbc9ccf41b49f7b975ebe8bc5d1b8
2024-10-30 18:07:42 +02:00
Walter Agazzi 96db95c255 AGS: Engine: fix some minor warnings
From upstream 28693377db7ae242782b313717ec9c476ecaff0f
2024-10-30 18:07:42 +02:00
Walter Agazzi ffe86114e4 AGS: Complete "query gfxdriver for texture mem" commit
Completes a7f392a8f08ec14c48297ee05dd0bd0edb765df8
2024-10-30 18:07:42 +02:00
Walter Agazzi e407658475 AGS: Engine: in hw draw mode always assume walk-behinds are sprites
From upstream a2cfb4b3708aab7ef0911772fa83921420485999
and
b1e3a485c3e8500923aa9395fb5af69e288d3c0a
2024-10-30 18:07:42 +02:00
Walter Agazzi b498b14ecc AGS: Engine: save global draw method args in DrawState struct
Avoid query gfxDriver's properties all the time, instead save them once in init_draw_method() and use saved values.

From upstream db535512af65119d50ae3d6fb06c221d56f42d85
2024-10-30 18:07:42 +02:00
Walter Agazzi ee82074a47 AGS: Engine: further tidy up around agsplugin.h/cpp
* Moved plugin API event constants to a separate header agsplugin_evts.h.
Engine should not include whole plugin API, this is unnecessary, and may
 create naming conflicts.
* Moved SimulateMouseClick to mouse.cpp.
* Minor cleanup in agsplugin.cpp

From upstream 510293c1fd277d853544534423ceea27b8ae3e2d
2024-10-30 18:07:42 +02:00
Walter Agazzi 22cb981566 AGS: Engine: rewrote MoveList to avoid packed shorts
From upstream d463adac63817fd08eb757038f90c730726124d3
and 09203df6efb19cf0f2eafd098c798733bd85cfe0
2024-10-30 18:07:42 +02:00
Walter Agazzi 0da5748fa0 AGS: Fix FPS calculation 2024-10-30 18:07:42 +02:00
Walter Agazzi bd1bf59315 AGS: Common: hide GUIObject's size behind the get/set methods
From upstream ca442e0f9259d74a2bc6ccd7d28e59381ac1b9d1
2024-10-30 18:07:42 +02:00
Walter Agazzi 84f7493959 AGS: Engine: support scaling character sprite offsets after char's own zoom
Historically, neither Character.z (vertical offset), nor picture offsets (ones set by Character.LockViewAligned() and Character.LockViewOffset())
 were not scaled along with the character's sprite.
Although it seems like that would be a right thing to do in a majority of practical applications of these properties.

This change introduces a separate zoom factor for these parameters. It's done separately to be able to maintain backwards compatibility.
 In backwards mode this factor is always 100 (%), in the new mode it is always set equal to regular character's zoom (whether got from
  a manual property, or a walkable area scaling).
The switch between modes is controlled by OPT_SCALECHAROFFSETS. This supposed to be always set in the new games. But this is also
 a backup opportunity to disable this behavior, if a user finds it making it impossible to achieve a previously possible effect: in such case
  one may disable this when compiling a game, or call SetGameOption(OPT_SCALECHAROFFSETS, 0) in script.

Code-wise, I had to move get_effective_y() method to CharacterExtras class, which makes more sense, as that's a runtime character class,
 as opposed to CharacterInfo which is a game data serialization class, shared with the Editor.

There's still alot of potential for refactor and tidying the code, but I'd leave that for another task.

From upstream a2b0c88379f37fdaf44155e37f372b7de725db21
2024-10-30 18:07:42 +02:00
Walter Agazzi 9c633e250e AGS: Engine: cut out DebugConsole implementation, as unusable
This "console" implementation has multiple issues, making it unusable in practice:
- saves and displays only few lines, cannot scroll back;
while multiple game messages may be printed per a single game frame;
- messages cannot be filtered at runtime;
- uses a game font of a fixed number, which in unreliable (as the font may not be suitable);

There's not much value in its code; if a new console will be wanted in the future, then it
would be best to reimplement one from scratch, but with a good planning first.
From upstream c303590efca4632fef0fb2ab3143faba6e605ba8
2024-10-30 18:07:42 +02:00
Walter Agazzi 5b66b860af AGS: Engine: separate functions for getting game's set and real fps
From upstream cacaa9be6f7a0194b89fd2255acc9b8b612622b4
2024-10-30 18:07:42 +02:00
Walter Agazzi f9087ab378 AGS: Engine: optimized ScreenOverlays storage (vector variant)
Keep ScreenOverlays in std::vector, but do not erase elements
 in the middle and invalidate them instead. Record free indexes
 in a helper stack.
 When creating a new overlay, first check for the recorded free indexes.
Overlay's type now equals storage index.

This speeds up both creation/deletion of overlays, and their access.

Removed the gap between "fixed" overlay types and custom ones,
 to save space. If we ever need more special overlays, these could
 be created as custom and their ids saved in a variable (similar to
 how background speech works). Previously present special overlay
  types are left for backwards compatibility (and to simplify the transition).
  From upstream f7d2f162fa55aa1b6f37195d890ebe047a204154
2024-10-30 18:07:42 +02:00
Walter Agazzi d8d4a77724 AGS: Engine: hide "screenover" vector behind interface functions
From upstream 3b049092875293b0960013910586f3adb017c862
2024-10-30 18:07:42 +02:00
Walter Agazzi 9225909b77 AGS: Engine: disable vsync in the "infinite fps" mode
From upstream 689c4e459077d754e5dcbf8e4d97489122ac1e59
2024-10-30 18:07:42 +02:00
Walter Agazzi 90f94f74c0 AGS: Engine: reduced spriteset's [] operator use where possible
The spriteset's [] operator loads a sprite, but some operations may
 omit that and check the preloaded information instead.
This also makes it more certain where the actual sprite's bitmap is necessary.
From upstream df30fc1edd30d4f334addaf7883286e745dea2c3
2024-10-30 18:07:42 +02:00
Walter Agazzi b5617e2fc2 AGS: Engine: fixed a call to get_local_tint()
Was broken by a9e3a80
From upstream 8291c23dff6cea60b7e4d2c054b6453efb36b920
2024-10-30 18:07:42 +02:00
Walter Agazzi 32c2511523 AGS: Engine: a bool cast fix in construct_object_gfx()
From upstream a9e3a802cc34f72e17b1cad502f9ae949f7a30d7
2024-10-30 18:07:42 +02:00
Walter Agazzi dc693a5cb4 AGS: Engine: fixed get_local_tint() was inverting meaning of "use tint" arg
From upstream db3749a1bceb7d2b0ad3a5abeb3655e74f2f2ab6
2024-10-30 18:07:42 +02:00
Walter Agazzi 49fb8efa68 AGS: Engine: character and room object share function preparing texture
From upstream f1248c19ef988eb8b2c2f19f5a8b1465406b382f
2024-10-30 18:07:42 +02:00
Walter Agazzi 582a5ba422 AGS: Engine: pass ObjTexture directly into obj gfx generating funcs
From upstream 948837e7057cf4b41fc04c5684841b8d0c920d95
2024-10-30 18:07:42 +02:00
Walter Agazzi 1f335d8364 AGS: Engine: character and room object share function constructing gfx
from upstream 878da2b324a8afd4fcc761a66158cdf5e189386e
2024-10-30 18:07:42 +02:00
Walter Agazzi 69ea55b721 AGS: Engine: fixes to construct_object_gfx()
from upstream fb240801322d30eb957fbb6a9e228928a7345553
2024-10-30 18:07:42 +02:00
Walter Agazzi ca93d22ddd AGS: Engine: moved character scaling update from draw to main game update
from upstream f41eb86f25d425f4c8c040089131897d20419559
2024-10-30 18:07:42 +02:00
Walter Agazzi ddadaa75c7 AGS: Engine: moved room object scaling update from draw to main game update
From upstream c5e20301a490d22631975ada3e4fba91d650039d
2024-10-30 18:07:42 +02:00
Walter Agazzi 1eb11a29bc AGS: Engine: in construct_*_gfx use direct obj/char reference
From upstream 094e5e912fad794c1af00f31a49209cea4b54b79
2024-10-30 18:07:42 +02:00
Walter Agazzi 393aed7dd2 AGS: Engine: removed AGS_INLINE macro, as it's useless
from upstream e1919aa3b9e719f437e966780a41dd297eb82940
2024-10-30 18:07:42 +02:00
Walter Agazzi af1c822a15 AGS: Engine: picked out few bitmap conv functions to BitmapHelper
partially from upstream 0115cdafb1928245cf4613bda6dcebae60264b36
2024-10-30 18:07:42 +02:00