Beispiel #1
0
void OSystem_SDL::init() {
    // Initialize SDL
    initSDL();

    if (!_logger)
        _logger = new Backends::Log::Log(this);

    if (_logger) {
        Common::WriteStream *logFile = createLogFile();
        if (logFile)
            _logger->open(logFile);
    }


    // Creates the early needed managers, if they don't exist yet
    // (we check for this to allow subclasses to provide their own).
    if (_mutexManager == 0)
        _mutexManager = new SdlMutexManager();

    if (_timerManager == 0)
        _timerManager = new SdlTimerManager();

#ifdef USE_OPENGL
    // Setup a list with both SDL and OpenGL graphics modes
    setupGraphicsModes();
#endif
}
Beispiel #2
0
void OSystem_SDL::initBackend() {
	// Check if backend has not been initialized
	assert(!_inited);

	const int maxNameLen = 20;
	char sdlDriverName[maxNameLen];
	sdlDriverName[0] = '\0';
	SDL_VideoDriverName(sdlDriverName, maxNameLen);
	// Using printf rather than debug() here as debug()/logging
	// is not active by this point.
	debug(1, "Using SDL Video Driver \"%s\"", sdlDriverName);

	// Create the default event source, in case a custom backend
	// manager didn't provide one yet.
	if (_eventSource == 0)
		_eventSource = new SdlEventSource();

#ifdef USE_OPENGL
	// Query the desktop resolution. We simply hope nothing tried to change
	// the resolution so far.
	const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
	if (videoInfo && videoInfo->current_w > 0 && videoInfo->current_h > 0) {
		_desktopWidth  = videoInfo->current_w;
		_desktopHeight = videoInfo->current_h;
	}
#endif

	if (_graphicsManager == 0) {
#ifdef USE_OPENGL
		// Setup a list with both SDL and OpenGL graphics modes. We only do
		// this whenever the subclass did not already set up an graphics
		// manager yet. This is because we don't know the type of the graphics
		// manager of the subclass, thus we cannot easily switch between the
		// OpenGL one and the set up one. It also is to be expected that the
		// subclass does not want any switching of graphics managers anyway.
		setupGraphicsModes();

		if (ConfMan.hasKey("gfx_mode")) {
			// If the gfx_mode is from OpenGL, create the OpenGL graphics manager
			Common::String gfxMode(ConfMan.get("gfx_mode"));
			for (uint i = _firstGLMode; i < _graphicsModeIds.size(); ++i) {
				if (!scumm_stricmp(_graphicsModes[i].name, gfxMode.c_str())) {
					_graphicsManager = new OpenGLSdlGraphicsManager(_desktopWidth, _desktopHeight, _eventSource);
					_graphicsMode = i;
					break;
				}
			}
		}
#endif

		if (_graphicsManager == 0) {
			_graphicsManager = new SurfaceSdlGraphicsManager(_eventSource);
		}
	}

	if (_savefileManager == 0)
		_savefileManager = new DefaultSaveFileManager();

	if (_mixerManager == 0) {
		_mixerManager = new SdlMixerManager();
		// Setup and start mixer
		_mixerManager->init();
	}

#ifdef ENABLE_EVENTRECORDER
	g_eventRec.registerMixerManager(_mixerManager);

	g_eventRec.registerTimerManager(new SdlTimerManager());
#else
	if (_timerManager == 0)
		_timerManager = new SdlTimerManager();
#endif

	if (_audiocdManager == 0) {
		// Audio CD support was removed with SDL 1.3
#if SDL_VERSION_ATLEAST(1, 3, 0)
		_audiocdManager = new DefaultAudioCDManager();
#else
		_audiocdManager = new SdlAudioCDManager();
#endif

	}

	// Setup a custom program icon.
	setupIcon();

	_inited = true;

	ModularBackend::initBackend();

	// We have to initialize the graphics manager before the event manager
	// so the virtual keyboard can be initialized, but we have to add the
	// graphics manager as an event observer after initializing the event
	// manager.
	dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager();
}