TITANIC: Adding screen initialization code

This commit is contained in:
Paul Gilbert 2016-02-07 23:25:34 -05:00
parent 43d3b138ca
commit c9c85ee622
10 changed files with 211 additions and 46 deletions

View file

@ -20,26 +20,79 @@
* *
*/ */
#include "common/debug.h"
#include "engines/util.h"
#include "titanic/titanic.h"
#include "titanic/direct_draw.h" #include "titanic/direct_draw.h"
namespace Titanic { namespace Titanic {
DirectDraw::DirectDraw(TitanicEngine *vm) : Manager(vm) { DirectDraw::DirectDraw(TitanicEngine *vm) : _vm(vm) {
_field8 = 0; _field8 = 0;
_fieldC = 0; _fieldC = 0;
_width = 0; _width = 0;
_height = 0; _height = 0;
_bpp = 0; _bpp = 0;
_field1C = 0; _numBackSurfaces = 0;
_field24 = 0; _field24 = 0;
} }
void DirectDraw::setDisplayMode(int width, int height, int bpp, int refreshRate) {
debugC(ERROR_BASIC, kDebugGraphics, "DirectDraw::SetDisplayMode (%d x %d), %d bpp",
width, height, bpp);
assert(bpp == 8);
initGraphics(width, height, true);
}
void DirectDraw::diagnostics() {
debugC(ERROR_BASIC, kDebugGraphics, "Running DirectDraw Diagnostic...");
}
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
DirectDrawManager::DirectDrawManager(TitanicEngine *vm) : DirectDrawManager::DirectDrawManager(TitanicEngine *vm, int v) : _directDraw(vm) {
Manager(vm), _directDraw(vm) {
_mainSurface = nullptr; _mainSurface = nullptr;
_backSurfaces[0] = _backSurfaces[1] = nullptr; _backSurfaces[0] = _backSurfaces[1] = nullptr;
_directDraw._field8 = v;
}
void DirectDrawManager::initVideo(int width, int height, int bpp, int numBackSurfaces) {
debugC(ERROR_BASIC, kDebugGraphics, "Initialising video surfaces");
_directDraw._width = width;
_directDraw._numBackSurfaces = numBackSurfaces;
_directDraw._height = height;
_directDraw._bpp = bpp;
if (numBackSurfaces) {
setResolution();
} else {
initSurface();
}
}
void DirectDrawManager::setResolution() {
// TODO
}
void DirectDrawManager::proc2() {
}
void DirectDrawManager::proc3() {
}
void DirectDrawManager::initSurface() {
debugC(ERROR_BASIC, kDebugGraphics, "Creating surfaces");
_directDraw.setDisplayMode(_directDraw._width, _directDraw._height,
_directDraw._bpp, 0);
_mainSurface = new Graphics::Surface();
_mainSurface->create(_directDraw._width, _directDraw._height,
Graphics::PixelFormat::createFormatCLUT8());
_backSurfaces[0] = new Graphics::Surface();
_backSurfaces[0]->create(_directDraw._width, _directDraw._height,
Graphics::PixelFormat::createFormatCLUT8());
} }
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -25,30 +25,64 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/array.h" #include "common/array.h"
#include "titanic/titanic.h" #include "graphics/surface.h"
namespace Titanic { namespace Titanic {
class DirectDraw: public Manager { class TitanicEngine;
class DirectDraw {
private:
TitanicEngine *_vm;
public: public:
int _field8; int _field8;
int _fieldC; int _fieldC;
int _width; int _width;
int _height; int _height;
int _bpp; int _bpp;
int _field1C; int _numBackSurfaces;
int _field24; int _field24;
public: public:
DirectDraw(TitanicEngine *vm); DirectDraw(TitanicEngine *vm);
/**
* Sets a new display mode
*/
void setDisplayMode(int width, int height, int bpp, int refreshRate);
/**
* Logs diagnostic information
*/
void diagnostics();
}; };
class DirectDrawManager: public Manager { class DirectDrawManager {
public: public:
DirectDraw _directDraw; DirectDraw _directDraw;
void *_mainSurface; Graphics::Surface *_mainSurface;
void *_backSurfaces[2]; Graphics::Surface *_backSurfaces[2];
public: public:
DirectDrawManager(TitanicEngine *vm); DirectDrawManager(TitanicEngine *vm, int v);
/**
* Initializes video surfaces
* @param width Screen width
* @param height Screen height
* @param bpp Bits per pixel
* @param numBackSurfaces Number of back surfaces
*/
void initVideo(int width, int height, int bpp, int numBackSurfaces);
void setResolution();
void proc2();
void proc3();
/**
* Initializes the surface for the screen
*/
void initSurface();
}; };
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -27,4 +27,8 @@ namespace Titanic {
STFont::STFont() { STFont::STFont() {
} }
void STFont::load(int fontNumber) {
// TODO
}
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -31,6 +31,8 @@ class STFont {
public: public:
public: public:
STFont(); STFont();
void load(int fontNumber);
}; };
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -21,6 +21,7 @@
*/ */
#include "titanic/screen_manager.h" #include "titanic/screen_manager.h"
#include "titanic/video_surface.h"
namespace Titanic { namespace Titanic {
@ -33,11 +34,10 @@ CScreenManagerRec::CScreenManagerRec() {
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
CScreenManager::CScreenManager() { CScreenManager::CScreenManager(TitanicEngine *vm): _vm(vm) {
_screenManagerPtr = nullptr; _screenManagerPtr = nullptr;
_field4 = 0; _frontRenderSurface = nullptr;
_fontRenderSurface = nullptr;
_mouseCursor = nullptr; _mouseCursor = nullptr;
_textCursor = nullptr; _textCursor = nullptr;
_fontNumber = 0; _fontNumber = 0;
@ -47,31 +47,51 @@ CScreenManager::~CScreenManager() {
_screenManagerPtr = nullptr; _screenManagerPtr = nullptr;
} }
void CScreenManager::proc2(int v) { void CScreenManager::setWindowHandle(int v) {
if (v) // Not needed
_field4 = v;
} }
bool CScreenManager::proc3(int v) { bool CScreenManager::resetWindowHandle(int v) {
if (!v || _field4)
return false;
_field4 = 0;
proc27(); proc27();
return true; return true;
} }
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
OSScreenManager::OSScreenManager(): CScreenManager() { OSScreenManager::OSScreenManager(TitanicEngine *vm): CScreenManager(vm),
_directDrawManager(vm, 0) {
_field48 = 0; _field48 = 0;
_field4C = 0; _field4C = 0;
_field50 = 0; _field50 = 0;
_field54 = 0; _field54 = 0;
_directDrawManager = nullptr;
} }
void OSScreenManager::setMode() {} OSScreenManager::~OSScreenManager() {
destroyFrontAndBackBuffers();
}
void OSScreenManager::setMode(int width, int height, int bpp, int numBackSurfaces, bool flag2) {
destroyFrontAndBackBuffers();
_directDrawManager.initVideo(width, height, bpp, numBackSurfaces);
_frontRenderSurface = new OSVideoSurface(this, nullptr);
_frontRenderSurface->setSurface(this, _directDrawManager._mainSurface);
for (uint idx = 0; idx < numBackSurfaces; ++idx) {
OSVideoSurface videoSurface(this, nullptr);
videoSurface.setSurface(this, _directDrawManager._backSurfaces[idx]);
}
// Load fonts
_fonts[0].load(149);
_fonts[1].load(151);
_fonts[2].load(152);
_fonts[3].load(153);
// Load the cursors
loadCursors();
}
void OSScreenManager::proc5() {} void OSScreenManager::proc5() {}
void OSScreenManager::proc6() {} void OSScreenManager::proc6() {}
void OSScreenManager::proc7() {} void OSScreenManager::proc7() {}
@ -96,4 +116,17 @@ void OSScreenManager::proc25() {}
void OSScreenManager::showCursor() {} void OSScreenManager::showCursor() {}
void OSScreenManager::proc27() {} void OSScreenManager::proc27() {}
void OSScreenManager::destroyFrontAndBackBuffers() {
delete _frontRenderSurface;
_frontRenderSurface = nullptr;
for (uint idx = 0; idx < _backSurfaces.size(); ++idx)
delete _backSurfaces[idx];
_backSurfaces.clear();
}
void OSScreenManager::loadCursors() {
// TODO
}
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -25,10 +25,14 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/array.h" #include "common/array.h"
#include "titanic/direct_draw.h"
#include "titanic/font.h" #include "titanic/font.h"
#include "titanic/video_surface.h"
namespace Titanic { namespace Titanic {
class TitanicEngine;
class CSurface { class CSurface {
}; };
@ -43,26 +47,27 @@ public:
}; };
class CScreenManager { class CScreenManager {
protected:
TitanicEngine *_vm;
public: public:
void *_screenManagerPtr; void *_screenManagerPtr;
public: public:
int _field4; Common::Array<CVideoSurface *> _backSurfaces;
Common::Array<CSurface> _backSurfaces; CVideoSurface *_frontRenderSurface;
CSurface *_fontRenderSurface;
CScreenManagerRec _entries[2]; CScreenManagerRec _entries[2];
void *_mouseCursor; void *_mouseCursor;
void *_textCursor; void *_textCursor;
int _fontNumber; int _fontNumber;
public: public:
CScreenManager(); CScreenManager(TitanicEngine *vm);
virtual ~CScreenManager(); virtual ~CScreenManager();
void fn1() {} void fn1() {}
void fn2() {} void fn2() {}
virtual void proc2(int v); virtual void setWindowHandle(int v);
virtual bool proc3(int v); virtual bool resetWindowHandle(int v);
virtual void setMode() = 0; virtual void setMode(int width, int height, int bpp, int numBackSurfaces, bool flag2) = 0;
virtual void proc5() = 0; virtual void proc5() = 0;
virtual void proc6() = 0; virtual void proc6() = 0;
virtual void proc7() = 0; virtual void proc7() = 0;
@ -89,17 +94,29 @@ public:
}; };
class OSScreenManager: CScreenManager { class OSScreenManager: CScreenManager {
private:
DirectDrawManager _directDrawManager;
/**
* Frees any surface buffers
*/
void destroyFrontAndBackBuffers();
/**
* Load game cursors
*/
void loadCursors();
public: public:
int _field48; int _field48;
int _field4C; int _field4C;
int _field50; int _field50;
int _field54; int _field54;
void *_directDrawManager;
STFont _fonts[4]; STFont _fonts[4];
public: public:
OSScreenManager(); OSScreenManager(TitanicEngine *vm);
virtual ~OSScreenManager();
virtual void setMode(); virtual void setMode(int width, int height, int bpp, int numBackSurfaces, bool flag2);
virtual void proc5(); virtual void proc5();
virtual void proc6(); virtual void proc6();
virtual void proc7(); virtual void proc7();

View file

@ -53,7 +53,7 @@ void TitanicEngine::initialize() {
CSaveableObject::initClassList(); CSaveableObject::initClassList();
_window = new CMainGameWindow(this); _window = new CMainGameWindow(this);
_screenManager = new OSScreenManager(); _screenManager = new OSScreenManager(this);
} }
Common::Error TitanicEngine::run() { Common::Error TitanicEngine::run() {

View file

@ -50,6 +50,10 @@ enum TitanicDebugChannels {
#define TITANIC_SAVEGAME_VERSION 1 #define TITANIC_SAVEGAME_VERSION 1
#define ERROR_BASIC 1
#define ERROR_INTERMEDIATE 2
#define ERROR_DETAILED 3
struct TitanicGameDescription; struct TitanicGameDescription;
class TitanicEngine; class TitanicEngine;
@ -62,13 +66,6 @@ struct TitanicSavegameHeader {
int _totalFrames; int _totalFrames;
}; };
class Manager {
protected:
TitanicEngine *_vm;
public:
Manager(TitanicEngine *vm) : _vm(vm) {}
};
class TitanicEngine : public Engine { class TitanicEngine : public Engine {
private: private:
/** /**

View file

@ -24,4 +24,19 @@
namespace Titanic { namespace Titanic {
CVideoSurface::CVideoSurface(CScreenManager *screenManager, Graphics::Surface *surface):
_screenManager(screenManager), _surface(surface) {
}
void CVideoSurface::setSurface(CScreenManager *screenManager, Graphics::Surface *surface) {
_screenManager = screenManager;
_surface = surface;
}
/*------------------------------------------------------------------------*/
OSVideoSurface::OSVideoSurface(CScreenManager *screenManager, Graphics::Surface *surface):
CVideoSurface(screenManager, surface) {
}
} // End of namespace Titanic } // End of namespace Titanic

View file

@ -25,16 +25,26 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/array.h" #include "common/array.h"
#include "graphics/surface.h"
#include "titanic/font.h" #include "titanic/font.h"
namespace Titanic { namespace Titanic {
class CVideoSurface { class CScreenManager;
class CVideoSurface {
private:
CScreenManager *_screenManager;
Graphics::Surface *_surface;
public:
CVideoSurface(CScreenManager *screenManager, Graphics::Surface *surface);
void setSurface(CScreenManager *screenManager, Graphics::Surface *surface);
}; };
class OSVideoSurface : CVideoSurface { class OSVideoSurface : public CVideoSurface {
public:
OSVideoSurface(CScreenManager *screenManager, Graphics::Surface *surface);
}; };
} // End of namespace Titanic } // End of namespace Titanic