]> git.xonotic.org Git - xonotic/darkplaces.git/blob - r_modules.c
Fix client version of ambientsound, a buffer position check and a typo. Add missing...
[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(CMD_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_StartModules: module \"%s\" already active\n", rendermodule[i].name);
59                         continue;
60                 }
61                 rendermodule[i].active = 1;
62                 rendermodule[i].start();
63         }
64 }
65
66 void R_Modules_Shutdown(void)
67 {
68         int i;
69         // shutdown in reverse
70         for (i = MAXRENDERMODULES - 1;i >= 0;i--)
71         {
72                 if (rendermodule[i].name == NULL)
73                         continue;
74                 if (!rendermodule[i].active)
75                         continue;
76                 rendermodule[i].active = 0;
77                 rendermodule[i].shutdown();
78         }
79 }
80
81 void R_Modules_Restart_f(cmd_state_t *cmd)
82 {
83         Host_StartVideo();
84         Con_Print("restarting renderer\n");
85         R_Modules_Shutdown();
86         R_Modules_Start();
87 }
88
89 void R_Modules_NewMap(void)
90 {
91         int i;
92         R_SkinFrame_PrepareForPurge();
93         for (i = 0;i < MAXRENDERMODULES;i++)
94         {
95                 if (rendermodule[i].name == NULL)
96                         continue;
97                 if (!rendermodule[i].active)
98                         continue;
99                 rendermodule[i].newmap();
100         }
101         R_SkinFrame_Purge();
102 }
103
104 void R_Modules_DeviceLost(void)
105 {
106         int i;
107         for (i = 0;i < MAXRENDERMODULES;i++)
108         {
109                 if (rendermodule[i].name == NULL)
110                         continue;
111                 if (!rendermodule[i].active)
112                         continue;
113                 if (!rendermodule[i].devicelost)
114                         continue;
115                 rendermodule[i].devicelost();
116         }
117 }
118
119
120 void R_Modules_DeviceRestored(void)
121 {
122         int i;
123         for (i = 0;i < MAXRENDERMODULES;i++)
124         {
125                 if (rendermodule[i].name == NULL)
126                         continue;
127                 if (!rendermodule[i].active)
128                         continue;
129                 if (!rendermodule[i].devicerestored)
130                         continue;
131                 rendermodule[i].devicerestored();
132         }
133 }
134