mirror of https://github.com/auygun/kaliber.git
Compare commits
3 Commits
2ac1520c9b
...
41a1cfe6f5
Author | SHA1 | Date |
---|---|---|
Attila Uygun | 41a1cfe6f5 | |
Attila Uygun | 92dbf5cd97 | |
Attila Uygun | eb50e547b8 |
|
@ -2,10 +2,13 @@
|
|||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
namespace base {
|
||||
|
@ -38,6 +41,10 @@ LogMessage::~LogMessage() {
|
|||
#if defined(__ANDROID__)
|
||||
__android_log_print(ANDROID_LOG_ERROR, "kaliber", "%d [%s:%d] %s",
|
||||
verbosity_level_, filename.c_str(), line_, text.c_str());
|
||||
#elif defined(_WIN32)
|
||||
std::string s = std::format("{} [{}:{}] {}", verbosity_level_,
|
||||
filename.c_str(), line_, text.c_str());
|
||||
OutputDebugStringA(s.c_str());
|
||||
#else
|
||||
printf("%d [%s:%d] %s", verbosity_level_, filename.c_str(), line_,
|
||||
text.c_str());
|
||||
|
|
|
@ -108,6 +108,8 @@ void Engine::Initialize() {
|
|||
|
||||
thread_pool_.Initialize();
|
||||
|
||||
platform_->CreateMainWindow();
|
||||
|
||||
CreateRendererInternal(RendererType::kVulkan);
|
||||
|
||||
CreateProjectionMatrix();
|
||||
|
@ -493,8 +495,8 @@ void Engine::OnWindowDestroyed() {
|
|||
}
|
||||
|
||||
void Engine::OnWindowResized(int width, int height) {
|
||||
if (width != renderer_->GetScreenWidth() ||
|
||||
height != renderer_->GetScreenHeight()) {
|
||||
if (renderer_ && (width != renderer_->GetScreenWidth() ||
|
||||
height != renderer_->GetScreenHeight())) {
|
||||
renderer_->OnWindowResized(width, height);
|
||||
CreateProjectionMatrix();
|
||||
}
|
||||
|
|
|
@ -36,10 +36,12 @@ class Platform {
|
|||
#elif defined(__linux__)
|
||||
Platform();
|
||||
#elif defined(_WIN32)
|
||||
Platform(HINSTANCE hInstance, int nCmdShow);
|
||||
Platform(HINSTANCE instance, int cmd_show);
|
||||
#endif
|
||||
~Platform();
|
||||
|
||||
void CreateMainWindow();
|
||||
|
||||
void Update();
|
||||
|
||||
void Exit();
|
||||
|
@ -125,11 +127,10 @@ class Platform {
|
|||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
// Global Variables:
|
||||
HINSTANCE hInst; // current instance
|
||||
HWND hWnd;
|
||||
HINSTANCE instance_;
|
||||
HWND wnd_;
|
||||
int cmd_show_;
|
||||
|
||||
// Forward declarations of functions included in this code module:
|
||||
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -292,20 +292,18 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
|
|||
DLOG(0) << "APP_CMD_INIT_WINDOW";
|
||||
if (app->window != NULL) {
|
||||
platform->SetFrameRate(60);
|
||||
if (platform->observer_)
|
||||
platform->observer_->OnWindowCreated();
|
||||
platform->observer_->OnWindowCreated();
|
||||
}
|
||||
break;
|
||||
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
DLOG(0) << "APP_CMD_TERM_WINDOW";
|
||||
if (platform->observer_)
|
||||
platform->observer_->OnWindowDestroyed();
|
||||
platform->observer_->OnWindowDestroyed();
|
||||
break;
|
||||
|
||||
case APP_CMD_CONFIG_CHANGED:
|
||||
DLOG(0) << "APP_CMD_CONFIG_CHANGED";
|
||||
if (platform->app_->window != NULL && platform->observer_)
|
||||
if (platform->app_->window != NULL)
|
||||
platform->observer_->OnWindowResized(
|
||||
ANativeWindow_getWidth(app->window),
|
||||
ANativeWindow_getHeight(app->window));
|
||||
|
@ -319,16 +317,14 @@ void Platform::HandleCmd(android_app* app, int32_t cmd) {
|
|||
DLOG(0) << "APP_CMD_GAINED_FOCUS";
|
||||
// platform->timer_.Reset();
|
||||
platform->has_focus_ = true;
|
||||
if (platform->observer_)
|
||||
platform->observer_->GainedFocus(g_showing_interstitial_ad);
|
||||
platform->observer_->GainedFocus(g_showing_interstitial_ad);
|
||||
g_showing_interstitial_ad = false;
|
||||
break;
|
||||
|
||||
case APP_CMD_LOST_FOCUS:
|
||||
DLOG(0) << "APP_CMD_LOST_FOCUS";
|
||||
platform->has_focus_ = false;
|
||||
if (platform->observer_)
|
||||
platform->observer_->LostFocus();
|
||||
platform->observer_->LostFocus();
|
||||
break;
|
||||
|
||||
case APP_CMD_LOW_MEMORY:
|
||||
|
@ -370,8 +366,12 @@ Platform::Platform(android_app* app) {
|
|||
reinterpret_cast<PFN_ANativeWindow_setFrameRateWithChangeStrategy>(
|
||||
dlsym(mLibAndroid, "ANativeWindow_setFrameRateWithChangeStrategy"));
|
||||
}
|
||||
}
|
||||
|
||||
void Platform::CreateMainWindow() {
|
||||
DCHECK(!app_->window);
|
||||
Update();
|
||||
DCHECK(app_->window);
|
||||
}
|
||||
|
||||
Platform::~Platform() {
|
||||
|
|
|
@ -39,7 +39,9 @@ Platform::Platform() {
|
|||
LOG(0) << "Root path: " << root_path_.c_str();
|
||||
LOG(0) << "Data path: " << data_path_.c_str();
|
||||
LOG(0) << "Shared data path: " << shared_data_path_.c_str();
|
||||
}
|
||||
|
||||
void Platform::CreateMainWindow() {
|
||||
bool res = CreateWindow(800, 1205);
|
||||
CHECK(res) << "Failed to create window.";
|
||||
|
||||
|
@ -103,6 +105,7 @@ void Platform::Update() {
|
|||
}
|
||||
case ClientMessage: {
|
||||
// WM_DELETE_WINDOW is the only registered type for now.
|
||||
observer_->OnWindowDestroyed();
|
||||
should_exit_ = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "base/log.h"
|
||||
// #include "base/vecmath.h"
|
||||
// #include "engine/input_event.h"
|
||||
// #include "engine/platform/platform_observer.h"
|
||||
#include "engine/platform/platform_observer.h"
|
||||
|
||||
using namespace base;
|
||||
|
||||
|
@ -16,7 +16,8 @@ namespace eng {
|
|||
|
||||
void KaliberMain(Platform* platform);
|
||||
|
||||
Platform::Platform(HINSTANCE hInstance, int nCmdShow) : hInst(hInstance) {
|
||||
Platform::Platform(HINSTANCE instance, int cmd_show)
|
||||
: instance_(instance), cmd_show_(cmd_show) {
|
||||
LOG(0) << "Initializing platform.";
|
||||
|
||||
root_path_ = "./";
|
||||
|
@ -33,31 +34,44 @@ Platform::Platform(HINSTANCE hInstance, int nCmdShow) : hInst(hInstance) {
|
|||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon =
|
||||
nullptr; // LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
|
||||
wcex.hInstance = instance_;
|
||||
wcex.hIcon = nullptr;
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
wcex.lpszMenuName = nullptr; // MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1);
|
||||
wcex.lpszClassName = L"szWindowClass";
|
||||
wcex.hIconSm =
|
||||
nullptr; // LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
||||
RegisterClassExW(&wcex);
|
||||
wcex.hbrBackground = nullptr;
|
||||
wcex.lpszMenuName = nullptr;
|
||||
wcex.lpszClassName = L"KaliberWndClass";
|
||||
wcex.hIconSm = nullptr;
|
||||
RegisterClassEx(&wcex);
|
||||
}
|
||||
|
||||
hWnd = CreateWindowW(L"szWindowClass", L"kaliber", WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr,
|
||||
hInstance, nullptr);
|
||||
CHECK(hWnd);
|
||||
void Platform::CreateMainWindow() {
|
||||
wnd_ = CreateWindow(L"KaliberWndClass", L"Kaliber", WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, 800, 1205, nullptr, nullptr, instance_,
|
||||
this);
|
||||
CHECK(wnd_);
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
ShowWindow(wnd_, cmd_show_);
|
||||
UpdateWindow(wnd_);
|
||||
}
|
||||
|
||||
Platform::~Platform() {
|
||||
LOG(0) << "Shutting down platform.";
|
||||
DestroyWindow(wnd_);
|
||||
}
|
||||
|
||||
void Platform::Update() {}
|
||||
void Platform::Update() {
|
||||
DCHECK(!should_exit_);
|
||||
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
|
||||
if (msg.message == WM_QUIT) {
|
||||
should_exit_ = true;
|
||||
break;
|
||||
}
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Platform::Exit() {
|
||||
should_exit_ = true;
|
||||
|
@ -72,60 +86,45 @@ void Platform::ShareFile(const std::string& file_name) {}
|
|||
void Platform::SetKeepScreenOn(bool keep_screen_on) {}
|
||||
|
||||
HINSTANCE Platform::GetInstance() {
|
||||
return hInst;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
HWND Platform::GetWindow() {
|
||||
return hWnd;
|
||||
return wnd_;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Platform::WndProc(HWND hWnd,
|
||||
LRESULT CALLBACK Platform::WndProc(HWND wnd,
|
||||
UINT message,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
// switch (message)
|
||||
// {
|
||||
// case WM_COMMAND:
|
||||
// {
|
||||
// int wmId = LOWORD(wParam);
|
||||
// // Parse the menu selections:
|
||||
// switch (wmId)
|
||||
// {
|
||||
// case IDM_ABOUT:
|
||||
// DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
||||
// break;
|
||||
// case IDM_EXIT:
|
||||
// DestroyWindow(hWnd);
|
||||
// break;
|
||||
// default:
|
||||
// return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case WM_PAINT:
|
||||
// {
|
||||
// PAINTSTRUCT ps;
|
||||
// HDC hdc = BeginPaint(hWnd, &ps);
|
||||
// // TODO: Add any drawing code that uses hdc here...
|
||||
// EndPaint(hWnd, &ps);
|
||||
// }
|
||||
// break;
|
||||
// case WM_DESTROY:
|
||||
// PostQuitMessage(0);
|
||||
// break;
|
||||
// default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
// }
|
||||
// return 0;
|
||||
WPARAM wparam,
|
||||
LPARAM lparam) {
|
||||
auto* platform =
|
||||
reinterpret_cast<Platform*>(GetWindowLongPtr(wnd, GWL_USERDATA));
|
||||
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
SetWindowLongPtr(wnd, GWL_USERDATA,
|
||||
(LONG_PTR)(((LPCREATESTRUCT)lparam)->lpCreateParams));
|
||||
break;
|
||||
case WM_SIZE:
|
||||
platform->observer_->OnWindowResized(LOWORD(lparam), HIWORD(lparam));
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
platform->observer_->OnWindowDestroyed();
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(wnd, message, wparam, lparam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace eng
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_opt_ HINSTANCE hPrevInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow) {
|
||||
eng::Platform platform(hInstance, nCmdShow);
|
||||
int WINAPI WinMain(HINSTANCE instance,
|
||||
HINSTANCE prev_instance,
|
||||
PSTR cmd_line,
|
||||
int cmd_show) {
|
||||
eng::Platform platform(instance, cmd_show);
|
||||
eng::KaliberMain(&platform);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue