DEV Community

🏎️Tim Beaudet🚀
🏎️Tim Beaudet🚀

Posted on

Crafting Games: Building a Custom Editor with Undo/Redo Support

Recently I’ve added Spline Based Editing to my level editor for building racetracks. This speeds up the process significantly because the designer, me, can drag a few nodes around the world and generate a smooth racetrack. The editor automatically creates the racetrack surface from a simple segment mesh that is input.

I did take a few shortcuts by using the CatmullRom to create the control points/handles for the underlying BezierCurve. This ensures the curve will pass directly through all the points, but doesn’t allow the designer complete control over the curve. It shouldn’t be the end of the world to add these later, famous last words.

Any good tool will support Undo/Redo and Track Builder (my editor) is built to be a good tool! Track Builder has been in development, adding a feature here and there, since 2019. Undo/Redo support was built in from the start using a command-based system. Each action the user can take is a small object that modifies the state of the editor/data, like: class AddNewOjectCommand.

This keeps a very small memory footprint and allows for the possibility of real-time collaboration features. 🤣 That will never happen! But commands do become a pain to deal with for add and delete type actions since object lifetimes are difficult. State-based undo/redo support is a little easier, tracking each state change by copying the previous state before making changes. This uses more memory, but that’s cheap these days!

Protip:

You can actually combine the command-based with state-based undo/redo support and if your (partial) state is small, it might not even use much memory.

For splines the state is actually quite small, just a handful of positions, so I created a generic ChangeSplineCommand() which took in the state of the spline before and after the change. This let me mix the command-based system with a bit of state-based undo/redo and get the support with minimal effort!

Why Not Use Game Engine?

This is a great question and as an independent developer it is one that should be very carefully considered. I have weighed the benefits carefully and although speed and ease of development may be improved with a major engine, it doesn't fit my long-term goals.

With a custom built engine:

  • I have full ownership of the engine.
  • I can design a workflow to meet my expectations.
  • I am responsible for, and capable of, fixing bugs.
    • Don’t need to design/work around issues.
    • OpenSource doesn’t always pull your fix/patches.
  • Having complete control over EXACTLY HOW things work.
    • No guessing, no undesired shortcuts, etc

This week I’m adding functionality to create decals, the plan is to add them into the editor first as cuboids and stub out the architecture in the game engine. I plan to hire this out because …

You can watch the development process of building custom editors this week and get inspired for your own tools to create games faster!

Top comments (0)