Initial HD stamp loading code.

This commit is contained in:
Justin Marshall
2020-06-20 14:31:11 -07:00
parent 2ba8a7a2dd
commit 79b24cb81d
6 changed files with 109 additions and 7 deletions
+10 -1
View File
@@ -46,7 +46,7 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h" #include "function.h"
#include "image.h"
static TemplateTypeClass const Empty( static TemplateTypeClass const Empty(
TEMPLATE_CLEAR1, TEMPLATE_CLEAR1,
@@ -3137,7 +3137,16 @@ void TemplateTypeClass::Init(TheaterType theater)
((unsigned char &)tplate.Width) = Get_IconSet_MapWidth(ptr); ((unsigned char &)tplate.Width) = Get_IconSet_MapWidth(ptr);
((unsigned char &)tplate.Height) = Get_IconSet_MapHeight(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]; char tmp[512];
sprintf(tmp, "icon_%s", fullname); sprintf(tmp, "icon_%s", fullname);
((void const*&)tplate.HDImageData) = Load_Stamp(fullname, tplate.ImageData); ((void const*&)tplate.HDImageData) = Load_Stamp(fullname, tplate.ImageData);
+3 -1
View File
@@ -21,6 +21,7 @@ struct Image_t {
__forceinline Image_t::Image_t() { __forceinline Image_t::Image_t() {
IconMapPtr = NULL; IconMapPtr = NULL;
numAnimFrames = 0; numAnimFrames = 0;
memset(image, 0, sizeof(image));
} }
__forceinline Image_t::~Image_t() { __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_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* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsigned char* data, unsigned char *remap = NULL);
Image_t* Find_Image(const char* name); 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); 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);
+8
View File
@@ -690,6 +690,14 @@ void TerrainTypeClass::Init(TheaterType theater)
_makepath(fullname, NULL, NULL, terrain.IniName, Theaters[theater].Suffix); _makepath(fullname, NULL, NULL, terrain.IniName, Theaters[theater].Suffix);
((void const *&)terrain.ImageData) = MFCD::Retrieve(fullname); ((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]; char tmp[512];
sprintf(tmp, "icon_%s", fullname); sprintf(tmp, "icon_%s", fullname);
+80 -3
View File
@@ -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; 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; uint8_t* MapPtr = (uint8_t * )iconImage->IconMapPtr;
int icon_index = MapPtr != nullptr ? MapPtr[icon] : icon; int icon_index = MapPtr != nullptr ? MapPtr[icon] : icon;
{ {
int blit_height = IconHeight; int blit_height = iconImage->renderheight;
int blit_width = IconWidth; int blit_width = iconImage->renderwidth;
int width = left + right; int width = left + right;
int xstart = left + x; int xstart = left + x;
@@ -320,6 +394,9 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void
// src += IconWidth; // src += IconWidth;
//} //}
if (iconImage->image[0][icon_index] == 0)
return;
GL_SetClipRect(xstart, ystart, blit_width, blit_height); GL_SetClipRect(xstart, ystart, blit_width, blit_height);
GL_RenderImage(iconImage, xstart, ystart, blit_width, blit_height, 0, icon_index); GL_RenderImage(iconImage, xstart, ystart, blit_width, blit_height, 0, icon_index);
GL_ResetClipRect(); GL_ResetClipRect();
+5 -1
View File
@@ -61,7 +61,11 @@ extern "C" {
void * __cdecl Get_Font_Palette_Ptr ( void ); 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 GraphicViewPortClass *LogicPage;
extern BOOL AllowHardwareBlitFills; extern BOOL AllowHardwareBlitFills;
+3 -1
View File
@@ -433,7 +433,9 @@ void Image_Add8BitImage(Image_t *image, int HouseId, int ShapeID, int Width, int
delete buffer; 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) { BOOL Set_Video_Mode(HWND hwnd, int w, int h, int bits_per_pixel) {
// Todo implement resoluton scaling. // Todo implement resoluton scaling.