EMI: Add half-complete setb-loading to scene

This commit is contained in:
Einar Johan T. Sømåen 2011-05-09 04:43:06 +08:00 committed by Pawel Kolodziejski
parent dcbf9ac582
commit 840db801e9
2 changed files with 110 additions and 17 deletions
engines/grim

@ -25,6 +25,8 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_printf
#include "common/memstream.h"
#include "engines/grim/scene.h"
#include "engines/grim/textsplit.h"
#include "engines/grim/colormap.h"
@ -40,11 +42,41 @@ int Scene::s_id = 0;
Scene::Scene(const char *sceneName, const char *buf, int len) :
_locked(false), _name(sceneName), _enableLights(false) {
TextSplitter ts(buf, len);
char tempBuf[256];
++s_id;
_id = s_id;
if (len >= 7 && memcmp(buf, "section", 7) == 0) {
TextSplitter ts(buf, len);
loadText(ts);
} else {
Common::MemoryReadStream ms((const byte *)buf, len);
loadBinary(&ms);
}
}
Scene::Scene() :
_cmaps(NULL) {
}
Scene::~Scene() {
if (_cmaps) {
delete[] _cmaps;
delete[] _setups;
delete[] _lights;
for (int i = 0; i < _numSectors; ++i) {
delete _sectors[i];
}
delete[] _sectors;
for (StateList::iterator i = _states.begin(); i != _states.end(); ++i)
delete (*i);
}
}
void Scene::loadText(TextSplitter &ts){
char tempBuf[256];
ts.expectString("section: colormaps");
ts.scanString(" numcolormaps %d", 1, &_numCmaps);
_cmaps = new CMapPtr[_numCmaps];
@ -109,30 +141,52 @@ Scene::Scene(const char *sceneName, const char *buf, int len) :
_sectors = new Sector*[_numSectors];
ts.setLineNumber(sectorStart);
for (int i = 0; i < _numSectors; i++) {
_sectors[i] = new Sector();
_sectors[i] = new Sector();
_sectors[i]->load(ts);
}
}
Scene::Scene() :
_cmaps(NULL) {
void Scene::loadBinary(Common::MemoryReadStream *ms)
{
// yes, an array of size 0
_cmaps = new CMapPtr[0];
}
Scene::~Scene() {
if (_cmaps) {
delete[] _cmaps;
delete[] _setups;
delete[] _lights;
for (int i = 0; i < _numSectors; ++i) {
delete _sectors[i];
}
delete[] _sectors;
for (StateList::iterator i = _states.begin(); i != _states.end(); ++i)
delete (*i);
_numSetups = ms->readUint32LE();
_setups = new Setup[_numSetups];
for (int i = 0; i < _numSetups; i++)
_setups[i].loadBinary(ms);
_setups = new Setup[1];
_currSetup = _setups;
_numSectors = 0;
_numLights = 0;
_lights = NULL;
_sectors = NULL;
_minVolume = 0;
_maxVolume = 0;
// the rest may or may not be optional. Might be a good idea to check if there is no more data.
_numLights = ms->readUint32LE();
_lights = new Light[_numLights];
for (int i = 0; i < _numLights; i++)
_lights[i].loadBinary(ms);
// bypass light stuff for now
_numLights = 0;
_numSectors = ms->readUint32LE();
// Allocate and fill an array of sector info
_sectors = new Sector*[_numSectors];
for (int i = 0; i < _numSectors; i++) {
_sectors[i] = new Sector();
_sectors[i]->loadBinary(ms);
}
}
void Scene::saveState(SaveGame *savedState) const {
savedState->writeString(_name);
savedState->writeLESint32(_numCmaps);
@ -330,6 +384,32 @@ void Scene::Setup::load(TextSplitter &ts) {
}
}
void Scene::Setup::loadBinary(Common::MemoryReadStream *ms) {
char name[128];
ms->read(name, 128);
_name = Common::String(name);
// Skip an unknown number (this is the stringlength of the following string)
int fNameLen = 0;
fNameLen = ms->readUint32LE();
char* fileName = new char[fNameLen];
ms->read(fileName,fNameLen);
_bkgndBm = g_resourceloader->getBitmap(fileName);
ms->read(_pos._coords, 12);
ms->read(_interest._coords, 12);
ms->read(&_roll, 4);
ms->read(&_fov, 4);
ms->read(&_nclip, 4);
ms->read(&_fclip, 4);
}
void Scene::Light::load(TextSplitter &ts) {
char buf[256];
@ -358,6 +438,11 @@ void Scene::Light::load(TextSplitter &ts) {
_color.getBlue() = b;
}
void Scene::Light::loadBinary(Common::MemoryReadStream *ms) {
// skip lights for now
ms->seek(100, SEEK_CUR);
}
void Scene::Setup::setupCamera() const {
// Ignore nclip_ and fclip_ for now. This fixes:
// (a) Nothing was being displayed in the Land of the Living

@ -30,6 +30,9 @@
#include "engines/grim/walkplane.h"
#include "engines/grim/objectstate.h"
namespace Common {
class MemoryReadStream;
}
namespace Grim {
class SaveGame;
@ -40,6 +43,9 @@ public:
Scene();
~Scene();
void loadText(TextSplitter &ts);
void loadBinary(Common::MemoryReadStream *ms);
void saveState(SaveGame *savedState) const;
bool restoreState(SaveGame *savedState);
@ -100,6 +106,7 @@ public:
struct Setup { // Camera setup data
void load(TextSplitter &ts);
void loadBinary(Common::MemoryReadStream *ms);
void setupCamera() const;
Common::String _name;
BitmapPtr _bkgndBm, _bkgndZBm;
@ -109,6 +116,7 @@ public:
struct Light { // Scene lighting data
void load(TextSplitter &ts);
void loadBinary(Common::MemoryReadStream *ms);
Common::String _name;
Common::String _type;
Graphics::Vector3d _pos, _dir;