]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fixed r_restart/vid_restart bugs with skybox (now reloads skybox as it should) and...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 5 Nov 2003 08:00:34 +0000 (08:00 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 5 Nov 2003 08:00:34 +0000 (08:00 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3626 d7cf8633-e32d-0410-b094-e92efae38249

r_sky.c

diff --git a/r_sky.c b/r_sky.c
index c216ed2ac2be66c539c8f22b396bfd4876213eec..7681a8dc26a42c7455584c0e202b86406d976c21 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -41,48 +41,63 @@ void R_SkyStartFrame(void)
 R_SetSkyBox
 ==================
 */
-int R_SetSkyBox(const char *sky)
+void R_UnloadSkyBox(void)
 {
        int i;
-       char name[1024];
-       qbyte *image_rgba;
-
-       if (strcmp(sky, skyname) == 0) // no change
-               return true;
-
-       skyboxside[0] = skyboxside[1] = skyboxside[2] = skyboxside[3] = skyboxside[4] = skyboxside[5] = NULL;
-       skyavailable_box = false;
-       skyname[0] = 0;
-
-       if (!sky[0])
-               return true;
-
-       if (strlen(sky) > 1000)
+       for (i = 0;i < 6;i++)
        {
-               Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(sky));
-               return false;
+               if (skyboxside[i])
+                       R_FreeTexture(skyboxside[i]);
+               skyboxside[i] = NULL;;
        }
+}
 
+void R_LoadSkyBox(void)
+{
+       int i;
+       char name[1024];
+       qbyte *image_rgba;
+       R_UnloadSkyBox();
+       if (!skyname[0])
+               return;
        for (i = 0;i < 6;i++)
        {
-               sprintf (name, "env/%s%s", sky, suf[i]);
-               if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
+               if (snprintf(name, sizeof(name), "env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0)))
                {
-                       sprintf (name, "gfx/env/%s%s", sky, suf[i]);
-                       if (!(image_rgba = loadimagepixels(name, false, 0, 0)))
+                       if (snprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0)))
                        {
-                               Con_Printf ("Couldn't load env/%s%s or gfx/env/%s%s\n", sky, suf[i], sky, suf[i]);
+                               Con_Printf ("Couldn't load env/%s%s or gfx/env/%s%s\n", skyname, suf[i], skyname, suf[i]);
                                continue;
                        }
                }
                skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_CLAMP | TEXF_PRECACHE, NULL);
                Mem_Free(image_rgba);
        }
+}
+
+int R_SetSkyBox(const char *sky)
+{
+       if (strcmp(sky, skyname) == 0) // no change
+               return true;
+
+       if (strlen(sky) > 1000)
+       {
+               Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(sky));
+               return false;
+       }
+
+       skyavailable_box = false;
+       strcpy(skyname, sky);
+
+       R_UnloadSkyBox();
+       R_LoadSkyBox();
+
+       if (!skyname[0])
+               return true;
 
        if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
        {
                skyavailable_box = true;
-               strcpy(skyname, sky);
                return true;
        }
        return false;
@@ -480,10 +495,12 @@ static void r_sky_start(void)
        skytexturepool = R_AllocTexturePool();
        solidskytexture = NULL;
        alphaskytexture = NULL;
+       R_LoadSkyBox();
 }
 
 static void r_sky_shutdown(void)
 {
+       R_UnloadSkyBox();
        R_FreeTexturePool(&skytexturepool);
        solidskytexture = NULL;
        alphaskytexture = NULL;