Esempio n. 1
0
        /*
        ================
        R_DrawSurfaceBlock8_mip3
        ================
        */
        static void R_DrawSurfaceBlock8_mip3()
        {
            int v, i, b, lightstep, lighttemp, light;
            byte pix;
            helper.ByteBuffer psource, prowdest;

            psource = new helper.ByteBuffer(pbasesource);
            prowdest = new helper.ByteBuffer(prowdestbase);

            for (v = 0; v < r_numvblocks; v++)
            {
                // FIXME: make these locals?
                // FIXME: use delta rather than both right and left, like ASM?
                lightleft = (int)r_lightptr[0];
                lightright = (int)r_lightptr[1];
                r_lightptr += r_lightwidth;
                lightleftstep = (int)(r_lightptr[0] - lightleft) >> 1;
                lightrightstep = (int)(r_lightptr[1] - lightright) >> 1;

                for (i = 0; i < 2; i++)
                {
                    lighttemp = lightleft - lightright;
                    lightstep = lighttemp >> 1;

                    light = lightright;

                    for (b = 1; b >= 0; b--)
                    {
                        pix = psource[b];
                        prowdest[b] = screen.vid.colormap
                                [(light & 0xFF00) + pix];
                        light += lightstep;
                    }

                    psource.Add(sourcetstep);
                    lightright += lightrightstep;
                    lightleft += lightleftstep;
                    prowdest.Add(surfrowbytes);
                }

                if (psource >= r_sourcemax)
                    psource.Sub(r_stepback);
            }
        }
Esempio n. 2
0
        /*
        ===============
        R_DrawSurface
        ===============
        */
        public static void R_DrawSurface()
        {
            helper.ByteBuffer   basetptr;
            int				    smax, tmax, twidth;
            int				    u;
            int				    soffset, basetoffset, texwidth;
            int				    horzblockstep;
            helper.ByteBuffer   pcolumndest;
            blockdrawer         pblockdrawer;
            model.texture_t	    mt;

            // calculate the lightings
            R_BuildLightMap ();

            surfrowbytes = r_drawsurf.rowbytes;

            mt = r_drawsurf.texture;

            r_source = new helper.ByteBuffer(mt.pixels, (int)mt.offsets[r_drawsurf.surfmip]);

            // the fractional light values should range from 0 to (VID_GRADES - 1) << 16
            // from a source range of 0 - 255

            texwidth = (int)(mt.width >> r_drawsurf.surfmip);

            blocksize = 16 >> r_drawsurf.surfmip;
            blockdivshift = 4 - r_drawsurf.surfmip;
            blockdivmask = (uint)((1 << blockdivshift) - 1);

            r_lightwidth = (r_drawsurf.surf.extents[0]>>4)+1;

            r_numhblocks = r_drawsurf.surfwidth >> blockdivshift;
            r_numvblocks = r_drawsurf.surfheight >> blockdivshift;

            //==============================

            if (r_pixbytes == 1)
            {
                pblockdrawer = surfmiptable[r_drawsurf.surfmip];
            // TODO: only needs to be set when there is a display settings change
                horzblockstep = blocksize;
            }
            else
            {
                pblockdrawer = R_DrawSurfaceBlock16;
            // TODO: only needs to be set when there is a display settings change
                horzblockstep = blocksize << 1;
            }

            smax = (int)(mt.width >> r_drawsurf.surfmip);
            twidth = texwidth;
            tmax = (int)(mt.height >> r_drawsurf.surfmip);
            sourcetstep = texwidth;
            r_stepback = tmax * twidth;

            r_sourcemax = r_source + (tmax * smax);

            soffset = r_drawsurf.surf.texturemins[0];
            basetoffset = r_drawsurf.surf.texturemins[1];

            // << 16 components are to guarantee positive values for %
            soffset = ((soffset >> r_drawsurf.surfmip) + (smax << 16)) % smax;
            basetptr = new helper.ByteBuffer(r_source, ((((basetoffset >> r_drawsurf.surfmip)
                + (tmax << 16)) % tmax) * twidth));

            pcolumndest = new helper.ByteBuffer(r_drawsurf.surfdat);

            for (u=0 ; u<r_numhblocks; u++)
            {
                r_lightptr = new helper.UIntBuffer(blocklights, u);

                prowdestbase = new helper.ByteBuffer(pcolumndest);

                pbasesource = new helper.ByteBuffer(basetptr, soffset);

                pblockdrawer();

                soffset = soffset + blocksize;
                if (soffset >= smax)
                    soffset = 0;

                pcolumndest.Add(horzblockstep);
            }
        }
Esempio n. 3
0
        /*
        ===============
        PR_LoadProgs
        ===============
        */
        public static void PR_LoadProgs()
        {
            int i;
            Uint8Array buf;
            int kk;
            helper.ByteBuffer bbuf;

            pr_crc = crc.CRC_Init();

            buf = common.COM_LoadHunkFile("progs.dat");
            progs = (dprograms_t)buf;
            if (progs == null)
                sys_linux.Sys_Error("PR_LoadProgs: couldn't load progs.dat");
            console.Con_DPrintf("Programs occupy " + (common.com_filesize / 1024) + "K.\n");

            for (i = 0; i < common.com_filesize; i++)
                pr_crc = crc.CRC_ProcessByte(pr_crc, (byte)buf[i]);

            if (progs.version != PROG_VERSION)
                sys_linux.Sys_Error("progs.dat has wrong version number (" + progs.version + " should be " + PROG_VERSION + ")");
            if (progs.crc != PROGHEADER_CRC)
                sys_linux.Sys_Error("progs.dat system vars have been modified, progdefs.h is out of date");

            bbuf = new helper.ByteBuffer(buf);
            //pr_functions = (dfunction_t*)((byte*)progs + progs.ofs_functions);
            bbuf.ofs = progs.ofs_functions;
            pr_functions = new dfunction_t[progs.numfunctions];
            for (kk = 0; kk < progs.numfunctions; kk++)
            {
                pr_functions[kk] = (dfunction_t)bbuf;
                bbuf.ofs += sizeof_dfunction_t;
            }
            //pr_strings = (char*)progs + progs.ofs_strings;
            pr_strings = buf;
            //pr_globaldefs = (ddef_t*)((byte*)progs + progs.ofs_globaldefs);
            bbuf.ofs = progs.ofs_globaldefs;
            pr_globaldefs = new ddef_t[progs.numglobaldefs];
            for (kk = 0; kk < progs.numglobaldefs; kk++)
            {
                pr_globaldefs[kk] = (ddef_t)bbuf;
                bbuf.ofs += sizeof_ddef_t;
            }
            //pr_fielddefs = (ddef_t*)((byte*)progs + progs.ofs_fielddefs);
            bbuf.ofs = progs.ofs_fielddefs;
            pr_fielddefs = new ddef_t[progs.numfielddefs];
            for (kk = 0; kk < progs.numfielddefs; kk++)
            {
                pr_fielddefs[kk] = (ddef_t)bbuf;
                bbuf.ofs += sizeof_ddef_t;
            }
            //pr_statements = (dstatement_t*)((byte*)progs + progs.ofs_statements);
            bbuf.ofs = progs.ofs_statements;
            pr_statements = new dstatement_t[progs.numstatements];
            for (kk = 0; kk < progs.numstatements; kk++)
            {
                pr_statements[kk] = (dstatement_t)bbuf;
                bbuf.ofs += sizeof_dstatement_t;
            }

            //pr_global_struct = (globalvars_t*)((byte*)progs + progs.ofs_globals);
            bbuf.ofs = progs.ofs_globals;
            pr_global_struct = new globalvars_t[progs.numglobals * 4 / 368];
            for (kk = 0; kk < progs.numglobals * 4 / 368; kk++)
            {
                pr_global_struct[kk] = (globalvars_t)bbuf;
                bbuf.ofs += sizeof_globalvars_t;
            }

            pr_edict_size = progs.entityfields * 4 + sizeof_edict_t - sizeof_entvars_t;
        }