Need to reduce FPS in the second thread, so here it is:
Just put this before your main loop:
GLOBAL THREAD_FPS=60 //Second Thread Runs at 60 FPS
StartThread_()
LIMITFPS -1
Put This in your main loop:
print magicnumber,10,10
Put this after your main loop..
FUNCTION StartThread_:
StartThread_A()
ENDFUNCTION
INLINE
extern "C" unsigned int _beginthread(void*, unsigned int stacksize, void* args);
void ThreadFunc( void *dummy ) {StartThread_B();}
ENDINLINE
FUNCTION StartThread_A:
INLINE
_beginthread((void*)ThreadFunc, 0,NULL);
ENDINLINE
ENDFUNCTION
FUNCTION StartThread_B:
WHILE TRUE //second thread running THREAD_FPS:
magicnumber=RND(1024)
SLEEP 1000/THREAD_FPS
WEND
ENDFUNCTION
Thank you gernot for the original release, ive been intending to play with this, but i never got around to it.
It works really good, and i think i can find a thousand uses for it.
btw i ditched the sub routine, made it all functions with the same-likeness name.
Very interesting... not sure how safe this is without MUTEX locking though ;)
use HThreads is multiplatform and has mutex functions
Quote from: trucidare on 2008-Oct-17
use HThreads is multiplatform and has mutex functions
What is mutex, and hthreads?
woops
i think this sleep command needs to be like this for fps
Quote
SLEEP 1000/THREAD_FPS
Edit: on hthreads.
I looked up hthreads....its too daunting for me to even begin to understand, and more so to implement.
I dont even have a way to test cross platform, even if i coded a c++ inline to do it.
I wanted to originally use the multithreading for mousestate to report independantly.
I think the best use for this might be networking, but i havent had time to tinker.
If anyone plays around with networking and this, let us know how well it does here..
notes:
1. maintain fps reports from each thread to find efficiency.
2. i think only 2 (main and second(this)) threads will run on windows.