From 6ff457eb6806fd11b9981a423c03b2dfc0259419 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sat, 30 Jan 2021 14:19:25 +0300 Subject: [PATCH] Cleaned up objlist_class. --- SpaceCadetPinball/SpaceCadetPinball.cpp | 2 +- SpaceCadetPinball/SpaceCadetPinball.vcxproj | 2 - .../SpaceCadetPinball.vcxproj.filters | 6 - SpaceCadetPinball/TBall.cpp | 7 +- SpaceCadetPinball/TBlocker.cpp | 4 +- SpaceCadetPinball/TBumper.cpp | 16 +-- SpaceCadetPinball/TCollisionComponent.cpp | 10 +- SpaceCadetPinball/TCollisionComponent.h | 3 +- SpaceCadetPinball/TComponentGroup.cpp | 6 +- SpaceCadetPinball/TComponentGroup.h | 3 +- SpaceCadetPinball/TEdgeBox.cpp | 4 +- SpaceCadetPinball/TEdgeBox.h | 10 +- SpaceCadetPinball/TEdgeManager.cpp | 8 +- SpaceCadetPinball/TFlagSpinner.cpp | 11 +- SpaceCadetPinball/TFlipper.cpp | 14 +-- SpaceCadetPinball/TGate.cpp | 6 +- SpaceCadetPinball/TKickback.cpp | 10 +- SpaceCadetPinball/TLight.cpp | 14 +-- SpaceCadetPinball/TLightBargraph.cpp | 4 +- SpaceCadetPinball/TLightGroup.cpp | 114 +++++++++--------- SpaceCadetPinball/TLightGroup.h | 6 +- SpaceCadetPinball/TLightRollover.cpp | 4 +- SpaceCadetPinball/TPinballComponent.cpp | 13 +- SpaceCadetPinball/TPinballComponent.h | 8 +- SpaceCadetPinball/TPinballTable.cpp | 46 +++---- SpaceCadetPinball/TPinballTable.h | 6 +- SpaceCadetPinball/TPlunger.cpp | 20 +-- SpaceCadetPinball/TPopupTarget.cpp | 4 +- SpaceCadetPinball/TRollover.cpp | 8 +- SpaceCadetPinball/TSink.cpp | 2 +- SpaceCadetPinball/TSoloTarget.cpp | 6 +- SpaceCadetPinball/TTextBox.cpp | 2 +- SpaceCadetPinball/TWall.cpp | 4 +- SpaceCadetPinball/TZmapList.h | 15 --- SpaceCadetPinball/WaveMix.cpp | 6 +- SpaceCadetPinball/control.cpp | 4 +- SpaceCadetPinball/loader.cpp | 2 +- SpaceCadetPinball/nudge.cpp | 4 +- SpaceCadetPinball/objlist_class.cpp | 94 --------------- SpaceCadetPinball/objlist_class.h | 88 +++++++++++--- SpaceCadetPinball/pb.cpp | 18 +-- SpaceCadetPinball/score.cpp | 2 +- 42 files changed, 276 insertions(+), 340 deletions(-) delete mode 100644 SpaceCadetPinball/TZmapList.h delete mode 100644 SpaceCadetPinball/objlist_class.cpp diff --git a/SpaceCadetPinball/SpaceCadetPinball.cpp b/SpaceCadetPinball/SpaceCadetPinball.cpp index 1bd6890..e5a423f 100644 --- a/SpaceCadetPinball/SpaceCadetPinball.cpp +++ b/SpaceCadetPinball/SpaceCadetPinball.cpp @@ -29,7 +29,7 @@ int main() auto dib = gdrv::DibCreate(8, 1, 1); gdrv::DibSetUsage(dib, 0, 1); - objlist_class d = objlist_class(2, 4); + auto d = objlist_class(2, 4); for (int i = 0; i < 100; i++) { d.Add((void*)i); diff --git a/SpaceCadetPinball/SpaceCadetPinball.vcxproj b/SpaceCadetPinball/SpaceCadetPinball.vcxproj index c86fcf8..647c3a0 100644 --- a/SpaceCadetPinball/SpaceCadetPinball.vcxproj +++ b/SpaceCadetPinball/SpaceCadetPinball.vcxproj @@ -219,7 +219,6 @@ - @@ -234,7 +233,6 @@ - diff --git a/SpaceCadetPinball/SpaceCadetPinball.vcxproj.filters b/SpaceCadetPinball/SpaceCadetPinball.vcxproj.filters index 36d606f..89692b0 100644 --- a/SpaceCadetPinball/SpaceCadetPinball.vcxproj.filters +++ b/SpaceCadetPinball/SpaceCadetPinball.vcxproj.filters @@ -81,9 +81,6 @@ Header Files\TPinballComponent - - Header Files\TPinballComponent - Header Files @@ -236,9 +233,6 @@ Source Files - - Source Files - Source Files diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index a1f9c7e..e6c5659 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -8,7 +8,6 @@ #include "proj.h" #include "render.h" #include "TPinballTable.h" -#include "TZmapList.h" TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) { @@ -30,7 +29,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) Position.X = 0.0; Position.Y = 0.0; - ListBitmap = new TZmapList(0, 4); + ListBitmap = new objlist_class(0, 4); auto groupIndex = loader::query_handle("ball"); Offset = *loader::query_float_attribute(groupIndex, 0, 500); auto visualCount = loader::query_visual_states(groupIndex); @@ -73,12 +72,12 @@ void TBall::Repaint() auto zArrPtr = VisualZArray; int index; - for (index = 0; index < ListBitmap->Count() - 1; ++index, zArrPtr++) + for (index = 0; index < ListBitmap->GetCount() - 1; ++index, zArrPtr++) { if (*zArrPtr <= zDepth) break; } - auto bmp = static_cast(ListBitmap->Get(index)); + auto bmp = ListBitmap->Get(index); render::ball_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TBlocker.cpp b/SpaceCadetPinball/TBlocker.cpp index 711a5fc..f3458e4 100644 --- a/SpaceCadetPinball/TBlocker.cpp +++ b/SpaceCadetPinball/TBlocker.cpp @@ -4,9 +4,9 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" -#include "TZmapList.h" TBlocker::TBlocker(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -46,7 +46,7 @@ int TBlocker::Message(int code, float value) case 52: ActiveFlag = 1; loader::play_sound(SoundIndex4); - render::sprite_set_bitmap(RenderSprite, static_cast(ListBitmap->Get(0))); + render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); break; case 59: break; diff --git a/SpaceCadetPinball/TBumper.cpp b/SpaceCadetPinball/TBumper.cpp index ad5a2d0..bba3fc6 100644 --- a/SpaceCadetPinball/TBumper.cpp +++ b/SpaceCadetPinball/TBumper.cpp @@ -4,10 +4,10 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TBumper::TBumper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -29,8 +29,8 @@ int TBumper::Message(int code, float value) case 11: { auto nextBmp = static_cast(floor(value)); - if (2 * nextBmp > ListBitmap->Count() - 1) - nextBmp = (ListBitmap->Count() - 1) / 2; + if (2 * nextBmp > ListBitmap->GetCount() - 1) + nextBmp = (ListBitmap->GetCount() - 1) / 2; if (nextBmp < 0) nextBmp = 0; if (nextBmp != BmpIndex) @@ -48,7 +48,7 @@ int TBumper::Message(int code, float value) case 12: { auto nextBmp = BmpIndex + 1; - auto maxBmp = ListBitmap->Count() - 1; + auto maxBmp = ListBitmap->GetCount() - 1; if (2 * nextBmp > maxBmp) nextBmp = maxBmp / 2; TBumper::Message(11, static_cast(nextBmp)); @@ -124,8 +124,8 @@ int TBumper::get_scoring(int index) void TBumper::TimerExpired(int timerId, void* caller) { auto bump = static_cast(caller); - auto bmp = static_cast(bump->ListBitmap->Get(bump->BmpIndex * 2)); - auto zMap = static_cast(bump->ListZMap->Get(bump->BmpIndex * 2)); + auto bmp = bump->ListBitmap->Get(bump->BmpIndex * 2); + auto zMap = bump->ListZMap->Get(bump->BmpIndex * 2); bump->Timer = 0; render::sprite_set( bump->RenderSprite, @@ -139,8 +139,8 @@ void TBumper::TimerExpired(int timerId, void* caller) void TBumper::Fire() { int bmpIndex = 2 * BmpIndex + 1; - auto bmp = static_cast(ListBitmap->Get(bmpIndex)); - auto zMap = static_cast(ListZMap->Get(bmpIndex)); + auto bmp = ListBitmap->Get(bmpIndex); + auto zMap = ListZMap->Get(bmpIndex); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TCollisionComponent.cpp b/SpaceCadetPinball/TCollisionComponent.cpp index 2cdfd95..1fdbe4e 100644 --- a/SpaceCadetPinball/TCollisionComponent.cpp +++ b/SpaceCadetPinball/TCollisionComponent.cpp @@ -12,7 +12,7 @@ TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, b { visualStruct visual{}; - EdgeList = new objlist_class(4, 4); + EdgeList = new objlist_class(4, 4); ActiveFlag = 1; if (GroupName != nullptr) UnusedBaseFlag = 1; @@ -42,9 +42,9 @@ TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, b TCollisionComponent::~TCollisionComponent() { - for (TEdgeSegment* edge; EdgeList->Count() > 0;) + for (TEdgeSegment* edge; EdgeList->GetCount() > 0;) { - edge = static_cast(EdgeList->Get(0)); + edge = EdgeList->Get(0); EdgeList->Delete(edge); delete edge; } @@ -54,9 +54,9 @@ TCollisionComponent::~TCollisionComponent() void TCollisionComponent::port_draw() { - for (int index = EdgeList->Count() - 1; index >= 0; index--) + for (int index = EdgeList->GetCount() - 1; index >= 0; index--) { - static_cast(EdgeList->Get(index))->port_draw(); + EdgeList->Get(index)->port_draw(); } } diff --git a/SpaceCadetPinball/TCollisionComponent.h b/SpaceCadetPinball/TCollisionComponent.h index 6a72219..82707a9 100644 --- a/SpaceCadetPinball/TCollisionComponent.h +++ b/SpaceCadetPinball/TCollisionComponent.h @@ -1,7 +1,6 @@ #pragma once #include "TPinballComponent.h" -class objlist_class; struct vector_type; class TEdgeSegment; class TBall; @@ -9,7 +8,7 @@ class TBall; class TCollisionComponent : public TPinballComponent { public: - objlist_class* EdgeList; + objlist_class* EdgeList; float Elasticity; float Smoothness; float Boost; diff --git a/SpaceCadetPinball/TComponentGroup.cpp b/SpaceCadetPinball/TComponentGroup.cpp index e94a19d..7f14b34 100644 --- a/SpaceCadetPinball/TComponentGroup.cpp +++ b/SpaceCadetPinball/TComponentGroup.cpp @@ -10,7 +10,7 @@ TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) { - List = new objlist_class(4, 4); + List = new objlist_class(4, 4); Timer = 0; if (groupIndex > 0) { @@ -50,9 +50,9 @@ int TComponentGroup::Message(int code, float value) } else if (code <= 1007 || code > 1011 && code != 1020 && code != 1022) { - for (int i = 0; i < List->Count(); i++) + for (int i = 0; i < List->GetCount(); i++) { - static_cast(List->Get(i))->Message(code, value); + List->Get(i)->Message(code, value); } } return 0; diff --git a/SpaceCadetPinball/TComponentGroup.h b/SpaceCadetPinball/TComponentGroup.h index ec44329..e83c6b3 100644 --- a/SpaceCadetPinball/TComponentGroup.h +++ b/SpaceCadetPinball/TComponentGroup.h @@ -1,7 +1,6 @@ #pragma once #include "TPinballComponent.h" -class objlist_class; class TComponentGroup : public TPinballComponent @@ -12,6 +11,6 @@ public: int Message(int code, float value) override; static void NotifyTimerExpired(int timerId, void* caller); - objlist_class* List; + objlist_class* List; int Timer; }; diff --git a/SpaceCadetPinball/TEdgeBox.cpp b/SpaceCadetPinball/TEdgeBox.cpp index 6d998b5..05575df 100644 --- a/SpaceCadetPinball/TEdgeBox.cpp +++ b/SpaceCadetPinball/TEdgeBox.cpp @@ -5,8 +5,8 @@ TEdgeBox::TEdgeBox() { - EdgeList = new objlist_class(0, 4); - FieldList = new objlist_class(0, 1); + EdgeList = new objlist_class(0, 4); + FieldList = new objlist_class(0, 1); } TEdgeBox::~TEdgeBox() diff --git a/SpaceCadetPinball/TEdgeBox.h b/SpaceCadetPinball/TEdgeBox.h index 4a25313..aac6312 100644 --- a/SpaceCadetPinball/TEdgeBox.h +++ b/SpaceCadetPinball/TEdgeBox.h @@ -1,5 +1,9 @@ #pragma once -class objlist_class; +#include "objlist_class.h" + + +struct field_effect_type; +class TEdgeSegment; class TEdgeBox { @@ -7,7 +11,7 @@ public: TEdgeBox(); ~TEdgeBox(); - objlist_class* EdgeList; - objlist_class* FieldList; + objlist_class* EdgeList; + objlist_class* FieldList; }; diff --git a/SpaceCadetPinball/TEdgeManager.cpp b/SpaceCadetPinball/TEdgeManager.cpp index 783b282..8872601 100644 --- a/SpaceCadetPinball/TEdgeManager.cpp +++ b/SpaceCadetPinball/TEdgeManager.cpp @@ -64,9 +64,9 @@ int TEdgeManager::TestGridBox(int x, int y, float* distPtr, TEdgeSegment** edgeD { TEdgeBox* edgeBox = &BoxArray[x + y * MaxBoxX]; TEdgeSegment** edgePtr = &EdgeArray[edgeIndex]; - for (auto index = edgeBox->EdgeList->Count() - 1; index >= 0; --index) + for (auto index = edgeBox->EdgeList->GetCount() - 1; index >= 0; --index) { - auto edge = static_cast(edgeBox->EdgeList->Get(index)); + auto edge = edgeBox->EdgeList->Get(index); if (!edge->ProcessedFlag && *edge->ActiveFlag && (edge->CollisionGroup & ray->FieldFlag)) { if (!ball->already_hit(edge)) @@ -94,9 +94,9 @@ void TEdgeManager::FieldEffects(TBall* ball, vector_type* dstVec) TEdgeBox* edgeBox = &BoxArray[box_x(ball->Position.X) + box_y(ball->Position.Y) * MaxBoxX]; - for (int index = edgeBox->FieldList->Count() - 1; index >= 0; --index) + for (int index = edgeBox->FieldList->GetCount() - 1; index >= 0; --index) { - auto field = static_cast(edgeBox->FieldList->Get(index)); + auto field = edgeBox->FieldList->Get(index); if (*field->Flag2Ptr && ball->FieldFlag & field->Mask) { if (field->CollisionComp->FieldEffect(ball, &vec)) diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 9b1bac4..1ec42d8 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -10,7 +10,6 @@ #include "timer.h" #include "TLine.h" #include "TPinballTable.h" -#include "TZmapList.h" TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) { @@ -62,8 +61,8 @@ int TFlagSpinner::Message(int code, float value) Timer = 0; } BmpIndex = 0; - auto bmp = static_cast(ListBitmap->Get(0)); - auto zMap = static_cast(ListZMap->Get(0)); + auto bmp = ListBitmap->Get(0); + auto zMap = ListZMap->Get(0); render::sprite_set( RenderSprite, bmp, @@ -109,7 +108,7 @@ void TFlagSpinner::NextFrame() { BmpIndex += SpinDirection; int bmpIndex = BmpIndex; - int bmpCount = ListBitmap->Count(); + int bmpCount = ListBitmap->GetCount(); if (bmpIndex >= bmpCount) BmpIndex = 0; else if (bmpIndex < 0) @@ -124,8 +123,8 @@ void TFlagSpinner::NextFrame() control::handler(62, this); } - auto bmp = static_cast(ListBitmap->Get(BmpIndex)); - auto zMap = static_cast(ListZMap->Get(BmpIndex)); + auto bmp = ListBitmap->Get(BmpIndex); + auto zMap = ListZMap->Get(BmpIndex); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TFlipper.cpp b/SpaceCadetPinball/TFlipper.cpp index a2dcb42..b3c7133 100644 --- a/SpaceCadetPinball/TFlipper.cpp +++ b/SpaceCadetPinball/TFlipper.cpp @@ -4,11 +4,11 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "pb.h" #include "render.h" #include "TFlipperEdge.h" #include "timer.h" -#include "TZmapList.h" TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) { @@ -47,8 +47,8 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t FlipperEdge = flipperEdge; if (flipperEdge) { - BmpCoef1 = flipperEdge->BmpCoef1 / static_cast(ListBitmap->Count() - 1); - BmpCoef2 = flipperEdge->BmpCoef2 / static_cast(ListBitmap->Count() - 1); + BmpCoef1 = flipperEdge->BmpCoef1 / static_cast(ListBitmap->GetCount() - 1); + BmpCoef2 = flipperEdge->BmpCoef2 / static_cast(ListBitmap->GetCount() - 1); } BmpIndex = 0; InputTime = 0.0; @@ -137,7 +137,7 @@ void TFlipper::TimerExpired(int timerId, void* caller) bool bmpIndexOutOfBounds = false; auto bmpIndexAdvance = static_cast(floor((pb::time_now - flip->InputTime) / flip->TimerTime + 0.5f)); - int bmpCount = flip->ListBitmap->Count(); + int bmpCount = flip->ListBitmap->GetCount(); if (bmpIndexAdvance > bmpCount) bmpIndexAdvance = bmpCount; if (bmpIndexAdvance < 0) @@ -149,7 +149,7 @@ void TFlipper::TimerExpired(int timerId, void* caller) if (flip->MessageField == 1) { flip->BmpIndex += bmpIndexAdvance; - int countSub1 = flip->ListBitmap->Count() - 1; + int countSub1 = flip->ListBitmap->GetCount() - 1; if (flip->BmpIndex >= countSub1) { flip->BmpIndex = countSub1; @@ -177,8 +177,8 @@ void TFlipper::TimerExpired(int timerId, void* caller) timer = timer::set(flip->TimerTime, flip, TimerExpired); flip->Timer = timer; - auto bmp = static_cast(flip->ListBitmap->Get(flip->BmpIndex)); - auto zMap = static_cast(flip->ListZMap->Get(flip->BmpIndex)); + auto bmp = flip->ListBitmap->Get(flip->BmpIndex); + auto zMap = flip->ListZMap->Get(flip->BmpIndex); render::sprite_set( flip->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TGate.cpp b/SpaceCadetPinball/TGate.cpp index cced6c6..381fef7 100644 --- a/SpaceCadetPinball/TGate.cpp +++ b/SpaceCadetPinball/TGate.cpp @@ -4,8 +4,8 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" -#include "TZmapList.h" TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -15,7 +15,7 @@ TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, SoundIndex4 = visual.SoundIndex4; SoundIndex3 = visual.SoundIndex3; ActiveFlag = 1; - render::sprite_set_bitmap(RenderSprite, static_cast(ListBitmap->Get(0))); + render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); control::handler(1024, this); } @@ -32,7 +32,7 @@ int TGate::Message(int code, float value) else if (code == 54 || code == 1024) { ActiveFlag = 1; - render::sprite_set_bitmap(RenderSprite, static_cast(ListBitmap->Get(0))); + render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); if (code == 54) loader::play_sound(SoundIndex4); } diff --git a/SpaceCadetPinball/TKickback.cpp b/SpaceCadetPinball/TKickback.cpp index c83bf9b..53e55c3 100644 --- a/SpaceCadetPinball/TKickback.cpp +++ b/SpaceCadetPinball/TKickback.cpp @@ -5,10 +5,10 @@ #include "control.h" #include "loader.h" #include "maths.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TKickback::TKickback(TPinballTable* table, int groupIndex): TCollisionComponent(table, groupIndex, true) { @@ -66,8 +66,8 @@ void TKickback::TimerExpired(int timerId, void* caller) loader::play_sound(kick->HardHitSoundId); if (kick->ListBitmap) { - auto bmp = static_cast(kick->ListBitmap->Get(1)); - auto zMap = static_cast(kick->ListZMap->Get(1)); + auto bmp = kick->ListBitmap->Get(1); + auto zMap = kick->ListZMap->Get(1); render::sprite_set( kick->RenderSprite, bmp, @@ -80,8 +80,8 @@ void TKickback::TimerExpired(int timerId, void* caller) { if (kick->ListBitmap) { - auto bmp = static_cast(kick->ListBitmap->Get(0)); - auto zMap = static_cast(kick->ListZMap->Get(0)); + auto bmp = kick->ListBitmap->Get(0); + auto zMap = kick->ListZMap->Get(0); render::sprite_set( kick->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TLight.cpp b/SpaceCadetPinball/TLight.cpp index 70c572c..3a5d078 100644 --- a/SpaceCadetPinball/TLight.cpp +++ b/SpaceCadetPinball/TLight.cpp @@ -4,10 +4,10 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TLight::TLight(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, true) { @@ -144,13 +144,13 @@ int TLight::Message(int code, float value) break; case 11: BmpIndex2 = static_cast(floor(value)); - if (BmpIndex2 > ListBitmap->Count()) - BmpIndex2 = ListBitmap->Count(); + if (BmpIndex2 > ListBitmap->GetCount()) + BmpIndex2 = ListBitmap->GetCount(); bmpIndex = 0; if (BmpIndex2 < 0) BmpIndex2 = 0; Flasher.BmpArr[0] = nullptr; - Flasher.BmpArr[1] = static_cast(ListBitmap->Get(BmpIndex2)); + Flasher.BmpArr[1] = ListBitmap->Get(BmpIndex2); if (FlasherActive == 0) { if (!FlasherFlag1) @@ -169,8 +169,8 @@ int TLight::Message(int code, float value) break; case 12: bmpIndex = BmpIndex2 + 1; - if (bmpIndex > ListBitmap->Count()) - bmpIndex = ListBitmap->Count(); + if (bmpIndex > ListBitmap->GetCount()) + bmpIndex = ListBitmap->GetCount(); Message(11, static_cast(bmpIndex)); break; case 13: @@ -257,7 +257,7 @@ void TLight::Reset() Flasher.Sprite = RenderSprite; Flasher.BmpArr[0] = nullptr; if (ListBitmap) - Flasher.BmpArr[1] = static_cast(ListBitmap->Get(0)); + Flasher.BmpArr[1] = ListBitmap->Get(0); Flasher.Unknown4 = 0; Flasher.Unknown3 = 0; MessageField = 0; diff --git a/SpaceCadetPinball/TLightBargraph.cpp b/SpaceCadetPinball/TLightBargraph.cpp index 0fe720f..0ad1a43 100644 --- a/SpaceCadetPinball/TLightBargraph.cpp +++ b/SpaceCadetPinball/TLightBargraph.cpp @@ -18,7 +18,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro float* floatArr = loader::query_float_attribute(groupIndex, 0, 904); if (floatArr) { - int count = 2 * List->Count(); + int count = 2 * List->GetCount(); TimerTimeArray = reinterpret_cast(memory::allocate(count * sizeof(float))); if (TimerTimeArray) { @@ -49,7 +49,7 @@ int TLightBargraph::Message(int code, float value) TimerBargraph = 0; } auto timeIndex = static_cast(floor(value)); - auto maxCount = 2 * List->Count(); + auto maxCount = 2 * List->GetCount(); if (timeIndex >= maxCount) timeIndex = maxCount - 1; if (timeIndex >= 0) diff --git a/SpaceCadetPinball/TLightGroup.cpp b/SpaceCadetPinball/TLightGroup.cpp index fecc74c..b41f4e2 100644 --- a/SpaceCadetPinball/TLightGroup.cpp +++ b/SpaceCadetPinball/TLightGroup.cpp @@ -11,7 +11,7 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) { - List = new objlist_class(4, 4); + List = new objlist_class(4, 4); Timer = 0; NotifyTimer = 0; Reset(); @@ -22,7 +22,7 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone __int16* groupIndArr = loader::query_iattribute(groupIndex, 1027, &count); for (int index = 0; index < count; ++groupIndArr) { - auto comp = table->find_component(*groupIndArr); + auto comp = dynamic_cast(table->find_component(*groupIndArr)); if (comp) List->Add(comp); ++index; @@ -71,8 +71,8 @@ int TLightGroup::Message(int code, float value) break; case 24: { - auto count = List->Count(); - auto lastLight = static_cast(List->Get(count - 1)); + auto count = List->GetCount(); + auto lastLight = List->Get(count - 1); if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) break; if (MessageField2) @@ -85,12 +85,12 @@ int TLightGroup::Message(int code, float value) auto bmpIndex1 = lastLight->BmpIndex1; for (auto index = count - 1; index > 0; --index) { - auto lightCur = static_cast(List->Get(index)); - auto lightPrev = static_cast(List->Get(index - 1)); + auto lightCur = List->Get(index); + auto lightPrev = List->Get(index - 1); lightCur->Message(lightPrev->BmpIndex1 != 0, 0.0); lightCur->MessageField = lightPrev->MessageField; } - auto firstLight = static_cast(List->Get(0)); + auto firstLight = List->Get(0); firstLight->Message(bmpIndex1 != 0, 0.0); firstLight->MessageField = lightMessageField; reschedule_animation(value); @@ -98,23 +98,23 @@ int TLightGroup::Message(int code, float value) } case 25: { - auto count = List->Count(); - auto lastLight = static_cast(List->Get(count - 1)); + auto count = List->GetCount(); + auto lastLight = List->Get(count - 1); if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) break; if (MessageField2) { TLightGroup::Message(34, 0.0); } - auto firstLight = static_cast(List->Get(0)); + auto firstLight = List->Get(0); AnimationFlag = 1; MessageField2 = code; auto lightMessageField = firstLight->MessageField; auto bmpIndex1 = firstLight->BmpIndex1; for (auto index = 0; index < count - 1; index++) { - auto lightCur = static_cast(List->Get(index)); - auto lightNext = static_cast(List->Get(index + 1)); + auto lightCur = List->Get(index); + auto lightNext = List->Get(index + 1); lightCur->Message(lightNext->BmpIndex1 != 0, 0.0); lightCur->MessageField = lightNext->MessageField; } @@ -129,16 +129,16 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->Count(); - auto lastLight = static_cast(List->Get(count - 1)); + auto count = List->GetCount(); + auto lastLight = List->Get(count - 1); auto flasherFlag2 = lastLight->FlasherFlag2; for (auto i = count - 1; i > 0; --i) { - auto lightCur = static_cast(List->Get(i)); - auto lightPrev = static_cast(List->Get(i - 1)); + auto lightCur = List->Get(i); + auto lightPrev = List->Get(i - 1); lightCur->Message((lightPrev->FlasherFlag2 != 0) + 8, 0.0); } - auto firstLight = static_cast(List->Get(0)); + auto firstLight = List->Get(0); firstLight->Message((flasherFlag2 != 0) + 8, 0); reschedule_animation(value); break; @@ -149,16 +149,16 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->Count(); - auto firstLight = static_cast(List->Get(0)); + auto count = List->GetCount(); + auto firstLight = List->Get(0); auto flasherFlag2 = firstLight->FlasherFlag2; for (auto i = 0; i < count - 1; i++) { - auto lightCur = static_cast(List->Get(i)); - auto lightNext = static_cast(List->Get(i + 1)); + auto lightCur = List->Get(i); + auto lightNext = List->Get(i + 1); lightCur->Message((lightNext->FlasherFlag2 != 0) + 8, 0.0); } - auto lastLight = static_cast(List->Get(count - 1)); + auto lastLight = List->Get(count - 1); lastLight->Message((flasherFlag2 != 0) + 8, 0); reschedule_animation(value); break; @@ -169,12 +169,12 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->Count(); + auto count = List->GetCount(); for (auto i = 0; i < count - 1; i++) { if (rand() % 100 > 70) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); auto randVal = static_cast(rand()) * 0.00003051850947599719f * value * 3.0f + 0.1f; light->Message(9, randVal); } @@ -188,10 +188,10 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->Count(); + auto count = List->GetCount(); for (auto i = 0; i < count - 1; i++) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); auto randVal = static_cast(rand() % 100 > 70); light->Message(18, randVal); } @@ -201,13 +201,13 @@ int TLightGroup::Message(int code, float value) case 30: { auto noBmpInd1Count = 0; - auto countSub1 = List->Count() - 1; + auto countSub1 = List->GetCount() - 1; if (countSub1 < 0) break; for (auto i = countSub1; i >= 0; i--) { - if (!static_cast(List->Get(i))->BmpIndex1) + if (!List->Get(i)->BmpIndex1) ++noBmpInd1Count; } if (!noBmpInd1Count) @@ -216,7 +216,7 @@ int TLightGroup::Message(int code, float value) auto randModCount = rand() % noBmpInd1Count; for (auto i = countSub1; i >= 0; i--) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); if (!light->BmpIndex1 && randModCount-- == 0) { light->Message(1, 0.0); @@ -231,13 +231,13 @@ int TLightGroup::Message(int code, float value) case 31: { auto bmpInd1Count = 0; - auto countSub1 = List->Count() - 1; + auto countSub1 = List->GetCount() - 1; if (countSub1 < 0) break; for (auto i = countSub1; i >= 0; i--) { - if (static_cast(List->Get(i))->BmpIndex1) + if (List->Get(i)->BmpIndex1) ++bmpInd1Count; } if (!bmpInd1Count) @@ -246,7 +246,7 @@ int TLightGroup::Message(int code, float value) auto randModCount = rand() % bmpInd1Count; for (auto i = countSub1; i >= 0; i--) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); if (light->BmpIndex1 && randModCount-- == 0) { light->Message(0, 0.0); @@ -263,7 +263,7 @@ int TLightGroup::Message(int code, float value) auto index = next_light_up(); if (index < 0) break; - static_cast(List->Get(index))->Message(1, 0.0); + List->Get(index)->Message(1, 0.0); if (MessageField2) start_animation(); return 1; @@ -273,7 +273,7 @@ int TLightGroup::Message(int code, float value) auto index = next_light_down(); if (index < 0) break; - static_cast(List->Get(index))->Message(0, 0.0); + List->Get(index)->Message(0, 0.0); if (MessageField2) start_animation(); return 1; @@ -292,10 +292,10 @@ int TLightGroup::Message(int code, float value) case 35: { auto index = static_cast(floor(value)); - if (index >= List->Count() || index < 0) + if (index >= List->GetCount() || index < 0) break; - auto light = static_cast(List->Get(index)); + auto light = List->Get(index); light->Message(1, 0.0); if (MessageField2) start_animation(); @@ -304,10 +304,10 @@ int TLightGroup::Message(int code, float value) case 36: { auto index = static_cast(floor(value)); - if (index >= List->Count() || index < 0) + if (index >= List->GetCount() || index < 0) break; - auto light = static_cast(List->Get(index)); + auto light = List->Get(index); light->Message(0, 0.0); if (MessageField2) start_animation(); @@ -316,16 +316,16 @@ int TLightGroup::Message(int code, float value) case 37: { auto bmp1Count = 0; - auto countSub1 = List->Count() - 1; + auto countSub1 = List->GetCount() - 1; for (auto i = countSub1; i >= 0; i--) { - if (static_cast(List->Get(i))->BmpIndex1) + if (List->Get(i)->BmpIndex1) ++bmp1Count; } return bmp1Count; } case 38: - return List->Count(); + return List->GetCount(); case 39: return MessageField2; case 40: @@ -337,7 +337,7 @@ int TLightGroup::Message(int code, float value) break; if (MessageField2 || AnimationFlag) TLightGroup::Message(34, 0.0); - static_cast(List->Get(index))->Message(15, value); + List->Get(index)->Message(15, value); return 1; } case 42: @@ -347,7 +347,7 @@ int TLightGroup::Message(int code, float value) break; if (MessageField2 || AnimationFlag) TLightGroup::Message(34, 0.0); - static_cast(List->Get(index))->Message(16, value); + List->Get(index)->Message(16, value); return 1; } case 43: @@ -359,10 +359,10 @@ int TLightGroup::Message(int code, float value) break; case 44: { - auto countSub1 = List->Count() - 1; + auto countSub1 = List->GetCount() - 1; for (auto index = countSub1; index >= 0; index--) { - auto light = static_cast(List->Get(index)); + auto light = List->Get(index); if (light->BmpIndex1) { light->Message(0, 0.0); @@ -378,7 +378,7 @@ int TLightGroup::Message(int code, float value) auto index = static_cast(floor(value)); if (index >= 0) { - auto count = List->Count(); + auto count = List->GetCount(); if (index <= count) { auto countSub1 = count - 1; @@ -387,7 +387,7 @@ int TLightGroup::Message(int code, float value) countSub1 = index; for (auto i = countSub1, k = countSub1 - index; k != 0; i--, k--) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); light->Message(20, 0.0); } } @@ -395,7 +395,7 @@ int TLightGroup::Message(int code, float value) { for (auto i = countSub1; i != 0; i--) { - auto light = static_cast(List->Get(i)); + auto light = List->Get(i); light->Message(19, 0.0); } } @@ -408,14 +408,14 @@ int TLightGroup::Message(int code, float value) auto index = next_light_down(); if (index >= 0) { - static_cast(List->Get(index))->Message(4, 0.0); + List->Get(index)->Message(4, 0.0); } break; } default: - for (auto index = List->Count() - 1; index >= 0; index--) + for (auto index = List->GetCount() - 1; index >= 0; index--) { - static_cast(List->Get(index))->Message(code, value); + List->Get(index)->Message(code, value); } break; } @@ -453,9 +453,9 @@ void TLightGroup::reschedule_animation(float time) void TLightGroup::start_animation() { - for (int index = List->Count() - 1; index >= 0; --index) + for (int index = List->GetCount() - 1; index >= 0; --index) { - auto light = static_cast(List->Get(index)); + auto light = List->Get(index); if (light->BmpIndex1) light->Message(9, 0.0); else @@ -465,9 +465,9 @@ void TLightGroup::start_animation() int TLightGroup::next_light_up() { - for (int index = 0; index < List->Count(); ++index) + for (int index = 0; index < List->GetCount(); ++index) { - if (!static_cast(List->Get(index))->BmpIndex1) + if (!List->Get(index)->BmpIndex1) return index; } return -1; @@ -475,9 +475,9 @@ int TLightGroup::next_light_up() int TLightGroup::next_light_down() { - for (int index = List->Count() - 1; index >= 0; --index) + for (int index = List->GetCount() - 1; index >= 0; --index) { - if (!static_cast(List->Get(index))->BmpIndex1) + if (!List->Get(index)->BmpIndex1) return index; } return -1; diff --git a/SpaceCadetPinball/TLightGroup.h b/SpaceCadetPinball/TLightGroup.h index 623c7e7..1d21219 100644 --- a/SpaceCadetPinball/TLightGroup.h +++ b/SpaceCadetPinball/TLightGroup.h @@ -1,6 +1,8 @@ #pragma once #include "TPinballComponent.h" -class objlist_class; + + +class TLight; struct TLightGroup_player_backup { @@ -27,7 +29,7 @@ public: static void TimerExpired(int timerId, void* caller); static void NotifyTimerExpired(int timerId, void* caller); - objlist_class* List; + objlist_class* List; float Timer1Time; float Timer1TimeDefault; int MessageField2; diff --git a/SpaceCadetPinball/TLightRollover.cpp b/SpaceCadetPinball/TLightRollover.cpp index 0cdb01c..53a7118 100644 --- a/SpaceCadetPinball/TLightRollover.cpp +++ b/SpaceCadetPinball/TLightRollover.cpp @@ -4,11 +4,11 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "TBall.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TLightRollover::TLightRollover(TPinballTable* table, int groupIndex) : TRollover(table, groupIndex, false) { @@ -58,7 +58,7 @@ void TLightRollover::Collision(TBall* ball, vector_type* nextPosition, vector_ty control::handler(63, this); RolloverFlag = RolloverFlag == 0; if (ListBitmap) - render::sprite_set_bitmap(RenderSprite, static_cast(ListBitmap->Get(0))); + render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); } } } diff --git a/SpaceCadetPinball/TPinballComponent.cpp b/SpaceCadetPinball/TPinballComponent.cpp index e8a1b61..0b81713 100644 --- a/SpaceCadetPinball/TPinballComponent.cpp +++ b/SpaceCadetPinball/TPinballComponent.cpp @@ -3,7 +3,6 @@ #include "loader.h" #include "objlist_class.h" #include "render.h" -#include "TZmapList.h" #include "TPinballTable.h" TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool loadVisuals) @@ -32,32 +31,32 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool if (visual.Bitmap) { if (!ListBitmap) - ListBitmap = new TZmapList(visualCount, 4); + ListBitmap = new objlist_class(visualCount, 4); if (ListBitmap) ListBitmap->Add(visual.Bitmap); } if (visual.ZMap) { if (!ListZMap) - ListZMap = new TZmapList(visualCount, 4); + ListZMap = new objlist_class(visualCount, 4); if (ListZMap) ListZMap->Add(visual.ZMap); } } zmap_header_type* zMap = nullptr; if (ListZMap) - zMap = static_cast(ListZMap->Get(0)); + zMap = ListZMap->Get(0); if (ListBitmap) { rectangle_type bmp1Rect{}, tmpRect{}; - auto rootBmp = static_cast(ListBitmap->Get(0)); + auto rootBmp = ListBitmap->Get(0); bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset; bmp1Rect.YPosition = rootBmp->YPosition - table->YOffset; bmp1Rect.Width = rootBmp->Width; bmp1Rect.Height = rootBmp->Height; - for (int index = 1; index < ListBitmap->Count(); index++) + for (int index = 1; index < ListBitmap->GetCount(); index++) { - auto bmp = static_cast(ListBitmap->Get(index)); + auto bmp = ListBitmap->Get(index); tmpRect.XPosition = bmp->XPosition - table->XOffset; tmpRect.YPosition = bmp->YPosition - table->YOffset; tmpRect.Width = bmp->Width; diff --git a/SpaceCadetPinball/TPinballComponent.h b/SpaceCadetPinball/TPinballComponent.h index 7bbdee6..d23d0c5 100644 --- a/SpaceCadetPinball/TPinballComponent.h +++ b/SpaceCadetPinball/TPinballComponent.h @@ -1,9 +1,11 @@ #pragma once +#include "objlist_class.h" +struct zmap_header_type; +struct gdrv_bitmap8; struct render_sprite_type_struct; struct component_control; class TPinballTable; -class TZmapList; enum class message_code { @@ -35,6 +37,6 @@ public: int GroupIndex; render_sprite_type_struct* RenderSprite; TPinballTable* PinballTable; - TZmapList* ListBitmap; - TZmapList* ListZMap; + objlist_class* ListBitmap; + objlist_class* ListZMap; }; diff --git a/SpaceCadetPinball/TPinballTable.cpp b/SpaceCadetPinball/TPinballTable.cpp index 75c0099..3fa290a 100644 --- a/SpaceCadetPinball/TPinballTable.cpp +++ b/SpaceCadetPinball/TPinballTable.cpp @@ -48,8 +48,8 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) { int shortArrLength; - ComponentList = new objlist_class(32, 16); - BallList = new objlist_class(3, 1); + ComponentList = new objlist_class(32, 16); + BallList = new objlist_class(3, 1); CurScoreStruct = nullptr; ScoreBallcount = nullptr; ScorePlayerNumber1 = nullptr; @@ -213,9 +213,9 @@ TPinballTable::~TPinballTable() ScoreBallcount = nullptr; } delete LightGroup; - while (ComponentList->Count() > 0) + while (ComponentList->GetCount() > 0) { - delete static_cast(ComponentList->Get(0)); + delete ComponentList->Get(0); } delete BallList; delete ComponentList; @@ -223,12 +223,12 @@ TPinballTable::~TPinballTable() TPinballComponent* TPinballTable::find_component(LPCSTR componentName) { - int objCount = ComponentList->Count(); + int objCount = ComponentList->GetCount(); if (objCount > 0) { for (int index = 0; index < objCount; ++index) { - TPinballComponent* obj = static_cast(ComponentList->Get(index)); + TPinballComponent* obj = ComponentList->Get(index); const CHAR* groupName = obj->GroupName; if (groupName && !lstrcmpA(groupName, componentName)) { @@ -243,12 +243,12 @@ TPinballComponent* TPinballTable::find_component(LPCSTR componentName) TPinballComponent* TPinballTable::find_component(int groupIndex) { char Buffer[40]; - int objCount = ComponentList->Count(); + int objCount = ComponentList->GetCount(); if (objCount > 0) { for (int index = 0; index < objCount; ++index) { - TPinballComponent* obj = static_cast(ComponentList->Get(index)); + TPinballComponent* obj = ComponentList->Get(index); if (obj->GroupIndex == groupIndex) return obj; } @@ -307,9 +307,9 @@ void TPinballTable::tilt(float time) loader::play_sound(SoundIndex3); TiltTimeoutTimer = timer::set(30.0, this, tilt_timeout); - for (int i = 0; i < ComponentList->Count(); i++) + for (int i = 0; i < ComponentList->GetCount(); i++) { - static_cast(ComponentList->Get(i))->Message(1011, time); + ComponentList->Get(i)->Message(1011, time); } LightGroup->Message(8, 0); TiltLockFlag = 1; @@ -320,9 +320,9 @@ void TPinballTable::tilt(float time) void TPinballTable::port_draw() { - for (int index = ComponentList->Count() - 1; index >= 0; index--) + for (int index = ComponentList->GetCount() - 1; index >= 0; index--) { - static_cast(ComponentList->Get(index))->port_draw(); + ComponentList->Get(index)->port_draw(); } } @@ -362,9 +362,9 @@ int TPinballTable::Message(int code, float value) case 1008: case 1009: case 1010: - for (int i = 0; i < ComponentList->Count(); i++) + for (int i = 0; i < ComponentList->GetCount(); i++) { - static_cast(ComponentList->Get(i))->Message(code, value); + ComponentList->Get(i)->Message(code, value); } break; case 1012: @@ -406,7 +406,7 @@ int TPinballTable::Message(int code, float value) { CheatsUsed = 0; Message(1024, 0.0); - auto ball = static_cast(BallList->Get(0)); + auto ball = BallList->Get(0); ball->Position.Y = 0.0; ball->Position.X = 0.0; ball->Position.Z = -0.8f; @@ -513,9 +513,9 @@ int TPinballTable::Message(int code, float value) score::set(ScorePlayerNumber1, nextPlayer + 1); score::update(ScorePlayerNumber1); - for (int i = 0; i < ComponentList->Count(); i++) + for (int i = 0; i < ComponentList->GetCount(); i++) { - static_cast(ComponentList->Get(i))->Message(1020, static_cast(nextPlayer)); + ComponentList->Get(i)->Message(1020, static_cast(nextPlayer)); } char* textboxText = nullptr; @@ -564,9 +564,9 @@ int TPinballTable::Message(int code, float value) EndGameTimeoutTimer = timer::set(3.0, this, EndGame_timeout); break; case 1024: - for (int i = 0; i < ComponentList->Count(); i++) + for (int i = 0; i < ComponentList->GetCount(); i++) { - static_cast(ComponentList->Get(i))->Message(1024, 0); + ComponentList->Get(i)->Message(1024, 0); } if (ReplayTimer) timer::kill(ReplayTimer); @@ -608,9 +608,9 @@ void TPinballTable::EndGame_timeout(int timerId, void* caller) table->EndGameTimeoutTimer = 0; pb::end_game(); - for (int i = 0; i < table->ComponentList->Count(); i++) + for (int i = 0; i < table->ComponentList->GetCount(); i++) { - static_cast(table->ComponentList->Get(i))->Message(1022, 0); + table->ComponentList->Get(i)->Message(1022, 0); } if (table->Demo) table->Demo->Message(1022, 0.0); @@ -640,9 +640,9 @@ void TPinballTable::tilt_timeout(int timerId, void* caller) table->TiltTimeoutTimer = 0; if (table->TiltLockFlag) { - for (int i = 0; i < table->BallList->Count(); i++) + for (int i = 0; i < table->BallList->GetCount(); i++) { - table->Drain->Collision(static_cast(table->BallList->Get(i)), &vec, &vec, 0.0, nullptr); + table->Drain->Collision(table->BallList->Get(i), &vec, &vec, 0.0, nullptr); } } } diff --git a/SpaceCadetPinball/TPinballTable.h b/SpaceCadetPinball/TPinballTable.h index b587c27..037b357 100644 --- a/SpaceCadetPinball/TPinballTable.h +++ b/SpaceCadetPinball/TPinballTable.h @@ -2,12 +2,12 @@ #include "TPinballComponent.h" +class TBall; struct scoreStruct; class TFlipper; class TPlunger; class TDrain; class TDemo; -class objlist_class; class TLightGroup; struct score_struct_super @@ -65,8 +65,8 @@ public: int YOffset; int Width; int Height; - objlist_class* ComponentList; - objlist_class* BallList; + objlist_class* ComponentList; + objlist_class* BallList; TLightGroup* LightGroup; float GravityDirVectMult; float GravityAngleX; diff --git a/SpaceCadetPinball/TPlunger.cpp b/SpaceCadetPinball/TPlunger.cpp index b671b66..b3b3e7b 100644 --- a/SpaceCadetPinball/TPlunger.cpp +++ b/SpaceCadetPinball/TPlunger.cpp @@ -5,12 +5,12 @@ #include "control.h" #include "loader.h" #include "maths.h" +#include "objlist_class.h" #include "pb.h" #include "render.h" #include "TBall.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -27,7 +27,7 @@ TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(t MaxPullback = 100; Elasticity = 0.5f; Smoothness = 0.5f; - PullbackIncrement = static_cast(100.0 / (ListBitmap->Count() * 8.0)); + PullbackIncrement = static_cast(100.0 / (ListBitmap->GetCount() * 8.0)); Unknown4F = 0.025f; float* floatArr = loader::query_float_attribute(groupIndex, 0, 601); table->PlungerPositionX = floatArr[0]; @@ -65,8 +65,8 @@ int TPlunger::Message(int code, float value) PullbackTimer_ = 0; if (code == 1005) loader::play_sound(SoundIndexP2); - auto bmp = static_cast(ListBitmap->Get(0)); - auto zMap = static_cast(ListZMap->Get(0)); + auto bmp = ListBitmap->Get(0); + auto zMap = ListZMap->Get(0); render::sprite_set( RenderSprite, bmp, @@ -79,7 +79,7 @@ int TPlunger::Message(int code, float value) } case 1015: { - auto ball = static_cast(PinballTable->ComponentList->Get(0)); + auto ball = PinballTable->BallList->Get(0); ball->Message(1024, 0.0); ball->Position.X = PinballTable->PlungerPositionX; ball->Position.Y = PinballTable->PlungerPositionY; @@ -112,8 +112,8 @@ int TPlunger::Message(int code, float value) PullbackTimer_ = 0; if (code == 1005) loader::play_sound(SoundIndexP2); - auto bmp = static_cast(ListBitmap->Get(0)); - auto zMap = static_cast(ListZMap->Get(0)); + auto bmp = ListBitmap->Get(0); + auto zMap = ListZMap->Get(0); render::sprite_set( RenderSprite, bmp, @@ -151,10 +151,10 @@ void TPlunger::PullbackTimer(int timerId, void* caller) plunger->Boost = static_cast(plunger->MaxPullback); } int index = static_cast(floor( - static_cast(plunger->ListBitmap->Count() - 1) * + static_cast(plunger->ListBitmap->GetCount() - 1) * (plunger->Boost / static_cast(plunger->MaxPullback)))); - auto bmp = static_cast(plunger->ListBitmap->Get(index)); - auto zMap = static_cast(plunger->ListZMap->Get(index)); + auto bmp = plunger->ListBitmap->Get(index); + auto zMap = plunger->ListZMap->Get(index); render::sprite_set( plunger->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TPopupTarget.cpp b/SpaceCadetPinball/TPopupTarget.cpp index 4747cd4..47c76ab 100644 --- a/SpaceCadetPinball/TPopupTarget.cpp +++ b/SpaceCadetPinball/TPopupTarget.cpp @@ -4,10 +4,10 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TPopupTarget::TPopupTarget(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -91,7 +91,7 @@ void TPopupTarget::TimerExpired(int timerId, void* caller) auto target = static_cast(caller); target->Timer = 0; target->ActiveFlag = 1; - render::sprite_set_bitmap(target->RenderSprite, static_cast(target->ListBitmap->Get(0))); + render::sprite_set_bitmap(target->RenderSprite, target->ListBitmap->Get(0)); if (timerId) { if (target->SoftHitSoundId) diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index bf4230f..fd7274b 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -5,12 +5,12 @@ #include "control.h" #include "gdrv.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "TBall.h" #include "TEdgeSegment.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TRollover::TRollover(TPinballTable* table, int groupIndex, bool createWall) : TCollisionComponent( table, groupIndex, createWall) @@ -22,7 +22,7 @@ TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent { RolloverFlag = 0; if (ListBitmap) - render::sprite_set_bitmap(RenderSprite, static_cast(ListBitmap->Get(0))); + render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); build_walls(groupIndex); } @@ -34,7 +34,7 @@ int TRollover::Message(int code, float value) this->ActiveFlag = 1; this->RolloverFlag = 0; if (this->ListBitmap) - render::sprite_set_bitmap(this->RenderSprite, static_cast(this->ListBitmap->Get(0))); + render::sprite_set_bitmap(this->RenderSprite, this->ListBitmap->Get(0)); } return 0; } @@ -63,7 +63,7 @@ void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* d if (ListBitmap) { if (!RolloverFlag) - bmp = static_cast(ListBitmap->Get(0)); + bmp = ListBitmap->Get(0); render::sprite_set_bitmap(RenderSprite, bmp); } } diff --git a/SpaceCadetPinball/TSink.cpp b/SpaceCadetPinball/TSink.cpp index d1939ad..66ddc80 100644 --- a/SpaceCadetPinball/TSink.cpp +++ b/SpaceCadetPinball/TSink.cpp @@ -95,7 +95,7 @@ void TSink::Collision(TBall* ball, vector_type* nextPosition, vector_type* direc void TSink::TimerExpired(int timerId, void* caller) { auto sink = static_cast(caller); - auto ball = static_cast(sink->PinballTable->BallList->Get(0)); + auto ball = sink->PinballTable->BallList->Get(0); ball->CollisionComp = nullptr; ball->ActiveFlag = 1; ball->Position.X = sink->BallPosition.X; diff --git a/SpaceCadetPinball/TSoloTarget.cpp b/SpaceCadetPinball/TSoloTarget.cpp index 89d974e..25af76f 100644 --- a/SpaceCadetPinball/TSoloTarget.cpp +++ b/SpaceCadetPinball/TSoloTarget.cpp @@ -4,10 +4,10 @@ #include "control.h" #include "loader.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" -#include "TZmapList.h" TSoloTarget::TSoloTarget(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { @@ -41,8 +41,8 @@ int TSoloTarget::Message(int code, float value) if (ListBitmap) { auto index = 1 - ActiveFlag; - auto bmp = static_cast(ListBitmap->Get(index)); - auto zMap = static_cast(ListZMap->Get(index)); + auto bmp = ListBitmap->Get(index); + auto zMap = ListZMap->Get(index); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TTextBox.cpp b/SpaceCadetPinball/TTextBox.cpp index 4380ae3..c687c16 100644 --- a/SpaceCadetPinball/TTextBox.cpp +++ b/SpaceCadetPinball/TTextBox.cpp @@ -262,7 +262,7 @@ void TTextBox::Draw() } else { - auto timeLeft = (Message1->TimeLeft()); + auto timeLeft = Message1->TimeLeft(); if (timeLeft >= -2.0f) { int timer; diff --git a/SpaceCadetPinball/TWall.cpp b/SpaceCadetPinball/TWall.cpp index 4cf139f..ed63ea6 100644 --- a/SpaceCadetPinball/TWall.cpp +++ b/SpaceCadetPinball/TWall.cpp @@ -3,16 +3,16 @@ #include "control.h" +#include "objlist_class.h" #include "render.h" #include "timer.h" -#include "TZmapList.h" TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) { if (RenderSprite) render::sprite_set_bitmap(RenderSprite, nullptr); if (ListBitmap) - BmpPtr = static_cast(ListBitmap->Get(0)); + BmpPtr = ListBitmap->Get(0); Timer = 0; } diff --git a/SpaceCadetPinball/TZmapList.h b/SpaceCadetPinball/TZmapList.h deleted file mode 100644 index 764ded4..0000000 --- a/SpaceCadetPinball/TZmapList.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "objlist_class.h" - -class TZmapList : // TImageList, template? - public objlist_class -{ -public: - TZmapList(int SizeInt, int growSize): objlist_class(SizeInt, growSize) - { - }; - - ~TZmapList() - { - }; -}; diff --git a/SpaceCadetPinball/WaveMix.cpp b/SpaceCadetPinball/WaveMix.cpp index 967584d..0c58f36 100644 --- a/SpaceCadetPinball/WaveMix.cpp +++ b/SpaceCadetPinball/WaveMix.cpp @@ -290,7 +290,7 @@ MIXWAVE* WaveMix::OpenWave(HANDLE hMixSession, LPCSTR szWaveFilename, HINSTANCE break; } - memset(&pmmioinfo, 0, sizeof(pmmioinfo)); + memset(&pmmioinfo, 0, sizeof pmmioinfo); pmmioinfo.pchBuffer = static_cast(LockResource(hResData)); if (!pmmioinfo.pchBuffer) { @@ -319,7 +319,7 @@ MIXWAVE* WaveMix::OpenWave(HANDLE hMixSession, LPCSTR szWaveFilename, HINSTANCE } else if ((dwFlags & 4) != 0) { - memcpy(&pmmioinfo, szWaveFilename, sizeof(pmmioinfo)); + memcpy(&pmmioinfo, szWaveFilename, sizeof pmmioinfo); hMmio = mmioOpenA(nullptr, &pmmioinfo, 0); if (!hMmio) { @@ -667,7 +667,7 @@ int WaveMix::Play(MIXPLAYPARAMS* lpMixPlayParams) if (!channel) break; - memcpy(&channel->PlayParams, lpMixPlayParams, sizeof(channel->PlayParams)); + memcpy(&channel->PlayParams, lpMixPlayParams, sizeof channel->PlayParams); channel->lpMixWave = channel->PlayParams.lpMixWave; channel->dwNumSamples = channel->PlayParams.lpMixWave->wh.dwBufferLength; auto lpData = (unsigned __int8*)channel->PlayParams.lpMixWave->wh.lpData; diff --git a/SpaceCadetPinball/control.cpp b/SpaceCadetPinball/control.cpp index fa367f4..d44cbe1 100644 --- a/SpaceCadetPinball/control.cpp +++ b/SpaceCadetPinball/control.cpp @@ -597,9 +597,9 @@ TPinballComponent* control::make_component_link(component_tag_base* tag) return tag->GetComponent(); auto compList = TableG->ComponentList; - for (int index = 0; index < compList->Count(); index++) + for (int index = 0; index < compList->GetCount(); index++) { - auto comp = static_cast(compList->Get(index)); + auto comp = compList->Get(index); if (comp->GroupName) { if (!strcmp(comp->GroupName, tag->Name)) diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index 6b4fbb7..edf6d4a 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -436,7 +436,7 @@ int loader::query_visual(int groupIndex, int groupIndexOffset, visualStruct* vis if (*floatArr != 600.0) return 0; - visual->FloatArrCount = (partman::field_size(loader_table, stateId, datFieldTypes::FloatArray) / 4) / 2 - 2; + visual->FloatArrCount = partman::field_size(loader_table, stateId, datFieldTypes::FloatArray) / 4 / 2 - 2; auto floatVal = static_cast(floor(floatArr[1]) - 1.0); switch (floatVal) { diff --git a/SpaceCadetPinball/nudge.cpp b/SpaceCadetPinball/nudge.cpp index c276e09..79a4087 100644 --- a/SpaceCadetPinball/nudge.cpp +++ b/SpaceCadetPinball/nudge.cpp @@ -71,9 +71,9 @@ void nudge::_nudge(float xDiff, float yDiff) auto ballList = pb::MainTable->BallList; accelMod.X = xDiff * 0.5f; accelMod.Y = yDiff * 0.5f; - for (auto index = 0; index < ballList->Count(); index++) + for (auto index = 0; index < ballList->GetCount(); index++) { - auto ball = static_cast(ballList->Get(index)); + auto ball = ballList->Get(index); if (ball->ActiveFlag && !ball->CollisionComp) { ball->Acceleration.X = ball->Acceleration.X * ball->Speed; diff --git a/SpaceCadetPinball/objlist_class.cpp b/SpaceCadetPinball/objlist_class.cpp deleted file mode 100644 index af319d3..0000000 --- a/SpaceCadetPinball/objlist_class.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "pch.h" -#include "objlist_class.h" -#include - -#include "memory.h" -// v1 from Ida - -objlist_class::objlist_class(int SizeInt, int growSize) -{ - ListPtr = objlist_new(SizeInt); - GrowSize = growSize; -} - -objlist_class::~objlist_class() -{ - if (ListPtr) - memory::free(ListPtr); -} - -void objlist_class::Add(void* value) -{ - if (this->ListPtr->Count == this->ListPtr->Size) - Grow(); - objlist_add_object(ListPtr, value); -} - -void objlist_class::Grow() -{ - this->ListPtr = objlist_grow(this->ListPtr, this->GrowSize); -} - -int objlist_class::Delete(void* value) -{ - return objlist_delete_object(ListPtr, value); -} - -void* objlist_class::Get(int index) -{ - if (index >= ListPtr->Count) - return nullptr; - return this->ListPtr->Array[index]; -} - - -objlist_struct1* objlist_class::objlist_new(int sizeInt) -{ - objlist_struct1* result = (objlist_struct1 *)memory::allocate(sizeof(void*) * sizeInt + sizeof(objlist_struct1)); - if (!result) - return result; - result->Count = 0; - result->Size = sizeInt; - return result; -} - -int objlist_class::objlist_add_object(objlist_struct1* ptrToStruct, void* value) -{ - int addIndex = ptrToStruct->Count; - if (addIndex >= ptrToStruct->Size) - return 0; - ptrToStruct->Array[addIndex] = value; - return ++ptrToStruct->Count; -} - -objlist_struct1* objlist_class::objlist_grow(objlist_struct1* ptrToStruct, int growSize) -{ - objlist_struct1* resultPtr = ptrToStruct; - if (!ptrToStruct) - return resultPtr; - int newSizeInt = growSize + ptrToStruct->Count; - if (newSizeInt <= ptrToStruct->Size) - return resultPtr; - objlist_struct1* resultPtr2 = (objlist_struct1*)memory::realloc(ptrToStruct, sizeof(void*) * newSizeInt + sizeof(objlist_struct1)); - if (!resultPtr2) - return resultPtr; - resultPtr = resultPtr2; - resultPtr2->Size = growSize + resultPtr2->Count; - return resultPtr; -} - -int objlist_class::objlist_delete_object(objlist_struct1* ptrToStruct, void* value) -{ - int count = ptrToStruct->Count; - int index = count - 1; - if (count - 1 < 0) - return 0; - for (void** i = &ptrToStruct->Array[index]; *i != value; --i) - { - if (--index < 0) - return 0; - } - ptrToStruct->Array[index] = ptrToStruct->Array[count - 1]; - --ptrToStruct->Count; - return 1; -} diff --git a/SpaceCadetPinball/objlist_class.h b/SpaceCadetPinball/objlist_class.h index dd2687c..7b1cafb 100644 --- a/SpaceCadetPinball/objlist_class.h +++ b/SpaceCadetPinball/objlist_class.h @@ -1,28 +1,78 @@ #pragma once -struct objlist_struct1 -{ - int Size; - int Count; - void* Array[1]; -}; +#include "memory.h" +template class objlist_class { public: - objlist_class(int SizeInt, int growSize); - ~objlist_class(); - void Add(void* value); - void Grow(); - int Delete(void* value); - void* Get(int index); - int Count() const { return !ListPtr ? 0 : ListPtr->Count; } - int Size() const { return !ListPtr ? 0 : ListPtr->Size; } + objlist_class(int sizeInt, int growSize) + { + ListPtr = reinterpret_cast(memory::allocate(sizeof(T*) * sizeInt)); + Count = 0; + Size = sizeInt; + GrowSize = growSize; + } + + ~objlist_class() + { + if (ListPtr) + memory::free(ListPtr); + } + + void Add(T* value) + { + if (Count == Size) + Grow(); + if (Count >= Size) + return; + + ListPtr[Count] = value; + Count++; + } + + void Grow() + { + if (!ListPtr) + return; + auto newSize = Count + GrowSize; + if (newSize <= Size) + return; + + auto newList = reinterpret_cast(memory::realloc(ListPtr, sizeof(T*) * newSize)); + if (!newList) + return; + + ListPtr = newList; + Size = newSize; + } + + int Delete(T* value) + { + for (auto index = Count - 1; index >= 0; index--) + { + if (ListPtr[index] == value) + { + ListPtr[index] = ListPtr[Count - 1]; + Count--; + return 1; + } + } + return 0; + } + + T* Get(int index) const + { + if (index >= Count) + return nullptr; + return ListPtr[index]; + } + + int GetCount() const { return Count; } + int GetSize() const { return Size; } private: - objlist_struct1* ListPtr; + T** ListPtr; int GrowSize; - static objlist_struct1* objlist_new(int sizeInt); - static int objlist_add_object(objlist_struct1* ptrToStruct, void* value); - static objlist_struct1* objlist_grow(objlist_struct1* ptrToStruct, int growSize); - static int objlist_delete_object(objlist_struct1* ptrToStruct, void* value); + int Size; + int Count; }; diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 7165488..cb39852 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -94,7 +94,7 @@ int pb::init() MainTable = new TPinballTable(); high_score::read(highscore_table, &state); - ball_speed_limit = static_cast(MainTable->BallList->Get(0))->Offset * 200.0f; + ball_speed_limit = MainTable->BallList->Get(0)->Offset * 200.0f; --memory::critical_allocation; return 0; } @@ -209,7 +209,7 @@ void pb::replay_level(int demoMode) void pb::ballset(int x, int y) { - TBall* ball = static_cast(MainTable->BallList->Get(0)); + TBall* ball = MainTable->BallList->Get(0); ball->Acceleration.X = x * 30.0f; ball->Acceleration.Y = y * 30.0f; ball->Speed = maths::normalize_2d(&ball->Acceleration); @@ -257,9 +257,9 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) { vector_type vec1{}, vec2{}; - for (int i = 0; i < MainTable->BallList->Count(); i++) + for (int i = 0; i < MainTable->BallList->GetCount(); i++) { - auto ball = static_cast(MainTable->BallList->Get(i)); + auto ball = MainTable->BallList->Get(i); if (ball->ActiveFlag != 0) { auto collComp = ball->CollisionComp; @@ -300,9 +300,9 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) if (drawBalls) { - for (int i = 0; i < MainTable->BallList->Count(); i++) + for (int i = 0; i < MainTable->BallList->GetCount(); i++) { - auto ball = static_cast(MainTable->BallList->Get(i)); + auto ball = MainTable->BallList->Get(i); if (ball->ActiveFlag) ball->Repaint(); } @@ -440,7 +440,7 @@ void pb::keydown(int key) { case 'B': TBall* ball; - if (MainTable->BallList->Count() <= 0) + if (MainTable->BallList->GetCount() <= 0) { ball = new TBall(MainTable); } @@ -448,11 +448,11 @@ void pb::keydown(int key) { for (auto index = 0; ;) { - ball = static_cast(MainTable->BallList->Get(index)); + ball = MainTable->BallList->Get(index); if (!ball->ActiveFlag) break; ++index; - if (index >= MainTable->BallList->Count()) + if (index >= MainTable->BallList->GetCount()) { ball = new TBall(MainTable); break; diff --git a/SpaceCadetPinball/score.cpp b/SpaceCadetPinball/score.cpp index 8badab3..dd2cdf6 100644 --- a/SpaceCadetPinball/score.cpp +++ b/SpaceCadetPinball/score.cpp @@ -70,7 +70,7 @@ void score::load_msg_font(LPCSTR lpName) FreeResource(resGlobal); return; } - memset(fontp->Chars, 0, sizeof(fontp->Chars)); + memset(fontp->Chars, 0, sizeof fontp->Chars); auto maxWidth = 0; auto ptrToWidths = (char*)rcData + 6;