First a little background… In the game engine that I am developing my world consists of a bunch of entities. Each entity is composed of a bunch of components. One such component is a
Script component class. This class represents a single chaiscript file. My main loop simply calls the
update() method on every component attached to every entity in the game world. The
update() method just calls the
update() function defined within the chaiscript file.
Each entity can have more than one
Script component, each representing different chaiscript files. Ideally, I would like each script to be sandboxed so that one does not affect the other. Also, the state of each script should persist across update calls so that any global variables defined in one iteration of the main loop are available in the next.
I see two possible options for achieving this:
Scriptinstance has its own
- Use a single
chaiscript::ChaiScriptobject. Each script then stores a
chaiscript::ChaiScript::Stateobject, which is restored before
update()and saved after
I’m curious as to which option is preferable from a performance standpoint. Bear in mind that the game world can have hundreds of entities each containing several
Script components. Using the second option would require copying and restoring the
chaiscript::ChaiScript::State object hundreds of times per frame.
Thank you for any insight.