Skip to content

Implement socket communication via protocol buffers #49

Description

@douglasrizzo

Hello @santiontanon . You have mentioned to me in another medium that, when communicating to and from MicroRTS using sockets, building and passing XML and JSON messages creates a bottleneck in simulation time.

I have seen a tendency in the community to opt for protocol buffers (protobuf) when communication time is a priority over human-readability.

Basically, you create a .proto text file which dictates the message format, compile it using a tool that generates classes in multiple languages, and use these classes to create interchangeable objects, which can be serialized in byte arrays, for example.

I have found this comparison between JSON and Protobuf which indicates that the later is up to 5x times faster.

I was working through the tutorials and ended up creating a .proto file for a MicroRTS game state and was thinking about testing it sometime soon.

If successful, would there be interest to include something like this into MicroRTS?

syntax = "proto3";

option java_package = "ai.socket.protobuf";
option java_outer_classname = "GameStateProtobuf";

message unit {
  string type = 1;
  int32 ID = 2;
  int32 player = 3;
  int32 x = 4;
  int32 y = 5;
  int32 resources = 6;
  int32 hitpoints = 7;
}

message player {
  int32 ID = 1;
  int32 resources = 2;
}

message PGS {
  int32 width = 1;
  int32 height = 2;
  string terrain = 3;
  repeated player players = 4;
  repeated unit units = 5;
}

message action {
  int32 type = 1;
  int32 parameter = 2;
}

message actions {
  int32 ID = 1;
  int32 time = 2;
  action action = 3;
}

message state {
  int32 time = 1;
  PGS pgs = 2;
  repeated actions actions = 3;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions