2022-10-02 04:29:51 +08:00
|
|
|
#include <blah_app.h>
|
|
|
|
#include <blah_common.h>
|
|
|
|
#include <blah_time.h>
|
|
|
|
#include "internal/blah_internal.h"
|
|
|
|
#include "internal/blah_platform.h"
|
|
|
|
#include "internal/blah_renderer.h"
|
2020-08-26 15:38:01 +08:00
|
|
|
|
2021-01-04 16:58:24 +08:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
#include <emscripten.h>
|
|
|
|
#include <emscripten/html5.h>
|
|
|
|
#endif
|
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
using namespace Blah;
|
|
|
|
|
2022-11-14 09:59:35 +08:00
|
|
|
// Internal Audio bool
|
2022-11-20 06:09:08 +08:00
|
|
|
bool Internal::audio_is_init = false;
|
2022-11-14 09:59:35 +08:00
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
namespace
|
|
|
|
{
|
2022-02-12 16:17:21 +08:00
|
|
|
// Global App State
|
|
|
|
Config app_config;
|
|
|
|
bool app_is_running = false;
|
|
|
|
bool app_is_exiting = false;
|
|
|
|
u64 app_time_last;
|
|
|
|
u64 app_time_accumulator = 0;
|
2022-08-22 08:41:29 +08:00
|
|
|
u32 app_flags = 0;
|
2022-02-12 16:17:21 +08:00
|
|
|
TargetRef app_backbuffer;
|
2022-11-20 09:53:21 +08:00
|
|
|
Renderer* app_renderer_api;
|
2022-02-12 16:17:21 +08:00
|
|
|
|
2022-08-22 05:48:46 +08:00
|
|
|
void get_drawable_size(int* w, int* h)
|
|
|
|
{
|
|
|
|
// Some renderer implementations might return their own size
|
2022-11-20 09:53:21 +08:00
|
|
|
if (app_renderer_api->get_draw_size(w, h))
|
2022-08-22 05:48:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// otherwise fallback to the platform size
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::get_draw_size(w, h);
|
2022-08-22 05:48:46 +08:00
|
|
|
}
|
|
|
|
|
2022-02-12 16:17:21 +08:00
|
|
|
// A dummy Target that represents the Back Buffer.
|
|
|
|
// It doesn't contain any data, rather it forwards calls along to the actual BackBuffer.
|
2022-02-10 17:13:20 +08:00
|
|
|
class BackBuffer final : public Target
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Attachments empty_textures;
|
|
|
|
Attachments& textures() override { BLAH_ASSERT(false, "Backbuffer doesn't have any textures"); return empty_textures; }
|
|
|
|
const Attachments& textures() const override { BLAH_ASSERT(false, "Backbuffer doesn't have any textures"); return empty_textures; }
|
2022-08-22 05:48:46 +08:00
|
|
|
int width() const override { int w, h; get_drawable_size(&w, &h); return w; }
|
|
|
|
int height() const override { int w, h; get_drawable_size(&w, &h); return h; }
|
2022-02-10 17:13:20 +08:00
|
|
|
void clear(Color color, float depth, u8 stencil, ClearMask mask) override
|
|
|
|
{
|
|
|
|
BLAH_ASSERT_RENDERER();
|
2022-11-20 09:53:21 +08:00
|
|
|
if (app_renderer_api)
|
|
|
|
app_renderer_api->clear_backbuffer(color, depth, stencil, mask);
|
2022-02-10 17:13:20 +08:00
|
|
|
}
|
|
|
|
};
|
2021-01-04 16:58:24 +08:00
|
|
|
}
|
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
bool App::run(const Config* c)
|
|
|
|
{
|
|
|
|
BLAH_ASSERT(!app_is_running, "The Application is already running");
|
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
// copy config over
|
2020-08-26 15:38:01 +08:00
|
|
|
app_config = *c;
|
2022-02-10 10:49:47 +08:00
|
|
|
|
|
|
|
// exit the application by default
|
|
|
|
if (!app_config.on_exit_request)
|
|
|
|
app_config.on_exit_request = App::exit;
|
|
|
|
|
|
|
|
// default renderer type
|
|
|
|
if (app_config.renderer_type == RendererType::None)
|
|
|
|
app_config.renderer_type = Renderer::default_type();
|
|
|
|
|
2022-02-12 07:20:07 +08:00
|
|
|
// exit out if setup is wrong
|
|
|
|
BLAH_ASSERT(c != nullptr, "The Application requires a valid Config");
|
|
|
|
BLAH_ASSERT(c->name != nullptr, "The Application Name cannot be null");
|
|
|
|
BLAH_ASSERT(c->width > 0 && c->height > 0, "The Width and Height must be larget than 0");
|
|
|
|
BLAH_ASSERT(c->max_updates > 0, "Max Updates must be >= 1");
|
|
|
|
BLAH_ASSERT(c->target_framerate > 0, "Target Framerate must be >= 1");
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-02-12 07:20:07 +08:00
|
|
|
if (app_is_running || c == nullptr || c->width <= 0 || c->height <= 0 || c->max_updates <= 0 || c->target_framerate <= 0)
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_shutdown();
|
2022-02-12 07:20:07 +08:00
|
|
|
return false;
|
2022-02-12 12:19:14 +08:00
|
|
|
}
|
2022-02-12 07:20:07 +08:00
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
// default values
|
2020-08-26 15:38:01 +08:00
|
|
|
app_is_running = true;
|
|
|
|
app_is_exiting = false;
|
2022-08-22 08:41:29 +08:00
|
|
|
app_flags = app_config.flags;
|
2022-02-12 07:20:07 +08:00
|
|
|
app_backbuffer = TargetRef(new BackBuffer());
|
2020-08-26 15:38:01 +08:00
|
|
|
|
|
|
|
// initialize the system
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
if (!Platform::init(app_config))
|
2022-02-12 16:17:21 +08:00
|
|
|
{
|
|
|
|
Log::error("Failed to initialize Platform module");
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_shutdown();
|
2022-02-12 16:17:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 09:59:35 +08:00
|
|
|
// initialize audio
|
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
if (!Internal::audio_is_init) {
|
2022-11-14 09:59:35 +08:00
|
|
|
int more_on_emscripten = 1;
|
2022-11-20 09:53:21 +08:00
|
|
|
#ifdef __EMSCRIPTEN__
|
2022-11-14 09:59:35 +08:00
|
|
|
more_on_emscripten = 4;
|
2022-11-20 09:53:21 +08:00
|
|
|
#endif
|
|
|
|
Internal::audio_is_init = Internal::audio_init(c->audio_frequency_in_Hz, 1024 * more_on_emscripten);
|
2022-11-14 09:59:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
// initialize graphics
|
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
app_renderer_api = Renderer::try_make_renderer(app_config.renderer_type);
|
|
|
|
if (app_renderer_api == nullptr)
|
2022-02-12 16:17:21 +08:00
|
|
|
{
|
|
|
|
Log::error("Renderer module was not found");
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_shutdown();
|
2022-02-12 16:17:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-10 10:49:47 +08:00
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
if (!app_renderer_api->init())
|
2022-02-12 16:17:21 +08:00
|
|
|
{
|
|
|
|
Log::error("Failed to initialize Renderer module");
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_shutdown();
|
2022-02-12 16:17:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
// apply default flags
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::set_app_flags(app_flags);
|
|
|
|
app_renderer_api->set_app_flags(app_flags);
|
2022-08-22 08:41:29 +08:00
|
|
|
|
2022-02-12 16:17:21 +08:00
|
|
|
// input + poll the platform once
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::input_init();
|
|
|
|
Internal::input_step_state();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::update(Input::state);
|
2021-12-13 12:41:23 +08:00
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
// startup
|
|
|
|
if (app_config.on_startup != nullptr)
|
|
|
|
app_config.on_startup();
|
2022-11-20 09:53:21 +08:00
|
|
|
app_time_last = Platform::ticks();
|
2022-02-10 10:49:47 +08:00
|
|
|
app_time_accumulator = 0;
|
2020-08-26 15:38:01 +08:00
|
|
|
|
|
|
|
// display window
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::ready();
|
2020-08-26 15:38:01 +08:00
|
|
|
|
2021-01-06 12:44:02 +08:00
|
|
|
// Begin main loop
|
2021-01-04 16:58:24 +08:00
|
|
|
#ifdef __EMSCRIPTEN__
|
2022-11-20 08:15:31 +08:00
|
|
|
emscripten_set_main_loop(Internal::iterate, 0, 1);
|
2021-01-04 16:58:24 +08:00
|
|
|
#else
|
2020-08-26 15:38:01 +08:00
|
|
|
while (!app_is_exiting)
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_step();
|
2021-01-04 16:58:24 +08:00
|
|
|
#endif
|
2020-08-26 15:38:01 +08:00
|
|
|
|
|
|
|
// shutdown
|
|
|
|
if (app_config.on_shutdown != nullptr)
|
|
|
|
app_config.on_shutdown();
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::app_shutdown();
|
2022-02-12 12:19:14 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-13 15:14:35 +08:00
|
|
|
bool App::is_running()
|
|
|
|
{
|
|
|
|
return app_is_running;
|
|
|
|
}
|
|
|
|
|
2022-11-20 08:15:31 +08:00
|
|
|
void Internal::app_step()
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
2022-08-22 08:41:29 +08:00
|
|
|
static const auto step = []()
|
|
|
|
{
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::input_step_state();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::update(Input::state);
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::input_step_bindings();
|
2022-11-20 09:53:21 +08:00
|
|
|
app_renderer_api->update();
|
2022-08-22 08:41:29 +08:00
|
|
|
if (app_config.on_update != nullptr)
|
|
|
|
app_config.on_update();
|
|
|
|
};
|
|
|
|
|
2022-11-20 08:15:31 +08:00
|
|
|
bool is_fixed_timestep = App::get_flag(Flags::FixedTimestep);
|
2022-08-22 08:41:29 +08:00
|
|
|
|
|
|
|
// Update in Fixed Timestep
|
|
|
|
if (is_fixed_timestep)
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
|
|
|
u64 time_target = (u64)((1.0 / app_config.target_framerate) * Time::ticks_per_second);
|
2022-11-20 09:53:21 +08:00
|
|
|
u64 ticks_curr = Platform::ticks();
|
2022-08-22 08:41:29 +08:00
|
|
|
u64 ticks_diff = ticks_curr - app_time_last;
|
|
|
|
app_time_last = ticks_curr;
|
|
|
|
app_time_accumulator += ticks_diff;
|
2022-02-12 12:19:14 +08:00
|
|
|
|
|
|
|
// do not let us run too fast
|
|
|
|
while (app_time_accumulator < time_target)
|
|
|
|
{
|
|
|
|
int milliseconds = (int)(time_target - app_time_accumulator) / (Time::ticks_per_second / 1000);
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::sleep(milliseconds);
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
ticks_curr = Platform::ticks();
|
2022-08-22 08:41:29 +08:00
|
|
|
ticks_diff = ticks_curr - app_time_last;
|
|
|
|
app_time_last = ticks_curr;
|
|
|
|
app_time_accumulator += ticks_diff;
|
2022-02-12 12:19:14 +08:00
|
|
|
}
|
2020-08-26 15:38:01 +08:00
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
// Do not allow us to fall behind too many updates
|
|
|
|
// (otherwise we'll get spiral of death)
|
|
|
|
u64 time_maximum = app_config.max_updates * time_target;
|
|
|
|
if (app_time_accumulator > time_maximum)
|
|
|
|
app_time_accumulator = time_maximum;
|
2022-02-10 17:13:20 +08:00
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
// do as many updates as we can
|
|
|
|
while (app_time_accumulator >= time_target)
|
|
|
|
{
|
|
|
|
app_time_accumulator -= time_target;
|
|
|
|
|
|
|
|
Time::delta = (1.0f / app_config.target_framerate);
|
|
|
|
|
|
|
|
if (Time::pause_timer > 0)
|
|
|
|
{
|
|
|
|
Time::pause_timer -= Time::delta;
|
|
|
|
if (Time::pause_timer <= -0.0001)
|
|
|
|
Time::delta = -Time::pause_timer;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Time::previous_ticks = Time::ticks;
|
|
|
|
Time::ticks += time_target;
|
|
|
|
Time::previous_seconds = Time::seconds;
|
|
|
|
Time::seconds += Time::delta;
|
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
step();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update with Variable Timestep
|
|
|
|
else
|
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
u64 ticks_curr = Platform::ticks();
|
2022-08-22 08:41:29 +08:00
|
|
|
u64 ticks_diff = ticks_curr - app_time_last;
|
|
|
|
app_time_last = ticks_curr;
|
|
|
|
app_time_accumulator += ticks_diff;
|
|
|
|
|
|
|
|
Time::delta = ticks_diff / (float)Time::ticks_per_second;
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
if (Time::pause_timer > 0)
|
|
|
|
{
|
|
|
|
Time::pause_timer -= Time::delta;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Time::previous_ticks = Time::ticks;
|
|
|
|
Time::ticks += ticks_diff;
|
|
|
|
Time::previous_seconds = Time::seconds;
|
|
|
|
Time::seconds += Time::delta;
|
|
|
|
|
|
|
|
step();
|
2022-02-12 12:19:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
// Draw Frame
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
app_renderer_api->before_render();
|
2022-02-12 12:19:14 +08:00
|
|
|
if (app_config.on_render != nullptr)
|
|
|
|
app_config.on_render();
|
2022-11-20 09:53:21 +08:00
|
|
|
app_renderer_api->after_render();
|
|
|
|
Platform::present();
|
2022-02-12 12:19:14 +08:00
|
|
|
}
|
2022-11-20 06:09:08 +08:00
|
|
|
|
|
|
|
// Update audio
|
2022-11-20 09:53:21 +08:00
|
|
|
if (Internal::audio_is_init)
|
|
|
|
Blah::Internal::audio_update();
|
2022-02-12 12:19:14 +08:00
|
|
|
}
|
|
|
|
|
2022-11-20 08:15:31 +08:00
|
|
|
void Internal::app_shutdown()
|
2022-02-12 12:19:14 +08:00
|
|
|
{
|
2022-11-20 08:15:31 +08:00
|
|
|
Internal::input_shutdown();
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
if (app_renderer_api)
|
|
|
|
{
|
|
|
|
app_renderer_api->shutdown();
|
|
|
|
delete app_renderer_api;
|
|
|
|
}
|
|
|
|
app_renderer_api = nullptr;
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
if (Internal::audio_is_init)
|
|
|
|
{
|
|
|
|
Internal::audio_shutdown();
|
|
|
|
Internal::audio_is_init = false;
|
|
|
|
}
|
2022-02-12 12:19:14 +08:00
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::shutdown();
|
2022-11-14 09:59:35 +08:00
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
// clear static App state
|
|
|
|
app_config = Config();
|
2020-08-26 15:38:01 +08:00
|
|
|
app_is_running = false;
|
|
|
|
app_is_exiting = false;
|
2022-02-12 12:19:14 +08:00
|
|
|
app_time_last = 0;
|
|
|
|
app_time_accumulator = 0;
|
2022-02-12 07:20:07 +08:00
|
|
|
app_backbuffer = TargetRef();
|
2021-02-06 16:13:50 +08:00
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
// clear static Time state
|
2021-02-06 16:13:50 +08:00
|
|
|
Time::ticks = 0;
|
|
|
|
Time::seconds = 0;
|
|
|
|
Time::previous_ticks = 0;
|
|
|
|
Time::previous_seconds = 0;
|
2020-08-26 15:38:01 +08:00
|
|
|
Time::delta = 0;
|
|
|
|
}
|
|
|
|
|
2022-11-20 09:53:21 +08:00
|
|
|
Renderer* Internal::app_renderer()
|
|
|
|
{
|
|
|
|
BLAH_ASSERT_RUNNING();
|
|
|
|
return app_renderer_api;
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
void App::exit()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2020-08-26 15:38:01 +08:00
|
|
|
if (!app_is_exiting && app_is_running)
|
|
|
|
app_is_exiting = true;
|
|
|
|
}
|
|
|
|
|
2021-05-10 10:40:50 +08:00
|
|
|
const Config& App::config()
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2021-05-10 10:40:50 +08:00
|
|
|
return app_config;
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* App::path()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
return Platform::app_path();
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* App::user_path()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
return Platform::user_path();
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 10:46:08 +08:00
|
|
|
const char* App::get_title()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
return Platform::get_title();
|
2021-05-10 10:46:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::set_title(const char* title)
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::set_title(title);
|
2021-05-10 10:46:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Point App::get_position()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2021-05-10 10:46:08 +08:00
|
|
|
Point result;
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::get_position(&result.x, &result.y);
|
2021-05-10 10:46:08 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::set_position(Point point)
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::set_position(point.x, point.y);
|
2021-05-10 10:46:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Point App::get_size()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2021-05-10 10:46:08 +08:00
|
|
|
Point result;
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::get_size(&result.x, &result.y);
|
2021-05-10 10:46:08 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::set_size(Point point)
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::set_size(point.x, point.y);
|
2021-05-10 10:46:08 +08:00
|
|
|
}
|
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
Point App::get_backbuffer_size()
|
2020-08-26 15:38:01 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
if (app_renderer_api)
|
2022-02-12 07:20:07 +08:00
|
|
|
return Point(app_backbuffer->width(), app_backbuffer->height());
|
2022-02-10 10:49:47 +08:00
|
|
|
return Point(0, 0);
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
float App::content_scale()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
return Platform::get_content_scale();
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 14:50:20 +08:00
|
|
|
bool App::focused()
|
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
return Platform::get_focused();
|
2022-01-26 14:50:20 +08:00
|
|
|
}
|
|
|
|
|
2022-08-22 08:41:29 +08:00
|
|
|
void App::set_flag(u32 flag, bool enabled)
|
|
|
|
{
|
|
|
|
BLAH_ASSERT_RUNNING();
|
|
|
|
|
|
|
|
u32 was = app_flags;
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
app_flags |= flag;
|
|
|
|
else
|
|
|
|
app_flags &= ~flag;
|
|
|
|
|
|
|
|
if (was != app_flags)
|
|
|
|
{
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::set_app_flags(app_flags);
|
|
|
|
if (app_renderer_api)
|
|
|
|
app_renderer_api->set_app_flags(app_flags);
|
2022-08-22 08:41:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool App::get_flag(u32 flag)
|
2020-12-27 06:44:48 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-08-22 08:41:29 +08:00
|
|
|
return ((app_flags & flag) == flag);
|
2020-12-27 06:44:48 +08:00
|
|
|
}
|
|
|
|
|
2022-02-12 12:19:14 +08:00
|
|
|
const RendererInfo& App::renderer()
|
2020-12-27 06:44:48 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
|
|
|
BLAH_ASSERT_RENDERER();
|
2022-11-20 09:53:21 +08:00
|
|
|
return app_renderer_api->info;
|
2020-12-27 06:44:48 +08:00
|
|
|
}
|
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
const TargetRef& App::backbuffer()
|
2022-01-26 14:50:20 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-02-12 07:20:07 +08:00
|
|
|
return app_backbuffer;
|
2022-01-26 14:50:20 +08:00
|
|
|
}
|
|
|
|
|
2022-02-10 10:49:47 +08:00
|
|
|
void System::open_url(const char* url)
|
2020-12-27 06:44:48 +08:00
|
|
|
{
|
2022-02-10 10:49:47 +08:00
|
|
|
BLAH_ASSERT_RUNNING();
|
2022-11-20 09:53:21 +08:00
|
|
|
Platform::open_url(url);
|
2022-02-10 10:49:47 +08:00
|
|
|
}
|