Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38d4d4a
(WIP) Refactor state management
Fripe070 Mar 13, 2025
5b71b72
Slight cleanups (still broken)
Fripe070 Mar 13, 2025
f6252b7
Fix depth clipping (I spent hours realising I forgot a #define
Fripe070 Mar 14, 2025
2fe96e5
Better mouse capture toggles
Fripe070 Mar 17, 2025
1b055ad
Type nudge to stop the linter from complaining
Fripe070 Mar 17, 2025
535e91b
Super basic spdlog logging (from spdlog branch)
Fripe070 Mar 19, 2025
a779d1a
move logging to util
Fripe070 Mar 19, 2025
e94b043
I FORGOT WRAP
Fripe070 Mar 20, 2025
23fb85f
#pragma once
Fripe070 Mar 24, 2025
3db56ed
physics -> fixed
Fripe070 Mar 24, 2025
98e4a6c
Move window swap responsibility to render update
Fripe070 Mar 24, 2025
54d1278
Entirely rework resource manager, error handling, and add support for…
Fripe070 Mar 27, 2025
f71bb5f
Total resource rewrite (nonfunctional)
Fripe070 Apr 14, 2025
92a2053
Make it launch (still nonfunctional)
Fripe070 Apr 14, 2025
be39368
Remove comments of dead code
Fripe070 Apr 16, 2025
2865cc3
Error if resource manager defaults are not properly initialised
Fripe070 Apr 16, 2025
7822571
Add debug logging for resource loading operations to get an overview …
Fripe070 Apr 16, 2025
63b533b
Add embedded binary directly to sources
Fripe070 Apr 17, 2025
a9902c2
GitHub Actions (#26)
Fripe070 Apr 26, 2025
466c0ec
Fix lag by remaking skybox for new state system
Fripe070 May 2, 2025
6e672bb
Forward error in powershell build scripts
Fripe070 May 3, 2025
2541eb8
Cleaner OpenGL logging
Fripe070 May 3, 2025
1274503
Assert index in range during mesh rendering
Fripe070 May 3, 2025
72c2680
Add mesh indices to meshes
Fripe070 May 3, 2025
620cde0
FIx logging (oops)
Fripe070 May 3, 2025
0cf9e34
Make things render again
Fripe070 May 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build meson project

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
name: ${{ matrix.os }} / ${{ matrix.compiler }} (${{ matrix.build_type }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [release]
compiler: [gcc, clang]

exclude:
- os: windows-latest # Issues with meson for whatever reason
compiler: clang

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache Meson dependencies
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/subprojects/*/
key: ${{ runner.os }}-meson-${{ hashFiles('**/meson.build', '**/meson_options.txt', '**/subprojects/*.wrap') }}
restore-keys: |
${{ runner.os }}-meson-

- name: Set up C++ environment
uses: aminya/setup-cpp@v1
with:
ninja: true
meson: true
cmake: true
compiler: ${{ matrix.compiler }}

- name: Install System Dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libglu1-mesa-dev libgl1-mesa-dev

- name: Set reusable workflow outputs
id: set_outputs
shell: bash
run: |
echo "build-dir=${{ github.workspace }}/build" >> $GITHUB_OUTPUT

- name: Configure Meson
run: meson setup ${{ steps.set_outputs.outputs.build-dir }} --buildtype=${{ matrix.build_type }}

- name: Build
run: meson compile -C ${{ steps.set_outputs.outputs.build-dir }}


- name: Prepare Artifacts (Linux)
if: github.event_name == 'push' && runner.os == 'Linux'
run: |
cp ${{ steps.set_outputs.outputs.build-dir }}/lowlevelgame ${{ github.workspace }}/lowlevelgame

- name: Prepare Artifacts (Windows)
if: github.event_name == 'push' && runner.os == 'Windows'
run: |
cp ${{ steps.set_outputs.outputs.build-dir }}/lowlevelgame.exe ${{ github.workspace }}/lowlevelgame.exe

- name: Upload Build Artifacts
if: github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.os }}-${{ matrix.compiler }}-${{ matrix.build_type }}
path: |
${{ github.workspace }}/lowlevelgame
${{ github.workspace }}/lowlevelgame.exe
${{ github.workspace }}/resources/
1 change: 1 addition & 0 deletions debug.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
meson setup build/debug
meson compile -C build/debug
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
43 changes: 32 additions & 11 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ if not assimp_dep.found()
assimp_dep = cmake.subproject('assimp', options : assimp_opt).dependency('assimp')
endif

dependencies = [sdl2_dep, glew_dep, glm_dep, imgui_dep, assimp_dep]

spdlog_options = ['default_library=static', 'compile_library=true', 'werror=false', 'tests=disabled', 'external_fmt=disabled', 'std_format=disabled']
spdlog_dep = dependency('spdlog', default_options: spdlog_options)

dependencies = [sdl2_dep, glew_dep, glm_dep, imgui_dep, assimp_dep, spdlog_dep]

if host_machine.system() == 'windows'
sdl2_main_dep = dependency('sdl2main')
Expand All @@ -37,28 +41,45 @@ endif
sources = [
'src/main.cpp',
'src/engine/run.cpp',
'src/engine/logging.cpp',
'src/engine/loader/shader/shader_program.cpp',
'src/engine/loader/scene.cpp',
'src/engine/loader/texture.cpp',
'src/engine/loader/generic.cpp',
'src/engine/manager/texture.cpp',
'src/engine/manager/scene.cpp',
'src/engine/util/logging.cpp',
'src/engine/util/file.cpp',
'src/engine/resources/shader.cpp',
'src/engine/resources/texture.cpp',
'src/engine/resources/scene.cpp',
'src/engine/resources/mesh.cpp',
'src/engine/render/overlay.cpp',
'src/engine/render/frame_buffer.cpp',
'src/engine/resources/resource_manager.cpp',

'src/game/game.cpp',
'src/game/camera.cpp',
'src/game/camera_utils.cpp',
'src/game/player.cpp',
'src/game/skybox.cpp',
'src/game/gui.cpp',
]


bin2h = executable('bin2h', 'tools/bin2h.cpp')
static_binaries = [
['resources/static/error.png', 'error_png'],
['resources/static/error.obj', 'error_obj'],
['resources/static/error_shader.vert', 'error_shader_vert'],
['resources/static/error_shader.frag', 'error_shader_frag'],
]
foreach binary : static_binaries
sources += custom_target(
'embed_binary_' + binary[1],
input: binary[0],
output: binary[1] + '.h',
command: [bin2h, '@INPUT@', '@OUTPUT@'],
)
endforeach


exe = executable(
'lowlevelgame', sources,
# win_subsystem: 'windows', # Supresses stdout on Windows
include_directories : include_directories('src', 'include'),
dependencies : dependencies,
cpp_args : ['-std=c++23']
)

test('basic', exe)
1 change: 1 addition & 0 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
meson setup build/release --buildtype release --optimization=3
meson compile -C build/release
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
34 changes: 18 additions & 16 deletions resources/assets/shaders/frag.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ in vec3 Normal;
in vec3 FragPos;

struct Material {
sampler2D texture_diffuse;
sampler2D texture_specular;
float shininess;
sampler2D albedo_tex;
sampler2D normal_tex;
sampler2D roughness_tex;
sampler2D metallic_tex;
sampler2D ambientOcclusion_tex;
};

struct DirLight {
Expand Down Expand Up @@ -61,7 +63,7 @@ vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
void main()
{
// TODO: Transparency blending
if (texture(material.texture_diffuse, TexCoord).a < 0.5)
if (texture(material.albedo_tex, TexCoord).a < 0.5)
discard;

vec3 norm = normalize(Normal);
Expand All @@ -84,11 +86,11 @@ vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 1); // material.shininess);
// combine results
vec3 ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.texture_specular, TexCoord));
vec3 ambient = light.ambient * vec3(texture(material.albedo_tex, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.albedo_tex, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.roughness_tex, TexCoord));
return (ambient + diffuse + specular);
}

Expand All @@ -100,14 +102,14 @@ vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 1); // material.shininess);
// attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// combine results
vec3 ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.texture_specular, TexCoord));
vec3 ambient = light.ambient * vec3(texture(material.albedo_tex, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.albedo_tex, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.roughness_tex, TexCoord));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
Expand All @@ -122,7 +124,7 @@ vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
float diff = max(dot(normal, lightDir), 0.0);
// specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 1); // material.shininess);
// attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
Expand All @@ -131,9 +133,9 @@ vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
float epsilon = light.cutOff - light.outerCutOff;
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
// combine results
vec3 ambient = light.ambient * vec3(texture(material.texture_diffuse, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.texture_diffuse, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.texture_specular, TexCoord));
vec3 ambient = light.ambient * vec3(texture(material.albedo_tex, TexCoord));
vec3 diffuse = light.diffuse * diff * vec3(texture(material.albedo_tex, TexCoord));
vec3 specular = light.specular * spec * vec3(texture(material.roughness_tex, TexCoord));
ambient *= attenuation * intensity;
diffuse *= attenuation * intensity;
specular *= attenuation * intensity;
Expand Down
File renamed without changes.
File renamed without changes
16 changes: 16 additions & 0 deletions resources/static/error_shader.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 410 core
out vec4 oFragColor;

float hash(float x) {
return fract(sin(x) * 78657.11909);
}

void main()
{
float id = float(gl_PrimitiveID);
float r = hash(id);
float g = hash(id+1);
float b = hash(id+2);
vec3 col = (vec3(r, g, b) - 0.5) * 0.75 + 0.5;
oFragColor = vec4(col, 1.0);
}
14 changes: 14 additions & 0 deletions resources/static/error_shader.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 410 core

in vec3 iPos;

layout(std140) uniform Matrices
{
mat4 projection;
mat4 view;
};
uniform mat4 model;

void main() {
gl_Position = projection * view * vec4(vec3(model * vec4(iPos, 1.0)), 1.0);
}
16 changes: 6 additions & 10 deletions src/engine/game.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#ifndef GAME_H
#define GAME_H
#include "engine/run.h"
#pragma once
#include <SDL_events.h>

bool setupGame();
void shutdownGame();

bool setupGame(StatePackage &statePackage, SDL_Window *sdlWindow, SDL_GLContext glContext);
void shutdownGame(StatePackage &statePackage);
bool renderUpdate(double deltaTime);
bool fixedUpdate(double deltaTime);

bool renderUpdate(double deltaTime, StatePackage &statePackage);
bool fixedUpdate(double deltaTime, StatePackage &statePackage);
bool handleEvent(const SDL_Event &event);

bool handleEvent(const SDL_Event &event, StatePackage &statePackage);


#endif //GAME_H
22 changes: 0 additions & 22 deletions src/engine/loader/generic.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/engine/loader/generic.h

This file was deleted.

Loading
Loading