-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.swp | ||
*.o | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
NAME = ijengine | ||
VERSION = 0.1.0 | ||
|
||
SRC_DIR = src | ||
INC_DIR = include | ||
OBJ_DIR = obj | ||
LIB_DIR = lib | ||
TST_DIR = test | ||
|
||
INSTALL_DIR = /usr/local | ||
INCLUDES_INSTALL_DIR = $(INSTALL_DIR)/include/$(NAME) | ||
LIB_INSTALL_DIR = $(INSTALL_DIR)/lib | ||
|
||
PACKAGE = $(NAME)-$(VERSION).tar.gz | ||
|
||
CC = g++ | ||
AR = ar | ||
|
||
ARFLAGS = rcs | ||
CFLAGS = -pedantic -std=c++11 -MMD -g3 -g\ | ||
-W -Wall -Wextra -Wshadow -Wcast-align -Wcast-qual -Wctor-dtor-privacy\ | ||
-Wdisabled-optimization -Wformat=2 -Wlogical-op -Wmissing-declarations\ | ||
-Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls\ | ||
-Wsign-promo -Wstrict-null-sentinel -Wswitch-default -Wundef\ | ||
-Wzero-as-null-pointer-constant -Wuseless-cast -Wnon-virtual-dtor | ||
INCLUDES = -Iinclude -Itest `sdl2-config --cflags` | ||
LIBS = `sdl2-config --libs` -lSDL2_image -lSDL2_ttf -lSDL2_mixer | ||
|
||
TARGET = $(LIB_DIR)/lib$(NAME).a | ||
|
||
TEST = $(TST_DIR)/test | ||
TST_SRC = ${wildcard $(TST_DIR)/*.cpp} | ||
TST_OBJ = ${addprefix $(TST_DIR)/, ${notdir ${TST_SRC:.cpp=.o}}} | ||
|
||
SRC = ${wildcard $(SRC_DIR)/*.cpp} | ||
OBJ = ${addprefix $(OBJ_DIR)/, ${notdir ${SRC:.cpp=.o}}} | ||
|
||
.PHONY: clean depend dist-clean dist install uninstall | ||
|
||
all: | ||
@mkdir -p $(OBJ_DIR) $(LIB_DIR) | ||
$(MAKE) $(TARGET) | ||
|
||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | ||
@echo Building $@ | ||
@$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ | ||
|
||
$(TST_DIR)/%.o: $(TST_DIR)/%.cpp | ||
@echo Building $@ | ||
@$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@ | ||
|
||
$(TARGET): $(OBJ) | ||
@echo Building $@ | ||
@$(AR) $(ARFLAGS) $@ $(OBJ) | ||
|
||
$(TEST): $(TST_OBJ) $(TARGET) | ||
@echo Building executable... | ||
@$(CC) $(CFLAGS) $(INCLUDES) $(TST_OBJ) $(TARGET) -o $@ $(LIBS) | ||
|
||
clean: | ||
@echo Cleaning... | ||
@find . -name *.o -exec rm {} \; | ||
@find . -name *.d -exec rm {} \; | ||
@rm -rf *~ *.o prog out.txt | ||
|
||
dist: | ||
@rm -rf *~ | ||
@tar czf $(PACKAGE) include src Makefile | ||
|
||
dist-clean: clean | ||
@find . -name *.a -exec rm {} \; | ||
@rm -f test/test $(TARGET) | ||
@rm -rf *.tar.gz | ||
@rm -rf $(OBJ_DIR) $(LIB_DIR) | ||
|
||
install: $(TARGET) | ||
@mkdir -p $(INCLUDES_INSTALL_DIR) $(LIB_INSTALL_DIR) | ||
@cp -rf include/* $(INCLUDES_INSTALL_DIR) | ||
@cp -f $(TARGET) $(LIB_INSTALL_DIR) | ||
|
||
uninstall: | ||
@rm -rf $(INCLUDES_INSTALL_DIR) $(INSTALL_DIR)/$(TARGET) | ||
|
||
-include $(OBJ:.o=.d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef GAME_H | ||
#define GAME_H | ||
|
||
namespace ijengine { | ||
|
||
class Game { | ||
public: | ||
Game(); | ||
virtual ~Game(); | ||
|
||
int run(); | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef LIBS_H | ||
#define LIBS_H | ||
|
||
#include <string> | ||
|
||
using std::string; | ||
|
||
namespace ijengine { | ||
|
||
class Lib { | ||
public: | ||
virtual ~Lib() = default; | ||
virtual string name() const = 0; | ||
virtual string version() const = 0; | ||
|
||
virtual void config(const string& param, const string& value) = 0; | ||
virtual void init() = 0; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef IJENGINE_SDL2_H | ||
#define IJENGINE_SDL2_H | ||
|
||
#include "libs.h" | ||
|
||
namespace ijengine { | ||
|
||
class LibSDL2 : public Lib { | ||
public: | ||
~LibSDL2(); | ||
|
||
string name() const; | ||
string version() const; | ||
|
||
void config(const string& param, const string& value); | ||
void init(); | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef SDL2DVIDEO_H | ||
#define SDL2DVIDEO_H | ||
|
||
#include "video.h" | ||
|
||
namespace ijengine { | ||
|
||
class SDL2DVideo : public Video { | ||
public: | ||
SDL2DVideo(); | ||
~SDL2DVideo(); | ||
|
||
Window * create_window(int w, int h); | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef SDL2_GAME_H | ||
#define SDL2_GAME_H | ||
|
||
#include "game.h" | ||
#include "sdl2.h" | ||
#include "sdl2Dvideo.h" | ||
#include "window.h" | ||
|
||
#include <memory> | ||
|
||
using std::unique_ptr; | ||
using std::shared_ptr; | ||
|
||
namespace ijengine { | ||
|
||
class SDL2Game : public Game { | ||
public: | ||
SDL2Game(); | ||
|
||
private: | ||
unique_ptr<LibSDL2> m_lib; | ||
unique_ptr<SDL2DVideo> m_video; | ||
shared_ptr<Window> m_window; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef SDL2_WINDOW_H | ||
#define SDL2_WINDOW_H | ||
|
||
#include "window.h" | ||
#include <SDL2/SDL.h> | ||
|
||
namespace ijengine { | ||
|
||
class SDL2Window : public Window { | ||
public: | ||
SDL2Window(SDL_Window *window, SDL_Renderer *renderer); | ||
~SDL2Window(); | ||
|
||
int w() const; | ||
int h() const; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef VIDEO_H | ||
#define VIDEO_H | ||
|
||
namespace ijengine { | ||
|
||
class Window; | ||
|
||
class Video { | ||
public: | ||
virtual ~Video() = default; | ||
virtual Window * create_window(int w, int h) = 0; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef WINDOW_H | ||
#define WINDOW_H | ||
|
||
namespace ijengine { | ||
|
||
class Window { | ||
public: | ||
virtual ~Window() = default; | ||
virtual int w() const = 0; | ||
virtual int h() const = 0; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "game.h" | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
namespace ijengine { | ||
|
||
Game::Game() | ||
{ | ||
cout << "Initializing...\n"; | ||
} | ||
|
||
Game::~Game() | ||
{ | ||
cout << "Shutting down...\n"; | ||
} | ||
|
||
int | ||
Game::run() | ||
{ | ||
cout << "Hello World\n"; | ||
|
||
return 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "sdl2.h" | ||
|
||
#include <SDL2/SDL.h> | ||
#include <SDL2/SDL_version.h> | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
namespace ijengine { | ||
|
||
LibSDL2::~LibSDL2() | ||
{ | ||
printf("Desligando a SDL2...\n"); | ||
if (SDL_WasInit(SDL_INIT_VIDEO)) | ||
SDL_Quit(); | ||
} | ||
|
||
string | ||
LibSDL2::name() const | ||
{ | ||
return "SDL2"; | ||
} | ||
|
||
string | ||
LibSDL2::version() const | ||
{ | ||
SDL_version v; | ||
SDL_GetVersion(&v); | ||
|
||
char buffer[128]; | ||
sprintf(buffer, "%d.%d.%d", v.major, v.minor, v.patch); | ||
|
||
return string(buffer); | ||
} | ||
|
||
void | ||
LibSDL2::config(const string&, const string&) | ||
{ | ||
} | ||
|
||
void | ||
LibSDL2::init() | ||
{ | ||
int rc = SDL_Init(SDL_INIT_VIDEO); | ||
|
||
if (rc) | ||
throw "Error on LibSDL2::init()"; | ||
|
||
printf("nome = [%s], versao = [%s]\n", name().c_str(), version().c_str()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "sdl2Dvideo.h" | ||
#include "sdl2window.h" | ||
|
||
#include <SDL2/SDL.h> | ||
|
||
namespace ijengine { | ||
|
||
SDL2DVideo::SDL2DVideo() | ||
{ | ||
if (SDL_WasInit(SDL_INIT_VIDEO) == 0 and SDL_InitSubSystem(SDL_INIT_VIDEO)) | ||
throw "Error on SDL2DVideo::SDL2DVideo()"; | ||
} | ||
|
||
SDL2DVideo::~SDL2DVideo() | ||
{ | ||
SDL_Delay(3000); | ||
|
||
if (SDL_WasInit(SDL_INIT_VIDEO)) | ||
SDL_QuitSubSystem(SDL_INIT_VIDEO); | ||
} | ||
|
||
Window * | ||
SDL2DVideo::create_window(int w, int h) | ||
{ | ||
SDL_Window *window; | ||
SDL_Renderer *renderer; | ||
|
||
if (SDL_CreateWindowAndRenderer(w, h, 0, &window, &renderer)) | ||
return nullptr; | ||
|
||
return new SDL2Window(window, renderer); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "sdl2game.h" | ||
|
||
#include <memory> | ||
using std::make_shared; | ||
|
||
namespace ijengine { | ||
|
||
SDL2Game::SDL2Game() | ||
: m_lib(new LibSDL2()) | ||
{ | ||
if (m_lib) | ||
m_lib->init(); | ||
|
||
m_video = unique_ptr<SDL2DVideo>(new SDL2DVideo()); | ||
|
||
if (not m_video) | ||
throw "Error on SDL2Game::SDL2Game()"; | ||
|
||
m_window = shared_ptr<Window>(m_video->create_window(800, 600)); | ||
|
||
if (not m_window) | ||
throw "Error on SDL2Game::SDL2Game()"; | ||
} | ||
|
||
} |
Oops, something went wrong.