]> de.git.xonotic.org Git - xonotic/darkplaces.git/blob - r_modules.c
updated OBJECTS list and added cleaning of darkplaces-3dfx
[xonotic/darkplaces.git] / r_modules.c
1
2 #include "quakedef.h"
3
4 typedef struct rendermodule_s
5 {
6         int active; // set by start, cleared by shutdown
7         char *name;
8         void(*start)();
9         void(*shutdown)();
10 }
11 rendermodule_t;
12
13 rendermodule_t rendermodule[64];
14
15 void R_Modules_Init()
16 {
17         int i;
18         for (i = 0;i < 64;i++)
19                 rendermodule[i].name = NULL;
20 }
21
22 void R_RegisterModule(char *name, void(*start)(), void(*shutdown)())
23 {
24         int i;
25         for (i = 0;i < 64;i++)
26         {
27                 if (rendermodule[i].name == NULL)
28                         break;
29                 if (!strcmp(name, rendermodule[i].name))
30                         Sys_Error("R_RegisterModule: module \"%s\" registered twice\n", name);
31         }
32         if (i >= 64)
33                 Sys_Error("R_RegisterModule: ran out of renderer module slots (64)\n");
34         rendermodule[i].active = 0;
35         rendermodule[i].name = name;
36         rendermodule[i].start = start;
37         rendermodule[i].shutdown = shutdown;
38 }
39
40 void R_StartModules ()
41 {
42         int i;
43         for (i = 0;i < 64;i++)
44         {
45                 if (rendermodule[i].name == NULL)
46                         continue;
47                 if (rendermodule[i].active)
48                         Sys_Error("R_StartModules: module \"%s\" already active\n", rendermodule[i].name);
49                 rendermodule[i].active = 1;
50                 rendermodule[i].start();
51         }
52 }
53
54 void R_ShutdownModules ()
55 {
56         int i;
57         for (i = 0;i < 64;i++)
58         {
59                 if (rendermodule[i].name == NULL)
60                         continue;
61                 if (!rendermodule[i].active)
62                         continue;
63                 rendermodule[i].active = 0;
64                 rendermodule[i].shutdown();
65         }
66 }
67
68 void R_Restart ()
69 {
70         R_ShutdownModules();
71         R_StartModules();
72 }