These days I'm working on my own engine, again. For the moment the whole environment runs on a PlayStation setup with non-linear code flow, which is basically a main loop with a scheduler of sorts that can jump among tasks, something that is referred by Sony as threading (but it's really not). So my question would be: is there any way on PC to preserve the machine state, jump to a section of code and keep that in sync between critical sections? Here's a sample of what I mean:
int main()This is my game loop, which keeps executing between frame VSync. Now, what Scheduler() does there is fetching tasks and returning to the main loop as soon as a "sleep" signal is hit. Here's an example of tasks altering code flow:
// reset pool
// cache pad reads
// set sort lists
// progress with threads
// carry fade effects
// display primitives and flip buffers
void Init_main()Task_sleep() is a function that takes a timer as a parameter to tell the scheduler how many vsync cycles it has to wait before code can be executed again from the point where it left, keeping the CPU state almost exactly like it was. The moment Task_sleep is called, my code returns to the body of Scheduler() and carries on with the following tasks if they are active. Usually the first task must always be active in order to have anything moving on screen, which is what Task_execute(0,Init_main) does. Task_execute() sets a function to the task list (first parameter is the priority of it, ranging from 0 to 2, where 0 means it's the first to be executed and 2 means the last), while Task_chain reroutes the program counter to another function by effectively taking the current task and changing code flow in a critical section, almost like an interrupt.
if(!(G.System_flg & SYSFLG_STOP))
for(i=0; i<MAX_ENEMIES; i++)
I tried searching for many approaches and apparently semaphores and mutex seem the closest thing, but I'm not entirely sure if they are even remotely similar, given the structure of my code so far.