2020-11-05 16:44:34 +01:00
|
|
|
#pragma once
|
2020-11-29 16:50:49 +01:00
|
|
|
#include "gdrv.h"
|
2020-11-05 16:44:34 +01:00
|
|
|
|
2021-09-28 07:14:18 +02:00
|
|
|
struct SdlTickClock
|
|
|
|
{
|
|
|
|
using duration = std::chrono::milliseconds;
|
|
|
|
using rep = duration::rep;
|
|
|
|
using period = duration::period;
|
|
|
|
using time_point = std::chrono::time_point<SdlTickClock>;
|
|
|
|
static constexpr bool is_steady = true;
|
|
|
|
|
|
|
|
static time_point now() noexcept
|
|
|
|
{
|
|
|
|
return time_point{duration{SDL_GetTicks()}};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SdlPerformanceClock
|
|
|
|
{
|
|
|
|
using duration = std::chrono::duration<uint64_t, std::nano>;
|
|
|
|
using rep = duration::rep;
|
|
|
|
using period = duration::period;
|
|
|
|
using time_point = std::chrono::time_point<SdlPerformanceClock>;
|
|
|
|
static constexpr bool is_steady = true;
|
|
|
|
|
|
|
|
static time_point now() noexcept
|
|
|
|
{
|
|
|
|
const auto freq = SDL_GetPerformanceFrequency();
|
|
|
|
const auto ctr = SDL_GetPerformanceCounter();
|
|
|
|
const auto whole = (ctr / freq) * period::den;
|
|
|
|
const auto part = (ctr % freq) * period::den / freq;
|
|
|
|
return time_point(duration(whole + part));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
class winmain
|
|
|
|
{
|
2021-09-28 07:14:18 +02:00
|
|
|
using Clock = SdlPerformanceClock; // Or std::chrono::steady_clock.
|
|
|
|
using DurationMs = std::chrono::duration<double, std::milli>;
|
|
|
|
using TimePoint = std::chrono::time_point<Clock>;
|
|
|
|
|
2020-11-07 16:41:14 +01:00
|
|
|
public:
|
2021-09-16 09:57:46 +02:00
|
|
|
static std::string DatFileName;
|
2021-10-23 08:02:51 +02:00
|
|
|
static bool single_step;
|
2021-09-01 10:02:57 +02:00
|
|
|
static SDL_Window* MainWindow;
|
|
|
|
static SDL_Renderer* Renderer;
|
2021-09-05 09:47:05 +02:00
|
|
|
static ImGuiIO* ImIO;
|
2021-09-06 15:27:58 +02:00
|
|
|
static bool LaunchBallEnabled;
|
|
|
|
static bool HighScoresEnabled;
|
2021-09-22 14:50:07 +02:00
|
|
|
static bool DemoActive;
|
2021-09-14 14:33:18 +02:00
|
|
|
static char* BasePath;
|
2021-10-24 17:38:23 +02:00
|
|
|
static int MainMenuHeight;
|
2020-12-02 18:12:34 +01:00
|
|
|
|
2021-09-01 10:02:57 +02:00
|
|
|
static int WinMain(LPCSTR lpCmdLine);
|
2021-08-27 12:29:41 +02:00
|
|
|
static int event_handler(const SDL_Event* event);
|
2021-10-02 16:45:31 +02:00
|
|
|
[[ noreturn ]] static void memalloc_failure();
|
2020-11-07 16:41:14 +01:00
|
|
|
static int ProcessWindowMessages();
|
2021-09-05 09:47:05 +02:00
|
|
|
static void a_dialog();
|
2020-12-02 18:12:34 +01:00
|
|
|
static void end_pause();
|
|
|
|
static void new_game();
|
|
|
|
static void pause();
|
2021-02-06 14:53:47 +01:00
|
|
|
static void Restart();
|
2021-09-22 14:50:07 +02:00
|
|
|
static bool RestartRequested() { return restart; }
|
2021-09-28 07:14:18 +02:00
|
|
|
static void UpdateFrameRate();
|
2020-11-07 16:41:14 +01:00
|
|
|
private:
|
2021-10-23 08:02:51 +02:00
|
|
|
static int return_value, DispFrameRate, DispGRhistory;
|
|
|
|
static int mouse_down, last_mouse_x, last_mouse_y;
|
|
|
|
static bool no_time_loss, activated, bQuit, has_focus;
|
2021-10-02 16:45:31 +02:00
|
|
|
static gdrv_bitmap8* gfr_display;
|
2021-09-23 11:16:58 +02:00
|
|
|
static std::string FpsDetails;
|
2021-02-06 14:53:47 +01:00
|
|
|
static bool restart;
|
2021-09-05 09:47:05 +02:00
|
|
|
static bool ShowAboutDialog;
|
|
|
|
static bool ShowImGuiDemo;
|
2021-09-21 12:14:39 +02:00
|
|
|
static bool ShowSpriteViewer;
|
2021-09-28 07:14:18 +02:00
|
|
|
static double UpdateToFrameRatio;
|
|
|
|
static DurationMs TargetFrameTime;
|
2021-10-09 16:28:30 +02:00
|
|
|
static struct optionsStruct& Options;
|
2021-09-22 14:50:07 +02:00
|
|
|
|
2021-09-05 09:47:05 +02:00
|
|
|
static void RenderUi();
|
2020-11-07 16:41:14 +01:00
|
|
|
};
|