From 67a0aa7a28f2a5d6d8ef44c19dbc17d4ed4d1822 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 13 Sep 2024 14:29:31 -0400 Subject: [PATCH] silly little textured blocks --- CMakeLists.txt | 2 +- include/voxel/block.h | 94 ++++++++++++++++++++++++++++++++++++++++++ include/voxel/chunk.h | 1 + include/voxel/fwdecl.h | 3 ++ src/voxel/chunk.cpp | 18 ++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 include/voxel/block.h create mode 100644 src/voxel/chunk.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a8aa3df..d81ced5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(voxel-game VERSION 0.0.3) +project(voxel-game VERSION 0.0.4) option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF) option(ENABLE_UBSAN "Enable the ub sanitizer" OFF) diff --git a/include/voxel/block.h b/include/voxel/block.h new file mode 100644 index 0000000..ddde03d --- /dev/null +++ b/include/voxel/block.h @@ -0,0 +1,94 @@ +#pragma once +/* + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef VOXEL_GAME_BLOCK_H +#define VOXEL_GAME_BLOCK_H + +#include +#include +#include + +namespace voxel +{ + enum class face_t : blt::u32 + { + NORTH, SOUTH, EAST, WEST, UP, DOWN, COUNT + }; + + constexpr inline blt::u32 face_to_int(face_t face) + { + return static_cast(face); + } + + class textured_block_t + { + public: + explicit textured_block_t(texture_id_t id) + { + for (auto& f : faces) + f = id; + } + + explicit textured_block_t(texture_id_t top, texture_id_t id) + { + for (auto& f : faces) + f = id; + faces[face_to_int(face_t::UP)] = top; + } + + explicit textured_block_t(texture_id_t top, texture_id_t bottom, texture_id_t sides) + { + for (auto& f : faces) + f = sides; + faces[face_to_int(face_t::UP)] = top; + faces[face_to_int(face_t::DOWN)] = bottom; + } + + explicit textured_block_t(std::array faces): faces(faces) + {} + + texture_id_t get_texture_facing(face_t face) + { + return faces[face_to_int(face)]; + } + + private: + std::array faces{}; + }; + + class block_model_t + { + public: + + private: + + }; + + /** + * Defines data about a block + */ + class block_t + { + public: + private: + block_id_t id; + std::variant model; + }; +} + +#endif //VOXEL_GAME_BLOCK_H diff --git a/include/voxel/chunk.h b/include/voxel/chunk.h index f10db34..f0cedd4 100644 --- a/include/voxel/chunk.h +++ b/include/voxel/chunk.h @@ -21,6 +21,7 @@ #include #include +#include #include namespace voxel diff --git a/include/voxel/fwdecl.h b/include/voxel/fwdecl.h index 9bb3d09..1dce068 100644 --- a/include/voxel/fwdecl.h +++ b/include/voxel/fwdecl.h @@ -28,8 +28,11 @@ namespace voxel inline constexpr blt::u64 CHUNK_SIZE = 32; inline const blt::u64 CHUNK_MASK = static_cast(std::log2(CHUNK_SIZE)); + using block_id_t = blt::u64; + using texture_id_t = blt::u64; using vid_t = blt::u16; + class block_t; class chunk_t; } diff --git a/src/voxel/chunk.cpp b/src/voxel/chunk.cpp new file mode 100644 index 0000000..e8ec753 --- /dev/null +++ b/src/voxel/chunk.cpp @@ -0,0 +1,18 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include \ No newline at end of file