From 3ead0f4289cce2329b46f993eeefd609e9805dba Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 14 Dec 2017 17:35:34 +0000 Subject: [PATCH] Finish loading water JSON objects --- src/openrct2/drawing/Drawing.h | 1 + src/openrct2/drawing/Sprite.cpp | 15 ++------------- src/openrct2/object/ObjectFactory.cpp | 1 + src/openrct2/object/WaterObject.cpp | 8 +++++--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/openrct2/drawing/Drawing.h b/src/openrct2/drawing/Drawing.h index 2346351e8d..54d7d5d647 100644 --- a/src/openrct2/drawing/Drawing.h +++ b/src/openrct2/drawing/Drawing.h @@ -56,6 +56,7 @@ enum { G1_FLAG_BMP = (1 << 0), // Image data is encoded as raw pixels (no transparency) G1_FLAG_1 = (1 << 1), G1_FLAG_RLE_COMPRESSION = (1 << 2), // Image data is encoded using RCT2's form of run length encoding + G1_FLAG_PALETTE = (1 << 3), // Image data is a sequence of palette entries R8G8B8 G1_FLAG_HAS_ZOOM_SPRITE = (1 << 4), // Use a different sprite for higher zoom levels G1_FLAG_NO_ZOOM_DRAW = (1 << 5), // Does not get drawn at higher zoom levels (only zoom 0) }; diff --git a/src/openrct2/drawing/Sprite.cpp b/src/openrct2/drawing/Sprite.cpp index 9e7442ebbc..0f34364295 100644 --- a/src/openrct2/drawing/Sprite.cpp +++ b/src/openrct2/drawing/Sprite.cpp @@ -863,20 +863,9 @@ rct_size16 FASTCALL gfx_get_sprite_size(uint32 image_id) size_t g1_calculate_data_size(const rct_g1_element * g1) { - if (g1->flags & G1_FLAG_RLE_COMPRESSION) + if (g1->flags & G1_FLAG_PALETTE) { - uint16 * offsets = (uint16 *)g1->offset; - uint8 * ptr = g1->offset + offsets[g1->height - 1]; - bool endOfLine = false; - do - { - uint8 chunk0 = *ptr++; - ptr++; // offset - uint8 chunkSize = chunk0 & 0x7F; - ptr += chunkSize; - endOfLine = (chunk0 & 0x80) != 0; - } while (!endOfLine); - return ptr - g1->offset; + return g1->width * 3; } else if (g1->flags & G1_FLAG_RLE_COMPRESSION) { diff --git a/src/openrct2/object/ObjectFactory.cpp b/src/openrct2/object/ObjectFactory.cpp index 1064fb76a1..d16cc7af3e 100644 --- a/src/openrct2/object/ObjectFactory.cpp +++ b/src/openrct2/object/ObjectFactory.cpp @@ -212,6 +212,7 @@ namespace ObjectFactory if (s == "footpath_banner") return OBJECT_TYPE_BANNERS; if (s == "footpath_item") return OBJECT_TYPE_PATH_BITS; if (s == "park_entrance") return OBJECT_TYPE_PARK_ENTRANCE; + if (s == "water") return OBJECT_TYPE_WATER; return 0xFF; } diff --git a/src/openrct2/object/WaterObject.cpp b/src/openrct2/object/WaterObject.cpp index c18c9ccfd3..2edcc3c338 100644 --- a/src/openrct2/object/WaterObject.cpp +++ b/src/openrct2/object/WaterObject.cpp @@ -99,7 +99,7 @@ void WaterObject::ReadJsonPalette(const json_t * jPalette) auto jColours = json_object_get(jPalette, "colours"); auto numColours = json_array_size(jColours); - auto data = std::make_unique(numColours); + auto data = std::make_unique(numColours * 3); size_t dataIndex = 0; size_t index; @@ -110,16 +110,18 @@ void WaterObject::ReadJsonPalette(const json_t * jPalette) if (szColour != nullptr) { auto colour = ParseColour(szColour); - data[dataIndex + 0] = colour; + data[dataIndex + 0] = (colour >> 16) & 0xFF; data[dataIndex + 1] = (colour >> 8) & 0xFF; - data[dataIndex + 2] = (colour >> 16) & 0xFF; + data[dataIndex + 2] = colour & 0xFF; } dataIndex += 3; } rct_g1_element g1 = { 0 }; g1.offset = data.get(); + g1.width = (sint16)numColours; g1.x_offset = (sint16)paletteStartIndex; + g1.flags = G1_FLAG_PALETTE; auto &imageTable = GetImageTable(); imageTable.AddImage(&g1);