diff options
author | Matthew Hoops | 2011-07-20 09:27:39 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-07-20 09:27:39 -0400 |
commit | ad293b249e74dd1cfbdbd721d02145efbdaf9eca (patch) | |
tree | e568d96f6d7f64c5e58b4c7cd1c4fda7e649bfc7 /engines/teenagent | |
parent | d7411acc2b1c7702280dbff1c3e1bafee528184b (diff) | |
parent | e25e85fbb047fef895ede97c3c2c73451631052c (diff) | |
download | scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.gz scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.tar.bz2 scummvm-rg350-ad293b249e74dd1cfbdbd721d02145efbdaf9eca.zip |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/teenagent')
-rw-r--r-- | engines/teenagent/animation.cpp | 4 | ||||
-rw-r--r-- | engines/teenagent/inventory.cpp | 2 | ||||
-rw-r--r-- | engines/teenagent/inventory.h | 4 | ||||
-rw-r--r-- | engines/teenagent/resources.cpp | 11 | ||||
-rw-r--r-- | engines/teenagent/resources.h | 6 | ||||
-rw-r--r-- | engines/teenagent/scene.cpp | 8 | ||||
-rw-r--r-- | engines/teenagent/teenagent.cpp | 135 |
7 files changed, 126 insertions, 44 deletions
diff --git a/engines/teenagent/animation.cpp b/engines/teenagent/animation.cpp index af54bca6a4..e945bda1e5 100644 --- a/engines/teenagent/animation.cpp +++ b/engines/teenagent/animation.cpp @@ -115,7 +115,7 @@ void Animation::load(Common::SeekableReadStream *s, Type type) { return; } - uint16 pos = 0; + //uint16 pos = 0; int off = 0; switch (type) { case kTypeLan: @@ -141,7 +141,7 @@ void Animation::load(Common::SeekableReadStream *s, Type type) { frames = new Surface[frames_count]; s->skip(frames_count * 2 - 2); //sizes - pos = s->readUint16LE(); + /*pos = */s->readUint16LE(); //debug(0, "pos?: %04x", pos); for (uint16 i = 0; i < frames_count; ++i) { diff --git a/engines/teenagent/inventory.cpp b/engines/teenagent/inventory.cpp index 8430f42c61..4951b2d940 100644 --- a/engines/teenagent/inventory.cpp +++ b/engines/teenagent/inventory.cpp @@ -58,7 +58,7 @@ Inventory::Inventory(TeenAgentEngine *engine) { for (byte i = 0; i < offsets; ++i) { _offset[i] = READ_LE_UINT16(_items + i * 2 + 1); } - _offset[92] = items_size; + _offset[92] = items_size; Resources *res = Resources::instance(); for (byte i = 0; i <= 92; ++i) { diff --git a/engines/teenagent/inventory.h b/engines/teenagent/inventory.h index 55c58a1c22..61e5364542 100644 --- a/engines/teenagent/inventory.h +++ b/engines/teenagent/inventory.h @@ -75,12 +75,12 @@ private: void backgroundEffect(Graphics::Surface *s); void render(Inventory *inventory, uint item_id, Graphics::Surface *surface, int delta); }; - + Item _graphics[24]; bool _active; Common::Point _mouse; - + bool tryObjectCallback(InventoryObject *obj); InventoryObject *_hoveredObj; diff --git a/engines/teenagent/resources.cpp b/engines/teenagent/resources.cpp index 9e69383215..597ca670c0 100644 --- a/engines/teenagent/resources.cpp +++ b/engines/teenagent/resources.cpp @@ -106,13 +106,20 @@ void Resources::loadOff(Graphics::Surface &surface, byte *palette, int id) { error("invalid background %d", id); return; } - byte buf[64768]; - off.read(id, buf, sizeof(buf)); + + const uint bufferSize = 64768; + byte *buf = (byte *)malloc(bufferSize); + if (!buf) + error("[Resources::loadOff] Cannot allocate buffer"); + + off.read(id, buf, bufferSize); byte *src = buf; byte *dst = (byte *)surface.pixels; memcpy(dst, src, 64000); memcpy(palette, buf + 64000, 768); + + free(buf); } Common::SeekableReadStream *Resources::loadLan(uint32 id) const { diff --git a/engines/teenagent/resources.h b/engines/teenagent/resources.h index c2eb32dbd4..5c08a46489 100644 --- a/engines/teenagent/resources.h +++ b/engines/teenagent/resources.h @@ -44,9 +44,9 @@ public: //void loadOn(Graphics::Surface &surface, int id, uint16 &dst, uint16 *flags); //void loadOns(Graphics::Surface &surface, int id, uint16 &dst); - /* - * PSP (as the other sony playstation consoles - to be confirmed and 'ifdef'ed here too) - * is very sensitive to the number of simultaneously opened files. + /* + * PSP (as the other sony playstation consoles - to be confirmed and 'ifdef'ed here too) + * is very sensitive to the number of simultaneously opened files. * This is an attempt to reduce their number to zero. * TransientFilePack does not keep opened file descriptors and reopens it on each request. */ diff --git a/engines/teenagent/scene.cpp b/engines/teenagent/scene.cpp index ef18b95f5a..4be6c9c31a 100644 --- a/engines/teenagent/scene.cpp +++ b/engines/teenagent/scene.cpp @@ -576,7 +576,7 @@ void Scene::paletteEffect(byte step) { byte *src = res->dseg.ptr(0x6609); byte *dst = palette + 3 * 0xf2; for(byte i = 0; i < 0xd; ++i) { - for(byte c = 0; c < 3; ++c, ++src) + for(byte c = 0; c < 3; ++c, ++src) *dst++ = *src > step? *src - step: 0; } } @@ -812,9 +812,9 @@ bool Scene::render(bool tick_game, bool tick_mark, uint32 delta) { _system->unlockScreen(); continue; } - //removed mark == null. In final scene of chapter 2 mark rendered above table. - //if it'd cause any bugs, add hack here. (_id != 23 && mark == NULL) - if (on_enabled && + //removed mark == null. In final scene of chapter 2 mark rendered above table. + //if it'd cause any bugs, add hack here. (_id != 23 && mark == NULL) + if (on_enabled && debug_features.feature[DebugFeatures::kShowOn]) { on.render(surface, actor_animation_position); } diff --git a/engines/teenagent/teenagent.cpp b/engines/teenagent/teenagent.cpp index ce8862ffd0..0289b994e6 100644 --- a/engines/teenagent/teenagent.cpp +++ b/engines/teenagent/teenagent.cpp @@ -206,7 +206,7 @@ void TeenAgentEngine::deinit() { Common::Error TeenAgentEngine::loadGameState(int slot) { debug(0, "loading from slot %d", slot); - Common::ScopedPtr<Common::InSaveFile> + Common::ScopedPtr<Common::InSaveFile> in(_saveFileMan->openForLoading(Common::String::format("teenagent.%02d", slot))); if (!in) in.reset(_saveFileMan->openForLoading(Common::String::format("teenagent.%d", slot))); @@ -216,14 +216,22 @@ Common::Error TeenAgentEngine::loadGameState(int slot) { Resources *res = Resources::instance(); - assert(res->dseg.size() >= 0x6478 + 0x777a); - char data[0x777a]; + const uint dataSize = 0x777a; + assert(res->dseg.size() >= 0x6478 + dataSize); + + char *data = (char *)malloc(dataSize); + if (!data) + error("[TeenAgentEngine::loadGameState] Cannot allocate buffer"); + in->seek(0); - if (in->read(data, 0x777a) != 0x777a) { + if (in->read(data, dataSize) != dataSize) { + free(data); return Common::kReadingFailed; } - memcpy(res->dseg.ptr(0x6478), data, sizeof(data)); + memcpy(res->dseg.ptr(0x6478), data, dataSize); + + free(data); scene->clear(); inventory->activate(false); @@ -290,17 +298,32 @@ bool TeenAgentEngine::showCDLogo() { if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res")) return true; - byte bg[0xfa00]; - byte palette[3*256]; + const uint bgSize = 0xfa00; + const uint paletteSize = 3 * 256; + + byte *bg = (byte *)malloc(bgSize); + if (!bg) + error("[TeenAgentEngine::showCDLogo] Cannot allocate background buffer"); - cdlogo.read(bg, sizeof(bg)); - cdlogo.read(palette, sizeof(palette)); - for (uint c = 0; c < 3*256; ++c) + byte *palette = (byte *)malloc(paletteSize); + if (!palette) { + free(bg); + error("[TeenAgentEngine::showCDLogo] Cannot allocate palette buffer"); + } + + cdlogo.read(bg, bgSize); + cdlogo.read(palette, paletteSize); + + for (uint c = 0; c < paletteSize; ++c) palette[c] *= 4; + _system->getPaletteManager()->setPalette(palette, 0, 0x100); _system->copyRectToScreen(bg, 320, 0, 0, 320, 200); _system->updateScreen(); + free(bg); + free(palette); + for(uint i = 0; i < 20; ++i) { int r = skipEvents(); if (r != 0) @@ -317,43 +340,66 @@ bool TeenAgentEngine::showLogo() { if (!logo.open("unlogic.res")) return true; - byte bg[0xfa00]; - byte palette[3*256]; - Common::ScopedPtr<Common::SeekableReadStream> frame(logo.getStream(1)); if (!frame) return true; - frame->read(bg, sizeof(bg)); - frame->read(palette, sizeof(palette)); - for (uint c = 0; c < 3*256; ++c) + const uint bgSize = 0xfa00; + const uint paletteSize = 3 * 256; + + byte *bg = (byte *)malloc(bgSize); + if (!bg) + error("[TeenAgentEngine::showLogo] Cannot allocate background buffer"); + + byte *palette = (byte *)malloc(paletteSize); + if (!palette) { + free(bg); + error("[TeenAgentEngine::showLogo] Cannot allocate palette buffer"); + } + + frame->read(bg, bgSize); + frame->read(palette, paletteSize); + + for (uint c = 0; c < paletteSize; ++c) palette[c] *= 4; + _system->getPaletteManager()->setPalette(palette, 0, 0x100); + free(palette); + uint n = logo.fileCount(); for(uint f = 0; f < 4; ++f) for(uint i = 2; i <= n; ++i) { { int r = skipEvents(); - if (r != 0) + if (r != 0) { + free(bg); return r > 0? true: false; + } } _system->copyRectToScreen(bg, 320, 0, 0, 320, 200); frame.reset(logo.getStream(i)); - if (!frame) + if (!frame) { + free(bg); return true; + } Surface s; s.load(frame, Surface::kTypeOns); - if (s.empty()) + if (s.empty()) { + free(bg); return true; + } _system->copyRectToScreen((const byte *)s.pixels, s.w, s.x, s.y, s.w, s.h); _system->updateScreen(); _system->delayMillis(100); } + + free(bg); + return true; } @@ -364,29 +410,53 @@ bool TeenAgentEngine::showMetropolis() { FilePack varia; varia.open("varia.res"); - byte palette[3*256]; + const uint paletteSize = 3 * 256; + byte *palette = (byte *)malloc(paletteSize); + if (!palette) + error("[TeenAgentEngine::showMetropolis] Cannot allocate palette buffer"); + { Common::ScopedPtr<Common::SeekableReadStream> s(varia.getStream(5)); - s->read(palette, sizeof(palette)); - for (uint c = 0; c < 3*256; ++c) + s->read(palette, paletteSize); + for (uint c = 0; c < paletteSize; ++c) palette[c] *= 4; } _system->getPaletteManager()->setPalette(palette, 0, 0x100); - byte varia_6[21760], varia_9[18302]; - varia.read(6, varia_6, sizeof(varia_6)); - varia.read(9, varia_9, sizeof(varia_9)); + free(palette); - byte colors[56 * 160 * 2]; - memset(colors, 0, sizeof(colors)); + const uint varia6Size = 21760; + const uint varia9Size = 18302; + byte *varia_6 = (byte *)malloc(varia6Size); + byte *varia_9 = (byte *)malloc(varia9Size); + if (!varia_6 || !varia_9) { + free(varia_6); + free(varia_9); + + error("[TeenAgentEngine::showMetropolis] Cannot allocate buffer"); + } + + varia.read(6, varia_6, varia6Size); + varia.read(9, varia_9, varia9Size); + + const uint colorsSize = 56 * 160 * 2; + byte *colors = (byte *)malloc(colorsSize); + if (!colors) + error("[TeenAgentEngine::showMetropolis] Cannot allocate colors buffer"); + + memset(colors, 0, colorsSize); int logo_y = -56; for(uint f = 0; f < 300; ++f) { { int r = skipEvents(); - if (r != 0) + if (r != 0) { + free(varia_6); + free(varia_9); + free(colors); return r > 0? true: false; + } } Graphics::Surface *surface = _system->lockScreen(); @@ -441,6 +511,11 @@ bool TeenAgentEngine::showMetropolis() { _system->updateScreen(); _system->delayMillis(100); } + + free(varia_6); + free(varia_9); + free(colors); + return true; } @@ -963,10 +1038,10 @@ void TeenAgentEngine::playSoundNow(byte id) { void TeenAgentEngine::setMusic(byte id) { debug(0, "starting music %u", id); Resources *res = Resources::instance(); - + if (id != 1) //intro music *res->dseg.ptr(0xDB90) = id; - + if (_gameDescription->flags & ADGF_CD) { byte track2cd[] = {7, 2, 0, 9, 3, 6, 8, 10, 4, 5, 11}; if (id == 0 || id > 11 || track2cd[id - 1] == 0) { |