mirror of
https://git.xeondev.com/LR/S.git
synced 2026-02-04 06:55:06 +01:00
refactor(scene): decouple player level/position from notifying systems
This commit is contained in:
@@ -15,10 +15,32 @@ pub const PlayerId = struct {
|
|||||||
uid: mem.LimitedString(max_length),
|
uid: mem.LimitedString(max_length),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: this can be made a persistent Player component.
|
||||||
|
pub const Location = struct {
|
||||||
|
const default_level = "map02_lv001";
|
||||||
|
|
||||||
|
level: i32,
|
||||||
|
position: [3]f32,
|
||||||
|
|
||||||
|
fn createDefault(assets: *const Assets) Location {
|
||||||
|
const level_config = assets.level_config_table.getPtr(default_level).?;
|
||||||
|
|
||||||
|
return .{
|
||||||
|
.level = level_config.idNum,
|
||||||
|
.position = .{
|
||||||
|
level_config.playerInitPos.x,
|
||||||
|
level_config.playerInitPos.y,
|
||||||
|
level_config.playerInitPos.z,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
player_id: PlayerId,
|
player_id: PlayerId,
|
||||||
session: *Session, // TODO: should it be here this way? Do we need an abstraction?
|
session: *Session, // TODO: should it be here this way? Do we need an abstraction?
|
||||||
res: logic.Resource,
|
res: logic.Resource,
|
||||||
player: logic.Player,
|
player: logic.Player,
|
||||||
|
location: Location,
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
session: *Session,
|
session: *Session,
|
||||||
@@ -34,6 +56,7 @@ pub fn init(
|
|||||||
.session = session,
|
.session = session,
|
||||||
.player = player,
|
.player = player,
|
||||||
.res = .init(assets, io),
|
.res = .init(assets, io),
|
||||||
|
.location = .createDefault(assets),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +71,7 @@ pub const GetComponentError = error{
|
|||||||
pub fn getComponentByType(world: *World, comptime T: type) GetComponentError!T {
|
pub fn getComponentByType(world: *World, comptime T: type) GetComponentError!T {
|
||||||
switch (T) {
|
switch (T) {
|
||||||
PlayerId => return world.player_id,
|
PlayerId => return world.player_id,
|
||||||
|
*Location, *const Location => return &world.location,
|
||||||
*Session => return world.session,
|
*Session => return world.session,
|
||||||
*logic.Resource.PingTimer => return &world.res.ping_timer,
|
*logic.Resource.PingTimer => return &world.res.ping_timer,
|
||||||
*const Assets => return world.res.assets,
|
*const Assets => return world.res.assets,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
pub const Login = struct {};
|
pub const Login = struct {};
|
||||||
|
|
||||||
|
pub const ChangeSceneBegin = struct {};
|
||||||
|
|
||||||
pub const CharBagTeamModified = struct {
|
pub const CharBagTeamModified = struct {
|
||||||
team_index: usize,
|
team_index: usize,
|
||||||
modification: enum {
|
modification: enum {
|
||||||
|
|||||||
@@ -8,32 +8,37 @@ const Player = logic.Player;
|
|||||||
const ArrayList = std.ArrayList;
|
const ArrayList = std.ArrayList;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
const default_level = "map02_lv001";
|
|
||||||
|
|
||||||
pub fn enterSceneOnLogin(
|
pub fn enterSceneOnLogin(
|
||||||
rx: logic.event.Receiver(.login),
|
rx: logic.event.Receiver(.login),
|
||||||
|
tx: logic.event.Sender(.change_scene_begin),
|
||||||
|
) !void {
|
||||||
|
_ = rx;
|
||||||
|
try tx.send(.{});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn beginChangingScene(
|
||||||
|
rx: logic.event.Receiver(.change_scene_begin),
|
||||||
session: *Session,
|
session: *Session,
|
||||||
assets: *const Assets,
|
|
||||||
base_comp: Player.Component(.base),
|
base_comp: Player.Component(.base),
|
||||||
|
location: *const logic.World.Location,
|
||||||
) !void {
|
) !void {
|
||||||
_ = rx;
|
_ = rx;
|
||||||
|
|
||||||
const level_config = assets.level_config_table.getPtr(default_level).?;
|
|
||||||
const position: pb.VECTOR = .{
|
const position: pb.VECTOR = .{
|
||||||
.X = level_config.playerInitPos.x,
|
.X = location.position[0],
|
||||||
.Y = level_config.playerInitPos.y,
|
.Y = location.position[1],
|
||||||
.Z = level_config.playerInitPos.z,
|
.Z = location.position[2],
|
||||||
};
|
};
|
||||||
|
|
||||||
try session.send(pb.SC_CHANGE_SCENE_BEGIN_NOTIFY{
|
try session.send(pb.SC_CHANGE_SCENE_BEGIN_NOTIFY{
|
||||||
.scene_num_id = level_config.idNum,
|
.scene_num_id = location.level,
|
||||||
.position = position,
|
.position = position,
|
||||||
.pass_through_data = .init,
|
.pass_through_data = .init,
|
||||||
});
|
});
|
||||||
|
|
||||||
try session.send(pb.SC_ENTER_SCENE_NOTIFY{
|
try session.send(pb.SC_ENTER_SCENE_NOTIFY{
|
||||||
.role_id = base_comp.data.role_id,
|
.role_id = base_comp.data.role_id,
|
||||||
.scene_num_id = level_config.idNum,
|
.scene_num_id = location.level,
|
||||||
.position = position,
|
.position = position,
|
||||||
.pass_through_data = .init,
|
.pass_through_data = .init,
|
||||||
});
|
});
|
||||||
@@ -58,6 +63,7 @@ pub fn syncSelfScene(
|
|||||||
session: *Session,
|
session: *Session,
|
||||||
arena: logic.Resource.Allocator(.arena),
|
arena: logic.Resource.Allocator(.arena),
|
||||||
char_bag: logic.Player.Component(.char_bag),
|
char_bag: logic.Player.Component(.char_bag),
|
||||||
|
location: *const logic.World.Location,
|
||||||
assets: *const Assets,
|
assets: *const Assets,
|
||||||
) !void {
|
) !void {
|
||||||
const reason: pb.SELF_INFO_REASON_TYPE = switch (rx.payload.reason) {
|
const reason: pb.SELF_INFO_REASON_TYPE = switch (rx.payload.reason) {
|
||||||
@@ -65,18 +71,17 @@ pub fn syncSelfScene(
|
|||||||
.team_modified => .SLR_CHANGE_TEAM,
|
.team_modified => .SLR_CHANGE_TEAM,
|
||||||
};
|
};
|
||||||
|
|
||||||
const level_config = assets.level_config_table.getPtr(default_level).?;
|
|
||||||
const position: pb.VECTOR = .{
|
const position: pb.VECTOR = .{
|
||||||
.X = level_config.playerInitPos.x,
|
.X = location.position[0],
|
||||||
.Y = level_config.playerInitPos.y,
|
.Y = location.position[1],
|
||||||
.Z = level_config.playerInitPos.z,
|
.Z = location.position[2],
|
||||||
};
|
};
|
||||||
|
|
||||||
const team_index = char_bag.data.meta.curr_team_index;
|
const team_index = char_bag.data.meta.curr_team_index;
|
||||||
const leader_index = char_bag.data.teams.items(.leader_index)[team_index];
|
const leader_index = char_bag.data.teams.items(.leader_index)[team_index];
|
||||||
|
|
||||||
var self_scene_info: pb.SC_SELF_SCENE_INFO = .{
|
var self_scene_info: pb.SC_SELF_SCENE_INFO = .{
|
||||||
.scene_num_id = level_config.idNum,
|
.scene_num_id = location.level,
|
||||||
.self_info_reason = @intFromEnum(reason),
|
.self_info_reason = @intFromEnum(reason),
|
||||||
.teamInfo = .{
|
.teamInfo = .{
|
||||||
.team_type = .CHAR_BAG_TEAM_TYPE_MAIN,
|
.team_type = .CHAR_BAG_TEAM_TYPE_MAIN,
|
||||||
@@ -106,7 +111,7 @@ pub fn syncSelfScene(
|
|||||||
.templateid = char_template_id,
|
.templateid = char_template_id,
|
||||||
.position = position,
|
.position = position,
|
||||||
.rotation = .{},
|
.rotation = .{},
|
||||||
.scene_num_id = level_config.idNum,
|
.scene_num_id = location.level,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user