Farama-Foundation / Farama-Foundation/MicroRTS

Implement socket communication via protocol buffers

Open
#49 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
360
Forks
134
PR merge metrics
No merged PRs in 30d

Description

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](https://developers.google.com/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](https://auth0.com/blog/beating-json-performance-with-protobuf/) 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?

```proto
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;
}
```

Contributor guide

Open the contributing guide

Research direction

The issue provides a proposed .proto schema but names no repository files or tests. Start by locating MicroRTS's existing socket message path and comparing its XML/JSON serialization with the proposed schema. Done would require an agreed integration scope and demonstrated protobuf-based state and action communication with a performance comparison.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.