mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26544) [1.4] -Backport from trunk:
- Fix: [Windows] Crash when the operating system performs the "paint" callback during window creation [FS#5994] (r26539, r26538) - Fix: OpenBSD compilation [FS#5992] (r26523) - Fix: prevent from ever reading huge (or negative) amounts of data in strgen (r26521) - Fix: Severity rating of dedicated server messages during world generation (r26518)
This commit is contained in:
parent
b720a16a1c
commit
c57b316570
|
@ -480,7 +480,7 @@ void Blitter_32bppAnim::PaletteAnimate(const Palette &palette)
|
|||
}
|
||||
|
||||
/* Make sure the backend redraws the whole screen */
|
||||
_video_driver->MakeDirty(0, 0, _screen.width, _screen.height);
|
||||
VideoDriver::GetInstance()->MakeDirty(0, 0, _screen.width, _screen.height);
|
||||
}
|
||||
|
||||
Blitter::PaletteAnimation Blitter_32bppAnim::UsePaletteAnimation()
|
||||
|
|
|
@ -244,7 +244,7 @@ bool HandleBootstrap()
|
|||
new BootstrapAskForDownloadWindow();
|
||||
|
||||
/* Process the user events. */
|
||||
_video_driver->MainLoop();
|
||||
VideoDriver::GetInstance()->MainLoop();
|
||||
|
||||
/* _exit_game is used to get out of the video driver's main loop.
|
||||
* In case GM_BOOTSTRAP is still set we did not exit it via the
|
||||
|
|
|
@ -185,7 +185,7 @@ struct IConsoleWindow : Window
|
|||
~IConsoleWindow()
|
||||
{
|
||||
_iconsole_mode = ICONSOLE_CLOSED;
|
||||
_video_driver->EditBoxLostFocus();
|
||||
VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -374,7 +374,7 @@ struct IConsoleWindow : Window
|
|||
|
||||
virtual void OnFocusLost()
|
||||
{
|
||||
_video_driver->EditBoxLostFocus();
|
||||
VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -138,14 +138,14 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
|
|||
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
|
||||
BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
|
||||
_current_language == NULL ? "none" : _current_language->file,
|
||||
_music_driver == NULL ? "none" : _music_driver->GetName(),
|
||||
MusicDriver::GetInstance() == NULL ? "none" : MusicDriver::GetInstance()->GetName(),
|
||||
BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
|
||||
BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
|
||||
_networking ? (_network_server ? "server" : "client") : "no",
|
||||
_sound_driver == NULL ? "none" : _sound_driver->GetName(),
|
||||
SoundDriver::GetInstance() == NULL ? "none" : SoundDriver::GetInstance()->GetName(),
|
||||
BaseSounds::GetUsedSet() == NULL ? "none" : BaseSounds::GetUsedSet()->name,
|
||||
BaseSounds::GetUsedSet() == NULL ? UINT32_MAX : BaseSounds::GetUsedSet()->version,
|
||||
_video_driver == NULL ? "none" : _video_driver->GetName()
|
||||
VideoDriver::GetInstance() == NULL ? "none" : VideoDriver::GetInstance()->GetName()
|
||||
);
|
||||
|
||||
buffer += seprintf(buffer, last,
|
||||
|
@ -482,7 +482,7 @@ bool CrashLog::MakeCrashLog() const
|
|||
*/
|
||||
/* static */ void CrashLog::AfterCrashLogCleanup()
|
||||
{
|
||||
if (_music_driver != NULL) _music_driver->Stop();
|
||||
if (_sound_driver != NULL) _sound_driver->Stop();
|
||||
if (_video_driver != NULL) _video_driver->Stop();
|
||||
if (MusicDriver::GetInstance() != NULL) MusicDriver::GetInstance()->Stop();
|
||||
if (SoundDriver::GetInstance() != NULL) SoundDriver::GetInstance()->Stop();
|
||||
if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
|
||||
}
|
||||
|
|
|
@ -16,17 +16,14 @@
|
|||
#include "video/video_driver.hpp"
|
||||
#include "string_func.h"
|
||||
|
||||
VideoDriver *_video_driver; ///< The currently active video driver.
|
||||
char *_ini_videodriver; ///< The video driver a stored in the configuration file.
|
||||
int _num_resolutions; ///< The number of resolutions.
|
||||
Dimension _resolutions[32]; ///< List of resolutions.
|
||||
Dimension _cur_resolution; ///< The current resolution.
|
||||
bool _rightclick_emulate; ///< Whether right clicking is emulated.
|
||||
|
||||
SoundDriver *_sound_driver; ///< The currently active sound driver.
|
||||
char *_ini_sounddriver; ///< The sound driver a stored in the configuration file.
|
||||
|
||||
MusicDriver *_music_driver; ///< The currently active music driver.
|
||||
char *_ini_musicdriver; ///< The music driver a stored in the configuration file.
|
||||
|
||||
char *_ini_blitter; ///< The blitter as stored in the configuration file.
|
||||
|
@ -86,9 +83,25 @@ int GetDriverParamInt(const char * const *parm, const char *name, int def)
|
|||
* @param type the type of driver to select
|
||||
* @post Sets the driver so GetCurrentDriver() returns it too.
|
||||
*/
|
||||
Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
||||
void DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
||||
{
|
||||
if (GetDrivers().size() == 0) return NULL;
|
||||
if (!DriverFactoryBase::SelectDriverImpl(name, type)) {
|
||||
StrEmpty(name) ?
|
||||
usererror("Failed to autoprobe %s driver", GetDriverTypeName(type)) :
|
||||
usererror("Failed to select requested %s driver '%s'", GetDriverTypeName(type), name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the requested driver and return its class.
|
||||
* @param name the driver to select.
|
||||
* @param type the type of driver to select
|
||||
* @post Sets the driver so GetCurrentDriver() returns it too.
|
||||
* @return True upon success, otherwise false.
|
||||
*/
|
||||
bool DriverFactoryBase::SelectDriverImpl(const char *name, Driver::Type type)
|
||||
{
|
||||
if (GetDrivers().size() == 0) return false;
|
||||
|
||||
if (StrEmpty(name)) {
|
||||
/* Probe for this driver, but do not fall back to dedicated/null! */
|
||||
|
@ -101,15 +114,18 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
|||
if (d->type != type) continue;
|
||||
if (d->priority != priority) continue;
|
||||
|
||||
Driver *oldd = *GetActiveDriver(type);
|
||||
Driver *newd = d->CreateInstance();
|
||||
*GetActiveDriver(type) = newd;
|
||||
|
||||
const char *err = newd->Start(NULL);
|
||||
if (err == NULL) {
|
||||
DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
|
||||
delete *GetActiveDriver(type);
|
||||
*GetActiveDriver(type) = newd;
|
||||
return newd;
|
||||
delete oldd;
|
||||
return true;
|
||||
}
|
||||
|
||||
*GetActiveDriver(type) = oldd;
|
||||
DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
|
||||
delete newd;
|
||||
}
|
||||
|
@ -158,7 +174,7 @@ Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
|
|||
DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
|
||||
delete *GetActiveDriver(type);
|
||||
*GetActiveDriver(type) = newd;
|
||||
return newd;
|
||||
return true;
|
||||
}
|
||||
usererror("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,10 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type)
|
|||
/** Base for all driver factories. */
|
||||
class DriverFactoryBase {
|
||||
private:
|
||||
friend class MusicDriver;
|
||||
friend class SoundDriver;
|
||||
friend class VideoDriver;
|
||||
|
||||
Driver::Type type; ///< The type of driver.
|
||||
int priority; ///< The priority of this factory.
|
||||
const char *name; ///< The name of the drivers of this factory.
|
||||
|
@ -97,6 +101,8 @@ private:
|
|||
return driver_type_name[type];
|
||||
}
|
||||
|
||||
static bool SelectDriverImpl(const char *name, Driver::Type type);
|
||||
|
||||
protected:
|
||||
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description);
|
||||
|
||||
|
@ -114,7 +120,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static Driver *SelectDriver(const char *name, Driver::Type type);
|
||||
static void SelectDriver(const char *name, Driver::Type type);
|
||||
static char *GetDriversInfo(char *p, const char *last);
|
||||
|
||||
/**
|
||||
|
|
|
@ -98,7 +98,7 @@ static void _GenerateWorld(void *)
|
|||
try {
|
||||
_generating_world = true;
|
||||
_modal_progress_work_mutex->BeginCritical();
|
||||
if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
|
||||
if (_network_dedicated) DEBUG(net, 1, "Generating map, please wait...");
|
||||
/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
|
||||
if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
|
||||
_random.SetSeed(_settings_game.game_creation.generation_seed);
|
||||
|
@ -195,7 +195,7 @@ static void _GenerateWorld(void *)
|
|||
|
||||
ShowNewGRFError();
|
||||
|
||||
if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
|
||||
if (_network_dedicated) DEBUG(net, 1, "Map generated, starting game");
|
||||
DEBUG(desync, 1, "new_map: %08x", _settings_game.game_creation.generation_seed);
|
||||
|
||||
if (_debug_desync_level > 0) {
|
||||
|
@ -328,7 +328,7 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
|
|||
_gw.thread = NULL;
|
||||
}
|
||||
|
||||
if (!_video_driver->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
|
||||
if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
|
||||
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
|
||||
_gw.threaded = false;
|
||||
_modal_progress_work_mutex->EndCritical();
|
||||
|
|
12
src/gfx.cpp
12
src/gfx.cpp
|
@ -85,7 +85,7 @@ void GfxScroll(int left, int top, int width, int height, int xo, int yo)
|
|||
|
||||
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
|
||||
/* This part of the screen is now dirty. */
|
||||
_video_driver->MakeDirty(left, top, width, height);
|
||||
VideoDriver::GetInstance()->MakeDirty(left, top, width, height);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1183,7 +1183,7 @@ void UndrawMouseCursor()
|
|||
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
|
||||
_cursor.visible = false;
|
||||
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup.GetBuffer(), _cursor.draw_size.x, _cursor.draw_size.y);
|
||||
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
||||
VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1243,7 +1243,7 @@ void DrawMouseCursor()
|
|||
_cur_dpi = &_screen;
|
||||
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x + _cursor.short_vehicle_offset, _cursor.pos.y);
|
||||
|
||||
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
||||
VideoDriver::GetInstance()->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
||||
|
||||
_cursor.visible = true;
|
||||
_cursor.dirty = false;
|
||||
|
@ -1267,7 +1267,7 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
|
|||
|
||||
DrawOverlappedWindowForAll(left, top, right, bottom);
|
||||
|
||||
_video_driver->MakeDirty(left, top, right - left, bottom - top);
|
||||
VideoDriver::GetInstance()->MakeDirty(left, top, right - left, bottom - top);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1576,12 +1576,12 @@ void SetAnimatedMouseCursor(const AnimCursor *table)
|
|||
|
||||
bool ChangeResInGame(int width, int height)
|
||||
{
|
||||
return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height);
|
||||
return (_screen.width == width && _screen.height == height) || VideoDriver::GetInstance()->ChangeResolution(width, height);
|
||||
}
|
||||
|
||||
bool ToggleFullScreen(bool fs)
|
||||
{
|
||||
bool result = _video_driver->ToggleFullscreen(fs);
|
||||
bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
|
||||
if (_fullscreen != fs && _num_resolutions == 0) {
|
||||
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
|
||||
}
|
||||
|
|
|
@ -282,9 +282,9 @@ static bool SwitchNewGRFBlitter()
|
|||
break;
|
||||
}
|
||||
|
||||
if (!_video_driver->AfterBlitterChange()) {
|
||||
if (!VideoDriver::GetInstance()->AfterBlitterChange()) {
|
||||
/* Failed to switch blitter, let's hope we can return to the old one. */
|
||||
if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !_video_driver->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
|
||||
if (BlitterFactory::SelectBlitter(cur_blitter) == NULL || !VideoDriver::GetInstance()->AfterBlitterChange()) usererror("Failed to reinitialize video driver. Specify a fixed blitter in the config");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -35,8 +35,8 @@ static FMusicDriver_ExtMidi iFMusicDriver_ExtMidi;
|
|||
|
||||
const char *MusicDriver_ExtMidi::Start(const char * const * parm)
|
||||
{
|
||||
if (strcmp(_video_driver->GetName(), "allegro") == 0 ||
|
||||
strcmp(_sound_driver->GetName(), "allegro") == 0) {
|
||||
if (strcmp(VideoDriver::GetInstance()->GetName(), "allegro") == 0 ||
|
||||
strcmp(SoundDriver::GetInstance()->GetName(), "allegro") == 0) {
|
||||
return "the extmidi driver does not work when Allegro is loaded.";
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,15 @@ public:
|
|||
* @param vol The new volume.
|
||||
*/
|
||||
virtual void SetVolume(byte vol) = 0;
|
||||
|
||||
/**
|
||||
* Get the currently active instance of the music driver.
|
||||
*/
|
||||
static MusicDriver *GetInstance() {
|
||||
return static_cast<MusicDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_MUSIC));
|
||||
}
|
||||
};
|
||||
|
||||
extern MusicDriver *_music_driver;
|
||||
extern char *_ini_musicdriver;
|
||||
|
||||
#endif /* MUSIC_MUSIC_DRIVER_HPP */
|
||||
|
|
|
@ -174,7 +174,7 @@ static void SkipToNextSong()
|
|||
|
||||
static void MusicVolumeChanged(byte new_vol)
|
||||
{
|
||||
_music_driver->SetVolume(new_vol);
|
||||
MusicDriver::GetInstance()->SetVolume(new_vol);
|
||||
}
|
||||
|
||||
static void DoPlaySong()
|
||||
|
@ -183,13 +183,13 @@ static void DoPlaySong()
|
|||
if (FioFindFullPath(filename, lengthof(filename), BASESET_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename) == NULL) {
|
||||
FioFindFullPath(filename, lengthof(filename), OLD_GM_DIR, BaseMusic::GetUsedSet()->files[_music_wnd_cursong - 1].filename);
|
||||
}
|
||||
_music_driver->PlaySong(filename);
|
||||
MusicDriver::GetInstance()->PlaySong(filename);
|
||||
SetWindowDirty(WC_MUSIC_WINDOW, 0);
|
||||
}
|
||||
|
||||
static void DoStopMusic()
|
||||
{
|
||||
_music_driver->StopSong();
|
||||
MusicDriver::GetInstance()->StopSong();
|
||||
SetWindowDirty(WC_MUSIC_WINDOW, 0);
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ void MusicLoop()
|
|||
|
||||
if (!_song_is_active) return;
|
||||
|
||||
if (!_music_driver->IsSongPlaying()) {
|
||||
if (!MusicDriver::GetInstance()->IsSongPlaying()) {
|
||||
if (_game_mode != GM_MENU) {
|
||||
StopMusic();
|
||||
SkipToNextSong();
|
||||
|
|
|
@ -167,7 +167,7 @@ void NetworkUndrawChatMessage()
|
|||
/* Put our 'shot' back to the screen */
|
||||
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup, width, height);
|
||||
/* And make sure it is updated next time */
|
||||
_video_driver->MakeDirty(x, y, width, height);
|
||||
VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
|
||||
|
||||
_chatmessage_dirty = true;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ void NetworkDrawChatMessage()
|
|||
}
|
||||
|
||||
/* Make sure the data is updated next flush */
|
||||
_video_driver->MakeDirty(x, y, width, height);
|
||||
VideoDriver::GetInstance()->MakeDirty(x, y, width, height);
|
||||
|
||||
_chatmessage_visible = true;
|
||||
_chatmessage_dirty = false;
|
||||
|
|
|
@ -773,7 +773,7 @@ void ScanNewGRFFiles(NewGRFScanCallback *callback)
|
|||
/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
|
||||
MarkWholeScreenDirty();
|
||||
|
||||
if (!_video_driver->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
|
||||
if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
|
||||
_modal_progress_work_mutex->EndCritical();
|
||||
_modal_progress_paint_mutex->EndCritical();
|
||||
DoScanNewGRFFiles(callback);
|
||||
|
|
|
@ -95,7 +95,7 @@ void CDECL usererror(const char *s, ...)
|
|||
va_end(va);
|
||||
|
||||
ShowOSErrorBox(buf, false);
|
||||
if (_video_driver != NULL) _video_driver->Stop();
|
||||
if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
@ -341,7 +341,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
|
|||
CheckForMissingGlyphs();
|
||||
|
||||
/* Play main theme */
|
||||
if (_music_driver->IsSongPlaying()) ResetMusic();
|
||||
if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
|
||||
}
|
||||
|
||||
void MakeNewgameSettingsLive()
|
||||
|
@ -434,7 +434,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
|
|||
*save_config_ptr = save_config;
|
||||
|
||||
/* restore saved music volume */
|
||||
_music_driver->SetVolume(_settings_client.music.music_vol);
|
||||
MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
|
||||
|
||||
if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
|
||||
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
|
||||
|
@ -766,12 +766,7 @@ int openttd_main(int argc, char *argv[])
|
|||
free(blitter);
|
||||
|
||||
if (videodriver == NULL && _ini_videodriver != NULL) videodriver = strdup(_ini_videodriver);
|
||||
_video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
||||
if (_video_driver == NULL) {
|
||||
StrEmpty(videodriver) ?
|
||||
usererror("Failed to autoprobe video driver") :
|
||||
usererror("Failed to select requested video driver '%s'", videodriver);
|
||||
}
|
||||
DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
||||
free(videodriver);
|
||||
|
||||
InitializeSpriteSorter();
|
||||
|
@ -802,7 +797,7 @@ int openttd_main(int argc, char *argv[])
|
|||
goto exit_bootstrap;
|
||||
}
|
||||
|
||||
_video_driver->ClaimMousePointer();
|
||||
VideoDriver::GetInstance()->ClaimMousePointer();
|
||||
|
||||
/* initialize screenshot formats */
|
||||
InitializeScreenshotFormats();
|
||||
|
@ -834,21 +829,11 @@ int openttd_main(int argc, char *argv[])
|
|||
free(music_set);
|
||||
|
||||
if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = strdup(_ini_sounddriver);
|
||||
_sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
||||
if (_sound_driver == NULL) {
|
||||
StrEmpty(sounddriver) ?
|
||||
usererror("Failed to autoprobe sound driver") :
|
||||
usererror("Failed to select requested sound driver '%s'", sounddriver);
|
||||
}
|
||||
DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
||||
free(sounddriver);
|
||||
|
||||
if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = strdup(_ini_musicdriver);
|
||||
_music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
||||
if (_music_driver == NULL) {
|
||||
StrEmpty(musicdriver) ?
|
||||
usererror("Failed to autoprobe music driver") :
|
||||
usererror("Failed to select requested music driver '%s'", musicdriver);
|
||||
}
|
||||
DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
||||
free(musicdriver);
|
||||
|
||||
/* Take our initial lock on whatever we might want to do! */
|
||||
|
@ -866,7 +851,7 @@ int openttd_main(int argc, char *argv[])
|
|||
ScanNewGRFFiles(scanner);
|
||||
scanner = NULL;
|
||||
|
||||
_video_driver->MainLoop();
|
||||
VideoDriver::GetInstance()->MainLoop();
|
||||
|
||||
WaitTillSaved();
|
||||
|
||||
|
@ -934,7 +919,7 @@ static void MakeNewGameDone()
|
|||
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
|
||||
|
||||
/* In a dedicated server, the server does not play */
|
||||
if (!_video_driver->HasGUI()) {
|
||||
if (!VideoDriver::GetInstance()->HasGUI()) {
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
||||
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
||||
|
@ -1500,6 +1485,6 @@ void GameLoop()
|
|||
|
||||
InputLoop();
|
||||
|
||||
_sound_driver->MainLoop();
|
||||
SoundDriver::GetInstance()->MainLoop();
|
||||
MusicLoop();
|
||||
}
|
||||
|
|
|
@ -337,9 +337,18 @@ uint GetCPUCoreCount()
|
|||
int ncpu = 0;
|
||||
size_t len = sizeof(ncpu);
|
||||
|
||||
#ifdef OPENBSD
|
||||
int name[2];
|
||||
name[0] = CTL_HW;
|
||||
name[1] = HW_NCPU;
|
||||
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
|
||||
ncpu = 0;
|
||||
}
|
||||
#else
|
||||
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
|
||||
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
|
||||
}
|
||||
#endif /* #ifdef OPENBSD */
|
||||
|
||||
if (ncpu > 0) count = ncpu;
|
||||
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||
|
|
|
@ -521,7 +521,7 @@ static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep)
|
|||
/* Close any possible log files */
|
||||
CloseConsoleLogIfActive();
|
||||
|
||||
if ((_video_driver == NULL || _video_driver->HasGUI()) && _safe_esp != NULL) {
|
||||
if ((VideoDriver::GetInstance() == NULL || VideoDriver::GetInstance()->HasGUI()) && _safe_esp != NULL) {
|
||||
#ifdef _M_AMD64
|
||||
ep->ContextRecord->Rip = (DWORD64)ShowCrashlogWindow;
|
||||
ep->ContextRecord->Rsp = (DWORD64)_safe_esp;
|
||||
|
|
|
@ -206,7 +206,7 @@ struct OskWindow : public Window {
|
|||
|
||||
virtual void OnFocusLost()
|
||||
{
|
||||
_video_driver->EditBoxLostFocus();
|
||||
VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
delete this;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -19,9 +19,15 @@ class SoundDriver : public Driver {
|
|||
public:
|
||||
/** Called once every tick */
|
||||
virtual void MainLoop() {}
|
||||
|
||||
/**
|
||||
* Get the currently active instance of the sound driver.
|
||||
*/
|
||||
static SoundDriver *GetInstance() {
|
||||
return static_cast<SoundDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_SOUND));
|
||||
}
|
||||
};
|
||||
|
||||
extern SoundDriver *_sound_driver;
|
||||
extern char *_ini_sounddriver;
|
||||
|
||||
#endif /* SOUND_SOUND_DRIVER_HPP */
|
||||
|
|
|
@ -122,7 +122,7 @@ struct FileStringReader : StringReader {
|
|||
|
||||
/* virtual */ char *ReadLine(char *buffer, size_t size)
|
||||
{
|
||||
return fgets(buffer, size, this->fh);
|
||||
return fgets(buffer, ClampToU16(size), this->fh);
|
||||
}
|
||||
|
||||
/* virtual */ void HandlePragma(char *str);
|
||||
|
|
|
@ -597,16 +597,16 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
|||
_cocoa_video_dialog = true;
|
||||
|
||||
bool wasstarted = _cocoa_video_started;
|
||||
if (_video_driver == NULL) {
|
||||
if (VideoDriver::GetInstance() == NULL) {
|
||||
setupApplication(); // Setup application before showing dialog
|
||||
} else if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {
|
||||
} else if (!_cocoa_video_started && VideoDriver::GetInstance()->Start(NULL) != NULL) {
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
return;
|
||||
}
|
||||
|
||||
NSRunAlertPanel([ NSString stringWithUTF8String:title ], [ NSString stringWithUTF8String:message ], [ NSString stringWithUTF8String:buttonLabel ], nil, nil);
|
||||
|
||||
if (!wasstarted && _video_driver != NULL) _video_driver->Stop();
|
||||
if (!wasstarted && VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
|
||||
|
||||
_cocoa_video_dialog = false;
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow
|
|||
case QZ_RETURN:
|
||||
case QZ_f:
|
||||
if (down && (_current_mods & NSCommandKeyMask)) {
|
||||
_video_driver->ToggleFullscreen(!_fullscreen);
|
||||
VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -409,7 +409,7 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h)
|
|||
break;
|
||||
|
||||
case Blitter::PALETTE_ANIMATION_BLITTER:
|
||||
if (_video_driver != NULL) blitter->PaletteAnimate(_local_palette);
|
||||
if (VideoDriver::GetInstance() != NULL) blitter->PaletteAnimate(_local_palette);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -78,9 +78,15 @@ public:
|
|||
* An edit box lost the input focus. Abort character compositing if necessary.
|
||||
*/
|
||||
virtual void EditBoxLostFocus() {}
|
||||
|
||||
/**
|
||||
* Get the currently active instance of the video driver.
|
||||
*/
|
||||
static VideoDriver *GetInstance() {
|
||||
return static_cast<VideoDriver*>(*DriverFactoryBase::GetActiveDriver(Driver::DT_VIDEO));
|
||||
}
|
||||
};
|
||||
|
||||
extern VideoDriver *_video_driver;
|
||||
extern char *_ini_videodriver;
|
||||
extern int _num_resolutions;
|
||||
extern Dimension _resolutions[32];
|
||||
|
|
|
@ -1003,7 +1003,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
|
|||
if (active && minimized) {
|
||||
/* Restore the game window */
|
||||
ShowWindow(hwnd, SW_RESTORE);
|
||||
static_cast<VideoDriver_Win32 *>(_video_driver)->MakeWindow(true);
|
||||
static_cast<VideoDriver_Win32 *>(VideoDriver::GetInstance())->MakeWindow(true);
|
||||
} else if (!active && !minimized) {
|
||||
/* Minimise the window and restore desktop */
|
||||
ShowWindow(hwnd, SW_MINIMIZE);
|
||||
|
|
|
@ -446,7 +446,7 @@ bool EditBoxInGlobalFocus()
|
|||
void Window::UnfocusFocusedWidget()
|
||||
{
|
||||
if (this->nested_focus != NULL) {
|
||||
if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
|
||||
if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
|
||||
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
|
||||
this->nested_focus->SetDirty(this);
|
||||
|
@ -470,7 +470,7 @@ bool Window::SetFocusedWidget(int widget_index)
|
|||
|
||||
/* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
|
||||
this->nested_focus->SetDirty(this);
|
||||
if (this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
|
||||
if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
}
|
||||
this->nested_focus = this->GetWidget<NWidgetCore>(widget_index);
|
||||
return true;
|
||||
|
@ -481,7 +481,7 @@ bool Window::SetFocusedWidget(int widget_index)
|
|||
*/
|
||||
void Window::OnFocusLost()
|
||||
{
|
||||
if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) _video_driver->EditBoxLostFocus();
|
||||
if (this->nested_focus != NULL && this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue