Now all configurable with json.

This commit is contained in:
Zed A. Shaw 2026-08-26 19:56:01 -04:00
parent 3041ae0172
commit d3169d3eca
25 changed files with 720 additions and 244 deletions

View file

@ -0,0 +1,74 @@
{
"material_test": {
"ambient": [0.1, 0.1, 0.1],
"shininess": 32.0,
"diffuseMap": 0,
"specularMap": 0
},
"lighting_test": {
"directional": [
{
"position": [0, 0, 0.0],
"direction":[-0.2, -1.0, -0.3],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 0.0,
"linear": 0.0,
"quadratic": 0.0,
"cut_off": 0.0,
"outer_cut_off": 0.0
}
],
"positioned": [
{
"position": [1.2, 1.0, 2.0],
"direction":[-0.2, -1.0, -0.3],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 1.0,
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
}
],
"spot": [
],
"camera": {
"position":[2.2, 1.0, 2.0],
"direction":[0.0, 0.0, -1.0],
"ambient":[0.2, 0.2, 0.2],
"diffuse":[0.8, 0.8, 0.8],
"specular":[1.0, 1.0, 1.0],
"constant": 1.0,
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
}
},
"camera_test": {
"position": [0.0, 0.0, 3.0],
"front": [0.0, 0.0, -1.0],
"up": [0.0, 1.0, 0.0],
"direction": [0.0, 0.0, 0.0],
"movement_speed": 20.0
},
"model_test": {
"directory": "assets",
"model_path": "create.obj"
},
"thing_test": {
"model": "crate",
"position": [0.0, 0.0, 0.0],
"material": "crate"
},
"shader_test": {
"vertex_path": "shaders/16-vert.glsl",
"frag_path": "shaders/16-frag.glsl"
}
}

View file

@ -0,0 +1,46 @@
#include <fuc2/testing.hpp>
#include "components.hpp"
#include <fstream>
#include "json.hpp"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace fuc2;
/*
* This also tests Mesh by using Model to load them.
*/
namespace config_tests {
void test_json_components() {
std::ifstream f{"tests/config.json"};
auto j = json::parse(f);
auto mat = j["material_test"].get<components::Material>();
CHECK(mat.ambient.x == 0.1f, "wrong value");
auto light = j["lighting_test"].get<components::Lighting>();
auto camera = j["camera_test"].get<components::Camera>();
auto model = j["model_test"].get<components::Model>();
auto thing = j["thing_test"].get<components::Thing>();
}
void test_load_json_config() {
std::ifstream f{"config.json"};
auto j = json::parse(f);
auto scene = j["scene"].get<components::Scene>();
}
fuc2::Set TESTS{
.name="config",
.options={ .fail_fast=false },
.tests={
TEST(test_json_components),
TEST(test_load_json_config),
}
};
}

View file

@ -5,6 +5,7 @@
TEST_SET(shader_tests);
TEST_SET(model_tests);
TEST_SET(config_tests);
using namespace fuc2;
@ -33,7 +34,8 @@ int main(int argc, char* argv[]) {
std::vector<fuc2::Set> tests{
shader_tests::TESTS,
model_tests::TESTS
model_tests::TESTS,
config_tests::TESTS,
};
return run_tests(tests, argc, argv);

View file

@ -2,4 +2,5 @@ fuc2_tests = files(
'main.cpp',
'shader_tests.cpp',
'model_tests.cpp',
'config_tests.cpp',
)