1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-18 10:37:53 +01:00

Replaced objlist_class with std::vector.

Fixed minor bug in TLightGroup.
Cleaned up some warnings.
This commit is contained in:
Muzychenko Andrey 2021-10-01 18:55:44 +03:00
parent 8a421a2623
commit 81c2034a16
54 changed files with 249 additions and 453 deletions

View file

@ -48,7 +48,6 @@ set(SOURCE_FILES
SpaceCadetPinball/midi.h SpaceCadetPinball/midi.h
SpaceCadetPinball/nudge.cpp SpaceCadetPinball/nudge.cpp
SpaceCadetPinball/nudge.h SpaceCadetPinball/nudge.h
SpaceCadetPinball/objlist_class.h
SpaceCadetPinball/options.cpp SpaceCadetPinball/options.cpp
SpaceCadetPinball/options.h SpaceCadetPinball/options.h
SpaceCadetPinball/partman.cpp SpaceCadetPinball/partman.cpp
@ -83,7 +82,6 @@ set(SOURCE_FILES
SpaceCadetPinball/TDemo.h SpaceCadetPinball/TDemo.h
SpaceCadetPinball/TDrain.cpp SpaceCadetPinball/TDrain.cpp
SpaceCadetPinball/TDrain.h SpaceCadetPinball/TDrain.h
SpaceCadetPinball/TEdgeBox.cpp
SpaceCadetPinball/TEdgeBox.h SpaceCadetPinball/TEdgeBox.h
SpaceCadetPinball/TEdgeManager.cpp SpaceCadetPinball/TEdgeManager.cpp
SpaceCadetPinball/TEdgeManager.h SpaceCadetPinball/TEdgeManager.h

View file

@ -247,8 +247,8 @@ int DatFile::record_labeled(LPCSTR targetGroupName)
if (!groupName) if (!groupName)
continue; continue;
int index; auto index = 0u;
for (index = 0; index < targetLength; index++) for (; index < targetLength; index++)
if (targetGroupName[index] != groupName[index]) if (targetGroupName[index] != groupName[index])
break; break;
if (index == targetLength && !targetGroupName[index] && !groupName[index]) if (index == targetLength && !targetGroupName[index] && !groupName[index])

View file

@ -12,7 +12,7 @@ int Sound::Init(int voices)
channelCount = 8; channelCount = 8;
num_channels = channelCount; 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); return Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024);
} }

View file

@ -5,7 +5,6 @@
#include "fullscrn.h" #include "fullscrn.h"
#include "loader.h" #include "loader.h"
#include "maths.h" #include "maths.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "proj.h" #include "proj.h"
#include "render.h" #include "render.h"
@ -32,7 +31,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false)
Position.X = 0.0; Position.X = 0.0;
Position.Y = 0.0; Position.Y = 0.0;
ListBitmap = new objlist_class<gdrv_bitmap8>(0, 4); ListBitmap = new std::vector<gdrv_bitmap8*>();
/*Full tilt: ball is ballN, where N[0,2] resolution*/ /*Full tilt: ball is ballN, where N[0,2] resolution*/
if (pb::FullTiltMode) if (pb::FullTiltMode)
@ -49,7 +48,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false)
{ {
loader::query_visual(groupIndex, index, &visual); loader::query_visual(groupIndex, index, &visual);
if (ListBitmap) if (ListBitmap)
ListBitmap->Add(visual.Bitmap); ListBitmap->push_back(visual.Bitmap);
auto visVec = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, index, 501)); auto visVec = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, index, 501));
auto zDepth = proj::z_distance(visVec); auto zDepth = proj::z_distance(visVec);
++index; ++index;
@ -79,13 +78,13 @@ void TBall::Repaint()
auto zDepth = proj::z_distance(&Position); auto zDepth = proj::z_distance(&Position);
auto zArrPtr = VisualZArray; auto zArrPtr = VisualZArray;
int index; auto index = 0u;
for (index = 0; index < ListBitmap->GetCount() - 1; ++index, zArrPtr++) for (; index < ListBitmap->size() - 1; ++index, zArrPtr++)
{ {
if (*zArrPtr <= zDepth) break; if (*zArrPtr <= zDepth) break;
} }
auto bmp = ListBitmap->Get(index); auto bmp = ListBitmap->at(index);
render::ball_set( render::ball_set(
RenderSprite, RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
@ -46,7 +45,7 @@ int TBlocker::Message(int code, float value)
case 52: case 52:
ActiveFlag = 1; ActiveFlag = 1;
loader::play_sound(SoundIndex4); loader::play_sound(SoundIndex4);
render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0));
break; break;
case 59: case 59:
break; break;

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -29,8 +28,9 @@ int TBumper::Message(int code, float value)
case 11: case 11:
{ {
auto nextBmp = static_cast<int>(floor(value)); auto nextBmp = static_cast<int>(floor(value));
if (2 * nextBmp > ListBitmap->GetCount() - 1) auto maxBmp = static_cast<int>(ListBitmap->size()) - 1;
nextBmp = (ListBitmap->GetCount() - 1) / 2; if (2 * nextBmp > maxBmp)
nextBmp = maxBmp / 2;
if (nextBmp < 0) if (nextBmp < 0)
nextBmp = 0; nextBmp = 0;
if (nextBmp != BmpIndex) if (nextBmp != BmpIndex)
@ -48,7 +48,7 @@ int TBumper::Message(int code, float value)
case 12: case 12:
{ {
auto nextBmp = BmpIndex + 1; auto nextBmp = BmpIndex + 1;
auto maxBmp = ListBitmap->GetCount() - 1; auto maxBmp = static_cast<int>(ListBitmap->size()) - 1;
if (2 * nextBmp > maxBmp) if (2 * nextBmp > maxBmp)
nextBmp = maxBmp / 2; nextBmp = maxBmp / 2;
TBumper::Message(11, static_cast<float>(nextBmp)); TBumper::Message(11, static_cast<float>(nextBmp));
@ -124,8 +124,8 @@ int TBumper::get_scoring(int index)
void TBumper::TimerExpired(int timerId, void* caller) void TBumper::TimerExpired(int timerId, void* caller)
{ {
auto bump = static_cast<TBumper*>(caller); auto bump = static_cast<TBumper*>(caller);
auto bmp = bump->ListBitmap->Get(bump->BmpIndex * 2); auto bmp = bump->ListBitmap->at(bump->BmpIndex * 2);
auto zMap = bump->ListZMap->Get(bump->BmpIndex * 2); auto zMap = bump->ListZMap->at(bump->BmpIndex * 2);
bump->Timer = 0; bump->Timer = 0;
render::sprite_set( render::sprite_set(
bump->RenderSprite, bump->RenderSprite,
@ -139,8 +139,8 @@ void TBumper::TimerExpired(int timerId, void* caller)
void TBumper::Fire() void TBumper::Fire()
{ {
int bmpIndex = 2 * BmpIndex + 1; int bmpIndex = 2 * BmpIndex + 1;
auto bmp = ListBitmap->Get(bmpIndex); auto bmp = ListBitmap->at(bmpIndex);
auto zMap = ListZMap->Get(bmpIndex); auto zMap = ListZMap->at(bmpIndex);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,

View file

@ -2,17 +2,15 @@
#include "TCollisionComponent.h" #include "TCollisionComponent.h"
#include "loader.h" #include "loader.h"
#include "maths.h" #include "maths.h"
#include "objlist_class.h"
#include "TEdgeSegment.h" #include "TEdgeSegment.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) : TPinballComponent( TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) :
table, groupIndex, true) TPinballComponent(table, groupIndex, true)
{ {
visualStruct visual{}; visualStruct visual{};
EdgeList = new objlist_class<TEdgeSegment>(4, 4);
ActiveFlag = 1; ActiveFlag = 1;
if (GroupName != nullptr) if (GroupName != nullptr)
UnusedBaseFlag = 1; UnusedBaseFlag = 1;
@ -42,22 +40,15 @@ TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, b
TCollisionComponent::~TCollisionComponent() TCollisionComponent::~TCollisionComponent()
{ {
for (TEdgeSegment* edge; EdgeList->GetCount() > 0;) for (auto edge : EdgeList)
{
edge = EdgeList->Get(0);
EdgeList->Delete(edge);
delete edge; delete edge;
}
delete EdgeList;
} }
void TCollisionComponent::port_draw() void TCollisionComponent::port_draw()
{ {
for (int index = EdgeList->GetCount() - 1; index >= 0; index--) for (auto edge : EdgeList)
{ edge->port_draw();
EdgeList->Get(index)->port_draw();
}
} }
int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction) int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)

View file

@ -8,7 +8,7 @@ class TBall;
class TCollisionComponent : public TPinballComponent class TCollisionComponent : public TPinballComponent
{ {
public: public:
objlist_class<TEdgeSegment>* EdgeList; std::vector<TEdgeSegment*> EdgeList;
float Elasticity; float Elasticity;
float Smoothness; float Smoothness;
float Boost; float Boost;

View file

@ -4,13 +4,11 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false)
{ {
List = new objlist_class<TPinballComponent>(4, 4);
Timer = 0; Timer = 0;
if (groupIndex > 0) if (groupIndex > 0)
{ {
@ -21,7 +19,7 @@ TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinbal
{ {
auto component = table->find_component(*shortArrPtr); auto component = table->find_component(*shortArrPtr);
if (component) if (component)
List->Add(component); List.push_back(component);
} }
} }
} }
@ -33,7 +31,6 @@ TComponentGroup::~TComponentGroup()
timer::kill(Timer); timer::kill(Timer);
Timer = 0; Timer = 0;
} }
delete List;
} }
int TComponentGroup::Message(int code, float value) 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) 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; return 0;

View file

@ -11,6 +11,6 @@ public:
int Message(int code, float value) override; int Message(int code, float value) override;
static void NotifyTimerExpired(int timerId, void* caller); static void NotifyTimerExpired(int timerId, void* caller);
objlist_class<TPinballComponent>* List; std::vector<TPinballComponent*> List;
int Timer; int Timer;
}; };

View file

@ -1,16 +0,0 @@
#include "pch.h"
#include "TEdgeBox.h"
#include "objlist_class.h"
TEdgeBox::TEdgeBox()
{
EdgeList = new objlist_class<TEdgeSegment>(0, 4);
FieldList = new objlist_class<field_effect_type>(0, 1);
}
TEdgeBox::~TEdgeBox()
{
delete EdgeList;
delete FieldList;
}

View file

@ -1,6 +1,4 @@
#pragma once #pragma once
#include "objlist_class.h"
struct field_effect_type; struct field_effect_type;
class TEdgeSegment; class TEdgeSegment;
@ -8,10 +6,6 @@ class TEdgeSegment;
class TEdgeBox class TEdgeBox
{ {
public: public:
TEdgeBox(); std::vector<TEdgeSegment*> EdgeList{};
~TEdgeBox(); std::vector<field_effect_type*> FieldList{};
objlist_class<TEdgeSegment>* EdgeList;
objlist_class<field_effect_type>* FieldList;
}; };

View file

@ -3,7 +3,6 @@
#include "maths.h" #include "maths.h"
#include "objlist_class.h"
#include "TBall.h" #include "TBall.h"
#include "TEdgeBox.h" #include "TEdgeBox.h"
#include "TEdgeSegment.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) 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) 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, 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]; TEdgeBox* edgeBox = &BoxArray[x + y * MaxBoxX];
TEdgeSegment** edgePtr = &EdgeArray[edgeIndex]; 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 (!edge->ProcessedFlag && *edge->ActiveFlag && (edge->CollisionGroup & ray->FieldFlag))
{ {
if (!ball->already_hit(edge)) 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) * TEdgeBox* edgeBox = &BoxArray[box_x(ball->Position.X) + box_y(ball->Position.Y) *
MaxBoxX]; 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->Flag2Ptr && ball->FieldFlag & field->Mask)
{ {
if (field->CollisionComp->FieldEffect(ball, &vec)) if (field->CollisionComp->FieldEffect(ball, &vec))

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "TEdgeSegment.h" #include "TEdgeSegment.h"
#include "objlist_class.h"
#include "TCircle.h" #include "TCircle.h"
#include "TCollisionComponent.h" #include "TCollisionComponent.h"
#include "TLine.h" #include "TLine.h"
@ -41,7 +40,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
circle->place_in_grid(); circle->place_in_grid();
} }
collComp->EdgeList->Add(circle); collComp->EdgeList.push_back(circle);
break; break;
} }
case wall_type::Line: case wall_type::Line:
@ -58,7 +57,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
line->WallValue = reinterpret_cast<void*>(wallValue); line->WallValue = reinterpret_cast<void*>(wallValue);
line->Offset(offset); line->Offset(offset);
line->place_in_grid(); line->place_in_grid();
collComp->EdgeList->Add(line); collComp->EdgeList.push_back(line);
} }
break; break;
} }
@ -104,7 +103,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
{ {
circle->WallValue = reinterpret_cast<void*>(wallValue); circle->WallValue = reinterpret_cast<void*>(wallValue);
circle->place_in_grid(); 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<void*>(wallValue); line->WallValue = reinterpret_cast<void*>(wallValue);
line->Offset(offset); line->Offset(offset);
line->place_in_grid(); line->place_in_grid();
collComp->EdgeList->Add(line); collComp->EdgeList.push_back(line);
} }
prevCenter = center; prevCenter = center;

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "TBall.h" #include "TBall.h"
#include "timer.h" #include "timer.h"
@ -26,7 +25,7 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom
if (line) if (line)
{ {
line->place_in_grid(); line->place_in_grid();
EdgeList->Add(line); EdgeList.push_back(line);
} }
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start); line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start);
@ -34,7 +33,7 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom
if (line) if (line)
{ {
line->place_in_grid(); line->place_in_grid();
EdgeList->Add(line); EdgeList.push_back(line);
} }
SpeedDecrement = 0.64999998f; SpeedDecrement = 0.64999998f;
@ -61,8 +60,8 @@ int TFlagSpinner::Message(int code, float value)
Timer = 0; Timer = 0;
} }
BmpIndex = 0; BmpIndex = 0;
auto bmp = ListBitmap->Get(0); auto bmp = ListBitmap->at(0);
auto zMap = ListZMap->Get(0); auto zMap = ListZMap->at(0);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,
@ -108,7 +107,7 @@ void TFlagSpinner::NextFrame()
{ {
BmpIndex += SpinDirection; BmpIndex += SpinDirection;
int bmpIndex = BmpIndex; int bmpIndex = BmpIndex;
int bmpCount = ListBitmap->GetCount(); int bmpCount = ListBitmap->size();
if (bmpIndex >= bmpCount) if (bmpIndex >= bmpCount)
BmpIndex = 0; BmpIndex = 0;
else if (bmpIndex < 0) else if (bmpIndex < 0)
@ -123,8 +122,8 @@ void TFlagSpinner::NextFrame()
control::handler(62, this); control::handler(62, this);
} }
auto bmp = ListBitmap->Get(BmpIndex); auto bmp = ListBitmap->at(BmpIndex);
auto zMap = ListZMap->Get(BmpIndex); auto zMap = ListZMap->at(BmpIndex);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "render.h" #include "render.h"
#include "TFlipperEdge.h" #include "TFlipperEdge.h"
@ -52,8 +51,8 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t
FlipperEdge = flipperEdge; FlipperEdge = flipperEdge;
if (flipperEdge) if (flipperEdge)
{ {
BmpCoef1 = flipperEdge->BmpCoef1 / static_cast<float>(ListBitmap->GetCount() - 1); BmpCoef1 = flipperEdge->BmpCoef1 / static_cast<float>(ListBitmap->size() - 1);
BmpCoef2 = flipperEdge->BmpCoef2 / static_cast<float>(ListBitmap->GetCount() - 1); BmpCoef2 = flipperEdge->BmpCoef2 / static_cast<float>(ListBitmap->size() - 1);
} }
BmpIndex = 0; BmpIndex = 0;
InputTime = 0.0; InputTime = 0.0;
@ -142,7 +141,7 @@ void TFlipper::TimerExpired(int timerId, void* caller)
bool bmpIndexOutOfBounds = false; bool bmpIndexOutOfBounds = false;
auto bmpIndexAdvance = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime + 0.5f)); auto bmpIndexAdvance = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime + 0.5f));
int bmpCount = flip->ListBitmap->GetCount(); int bmpCount = flip->ListBitmap->size();
if (bmpIndexAdvance > bmpCount) if (bmpIndexAdvance > bmpCount)
bmpIndexAdvance = bmpCount; bmpIndexAdvance = bmpCount;
if (bmpIndexAdvance < 0) if (bmpIndexAdvance < 0)
@ -154,7 +153,7 @@ void TFlipper::TimerExpired(int timerId, void* caller)
if (flip->MessageField == 1) if (flip->MessageField == 1)
{ {
flip->BmpIndex += bmpIndexAdvance; flip->BmpIndex += bmpIndexAdvance;
int countSub1 = flip->ListBitmap->GetCount() - 1; int countSub1 = flip->ListBitmap->size() - 1;
if (flip->BmpIndex >= countSub1) if (flip->BmpIndex >= countSub1)
{ {
flip->BmpIndex = countSub1; flip->BmpIndex = countSub1;
@ -182,8 +181,8 @@ void TFlipper::TimerExpired(int timerId, void* caller)
timer = timer::set(flip->TimerTime, flip, TimerExpired); timer = timer::set(flip->TimerTime, flip, TimerExpired);
flip->Timer = timer; flip->Timer = timer;
auto bmp = flip->ListBitmap->Get(flip->BmpIndex); auto bmp = flip->ListBitmap->at(flip->BmpIndex);
auto zMap = flip->ListZMap->Get(flip->BmpIndex); auto zMap = flip->ListZMap->at(flip->BmpIndex);
render::sprite_set( render::sprite_set(
flip->RenderSprite, flip->RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) 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; SoundIndex4 = visual.SoundIndex4;
SoundIndex3 = visual.SoundIndex3; SoundIndex3 = visual.SoundIndex3;
ActiveFlag = 1; ActiveFlag = 1;
render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0));
control::handler(1024, this); control::handler(1024, this);
} }
@ -32,7 +31,7 @@ int TGate::Message(int code, float value)
else if (code == 54 || code == 1024) else if (code == 54 || code == 1024)
{ {
ActiveFlag = 1; ActiveFlag = 1;
render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0));
if (code == 54) if (code == 54)
loader::play_sound(SoundIndex4); loader::play_sound(SoundIndex4);
} }

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "TBall.h" #include "TBall.h"
#include "timer.h" #include "timer.h"
@ -37,7 +36,7 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
if (tCircle) if (tCircle)
{ {
tCircle->place_in_grid(); tCircle->place_in_grid();
EdgeList->Add(tCircle); EdgeList.push_back(tCircle);
} }
ZSetValue = loader::query_float_attribute(groupIndex, 0, 408)[2]; ZSetValue = loader::query_float_attribute(groupIndex, 0, 408)[2];

View file

@ -5,7 +5,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "maths.h" #include "maths.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -66,8 +65,8 @@ void TKickback::TimerExpired(int timerId, void* caller)
loader::play_sound(kick->HardHitSoundId); loader::play_sound(kick->HardHitSoundId);
if (kick->ListBitmap) if (kick->ListBitmap)
{ {
auto bmp = kick->ListBitmap->Get(1); auto bmp = kick->ListBitmap->at(1);
auto zMap = kick->ListZMap->Get(1); auto zMap = kick->ListZMap->at(1);
render::sprite_set( render::sprite_set(
kick->RenderSprite, kick->RenderSprite,
bmp, bmp,
@ -80,8 +79,8 @@ void TKickback::TimerExpired(int timerId, void* caller)
{ {
if (kick->ListBitmap) if (kick->ListBitmap)
{ {
auto bmp = kick->ListBitmap->Get(0); auto bmp = kick->ListBitmap->at(0);
auto zMap = kick->ListZMap->Get(0); auto zMap = kick->ListZMap->at(0);
render::sprite_set( render::sprite_set(
kick->RenderSprite, kick->RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "TBall.h" #include "TBall.h"
#include "TCircle.h" #include "TCircle.h"
#include "timer.h" #include "timer.h"
@ -40,7 +39,7 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis
if (tCircle) if (tCircle)
{ {
tCircle->place_in_grid(); tCircle->place_in_grid();
EdgeList->Add(tCircle); EdgeList.push_back(tCircle);
} }
Circle.RadiusSq = visual.FloatArr[2] * visual.FloatArr[2]; Circle.RadiusSq = visual.FloatArr[2] * visual.FloatArr[2];

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -143,14 +142,14 @@ int TLight::Message(int code, float value)
schedule_timeout(value); schedule_timeout(value);
break; break;
case 11: case 11:
BmpIndex2 = static_cast<int>(floor(value));
if (BmpIndex2 > ListBitmap->GetCount())
BmpIndex2 = ListBitmap->GetCount();
bmpIndex = 0; bmpIndex = 0;
BmpIndex2 = static_cast<int>(floor(value));
if (BmpIndex2 > static_cast<int>(ListBitmap->size()))
BmpIndex2 = ListBitmap->size();
if (BmpIndex2 < 0) if (BmpIndex2 < 0)
BmpIndex2 = 0; BmpIndex2 = 0;
Flasher.BmpArr[0] = nullptr; Flasher.BmpArr[0] = nullptr;
Flasher.BmpArr[1] = ListBitmap->Get(BmpIndex2); Flasher.BmpArr[1] = ListBitmap->at(BmpIndex2);
if (FlasherActive == 0) if (FlasherActive == 0)
{ {
if (!FlasherFlag1) if (!FlasherFlag1)
@ -169,8 +168,8 @@ int TLight::Message(int code, float value)
break; break;
case 12: case 12:
bmpIndex = BmpIndex2 + 1; bmpIndex = BmpIndex2 + 1;
if (bmpIndex > ListBitmap->GetCount()) if (bmpIndex > static_cast<int>(ListBitmap->size()))
bmpIndex = ListBitmap->GetCount(); bmpIndex = ListBitmap->size();
Message(11, static_cast<float>(bmpIndex)); Message(11, static_cast<float>(bmpIndex));
break; break;
case 13: case 13:
@ -257,7 +256,7 @@ void TLight::Reset()
Flasher.Sprite = RenderSprite; Flasher.Sprite = RenderSprite;
Flasher.BmpArr[0] = nullptr; Flasher.BmpArr[0] = nullptr;
if (ListBitmap) if (ListBitmap)
Flasher.BmpArr[1] = ListBitmap->Get(0); Flasher.BmpArr[1] = ListBitmap->at(0);
Flasher.Unknown4 = 0; Flasher.Unknown4 = 0;
Flasher.Unknown3 = 0; Flasher.Unknown3 = 0;
MessageField = 0; MessageField = 0;

View file

@ -5,7 +5,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "memory.h" #include "memory.h"
#include "objlist_class.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -18,7 +17,7 @@ TLightBargraph::TLightBargraph(TPinballTable* table, int groupIndex) : TLightGro
float* floatArr = loader::query_float_attribute(groupIndex, 0, 904); float* floatArr = loader::query_float_attribute(groupIndex, 0, 904);
if (floatArr) if (floatArr)
{ {
int count = 2 * List->GetCount(); int count = 2 * List.size();
TimerTimeArray = memory::allocate<float>(count); TimerTimeArray = memory::allocate<float>(count);
if (TimerTimeArray) if (TimerTimeArray)
{ {
@ -49,7 +48,7 @@ int TLightBargraph::Message(int code, float value)
TimerBargraph = 0; TimerBargraph = 0;
} }
auto timeIndex = static_cast<int>(floor(value)); auto timeIndex = static_cast<int>(floor(value));
auto maxCount = 2 * List->GetCount(); auto maxCount = static_cast<int>(List.size()) * 2;
if (timeIndex >= maxCount) if (timeIndex >= maxCount)
timeIndex = maxCount - 1; timeIndex = maxCount - 1;
if (timeIndex >= 0) if (timeIndex >= 0)

View file

@ -4,17 +4,15 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "timer.h" #include "timer.h"
#include "TLight.h" #include "TLight.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false)
{ {
List = new objlist_class<TLight>(4, 4);
Timer = 0; Timer = 0;
NotifyTimer = 0; NotifyTimer = 0;
Reset(); TLightGroup::Reset();
if (groupIndex > 0) if (groupIndex > 0)
{ {
int count; int count;
@ -24,7 +22,7 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone
{ {
auto comp = dynamic_cast<TLight*>(table->find_component(*groupIndArr)); auto comp = dynamic_cast<TLight*>(table->find_component(*groupIndArr));
if (comp) if (comp)
List->Add(comp); List.push_back(comp);
++index; ++index;
} }
} }
@ -32,11 +30,11 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone
TLightGroup::~TLightGroup() TLightGroup::~TLightGroup()
{ {
delete List;
} }
int TLightGroup::Message(int code, float value) int TLightGroup::Message(int code, float value)
{ {
auto count = static_cast<int>(List.size());
switch (code) switch (code)
{ {
case 1011: case 1011:
@ -71,8 +69,7 @@ int TLightGroup::Message(int code, float value)
break; break;
case 24: case 24:
{ {
auto count = List->GetCount(); auto lastLight = List.at(count - 1);
auto lastLight = List->Get(count - 1);
if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1)
break; break;
if (MessageField2) if (MessageField2)
@ -85,12 +82,12 @@ int TLightGroup::Message(int code, float value)
auto bmpIndex1 = lastLight->BmpIndex1; auto bmpIndex1 = lastLight->BmpIndex1;
for (auto index = count - 1; index > 0; --index) for (auto index = count - 1; index > 0; --index)
{ {
auto lightCur = List->Get(index); auto lightCur = List.at(index);
auto lightPrev = List->Get(index - 1); auto lightPrev = List.at(index - 1);
lightCur->Message(lightPrev->BmpIndex1 != 0, 0.0); lightCur->Message(lightPrev->BmpIndex1 != 0, 0.0);
lightCur->MessageField = lightPrev->MessageField; lightCur->MessageField = lightPrev->MessageField;
} }
auto firstLight = List->Get(0); auto firstLight = List.at(0);
firstLight->Message(bmpIndex1 != 0, 0.0); firstLight->Message(bmpIndex1 != 0, 0.0);
firstLight->MessageField = lightMessageField; firstLight->MessageField = lightMessageField;
reschedule_animation(value); reschedule_animation(value);
@ -98,23 +95,22 @@ int TLightGroup::Message(int code, float value)
} }
case 25: case 25:
{ {
auto count = List->GetCount(); auto lastLight = List.at(count - 1);
auto lastLight = List->Get(count - 1);
if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1) if (lastLight->FlasherActive || lastLight->FlasherFlag2 || lastLight->FlasherFlag1)
break; break;
if (MessageField2) if (MessageField2)
{ {
TLightGroup::Message(34, 0.0); TLightGroup::Message(34, 0.0);
} }
auto firstLight = List->Get(0); auto firstLight = List.at(0);
AnimationFlag = 1; AnimationFlag = 1;
MessageField2 = code; MessageField2 = code;
auto lightMessageField = firstLight->MessageField; auto lightMessageField = firstLight->MessageField;
auto bmpIndex1 = firstLight->BmpIndex1; auto bmpIndex1 = firstLight->BmpIndex1;
for (auto index = 0; index < count - 1; index++) for (auto index = 0; index < count - 1; index++)
{ {
auto lightCur = List->Get(index); auto lightCur = List.at(index);
auto lightNext = List->Get(index + 1); auto lightNext = List.at(index + 1);
lightCur->Message(lightNext->BmpIndex1 != 0, 0.0); lightCur->Message(lightNext->BmpIndex1 != 0, 0.0);
lightCur->MessageField = lightNext->MessageField; lightCur->MessageField = lightNext->MessageField;
} }
@ -129,16 +125,15 @@ int TLightGroup::Message(int code, float value)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto count = List->GetCount(); auto lastLight = List.at(count - 1);
auto lastLight = List->Get(count - 1);
auto flasherFlag2 = lastLight->FlasherFlag2; auto flasherFlag2 = lastLight->FlasherFlag2;
for (auto i = count - 1; i > 0; --i) for (auto i = count - 1; i > 0; --i)
{ {
auto lightCur = List->Get(i); auto lightCur = List.at(i);
auto lightPrev = List->Get(i - 1); auto lightPrev = List.at(i - 1);
lightCur->Message((lightPrev->FlasherFlag2 != 0) + 8, 0.0); lightCur->Message((lightPrev->FlasherFlag2 != 0) + 8, 0.0);
} }
auto firstLight = List->Get(0); auto firstLight = List.at(0);
firstLight->Message((flasherFlag2 != 0) + 8, 0); firstLight->Message((flasherFlag2 != 0) + 8, 0);
reschedule_animation(value); reschedule_animation(value);
break; break;
@ -149,16 +144,15 @@ int TLightGroup::Message(int code, float value)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto count = List->GetCount(); auto firstLight = List.at(0);
auto firstLight = List->Get(0);
auto flasherFlag2 = firstLight->FlasherFlag2; auto flasherFlag2 = firstLight->FlasherFlag2;
for (auto i = 0; i < count - 1; i++) for (auto i = 0; i < count - 1; i++)
{ {
auto lightCur = List->Get(i); auto lightCur = List.at(i);
auto lightNext = List->Get(i + 1); auto lightNext = List.at(i + 1);
lightCur->Message((lightNext->FlasherFlag2 != 0) + 8, 0.0); 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); lastLight->Message((flasherFlag2 != 0) + 8, 0);
reschedule_animation(value); reschedule_animation(value);
break; break;
@ -169,12 +163,10 @@ int TLightGroup::Message(int code, float value)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto count = List->GetCount(); for (auto light : List)
for (auto i = 0; i < count - 1; i++)
{ {
if (rand() % 100 > 70) if (rand() % 100 > 70)
{ {
auto light = List->Get(i);
auto randVal = RandFloat() * value * 3.0f + 0.1f; auto randVal = RandFloat() * value * 3.0f + 0.1f;
light->Message(9, randVal); light->Message(9, randVal);
} }
@ -188,10 +180,8 @@ int TLightGroup::Message(int code, float value)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto count = List->GetCount(); for (auto light : List)
for (auto i = 0; i < count - 1; i++)
{ {
auto light = List->Get(i);
auto randVal = static_cast<float>(rand() % 100 > 70); auto randVal = static_cast<float>(rand() % 100 > 70);
light->Message(18, randVal); light->Message(18, randVal);
} }
@ -201,22 +191,18 @@ int TLightGroup::Message(int code, float value)
case 30: case 30:
{ {
auto noBmpInd1Count = 0; auto noBmpInd1Count = 0;
auto countSub1 = List->GetCount() - 1; for (auto light : List)
if (countSub1 < 0)
break;
for (auto i = countSub1; i >= 0; i--)
{ {
if (!List->Get(i)->BmpIndex1) if (!light->BmpIndex1)
++noBmpInd1Count; ++noBmpInd1Count;
} }
if (!noBmpInd1Count) if (!noBmpInd1Count)
break; break;
auto randModCount = rand() % noBmpInd1Count; 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) if (!light->BmpIndex1 && randModCount-- == 0)
{ {
light->Message(1, 0.0); light->Message(1, 0.0);
@ -231,22 +217,18 @@ int TLightGroup::Message(int code, float value)
case 31: case 31:
{ {
auto bmpInd1Count = 0; auto bmpInd1Count = 0;
auto countSub1 = List->GetCount() - 1; for (auto light : List)
if (countSub1 < 0)
break;
for (auto i = countSub1; i >= 0; i--)
{ {
if (List->Get(i)->BmpIndex1) if (light->BmpIndex1)
++bmpInd1Count; ++bmpInd1Count;
} }
if (!bmpInd1Count) if (!bmpInd1Count)
break; break;
auto randModCount = rand() % bmpInd1Count; 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) if (light->BmpIndex1 && randModCount-- == 0)
{ {
light->Message(0, 0.0); light->Message(0, 0.0);
@ -263,7 +245,7 @@ int TLightGroup::Message(int code, float value)
auto index = next_light_up(); auto index = next_light_up();
if (index < 0) if (index < 0)
break; break;
List->Get(index)->Message(1, 0.0); List.at(index)->Message(1, 0.0);
if (MessageField2) if (MessageField2)
start_animation(); start_animation();
return 1; return 1;
@ -273,7 +255,7 @@ int TLightGroup::Message(int code, float value)
auto index = next_light_down(); auto index = next_light_down();
if (index < 0) if (index < 0)
break; break;
List->Get(index)->Message(0, 0.0); List.at(index)->Message(0, 0.0);
if (MessageField2) if (MessageField2)
start_animation(); start_animation();
return 1; return 1;
@ -292,10 +274,10 @@ int TLightGroup::Message(int code, float value)
case 35: case 35:
{ {
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= List->GetCount() || index < 0) if (index >= count || index < 0)
break; break;
auto light = List->Get(index); auto light = List.at(index);
light->Message(1, 0.0); light->Message(1, 0.0);
if (MessageField2) if (MessageField2)
start_animation(); start_animation();
@ -304,10 +286,10 @@ int TLightGroup::Message(int code, float value)
case 36: case 36:
{ {
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= List->GetCount() || index < 0) if (index >= count || index < 0)
break; break;
auto light = List->Get(index); auto light = List.at(index);
light->Message(0, 0.0); light->Message(0, 0.0);
if (MessageField2) if (MessageField2)
start_animation(); start_animation();
@ -316,16 +298,15 @@ int TLightGroup::Message(int code, float value)
case 37: case 37:
{ {
auto bmp1Count = 0; auto bmp1Count = 0;
auto countSub1 = List->GetCount() - 1; for (auto light : List)
for (auto i = countSub1; i >= 0; i--)
{ {
if (List->Get(i)->BmpIndex1) if (light->BmpIndex1)
++bmp1Count; ++bmp1Count;
} }
return bmp1Count; return bmp1Count;
} }
case 38: case 38:
return List->GetCount(); return count;
case 39: case 39:
return MessageField2; return MessageField2;
case 40: case 40:
@ -337,7 +318,7 @@ int TLightGroup::Message(int code, float value)
break; break;
if (MessageField2 || AnimationFlag) if (MessageField2 || AnimationFlag)
TLightGroup::Message(34, 0.0); TLightGroup::Message(34, 0.0);
List->Get(index)->Message(15, value); List.at(index)->Message(15, value);
return 1; return 1;
} }
case 42: case 42:
@ -347,7 +328,7 @@ int TLightGroup::Message(int code, float value)
break; break;
if (MessageField2 || AnimationFlag) if (MessageField2 || AnimationFlag)
TLightGroup::Message(34, 0.0); TLightGroup::Message(34, 0.0);
List->Get(index)->Message(16, value); List.at(index)->Message(16, value);
return 1; return 1;
} }
case 43: case 43:
@ -359,10 +340,9 @@ int TLightGroup::Message(int code, float value)
break; break;
case 44: case 44:
{ {
auto countSub1 = List->GetCount() - 1; for (auto it = List.rbegin(); it != List.rend(); ++it)
for (auto index = countSub1; index >= 0; index--)
{ {
auto light = List->Get(index); auto light = *it;
if (light->BmpIndex1) if (light->BmpIndex1)
{ {
light->Message(0, 0.0); light->Message(0, 0.0);
@ -378,26 +358,21 @@ int TLightGroup::Message(int code, float value)
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= 0) if (index >= 0)
{ {
auto count = List->GetCount();
if (index <= count) if (index <= count)
{ {
auto countSub1 = count - 1; auto countSub1 = count - 1;
if (countSub1 > index) if (countSub1 > index)
{ {
countSub1 = index;
for (auto i = countSub1, k = countSub1 - index; k != 0; i--, k--) 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); light->Message(20, 0.0);
} }
} }
if (countSub1 >= 0)
for (auto it = List.rbegin(); it != List.rend(); ++it)
{ {
for (auto i = countSub1; i != 0; i--) (*it)->Message(19, 0.0);
{
auto light = List->Get(i);
light->Message(19, 0.0);
}
} }
} }
} }
@ -408,14 +383,14 @@ int TLightGroup::Message(int code, float value)
auto index = next_light_down(); auto index = next_light_down();
if (index >= 0) if (index >= 0)
{ {
List->Get(index)->Message(4, 0.0); List.at(index)->Message(4, 0.0);
} }
break; break;
} }
default: 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; break;
} }
@ -453,9 +428,9 @@ void TLightGroup::reschedule_animation(float time)
void TLightGroup::start_animation() 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) if (light->BmpIndex1)
light->Message(9, 0.0); light->Message(9, 0.0);
else else
@ -465,19 +440,19 @@ void TLightGroup::start_animation()
int TLightGroup::next_light_up() 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) if (!List.at(index)->BmpIndex1)
return index; return static_cast<int>(index);
} }
return -1; return -1;
} }
int TLightGroup::next_light_down() int TLightGroup::next_light_down()
{ {
for (int index = List->GetCount() - 1; index >= 0; --index) for (auto index = static_cast<int>(List.size()) - 1; index >= 0; --index)
{ {
if (!List->Get(index)->BmpIndex1) if (!List.at(index)->BmpIndex1)
return index; return index;
} }
return -1; return -1;

View file

@ -29,7 +29,7 @@ public:
static void TimerExpired(int timerId, void* caller); static void TimerExpired(int timerId, void* caller);
static void NotifyTimerExpired(int timerId, void* caller); static void NotifyTimerExpired(int timerId, void* caller);
objlist_class<TLight>* List; std::vector<TLight*> List;
float Timer1Time; float Timer1Time;
float Timer1TimeDefault; float Timer1TimeDefault;
int MessageField2; int MessageField2;

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "TBall.h" #include "TBall.h"
#include "timer.h" #include "timer.h"
@ -58,7 +57,7 @@ void TLightRollover::Collision(TBall* ball, vector_type* nextPosition, vector_ty
control::handler(63, this); control::handler(63, this);
RolloverFlag = RolloverFlag == 0; RolloverFlag = RolloverFlag == 0;
if (ListBitmap) if (ListBitmap)
render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0));
} }
} }
} }

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "TBall.h" #include "TBall.h"
#include "TLine.h" #include "TLine.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -27,7 +26,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab
{ {
line->Offset(table->CollisionCompOffset); line->Offset(table->CollisionCompOffset);
line->place_in_grid(); line->place_in_grid();
EdgeList->Add(line); EdgeList.push_back(line);
} }
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2); 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->Offset(-table->CollisionCompOffset * 0.8f);
Line->place_in_grid(); Line->place_in_grid();
EdgeList->Add(Line); EdgeList.push_back(Line);
} }
} }
} }

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "TPinballComponent.h" #include "TPinballComponent.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -19,7 +18,7 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
GroupName = nullptr; GroupName = nullptr;
Control = nullptr; Control = nullptr;
if (table) if (table)
table->ComponentList->Add(this); table->ComponentList.push_back(this);
if (groupIndex >= 0) if (groupIndex >= 0)
GroupName = loader::query_name(groupIndex); GroupName = loader::query_name(groupIndex);
if (loadVisuals && groupIndex >= 0) if (loadVisuals && groupIndex >= 0)
@ -31,32 +30,31 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
if (visual.Bitmap) if (visual.Bitmap)
{ {
if (!ListBitmap) if (!ListBitmap)
ListBitmap = new objlist_class<gdrv_bitmap8>(visualCount, 4); ListBitmap = new std::vector<gdrv_bitmap8*>();
if (ListBitmap) if (ListBitmap)
ListBitmap->Add(visual.Bitmap); ListBitmap->push_back(visual.Bitmap);
} }
if (visual.ZMap) if (visual.ZMap)
{ {
if (!ListZMap) if (!ListZMap)
ListZMap = new objlist_class<zmap_header_type>(visualCount, 4); ListZMap = new std::vector<zmap_header_type*>();
if (ListZMap) if (ListZMap)
ListZMap->Add(visual.ZMap); ListZMap->push_back(visual.ZMap);
} }
} }
zmap_header_type* zMap = nullptr;
if (ListZMap) auto zMap = ListZMap ? ListZMap->at(0) : nullptr;
zMap = ListZMap->Get(0);
if (ListBitmap) if (ListBitmap)
{ {
rectangle_type bmp1Rect{}, tmpRect{}; rectangle_type bmp1Rect{}, tmpRect{};
auto rootBmp = ListBitmap->Get(0); auto rootBmp = ListBitmap->at(0);
bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset; bmp1Rect.XPosition = rootBmp->XPosition - table->XOffset;
bmp1Rect.YPosition = rootBmp->YPosition - table->YOffset; bmp1Rect.YPosition = rootBmp->YPosition - table->YOffset;
bmp1Rect.Width = rootBmp->Width; bmp1Rect.Width = rootBmp->Width;
bmp1Rect.Height = rootBmp->Height; 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.XPosition = bmp->XPosition - table->XOffset;
tmpRect.YPosition = bmp->YPosition - table->YOffset; tmpRect.YPosition = bmp->YPosition - table->YOffset;
tmpRect.Width = bmp->Width; tmpRect.Width = bmp->Width;
@ -79,9 +77,14 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
TPinballComponent::~TPinballComponent() TPinballComponent::~TPinballComponent()
{ {
TPinballTable* table = PinballTable; if (PinballTable)
if (table) {
table->ComponentList->Delete(this); // 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 ListBitmap;
delete ListZMap; delete ListZMap;

View file

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "objlist_class.h"
struct zmap_header_type; struct zmap_header_type;
struct gdrv_bitmap8; struct gdrv_bitmap8;
@ -32,11 +31,10 @@ public:
char ActiveFlag; char ActiveFlag;
int MessageField; int MessageField;
char* GroupName; char* GroupName;
int Unknown4;
component_control* Control; component_control* Control;
int GroupIndex; int GroupIndex;
render_sprite_type_struct* RenderSprite; render_sprite_type_struct* RenderSprite;
TPinballTable* PinballTable; TPinballTable* PinballTable;
objlist_class<gdrv_bitmap8>* ListBitmap; std::vector<gdrv_bitmap8*>* ListBitmap;
objlist_class<zmap_header_type>* ListZMap; std::vector<zmap_header_type*>* ListZMap;
}; };

View file

@ -5,11 +5,9 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "memory.h" #include "memory.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "pinball.h" #include "pinball.h"
#include "render.h" #include "render.h"
#include "Sound.h"
#include "TBall.h" #include "TBall.h"
#include "TBlocker.h" #include "TBlocker.h"
#include "TBumper.h" #include "TBumper.h"
@ -48,8 +46,6 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
{ {
int shortArrLength; int shortArrLength;
ComponentList = new objlist_class<TPinballComponent>(32, 16);
BallList = new objlist_class<TBall>(3, 1);
CurScoreStruct = nullptr; CurScoreStruct = nullptr;
ScoreBallcount = nullptr; ScoreBallcount = nullptr;
ScorePlayerNumber1 = nullptr; ScorePlayerNumber1 = nullptr;
@ -64,7 +60,7 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
PlayerCount = 0; PlayerCount = 0;
auto ballObj = new TBall(this); auto ballObj = new TBall(this);
BallList->Add(ballObj); BallList.push_back(ballObj);
if (ballObj) if (ballObj)
ballObj->ActiveFlag = 0; ballObj->ActiveFlag = 0;
new TTableLayer(this); new TTableLayer(this);
@ -103,7 +99,7 @@ TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false)
Plunger = new TPlunger(this, groupIndex); Plunger = new TPlunger(this, groupIndex);
break; break;
case 1002: case 1002:
LightGroup->List->Add(new TLight(this, groupIndex)); LightGroup->List.push_back(new TLight(this, groupIndex));
break; break;
case 1003: case 1003:
FlipperL = new TFlipper(this, groupIndex); FlipperL = new TFlipper(this, groupIndex);
@ -213,30 +209,25 @@ TPinballTable::~TPinballTable()
ScoreBallcount = nullptr; ScoreBallcount = nullptr;
} }
delete LightGroup; 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(); control::ClearLinks();
} }
TPinballComponent* TPinballTable::find_component(LPCSTR componentName) TPinballComponent* TPinballTable::find_component(LPCSTR componentName)
{ {
int objCount = ComponentList->GetCount(); for (auto component : ComponentList)
if (objCount > 0)
{ {
for (int index = 0; index < objCount; ++index) const char* groupName = component->GroupName;
if (groupName && !strcmp(groupName, componentName))
{ {
TPinballComponent* obj = ComponentList->Get(index); return component;
const char* groupName = obj->GroupName;
if (groupName && !strcmp(groupName, componentName))
{
return obj;
}
} }
} }
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName, nullptr); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find:", componentName, nullptr);
return nullptr; return nullptr;
} }
@ -244,16 +235,12 @@ TPinballComponent* TPinballTable::find_component(LPCSTR componentName)
TPinballComponent* TPinballTable::find_component(int groupIndex) TPinballComponent* TPinballTable::find_component(int groupIndex)
{ {
char Buffer[40]{}; char Buffer[40]{};
int objCount = ComponentList->GetCount(); for (auto component : ComponentList)
if (objCount > 0)
{ {
for (int index = 0; index < objCount; ++index) if (component->GroupIndex == groupIndex)
{ return component;
TPinballComponent* obj = ComponentList->Get(index);
if (obj->GroupIndex == groupIndex)
return obj;
}
} }
snprintf(Buffer, sizeof Buffer, "%d", groupIndex); snprintf(Buffer, sizeof Buffer, "%d", groupIndex);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer, nullptr); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Table cant find (lh):", Buffer, nullptr);
return nullptr; return nullptr;
@ -308,9 +295,9 @@ void TPinballTable::tilt(float time)
loader::play_sound(SoundIndex3); loader::play_sound(SoundIndex3);
TiltTimeoutTimer = timer::set(30.0, this, tilt_timeout); 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); LightGroup->Message(8, 0);
TiltLockFlag = 1; TiltLockFlag = 1;
@ -321,9 +308,9 @@ void TPinballTable::tilt(float time)
void TPinballTable::port_draw() 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 1008:
case 1009: case 1009:
case 1010: 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; break;
case 1012: case 1012:
@ -407,7 +394,7 @@ int TPinballTable::Message(int code, float value)
{ {
CheatsUsed = 0; CheatsUsed = 0;
Message(1024, 0.0); Message(1024, 0.0);
auto ball = BallList->Get(0); auto ball = BallList[0];
ball->Position.Y = 0.0; ball->Position.Y = 0.0;
ball->Position.X = 0.0; ball->Position.X = 0.0;
ball->Position.Z = -0.8f; ball->Position.Z = -0.8f;
@ -509,9 +496,9 @@ int TPinballTable::Message(int code, float value)
score::set(ScorePlayerNumber1, nextPlayer + 1); score::set(ScorePlayerNumber1, nextPlayer + 1);
score::update(ScorePlayerNumber1); score::update(ScorePlayerNumber1);
for (int i = 0; i < ComponentList->GetCount(); i++) for (auto component : ComponentList)
{ {
ComponentList->Get(i)->Message(1020, static_cast<float>(nextPlayer)); component->Message(1020, static_cast<float>(nextPlayer));
} }
char* textboxText = nullptr; char* textboxText = nullptr;
@ -560,9 +547,9 @@ int TPinballTable::Message(int code, float value)
EndGameTimeoutTimer = timer::set(3.0, this, EndGame_timeout); EndGameTimeoutTimer = timer::set(3.0, this, EndGame_timeout);
break; break;
case 1024: 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) if (ReplayTimer)
timer::kill(ReplayTimer); timer::kill(ReplayTimer);
@ -604,9 +591,9 @@ void TPinballTable::EndGame_timeout(int timerId, void* caller)
table->EndGameTimeoutTimer = 0; table->EndGameTimeoutTimer = 0;
pb::end_game(); 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) if (table->Demo)
table->Demo->Message(1022, 0.0); table->Demo->Message(1022, 0.0);
@ -636,9 +623,9 @@ void TPinballTable::tilt_timeout(int timerId, void* caller)
table->TiltTimeoutTimer = 0; table->TiltTimeoutTimer = 0;
if (table->TiltLockFlag) 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);
} }
} }
} }

View file

@ -65,8 +65,8 @@ public:
int YOffset; int YOffset;
int Width; int Width;
int Height; int Height;
objlist_class<TPinballComponent>* ComponentList; std::vector<TPinballComponent*> ComponentList;
objlist_class<TBall>* BallList; std::vector<TBall*> BallList;
TLightGroup* LightGroup; TLightGroup* LightGroup;
float GravityDirVectMult; float GravityDirVectMult;
float GravityAngleX; float GravityAngleX;

View file

@ -5,7 +5,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "maths.h" #include "maths.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "render.h" #include "render.h"
#include "TBall.h" #include "TBall.h"
@ -27,7 +26,7 @@ TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(t
MaxPullback = 100; MaxPullback = 100;
Elasticity = 0.5f; Elasticity = 0.5f;
Smoothness = 0.5f; Smoothness = 0.5f;
PullbackIncrement = static_cast<int>(100.0 / (ListBitmap->GetCount() * 8.0)); PullbackIncrement = static_cast<int>(100.0 / (ListBitmap->size() * 8.0));
Unknown4F = 0.025f; Unknown4F = 0.025f;
float* floatArr = loader::query_float_attribute(groupIndex, 0, 601); float* floatArr = loader::query_float_attribute(groupIndex, 0, 601);
table->PlungerPositionX = floatArr[0]; table->PlungerPositionX = floatArr[0];
@ -65,8 +64,8 @@ int TPlunger::Message(int code, float value)
PullbackTimer_ = 0; PullbackTimer_ = 0;
if (code == 1005) if (code == 1005)
loader::play_sound(SoundIndexP2); loader::play_sound(SoundIndexP2);
auto bmp = ListBitmap->Get(0); auto bmp = ListBitmap->at(0);
auto zMap = ListZMap->Get(0); auto zMap = ListZMap->at(0);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,
@ -79,7 +78,7 @@ int TPlunger::Message(int code, float value)
} }
case 1015: case 1015:
{ {
auto ball = PinballTable->BallList->Get(0); auto ball = PinballTable->BallList.at(0);
ball->Message(1024, 0.0); ball->Message(1024, 0.0);
ball->Position.X = PinballTable->PlungerPositionX; ball->Position.X = PinballTable->PlungerPositionX;
ball->Position.Y = PinballTable->PlungerPositionY; ball->Position.Y = PinballTable->PlungerPositionY;
@ -112,8 +111,8 @@ int TPlunger::Message(int code, float value)
PullbackTimer_ = 0; PullbackTimer_ = 0;
if (code == 1005) if (code == 1005)
loader::play_sound(SoundIndexP2); loader::play_sound(SoundIndexP2);
auto bmp = ListBitmap->Get(0); auto bmp = ListBitmap->at(0);
auto zMap = ListZMap->Get(0); auto zMap = ListZMap->at(0);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,
@ -151,10 +150,10 @@ void TPlunger::PullbackTimer(int timerId, void* caller)
plunger->Boost = static_cast<float>(plunger->MaxPullback); plunger->Boost = static_cast<float>(plunger->MaxPullback);
} }
int index = static_cast<int>(floor( int index = static_cast<int>(floor(
static_cast<float>(plunger->ListBitmap->GetCount() - 1) * static_cast<float>(plunger->ListBitmap->size() - 1) *
(plunger->Boost / static_cast<float>(plunger->MaxPullback)))); (plunger->Boost / static_cast<float>(plunger->MaxPullback))));
auto bmp = plunger->ListBitmap->Get(index); auto bmp = plunger->ListBitmap->at(index);
auto zMap = plunger->ListZMap->Get(index); auto zMap = plunger->ListZMap->at(index);
render::sprite_set( render::sprite_set(
plunger->RenderSprite, plunger->RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -91,7 +90,7 @@ void TPopupTarget::TimerExpired(int timerId, void* caller)
auto target = static_cast<TPopupTarget*>(caller); auto target = static_cast<TPopupTarget*>(caller);
target->Timer = 0; target->Timer = 0;
target->ActiveFlag = 1; 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 (timerId)
{ {
if (target->SoftHitSoundId) if (target->SoftHitSoundId)

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "TBall.h" #include "TBall.h"
#include "TEdgeSegment.h" #include "TEdgeSegment.h"
#include "TLine.h" #include "TLine.h"
@ -35,7 +34,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
start.X = floatArr4[4]; start.X = floatArr4[4];
start.Y = floatArr4[5]; start.Y = floatArr4[5];
Line1 = new TLine(this, &ActiveFlag, 1 << static_cast<int>(floor(floatArr4[0])), &start, &end); Line1 = new TLine(this, &ActiveFlag, 1 << static_cast<int>(floor(floatArr4[0])), &start, &end);
EdgeList->Add(Line1); EdgeList.push_back(Line1);
if (Line1) if (Line1)
{ {
Line1->WallValue = nullptr; Line1->WallValue = nullptr;
@ -53,7 +52,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
&end2, &end2,
&start2); &start2);
Line2 = new TLine(this, &ActiveFlag, CollisionGroup, start2, end2); Line2 = new TLine(this, &ActiveFlag, CollisionGroup, start2, end2);
EdgeList->Add(Line2); EdgeList.push_back(Line2);
if (Line2) if (Line2)
{ {
Line2->WallValue = nullptr; Line2->WallValue = nullptr;
@ -71,7 +70,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
&end3, &end3,
&start3); &start3);
Line3 = new TLine(this, &ActiveFlag, CollisionGroup, start3, end3); Line3 = new TLine(this, &ActiveFlag, CollisionGroup, start3, end3);
EdgeList->Add(Line3); EdgeList.push_back(Line3);
if (Line3) if (Line3)
{ {
Line3->WallValue = nullptr; Line3->WallValue = nullptr;
@ -118,7 +117,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
if (collisionGroup) if (collisionGroup)
{ {
auto line = new TLine(this, &ActiveFlag, collisionGroup, point1, point2); auto line = new TLine(this, &ActiveFlag, collisionGroup, point1, point2);
EdgeList->Add(line); EdgeList.push_back(line);
if (line) if (line)
{ {
line->WallValue = plane; line->WallValue = plane;

View file

@ -5,7 +5,6 @@
#include "control.h" #include "control.h"
#include "gdrv.h" #include "gdrv.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "TBall.h" #include "TBall.h"
#include "TEdgeSegment.h" #include "TEdgeSegment.h"
@ -22,7 +21,7 @@ TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent
{ {
RolloverFlag = 0; RolloverFlag = 0;
if (ListBitmap) if (ListBitmap)
render::sprite_set_bitmap(RenderSprite, ListBitmap->Get(0)); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0));
build_walls(groupIndex); build_walls(groupIndex);
} }
@ -34,7 +33,7 @@ int TRollover::Message(int code, float value)
this->ActiveFlag = 1; this->ActiveFlag = 1;
this->RolloverFlag = 0; this->RolloverFlag = 0;
if (this->ListBitmap) 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; return 0;
} }
@ -63,7 +62,7 @@ void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* d
if (ListBitmap) if (ListBitmap)
{ {
if (!RolloverFlag) if (!RolloverFlag)
bmp = ListBitmap->Get(0); bmp = ListBitmap->at(0);
render::sprite_set_bitmap(RenderSprite, bmp); render::sprite_set_bitmap(RenderSprite, bmp);
} }
} }

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "TPinballTable.h" #include "TPinballTable.h"
#include "TBall.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) void TSink::TimerExpired(int timerId, void* caller)
{ {
auto sink = static_cast<TSink*>(caller); auto sink = static_cast<TSink*>(caller);
auto ball = sink->PinballTable->BallList->Get(0); auto ball = sink->PinballTable->BallList.at(0);
ball->CollisionComp = nullptr; ball->CollisionComp = nullptr;
ball->ActiveFlag = 1; ball->ActiveFlag = 1;
ball->Position.X = sink->BallPosition.X; ball->Position.X = sink->BallPosition.X;

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
@ -41,8 +40,8 @@ int TSoloTarget::Message(int code, float value)
if (ListBitmap) if (ListBitmap)
{ {
auto index = 1 - ActiveFlag; auto index = 1 - ActiveFlag;
auto bmp = ListBitmap->Get(index); auto bmp = ListBitmap->at(index);
auto zMap = ListZMap->Get(index); auto zMap = ListZMap->at(index);
render::sprite_set( render::sprite_set(
RenderSprite, RenderSprite,
bmp, bmp,

View file

@ -4,7 +4,6 @@
#include "fullscrn.h" #include "fullscrn.h"
#include "loader.h" #include "loader.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "proj.h" #include "proj.h"
#include "render.h" #include "render.h"
@ -91,7 +90,7 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f
if (line) if (line)
{ {
line->place_in_grid(); line->place_in_grid();
EdgeList->Add(line); EdgeList.push_back(line);
} }
visArrPtr += 2; visArrPtr += 2;

View file

@ -4,7 +4,6 @@
#include "control.h" #include "control.h"
#include "fullscrn.h" #include "fullscrn.h"
#include "loader.h" #include "loader.h"
#include "pb.h"
#include "render.h" #include "render.h"
#include "score.h" #include "score.h"
#include "timer.h" #include "timer.h"

View file

@ -3,7 +3,6 @@
#include "control.h" #include "control.h"
#include "objlist_class.h"
#include "render.h" #include "render.h"
#include "timer.h" #include "timer.h"
@ -12,7 +11,7 @@ TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
if (RenderSprite) if (RenderSprite)
render::sprite_set_bitmap(RenderSprite, nullptr); render::sprite_set_bitmap(RenderSprite, nullptr);
if (ListBitmap) if (ListBitmap)
BmpPtr = ListBitmap->Get(0); BmpPtr = ListBitmap->at(0);
Timer = 0; Timer = 0;
} }

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "control.h" #include "control.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "pinball.h" #include "pinball.h"
#include "TBlocker.h" #include "TBlocker.h"
@ -606,16 +605,14 @@ TPinballComponent* control::make_component_link(component_tag_base* tag)
if (tag->GetComponent()) if (tag->GetComponent())
return tag->GetComponent(); return tag->GetComponent();
auto compList = TableG->ComponentList; for (auto component: TableG->ComponentList)
for (int index = 0; index < compList->GetCount(); index++)
{ {
auto comp = compList->Get(index); if (component->GroupName)
if (comp->GroupName)
{ {
if (!strcmp(comp->GroupName, tag->Name)) if (!strcmp(component->GroupName, tag->Name))
{ {
tag->SetComponent(comp); tag->SetComponent(component);
return comp; return component;
} }
} }
} }

View file

@ -3,7 +3,6 @@
#include "GroupData.h" #include "GroupData.h"
#include "memory.h" #include "memory.h"
#include "options.h"
#include "partman.h" #include "partman.h"
#include "pb.h" #include "pb.h"
#include "score.h" #include "score.h"

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "high_score.h" #include "high_score.h"
#include "memory.h"
#include "options.h" #include "options.h"
#include "pinball.h" #include "pinball.h"
#include "score.h" #include "score.h"

View file

@ -87,7 +87,7 @@ void loader::loadfrom(DatFile* datFile)
loader_table = datFile; loader_table = datFile;
sound_record_table = loader_table; sound_record_table = loader_table;
for (auto groupIndex = 0; groupIndex < datFile->Groups.size(); ++groupIndex) for (auto groupIndex = 0; groupIndex < static_cast<int>(datFile->Groups.size()); ++groupIndex)
{ {
auto value = reinterpret_cast<int16_t*>(datFile->field(groupIndex, FieldTypes::ShortValue)); auto value = reinterpret_cast<int16_t*>(datFile->field(groupIndex, FieldTypes::ShortValue));
if (value && *value == 202) if (value && *value == 202)

View file

@ -4,7 +4,7 @@
#include "zdrv.h" #include "zdrv.h"
struct DatFile; class DatFile;
struct errorMsg struct errorMsg
{ {

View file

@ -6,7 +6,7 @@
#include "pinball.h" #include "pinball.h"
objlist_class<Mix_Music>* midi::LoadedTracks; std::vector<Mix_Music*> midi::LoadedTracks{};
Mix_Music *midi::track1, *midi::track2, *midi::track3, *midi::active_track, *midi::NextTrack; Mix_Music *midi::track1, *midi::track2, *midi::track3, *midi::active_track, *midi::NextTrack;
bool midi::SetNextTrackFlag; bool midi::SetNextTrackFlag;
@ -50,7 +50,6 @@ int midi::music_stop()
int midi::music_init() int midi::music_init()
{ {
active_track = nullptr; active_track = nullptr;
LoadedTracks = new objlist_class<Mix_Music>(0, 1);
if (pb::FullTiltMode) if (pb::FullTiltMode)
{ {
@ -76,14 +75,12 @@ void midi::music_shutdown()
if (active_track) if (active_track)
Mix_HaltMusic(); Mix_HaltMusic();
while (LoadedTracks->GetCount()) for (auto midi : LoadedTracks)
{ {
auto midi = LoadedTracks->Get(0);
Mix_FreeMusic(midi); Mix_FreeMusic(midi);
LoadedTracks->Delete(midi);
} }
active_track = nullptr; active_track = nullptr;
delete LoadedTracks; LoadedTracks.clear();
} }
Mix_Music* midi::load_track(std::string fileName) Mix_Music* midi::load_track(std::string fileName)
@ -132,7 +129,7 @@ Mix_Music* midi::load_track(std::string fileName)
if (!audio) if (!audio)
return nullptr; return nullptr;
LoadedTracks->Add(audio); LoadedTracks.push_back(audio);
return audio; return audio;
} }

View file

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "objlist_class.h"
constexpr uint32_t SwapByteOrderInt(uint32_t val) constexpr uint32_t SwapByteOrderInt(uint32_t val)
{ {
@ -92,7 +91,7 @@ public:
static int music_init(); static int music_init();
static void music_shutdown(); static void music_shutdown();
private: private:
static objlist_class<Mix_Music>* LoadedTracks; static std::vector<Mix_Music*> LoadedTracks;
static Mix_Music *track1, *track2, *track3, *active_track, *NextTrack; static Mix_Music *track1, *track2, *track3, *active_track, *NextTrack;
static bool SetNextTrackFlag; static bool SetNextTrackFlag;
static Mix_Music* load_track(std::string fileName); static Mix_Music* load_track(std::string fileName);

View file

@ -2,7 +2,6 @@
#include "nudge.h" #include "nudge.h"
#include "objlist_class.h"
#include "pb.h" #include "pb.h"
#include "render.h" #include "render.h"
#include "TBall.h" #include "TBall.h"
@ -68,12 +67,10 @@ void nudge::_nudge(float xDiff, float yDiff)
vector_type accelMod; vector_type accelMod;
float invAccelX, invAccelY; float invAccelX, invAccelY;
auto ballList = pb::MainTable->BallList;
accelMod.X = xDiff * 0.5f; accelMod.X = xDiff * 0.5f;
accelMod.Y = yDiff * 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) if (ball->ActiveFlag && !ball->CollisionComp)
{ {
ball->Acceleration.X = ball->Acceleration.X * ball->Speed; ball->Acceleration.X = ball->Acceleration.X * ball->Speed;

View file

@ -1,78 +0,0 @@
#pragma once
#include "memory.h"
template <class T>
class objlist_class
{
public:
objlist_class(int sizeInt, int growSize)
{
ListPtr = memory::allocate<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 = 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;
};

View file

@ -4,7 +4,6 @@
#include "fullscrn.h" #include "fullscrn.h"
#include "memory.h" #include "memory.h"
#include "midi.h" #include "midi.h"
#include "pb.h"
#include "Sound.h" #include "Sound.h"
#include "winmain.h" #include "winmain.h"

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "partman.h" #include "partman.h"
#include "fullscrn.h"
#include "gdrv.h" #include "gdrv.h"
#include "GroupData.h" #include "GroupData.h"
#include "memory.h" #include "memory.h"
@ -56,27 +55,25 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
bool abort = false; bool abort = false;
for (auto groupIndex = 0; !abort && groupIndex < header.NumberOfGroups; ++groupIndex) for (auto groupIndex = 0; !abort && groupIndex < header.NumberOfGroups; ++groupIndex)
{ {
auto entryCount = _lread_char(fileHandle); auto entryCount = LRead<uint8_t>(fileHandle);
auto groupData = new GroupData(groupIndex); auto groupData = new GroupData(groupIndex);
groupData->ReserveEntries(entryCount); groupData->ReserveEntries(entryCount);
for (auto entryIndex = 0; entryIndex < entryCount; ++entryIndex) for (auto entryIndex = 0; entryIndex < entryCount; ++entryIndex)
{ {
auto entryData = new EntryData(); auto entryData = new EntryData();
auto entryType = static_cast<FieldTypes>(_lread_char(fileHandle)); auto entryType = static_cast<FieldTypes>(LRead<uint8_t>(fileHandle));
entryData->EntryType = entryType; entryData->EntryType = entryType;
int fieldSize = _field_size[static_cast<int>(entryType)]; int fixedSize = _field_size[static_cast<int>(entryType)];
if (fieldSize < 0) size_t fieldSize = fixedSize >= 0 ? fixedSize : LRead<uint32_t>(fileHandle);
fieldSize = _lread_long(fileHandle); entryData->FieldSize = static_cast<int>(fieldSize);
entryData->FieldSize = fieldSize;
if (entryType == FieldTypes::Bitmap8bit) if (entryType == FieldTypes::Bitmap8bit)
{ {
fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle); fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle);
assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size"); assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size");
assertm(bmpHeader.Resolution >= 0 && bmpHeader.Resolution <= 2, assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds");
"partman: bitmap resolution out of bounds");
auto bmp = memory::allocate<gdrv_bitmap8>(); auto bmp = memory::allocate<gdrv_bitmap8>();
entryData->Buffer = reinterpret_cast<char*>(bmp); entryData->Buffer = reinterpret_cast<char*>(bmp);
@ -90,28 +87,28 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
else if (entryType == FieldTypes::Bitmap16bit) else if (entryType == FieldTypes::Bitmap16bit)
{ {
/*Full tilt has extra byte(@0:resolution) in zMap*/ /*Full tilt has extra byte(@0:resolution) in zMap*/
char zMapResolution = 0; auto zMapResolution = 0u;
if (fullTiltMode) if (fullTiltMode)
{ {
zMapResolution = _lread_char(fileHandle); zMapResolution = LRead<uint8_t>(fileHandle);
fieldSize--; 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); fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle);
int length = fieldSize - sizeof(dat16BitBmpHeader); auto length = fieldSize - sizeof(dat16BitBmpHeader);
auto zMap = memory::allocate<zmap_header_type>(); auto zMap = memory::allocate<zmap_header_type>();
zdrv::create_zmap(zMap, zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride); zdrv::create_zmap(zMap, zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride);
zMap->Resolution = zMapResolution; zMap->Resolution = zMapResolution;
if (zMapHeader.Stride * zMapHeader.Height * 2 == length) if (zMapHeader.Stride * zMapHeader.Height * 2u == length)
{ {
fread(zMap->ZPtr1, 1, length, fileHandle); fread(zMap->ZPtr1, 1, length, fileHandle);
} }
else else
{ {
// 3DPB .dat has zeroed zMap headers, in groups 497 and 498, skip them. // 3DPB .dat has zeroed zMap headers, in groups 497 and 498, skip them.
fseek(fileHandle, length, SEEK_CUR); fseek(fileHandle, static_cast<int>(length), SEEK_CUR);
} }
entryData->Buffer = reinterpret_cast<char*>(zMap); entryData->Buffer = reinterpret_cast<char*>(zMap);
} }
@ -140,17 +137,3 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
delete datFile; delete datFile;
return nullptr; 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;
}

View file

@ -59,9 +59,15 @@ static_assert(sizeof(dat16BitBmpHeader) == 14, "Wrong size of zmap_header_type")
class partman class partman
{ {
public: public:
static struct DatFile* load_records(LPCSTR lpFileName, bool fullTiltMode); static class DatFile* load_records(LPCSTR lpFileName, bool fullTiltMode);
private: private:
static short _field_size[]; static short _field_size[];
static char _lread_char(FILE* file);
static int _lread_long(FILE* file); template <typename T>
static T LRead(FILE* file)
{
T Buffer{};
fread(&Buffer, 1, sizeof(T), file);
return Buffer;
}
}; };

View file

@ -12,7 +12,6 @@
#include "loader.h" #include "loader.h"
#include "midi.h" #include "midi.h"
#include "nudge.h" #include "nudge.h"
#include "objlist_class.h"
#include "options.h" #include "options.h"
#include "timer.h" #include "timer.h"
#include "winmain.h" #include "winmain.h"
@ -101,7 +100,7 @@ int pb::init()
MainTable = new TPinballTable(); MainTable = new TPinballTable();
high_score::read(highscore_table); 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; --memory::critical_allocation;
return 0; return 0;
} }
@ -112,8 +111,7 @@ int pb::uninit()
loader::unload(); loader::unload();
delete record_table; delete record_table;
high_score::write(highscore_table); high_score::write(highscore_table);
if (MainTable) delete MainTable;
delete MainTable;
MainTable = nullptr; MainTable = nullptr;
timer::uninit(); timer::uninit();
render::uninit(); render::uninit();
@ -208,7 +206,7 @@ void pb::replay_level(int demoMode)
void pb::ballset(int x, int y) 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.X = x * 30.0f;
ball->Acceleration.Y = y * 30.0f; ball->Acceleration.Y = y * 30.0f;
ball->Speed = maths::normalize_2d(&ball->Acceleration); ball->Speed = maths::normalize_2d(&ball->Acceleration);
@ -216,7 +214,6 @@ void pb::ballset(int x, int y)
void pb::frame(int dtMilliSec) void pb::frame(int dtMilliSec)
{ {
if (dtMilliSec > 100) if (dtMilliSec > 100)
dtMilliSec = 100; dtMilliSec = 100;
if (dtMilliSec <= 0) if (dtMilliSec <= 0)
@ -258,9 +255,8 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
{ {
vector_type vec1{}, vec2{}; 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) if (ball->ActiveFlag != 0)
{ {
auto collComp = ball->CollisionComp; auto collComp = ball->CollisionComp;
@ -301,9 +297,8 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
if (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) if (ball->ActiveFlag)
ball->Repaint(); ball->Repaint();
} }
@ -444,19 +439,19 @@ void pb::keydown(int key)
{ {
case 'b': case 'b':
TBall* ball; TBall* ball;
if (MainTable->BallList->GetCount() <= 0) if (MainTable->BallList.empty())
{ {
ball = new TBall(MainTable); ball = new TBall(MainTable);
} }
else else
{ {
for (auto index = 0; ;) for (auto index = 0u; ;)
{ {
ball = MainTable->BallList->Get(index); ball = MainTable->BallList.at(index);
if (!ball->ActiveFlag) if (!ball->ActiveFlag)
break; break;
++index; ++index;
if (index >= MainTable->BallList->GetCount()) if (index >= MainTable->BallList.size())
{ {
ball = new TBall(MainTable); ball = new TBall(MainTable);
break; break;

View file

@ -517,7 +517,7 @@ void render::SpriteViewer(bool* show)
if (!bmp) if (!bmp)
continue; continue;
auto type = BitmapTypes[static_cast<char>(bmp->BitmapType)]; auto type = BitmapTypes[static_cast<uint8_t>(bmp->BitmapType)];
ImGui::Text("type:%s, size:%d, resolution: %dx%d, offset:%dx%d", type, ImGui::Text("type:%s, size:%d, resolution: %dx%d, offset:%dx%d", type,
bmp->Resolution, bmp->Resolution,
bmp->Width, bmp->Height, bmp->XPosition, bmp->YPosition); bmp->Width, bmp->Height, bmp->XPosition, bmp->YPosition);
@ -575,7 +575,7 @@ void render::BlitVScreen()
reinterpret_cast<void**>(&lockedPixels), reinterpret_cast<void**>(&lockedPixels),
&pitch &pitch
); );
assertm(pitch == vscreen.Width * sizeof(ColorRgba), "Padding on vScreen texture"); assertm(static_cast<unsigned>(pitch) == vscreen.Width * sizeof(ColorRgba), "Padding on vScreen texture");
if (offset_x == 0 && offset_y == 0) if (offset_x == 0 && offset_y == 0)
{ {

View file

@ -1,7 +1,6 @@
#include "pch.h" #include "pch.h"
#include "zdrv.h" #include "zdrv.h"
#include "memory.h" #include "memory.h"
#include "pb.h"
#include "winmain.h" #include "winmain.h"