Moved Scene implementation around
This commit is contained in:
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#include "RenderPipeline.hpp"
|
#include "RenderPipeline.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "display/RenderManager.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "scene/SceneItem.hpp"
|
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "scene/components/display/Material.hpp"
|
#include "scene/components/display/Material.hpp"
|
||||||
#include "scene/components/display/MeshRenderer.hpp"
|
#include "scene/components/display/MeshRenderer.hpp"
|
||||||
#include "scene/components/display/Camera.hpp"
|
#include "scene/components/display/Camera.hpp"
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "time/TimeManager.hpp"
|
#include "time/TimeManager.hpp"
|
||||||
#include "input/InputBinds.hpp"
|
#include "input/InputBinds.hpp"
|
||||||
#include "locale/LocaleManager.hpp"
|
#include "locale/LocaleManager.hpp"
|
||||||
#include "physics/PhysicsManager.hpp"
|
|
||||||
#include "save/SaveManager.hpp"
|
#include "save/SaveManager.hpp"
|
||||||
#include "audio/AudioManager.hpp"
|
#include "audio/AudioManager.hpp"
|
||||||
|
|
||||||
|
15
src/dawn/physics/2d/Box.cpp
Normal file
15
src/dawn/physics/2d/Box.cpp
Normal 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
|
||||||
|
);
|
||||||
|
}
|
20
src/dawn/physics/2d/Box.hpp
Normal file
20
src/dawn/physics/2d/Box.hpp
Normal 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);
|
||||||
|
}
|
11
src/dawn/physics/2d/CMakeLists.txt
Normal file
11
src/dawn/physics/2d/CMakeLists.txt
Normal 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
|
||||||
|
)
|
@ -4,14 +4,9 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "dawnlibs.hpp"
|
||||||
|
#include "assert/assert.hpp
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
|
||||||
|
|
||||||
class PhysicsManager {
|
|
||||||
public:
|
|
||||||
DawnGame *game;
|
|
||||||
|
|
||||||
PhysicsManager(DawnGame *game);
|
|
||||||
};
|
|
||||||
}
|
}
|
0
src/dawn/physics/2d/PhysicsGrid.hpp
Normal file
0
src/dawn/physics/2d/PhysicsGrid.hpp
Normal file
@ -1,27 +1,27 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "Ray2D.hpp"
|
#include "Ray2D.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
|
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
|
||||||
position(pos),
|
position(pos),
|
||||||
direction(dir)
|
direction(dir)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
|
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
|
||||||
glm::vec2 j = this->position - ray.position;
|
glm::vec2 j = this->position - ray.position;
|
||||||
float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y;
|
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 s = (-direction.y * j.x + direction.x * j.y) / f;
|
||||||
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
|
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
|
||||||
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
|
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
|
||||||
*out = position + (t * direction);
|
*out = position + (t * direction);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
@ -1,31 +1,31 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
struct Ray2D {
|
struct Ray2D {
|
||||||
const glm::vec2 position;
|
const glm::vec2 position;
|
||||||
const glm::vec2 direction;
|
const glm::vec2 direction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Ray 2D.
|
* Constructs a new Ray 2D.
|
||||||
*
|
*
|
||||||
* @param position Position of this ray in 2D space.
|
* @param position Position of this ray in 2D space.
|
||||||
* @param direction Direction from the origin in 2D space of this ray.
|
* @param direction Direction from the origin in 2D space of this ray.
|
||||||
*/
|
*/
|
||||||
Ray2D(glm::vec2 position, glm::vec2 direction);
|
Ray2D(glm::vec2 position, glm::vec2 direction);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether one ray is intersecting with another ray.
|
* Checks whether one ray is intersecting with another ray.
|
||||||
*
|
*
|
||||||
* @param ray The ray to check if this ray is intersecting.
|
* @param ray The ray to check if this ray is intersecting.
|
||||||
* @param out The point in space where the two rays intersect.
|
* @param out The point in space where the two rays intersect.
|
||||||
* @return True if they intersect, otherwise false.
|
* @return True if they intersect, otherwise false.
|
||||||
*/
|
*/
|
||||||
bool_t intersects(struct Ray2D ray, glm::vec2 *out);
|
bool_t intersects(struct Ray2D ray, glm::vec2 *out);
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -6,8 +6,9 @@
|
|||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
PhysicsManager.cpp
|
ScenePhysicsManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
|
add_subdirectory(2d)
|
||||||
add_subdirectory(3d)
|
add_subdirectory(3d)
|
17
src/dawn/physics/ScenePhysicsManager.cpp
Normal file
17
src/dawn/physics/ScenePhysicsManager.cpp
Normal 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() {
|
||||||
|
|
||||||
|
}
|
29
src/dawn/physics/ScenePhysicsManager.hpp
Normal file
29
src/dawn/physics/ScenePhysicsManager.hpp
Normal 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;
|
||||||
|
};
|
||||||
|
}
|
@ -6,7 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/SceneItemComponent.hpp"
|
#include "scene/SceneItemComponent.hpp"
|
||||||
#include "Card.hpp"
|
#include "Card.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "PokerPot.hpp"
|
#include "PokerPot.hpp"
|
||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
#include "display/animation/Easing.hpp"
|
#include "display/animation/Easing.hpp"
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "asset/AssetManager.hpp"
|
#include "asset/AssetManager.hpp"
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/SceneItemComponent.hpp"
|
||||||
#include "util/array.hpp"
|
#include "util/array.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
template<class O, typename J, class P = O>
|
template<class O, typename J, class P = O>
|
||||||
class Prefab {
|
class Prefab {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Returns the list of assets required for this prefab.
|
* Returns the list of assets required for this prefab.
|
||||||
*
|
*
|
||||||
* @param man Asset Manasger for getting required assets from.
|
* @param man Asset Manasger for getting required assets from.
|
||||||
* @return List of required assets this prefab.
|
* @return List of required assets this prefab.
|
||||||
*/
|
*/
|
||||||
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
|
static std::vector<Asset*> getRequiredAssets(AssetManager *man) {
|
||||||
return P::prefabAssets(man);
|
return P::prefabAssets(man);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this prefabricated asset.
|
* Creates a new instance of this prefabricated asset.
|
||||||
*
|
*
|
||||||
* @param context Custom context that this prefab needs to initialize.
|
* @param context Custom context that this prefab needs to initialize.
|
||||||
* @return The instance of the created prefab.
|
* @return The instance of the created prefab.
|
||||||
*/
|
*/
|
||||||
static O * create(J *context) {
|
static O * create(J *context) {
|
||||||
assertNotNull(context);
|
assertNotNull(context);
|
||||||
return P::prefabCreate(context);
|
return P::prefabCreate(context);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,48 +1,47 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Prefab.hpp"
|
#include "Prefab.hpp"
|
||||||
#include "scene/SceneItem.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
|
||||||
|
namespace Dawn {
|
||||||
namespace Dawn {
|
template<class O>
|
||||||
template<class O>
|
class SceneItemPrefab :
|
||||||
class SceneItemPrefab :
|
public SceneItem,
|
||||||
public SceneItem,
|
public Prefab<O, Scene, O>
|
||||||
public Prefab<O, Scene, O>
|
{
|
||||||
{
|
public:
|
||||||
public:
|
/**
|
||||||
/**
|
* Creates an instance of this prefab for the given scene.
|
||||||
* Creates an instance of this prefab for the given scene.
|
*
|
||||||
*
|
* @param scene Scene that this prefab is going to be added to.
|
||||||
* @param scene Scene that this prefab is going to be added to.
|
* @return The created prefab instance.
|
||||||
* @return The created prefab instance.
|
*/
|
||||||
*/
|
static O * prefabCreate(Scene *scene) {
|
||||||
static O * prefabCreate(Scene *scene) {
|
O *item = scene->createSceneItemOfType<O>();
|
||||||
O *item = scene->createSceneItemOfType<O>();
|
item->prefabInit(&scene->game->assetManager);
|
||||||
item->prefabInit(&scene->game->assetManager);
|
return item;
|
||||||
return item;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Constructor for this SceneItemPrefab.
|
||||||
* Constructor for this SceneItemPrefab.
|
*
|
||||||
*
|
* @param scene Scene that this prefab belongs to.
|
||||||
* @param scene Scene that this prefab belongs to.
|
* @param id ID of this scene item.
|
||||||
* @param id ID of this scene item.
|
*/
|
||||||
*/
|
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
|
||||||
SceneItemPrefab(Scene *scene, sceneitemid_t id) :
|
SceneItem(scene, id)
|
||||||
SceneItem(scene, id)
|
{
|
||||||
{
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Virtual method called by the subclass for initialization after the
|
||||||
* Virtual method called by the subclass for initialization after the
|
* prefab has been created.
|
||||||
* prefab has been created.
|
*/
|
||||||
*/
|
virtual void prefabInit(AssetManager *man) = 0;
|
||||||
virtual void prefabInit(AssetManager *man) = 0;
|
};
|
||||||
};
|
|
||||||
}
|
}
|
@ -4,6 +4,8 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "Scene.hpp"
|
#include "Scene.hpp"
|
||||||
|
#include "SceneItem.hpp"
|
||||||
|
#include "SceneItemComponent.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
@ -4,13 +4,19 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SceneItem.hpp"
|
|
||||||
#include "event/Event.hpp"
|
#include "event/Event.hpp"
|
||||||
#include "asset/Asset.hpp"
|
#include "asset/Asset.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
class RenderPipeline;
|
class RenderPipeline;
|
||||||
|
class SceneItem;
|
||||||
|
class SceneItemComponent;
|
||||||
|
|
||||||
|
typedef int32_t sceneitemid_t;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T * _sceneForwardGetComponent(SceneItem *item);
|
||||||
|
|
||||||
class Scene {
|
class Scene {
|
||||||
private:
|
private:
|
||||||
@ -84,13 +90,13 @@ namespace Dawn {
|
|||||||
T * findComponent() {
|
T * findComponent() {
|
||||||
auto it = this->itemsNotInitialized.begin();
|
auto it = this->itemsNotInitialized.begin();
|
||||||
while(it != this->itemsNotInitialized.end()) {
|
while(it != this->itemsNotInitialized.end()) {
|
||||||
auto component = it->second->getComponent<T>();
|
auto component = _sceneForwardGetComponent<T>(it->second);
|
||||||
if(component != nullptr) return component;
|
if(component != nullptr) return component;
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
auto it2 = this->items.begin();
|
auto it2 = this->items.begin();
|
||||||
while(it2 != this->items.end()) {
|
while(it2 != this->items.end()) {
|
||||||
auto component = it2->second->getComponent<T>();
|
auto component = _sceneForwardGetComponent<T>(it2->second);
|
||||||
if(component != nullptr) return component;
|
if(component != nullptr) return component;
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
@ -110,14 +116,14 @@ namespace Dawn {
|
|||||||
|
|
||||||
auto it = this->itemsNotInitialized.begin();
|
auto it = this->itemsNotInitialized.begin();
|
||||||
while(it != this->itemsNotInitialized.end()) {
|
while(it != this->itemsNotInitialized.end()) {
|
||||||
auto component = it->second->getComponent<T>();
|
auto component = _sceneForwardGetComponent<T>(it->second);
|
||||||
if(component != nullptr) components.push_back(component);
|
if(component != nullptr) components.push_back(component);
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it2 = this->items.begin();
|
auto it2 = this->items.begin();
|
||||||
while(it2 != this->items.end()) {
|
while(it2 != this->items.end()) {
|
||||||
auto component = it2->second->getComponent<T>();
|
auto component = _sceneForwardGetComponent<T>(it2->second);
|
||||||
if(component != nullptr) components.push_back(component);
|
if(component != nullptr) components.push_back(component);
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "SceneItem.hpp"
|
#include "SceneItem.hpp"
|
||||||
#include "Scene.hpp"
|
#include "SceneItemComponent.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
|
@ -4,14 +4,12 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "SceneItemComponent.hpp"
|
|
||||||
#include "display/Transform.hpp"
|
#include "display/Transform.hpp"
|
||||||
#include "event/Event.hpp"
|
#include "event/Event.hpp"
|
||||||
|
#include "scene/Scene.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
typedef int32_t sceneitemid_t;
|
class SceneItemComponent;
|
||||||
|
|
||||||
class Scene;
|
|
||||||
|
|
||||||
class SceneItem {
|
class SceneItem {
|
||||||
private:
|
private:
|
||||||
|
@ -6,10 +6,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dawnlibs.hpp"
|
#include "dawnlibs.hpp"
|
||||||
#include "display/Transform.hpp"
|
#include "display/Transform.hpp"
|
||||||
|
#include "scene/SceneItem.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class SceneItem;
|
|
||||||
class Scene;
|
|
||||||
class DawnGame;
|
class DawnGame;
|
||||||
|
|
||||||
class SceneItemComponent {
|
class SceneItemComponent {
|
||||||
@ -70,4 +69,11 @@ namespace Dawn {
|
|||||||
*/
|
*/
|
||||||
~SceneItemComponent();
|
~SceneItemComponent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T * _sceneForwardGetComponent(SceneItem *item) {
|
||||||
|
return item->getComponent<T>();
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,38 +1,37 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "AnimationController.hpp"
|
#include "AnimationController.hpp"
|
||||||
#include "scene/Scene.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
|
||||||
|
using namespace Dawn;
|
||||||
using namespace Dawn;
|
|
||||||
|
AnimationController::AnimationController(SceneItem *item) :
|
||||||
AnimationController::AnimationController(SceneItem *item) :
|
SceneItemComponent(item)
|
||||||
SceneItemComponent(item)
|
{
|
||||||
{
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
void AnimationController::addAnimation(Animation *animation) {
|
||||||
void AnimationController::addAnimation(Animation *animation) {
|
assertNotNull(animation);
|
||||||
assertNotNull(animation);
|
this->animations.push_back(animation);
|
||||||
this->animations.push_back(animation);
|
}
|
||||||
}
|
|
||||||
|
void AnimationController::onSceneUpdate() {
|
||||||
void AnimationController::onSceneUpdate() {
|
auto it = this->animations.begin();
|
||||||
auto it = this->animations.begin();
|
while(it != this->animations.end()) {
|
||||||
while(it != this->animations.end()) {
|
(*it)->tick(this->getGame()->timeManager.delta);
|
||||||
(*it)->tick(this->getGame()->timeManager.delta);
|
++it;
|
||||||
++it;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void AnimationController::onStart() {
|
||||||
void AnimationController::onStart() {
|
SceneItemComponent::onStart();
|
||||||
SceneItemComponent::onStart();
|
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
|
||||||
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
|
}
|
||||||
}
|
|
||||||
|
void AnimationController::onDispose() {
|
||||||
void AnimationController::onDispose() {
|
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
|
||||||
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
|
|
||||||
}
|
}
|
@ -4,7 +4,6 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "Camera.hpp"
|
#include "Camera.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "Material.hpp"
|
#include "Material.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
@ -1,81 +1,80 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "SimpleRenderTargetQuad.hpp"
|
#include "SimpleRenderTargetQuad.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
|
using namespace Dawn;
|
||||||
using namespace Dawn;
|
|
||||||
|
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
|
||||||
SimpleRenderTargetQuad::SimpleRenderTargetQuad(SceneItem *i) :
|
SceneItemComponent(i)
|
||||||
SceneItemComponent(i)
|
{
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
void SimpleRenderTargetQuad::onRenderTargetResized(
|
||||||
void SimpleRenderTargetQuad::onRenderTargetResized(
|
RenderTarget *target, float_t w, float_t h
|
||||||
RenderTarget *target, float_t w, float_t h
|
) {
|
||||||
) {
|
assertTrue(target == this->renderTarget);
|
||||||
assertTrue(target == this->renderTarget);
|
// Update mesh
|
||||||
// Update mesh
|
QuadMesh::bufferQuadMesh(
|
||||||
QuadMesh::bufferQuadMesh(
|
&this->meshHost->mesh,
|
||||||
&this->meshHost->mesh,
|
glm::vec2(0, 0), glm::vec2(0, 0),
|
||||||
glm::vec2(0, 0), glm::vec2(0, 0),
|
glm::vec2(w, h), glm::vec2(1, 1),
|
||||||
glm::vec2(w, h), glm::vec2(1, 1),
|
0, 0
|
||||||
0, 0
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
|
||||||
void SimpleRenderTargetQuad::setRenderTarget(RenderTarget *rt) {
|
assertTrue(rt != this->renderTarget);
|
||||||
assertTrue(rt != this->renderTarget);
|
|
||||||
|
// Remove old event listener
|
||||||
// Remove old event listener
|
if(this->renderTarget != nullptr) {
|
||||||
if(this->renderTarget != nullptr) {
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
this->renderTarget->eventRenderTargetResized.removeListener(
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
this->renderTarget = rt;
|
||||||
this->renderTarget = rt;
|
|
||||||
|
// Add new event listener.
|
||||||
// Add new event listener.
|
if(rt != nullptr) {
|
||||||
if(rt != nullptr) {
|
rt->eventRenderTargetResized.addListener(
|
||||||
rt->eventRenderTargetResized.addListener(
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
|
||||||
std::vector<SceneItemComponent*> SimpleRenderTargetQuad::getDependencies() {
|
return std::vector<SceneItemComponent*>{
|
||||||
return std::vector<SceneItemComponent*>{
|
(this->meshHost = this->item->getComponent<MeshHost>())
|
||||||
(this->meshHost = this->item->getComponent<MeshHost>())
|
};
|
||||||
};
|
}
|
||||||
}
|
|
||||||
|
void SimpleRenderTargetQuad::onStart() {
|
||||||
void SimpleRenderTargetQuad::onStart() {
|
assertNotNull(this->meshHost);
|
||||||
assertNotNull(this->meshHost);
|
|
||||||
|
// Create quad mesh
|
||||||
// Create quad mesh
|
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
||||||
this->meshHost->mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
|
|
||||||
|
// Perform first resize.
|
||||||
// Perform first resize.
|
if(this->renderTarget != nullptr) {
|
||||||
if(this->renderTarget != nullptr) {
|
QuadMesh::bufferQuadMesh(
|
||||||
QuadMesh::bufferQuadMesh(
|
&this->meshHost->mesh,
|
||||||
&this->meshHost->mesh,
|
glm::vec2(0, 0),
|
||||||
glm::vec2(0, 0),
|
glm::vec2(0, 0),
|
||||||
glm::vec2(0, 0),
|
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
|
||||||
glm::vec2(this->renderTarget->getWidth(), this->renderTarget->getHeight()),
|
glm::vec2(1,1),
|
||||||
glm::vec2(1,1),
|
0, 0
|
||||||
0, 0
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
void SimpleRenderTargetQuad::onDispose() {
|
||||||
void SimpleRenderTargetQuad::onDispose() {
|
if(this->renderTarget != nullptr) {
|
||||||
if(this->renderTarget != nullptr) {
|
this->renderTarget->eventRenderTargetResized.removeListener(
|
||||||
this->renderTarget->eventRenderTargetResized.removeListener(
|
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
||||||
this, &SimpleRenderTargetQuad::onRenderTargetResized
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,45 +1,44 @@
|
|||||||
// Copyright (c) 2022 Dominic Masters
|
// Copyright (c) 2022 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "ExampleSpin.hpp"
|
#include "ExampleSpin.hpp"
|
||||||
#include "scene/Scene.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "scene/components/display/MeshRenderer.hpp"
|
||||||
#include "scene/components/display/MeshRenderer.hpp"
|
#include "display/mesh/CubeMesh.hpp"
|
||||||
#include "display/mesh/CubeMesh.hpp"
|
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
|
||||||
|
using namespace Dawn;
|
||||||
using namespace Dawn;
|
|
||||||
|
SceneItem * ExampleSpin::create(Scene *scene) {
|
||||||
SceneItem * ExampleSpin::create(Scene *scene) {
|
auto item = scene->createSceneItem();
|
||||||
auto item = scene->createSceneItem();
|
auto mr = item->addComponent<MeshRenderer>();
|
||||||
auto mr = item->addComponent<MeshRenderer>();
|
mr->mesh = new Mesh();
|
||||||
mr->mesh = new Mesh();
|
mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
|
||||||
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);
|
||||||
CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0);
|
auto mat = item->addComponent<SimpleTexturedMaterial>();
|
||||||
auto mat = item->addComponent<SimpleTexturedMaterial>();
|
item->addComponent<ExampleSpin>();
|
||||||
item->addComponent<ExampleSpin>();
|
|
||||||
|
return item;
|
||||||
return item;
|
}
|
||||||
}
|
|
||||||
|
ExampleSpin::ExampleSpin(SceneItem *item) :
|
||||||
ExampleSpin::ExampleSpin(SceneItem *item) :
|
SceneItemComponent(item)
|
||||||
SceneItemComponent(item)
|
{
|
||||||
{
|
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||||
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
void ExampleSpin::onUnpausedUpdate() {
|
||||||
void ExampleSpin::onUnpausedUpdate() {
|
auto quat = this->transform->getLocalRotation();
|
||||||
auto quat = this->transform->getLocalRotation();
|
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
|
||||||
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 / 2.0f, glm::vec3(1, 0, 0));
|
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
|
||||||
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
|
|
||||||
|
this->transform->setLocalRotation(quat);
|
||||||
this->transform->setLocalRotation(quat);
|
}
|
||||||
}
|
|
||||||
|
void ExampleSpin::onDispose() {
|
||||||
void ExampleSpin::onDispose() {
|
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||||
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
|
|
||||||
}
|
}
|
@ -3,11 +3,10 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "PhysicsManager.hpp"
|
#include "BoxCollider.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
|
||||||
|
|
||||||
using namespace Dawn;
|
using namespace Dawn;
|
||||||
|
|
||||||
PhysicsManager::PhysicsManager(DawnGame *game) {
|
BoxCollider::BoxCollider(SceneItem *i) : Collider2D(i) {
|
||||||
this->game = game;
|
|
||||||
}
|
}
|
18
src/dawn/scene/components/physics/2d/BoxCollider.hpp
Normal file
18
src/dawn/scene/components/physics/2d/BoxCollider.hpp
Normal 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);
|
||||||
|
};
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
# Copyright (c) 2023 Dominic Masters
|
# Copyright (c) 2023 Dominic Masters
|
||||||
#
|
#
|
||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
Collider2D.cpp
|
BoxCollider.cpp
|
||||||
Ray2D.cpp
|
Collider2D.cpp
|
||||||
)
|
)
|
@ -4,10 +4,10 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Sources
|
# Sources
|
||||||
target_sources(${DAWN_TARGET_NAME}
|
# target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
# PRIVATE
|
||||||
RayTester3D.cpp
|
# RayTester3D.cpp
|
||||||
)
|
# )
|
||||||
|
|
||||||
# Subdirs
|
# Subdirs
|
||||||
add_subdirectory(collider)
|
add_subdirectory(collider)
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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();
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,28 +1,28 @@
|
|||||||
// Copyright (c) 2023 Dominic Masters
|
// Copyright (c) 2023 Dominic Masters
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/Scene.hpp"
|
#include "scene/SceneItemComponent.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class SubSceneController : public SceneItemComponent {
|
class SubSceneController : public SceneItemComponent {
|
||||||
protected:
|
protected:
|
||||||
Scene *subScene = nullptr;
|
Scene *subScene = nullptr;
|
||||||
|
|
||||||
void onSceneUpdate();
|
void onSceneUpdate();
|
||||||
void onSceneUnpausedUpdate();
|
void onSceneUnpausedUpdate();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool_t onlyUpdateUnpaused = false;
|
bool_t onlyUpdateUnpaused = false;
|
||||||
|
|
||||||
SubSceneController(SceneItem *item);
|
SubSceneController(SceneItem *item);
|
||||||
|
|
||||||
Scene * getSubScene();
|
Scene * getSubScene();
|
||||||
void setSubScene(Scene *scene);
|
void setSubScene(Scene *scene);
|
||||||
|
|
||||||
void onStart() override;
|
void onStart() override;
|
||||||
void onDispose() override;
|
void onDispose() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -4,7 +4,6 @@
|
|||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
#include "UICanvas.hpp"
|
#include "UICanvas.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "ui/UIComponent.hpp"
|
#include "ui/UIComponent.hpp"
|
||||||
#include "game/DawnGame.hpp"
|
#include "game/DawnGame.hpp"
|
||||||
#include "ui/UIMenu.hpp"
|
#include "ui/UIMenu.hpp"
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "scene/components/ui/UICanvas.hpp"
|
#include "scene/components/ui/UICanvas.hpp"
|
||||||
#include "scene/Scene.hpp"
|
|
||||||
#include "display/Color.hpp"
|
#include "display/Color.hpp"
|
||||||
#include "util/array.hpp"
|
#include "util/array.hpp"
|
||||||
#include "util/mathutils.hpp"
|
#include "util/mathutils.hpp"
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
target_sources(${DAWN_TARGET_NAME}
|
target_sources(${DAWN_TARGET_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
TicTacToeTile.cpp
|
TicTacToeTile.cpp
|
||||||
|
TicTacToeGame.cpp
|
||||||
)
|
)
|
27
src/dawntictactoe/components/TicTacToeGame.cpp
Normal file
27
src/dawntictactoe/components/TicTacToeGame.cpp
Normal 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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
src/dawntictactoe/components/TicTacToeGame.hpp
Normal file
21
src/dawntictactoe/components/TicTacToeGame.hpp
Normal 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();
|
||||||
|
};
|
||||||
|
}
|
@ -13,7 +13,6 @@ DawnGame::DawnGame(DawnHost *host) :
|
|||||||
renderManager(this),
|
renderManager(this),
|
||||||
inputManager(this),
|
inputManager(this),
|
||||||
localeManager(this),
|
localeManager(this),
|
||||||
physicsManager(this),
|
|
||||||
saveManager(this)
|
saveManager(this)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ namespace Dawn {
|
|||||||
TimeManager timeManager;
|
TimeManager timeManager;
|
||||||
LocaleManager localeManager;
|
LocaleManager localeManager;
|
||||||
DawnGameSaveManager saveManager;
|
DawnGameSaveManager saveManager;
|
||||||
PhysicsManager physicsManager;
|
|
||||||
|
|
||||||
DawnGame(DawnHost *host);
|
DawnGame(DawnHost *host);
|
||||||
int32_t init() override;
|
int32_t init() override;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "scene/components/display/MeshHost.hpp"
|
#include "scene/components/display/MeshHost.hpp"
|
||||||
#include "scene/components/display/MeshRenderer.hpp"
|
#include "scene/components/display/MeshRenderer.hpp"
|
||||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||||
|
#include "scene/components/physics/2d/BoxCollider.hpp"
|
||||||
#include "components/TicTacToeTile.hpp"
|
#include "components/TicTacToeTile.hpp"
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
@ -27,6 +28,7 @@ namespace Dawn {
|
|||||||
MeshRenderer *meshRenderer;
|
MeshRenderer *meshRenderer;
|
||||||
SimpleTexturedMaterial *material;
|
SimpleTexturedMaterial *material;
|
||||||
TicTacToeTile *ticTacToe;
|
TicTacToeTile *ticTacToe;
|
||||||
|
BoxCollider *boxCollider;
|
||||||
|
|
||||||
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
|
TicTacToeTilePrefab(Scene *s, sceneitemid_t i) :
|
||||||
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
|
SceneItemPrefab<TicTacToeTilePrefab>(s,i)
|
||||||
@ -48,7 +50,11 @@ namespace Dawn {
|
|||||||
sprite = this->addComponent<TiledSprite>();
|
sprite = this->addComponent<TiledSprite>();
|
||||||
sprite->setTileset(&tileset->tileset);
|
sprite->setTileset(&tileset->tileset);
|
||||||
sprite->setSize(glm::vec2(1, 1));
|
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>();
|
ticTacToe = this->addComponent<TicTacToeTile>();
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,12 @@
|
|||||||
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
#include "prefabs/SimpleSpinningCubePrefab.hpp"
|
||||||
#include "prefabs/TicTacToeTilePrefab.hpp"
|
#include "prefabs/TicTacToeTilePrefab.hpp"
|
||||||
#include "display/mesh/TriangleMesh.hpp"
|
#include "display/mesh/TriangleMesh.hpp"
|
||||||
|
#include "components/TicTacToeGame.hpp"
|
||||||
#include "scene/components/physics/3d/RayTester3D.hpp"
|
|
||||||
|
|
||||||
namespace Dawn {
|
namespace Dawn {
|
||||||
class TicTacToeScene : public Scene {
|
class TicTacToeScene : public Scene {
|
||||||
protected:
|
protected:
|
||||||
Camera *camera;
|
Camera *camera;
|
||||||
TicTacToeTilePrefab* tiles[9];
|
|
||||||
|
|
||||||
void stage() override {
|
void stage() override {
|
||||||
camera = Camera::create(this);
|
camera = Camera::create(this);
|
||||||
@ -30,22 +28,19 @@ namespace Dawn {
|
|||||||
camera->orthoLeft = -s * ratio;
|
camera->orthoLeft = -s * ratio;
|
||||||
camera->orthoRight = s * ratio;
|
camera->orthoRight = s * ratio;
|
||||||
|
|
||||||
auto cube = SimpleSpinningCubePrefab::create(this);
|
// auto cube = SimpleSpinningCubePrefab::create(this);
|
||||||
TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
|
// TriangleMesh::createTriangleMesh(&cube->meshHost->mesh);
|
||||||
// SphereMesh::createSphere(&cube->meshHost->mesh, 1.0f, 16, 16);
|
// 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;
|
int32_t i = 0;
|
||||||
for(int32_t x = -1; x <= 1; x++) {
|
for(int32_t x = -1; x <= 1; x++) {
|
||||||
for(int32_t y = -1; y <= 1; y++) {
|
for(int32_t y = -1; y <= 1; y++) {
|
||||||
continue;
|
|
||||||
auto tile = TicTacToeTilePrefab::create(this);
|
auto tile = TicTacToeTilePrefab::create(this);
|
||||||
tile->transform.setLocalPosition(glm::vec3(x * 1.25f, y * 1.25f, 0));
|
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);
|
// tile->ticTacToe->setState(i % 2 == 0 ? TIC_TAC_TOE_CROSS : TIC_TAC_TOE_NOUGHT);
|
||||||
tiles[i++] = tile;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user