aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/prince/graphics.cpp58
-rw-r--r--engines/prince/graphics.h16
-rw-r--r--engines/prince/prince.cpp183
-rw-r--r--engines/prince/prince.h4
4 files changed, 160 insertions, 101 deletions
diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp
index e516cd7980..593390ea56 100644
--- a/engines/prince/graphics.cpp
+++ b/engines/prince/graphics.cpp
@@ -37,6 +37,8 @@ GraphicsMan::GraphicsMan(PrinceEngine *vm)
initGraphics(640, 480, true);
_frontScreen = new Graphics::Surface();
_frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
+ _screenForInventory = new Graphics::Surface();
+ _screenForInventory->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
_shadowTable70 = new byte[256];
_shadowTable50 = new byte[256];
}
@@ -48,9 +50,9 @@ GraphicsMan::~GraphicsMan() {
delete[] _shadowTable50;
}
-void GraphicsMan::update() {
+void GraphicsMan::update(Graphics::Surface *screen) {
if (_changed) {
- _vm->_system->copyRectToScreen((byte*)_frontScreen->getBasePtr(0,0), 640, 0, 0, 640, 480);
+ _vm->_system->copyRectToScreen((byte*)screen->getBasePtr(0,0), 640, 0, 0, 640, 480);
_vm->_system->updateScreen();
_changed = false;
@@ -65,24 +67,24 @@ void GraphicsMan::change() {
_changed = true;
}
-void GraphicsMan::draw(uint16 posX, uint16 posY, const Graphics::Surface *s) {
- uint16 w = MIN(_frontScreen->w, s->w);
+void GraphicsMan::draw(Graphics::Surface *screen, uint16 posX, uint16 posY, const Graphics::Surface *s) {
+ uint16 w = MIN(screen->w, s->w);
for (uint y = 0; y < s->h; y++) {
- if (y < _frontScreen->h) {
- memcpy((byte*)_frontScreen->getBasePtr(0, y), (byte*)s->getBasePtr(0, y), w);
+ if (y < screen->h) {
+ memcpy((byte*)screen->getBasePtr(0, y), (byte*)s->getBasePtr(0, y), w);
}
}
change();
}
-void GraphicsMan::drawTransparentSurface(int32 posX, int32 posY, const Graphics::Surface *s, int transColor) {
+void GraphicsMan::drawTransparentSurface(Graphics::Surface *screen, int32 posX, int32 posY, const Graphics::Surface *s, int transColor) {
for (int y = 0; y < s->h; y++) {
for (int x = 0; x < s->w; x++) {
byte pixel = *((byte*)s->getBasePtr(x, y));
if (pixel != transColor) {
- if (x + posX < _frontScreen->w && x + posX >= 0) {
- if (y + posY < _frontScreen->h && y + posY >= 0) {
- *((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = pixel;
+ if (x + posX < screen->w && x + posX >= 0) {
+ if (y + posY < screen->h && y + posY >= 0) {
+ *((byte*)screen->getBasePtr(x + posX, y + posY)) = pixel;
}
}
}
@@ -91,7 +93,7 @@ void GraphicsMan::drawTransparentSurface(int32 posX, int32 posY, const Graphics:
change();
}
-void GraphicsMan::drawTransparentWithBlend(int32 posX, int32 posY, const Graphics::Surface *s, int transColor) {
+void GraphicsMan::drawTransparentWithBlend(Graphics::Surface *screen, int32 posX, int32 posY, const Graphics::Surface *s, int transColor) {
_blendTable = new byte[256];
for (int i = 0; i < 256; i++) {
_blendTable[i] = 255;
@@ -100,11 +102,11 @@ void GraphicsMan::drawTransparentWithBlend(int32 posX, int32 posY, const Graphic
for (int x = 0; x < s->w; x++) {
byte pixel = *((byte*)s->getBasePtr(x, y));
if (pixel != transColor) {
- if (x + posX < _frontScreen->w && x + posX >= 0) {
- if (y + posY < _frontScreen->h && y + posY >= 0) {
- byte backgroundPixel = *((byte*)_frontScreen->getBasePtr(x + posX, y + posY));
+ if (x + posX < screen->w && x + posX >= 0) {
+ if (y + posY < screen->h && y + posY >= 0) {
+ byte backgroundPixel = *((byte*)screen->getBasePtr(x + posX, y + posY));
byte blendPixel = getBlendTableColor(pixel, backgroundPixel);
- *((byte*)_frontScreen->getBasePtr(x + posX, y + posY)) = blendPixel;
+ *((byte*)screen->getBasePtr(x + posX, y + posY)) = blendPixel;
}
}
}
@@ -114,14 +116,14 @@ void GraphicsMan::drawTransparentWithBlend(int32 posX, int32 posY, const Graphic
change();
}
-void GraphicsMan::drawTransparent(Graphics::Surface *frontScreen, DrawNode *drawNode) {
+void GraphicsMan::drawTransparent(Graphics::Surface *screen, DrawNode *drawNode) {
for (int y = 0; y < drawNode->s->h; y++) {
for (int x = 0; x < drawNode->s->w; x++) {
byte pixel = *((byte*)drawNode->s->getBasePtr(x, y));
if (pixel != 255) {
- if (x + drawNode->posX < frontScreen->w && x + drawNode->posX >= 0) {
- if (y + drawNode->posY < frontScreen->h && y + drawNode->posY >= 0) {
- *((byte*)frontScreen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = pixel;
+ if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
+ if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
+ *((byte*)screen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = pixel;
}
}
}
@@ -129,19 +131,19 @@ void GraphicsMan::drawTransparent(Graphics::Surface *frontScreen, DrawNode *draw
}
}
-void GraphicsMan::drawMask(Graphics::Surface *frontScreen, DrawNode *drawNode) {
+void GraphicsMan::drawMask(Graphics::Surface *screen, DrawNode *drawNode) {
int maskWidth = drawNode->width >> 3;
int maskPostion = 0;
int maskCounter = 128;
for (int y = 0; y < drawNode->height; y++) {
int tempMaskPostion = maskPostion;
for (int x = 0; x < drawNode->width; x++) {
- if (x + drawNode->posX < frontScreen->w && x + drawNode->posX >= 0) {
- if (y + drawNode->posY < frontScreen->h && y + drawNode->posY >= 0) {
+ if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
+ if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
if ((drawNode->data[tempMaskPostion] & maskCounter) != 0) {
byte orgPixel = *((byte*)drawNode->originalRoomSurface->getBasePtr(x + drawNode->posX, y + drawNode->posY));
- *((byte*)frontScreen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = orgPixel;
- //*((byte*)frontScreen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = 0; // for debugging
+ *((byte*)screen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = orgPixel;
+ //*((byte*)screen->getBasePtr(x + drawNode->posX, y + drawNode->posY)) = 0; // for debugging
}
}
}
@@ -156,14 +158,14 @@ void GraphicsMan::drawMask(Graphics::Surface *frontScreen, DrawNode *drawNode) {
}
}
-void GraphicsMan::drawAsShadow(Graphics::Surface *frontScreen, DrawNode *drawNode) {
+void GraphicsMan::drawAsShadow(Graphics::Surface *screen, DrawNode *drawNode) {
for (int y = 0; y < drawNode->s->h; y++) {
for (int x = 0; x < drawNode->s->w; x++) {
byte pixel = *((byte*)drawNode->s->getBasePtr(x, y));
if (pixel == kShadowColor) {
- if (x + drawNode->posX < frontScreen->w && x + drawNode->posX >= 0) {
- if (y + drawNode->posY < frontScreen->h && y + drawNode->posY >= 0) {
- byte *background = (byte *)frontScreen->getBasePtr(x + drawNode->posX, y + drawNode->posY);
+ if (x + drawNode->posX < screen->w && x + drawNode->posX >= 0) {
+ if (y + drawNode->posY < screen->h && y + drawNode->posY >= 0) {
+ byte *background = (byte *)screen->getBasePtr(x + drawNode->posX, y + drawNode->posY);
*background = *(drawNode->data + *background);
}
}
diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h
index 7651dae7a1..c383c03bac 100644
--- a/engines/prince/graphics.h
+++ b/engines/prince/graphics.h
@@ -38,25 +38,25 @@ public:
GraphicsMan(PrinceEngine *vm);
~GraphicsMan();
- void update();
+ void update(Graphics::Surface *screen);
void change();
void setPalette(const byte *palette);
void makeShadowTable(int brightness, byte *shadowTable);
- void draw(uint16 x, uint16 y, const Graphics::Surface *s);
- void drawTransparentSurface(int32 posX, int32 poxY, const Graphics::Surface *s, int transColor);
- void drawTransparentWithBlend(int32 posX, int32 poxY, const Graphics::Surface *s, int transColor);
+ void draw(Graphics::Surface *screen, uint16 x, uint16 y, const Graphics::Surface *s);
+ void drawTransparentSurface(Graphics::Surface *screen, int32 posX, int32 poxY, const Graphics::Surface *s, int transColor);
+ void drawTransparentWithBlend(Graphics::Surface *screen, int32 posX, int32 poxY, const Graphics::Surface *s, int transColor);
- static void drawTransparent(Graphics::Surface *frontScreen, DrawNode *drawNode);
- static void drawAsShadow(Graphics::Surface *frontScreen, DrawNode *drawNode);
- static void drawMask(Graphics::Surface *frontScreen, DrawNode *drawNode);
+ static void drawTransparent(Graphics::Surface *screen, DrawNode *drawNode);
+ static void drawAsShadow(Graphics::Surface *screen, DrawNode *drawNode);
+ static void drawMask(Graphics::Surface *screen, DrawNode *drawNode);
byte getBlendTableColor(byte pixelColor, byte backgroundPixelColor);
Graphics::Surface *_frontScreen;
- Graphics::Surface *_backScreen;
+ Graphics::Surface *_screenForInventory;
const Graphics::Surface *_roomBackground;
byte *_shadowTable70;
diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp
index 0f0683ba29..261ba70b26 100644
--- a/engines/prince/prince.cpp
+++ b/engines/prince/prince.cpp
@@ -245,8 +245,8 @@ void PrinceEngine::showLogo() {
MhwanhDecoder logo;
if (Resource::loadResource(&logo, "logo.raw", true)) {
_graph->setPalette(logo.getPalette());
- _graph->draw(0, 0, logo.getSurface());
- _graph->update();
+ _graph->draw(_graph->_frontScreen, 0, 0, logo.getSurface());
+ _graph->update(_graph->_frontScreen);
_system->delayMillis(700);
}
}
@@ -411,7 +411,7 @@ bool PrinceEngine::playNextFrame() {
const Graphics::Surface *s = _flicPlayer.decodeNextFrame();
if (s) {
- _graph->drawTransparentSurface(0, 0, s, 255);
+ _graph->drawTransparentSurface(_graph->_frontScreen, 0, 0, s, 255);
_graph->change();
} else if (_flicLooped) {
_flicPlayer.rewind();
@@ -658,7 +658,6 @@ void PrinceEngine::keyHandler(Common::Event event) {
break;
case Common::KEYCODE_i:
_mainHero->_middleY -= 5;
- inventoryFlagChange();
break;
case Common::KEYCODE_k:
_mainHero->_middleY += 5;
@@ -686,38 +685,36 @@ void PrinceEngine::keyHandler(Common::Event event) {
}
}
-void PrinceEngine::hotspot() {
+void PrinceEngine::hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList) {
Common::Point mousepos = _system->getEventManager()->getMousePos();
Common::Point mousePosCamera(mousepos.x + _picWindowX, mousepos.y);
- for (Common::Array<Mob>::const_iterator it = _mobList.begin(); it != _mobList.end() ; it++) {
+ for (Common::Array<Mob>::const_iterator it = mobList.begin(); it != mobList.end() ; it++) {
const Mob& mob = *it;
- if (mob._visible)
+ if (mob._visible != 0) { // 0 is for visible
continue;
+ }
if (mob._rect.contains(mousePosCamera)) {
uint16 textW = 0;
- for (uint16 i = 0; i < mob._name.size(); ++i)
+ for (uint16 i = 0; i < mob._name.size(); i++) {
textW += _font->getCharWidth(mob._name[i]);
+ }
uint16 x = mousepos.x - textW/2;
- if (x > _graph->_frontScreen->w)
+ if (x > screen->w) {
x = 0;
+ }
- if (x + textW > _graph->_frontScreen->w)
- x = _graph->_frontScreen->w - textW;
+ if (x + textW > screen->w) {
+ x = screen->w - textW;
+ }
uint16 y = mousepos.y - _font->getFontHeight();
- if (y > _graph->_frontScreen->h)
+ if (y > screen->h) {
y = _font->getFontHeight() - 2;
+ }
- _font->drawString(
- _graph->_frontScreen,
- mob._name,
- x,
- y,
- _graph->_frontScreen->w,
- 216
- );
+ _font->drawString(screen, mob._name, x, y, screen->w, 216);
break;
}
}
@@ -1197,7 +1194,7 @@ void PrinceEngine::drawScreen() {
Graphics::Surface visiblePart;
if (roomSurface) {
visiblePart = roomSurface->getSubArea(Common::Rect(_picWindowX, 0, roomSurface->w, roomSurface->h));
- _graph->draw(0, 0, &visiblePart);
+ _graph->draw(_graph->_frontScreen, 0, 0, &visiblePart);
}
Graphics::Surface *mainHeroSurface = NULL;
@@ -1252,20 +1249,18 @@ void PrinceEngine::drawScreen() {
playNextFrame();
if (!_inventoryBackgroundRemember) {
- hotspot();
+ hotspot(_graph->_frontScreen, _mobList);
showTexts();
} else {
- rememberScreenInv();
_inventoryBackgroundRemember = false;
}
+ getDebugger()->onFrame();
+ _graph->update(_graph->_frontScreen);
+
} else {
displayInventory();
}
-
- getDebugger()->onFrame();
-
- _graph->update();
}
void PrinceEngine::pause() {
@@ -1276,24 +1271,34 @@ void PrinceEngine::pause() {
}
void PrinceEngine::addInvObj() {
- changeCursor(0); // turn on cursor later?
+ changeCursor(0);
//prepareInventoryToView();
+ _inventoryBackgroundRemember = true;
+ drawScreen();
+
+ Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
+
if (!_flags->getFlagValue(Flags::CURSEBLINK)) {
loadSample(27, "PRZEDMIO.WAV");
playSample(27, 0);
_mst_shadow2 = 1;
+
while (_mst_shadow2 < 512) {
- displayInventory();
- _graph->update();
+ rememberScreenInv();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
+ drawInvItems();
+ _graph->update(_graph->_screenForInventory);
_mst_shadow2 += 50;
pause();
}
while (_mst_shadow2 > 256) {
- displayInventory();
- _graph->update();
+ rememberScreenInv();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
+ drawInvItems();
+ _graph->update(_graph->_screenForInventory);
_mst_shadow2 -= 42;
pause();
}
@@ -1302,14 +1307,18 @@ void PrinceEngine::addInvObj() {
for (int i = 0; i < 3; i++) {
_mst_shadow2 = 256;
while (_mst_shadow2 < 512) {
- displayInventory();
- _graph->update();
+ rememberScreenInv();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
+ drawInvItems();
+ _graph->update(_graph->_screenForInventory);
_mst_shadow2 += 50;
pause();
}
while (_mst_shadow2 > 256) {
- displayInventory();
- _graph->update();
+ rememberScreenInv();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
+ drawInvItems();
+ _graph->update(_graph->_screenForInventory);
_mst_shadow2 -= 50;
pause();
}
@@ -1317,17 +1326,21 @@ void PrinceEngine::addInvObj() {
}
_mst_shadow2 = 0;
for (int i = 0; i < 20; i++) {
- displayInventory();
- _graph->update();
+ rememberScreenInv();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
+ drawInvItems();
+ _graph->update(_graph->_screenForInventory);
pause();
}
+ changeCursor(1); // here?
}
void PrinceEngine::rememberScreenInv() {
+ _graph->_screenForInventory->copyFrom(*_graph->_frontScreen);
}
-void PrinceEngine::inventoryFlagChange() {
- if (!_showInventoryFlag) {
+void PrinceEngine::inventoryFlagChange(bool inventoryState) {
+ if (inventoryState) {
_showInventoryFlag = true;
_inventoryBackgroundRemember = true;
} else {
@@ -1360,12 +1373,18 @@ void PrinceEngine::prepareInventoryToView() {
Mob tempMobItem;
if (item < _mainHero->_inventory.size()) {
int itemNr = _mainHero->_inventory[item];
+ tempMobItem._visible = 0;
tempMobItem._mask = itemNr; // itemNr - 1??
tempMobItem._x1 = currInvX + _picWindowX; //picWindowX2 ?
tempMobItem._x2 = currInvX + _picWindowX + _invLineW - 1; // picWindowX2 ?
tempMobItem._y1 = currInvY;
tempMobItem._y2 = currInvY + _invLineH - 1;
+ tempMobItem._rect.left = tempMobItem._x1;
+ tempMobItem._rect.right = tempMobItem._x2;
+ tempMobItem._rect.top = tempMobItem._y1;
+ tempMobItem._rect.bottom = tempMobItem._y2;
+
tempMobItem._name = "";
tempMobItem._examText = "";
int txtOffset = READ_UINT32(&_invTxt[itemNr * 8]);
@@ -1388,11 +1407,6 @@ void PrinceEngine::prepareInventoryToView() {
currInvX = _invLineX;
currInvY += _invLineSkipY + _invLineH;
}
- //moblistcreated:
- //mov w [edi.Mob_Visible],-1
- //mov eax,d InvMobList
- //mov d MobListAddr,eax
- //mov d MobPriAddr,o InvMobPri
}
void PrinceEngine::drawInvItems() {
@@ -1438,10 +1452,10 @@ void PrinceEngine::drawInvItems() {
drawX += (_maxInvW - itemSurface->w) / 2;
}
if (!_mst_shadow) {
- _graph->drawTransparentSurface(drawX, drawY, itemSurface, 0);
+ _graph->drawTransparentSurface(_graph->_screenForInventory, drawX, drawY, itemSurface, 0);
} else {
_mst_shadow = _mst_shadow2;
- _graph->drawTransparentWithBlend(drawX, drawY, itemSurface, 0);
+ _graph->drawTransparentWithBlend(_graph->_screenForInventory, drawX, drawY, itemSurface, 0);
}
}
currInvX += _invLineW + _invLineSkipX;
@@ -1463,26 +1477,63 @@ void PrinceEngine::displayInventory() {
prepareInventoryToView();
- _graph->drawTransparentSurface(0, 0, _graph->_frontScreen, 0);
- Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
- _graph->drawTransparentSurface(0, 0, suitcase, 0);
+ while (!shouldQuit()) {
+
+ Common::Event event;
+ Common::EventManager *eventMan = _system->getEventManager();
+ while (eventMan->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_KEYDOWN:
+ keyHandler(event);
+ break;
+ case Common::EVENT_KEYUP:
+ break;
+ case Common::EVENT_MOUSEMOVE:
+ break;
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_RBUTTONDOWN:
+ break;
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ break;
+ case Common::EVENT_QUIT:
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (shouldQuit())
+ return;
- drawInvItems();
+ rememberScreenInv();
- Common::Rect _inventoryRect;
- _inventoryRect.left = _invX1;
- _inventoryRect.top = _invY1;
- _inventoryRect.right = _invX1 + _invWidth;
- _inventoryRect.bottom = _invY1 + _invHeight;
- Common::Point mousePos = _system->getEventManager()->getMousePos();
+ Graphics::Surface *suitcase = _suitcaseBmp->getSurface();
+ _graph->drawTransparentSurface(_graph->_screenForInventory, 0, 0, suitcase, 0);
- if (!_invCurInside && _inventoryRect.contains(mousePos)) {
- _invCurInside = true;
- }
+ drawInvItems();
- if (_invCurInside && !_inventoryRect.contains(mousePos)) {
- inventoryFlagChange();
- _invCurInside = false;
+ Common::Rect _inventoryRect;
+ _inventoryRect.left = _invX1;
+ _inventoryRect.top = _invY1;
+ _inventoryRect.right = _invX1 + _invWidth;
+ _inventoryRect.bottom = _invY1 + _invHeight;
+ Common::Point mousePos = _system->getEventManager()->getMousePos();
+
+ if (!_invCurInside && _inventoryRect.contains(mousePos)) {
+ _invCurInside = true;
+ }
+
+ if (_invCurInside && !_inventoryRect.contains(mousePos)) {
+ inventoryFlagChange(false);
+ _invCurInside = false;
+ break;
+ }
+
+ hotspot(_graph->_screenForInventory, _invMobList);
+ getDebugger()->onFrame();
+ _graph->update(_graph->_screenForInventory);
+ pause();
}
}
@@ -1542,6 +1593,12 @@ void PrinceEngine::mainLoop() {
_frameNr++;
+ // inventory turning on:
+ Common::Point mousePos = _system->getEventManager()->getMousePos();
+ if (mousePos.y == 0 && !_showInventoryFlag) {
+ inventoryFlagChange(true);
+ }
+
if (_debugger->_locationNr != _locationNr)
loadLocation(_debugger->_locationNr);
if (_debugger->_cursorNr != _cursorNr)
diff --git a/engines/prince/prince.h b/engines/prince/prince.h
index 9259fe703a..b85a1610c8 100644
--- a/engines/prince/prince.h
+++ b/engines/prince/prince.h
@@ -299,7 +299,7 @@ public:
int _mst_shadow2; // blinking after adding new item
int _candleCounter; // special counter for candle inventory item
- void inventoryFlagChange();
+ void inventoryFlagChange(bool inventoryState);
bool loadAllInv();
void rememberScreenInv();
void prepareInventoryToView();
@@ -314,7 +314,7 @@ public:
private:
bool playNextFrame();
void keyHandler(Common::Event event);
- void hotspot();
+ void hotspot(Graphics::Surface *screen, Common::Array<Mob> &mobList);
void drawScreen();
void showTexts();
void init();