Skip to content

Commit

Permalink
RECORDER: Implement Events Recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed May 16, 2013
1 parent 4a62d6c commit f59512c
Show file tree
Hide file tree
Showing 98 changed files with 4,633 additions and 1,201 deletions.
13 changes: 8 additions & 5 deletions audio/mixer.cpp
Expand Up @@ -20,6 +20,8 @@
*
*/

#include "gui/EventRecorder.h"

#include "common/util.h"
#include "common/system.h"
#include "common/textconsole.h"
Expand Down Expand Up @@ -427,6 +429,7 @@ void MixerImpl::pauseHandle(SoundHandle handle, bool paused) {

bool MixerImpl::isSoundIDActive(int id) {
Common::StackLock lock(_mutex);
g_eventRec.updateSubsystems();
for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i] && _channels[i]->getId() == id)
return true;
Expand All @@ -443,6 +446,7 @@ int MixerImpl::getSoundID(SoundHandle handle) {

bool MixerImpl::isSoundHandleActive(SoundHandle handle) {
Common::StackLock lock(_mutex);
g_eventRec.updateSubsystems();
const int index = handle._val % NUM_CHANNELS;
return _channels[index] && _channels[index]->getHandle()._val == handle._val;
}
Expand Down Expand Up @@ -556,12 +560,12 @@ void Channel::pause(bool paused) {
_pauseLevel++;

if (_pauseLevel == 1)
_pauseStartTime = g_system->getMillis();
_pauseStartTime = g_system->getMillis(true);
} else if (_pauseLevel > 0) {
_pauseLevel--;

if (!_pauseLevel) {
_pauseTime = (g_system->getMillis() - _pauseStartTime);
_pauseTime = (g_system->getMillis(true) - _pauseStartTime);
_pauseStartTime = 0;
}
}
Expand All @@ -579,7 +583,7 @@ Timestamp Channel::getElapsedTime() {
if (isPaused())
delta = _pauseStartTime - _mixerTimeStamp;
else
delta = g_system->getMillis() - _mixerTimeStamp - _pauseTime;
delta = g_system->getMillis(true) - _mixerTimeStamp - _pauseTime;

// Convert the number of samples into a time duration.

Expand All @@ -599,13 +603,12 @@ int Channel::mix(int16 *data, uint len) {
assert(_stream);

int res = 0;

if (_stream->endOfData()) {
// TODO: call drain method
} else {
assert(_converter);
_samplesConsumed = _samplesDecoded;
_mixerTimeStamp = g_system->getMillis();
_mixerTimeStamp = g_system->getMillis(true);
_pauseTime = 0;
res = _converter->flow(*_stream, data, len, _volL, _volR);
_samplesDecoded += res;
Expand Down
3 changes: 2 additions & 1 deletion backends/events/default/default-events.cpp
Expand Up @@ -84,7 +84,8 @@ void DefaultEventManager::init() {
}

bool DefaultEventManager::pollEvent(Common::Event &event) {
uint32 time = g_system->getMillis();
// Skip recording of these events
uint32 time = g_system->getMillis(true);
bool result = false;

_dispatcher.dispatch();
Expand Down
4 changes: 3 additions & 1 deletion backends/events/sdl/sdl-events.cpp
Expand Up @@ -106,7 +106,9 @@ void SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) {
}

void SdlEventSource::handleKbdMouse() {
uint32 curTime = g_system->getMillis();
// Skip recording of these events
uint32 curTime = g_system->getMillis(true);

if (curTime >= _km.last_time + _km.delay_time) {
_km.last_time = curTime;
if (_km.x_down_count == 1) {
Expand Down
30 changes: 25 additions & 5 deletions backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -40,6 +40,7 @@
#include "graphics/scaler.h"
#include "graphics/scaler/aspect.h"
#include "graphics/surface.h"
#include "gui/EventRecorder.h"

static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{"1x", _s("Normal (no scaling)"), GFX_NORMAL},
Expand Down Expand Up @@ -135,6 +136,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
_paletteDirtyStart(0), _paletteDirtyEnd(0),
_screenIsLocked(false),
_graphicsMutex(0),
_displayDisabled(false),
#ifdef USE_SDL_DEBUG_FOCUSRECT
_enableFocusRectDebugCode(false), _enableFocusRect(false), _focusRect(),
#endif
Expand Down Expand Up @@ -765,9 +767,20 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
fixupResolutionForAspectRatio(_videoMode.desiredAspectRatio, _videoMode.hardwareWidth, _videoMode.hardwareHeight);
}

_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16,
_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
);

#ifdef ENABLE_KEYMAPPER
_displayDisabled = ConfMan.getBool("disable_display");

if (_displayDisabled) {
_hwscreen = g_eventRec.getSurface(_videoMode.hardwareWidth, _videoMode.hardwareHeight);
} else
#endif
{
_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 16,
_videoMode.fullscreen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE
);
}

#ifdef USE_RGB_COLOR
detectSupportedFormats();
#endif
Expand Down Expand Up @@ -865,7 +878,12 @@ void SurfaceSdlGraphicsManager::unloadGFXMode() {
}

if (_hwscreen) {
SDL_FreeSurface(_hwscreen);
if (_displayDisabled) {
delete _hwscreen;
} else {
SDL_FreeSurface(_hwscreen);
}

_hwscreen = NULL;
}

Expand Down Expand Up @@ -1188,7 +1206,9 @@ void SurfaceSdlGraphicsManager::internUpdateScreen() {
#endif

// Finally, blit all our changes to the screen
SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList);
if (!_displayDisabled) {
SDL_UpdateRects(_hwscreen, _numDirtyRects, _dirtyRectList);
}
}

_numDirtyRects = 0;
Expand Down
3 changes: 3 additions & 0 deletions backends/graphics/surfacesdl/surfacesdl-graphics.h
Expand Up @@ -232,6 +232,9 @@ class SurfaceSdlGraphicsManager : public GraphicsManager, public SdlGraphicsMana
int _scalerType;
int _transactionMode;

// Indicates whether it is needed to free _hwsurface in destructor
bool _displayDisabled;

bool _screenIsLocked;
Graphics::Surface _framebuffer;

Expand Down
75 changes: 75 additions & 0 deletions backends/mixer/nullmixer/nullsdl-mixer.cpp
@@ -0,0 +1,75 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "backends/mixer/nullmixer/nullsdl-mixer.h"
#include "common/savefile.h"

NullSdlMixerManager::NullSdlMixerManager() : SdlMixerManager() {
_outputRate = 22050;
_callsCounter = 0;
_callbackPeriod = 10;
_samples = 8192;
while (_samples * 16 > _outputRate * 2)
_samples >>= 1;
_samplesBuf = new uint8[_samples * 4];
}

NullSdlMixerManager::~NullSdlMixerManager() {
delete _samplesBuf;
}

void NullSdlMixerManager::init() {
_mixer = new Audio::MixerImpl(g_system, _outputRate);
assert(_mixer);
_mixer->setReady(true);
}

void NullSdlMixerManager::suspendAudio() {
_audioSuspended = true;
}

int NullSdlMixerManager::resumeAudio() {
if (!_audioSuspended) {
return -2;
}
_audioSuspended = false;
return 0;
}


void NullSdlMixerManager::startAudio() {
}

void NullSdlMixerManager::callbackHandler(byte *samples, int len) {
assert(_mixer);
_mixer->mixCallback(samples, len);
}

void NullSdlMixerManager::update() {
if (_audioSuspended) {
return;
}
_callsCounter++;
if ((_callsCounter % _callbackPeriod) == 0) {
callbackHandler(_samplesBuf, _samples);
}
}
62 changes: 62 additions & 0 deletions backends/mixer/nullmixer/nullsdl-mixer.h
@@ -0,0 +1,62 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef BACKENDS_MIXER_NULLSDL_H
#define BACKENDS_MIXER_NULLSDL_H

#include "backends/mixer/sdl/sdl-mixer.h"
#include "common/str.h"

/** Audio mixer which in fact does not output audio.
*
* It is used by events recorder since the recorder is intentionally
* turning sound off to avoid stuttering.
*
* It returns correct output and shoots callbacks, so all OSystem
* users could work without modifications.
*/

class NullSdlMixerManager : public SdlMixerManager {
public:
NullSdlMixerManager();
virtual ~NullSdlMixerManager();

virtual void init();
void update();

virtual void suspendAudio();
virtual int resumeAudio();

protected:

virtual void startAudio();
virtual void callbackHandler(byte *samples, int len);

private:
uint32 _outputRate;
uint32 _callsCounter;
uint8 _callbackPeriod;
uint32 _samples;
uint8 *_samplesBuf;
};

#endif
3 changes: 3 additions & 0 deletions backends/modular-backend.cpp
Expand Up @@ -26,6 +26,7 @@

#include "backends/graphics/graphics.h"
#include "backends/mutex/mutex.h"
#include "gui/EventRecorder.h"

#include "audio/mixer.h"
#include "graphics/pixelformat.h"
Expand Down Expand Up @@ -141,7 +142,9 @@ void ModularBackend::fillScreen(uint32 col) {
}

void ModularBackend::updateScreen() {
g_eventRec.preDrawOverlayGui();
_graphicsManager->updateScreen();
g_eventRec.postDrawOverlayGui();
}

void ModularBackend::setShakePos(int shakeOffset) {
Expand Down
8 changes: 7 additions & 1 deletion backends/module.mk
Expand Up @@ -70,7 +70,7 @@ MODULE_OBJS += \
mutex/sdl/sdl-mutex.o \
plugins/sdl/sdl-provider.o \
timer/sdl/sdl-timer.o

# SDL 1.3 removed audio CD support
ifndef USE_SDL13
MODULE_OBJS += \
Expand Down Expand Up @@ -214,5 +214,11 @@ MODULE_OBJS += \
plugins/wii/wii-provider.o
endif

ifdef ENABLE_EVENTRECORDER
MODULE_OBJS += \
mixer/nullmixer/nullsdl-mixer.o \
saves/recorder/recorder-saves.o
endif

# Include common rules
include $(srcdir)/rules.mk
6 changes: 3 additions & 3 deletions backends/mutex/sdl/sdl-mutex.cpp
Expand Up @@ -33,15 +33,15 @@ OSystem::MutexRef SdlMutexManager::createMutex() {
}

void SdlMutexManager::lockMutex(OSystem::MutexRef mutex) {
SDL_mutexP((SDL_mutex *) mutex);
SDL_mutexP((SDL_mutex *)mutex);
}

void SdlMutexManager::unlockMutex(OSystem::MutexRef mutex) {
SDL_mutexV((SDL_mutex *) mutex);
SDL_mutexV((SDL_mutex *)mutex);
}

void SdlMutexManager::deleteMutex(OSystem::MutexRef mutex) {
SDL_DestroyMutex((SDL_mutex *) mutex);
SDL_DestroyMutex((SDL_mutex *)mutex);
}

#endif
2 changes: 1 addition & 1 deletion backends/platform/android/android.cpp
Expand Up @@ -450,7 +450,7 @@ bool OSystem_Android::getFeatureState(Feature f) {
}
}

uint32 OSystem_Android::getMillis() {
uint32 OSystem_Android::getMillis(bool skipRecord) {
timeval curTime;

gettimeofday(&curTime, 0);
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/android/android.h
Expand Up @@ -274,7 +274,7 @@ class OSystem_Android : public EventsBaseBackend, public PaletteManager {
virtual void setCursorPalette(const byte *colors, uint start, uint num);

virtual bool pollEvent(Common::Event &event);
virtual uint32 getMillis();
virtual uint32 getMillis(bool skipRecord = false);
virtual void delayMillis(uint msecs);

virtual MutexRef createMutex(void);
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/bada/system.cpp
Expand Up @@ -373,7 +373,7 @@ bool BadaSystem::pollEvent(Common::Event &event) {
return _appForm->pollEvent(event);
}

uint32 BadaSystem::getMillis() {
uint32 BadaSystem::getMillis(bool skipRecord) {
long long result, ticks = 0;
SystemTime::GetTicks(ticks);
result = ticks - _epoch;
Expand Down
2 changes: 1 addition & 1 deletion backends/platform/bada/system.h
Expand Up @@ -83,7 +83,7 @@ class BadaSystem : public ModularBackend,

void updateScreen();
bool pollEvent(Common::Event &event);
uint32 getMillis();
uint32 getMillis(bool skipRecord = false);
void delayMillis(uint msecs);
void getTimeAndDate(TimeDate &t) const;
void fatalError();
Expand Down

0 comments on commit f59512c

Please sign in to comment.