X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_modules.c;h=df260db6780f1de6006ebd44c4877e12a9948c34;hp=1c30a4caf638fcb347205fcc74c9b9d1eed244e7;hb=3a466b8a6397138a30c965e4a7f75e181d6f0181;hpb=855932aeb5707c5efb2858c3e51b913d8203ebbe diff --git a/r_modules.c b/r_modules.c index 1c30a4ca..df260db6 100644 --- a/r_modules.c +++ b/r_modules.c @@ -1,60 +1,69 @@ #include "quakedef.h" +#define MAXRENDERMODULES 64 + typedef struct rendermodule_s { int active; // set by start, cleared by shutdown char *name; - void(*start)(); - void(*shutdown)(); + void(*start)(void); + void(*shutdown)(void); + void(*newmap)(void); } rendermodule_t; -rendermodule_t rendermodule[64]; +rendermodule_t rendermodule[MAXRENDERMODULES]; -void R_Modules_Init() +void R_Modules_Init(void) { - int i; - for (i = 0;i < 64;i++) - rendermodule[i].name = NULL; + Cmd_AddCommand("r_restart", R_Modules_Restart, "restarts renderer"); } -void R_RegisterModule(char *name, void(*start)(), void(*shutdown)()) +void R_RegisterModule(char *name, void(*start)(void), void(*shutdown)(void), void(*newmap)(void)) { int i; - for (i = 0;i < 64;i++) + for (i = 0;i < MAXRENDERMODULES;i++) { 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 >= 64) - Sys_Error("R_RegisterModule: ran out of renderer module slots (64)\n"); + if (i >= 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; } -void R_StartModules () +void R_Modules_Start(void) { int i; - for (i = 0;i < 64;i++) + for (i = 0;i < MAXRENDERMODULES;i++) { 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(); } } -void R_ShutdownModules () +void R_Modules_Shutdown(void) { int i; - for (i = 0;i < 64;i++) + // shutdown in reverse + for (i = MAXRENDERMODULES - 1;i >= 0;i--) { if (rendermodule[i].name == NULL) continue; @@ -65,8 +74,24 @@ void R_ShutdownModules () } } -void R_Restart () +void R_Modules_Restart(void) { - R_ShutdownModules(); - R_StartModules(); + Host_StartVideo(); + Con_Print("restarting renderer\n"); + R_Modules_Shutdown(); + R_Modules_Start(); +} + +void R_Modules_NewMap(void) +{ + int i; + for (i = 0;i < MAXRENDERMODULES;i++) + { + if (rendermodule[i].name == NULL) + continue; + if (!rendermodule[i].active) + continue; + rendermodule[i].newmap(); + } } +