Prepare script lifecycle and data layer

This commit is contained in:
2026-03-26 20:14:58 +08:00
parent 5ca5ca1f19
commit 0921f2a459
20 changed files with 1367 additions and 26 deletions

View File

@@ -18,6 +18,7 @@ struct PendingComponentData {
struct PendingGameObjectData {
GameObject::ID id = GameObject::INVALID_ID;
uint64_t uuid = 0;
std::string name = "GameObject";
bool active = true;
GameObject::ID parentId = GameObject::INVALID_ID;
@@ -70,6 +71,7 @@ void SerializeGameObjectRecursive(std::ostream& os, GameObject* gameObject) {
os << "gameobject_begin\n";
os << "id=" << gameObject->GetID() << "\n";
os << "uuid=" << gameObject->GetUUID() << "\n";
os << "name=" << EscapeString(gameObject->GetName()) << "\n";
os << "active=" << (gameObject->IsActive() ? 1 : 0) << "\n";
os << "parent=" << (gameObject->GetParent() ? gameObject->GetParent()->GetID() : GameObject::INVALID_ID) << "\n";
@@ -219,6 +221,7 @@ std::vector<GameObject*> Scene::GetRootGameObjects() const {
void Scene::Update(float deltaTime) {
for (auto* go : GetRootGameObjects()) {
if (go->IsActiveInHierarchy()) {
go->Start();
go->Update(deltaTime);
}
}
@@ -285,6 +288,8 @@ void Scene::DeserializeFromString(const std::string& data) {
if (key == "id") {
currentObject->id = static_cast<GameObject::ID>(std::stoull(value));
maxId = std::max(maxId, currentObject->id);
} else if (key == "uuid") {
currentObject->uuid = std::stoull(value);
} else if (key == "name") {
currentObject->name = UnescapeString(value);
} else if (key == "active") {
@@ -312,6 +317,9 @@ void Scene::DeserializeFromString(const std::string& data) {
for (const PendingGameObjectData& pending : pendingObjects) {
auto go = std::make_unique<GameObject>(pending.name);
go->m_id = pending.id;
if (pending.uuid != 0) {
go->m_uuid = pending.uuid;
}
go->m_activeSelf = pending.active;
go->m_scene = this;