Just making tiny improvements to things.

This commit is contained in:
2023-01-07 14:35:54 -08:00
parent d6b7895cab
commit 19f688afe1
33 changed files with 312 additions and 153 deletions

View File

@ -28,4 +28,7 @@ add_subdirectory(save)
add_subdirectory(scene)
add_subdirectory(time)
add_subdirectory(ui)
add_subdirectory(visualnovel)
if(DAWN_VISUAL_NOVEL)
add_subdirectory(visualnovel)
endif()

View File

@ -96,6 +96,19 @@ namespace Dawn {
}
}
float_t getAxis(inputbind_t negative, inputbind_t positive) {
return -getValue(negative) + getValue(positive);
}
glm::vec2 getAxis2D(
inputbind_t negativeX,
inputbind_t positiveX,
inputbind_t negativeY,
inputbind_t positiveY
) {
return glm::vec2(getAxis(negativeX, positiveX), getAxis(negativeY, positiveY));
}
/**
* Returns true if the given bind is currently being pressed (a non-zero
* value).

View File

@ -15,4 +15,6 @@ target_sources(${DAWN_TARGET_NAME}
)
# Subdirs
add_subdirectory(visualnovel)
if(DAWN_VISUAL_NOVEL)
add_subdirectory(visualnovel)
endif()

View File

@ -6,6 +6,7 @@
#pragma once
#include "asset/AssetManager.hpp"
#include "scene/Scene.hpp"
#include "util/array.hpp"
namespace Dawn {
template<class T, typename J, class P = T>

View File

@ -11,7 +11,7 @@ namespace Dawn {
template<class T>
class SceneItemPrefab :
public SceneItem,
public Prefab<T, Scene>
public Prefab<T, Scene, T>
{
public:
/**

View File

@ -9,6 +9,7 @@
#include "scene/components/display/MeshHost.hpp"
#include "scene/components/display/MeshRenderer.hpp"
#include "scene/components/display/Material.hpp"
#include "scene/components/display/PixelPerfectCamera.hpp"
#include "scene/components/display/TiledSprite.hpp"
#include "scene/components/example/ExampleSpin.hpp"

View File

@ -11,5 +11,6 @@ target_sources(${DAWN_TARGET_NAME}
Material.cpp
MeshHost.cpp
MeshRenderer.cpp
PixelPerfectCamera.cpp
TiledSprite.cpp
)

View File

@ -0,0 +1,64 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PixelPerfectCamera.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;
PixelPerfectCamera::PixelPerfectCamera(SceneItem *i) : SceneItemComponent(i) {
}
std::vector<SceneItemComponent*> PixelPerfectCamera::getDependencies() {
return std::vector<SceneItemComponent*>{
(this->camera = this->item->getComponent<Camera>())
};
}
void PixelPerfectCamera::onRenderTargetResized(
RenderTarget *t, float_t w, float_t h
) {
this->updateDimensions();
}
void PixelPerfectCamera::updateDimensions() {
float_t w, h;
assertNotNull(this->camera);
auto target = this->camera->getRenderTarget();
switch(this->camera->type) {
case CAMERA_TYPE_ORTHONOGRAPHIC:
w = target->getWidth() / 2.0f / this->scale;
h = target->getHeight() / 2.0f / this->scale;
camera->orthoLeft = -w;
camera->orthoRight = w;
camera->orthoTop = h;
camera->orthoBottom = -h;
camera->updateProjection();
break;
case CAMERA_TYPE_PERSPECTIVE:
assertDeprecated();
break;
default:
assertUnreachable();
}
}
void PixelPerfectCamera::onStart() {
assertNotNull(this->camera);
this->updateDimensions();
camera->getRenderTarget()->eventRenderTargetResized
.addListener(this, &PixelPerfectCamera::onRenderTargetResized)
;
}
PixelPerfectCamera::~PixelPerfectCamera() {
camera->getRenderTarget()->eventRenderTargetResized
.removeListener(this, &PixelPerfectCamera::onRenderTargetResized)
;
}

View File

@ -0,0 +1,36 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "Camera.hpp"
namespace Dawn {
class PixelPerfectCamera : public SceneItemComponent {
protected:
Camera *camera = nullptr;
/** Event for when the render target is resized. */
void onRenderTargetResized(RenderTarget *target, float_t w, float_t h);
/**
* Updates the underlying camera's projection information.
*/
void updateDimensions();
public:
float_t scale = 4.0f;
/**
* Create a new PixelPerfectCamera Component.
*
* @param item Item that this component belongs to.
*/
PixelPerfectCamera(SceneItem *item);
std::vector<SceneItemComponent*> getDependencies() override;
void onStart() override;
~PixelPerfectCamera();
};
}

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "SimpleVNScene.hpp"
#include "prefabs/ui/VisualNovelTextboxPrefab.hpp"
using namespace Dawn;

View File

@ -13,7 +13,6 @@
#include "visualnovel/events/VisualNovelPauseEvent.hpp"
#include "visualnovel/events/VisualNovelFadeEvent.hpp"
#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp"
#include "prefabs/ui/VisualNovelTextboxPrefab.hpp"
namespace Dawn {
class SimpleVNScene : public Scene {