Skip to main content
added 105 characters in body
Source Link
ratchet freak
  • 8.1k
  • 20
  • 16

itIt would be simpler to create to use events and fibers

usingUsing a fiber means you can yieldyield and sayreturn how many frames to wait until calling it should be called it again.

thenThen with a priority queue you can iterate over all events scheduled for the current frame.

IEnumerator<int> ai_script() 
    yield return 60;
    while(true)
    {
        shootAtPlayer();
        yield return 30;
    }
}

and then in the gameloop

while(running){

    frame++;
    updateFysics();
    
    IEnumerator<int> ie;
    while((ie = delayQueue.Pop(frame))!=null){
        if(ie.MoveNext()){//move next then does the call true means there is another wait, false means the task is done
            delayQueue.add(ie,ie.Current+frame);//Current holds the delay requested
        }
    }

}

thisThis solution is heavy misuse of C# syntax, but you can use explicit Fibers instead.

it would be simpler to create to use events and fibers

using a fiber means you can yield and say how many frames to wait until calling it again

then with a priority queue you can iterate over all for the current frame

yield return 60;
while(true)
{
    shootAtPlayer();
    yield return 30;
}

and then in the gameloop

while(running){

    frame++;
    updateFysics();
    
    IEnumerator<int> ie;
    while((ie = delayQueue.Pop(frame))!=null){
        if(ie.MoveNext()){//move next then does the call true means there is another wait, false means the task is done
            delayQueue.add(ie,ie.Current+frame);//Current holds the delay requested
        }
    }

}

this solution is heavy misuse of C# syntax, but you can use explicit Fibers instead

It would be simpler to create to use events and fibers

Using a fiber means you can yield and return how many frames to wait until it should be called it again.

Then with a priority queue you can iterate over all events scheduled for the current frame.

IEnumerator<int> ai_script() 
    yield return 60;
    while(true)
    {
        shootAtPlayer();
        yield return 30;
    }
}

and then in the gameloop

while(running){

    frame++;
    updateFysics();
    
    IEnumerator<int> ie;
    while((ie = delayQueue.Pop(frame))!=null){
        if(ie.MoveNext()){//move next then does the call true means there is another wait, false means the task is done
            delayQueue.add(ie,ie.Current+frame);//Current holds the delay requested
        }
    }

}

This solution is heavy misuse of C# syntax, but you can use explicit Fibers instead.

Source Link
ratchet freak
  • 8.1k
  • 20
  • 16

it would be simpler to create to use events and fibers

using a fiber means you can yield and say how many frames to wait until calling it again

then with a priority queue you can iterate over all for the current frame

yield return 60;
while(true)
{
    shootAtPlayer();
    yield return 30;
}

and then in the gameloop

while(running){

    frame++;
    updateFysics();
    
    IEnumerator<int> ie;
    while((ie = delayQueue.Pop(frame))!=null){
        if(ie.MoveNext()){//move next then does the call true means there is another wait, false means the task is done
            delayQueue.add(ie,ie.Current+frame);//Current holds the delay requested
        }
    }

}

this solution is heavy misuse of C# syntax, but you can use explicit Fibers instead