Skip to content

Commit

Permalink
Merge pull request #302 from Laguna1989/fix/RenameRenderTargetLayer
Browse files Browse the repository at this point in the history
Fix/rename render target layer
  • Loading branch information
Laguna1989 authored Nov 2, 2023
2 parents 7b61cd9 + f0416b4 commit 8b83929
Show file tree
Hide file tree
Showing 47 changed files with 171 additions and 124 deletions.
9 changes: 6 additions & 3 deletions impl/jamtemplate/common/collision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ class Collision {
auto const Radius1 = (Obj1Size.x + Obj1Size.y) / 4.0f;
auto const Radius2 = (Obj2Size.x + Obj2Size.y) / 4.0f;

auto const distance = getCenter(obj1) - getCenter(obj2);
auto const center1 = getCenter(obj1);
auto const center2 = getCenter(obj2);
auto const distance = center1 - center2;

return (
jt::MathHelper::lengthSquared(distance) < ((Radius1 + Radius2) * (Radius1 + Radius2)));
auto const thresholdR = (Radius1 + Radius2) * (Radius1 + Radius2);
auto const lengthSquared = jt::MathHelper::lengthSquared(distance);
return (lengthSquared < thresholdR);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/common/drawable_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_DRAWABLE_HELPER_HPP

#include <color/color.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sprite.hpp>
#include <vector.hpp>
#include <memory>
Expand Down
6 changes: 3 additions & 3 deletions impl/jamtemplate/common/game_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <graphics/render_window_interface.hpp>
#include <input/input_manager_interface.hpp>
#include <log/logger_interface.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <state_manager/state_manager_interface.hpp>
#include <memory>

Expand Down Expand Up @@ -52,9 +52,9 @@ class GameInterface {
virtual ~GameInterface() = default;

// no copy, no move. Avoid slicing.
GameInterface(const GameInterface&) = delete;
GameInterface(GameInterface const&) = delete;
GameInterface(GameInterface&&) = delete;
GameInterface& operator=(const GameInterface&) = delete;
GameInterface& operator=(GameInterface const&) = delete;
GameInterface& operator=(GameInterface&&) = delete;

protected:
Expand Down
4 changes: 3 additions & 1 deletion impl/jamtemplate/common/graphics/flash_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_FLASH_INTERFACE_HPP

#include <color/color.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <memory>

namespace jt {
Expand All @@ -23,7 +23,9 @@ class FlashImpl {

private:
virtual void doDrawFlash(std::shared_ptr<jt::RenderTargetLayer> sptr) const = 0;

virtual void doFlashImpl(float /*t*/, jt::Color /*col = jt::colors::White*/) { }

float m_flashTimer { -1.0f };
float m_maxFlashTimer { -1.0f };

Expand Down
5 changes: 5 additions & 0 deletions impl/jamtemplate/common/graphics/logging_render_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,28 @@ void jt::LoggingRenderWindow::setMouseCursorVisible(bool visible)
m_logger.info("setMouseCursorVisible" + std::to_string(visible), { "jt", "RenderWindow" });
m_decoratee.setMouseCursorVisible(visible);
}

bool jt::LoggingRenderWindow::getMouseCursorVisible() const
{
m_logger.info("getMouseCursorVisible", { "jt", "RenderWindow" });
return m_decoratee.getMouseCursorVisible();
}

void jt::LoggingRenderWindow::updateGui(float elapsed)
{
m_logger.verbose("updateGui", { "jt", "RenderWindow" });
m_decoratee.updateGui(elapsed);
}

void jt::LoggingRenderWindow::startRenderGui()
{
m_logger.verbose("startRenderGui", { "jt", "RenderWindow" });
m_decoratee.startRenderGui();
}

bool jt::LoggingRenderWindow::shouldProcessKeyboard()
{
return m_decoratee.shouldProcessKeyboard();
}

bool jt::LoggingRenderWindow::shouldProcessMouse() { return m_decoratee.shouldProcessMouse(); }
2 changes: 1 addition & 1 deletion impl/jamtemplate/common/graphics/outline_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_OUTLINE_IMPL_HPP

#include <color/color.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <vector.hpp>
#include <memory>
#include <vector>
Expand Down
6 changes: 3 additions & 3 deletions impl/jamtemplate/common/graphics/render_target_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef JAMTEMPLATE_RENDER_TARGET_INTERFACE_HPP
#define JAMTEMPLATE_RENDER_TARGET_INTERFACE_HPP

#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <functional>
#include <map>
#include <memory>
Expand All @@ -18,9 +18,9 @@ class RenderTargetInterface {
virtual ~RenderTargetInterface() = default;

// no copy, no move. Avoid slicing.
RenderTargetInterface(const RenderTargetInterface&) = delete;
RenderTargetInterface(RenderTargetInterface const&) = delete;
RenderTargetInterface(RenderTargetInterface&&) = delete;
RenderTargetInterface& operator=(const RenderTargetInterface&) = delete;
RenderTargetInterface& operator=(RenderTargetInterface const&) = delete;
RenderTargetInterface& operator=(RenderTargetInterface&&) = delete;

protected:
Expand Down
6 changes: 3 additions & 3 deletions impl/jamtemplate/common/graphics/render_window_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef JAMTEMPLATE_RENDERWINDOW_INTERFACE_HPP
#define JAMTEMPLATE_RENDERWINDOW_INTERFACE_HPP

#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sprite.hpp>
#include <vector.hpp>
#include <memory>
Expand Down Expand Up @@ -64,9 +64,9 @@ class RenderWindowInterface {
virtual ~RenderWindowInterface() = default;

// no copy, no move. Avoid slicing.
RenderWindowInterface(const RenderWindowInterface&) = delete;
RenderWindowInterface(RenderWindowInterface const&) = delete;
RenderWindowInterface(RenderWindowInterface&&) = delete;
RenderWindowInterface& operator=(const RenderWindowInterface&) = delete;
RenderWindowInterface& operator=(RenderWindowInterface const&) = delete;
RenderWindowInterface& operator=(RenderWindowInterface&&) = delete;

protected:
Expand Down
10 changes: 10 additions & 0 deletions impl/jamtemplate/common/graphics/render_window_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,25 @@ jt::null_objects::RenderWindowNull::RenderWindowNull(
}

bool jt::null_objects::RenderWindowNull::isOpen() const { return true; }

void jt::null_objects::RenderWindowNull::checkForClose() { }

std::shared_ptr<jt::RenderTargetLayer> jt::null_objects::RenderWindowNull::createRenderTarget()
{
return nullptr;
}

jt::Vector2f jt::null_objects::RenderWindowNull::getSize() const { return m_size; }

void jt::null_objects::RenderWindowNull::draw(std::unique_ptr<jt::Sprite>& ptr)
{
if (!ptr) {
throw std::invalid_argument { "cannot draw nullptr sprite" };
}
}

void jt::null_objects::RenderWindowNull::display() { }

jt::Vector2f jt::null_objects::RenderWindowNull::getMousePosition()
{
auto const magic_mouse_position = 20.0f;
Expand All @@ -31,12 +37,16 @@ void jt::null_objects::RenderWindowNull::setMouseCursorVisible(bool visible)
{
m_mouseCursorVisible = visible;
}

bool jt::null_objects::RenderWindowNull::getMouseCursorVisible() const
{
return m_mouseCursorVisible;
}

void jt::null_objects::RenderWindowNull::updateGui(float /*elapsed*/) { }

void jt::null_objects::RenderWindowNull::startRenderGui() { }

bool jt::null_objects::RenderWindowNull::shouldProcessKeyboard() { return true; }

bool jt::null_objects::RenderWindowNull::shouldProcessMouse() { return true; }
2 changes: 1 addition & 1 deletion impl/jamtemplate/common/graphics/shadow_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_SHADOW_IMPL_HPP

#include <color/color.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <vector.hpp>
#include <memory>

Expand Down
6 changes: 6 additions & 0 deletions impl/jamtemplate/common/math_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ bool jt::MathHelper::checkIsIn(jt::Rectf const& rect, jt::Vector2f const& point)
bool const overlapsY = point.y > rect.top && point.y < rect.top + rect.height;
return (overlapsX && overlapsY);
}

jt::Vector2f jt::MathHelper::castToInteger(jt::Vector2f const& input)
{
return jt::Vector2f { static_cast<float>(static_cast<int>(input.x)),
static_cast<float>(static_cast<int>(input.y)) };
}
5 changes: 5 additions & 0 deletions impl/jamtemplate/common/math_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ float dot(Vector2f const& a, Vector2f const& b);
/// \return true if point is in rect, false otherwise
bool checkIsIn(jt::Rectf const& rect, jt::Vector2f const& point);

/// Cast a jt::Vector2f to it's integer values. This is needed e.g. for drawing pixel-perfect.
/// \param input input vector
/// \return cast to integer position
jt::Vector2f castToInteger(jt::Vector2f const& input);

} // namespace MathHelper
} // namespace jt

Expand Down
1 change: 0 additions & 1 deletion impl/jamtemplate/common/render_target.cpp

This file was deleted.

6 changes: 0 additions & 6 deletions impl/jamtemplate/common/render_target.hpp

This file was deleted.

1 change: 1 addition & 0 deletions impl/jamtemplate/common/render_target_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "render_target_layer.hpp"
6 changes: 6 additions & 0 deletions impl/jamtemplate/common/render_target_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef JAMTEMPLATE_RENDERTARGETLAYER_HPP
#define JAMTEMPLATE_RENDERTARGETLAYER_HPP

#include <render_target_layer_lib.hpp>

#endif
8 changes: 3 additions & 5 deletions impl/jamtemplate/common/screeneffects/star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ void jt::Star::setPosition(jt::Vector2f const& screenSizeHint)
if (!m_shape) {
throw std::logic_error { "Cannot set star position before create has been called." };
}
auto p = jt::Random::getRandomPointIn(
jt::Rectf { 0.0f, 0.0f, screenSizeHint.x, screenSizeHint.y });

p.x = static_cast<float>(static_cast<int>(p.x));
p.y = static_cast<float>(static_cast<int>(p.y));
auto const p = jt::MathHelper::castToInteger(
jt::Random::getRandomPointIn(jt::Rectf { 0.0f, 0.0f, screenSizeHint.x, screenSizeHint.y }));

m_shape->setPosition(p);
m_shape->setScreenSizeHint(screenSizeHint);
Expand Down Expand Up @@ -89,6 +86,7 @@ void jt::Star::doDraw() const
m_glow->draw(getGame()->gfx().target());
m_shape->draw(getGame()->gfx().target());
}

void jt::Star::setCamMovementFactor(float factor)
{
m_shape->setCamMovementFactor(factor);
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/common/tilemap/tile_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <graphics/drawable_impl.hpp>
#include <pathfinder/node_interface.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sprite.hpp>
#include <texture_manager_interface.hpp>
#include <tilemap/info_rect.hpp>
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <game_base.hpp>
#include <graphics/render_window_interface.hpp>
#include <rect.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <chrono>
#include <memory>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_LINE_HPP

#include <drawable_impl_sdl.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <vector.hpp>

namespace jt {
Expand Down
1 change: 1 addition & 0 deletions impl/jamtemplate/sdl/render_window_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ bool RenderWindow::shouldProcessKeyboard()
}
return !ImGui::GetIO().WantCaptureKeyboard;
}

bool RenderWindow::shouldProcessMouse()
{
if (!m_renderTargetCreated) {
Expand Down
2 changes: 0 additions & 2 deletions impl/jamtemplate/sdl/shape.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "shape.hpp"
#include <rect.hpp>
#include <render_target.hpp>
#include <sdl_2_include.hpp>
#include <sdl_helper.hpp>
#include <vector.hpp>
#include <iostream>
#include <memory>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/shape.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <drawable_impl_sdl.hpp>
#include <rect.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <texture_manager_interface.hpp>
#include <vector.hpp>
Expand Down
1 change: 0 additions & 1 deletion impl/jamtemplate/sdl/sprite.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "sprite.hpp"
#include <math_helper.hpp>
#include <render_target.hpp>
#include <sdl_helper.hpp>
#include <SDL_image.h>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <color/color.hpp>
#include <drawable_impl_sdl.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <texture_manager_interface.hpp>
#include <vector.hpp>
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/sprite_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_SPRITEFUNCTIONS_HPP

#include <color/color.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <memory>

Expand Down
1 change: 0 additions & 1 deletion impl/jamtemplate/sdl/text.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "text.hpp"
#include <render_target.hpp>
#include <sdl_helper.hpp>
#include <strutils.hpp>
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define JAMTEMPLATE_TEXT_HPP

#include <drawable_impl_sdl.hpp>
#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <memory>
#include <string>
Expand Down
5 changes: 3 additions & 2 deletions impl/jamtemplate/sdl/texture_manager_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef JAMTEMPLATE_TEXTUREMANAGER_HPP
#define JAMTEMPLATE_TEXTUREMANAGER_HPP

#include <render_target.hpp>
#include <texture_manager_interface.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <texture_manager_interface.hpp>
#include <map>
#include <memory>
#include <string>
Expand All @@ -25,6 +25,7 @@ class TextureManagerImpl : public jt::TextureManagerInterface {
private:
std::map<std::string, std::shared_ptr<SDL_Texture>> m_textures;
std::weak_ptr<jt::RenderTargetLayer> m_renderer;

bool containsTexture(std::string const& str) { return (m_textures.count(str) != 0); }
};

Expand Down
2 changes: 1 addition & 1 deletion impl/jamtemplate/sdl/texture_manager_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef JAMTEMPLATE_TEXTURE_MANAGER_INTERFACE_HPP
#define JAMTEMPLATE_TEXTURE_MANAGER_INTERFACE_HPP

#include <render_target.hpp>
#include <render_target_layer.hpp>
#include <sdl_2_include.hpp>
#include <cstddef>
#include <memory>
Expand Down
Loading

0 comments on commit 8b83929

Please sign in to comment.