COSC-3P98-Final-Project/include/world/registry.h

89 lines
3.1 KiB
C
Raw Normal View History

/*
* Created by Brett on 11/02/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef FINALPROJECT_REGISTRY_H
#define FINALPROJECT_REGISTRY_H
#include <string>
#include <render/textures.h>
2023-02-13 23:37:18 -05:00
namespace fp {
typedef unsigned char block_type;
}
namespace fp::registry {
/**
* Bit masked enum description how the block should be treated by the renderer
*/
2023-02-13 23:37:18 -05:00
enum block_visibility {
// has no transparency
2023-02-13 23:37:18 -05:00
OPAQUE = 0,
// opaque but texture has alpha which should be treated as 100% transparent
// this allows us to insert it into the opaque blocks render but requires us to include its neighbour's mesh
TRANSPARENT_TEXTURE = 1,
// texture is partially see-through
TRANSLUCENT = 2,
// block should be treated as 100% transparent everywhere
TRANSPARENT = 4,
2023-02-13 23:37:18 -05:00
};
struct block_properties {
// how should we handle this block? Blocks with transparent textures can be added to OPAQUE blocks
2023-02-13 23:37:18 -05:00
block_visibility visibility = OPAQUE;
// WebGL doesn't default to empty textures, use index 0 to store an empty texture
std::string textureName = "Air";
2023-03-05 00:01:54 -05:00
// does this block produce light?
bool produces_light = false;
2023-02-13 23:37:18 -05:00
};
constexpr block_type AIR = 0;
constexpr block_type STONE = 1;
2023-03-05 00:01:54 -05:00
constexpr block_type DIRT = 2;
constexpr block_type COBBLE = 3;
constexpr block_type GRASS = 4;
2023-02-13 23:37:18 -05:00
void registerBlock(block_type id, block_properties properties);
void registerTexture(texture::file_texture* texture);
2023-03-03 00:49:15 -05:00
void textureInit();
void setupTextureLoaderThreads(int count = 8);
void generateTexturePalette();
2023-03-04 23:24:36 -05:00
void cleanup();
2023-02-13 23:37:18 -05:00
2023-03-05 00:01:54 -05:00
block_properties& get(block_type id);
2023-03-04 23:24:36 -05:00
unsigned int getTextureID();
texture::texture_index getTextureIndex(const std::string& name);
2023-02-13 23:37:18 -05:00
/**
* Registers all the default blocks used by the engine
*/
inline void registerDefaultBlocks(){
registerBlock(AIR, {TRANSPARENT});
2023-03-05 00:01:54 -05:00
registerBlock(STONE, {OPAQUE, "Stone"});
registerBlock(DIRT, {OPAQUE, "Dolph"});
registerBlock(COBBLE, {OPAQUE, "Sit"});
2023-02-13 23:37:18 -05:00
}
inline void registerDefaultTextures() {
2023-03-03 00:49:15 -05:00
textureInit();
registerTexture(new texture::file_texture{"assets/textures/1676004600027876.jpg", "Stone"});
registerTexture(new texture::file_texture{"assets/textures/1668750351593692.jpg", "Dirt"});
registerTexture(new texture::file_texture{"assets/textures/1638777414645.jpg", "Dolph"});
registerTexture(new texture::file_texture{"assets/textures/1603423355849.jpg", "Sit"});
registerTexture(new texture::file_texture{"assets/textures/1603422678312.jpg", "Loser"});
registerTexture(new texture::file_texture{"assets/textures/1592244663459.png", "Frog"});
registerTexture(new texture::file_texture{"assets/textures/1592234267606.png", "Explode"});
2023-03-03 00:49:15 -05:00
setupTextureLoaderThreads();
generateTexturePalette();
}
2023-02-13 23:37:18 -05:00
}
#endif //FINALPROJECT_REGISTRY_H