-
-
Notifications
You must be signed in to change notification settings - Fork 232
Add rotation to tp command #3413
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
base: master
Are you sure you want to change the base?
Changes from all commits
2365b7f
95a5c88
ac4f01e
cece174
5126ed5
a8ee327
9c47bfd
d715173
1a373bc
46daa74
6a37cd6
4f52606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,6 +139,19 @@ pub const server = struct { // MARK: server | |
| threadContext = .other; | ||
| } | ||
|
|
||
| pub fn sendSyncOperation(op: Command.SyncOperation, source: ?*main.server.User) void { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You mean like this? |
||
| const syncData = op.serialize(main.stackAllocator); | ||
| defer main.stackAllocator.free(syncData); | ||
|
|
||
| const users = op.getUsers(main.stackAllocator); | ||
| defer main.stackAllocator.free(users); | ||
|
|
||
| for (users) |user| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally this should only be sent to one user, you are sending it to all users, so everyone's rotation will get changed when executed. I would suggest to not try to deduplicate code here, this function should just take a single user and only send it to that single user. |
||
| if (user == source and op.ignoreSource()) continue; | ||
| main.network.protocols.inventory.sendSyncOperation(user.conn, syncData); | ||
| } | ||
| } | ||
|
|
||
| pub fn executeCommand(payload: Command.Payload, source: ?*main.server.User) void { | ||
| var command = Command{ | ||
| .payload = payload, | ||
|
|
@@ -153,16 +166,7 @@ pub const server = struct { // MARK: server | |
| main.network.protocols.inventory.sendConfirmation(source.?.conn, confirmationData); | ||
| } | ||
| for (command.syncOperations.items) |op| { | ||
| const syncData = op.serialize(main.stackAllocator); | ||
| defer main.stackAllocator.free(syncData); | ||
|
|
||
| const users = op.getUsers(main.stackAllocator); | ||
| defer main.stackAllocator.free(users); | ||
|
|
||
| for (users) |user| { | ||
| if (user == source and op.ignoreSource()) continue; | ||
| main.network.protocols.inventory.sendSyncOperation(user.conn, syncData); | ||
| } | ||
| sendSyncOperation(op, source); | ||
| } | ||
| if (source != null and command.payload == .open) { // Send initial items | ||
| for (command.payload.open.inv._items, 0..) |stack, slot| { | ||
|
|
@@ -333,6 +337,7 @@ pub const Command = struct { // MARK: Command | |
| health = 3, | ||
| kill = 4, | ||
| energy = 5, | ||
| rotation = 6, | ||
| }; | ||
|
|
||
| const SyncOperation = union(SyncOperationType) { // MARK: SyncOperation | ||
|
|
@@ -362,6 +367,10 @@ pub const Command = struct { // MARK: Command | |
| target: ?*main.server.User, | ||
| energy: f32, | ||
| }, | ||
| rotation: struct { | ||
| target: ?*main.server.User, | ||
| rotation: Vec3f, | ||
| }, | ||
|
|
||
| pub fn executeFromData(reader: *BinaryReader) !void { | ||
| switch (try deserialize(reader)) { | ||
|
|
@@ -408,6 +417,9 @@ pub const Command = struct { // MARK: Command | |
| .energy => |energy| { | ||
| main.game.Player.super.energy = std.math.clamp(main.game.Player.super.energy + energy.energy, 0, main.game.Player.super.maxEnergy); | ||
| }, | ||
| .rotation => |rotation| { | ||
| main.game.camera.rotation = rotation.rotation; | ||
| }, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -421,7 +433,7 @@ pub const Command = struct { // MARK: Command | |
| } | ||
| return result; | ||
| }, | ||
| inline .health, .kill, .energy => |data| { | ||
| inline .health, .kill, .energy, .rotation => |data| { | ||
| const out = allocator.alloc(*main.server.User, 1); | ||
| out[0] = data.target.?; | ||
| return out; | ||
|
|
@@ -431,7 +443,7 @@ pub const Command = struct { // MARK: Command | |
|
|
||
| pub fn ignoreSource(self: SyncOperation) bool { | ||
| return switch (self) { | ||
| .create, .delete, .useDurability, .health, .energy => true, | ||
| .create, .delete, .useDurability, .health, .energy, .rotation => true, | ||
| .kill => false, | ||
| }; | ||
| } | ||
|
|
@@ -482,6 +494,12 @@ pub const Command = struct { // MARK: Command | |
| .energy = try reader.readFloat(f32), | ||
| }}; | ||
| }, | ||
| .rotation => { | ||
| return .{.rotation = .{ | ||
| .target = null, | ||
| .rotation = try reader.readVec(Vec3f), | ||
| }}; | ||
| }, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -513,6 +531,9 @@ pub const Command = struct { // MARK: Command | |
| .energy => |energy| { | ||
| writer.writeFloat(f32, energy.energy); | ||
| }, | ||
| .rotation => |rotation| { | ||
| writer.writeVec(Vec3f, rotation.rotation); | ||
| }, | ||
| } | ||
| return writer.data.toOwnedSlice(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do the conversion from degrees during parsing, also there is a helper function in std.math for this, which is more readable.