'Elroids' Developer Code Notes.

Details on how/why the code works:

Structure

Top level classes work something like

Save/Load mechanism.

Game images are saved as JSON files.

Each object persists only none recreatable members. i.e NOT stuff, like meshes, that don't change and can be dynamically re-created.

Each persistable object has two methods:

Object sets can be handled with the utility class JSONSet.

Item/System IDs

During game operation references between objects are handled by standard javascript reference. However these won't survive save/load operations.

When a reference need to be saved the target object is assigned a unique ID. This is converted back to the new reference during re-load.

Item activation

In attempt to reduce memory/cpu footprint most threejs derived graphical object can exist in two states:

When Systems are constructed their Items are created with a populate() method. The Items are created in 'inactive' state.

When a System becomed 'active', generally because th Ship has moved into it, its setActive(true) method is called. This invokes the setActive() of it's child Items. Each sets up it's graphical components (generally by calling setumMesh()) and adds itself to the scene.

When a System become 'inactive' its setActive(false) method is called. The child Items must remove themselves from the scene and null all theit grapical components. The graphical parts should then be GCed.

ToDo: Maybe 'System' should extend threejs.Group. Objects contained in the System could be added to it. The the whole Group could be added/removed from scene.

Learnings

Units and dimensions

This project was coded with arbitary units of distance, mass and time. I have since modified it to use something resembling SI.

There are a few incorrect 'artifacts' to make the game playable.

Why not Typescript?

As a Java coder I prefer stongly typed languages. However...

  1. I only found out about Typescript late in the development of this project.
  2. I want the code available warts/comments and all. Not an additional build step with modified output.