From 4ec30cf4726ae6c75fbffdaa5464c40209e96a31 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Thu, 29 Sep 2022 14:45:14 +0300 Subject: [PATCH] Render tweaks part 3: bitmap/zMap pairs. --- SpaceCadetPinball/TBall.cpp | 2 +- SpaceCadetPinball/TPinballComponent.cpp | 35 +++++++++++-------------- SpaceCadetPinball/TPinballComponent.h | 4 +-- SpaceCadetPinball/TTableLayer.cpp | 9 ++++--- SpaceCadetPinball/loader.cpp | 8 +++--- SpaceCadetPinball/loader.h | 14 ++++++---- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index b65466e..c6881b7 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -30,7 +30,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) Position.X = 0.0; Position.Y = 0.0; - ListBitmap = new std::vector(); + ListBitmap = new std::vector(); /*Full tilt: ball is ballN, where N[0,2] resolution*/ auto groupIndex = loader::query_handle(ballGroupName); diff --git a/SpaceCadetPinball/TPinballComponent.cpp b/SpaceCadetPinball/TPinballComponent.cpp index 6c3d14c..317be2c 100644 --- a/SpaceCadetPinball/TPinballComponent.cpp +++ b/SpaceCadetPinball/TPinballComponent.cpp @@ -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(); + ListBitmap = new std::vector(); ListBitmap->push_back(visual.Bitmap); } - if (visual.ZMap) - { - if (!ListZMap) - ListZMap = new std::vector(); - 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); } } diff --git a/SpaceCadetPinball/TPinballComponent.h b/SpaceCadetPinball/TPinballComponent.h index e766c95..e0ccd71 100644 --- a/SpaceCadetPinball/TPinballComponent.h +++ b/SpaceCadetPinball/TPinballComponent.h @@ -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* ListBitmap; - std::vector* ListZMap; + std::vector* ListBitmap; private: float VisualPosNormX; float VisualPosNormY; diff --git a/SpaceCadetPinball/TTableLayer.cpp b/SpaceCadetPinball/TTableLayer.cpp index d558f8e..c1d3932 100644 --- a/SpaceCadetPinball/TTableLayer.cpp +++ b/SpaceCadetPinball/TTableLayer.cpp @@ -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; diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index df5a572..1551094 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -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(loader_table->field(stateId, FieldTypes::ShortArray)); if (shortArr) diff --git a/SpaceCadetPinball/loader.h b/SpaceCadetPinball/loader.h index d9085ac..ea4176c 100644 --- a/SpaceCadetPinball/loader.h +++ b/SpaceCadetPinball/loader.h @@ -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)