BLADERUNNER: fixed loading of new set/scene, fixed memoryleak in lights

This commit is contained in:
Peter Kohaut 2016-09-29 21:00:36 +02:00 committed by Eugene Sandulenko
parent f5d5f3302f
commit af70a90cbc
10 changed files with 83 additions and 39 deletions

View File

@ -95,7 +95,8 @@ int AudStream::readBuffer(int16 *buffer, const int numSamples) {
samplesRead += 2 * bytesConsumed;
}
} else {
assert(0 && "readBuffer: Unimplemented");
//assert(0 && "readBuffer: Unimplemented");
warning("AudStream::readBuffer unknown compression type %d", _compressionType);
}
return samplesRead;

View File

@ -613,7 +613,7 @@ void BladeRunnerEngine::gameTick() {
_walkSoundId = -1;
}
#if 0 //_DEBUG
#if _DEBUG
//draw scene objects
int count = _sceneObjects->_count;
if (count > 0) {
@ -667,6 +667,19 @@ void BladeRunnerEngine::gameTick() {
}
}
for (int i = 0; i < (int)_lights->_lights.size(); i++) {
Light *light = _lights->_lights[i];
Matrix4x3 m = light->_matrix;
Vector3 pos = Vector3(m(0, 3), m(1, 3), m(2, 3));
Vector3 size = Vector3(5.0f, 5.0f, 5.0f);
int colorR = (light->_color.r * 31.0f);
int colorG = (light->_color.g * 31.0f);
int colorB = (light->_color.b * 31.0f);
int color = (colorR << 10) + (colorG << 5) + colorB;
drawBBox(pos-size, pos+size, _view, &_surface2, color);
}
#endif
_system->copyRectToScreen((const byte *)_surface2.getBasePtr(0, 0), _surface2.pitch, 0, 0, 640, 480);

View File

@ -32,14 +32,14 @@ namespace BladeRunner {
GameInfo::GameInfo(BladeRunnerEngine *vm)
: _vm(vm)
{
_set_names = nullptr;
_scene_names = nullptr;
_sfx_tracks = nullptr;
_music_tracks = nullptr;
_outtakes = nullptr;
}
GameInfo::~GameInfo() {
delete[] _set_names;
delete[] _scene_names;
delete[] _sfx_tracks;
delete[] _music_tracks;
delete[] _outtakes;
@ -73,9 +73,9 @@ bool GameInfo::open(const Common::String &name) {
(void)unk;
_set_names = new char[_set_names_count][5];
_scene_names = new char[_set_names_count][5];
for (uint32 i = 0; i != _set_names_count; ++i)
s->read(_set_names[i], 5);
s->read(_scene_names[i], 5);
_sfx_tracks = new char[_sfx_track_count][13];
for (uint32 i = 0; i != _sfx_track_count; ++i)
@ -97,7 +97,7 @@ bool GameInfo::open(const Common::String &name) {
if (false) {
for (uint32 i = 0; i != _set_names_count; ++i)
debug("%3d: %s", i, _set_names[i]);
debug("%3d: %s", i, _scene_names[i]);
for (uint32 i = 0; i != _sfx_track_count; ++i)
debug("%3d: %s", i, _sfx_tracks[i]);
for (uint32 i = 0; i != _music_track_count; ++i)

View File

@ -49,7 +49,7 @@ class GameInfo {
uint32 _cover_waypoint_count;
uint32 _flee_waypoint_count;
char (*_set_names)[5];
char (*_scene_names)[5];
char (*_sfx_tracks)[13];
char (*_music_tracks)[13];
char (*_outtakes)[13];
@ -75,7 +75,7 @@ public:
uint32 getCoverWaypointCount() { return _cover_waypoint_count; }
uint32 getFleeWaypointCount() { return _flee_waypoint_count; }
const char *getSetName(int i) { return _set_names[i]; }
const char *getSceneName(int i) { return _scene_names[i]; }
const char *getSfxTrack(int i) { return _sfx_tracks[i]; }
const char *getMusicTrack(int i) { return _music_tracks[i]; }
const char *getOuttake(int i) { return _outtakes[i]; }

View File

@ -9,7 +9,6 @@ Lights::Lights(BladeRunnerEngine *vm) {
_ambientLightColor.g = 0.0;
_ambientLightColor.b = 0.0;
_lightsCount = 0;
_lights.clear();
_frame = 0;
}
@ -23,9 +22,8 @@ void Lights::read(Common::ReadStream *stream, int framesCount) {
_ambientLightColor.g = stream->readFloatLE();
_ambientLightColor.b = stream->readFloatLE();
_lightsCount = stream->readUint32LE();
int i;
for (i = 0; i < _lightsCount; i++) {
uint _lightsCount = stream->readUint32LE();
for (uint i = 0; i < _lightsCount; i++) {
Light *light;
int type = stream->readUint32LE();
switch (type) {
@ -54,7 +52,7 @@ void Lights::read(Common::ReadStream *stream, int framesCount) {
}
void Lights::removeAnimated() {
for (int i = (int)(_lights.size() - 1); i > 0; i--) {
for (int i = (int)(_lights.size() - 1); i >= 0; i--) {
if (_lights[i]->_animated) {
delete _lights.remove_at(i);
}
@ -106,7 +104,7 @@ void Lights::setupFrame(int frame) {
}
void Lights::reset() {
for (int i = (int)(_lights.size() - 1); i > 0; i--) {
for (int i = (int)(_lights.size() - 1); i >= 0; i--) {
delete _lights.remove_at(i);
}
_lights.clear();

View File

@ -39,12 +39,9 @@ class Lights {
BladeRunnerEngine *_vm;
Color _ambientLightColor;
int _lightsCount;
Color _ambientLightColor;
Common::Array<Light*> _lights;
int _frame;
int _frame;
//char gap[28];
public:

View File

@ -32,7 +32,6 @@
#include "bladerunner/slice_renderer.h"
#include "common/str.h"
#include "common/stream.h"
namespace BladeRunner {
@ -44,7 +43,7 @@ bool Scene::open(int setId, int sceneId, bool isLoadingGame) {
_setId = setId;
_sceneId = sceneId;
const Common::String setName = _vm->_gameInfo->getSetName(_sceneId);
const Common::String setName = _vm->_gameInfo->getSceneName(_sceneId);
if (isLoadingGame) {
// TODO: Set up overlays
@ -70,10 +69,15 @@ bool Scene::open(int setId, int sceneId, bool isLoadingGame) {
vqaName = Common::String::format("%s_%d.VQA", setName.c_str(), MIN(currentResourceId, 3));
}
if (!_vqaPlayer.open(vqaName))
if (_vqaPlayer != nullptr)
delete _vqaPlayer;
_vqaPlayer = new VQAPlayer(_vm);
if (!_vqaPlayer->open(vqaName))
return false;
Common::String sceneName = _vm->_gameInfo->getSetName(sceneId);
Common::String sceneName = _vm->_gameInfo->getSceneName(sceneId);
if (!_vm->_script->open(sceneName))
return false;
@ -124,20 +128,44 @@ bool Scene::open(int setId, int sceneId, bool isLoadingGame) {
// TODO: add all items to scene
// TODO: calculate walking obstacles??
// if (_playerWalkedIn) { // TODO: Not _playerWalkedIn
// _vm->_script->PlayerWalkedIn();
// }
if (_specialLoopMode) {
_vm->_script->PlayerWalkedIn();
}
return true;
}
bool Scene::close(bool isLoadingGame) {
bool result = true;
if (getSetId() == -1) {
return true;
}
//_vm->_policeMaze->clear(!isLoadingGame);
if (isLoadingGame) {
_vm->_script->PlayerWalkedOut();
}
// if (SceneScript_isLoaded() && !SceneScript_unload()) {
// result = false;
// }
if (_vqaPlayer != nullptr) {
//_vqaPlayer->stop();
delete _vqaPlayer;
_vqaPlayer = nullptr;
}
_sceneId = -1;
_setId = -1;
return result;
}
int Scene::advanceFrame(Graphics::Surface &surface, uint16 *&zBuffer) {
int frame = _vqaPlayer.update();
int frame = _vqaPlayer->update();
if (frame >= 0) {
surface.copyFrom(*_vqaPlayer.getSurface());
memcpy(zBuffer, _vqaPlayer.getZBuffer(), 640*480*2);
_vqaPlayer.updateView(_vm->_view);
_vqaPlayer.updateLights(_vm->_lights);
surface.copyFrom(*_vqaPlayer->getSurface());
memcpy(zBuffer, _vqaPlayer->getZBuffer(), 640*480*2);
_vqaPlayer->updateView(_vm->_view);
_vqaPlayer->updateLights(_vm->_lights);
}
if (frame < 0) {
@ -145,12 +173,12 @@ int Scene::advanceFrame(Graphics::Surface &surface, uint16 *&zBuffer) {
}
_frame = frame;
if (_specialLoopMode == 0 && frame == _vqaPlayer.getLoopEndFrame(_specialLoop)) {
if (_specialLoopMode == 0 && frame == _vqaPlayer->getLoopEndFrame(_specialLoop)) {
_playerWalkedIn = true;
_specialLoopMode = -1;
}
if (_specialLoopMode == 0 && !_defaultLoopSet) {
_vqaPlayer.setLoop(_defaultLoop + 1);
_vqaPlayer->setLoop(_defaultLoop + 1);
_defaultLoopSet = true;
}

View File

@ -41,7 +41,7 @@ public:
Set *_set;
int _setId;
int _sceneId;
VQAPlayer _vqaPlayer;
VQAPlayer *_vqaPlayer;
int _defaultLoop;
int _defaultLoopSet;
@ -69,7 +69,7 @@ public:
_set(new Set(vm)),
_setId(-1),
_sceneId(-1),
_vqaPlayer(vm),
_vqaPlayer(nullptr),
_defaultLoop(0),
_nextSetId(-1),
_nextSceneId(-1),
@ -83,9 +83,13 @@ public:
delete _set;
delete _regions;
delete _exits;
if (_vqaPlayer != nullptr) {
delete _vqaPlayer;
}
}
bool open(int setId, int sceneId, bool isLoadingGame);
bool close(bool isLoadingGame);
int advanceFrame(Graphics::Surface &surface, uint16 *&zBuffer);
void setActorStart(Vector3 position, int facing);

View File

@ -57,6 +57,9 @@ bool Settings::openNewScene() {
if (_startingGame) {
// Stop ambient audio and music
// ambient::removeAllNonLoopingSounds(Ambient, 1);
// ambient::removeAllLoopingSounds(Ambient, 1);
// music::stop(Music, 2);
}
int currentSet = _vm->_scene->_setId;
@ -65,7 +68,9 @@ bool Settings::openNewScene() {
_newSet = -1;
_newScene = -1;
if (currentSet != -1) {
_vm->_scene->close(!_loadingGame && !_startingGame);
}
if (_chapterChanged) {
if (_vm->_chapters->hasOpenResources())
_vm->_chapters->closeResources();

View File

@ -65,7 +65,6 @@ int VQAPlayer::update() {
queueAudioFrame(_decoder.decodeAudioFrame());
_surface = _decoder.decodeVideoFrame();
_zBuffer = _decoder.decodeZBuffer();
//_view = _decoder.getView();
}
_decodedFrame = calcNextFrame(_curFrame);
@ -89,7 +88,6 @@ int VQAPlayer::update() {
if (_curFrame >= 0) {
_surface = _decoder.decodeVideoFrame();
_zBuffer = _decoder.decodeZBuffer();
//_view = _decoder.getView();
}
_decodedFrame = calcNextFrame(_curFrame);