Skip to content

Commit

Permalink
Project structure update
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Nov 5, 2023
1 parent d67c707 commit 7730da0
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/Assets.cpp → src/assets/Assets.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "Assets.h"

#include "graphics/Texture.h"
#include "graphics/Shader.h"
#include "graphics/Font.h"
#include "../graphics/Texture.h"
#include "../graphics/Shader.h"
#include "../graphics/Font.h"

Assets::~Assets() {
for (auto& iter : shaders){
Expand Down
6 changes: 3 additions & 3 deletions src/Assets.h → src/assets/Assets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SRC_ASSETS_H_
#define SRC_ASSETS_H_
#ifndef ASSETS_ASSETS_H_
#define ASSETS_ASSETS_H_

#include <string>
#include <unordered_map>
Expand All @@ -24,4 +24,4 @@ class Assets {
void store(Font* font, std::string name);
};

#endif /* SRC_ASSETS_H_ */
#endif /* ASSETS_ASSETS_H_ */
23 changes: 18 additions & 5 deletions src/AssetsLoader.cpp → src/assets/AssetsLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ bool AssetsLoader::loadNext() {
return status;
}

#include "graphics/Shader.h"
#include "graphics/Texture.h"
#include "graphics/Font.h"
#include "../coders/png.h"
#include "../graphics/Shader.h"
#include "../graphics/Texture.h"
#include "../graphics/Font.h"

bool _load_shader(Assets* assets, const std::string& filename, const std::string& name) {
Shader* shader = load_shader(filename + ".glslv", filename + ".glslf");
Expand All @@ -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) {
Texture* texture = load_texture(filename);
Texture* texture = png::load_texture(filename);
if (texture == nullptr) {
std::cerr << "failed to load texture '" << name << "'" << std::endl;
return false;
Expand All @@ -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) {
std::vector<Texture*> pages;
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) {
std::cerr << "failed to load bitmap font '" << name << "' (missing page " << std::to_string(i) << ")" << std::endl;
return false;
Expand All @@ -77,3 +78,15 @@ void AssetsLoader::createDefaults(AssetsLoader& loader) {
loader.addLoader(ASSET_TEXTURE, _load_texture);
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");
}
7 changes: 4 additions & 3 deletions src/AssetsLoader.h → src/assets/AssetsLoader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SRC_ASSETS_LOADER_H
#define SRC_ASSETS_LOADER_H
#ifndef ASSETS_ASSETS_LOADER_H
#define ASSETS_ASSETS_LOADER_H

#include <string>
#include <functional>
Expand Down Expand Up @@ -33,6 +33,7 @@ class AssetsLoader {
bool loadNext();

static void createDefaults(AssetsLoader& loader);
static void addDefaults(AssetsLoader& loader);
};

#endif // SRC_ASSETS_LOADER_H
#endif // ASSETS_ASSETS_LOADER_H
4 changes: 2 additions & 2 deletions src/loaders/png_loading.cpp → src/coders/png.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "png_loading.h"
#include "png.h"

#include <iostream>
#include <GL/glew.h>
Expand Down Expand Up @@ -263,7 +263,7 @@ int _png_load(const char* file, int* pwidth, int* pheight){

#endif

Texture* load_texture(std::string filename){
Texture* png::load_texture(std::string filename){
int width, height;
GLuint texture = _png_load(filename.c_str(), &width, &height);
if (texture == 0){
Expand Down
12 changes: 12 additions & 0 deletions src/coders/png.h
Original file line number Diff line number Diff line change
@@ -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_ */
17 changes: 1 addition & 16 deletions src/declarations.cpp → src/definitions.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
#include "declarations.h"
#include "definitions.h"

#include "AssetsLoader.h"
#include "window/Window.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..)
void setup_definitions() {
for (size_t i = 0; i < 256; i++) {
Expand Down
3 changes: 0 additions & 3 deletions src/declarations.h → src/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#define BLOCK_METAL 15
#define BLOCK_RUST 16

class AssetsLoader;

void initialize_assets(AssetsLoader* loader);
void setup_definitions();

#endif // DECLARATIONS_H
Expand Down
2 changes: 1 addition & 1 deletion src/files/WorldFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../voxels/voxel.h"
#include "../voxels/Chunk.h"
#include "../typedefs.h"
#include "../voxmaths.h"
#include "../maths/voxmaths.h"

#include <cassert>
#include <iostream>
Expand Down
2 changes: 0 additions & 2 deletions src/graphics/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ class Texture {
void reload(unsigned char* data);
};

extern Texture* load_texture(std::string filename);

#endif /* GRAPHICS_TEXTURE_H_ */
2 changes: 1 addition & 1 deletion src/hud_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <GLFW/glfw3.h>

#include "typedefs.h"
#include "Assets.h"
#include "assets/Assets.h"
#include "graphics/Shader.h"
#include "graphics/Batch2D.h"
#include "graphics/Font.h"
Expand Down
10 changes: 0 additions & 10 deletions src/loaders/png_loading.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/voxmaths.h → src/maths/voxmaths.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SRC_VOXNATHS_H_
#define SRC_VOXNATHS_H_

#include "typedefs.h"
#include "../typedefs.h"

inline int floordiv(int a, int b) {
if (a < 0 && a % b) {
Expand Down Expand Up @@ -40,4 +40,4 @@ inline light_t light_pack(ubyte r, ubyte g, ubyte b, ubyte s) {
return r | (g << 4) | (b << 8) | (s << 12);
}

#endif // SRC_VOXNATHS_H_
#endif // SRC_VOXNATHS_H_
8 changes: 4 additions & 4 deletions src/voxel_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include "objects/Player.h"
#include "world/Level.h"
#include "world/World.h"
#include "declarations.h"
#include "Assets.h"
#include "AssetsLoader.h"
#include "definitions.h"
#include "assets/Assets.h"
#include "assets/AssetsLoader.h"
#include "world_render.h"
#include "hud_render.h"

Expand Down Expand Up @@ -76,7 +76,7 @@ Engine::Engine(const EngineSettings& settings) {
std::cout << "-- loading assets" << std::endl;
AssetsLoader loader(assets);
AssetsLoader::createDefaults(loader);
initialize_assets(&loader);
AssetsLoader::addDefaults(loader);
while (loader.hasNext()) {
if (!loader.loadNext()) {
delete assets;
Expand Down
2 changes: 1 addition & 1 deletion src/voxels/Chunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../world/LevelEvents.h"

#include "../graphics/Mesh.h"
#include "../voxmaths.h"
#include "../maths/voxmaths.h"

#include <math.h>
#include <limits.h>
Expand Down
4 changes: 2 additions & 2 deletions src/voxels/ChunksController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
lighting->buildSkyLight(chunk->x, chunk->z);
lighting->onChunkLoaded(chunk->x, chunk->z);
chunk->setLighted(true);
return false;
return true;
}
continue;
}
Expand Down Expand Up @@ -101,4 +101,4 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
}
lighting->prebuildSkyLight(chunk->x, chunk->z);
return true;
}
}
4 changes: 2 additions & 2 deletions src/voxels/ChunksStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "VoxelsVolume.h"
#include "Chunk.h"
#include "../voxmaths.h"
#include "../maths/voxmaths.h"
#include "../lighting/Lightmap.h"


Expand Down Expand Up @@ -97,4 +97,4 @@ void ChunksStorage::getVoxels(VoxelsVolume* volume) const {
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/voxels/WorldGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../maths/FastNoiseLite.h"
#include <time.h>

#include "../declarations.h"
#include "../definitions.h"

class PseudoRandom {
unsigned short seed;
Expand Down
2 changes: 1 addition & 1 deletion src/world_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "world/Level.h"
#include "world/LevelEvents.h"
#include "objects/Player.h"
#include "Assets.h"
#include "assets/Assets.h"
#include "player_control.h"

using std::shared_ptr;
Expand Down

0 comments on commit 7730da0

Please sign in to comment.