Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
020422b
Assets.
tillpp Mar 6, 2026
37adbae
removed material
tillpp Mar 6, 2026
a8fba76
added Templates for entity component and entity systems
tillpp Mar 6, 2026
61e9795
Entity registers and unregisters from entityComponents,
tillpp Mar 6, 2026
acc5c1b
have general Base64 classes and functions
tillpp Mar 6, 2026
9a3e70e
EntityComponentUpdate Protocol
tillpp Mar 6, 2026
bafca57
load EntityTypes from Assets
tillpp Mar 6, 2026
93bd094
made player a function
tillpp Mar 6, 2026
5fbf9ba
removed loadWorldAsset function
tillpp Mar 6, 2026
c2e7539
Merge remote-tracking branch 'origin/ECS_PlayerIsAFunction'
tillpp Mar 6, 2026
8f3bd44
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 6, 2026
0a32373
Merge remote-tracking branch 'origin/ECS_EntityTypeLoadingFromAsset' …
tillpp Mar 6, 2026
0fe9857
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 6, 2026
60254d9
Merge remote-tracking branch 'origin/ECS_Template' into ECS_United7
tillpp Mar 6, 2026
a912431
Merge remote-tracking branch 'origin/ECS_Template' into ECS_ServerEnt…
tillpp Mar 6, 2026
9af0011
Merge remote-tracking branch 'origin/ECS_Template' into ECS_Protocol
tillpp Mar 6, 2026
2dbc78e
Merge remote-tracking branch 'origin/ECS_Template' into ECS_EntityTyp…
tillpp Mar 6, 2026
1e04fa3
removed loadWorldAssets
tillpp Mar 6, 2026
ac18860
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 6, 2026
1b44749
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 6, 2026
baae55c
Merge remote-tracking branch 'origin/ECS_EntityTypeLoadingFromAsset' …
tillpp Mar 6, 2026
033c645
entityModel
tillpp Mar 6, 2026
3932133
added entityModelComponent
tillpp Mar 6, 2026
927849b
temporary Deinits
tillpp Mar 7, 2026
c962389
Merge remote-tracking branch 'origin/ECS_ServerEntityLoadsComponents'…
tillpp Mar 7, 2026
87b048a
fmt
tillpp Mar 7, 2026
82a8004
Merge remote-tracking branch 'origin/ECS_Protocol' into ECS_United7
tillpp Mar 7, 2026
c58f1e5
Merge remote-tracking branch 'origin/ECS_United7' into ECS_AddEntityM…
tillpp Mar 7, 2026
9fa8825
Merge remote-tracking branch 'origin/ECS_United7' into ECS_AddEntityM…
tillpp Mar 7, 2026
aadf9e8
fmt
tillpp Mar 7, 2026
74608ef
fmt
tillpp Mar 7, 2026
253f1b7
make merging easier
tillpp Apr 4, 2026
fa854b4
more simplification
tillpp Apr 4, 2026
c44644b
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 4, 2026
34a7c31
bringing more inline
tillpp Apr 4, 2026
7eb07c7
less
tillpp Apr 4, 2026
1fd28a9
fmt
tillpp Apr 4, 2026
8407584
fmt
tillpp Apr 4, 2026
31fe8e9
fmt
tillpp Apr 4, 2026
ae685f5
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 5, 2026
9e4e6a6
tmp rename
tillpp Apr 5, 2026
381e458
Merge branch 'master' into ECS_AddEntityModel
tillpp Apr 5, 2026
b7d0a68
merged
tillpp Apr 5, 2026
bc6e275
itemDrop not needed as component
tillpp Apr 5, 2026
42fd688
.
tillpp Apr 5, 2026
2768938
.
tillpp Apr 5, 2026
8a1e849
.
tillpp Apr 5, 2026
8e80725
.
tillpp Apr 5, 2026
807d8b8
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 5, 2026
084543a
merge...
tillpp Apr 5, 2026
30c0996
.
tillpp Apr 5, 2026
41181f3
.
tillpp Apr 5, 2026
0081ea5
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 5, 2026
d007e7c
Model split
tillpp Apr 5, 2026
8581157
a solution to make @ranPix happy
tillpp Apr 5, 2026
9ff6aaa
comments
tillpp Apr 5, 2026
1ed66b6
Each descriptor has a model
tillpp Apr 6, 2026
0403d13
removed rawEntityModelData
tillpp Apr 6, 2026
3039d14
fmt
tillpp Apr 6, 2026
8a5db6e
descriptions is a better name then descriptor
tillpp Apr 6, 2026
e18f348
make it easier for #2762 to use glb files instead of obj
tillpp Apr 6, 2026
0fecebb
the .obj/.glb files are to heavy to be kept in memory. Remove them af…
tillpp Apr 6, 2026
03cdfeb
fmt
tillpp Apr 7, 2026
51553d7
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 7, 2026
84654ee
merge fixed; Quantum really needs to hire a second PR reviewer - he i…
tillpp Apr 7, 2026
e6f4f97
Merge branch 'PixelGuys:master' into ECS_AddEntityModelComponent
tillpp Apr 8, 2026
20740ca
Quantums request changes for assets.zig
tillpp Apr 10, 2026
8bb00a0
use append and renamed functions
tillpp Apr 10, 2026
b0246c4
most of Quantums changed for entityModel.zig
tillpp Apr 10, 2026
9de1ab1
add entity model palette
tillpp Apr 10, 2026
6bd6680
used worldArena
tillpp Apr 10, 2026
b1d3059
forgot to remove temporary debug thing
tillpp Apr 10, 2026
00836e6
Merge branch 'PixelGuys:master' into ECS_AddEntityModel
tillpp Apr 10, 2026
d42c17c
Merge branch 'PixelGuys:master' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
8e34363
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
09c4c26
typo
tillpp Apr 10, 2026
5247f07
missed a entryValue
tillpp Apr 10, 2026
5aa0ddc
Merge branch 'ECS_AddEntityModel' of https://github.com/tillpp/Cubzio…
tillpp Apr 10, 2026
23156fe
fmt
tillpp Apr 10, 2026
da2175f
Wunka told me to use main.files
tillpp Apr 10, 2026
14a7e6f
fix crash
tillpp Apr 10, 2026
abe9640
fmt
tillpp Apr 10, 2026
232b581
temporary loadfunction moved somewhere else
tillpp Apr 10, 2026
5ac7159
invalid boolean
tillpp Apr 10, 2026
fa6ba84
renamed invalid to isLoaded
tillpp Apr 10, 2026
3cd9f82
fmt
tillpp Apr 10, 2026
aa4a56d
fmt
tillpp Apr 10, 2026
37e3fe2
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 10, 2026
66aa25e
fmt
tillpp Apr 10, 2026
8f9b624
name it worldAssetFolder
tillpp Apr 11, 2026
aae144c
allocations can't fail
tillpp Apr 11, 2026
6061302
You are using mismatched allocators in both paths.
tillpp Apr 11, 2026
ef98a78
removed deinitModelAndTexture
tillpp Apr 11, 2026
f17d3eb
nitpicking
tillpp Apr 11, 2026
b253c93
asserted here and the incorrect data (index < len) should be handled …
tillpp Apr 11, 2026
b3b5fc8
"loadModelsAndTexture"
tillpp Apr 11, 2026
84caf1a
We know the per world asset folder locally, you can also make it priv…
tillpp Apr 11, 2026
677638f
Idea, that me and MNHS came up with. to declare the entityModel as fa…
tillpp Apr 11, 2026
22ea1a5
revert change into descriptions
tillpp Apr 11, 2026
a7caab8
asset removed descriptions folder
tillpp Apr 11, 2026
ccd4650
reverted removing "model" attr from entityModel
tillpp Apr 11, 2026
f877fef
Merge branch 'ECS_AddEntityModel' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
2e2a126
playerEntityModels as worldsetting
tillpp Apr 11, 2026
096eb57
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
e47eb77
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
601b319
Merge branch 'master' into ECS_AddEntityModelComponent
tillpp Apr 11, 2026
6f21573
merge artefact
tillpp Apr 11, 2026
46b2697
reverted chages
tillpp Apr 11, 2026
a43766b
revert changes 2
tillpp Apr 11, 2026
885dfac
more clean
tillpp Apr 11, 2026
bd5d699
fmt
tillpp Apr 11, 2026
05576eb
comment moved
tillpp Apr 12, 2026
5379fe5
preparation
tillpp Apr 12, 2026
a6a15c7
Merge branch 'ECS_AddEntityModelComponent' into PVP
tillpp Apr 12, 2026
2fa15a1
Merge branch 'ECS_AddEntityModelComponent' into PVP
tillpp Apr 12, 2026
0a77f74
tmp changes
tillpp Apr 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/client/entity_manager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ pub fn initAfterWorld() void {
std.log.err("EntityModel {s} wasn't found", .{"cubyz:snale"});
break :blk main.entityModel.default();
}).get();
// TODO: remove before merge
addEntity(ZonElement.parseFromString(main.globalArena, null,
\\ .{
\\ .id = 1,
\\ .name = "bobik",
\\
\\ }
)) catch unreachable;
}
pub fn renderNames(projMatrix: Mat4f, playerPos: Vec3d) void {
mutex.lock();
Expand Down Expand Up @@ -211,3 +219,23 @@ pub fn serverUpdate(time: i16, entityData: []main.entity.EntityNetworkData) void
}
}
}
const Intersection = struct {
distance:f64,
entityId:u32
};
pub fn select(pos: Vec3d, dir: Vec3d, item: main.items.Item, maxDistance:f64) ?Intersection {
if(true)
return Intersection{
.distance = maxDistance/2,
.entityId = 0,
};
_ = dir;
_ = item;
for (main.entity.components.@"cubyz:model".client.renderComponents.dense.items) |*renderComponent| {
const entModel = renderComponent.entityModel.get();
_ = entModel;
// TODO: let entityModel decide the dimensions for the hitbox.
const difference = entities.items()[renderComponent.entity].getRenderPosition()-pos;
_ = difference;
}
}
6 changes: 5 additions & 1 deletion src/entity.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ pub const EntityComponentLoadError = error{
UnreadableComponentData,
UnknownComponentId,
};
// Analogous to Protocols.
pub const Entity = enum(u32) {
noValue = std.math.maxInt(u32),
_,
};
pub const EntityComponentId = u32;
// Analogous to Protocols.
const EntityComponentVTable = struct {
serverLoad: *const fn (entityId: u32, reader: *main.utils.BinaryReader, version: u32) EntityComponentLoadError!void,
clientLoad: *const fn (entityId: u32, reader: *main.utils.BinaryReader, version: u32) EntityComponentLoadError!void,
Expand Down
1 change: 1 addition & 0 deletions src/entityComponent/_list.zig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub const @"cubyz:model" = @import("model.zig");
pub const @"cubyz:_template" = @import("_template.zig");
106 changes: 106 additions & 0 deletions src/entityComponent/model.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const std = @import("std");

const main = @import("main");
const chunk = main.chunk;
const game = main.game;
const graphics = main.graphics;
const c = graphics.c;
const ZonElement = main.ZonElement;
const renderer = main.renderer;
const settings = main.settings;
const utils = main.utils;
const vec = main.vec;
const Mat4f = vec.Mat4f;
const Vec3d = vec.Vec3d;
const Vec3f = vec.Vec3f;
const Vec4f = vec.Vec4f;
const NeverFailingAllocator = main.heap.NeverFailingAllocator;

const BinaryReader = main.utils.BinaryReader;

pub var entityComponentID: u32 = undefined;
pub const entityComponentVersion = 0;

// ############################# Client only stuff ################################
pub const client = struct {
const RenderComponent = struct {
entity: u32, // entity
entityModel: main.entityModel.EntityModelIndex, // model
};
pub var renderComponents: main.utils.SparseSet(RenderComponent, main.entity.Entity) = undefined;

pub fn init() void {
renderComponents = .{};
}
pub fn deinit() void {
renderComponents.deinit(main.globalAllocator);
}
pub fn clear() void {
renderComponents.deinit(main.globalAllocator);
renderComponents = .{};
}
pub fn load(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void {
_ = version;
const entityModel = reader.readInt(u32) catch return;

const ptr = renderComponents.get(@enumFromInt(entity)) orelse renderComponents.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = RenderComponent{
.entity = entity,
.entityModel = main.entityModel.EntityModelIndex{.index = entityModel},
};
}
pub fn unload(entity: u32) void {
renderComponents.remove(@enumFromInt(entity)) catch {
std.log.err("entity {} couldn't be unloaded", .{entity});
};
}
};

// ############################# Server only stuff ################################

pub const server = struct {
pub const RenderComponent = struct {
entity: u32, // entity
entityModel: main.entityModel.EntityModelIndex, // model
pub fn save(self: RenderComponent, writer: *utils.BinaryWriter, audience: main.entity.AudienceInfo) main.entity.ComponentSaveBehaviour {
_ = audience;
writer.writeInt(u32, self.entityModel.index);
return .save;
}
};
var renderComponents: main.utils.SparseSet(RenderComponent, main.entity.Entity) = undefined;
pub fn init() void {
renderComponents = .{};
}
pub fn deinit() void {
renderComponents.deinit(main.globalAllocator);
}
pub fn loadFromData(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void {
_ = version;
const entityModel = reader.readInt(u32) catch return;

try loadByIndex(entity, main.entityModel.EntityModelIndex{.index = entityModel});
}
pub fn loadByID(entity: u32, entityModelID: []const u8) main.entity.EntityComponentLoadError!void {
try loadByIndex(entity, main.entityModel.getById(entityModelID) orelse main.entityModel.default());
}
pub fn loadByIndex(entity: u32, entityModel: main.entityModel.EntityModelIndex) main.entity.EntityComponentLoadError!void {
const ptr = renderComponents.get(@enumFromInt(entity)) orelse renderComponents.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = RenderComponent{
.entity = entity,
.entityModel = entityModel,
};
}
pub fn unload(entity: u32) void {
renderComponents.remove(@enumFromInt(entity)) catch {
std.log.err("entity {} couldn't be unloaded", .{entity});
};
}
pub fn put(entity: u32, renderComponent: RenderComponent) void {
const ptr = renderComponents.get(@enumFromInt(entity)) orelse renderComponents.add(main.globalAllocator, @enumFromInt(entity));
ptr.* = renderComponent;
}
pub fn get(entity: u32) ?*RenderComponent {
return renderComponents.get(@enumFromInt(entity));
}
};
8 changes: 8 additions & 0 deletions src/renderer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ pub const MeshSelection = struct { // MARK: MeshSelection

// Test blocks:
const closestDistance: f64 = 6.0; // selection now limited
var blockIntersectionDistance: f64 = 6.0;
// Implementation of "A Fast Voxel Traversal Algorithm for Ray Tracing" http://www.cse.yorku.ca/~amana/research/grid.pdf
const step: Vec3i = @intFromFloat(std.math.sign(dir));
const invDir = @as(Vec3d, @splat(1))/dir;
Expand All @@ -932,6 +933,7 @@ pub const MeshSelection = struct { // MARK: MeshSelection
const relativePlayerPos: Vec3f = @floatCast(pos - @as(Vec3d, @floatFromInt(voxelPos)));
if (block.mode().rayIntersection(block, item, relativePlayerPos, _dir)) |intersection| {
if (intersection.distance <= closestDistance) {
blockIntersectionDistance = intersection.distance;
selectedBlockPos = voxelPos;
selectionMin = intersection.min;
selectionMax = intersection.max;
Expand Down Expand Up @@ -968,6 +970,12 @@ pub const MeshSelection = struct { // MARK: MeshSelection
}
}
// TODO: Test entities
if(main.client.entity_manager.select(pos, dir, item,closestDistance)) |entityIntersection|{
if(selectedBlockPos == null or blockIntersectionDistance > entityIntersection.distance){
std.log.debug("intersected: {}", .{entityIntersection.entityId});
selectedBlockPos = null;
}
}
}

fn canPlaceBlock(pos: Vec3i, block: main.blocks.Block) bool {
Expand Down
4 changes: 4 additions & 0 deletions src/server/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ pub const User = struct { // MARK: User
self.id = freeId;
freeId += 1;

if (world.?.playerEntityModels.items.len != 0) {
const defaultModel = world.?.playerEntityModels.items[main.random.nextInt(u32, &main.seed)%world.?.playerEntityModels.items.len];
main.entity.components.@"cubyz:model".server.loadByID(self.id, defaultModel) catch unreachable;
}
world.?.loadPlayer(self) catch {
std.log.err("Error while loading player data of {s}. Discarding data.", .{self.name});
};
Expand Down
40 changes: 40 additions & 0 deletions src/server/world.zig
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ pub const ServerWorld = struct { // MARK: ServerWorld

biomeChecksum: i64 = 0,

playerEntityModels: main.ListUnmanaged([]const u8),

const ChunkUpdateRequest = struct {
ch: *ServerChunk,
milliTimeStamp: i64,
Expand All @@ -474,6 +476,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
.path = main.globalAllocator.dupe(u8, path),
.chunkUpdateQueue = .init(main.globalAllocator, 256),
.regionUpdateQueue = .init(main.globalAllocator, 256),
.playerEntityModels = .{},
};
self.itemDropManager.init(main.globalAllocator, self);
errdefer self.itemDropManager.deinit();
Expand Down Expand Up @@ -520,6 +523,13 @@ pub const ServerWorld = struct { // MARK: ServerWorld
self.chunkManager = try ChunkManager.init(self, worldData.getChild("generatorSettings"));
errdefer self.chunkManager.deinit();

for (self.playerEntityModels.items) |entityModel| {
if (main.entityModel.getById(entityModel) == null) {
std.log.err("EntityModel {s} is not available.", .{entityModel});
continue;
}
}

return self;
}

Expand All @@ -546,6 +556,10 @@ pub const ServerWorld = struct { // MARK: ServerWorld
updateRequest.region.decreaseRefCount();
}
self.regionUpdateQueue.deinit();
for (self.playerEntityModels.items) |value| {
main.globalAllocator.free(value);
}
self.playerEntityModels.deinit(main.globalAllocator);
self.chunkManager.deinit();
self.itemDropManager.deinit();
self.blockPalette.deinit();
Expand Down Expand Up @@ -632,6 +646,26 @@ pub const ServerWorld = struct { // MARK: ServerWorld
self.biomeChecksum = worldData.get(i64, "biomeChecksum", 0);
self.name = main.globalAllocator.dupe(u8, worldData.get([]const u8, "name", self.path));
self.tickSpeed = .init(worldData.get(u32, "tickSpeed", 12));

// playerEntityModel
if (worldData.getChildOrNull("playerEntityModels")) |playerEntityModels| {
if (playerEntityModels != .array) {
std.log.err("playerEntityModels in world.zig.zon must be an Array.", .{});
} else {
for (playerEntityModels.array.items) |value| {
const entityModel = value.as(?[]const u8, null) orelse {
std.log.err("playerEntityModels in world.zig.zon must be an Array of strings.", .{});
continue;
};
self.playerEntityModels.append(main.globalAllocator, main.globalAllocator.dupe(u8, entityModel));
}
}
}
if (self.playerEntityModels.items.len == 0) {
for ([_][]const u8{"cubyz:snale", "cubyz:cubert"}) |entityModel| {
self.playerEntityModels.append(main.globalAllocator, main.globalAllocator.dupe(u8, entityModel));
}
}
}

pub fn saveWorldConfig(self: *ServerWorld) !void {
Expand All @@ -648,6 +682,12 @@ pub const ServerWorld = struct { // MARK: ServerWorld
worldData.put("lastUsedTime", (try std.Io.Clock.Timestamp.now(main.io, .real)).raw.toMilliseconds());
worldData.put("tickSpeed", self.tickSpeed.load(.monotonic));

const playerEntityModels = ZonElement.initArray(main.stackAllocator);
for (self.playerEntityModels.items) |entityModelId| {
playerEntityModels.append(entityModelId);
}
worldData.put("playerEntityModels", playerEntityModels);

try files.cubyzDir().writeZon(path, worldData);
}

Expand Down
Loading