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))
31 Sys_Error("R_RegisterModule: module \"%s\" registered twice\n", name);
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;
42 void R_Modules_Start(void)
45 for (i = 0;i < MAXRENDERMODULES;i++)
47 if (rendermodule[i].name == NULL)
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();
56 void R_Modules_Shutdown(void)
59 // shutdown in reverse
60 for (i = MAXRENDERMODULES - 1;i >= 0;i--)
62 if (rendermodule[i].name == NULL)
64 if (!rendermodule[i].active)
66 rendermodule[i].active = 0;
67 rendermodule[i].shutdown();
71 void R_Modules_Restart(void)
73 Con_Print("restarting renderer\n");
78 void R_Modules_NewMap(void)
81 for (i = 0;i < MAXRENDERMODULES;i++)
83 if (rendermodule[i].name == NULL)
85 if (!rendermodule[i].active)
87 rendermodule[i].newmap();