Started refactors for logging and level loading

This commit is contained in:
2017-02-27 01:04:30 -05:00
parent a7c2f5bb29
commit 84608d5981
20 changed files with 85 additions and 86 deletions

View File

@@ -16,20 +16,6 @@ namespace hexworld
public static void Main(string[] args)
{
using (var gw = new HexRender(1280, 720)) gw.Run();
// var s1 = new SubArray<int>(new[] {1, 3, 5, 7, 9});
// var s2 = new SubArray<int>(new[] {0, 2, 4, 6, 8});
//
// Console.Out.WriteLine($"s1 = {s1}");
// Console.Out.WriteLine($"s2 = {s2}");
//
// var arr = SubArray<int>.Join(s1, s2);
//
// Console.Out.WriteLine($"arr = {string.Join(", ", arr)}");
// Console.Out.WriteLine($"s1 = {s1}");
// Console.Out.WriteLine($"s2 = {s2}");
//
// Console.ReadKey();
}
}
}

View File

@@ -14,12 +14,35 @@ namespace hexworld
{
public class HexRender : GameWindow
{
#region Fields
#region GLObjects
private Program _pgm;
private Texture _grass;
private Texture _stone;
private Texture _gray;
private GLBuffer _tileGLBuffer;
private GLBuffer _vertexGLBuffer;
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_pgm.Dispose();
// _tileGLBuffer.Dispose();
_vertexGLBuffer.Dispose();
_grass.Dispose();
_stone.Dispose();
_gray.Dispose();
}
#endregion
private Matrix4 _view;
private Matrix4 _proj;
@@ -34,11 +57,11 @@ namespace hexworld
private Tile[] _allTiles;
private Vertex[] _allVertices;
private GLBuffer _tileGLBuffer;
private GLBuffer _vertexGLBuffer;
private double _time;
#endregion
public HexRender(int width, int height)
: base(width, height, new GraphicsMode(32, 24, 0, 0))
{
@@ -52,8 +75,11 @@ namespace hexworld
{
base.OnLoad(e);
using (var vs = Shader.FromFile("s.vs.glsl", ShaderType.VertexShader))
using (var fs = Shader.FromFile("s.fs.glsl", ShaderType.FragmentShader))
var vsPath = @"res\s.vs.glsl";
var fsPath = @"res\s.fs.glsl";
using (var vs = Shader.FromFile(vsPath, ShaderType.VertexShader))
using (var fs = Shader.FromFile(fsPath, ShaderType.FragmentShader))
{
if (!vs.Compiled | !fs.Compiled)
{
@@ -75,18 +101,18 @@ namespace hexworld
}
_cubeVertices = new SubArray<Vertex>(
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText("data_vert_cubes.json")));
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText(@"res\data_vert_cubes.json")));
_panelVertices = new SubArray<Vertex>(
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText("data_vert_panels.json")));
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText(@"res\data_vert_panels.json")));
_sidesVertices = new SubArray<Vertex>(
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText("data_vert_sides.json")));
JsonConvert.DeserializeObject<Vertex[]>(File.ReadAllText(@"res\data_vert_sides.json")));
_grassTiles = new SubArray<Tile>(
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText("data_tile_grass.json")));
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText(@"res\data_tile_grass.json")));
_stoneTiles = new SubArray<Tile>(
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText("data_tile_stone.json")));
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText(@"res\data_tile_stone.json")));
_grayTiles = new SubArray<Tile>(
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText("data_tile_gray.json")));
JsonConvert.DeserializeObject<Tile[]>(File.ReadAllText(@"res\data_tile_gray.json")));
_allTiles = SubArray<Tile>.Join(_stoneTiles, _grassTiles, _grayTiles);
_allVertices = SubArray<Vertex>.Join(_panelVertices, _cubeVertices, _sidesVertices);
@@ -100,9 +126,9 @@ namespace hexworld
_pgm.SetAttribPointers(_tileGLBuffer, typeof(Tile));
_pgm.SetAttribPointers(_vertexGLBuffer, typeof(Vertex));
_grass = Texture.FromBitmap(new Bitmap("grass.png"));
_stone = Texture.FromBitmap(new Bitmap("stone.png"));
_gray = Texture.FromBitmap(new Bitmap("gray.png"));
_grass = Texture.FromBitmap(new Bitmap(@"res\grass.png"));
_stone = Texture.FromBitmap(new Bitmap(@"res\stone.png"));
_gray = Texture.FromBitmap(new Bitmap(@"res\gray.png"));
}
protected override void OnUpdateFrame(FrameEventArgs e)
@@ -111,7 +137,8 @@ namespace hexworld
_time += e.Time;
_view = Matrix4.CreateRotationZ((float) _time/3)*Matrix4.LookAt(10 * Vector3.One, Vector3.Zero, Vector3.UnitZ);
_view = Matrix4.CreateRotationZ((float) _time / 3) *
Matrix4.LookAt(10 * Vector3.One, Vector3.Zero, Vector3.UnitZ);
_proj = Matrix4.CreateOrthographic(Width / 100f, Height / 100f, -100, 100);
for (var i = 0; i < _grassTiles.Length; i++)
@@ -179,19 +206,5 @@ namespace hexworld
SwapBuffers();
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_pgm.Dispose();
_tileGLBuffer.Dispose();
_vertexGLBuffer.Dispose();
_grass.Dispose();
_stone.Dispose();
_gray.Dispose();
}
}
}

View File

@@ -59,41 +59,41 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="data_tile_gray.json">
<None Include="res\data_tile_gray.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="data_tile_stone.json">
<None Include="res\data_tile_stone.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="data_vert_sides.json">
<None Include="res\data_vert_sides.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="data_vert_panels.json">
<None Include="res\data_vert_panels.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="OpenTK.dll.config" />
<None Include="packages.config" />
<None Include="s.fs.glsl">
<None Include="res\s.fs.glsl">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="s.vs.glsl">
<None Include="res\s.vs.glsl">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="data_vert_cubes.json">
<None Include="res\data_vert_cubes.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="data_tile_grass.json">
<None Include="res\data_tile_grass.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include="grass.png">
<Content Include="res\grass.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="gray.png">
<Content Include="res\gray.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="stone.png">
<Content Include="res\stone.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

View File

Before

Width:  |  Height:  |  Size: 771 B

After

Width:  |  Height:  |  Size: 771 B

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 670 B

After

Width:  |  Height:  |  Size: 670 B