diff --git a/SDLPongCPP/Main/main.cpp b/SDLPongCPP/Main/main.cpp index 6b56716..62281a3 100644 --- a/SDLPongCPP/Main/main.cpp +++ b/SDLPongCPP/Main/main.cpp @@ -5,8 +5,8 @@ Date Started: August 24, 2009 Date End: Webpage: http://www.richardallenonline.com - IDE: Visual Studio 2010 - Compiler: C\C++ 2010 + IDE: Visual Studio 2017 + Compiler: C\C++ 2017 Langage: C++ License: GNU GENERAL PUBLIC LICENSE Version 2 see license.txt for details diff --git a/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.cpp b/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.cpp index 16c0434..fd44a4a 100644 --- a/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.cpp +++ b/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.cpp @@ -98,12 +98,12 @@ void cSound::setLoops( const long int loops /*= -1*/ ) } ///Gets -const cString cSound::getDir() const +const cString& cSound::getDir() const { return m_dir; } -const cString cSound::getFileName() const +const cString& cSound::getFileName() const { return m_fileName; } diff --git a/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.hpp b/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.hpp index b68f632..3a36247 100644 --- a/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.hpp +++ b/TrooperEngineDLL/TrooperEngine/AudioEngine/cSound.hpp @@ -53,9 +53,9 @@ namespace AudioEngine { ///Gets /* Gets the directory of the sound */ - const cString getDir() const; + const cString& getDir() const; /* Gets the file name of the sound */ - const cString getFileName() const; + const cString& getFileName() const; /* Gets the Volume of the sound */ const unsigned char getVolume() const; /* Gets the Distance of the sound */ diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.cpp index 79d0983..7e88318 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.cpp @@ -2,7 +2,7 @@ using namespace GUIHelpers; -const RGBA GUIHelpers::StringtoRGBA( const cString& colour ) +const RGBA& GUIHelpers::StringtoRGBA( const cString& colour ) { RGBA rtn = DEFAULT; cString check = colour.upper(); diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.hpp index 4586251..0c899f3 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/GUIUtility.hpp @@ -39,9 +39,7 @@ namespace GUIHelpers { static const RGBA ROSE = { 255, 0, 128, 255 }; - const RGBA StringtoRGBA(const cString& colour); - - + const RGBA& StringtoRGBA(const cString& colour); }/// END NAMESPACE DEFINITION GUIHelpers #endif/// END IFNDEF _GUIUTILITY_HPP_ diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.cpp index e90a1c1..007404c 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.cpp @@ -83,9 +83,9 @@ void cXMLoader::GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* p tmp->Resize(); } -const cString cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const +const cString& cXMLoader::GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const { - cString rtn = ""; + cString rtn; const char* str = element.Attribute(attribute.c_str()); if ((str == nullptr) && (m_debugXML == true)) cUtility::Inst().Message("Error no attribute: " + attribute + " found in tag <" + element.Value() + ">"); @@ -211,18 +211,17 @@ GUIEngine::cBoxSizer* cXMLoader::BoxSizerBuild(const tinyxml2::XMLElement& eleme return rtn; } -const cString cXMLoader::getDir(const tinyxml2::XMLElement& element) const +const cString& cXMLoader::getDir(const tinyxml2::XMLElement& element) const { - cString rtn = GetAttribute(element, "dir"); - return rtn; + return GetAttribute(element, "dir"); } -const cString cXMLoader::getFileName(const tinyxml2::XMLElement& element) const +const cString& cXMLoader::getFileName(const tinyxml2::XMLElement& element) const { - cString rtn = GetAttribute(element, "filename"); - return rtn; + return GetAttribute(element, "filename"); } + const unsigned long int cXMLoader::getDebug( const tinyxml2::XMLElement& element ) const { unsigned long int rtn = 99; @@ -316,7 +315,7 @@ const GUIHelpers::eLayout cXMLoader::getLayout( const tinyxml2::XMLElement& elem return rtn; } -const GUIHelpers::Position cXMLoader::getPosition( const tinyxml2::XMLElement& element ) const +const GUIHelpers::Position& cXMLoader::getPosition( const tinyxml2::XMLElement& element ) const { GUIHelpers::Position rtn = { -1, -1 }; @@ -338,7 +337,7 @@ const GUIHelpers::Position cXMLoader::getPosition( const tinyxml2::XMLElement& e return rtn; } -const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element ) const +const GUIHelpers::Size& cXMLoader::getSize( const tinyxml2::XMLElement& element ) const { GUIHelpers::Size rtn = { -1, -1 }; @@ -360,7 +359,7 @@ const GUIHelpers::Size cXMLoader::getSize( const tinyxml2::XMLElement& element ) return rtn; } -const GUIHelpers::Padding cXMLoader::getPadding( const tinyxml2::XMLElement& element ) const +const GUIHelpers::Padding& cXMLoader::getPadding( const tinyxml2::XMLElement& element ) const { GUIHelpers::Padding rtn = { -1, -1, -1, -1 }; @@ -386,12 +385,12 @@ const GUIHelpers::Padding cXMLoader::getPadding( const tinyxml2::XMLElement& ele return rtn; } -const cString cXMLoader::getText( const tinyxml2::XMLElement& element ) const +const cString& cXMLoader::getText( const tinyxml2::XMLElement& element ) const { return GetAttribute(element, "text"); } -const GUIHelpers::RGBA cXMLoader::getColour( const tinyxml2::XMLElement& element ) const +const GUIHelpers::RGBA& cXMLoader::getColour( const tinyxml2::XMLElement& element ) const { GUIHelpers::RGBA rtn = GUIHelpers::DEFAULT; cString str = GetAttribute(element, "colour"); diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.hpp index 82ca75f..0b931ff 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/GUIHelpers/cXMLoader.hpp @@ -31,7 +31,7 @@ namespace GUIHelpers { private: void GetElement( tinyxml2::XMLElement& element, GUIEngine::cWindow* parent = nullptr ) const; - const cString GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const; + const cString& GetAttribute( const tinyxml2::XMLElement& element, const cString& attribute ) const; void Include( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const; void GUISetup( const tinyxml2::XMLElement& element ) const; @@ -43,20 +43,20 @@ namespace GUIHelpers { GUIEngine::cLabel* LabelBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const; GUIEngine::cBoxSizer* BoxSizerBuild( const tinyxml2::XMLElement& element, GUIEngine::cWindow* parent ) const; - const cString getDir( const tinyxml2::XMLElement& element ) const; - const cString getFileName( const tinyxml2::XMLElement& element ) const; + const cString& getDir( const tinyxml2::XMLElement& element ) const; + const cString& getFileName( const tinyxml2::XMLElement& element ) const; const unsigned long int getDebug( const tinyxml2::XMLElement& element ) const; const bool cXMLoader::getDebugXML(const tinyxml2::XMLElement& element) const; const signed long int getID( const tinyxml2::XMLElement& element ) const; const GUIHelpers::eOrientation getOrientation( const tinyxml2::XMLElement& element ) const; const GUIHelpers::eAlign getAlign( const tinyxml2::XMLElement& element ) const; const GUIHelpers::eLayout getLayout( const tinyxml2::XMLElement& element ) const; - const GUIHelpers::Position getPosition( const tinyxml2::XMLElement& element ) const; - const GUIHelpers::Size getSize( const tinyxml2::XMLElement& element ) const; - const GUIHelpers::Padding getPadding( const tinyxml2::XMLElement& element ) const; - const cString getText( const tinyxml2::XMLElement& element ) const; + const GUIHelpers::Position& getPosition( const tinyxml2::XMLElement& element ) const; + const GUIHelpers::Size& getSize( const tinyxml2::XMLElement& element ) const; + const GUIHelpers::Padding& getPadding( const tinyxml2::XMLElement& element ) const; + const cString& getText( const tinyxml2::XMLElement& element ) const; - const GUIHelpers::RGBA getColour( const tinyxml2::XMLElement& element ) const; + const GUIHelpers::RGBA& getColour( const tinyxml2::XMLElement& element ) const; const signed long int getFontSize( const tinyxml2::XMLElement& element ) const; void LoadDefault() const; diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.cpp index ef71732..18173ba 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.cpp @@ -34,7 +34,7 @@ void cBoxSizer::Create( cWindow* parent, const signed int id, const GUIHelpers:: return GUIHelpers::eType::CBOXSIZER; } -/*virtual*/ const GUIHelpers::RGBA cBoxSizer::getDebugColour() const +/*virtual*/ const GUIHelpers::RGBA& cBoxSizer::getDebugColour() const { return GUIHelpers::CYAN; } \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.hpp index 182e1e4..0fbea59 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cBoxSizer.hpp @@ -37,7 +37,7 @@ namespace GUIEngine { const cString& name = sNAME ); virtual const GUIHelpers::eType getType() const; - virtual const GUIHelpers::RGBA getDebugColour() const; + virtual const GUIHelpers::RGBA& getDebugColour() const; private: private: };/// END CLASS DEFINITION cBoxSizer diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.cpp index a903919..15e6883 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.cpp @@ -102,7 +102,7 @@ const cString& cLabel::getText() const return GUIHelpers::eType::CLABEL; } -/*virtual*/ const GUIHelpers::RGBA cLabel::getDebugColour() const +/*virtual*/ const GUIHelpers::RGBA& cLabel::getDebugColour() const { return GUIHelpers::GREEN; } diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.hpp index d8e7445..7000b16 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLabel.hpp @@ -45,7 +45,7 @@ namespace GUIEngine { const TextTypeEngine::cFont* getFont() const; const cString& getText() const; virtual const GUIHelpers::eType getType() const; - virtual const GUIHelpers::RGBA getDebugColour() const; + virtual const GUIHelpers::RGBA& getDebugColour() const; //virtual void Resize(); diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.cpp index 58bd62b..34484cf 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.cpp @@ -43,7 +43,7 @@ cLayout::cLayout(cWindow* parent, const signed int id, const GUIHelpers::eOrient return GUIHelpers::eType::CLAYOUT; } -/*virtual*/ const GUIHelpers::RGBA cLayout::getDebugColour() const +/*virtual*/ const GUIHelpers::RGBA& cLayout::getDebugColour() const { return GUIHelpers::BLUE; } \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.hpp index e0f3e85..07dd738 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cLayout.hpp @@ -40,10 +40,9 @@ namespace GUIEngine { ///Set ///Get - virtual const GUIHelpers::eType getType() const; - virtual const GUIHelpers::RGBA getDebugColour() const; + virtual const GUIHelpers::RGBA& getDebugColour() const; private: GUIHelpers::eOrientation m_orientation; diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.cpp index 3676d7d..105fb25 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.cpp @@ -34,7 +34,7 @@ cPanel::cPanel( cWindow* parent /*= nullptr*/, const signed int id /*= -1*/, con return GUIHelpers::eType::CPANEL; } -/*virtual*/ const GUIHelpers::RGBA cPanel::getDebugColour() const +/*virtual*/ const GUIHelpers::RGBA& cPanel::getDebugColour() const { return GUIHelpers::RED; } \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.hpp index ce34587..4287193 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cPanel.hpp @@ -34,7 +34,7 @@ namespace GUIEngine { virtual const GUIHelpers::eType getType() const; - virtual const GUIHelpers::RGBA getDebugColour() const; + virtual const GUIHelpers::RGBA& getDebugColour() const; private: };/// END CLASS DEFINITION cPanel diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.cpp index 613b329..df2bab3 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.cpp @@ -41,12 +41,12 @@ void cTextButton::setTextSize(const unsigned long int size) } ///Gets -const cString cTextButton::getText() const +const cString& cTextButton::getText() const { return m_label.getText(); } -const GUIHelpers::RGBA cTextButton::getTextColour() +const GUIHelpers::RGBA& cTextButton::getTextColour() { return m_label.getFontColour(); } @@ -61,6 +61,7 @@ const unsigned long int cTextButton::getTextSize() return GUIHelpers::eType::CTEXTBUTTON; } +/// Private void CreateLabel() {} diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.hpp index 7e515b1..970cd2f 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cTextButton.hpp @@ -44,8 +44,8 @@ namespace GUIEngine { void setTextSize( const unsigned long int size ); ///Gets - const cString getText() const; - const GUIHelpers::RGBA getTextColour(); + const cString& getText() const; + const GUIHelpers::RGBA& getTextColour(); const unsigned long int getTextSize(); virtual const GUIHelpers::eType getType() const; diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.cpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.cpp index 50e14a9..4bc13b3 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.cpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.cpp @@ -449,7 +449,7 @@ cWindow* cWindow::getParent() } } -/*virtual*/ const GUIHelpers::RGBA cWindow::getDebugColour() const +/*virtual*/ const GUIHelpers::RGBA& cWindow::getDebugColour() const { return GUIHelpers::WHITE; } diff --git a/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.hpp b/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.hpp index 0b58fdf..436eadc 100644 --- a/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.hpp +++ b/TrooperEngineDLL/TrooperEngine/GUIEngine/cWindow.hpp @@ -97,7 +97,7 @@ namespace GUIEngine { virtual void RePos(); virtual void RebuildPos(); - virtual const GUIHelpers::RGBA getDebugColour() const; + virtual const GUIHelpers::RGBA& getDebugColour() const; /*protected:*/ std::vector& getChildren(); diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp index 68d78e7..8acc546 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.cpp @@ -7,35 +7,28 @@ using VideoEngine::cImage; using UtilityEngine::cUtility; -cImage::cImage( const cString& filename, const cString& dir /*= ""*/, const bool transparent /*= false*/, - const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/, +cImage::cImage( const bool transparent /*= false*/, const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/, const unsigned char translevel /*= 255*/, const bool isSurface /*= false*/ ) -: mp_texture(nullptr), mp_surface(nullptr), m_dir(dir), m_fileName(filename), m_transparent(transparent), +: mp_texture(nullptr), mp_surface(nullptr), m_transparent(transparent), m_transRed(red), m_transBlue(blue), m_transGreen(green), m_transLevel(translevel), m_isSurface(isSurface) -{ - if (m_fileName != (char*)"") - LoadImage(); - if (mp_texture != nullptr) - TransparentSetup(); -} +{} cImage::cImage( SDL_Surface* surface ) -: mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false), +: mp_texture(nullptr), mp_surface(nullptr), m_transparent(false), m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255) { setImage(surface); } cImage::cImage( SDL_Texture* texture ) - : mp_texture(nullptr), mp_surface(nullptr), m_dir(""), m_fileName(""), m_transparent(false), + : mp_texture(nullptr), mp_surface(nullptr), m_transparent(false), m_transRed(0), m_transBlue(0), m_transGreen(255), m_transLevel(255) { setImage(texture); } cImage::cImage( const cImage& copy, const bool surfaceCopy /*= true*/) -: mp_texture(nullptr), mp_surface(nullptr), m_dir(copy.getDir()), -m_fileName(copy.getFileName()), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()), +: mp_texture(nullptr), mp_surface(nullptr), m_transparent(copy.getTransparent()), m_transRed(copy.getRedTrans()), m_transBlue(copy.getBlueTrans()), m_transGreen(copy.getGreenTrans()), m_transLevel(copy.getLevelTrans()) { if (surfaceCopy == true) @@ -78,23 +71,6 @@ const cImage* cImage::NewImage( SDL_Rect& area ) const } ///Sets -void cImage::setDir( const cString& dir ) -{ - m_dir = dir; -} - -void cImage::setFileName( const cString& filename ) -{ - m_fileName = filename; - LoadImage(); -} - -void cImage::setFileNameandDir( const cString& filename, const cString& dir /*= ""*/ ) -{ - setDir(dir); - setFileName(filename); -} - void cImage::setTransparent( const bool transparent /*= true*/ ) { m_transparent = transparent; @@ -117,8 +93,17 @@ void cImage::setLevelTrans( const unsigned char translevel /*= 255*/ ) ///Gets SDL_Surface* cImage::getSurface() const { - return mp_surface; - //return cRenderer::Inst().TextureToSurface(mp_texture); + SDL_Surface* rtn = nullptr; + if (m_isSurface == false) + rtn = cRenderer::Inst().TextureToSurface(mp_texture); + else + rtn = mp_surface; + return rtn; +} + +SDL_Texture* cImage::getTexture() const +{ + return mp_texture; } SDL_Texture* cImage::getImage() const @@ -165,16 +150,6 @@ void cImage::getWH( unsigned long int& w, unsigned long int& h ) const h = height; } -const cString cImage::getDir() const -{ - return m_dir; -} - -const cString cImage::getFileName() const -{ - return m_fileName; -} - const bool cImage::getTransparent() const { return m_transparent; @@ -217,9 +192,12 @@ void cImage::setImage( SDL_Surface* surface ) { UnloadImage(); - mp_texture = cRenderer::Inst().SurfaceToTexture(surface); - - SDL_FreeSurface(surface); + if (m_isSurface == false) { + mp_texture = cRenderer::Inst().SurfaceToTexture(surface); + SDL_FreeSurface(surface); + } + else + mp_surface = surface; } void cImage::setImage( SDL_Texture* texture ) @@ -232,46 +210,26 @@ void cImage::setImage( SDL_Texture* texture ) ///Functions void cImage::TransparentSetup() { - if( (m_transparent == true) && (mp_texture != nullptr) ) { + if (m_transparent == false) + return; + + if( mp_texture != nullptr ) { if ((SDL_SetTextureColorMod(mp_texture, m_transRed, m_transGreen, m_transBlue) | SDL_SetTextureAlphaMod(mp_texture, m_transLevel)) < 0) cUtility::Inst().Message("Unable to set Transparent. SDL_SetTextureColorMod:", __AT__, cUtility::eTypeSDL::SDL); } - //LoadImage(); -} - -void cImage::LoadImage() -{ - UnloadImage(); - - SDL_Texture* tempText = nullptr; - SDL_Surface* tempSurface = nullptr; - - if (m_fileName != "") - { - cString temp = m_dir + m_fileName; - - if (m_isSurface == false) { - if ((tempText = IMG_LoadTexture(cRenderer::Inst().getRenderer(), temp.c_str())) == nullptr) - cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE); - else - mp_texture = tempText; - } - else { - if ((tempSurface = IMG_Load(temp.c_str())) == nullptr) - cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_Load():", __AT__, cUtility::eTypeSDL::IMAGE); - else - mp_surface = tempSurface; - } - } + if ((m_isSurface == true) && (mp_surface != nullptr)) { + if ((SDL_SetSurfaceColorMod(mp_surface, m_transRed, m_transGreen, m_transBlue) | SDL_SetSurfaceAlphaMod(mp_surface, m_transLevel)) < 0) + cUtility::Inst().Message("Unable to set Transparent. SDL_SetSurfaceColorMod:", __AT__, cUtility::eTypeSDL::SDL); + } } void cImage::UnloadImage() { if (mp_texture != nullptr) - { SDL_DestroyTexture(mp_texture); - mp_texture = nullptr; - } -} - + if (mp_surface != nullptr) + SDL_FreeSurface(mp_surface); + mp_texture = nullptr; + mp_surface = nullptr; +} \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp index b4fadbe..fb6aedb 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImage.hpp @@ -17,8 +17,7 @@ namespace VideoEngine { class EXPORT_FROM_MYDLL cImage { public: - cImage( const cString& filename = "", const cString& dir = "", const bool transparent = false, - const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255, + cImage( const bool transparent = false, const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255, const unsigned char translevel = 255, const bool isSurface = false ); cImage( SDL_Surface* surface ); cImage( SDL_Texture* texture ); @@ -32,13 +31,6 @@ namespace VideoEngine { const cImage* NewImage( SDL_Rect& area ) const; ///Sets - /* Sets the Directory of the image */ - void setDir( const cString& dir ); - /* Sets the File Name of the image */ - void setFileName( const cString& filename ); - /* Sets the File Name and the Directory of the image */ - void setFileNameandDir( const cString& filename, const cString& dir = "" ); - /* Sets Transparent on if set to true */ void setTransparent( const bool transparent = true ); /* Sets the colour to be made transparent */ @@ -50,6 +42,8 @@ namespace VideoEngine { /* Gets a pointer to the SDL_Surface */ SDL_Surface* getSurface() const; /* Gets a pointer to the SDL_Texture */ + SDL_Texture* getTexture() const; + /* Gets a pointer to the SDL_Texture */ SDL_Texture* getImage() const; /* Gets the width of the image */ const unsigned long int getWidth() const; @@ -59,12 +53,7 @@ namespace VideoEngine { const SDL_Rect getWH() const; /* Gets the Width and Height of the image */ void getWH( unsigned long int& w, unsigned long int& h ) const; - - /* Gets the Directory of the image */ - const cString getDir() const; - /* Gets the File Name of the image */ - const cString getFileName() const; - + /* Gets return true if transparent on false if off */ const bool getTransparent() const; /* Gets return the colour to be made transparent */ @@ -89,20 +78,13 @@ namespace VideoEngine { private: ///Functions void TransparentSetup(); - virtual void LoadImage(); //cFont over rides this void UnloadImage(); private: ///Variables SDL_Texture* mp_texture;// = nullptr SDL_Surface* mp_surface;// = nullptr - - cString m_dir;// = "" - cString m_fileName;// = "" - //char m_dir[255]; - //char m_fileName[255]; - bool m_transparent;// = false unsigned char m_transRed;// = 0 diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.cpp new file mode 100644 index 0000000..7bc8cf9 --- /dev/null +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.cpp @@ -0,0 +1,78 @@ +#include "cImageFile.hpp" + +/*** Custom Header Files ***/ +#include "cRenderer.hpp" +#include "../UtilityEngine/cUtility.hpp" + +using VideoEngine::cImageFile; +using UtilityEngine::cUtility; + +cImageFile::cImageFile(const cString& filename, const cString& dir /*= ""*/, const bool transparent /*= false*/, + const unsigned char red /*= 0*/, const unsigned char blue /*= 0*/, const unsigned char green /*= 255*/, + const unsigned char translevel /*= 255*/, const bool isSurface /*= false*/) + : cImage(transparent, red, blue, green, translevel, isSurface), m_dir(dir), m_fileName(filename) +{ + if (m_fileName != (char*)"") + LoadImage(); +} + +cImageFile::cImageFile(const cImageFile& copy, const bool surfaceCopy /*= true*/) + : cImage(copy) +{} + +cImageFile::~cImageFile() +{} + +///Sets +void cImageFile::setDir(const cString& dir) +{ + m_dir = dir; +} + +void cImageFile::setFileName(const cString& filename) +{ + m_fileName = filename; + LoadImage(); +} + +void cImageFile::setFileNameandDir(const cString& filename, const cString& dir /*= ""*/) +{ + setDir(dir); + setFileName(filename); +} + +const cString& cImageFile::getDir() const +{ + return m_dir; +} + +const cString& cImageFile::getFileName() const +{ + return m_fileName; +} + +///private +///Functions +void cImageFile::LoadImage() +{ + SDL_Texture* tempText = nullptr; + SDL_Surface* tempSurface = nullptr; + + if (m_fileName != "") + { + cString temp = m_dir + m_fileName; + + if (this->getIsSurface() == false) { + if ((tempText = IMG_LoadTexture(cRenderer::Inst().getRenderer(), temp.c_str())) == nullptr) + cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_LoadTexture():", __AT__, cUtility::eTypeSDL::IMAGE); + else + this->setImage(tempText); + } + else { + if ((tempSurface = IMG_Load(temp.c_str())) == nullptr) + cUtility::Inst().Message("Unable to load necessary image file. " + temp + " IMG_Load():", __AT__, cUtility::eTypeSDL::IMAGE); + else + this->setImage(tempSurface); + } + } +} \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.hpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.hpp new file mode 100644 index 0000000..aac6161 --- /dev/null +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cImageFile.hpp @@ -0,0 +1,52 @@ +#ifndef _CIMAGEFILE_HPP_ +#define _CIMAGEFILE_HPP_ + +/*** SDL Header Files ***/ +#include +#include + +/*** DLL Header File ***/ +#include "dllExport.h" + +/*** Custom Header Files ***/ +#include "cImage.hpp" +#include "../UtilityEngine/cString.hpp" + +using UtilityEngine::cString; + +namespace VideoEngine { + class EXPORT_FROM_MYDLL cImageFile : public cImage + { + public: + cImageFile(const cString& filename = "", const cString& dir = "", const bool transparent = false, + const unsigned char red = 0, const unsigned char blue = 0, const unsigned char green = 255, + const unsigned char translevel = 255, const bool isSurface = false); + /* Copy constructor */ + cImageFile(const cImageFile& copy, const bool surfaceCopy = true); + ~cImageFile(); + + ///Sets + /* Sets the Directory of the image */ + void setDir(const cString& dir); + /* Sets the File Name of the image */ + void setFileName(const cString& filename); + /* Sets the File Name and the Directory of the image */ + void setFileNameandDir(const cString& filename, const cString& dir = ""); + + ///Gets + /* Gets the Directory of the image */ + const cString& getDir() const; + /* Gets the File Name of the image */ + const cString& getFileName() const; + + private: + ///Functions + void LoadImage(); + + private: + ///Variables + cString m_dir;// = "" + cString m_fileName;// = "" + };/// END CLASS DEFINITION cImageFile +}/// END NAMESPACE DEFINITION VideoEngine +#endif/// END IFNDEF _CIMAGEFILE_HPP_ \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp index 58f667c..053fdef 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.cpp @@ -12,6 +12,7 @@ using UtilityEngine::cUtility; //private: cRenderer::cRenderer() + : mp_renderer(nullptr), mp_rendererSoftware(nullptr) { Setup(); } @@ -42,7 +43,11 @@ const bool cRenderer::Setup() if (cVideo::Inst().IsInit() == false) cUtility::Inst().Message("Unable to setup until SDL_Video is initialized."); else { + CleanUp(); mp_renderer = cVideo::Inst().CreateRender(); + SDL_Surface* surface = SDL_GetWindowSurface(cVideo::Inst().getWindow()); + mp_rendererSoftware = SDL_CreateSoftwareRenderer(surface); + //mp_rendererCopy = cVideo::Inst().CreateRender(); if (mp_renderer != nullptr) rtn = true; } @@ -51,8 +56,13 @@ const bool cRenderer::Setup() void cRenderer::CleanUp() { - SDL_DestroyRenderer(mp_renderer); + if (mp_renderer != nullptr) + SDL_DestroyRenderer(mp_renderer); + if (mp_rendererSoftware != nullptr) + SDL_DestroyRenderer(mp_rendererSoftware); + mp_renderer = nullptr; + mp_rendererSoftware = nullptr; } void cRenderer::Render( SDL_Texture* texture, SDL_Rect* srcrect, SDL_Rect* dstrect ) @@ -111,24 +121,12 @@ void cRenderer::RenderDrawRect( const SDL_Rect& rect, SDL_Texture* dst /*= nullp void cRenderer::ScreenShot( const cString& filename, const cString& dir /*= ""*/ ) { - SDL_Surface* infoSurface = SDL_GetWindowSurface(VideoEngine::cVideo::Inst().getWindow()); - SDL_Surface* saveSurface = NewSurface(); - - if (infoSurface == nullptr) { - cUtility::Inst().Message("Failed to create info surface from window.\n", __AT__, cUtility::eTypeSDL::SDL); - } else { - if (SDL_RenderReadPixels(mp_renderer, &infoSurface->clip_rect, infoSurface->format->format, saveSurface->pixels, infoSurface->w * infoSurface->format->BytesPerPixel) != 0) - cUtility::Inst().Message("Failed to read pixel data from SDL_Renderer object.\n", __AT__, cUtility::eTypeSDL::SDL); - else - SaveSurface(saveSurface, filename, dir); - SDL_FreeSurface(infoSurface); - infoSurface = nullptr; - } - SDL_FreeSurface(saveSurface); - saveSurface = nullptr; + SDL_Surface *sshot = NewSurface(); + SDL_RenderReadPixels(getRenderer(), nullptr, SDL_PIXELFORMAT_RGBA32, sshot->pixels, sshot->pitch); + SaveSurface(sshot, filename, dir); + SDL_FreeSurface(sshot); } - void cRenderer::SaveSurface( SDL_Surface* surface, const cString& fileName, const cString& dir /*= ""*/ ) { cString temp = dir + fileName; @@ -169,57 +167,27 @@ SDL_Surface* cRenderer::TextureToSurface( SDL_Texture* texture ) rtn = NewSurface(w, h); - void* srcPixels = nullptr; - int srcPitch = 0; + SDL_Rect rec = { 0, 0, w, h }; + + SDL_Texture* tmp_texture = NewTexture(w, h, true); // Create a new texture with Software Renderer + CopyTexture(texture, tmp_texture, true); // Copy old texture to the Software Renderer Texture renderer + + Render(tmp_texture, nullptr, mp_rendererSoftware, &rec); // Render to the mp_rendererSoftware - //Lock texture for manipulation - if (SDL_LockTexture( texture, nullptr, &srcPixels, &srcPitch ) < 0) - cUtility::Inst().Message("Unable to lock texture. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL); - - if (SDL_LockSurface(rtn)) - cUtility::Inst().Message("Unable to lock surface rtn. SDL_LockSurface():", __AT__, cUtility::eTypeSDL::SDL); - - //Copy loaded/formatted surface pixels - memcpy( rtn->pixels, srcPixels, srcPitch * h ); - - //Unlock texture to update - SDL_UnlockSurface(rtn); - SDL_UnlockTexture( texture ); - - srcPixels = nullptr; - + SDL_RenderReadPixels(mp_rendererSoftware, nullptr, SDL_PIXELFORMAT_RGBA32, rtn->pixels, rtn->pitch); + return rtn; } -void cRenderer::CopyTexture( SDL_Texture* src, SDL_Texture* dst ) +void cRenderer::CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software /*= false*/ ) { - void* srcPixels = nullptr; - int srcPitch = 0; - - void* dstPixels = nullptr; - int dstPitch = 0; - - int height = 0; - - if (SDL_QueryTexture( src, nullptr, nullptr, nullptr, &height ) < 0) - cUtility::Inst().Message("Unable to query texture. SDL_QueryTexture():", __AT__, cUtility::eTypeSDL::SDL); - - //Lock texture for manipulation - if (SDL_LockTexture( src, nullptr, &srcPixels, &srcPitch ) < 0) - cUtility::Inst().Message("Unable to lock texture src. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL); - - if (SDL_LockTexture( dst, nullptr, &dstPixels, &dstPitch ) < 0) - cUtility::Inst().Message("Unable to lock texture dst. SDL_LockTexture():", __AT__, cUtility::eTypeSDL::SDL); - - //Copy loaded/formatted surface pixels - memcpy( dstPixels, srcPixels, srcPitch * height ); - - //Unlock texture to update - SDL_UnlockTexture( dst ); - SDL_UnlockTexture( src ); - srcPixels = nullptr; - dstPixels = nullptr; - + SDL_Renderer* render = mp_renderer; + if (software == true) + render = mp_rendererSoftware; + if (SDL_SetRenderTarget(render, dst) < 0) + cUtility::Inst().Message("Unable to set render target to dst. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL); + Render(src, nullptr, render, nullptr); + ResetRenderTarget(); } SDL_Surface* cRenderer::CopySurface( SDL_Surface* src ) @@ -242,19 +210,72 @@ SDL_Surface* cRenderer::NewSurface( long int width /*= -1*/, long int height /*= return rtn; } -SDL_Texture* cRenderer::NewTexture( long int width, long int height, const unsigned long int access /*= SDL_TEXTUREACCESS_TARGET*/ ) const +SDL_Texture* cRenderer::NewTexture( long int width, long int height, const bool copyRenderer /*= false*/, const unsigned long int access /*= SDL_TEXTUREACCESS_TARGET*/ ) const { if (width < 0) width = cVideo::Inst().getWidth(); if (height < 0) height = cVideo::Inst().getHeight(); - SDL_Texture* rtn = SDL_CreateTexture(mp_renderer, SDL_PIXELFORMAT_ABGR8888, access, width, height); + SDL_Renderer* renderer = nullptr; + if (copyRenderer == false) + renderer = mp_renderer; + else + renderer = mp_rendererSoftware; + + SDL_Texture* rtn = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888, access, width, height); if (rtn == nullptr) cUtility::Inst().Message("Unable to create texture. SDL_CreateTexture:", __AT__, cUtility::eTypeSDL::SDL); return rtn; } +const bool cRenderer::AreEqual(SDL_Surface& one, SDL_Surface& two) +{ + bool rtn = false; + + int x = 0; + int y = 0; + + if (SDL_MUSTLOCK(&one) > 0) + SDL_LockSurface(&one); + + if (SDL_MUSTLOCK(&two) > 0) + SDL_LockSurface(&two); + + if ((one.pitch == two.pitch) && (one.h == two.h)) { + unsigned char *one_pixels = (unsigned char *)one.pixels; + unsigned char *two_pixels = (unsigned char *)two.pixels; + + rtn = true; // we are equal so far.... + + for (x = 0; x < one.pitch; x++) { + for (y = 0; y < one.h; y++) { + if (one_pixels[y + x] != two_pixels[y + x]) { + rtn = false; + x = one.pitch + two.pitch + 1; // break out of the top for loop + y = one.h + two.h + 1; + break; // we found a pixel that is not equal no need to continue + } + } + } + } + + if (SDL_MUSTLOCK(&one) > 0) + SDL_UnlockSurface(&one); + + if (SDL_MUSTLOCK(&two) > 0) + SDL_UnlockSurface(&two); + + + return rtn; +} + +void cRenderer::SetRenderTarget(SDL_Renderer* renderer, SDL_Texture* target /*= nullptr*/) +{ + if (SDL_SetRenderTarget(renderer, target) < 0) + cUtility::Inst().Message("Unable to set render target to dst. SDL_SetRenderTarget():", __AT__, cUtility::eTypeSDL::SDL); +} + void cRenderer::SetRenderTarget( SDL_Texture* target /*= nullptr*/ ) { if (SDL_SetRenderTarget(mp_renderer, target) < 0) @@ -271,3 +292,8 @@ SDL_Renderer* cRenderer::getRenderer() { return mp_renderer; } + +SDL_Renderer* cRenderer::getRendererCopy() +{ + return mp_rendererSoftware; +} \ No newline at end of file diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.hpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.hpp index 31f1ca7..47d542a 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.hpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cRenderer.hpp @@ -47,23 +47,28 @@ namespace VideoEngine { SDL_Texture* SurfaceToTexture( SDL_Surface* surface ); SDL_Surface* TextureToSurface( SDL_Texture* texture ); - void CopyTexture( SDL_Texture* src, SDL_Texture* dst ); + void CopyTexture( SDL_Texture* src, SDL_Texture* dst, bool software = false); SDL_Surface* CopySurface( SDL_Surface* src ); SDL_Surface* NewSurface( long int width = -1, long int height = -1 ) const; - SDL_Texture* NewTexture( long int width = -1, long int height = -1, 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; - void SetRenderTarget( SDL_Texture* target = nullptr ); + const bool AreEqual(SDL_Surface& one, SDL_Surface& two); + + void SetRenderTarget(SDL_Renderer* renderer, SDL_Texture* target = nullptr); + void SetRenderTarget(SDL_Texture* target = nullptr); void ResetRenderTarget(); ///Sets ///Gets - SDL_Renderer* getRenderer(); + SDL_Renderer* getRenderer(); + SDL_Renderer* getRendererCopy(); private: SDL_Renderer* mp_renderer; + SDL_Renderer* mp_rendererSoftware; static cRenderer* sp_inst;// = nullptr };/// END CLASS DEFINITION cRenderer diff --git a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp index 2349dfc..a975143 100644 --- a/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp +++ b/TrooperEngineDLL/TrooperEngine/VideoEngine/cVideo.cpp @@ -67,7 +67,7 @@ const bool cVideo::Setup() CleanUp(); VideoSettings(); - mp_window = SDL_CreateWindow("Hello World!", 100, 100, m_width, m_height, SDL_WINDOW_SHOWN); + mp_window = SDL_CreateWindow("Hello World!", m_xPos, m_yPos, m_width, m_height, SDL_WINDOW_SHOWN); if (mp_window == nullptr) cUtility::Inst().Message("Unable to set Window. SDL_CreateWindow():", __AT__, cUtility::eTypeSDL::SDL); else diff --git a/TrooperEngineDLL/TrooperEngineDLL.vcxproj b/TrooperEngineDLL/TrooperEngineDLL.vcxproj index 176e1df..c7d8299 100644 --- a/TrooperEngineDLL/TrooperEngineDLL.vcxproj +++ b/TrooperEngineDLL/TrooperEngineDLL.vcxproj @@ -162,6 +162,7 @@ + @@ -212,6 +213,7 @@ + diff --git a/TrooperEngineDLL/TrooperEngineDLL.vcxproj.filters b/TrooperEngineDLL/TrooperEngineDLL.vcxproj.filters index d5f9026..70c4d83 100644 --- a/TrooperEngineDLL/TrooperEngineDLL.vcxproj.filters +++ b/TrooperEngineDLL/TrooperEngineDLL.vcxproj.filters @@ -55,6 +55,9 @@ {f6fc613b-8e1a-4df1-aee7-f37382d38981} + + {b13cf78d-bfda-4467-9cdc-79dcb63fd8a9} + @@ -180,9 +183,6 @@ TrooperEngine\VideoEngine - - TrooperEngine\TextTypeEngine - TrooperEngine\UtilityEngine @@ -213,6 +213,12 @@ TrooperEngine\EventEngine + + TrooperEngine\VideoEngine + + + TrooperEngine\TextTypeEngine\TextTypeHelpers + @@ -320,9 +326,6 @@ TrooperEngine\VideoEngine - - TrooperEngine\TextTypeEngine - TrooperEngine\GUIEngine\GUIHelpers @@ -359,5 +362,11 @@ TrooperEngine\EventEngine + + TrooperEngine\VideoEngine + + + TrooperEngine\TextTypeEngine\TextTypeHelpers + \ No newline at end of file diff --git a/TrooperEngineDLL/dllExportFiles/TrooperEngine.hpp b/TrooperEngineDLL/dllExportFiles/TrooperEngine.hpp index deafaa4..c7e3768 100644 --- a/TrooperEngineDLL/dllExportFiles/TrooperEngine.hpp +++ b/TrooperEngineDLL/dllExportFiles/TrooperEngine.hpp @@ -17,6 +17,7 @@ #include "../TrooperEngine/VideoEngine/cSprite.hpp" #include "../TrooperEngine/VideoEngine/cAnimatedSprite.hpp" #include "../TrooperEngine/VideoEngine/cImage.hpp" +#include "../TrooperEngine/VideoEngine/cImageFile.hpp" #include "../TrooperEngine/VideoEngine/cCamera.hpp" /*** AudioEngine Folder ***/ @@ -55,6 +56,9 @@ #include "../TrooperEngine/TextTypeEngine/cFont.hpp" #include "../TrooperEngine/TextTypeEngine/cText.hpp" +/*** TextTypeHelpers ***/ +#include "../TrooperEngine/TextTypeEngine/TextTypeHelpers/cFontHolder.hpp" + /*** EventEngine ***/ #include "../TrooperEngine/EventEngine/cEventControl.hpp" #include "../TrooperEngine/EventEngine/cEvent.hpp" diff --git a/TrooperEngineTest/ImageTestSaveRenderer.bmp b/TrooperEngineTest/ImageTestSaveRenderer.bmp new file mode 100644 index 0000000..35ead73 Binary files /dev/null and b/TrooperEngineTest/ImageTestSaveRenderer.bmp differ diff --git a/TrooperEngineTest/TrooperEngineTest.vcxproj b/TrooperEngineTest/TrooperEngineTest.vcxproj index 132b67b..009941c 100644 --- a/TrooperEngineTest/TrooperEngineTest.vcxproj +++ b/TrooperEngineTest/TrooperEngineTest.vcxproj @@ -150,8 +150,9 @@ - + + @@ -159,8 +160,9 @@ - + + diff --git a/TrooperEngineTest/TrooperEngineTest.vcxproj.filters b/TrooperEngineTest/TrooperEngineTest.vcxproj.filters index 6212f76..20b720c 100644 --- a/TrooperEngineTest/TrooperEngineTest.vcxproj.filters +++ b/TrooperEngineTest/TrooperEngineTest.vcxproj.filters @@ -39,7 +39,10 @@ VideoEngineTest - + + VideoEngineTest + + VideoEngineTest @@ -63,7 +66,10 @@ VideoEngineTest - + + VideoEngineTest + + VideoEngineTest diff --git a/TrooperEngineTest/UTest/UTest.cpp b/TrooperEngineTest/UTest/UTest.cpp index 4c9140a..bb67f1a 100644 --- a/TrooperEngineTest/UTest/UTest.cpp +++ b/TrooperEngineTest/UTest/UTest.cpp @@ -1,21 +1,27 @@ #include "UTest.hpp" -const /*static*/ char * UTest::sp_pstr = "pass"; -const /*static*/ char * UTest::sp_fstr = "fail"; +#include + +/*static*/ const char* UTest::sp_pstr = "pass"; +/*static*/ const char* UTest::sp_fstr = "fail"; /*static*/ unsigned long int UTest::s_pass = 0; /*static*/ unsigned long int UTest::s_fail = 0; -UTest::UTest( const char * tstr ) { +UTest::UTest( const char* tstr ) + : m_pass(0), m_fail(0) +{ init(tstr); } -void UTest::init( const char * tstr ) { +void UTest::init( const char* tstr ) +{ mp_tstr = tstr; m_pass = m_fail = 0; } -void UTest::test( const char * description, const int flag ) { +void UTest::test( const char* description, const int flag ) +{ const char * pf = nullptr; if (flag) { pf = sp_pstr; @@ -29,7 +35,8 @@ void UTest::test( const char * description, const int flag ) { printf("%s: %s -> %s\n", mp_tstr, description, pf); } -void UTest::report() const { +void UTest::report() const +{ printf("%s: pass: %ld, fail: %ld\n", mp_tstr, m_pass, m_fail); } diff --git a/TrooperEngineTest/UTest/UTest.hpp b/TrooperEngineTest/UTest/UTest.hpp index 1028280..eeea2d7 100644 --- a/TrooperEngineTest/UTest/UTest.hpp +++ b/TrooperEngineTest/UTest/UTest.hpp @@ -1,8 +1,6 @@ #ifndef __UTEST__ #define __UTEST__ -#include - #define __UTest_VERSION "1.0.0" class UTest { @@ -11,11 +9,11 @@ private: UTest operator = ( UTest & ); // no assignment operator UTest(){} public: - static const char * version() { return __UTest_VERSION; } + static const char* version() { return __UTest_VERSION; } - UTest( const char * ); - void init( const char * ); - void test( const char * description, const int flag ); + UTest( const char* tstr ); + void init( const char* tstr ); + void test( const char* description, const int flag ); void report() const; static void OverAllReport(); @@ -24,13 +22,13 @@ private: unsigned long int m_pass = 0; unsigned long int m_fail = 0; - const char * mp_tstr = nullptr; + const char* mp_tstr = nullptr; - const static char * sp_pstr; /*= "pass";*/ - const static char * sp_fstr; /*= "fail";*/ + static const char* sp_pstr; /*= "pass";*/ + static const char* sp_fstr; /*= "fail";*/ - static unsigned long int s_pass; - static unsigned long int s_fail; + static unsigned long int s_pass; //= 0 + static unsigned long int s_fail; //= 0 }; #endif // __UTEST__ diff --git a/TrooperEngineTest/VideoEngineTest/ImageFileTest.cpp b/TrooperEngineTest/VideoEngineTest/ImageFileTest.cpp new file mode 100644 index 0000000..166ef78 --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/ImageFileTest.cpp @@ -0,0 +1,31 @@ +#include "ImageFileTest.hpp" + +#include "../UTest/UTest.hpp" + +/*** TrooperEngine DLL Header Files ***/ +#include "TrooperEngine.hpp" + +using VideoEngine::cImageFile; + +using VideoEngine::cSprite; + +void ImageFileTest() +{ + // cImageFile + printf("\nTesting cImageFile -----\n\n"); + + UTest u("cImageFile"); + + cImageFile* image = new cImageFile("ImageTest.bmp"); + + //u.test() + + //image->SaveImage("ImageTestSaved.bmp"); + + //cSprite* sprite = new cSprite(&image); + + //sprite->Draw(); + + + u.report(); +} \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/ImageFileTest.hpp b/TrooperEngineTest/VideoEngineTest/ImageFileTest.hpp new file mode 100644 index 0000000..17bd142 --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/ImageFileTest.hpp @@ -0,0 +1,6 @@ +#ifndef __IMAGEFILETEST__ +#define __IMAGEFILETEST__ + +void ImageFileTest(); + +#endif // __IMAGEFILETEST__ diff --git a/TrooperEngineTest/VideoEngineTest/ImageTest.cpp b/TrooperEngineTest/VideoEngineTest/ImageTest.cpp deleted file mode 100644 index 1024cad..0000000 --- a/TrooperEngineTest/VideoEngineTest/ImageTest.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "ImageTest.hpp" - -#include "../UTest/UTest.hpp" - -/*** TrooperEngine DLL Header Files ***/ -#include "TrooperEngine.hpp" - -using VideoEngine::cImage; - -using VideoEngine::cSprite; - -void ImageTest() -{ - // cRenderer - printf("\nTesting cImage -----\n\n"); - - UTest u("cImage"); - - cImage* image = new cImage("ImageTest.bmp", "", false, 0, 0, 255, 255, true); - - image->SaveImage("ImageTestSaved.bmp"); - - cSprite* sprite = new cSprite(&image); - - sprite->Draw(); - - - u.report(); -} \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/ImageTest.hpp b/TrooperEngineTest/VideoEngineTest/ImageTest.hpp deleted file mode 100644 index f7c1ec5..0000000 --- a/TrooperEngineTest/VideoEngineTest/ImageTest.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __IMAGETEST__ -#define __IMAGETEST__ - -void ImageTest(); - -#endif // __IMAGETEST__ diff --git a/TrooperEngineTest/VideoEngineTest/RendererTest.cpp b/TrooperEngineTest/VideoEngineTest/RendererTest.cpp index 9a2e26e..f1f12af 100644 --- a/TrooperEngineTest/VideoEngineTest/RendererTest.cpp +++ b/TrooperEngineTest/VideoEngineTest/RendererTest.cpp @@ -14,8 +14,50 @@ void RendererTest() UTest u("cRenderer"); - SDL_Surface* sur = nullptr; - //cRenderer::Inst()->TextureToSurface(); + u.test("cRenderer. Setup()", cRenderer::Inst().Setup()); + + u.test("Are Surface Equal. AreEqual()", RendererAreaEqual()); + u.test("Are Surface Equal Not Equal. AreEqual()", RendererAreaEqualNotEqual()); + + u.test("Texture To Surface. TextureToSurface()", RendererTextureToSurface()); + + + + //u.test("Screen Shot", RendererTextureToSurface()); + u.report(); +} + +const bool RendererAreaEqual() +{ + SDL_Surface* one = SDL_LoadBMP("ImageTest.bmp"); + SDL_Surface* two = SDL_LoadBMP("ImageTest.bmp"); + + return cRenderer::Inst().AreEqual(*one, *two); +} + +const bool RendererAreaEqualNotEqual() +{ + SDL_Surface* one = SDL_LoadBMP("ImageTest.bmp"); + SDL_Surface* two = SDL_LoadBMP("ImageTest.bmp"); + + one = SDL_ConvertSurfaceFormat(one, SDL_PIXELFORMAT_RGBA32, 0); + + bool rtn = false; + if (cRenderer::Inst().AreEqual(*one, *two) == false) + rtn = true; + return rtn; +} + +const bool RendererTextureToSurface() +{ + SDL_Texture* text = IMG_LoadTexture(cRenderer::Inst().getRendererCopy(), "ImageTest.bmp"); + + SDL_Surface* one = SDL_LoadBMP("ImageTest.bmp"); + one = SDL_ConvertSurfaceFormat(one, SDL_PIXELFORMAT_RGBA32, 0); + + SDL_Surface* sur = cRenderer::Inst().TextureToSurface(text); + + return cRenderer::Inst().AreEqual(*one, *sur); } \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/RendererTest.hpp b/TrooperEngineTest/VideoEngineTest/RendererTest.hpp index 546b46c..8524879 100644 --- a/TrooperEngineTest/VideoEngineTest/RendererTest.hpp +++ b/TrooperEngineTest/VideoEngineTest/RendererTest.hpp @@ -3,4 +3,10 @@ void RendererTest(); +const bool RendererAreaEqual(); + +const bool RendererAreaEqualNotEqual(); + +const bool RendererTextureToSurface(); + #endif // __RENDERERTEST__ \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/VideoEngineTest.cpp b/TrooperEngineTest/VideoEngineTest/VideoEngineTest.cpp new file mode 100644 index 0000000..3879337 --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/VideoEngineTest.cpp @@ -0,0 +1,14 @@ +#include "VideoEngineTest.hpp" + +#include "VideoTest.hpp" +#include "RendererTest.hpp" +#include "ImageFileTest.hpp" + +void VideoEngineTest() +{ + VideoTest(); + + RendererTest(); + + ImageFileTest(); +} \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/VideoEngineTest.hpp b/TrooperEngineTest/VideoEngineTest/VideoEngineTest.hpp new file mode 100644 index 0000000..8932db1 --- /dev/null +++ b/TrooperEngineTest/VideoEngineTest/VideoEngineTest.hpp @@ -0,0 +1,6 @@ +#ifndef __VIDEOENGINETEST__ +#define __VIDEOENGINETEST__ + +void VideoEngineTest(); + +#endif // __VIDEOENGINETEST__ \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/VideoTest.cpp b/TrooperEngineTest/VideoEngineTest/VideoTest.cpp index 9151f27..87a9568 100644 --- a/TrooperEngineTest/VideoEngineTest/VideoTest.cpp +++ b/TrooperEngineTest/VideoEngineTest/VideoTest.cpp @@ -18,16 +18,26 @@ void VideoTest() VideoEngine::cVideo& video = VideoEngine::cVideo::Inst(); video.Initialize(); - u.test("Video Initialize", video.IsInit()); + u.test("Video Initialize. IsInit()", video.IsInit()); - u.test("Video Setup", video.Setup()); + u.test("Video Setup. Setup()", video.Setup()); // CaptionTest - cString cap_set = "Hello World"; + u.test("setCaption() and getCaption()", CaptionTest()); + + u.report(); +} + +const bool CaptionTest() +{ + bool rtn = false; + + cString cap_set = "Caption Test"; cVideo::Inst().setCaption(cap_set); cString cap_get = cVideo::Inst().getCaption(); - u.test("setCaption() and getCaption()", (cap_get == cap_set)); + if (cap_get == cap_set) + rtn = true; - u.report(); + return rtn; } \ No newline at end of file diff --git a/TrooperEngineTest/VideoEngineTest/VideoTest.hpp b/TrooperEngineTest/VideoEngineTest/VideoTest.hpp index b8102fc..3f6ff31 100644 --- a/TrooperEngineTest/VideoEngineTest/VideoTest.hpp +++ b/TrooperEngineTest/VideoEngineTest/VideoTest.hpp @@ -3,4 +3,6 @@ void VideoTest(); +const bool CaptionTest(); + #endif // __VIDEOTEST__ \ No newline at end of file diff --git a/TrooperEngineTest/main.cpp b/TrooperEngineTest/main.cpp index 6ddd5dd..64b3765 100644 --- a/TrooperEngineTest/main.cpp +++ b/TrooperEngineTest/main.cpp @@ -1,12 +1,12 @@ /* Copyright (C) 2016 Richard W. Allen -Program Name: SDL Pong C++ +Program Name: TrooperEngineTest Author: Richard W. Allen Version: V1.0 Date Started: August 24, 2016 Date End: Webpage: http://www.richardallenonline.com -IDE: Visual Studio 2015 -Compiler: C\C++ 2014 +IDE: Visual Studio 2017 +Compiler: C\C++ 2017 Langage: C++ License: GNU GENERAL PUBLIC LICENSE Version 2 see license.txt for details @@ -19,11 +19,11 @@ see license.txt for details /*** SDL Header Files ***/ #include "SDL.h" +/*** Unit Testing ***/ #include "UTest/UTest.hpp" /*** Video Engine Test ***/ -#include "VideoEngineTest/VideoTest.hpp" -#include "VideoEngineTest/ImageTest.hpp" +#include "VideoEngineTest/VideoEngineTest.hpp" /*** Utility Engine Test ***/ #include "UtilityEngineTest/StringTest.hpp" @@ -45,15 +45,16 @@ int main(int argc, char *argv[]) printf(cString("TrooperEngine V") + TrooperEngineCore::cTrooperEngineCore::Version() + "\n"); - VideoTest(); + VideoEngineTest(); - + //UtilityEngineTest(); + - StringTest(); + //StringTest(); - GUIXMLTest(); + //GUIXMLTest(); - ImageTest(); + //ImageTest(); UTest::OverAllReport();