packets :: package packets
}
-#local Verify_Connect_Handle :: struct {
- use base := Packet_Handler.{ .Verify_Connect };
+#tag Packet_Handler.{ .Verify_Connect }
+#local handle_verify_connect :: (packet: ^packets.Verify_Connect) {
+ player_manager.player_id = packet.player_id;
- handle :: (packet: ^packets.Verify_Connect) {
- player_manager.player_id = packet.player_id;
-
- push_game_state(Game_State, null);
- }
+ push_game_state(Game_State, null);
}
-#local Player_Joined_Handle :: struct {
- use base := Packet_Handler.{ .Player_Joined };
-
- handle :: (packet: ^packets.Player_Joined) {
- name := packet->name();
- player_manager->add_player(packet.player_id, name);
+#tag Packet_Handler.{ .Player_Joined }
+#local handle_player_joined :: (packet: ^packets.Player_Joined) {
+ name := packet->name();
+ player_manager->add_player(packet.player_id, name);
- if packet.player_id != player_manager.player_id {
- buf: [1024] u8;
- chat_messages << (conv.format(buf, "{} joined the server!", name) |> string.alloc_copy());
- }
+ if packet.player_id != player_manager.player_id {
+ chat_messages << aprintf("{} joined the server!", name);
}
}
-#local Connection_Rejected_Handle :: struct {
- use base := Packet_Handler.{ .Connection_Rejected };
+#tag Packet_Handler.{ .Connection_Rejected }
+#local handle_connection_rejected :: (packet: ^packets.Connection_Rejected) {
+ @NetworkErrors // Handle this case.
+ printf("Connection refused: {}\n", packet.reason);
- handle :: (packet: ^packets.Connection_Rejected) {
- @NetworkErrors // Handle this case.
- printf("Connection refused: {}\n", packet.reason);
-
- pop_game_state();
- push_game_state(Connect_Menu, null);
- }
+ pop_game_state();
+ push_game_state(Connect_Menu, null);
}
-#local Chat_Message_Handle :: struct {
- use base := Packet_Handler.{ .Chat_Message };
-
- handle :: (packet: ^packets.Chat_Message) {
- buf: [1024] u8;
- msg: str;
+#tag Packet_Handler.{ .Chat_Message }
+#local handle_chat_message :: (packet: ^packets.Chat_Message) {
+ buf: [1024] u8;
+ msg: str;
- sender := player_manager->get_player(packet.sender_id);
- if sender != null {
- msg = conv.format(buf, "[{}] {}\n", sender.name, packet->message());
- } else {
- msg = packet->message();
- }
-
- chat_messages << string.alloc_copy(msg);
+ sender := player_manager->get_player(packet.sender_id);
+ if sender != null {
+ msg = conv.format(buf, "[{}] {}\n", sender.name, packet->message());
+ } else {
+ msg = packet->message();
}
-}
-#local Player_Moved_Handle :: struct {
- use base := Packet_Handler.{ .Player_Moved };
+ chat_messages << string.alloc_copy(msg);
+}
- handle :: (packet: ^packets.Player_Moved) {
- if packet.player_id == player_manager.player_id do return;
+#tag Packet_Handler.{ .Player_Moved }
+#local handle_player_moved :: (packet: ^packets.Player_Moved) {
+ if packet.player_id == player_manager.player_id do return;
- player := player_manager->get_player(packet.player_id);
- player.position = packet.position;
- player.velocity = packet.velocity;
- player.facing = packet.facing;
- player.on_ground = packet.on_ground;
- }
+ player := player_manager->get_player(packet.player_id);
+ player.position = packet.position;
+ player.velocity = packet.velocity;
+ player.facing = packet.facing;
+ player.on_ground = packet.on_ground;
}
-#local Block_Updates_Handle :: struct {
- use base := Packet_Handler.{ .Block_Updates };
-
- handle :: (packet: ^packets.Block_Updates) {
- updates := packet->updates();
- for updates {
- pos := it.position;
- world_set_block(world, pos.x, pos.y, pos.z, it.new_block);
- }
+#tag Packet_Handler.{ .Block_Updates }
+#local handle_block_updates :: (packet: ^packets.Block_Updates) {
+ updates := packet->updates();
+ for updates {
+ pos := it.position;
+ world_set_block(world, pos.x, pos.y, pos.z, it.new_block);
}
}
#local hash :: package core.hash
+#tag conv.Custom_Format.{format_vector2i}
+#tag conv.Custom_Parse.{parse_vector2i}
Vector2i :: struct {
x, y: i32;
- #struct_tag conv.Custom_Format.{format_vector2i}
- #struct_tag conv.Custom_Parse.{parse_vector2i}
}
+#tag conv.Custom_Format.{format_vector2}
+#tag conv.Custom_Parse.{parse_vector2}
Vector2 :: struct {
x, y: f32;
Zero :: Vector2.{0, 0}
-
- #struct_tag conv.Custom_Format.{format_vector2}
- #struct_tag conv.Custom_Parse.{parse_vector2}
}
+#tag conv.Custom_Format.{format_vector3i}
Vector3i :: struct {
x, y, z: i32;
- #struct_tag conv.Custom_Format.{format_vector3i}
}
+#tag conv.Custom_Format.{format_vector3}
Vector3 :: struct {
x, y, z: f32;
math.clamp(v.z, min.z, max.z),
};
}
-
- #struct_tag conv.Custom_Format.{format_vector3}
}
#operator + macro (v1, v2: Vector2i) => (typeof v1).{ v1.x + v2.x, v1.y + v2.y };