aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine/segment.h
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/engine/segment.h')
-rw-r--r--engines/sci/engine/segment.h120
1 files changed, 57 insertions, 63 deletions
diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h
index 2af47801b2..361c1cb895 100644
--- a/engines/sci/engine/segment.h
+++ b/engines/sci/engine/segment.h
@@ -475,15 +475,13 @@ public:
/**
* Sets the type of this array. The type of the array may only be set once.
*/
- void setType(SciArrayType type) {
+ void setType(const SciArrayType type) {
assert(_type == kArrayTypeInvalid);
switch(type) {
+ case kArrayTypeInt16:
case kArrayTypeID:
_elementSize = sizeof(reg_t);
break;
- case kArrayTypeInt16:
- _elementSize = sizeof(int16);
- break;
case kArrayTypeString:
_elementSize = sizeof(char);
break;
@@ -551,12 +549,11 @@ public:
switch(_type) {
case kArrayTypeInt16:
- return make_reg(0, ((int16 *)_data)[index]);
+ case kArrayTypeID:
+ return ((reg_t *)_data)[index];
case kArrayTypeByte:
case kArrayTypeString:
return make_reg(0, ((byte *)_data)[index]);
- case kArrayTypeID:
- return ((reg_t *)_data)[index];
default:
error("Invalid array type %d", _type);
}
@@ -574,26 +571,23 @@ public:
switch(_type) {
case kArrayTypeInt16:
- ((int16 *)_data)[index] = value.toSint16();
+ case kArrayTypeID:
+ ((reg_t *)_data)[index] = value;
break;
case kArrayTypeByte:
case kArrayTypeString:
((byte *)_data)[index] = value.toSint16();
break;
- case kArrayTypeID:
- ((reg_t *)_data)[index] = value;
- break;
default:
error("Invalid array type %d", _type);
}
}
/**
- * Returns a reference to the byte at the given index. Only valid for
- * string and byte arrays.
+ * Gets the value at the given index as an int16.
*/
- byte &byteAt(const uint16 index) {
- assert(_type == kArrayTypeString || _type == kArrayTypeByte);
+ int16 getAsInt16(const uint16 index) {
+ assert(_type == kArrayTypeInt16);
if (getSciVersion() >= SCI_VERSION_3) {
resize(index);
@@ -601,14 +595,31 @@ public:
assert(index < _size);
}
- return ((byte *)_data)[index];
+ const reg_t value = ((reg_t *)_data)[index];
+ assert(value.isNumber());
+ return value.toSint16();
}
/**
- * Returns a reference to the char at the given index. Only valid for
+ * Sets the value at the given index from an int16.
+ */
+ void setFromInt16(const uint16 index, const int16 value) {
+ assert(_type == kArrayTypeInt16);
+
+ if (getSciVersion() >= SCI_VERSION_3) {
+ resize(index + 1);
+ } else {
+ assert(index < _size);
+ }
+
+ ((reg_t *)_data)[index] = make_reg(0, value);
+ }
+
+ /**
+ * Returns a reference to the byte at the given index. Only valid for
* string and byte arrays.
*/
- char &charAt(const uint16 index) {
+ byte &byteAt(const uint16 index) {
assert(_type == kArrayTypeString || _type == kArrayTypeByte);
if (getSciVersion() >= SCI_VERSION_3) {
@@ -617,15 +628,15 @@ public:
assert(index < _size);
}
- return ((char *)_data)[index];
+ return ((byte *)_data)[index];
}
/**
- * Returns a reference to the int16 at the given index. Only valid for int16
- * arrays.
+ * Returns a reference to the char at the given index. Only valid for
+ * string and byte arrays.
*/
- int16 &int16At(const uint16 index) {
- assert(_type == kArrayTypeInt16);
+ char &charAt(const uint16 index) {
+ assert(_type == kArrayTypeString || _type == kArrayTypeByte);
if (getSciVersion() >= SCI_VERSION_3) {
resize(index);
@@ -633,15 +644,15 @@ public:
assert(index < _size);
}
- return ((int16 *)_data)[index];
+ return ((char *)_data)[index];
}
/**
* Returns a reference to the reg_t at the given index. Only valid for ID
- * arrays.
+ * and int16 arrays.
*/
reg_t &IDAt(const uint16 index) {
- assert(_type == kArrayTypeID);
+ assert(_type == kArrayTypeID || _type == kArrayTypeInt16);
if (getSciVersion() >= SCI_VERSION_3) {
resize(index);
@@ -660,18 +671,7 @@ public:
resize(index + count);
switch (_type) {
- case kArrayTypeInt16: {
- const reg_t *source = values;
- int16 *target = (int16 *)_data + index;
- while (count--) {
- if (!source->isNumber()) {
- error("Non-number %04x:%04x sent to int16 array", PRINT_REG(*source));
- }
- *target++ = source->toSint16();
- ++source;
- }
- break;
- }
+ case kArrayTypeInt16:
case kArrayTypeID: {
const reg_t *source = values;
reg_t *target = (reg_t *)_data + index;
@@ -714,14 +714,7 @@ public:
resize(index + count);
switch (_type) {
- case kArrayTypeInt16: {
- const int16 fillValue = value.toSint16();
- int16 *target = (int16 *)_data + index;
- while (count--) {
- *target++ = fillValue;
- }
- break;
- }
+ case kArrayTypeInt16:
case kArrayTypeID: {
reg_t *target = (reg_t *)_data + index;
while (count--) {
@@ -834,7 +827,7 @@ public:
}
}
}
-
+
/**
* Copies the string data held by this array into a new Common::String.
*/
@@ -970,7 +963,7 @@ public:
/**
* Allocates and initialises a new bitmap.
*/
- inline void create(const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 paletteSize, const bool remap, const bool gc) {
+ inline void create(const int16 width, const int16 height, const uint8 skipColor, const int16 originX, const int16 originY, const int16 xResolution, const int16 yResolution, const uint32 paletteSize, const bool remap, const bool gc) {
_dataSize = getBitmapSize(width, height) + paletteSize;
_data = (byte *)realloc(_data, _dataSize);
@@ -980,7 +973,7 @@ public:
setWidth(width);
setHeight(height);
- setDisplace(Common::Point(displaceX, displaceY));
+ setOrigin(Common::Point(originX, originY));
setSkipColor(skipColor);
_data[9] = 0;
WRITE_SCI11ENDIAN_UINT16(_data + 10, 0);
@@ -991,8 +984,8 @@ public:
setDataOffset(bitmapHeaderSize);
setUncompressedDataOffset(bitmapHeaderSize);
setControlOffset(0);
- setScaledWidth(scaledWidth);
- setScaledHeight(scaledHeight);
+ setXResolution(xResolution);
+ setYResolution(yResolution);
_buffer = Buffer(getWidth(), getHeight(), getPixels());
}
@@ -1024,16 +1017,16 @@ public:
BITMAP_PROPERTY(16, Width, 0);
BITMAP_PROPERTY(16, Height, 2);
- inline Common::Point getDisplace() const {
+ inline Common::Point getOrigin() const {
return Common::Point(
(int16)READ_SCI11ENDIAN_UINT16(_data + 4),
(int16)READ_SCI11ENDIAN_UINT16(_data + 6)
);
}
- inline void setDisplace(const Common::Point &displace) {
- WRITE_SCI11ENDIAN_UINT16(_data + 4, (uint16)displace.x);
- WRITE_SCI11ENDIAN_UINT16(_data + 6, (uint16)displace.y);
+ inline void setOrigin(const Common::Point &origin) {
+ WRITE_SCI11ENDIAN_UINT16(_data + 4, (uint16)origin.x);
+ WRITE_SCI11ENDIAN_UINT16(_data + 6, (uint16)origin.y);
}
inline uint8 getSkipColor() const {
@@ -1082,7 +1075,7 @@ public:
// NOTE: This property always seems to be zero
BITMAP_PROPERTY(32, ControlOffset, 32);
- inline uint16 getScaledWidth() const {
+ inline uint16 getXResolution() const {
if (getDataOffset() >= 40) {
return READ_SCI11ENDIAN_UINT16(_data + 36);
}
@@ -1091,13 +1084,13 @@ public:
return 320;
}
- inline void setScaledWidth(uint16 scaledWidth) {
+ inline void setXResolution(uint16 xResolution) {
if (getDataOffset() >= 40) {
- WRITE_SCI11ENDIAN_UINT16(_data + 36, scaledWidth);
+ WRITE_SCI11ENDIAN_UINT16(_data + 36, xResolution);
}
}
- inline uint16 getScaledHeight() const {
+ inline uint16 getYResolution() const {
if (getDataOffset() >= 40) {
return READ_SCI11ENDIAN_UINT16(_data + 38);
}
@@ -1106,9 +1099,9 @@ public:
return 200;
}
- inline void setScaledHeight(uint16 scaledHeight) {
+ inline void setYResolution(uint16 yResolution) {
if (getDataOffset() >= 40) {
- WRITE_SCI11ENDIAN_UINT16(_data + 38, scaledHeight);
+ WRITE_SCI11ENDIAN_UINT16(_data + 38, yResolution);
}
}
@@ -1129,8 +1122,9 @@ public:
const int length = getWidth() * getHeight();
uint8 *pixel = getPixels();
for (int i = 0; i < length; ++i) {
- uint8 color = clut.int16At(*pixel);
- *pixel++ = color;
+ const int16 color = clut.getAsInt16(*pixel);
+ assert(color >= 0 && color <= 255);
+ *pixel++ = (uint8)color;
}
}
};