{"id":25948797,"url":"https://github.com/nglsg/rttm","last_synced_at":"2025-07-08T04:04:10.845Z","repository":{"id":278788609,"uuid":"936560998","full_name":"NGLSG/RTTM","owner":"NGLSG","description":"Blazing-fast C++ reflection powered by pure standard C++ - Zero macros, compiler-automated type introspection","archived":false,"fork":false,"pushed_at":"2025-06-03T09:41:29.000Z","size":162,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T20:37:08.919Z","etag":null,"topics":["c-plus-plus","c-plus-plus-17","cmake","ecs","game-development","high-performance","reflection","serialization","serializations","template-library","zero-overhead"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NGLSG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-21T09:47:23.000Z","updated_at":"2025-06-03T09:41:31.000Z","dependencies_parsed_at":"2025-03-12T15:30:39.630Z","dependency_job_id":"0039058c-5cee-452d-a207-9354acb3ee2d","html_url":"https://github.com/NGLSG/RTTM","commit_stats":null,"previous_names":["nglsg/rttm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NGLSG/RTTM","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NGLSG%2FRTTM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NGLSG%2FRTTM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NGLSG%2FRTTM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NGLSG%2FRTTM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NGLSG","download_url":"https://codeload.github.com/NGLSG/RTTM/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NGLSG%2FRTTM/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264192215,"owners_count":23570734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","c-plus-plus-17","cmake","ecs","game-development","high-performance","reflection","serialization","serializations","template-library","zero-overhead"],"created_at":"2025-03-04T11:22:33.413Z","updated_at":"2025-07-08T04:04:10.839Z","avatar_url":"https://github.com/NGLSG.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"imgs/logo.svg\" alt=\"RTTM Logo\"/\u003e\n\n# RTTM\n**Runtime Turbo Mirror**\n\n  \u003cp\u003e\u003cem\u003e高性能、轻量级的C++17动态反射库\u003c/em\u003e\u003c/p\u003e\n\n[![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)](https://en.cppreference.com/w/cpp/17)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n[![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)]()\n[![Compiler](https://img.shields.io/badge/compiler-MSVC%20%7C%20GCC%20%7C%20Clang-orange.svg)]()\n\n\u003ca href=\"README_EN.md\"\u003e🌐 English\u003c/a\u003e • \u003ca href=\"README.md\"\u003e🇨🇳 中文\u003c/a\u003e\n\u003c/div\u003e\n\n---\n\n## 🎯 概述\n\nRTTM是一个专为**游戏引擎**和**性能敏感应用**设计的现代C++反射库。基于C++17标准，零外部依赖，提供运行时类型信息、动态对象创建和方法调用等核心功能。\n\n## ✨ 核心特性\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd width=\"33%\"\u003e\n\n### 🚀 高性能\n- 比主流库快 **51%**\n- 内存占用减少 **50%**\n- 多线程优化设计\n\n\u003c/td\u003e\n\u003ctd width=\"33%\"\u003e\n\n### 🔧 零依赖\n- 仅需 C++17 标准库\n- 跨平台兼容\n- 支持 MSVC/GCC/Clang\n\n\u003c/td\u003e\n\u003ctd width=\"33%\"\u003e\n\n### 💡 易用性\n- 直观的 API 设计\n- 链式调用支持\n- 自动注册机制\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n**支持反射**：枚举 • 类/结构体 • 模板类 • 全局变量 • 全局函数\n\n## 📊 性能基准\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e🏆 与主流库性能对比\u003c/strong\u003e\u003c/summary\u003e\n\n| 测试维度 | RTTM                                                    | Boost.Hana                                       | RTTR                                              |\n|---------|---------------------------------------------------------|--------------------------------------------------|---------------------------------------------------|\n| **序列化时间** | **2946ms**                                              | 3343ms \u003cspan style=\"color:#e74c3c\"\u003e(+13%)\u003c/span\u003e | 4450ms \u003cspan style=\"color:#e74c3c\"\u003e(+51%)\u003c/span\u003e  |\n| **属性访问** | **1.5ns**                                               | 1.5ns                                            | 13.7ns \u003cspan style=\"color:#e74c3c\"\u003e(+813%)\u003c/span\u003e |\n| **多线程吞吐** | **1354 ops/ms**                                         | 896 ops/ms                                       | 459 ops/ms                                        |\n| **内存效率** | **4 KB/千对象**                                            | 8 KB/千对象                                         | 8 KB/千对象                                          |\n|**对象创建**| 271us/千对象 \u003cspan style=\"color:#e74c3c\"\u003e(+3387.5%)\u003c/span\u003e | **8us/千对象**                                      | **7us/千对象**                                       |\n\n\u003e 🔬 **测试环境**：MSVC Release模式，基于100w对象操作场景\n\u003c/details\u003e\n\n## 🚀 快速开始\n\n### 1️⃣ 引入头文件\n\n```cpp\n#include \"RTTM/RTTM.hpp\"\nusing namespace RTTM;\n```\n\n### 2️⃣ 注册类型\n\n```cpp\nclass Person {\npublic:\n    std::string name;\n    int age = 0;\n    \n    Person() = default;\n    Person(const std::string\u0026 n, int a) : name(n), age(a) {}\n    \n    std::string greeting() { return \"Hello, I'm \" + name; }\n};\n\n// 注册反射信息\nRTTM_REGISTRATION {\n    Registry_\u003cPerson\u003e()\n        .property(\"name\", \u0026Person::name)\n        .property(\"age\", \u0026Person::age)\n        .method(\"greeting\", \u0026Person::greeting)\n        .constructor\u003c\u003e()\n        .constructor\u003cconst std::string\u0026, int\u003e();\n}\n```\n\n### 3️⃣ 动态操作\n\n```cpp\n// 获取类型并创建实例\nauto personType = RType::Get\u003cPerson\u003e();\nauto result = personType-\u003eCreate(\"Alice\", 30);\n\n// 属性操作\npersonType-\u003eGetProperty\u003cstd::string\u003e(\"name\") = \"Bob\";\nint age = personType-\u003eGetProperty\u003cint\u003e(\"age\");\n\n// 方法调用\nstd::string greeting = personType-\u003eInvoke\u003cstd::string\u003e(\"greeting\");\n```\n\n## 🎮 ECS系统示例\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e💡 查看完整的实体组件系统实现\u003c/strong\u003e\u003c/summary\u003e\n\n```cpp\n#include \"RTTM/Entity.hpp\"\n\n// 健康组件\nclass Health : public RTTM::Component\u003cHealth\u003e {\npublic:\n    int hp = 100;\n    Health(int h = 100) : hp(h) {}\n    \n    std::string GetTypeName() const override { return \"Health\"; }\n    std::type_index GetTypeIndex() const override { return std::type_index(typeid(Health)); }\n};\n\n// 武器系统（抽象组件）\nclass WeaponSystem : public RTTM::SingletonComponent\u003cWeaponSystem\u003e {\npublic:\n    COMPONENT_DEPENDENCIES(Health) // 声明依赖\n    \n    int damage = 10;\n    virtual void Attack() = 0;\n    \n    std::string GetTypeName() const override { return \"WeaponSystem\"; }\n    std::type_index GetTypeIndex() const override { return std::type_index(typeid(WeaponSystem)); }\n};\n\n// 具体武器实现\nclass Sword : public WeaponSystem {\npublic:\n    Sword() { damage = 30; }\n    void Attack() override { std::cout \u003c\u003c \"剑击！伤害:\" \u003c\u003c damage \u003c\u003c std::endl; }\n    std::string GetTypeName() const override { return \"Sword\"; }\n    std::type_index GetTypeIndex() const override { return std::type_index(typeid(Sword)); }\n};\n\n// 战士实体\nclass Fighter : REQUIRE_COMPONENTS(WeaponSystem) {\npublic:\n    void Attack() {\n        GetComponentDynamic\u003cWeaponSystem\u003e().Attack();\n    }\n    \n    template\u003ctypename T\u003e\n    void ChangeWeapon() {\n        SwapComponent\u003cWeaponSystem, T\u003e();\n    }\n};\n\n// 使用示例\nint main() {\n    Fighter player;\n    player.AddComponent\u003cHealth\u003e(80);\n    player.AddComponent\u003cSword\u003e();\n    \n    player.Attack();              // 剑击！伤害:30\n    player.ChangeWeapon\u003cGun\u003e();   // 动态切换武器\n    player.Attack();              // 射击！伤害:20\n}\n```\n\u003c/details\u003e\n\n## 🔄 序列化支持\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003e📝 JSON序列化示例\u003c/strong\u003e\u003c/summary\u003e\n\n```cpp\n#include \u003cnlohmann/json.hpp\u003e\nusing json = nlohmann::json;\n\n// 通用序列化函数\njson ToJson(const RType\u0026 type) {\n    json j;\n    for (const auto\u0026 name : type.GetPropertyNames()) {\n        auto prop = type.GetProperty(name);\n        if (prop-\u003eIs\u003cint\u003e()) j[name] = prop-\u003eAs\u003cint\u003e();\n        else if (prop-\u003eIs\u003cstd::string\u003e()) j[name] = prop-\u003eAs\u003cstd::string\u003e();\n        else if (prop-\u003eIsClass()) j[name] = ToJson(*prop);\n    }\n    return j;\n}\n\n// 通用反序列化函数\nvoid FromJson(const RType\u0026 type, const json\u0026 j) {\n    for (const auto\u0026 name : type.GetPropertyNames()) {\n        if (j.contains(name)) {\n            auto prop = type.GetProperty(name);\n            if (prop-\u003eIs\u003cint\u003e()) prop-\u003eSetValue(j[name].get\u003cint\u003e());\n            else if (prop-\u003eIsClass()) FromJson(*prop, j[name]);\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n## ⚙️ 构建集成\n\n### 系统要求\n- **C++17** 或更高版本\n- **编译器**：MSVC 2019+ / GCC 7+ / Clang 5+\n- **平台**：Windows / Linux / macOS\n\n### CMake集成\n\n```cmake\n# 添加RTTM\nadd_executable(MyProject main.cpp)\ntarget_link_libraries(MyProject PRIVATE RTTM)\n\n# 启用自动反射生成\ninclude(\u003cRTTM_PATH\u003e/cmake/reflection.cmake)\nrttm_add_reflection(MyProject)\n```\n\n### 手动集成\n\n```bash\n# 1. 克隆仓库\ngit clone https://github.com/NGLSG/RTTM.git\n\n# 2. 添加到项目\n# 将RTTM文件夹复制到项目中\n\n# 3. 编译选项\n# GCC/Clang: -std=c++17\n# MSVC: /std:c++17\n```\n\n## 📚 高级特性\n\n\u003cdiv align=\"center\"\u003e\n\n| 特性 | 说明 | 示例 |\n|------|------|------|\n| **枚举反射** | 支持枚举值的动态访问 | `Enum::Get\u003cMyEnum\u003e()` |\n| **模板类** | 支持模板类型反射 | `Registry_\u003cVec\u003cint\u003e\u003e()` |\n| **全局函数** | 注册和调用全局函数 | `Global::RegisterMethod()` |\n| **继承支持** | 支持类继承关系反射 | `base()` 链式调用 |\n| **自动依赖** | ECS组件自动依赖管理 | `COMPONENT_DEPENDENCIES()` |\n\n\u003c/div\u003e\n\n## 🤝 贡献指南\n\n我们欢迎所有形式的贡献！\n\n1. 🍴 **Fork** 本仓库\n2. 🌿 创建特性分支：`git checkout -b feature/amazing-feature`\n3. 💾 提交更改：`git commit -m 'Add amazing feature'`\n4. 📤 推送分支：`git push origin feature/amazing-feature`\n5. 🔄 创建 **Pull Request**\n\n## 📄 许可证\n\n本项目采用 [MIT许可证](LICENSE) - 查看文件了解详情\n\n---\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e🌟 为高性能应用打造的现代C++反射解决方案\u003c/h3\u003e\n\n**Made with ❤️ by [NGLSG](https://github.com/NGLSG)**\n\n[![Star](https://img.shields.io/github/stars/NGLSG/RTTM?style=social)](https://github.com/NGLSG/RTTM)\n[![Fork](https://img.shields.io/github/forks/NGLSG/RTTM?style=social)](https://github.com/NGLSG/RTTM/fork)\n[![Watch](https://img.shields.io/github/watchers/NGLSG/RTTM?style=social)](https://github.com/NGLSG/RTTM)\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnglsg%2Frttm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnglsg%2Frttm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnglsg%2Frttm/lists"}