Commit Graph
150 Commits
Author SHA1 Message Date
sluicebox 6eea9e517b SCI: Detect SCI16 unthrottled inner loops
This restores kGetEvent throttling (10ms delay) during inner loops that
don't throttle themselves. For example, the event processing loop in
Dialog:doit doesn't include a kWait(1) call in some games.
In these games, dialogs max out CPU, and if they run animations then
they run too fast. This happens in the CD version of JONES, bug #14020.

I had considered doing something like this earlier, but it wasn't clear
how to best detect these loops. What I didn't realize is that the SCI32
code already does this by counting kGetEvent calls in between kFrameout.
Now that technique is adapted for SCI16. Combined with the existing
"fast cast" detection, this throttles event-polling inner loops while
keeping the kGetEvent and kGameIsRestarting throttling separate so that
they don't overlap and conflict.

See: e09010f7d8
2023-01-10 14:50:51 -08:00
sluicebox e09010f7d8 SCI: Restrict kGetEvent throttling to fast cast mode
In 2010 a 10 ms delay was added to every kGetEvent call to prevent
maxing out the CPU when some games display message boxes:
b0b4ddcc52

This rapid kGetEvent polling is called fast cast and it only exists in
SCI1.1 games and some SCI1 games. It occurs in an inner loop when the
fast cast global is set.

Now the workaround is only applied to fast cast games and only when the
kGetEvent polling occurs.

Removing this 10 ms delay from every SCI16 game cycle doesn't change
game speed by itself because the larger dynamic throttling in
kGameIsRestarting has been absorbing the 10 ms. But this does make the
other throttles easier to understand and work with, and solves minor
edge cases where delays from multiple kGetEvent calls add up.
2022-08-02 17:23:34 -04:00
sluicebox 1b4660a508 SCI32: Fix event type for Direction events
The direction event type changed from 64 in SCI16 to 16 in SCI32.

Fixes direction events not appearing when pressing arrow keys in SCI32
games, such as on the QFG4 character creation screen: bug #13223
2022-01-16 13:52:09 -05:00
Eugene Sandulenko abea37c9bb ALL: Update ScummVM project license to GPLv3+ 2021-12-26 18:48:43 +01:00
Orgad Shaneh 940c7bfc14 SCI: Use nullptr
Using clang-tidy modernize-use-nullptr
2021-11-14 15:51:59 +02:00
Paul Gilbert 0136043f09 COMMON: Revert Change Rect and Point to have int32 fields
This reverts commit 1c3e7fb4e9.
2021-07-06 20:35:42 -07:00
Paul Gilbert 1c3e7fb4e9 COMMON: Change Rect and Point to have int32 fields 2021-07-04 18:24:26 -07:00
sluicebox 9982c761a2 SCI: Update all old bug tracker ticket numbers 2021-02-25 01:18:52 -08:00
sluicebox 82ccce948a SCI: Fix Mac icon bar event handling
Fix mouse presses falling through the icon bar in KQ6 and FPFP Mac
2019-04-01 01:16:53 +03:00
Colin Snover 7a41b6f023 SCI: Add support for keyup events
Basic keyup event support appears to have been added in the SCI1.1
IBM keyboard driver, and more robust support was provided in SCI32
which actually gets used by at least Lighthouse. This patch adds
support for keyup events in SCI1.1+.

Fixes Trac#10242.
2017-09-27 20:27:34 -05:00
Colin Snover 9a8070da3c SCI: Do some clean-up of event handling system
Convert macros and vars to enums, rename keyboard events in
preparation for adding key up events, clean up unnecessary nested
conditionals, add TODOs for potential future work.
2017-09-27 20:27:33 -05:00
Colin Snover 6b87b13ab1 SCI: Minor cleanups in kGetEvent 2017-07-23 10:35:13 -05:00
Colin Snover 3d92f05261 SCI32: Fix hot rectangle events
This fixes delayed mouse cursor updates during the chase scene in
Phant1.

Refs Trac#9975.
2017-07-23 10:35:13 -05:00
Colin Snover 9f910535c9 SCI32: Centralise OSystem screen updates 2017-07-06 19:12:35 -05:00
Colin Snover 57dd79d4dc SCI32: Detect and handle tight loops around kGetEvent
In SSCI, mouse events are received through a hardware interrupt
and the cursor is drawn directly to the graphics card by the
interrupt handler. This allows game scripts to omit calls to
kFrameOut without stopping the mouse cursor from being redrawn
in response to mouse movement.

ScummVM, in contrast, needs to poll for events and submit screen
updates explicitly from the main thread. Submitting screen updates
may block on vsync, which means that this call should really only
be made once per frame, just after the game has finished updating
its back buffer. The closest signal in SCI32 for having completed
drawing a frame is the kFrameOut call, so this is where the
update is submitted (by calling OSystem::updateScreen).

The problem with the approach in ScummVM is that, even though the
mouse position is being updated (by calls to kGetEvent) and drawn
to the backend's back buffer (by GfxCursor32::drawToHardware),
OSystem::updateScreen is never called during game loops that omit
calls to kFrameOut.

This commit introduces a workaround that looks at the number of
times kGetEvent is called between calls to kFrameOut. If the
number of kGetEvent calls is higher than usual (where "usual"
seems to be 0 or 1), we assume that the game is running one of
these tight event loops, and kGetEvent starts calling
OSystem::updateScreen until the next kFrameOut call. We also
then start throttling the calls to kGetEvent to keep CPU usage
down. This fixes at least two such known loops:

1. When interacting with the menu bar at the top of the screen
   in LSL6hires;
2. When restoring a game in Phant2 and sitting on the "click mouse"
   screen.

A similar workaround may also be needed for kGetTime, though loops
around kGetTime should preferably be replaced using a script patch
to call kWait instead.
2017-05-06 19:03:54 -05:00
Colin Snover 1ed185bbbb SCI: Implement delayed restore for SCI32 and move implementations to GuestAdditions 2017-04-22 13:01:35 -05:00
Colin Snover c8486395fa SCI: Clean up unnecessary delayed restore flags
_delayedRestoreGame is always set and cleared at the same time as
_delayedRestoreGameId, and _delayedRestoreFromLauncher is written
but never read.
2017-04-22 13:01:35 -05:00
Colin Snover 8c555200d9 SCI32: Change storage type of int16 arrays to hold reg_ts instead
Memory references and integers in SSCI are both 16-bit numbers,
so game scripts frequently (incorrectly) use an IntArray instead
of an IDArray for holding references. Since references in ScummVM
are 32-bit reg_ts, IntArray entries must be large enough to hold
reg_ts in order to be compatible with game scripts that store
references in integer arrays.

The alternative solution is to find and patch all incorrect use of
IntArray across all games. This is possible, but a bit risky from
a save game stability perspective, since incorrect IntArray usage
is sometimes not apparent until well after the array is
instantiated (like GK1's global interview array).

This change invalidates existing SCI32 save games.
2016-10-09 11:21:13 -05:00
Eugene Sandulenko dead4aa014 JANITORIAL: Remove trailing spaces 2016-10-09 14:59:58 +02:00
Colin Snover 44dd029cb1 SCI32: Implement kSetHotRectangles
Used only by chapter 7 of Phant1.
2016-09-29 19:39:16 -05:00
Colin Snover d0517f515e SCI32: Update screen on frameout, instead of in the event loop 2016-09-29 19:39:16 -05:00
Colin Snover eae6891404 SCI32: Fix kGlobalToLocal and kLocalToGlobal
Fixes (at least) the native SCI save dialogs.
2016-08-19 15:23:10 -05:00
Colin Snover 80d9182554 SCI32: Implement SCI32 cursor support 2016-08-19 13:57:40 -05:00
Martin Kiewitz c270b30a79 SCI: Fix pseudo mouse in various SCI1 games like e.g. Larry5
Pseudo mouse was functionality in SCI1+ games, that allowed the
user to control the mouse via keyboard cursor keys.

This new class only worked, when a tiny difference inside
the keyboard driver happened on kMapKeyToDir calls. We previously
tried to enable this behavior depending on cursor type, but
this didn't work correctly (Larry 5 for example was not detected
as such, but had PseudoMouse support).
2016-08-13 14:58:07 +02:00
Colin Snover 287391d1d5 SCI32: Fix incorrect mouse event coordinates in SCI2 hires 2016-03-11 19:05:13 -06:00
Martin Kiewitz 4ebca03534 SCI: Make cursor workaround work properly on OpenPandora
Other platforms, that support analog stick + touch screen at the
same time, are possibly also affected.

Cursor workarounds exist for qfg1vga, qfg3, lsl5 and Island of
Dr. Brain. Those sometimes worked and sometimes didn't on
at least OpenPandora and should be fixed now.
2016-03-05 21:28:09 +01:00
Martin Kiewitz 59d2c4b27e SCI: Do not pass/use .data for mouse button type
Also added comment about .data field. Should be renamed.
2016-02-02 02:10:43 +01:00
Martin Kiewitz c0bdbe1ca8 SCI: Fix control/Fx keys not working anymore
Was effectively caused by commit adding the keyboard driver bug
for SCI0/SCI01, although the bug is actually real and happens.

It seems Sierra did not check the key-modifier in kMenuSelect.
We do and that's why the code didn't recognize all sorts of
menu keys anymore.
We now isolate the lower byte before comparing.

I also noticed, that Sierra passed keyboard modifiers in mouse
events. This was probably done, so that owners of a 1-button
mouse were able to right-click. We do this now too.

Also added information about mouse modifiers in kGetEvent.

Moved the mouse modifier code into getScummVMEvent().

This should fix bug #7009.
2016-02-02 01:56:08 +01:00
Martin Kiewitz 453afd7bbc SCI: kGetEvent modifiers bug was fixed in SCI1
- SCI1 EGA QfG2 keyboard driver resets AH

In the original commit I forgot to mention:
- thanks to lskovlun for figuring out that bit 9 is checked/set
- thanks to wjp for checking SCI32
2016-01-03 18:32:25 +01:00
Martin Kiewitz f9459656f5 SCI: implement kGetEvent modifiers DOS bug
Will fix darts minigame in the fan game "Betrayed Alliance"
This bug in the original interpreter/keyboard driver seems to have
been fixed in SCI32.
2016-01-03 18:09:06 +01:00
Martin Kiewitz 0dd760724e SCI32: split up SCI2.1 into EARLY/MIDDLE/LATE
- Detection works via signatures (couldn't find a better way)
- new kString subcalls were introduced SCI2.1 LATE
- kString now has signatures and is split via subcall table
- kString fix, so that KQ7 doesn't crash, when starting a chapter
- Sci2StringFunctionType removed, because no longer needed
2015-12-29 01:44:11 +01:00
Martin Kiewitz bfba28c335 SCI: implement delayed restore via ScummVM menu
will delay restoring a saved game until the next
 kGetEvent or kWait
also implement aborting playback for kPortrait
 and kShowMovie
2015-04-26 09:08:46 +02:00
Willem Jan Palenstijn 4c03e4b699 SCI: Stop processing in kGetEvent after loading
getSciEvent can trigger the main ScummVM menu, which can trigger loading
a game, which will invalidate the game state that kGetEvent is operating
on.

Other kernel functions may still have the same problem, and a better
solution may be necessary.
2015-04-26 00:48:07 +02:00
Johannes Schickel daa8d57a86 ALL: Rename Debugger::DebugPrintf to Debugger::debugPrintf. 2014-05-27 02:04:07 +02:00
Johannes Schickel 8fc7d60feb SCI: Make GPL headers consistent in themselves. 2014-02-18 02:39:37 +01:00
Filippos Karapetis d840aa4dec SCI: Change wording for the cursor position workarounds 2013-04-28 23:31:10 +03:00
Filippos Karapetis 2b50824133 SCI: Add setter/getter methods to reg_t's
No functionality change has been made with this commit. This avoids
setting and getting the reg_t members directly, and is the basis of any
future work on large SCI3 scripts (larger than 64KB)
2012-06-18 05:24:06 +03:00
Max Horn 88913c0139 ALL: Remove trailing whitespaces
This tries to make our code a bit more compliant with our code formatting
conventions. For future use, this is the command I used:
  git ls-files "*.cpp" "*.h" | xargs sed -i -e 's/[ \t]*$//'
2011-06-20 00:59:48 +02:00
strangerke 69b1485a22 GIT: Clean up: Suppress SVN tags, now useless 2011-05-12 01:16:22 +02:00
Walter van Niftrik 952d1a084c SCI: Implement Mac iconbar event handling. 2011-03-09 21:05:19 +01:00
Johannes Schickel 463e475bd6 SCI: Save mouse position in SciEvent.
Instead of querying the event manager for the current mouse cursor coordinates
kGetEvent now uses the saved mouse positions, which will assure every event
will be processed with the correct coordinates instead of the current ones.
Various other functions using SciEvent directly were adapted too.

This fixes cursor click positions for the WinCE backend.

Thanks to wjp and waltervn for helping me with this.
2011-03-09 01:19:12 +01:00
md5 bd64c5078c SCI: Cleaned up kMapKeyToDir and removed an incorrect heuristic
The heuristic in question was used to detect the pseudo mouse control
functionality, however the change in controls seems to have occurred with the
transition to cursor views. Fixes keypad control in Conquest of the Longbow.
Moreover, the code also checked for key scan code 76 when checking for the middle
keypad button, which seems to be a mistake, as that case never occurred.
2011-02-15 15:46:15 +02:00
Filippos Karapetis 1528a3d904 SCI: A more efficient solution for bug #3037874 (SCI high CPU usage), which will hopefully
not clash with the speed throttler. This is a more proper fix for bug #3058865, and a
partial fix for bug #3127824

svn-id: r55046
2010-12-26 15:28:02 +00:00
Filippos Karapetis 976458058d SCI: Fixed bug #3058865 - "Jones in the Fast Lane CD: Graphics Missing"
svn-id: r52511
2010-09-03 22:51:27 +00:00
Martin Kiewitz fa7c6a9969 SCI: adding workaround for platform-specific
incompatibility with some sierra games. Some games open a new menu, set mouse cursor within that menu and expect the mouse cursor to be in there and will close it, if it's outside. In case of Wiimote/touch interfaces this logic won't work of course. Fixes island of dr. brain and QfG1VGA on Wii and touch-interface platforms

svn-id: r52474
2010-08-31 15:50:46 +00:00
Filippos Karapetis b0b4ddcc52 SCI: Fixed bug #3037874 - "SCI1.1: High cpu usage when a textbox is displayed"
svn-id: r52432
2010-08-29 00:58:27 +00:00
Martin Kiewitz b3949cf4be SCI: sci32 coord adjustment changes
- fixes lsl6hires inventory

svn-id: r51275
2010-07-25 16:31:46 +00:00
Martin Kiewitz 3090ee6ee7 SCI: sci32 changes
- mouse position now gets adjusted inside kGetEvent
- priority is read out during kFrameout
- check planeRect
- check if plane picture resource actually exists

fixes sq6

svn-id: r51270
2010-07-25 04:45:28 +00:00
Martin Kiewitz 15fc39589d SCI: more work on coordadjustment sci32
svn-id: r51084
2010-07-21 12:05:10 +00:00
Martin Kiewitz cef2e24edc SCI: fixing comment
svn-id: r51037
2010-07-19 20:13:17 +00:00