Beispiel #1
0
    public void RenderMapObjects(IGameViewport viewport, int tileX1, int tileX2, int tileY1, int tileY2)
    {
        using var perfGroup = mDevice.CreatePerfGroup("Map Objects");

        mTotalLastFrame    = 0;
        mRenderedLastFrame = 0;

        using var iterator = new SectorIterator(tileX1, tileX2, tileY1, tileY2);
        foreach (var obj in iterator.EnumerateObjects())
        {
            RenderObject(viewport, obj, true);
        }
    }
Beispiel #2
0
    public void Render(IGameViewport viewport, TileRect tileRect)
    {
        _device.SetMaterial(_material.Resource);
        var viewProj = viewport.Camera.GetViewProj();

        _device.SetVertexShaderConstants(0, ref viewProj);

        using var sectorIt = new SectorIterator(tileRect);
        foreach (var sector in sectorIt.EnumerateSectors())
        {
            if (!sector.IsValid)
            {
                continue;
            }

            if (!_sectorDebugState.TryGetValue(sector.Loc, out var renderingState))
            {
                renderingState = BuildSubTileMesh(_device, _material.Resource.VertexShader, sector.Sector);
                _sectorDebugState.Add(sector.Loc, renderingState);
            }

            renderingState.Render(_device);
        }
    }
Beispiel #3
0
    public List <Light3d> FindLights(LocAndOffsets atLocation, float radius)
    {
        List <Light3d> lights = new List <Light3d>();

        if (GameSystems.Light.IsGlobalLightEnabled)
        {
            Light3d light       = new Light3d();
            var     legacyLight = GameSystems.Light.GlobalLight;
            light.type  = (Light3dType)legacyLight.type;
            light.color = legacyLight.Color;
            light.dir.X = legacyLight.dir.X;
            light.dir.Y = legacyLight.dir.Y;
            light.dir.Z = legacyLight.dir.Z;
            light.pos.X = legacyLight.pos.X;
            light.pos.Y = legacyLight.pos.Y;
            light.pos.Z = legacyLight.pos.Z;
            light.range = legacyLight.range;
            light.phi   = legacyLight.phi;
            lights.Add(light);
        }

        if (radius == 0)
        {
            return(lights);
        }

        // Build a box that has twice the radius convert to tiles as it's width/height
        // For some reason, ToEE will add one more INCH_PER_TILE here, which translates to
        // roughly 28 tiles more search radius than is needed
        var boxDimensions = (int)(radius / locXY.INCH_PER_TILE + locXY.INCH_PER_TILE);
        var tileX1        = atLocation.location.locx - 1 - boxDimensions;
        var tileX2        = atLocation.location.locx + 1 + boxDimensions;
        var tileY1        = atLocation.location.locy - 1 - boxDimensions;
        var tileY2        = atLocation.location.locy + 1 + boxDimensions;

        using var sectorIterator = new SectorIterator(tileX1, tileX2, tileY1, tileY2);

        var atPos = atLocation.ToInches2D();

        while (sectorIterator.HasNext)
        {
            using var sector = sectorIterator.Next();

            foreach (ref var light in sector.Lights)
            {
                int         type;
                LinearColor color;
                Vector3     direction;
                float       range, phi;
                var         lightPos = light.position.ToInches2D();

                if ((light.flags & 0x40) != 0)
                {
                    if (GameSystems.Light.IsNight)
                    {
                        type      = light.light2.type;
                        color     = light.light2.color;
                        direction = light.light2.direction;
                        range     = light.range; // Notice how it's using light 1's range
                        phi       = light.light2.phi;

                        /*
                         * Kill the daytime particle system if it's night and the
                         * daytime particle system is still alive.
                         */
                        if (light.partSys.handle != null)
                        {
                            GameSystems.ParticleSys.Remove(light.partSys.handle);
                            light.partSys.handle = null;
                        }

                        /*
                         * If the nighttime particle system has not yet been started,
                         * do it here.
                         */
                        ref var nightPartSys = ref light.light2.partSys;
                        if (nightPartSys.handle == null && nightPartSys.hashCode != 0)
                        {
                            var centerOfTile = light.position.ToInches3D(light.offsetZ);
                            nightPartSys.handle = GameSystems.ParticleSys.CreateAt(
                                nightPartSys.hashCode, centerOfTile
                                );
                        }
                    }
                    else
                    {
                        type      = light.type;
                        color     = light.color;
                        direction = light.direction;
                        range     = light.range;
                        phi       = light.phi;

                        // This is just the inverse of what we're doing at night (see above)
                        ref var nightPartSys = ref light.light2.partSys;
                        if (nightPartSys.handle != null)
                        {
                            GameSystems.ParticleSys.Remove(nightPartSys.handle);
                            nightPartSys.handle = null;
                        }

                        ref var dayPartSys = ref light.partSys;
                        if (dayPartSys.handle == null && dayPartSys.hashCode != 0)
                        {
                            var centerOfTile = light.position.ToInches3D(light.offsetZ);
                            dayPartSys.handle = GameSystems.ParticleSys.CreateAt(
                                dayPartSys.hashCode, centerOfTile
                                );
                        }
                    }
                }