diff --git a/CMakeLists.txt b/CMakeLists.txt index e883a38..52ed2b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} diff --git a/src/colour.hpp b/src/colour.hpp new file mode 100644 index 0000000..1e06308 --- /dev/null +++ b/src/colour.hpp @@ -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 . + +*/ + +#ifndef id1DA767EB516A4F4588347DFC14D1A999 +#define id1DA767EB516A4F4588347DFC14D1A999 + +#if defined(WITH_DEBUG_VISUALS) +#include + +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 diff --git a/src/drawableline.cpp b/src/drawableline.cpp new file mode 100644 index 0000000..8d3a5b5 --- /dev/null +++ b/src/drawableline.cpp @@ -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 . + +*/ + +#include "drawableline.hpp" +#include "sdlmain.hpp" +#include + +#if defined(WITH_DEBUG_VISUALS) +namespace cloonel { + namespace { + ///---------------------------------------------------------------------- + ///---------------------------------------------------------------------- + void ClipLine (const SDL_Rect& /*parArea*/, Line& /*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(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 diff --git a/src/drawableline.hpp b/src/drawableline.hpp new file mode 100644 index 0000000..c4626ee --- /dev/null +++ b/src/drawableline.hpp @@ -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 . + +*/ + +#ifndef idE8A33294FB164199B0A23E0385DD0E09 +#define idE8A33294FB164199B0A23E0385DD0E09 + +#if defined(WITH_DEBUG_VISUALS) + +#include "colour.hpp" +#include "line.hpp" +#include + +namespace cloonel { + class SDLMain; + + class DrawableLine : public Line { + typedef Line 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 diff --git a/src/platform.cpp b/src/platform.cpp index 78ac61b..4b8b269 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -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& parOut) const { + parOut.push_back(this); + } } //namespace cloonel diff --git a/src/platform.hpp b/src/platform.hpp index 9d7c267..a2130cf 100644 --- a/src/platform.hpp +++ b/src/platform.hpp @@ -25,6 +25,7 @@ #include "placeable.hpp" #include "collidertypedef.hpp" #include +#include 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& parOut ) const; //Overrides virtual void Draw ( void ) const; diff --git a/src/platformset.cpp b/src/platformset.cpp index 5c86129..40b2333 100644 --- a/src/platformset.cpp +++ b/src/platformset.cpp @@ -78,9 +78,9 @@ namespace cloonel { void PlatformSet::CopyDrawables (std::vector& 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; } }