Just making tiny improvements to things.
This commit is contained in:
@ -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()
|
@ -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).
|
||||
|
@ -15,4 +15,6 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
)
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(visualnovel)
|
||||
if(DAWN_VISUAL_NOVEL)
|
||||
add_subdirectory(visualnovel)
|
||||
endif()
|
@ -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>
|
||||
|
@ -11,7 +11,7 @@ namespace Dawn {
|
||||
template<class T>
|
||||
class SceneItemPrefab :
|
||||
public SceneItem,
|
||||
public Prefab<T, Scene>
|
||||
public Prefab<T, Scene, T>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -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"
|
||||
|
@ -11,5 +11,6 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
Material.cpp
|
||||
MeshHost.cpp
|
||||
MeshRenderer.cpp
|
||||
PixelPerfectCamera.cpp
|
||||
TiledSprite.cpp
|
||||
)
|
64
src/dawn/scene/components/display/PixelPerfectCamera.cpp
Normal file
64
src/dawn/scene/components/display/PixelPerfectCamera.cpp
Normal 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)
|
||||
;
|
||||
}
|
36
src/dawn/scene/components/display/PixelPerfectCamera.hpp
Normal file
36
src/dawn/scene/components/display/PixelPerfectCamera.hpp
Normal 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();
|
||||
};
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SimpleVNScene.hpp"
|
||||
#include "prefabs/ui/VisualNovelTextboxPrefab.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user