Exemplo n.º 1
0
        internal static void Render(bool allowextras = true)
        {
            screen.Clear();
            _fbcache.Clear();

            camDir = game.game.GetLocalPlayer().dir;
            float fov = player.cvarFov.Valuef() / 100;

            camPlane.x = camDir.y * (fov * 1.33f);
            camPlane.y = -camDir.x * (fov * 1.33f);

            sb           = cache.GetTexture(world.skybox);
            centersprite = new screensprite {
                dist = -1
            };

            DrawWorld((int)DispHeight);
            world.RefreshSprites();
            DrawSprites((int)engine.SCREEN_HEIGHT);
            PostProcess();

            var velocity = new vector(0, 0);

            if (!ReferenceEquals(null, _plast))
            {
                velocity = world.Player.pos - _plast;
            }
            world.Player.weapon.Draw(velocity);

            _plast = world.Player.pos;
        }
Exemplo n.º 2
0
        private static void DrawSprites(int h)
        {
            var nsprites    = world.sprites.Length;
            var spriteorder = SortSprites();
            int w           = (int)engine.SCREEN_WIDTH;

            for (var i = 0; i < nsprites; i++)
            {
                var pos = new vector((float)spriteorder[i].x - world.Player.pos.x,
                                     (float)spriteorder[i].y - world.Player.pos.y);

                // transform
                var invDet    = (float)1.0 / (camPlane.x * camDir.y - camDir.x * camPlane.y);
                var transform = new vector(invDet * (camDir.y * pos.x - camDir.x * pos.y),
                                           invDet * (-camPlane.y * pos.x + camPlane.x * pos.y));

                if (transform.x == 0)
                {
                    continue;
                }

                var s = world.sprites[spriteorder[i].index];
                if (!s.visible)
                {
                    return;
                }

                var screenx = (int)(w / 2 * (1 + transform.x / transform.y));

                var scaleWidth  = Math.Abs((int)(h / transform.y / (16 / s.sprwidth)));
                var scaleHeight = Math.Abs((int)(h / transform.y));

                var ymin = (-scaleHeight / 2 + h / 2).Clamp(0, h);
                var ymax = (scaleHeight / 2 + h / 2).Clamp(0, h);

                var xmin = (-scaleWidth / 2 + screenx).Clamp(0, w);
                var xmax = (scaleWidth / 2 + screenx).Clamp(0, w);

                // draw
                for (var x = xmin; x < xmax; x++)
                {
                    if (!(x >= BORDER && x < w - BORDER))
                    {
                        continue;
                    }

                    var txs    = s.sprx * s.sprwidth;
                    var texelx = 256 * (x - (-scaleWidth / 2 + screenx)) * (int)s.sprwidth / scaleWidth / 256;

                    var vis = transform.y <= 10 - _zBuffer[x, screen.height / 2];
                    if (transform.y > 0 && x > 0 && x < w && vis)
                    {
                        if (x == screen.width / 2 &&
                            (centersprite.dist == -1 || centersprite.dist > spriteorder[i].dist) && !s.fetchignore)
                        {
                            centersprite = new screensprite
                            {
                                index = spriteorder[i].index,
                                dist  = (float)spriteorder[i].dist
                            };
                        }

                        for (var y = ymin; y < ymax; y++)
                        {
                            if (!(y >= BORDER && y < h - HUDSIZE))
                            {
                                continue;
                            }

                            var d      = y * 2 - h + scaleHeight;
                            var texely = d * (int)s.sprheight / scaleHeight / 2;
                            texely = texely.Clamp(0, (int)s.sprheight);

                            var c = s.Tex.GetPixel(txs + (uint)texelx, (uint)texely);
                            if (c != magicpink)
                            {
                                _zBuffer[x, y] = 10 - (float)spriteorder[i].dist;

                                var world = new vector(s.pos.x, s.pos.y) * TEXSIZE;
                                var ic    = Additive(c, level.lightmap[(int)world.x, (int)world.y]);

                                var v = new vector(x, y);
                                if (_fbcache.ContainsKey(v))
                                {
                                    _fbcache.Remove(v);
                                }
                                screen.SetPixel((uint)x, (uint)y, ic);
                            }
                        }
                    }
                }
            }
        }