docs: 更新 containers 和 threading 模块文档
- containers: 更新 string 类的多个方法文档 - threading: 更新 mutex 和 task-group 方法文档
This commit is contained in:
@@ -66,6 +66,8 @@ public:
|
||||
|
||||
void Save(const std::string& filePath);
|
||||
void Load(const std::string& filePath);
|
||||
std::string SerializeToString() const;
|
||||
void DeserializeFromString(const std::string& data);
|
||||
|
||||
Core::Event<GameObject*>& OnGameObjectCreated() { return m_onGameObjectCreated; }
|
||||
Core::Event<GameObject*>& OnGameObjectDestroyed() { return m_onGameObjectDestroyed; }
|
||||
@@ -112,4 +114,4 @@ private:
|
||||
};
|
||||
|
||||
} // namespace Components
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user