Moved Scene implementation around

This commit is contained in:
2023-02-21 20:59:42 -08:00
parent cd686c2bd6
commit c065ab08b3
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

@ -1,27 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Ray2D.hpp"
using namespace Dawn;
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
position(pos),
direction(dir)
{
}
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
glm::vec2 j = this->position - ray.position;
float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y;
float_t s = (-direction.y * j.x + direction.x * j.y) / f;
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
*out = position + (t * direction);
return true;
}
return false;
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Ray2D.hpp"
using namespace Dawn;
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
position(pos),
direction(dir)
{
}
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
glm::vec2 j = this->position - ray.position;
float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y;
float_t s = (-direction.y * j.x + direction.x * j.y) / f;
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
*out = position + (t * direction);
return true;
}
return false;
}

View File

@ -1,31 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Ray2D {
const glm::vec2 position;
const glm::vec2 direction;
/**
* Constructs a new Ray 2D.
*
* @param position Position of this ray in 2D space.
* @param direction Direction from the origin in 2D space of this ray.
*/
Ray2D(glm::vec2 position, glm::vec2 direction);
/**
* Checks whether one ray is intersecting with another ray.
*
* @param ray The ray to check if this ray is intersecting.
* @param out The point in space where the two rays intersect.
* @return True if they intersect, otherwise false.
*/
bool_t intersects(struct Ray2D ray, glm::vec2 *out);
};
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Ray2D {
const glm::vec2 position;
const glm::vec2 direction;
/**
* Constructs a new Ray 2D.
*
* @param position Position of this ray in 2D space.
* @param direction Direction from the origin in 2D space of this ray.
*/
Ray2D(glm::vec2 position, glm::vec2 direction);
/**
* Checks whether one ray is intersecting with another ray.
*
* @param ray The ray to check if this ray is intersecting.
* @param out The point in space where the two rays intersect.
* @return True if they intersect, otherwise false.
*/
bool_t intersects(struct Ray2D ray, glm::vec2 *out);
};
}

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

@ -1,36 +1,36 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/Scene.hpp"
#include "util/array.hpp"
namespace Dawn {
template<class O, typename J, class P = O>
class Prefab {
public:
/**
* Returns the list of assets required for this prefab.
*
* @param man Asset Manasger for getting required assets from.
* @return List of required assets this prefab.
*/
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
return P::prefabAssets(man);
}
/**
* Creates a new instance of this prefabricated asset.
*
* @param context Custom context that this prefab needs to initialize.
* @return The instance of the created prefab.
*/
static O * create(J *context) {
assertNotNull(context);
return P::prefabCreate(context);
}
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/SceneItemComponent.hpp"
#include "util/array.hpp"
namespace Dawn {
template<class O, typename J, class P = O>
class Prefab {
public:
/**
* Returns the list of assets required for this prefab.
*
* @param man Asset Manasger for getting required assets from.
* @return List of required assets this prefab.
*/
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
return P::prefabAssets(man);
}
/**
* Creates a new instance of this prefabricated asset.
*
* @param context Custom context that this prefab needs to initialize.
* @return The instance of the created prefab.
*/
static O * create(J *context) {
assertNotNull(context);
return P::prefabCreate(context);
}
};
}

View File

@ -1,48 +1,47 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Prefab.hpp"
#include "scene/SceneItem.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {
template<class O>
class SceneItemPrefab :
public SceneItem,
public Prefab<O, Scene, O>
{
public:
/**
* Creates an instance of this prefab for the given scene.
*
* @param scene Scene that this prefab is going to be added to.
* @return The created prefab instance.
*/
static O * prefabCreate(Scene *scene) {
O *item = scene->createSceneItemOfType<O>();
item->prefabInit(&scene->game->assetManager);
return item;
}
/**
* Constructor for this SceneItemPrefab.
*
* @param scene Scene that this prefab belongs to.
* @param id ID of this scene item.
*/
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
SceneItem(scene, id)
{
}
/**
* Virtual method called by the subclass for initialization after the
* prefab has been created.
*/
virtual void prefabInit(AssetManager *man) = 0;
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Prefab.hpp"
#include "game/DawnGame.hpp"
namespace Dawn {
template<class O>
class SceneItemPrefab :
public SceneItem,
public Prefab<O, Scene, O>
{
public:
/**
* Creates an instance of this prefab for the given scene.
*
* @param scene Scene that this prefab is going to be added to.
* @return The created prefab instance.
*/
static O * prefabCreate(Scene *scene) {
O *item = scene->createSceneItemOfType<O>();
item->prefabInit(&scene->game->assetManager);
return item;
}
/**
* Constructor for this SceneItemPrefab.
*
* @param scene Scene that this prefab belongs to.
* @param id ID of this scene item.
*/
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
SceneItem(scene, id)
{
}
/**
* Virtual method called by the subclass for initialization after the
* prefab has been created.
*/
virtual void prefabInit(AssetManager *man) = 0;
};
}

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

@ -1,38 +1,37 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "AnimationController.hpp"
#include "scene/Scene.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
AnimationController::AnimationController(SceneItem *item) :
SceneItemComponent(item)
{
}
void AnimationController::addAnimation(Animation *animation) {
assertNotNull(animation);
this->animations.push_back(animation);
}
void AnimationController::onSceneUpdate() {
auto it = this->animations.begin();
while(it != this->animations.end()) {
(*it)->tick(this->getGame()->timeManager.delta);
++it;
}
}
void AnimationController::onStart() {
SceneItemComponent::onStart();
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
}
void AnimationController::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "AnimationController.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
AnimationController::AnimationController(SceneItem *item) :
SceneItemComponent(item)
{
}
void AnimationController::addAnimation(Animation *animation) {
assertNotNull(animation);
this->animations.push_back(animation);
}
void AnimationController::onSceneUpdate() {
auto it = this->animations.begin();
while(it != this->animations.end()) {
(*it)->tick(this->getGame()->timeManager.delta);
++it;
}
}
void AnimationController::onStart() {
SceneItemComponent::onStart();
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
}
void AnimationController::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
}

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

@ -1,81 +1,80 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleRenderTargetQuad.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
SceneItemComponent(i)
{
}
void SimpleRenderTargetQuad::onRenderTargetResized(
RenderTarget *target, float_t w, float_t h
) {
assertTrue(target == this->renderTarget);
// Update mesh
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(w, h), glm::vec2(1, 1),
0, 0
);
}
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
assertTrue(rt != this->renderTarget);
// Remove old event listener
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
this->renderTarget = rt;
// Add new event listener.
if(rt != nullptr) {
rt->eventRenderTargetResized.addListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->meshHost = this->item->getComponent<MeshHost>())
};
}
void SimpleRenderTargetQuad::onStart() {
assertNotNull(this->meshHost);
// Create quad mesh
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
// Perform first resize.
if(this->renderTarget != nullptr) {
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0),
glm::vec2(0, 0),
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
glm::vec2(1,1),
0, 0
);
}
}
void SimpleRenderTargetQuad::onDispose() {
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SimpleRenderTargetQuad.hpp"
using namespace Dawn;
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
SceneItemComponent(i)
{
}
void SimpleRenderTargetQuad::onRenderTargetResized(
RenderTarget *target, float_t w, float_t h
) {
assertTrue(target == this->renderTarget);
// Update mesh
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0), glm::vec2(0, 0),
glm::vec2(w, h), glm::vec2(1, 1),
0, 0
);
}
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
assertTrue(rt != this->renderTarget);
// Remove old event listener
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
this->renderTarget = rt;
// Add new event listener.
if(rt != nullptr) {
rt->eventRenderTargetResized.addListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->meshHost = this->item->getComponent<MeshHost>())
};
}
void SimpleRenderTargetQuad::onStart() {
assertNotNull(this->meshHost);
// Create quad mesh
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
// Perform first resize.
if(this->renderTarget != nullptr) {
QuadMesh::bufferQuadMesh(
&this->meshHost->mesh,
glm::vec2(0, 0),
glm::vec2(0, 0),
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
glm::vec2(1,1),
0, 0
);
}
}
void SimpleRenderTargetQuad::onDispose() {
if(this->renderTarget != nullptr) {
this->renderTarget->eventRenderTargetResized.removeListener(
this, &SimpleRenderTargetQuad::onRenderTargetResized
);
}
}

View File

@ -1,45 +1,44 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// 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"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
using namespace Dawn;
SceneItem * ExampleSpin::create(Scene *scene) {
auto item = scene->createSceneItem();
auto mr = item->addComponent<MeshRenderer>();
mr->mesh = new Mesh();
mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
auto mat = item->addComponent<SimpleTexturedMaterial>();
item->addComponent<ExampleSpin>();
return item;
}
ExampleSpin::ExampleSpin(SceneItem *item) :
SceneItemComponent(item)
{
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
}
void ExampleSpin::onUnpausedUpdate() {
auto quat = this->transform->getLocalRotation();
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
this->transform->setLocalRotation(quat);
}
void ExampleSpin::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "ExampleSpin.hpp"
#include "game/DawnGame.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "display/mesh/CubeMesh.hpp"
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
using namespace Dawn;
SceneItem * ExampleSpin::create(Scene *scene) {
auto item = scene->createSceneItem();
auto mr = item->addComponent<MeshRenderer>();
mr->mesh = new Mesh();
mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
auto mat = item->addComponent<SimpleTexturedMaterial>();
item->addComponent<ExampleSpin>();
return item;
}
ExampleSpin::ExampleSpin(SceneItem *item) :
SceneItemComponent(item)
{
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
}
void ExampleSpin::onUnpausedUpdate() {
auto quat = this->transform->getLocalRotation();
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
this->transform->setLocalRotation(quat);
}
void ExampleSpin::onDispose() {
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
}

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

@ -1,11 +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
Collider2D.cpp
Ray2D.cpp
# 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
BoxCollider.cpp
Collider2D.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

@ -1,28 +1,28 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/Scene.hpp"
namespace Dawn {
class SubSceneController : public SceneItemComponent {
protected:
Scene *subScene = nullptr;
void onSceneUpdate();
void onSceneUnpausedUpdate();
public:
bool_t onlyUpdateUnpaused = false;
SubSceneController(SceneItem *item);
Scene * getSubScene();
void setSubScene(Scene *scene);
void onStart() override;
void onDispose() override;
};
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "scene/SceneItemComponent.hpp"
namespace Dawn {
class SubSceneController : public SceneItemComponent {
protected:
Scene *subScene = nullptr;
void onSceneUpdate();
void onSceneUnpausedUpdate();
public:
bool_t onlyUpdateUnpaused = false;
SubSceneController(SceneItem *item);
Scene * getSubScene();
void setSubScene(Scene *scene);
void onStart() override;
void onDispose() override;
};
}

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);
}
}
}