Comments (2)
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 ingame_state
: note the change innext_screen
and raise a game loop flagF_LOOP_WARP_TO_SCREEN
to signal that a screen switch is requested to thenext_screen
- Move the
next_screen
field into a newstruct warp_next_screen
ingame_state
, and add new fieldshero_x
andhero_y
, which contain the new hero coordinates after switching to thenext_screen
. - Modify the
do_rule_action_warp_to_screen
function to note the changes instruct warp_next_screen
instead of directly modifying the hero position - Modify the
game_state_switch_to_next_screen
function to use the noted changes instruct warp_next_screen
to switch the screen and move the hero to the new position in a single place.
from rage1.
fixed in 5e3746d
from rage1.
Related Issues (20)
- build: check that all banked functions are defined correctly HOT 1
- memory: migrate SP1 to banked code HOT 1
- sound: code refactor and event system HOT 1
- tracker: avoid including tracker functions when not used HOT 5
- banked_code: automatic generation of banked_code function definitions HOT 1
- main: create docker image HOT 1
- btile: change data layout to match struct sp1_tp
- tracker: allow use in 48K model with external AY addons
- btile: allow 8-bit tile IDs for lower memory usage
- btile: alternative XOR storage of tile data for better compression ratio HOT 1
- btile: alternative DATASET compression: ZX0 with initial prefix table HOT 1
- bullet: allow weapon enable/disable HOT 1
- enemy: allow non-harmful enemies
- btile: foreground tiles
- all: remove optimizations that are not HOT 1
- flow: add ELSE clause to rules
- Use game buffers for single-use code, like intros, demos, etc.
- Remove NETPBM dependency
- allow redefinition of keys for controlling the hero HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rage1.