docs: 更新 containers 和 threading 模块文档

- containers: 更新 string 类的多个方法文档
- threading: 更新 mutex 和 task-group 方法文档
This commit is contained in:
2026-03-26 01:59:14 +08:00
parent 8df04c120f
commit 5c3566774b
42 changed files with 714 additions and 96 deletions

View File

@@ -264,22 +264,18 @@ void Scene::LateUpdate(float deltaTime) {
}
}
void Scene::Load(const std::string& filePath) {
std::ifstream file(filePath);
if (!file.is_open()) {
return;
}
void Scene::DeserializeFromString(const std::string& data) {
m_gameObjects.clear();
m_rootGameObjects.clear();
m_gameObjectIDs.clear();
std::vector<PendingGameObjectData> pendingObjects;
std::istringstream input(data);
std::string line;
PendingGameObjectData* currentObject = nullptr;
GameObject::ID maxId = 0;
while (std::getline(file, line)) {
while (std::getline(input, line)) {
if (line.empty() || line[0] == '#') continue;
if (line == "gameobject_begin") {
@@ -389,20 +385,39 @@ void Scene::Load(const std::string& filePath) {
}
}
std::string Scene::SerializeToString() const {
std::ostringstream output;
output << "# XCEngine Scene File\n";
output << "scene=" << EscapeString(m_name) << "\n";
output << "active=" << (m_active ? "1" : "0") << "\n\n";
for (auto* go : GetRootGameObjects()) {
SerializeGameObjectRecursive(output, go);
output << "\n";
}
return output.str();
}
void Scene::Load(const std::string& filePath) {
std::ifstream file(filePath);
if (!file.is_open()) {
return;
}
std::stringstream buffer;
buffer << file.rdbuf();
DeserializeFromString(buffer.str());
}
void Scene::Save(const std::string& filePath) {
std::ofstream file(filePath);
if (!file.is_open()) {
return;
}
file << "# XCEngine Scene File\n";
file << "scene=" << EscapeString(m_name) << "\n";
file << "active=" << (m_active ? "1" : "0") << "\n\n";
for (auto* go : GetRootGameObjects()) {
SerializeGameObjectRecursive(file, go);
file << "\n";
}
file << SerializeToString();
}
} // namespace Components