Compare commits

..

4 Commits

Author SHA1 Message Date
Attila Uygun 41a1cfe6f5 tmp 2023-08-09 23:12:49 +02:00
Attila Uygun 92dbf5cd97 Add Platform::CreateMainWindow 2023-08-09 23:02:24 +02:00
Attila Uygun eb50e547b8 win log 2023-08-09 23:00:38 +02:00
Attila Uygun 2ac1520c9b tmp 2023-08-08 23:26:31 +02:00
4 changed files with 11 additions and 47 deletions

View File

@ -26,9 +26,7 @@ AudioMixer::AudioMixer()
#elif defined(__linux__) #elif defined(__linux__)
audio_sink_{std::make_unique<AudioSinkAlsa>(this)} { audio_sink_{std::make_unique<AudioSinkAlsa>(this)} {
#elif defined(_WIN32) #elif defined(_WIN32)
// TODO: Implement AudioSinkWindows audio_sink_{std::make_unique<AudioSinkNull>()} {
audio_sink_{std::make_unique<AudioSinkNull>()},
audio_enabled_(false) {
#endif #endif
bool res = audio_sink_->Initialize(); bool res = audio_sink_->Initialize();
CHECK(res) << "Failed to initialize audio sink."; CHECK(res) << "Failed to initialize audio sink.";

View File

@ -487,8 +487,7 @@ bool Engine::IsMobile() const {
} }
void Engine::OnWindowCreated() { void Engine::OnWindowCreated() {
if (renderer_) renderer_->Initialize(platform_);
renderer_->Initialize(platform_);
} }
void Engine::OnWindowDestroyed() { void Engine::OnWindowDestroyed() {

View File

@ -106,9 +106,8 @@ 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(); observer_->OnWindowDestroyed();
DestroyWindow();
should_exit_ = true; should_exit_ = true;
return; break;
} }
case ConfigureNotify: { case ConfigureNotify: {
XConfigureEvent xce = e.xconfigure; XConfigureEvent xce = e.xconfigure;

View File

@ -6,8 +6,8 @@
// #include <memory> // #include <memory>
// //
#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;
@ -20,22 +20,9 @@ Platform::Platform(HINSTANCE instance, int cmd_show)
: instance_(instance), cmd_show_(cmd_show) { : instance_(instance), cmd_show_(cmd_show) {
LOG(0) << "Initializing platform."; LOG(0) << "Initializing platform.";
root_path_ = ".\\"; root_path_ = "./";
data_path_ = ".\\"; data_path_ = "./";
shared_data_path_ = ".\\"; shared_data_path_ = "./";
char dest[MAX_PATH];
memset(dest, 0, sizeof(dest));
if (GetModuleFileNameA(NULL, dest, MAX_PATH) > 0) {
std::string path = dest;
std::size_t last_slash_pos = path.find_last_of('\\');
if (last_slash_pos != std::string::npos)
path = path.substr(0, last_slash_pos + 1);
root_path_ = path;
data_path_ = path;
shared_data_path_ = path;
}
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();
@ -69,9 +56,12 @@ void Platform::CreateMainWindow() {
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; MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) { if (msg.message == WM_QUIT) {
@ -122,28 +112,6 @@ LRESULT CALLBACK Platform::WndProc(HWND wnd,
platform->observer_->OnWindowDestroyed(); platform->observer_->OnWindowDestroyed();
PostQuitMessage(0); PostQuitMessage(0);
break; break;
case WM_MOUSEMOVE: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDrag, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
case WM_LBUTTONDOWN: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragStart, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
case WM_LBUTTONUP: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragEnd, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
default: default:
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
} }