Moved Scene implementation around

This commit is contained in:
2023-02-21 20:59:42 -08:00
parent fc14618f38
commit 38527a7de6
42 changed files with 540 additions and 459 deletions

View File

@ -5,7 +5,6 @@
#include "RenderPipeline.hpp"
#include "game/DawnGame.hpp"
#include "display/RenderManager.hpp"
using namespace Dawn;

View File

@ -5,8 +5,6 @@
#pragma once
#include "dawnlibs.hpp"
#include "scene/SceneItem.hpp"
#include "scene/Scene.hpp"
#include "scene/components/display/Material.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/Camera.hpp"

View File

@ -12,7 +12,6 @@
#include "time/TimeManager.hpp"
#include "input/InputBinds.hpp"
#include "locale/LocaleManager.hpp"
#include "physics/PhysicsManager.hpp"
#include "save/SaveManager.hpp"
#include "audio/AudioManager.hpp"

View File

@ -0,0 +1,15 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Box.hpp"
using namespace Dawn;
bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max) {
return (
point.x >= min.x && point.x <= max.x &&
point.y >= min.y && point.y <= max.y
);
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
/**
* Checks if a given point is within the 2D Boundaries of an object.
*
* @param point Point to test.
* @param min Minimum point on the box.
* @param max Maximum point on the box.
* @return True if the point is within the box.
*/
static bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max);
}

View File

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

View File

@ -4,14 +4,9 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp
namespace Dawn {
class DawnGame;
class PhysicsManager {
public:
DawnGame *game;
PhysicsManager(DawnGame *game);
};
}

View File

View File

@ -6,8 +6,9 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
PhysicsManager.cpp
ScenePhysicsManager.cpp
)
# Subdirs
add_subdirectory(2d)
add_subdirectory(3d)

View File

@ -0,0 +1,17 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "ScenePhysicsManager.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;
ScenePhysicsManager::ScenePhysicsManager() {
}
void ScenePhysicsManager::update() {
}

View File

@ -0,0 +1,29 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "scene/SceneItem.hpp"
typedef int64_t scenechunk_t;
#define SCENE_CHUNK_SIZE_2D 512
namespace Dawn {
class Scene;
class ScenePhysicsManager {
protected:
std::map<scenechunk_t, std::vector<SceneItem*>> chunkItems;
std::map<SceneItem*, std::vector<scenechunk_t>> itemChunks;
public:
ScenePhysicsManager();
void update();
friend class Scene;
};
}

View File

@ -6,7 +6,6 @@
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "Card.hpp"
#include "scene/Scene.hpp"
#include "PokerPot.hpp"
#include "util/mathutils.hpp"
#include "display/animation/Easing.hpp"

View File

@ -5,7 +5,7 @@
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/Scene.hpp"
#include "scene/SceneItemComponent.hpp"
#include "util/array.hpp"
namespace Dawn {

View File

@ -5,7 +5,6 @@
#pragma once
#include "Prefab.hpp"
#include "scene/SceneItem.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {

View File

@ -4,6 +4,8 @@
// https://opensource.org/licenses/MIT
#include "Scene.hpp"
#include "SceneItem.hpp"
#include "SceneItemComponent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -4,13 +4,19 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "SceneItem.hpp"
#include "event/Event.hpp"
#include "asset/Asset.hpp"
namespace Dawn {
class DawnGame;
class RenderPipeline;
class SceneItem;
class SceneItemComponent;
typedef int32_t sceneitemid_t;
template<class T>
T * _sceneForwardGetComponent(SceneItem *item);
class Scene {
private:
@ -84,13 +90,13 @@ namespace Dawn {
T * findComponent() {
auto it = this->itemsNotInitialized.begin();
while(it != this->itemsNotInitialized.end()) {
auto component = it->second->getComponent<T>();
auto component = _sceneForwardGetComponent<T>(it->second);
if(component != nullptr) return component;
++it;
}
auto it2 = this->items.begin();
while(it2 != this->items.end()) {
auto component = it2->second->getComponent<T>();
auto component = _sceneForwardGetComponent<T>(it2->second);
if(component != nullptr) return component;
++it2;
}
@ -110,14 +116,14 @@ namespace Dawn {
auto it = this->itemsNotInitialized.begin();
while(it != this->itemsNotInitialized.end()) {
auto component = it->second->getComponent<T>();
auto component = _sceneForwardGetComponent<T>(it->second);
if(component != nullptr) components.push_back(component);
++it;
}
auto it2 = this->items.begin();
while(it2 != this->items.end()) {
auto component = it2->second->getComponent<T>();
auto component = _sceneForwardGetComponent<T>(it2->second);
if(component != nullptr) components.push_back(component);
++it2;
}

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#include "SceneItem.hpp"
#include "Scene.hpp"
#include "SceneItemComponent.hpp"
using namespace Dawn;

View File

@ -4,14 +4,12 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "SceneItemComponent.hpp"
#include "display/Transform.hpp"
#include "event/Event.hpp"
#include "scene/Scene.hpp"
namespace Dawn {
typedef int32_t sceneitemid_t;
class Scene;
class SceneItemComponent;
class SceneItem {
private:

View File

@ -6,10 +6,9 @@
#pragma once
#include "dawnlibs.hpp"
#include "display/Transform.hpp"
#include "scene/SceneItem.hpp"
namespace Dawn {
class SceneItem;
class Scene;
class DawnGame;
class SceneItemComponent {
@ -70,4 +69,11 @@ namespace Dawn {
*/
~SceneItemComponent();
};
template<class T>
T * _sceneForwardGetComponent(SceneItem *item) {
return item->getComponent<T>();
}
}

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "AnimationController.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "Camera.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "Material.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "SimpleRenderTargetQuad.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "ExampleSpin.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "display/mesh/CubeMesh.hpp"

View File

@ -3,11 +3,10 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PhysicsManager.hpp"
#include "game/DawnGame.hpp"
#include "BoxCollider.hpp"
using namespace Dawn;
PhysicsManager::PhysicsManager(DawnGame *game) {
this->game = game;
BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) {
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Collider2D.hpp"
#include "physics/2d/Box.hpp"
namespace Dawn {
class BoxCollider : public Collider2D {
public:
glm::vec2 min = glm::vec2(-0.5f, -0.5f);
glm::vec2 max = glm::vec2( 0.5f, 0.5f);
BoxCollider(SceneItem *item);
};
}

View File

@ -6,6 +6,6 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
BoxCollider.cpp
Collider2D.cpp
Ray2D.cpp
)

View File

@ -4,10 +4,10 @@
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
RayTester3D.cpp
)
# target_sources(${DAWN_TARGET_NAME}
# PRIVATE
# RayTester3D.cpp
# )
# Subdirs
add_subdirectory(collider)

View File

@ -1,44 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "RayTester3D.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;
RayTester3D::RayTester3D(SceneItem *item) : SceneItemComponent(item) {
}
void RayTester3D::onStart() {
this->getScene()->eventSceneUpdate.addListener(this, &RayTester3D::onUpdate);
}
void RayTester3D::onUpdate() {
prefab->transform.setLocalPosition(glm::vec3(0, 0, 0));
triangle.v0 = glm::vec3(-0.5f, -0.5f, 0);
triangle.v1 = glm::vec3(0.5f, -0.5f, 0);
triangle.v2 = glm::vec3(0, 0.5f, 0);
auto mouse = this->getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
mouse *= 2.0f;
mouse -= glm::vec2(1, 1);
glm::vec3 pos = glm::vec3(mouse.x * camera->orthoRight, mouse.y * camera->orthoBottom, 0.0f);
ray.direction = glm::vec3(0, 0, -15);
ray.origin = pos;
// prefab->transform.setLocalPosition(pos);
// ray.origin = glm::vec3(0, 0, 5);
bool_t x = raytestTriangle(ray, triangle, &hit, &normal, &distance);
if(x) {
prefab->material->color = COLOR_RED;
} else {
prefab->material->color = COLOR_WHITE;
}
}

View File

@ -1,27 +0,0 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "physics/3d/Ray3D.hpp"
#include "scene/components/display/Camera.hpp"
namespace Dawn {
class RayTester3D : public SceneItemComponent {
public:
SimpleSpinningCubePrefab *prefab;
Camera *camera;
struct PhysicsTriangle triangle;
struct Ray3D ray;
glm::vec3 hit;
glm::vec3 normal;
float_t distance;
RayTester3D(SceneItem *item);
void onStart() override;
void onUpdate();
};
}

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
#include "scene/SceneItemComponent.hpp"
namespace Dawn {
class SubSceneController : public SceneItemComponent {

View File

@ -4,7 +4,6 @@
// https://opensource.org/licenses/MIT
#include "UICanvas.hpp"
#include "scene/Scene.hpp"
#include "ui/UIComponent.hpp"
#include "game/DawnGame.hpp"
#include "ui/UIMenu.hpp"

View File

@ -5,7 +5,6 @@
#pragma once
#include "scene/components/ui/UICanvas.hpp"
#include "scene/Scene.hpp"
#include "display/Color.hpp"
#include "util/array.hpp"
#include "util/mathutils.hpp"

View File

@ -7,4 +7,5 @@
target_sources(${DAWN_TARGET_NAME}
PRIVATE
TicTacToeTile.cpp
TicTacToeGame.cpp
)

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TicTacToeGame.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
TicTacToeGame::TicTacToeGame(SceneItem *item) : SceneItemComponent(item) {}
void TicTacToeGame::onStart() {
std::cout << "Test" << std::endl;
this->tiles = getScene()->findComponents<TicTacToeTile>();
getScene()->eventSceneUpdate.addListener(this, &TicTacToeGame::onSceneUpdate);
}
void TicTacToeGame::onSceneUpdate() {
// Get mouse in screen space.
auto mouse = getGame()->inputManager.getAxis2D(INPUT_BIND_MOUSE_X, INPUT_BIND_MOUSE_Y);
mouse *= 2.0f;
mouse -= glm::vec2(1, 1);
}

View File

@ -0,0 +1,21 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
#include "TicTacToeTile.hpp"
namespace Dawn {
class TicTacToeGame : public SceneItemComponent {
public:
std::vector<TicTacToeTile*> tiles;
TicTacToeGame(SceneItem *item);
void onStart() override;
void onSceneUpdate();
};
}

View File

@ -13,7 +13,6 @@ DawnGame::DawnGame(DawnHost *host) :
renderManager(this),
inputManager(this),
localeManager(this),
physicsManager(this),
saveManager(this)
{
}

View File

@ -20,7 +20,6 @@ namespace Dawn {
TimeManager timeManager;
LocaleManager localeManager;
DawnGameSaveManager saveManager;
PhysicsManager physicsManager;
DawnGame(DawnHost *host);
int32_t init() override;

View File

@ -9,6 +9,7 @@
#include "scene/components/display/MeshHost.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
#include "scene/components/physics/2d/BoxCollider.hpp"
#include "components/TicTacToeTile.hpp"
namespace Dawn {
@ -27,6 +28,7 @@ namespace Dawn {
MeshRenderer *meshRenderer;
SimpleTexturedMaterial *material;
TicTacToeTile *ticTacToe;
BoxCollider *boxCollider;
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
@ -48,7 +50,11 @@ namespace Dawn {
sprite = this->addComponent<TiledSprite>();
sprite->setTileset(&tileset->tileset);
sprite->setSize(glm::vec2(1, 1));
sprite->setTile(0x00);
sprite->setTile(0x01);
boxCollider = this->addComponent<BoxCollider>();
boxCollider->min = glm::vec2();
boxCollider->max = glm::vec2(1, 1);
ticTacToe = this->addComponent<TicTacToeTile>();
}

View File

@ -8,14 +8,12 @@
#include "prefabs/SimpleSpinningCubePrefab.hpp"
#include "prefabs/TicTacToeTilePrefab.hpp"
#include "display/mesh/TriangleMesh.hpp"
#include "scene/components/physics/3d/RayTester3D.hpp"
#include "components/TicTacToeGame.hpp"
namespace Dawn {
class TicTacToeScene : public Scene {
protected:
Camera *camera;
TicTacToeTilePrefab* tiles[9];
void stage() override {
camera = Camera::create(this);
@ -30,22 +28,19 @@ namespace Dawn {
camera->orthoLeft = -s * ratio;
camera->orthoRight = s * ratio;
auto cube = SimpleSpinningCubePrefab::create(this);
TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
// auto cube = SimpleSpinningCubePrefab::create(this);
// TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
// SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16);
auto tester = cube->addComponent<RayTester3D>();
tester->prefab = cube;
tester->camera = camera;
auto gameItem = this->createSceneItem();
auto game = gameItem->addComponent<TicTacToeGame>();
int32_t i = 0;
for(int32_t x = -1; x <= 1; x++) {
for(int32_t y = -1; y <= 1; y++) {
continue;
auto tile = TicTacToeTilePrefab::create(this);
tile->transform.setLocalPosition(glm::vec3(x * 1.25f, y * 1.25f, 0));
tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
tiles[i++] = tile;
// tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
}
}
}