Exemplo n.º 1
0
        public void DamageChunk(Coordinates2D coords)
        {
            var x = coords.X / Width - (coords.X < 0 ? 1 : 0);
            var z = coords.Z / Depth - (coords.Z < 0 ? 1 : 0);

            DirtyChunks.Add(new Coordinates2D(coords.X - x * 32, coords.Z - z * 32));
        }
Exemplo n.º 2
0
 /// <summary>
 ///  Sets the chunk at the specified local position to the given value.
 /// </summary>
 public void SetChunk(Coordinates2D position, IChunk chunk)
 {
     Chunks[position] = chunk;
     chunk.IsModified = true;
     DirtyChunks.Add(position);
     chunk.ParentRegion = this;
 }
Exemplo n.º 3
0
        public void DamageChunk(Coordinates2D coords)
        {
            int x = coords.X / Region.Width - ((coords.X < 0) ? 1 : 0);
            int z = coords.Z / Region.Depth - ((coords.Z < 0) ? 1 : 0);

            DirtyChunks.Add(new Coordinates2D(coords.X - x * 32, coords.Z - z * 32));
        }
Exemplo n.º 4
0
        public void GenerateChunk(Coordinates2D position)
        {
            var globalPosition = Position * new Coordinates2D(Width, Depth) + position;
            var chunk          = World.ChunkProvider.GenerateChunk(World, globalPosition);

            chunk.IsModified   = true;
            chunk.Coordinates  = globalPosition;
            chunk.ParentRegion = this;
            DirtyChunks.Add(position);
            Chunks[position] = chunk;
            World.OnChunkGenerated(new ChunkLoadedEventArgs(chunk));
        }
Exemplo n.º 5
0
        /// <summary>
        ///  Saves this region to the open region file.
        /// </summary>
        public void Save()
        {
            lock (streamLock)
            {
                var toRemove = new List <Coordinates2D>();
                var chunks   = DirtyChunks.ToList();
                DirtyChunks.Clear();
                foreach (var coords in chunks)
                {
                    var chunk = GetChunk(coords, false);
                    if (chunk.IsModified)
                    {
                        var data = ((Chunk)chunk).ToNbt();
                        var raw  = data.SaveToBuffer(NbtCompression.ZLib);

                        var header = GetChunkFromTable(coords);
                        if (header == null || header.Item2 > raw.Length)
                        {
                            header = AllocateNewChunks(coords, raw.Length);
                        }

                        regionFile.Seek(header.Item1, SeekOrigin.Begin);
                        new McStream(regionFile).WriteInt32(raw.Length);
                        regionFile.WriteByte(2);                         // Compressed with zlib
                        regionFile.Write(raw, 0, raw.Length);

                        chunk.IsModified = false;
                    }

                    if ((DateTime.UtcNow - chunk.LastAccessed).TotalMinutes > 5)
                    {
                        toRemove.Add(coords);
                    }
                }

                regionFile.Flush();
                // Unload idle chunks
                foreach (var chunk in toRemove)
                {
                    var c = Chunks[chunk];
                    Chunks.Remove(chunk);
                    c.Dispose();
                }
            }
        }
Exemplo n.º 6
0
        private void MakeGame(bool singleplayer)
        {
            var gamedata = new GameDataTilesMinecraft();

            INetworkClient network;
            if (singleplayer)
            {
                network = new NetworkClientDummy();
            }
            else
            {
                network = new NetworkClientMinecraft();
            }
            clientgame = new GameMinecraft();
            /* fix for crash */
            //w.fpshistorygraphrenderer = new FpsHistoryGraphRenderer() { draw = w, viewportsize = w };
            var mapstorage = clientgame;
            var getfile = new GetFilePath(new[] { "mine", "minecraft" });
            var config3d = new Config3d();
            var mapManipulator = new MapManipulator();
            var terrainDrawer = new TerrainRenderer();
            var the3d = w;
            var exit = w;
            var localplayerposition = w;
            var worldfeatures = new WorldFeaturesDrawer();
            var physics = new CharacterPhysics();
            var mapgenerator = new MapGeneratorPlain();
            var internetgamefactory = this;
            if (singleplayer)
            {
                var n = (NetworkClientDummy)network;
                n.player = localplayerposition;
                n.Gui = w;
                n.Map1 = w;
                n.Map = mapstorage;
                n.Data = gamedata;
                n.Gen = new fCraft.MapGenerator();
                n.Gen.data = gamedata;
                n.Gen.log = new fCraft.FLogDummy();
                n.Gen.map = new MyFCraftMap() { data = gamedata, map = mapstorage, mapManipulator = mapManipulator };
                n.Gen.rand = new GetRandomDummy();
                n.DEFAULTMAP = "mountains";
            }
            else
            {
                var n = (NetworkClientMinecraft)network;
                n.Map = w;
                n.Clients = clientgame;
                n.Chatlines = w;
                n.Position = localplayerposition;
                n.gameworld = new GameWorldTodoDummy();
            }
            terrainDrawer.the3d = the3d;
            terrainDrawer.getfile = getfile;
            terrainDrawer.config3d = config3d;
            terrainDrawer.mapstorage = clientgame;
            terrainDrawer.data = gamedata;
            terrainDrawer.exit = exit;
            terrainDrawer.localplayerposition = localplayerposition;
            terrainDrawer.worldfeatures = worldfeatures;
            terrainDrawer.OnCrash += (a, b) => { CrashReporter.Crash(b.exception); };
            var terrainChunkDrawer = new TerrainChunkRenderer();
            terrainChunkDrawer.config3d = config3d;
            terrainChunkDrawer.data = gamedata;
            terrainChunkDrawer.mapstorage = clientgame;
            terrainDrawer.terrainchunkdrawer = terrainChunkDrawer;
            terrainChunkDrawer.terrainrenderer = terrainDrawer;
            worldfeatures.getfile = getfile;
            worldfeatures.localplayerposition = localplayerposition;
            worldfeatures.mapstorage = mapstorage;
            worldfeatures.the3d = the3d;
            mapManipulator.getfile = getfile;
            mapManipulator.mapgenerator = mapgenerator;
            w.map = clientgame;
            w.physics = physics;
            w.clients = clientgame;
            w.network = network;
            w.data = gamedata;
            w.getfile = getfile;
            w.config3d = config3d;
            w.mapManipulator = mapManipulator;
            w.terrain = terrainDrawer;
            bool IsMono = Type.GetType("Mono.Runtime") != null;
            terrainDrawer.textureatlasconverter = new TextureAtlasConverter();
            if (IsMono)
            {
                terrainDrawer.textureatlasconverter.fastbitmapfactory = () => { return new FastBitmapDummy(); };
            }
            else
            {
                terrainDrawer.textureatlasconverter.fastbitmapfactory = () => { return new FastBitmap(); };
            }
            weapon = new WeaponBlockInfo() { data = gamedata, terrain = terrainDrawer, viewport = w, map = clientgame, shadows = shadowssimple };
            w.weapon = new WeaponRenderer() { info = weapon, playerpos = w }; //no torch in mine mode
            var playerdrawer = new CharacterRendererMonsterCode();
            playerdrawer.Load(new List<string>(File.ReadAllLines(getfile.GetFile("player.mdc"))));
            w.characterdrawer = playerdrawer;
            w.particleEffectBlockBreak = new ParticleEffectBlockBreak() {  d_Data = gamedata, d_Map = clientgame, d_Terrain = terrainDrawer, d_Shadows = shadowsfull};
            clientgame.terrain = terrainDrawer;
            clientgame.network = network;

            clientgame.viewport = w;
            clientgame.data = gamedata;
            w.game = clientgame;
            w.login = new LoginClientMinecraft();
            w.internetgamefactory = internetgamefactory;
            PlayerSkinDownloader playerskindownloader = new PlayerSkinDownloader();
            playerskindownloader.exit = w;
            playerskindownloader.the3d = the3d;
            playerskindownloader.skinserver = "http://minecraft.net/skin/";
            w.playerskindownloader = playerskindownloader;
            physics.map = clientgame;
            physics.data = gamedata;
            mapgenerator.data = gamedata;
            audio.getfile = getfile;
            audio.gameexit = w;
            shadowsfull = new Shadows()
            {
                data = gamedata,
                map = clientgame,
                terrain = terrainDrawer,
                localplayerposition = localplayerposition,
                config3d = config3d
            };
            shadowssimple = new ShadowsSimple() { data = gamedata, map = clientgame};
            UseShadowsSimple();
            w.currentshadows = this;

            var frustumculling = new FrustumCulling() { the3d = the3d };
            terrainDrawer.frustumculling = frustumculling;
            terrainDrawer.batcher = new MeshBatcher() { frustumculling = frustumculling };
            terrainDrawer.frustumculling = frustumculling;
            w.RenderFrame += (a, b) => { frustumculling.CalcFrustumEquations(); };
            var dirtychunks = new DirtyChunks() { mapstorage = clientgame };
            terrainDrawer.ischunkready = dirtychunks;
            terrainDrawer.ischunkready.frustum = frustumculling;
            terrainDrawer.ischunkready.Start();
            //clientgame.ischunkready = dirtychunks;

            if (Debugger.IsAttached)
            {
                new DependencyChecker(typeof(InjectAttribute)).CheckDependencies(
                    w, audio, gamedata, clientgame, network, mapstorage, getfile,
                    config3d, mapManipulator, terrainDrawer, the3d, exit,
                    localplayerposition, worldfeatures, physics, mapgenerator,
                    internetgamefactory, playerdrawer, mapManipulator,
                    w.login, shadowsfull, shadowssimple, terrainChunkDrawer);
            }
        }