Repository navigation
EntityComponent Player #2889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
EntityComponent Player #2889
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e1f72bc
playerComponent
tillpp e7c4038
corrected deinit order
tillpp 59ffe78
don't throw an error
tillpp 0d66f05
Merge branch 'master' into PlayerComponent
tillpp 97f5aa6
nitpickings
tillpp 8e6809a
fmt
tillpp 336170a
Merge remote-tracking branch 'origin/master' into PlayerComponent
tillpp 87be3b7
qd requested changes
tillpp 8ed5257
fmt
tillpp b2c6625
removed ghostly comment
tillpp bf79f8f
Update src/entityComponent/player.zig
tillpp 8e6d189
Update src/entityComponent/player.zig
tillpp 51762da
Update src/entityComponent/player.zig
tillpp be3fda0
Update src/entityComponent/player.zig
tillpp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub const @"cubyz:_template" = @import("_template.zig"); | ||
| pub const @"cubyz:bag" = @import("bag.zig"); | ||
| pub const @"cubyz:model" = @import("model.zig"); | ||
| pub const @"cubyz:player" = @import("player.zig"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| 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: main.entity.EntityComponentId = undefined; | ||
| pub const entityComponentVersion = 0; | ||
|
|
||
| // ############################# Client only stuff ################################ | ||
| pub const client = struct { | ||
| const Component = struct { | ||
| playerIndex: u32, | ||
| }; | ||
| pub var components: main.utils.SparseSet(Component, main.entity.Entity) = .{}; | ||
|
|
||
| pub fn init() void {} | ||
| pub fn deinit() void { | ||
| components.deinit(main.globalAllocator); | ||
| } | ||
| pub fn clear() void { | ||
| components.clear(); | ||
| } | ||
| pub fn load(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void { | ||
| if (version != 0) | ||
| return error.InvalidComponentVersion; | ||
| const playerIndex = reader.readVarInt(u32) catch return error.UnreadableComponentData; | ||
|
|
||
| const ptr = components.get(@enumFromInt(entity)) orelse components.add(main.globalAllocator, @enumFromInt(entity)); | ||
| ptr.* = Component{ | ||
| .playerIndex = playerIndex, | ||
| }; | ||
| } | ||
| pub fn unload(entity: u32) void { | ||
| components.remove(@enumFromInt(entity)) catch {}; | ||
| } | ||
| pub fn get(entity: u32) ?*Component { | ||
| return components.get(@enumFromInt(entity)); | ||
| } | ||
| }; | ||
|
|
||
| // ############################# Server only stuff ################################ | ||
|
|
||
| pub const server = struct { | ||
| pub const Component = struct { | ||
| playerIndex: u32, // model | ||
| pub fn save(self: Component, writer: *utils.BinaryWriter, audience: main.entity.AudienceInfo) main.entity.ComponentSaveBehaviour { | ||
| writer.writeVarInt(u32, self.playerIndex); | ||
| if (audience == .disk) | ||
| return .discard; | ||
| return .save; | ||
| } | ||
| }; | ||
| var components: main.utils.SparseSet(Component, main.entity.Entity) = undefined; | ||
| pub fn init() void { | ||
| components = .{}; | ||
| } | ||
| pub fn deinit() void { | ||
| components.deinit(main.globalAllocator); | ||
| } | ||
| pub fn loadFromData(entity: u32, reader: *utils.BinaryReader, version: u32) main.entity.EntityComponentLoadError!void { | ||
| if (version != 0) | ||
| return error.InvalidComponentVersion; | ||
| const playerIndex = reader.readVarInt(u32) catch return error.UnreadableComponentData; | ||
|
|
||
| load(entity, playerIndex); | ||
| } | ||
| pub fn load(entity: u32, playerIndex: u32) void { | ||
| put(entity, Component{ | ||
| .playerIndex = playerIndex, | ||
| }); | ||
| } | ||
| pub fn unload(entity: u32) void { | ||
| components.remove(@enumFromInt(entity)) catch {}; | ||
| } | ||
| pub fn put(entity: u32, renderComponent: Component) void { | ||
| const ptr = components.get(@enumFromInt(entity)) orelse components.add(main.globalAllocator, @enumFromInt(entity)); | ||
| ptr.* = renderComponent; | ||
| } | ||
| pub fn get(entity: u32) ?*Component { | ||
| return components.get(@enumFromInt(entity)); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.