#6229 AGI FANMADE: function slowing down game

AGI Fanmade
closed-fixed
5
2013-05-11
2013-01-14
f100101ff
No

ScummVM 1.5.0 - Windows 7
I'm going through the fanmade game "Hank's Quest: Victim of Society" at the moment and I came across the following issue:
Having have.key() during a loop (the command that waits for the player to press any key during a cutscene (e.g.)) slows the game down considerably. It seems like the game speed is slowed down by 1 step (this is controlled with the variable v10), but this might be just the game itself slowing down.
Thanks in advance.

Discussion

  • f100101ff
    f100101ff
    2013-02-05

    Just some additional info: I notice it happening in other AGI games as well (fan and Sierra), so it's not an isolated problem. Hope that helps.

     
  • Could you give an explicit example of a scene in a Sierra AGI game where this happens? (With a savegame ideally.)

     
  • f100101ff
    f100101ff
    2013-02-07

    Thanks for the reply!

    I've tried several Sierra AGI games in both ScummVM and the NAGI interperter. I focused only on the introduction scenes of these games (so that's why I haven't attached any savegames for now).

    Games that slowed down in ScummVM:
    - King's Quest 3
    - Police Quest 1

    Games that worked normal:
    - Space Quest 1
    - Space Quest 2
    - Gold Rush
    - King's Quest 1
    - King's Quest 2
    - Leisure Suit Larry 1
    - Manhunter 1 : New York
    - Manhunter 2: San Fransisco

    Sierra games I didn't/couldn't test:
    - Donald Duck's Playground
    - King's Quest 4 (AGI)
    - The Black Cauldron

    I hope this helps!

    (BTW: I could test a couple of fanmade games as well if you like)

     
  • AgiEngine::testKeypressed() is calling mainCycle(). This seems needlessly overcomplicated just for a testing function.

    NAGI has a much simpler implementation of have.key which just checks for keyboard keypresses without invoking a game cycle.

    NAGI is doing this:

    u8 cmd_have_key()
    {
    u16 ax;
    ax = state.var[V19_KEYPRESSED];
    if ( ax == 0)
    {
    do
    {
    ax = char_poll();
    }
    while (ax == 0xFFFF);
    }

    if ( ax != 0 )
    {
    state.var[V19_KEYPRESSED] = ax;
    return 1;
    }
    else
    return 0;
    }

    An equivalent in ScummVM would be something like:
    uint32 key = doPollKeyboard();
    uint32 kascii = KEY_ASCII(key);
    if (kascii)
    setvar(vKey, kascii);
    handleController(key);
    if (key)
    _game.keypress = key;

    This will need testing, though

     
  • And here's the full implementation of uint8 AgiEngine::testKeypressed():

    uint8 AgiEngine::testKeypressed() {
    if (!_game.keypress) {
    uint32 key = doPollKeyboard();
    uint32 kascii = KEY_ASCII(key);
    if (kascii)
    setvar(vKey, kascii);
    handleController(key);

    if (key) {
    _game.keypress = key;
    return 1;
    }

    }

    return 0;
    }

    Do note that the function is only supposed to return true/false according to NAGI, not the full scancode

     
    • assigned_to: nobody --> thebluegr
    • status: open --> closed-fixed
     
  • Fixed in commit 5fadff5

    We now only test for events in testKeypressed() without updating the
    game cycle at all (NAGI doesn't update the game cycle either). This
    fixes the slowdowns in some animations where have.key() is issued,
    like Manannan's lightnings in the intro of KQ3 and the bullets in the
    intro of PQ1

    The fix will be available in the next daily version of ScummVM