From 6565ed2871601a2954986b6c25bcad980109b35c Mon Sep 17 00:00:00 2001 From: Joost Peters Date: Fri, 11 Feb 2005 11:14:33 +0000 Subject: Make rnc unpacker a member of Disk class so it reuses the same object, and change rnc code to only build the crc table once instead of for every unpack operation. This should speed it up a bit. svn-id: r16771 --- sky/disk.cpp | 5 ++--- sky/disk.h | 4 +++- sky/rnc_deco.cpp | 15 +++++++-------- sky/rnc_deco.h | 2 ++ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/sky/disk.cpp b/sky/disk.cpp index 020368df60..f41a27a906 100644 --- a/sky/disk.cpp +++ b/sky/disk.cpp @@ -153,11 +153,10 @@ uint8 *Disk::loadFile(uint16 fileNr) { uint8 *uncompDest = (uint8 *)malloc(decompSize); - RncDecoder rncDecoder; int32 unpackLen; if ((fileFlags >> 22) & 0x1) { //do we include the header? // don't return the file's header - unpackLen = rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest, 0); + unpackLen = _rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest, 0); } else { #ifdef SCUMM_BIG_ENDIAN // Convert dataFileHeader to BE (it only consists of 16 bit words) @@ -166,7 +165,7 @@ uint8 *Disk::loadFile(uint16 fileNr) { *(headPtr + i) = READ_LE_UINT16(headPtr + i); #endif memcpy(uncompDest, fileDest, sizeof(dataFileHeader)); - unpackLen = rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest + sizeof(dataFileHeader), 0); + unpackLen = _rncDecoder.unpackM1(fileDest + sizeof(dataFileHeader), uncompDest + sizeof(dataFileHeader), 0); if (unpackLen) unpackLen += sizeof(dataFileHeader); } diff --git a/sky/disk.h b/sky/disk.h index 9b8d1b4fe8..3b4b16ed2b 100644 --- a/sky/disk.h +++ b/sky/disk.h @@ -25,6 +25,7 @@ #include "stdafx.h" #include "common/scummsys.h" #include "common/str.h" +#include "sky/rnc_deco.h" class File; @@ -74,7 +75,8 @@ protected: uint8 *_dinnerTableArea; File *_dataDiskHandle; File *_dnrHandle; - + RncDecoder _rncDecoder; + uint16 _buildList[MAX_FILES_IN_LIST]; uint32 _loadedFilesList[MAX_FILES_IN_LIST]; }; diff --git a/sky/rnc_deco.cpp b/sky/rnc_deco.cpp index d900939488..24db371b1b 100644 --- a/sky/rnc_deco.cpp +++ b/sky/rnc_deco.cpp @@ -36,14 +36,10 @@ namespace Sky { #define HEADER_LEN 18 RncDecoder::RncDecoder() { - _bitBuffl = 0; - _bitBuffh = 0; - _bitCount = 0; + initCrc(); } -RncDecoder::~RncDecoder() { - -} +RncDecoder::~RncDecoder() { } void RncDecoder::initCrc() { uint16 cnt = 0; @@ -175,10 +171,13 @@ int32 RncDecoder::unpackM1(const void *input, void *output, uint16 key) { uint16 crcUnpacked = 0; uint16 crcPacked = 0; - initCrc(); + + _bitBuffl = 0; + _bitBuffh = 0; + _bitCount = 0; //Check for "RNC " - if (READ_BE_UINT32(inputptr) != 0x524e4301) + if (READ_BE_UINT32(inputptr) != RNC_SIGNATURE) return NOT_PACKED; inputptr += 4; diff --git a/sky/rnc_deco.h b/sky/rnc_deco.h index bb4c11d2fb..c2389b1a71 100644 --- a/sky/rnc_deco.h +++ b/sky/rnc_deco.h @@ -24,6 +24,8 @@ #include "stdafx.h" +#define RNC_SIGNATURE 0x524E4301 // "RNC\001" + namespace Sky { class RncDecoder { -- cgit v1.2.3