theRAPTLab / gsgo

GEM-STEP Foundation repo migrated from GitLab June 2023
1 stars 1 forks source link

FIX: #421 `when` and `onEvent` now initialize at INIT time, not at COMPILE time - [merged] #697

Closed benloh closed 1 year ago

benloh commented 2 years ago

In GitLab by @daveseah on Jul 18, 2022, 13:47

Merges dev-sri/421-eventish-fix -> dev-next-gui

ELIMINATE PHANTOM EVENT HANDLERS

Issue #421 describes the case where event handlers are piling-up on recompile. This merge request addresses this by fixing the bugs in onEvent and when that modifies the simulation state at compile time instead of during an appropriate program phase; every time the GUI recompiles a blueprint, another copy of the handler was added to the simulation state.

These keywords now properly emit additional setup code into PROGRAM INIT automatically to do the registration at simulation start, not during compilation.

TESTING

TECHNICAL CHANGES

Additionally, there is some "secret smarts" enabled:

BONUS: REMOVE EXTRANEOUS PROGRAMS

Statements that go into PROGRAM EVENT:

Statements that go into PROGRAM UPDATE:

NOTICE: Possible complications with every

This keyword generates idiosyncratic timers that make assumptions about running inside a frame tick with a period of 30fps, which isn't the case with all block-defining statements.

benloh commented 2 years ago

In GitLab by @daveseah on Jul 18, 2022, 13:48

added 2 commits

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 18, 2022, 18:34

added 1 commit

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 18, 2022, 18:51

added 1 commit

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 18, 2022, 19:25

added 1 commit

Compare with previous version

benloh commented 2 years ago

I'm getting multiple complaints about the use of an unknown toUpperCase function:

It appears that the objects that toUpperCase is being called on are not necessarily strings, which causes js to choke.

We could just wrap the errant lines in a String() method, e.g.

      if (CHECK.IsValidBundleProgram(String(bundleOut).toUpperCase()))

But I want to make sure there aren't deeper issues at play here (e.g. bundleOut should be defined AND a string, and if isn't there's something else wrong up the chain).

Will test more tomorrow.

benloh commented 2 years ago

In GitLab by @daveseah on Jul 19, 2022, 24:47

added 2 commits

Compare with previous version

benloh commented 2 years ago

In GitLab by @daveseah on Jul 19, 2022, 24:49

@benloh ScriptEditor crash fixed; script-bundler GetBundleOutSymbols() was wrapping an array with Object.keys() when it should have returned it as-is. The keys of an array are the numeric indices.

benloh commented 2 years ago

Testing

onEvent

  1. Add an onEvent Start [[ ]] block
  2. Add a dbgOut 'one' line.
  3. Run the sim
  4. Console should show one line.
  5. Add a dbgOut 'two' line.
  6. Run the sim
  7. You should see one followed by two only once:
    one
    two

    If you see repeats, then the first compile of the program is still running, e.g.

    one
    one
    two

when

  1. Add this blueprint:

    # BLUEPRINT Character12
    # PROGRAM DEFINE
    useFeature Costume
    featCall Costume setCostume 'circle.json'
    useFeature Physics
    addFeature Touches
    featCall agent.Touches monitor 'Character12' b2b
    # PROGRAM INIT
    # PROGRAM EVENT
    when Character12 touches Character12 [[
    dbgOut 'TOUCH EVENT'
    ]]
    # PROGRAM UPDATE
    when Character12 touches Character12 [[
    featCall agent.Costume setGlow 1
    ]]
    # PROGRAM CONDITION
  2. Add two instances, set them next to each other so they touch

  3. Run the sim

  4. You should see both glow

  5. You should see multiple "TOUCH EVENT" in console.

  6. Comment out dbgOut 'TOUCH EVENT'

  7. Change featCall agent.Costume setGlow 1 to dbgOut 'NEW'

  8. Save to server

  9. Run the sim

  10. The two should no longer glow

  11. The console output should only show "NEW" -- if the characters are still glowing or you see "TOUCH EVENT" then the program was not cleared.


Confirmed onEvent works. Confirmed when works inside PROGRAM EVENT and PROGRAM UPDATE.

One note: We still need to modify mx-sim-control to do a full reset and re-compilation of blueprints. Otherwise old programs continue to run. The tests above won't work without this fix.

I already have code in my other branch that does this. Pushing it here momentarily.

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

@daveseah there's a demo when test called dies that I believe we should remove or comment out, if only so dies does not show up as a when test option.

It's in sim-conditions:25.

Wanted to make sure you weren't using it for something else before commenting out.

benloh commented 2 years ago

In GitLab by @daveseah on Jul 19, 2022, 11:25

re: simulator resets - yah, I didn't know where you were doing it figured you would take care of it!

re: mystery test - yah, go ahead and remove it!

benloh commented 2 years ago

added 1 commit

Compare with previous version

benloh commented 2 years ago

mentioned in commit be1b630035875e5d5c75c988af660816e0cd37f4