Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit 0cf4538

Browse files
committed
Cactus
+.tga files can be loaded by Texture.CreateTextureArray +grass block done +cactus done +water could be better, good enought for now. TODO: change texture to make it animated
1 parent 1b2df8a commit 0cf4538

File tree

13 files changed

+2921
-66
lines changed

13 files changed

+2921
-66
lines changed

BuildPlate_Editor.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<Compile Include="BuildPlateDimension.cs" />
8484
<Compile Include="BuildPlateOffset.cs" />
8585
<Compile Include="Camera.cs" />
86+
<Compile Include="EXITCODE.cs" />
8687
<Compile Include="GLGetVersion.cs" />
8788
<Compile Include="JsonBuildPlate.cs" />
8889
<Compile Include="Maths\Vector2i.cs" />
@@ -93,6 +94,7 @@
9394
<Compile Include="Shader.cs" />
9495
<Compile Include="SkyBox.cs" />
9596
<Compile Include="SubChunk.cs" />
97+
<Compile Include="TargaImage.cs" />
9698
<Compile Include="Texture.cs" />
9799
<Compile Include="Util.cs" />
98100
<Compile Include="Vertex.cs" />
@@ -131,7 +133,7 @@
131133
</ItemGroup>
132134
<ItemGroup>
133135
<Content Include="1051469223874011206.ico" />
134-
<Content Include="Data\Textures\Black.png">
136+
<Content Include="Data\Textures\Notfound.png">
135137
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
136138
</Content>
137139
<Content Include="Data\Textures\Skybox_0.png">

Data/Textures/Black.png

-141 Bytes
Binary file not shown.

Data/Textures/Notfound.png

155 Bytes
Loading

EXITCODE.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace BuildPlate_Editor
8+
{
9+
public enum EXITCODE : int
10+
{
11+
Normal = 0,
12+
OpenGL_LowVersion = 1,
13+
World_Load_TextureArray = 2,
14+
World_Render_Block = 3,
15+
World_Unknown = 4,
16+
}
17+
}

Palette.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ public Palette(string _name, int _data, int[] _textures)
2121

2222
public Palette(string _name, int _data, int _texture) : this(_name, _data, new int[1] { _texture })
2323
{ }
24+
25+
public override string ToString() => $"Name: {name}, Numb tex: {textures.Length}, Data: {data}";
2426
}
2527
}

Program.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Reflection;
88
using System.Runtime.ExceptionServices;
9+
using System.Runtime.InteropServices;
910
using System.Text;
1011
using System.Threading.Tasks;
1112
using SystemPlus;
@@ -19,6 +20,10 @@ class Program
1920

2021
static void Main(string[] args)
2122
{
23+
// this will run on console close
24+
handler = new ConsoleEventDelegate(ConsoleEventCallback);
25+
SetConsoleCtrlHandler(handler, true);
26+
2227
// Get base path (.exe location)
2328
string myExecutable = Assembly.GetEntryAssembly().Location;
2429

@@ -91,7 +96,8 @@ static void Main(string[] args)
9196
texturesPath += '/';
9297
World.textureBasePath = texturesPath;
9398
#if DEBUG
94-
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\70c9c5eb-580d-41d2-8201-2577fec29dd6.json";
99+
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json";
100+
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json"; // fancy
95101
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\2cb8bda2-c49b-4ead-887f-593d37bc2784.json";
96102
#else
97103
Console.Write("Build plate to edit (.json): ");
@@ -157,7 +163,21 @@ private static void LowVersion()
157163
Console.WriteLine("OpenGL version is low. The editor might not work correctly");
158164
Console.WriteLine("Press ENTER to continue anyway...");
159165
if (Console.ReadKey(true).Key != ConsoleKey.Enter)
160-
Environment.Exit(2);
166+
Util.Exit(EXITCODE.OpenGL_LowVersion);
167+
}
168+
169+
// Handle on close event
170+
static bool ConsoleEventCallback(int eventType)
171+
{
172+
if (eventType == 2) { // on exit
173+
Util.Exit(EXITCODE.Normal);
174+
}
175+
return false;
161176
}
177+
static ConsoleEventDelegate handler; // Keeps it from getting garbage collected
178+
179+
private delegate bool ConsoleEventDelegate(int eventType);
180+
[DllImport("kernel32.dll", SetLastError = true)]
181+
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
162182
}
163183
}

SubChunk.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,20 @@ public void CreateMeshData()
7171

7272
int renderer = renderers[currentBlock];
7373
if (renderer > -1 && blocks[currentBlock] < palette.Length) { // don't render air
74-
Palette pal = palette[blocks[currentBlock]];
74+
#if DEBUG
75+
uint blockId = blocks[currentBlock];
76+
Palette pal = palette[blockId];
7577
World.blockRenderers[renderer](new Vector3(x, y, z), pos * 16, pal.textures, pal.data,
7678
ref vertices, ref triangles);
79+
#else
80+
try {
81+
Palette pal = palette[blocks[currentBlock]];
82+
World.blockRenderers[renderer](new Vector3(x, y, z), pos * 16, pal.textures, pal.data,
83+
ref vertices, ref triangles);
84+
} catch (Exception ex) {
85+
Util.Exit(EXITCODE.World_Render_Block, ex, $"Block ID: {blocks[currentBlock]}, SubChunk pos: {pos}, Renderer ID: {renderer}");
86+
}
87+
#endif
7788
}
7889

7990
z = origz;
@@ -165,5 +176,46 @@ public int GetRenderer(int X, int Y, int Z)
165176

166177
public int GetRenderer(Vector3i pos)
167178
=> GetRenderer(pos.X, pos.Y, pos.Z);
179+
180+
public void GetBlockIndex(int bx, int by, int bz, out int blockIndex)
181+
{
182+
Vector3i block = new Vector3i(bx, by, bz);
183+
184+
int x = 0;
185+
int y = 0;
186+
int z = 0;
187+
int origx;
188+
int origy;
189+
int origz;
190+
Vector3i offset = new Vector3i(pos.X * VoxelData.ChunkWidth, pos.Y * VoxelData.ChunkHeight, pos.Z * VoxelData.ChunkWidth);
191+
192+
for (int currentBlock = 0; currentBlock < blocks.Length; currentBlock++) {
193+
z++;
194+
if (z == 16) { z = 0; y += 1; }
195+
if (y == 16) { y = 0; x += 1; }
196+
197+
origz = z;
198+
origy = y;
199+
200+
if (z == 0) {
201+
z = 16;
202+
y -= 1;
203+
}
204+
205+
if (y == -1)
206+
y = 16;
207+
208+
if (new Vector3i(x, y, z) + offset == block) {
209+
blockIndex = currentBlock;
210+
return;
211+
}
212+
213+
214+
z = origz;
215+
y = origy;
216+
}
217+
218+
blockIndex = -1;
219+
}
168220
}
169221
}

0 commit comments

Comments
 (0)