Worked a bit on prefabs of all things

This commit is contained in:
2024-09-10 18:26:14 -05:00
parent e5f3f69120
commit 0e5b85633c
23 changed files with 286 additions and 19 deletions

View File

@ -16,6 +16,8 @@ target_sources(${DAWN_TARGET_NAME}
)
# Subdirs
add_subdirectory(component)
add_subdirectory(prefab)
add_subdirectory(scenes)
# Assets

View File

@ -0,0 +1,7 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
add_subdirectory(entity)
add_subdirectory(world)

View File

@ -0,0 +1,9 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Entity.cpp
)

View File

@ -0,0 +1,18 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Entity.hpp"
#include "assert/assert.hpp"
using namespace Dawn;
void Entity::onInit() {
auto world = this->world.lock();
assertNotNull(world, "World is no longer active.");
}
void Entity::onDispose() {
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneComponent.hpp"
typedef uint32_t entityid_t;
namespace Dawn {
class World;
class Entity final : public SceneComponent {
public:
std::weak_ptr<World> world;
void onInit() override;
void onDispose() override;
};
}

View File

@ -0,0 +1,9 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
World.cpp
)

View File

@ -0,0 +1,14 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "World.hpp"
using namespace Dawn;
void World::onInit() {
}
void World::onDispose() {
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "component/entity/Entity.hpp"
namespace Dawn {
class World : public SceneComponent {
private:
std::map<entityid_t, std::shared_ptr<Entity>> entities;
public:
void onInit() override;
void onDispose() override;
};
}

View File

@ -8,5 +8,5 @@
using namespace Dawn;
const std::function<void(Scene&)> Scene::getInitialScene() {
return Dawn::testScene;
return Dawn::worldScene;
}

View File

@ -0,0 +1,10 @@
# Copyright (c) 2024 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
target_sources(${DAWN_TARGET_NAME}
PRIVATE
PlayerPrefab.cpp
WorldPrefab.cpp
)

View File

@ -0,0 +1,20 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PlayerPrefab.hpp"
using namespace Dawn;
struct PlayerPrefab Dawn::createPlayerPrefab(
const std::shared_ptr<World> world
) {
struct PlayerPrefab player;
player.item = world->getScene()->createSceneItem();
player.entity = player.item->addComponent<Entity>();
player.entity->world = world;
return player;
}

View File

@ -0,0 +1,17 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "prefab/Prefab.hpp"
#include "component/world/World.hpp"
namespace Dawn {
struct PlayerPrefab : public Prefab {
public:
std::shared_ptr<Entity> entity;
};
struct PlayerPrefab createPlayerPrefab(const std::shared_ptr<World> world);
}

View File

@ -0,0 +1,17 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "WorldPrefab.hpp"
using namespace Dawn;
struct WorldPrefab Dawn::createWorldPrefab(Scene &s) {
struct WorldPrefab world;
world.item = s.createSceneItem();
world.world = world.item->addComponent<World>();
return world;
}

View File

@ -0,0 +1,17 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "prefab/Prefab.hpp"
#include "component/world/World.hpp"
namespace Dawn {
struct WorldPrefab : public Prefab {
public:
std::shared_ptr<World> world;
};
struct WorldPrefab createWorldPrefab(Scene &scene);
}

View File

@ -6,4 +6,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
TestScene.cpp
WorldScene.cpp
)

View File

@ -8,4 +8,5 @@
namespace Dawn {
void testScene(Scene &scene);
void worldScene(Scene &scene);
}

View File

@ -0,0 +1,46 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "scenes/SceneList.hpp"
#include "prefab/PlayerPrefab.hpp"
#include "prefab/WorldPrefab.hpp"
// #include "component/display/Camera.hpp"
// #include "prefab/SimpleSpinningCube.hpp"
// #include "component/display/material/SimpleTexturedMaterial.hpp"
// #include "display/mesh/CubeMesh.hpp"
// #include "component/ui/UICanvas.hpp"
// #include "ui/elements/UIRectangle.hpp"
// #include "ui/elements/UILabel.hpp"
// #include "ui/UIMenu.hpp"
// #include "ui/container/UIRowContainer.hpp"
// #include "ui/container/UIPaddingContainer.hpp"
// #include "poker/PokerGame.hpp"
using namespace Dawn;
void Dawn::worldScene(Scene &s) {
// auto cameraItem = s.createSceneItem();
// auto camera = cameraItem->addComponent<Camera>();
// cameraItem->lookAt({ 3, 3, 3 }, { 0, 0, 0 }, { 0, 1, 0 });
// camera->clipFar = 99999.99f;
// auto cube = s.createSceneItem();
// auto cubeMesh = std::make_shared<Mesh>();
// auto cubeRenderer = cube->addComponent<MeshRenderer>();
// auto cubeMaterial = cube->addComponent<SimpleTexturedMaterial>();
// cubeRenderer->mesh = cubeMesh;
// cubeMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
// CubeMesh::buffer(cubeMesh, glm::vec3(0,0,0), glm::vec3(1, 1, 1), 0, 0);
// auto canvasItem = s.createSceneItem();
// auto canvas = canvasItem->addComponent<UICanvas>();
auto world = createWorldPrefab(s);
auto player = createPlayerPrefab(world.world);
}