Skip to content

Commit

Permalink
BLADERUNNER: First pass at slice animation renderer
Browse files Browse the repository at this point in the history
Z-buffers are not being read from the VQA background yet, so z-buffer
handling is faked for now.
  • Loading branch information
madmoose authored and sev- committed Sep 29, 2016
1 parent d945305 commit 4b181e4
Show file tree
Hide file tree
Showing 7 changed files with 836 additions and 7 deletions.
32 changes: 31 additions & 1 deletion engines/bladerunner/bladerunner.cpp
Expand Up @@ -29,6 +29,8 @@
#include "bladerunner/scene.h"
#include "bladerunner/script/script.h"
#include "bladerunner/settings.h"
#include "bladerunner/slice_animations.h"
#include "bladerunner/slice_renderer.h"
#include "bladerunner/vqa_decoder.h"

#include "common/error.h"
Expand All @@ -50,16 +52,21 @@ BladeRunnerEngine::BladeRunnerEngine(OSystem *syst) : Engine(syst) {
_scene = new Scene(this);
_script = new Script(this);
_settings = new Settings(this);
_sliceAnimations = new SliceAnimations(this);
_sliceRenderer = new SliceRenderer(this);
}

BladeRunnerEngine::~BladeRunnerEngine() {
delete _sliceRenderer;
delete _sliceAnimations;
delete _settings;
delete _script;
delete _scene;
delete _gameInfo;
delete _chapters;

_surface1.free();
_surface2.free();
}

bool BladeRunnerEngine::hasFeature(EngineFeature f) const {
Expand Down Expand Up @@ -120,6 +127,18 @@ bool BladeRunnerEngine::startup() {
if (!r)
return false;

r = _sliceAnimations->open("INDEX.DAT");
if (!r)
return false;

r = _sliceAnimations->openCoreAnim();
if (!r)
return false;

r = _sliceAnimations->openHDFrames();
if (!r)
return false;

initChapterAndScene();

return true;
Expand Down Expand Up @@ -201,21 +220,32 @@ void BladeRunnerEngine::gameTick() {
_script->SceneFrameAdvanced(frame);
backgroundChanged = true;
}
_surface2.copyFrom(_surface1);

// TODO: Render overlays (mostly in Replicant)
// TODO: Tick Actor AI and Timers (timers in Replicant)

if (_settings->getNewScene() == -1 || _script->_inScriptCounter /* || in_ai */) {

// TODO: Tick and draw all actors in current set (drawing works in Replicant)

// Hardcode McCoy in place to test the slice renderer
Vector3 pos(-151.98f, -0.30f, 318.15f);
Vector3 draw_pos(pos.x, -pos.z, pos.y + 2);
float facing = -1.570796f;

_sliceRenderer->setView(_scene->_view);
_sliceRenderer->setupFrame(19, 1, draw_pos, facing);
_sliceRenderer->drawFrame(_surface2);

// TODO: Draw items (drawing works in Replicant)
// TODO: Draw item pickup (understood, drawing works in Replicant)
// TODO: Draw dialogue menu
// TODO: Draw mouse (understood)
// TODO: Process AUD (audio in Replicant)
// TODO: Footstep sound

_system->copyRectToScreen((const byte *) _surface1.getBasePtr(0, 0), _surface1.pitch, 0, 0, 640, 480);
_system->copyRectToScreen((const byte *)_surface2.getBasePtr(0, 0), _surface2.pitch, 0, 0, 640, 480);
_system->updateScreen();
_system->delayMillis(10);
}
Expand Down
17 changes: 11 additions & 6 deletions engines/bladerunner/bladerunner.h
Expand Up @@ -36,25 +36,30 @@
namespace BladeRunner {

class Chapters;
class GameInfo;
class Scene;
class Script;
class Settings;
class GameInfo;
class SliceAnimations;
class SliceRenderer;

class BladeRunnerEngine : public Engine {
public:
bool _gameIsRunning;
bool _windowIsActive;

Chapters *_chapters;
GameInfo *_gameInfo;
Scene *_scene;
Script *_script;
Settings *_settings;
Chapters *_chapters;
GameInfo *_gameInfo;
Scene *_scene;
Script *_script;
Settings *_settings;
SliceAnimations *_sliceAnimations;
SliceRenderer *_sliceRenderer;

int in_script_counter;

Graphics::Surface _surface1;
Graphics::Surface _surface2;

private:
static const int kArchiveCount = 10;
Expand Down
2 changes: 2 additions & 0 deletions engines/bladerunner/module.mk
Expand Up @@ -17,6 +17,8 @@ MODULE_OBJS = \
script/script.o \
set.o \
settings.o \
slice_animations.o \
slice_renderer.o \
view.o \
vqa_decoder.o \
vqa_player.o
Expand Down
173 changes: 173 additions & 0 deletions engines/bladerunner/slice_animations.cpp
@@ -0,0 +1,173 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "bladerunner/slice_animations.h"

#include "bladerunner/bladerunner.h"

#include "common/debug.h"
#include "common/file.h"
#include "common/system.h"

namespace BladeRunner {

bool SliceAnimations::open(const Common::String &name) {
Common::File file;
if (!file.open(_vm->getResourceStream(name), name))
return false;

_timestamp = file.readUint32LE();
_pageSize = file.readUint32LE();
_pageCount = file.readUint32LE();
_paletteCount = file.readUint32LE();

if (_timestamp != 0x3457b6f6) // Timestamp: Wed, 29 Oct 1997 22:21:42 GMT
return false;

_palettes.resize(_paletteCount);

for (uint32 i = 0; i != _paletteCount; ++i) {
for (uint32 j = 0; j != 256; ++j) {
uint8 color_r = file.readByte();
uint8 color_g = file.readByte();
uint8 color_b = file.readByte();

uint16 rgb555 = ((uint16)color_r << 10) |
((uint16)color_g << 5) |
(uint16)color_b;

_palettes[i][j] = rgb555;
}
}

uint32 animationCount = file.readUint32LE();
_animations.resize(animationCount);

for (uint32 i = 0; i != animationCount; ++i) {
_animations[i].frameCount = file.readUint32LE();
_animations[i].frameSize = file.readUint32LE();
_animations[i].fps = file.readFloatLE();
_animations[i].unk0 = file.readFloatLE();
_animations[i].unk1 = file.readFloatLE();
_animations[i].unk2 = file.readFloatLE();
_animations[i].unk3 = file.readFloatLE();
_animations[i].offset = file.readUint32LE();

#if 0
debug("%4d %6d %6x %7.2g %7.2g %7.2g %7.2g %7.2g %8x",
i,
_animations[i].frameCount,
_animations[i].frameSize,
_animations[i].fps,
_animations[i].unk0,
_animations[i].unk1,
_animations[i].unk2,
_animations[i].unk3,
_animations[i].offset);
#endif
}

_pages.resize(_pageCount);
for (uint32 i = 0; i != _pageCount; ++i)
_pages[i]._data = nullptr;

return true;
}

SliceAnimations::~SliceAnimations() {
for (uint32 i = 0; i != _pageCount; ++i)
free(_pages[i]._data);
}

bool SliceAnimations::openCoreAnim() {
return _coreAnimPageFile.open("COREANIM.DAT");
}

bool SliceAnimations::openHDFrames() {
return _framesPageFile.open("HDFRAMES.DAT");
}

bool SliceAnimations::PageFile::open(const Common::String &name) {
if (!_file.open(name))
return false;

uint32 timestamp = _file.readUint32LE();
if (timestamp != _sliceAnimations->_timestamp)
return false;

_pageOffsets.resize(_sliceAnimations->_pageCount);
for (uint32 i = 0; i != _sliceAnimations->_pageCount; ++i)
_pageOffsets[i] = -1;

uint32 pageCount = _file.readUint32LE();
uint32 dataOffset = 8 + 4 * pageCount;

for (uint32 i = 0; i != pageCount; ++i) {
uint32 pageNumber = _file.readUint32LE();
if (pageNumber == 0xffffffff)
continue;
_pageOffsets[pageNumber] = dataOffset + i * _sliceAnimations->_pageSize;
}

debug("PageFile::Open: page file \"%s\" opened with %d pages", name.c_str(), pageCount);

return true;
}

void *SliceAnimations::PageFile::loadPage(uint32 pageNumber) {
if (_pageOffsets[pageNumber] == -1)
return nullptr;

uint32 pageSize = _sliceAnimations->_pageSize;

// TODO: Retire oldest pages if we exceed some memory limit

void *data = malloc(pageSize);
_file.seek(_pageOffsets[pageNumber], SEEK_SET);
uint32 r = _file.read(data, pageSize);
assert(r == pageSize);

return data;
}

void *SliceAnimations::getFramePtr(uint32 animation, uint32 frame) {
assert(frame < _animations[animation].frameCount);

uint32 frameOffset = _animations[animation].offset + frame * _animations[animation].frameSize;
uint32 page = frameOffset / _pageSize;
uint32 pageOffset = frameOffset % _pageSize;

if (!_pages[page]._data)
_pages[page]._data = _coreAnimPageFile.loadPage(page);

if (!_pages[page]._data)
_pages[page]._data = _framesPageFile.loadPage(page);

if (!_pages[page]._data)
error("Unable to locate page %d for animation %d frame %d", page, animation, frame);

_pages[page]._lastAccess = _vm->_system->getMillis();

return (byte*)_pages[page]._data + pageOffset;
}

} // End of namespace BladeRunner

0 comments on commit 4b181e4

Please sign in to comment.