1
0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-21 18:22:40 +01:00

Render tweaks part 3: bitmap/zMap pairs.

This commit is contained in:
Muzychenko Andrey 2022-09-29 14:45:14 +03:00
parent e7ddebd16c
commit 4ec30cf472
6 changed files with 37 additions and 35 deletions

View File

@ -30,7 +30,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false)
Position.X = 0.0;
Position.Y = 0.0;
ListBitmap = new std::vector<gdrv_bitmap8*>();
ListBitmap = new std::vector<SpriteData>();
/*Full tilt: ball is ballN, where N[0,2] resolution*/
auto groupIndex = loader::query_handle(ballGroupName);

View File

@ -18,7 +18,6 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
PinballTable = table;
RenderSprite = nullptr;
ListBitmap = nullptr;
ListZMap = nullptr;
GroupName = nullptr;
Control = nullptr;
VisualPosNormX= -1.0f;
@ -35,31 +34,29 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
for (int index = 0; index < visualCount; ++index)
{
loader::query_visual(groupIndex, index, &visual);
if (visual.Bitmap)
if (visual.Bitmap.Bmp)
{
assertm(visual.Bitmap.ZMap, "Bitmap/zMap pairing is mandatory");
if (!ListBitmap)
ListBitmap = new std::vector<gdrv_bitmap8*>();
ListBitmap = new std::vector<SpriteData>();
ListBitmap->push_back(visual.Bitmap);
}
if (visual.ZMap)
{
if (!ListZMap)
ListZMap = new std::vector<zmap_header_type*>();
ListZMap->push_back(visual.ZMap);
}
}
if (ListBitmap)
{
rectangle_type bmp1Rect{}, tmpRect{};
auto rootBmp = ListBitmap->at(0);
const auto rootSprite = ListBitmap->at(0);
const auto rootBmp = rootSprite.Bmp;
bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset;
bmp1Rect.YPosition = rootBmp->YPosition - table->YOffset;
bmp1Rect.Width = rootBmp->Width;
bmp1Rect.Height = rootBmp->Height;
for (auto index = 1u; index < ListBitmap->size(); index++)
{
auto bmp = ListBitmap->at(index);
auto bmp = ListBitmap->at(index).Bmp;
tmpRect.XPosition = bmp->XPosition - table->XOffset;
tmpRect.YPosition = bmp->YPosition - table->YOffset;
tmpRect.Width = bmp->Width;
@ -67,12 +64,10 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
maths::enclosing_box(bmp1Rect, tmpRect, bmp1Rect);
}
assertm(ListZMap, "All sprites should have bitmap/zMap pairs");
auto zMap = ListZMap ? ListZMap->at(0) : nullptr;
RenderSprite = new render_sprite(
VisualTypes::Sprite,
rootBmp,
zMap,
rootSprite.ZMap,
rootBmp->XPosition - table->XOffset,
rootBmp->YPosition - table->YOffset,
&bmp1Rect);
@ -101,7 +96,6 @@ TPinballComponent::~TPinballComponent()
}
delete ListBitmap;
delete ListZMap;
}
@ -137,8 +131,9 @@ void TPinballComponent::SpriteSet(int index) const
zmap_header_type* zMap;
if (index >= 0)
{
bmp = ListBitmap->at(index);
zMap = ListZMap->at(index);
auto& spriteData = ListBitmap->at(index);
bmp = spriteData.Bmp;
zMap = spriteData.ZMap;
xPos = bmp->XPosition - PinballTable->XOffset;
yPos = bmp->YPosition - PinballTable->YOffset;
}
@ -157,12 +152,14 @@ void TPinballComponent::SpriteSetBall(int index, vector2i pos, float depth) cons
{
if (ListBitmap)
{
auto bmp = index >= 0 ? ListBitmap->at(index) : nullptr;
if (bmp)
gdrv_bitmap8* bmp = nullptr;
if (index >= 0)
{
bmp = ListBitmap->at(index).Bmp;
pos.X -= bmp->Width / 2;
pos.Y -= bmp->Height / 2;
}
RenderSprite->ball_set(bmp, depth, pos.X, pos.Y);
}
}

View File

@ -1,5 +1,6 @@
#pragma once
struct SpriteData;
struct vector2i;
struct zmap_header_type;
struct gdrv_bitmap8;
@ -150,8 +151,7 @@ public:
int GroupIndex;
render_sprite* RenderSprite;
TPinballTable* PinballTable;
std::vector<gdrv_bitmap8*>* ListBitmap;
std::vector<zmap_header_type*>* ListZMap;
std::vector<SpriteData>* ListBitmap;
private:
float VisualPosNormX;
float VisualPosNormY;

View File

@ -20,19 +20,20 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f
auto groupIndex = loader::query_handle("table");
loader::query_visual(groupIndex, 0, &visual);
auto spriteData = visual.Bitmap;
/*Full tilt: proj center first value is offset by resolution*/
auto projCenter = loader::query_float_attribute(groupIndex, 0, 700 + fullscrn::GetResolution());
proj::recenter(projCenter[0], projCenter[1]);
render::set_background_zmap(visual.ZMap, 0, 0);
render::set_background_zmap(spriteData.ZMap, 0, 0);
auto bmp = visual.Bitmap;
VisBmp = visual.Bitmap;
auto bmp = spriteData.Bmp;
VisBmp = bmp;
rect.XPosition = 0;
rect.YPosition = 0;
rect.Width = bmp->Width;
rect.Height = bmp->Height;
new render_sprite(VisualTypes::Background, bmp, visual.ZMap, 0, 0, &rect);
new render_sprite(VisualTypes::Background, bmp, spriteData.ZMap, 0, 0, &rect);
PinballTable->SoundIndex1 = visual.SoundIndex4;
PinballTable->SoundIndex2 = visual.SoundIndex3;

View File

@ -75,8 +75,7 @@ void loader::default_vsi(visualStruct* visual)
visual->Elasticity = 0.60000002f;
visual->FloatArrCount = 0;
visual->SoftHitSoundId = 0;
visual->Bitmap = nullptr;
visual->ZMap = nullptr;
visual->Bitmap = { nullptr, nullptr };
visual->SoundIndex3 = 0;
visual->SoundIndex4 = 0;
}
@ -421,8 +420,9 @@ int loader::query_visual(int groupIndex, int groupIndexOffset, visualStruct* vis
if (stateId < 0)
return error(16, 18);
visual->Bitmap = loader_table->GetBitmap(stateId);
visual->ZMap = loader_table->GetZMap(stateId);
auto bmp = loader_table->GetBitmap(stateId);
auto zMap = loader_table->GetZMap(stateId);
visual->Bitmap = { bmp, zMap };
auto shortArr = reinterpret_cast<int16_t*>(loader_table->field(stateId, FieldTypes::ShortArray));
if (shortArr)

View File

@ -1,10 +1,10 @@
#pragma once
#include "gdrv.h"
#include "maths.h"
#include "zdrv.h"
#include "TPinballComponent.h"
class TPinballComponent;
struct zmap_header_type;
struct gdrv_bitmap8;
class DatFile;
struct errorMsg
@ -31,6 +31,11 @@ struct visualKickerStruct
int HardHitSoundId;
};
struct SpriteData
{
gdrv_bitmap8* Bmp;
zmap_header_type* ZMap;
};
struct visualStruct
{
@ -43,8 +48,7 @@ struct visualStruct
int CollisionGroup;
int SoundIndex4;
int SoundIndex3;
gdrv_bitmap8* Bitmap;
zmap_header_type* ZMap;
SpriteData Bitmap;
};
#pragma pack(push)