Real time Lighting, Blocks, Chunks, Registries, Blockstates
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -23,6 +24,8 @@ namespace VoxelIsometricRenderer
|
||||
public static float scale = 2f;
|
||||
public static int FPS = 0;
|
||||
public static int Frames = 0;
|
||||
public static double TotalRamUsage = 0;
|
||||
public static double RamUsage = 0;
|
||||
public Terrain4()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -49,36 +52,19 @@ namespace VoxelIsometricRenderer
|
||||
TextureManager.AddBitmap(Resources.PinkSquare);
|
||||
TextureManager.AddBitmap(Resources.OrangeSquare);
|
||||
TextureManager.AddBitmap(Resources.ColourEdges);
|
||||
Voxels.Add(new Voxel(0, 0, 0, 0, 0, 0));
|
||||
Voxels.Add(new Voxel(9, 9, 9, 9, 9, 9));
|
||||
Voxels.Add(new Voxel(10, 10, 10, 10, 10, 10));
|
||||
Voxels.Add(new Voxel(11, 11, 11, 11, 11, 11));
|
||||
Voxels.Add(new Voxel(12, 12, 12, 12, 12, 12));
|
||||
Voxels.Add(new Voxel(3, 3, 3, 3, 3, 3));
|
||||
Voxels.Add(new Voxel(1, 1, 1, 1, 2, 3));
|
||||
Voxels.Add(new Voxel(4, 4, 4, 4, 6, 6));
|
||||
Voxels.Add(new Voxel(5, 5, 5, 5, 6, 6));
|
||||
Voxels.Add(new Voxel(7, 7, 7, 7, 7, 7));
|
||||
Voxels.Add(new Voxel(17, 18, 19, 20, 21, 22));
|
||||
Voxels.Add(new Voxel(23, 23, 23, 23, 23, 23));
|
||||
Voxels.Add(new Voxel(17, 18, 19, 20, -1, -1));
|
||||
Voxels.Add(new Voxel(23, 23, 23, 23, -1, -1));
|
||||
Voxels.Add(new Voxel(-1, -1, -1, -1, 21, 22));
|
||||
Voxels.Add(new Voxel(-1, -1, -1, -1, 23, 23));
|
||||
Voxels.Add(new Voxel(1, 13, 13, 13, 13, -1, -1));
|
||||
Voxels.Add(new Voxel(1, 14, 14, 14,14, -1, -1));
|
||||
Voxels.Add(new Voxel(1, 15, 15, 15,15, -1, -1));
|
||||
Voxels.Add(new Voxel(1, 16, 16, 16,16, -1, -1));
|
||||
Random rnd = new Random();
|
||||
for(int i = 0; i < 25; i++)
|
||||
{
|
||||
Voxels.Add(new Voxel(rnd.Next(0,TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1), rnd.Next(0, TextureManager.textures.Count - 1)));
|
||||
}
|
||||
TextureManager.GenerateVoxelFaces();
|
||||
for (int i = 0; i < Voxels.Count; i++)
|
||||
{
|
||||
//TextureManager.CreateModel(Voxels[i]);
|
||||
Chunk TestChunk = ChunkRegistry.IndexChunk(0, 0, 0);
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
for (int k = 0; k < 16; k++) {
|
||||
if (i < 10 && k < 10 && rnd.Next(0, 3) > 0) TestChunk.CreateBlock(new int[] { rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13), rnd.Next(0, 13) }, 0, new BlockState(false, BlockType.Ground, true), i, j, k);
|
||||
else TestChunk.CreateAir(i, j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
TestChunk.GenerateLightMap();
|
||||
TestChunk.CalculateCull();
|
||||
MainThread = new Thread(Runtime);
|
||||
MainThread.SetApartmentState(ApartmentState.STA);
|
||||
MainThread.Start();
|
||||
@@ -97,28 +83,16 @@ namespace VoxelIsometricRenderer
|
||||
{
|
||||
LightingFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
|
||||
LightingManager.UpdateLighting();
|
||||
LightingManager.sunAngles[0] += 5f;
|
||||
LightingManager.sunAngles[1] += 1f;
|
||||
//LightingManager.sunAngles[0] += 5f;
|
||||
// LightingManager.sunAngles[1] += 1f;
|
||||
}
|
||||
if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds - SecondFrameTime > 1000) {
|
||||
TotalRamUsage = Math.Round(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 / 1000000.0);
|
||||
RamUsage = Math.Round(GC.GetTotalMemory(false) / 1000000.0);
|
||||
SecondFrameTime = Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
|
||||
FPS = Frames;
|
||||
Frames = 0;
|
||||
}
|
||||
if (up && LightingManager.AmbientColouring[0] < 1.5f)
|
||||
{
|
||||
//LightingManager.AmbientColouring[0] += 0.01f;
|
||||
//LightingManager.AmbientColouring[1] += 0.01f;
|
||||
//LightingManager.AmbientColouring[2] += 0.01f;
|
||||
}
|
||||
else if (up) up = false;
|
||||
else if (LightingManager.AmbientColouring[0] > 0.5f)
|
||||
{
|
||||
//LightingManager.AmbientColouring[0] -= 0.01f;
|
||||
//LightingManager.AmbientColouring[1] -= 0.01f;
|
||||
//LightingManager.AmbientColouring[2] -= 0.01f;
|
||||
}
|
||||
else up = true;
|
||||
}
|
||||
}
|
||||
private void Draw(object sender, PaintEventArgs e)
|
||||
@@ -127,20 +101,9 @@ namespace VoxelIsometricRenderer
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
g.ScaleTransform(scale, scale);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
foreach(Voxel voxel in Voxels)
|
||||
{
|
||||
voxel.Draw(g,2 + x,2 + y);
|
||||
x += 36;
|
||||
if ((x+32) * scale > Width)
|
||||
{
|
||||
y += 36;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
ChunkRegistry.RenderChunk(g, 0);
|
||||
g.ResetTransform();
|
||||
g.DrawString(String.Format("FPS: {0}", FPS), SystemFonts.DefaultFont, Brushes.Red, new PointF(0, 0));
|
||||
g.DrawString(String.Format("FPS: {0} Ram Usage: {9}MB Ram Allocated: {8}MB\nSunValue: {1}\nMoonValue:{3}\nLightDirection:{4}\nAmbientColourGrading: R{5} G{6} B{7}\nSunAngles:{2}", FPS, LightingManager.SkyLightMetrics[0], String.Format(" x={0}° y={1}°", LightingManager.sunAngles[0], LightingManager.sunAngles[1]), LightingManager.SkyLightMetrics[2], LightingManager.SunAngle, LightingManager.SkyLightMetrics[3], LightingManager.SkyLightMetrics[4], LightingManager.SkyLightMetrics[5], TotalRamUsage, RamUsage), SystemFonts.DefaultFont, Brushes.Red, new PointF(0, 0));
|
||||
Frames++;
|
||||
}
|
||||
public void ResizeDisplay()
|
||||
@@ -164,6 +127,22 @@ namespace VoxelIsometricRenderer
|
||||
{
|
||||
if (e.KeyCode == Keys.Up) scale += 0.25f;
|
||||
if (e.KeyCode == Keys.Down) scale -= 0.25f;
|
||||
if (e.KeyCode == Keys.W)
|
||||
{
|
||||
LightingManager.sunAngles[1] += 10f;
|
||||
}
|
||||
if (e.KeyCode == Keys.S)
|
||||
{
|
||||
LightingManager.sunAngles[1] -= 10f;
|
||||
}
|
||||
if (e.KeyCode == Keys.A)
|
||||
{
|
||||
LightingManager.sunAngles[0] += 10f;
|
||||
}
|
||||
if (e.KeyCode == Keys.D)
|
||||
{
|
||||
LightingManager.sunAngles[0] += 10f;
|
||||
}
|
||||
}
|
||||
|
||||
private void KeyUpEvent(object sender, KeyEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user