Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
120,961 changes: 120,961 additions & 0 deletions Assets/Levels/LightingTest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Config/EngineConf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ display=true

; Start level is relative to the assets directory
; @see World::LoadLevel
StartLevel=Levels/EmptyLevel.json
StartLevel=Levels/LightingTest.json
WindowIcon=Icons/Fling_Logo.png

; Localization: string tables for DisplayText. See Plans/strings.md
Expand Down
2 changes: 1 addition & 1 deletion Docs/agent-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ the tests from the repository root. clang-cl configure flags are in
`Skills/building.md`.

Headless run: `Sandbox --null-render --unattended --frames 120 --seed 1` (the last log
lines print `Sandbox: 754 transforms, checksum ...` and `Fling exit: code=0 ticks=120 ...`).
lines print `Sandbox: 3266 transforms, checksum ...` and `Fling exit: code=0 ticks=120 ...`).
To see what a run did without a window, read the state (`--dump-state`), or render
offscreen and look at a PNG (`--offscreen --screenshot`; a software Vulkan driver such
as llvmpipe is enough): `Skills/testing.md`, "Seeing the game without a window".
Expand Down
8 changes: 7 additions & 1 deletion FlingEngine/Application/src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,13 @@ namespace Fling
std::optional<uint32> Engine::WindowMonitorHz() const
{
const FlingWindow* Window = m_Options.IsHeadless() ? nullptr : VulkanApp::Get().GetCurrentWindow();
return Window != nullptr ? std::optional<uint32>(Window->GetRefreshRate()) : std::nullopt;
if (Window == nullptr)
{
return std::nullopt;
}
// 0 is not a refresh rate: unknown, so the frame limiter does not take the display to pace the frames
const uint32 Hz = Window->GetRefreshRate();
return Hz > 0 ? std::optional<uint32>(Hz) : std::nullopt;
}

void Engine::UpdateFrameLimiter()
Expand Down
3 changes: 2 additions & 1 deletion FlingEngine/Graphics/inc/FlingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ namespace Fling

/**
* The refresh rate in Hz of the monitor that the window is on (the one that holds the
* window's center), from its video mode. 0 when it is not known.
* window's center), from its video mode. 0 when it is not known: a windowed window on
* Wayland, which has no position.
*/
virtual uint32 GetRefreshRate() const = 0;

Expand Down
7 changes: 7 additions & 0 deletions FlingEngine/Graphics/src/DesktopWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ namespace Fling
// A full screen window has its monitor. A windowed one has none, so find the monitor
// whose area holds the window's center; fall back to the primary monitor.
GLFWmonitor* Monitor = glfwGetWindowMonitor(m_Window);
if (Monitor == nullptr && glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
{
// Wayland does not tell a window where it is: glfwGetWindowPos is always (0, 0),
// which would pick the monitor at the origin whichever one the window is on, and
// the primary monitor is a guess too. Say that it is not known.
return 0;
}
if (Monitor == nullptr)
{
int X = 0, Y = 0, Width = 0, Height = 0;
Expand Down
8 changes: 5 additions & 3 deletions FlingEngine/Graphics/src/OffscreenSubpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ namespace Fling
VK_CHECK_RESULT(m_OffscreenFrameBuf->CreateRenderPass());
F_LOG_TRACE("Offscreen render pass created...");

// Create the descriptor pool for off screen things
uint32 DescriptorCount = 2000 * m_SwapChain->GetImageViewCount();
// Create the descriptor pool for off screen things. Each mesh holds one set, so
// MaxMeshSetsPerImage is also about how many meshes a scene can have
static constexpr uint32 MaxMeshSetsPerImage = 5000;
uint32 DescriptorCount = 2 * MaxMeshSetsPerImage * m_SwapChain->GetImageViewCount();

static std::vector<VkDescriptorPoolSize> poolSizes = {
Initializers::DescriptorPoolSize(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, DescriptorCount),
Expand All @@ -452,7 +454,7 @@ namespace Fling
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
poolInfo.poolSizeCount = static_cast<uint32>(poolSizes.size());
poolInfo.pPoolSizes = poolSizes.data();
poolInfo.maxSets = to_u32(1000 * m_SwapChain->GetImageViewCount());
poolInfo.maxSets = to_u32(MaxMeshSetsPerImage * m_SwapChain->GetImageViewCount());

if (vkCreateDescriptorPool(m_Device->GetVkDevice(), &poolInfo, nullptr, &m_DescriptorPool) != VK_SUCCESS)
{
Expand Down
12 changes: 6 additions & 6 deletions Sandbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ if( FLING_BUILD_TESTS )
if( NOT FLING_PHYSICS_PROVIDER STREQUAL "None" )
list( APPEND _LevelDumpLevels "PhysicsTest|Levels/PhysicsTest.json" )
endif()
set( _LevelDumpSha256_Default "3c8ea95f10bebb9a2572c3a245950a52f90bce9d9fe2ef1f415f70d404de593c" )
set( _LevelDumpSha256_Level_1 "4b6842bc226437aa64cff15b4c09b25b406e5c98a1333042acc117eaf56a195f" )
set( _LevelDumpSha256_Default "f0ac084fee2b20fec916bd839644407d8116aac0aba69cd44f401021c3d149dd" )
set( _LevelDumpSha256_Level_1 "f938f973a3053505f3bced9746eeec216febdbca8d14f8116d457c6c2c765601" )
set( _LevelDumpSha256_PhysicsTest "1dd37b2c3540524d014af7fcd4e160603c616e1c546c0554491c82d138311291" )
foreach( _case IN LISTS _LevelDumpLevels )
string( REPLACE "|" ";" _parts "${_case}" )
Expand Down Expand Up @@ -130,7 +130,7 @@ if( FLING_BUILD_TESTS )
WORKING_DIRECTORY "${FLING_ROOT_DIR}"
)
set_tests_properties( "Sandbox: systems move the lighting test ${_exec}" PROPERTIES
PASS_REGULAR_EXPRESSION "Sandbox: 754 transforms, checksum 47091.359022474.*Fling exit: code=0 ticks=120"
PASS_REGULAR_EXPRESSION "Sandbox: 3266 transforms, checksum 76083.598973967.*Fling exit: code=0 ticks=120"
TIMEOUT 120
)

Expand All @@ -141,7 +141,7 @@ if( FLING_BUILD_TESTS )
WORKING_DIRECTORY "${FLING_ROOT_DIR}"
)
set_tests_properties( "Sandbox: systems move the lighting test ${_exec} interpolation off" PROPERTIES
PASS_REGULAR_EXPRESSION "interpolation off \\(command line\\).*Sandbox: 754 transforms, checksum 47091.359022474.*Fling exit: code=0 ticks=120"
PASS_REGULAR_EXPRESSION "interpolation off \\(command line\\).*Sandbox: 3266 transforms, checksum 76083.598973967.*Fling exit: code=0 ticks=120"
TIMEOUT 120
)
endforeach()
Expand Down Expand Up @@ -181,7 +181,7 @@ if( FLING_BUILD_TESTS )
WORKING_DIRECTORY "${FLING_ROOT_DIR}"
)
set_tests_properties( "Sandbox: look camera replay" PROPERTIES
PASS_REGULAR_EXPRESSION "checksum 44871.195499957.*Fling exit: code=0 ticks=20"
PASS_REGULAR_EXPRESSION "checksum 65798.493022203.*Fling exit: code=0 ticks=20"
TIMEOUT 120
)
endif()
Expand Down Expand Up @@ -258,7 +258,7 @@ if( FLING_BUILD_TESTS )
# The look camera replay's 600-tick dump is pinned, as the level dumps above
set( _pin "" )
if( _name STREQUAL "time" AND FLING_PHYSICS_PROVIDER STREQUAL "Jolt" )
set( _pin -DEXPECT_SHA256=14bce16318b1fdaf22792576cbeca4d8df040b03e9c993a0322db28ae32ea5e8 )
set( _pin -DEXPECT_SHA256=126564541f04c075050d1b438d053bee8183ebb1327f42e539793ec8b2d6dab2 )
endif()
add_test( NAME "Sandbox: tick dump exec modes ${_name}"
COMMAND ${CMAKE_COMMAND}
Expand Down
11 changes: 0 additions & 11 deletions Sandbox/Gameplay/inc/SandboxGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,5 @@ namespace Sandbox
void OnStopGame(Fling::EntityStorage& t_Reg) override final;

void Shutdown(Fling::EntityStorage& t_Reg) override final;

/* Creates a 3D array of meshes */
void GenerateTestMeshes(Fling::EntityStorage& t_Reg);

void LightingTest(Fling::EntityStorage& t_Reg);

private:
void AddFloor(Fling::EntityStorage& t_Reg,
Fling::StringView t_Model,
Fling::StringView t_Mat,
const glm::vec3 t_Scale = glm::vec3(1.0f));
};
} // namespace Sandbox
135 changes: 2 additions & 133 deletions Sandbox/Gameplay/src/SandboxGame.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
#include "BallControl.h"
#include "Components/Name.hpp"
#include "Components/Transform.h"
#include "Lighting/DirectionalLight.hpp"
#include "Lighting/PointLight.hpp"
#include "FlingWindow.h"
#include "Logger.h"
#include "LookCamera.h"
#include "MeshRenderer.h"
#include "PhysicsComponents.h"
#include "Random.h"
#include "SandboxGame.h"
#include "SimRandom.h"
#include "Stasis.h"
#include "Stats.h"
#include "Strings/String.h"
#include "VulkanApp.h"
#include "World.h"
// For getting some lighting info
#include "FlingWindow.h"
#include "Lighting/DeferredLightSettings.h"
#include "Logger.h"
#include "Mover.h"

namespace Sandbox
{
Expand All @@ -33,13 +21,6 @@ namespace Sandbox
{
F_LOG_TRACE("Sandbox OnStartGame!");

// A level with physics bodies (for example Levels/PhysicsTest.json) is a
// scene of its own. Only an empty level gets the lighting test grid.
if (t_Reg.View<RigidBody>().Empty())
{
LightingTest(t_Reg);
}

// The mouse look camera, unless the level has one. Sandbox.LookCamera turns it each
// tick, Sandbox.Stasis can stop it (G), and Sandbox.LookCameraView writes the CameraView
// that the renderer draws with. It has no Transform, so the transform checksum does not change.
Expand Down Expand Up @@ -80,116 +61,4 @@ namespace Sandbox
});
F_LOG_TRACE("Sandbox: {} transforms, checksum {:.9f}", Count, Checksum);
}

void Game::AddFloor(Fling::EntityStorage& t_Reg,
const Fling::StringView t_Model,
const Fling::StringView t_Mat,
const glm::vec3 t_Scale /* = glm::vec3(1.0f) */)
{
// One call makes the entity whole: no system sees it with only some of its components
Transform t0;
t0.Position = glm::vec3(0.0f, -1.0f, 0.0f);
t0.Scale = t_Scale;
t_Reg.Create(t0, MeshRenderer(Fling::String(t_Model), Fling::String(t_Mat)));
}

void Game::LightingTest(Fling::EntityStorage& t_Reg)
{
// Simulation setup: its own stream of the run seed, so the editor or cosmetic
// code that draws from the global Random cannot change where the lights start
SimRandom Rng(Random::GetSeed(), SimRandom::StreamOf("Sandbox.LightingTest"));
auto AddRandomPointLight = [&]()
{
glm::vec3 min = {-15.0f, 0.2f, -15.0f};
glm::vec3 max = {15.0f, 1.0f, 15.0f};
const glm::vec3 startPos = Rng.Range(min, max);

Transform t0;
t0.Position = startPos;

Mover m0;
m0.TargetPos = Rng.Range(min, max);

PointLight Light;
Light.DiffuseColor = glm::vec4(Rng.Range(glm::vec3(0.0f), glm::vec3(1.0f)), 1.0f);
Light.Intensity = 5.0f;
Light.Range = 3.0f;

// One call makes the entity whole: no system sees it with only some of its components
t_Reg.Create(t0, m0, Light);
};

AddFloor(t_Reg, "Models/cube.obj", "Materials/Cobblestone.mat", glm::vec3(40.0f, 0.1f, 40.0f));

// Add a bunch of random light bois
for (size_t i = 0; i < DeferredLightSettings::MaxPointLights; i++)
{
AddRandomPointLight();
}

// Spawn a little grid of spheres
float Spacing = 1.5f;
int32 GridSize = 25;

for (int32 i = 0; i < GridSize; i++)
{
Fling::String ModelPath = "Models/sphere.obj";
Fling::String MatPath = "Materials/DeferredBronzeMat.mat";

for (int32 j = 0; j < GridSize; j++)
{
if (j == 0)
{
MatPath = "Materials/Damascus.mat";
}
else if (j == 1)
{
MatPath = "Materials/SheetMetal.mat";
}
else if (j == 2)
{
MatPath = "Materials/Snow.mat";
}
else if (j == 3)
{
MatPath = "Materials/Cobblestone.mat";
}
else if (j == 4)
{
MatPath = "Materials/DotMetal.mat";
}
else
{
MatPath = "Materials/DeferredBronzeMat.mat";
}

if (i == 1)
{
ModelPath = "Models/cube.obj";
}
else if (i == 2)
{
ModelPath = "Models/cone.obj";
}
else if (i == 3)
{
ModelPath = "Models/RoundedCube.obj";
}
else if (i == 4)
{
ModelPath = "Models/torus.obj";
}
else
{
ModelPath = "Models/sphere.obj";
}

Transform t0;
t0.Position = glm::vec3((-(float)(GridSize / 2) + ((float)i * Spacing)),
(i > GridSize / 2) ? 1.0f : 0.0f,
-(float)(GridSize / 2) + float(j) * Spacing);
t_Reg.Create(t0, MeshRenderer(ModelPath.c_str(), MatPath.c_str()), Rotator{});
}
}
}
} // namespace Sandbox