Skip to main content

News

Topic: Proper way of using Sphere? (Read 179 times) previous topic - next topic

Proper way of using Sphere?
Any particular way Sphere is intended to be used? I seems pretty open/custom to me right now - run from the start script, drop in your code and just go. So can you really just plop whatever into your render/update loops, throw the map engine underneath and do whatever?

Or is there a more specific way of doing things the engine is suited for? Blit images and text over images and on and on? Use the map engine if you want, but it's totally not necessary and everything can just be fueled by the JavaScript?

Any particular way recommended to structure data? Just have global variables and objects for game data?

  • Rhuan
  • [*][*][*][*]
Re: Proper way of using Sphere?
Reply #1
miniSphere 5.0 is about to be released (due date the 31st) in which the Sphere v2 api will finally be stable additionally I'm hoping that the modules I've been working on to go with it https://github.com/rhuanjl/SphereLibs will provide a good base for a game (though no one other than me has tested them yet).

Previously with the Spherev1 api there were two basic means of working:
1. Use the mapEngine, have anything else you wanted to happen regularly go in the update script and render script and store key data as global objects.
2. Don't use the mapengine (as it's not suited to your project) set up your own loop with an update stage and a render stage etc.

With Sphere v2
1. The engine now provides the loop https://github.com/fatcerberus/minisphere/blob/master/docs/sphere2-core-api.txt#L153-L184
 - it has an update stage for logic a render stage and a dispatch stage (for handling one-offs)
2, I'm hoping that my Map Engine script can replace the v1 mapengine, it's intended to be more flexible and give more control - also for more complex maps it should run faster as there are fast less calls between JS and C
3. Generally with v2 globals are discouraged, run all your code as modules with their own seperate scopes, hand anything you need to share around as parameters.


  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Proper way of using Sphere?
Reply #2
Even with old Sphere, the engine was designed to be flexible and work in a "however you want" fashion, more or less. Newer versions of miniSphere add a LOT of convenience for the things everyone kept making their own solutions before in old Sphere.

But really, the basic idea of "lay out things however you like" is still applicable. You're free to define any scripts and load any code in any fashion you like. You don't even need to necessarily use the built in event loop if you don't want to.

Re: Proper way of using Sphere?
Reply #3
Generally with v2 globals are discouraged, run all your code as modules with their own seperate scopes, hand anything you need to share around as parameters.

Yeah, I remember modules throwing me off a while ago when I read about them when they were implemented.

I've been looking at this thread to try and learn more about them, but I'm still not 100% confident I know how to use them properly.

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Proper way of using Sphere?
Reply #4
I've started learning miniSphere more recently, but modules are surprisingly simple:

- Create a new mjs file, put some code in there.
- Prepend the export keyword to whatever functions or classes or variables you want to use in other script files.
- Do an import in those other script files.

Example:

main.mjs
Code: [Select]
import { SomeFunction, SomeClass } from '$/myscript'; //Refers to those functions in myscript.mjs

SomeFunction();
var f = new SomeClass();

myscript.mjs
Code: [Select]
export function SomeFunction() {
  //Regular function code in here
}

export class SomeClass() {
  constructor() {
      //Do class stuff in here or whatever
  }
}

Maybe you could come chat in the Discord chat, it's been very useful to me to get the hang of how things work as Fat Cerberus and Rhuan hang out there all the time. :)
  • Last Edit: October 29, 2017, 04:45:58 pm by DaVince

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Proper way of using Sphere?
Reply #5
Note the post you linked talks about CommonJS modules which are quite a bit different structurally from mJS but the same basic idea is present, to split up your program into self-contained units that don't interfere with each other.
miniSphere 5.0.1 - 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 enourmous man eating pigs ~Rhuan

Re: Proper way of using Sphere?
Reply #6
Really? That's all there is to them? Huh, thought they'd be more complicated than that.

And yeah, I've peeked into the Discord. Looks like you guys talk about stuff related to developing the engine that I can barely make sense of.

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: Proper way of using Sphere?
Reply #7
It used to be more complicated with CommonJS but now that it's built into the language, modules are very simple - you export from one file and import to another.  If you don't export it you can't access it from outside.
miniSphere 5.0.1 - 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 enourmous man eating pigs ~Rhuan

  • DaVince
  • [*][*][*][*][*]
  • Administrator
  • Used Sphere for, like, half my life
Re: Proper way of using Sphere?
Reply #8
Really? That's all there is to them? Huh, thought they'd be more complicated than that.

And yeah, I've peeked into the Discord. Looks like you guys talk about stuff related to developing the engine that I can barely make sense of.
That's just in the #engine-dev channel, which you could mute. #game-dev is there for game development questions and talk, and #spherical for any Sphere or community related talk at all.

Also, now that I'm actively working on a game, that's at least one person who's not talking about the complex inner mechanics all the time! But yeah, it'd be nice to have more people working on projects there, especially since it makes asking and answering questions so easy. It's very motivating.
  • Last Edit: October 29, 2017, 04:53:26 pm by DaVince

  • Rhuan
  • [*][*][*][*]
Re: Proper way of using Sphere?
Reply #9
And yeah, I've peeked into the Discord. Looks like you guys talk about stuff related to developing the engine that I can barely make sense of.
Sorry that's probably my fault :(

As for examples of modules, can I push my Map Engine and related files - all modular and all Sphere v2 code - have a read of the code: https://github.com/rhuanjl/SphereLibs