miniSphere 5.0.0
miniSphere 5.0.0 is the fifth major release of the miniSphere game engine. This release replaces Duktape with the blazing-fast ChakraCore JavaScript engine, brings native ES6 and mJS module support to Sphere for the first time, and includes a great many API refinements, under-the-hood enhancements and optimizations!
Windows users:
Please uninstall any previous version of miniSphere before installing miniSphere 5.0. A great many files were moved or renamed; uninstalling old versions first ensures stale files from the previously installed version will be deleted that would otherwise interfere with the new version.
Important Considerations
-
As of miniSphere 5.0.0, the Core API has been frozen. Going forward, no further breaking changes will be made to the Core API and games written against it will continue to function as-is in future versions. This freeze does not apply to the Sphere Runtime!
-
miniSphere now uses ChakraCore for blazing-fast JavaScript performance. Chakra is the same engine used in Microsoft Edge and supports most modern JavaScript syntax natively, so you no longer need a
transpile()step in your Cellscript to take advantage of ES2015+ features such as arrow functions, destructuring, evenawait! -
Thanks to the introduction of
asyncandawait, the event loop is now a first-class part of the Sphere development experience. To that end, all Sphere v2 functions dedicated the old blocking style have been removed or refactored: bothSphere.run()andscreen.flip()are gone, andSphere.sleep()has been changed to return an awaitable promise instead of blocking the caller. -
mJS modules are now supported natively, without a transpiler. This allows you to use
importandexportto organize your codebase into self-contained modules without the added complexity of CommonJS.require()has in fact been deprecated and is now provided only for interop with transpilers such as Babel and modules originally written for Node.js. New code should always use the ES2015 module syntax (import/export) and the.mjsfile extension. -
The entire Sphere Runtime was overhauled and is now written entirely in mJS. This brought several breaking changes both major and minor. The big changes are listed below, but be sure to review the API documentation to get fully up to speed!
-
Because ES2015+ syntax is now supported natively, the Cell Runtime
transpilemodule has been cut. If you're currently using it in your build, you can simply change your Cellscript to useinstall()in place oftranspile()and everything should work as before. -
screenwas renamed toSurface.Screen, and the customscreenmethods have been moved into theSpherenamespace. Soscreen.frameRatebecomesSphere.frameRate, etc. -
Dispatch.onUpdate()andDispatch.onRender()now take an options object as their second parameter. Job priority is now be specified as a property of the options argument and defaults to 0.0 if not provided, as before. -
DataReaderandDataWriterhave been combined into a single class,DataStream, which inherits fromFileStream. This makes it easier to use as it's no longer necessary to construct a FileStream separately. Naturally, any code using the old classes will need to be updated to work with the new class. -
The
Consoleobject has been refactored into a full-fledged class. This allows an in-game console to be set up using explicitnew Console()syntax rather than the somewhat awkwardConsole.initialize(). It also makes it possible to create multiple consoles, in case that's ever needed. Existing code using theConsoleobject will need to be updated. -
The new
FocusTargetclass provides a centralized mechanism for managing input focus. Only one focus target can have the focus at any given time, making this very well-suited to managing input focus in, e.g., menu systems and map engines. Just importFocusTargetfromsphere-runtimeto try it! -
The
Pactclass has returned and provides a convenient way to make promises and settle them out-of-band without the awkwardness of working around the promise closure. As long as you have a reference to both the Promise object and the Pact it came from, you can resolve or reject it at any time. -
Scene#run()now returns a promise that can beawaited and never blocks. The boolean parameter that specified whether or not to block until completion has been removed; if you want a scene to run in the background, simply ignore the promise. -
Thread.join()is no longer a blocking call and instead returns a promise that can beawaited. This allows any thread to await termination of another without delaying other threads, regardless of how many joins are already underway. -
A new
sandboxfield in the JSON game manifest can be used to relax the SphereFS sandbox in order to ease development. The default is a full sandbox as before; 'relaxed' allows use of absolute paths and write access to the game directory, while 'none' disables the sandbox completely. -
Sphere.exit()has been replaced withSphere.shutDown(). Unlike the former function,Sphere.shutDown()does not exit immediately but rather cancels all outstanding Dispatch jobs, allowing the event loop to unwind naturally on the next tick.
What's Changed?
- miniSphere and Cell now use the ChakraCore JS engine under the hood, vastly improving JavaScript execution performance and bringing long-overdue native support for ES2015+ syntax and built-ins to Sphere.
- Overhauls the entire Sphere Runtime to take full advantage of the event loop as well as modern JavaScript features such as classes,
asyncfunctions, and promises. - Adds native support for ES2015+ syntax and mJS modules without transpilation.
- Adds back the
Pactclass, a more intuitive way to manage promises. - Adds a new
FocusTargetclass as a centralized means to manage input focus. - Adds a new
DataStreamclass, which extends fromFileStreamto allow more easily reading binary data such as integers and strings from a file. - Adds
Sphere.shutDown()which initiates an asynchronous exit. - Adds a new
inBackgroundoption for Dispatch jobs, for setting up background tasks that shouldn't keep the event loop alive by themselves. - Adds an optional
sandboxfield togame.jsonwhich can be set to eitherrelaxedornoneto relax the file system sandbox and ease development. - Adds
SSj.flipScreen(), useful for debugging rendering code. - Adds a
[Symbol.iterator]toDirectoryStream, allowing directory contents to be enumerated using a standardfor...ofloop. - Adds a new
--performancecommand line option for SpheRun which disables the stepping debugger to ensure JavaScript code runs at full speed. - Adds
fullScreenmanifest field to specify a game's default fullscreen mode. - Adds support for quick refs to SSj: when using
examine, this assigns a numeric handle to each object in the result, which you can quickly drill into by typing, e.g.,x *123. - Adds
Sphere.Compilerwhich evaluates to the name and version number of the compiler used to build the current game. - Changes
Sphere.sleep()to return a promise instead of blocking, allowing it to be used withawaitso as to avoid starving the event loop. - Changes
Consoleinto a full-fledged class, which allows for a familiarnew Console()usage and gives games the ability to set up multiple consoles if desired. - Changes
RNGto be compatible with the ES2015 iterator protocol. - Changes
SSjnamespace functions to be no-ops in the redistributable engine. - Changes
SSj.log()to perform JSON serialization if its argument is an object. - Changes SSj commands
eval,examineto not require quoting the expression. - Renames
screentoSurface.Screenand moves the customscreenproperties into theSpherenamespace. - Renames
from.Array()andfrom.Object()to lowercase to match typical JavaScript naming conventions. - Renames
screen.frameRateandscreen.now()toSphere.frameRateandSphere.now(), respectively. - Renames
Dispatch.cancel()toJobToken#cancel(). - Renames
Color#fade()toColor#fadeTo(). - Renames
Keyboard#getChar()toKeyboard#charOf(). - Renames
fragmentandvertexShader constructor options tofragmentFileandvertexFile, respectively. - Removes the experimental
Personclass from the Sphere Runtime. - Removes the now-redundant
DataReaderandDataWriterclasses. - Removes
screen.flip(),Sphere.run()andSphere.exit()in favor of the engine-provided event loop. - Removes the Cell
transpilemodule in favor of promoting native ES2015. - Improves the startup routines to also look in
dist/for a bundled game. - Improves the SSj debugging experience by preventing the engine from switching to fullscreen mode as long as the debugger is attached.
- Improves internal handling of UTF-8 strings, fixing several bugs related to text encoding. Notably,
FS.readFile()now correctly handles the UTF-8 signature/BOM if one is present. - Improves error reporting. SpheRun now prints a complete JavaScript backtrack to the terminal when a JavaScript runtime error occurs.