Giter Site home page Giter Site logo

Comments (2)

jorgegv avatar jorgegv commented on June 12, 2024

After an intensive debug session, I discovered what was happening.

  • I took a SZX snapshot of the game just in Screen B
  • I used SDXDATA tool (from my zxtools repo) to inspect the data in the snapshot. All the rule tables and hotzones for all screens had the correct data.
  • I set a breakpoint in the FLOW routine for switching screen when an ACTION of type WARP_TO_SCREEN is detected (do_rule_action_warp_to_screen)
  • I noticed that when I move to the left in Screen B, the breakpoint triggers (expected): the hero is over hotzone AB, so it correctly sets the new screen to move to (Screen A), and (important!) sets the hero position to the new one in the new screen (i.e. to the right in Screen A). This was done by rule number 5 in Screen B.
  • But when rule 5 finishes processing, RAGE1 continues evaluating rules in the same table for screen B (rule 5 is not the last one), and then comes rule 20, which checks if the hero is over hotzone BC to see if it needs to switch to screen C.
  • The hero has been moved already by rule 5, and the new coordinates (which should be only relative to screen A) are instead checked against the hotzone BC in Screen B. And by a big coincidence, the hotzone BC happens to be near the new hero coordinates, so it again triggers the screen switch, sets the next screen to Screen C and sets the hero coordinates to the proper ones in Screen C.
  • And then processing continues, and the hero appears in Screen C instead of Screen A as expected.

The bug:

  • The rules must only check the current game state, but they must not modify it, so that all rules see the same state on each rule table run. If they need to change state (change screen, change hero coordinates), they should note it somewhere, and only when all rules have finished running, do the necessary updates to the game state.

In this case, solution:

  • Use the same approach as was used with the next_screen field in game_state: note the change in next_screen and raise a game loop flag F_LOOP_WARP_TO_SCREEN to signal that a screen switch is requested to the next_screen
  • Move the next_screen field into a new struct warp_next_screen in game_state, and add new fields hero_x and hero_y, which contain the new hero coordinates after switching to the next_screen.
  • Modify the do_rule_action_warp_to_screen function to note the changes in struct warp_next_screen instead of directly modifying the hero position
  • Modify the game_state_switch_to_next_screen function to use the noted changes in struct warp_next_screen to switch the screen and move the hero to the new position in a single place.

from rage1.

jorgegv avatar jorgegv commented on June 12, 2024

fixed in 5e3746d

from rage1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.