Prepare script lifecycle and data layer
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user