]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - r_modules.c
rewrote colormapping handling to store colormap_pantscolor and colormap_shirtcolor...
[xonotic/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                 {
32                         Con_Printf("R_RegisterModule: module \"%s\" registered twice\n", name);
33                         return;
34                 }
35         }
36         if (i >= MAXRENDERMODULES)
37                 Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)\n", MAXRENDERMODULES);
38         rendermodule[i].active = 0;
39         rendermodule[i].name = name;
40         rendermodule[i].start = start;
41         rendermodule[i].shutdown = shutdown;
42         rendermodule[i].newmap = newmap;
43 }
44
45 void R_Modules_Start(void)
46 {
47         int i;
48         for (i = 0;i < MAXRENDERMODULES;i++)
49         {
50                 if (rendermodule[i].name == NULL)
51                         continue;
52                 if (rendermodule[i].active)
53                 {
54                         Con_Printf ("R_StartModules: module \"%s\" already active\n", rendermodule[i].name);
55                         continue;
56                 }
57                 rendermodule[i].active = 1;
58                 rendermodule[i].start();
59         }
60 }
61
62 void R_Modules_Shutdown(void)
63 {
64         int i;
65         // shutdown in reverse
66         for (i = MAXRENDERMODULES - 1;i >= 0;i--)
67         {
68                 if (rendermodule[i].name == NULL)
69                         continue;
70                 if (!rendermodule[i].active)
71                         continue;
72                 rendermodule[i].active = 0;
73                 rendermodule[i].shutdown();
74         }
75 }
76
77 void R_Modules_Restart(void)
78 {
79         Con_Print("restarting renderer\n");
80         R_Modules_Shutdown();
81         R_Modules_Start();
82 }
83
84 void R_Modules_NewMap(void)
85 {
86         int i;
87         for (i = 0;i < MAXRENDERMODULES;i++)
88         {
89                 if (rendermodule[i].name == NULL)
90                         continue;
91                 if (!rendermodule[i].active)
92                         continue;
93                 rendermodule[i].newmap();
94         }
95 }
96