mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-21 18:35:04 +02:00
Initial HD stamp loading code.
This commit is contained in:
+10
-1
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
@@ -30,3 +31,4 @@ Image_t* Image_LoadImage(const char* name, bool loadAnims = false, bool loadHous
|
||||
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);
|
||||
bool Image_Add32BitImage(const char* name, Image_t* image, int HouseId, int ShapeID);
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user