예제 #1
0
        private void ОбновитьСостояниеОсвещенностиКарты(LiveMap _liveMap)
        {
#if DEBUG
            using (new Profiler())
#endif
            {
                using (new FboWrapper.DrawHelper(m_fboBlit))
                {
                    GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
                    GL.ReadPixels(0, 0, MAP_SIZE, MAP_SIZE, PixelFormat.Rgba, PixelType.Float, m_lightMap);

                    //FboWrapper.DrawHelper.Screenshot("e:\\1\\scr.png");

                    var dPoint       = _liveMap.GetData(); //.GetDPoint();
                    var viewportSize = _liveMap.VieportSize;

                    var layer        = World.TheWorld.Avatar.GeoInfo.Layer;
                    var fogLightness = layer.FogLightness;
                    for (var i = 0; i < MAP_SIZE; i++)
                    {
                        for (var j = 0; j < MAP_SIZE; j++)
                        {
                            var lc = m_shadowCasters[j, i].LiveMapCell;
                            lc.Lighted = m_lightMap[i, j];
                            lc.UpdateVisibility(fogLightness);
                        }
                    }
                }
            }
        }
예제 #2
0
        public void Recalc(LiveMap _liveMap)
        {
            m_lightsCount = 0;
            m_edgesCount  = 0;

            var avatarXY = BaseMapBlock.GetInBlockCoords(World.TheWorld.Avatar.GeoInfo.LiveCoords) + new Point(32, 32);

            m_lights[m_lightsCount++] = new Light
            {
                LightSource = new AvatarSight(),
                Point       = new PointF(avatarXY.X, avatarXY.Y),
                LiveMapCell = World.TheWorld.Avatar[0, 0]
            };

#if DEBUG
            using (new Profiler("LosManagerEx.Recalc"))
#endif
            {
                ПодготовкаКарты(_liveMap, avatarXY);
                СформироватьМассивГраней();
                while (m_fboBlit.CountOfBuffers < (m_lightsCount + 2))
                {
                    m_fboBlit.AddTextureBuffer();
                }
                Отрисовка(avatarXY);
                ОбновитьСостояниеОсвещенностиКарты(_liveMap);
            }

            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Texture2D);
        }
예제 #3
0
 public void LightCells(LiveMap _liveMap, Point _point)
 {
     if (!m_lightManagers.ContainsKey(Radius))
     {
         m_lightManagers.Add(Radius, new LosManager(Radius));
     }
     m_lightManagers[Radius].LightCells(_liveMap, _point, Color);
 }
예제 #4
0
        private void Redraw()
        {
            var halfScreen        = new Point(ContentRct.Width, ContentRct.Height) / 2;
            var avatarScreenPoint = halfScreen + ContentRct.LeftTop;

            TileHelper.DrawHelper.ClearTiles(Rct, BackgroundColor);

            var worldLayer = World.TheWorld.Avatar.GeoInfo.Layer;

            var width  = ContentRct.Width;
            var height = ContentRct.Height;

            for (var x = 0; x < width; ++x)
            {
                for (var y = 0; y < height; ++y)
                {
                    var xy = new Point(x, y);

                    var liveCellCoords = LiveMap.WrapCellCoords(xy + World.TheWorld.DPoint);
                    var liveCell       = World.TheWorld.LiveMap.Cells[liveCellCoords.X, liveCellCoords.Y];
                    var screenPoint    = xy + ContentRct.LeftTop;
                    var visibilityA    = 1f;                 // liveCell.Visibility.A;
                    var finalLighted   = liveCell.FinalLighted;

                    if (liveCell.IsVisibleNow)
                    {
                        var eTerrains   = liveCell.Terrain;
                        var terrainTile = eTerrains.GetTile((int)Math.Abs((liveCell.LiveCoords.GetHashCode() * liveCell.Rnd)));
                        var tcolor      = terrainTile.Color.Multiply(finalLighted).Clamp().Lerp(terrainTile.Color.Multiply(0.7f), 1f - visibilityA);
                        terrainTile.Draw(screenPoint, tcolor);

                        foreach (var tileInfoProvider in liveCell.TileInfoProviders)
                        {
                            var tile  = tileInfoProvider.Tileset.GetTile(tileInfoProvider.TileIndex);
                            var color = tile.Color.LerpColorsOnly(tileInfoProvider.LerpColor, tileInfoProvider.LerpColor.A).Multiply(finalLighted).Clamp().UpdateAlfa(visibilityA);
                            tile.Draw(screenPoint, color, tileInfoProvider.Direction, tileInfoProvider.IsCorpse);
                        }
                    }
                    else if (liveCell.IsSeenBefore)
                    {
                        var fogColorMultiplier = worldLayer.GetFogColorMultiplier(liveCell);

                        var eTerrains   = liveCell.Terrain;
                        var terrainTile = eTerrains.GetTile((int)Math.Abs((liveCell.LiveCoords.GetHashCode() * liveCell.Rnd)));

                        var tcolor = terrainTile.Color.Multiply(fogColorMultiplier).ToGrayScale();
                        terrainTile.Draw(screenPoint, tcolor);
                        foreach (var tileInfoProvider in liveCell.FoggedTileInfoProviders)
                        {
                            var tile = tileInfoProvider.Tileset.GetTile(tileInfoProvider.TileIndex);
                            tile.Draw(screenPoint, tile.Color.LerpColorsOnly(tileInfoProvider.LerpColor, tileInfoProvider.LerpColor.A).ToGrayScale(), tileInfoProvider.Direction, tileInfoProvider.IsCorpse);
                        }
                        DrawHelper.FogTile(screenPoint);
                    }
                }
            }
            World.TheWorld.Avatar.Tileset.GetTile(World.TheWorld.Avatar.TileIndex).Draw(avatarScreenPoint, FColor.White);
        }
예제 #5
0
        public void SetVisibleCelss(LiveMap _liveMap, Point _dPoint, FColor _startFrom)
        {
            unchecked
            {
                var cvisibles = new FColor[m_inOrder.Length];
                var visibles  = new float[m_inOrder.Length];

                cvisibles[0] = _startFrom;
                visibles[0]  = 1;

                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var visibilityCoeff = visibles[index];

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    var losCell = m_inOrder[index];
                    var myPnt   = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell   = _liveMap.Cells[myPnt.X, myPnt.Y];
                    var transColor = index == 0 ? FColor.White : liveCell.TransparentColor;

                    visibilityCoeff = transColor.A * visibilityCoeff;
                    var childsColor = cvisibles[index].Multiply(transColor);

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    foreach (var pair in losCell.CellIndexes)
                    {
                        visibles[pair.Key] += pair.Value * visibilityCoeff;
                        cvisibles[pair.Key] = cvisibles[pair.Key].ScreenColorsOnly(childsColor);
                    }
                }
                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var visibilityCoeff = visibles[index];
                    var color           = cvisibles[index];

                    if (visibilityCoeff < VISIBILITY_THRESHOLD)
                    {
                        continue;
                    }

                    var losCell = m_inOrder[index];
                    var myPnt   = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell = _liveMap.Cells[myPnt.X, myPnt.Y];
                    liveCell.Visibility = new FColor(Math.Min(1f, visibilityCoeff), color);
                }
            }
        }
예제 #6
0
        private void ПодготовкаКарты(LiveMap _liveMap, Point _avatarXY)
        {
#if DEBUG
            using (new Profiler())
#endif
            {
                var liveBlocks = _liveMap.GetLightedLiveBlocks();
                var point      = new Point(1, 1);

                for (var i = 0; i < 9; i++)
                {
                    var dlt        = (liveBlocks[i, 0] + point) * Constants.MAP_BLOCK_SIZE;
                    var livBlockXY = liveBlocks[i, 1];
                    for (var index = 0; index < m_allBlockPoints.Length; index++)
                    {
                        var blockPoint  = m_allBlockPoints[index];
                        var liveCellXY  = livBlockXY * Constants.MAP_BLOCK_SIZE + blockPoint;
                        var liveMapCell = _liveMap.Cells[liveCellXY.X, liveCellXY.Y];

                        m_shadowCasters[dlt.X + blockPoint.X, dlt.Y + blockPoint.Y].LiveMapCell = liveMapCell;
                        m_shadowCasters[dlt.X + blockPoint.X, dlt.Y + blockPoint.Y].Opacity     = liveMapCell.CalcOpacity();

                        #region источники света от существ

                        var creature = liveMapCell.Creature;
                        if (creature == null || creature.Light == null || _avatarXY.GetDistTill(liveCellXY) > (MAX_VISIBLE_RADIUS * 2))
                        {
                            continue;
                        }

                        var tempPoint = dlt + blockPoint;
                        m_lights[m_lightsCount].Point         = new PointF(tempPoint.X, tempPoint.Y);
                        m_lights[m_lightsCount].LiveMapCell   = liveMapCell;
                        m_lights[m_lightsCount++].LightSource = creature.Light;

                        #endregion
                    }

                    #region остальные источники света

                    foreach (var info in _liveMap.Blocks[livBlockXY.X, livBlockXY.Y].MapBlock.LightSources)
                    {
                        var tempPoint = dlt + info.Point;
                        if (_avatarXY.GetDistTill(tempPoint) > (MAX_VISIBLE_RADIUS * 2))
                        {
                            continue;
                        }
                        m_lights[m_lightsCount].Point         = new PointF(tempPoint.X, tempPoint.Y);
                        m_lights[m_lightsCount++].LightSource = info.Source;
                    }

                    #endregion
                }
            }
        }
예제 #7
0
        public World()
        {
            Rnd = new Random(Constants.WORLD_SEED);

            BattleProcessor = new BattleProcessor();
            CreatureManager = new CreatureManager();

            LiveMap = new LiveMap();

            if (Constants.GAME_MODE)
            {
                if (m_startingLayerType == null)
                {
                    throw new ApplicationException("Нужно задать тип стартового уровня");
                }
                m_layers.Add(CurrentLayer = (WorldLayer)Activator.CreateInstance(m_startingLayerType));
            }
            WorldTick = 0;
        }
예제 #8
0
        /// <summary>
        /// Regenerate the internal map for the locale; try not to do this often
        /// </summary>
        public void RemapInterior()
        {
            string[,,] returnMap = Cartographer.GenerateMapFromRoom(CentralRoom(), new HashSet <IRoom>(Rooms()), true);

            Interior = new LiveMap(returnMap, false);
        }
예제 #9
0
 public void LightCells(LiveMap _liveMap, Point _point)
 {
     m_lightSource.LightCells(_liveMap, _point);
 }
예제 #10
0
        public void LightCells(LiveMap _liveMap, Point _dPoint, FColor _fColor)
        {
            unchecked
            {
                var cvisibles       = new FColor[m_inOrder.Length];
                var power           = new float[m_inOrder.Length];
                var childVisibility = new float[m_inOrder.Length];

                power[0]           = _fColor.A;
                childVisibility[0] = 1;

                cvisibles[0] = new FColor(1f, _fColor);
                for (var index = 1; index < m_inOrder.Length; index++)
                {
                    cvisibles[index] = FColor.Empty;
                }
                for (var index = 0; index < m_inOrder.Length; index++)
                {
                    var losCell = m_inOrder[index];

                    var powerCoeff = power[index];

                    if (powerCoeff < LIGHT_THRESHOLD)
                    {
                        continue;
                    }

                    var myPnt = LiveMap.WrapCellCoords(losCell.Point + _dPoint);

                    var liveCell = _liveMap.Cells[myPnt.X, myPnt.Y];

                    var color = cvisibles[index].NormalColorOnly;

                    var transColor = index == 0 ? FColor.White : liveCell.TransparentColor;
                    if (childVisibility[index] > 0)
                    {
                        liveCell.Lighted = liveCell.Lighted.Screen(color.Multiply(powerCoeff));
                        powerCoeff      *= transColor.A;
                        if (powerCoeff < LIGHT_THRESHOLD)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        powerCoeff *= transColor.A;
                        if (powerCoeff < LIGHT_THRESHOLD)
                        {
                            continue;
                        }
                        liveCell.Lighted = liveCell.Lighted.Screen(color.Multiply(powerCoeff));
                    }

                    var childsColor = color.Multiply(transColor);

                    foreach (var pair in losCell.CellIndexes)
                    {
                        var i = pair.Key;

                        power[i] += pair.Value * powerCoeff;
                        cvisibles[i].AddColorOnly(childsColor);
                        childVisibility[i] = pair.Value * liveCell.Visibility.A;
                    }
                }
            }
        }
예제 #11
0
 public void LightCells(LiveMap _liveMap, Point _point)
 {
     throw new NotImplementedException();
 }