Exemplo n.º 1
0
 internal static void Dispose(ref VertexBuffer buffer)
 {
     if (buffer != null)
     {
         buffer.Dispose();
         buffer = null;
     }
 }
Exemplo n.º 2
0
        public HeadUpDisplay()
        {
            player = World.Instance.Player;

            for (int i = 0; i < labels.Length; i++)
            {
                labels[i] = new Label();
                labels[i].Color = new Vector4(1f, 1f, 0.2f, 1);
            }

            t.StartDrawingColoredQuads();
            Vector4 Color1 = new Vector4(0.1f, 0.1f, 0.1f, 1);
            t.AddVertexWithColor(new Vector4(0, 0, 0f, 1f), Color1);
            t.AddVertexWithColor(new Vector4(0, 1, 0f, 1f), Color1);
            t.AddVertexWithColor(new Vector4(1, 1, 0f, 1f), Color1);
            t.AddVertexWithColor(new Vector4(1, 0, 0f, 1f), Color1);
            background = t.GetVertexBuffer();
        }
Exemplo n.º 3
0
 public void Draw(VertexBuffer vertexBuffer)
 {
     VertexCount = vertexBuffer.VertexCount;
     DrawBuffer(vertexBuffer.Vertices);
     Reset();
 }
Exemplo n.º 4
0
 public VertexBuffer GetVertexBuffer()
 {
     VertexBuffer vertexBuffer = new VertexBuffer();
     vertexBuffer.Vertices = GetDrawBuffer();
     vertexBuffer.VertexCount = VertexCount;
     return vertexBuffer;
 }
Exemplo n.º 5
0
 private void Rebuild()
 {
     // rebuild
     VertexBuffer.Dispose(ref bufferText);
     if (string.IsNullOrEmpty(text))
         return;
     f.BeginBatch();
     if (!EnableShadow)
         f.RenderText(text, Position.X, Position.Y);
     else
         f.RenderTextShadow(Color, text, Position.X, Position.Y);
     f.StopBatch();
     bufferText = t.GetVertexBuffer();
 }
Exemplo n.º 6
0
 private void GenerateHungerBuffer()
 {
     if (lastHunger == player.Hunger)
         return;
     VertexBuffer.Dispose(ref hungerBuffer);
     float pixel = 1f / 256f;
     float texX = pixel * (16f + 9f * 0f);
     float texY = pixel * (9f * 3f);
     t.StartDrawingAlphaTexturedQuads("icons");
     Vector4 color = new Vector4(1, 1, 1, 1);
     float posx = 9f * 12;
     for (int i = 0; i < 10; i++)
     {
         t.SetTextureQuad(new Vector2(texX, texY), 9f * pixel, 9f * pixel);
         t.AddVertexWithColor(new Vector4(posx + 0f, 0f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 0f, 9f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 9f, 9f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 9f, 0f, 0f, 1.0f), color);
         if (i > (int)(player.Hunger / 10f) - 1)
         {
             t.SetTextureQuad(new Vector2(texX + pixel * 4f * 9f, texY), 9f * pixel, 9f * pixel);
             t.AddVertexWithColor(new Vector4(posx + 0f, 0f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 0f, 9f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 9f, 9f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 9f, 0f, 0f, 1.0f), color);
         }
         posx += 10.5f;
     }
     hungerBuffer = t.GetVertexBuffer();
     lastHunger = player.Hunger;
 }
Exemplo n.º 7
0
 private void GenerateHealthBuffer()
 {
     if (lastHealth == player.Health)
         return;
     VertexBuffer.Dispose(ref healthBuffer);
     float pixel = 1f / 256f;
     float texX = 16f * pixel;
     float texY = 0;
     t.StartDrawingAlphaTexturedQuads("icons");
     Vector4 color = new Vector4(1, 1, 1, 1);
     float posx = 0;
     for (int i = 0; i < 10; i++)
     {
         t.SetTextureQuad(new Vector2(texX, texY), 9f * pixel, 9f * pixel);
         t.AddVertexWithColor(new Vector4(posx + 0f, 0f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 0f, 9f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 9f, 9f, 0f, 1.0f), color);
         t.AddVertexWithColor(new Vector4(posx + 9f, 0f, 0f, 1.0f), color);
         if (i < (int)(player.Health / 10f))
         {
             t.SetTextureQuad(new Vector2(texX + pixel * 4f * 9f, texY), 9f * pixel, 9f * pixel);
             t.AddVertexWithColor(new Vector4(posx + 0f, 0f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 0f, 9f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 9f, 9f, 0f, 1.0f), color);
             t.AddVertexWithColor(new Vector4(posx + 9f, 0f, 0f, 1.0f), color);
         }
         posx += 9f;
     }
     healthBuffer = t.GetVertexBuffer();
     lastHealth = player.Health;
 }
Exemplo n.º 8
0
        internal void Build()
        {
            t.StartDrawingColoredQuads();
            Vector4 c = entity.Color;
            Vector3 min = entity.AABB.Min;
            Vector3 max = entity.AABB.Max;
            Vector4[] v = new Vector4[] {
            new Vector4(min.X, min.Y, min.Z,1),
            new Vector4(max.X, min.Y, min.Z,1),
            new Vector4(max.X, min.Y, max.Z,1),
            new Vector4(min.X, min.Y, max.Z,1),
            new Vector4(min.X, max.Y, min.Z,1),
            new Vector4(max.X, max.Y, min.Z,1),
            new Vector4(max.X, max.Y, max.Z,1),
            new Vector4(min.X, max.Y, max.Z,1),
            };

            // left
            t.AddVertexWithColor(v[0], c);
            t.AddVertexWithColor(v[4], c);
            t.AddVertexWithColor(v[7], c);
            t.AddVertexWithColor(v[3], c);

            //front
            t.AddVertexWithColor(v[3], c);
            t.AddVertexWithColor(v[7], c);
            t.AddVertexWithColor(v[6], c);
            t.AddVertexWithColor(v[2], c);

            //right
            t.AddVertexWithColor(v[2], c);
            t.AddVertexWithColor(v[6], c);
            t.AddVertexWithColor(v[5], c);
            t.AddVertexWithColor(v[1], c);

            //back
            t.AddVertexWithColor(v[1], c);
            t.AddVertexWithColor(v[5], c);
            t.AddVertexWithColor(v[4], c);
            t.AddVertexWithColor(v[0], c);

            //top
            t.AddVertexWithColor(v[4], c);
            t.AddVertexWithColor(v[5], c);
            t.AddVertexWithColor(v[6], c);
            t.AddVertexWithColor(v[7], c);

            //bottom
            t.AddVertexWithColor(v[0], c);
            t.AddVertexWithColor(v[3], c);
            t.AddVertexWithColor(v[2], c);
            t.AddVertexWithColor(v[1], c);

            buffer = t.GetVertexBuffer();
        }
Exemplo n.º 9
0
        internal void ProfilerSnapshot()
        {
            VertexBuffer.Dispose(ref profileVertexBuffer);

            t.ResetTransformation();
            FontRenderer f = FontRenderer.Instance;
            Player player = World.Instance.Player;
            f.BeginBatch();
            f.CharScale = 1;
            string report = p.Report();
            float y = TheGame.Instance.Height - FontRenderer.Instance.LineHeight;
            using (StringReader sr = new StringReader(report))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    f.RenderTextShadow(line, 0, y);
                    y -= f.LineHeight;
                }
            }

            // log...
            y -= f.LineHeight;

            if (World.Instance.PlayerVoxelTrace.Hit)
            {
                Vector4 impactpos = World.Instance.PlayerVoxelTrace.ImpactPosition;
                string line = string.Format(GetVectorAsString("impactpos", impactpos));
                f.RenderTextShadow(line, 0, y);
                y -= f.LineHeight;
            }
            else
            {
                f.RenderTextShadow("impactpos", 0, y);
                y -= f.LineHeight;

                Vector3 pos = new Vector3(player.Position.X, player.Position.Y, player.Position.Z);
                if (pos.Y > Chunk.MaxSizeY - 1)
                    pos.Y = Chunk.MaxSizeY - 1;
                else if (pos.Y < 0)
                    pos.Y = 0;
                PositionChunk chunkPos = PositionChunk.CreateFrom(pos);
                Vector3 chunkPos3 = new Vector3(chunkPos.X, chunkPos.Y, chunkPos.Z);
                f.RenderTextShadow(string.Format(GetVectorAsString("chunkpos", chunkPos3)), 0, y);
                y -= f.LineHeight;
                ChunkCache cache = World.Instance.GetCachedChunks();
                Chunk c = cache.GetChunk(chunkPos);
                if (c != null)
                {
                    f.RenderTextShadow(string.Format("chunk.Stage      = {0}", c.Stage.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("chunk.col.stage  = {0}", c.Column.Stage.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("chunk.col.active = {0}", c.Column.Active.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("cache.alleighbors= {0}", cache.AllNeighborColumns(c.Column).Where(cc => cc != null).Count()), 0, y);
                    y -= f.LineHeight;

                    List<Chunk> chunks = new List<Chunk>();
                    for (int i = 0; i < 8; i++)
                    {
                        chunks.Add(cache.GetChunk(new PositionChunk(c.Position.X, i, c.Position.Z)));

                    }
                }
            }
            f.RenderTextShadow(GetVectorAsString("direction", player.Direction), 0, y);

            y -= f.LineHeight;
            f.RenderTextShadow(GetVectorAsString("position", player.Position), 0, y);

            y -= f.LineHeight;
            y -= f.LineHeight;
            string[] lastLines = Log.Instance.Last(70);
            foreach (string line in lastLines)
            {
                f.RenderTextShadow(line, 0, y);
                y -= f.LineHeight;
            }
            f.StopBatch();
            profileVertexBuffer = t.GetVertexBuffer();
        }
Exemplo n.º 10
0
        internal void ProfilerSnapshot()
        {
            VertexBuffer.Dispose(ref profileVertexBuffer);

            t.ResetTransformation();
            FontRenderer f      = FontRenderer.Instance;
            Player       player = World.Instance.Player;

            f.BeginBatch();
            f.CharScale = 1;
            string report = p.Report();
            float  y      = TheGame.Instance.Height - FontRenderer.Instance.LineHeight;

            using (StringReader sr = new StringReader(report))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    f.RenderTextShadow(line, 0, y);
                    y -= f.LineHeight;
                }
            }

            // log...
            y -= f.LineHeight;

            if (World.Instance.PlayerVoxelTrace.Hit)
            {
                Vector4 impactpos = World.Instance.PlayerVoxelTrace.ImpactPosition;
                string  line      = string.Format(GetVectorAsString("impactpos", impactpos));
                f.RenderTextShadow(line, 0, y);
                y -= f.LineHeight;
            }
            else
            {
                f.RenderTextShadow("impactpos", 0, y);
                y -= f.LineHeight;

                Vector3 pos = new Vector3(player.Position.X, player.Position.Y, player.Position.Z);
                if (pos.Y > Chunk.MaxSizeY - 1)
                {
                    pos.Y = Chunk.MaxSizeY - 1;
                }
                else if (pos.Y < 0)
                {
                    pos.Y = 0;
                }
                PositionChunk chunkPos  = PositionChunk.CreateFrom(pos);
                Vector3       chunkPos3 = new Vector3(chunkPos.X, chunkPos.Y, chunkPos.Z);
                f.RenderTextShadow(string.Format(GetVectorAsString("chunkpos", chunkPos3)), 0, y);
                y -= f.LineHeight;
                ChunkCache cache = World.Instance.GetCachedChunks();
                Chunk      c     = cache.GetChunk(chunkPos);
                if (c != null)
                {
                    f.RenderTextShadow(string.Format("chunk.Stage      = {0}", c.Stage.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("chunk.col.stage  = {0}", c.Column.Stage.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("chunk.col.active = {0}", c.Column.Active.ToString()), 0, y);
                    y -= f.LineHeight;
                    f.RenderTextShadow(string.Format("cache.alleighbors= {0}", cache.AllNeighborColumns(c.Column).Where(cc => cc != null).Count()), 0, y);
                    y -= f.LineHeight;

                    List <Chunk> chunks = new List <Chunk>();
                    for (int i = 0; i < 8; i++)
                    {
                        chunks.Add(cache.GetChunk(new PositionChunk(c.Position.X, i, c.Position.Z)));
                    }
                }
            }
            f.RenderTextShadow(GetVectorAsString("direction", player.Direction), 0, y);

            y -= f.LineHeight;
            f.RenderTextShadow(GetVectorAsString("position", player.Position), 0, y);

            y -= f.LineHeight;
            y -= f.LineHeight;
            string[] lastLines = Log.Instance.Last(70);
            foreach (string line in lastLines)
            {
                f.RenderTextShadow(line, 0, y);
                y -= f.LineHeight;
            }
            f.StopBatch();
            profileVertexBuffer = t.GetVertexBuffer();
        }