UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
r_thread.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright(c) 1997-2001 Id Software, Inc.
7 Copyright(c) 2006 Quake2World.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or(at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #include "r_local.h"
27 #include "../../ports/system.h"
28 #include "../../shared/thread.h"
29 
30 #ifndef _MSC_VER
31 #include <unistd.h>
32 #endif
33 
35 
36 #define THREAD_SLEEP_INTERVAL 5
37 
38 int R_RunThread (void* p)
39 {
40  while (r_threads->integer) {
41  if (!refdef.ready) {
43  continue;
44  }
45 
46  /* the renderer is up, so busy-wait for it */
47  while (r_threadstate.state != THREAD_BSP)
48  Sys_Sleep(0);
49 
50  if (!r_threads->integer)
51  break;
52 
54 
55  /* draw brushes on current worldlevel */
57 
60  r_threadstate.state = THREAD_RENDERER;
61  }
62 
63  return 0;
64 }
65 
69 void R_ShutdownThreads (void)
70 {
71  if (r_threadstate.thread) {
72  const int old = r_threads->integer;
73  r_threads->integer = 0;
74  r_threadstate.state = THREAD_BSP;
75  SDL_WaitThread(r_threadstate.thread, nullptr);
76  r_threads->integer = old;
77  }
78 
79  r_threadstate.thread = nullptr;
80 }
81 
85 void R_InitThreads (void)
86 {
87  r_threadstate.thread = Com_CreateThread(R_RunThread, "RendererThread");
88 }
cvar_t * r_threads
Definition: r_main.cpp:93
local graphics definitions
SDL_Thread * Com_CreateThread(int(*fn)(void *), const char *name, void *data=nullptr)
Definition: thread.h:5
int integer
Definition: cvar.h:81
renderer_threadstate_t r_threadstate
Definition: r_thread.cpp:34
int R_RunThread(void *p)
Definition: r_thread.cpp:38
void Sys_Sleep(int milliseconds)
Calls the win32 sleep function.
Definition: unix_shared.cpp:68
rendererData_t refdef
Definition: r_main.cpp:45
void R_GetLevelSurfaceLists(void)
Fills the surface chains for the current worldlevel and hide other levels.
Definition: r_bsp.cpp:281
threadstate_t state
Definition: cl_renderer.h:227
void R_SetupFrustum(void)
Definition: r_main.cpp:137
void R_InitThreads(void)
Definition: r_thread.cpp:85
void R_ShutdownThreads(void)
Definition: r_thread.cpp:69
#define THREAD_SLEEP_INTERVAL
Definition: r_thread.cpp:36