4 #define MAXRENDERMODULES 64
6 typedef struct rendermodule_s
8 int active; // set by start, cleared by shutdown
11 void(*shutdown)(void);
16 rendermodule_t rendermodule[MAXRENDERMODULES];
18 void R_Modules_Init(void)
20 Cmd_AddCommand("r_restart", R_Modules_Restart);
23 void R_RegisterModule(char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void))
26 for (i = 0;i < MAXRENDERMODULES;i++)
28 if (rendermodule[i].name == NULL)
30 if (!strcmp(name, rendermodule[i].name))
32 Con_Printf("R_RegisterModule: module \"%s\" registered twice\n", name);
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;
45 void R_Modules_Start(void)
48 for (i = 0;i < MAXRENDERMODULES;i++)
50 if (rendermodule[i].name == NULL)
52 if (rendermodule[i].active)
54 Con_Printf ("R_StartModules: module \"%s\" already active\n", rendermodule[i].name);
57 rendermodule[i].active = 1;
58 rendermodule[i].start();
62 void R_Modules_Shutdown(void)
65 // shutdown in reverse
66 for (i = MAXRENDERMODULES - 1;i >= 0;i--)
68 if (rendermodule[i].name == NULL)
70 if (!rendermodule[i].active)
72 rendermodule[i].active = 0;
73 rendermodule[i].shutdown();
77 void R_Modules_Restart(void)
79 Con_Print("restarting renderer\n");
84 void R_Modules_NewMap(void)
87 for (i = 0;i < MAXRENDERMODULES;i++)
89 if (rendermodule[i].name == NULL)
91 if (!rendermodule[i].active)
93 rendermodule[i].newmap();