Esempio n. 1
0
        public override void Begin()
        {
            Name             = "Player";
            currentWorld     = World.GetInstance();
            hasHadInitialSet = false;

            heartIcon      = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/heart.png");
            heartHalfIcon  = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/heart_half.png");
            heartEmptyIcon = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/heart_empty.png");

            hungerIcon      = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/hunger.png");
            hungerHalfIcon  = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/hunger_half.png");
            hungerEmptyIcon = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/hunger_empty.png");

            Input.Input.GetSetting("Pause").KeyDown += InputPause;

            Input.Input.GetSetting("Jump").KeyDown += InputJump;

            Input.Input.GetSetting("Interact").KeyDown += InputInteract;

            Input.Input.GetSetting("Destroy Block").KeyDown += InputDestroyBlock;

            Input.Input.GetSetting("Inventory").KeyDown += InputInventory;

            Program.Window.MouseWheel += InputMouseWheel;

            Input.Input.GetSetting("Sprint").KeyDown += InputSprintDown;
            Input.Input.GetSetting("Sprint").KeyUp   += InputSprintUp;
        }
        public override void Execute()
        {
            var tex = AssetDatabase.GetAsset <Texture2D>(id);

            tex.SetFilter(filter);
            tex.Apply();
        }
Esempio n. 3
0
        public static void DrawNow(Mesh mesh, Material.Material material, Matrix4 worldMatrix = default)
        {
            if (material == null)
            {
                material = AssetDatabase.GetAsset <Material.Material>("Resources/Materials/Fallback.mat");
            }

            if (worldMatrix == default)
            {
                worldMatrix = Matrix4.Identity;
            }

            if (worldMatrix != default)
            {
                material.Shader.SetUniform("u_World", worldMatrix);
            }

            UniformBuffers.BindAll(material.Shader.Handle);
            material.Bind();
            mesh.VertexArray.Bind();
            mesh.IndexBuffer.Bind();

            GL.DrawElements(PrimitiveType.Triangles, mesh.IndexBuffer.Length, DrawElementsType.UnsignedInt, 0);

            mesh.VertexArray.Unbind();
            mesh.IndexBuffer.Unbind();
            material.Unbind();
            UniformBuffers.UnbindAll();
        }
        public override void Execute()
        {
            var tex = AssetDatabase.GetAsset <Texture2D>(id);

            tex.SetWrapping(wrapping);
            tex.Apply();
        }
Esempio n. 5
0
        public static Asset DeserializeAsset(XmlNode node)
        {
            int id = Convert.ToInt32(node.Attributes["id"].Value);

            AssetDatabase.Load(id);
            return(AssetDatabase.GetAsset(id));
        }
Esempio n. 6
0
        public static T[] DeserializeAssetArray <T>(XmlNode node) where T : Asset
        {
            List <T> assets = new List <T>();

            foreach (XmlNode c in node.ChildNodes)
            {
                int id = Convert.ToInt32(c.InnerText);
                AssetDatabase.Load(id);
                assets.Add(AssetDatabase.GetAsset <T>(id));
            }
            return(assets.ToArray());
        }
Esempio n. 7
0
        TextureContract IEditorService.GetTexture(int id)
        {
            AssetDatabase.Load(id);
            var tex = AssetDatabase.GetAsset <Texture2D>(id);

            return(new TextureContract
            {
                Name = tex.Name,
                Filter = tex.filter,
                Wrapping = tex.wrapping
            });
        }
Esempio n. 8
0
        ShaderContract IEditorService.GetShader(int id)
        {
            AssetDatabase.Load(id);
            var            shader = AssetDatabase.GetAsset <Shader>(id);
            ShaderContract sc     = new ShaderContract();

            sc.Name     = shader.Name;
            sc.uniforms = new List <Tuple <string, string> >();
            foreach (var u in shader.uniforms)
            {
                sc.uniforms.Add(new Tuple <string, string>(u.type.Name, u.name));
            }
            return(sc);
        }
Esempio n. 9
0
        public override void Show()
        {
            Player.SetMouseVisible(true);

            titleStyle.HorizontalAlignment = HorizontalAlignment.Middle;
            titleStyle.VerticalAlignment   = VerticalAlignment.Middle;
            titleStyle.FontSize            = 92;

            options.PreviousMenu = this;

            tex = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_bg.png");

            base.Show();
        }
Esempio n. 10
0
        //Init
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Logging.LogInfo(this, "Initializing");
            AssetDatabase.Init();
            UserCodeDatabase.Init();
            RenderPipeline.Init(this);
            Input.Init(this);

            //AssetDatabase.Load(7);
            //Material m = AssetDatabase.GetAsset<Material>(7);
            //RenderPipeline.AddPostProcessingEffect(m);

            AssetDatabase.Load(3);
            s = AssetDatabase.GetAsset <Scene>(3);
            AssetDatabase.Load(2);
        }
Esempio n. 11
0
        public void Begin()
        {
            TexturePack = AssetDatabase.GetAsset <TexturePack>("");

            TerrainNoise = new OpenSimplex(Seed.GetSeedNum());
            BiomeNoise   = new CellNoise(Seed.GetSeedNum());
            Randomizer   = new Random(Seed.GetSeedNum());
            WorldCamera  = new Camera();

            Skybox = new Skybox(AssetDatabase.GetAsset <Material>("Resources/Materials/World/Sky.mat"));
            loadingScreenTexture         = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/img_loading_screen.png");
            loadingScreenTextureDickJoke = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/img_loading_screen_willy.png");
            isDickJoke         = Maths.Chance(0.01f);
            loadingScreenStyle = new GUIStyle()
            {
                Normal = new GUIStyleOption()
                {
                    TextColor = Color4.White
                },
                HorizontalAlignment = HorizontalAlignment.Middle,
                VerticalAlignment   = VerticalAlignment.Middle,
                FontSize            = 48,
                Font = GUI.LabelStyle.Font
            };

            lightAngle      = 5;
            lightBufferData = new LightingUniformBufferData();

            HasFinishedInitialLoading = false;
            requiredChunksLoadedNum   = (worldSize + worldSize + 1) * (worldSize + worldSize + 1);

            foreach (var entity in loadedEntities)
            {
                entity.Begin();
            }

            ThreadStart chunkThreadStart = ChunkThread;

            chunkThread = new Thread(chunkThreadStart)
            {
                Name = "Chunk Generation Thread"
            };
            chunkThread.Start();
        }
Esempio n. 12
0
 public Skybox(Material.Material mat)
 {
     skyMesh = AssetDatabase.GetAsset <Mesh>("Resources/Models/SkySphere.obj");
     skyMat  = mat;
 }
Esempio n. 13
0
        public static void DrawRequest(Mesh mesh, Material.Material material, Matrix4 worldMatrix = default)
        {
            if (mesh.IndexBuffer.Length == 0)
            {
                return;
            }

            if (worldMatrix == default)
            {
                worldMatrix = Matrix4.Identity;
            }

            if (World.GetInstance() != null && !World.GetInstance().WorldCamera.Frustum.Intersects(mesh.Bounds.Transform(worldMatrix.ExtractTranslation(), Vector3.One)))
            {
                ClippedCount++;
                return;
            }

            if (material == null)
            {
                material = AssetDatabase.GetAsset <Material.Material>("Resources/Materials/Fallback.mat");
            }

            if (drawQueue.Contains(material.Name))
            {
                var batch = (BatchDraw)drawQueue[material.Name];
                batch.draws.Add(new QueuedDraw()
                {
                    mesh        = mesh,
                    worldMatrix = worldMatrix
                });
            }
            else if (material.Shader.IsTransparent)
            {
                drawQueue.Add(material.Name, new BatchDraw()
                {
                    draws = new List <QueuedDraw>()
                    {
                        new QueuedDraw()
                        {
                            mesh        = mesh,
                            worldMatrix = worldMatrix
                        }
                    },
                    material = material,
                });
            }
            else
            {
                drawQueue.Insert(0, material.Name, new BatchDraw()
                {
                    draws = new List <QueuedDraw>()
                    {
                        new QueuedDraw()
                        {
                            mesh        = mesh,
                            worldMatrix = worldMatrix
                        }
                    },
                    material = material,
                });
            }
            DrawCalls = drawQueue.Count;
        }
Esempio n. 14
0
        public IImportable Import(string path, ZipFile pack)
        {
            MemoryStream stream = new MemoryStream();

            pack[infoLocation].Extract(stream);
            TexturePack texPack = JsonConvert.DeserializeObject <TexturePack>(Encoding.ASCII.GetString(stream.ToArray()));//(File.ReadAllText(path + "/Pack.json"));

            texPack.IconTexture = AssetDatabase.GetAsset <Texture>(texturesLocation + "Pack_Icon.png");
            texPack.Blocks      = AssetDatabase.GetAsset <Texture>(texturesLocation + "Blocks.png");
            texPack.Crosshair   = AssetDatabase.GetAsset <Texture>(texturesLocation + "GUI/Crosshair.png");

            stream = new MemoryStream();
            pack[blocksLocation].Extract(stream);
            texPack.BlockData = JsonConvert.DeserializeObject <TexturePackBlocks>(Encoding.ASCII.GetString(stream.ToArray()));

            float oneSlotX = 1f / (float)texPack.BlockData.BlocksPerRow;
            float oneSlotY = 1f / (float)texPack.BlockData.BlocksPerColumn;

            foreach (var block in texPack.BlockData.Blocks)
            {
                var bl = BlockDatabase.GetBlock(block.block_id);

                if (bl == null)
                {
                    continue;
                }

                {
                    block.back_face.X *= oneSlotX;
                    block.back_face.Y *= oneSlotY;

                    block.front_face.X *= oneSlotX;
                    block.front_face.Y *= oneSlotY;

                    block.left_face.X *= oneSlotX;
                    block.left_face.Y *= oneSlotY;

                    block.right_face.X *= oneSlotX;
                    block.right_face.Y *= oneSlotY;

                    block.top_face.X *= oneSlotX;
                    block.top_face.Y *= oneSlotY;

                    block.bottom_face.X *= oneSlotX;
                    block.bottom_face.Y *= oneSlotY;

                    block.back_face_mask.X *= oneSlotX;
                    block.back_face_mask.Y *= oneSlotY;

                    block.front_face_mask.X *= oneSlotX;
                    block.front_face_mask.Y *= oneSlotY;

                    block.left_face_mask.X *= oneSlotX;
                    block.left_face_mask.Y *= oneSlotY;

                    block.right_face_mask.X *= oneSlotX;
                    block.right_face_mask.Y *= oneSlotY;

                    block.top_face_mask.X *= oneSlotX;
                    block.top_face_mask.Y *= oneSlotY;

                    block.bottom_face_mask.X *= oneSlotX;
                    block.bottom_face_mask.Y *= oneSlotY;
                }

                bl.BackFace = new Block.Face(new Rect(block.back_face.X, block.back_face.Y, block.back_face.X + oneSlotX, block.back_face.Y + oneSlotY),
                                             new Rect(block.back_face_mask.X, block.back_face_mask.Y, block.back_face_mask.X + oneSlotX, block.back_face_mask.Y + oneSlotY));
                bl.FrontFace = new Block.Face(new Rect(block.front_face.X, block.front_face.Y, block.front_face.X + oneSlotX, block.front_face.Y + oneSlotY),
                                              new Rect(block.front_face_mask.X, block.front_face_mask.Y, block.front_face_mask.X + oneSlotX, block.front_face_mask.Y + oneSlotY));

                bl.LeftFace = new Block.Face(new Rect(block.left_face.X, block.left_face.Y, block.left_face.X + oneSlotX, block.left_face.Y + oneSlotY),
                                             new Rect(block.left_face_mask.X, block.left_face_mask.Y, block.left_face_mask.X + oneSlotX, block.left_face_mask.Y + oneSlotY));
                bl.RightFace = new Block.Face(new Rect(block.right_face.X, block.right_face.Y, block.right_face.X + oneSlotX, block.right_face.Y + oneSlotY),
                                              new Rect(block.right_face_mask.X, block.right_face_mask.Y, block.right_face_mask.X + oneSlotX, block.right_face_mask.Y + oneSlotY));

                bl.TopFace = new Block.Face(new Rect(block.top_face.X, block.top_face.Y, block.top_face.X + oneSlotX, block.top_face.Y + oneSlotY),
                                            new Rect(block.top_face_mask.X, block.top_face_mask.Y, block.top_face_mask.X + oneSlotX, block.top_face_mask.Y + oneSlotY));

                bl.BottomFace = new Block.Face(new Rect(block.bottom_face.X, block.bottom_face.Y, block.bottom_face.X + oneSlotX, block.bottom_face.Y + oneSlotY),
                                               new Rect(block.bottom_face_mask.X, block.bottom_face_mask.Y, block.bottom_face_mask.X + oneSlotX, block.bottom_face_mask.Y + oneSlotY));

                BlockDatabase.SetBlock(block.block_id, bl);
            }

            return(texPack);
        }
Esempio n. 15
0
        static ContainerRenderer()
        {
            ContainerBackground = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_bg.png");
            ContainerSlot       = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_slot.png");
            SlotNumberStyle     = new GUIStyle()
            {
                Font                = GUI.ButtonStyle.Font,
                FontSize            = 40,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                AlignmentOffset     = new Vector2(8, 0),
                Normal              = new GUIStyleOption()
                {
                    TextColor = Color4.White
                }
            };
            Input.Input.MouseDown += (sender, args) =>
            {
                if (args.Button == MouseButton.Left)
                {
                    if (SelectedStack != null)
                    {
                        for (int i = 0; i < toDraw.Count; i++)
                        {
                            if (toDraw[i].SelectedSlot == new Vector2(-1, -1))
                            {
                                continue;
                            }

                            if (toDraw[i].GetIsSlotFree(toDraw[i].SelectedSlot))
                            {
                                SelectedStack.LocationInContainer = toDraw[i].SelectedSlot;
                                toDraw[i].ItemsList.Add(SelectedStack);
                                toDraw[i].ItemDroppedIntoContainer(SelectedStack);
                                StackBlockedForSelection = SelectedStack;
                                SelectedStack            = null;
                                return;
                            }
                            else
                            {
                                var stackAtLocation = toDraw[i].GetItemStackByLocation(toDraw[i].SelectedSlot);
                                if (stackAtLocation.ItemKey == SelectedStack.ItemKey)
                                {
                                    int possibleNewSize =
                                        (stackAtLocation.StackSize + stackAtLocation.StackSize) -
                                        stackAtLocation.Item.MaxStackSize;
                                    if (stackAtLocation.AddToStack(SelectedStack.StackSize) == ItemStackState.Full)
                                    {
                                        SelectedStack.StackSize  = possibleNewSize;
                                        StackBlockedForSelection = stackAtLocation;
                                    }
                                    else
                                    {
                                        StackBlockedForSelection = SelectedStack;
                                        SelectedStack            = null;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (args.Button == MouseButton.Right)
                {
                    if (SelectedStack != null)
                    {
                        for (int i = 0; i < toDraw.Count; i++)
                        {
                            if (toDraw[i].SelectedSlot == new Vector2(-1, -1))
                            {
                                continue;
                            }

                            if (toDraw[i].GetIsSlotFree(toDraw[i].SelectedSlot))
                            {
                                ItemStack newStack = new ItemStack(SelectedStack.ItemKey, 1, toDraw[i].SelectedSlot);
                                toDraw[i].ItemsList.Add(newStack);
                                toDraw[i].ItemDroppedIntoContainer(newStack);

                                if (SelectedStack.RemoveFromStack() == ItemStackState.Empty)
                                {
                                    SelectedStack = null;
                                }

                                return;
                            }
                            else
                            {
                                var stackAtLocation = toDraw[i].GetItemStackByLocation(toDraw[i].SelectedSlot);
                                if (stackAtLocation.ItemKey == SelectedStack.ItemKey && !stackAtLocation.IsStackFull())
                                {
                                    stackAtLocation.AddToStack();

                                    if (SelectedStack.RemoveFromStack() == ItemStackState.Empty)
                                    {
                                        SelectedStack = null;
                                    }
                                    return;
                                }
                            }
                        }
                    }
                }

                StackBlockedForSelection = null;
            };
        }
Esempio n. 16
0
        /// <summary>
        /// Use AssetData.GetAsset instead!
        /// </summary>
        /// <param name="file"></param>
        public Material(string file, string matName)
        {
            Name = matName;
            var lines = File.ReadAllLines(file);

            string          shader   = "";
            List <string[]> uniforms = new List <string[]>();

            //Store data to be process in correct order (textures don't matter)
            foreach (var line in lines)
            {
                if (line.StartsWith("//"))
                {
                    continue;
                }

                if (line.StartsWith("texture"))
                {
                    textures.Add(AssetDatabase.GetAsset <Texture>(line.Split(' ')[1]));
                }
                else if (line.StartsWith("shader"))
                {
                    shader = line.Split(' ')[1];
                }
                else if (line.StartsWith("uniform"))
                {
                    var split = line.Split(' ');
                    uniforms.Add(split);
                }
                else if (line.StartsWith("useMultiDraw"))
                {
                    var split = line.Split(' ')[1];
                    UseMultiDraw = split == "true";
                }
            }

            //Instantiate shader
            Shader = new Shader(shader);
            foreach (var uniform in uniforms)
            {
                ProcessUniform(uniform);
            }

            void ProcessUniform(string[] uniform)
            {
                string type  = uniform[1];
                string name  = uniform[2];
                string value = uniform[3];

                try
                {
                    switch (type)
                    {
                    case "number":
                        var f = float.Parse(value);
                        Shader.SetUniform(name, f);
                        break;

                    case "mat4":
                        Matrix4 mat4    = new Matrix4();
                        var     mat4Val = value.Split(',');
                        if (mat4Val.Length == 16)
                        {
                            mat4.M11 = float.Parse(mat4Val[0]);
                            mat4.M12 = float.Parse(mat4Val[1]);
                            mat4.M13 = float.Parse(mat4Val[2]);
                            mat4.M14 = float.Parse(mat4Val[3]);
                            mat4.M21 = float.Parse(mat4Val[4]);
                            mat4.M22 = float.Parse(mat4Val[5]);
                            mat4.M23 = float.Parse(mat4Val[6]);
                            mat4.M24 = float.Parse(mat4Val[7]);
                            mat4.M31 = float.Parse(mat4Val[8]);
                            mat4.M32 = float.Parse(mat4Val[9]);
                            mat4.M33 = float.Parse(mat4Val[10]);
                            mat4.M34 = float.Parse(mat4Val[11]);
                            mat4.M41 = float.Parse(mat4Val[12]);
                            mat4.M42 = float.Parse(mat4Val[13]);
                            mat4.M43 = float.Parse(mat4Val[14]);
                            mat4.M44 = float.Parse(mat4Val[15]);

                            Shader.SetUniform(name, mat4);
                        }
                        break;

                    case "vec2":
                        var vec2Val = value.Split(',');
                        if (vec2Val.Length == 2)
                        {
                            Shader.SetUniform(name, new Vector2(float.Parse(vec2Val[0]), float.Parse(vec2Val[1])));
                        }
                        break;

                    case "vec3":
                        var vec3Val = value.Split(',');
                        if (vec3Val.Length == 3)
                        {
                            Shader.SetUniform(name, new Vector3(float.Parse(vec3Val[0]), float.Parse(vec3Val[1]), float.Parse(vec3Val[2])));
                        }
                        break;

                    case "vec4":
                        var vec4Val = value.Split(',');
                        if (vec4Val.Length == 4)
                        {
                            Shader.SetUniform(name, new Vector4(float.Parse(vec4Val[0]), float.Parse(vec4Val[1]), float.Parse(vec4Val[2]), float.Parse(vec4Val[3])));
                        }
                        break;
                    }
                }
                catch
                {
                    Debug.Log($"There was any error parsing material {file}", DebugLevel.Error);
                }
            }
        }
Esempio n. 17
0
 public PlayerInventory()
 {
     SelectedSlotTexture = AssetDatabase.GetAsset <Texture>("Resources/Textures/GUI/inventory_slot_selected.png");
 }