I would like to implement a simple game logic engine that is agnostic to the rendering system, but I don't know how to do that, really... so I would like to have advise and know the state of the art!
the idea is to have a "logic" class that contains the step to be done to advance the game, for instance "show this to the user" or "wait for user input on this choice": while it was easy to make it work in a textual user interface like this:
forever {
switch logic_get_next_action() {
// Writes a message to the user on the provided output
when MESSAGE: write(stdout, logic_get_message());
// Writes multiple choices, then waits for an input
when CHOICE: {
for c in logic_get_choices() {
write(stdout, c);
}
logic_update_state(read(stdin));
}
...
}
}
initially I thought that decoupling from stdin and stdout would be enough, and I could devise some sort of encoding that would allow me to use another kind of interface, but I realized this is very textual-centered, and relies on some synchronicity.
for instance it relies on the writes in choice to happen and be concluded before the read, and also blocks on read.
I suppose a more asynchronous solution is needed here but not really sure on how to proceed: don't want to be trapped in local choices! for instance after the textual prototype I am using an immediate mode GUI toolkit now, but what changes will I have to make if I ever switch to a retained mode?