Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDavies8 committed Sep 19, 2024
2 parents acf5003 + d27029e commit fff7445
Show file tree
Hide file tree
Showing 53 changed files with 490 additions and 569 deletions.
2 changes: 1 addition & 1 deletion .zig-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.0
0.14.0-dev.1550+4fba7336a
46 changes: 46 additions & 0 deletions assets/cubyz/biomes/cave/void_roots.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"isCave" : true,
"maxHeight" : -50000,

"fogDensity" : 2,
"chance" : 100,
"caveRadiusFactor" : -1,
"caves" : 0.5,

"music" : "cubyz:heart-of-the-beast",



"structures" : [
{
"id" : "cubyz:ground_patch",
"block" : "cubyz:gravel",
"chance" : 0.064,
"width" : 5,
"variation" : 5,
"depth" : 3,
"smoothness" : 0.1
}
{
"id" : "cubyz:stalagmite",
"block" : "cubyz:stone",
"chance" : 0.048,
"size" : 3,
"size_variation" : 6
},
{
"id" : "cubyz:boulder",
"chance" : 0.016,
"block" : "cubyz:cobblestone",
"size" : 4,
"size_variance" : 3
},
{
"id" : "cubyz:boulder",
"chance" : 0.016,
"block" : "cubyz:stone",
"size" : 4,
"size_variance" : 4
}
]
}
4 changes: 4 additions & 0 deletions assets/cubyz/blocks/textures/lava.png_textureInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"fogDensity" : 0.7,
"fogColor" : 0xff9000,
}
2 changes: 1 addition & 1 deletion debug_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if [[ "$CURRENT_VERSION" != "$VERSION" ]]; then
rm -r compiler/zig
mkdir compiler/zig
echo "Downloading $VERSION..."
wget -O compiler/archive.tar.xz https://ziglang.org/builds/"$VERSION".tar.xz
wget -O compiler/archive.tar.xz https://github.com/PixelGuys/Cubyz-zig-versions/releases/download/$BASE_VERSION/"$VERSION".tar.xz
if [ $? != 0 ]
then
echo "Failed to download the Zig compiler."
Expand Down
2 changes: 1 addition & 1 deletion debug_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if not "%version%" == "%currVersion%" (
echo Deleting current Zig installation ...
if exist compiler\zig rmdir /s /q compiler\zig
echo Downloading %version% ...
powershell -Command $ProgressPreference = 'SilentlyContinue'; "Invoke-WebRequest -uri https://ziglang.org/builds/%version%.zip -OutFile compiler\archive.zip"
powershell -Command $ProgressPreference = 'SilentlyContinue'; "Invoke-WebRequest -uri https://github.com/PixelGuys/Cubyz-zig-versions/releases/download/%baseVersion%/%version%.zip -OutFile compiler\archive.zip"
if errorlevel 1 (
echo Failed to download the Zig compiler.
exit /b 1
Expand Down
14 changes: 7 additions & 7 deletions src/assets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ pub fn readAssets(externalAllocator: NeverFailingAllocator, assetPath: []const u
pub fn init() void {
biomes_zig.init();
blocks_zig.init();
arena = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator);
arena = .init(main.globalAllocator);
arenaAllocator = arena.allocator();
commonBlocks = std.StringHashMap(JsonElement).init(arenaAllocator.allocator);
commonItems = std.StringHashMap(JsonElement).init(arenaAllocator.allocator);
commonBiomes = std.StringHashMap(JsonElement).init(arenaAllocator.allocator);
commonRecipes = main.List([]const u8).init(arenaAllocator);
commonModels = std.StringHashMap([]const u8).init(arenaAllocator.allocator);
commonBlocks = .init(arenaAllocator.allocator);
commonItems = .init(arenaAllocator.allocator);
commonBiomes = .init(arenaAllocator.allocator);
commonRecipes = .init(arenaAllocator);
commonModels = .init(arenaAllocator.allocator);

readAssets(arenaAllocator, "assets/", &commonBlocks, &commonItems, &commonBiomes, &commonRecipes, &commonModels);
}
Expand Down Expand Up @@ -218,7 +218,7 @@ pub const Palette = struct { // MARK: Palette
pub fn init(allocator: NeverFailingAllocator, json: JsonElement, firstElement: ?[]const u8) !*Palette {
const self = allocator.create(Palette);
self.* = Palette {
.palette = main.List([]const u8).init(allocator),
.palette = .init(allocator),
};
errdefer self.deinit();
if(json != .JsonObject or json.JsonObject.count() == 0) {
Expand Down
28 changes: 14 additions & 14 deletions src/blocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ var reverseIndices = std.StringHashMap(u16).init(allocator.allocator);

var size: u32 = 0;

pub var ores: main.List(Ore) = main.List(Ore).init(allocator);
pub var ores: main.List(Ore) = .init(allocator);

var unfinishedOreSourceBlockIds: main.List([][]const u8) = undefined;

pub fn init() void {
unfinishedOreSourceBlockIds = main.List([][]const u8).init(main.globalAllocator);
unfinishedOreSourceBlockIds = .init(main.globalAllocator);
}

pub fn deinit() void {
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn reset() void {
ores.clearAndFree();
meshes.reset();
_ = arena.reset(.free_all);
reverseIndices = std.StringHashMap(u16).init(arena.allocator().allocator);
reverseIndices = .init(arena.allocator().allocator);
std.debug.assert(unfinishedOreSourceBlockIds.items.len == 0);
}

Expand Down Expand Up @@ -394,17 +394,17 @@ pub const meshes = struct { // MARK: meshes

pub fn init() void {
animationShader = Shader.initComputeAndGetUniforms("assets/cubyz/shaders/animation_pre_processing.glsl", "", &animationUniforms);
blockTextureArray = TextureArray.init();
emissionTextureArray = TextureArray.init();
reflectivityAndAbsorptionTextureArray = TextureArray.init();
textureIDs = main.List([]const u8).init(main.globalAllocator);
animation = main.List(AnimationData).init(main.globalAllocator);
blockTextures = main.List(Image).init(main.globalAllocator);
emissionTextures = main.List(Image).init(main.globalAllocator);
reflectivityTextures = main.List(Image).init(main.globalAllocator);
absorptionTextures = main.List(Image).init(main.globalAllocator);
textureFogData = main.List(FogData).init(main.globalAllocator);
arenaForWorld = main.utils.NeverFailingArenaAllocator.init(main.globalAllocator);
blockTextureArray = .init();
emissionTextureArray = .init();
reflectivityAndAbsorptionTextureArray = .init();
textureIDs = .init(main.globalAllocator);
animation = .init(main.globalAllocator);
blockTextures = .init(main.globalAllocator);
emissionTextures = .init(main.globalAllocator);
reflectivityTextures = .init(main.globalAllocator);
absorptionTextures = .init(main.globalAllocator);
textureFogData = .init(main.globalAllocator);
arenaForWorld = .init(main.globalAllocator);
}

pub fn deinit() void {
Expand Down
10 changes: 5 additions & 5 deletions src/chunk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ var serverPool: std.heap.MemoryPoolAligned(ServerChunk, @alignOf(ServerChunk)) =
var serverPoolMutex: std.Thread.Mutex = .{};

pub fn init() void {
memoryPool = std.heap.MemoryPoolAligned(Chunk, @alignOf(Chunk)).init(main.globalAllocator.allocator);
serverPool = std.heap.MemoryPoolAligned(ServerChunk, @alignOf(ServerChunk)).init(main.globalAllocator.allocator);
memoryPool = .init(main.globalAllocator.allocator);
serverPool = .init(main.globalAllocator.allocator);
}

pub fn deinit() void {
Expand All @@ -151,14 +151,14 @@ pub const ChunkPosition = struct { // MARK: ChunkPosition
}

pub fn equals(self: ChunkPosition, other: anytype) bool {
if(@typeInfo(@TypeOf(other)) == .Optional) {
if(@typeInfo(@TypeOf(other)) == .optional) {
if(other) |notNull| {
return self.equals(notNull);
}
return false;
} else if(@TypeOf(other.*) == ServerChunk) {
return self.wx == other.super.pos.wx and self.wy == other.super.pos.wy and self.wz == other.super.pos.wz and self.voxelSize == other.super.pos.voxelSize;
} else if(@typeInfo(@TypeOf(other)) == .Pointer) {
} else if(@typeInfo(@TypeOf(other)) == .pointer) {
return self.wx == other.pos.wx and self.wy == other.pos.wy and self.wz == other.pos.wz and self.voxelSize == other.pos.voxelSize;
} else @compileError("Unsupported");
}
Expand Down Expand Up @@ -281,7 +281,7 @@ pub const ServerChunk = struct { // MARK: ServerChunk
.voxelSizeMask = pos.voxelSize - 1,
.widthShift = voxelSizeShift + chunkShift,
},
.refCount = std.atomic.Value(u16).init(1),
.refCount = .init(1),
};
self.super.data.init();
return self;
Expand Down
2 changes: 1 addition & 1 deletion src/entity.zig
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub const ClientEntityManager = struct {
pub var mutex: std.Thread.Mutex = std.Thread.Mutex{};

pub fn init() void {
entities = main.VirtualList(ClientEntity, 1 << 20).init();
entities = .init();
shader = graphics.Shader.initAndGetUniforms("assets/cubyz/shaders/entity_vertex.vs", "assets/cubyz/shaders/entity_fragment.fs", "", &uniforms);
}

Expand Down
60 changes: 30 additions & 30 deletions src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,18 @@ pub const collision = struct {
};

pub const Player = struct { // MARK: Player
pub var super: main.server.Entity = .{};
pub var eyePos: Vec3d = .{ 0, 0, 0 };
pub var eyeVel: Vec3d = .{ 0, 0, 0 };
pub var eyeCoyote: f64 = 0;
pub var eyeStep: @Vector(3, bool) = .{ false, false, false };
pub var id: u32 = 0;
pub var isFlying: Atomic(bool) = Atomic(bool).init(false);
pub var isGhost: Atomic(bool) = Atomic(bool).init(false);
pub var hyperSpeed: Atomic(bool) = Atomic(bool).init(false);
pub var mutex: std.Thread.Mutex = std.Thread.Mutex{};
pub var inventory__SEND_CHANGES_TO_SERVER: Inventory = undefined;
pub var selectedSlot: u32 = 0;
pub var super: main.server.Entity = .{};
pub var eyePos: Vec3d = .{0, 0, 0};
pub var eyeVel: Vec3d = .{0, 0, 0};
pub var eyeCoyote: f64 = 0;
pub var eyeStep: @Vector(3, bool) = .{false, false, false};
pub var id: u32 = 0;
pub var isFlying: Atomic(bool) = .init(false);
pub var isGhost: Atomic(bool) = .init(false);
pub var hyperSpeed: Atomic(bool) = .init(false);
pub var mutex: std.Thread.Mutex = std.Thread.Mutex{};
pub var inventory__SEND_CHANGES_TO_SERVER: Inventory = undefined;
pub var selectedSlot: u32 = 0;

pub var maxHealth: f32 = 8;
pub var health: f32 = 4.5;
Expand Down Expand Up @@ -447,19 +447,19 @@ pub const Player = struct { // MARK: Player
pub const World = struct { // MARK: World
const dayCycle: u63 = 12000; // Length of one in-game day in 100ms. Midnight is at DAY_CYCLE/2. Sunrise and sunset each take about 1/16 of the day. Currently set to 20 minutes

conn: *Connection,
manager: *ConnectionManager,
ambientLight: f32 = 0,
clearColor: Vec4f = Vec4f{ 0, 0, 0, 1 },
gravity: f64 = 9.81 * 1.5, // TODO: Balance
name: []const u8,
milliTime: i64,
gameTime: Atomic(i64) = Atomic(i64).init(0),
spawn: Vec3f = undefined,
blockPalette: *assets.Palette = undefined,
biomePalette: *assets.Palette = undefined,
itemDrops: ClientItemDropManager = undefined,
playerBiome: Atomic(*const main.server.terrain.biomes.Biome) = undefined,
conn: *Connection,
manager: *ConnectionManager,
ambientLight: f32 = 0,
clearColor: Vec4f = Vec4f{0, 0, 0, 1},
gravity: f64 = 9.81*1.5, // TODO: Balance
name: []const u8,
milliTime: i64,
gameTime: Atomic(i64) = .init(0),
spawn: Vec3f = undefined,
blockPalette: *assets.Palette = undefined,
biomePalette: *assets.Palette = undefined,
itemDrops: ClientItemDropManager = undefined,
playerBiome: Atomic(*const main.server.terrain.biomes.Biome) = undefined,

pub fn init(self: *World, ip: []const u8, manager: *ConnectionManager) !void {
self.* = .{
Expand All @@ -474,11 +474,11 @@ pub const World = struct { // MARK: World

main.Window.setMouseGrabbed(true);

main.blocks.meshes.generateTextureArray();
main.models.uploadModels();
self.playerBiome = Atomic(*const main.server.terrain.biomes.Biome).init(main.server.terrain.biomes.getById(""));
main.audio.setMusic(self.playerBiome.raw.preferredMusic);
}
main.blocks.meshes.generateTextureArray();
main.models.uploadModels();
self.playerBiome = .init(main.server.terrain.biomes.getById(""));
main.audio.setMusic(self.playerBiome.raw.preferredMusic);
}

pub fn deinit(self: *World) void {
// TODO: Close all world related guis.
Expand Down
26 changes: 13 additions & 13 deletions src/graphics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,16 @@ pub const TextBuffer = struct { // MARK: TextBuffer
var parser = Parser {
.unicodeIterator = std.unicode.Utf8Iterator{.bytes = text, .i = 0},
.currentFontEffect = initialFontEffect,
.parsedText = main.List(u32).init(main.stackAllocator),
.fontEffects = main.List(FontEffect).init(allocator),
.characterIndex = main.List(u32).init(allocator),
.parsedText = .init(main.stackAllocator),
.fontEffects = .init(allocator),
.characterIndex = .init(allocator),
.showControlCharacters = showControlCharacters
};
defer parser.fontEffects.deinit();
defer parser.parsedText.deinit();
defer parser.characterIndex.deinit();
self.lines = main.List(Line).init(allocator);
self.lineBreaks = main.List(LineBreak).init(allocator);
self.lines = .init(allocator);
self.lineBreaks = .init(allocator);
parser.parse();
if(parser.parsedText.items.len == 0) {
self.lineBreaks.append(.{.index = 0, .width = 0});
Expand Down Expand Up @@ -1027,8 +1027,8 @@ const TextRendering = struct { // MARK: TextRendering
harfbuzzFace = hbft.hb_ft_face_create_referenced(freetypeFace);
harfbuzzFont = hbft.hb_font_create(harfbuzzFace);

glyphMapping = main.List(u31).init(main.globalAllocator);
glyphData = main.List(Glyph).init(main.globalAllocator);
glyphMapping = .init(main.globalAllocator);
glyphData = .init(main.globalAllocator);
glyphData.append(undefined); // 0 is a reserved value.
c.glGenTextures(2, &glyphTexture);
c.glBindTexture(c.GL_TEXTURE_2D, glyphTexture[0]);
Expand Down Expand Up @@ -1220,7 +1220,7 @@ pub const Shader = struct { // MARK: Shader

pub fn initAndGetUniforms(vertex: []const u8, fragment: []const u8, defines: []const u8, ptrToUniformStruct: anytype) Shader {
const self = Shader.init(vertex, fragment, defines);
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).Struct.fields) |field| {
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).@"struct".fields) |field| {
if(field.type == c_int) {
@field(ptrToUniformStruct, field.name) = c.glGetUniformLocation(self.id, field.name[0..]);
}
Expand All @@ -1237,7 +1237,7 @@ pub const Shader = struct { // MARK: Shader

pub fn initComputeAndGetUniforms(compute: []const u8, defines: []const u8, ptrToUniformStruct: anytype) Shader {
const self = Shader.initCompute(compute, defines);
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).Struct.fields) |field| {
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).@"struct".fields) |field| {
if(field.type == c_int) {
@field(ptrToUniformStruct, field.name) = c.glGetUniformLocation(self.id, field.name[0..]);
}
Expand Down Expand Up @@ -1319,7 +1319,7 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer
const Self = @This();

fn createBuffer(self: *Self, size: u31) void {
self.ssbo = SSBO.init();
self.ssbo = .init();
c.glBindBuffer(c.GL_SHADER_STORAGE_BUFFER, self.ssbo.bufferID);
const flags = c.GL_MAP_WRITE_BIT | c.GL_DYNAMIC_STORAGE_BIT;
const bytes = @as(c.GLsizeiptr, size)*@sizeOf(Entry);
Expand All @@ -1336,10 +1336,10 @@ pub fn LargeBuffer(comptime Entry: type) type { // MARK: LargerBuffer
fence.* = c.glFenceSync(c.GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
}
for(&self.fencedFreeLists) |*list| {
list.* = main.List(SubAllocation).init(allocator);
list.* = .init(allocator);
}

self.freeBlocks = main.List(SubAllocation).init(allocator);
self.freeBlocks = .init(allocator);
self.freeBlocks.append(.{.start = 0, .len = size});
}

Expand Down Expand Up @@ -1935,7 +1935,7 @@ const block_texture = struct { // MARK: block_texture

fn init() void {
shader = Shader.initAndGetUniforms("assets/cubyz/shaders/item_texture_post.vs", "assets/cubyz/shaders/item_texture_post.fs", "", &uniforms);
depthTexture = Texture.init();
depthTexture = .init();
depthTexture.bind();
var data: [128*128]f32 = undefined;

Expand Down
Loading

0 comments on commit fff7445

Please sign in to comment.