initial commit

This commit is contained in:
2025-05-01 23:03:47 +02:00
commit a23fbff52a
200 changed files with 434542 additions and 0 deletions

118
Application/ScriptSubRoutines.cpp git.filemode.normal_file
View File

@@ -0,0 +1,118 @@
#include <ScriptSubRoutines.h>
constexpr const float SPEED = 40.0f;
void WireframeHandler(Scop::NonOwningPtr<Scop::Scene> scene, Scop::Inputs& inputs)
{
static bool key_pressed_last_frame = false;
if(inputs.IsKeyPressed(SDL_SCANCODE_F))
key_pressed_last_frame = true;
else if(key_pressed_last_frame)
{
scene->GetForwardData().wireframe = !scene->GetForwardData().wireframe;
Scop::RenderCore::Get().WaitDeviceIdle();
scene->GetPipeline().Destroy();
key_pressed_last_frame = false;
}
static Scop::Vec3f rotations{ 0.0f, 0.0f, 0.0f };
}
void MovementHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta)
{
static Scop::Vec3f position{ 0.0f, 0.0f, 0.0f };
if(inputs.IsKeyPressed(SDL_SCANCODE_I))
position.x += SPEED * delta;
if(inputs.IsKeyPressed(SDL_SCANCODE_K))
position.x -= SPEED * delta;
if(inputs.IsKeyPressed(SDL_SCANCODE_L))
position.z += SPEED * delta;
if(inputs.IsKeyPressed(SDL_SCANCODE_J))
position.z -= SPEED * delta;
if(inputs.IsKeyPressed(SDL_SCANCODE_U))
position.y += SPEED * delta;
if(inputs.IsKeyPressed(SDL_SCANCODE_O))
position.y -= SPEED * delta;
actor->SetPosition(position);
}
void ColorsTransitionHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data)
{
static bool colors_transition = false;
static bool colors_key_pressed_last_frame = false;
static std::uint8_t colors_transition_way = 0;
if(inputs.IsKeyPressed(SDL_SCANCODE_C) && !colors_transition)
colors_key_pressed_last_frame = true;
else if(colors_key_pressed_last_frame)
{
colors_key_pressed_last_frame = false;
colors_transition = true;
colors_transition_way = (data.dissolve_black_white_colors_factor >= 0.5f);
}
if(colors_transition)
{
if(colors_transition_way == 1)
{
data.dissolve_black_white_colors_factor -= 1.0f * delta;
colors_transition = (data.dissolve_black_white_colors_factor > 0.0f);
}
else
{
data.dissolve_black_white_colors_factor += 1.0f * delta;
colors_transition = (data.dissolve_black_white_colors_factor < 1.0f);
}
}
static bool normals_transition = false;
static bool normals_key_pressed_last_frame = false;
static std::uint8_t normals_transition_way = 0;
if(inputs.IsKeyPressed(SDL_SCANCODE_N) && !normals_transition)
normals_key_pressed_last_frame = true;
else if(normals_key_pressed_last_frame)
{
normals_key_pressed_last_frame = false;
normals_transition = true;
normals_transition_way = (data.dissolve_normals_colors_factor >= 0.5f);
}
if(normals_transition)
{
if(normals_transition_way == 1)
{
data.dissolve_normals_colors_factor -= 1.0f * delta;
normals_transition = (data.dissolve_normals_colors_factor > 0.0f);
}
else
{
data.dissolve_normals_colors_factor += 1.0f * delta;
normals_transition = (data.dissolve_normals_colors_factor < 1.0f);
}
}
}
void TextureTransitionHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data)
{
static bool texture_transition = false;
static bool key_pressed_last_frame = false;
static std::uint8_t transition_way = 0;
if(inputs.IsKeyPressed(SDL_SCANCODE_T) && !texture_transition)
key_pressed_last_frame = true;
else if(key_pressed_last_frame)
{
texture_transition = true;
key_pressed_last_frame = false;
transition_way = (data.dissolve_texture_factor >= 0.5f);
}
if(texture_transition)
{
if(transition_way == 1)
{
data.dissolve_texture_factor -= 1.0f * delta;
texture_transition = (data.dissolve_texture_factor > 0.0f);
}
else
{
data.dissolve_texture_factor += 1.0f * delta;
texture_transition = (data.dissolve_texture_factor < 1.0f);
}
}
}

12
Application/ScriptSubRoutines.h git.filemode.normal_file
View File

@@ -0,0 +1,12 @@
#ifndef __SCRIPT_SUB_ROUTINES__
#define __SCRIPT_SUB_ROUTINES__
#include <ScopCore.h>
#include <ScopGraphics.h>
void WireframeHandler(Scop::NonOwningPtr<Scop::Scene> scene, Scop::Inputs& inputs);
void MovementHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta);
void ColorsTransitionHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data);
void TextureTransitionHandler(Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& inputs, float delta, Scop::MaterialData& data);
#endif

40
Application/Splash.cpp git.filemode.normal_file
View File

@@ -0,0 +1,40 @@
#include <ScopCore.h>
#include <ScopGraphics.h>
#include <thread>
std::shared_ptr<Scop::Scene> SplashScreen()
{
Scop::SceneDescriptor scene_desc;
scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader();
scene_desc.render_3D_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::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));
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)
{
using namespace std::chrono_literals;
if(Scop::CommandLineInterface::Get().HasFlag("skip-splash"))
scene->SwitchToChild("main");
static float x = 0.02f;
Scop::Vec4f color = sprite->GetColor();
color.w = std::abs(std::sin(x)) * 1.1;
x += 0.02f;
sprite->SetColor(color);
sprite->SetPosition(Scop::Vec2ui{ (Scop::ScopEngine::Get().GetWindow().GetWidth() >> 1) - (splash_size.x >> 1), (Scop::ScopEngine::Get().GetWindow().GetHeight() >> 1) - (splash_size.y >> 1) });
if(color.w <= 0.02f)
scene->SwitchToChild("main");
std::this_thread::sleep_for(33ms); // 30fps
};
using sprite_hook = std::function<void(Scop::NonOwningPtr<Scop::Sprite>)>;
splash.AttachScript(std::make_shared<Scop::NativeSpriteScript>(sprite_hook{}, splash_update, sprite_hook{}));
return scene;
}

8
Application/Splash.h git.filemode.normal_file
View File

@@ -0,0 +1,8 @@
#ifndef __SCOP_SPLASH__
#define __SCOP_SPLASH__
#include <ScopGraphics.h>
std::shared_ptr<Scop::Scene> SplashScreen();
#endif

77
Application/main.cpp git.filemode.normal_file
View File

@@ -0,0 +1,77 @@
#include <ScopCore.h>
#include <ScopGraphics.h>
#include <ScriptSubRoutines.h>
#include <Splash.h>
#include <climits>
#include <memory>
#include <unistd.h>
#include <filesystem>
#include <string>
#include <cmath>
std::filesystem::path GetExecutablePath()
{
char result[PATH_MAX];
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
return std::string(result, (count > 0) ? count : 0);
}
std::filesystem::path GetResourcesPath()
{
return GetExecutablePath().parent_path().parent_path() / "Resources";
}
int main(int ac, char** av)
{
Scop::ScopEngine engine(ac, av, "Vox", 0, 0, GetExecutablePath().parent_path().parent_path() / "ScopEngine/Assets");
std::shared_ptr<Scop::Scene> splash_scene = SplashScreen();
Scop::SceneDescriptor main_scene_desc;
main_scene_desc.fragment_shader = Scop::RenderCore::Get().GetDefaultFragmentShader();
main_scene_desc.camera = std::make_shared<Scop::FirstPerson3D>(Scop::Vec3f{ -10.0f, 0.0f, 0.0f });
Scop::Scene& main_scene = splash_scene->AddChildScene("main", std::move(main_scene_desc));
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));
Scop::Actor& object = main_scene.CreateActor(Scop::LoadModelFromObjFile(GetResourcesPath() / "knuckles.obj"));
object.SetScale(Scop::Vec3f{ 5.0f, 5.0f, 5.0f });
Scop::Actor& object2 = main_scene.CreateActor(Scop::CreateSphere());
object2.SetScale(Scop::Vec3f{ 5.0f, 5.0f, 5.0f });
object2.SetPosition(Scop::Vec3f{ 10.0f, 10.0f, 10.0f });
Scop::Vec2ui32 map_size;
Scop::MaterialTextures material_params;
material_params.albedo = std::make_shared<Scop::Texture>(Scop::LoadBMPFile(GetResourcesPath() / "knuckles.bmp", map_size), map_size.x, map_size.y);
std::shared_ptr<Scop::Material> material = std::make_shared<Scop::Material>(material_params);
object.GetModelRef().SetMaterial(material, 0);
auto object_update = [](Scop::NonOwningPtr<Scop::Scene> scene, Scop::NonOwningPtr<Scop::Actor> actor, Scop::Inputs& input, float delta)
{
static Scop::MaterialData material_data{};
WireframeHandler(scene, input);
MovementHandler(actor, input, delta);
ColorsTransitionHandler(actor, input, delta, material_data);
TextureTransitionHandler(actor, input, delta, material_data);
for(std::shared_ptr<Scop::Material> material : actor->GetModelRef().GetAllMaterials())
{
if(material)
material->SetMaterialData(material_data);
}
};
using actor_hook = std::function<void(Scop::NonOwningPtr<Scop::Actor>)>;
object.AttachScript(std::make_shared<Scop::NativeActorScript>(actor_hook{}, object_update, actor_hook{}));
engine.RegisterMainScene(splash_scene.get());
engine.Run();
return 0;
}