Skip to main content

News

Topic: Scenario 3.8.1 (multithreaded scene manager) (Read 11879 times) previous topic - next topic

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Scenario 3.8.1 (multithreaded scene manager)
Scenario is a cutscene engine for Sphere which allows you to coordinate complex cutscenes and other actions (such as animations) using multiple timelines and cooperative multithreading.

The current version is Scenario 3.8.1, released on March 14, 2015.

Get the script:


Changelog:
v3.8.1
  • Added support for minisphere's IsSkippedFrame.
v3.8
  • Refactored entire codebase and added documentation comments for all methods and scenelets.
  • Fixed bugs when forking inside of a doWhile loop where instructions inside the loop could overwrite each others' state.
  • Changed doWhile and doIf to take a function (lambda) as argument. The function will be called at scene time and should return true or false to determine how to proceed.
  • Removed scenelets doUntil and set.
v3.7.3
  • Hotfix for broken doIf and doUntil scenelets.
v3.7.2
  • Hotfix release to fix call scenelet regression in 3.7.
v3.7.1
  • Hotfix release to restore fork functionality which was completely broken in 3.7.
v3.7:
  • BREAKING CHANGE - Removed 'state' argument from all scenelet functions; scenelets should store state data using 'this' instead. Any custom scenelets will have to be rewritten.
  • New optional finish handler for scenelets, called immediately after the scenelet stops running (i.e. when its update function returns false).
  • Support for variables: Use set to set a variable; increment or decement to add or subtract 1 from its value, respectively. Variables can be accessed in scenelet code via scene.variables['var_name']
  • New control-flow commands: doIf, doWhile, doUntildoIf executes a block of commands only if a specified condition is met, the other two are similar but execute the same block repeatedly (loop) while or until the condition is met, respectively.
v3.6:
  • Renamed beginFork and endFork to fork and end, respectively.
  • New scene looping feature: Pass 'true' to the Scenario() constructor for an endlessly looping scene. This is useful for running looping animations in the background. Call Scenario.stop() if you need to break the loop.
  • New optional waitUntilDone argument for run() that mimics the old blocking behavior. Helpful for cutscenes.
  • Color mask for the fadeTo command is now shared by all scenes and persists after a scene ends. Don't forget to fade back in or the player won't be able to see anything!
  • Screen fades and camera manipulations are no longer reverted automatically at the end of a scene. This must now be done manually.
  • Running a scene no longer clears its command queue.  This lets you run the same scene more than once. Great for caching animation commands!
v3.5.4:
  • Sphere map engine is no longer required to be running to execute a scenario.
v3.5.3:
  • Running a scenario no longer detaches input automatically. If this is needed, you must detach and reattach the input yourself.
v3.5.2:
  • Added new commands marquee and tween. The latter is great for coordinating complex UI animations.
v3.5.1:
  • Removed unusable marquee command.
v3.5:
  • User is required to call Scenario.initialize before using the engine.
  • Calls to Scenario.update and Scenario.render must be added to the update and render scripts, respectively.
  • run() now returns immediately instead of running its own update loop. If your game relied on the old blocking behavior, you'll have to modify it.
  • New method: scene.isRunning checks whether the scene is still executing and returns true if it is, false if not.
v3.1:
  • Built-in commands now use seconds instead of milliseconds for duration.
  • Renamed 1 identifier:
    • checkInput -> getInput
  • Added support for cascaded command calls. This is the preferred method for scene composition now; examples updated accordingly.
  • Completed refactoring started in 3.0.
v3.0:
  • Major refactoring to make the codebase more readable and less bug-prone.
  • Renamed 4 identifiers:
    • defineAction -> defineCommand
    • walkPerson -> movePerson
    • execute -> run
    • handleInput -> checkInput

How to use Scenario:
First things first: The Sphere map engine must be running in order for Scenario to work. Then when you need a cutscene, you write something like this:
Code: (javascript) [Select]
DetachInput();
new Scenario()
    .marquee("Chapter 13: Some Random Girl Blows Up")
    .movePerson("Katelyn", "north", 100, 2, true)
    .pause(2.0)  // 2-second delay
    .killPerson("Katelyn")
    .playSound("BigExplosion.wav")
    .run(true);  // true to wait until scene finished, false to run in background
AttachInput("hero");

The real power of Scenario, however, lies in its forking feature, which enables multiple simultaneous timelines. For example, you can have the background music (or the screen!) fade in while other actions take place at the same time. As in this example:
Code: (javascript) [Select]
DetachInput();
new Scenario()
    .fork()  // fork the timeline
        // we're fading in, so we specify a transparent color (alpha=0) to fade to
        .fadeTo(CreateColor(0, 0, 0, 0), 5.0)  // fade in over 5 seconds
    .end()  // end the fork block
    .marquee("Chapter 13: Some Random Girl Blows Up")
    .movePerson("Katelyn", "north", 100, 2, true)
    .synchronize()  // pause until all forks are finished - we want to make sure the fade-in has finished before she blows up!
    .killPerson("Katelyn")
    .playSound("BigExplosion.wav")
    .run(true);
AttachInput("hero");

Starting with version 3.7, Scenario also includes support for conditional execution and looping.
Code: (javascript) [Select]
// The following scene flashes the screen to white and back twice:
var flashes = 0;
new Scenario()
    .doWhile(function() { return flashes++ < 2; })  // 2 iterations
        .fadeTo(CreateColor(255, 255, 255, 255), 0.25)
        .fadeTo(CreateColor(0, 0, 0, 0), 0.25)
    .end()
    .run();
  • Last Edit: September 17, 2017, 11:16:21 am by DaVince
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: [Script] Scenario 2.1.1
Reply #1
I changed your gist to use the Spherical [ gist ] tags, but it appears there is no limit to the box for the code. N E O should try and see if he can limit the height, so that scrollbars could pop up (I'm going to keep yours long like this, so N E O could test it). It's nice to have a gist here since I think it'll update as you update the source, and someone can copy and/or ask for the raw code all in one place.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: [Script] Scenario 2.1.1
Reply #2
Haha, thanks Radnen, I had no idea about the gist tag.  I was wondering why you guys wanted me to use Gist for this... now I know. :)
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

Re: [Script] Scenario 2.1.1
Reply #3
Awesome! I modified some version of Scenario to allow facing diagonal directions and to allow diagonal movement. Maybe I'll merge it or something, if you think that might be useful. I think I changed something else too (removed an obscure SpiderMonkey-specific trick, I think).

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: [Script] Scenario 2.1.1
Reply #4
Was the SpiderMonkey-specific trick my use of the "getter" syntax for the framerate property?  If so that was probably a wise move what with TurboSphere now using V8, and I believe that syntax is deprecated in newer versions of SpiderMonkey anyway.  I really wish JS had an elegant method of defining properties outside of an object literal...

Anyway, feel free to merge it, yeah.  I'm actually in the process of cleaning up Scenario's codebase right now, making the code easier to read.  Right now it's a bit of a mess as I did some odd stuff (not putting spaces between function arguments, etc.)
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: [Script] Scenario 2.1.1
Reply #5
@Radnen - thanks for the heads-up about long gists; I've added a bit of CSS to limit the height of a gist's content (not including the footer) to 20em and add scrollbars as needed.

Re: [Script] Scenario 2.1.1
Reply #6

Was the SpiderMonkey-specific trick my use of the "getter" syntax for the framerate property?  If so that was probably a wise move what with TurboSphere now using V8, and I believe that syntax is deprecated in newer versions of SpiderMonkey anyway.  I really wish JS had an elegant method of defining properties outside of an object literal...

Ah yes, that was it. The reason was actually because Esprima can't parse that syntax, even in the Harmony branch which parses a lot of SpiderMonkey-specific syntax. I'm using Esprima to do some... evil... stuff, compiling JS to JS so I can write a debugger as a separate Sphere game that can see all the local variables of the game being debugged... it's complicated and yucky, but in theory it might work.

Quote

Anyway, feel free to merge it, yeah.  I'm actually in the process of cleaning up Scenario's codebase right now, making the code easier to read.  Right now it's a bit of a mess as I did some odd stuff (not putting spaces between function arguments, etc.)

OK. How do I merge it? A new Gist?

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: [Script] Scenario 2.1.1
Reply #7
Oh, I assumed you already knew how.  I'm personally not at all familiar with git, but according to them, all gists are full git repositories, so I'd assume you could just commit to it somehow.  I don't know, either that or just tell me exactly what changes you made and I'll integrate them into Scenario 3.0...  :)
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • N E O
  • [*][*][*][*][*]
  • Administrator
  • Senior Administrator
Re: [Script] Scenario 2.1.1
Reply #8
GitHub has edit functionality (ie, a button labeled Edit) that apparently automates the "pull clone, commit update to clone, send pull request for merge" process all the way until the repo owner's choice to merge the edit or reject it. On gists, it shows up when you view the gist's revisions.

Oh, and glad to see Scenario back on the forums! I had an interesting time integrating it into my NShoot core for my Artyxx demo :)
  • Last Edit: April 09, 2013, 01:28:56 am by N E O

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: [Script] Scenario 2.1.1
Reply #9
I should also say that your Scenario had inspired me to make a clone of it for my RadLib library. It's a re-implementation of it: eventmanager.js.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

Re: [Script] Scenario 2.1.1
Reply #10

Oh, I assumed you already knew how.  I'm personally not at all familiar with git, but according to them, all gists are full git repositories, so I'd assume you could just commit to it somehow.  I don't know, either that or just tell me exactly what changes you made and I'll integrate them into Scenario 3.0...  :)

I don't really know how with Gists. Cool that they're full git repos, I wasn't aware of that.

Thanks NEO!

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Scenario 2.1.1
Reply #11
So the plan was originally just to clean up the Scenario codebase a little and do a minor version bump to 2.2, but instead I ended up getting caught up in a major refactoring exercise. So needless to say, it's going to take longer than originally planned, but hopefully Scenario 3.0 will be worth the wait. :)
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

Re: Scenario 2.1.1
Reply #12
Here's Scenario 2.1 (not 2.1.1) extended to support diagonal movement.



Feel free to incorporate this into Scenario 3.0 if you want, Lord English. It's not particularly complicated anyway.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Scenario 2.1.1
Reply #13
Haha, to be honest I don't even remember what I changed between 2.1 and 2.1.1. It couldn't have been anything major or I would have bumped it to 2.2 instead.  Oh well, I'll look over it, thanks alpha!

Edit: Hm, so apparently 2.1.1 was all refactoring, and somehow I managed to make the code MORE of a mess than it already was in the process.  I really have to get 3.0 finished as quickly as possible! :)
  • Last Edit: April 11, 2013, 02:03:17 pm by Lord English
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Scenario 3.0
Reply #14
The long-awaited Scenario 3.0 is finished!  I did some major refactoring on the codebase, documented the important methods in the JS file, and as per alpha123, added diagonal support to facePerson.  I refrained from incorporating the diagonal support in movePerson (renamed from walkPerson in 2.1.1) as it would require modifications to the way the step count is calculated, as walk speed is implemented as a vector with independent X and Y speeds.  Maybe that'll make it into 3.1...
miniSphere 5.0b2 (stable: 4.8.8) - Cell compiler - SSj debugger - thread | on GitHub
For the sake of our continued health I very much hope that Fat Cerberus does not become skilled enough at whatever arcane art it would require to cause computers to spawn enormous man-eating pigs ~Rhuan