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