rename some symbols

This commit is contained in:
bailehuni 2024-06-02 14:29:59 +01:00
parent dec129f280
commit 9c4e36ee91
5 changed files with 156 additions and 155 deletions

View File

@ -14,77 +14,79 @@
namespace engine { namespace engine {
class Application { struct AppConfiguration {
public:
struct Configuration {
bool enable_frame_limiter; bool enable_frame_limiter;
}; };
class Application {
private:
std::unique_ptr<Window> m_window;
std::unique_ptr<InputManager> m_input_manager;
std::unique_ptr<Renderer> m_renderer;
std::unordered_map<size_t, std::unique_ptr<IResourceManager>> m_resource_managers{};
std::filesystem::path m_resources_path;
std::unique_ptr<SceneManager> m_scene_manager;
AppConfiguration m_configuration;
public:
const char* const app_name; const char* const app_name;
const char* const app_version; const char* const app_version;
std::vector<Line> debug_lines{};
Application(const char* app_name, const char* app_version, gfx::GraphicsSettings graphics_settings, Configuration configuration); public:
~Application(); Application(const char* app_name, const char* app_version, gfx::GraphicsSettings graphics_settings, AppConfiguration configuration);
Application(const Application&) = delete; Application(const Application&) = delete;
~Application();
Application& operator=(const Application&) = delete; Application& operator=(const Application&) = delete;
/* resource stuff */ template <typename T>
void registerResourceManager();
template <typename T>
std::shared_ptr<T> addResource(const std::string& name, std::unique_ptr<T>&& resource);
template <typename T>
std::shared_ptr<T> getResource(const std::string& name);
void gameLoop();
void setFrameLimiter(bool on) { m_configuration.enable_frame_limiter = on; }
Window* window() { return m_window.get(); }
InputManager* input_manager() { return m_input_manager.get(); }
SceneManager* scene_manager() { return m_scene_manager.get(); }
Renderer* renderer() { return m_renderer.get(); }
std::string getResourcePath(const std::string relative_path) const { return (m_resources_path / relative_path).string(); }
private:
template <typename T>
ResourceManager<T>* getResourceManager();
};
template <typename T> template <typename T>
void RegisterResourceManager() void Application::registerResourceManager()
{ {
size_t hash = typeid(T).hash_code(); size_t hash = typeid(T).hash_code();
assert(resource_managers_.contains(hash) == false && "Registering resource manager type more than once."); assert(m_resource_managers.contains(hash) == false && "Registering resource manager type more than once.");
resource_managers_.emplace(hash, std::make_unique<ResourceManager<T>>()); m_resource_managers.emplace(hash, std::make_unique<ResourceManager<T>>());
} }
template <typename T> template <typename T>
std::shared_ptr<T> AddResource(const std::string& name, std::unique_ptr<T>&& resource) std::shared_ptr<T> Application::addResource(const std::string& name, std::unique_ptr<T>&& resource)
{ {
auto resource_manager = GetResourceManager<T>(); auto resource_manager = getResourceManager<T>();
return resource_manager->Add(name, std::move(resource)); return resource_manager->Add(name, std::move(resource));
} }
template <typename T> template <typename T>
std::shared_ptr<T> GetResource(const std::string& name) std::shared_ptr<T> Application::getResource(const std::string& name)
{ {
auto resource_manager = GetResourceManager<T>(); auto resource_manager = getResourceManager<T>();
return resource_manager->Get(name); return resource_manager->Get(name);
} }
/* methods */
void GameLoop();
void SetFrameLimiter(bool on) { configuration_.enable_frame_limiter = on; }
/* getters */
Window* window() { return window_.get(); }
InputManager* input_manager() { return input_manager_.get(); }
SceneManager* scene_manager() { return scene_manager_.get(); }
Renderer* renderer() { return renderer_.get(); }
std::string GetResourcePath(const std::string relative_path) const { return (resources_path_ / relative_path).string(); }
std::vector<Line> debug_lines{};
private:
std::unique_ptr<Window> window_;
std::unique_ptr<InputManager> input_manager_;
std::unique_ptr<Renderer> renderer_;
std::unordered_map<size_t, std::unique_ptr<IResourceManager>> resource_managers_{};
std::filesystem::path resources_path_;
// Most resources in the game are owned by component-lists found in scenes in this scene manager:
std::unique_ptr<SceneManager> scene_manager_;
Configuration configuration_;
template <typename T> template <typename T>
ResourceManager<T>* GetResourceManager() ResourceManager<T>* Application::getResourceManager()
{ {
size_t hash = typeid(T).hash_code(); size_t hash = typeid(T).hash_code();
auto it = resource_managers_.find(hash); auto it = m_resource_managers.find(hash);
if (it == resource_managers_.end()) { if (it == m_resource_managers.end()) {
throw std::runtime_error("Cannot find resource manager."); throw std::runtime_error("Cannot find resource manager.");
} }
auto ptr = it->second.get(); auto ptr = it->second.get();
@ -92,6 +94,5 @@ class Application {
assert(casted_ptr != nullptr); assert(casted_ptr != nullptr);
return casted_ptr; return casted_ptr;
} }
};
} // namespace engine } // namespace engine

View File

@ -53,33 +53,33 @@ static std::filesystem::path getResourcesPath()
static auto frametimeFromFPS(int fps) { return std::chrono::nanoseconds(1'000'000'000 / fps); } static auto frametimeFromFPS(int fps) { return std::chrono::nanoseconds(1'000'000'000 / fps); }
Application::Application(const char* appName, const char* appVersion, gfx::GraphicsSettings graphicsSettings, Configuration configuration) Application::Application(const char* appName, const char* appVersion, gfx::GraphicsSettings graphicsSettings, AppConfiguration configuration)
: app_name(appName), app_version(appVersion), configuration_(configuration) : app_name(appName), app_version(appVersion), m_configuration(configuration)
{ {
window_ = std::make_unique<Window>(appName, true, false); m_window = std::make_unique<Window>(appName, true, false);
input_manager_ = std::make_unique<InputManager>(window_.get()); m_input_manager = std::make_unique<InputManager>(m_window.get());
scene_manager_ = std::make_unique<SceneManager>(this); m_scene_manager = std::make_unique<SceneManager>(this);
// get base path for resources // get base path for resources
resources_path_ = getResourcesPath(); m_resources_path = getResourcesPath();
// register resource managers // register resource managers
RegisterResourceManager<Mesh>(); registerResourceManager<Mesh>();
RegisterResourceManager<Material>(); registerResourceManager<Material>();
RegisterResourceManager<Texture>(); registerResourceManager<Texture>();
RegisterResourceManager<Shader>(); registerResourceManager<Shader>();
RegisterResourceManager<Font>(); registerResourceManager<Font>();
im_gui_things.context = ImGui::CreateContext(); im_gui_things.context = ImGui::CreateContext();
// ImGuiIO& io = ImGui::GetIO() // ImGuiIO& io = ImGui::GetIO()
ImGui_ImplSDL2_InitForVulkan(window_->GetHandle()); ImGui_ImplSDL2_InitForVulkan(m_window->GetHandle());
renderer_ = std::make_unique<Renderer>(*this, graphicsSettings); m_renderer = std::make_unique<Renderer>(*this, graphicsSettings);
/* default fonts */ /* default fonts */
{ {
auto monoFont = std::make_unique<Font>(GetResourcePath("engine/fonts/mono.ttf")); auto monoFont = std::make_unique<Font>(getResourcePath("engine/fonts/mono.ttf"));
GetResourceManager<Font>()->AddPersistent("builtin.mono", std::move(monoFont)); getResourceManager<Font>()->AddPersistent("builtin.mono", std::move(monoFont));
} }
/* default shaders */ /* default shaders */
@ -95,8 +95,8 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
shaderSettings.write_z = true; shaderSettings.write_z = true;
shaderSettings.render_order = 0; shaderSettings.render_order = 0;
auto fancyShader = auto fancyShader =
std::make_unique<Shader>(renderer(), GetResourcePath("engine/shaders/fancy.vert"), GetResourcePath("engine/shaders/fancy.frag"), shaderSettings); std::make_unique<Shader>(renderer(), getResourcePath("engine/shaders/fancy.vert"), getResourcePath("engine/shaders/fancy.frag"), shaderSettings);
GetResourceManager<Shader>()->AddPersistent("builtin.fancy", std::move(fancyShader)); getResourceManager<Shader>()->AddPersistent("builtin.fancy", std::move(fancyShader));
} }
/* default textures */ /* default textures */
@ -108,7 +108,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest;
samplerInfo.anisotropic_filtering = false; samplerInfo.anisotropic_filtering = false;
auto whiteTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, true); auto whiteTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, true);
GetResourceManager<Texture>()->AddPersistent("builtin.white", std::move(whiteTexture)); getResourceManager<Texture>()->AddPersistent("builtin.white", std::move(whiteTexture));
} }
{ {
const uint8_t pixel[4] = {0, 0, 0, 255}; const uint8_t pixel[4] = {0, 0, 0, 255};
@ -118,7 +118,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest;
samplerInfo.anisotropic_filtering = false; samplerInfo.anisotropic_filtering = false;
auto blackTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, true); auto blackTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, true);
GetResourceManager<Texture>()->AddPersistent("builtin.black", std::move(blackTexture)); getResourceManager<Texture>()->AddPersistent("builtin.black", std::move(blackTexture));
} }
{ {
const uint8_t pixel[4] = {127, 127, 255, 255}; const uint8_t pixel[4] = {127, 127, 255, 255};
@ -128,7 +128,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest;
samplerInfo.anisotropic_filtering = false; samplerInfo.anisotropic_filtering = false;
auto normalTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, false); auto normalTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, false);
GetResourceManager<Texture>()->AddPersistent("builtin.normal", std::move(normalTexture)); getResourceManager<Texture>()->AddPersistent("builtin.normal", std::move(normalTexture));
} }
{ {
const uint8_t pixel[4] = {255, 127, 0, 255}; // AO, roughness, metallic const uint8_t pixel[4] = {255, 127, 0, 255}; // AO, roughness, metallic
@ -138,31 +138,31 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest;
samplerInfo.anisotropic_filtering = false; samplerInfo.anisotropic_filtering = false;
auto mrTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, false); auto mrTexture = std::make_unique<Texture>(renderer(), pixel, 1, 1, samplerInfo, false);
GetResourceManager<Texture>()->AddPersistent("builtin.mr", std::move(mrTexture)); getResourceManager<Texture>()->AddPersistent("builtin.mr", std::move(mrTexture));
} }
/* default materials */ /* default materials */
{ {
auto defaultMaterial = std::make_unique<Material>(renderer(), GetResource<Shader>("builtin.fancy")); auto defaultMaterial = std::make_unique<Material>(renderer(), getResource<Shader>("builtin.fancy"));
defaultMaterial->setAlbedoTexture(GetResource<Texture>("builtin.white")); defaultMaterial->setAlbedoTexture(getResource<Texture>("builtin.white"));
defaultMaterial->setNormalTexture(GetResource<Texture>("builtin.normal")); defaultMaterial->setNormalTexture(getResource<Texture>("builtin.normal"));
defaultMaterial->setOcclusionRoughnessMetallicTexture(GetResource<Texture>("builtin.mr")); defaultMaterial->setOcclusionRoughnessMetallicTexture(getResource<Texture>("builtin.mr"));
GetResourceManager<Material>()->AddPersistent("builtin.default", std::move(defaultMaterial)); getResourceManager<Material>()->AddPersistent("builtin.default", std::move(defaultMaterial));
} }
} }
Application::~Application() Application::~Application()
{ {
renderer_->GetDevice()->ShutdownImguiBackend(); m_renderer->GetDevice()->ShutdownImguiBackend();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext(im_gui_things.context); ImGui::DestroyContext(im_gui_things.context);
} }
void Application::GameLoop() void Application::gameLoop()
{ {
LOG_DEBUG("Begin game loop..."); LOG_DEBUG("Begin game loop...");
auto lastTick = window_->GetNanos(); auto lastTick = m_window->GetNanos();
std::array<float, 20> delta_times{}; std::array<float, 20> delta_times{};
struct DebugMenuState { struct DebugMenuState {
@ -174,8 +174,8 @@ void Application::GameLoop()
bool vsync = false; bool vsync = false;
bool show_info_window = false; bool show_info_window = false;
} debug_menu_state; } debug_menu_state;
debug_menu_state.enable_frame_limiter = configuration_.enable_frame_limiter; debug_menu_state.enable_frame_limiter = m_configuration.enable_frame_limiter;
switch (renderer_->GetDevice()->GetPresentMode()) { switch (m_renderer->GetDevice()->GetPresentMode()) {
case gfx::PresentMode::kDoubleBufferedNoVsync: case gfx::PresentMode::kDoubleBufferedNoVsync:
debug_menu_state.triple_buffering = false; debug_menu_state.triple_buffering = false;
debug_menu_state.vsync = false; debug_menu_state.vsync = false;
@ -194,32 +194,32 @@ void Application::GameLoop()
auto endFrame = beginFrame + frametimeFromFPS(fps_limit); auto endFrame = beginFrame + frametimeFromFPS(fps_limit);
// single-threaded game loop // single-threaded game loop
while (window_->IsRunning()) { while (m_window->IsRunning()) {
/* logic */ /* logic */
const float avg_fps = static_cast<float>(delta_times.size()) / std::accumulate(delta_times.begin(), delta_times.end(), 0.0f); const float avg_fps = static_cast<float>(delta_times.size()) / std::accumulate(delta_times.begin(), delta_times.end(), 0.0f);
Scene* scene = scene_manager_->UpdateActiveScene(window_->dt()); Scene* scene = m_scene_manager->UpdateActiveScene(m_window->dt());
uint64_t now = window_->GetNanos(); uint64_t now = m_window->GetNanos();
if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] { if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] {
lastTick = now; lastTick = now;
LOG_DEBUG("fps: {}", std::lroundf(avg_fps)); LOG_DEBUG("fps: {}", std::lroundf(avg_fps));
renderer()->GetDevice()->LogPerformanceInfo(); renderer()->GetDevice()->LogPerformanceInfo();
window_->ResetAvgFPS(); m_window->ResetAvgFPS();
} }
if (window_->GetKeyPress(inputs::Key::K_F5)) { if (m_window->GetKeyPress(inputs::Key::K_F5)) {
bool show_window = window_->MouseCaptured(); bool show_window = m_window->MouseCaptured();
debug_menu_state.menu_active = show_window; debug_menu_state.menu_active = show_window;
window_->SetRelativeMouseMode(!show_window); m_window->SetRelativeMouseMode(!show_window);
} }
if (window_->GetKeyPress(inputs::Key::K_F6)) { if (m_window->GetKeyPress(inputs::Key::K_F6)) {
debug_menu_state.show_info_window = !debug_menu_state.show_info_window; debug_menu_state.show_info_window = !debug_menu_state.show_info_window;
} }
if (window_->GetKeyPress(inputs::Key::K_L)) { if (m_window->GetKeyPress(inputs::Key::K_L)) {
debug_menu_state.enable_frame_limiter ^= true; debug_menu_state.enable_frame_limiter ^= true;
} }
@ -230,7 +230,7 @@ void Application::GameLoop()
//ImGui::ShowDemoWindow(); //ImGui::ShowDemoWindow();
// Stop mouse from moving the camera when the settings menu is open // Stop mouse from moving the camera when the settings menu is open
input_manager_->SetDeviceActive(InputDevice::kMouse, !debug_menu_state.menu_active); m_input_manager->SetDeviceActive(InputDevice::kMouse, !debug_menu_state.menu_active);
if (debug_menu_state.menu_active) { if (debug_menu_state.menu_active) {
if (ImGui::Begin("Settings", 0)) { if (ImGui::Begin("Settings", 0)) {
@ -244,10 +244,10 @@ void Application::GameLoop()
} }
if (ImGui::Checkbox("Enable vsync", &debug_menu_state.vsync)) { if (ImGui::Checkbox("Enable vsync", &debug_menu_state.vsync)) {
if (debug_menu_state.vsync) { if (debug_menu_state.vsync) {
renderer_->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedVsync); m_renderer->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedVsync);
} }
else { else {
renderer_->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedNoVsync); m_renderer->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedNoVsync);
} }
} }
if (debug_menu_state.triple_buffering) { if (debug_menu_state.triple_buffering) {
@ -256,14 +256,14 @@ void Application::GameLoop()
if (ImGui::Checkbox("Triple buffering", &debug_menu_state.triple_buffering)) { if (ImGui::Checkbox("Triple buffering", &debug_menu_state.triple_buffering)) {
if (debug_menu_state.triple_buffering) { if (debug_menu_state.triple_buffering) {
debug_menu_state.vsync = false; debug_menu_state.vsync = false;
renderer_->GetDevice()->ChangePresentMode(gfx::PresentMode::kTripleBuffered); m_renderer->GetDevice()->ChangePresentMode(gfx::PresentMode::kTripleBuffered);
} }
else { else {
if (debug_menu_state.vsync) { if (debug_menu_state.vsync) {
renderer_->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedVsync); m_renderer->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedVsync);
} }
else { else {
renderer_->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedNoVsync); m_renderer->GetDevice()->ChangePresentMode(gfx::PresentMode::kDoubleBufferedNoVsync);
} }
} }
} }
@ -506,33 +506,33 @@ void Application::GameLoop()
static_list = mesh_render_system->GetStaticRenderList(); static_list = mesh_render_system->GetStaticRenderList();
dynamic_list = mesh_render_system->GetDynamicRenderList(); dynamic_list = mesh_render_system->GetDynamicRenderList();
} }
renderer_->Render(window()->GetWindowResized(), camera_transform, static_list, dynamic_list, debug_lines); m_renderer->Render(window()->GetWindowResized(), camera_transform, static_list, dynamic_list, debug_lines);
debug_lines.clear(); // gets remade every frame :0 debug_lines.clear(); // gets remade every frame :0
/* poll events */ /* poll events */
window_->GetInputAndEvents(); m_window->GetInputAndEvents();
/* fps limiter */ /* fps limiter */
if (configuration_.enable_frame_limiter != debug_menu_state.enable_frame_limiter) { if (m_configuration.enable_frame_limiter != debug_menu_state.enable_frame_limiter) {
if (debug_menu_state.enable_frame_limiter) { if (debug_menu_state.enable_frame_limiter) {
configuration_.enable_frame_limiter = true; m_configuration.enable_frame_limiter = true;
// reset beginFrame and endFrame so the limiter doesn't hang for ages // reset beginFrame and endFrame so the limiter doesn't hang for ages
beginFrame = std::chrono::steady_clock::now(); beginFrame = std::chrono::steady_clock::now();
endFrame = beginFrame; endFrame = beginFrame;
} }
else { else {
configuration_.enable_frame_limiter = false; m_configuration.enable_frame_limiter = false;
} }
} }
if (configuration_.enable_frame_limiter) { if (m_configuration.enable_frame_limiter) {
std::this_thread::sleep_until(endFrame); std::this_thread::sleep_until(endFrame);
} }
beginFrame = endFrame; beginFrame = endFrame;
endFrame = beginFrame + frametimeFromFPS(fps_limit); endFrame = beginFrame + frametimeFromFPS(fps_limit);
delta_times[window_->GetFrameCount() % delta_times.size()] = window_->dt(); delta_times[m_window->GetFrameCount() % delta_times.size()] = m_window->dt();
} }
renderer_->GetDevice()->WaitIdle(); m_renderer->GetDevice()->WaitIdle();
} }
} // namespace engine } // namespace engine

View File

@ -7,7 +7,7 @@
namespace engine { namespace engine {
std::string ApplicationComponent::GetResourcePath(const std::string& relative_path) const { return app_.GetResourcePath(relative_path); } std::string ApplicationComponent::GetResourcePath(const std::string& relative_path) const { return app_.getResourcePath(relative_path); }
SDL_Window* ApplicationComponent::GetWindowHandle() const { SDL_Window* ApplicationComponent::GetWindowHandle() const {
return app_.window()->GetHandle(); return app_.window()->GetHandle();

View File

@ -150,7 +150,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
for (const tg::Texture& texture : model.textures) { for (const tg::Texture& texture : model.textures) {
// find the image first // find the image first
// use missing texture image by default // use missing texture image by default
textures.emplace_back(scene.app()->GetResource<Texture>("builtin.white")); textures.emplace_back(scene.app()->getResource<Texture>("builtin.white"));
if (texture.source == -1) { if (texture.source == -1) {
LOG_ERROR("A gltf file specifies a texture with no source."); LOG_ERROR("A gltf file specifies a texture with no source.");
@ -245,10 +245,10 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
} }
} }
materials.emplace_back(std::make_shared<Material>(scene.app()->renderer(), scene.app()->GetResource<Shader>("builtin.fancy"))); materials.emplace_back(std::make_shared<Material>(scene.app()->renderer(), scene.app()->getResource<Shader>("builtin.fancy")));
// base color // base color
materials.back()->setAlbedoTexture(scene.app()->GetResource<Texture>("builtin.white")); materials.back()->setAlbedoTexture(scene.app()->getResource<Texture>("builtin.white"));
if (material.pbrMetallicRoughness.baseColorTexture.index != -1) { if (material.pbrMetallicRoughness.baseColorTexture.index != -1) {
if (material.pbrMetallicRoughness.baseColorTexture.texCoord == 0) { if (material.pbrMetallicRoughness.baseColorTexture.texCoord == 0) {
materials.back()->setAlbedoTexture(textures.at(material.pbrMetallicRoughness.baseColorTexture.index)); materials.back()->setAlbedoTexture(textures.at(material.pbrMetallicRoughness.baseColorTexture.index));
@ -274,7 +274,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
// occlusion roughness metallic // occlusion roughness metallic
materials.back()->setOcclusionRoughnessMetallicTexture( materials.back()->setOcclusionRoughnessMetallicTexture(
scene.app()->GetResource<Texture>("builtin.white")); // default ao = 1.0, rough = 1.0, metal = 1.0 scene.app()->getResource<Texture>("builtin.white")); // default ao = 1.0, rough = 1.0, metal = 1.0
if (material.pbrMetallicRoughness.metallicRoughnessTexture.index != -1) { if (material.pbrMetallicRoughness.metallicRoughnessTexture.index != -1) {
if (material.pbrMetallicRoughness.metallicRoughnessTexture.texCoord == 0) { if (material.pbrMetallicRoughness.metallicRoughnessTexture.texCoord == 0) {
LOG_DEBUG("Setting occlusion roughness metallic texture!"); LOG_DEBUG("Setting occlusion roughness metallic texture!");
@ -316,7 +316,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
} }
// normal map // normal map
materials.back()->setNormalTexture(scene.app()->GetResource<Texture>("builtin.normal")); materials.back()->setNormalTexture(scene.app()->getResource<Texture>("builtin.normal"));
if (material.normalTexture.index != -1) { if (material.normalTexture.index != -1) {
if (material.normalTexture.texCoord == 0) { if (material.normalTexture.texCoord == 0) {
materials.back()->setNormalTexture(textures.at(material.normalTexture.index)); materials.back()->setNormalTexture(textures.at(material.normalTexture.index));
@ -558,7 +558,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
engine_material = materials.at(primitive.material); engine_material = materials.at(primitive.material);
} }
else { else {
engine_material = scene.app()->GetResource<Material>("builtin.default"); engine_material = scene.app()->getResource<Material>("builtin.default");
} }
// get AABB // get AABB

View File

@ -50,7 +50,7 @@ void PlayGame(GameSettings settings)
graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff; graphics_settings.msaa_level = engine::gfx::MSAALevel::kOff;
graphics_settings.enable_anisotropy = true; graphics_settings.enable_anisotropy = true;
engine::Application::Configuration configuration{}; engine::AppConfiguration configuration{};
configuration.enable_frame_limiter = settings.enable_frame_limiter; configuration.enable_frame_limiter = settings.enable_frame_limiter;
engine::Application app(PROJECT_NAME, PROJECT_VERSION, graphics_settings, configuration); engine::Application app(PROJECT_NAME, PROJECT_VERSION, graphics_settings, configuration);
@ -83,7 +83,7 @@ void PlayGame(GameSettings settings)
auto camren = main_scene->AddComponent<engine::MeshRenderableComponent>(camera_child); auto camren = main_scene->AddComponent<engine::MeshRenderableComponent>(camera_child);
camren->visible = false; camren->visible = false;
camren->mesh = GenSphereMesh(app.renderer()->GetDevice(), 1.0f, /*16*/32); camren->mesh = GenSphereMesh(app.renderer()->GetDevice(), 1.0f, /*16*/32);
camren->material = app.GetResource<engine::Material>("builtin.default"); camren->material = app.getResource<engine::Material>("builtin.default");
/* as of right now, the entity with tag 'camera' is used to build the view /* as of right now, the entity with tag 'camera' is used to build the view
* matrix */ * matrix */
@ -97,45 +97,45 @@ void PlayGame(GameSettings settings)
main_scene->AddComponent<CameraControllerComponent>(camera); main_scene->AddComponent<CameraControllerComponent>(camera);
/* floor */ /* floor */
engine::Entity floor = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/floor2.glb"), true); engine::Entity floor = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/floor2.glb"), true);
//main_scene->GetComponent<engine::MeshRenderableComponent>(main_scene->GetEntity("Cube", floor))->visible = false; //main_scene->GetComponent<engine::MeshRenderableComponent>(main_scene->GetEntity("Cube", floor))->visible = false;
engine::Entity monke = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/monke.glb"), true); engine::Entity monke = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/monke.glb"), true);
main_scene->GetComponent<engine::TransformComponent>(monke)->position.y += 10.0f; main_scene->GetComponent<engine::TransformComponent>(monke)->position.y += 10.0f;
// engine::Entity bottle = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/bottle.glb")); // engine::Entity bottle = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/bottle.glb"));
// main_scene->GetComponent<engine::TransformComponent>(bottle)->scale *= 10.0f; // main_scene->GetComponent<engine::TransformComponent>(bottle)->scale *= 10.0f;
// main_scene->GetComponent<engine::TransformComponent>(bottle)->position.x += 25.0f; // main_scene->GetComponent<engine::TransformComponent>(bottle)->position.x += 25.0f;
// main_scene->GetComponent<engine::TransformComponent>(bottle)->position.z += 5.0f; // main_scene->GetComponent<engine::TransformComponent>(bottle)->position.z += 5.0f;
engine::Entity helmet = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/DamagedHelmet.glb"), true); engine::Entity helmet = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/DamagedHelmet.glb"), true);
main_scene->GetPosition(helmet) += glm::vec3{5.0f, 5.0f, 5.0f}; main_scene->GetPosition(helmet) += glm::vec3{5.0f, 5.0f, 5.0f};
main_scene->GetScale(helmet) *= 3.0f; main_scene->GetScale(helmet) *= 3.0f;
main_scene->GetRotation(helmet) = glm::angleAxis(glm::pi<float>(), glm::vec3{ 0.0f, 0.0f, 1.0f }); main_scene->GetRotation(helmet) = glm::angleAxis(glm::pi<float>(), glm::vec3{ 0.0f, 0.0f, 1.0f });
main_scene->GetRotation(helmet) *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{ 1.0f, 0.0f, 0.0f }); main_scene->GetRotation(helmet) *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{ 1.0f, 0.0f, 0.0f });
engine::Entity toycar = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/ToyCar.glb"), true); engine::Entity toycar = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/ToyCar.glb"), true);
main_scene->GetScale(toycar) *= 150.0f; main_scene->GetScale(toycar) *= 150.0f;
main_scene->GetPosition(toycar).z -= 0.07f; main_scene->GetPosition(toycar).z -= 0.07f;
engine::Entity stairs = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/stairs.glb"), true); engine::Entity stairs = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/stairs.glb"), true);
main_scene->GetPosition(stairs) += glm::vec3{-8.0f, -5.0f, 0.1f}; main_scene->GetPosition(stairs) += glm::vec3{-8.0f, -5.0f, 0.1f};
main_scene->GetRotation(stairs) = glm::angleAxis(glm::half_pi<float>(), glm::vec3{0.0f, 0.0f, 1.0f}); main_scene->GetRotation(stairs) = glm::angleAxis(glm::half_pi<float>(), glm::vec3{0.0f, 0.0f, 1.0f});
main_scene->GetRotation(stairs) *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{1.0f, 0.0f, 0.0f}); main_scene->GetRotation(stairs) *= glm::angleAxis(glm::half_pi<float>(), glm::vec3{1.0f, 0.0f, 0.0f});
engine::Entity axes = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/MY_AXES.glb"), true); engine::Entity axes = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/MY_AXES.glb"), true);
main_scene->GetPosition(axes) += glm::vec3{-40.0f, -40.0f, 1.0f}; main_scene->GetPosition(axes) += glm::vec3{-40.0f, -40.0f, 1.0f};
engine::Entity bottle = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/bottle.glb"), true); engine::Entity bottle = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/bottle.glb"), true);
main_scene->GetPosition(bottle).y -= 10.0f; main_scene->GetPosition(bottle).y -= 10.0f;
main_scene->GetPosition(bottle).z += 2.5f; main_scene->GetPosition(bottle).z += 2.5f;
main_scene->GetScale(bottle) *= 25.0f; main_scene->GetScale(bottle) *= 25.0f;
//engine::Entity cube = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/cube.glb"), false); //engine::Entity cube = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/cube.glb"), false);
engine::Entity cube = main_scene->CreateEntity("cube", 0, glm::vec3{ 4.0f, -17.0f, 0.0f }); engine::Entity cube = main_scene->CreateEntity("cube", 0, glm::vec3{ 4.0f, -17.0f, 0.0f });
main_scene->GetTransform(cube)->is_static = false; main_scene->GetTransform(cube)->is_static = false;
auto cube_ren = main_scene->AddComponent<engine::MeshRenderableComponent>(cube); auto cube_ren = main_scene->AddComponent<engine::MeshRenderableComponent>(cube);
cube_ren->material = app.GetResource<engine::Material>("builtin.default"); cube_ren->material = app.getResource<engine::Material>("builtin.default");
cube_ren->mesh = GenCuboidMesh(app.renderer()->GetDevice(), 1.0f, 1.0f, 1.0f); cube_ren->mesh = GenCuboidMesh(app.renderer()->GetDevice(), 1.0f, 1.0f, 1.0f);
cube_ren->visible = true; cube_ren->visible = true;
auto cubeCustom = main_scene->AddComponent<engine::CustomComponent>(cube); auto cubeCustom = main_scene->AddComponent<engine::CustomComponent>(cube);
@ -148,15 +148,15 @@ void PlayGame(GameSettings settings)
}; };
engine::Entity teapot = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/teapot.glb"), true); engine::Entity teapot = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/teapot.glb"), true);
main_scene->GetPosition(teapot).y += 5.0f; main_scene->GetPosition(teapot).y += 5.0f;
main_scene->GetPosition(teapot).x -= 5.0f; main_scene->GetPosition(teapot).x -= 5.0f;
main_scene->GetScale(teapot) *= 5.0f; main_scene->GetScale(teapot) *= 5.0f;
engine::Entity tree = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/tree.glb"), true); engine::Entity tree = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/tree.glb"), true);
main_scene->GetPosition(tree) = glm::vec3{-5.0f, -5.0f, 0.0f}; main_scene->GetPosition(tree) = glm::vec3{-5.0f, -5.0f, 0.0f};
engine::Entity box = engine::util::LoadGLTF(*main_scene, app.GetResourcePath("models/box.glb"), true); engine::Entity box = engine::util::LoadGLTF(*main_scene, app.getResourcePath("models/box.glb"), true);
main_scene->GetPosition(box) = glm::vec3{ -5.0f, -17.0f, 0.1f }; main_scene->GetPosition(box) = glm::vec3{ -5.0f, -17.0f, 0.1f };
main_scene->GetScale(box) *= 10.0f; main_scene->GetScale(box) *= 10.0f;
main_scene->GetRotation(box) = glm::angleAxis(glm::pi<float>() * 0.0f, glm::vec3{ 0.0f, 0.0f, 1.0f }); main_scene->GetRotation(box) = glm::angleAxis(glm::pi<float>() * 0.0f, glm::vec3{ 0.0f, 0.0f, 1.0f });
@ -167,5 +167,5 @@ void PlayGame(GameSettings settings)
main_scene->GetSystem<CameraControllerSystem>()->next_scene_ = start_scene; main_scene->GetSystem<CameraControllerSystem>()->next_scene_ = start_scene;
app.scene_manager()->SetActiveScene(main_scene); app.scene_manager()->SetActiveScene(main_scene);
app.GameLoop(); app.gameLoop();
} }