Multithreading (render/logic) and "radar"
Hi,
It''s become quite apparent to me that I''m going to need to create two seperate threads for my game (namely one for logic and one for rendering). I have a couple of questions regarding this:
(1) Can static variables be used across different threads?
(2) In order to allow both threads to have about the same processing time, will they both be required to have a window and/or process windows messages?
And I was just wondering...as I''m doing an underwater game, how could I implement a "world-to-radar" system? Assume I know these facts:
(1) X,Y,Z rotation of player in radians
(2) X,Y,Z location of player
(3) X,Y,Z location of object
(4) X and Y values can range -32 to 32
...how would I go about conversion?
thanks
(1) It depends. Are you using static variables that are local to a function, and having both threads use the same function? Each thread has its own stack, so I don''t think it would work...then again, I''m not sure.
(2) The threads will be looping, right? Just put in a Sleep(0) statement at the end of the loops (one statement per thread function), if you find that Windows is unresponsive (or very slow) while your game is running. What that does is tell Windows to give up the remainder of the thread''s time slice to other threads -- putting it at the end of the loop makes sense, then. Usually, you should not tamper with the thread''s priority -- that''s really the only way that some threads won''t get a chance to execute.
If you have a lot of data that you''re sharing between threads, it might make sense to protected both threads from accessing the data, by using a critical section (I''m assuming you''re in Windows). If it''s just a simple series of "flags," you can just declare them volatile, like this:
volatile int nFlags;
I''m not exactly sure how that would affect the performance of your engine -- it depends on how much you access the volatile variables.
(3) I don''t know...
Good Luck!
- null_pointer
(2) The threads will be looping, right? Just put in a Sleep(0) statement at the end of the loops (one statement per thread function), if you find that Windows is unresponsive (or very slow) while your game is running. What that does is tell Windows to give up the remainder of the thread''s time slice to other threads -- putting it at the end of the loop makes sense, then. Usually, you should not tamper with the thread''s priority -- that''s really the only way that some threads won''t get a chance to execute.
If you have a lot of data that you''re sharing between threads, it might make sense to protected both threads from accessing the data, by using a critical section (I''m assuming you''re in Windows). If it''s just a simple series of "flags," you can just declare them volatile, like this:
volatile int nFlags;
I''m not exactly sure how that would affect the performance of your engine -- it depends on how much you access the volatile variables.
(3) I don''t know...
Good Luck!
- null_pointer
static function variables are not allocated on the stack. As for static global variables... they''re unique to a single translational unit, so if both threads have access to that translational unit, then yes.
Threads with the same priority will have similar processing time. Probably the thing that would throw them off the most is synchronizing on data with each other.
Hmmm... You could create a vector from player to object, rotate that by the inverse of the player rotation, and project that vector into the XY plane.
Threads with the same priority will have similar processing time. Probably the thing that would throw them off the most is synchronizing on data with each other.
Hmmm... You could create a vector from player to object, rotate that by the inverse of the player rotation, and project that vector into the XY plane.
(3) could you transform the object points into a "radar space" by using a "radar matrix" (like a camera) positioned above the player, looking at the player, with the roll equal to players direction, then clip to radar bounds?
i don''t think this is the best way, but it SEEMS easy enough.
crazy166
some people think i'm crazy, some people know it
i don''t think this is the best way, but it SEEMS easy enough.
crazy166
some people think i'm crazy, some people know it
(1) Static data is shared across threads, even static data in functions (since this data does not reside on the stack.) In order to make static data not shared, you have to declare it with __declspec(thread).
(2) Both threads should get the same processing time, unless their priorities are different, or one does more blocking IO. The only difference is I think the thread with the foreground window gets a priority boost to increase interactivity. But you wouldn''t be able to get around this by creating two windows (one would still be foreground.)
(2) Both threads should get the same processing time, unless their priorities are different, or one does more blocking IO. The only difference is I think the thread with the foreground window gets a priority boost to increase interactivity. But you wouldn''t be able to get around this by creating two windows (one would still be foreground.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement