2023-02-12 15:25:52 -05:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2023-03-01 00:52:27 -05:00
|
|
|
#include <string>
|
|
|
|
#include <render/textures.h>
|
|
|
|
|
2023-02-13 23:37:18 -05:00
|
|
|
namespace fp {
|
|
|
|
typedef unsigned char block_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace fp::registry {
|
|
|
|
|
2023-03-01 00:52:27 -05:00
|
|
|
/**
|
|
|
|
* Bit masked enum description how the block should be treated by the renderer
|
|
|
|
*/
|
2023-02-13 23:37:18 -05:00
|
|
|
enum block_visibility {
|
2023-03-01 00:52:27 -05:00
|
|
|
// has no transparency
|
2023-02-13 23:37:18 -05:00
|
|
|
OPAQUE = 0,
|
2023-03-01 00:52:27 -05:00
|
|
|
// 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 {
|
2023-03-01 00:52:27 -05:00
|
|
|
// 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;
|
2023-03-01 00:52:27 -05:00
|
|
|
// does this block produce light?
|
|
|
|
bool produces_light = false;
|
|
|
|
// WebGL doesn't default to empty textures, use index 0 to store an empty texture
|
|
|
|
std::string textureName = "Air";
|
|
|
|
|
2023-02-13 23:37:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr block_type AIR = 0;
|
|
|
|
constexpr block_type STONE = 1;
|
|
|
|
|
|
|
|
void registerBlock(block_type id, block_properties properties);
|
2023-03-01 00:52:27 -05:00
|
|
|
void registerTexture(texture::file_texture* texture);
|
|
|
|
|
|
|
|
void setupThreads(int count = 8);
|
|
|
|
void generatePalette();
|
2023-02-13 23:37:18 -05:00
|
|
|
|
|
|
|
block_properties get(block_type id);
|
2023-03-01 00:52:27 -05:00
|
|
|
unsigned int getTextureID(const std::string& name);
|
|
|
|
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});
|
|
|
|
registerBlock(STONE, {});
|
|
|
|
}
|
|
|
|
|
2023-03-01 00:52:27 -05:00
|
|
|
inline void registerDefaultTextures() {
|
|
|
|
setupThreads();
|
|
|
|
|
|
|
|
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"});
|
|
|
|
|
|
|
|
generatePalette();
|
|
|
|
}
|
|
|
|
|
2023-02-13 23:37:18 -05:00
|
|
|
}
|
2023-02-12 15:25:52 -05:00
|
|
|
#endif //FINALPROJECT_REGISTRY_H
|