Skip to content
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

Create Unity input FSM #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* [x] add AttackTarget curve
* [x] add FSM design document
* [x] add FSM blog entry
* [ ] **add Attack delay / targeting**
* [ ] add game state export / import
* [ ] log to file, log non-fatal errors instead of erroring out (e.g. `Run`)
* [ ] replace pathfinding with flow fields
Expand Down
11 changes: 10 additions & 1 deletion api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ message GetStatusResponse {

message AttackRequest {
double tick = 1;

// TODO(minkezhang): Remove after adding authentication.
string client_id = 2;

repeated string entity_ids = 3;
string target_entity_id = 4;
}
Expand All @@ -56,7 +59,10 @@ message AttackResponse {}

message MoveRequest {
double tick = 1;

// TODO(minkezhang): Remove after adding authentication.
string client_id = 2;

repeated string entity_ids = 3;
game.api.data.Position destination = 4;
game.api.constants.MoveType move_type = 5;
Expand All @@ -66,6 +72,8 @@ message MoveResponse {}

message StreamDataRequest {
double tick = 1;

// TODO(minkezhang): Remove after adding authentication.
string client_id = 2;
}

Expand All @@ -78,5 +86,6 @@ message StreamDataResponse {
message AddClientRequest {}
message AddClientResponse {
double tick = 1;
string client_id = 2;

game.api.data.ClientID client_id = 2;
}
2 changes: 2 additions & 0 deletions api/constants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum EntityProperty {
ENTITY_PROPERTY_POSITION = 1;
ENTITY_PROPERTY_ATTACK_TIMER = 2;
ENTITY_PROPERTY_HEALTH = 3;
ENTITY_PROPERTY_ATTACK_TARGET = 4;
ENTITY_PROPERTY_CLIENT_ID = 5;
}

// CurveType indicates the interpolation method that should be used for the
Expand Down
9 changes: 8 additions & 1 deletion api/data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import "api/constants.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

// ClientID contains identification information about a specific client
// connected to the game. This struct is surfaced as public information and does
// not contain any authentication-related tokens.
message ClientID {
string client_id = 1;
}

// Position is a specific point in the map, representing a point in the map.
message Position {
double x = 1;
Expand Down Expand Up @@ -73,7 +80,7 @@ message Entity {
// TODO(minkezhang): Rename to id instead.
string entity_id = 1;

game.api.constants.EntityType type = 2;
game.api.constants.EntityType type = 2;
}

message GameState {
Expand Down
2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Engine/Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public string ID
public string Connect()
{
var resp = _c.AddClient(new DF.Game.API.API.AddClientRequest());
ID = resp.ClientId;
ID = resp.ClientId.ClientId;
return ID;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions client/DownFlux/Assets/Engine/Utilities/FSM/FSM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace DF.Game.Utilities.FSM {
// TODO(minkezhang): Change to Dictionary<State, List<State>> instead.
using TransitionLookup = System.Collections.ObjectModel.ReadOnlyDictionary<State, State>;

public class State {
private int _s;
public State(int s) {
_s = s;
}
}

public interface IFSM {
bool To(State a, State b);
State State();
}

public abstract class Base : IFSM {
private TransitionLookup _transitions;
private State _state; // Default state must be UNKNOWN.

public Base(TransitionLookup transitions, State s) {
_transitions = transitions;
_state = s;
}

public bool To(State a, State b) {
if (_transitions.ContainsKey(a) && _transitions[a] == b) {
_state = b;
return true;
}
return false;
}

public abstract State State();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Packages.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions client/DownFlux/Assets/Plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## gRPC DLLs

gRPC requires some additionally packaged object files, e.g.
libgrpc_csharp_ext.so in order for Unity to run. These shared libraries may be
`libgrpc_csharp_ext.so` in order for Unity to run. These shared libraries may be
found in the `Grpc.Core` NuGet package.

See [#25223](https://github.com/grpc/grpc/issues/25223) for more information.
Remember to rename the runtime to the expected filename.

See [#25223](https://github.com/grpc/grpc/issues/25223) for more information.
2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Plugins/libgrpc_csharp_ext.so.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Protos/API.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Protos/API/API.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 46 additions & 28 deletions client/DownFlux/Assets/Protos/API/API/Api.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ static ApiReflection() {
"U3RyZWFtRGF0YVJlcXVlc3QSDAoEdGljaxgBIAEoARIRCgljbGllbnRfaWQY",
"AiABKAkiSwoSU3RyZWFtRGF0YVJlc3BvbnNlEgwKBHRpY2sYASABKAESJwoF",
"c3RhdGUYAiABKAsyGC5nYW1lLmFwaS5kYXRhLkdhbWVTdGF0ZSISChBBZGRD",
"bGllbnRSZXF1ZXN0IjQKEUFkZENsaWVudFJlc3BvbnNlEgwKBHRpY2sYASAB",
"KAESEQoJY2xpZW50X2lkGAIgASgJMpADCghEb3duRmx1eBJOCglBZGRDbGll",
"bnQSHi5nYW1lLmFwaS5hcGkuQWRkQ2xpZW50UmVxdWVzdBofLmdhb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waS5TdHJlYW1E",
"YXRhUmVxdWVzdBogLmdhbWUuYXBpLmFwaS5TdHJlYW1EYXRhUmVzcG9uc2Ui",
"A5ACAjABElEKCUdldFN0YXR1cxIeLmdhbWUuYXBpLmFwaS5HZXRTdGF0dXNS",
"ZXF1ZXN0Gh8uZ2FtZS5hcGkuYXBpLkdldFN0YXR1c1Jlc3BvbnNlIgOQAgJC",
"IFoMZ2FtZS5hcGkuYXBpqgIPREYuR2FtZS5BUEkuQVBJYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { global::DF.Game.API.Constants.ConstantsReflection.Descriptor, global::DF.Game.API.Data.DataReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
Expand Down Expand Up @@ -440,6 +440,9 @@ public double Tick {
/// <summary>Field number for the "client_id" field.</summary>
public const int ClientIdFieldNumber = 2;
private string clientId_ = "";
/// <summary>
/// TODO(minkezhang): Remove after adding authentication.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ClientId {
get { return clientId_; }
Expand Down Expand Up @@ -846,6 +849,9 @@ public double Tick {
/// <summary>Field number for the "client_id" field.</summary>
public const int ClientIdFieldNumber = 2;
private string clientId_ = "";
/// <summary>
/// TODO(minkezhang): Remove after adding authentication.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ClientId {
get { return clientId_; }
Expand Down Expand Up @@ -1293,6 +1299,9 @@ public double Tick {
/// <summary>Field number for the "client_id" field.</summary>
public const int ClientIdFieldNumber = 2;
private string clientId_ = "";
/// <summary>
/// TODO(minkezhang): Remove after adding authentication.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ClientId {
get { return clientId_; }
Expand Down Expand Up @@ -1834,7 +1843,7 @@ public AddClientResponse() {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public AddClientResponse(AddClientResponse other) : this() {
tick_ = other.tick_;
clientId_ = other.clientId_;
clientId_ = other.clientId_ != null ? other.clientId_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}

Expand All @@ -1856,12 +1865,12 @@ public double Tick {

/// <summary>Field number for the "client_id" field.</summary>
public const int ClientIdFieldNumber = 2;
private string clientId_ = "";
private global::DF.Game.API.Data.ClientID clientId_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string ClientId {
public global::DF.Game.API.Data.ClientID ClientId {
get { return clientId_; }
set {
clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
clientId_ = value;
}
}

Expand All @@ -1879,15 +1888,15 @@ public bool Equals(AddClientResponse other) {
return true;
}
if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(Tick, other.Tick)) return false;
if (ClientId != other.ClientId) return false;
if (!object.Equals(ClientId, other.ClientId)) return false;
return Equals(_unknownFields, other._unknownFields);
}

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (Tick != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Tick);
if (ClientId.Length != 0) hash ^= ClientId.GetHashCode();
if (clientId_ != null) hash ^= ClientId.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
Expand All @@ -1908,9 +1917,9 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(9);
output.WriteDouble(Tick);
}
if (ClientId.Length != 0) {
if (clientId_ != null) {
output.WriteRawTag(18);
output.WriteString(ClientId);
output.WriteMessage(ClientId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
Expand All @@ -1925,9 +1934,9 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(9);
output.WriteDouble(Tick);
}
if (ClientId.Length != 0) {
if (clientId_ != null) {
output.WriteRawTag(18);
output.WriteString(ClientId);
output.WriteMessage(ClientId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
Expand All @@ -1941,8 +1950,8 @@ public int CalculateSize() {
if (Tick != 0D) {
size += 1 + 8;
}
if (ClientId.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId);
if (clientId_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(ClientId);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
Expand All @@ -1958,8 +1967,11 @@ public void MergeFrom(AddClientResponse other) {
if (other.Tick != 0D) {
Tick = other.Tick;
}
if (other.ClientId.Length != 0) {
ClientId = other.ClientId;
if (other.clientId_ != null) {
if (clientId_ == null) {
ClientId = new global::DF.Game.API.Data.ClientID();
}
ClientId.MergeFrom(other.ClientId);
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
Expand All @@ -1980,7 +1992,10 @@ public void MergeFrom(pb::CodedInputStream input) {
break;
}
case 18: {
ClientId = input.ReadString();
if (clientId_ == null) {
ClientId = new global::DF.Game.API.Data.ClientID();
}
input.ReadMessage(ClientId);
break;
}
}
Expand All @@ -2002,7 +2017,10 @@ public void MergeFrom(pb::CodedInputStream input) {
break;
}
case 18: {
ClientId = input.ReadString();
if (clientId_ == null) {
ClientId = new global::DF.Game.API.Data.ClientID();
}
input.ReadMessage(ClientId);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Protos/API/API/Api.g.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/DownFlux/Assets/Protos/API/Constants.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading