Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Proposal: Coroutine support  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

jeremy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Proposal: Coroutine support
« on: December 07, 2013, 08:59:12 am »
Many game engines (I realize SFML isn't one but this is for discussion) have support for coroutines. That is, for two routines to run alongside one another and communicate with each other on one thread. This occurs with user defined commands to switch contexts in the code.

For games, this is useful because I can write game behavior routines like:

void MeleeAttack(Target &target) {
    MoveToTarget(target);
    WaitForSeconds(1);
    AttackTarget(target);
}
 

Notice the 1 second cooldown between the time the unit moves to the target and when the unit actually attacks. This code is a bit easier to read than managing a number of state variables.

To do this, one could use boost.context or boost.coroutine but they are a bit heavy and will pull in several other boost libraries as well. Would it make sense to implement this support for SFML? It would require assembly unfortunately as one needs to store the copy the function context from the stack to the heap when execution is suspended and back to the stack again when execution resumes. This would need to be written for each target processor supported.

Coroutines are supposedly coming in C++17 but I'm not holding my breath. Meanwhile, C# and many other languages support this programming concept (straight from Knuth's 1st volume of AoCP).

Any thoughts on us working on something like this?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Proposal: Coroutine support
« Reply #1 on: December 07, 2013, 11:47:25 am »
Quote
Would it make sense to implement this support for SFML?
I don't think so.
Laurent Gomila - SFML developer