X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_modules.c;h=904977146ece0e69771e7ebe2cb1a1838c4b5650;hp=a4e046ebadc7826f7cc4ebf46fee424215e36dbf;hb=73f27d62983b6af1cb9a6971d0a4cb6275b91a07;hpb=ea7c24e1fb41f3b1df984ac0eed6881c9fde16f5 diff --git a/r_modules.c b/r_modules.c index a4e046eb..90497714 100644 --- a/r_modules.c +++ b/r_modules.c @@ -1,15 +1,17 @@ #include "quakedef.h" -#define MAXRENDERMODULES 64 +#define MAXRENDERMODULES 20 typedef struct rendermodule_s { int active; // set by start, cleared by shutdown - char *name; + const char *name; void(*start)(void); void(*shutdown)(void); void(*newmap)(void); + void(*devicelost)(void); + void(*devicerestored)(void); } rendermodule_t; @@ -17,13 +19,10 @@ rendermodule_t rendermodule[MAXRENDERMODULES]; void R_Modules_Init(void) { - int i; - Cmd_AddCommand("r_restart", R_Modules_Restart); - for (i = 0;i < MAXRENDERMODULES;i++) - rendermodule[i].name = NULL; + Cmd_AddCommand(CF_CLIENT, "r_restart", R_Modules_Restart_f, "restarts renderer"); } -void R_RegisterModule(char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void)) +void R_RegisterModule(const char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void), void(*devicelost)(void), void(*devicerestored)(void)) { int i; for (i = 0;i < MAXRENDERMODULES;i++) @@ -31,15 +30,20 @@ void R_RegisterModule(char *name, void(*start)(void), void(*shutdown)(void), voi if (rendermodule[i].name == NULL) break; if (!strcmp(name, rendermodule[i].name)) - Sys_Error("R_RegisterModule: module \"%s\" registered twice\n", name); + { + Con_Printf("R_RegisterModule: module \"%s\" registered twice\n", name); + return; + } } if (i >= MAXRENDERMODULES) - Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)\n", MAXRENDERMODULES); + Sys_Error("R_RegisterModule: ran out of renderer module slots (%i)", MAXRENDERMODULES); rendermodule[i].active = 0; rendermodule[i].name = name; rendermodule[i].start = start; rendermodule[i].shutdown = shutdown; rendermodule[i].newmap = newmap; + rendermodule[i].devicelost = devicelost; + rendermodule[i].devicerestored = devicerestored; } void R_Modules_Start(void) @@ -50,7 +54,10 @@ void R_Modules_Start(void) if (rendermodule[i].name == NULL) continue; if (rendermodule[i].active) - Sys_Error("R_StartModules: module \"%s\" already active\n", rendermodule[i].name); + { + Con_Printf ("R_StartModules: module \"%s\" already active\n", rendermodule[i].name); + continue; + } rendermodule[i].active = 1; rendermodule[i].start(); } @@ -71,9 +78,10 @@ void R_Modules_Shutdown(void) } } -void R_Modules_Restart(void) +void R_Modules_Restart_f(cmd_state_t *cmd) { - Con_Printf("restarting renderer\n"); + CL_StartVideo(); + Con_Print("restarting renderer\n"); R_Modules_Shutdown(); R_Modules_Start(); } @@ -81,6 +89,7 @@ void R_Modules_Restart(void) void R_Modules_NewMap(void) { int i; + R_SkinFrame_PrepareForPurge(); for (i = 0;i < MAXRENDERMODULES;i++) { if (rendermodule[i].name == NULL) @@ -89,5 +98,37 @@ void R_Modules_NewMap(void) continue; rendermodule[i].newmap(); } + R_SkinFrame_Purge(); +} + +void R_Modules_DeviceLost(void) +{ + int i; + for (i = 0;i < MAXRENDERMODULES;i++) + { + if (rendermodule[i].name == NULL) + continue; + if (!rendermodule[i].active) + continue; + if (!rendermodule[i].devicelost) + continue; + rendermodule[i].devicelost(); + } +} + + +void R_Modules_DeviceRestored(void) +{ + int i; + for (i = 0;i < MAXRENDERMODULES;i++) + { + if (rendermodule[i].name == NULL) + continue; + if (!rendermodule[i].active) + continue; + if (!rendermodule[i].devicerestored) + continue; + rendermodule[i].devicerestored(); + } }