4 #define MAXRENDERMODULES 20
6 typedef struct rendermodule_s
8 int active; // set by start, cleared by shutdown
11 void(*shutdown)(void);
13 void(*devicelost)(void);
14 void(*devicerestored)(void);
18 rendermodule_t rendermodule[MAXRENDERMODULES];
20 void R_Modules_Init(void)
22 Cmd_AddCommand(CMD_CLIENT, "r_restart", R_Modules_Restart_f, "restarts renderer");
25 void R_RegisterModule(const char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void), void(*devicelost)(void), void(*devicerestored)(void))
28 for (i = 0;i < MAXRENDERMODULES;i++)
30 if (rendermodule[i].name == NULL)
32 if (!strcmp(name, rendermodule[i].name))
34 Con_Printf("R_RegisterModule: module \"%s\" registered twice\n", name);
38 if (i >= MAXRENDERMODULES)
39 Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)", MAXRENDERMODULES);
40 rendermodule[i].active = 0;
41 rendermodule[i].name = name;
42 rendermodule[i].start = start;
43 rendermodule[i].shutdown = shutdown;
44 rendermodule[i].newmap = newmap;
45 rendermodule[i].devicelost = devicelost;
46 rendermodule[i].devicerestored = devicerestored;
49 void R_Modules_Start(void)
52 for (i = 0;i < MAXRENDERMODULES;i++)
54 if (rendermodule[i].name == NULL)
56 if (rendermodule[i].active)
58 Con_Printf ("R_StartModules: module \"%s\" already active\n", rendermodule[i].name);
61 rendermodule[i].active = 1;
62 rendermodule[i].start();
66 void R_Modules_Shutdown(void)
69 // shutdown in reverse
70 for (i = MAXRENDERMODULES - 1;i >= 0;i--)
72 if (rendermodule[i].name == NULL)
74 if (!rendermodule[i].active)
76 rendermodule[i].active = 0;
77 rendermodule[i].shutdown();
81 void R_Modules_Restart_f(cmd_state_t *cmd)
84 Con_Print("restarting renderer\n");
89 void R_Modules_NewMap(void)
92 R_SkinFrame_PrepareForPurge();
93 for (i = 0;i < MAXRENDERMODULES;i++)
95 if (rendermodule[i].name == NULL)
97 if (!rendermodule[i].active)
99 rendermodule[i].newmap();
104 void R_Modules_DeviceLost(void)
107 for (i = 0;i < MAXRENDERMODULES;i++)
109 if (rendermodule[i].name == NULL)
111 if (!rendermodule[i].active)
113 if (!rendermodule[i].devicelost)
115 rendermodule[i].devicelost();
120 void R_Modules_DeviceRestored(void)
123 for (i = 0;i < MAXRENDERMODULES;i++)
125 if (rendermodule[i].name == NULL)
127 if (!rendermodule[i].active)
129 if (!rendermodule[i].devicerestored)
131 rendermodule[i].devicerestored();