News for hackers. Stuff that matters.
Re:Simple coroutines for games in C++ by jamesu on Sunday March 20, 2016 @03:12PM (#11324182)
One big problem with using coroutines for "scripting" long running events in games I don't often see mentioned is what to do - if anything - about saving their state. For cutscenes this can be ignored for sure, but what if you tie something like a long conversation tree into a coroutine?

For this example library if your making some sort of traditional adventure game and you wanted the player to be able to save the game you'd have to restrict saving to checkpoints, use a loop with a switch (practically moving back to the state machine approach), or just split the conversation up into multiple coroutines as it progresses.

And of course, there's the whole "what to do when you need to patch the game" problem on top of all that.

Re:Simple coroutines for games in C++ by arianvanp on Sunday March 20, 2016 @03:25PM (#11324246)
There was a discussion in the /r/haskell subreddit about serialisable coroutines a week back: https://www.reddit.com/r/haskell/comments/4a8wr8/how_to_get_...

Perhaps it helps

Re:Simple coroutines for games in C++ by TillE on Sunday March 20, 2016 @05:56PM (#11324868)
Yeah, I've had the exact same problem while exploring coroutines. Stackless Python is the only implementation I'm aware of which allows you to trivially serialize its microthreads.

In the end, I prefer to just use mostly "stateless" Lua scripts, with all the saveable data managed in C++.

Re:Simple coroutines for games in C++ by looki on Sunday March 20, 2016 @10:35PM (#11325842)
As a lot of people have mentioned Lua ITT, there's a library called Pluto[1] which can serialize coroutine states. It was used in the game Fable to store quest statuses[2].

[1]: http://lua-users.org/wiki/PlutoLibrary see also Tamed Pluto

[2]: http://www.slideshare.net/hughreynolds/lua-and-fable-jonatha...

Re:Simple coroutines for games in C++ by vmorgulis on Sunday March 20, 2016 @06:05PM (#11324899)
> For cutscenes this can be ignored for sure, but what if you tie something like a long conversation tree into a coroutine?

I would use an embeddable scripting language (like Duktape) for entities. The state would be available at any time. It can also be parallelized.

http://duktape.org/