Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

C++ API#203

Closed
mtmatt wants to merge 28 commits into
developfrom
feat/cpp-api
Closed

C++ API#203
mtmatt wants to merge 28 commits into
developfrom
feat/cpp-api

Conversation

@mtmatt

@mtmatt mtmatt commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

新增給 C++ 使用的 API。

@mtmatt mtmatt requested a review from HyperSoWeak July 25, 2025 09:00
Comment thread scripts/agents/agent.gd
result = game_self.score
else:
result = game_other.display_score
result = game_other.score

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. Please change it back.
If the behavior mismatches then something else is wrong.

Comment thread scripts/chat.gd
Comment on lines +53 to 58
# TODO: re-enable this after the tournament
if (
text.contains("start-process powershell --verb runAs")
false and text.contains("start-process powershell --verb runAs")
or text.contains("start-process powershell –verb runAs")
):
get_tree().change_scene_to_file("res://scenes/maps/water/storyline-triggered.tscn")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some workarounds and potential hacks or tweaks left by the final tournament that might be left unchecked. I suggest merging this PR after all the dust has settled.

Comment thread agent/cpp_api/Makefile Outdated
Comment on lines +61 to +74
# Install libraries and headers
install: $(STATIC_LIB) $(SHARED_LIB)
sudo mkdir -p /usr/local/lib
sudo mkdir -p /usr/local/include/game_api
sudo cp $(STATIC_LIB) $(SHARED_LIB) /usr/local/lib/
sudo cp $(HEADERS) /usr/local/include/game_api/
sudo ldconfig

# Uninstall
uninstall:
sudo rm -f /usr/local/lib/$(STATIC_LIB)
sudo rm -f /usr/local/lib/$(SHARED_LIB)
sudo rm -rf /usr/local/include/game_api
sudo ldconfig

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefiles should not execute sudo. Ask the user to do that instead (sudo make install).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, now I think about it, we should make it a header-only library so there will be no hassle compiling, installing, and building. And that is easier to use and maintain.

Comment thread agent/cpp_api/example.cpp Outdated
Comment on lines +194 to +200
std::cout << "\n--- Test Summary ---" << std::endl;
std::cout << "✓ All major API categories tested!" << std::endl;
std::cout << "✓ Connection and authentication working" << std::endl;
std::cout << "✓ Game state information retrieval working" << std::endl;
std::cout << "✓ Enemy parsing fix successful" << std::endl;
std::cout << "✓ Tower management APIs functional" << std::endl;
std::cout << "✓ Unit and spell systems accessible" << std::endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this summary useful? It did not take into account of all previous testing results.
By the way, I do not think using Unicode characters in C++ examples will be great.

Comment thread agent/cpp_api/structures.h Outdated
Comment on lines +17 to +19
std::string toString() const {
return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python equivalent __str__ is actually not used anywhere and not that handy.
I would rather overload those for basic_ostream operator<< or remove them.

Comment thread agent/cpp_api/varient.h Outdated
Comment on lines +47 to +160
class GodotNull : public GodotVariant {
public:
GodotNull() {}

std::vector<uint8_t> serialize() const override {
std::vector<uint8_t> result;
GodotSerializer::push_int32(result, static_cast<int32_t>(TypeCode::NULL_TYPE));
return result;
}

TypeCode getType() const override { return TypeCode::NULL_TYPE; }
};

class GodotBool : public GodotVariant {
public:
GodotBool(bool v) : value(v) {}

std::vector<uint8_t> serialize() const override {
std::vector<uint8_t> result;
GodotSerializer::push_int32(result, static_cast<int32_t>(TypeCode::BOOL_TYPE));
GodotSerializer::push_int32(result, value ? 1 : 0);
return result;
}

TypeCode getType() const override { return TypeCode::BOOL_TYPE; }
bool getValue() const { return value; }

private:
bool value;
};

class GodotInt : public GodotVariant {
public:
GodotInt(int64_t v) : value(v) {}
GodotInt(int v) : value(static_cast<int64_t>(v)) {}

std::vector<uint8_t> serialize() const override {
std::vector<uint8_t> result;

uint32_t header = static_cast<uint32_t>(TypeCode::INT_TYPE);

// Check if value fits in 32-bit range
if (value > INT32_MAX || value < INT32_MIN) {
// 64-bit integer serialization
header |= HEADER_DATA_FLAG_64;
GodotSerializer::push_int32(result, static_cast<int32_t>(header));
GodotSerializer::push_int64(result, value);
} else {
// 32-bit integer serialization
GodotSerializer::push_int32(result, static_cast<int32_t>(header));
GodotSerializer::push_int32(result, static_cast<int32_t>(value));
}

return result;
}

TypeCode getType() const override { return TypeCode::INT_TYPE; }
int64_t getValue() const { return value; }

private:
int64_t value;
};

class GodotFloat : public GodotVariant {
public:
GodotFloat(double v) : value(v) {}
GodotFloat(float v) : value(static_cast<double>(v)) {}

std::vector<uint8_t> serialize() const override {
std::vector<uint8_t> result;

uint32_t header = static_cast<uint32_t>(TypeCode::FLOAT_TYPE);
float f = static_cast<float>(value);

if (static_cast<double>(f) != value) {
// Need 64-bit precision
header |= HEADER_DATA_FLAG_64;
GodotSerializer::push_int32(result, static_cast<int32_t>(header));
GodotSerializer::push_double(result, value);
} else {
// 32-bit precision is sufficient
GodotSerializer::push_int32(result, static_cast<int32_t>(header));
GodotSerializer::push_float(result, f);
}

return result;
}

TypeCode getType() const override { return TypeCode::FLOAT_TYPE; }
double getValue() const { return value; }
float getValueAsFloat() const { return static_cast<float>(value); }

private:
double value;
};

class GodotString : public GodotVariant {
public:
GodotString(const std::string& v) : value(v) {}
GodotString(const char* v) : value(v) {}

std::vector<uint8_t> serialize() const override {
std::vector<uint8_t> result;
GodotSerializer::push_int32(result, static_cast<int32_t>(TypeCode::STRING_TYPE));
GodotSerializer::push_string(result, value);
return result;
}

TypeCode getType() const override { return TypeCode::STRING_TYPE; }
const std::string& getValue() const { return value; }

private:
std::string value;
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types really look like unnecessary bloat and why don't we just use C++ built-in types?

Comment thread agent/cpp_api/constants.h Outdated
CLIENT_ERR = 501
};

const std::unordered_map<int, std::string> StatusCodeToString = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to discuss the naming conventions in C++. Nevertheless, this should be either all uppercases or lowercases with underscores.

@littlecube8152 littlecube8152 changed the title Feat/cpp api C++ API Jul 25, 2025
@mtmatt mtmatt marked this pull request as draft July 25, 2025 14:25
@mtmatt

mtmatt commented Jul 25, 2025

Copy link
Copy Markdown
Contributor Author

I converted the PR to draft first. After dealing with the above problems, I will click ready again.

mtmatt added 2 commits July 26, 2025 07:39
- The code is not working yet, but this is a step towards a header-only library.
@mtmatt mtmatt closed this Nov 21, 2025
@PixelCat31415 PixelCat31415 deleted the feat/cpp-api branch March 9, 2026 13:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants