Exemple #1
0
        static void Sess_WritePrecache_f(CmdArgs args)
        {
            if (args.Count != 2)
            {
                common.Printf("USAGE: writePrecache <execFile>\n"); return;
            }
            var str = args[1];

            str = PathX.DefaultFileExtension(str, ".cfg");
            var f = fileSystem.OpenFileWrite(str, "fs_configpath");

            declManager.WritePrecacheCommands(f);
            renderModelManager.WritePrecacheCommands(f);
            uiManager.WritePrecacheCommands(f);

            fileSystem.CloseFile(f);
        }
Exemple #2
0
        // Loads any of the supported image types into a cannonical 32 bit format.
        // Automatically attempts to load .jpg files if .tga files fail to load.
        // *pic will be null if the load failed.
        // Anything that is going to make this into a texture would use makePowerOf2 = true, but something loading an image as a lookup table of some sort would leave it in identity form.
        // It is important to do this at image load time instead of texture load time for bump maps.
        // Timestamp may be null if the value is going to be ignored
        // If pic is null, the image won't actually be loaded, it will just find the timestamp.
        internal static void R_LoadImage(string cname, ref byte *pic, out int width, out int height, out DateTime timestamp, bool makePowerOf2)
        {
            var name = cname;

            if (pic != byteX.empty)
            {
                pic = null;
            }
            timestamp = default;
            width     = 0;
            height    = 0;

            name = PathX.DefaultFileExtension(name, ".tga");
            if (name.Length < 5)
            {
                return;
            }

            name = name.ToLowerInvariant();
            var ext = PathX.ExtractFileExtension(name);

            if (ext == "tga")
            {
                // try tga first
                LoadTGA(name, ref pic, out width, out height, out timestamp);
                if ((pic == byteX.empty) || (timestamp == default))
                {
                    LoadJPG(PathX.DefaultFileExtension(PathX.StripFileExtension(name), ".jpg"), ref pic, out width, out height, out timestamp);
                }
            }
            else if (ext == "pcx")
            {
                LoadPCX32(name, ref pic, out width, out height, out timestamp);
            }
            else if (ext == "bmp")
            {
                LoadBMP(name, ref pic, out width, out height, out timestamp);
            }
            else if (ext == "jpg")
            {
                LoadJPG(name, ref pic, out width, out height, out timestamp);
            }

            if (width < 1 || height < 1)
            {
                if (pic != byteX.empty)
                {
                    R_StaticFree(pic); pic = null;
                }
            }

            // convert to exact power of 2 sizes
            if (pic != byteX.empty && makePowerOf2)
            {
                int   w, h;
                int   scaled_width, scaled_height;
                byte *resampledBuffer;

                w = width;
                h = height;

                for (scaled_width = 1; scaled_width < w; scaled_width <<= 1)
                {
                    ;
                }
                for (scaled_height = 1; scaled_height < h; scaled_height <<= 1)
                {
                    ;
                }

                if (scaled_width != w || scaled_height != h)
                {
                    if (ImageManager.image_roundDown.Bool && scaled_width > w)
                    {
                        scaled_width >>= 1;
                    }
                    if (ImageManager.image_roundDown.Bool && scaled_height > h)
                    {
                        scaled_height >>= 1;
                    }

                    resampledBuffer = R_ResampleTexture(pic, w, h, scaled_width, scaled_height);
                    R_StaticFree(pic);
                    pic    = resampledBuffer;
                    width  = scaled_width;
                    height = scaled_height;
                }
            }
        }