]> icculus.org git repositories - divverent/darkplaces.git/blob - r_modules.c
updated dsp files from Willis
[divverent/darkplaces.git] / r_modules.c
1
2 #include "quakedef.h"
3
4 #define MAXRENDERMODULES 64
5
6 typedef struct rendermodule_s
7 {
8         int active; // set by start, cleared by shutdown
9         char *name;
10         void(*start)(void);
11         void(*shutdown)(void);
12         void(*newmap)(void);
13 }
14 rendermodule_t;
15
16 rendermodule_t rendermodule[MAXRENDERMODULES];
17
18 void R_Modules_Init(void)
19 {
20         Cmd_AddCommand("r_restart", R_Modules_Restart);
21 }
22
23 void R_RegisterModule(char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void))
24 {
25         int i;
26         for (i = 0;i < MAXRENDERMODULES;i++)
27         {
28                 if (rendermodule[i].name == NULL)
29                         break;
30                 if (!strcmp(name, rendermodule[i].name))
31                         Sys_Error("R_RegisterModule: module \"%s\" registered twice\n", name);
32         }
33         if (i >= MAXRENDERMODULES)
34                 Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)\n", MAXRENDERMODULES);
35         rendermodule[i].active = 0;
36         rendermodule[i].name = name;
37         rendermodule[i].start = start;
38         rendermodule[i].shutdown = shutdown;
39         rendermodule[i].newmap = newmap;
40 }
41
42 void R_Modules_Start(void)
43 {
44         int i;
45         for (i = 0;i < MAXRENDERMODULES;i++)
46         {
47                 if (rendermodule[i].name == NULL)
48                         continue;
49                 if (rendermodule[i].active)
50                         Sys_Error("R_StartModules: module \"%s\" already active\n", rendermodule[i].name);
51                 rendermodule[i].active = 1;
52                 rendermodule[i].start();
53         }
54 }
55
56 void R_Modules_Shutdown(void)
57 {
58         int i;
59         // shutdown in reverse
60         for (i = MAXRENDERMODULES - 1;i >= 0;i--)
61         {
62                 if (rendermodule[i].name == NULL)
63                         continue;
64                 if (!rendermodule[i].active)
65                         continue;
66                 rendermodule[i].active = 0;
67                 rendermodule[i].shutdown();
68         }
69 }
70
71 void R_Modules_Restart(void)
72 {
73         Con_Print("restarting renderer\n");
74         R_Modules_Shutdown();
75         R_Modules_Start();
76 }
77
78 void R_Modules_NewMap(void)
79 {
80         int i;
81         for (i = 0;i < MAXRENDERMODULES;i++)
82         {
83                 if (rendermodule[i].name == NULL)
84                         continue;
85                 if (!rendermodule[i].active)
86                         continue;
87                 rendermodule[i].newmap();
88         }
89 }
90