]> icculus.org git repositories - divverent/darkplaces.git/blob - r_modules.c
line editing: new binds ctrl-q (push line to history) and ctrl-u (delete line), simil...
[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, "restarts renderer");
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)", 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         Host_StartVideo();
80         Con_Print("restarting renderer\n");
81         R_Modules_Shutdown();
82         R_Modules_Start();
83 }
84
85 void R_Modules_NewMap(void)
86 {
87         int i;
88         for (i = 0;i < MAXRENDERMODULES;i++)
89         {
90                 if (rendermodule[i].name == NULL)
91                         continue;
92                 if (!rendermodule[i].active)
93                         continue;
94                 rendermodule[i].newmap();
95         }
96 }
97