~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Source/Core/DolphinWX/Src/Main.cpp

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Dolphin Emulator Project
 
2
// Licensed under GPLv2
 
3
// Refer to the license.txt file included.
 
4
 
 
5
#include <vector>
 
6
#include <string>
 
7
 
 
8
#include "Common.h"
 
9
#include "CommonPaths.h"
 
10
 
 
11
#if defined HAVE_X11 && HAVE_X11
 
12
#include <X11/Xlib.h>
 
13
#endif
 
14
 
 
15
#include "CPUDetect.h"
 
16
#include "IniFile.h"
 
17
#include "FileUtil.h"
 
18
 
 
19
#include "Host.h" // Core
 
20
#include "HW/Wiimote.h"
 
21
 
 
22
#include "WxUtils.h"
 
23
#include "Globals.h" // Local
 
24
#include "Main.h"
 
25
#include "ConfigManager.h"
 
26
#include "Debugger/CodeWindow.h"
 
27
#include "Debugger/JitWindow.h"
 
28
#include "ExtendedTrace.h"
 
29
#include "BootManager.h"
 
30
#include "Frame.h"
 
31
 
 
32
#include "VideoBackendBase.h"
 
33
 
 
34
#include <wx/intl.h>
 
35
 
 
36
#ifdef _WIN32
 
37
#include <shellapi.h>
 
38
 
 
39
#ifndef SM_XVIRTUALSCREEN
 
40
#define SM_XVIRTUALSCREEN 76
 
41
#endif
 
42
#ifndef SM_YVIRTUALSCREEN
 
43
#define SM_YVIRTUALSCREEN 77
 
44
#endif
 
45
#ifndef SM_CXVIRTUALSCREEN
 
46
#define SM_CXVIRTUALSCREEN 78
 
47
#endif
 
48
#ifndef SM_CYVIRTUALSCREEN
 
49
#define SM_CYVIRTUALSCREEN 79
 
50
#endif
 
51
 
 
52
#endif
 
53
 
 
54
#ifdef __APPLE__
 
55
#import <AppKit/AppKit.h>
 
56
#endif
 
57
 
 
58
// Nvidia drivers >= v302 will check if the application exports a global
 
59
// variable named NvOptimusEnablement to know if it should run the app in high
 
60
// performance graphics mode or using the IGP.
 
61
#ifdef WIN32
 
62
extern "C" {
 
63
        __declspec(dllexport) DWORD NvOptimusEnablement = 1;
 
64
}
 
65
#endif
 
66
 
 
67
// ------------
 
68
//  Main window
 
69
 
 
70
IMPLEMENT_APP(DolphinApp)
 
71
 
 
72
BEGIN_EVENT_TABLE(DolphinApp, wxApp)
 
73
        EVT_TIMER(wxID_ANY, DolphinApp::AfterInit)
 
74
        EVT_QUERY_END_SESSION(DolphinApp::OnEndSession)
 
75
        EVT_END_SESSION(DolphinApp::OnEndSession)
 
76
END_EVENT_TABLE()
 
77
 
 
78
#include <wx/stdpaths.h>
 
79
bool wxMsgAlert(const char*, const char*, bool, int);
 
80
std::string wxStringTranslator(const char *);
 
81
 
 
82
CFrame* main_frame = NULL;
 
83
 
 
84
#ifdef WIN32
 
85
//Has no error handling.
 
86
//I think that if an error occurs here there's no way to handle it anyway.
 
87
LONG WINAPI MyUnhandledExceptionFilter(LPEXCEPTION_POINTERS e) {
 
88
        //EnterCriticalSection(&g_uefcs);
 
89
 
 
90
        File::IOFile file("exceptioninfo.txt", "a");
 
91
        file.Seek(0, SEEK_END);
 
92
        etfprint(file.GetHandle(), "\n");
 
93
        //etfprint(file, g_buildtime);
 
94
        //etfprint(file, "\n");
 
95
        //dumpCurrentDate(file);
 
96
        etfprintf(file.GetHandle(), "Unhandled Exception\n  Code: 0x%08X\n",
 
97
                e->ExceptionRecord->ExceptionCode);
 
98
#ifndef _M_X64
 
99
        STACKTRACE2(file.GetHandle(), e->ContextRecord->Eip, e->ContextRecord->Esp, e->ContextRecord->Ebp);
 
100
#else
 
101
        STACKTRACE2(file.GetHandle(), e->ContextRecord->Rip, e->ContextRecord->Rsp, e->ContextRecord->Rbp);
 
102
#endif
 
103
        file.Close();
 
104
        _flushall();
 
105
 
 
106
        //LeaveCriticalSection(&g_uefcs);
 
107
        return EXCEPTION_CONTINUE_SEARCH;
 
108
}
 
109
#endif
 
110
 
 
111
bool DolphinApp::Initialize(int& c, wxChar **v)
 
112
{
 
113
#if defined HAVE_X11 && HAVE_X11
 
114
        XInitThreads();
 
115
#endif 
 
116
        return wxApp::Initialize(c, v);
 
117
}
 
118
 
 
119
// The `main program' equivalent that creates the main window and return the main frame 
 
120
 
 
121
bool DolphinApp::OnInit()
 
122
{
 
123
        InitLanguageSupport();
 
124
 
 
125
        // Declarations and definitions
 
126
        bool UseDebugger = false;
 
127
        bool UseLogger = false;
 
128
        bool selectVideoBackend = false;
 
129
        bool selectAudioEmulation = false;
 
130
 
 
131
        wxString videoBackendName;
 
132
        wxString audioEmulationName;
 
133
        wxString userPath;
 
134
 
 
135
#if wxUSE_CMDLINE_PARSER // Parse command lines
 
136
        wxCmdLineEntryDesc cmdLineDesc[] =
 
137
        {
 
138
                {
 
139
                        wxCMD_LINE_SWITCH, "h", "help",
 
140
                        "Show this help message",
 
141
                        wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP
 
142
                },
 
143
                {
 
144
                        wxCMD_LINE_SWITCH, "d", "debugger",
 
145
                        "Opens the debugger",
 
146
                        wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL
 
147
                },
 
148
                {
 
149
                        wxCMD_LINE_SWITCH, "l", "logger",
 
150
                        "Opens the logger",
 
151
                        wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL
 
152
                },
 
153
                {
 
154
                        wxCMD_LINE_OPTION, "e", "exec",
 
155
                        "Loads the specified file (DOL,ELF,GCM,ISO,WAD)",
 
156
                        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
 
157
                },
 
158
                {
 
159
                        wxCMD_LINE_SWITCH, "b", "batch",
 
160
                        "Exit Dolphin with emulator",
 
161
                        wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL
 
162
                },
 
163
                {
 
164
                        wxCMD_LINE_OPTION, "V", "video_backend",
 
165
                        "Specify a video backend",
 
166
                        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
 
167
                },
 
168
                {
 
169
                        wxCMD_LINE_OPTION, "A", "audio_emulation",
 
170
                        "Low level (LLE) or high level (HLE) audio",
 
171
                        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
 
172
                },
 
173
                {
 
174
                        wxCMD_LINE_OPTION, "m", "movie",
 
175
                        "Play a movie file",
 
176
                        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
 
177
                },
 
178
                {
 
179
                        wxCMD_LINE_OPTION, "U", "user",
 
180
                        "User folder path",
 
181
                        wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL
 
182
                },
 
183
                {
 
184
                        wxCMD_LINE_NONE, NULL, NULL, NULL, wxCMD_LINE_VAL_NONE, 0
 
185
                }
 
186
        };
 
187
 
 
188
        // Gets the command line parameters
 
189
        wxCmdLineParser parser(cmdLineDesc, argc, argv);
 
190
        if (parser.Parse() != 0)
 
191
        {
 
192
                return false;
 
193
        } 
 
194
 
 
195
        UseDebugger = parser.Found(wxT("debugger"));
 
196
        UseLogger = parser.Found(wxT("logger"));
 
197
        LoadFile = parser.Found(wxT("exec"), &FileToLoad);
 
198
        BatchMode = parser.Found(wxT("batch"));
 
199
        selectVideoBackend = parser.Found(wxT("video_backend"),
 
200
                &videoBackendName);
 
201
        selectAudioEmulation = parser.Found(wxT("audio_emulation"),
 
202
                &audioEmulationName);
 
203
        playMovie = parser.Found(wxT("movie"), &movieFile);
 
204
 
 
205
        if (parser.Found(wxT("user"), &userPath))
 
206
        {
 
207
                File::CreateFullPath(WxStrToStr(userPath) + DIR_SEP);
 
208
                File::GetUserPath(D_USER_IDX, userPath.ToStdString() + DIR_SEP);
 
209
        }
 
210
#endif // wxUSE_CMDLINE_PARSER
 
211
 
 
212
#if defined _DEBUG && defined _WIN32
 
213
        int tmpflag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
 
214
        tmpflag |= _CRTDBG_DELAY_FREE_MEM_DF;
 
215
        _CrtSetDbgFlag(tmpflag);
 
216
#endif
 
217
 
 
218
        // Register message box and translation handlers
 
219
        RegisterMsgAlertHandler(&wxMsgAlert);
 
220
        RegisterStringTranslator(&wxStringTranslator);
 
221
 
 
222
        // "ExtendedTrace" looks freakin' dangerous!!!
 
223
#ifdef _WIN32
 
224
        EXTENDEDTRACEINITIALIZE(".");
 
225
        SetUnhandledExceptionFilter(&MyUnhandledExceptionFilter);
 
226
#elif wxUSE_ON_FATAL_EXCEPTION
 
227
        wxHandleFatalExceptions(true);
 
228
#endif
 
229
 
 
230
#ifndef _M_ARM
 
231
        // TODO: if First Boot
 
232
        if (!cpu_info.bSSE2) 
 
233
        {
 
234
                PanicAlertT("Hi,\n\nDolphin requires that your CPU has support for SSE2 extensions.\n"
 
235
                                "Unfortunately your CPU does not support them, so Dolphin will not run.\n\n"
 
236
                                "Sayonara!\n");
 
237
                return false;
 
238
        }
 
239
#endif
 
240
#ifdef __APPLE__
 
241
        if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_7)
 
242
        {
 
243
                PanicAlertT("Hi,\n\nDolphin requires Mac OS X 10.7 or greater.\n"
 
244
                                "Unfortunately you're running an old version of OS X.\n"
 
245
                                "The last Dolphin version to support OS X 10.6 is Dolphin 3.5\n"
 
246
                                "Please upgrade to 10.7 or greater to use the newest Dolphin version.\n\n"
 
247
                                "Sayonara!\n");
 
248
                return false;
 
249
        }
 
250
#endif
 
251
 
 
252
        // Copy initial Wii NAND data from Sys to User.
 
253
        File::CopyDir(File::GetSysDirectory() + WII_USER_DIR DIR_SEP,
 
254
                      File::GetUserPath(D_WIIUSER_IDX));
 
255
 
 
256
        File::CreateFullPath(File::GetUserPath(D_USER_IDX));
 
257
        File::CreateFullPath(File::GetUserPath(D_CACHE_IDX));
 
258
        File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX));
 
259
        File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX));
 
260
        File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX));
 
261
        File::CreateFullPath(File::GetUserPath(D_GAMESETTINGS_IDX));
 
262
        File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX));
 
263
        File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP);
 
264
        File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP);
 
265
        File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP);
 
266
        File::CreateFullPath(File::GetUserPath(D_TRIUSER_IDX));
 
267
        File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX));
 
268
        File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX));
 
269
        File::CreateFullPath(File::GetUserPath(D_MAPS_IDX));
 
270
        File::CreateFullPath(File::GetUserPath(D_OPENCL_IDX));
 
271
        File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX));
 
272
        File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX));
 
273
        File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX));
 
274
        File::CreateFullPath(File::GetUserPath(D_THEMES_IDX));
 
275
 
 
276
        LogManager::Init();
 
277
        SConfig::Init();
 
278
        VideoBackend::PopulateList();
 
279
        WiimoteReal::LoadSettings();
 
280
 
 
281
        if (selectVideoBackend && videoBackendName != wxEmptyString)
 
282
                SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend =
 
283
                        WxStrToStr(videoBackendName);
 
284
 
 
285
        if (selectAudioEmulation)
 
286
        {
 
287
                if (audioEmulationName == "HLE")
 
288
                        SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE = true;
 
289
                else if (audioEmulationName == "LLE")
 
290
                        SConfig::GetInstance().m_LocalCoreStartupParameter.bDSPHLE = false;
 
291
        }
 
292
 
 
293
        VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend);
 
294
 
 
295
        // Enable the PNG image handler for screenshots
 
296
        wxImage::AddHandler(new wxPNGHandler);
 
297
 
 
298
        SetEnableAlert(SConfig::GetInstance().m_LocalCoreStartupParameter.bUsePanicHandlers);
 
299
 
 
300
        int x = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosX;
 
301
        int y = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosY;
 
302
        int w = SConfig::GetInstance().m_LocalCoreStartupParameter.iWidth;
 
303
        int h = SConfig::GetInstance().m_LocalCoreStartupParameter.iHeight;
 
304
 
 
305
#ifdef _WIN32
 
306
        if (File::Exists("www.dolphin-emulator.com.txt"))
 
307
        {
 
308
                File::Delete("www.dolphin-emulator.com.txt");
 
309
                MessageBox(NULL,
 
310
                                   L"This version of Dolphin was downloaded from a website stealing money from developers of the emulator. Please "
 
311
                                   L"download Dolphin from the official website instead: http://dolphin-emu.org/",
 
312
                                   L"Unofficial version detected", MB_OK | MB_ICONWARNING);
 
313
                ShellExecute(NULL, L"open", L"http://dolphin-emu.org/?ref=badver", NULL, NULL, SW_SHOWDEFAULT);
 
314
                exit(0);
 
315
        }
 
316
#endif
 
317
 
 
318
        // The following is not needed with X11, where window managers
 
319
        // do not allow windows to be created off the desktop.
 
320
#ifdef _WIN32
 
321
        // Out of desktop check
 
322
        int leftPos = GetSystemMetrics(SM_XVIRTUALSCREEN);
 
323
        int topPos = GetSystemMetrics(SM_YVIRTUALSCREEN);
 
324
        int width =  GetSystemMetrics(SM_CXVIRTUALSCREEN);
 
325
        int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);      
 
326
        if ((leftPos + width) < (x + w) || leftPos > x || (topPos + height) < (y + h) || topPos > y)
 
327
                x = y = wxDefaultCoord;
 
328
#elif defined __APPLE__
 
329
        if (y < 1)
 
330
                y = wxDefaultCoord;
 
331
#endif
 
332
 
 
333
        main_frame = new CFrame((wxFrame*)NULL, wxID_ANY,
 
334
                                StrToWxStr(scm_rev_str),
 
335
                                wxPoint(x, y), wxSize(w, h),
 
336
                                UseDebugger, BatchMode, UseLogger);
 
337
        SetTopWindow(main_frame);
 
338
        main_frame->SetMinSize(wxSize(400, 300));
 
339
 
 
340
        // Postpone final actions until event handler is running.
 
341
        // Updating the game list makes use of wxProgressDialog which may
 
342
        // only be run after OnInit() when the event handler is running.
 
343
        m_afterinit = new wxTimer(this, wxID_ANY);
 
344
        m_afterinit->Start(1, wxTIMER_ONE_SHOT);
 
345
 
 
346
        return true;
 
347
}
 
348
 
 
349
void DolphinApp::MacOpenFile(const wxString &fileName)
 
350
{
 
351
        FileToLoad = fileName;
 
352
        LoadFile = true;
 
353
 
 
354
        if (m_afterinit == NULL)
 
355
                main_frame->BootGame(WxStrToStr(FileToLoad));
 
356
}
 
357
 
 
358
void DolphinApp::AfterInit(wxTimerEvent& WXUNUSED(event))
 
359
{
 
360
        delete m_afterinit;
 
361
        m_afterinit = NULL;
 
362
 
 
363
        if (!BatchMode)
 
364
                main_frame->UpdateGameList();
 
365
 
 
366
        if (playMovie && movieFile != wxEmptyString)
 
367
        {
 
368
                if (Movie::PlayInput(movieFile.char_str()))
 
369
                {
 
370
                        if (LoadFile && FileToLoad != wxEmptyString)
 
371
                        {
 
372
                                main_frame->BootGame(WxStrToStr(FileToLoad));
 
373
                        }
 
374
                        else
 
375
                        {
 
376
                                main_frame->BootGame(std::string(""));
 
377
                        }
 
378
                }
 
379
        }
 
380
 
 
381
        // First check if we have an exec command line.
 
382
        else if (LoadFile && FileToLoad != wxEmptyString)
 
383
        {
 
384
                main_frame->BootGame(WxStrToStr(FileToLoad));
 
385
        }
 
386
        // If we have selected Automatic Start, start the default ISO,
 
387
        // or if no default ISO exists, start the last loaded ISO
 
388
        else if (main_frame->g_pCodeWindow)
 
389
        {
 
390
                if (main_frame->g_pCodeWindow->AutomaticStart())
 
391
                {
 
392
                        main_frame->BootGame("");
 
393
                }
 
394
        }
 
395
}
 
396
 
 
397
void DolphinApp::InitLanguageSupport()
 
398
{
 
399
        unsigned int language = 0;
 
400
 
 
401
        IniFile ini;
 
402
        ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
 
403
        ini.Get("Interface", "Language", &language, wxLANGUAGE_DEFAULT);
 
404
 
 
405
        // Load language if possible, fall back to system default otherwise
 
406
        if(wxLocale::IsAvailable(language))
 
407
        {
 
408
                m_locale = new wxLocale(language);
 
409
 
 
410
#ifdef _WIN32
 
411
                m_locale->AddCatalogLookupPathPrefix(StrToWxStr(File::GetExeDirectory() + DIR_SEP "Languages"));
 
412
#endif
 
413
 
 
414
                m_locale->AddCatalog(wxT("dolphin-emu"));
 
415
 
 
416
                if(!m_locale->IsOk())
 
417
                {
 
418
                        PanicAlertT("Error loading selected language. Falling back to system default.");
 
419
                        delete m_locale;
 
420
                        m_locale = new wxLocale(wxLANGUAGE_DEFAULT);
 
421
                }
 
422
        }
 
423
        else
 
424
        {
 
425
                PanicAlertT("The selected language is not supported by your system. Falling back to system default.");
 
426
                m_locale = new wxLocale(wxLANGUAGE_DEFAULT);
 
427
        }
 
428
}
 
429
 
 
430
void DolphinApp::OnEndSession(wxCloseEvent& event)
 
431
{
 
432
        // Close if we've recieved wxEVT_END_SESSION (ignore wxEVT_QUERY_END_SESSION)
 
433
        if (!event.CanVeto())
 
434
        {
 
435
                main_frame->Close(true);
 
436
        }
 
437
}
 
438
 
 
439
int DolphinApp::OnExit()
 
440
{
 
441
        WiimoteReal::Shutdown();
 
442
        VideoBackend::ClearList();
 
443
        SConfig::Shutdown();
 
444
        LogManager::Shutdown();
 
445
 
 
446
        delete m_locale;
 
447
 
 
448
        return wxApp::OnExit();
 
449
}
 
450
 
 
451
void DolphinApp::OnFatalException()
 
452
{
 
453
        WiimoteReal::Shutdown();
 
454
}
 
455
 
 
456
 
 
457
// ------------
 
458
// Talk to GUI
 
459
 
 
460
void Host_SysMessage(const char *fmt, ...) 
 
461
{
 
462
        va_list list;
 
463
        char msg[512];
 
464
 
 
465
        va_start(list, fmt);
 
466
        vsprintf(msg, fmt, list);
 
467
        va_end(list);
 
468
 
 
469
        if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
 
470
        //wxMessageBox(StrToWxStr(msg));
 
471
        PanicAlert("%s", msg);
 
472
}
 
473
 
 
474
bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*/)
 
475
{
 
476
#ifdef __WXGTK__
 
477
        if (wxIsMainThread())
 
478
#endif
 
479
                return wxYES == wxMessageBox(StrToWxStr(text), StrToWxStr(caption),
 
480
                                (yes_no) ? wxYES_NO : wxOK, wxGetActiveWindow());
 
481
#ifdef __WXGTK__
 
482
        else
 
483
        {
 
484
                wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_PANIC);
 
485
                event.SetString(StrToWxStr(caption) + wxT(":") + StrToWxStr(text));
 
486
                event.SetInt(yes_no);
 
487
                main_frame->GetEventHandler()->AddPendingEvent(event);
 
488
                main_frame->panic_event.Wait();
 
489
                return main_frame->bPanicResult;
 
490
        }
 
491
#endif
 
492
}
 
493
 
 
494
std::string wxStringTranslator(const char *text)
 
495
{
 
496
        return WxStrToStr(wxGetTranslation(wxString::FromUTF8(text)));
 
497
}
 
498
 
 
499
// Accessor for the main window class
 
500
CFrame* DolphinApp::GetCFrame()
 
501
{
 
502
        return main_frame;
 
503
}
 
504
 
 
505
void Host_Message(int Id)
 
506
{
 
507
        wxCommandEvent event(wxEVT_HOST_COMMAND, Id);
 
508
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
509
}
 
510
 
 
511
#ifdef _WIN32
 
512
extern "C" HINSTANCE wxGetInstance();
 
513
void* Host_GetInstance()
 
514
{
 
515
        return (void*)wxGetInstance();
 
516
}
 
517
#else
 
518
void* Host_GetInstance()
 
519
{
 
520
        return NULL;
 
521
}
 
522
#endif
 
523
 
 
524
void* Host_GetRenderHandle()
 
525
{
 
526
        return main_frame->GetRenderHandle();
 
527
}
 
528
 
 
529
// OK, this thread boundary is DANGEROUS on linux
 
530
// wxPostEvent / wxAddPendingEvent is the solution.
 
531
void Host_NotifyMapLoaded()
 
532
{
 
533
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_NOTIFYMAPLOADED);
 
534
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
535
 
 
536
        if (main_frame->g_pCodeWindow)
 
537
        {
 
538
                main_frame->g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
 
539
        }
 
540
}
 
541
 
 
542
 
 
543
void Host_UpdateLogDisplay()
 
544
{
 
545
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATELOGDISPLAY);
 
546
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
547
 
 
548
        if (main_frame->g_pCodeWindow)
 
549
        {
 
550
                main_frame->g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
 
551
        }
 
552
}
 
553
 
 
554
 
 
555
void Host_UpdateDisasmDialog()
 
556
{
 
557
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEDISASMDIALOG);
 
558
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
559
 
 
560
        if (main_frame->g_pCodeWindow)
 
561
        {
 
562
                main_frame->g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
 
563
        }
 
564
}
 
565
 
 
566
 
 
567
void Host_ShowJitResults(unsigned int address)
 
568
{
 
569
        if (main_frame->g_pCodeWindow && main_frame->g_pCodeWindow->m_JitWindow)
 
570
                main_frame->g_pCodeWindow->m_JitWindow->ViewAddr(address);
 
571
}
 
572
 
 
573
void Host_UpdateMainFrame()
 
574
{
 
575
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEGUI);
 
576
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
577
 
 
578
        if (main_frame->g_pCodeWindow)
 
579
        {
 
580
                main_frame->g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
 
581
        }
 
582
}
 
583
 
 
584
void Host_UpdateTitle(const char* title)
 
585
{
 
586
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATETITLE);
 
587
        event.SetString(StrToWxStr(title));
 
588
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
589
}
 
590
 
 
591
void Host_UpdateBreakPointView()
 
592
{
 
593
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATEBREAKPOINTS);
 
594
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
595
 
 
596
        if (main_frame->g_pCodeWindow)
 
597
        {
 
598
                main_frame->g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
 
599
        }
 
600
}
 
601
 
 
602
bool Host_GetKeyState(int keycode)
 
603
{
 
604
#ifdef _WIN32
 
605
        return (0 != GetAsyncKeyState(keycode));
 
606
#elif defined __WXGTK__
 
607
        std::unique_lock<std::recursive_mutex> lk(main_frame->keystate_lock, std::try_to_lock);
 
608
        if (!lk.owns_lock())
 
609
                return false;
 
610
 
 
611
        bool key_pressed;
 
612
        if (!wxIsMainThread()) wxMutexGuiEnter();
 
613
        key_pressed = wxGetKeyState(wxKeyCode(keycode));
 
614
        if (!wxIsMainThread()) wxMutexGuiLeave();
 
615
        return key_pressed;
 
616
#else
 
617
        return wxGetKeyState(wxKeyCode(keycode));
 
618
#endif
 
619
}
 
620
 
 
621
void Host_GetRenderWindowSize(int& x, int& y, int& width, int& height)
 
622
{
 
623
        main_frame->GetRenderWindowSize(x, y, width, height);
 
624
}
 
625
 
 
626
void Host_RequestRenderWindowSize(int width, int height)
 
627
{
 
628
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_WINDOWSIZEREQUEST);
 
629
        event.SetClientData(new std::pair<int, int>(width, height));
 
630
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
631
}
 
632
 
 
633
void Host_SetStartupDebuggingParameters()
 
634
{
 
635
        SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
 
636
        if (main_frame->g_pCodeWindow)
 
637
        {
 
638
                StartUp.bBootToPause = main_frame->g_pCodeWindow->BootToPause();
 
639
                StartUp.bAutomaticStart = main_frame->g_pCodeWindow->AutomaticStart();
 
640
                StartUp.bJITNoBlockCache = main_frame->g_pCodeWindow->JITNoBlockCache();
 
641
                StartUp.bJITBlockLinking = main_frame->g_pCodeWindow->JITBlockLinking();
 
642
        }
 
643
        else
 
644
        {
 
645
                StartUp.bBootToPause = false;
 
646
        }
 
647
        StartUp.bEnableDebugging = main_frame->g_pCodeWindow ? true : false; // RUNNING_DEBUG
 
648
}
 
649
 
 
650
void Host_UpdateStatusBar(const char* _pText, int Field)
 
651
{
 
652
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATESTATUSBAR);
 
653
        // Set the event string
 
654
        event.SetString(StrToWxStr(_pText));
 
655
        // Update statusbar field
 
656
        event.SetInt(Field);
 
657
        // Post message
 
658
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
659
}
 
660
 
 
661
void Host_SetWiiMoteConnectionState(int _State)
 
662
{
 
663
        static int currentState = -1;
 
664
        if (_State == currentState)
 
665
                return;
 
666
        currentState = _State;
 
667
 
 
668
        wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATESTATUSBAR);
 
669
 
 
670
        switch(_State)
 
671
        {
 
672
        case 0: event.SetString(_("Not connected")); break;
 
673
        case 1: event.SetString(_("Connecting...")); break;
 
674
        case 2: event.SetString(_("Wiimote Connected")); break;
 
675
        }
 
676
        // Update field 1 or 2
 
677
        event.SetInt(1);
 
678
 
 
679
        NOTICE_LOG(WIIMOTE, "%s", static_cast<const char*>(event.GetString().c_str()));
 
680
 
 
681
        main_frame->GetEventHandler()->AddPendingEvent(event);
 
682
}
 
683
 
 
684
bool Host_RendererHasFocus()
 
685
{
 
686
        return main_frame->RendererHasFocus();
 
687
}
 
688
 
 
689
void Host_ConnectWiimote(int wm_idx, bool connect)
 
690
{
 
691
        CFrame::ConnectWiimote(wm_idx, connect);
 
692
}