| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2016 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 #include <tchar.h> | |
| 10 | |
| 11 #include "SkTypes.h" | |
| 12 #include "Timer.h" | |
| 13 #include "Window_win.h" | |
| 14 #include "../Application.h" | |
| 15 | |
| 16 using sk_app::Application; | |
| 17 | |
| 18 static char* tchar_to_utf8(const TCHAR* str) { | |
| 19 #ifdef _UNICODE | |
| 20 int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL,
NULL); | |
| 21 char* str8 = (char*)sk_malloc_throw(size + 1); | |
| 22 WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL); | |
| 23 str8[size] = '\0'; | |
| 24 return str8; | |
| 25 #else | |
| 26 return _strdup(str); | |
| 27 #endif | |
| 28 } | |
| 29 | |
| 30 static double now_ms() { return SkTime::GetNSecs() * 1e-6; } | |
| 31 | |
| 32 // This file can work with GUI or CONSOLE subsystem types since we define _tWinM
ain and main(). | |
| 33 | |
| 34 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv); | |
| 35 | |
| 36 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCm
dLine, | |
| 37 int nCmdShow) { | |
| 38 | |
| 39 // convert from lpCmdLine to argc, argv. | |
| 40 char* argv[4096]; | |
| 41 int argc = 0; | |
| 42 TCHAR exename[1024], *next; | |
| 43 int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename)); | |
| 44 // we're ignoring the possibility that the exe name exceeds the exename buff
er | |
| 45 (void)exenameLen; | |
| 46 argv[argc++] = tchar_to_utf8(exename); | |
| 47 TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next); | |
| 48 while (arg != NULL) { | |
| 49 argv[argc++] = tchar_to_utf8(arg); | |
| 50 arg = _tcstok_s(NULL, _T(" "), &next); | |
| 51 } | |
| 52 int result = main_common(hInstance, nCmdShow, argc, argv); | |
| 53 for (int i = 0; i < argc; ++i) { | |
| 54 sk_free(argv[i]); | |
| 55 } | |
| 56 return result; | |
| 57 } | |
| 58 | |
| 59 int main(int argc, char**argv) { | |
| 60 return main_common(GetModuleHandle(NULL), SW_SHOW, argc, argv); | |
| 61 } | |
| 62 | |
| 63 static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) { | |
| 64 | |
| 65 Application* app = Application::Create(argc, argv, (void*)hInstance); | |
| 66 | |
| 67 MSG msg = { 0 }; | |
| 68 | |
| 69 double currentTime = 0.0; | |
| 70 double previousTime = 0.0; | |
| 71 | |
| 72 // Main message loop | |
| 73 while (WM_QUIT != msg.message) { | |
| 74 if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { | |
| 75 TranslateMessage(&msg); | |
| 76 DispatchMessage(&msg); | |
| 77 } else { | |
| 78 previousTime = currentTime; | |
| 79 currentTime = now_ms(); | |
| 80 app->onIdle(currentTime - previousTime); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 delete app; | |
| 85 | |
| 86 return (int)msg.wParam; | |
| 87 } | |
| OLD | NEW |