]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_modules.c
Fix GCC 12 warns: comparison will always evaluate as true
[xonotic/darkplaces.git] / r_modules.c
1
2 #include "quakedef.h"
3
4 #define MAXRENDERMODULES 20
5
6 typedef struct rendermodule_s
7 {
8         int active; // set by start, cleared by shutdown
9         const char *name;
10         void(*start)(void);
11         void(*shutdown)(void);
12         void(*newmap)(void);
13         void(*devicelost)(void);
14         void(*devicerestored)(void);
15 }
16 rendermodule_t;
17
18 rendermodule_t rendermodule[MAXRENDERMODULES];
19
20 void R_Modules_Init(void)
21 {
22         Cmd_AddCommand(CF_CLIENT, "r_restart", R_Modules_Restart_f, "restarts renderer");
23 }
24
25 void R_RegisterModule(const char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void), void(*devicelost)(void), void(*devicerestored)(void))
26 {
27         int i;
28         for (i = 0;i < MAXRENDERMODULES;i++)
29         {
30                 if (rendermodule[i].name == NULL)
31                         break;
32                 if (!strcmp(name, rendermodule[i].name))
33                 {
34                         Con_Printf("R_RegisterModule: module \"%s\" registered twice\n", name);
35                         return;
36                 }
37         }
38         if (i >= MAXRENDERMODULES)
39                 Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)", MAXRENDERMODULES);
40         rendermodule[i].active = 0;
41         rendermodule[i].name = name;
42         rendermodule[i].start = start;
43         rendermodule[i].shutdown = shutdown;
44         rendermodule[i].newmap = newmap;
45         rendermodule[i].devicelost = devicelost;
46         rendermodule[i].devicerestored = devicerestored;
47 }
48
49 void R_Modules_Start(void)
50 {
51         int i;
52         for (i = 0;i < MAXRENDERMODULES;i++)
53         {
54                 if (rendermodule[i].name == NULL)
55                         continue;
56                 if (rendermodule[i].active)
57                 {
58                         Con_Printf ("R_Modules_Start: module \"%s\" already active\n", rendermodule[i].name);
59                         continue;
60                 }
61                 Con_DPrintf("Starting render module \"%s\"\n", rendermodule[i].name);
62                 rendermodule[i].active = 1;
63                 rendermodule[i].start();
64         }
65 }
66
67 void R_Modules_Shutdown(void)
68 {
69         int i;
70         // shutdown in reverse
71         for (i = MAXRENDERMODULES - 1;i >= 0;i--)
72         {
73                 if (rendermodule[i].name == NULL)
74                         continue;
75                 if (!rendermodule[i].active)
76                         continue;
77                 Con_DPrintf("Stopping render module \"%s\"\n", rendermodule[i].name);
78                 rendermodule[i].active = 0;
79                 rendermodule[i].shutdown();
80         }
81 }
82
83 void R_Modules_Restart_f(cmd_state_t *cmd)
84 {
85         CL_StartVideo();
86         Con_Print("Restarting renderer\n");
87         SCR_BeginLoadingPlaque(false);
88         R_Modules_Shutdown();
89         R_Modules_Start();
90 }
91
92 void R_Modules_NewMap(void)
93 {
94         int i;
95         R_SkinFrame_PrepareForPurge();
96         for (i = 0;i < MAXRENDERMODULES;i++)
97         {
98                 if (rendermodule[i].name == NULL)
99                         continue;
100                 if (!rendermodule[i].active)
101                         continue;
102                 rendermodule[i].newmap();
103         }
104         R_SkinFrame_Purge();
105 }
106
107 void R_Modules_DeviceLost(void)
108 {
109         int i;
110         for (i = 0;i < MAXRENDERMODULES;i++)
111         {
112                 if (rendermodule[i].name == NULL)
113                         continue;
114                 if (!rendermodule[i].active)
115                         continue;
116                 if (!rendermodule[i].devicelost)
117                         continue;
118                 rendermodule[i].devicelost();
119         }
120 }
121
122
123 void R_Modules_DeviceRestored(void)
124 {
125         int i;
126         for (i = 0;i < MAXRENDERMODULES;i++)
127         {
128                 if (rendermodule[i].name == NULL)
129                         continue;
130                 if (!rendermodule[i].active)
131                         continue;
132                 if (!rendermodule[i].devicerestored)
133                         continue;
134                 rendermodule[i].devicerestored();
135         }
136 }
137