Add MathEngineTest and Commects and clean ups

This commit is contained in:
2018-08-18 20:50:06 -04:00
parent bd3c111fa1
commit a815367c9d
52 changed files with 386 additions and 144 deletions
@@ -31,8 +31,7 @@ namespace AudioEngine {
/* Plays the sounds */ /* Plays the sounds */
void SoundPlay(); void SoundPlay();
/* Plays the music */ /* Plays the music */
void MusicPlay(); void MusicPlay();
/// Set /// Set
/* Sets the rate */ /* Sets the rate */
@@ -40,8 +40,6 @@ namespace AudioEngine {
Mix_Music* mp_music; Mix_Music* mp_music;
unsigned char m_volume;/// = 255 unsigned char m_volume;/// = 255
};/// END CLASS DEFINITION cMusic };/// END CLASS DEFINITION cMusic
}/// END NAMESPACE DEFINITION AudioEngine }/// END NAMESPACE DEFINITION AudioEngine
#endif/// END IFNDEF _CMUSIC_HPP_ #endif/// END IFNDEF _CMUSIC_HPP_
@@ -79,13 +79,12 @@ namespace AudioEngine {
cString m_dir;/// = "" cString m_dir;/// = ""
cString m_fileName;/// = "" cString m_fileName;/// = ""
unsigned char m_volume;/// = 255
unsigned char m_distance;/// = 100
unsigned char m_volume;// = 255 short int m_angle;/// = 0
unsigned char m_distance;// = 100 long int m_channel;/// = -1
long int m_loops;/// = 0
short int m_angle;// = 0
long int m_channel;// = -1
long int m_loops;// = 0
};/// END CLASS DEFINITION cSound };/// END CLASS DEFINITION cSound
}/// END NAMESPACE DEFINITION AudioEngine }/// END NAMESPACE DEFINITION AudioEngine
#endif/// END IFNDEF _CSOUND_HPP_ #endif/// END IFNDEF _CSOUND_HPP_
@@ -28,10 +28,10 @@ cEvent::cEvent()
OnMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, (event.motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0); OnMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, (event.motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
OnMouseButtonUp(event); OnMouseButtonDown(event);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
OnMouseButtonDown(event); OnMouseButtonUp(event);
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
OnJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value); OnJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
@@ -67,6 +67,7 @@ namespace EventEngine {
virtual void OnExit(); virtual void OnExit();
virtual void OnUser( Uint32 type, int code, void* data1, void* data2 ); virtual void OnUser( Uint32 type, int code, void* data1, void* data2 );
private: private:
void OnWindowsEvent( const SDL_Event& event ); void OnWindowsEvent( const SDL_Event& event );
void OnMouseButtonDown( const SDL_Event& event ); void OnMouseButtonDown( const SDL_Event& event );
@@ -24,7 +24,7 @@ namespace EventEngine {
static cEventControl& Inst(); static cEventControl& Inst();
static void Delete(); static void Delete();
//Functions /// Functions
const bool Initialize() const; const bool Initialize() const;
const bool Setup(); const bool Setup();
@@ -39,13 +39,14 @@ namespace EventEngine {
std::vector<EventEngine::cEvent*>& GetEvents(); std::vector<EventEngine::cEvent*>& GetEvents();
///Sets /// Sets
///Gets /// Gets
/* Gets return true if Event was initialized */ /* Gets return true if Event was initialized */
const bool IsInit() const; const bool IsInit() const;
private: private:
/// Variables
std::vector<cEvent*> m_children; std::vector<cEvent*> m_children;
static cEventControl* sp_inst;// = nullptr static cEventControl* sp_inst;// = nullptr
};/// END CLASS DEFINITION cEventControl };/// END CLASS DEFINITION cEventControl
@@ -41,6 +41,13 @@ void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Co
cUtility::Inst().Message("Unable to render text. stringRGBA():", __AT__, cUtility::eTypeSDL::GFX); cUtility::Inst().Message("Unable to render text. stringRGBA():", __AT__, cUtility::eTypeSDL::GFX);
} }
void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Surface* surface ) const
{
//cRenderer::Inst().SetRenderTarget(texture);
//StringDefault(text, pos, colour);
//cRenderer::Inst().ResetRenderTarget();
}
void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Texture* texture ) const void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Texture* texture ) const
{ {
cRenderer::Inst().SetRenderTarget(texture); cRenderer::Inst().SetRenderTarget(texture);
@@ -48,6 +55,17 @@ void cGFX::StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Co
cRenderer::Inst().ResetRenderTarget(); cRenderer::Inst().ResetRenderTarget();
} }
SDL_Texture* cGFX::StringTexture( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const
{
SDL_Texture* rtn = cRenderer::Inst().NewTexture(8 * text.length(), 8, false, SDL_TEXTUREACCESS_TARGET);
if (rtn != nullptr)
cGFX::Inst().StringDefault(text, pos, colour, rtn);
else
cUtility::Inst().Message("Unable to create NewTexture in StringTexture. cRenderer::NewTexture():", __AT__);
return rtn;
}
void cGFX::Box( const SDL_Rect& rect, const SDL_Colour& colour ) const void cGFX::Box( const SDL_Rect& rect, const SDL_Colour& colour ) const
{ {
if (boxRGBA(cRenderer::Inst().getRenderer(), (Sint16)rect.x, (Sint16)rect.y, (Sint16)rect.w, (Sint16)rect.h, colour.r, colour.g, colour.b, colour.a) < 0) if (boxRGBA(cRenderer::Inst().getRenderer(), (Sint16)rect.x, (Sint16)rect.y, (Sint16)rect.w, (Sint16)rect.h, colour.r, colour.g, colour.b, colour.a) < 0)
@@ -100,17 +118,28 @@ void cGFX::Rectangle( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Textur
cRenderer::Inst().ResetRenderTarget(); cRenderer::Inst().ResetRenderTarget();
} }
void cGFX::ZoomIn( SDL_Texture* texture, const double zoomx, const double zoomy, const unsigned long int smooth /*= SMOOTHING_ON*/ ) const SDL_Surface* cGFX::ZoomIn( SDL_Surface* surface, const double zoomx, const double zoomy, const unsigned long int smooth /*= SMOOTHING_ON*/ ) const
{
SDL_Surface* rtn = nullptr;
rtn = zoomSurface(surface, zoomx, zoomy, smooth);
return rtn;
}
SDL_Texture* cGFX::ZoomIn( SDL_Texture* texture, const double zoomx, const double zoomy, const unsigned long int smooth /*= SMOOTHING_ON*/ ) const
{ {
SDL_Surface* surface = cRenderer::Inst().TextureToSurface(texture); SDL_Surface* surface = cRenderer::Inst().TextureToSurface(texture);
SDL_DestroyTexture(texture); SDL_Surface* zoom_sur = zoomSurface(surface, zoomx, zoomy, smooth);
texture = nullptr;
zoomSurface(surface, zoomx, zoomy, smooth);
texture = cRenderer::Inst().SurfaceToTexture(surface);
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
surface = nullptr; surface = nullptr;
SDL_Texture* rtn = cRenderer::Inst().SurfaceToTexture(zoom_sur);
SDL_FreeSurface(zoom_sur);
zoom_sur = nullptr;
return rtn;
} }
@@ -25,24 +25,42 @@ namespace FXEngine {
static cGFX& Inst(); static cGFX& Inst();
static void Delete(); static void Delete();
/* Render to the renderer with stringRGBA() from SDL2_gfx */
void StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const; void StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const;
void StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Surface* surface ) const;
/* Sets texture to renderer and calls StringDefault(text, pos, colour) */
void StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Texture* texture ) const; void StringDefault( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour, SDL_Texture* texture ) const;
/* Creates a Texture for use and calls StringDefault(text, pos, colour, texture) */
SDL_Texture* StringTexture( const cString& text, const SDL_Rect& pos, const SDL_Colour& colour ) const;
/* Render to the renderer with boxRGBA() from SDL2_gfx */
void Box( const SDL_Rect& rect, const SDL_Colour& colour ) const; void Box( const SDL_Rect& rect, const SDL_Colour& colour ) const;
/* Sets texture to renderer and calls Box(rect, colour) */
void Box( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const; void Box( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const;
/* Render to the renderer with roundedBoxRGBA() from SDL2_gfx */
void RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour ) const; void RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour ) const;
/* Sets texture to renderer and calls RoundedBox(rect, rad, colour) */
void RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour, SDL_Texture* texture ) const; void RoundedBox( const SDL_Rect& rect, const unsigned long int rad, const SDL_Colour& colour, SDL_Texture* texture ) const;
/* Render to the renderer with pixelRGBA() from SDL2_gfx */
void Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour ) const; void Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour ) const;
/* Sets texture to renderer and calls Pixel(x, y, colour) */
void Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour, SDL_Texture* texture ) const; void Pixel( const unsigned long int x, const unsigned long int y, const SDL_Colour& colour, SDL_Texture* texture ) const;
/* Render to the renderer with rectangleRGBA() from SDL2_gfx */
void Rectangle( const SDL_Rect& rect, const SDL_Colour& colour ) const; void Rectangle( const SDL_Rect& rect, const SDL_Colour& colour ) const;
/* Sets texture to renderer and calls Rectangle(rect, colour) */
void Rectangle( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const; void Rectangle( const SDL_Rect& rect, const SDL_Colour& colour, SDL_Texture* texture ) const;
void ZoomIn( SDL_Texture* texture, const double zoomx, const double zoomy, const unsigned long int smooth = SMOOTHING_ON ) const; /* Zooms in or out to stretch or shrink the surface and returns a new surface with zoomSurface() from SDL2_gfx */
SDL_Surface* ZoomIn( SDL_Surface* surface, const double zoomx, const double zoomy, const unsigned long int smooth = SMOOTHING_ON ) const;
/* Zooms in or out to stretch or shrink the texture and returns a new texture with zoomSurface() from SDL2_gfx */
SDL_Texture* ZoomIn( SDL_Texture* texture, const double zoomx, const double zoomy, const unsigned long int smooth = SMOOTHING_ON ) const;
private: private:
/// Variables
static cGFX* sp_inst;/// = nullptr static cGFX* sp_inst;/// = nullptr
};/// END CLASS DEFINITION cGFX };/// END CLASS DEFINITION cGFX
}/// END NAMESPACE DEFINITION FXEngine }/// END NAMESPACE DEFINITION FXEngine
@@ -38,7 +38,7 @@ namespace GUIHelpers {
static const RGBA DEFAULT = WHITE; static const RGBA DEFAULT = WHITE;
const RGBA StringtoRGBA(const cString& colour); const RGBA StringtoRGBA( const cString& colour );
}/// END NAMESPACE DEFINITION GUIHelpers }/// END NAMESPACE DEFINITION GUIHelpers
#endif/// END IFNDEF _GUIUTILITY_HPP_ #endif/// END IFNDEF _GUIUTILITY_HPP_
@@ -16,16 +16,17 @@ namespace GUIHelpers {
bool operator == ( const cObject& other ); bool operator == ( const cObject& other );
///Functions /// Functions
///Sets /// Sets
const void setID( const signed int id ); const void setID( const signed int id );
///Gets /// Gets
const signed int getID() const; const signed int getID() const;
virtual const GUIHelpers::eType getType() const; virtual const GUIHelpers::eType getType() const;
private: private:
/// Variables
signed int m_id;// = 0 signed int m_id;// = 0
};/// END CLASS DEFINITION cObject };/// END CLASS DEFINITION cObject
}/// END NAMESPACE DEFINITION GUIEngine }/// END NAMESPACE DEFINITION GUIEngine
@@ -62,6 +62,7 @@ namespace GUIHelpers {
void LoadDefault() const; void LoadDefault() const;
private: private:
/// Variables
bool m_loadDef;/// = false; bool m_loadDef;/// = false;
bool m_debugXML;/// = false; bool m_debugXML;/// = false;
@@ -53,6 +53,7 @@ namespace GUIEngine {
void GenerateTexture(); void GenerateTexture();
private: private:
/// Variables
VideoEngine::cImage* mp_texture;/// = nullptr VideoEngine::cImage* mp_texture;/// = nullptr
VideoEngine::cImage* mp_texturePress;/// = nullptr VideoEngine::cImage* mp_texturePress;/// = nullptr
@@ -82,6 +82,7 @@ namespace GUIEngine {
const bool IsInit() const; const bool IsInit() const;
private: private:
/// Variables
static cGUI* sp_inst;/// = nullptr static cGUI* sp_inst;/// = nullptr
unsigned long int m_debugLevel;/// = 0 unsigned long int m_debugLevel;/// = 0
@@ -55,6 +55,7 @@ namespace GUIEngine {
void SetSize(); void SetSize();
private: private:
/// Variables
VideoEngine::cSprite m_sprite; VideoEngine::cSprite m_sprite;
TextTypeEngine::cText* mp_text;/// = nullptr TextTypeEngine::cText* mp_text;/// = nullptr
};/// END CLASS DEFINITION cLabel };/// END CLASS DEFINITION cLabel
@@ -45,6 +45,7 @@ namespace GUIEngine {
virtual const GUIHelpers::RGBA& getDebugColour() const; virtual const GUIHelpers::RGBA& getDebugColour() const;
private: private:
/// Variables
GUIHelpers::eOrientation m_orientation; GUIHelpers::eOrientation m_orientation;
};/// END CLASS DEFINITION cLayout };/// END CLASS DEFINITION cLayout
}/// END NAMESPACE DEFINITION GUIEngine }/// END NAMESPACE DEFINITION GUIEngine
@@ -37,6 +37,7 @@ namespace GUIEngine {
virtual const GUIHelpers::RGBA& getDebugColour() const; virtual const GUIHelpers::RGBA& getDebugColour() const;
private: private:
/// Variables
};/// END CLASS DEFINITION cPanel };/// END CLASS DEFINITION cPanel
}/// END NAMESPACE DEFINITION GUIEngine }/// END NAMESPACE DEFINITION GUIEngine
#endif/// END IFNDEF _CPANEL_HPP_ #endif/// END IFNDEF _CPANEL_HPP_
@@ -39,7 +39,8 @@ namespace GUIEngine {
virtual const GUIHelpers::eType getType() const; virtual const GUIHelpers::eType getType() const;
virtual const GUIHelpers::RGBA& getDebugColour() const; virtual const GUIHelpers::RGBA& getDebugColour() const;
private: private:
private: private:
/// Variables
};/// END CLASS DEFINITION cSizer };/// END CLASS DEFINITION cSizer
}/// END NAMESPACE DEFINITION GUIEngine }/// END NAMESPACE DEFINITION GUIEngine
#endif/// END IFNDEF _CSIZER_HPP_ #endif/// END IFNDEF _CSIZER_HPP_
@@ -56,6 +56,7 @@ namespace GUIEngine {
void GenerateTexture(); void GenerateTexture();
private: private:
/// Variables
cLabel m_label;/// = nullptr cLabel m_label;/// = nullptr
};/// END CLASS DEFINITION cButton };/// END CLASS DEFINITION cButton
}/// END NAMESPACE DEFINITION GUIEngine }/// END NAMESPACE DEFINITION GUIEngine
@@ -114,6 +114,7 @@ namespace GUIEngine {
void DebugDisplay() const; void DebugDisplay() const;
private: private:
/// Variables
GUIHelpers::eOrientation m_orientation;/// = GUIHelper::eOrientation::NONE; GUIHelpers::eOrientation m_orientation;/// = GUIHelper::eOrientation::NONE;
GUIHelpers::eAlign m_align;/// = GUIHelper::eAlign::CENTER; GUIHelpers::eAlign m_align;/// = GUIHelper::eAlign::CENTER;
GUIHelpers::eLayout m_layout;/// = GUIHelper::eLayout::FILL_PARENT; GUIHelpers::eLayout m_layout;/// = GUIHelper::eLayout::FILL_PARENT;
@@ -61,6 +61,7 @@ namespace InputEngine {
const bool IsInit() const; const bool IsInit() const;
private: private:
/// Variables
std::vector<InputEngine::cKeyboard*> m_keyboards; std::vector<InputEngine::cKeyboard*> m_keyboards;
SDL_Event m_event; SDL_Event m_event;
@@ -32,7 +32,6 @@ namespace InputEngine {
/// Used when looking for keys that have been add to the check list /// Used when looking for keys that have been add to the check list
void JoystickCheck(); void JoystickCheck();
};/// END CLASS DEFINITION cJoystick };/// END CLASS DEFINITION cJoystick
}/// END NAMESPACE DEFINITION InputEngine }/// END NAMESPACE DEFINITION InputEngine
#endif/// END IFNDEF _CJOYSTICK_HPP_ #endif/// END IFNDEF _CJOYSTICK_HPP_
@@ -15,7 +15,7 @@ namespace InputEngine {
cKey( const cKey& copy ); cKey( const cKey& copy );
virtual ~cKey(); virtual ~cKey();
/// Funtions /// Functions
/* Call to check if the key is pressed */ /* Call to check if the key is pressed */
virtual void KeyPress(); virtual void KeyPress();
/* Call to check if the key is released */ /* Call to check if the key is released */
@@ -31,6 +31,7 @@ namespace InputEngine {
private: private:
private: private:
/// Variables
SDL_Keycode m_key; SDL_Keycode m_key;
};/// END CLASS DEFINITION cKey };/// END CLASS DEFINITION cKey
}/// END NAMESPACE DEFINITION InputEngine }/// END NAMESPACE DEFINITION InputEngine
@@ -24,7 +24,6 @@ EXPIMP_TEMPLATE template class EXPORT_FROM_MYDLL std::vector<InputEngine::cKey*,
/*#pragma warning (default : 4231)*/ /*#pragma warning (default : 4231)*/
namespace InputEngine { namespace InputEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cKeyboard class EXPORT_FROM_MYDLL cKeyboard
{ {
public: public:
@@ -47,6 +46,7 @@ namespace InputEngine {
const cString& getLabel() const; const cString& getLabel() const;
private: private:
/// Variables
cString m_label;/// = "" cString m_label;/// = ""
std::vector<InputEngine::cKey*> m_keys; std::vector<InputEngine::cKey*> m_keys;
@@ -29,8 +29,10 @@ namespace InputEngine {
virtual void KeyboardCheck( const SDL_Event& event ); virtual void KeyboardCheck( const SDL_Event& event );
/* Clears out the Text */ /* Clears out the Text */
void ClearText(); void ClearText();
/// Sets /// Sets
void setText( const cString& text ); void setText( const cString& text );
/// Gets /// Gets
const cString& getText() const; const cString& getText() const;
@@ -38,6 +40,7 @@ namespace InputEngine {
const char UnicodeValue( const SDL_Event& event ); const char UnicodeValue( const SDL_Event& event );
private: private:
/// Variables
cString m_text;/// = "" cString m_text;/// = ""
bool m_caps;/// = false bool m_caps;/// = false
bool m_shift;/// = false bool m_shift;/// = false
@@ -45,6 +45,21 @@ cCollision::~cCollision()
return true; /// bounding boxes intersect return true; /// bounding boxes intersect
} }
/*static*/ const bool cCollision::BoundingBox(const iVector4& a, const iVector4& b)
{
if ((b.x + b.z) < a.x)
return false; /// just checking if their
if ((a.x + a.z) < b.x)
return false; /// bounding boxes even touch
if ((b.y + b.w) < a.y)
return false;
if ((a.y + a.w) < b.y)
return false;
return true; /// bounding boxes intersect
}
/*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const Vector4& b ) /*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const Vector4& b )
{ {
Vector4 temp = a; Vector4 temp = a;
@@ -57,21 +72,6 @@ cCollision::~cCollision()
return cCollision::BoundingBox(b, a); return cCollision::BoundingBox(b, a);
} }
/*static*/ const bool cCollision::BoundingBox( const iVector4& a, const iVector4& b )
{
if ((b.x + b.z) < a.x)
return false; /// just checking if their
if ((a.x + a.z) < b.x )
return false; /// bounding boxes even touch
if ((b.y + b.w) < a.y)
return false;
if ((a.y + a.w) < b.y)
return false;
return true; /// bounding boxes intersect
}
/*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const iVector4& b ) /*static*/ const bool cCollision::BoundingBox( const SDL_Rect& a, const iVector4& b )
{ {
iVector4 temp = a; iVector4 temp = a;
@@ -96,28 +96,6 @@ cCollision::~cCollision()
return cCollision::BoundingBox( b, a ); return cCollision::BoundingBox( b, a );
} }
/*static*/ const Vector2 cCollision::Inside( const SDL_Rect& a, const SDL_Rect& b )
{
Vector2 rtn;
rtn.x = 0.0f;
rtn.y = 0.0f;
/// Check if left side of b is inside of a
if (b.x < a.x)
rtn.x = (float)(b.x - a.x);
/// Check if right side of b is inside of a
if ((b.x + b.w) > (a.x + a.w))
rtn.x = (float)((b.x + b.w) - (a.x + a.w));
/// Check if top side of b is inside of a
if (b.y < a.y)
rtn.y = (float)(b.y - a.y);
/// Check if bottom side of b is inside of a
if ((b.y + b.h) > (a.y + a.h))
rtn.y = (float)((b.y + b.h) - (a.y + a.h));
return rtn;
}
/*static*/ const Vector2 cCollision::Inside( const Vector4& a, const Vector4& b ) /*static*/ const Vector2 cCollision::Inside( const Vector4& a, const Vector4& b )
{ {
Vector2 rtn; Vector2 rtn;
@@ -154,6 +132,44 @@ cCollision::~cCollision()
return cCollision::Inside(a, temp); return cCollision::Inside(a, temp);
} }
/*static*/ const bool cCollision::isInside( const signed long int x, const signed long int y, const SDL_Rect& inside )
{
iVector4 temp = inside;
return cCollision::isInside(x, y, temp);
}
/*static*/ const bool cCollision::isInside( const signed long int x, const signed long int y, const iVector4& inside )
{
bool rtn = false;
if ((inside.x < x) && (inside.w > x)) {
if ((inside.y < y) && (inside.z > y))
rtn = true;
}
return rtn;
}
/*static*/ const iVector2 cCollision::Inside(const SDL_Rect& a, const SDL_Rect& b)
{
iVector2 rtn;
rtn.x = 0.0f;
rtn.y = 0.0f;
/// Check if left side of b is inside of a
if (b.x < a.x)
rtn.x = (float)(b.x - a.x);
/// Check if right side of b is inside of a
if ((b.x + b.w) > (a.x + a.w))
rtn.x = (float)((b.x + b.w) - (a.x + a.w));
/// Check if top side of b is inside of a
if (b.y < a.y)
rtn.y = (float)(b.y - a.y);
/// Check if bottom side of b is inside of a
if ((b.y + b.h) > (a.y + a.h))
rtn.y = (float)((b.y + b.h) - (a.y + a.h));
return rtn;
}
/*static*/ const iVector2 cCollision::Inside( const iVector4& a, const iVector4& b ) /*static*/ const iVector2 cCollision::Inside( const iVector4& a, const iVector4& b )
{ {
iVector2 rtn; iVector2 rtn;
@@ -20,31 +20,52 @@ namespace MathEngine {
private: private:
cCollision(); cCollision();
~cCollision(); ~cCollision();
public: public:
/// Functions /// Functions
/* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const SDL_Rect& b ); static const bool BoundingBox( const SDL_Rect& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const Vector4& b ); static const bool BoundingBox( const Vector4& a, const Vector4& b );
static const bool BoundingBox( const SDL_Rect& a, const Vector4& b ); /* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const SDL_Rect& b ); static const bool BoundingBox(const iVector4& a, const iVector4& b);
static const bool BoundingBox( const iVector4& a, const iVector4& b ); /* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const Vector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const SDL_Rect& a, const iVector4& b ); static const bool BoundingBox( const SDL_Rect& a, const iVector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const iVector4& a, const SDL_Rect& b ); static const bool BoundingBox( const iVector4& a, const SDL_Rect& b );
/* returns true if a is touching b */
static const bool BoundingBox( const iVector4& a, const Vector4& b ); static const bool BoundingBox( const iVector4& a, const Vector4& b );
/* returns true if a is touching b */
static const bool BoundingBox( const Vector4& a, const iVector4& b ); static const bool BoundingBox( const Vector4& a, const iVector4& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const SDL_Rect& a, const SDL_Rect& b );
static const Vector2 Inside( const Vector4& a, const Vector4& b ); static const Vector2 Inside( const Vector4& a, const Vector4& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const SDL_Rect& a, const Vector4& b ); static const Vector2 Inside( const SDL_Rect& a, const Vector4& b );
/* returns the Vector2 were a over laps b */
static const Vector2 Inside( const Vector4& a, const SDL_Rect& b ); static const Vector2 Inside( const Vector4& a, const SDL_Rect& b );
/* returns true if xy are inside SDL_Rect */
static const bool isInside( const signed long int x, const signed long int y, const SDL_Rect& inside );
/* returns true if xy are inside iVector4 */
static const bool isInside( const signed long int x, const signed long int y, const iVector4& inside );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside(const SDL_Rect& a, const SDL_Rect& b);
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const iVector4& a, const iVector4& b ); static const iVector2 Inside( const iVector4& a, const iVector4& b );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const SDL_Rect& a, const iVector4& b ); static const iVector2 Inside( const SDL_Rect& a, const iVector4& b );
/* returns the iVector2 were a over laps b */
static const iVector2 Inside( const iVector4& a, const SDL_Rect& b ); static const iVector2 Inside( const iVector4& a, const SDL_Rect& b );
static const Vector2 Inside( const iVector4& a, const Vector4& b ); static const Vector2 Inside( const iVector4& a, const Vector4& b );
static const Vector2 Inside( const Vector4& a, const iVector4& b ); static const Vector2 Inside( const Vector4& a, const iVector4& b );
};/// END CLASS DEFINITION cCollision };/// END CLASS DEFINITION cCollision
}/// END NAMESPACE DEFINITION MathEngine }/// END NAMESPACE DEFINITION MathEngine
#endif/// END IFNDEF _CCOLLISION_HPP_ #endif/// END IFNDEF _CCOLLISION_HPP_
@@ -26,6 +26,7 @@ namespace MathEngine {
const float Rand( const float max, const float min = 0.0f ) const; const float Rand( const float max, const float min = 0.0f ) const;
private: private:
/// Variables
static cRandom* sp_inst;/// = nullptr static cRandom* sp_inst;/// = nullptr
};/// END CLASS DEFINITION cRandom };/// END CLASS DEFINITION cRandom
}/// END NAMESPACE DEFINITION MathEngine }/// END NAMESPACE DEFINITION MathEngine
@@ -21,6 +21,7 @@ namespace TextTypeHelpers {
const unsigned long int getSize() const; const unsigned long int getSize() const;
private: private:
/// Variables
TTF_Font* mp_font;/// = nullptr TTF_Font* mp_font;/// = nullptr
unsigned long int m_size;/// = 16 unsigned long int m_size;/// = 16
};/// END CLASS DEFINITION cFontHolder };/// END CLASS DEFINITION cFontHolder
@@ -7,7 +7,7 @@ using TextTypeEngine::cFont;
using TextTypeHelpers::cFontHolder; using TextTypeHelpers::cFontHolder;
using UtilityEngine::cUtility; using UtilityEngine::cUtility;
cFont::cFont( const cString& filename /*= ""*/, const cString& dir /*= ""*/, const unsigned long int size /*= 16*/ ) cFont::cFont( const cString& filename /*= ""*/, const cString& dir /*= ""*/, const unsigned long int size /*= 8*/ )
: m_dir(dir), m_fileName(filename), mpp_default(nullptr) : m_dir(dir), m_fileName(filename), mpp_default(nullptr)
{ {
setSize(size); setSize(size);
@@ -42,7 +42,7 @@ void cFont::setFileNameandDir( const cString& filename, const cString& dir /*= "
setFileName(filename); setFileName(filename);
} }
void cFont::setSize( const unsigned long int size /*= 16*/ ) void cFont::setSize( const unsigned long int size /*= 8*/ )
{ {
while ((mpp_default == nullptr) || ((*mpp_default) == nullptr)) { while ((mpp_default == nullptr) || ((*mpp_default) == nullptr)) {
getFont(size); getFont(size);
@@ -28,12 +28,11 @@ namespace TextTypeEngine {
class EXPORT_FROM_MYDLL cFont class EXPORT_FROM_MYDLL cFont
{ {
public: public:
cFont( const cString& filename = "", const cString& dir = "", const unsigned long int size = 16 ); cFont( const cString& filename = "", const cString& dir = "", const unsigned long int size = 8 );
cFont( const cFont& copy ); cFont( const cFont& copy );
~cFont(); ~cFont();
/// Functions /// Functions
/// Sets /// Sets
/* Sets the Directory of the TTF file */ /* Sets the Directory of the TTF file */
@@ -43,7 +42,7 @@ namespace TextTypeEngine {
/* Sets the Filename and Directory of the TTF file */ /* Sets the Filename and Directory of the TTF file */
void setFileNameandDir( const cString& filename, const cString& dir = "" ); void setFileNameandDir( const cString& filename, const cString& dir = "" );
/* Sets the size of the TTF. Default is 16 */ /* Sets the size of the TTF. Default is 16 */
void setSize( const unsigned long int size = 16 ); void setSize( const unsigned long int size = 8 );
/// Gets /// Gets
/* Gets the Directory of the TTF file */ /* Gets the Directory of the TTF file */
@@ -67,13 +66,13 @@ namespace TextTypeEngine {
void UnloadFont(); void UnloadFont();
private: private:
/// Variables
std::vector<TextTypeHelpers::cFontHolder*> m_fonts; std::vector<TextTypeHelpers::cFontHolder*> m_fonts;
//cFontHolder m_fonts; //cFontHolder m_fonts;
//cFont::cFontHolder m_fonts; //cFont::cFontHolder m_fonts;
TextTypeHelpers::cFontHolder** mpp_default;/// = nullptr TextTypeHelpers::cFontHolder** mpp_default;/// = nullptr
cString m_dir;/// = "" cString m_dir;/// = ""
cString m_fileName;/// = "" cString m_fileName;/// = ""
};/// END CLASS DEFINITION cFont };/// END CLASS DEFINITION cFont
}/// END NAMESPACE DEFINITION TextTypeEngine }/// END NAMESPACE DEFINITION TextTypeEngine
#endif/// END IFNDEF _CFONT_HPP_ #endif/// END IFNDEF _CFONT_HPP_
@@ -76,6 +76,7 @@ void cText::setSize( const unsigned long int size /*= 8*/ )
m_size = size; m_size = size;
if ((mpp_font != nullptr) && ((*mpp_font) != nullptr)) if ((mpp_font != nullptr) && ((*mpp_font) != nullptr))
(*mpp_font)->setSize(size); (*mpp_font)->setSize(size);
Text();
} }
} }
@@ -157,6 +158,8 @@ const cText::eRender& cText::getRender() const
/// private /// private
void cText::Text() void cText::Text()
{ {
/// if we have a font use SDL2_ttf to render the text.
/// else use SDL2_gfx to render text and use ZoomIn if it's size is larger then 8.
if((mpp_font != nullptr) && (*mpp_font != nullptr)) { if((mpp_font != nullptr) && (*mpp_font != nullptr)) {
SDL_Surface* sur = nullptr; SDL_Surface* sur = nullptr;
switch (m_render) switch (m_render)
@@ -176,39 +179,19 @@ void cText::Text()
setImage(sur); setImage(sur);
} else { } else {
SDL_Rect pos = { 0, 0, 0, 0 }; SDL_Rect pos = { 0, 0, 0, 0 };
//m_size == 25; SDL_Texture* texture = cGFX::Inst().StringTexture(m_text, pos, m_colour);
SDL_Texture* texture = cRenderer::Inst().NewTexture(8 * m_text.length(), 8, false, SDL_TEXTUREACCESS_TARGET);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
//int t = SDL_SetTextureColorMod(texture, 0, 255, 0);
// 376840196
//t = SDL_SetTextureAlphaMod(texture, 0);
//SDL_fill
//cRenderer::Inst().SetRenderTarget(texture);
//SDL_Colour col = { 0, 255, 255, 255};
//SDL_Rect re= { 0, 0, 100, 100};
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
//cRenderer::Inst().RenderDrawColor(col);
//cRenderer::Inst().RenderDrawRect(re, texture);
//cGFX::Inst().RoundedRectangle(pos, 4, col, texture);
//cRenderer::Inst().Render( texture, nullptr, nullptr);
//SDL_RenderCopy(cRenderer::Inst().getRenderer(), texture, nullptr, nullptr);
//cRenderer::Inst().Render(texture, nullptr, nullptr);
//cRenderer::Inst().ResetRenderTarget();
if (texture != nullptr) { if (texture != nullptr) {
if (m_size > 8) {
//cGFX::Inst().StringDefault(m_text, pos, m_colour); SDL_Texture* newTexture = cRenderer::Inst().NewTexture(((m_size / 4) * m_text.length()), m_size);
cGFX::Inst().StringDefault(m_text, pos, m_colour, texture);
//cGFX::Inst().ZoomIn(texture, m_size * m_text.length(), m_size, SMOOTHING_ON); double x = ((m_size / 4 ) * m_text.length()) / 8;
setImage(texture); double y = m_size / 8;
setImage(cGFX::Inst().ZoomIn(texture, x, y, SMOOTHING_ON));
SDL_DestroyTexture(texture);
}
else
setImage(texture);
} }
} }
} }
@@ -81,10 +81,11 @@ namespace TextTypeEngine {
void Text(); void Text();
private: private:
/// Variables
TextTypeEngine::cFont** mpp_font;/// = nullptr TextTypeEngine::cFont** mpp_font;/// = nullptr
cString m_text;/// = "" cString m_text;/// = ""
unsigned long int m_size;// = 16 unsigned long int m_size;/// = 16
SDL_Colour m_colour;/// = nullptr SDL_Colour m_colour;/// = nullptr
eRender m_render;/// = Solid eRender m_render;/// = Solid
};/// END CLASS DEFINITION cText };/// END CLASS DEFINITION cText
@@ -34,6 +34,7 @@ namespace TextTypeEngine {
const bool IsInit() const; const bool IsInit() const;
private: private:
/// Variables
static cTextType* sp_inst;/// = nullptr static cTextType* sp_inst;/// = nullptr
};/// END CLASS DEFINITION cTextType };/// END CLASS DEFINITION cTextType
}/// END NAMESPACE DEFINITION TextTypeEngine }/// END NAMESPACE DEFINITION TextTypeEngine
@@ -75,9 +75,9 @@ namespace UtilityEngine {
operator std::string () const; /// c++ string class operator std::string () const; /// c++ string class
private: private:
/// Variables
char* mp_str = nullptr; char* mp_str = nullptr;
size_t m_len = 0; size_t m_len = 0;
};/// END CLASS DEFINITION cString };/// END CLASS DEFINITION cString
}/// END NAMESPACE DEFINITION UtilityEngine }/// END NAMESPACE DEFINITION UtilityEngine
/// function overloads /// function overloads
@@ -46,7 +46,7 @@ namespace UtilityEngine {
static cUtility& Inst(); static cUtility& Inst();
static void Delete(); static void Delete();
void Message( const cString& msg, const cString& funcName = "", const eTypeSDL typeSDL = eTypeSDL::NONE ) const; void Message( const cString& msg, const cString& debugInfo = "", const eTypeSDL typeSDL = eTypeSDL::NONE ) const;
void PrintVersion( const eTypeSDL typeSDL = eTypeSDL::ALL ) const; void PrintVersion( const eTypeSDL typeSDL = eTypeSDL::ALL ) const;
@@ -83,7 +83,7 @@ namespace VideoEngine {
private: private:
/// Variables /// Variables
SDL_Texture* mp_texture;/// = nullptr SDL_Texture* mp_texture;/// = nullptr
SDL_Surface* mp_surface;// = nullptr SDL_Surface* mp_surface;/// = nullptr
bool m_transparent;/// = false bool m_transparent;/// = false
@@ -47,7 +47,6 @@ const bool cRenderer::Setup()
mp_renderer = cVideo::Inst().CreateRender(); mp_renderer = cVideo::Inst().CreateRender();
SDL_Surface* surface = SDL_GetWindowSurface(cVideo::Inst().getWindow()); SDL_Surface* surface = SDL_GetWindowSurface(cVideo::Inst().getWindow());
mp_rendererSoftware = SDL_CreateSoftwareRenderer(surface); mp_rendererSoftware = SDL_CreateSoftwareRenderer(surface);
//mp_rendererCopy = cVideo::Inst().CreateRender();
if (mp_renderer != nullptr) if (mp_renderer != nullptr)
rtn = true; rtn = true;
} }
@@ -169,13 +168,13 @@ SDL_Surface* cRenderer::TextureToSurface( SDL_Texture* texture )
SDL_Rect rec = { 0, 0, w, h }; SDL_Rect rec = { 0, 0, w, h };
SDL_Texture* tmp_texture = NewTexture(w, h, true); // Create a new texture with Software Renderer SetRenderTarget(texture);
CopyTexture(texture, tmp_texture, true); // Copy old texture to the Software Renderer Texture renderer
if (SDL_RenderReadPixels(mp_renderer, nullptr, SDL_PIXELFORMAT_RGBA32, rtn->pixels, rtn->pitch) < 0)
cUtility::Inst().Message("Unable to Read Texture's Pixels. SDL_RenderReadPixels():", __AT__, cUtility::eTypeSDL::SDL);
ResetRenderTarget();
Render(tmp_texture, nullptr, mp_rendererSoftware, &rec); // Render to the mp_rendererSoftware
SDL_RenderReadPixels(mp_rendererSoftware, nullptr, SDL_PIXELFORMAT_RGBA32, rtn->pixels, rtn->pitch);
return rtn; return rtn;
} }
@@ -266,7 +265,6 @@ const bool cRenderer::AreEqual( SDL_Surface& one, SDL_Surface& two )
if (SDL_MUSTLOCK(&two) > 0) if (SDL_MUSTLOCK(&two) > 0)
SDL_UnlockSurface(&two); SDL_UnlockSurface(&two);
return rtn; return rtn;
} }
@@ -40,11 +40,16 @@ namespace VideoEngine {
void RenderDrawColor( const SDL_Colour& colour ); void RenderDrawColor( const SDL_Colour& colour );
void RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst = nullptr ); void RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst = nullptr );
/* Takes a screen shot by copying the pixels from the Renderer to a new SDL_Surface and Calls SaveSurface(). */
void ScreenShot(const cString& filename, const cString& dir = ""); void ScreenShot(const cString& filename, const cString& dir = "");
/* Saves the SDL_Surface to the given file name and directory */
void SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir = "" ); void SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir = "" );
/* Saves the SDL_Texture to the given file name and directory */
void SaveTexture( SDL_Texture* texture, const cString& fileName, const cString& dir = "" ); void SaveTexture( SDL_Texture* texture, const cString& fileName, const cString& dir = "" );
/* Give it a SDL_Surface and it returns a SDL_Texture */
SDL_Texture* SurfaceToTexture( SDL_Surface* surface ); SDL_Texture* SurfaceToTexture( SDL_Surface* surface );
/* Give it a SDL_Texture and it returns and SDL_Surface */
SDL_Surface* TextureToSurface( SDL_Texture* texture ); SDL_Surface* TextureToSurface( SDL_Texture* texture );
void CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software = false ); void CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software = false );
@@ -54,6 +59,7 @@ namespace VideoEngine {
SDL_Surface* NewSurface( long int width = -1, long int height = -1 ) const; SDL_Surface* NewSurface( long int width = -1, long int height = -1 ) const;
SDL_Texture* NewTexture( long int width = -1, long int height = -1, const bool copyRenderer = false, const unsigned long int access = SDL_TEXTUREACCESS_TARGET ) const; SDL_Texture* NewTexture( long int width = -1, long int height = -1, const bool copyRenderer = false, const unsigned long int access = SDL_TEXTUREACCESS_TARGET ) const;
/* Give it two SDL_Surface you wish to compare returns true if the pixels are the same. */
const bool AreEqual( SDL_Surface& one, SDL_Surface& two ); const bool AreEqual( SDL_Surface& one, SDL_Surface& two );
void SetRenderTarget( SDL_Renderer* renderer, SDL_Texture* target = nullptr ); void SetRenderTarget( SDL_Renderer* renderer, SDL_Texture* target = nullptr );
@@ -67,6 +73,7 @@ namespace VideoEngine {
SDL_Renderer* getRendererCopy(); SDL_Renderer* getRendererCopy();
private: private:
/// Variables
SDL_Renderer* mp_renderer; SDL_Renderer* mp_renderer;
SDL_Renderer* mp_rendererSoftware; SDL_Renderer* mp_rendererSoftware;
@@ -124,6 +124,17 @@ void cSprite::AddPosY( const signed long int y )
m_position.y += Sint16(y); m_position.y += Sint16(y);
} }
void cSprite::AddPosXPosY( const signed long int x, const signed long int y )
{
AddPosX(x);
AddPosY(y);
}
void VideoEngine::cSprite::AddPosXPosY( const MathEngine::iVector2& addPos /*= MathEngine::iVector2(0, 0)*/ )
{
AddPosXPosY(addPos.x, addPos.y);
}
void cSprite::SaveImage( const cString& fileName, const cString& dir /*= ""*/ ) void cSprite::SaveImage( const cString& fileName, const cString& dir /*= ""*/ )
{ {
if (mpp_image != nullptr && *mpp_image != nullptr) { if (mpp_image != nullptr && *mpp_image != nullptr) {
@@ -44,9 +44,16 @@ namespace VideoEngine {
/* Draws the sprite to the video buffer with out positioning it */ /* Draws the sprite to the video buffer with out positioning it */
void DefaltDraw(); void DefaltDraw();
/* Adds X to the position of the sprite */
void AddPosX( const signed long int x ); void AddPosX( const signed long int x );
/* Adds Y to the position of the sprite */
void AddPosY( const signed long int y ); void AddPosY( const signed long int y );
/* Adds X and Y to the position of the sprite */
void AddPosXPosY( const signed long int x, const signed long int y );
/* Adds X and Y to the Position of the sprite via iVector2 */
void AddPosXPosY( const MathEngine::iVector2& addPos = MathEngine::iVector2(0, 0) );
/* Saves the Image to the given file name and directory via cRenderer's SaveTextrue()*/
void SaveImage( const cString& fileName, const cString& dir = "" ); void SaveImage( const cString& fileName, const cString& dir = "" );
/// Sets /// Sets
@@ -122,18 +122,18 @@ namespace VideoEngine {
static cVideo* sp_inst;/// = nullptr static cVideo* sp_inst;/// = nullptr
/*SDL interprets each pixel as a 32-bit number, so our masks must depend /* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */ on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned long int m_rmask;// = 0xff000000; const unsigned long int m_rmask;/// = 0xff000000;
const unsigned long int m_gmask;// = 0x00ff0000; const unsigned long int m_gmask;/// = 0x00ff0000;
const unsigned long int m_bmask;// = 0x0000ff00; const unsigned long int m_bmask;/// = 0x0000ff00;
const unsigned long int m_amask;// = 0x000000ff; const unsigned long int m_amask;/// = 0x000000ff;
#else #else
const unsigned long int m_rmask;// = 0x000000ff; const unsigned long int m_rmask;/// = 0x000000ff;
const unsigned long int m_gmask;// = 0x0000ff00; const unsigned long int m_gmask;/// = 0x0000ff00;
const unsigned long int m_bmask;// = 0x00ff0000; const unsigned long int m_bmask;/// = 0x00ff0000;
const unsigned long int m_amask;// = 0xff000000; const unsigned long int m_amask;/// = 0xff000000;
#endif #endif
};/// END CLASS DEFINITION cVideo };/// END CLASS DEFINITION cVideo
}/// END NAMESPACE DEFINITION VideoEngine }/// END NAMESPACE DEFINITION VideoEngine
@@ -3,4 +3,4 @@
void EventEngineTest(); void EventEngineTest();
#endif ///__EVENTENGINETEST__ #endif /// __EVENTENGINETEST__
@@ -0,0 +1,98 @@
#include "CollisionTest.hpp"
#include "../UTest/UTest.hpp"
/*** TrooperEngine DLL Header Files ***/
#include "TrooperEngine.hpp"
using MathEngine::cCollision;
void CollisionTest()
{
/// cCollision
printf("\nTesting cCollision -----\n\n");
UTest u("cCollision");
SDL_Rect a = { 50, 50, 50, 50 };
SDL_Rect bLeftTouch = { 0, 50, 50, 50 };
SDL_Rect bRightTouch = { 100, 50, 50, 50 };
SDL_Rect bTopTouch = { 50, 0, 50, 50 };
SDL_Rect bBottomTouch = { 50, 100, 50, 50 };
SDL_Rect bxywhTouch = { 1, 1, 49, 49 };
SDL_Rect bxnotTouch = { 101, 101, 50, 50 };
cString boundingbox = "BoundingBox(SDL_Rect a, SDL_Rect b) Check two SDL_Rect ";
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(a, a));
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(a, bLeftTouch));
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(a, bRightTouch));
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(a, bTopTouch));
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(a, bBottomTouch));
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(a, bxywhTouch));
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(a, bxnotTouch)));
//////////////////////////////////////////////////////////////////////////
/// Vector4
//////////////////////////////////////////////////////////////////////////
MathEngine::Vector4 Va = { 50.0, 50.0, 50.0, 50.0 };
MathEngine::Vector4 VbLeftTouch = { 0.0, 50.0, 50.0, 50.0 };
MathEngine::Vector4 VbRightTouch = { 100.0, 50.0, 50.0, 50.0 };
MathEngine::Vector4 VbTopTouch = { 50.0, 0.0, 50.0, 50.0 };
MathEngine::Vector4 VbBottomTouch = { 50.0, 100.0, 50.0, 50.0 };
MathEngine::Vector4 VbxywhTouch = { 1.0, 1.0, 49.0, 49.0 };
MathEngine::Vector4 VbxnotTouch = { 101.0, 101.0, 50.0, 50.0 };
boundingbox = "BoundingBox( const Vector4& a, const Vector4& b ) Check two Vector4 ";
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(Va, Va));
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(Va, VbLeftTouch));
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(Va, VbRightTouch));
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(Va, VbTopTouch));
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(Va, VbBottomTouch));
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(Va, VbxywhTouch));
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(Va, VbxnotTouch)));
//////////////////////////////////////////////////////////////////////////
/// iVector4
//////////////////////////////////////////////////////////////////////////
MathEngine::iVector4 iVa = { 50, 50, 50, 50 };
MathEngine::iVector4 iVbLeftTouch = { 0, 50, 50, 50 };
MathEngine::iVector4 iVbRightTouch = { 100, 50, 50, 50 };
MathEngine::iVector4 iVbTopTouch = { 50, 0, 50, 50 };
MathEngine::iVector4 iVbBottomTouch = { 50, 100, 50, 50 };
MathEngine::iVector4 iVbxywhTouch = { 1, 1, 49, 49 };
MathEngine::iVector4 iVbxnotTouch = { 101, 101, 50, 50 };
boundingbox = "BoundingBox( const iVector4& a, const iVector4& b ) Check two iVector4 ";
u.test(boundingbox + "that overlap, should return true.", cCollision::BoundingBox(iVa, iVa));
u.test(boundingbox + "that overlap on the left side only, should return true.", cCollision::BoundingBox(iVa, iVbLeftTouch));
u.test(boundingbox + "that overlap on the right side only, should return true.", cCollision::BoundingBox(iVa, iVbRightTouch));
u.test(boundingbox + "that overlap on the Top side only, should return true.", cCollision::BoundingBox(iVa, iVbTopTouch));
u.test(boundingbox + "that overlap on the Bottom side only, should return true.", cCollision::BoundingBox(iVa, iVbBottomTouch));
u.test(boundingbox + "one is inside the other, should return true.", cCollision::BoundingBox(iVa, iVbxywhTouch));
u.test(boundingbox + "that don't overlap, should return false.", !(cCollision::BoundingBox(iVa, iVbxnotTouch)));
u.report();
}
@@ -0,0 +1,6 @@
#ifndef __COLLISIONTEST__
#define __COLLISIONTEST__
void CollisionTest();
#endif /// __COLLISIONTEST__
@@ -0,0 +1,8 @@
#include "MathEngineTest.hpp"
#include "CollisionTest.hpp"
void MathEngineTest()
{
CollisionTest();
}
@@ -0,0 +1,6 @@
#ifndef __MATHENGINETEST__
#define __MATHENGINETEST__
void MathEngineTest();
#endif /// __MATHENGINETEST__
@@ -148,6 +148,8 @@
<ClCompile Include="EventEngineTest\EventEngineTest.cpp" /> <ClCompile Include="EventEngineTest\EventEngineTest.cpp" />
<ClCompile Include="GUIEngineTest\GUIXMLTest.cpp" /> <ClCompile Include="GUIEngineTest\GUIXMLTest.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="MathEngineTest\CollisionTest.cpp" />
<ClCompile Include="MathEngineTest\MathEngineTest.cpp" />
<ClCompile Include="UTest\UTest.cpp" /> <ClCompile Include="UTest\UTest.cpp" />
<ClCompile Include="UtilityEngineTest\StringTest.cpp" /> <ClCompile Include="UtilityEngineTest\StringTest.cpp" />
<ClCompile Include="UtilityEngineTest\UtilityEngineTest.cpp" /> <ClCompile Include="UtilityEngineTest\UtilityEngineTest.cpp" />
@@ -159,6 +161,8 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="EventEngineTest\EventEngineTest.hpp" /> <ClInclude Include="EventEngineTest\EventEngineTest.hpp" />
<ClInclude Include="GUIEngineTest\GUIXMLTest.hpp" /> <ClInclude Include="GUIEngineTest\GUIXMLTest.hpp" />
<ClInclude Include="MathEngineTest\CollisionTest.hpp" />
<ClInclude Include="MathEngineTest\MathEngineTest.hpp" />
<ClInclude Include="UTest\UTest.hpp" /> <ClInclude Include="UTest\UTest.hpp" />
<ClInclude Include="UtilityEngineTest\StringTest.hpp" /> <ClInclude Include="UtilityEngineTest\StringTest.hpp" />
<ClInclude Include="UtilityEngineTest\UtilityEngineTest.hpp" /> <ClInclude Include="UtilityEngineTest\UtilityEngineTest.hpp" />
@@ -19,6 +19,9 @@
<Filter Include="EventEngineTest"> <Filter Include="EventEngineTest">
<UniqueIdentifier>{30bb6c80-fc2a-4954-bf14-10c6dc5aceec}</UniqueIdentifier> <UniqueIdentifier>{30bb6c80-fc2a-4954-bf14-10c6dc5aceec}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="MathEngineTest">
<UniqueIdentifier>{846ddb6a-bcb4-4e29-9be7-e3c249de1213}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="UTest\UTest.hpp"> <ClInclude Include="UTest\UTest.hpp">
@@ -48,6 +51,12 @@
<ClInclude Include="UtilityEngineTest\UtilityEngineTest.hpp"> <ClInclude Include="UtilityEngineTest\UtilityEngineTest.hpp">
<Filter>UtitlityEngineTest</Filter> <Filter>UtitlityEngineTest</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="MathEngineTest\CollisionTest.hpp">
<Filter>MathEngineTest</Filter>
</ClInclude>
<ClInclude Include="MathEngineTest\MathEngineTest.hpp">
<Filter>MathEngineTest</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="UTest\UTest.cpp"> <ClCompile Include="UTest\UTest.cpp">
@@ -78,6 +87,12 @@
<ClCompile Include="UtilityEngineTest\UtilityEngineTest.cpp"> <ClCompile Include="UtilityEngineTest\UtilityEngineTest.cpp">
<Filter>UtitlityEngineTest</Filter> <Filter>UtitlityEngineTest</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MathEngineTest\CollisionTest.cpp">
<Filter>MathEngineTest</Filter>
</ClCompile>
<ClCompile Include="MathEngineTest\MathEngineTest.cpp">
<Filter>MathEngineTest</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Xml Include="xml\GUI.xml"> <Xml Include="xml\GUI.xml">
+9 -9
View File
@@ -28,9 +28,14 @@ see license.txt for details
/*** Utility Engine Test ***/ /*** Utility Engine Test ***/
#include "UtilityEngineTest/UtilityEngineTest.hpp" #include "UtilityEngineTest/UtilityEngineTest.hpp"
/*** Math Engine Test ***/
#include "MathEngineTest/MathEngineTest.hpp"
/*** GUI Engine Test ***/ /*** GUI Engine Test ***/
#include "GUIEngineTest/GUIXMLTest.hpp" #include "GUIEngineTest/GUIXMLTest.hpp"
#include <string>
using UtilityEngine::cString; using UtilityEngine::cString;
void CleanUp() void CleanUp()
@@ -43,19 +48,16 @@ int main(int argc, char *argv[])
argc, argv; argc, argv;
printf(cString("TrooperEngine V") + TrooperEngineCore::cTrooperEngineCore::Version() + "\n"); printf(cString("TrooperEngine V") + TrooperEngineCore::cTrooperEngineCore::Version() + "\n");
VideoEngineTest(); VideoEngineTest();
UtilityEngineTest(); UtilityEngineTest();
MathEngineTest();
GUIXMLTest(); //GUIXMLTest();
//ImageTest(); //ImageTest();
UTest::OverAllReport(); UTest::OverAllReport();
SDL_Event event; SDL_Event event;
@@ -90,7 +92,5 @@ int main(int argc, char *argv[])
CleanUp(); CleanUp();
//system("pause");
return 0; return 0;
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

+1 -1
View File
@@ -4,7 +4,7 @@
<Layout> <Layout>
<!--<Include dir ="xml/" filename="include.xml"/>--> <!--<Include dir ="xml/" filename="include.xml"/>-->
<Sizer /> <Sizer />
<Label>Sizer</Label> <Label fontsize="16">Sizer</Label>
<Sizer /> <Sizer />
<Sizer /> <Sizer />
</Layout> </Layout>
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB