Skip to content

Commit

Permalink
PINK: Implemented changing page and module, but without unloading old…
Browse files Browse the repository at this point in the history
… page. For now it can play logo of Wanderlust Interactive, then logo of MGM and Localizer Logo.
  • Loading branch information
whitertandrek authored and sev- committed Jun 28, 2018
1 parent c6df869 commit 0e39a87
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 97 deletions.
7 changes: 7 additions & 0 deletions engines/pink/cel_decoder.cpp
Expand Up @@ -64,6 +64,13 @@ uint32 CelDecoder::getY() {
return track->getY();
}

Graphics::Surface *CelDecoder::getCurrentFrame() {
CelVideoTrack *track = (CelVideoTrack*) getTrack(0);
if (!track)
return nullptr;
return nullptr;
}

CelDecoder::CelVideoTrack::CelVideoTrack(Common::SeekableReadStream *stream, uint16 frameCount, uint16 width, uint16 height, bool skipHeader)
: FlicVideoTrack(stream, frameCount, width, height, 1) {
readHeader();
Expand Down
2 changes: 2 additions & 0 deletions engines/pink/cel_decoder.h
Expand Up @@ -33,6 +33,8 @@ class CelDecoder : public Video::FlicDecoder {
uint32 getX();
uint32 getY();

Graphics::Surface *getCurrentFrame();

virtual bool loadStream(Common::SeekableReadStream *stream);

protected:
Expand Down
30 changes: 29 additions & 1 deletion engines/pink/director.cpp
Expand Up @@ -21,6 +21,7 @@
*/

#include "director.h"
#include <engines/pink/objects/actions/action_sound.h>
#include <engines/pink/objects/actions/action_cel.h>
#include "graphics/surface.h"
#include "graphics/palette.h"
Expand All @@ -47,7 +48,14 @@ void Director::draw() {
}

void Director::addSprite(ActionCEL *sprite) {
_sprites.push_back(sprite); //TODO impl sorting
_sprites.push_back(sprite);
int i;
for (i = _sprites.size() - 1; i > 0 ; --i) {
if (sprite->getZ() < _sprites[i - 1]->getZ()){
_sprites[i] = _sprites[i - 1];
} else break;
}
_sprites[i] = sprite;
}

void Director::removeSprite(ActionCEL *sprite) {
Expand All @@ -63,4 +71,24 @@ void Director::setPallette(const byte *pallete) {
_system->getPaletteManager()->setPalette(pallete, 0, 256);
}

void Director::update() {
for (int i = 0; i < _sounds.size(); ++i) {
_sounds[i]->update();
}
for (int i = 0; i < _sprites.size(); ++i) {
_sprites[i]->update();
}
}

void Director::addSound(ActionSound *sound) {
_sounds.push_back(sound);
}

void Director::removeSound(ActionSound *sound) {
for (int i = 0; i < _sounds.size(); ++i) {
if (_sounds[i] == sound)
_sounds.remove_at(i);
}
}

}
11 changes: 8 additions & 3 deletions engines/pink/director.h
Expand Up @@ -29,22 +29,27 @@
namespace Pink {

class ActionCEL;
class ActionSound;

class Director {
public:
Director(OSystem *system);
//void addSoundObject();
//void removeSound();
//void updateSoundAction
//CActor *getActorByCoords()

void draw();
void update();

void addSprite(ActionCEL *sprite);
void removeSprite(ActionCEL *sprite);
void setPallette(const byte *pallete);

void addSound(ActionSound* sound);
void removeSound(ActionSound* sound);

private:
OSystem *_system;
Common::Array<ActionCEL*> _sprites;
Common::Array<ActionSound*> _sounds;
};

} // End of namespace Pink
Expand Down
2 changes: 1 addition & 1 deletion engines/pink/file.cpp
Expand Up @@ -167,7 +167,7 @@ void ResourceDescription::load(Common::File &file) {

uint16 temp;
file.read(&temp, sizeof(temp));
inBro = temp ? true : false;
inBro = temp;
}

} // End of namespace Pink
9 changes: 9 additions & 0 deletions engines/pink/objects/actions/action_cel.cpp
Expand Up @@ -64,8 +64,17 @@ CelDecoder *ActionCEL::getDecoder() {
bool ActionCEL::initPallete(Director *director) {
_decoder = _actor->getPage()->loadCel(_fileName);
_decoder->decodeNextFrame();
_decoder->rewind();
director->setPallette(_decoder->getPalette());

return 1;
}

void ActionCEL::update() {
if (_decoder->endOfVideo()){
_decoder->stop();
_actor->endAction();
}
}

} // End of namespace Pink
1 change: 1 addition & 0 deletions engines/pink/objects/actions/action_cel.h
Expand Up @@ -36,6 +36,7 @@ class ActionCEL : public Action {
virtual void deserialize(Archive &archive);
virtual void start(bool unk);
virtual void end();
virtual void update();

uint32 getZ();
CelDecoder *getDecoder();
Expand Down
9 changes: 9 additions & 0 deletions engines/pink/objects/actions/action_sound.cpp
Expand Up @@ -26,6 +26,7 @@
#include <engines/pink/objects/actors/actor.h>
#include <engines/pink/objects/pages/game_page.h>
#include <engines/pink/sound.h>
#include "engines/pink/pink.h"


namespace Pink {
Expand Down Expand Up @@ -53,6 +54,10 @@ void ActionSound::start(bool unk) {

Audio::Mixer::SoundType soundType = _isBackground ? Audio::Mixer::SoundType::kMusicSoundType
: Audio::Mixer::SoundType::kSpeechSoundType;

Director *director = _actor->getPage()->getGame()->getDirector();
director->addSound(this);

_sound->play(soundType, _volume, _isLoop);
if (_isLoop)
_actor->endAction();
Expand All @@ -62,6 +67,10 @@ void ActionSound::start(bool unk) {

void ActionSound::end() {
debug("ActionSound %s of Actor %s is ended", _name.c_str(), _actor->getName().c_str());

Director *director = _actor->getPage()->getGame()->getDirector();
director->removeSound(this);

_sound->stop();
delete _sound;
_sound = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions engines/pink/objects/actions/action_still.cpp
Expand Up @@ -34,8 +34,8 @@ void ActionStill::deserialize(Archive &archive) {
}

void ActionStill::toConsole() {
debug("\tActionStill: _name = %s, _fileName = %s, _startFrame = %u",
_name.c_str(), _fileName.c_str(), _startFrame);
debug("\tActionStill: _name = %s, _fileName = %s, _z =%u _startFrame = %u",
_name.c_str(), _fileName.c_str(), _z, _startFrame);
}

void ActionStill::end() {
Expand Down
3 changes: 1 addition & 2 deletions engines/pink/objects/actions/walk_action.cpp
Expand Up @@ -22,14 +22,13 @@

#include "walk_action.h"
#include <engines/pink/archive.h>
#include <common/debug.h>

namespace Pink {

void WalkAction::deserialize(Archive &archive) {
ActionCEL::deserialize(archive);
uint32 calcFramePositions = archive.readDWORD();
_toCalcFramePositions = calcFramePositions ? true : false;
_toCalcFramePositions = calcFramePositions;
}

void WalkAction::toConsole() {
Expand Down
5 changes: 3 additions & 2 deletions engines/pink/objects/actors/actor.cpp
Expand Up @@ -108,14 +108,15 @@ Action *Actor::getAction() const {
}

bool Actor::isPlaying() {
return _isActionEnded;
return !_isActionEnded;
}

bool Actor::initPallete(Director *director) {
for (int i = 0; i < _actions.size(); ++i) {
if (_actions[i]->initPallete(director))
break;
return true;
}
return false;
}

} // End of namespace Pink
2 changes: 2 additions & 0 deletions engines/pink/objects/actors/actor.h
Expand Up @@ -59,6 +59,8 @@ class Actor : public NamedObject {

bool initPallete(Director *director);

void update() {};

protected:
GamePage *_page;
Action *_action;
Expand Down
14 changes: 14 additions & 0 deletions engines/pink/objects/actors/lead_actor.cpp
Expand Up @@ -50,6 +50,7 @@ void LeadActor::init(bool unk) {
_state = kReady;
}
_page->getModule()->getInventoryMgr()->setLeadActor(this);
_page->getGame()->setLeadActor(this);
Actor::init(unk);
}

Expand All @@ -64,6 +65,19 @@ LeadActor::State LeadActor::getState() const {
return _state;
}

void LeadActor::update() {
switch (_state) {
case kPlayingVideo:
_sequencer->update();
if (!_sequencer->_context){
_state = kUnk_Loading;
_page->getGame()->changeScene(_page);
}
default:
break;
}
}

void ParlSqPink::toConsole() {
debug("ParlSqPink: _name = %s", _name.c_str());
for (int i = 0; i < _actions.size(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions engines/pink/objects/actors/lead_actor.h
Expand Up @@ -54,6 +54,7 @@ class LeadActor : public Actor {
State getState() const;

void start(bool isHandler);
void update();

private:
State _state;
Expand Down
59 changes: 22 additions & 37 deletions engines/pink/objects/module.cpp
Expand Up @@ -22,6 +22,7 @@

#include "module.h"
#include "engines/pink/objects/pages/game_page.h"
#include "pink/pink.h"

namespace Pink {

Expand All @@ -45,52 +46,36 @@ void Module::load(Archive &archive){
archive >> _pages;
}

void Module::init(bool isLoadingSave, const Common::String *pageName) {
// debugging original
void Module::init(bool isLoadingSave, const Common::String &pageName) {
// 0 0 - new game
// 0 1 - module changed
// 1 0 - from save

// 1 1 - haven't seen those values

//this func will be rewrited after testing

if (_page) {
debug("loading from save");
}
if (pageName){
debug("module changed");
}
assert(_pages.size() != 0);

if (pageName) {
uint i;
for (i = 0; i < _pages.size(); ++i) {
if(*pageName == _pages[i]->getName()) {
_page = _pages[i];
}
}
assert(i < _pages.size());
}

if (_page) {
_page->init(isLoadingSave); // module changed or from save
return;
if (!pageName.empty()) {
_page = findPage(pageName);
}

if (_page != _pages[0]) {
if (_page) {
assert(0); // in original code there is call to page func but I've never seen it
return;
}
if (!_page)
_page = _pages[0];
_page->init(isLoadingSave); // new game
return;
}

assert(0);
_page->init(isLoadingSave);
}

void Module::changePage(const Common::String &pageName) {
GamePage *page = nullptr;
page = findPage(pageName);
assert(_page != page);
//_page->clear
page->init(kLoadingNewGame);
}

GamePage *Module::findPage(const Common::String &pageName) const {
return *Common::find_if(_pages.begin(), _pages.end(), [&pageName]
(GamePage* page) {
return pageName == page->getName();
});
}


PinkEngine *Module::getGame() const {
return _game;
}
Expand Down
6 changes: 4 additions & 2 deletions engines/pink/objects/module.h
Expand Up @@ -45,20 +45,22 @@ class Module : public NamedObject {
Module(PinkEngine *game, const Common::String &name);

void load(Archive &archive);
void init(bool isLoadingSave, const Common::String *pageName);
void init(bool isLoadingSave, const Common::String &pageName);
void changePage(const Common::String &pageName);

void OnLeftButtonDown();
void OnMouseMove();
void OnKeyboardButtonClick();


PinkEngine *getGame() const;
InventoryMgr *getInventoryMgr();

bool checkValueOfVariable(Common::String &variable, Common::String &value);
void setVariable(Common::String &variable, Common::String &value);

private:
GamePage *findPage(const Common::String &pageName) const;

PinkEngine *_game;
GamePage *_page;
Common::Array<GamePage*> _pages;
Expand Down

0 comments on commit 0e39a87

Please sign in to comment.