mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 14:43:34 +00:00
fixing crash issue
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
std::memset(data.data(), static_cast<std::uint32_t>(BlockType::Air), data.size() * sizeof(std::uint32_t));
|
std::memset(data.data(), static_cast<std::uint32_t>(BlockType::Air), data.size() * sizeof(std::uint32_t));
|
||||||
|
|
||||||
std::uint32_t height = std::abs(std::sin((float)pos.x / 20.0f) * std::cos((float)pos.y / 20.0f) * 60.0f) + 1;
|
std::uint32_t height = std::abs(std::sin((float)pos.x / 20.0f) * std::cos((float)pos.y / 20.0f) * 60.0f) + 1;
|
||||||
|
|
||||||
|
// Must not exceed CHUNK_SIZE.y
|
||||||
for(std::uint32_t y = 0; y < std::min(height, CHUNK_SIZE.y); y++)
|
for(std::uint32_t y = 0; y < std::min(height, CHUNK_SIZE.y); y++)
|
||||||
{
|
{
|
||||||
if(y > std::min(height, CHUNK_SIZE.y) - 2)
|
if(y > std::min(height, CHUNK_SIZE.y) - 2)
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
#include <ScopGraphics.h>
|
#include <ScopGraphics.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
std::shared_ptr<Scop::Scene> SplashScreen()
|
Scop::Scene& SplashScreen()
|
||||||
{
|
{
|
||||||
Scop::SceneDescriptor scene_desc;
|
Scop::SceneDescriptor scene_desc;
|
||||||
scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader();
|
scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader();
|
||||||
scene_desc.render_3D_enabled = false;
|
scene_desc.render_3D_enabled = false;
|
||||||
scene_desc.render_skybox_enabled = false;
|
scene_desc.render_skybox_enabled = false;
|
||||||
std::shared_ptr<Scop::Scene> scene = std::make_shared<Scop::Scene>("splash", std::move(scene_desc));
|
Scop::Scene& scene = Scop::ScopEngine::Get().CreateMainScene("splash", std::move(scene_desc));
|
||||||
|
|
||||||
Scop::Vec2ui32 splash_size;
|
Scop::Vec2ui32 splash_size;
|
||||||
Scop::Sprite& splash = scene->CreateSprite(std::make_shared<Scop::Texture>(Scop::LoadBMPFile(Scop::ScopEngine::Get().GetAssetsPath() / "Images/splashscreen.bmp", splash_size), splash_size.x, splash_size.y));
|
Scop::Sprite& splash = scene.CreateSprite(std::make_shared<Scop::Texture>(Scop::LoadBMPFile(Scop::ScopEngine::Get().GetAssetsPath() / "Images/splashscreen.bmp", splash_size), splash_size.x, splash_size.y));
|
||||||
splash.SetPosition(Scop::Vec2ui{ Scop::ScopEngine::Get().GetWindow().GetWidth() / 2 - splash_size.x / 2, Scop::ScopEngine::Get().GetWindow().GetHeight() / 2 - splash_size.y / 2 });
|
splash.SetPosition(Scop::Vec2ui{ Scop::ScopEngine::Get().GetWindow().GetWidth() / 2 - splash_size.x / 2, Scop::ScopEngine::Get().GetWindow().GetHeight() / 2 - splash_size.y / 2 });
|
||||||
|
|
||||||
auto splash_update = [splash_size](Scop::NonOwningPtr<Scop::Scene> scene, Scop::NonOwningPtr<Scop::Sprite> sprite, Scop::Inputs& input, float delta)
|
auto splash_update = [splash_size](Scop::NonOwningPtr<Scop::Scene> scene, Scop::NonOwningPtr<Scop::Sprite> sprite, Scop::Inputs& input, float delta)
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <ScopGraphics.h>
|
#include <ScopGraphics.h>
|
||||||
|
|
||||||
std::shared_ptr<Scop::Scene> SplashScreen();
|
Scop::Scene& SplashScreen();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ World::World(Scop::Scene& scene) : m_scene(scene), m_previous_chunk_position(-10
|
|||||||
m_scene.CreateNarrator().AttachScript(std::make_shared<Scop::NativeNarratorScript>(std::function<void()>{}, narrator_update, std::function<void()>{}));
|
m_scene.CreateNarrator().AttachScript(std::make_shared<Scop::NativeNarratorScript>(std::function<void()>{}, narrator_update, std::function<void()>{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::Quit() noexcept
|
||||||
|
{
|
||||||
|
m_generation_status = GenerationState::Quitting;
|
||||||
|
while(m_generation_status != GenerationState::Finished)
|
||||||
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(16ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] Scop::NonOwningPtr<Chunk> World::GetChunk(Scop::Vec2i position)
|
[[nodiscard]] Scop::NonOwningPtr<Chunk> World::GetChunk(Scop::Vec2i position)
|
||||||
{
|
{
|
||||||
auto it = m_chunks.find(position);
|
auto it = m_chunks.find(position);
|
||||||
@@ -78,12 +88,15 @@ void World::UnloadChunks()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define QUIT_CHECK() if(m_generation_status == GenerationState::Quitting) goto quit
|
||||||
void World::GenerateWorld()
|
void World::GenerateWorld()
|
||||||
{
|
{
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
QUIT_CHECK();
|
||||||
if(m_generation_status != GenerationState::Working)
|
if(m_generation_status != GenerationState::Working)
|
||||||
{
|
{
|
||||||
|
QUIT_CHECK();
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
std::this_thread::sleep_for(16ms);
|
std::this_thread::sleep_for(16ms);
|
||||||
continue;
|
continue;
|
||||||
@@ -94,6 +107,7 @@ void World::GenerateWorld()
|
|||||||
{
|
{
|
||||||
for(std::int32_t z = m_current_chunk_position.y - RENDER_DISTANCE; z <= m_current_chunk_position.y + RENDER_DISTANCE; z++)
|
for(std::int32_t z = m_current_chunk_position.y - RENDER_DISTANCE; z <= m_current_chunk_position.y + RENDER_DISTANCE; z++)
|
||||||
{
|
{
|
||||||
|
QUIT_CHECK();
|
||||||
auto res = m_chunks.try_emplace(Scop::Vec2i{ x, z }, *this, Scop::Vec2i{ x, z });
|
auto res = m_chunks.try_emplace(Scop::Vec2i{ x, z }, *this, Scop::Vec2i{ x, z });
|
||||||
if(res.second)
|
if(res.second)
|
||||||
{
|
{
|
||||||
@@ -107,6 +121,7 @@ void World::GenerateWorld()
|
|||||||
}
|
}
|
||||||
while(!mesh_generation_queue.empty())
|
while(!mesh_generation_queue.empty())
|
||||||
{
|
{
|
||||||
|
QUIT_CHECK();
|
||||||
auto chunk = mesh_generation_queue.front();
|
auto chunk = mesh_generation_queue.front();
|
||||||
mesh_generation_queue.pop();
|
mesh_generation_queue.pop();
|
||||||
chunk.get().GenerateMesh();
|
chunk.get().GenerateMesh();
|
||||||
@@ -114,6 +129,9 @@ void World::GenerateWorld()
|
|||||||
}
|
}
|
||||||
m_generation_status = GenerationState::Finished;
|
m_generation_status = GenerationState::Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quit:
|
||||||
|
m_generation_status = GenerationState::Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::Upload()
|
void World::Upload()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ enum class GenerationState: std::uint8_t
|
|||||||
{
|
{
|
||||||
Ready,
|
Ready,
|
||||||
Working,
|
Working,
|
||||||
|
Quitting,
|
||||||
Finished,
|
Finished,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ class World
|
|||||||
public:
|
public:
|
||||||
World(Scop::Scene& scene);
|
World(Scop::Scene& scene);
|
||||||
|
|
||||||
|
void Quit() noexcept;
|
||||||
|
|
||||||
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
|
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
|
||||||
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
|
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
|
||||||
[[nodiscard]] Scop::NonOwningPtr<Chunk> GetChunk(Scop::Vec2i position);
|
[[nodiscard]] Scop::NonOwningPtr<Chunk> GetChunk(Scop::Vec2i position);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ int main(int ac, char** av)
|
|||||||
{
|
{
|
||||||
Scop::ScopEngine engine(ac, av, "Vox", 0, 0, GetExecutablePath().parent_path().parent_path() / "ScopEngine/Assets");
|
Scop::ScopEngine engine(ac, av, "Vox", 0, 0, GetExecutablePath().parent_path().parent_path() / "ScopEngine/Assets");
|
||||||
|
|
||||||
std::shared_ptr<Scop::Scene> splash_scene = SplashScreen();
|
Scop::Scene& splash_scene = SplashScreen();
|
||||||
|
|
||||||
Scop::ShaderLayout shader_layout(
|
Scop::ShaderLayout shader_layout(
|
||||||
{
|
{
|
||||||
@@ -27,14 +27,15 @@ int main(int ac, char** av)
|
|||||||
main_scene_desc.fragment_shader = shader;
|
main_scene_desc.fragment_shader = shader;
|
||||||
main_scene_desc.camera = std::make_shared<Scop::FirstPerson3D>(Scop::Vec3f{ 0.0f, 20.0f, 0.0f }, 80.f);
|
main_scene_desc.camera = std::make_shared<Scop::FirstPerson3D>(Scop::Vec3f{ 0.0f, 20.0f, 0.0f }, 80.f);
|
||||||
main_scene_desc.culling = Scop::CullMode::Front;
|
main_scene_desc.culling = Scop::CullMode::Front;
|
||||||
Scop::Scene& main_scene = splash_scene->AddChildScene("main", std::move(main_scene_desc));
|
Scop::Scene& main_scene = splash_scene.AddChildScene("main", std::move(main_scene_desc));
|
||||||
|
|
||||||
Scop::Vec2ui32 skybox_size;
|
Scop::Vec2ui32 skybox_size;
|
||||||
main_scene.AddSkybox(std::make_shared<Scop::CubeTexture>(Scop::LoadBMPFile(GetResourcesPath() / "skybox.bmp", skybox_size), skybox_size.x, skybox_size.y));
|
main_scene.AddSkybox(std::make_shared<Scop::CubeTexture>(Scop::LoadBMPFile(GetResourcesPath() / "skybox.bmp", skybox_size), skybox_size.x, skybox_size.y));
|
||||||
|
|
||||||
World world(main_scene);
|
World world(main_scene);
|
||||||
|
|
||||||
engine.RegisterMainScene(splash_scene.get());
|
|
||||||
engine.Run();
|
engine.Run();
|
||||||
|
|
||||||
|
world.Quit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ namespace Scop
|
|||||||
[[nodiscard]] inline const Window& GetWindow() const noexcept { return m_window; }
|
[[nodiscard]] inline const Window& GetWindow() const noexcept { return m_window; }
|
||||||
[[nodiscard]] inline std::filesystem::path GetAssetsPath() const { return m_assets_path; }
|
[[nodiscard]] inline std::filesystem::path GetAssetsPath() const { return m_assets_path; }
|
||||||
|
|
||||||
inline void RegisterMainScene(NonOwningPtr<Scene> scene) noexcept { m_main_scene = scene; p_current_scene = m_main_scene; }
|
inline Scene& CreateMainScene(std::string_view name, SceneDescriptor desc) noexcept { p_main_scene = std::make_unique<Scene>(name, std::move(desc)); p_current_scene = p_main_scene.get(); return *p_main_scene; }
|
||||||
inline NonOwningPtr<Scene> GetRootScene() const noexcept { return m_main_scene; }
|
inline NonOwningPtr<Scene> GetRootScene() const noexcept { return p_main_scene.get(); }
|
||||||
|
|
||||||
constexpr void Quit() noexcept { m_running = false; }
|
constexpr void Quit() noexcept { m_running = false; }
|
||||||
|
|
||||||
@@ -54,10 +54,10 @@ namespace Scop
|
|||||||
#endif
|
#endif
|
||||||
CommandLineInterface m_cli;
|
CommandLineInterface m_cli;
|
||||||
Window m_window;
|
Window m_window;
|
||||||
NonOwningPtr<Scene> m_main_scene;
|
|
||||||
SceneRenderer m_scene_renderer;
|
SceneRenderer m_scene_renderer;
|
||||||
std::filesystem::path m_assets_path;
|
std::filesystem::path m_assets_path;
|
||||||
std::unique_ptr<RenderCore> p_renderer_core;
|
std::unique_ptr<RenderCore> p_renderer_core;
|
||||||
|
std::unique_ptr<Scene> p_main_scene;
|
||||||
NonOwningPtr<Scene> p_current_scene;
|
NonOwningPtr<Scene> p_current_scene;
|
||||||
bool m_running = true;
|
bool m_running = true;
|
||||||
bool m_scene_changed = false;
|
bool m_scene_changed = false;
|
||||||
|
|||||||
@@ -109,7 +109,8 @@ namespace Scop
|
|||||||
ScopEngine::~ScopEngine()
|
ScopEngine::~ScopEngine()
|
||||||
{
|
{
|
||||||
RenderCore::Get().WaitDeviceIdle();
|
RenderCore::Get().WaitDeviceIdle();
|
||||||
m_main_scene->Destroy();
|
p_main_scene->Destroy();
|
||||||
|
p_main_scene.reset();
|
||||||
m_window.Destroy();
|
m_window.Destroy();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
m_imgui.Destroy();
|
m_imgui.Destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user