Added 32bit image(single frame) overrides for buildings. Image_t now stores raw pixel data.

This commit is contained in:
Justin Marshall
2020-06-16 07:25:15 -07:00
parent a8494d7de4
commit 19b6c46149
14 changed files with 273 additions and 37 deletions
+8 -2
View File
@@ -58,7 +58,7 @@
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
#include "Image.h"
#define FATSHIP
@@ -3356,7 +3356,13 @@ void BuildingTypeClass::Init(TheaterType theater)
if (classptr->IsTheater) {
_makepath(fullname, NULL, NULL, classptr->Graphic_Name(), Theaters[theater].Suffix);
((void const *&)classptr->ImageData) = MFCD::Retrieve(fullname);
// jmarshall
{
char imageFileName[512];
sprintf(imageFileName, "textures/%s.png", fullname);
((BuildingTypeClass *)classptr)->HDImageData = Image_LoadImage(imageFileName);
}
// jmarshall end
/*
** Buildup data is probably theater specific as well. Fetch a pointer to the
** data at this time as well.
+15
View File
@@ -451,6 +451,14 @@ 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
@@ -5919,6 +5927,13 @@ void const * BuildingClass::Get_Image_Data(void) const
return(TechnoClass::Get_Image_Data());
}
struct Image_t *BuildingClass::Get_HDImage_Data(void) const
{
if (BState == BSTATE_CONSTRUCTION) {
return NULL;
}
return(TechnoClass::Get_HDImage_Data());
}
/***********************************************************************************************
* BuildingClass::Value -- Determine the value of this building. *
+3
View File
@@ -236,6 +236,9 @@ class BuildingClass : public TechnoClass
*/
virtual int Value(void) const;
virtual void const * Get_Image_Data(void) const;
// jmarshall
struct Image_t* BuildingClass::Get_HDImage_Data(void) const;
// jmarshall end
virtual int How_Many_Survivors(void) const;
virtual DirType Turret_Facing(void) const;
virtual CELL Find_Exit_Cell(TechnoClass const * techno) const;
+135
View File
@@ -105,6 +105,7 @@ TcpipManagerClass Winsock;
#include "vortex.h"
#include "VQAMOVIE.H"
#include "AUDIOMIX.H"
#include "image.h"
#ifdef WOLAPI_INTEGRATION
//#include "WolDebug.h"
@@ -3469,6 +3470,140 @@ void CC_Draw_Pip(const ObjectClass *object, void const * shapefile, int shapenum
CC_Draw_Shape(shapefile, shapenum, x, y, window, flags, fadingdata, ghostdata, rotation);
}
// jmarshall - this is for hd textures
void CC_Draw_Shape(Image_t* image, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const* fadingdata, void const* ghostdata, DirType rotation) {
int predoffset;
/*
** Special kludge for E3 to prevent crashes
*/
if ((flags & SHAPE_GHOST) && (!ghostdata)) {
ghostdata = DisplayClass::SpecialGhost;
}
if ((flags & SHAPE_FADING) && (!fadingdata)) {
fadingdata = DisplayClass::FadingShade;
}
static unsigned char* _xbuffer = 0;
if (!_xbuffer) {
_xbuffer = new unsigned char[SHAPE_BUFFER_SIZE];
}
if (image != NULL && shapenum != -1) {
int width = image->width;
int height = image->height;
#ifdef NEVER
/*
** Perform a quick clip check against the destination rectangle.
*/
if (flags & SHAPE_CENTER) {
if (x - width / 2 >= WindowList[window][WINDOWWIDTH]) return;
if (y - width / 2 >= WindowList[window][WINDOWHEIGHT]) return;
if (x + width / 2 < 0) return;
if (y + height / 2 < 0) return;
}
else {
if (x >= WindowList[window][WINDOWWIDTH]) return;
if (y >= WindowList[window][WINDOWHEIGHT]) return;
if (x + width < 0) return;
if (y + height < 0) return;
}
#endif
{
//GraphicViewPortClass draw_window(LogicPage->Get_Graphic_Buffer(),
// WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
// WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
// WindowList[window][WINDOWWIDTH],
// WindowList[window][WINDOWHEIGHT]);
UseOldShapeDraw = false;
/*
** Rotation handler.
*/
// jmarshall: todo HD rotation code!
// if (rotation != DIR_N) {
//
// /*
// ** Get the raw shape data without the new header and flag to use the old shape drawing
// */
// UseOldShapeDraw = true;
//
// if (Debug_Rotate) {
//#if (0)//PG
// GraphicBufferClass src(width, height, buffer);
// width *= 2;
// height *= 2;
// memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
// GraphicBufferClass dst(width, height, _xbuffer);
// Rotate_Bitmap(&src, &dst, rotation);
// buffer = _xbuffer;
//#endif
// }
// else {
//
// BitmapClass bm(width, height, buffer);
// width *= 2;
// height *= 2;
// memset(_xbuffer, '\0', SHAPE_BUFFER_SIZE);
// GraphicBufferClass gb(width, height, _xbuffer);
// TPoint2D pt(width / 2, height / 2);
//
// gb.Scale_Rotate(bm, pt, 0x0100, (256 - (rotation - 64)));
// buffer = _xbuffer;
// }
// }
// jmarshall end
/*
** Special shadow drawing code (used for aircraft and bullets).
*/
if ((flags & (SHAPE_FADING | SHAPE_PREDATOR)) == (SHAPE_FADING | SHAPE_PREDATOR)) {
flags = flags & ~(SHAPE_FADING | SHAPE_PREDATOR);
flags = flags | SHAPE_GHOST;
ghostdata = DisplayClass::SpecialGhost;
}
predoffset = Frame;
//if (x > ( WindowList[window][WINDOWWIDTH] << 2)) {
// predoffset = -predoffset;
//}
x = x + WindowList[window][WINDOWX] + LogicPage->Get_XPos();
y = y + WindowList[window][WINDOWY] + LogicPage->Get_YPos();
Buffer_Enable_HD_Texture(true);
//if (draw_window.Lock()) {
if ((flags & (SHAPE_GHOST | SHAPE_FADING)) == (SHAPE_GHOST | SHAPE_FADING)) {
Buffer_Frame_To_Page(x, y, width, height, image, HiddenPage, flags | SHAPE_TRANS, ghostdata, fadingdata, 1, predoffset);
}
else {
if (flags & SHAPE_FADING) {
Buffer_Frame_To_Page(x, y, width, height, image, HiddenPage, flags | SHAPE_TRANS, fadingdata, 1, predoffset);
}
else {
if (flags & SHAPE_PREDATOR) {
Buffer_Frame_To_Page(x, y, width, height, image, HiddenPage, flags | SHAPE_TRANS, predoffset);
}
else {
Buffer_Frame_To_Page(x, y, width, height, image, HiddenPage, flags | SHAPE_TRANS, ghostdata, predoffset);
}
}
}
// draw_window.Unlock();
//}
Buffer_Enable_HD_Texture(false);
}
}
}
// jmarshall end
/***********************************************************************************************
* CC_Draw_Shape -- Custom draw shape handler. *
+3
View File
@@ -549,6 +549,7 @@ void CC_Draw_Shape(void const * shapefile, int shapenum, int x, int y, WindowNum
// Added for draw intercept. ST - 1/17/2019 12:31PM
void CC_Draw_Shape(const ObjectClass *object, void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata = 0, void const * ghostdata = 0, DirType rotation = DIR_N, long virtualscale = 0x0100);
void CC_Draw_Shape(Image_t *image, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const* fadingdata, void const* ghostdata, DirType rotation);
void CC_Draw_Shape(const ObjectClass *object, const char *shape_file_name, void const * shapefile, int shapenum, int x, int y, WindowNumberType window, ShapeFlags_Type flags, void const * fadingdata = 0, void const * ghostdata = 0, DirType rotation = DIR_N, long virtualscale = 0x0100, char override_owner = HOUSE_NONE);
// Added for pip draw intercept - SKY
@@ -704,6 +705,8 @@ void *Build_Translucent_Table(PaletteClass const & palette, TLucentType const *c
void *Conquer_Build_Translucent_Table(PaletteClass const & palette, TLucentType const *control, int count, void *buffer);
void * Make_Fading_Table(PaletteClass const & palette, void * dest, int color, int frac);
void Buffer_Enable_HD_Texture(bool hdTextureEnabled);
/*
** KEYFBUFF.ASM
*/
+15
View File
@@ -2,10 +2,25 @@
//
struct Image_t {
Image_t();
~Image_t();
char name[512];
unsigned int image;
int width;
int height;
unsigned char* buffer;
};
__forceinline Image_t::Image_t() {
buffer = NULL;
}
__forceinline Image_t::~Image_t() {
if (buffer) {
delete buffer;
buffer = NULL;
}
}
Image_t* Image_LoadImage(const char* name);
+1 -11
View File
@@ -517,17 +517,7 @@ bool WWKeyboardClass::Is_Buffer_Empty(void) const
*=============================================================================================*/
void WWKeyboardClass::Fill_Buffer_From_System(void)
{
//if (!Is_Buffer_Full())
//{
// MSG msg;
// while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
// if (!GetMessage( &msg, NULL, 0, 0 )) {
// return;
// }
// TranslateMessage(&msg);
// DispatchMessage(&msg);
// }
//}
}
+5
View File
@@ -164,6 +164,11 @@ void const * ObjectClass::Get_Image_Data(void) const
return(Class_Of().Get_Image_Data());
}
struct Image_t *ObjectClass::Get_HDImage_Data(void) const
{
return(Class_Of().Get_HDImage_Data());
}
/***********************************************************************************************
* ObjectClass::Name -- Fetches the identification name of this object. *
+1
View File
@@ -152,6 +152,7 @@ class ObjectClass : public AbstractClass
*/
virtual bool Is_Players_Army(void) const {return(false);}
virtual void const * Get_Image_Data(void) const;
virtual struct Image_t *Get_HDImage_Data(void) const;
virtual ActionType What_Action(ObjectClass const *) const;
virtual ActionType What_Action(CELL) const;
virtual LayerType In_Which_Layer(void) const;
+64 -20
View File
@@ -32,6 +32,8 @@
#include <cstdarg>
#include <cstring>
#include "Image.h"
#define le16toh(x) x
#define le32toh(x) x
@@ -99,6 +101,13 @@ static uint8_t* g_PredatorLimit = nullptr;
typedef void (*BF_Function)(int, int, uint8_t*, uint8_t*, int, int, uint8_t*, uint8_t*, uint8_t*, int);
typedef void (*Single_Line_Function)(int, uint8_t*, uint8_t*, uint8_t*, uint8_t*, uint8_t*, int);
static bool renderHDTexture = false;
void Buffer_Enable_HD_Texture(bool hdTextureEnabled) {
renderHDTexture = hdTextureEnabled;
}
#define ChannelBlend_Alpha(A,B,O) ((uint8_t)((O / 255.0f) * A + (1 - (O / 255.0f)) * B))
// Just copy source to dest as is.
void BF_Copy(int width, int height, uint8_t* dst, uint8_t* src, int dst_pitch, int src_pitch, uint8_t* ghost_lookup,
uint8_t* ghost_tab, uint8_t* fade_tab, int count)
@@ -120,12 +129,12 @@ void BF_Trans(int width, int height, uint8_t* dst, uint8_t* src, int dst_pitch,
if (sbyte) {
dst[0] = backbuffer_palette[(sbyte * 3) + 0];
dst[1] = backbuffer_palette[(sbyte * 3) + 1];
dst[2] = backbuffer_palette[(sbyte * 3) + 2];
dst[3] = 255;
dst[1] = backbuffer_palette[(sbyte * 3) + 1];
dst[2] = backbuffer_palette[(sbyte * 3) + 2];
dst[3] = 255;
}
dst+=4;
dst += 4;
}
src += src_pitch;
@@ -1394,19 +1403,22 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap
uint8_t* frame_data = static_cast<uint8_t*>(shape);
if (UseOldShapeDraw) {
use_old_drawer = true;
}
else if (UseBigShapeBuffer) {
draw_header = static_cast<ShapeBufferHeader*>(shape);
uint8_t* shape_buff = reinterpret_cast<uint8_t*>(BigShapeBufferStart);
if (draw_header->m_IsTheaterShape) {
shape_buff = reinterpret_cast<uint8_t*>(TheaterShapeBufferStart);
if (!renderHDTexture)
{
if (UseOldShapeDraw) {
use_old_drawer = true;
}
else if (UseBigShapeBuffer) {
draw_header = static_cast<ShapeBufferHeader*>(shape);
uint8_t* shape_buff = reinterpret_cast<uint8_t*>(BigShapeBufferStart);
frame_data = shape_buff + draw_header->m_FrameOffset;
use_old_drawer = false;
if (draw_header->m_IsTheaterShape) {
shape_buff = reinterpret_cast<uint8_t*>(TheaterShapeBufferStart);
}
frame_data = shape_buff + draw_header->m_FrameOffset;
use_old_drawer = false;
}
}
va_list ap;
@@ -1435,8 +1447,10 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap
use_old_drawer = true;
}
if (use_old_drawer != true && (draw_header->m_DrawFlags == 0xFFFFFFFF || draw_header->m_DrawFlags != (flags & 0x1340))) {
Single_Line_Flagger(width, height, frame_data, draw_header, flags, ghost_table, ghost_lookup);
if (!renderHDTexture) {
if (use_old_drawer != true && (draw_header->m_DrawFlags == 0xFFFFFFFF || draw_header->m_DrawFlags != (flags & 0x1340))) {
Single_Line_Flagger(width, height, frame_data, draw_header, flags, ghost_table, ghost_lookup);
}
}
// Sets for BF_Fading functions
@@ -1519,11 +1533,16 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap
int pitch = viewport.Get_Full_Pitch();
uint8_t* dst = (ystart * pitch * 4) + (xstart * 4) + (uint8_t*)(viewport.Get_Offset());
uint8_t* src = frame_data + ms_img_offset;
if (renderHDTexture) {
Image_t* image = (Image_t*)shape;
src = image->buffer + (ms_img_offset * 4);
}
int dst_pitch = pitch - blit_width;
int src_pitch = width - blit_width;
// Use "new" line drawing routines that appear to have been added during the windows port.
if (use_old_drawer != true) {
if (use_old_drawer != true && !renderHDTexture) {
// DEBUG_SAY("Drawing with Single_Line draw functions\n");
// Here we can use the individual line drawing routines
@@ -1544,8 +1563,33 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap
// using the appropriate effects.
if (blit_height > 0 && blit_width > 0) {
// DEBUG_SAY("Drawing with BF draw functions\n");
OldShapeJumpTable[blit_style & 0xF](
blit_width, blit_height, dst, src, dst_pitch, src_pitch, ghost_lookup, ghost_table, fade_table, fade_count);
if (!renderHDTexture)
{
OldShapeJumpTable[blit_style & 0xF](blit_width, blit_height, dst, src, dst_pitch, src_pitch, ghost_lookup, ghost_table, fade_table, fade_count);
}
else
{
int src_index = 0;
for (int f = 0; f < height; f++)
{
for (int i = width; i > 0; --i) {
//if (src_index >= ((f + 1) * blit_height * 4))
// break;
if (src[src_index + 3] > 0) {
dst[0] = ChannelBlend_Alpha(src[(src_index) + 0], dst[0], src[(src_index) + 3]);
dst[1] = ChannelBlend_Alpha(src[(src_index) + 1], dst[1], src[(src_index) + 3]);
dst[2] = ChannelBlend_Alpha(src[(src_index) + 2], dst[2], src[(src_index) + 3]);
dst[3] = 255;
}
src_index += 4;
dst += 4;
}
src_index += src_pitch * 4;
dst += dst_pitch * 4;
}
}
}
return 0;
+7
View File
@@ -4450,6 +4450,13 @@ VisualType TechnoClass::Visual_Character(bool raw) const
return(VISUAL_HIDDEN);
}
void TechnoClass::Techno_Draw_Object_HD(struct Image_t* image, int shapenum, int x, int y, WindowNumberType window, DirType rotation, int scale) const {
void const* remap = Remap_Table();
void const* shadow = Map.UnitShadow;
y -= Lepton_To_Pixel(Height);
CC_Draw_Shape(image, shapenum, x, y, window, SHAPE_CENTER | SHAPE_WIN_REL | SHAPE_FADING | SHAPE_GHOST, remap, shadow, rotation);
}
/***********************************************************************************************
* TechnoClass::Techno_Draw_Object -- General purpose draw object routine. *
+3
View File
@@ -369,6 +369,9 @@ class TechnoClass : public RadioClass,
virtual void const * Remap_Table(void) const;
VisualType Visual_Character(bool raw = false) const;
void Techno_Draw_Object(void const * shapefile, int shapenum, int x, int y, WindowNumberType window, DirType rotation=DIR_N, int scale=0x0100) const;
// jmarshall
void Techno_Draw_Object_HD(struct Image_t* image, int shapenum, int x, int y, WindowNumberType window, DirType rotation = DIR_N, int scale = 0x0100) const;
// jmarshall end
// Added. ST - 8/1/2019 5:37PM
void Techno_Draw_Object_Virtual(void const * shapefile, int shapenum, int x, int y, WindowNumberType window, DirType rotation=DIR_N, int scale=0x0100, const char *shape_name = NULL) const;
+6 -1
View File
@@ -257,7 +257,9 @@ class ObjectTypeClass : public AbstractTypeClass
** The "mutable" keyword allows easy modification to this otherwise const object.
*/
void const * ImageData;
// jmarshall
struct Image_t *HDImageData;
// jmarshall end
/*
** Points to the dimension data for each shape in the image list. By using this
** data, the minimum number of cells will be redrawn when the object changes shape.
@@ -298,6 +300,9 @@ class ObjectTypeClass : public AbstractTypeClass
virtual short const * Overlap_List(void) const;
virtual BuildingClass * Who_Can_Build_Me(bool intheory, bool legal, HousesType house) const;
virtual void const * Get_Cameo_Data(void) const;
// jmarshall
struct Image_t* Get_HDImage_Data(void) const { return HDImageData; }
// jmarshall end
void const * Get_Image_Data(void) const {return ImageData;};
void const * Get_Radar_Data(void) const {return RadarIcon;};
+7 -3
View File
@@ -100,6 +100,7 @@ Image_t* Image_LoadImage(const char* name) {
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
if (!ilLoadImage(name)) {
ilDeleteImages(1, &ImageName);
return NULL;
}
@@ -127,16 +128,19 @@ Image_t* Image_LoadImage(const char* name) {
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
ilDeleteImages(1, &ImageName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Image_t* image = new Image_t();
strcpy(image->name, name);
image->image = texture;
image->width = Width;
image->height = Height;
image->buffer = new unsigned char[Width * Height * Bpp];
memcpy(image->buffer, Data, Width * Height * Bpp);
loaded_images.push_back(image);
ilDeleteImages(1, &ImageName);
return image;
}