Lot of changes. [...]
[Renderer] Deleted, code moved to Application. [Transformable] Transformations are now applied to model matrix in applyTransform. [ResourceHandler|TextureLoader|XMLFile] Added. [Debug|Exception] Updated.
This commit is contained in:
parent
9af917357a
commit
fb3f7f0501
@ -1,4 +1,4 @@
|
|||||||
# Generated by YCM Generator at 2018-06-21 01:05:00.362117
|
# Generated by YCM Generator at 2018-06-21 04:46:08.057827
|
||||||
|
|
||||||
# This file is NOT licensed under the GPLv3, which is the license for the rest
|
# This file is NOT licensed under the GPLv3, which is the license for the rest
|
||||||
# of YouCompleteMe.
|
# of YouCompleteMe.
|
||||||
@ -42,6 +42,7 @@ flags = [
|
|||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/gui',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/gui',
|
||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/hud',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/hud',
|
||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/inventory',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/inventory',
|
||||||
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/resource',
|
||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/states',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/states',
|
||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/system',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/system',
|
||||||
'-I/home/bazin_q/rendu/Perso/KubKraft/include/utils',
|
'-I/home/bazin_q/rendu/Perso/KubKraft/include/utils',
|
||||||
|
@ -92,6 +92,7 @@ include_directories(${SDL2_INCLUDE_DIRS}
|
|||||||
# Link options
|
# Link options
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
|
${TINYXML2_LIBRARIES}
|
||||||
${OPENGL_LIBRARIES}
|
${OPENGL_LIBRARIES}
|
||||||
${SDL2_LIBRARIES}
|
${SDL2_LIBRARIES}
|
||||||
${SDL2IMAGE_LIBRARIES}
|
${SDL2IMAGE_LIBRARIES}
|
||||||
|
32
TODO
32
TODO
@ -2,19 +2,19 @@ TODO
|
|||||||
|
|
||||||
# Nettoyage
|
# Nettoyage
|
||||||
|
|
||||||
• TODO: Vérifier les utilisations inutiles de pointeurs
|
• DONE: Découper les gros pâtés en sous-classes
|
||||||
• DONE: Nettoyer les vieux headers
|
• DONE: Nettoyer les vieux headers
|
||||||
• TODO: `Types.hpp` → `IntTypes.hpp`
|
|
||||||
→ TODO: Vérifier que les types sont bien corrects
|
→ TODO: Vérifier que les types sont bien corrects
|
||||||
• TODO: Remplacer les anciennes classes par leur upgrade:
|
• WIP: Remplacer les anciennes classes par leur upgrade:
|
||||||
◦ DONE: `ApplicationState` / `ApplicationStateStack`
|
◦ DONE: `ApplicationState` / `ApplicationStateStack`
|
||||||
◦ DONE: `GameClock`
|
◦ DONE: `GameClock`
|
||||||
|
◦ DONE: `Debug` / `Exception`
|
||||||
◦ TODO: `Window` et `Texture` (depuis `ZeldaOOL`)
|
◦ TODO: `Window` et `Texture` (depuis `ZeldaOOL`)
|
||||||
◦ TODO: `Debug` / `Exception`
|
|
||||||
◦ TODO: Input system (Mouse + Keyboard)
|
◦ TODO: Input system (Mouse + Keyboard)
|
||||||
|
• TODO: `Types.hpp` → `IntTypes.hpp`
|
||||||
|
• TODO: Vérifier les utilisations inutiles de pointeurs
|
||||||
• TODO: Catch SDLLoader exception
|
• TODO: Catch SDLLoader exception
|
||||||
• TODO: Passer un clang-tidy sur le code
|
• TODO: Passer un clang-tidy sur le code
|
||||||
• TODO: Découper les gros pâtés en sous-classes
|
|
||||||
• TODO: Passer à la SFML
|
• TODO: Passer à la SFML
|
||||||
• TODO: Séparer l’engine et le gameplay
|
• TODO: Séparer l’engine et le gameplay
|
||||||
• TODO: Séparer le code client du code serveur
|
• TODO: Séparer le code client du code serveur
|
||||||
@ -30,18 +30,21 @@ TODO
|
|||||||
|
|
||||||
# ToDoList
|
# ToDoList
|
||||||
|
|
||||||
|
## Moteur
|
||||||
|
|
||||||
|
• DONE: Rajouter le `ResourceHandler`
|
||||||
|
|
||||||
## Joueur
|
## Joueur
|
||||||
|
|
||||||
• DONE: Ciblage de bloc
|
• DONE: Ciblage de bloc
|
||||||
◦ DONE: Suppression de bloc
|
◦ DONE: Suppression de bloc
|
||||||
◦ DONE: Ajout de bloc
|
◦ DONE: Ajout de bloc
|
||||||
• TODO: Collisions + Gravité
|
• TODO: Collisions + Gravité
|
||||||
◦ TODO: Système d’entités (réutiliser l’ECS mais en multi-thread)
|
• TODO: Système d’entités (réutiliser l’ECS mais en multi-thread)
|
||||||
|
|
||||||
## Items
|
## Items
|
||||||
|
|
||||||
• TODO: Créer un système d’items
|
• TODO: Créer un système d’items
|
||||||
◦ TODO: Inventaire basique (1 slot)
|
|
||||||
◦ TODO: Récupération du bloc cassé
|
◦ TODO: Récupération du bloc cassé
|
||||||
• TODO: Ajouter les animations de destruction des blocs
|
• TODO: Ajouter les animations de destruction des blocs
|
||||||
• TODO: Faire un vrai drop d’item
|
• TODO: Faire un vrai drop d’item
|
||||||
@ -54,18 +57,19 @@ TODO
|
|||||||
|
|
||||||
## Génération
|
## Génération
|
||||||
|
|
||||||
• TODO: Augmenter la hauteur du terrain
|
• DONE: Augmenter la hauteur du terrain
|
||||||
• TODO: Dirt + Grass
|
• WIP: Rajouter des blocs
|
||||||
• TODO: WATEEEEEEER
|
◦ DONE: Dirt + Grass
|
||||||
• TODO: Arbres
|
◦ DONE: WATEEEEEEER
|
||||||
• TODO: Fleurs (emit light at night?)
|
◦ DONE: Arbres
|
||||||
|
◦ TODO: Fleurs (emit light at night?)
|
||||||
• TODO: Biomes
|
• TODO: Biomes
|
||||||
• TODO: Génération multi-thread
|
• TODO: Génération multi-thread
|
||||||
|
|
||||||
## Affichage
|
## Affichage
|
||||||
|
|
||||||
• TODO: Optimiser au maximum l’affichage des chunks
|
• WIP: Optimiser au maximum l’affichage des chunks
|
||||||
◦ TODO: Faire le max de culling
|
◦ WIP: Faire le max de culling
|
||||||
▸ DONE: Face culling
|
▸ DONE: Face culling
|
||||||
▸ DONE: Frustum culling
|
▸ DONE: Frustum culling
|
||||||
▸ TODO: Occlusion culling
|
▸ TODO: Occlusion culling
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#define APPLICATION_HPP_
|
#define APPLICATION_HPP_
|
||||||
|
|
||||||
#include "CoreApplication.hpp"
|
#include "CoreApplication.hpp"
|
||||||
#include "Renderer.hpp"
|
|
||||||
|
|
||||||
class Application : public CoreApplication {
|
class Application : public CoreApplication {
|
||||||
public:
|
public:
|
||||||
@ -23,8 +22,7 @@ class Application : public CoreApplication {
|
|||||||
|
|
||||||
void init() override;
|
void init() override;
|
||||||
|
|
||||||
private:
|
void initOpenGL();
|
||||||
Renderer m_renderer;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATION_HPP_
|
#endif // APPLICATION_HPP_
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include "ApplicationStateStack.hpp"
|
#include "ApplicationStateStack.hpp"
|
||||||
#include "GameClock.hpp"
|
#include "GameClock.hpp"
|
||||||
// #include "KeyboardHandler.hpp"
|
// #include "KeyboardHandler.hpp"
|
||||||
// #include "ResourceHandler.hpp"
|
#include "ResourceHandler.hpp"
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
class CoreApplication {
|
class CoreApplication {
|
||||||
@ -38,8 +38,8 @@ class CoreApplication {
|
|||||||
GameClock m_clock;
|
GameClock m_clock;
|
||||||
|
|
||||||
// KeyboardHandler m_keyboardHandler;
|
// KeyboardHandler m_keyboardHandler;
|
||||||
//
|
|
||||||
// ResourceHandler m_resourceHandler;
|
ResourceHandler m_resourceHandler;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleEvents();
|
void handleEvents();
|
||||||
|
37
include/core/XMLFile.hpp
Normal file
37
include/core/XMLFile.hpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: XMLFile.hpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 17/01/2018 19:21:52
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef XMLFILE_HPP_
|
||||||
|
#define XMLFILE_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <tinyxml2.h>
|
||||||
|
|
||||||
|
class XMLFile {
|
||||||
|
public:
|
||||||
|
XMLFile() = default;
|
||||||
|
XMLFile(const std::string &filename);
|
||||||
|
XMLFile(const XMLFile &) = default;
|
||||||
|
XMLFile(XMLFile &&) = default;
|
||||||
|
|
||||||
|
void load(const std::string &filename);
|
||||||
|
|
||||||
|
tinyxml2::XMLHandle FirstChildElement(const char *element) { return m_doc.FirstChildElement(element); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
tinyxml2::XMLDocument m_xml;
|
||||||
|
tinyxml2::XMLHandle m_doc{m_xml};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // XMLFILE_HPP_
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* =====================================================================================
|
|
||||||
*
|
|
||||||
* Filename: Renderer.hpp
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* Created: 05/06/2018 15:40:44
|
|
||||||
*
|
|
||||||
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
||||||
*
|
|
||||||
* =====================================================================================
|
|
||||||
*/
|
|
||||||
#ifndef RENDERER_HPP_
|
|
||||||
#define RENDERER_HPP_
|
|
||||||
|
|
||||||
#include "Window.hpp"
|
|
||||||
|
|
||||||
class Renderer {
|
|
||||||
public:
|
|
||||||
void init(Window &window);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Window *m_window = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // RENDERER_HPP_
|
|
@ -25,7 +25,7 @@ class Texture {
|
|||||||
Texture(const std::string &filename);
|
Texture(const std::string &filename);
|
||||||
~Texture() noexcept;
|
~Texture() noexcept;
|
||||||
|
|
||||||
void load(const std::string &filename);
|
void loadFromFile(const std::string &filename);
|
||||||
|
|
||||||
static void bind(const Texture *texture);
|
static void bind(const Texture *texture);
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class Texture {
|
|||||||
u16 m_width;
|
u16 m_width;
|
||||||
u16 m_height;
|
u16 m_height;
|
||||||
|
|
||||||
GLuint m_texture;
|
GLuint m_texture = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEXTURE_HPP_
|
#endif // TEXTURE_HPP_
|
||||||
|
@ -23,15 +23,19 @@ class Transformable {
|
|||||||
void move(float x, float y, float z);
|
void move(float x, float y, float z);
|
||||||
void setPosition(float x, float y, float z);
|
void setPosition(float x, float y, float z);
|
||||||
|
|
||||||
void setScale(float factor) { setScale(factor, factor, factor); }
|
|
||||||
void setScale(float factorX, float factorY, float factorZ);
|
void setScale(float factorX, float factorY, float factorZ);
|
||||||
|
|
||||||
void applyTransform(RenderStates &states) const;
|
void applyTransform(RenderStates &states) const;
|
||||||
|
|
||||||
const glm::mat4 &getTransform() const { return m_modelMatrix; }
|
const glm::vec3 &getPosition() const { return m_position; }
|
||||||
|
const glm::vec3 &getScale() const { return m_scale; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
glm::mat4 m_modelMatrix{1};
|
glm::mat4 m_modelMatrix{1};
|
||||||
|
glm::mat4 m_tmpMatrix;
|
||||||
|
|
||||||
|
glm::vec3 m_position;
|
||||||
|
glm::vec3 m_scale{1, 1, 1};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRANSFORMABLE_HPP_
|
#endif // TRANSFORMABLE_HPP_
|
||||||
|
@ -18,8 +18,9 @@
|
|||||||
|
|
||||||
#include "Inventory.hpp"
|
#include "Inventory.hpp"
|
||||||
#include "ItemWidget.hpp"
|
#include "ItemWidget.hpp"
|
||||||
|
#include "Transformable.hpp"
|
||||||
|
|
||||||
class InventoryWidget : public IDrawable {
|
class InventoryWidget : public IDrawable, public Transformable {
|
||||||
public:
|
public:
|
||||||
void update(const Inventory &inventory);
|
void update(const Inventory &inventory);
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ class ItemWidget : public IDrawable, public Transformable {
|
|||||||
private:
|
private:
|
||||||
void draw(RenderTarget &target, RenderStates states) const override;
|
void draw(RenderTarget &target, RenderStates states) const override;
|
||||||
|
|
||||||
Texture m_texture;
|
u16 m_id;
|
||||||
|
|
||||||
Image m_image;
|
Image m_image;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ class WorkbenchWidget : public IDrawable, public Transformable {
|
|||||||
private:
|
private:
|
||||||
void draw(RenderTarget &target, RenderStates states) const override;
|
void draw(RenderTarget &target, RenderStates states) const override;
|
||||||
|
|
||||||
Texture m_backgroundTexture;
|
|
||||||
Image m_background;
|
Image m_background;
|
||||||
|
|
||||||
Inventory m_inventory{9, 3};
|
Inventory m_inventory{9, 3};
|
||||||
|
@ -32,13 +32,11 @@ class Hotbar : public IDrawable {
|
|||||||
private:
|
private:
|
||||||
void draw(RenderTarget &target, RenderStates states) const override;
|
void draw(RenderTarget &target, RenderStates states) const override;
|
||||||
|
|
||||||
Texture m_texture;
|
|
||||||
Image m_background;
|
Image m_background;
|
||||||
|
|
||||||
Image m_cursor;
|
Image m_cursor;
|
||||||
int m_cursorPos = 0;
|
int m_cursorPos = 0;
|
||||||
|
|
||||||
Texture m_blocksTexture;
|
|
||||||
// std::vector<Image> m_items;
|
// std::vector<Image> m_items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
class Image : public IDrawable, public Transformable {
|
class Image : public IDrawable, public Transformable {
|
||||||
public:
|
public:
|
||||||
Image() = default;
|
Image() = default;
|
||||||
|
Image(const std::string &textureName);
|
||||||
Image(const Texture &texture);
|
Image(const Texture &texture);
|
||||||
|
|
||||||
|
void load(const std::string &textureName);
|
||||||
void load(const Texture &texture);
|
void load(const Texture &texture);
|
||||||
|
|
||||||
const FloatRect &clipRect() const { return m_clipRect; }
|
const FloatRect &clipRect() const { return m_clipRect; }
|
||||||
|
29
include/resource/IResourceLoader.hpp
Normal file
29
include/resource/IResourceLoader.hpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: IResourceLoader.hpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 17/01/2018 19:31:24
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef IRESOURCELOADER_HPP_
|
||||||
|
#define IRESOURCELOADER_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class ResourceHandler;
|
||||||
|
|
||||||
|
class IResourceLoader {
|
||||||
|
public:
|
||||||
|
virtual ~IResourceLoader() = default;
|
||||||
|
|
||||||
|
virtual void load(const char *xmlFilename, ResourceHandler &handler) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RESOURCELOADER_HPP_
|
||||||
|
|
67
include/resource/ResourceHandler.hpp
Normal file
67
include/resource/ResourceHandler.hpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: ResourceHandler.hpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 17/01/2018 19:16:19
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef RESOURCEHANDLER_HPP_
|
||||||
|
#define RESOURCEHANDLER_HPP_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Exception.hpp"
|
||||||
|
#include "IResourceLoader.hpp"
|
||||||
|
#include "XMLFile.hpp"
|
||||||
|
|
||||||
|
class ResourceHandler {
|
||||||
|
public:
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
T &add(const std::string &name, Args &&...args) {
|
||||||
|
if(has(name)) {
|
||||||
|
throw EXCEPTION("A resource of type", typeid(T).name(), "already exists with name:", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_resources.emplace(name, std::make_shared<T>(std::forward<Args>(args)...));
|
||||||
|
|
||||||
|
return get<T>(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool has(const std::string &name) {
|
||||||
|
return m_resources.count(name) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T &get(const std::string &name) {
|
||||||
|
auto it = m_resources.find(name);
|
||||||
|
if(it == m_resources.end()) {
|
||||||
|
throw EXCEPTION("Unable to find resource with name:", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *std::static_pointer_cast<T>(it->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ResourceLoader>
|
||||||
|
static auto loadConfigFile(const char *xmlFilename) -> typename std::enable_if<std::is_base_of<IResourceLoader, ResourceLoader>::value>::type {
|
||||||
|
ResourceLoader loader;
|
||||||
|
loader.load(xmlFilename, getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
static ResourceHandler &getInstance();
|
||||||
|
|
||||||
|
static void setInstance(ResourceHandler &handler);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static ResourceHandler *instance;
|
||||||
|
|
||||||
|
std::map<std::string, std::shared_ptr<void>> m_resources;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RESOURCEHANDLER_HPP_
|
24
include/resource/TextureLoader.hpp
Normal file
24
include/resource/TextureLoader.hpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: TextureLoader.hpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 09/04/2018 01:37:23
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#ifndef TEXTURELOADER_HPP_
|
||||||
|
#define TEXTURELOADER_HPP_
|
||||||
|
|
||||||
|
#include "IResourceLoader.hpp"
|
||||||
|
|
||||||
|
class TextureLoader : public IResourceLoader {
|
||||||
|
public:
|
||||||
|
void load(const char *xmlFilename, ResourceHandler &handler);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEXTURELOADER_HPP_
|
@ -18,6 +18,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Types.hpp"
|
#include "Types.hpp"
|
||||||
|
|
||||||
@ -47,23 +48,17 @@ namespace Debug {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename... Args>
|
||||||
std::string makeString(std::stringstream &stream, T value) {
|
std::string makeString(Args &&...args) {
|
||||||
stream << value;
|
std::ostringstream stream;
|
||||||
|
std::vector<int> tmp{0, ((void)(stream << args << " "), 0)...};
|
||||||
|
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
std::string makeString(std::stringstream &stream, T value, Args... args) {
|
|
||||||
stream << value << " ";
|
|
||||||
return makeString(stream, args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void print(Args... args) {
|
void print(Args &&...args) {
|
||||||
std::stringstream stream;
|
std::cerr << makeString(std::forward<Args>(args)...) << std::endl;
|
||||||
|
|
||||||
std::cout << textColor(0, true) << makeString(stream, args...) << textColor() << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,24 +26,14 @@ class Exception {
|
|||||||
public:
|
public:
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
Exception(u16 line, std::string filename, Args... args) throw() {
|
Exception(u16 line, std::string filename, Args... args) throw() {
|
||||||
m_line = line;
|
m_errorMsg = Debug::textColor(Debug::TextColor::Red, true) + "at " + filename + ":" + std::to_string(line) + ": " + Debug::textColor(0, true) + Debug::makeString(args...) + Debug::textColor();
|
||||||
m_filename = filename;
|
|
||||||
|
|
||||||
std::stringstream stream;
|
|
||||||
m_errorMsg = Debug::makeString(stream, args...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Exception() throw() {
|
virtual std::string what() const noexcept {
|
||||||
}
|
return m_errorMsg.c_str();
|
||||||
|
|
||||||
virtual std::string what() const throw() {
|
|
||||||
return Debug::textColor(Debug::TextColor::Red, true) + "at " + m_filename + ":" + std::to_string(m_line) + ": " + Debug::textColor(0, true) + m_errorMsg.c_str() + Debug::textColor();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u16 m_line;
|
|
||||||
std::string m_filename;
|
|
||||||
|
|
||||||
std::string m_errorMsg;
|
std::string m_errorMsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class Chunk : public NonCopyable, public IDrawable {
|
|||||||
s32 m_y;
|
s32 m_y;
|
||||||
s32 m_z;
|
s32 m_z;
|
||||||
|
|
||||||
Texture m_texture;
|
Texture &m_texture;
|
||||||
|
|
||||||
using DataArray = std::array<std::array<std::array<std::unique_ptr<Block>, Chunk::depth>, Chunk::height>, Chunk::width>;
|
using DataArray = std::array<std::array<std::array<std::unique_ptr<Block>, Chunk::depth>, Chunk::height>, Chunk::width>;
|
||||||
DataArray m_data;
|
DataArray m_data;
|
||||||
|
@ -43,7 +43,7 @@ class World : public IDrawable {
|
|||||||
const s32 m_height = 4;
|
const s32 m_height = 4;
|
||||||
const s32 m_depth = 32;
|
const s32 m_depth = 32;
|
||||||
|
|
||||||
Texture m_texture;
|
Texture &m_texture;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Chunk>> m_chunks;
|
std::vector<std::unique_ptr<Chunk>> m_chunks;
|
||||||
|
|
||||||
|
5
resources/config/textures.xml
Normal file
5
resources/config/textures.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<textures>
|
||||||
|
<texture name="blocks" path="textures/blocks.png" />
|
||||||
|
<texture name="widgets" path="textures/widgets.png" />
|
||||||
|
<texture name="workbench" path="textures/workbench.png" />
|
||||||
|
</textures>
|
@ -15,6 +15,8 @@
|
|||||||
#include "Config.hpp"
|
#include "Config.hpp"
|
||||||
#include "Mouse.hpp"
|
#include "Mouse.hpp"
|
||||||
|
|
||||||
|
#include "TextureLoader.hpp"
|
||||||
|
|
||||||
#include "GameState.hpp"
|
#include "GameState.hpp"
|
||||||
|
|
||||||
void Application::init() {
|
void Application::init() {
|
||||||
@ -23,11 +25,38 @@ void Application::init() {
|
|||||||
createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, APP_NAME);
|
createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, APP_NAME);
|
||||||
m_window.setVerticalSyncEnabled(true);
|
m_window.setVerticalSyncEnabled(true);
|
||||||
|
|
||||||
|
initOpenGL();
|
||||||
|
|
||||||
Mouse::setCursorVisible(false);
|
Mouse::setCursorVisible(false);
|
||||||
Mouse::setCursorGrabbed(true);
|
Mouse::setCursorGrabbed(true);
|
||||||
|
|
||||||
m_renderer.init(m_window);
|
m_resourceHandler.loadConfigFile<TextureLoader>("resources/config/textures.xml");
|
||||||
|
|
||||||
m_stateStack.push<GameState>();
|
m_stateStack.push<GameState>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::initOpenGL() {
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
if(glewInit() != GLEW_OK) {
|
||||||
|
throw EXCEPTION("glew init failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// FIXME: Water transparency is fkin buggy...
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
// glBlendEquation(GL_FUNC_ADD);
|
||||||
|
// glEnable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
glPolygonOffset(1, 1);
|
||||||
|
|
||||||
|
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
||||||
|
|
||||||
|
glClearColor(0.196078, 0.6, 0.8, 1.0); // Skyblue
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ void CoreApplication::init() {
|
|||||||
// GamePad::init(m_keyboardHandler);
|
// GamePad::init(m_keyboardHandler);
|
||||||
|
|
||||||
ApplicationStateStack::setInstance(m_stateStack);
|
ApplicationStateStack::setInstance(m_stateStack);
|
||||||
// ResourceHandler::setInstance(m_resourceHandler);
|
ResourceHandler::setInstance(m_resourceHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CoreApplication::run() {
|
int CoreApplication::run() {
|
||||||
|
75
source/core/XMLFile.cpp
Normal file
75
source/core/XMLFile.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: XMLFile.cpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 17/01/2018 19:22:02
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include "Exception.hpp"
|
||||||
|
#include "XMLFile.hpp"
|
||||||
|
|
||||||
|
XMLFile::XMLFile(const std::string &filename) {
|
||||||
|
load(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XMLFile::load(const std::string &filename) {
|
||||||
|
int code = m_xml.LoadFile(filename.c_str());
|
||||||
|
|
||||||
|
if(code != 0) {
|
||||||
|
std::string errorString;
|
||||||
|
|
||||||
|
switch(code) {
|
||||||
|
case tinyxml2::XML_ERROR_FILE_NOT_FOUND:
|
||||||
|
errorString = "File not found.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED:
|
||||||
|
errorString = "File couldn't be opened.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_FILE_READ_ERROR:
|
||||||
|
errorString = "File read error.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_ELEMENT:
|
||||||
|
errorString = "Error while parsing element.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_ATTRIBUTE:
|
||||||
|
errorString = "Error while parsing attribute.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_TEXT:
|
||||||
|
errorString = "Error while parsing text.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_CDATA:
|
||||||
|
errorString = "Error while parsing cdata.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_COMMENT:
|
||||||
|
errorString = "Error while parsing comment.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_DECLARATION:
|
||||||
|
errorString = "Error while parsing declaration.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING_UNKNOWN:
|
||||||
|
errorString = "Parsing error: Unknown object.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_EMPTY_DOCUMENT:
|
||||||
|
errorString = "Empty document.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_MISMATCHED_ELEMENT:
|
||||||
|
errorString = "Element mismatched.";
|
||||||
|
break;
|
||||||
|
case tinyxml2::XML_ERROR_PARSING:
|
||||||
|
errorString = "Parsing error.";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errorString = "Unknown error.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw EXCEPTION("Failed to load", filename, "\nError", code, ":", errorString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* =====================================================================================
|
|
||||||
*
|
|
||||||
* Filename: Renderer.cpp
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
*
|
|
||||||
* Created: 05/06/2018 15:41:00
|
|
||||||
*
|
|
||||||
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
||||||
*
|
|
||||||
* =====================================================================================
|
|
||||||
*/
|
|
||||||
#include "Exception.hpp"
|
|
||||||
#include "OpenGL.hpp"
|
|
||||||
#include "Renderer.hpp"
|
|
||||||
|
|
||||||
void Renderer::init(Window &window) {
|
|
||||||
m_window = &window;
|
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
|
||||||
if(glewInit() != GLEW_OK) {
|
|
||||||
throw EXCEPTION("glew init failed");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// FIXME: Water transparency is fkin buggy...
|
|
||||||
glEnable(GL_BLEND);
|
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
// glBlendEquation(GL_FUNC_ADD);
|
|
||||||
// glEnable(GL_ALPHA_TEST);
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glEnable(GL_CULL_FACE);
|
|
||||||
|
|
||||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
||||||
glPolygonOffset(1, 1);
|
|
||||||
|
|
||||||
glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
|
|
||||||
|
|
||||||
glClearColor(0.196078, 0.6, 0.8, 1.0); // Skyblue
|
|
||||||
}
|
|
||||||
|
|
@ -16,14 +16,14 @@
|
|||||||
#include "Texture.hpp"
|
#include "Texture.hpp"
|
||||||
|
|
||||||
Texture::Texture(const std::string &filename) {
|
Texture::Texture(const std::string &filename) {
|
||||||
load(filename);
|
loadFromFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::~Texture() noexcept {
|
Texture::~Texture() noexcept {
|
||||||
glDeleteTextures(1, &m_texture);
|
if (m_texture) glDeleteTextures(1, &m_texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::load(const std::string &filename) {
|
void Texture::loadFromFile(const std::string &filename) {
|
||||||
SDL_Surface *surface = IMG_Load(filename.c_str());
|
SDL_Surface *surface = IMG_Load(filename.c_str());
|
||||||
if(!surface) {
|
if(!surface) {
|
||||||
throw EXCEPTION("Failed to load texture:", filename);
|
throw EXCEPTION("Failed to load texture:", filename);
|
||||||
|
@ -17,24 +17,36 @@
|
|||||||
#include "Transformable.hpp"
|
#include "Transformable.hpp"
|
||||||
|
|
||||||
void Transformable::move(float x, float y, float z) {
|
void Transformable::move(float x, float y, float z) {
|
||||||
m_modelMatrix = glm::translate(m_modelMatrix, glm::vec3{x, y, z});
|
m_position.x += x;
|
||||||
|
m_position.y += y;
|
||||||
|
m_position.z += z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transformable::setPosition(float x, float y, float z) {
|
void Transformable::setPosition(float x, float y, float z) {
|
||||||
m_modelMatrix = glm::translate(glm::mat4{1}, glm::vec3{x, y, z});
|
m_position.x = x;
|
||||||
|
m_position.y = y;
|
||||||
|
m_position.z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transformable::setScale(float factorX, float factorY, float factorZ) {
|
void Transformable::setScale(float factorX, float factorY, float factorZ) {
|
||||||
m_modelMatrix = glm::scale(m_modelMatrix, glm::vec3{factorX, factorY, factorZ});
|
m_scale.x = factorX;
|
||||||
|
m_scale.y = factorY;
|
||||||
|
m_scale.z = factorZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transformable::applyTransform(RenderStates &states) const {
|
void Transformable::applyTransform(RenderStates &states) const {
|
||||||
|
glm::mat4 &modelMatrix = const_cast<Transformable *>(this)->m_modelMatrix;
|
||||||
|
modelMatrix = glm::mat4{1};
|
||||||
|
modelMatrix = glm::translate(modelMatrix, m_position);
|
||||||
|
modelMatrix = glm::scale(modelMatrix, m_scale);
|
||||||
|
|
||||||
if (states.modelMatrix) {
|
if (states.modelMatrix) {
|
||||||
static glm::mat4 modelMatrix = *states.modelMatrix * getTransform();
|
const_cast<Transformable *>(this)->m_tmpMatrix = *states.modelMatrix * m_modelMatrix;
|
||||||
states.modelMatrix = &modelMatrix;
|
|
||||||
|
states.modelMatrix = &m_tmpMatrix;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
states.modelMatrix = &getTransform();
|
states.modelMatrix = &m_modelMatrix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,13 +16,16 @@
|
|||||||
void InventoryWidget::update(const Inventory &inventory) {
|
void InventoryWidget::update(const Inventory &inventory) {
|
||||||
m_itemWidgets.clear();
|
m_itemWidgets.clear();
|
||||||
|
|
||||||
for (u16 id : inventory.items()) {
|
u16 i = 0;
|
||||||
// TODO: Set the right position
|
for (u16 id : inventory.items())
|
||||||
m_itemWidgets.emplace_back(id);
|
m_itemWidgets.emplace_back(id).setPosition((++i - 1) * 18, 0, 0);
|
||||||
}
|
|
||||||
|
setPosition(10.5, 86.5, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryWidget::draw(RenderTarget &target, RenderStates states) const {
|
void InventoryWidget::draw(RenderTarget &target, RenderStates states) const {
|
||||||
|
applyTransform(states);
|
||||||
|
|
||||||
for (auto &it : m_itemWidgets)
|
for (auto &it : m_itemWidgets)
|
||||||
target.draw(it, states);
|
target.draw(it, states);
|
||||||
}
|
}
|
||||||
|
@ -14,18 +14,17 @@
|
|||||||
#include "ItemWidget.hpp"
|
#include "ItemWidget.hpp"
|
||||||
|
|
||||||
ItemWidget::ItemWidget(u16 id) {
|
ItemWidget::ItemWidget(u16 id) {
|
||||||
m_texture.load("textures/blocks.png");
|
m_id = id;
|
||||||
|
|
||||||
m_image.load(m_texture);
|
m_image.load("texture-blocks");
|
||||||
m_image.setClipRect(id * 16, 0, 16, 16);
|
m_image.setClipRect(m_id * 16, 0, 16, 16);
|
||||||
m_image.setScale(2.0f / 3.0f, 2.0f / 3.0f, 1.0f);
|
m_image.setScale(2.0f / 3.0f, 2.0f / 3.0f, 1.0f);
|
||||||
|
|
||||||
setPosition(10, 10, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::draw(RenderTarget &target, RenderStates states) const {
|
void ItemWidget::draw(RenderTarget &target, RenderStates states) const {
|
||||||
applyTransform(states);
|
applyTransform(states);
|
||||||
|
|
||||||
|
// FIXME: Image act weirdly when created in the constructor...
|
||||||
target.draw(m_image, states);
|
target.draw(m_image, states);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
#include "WorkbenchWidget.hpp"
|
#include "WorkbenchWidget.hpp"
|
||||||
|
|
||||||
WorkbenchWidget::WorkbenchWidget() {
|
WorkbenchWidget::WorkbenchWidget() {
|
||||||
m_backgroundTexture.load("textures/workbench.png");
|
m_background.load("texture-workbench");
|
||||||
m_background.load(m_backgroundTexture);
|
|
||||||
m_background.setClipRect(0, 0, 176, 166);
|
m_background.setClipRect(0, 0, 176, 166);
|
||||||
|
|
||||||
for (u16 i = 1 ; i < 10 ; ++i)
|
for (u16 i = 1 ; i < 10 ; ++i)
|
||||||
|
@ -19,20 +19,16 @@ static const auto backgroundX = SCREEN_WIDTH / 2 - 182 * 3 / 2;
|
|||||||
static const auto backgroundY = SCREEN_HEIGHT - 22 * 3;
|
static const auto backgroundY = SCREEN_HEIGHT - 22 * 3;
|
||||||
|
|
||||||
Hotbar::Hotbar() {
|
Hotbar::Hotbar() {
|
||||||
m_texture.load("textures/widgets.png");
|
m_background.load("texture-widgets");
|
||||||
|
|
||||||
m_background.load(m_texture);
|
|
||||||
m_background.setClipRect(0, 0, 182, 22);
|
m_background.setClipRect(0, 0, 182, 22);
|
||||||
m_background.setPosition(backgroundX, backgroundY, 0);
|
m_background.setPosition(backgroundX, backgroundY, 0);
|
||||||
m_background.setScale(3, 3, 1);
|
m_background.setScale(3, 3, 1);
|
||||||
|
|
||||||
m_cursor.load(m_texture);
|
m_cursor.load("texture-widgets");
|
||||||
m_cursor.setClipRect(0, 22, 24, 24);
|
m_cursor.setClipRect(0, 22, 24, 24);
|
||||||
m_cursor.setPosition(backgroundX - 3, backgroundY - 3, 0);
|
m_cursor.setPosition(backgroundX - 3, backgroundY - 3, 0);
|
||||||
m_cursor.setScale(3, 3, 1);
|
m_cursor.setScale(3, 3, 1);
|
||||||
|
|
||||||
m_blocksTexture.load("textures/blocks.png");
|
|
||||||
|
|
||||||
// for (u16 i = 1 ; i < 9 ; ++i)
|
// for (u16 i = 1 ; i < 9 ; ++i)
|
||||||
// addItem(i);
|
// addItem(i);
|
||||||
}
|
}
|
||||||
@ -45,6 +41,8 @@ void Hotbar::onEvent(const SDL_Event &event) {
|
|||||||
m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1;
|
m_cursorPos = (m_cursorPos == 0) ? 8 : m_cursorPos - 1;
|
||||||
|
|
||||||
m_cursor.setPosition(backgroundX - 3 + 20 * 3 * m_cursorPos, backgroundY - 3, 0);
|
m_cursor.setPosition(backgroundX - 3 + 20 * 3 * m_cursorPos, backgroundY - 3, 0);
|
||||||
|
// FIXME: Setting position resets scaling, fix that in Transformable
|
||||||
|
m_cursor.setScale(3, 3, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +61,7 @@ void Hotbar::draw(RenderTarget &target, RenderStates states) const {
|
|||||||
|
|
||||||
for (u16 i = 1 ; i < 10 ; ++i) {
|
for (u16 i = 1 ; i < 10 ; ++i) {
|
||||||
Image image;
|
Image image;
|
||||||
image.load(m_blocksTexture);
|
image.load("texture-blocks");
|
||||||
image.setClipRect(i * 16, 0, 16, 16);
|
image.setClipRect(i * 16, 0, 16, 16);
|
||||||
image.setPosition(backgroundX + 16 + 182 * 3 / 9 * (i - 1), backgroundY + 16, 0);
|
image.setPosition(backgroundX + 16 + 182 * 3 / 9 * (i - 1), backgroundY + 16, 0);
|
||||||
image.setScale(2, 2, 1);
|
image.setScale(2, 2, 1);
|
||||||
|
@ -14,24 +14,30 @@
|
|||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "Application.hpp"
|
|
||||||
#include "Config.hpp"
|
#include "Config.hpp"
|
||||||
#include "Image.hpp"
|
#include "Image.hpp"
|
||||||
|
#include "ResourceHandler.hpp"
|
||||||
#include "Vertex.hpp"
|
#include "Vertex.hpp"
|
||||||
|
|
||||||
|
Image::Image(const std::string &textureName) {
|
||||||
|
load(ResourceHandler::getInstance().get<Texture>(textureName));
|
||||||
|
}
|
||||||
|
|
||||||
Image::Image(const Texture &texture) {
|
Image::Image(const Texture &texture) {
|
||||||
load(texture);
|
load(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Image::load(const std::string &textureName) {
|
||||||
|
load(ResourceHandler::getInstance().get<Texture>(textureName));
|
||||||
|
}
|
||||||
|
|
||||||
void Image::load(const Texture &texture) {
|
void Image::load(const Texture &texture) {
|
||||||
m_texture = &texture;
|
m_texture = &texture;
|
||||||
|
|
||||||
m_width = m_texture->width();
|
m_width = m_texture->width();
|
||||||
m_height = m_texture->height();
|
m_height = m_texture->height();
|
||||||
|
|
||||||
m_clipRect = FloatRect(0, 0, m_width, m_height);
|
setClipRect(0, 0, m_width, m_height);
|
||||||
|
|
||||||
updateVertexBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::setClipRect(float x, float y, u16 width, u16 height) {
|
void Image::setClipRect(float x, float y, u16 width, u16 height) {
|
||||||
|
25
source/resource/ResourceHandler.cpp
Normal file
25
source/resource/ResourceHandler.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: ResourceHandler.cpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 17/01/2018 19:30:47
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include "ResourceHandler.hpp"
|
||||||
|
|
||||||
|
ResourceHandler *ResourceHandler::instance = nullptr;
|
||||||
|
|
||||||
|
ResourceHandler &ResourceHandler::getInstance() {
|
||||||
|
return *instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResourceHandler::setInstance(ResourceHandler &handler) {
|
||||||
|
instance = &handler;
|
||||||
|
}
|
||||||
|
|
33
source/resource/TextureLoader.cpp
Normal file
33
source/resource/TextureLoader.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* =====================================================================================
|
||||||
|
*
|
||||||
|
* Filename: TextureLoader.cpp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
*
|
||||||
|
* Created: 09/04/2018 01:38:03
|
||||||
|
*
|
||||||
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
||||||
|
*
|
||||||
|
* =====================================================================================
|
||||||
|
*/
|
||||||
|
#include "ResourceHandler.hpp"
|
||||||
|
#include "Texture.hpp"
|
||||||
|
#include "TextureLoader.hpp"
|
||||||
|
#include "XMLFile.hpp"
|
||||||
|
|
||||||
|
void TextureLoader::load(const char *xmlFilename, ResourceHandler &handler) {
|
||||||
|
XMLFile doc(xmlFilename);
|
||||||
|
|
||||||
|
tinyxml2::XMLElement *textureElement = doc.FirstChildElement("textures").FirstChildElement("texture").ToElement();
|
||||||
|
while (textureElement) {
|
||||||
|
std::string name = textureElement->Attribute("name");
|
||||||
|
std::string path = textureElement->Attribute("path");
|
||||||
|
|
||||||
|
auto &texture = handler.add<Texture>("texture-" + name);
|
||||||
|
texture.loadFromFile(path);
|
||||||
|
|
||||||
|
textureElement = textureElement->NextSiblingElement("texture");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,11 +16,10 @@
|
|||||||
|
|
||||||
#include "Camera.hpp"
|
#include "Camera.hpp"
|
||||||
#include "Config.hpp"
|
#include "Config.hpp"
|
||||||
|
#include "ResourceHandler.hpp"
|
||||||
#include "World.hpp"
|
#include "World.hpp"
|
||||||
|
|
||||||
World::World() {
|
World::World() : m_texture(ResourceHandler::getInstance().get<Texture>("texture-blocks")) {
|
||||||
m_texture.load("textures/blocks.png");
|
|
||||||
|
|
||||||
for(s32 z = 0 ; z < m_depth ; z++) {
|
for(s32 z = 0 ; z < m_depth ; z++) {
|
||||||
for(s32 y = 0 ; y < m_height ; y++) {
|
for(s32 y = 0 ; y < m_height ; y++) {
|
||||||
for(s32 x = 0 ; x < m_width ; x++) {
|
for(s32 x = 0 ; x < m_width ; x++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user