Entities respect their parent's transforms again

master
Joey Pollack 3 years ago
parent 4b9bbc8991
commit f16ce840b2

@ -15,6 +15,10 @@
namespace lunarium { namespace editor
{
// TODO: Add an X button on the right of the title line to remove components
// Will need to have the functions return a bool indicating when this
// button is pressed
/////////////////////////////////////////////////////////////////////
// COMMON SECTIONS
/////////////////////////////////////////////////////////////////////

@ -151,7 +151,8 @@ namespace lunarium { namespace editor
void PropertiesView::ShowEntity()
{
ImGui::Text("UUID: %ull", (u64)mpSelectedEntity->GetUUID());
LUUID id = mpSelectedEntity->GetUUID();
ImGui::Text("UUID: %llu", (u64)id);
char buffer[256] = { 0 };
strcpy(buffer, mpSelectedEntity->GetName().c_str());
ImGui::Text("Name:");

@ -16,15 +16,14 @@ namespace lunarium
Entity::Entity(World& w)
: mHandle(entt::null), mWorld(w), mParent(0), mParentSet(false)
{
mUUID = UUID::GetNewID();
Init();
}
Entity::Entity(World& w, LUUID uuid, entt::entity handle)
: mHandle(handle), mWorld(w), mUUID(uuid)
{
Init();
}
// Entity::Entity(World& w, entt::entity handle)
// : mHandle(handle), mWorld(w)
// {
// Init();
// }
void Entity::Init()
{
@ -35,11 +34,14 @@ namespace lunarium
{
Logger::Warn(LogCategory::GAME_SYSTEM, "Requested entity handle was not used");
}
AddComponent<UUIDComponent>(UUID::GetNewID());
}
LUUID Entity::GetUUID() const
LUUID Entity::GetUUID()
{
return mUUID;
return GetComponent<UUIDComponent>().UUID;
// return mUUID;
}
entt::entity Entity::GetEnttHandle() const
@ -68,7 +70,7 @@ namespace lunarium
void Entity::AddChild(LUUID child)
{
Entity* e = mWorld.GetEntity(child);
e->AddComponent<ParentEntityComponent>(mUUID);
e->AddComponent<ParentEntityComponent>(GetUUID());
if (!HasComponent<ChildrenComponent>())
{
@ -151,7 +153,7 @@ namespace lunarium
{
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
node["UUID"] = mUUID;
// node["UUID"] = mUUID;
node["name"] = mName;
auto& components = node["components"];
@ -299,7 +301,7 @@ namespace lunarium
{
#if !BUILD_NO_EDITOR // Only does this when this is an editor build
mUUID = node["UUID"].get<u64>();
//mUUID = node["UUID"].get<u64>();
mName = node["name"].get<std::string>();
// TODO: Load components
@ -313,7 +315,11 @@ namespace lunarium
if ("UUIDComponent" == comp_type_name)
{
LUUID uuid = comp["UUID"].get<u64>();
AddComponent<UUIDComponent>(uuid);
//AddComponent<UUIDComponent>(uuid);
if (HasComponent<UUIDComponent>())
{
GetComponent<UUIDComponent>().UUID = uuid;
}
}
if ("TagComponent" == comp_type_name)
@ -433,8 +439,8 @@ namespace lunarium
bool Entity::IsValidNode(nlohmann::ordered_json& node)
{
if (node["UUID"].is_null()) { return false; }
if (!node["UUID"].is_number()) { return false; }
// if (node["UUID"].is_null()) { return false; }
// if (!node["UUID"].is_number()) { return false; }
return true;
}

@ -22,7 +22,7 @@ namespace lunarium // TODO: : public JSONSerializable
{
public:
Entity(World& w);
Entity(World& w, LUUID uuid, entt::entity handle = entt::null);
//Entity(World& w, entt::entity handle = entt::null);
// These component methods are based on methods from the Hazel engine, written by Cherno
// https://github.com/TheCherno/Hazel/blob/dev/Hazel/src/Hazel/Scene/Entity.h
@ -64,7 +64,7 @@ namespace lunarium // TODO: : public JSONSerializable
mWorld.GetEntityRegistry()->remove<T>(mHandle);
}
LUUID GetUUID() const;
LUUID GetUUID();
entt::entity GetEnttHandle() const;
std::string GetName() const;
void SetName(std::string name);
@ -86,7 +86,7 @@ namespace lunarium // TODO: : public JSONSerializable
[[nodiscard]] virtual nlohmann::ordered_json AsJSON();
private:
LUUID mUUID;
//LUUID mUUID;
LUUID mParent;
bool mParentSet;
std::string mName;

@ -111,9 +111,16 @@ namespace lunarium
Rectangle rect(transform.Position.x, transform.Position.y, blockout.Size.x, blockout.Size.y);
Color color(blockout.Color.x, blockout.Color.y, blockout.Color.z, blockout.Color.w);
// TODO: Get and apply parent transforms
// Get and apply parent transforms
LUUID uuid = mECSRegistry.get<UUIDComponent>(entity).UUID;
Entity* pEnt = GetEntity(uuid);
glm::mat4 parent_transform = glm::mat4(1.0f);
if (pEnt->HasComponent<ParentEntityComponent>())
{
parent_transform = GetParentTransform(uuid);
}
pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), glm::mat4(1.0f));
pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), parent_transform);
}
}

Loading…
Cancel
Save