mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [OSX] Drain autoreleased objects in each game loop cycle.
parent
8aaf4ea098
commit
60f30036f1
|
@ -203,6 +203,7 @@ bool CocoaSetupApplication()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Become the front process, important when start from the command line. */
|
/* Become the front process, important when start from the command line. */
|
||||||
|
[ [ NSApplication sharedApplication ] setActivationPolicy:NSApplicationActivationPolicyRegular ];
|
||||||
[ [ NSApplication sharedApplication ] activateIgnoringOtherApps:YES ];
|
[ [ NSApplication sharedApplication ] activateIgnoringOtherApps:YES ];
|
||||||
|
|
||||||
/* Set up the menubar */
|
/* Set up the menubar */
|
||||||
|
@ -247,15 +248,17 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSAlert *alert = [ [ NSAlert alloc ] init ];
|
@autoreleasepool {
|
||||||
[ alert setAlertStyle: NSCriticalAlertStyle ];
|
NSAlert *alert = [ [ NSAlert alloc ] init ];
|
||||||
[ alert setMessageText:[ NSString stringWithUTF8String:title ] ];
|
[ alert setAlertStyle: NSCriticalAlertStyle ];
|
||||||
[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ];
|
[ alert setMessageText:[ NSString stringWithUTF8String:title ] ];
|
||||||
[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ];
|
[ alert setInformativeText:[ NSString stringWithUTF8String:message ] ];
|
||||||
[ alert runModal ];
|
[ alert addButtonWithTitle: [ NSString stringWithUTF8String:buttonLabel ] ];
|
||||||
[ alert release ];
|
[ alert runModal ];
|
||||||
|
[ alert release ];
|
||||||
|
}
|
||||||
|
|
||||||
if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
|
if (!wasstarted && VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
|
||||||
|
|
||||||
_cocoa_video_dialog = false;
|
_cocoa_video_dialog = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,57 +609,60 @@ void VideoDriver_Cocoa::GameLoop()
|
||||||
this->Draw(true);
|
this->Draw(true);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
|
@autoreleasepool {
|
||||||
InteractiveRandom(); // randomness
|
|
||||||
|
|
||||||
while (this->PollEvent()) {}
|
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
|
||||||
|
InteractiveRandom(); // randomness
|
||||||
|
|
||||||
if (_exit_game) {
|
while (this->PollEvent()) {}
|
||||||
/* Restore saved resolution if in fullscreen mode. */
|
|
||||||
if (this->IsFullscreen()) _cur_resolution = this->orig_res;
|
if (_exit_game) {
|
||||||
break;
|
/* Restore saved resolution if in fullscreen mode. */
|
||||||
}
|
if (this->IsFullscreen()) _cur_resolution = this->orig_res;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_DEBUG)
|
#if defined(_DEBUG)
|
||||||
if (_current_mods & NSShiftKeyMask)
|
if (_current_mods & NSShiftKeyMask)
|
||||||
#else
|
#else
|
||||||
if (_tab_is_down)
|
if (_tab_is_down)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
|
||||||
} else if (_fast_forward & 2) {
|
} else if (_fast_forward & 2) {
|
||||||
_fast_forward = 0;
|
_fast_forward = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_ticks = GetTick();
|
cur_ticks = GetTick();
|
||||||
if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
|
if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
|
||||||
_realtime_tick += cur_ticks - last_cur_ticks;
|
_realtime_tick += cur_ticks - last_cur_ticks;
|
||||||
last_cur_ticks = cur_ticks;
|
last_cur_ticks = cur_ticks;
|
||||||
next_tick = cur_ticks + MILLISECONDS_PER_TICK;
|
next_tick = cur_ticks + MILLISECONDS_PER_TICK;
|
||||||
|
|
||||||
bool old_ctrl_pressed = _ctrl_pressed;
|
bool old_ctrl_pressed = _ctrl_pressed;
|
||||||
|
|
||||||
_ctrl_pressed = !!(_current_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
|
_ctrl_pressed = !!(_current_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
|
||||||
_shift_pressed = !!(_current_mods & NSShiftKeyMask);
|
_shift_pressed = !!(_current_mods & NSShiftKeyMask);
|
||||||
|
|
||||||
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
|
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
|
||||||
|
|
||||||
::GameLoop();
|
::GameLoop();
|
||||||
|
|
||||||
UpdateWindows();
|
UpdateWindows();
|
||||||
this->CheckPaletteAnim();
|
this->CheckPaletteAnim();
|
||||||
this->Draw();
|
this->Draw();
|
||||||
} else {
|
} else {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
uint32 st0 = GetTick();
|
uint32 st0 = GetTick();
|
||||||
#endif
|
#endif
|
||||||
CSleep(1);
|
CSleep(1);
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
st += GetTick() - st0;
|
st += GetTick() - st0;
|
||||||
#endif
|
#endif
|
||||||
NetworkDrawChatMessage();
|
NetworkDrawChatMessage();
|
||||||
DrawMouseCursor();
|
DrawMouseCursor();
|
||||||
this->Draw();
|
this->Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue