WiP - causes an internal error in gcc 4.9
This commit is contained in:
parent
eced8388f2
commit
149174c186
22 changed files with 799 additions and 11 deletions
|
@ -59,9 +59,13 @@ add_executable(${PROJECT_NAME}
|
|||
src/drawable.cpp
|
||||
src/sizeratio.cpp
|
||||
src/sizenotifiable.cpp
|
||||
src/horzcollisionbar.cpp
|
||||
src/platform.cpp
|
||||
src/geometry.cpp
|
||||
src/geometry_2d.cpp
|
||||
src/vectormath.cpp
|
||||
src/platformsystem.cpp
|
||||
src/movers/moverconstant.cpp
|
||||
src/movers/moverworld.cpp
|
||||
src/line.cpp
|
||||
src/collider.cpp
|
||||
|
|
BIN
docs/Geometry1x1.pdf
Normal file
BIN
docs/Geometry1x1.pdf
Normal file
Binary file not shown.
31
src/algorithm.hpp
Normal file
31
src/algorithm.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
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 id9278692FCFD447B7AC3E8987D745BA16
|
||||
|
||||
#include <algorithm>
|
||||
#include "vector.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
template <typename T>
|
||||
void swap ( T& parA, T& parB) noexcept;
|
||||
} //namespace cloonel
|
||||
|
||||
#include <algorithm.inl>
|
||||
#endif
|
26
src/algorithm.inl
Normal file
26
src/algorithm.inl
Normal file
|
@ -0,0 +1,26 @@
|
|||
namespace cloonel {
|
||||
namespace implem {
|
||||
template <typename T>
|
||||
struct Swapper {
|
||||
static void swap ( T& parA, T& parB ) noexcept {
|
||||
std::swap(parA, parB);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename U, uint32_t S>
|
||||
struct Swapper<Vector<U, S> > {
|
||||
static void swap ( Vector<U, S>& parA, Vector<U, S>& parB ) noexcept {
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
swap(parA[z], parB[z]);
|
||||
}
|
||||
}
|
||||
};
|
||||
} //namespace implem
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void swap ( T& parA, T& parB) noexcept {
|
||||
implem::Swapper<T>::swap(parA, parB);
|
||||
}
|
||||
} //namespace cloonel
|
|
@ -28,6 +28,7 @@ namespace cloonel {
|
|||
Character::Character (const std::string& parPath, SDLMain* parMain, float2 parSize) :
|
||||
Placeable(float2(0.0f)),
|
||||
Drawable(parSize),
|
||||
m_bottomBar(float2(0.0f), parSize.x()),
|
||||
m_screenRatio(parMain),
|
||||
m_texture(new Texture(parPath, parMain, false))
|
||||
{
|
||||
|
@ -39,6 +40,7 @@ namespace cloonel {
|
|||
Character::Character (const std::string&& parPath, SDLMain* parMain, float2 parSize) :
|
||||
Placeable(float2(0.0f)),
|
||||
Drawable(parSize),
|
||||
m_bottomBar(float2(0.0f), parSize.x()),
|
||||
m_screenRatio(parMain),
|
||||
m_texture(new Texture(parPath, parMain, false))
|
||||
{
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "drawable.hpp"
|
||||
#include "vector.hpp"
|
||||
#include "sizenotifiable.hpp"
|
||||
#include "horzcollisionbar.hpp"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
|
@ -42,6 +43,7 @@ namespace cloonel {
|
|||
virtual void Draw ( void ) const;
|
||||
|
||||
private:
|
||||
HorzCollisionBar m_bottomBar;
|
||||
SizeNotifiable<regbehaviours::AutoRegister> m_screenRatio;
|
||||
const std::unique_ptr<Texture> m_texture;
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <functional>
|
||||
#include <ciso646>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(WITH_VERBOSE_COLLIDER) && !defined(NDEBUG)
|
||||
#define VERBOSE_COLLIDER
|
||||
|
@ -31,6 +32,9 @@
|
|||
#endif
|
||||
|
||||
namespace cloonel {
|
||||
namespace {
|
||||
} //unnamed namespace
|
||||
|
||||
struct Collider::LocalData {
|
||||
LocalData ( void );
|
||||
~LocalData ( void ) noexcept = default;
|
||||
|
|
25
src/geometry.cpp
Normal file
25
src/geometry.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
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 "geometry.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
} //namespace cloonel
|
34
src/geometry.hpp
Normal file
34
src/geometry.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
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 id3E40B29606D048569E18083DB682280F
|
||||
#define id3E40B29606D048569E18083DB682280F
|
||||
|
||||
#include "vector.hpp"
|
||||
#include <ciso646>
|
||||
#include <algorithm>
|
||||
|
||||
namespace cloonel {
|
||||
template <typename T, uint32_t S>
|
||||
bool IsPointOnSegment ( const Vector<T, S>& parPoint, const Vector<T, S>& parSegA, const Vector<T, S>& parSegB ) __attribute__((pure));
|
||||
} //namespace cloonel
|
||||
|
||||
#include "geometry.inl"
|
||||
|
||||
#endif
|
31
src/geometry.inl
Normal file
31
src/geometry.inl
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T, uint32_t S>
|
||||
bool IsPointOnSegment (const Vector<T, S>& parPoint, const Vector<T, S>& parSegA, const Vector<T, S>& parSegB) {
|
||||
for (uint32_t z = 0; z < S; ++z) {
|
||||
if (parPoint[z] <= std::max(parSegA[z], parSegB[z]) and parPoint[z] >= std::min(parSegA[z], parSegB[z]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} //namespace cloonel
|
23
src/geometry_2d.cpp
Normal file
23
src/geometry_2d.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
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 "geometry_2d.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
} //namespace cloonel
|
42
src/geometry_2d.hpp
Normal file
42
src/geometry_2d.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
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 "vector.hpp"
|
||||
#include "line.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include <ciso646>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef id2B404E7CFDD3470680E572779CB819F6
|
||||
#define id2B404E7CFDD3470680E572779CB819F6
|
||||
|
||||
namespace cloonel {
|
||||
template <typename T>
|
||||
int GetOrientation ( const Vector<T, 2>& parPointA, const Vector<T, 2>& parPointB, const Vector<T, 2>& parPointC ) __attribute__((pure));
|
||||
|
||||
template <typename T>
|
||||
bool Intersection2D ( const Vector<T, 2>& parSegA1, const Vector<T, 2>& parSegA2, const Vector<T, 2>& parSegB1, const Vector<T, 2>& parSegB2 ) __attribute__((pure));
|
||||
|
||||
template <typename T>
|
||||
Vector<T, 2> Intersection ( const Line<T, 2>& parSegA, Vector<T, 2>& parOffsA, const Line<T, 2>& parSegB, const Vector<T, 2>& parOffsB ) __attribute__((pure));
|
||||
} //namespace cloonel
|
||||
|
||||
#include "geometry_2d.inl"
|
||||
|
||||
#endif
|
74
src/geometry_2d.inl
Normal file
74
src/geometry_2d.inl
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
int GetOrientation (const Vector<T, 2>& parPointA, const Vector<T, 2>& parPointB, const Vector<T, 2>& parPointC) {
|
||||
const auto ret =
|
||||
(parPointB.y() - parPointA.y()) * (parPointC.x() - parPointB.x()) -
|
||||
(parPointB.x() - parPointA.x()) * (parPointC.y() - parPointB.y());
|
||||
const T zero(0);
|
||||
if (ret == zero)
|
||||
return 0;
|
||||
else if (ret < zero)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
bool Intersection2D (const Vector<T, 2>& parSegA1, const Vector<T, 2>& parSegA2, const Vector<T, 2>& parSegB1, const Vector<T, 2>& parSegB2) {
|
||||
const int o1 = GetOrientation(parSegA1, parSegA2, parSegB1);
|
||||
const int o2 = GetOrientation(parSegA1, parSegA2, parSegB2);
|
||||
const int o3 = GetOrientation(parSegB1, parSegB2, parSegA1);
|
||||
const int o4 = GetOrientation(parSegB1, parSegB2, parSegA2);
|
||||
|
||||
if (o1 != o2 and o3 != o4)
|
||||
return true;
|
||||
|
||||
if (0 == o1 and IsPointOnSegment(parSegA1, parSegB1, parSegA2))
|
||||
return true;
|
||||
if (0 == o2 and IsPointOnSegment(parSegA1, parSegB2, parSegA2))
|
||||
return true;
|
||||
if (0 == o3 and IsPointOnSegment(parSegB1, parSegA1, parSegB2))
|
||||
return true;
|
||||
if (0 == o4 and IsPointOnSegment(parSegB1, parSegA2, parSegB2))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
Vector<T, 2> Intersection (const Line<T, 2>& parSegA, Vector<T, 2>& parOffsA, const Line<T, 2>& parSegB, const Vector<T, 2>& parOffsB) {
|
||||
typedef Line<T, 2> LineType;
|
||||
|
||||
const LineType& startA = parSegA;
|
||||
const LineType endA = startA + parOffsA;
|
||||
const LineType& startB = parSegB;
|
||||
const LineType endB = startB + parOffsB;
|
||||
|
||||
|
||||
}
|
||||
} //namespace cloonel
|
90
src/horzcollisionbar.cpp
Normal file
90
src/horzcollisionbar.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
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 "horzcollisionbar.hpp"
|
||||
#include "line_helpers.hpp"
|
||||
#include <cassert>
|
||||
#include <utility>
|
||||
#include <ciso646>
|
||||
|
||||
namespace cloonel {
|
||||
namespace {
|
||||
typedef Line<float, 2> Line2D;
|
||||
|
||||
float calculateOverlappingTime ( float parDeltaT, float parAY, float parBY ) __attribute__((pure));
|
||||
void DoNothing ( void ) __attribute__((pure));
|
||||
std::pair<bool, Line2D> getOverlap ( float parDeltaT, const Line2D& parA, const Line2D& parB, const float2& parDeltaA, const float2& parDeltaB ) __attribute__((pure));
|
||||
|
||||
///----------------------------------------------------------------------
|
||||
///Calculate the time t at which the two segments (which are assumed to
|
||||
///be horizontal) will lie on the same line. parDeltaT is the duration
|
||||
///of the time frame being considered, parAY and parBY are the starting
|
||||
///y position of the two segments, parDeltaA and parDeltaB are the
|
||||
///distance traveled by segment A and segment B respectively in the
|
||||
///reference time frame.
|
||||
///----------------------------------------------------------------------
|
||||
float calculateOverlappingTime (float parDeltaT, float parAY, float parBY, float parDeltaA, float parDeltaB) {
|
||||
const float deltaDiff = std::max(parDeltaA, parDeltaB) - std::min(parDeltaA, parDeltaB);
|
||||
assert(deltaDiff >= 0.0f);
|
||||
|
||||
if (deltaDiff <= 0.00001f)
|
||||
return 0.0f;
|
||||
else
|
||||
return (parDeltaT * (parBY - parAY)) / (parDeltaA - parDeltaB);
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------
|
||||
///----------------------------------------------------------------------
|
||||
std::pair<bool, Line2D> getOverlap (float parDeltaT, const Line2D& parA, const Line2D& parB, const float2& parDeltaA, const float2& parDeltaB) {
|
||||
const float overlapTime = calculateOverlappingTime(parDeltaT, parA.Start().y(), parB.Start().y(), parDeltaA.y(), parDeltaB.y());
|
||||
if (overlapTime < 0.0f or overlapTime > parDeltaT)
|
||||
return std::make_pair(false, Line2D());
|
||||
|
||||
return std::make_pair(true, Line2D());
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------
|
||||
///no-op
|
||||
///----------------------------------------------------------------------
|
||||
void DoNothing() {
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
HorzCollisionBar::HorzCollisionBar (const float2& parFrom, float parLength) :
|
||||
Placeable(parFrom),
|
||||
m_segment(parFrom, float2(1.0f, 0.0f), parLength),
|
||||
m_callback(&DoNothing)
|
||||
{
|
||||
assert(parLength != 0.0f);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void HorzCollisionBar::SetCallback (std::function<void()> parCallback) {
|
||||
m_callback = parCallback;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
float2 HorzCollisionBar::To() const {
|
||||
return this->GetPos() + len(m_segment);
|
||||
}
|
||||
} //namespace cloonel
|
47
src/horzcollisionbar.hpp
Normal file
47
src/horzcollisionbar.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
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 id202E39A912AA43E5A224AC77D676F6CA
|
||||
#define id202E39A912AA43E5A224AC77D676F6CA
|
||||
|
||||
#include "vector.hpp"
|
||||
#include "placeable.hpp"
|
||||
#include "line.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace cloonel {
|
||||
class HorzCollisionBar;
|
||||
|
||||
class HorzCollisionBar : public Placeable {
|
||||
public:
|
||||
HorzCollisionBar ( const float2& parFrom, float parLength );
|
||||
~HorzCollisionBar ( void ) noexcept = default;
|
||||
|
||||
float2 From ( void ) const { return this->GetPos(); }
|
||||
float2 To ( void ) const;
|
||||
|
||||
void SetCallback ( std::function<void()> parCallback );
|
||||
|
||||
private:
|
||||
Line<float, 2> m_segment;
|
||||
std::function<void()> m_callback;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
#endif
|
15
src/movers/moverconstant.cpp
Normal file
15
src/movers/moverconstant.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "moverconstant.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
MoverConstant::MoverConstant (const float2& parVelocity) :
|
||||
m_velocity(parVelocity),
|
||||
m_space()
|
||||
{
|
||||
}
|
||||
|
||||
void MoverConstant::ApplyMotion (float parDelta) {
|
||||
m_space = m_velocity * parDelta;
|
||||
}
|
||||
} //namespace cloonel
|
39
src/movers/moverconstant.hpp
Normal file
39
src/movers/moverconstant.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
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 id89F6F718D6694E5BB1724165CD7E9B3B
|
||||
|
||||
#include "moveroneshot.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
class MoverConstant : public MoverOneShot {
|
||||
public:
|
||||
explicit MoverConstant ( const float2& parVelocity );
|
||||
virtual ~MoverConstant ( void ) noexcept = default;
|
||||
|
||||
private:
|
||||
virtual float2 GetOffset ( void ) const { return m_space; }
|
||||
virtual void ApplyMotion ( float parDelta );
|
||||
|
||||
const float2 m_velocity;
|
||||
float2 m_space;
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
#endif
|
246
src/observersmanager.hpp.orig
Normal file
246
src/observersmanager.hpp.orig
Normal file
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
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 idF5E41734950640CDA3C949E0D3A9A30D
|
||||
#define idF5E41734950640CDA3C949E0D3A9A30D
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <ciso646>
|
||||
#include <tree.hh>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
namespace cloonel {
|
||||
namespace implem {
|
||||
template <typename T>
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator ( const std::vector<bool>& parOccupied, std::vector<T>& parItems, bool parEnd ) :
|
||||
m_occupied(parOccupied),
|
||||
m_items(parItems),
|
||||
m_pos(parEnd ? m_occupied.size() : 0)
|
||||
{
|
||||
assert(m_occupied.size() == m_items.size());
|
||||
}
|
||||
Iterator ( const Iterator& parOther ) :
|
||||
m_occupied(parOther.m_occupied),
|
||||
m_items(parOther.m_items),
|
||||
m_pos(parOther.m_pos)
|
||||
{
|
||||
}
|
||||
~Iterator ( void ) noexcept = default;
|
||||
|
||||
T operator-> ( void ) {
|
||||
assert(m_pos < m_occupied.size());
|
||||
assert(m_occupied[m_pos]);
|
||||
return m_items[m_pos];
|
||||
}
|
||||
T operator* ( void ) {
|
||||
assert(m_pos < m_occupied.size());
|
||||
assert(m_occupied[m_pos]);
|
||||
return m_items[m_pos];
|
||||
}
|
||||
|
||||
Iterator& operator++ ( void ) {
|
||||
if (m_occupied.size() == m_pos)
|
||||
return *this;
|
||||
auto itNext = std::find(m_occupied.begin() + static_cast<std::vector<bool>::difference_type>(m_pos + 1), m_occupied.end(), true);
|
||||
if (m_occupied.end() != itNext)
|
||||
m_pos = static_cast<std::size_t>(itNext - m_occupied.begin());
|
||||
else
|
||||
m_pos = m_occupied.size();
|
||||
return *this;
|
||||
}
|
||||
Iterator operator++ ( int ) {
|
||||
Iterator prevState(*this);
|
||||
++(*this);
|
||||
return prevState;
|
||||
}
|
||||
|
||||
bool operator== ( const Iterator& parOther ) const {
|
||||
return m_pos == parOther.m_pos and &m_items == &parOther.m_items;
|
||||
}
|
||||
bool operator!= ( const Iterator& parOther ) const { return not this->operator==(parOther); }
|
||||
|
||||
private:
|
||||
const std::vector<bool>& m_occupied;
|
||||
std::vector<T>& m_items;
|
||||
std::size_t m_pos;
|
||||
};
|
||||
} //namespace implem
|
||||
|
||||
template <typename T>
|
||||
class ObserversManager {
|
||||
public:
|
||||
typedef size_t TicketType;
|
||||
<<<<<<< HEAD
|
||||
|
||||
private:
|
||||
struct TicketedWrapper {
|
||||
TicketedWrapper ( void ) = default;
|
||||
TicketedWrapper ( T parItem, TicketType parTicket ) :
|
||||
itm(parItem),
|
||||
ticket(parTicket)
|
||||
{
|
||||
}
|
||||
|
||||
T itm;
|
||||
TicketType ticket;
|
||||
|
||||
bool operator== ( const TicketedWrapper& parOther ) const { return parOther.ticket == ticket; }
|
||||
bool operator== ( TicketType parOther ) const { return parOther == ticket; }
|
||||
};
|
||||
static T& TicketedWrapperToItm ( TicketedWrapper& parWrapper ) { return parWrapper.itm; }
|
||||
|
||||
typedef tree<TicketedWrapper> TreeType;
|
||||
typedef typename tree<TicketedWrapper>::iterator TreeIteratorType;
|
||||
|
||||
public:
|
||||
enum {
|
||||
Ticket_Null = 0
|
||||
};
|
||||
typedef boost::transform_iterator<std::function<T&(TicketedWrapper&)>, TreeIteratorType> iterator;
|
||||
|
||||
=======
|
||||
typedef implem::Iterator<T> iterator;
|
||||
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
ObserversManager ( void );
|
||||
~ObserversManager ( void ) noexcept = default;
|
||||
|
||||
TicketType Add ( T parObserver, TicketType parParent=Ticket_Null );
|
||||
void Remove ( TicketType parTicket ) noexcept;
|
||||
void Update ( TicketType parTicket, T parObserver );
|
||||
<<<<<<< HEAD
|
||||
std::size_t size ( void ) const { return m_tree.size(); }
|
||||
iterator begin ( void ) { return iterator(m_tree.begin(), &TicketedWrapperToItm); }
|
||||
iterator end ( void ) { return iterator(m_tree.end(), &TicketedWrapperToItm); }
|
||||
|
||||
private:
|
||||
TreeIteratorType GetByTicket_AssertPresent ( TicketType parTicket );
|
||||
|
||||
TreeType m_tree;
|
||||
TicketType m_nextTicket;
|
||||
=======
|
||||
std::size_t size ( void ) const { return m_usedCount; }
|
||||
iterator begin ( void ) { return iterator(m_occupied, m_list, false); }
|
||||
iterator end ( void ) { return iterator(m_occupied, m_list, true); }
|
||||
|
||||
private:
|
||||
std::vector<T> m_list;
|
||||
std::vector<bool> m_occupied;
|
||||
std::size_t m_usedCount;
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
};
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
ObserversManager<T>::ObserversManager() :
|
||||
<<<<<<< HEAD
|
||||
m_nextTicket(1)
|
||||
=======
|
||||
m_usedCount(0)
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
{
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
<<<<<<< HEAD
|
||||
typename ObserversManager<T>::TicketType ObserversManager<T>::Add (T parObserver, TicketType parParent) {
|
||||
const auto currTicket = m_nextTicket;
|
||||
if (Ticket_Null == parParent)
|
||||
m_tree.insert(m_tree.begin(), TicketedWrapper(parObserver, currTicket));
|
||||
else
|
||||
m_tree.append_child(GetByTicket_AssertPresent(parParent), TicketedWrapper(parObserver, currTicket));
|
||||
|
||||
++m_nextTicket;
|
||||
return currTicket;
|
||||
=======
|
||||
typename ObserversManager<T>::TicketType ObserversManager<T>::Add (T parObserver) {
|
||||
m_list.push_back(parObserver);
|
||||
m_occupied.push_back(true);
|
||||
++m_usedCount;
|
||||
return static_cast<TicketType>(m_list.size());
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void ObserversManager<T>::Remove (TicketType parTicket) noexcept {
|
||||
<<<<<<< HEAD
|
||||
auto deleme = GetByTicket_AssertPresent(parTicket);
|
||||
m_tree.erase(deleme);
|
||||
if (parTicket == m_nextTicket - 1)
|
||||
--m_nextTicket;
|
||||
=======
|
||||
assert(static_cast<std::size_t>(parTicket) <= m_list.size());
|
||||
assert(m_occupied[parTicket - 1]);
|
||||
assert(m_usedCount > 0);
|
||||
assert(m_list.size() == m_occupied.size());
|
||||
|
||||
m_occupied[parTicket - 1] = false;
|
||||
--m_usedCount;
|
||||
|
||||
std::size_t deleCount = 0;
|
||||
for (auto itOcc = m_occupied.rbegin(), itOccEND = m_occupied.rend(); itOcc != itOccEND and not *itOcc; ++itOcc) {
|
||||
++deleCount;
|
||||
}
|
||||
|
||||
if (deleCount) {
|
||||
assert(deleCount <= m_occupied.size());
|
||||
const std::size_t newSize = m_occupied.size() - deleCount;
|
||||
m_occupied.resize(newSize);
|
||||
m_list.resize(newSize);
|
||||
}
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void ObserversManager<T>::Update (TicketType parTicket, T parObserver) {
|
||||
<<<<<<< HEAD
|
||||
std::swap(GetByTicket_AssertPresent(parTicket)->itm, parObserver);
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
typename ObserversManager<T>::TreeIteratorType ObserversManager<T>::GetByTicket_AssertPresent (TicketType parTicket) {
|
||||
auto ret = std::find(m_tree.begin(), m_tree.end(), parTicket);
|
||||
assert(m_tree.end() != ret);
|
||||
return ret;
|
||||
=======
|
||||
assert(static_cast<std::size_t>(parTicket) <= m_list.size());
|
||||
assert(m_occupied[parTicket - 1]);
|
||||
assert(m_usedCount > 0);
|
||||
assert(m_list.size() == m_occupied.size());
|
||||
|
||||
std::swap(m_list[parTicket - 1], parObserver);
|
||||
>>>>>>> parent of 9c2f619... Refactoring in ObserversManager.
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
||||
#endif
|
32
src/parallelogram.hpp
Normal file
32
src/parallelogram.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
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 id751DA3D76B4D48E4B6F2510B1C4CE94D
|
||||
#define id751DA3D76B4D48E4B6F2510B1C4CE94D
|
||||
|
||||
namespace cloonel {
|
||||
class Parallelogram {
|
||||
public:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
} //namespace cloonel
|
||||
|
||||
#endif
|
|
@ -26,6 +26,7 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
Platform::Platform (SDLMain* parSdlMain, const float2& parPos, Texture* parTexture, const float2& parSize) :
|
||||
Placeable(parPos),
|
||||
m_collisionTop(parPos, parSize.x()),
|
||||
m_screenRatio(parSdlMain),
|
||||
m_size(parSize),
|
||||
m_surface(parTexture)
|
||||
|
@ -37,6 +38,7 @@ namespace cloonel {
|
|||
///--------------------------------------------------------------------------
|
||||
Platform::Platform (Platform&& parOther) noexcept :
|
||||
Placeable(parOther.GetPos()),
|
||||
m_collisionTop(parOther.m_collisionTop),
|
||||
m_screenRatio(std::move(parOther.m_screenRatio)),
|
||||
m_size(parOther.m_size),
|
||||
m_surface(parOther.m_surface)
|
||||
|
@ -59,4 +61,10 @@ namespace cloonel {
|
|||
m_surface = parOther.m_surface;
|
||||
return *this;
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
void Platform::OnRegister (Mover& parMover, Mover::PlaceableTicketType parParentTicket) {
|
||||
parMover.RegisterPlaceable(&m_collisionTop, parParentTicket);
|
||||
}
|
||||
} //namespace cloonel
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "sizenotifiable.hpp"
|
||||
#include "drawable.hpp"
|
||||
#include "placeable.hpp"
|
||||
#include "horzcollisionbar.hpp"
|
||||
|
||||
namespace cloonel {
|
||||
class Texture;
|
||||
|
@ -36,11 +37,15 @@ namespace cloonel {
|
|||
virtual ~Platform ( void ) noexcept = default;
|
||||
Platform& operator= ( const Platform& parOther );
|
||||
|
||||
virtual void Draw ( void ) const;
|
||||
float2 TopLeft ( void ) const { return GetPos(); }
|
||||
float2 BottomRight ( void ) const { return TopLeft() + m_size; }
|
||||
|
||||
//Overrides
|
||||
virtual void Draw ( void ) const;
|
||||
virtual void OnRegister ( Mover& parMover, Mover::PlaceableTicketType parParentTicket );
|
||||
|
||||
private:
|
||||
HorzCollisionBar m_collisionTop;
|
||||
SizeNotifiable<regbehaviours::AutoRegister> m_screenRatio;
|
||||
float2 m_size;
|
||||
Texture* m_surface;
|
||||
|
|
|
@ -34,6 +34,21 @@ namespace cloonel {
|
|||
namespace {
|
||||
const uint32_t g_platfWidth = 104;
|
||||
const uint32_t g_platfHeight = 25;
|
||||
|
||||
float2 PositionForNewPlatf (float parStart, float parMaxDist, size_t parLeft) {
|
||||
return float2(0.0f);
|
||||
////Check how many platforms at least will let the player jump his way
|
||||
////from parStart to the top
|
||||
//const float refHeight = static_cast<float>(REFERENCE_HEIGHT);
|
||||
//const float minCountRequired = (refHeightInv - parStart) / parMaxDistance;
|
||||
|
||||
//const float y = std::min(
|
||||
// static_cast<float>(REFERENCE_HEIGHT) - 25.0f,
|
||||
// static_cast<float>(z) * (static_cast<float>(REFERENCE_HEIGHT) * totalPlatfFloatInv)
|
||||
//);
|
||||
//const auto rndNum = std::rand() % (REFERENCE_WIDTH - platfWH.x());
|
||||
//const float2 newPos(static_cast<float>(rndNum), 100.0f + std::min(m_localdata->maxDistance, y));
|
||||
}
|
||||
} //unnamed namespace
|
||||
|
||||
struct PlatformInfo {
|
||||
|
@ -131,15 +146,11 @@ namespace cloonel {
|
|||
//Spawn the initial platforms
|
||||
m_localdata->platforms.reset();
|
||||
const size_t totalPlatf = m_localdata->platforms.capacity();
|
||||
const auto totalPlatfFloatInv = 1.0f / static_cast<float>(totalPlatf);
|
||||
//const auto totalPlatfFloatInv = 1.0f / static_cast<float>(totalPlatf);
|
||||
const int2 platfWH(g_platfWidth, g_platfHeight);
|
||||
for (size_t z = 0; z < totalPlatf; ++z) {
|
||||
const float y = std::min(
|
||||
static_cast<float>(REFERENCE_HEIGHT) - 25.0f,
|
||||
static_cast<float>(z) * (static_cast<float>(REFERENCE_HEIGHT) * totalPlatfFloatInv)
|
||||
);
|
||||
const auto rndNum = std::rand() % (REFERENCE_WIDTH - platfWH.x());
|
||||
const float2 newPos(static_cast<float>(rndNum), 100.0f + std::min(m_localdata->maxDistance, y));
|
||||
const auto newPos(PositionForNewPlatf(0.0f, m_localdata->maxDistance, totalPlatf - z));
|
||||
|
||||
m_localdata->platforms.push(Platform(m_localdata->sdlmain, newPos, &m_localdata->texture, static_cast<float2>(platfWH)));
|
||||
}
|
||||
}
|
||||
|
@ -149,9 +160,6 @@ namespace cloonel {
|
|||
void PlatformSystem::Destroy() noexcept {
|
||||
m_localdata->texture.Destroy();
|
||||
|
||||
for (size_t z = 0; z < m_localdata->platforms.size(); ++z) {
|
||||
m_localdata->mover.UnregisterPlaceable(m_localdata->platforms[z].ticket);
|
||||
}
|
||||
m_localdata->platforms.reset();
|
||||
m_localdata->platformsBuff.clear();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue