This commit is contained in:
2016-05-29 18:10:44 +02:00
parent 61aa1de2e0
commit cb7005fff0
381 changed files with 73702 additions and 2 deletions

View File

@ -0,0 +1,123 @@
#ifndef CORE_H_
# define CORE_H_
#include <list>
#include <SFML/Audio.hpp>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <iostream>
#include "QuadTree.hh"
#include "../IRenderable.hh"
# ifndef __DWIDTH
# define __DWIDTH 1920
# define __DHEIGHT 1080
# endif
#ifndef __DQUADTREE_COMPLEXITY__
#define __DQUADTREE_COMPLEXITY__ 6
#endif
#if __DQUADTREE_COMPLEXITY__ > 10
#warning "you will use more than 300 Mb =O"
#endif
namespace DamnCute {
class APhysics;
class Core {
public:
Core(const Core&) = delete;
Core(const Core&&) = delete;
Core& operator=(const Core&) = delete;
Core& operator=(const Core&&) = delete;
static Core* getInstance();
void closeWin();
void reset();
void freeAll();
void addObject(IRenderable*);
void delObject(IRenderable*);
void hideObject(IRenderable*);
void addOnBg(IRenderable*);
void flushScene();
void flushEvent();
template <unsigned int SIZEX = __DWIDTH, unsigned int SIZEY = __DHEIGHT>
void createWindow(unsigned int width = 0, unsigned int height = 0, bool full = false) {
unsigned int style = full << 3 | sf::Style::Titlebar;
sf::VideoMode v;
if (full) {
v = sf::VideoMode::getFullscreenModes()[0];
} else if (width == 0 && height == 0) {
v = sf::VideoMode::getDesktopMode();
} else {
v = sf::VideoMode(width, height);
}
_win = new sf::RenderWindow(v, "DamnCute Engine", style);
_Rtex.create(SIZEX, SIZEY);
_Rtex.setSmooth(true);
_rsp.setTexture(_Rtex.getTexture());
_rsp.setScale((float)getWindowSizeX() / (float)__DWIDTH , (float)getWindowSizeY() / (float)__DHEIGHT);
_win->setVerticalSyncEnabled(true);
_win->setFramerateLimit(60);
}
int getWindowStatus();
int getWindowSizeX();
int getWindowSizeY();
sf::Music& getMusic();
void musicPath(std::string);
void musicPlay(int);
int getMusicListSize();
inline bool getGameStatus() const {
return _gameStatus;
}
inline void switchGameStatus() {
_gameStatus = !_gameStatus;
}
inline sf::Event getEvent() const {
return event;
}
inline void setFPSDisplay(bool value) {
_displayFPS = value;
}
inline void addBulletsCounter() {
++_numberOfBullets;
}
inline QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__>* getQuadTree() {
return &_physicTree;
}
private:
Core();
~Core();
void refresh();
static Core* __coreInstance;
QuadTree<std::list<APhysics*>, __DQUADTREE_COMPLEXITY__> _physicTree;
sf::RenderWindow* _win;
sf::RenderTexture _Rtex;
std::list<IRenderable*> _objects;
bool _gameStatus;
bool _displayFPS;
unsigned int _numberOfBullets;
unsigned int _Pframmes;
unsigned int _tmpFrammes;
sf::Sprite _rsp;
sf::Clock _gameClock;
sf::Event event;
sf::Music _music;
std::string _musicPath;
std::vector<std::string> _musicList;
void saveFolderMusic(std::string);
bool supportedFileFormat(std::string);
};
}
#define sCore Core::getInstance()
#endif /* !CORE_H_ */

View File

@ -0,0 +1,76 @@
#include <array>
#include <utility>
#ifndef QUADTREE_H_
# define QUADTREE_H_
namespace DamnCute {
template <typename T, unsigned int LEVEL>
class QuadTree {
public:
enum TDir {
AZone,
BZone,
CZone,
DZone
};
enum _CQTREEVALUES_ {
_COMPLEXITY_ = LEVEL,
};
private:
#include "TreeNode.hh"
typedef std::array<TDir, LEVEL> __path_ar_;
TreeNode<T>* _head;
inline TreeNode<T>* _getNode(__path_ar_ path) const {
TreeNode<T>* x = _head;
for (typename __path_ar_::const_iterator it = path.cbegin(); it != path.cend(); ++it) {
if (*it == AZone)
x = x->up;
else if (*it == BZone)
x = x->down;
else if (*it == CZone)
x = x->right;
else if (*it == DZone)
x = x->left;
}
return x;
}
public:
explicit QuadTree() : _head(new TreeNode<T>(LEVEL)) {}
T* getDataTreeNode(__path_ar_& path) const {
return _getNode(path)->data;
}
void setTreeNode(T* value, const __path_ar_& path) {
_getNode(path)->data = value;
}
void swap(__path_ar_& path1, const __path_ar_& path2) {
T* a = _getNode(path1)->data;
T* b = _getNode(path2)->data;
T* tmp;
tmp = a;
a = b;
b = tmp;
}
bool thereIsObject(const __path_ar_& p) {
if (_getNode(p)->data) {
return true;
}
return false;
}
inline unsigned int&& getLevel() const {
return std::move(LEVEL);
}
typedef __path_ar_ Array_Type_;
};
}
#endif /* !QUADTREE_H_ */

View File

@ -0,0 +1,38 @@
#include <type_traits>
#ifndef NODE_H_
# define NODE_H_
template <typename DATANODE>
struct TreeNode {
DATANODE* data; // TODO must exist only for final recurtion
TreeNode<DATANODE>* up;
TreeNode<DATANODE>* down;
TreeNode<DATANODE>* right;
TreeNode<DATANODE>* left;
explicit TreeNode(unsigned short level) {
if (level) {
up = new TreeNode<DATANODE>(level - 1);
down = new TreeNode<DATANODE>(level - 1);
left = new TreeNode<DATANODE>(level - 1);
right = new TreeNode<DATANODE>(level - 1);
} else {
up = NULL;
down = NULL;
left = NULL;
right = NULL;
}
data = NULL;
}
virtual ~TreeNode() {
delete up;
delete down;
delete left;
delete right;
}
};
#endif /* !NODE_H_ */