Project structure update

This commit is contained in:
MihailRis 2023-11-05 22:30:52 +03:00
parent d67c707916
commit 7730da0056
19 changed files with 58 additions and 62 deletions

View File

@ -1,8 +1,8 @@
#include "Assets.h" #include "Assets.h"
#include "graphics/Texture.h" #include "../graphics/Texture.h"
#include "graphics/Shader.h" #include "../graphics/Shader.h"
#include "graphics/Font.h" #include "../graphics/Font.h"
Assets::~Assets() { Assets::~Assets() {
for (auto& iter : shaders){ for (auto& iter : shaders){

View File

@ -1,5 +1,5 @@
#ifndef SRC_ASSETS_H_ #ifndef ASSETS_ASSETS_H_
#define SRC_ASSETS_H_ #define ASSETS_ASSETS_H_
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
@ -24,4 +24,4 @@ public:
void store(Font* font, std::string name); void store(Font* font, std::string name);
}; };
#endif /* SRC_ASSETS_H_ */ #endif /* ASSETS_ASSETS_H_ */

View File

@ -33,9 +33,10 @@ bool AssetsLoader::loadNext() {
return status; return status;
} }
#include "graphics/Shader.h" #include "../coders/png.h"
#include "graphics/Texture.h" #include "../graphics/Shader.h"
#include "graphics/Font.h" #include "../graphics/Texture.h"
#include "../graphics/Font.h"
bool _load_shader(Assets* assets, const std::string& filename, const std::string& name) { bool _load_shader(Assets* assets, const std::string& filename, const std::string& name) {
Shader* shader = load_shader(filename + ".glslv", filename + ".glslf"); Shader* shader = load_shader(filename + ".glslv", filename + ".glslf");
@ -48,7 +49,7 @@ bool _load_shader(Assets* assets, const std::string& filename, const std::string
} }
bool _load_texture(Assets* assets, const std::string& filename, const std::string& name) { bool _load_texture(Assets* assets, const std::string& filename, const std::string& name) {
Texture* texture = load_texture(filename); Texture* texture = png::load_texture(filename);
if (texture == nullptr) { if (texture == nullptr) {
std::cerr << "failed to load texture '" << name << "'" << std::endl; std::cerr << "failed to load texture '" << name << "'" << std::endl;
return false; return false;
@ -60,7 +61,7 @@ bool _load_texture(Assets* assets, const std::string& filename, const std::strin
bool _load_font(Assets* assets, const std::string& filename, const std::string& name) { bool _load_font(Assets* assets, const std::string& filename, const std::string& name) {
std::vector<Texture*> pages; std::vector<Texture*> pages;
for (size_t i = 0; i <= 4; i++) { for (size_t i = 0; i <= 4; i++) {
Texture* texture = load_texture(filename + "_" + std::to_string(i) + ".png"); Texture* texture = png::load_texture(filename + "_" + std::to_string(i) + ".png");
if (texture == nullptr) { if (texture == nullptr) {
std::cerr << "failed to load bitmap font '" << name << "' (missing page " << std::to_string(i) << ")" << std::endl; std::cerr << "failed to load bitmap font '" << name << "' (missing page " << std::to_string(i) << ")" << std::endl;
return false; return false;
@ -77,3 +78,15 @@ void AssetsLoader::createDefaults(AssetsLoader& loader) {
loader.addLoader(ASSET_TEXTURE, _load_texture); loader.addLoader(ASSET_TEXTURE, _load_texture);
loader.addLoader(ASSET_FONT, _load_font); loader.addLoader(ASSET_FONT, _load_font);
} }
void AssetsLoader::addDefaults(AssetsLoader& loader) {
loader.add(ASSET_SHADER, "res/main", "main");
loader.add(ASSET_SHADER, "res/crosshair", "crosshair");
loader.add(ASSET_SHADER, "res/lines", "lines");
loader.add(ASSET_SHADER, "res/ui", "ui");
loader.add(ASSET_TEXTURE, "res/block.png", "block");
loader.add(ASSET_TEXTURE, "res/slot.png", "slot");
loader.add(ASSET_FONT, "res/font", "normal");
}

View File

@ -1,5 +1,5 @@
#ifndef SRC_ASSETS_LOADER_H #ifndef ASSETS_ASSETS_LOADER_H
#define SRC_ASSETS_LOADER_H #define ASSETS_ASSETS_LOADER_H
#include <string> #include <string>
#include <functional> #include <functional>
@ -33,6 +33,7 @@ public:
bool loadNext(); bool loadNext();
static void createDefaults(AssetsLoader& loader); static void createDefaults(AssetsLoader& loader);
static void addDefaults(AssetsLoader& loader);
}; };
#endif // SRC_ASSETS_LOADER_H #endif // ASSETS_ASSETS_LOADER_H

View File

@ -1,4 +1,4 @@
#include "png_loading.h" #include "png.h"
#include <iostream> #include <iostream>
#include <GL/glew.h> #include <GL/glew.h>
@ -263,7 +263,7 @@ int _png_load(const char* file, int* pwidth, int* pheight){
#endif #endif
Texture* load_texture(std::string filename){ Texture* png::load_texture(std::string filename){
int width, height; int width, height;
GLuint texture = _png_load(filename.c_str(), &width, &height); GLuint texture = _png_load(filename.c_str(), &width, &height);
if (texture == 0){ if (texture == 0){

12
src/coders/png.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef CODERS_PNG_H_
#define CODERS_PNG_H_
#include <string>
class Texture;
namespace png {
extern Texture* load_texture(std::string filename);
}
#endif /* CODERS_PNG_H_ */

View File

@ -1,23 +1,8 @@
#include "declarations.h" #include "definitions.h"
#include "AssetsLoader.h"
#include "window/Window.h" #include "window/Window.h"
#include "voxels/Block.h" #include "voxels/Block.h"
void initialize_assets(AssetsLoader* loader) {
loader->add(ASSET_SHADER, "res/main", "main");
loader->add(ASSET_SHADER, "res/crosshair", "crosshair");
loader->add(ASSET_SHADER, "res/lines", "lines");
loader->add(ASSET_SHADER, "res/ui", "ui");
loader->add(ASSET_TEXTURE, "res/block.png", "block");
loader->add(ASSET_TEXTURE, "res/slot.png", "slot");
loader->add(ASSET_FONT, "res/font", "normal");
}
// All in-game definitions (blocks, items, etc..) // All in-game definitions (blocks, items, etc..)
void setup_definitions() { void setup_definitions() {
for (size_t i = 0; i < 256; i++) { for (size_t i = 0; i < 256; i++) {

View File

@ -21,9 +21,6 @@
#define BLOCK_METAL 15 #define BLOCK_METAL 15
#define BLOCK_RUST 16 #define BLOCK_RUST 16
class AssetsLoader;
void initialize_assets(AssetsLoader* loader);
void setup_definitions(); void setup_definitions();
#endif // DECLARATIONS_H #endif // DECLARATIONS_H

View File

@ -8,7 +8,7 @@
#include "../voxels/voxel.h" #include "../voxels/voxel.h"
#include "../voxels/Chunk.h" #include "../voxels/Chunk.h"
#include "../typedefs.h" #include "../typedefs.h"
#include "../voxmaths.h" #include "../maths/voxmaths.h"
#include <cassert> #include <cassert>
#include <iostream> #include <iostream>

View File

@ -16,6 +16,4 @@ public:
void reload(unsigned char* data); void reload(unsigned char* data);
}; };
extern Texture* load_texture(std::string filename);
#endif /* GRAPHICS_TEXTURE_H_ */ #endif /* GRAPHICS_TEXTURE_H_ */

View File

@ -5,7 +5,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "typedefs.h" #include "typedefs.h"
#include "Assets.h" #include "assets/Assets.h"
#include "graphics/Shader.h" #include "graphics/Shader.h"
#include "graphics/Batch2D.h" #include "graphics/Batch2D.h"
#include "graphics/Font.h" #include "graphics/Font.h"

View File

@ -1,10 +0,0 @@
#ifndef LOADERS_PNG_LOADING_H_
#define LOADERS_PNG_LOADING_H_
#include <string>
class Texture;
extern Texture* load_texture(std::string filename);
#endif /* LOADERS_PNG_LOADING_H_ */

View File

@ -1,7 +1,7 @@
#ifndef SRC_VOXNATHS_H_ #ifndef SRC_VOXNATHS_H_
#define SRC_VOXNATHS_H_ #define SRC_VOXNATHS_H_
#include "typedefs.h" #include "../typedefs.h"
inline int floordiv(int a, int b) { inline int floordiv(int a, int b) {
if (a < 0 && a % b) { if (a < 0 && a % b) {

View File

@ -29,9 +29,9 @@
#include "objects/Player.h" #include "objects/Player.h"
#include "world/Level.h" #include "world/Level.h"
#include "world/World.h" #include "world/World.h"
#include "declarations.h" #include "definitions.h"
#include "Assets.h" #include "assets/Assets.h"
#include "AssetsLoader.h" #include "assets/AssetsLoader.h"
#include "world_render.h" #include "world_render.h"
#include "hud_render.h" #include "hud_render.h"
@ -76,7 +76,7 @@ Engine::Engine(const EngineSettings& settings) {
std::cout << "-- loading assets" << std::endl; std::cout << "-- loading assets" << std::endl;
AssetsLoader loader(assets); AssetsLoader loader(assets);
AssetsLoader::createDefaults(loader); AssetsLoader::createDefaults(loader);
initialize_assets(&loader); AssetsLoader::addDefaults(loader);
while (loader.hasNext()) { while (loader.hasNext()) {
if (!loader.loadNext()) { if (!loader.loadNext()) {
delete assets; delete assets;

View File

@ -8,7 +8,7 @@
#include "../world/LevelEvents.h" #include "../world/LevelEvents.h"
#include "../graphics/Mesh.h" #include "../graphics/Mesh.h"
#include "../voxmaths.h" #include "../maths/voxmaths.h"
#include <math.h> #include <math.h>
#include <limits.h> #include <limits.h>

View File

@ -56,7 +56,7 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
lighting->buildSkyLight(chunk->x, chunk->z); lighting->buildSkyLight(chunk->x, chunk->z);
lighting->onChunkLoaded(chunk->x, chunk->z); lighting->onChunkLoaded(chunk->x, chunk->z);
chunk->setLighted(true); chunk->setLighted(true);
return false; return true;
} }
continue; continue;
} }

View File

@ -4,7 +4,7 @@
#include "VoxelsVolume.h" #include "VoxelsVolume.h"
#include "Chunk.h" #include "Chunk.h"
#include "../voxmaths.h" #include "../maths/voxmaths.h"
#include "../lighting/Lightmap.h" #include "../lighting/Lightmap.h"

View File

@ -10,7 +10,7 @@
#include "../maths/FastNoiseLite.h" #include "../maths/FastNoiseLite.h"
#include <time.h> #include <time.h>
#include "../declarations.h" #include "../definitions.h"
class PseudoRandom { class PseudoRandom {
unsigned short seed; unsigned short seed;

View File

@ -19,7 +19,7 @@
#include "world/Level.h" #include "world/Level.h"
#include "world/LevelEvents.h" #include "world/LevelEvents.h"
#include "objects/Player.h" #include "objects/Player.h"
#include "Assets.h" #include "assets/Assets.h"
#include "player_control.h" #include "player_control.h"
using std::shared_ptr; using std::shared_ptr;