]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_modules.c
Fix engine not starting on Windows if linked against SDL > 2.0.5
[xonotic/darkplaces.git] / r_modules.c
index 69086f6771d81d795f973b1ff9ecc3ee1b4c90eb..818637e8467d67100f0e75e6291d403403a40c8e 100644 (file)
@@ -1,28 +1,28 @@
 
 #include "quakedef.h"
 
-#define MAXRENDERMODULES 64
+#define MAXRENDERMODULES 20
 
 typedef struct rendermodule_s
 {
        int active; // set by start, cleared by shutdown
-       char *name;
-       void(*start)();
-       void(*shutdown)();
-       void(*newmap)();
+       const char *name;
+       void(*start)(void);
+       void(*shutdown)(void);
+       void(*newmap)(void);
+       void(*devicelost)(void);
+       void(*devicerestored)(void);
 }
 rendermodule_t;
 
 rendermodule_t rendermodule[MAXRENDERMODULES];
 
-void R_Modules_Init()
+void R_Modules_Init(void)
 {
-       int i;
-       for (i = 0;i < MAXRENDERMODULES;i++)
-               rendermodule[i].name = NULL;
+       Cmd_AddCommand("r_restart", R_Modules_Restart, "restarts renderer");
 }
 
-void R_RegisterModule(char *name, void(*start)(), void(*shutdown)(), void(*newmap)())
+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++)
@@ -30,18 +30,23 @@ void R_RegisterModule(char *name, void(*start)(), void(*shutdown)(), void(*newma
                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 R_Modules_Start(void)
 {
        int i;
        for (i = 0;i < MAXRENDERMODULES;i++)
@@ -49,16 +54,20 @@ void R_Modules_Start ()
                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_Modules_Shutdown ()
+void R_Modules_Shutdown(void)
 {
        int i;
-       for (i = 0;i < MAXRENDERMODULES;i++)
+       // shutdown in reverse
+       for (i = MAXRENDERMODULES - 1;i >= 0;i--)
        {
                if (rendermodule[i].name == NULL)
                        continue;
@@ -69,15 +78,18 @@ void R_Modules_Shutdown ()
        }
 }
 
-void R_Modules_Restart ()
+void R_Modules_Restart(void)
 {
+       Host_StartVideo();
+       Con_Print("restarting renderer\n");
        R_Modules_Shutdown();
        R_Modules_Start();
 }
 
-void R_Modules_NewMap ()
+void R_Modules_NewMap(void)
 {
        int i;
+       R_SkinFrame_PrepareForPurge();
        for (i = 0;i < MAXRENDERMODULES;i++)
        {
                if (rendermodule[i].name == NULL)
@@ -86,4 +98,37 @@ void R_Modules_NewMap ()
                        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();
+       }
+}
+