diff --git a/code/REDALERT/CDATA.CPP b/code/REDALERT/CDATA.CPP index 06cdfc4..962930a 100644 --- a/code/REDALERT/CDATA.CPP +++ b/code/REDALERT/CDATA.CPP @@ -46,7 +46,7 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #include "function.h" - +#include "image.h" static TemplateTypeClass const Empty( TEMPLATE_CLEAR1, @@ -3137,7 +3137,16 @@ void TemplateTypeClass::Init(TheaterType theater) ((unsigned char &)tplate.Width) = Get_IconSet_MapWidth(ptr); ((unsigned char &)tplate.Height) = Get_IconSet_MapHeight(ptr); + // Try and load HD assets first. + Image_t *hdImage = Load_StampHD(Theaters[theater].Name, fullname, tplate.ImageData); + if (hdImage) { + Get_Stamp_Size(tplate.ImageData, hdImage->renderwidth, hdImage->renderheight); + ((void const*&)tplate.HDImageData) = hdImage; + } + else + { + // If no HD assets, load the legacy assets into a texture. char tmp[512]; sprintf(tmp, "icon_%s", fullname); ((void const*&)tplate.HDImageData) = Load_Stamp(fullname, tplate.ImageData); diff --git a/code/REDALERT/Image.h b/code/REDALERT/Image.h index 9c01ed8..fe5302f 100644 --- a/code/REDALERT/Image.h +++ b/code/REDALERT/Image.h @@ -21,6 +21,7 @@ struct Image_t { __forceinline Image_t::Image_t() { IconMapPtr = NULL; numAnimFrames = 0; + memset(image, 0, sizeof(image)); } __forceinline Image_t::~Image_t() { @@ -29,4 +30,5 @@ __forceinline Image_t::~Image_t() { Image_t* Image_LoadImage(const char* name, bool loadAnims = false, bool loadHouseColor = false); Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsigned char* data, unsigned char *remap = NULL); Image_t* Find_Image(const char* name); -void Image_Add8BitImage(Image_t* image, int HouseId, int ShapeID, int Width, int Height, unsigned char* data, unsigned char* remap); \ No newline at end of file +void Image_Add8BitImage(Image_t* image, int HouseId, int ShapeID, int Width, int Height, unsigned char* data, unsigned char* remap); +bool Image_Add32BitImage(const char* name, Image_t* image, int HouseId, int ShapeID); \ No newline at end of file diff --git a/code/REDALERT/TDATA.CPP b/code/REDALERT/TDATA.CPP index 3dadc71..41c21bd 100644 --- a/code/REDALERT/TDATA.CPP +++ b/code/REDALERT/TDATA.CPP @@ -690,6 +690,14 @@ void TerrainTypeClass::Init(TheaterType theater) _makepath(fullname, NULL, NULL, terrain.IniName, Theaters[theater].Suffix); ((void const *&)terrain.ImageData) = MFCD::Retrieve(fullname); + // Try and load HD assets first. + Image_t* hdImage = Load_StampHD(Theaters[theater].Name, fullname, terrain.ImageData); + if (hdImage) + { + Get_Stamp_Size(terrain.ImageData, hdImage->renderwidth, hdImage->renderheight); + ((void const*&)terrain.HDImageData) = hdImage; + } + else { char tmp[512]; sprintf(tmp, "icon_%s", fullname); diff --git a/code/REDALERT/TILESET.CPP b/code/REDALERT/TILESET.CPP index a17da1d..6faa8c0 100644 --- a/code/REDALERT/TILESET.CPP +++ b/code/REDALERT/TILESET.CPP @@ -190,7 +190,81 @@ void __cdecl Buffer_Draw_Stamp2(GraphicViewPortClass& viewport, IconControlType* } } -struct Image_t *__cdecl Load_Stamp(const char *name, const void* icondata) +Image_t* Load_StampHD(const char* theaterName, const char* iconName, const void* icondata) { + char filename[2048]; + Image_t* image = NULL; + + IconControlType* tileset = (IconControlType*)icondata; + + if (!tileset) { + return NULL; + } + + if (LastIconset != tileset) { + Init_Stamps(tileset); + } + + // This is because were trying to avoid parsing the XML's and the filenames aren't consistant. + char* baseFileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d.DDS"; + char* fileNameTemplate = baseFileNameTemplate; + + for (int i = 0; i < IconCount; i++) + { + sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i); + if (image == NULL) { + image = Image_LoadImage(filename); + if (image == NULL) { + fileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d-0000.DDS"; + sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i); + image = Image_LoadImage(filename); + if (image == NULL) { + fileNameTemplate = "DATA/ART/TEXTURES/SRGB/RED_ALERT/TERRAIN/%s/%s/%s-%04d-00.DDS"; + sprintf(filename, fileNameTemplate, theaterName, iconName, iconName, i); + image = Image_LoadImage(filename); + if (image == NULL) { + fileNameTemplate = baseFileNameTemplate; // Restore back to the original template. + continue; + } + } + } + + //if (i != 0) { + // image->image[0][i] = image->image[0][0]; + // image->image[0][0] = 0; + //} + } + else { + if (!Image_Add32BitImage(filename, image, -1, i)) { + continue; + } + } + } + + //if (image) { + // image->IconMapPtr = MapPtr; + //} + + return image; +} + +void Get_Stamp_Size(const void* icondata, int& width, int& height) { + IconControlType* tileset = (IconControlType*)icondata; + + if (!tileset) { + width = -1; + height = -1; + return; + } + + if (LastIconset != tileset) { + Init_Stamps(tileset); + } + + width = IconWidth; + height = IconHeight; +} + +Image_t * Load_Stamp(const char *name, const void* icondata) { IconControlType* tileset = (IconControlType*)icondata; @@ -239,8 +313,8 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void uint8_t* MapPtr = (uint8_t * )iconImage->IconMapPtr; int icon_index = MapPtr != nullptr ? MapPtr[icon] : icon; { - int blit_height = IconHeight; - int blit_width = IconWidth; + int blit_height = iconImage->renderheight; + int blit_width = iconImage->renderwidth; int width = left + right; int xstart = left + x; @@ -320,6 +394,9 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void // src += IconWidth; //} + if (iconImage->image[0][icon_index] == 0) + return; + GL_SetClipRect(xstart, ystart, blit_width, blit_height); GL_RenderImage(iconImage, xstart, ystart, blit_width, blit_height, 0, icon_index); GL_ResetClipRect(); diff --git a/code/REDALERT/WIN32LIB/DRAWBUFF.H b/code/REDALERT/WIN32LIB/DRAWBUFF.H index 72ace4c..4ee36f6 100644 --- a/code/REDALERT/WIN32LIB/DRAWBUFF.H +++ b/code/REDALERT/WIN32LIB/DRAWBUFF.H @@ -61,7 +61,11 @@ extern "C" { void * __cdecl Get_Font_Palette_Ptr ( void ); } -struct Image_t* __cdecl Load_Stamp(const char* name, const void* icondata); +struct Image_t; + +Image_t* Load_Stamp(const char* name, const void* icondata); +void Get_Stamp_Size(const void* icondata, int &width, int &height); +Image_t* Load_StampHD(const char* theaterName, const char* iconName, const void *icondata); extern GraphicViewPortClass *LogicPage; extern BOOL AllowHardwareBlitFills; diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 7a9f856..71e7f2c 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -433,7 +433,9 @@ void Image_Add8BitImage(Image_t *image, int HouseId, int ShapeID, int Width, int delete buffer; } - +bool Image_Add32BitImage(const char *name, Image_t* image, int HouseId, int ShapeID) { + return Image_loadHDImage(image, name, HouseId, ShapeID, image->namehash, false); +} BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel) { // Todo implement resoluton scaling.