2020-11-06 13:56:32 +00:00
|
|
|
#include "pch.h"
|
|
|
|
#include "render.h"
|
2021-09-21 10:14:39 +00:00
|
|
|
|
2021-10-24 04:13:51 +00:00
|
|
|
#include "fullscrn.h"
|
2021-09-21 10:14:39 +00:00
|
|
|
#include "GroupData.h"
|
2021-09-25 13:52:19 +00:00
|
|
|
#include "options.h"
|
2021-09-21 10:14:39 +00:00
|
|
|
#include "pb.h"
|
2021-10-09 14:28:30 +00:00
|
|
|
#include "score.h"
|
2021-09-25 13:52:19 +00:00
|
|
|
#include "TPinballTable.h"
|
|
|
|
#include "winmain.h"
|
2020-11-08 15:37:59 +00:00
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
std::vector<render_sprite_type_struct*> render::dirty_list, render::sprite_list, render::ball_list;
|
2020-11-08 15:37:59 +00:00
|
|
|
zmap_header_type* render::background_zmap;
|
2020-11-15 14:39:00 +00:00
|
|
|
int render::zmap_offset, render::zmap_offsetY, render::offset_x, render::offset_y;
|
|
|
|
float render::zscaler, render::zmin, render::zmax;
|
|
|
|
rectangle_type render::vscreen_rect;
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv_bitmap8 *render::vscreen, *render::background_bitmap, *render::ball_bitmap[20];
|
|
|
|
zmap_header_type* render::zscreen;
|
2021-09-25 13:52:19 +00:00
|
|
|
SDL_Rect render::DestinationRect{};
|
2020-11-06 13:56:32 +00:00
|
|
|
|
2020-11-15 14:39:00 +00:00
|
|
|
void render::init(gdrv_bitmap8* bmp, float zMin, float zScaler, int width, int height)
|
2020-11-06 13:56:32 +00:00
|
|
|
{
|
2020-11-15 14:39:00 +00:00
|
|
|
zscaler = zScaler;
|
|
|
|
zmin = zMin;
|
|
|
|
zmax = 4294967300.0f / zScaler + zMin;
|
2021-10-02 14:45:31 +00:00
|
|
|
vscreen = new gdrv_bitmap8(width, height, false);
|
|
|
|
zscreen = new zmap_header_type(width, height, width);
|
|
|
|
zdrv::fill(zscreen, zscreen->Width, zscreen->Height, 0, 0, 0xFFFF);
|
2020-11-15 14:39:00 +00:00
|
|
|
vscreen_rect.YPosition = 0;
|
|
|
|
vscreen_rect.XPosition = 0;
|
|
|
|
vscreen_rect.Width = width;
|
|
|
|
vscreen_rect.Height = height;
|
2021-10-02 14:45:31 +00:00
|
|
|
vscreen->YPosition = 0;
|
|
|
|
vscreen->XPosition = 0;
|
2021-09-22 12:50:07 +00:00
|
|
|
for (auto& ballBmp : ball_bitmap)
|
2021-10-02 14:45:31 +00:00
|
|
|
ballBmp = new gdrv_bitmap8(64, 64, false);
|
2021-09-22 12:50:07 +00:00
|
|
|
|
2020-11-15 14:39:00 +00:00
|
|
|
background_bitmap = bmp;
|
|
|
|
if (bmp)
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv::copy_bitmap(vscreen, width, height, 0, 0, bmp, 0, 0);
|
2020-11-15 14:39:00 +00:00
|
|
|
else
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv::fill_bitmap(vscreen, vscreen->Width, vscreen->Height, 0, 0, 0);
|
2021-09-25 13:52:19 +00:00
|
|
|
|
2021-10-25 03:42:36 +00:00
|
|
|
recreate_screen_texture();
|
2020-11-06 13:56:32 +00:00
|
|
|
}
|
2020-11-07 15:41:14 +00:00
|
|
|
|
2020-11-15 14:39:00 +00:00
|
|
|
void render::uninit()
|
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
delete vscreen;
|
|
|
|
delete zscreen;
|
|
|
|
for (auto sprite : sprite_list)
|
|
|
|
remove_sprite(sprite, false);
|
|
|
|
for (auto ball : ball_list)
|
|
|
|
remove_ball(ball, false);
|
2021-09-22 12:50:07 +00:00
|
|
|
for (auto& ballBmp : ball_bitmap)
|
2021-10-02 14:45:31 +00:00
|
|
|
delete ballBmp;
|
|
|
|
ball_list.clear();
|
|
|
|
dirty_list.clear();
|
|
|
|
sprite_list.clear();
|
2021-10-25 03:42:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void render::recreate_screen_texture()
|
|
|
|
{
|
2021-11-11 11:30:56 +00:00
|
|
|
vscreen->CreateTexture(options::Options.LinearFiltering ? "linear" : "nearest", SDL_TEXTUREACCESS_STREAMING);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
2020-11-07 15:41:14 +00:00
|
|
|
|
2020-11-15 14:39:00 +00:00
|
|
|
void render::update()
|
2020-11-07 15:41:14 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
unpaint_balls();
|
2020-11-15 14:39:00 +00:00
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
// Clip dirty sprites with vScreen, clear clipping (dirty) rectangles
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto curSprite : dirty_list)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
bool clearSprite = false;
|
|
|
|
switch (curSprite->VisualType)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
case VisualTypes::Sprite:
|
|
|
|
if (curSprite->DirtyRectPrev.Width > 0)
|
|
|
|
maths::enclosing_box(&curSprite->DirtyRectPrev, &curSprite->BmpRect, &curSprite->DirtyRect);
|
2020-11-15 14:39:00 +00:00
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
if (maths::rectangle_clip(&curSprite->DirtyRect, &vscreen_rect, &curSprite->DirtyRect))
|
|
|
|
clearSprite = true;
|
|
|
|
else
|
|
|
|
curSprite->DirtyRect.Width = -1;
|
|
|
|
break;
|
|
|
|
case VisualTypes::None:
|
|
|
|
if (maths::rectangle_clip(&curSprite->BmpRect, &vscreen_rect, &curSprite->DirtyRect))
|
|
|
|
clearSprite = !curSprite->Bmp;
|
|
|
|
else
|
|
|
|
curSprite->DirtyRect.Width = -1;
|
|
|
|
break;
|
|
|
|
default: break;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
2021-09-25 13:52:19 +00:00
|
|
|
|
|
|
|
if (clearSprite)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
auto yPos = curSprite->DirtyRect.YPosition;
|
|
|
|
auto width = curSprite->DirtyRect.Width;
|
|
|
|
auto xPos = curSprite->DirtyRect.XPosition;
|
|
|
|
auto height = curSprite->DirtyRect.Height;
|
2021-10-02 14:45:31 +00:00
|
|
|
zdrv::fill(zscreen, width, height, xPos, yPos, 0xFFFF);
|
2021-09-25 13:52:19 +00:00
|
|
|
if (background_bitmap)
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv::copy_bitmap(vscreen, width, height, xPos, yPos, background_bitmap, xPos, yPos);
|
2021-09-25 13:52:19 +00:00
|
|
|
else
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv::fill_bitmap(vscreen, width, height, xPos, yPos, 0);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
// Paint dirty rectangles of dirty sprites
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto sprite : dirty_list)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
if (sprite->DirtyRect.Width > 0 && (sprite->VisualType == VisualTypes::None || sprite->VisualType ==
|
2021-09-09 08:40:54 +00:00
|
|
|
VisualTypes::Sprite))
|
2021-09-25 13:52:19 +00:00
|
|
|
repaint(sprite);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
paint_balls();
|
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
// In the original, this used to blit dirty sprites and balls
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto sprite : dirty_list)
|
2021-09-25 13:52:19 +00:00
|
|
|
{
|
|
|
|
sprite->DirtyRectPrev = sprite->DirtyRect;
|
|
|
|
if (sprite->UnknownFlag != 0)
|
2021-10-02 14:45:31 +00:00
|
|
|
remove_sprite(sprite, true);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
dirty_list.clear();
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
2020-11-08 15:37:59 +00:00
|
|
|
|
2020-11-15 14:39:00 +00:00
|
|
|
void render::sprite_modified(render_sprite_type_struct* sprite)
|
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
if (sprite->VisualType != VisualTypes::Ball && dirty_list.size() < 999)
|
|
|
|
dirty_list.push_back(sprite);
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 08:40:54 +00:00
|
|
|
render_sprite_type_struct* render::create_sprite(VisualTypes visualType, gdrv_bitmap8* bmp, zmap_header_type* zMap,
|
2020-11-15 14:39:00 +00:00
|
|
|
int xPosition, int yPosition, rectangle_type* rect)
|
2020-11-08 15:37:59 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
auto sprite = new render_sprite_type_struct();
|
2020-11-08 15:37:59 +00:00
|
|
|
if (!sprite)
|
2020-11-15 14:39:00 +00:00
|
|
|
return nullptr;
|
|
|
|
sprite->BmpRect.YPosition = yPosition;
|
|
|
|
sprite->BmpRect.XPosition = xPosition;
|
|
|
|
sprite->Bmp = bmp;
|
2020-11-08 15:37:59 +00:00
|
|
|
sprite->VisualType = visualType;
|
2020-12-27 15:19:36 +00:00
|
|
|
sprite->UnknownFlag = 0;
|
2020-11-15 14:39:00 +00:00
|
|
|
sprite->SpriteArray = nullptr;
|
2021-01-05 12:12:54 +00:00
|
|
|
sprite->DirtyRect = rectangle_type{};
|
2020-11-08 15:37:59 +00:00
|
|
|
if (rect)
|
|
|
|
{
|
2020-11-15 14:39:00 +00:00
|
|
|
sprite->BoundingRect = *rect;
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-15 14:39:00 +00:00
|
|
|
sprite->BoundingRect.Width = -1;
|
|
|
|
sprite->BoundingRect.Height = -1;
|
|
|
|
sprite->BoundingRect.XPosition = 0;
|
|
|
|
sprite->BoundingRect.YPosition = 0;
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
2020-11-15 14:39:00 +00:00
|
|
|
if (bmp)
|
2020-11-08 15:37:59 +00:00
|
|
|
{
|
2020-11-15 14:39:00 +00:00
|
|
|
sprite->BmpRect.Width = bmp->Width;
|
|
|
|
sprite->BmpRect.Height = bmp->Height;
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-15 14:39:00 +00:00
|
|
|
sprite->BmpRect.Width = 0;
|
|
|
|
sprite->BmpRect.Height = 0;
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
|
|
|
sprite->ZMap = zMap;
|
|
|
|
sprite->ZMapOffestX = 0;
|
|
|
|
sprite->ZMapOffestY = 0;
|
2021-09-09 08:40:54 +00:00
|
|
|
if (!zMap && visualType != VisualTypes::Ball)
|
2020-11-08 15:37:59 +00:00
|
|
|
{
|
|
|
|
sprite->ZMap = background_zmap;
|
|
|
|
sprite->ZMapOffestY = xPosition - zmap_offset;
|
|
|
|
sprite->ZMapOffestX = yPosition - zmap_offsetY;
|
|
|
|
}
|
2021-09-25 13:52:19 +00:00
|
|
|
sprite->DirtyRectPrev = sprite->BmpRect;
|
2021-09-09 08:40:54 +00:00
|
|
|
if (visualType == VisualTypes::Ball)
|
2020-11-08 15:37:59 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
ball_list.push_back(sprite);
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
sprite_list.push_back(sprite);
|
2020-11-08 15:37:59 +00:00
|
|
|
sprite_modified(sprite);
|
|
|
|
}
|
2020-11-15 14:39:00 +00:00
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
void render::remove_sprite(render_sprite_type_struct* sprite, bool removeFromList)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
if (removeFromList)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
auto it = std::find(sprite_list.begin(), sprite_list.end(), sprite);
|
|
|
|
if (it != sprite_list.end())
|
|
|
|
sprite_list.erase(it);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
2021-10-02 14:45:31 +00:00
|
|
|
|
|
|
|
delete sprite->SpriteArray;
|
|
|
|
delete sprite;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
void render::remove_ball(render_sprite_type_struct* ball, bool removeFromList)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
if (removeFromList)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
auto it = std::find(ball_list.begin(), ball_list.end(), ball);
|
|
|
|
if (it != ball_list.end())
|
|
|
|
ball_list.erase(it);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
2021-10-02 14:45:31 +00:00
|
|
|
|
|
|
|
delete ball->SpriteArray;
|
|
|
|
delete ball;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void render::sprite_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, zmap_header_type* zMap, int xPos,
|
|
|
|
int yPos)
|
|
|
|
{
|
|
|
|
if (sprite)
|
|
|
|
{
|
|
|
|
sprite->BmpRect.XPosition = xPos;
|
|
|
|
sprite->BmpRect.YPosition = yPos;
|
|
|
|
sprite->Bmp = bmp;
|
|
|
|
if (bmp)
|
|
|
|
{
|
|
|
|
sprite->BmpRect.Width = bmp->Width;
|
|
|
|
sprite->BmpRect.Height = bmp->Height;
|
|
|
|
}
|
|
|
|
sprite->ZMap = zMap;
|
|
|
|
sprite_modified(sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render::sprite_set_bitmap(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp)
|
|
|
|
{
|
|
|
|
if (sprite && sprite->Bmp != bmp)
|
|
|
|
{
|
|
|
|
sprite->Bmp = bmp;
|
|
|
|
if (bmp)
|
|
|
|
{
|
|
|
|
sprite->BmpRect.Width = bmp->Width;
|
|
|
|
sprite->BmpRect.Height = bmp->Height;
|
|
|
|
}
|
|
|
|
sprite_modified(sprite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render::set_background_zmap(struct zmap_header_type* zMap, int offsetX, int offsetY)
|
|
|
|
{
|
|
|
|
background_zmap = zMap;
|
|
|
|
zmap_offset = offsetX;
|
|
|
|
zmap_offsetY = offsetY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void render::ball_set(render_sprite_type_struct* sprite, gdrv_bitmap8* bmp, float depth, int xPos, int yPos)
|
|
|
|
{
|
|
|
|
if (sprite)
|
|
|
|
{
|
|
|
|
sprite->Bmp = bmp;
|
|
|
|
if (bmp)
|
|
|
|
{
|
|
|
|
sprite->BmpRect.XPosition = xPos;
|
|
|
|
sprite->BmpRect.YPosition = yPos;
|
|
|
|
sprite->BmpRect.Width = bmp->Width;
|
|
|
|
sprite->BmpRect.Height = bmp->Height;
|
|
|
|
}
|
|
|
|
if (depth >= zmin)
|
|
|
|
{
|
|
|
|
float depth2 = (depth - zmin) * zscaler;
|
|
|
|
if (depth2 <= zmax)
|
|
|
|
sprite->Depth = static_cast<short>(depth2);
|
|
|
|
else
|
|
|
|
sprite->Depth = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite->Depth = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render::repaint(struct render_sprite_type_struct* sprite)
|
|
|
|
{
|
|
|
|
rectangle_type clipRect{};
|
|
|
|
if (!sprite->SpriteArray)
|
|
|
|
return;
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto refSprite : *sprite->SpriteArray)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
if (!refSprite->UnknownFlag && refSprite->Bmp)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
if (maths::rectangle_clip(&refSprite->BmpRect, &sprite->DirtyRect, &clipRect))
|
2020-11-15 14:39:00 +00:00
|
|
|
zdrv::paint(
|
|
|
|
clipRect.Width,
|
|
|
|
clipRect.Height,
|
2021-10-02 14:45:31 +00:00
|
|
|
vscreen,
|
2020-11-15 14:39:00 +00:00
|
|
|
clipRect.XPosition,
|
|
|
|
clipRect.YPosition,
|
2021-10-02 14:45:31 +00:00
|
|
|
zscreen,
|
2020-11-15 14:39:00 +00:00
|
|
|
clipRect.XPosition,
|
|
|
|
clipRect.YPosition,
|
2021-09-25 13:52:19 +00:00
|
|
|
refSprite->Bmp,
|
|
|
|
clipRect.XPosition - refSprite->BmpRect.XPosition,
|
|
|
|
clipRect.YPosition - refSprite->BmpRect.YPosition,
|
|
|
|
refSprite->ZMap,
|
|
|
|
clipRect.XPosition + refSprite->ZMapOffestY - refSprite->BmpRect.XPosition,
|
|
|
|
clipRect.YPosition + refSprite->ZMapOffestX - refSprite->BmpRect.YPosition);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void render::paint_balls()
|
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
// Sort ball sprites by depth
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto i = 0u; i < ball_list.size(); i++)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto j = i; j < ball_list.size() / 2; ++j)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
auto ballA = ball_list[j];
|
|
|
|
auto ballB = ball_list[i];
|
|
|
|
if (ballB->Depth > ballA->Depth)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
ball_list[i] = ballA;
|
|
|
|
ball_list[j] = ballB;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
// For balls that clip vScreen: save original vScreen contents and paint ball bitmap.
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto index = 0u; index < ball_list.size(); ++index)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
auto ball = ball_list[index];
|
|
|
|
auto dirty = &ball->DirtyRect;
|
|
|
|
if (ball->Bmp && maths::rectangle_clip(&ball->BmpRect, &vscreen_rect, &ball->DirtyRect))
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
int xPos = dirty->XPosition;
|
|
|
|
int yPos = dirty->YPosition;
|
2021-10-02 14:45:31 +00:00
|
|
|
gdrv::copy_bitmap(ball_bitmap[index], dirty->Width, dirty->Height, 0, 0, vscreen, xPos, yPos);
|
2020-11-15 14:39:00 +00:00
|
|
|
zdrv::paint_flat(
|
2021-09-25 13:52:19 +00:00
|
|
|
dirty->Width,
|
|
|
|
dirty->Height,
|
2021-10-02 14:45:31 +00:00
|
|
|
vscreen,
|
2020-11-15 14:39:00 +00:00
|
|
|
xPos,
|
|
|
|
yPos,
|
2021-10-02 14:45:31 +00:00
|
|
|
zscreen,
|
2020-11-15 14:39:00 +00:00
|
|
|
xPos,
|
|
|
|
yPos,
|
2021-09-25 13:52:19 +00:00
|
|
|
ball->Bmp,
|
|
|
|
xPos - ball->BmpRect.XPosition,
|
|
|
|
yPos - ball->BmpRect.YPosition,
|
|
|
|
ball->Depth);
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
dirty->Width = -1;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void render::unpaint_balls()
|
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
// Restore portions of vScreen saved during previous paint_balls call.
|
2021-10-02 14:45:31 +00:00
|
|
|
for (int index = static_cast<int>(ball_list.size()) - 1; index >= 0; index--)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
2021-02-09 15:09:44 +00:00
|
|
|
auto curBall = ball_list[index];
|
|
|
|
if (curBall->DirtyRect.Width > 0)
|
|
|
|
gdrv::copy_bitmap(
|
2021-10-02 14:45:31 +00:00
|
|
|
vscreen,
|
2021-02-09 15:09:44 +00:00
|
|
|
curBall->DirtyRect.Width,
|
|
|
|
curBall->DirtyRect.Height,
|
|
|
|
curBall->DirtyRect.XPosition,
|
|
|
|
curBall->DirtyRect.YPosition,
|
2021-10-02 14:45:31 +00:00
|
|
|
ball_bitmap[index],
|
2021-02-09 15:09:44 +00:00
|
|
|
0,
|
|
|
|
0);
|
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
curBall->DirtyRectPrev = curBall->DirtyRect;
|
2020-11-15 14:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
void render::shift(int offsetX, int offsetY)
|
2020-11-15 14:39:00 +00:00
|
|
|
{
|
|
|
|
offset_x += offsetX;
|
|
|
|
offset_y += offsetY;
|
2020-11-08 15:37:59 +00:00
|
|
|
}
|
2020-12-27 15:19:36 +00:00
|
|
|
|
|
|
|
void render::build_occlude_list()
|
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
std::vector<render_sprite_type_struct*>* spriteArr = nullptr;
|
|
|
|
for (auto mainSprite : sprite_list)
|
2020-12-27 15:19:36 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
if (mainSprite->SpriteArray)
|
2020-12-27 15:19:36 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
delete mainSprite->SpriteArray;
|
2021-09-25 13:52:19 +00:00
|
|
|
mainSprite->SpriteArray = nullptr;
|
2020-12-27 15:19:36 +00:00
|
|
|
}
|
2021-09-25 13:52:19 +00:00
|
|
|
|
|
|
|
if (!mainSprite->UnknownFlag && mainSprite->BoundingRect.Width != -1)
|
2020-12-27 15:19:36 +00:00
|
|
|
{
|
|
|
|
if (!spriteArr)
|
2021-10-02 14:45:31 +00:00
|
|
|
spriteArr = new std::vector<render_sprite_type_struct*>();
|
2021-09-25 13:52:19 +00:00
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
for (auto refSprite : sprite_list)
|
2020-12-27 15:19:36 +00:00
|
|
|
{
|
2021-09-25 13:52:19 +00:00
|
|
|
if (!refSprite->UnknownFlag
|
|
|
|
&& refSprite->BoundingRect.Width != -1
|
|
|
|
&& maths::rectangle_clip(&mainSprite->BoundingRect, &refSprite->BoundingRect, nullptr)
|
2020-12-27 15:19:36 +00:00
|
|
|
&& spriteArr)
|
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
spriteArr->push_back(refSprite);
|
2020-12-27 15:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-25 13:52:19 +00:00
|
|
|
|
2021-10-23 04:33:04 +00:00
|
|
|
if (mainSprite->Bmp && spriteArr->size() < 2)
|
2021-10-02 14:45:31 +00:00
|
|
|
spriteArr->clear();
|
|
|
|
if (!spriteArr->empty())
|
2020-12-27 15:19:36 +00:00
|
|
|
{
|
2021-10-02 14:45:31 +00:00
|
|
|
mainSprite->SpriteArray = spriteArr;
|
2020-12-27 15:19:36 +00:00
|
|
|
spriteArr = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-02 14:45:31 +00:00
|
|
|
delete spriteArr;
|
2020-12-27 15:19:36 +00:00
|
|
|
}
|
2021-09-21 10:14:39 +00:00
|
|
|
|
|
|
|
void render::SpriteViewer(bool* show)
|
|
|
|
{
|
|
|
|
static const char* BitmapTypes[] =
|
|
|
|
{
|
|
|
|
"None",
|
|
|
|
"RawBitmap",
|
|
|
|
"DibBitmap",
|
|
|
|
"Spliced",
|
|
|
|
};
|
|
|
|
static float scale = 1.0f;
|
|
|
|
auto uv_min = ImVec2(0.0f, 0.0f); // Top-left
|
|
|
|
auto uv_max = ImVec2(1.0f, 1.0f); // Lower-right
|
|
|
|
auto tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
|
|
|
|
auto border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); // 50% opaque white
|
|
|
|
|
|
|
|
if (ImGui::Begin("Sprite viewer", show, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_MenuBar))
|
|
|
|
{
|
|
|
|
if (ImGui::BeginMenuBar())
|
|
|
|
{
|
|
|
|
ImGui::SliderFloat("Sprite scale", &scale, 0.1f, 10.0f, "scale = %.3f");
|
|
|
|
ImGui::EndMenuBar();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto group : pb::record_table->Groups)
|
|
|
|
{
|
|
|
|
bool emptyGroup = true;
|
|
|
|
for (int i = 0; i <= 2; i++)
|
|
|
|
{
|
|
|
|
auto bmp = group->GetBitmap(i);
|
|
|
|
if (bmp)
|
|
|
|
{
|
|
|
|
emptyGroup = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (emptyGroup)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ImGui::Text("Group: %d, name:%s", group->GroupId, group->GroupName.c_str());
|
|
|
|
for (int i = 0; i <= 2; i++)
|
|
|
|
{
|
|
|
|
auto bmp = group->GetBitmap(i);
|
|
|
|
if (!bmp)
|
|
|
|
continue;
|
|
|
|
|
2021-10-01 15:55:44 +00:00
|
|
|
auto type = BitmapTypes[static_cast<uint8_t>(bmp->BitmapType)];
|
2021-09-21 10:14:39 +00:00
|
|
|
ImGui::Text("type:%s, size:%d, resolution: %dx%d, offset:%dx%d", type,
|
|
|
|
bmp->Resolution,
|
|
|
|
bmp->Width, bmp->Height, bmp->XPosition, bmp->YPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int same = 0, i = 0; i <= 2; i++)
|
|
|
|
{
|
|
|
|
auto bmp = group->GetBitmap(i);
|
|
|
|
if (!bmp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gdrv::CreatePreview(*bmp);
|
|
|
|
if (bmp->Texture)
|
|
|
|
{
|
|
|
|
if (!same)
|
|
|
|
same = true;
|
|
|
|
else
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
ImGui::Image(bmp->Texture, ImVec2(bmp->Width * scale, bmp->Height * scale),
|
|
|
|
uv_min, uv_max, tint_col, border_col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int same = 0, i = 0; i <= 2; i++)
|
|
|
|
{
|
|
|
|
auto zMap = group->GetZMap(i);
|
|
|
|
if (!zMap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
zdrv::CreatePreview(*zMap);
|
|
|
|
if (zMap->Texture)
|
|
|
|
{
|
|
|
|
if (!same)
|
|
|
|
same = true;
|
|
|
|
else
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::Image(zMap->Texture, ImVec2(zMap->Width * scale, zMap->Height * scale),
|
|
|
|
uv_min, uv_max, tint_col, border_col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
2021-09-25 13:52:19 +00:00
|
|
|
|
2021-10-24 04:13:51 +00:00
|
|
|
void render::PresentVScreen()
|
|
|
|
{
|
2021-11-11 11:30:56 +00:00
|
|
|
vscreen->BlitToTexture();
|
2021-10-24 04:13:51 +00:00
|
|
|
|
2021-09-25 13:52:19 +00:00
|
|
|
if (offset_x == 0 && offset_y == 0)
|
|
|
|
{
|
2021-11-11 11:30:56 +00:00
|
|
|
SDL_RenderCopy(winmain::Renderer, vscreen->Texture, nullptr, &DestinationRect);
|
2021-09-25 13:52:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-25 05:03:30 +00:00
|
|
|
auto tableWidthCoef = static_cast<float>(pb::MainTable->Width) / vscreen->Width;
|
|
|
|
auto srcSeparationX = static_cast<int>(round(vscreen->Width * tableWidthCoef));
|
|
|
|
auto srcBoardRect = SDL_Rect
|
2021-09-25 13:52:19 +00:00
|
|
|
{
|
2021-10-24 04:13:51 +00:00
|
|
|
0, 0,
|
|
|
|
srcSeparationX, vscreen->Height
|
|
|
|
};
|
2021-10-25 05:03:30 +00:00
|
|
|
auto srcSidebarRect = SDL_Rect
|
2021-09-25 13:52:19 +00:00
|
|
|
{
|
2021-10-24 04:13:51 +00:00
|
|
|
srcSeparationX, 0,
|
|
|
|
vscreen->Width - srcSeparationX, vscreen->Height
|
|
|
|
};
|
|
|
|
|
2021-10-25 05:03:30 +00:00
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 10)
|
|
|
|
// SDL_RenderCopyF was added in 2.0.10
|
|
|
|
auto dstSeparationX = DestinationRect.w * tableWidthCoef;
|
|
|
|
auto dstBoardRect = SDL_FRect
|
|
|
|
{
|
|
|
|
DestinationRect.x + offset_x * fullscrn::ScaleX,
|
|
|
|
DestinationRect.y + offset_y * fullscrn::ScaleY,
|
|
|
|
dstSeparationX, static_cast<float>(DestinationRect.h)
|
|
|
|
};
|
|
|
|
auto dstSidebarRect = SDL_FRect
|
|
|
|
{
|
|
|
|
DestinationRect.x + dstSeparationX, static_cast<float>(DestinationRect.y),
|
|
|
|
DestinationRect.w - dstSeparationX, static_cast<float>(DestinationRect.h)
|
|
|
|
};
|
2021-10-24 04:13:51 +00:00
|
|
|
|
2021-11-11 11:30:56 +00:00
|
|
|
SDL_RenderCopyF(winmain::Renderer, vscreen->Texture, &srcBoardRect, &dstBoardRect);
|
|
|
|
SDL_RenderCopyF(winmain::Renderer, vscreen->Texture, &srcSidebarRect, &dstSidebarRect);
|
2021-10-25 05:03:30 +00:00
|
|
|
#else
|
|
|
|
// SDL_RenderCopy cannot express sub pixel offset.
|
|
|
|
// Vscreen shift is required for that.
|
|
|
|
auto dstSeparationX = static_cast<int>(DestinationRect.w * tableWidthCoef);
|
|
|
|
auto scaledOffX = static_cast<int>(round(offset_x * fullscrn::ScaleX));
|
|
|
|
if (offset_x != 0 && scaledOffX == 0)
|
|
|
|
scaledOffX = Sign(offset_x);
|
|
|
|
auto scaledOffY = static_cast<int>(round(offset_y * fullscrn::ScaleY));
|
|
|
|
if (offset_y != 0 && scaledOffX == 0)
|
|
|
|
scaledOffY = Sign(offset_y);
|
|
|
|
|
|
|
|
auto dstBoardRect = SDL_Rect
|
2021-09-25 13:52:19 +00:00
|
|
|
{
|
2021-10-25 05:03:30 +00:00
|
|
|
DestinationRect.x + scaledOffX, DestinationRect.y + scaledOffY,
|
2021-10-24 04:13:51 +00:00
|
|
|
dstSeparationX, DestinationRect.h
|
|
|
|
};
|
2021-10-25 05:03:30 +00:00
|
|
|
auto dstSidebarRect = SDL_Rect
|
2021-09-25 13:52:19 +00:00
|
|
|
{
|
2021-10-24 04:13:51 +00:00
|
|
|
DestinationRect.x + dstSeparationX, DestinationRect.y,
|
|
|
|
DestinationRect.w - dstSeparationX, DestinationRect.h
|
|
|
|
};
|
2021-09-25 13:52:19 +00:00
|
|
|
|
2021-11-11 11:30:56 +00:00
|
|
|
SDL_RenderCopy(winmain::Renderer, vscreen->Texture, &srcBoardRect, &dstBoardRect);
|
|
|
|
SDL_RenderCopy(winmain::Renderer, vscreen->Texture, &srcSidebarRect, &dstSidebarRect);
|
2021-10-25 05:03:30 +00:00
|
|
|
#endif
|
2021-09-25 13:52:19 +00:00
|
|
|
}
|
|
|
|
}
|