Fix some bugs, remove some debug output.

This commit is contained in:
IntegratedQuantum 2022-09-15 20:30:55 +02:00
parent faa018093f
commit d532848262
8 changed files with 22 additions and 27 deletions

View File

@ -27,12 +27,11 @@ pub fn readAllJsonFilesInAddons(externalAllocator: Allocator, addons: std.ArrayL
while(try walker.next()) |entry| {
if(entry.kind == .File and std.ascii.endsWithIgnoreCase(entry.basename, ".json")) {
const folderName = addonNames.items[addonIndex];
var id: []u8 = try externalAllocator.alloc(u8, folderName.len + 1 + entry.basename.len - 5);
var id: []u8 = try externalAllocator.alloc(u8, folderName.len + 1 + entry.path.len - 5);
std.mem.copy(u8, id[0..], folderName);
id[folderName.len] = ':';
std.mem.copy(u8, id[folderName.len+1..], entry.basename[0..entry.basename.len-5]);
std.mem.copy(u8, id[folderName.len+1..], entry.path[0..entry.path.len-5]);
std.log.info("ID: {s}", .{id});
var file = try dir.dir.openFile(entry.path, .{});
defer file.close();
const string = try file.readToEndAlloc(main.threadAllocator, std.math.maxInt(usize));
@ -168,7 +167,7 @@ pub const BlockPalette = struct {
}
pub fn add(self: *BlockPalette, id: []const u8) !void {
try self.palette.append(id);
try self.palette.append(try self.palette.allocator.dupe(u8, id));
}
pub fn save(self: *BlockPalette, allocator: Allocator) !JsonElement {
@ -210,7 +209,7 @@ pub fn loadWorldAssets(assetFolder: []const u8, palette: *BlockPalette) !void {
var iterator = blocks.iterator();
while(iterator.next()) |entry| {
try registerBlock(assetFolder, entry.key_ptr.*, entry.value_ptr.*);
try palette.palette.append(entry.key_ptr.*);
try palette.add(entry.key_ptr.*);
block += 1;
}

View File

@ -318,7 +318,7 @@ pub const meshes = struct {
const textures = textureInfo.getChild("textures");
if(textures != .JsonArray) return result;
// Add the new textures into the list. Since this is an animation all textures that weren't found need to be replaced with undefined.
result = @intCast(u31, textures.JsonArray.items.len);
result = @intCast(u31, blockTextures.items.len);
for(textures.JsonArray.items) |item, i| {
if(i == 0) {
try animationFrames.append(@intCast(u32, textures.JsonArray.items.len));

View File

@ -494,16 +494,16 @@ pub const meshing = struct {
modelPosition: c_int,
ambientLight: c_int,
directionalLight: c_int,
fog_activ: c_int,
fog_color: c_int,
fog_density: c_int,
@"fog.activ": c_int,
@"fog.color": c_int,
@"fog.density": c_int,
lowerBounds: c_int,
upperBounds: c_int,
texture_sampler: c_int,
emissionSampler: c_int,
waterFog_activ: c_int,
waterFog_color: c_int,
waterFog_density: c_int,
@"waterFog.activ": c_int,
@"waterFog.color": c_int,
@"waterFog.density": c_int,
time: c_int,
} = undefined;
var vao: c_uint = undefined;
@ -541,9 +541,9 @@ pub const meshing = struct {
pub fn bindShaderAndUniforms(projMatrix: Mat4f, ambient: Vec3f, directional: Vec3f, time: u32) void {
shader.bind();
c.glUniform1i(uniforms.fog_activ, if(game.fog.active) 1 else 0);
c.glUniform3fv(uniforms.fog_color, 1, @ptrCast([*c]f32, &game.fog.color));
c.glUniform1f(uniforms.fog_density, game.fog.density);
c.glUniform1i(uniforms.@"fog.activ", if(game.fog.active) 1 else 0);
c.glUniform3fv(uniforms.@"fog.color", 1, @ptrCast([*c]f32, &game.fog.color));
c.glUniform1f(uniforms.@"fog.density", game.fog.density);
c.glUniformMatrix4fv(uniforms.projectionMatrix, 1, c.GL_FALSE, @ptrCast([*c]f32, &projMatrix));

View File

@ -38,4 +38,4 @@ pub var world: ?*World = &testWorld;
pub var projectionMatrix: Mat4f = Mat4f.identity();
pub var lodProjectionMatrix: Mat4f = Mat4f.identity();
pub var fog = Fog{.active = true, .color=.{.x=0.5, .y=0.5, .z=0.5}, .density=0.025};
pub var fog = Fog{.active = true, .color=.{.x=0, .y=1, .z=0.5}, .density=1.0/15.0/256.0};

View File

@ -582,9 +582,7 @@ pub const Image = struct {
const data = stb_image.stbi_load(nullTerminatedPath.ptr, @ptrCast([*c]c_int, &result.width), @ptrCast([*c]c_int, &result.height), &channel, 4) orelse {
return error.FileNotFound;
};
std.log.info("Image sample direct: {} {} {} {}", .{data[0], data[1], data[2], data[3]});
result.imageData = try allocator.dupe(Color, @ptrCast([*]Color, data)[0..result.width*result.height]);
std.log.info("Image sample: {} {} {} {}", .{result.imageData[0].r, result.imageData[0].g, result.imageData[0].b, result.imageData[0].a});
stb_image.stbi_image_free(data);
return result;
}

View File

@ -171,15 +171,15 @@ pub fn main() !void {
network.init();
try renderer.RenderOctree.init();
defer renderer.RenderOctree.deinit();
var conn = try network.ConnectionManager.init(12347, true);
defer conn.deinit();
var conn2 = try network.Connection.init(conn, "127.0.0.1");
defer conn2.deinit();
try renderer.RenderOctree.init();
defer renderer.RenderOctree.deinit();
try network.Protocols.handShake.clientSide(conn2, "quanturmdoelvloper");
try assets.loadWorldAssets("serverAssets", game.blockPalette);
@ -189,6 +189,7 @@ pub fn main() !void {
c.glCullFace(c.GL_BACK);
c.glEnable(c.GL_BLEND);
c.glBlendFunc(c.GL_SRC_ALPHA, c.GL_ONE_MINUS_SRC_ALPHA);
Window.GLFWCallbacks.framebufferSize(null, Window.width, Window.height);
while(c.glfwWindowShouldClose(Window.window) == 0) {
{ // Check opengl errors:

View File

@ -675,7 +675,6 @@ pub const Protocols = blk: {
std.mem.writeIntBig(chunk.ChunkCoordinate, remaining[4..8], req.wy);
std.mem.writeIntBig(chunk.ChunkCoordinate, remaining[8..12], req.wz);
std.mem.writeIntBig(chunk.ChunkCoordinate, remaining[12..16], req.voxelSize);
std.log.info("Requested some chunk: {}", .{req.voxelSize});
remaining = remaining[16..];
}
try conn.sendImportant(id, data);

View File

@ -261,9 +261,9 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, directionalLight: Vec3f,
// Render the far away ReducedChunks:
c.glDepthRangef(0.05, 1.0); // Used to fix z-fighting.
chunk.meshing.bindShaderAndUniforms(game.projectionMatrix, ambientLight, directionalLight, time);
c.glUniform1i(chunk.meshing.uniforms.waterFog_activ, if(waterFog.active) 1 else 0);
c.glUniform3fv(chunk.meshing.uniforms.waterFog_color, 1, @ptrCast([*c]f32, &waterFog.color));
c.glUniform1f(chunk.meshing.uniforms.waterFog_density, waterFog.density);
c.glUniform1i(chunk.meshing.uniforms.@"waterFog.activ", if(waterFog.active) 1 else 0);
c.glUniform3fv(chunk.meshing.uniforms.@"waterFog.color", 1, @ptrCast([*c]f32, &waterFog.color));
c.glUniform1f(chunk.meshing.uniforms.@"waterFog.density", waterFog.density);
for(meshes.items) |mesh| {
mesh.render(playerPos);
@ -618,7 +618,6 @@ pub const RenderOctree = struct {
var meshRequests = std.ArrayList(chunk.ChunkPosition).init(main.threadAllocator);
defer meshRequests.deinit();
var x = minX;
std.log.info("In the thing to request:{} {}", .{minX, maxX});
while(x <= maxX): (x += LODSize) {
var maxYRenderDistanceSquare = @intToFloat(f32, maxRenderDistance)*@intToFloat(f32, maxRenderDistance) - @intToFloat(f32, (x - px))*@intToFloat(f32, (x - px));
if(maxYRenderDistanceSquare < 0) continue;
@ -714,7 +713,6 @@ pub const RenderOctree = struct {
mutex.lock();
defer mutex.unlock();
while(updatableList.items.len != 0) {
std.log.info("Generating mesh.", .{});
const mesh = updatableList.pop();
const nullNode = findNode(mesh.pos);
if(nullNode) |node| {