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(CF_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_Modules_Start: module \"%s\" already active\n", rendermodule[i].name);
61 Con_DPrintf("Starting render module \"%s\"\n", rendermodule[i].name);
62 rendermodule[i].active = 1;
63 rendermodule[i].start();
67 void R_Modules_Shutdown(void)
70 // shutdown in reverse
71 for (i = MAXRENDERMODULES - 1;i >= 0;i--)
73 if (rendermodule[i].name == NULL)
75 if (!rendermodule[i].active)
77 Con_DPrintf("Stopping render module \"%s\"\n", rendermodule[i].name);
78 rendermodule[i].active = 0;
79 rendermodule[i].shutdown();
83 void R_Modules_Restart_f(cmd_state_t *cmd)
86 Con_Print("Restarting renderer\n");
87 SCR_BeginLoadingPlaque(false);
92 void R_Modules_NewMap(void)
95 R_SkinFrame_PrepareForPurge();
96 for (i = 0;i < MAXRENDERMODULES;i++)
98 if (rendermodule[i].name == NULL)
100 if (!rendermodule[i].active)
102 rendermodule[i].newmap();
107 void R_Modules_DeviceLost(void)
110 for (i = 0;i < MAXRENDERMODULES;i++)
112 if (rendermodule[i].name == NULL)
114 if (!rendermodule[i].active)
116 if (!rendermodule[i].devicelost)
118 rendermodule[i].devicelost();
123 void R_Modules_DeviceRestored(void)
126 for (i = 0;i < MAXRENDERMODULES;i++)
128 if (rendermodule[i].name == NULL)
130 if (!rendermodule[i].active)
132 if (!rendermodule[i].devicerestored)
134 rendermodule[i].devicerestored();