[Scummvm-cvs-logs] SF.net SVN: scummvm:[48372] scummvm/branches/branch-1-1-0/engines/teenagent
megath at users.sourceforge.net
megath at users.sourceforge.net
Tue Mar 23 22:23:57 CET 2010
Revision: 48372
http://scummvm.svn.sourceforge.net/scummvm/?rev=48372&view=rev
Author: megath
Date: 2010-03-23 21:23:56 +0000 (Tue, 23 Mar 2010)
Log Message:
-----------
merged teenagent engine back from trunk
Modified Paths:
--------------
scummvm/branches/branch-1-1-0/engines/teenagent/callbacks.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/detection.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/font.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/font.h
scummvm/branches/branch-1-1-0/engines/teenagent/inventory.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/inventory.h
scummvm/branches/branch-1-1-0/engines/teenagent/music.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/music.h
scummvm/branches/branch-1-1-0/engines/teenagent/objects.h
scummvm/branches/branch-1-1-0/engines/teenagent/pack.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/pack.h
scummvm/branches/branch-1-1-0/engines/teenagent/resources.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/resources.h
scummvm/branches/branch-1-1-0/engines/teenagent/scene.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/scene.h
scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.cpp
scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.h
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/callbacks.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/callbacks.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/callbacks.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -289,6 +289,7 @@
Dialog::show(scene, 0x6117, 0, 813, 0xd1, 0xec, 0, 1);
loadScene(6, 230, 184);
+ playMusic(5);
Dialog::show(scene, 0x626a, 0, 814, 0xd1, 0xec, 0, 1);
playSound(4, 14);
playAnimation(815, 0);
@@ -297,7 +298,6 @@
Dialog::showMono(scene, 0x62dc, 0, 0xd1, 0);
SET_FLAG(0xDBDF, 1);
- playMusic(5);
}
return true;
@@ -1389,8 +1389,8 @@
case 0x5502:
setOns(0, 0);
loadScene(15, 115, 180, 1);
+ playMusic(6);
playActorAnimation(568);
- playMusic(6);
return true;
case 0x5561://Enter lakeside house
@@ -2199,6 +2199,7 @@
case 0x7f23://Use grenade on captains drawer
if (CHECK_FLAG(0xDBDF, 3)) {
+ enableOn(false);
playSound(5, 3);
playSound(58, 11);
playSound(46, 56);
@@ -2212,6 +2213,7 @@
moveTo(224, 194, 0, true);
displayCutsceneMessage(0x57df, 30423);
inventory->remove(0x59);
+ enableOn(true);
} else {
displayMessage(0x5de2);
}
@@ -2439,17 +2441,17 @@
SET_FLAG(0xDB9F, 1);
return true;
- case 0x84c7:
+ case 0x84c7: //using paddle on boat
playSound(20, 9);
playActorAnimation(530);
loadScene(16, 236, 95, 1);
+ playMusic(9);
playActorAnimation(531);
playSound(36, 4);
playActorAnimation(532);
playActorAnimation(533);
setOns(0, 9);
moveTo(236, 95, 1, true);
- playMusic(9);
return true;
case 0x8538://Sharpen sickle on well
@@ -2707,11 +2709,11 @@
playAnimation(675, 0, true);
waitAnimation();
loadScene(28, 0, 167, 2);
+ playMusic(10);
moveTo(66, 167, 2);
displayMessage(0x4a6f);
inventory->clear();
inventory->add(29);
- playMusic(10);
} else
displayMessage(0x4a29);
return true;
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/detection.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/detection.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/detection.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -76,6 +76,7 @@
#define MAX_SAVES 20
+
class TeenAgentMetaEngine : public AdvancedMetaEngine {
public:
TeenAgentMetaEngine() : AdvancedMetaEngine(detectionParams) {
@@ -129,17 +130,15 @@
int slot;
const char *ext = strrchr(file->c_str(), '.');
if (ext && (slot = atoi(ext + 1)) >= 0 && slot < MAX_SAVES) {
- Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file);
- if (in) {
- char buf[25];
- in->seek(0);
- in->read(buf, 24);
- buf[24] = 0;
- Common::String description = buf;
- saveList.push_back(SaveStateDescriptor(slot, description));
+ TeenAgent::ScopedPtr<Common::InSaveFile> in(g_system->getSavefileManager()->openForLoading(*file));
+ if (!in)
+ continue;
- delete in;
- }
+ char buf[25];
+ in->seek(0);
+ in->read(buf, 24);
+ buf[24] = 0;
+ saveList.push_back(SaveStateDescriptor(slot, buf));
}
}
return saveList;
@@ -156,8 +155,8 @@
virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const {
Common::String filename = generateGameStateFileName(target, slot);
- Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename);
- if (in == NULL)
+ TeenAgent::ScopedPtr<Common::InSaveFile> in(g_system->getSavefileManager()->openForLoading(filename));
+ if (!in)
return SaveStateDescriptor();
char buf[25];
@@ -171,15 +170,14 @@
if (!Graphics::checkThumbnailHeader(*in))
return SaveStateDescriptor(slot, desc);
- Graphics::Surface *thumb = new Graphics::Surface;
- if (!Graphics::loadThumbnail(*in, *thumb)) {
- delete thumb;
- return SaveStateDescriptor(slot, desc);
- }
-
SaveStateDescriptor ssd(slot, desc);
- ssd.setThumbnail(thumb);
+ ssd.setDeletableFlag(true);
+ //checking for the thumbnail
+ TeenAgent::ScopedPtr<Graphics::Surface> thumb(new Graphics::Surface);
+ if (Graphics::loadThumbnail(*in, *thumb))
+ ssd.setThumbnail(thumb.release());
+
return ssd;
}
};
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/font.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/font.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/font.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -23,19 +23,22 @@
*/
#include "teenagent/font.h"
-#include "teenagent/resources.h"
+#include "teenagent/pack.h"
+#include "teenagent/objects.h"
+#include "common/stream.h"
+#include "common/ptr.h"
namespace TeenAgent {
Font::Font() : grid_color(0xd0), shadow_color(0), height(0), width_pack(0), data(0) {
}
-void Font::load(int id) {
+void Font::load(const Pack &pack, int id) {
delete[] data;
data = NULL;
- Common::SeekableReadStream *s = Resources::instance()->varia.getStream(id);
- if (s == NULL)
+ ScopedPtr<Common::SeekableReadStream> s(pack.getStream(id));
+ if (!s)
error("loading font %d failed", id);
data = new byte[s->size()];
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/font.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/font.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/font.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -29,13 +29,14 @@
namespace TeenAgent {
+class Pack;
class Font {
public:
byte grid_color, shadow_color;
byte height, width_pack;
Font();
- void load(int id);
+ void load(const Pack &pack, int id);
uint render(Graphics::Surface *surface, int x, int y, const Common::String &str, byte color, bool grid = false);
uint render(Graphics::Surface *surface, int x, int y, char c, byte color);
static void grid(Graphics::Surface *surface, int x, int y, int w, int h, byte color);
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/inventory.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/inventory.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/inventory.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -35,22 +35,33 @@
void Inventory::init(TeenAgentEngine *engine) {
_engine = engine;
_active = false;
- Resources *res = Resources::instance();
- Common::SeekableReadStream *s = res->varia.getStream(3);
- assert(s != NULL);
- debug(0, "loading inventory background...");
- background.load(s, Surface::kTypeOns);
+ FilePack varia;
+ varia.open("varia.res");
- items = res->varia.getStream(4);
- assert(items != NULL);
+ {
+ ScopedPtr<Common::SeekableReadStream> s(varia.getStream(3));
+ if (!s)
+ error("no inventory background");
+ debug(0, "loading inventory background...");
+ background.load(s, Surface::kTypeOns);
+ }
- byte offsets = items->readByte();
+ uint32 items_size = varia.getSize(4);
+ if (items_size == 0)
+ error("invalid inventory items size");
+ debug(0, "loading items, size: %u", items_size);
+ items = new byte[items_size];
+ varia.read(4, items, items_size);
+
+ byte offsets = items[0];
assert(offsets == 92);
- for (byte i = 0; i <= offsets; ++i) {
- offset[i] = items->readUint16LE();
+ for (byte i = 0; i < offsets; ++i) {
+ offset[i] = READ_LE_UINT16(items + i * 2 + 1);
}
+ offset[92] = items_size;
+ Resources *res = Resources::instance();
for (byte i = 0; i <= 92; ++i) {
InventoryObject io;
uint16 obj_addr = res->dseg.get_word(0xc4a4 + i * 2);
@@ -70,6 +81,7 @@
graphics[i].rect.bottom = graphics[i].rect.top + 26;
}
+ varia.close();
hovered_obj = selected_obj = NULL;
}
@@ -105,6 +117,14 @@
}
}
+void Inventory::reload() {
+ for (int i = 0; i < 24; ++i) {
+ graphics[i].free();
+ uint item = inventory[i];
+ if (item != 0)
+ graphics[i].load(this, item);
+ }
+}
void Inventory::add(byte item) {
if (has(item))
@@ -138,20 +158,21 @@
switch (event.type) {
case Common::EVENT_MOUSEMOVE:
- mouse = event.mouse;
- if (!active() && event.mouse.y < 5) {
- activate(true);
- return _active;
+
+ if (!_active) {
+ if (event.mouse.y < 5)
+ activate(true);
+ mouse = event.mouse;
+ return false;
}
- if (event.mouse.x < 17 || event.mouse.x >= 303 || event.mouse.y >= 153) {
+ if (event.mouse.x < 17 || event.mouse.x >= 303 || (event.mouse.y - mouse.y > 0 && event.mouse.y >= 153)) {
activate(false);
- return _active;
+ mouse = event.mouse;
+ return false;
}
- if (!_active)
- return false;
-
+ mouse = event.mouse;
hovered_obj = NULL;
for (int i = 0; i < 24; ++i) {
@@ -238,6 +259,10 @@
activate(false);
return true;
}
+ if (event.kbd.keycode == Common::KEYCODE_RETURN) { //triangle button on psp
+ activate(!_active);
+ return true;
+ }
return false;
case Common::EVENT_LBUTTONUP:
@@ -266,17 +291,31 @@
}
}
-void Inventory::Item::render(Inventory *inventory, InventoryObject *obj, Graphics::Surface *dst, int delta) {
+void Inventory::Item::load(Inventory *inventory, uint item_id) {
+ InventoryObject *obj = &inventory->objects[item_id];
+ if (obj->animated) {
+ if (animation.empty()) {
+ debug(0, "loading item %d from offset %x", obj->id, inventory->offset[obj->id - 1]);
+ Common::MemoryReadStream s(inventory->items + inventory->offset[obj->id - 1], inventory->offset[obj->id] - inventory->offset[obj->id - 1]);
+ animation.load(&s, Animation::kTypeInventory);
+ }
+ } else {
+ if (surface.empty()) {
+ debug(0, "loading item %d from offset %x", obj->id, inventory->offset[obj->id - 1]);
+ Common::MemoryReadStream s(inventory->items + inventory->offset[obj->id - 1], inventory->offset[obj->id] - inventory->offset[obj->id - 1]);
+ surface.load(&s, Surface::kTypeOns);
+ }
+ }
+}
+
+void Inventory::Item::render(Inventory *inventory, uint item_id, Graphics::Surface *dst, int delta) {
+ InventoryObject *obj = &inventory->objects[item_id];
Resources *res = Resources::instance();
backgroundEffect(dst);
rect.render(dst, hovered ? 233 : 234);
+ load(inventory, item_id);
if (obj->animated) {
- if (animation.empty()) {
- debug(0, "loading item %d from offset %x", obj->id, inventory->offset[obj->id - 1]);
- inventory->items->seek(inventory->offset[obj->id - 1]);
- animation.load(inventory->items, Animation::kTypeInventory);
- }
if (hovered) {
Surface *s = animation.currentFrame(delta);
if (animation.currentIndex() == 0)
@@ -289,11 +328,6 @@
s->render(dst, rect.left + 1, rect.top + 1);
}
} else {
- if (surface.empty()) {
- debug(0, "loading item %d from offset %x", obj->id, inventory->offset[obj->id - 1]);
- inventory->items->seek(inventory->offset[obj->id - 1]);
- surface.load(inventory->items, Surface::kTypeOns);
- }
surface.render(dst, rect.left + 1, rect.top + 1);
}
@@ -325,9 +359,7 @@
continue;
//debug(0, "%d,%d -> %u", x0, y0, item);
-
- InventoryObject *obj = &objects[item];
- graphics[idx].render(this, obj, surface, delta);
+ graphics[idx].render(this, item, surface, delta);
}
}
}
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/inventory.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/inventory.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/inventory.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -42,6 +42,7 @@
void render(Graphics::Surface *surface, int delta);
void clear();
+ void reload();
void add(byte item);
bool has(byte item) const;
void remove(byte item);
@@ -57,8 +58,8 @@
private:
TeenAgentEngine *_engine;
Surface background;
- Common::SeekableReadStream *items;
- uint16 offset[93];
+ byte *items;
+ uint offset[93];
Common::Array<InventoryObject> objects;
byte *inventory;
@@ -70,8 +71,9 @@
Item() : hovered(false) {}
void free();
+ void load(Inventory *inventory, uint item_id);
void backgroundEffect(Graphics::Surface *s);
- void render(Inventory *inventory, InventoryObject *obj, Graphics::Surface *surface, int delta);
+ void render(Inventory *inventory, uint item_id, Graphics::Surface *surface, int delta);
} graphics[24];
bool _active;
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/music.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/music.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/music.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -24,7 +24,9 @@
*/
#include "teenagent/music.h"
+#include "teenagent/objects.h"
#include "teenagent/resources.h"
+#include "common/ptr.h"
namespace TeenAgent {
@@ -43,8 +45,8 @@
bool MusicPlayer::load(int id) {
Resources *res = Resources::instance();
- Common::SeekableReadStream *stream = res->mmm.getStream(id);
- if (stream == NULL)
+ ScopedPtr<Common::SeekableReadStream> stream(res->mmm.getStream(id));
+ if (!stream)
return false;
char header[4];
@@ -62,17 +64,15 @@
// Load the sample data
byte sampleResource = ((sample >> 4) & 0x0F) * 10 + (sample & 0x0F);
debug(0, "currSample = %d, sample = 0x%02x, resource: %d", currSample, sample, sampleResource);
- uint32 sampleSize = res->sam_mmm.get_size(sampleResource);
- Common::SeekableReadStream *in = res->sam_mmm.getStream(sampleResource);
-
- if (in == 0) {
+ uint32 sampleSize = res->sam_mmm.getSize(sampleResource);
+ if (sampleSize == 0) {
warning("load: invalid sample %d (0x%02x)", sample, sample);
_samples[sample].clear();
continue;
}
_samples[sample].resize(sampleSize);
- in->read(_samples[sample].data, sampleSize);
+ res->sam_mmm.read(sampleResource, _samples[sample].data, sampleSize);
}
// Load the music data
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/music.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/music.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/music.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -27,6 +27,7 @@
#define TEEN_MUSIC_H
#include "sound/mods/paula.h"
+#include "common/array.h"
namespace TeenAgent {
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/objects.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/objects.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/objects.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -26,6 +26,7 @@
#ifndef TEENAGENT_OBJECTS_H
#define TEENAGENT_OBJECTS_H
+#include "common/noncopyable.h"
#include "common/rect.h"
#include "graphics/surface.h"
@@ -222,6 +223,60 @@
void load(byte *src);
};
+template<typename T>
+class ScopedPtr : Common::NonCopyable {
+public:
+ typedef T ValueType;
+ typedef T *PointerType;
+ typedef T &ReferenceType;
+
+ explicit ScopedPtr(PointerType o = 0) : _pointer(o) {}
+
+ ReferenceType operator*() const { return *_pointer; }
+ PointerType operator->() const { return _pointer; }
+ operator PointerType() const { return _pointer; }
+
+ /**
+ * Implicit conversion operator to bool for convenience, to make
+ * checks like "if (scopedPtr) ..." possible.
+ */
+ operator bool() const { return _pointer != 0; }
+
+ ~ScopedPtr() {
+ delete _pointer;
+ }
+
+ /**
+ * Resets the pointer with the new value. Old object will be destroyed
+ */
+ void reset(PointerType o = 0) {
+ delete _pointer;
+ _pointer = o;
+ }
+
+ /**
+ * Returns the plain pointer value.
+ *
+ * @return the pointer the ScopedPtr manages
+ */
+ PointerType get() const { return _pointer; }
+
+ /**
+ * Returns the plain pointer value and releases ScopedPtr.
+ * After release() call you need to delete object yourself
+ *
+ * @return the pointer the ScopedPtr manages
+ */
+ PointerType release() {
+ PointerType r = _pointer;
+ _pointer = 0;
+ return r;
+ }
+
+private:
+ PointerType _pointer;
+};
+
//\todo move it to util.h?
template<typename T> inline T SIGN (T x) { return (x > 0)? 1: ((x < 0)? -1: 0); }
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/pack.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/pack.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/pack.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -28,60 +28,177 @@
namespace TeenAgent {
-Pack::Pack() : count(0), offsets(0) {}
+FilePack::FilePack() : offsets(0) {}
-Pack::~Pack() {
+FilePack::~FilePack() {
close();
}
-
-void Pack::close() {
+void FilePack::close() {
delete[] offsets;
offsets = NULL;
file.close();
}
+bool FilePack::open(const Common::String &filename) {
+ if (!file.open(filename))
+ return false;
-bool Pack::open(const Common::String &filename) {
+ _fileCount = file.readUint32LE();
+ debug(0, "opened %s, found %u entries", filename.c_str(), _fileCount);
+ offsets = new uint32[_fileCount + 1];
+ for (uint32 i = 0; i <= _fileCount; ++i) {
+ offsets[i] = file.readUint32LE();
+ }
+ return true;
+}
+
+uint32 FilePack::getSize(uint32 id) const {
+ if (id < 1 || id > _fileCount)
+ return 0;
+ return offsets[id] - offsets[id - 1];
+}
+
+uint32 FilePack::read(uint32 id, byte *dst, uint32 size) const {
+ if (id < 1 || id > _fileCount)
+ return 0;
+
+ file.seek(offsets[id - 1]);
+ uint32 rsize = offsets[id] - offsets[id - 1];
+ uint32 r = file.read(dst, MIN(rsize, size));
+ //debug(0, "read(%u, %u) = %u", id, size, r);
+ return r;
+}
+
+Common::SeekableReadStream *FilePack::getStream(uint32 id) const {
+ if (id < 1 || id > _fileCount)
+ return NULL;
+ //debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
+ return new Common::SeekableSubReadStream(&file, offsets[id - 1], offsets[id]);
+}
+
+
+TransientFilePack::TransientFilePack() : offsets(0) {}
+
+TransientFilePack::~TransientFilePack() {
+ close();
+}
+
+void TransientFilePack::close() {
+ delete[] offsets;
+ offsets = NULL;
+ _filename.clear();
+}
+
+bool TransientFilePack::open(const Common::String &filename) {
+ _filename = filename;
+
+ Common::File file;
if (!file.open(filename))
return false;
- count = file.readUint32LE();
- debug(0, "opened %s, found %u entries", filename.c_str(), count);
- offsets = new uint32[count + 1];
- for (uint32 i = 0; i <= count; ++i) {
+ _fileCount = file.readUint32LE();
+ debug(0, "opened %s, found %u entries", filename.c_str(), _fileCount);
+ offsets = new uint32[_fileCount + 1];
+ for (uint32 i = 0; i <= _fileCount; ++i) {
offsets[i] = file.readUint32LE();
- //debug(0, "%d: %06x", i, offsets[i]);
}
- /* for (uint32 i = 0; i < count; ++i) {
- debug(0, "%d: len = %d", i, offsets[i + 1] - offsets[i]);
- }
- */
+ file.close();
return true;
}
-uint32 Pack::get_size(uint32 id) const {
- if (id < 1 || id > count)
+uint32 TransientFilePack::getSize(uint32 id) const {
+ if (id < 1 || id > _fileCount)
return 0;
return offsets[id] - offsets[id - 1];
}
-uint32 Pack::read(uint32 id, byte *dst, uint32 size) const {
- if (id < 1 || id > count)
+uint32 TransientFilePack::read(uint32 id, byte *dst, uint32 size) const {
+ if (id < 1 || id > _fileCount)
return 0;
+ Common::File file;
+ if (!file.open(_filename))
+ return 0;
+
file.seek(offsets[id - 1]);
uint32 rsize = offsets[id] - offsets[id - 1];
uint32 r = file.read(dst, MIN(rsize, size));
+ file.close();
//debug(0, "read(%u, %u) = %u", id, size, r);
return r;
}
-Common::SeekableReadStream *Pack::getStream(uint32 id) const {
- if (id < 1 || id > count)
- return 0;
+Common::SeekableReadStream *TransientFilePack::getStream(uint32 id) const {
+ if (id < 1 || id > _fileCount)
+ return NULL;
//debug(0, "stream: %04x-%04x", offsets[id - 1], offsets[id]);
- return new Common::SeekableSubReadStream(&file, offsets[id - 1], offsets[id], DisposeAfterUse::NO);
+ Common::File file;
+ if (!file.open(_filename))
+ return NULL;
+
+ file.seek(offsets[id - 1]);
+ uint32 size = offsets[id] - offsets[id - 1];
+ byte *ptr = (byte *)malloc(size);
+ if (ptr == NULL)
+ return NULL;
+ uint32 r = file.read(ptr, size);
+ file.close();
+ return new Common::MemoryReadStream(ptr, r, DisposeAfterUse::YES);
}
+
+void MemoryPack::close() {
+ chunks.clear();
+}
+
+bool MemoryPack::open(const Common::String &filename) {
+ Common::File file;
+ if (!file.open(filename))
+ return false;
+
+ uint32 count = file.readUint32LE();
+ debug(0, "opened %s, found %u entries [memory]", filename.c_str(), count);
+ for (uint32 i = 0; i < count; ++i) {
+ uint32 offset = file.readUint32LE();
+ int32 pos = file.pos();
+ uint32 next_offset = file.readUint32LE();
+ uint32 size = next_offset - offset;
+ Chunk chunk;
+ if (size != 0) {
+ file.seek(offset);
+ chunk.data = new byte[size];
+ chunk.size = size;
+ file.read(chunk.data, size);
+ file.seek(pos);
+ }
+ chunks.push_back(chunk);
+ }
+ file.close();
+ return true;
+}
+
+uint32 MemoryPack::getSize(uint32 id) const {
+ --id;
+ return id < chunks.size()? chunks[id].size: 0;
+}
+
+uint32 MemoryPack::read(uint32 id, byte *dst, uint32 size) const {
+ --id;
+ if (id >= chunks.size())
+ return 0;
+ const Chunk &c = chunks[id];
+ memcpy(dst, c.data, c.size);
+ return c.size;
+}
+
+Common::SeekableReadStream *MemoryPack::getStream(uint32 id) const {
+ --id;
+ if (id >= chunks.size())
+ return 0;
+ const Chunk &c = chunks[id];
+ return new Common::MemoryReadStream(c.data, c.size, DisposeAfterUse::NO);
+}
+
+
} // End of namespace TeenAgent
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/pack.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/pack.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/pack.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -27,26 +27,87 @@
#define TEENAGENT_PACK_H
#include "common/file.h"
+#include "common/array.h"
namespace TeenAgent {
+
class Pack {
+protected:
+ uint32 _fileCount;
+public:
+ Pack(): _fileCount(0) {}
+ virtual ~Pack() {};
+ virtual bool open(const Common::String &filename) = 0;
+ virtual void close() = 0;
+
+ virtual uint32 fileCount() const { return _fileCount; }
+ virtual uint32 getSize(uint32 id) const = 0;
+ virtual uint32 read(uint32 id, byte *dst, uint32 size) const = 0;
+ virtual Common::SeekableReadStream *getStream(uint32 id) const = 0;
+};
+
+///FilePack keeps opened file and returns substream for each request.
+class FilePack : public Pack {
mutable Common::File file;
- uint32 count;
uint32 *offsets;
public:
- Pack();
- ~Pack();
+ FilePack();
+ ~FilePack();
- bool open(const Common::String &filename);
- void close();
+ virtual bool open(const Common::String &filename);
+ virtual void close();
- inline uint32 files_count() const { return count; }
- uint32 get_size(uint32 id) const;
- uint32 read(uint32 id, byte *dst, uint32 size) const;
- Common::SeekableReadStream *getStream(uint32 id) const;
+ virtual uint32 getSize(uint32 id) const;
+ virtual uint32 read(uint32 id, byte *dst, uint32 size) const;
+ virtual Common::SeekableReadStream *getStream(uint32 id) const;
};
+/** Pack file which reopens file each request. Do not keep file descriptor open.
+ ** Useful for minimizing file descriptors opened at the same time. Critical for PSP backend.
+ **/
+class TransientFilePack : public Pack {
+ uint32 *offsets;
+ Common::String _filename;
+
+public:
+ TransientFilePack();
+ ~TransientFilePack();
+
+ virtual bool open(const Common::String &filename);
+ virtual void close();
+
+ virtual uint32 getSize(uint32 id) const;
+ virtual uint32 read(uint32 id, byte *dst, uint32 size) const;
+ virtual Common::SeekableReadStream *getStream(uint32 id) const;
+};
+
+///MemoryPack loads whole pack in memory, currently unused.
+class MemoryPack : public Pack {
+ struct Chunk {
+ byte *data;
+ uint32 size;
+ inline Chunk(): data(0), size(0) {}
+ inline Chunk(const Chunk &c): data(c.data), size(c.size) { c.reset(); }
+ inline Chunk& operator=(const Chunk &c) { data = c.data; size = c.size; c.reset(); return *this; }
+ inline ~Chunk() { delete[] data; }
+ inline void reset() const {
+ Chunk *c = const_cast<Chunk *>(this);
+ c->data = 0;
+ c->size = 0;
+ }
+ };
+ Common::Array<Chunk> chunks;
+
+public:
+ virtual bool open(const Common::String &filename);
+ virtual void close();
+
+ virtual uint32 getSize(uint32 id) const;
+ virtual uint32 read(uint32 id, byte *dst, uint32 size) const;
+ virtual Common::SeekableReadStream *getStream(uint32 id) const;
+};
+
} // End of namespace TeenAgent
#endif
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/resources.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/resources.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/resources.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -36,7 +36,6 @@
}
void Resources::deinit() {
- varia.close();
off.close();
on.close();
ons.close();
@@ -77,8 +76,18 @@
dat_file.close();
+ {
+ FilePack varia;
+ varia.open("varia.res");
+ font7.load(varia, 7);
+ font7.width_pack = 1;
+ font7.height = 11;
+ font8.load(varia, 8);
+ font8.height = 31;
+ varia.close();
+ }
+
off.open("off.res");
- varia.open("varia.res");
on.open("on.res");
ons.open("ons.res");
lan000.open("lan_000.res");
@@ -87,17 +96,12 @@
sam_mmm.open("sam_mmm.res");
sam_sam.open("sam_sam.res");
- font7.load(7);
- font7.width_pack = 1;
- font7.height = 11;
- font8.load(8);
- font8.height = 31;
return true;
}
void Resources::loadOff(Graphics::Surface &surface, byte *palette, int id) {
- uint32 size = off.get_size(id);
+ uint32 size = off.getSize(id);
if (size == 0) {
error("invalid background %d", id);
return;
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/resources.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/resources.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/resources.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -47,7 +47,18 @@
//void loadOn(Graphics::Surface &surface, int id, uint16 &dst, uint16 *flags);
//void loadOns(Graphics::Surface &surface, int id, uint16 &dst);
- Pack varia, off, on, ons, lan000, lan500, mmm, sam_mmm, sam_sam;
+ /*
+ * 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.
+ */
+#ifdef __PSP__
+ TransientFilePack off, on, ons, lan000, lan500, sam_mmm, sam_sam, mmm;
+#else
+ FilePack off, on, ons, lan000, lan500, sam_mmm, sam_sam, mmm;
+#endif
+
Segment cseg, dseg, eseg;
Font font7, font8;
};
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/scene.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/scene.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/scene.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -204,26 +204,30 @@
_system = system;
_fade_timer = 0;
+ on_enabled = true;
memset(palette, 0, sizeof(palette));
- Resources *res = Resources::instance();
- Common::SeekableReadStream *s = res->varia.getStream(1);
- if (s == NULL)
+ FilePack varia;
+ varia.open("varia.res");
+
+ ScopedPtr<Common::SeekableReadStream> s(varia.getStream(1));
+ if (!s)
error("invalid resource data");
teenagent.load(s, Animation::kTypeVaria);
if (teenagent.empty())
error("invalid mark animation");
- s = res->varia.getStream(2);
- if (s == NULL)
+ s.reset(varia.getStream(2));
+ if (!s)
error("invalid resource data");
teenagent_idle.load(s, Animation::kTypeVaria);
if (teenagent_idle.empty())
error("invalid mark animation");
+ varia.close();
loadObjectData();
}
@@ -331,9 +335,10 @@
if (ons_count > 0) {
ons = new Surface[ons_count];
for (uint32 i = 0; i < ons_count; ++i) {
- Common::SeekableReadStream *s = res->ons.getStream(on_id[i]);
- if (s != NULL)
+ ScopedPtr<Common::SeekableReadStream> s(res->ons.getStream(on_id[i]));
+ if (s) {
ons[i].load(s, Surface::kTypeOns);
+ }
}
}
}
@@ -353,22 +358,19 @@
if (bxv == 0)
continue;
- Common::SeekableReadStream *s = res->loadLan000(res_id);
- if (s != NULL) {
+ ScopedPtr<Common::SeekableReadStream> s(res->loadLan000(res_id));
+ if (s) {
animation[i].load(s, Animation::kTypeLan);
if (bxv != 0 && bxv != 0xff)
animation[i].id = bxv;
- delete s;
}
-
- //uint16 bp = res->dseg.get_word();
}
-
}
void Scene::init(int id, const Common::Point &pos) {
debug(0, "init(%d)", id);
_id = id;
+ on_enabled = true; //reset on-rendering flag on loading.
sounds.clear();
for (byte i = 0; i < 4; ++i)
custom_animation[i].free();
@@ -394,7 +396,7 @@
}
}
- Common::SeekableReadStream *stream = res->on.getStream(id);
+ ScopedPtr<Common::SeekableReadStream> stream(res->on.getStream(id));
int sub_hack = 0;
if (id == 7) { //something patched in the captains room
switch(res->dseg.get_byte(0xdbe6)) {
@@ -408,7 +410,6 @@
}
}
on.load(stream, SurfaceList::kTypeOn, sub_hack);
- delete stream;
loadOns();
loadLans();
@@ -426,8 +427,8 @@
void Scene::playAnimation(byte idx, uint id, bool loop, bool paused, bool ignore) {
debug(0, "playAnimation(%u, %u, loop:%s, paused:%s, ignore:%s)", idx, id, loop?"true":"false", paused?"true":"false", ignore?"true":"false");
assert(idx < 4);
- Common::SeekableReadStream *s = Resources::instance()->loadLan(id + 1);
- if (s == NULL)
+ ScopedPtr<Common::SeekableReadStream> s(Resources::instance()->loadLan(id + 1));
+ if (!s)
error("playing animation %u failed", id);
custom_animation[idx].load(s);
@@ -438,13 +439,14 @@
void Scene::playActorAnimation(uint id, bool loop, bool ignore) {
debug(0, "playActorAnimation(%u, loop:%s, ignore:%s)", id, loop?"true":"false", ignore?"true":"false");
- Common::SeekableReadStream *s = Resources::instance()->loadLan(id + 1);
- if (s == NULL)
+ ScopedPtr<Common::SeekableReadStream> s(Resources::instance()->loadLan(id + 1));
+ if (!s)
error("playing animation %u failed", id);
actor_animation.load(s);
actor_animation.loop = loop;
actor_animation.ignore = ignore;
+ actor_animation.id = id;
}
Animation * Scene::getAnimation(byte slot) {
@@ -467,7 +469,7 @@
//event.dump();
if (event.type == SceneEvent::kWalk && !events.empty()) {
SceneEvent &prev = events.back();
- if (prev.type == SceneEvent::kWalk) {
+ if (prev.type == SceneEvent::kWalk && prev.color == event.color) {
debug(0, "fixing double-move [skipping event!]");
if ((event.color & 2) != 0) { //relative move
prev.dst.x += event.dst.x;
@@ -810,7 +812,8 @@
}
//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 (debug_features.feature[DebugFeatures::kShowOn]) {
+ if (on_enabled &&
+ debug_features.feature[DebugFeatures::kShowOn]) {
on.render(surface, actor_animation_position);
}
@@ -916,9 +919,16 @@
switch (current_event.type) {
case SceneEvent::kSetOn: {
- byte *ptr = getOns(current_event.scene == 0 ? _id : current_event.scene);
- debug(0, "on[%u] = %02x", current_event.ons - 1, current_event.color);
- ptr[current_event.ons - 1] = current_event.color;
+ byte on_id = current_event.ons;
+ if (on_id != 0) {
+ --on_id;
+ byte *ptr = getOns(current_event.scene == 0 ? _id : current_event.scene);
+ debug(0, "on[%u] = %02x", on_id, current_event.color);
+ ptr[on_id] = current_event.color;
+ } else {
+ on_enabled = current_event.color != 0;
+ debug(0, "%s on rendering", on_enabled? "enabling": "disabling");
+ }
loadOns();
current_event.clear();
}
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/scene.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/scene.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/scene.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -27,12 +27,14 @@
#include "teenagent/surface.h"
#include "teenagent/actor.h"
-#include "common/system.h"
-#include "common/list.h"
#include "teenagent/objects.h"
#include "teenagent/surface.h"
#include "teenagent/surface_list.h"
+#include "common/system.h"
+#include "common/array.h"
+#include "common/list.h"
+
namespace TeenAgent {
class TeenAgentEngine;
@@ -190,6 +192,7 @@
int _id;
Graphics::Surface background;
SurfaceList on;
+ bool on_enabled;
Surface *ons;
uint32 ons_count;
Animation actor_animation, animation[4], custom_animation[4];
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.cpp 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.cpp 2010-03-23 21:23:56 UTC (rev 48372)
@@ -190,11 +190,12 @@
Common::Error TeenAgentEngine::loadGameState(int slot) {
debug(0, "loading from slot %d", slot);
- Common::InSaveFile *in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot));
- if (in == NULL)
- in = _saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot));
+ ScopedPtr<Common::InSaveFile>
+ in(_saveFileMan->openForLoading(Common::String::printf("teenagent.%02d", slot)));
+ if (!in)
+ in.reset(_saveFileMan->openForLoading(Common::String::printf("teenagent.%d", slot)));
- if (in == NULL)
+ if (!in)
return Common::kReadPermissionDenied;
Resources *res = Resources::instance();
@@ -203,16 +204,14 @@
char data[0x777a];
in->seek(0);
if (in->read(data, 0x777a) != 0x777a) {
- delete in;
return Common::kReadingFailed;
}
- delete in;
-
memcpy(res->dseg.ptr(0x6478), data, sizeof(data));
scene->clear();
inventory->activate(false);
+ inventory->reload();
setMusic(Resources::instance()->dseg.get_byte(0xDB90));
@@ -227,9 +226,9 @@
Common::Error TeenAgentEngine::saveGameState(int slot, const char *desc) {
debug(0, "saving to slot %d", slot);
- Common::OutSaveFile *out = _saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot));
- if (out == NULL)
- return Common::kWritePermissionDenied;
+ ScopedPtr<Common::OutSaveFile> out(_saveFileMan->openForSaving(Common::String::printf("teenagent.%02d", slot)));
+ if (!out)
+ return Common::kWritingFailed;
Resources *res = Resources::instance();
res->dseg.set_byte(0xB4F3, scene->getId());
@@ -242,8 +241,8 @@
out->write(res->dseg.ptr(0x6478), 0x777a);
if (!Graphics::saveThumbnail(*out))
warning("saveThumbnail failed");
- delete out;
+ out->finalize();
return Common::kNoError;
}
@@ -270,15 +269,15 @@
}
bool TeenAgentEngine::showLogo() {
- Pack logo;
+ FilePack logo;
if (!logo.open("unlogic.res"))
return true;
byte bg[0xfa00];
byte palette[0x400];
- Common::SeekableReadStream *frame = logo.getStream(1);
- if (frame == NULL)
+ ScopedPtr<Common::SeekableReadStream> frame(logo.getStream(1));
+ if (!frame)
return true;
frame->read(bg, sizeof(bg));
@@ -293,7 +292,7 @@
}
_system->setPalette(palette, 0, 0x100);
- uint n = logo.files_count();
+ uint n = logo.fileCount();
for(uint f = 0; f < 4; ++f)
for(uint i = 2; i <= n; ++i) {
{
@@ -303,13 +302,12 @@
}
_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
- frame = logo.getStream(i);
- if (frame == NULL)
+ frame.reset(logo.getStream(i));
+ if (!frame)
return true;
Surface s;
s.load(frame, Surface::kTypeOns);
- delete frame;
if (s.empty())
return true;
@@ -325,26 +323,26 @@
_system->fillScreen(0);
_system->updateScreen();
- Resources *res = Resources::instance();
+ FilePack varia;
+ varia.open("varia.res");
byte palette[0x400];
memset(palette, 0, sizeof(palette));
{
- Common::SeekableReadStream *s = res->varia.getStream(5);
- for(uint c = 0; c < 0x100; ++c) {
- uint idx = c * 4;
- s->read(palette + idx, 3);
- palette[idx] *= 4;
- palette[idx + 1] *= 4;
- palette[idx + 2] *= 4;
+ ScopedPtr<Common::SeekableReadStream> s(varia.getStream(5));
+ for(uint c = 0; c < 0x400; c += 4) {
+ s->read(palette + c, 3);
+ palette[c] *= 4;
+ palette[c + 1] *= 4;
+ palette[c + 2] *= 4;
}
}
_system->setPalette(palette, 0, 0x100);
byte varia_6[21760], varia_9[18302];
- res->varia.read(6, varia_6, sizeof(varia_6));
- res->varia.read(9, varia_9, sizeof(varia_9));
+ varia.read(6, varia_6, sizeof(varia_6));
+ varia.read(9, varia_9, sizeof(varia_9));
byte colors[56 * 160 * 2];
memset(colors, 0, sizeof(colors));
@@ -779,6 +777,13 @@
fadeIn();
}
+void TeenAgentEngine::enableOn(bool enable) {
+ SceneEvent event(SceneEvent::kSetOn);
+ event.ons = 0;
+ event.color = enable? 1: 0;
+ scene->push(event);
+}
+
void TeenAgentEngine::setOns(byte id, byte value, byte scene_id) {
SceneEvent event(SceneEvent::kSetOn);
event.ons = id + 1;
@@ -905,19 +910,18 @@
void TeenAgentEngine::playSoundNow(byte id) {
Resources *res = Resources::instance();
- Common::SeekableReadStream *in = res->sam_sam.getStream(id);
- if (in == NULL) {
+ uint size = res->sam_sam.getSize(id);
+ if (size == 0) {
warning("skipping invalid sound %u", id);
return;
}
- uint size = in->size();
byte *data = (byte *)malloc(size);
- in->read(data, size);
+ res->sam_sam.read(id, data, size);
//debug(0, "playing %u samples...", size);
Audio::AudioStream *stream = Audio::makeRawStream(data, size, 11025, 0);
- _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream);
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_soundHandle, stream); //dispose is YES by default
}
@@ -932,9 +936,9 @@
bool TeenAgentEngine::hasFeature(EngineFeature f) const {
switch (f) {
case kSupportsRTL:
+ case kSupportsSubtitleOptions:
case kSupportsLoadingDuringRuntime:
case kSupportsSavingDuringRuntime:
- case kSupportsSubtitleOptions:
return true;
default:
return false;
Modified: scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.h 2010-03-23 20:58:40 UTC (rev 48371)
+++ scummvm/branches/branch-1-1-0/engines/teenagent/teenagent.h 2010-03-23 21:23:56 UTC (rev 48372)
@@ -93,6 +93,7 @@
void playAnimation(uint16 id, byte slot, bool async = false, bool ignore = false, bool loop = false);
void loadScene(byte id, const Common::Point &pos, byte o = 0);
void loadScene(byte id, uint16 x, uint16 y, byte o = 0);
+ void enableOn(bool enable = true);
void setOns(byte id, byte value, byte scene_id = 0);
void setLan(byte id, byte value, byte scene_id = 0);
void setFlag(uint16 addr, byte value);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list