Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
edsomjr committed Apr 7, 2016
1 parent fe4d4f3 commit 9100387
Show file tree
Hide file tree
Showing 16 changed files with 413 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.swp
*.o
*~
84 changes: 84 additions & 0 deletions Makefile
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)
16 changes: 16 additions & 0 deletions include/game.h
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
22 changes: 22 additions & 0 deletions include/libs.h
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
21 changes: 21 additions & 0 deletions include/sdl2.h
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
18 changes: 18 additions & 0 deletions include/sdl2Dvideo.h
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
28 changes: 28 additions & 0 deletions include/sdl2game.h
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
19 changes: 19 additions & 0 deletions include/sdl2window.h
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
16 changes: 16 additions & 0 deletions include/video.h
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
14 changes: 14 additions & 0 deletions include/window.h
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
26 changes: 26 additions & 0 deletions src/game.cpp
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;
}

}
52 changes: 52 additions & 0 deletions src/sdl2.cpp
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());
}

}
34 changes: 34 additions & 0 deletions src/sdl2Dvideo.cpp
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);
}

}
25 changes: 25 additions & 0 deletions src/sdl2game.cpp
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()";
}

}
Loading

0 comments on commit 9100387

Please sign in to comment.