C++ API#203
Conversation
…t/final-tournament
| result = game_self.score | ||
| else: | ||
| result = game_other.display_score | ||
| result = game_other.score |
There was a problem hiding this comment.
This is intentional. Please change it back.
If the behavior mismatches then something else is wrong.
| # 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") |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
Makefiles should not execute sudo. Ask the user to do that instead (sudo make install).
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| std::string toString() const { | ||
| return "(" + std::to_string(x) + ", " + std::to_string(y) + ")"; | ||
| } |
There was a problem hiding this comment.
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.
| 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; | ||
| }; |
There was a problem hiding this comment.
These types really look like unnecessary bloat and why don't we just use C++ built-in types?
| CLIENT_ERR = 501 | ||
| }; | ||
|
|
||
| const std::unordered_map<int, std::string> StatusCodeToString = { |
There was a problem hiding this comment.
We need to discuss the naming conventions in C++. Nevertheless, this should be either all uppercases or lowercases with underscores.
|
I converted the PR to draft first. After dealing with the above problems, I will click ready again. |
- The code is not working yet, but this is a step towards a header-only library.
新增給 C++ 使用的 API。