diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index cbe2a34b..fcb06dbe 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -43,6 +43,7 @@ set(COMMON_SRC getshape.cpp graphicsviewport.cpp hsv.cpp + iconset.cpp iff.cpp ini.cpp int.cpp diff --git a/tiberiandawn/iconset.cpp b/common/iconset.cpp similarity index 65% rename from tiberiandawn/iconset.cpp rename to common/iconset.cpp index c89b430c..3276b884 100644 --- a/tiberiandawn/iconset.cpp +++ b/common/iconset.cpp @@ -40,25 +40,15 @@ #include #include -#include "common/wwstd.h" -#include "common/file.h" +#include "wwstd.h" +#include "file.h" #include "tile.h" -#include "common/iff.h" +#include "iff.h" // Misc? ST - 1/3/2019 10:40AM // extern int Misc; int Misc; -int Get_Icon_Set_Size(void const* iconset); -int Get_Icon_Set_Width(void const* iconset); -int Get_Icon_Set_Height(void const* iconset); -void* Get_Icon_Set_Icondata(void const* iconset); -void* Get_Icon_Set_Trans(void const* iconset); -void* Get_Icon_Set_Remapdata(void const* iconset); -void* Get_Icon_Set_Palettedata(void const* iconset); -int Get_Icon_Set_Count(void const* iconset); -void* Get_Icon_Set_Map(void const* iconset); - //#define ICON_PALETTE_BYTES 16 //#define ICON_MAX 256 @@ -76,7 +66,11 @@ int Get_Icon_Set_Size(void const* iconset) icontrol = (IControl_Type*)iconset; if (icontrol) { - size = le32toh(icontrol->Size); + if (icontrol->Is_CC_Icon()) { + size = le32toh(icontrol->CC.Size); + } else { + size = le32toh(icontrol->RA.Size); + } } return (size); } @@ -110,7 +104,11 @@ void* Get_Icon_Set_Icondata(void const* iconset) IControl_Type* icontrol; icontrol = (IControl_Type*)iconset; if (icontrol) - return (Add_Long_To_Pointer(iconset, le32toh(icontrol->Icons))); + if (icontrol->Is_CC_Icon()) { + return (Add_Long_To_Pointer(iconset, le32toh(icontrol->CC.Icons))); + } else { + return (Add_Long_To_Pointer(iconset, le32toh(icontrol->RA.Icons))); + } return (NULL); } @@ -121,7 +119,11 @@ void* Get_Icon_Set_Trans(void const* iconset) icontrol = (IControl_Type*)iconset; if (icontrol) { - ptr = Add_Long_To_Pointer((void*)iconset, le32toh(icontrol->TransFlag)); + if (icontrol->Is_CC_Icon()) { + ptr = Add_Long_To_Pointer((void*)iconset, le32toh(icontrol->CC.TransFlag)); + } else { + ptr = Add_Long_To_Pointer((void*)iconset, le32toh(icontrol->RA.TransFlag)); + } } return (ptr); } @@ -140,11 +142,62 @@ int Get_Icon_Set_Count(void const* iconset) void* Get_Icon_Set_Map(void const* iconset) { - char* icontrol = (char*)iconset; + IControl_Type* icontrol; + int32_t icontrol_map; + + icontrol = (IControl_Type*)iconset; if (icontrol) { - uint32_t icontrol_map; - memcpy(&icontrol_map, icontrol + offsetof(IControl_Type, Map), sizeof(uint32_t)); - return icontrol + le32toh(icontrol_map); + if (icontrol->Is_CC_Icon()) { + memcpy(&icontrol_map, (char *)iconset + offsetof(IControl_Type, CC.Map), sizeof(int32_t)); + } else { + memcpy(&icontrol_map, (char *)iconset + offsetof(IControl_Type, RA.Map), sizeof(int32_t)); + } + return (char *)iconset + le32toh(icontrol_map); } return (NULL); -} \ No newline at end of file +} + +int Get_Icon_Set_MapWidth(void const* iconset) +{ + IControl_Type* icontrol; + + icontrol = (IControl_Type*)iconset; + if (iconset) { + if (icontrol->Is_CC_Icon()) { + //CC doesn't have this + } else { + return le16toh((((IControl_Type*)iconset)->RA.MapWidth)); + } + } + return (0); +} + +int Get_Icon_Set_MapHeight(void const* iconset) +{ + IControl_Type* icontrol; + + icontrol = (IControl_Type*)iconset; + if (iconset) { + if (icontrol->Is_CC_Icon()) { + //CC doesn't have this + } else { + return le16toh((((IControl_Type*)iconset)->RA.MapHeight)); + } + } + return (0); +} + +unsigned char const* Get_Icon_Set_ControlMap(void const* iconset) +{ + IControl_Type* icontrol; + + icontrol = (IControl_Type*)iconset; + if (iconset) { + if (icontrol->Is_CC_Icon()) { + //CC doesn't have this + } else { + return ((unsigned char const*)((char*)iconset + ((IControl_Type*)iconset)->RA.ColorMap)); + } + } + return (0); +} diff --git a/common/stamp.cpp b/common/stamp.cpp index 1b5f0501..22e49a94 100644 --- a/common/stamp.cpp +++ b/common/stamp.cpp @@ -9,6 +9,7 @@ // distributed with this program. You should have received a copy of the // GNU General Public License along with permitted additional restrictions // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection +#include "tile.h" #include "endianness.h" #include "graphicsviewport.h" #include @@ -16,63 +17,10 @@ #define TD_TILESET_CHECK 0x20 -#pragma pack(push, 1) -struct IconControlType -{ - uint8_t* Get_Icon_Data() - { - if (TD.Icons == TD_TILESET_CHECK) { - return reinterpret_cast(this) + TD.Icons; - } else { - return reinterpret_cast(this) + RA.Icons; - } - } - - uint8_t* Get_Icon_Map() - { - if (TD.Icons == TD_TILESET_CHECK) { - return reinterpret_cast(this) + TD.Map; - } else { - return reinterpret_cast(this) + RA.Map; - } - } - - int16_t Width; // always 24 (ICON_WIDTH) - int16_t Height; // always 24 (ICON_HEIGHT) - int16_t Count; // count of cells in set, not same as images - int16_t Allocated; // is treated like a bool, always 0 in the file? - - union - { - struct - { - int32_t Size; // filesize - int32_t Icons; // always 0x00000020 - int32_t Palettes; // seems to always be 0x00000000 - int32_t Remaps; // unknown, bitfield? - int32_t TransFlag; // array of images length, unknown - int32_t Map; // image index for each cell - } TD; - - struct - { - int16_t MapWidth; // tile width in cells - int16_t MapHeight; // tile height in cells - int32_t Size; // filesize - int32_t Icons; // always 0x00000028 - int32_t Palettes; // seems to always be 0x00000000 - int32_t Remaps; // unknown, bitfield? - int32_t TransFlag; // array of images length, unknown - int32_t ColorMap; // terrain type index, ra only - int32_t Map; // image index for each cell - } RA; - }; -}; -#pragma pack(pop) int IconEntry; void* IconData; -const IconControlType* LastIconset; +const IControl_Type* LastIconset; const uint8_t* StampPtr; const uint8_t* TransFlagPtr; const uint8_t* MapPtr; @@ -80,8 +28,9 @@ int IconWidth; int IconHeight; int IconSize; int IconCount; +int TDIcons; -void Init_Stamps(const IconControlType* iconset) +void Init_Stamps(const IControl_Type* iconset) { if (iconset && LastIconset != iconset) { IconCount = le16toh(iconset->Count); @@ -91,10 +40,10 @@ void Init_Stamps(const IconControlType* iconset) IconSize = IconWidth * IconHeight; // TD and RA tileset headers are slightly different, so check a constant that only exists in one type. - if (le32toh(iconset->TD.Icons) == TD_TILESET_CHECK) { - MapPtr = reinterpret_cast(iconset) + le32toh(iconset->TD.Map); - StampPtr = reinterpret_cast(iconset) + le32toh(iconset->TD.Icons); - TransFlagPtr = reinterpret_cast(iconset) + le32toh(iconset->TD.TransFlag); + if (iconset->Is_CC_Icon()) { + MapPtr = reinterpret_cast(iconset) + le32toh(iconset->CC.Map); + StampPtr = reinterpret_cast(iconset) + le32toh(iconset->CC.Icons); + TransFlagPtr = reinterpret_cast(iconset) + le32toh(iconset->CC.TransFlag); } else { MapPtr = reinterpret_cast(iconset) + le32toh(iconset->RA.Map); StampPtr = reinterpret_cast(iconset) + le32toh(iconset->RA.Icons); @@ -106,7 +55,7 @@ void Init_Stamps(const IconControlType* iconset) void Buffer_Draw_Stamp(void* thisptr, void* icondata, int icon, int x, int y, const void* remapper) { GraphicViewPortClass& viewport = *static_cast(thisptr); - IconControlType* tileset = static_cast(icondata); + IControl_Type* tileset = static_cast(icondata); if (!tileset) { return; @@ -177,7 +126,7 @@ void Buffer_Draw_Stamp_Clip(void const* thisptr, int bottom) { const GraphicViewPortClass& viewport = *static_cast(thisptr); - const IconControlType* tileset = static_cast(icondata); + const IControl_Type* tileset = static_cast(icondata); if (!tileset) { return; @@ -264,16 +213,3 @@ void Buffer_Draw_Stamp_Clip(void const* thisptr, } } } - -uint8_t* Get_Icon_Set_Map(void* temp) -{ - if (temp != nullptr) { - if (le32toh(static_cast(temp)->TD.Icons) == TD_TILESET_CHECK) { - return static_cast(temp) + le32toh(static_cast(temp)->TD.Icons); - } else { - return static_cast(temp) + le32toh(static_cast(temp)->RA.Icons); - } - } - - return nullptr; -} diff --git a/tiberiandawn/tile.h b/common/tile.h similarity index 65% rename from tiberiandawn/tile.h rename to common/tile.h index d343fea4..03c7a600 100644 --- a/tiberiandawn/tile.h +++ b/common/tile.h @@ -34,6 +34,9 @@ #ifndef TILE_H #define TILE_H +#include "endianness.h" +#include + /*=========================================================================*/ /* The following prototypes are for the file: ICONSET.CPP */ /*=========================================================================*/ @@ -47,25 +50,61 @@ void* Get_Icon_Set_Palettedata(void const* iconset); int Get_Icon_Set_Count(void const* iconset); void* Get_Icon_Set_Map(void const* iconset); +int Get_Icon_Set_MapWidth(void const* iconset); +int Get_Icon_Set_MapHeight(void const* iconset); + +unsigned char const* Get_Icon_Set_ControlMap(void const* iconset); + +#define CC_ICON_OFFSET 0x20 + /* ** This is the control structure at the start of a loaded icon set. It must match ** the structure in WWLIB.I! This structure MUST be a multiple of 16 bytes long. */ - -// C&C version of struct #pragma pack(push, 2) typedef struct { + + bool Is_CC_Icon(void) const + { + // maybe TODO, + // IControl_Type in TD is 0x20 bytes in size, if Count == 0 then this would return true on a RA tile with Size == 0x20 + // Not sure if there are empty tile files however + return le32toh(CC.Icons) == CC_ICON_OFFSET; + } + int16_t Width; // Width of icons (pixels). int16_t Height; // Height of icons (pixels). int16_t Count; // Number of (logical) icons in this set. int16_t Allocated; // Was this iconset allocated? - int32_t Size; // Size of entire iconset memory block. - int32_t Icons; // Offset from buffer start to icon data. - int32_t Palettes; // Offset from buffer start to palette data. - int32_t Remaps; // Offset from buffer start to remap index data. - int32_t TransFlag; // Offset for transparency flag table. - int32_t Map; // Icon map offset (if present). + + union + { + // C&C version of struct + struct + { + int32_t Size; // Size of entire iconset memory block. + int32_t Icons; // Offset from buffer start to icon data. + int32_t Palettes; // Offset from buffer start to palette data. + int32_t Remaps; // Offset from buffer start to remap index data. + int32_t TransFlag; // Offset for transparency flag table. + int32_t Map; // Icon map offset (if present). + } CC; + + // RA version of struct + struct + { + int16_t MapWidth; // Width of map (in icons). + int16_t MapHeight; // Height of map (in icons). + int32_t Size; // Size of entire iconset memory block. + int32_t Icons; // Offset from buffer start to icon data. + int32_t Palettes; // Offset from buffer start to palette data. + int32_t Remaps; // Offset from buffer start to remap index data. + int32_t TransFlag; // Offset for transparency flag table. + int32_t ColorMap; // Offset for color control value table. + int32_t Map; // Icon map offset (if present). + } RA; + }; } IControl_Type; #pragma pack(pop) diff --git a/redalert/CMakeLists.txt b/redalert/CMakeLists.txt index 60a3e854..2c2f34a0 100644 --- a/redalert/CMakeLists.txt +++ b/redalert/CMakeLists.txt @@ -61,7 +61,6 @@ set(REDALERT_SRC help.cpp house.cpp iconlist.cpp - iconset.cpp idata.cpp infantry.cpp init.cpp diff --git a/redalert/cdata.cpp b/redalert/cdata.cpp index af1cf39a..d7a53ebb 100644 --- a/redalert/cdata.cpp +++ b/redalert/cdata.cpp @@ -1010,10 +1010,10 @@ void TemplateTypeClass::Init_Heap(void) *=============================================================================================*/ LandType TemplateTypeClass::Land_Type(int icon) const { - IconsetClass const* icontrol = (IconsetClass const*)Get_Image_Data(); + void const* icontrol = Get_Image_Data(); if (icontrol != NULL) { - unsigned char const* map = icontrol->Control_Map(); + unsigned char const* map = Get_Icon_Set_ControlMap(icontrol); if (map != NULL) { static LandType _land[16] = { LAND_CLEAR, @@ -1034,7 +1034,7 @@ LandType TemplateTypeClass::Land_Type(int icon) const LAND_CLEAR, }; - return (_land[map[icon % (icontrol->Map_Width() * icontrol->Map_Height())]]); + return (_land[map[icon % (Get_Icon_Set_MapWidth(icontrol) * Get_Icon_Set_MapHeight(icontrol))]]); } } return (LAND_CLEAR); @@ -1093,8 +1093,8 @@ short const* TemplateTypeClass::Occupy_List(bool) const static short _occupy[13 * 8 + 5]; short* ptr; - IconsetClass const* iconset = (IconsetClass const*)Get_Image_Data(); - unsigned char const* map = iconset->Map_Data(); + void const* iconset = Get_Image_Data(); + unsigned char const* map = (unsigned char const*)Get_Icon_Set_Map(iconset); ptr = &_occupy[0]; for (int index = 0; index < Width * Height; index++) { @@ -1138,8 +1138,8 @@ void TemplateTypeClass::Init(TheaterType theater) _makepath(fullname, NULL, NULL, tplate.IniName, Theaters[theater].Suffix); ptr = MFCD::Retrieve(fullname); ((void const*&)tplate.ImageData) = ptr; - ((unsigned char&)tplate.Width) = Get_IconSet_MapWidth(ptr); - ((unsigned char&)tplate.Height) = Get_IconSet_MapHeight(ptr); + ((unsigned char&)tplate.Width) = Get_Icon_Set_MapWidth(ptr); + ((unsigned char&)tplate.Height) = Get_Icon_Set_MapHeight(ptr); } } } @@ -1181,8 +1181,8 @@ void TemplateTypeClass::Display(int x, int y, WindowNumberType window, HousesTyp x += WindowList[window][WINDOWX]; y += WindowList[window][WINDOWY]; - IconsetClass const* iconset = (IconsetClass const*)Get_Image_Data(); - unsigned char const* map = iconset->Map_Data(); + void const* iconset = Get_Image_Data(); + unsigned char const* map = (unsigned char const*)Get_Icon_Set_Map(iconset); for (index = 0; index < w * h; index++) { if (map[index] != 0xFF) { diff --git a/redalert/compat.h b/redalert/compat.h index ce8974bc..42f3484d 100644 --- a/redalert/compat.h +++ b/redalert/compat.h @@ -66,116 +66,4 @@ typedef enum MenuIndexType #define DKGRAY GREY #define LTGRAY LTGREY -inline int Get_IconSet_MapWidth(void const* data) -{ - if (data) { - return le16toh((((IControl_Type*)data)->MapWidth)); - } - return (0); -} - -inline int Get_IconSet_MapHeight(void const* data) -{ - if (data) { - return le16toh((((IControl_Type*)data)->MapHeight)); - } - return (0); -} - -inline unsigned char const* Get_IconSet_ControlMap(void const* data) -{ - if (data) { - return ((unsigned char const*)((char*)data + ((IControl_Type*)data)->ColorMap)); - } - return (0); -} - -class IconsetClass : protected IControl_Type -{ -public: - /* - ** Query functions. - */ - int Map_Width(void) const - { - return (le16toh(MapWidth)); - }; - int Map_Height(void) const - { - return (le16toh(MapHeight)); - }; - unsigned char* Control_Map(void) - { - return ((unsigned char*)this + le32toh(ColorMap)); - }; - unsigned char const* Control_Map(void) const - { - return ((unsigned char const*)this + le32toh(ColorMap)); - }; - int Icon_Count(void) const - { - return (le16toh(Count)); - }; - int Pixel_Width(void) const - { - return (le16toh(Width)); - }; - int Pixel_Height(void) const - { - return (le16toh(Height)); - }; - int Total_Size(void) const - { - return (le32toh(Size)); - }; - unsigned char const* Palette_Data(void) const - { - return ((unsigned char const*)this + le32toh(Palettes)); - }; - unsigned char* Palette_Data(void) - { - return ((unsigned char*)this + le32toh(Palettes)); - }; - unsigned char const* Icon_Data(void) const - { - return ((unsigned char const*)this + le32toh(Icons)); - }; - unsigned char* Icon_Data(void) - { - return ((unsigned char*)this + le32toh(Icons)); - }; - unsigned char const* Map_Data(void) const - { - return ((unsigned char const*)this + le32toh(Map)); - }; - unsigned char* Map_Data(void) - { - return ((unsigned char*)this + le32toh(Map)); - }; - unsigned char const* Remap_Data(void) const - { - return ((unsigned char const*)this + le32toh(Remaps)); - }; - unsigned char* Remap_Data(void) - { - return ((unsigned char*)this + le32toh(Remaps)); - }; - unsigned char const* Trans_Data(void) const - { - return ((unsigned char const*)this + le32toh(TransFlag)); - }; - unsigned char* Trans_Data(void) - { - return ((unsigned char*)this + le32toh(TransFlag)); - }; - - /* - ** Disallow these operations with an IconsetClass object. - */ -private: - IconsetClass& operator=(IconsetClass const&); - IconsetClass(void); - static void* operator new(size_t) noexcept; -}; - #endif diff --git a/redalert/iconset.cpp b/redalert/iconset.cpp deleted file mode 100644 index 6aca6095..00000000 --- a/redalert/iconset.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// -// Copyright 2020 Electronic Arts Inc. -// -// TiberianDawn.DLL and RedAlert.dll and corresponding source code 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 3 of the License, or (at your option) any later version. - -// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed -// in the hope that it will be useful, but with permitted additional restrictions -// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT -// distributed with this program. You should have received a copy of the -// GNU General Public License along with permitted additional restrictions -// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection - -/*************************************************************************** - ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S ** - *************************************************************************** - * * - * Project Name : Library * - * * - * File Name : ICONSET.C * - * * - * Programmer : Joe L. Bostic * - * * - * Start Date : June 9, 1991 * - * * - * Last Update : September 15, 1993 [JLB] * - * * - *-------------------------------------------------------------------------* - * Functions: * - * Load_Icon_Set -- Loads an icons set and initializes it. * - * Free_Icon_Set -- Frees allocations made by Load_Icon_Set(). * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -//#include "function.h" - -#include -#include -#include "common/wwstd.h" -#include "common/file.h" -#include "tile.h" -#include "common/iff.h" - -// Misc? ST - 1/3/2019 10:40AM -// extern int Misc; -int Misc; - -void* Load_Icon_Set(char const* filename, void* iconsetptr, int buffsize); -void Free_Icon_Set(void const* iconset); -int Get_Icon_Set_Size(void const* iconset); -int Get_Icon_Set_Width(void const* iconset); -int Get_Icon_Set_Height(void const* iconset); -void* Get_Icon_Set_Icondata(void const* iconset); -void* Get_Icon_Set_Trans(void const* iconset); -void* Get_Icon_Set_Remapdata(void const* iconset); -void* Get_Icon_Set_Palettedata(void const* iconset); -int Get_Icon_Set_Count(void const* iconset); -void* Get_Icon_Set_Map(void const* iconset); - -//#define ICON_PALETTE_BYTES 16 -//#define ICON_MAX 256 - -/*************************************************************************** -** The terrain is rendered by using icons. These are the buffers that hold -** the icon data, remap tables, and remap index arrays. -*/ -// PRIVATE char *IconPalette = NULL; // MCGA only. -// PRIVATE char *IconRemap = NULL; // MCGA only. - -int Get_Icon_Set_Size(void const* iconset) -{ - IControl_Type* icontrol; - int size = 0; - - icontrol = (IControl_Type*)iconset; - if (icontrol) { - size = le32toh(icontrol->Size); - } - return (size); -} - -int Get_Icon_Set_Width(void const* iconset) -{ - IControl_Type* icontrol; - int width = 0; - - icontrol = (IControl_Type*)iconset; - if (icontrol) { - width = le16toh(icontrol->Width); - } - return (width); -} - -int Get_Icon_Set_Height(void const* iconset) -{ - IControl_Type* icontrol; - int height = 0; - - icontrol = (IControl_Type*)iconset; - if (icontrol) { - height = le16toh(icontrol->Height); - } - return (height); -} - -void* Get_Icon_Set_Icondata(void const* iconset) -{ - IControl_Type* icontrol; - icontrol = (IControl_Type*)iconset; - if (icontrol) - return (Add_Long_To_Pointer(iconset, le32toh(icontrol->Icons))); - return (NULL); -} - -void* Get_Icon_Set_Trans(void const* iconset) -{ - IControl_Type* icontrol; - void* ptr = NULL; - - icontrol = (IControl_Type*)iconset; - if (icontrol) { - ptr = Add_Long_To_Pointer((void*)iconset, le32toh(icontrol->TransFlag)); - } - return (ptr); -} - -int Get_Icon_Set_Count(void const* iconset) -{ - IControl_Type* icontrol; - int count; - - icontrol = (IControl_Type*)iconset; - if (icontrol) { - count = le16toh(icontrol->Count); - } - return (count); -} - -void* Get_Icon_Set_Map(void const* iconset) -{ - IControl_Type* icontrol; - icontrol = (IControl_Type*)iconset; - if (icontrol) - return (Add_Long_To_Pointer(iconset, le32toh(icontrol->Map))); - return (NULL); -} diff --git a/redalert/jshell.cpp b/redalert/jshell.cpp index f5d7582b..64ee6c72 100644 --- a/redalert/jshell.cpp +++ b/redalert/jshell.cpp @@ -68,8 +68,9 @@ void* Small_Icon(void const* iconptr, int iconnum) unsigned char* data; if (iconptr) { - iconnum = ((char*)((char*)iptr + iptr->Map))[iconnum]; - data = &((unsigned char*)((unsigned char*)iptr + iptr->Icons))[iconnum * (24 * 24)]; + iconnum = ((char*)Get_Icon_Set_Map(iptr))[iconnum]; + // TODO these 24's need unhardcoding if Icon size is changed + data = &((unsigned char*)Get_Icon_Set_Icondata(iptr))[iconnum * (24 * 24)]; // data = &iptr->Icons[iconnum*(24*24)]; for (int index = 0; index < 9; index++) { diff --git a/redalert/radar.cpp b/redalert/radar.cpp index 6211ff4b..537692d3 100644 --- a/redalert/radar.cpp +++ b/redalert/radar.cpp @@ -1039,14 +1039,14 @@ void RadarClass::Plot_Radar_Pixel(CELL cell) icon = cellptr->Clear_Icon(); } - IconsetClass const* iconset = (IconsetClass const*)ptr; - unsigned char const* icondata = iconset->Icon_Data(); + unsigned char const* icondata = (unsigned char const*)Get_Icon_Set_Icondata(ptr); + unsigned char const* map = (unsigned char const*)Get_Icon_Set_Map(ptr); /* ** Convert the logical icon number into the actual icon number. */ icon &= 0x00FF; - icon = *(iconset->Map_Data() + icon); + icon = map[icon]; unsigned char* data = (unsigned char*)icondata + icon * (24 * 24); Buffer_To_Page(0, 0, 24, 24, data, _TileStage); diff --git a/redalert/tile.h b/redalert/tile.h deleted file mode 100644 index 983807d3..00000000 --- a/redalert/tile.h +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2020 Electronic Arts Inc. -// -// TiberianDawn.DLL and RedAlert.dll and corresponding source code 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 3 of the License, or (at your option) any later version. - -// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed -// in the hope that it will be useful, but with permitted additional restrictions -// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT -// distributed with this program. You should have received a copy of the -// GNU General Public License along with permitted additional restrictions -// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection - -/*************************************************************************** - ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S ** - *************************************************************************** - * * - * Project Name : Part of the TILE Library * - * * - * File Name : TILE.H * - * * - * Programmer : Barry W. Green * - * * - * Start Date : February 2, 1995 * - * * - * Last Update : February 2, 1995 [BWG] * - * * - *-------------------------------------------------------------------------* - * Functions: * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#ifndef TILE_H -#define TILE_H - -/*=========================================================================*/ -/* The following prototypes are for the file: ICONSET.CPP */ -/*=========================================================================*/ -int Get_Icon_Set_Size(void const* iconset); -int Get_Icon_Set_Width(void const* iconset); -int Get_Icon_Set_Height(void const* iconset); -void* Get_Icon_Set_Icondata(void const* iconset); -void* Get_Icon_Set_Trans(void const* iconset); -void* Get_Icon_Set_Remapdata(void const* iconset); -void* Get_Icon_Set_Palettedata(void const* iconset); -int Get_Icon_Set_Count(void const* iconset); -void* Get_Icon_Set_Map(void const* iconset); - -/* -** This is the control structure at the start of a loaded icon set. It must match -** the structure in WWLIB.I! This structure MUST be a multiple of 16 bytes long. -*/ - -// RA version of struct -#pragma pack(push, 2) -typedef struct -{ - uint16_t Width; // Width of icons (pixels). - uint16_t Height; // Height of icons (pixels). - uint16_t Count; // Number of (logical) icons in this set. - uint16_t Allocated; // Was this iconset allocated? - uint16_t MapWidth; // Width of map (in icons). - uint16_t MapHeight; // Height of map (in icons). - int32_t Size; // Size of entire iconset memory block. - int32_t Icons; // Offset from buffer start to icon data. - int32_t Palettes; // Offset from buffer start to palette data. - int32_t Remaps; // Offset from buffer start to remap index data. - int32_t TransFlag; // Offset for transparency flag table. - int32_t ColorMap; // Offset for color control value table. - int32_t Map; // Icon map offset (if present). -} IControl_Type; -#pragma pack(pop) - -#endif // TILE_H diff --git a/tiberiandawn/CMakeLists.txt b/tiberiandawn/CMakeLists.txt index a26cf467..d8af8b5f 100644 --- a/tiberiandawn/CMakeLists.txt +++ b/tiberiandawn/CMakeLists.txt @@ -50,7 +50,6 @@ set(TIBDAWN_SRC heap.cpp help.cpp house.cpp - iconset.cpp idata.cpp infantry.cpp init.cpp diff --git a/tiberiandawn/jshell.cpp b/tiberiandawn/jshell.cpp index e3dc221f..e9b85750 100644 --- a/tiberiandawn/jshell.cpp +++ b/tiberiandawn/jshell.cpp @@ -71,8 +71,9 @@ void* Small_Icon(void const* iconptr, int iconnum) unsigned char* data; if (iconptr) { - iconnum = ((char*)((char*)iptr + iptr->Map))[iconnum]; - data = &((unsigned char*)((unsigned char*)iptr + iptr->Icons))[iconnum * (24 * 24)]; + iconnum = ((char*)Get_Icon_Set_Map(iptr))[iconnum]; + // TODO these 24's need unhardcoding if Icon size is changed + data = &((unsigned char*)Get_Icon_Set_Icondata(iptr))[iconnum * (24 * 24)]; // data = &iptr->Icons[iconnum*(24*24)]; for (int index = 0; index < 9; index++) {