diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-03-24 02:01:28 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2024-04-06 04:32:13 -0600 |
| commit | 641a43cbf9b4f4c4f545218e201fb58bbe15fcd7 (patch) | |
| tree | 50ecef61c66e171580ef1a09c2d3a9fc32591768 /src/port/Engine.cpp | |
| parent | 126a55aa0eadaf8b2ed8f370cbba63368be7a964 (diff) | |
First compilation, we just need more stupid assets
Diffstat (limited to 'src/port/Engine.cpp')
| -rw-r--r-- | src/port/Engine.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp new file mode 100644 index 00000000..b6a1f636 --- /dev/null +++ b/src/port/Engine.cpp @@ -0,0 +1,119 @@ +#include "Engine.h" +#include "ui/ImguiUI.h" +#include "ZAPDUtils/Utils/StringHelper.h" +#include "libultraship/src/Context.h" + +#include <Fast3D/gfx_pc.h> +#include <Fast3D/gfx_rendering_api.h> +#include <SDL2/SDL_net.h> + +#include <utility> + +extern "C" { +float gInterpolationStep = 0.0f; +} + +GameEngine* GameEngine::Instance; + +GameEngine::GameEngine() { + std::vector<std::string> OTRFiles; + if (const std::string cube_path = LUS::Context::GetPathRelativeToAppDirectory("smcube.otr"); std::filesystem::exists(cube_path)) { + OTRFiles.push_back(cube_path); + } + if (const std::string sm64_otr_path = LUS::Context::GetPathRelativeToAppBundle("lylat.otr"); std::filesystem::exists(sm64_otr_path)) { + OTRFiles.push_back(sm64_otr_path); + } + if (const std::string patches_path = LUS::Context::GetPathRelativeToAppDirectory("mods"); !patches_path.empty() && std::filesystem::exists(patches_path)) { + if (std::filesystem::is_directory(patches_path)) { + for (const auto&p: std::filesystem::recursive_directory_iterator(patches_path)) { + if (StringHelper::IEquals(p.path().extension().string(), ".otr")) { + OTRFiles.push_back(p.path().generic_string()); + } + } + } + } + this->context = LUS::Context::CreateInstance("Lylat64", "sf64", "lylat.cfg.json", OTRFiles, + {0xFF2B5A63, 0xE3DAA4E}, 3); + // this->context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory( + // LUS::ResourceType::SAnim, "Animation", std::make_shared<CubeOS::AnimationFactory>()); +} + +void GameEngine::Create(){ + const auto instance = Instance = new GameEngine(); + GameUI::SetupGuiElements(); +} + +void GameEngine::Destroy(){ + +} + +bool ShouldClearTextureCacheAtEndOfFrame = false; + +void GameEngine::StartFrame() const{ + using LUS::KbScancode; + const int32_t dwScancode = this->context->GetWindow()->GetLastScancode(); + this->context->GetWindow()->SetLastScancode(-1); + + switch (dwScancode) { + case KbScancode::LUS_KB_TAB: { + // Toggle HD Assets + CVarSetInteger("gAltAssets", !CVarGetInteger("gAltAssets", 0)); + ShouldClearTextureCacheAtEndOfFrame = true; + break; + } + default: break; + } + this->context->GetWindow()->StartFrame(); +} + +void GameEngine::ProcessFrame(void (*run_one_game_iter)()) const { + this->context->GetWindow()->MainLoop(run_one_game_iter); +} + +void GameEngine::RunCommands(Gfx* Commands) { + gfx_run(Commands, {}); + gfx_end_frame(); + + if (ShouldClearTextureCacheAtEndOfFrame) { + gfx_texture_cache_clear(); + ShouldClearTextureCacheAtEndOfFrame = false; + } +} + +void GameEngine::ProcessGfxCommands(Gfx* commands) { + RunCommands(commands); + Instance->context->GetWindow()->SetTargetFps(30); + Instance->context->GetWindow()->SetMaximumFrameLatency(1); +} + +extern "C" uint32_t GameEngine_GetSampleRate() { + auto player = LUS::Context::GetInstance()->GetAudio()->GetAudioPlayer(); + if (player == nullptr) { + return 0; + } + + if (!player->IsInitialized()) { + return 0; + } + + return player->GetSampleRate(); +} + +extern "C" uint32_t GameEngine_GetSamplesPerFrame(){ + return SAMPLES_PER_FRAME; +} + +// End + +extern "C" float GameEngine_GetAspectRatio() { + return gfx_current_dimensions.aspect_ratio; +} + +extern "C" uint32_t GameEngine_GetGameVersion() { + return 0x00000001; +} + +extern "C" int GameEngine_OTRSigCheck(const char* data) { + static const char* sOtrSignature = "__OTR__"; + return strncmp(data, sOtrSignature, strlen(sOtrSignature)) == 0; +}
\ No newline at end of file |
