Exemple #1
0
        internal void liquidThreadUpdate()
        {
            Profiler.start("liquid");

            int border = 16;

            for (int x = viewPortInTiles.X - border; x < viewPortInTiles.X + viewPortInTiles.Width + 1 + border; x++)
            {
                for (int y = viewPortInTiles.Y + viewPortInTiles.Height + 1 + border; y > viewPortInTiles.Y - border; y--)
                {
                    if (inWorld(x, y))
                    {
                        if (LiquidNeedsUpdateMatrix[x, y])
                        {
                            updateLiquid(x, y);
                            LiquidNeedsUpdateMatrix[x, y] = false;
                        }
                    }
                }
            }

            Profiler.end("liquid");

            liquidThreadFps.update();
        }
Exemple #2
0
        protected override void Update(GameTime gameTime)
        {
            tick++;
            updateMessage = "";
            inputState.set(Keyboard.GetState(), Mouse.GetState());

            if (needToResetUserInput)
            {
                needToResetUserInput = false;
                userInputList.Clear();
                userInputList.Add(console);
                userInputList.Add(inventory);
                if (currentWorld != null)
                {
                    if (currentWorld.player != null)
                    {
                        userInputList.Add(currentWorld.player.movement);
                    }
                }
            }

            foreach (InputUser i in userInputList)
            {
                inputState = i.update(this, inputState);
            }
            inputState.regergitateKeyboardAndMouse();

            if (inputState.down(Keys.X))
            {
                currentWorld.player.position.Y += 16;
            }

            if (inputState.pressed(Game.KEY_ESCAPE))
            {
                this.Exit();
            }
            if (inputState.pressed(Game.KEY_DEBUG_MENU))
            {
                debugEnabled = !debugEnabled;
            }

            SoundEffectPlayer.update();

            if (currentWorld != null)
            {
                currentWorld.Update(this, tick);
                if (inputState.getKeyboardState().IsKeyDown(Game.KEY_FAST_FORWARD_CLOCK))
                {
                    currentWorld.time += 10;
                }
            }

            EntityItem.playedSoundEffectRecently = false;

            inputState.setLast(Keyboard.GetState(), Mouse.GetState());
            base.Update(gameTime);
            updateFps.update();
        }
Exemple #3
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(currentWorld == null?Color.CornflowerBlue:currentWorld.getBgColor());
            spriteBatch.Begin(SpriteSortMode.BackToFront, normalBlendState, SamplerState.PointClamp, DepthStencilState.DepthRead, RasterizerState.CullNone);

            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

            string e = "";
            string t = "";

            if (currentWorld != null)
            {
                currentWorld.Draw(this, gameTime);
                e = "Entity Count: " + currentWorld.EntityList.Count;

                int hr = (int)(currentWorld.time / 1000);

                t = "Time: " + (hr > 12?hr - 12:(hr == 0?12:hr)) + ":" + formatToHave2Digits(((int)(((currentWorld.time % 1000.0) / 1000.0) * 60.0))) + " " + (hr >= 12 ? "PM" : "AM") + " (" + (int)currentWorld.time + ")";
            }

            Profiler.start("draw gui");
            if (inventory != null)
            {
                inventory.draw(this, gameTime);
            }
            Profiler.end("draw gui");

            if (debugEnabled)
            {
                string d  = "Draw Fps: " + drawFps.getFps() + " (ms/t:" + drawFps.getMpt() + ") " + percent(drawFps.getFps(), 60) + "%";
                string u  = "Update Fps: " + updateFps.getFps() + " (ms/t:" + updateFps.getMpt() + ") " + percent(updateFps.getFps(), 60) + "%";
                string l  = "Lighting Fps: " + currentWorld.lightingThreadFps.getFps() + " (ms/t:" + currentWorld.lightingThreadFps.getMpt() + ") ";
                string lq = "Liquid Fps:   " + currentWorld.liquidThreadFps.getFps() + " (ms/t:" + currentWorld.liquidThreadFps.getMpt() + ") ";
                string p  = "Rendering:\n  Gui: " + Profiler.get("draw gui") + "\n  Tile: " + Profiler.get("draw tiles") + "\n  Entity: " + Profiler.get("draw entities");
                p += "\n\nLighting: " + Profiler.get("lighting");
                string ti = "T: " + currentWorld.getTileIndex(inventory.mouseTileX, inventory.mouseTileY, World.TileDepth.tile) + "`" + currentWorld.getTileData(inventory.mouseTileX, inventory.mouseTileY, World.TileDepth.tile);
                ti += "  W: " + currentWorld.getTileIndex(inventory.mouseTileX, inventory.mouseTileY, World.TileDepth.wall) + "`" + currentWorld.getTileData(inventory.mouseTileX, inventory.mouseTileY, World.TileDepth.wall);
                string pp = "Position: " + currentWorld.player.position.X + ", " + currentWorld.player.position.Y;

                spriteBatch.DrawString(fontNormal, d + "\n" + u + "\n" + l + "\n" + lq + "\n" + e + "\n" + t + "\n" + p + "\n" + ti + "\n" + pp + "\n" + drawMessage + "\n" + updateMessage, new Vector2(140, 10), Color.White);
            }
            drawMessage = "";

            console.draw(this, gameTime);

            spriteBatch.End();
            base.Draw(gameTime);
            drawFps.update();
        }
Exemple #4
0
        internal void lightingThreadUpdate()
        {
            if (lightingNeedsUpdate)
            {
                Profiler.start("lighting");

                TempLightMatrix = (int[, ])LightMatrix.Clone();

                int border = 16;

                for (int x = viewPortInTiles.X - border; x < viewPortInTiles.X + viewPortInTiles.Width + 1 + border; x++)
                {
                    for (int y = viewPortInTiles.Y - border; y < viewPortInTiles.Y + viewPortInTiles.Height + 1 + border; y++)
                    {
                        lightUpdate1(x, y);
                    }
                }

                for (int x = viewPortInTiles.X - border; x < viewPortInTiles.X + viewPortInTiles.Width + 1 + border; x++)
                {
                    lightUpdate2(x, viewPortInTiles.Y - border, true);
                    for (int y = viewPortInTiles.Y + 1 - border; y < viewPortInTiles.Y + viewPortInTiles.Height + 1 + border; y++)
                    {
                        lightUpdate2(x, y, false);
                    }
                }

                LightMatrix = (int[, ])TempLightMatrix.Clone();

                lightingNeedsUpdate = false;

                Profiler.end("lighting");

                lightingThreadFps.update();
            }
        }