Added a DrawableLine class for debug builds.

This commit is contained in:
King_DuckZ 2014-08-19 21:49:08 +02:00
parent f300c94924
commit 105020b5c1
7 changed files with 223 additions and 3 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(CloonelJump CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic -Wconversion")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra -pedantic -Wconversion")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -Wextra -pedantic -Wconversion -DWITH_DEBUG_VISUALS")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -Wall -Wextra -pedantic -Wconversion")
option(WITH_BUILTIN_PHYSFS "Force using the version of PhysFS accompanying the code even if a system library is available" OFF)
@ -103,6 +103,7 @@ add_executable(${PROJECT_NAME}
src/line.cpp
src/collider.cpp
src/platformset.cpp
src/drawableline.cpp
)
target_link_libraries(${PROJECT_NAME}

61
src/colour.hpp Normal file
View file

@ -0,0 +1,61 @@
/*
Copyright 2014 Michele "King_DuckZ" Santullo
This file is part of CloonelJump.
CloonelJump is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CloonelJump is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id1DA767EB516A4F4588347DFC14D1A999
#define id1DA767EB516A4F4588347DFC14D1A999
#if defined(WITH_DEBUG_VISUALS)
#include <cstdint>
namespace cloonel {
struct Colour {
typedef uint8_t ChannelType;
Colour ( void ) = default;
Colour ( ChannelType parR, ChannelType parG, ChannelType parB, ChannelType parA );
explicit Colour ( ChannelType parFill );
Colour ( const Colour& parOther ) = default;
ChannelType r, g, b, a;
};
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline Colour::Colour (ChannelType parR, ChannelType parG, ChannelType parB, ChannelType parA) :
r(parR),
g(parG),
b(parB),
a(parA)
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline Colour::Colour (ChannelType parFill) :
r(parFill),
g(parFill),
b(parFill),
a(parFill)
{
}
} //namespace cloonel
#endif
#endif

75
src/drawableline.cpp Normal file
View file

@ -0,0 +1,75 @@
/*
Copyright 2014 Michele "King_DuckZ" Santullo
This file is part of CloonelJump.
CloonelJump is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CloonelJump is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
#include "drawableline.hpp"
#include "sdlmain.hpp"
#include <SDL2/SDL.h>
#if defined(WITH_DEBUG_VISUALS)
namespace cloonel {
namespace {
///----------------------------------------------------------------------
///----------------------------------------------------------------------
void ClipLine (const SDL_Rect& /*parArea*/, Line<uint16_t, 2>& /*parLine*/) {
}
} //unnamed namespace
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
DrawableLine::DrawableLine (SDLMain* parMain, Colour parColour, const LineBase& parLine) :
LineBase(parLine),
m_sdlmain(parMain),
m_colour(parColour)
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
DrawableLine::DrawableLine (SDLMain* parMain, Colour parColour, const LineBase::Point& parStart, const LineBase::Point& parEnd) :
LineBase(parStart, parEnd),
m_sdlmain(parMain),
m_colour(parColour)
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void DrawableLine::Render (const float2& parPos, const float2& parScaling) const {
SDL_SetRenderDrawColor(m_sdlmain->GetRenderer(), m_colour.r, m_colour.g, m_colour.b, m_colour.a);
LineBase scaledLine(*this);
scaledLine += static_cast<ushort2>(parPos);
scaledLine *= parScaling;
{
SDL_Rect screen;
screen.x = screen.y = 0;
const ushort2 wh(m_sdlmain->WidthHeight());
screen.w = wh.x();
screen.h = wh.y();
ClipLine(screen, scaledLine);
}
//SDL_RenderDrawLine(m_sdlmain->GetRenderer(), x1, y1, x2, y2
//Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.
//http://www.ginkgobitter.org/sdl/?SDL_RenderDrawLine
}
} //namespace cloonel
#endif

71
src/drawableline.hpp Normal file
View file

@ -0,0 +1,71 @@
/*
Copyright 2014 Michele "King_DuckZ" Santullo
This file is part of CloonelJump.
CloonelJump is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CloonelJump is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CloonelJump. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idE8A33294FB164199B0A23E0385DD0E09
#define idE8A33294FB164199B0A23E0385DD0E09
#if defined(WITH_DEBUG_VISUALS)
#include "colour.hpp"
#include "line.hpp"
#include <cstdint>
namespace cloonel {
class SDLMain;
class DrawableLine : public Line<uint16_t, 2> {
typedef Line<uint16_t, 2> LineBase;
public:
explicit DrawableLine ( SDLMain* parMain );
explicit DrawableLine ( SDLMain* parMain, Colour parColour );
DrawableLine ( SDLMain* parMain, Colour parColour, const LineBase& parLine );
DrawableLine ( SDLMain* parMain, Colour parColour, const LineBase::Point& parStart, const LineBase::Point& parEnd );
DrawableLine ( const DrawableLine& parOther ) = default;
virtual ~DrawableLine ( void ) noexcept = default;
DrawableLine& operator= ( const DrawableLine& ) = delete;
void Render ( const float2& parPos, const float2& parScaling ) const;
private:
SDLMain* const m_sdlmain;
Colour m_colour;
};
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline DrawableLine::DrawableLine (SDLMain* parMain) :
m_sdlmain(parMain),
m_colour()
{
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
inline DrawableLine::DrawableLine (SDLMain* parMain, Colour parColour) :
m_sdlmain(parMain),
m_colour(parColour)
{
}
} //namespace cloonel
#endif
#endif

View file

@ -74,4 +74,10 @@ namespace cloonel {
void Platform::OnRegister (Mover& parMover, Mover::PlaceableTicketType parParentTicket) {
parMover.RegisterPlaceable(m_collisionTop.get(), parParentTicket);
}
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
void Platform::CopyDrawables (std::vector<const Drawable*>& parOut) const {
parOut.push_back(this);
}
} //namespace cloonel

View file

@ -25,6 +25,7 @@
#include "placeable.hpp"
#include "collidertypedef.hpp"
#include <memory>
#include <vector>
namespace cloonel {
class Texture;
@ -33,6 +34,10 @@ namespace cloonel {
class Platform : public Drawable, public Placeable {
public:
enum {
SurfaceCount = 1
};
Platform ( SDLMain* parSdlMain, const float2& parPos, Texture* parTexture, const float2& parSize );
Platform ( Platform&& parOther ) noexcept;
Platform ( const Platform& ) = delete;
@ -42,6 +47,7 @@ namespace cloonel {
float2 TopLeft ( void ) const { return GetPos(); }
float2 BottomRight ( void ) const { return TopLeft() + m_size; }
const HorzCollisionBar* TopCollisionBar ( void ) const { return m_collisionTop.get(); }
void CopyDrawables ( std::vector<const Drawable*>& parOut ) const;
//Overrides
virtual void Draw ( void ) const;

View file

@ -78,9 +78,9 @@ namespace cloonel {
void PlatformSet::CopyDrawables (std::vector<const Drawable*>& parOut) const {
auto eleCopy = FindFirstVisible(m_platforms);
const size_t count = m_platforms.end() - eleCopy;
parOut.reserve(parOut.size() + count);
parOut.reserve(parOut.size() + count * Platform::SurfaceCount);
while (m_platforms.end() != eleCopy) {
parOut.push_back(&*eleCopy);
eleCopy->CopyDrawables(parOut);
++eleCopy;
}
}