Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary Actor Locals #1565

Open
Steinbeuge opened this issue Sep 4, 2024 · 2 comments
Open

Temporary Actor Locals #1565

Steinbeuge opened this issue Sep 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Steinbeuge
Copy link

Is your feature request related to a problem? Please describe.

Actor Locals consume script_memory values and limit the amount of actors you can place if you use them. They behave as hidden globals.
There are no Temporary Actor Locals for scripting behaviours.

Describe the solution you'd like

Reserved 16 slots in script_memory for temporary actor values. The values are reused for the 10 total actor instances available at any one time.

Change the default behaviour of Actors Locals to become temporary. Add a switch (tick box) on the Actor panel Labelled something like "Remember Locals", when Enabled the Actor Locals behave as they currently do. (alternatively make it say "Locals are temporary", disabled is current behaviour, enabled is the new temporary value)

Other solutions might be:

On the actor panel a list of the locals with a tick box controls, each Actor Local can be toggled between temporary and persistent

Add Instance Temps to the list of Actor Local properties, the instance temps are variables stored in the Actors C Struct, they can only be accessed via Property. add a "Self" reference when selecting an actor in Event editor and expressions to get the temp values. For expressions and VM, something like $Self_Temp1, .Self_Temp1 ( I feel like this is the ideal solution, it will allow scripting native behaviours that share a variable across native, VM and Events)

Reserve more than 16 slots, so that actors in scrolling scenes that exceed the 10 Actor limit can still have their own temps, an actor that does not have "keep running while offscreen" enabled can then be disabled when off screen, and enabled again when on, and remember its state for the duration of that scene.

Describe alternatives you've considered
Programming a plugin that does all this. I feel something like this should be in GB Studio by default though, to reduce hidden global usage when placing repeating actor prefabs. It will also allow repeated spawning of an actor that has a prefab defined amount of hitpoints and things like that. Whatever the solution, I think having temporary locals is ideal for reusability

@Steinbeuge Steinbeuge added the enhancement New feature or request label Sep 4, 2024
@chrismaltby
Copy link
Owner

chrismaltby commented Sep 5, 2024

Hi @Steinbeuge good idea. I'm testing out a few ideas of how to implement without changing too much. I have a branch now that's not exactly what you've suggested but maybe this will still work for your needs:

  • The two temporary variables (which were previously just two globals) have been expanded to six
  • Temporary variables used within actors/scenes/triggers/prefabs are now local to that entity
  • Temporary locals can be renamed per entity
  • When building your project the addresses of temporary locals are allocated so that the memory is reused for every different scene
  • So if you used every temporary local available in a single scene that would take 306 global variables (6 for the scene itself, 6 * 20 actors, 6 * 30 triggers) but you could do this in EVERY scene and it would still only take up the same 306 global variables
  • On each scene init, all the temporary locals are reset back to 0

Not sure how much sense this makes but basically the 6 locals still work exactly how they did before, but there's now 6 extra temporary locals that are in shared memory, they will keep their value while you stay on the current scene but when you change scene they will all reset back to zero.

If you want to try this build out you can download it here:
https://github.com/chrismaltby/gb-studio/actions/runs/10722899049

I think there's a few issues with how the shared variable addresses appear in the debugger and I'll need to write lots of tests but it seems like it might be a solution that doesn't require too much extra to add to the UI

@Steinbeuge
Copy link
Author

Steinbeuge commented Sep 7, 2024

If you want to try this build out you can download it here:

Just did some tests and it appears to work great!

Updated my Native Actors plugin to it and it seems to work flawlessly. Scenes can have more than 10 actors, off screen disabling works and they recall their positions when back on screen.

Seems ideal, keen to see it in main, cheers for the test build!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants