Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add SDLImageInterface #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ SET (SOURCES src/core/Game.cpp
src/core/builder/ImageTextureBuilder.cpp
src/core/builder/TextTextureBuilder.cpp

src/core/impl/SDLImageTexture.cpp

src/interfaces/impl/INISettingsInterface.cpp
src/interfaces/impl/SDLImageInterface.cpp

src/utils/Color.cpp
src/utils/Colors.cpp
Expand Down Expand Up @@ -86,6 +89,7 @@ SET(HEADERS include/bkengine/core/builder/templates/AnimationBuilder_templates.h
include/bkengine/exceptions/NullPointerException.h

include/bkengine/interfaces/impl/INISettingsInterface.h
include/bkengine/interfaces/impl/SDLImageInterface.h

include/bkengine/interfaces/EventInterface.h
include/bkengine/interfaces/FontInterface.h
Expand All @@ -106,7 +110,69 @@ SET(HEADERS include/bkengine/core/builder/templates/AnimationBuilder_templates.h
include/bkengine/utils/Keys.h
include/bkengine/utils/Logger.h
include/bkengine/utils/Timer.h
)
include/bkengine/core/impl/SDLImageTexture.h
include/bkengine/exceptions/NotImplementedException.h
src/utils/InterfaceContainer.cpp
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you mixing .h and .cpp files here?

src/core/impl/SDLImageTexture.cpp
)

SET(HEADERS include/bkengine/core/builder/templates/AnimationBuilder_templates.h
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't that part of the most recent PR?

include/bkengine/core/builder/templates/ElementBuilder_templates.h
include/bkengine/core/builder/templates/GameBuilder_templates.h
include/bkengine/core/builder/templates/SceneBuilder_templates.h

include/bkengine/core/builder/AnimationBuilder.h
include/bkengine/core/builder/ElementBuilder.h
include/bkengine/core/builder/GameBuilder.h
include/bkengine/core/builder/ImageTextureBuilder.h
include/bkengine/core/builder/SceneBuilder.h
include/bkengine/core/builder/TextTextureBuilder.h
include/bkengine/core/builder/TextureBuilder.h

include/bkengine/core/utils/AnimationUtils.h
include/bkengine/core/utils/ElementUtils.h
include/bkengine/core/utils/GameUtils.h
include/bkengine/core/utils/SceneUtils.h

include/bkengine/core/Animation.h
include/bkengine/core/Element.h
include/bkengine/core/Game.h
include/bkengine/core/ImageTexture.h
include/bkengine/core/Scene.h
include/bkengine/core/TextTexture.h
include/bkengine/core/Texture.h

include/bkengine/exceptions/BuilderException.h
include/bkengine/exceptions/GameLoopException.h
include/bkengine/exceptions/NameAlreadyExistsException.h
include/bkengine/exceptions/NameNotFoundException.h
include/bkengine/exceptions/NullPointerException.h

include/bkengine/interfaces/impl/INISettingsInterface.h
include/bkengine/interfaces/impl/SDLImageInterface.h

include/bkengine/interfaces/EventInterface.h
include/bkengine/interfaces/FontInterface.h
include/bkengine/interfaces/GraphicsInterface.h
include/bkengine/interfaces/ImageInterface.h
include/bkengine/interfaces/SettingsInterface.h

include/bkengine/utils/templates/InterfaceContainer_templates.h

include/bkengine/utils/backtrace.h
include/bkengine/utils/Color.h
include/bkengine/utils/Colors.h
include/bkengine/utils/CoordinateUtils.h
include/bkengine/utils/Event.h
include/bkengine/utils/Geometry.h
include/bkengine/utils/InterfaceContainer.h
include/bkengine/utils/Key.h
include/bkengine/utils/Keys.h
include/bkengine/utils/Logger.h
include/bkengine/utils/Timer.h
include/bkengine/core/impl/SDLImageTexture.h
include/bkengine/exceptions/NotImplementedException.h
)

SET (TEST_SOURCES tests/main.cpp
tests/INISettingsInterfaceTest.cpp
Expand Down
29 changes: 29 additions & 0 deletions include/bkengine/core/impl/SDLImageTexture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef BKENGINE_SDLIMAGETEXTURE_H
#define BKENGINE_SDLIMAGETEXTURE_H

#include <SDL_surface.h>
#include <SDL_system.h>

#include "core/ImageTexture.h"
#include "exceptions/NotImplementedException.h"

namespace bkengine
{
class SDLImageTexture : public ImageTexture
{
friend class SDLImageInterface;

public:
void onRender() override;

const SDL_Texture *getTexture() const;

~SDLImageTexture();
SDLImageTexture(SDL_Texture *);

private:
SDL_Texture *texture;
};
}

#endif //BKENGINE_SDLIMAGETEXTURE_H
15 changes: 15 additions & 0 deletions include/bkengine/exceptions/NotImplementedException.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef BKENGINE_NOTIMPLEMENTEDEXCEPTION_H
#define BKENGINE_NOTIMPLEMENTEDEXCEPTION_H

#include <stdexcept>

namespace bkengine
{
class NotImplementedException : public std::logic_error
{
public:
NotImplementedException() : std::logic_error("Function not yet implemented.") { };
};
}

#endif //BKENGINE_NOTIMPLEMENTEDEXCEPTION_H
1 change: 1 addition & 0 deletions include/bkengine/interfaces/ImageInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace bkengine
class ImageInterface
{
public:

virtual std::shared_ptr<ImageTexture> renderImageFileToTexture(const std::string &filePath,
const AbsRect &) = 0;
};
Expand Down
22 changes: 22 additions & 0 deletions include/bkengine/interfaces/impl/SDLImageInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef BKENGINE_SDLIMAGEINTERFACE_H
#define BKENGINE_SDLIMAGEINTERFACE_H

#include <SDL_image.h>
#include <SDL_system.h>
#include <fstream>

#include "interfaces/ImageInterface.h"

namespace bkengine
{
class SDLImageInterface : public ImageInterface
{
public:
virtual void init();
virtual void cleanup();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious where you wanna call these two methods^^
(static constructor)

virtual std::shared_ptr<ImageTexture> renderImageFileToTexture(const std::string &filePath,
const AbsRect &) override;
};
}

#endif //BKENGINE_SDLIMAGEINTERFACE_H
2 changes: 0 additions & 2 deletions src/core/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


bool Animation::onRender()
{
return false;
Expand All @@ -18,7 +17,6 @@ uint32_t Animation::getFramesPerTexture() const
return framesPerTexture;
}


void Animation::_onRender()
{
bool suppress = onRender();
Expand Down
3 changes: 0 additions & 3 deletions src/core/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


bool Element::onRender()
{
return false;
Expand All @@ -18,7 +17,6 @@ bool Element::onEvent(const Event &e)
return false;
}


std::string Element::getName() const
{
return name;
Expand All @@ -34,7 +32,6 @@ RelRect Element::getCollisionBox() const
return collisionBox;
}


void Element::_onRender()
{
bool suppress = onRender();
Expand Down
4 changes: 0 additions & 4 deletions src/core/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

using namespace bkengine;


// FPS = 60
static const double SCREEN_TICKS_PER_FRAME = 1000. / 60.;


void Game::run()
{
auto eventInterface = interfaceContainer.getEventInterface();
Expand Down Expand Up @@ -80,7 +78,6 @@ bool Game::onEvent(const Event &event)
return false;
}


void Game::setIconFile(const std::string &file)
{
auto graphicsInterface = interfaceContainer.getGraphicsInterface();
Expand Down Expand Up @@ -108,7 +105,6 @@ void Game::setWindowTitle(const std::string &title)
graphicsInterface->setWindowTitle(title);
}


void Game::_onRender()
{
bool suppress = onRender();
Expand Down
1 change: 0 additions & 1 deletion src/core/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


bool Scene::onRender()
{
return false;
Expand Down
1 change: 0 additions & 1 deletion src/core/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


std::string Texture::getName() const
{
return name;
Expand Down
1 change: 0 additions & 1 deletion src/core/builder/AnimationBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


AnimationBuilder AnimationBuilder::createBuilder()
{
return AnimationBuilder();
Expand Down
1 change: 0 additions & 1 deletion src/core/builder/ElementBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


ElementBuilder ElementBuilder::createBuilder()
{
return ElementBuilder();
Expand Down
1 change: 0 additions & 1 deletion src/core/builder/GameBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


GameBuilder GameBuilder::createBuilder()
{
return GameBuilder();
Expand Down
4 changes: 1 addition & 3 deletions src/core/builder/ImageTextureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


ImageTextureBuilder &ImageTextureBuilder::setGame(const std::shared_ptr<Game> &game)
{
ImageTextureBuilder::game = game;
Expand Down Expand Up @@ -52,7 +51,6 @@ ImageTextureBuilder &ImageTextureBuilder::setFlip(bool horizontal, bool vertical
return *this;
}


std::shared_ptr<Texture> ImageTextureBuilder::build() const
{
if (game == nullptr) {
Expand All @@ -79,6 +77,6 @@ std::shared_ptr<Texture> ImageTextureBuilder::build() const
texture->angle = angleRadians;
texture->flipHorizontally = flipHorizontally;
texture->flipVertically = flipVertically;

return texture;
}
1 change: 0 additions & 1 deletion src/core/builder/SceneBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


SceneBuilder SceneBuilder::createBuilder()
{
return SceneBuilder();
Expand Down
4 changes: 1 addition & 3 deletions src/core/builder/TextTextureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


TextTextureBuilder &TextTextureBuilder::setGame(const std::shared_ptr<Game> &game)
{
TextTextureBuilder::game = game;
Expand Down Expand Up @@ -64,7 +63,6 @@ TextTextureBuilder &TextTextureBuilder::setFlip(bool horizontal, bool vertical)
return *this;
}


std::shared_ptr<Texture> TextTextureBuilder::build() const
{
if (game == nullptr) {
Expand Down Expand Up @@ -99,6 +97,6 @@ std::shared_ptr<Texture> TextTextureBuilder::build() const
texture->angle = angleRadians;
texture->flipHorizontally = flipHorizontally;
texture->flipVertically = flipVertically;

return texture;
}
1 change: 0 additions & 1 deletion src/core/builder/TextureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


TextTextureBuilder TextureBuilder::createTextBuilder()
{
return TextTextureBuilder();
Expand Down
23 changes: 23 additions & 0 deletions src/core/impl/SDLImageTexture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "core/impl/SDLImageTexture.h"

using namespace bkengine;

void SDLImageTexture::onRender()
{
throw NotImplementedException();
}

const SDL_Texture *SDLImageTexture::getTexture() const
{
return texture;
}

SDLImageTexture::~SDLImageTexture()
{
SDL_DestroyTexture(texture);
}

SDLImageTexture::SDLImageTexture(SDL_Texture *texture)
{
this->texture = texture;
}
1 change: 0 additions & 1 deletion src/core/utils/AnimationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


void AnimationUtils::addTexture(const std::shared_ptr<Animation> &animation, const std::shared_ptr<Texture> &texture)
{
assert(animation != nullptr);
Expand Down
1 change: 0 additions & 1 deletion src/core/utils/ElementUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


void ElementUtils::addAnimation(const std::shared_ptr<Element> &element, const std::shared_ptr<Animation> &animation)
{
assert(element != nullptr);
Expand Down
2 changes: 0 additions & 2 deletions src/core/utils/GameUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using namespace bkengine;


void GameUtils::addScene(const std::shared_ptr<Game> &game, const std::shared_ptr<Scene> &scene)
{
assert(game != nullptr);
Expand Down Expand Up @@ -94,7 +93,6 @@ uint32_t GameUtils::getSceneCount(const std::shared_ptr<Game> &game)
return game->scenes.size();
}


void GameUtils::activateScene(const std::shared_ptr<Game> &game, const std::string &name)
{
assert(game != nullptr);
Expand Down
Loading