Example #1
0
        public static Package Load(string path)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Package pkg = JsonConvert.DeserializeObject <Package>(File.ReadAllText(path));

            pkg.ParseItems();
            pkg.ParseManufactureTables();
            pkg.ParseHarvestTables();

            sw.Stop();
            Debug.LogWarning($"Database loaded ({sw.Elapsed.TotalMilliseconds:F2} ms)");

            return(pkg);
        }
Example #2
0
        private void ConstructInternal()
        {
            if (this.Deleted)
            {
                return;
            }

            if (this.Blocks == null)
            {
                BuildEndFrame = true;
                return;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            cwest = WestNeighbor?.Blocks != null;
            if (cwest)
            {
                bwest = new ushort[Chunk.TotalBlocks];
                WestNeighbor.Blocks.CopyTo(bwest, 0);
            }
            ceast = (EastNeighbor?.Blocks != null);
            if (ceast)
            {
                beast = new ushort[Chunk.TotalBlocks];
                EastNeighbor.Blocks.CopyTo(beast, 0);
            }
            cnorth = (NorthNeighbor?.Blocks != null);
            if (cnorth)
            {
                bnorth = new ushort[Chunk.TotalBlocks];
                NorthNeighbor.Blocks.CopyTo(bnorth, 0);
            }
            csouth = (SouthNeighbor?.Blocks != null);
            if (csouth)
            {
                bsouth = new ushort[Chunk.TotalBlocks];
                SouthNeighbor.Blocks.CopyTo(bsouth, 0);
            }

            List <Vector3F> svertices  = new List <Vector3F>(1 << 18);
            List <Vector2F> suv        = new List <Vector2F>(1 << 18);
            List <Vector3F> snormals   = new List <Vector3F>(1 << 18);
            List <uint>     striangles = new List <uint>(1 << 18);
            uint            striangle  = 0;

            List <Vector3F> tvertices  = new List <Vector3F>(1 << 18);
            List <Vector2F> tuv        = new List <Vector2F>(1 << 18);
            List <Vector3F> tnormals   = new List <Vector3F>(1 << 18);
            List <uint>     ttriangles = new List <uint>(1 << 18);
            uint            ttriangle  = 0;

            Stack <BlockFaces> faces = new Stack <BlockFaces>(6);

            Block  block = null;
            ushort index = 0;

            if (this.Deleted)
            {
                return;
            }

            Vector3F thisWP = this.WObject.Position;

            for (int z = 0; z < Depth; z++)
            {
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        if (this.Deleted)
                        {
                            return;
                        }

                        index = this.Blocks[x + Width * y + Width * Height * z];

                        if (!constructblocks.TryGetValue(index, out block))
                        {
                            block = ItemCache.Get <Block>(index);
                            constructblocks.Add(index, block);
                        }

                        if (block.Identifier == "winecrash:air")
                        {
                            continue;                                      // ignore if air
                        }
                        bool transparent = block.Transparent;

                        if (block.DrawAllSides)
                        {
                            faces.Push(BlockFaces.Up);    // up
                            faces.Push(BlockFaces.Down);  // down
                            faces.Push(BlockFaces.West);  // west
                            faces.Push(BlockFaces.East);  // east
                            faces.Push(BlockFaces.North); // north
                            faces.Push(BlockFaces.South); // south
                        }
                        else
                        {
                            if (IsTransparent(block, x, y + 1, z, constructblocks))
                            {
                                faces.Push(BlockFaces.Up);                                                     // up
                            }
                            if (IsTransparent(block, x, y - 1, z, constructblocks))
                            {
                                faces.Push(BlockFaces.Down);                                                     // down
                            }
                            if (IsTransparent(block, x - 1, y, z, constructblocks))
                            {
                                faces.Push(BlockFaces.West);                                                     // west
                            }
                            if (IsTransparent(block, x + 1, y, z, constructblocks))
                            {
                                faces.Push(BlockFaces.East);                                                     // east
                            }
                            if (IsTransparent(block, x, y, z + 1, constructblocks))
                            {
                                faces.Push(BlockFaces.North);                                                     // north
                            }
                            if (IsTransparent(block, x, y, z - 1, constructblocks))
                            {
                                faces.Push(BlockFaces.South);                                                     // south
                            }
                        }

                        foreach (BlockFaces face in faces)
                        {
                            CreateVerticesCube(x, y, z, face, transparent ? tvertices : svertices);

                            /*int count = usedvertices.Count;
                             * for (int i = count - 6; i < count; i++)
                             * {
                             *  Vector3F worldPos = thisWP + usedvertices[i] - new Vector3F(572, 0, 459);
                             *
                             *  Vector3F final = worldPos.RotateAround(new Vector3F(0,-360, 0), new Quaternion(worldPos.X * 0.1,0,worldPos.Z * 0.1));
                             *
                             *
                             *  final += new Vector3F(572, 0, 459);
                             *  usedvertices[i] = final - thisWP;
                             * }*/

                            CreateUVsCube(face, transparent ? tuv : suv, index);

                            CreateNormalsCube(face, transparent ? tnormals : snormals);

                            if (transparent)
                            {
                                ttriangles.AddRange(new uint[6]
                                {
                                    ttriangle, ttriangle + 1, ttriangle + 2, ttriangle + 3, ttriangle + 4, ttriangle + 5
                                });

                                ttriangle += 6;
                            }
                            else
                            {
                                striangles.AddRange(new uint[6]
                                {
                                    striangle, striangle + 1, striangle + 2, striangle + 3, striangle + 4, striangle + 5
                                });

                                striangle += 6;
                            }
                        }

                        faces.Clear();
                    }
                }
            }


            sw.Stop();

            Debug.Log("Chunk build time: " + sw.Elapsed.TotalMilliseconds.ToString("F2") + "ms");

            if (svertices.Count != 0)
            {
                if (this.SolidRenderer.Mesh == null)
                {
                    this.SolidRenderer.Mesh = new Mesh("Chunk Mesh");
                }

                this.SolidRenderer.Mesh.Vertices  = svertices.ToArray();
                this.SolidRenderer.Mesh.Triangles = striangles.ToArray();
                this.SolidRenderer.Mesh.UVs       = suv.ToArray();
                this.SolidRenderer.Mesh.Normals   = snormals.ToArray();
                this.SolidRenderer.Mesh.Tangents  = new Vector4F[svertices.Count];

                this.SolidRenderer.Mesh.Apply(true);
            }
            else
            {
                this.SolidRenderer.Mesh?.Delete();
                this.SolidRenderer.Mesh = null;
            }
            if (tvertices.Count != 0)
            {
                if (this.TransparentRenderer.Mesh == null)
                {
                    this.TransparentRenderer.Mesh = new Mesh("Chunk Transparent Mesh");
                }

                this.TransparentRenderer.Mesh.Vertices  = tvertices.ToArray();
                this.TransparentRenderer.Mesh.Triangles = ttriangles.ToArray();
                this.TransparentRenderer.Mesh.UVs       = tuv.ToArray();
                this.TransparentRenderer.Mesh.Normals   = tnormals.ToArray();
                this.TransparentRenderer.Mesh.Tangents  = new Vector4F[tvertices.Count];

                this.TransparentRenderer.Mesh.Apply(true);
            }
            else
            {
                this.TransparentRenderer.Mesh?.Delete();
                this.TransparentRenderer.Mesh = null;
            }

            svertices  = null;
            striangles = null;
            suv        = null;
            snormals   = null;

            tvertices  = null;
            ttriangles = null;
            tuv        = null;
            tnormals   = null;

            cwest  = ceast = cnorth = csouth = false;
            bsouth = null;
            bnorth = null;
            beast  = null;
            bwest  = null;

            ConstructedOnce = true;
        }
Example #3
0
        static void Main(string[] args)
        {
            CreateDebugWindow();

            Engine.Run(true, args).Wait();

            Engine.OnStop += () => End.Set();

            Debug.Log("\n\n");

            Time.PhysicsRate = 128D;
            Vector3D soloPlayerSpawnpoint = /*new Vector3D(32_000_000D, 0, 32_000_000D);//*/
                                            new Vector3D(572, 66, 459);


            //MainLoadScreen.Show();

            new Sound(@"assets/sounds/button_click.mp3");
            //new Shader("assets/shaders/Debug/Volume/DebugVolume.vert", "assets/shaders/Debug/Volume/DebugVolume.frag");

            Tester = new WObject("tester").AddModule <ClientTester>();

            /* ego mode enabled */
            Player.LocalPlayer = new Player("Arthur_" + new Random().Next(1000, 10000));

            Camera.Main.WObject.Delete();
            Camera.Main = null;



            WObject localPlayerWobj = new WObject("Local Player");

            localPlayerWobj.Enabled = false;
            PlayerController pc = localPlayerWobj.AddModule <PlayerController>();

            WObject camW = new WObject("Player Camera");

            camW.Parent        = localPlayerWobj;
            camW.LocalPosition = Vector3D.Up * 1.62D;
            Camera main = Camera.Main = camW.AddModule <Camera>();

            main.FOV           = 80;
            main.NearClip      = 0.01D;
            main.FarClip       = 4096.0D;
            main.RenderLayers &= ~(ulong)Layers.UI;
            main.WObject.AddModule <PanoramicPhotographer>();

            Winecrash.RenderDistance = 5;

            GameApplication app = (GameApplication)Graphics.Window;

            app.VSync = VSyncMode.On;

            string title = $"Winecrash {Winecrash.Version} ({IntPtr.Size * 8}bits)";

#if DEBUG
            title += " <DEBUG BUILD>";
#endif

            app.Title = title;

            app.OnLoaded += () =>
            {
                new Shader("assets/shaders/player/Player.vert", "assets/shaders/player/Player.frag");
                new Shader("assets/shaders/Unlit/Unlit.vert", "assets/shaders/Unlit/Unlit.frag");
                new Shader("assets/shaders/chunk/Chunk.vert", "assets/shaders/chunk/Chunk.frag");
                new Shader("assets/shaders/skybox/Skybox.vert", "assets/shaders/skybox/Skybox.frag");
                new Shader("assets/shaders/celestialbody/CelestialBody.vert", "assets/shaders/celestialbody/CelestialBody.frag");
                new Shader("assets/shaders/item/Item.vert", "assets/shaders/item/Item.frag");
                //new Shader("assets/shaders/fun/Fun.vert", "assets/shaders/fun/Fun.frag");


                Package.Load("assets/winecrash.package");
                ItemCache.BuildChunkTexture(out int xsize, out int ysize);
                //Chunk.Texture.Save(Folders.UserData + "items_atlas.png");

                Winecrash.CurrentSave = new Save(Save.DefaultName, Save.Exists(Save.DefaultName));

                Canvas.Main.UICamera.NearClip = -8192.0D;
                Canvas.Main.UICamera.FarClip  = 8192.0D;

                EngineCore.Instance.WObject.AddModule <GameDebug>();

                GameUI gui = Canvas.Main.WObject.AddModule <GameUI>();
                gui.Enabled = false;

                Client = new GameClient();
                Client.OnDisconnected += client =>
                {
                    Game.InvokePartyLeft(PartyType.Multiplayer);
                };

                MainMenu.Show();
            };

            Game.OnPartyJoined += type =>
            {
                GameUI.Instance.Enabled = true;
                Input.LockMode          = CursorLockModes.Lock;
                Input.CursorVisible     = false;
                MainMenu.Hide();

                localPlayerWobj.Enabled = true;
                Player.LocalPlayer.CreateEntity(localPlayerWobj);

                localPlayerWobj.Position = new Vector3D(soloPlayerSpawnpoint.X, 0, soloPlayerSpawnpoint.Z) + Vector3D.Up * (World.GetSurface(soloPlayerSpawnpoint, "winecraft:dimension") + 1);

                if (SkyboxController.Instance)
                {
                    SkyboxController.Instance.Show();
                }
                else
                {
                    new WObject("Skybox").AddModule <SkyboxController>();
                }

                Player.LocalPlayer.Entity.OnRotate += rotation =>
                {
                    if (!PlayerController.CameraLocked)
                    {
                        Camera.Main.WObject.Rotation = rotation;
                    }
                };

                if (type == PartyType.Singleplayer)
                {
                    Player.LocalPlayer.CameraAngles = Vector2I.Zero;

                    //Player.LocalPlayer.Entity.WObject.AddModule<DebugArrow>();

                    Task.Run(() =>
                    {
                        World.GlobalToLocal(soloPlayerSpawnpoint, out Vector2I cpos, out _);

                        Parallel.ForEach(World.GetCoordsInRange(cpos, Winecrash.RenderDistance),
                                         vector => { World.GetOrCreateChunk(vector, "winecrash:overworld"); });
                    });
                }
            };
            Game.OnPartyLeft += type =>
            {
                GameUI.Instance.Enabled = false;
                Input.LockMode          = CursorLockModes.Free;
                Input.CursorVisible     = true;
                World.Unload();

                localPlayerWobj.Enabled = false;
                Player.LocalPlayer.Entity?.Delete();
                Player.LocalPlayer.Entity = null;

                if (SkyboxController.Instance)
                {
                    SkyboxController.Instance.Hide();
                }

                MainMenu.Show();

                if (type == PartyType.Multiplayer)
                {
                    MainMenu.HideMain();
                }

                //Camera.Main._FarClip = 4096;
                //Camera.Main.WObject.Position = Vector3D.Zero;
            };


            Task.Run(() => End.WaitOne()).Wait();
        }
Example #4
0
 private static void CreateDebugWindow()
 {
     Debug.AddLogger(new Logger(LogVerbose, LogWarning, LogError, LogException));
     Debug.AddLogger(new Logger(LogVerboseCMD, LogWarnCMD, LogErrCMD, LogExceptionCMD));
 }