diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | assets/all_assets.cpp.in | 5 | ||||
| -rw-r--r-- | assets/meson.build | 29 | ||||
| -rw-r--r-- | default.nix | 10 | ||||
| -rw-r--r-- | flake.nix | 2 | ||||
| -rw-r--r-- | meson.build | 15 | ||||
| -rw-r--r-- | src/Assets.cpp | 44 | ||||
| -rw-r--r-- | src/Assets.hpp | 32 | ||||
| -rw-r--r-- | src/meson.build | 41 |
9 files changed, 128 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore index 7edc99a..289b94b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,8 @@ .idea .fleet +.vscode build -cmake* +result assets/generated \ No newline at end of file diff --git a/assets/all_assets.cpp.in b/assets/all_assets.cpp.in new file mode 100644 index 0000000..03b5dae --- /dev/null +++ b/assets/all_assets.cpp.in @@ -0,0 +1,5 @@ +namespace MC::Assets::Files { + +@content@ + +} \ No newline at end of file diff --git a/assets/meson.build b/assets/meson.build new file mode 100644 index 0000000..75265c2 --- /dev/null +++ b/assets/meson.build @@ -0,0 +1,29 @@ +fs = import('fs') + +asset_files = [ + 'images/atlas.ppm', + + 'shaders/block_outline.frag.glsl', 'shaders/block_outline.vert.glsl', + 'shaders/clouds.frag.glsl', 'shaders/clouds.vert.glsl', + 'shaders/image_viewer.frag.glsl', 'shaders/image_viewer.vert.glsl', + 'shaders/terrain.frag.glsl', 'shaders/terrain.vert.glsl' +] + +assets = [] +foreach file : asset_files + content = fs.read(file) + name = file.replace('/', '_') \ + .replace('.frag.glsl', '_fragment') \ + .replace('.vert.glsl', '_vertex') \ + .replace('.', '_') + + delim = 'meowcraft_asset' + + assets += f'char const* @name@ = R"@delim@(@content@)@delim@";' +endforeach + +merged_assets = '\n\n'.join(assets) + +asset_file = configure_file(input: 'all_assets.cpp.in', + output: 'all_assets.cpp', + configuration: {'content': merged_assets}) \ No newline at end of file diff --git a/default.nix b/default.nix index ec42aa9..afaf4e9 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, cmake, glew, glfw }: +{ lib, stdenv, meson, ninja, pkg-config, glew, glfw }: stdenv.mkDerivation { pname = "meowcraft"; @@ -6,14 +6,14 @@ stdenv.mkDerivation { src = ./.; - nativeBuildInputs = [ cmake ]; + nativeBuildInputs = [ meson ninja pkg-config ]; buildInputs = [ glew glfw ]; # NOTE: Don't packages usually also add the Apple SDKs as buildInputs? # Like OpenGL.framework, etc.? It seems to work without them, but I'm not sure. - cmakeFlags = [ - "-DCMAKE_BUILD_TYPE=Release" - "-DCMAKE_INSTALL_PREFIX=\${out}" + mesonFlags = [ + "--buildtype" "release" + "--prefix" "${placeholder "out"}" ]; meta = with lib; { diff --git a/flake.nix b/flake.nix index 3acf657..020ef53 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ devShells = { ${system}.default = pkgs.mkShell { buildInputs = with pkgs; [ - glfw glew cmake + pkg-config cmake meson glfw glew ]; }; }; diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..c0935c3 --- /dev/null +++ b/meson.build @@ -0,0 +1,15 @@ +project('meowcraft', 'cpp', + version : '0.0.1', + default_options : ['warning_level=3']) + +subdir('assets') +subdir('src') + +glfw = dependency('glfw3', version : '>=3.3') +glew = dependency('glew', version : '>=2.1.0') +opengl = dependency('appleframeworks', modules : ['OpenGL']) + +executable('meowcraft', + source_files + [asset_file], + dependencies : [glfw, glew, opengl], + install : true) diff --git a/src/Assets.cpp b/src/Assets.cpp index dc2495e..7cf361c 100644 --- a/src/Assets.cpp +++ b/src/Assets.cpp @@ -1,41 +1,19 @@ #include "Assets.hpp" -namespace MC::Assets { - -Char const* Shaders::terrain::vertex = -#include "../assets/generated/shaders/terrain.vert.glsl.include" -; - -Char const* Shaders::terrain::fragment = -#include "../assets/generated/shaders/terrain.frag.glsl.include" -; - -Char const* Shaders::clouds::vertex = -#include "../assets/generated/shaders/clouds.vert.glsl.include" -; +#define ASSET(ns, name, raw_name) \ + namespace ns { Char const* name = ::MC::Assets::Files::raw_name; } -Char const* Shaders::clouds::fragment = -#include "../assets/generated/shaders/clouds.frag.glsl.include" -; +#define SHADER_ASSET(name) \ + ASSET(Shaders::name, vertex, shaders_##name##_vertex) \ + ASSET(Shaders::name, fragment, shaders_##name##_fragment) -Char const* Shaders::image_viewer::vertex = -#include "../assets/generated/shaders/image_viewer.vert.glsl.include" -; - -Char const* Shaders::image_viewer::fragment = -#include "../assets/generated/shaders/image_viewer.frag.glsl.include" -; - -Char const* Shaders::block_outline::vertex = -#include "../assets/generated/shaders/block_outline.vert.glsl.include" -; +namespace MC::Assets { -Char const* Shaders::block_outline::fragment = -#include "../assets/generated/shaders/block_outline.frag.glsl.include" -; +SHADER_ASSET(terrain) +SHADER_ASSET(clouds) +SHADER_ASSET(block_outline) +SHADER_ASSET(image_viewer) -Char const* Images::atlas = -#include "../assets/generated/images/atlas.ppm.include" -; +ASSET(Images, atlas, images_atlas_ppm) } \ No newline at end of file diff --git a/src/Assets.hpp b/src/Assets.hpp index f4b2f46..0de6d90 100644 --- a/src/Assets.hpp +++ b/src/Assets.hpp @@ -2,23 +2,29 @@ #include "Common/Sizes.hpp" -namespace MC::Assets { - -namespace Shaders { - -#define MC_ASSETS_SHADER(name) namespace name { extern Char const* vertex; extern Char const* fragment; } +#define MC_DECLARE_ASSET(ns, name, raw_name) \ + namespace Files { extern char const* raw_name; } \ + namespace ns { extern Char const* name; } -MC_ASSETS_SHADER(terrain) -MC_ASSETS_SHADER(clouds) -MC_ASSETS_SHADER(block_outline) -MC_ASSETS_SHADER(image_viewer) +#define MC_DECLARE_SHADER_ASSET(name) \ + MC_DECLARE_ASSET(Shaders::name, vertex, shaders_##name##_vertex) \ + MC_DECLARE_ASSET(Shaders::name, fragment, shaders_##name##_fragment) -} +namespace MC::Assets { -namespace Images { +MC_DECLARE_SHADER_ASSET(terrain) +MC_DECLARE_SHADER_ASSET(clouds) +MC_DECLARE_SHADER_ASSET(block_outline) +MC_DECLARE_SHADER_ASSET(image_viewer) -extern Char const* atlas; +MC_DECLARE_ASSET(Images, atlas, images_atlas_ppm) } -} \ No newline at end of file +// NOTE: We need to declare dependencies both in Assets.cpp and and here +// in Assets.hpp but only because we rename the variable name from it's +// file name to a more readable name. If we didn't do that we could just +// declare the variable in the hpp file, without needing another compilation +// unit at all. +// This would work easily if there was a using x = y; directive that didn't +// just work for types but for variables as well. But there isn't, I think.. :( \ No newline at end of file diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..9a33eed --- /dev/null +++ b/src/meson.build @@ -0,0 +1,41 @@ +source_files = files([ + 'main.cpp', + 'Game.cpp', + 'Render.cpp', + 'Input.cpp', + 'Time.cpp', + 'Transform.cpp', + 'Assets.cpp', + + 'Math/AABB.cpp', + 'Math/Grid.cpp', + 'Math/Interpolation.cpp', + 'Math/Perlin.cpp', + 'Math/Random.cpp', + + 'Util/ImageViewer.cpp', + + 'GFX/Camera.cpp', + 'GFX/Mesh.cpp', + 'GFX/Resources.cpp', + 'GFX/Texture.cpp', + 'GFX/Window.cpp', + 'GFX/Util/Primitives.cpp', + 'GFX/Image/PPMParser.cpp', + 'GFX/Image/RawImage.cpp', + 'GFX/Shading/Shader.cpp', + 'GFX/Shading/Program.cpp', + 'GFX/Shading/Uniform.cpp', + + 'World/World.cpp', + 'World/Chunk.cpp', + 'World/ChunkRegistry.cpp', + 'World/Clouds.cpp', + 'World/Generation/Generator.cpp', + 'World/Generation/Lighting.cpp', + 'World/Generation/Decoration.cpp', + 'World/Generation/ChunkNeighbors.cpp', + 'World/Generation/ChunkMeshing.cpp', + + 'Entities/Player.cpp', +]) \ No newline at end of file |
