diff --git a/code/REDALERT/CELL.CPP b/code/REDALERT/CELL.CPP index a8e0ed6..6d776c7 100644 --- a/code/REDALERT/CELL.CPP +++ b/code/REDALERT/CELL.CPP @@ -84,6 +84,11 @@ */ #include "SidebarGlyphx.h" +std::vector renderedFrameObjects; + +bool HasRenderedObject(const ObjectClass* technoClass) { + return std::find(renderedFrameObjects.begin(), renderedFrameObjects.end(), technoClass) != renderedFrameObjects.end(); +} /*********************************************************************************************** * CellClass::CellClass -- Constructor for cell objects. * @@ -993,8 +998,6 @@ bool CellClass::Get_Template_Info(char *template_name, int &icon, void *&image_d return false; } - - /*********************************************************************************************** * CellClass::Draw_It -- Draws the cell imagery at the location specified. * * * @@ -1088,7 +1091,7 @@ void CellClass::Draw_It(int x, int y, bool objects) const ** This is the underlying terrain icon. */ if (ttype->Get_Image_Data()) { - LogicPage->Draw_Stamp(ttype->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL); + LogicPage->Draw_Stamp(ttype, icon, x, y, NULL, WINDOW_TACTICAL); if (remap) { LogicPage->Remap(x+Map.TacPixelX, y+Map.TacPixelY, ICON_PIXEL_W, ICON_PIXEL_H, remap); } @@ -1210,7 +1213,9 @@ void CellClass::Draw_It(int x, int y, bool objects) const icon = (Cell_X(cell) - Cell_X(Map.ZoneCell + Map.ZoneOffset)) + (Cell_Y(cell) - Cell_Y(Map.ZoneCell + Map.ZoneOffset)) * tptr->Width; - LogicPage->Draw_Stamp(tptr->Get_Image_Data(), icon, x, y, NULL, WINDOW_TACTICAL); +// jmarshall - pass in raw tptr + LogicPage->Draw_Stamp(tptr, icon, x, y, NULL, WINDOW_TACTICAL); +// jmarshall end } break; @@ -1334,6 +1339,10 @@ void CellClass::Draw_It(int x, int y, bool objects) const */ for (int index = 0; index < count; index++) { object = optr[index]; + if (HasRenderedObject(object)) { + continue; + } + renderedFrameObjects.push_back(object); int xx,yy; if (object->IsToDisplay && (!object->Is_Techno() || ((TechnoClass *)object)->Visual_Character() == VISUAL_NORMAL) && Map.Coord_To_Pixel(object->Render_Coord(), xx, yy)) { if (_Calc_Partial_Window(x, y, xx, yy)) { diff --git a/code/REDALERT/CONQUER.CPP b/code/REDALERT/CONQUER.CPP index f8aaa77..b110b37 100644 --- a/code/REDALERT/CONQUER.CPP +++ b/code/REDALERT/CONQUER.CPP @@ -2121,8 +2121,8 @@ static void Sync_Delay(void) ** Delay until the frame timer expires. This forces the game loop to be regulated to a ** speed controlled by the game options slider. */ - while (FrameTimer) { - Color_Cycle(); + while (FrameTimer) { + Color_Cycle(); Call_Back(); if (SpecialDialog == SDLG_NONE) { @@ -2136,10 +2136,12 @@ static void Sync_Delay(void) Keyboard_Process(input); } Map.Render(); - } + } + } + if (!FrameTimer) { + Color_Cycle(); + Call_Back(); } - Color_Cycle(); - Call_Back(); } @@ -2321,8 +2323,7 @@ Mono_Set_Cursor(0,0); ** Keep track of elapsed time in the game. */ Score.ElapsedTime += TIMER_SECOND / TICKS_PER_SECOND; - - Call_Back(); + //Call_Back(); /* ** Check for player wins or loses according to global event flag. @@ -3580,24 +3581,21 @@ void CC_Draw_Shape(Image_t* image, int shapenum, int x, int y, WindowNumberType // 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); + Buffer_Frame_To_Page(x, y, width, height, image, window, 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); + Buffer_Frame_To_Page(x, y, width, height, image, window, 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); + Buffer_Frame_To_Page(x, y, width, height, image, window, flags | SHAPE_TRANS, predoffset); } else { - Buffer_Frame_To_Page(x, y, width, height, image, HiddenPage, flags | SHAPE_TRANS, ghostdata, predoffset); + Buffer_Frame_To_Page(x, y, width, height, image, window, flags | SHAPE_TRANS, ghostdata, predoffset); } } } @@ -3698,13 +3696,16 @@ void CC_Draw_Shape(void const * shapefile, int shapenum, int x, int y, WindowNum /* ** In WIn95, build shape returns a pointer to the shape not its size */ + + Image_t* shape_image = NULL; shape_pointer = Build_Frame(shapefile, shapenum, _ShapeBuffer); + if (shape_pointer) { - 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]); + //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]); unsigned char * buffer = (unsigned char *) shape_pointer; //Get_Shape_Header_Data((void*)shape_pointer); #else //WIN32 @@ -3755,6 +3756,18 @@ void CC_Draw_Shape(void const * shapefile, int shapenum, int x, int y, WindowNum } } + { + char tmp[512]; + sprintf(tmp, "s%d%d%d%d%d", shapefile, shapenum, rotation, fadingdata, flags); + + if (flags & SHAPE_FADING) { + shape_image = Image_CreateImageFrom8Bit(tmp, width, height, (unsigned char*)shape_pointer, (unsigned char*)fadingdata); + } + else { + shape_image = Image_CreateImageFrom8Bit(tmp, width, height, (unsigned char*)shape_pointer, NULL); + } + } + /* ** Special shadow drawing code (used for aircraft and bullets). */ @@ -3770,21 +3783,20 @@ void CC_Draw_Shape(void const * shapefile, int shapenum, int x, int y, WindowNum // predoffset = -predoffset; //} - if (draw_window.Lock()) { + { if ((flags & (SHAPE_GHOST|SHAPE_FADING)) == (SHAPE_GHOST|SHAPE_FADING)) { - Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, fadingdata, 1, predoffset); + Buffer_Frame_To_Page(x, y, width, height, shape_image, window, flags | SHAPE_TRANS, ghostdata, fadingdata, 1, predoffset); } else { if (flags & SHAPE_FADING) { - Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, fadingdata, 1, predoffset); + Buffer_Frame_To_Page(x, y, width, height, shape_image, window, flags | SHAPE_TRANS, fadingdata, 1, predoffset); } else { if (flags & SHAPE_PREDATOR) { - Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, predoffset); + Buffer_Frame_To_Page(x, y, width, height, shape_image, window, flags | SHAPE_TRANS, predoffset); } else { - Buffer_Frame_To_Page(x, y, width, height, buffer, draw_window, flags | SHAPE_TRANS, ghostdata, predoffset); + Buffer_Frame_To_Page(x, y, width, height, shape_image, window, flags | SHAPE_TRANS, ghostdata, predoffset); } } } - draw_window.Unlock(); } } } diff --git a/code/REDALERT/DISPLAY.H b/code/REDALERT/DISPLAY.H index e2fae5b..73c37b0 100644 --- a/code/REDALERT/DISPLAY.H +++ b/code/REDALERT/DISPLAY.H @@ -189,8 +189,9 @@ class DisplayClass: public MapClass void Repair_Mode_Control(int control); virtual void Flag_Cell(CELL cell); - bool Is_Cell_Flagged(CELL cell) const {return CellRedraw.Is_True(cell);}; - +// jmarshall + bool Is_Cell_Flagged(CELL cell) const { return true; } +// jmarshall end /* ** Computes starting position based on player's units' Coords. */ diff --git a/code/REDALERT/DLLInterface.cpp b/code/REDALERT/DLLInterface.cpp index 1d71c02..48daa36 100644 --- a/code/REDALERT/DLLInterface.cpp +++ b/code/REDALERT/DLLInterface.cpp @@ -1474,33 +1474,35 @@ bool Debug_Write_Shape(const char *file_name, void const * shapefile, int shapen /* ** Build frame returns a pointer now instead of the shapes length */ - char *shape_pointer = (char*) Build_Frame(shapefile , shapenum , _ShapeBuffer); - if (shape_pointer == NULL) { - return false;; - } - if (Get_Last_Frame_Length() > _ShapeBufferSize) { - return false;; - } - - int width = Get_Build_Frame_Width(shapefile); - int height = Get_Build_Frame_Height(shapefile); - - GraphicBufferClass temp_gbuffer(width, height); - GraphicViewPortClass temp_viewport(&temp_gbuffer, 0, 0, width, height); - - WindowList[WINDOW_CUSTOM][WINDOWX] = 0; - WindowList[WINDOW_CUSTOM][WINDOWY] = 0; - WindowList[WINDOW_CUSTOM][WINDOWWIDTH] = width; - WindowList[WINDOW_CUSTOM][WINDOWHEIGHT] = height; - - static const char _shape_trans = 0x40; - - if (flags == 0) { - Buffer_Frame_To_Page(0, 0, width, height, shape_pointer, temp_viewport, SHAPE_NORMAL|SHAPE_WIN_REL|_shape_trans); //, ghostdata, predoffset); - } else { - Buffer_Frame_To_Page(0, 0, width, height, shape_pointer, temp_viewport, flags, ghostdata); - } - Write_PCX_File((char*)file_name, temp_viewport, (unsigned char*)GamePalette.Get_Data()); +// jmarshall - do we need this? + //char *shape_pointer = (char*) Build_Frame(shapefile , shapenum , _ShapeBuffer); + //if (shape_pointer == NULL) { + // return false;; + //} + //if (Get_Last_Frame_Length() > _ShapeBufferSize) { + // return false;; + //} + // + //int width = Get_Build_Frame_Width(shapefile); + //int height = Get_Build_Frame_Height(shapefile); + // + //GraphicBufferClass temp_gbuffer(width, height); + //GraphicViewPortClass temp_viewport(&temp_gbuffer, 0, 0, width, height); + // + //WindowList[WINDOW_CUSTOM][WINDOWX] = 0; + //WindowList[WINDOW_CUSTOM][WINDOWY] = 0; + //WindowList[WINDOW_CUSTOM][WINDOWWIDTH] = width; + //WindowList[WINDOW_CUSTOM][WINDOWHEIGHT] = height; + // + //static const char _shape_trans = 0x40; + // + //if (flags == 0) { + // Buffer_Frame_To_Page(0, 0, width, height, shape_pointer, temp_viewport, SHAPE_NORMAL|SHAPE_WIN_REL|_shape_trans); //, ghostdata, predoffset); + //} else { + // Buffer_Frame_To_Page(0, 0, width, height, shape_pointer, temp_viewport, flags, ghostdata); + //} + //Write_PCX_File((char*)file_name, temp_viewport, (unsigned char*)GamePalette.Get_Data()); +// jmarshall end return true; } diff --git a/code/REDALERT/FUNCTION.H b/code/REDALERT/FUNCTION.H index 90fe9ba..6c4decc 100644 --- a/code/REDALERT/FUNCTION.H +++ b/code/REDALERT/FUNCTION.H @@ -710,9 +710,7 @@ void Buffer_Enable_HD_Texture(bool hdTextureEnabled); /* ** KEYFBUFF.ASM */ -extern "C" { - long __cdecl Buffer_Frame_To_Page(int x, int y, int w, int h, void *Buffer, GraphicViewPortClass &view, int flags, ...); -} +long __cdecl Buffer_Frame_To_Page(int x, int y, int w, int h, Image_t* image, unsigned int Window, int flags, ...); /* ** KEYFRAME.CPP diff --git a/code/REDALERT/GSCREEN.CPP b/code/REDALERT/GSCREEN.CPP index 4ddf2a1..e315b54 100644 --- a/code/REDALERT/GSCREEN.CPP +++ b/code/REDALERT/GSCREEN.CPP @@ -397,7 +397,7 @@ void GScreenClass::Render(void) //if (Buttons && Buttons->Is_List_To_Redraw()) { // IsToRedraw = true; //} - + IsToRedraw = true; if (IsToUpdate || IsToRedraw) { BStart(BENCH_GSCREEN_RENDER); diff --git a/code/REDALERT/Image.h b/code/REDALERT/Image.h index 57b88bf..8ca0c14 100644 --- a/code/REDALERT/Image.h +++ b/code/REDALERT/Image.h @@ -24,4 +24,4 @@ __forceinline Image_t::~Image_t() { } Image_t* Image_LoadImage(const char* name); -Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, char* data); \ No newline at end of file +Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsigned char* data, unsigned char *remap = NULL); \ No newline at end of file diff --git a/code/REDALERT/POWER.CPP b/code/REDALERT/POWER.CPP index 5e1fc0d..1f55d49 100644 --- a/code/REDALERT/POWER.CPP +++ b/code/REDALERT/POWER.CPP @@ -166,6 +166,10 @@ void PowerClass::Draw_It(bool complete) 0, -1, 0, 1, 0, -1, -2, -1, 0, 1, 2, 1 ,0 }; +// jmarshall - render the world before the power bar. + RadarClass::Draw_It(complete); +// jmarshall end + { BStart(BENCH_POWER); @@ -244,8 +248,7 @@ void PowerClass::Draw_It(bool complete) LogicPage->Unlock(); } BEnd(BENCH_POWER); - } - RadarClass::Draw_It(complete); + } } diff --git a/code/REDALERT/STARTUP.CPP b/code/REDALERT/STARTUP.CPP index 8e6c472..f5febf1 100644 --- a/code/REDALERT/STARTUP.CPP +++ b/code/REDALERT/STARTUP.CPP @@ -924,8 +924,8 @@ void Read_Setup_Options( RawFileClass *config_file ) VideoBackBufferAllowed = ini.Get_Bool("Options", "VideoBackBuffer", true); AllowHardwareBlitFills = ini.Get_Bool("Options", "HardwareFills", true); - ScreenWidth = 1024; - ScreenHeight = 768; + ScreenWidth = 1280; + ScreenHeight = 720; /* ** See if an alternative socket number has been specified diff --git a/code/REDALERT/Shape.cpp b/code/REDALERT/Shape.cpp index 0cfd6c2..9c2480e 100644 --- a/code/REDALERT/Shape.cpp +++ b/code/REDALERT/Shape.cpp @@ -28,6 +28,14 @@ * A full copy of the GNU General Public License can be found in * LICENSE */ +/* +============================ + +This file has been heavily modified by IceColdDuke(Justin Marshall) to render with OpenGL. + +============================ +*/ + #include "FUNCTION.H" #include #include @@ -1388,7 +1396,7 @@ static void Single_Line_Flagger( } } -long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, GraphicViewPortClass& viewport, int flags, ...) +long Buffer_Frame_To_Page(int x, int y, int width, int height, struct Image_t * shape_image, unsigned int Window, int flags, ...) { BOOL use_old_drawer = false; int fade_count = 0; @@ -1397,30 +1405,10 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap uint8_t* ghost_table = nullptr; uint8_t* ghost_lookup = nullptr; - if (!shape) { + if (!shape_image) { return 0; } - uint8_t* frame_data = static_cast(shape); - - if (!renderHDTexture) - { - if (UseOldShapeDraw) { - use_old_drawer = true; - } - else if (UseBigShapeBuffer) { - draw_header = static_cast(shape); - uint8_t* shape_buff = reinterpret_cast(BigShapeBufferStart); - - if (draw_header->m_IsTheaterShape) { - shape_buff = reinterpret_cast(TheaterShapeBufferStart); - } - - frame_data = shape_buff + draw_header->m_FrameOffset; - use_old_drawer = false; - } - } - va_list ap; va_start(ap, flags); @@ -1447,12 +1435,6 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap use_old_drawer = true; } - 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 if (flags & SHAPE_FADING) { fade_table = va_arg(ap, uint8_t*); @@ -1474,18 +1456,18 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap } // Sets for BF_Predator functions - if (flags & SHAPE_PREDATOR) { - int current_frame = va_arg(ap, uint32_t); - blit_style |= 8; - - g_PredFrame = ((unsigned)current_frame) % 8; - g_PartialCount = 0; - g_PartialPred = 256; - - // Calculates the end of the visible display buffer, hopefully prevent crashes from predator effect. - // Unused by default in RA, but would be nice on the phase tank in Aftermath. - g_PredatorLimit = (uint8_t*)(viewport.Get_Offset()) + viewport.Get_Full_Pitch() * viewport.Get_Height(); - } + //if (flags & SHAPE_PREDATOR) { + // int current_frame = va_arg(ap, uint32_t); + // blit_style |= 8; + // + // g_PredFrame = ((unsigned)current_frame) % 8; + // g_PartialCount = 0; + // g_PartialPred = 256; + // + // // Calculates the end of the visible display buffer, hopefully prevent crashes from predator effect. + // // Unused by default in RA, but would be nice on the phase tank in Aftermath. + // g_PredatorLimit = (uint8_t*)(viewport.Get_Offset()) + viewport.Get_Full_Pitch() * viewport.Get_Height(); + //} if (flags & SHAPE_PARTIAL) { g_PartialPred = va_arg(ap, int) & 0xFF; @@ -1500,97 +1482,105 @@ long Buffer_Frame_To_Page(int x, int y, int width, int height, void* shape, Grap int ms_img_offset = 0; // If we aren't drawing within the viewport, return. - if (xstart >= viewport.Get_Width() || ystart >= viewport.Get_Height() || xend <= 0 || yend <= 0) { - return 0; - } + //if (xstart >= viewport.Get_Width() || ystart >= viewport.Get_Height() || xend <= 0 || yend <= 0) { + // return 0; + //} // Do any needed clipping. - if (xstart < 0) { - ms_img_offset = -xstart; - xstart = 0; - use_old_drawer = true; - } + //if (xstart < 0) { + // ms_img_offset = -xstart; + // xstart = 0; + // use_old_drawer = true; + //} + // + //if (ystart < 0) { + // //frame_data += width * (-ystart); + // ystart = 0; + // use_old_drawer = true; + //} - if (ystart < 0) { - frame_data += width * (-ystart); - ystart = 0; - use_old_drawer = true; - } + if (xstart + width < 0 || ystart + height < 0) + return 0; - if (xend >= viewport.Get_Width() - 1) { - xend = viewport.Get_Width() - 1; - use_old_drawer = true; - } - - if (yend >= viewport.Get_Height() - 1) { - yend = viewport.Get_Height() - 1; - use_old_drawer = true; - } + // if (xend >= viewport.Get_Width() - 1) { + // xend = viewport.Get_Width() - 1; + // use_old_drawer = true; + // } + // + // if (yend >= viewport.Get_Height() - 1) { + // yend = viewport.Get_Height() - 1; + // use_old_drawer = true; + // } int blit_width = xend - xstart + 1; int blit_height = yend - ystart + 1; - 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 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; + //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 && !renderHDTexture) { - // DEBUG_SAY("Drawing with Single_Line draw functions\n"); - - // Here we can use the individual line drawing routines - // Means we can skip drawing some lines all together or avoid using - // more expensive routines on some lines. - uint8_t* line_flags = reinterpret_cast(draw_header + 1); - - for (int i = 0; i < blit_height; ++i) { - NewShapeJumpTable[line_flags[i] & 0x1F](blit_width, dst, src, ghost_lookup, ghost_table, fade_table, fade_count); - src += width; - dst += pitch * 4; - } - - return 0; - } + //if (use_old_drawer != true && !renderHDTexture) { + // // DEBUG_SAY("Drawing with Single_Line draw functions\n"); + // + // // Here we can use the individual line drawing routines + // // Means we can skip drawing some lines all together or avoid using + // // more expensive routines on some lines. + // uint8_t* line_flags = reinterpret_cast(draw_header + 1); + // + // for (int i = 0; i < blit_height; ++i) { + // NewShapeJumpTable[line_flags[i] & 0x1F](blit_width, dst, src, ghost_lookup, ghost_table, fade_table, fade_count); + // src += width; + // dst += pitch * 4; + // } + // + // return 0; + //} + xstart = xstart + WindowList[Window][WINDOWX];// + LogicPage->Get_XPos(); + ystart = ystart + WindowList[Window][WINDOWY];// + LogicPage->Get_YPos(); + //GL_SetClipRect(WindowList[Window][WINDOWX], WindowList[Window][WINDOWY], WindowList[Window][WINDOWWIDTH], WindowList[Window][WINDOWWIDTH]); + GL_RenderImage(shape_image, xstart, ystart, width, height); + // Here we just use the function that will blit the entire frame // using the appropriate effects. - if (blit_height > 0 && blit_width > 0) { - // DEBUG_SAY("Drawing with BF draw functions\n"); - 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; - } - } - } + //if (blit_height > 0 && blit_width > 0) { + // // DEBUG_SAY("Drawing with BF draw functions\n"); + // 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; } diff --git a/code/REDALERT/TILESET.CPP b/code/REDALERT/TILESET.CPP index 1b34281..95f639e 100644 --- a/code/REDALERT/TILESET.CPP +++ b/code/REDALERT/TILESET.CPP @@ -13,8 +13,17 @@ * A full copy of the GNU General Public License can be found in * LICENSE */ + /* + ============================ + + This file has been heavily modified by IceColdDuke(Justin Marshall) to render with OpenGL. + + ============================ + */ + #include "FUNCTION.H" #include "gbuffer.h" +#include "Image.h" #include using std::memcpy; @@ -23,6 +32,8 @@ class GraphicViewPortClass; #define TD_TILESET_CHECK 0x20 +Image_t* tileset_icon_cache[4096]; + /** * @brief union is to handle the parts of the header which vary between TD and RA format tiles. */ @@ -93,6 +104,7 @@ static int IconCount; void __cdecl Init_Stamps(IconControlType* iconset) { + memset(&tileset_icon_cache, 0, sizeof(tileset_icon_cache)); if (iconset && LastIconset != iconset) { IconCount = (iconset->count); IconWidth = (iconset->width); @@ -181,8 +193,17 @@ void __cdecl Buffer_Draw_Stamp2(GraphicViewPortClass& viewport, IconControlType* } } -void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, IconControlType* tileset, int icon, int x, int y, const void* remapper, int left, int top, int right, int bottom) +void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, const void *icondata, int icon, int x, int y, const void* remapper, int left, int top, int right, int bottom) { + const TemplateTypeClass* ttype = (TemplateTypeClass const*)icondata; + IconControlType* tileset = (IconControlType * )ttype->Get_Image_Data(); + + // This is a awful hack, but need type info to generate unique id's for tileset generation. + if (icondata == DisplayClass::TransIconset) { + tileset = (IconControlType*)DisplayClass::TransIconset; + ttype = NULL; + } + if (!tileset) { return; } @@ -192,7 +213,7 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, IconControl } int icon_index = MapPtr != nullptr ? MapPtr[icon] : icon; - + if (icon_index < IconCount) { int blit_height = IconHeight; int blit_width = IconWidth; @@ -202,83 +223,103 @@ void __cdecl Buffer_Draw_Stamp_Clip2(GraphicViewPortClass& viewport, IconControl int height = top + bottom; int ystart = top + y; + // + if (!tileset_icon_cache[icon_index]) { + char tmp[512]; + if (ttype != NULL) { + sprintf(tmp, "icon_%d_%d", ttype->Type, icon_index); + } + else { + sprintf(tmp, "icon_%d_%d", icondata, icon_index); + } + tileset_icon_cache[icon_index] = Image_CreateImageFrom8Bit(tmp, IconWidth, IconHeight, (unsigned char *)src); + } + if (xstart < width && ystart < height && IconHeight + ystart > top && IconWidth + xstart > left) { if (xstart < left) { src += left - xstart; blit_width -= left - xstart; xstart = left; } - + int src_pitch = IconWidth - blit_width; - + if (blit_width + xstart > width) { src_pitch += blit_width - (width - xstart); blit_width = width - xstart; } - + if (top > ystart) { blit_height = IconHeight - (top - ystart); src += IconWidth * (top - ystart); ystart = top; } - + if (blit_height + ystart > height) { blit_height = height - ystart; } - + int full_pitch = viewport.Get_Full_Pitch(); //(viewport.Get_Pitch() + viewport.Get_XAdd() + viewport.Get_Width()); uint8_t* dst = (xstart * 4) + (ystart * 4) * full_pitch + (uint8_t*)(viewport.Get_Offset()); int dst_pitch = full_pitch - blit_width; + + //if (remapper) { + // const uint8_t* remap = static_cast(remapper); + // for (int i = 0; i < blit_height; ++i) { + // for (int j = 0; j < blit_width; ++j) { + // uint8_t cur_byte = remap[*src++]; + // if (cur_byte) { + // dst[0] = backbuffer_data_raw[(cur_byte * 3) + 0]; + // dst[1] = backbuffer_data_raw[(cur_byte * 3) + 1]; + // dst[2] = backbuffer_data_raw[(cur_byte * 3) + 2]; + // dst[3] = 255; + // } + // + // dst += 4; + // } + // dst += dst_pitch * 4; + // } + // + //} + //else if (TransFlagPtr[icon_index]) { + // for (int i = 0; i < blit_height; ++i) { + // for (int j = 0; j < blit_width; ++j) { + // uint8_t cur_byte = *src++; + // if (cur_byte) { + // dst[0] = backbuffer_data_raw[(cur_byte * 3) + 0]; + // dst[1] = backbuffer_data_raw[(cur_byte * 3) + 1]; + // dst[2] = backbuffer_data_raw[(cur_byte * 3) + 2]; + // dst[3] = 255; + // } + // + // dst += 4; + // } + // src += src_pitch; + // dst += dst_pitch * 4; + // } + // + //} + //else { + { + //for (int i = 0; i < blit_height; ++i) { + // FastScanlinePaletteBlit(dst, src, blit_width); + // dst += full_pitch * 4; + // src += IconWidth; + //} - if (remapper) { - const uint8_t* remap = static_cast(remapper); - for (int i = 0; i < blit_height; ++i) { - for (int j = 0; j < blit_width; ++j) { - uint8_t cur_byte = remap[*src++]; - if (cur_byte) { - dst[0] = backbuffer_data_raw[(cur_byte * 3) + 0]; - dst[1] = backbuffer_data_raw[(cur_byte * 3) + 1]; - dst[2] = backbuffer_data_raw[(cur_byte * 3) + 2]; - dst[3] = 255; - } - - dst += 4; - } - dst += dst_pitch * 4; - } - - } - else if (TransFlagPtr[icon_index]) { - for (int i = 0; i < blit_height; ++i) { - for (int j = 0; j < blit_width; ++j) { - uint8_t cur_byte = *src++; - if (cur_byte) { - dst[0] = backbuffer_data_raw[(cur_byte * 3) + 0]; - dst[1] = backbuffer_data_raw[(cur_byte * 3) + 1]; - dst[2] = backbuffer_data_raw[(cur_byte * 3) + 2]; - dst[3] = 255; - } - - dst += 4; - } - src += src_pitch; - dst += dst_pitch * 4; - } - - } - else { - for (int i = 0; i < blit_height; ++i) { - FastScanlinePaletteBlit(dst, src, blit_width); - dst += full_pitch * 4; - src += IconWidth; - } + GL_SetClipRect(xstart, ystart, blit_width, blit_height); + GL_RenderImage(tileset_icon_cache[icon_index], xstart, ystart, blit_width, blit_height); + GL_ResetClipRect(); } } } } extern "C" void __cdecl Buffer_Draw_Stamp_Clip(void const* this_object, void const* icondata, int icon, int x_pixel, int y_pixel, void const* remap, int min_x, int min_y, int max_x, int max_y) { - Buffer_Draw_Stamp_Clip2(*((GraphicViewPortClass*)this_object), (IconControlType*)icondata, icon, x_pixel, y_pixel, remap, min_x, min_y, max_x, max_y); + if (icondata == NULL) + return; + + Buffer_Draw_Stamp_Clip2(*((GraphicViewPortClass*)this_object), icondata, icon, x_pixel, y_pixel, remap, min_x, min_y, max_x, max_y); } extern "C" void __cdecl Buffer_Draw_Stamp(void const* thisptr, void const* icondata, int icon, int x_pixel, int y_pixel, void const* remap) { diff --git a/code/REDALERT/VORTEX.CPP b/code/REDALERT/VORTEX.CPP index bdf455a..da3dbe9 100644 --- a/code/REDALERT/VORTEX.CPP +++ b/code/REDALERT/VORTEX.CPP @@ -935,7 +935,9 @@ void ChronalVortexClass::Render (void) ** Draw the template */ if (ttype->Get_Image_Data()) { - RenderBuffer->Draw_Stamp(ttype->Get_Image_Data(), icon, x*CELL_PIXEL_W, y*CELL_PIXEL_H, NULL, WINDOW_MAIN); +// jmarshall - send down the raw ttype + RenderBuffer->Draw_Stamp(ttype, icon, x*CELL_PIXEL_W, y*CELL_PIXEL_H, NULL, WINDOW_MAIN); +// jmarshall end } /* diff --git a/code/REDALERT/WIN32LIB/GBUFFER.H b/code/REDALERT/WIN32LIB/GBUFFER.H index 3bdf860..ec7fb5d 100644 --- a/code/REDALERT/WIN32LIB/GBUFFER.H +++ b/code/REDALERT/WIN32LIB/GBUFFER.H @@ -1122,28 +1122,28 @@ inline void GraphicViewPortClass::Draw_Stamp(void const * icondata, int icon, in int cache_index=-1; int drewit = 0; - if (IconCacheAllowed){ - if (IsDirectDraw){ - if (!remap){ - cache_index = Is_Icon_Cached(icondata,icon); - } - - if (cache_index != -1){ - if (CachedIcons[cache_index].Get_Is_Cached() ){ - CachedIcons[cache_index].Draw_It (GraphicBuff->Get_DD_Surface() , x_pixel, y_pixel, - WindowList[clip_window][WINDOWX] + XPos, - WindowList[clip_window][WINDOWY] +YPos, - WindowList[clip_window][WINDOWWIDTH], - WindowList[clip_window][WINDOWHEIGHT]); - CachedIconsDrawn++; - drewit = 1; - } - } - } - } + //if (IconCacheAllowed){ + // if (IsDirectDraw){ + // if (!remap){ + // cache_index = Is_Icon_Cached(icondata,icon); + // } + // + // if (cache_index != -1){ + // if (CachedIcons[cache_index].Get_Is_Cached() ){ + // CachedIcons[cache_index].Draw_It (GraphicBuff->Get_DD_Surface() , x_pixel, y_pixel, + // WindowList[clip_window][WINDOWX] + XPos, + // WindowList[clip_window][WINDOWY] +YPos, + // WindowList[clip_window][WINDOWWIDTH], + // WindowList[clip_window][WINDOWHEIGHT]); + // CachedIconsDrawn++; + // drewit = 1; + // } + // } + // } + //} - if (drewit == 0) { + { if (Lock()){ UnCachedIconsDrawn++; extern int ScreenHeight, ScreenWidth; @@ -1173,7 +1173,10 @@ inline VOID GraphicViewPortClass::Draw_Line(int sx, int sy, int dx, int dy, unsi // Buffer_Draw_Line(this, sx, sy, dx, dy, color); //} //Unlock(); - + sx += XPos; + sy += YPos; + dx += XPos; + dy += YPos; GL_DrawLine(color, sx, sy, dx, dy); } @@ -1191,14 +1194,11 @@ inline VOID GraphicViewPortClass::Draw_Line(int sx, int sy, int dx, int dy, unsi *=========================================================================*/ inline VOID GraphicViewPortClass::Fill_Rect(int sx, int sy, int dx, int dy, unsigned char color) { -// jmarshall - // Still needed for gameplay. - if (Lock()) { - Buffer_Fill_Rect(this, sx, sy, dx, dy, color); - Unlock(); - } - //GL_FillRect(color, sx, sy, dx - sx, dy - sy); -// jmarshall end + sx += XPos; + sy += YPos; + dx += XPos; + dy += YPos; + GL_FillRect(color, sx - 1, sy - 1, (dx - sx) + 1, ((dy - sy) + 1)); } diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index e9dbb29..52c105d 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -73,6 +73,8 @@ SDL_Window* game_window; SDL_GLContext game_context; int OverlappedVideoBlits = 0; +extern std::vector renderedFrameObjects; + bool renderConsole = false; void (*Misc_Focus_Loss_Function)(void) = nullptr; @@ -127,8 +129,8 @@ Image_t* Image_LoadImage(const char* name) { assert(!"Unknown BPP in image!"); } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Image_t* image = new Image_t(); strcpy(image->name, name); @@ -144,7 +146,7 @@ Image_t* Image_LoadImage(const char* name) { return image; } -Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, char *data) { +Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsigned char *data, unsigned char* remap) { // Check to see if the image is already loaded. for (int i = 0; i < loaded_images.size(); i++) { if (!strcmp(loaded_images[i]->name, name)) { @@ -152,21 +154,37 @@ Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, char } } + unsigned char* ccpalete = (unsigned char*)CCPalette.Get_Data(); + Image_t* image = new Image_t(); image->buffer = new unsigned char[Width * Height * 4]; for (int i = 0; i < Width * Height; i++) { - char c = data[i]; + unsigned char c = data[i]; + if (remap) { + c = remap[c]; + } - image->buffer[(i * 4) + 0] = backbuffer_palette[(c * 3) + 0]; - image->buffer[(i * 4) + 1] = backbuffer_palette[(c * 3) + 1]; - image->buffer[(i * 4) + 2] = backbuffer_palette[(c * 3) + 2]; - if (c == 0) { - image->buffer[(i * 4) + 3] = 0; + unsigned char r = ccpalete[(c * 3) + 0] << 2; + unsigned char g = ccpalete[(c * 3) + 1] << 2; + unsigned char b = ccpalete[(c * 3) + 2] << 2; + unsigned char a = 0; + + if ((r == 84 && g == 252 && b == 84) || (r == 0 && g == 168 && b == 0)) { + r = 0; + g = 0; + b = 0; + a = 128; } - else { - image->buffer[(i * 4) + 3] = 255; + else if (c != 0) { + a = 255; } + + + image->buffer[(i * 4) + 0] = r; + image->buffer[(i * 4) + 1] = g; + image->buffer[(i * 4) + 2] = b; + image->buffer[(i * 4) + 3] = a; } @@ -228,6 +246,8 @@ void ImGui_NewFrame(void) { ImGui::NewFrame(show_oldframebuffer); ImGui_ImplSDL2_NewFrame(game_window); + + renderedFrameObjects.clear(); } void Device_Present(void) { diff --git a/textures/afv01.sno.png b/textures/afv01.tem.png similarity index 100% rename from textures/afv01.sno.png rename to textures/afv01.tem.png diff --git a/textures/afv02.tem.png b/textures/afv02.tem.png new file mode 100644 index 0000000..5c9433c Binary files /dev/null and b/textures/afv02.tem.png differ diff --git a/textures/afv03.tem.png b/textures/afv03.tem.png new file mode 100644 index 0000000..2019cb7 Binary files /dev/null and b/textures/afv03.tem.png differ