feat(scene): implement CS_MOVE_OBJECT_MOVE handler

Last player position should be also saved properly now
This commit is contained in:
xeon
2026-02-07 16:51:31 +03:00
parent 69a95a1e24
commit ff0d410cf0
2 changed files with 64 additions and 0 deletions

View File

@@ -134,3 +134,16 @@ pub fn getObjectByNetId(level: *Level, net_id: Object.NetID) ?Object.Handle {
const index = level.object_id_map.get(@intFromEnum(net_id)) orelse return null; const index = level.object_id_map.get(@intFromEnum(net_id)) orelse return null;
return @enumFromInt(index); return @enumFromInt(index);
} }
pub fn moveObject(
level: *Level,
handle: Object.Handle,
position: Object.Vector,
rotation: Object.Vector,
) void {
const index = @intFromEnum(handle);
const objects = level.objects.slice();
objects.items(.position)[index] = position;
objects.items(.rotation)[index] = rotation;
}

View File

@@ -2,9 +2,60 @@ const pb = @import("proto").pb;
const logic = @import("../../logic.zig"); const logic = @import("../../logic.zig");
const messaging = logic.messaging; const messaging = logic.messaging;
const Level = logic.Level;
const Player = logic.Player;
pub fn onSceneLoadFinish( pub fn onSceneLoadFinish(
_: messaging.Request(pb.CS_SCENE_LOAD_FINISH), _: messaging.Request(pb.CS_SCENE_LOAD_FINISH),
sync_self_scene_tx: logic.event.Sender(.sync_self_scene), sync_self_scene_tx: logic.event.Sender(.sync_self_scene),
) !void { ) !void {
try sync_self_scene_tx.send(.{ .reason = .entrance }); try sync_self_scene_tx.send(.{ .reason = .entrance });
} }
pub fn onMoveObjectMove(
request: messaging.Request(pb.CS_MOVE_OBJECT_MOVE),
char_bag: Player.Component(.char_bag),
scene: Player.Component(.scene),
level: *Level,
cur_scene_modified_tx: logic.event.Sender(.current_scene_modified),
) !void {
const team_index = char_bag.data.meta.curr_team_index;
const leader_index = char_bag.data.teams.items(.leader_index)[team_index];
for (request.message.move_info.items) |move_info| {
if (move_info.scene_num_id != scene.data.current.level_id) continue;
const motion = move_info.motion_info orelse continue;
const position: Level.Object.Vector = if (motion.position) |v| .{
.x = v.X,
.y = v.Y,
.z = v.Z,
} else continue;
const rotation: Level.Object.Vector = if (motion.rotation) |v| .{
.x = v.X,
.y = v.Y,
.z = v.Z,
} else continue;
const net_id: Level.Object.NetID = @enumFromInt(move_info.objid);
const handle = level.getObjectByNetId(net_id) orelse continue;
level.moveObject(handle, position, rotation);
if (@intFromEnum(net_id) == leader_index.objectId() and motion.state == .MOTION_WALK) {
scene.data.current.position = .{
position.x,
position.y,
position.z,
};
scene.data.current.rotation = .{
rotation.x,
rotation.y,
rotation.z,
};
try cur_scene_modified_tx.send(.{});
}
}
}