Example #1
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();
        }
Example #2
0
        public static void GenerateBlockItemIcons()
        {
            const int ICON_SIZE = 64;

            FrameBufferObject fbo = null;

            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.ClearColor(0, 0, 0, 0);

            LightingUniformBufferData lighting = new LightingUniformBufferData();

            lighting.AmbientColour = new Vector4(0.5f, 0.5f, 0.5f, 1);
            lighting.SunColour     = new Vector4(1, 1, 1, 1);
            lighting.SunStrength   = 1;
            lighting.SunDirection  = new Vector4(0.5f, 0.5f, 0.5f, 1);

            Chunk tempChunk = new Chunk(Vector2.Zero);

            tempChunk.Blocks = new Chunk.BlockState[Chunk.WIDTH, Chunk.HEIGHT, Chunk.WIDTH];

            Camera tempCamera = new Camera();

            tempCamera.ProjectionType = CameraProjectionType.Orthographic;
            tempCamera.CameraSize     = new Vector2(0.8f);
            tempCamera.GenerateProjectionMatrix();
            tempCamera.Position = new Vector3(0, 0, 15f);

            UniformBuffers.DirectionLightBuffer.Update(lighting);
            tempCamera.Update();

            var items = ItemDatabase.GetItems();

            for (int i = 0; i < items.Count; i++)
            {
                if (items[i] is BlockItem item)
                {
                    fbo = new FrameBufferObject(ICON_SIZE, ICON_SIZE, FBOType.None);
                    fbo.Bind();
                    GL.Clear(ClearBufferMask.ColorBufferBit);

                    var newState = new Chunk.BlockState(0, 0, 0, tempChunk);
                    newState.id = (short)item.Block.ID;
                    tempChunk.Blocks[0, 0, 0] = newState;
                    tempChunk.GenerateMesh();

                    tempChunk.RenderForIcon();

                    //Render here...
                    Texture icon = new Texture(fbo, true);
                    AssetDatabase.RegisterAsset(icon, "GeneratedIcons/" + item.Key);

                    item.IconLocation = "GeneratedIcons/" + item.Key;
                    item.GenerateGraphics();
                }
            }

            fbo?.Unbind();

            fbo?.DisposeWithoutColorHandle();
            tempChunk.Dispose();

            GL.ClearColor(Window.CLEAR_COLOUR.X, Window.CLEAR_COLOUR.Y, Window.CLEAR_COLOUR.Z, Window.CLEAR_COLOUR.W);

            fbo        = null;
            tempChunk  = null;
            tempCamera = null;
        }