aboutsummaryrefslogtreecommitdiff
path: root/engines/cryo
diff options
context:
space:
mode:
authorStrangerke2016-11-30 22:51:15 -0800
committerEugene Sandulenko2017-01-25 22:42:10 +0100
commitbe3e74882986c8fb2cb164cf5e3dfbb777396e4a (patch)
tree7c13cdbd2936aed80a7a61c40e91b18bbd550390 /engines/cryo
parent1e3e2b992b8bb51eeb81b75b93fe943b903033e4 (diff)
downloadscummvm-rg350-be3e74882986c8fb2cb164cf5e3dfbb777396e4a.tar.gz
scummvm-rg350-be3e74882986c8fb2cb164cf5e3dfbb777396e4a.tar.bz2
scummvm-rg350-be3e74882986c8fb2cb164cf5e3dfbb777396e4a.zip
CRYO: Objectify View
Diffstat (limited to 'engines/cryo')
-rw-r--r--engines/cryo/cryo.cpp3
-rw-r--r--engines/cryo/cryo.h2
-rw-r--r--engines/cryo/cryolib.cpp105
-rw-r--r--engines/cryo/cryolib.h28
-rw-r--r--engines/cryo/eden.cpp88
5 files changed, 117 insertions, 109 deletions
diff --git a/engines/cryo/cryo.cpp b/engines/cryo/cryo.cpp
index b3f155c6d5..0b02b07ea0 100644
--- a/engines/cryo/cryo.cpp
+++ b/engines/cryo/cryo.cpp
@@ -61,6 +61,7 @@ CryoEngine::CryoEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engin
_rnd = new Common::RandomSource("cryo");
_game = nullptr;
_video = nullptr;
+ ScreenView = nullptr;
debug("CryoEngine::CryoEngine");
@@ -74,6 +75,7 @@ CryoEngine::~CryoEngine() {
delete _rnd;
delete _game;
delete _video;
+ delete ScreenView;
// Remove all of our debug levels here
DebugMan.clearAllDebugChannels();
@@ -82,6 +84,7 @@ CryoEngine::~CryoEngine() {
Common::Error CryoEngine::run() {
_game = new EdenGame(this);
_video = new HnmPlayer(this);
+ ScreenView = new View(this, 320, 200);
///// CLTimer
TimerTicks = 0; // incremented in realtime
diff --git a/engines/cryo/cryo.h b/engines/cryo/cryo.h
index df47fb245c..5b03987643 100644
--- a/engines/cryo/cryo.h
+++ b/engines/cryo/cryo.h
@@ -72,7 +72,7 @@ public:
EdenGame *_game;
HnmPlayer *_video;
- View ScreenView;
+ View *ScreenView;
volatile int32 TimerTicks;
private:
diff --git a/engines/cryo/cryolib.cpp b/engines/cryo/cryolib.cpp
index 48e57ec381..bcbca02d7d 100644
--- a/engines/cryo/cryolib.cpp
+++ b/engines/cryo/cryolib.cpp
@@ -54,59 +54,56 @@ int32 TickCount() {
}
///// CLView
-void CLView_SetSrcZoomValues(View *view, int x, int y) {
- view->_zoom._srcLeft = x;
- view->_zoom._srcTop = y;
+
+View::View(CryoEngine *vm, int w, int h) : _vm(vm) {
+ void *buffer = (byte *)malloc(w * h);
+ if (buffer) {
+ _allocated = true;
+ CLView_InitDatas(w, h, buffer);
+ } else
+ error("Unable to allocate view buffer");
}
-void CLView_SetDisplayZoomValues(View *view, int w, int h) {
- view->_zoom._width = w;
- view->_zoom._height = h;
+
+View::~View() {
+ if (_bufferPtr && _allocated)
+ free(_bufferPtr);
}
-void CLView_Free(View *view) {
- if (view->_bufferPtr && view->_allocated)
- free(view->_bufferPtr);
- if (view)
- free(view);
-}
-void CLView_InitDatas(View *view, int w, int h, void *buffer) {
- view->_bufferPtr = (byte *)buffer;
- view->_width = w;
- view->_height = h;
- view->_pitch = w;
- view->_doubled = false;
- view->_normal._srcLeft = 0;
- view->_normal._srcTop = 0;
- view->_normal._dstLeft = 0;
- view->_normal._dstTop = 0;
- view->_normal._width = w;
- view->_normal._height = h;
- view->_zoom._srcLeft = 0;
- view->_zoom._srcTop = 0;
- view->_zoom._dstLeft = 0;
- view->_zoom._dstTop = 0;
- view->_zoom._width = w;
- view->_zoom._height = h;
-}
-View *CLView_New(int w, int h) {
- View *view = (View *)malloc(sizeof(View));
- if (view) {
- void *buffer = (byte *)malloc(w * h);
- if (buffer) {
- view->_allocated = true;
- CLView_InitDatas(view, w, h, buffer);
- } else {
- view->_allocated = false;
- free(view);
- view = 0;
- }
- }
- return view;
+
+void View::CLView_SetSrcZoomValues(int x, int y) {
+ _zoom._srcLeft = x;
+ _zoom._srcTop = y;
+}
+
+void View::CLView_SetDisplayZoomValues(int w, int h) {
+ _zoom._width = w;
+ _zoom._height = h;
}
-void CLView_CenterIn(View *parent, View *child) {
- child->_normal._dstLeft = (parent->_width - child->_normal._width) / 2;
- child->_normal._dstTop = (parent->_height - child->_normal._height) / 2;
- child->_zoom._dstLeft = (parent->_width - child->_zoom._width) / 2;
- child->_zoom._dstTop = (parent->_height - child->_zoom._height) / 2;
+
+void View::CLView_InitDatas(int w, int h, void *buffer) {
+ _bufferPtr = (byte *)buffer;
+ _width = w;
+ _height = h;
+ _pitch = w;
+ _doubled = false;
+ _normal._srcLeft = 0;
+ _normal._srcTop = 0;
+ _normal._dstLeft = 0;
+ _normal._dstTop = 0;
+ _normal._width = w;
+ _normal._height = h;
+ _zoom._srcLeft = 0;
+ _zoom._srcTop = 0;
+ _zoom._dstLeft = 0;
+ _zoom._dstTop = 0;
+ _zoom._width = w;
+ _zoom._height = h;
+}
+
+void View::CLView_CenterIn(View *parent) {
+ _normal._dstLeft = (parent->_width - _normal._width) / 2;
+ _normal._dstTop = (parent->_height - _normal._height) / 2;
+ _zoom._dstLeft = (parent->_width - _zoom._width) / 2;
+ _zoom._dstTop = (parent->_height - _zoom._height) / 2;
}
///// CLPalette
@@ -222,7 +219,7 @@ void CLBlitter_CopyView2ViewSimpleSize(byte *src, int16 srcw, int16 srcp, int16
void CLBlitter_CopyView2ScreenCUSTOM(View *view) {
if (!view->_doubled) {
- View *dest = &g_ed->ScreenView;
+ View *dest = g_ed->ScreenView;
int16 srcpitch = view->_pitch;
int16 dstpitch = dest->_pitch;
@@ -249,7 +246,7 @@ void CLBlitter_CopyView2Screen(View *view) {
if (view)
CLBlitter_CopyView2ScreenCUSTOM(view);
- g_system->copyRectToScreen(g_ed->ScreenView._bufferPtr, g_ed->ScreenView._pitch, 0, 0, g_ed->ScreenView._width, g_ed->ScreenView._height);
+ g_system->copyRectToScreen(g_ed->ScreenView->_bufferPtr, g_ed->ScreenView->_pitch, 0, 0, g_ed->ScreenView->_width, g_ed->ScreenView->_height);
g_system->updateScreen();
}
@@ -269,7 +266,7 @@ void CLBlitter_FillView(View *view, unsigned int fill) {
}
void CLBlitter_FillScreenView(unsigned int fill) {
- CLBlitter_FillView(&g_ed->ScreenView, fill);
+ CLBlitter_FillView(g_ed->ScreenView, fill);
}
///// events wrapper
@@ -430,7 +427,7 @@ void CLTimer_Action(void *arg) {
///// CRYOLib
void CRYOLib_ManagersInit() {
g_system->getTimerManager()->installTimerProc(CLTimer_Action, 10000, nullptr, "100hz timer");
- CLView_InitDatas(&g_ed->ScreenView, g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
+ g_ed->ScreenView->CLView_InitDatas(g_ed->_screen.w, g_ed->_screen.h, g_ed->_screen.getPixels());
}
void CRYOLib_ManagersDone() {
diff --git a/engines/cryo/cryolib.h b/engines/cryo/cryolib.h
index 7af53a1c7f..1c84929cc5 100644
--- a/engines/cryo/cryolib.h
+++ b/engines/cryo/cryolib.h
@@ -30,6 +30,8 @@
namespace Cryo {
+class CryoEngine;
+
#define SW16(n) ( (((n) & 0xFF) << 8) | (((n) >> 8) & 0xFF) )
#define SW32(n) ( (((n) & 0xFF) << 24) | (((n) >> 24) & 0xFF) | (((n) & 0xFF00) << 8) | (((n) >> 8) & 0xFF00))
#if 0
@@ -61,13 +63,26 @@ struct BlitView{
int _height;
};
-struct View {
- byte *_bufferPtr;
+class View {
+private:
+ CryoEngine *_vm;
+
+ bool _allocated;
+
+public:
+ View(CryoEngine *vm, int w, int h);
+ ~View();
+
+ void CLView_SetSrcZoomValues(int x, int y);
+ void CLView_SetDisplayZoomValues(int w, int h);
+ void CLView_InitDatas(int w, int h, void *buffer);
+ void CLView_CenterIn(View *parent);
+
int _width;
int _height;
+ byte *_bufferPtr;
int16 _pitch;
bool _doubled;
- bool _allocated;
BlitView _normal;
BlitView _zoom;
};
@@ -217,13 +232,6 @@ void CLMouse_GetPosition(int16 *x, int16 *y);
void CLMouse_SetPosition(int16 x, int16 y);
uint16 CLMouse_IsDown();
-void CLView_SetSrcZoomValues(View *view, int x, int y);
-void CLView_SetDisplayZoomValues(View *view, int w, int h);
-void CLView_Free(View *view);
-void CLView_InitDatas(View *view, int w, int h, void *buffer);
-View *CLView_New(int w, int h);
-void CLView_CenterIn(View *parent, View *child);
-
void CRYOLib_ManagersInit();
void CRYOLib_ManagersDone();
diff --git a/engines/cryo/eden.cpp b/engines/cryo/eden.cpp
index 3b70cbd0ce..027600f362 100644
--- a/engines/cryo/eden.cpp
+++ b/engines/cryo/eden.cpp
@@ -4075,9 +4075,9 @@ void EdenGame::effet1() {
for (int16 i = 16; i <= 96; i += 4) {
for (int x = p_mainview->_normal._dstLeft; x < p_mainview->_normal._dstLeft + 320; x += 16) {
setRD1(x, y + i, x + 16 - 1, y + i + 4 - 1);
- CLBlitter_CopyViewRect(p_view2, &_vm->ScreenView, &rect_src, &rect_dst);
+ CLBlitter_CopyViewRect(p_view2, _vm->ScreenView, &rect_src, &rect_dst);
setRD1(x, y + 192 - i, x + 16 - 1, y + 192 - i + 4 - 1);
- CLBlitter_CopyViewRect(p_view2, &_vm->ScreenView, &rect_src, &rect_dst);
+ CLBlitter_CopyViewRect(p_view2, _vm->ScreenView, &rect_src, &rect_dst);
}
CLBlitter_UpdateScreen();
wait(1);
@@ -4088,9 +4088,9 @@ void EdenGame::effet1() {
for (int16 i = 16 * 2; i <= 96 * 2; i += 4 * 2) {
for (int x = p_mainview->_zoom._dstLeft; x < p_mainview->_zoom._dstLeft + 320 * 2; x += 16 * 2) {
setRD1(x, y + i, x + 16 * 2 - 1, y + i + 4 * 2 - 1);
- CLBlitter_CopyViewRect(p_view2, &_vm->ScreenView, &rect_src, &rect_dst);
+ CLBlitter_CopyViewRect(p_view2, _vm->ScreenView, &rect_src, &rect_dst);
setRD1(x, y + 192 * 2 - i, x + 16 * 2 - 1, y + 192 * 2 - i + 4 * 2 - 1);
- CLBlitter_CopyViewRect(p_view2, &_vm->ScreenView, &rect_src, &rect_dst);
+ CLBlitter_CopyViewRect(p_view2, _vm->ScreenView, &rect_src, &rect_dst);
}
wait(1);
}
@@ -4183,14 +4183,14 @@ void EdenGame::effet4() {
CLPalette_Send2Screen(global_palette, 0, 256);
// Unused
-// int16 w = _vm->ScreenView._width;
-// int16 h = _vm->ScreenView._height;
- int16 ww = _vm->ScreenView._pitch;
+// int16 w = _vm->ScreenView->_width;
+// int16 h = _vm->ScreenView->_height;
+ int16 ww = _vm->ScreenView->_pitch;
if (!_doubledScreen) {
x = p_mainview->_normal._dstLeft;
y = p_mainview->_normal._dstTop;
for (int16 i = 32; i > 0; i -= 2) {
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16) * ww + x;
pix = p_mainview->_bufferPtr + 16 * 640;
r17 = 320 / i;
@@ -4254,7 +4254,7 @@ void EdenGame::effet4() {
x = p_mainview->_zoom._dstLeft;
y = p_mainview->_zoom._dstTop;
for (int16 i = 32; i > 0; i -= 2) {
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16 * 2) * ww + x;
pix = p_mainview->_bufferPtr + 16 * 640;
r17 = 320 / i;
@@ -4322,13 +4322,13 @@ void EdenGame::ClearScreen() {
int16 x, y;
// Unused
-// int16 w = _vm->ScreenView._width;
-// int16 h = _vm->ScreenView._height;
- int16 ww = _vm->ScreenView._pitch;
+// int16 w = _vm->ScreenView->_width;
+// int16 h = _vm->ScreenView->_height;
+ int16 ww = _vm->ScreenView->_pitch;
if (!_doubledScreen) {
x = p_mainview->_normal._dstLeft;
y = p_mainview->_normal._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16) * ww + x;
for (int16 yy = 0; yy < 160; yy++) {
for (int16 xx = 0; xx < 320; xx++)
@@ -4338,7 +4338,7 @@ void EdenGame::ClearScreen() {
} else {
x = p_mainview->_zoom._dstLeft;
y = p_mainview->_zoom._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 32) * ww + x;
for (int16 yy = 0; yy < 160; yy++) {
for (int16 xx = 0; xx < 320; xx++) {
@@ -4360,13 +4360,13 @@ void EdenGame::colimacon(int16 pattern[16]) {
int16 p, r27, r25;
// Unused
-// int16 w = _vm->ScreenView._width;
-// int16 h = _vm->ScreenView._height;
- int16 ww = _vm->ScreenView._pitch;
+// int16 w = _vm->ScreenView->_width;
+// int16 h = _vm->ScreenView->_height;
+ int16 ww = _vm->ScreenView->_pitch;
if (!_doubledScreen) {
x = p_mainview->_normal._dstLeft;
y = p_mainview->_normal._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16) * ww + x;
for (int16 i = 0; i < 16; i++) {
p = pattern[i];
@@ -4379,7 +4379,7 @@ void EdenGame::colimacon(int16 pattern[16]) {
} else {
x = p_mainview->_zoom._dstLeft;
y = p_mainview->_zoom._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16 * 2) * ww + x;
for (int16 i = 0; i < 16; i++) {
p = pattern[i];
@@ -4400,7 +4400,7 @@ void EdenGame::colimacon(int16 pattern[16]) {
x = p_mainview->_normal._dstLeft;
y = p_mainview->_normal._dstTop;
pix += 640 * 16;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16) * ww + x;
for (int16 i = 0; i < 16; i++) {
p = pattern[i];
@@ -4417,7 +4417,7 @@ void EdenGame::colimacon(int16 pattern[16]) {
x = p_mainview->_zoom._dstLeft;
y = p_mainview->_zoom._dstTop;
pix += 640 * 16;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16 * 2) * ww + x;
for (int16 i = 0; i < 16; i++) {
p = pattern[i];
@@ -4522,21 +4522,21 @@ void EdenGame::effetpix() {
int16 r25, r18, r31, r30; //TODO: change to xx/yy
// Unused
-// int16 w = _vm->ScreenView._width;
-// int16 h = _vm->ScreenView._height;
- int16 ww = _vm->ScreenView._pitch;
+// int16 w = _vm->ScreenView->_width;
+// int16 h = _vm->ScreenView->_height;
+ int16 ww = _vm->ScreenView->_pitch;
r25 = ww * 80;
r18 = 640 * 80;
pix = p_mainview->_bufferPtr + 16 * 640;
if (!_doubledScreen) {
x = p_mainview->_normal._dstLeft;
y = p_mainview->_normal._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16) * ww + x;
} else {
x = p_mainview->_zoom._dstLeft;
y = p_mainview->_zoom._dstTop;
- scr = _vm->ScreenView._bufferPtr;
+ scr = _vm->ScreenView->_bufferPtr;
scr += (y + 16 * 2) * ww + x;
r25 *= 2;
}
@@ -4619,7 +4619,7 @@ void EdenGame::effetpix() {
}
}
} while (r27 != 1);
- assert(_vm->ScreenView._pitch == 320);
+ assert(_vm->ScreenView->_pitch == 320);
}
////// datfile.c
@@ -5226,7 +5226,7 @@ void EdenGame::displayRoom() {
debug("drawroom: room 0x%X using bank %d", p_global->roomNum, p_global->roomImgBank);
useBank(p_global->roomImgBank);
displaySingleRoom(room);
- assert(_vm->ScreenView._pitch == 320);
+ assert(_vm->ScreenView->_pitch == 320);
}
}
@@ -5438,7 +5438,7 @@ void EdenGame::initPlace(int16 roomNum) {
void EdenGame::maj2() {
displayPlace();
- assert(_vm->ScreenView._pitch == 320);
+ assert(_vm->ScreenView->_pitch == 320);
if (p_global->roomNum == 273 && p_global->prevLocation == 18)
p_global->ff_102 = 1;
if (p_global->eventType == EventType::etEventC) {
@@ -5446,7 +5446,7 @@ void EdenGame::maj2() {
showObjects();
}
FRDevents();
- assert(_vm->ScreenView._pitch == 320);
+ assert(_vm->ScreenView->_pitch == 320);
bool r30 = false;
if (p_global->curAreaType == AreaType::atValley && !(p_global->displayFlags & DisplayFlags::dfPanable))
r30 = true;
@@ -5533,24 +5533,24 @@ void EdenGame::freebuf() {
}
void EdenGame::openwindow() {
- p_underBarsView = CLView_New(320, 40);
+ p_underBarsView = new View(_vm, 320, 40);
p_underBarsView->_normal._width = 320;
- p_view2 = CLView_New(32, 32);
+ p_view2 = new View(_vm, 32, 32);
p_view2_buf = p_view2->_bufferPtr;
- p_subtitlesview = CLView_New(subtitles_x_width, 60);
+ p_subtitlesview = new View(_vm, subtitles_x_width, 60);
p_subtitlesview_buf = p_subtitlesview->_bufferPtr;
- p_underSubtitlesView = CLView_New(subtitles_x_width, 60);
+ p_underSubtitlesView = new View(_vm, subtitles_x_width, 60);
p_underSubtitlesView_buf = p_underSubtitlesView->_bufferPtr;
- p_mainview = CLView_New(640, 200);
+ p_mainview = new View(_vm, 640, 200);
p_mainview->_normal._width = 320;
CLBlitter_FillView(p_mainview, 0xFFFFFFFF);
- CLView_SetSrcZoomValues(p_mainview, 0, 0);
- CLView_SetDisplayZoomValues(p_mainview, 640, 400);
- CLView_CenterIn(&_vm->ScreenView, p_mainview);
+ p_mainview->CLView_SetSrcZoomValues(0, 0);
+ p_mainview->CLView_SetDisplayZoomValues(640, 400);
+ p_mainview->CLView_CenterIn(_vm->ScreenView);
p_mainview_buf = p_mainview->_bufferPtr;
mouse_x_center = p_mainview->_normal._dstLeft + p_mainview->_normal._width / 2;
@@ -6222,10 +6222,10 @@ void EdenGame::showMovie(char arg1) {
bool playing = true;
_vm->_video->allocMemory(_hnmContext);
- p_hnmview = CLView_New(_hnmContext->_header._width, _hnmContext->_header._height);
- CLView_SetSrcZoomValues(p_hnmview, 0, 0);
- CLView_SetDisplayZoomValues(p_hnmview, _hnmContext->_header._width * 2, _hnmContext->_header._height * 2);
- CLView_CenterIn(&_vm->ScreenView, p_hnmview);
+ p_hnmview = new View(_vm, _hnmContext->_header._width, _hnmContext->_header._height);
+ p_hnmview->CLView_SetSrcZoomValues(0, 0);
+ p_hnmview->CLView_SetDisplayZoomValues(_hnmContext->_header._width * 2, _hnmContext->_header._height * 2);
+ p_hnmview->CLView_CenterIn(_vm->ScreenView);
p_hnmview_buf = p_hnmview->_bufferPtr;
if (arg1) {
p_hnmview->_normal._height = 160;
@@ -6244,7 +6244,7 @@ void EdenGame::showMovie(char arg1) {
else
musicspy();
CLBlitter_CopyView2Screen(p_hnmview);
- assert(_vm->ScreenView._pitch == 320);
+ assert(_vm->ScreenView->_pitch == 320);
CLKeyboard_Read();
if (_allowDoubled) {
if (CLKeyboard_IsScanCodeDown(0x30)) { //TODO: const
@@ -6267,7 +6267,7 @@ void EdenGame::showMovie(char arg1) {
mouse_held = false;
}
} while (playing && !videoCanceled);
- CLView_Free(p_hnmview);
+ delete p_hnmview;
_vm->_video->deallocMemory(_hnmContext);
}