mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-16 22:58:09 +00:00
ZVISION: Optimize integer type usages
The general thought is int is faster than int16 or byte. So if you can afford the space, use it over int16 or byte. Also, only use int32 when you specifically need the 32 bits.
This commit is contained in:
parent
89d8496dba
commit
f1135292d0
@ -28,7 +28,7 @@
|
||||
|
||||
namespace ZVision {
|
||||
|
||||
NodeTimer::NodeTimer(uint32 key, uint32 timeInSeconds)
|
||||
NodeTimer::NodeTimer(uint32 key, uint timeInSeconds)
|
||||
: _key(key), _timeLeft(timeInSeconds * 1000) {}
|
||||
|
||||
bool NodeTimer::process(ZVision *engine, uint32 deltaTimeInMillis) {
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
|
||||
class NodeTimer : public ActionNode {
|
||||
public:
|
||||
NodeTimer(uint32 key, uint32 timeInSeconds);
|
||||
NodeTimer(uint32 key, uint timeInSeconds);
|
||||
/**
|
||||
* Decrement the timer by the delta time. If the timer is finished, set the status
|
||||
* in _globalState and let this node be deleted
|
||||
|
@ -174,7 +174,7 @@ ResultAction *ActionRandom::clone() const {
|
||||
}
|
||||
|
||||
bool ActionRandom::execute(ZVision *engine) {
|
||||
uint32 randNumber = engine->getRandomSource()->getRandomNumber(_max);
|
||||
uint randNumber = engine->getRandomSource()->getRandomNumber(_max);
|
||||
engine->getScriptManager()->setStateValue(_key, randNumber);
|
||||
return true;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _key;
|
||||
byte _value;
|
||||
uint _value;
|
||||
};
|
||||
|
||||
class ActionAssign : public ResultAction {
|
||||
@ -90,7 +90,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _key;
|
||||
byte _value;
|
||||
uint _value;
|
||||
};
|
||||
|
||||
class ActionAttenuate : public ResultAction {
|
||||
@ -101,7 +101,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _key;
|
||||
int16 _attenuation;
|
||||
int _attenuation;
|
||||
};
|
||||
|
||||
class ActionChangeLocation : public ResultAction {
|
||||
@ -115,7 +115,7 @@ private:
|
||||
char _room;
|
||||
char _node;
|
||||
char _view;
|
||||
int16 _x;
|
||||
uint32 _x;
|
||||
};
|
||||
|
||||
class ActionCrossfade : public ResultAction {
|
||||
@ -127,11 +127,11 @@ public:
|
||||
private:
|
||||
uint32 _keyOne;
|
||||
uint32 _keyTwo;
|
||||
byte _oneStartVolume;
|
||||
byte _twoStartVolume;
|
||||
byte _oneEndVolume;
|
||||
byte _twoEndVolume;
|
||||
uint16 _timeInMillis;
|
||||
uint _oneStartVolume;
|
||||
uint _twoStartVolume;
|
||||
uint _oneEndVolume;
|
||||
uint _twoEndVolume;
|
||||
uint _timeInMillis;
|
||||
};
|
||||
|
||||
class ActionDelayRender : public ResultAction {
|
||||
@ -142,7 +142,7 @@ public:
|
||||
|
||||
private:
|
||||
// TODO: Check if this should actually be frames or if it should be milliseconds/seconds
|
||||
byte framesToDelay;
|
||||
uint32 framesToDelay;
|
||||
};
|
||||
|
||||
class ActionPlayAnimation : public ResultAction {
|
||||
@ -160,8 +160,8 @@ private:
|
||||
uint32 _height;
|
||||
uint32 _start;
|
||||
uint32 _end;
|
||||
uint32 _mask;
|
||||
byte _framerate;
|
||||
uint _mask;
|
||||
uint _framerate;
|
||||
bool _loop;
|
||||
};
|
||||
|
||||
@ -174,8 +174,8 @@ public:
|
||||
private:
|
||||
uint32 _key;
|
||||
Common::String _fileName;
|
||||
uint32 _mask;
|
||||
byte _framerate;
|
||||
uint _mask;
|
||||
uint _framerate;
|
||||
};
|
||||
|
||||
// TODO: See if this exists in ZGI. It doesn't in ZNem
|
||||
@ -193,7 +193,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _key;
|
||||
uint32 _max;
|
||||
uint _max;
|
||||
};
|
||||
|
||||
class ActionTimer : public ResultAction {
|
||||
@ -204,7 +204,7 @@ public:
|
||||
|
||||
private:
|
||||
uint32 _key;
|
||||
uint32 _time;
|
||||
uint _time;
|
||||
};
|
||||
|
||||
} // End of namespace ZVision
|
||||
|
@ -54,8 +54,8 @@ void Control::parsePanoramaControl(ZVision *engine, Common::SeekableReadStream &
|
||||
sscanf(line.c_str(), "angle(%f)", &scale);
|
||||
renderTable->setPanoramaScale(scale);
|
||||
} else if (line.matchString("reversepana*", true)) {
|
||||
byte reverse;
|
||||
sscanf(line.c_str(), "reversepana(%hhu)", &reverse);
|
||||
uint reverse;
|
||||
sscanf(line.c_str(), "reversepana(%u)", &reverse);
|
||||
if (reverse == 1) {
|
||||
renderTable->setPanoramaReverse(true);
|
||||
}
|
||||
@ -86,8 +86,8 @@ void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stre
|
||||
sscanf(line.c_str(), "angle(%f)", &scale);
|
||||
renderTable->setTiltScale(scale);
|
||||
} else if (line.matchString("reversepana*", true)) {
|
||||
byte reverse;
|
||||
sscanf(line.c_str(), "reversepana(%hhu)", &reverse);
|
||||
uint reverse;
|
||||
sscanf(line.c_str(), "reversepana(%u)", &reverse);
|
||||
if (reverse == 1) {
|
||||
renderTable->setTiltReverse(true);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ void ZVision::onMouseMove(const Common::Point &pos) {
|
||||
|
||||
}
|
||||
|
||||
void ZVision::onKeyDown(uint16 keyCode) {
|
||||
void ZVision::onKeyDown(uint keyCode) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,9 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes)
|
||||
byte flagbyte = _source->readByte();
|
||||
if (_source->eos())
|
||||
break;
|
||||
byte mask = 1;
|
||||
uint mask = 1;
|
||||
|
||||
for (uint32 i = 0; i < 8; i++) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if ((flagbyte & mask) == mask)
|
||||
{
|
||||
byte data = _source->readByte();
|
||||
@ -70,7 +70,7 @@ uint32 LzssReadStream::decompressBytes(byte *destination, uint32 numberOfBytes)
|
||||
uint16 length = (high & 0xF) + 2;
|
||||
uint16 offset = low | ((high & 0xF0)<<4);
|
||||
|
||||
for(byte j = 0; j <= length; j++)
|
||||
for(int j = 0; j <= length; j++)
|
||||
{
|
||||
byte temp = _window[(offset + j) & 0xFFF];
|
||||
_window[_windowCursor] = temp;
|
||||
|
@ -49,8 +49,8 @@ public:
|
||||
|
||||
private:
|
||||
Common::SeekableReadStream *_source;
|
||||
char _window[_blockSize];
|
||||
uint16 _windowCursor;
|
||||
byte _window[BLOCK_SIZE];
|
||||
uint _windowCursor;
|
||||
bool _eosFlag;
|
||||
|
||||
public:
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
Common::List<Criteria> criteriaList;
|
||||
// This has to be list of pointers because ResultAction is abstract
|
||||
Common::List<ResultAction *> resultActions;
|
||||
byte flags;
|
||||
uint flags;
|
||||
|
||||
// Used by the ScriptManager to allow unique-ification of _referenceTable
|
||||
// The unique-ification is done by sorting, then iterating and removing duplicates
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace ZVision {
|
||||
|
||||
RenderTable::RenderTable(uint32 numColumns, uint32 numRows)
|
||||
RenderTable::RenderTable(uint numColumns, uint numRows)
|
||||
: _numRows(numRows),
|
||||
_numColumns(numColumns),
|
||||
_renderState(FLAT) {
|
||||
@ -85,10 +85,10 @@ void RenderTable::mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 i
|
||||
bool isTransposed = _renderState == RenderTable::PANORAMA || _renderState == RenderTable::TILT;
|
||||
|
||||
for (int y = subRectangle.top; y < subRectangle.bottom; y++) {
|
||||
uint32 normalizedY = y - subRectangle.top;
|
||||
uint normalizedY = y - subRectangle.top;
|
||||
|
||||
for (int x = subRectangle.left; x < subRectangle.right; x++) {
|
||||
uint32 normalizedX = x - subRectangle.left;
|
||||
uint normalizedX = x - subRectangle.left;
|
||||
|
||||
uint32 index = (y + destRectangle.top) * _numColumns + (x + destRectangle.left);
|
||||
|
||||
@ -137,15 +137,15 @@ void RenderTable::generatePanoramaLookupTable() {
|
||||
float tanOverHalfHeight = tan(fovRadians) / halfHeight;
|
||||
|
||||
// TODO: Change the algorithm to write a whole row at a time instead of a whole column at a time. AKA: for(y) { for(x) {}} instead of for(x) { for(y) {}}
|
||||
for (uint32 x = 0; x < _numColumns; x++) {
|
||||
for (uint x = 0; x < _numColumns; x++) {
|
||||
// Add an offset of 0.01 to overcome zero tan/atan issue (vertical line on half of screen)
|
||||
float temp = atan(tanOverHalfHeight * ((float)x - halfWidth + 0.01f));
|
||||
|
||||
int32 newX = floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth);
|
||||
int32 newX = int32(floor((halfHeightOverTan * _panoramaOptions.linearScale * temp) + halfWidth));
|
||||
float cosX = cos(temp);
|
||||
|
||||
for (uint32 y = 0; y < _numRows; y++) {
|
||||
int32 newY = floor(halfHeight + (y - halfHeight) * cosX);
|
||||
for (uint y = 0; y < _numRows; y++) {
|
||||
int32 newY = int32(floor(halfHeight + ((float)y - halfHeight) * cosX));
|
||||
|
||||
uint32 index = y * _numColumns + x;
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace ZVision {
|
||||
|
||||
class RenderTable {
|
||||
public:
|
||||
RenderTable(uint32 numRows, uint32 numColumns);
|
||||
RenderTable(uint numRows, uint numColumns);
|
||||
~RenderTable();
|
||||
|
||||
public:
|
||||
@ -43,7 +43,7 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
uint32 _numColumns, _numRows;
|
||||
uint _numColumns, _numRows;
|
||||
Vector2 *_internalBuffer;
|
||||
RenderState _renderState;
|
||||
|
||||
|
@ -267,8 +267,8 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis
|
||||
return;
|
||||
}
|
||||
|
||||
byte ScriptManager::parseFlags(Common::SeekableReadStream &stream) const {
|
||||
byte flags;
|
||||
uint ScriptManager::parseFlags(Common::SeekableReadStream &stream) const {
|
||||
uint flags = 0;
|
||||
|
||||
// Loop until we find the closing brace
|
||||
Common::String line = stream.readLine();
|
||||
|
@ -60,7 +60,7 @@ void ScriptManager::createReferenceTable() {
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::updateNodes(uint32 deltaTimeMillis) {
|
||||
void ScriptManager::updateNodes(uint deltaTimeMillis) {
|
||||
// If process() returns true, it means the node can be deleted
|
||||
for (Common::List<ActionNode *>::iterator iter = _activeNodes.begin(); iter != _activeNodes.end();) {
|
||||
if ((*iter)->process(_engine, deltaTimeMillis)) {
|
||||
@ -82,7 +82,7 @@ void ScriptManager::checkPuzzleCriteria() {
|
||||
bool criteriaMet = false;
|
||||
for (Common::List<Puzzle::Criteria>::iterator iter = puzzle->criteriaList.begin(); iter != puzzle->criteriaList.end(); iter++) {
|
||||
// Get the value to compare against
|
||||
byte argumentValue;
|
||||
uint argumentValue;
|
||||
if ((*iter).argument)
|
||||
argumentValue = getStateValue(iter->argument);
|
||||
else
|
||||
@ -119,16 +119,16 @@ void ScriptManager::checkPuzzleCriteria() {
|
||||
}
|
||||
}
|
||||
|
||||
byte ScriptManager::getStateValue(uint32 key) {
|
||||
uint ScriptManager::getStateValue(uint32 key) {
|
||||
return _globalState[key];
|
||||
}
|
||||
|
||||
// TODO: Add logic to check _referenceTable and add to _puzzlesToCheck if necessary
|
||||
void ScriptManager::setStateValue(uint32 key, byte value) {
|
||||
void ScriptManager::setStateValue(uint32 key, uint value) {
|
||||
_globalState[key] = value;
|
||||
}
|
||||
|
||||
void ScriptManager::addToStateValue(uint32 key, byte valueToAdd) {
|
||||
void ScriptManager::addToStateValue(uint32 key, uint valueToAdd) {
|
||||
_globalState[key] += valueToAdd;
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ void ScriptManager::addActionNode(ActionNode *node) {
|
||||
_activeNodes.push_back(node);
|
||||
}
|
||||
|
||||
void ScriptManager::changeLocation(char world, char room, char node, char view, uint16 x) {
|
||||
void ScriptManager::changeLocation(char world, char room, char node, char view, uint32 x) {
|
||||
// Clear all the containers
|
||||
_referenceTable.clear();
|
||||
_puzzlesToCheck.clear();
|
||||
|
@ -50,7 +50,7 @@ private:
|
||||
* mutators getStateValue() and setStateValue(). This ensures that Puzzles that reference a
|
||||
* particular state key are checked after the key is modified.
|
||||
*/
|
||||
Common::HashMap<uint32, byte> _globalState;
|
||||
Common::HashMap<uint32, uint> _globalState;
|
||||
/** Holds the currently active ActionNodes */
|
||||
Common::List<ActionNode *> _activeNodes;
|
||||
/** References _globalState keys to Puzzles */
|
||||
@ -65,16 +65,16 @@ private:
|
||||
public:
|
||||
|
||||
void initialize();
|
||||
void updateNodes(uint32 deltaTimeMillis);
|
||||
void updateNodes(uint deltaTimeMillis);
|
||||
void checkPuzzleCriteria();
|
||||
|
||||
byte getStateValue(uint32 key);
|
||||
void setStateValue(uint32 key, byte value);
|
||||
void addToStateValue(uint32 key, byte valueToAdd);
|
||||
uint getStateValue(uint32 key);
|
||||
void setStateValue(uint32 key, uint value);
|
||||
void addToStateValue(uint32 key, uint valueToAdd);
|
||||
|
||||
void addActionNode(ActionNode *node);
|
||||
|
||||
void changeLocation(char world, char room, char node, char view, uint16 x);
|
||||
void changeLocation(char world, char room, char node, char view, uint32 x);
|
||||
|
||||
private:
|
||||
void createReferenceTable();
|
||||
@ -118,9 +118,9 @@ private:
|
||||
* Helper method for parsePuzzle. Parses the stream into a bitwise or of the StateFlags enum
|
||||
*
|
||||
* @param stream Scr file stream
|
||||
* @return Bitwise or of all the flags set within the puzzle
|
||||
* @return Bitwise OR of all the flags set within the puzzle
|
||||
*/
|
||||
byte parseFlags(Common::SeekableReadStream &stream) const;
|
||||
uint parseFlags(Common::SeekableReadStream &stream) const;
|
||||
|
||||
/**
|
||||
* Helper method for parseScrFile. Parses the stream into a Control object
|
||||
|
@ -70,7 +70,7 @@ template<class T>
|
||||
void removeDuplicateEntries(Common::Array<T> *container) {
|
||||
Common::sort(container->front(), container->back());
|
||||
|
||||
for (uint32 i = 0; i < container->size(); i++) {
|
||||
for (int i = 0; i < container->size(); i++) {
|
||||
while (container[i] == container[i +1]) {
|
||||
container->remove_at(i + 1);
|
||||
}
|
||||
|
@ -33,15 +33,15 @@
|
||||
namespace ZVision {
|
||||
|
||||
// Taken from SCI
|
||||
void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte bytesPerPixel) {
|
||||
void scale2x(const byte *src, byte *dst, uint32 srcWidth, uint32 srcHeight, byte bytesPerPixel) {
|
||||
assert(bytesPerPixel == 1 || bytesPerPixel == 2);
|
||||
const int newWidth = srcWidth * 2;
|
||||
const int pitch = newWidth * bytesPerPixel;
|
||||
const uint32 newWidth = srcWidth * 2;
|
||||
const uint32 pitch = newWidth * bytesPerPixel;
|
||||
const byte *srcPtr = src;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
for (int y = 0; y < srcHeight; y++) {
|
||||
for (int x = 0; x < srcWidth; x++) {
|
||||
for (uint32 y = 0; y < srcHeight; y++) {
|
||||
for (uint32 x = 0; x < srcWidth; x++) {
|
||||
const byte color = *srcPtr++;
|
||||
dst[0] = color;
|
||||
dst[1] = color;
|
||||
@ -52,8 +52,8 @@ void scale2x(const byte *src, byte *dst, int16 srcWidth, int16 srcHeight, byte b
|
||||
dst += newWidth;
|
||||
}
|
||||
} else if (bytesPerPixel == 2) {
|
||||
for (int y = 0; y < srcHeight; y++) {
|
||||
for (int x = 0; x < srcWidth; x++) {
|
||||
for (uint32 y = 0; y < srcHeight; y++) {
|
||||
for (uint32 x = 0; x < srcWidth; x++) {
|
||||
const byte color = *srcPtr++;
|
||||
const byte color2 = *srcPtr++;
|
||||
dst[0] = color;
|
||||
|
@ -73,10 +73,10 @@ RawZorkStream::RawZorkStream(uint32 rate, bool stereo, DisposeAfterUse::Flag dis
|
||||
}
|
||||
|
||||
int RawZorkStream::readBuffer(int16 *buffer, const int numSamples) {
|
||||
uint32 bytesRead = 0;
|
||||
int bytesRead = 0;
|
||||
|
||||
// 0: Left, 1: Right
|
||||
byte channel = 0;
|
||||
uint channel = 0;
|
||||
|
||||
while (bytesRead < numSamples) {
|
||||
byte encodedSample = _stream->readByte();
|
||||
|
@ -36,7 +36,7 @@ class ZVision;
|
||||
|
||||
struct SoundParams {
|
||||
char identifier;
|
||||
uint16 rate;
|
||||
uint32 rate;
|
||||
bool stereo;
|
||||
bool packed;
|
||||
};
|
||||
@ -73,7 +73,7 @@ private:
|
||||
Audio::Timestamp _playtime; // Calculated total play time
|
||||
Common::DisposablePtr<Common::SeekableReadStream> _stream; // Stream to read data from
|
||||
bool _endOfData; // Whether the stream end has been reached
|
||||
byte _stereo;
|
||||
uint _stereo;
|
||||
|
||||
/**
|
||||
* Holds the frequency and index from the last sample
|
||||
|
@ -117,7 +117,7 @@ Common::Error ZVision::run() {
|
||||
// Main loop
|
||||
uint32 currentTime = _system->getMillis();
|
||||
uint32 lastTime = currentTime;
|
||||
const uint32 desiredFrameTime = 33; // ~30 fps
|
||||
const uint desiredFrameTime = 33; // ~30 fps
|
||||
|
||||
while (!shouldQuit()) {
|
||||
processEvents();
|
||||
|
@ -83,7 +83,7 @@ private:
|
||||
void processEvents();
|
||||
void onMouseDown(const Common::Point &pos);
|
||||
void onMouseMove(const Common::Point &pos);
|
||||
void onKeyDown(uint16 keyCode);
|
||||
void onKeyDown(uint keyCode);
|
||||
};
|
||||
|
||||
} // End of namespace ZVision
|
||||
|
Loading…
Reference in New Issue
Block a user