#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++)
+ Cmd_AddCommand("r_restart", R_Modules_Restart);
+ for (i = 0;i < MAXRENDERMODULES;i++)
rendermodule[i].name = NULL;
}
-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);
}
- 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)\n", 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;
}
}
-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;
}
}
-void R_Restart ()
+void R_Modules_Restart(void)
+{
+ Con_Printf("restarting renderer\n");
+ R_Modules_Shutdown();
+ R_Modules_Start();
+}
+
+void R_Modules_NewMap(void)
{
- R_ShutdownModules();
- R_StartModules();
+ int i;
+ for (i = 0;i < MAXRENDERMODULES;i++)
+ {
+ if (rendermodule[i].name == NULL)
+ continue;
+ if (!rendermodule[i].active)
+ continue;
+ rendermodule[i].newmap();
+ }
}