将 openspec skills 迁移到全局 + 定义后续 proto 类型

This commit is contained in:
SepComet
2026-03-28 09:48:53 +08:00
parent 156d72bf4a
commit 371ab30eea
37 changed files with 1560 additions and 2342 deletions
File diff suppressed because it is too large Load Diff
+11 -12
View File
@@ -4,35 +4,34 @@ namespace Network.Defines
{
Unknow = 0,
// 游戏相关
PlayerInput = 1,
// Gameplay
MoveInput = 1,
PlayerState = 2,
PlayerAction = 3,
GameState = 4,
ShootInput = 3,
CombatEvent = 4,
PlayerJoin = 5,
PlayerLeave = 6,
PlayerAction = 7,
GameState = 8,
// 聊天相关
// Chat
ChatMessage = 10,
PrivateMessage = 11,
SystemMessage = 12,
// 系统相关
// Session
HeartBeat = 20,
LoginRequest = 21,
LoginResponse = 22,
LogoutRequest = 23,
// 房间管理
// Room management
CreateRoom = 30,
JoinRoom = 31,
LeaveRoom = 32,
RoomList = 33,
Heartbeat = 40,
HeartbeatResponse = 41,
}
}
}
@@ -0,0 +1,85 @@
syntax = "proto3";
package Network.Defines;
option csharp_namespace = "Network.Defines";
message Envelope {
int32 type = 1;
bytes payload = 2;
}
message Vector3 {
float x = 1;
float y = 2;
float z = 3;
}
message LoginRequest {
string player_id = 1;
int32 speed = 2;
}
message LoginResponse {
repeated string player_id = 1;
repeated Vector3 positions = 2;
int32 speed = 3;
int64 server_tick = 4;
bool result = 5;
}
message PlayerJoin {
string player_id = 1;
Vector3 position = 2;
}
message LogoutRequest {
string player_id = 1;
}
message MoveInput {
string player_id = 1;
int64 tick = 2;
float move_x = 3;
float move_y = 4;
}
message ShootInput {
string player_id = 1;
int64 tick = 2;
float dir_x = 3;
float dir_y = 4;
string target_id = 5;
}
enum CombatEventType {
COMBAT_EVENT_TYPE_UNSPECIFIED = 0;
COMBAT_EVENT_TYPE_HIT = 1;
COMBAT_EVENT_TYPE_DAMAGE_APPLIED = 2;
COMBAT_EVENT_TYPE_DEATH = 3;
COMBAT_EVENT_TYPE_SHOOT_REJECTED = 4;
}
message CombatEvent {
int64 tick = 1;
CombatEventType event_type = 2;
string attacker_id = 3;
string target_id = 4;
int32 damage = 5;
Vector3 hit_position = 6;
}
message PlayerState {
string player_id = 1;
Vector3 position = 2;
Vector3 velocity = 3;
float rotation = 4;
int64 tick = 5;
int32 hp = 6;
}
message Heartbeat {
}
message HeartbeatResponse {
int64 server_tick = 1;
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 188a244376e8ae247b1c065b510a70d0
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -7,13 +7,13 @@ namespace Network.NetworkApplication
{
public sealed class ClientPredictionBuffer
{
private readonly List<PlayerInput> pendingInputs = new();
private readonly List<MoveInput> pendingInputs = new();
public long? LastAuthoritativeTick { get; private set; }
public IReadOnlyList<PlayerInput> PendingInputs => pendingInputs;
public IReadOnlyList<MoveInput> PendingInputs => pendingInputs;
public void Record(PlayerInput input)
public void Record(MoveInput input)
{
if (input == null)
{
@@ -28,7 +28,7 @@ namespace Network.NetworkApplication
pendingInputs.Add(input);
}
public bool TryApplyAuthoritativeState(PlayerState state, out IReadOnlyList<PlayerInput> replayInputs)
public bool TryApplyAuthoritativeState(PlayerState state, out IReadOnlyList<MoveInput> replayInputs)
{
if (state == null)
{
@@ -37,7 +37,7 @@ namespace Network.NetworkApplication
if (LastAuthoritativeTick.HasValue && state.Tick <= LastAuthoritativeTick.Value)
{
replayInputs = Array.Empty<PlayerInput>();
replayInputs = Array.Empty<MoveInput>();
return false;
}
@@ -47,4 +47,4 @@ namespace Network.NetworkApplication
return true;
}
}
}
}
@@ -8,7 +8,7 @@ namespace Network.NetworkApplication
private static readonly IReadOnlyDictionary<MessageType, DeliveryPolicy> DefaultPolicies =
new Dictionary<MessageType, DeliveryPolicy>
{
{ MessageType.PlayerInput, DeliveryPolicy.HighFrequencySync },
{ MessageType.MoveInput, DeliveryPolicy.HighFrequencySync },
{ MessageType.PlayerState, DeliveryPolicy.HighFrequencySync }
};
@@ -19,4 +19,4 @@ namespace Network.NetworkApplication
: DeliveryPolicy.ReliableOrdered;
}
}
}
}
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Net;
using Network.Defines;
@@ -39,9 +38,9 @@ namespace Network.NetworkApplication
{
switch (messageType)
{
case MessageType.PlayerInput:
case MessageType.MoveInput:
{
var input = PlayerInput.Parser.ParseFrom(payload);
var input = MoveInput.Parser.ParseFrom(payload);
streamKey = $"input:{Normalize(sender)}:{input.PlayerId}";
sequence = input.Tick;
return true;
@@ -67,4 +66,4 @@ namespace Network.NetworkApplication
return sender == null ? "unknown" : sender.ToString();
}
}
}
}