SpaceCadetPinball/SpaceCadetPinball/TPinballComponent.cpp

134 lines
3.2 KiB
C++
Raw Normal View History

#include "pch.h"
#include "TPinballComponent.h"
#include "loader.h"
#include "objlist_class.h"
2020-11-08 16:37:59 +01:00
#include "render.h"
#include "TPinballTable.h"
TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool loadVisuals)
{
visualStruct visual{};
2020-11-08 16:37:59 +01:00
MessageField = 0;
2021-01-28 16:01:26 +01:00
UnusedBaseFlag = 0;
ActiveFlag = 0;
2020-11-08 16:37:59 +01:00
PinballTable = table;
RenderSprite = nullptr;
ListBitmap = nullptr;
ListZMap = nullptr;
2021-01-05 13:12:54 +01:00
GroupName = nullptr;
Control = nullptr;
if (table)
table->ComponentList->Add(this);
if (groupIndex >= 0)
2020-11-08 16:37:59 +01:00
GroupName = loader::query_name(groupIndex);
if (loadVisuals && groupIndex >= 0)
{
int visualCount = loader::query_visual_states(groupIndex);
for (int index = 0; index < visualCount; ++index)
{
loader::query_visual(groupIndex, index, &visual);
2020-11-08 16:37:59 +01:00
if (visual.Bitmap)
{
2020-11-08 16:37:59 +01:00
if (!ListBitmap)
2021-01-30 12:19:25 +01:00
ListBitmap = new objlist_class<gdrv_bitmap8>(visualCount, 4);
2020-11-08 16:37:59 +01:00
if (ListBitmap)
ListBitmap->Add(visual.Bitmap);
}
2020-11-08 16:37:59 +01:00
if (visual.ZMap)
{
2020-11-08 16:37:59 +01:00
if (!ListZMap)
2021-01-30 12:19:25 +01:00
ListZMap = new objlist_class<zmap_header_type>(visualCount, 4);
2020-11-08 16:37:59 +01:00
if (ListZMap)
ListZMap->Add(visual.ZMap);
}
}
2020-11-08 16:37:59 +01:00
zmap_header_type* zMap = nullptr;
if (ListZMap)
2021-01-30 12:19:25 +01:00
zMap = ListZMap->Get(0);
2020-11-08 16:37:59 +01:00
if (ListBitmap)
{
/* Full tilt hack - spliced bitmap includes zMap
* Users access bitmap-zMap in pairs, pad zMap list with 0 for such users
* zdrv does not access zMap when drawing spliced bitmap*/
if (!ListZMap)
{
ListZMap = new objlist_class<zmap_header_type>(0, 4);
for (int index = 0; index < ListBitmap->GetCount(); index++)
{
assertm(ListBitmap->Get(index)->BitmapType == BitmapType::Spliced, "Wrong zMap padding");
ListZMap->Add(visual.ZMap);
}
}
2020-11-15 15:39:00 +01:00
rectangle_type bmp1Rect{}, tmpRect{};
2021-01-30 12:19:25 +01:00
auto rootBmp = ListBitmap->Get(0);
2020-11-08 16:37:59 +01:00
bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset;
bmp1Rect.YPosition = rootBmp->YPosition - table->YOffset;
bmp1Rect.Width = rootBmp->Width;
bmp1Rect.Height = rootBmp->Height;
2021-01-30 12:19:25 +01:00
for (int index = 1; index < ListBitmap->GetCount(); index++)
{
2021-01-30 12:19:25 +01:00
auto bmp = ListBitmap->Get(index);
2020-11-08 16:37:59 +01:00
tmpRect.XPosition = bmp->XPosition - table->XOffset;
tmpRect.YPosition = bmp->YPosition - table->YOffset;
tmpRect.Width = bmp->Width;
tmpRect.Height = bmp->Height;
maths::enclosing_box(&bmp1Rect, &tmpRect, &bmp1Rect);
}
2020-11-08 16:37:59 +01:00
RenderSprite = render::create_sprite(
2021-01-05 13:12:54 +01:00
visualCount > 0 ? VisualType::Sprite : VisualType::None,
2020-11-08 16:37:59 +01:00
rootBmp,
zMap,
rootBmp->XPosition - table->XOffset,
rootBmp->YPosition - table->YOffset,
&bmp1Rect);
}
}
2020-11-08 16:37:59 +01:00
GroupIndex = groupIndex;
}
2020-11-04 14:22:52 +01:00
TPinballComponent::~TPinballComponent()
{
TPinballTable* table = PinballTable;
if (table)
table->ComponentList->Delete(this);
2020-11-04 14:22:52 +01:00
2020-11-08 16:37:59 +01:00
delete ListBitmap;
delete ListZMap;
2020-11-04 14:22:52 +01:00
}
int TPinballComponent::Message(int code, float value)
2020-11-04 14:22:52 +01:00
{
MessageField = code;
if (code == 1024)
2020-11-08 16:37:59 +01:00
MessageField = 0;
2020-11-04 14:22:52 +01:00
return 0;
}
void TPinballComponent::port_draw()
{
}
void TPinballComponent::put_scoring(int index, int score)
2020-11-08 16:37:59 +01:00
{
2020-11-04 14:22:52 +01:00
}
int TPinballComponent::get_scoring(int index)
2020-11-04 14:22:52 +01:00
{
return 0;
2020-11-08 16:37:59 +01:00
}
2021-01-18 16:30:19 +01:00
void* TPinballComponent::operator new(size_t Size)
{
return calloc(1u, Size);
}
void TPinballComponent::operator delete(void* p)
{
free(p); /*Original does not have this*/
}