From 81c2034a168f05026a4377ff84a2132db95b3299 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:55:44 +0300 Subject: [PATCH] Replaced objlist_class with std::vector. Fixed minor bug in TLightGroup. Cleaned up some warnings. --- CMakeLists.txt | 2 - SpaceCadetPinball/GroupData.cpp | 4 +- SpaceCadetPinball/Sound.cpp | 2 +- SpaceCadetPinball/TBall.cpp | 11 +- SpaceCadetPinball/TBlocker.cpp | 3 +- SpaceCadetPinball/TBumper.cpp | 16 +-- SpaceCadetPinball/TCollisionComponent.cpp | 19 +-- SpaceCadetPinball/TCollisionComponent.h | 2 +- SpaceCadetPinball/TComponentGroup.cpp | 9 +- SpaceCadetPinball/TComponentGroup.h | 2 +- SpaceCadetPinball/TEdgeBox.cpp | 16 --- SpaceCadetPinball/TEdgeBox.h | 10 +- SpaceCadetPinball/TEdgeManager.cpp | 13 +- SpaceCadetPinball/TEdgeSegment.cpp | 9 +- SpaceCadetPinball/TFlagSpinner.cpp | 15 ++- SpaceCadetPinball/TFlipper.cpp | 13 +- SpaceCadetPinball/TGate.cpp | 5 +- SpaceCadetPinball/THole.cpp | 3 +- SpaceCadetPinball/TKickback.cpp | 9 +- SpaceCadetPinball/TKickout.cpp | 3 +- SpaceCadetPinball/TLight.cpp | 15 ++- SpaceCadetPinball/TLightBargraph.cpp | 5 +- SpaceCadetPinball/TLightGroup.cpp | 137 +++++++++------------- SpaceCadetPinball/TLightGroup.h | 2 +- SpaceCadetPinball/TLightRollover.cpp | 3 +- SpaceCadetPinball/TOneway.cpp | 5 +- SpaceCadetPinball/TPinballComponent.cpp | 33 +++--- SpaceCadetPinball/TPinballComponent.h | 6 +- SpaceCadetPinball/TPinballTable.cpp | 73 +++++------- SpaceCadetPinball/TPinballTable.h | 4 +- SpaceCadetPinball/TPlunger.cpp | 19 ++- SpaceCadetPinball/TPopupTarget.cpp | 3 +- SpaceCadetPinball/TRamp.cpp | 9 +- SpaceCadetPinball/TRollover.cpp | 7 +- SpaceCadetPinball/TSink.cpp | 3 +- SpaceCadetPinball/TSoloTarget.cpp | 5 +- SpaceCadetPinball/TTableLayer.cpp | 3 +- SpaceCadetPinball/TTextBox.cpp | 1 - SpaceCadetPinball/TWall.cpp | 3 +- SpaceCadetPinball/control.cpp | 13 +- SpaceCadetPinball/gdrv.cpp | 1 - SpaceCadetPinball/high_score.cpp | 1 - SpaceCadetPinball/loader.cpp | 2 +- SpaceCadetPinball/loader.h | 2 +- SpaceCadetPinball/midi.cpp | 11 +- SpaceCadetPinball/midi.h | 3 +- SpaceCadetPinball/nudge.cpp | 5 +- SpaceCadetPinball/objlist_class.h | 78 ------------ SpaceCadetPinball/options.cpp | 1 - SpaceCadetPinball/partman.cpp | 41 ++----- SpaceCadetPinball/partman.h | 12 +- SpaceCadetPinball/pb.cpp | 25 ++-- SpaceCadetPinball/render.cpp | 4 +- SpaceCadetPinball/zdrv.cpp | 1 - 54 files changed, 249 insertions(+), 453 deletions(-) delete mode 100644 SpaceCadetPinball/TEdgeBox.cpp delete mode 100644 SpaceCadetPinball/objlist_class.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d88ce..a3c0ebd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ set(SOURCE_FILES SpaceCadetPinball/midi.h SpaceCadetPinball/nudge.cpp SpaceCadetPinball/nudge.h - SpaceCadetPinball/objlist_class.h SpaceCadetPinball/options.cpp SpaceCadetPinball/options.h SpaceCadetPinball/partman.cpp @@ -83,7 +82,6 @@ set(SOURCE_FILES SpaceCadetPinball/TDemo.h SpaceCadetPinball/TDrain.cpp SpaceCadetPinball/TDrain.h - SpaceCadetPinball/TEdgeBox.cpp SpaceCadetPinball/TEdgeBox.h SpaceCadetPinball/TEdgeManager.cpp SpaceCadetPinball/TEdgeManager.h diff --git a/SpaceCadetPinball/GroupData.cpp b/SpaceCadetPinball/GroupData.cpp index 4722551..2cce846 100644 --- a/SpaceCadetPinball/GroupData.cpp +++ b/SpaceCadetPinball/GroupData.cpp @@ -247,8 +247,8 @@ int DatFile::record_labeled(LPCSTR targetGroupName) if (!groupName) continue; - int index; - for (index = 0; index < targetLength; index++) + auto index = 0u; + for (; index < targetLength; index++) if (targetGroupName[index] != groupName[index]) break; if (index == targetLength && !targetGroupName[index] && !groupName[index]) diff --git a/SpaceCadetPinball/Sound.cpp b/SpaceCadetPinball/Sound.cpp index 15f0ee3..4e053b1 100644 --- a/SpaceCadetPinball/Sound.cpp +++ b/SpaceCadetPinball/Sound.cpp @@ -12,7 +12,7 @@ int Sound::Init(int voices) channelCount = 8; num_channels = channelCount; - auto init = Mix_Init(MIX_INIT_MID); + Mix_Init(MIX_INIT_MID); return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024); } diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index eeb035c..25dd48f 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -5,7 +5,6 @@ #include "fullscrn.h" #include "loader.h" #include "maths.h" -#include "objlist_class.h" #include "pb.h" #include "proj.h" #include "render.h" @@ -32,7 +31,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) Position.X = 0.0; Position.Y = 0.0; - ListBitmap = new objlist_class(0, 4); + ListBitmap = new std::vector(); /*Full tilt: ball is ballN, where N[0,2] resolution*/ if (pb::FullTiltMode) @@ -49,7 +48,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) { loader::query_visual(groupIndex, index, &visual); if (ListBitmap) - ListBitmap->Add(visual.Bitmap); + ListBitmap->push_back(visual.Bitmap); auto visVec = reinterpret_cast(loader::query_float_attribute(groupIndex, index, 501)); auto zDepth = proj::z_distance(visVec); ++index; @@ -79,13 +78,13 @@ void TBall::Repaint() auto zDepth = proj::z_distance(&Position); auto zArrPtr = VisualZArray; - int index; - for (index = 0; index < ListBitmap->GetCount() - 1; ++index, zArrPtr++) + auto index = 0u; + for (; index < ListBitmap->size() - 1; ++index, zArrPtr++) { if (*zArrPtr <= zDepth) break; } - auto bmp = ListBitmap->Get(index); + auto bmp = ListBitmap->at(index); render::ball_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TBlocker.cpp b/SpaceCadetPinball/TBlocker.cpp index a33df00..41bc3c2 100644 --- a/SpaceCadetPinball/TBlocker.cpp +++ b/SpaceCadetPinball/TBlocker.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" @@ -46,7 +45,7 @@ int TBlocker::Message(int code, float value) case 52: ActiveFlag = 1; loader::play_sound(SoundIndex4); - render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); break; case 59: break; diff --git a/SpaceCadetPinball/TBumper.cpp b/SpaceCadetPinball/TBumper.cpp index bba3fc6..6942192 100644 --- a/SpaceCadetPinball/TBumper.cpp +++ b/SpaceCadetPinball/TBumper.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" @@ -29,8 +28,9 @@ int TBumper::Message(int code, float value) case 11: { auto nextBmp = static_cast(floor(value)); - if (2 * nextBmp > ListBitmap->GetCount() - 1) - nextBmp = (ListBitmap->GetCount() - 1) / 2; + auto maxBmp = static_cast(ListBitmap->size()) - 1; + if (2 * nextBmp > maxBmp) + nextBmp = maxBmp / 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->GetCount() - 1; + auto maxBmp = static_cast(ListBitmap->size()) - 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 = bump->ListBitmap->Get(bump->BmpIndex * 2); - auto zMap = bump->ListZMap->Get(bump->BmpIndex * 2); + auto bmp = bump->ListBitmap->at(bump->BmpIndex * 2); + auto zMap = bump->ListZMap->at(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 = ListBitmap->Get(bmpIndex); - auto zMap = ListZMap->Get(bmpIndex); + auto bmp = ListBitmap->at(bmpIndex); + auto zMap = ListZMap->at(bmpIndex); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TCollisionComponent.cpp b/SpaceCadetPinball/TCollisionComponent.cpp index 1a9c891..493aad1 100644 --- a/SpaceCadetPinball/TCollisionComponent.cpp +++ b/SpaceCadetPinball/TCollisionComponent.cpp @@ -2,17 +2,15 @@ #include "TCollisionComponent.h" #include "loader.h" #include "maths.h" -#include "objlist_class.h" #include "TEdgeSegment.h" #include "TPinballTable.h" -TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) : TPinballComponent( - table, groupIndex, true) +TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) : + TPinballComponent(table, groupIndex, true) { visualStruct visual{}; - EdgeList = new objlist_class(4, 4); ActiveFlag = 1; if (GroupName != nullptr) UnusedBaseFlag = 1; @@ -42,22 +40,15 @@ TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, b TCollisionComponent::~TCollisionComponent() { - for (TEdgeSegment* edge; EdgeList->GetCount() > 0;) - { - edge = EdgeList->Get(0); - EdgeList->Delete(edge); + for (auto edge : EdgeList) delete edge; - } - delete EdgeList; } void TCollisionComponent::port_draw() { - for (int index = EdgeList->GetCount() - 1; index >= 0; index--) - { - EdgeList->Get(index)->port_draw(); - } + for (auto edge : EdgeList) + edge->port_draw(); } int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction) diff --git a/SpaceCadetPinball/TCollisionComponent.h b/SpaceCadetPinball/TCollisionComponent.h index 82707a9..e10232c 100644 --- a/SpaceCadetPinball/TCollisionComponent.h +++ b/SpaceCadetPinball/TCollisionComponent.h @@ -8,7 +8,7 @@ class TBall; class TCollisionComponent : public TPinballComponent { public: - objlist_class* EdgeList; + std::vector EdgeList; float Elasticity; float Smoothness; float Boost; diff --git a/SpaceCadetPinball/TComponentGroup.cpp b/SpaceCadetPinball/TComponentGroup.cpp index b5a87e2..6021766 100644 --- a/SpaceCadetPinball/TComponentGroup.cpp +++ b/SpaceCadetPinball/TComponentGroup.cpp @@ -4,13 +4,11 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "timer.h" #include "TPinballTable.h" TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) { - List = new objlist_class(4, 4); Timer = 0; if (groupIndex > 0) { @@ -21,7 +19,7 @@ TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinbal { auto component = table->find_component(*shortArrPtr); if (component) - List->Add(component); + List.push_back(component); } } } @@ -33,7 +31,6 @@ TComponentGroup::~TComponentGroup() timer::kill(Timer); Timer = 0; } - delete List; } int TComponentGroup::Message(int code, float value) @@ -50,9 +47,9 @@ int TComponentGroup::Message(int code, float value) } else if (code <= 1007 || code > 1011 && code != 1020 && code != 1022) { - for (int i = 0; i < List->GetCount(); i++) + for (auto component : List) { - List->Get(i)->Message(code, value); + component->Message(code, value); } } return 0; diff --git a/SpaceCadetPinball/TComponentGroup.h b/SpaceCadetPinball/TComponentGroup.h index e83c6b3..8d03163 100644 --- a/SpaceCadetPinball/TComponentGroup.h +++ b/SpaceCadetPinball/TComponentGroup.h @@ -11,6 +11,6 @@ public: int Message(int code, float value) override; static void NotifyTimerExpired(int timerId, void* caller); - objlist_class* List; + std::vector List; int Timer; }; diff --git a/SpaceCadetPinball/TEdgeBox.cpp b/SpaceCadetPinball/TEdgeBox.cpp deleted file mode 100644 index 05575df..0000000 --- a/SpaceCadetPinball/TEdgeBox.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "pch.h" -#include "TEdgeBox.h" - -#include "objlist_class.h" - -TEdgeBox::TEdgeBox() -{ - EdgeList = new objlist_class(0, 4); - FieldList = new objlist_class(0, 1); -} - -TEdgeBox::~TEdgeBox() -{ - delete EdgeList; - delete FieldList; -} diff --git a/SpaceCadetPinball/TEdgeBox.h b/SpaceCadetPinball/TEdgeBox.h index aac6312..bd9f70d 100644 --- a/SpaceCadetPinball/TEdgeBox.h +++ b/SpaceCadetPinball/TEdgeBox.h @@ -1,6 +1,4 @@ #pragma once -#include "objlist_class.h" - struct field_effect_type; class TEdgeSegment; @@ -8,10 +6,6 @@ class TEdgeSegment; class TEdgeBox { public: - TEdgeBox(); - ~TEdgeBox(); - - objlist_class* EdgeList; - objlist_class* FieldList; + std::vector EdgeList{}; + std::vector FieldList{}; }; - diff --git a/SpaceCadetPinball/TEdgeManager.cpp b/SpaceCadetPinball/TEdgeManager.cpp index 4fafa8e..634bb31 100644 --- a/SpaceCadetPinball/TEdgeManager.cpp +++ b/SpaceCadetPinball/TEdgeManager.cpp @@ -3,7 +3,6 @@ #include "maths.h" -#include "objlist_class.h" #include "TBall.h" #include "TEdgeBox.h" #include "TEdgeSegment.h" @@ -49,12 +48,12 @@ int TEdgeManager::increment_box_y(int y) void TEdgeManager::add_edge_to_box(int x, int y, TEdgeSegment* edge) { - BoxArray[x + y * MaxBoxX].EdgeList->Add(edge); + BoxArray[x + y * MaxBoxX].EdgeList.push_back(edge); } void TEdgeManager::add_field_to_box(int x, int y, field_effect_type* field) { - BoxArray[x + y * MaxBoxX].FieldList->Add(field); + BoxArray[x + y * MaxBoxX].FieldList.push_back(field); } int TEdgeManager::TestGridBox(int x, int y, float* distPtr, TEdgeSegment** edgeDst, ray_type* ray, TBall* ball, @@ -64,9 +63,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->GetCount() - 1; index >= 0; --index) + for (auto it = edgeBox->EdgeList.rbegin(); it != edgeBox->EdgeList.rend(); ++it) { - auto edge = edgeBox->EdgeList->Get(index); + auto edge = *it; if (!edge->ProcessedFlag && *edge->ActiveFlag && (edge->CollisionGroup & ray->FieldFlag)) { if (!ball->already_hit(edge)) @@ -94,9 +93,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->GetCount() - 1; index >= 0; --index) + for (auto it = edgeBox->FieldList.rbegin(); it != edgeBox->FieldList.rend(); ++it) { - auto field = edgeBox->FieldList->Get(index); + auto field = *it; if (*field->Flag2Ptr && ball->FieldFlag & field->Mask) { if (field->CollisionComp->FieldEffect(ball, &vec)) diff --git a/SpaceCadetPinball/TEdgeSegment.cpp b/SpaceCadetPinball/TEdgeSegment.cpp index 382c69b..53a7675 100644 --- a/SpaceCadetPinball/TEdgeSegment.cpp +++ b/SpaceCadetPinball/TEdgeSegment.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "TEdgeSegment.h" -#include "objlist_class.h" #include "TCircle.h" #include "TCollisionComponent.h" #include "TLine.h" @@ -41,7 +40,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c circle->place_in_grid(); } - collComp->EdgeList->Add(circle); + collComp->EdgeList.push_back(circle); break; } case wall_type::Line: @@ -58,7 +57,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c line->WallValue = reinterpret_cast(wallValue); line->Offset(offset); line->place_in_grid(); - collComp->EdgeList->Add(line); + collComp->EdgeList.push_back(line); } break; } @@ -104,7 +103,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c { circle->WallValue = reinterpret_cast(wallValue); circle->place_in_grid(); - collComp->EdgeList->Add(circle); + collComp->EdgeList.push_back(circle); } } } @@ -121,7 +120,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c line->WallValue = reinterpret_cast(wallValue); line->Offset(offset); line->place_in_grid(); - collComp->EdgeList->Add(line); + collComp->EdgeList.push_back(line); } prevCenter = center; diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 9e1ccd4..7286c1c 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "TBall.h" #include "timer.h" @@ -26,7 +25,7 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom if (line) { line->place_in_grid(); - EdgeList->Add(line); + EdgeList.push_back(line); } line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start); @@ -34,7 +33,7 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom if (line) { line->place_in_grid(); - EdgeList->Add(line); + EdgeList.push_back(line); } SpeedDecrement = 0.64999998f; @@ -61,8 +60,8 @@ int TFlagSpinner::Message(int code, float value) Timer = 0; } BmpIndex = 0; - auto bmp = ListBitmap->Get(0); - auto zMap = ListZMap->Get(0); + auto bmp = ListBitmap->at(0); + auto zMap = ListZMap->at(0); render::sprite_set( RenderSprite, bmp, @@ -108,7 +107,7 @@ void TFlagSpinner::NextFrame() { BmpIndex += SpinDirection; int bmpIndex = BmpIndex; - int bmpCount = ListBitmap->GetCount(); + int bmpCount = ListBitmap->size(); if (bmpIndex >= bmpCount) BmpIndex = 0; else if (bmpIndex < 0) @@ -123,8 +122,8 @@ void TFlagSpinner::NextFrame() control::handler(62, this); } - auto bmp = ListBitmap->Get(BmpIndex); - auto zMap = ListZMap->Get(BmpIndex); + auto bmp = ListBitmap->at(BmpIndex); + auto zMap = ListZMap->at(BmpIndex); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TFlipper.cpp b/SpaceCadetPinball/TFlipper.cpp index 0092c97..a9f194d 100644 --- a/SpaceCadetPinball/TFlipper.cpp +++ b/SpaceCadetPinball/TFlipper.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "pb.h" #include "render.h" #include "TFlipperEdge.h" @@ -52,8 +51,8 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t FlipperEdge = flipperEdge; if (flipperEdge) { - BmpCoef1 = flipperEdge->BmpCoef1 / static_cast(ListBitmap->GetCount() - 1); - BmpCoef2 = flipperEdge->BmpCoef2 / static_cast(ListBitmap->GetCount() - 1); + BmpCoef1 = flipperEdge->BmpCoef1 / static_cast(ListBitmap->size() - 1); + BmpCoef2 = flipperEdge->BmpCoef2 / static_cast(ListBitmap->size() - 1); } BmpIndex = 0; InputTime = 0.0; @@ -142,7 +141,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->GetCount(); + int bmpCount = flip->ListBitmap->size(); if (bmpIndexAdvance > bmpCount) bmpIndexAdvance = bmpCount; if (bmpIndexAdvance < 0) @@ -154,7 +153,7 @@ void TFlipper::TimerExpired(int timerId, void* caller) if (flip->MessageField == 1) { flip->BmpIndex += bmpIndexAdvance; - int countSub1 = flip->ListBitmap->GetCount() - 1; + int countSub1 = flip->ListBitmap->size() - 1; if (flip->BmpIndex >= countSub1) { flip->BmpIndex = countSub1; @@ -182,8 +181,8 @@ void TFlipper::TimerExpired(int timerId, void* caller) timer = timer::set(flip->TimerTime, flip, TimerExpired); flip->Timer = timer; - auto bmp = flip->ListBitmap->Get(flip->BmpIndex); - auto zMap = flip->ListZMap->Get(flip->BmpIndex); + auto bmp = flip->ListBitmap->at(flip->BmpIndex); + auto zMap = flip->ListZMap->at(flip->BmpIndex); render::sprite_set( flip->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TGate.cpp b/SpaceCadetPinball/TGate.cpp index 381fef7..851571e 100644 --- a/SpaceCadetPinball/TGate.cpp +++ b/SpaceCadetPinball/TGate.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) @@ -15,7 +14,7 @@ TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, SoundIndex4 = visual.SoundIndex4; SoundIndex3 = visual.SoundIndex3; ActiveFlag = 1; - render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); control::handler(1024, this); } @@ -32,7 +31,7 @@ int TGate::Message(int code, float value) else if (code == 54 || code == 1024) { ActiveFlag = 1; - render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); if (code == 54) loader::play_sound(SoundIndex4); } diff --git a/SpaceCadetPinball/THole.cpp b/SpaceCadetPinball/THole.cpp index cb06149..53bab24 100644 --- a/SpaceCadetPinball/THole.cpp +++ b/SpaceCadetPinball/THole.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "pb.h" #include "TBall.h" #include "timer.h" @@ -37,7 +36,7 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, if (tCircle) { tCircle->place_in_grid(); - EdgeList->Add(tCircle); + EdgeList.push_back(tCircle); } ZSetValue = loader::query_float_attribute(groupIndex, 0, 408)[2]; diff --git a/SpaceCadetPinball/TKickback.cpp b/SpaceCadetPinball/TKickback.cpp index 53e55c3..5aa486a 100644 --- a/SpaceCadetPinball/TKickback.cpp +++ b/SpaceCadetPinball/TKickback.cpp @@ -5,7 +5,6 @@ #include "control.h" #include "loader.h" #include "maths.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" @@ -66,8 +65,8 @@ void TKickback::TimerExpired(int timerId, void* caller) loader::play_sound(kick->HardHitSoundId); if (kick->ListBitmap) { - auto bmp = kick->ListBitmap->Get(1); - auto zMap = kick->ListZMap->Get(1); + auto bmp = kick->ListBitmap->at(1); + auto zMap = kick->ListZMap->at(1); render::sprite_set( kick->RenderSprite, bmp, @@ -80,8 +79,8 @@ void TKickback::TimerExpired(int timerId, void* caller) { if (kick->ListBitmap) { - auto bmp = kick->ListBitmap->Get(0); - auto zMap = kick->ListZMap->Get(0); + auto bmp = kick->ListBitmap->at(0); + auto zMap = kick->ListZMap->at(0); render::sprite_set( kick->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index 8a2b78e..0cce616 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "TBall.h" #include "TCircle.h" #include "timer.h" @@ -40,7 +39,7 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis if (tCircle) { tCircle->place_in_grid(); - EdgeList->Add(tCircle); + EdgeList.push_back(tCircle); } Circle.RadiusSq = visual.FloatArr[2] * visual.FloatArr[2]; diff --git a/SpaceCadetPinball/TLight.cpp b/SpaceCadetPinball/TLight.cpp index a093c6a..6903eaa 100644 --- a/SpaceCadetPinball/TLight.cpp +++ b/SpaceCadetPinball/TLight.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" @@ -143,14 +142,14 @@ int TLight::Message(int code, float value) schedule_timeout(value); break; case 11: - BmpIndex2 = static_cast(floor(value)); - if (BmpIndex2 > ListBitmap->GetCount()) - BmpIndex2 = ListBitmap->GetCount(); bmpIndex = 0; + BmpIndex2 = static_cast(floor(value)); + if (BmpIndex2 > static_cast(ListBitmap->size())) + BmpIndex2 = ListBitmap->size(); if (BmpIndex2 < 0) BmpIndex2 = 0; Flasher.BmpArr[0] = nullptr; - Flasher.BmpArr[1] = ListBitmap->Get(BmpIndex2); + Flasher.BmpArr[1] = ListBitmap->at(BmpIndex2); if (FlasherActive == 0) { if (!FlasherFlag1) @@ -169,8 +168,8 @@ int TLight::Message(int code, float value) break; case 12: bmpIndex = BmpIndex2 + 1; - if (bmpIndex > ListBitmap->GetCount()) - bmpIndex = ListBitmap->GetCount(); + if (bmpIndex > static_cast(ListBitmap->size())) + bmpIndex = ListBitmap->size(); Message(11, static_cast(bmpIndex)); break; case 13: @@ -257,7 +256,7 @@ void TLight::Reset() Flasher.Sprite = RenderSprite; Flasher.BmpArr[0] = nullptr; if (ListBitmap) - Flasher.BmpArr[1] = ListBitmap->Get(0); + Flasher.BmpArr[1] = ListBitmap->at(0); Flasher.Unknown4 = 0; Flasher.Unknown3 = 0; MessageField = 0; diff --git a/SpaceCadetPinball/TLightBargraph.cpp b/SpaceCadetPinball/TLightBargraph.cpp index f2d3699..041f4e3 100644 --- a/SpaceCadetPinball/TLightBargraph.cpp +++ b/SpaceCadetPinball/TLightBargraph.cpp @@ -5,7 +5,6 @@ #include "control.h" #include "loader.h" #include "memory.h" -#include "objlist_class.h" #include "timer.h" #include "TPinballTable.h" @@ -18,7 +17,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro float* floatArr = loader::query_float_attribute(groupIndex, 0, 904); if (floatArr) { - int count = 2 * List->GetCount(); + int count = 2 * List.size(); TimerTimeArray = memory::allocate(count); if (TimerTimeArray) { @@ -49,7 +48,7 @@ int TLightBargraph::Message(int code, float value) TimerBargraph = 0; } auto timeIndex = static_cast(floor(value)); - auto maxCount = 2 * List->GetCount(); + auto maxCount = static_cast(List.size()) * 2; if (timeIndex >= maxCount) timeIndex = maxCount - 1; if (timeIndex >= 0) diff --git a/SpaceCadetPinball/TLightGroup.cpp b/SpaceCadetPinball/TLightGroup.cpp index 7faec1b..e6d91ae 100644 --- a/SpaceCadetPinball/TLightGroup.cpp +++ b/SpaceCadetPinball/TLightGroup.cpp @@ -4,17 +4,15 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "timer.h" #include "TLight.h" #include "TPinballTable.h" TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) { - List = new objlist_class(4, 4); Timer = 0; NotifyTimer = 0; - Reset(); + TLightGroup::Reset(); if (groupIndex > 0) { int count; @@ -24,7 +22,7 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone { auto comp = dynamic_cast(table->find_component(*groupIndArr)); if (comp) - List->Add(comp); + List.push_back(comp); ++index; } } @@ -32,11 +30,11 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone TLightGroup::~TLightGroup() { - delete List; } int TLightGroup::Message(int code, float value) { + auto count = static_cast(List.size()); switch (code) { case 1011: @@ -71,8 +69,7 @@ int TLightGroup::Message(int code, float value) break; case 24: { - auto count = List->GetCount(); - auto lastLight = List->Get(count - 1); + auto lastLight = List.at(count - 1); if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) break; if (MessageField2) @@ -85,12 +82,12 @@ int TLightGroup::Message(int code, float value) auto bmpIndex1 = lastLight->BmpIndex1; for (auto index = count - 1; index > 0; --index) { - auto lightCur = List->Get(index); - auto lightPrev = List->Get(index - 1); + auto lightCur = List.at(index); + auto lightPrev = List.at(index - 1); lightCur->Message(lightPrev->BmpIndex1 != 0, 0.0); lightCur->MessageField = lightPrev->MessageField; } - auto firstLight = List->Get(0); + auto firstLight = List.at(0); firstLight->Message(bmpIndex1 != 0, 0.0); firstLight->MessageField = lightMessageField; reschedule_animation(value); @@ -98,23 +95,22 @@ int TLightGroup::Message(int code, float value) } case 25: { - auto count = List->GetCount(); - auto lastLight = List->Get(count - 1); + auto lastLight = List.at(count - 1); if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) break; if (MessageField2) { TLightGroup::Message(34, 0.0); } - auto firstLight = List->Get(0); + auto firstLight = List.at(0); AnimationFlag = 1; MessageField2 = code; auto lightMessageField = firstLight->MessageField; auto bmpIndex1 = firstLight->BmpIndex1; for (auto index = 0; index < count - 1; index++) { - auto lightCur = List->Get(index); - auto lightNext = List->Get(index + 1); + auto lightCur = List.at(index); + auto lightNext = List.at(index + 1); lightCur->Message(lightNext->BmpIndex1 != 0, 0.0); lightCur->MessageField = lightNext->MessageField; } @@ -129,16 +125,15 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->GetCount(); - auto lastLight = List->Get(count - 1); + auto lastLight = List.at(count - 1); auto flasherFlag2 = lastLight->FlasherFlag2; for (auto i = count - 1; i > 0; --i) { - auto lightCur = List->Get(i); - auto lightPrev = List->Get(i - 1); + auto lightCur = List.at(i); + auto lightPrev = List.at(i - 1); lightCur->Message((lightPrev->FlasherFlag2 != 0) + 8, 0.0); } - auto firstLight = List->Get(0); + auto firstLight = List.at(0); firstLight->Message((flasherFlag2 != 0) + 8, 0); reschedule_animation(value); break; @@ -149,16 +144,15 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->GetCount(); - auto firstLight = List->Get(0); + auto firstLight = List.at(0); auto flasherFlag2 = firstLight->FlasherFlag2; for (auto i = 0; i < count - 1; i++) { - auto lightCur = List->Get(i); - auto lightNext = List->Get(i + 1); + auto lightCur = List.at(i); + auto lightNext = List.at(i + 1); lightCur->Message((lightNext->FlasherFlag2 != 0) + 8, 0.0); } - auto lastLight = List->Get(count - 1); + auto lastLight = List.at(count - 1); lastLight->Message((flasherFlag2 != 0) + 8, 0); reschedule_animation(value); break; @@ -169,12 +163,10 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->GetCount(); - for (auto i = 0; i < count - 1; i++) + for (auto light : List) { if (rand() % 100 > 70) { - auto light = List->Get(i); auto randVal = RandFloat() * value * 3.0f + 0.1f; light->Message(9, randVal); } @@ -188,10 +180,8 @@ int TLightGroup::Message(int code, float value) start_animation(); MessageField2 = code; AnimationFlag = 0; - auto count = List->GetCount(); - for (auto i = 0; i < count - 1; i++) + for (auto light : List) { - auto light = List->Get(i); auto randVal = static_cast(rand() % 100 > 70); light->Message(18, randVal); } @@ -201,22 +191,18 @@ int TLightGroup::Message(int code, float value) case 30: { auto noBmpInd1Count = 0; - auto countSub1 = List->GetCount() - 1; - if (countSub1 < 0) - break; - - for (auto i = countSub1; i >= 0; i--) + for (auto light : List) { - if (!List->Get(i)->BmpIndex1) + if (!light->BmpIndex1) ++noBmpInd1Count; } if (!noBmpInd1Count) break; auto randModCount = rand() % noBmpInd1Count; - for (auto i = countSub1; i >= 0; i--) + for (auto it = List.rbegin(); it != List.rend(); ++it) { - auto light = List->Get(i); + auto light = *it; if (!light->BmpIndex1 && randModCount-- == 0) { light->Message(1, 0.0); @@ -231,22 +217,18 @@ int TLightGroup::Message(int code, float value) case 31: { auto bmpInd1Count = 0; - auto countSub1 = List->GetCount() - 1; - if (countSub1 < 0) - break; - - for (auto i = countSub1; i >= 0; i--) + for (auto light : List) { - if (List->Get(i)->BmpIndex1) + if (light->BmpIndex1) ++bmpInd1Count; } if (!bmpInd1Count) break; auto randModCount = rand() % bmpInd1Count; - for (auto i = countSub1; i >= 0; i--) + for (auto it = List.rbegin(); it != List.rend(); ++it) { - auto light = List->Get(i); + auto light = *it; if (light->BmpIndex1 && randModCount-- == 0) { light->Message(0, 0.0); @@ -263,7 +245,7 @@ int TLightGroup::Message(int code, float value) auto index = next_light_up(); if (index < 0) break; - List->Get(index)->Message(1, 0.0); + List.at(index)->Message(1, 0.0); if (MessageField2) start_animation(); return 1; @@ -273,7 +255,7 @@ int TLightGroup::Message(int code, float value) auto index = next_light_down(); if (index < 0) break; - List->Get(index)->Message(0, 0.0); + List.at(index)->Message(0, 0.0); if (MessageField2) start_animation(); return 1; @@ -292,10 +274,10 @@ int TLightGroup::Message(int code, float value) case 35: { auto index = static_cast(floor(value)); - if (index >= List->GetCount() || index < 0) + if (index >= count || index < 0) break; - auto light = List->Get(index); + auto light = List.at(index); light->Message(1, 0.0); if (MessageField2) start_animation(); @@ -304,10 +286,10 @@ int TLightGroup::Message(int code, float value) case 36: { auto index = static_cast(floor(value)); - if (index >= List->GetCount() || index < 0) + if (index >= count || index < 0) break; - auto light = List->Get(index); + auto light = List.at(index); light->Message(0, 0.0); if (MessageField2) start_animation(); @@ -316,16 +298,15 @@ int TLightGroup::Message(int code, float value) case 37: { auto bmp1Count = 0; - auto countSub1 = List->GetCount() - 1; - for (auto i = countSub1; i >= 0; i--) + for (auto light : List) { - if (List->Get(i)->BmpIndex1) + if (light->BmpIndex1) ++bmp1Count; } return bmp1Count; } case 38: - return List->GetCount(); + return count; case 39: return MessageField2; case 40: @@ -337,7 +318,7 @@ int TLightGroup::Message(int code, float value) break; if (MessageField2 || AnimationFlag) TLightGroup::Message(34, 0.0); - List->Get(index)->Message(15, value); + List.at(index)->Message(15, value); return 1; } case 42: @@ -347,7 +328,7 @@ int TLightGroup::Message(int code, float value) break; if (MessageField2 || AnimationFlag) TLightGroup::Message(34, 0.0); - List->Get(index)->Message(16, value); + List.at(index)->Message(16, value); return 1; } case 43: @@ -359,10 +340,9 @@ int TLightGroup::Message(int code, float value) break; case 44: { - auto countSub1 = List->GetCount() - 1; - for (auto index = countSub1; index >= 0; index--) + for (auto it = List.rbegin(); it != List.rend(); ++it) { - auto light = List->Get(index); + auto light = *it; if (light->BmpIndex1) { light->Message(0, 0.0); @@ -378,26 +358,21 @@ int TLightGroup::Message(int code, float value) auto index = static_cast(floor(value)); if (index >= 0) { - auto count = List->GetCount(); if (index <= count) { auto countSub1 = count - 1; if (countSub1 > index) { - countSub1 = index; for (auto i = countSub1, k = countSub1 - index; k != 0; i--, k--) { - auto light = List->Get(i); + auto light = List.at(i); light->Message(20, 0.0); } } - if (countSub1 >= 0) + + for (auto it = List.rbegin(); it != List.rend(); ++it) { - for (auto i = countSub1; i != 0; i--) - { - auto light = List->Get(i); - light->Message(19, 0.0); - } + (*it)->Message(19, 0.0); } } } @@ -408,14 +383,14 @@ int TLightGroup::Message(int code, float value) auto index = next_light_down(); if (index >= 0) { - List->Get(index)->Message(4, 0.0); + List.at(index)->Message(4, 0.0); } break; } default: - for (auto index = List->GetCount() - 1; index >= 0; index--) + for (auto it = List.rbegin(); it != List.rend(); ++it) { - List->Get(index)->Message(code, value); + (*it)->Message(code, value); } break; } @@ -453,9 +428,9 @@ void TLightGroup::reschedule_animation(float time) void TLightGroup::start_animation() { - for (int index = List->GetCount() - 1; index >= 0; --index) + for (auto it = List.rbegin(); it != List.rend(); ++it) { - auto light = List->Get(index); + auto light = *it; if (light->BmpIndex1) light->Message(9, 0.0); else @@ -465,19 +440,19 @@ void TLightGroup::start_animation() int TLightGroup::next_light_up() { - for (int index = 0; index < List->GetCount(); ++index) + for (auto index = 0u; index < List.size(); ++index) { - if (!List->Get(index)->BmpIndex1) - return index; + if (!List.at(index)->BmpIndex1) + return static_cast(index); } return -1; } int TLightGroup::next_light_down() { - for (int index = List->GetCount() - 1; index >= 0; --index) + for (auto index = static_cast(List.size()) - 1; index >= 0; --index) { - if (!List->Get(index)->BmpIndex1) + if (!List.at(index)->BmpIndex1) return index; } return -1; diff --git a/SpaceCadetPinball/TLightGroup.h b/SpaceCadetPinball/TLightGroup.h index 1d21219..1d4129e 100644 --- a/SpaceCadetPinball/TLightGroup.h +++ b/SpaceCadetPinball/TLightGroup.h @@ -29,7 +29,7 @@ public: static void TimerExpired(int timerId, void* caller); static void NotifyTimerExpired(int timerId, void* caller); - objlist_class* List; + std::vector List; float Timer1Time; float Timer1TimeDefault; int MessageField2; diff --git a/SpaceCadetPinball/TLightRollover.cpp b/SpaceCadetPinball/TLightRollover.cpp index 53a7118..5ec855d 100644 --- a/SpaceCadetPinball/TLightRollover.cpp +++ b/SpaceCadetPinball/TLightRollover.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "TBall.h" #include "timer.h" @@ -58,7 +57,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, ListBitmap->Get(0)); + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); } } } diff --git a/SpaceCadetPinball/TOneway.cpp b/SpaceCadetPinball/TOneway.cpp index 9082dbc..ca97678 100644 --- a/SpaceCadetPinball/TOneway.cpp +++ b/SpaceCadetPinball/TOneway.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "TBall.h" #include "TLine.h" #include "TPinballTable.h" @@ -27,7 +26,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab { line->Offset(table->CollisionCompOffset); line->place_in_grid(); - EdgeList->Add(line); + EdgeList.push_back(line); } line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2); @@ -36,7 +35,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab { line->Offset(-table->CollisionCompOffset * 0.8f); Line->place_in_grid(); - EdgeList->Add(Line); + EdgeList.push_back(Line); } } } diff --git a/SpaceCadetPinball/TPinballComponent.cpp b/SpaceCadetPinball/TPinballComponent.cpp index 61b6b5a..d23d412 100644 --- a/SpaceCadetPinball/TPinballComponent.cpp +++ b/SpaceCadetPinball/TPinballComponent.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "TPinballComponent.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "TPinballTable.h" @@ -19,7 +18,7 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool GroupName = nullptr; Control = nullptr; if (table) - table->ComponentList->Add(this); + table->ComponentList.push_back(this); if (groupIndex >= 0) GroupName = loader::query_name(groupIndex); if (loadVisuals && groupIndex >= 0) @@ -31,32 +30,31 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool if (visual.Bitmap) { if (!ListBitmap) - ListBitmap = new objlist_class(visualCount, 4); + ListBitmap = new std::vector(); if (ListBitmap) - ListBitmap->Add(visual.Bitmap); + ListBitmap->push_back(visual.Bitmap); } if (visual.ZMap) { if (!ListZMap) - ListZMap = new objlist_class(visualCount, 4); + ListZMap = new std::vector(); if (ListZMap) - ListZMap->Add(visual.ZMap); + ListZMap->push_back(visual.ZMap); } } - zmap_header_type* zMap = nullptr; - if (ListZMap) - zMap = ListZMap->Get(0); + + auto zMap = ListZMap ? ListZMap->at(0) : nullptr; if (ListBitmap) { rectangle_type bmp1Rect{}, tmpRect{}; - auto rootBmp = ListBitmap->Get(0); + auto rootBmp = ListBitmap->at(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->GetCount(); index++) + for (auto index = 1u; index < ListBitmap->size(); index++) { - auto bmp = ListBitmap->Get(index); + auto bmp = ListBitmap->at(index); tmpRect.XPosition = bmp->XPosition - table->XOffset; tmpRect.YPosition = bmp->YPosition - table->YOffset; tmpRect.Width = bmp->Width; @@ -79,9 +77,14 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool TPinballComponent::~TPinballComponent() { - TPinballTable* table = PinballTable; - if (table) - table->ComponentList->Delete(this); + if (PinballTable) + { + // ComponentList contains one reference to each component. + auto& components = PinballTable->ComponentList; + auto position = std::find(components.begin(), components.end(), this); + if (position != components.end()) + components.erase(position); + } delete ListBitmap; delete ListZMap; diff --git a/SpaceCadetPinball/TPinballComponent.h b/SpaceCadetPinball/TPinballComponent.h index 839c570..a3040da 100644 --- a/SpaceCadetPinball/TPinballComponent.h +++ b/SpaceCadetPinball/TPinballComponent.h @@ -1,5 +1,4 @@ #pragma once -#include "objlist_class.h" struct zmap_header_type; struct gdrv_bitmap8; @@ -32,11 +31,10 @@ public: char ActiveFlag; int MessageField; char* GroupName; - int Unknown4; component_control* Control; int GroupIndex; render_sprite_type_struct* RenderSprite; TPinballTable* PinballTable; - objlist_class* ListBitmap; - objlist_class* ListZMap; + std::vector* ListBitmap; + std::vector* ListZMap; }; diff --git a/SpaceCadetPinball/TPinballTable.cpp b/SpaceCadetPinball/TPinballTable.cpp index 96f8602..f995b91 100644 --- a/SpaceCadetPinball/TPinballTable.cpp +++ b/SpaceCadetPinball/TPinballTable.cpp @@ -5,11 +5,9 @@ #include "control.h" #include "loader.h" #include "memory.h" -#include "objlist_class.h" #include "pb.h" #include "pinball.h" #include "render.h" -#include "Sound.h" #include "TBall.h" #include "TBlocker.h" #include "TBumper.h" @@ -48,8 +46,6 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) { int shortArrLength; - ComponentList = new objlist_class(32, 16); - BallList = new objlist_class(3, 1); CurScoreStruct = nullptr; ScoreBallcount = nullptr; ScorePlayerNumber1 = nullptr; @@ -64,7 +60,7 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) PlayerCount = 0; auto ballObj = new TBall(this); - BallList->Add(ballObj); + BallList.push_back(ballObj); if (ballObj) ballObj->ActiveFlag = 0; new TTableLayer(this); @@ -103,7 +99,7 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) Plunger = new TPlunger(this, groupIndex); break; case 1002: - LightGroup->List->Add(new TLight(this, groupIndex)); + LightGroup->List.push_back(new TLight(this, groupIndex)); break; case 1003: FlipperL = new TFlipper(this, groupIndex); @@ -213,30 +209,25 @@ TPinballTable::~TPinballTable() ScoreBallcount = nullptr; } delete LightGroup; - while (ComponentList->GetCount() > 0) + while (!ComponentList.empty()) { - delete ComponentList->Get(0); + // Component destructor removes it from the list. + delete ComponentList[0]; } - delete BallList; - delete ComponentList; control::ClearLinks(); } TPinballComponent* TPinballTable::find_component(LPCSTR componentName) { - int objCount = ComponentList->GetCount(); - if (objCount > 0) + for (auto component : ComponentList) { - for (int index = 0; index < objCount; ++index) + const char* groupName = component->GroupName; + if (groupName && !strcmp(groupName, componentName)) { - TPinballComponent* obj = ComponentList->Get(index); - const char* groupName = obj->GroupName; - if (groupName && !strcmp(groupName, componentName)) - { - return obj; - } + return component; } } + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName, nullptr); return nullptr; } @@ -244,16 +235,12 @@ TPinballComponent* TPinballTable::find_component(LPCSTR componentName) TPinballComponent* TPinballTable::find_component(int groupIndex) { char Buffer[40]{}; - int objCount = ComponentList->GetCount(); - if (objCount > 0) + for (auto component : ComponentList) { - for (int index = 0; index < objCount; ++index) - { - TPinballComponent* obj = ComponentList->Get(index); - if (obj->GroupIndex == groupIndex) - return obj; - } + if (component->GroupIndex == groupIndex) + return component; } + snprintf(Buffer, sizeof Buffer, "%d", groupIndex); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer, nullptr); return nullptr; @@ -308,9 +295,9 @@ void TPinballTable::tilt(float time) loader::play_sound(SoundIndex3); TiltTimeoutTimer = timer::set(30.0, this, tilt_timeout); - for (int i = 0; i < ComponentList->GetCount(); i++) + for (auto component : ComponentList) { - ComponentList->Get(i)->Message(1011, time); + component->Message(1011, time); } LightGroup->Message(8, 0); TiltLockFlag = 1; @@ -321,9 +308,9 @@ void TPinballTable::tilt(float time) void TPinballTable::port_draw() { - for (int index = ComponentList->GetCount() - 1; index >= 0; index--) + for (auto component : ComponentList) { - ComponentList->Get(index)->port_draw(); + component->port_draw(); } } @@ -363,9 +350,9 @@ int TPinballTable::Message(int code, float value) case 1008: case 1009: case 1010: - for (int i = 0; i < ComponentList->GetCount(); i++) + for (auto component : ComponentList) { - ComponentList->Get(i)->Message(code, value); + component->Message(code, value); } break; case 1012: @@ -407,7 +394,7 @@ int TPinballTable::Message(int code, float value) { CheatsUsed = 0; Message(1024, 0.0); - auto ball = BallList->Get(0); + auto ball = BallList[0]; ball->Position.Y = 0.0; ball->Position.X = 0.0; ball->Position.Z = -0.8f; @@ -452,7 +439,7 @@ int TPinballTable::Message(int code, float value) { score::set(PlayerScores[scoreIndex].ScoreStruct, -1); } - + ScoreSpecial3Flag = 0; ScoreSpecial2Flag = 0; UnknownP71 = 0; @@ -509,9 +496,9 @@ int TPinballTable::Message(int code, float value) score::set(ScorePlayerNumber1, nextPlayer + 1); score::update(ScorePlayerNumber1); - for (int i = 0; i < ComponentList->GetCount(); i++) + for (auto component : ComponentList) { - ComponentList->Get(i)->Message(1020, static_cast(nextPlayer)); + component->Message(1020, static_cast(nextPlayer)); } char* textboxText = nullptr; @@ -560,9 +547,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->GetCount(); i++) + for (auto component : ComponentList) { - ComponentList->Get(i)->Message(1024, 0); + component->Message(1024, 0); } if (ReplayTimer) timer::kill(ReplayTimer); @@ -604,9 +591,9 @@ void TPinballTable::EndGame_timeout(int timerId, void* caller) table->EndGameTimeoutTimer = 0; pb::end_game(); - for (int i = 0; i < table->ComponentList->GetCount(); i++) + for (auto component : table->ComponentList) { - table->ComponentList->Get(i)->Message(1022, 0); + component->Message(1022, 0); } if (table->Demo) table->Demo->Message(1022, 0.0); @@ -636,9 +623,9 @@ void TPinballTable::tilt_timeout(int timerId, void* caller) table->TiltTimeoutTimer = 0; if (table->TiltLockFlag) { - for (int i = 0; i < table->BallList->GetCount(); i++) + for (auto ball : table->BallList) { - table->Drain->Collision(table->BallList->Get(i), &vec, &vec, 0.0, nullptr); + table->Drain->Collision(ball, &vec, &vec, 0.0, nullptr); } } } diff --git a/SpaceCadetPinball/TPinballTable.h b/SpaceCadetPinball/TPinballTable.h index 037b357..031955d 100644 --- a/SpaceCadetPinball/TPinballTable.h +++ b/SpaceCadetPinball/TPinballTable.h @@ -65,8 +65,8 @@ public: int YOffset; int Width; int Height; - objlist_class* ComponentList; - objlist_class* BallList; + std::vector ComponentList; + std::vector BallList; TLightGroup* LightGroup; float GravityDirVectMult; float GravityAngleX; diff --git a/SpaceCadetPinball/TPlunger.cpp b/SpaceCadetPinball/TPlunger.cpp index 65b6f27..dcbf324 100644 --- a/SpaceCadetPinball/TPlunger.cpp +++ b/SpaceCadetPinball/TPlunger.cpp @@ -5,7 +5,6 @@ #include "control.h" #include "loader.h" #include "maths.h" -#include "objlist_class.h" #include "pb.h" #include "render.h" #include "TBall.h" @@ -27,7 +26,7 @@ TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(t MaxPullback = 100; Elasticity = 0.5f; Smoothness = 0.5f; - PullbackIncrement = static_cast(100.0 / (ListBitmap->GetCount() * 8.0)); + PullbackIncrement = static_cast(100.0 / (ListBitmap->size() * 8.0)); Unknown4F = 0.025f; float* floatArr = loader::query_float_attribute(groupIndex, 0, 601); table->PlungerPositionX = floatArr[0]; @@ -65,8 +64,8 @@ int TPlunger::Message(int code, float value) PullbackTimer_ = 0; if (code == 1005) loader::play_sound(SoundIndexP2); - auto bmp = ListBitmap->Get(0); - auto zMap = ListZMap->Get(0); + auto bmp = ListBitmap->at(0); + auto zMap = ListZMap->at(0); render::sprite_set( RenderSprite, bmp, @@ -79,7 +78,7 @@ int TPlunger::Message(int code, float value) } case 1015: { - auto ball = PinballTable->BallList->Get(0); + auto ball = PinballTable->BallList.at(0); ball->Message(1024, 0.0); ball->Position.X = PinballTable->PlungerPositionX; ball->Position.Y = PinballTable->PlungerPositionY; @@ -112,8 +111,8 @@ int TPlunger::Message(int code, float value) PullbackTimer_ = 0; if (code == 1005) loader::play_sound(SoundIndexP2); - auto bmp = ListBitmap->Get(0); - auto zMap = ListZMap->Get(0); + auto bmp = ListBitmap->at(0); + auto zMap = ListZMap->at(0); render::sprite_set( RenderSprite, bmp, @@ -151,10 +150,10 @@ void TPlunger::PullbackTimer(int timerId, void* caller) plunger->Boost = static_cast(plunger->MaxPullback); } int index = static_cast(floor( - static_cast(plunger->ListBitmap->GetCount() - 1) * + static_cast(plunger->ListBitmap->size() - 1) * (plunger->Boost / static_cast(plunger->MaxPullback)))); - auto bmp = plunger->ListBitmap->Get(index); - auto zMap = plunger->ListZMap->Get(index); + auto bmp = plunger->ListBitmap->at(index); + auto zMap = plunger->ListZMap->at(index); render::sprite_set( plunger->RenderSprite, bmp, diff --git a/SpaceCadetPinball/TPopupTarget.cpp b/SpaceCadetPinball/TPopupTarget.cpp index 47c76ab..7a72786 100644 --- a/SpaceCadetPinball/TPopupTarget.cpp +++ b/SpaceCadetPinball/TPopupTarget.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" @@ -91,7 +90,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, target->ListBitmap->Get(0)); + render::sprite_set_bitmap(target->RenderSprite, target->ListBitmap->at(0)); if (timerId) { if (target->SoftHitSoundId) diff --git a/SpaceCadetPinball/TRamp.cpp b/SpaceCadetPinball/TRamp.cpp index 58e2393..5b524ce 100644 --- a/SpaceCadetPinball/TRamp.cpp +++ b/SpaceCadetPinball/TRamp.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "TBall.h" #include "TEdgeSegment.h" #include "TLine.h" @@ -35,7 +34,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, start.X = floatArr4[4]; start.Y = floatArr4[5]; Line1 = new TLine(this, &ActiveFlag, 1 << static_cast(floor(floatArr4[0])), &start, &end); - EdgeList->Add(Line1); + EdgeList.push_back(Line1); if (Line1) { Line1->WallValue = nullptr; @@ -53,7 +52,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, &end2, &start2); Line2 = new TLine(this, &ActiveFlag, CollisionGroup, start2, end2); - EdgeList->Add(Line2); + EdgeList.push_back(Line2); if (Line2) { Line2->WallValue = nullptr; @@ -71,7 +70,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, &end3, &start3); Line3 = new TLine(this, &ActiveFlag, CollisionGroup, start3, end3); - EdgeList->Add(Line3); + EdgeList.push_back(Line3); if (Line3) { Line3->WallValue = nullptr; @@ -118,7 +117,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, if (collisionGroup) { auto line = new TLine(this, &ActiveFlag, collisionGroup, point1, point2); - EdgeList->Add(line); + EdgeList.push_back(line); if (line) { line->WallValue = plane; diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index fd7274b..ef77575 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -5,7 +5,6 @@ #include "control.h" #include "gdrv.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "TBall.h" #include "TEdgeSegment.h" @@ -22,7 +21,7 @@ TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent { RolloverFlag = 0; if (ListBitmap) - render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); build_walls(groupIndex); } @@ -34,7 +33,7 @@ int TRollover::Message(int code, float value) this->ActiveFlag = 1; this->RolloverFlag = 0; if (this->ListBitmap) - render::sprite_set_bitmap(this->RenderSprite, this->ListBitmap->Get(0)); + render::sprite_set_bitmap(this->RenderSprite, this->ListBitmap->at(0)); } return 0; } @@ -63,7 +62,7 @@ void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* d if (ListBitmap) { if (!RolloverFlag) - bmp = ListBitmap->Get(0); + bmp = ListBitmap->at(0); render::sprite_set_bitmap(RenderSprite, bmp); } } diff --git a/SpaceCadetPinball/TSink.cpp b/SpaceCadetPinball/TSink.cpp index fd87525..21323f6 100644 --- a/SpaceCadetPinball/TSink.cpp +++ b/SpaceCadetPinball/TSink.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "TPinballTable.h" #include "TBall.h" @@ -95,7 +94,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 = sink->PinballTable->BallList->Get(0); + auto ball = sink->PinballTable->BallList.at(0); ball->CollisionComp = nullptr; ball->ActiveFlag = 1; ball->Position.X = sink->BallPosition.X; diff --git a/SpaceCadetPinball/TSoloTarget.cpp b/SpaceCadetPinball/TSoloTarget.cpp index 25af76f..8ac9e28 100644 --- a/SpaceCadetPinball/TSoloTarget.cpp +++ b/SpaceCadetPinball/TSoloTarget.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "loader.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" #include "TPinballTable.h" @@ -41,8 +40,8 @@ int TSoloTarget::Message(int code, float value) if (ListBitmap) { auto index = 1 - ActiveFlag; - auto bmp = ListBitmap->Get(index); - auto zMap = ListZMap->Get(index); + auto bmp = ListBitmap->at(index); + auto zMap = ListZMap->at(index); render::sprite_set( RenderSprite, bmp, diff --git a/SpaceCadetPinball/TTableLayer.cpp b/SpaceCadetPinball/TTableLayer.cpp index 0c2b5f5..e45ba36 100644 --- a/SpaceCadetPinball/TTableLayer.cpp +++ b/SpaceCadetPinball/TTableLayer.cpp @@ -4,7 +4,6 @@ #include "fullscrn.h" #include "loader.h" -#include "objlist_class.h" #include "pb.h" #include "proj.h" #include "render.h" @@ -91,7 +90,7 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f if (line) { line->place_in_grid(); - EdgeList->Add(line); + EdgeList.push_back(line); } visArrPtr += 2; diff --git a/SpaceCadetPinball/TTextBox.cpp b/SpaceCadetPinball/TTextBox.cpp index fd66558..7044770 100644 --- a/SpaceCadetPinball/TTextBox.cpp +++ b/SpaceCadetPinball/TTextBox.cpp @@ -4,7 +4,6 @@ #include "control.h" #include "fullscrn.h" #include "loader.h" -#include "pb.h" #include "render.h" #include "score.h" #include "timer.h" diff --git a/SpaceCadetPinball/TWall.cpp b/SpaceCadetPinball/TWall.cpp index ed63ea6..4ed3106 100644 --- a/SpaceCadetPinball/TWall.cpp +++ b/SpaceCadetPinball/TWall.cpp @@ -3,7 +3,6 @@ #include "control.h" -#include "objlist_class.h" #include "render.h" #include "timer.h" @@ -12,7 +11,7 @@ TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent(table, if (RenderSprite) render::sprite_set_bitmap(RenderSprite, nullptr); if (ListBitmap) - BmpPtr = ListBitmap->Get(0); + BmpPtr = ListBitmap->at(0); Timer = 0; } diff --git a/SpaceCadetPinball/control.cpp b/SpaceCadetPinball/control.cpp index 900de4d..ab775fc 100644 --- a/SpaceCadetPinball/control.cpp +++ b/SpaceCadetPinball/control.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "control.h" -#include "objlist_class.h" #include "pb.h" #include "pinball.h" #include "TBlocker.h" @@ -606,16 +605,14 @@ TPinballComponent* control::make_component_link(component_tag_base* tag) if (tag->GetComponent()) return tag->GetComponent(); - auto compList = TableG->ComponentList; - for (int index = 0; index < compList->GetCount(); index++) + for (auto component: TableG->ComponentList) { - auto comp = compList->Get(index); - if (comp->GroupName) + if (component->GroupName) { - if (!strcmp(comp->GroupName, tag->Name)) + if (!strcmp(component->GroupName, tag->Name)) { - tag->SetComponent(comp); - return comp; + tag->SetComponent(component); + return component; } } } diff --git a/SpaceCadetPinball/gdrv.cpp b/SpaceCadetPinball/gdrv.cpp index 6eb5e6b..b906799 100644 --- a/SpaceCadetPinball/gdrv.cpp +++ b/SpaceCadetPinball/gdrv.cpp @@ -3,7 +3,6 @@ #include "GroupData.h" #include "memory.h" -#include "options.h" #include "partman.h" #include "pb.h" #include "score.h" diff --git a/SpaceCadetPinball/high_score.cpp b/SpaceCadetPinball/high_score.cpp index a092d93..1254c8c 100644 --- a/SpaceCadetPinball/high_score.cpp +++ b/SpaceCadetPinball/high_score.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "high_score.h" -#include "memory.h" #include "options.h" #include "pinball.h" #include "score.h" diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index 258d399..66aea80 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -87,7 +87,7 @@ void loader::loadfrom(DatFile* datFile) loader_table = datFile; sound_record_table = loader_table; - for (auto groupIndex = 0; groupIndex < datFile->Groups.size(); ++groupIndex) + for (auto groupIndex = 0; groupIndex < static_cast(datFile->Groups.size()); ++groupIndex) { auto value = reinterpret_cast(datFile->field(groupIndex, FieldTypes::ShortValue)); if (value && *value == 202) diff --git a/SpaceCadetPinball/loader.h b/SpaceCadetPinball/loader.h index f6415d0..0e7e22a 100644 --- a/SpaceCadetPinball/loader.h +++ b/SpaceCadetPinball/loader.h @@ -4,7 +4,7 @@ #include "zdrv.h" -struct DatFile; +class DatFile; struct errorMsg { diff --git a/SpaceCadetPinball/midi.cpp b/SpaceCadetPinball/midi.cpp index 7ab3f17..68a19a1 100644 --- a/SpaceCadetPinball/midi.cpp +++ b/SpaceCadetPinball/midi.cpp @@ -6,7 +6,7 @@ #include "pinball.h" -objlist_class* midi::LoadedTracks; +std::vector midi::LoadedTracks{}; Mix_Music *midi::track1, *midi::track2, *midi::track3, *midi::active_track, *midi::NextTrack; bool midi::SetNextTrackFlag; @@ -50,7 +50,6 @@ int midi::music_stop() int midi::music_init() { active_track = nullptr; - LoadedTracks = new objlist_class(0, 1); if (pb::FullTiltMode) { @@ -76,14 +75,12 @@ void midi::music_shutdown() if (active_track) Mix_HaltMusic(); - while (LoadedTracks->GetCount()) + for (auto midi : LoadedTracks) { - auto midi = LoadedTracks->Get(0); Mix_FreeMusic(midi); - LoadedTracks->Delete(midi); } active_track = nullptr; - delete LoadedTracks; + LoadedTracks.clear(); } Mix_Music* midi::load_track(std::string fileName) @@ -132,7 +129,7 @@ Mix_Music* midi::load_track(std::string fileName) if (!audio) return nullptr; - LoadedTracks->Add(audio); + LoadedTracks.push_back(audio); return audio; } diff --git a/SpaceCadetPinball/midi.h b/SpaceCadetPinball/midi.h index a1e1957..15a4842 100644 --- a/SpaceCadetPinball/midi.h +++ b/SpaceCadetPinball/midi.h @@ -1,5 +1,4 @@ #pragma once -#include "objlist_class.h" constexpr uint32_t SwapByteOrderInt(uint32_t val) { @@ -92,7 +91,7 @@ public: static int music_init(); static void music_shutdown(); private: - static objlist_class* LoadedTracks; + static std::vector LoadedTracks; static Mix_Music *track1, *track2, *track3, *active_track, *NextTrack; static bool SetNextTrackFlag; static Mix_Music* load_track(std::string fileName); diff --git a/SpaceCadetPinball/nudge.cpp b/SpaceCadetPinball/nudge.cpp index e54c70c..3609b8a 100644 --- a/SpaceCadetPinball/nudge.cpp +++ b/SpaceCadetPinball/nudge.cpp @@ -2,7 +2,6 @@ #include "nudge.h" -#include "objlist_class.h" #include "pb.h" #include "render.h" #include "TBall.h" @@ -68,12 +67,10 @@ void nudge::_nudge(float xDiff, float yDiff) vector_type accelMod; float invAccelX, invAccelY; - auto ballList = pb::MainTable->BallList; accelMod.X = xDiff * 0.5f; accelMod.Y = yDiff * 0.5f; - for (auto index = 0; index < ballList->GetCount(); index++) + for (auto ball : pb::MainTable->BallList) { - auto ball = ballList->Get(index); if (ball->ActiveFlag && !ball->CollisionComp) { ball->Acceleration.X = ball->Acceleration.X * ball->Speed; diff --git a/SpaceCadetPinball/objlist_class.h b/SpaceCadetPinball/objlist_class.h deleted file mode 100644 index b88abba..0000000 --- a/SpaceCadetPinball/objlist_class.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include "memory.h" - -template -class objlist_class -{ -public: - objlist_class(int sizeInt, int growSize) - { - ListPtr = memory::allocate(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 = 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: - T** ListPtr; - int GrowSize; - int Size; - int Count; -}; diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index d41f691..4a9112c 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -4,7 +4,6 @@ #include "fullscrn.h" #include "memory.h" #include "midi.h" -#include "pb.h" #include "Sound.h" #include "winmain.h" diff --git a/SpaceCadetPinball/partman.cpp b/SpaceCadetPinball/partman.cpp index 2df27fc..a8189ae 100644 --- a/SpaceCadetPinball/partman.cpp +++ b/SpaceCadetPinball/partman.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "partman.h" -#include "fullscrn.h" #include "gdrv.h" #include "GroupData.h" #include "memory.h" @@ -56,27 +55,25 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) bool abort = false; for (auto groupIndex = 0; !abort && groupIndex < header.NumberOfGroups; ++groupIndex) { - auto entryCount = _lread_char(fileHandle); + auto entryCount = LRead(fileHandle); auto groupData = new GroupData(groupIndex); groupData->ReserveEntries(entryCount); for (auto entryIndex = 0; entryIndex < entryCount; ++entryIndex) { auto entryData = new EntryData(); - auto entryType = static_cast(_lread_char(fileHandle)); + auto entryType = static_cast(LRead(fileHandle)); entryData->EntryType = entryType; - int fieldSize = _field_size[static_cast(entryType)]; - if (fieldSize < 0) - fieldSize = _lread_long(fileHandle); - entryData->FieldSize = fieldSize; + int fixedSize = _field_size[static_cast(entryType)]; + size_t fieldSize = fixedSize >= 0 ? fixedSize : LRead(fileHandle); + entryData->FieldSize = static_cast(fieldSize); if (entryType == FieldTypes::Bitmap8bit) { fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle); assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size"); - assertm(bmpHeader.Resolution >= 0 && bmpHeader.Resolution <= 2, - "partman: bitmap resolution out of bounds"); + assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds"); auto bmp = memory::allocate(); entryData->Buffer = reinterpret_cast(bmp); @@ -90,28 +87,28 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) else if (entryType == FieldTypes::Bitmap16bit) { /*Full tilt has extra byte(@0:resolution) in zMap*/ - char zMapResolution = 0; + auto zMapResolution = 0u; if (fullTiltMode) { - zMapResolution = _lread_char(fileHandle); + zMapResolution = LRead(fileHandle); fieldSize--; - assertm(zMapResolution >= 0 && zMapResolution <= 2, "partman: zMap resolution out of bounds"); + assertm(zMapResolution <= 2, "partman: zMap resolution out of bounds"); } fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle); - int length = fieldSize - sizeof(dat16BitBmpHeader); + auto length = fieldSize - sizeof(dat16BitBmpHeader); auto zMap = memory::allocate(); zdrv::create_zmap(zMap, zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride); zMap->Resolution = zMapResolution; - if (zMapHeader.Stride * zMapHeader.Height * 2 == length) + if (zMapHeader.Stride * zMapHeader.Height * 2u == length) { fread(zMap->ZPtr1, 1, length, fileHandle); } else { // 3DPB .dat has zeroed zMap headers, in groups 497 and 498, skip them. - fseek(fileHandle, length, SEEK_CUR); + fseek(fileHandle, static_cast(length), SEEK_CUR); } entryData->Buffer = reinterpret_cast(zMap); } @@ -140,17 +137,3 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) delete datFile; return nullptr; } - -char partman::_lread_char(FILE* file) -{ - char Buffer = 0; - fread(&Buffer, 1, 1, file); - return Buffer; -} - -int partman::_lread_long(FILE* file) -{ - int Buffer = 0; - fread(&Buffer, 1, 4, file); - return Buffer; -} diff --git a/SpaceCadetPinball/partman.h b/SpaceCadetPinball/partman.h index c421a2e..04fd02a 100644 --- a/SpaceCadetPinball/partman.h +++ b/SpaceCadetPinball/partman.h @@ -59,9 +59,15 @@ static_assert(sizeof(dat16BitBmpHeader) == 14, "Wrong size of zmap_header_type") class partman { public: - static struct DatFile* load_records(LPCSTR lpFileName, bool fullTiltMode); + static class DatFile* load_records(LPCSTR lpFileName, bool fullTiltMode); private: static short _field_size[]; - static char _lread_char(FILE* file); - static int _lread_long(FILE* file); + + template + static T LRead(FILE* file) + { + T Buffer{}; + fread(&Buffer, 1, sizeof(T), file); + return Buffer; + } }; diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 4c9bfda..be0287a 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -12,7 +12,6 @@ #include "loader.h" #include "midi.h" #include "nudge.h" -#include "objlist_class.h" #include "options.h" #include "timer.h" #include "winmain.h" @@ -75,7 +74,7 @@ int pb::init() zMin = cameraInfo[1]; zScaler = cameraInfo[2]; } - + render::init(nullptr, zMin, zScaler, resInfo->TableWidth, resInfo->TableHeight); gdrv::copy_bitmap( &render::vscreen, @@ -101,7 +100,7 @@ int pb::init() MainTable = new TPinballTable(); high_score::read(highscore_table); - ball_speed_limit = MainTable->BallList->Get(0)->Offset * 200.0f; + ball_speed_limit = MainTable->BallList.at(0)->Offset * 200.0f; --memory::critical_allocation; return 0; } @@ -112,8 +111,7 @@ int pb::uninit() loader::unload(); delete record_table; high_score::write(highscore_table); - if (MainTable) - delete MainTable; + delete MainTable; MainTable = nullptr; timer::uninit(); render::uninit(); @@ -208,7 +206,7 @@ void pb::replay_level(int demoMode) void pb::ballset(int x, int y) { - TBall* ball = MainTable->BallList->Get(0); + TBall* ball = MainTable->BallList.at(0); ball->Acceleration.X = x * 30.0f; ball->Acceleration.Y = y * 30.0f; ball->Speed = maths::normalize_2d(&ball->Acceleration); @@ -216,7 +214,6 @@ void pb::ballset(int x, int y) void pb::frame(int dtMilliSec) { - if (dtMilliSec > 100) dtMilliSec = 100; if (dtMilliSec <= 0) @@ -258,9 +255,8 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) { vector_type vec1{}, vec2{}; - for (int i = 0; i < MainTable->BallList->GetCount(); i++) + for (auto ball : MainTable->BallList) { - auto ball = MainTable->BallList->Get(i); if (ball->ActiveFlag != 0) { auto collComp = ball->CollisionComp; @@ -301,9 +297,8 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) if (drawBalls) { - for (int i = 0; i < MainTable->BallList->GetCount(); i++) + for (auto ball : MainTable->BallList) { - auto ball = MainTable->BallList->Get(i); if (ball->ActiveFlag) ball->Repaint(); } @@ -444,19 +439,19 @@ void pb::keydown(int key) { case 'b': TBall* ball; - if (MainTable->BallList->GetCount() <= 0) + if (MainTable->BallList.empty()) { ball = new TBall(MainTable); } else { - for (auto index = 0; ;) + for (auto index = 0u; ;) { - ball = MainTable->BallList->Get(index); + ball = MainTable->BallList.at(index); if (!ball->ActiveFlag) break; ++index; - if (index >= MainTable->BallList->GetCount()) + if (index >= MainTable->BallList.size()) { ball = new TBall(MainTable); break; diff --git a/SpaceCadetPinball/render.cpp b/SpaceCadetPinball/render.cpp index b5f2e88..51111ce 100644 --- a/SpaceCadetPinball/render.cpp +++ b/SpaceCadetPinball/render.cpp @@ -517,7 +517,7 @@ void render::SpriteViewer(bool* show) if (!bmp) continue; - auto type = BitmapTypes[static_cast(bmp->BitmapType)]; + auto type = BitmapTypes[static_cast(bmp->BitmapType)]; ImGui::Text("type:%s, size:%d, resolution: %dx%d, offset:%dx%d", type, bmp->Resolution, bmp->Width, bmp->Height, bmp->XPosition, bmp->YPosition); @@ -575,7 +575,7 @@ void render::BlitVScreen() reinterpret_cast(&lockedPixels), &pitch ); - assertm(pitch == vscreen.Width * sizeof(ColorRgba), "Padding on vScreen texture"); + assertm(static_cast(pitch) == vscreen.Width * sizeof(ColorRgba), "Padding on vScreen texture"); if (offset_x == 0 && offset_y == 0) { diff --git a/SpaceCadetPinball/zdrv.cpp b/SpaceCadetPinball/zdrv.cpp index 3eee96b..5b1ab21 100644 --- a/SpaceCadetPinball/zdrv.cpp +++ b/SpaceCadetPinball/zdrv.cpp @@ -1,7 +1,6 @@ #include "pch.h" #include "zdrv.h" #include "memory.h" -#include "pb.h" #include "winmain.h"