War Factory renders more correctly.

This commit is contained in:
Justin Marshall
2020-06-24 08:21:50 -07:00
parent 61ca0cfa5a
commit cc449351d2
3 changed files with 89 additions and 54 deletions
+67 -43
View File
@@ -2759,6 +2759,7 @@ static BuildingTypeClass const ClassLarva2(
);
#endif
void const * BuildingTypeClass::WarFactoryOverlay;
Image_t* BuildingTypeClass::WarFactoryHDOverlay;
void const * LightningShapes;
@@ -3034,6 +3035,47 @@ void BuildingTypeClass::Init_Heap(void)
#endif
}
Image_t* BuildingTypeClass::LoadHDImage(const char* fullname, int& numHDShapes) {
const char* imageFileName = Buildings_FindHDTexture(fullname, 0, 0);
Image_t* image = NULL;
numHDShapes = -1;
if (imageFileName) {
image = Image_LoadImage(imageFileName, true, true);
int numBuildingAnims = Buildings_GetNumFramesForTile(fullname, 0);
int shapeId = 1;
// Load the old school animation pipeline.
{
while (true) {
imageFileName = Buildings_FindHDTexture(fullname, shapeId, 0);
if (imageFileName == NULL)
break;
for (int d = 0; d < MAX_MPLAYER_COLORS; d++) {
Image_Add32BitImage(imageFileName, image, d, shapeId, 0);
}
shapeId++;
}
}
if (numBuildingAnims > 0)
{
for (int i = 1; i < numBuildingAnims; i++) {
imageFileName = Buildings_FindHDTexture(fullname, 0, i);
for (int d = 0; d < MAX_MPLAYER_COLORS; d++) {
Image_Add32BitImage(imageFileName, image, d, 0, i);
}
}
}
image->numFrames = numBuildingAnims;
numHDShapes = shapeId;
}
return image;
}
/***********************************************************************************************
* BuildingTypeClass::One_Time -- Performs special one time action for buildings. *
@@ -3135,63 +3177,45 @@ void BuildingTypeClass::One_Time(void)
building.Init_Anim(BSTATE_CONSTRUCTION, 0, count, timedelay);
}
int numhdimages = 0;
/*
** Fetch the normal game shape for this building.
*/
_makepath(fullname, NULL, NULL, building.Graphic_Name(), ".SHP");
((void const *&)building.ImageData) = MFCD::Retrieve(fullname);
{
const char* imageFileName = Buildings_FindHDTexture(fullname, 0, 0);
((void const*&)building.HDImageData) = LoadHDImage(fullname, numhdimages);
if (imageFileName) {
Image_t *image = Image_LoadImage(imageFileName, true, true);
int numBuildingAnims = Buildings_GetNumFramesForTile(fullname, 0);
int shapeId = 1;
if (building.ImageData != NULL && building.HDImageData != NULL) {
int width = Get_Build_Frame_Width(building.ImageData);
int height = Get_Build_Frame_Height(building.ImageData);
// Load the old school animation pipeline.
{
while (true) {
imageFileName = Buildings_FindHDTexture(fullname, shapeId, 0);
if (imageFileName == NULL)
break;
for (int d = 0; d < MAX_MPLAYER_COLORS; d++) {
Image_Add32BitImage(imageFileName, image, d, shapeId, 0);
}
shapeId++;
}
}
if (numBuildingAnims > 0)
{
for (int i = 1; i < numBuildingAnims; i++) {
imageFileName = Buildings_FindHDTexture(fullname, 0, i);
for (int d = 0; d < MAX_MPLAYER_COLORS; d++) {
Image_Add32BitImage(imageFileName, image, d, 0, i);
}
}
}
image->numFrames = numBuildingAnims;
((void const*&)building.HDImageData) = image;
if (building.ImageData != NULL && building.HDImageData != NULL) {
int width = Get_Build_Frame_Width(building.ImageData);
int height = Get_Build_Frame_Height(building.ImageData);
for (int d = 0; d < shapeId; d++)
{
building.HDImageData->renderwidth[d] = width;
building.HDImageData->renderheight[d] = height;
}
}
}
for (int d = 0; d < numhdimages; d++)
{
building.HDImageData->renderwidth[d] = width;
building.HDImageData->renderheight[d] = height;
}
}
}
int specialNumHDImages = 0;
// Try to load weap2.shp and tesla coil's lightning shapes
char fullname[_MAX_FNAME+_MAX_EXT];
_makepath(fullname, NULL, NULL, (char const *)"WEAP2",".SHP");
WarFactoryOverlay = MFCD::Retrieve(fullname);
WarFactoryHDOverlay = LoadHDImage(fullname, specialNumHDImages);
if (WarFactoryOverlay != NULL && WarFactoryHDOverlay != NULL) {
int width = Get_Build_Frame_Width(WarFactoryOverlay);
int height = Get_Build_Frame_Height(WarFactoryOverlay);
for (int d = 0; d < specialNumHDImages; d++)
{
WarFactoryHDOverlay->renderwidth[d] = width;
WarFactoryHDOverlay->renderheight[d] = height;
}
}
_makepath(fullname, NULL, NULL, (char const *)"LITNING",".SHP");
LightningShapes = MFCD::Retrieve(fullname);
+19 -11
View File
@@ -454,14 +454,8 @@ void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const
{
assert(Buildings.ID(this) == ID);
assert(IsActive);
// jmarshall
Image_t* hdimage = Get_HDImage_Data();
if (hdimage != NULL) {
Techno_Draw_Object_HD(hdimage, Shape_Number(), x, y, window);
TechnoClass::Draw_It(x, y, window);
return;
}
// jmarshall end
/*
** The shape file to use for rendering depends on whether the building
@@ -474,7 +468,14 @@ void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const
** Actually draw the building shape.
*/
IsTheaterShape = Class->IsTheater; //Let Build_Frame know if this is a theater specific shape
Techno_Draw_Object(shapefile, Shape_Number(), x, y, window);
// jmarshall - added HD support
if (hdimage != NULL) {
Techno_Draw_Object_HD(hdimage, Shape_Number(), x, y, window);
}
else {
Techno_Draw_Object(shapefile, Shape_Number(), x, y, window);
}
// jmarshall end
IsTheaterShape = false;
/*
@@ -504,9 +505,16 @@ void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const
if ( (*this == STRUCT_WEAP || *this == STRUCT_FAKEWEAP)) {
int shapenum = Door_Stage();
if (Health_Ratio() <= Rule.ConditionYellow) shapenum += 4;
// Added override shape file name. ST - 8/1/2019 5:24PM
//Techno_Draw_Object(Class->WarFactoryOverlay, shapenum, x, y, window);
Techno_Draw_Object_Virtual(Class->WarFactoryOverlay, shapenum, x, y, window, DIR_N, 0x0100, "WEAP2");
// jmarshall - added HD support.
if (Class->WarFactoryHDOverlay)
{
Techno_Draw_Object_HD(Class->WarFactoryHDOverlay, shapenum, x, y, window, DIR_N, 0x0100);
}
else
{
Techno_Draw_Object_Virtual(Class->WarFactoryOverlay, shapenum, x, y, window, DIR_N, 0x0100, "WEAP2");
}
// jmarshall end
}
/*
+3
View File
@@ -41,6 +41,7 @@
class MapEditClass;
class HouseClass;
class WeaponTypeClass;
struct Image_t;
/***************************************************************************
** This is the abstract type class. It holds information common to all
@@ -815,6 +816,7 @@ class BuildingTypeClass : public TechnoTypeClass {
** Special overlay for the weapons factory.
*/
static void const * WarFactoryOverlay;
static Image_t* WarFactoryHDOverlay;
private:
@@ -839,6 +841,7 @@ class BuildingTypeClass : public TechnoTypeClass {
void const * BuildupData;
void Init_Anim(BStateType state, int start, int count, int rate) const;
static Image_t* LoadHDImage(const char* fullname, int &numHDShapes);
};