mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-10 22:23:35 +00:00
adding loading screen
This commit is contained in:
@@ -29,6 +29,27 @@ World::World(Scop::Scene& scene) : m_noisecollection(42), p_water_pipeline(std::
|
||||
|
||||
std::thread(&World::GenerateWorld, this).detach();
|
||||
|
||||
Scop::Vec2ui32 loading_size;
|
||||
Scop::Sprite& loading = scene.CreateSprite(std::make_shared<Scop::Texture>(Scop::LoadBMPFile(GetResourcesPath() / "loading.bmp", loading_size), loading_size.x, loading_size.y));
|
||||
|
||||
auto loading_update = [this, loading_size](Scop::NonOwningPtr<Scop::Scene> scene, Scop::NonOwningPtr<Scop::Sprite> sprite, Scop::Inputs& input, float delta)
|
||||
{
|
||||
if(!m_show_loading_screen && Scop::CommandLineInterface::Get().HasFlag("no-loading-screen"))
|
||||
{
|
||||
sprite->SetColor(Scop::Vec4f{ 0.0f });
|
||||
return;
|
||||
}
|
||||
Scop::Vec2f scale = Scop::Vec2f{
|
||||
static_cast<float>(Scop::ScopEngine::Get().GetWindow().GetWidth()) / static_cast<float>(loading_size.x),
|
||||
static_cast<float>(Scop::ScopEngine::Get().GetWindow().GetHeight()) / static_cast<float>(loading_size.y),
|
||||
};
|
||||
sprite->SetScale(scale);
|
||||
sprite->SetPosition(Scop::Vec2ui{ 0, 0 });
|
||||
};
|
||||
|
||||
using sprite_hook = std::function<void(Scop::NonOwningPtr<Scop::Sprite>)>;
|
||||
loading.AttachScript(std::make_shared<Scop::NativeSpriteScript>(sprite_hook{}, loading_update, sprite_hook{}));
|
||||
|
||||
auto narrator_update = [this](Scop::NonOwningPtr<Scop::Scene> scene, Scop::Inputs& input, float delta)
|
||||
{
|
||||
static bool generate = true;
|
||||
@@ -54,8 +75,8 @@ World::World(Scop::Scene& scene) : m_noisecollection(42), p_water_pipeline(std::
|
||||
};
|
||||
|
||||
m_current_chunk_position = Scop::Vec2i{
|
||||
static_cast<std::int32_t>(global_block_position.x < 0 ? std::floorf(global_block_position.x / static_cast<float>(CHUNK_SIZE.x)) : global_block_position.x / static_cast<std::int32_t>(CHUNK_SIZE.x)),
|
||||
static_cast<std::int32_t>(global_block_position.y < 0 ? std::floorf(global_block_position.y / static_cast<float>(CHUNK_SIZE.z)) : global_block_position.y / static_cast<std::int32_t>(CHUNK_SIZE.z)),
|
||||
static_cast<std::int32_t>(global_block_position.x < 0 ? std::floorf(global_block_position.x / static_cast<float>(CHUNK_SIZE.x)) : static_cast<float>(global_block_position.x) / static_cast<std::int32_t>(CHUNK_SIZE.x)),
|
||||
static_cast<std::int32_t>(global_block_position.y < 0 ? std::floorf(global_block_position.y / static_cast<float>(CHUNK_SIZE.z)) : static_cast<float>(global_block_position.y) / static_cast<std::int32_t>(CHUNK_SIZE.z)),
|
||||
};
|
||||
|
||||
if(Scop::NonOwningPtr<Chunk> current_chunk = GetChunk(m_current_chunk_position); current_chunk)
|
||||
@@ -90,7 +111,10 @@ World::World(Scop::Scene& scene) : m_noisecollection(42), p_water_pipeline(std::
|
||||
m_generation_status = GenerationState::Working;
|
||||
}
|
||||
else if(m_generation_status == GenerationState::Finished)
|
||||
{
|
||||
m_generation_status = GenerationState::Ready;
|
||||
m_show_loading_screen = false;
|
||||
}
|
||||
m_previous_chunk_position = m_current_chunk_position;
|
||||
}
|
||||
Upload();
|
||||
|
||||
@@ -63,6 +63,7 @@ class World
|
||||
std::atomic<GenerationState> m_generation_status = GenerationState::Ready;
|
||||
Scop::NonOwningPtr<Scop::Text> p_fps_text;
|
||||
std::uint32_t m_last_fps_count = 0;
|
||||
bool m_show_loading_screen = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
BIN
Resources/loading.bmp
git.filemode.normal_file
BIN
Resources/loading.bmp
git.filemode.normal_file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 MiB |
@@ -23,8 +23,8 @@ struct ViewerData
|
||||
|
||||
struct SpriteData
|
||||
{
|
||||
model_matrix: mat4[f32],
|
||||
color: vec4[f32],
|
||||
position: vec2[f32]
|
||||
}
|
||||
|
||||
external
|
||||
@@ -36,10 +36,11 @@ external
|
||||
[entry(vert)]
|
||||
fn main(input: VertIn) -> VertOut
|
||||
{
|
||||
let position: vec4[f32] = vec4[f32](input.pos.xy, 0.0, 1.0);
|
||||
input.uv.x *= -1.0;
|
||||
let output: VertOut;
|
||||
output.uv = input.uv;
|
||||
output.color = model.color;
|
||||
output.pos = viewer_data.projection_matrix * vec4[f32](input.pos.xy + model.position, 0.0, 1.0);
|
||||
output.pos = viewer_data.projection_matrix * model.model_matrix * position;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Scop
|
||||
{
|
||||
struct SpriteData
|
||||
{
|
||||
Mat4f model_matrix;
|
||||
Vec4f color;
|
||||
Vec2f position;
|
||||
};
|
||||
|
||||
struct ViewerData2D
|
||||
@@ -88,8 +88,15 @@ namespace Scop
|
||||
for(const auto& [_, sprite] : scene.GetSprites())
|
||||
{
|
||||
SpriteData sprite_data;
|
||||
sprite_data.position = Vec2f{ static_cast<float>(sprite.GetPosition().x), static_cast<float>(sprite.GetPosition().y) };
|
||||
sprite_data.color = sprite.GetColor();
|
||||
|
||||
Mat4f translation_matrix = Mat4f::Identity().ApplyTranslation(Vec3f{ Vec2f(sprite.GetPosition()), 0.0f });
|
||||
Mat4f scale_matrix = Mat4f::Identity().ApplyScale(Vec3f{ sprite.GetScale(), 1.0f });
|
||||
|
||||
sprite_data.model_matrix = Mat4f::Identity();
|
||||
sprite_data.model_matrix.ConcatenateTransform(scale_matrix);
|
||||
sprite_data.model_matrix.ConcatenateTransform(translation_matrix);
|
||||
|
||||
if(!sprite.IsSetInit())
|
||||
const_cast<Sprite&>(sprite).UpdateDescriptorSet(p_texture_set);
|
||||
const_cast<Sprite&>(sprite).Bind(frame_index, cmd);
|
||||
@@ -101,8 +108,15 @@ namespace Scop
|
||||
for(const auto& [_, text] : scene.GetTexts())
|
||||
{
|
||||
SpriteData sprite_data;
|
||||
sprite_data.position = Vec2f{ static_cast<float>(text.GetPosition().x), static_cast<float>(text.GetPosition().y) };
|
||||
sprite_data.color = text.GetColor();
|
||||
|
||||
Mat4f translation_matrix = Mat4f::Identity().ApplyTranslation(Vec3f{ Vec2f(text.GetPosition()), 0.0f });
|
||||
Mat4f scale_matrix = Mat4f::Identity().ApplyScale(Vec3f{ text.GetScale(), 1.0f });
|
||||
|
||||
sprite_data.model_matrix = Mat4f::Identity();
|
||||
sprite_data.model_matrix.ConcatenateTransform(scale_matrix);
|
||||
sprite_data.model_matrix.ConcatenateTransform(translation_matrix);
|
||||
|
||||
if(!text.IsSetInit())
|
||||
const_cast<Text&>(text).UpdateDescriptorSet(p_texture_set);
|
||||
const_cast<Text&>(text).Bind(frame_index, cmd);
|
||||
|
||||
Reference in New Issue
Block a user