Skip to content

Commit

Permalink
Merge pull request #44 from fingolfin/modular-osystem
Browse files Browse the repository at this point in the history
Modularize OSystem some more
  • Loading branch information
fingolfin committed Jun 8, 2011
2 parents b5bb412 + c701bdb commit 5e5661b
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 262 deletions.
26 changes: 2 additions & 24 deletions backends/modular-backend.cpp
Expand Up @@ -30,31 +30,24 @@

#include "audio/mixer.h"
#include "common/events.h"
#include "common/timer.h"
#include "common/savefile.h"
#include "gui/message.h"
#include "graphics/pixelformat.h"

ModularBackend::ModularBackend()
:
_fsFactory(0),
_savefileManager(0),
_timerManager(0),
_mutexManager(0),
_graphicsManager(0),
_mixer(0) {

}

ModularBackend::~ModularBackend() {
delete _fsFactory;
_fsFactory = 0;
delete _graphicsManager;
_graphicsManager = 0;
delete _mixer;
_mixer = 0;
delete _savefileManager;
_savefileManager = 0;
delete _timerManager;
_timerManager = 0;
delete _mutexManager;
_mutexManager = 0;
}
Expand Down Expand Up @@ -215,11 +208,6 @@ void ModularBackend::setCursorPalette(const byte *colors, uint start, uint num)
_graphicsManager->setCursorPalette(colors, start, num);
}

Common::TimerManager *ModularBackend::getTimerManager() {
assert(_timerManager);
return _timerManager;
}

OSystem::MutexRef ModularBackend::createMutex() {
assert(_mutexManager);
return _mutexManager->createMutex();
Expand Down Expand Up @@ -249,16 +237,6 @@ void ModularBackend::displayMessageOnOSD(const char *msg) {
_graphicsManager->displayMessageOnOSD(msg);
}

Common::SaveFileManager *ModularBackend::getSavefileManager() {
assert(_savefileManager);
return _savefileManager;
}

FilesystemFactory *ModularBackend::getFilesystemFactory() {
assert(_fsFactory);
return _fsFactory;
}

void ModularBackend::quit() {
exit(0);
}
8 changes: 0 additions & 8 deletions backends/modular-backend.h
Expand Up @@ -24,8 +24,6 @@
#define BACKENDS_MODULAR_BACKEND_H

#include "common/system.h"
#include "common/timer.h"
#include "common/savefile.h"

class GraphicsManager;
class MutexManager;
Expand Down Expand Up @@ -110,7 +108,6 @@ class ModularBackend : public OSystem {
/** @name Events and Time */
//@{

virtual Common::TimerManager *getTimerManager();
virtual Common::HardwareKeySet *getHardwareKeySet() { return 0; }

//@}
Expand All @@ -135,8 +132,6 @@ class ModularBackend : public OSystem {
/** @name Miscellaneous */
//@{

virtual Common::SaveFileManager *getSavefileManager();
virtual FilesystemFactory *getFilesystemFactory();
virtual void quit();
virtual void displayMessageOnOSD(const char *msg);

Expand All @@ -146,9 +141,6 @@ class ModularBackend : public OSystem {
/** @name Managers variables */
//@{

FilesystemFactory *_fsFactory;
Common::SaveFileManager *_savefileManager;
Common::TimerManager *_timerManager;
MutexManager *_mutexManager;
GraphicsManager *_graphicsManager;
Audio::Mixer *_mixer;
Expand Down
30 changes: 8 additions & 22 deletions backends/platform/android/android.cpp
Expand Up @@ -132,10 +132,7 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_show_mouse(false),
_show_overlay(false),
_enable_zoning(false),
_savefile(0),
_mixer(0),
_timer(0),
_fsFactory(new POSIXFilesystemFactory()),
_shake_offset(0),
_event_queue_lock(createMutex()),
_touch_pt_down(),
Expand All @@ -149,6 +146,9 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
_dpad_scale(4),
_fingersDown(0),
_trackball_scale(2) {

_fsFactory = new POSIXFilesystemFactory();

Common::String mf = getSystemProperty("ro.product.manufacturer");

LOGI("Running on: [%s] [%s] [%s] [%s] [%s] SDK:%s ABI:%s",
Expand All @@ -170,17 +170,17 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) :
OSystem_Android::~OSystem_Android() {
ENTER();

delete _savefile;
delete _timer;
delete _mixer;
_mixer = 0;
delete _fsFactory;
_fsFactory = 0;

deleteMutex(_event_queue_lock);
}

void *OSystem_Android::timerThreadFunc(void *arg) {
OSystem_Android *system = (OSystem_Android *)arg;
DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timer);
DefaultTimerManager *timer = (DefaultTimerManager *)(system->_timerManager);

// renice this thread to boost the audio thread
if (setpriority(PRIO_PROCESS, 0, 19) < 0)
Expand Down Expand Up @@ -359,8 +359,8 @@ void OSystem_Android::initBackend() {
// BUG: "transient" ConfMan settings get nuked by the options
// screen. Passing the savepath in this way makes it stick
// (via ConfMan.registerDefault)
_savefile = new DefaultSaveFileManager(ConfMan.get("savepath"));
_timer = new DefaultTimerManager();
_savefileManager = new DefaultSaveFileManager(ConfMan.get("savepath"));
_timerManager = new DefaultTimerManager();

gettimeofday(&_startTime, 0);

Expand Down Expand Up @@ -535,21 +535,11 @@ void OSystem_Android::showVirtualKeyboard(bool enable) {
JNI::showVirtualKeyboard(enable);
}

Common::SaveFileManager *OSystem_Android::getSavefileManager() {
assert(_savefile);
return _savefile;
}

Audio::Mixer *OSystem_Android::getMixer() {
assert(_mixer);
return _mixer;
}

Common::TimerManager *OSystem_Android::getTimerManager() {
assert(_timer);
return _timer;
}

void OSystem_Android::getTimeAndDate(TimeDate &td) const {
struct tm tm;
const time_t curTime = time(0);
Expand All @@ -563,10 +553,6 @@ void OSystem_Android::getTimeAndDate(TimeDate &td) const {
td.tm_year = tm.tm_year;
}

FilesystemFactory *OSystem_Android::getFilesystemFactory() {
return _fsFactory;
}

void OSystem_Android::addSysArchivesToSearchSet(Common::SearchSet &s,
int priority) {
ENTER("");
Expand Down
6 changes: 0 additions & 6 deletions backends/platform/android/android.h
Expand Up @@ -152,10 +152,7 @@ class OSystem_Android : public BaseBackend, public PaletteManager {
bool _enable_zoning;
bool _virtkeybd_on;

Common::SaveFileManager *_savefile;
Audio::MixerImpl *_mixer;
Common::TimerManager *_timer;
FilesystemFactory *_fsFactory;
timeval _startTime;

Common::String getSystemProperty(const char *name) const;
Expand Down Expand Up @@ -289,11 +286,8 @@ class OSystem_Android : public BaseBackend, public PaletteManager {
virtual void displayMessageOnOSD(const char *msg);
virtual void showVirtualKeyboard(bool enable);

virtual Common::SaveFileManager *getSavefileManager();
virtual Audio::Mixer *getMixer();
virtual void getTimeAndDate(TimeDate &t) const;
virtual Common::TimerManager *getTimerManager();
virtual FilesystemFactory *getFilesystemFactory();
virtual void logMessage(LogMessageType::Type type, const char *message);
virtual void addSysArchivesToSearchSet(Common::SearchSet &s,
int priority = 0);
Expand Down
5 changes: 0 additions & 5 deletions backends/platform/dc/dc.h
Expand Up @@ -185,24 +185,19 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Palette
void setWindowCaption(const char *caption);

// Modulatized backend
Common::SaveFileManager *getSavefileManager() { return _savefile; }
Audio::Mixer *getMixer() { return _mixer; }
Common::TimerManager *getTimerManager() { return _timer; }

// Extra SoftKbd support
void mouseToSoftKbd(int x, int y, int &rx, int &ry) const;

// Filesystem
FilesystemFactory *getFilesystemFactory() { return this; }
AbstractFSNode *makeRootFileNode() const;
AbstractFSNode *makeCurrentDirectoryFileNode() const;
AbstractFSNode *makeFileNodePath(const Common::String &path) const;

private:

Common::SaveFileManager *_savefile;
Audio::MixerImpl *_mixer;
DefaultTimerManager *_timer;
SoftKeyboard _softkbd;

int _ms_cur_x, _ms_cur_y, _ms_cur_w, _ms_cur_h, _ms_old_x, _ms_old_y;
Expand Down
7 changes: 4 additions & 3 deletions backends/platform/dc/dcmain.cpp
Expand Up @@ -41,20 +41,21 @@ const char *gGameName;

OSystem_Dreamcast::OSystem_Dreamcast()
: _devpoll(0), screen(NULL), mouse(NULL), overlay(NULL), _softkbd(this),
_ms_buf(NULL), _timer(NULL), _mixer(NULL), _savefile(NULL),
_ms_buf(NULL), _mixer(NULL),
_current_shake_pos(0), _aspect_stretch(false), _softkbd_on(false),
_softkbd_motion(0), _enable_cursor_palette(false), _screenFormat(0)
{
memset(screen_tx, 0, sizeof(screen_tx));
memset(mouse_tx, 0, sizeof(mouse_tx));
memset(ovl_tx, 0, sizeof(ovl_tx));
_fsFactory = this;
}

void OSystem_Dreamcast::initBackend()
{
ConfMan.setInt("autosave_period", 0);
_savefile = createSavefileManager();
_timer = new DefaultTimerManager();
_savefileManager = createSavefileManager();
_timerManager = new DefaultTimerManager();

uint sampleRate = initSound();
_mixer = new Audio::MixerImpl(this, sampleRate);
Expand Down
4 changes: 2 additions & 2 deletions backends/platform/dc/input.cpp
Expand Up @@ -192,8 +192,8 @@ bool OSystem_Dreamcast::pollEvent(Common::Event &event)
{
unsigned int t = Timer();

if (_timer != NULL)
_timer->handler();
if (_timerManager != NULL)
((DefaultTimerManager *)_timerManager)->handler();

if (((int)(t-_devpoll))<0)
return false;
Expand Down
4 changes: 2 additions & 2 deletions backends/platform/dc/time.cpp
Expand Up @@ -48,8 +48,8 @@ void OSystem_Dreamcast::delayMillis(uint msecs)
unsigned int t, start = Timer();
int time = (((unsigned int)msecs)*3125U)>>6;
while (((int)((t = Timer())-start))<time) {
if (_timer != NULL)
_timer->handler();
if (_timerManager != NULL)
((DefaultTimerManager *)_timerManager)->handler();
checkSound();
}
getMillis();
Expand Down
19 changes: 7 additions & 12 deletions backends/platform/ds/arm9/source/osystem_ds.cpp
Expand Up @@ -42,6 +42,7 @@
#include "backends/fs/ds/ds-fs-factory.h"

#include "backends/audiocd/default/default-audiocd.h"
#include "backends/timer/default/default-timer.h"

#ifdef ENABLE_AGI
#include "wordcompletion.h"
Expand Down Expand Up @@ -81,21 +82,19 @@
OSystem_DS *OSystem_DS::_instance = NULL;

OSystem_DS::OSystem_DS()
: eventNum(0), lastPenFrame(0), queuePos(0), _mixer(NULL), _timer(NULL), _frameBufferExists(false),
: eventNum(0), lastPenFrame(0), queuePos(0), _mixer(NULL), _frameBufferExists(false),
_disableCursorPalette(true), _graphicsEnable(true), _gammaValue(0)
{
// eventNum = 0;
// lastPenFrame = 0;
// queuePos = 0;
_instance = this;
// _mixer = NULL;
// _timer = NULL;
//_frameBufferExists = false;
}

OSystem_DS::~OSystem_DS() {
delete _mixer;
delete _timer;
}

int OSystem_DS::timerHandler(int t) {
Expand All @@ -108,7 +107,11 @@ void OSystem_DS::initBackend() {
ConfMan.setInt("autosave_period", 0);
ConfMan.setBool("FM_medium_quality", true);

_timer = new DefaultTimerManager();
if (DS::isGBAMPAvailable()) {
_savefileManager = &mpSaveManager;
}

_timerManager = new DefaultTimerManager();
DS::setTimerCallback(&OSystem_DS::timerHandler, 10);

if (ConfMan.hasKey("22khzaudio", "ds") && ConfMan.getBool("22khzaudio", "ds")) {
Expand Down Expand Up @@ -747,14 +750,6 @@ void OSystem_DS::quit() {
swiSoftReset();*/
}

Common::SaveFileManager *OSystem_DS::getSavefileManager() {
if (DS::isGBAMPAvailable()) {
return &mpSaveManager;
}
return NULL;
}


Graphics::Surface *OSystem_DS::createTempFrameBuffer() {

// Ensure we copy using 16 bit quantities due to limitation of VRAM addressing
Expand Down
5 changes: 0 additions & 5 deletions backends/platform/ds/arm9/source/osystem_ds.h
Expand Up @@ -29,7 +29,6 @@
#include "nds.h"
#include "gbampsave.h"
#include "backends/saves/default/default-saves.h"
#include "backends/timer/default/default-timer.h"
#include "audio/mixer_intern.h"
#include "graphics/surface.h"
#include "graphics/colormasks.h"
Expand All @@ -46,7 +45,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager {

GBAMPSaveFileManager mpSaveManager;
Audio::MixerImpl *_mixer;
DefaultTimerManager *_timer;
Graphics::Surface _framebuffer;
bool _frameBufferExists;
bool _graphicsEnable;
Expand Down Expand Up @@ -140,8 +138,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager {

virtual void quit();

virtual Common::SaveFileManager *getSavefileManager();

void addEvent(const Common::Event& e);
bool isEventQueueEmpty() const { return queuePos == 0; }

Expand All @@ -159,7 +155,6 @@ class OSystem_DS : public BaseBackend, public PaletteManager {
virtual Audio::Mixer *getMixer() { return _mixer; }
Audio::MixerImpl *getMixerImpl() { return _mixer; }

virtual Common::TimerManager *getTimerManager() { return _timer; }
static int timerHandler(int t);


Expand Down

0 comments on commit 5e5661b

Please sign in to comment.