2020-11-01 16:45:29 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TTableLayer.h"
|
2020-12-20 12:13:12 +01:00
|
|
|
|
|
|
|
#include "loader.h"
|
2021-01-08 16:50:12 +01:00
|
|
|
#include "objlist_class.h"
|
2020-12-20 12:13:12 +01:00
|
|
|
#include "proj.h"
|
2020-12-25 14:46:06 +01:00
|
|
|
#include "render.h"
|
2021-01-08 16:50:12 +01:00
|
|
|
#include "TBall.h"
|
2020-12-20 12:13:12 +01:00
|
|
|
#include "TLine.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
|
|
|
TEdgeManager* TTableLayer::edge_manager;
|
|
|
|
|
|
|
|
TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, false)
|
|
|
|
{
|
|
|
|
visualStruct visual{};
|
|
|
|
rectangle_type rect{};
|
|
|
|
|
|
|
|
auto groupIndex = loader::query_handle("table");
|
|
|
|
loader::query_visual(groupIndex, 0, &visual);
|
|
|
|
|
|
|
|
auto projCenter = loader::query_float_attribute(groupIndex, 0, 700);
|
|
|
|
proj::recenter(projCenter[0], projCenter[1]);
|
|
|
|
render::set_background_zmap(visual.ZMap, 0, 0);
|
|
|
|
|
|
|
|
auto bmp = visual.Bitmap;
|
|
|
|
VisBmp = visual.Bitmap;
|
|
|
|
rect.XPosition = 0;
|
|
|
|
rect.YPosition = 0;
|
|
|
|
rect.Width = bmp->Width;
|
|
|
|
rect.Height = bmp->Height;
|
|
|
|
render::create_sprite(VisualType::None, bmp, visual.ZMap, 0, 0, &rect);
|
|
|
|
|
|
|
|
PinballTable->SoundIndex1 = visual.SoundIndex4;
|
|
|
|
PinballTable->SoundIndex2 = visual.SoundIndex3;
|
|
|
|
PinballTable->SoundIndex3 = visual.Kicker.SoundIndex;
|
|
|
|
|
|
|
|
auto tableAngleArr = loader::query_float_attribute(groupIndex, 0, 305);
|
|
|
|
if (tableAngleArr)
|
|
|
|
{
|
2021-01-07 17:00:38 +01:00
|
|
|
PinballTable->GravityDirVectMult = tableAngleArr[0];
|
|
|
|
PinballTable->GravityAngleX = tableAngleArr[1];
|
|
|
|
PinballTable->GravityAnglY = tableAngleArr[2];
|
2020-12-20 12:13:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-07 17:00:38 +01:00
|
|
|
PinballTable->GravityDirVectMult = 25.0f;
|
|
|
|
PinballTable->GravityAngleX = 0.5f;
|
|
|
|
PinballTable->GravityAnglY = 1.570796f;
|
2020-12-20 12:13:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto table3 = PinballTable;
|
2021-01-07 17:00:38 +01:00
|
|
|
GraityDirX = cos(table3->GravityAnglY) * sin(table3->GravityAngleX) * table3->GravityDirVectMult;
|
|
|
|
GraityDiY = sin(table3->GravityAnglY) * sin(table3->GravityAngleX) * table3->GravityDirVectMult;
|
2020-12-20 12:13:12 +01:00
|
|
|
auto angleMultArr = loader::query_float_attribute(groupIndex, 0, 701);
|
|
|
|
if (angleMultArr)
|
2021-01-07 17:00:38 +01:00
|
|
|
GraityMult = *angleMultArr;
|
2020-12-20 12:13:12 +01:00
|
|
|
else
|
2021-01-07 17:00:38 +01:00
|
|
|
GraityMult = 0.2f;
|
2020-12-20 12:13:12 +01:00
|
|
|
|
|
|
|
table->XOffset = bmp->XPosition;
|
|
|
|
table->YOffset = bmp->YPosition;
|
|
|
|
table->Width = bmp->Width;
|
|
|
|
table->Height = bmp->Height;
|
2021-01-07 17:00:38 +01:00
|
|
|
MaxCollisionSpeed = visual.Kicker.Unknown1F;
|
|
|
|
CollisionMultiplier = 15.0f;
|
2020-12-20 12:13:12 +01:00
|
|
|
|
|
|
|
auto visArrPtr = visual.FloatArr;
|
|
|
|
Unknown1F = min(visArrPtr[0], min(visArrPtr[2], visArrPtr[4]));
|
|
|
|
Unknown2F = min(visArrPtr[1], min(visArrPtr[3], visArrPtr[5]));
|
|
|
|
Unknown3F = max(visArrPtr[0], max(visArrPtr[2], visArrPtr[4]));
|
|
|
|
Unknown4F = max(visArrPtr[1], max(visArrPtr[3], visArrPtr[5]));
|
|
|
|
auto a2 = Unknown4F - Unknown2F;
|
|
|
|
auto a1 = Unknown3F - Unknown1F;
|
|
|
|
edge_manager = new TEdgeManager(Unknown1F, Unknown2F, a1, a2);
|
|
|
|
|
|
|
|
for (auto visFloatArrCount = visual.FloatArrCount; visFloatArrCount > 0; visFloatArrCount--)
|
|
|
|
{
|
|
|
|
auto line = new TLine(this,
|
|
|
|
&UnknownBaseFlag2,
|
|
|
|
visual.Flag,
|
|
|
|
visArrPtr[2],
|
|
|
|
visArrPtr[3],
|
|
|
|
visArrPtr[0],
|
|
|
|
visArrPtr[1]);
|
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
line->place_in_grid();
|
|
|
|
EdgeList->Add(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
visArrPtr += 2;
|
|
|
|
}
|
|
|
|
|
2021-01-07 17:00:38 +01:00
|
|
|
Field.Mask = -1;
|
2020-12-20 12:13:12 +01:00
|
|
|
Field.Flag2Ptr = &UnknownBaseFlag2;
|
|
|
|
Field.CollisionComp = this;
|
2021-01-07 17:00:38 +01:00
|
|
|
edges_insert_square(Unknown2F, Unknown1F, Unknown4F, Unknown3F, nullptr,
|
|
|
|
&Field);
|
2020-12-20 12:13:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TTableLayer::~TTableLayer()
|
|
|
|
{
|
|
|
|
if (edge_manager)
|
|
|
|
delete edge_manager;
|
|
|
|
}
|
2021-01-07 17:00:38 +01:00
|
|
|
|
|
|
|
int TTableLayer::FieldEffect(TBall* ball, vector_type* vecDst)
|
|
|
|
{
|
|
|
|
vecDst->X = GraityDirX - (0.5f - static_cast<float>(rand()) * 0.00003051850947599719f + ball->Acceleration.X) *
|
|
|
|
ball->Speed * GraityMult;
|
|
|
|
vecDst->Y = GraityDiY - ball->Acceleration.Y * ball->Speed * GraityMult;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTableLayer::edges_insert_square(float y0, float x0, float y1, float x1, TEdgeSegment* edge,
|
|
|
|
field_effect_type* field)
|
|
|
|
{
|
2021-01-08 16:50:12 +01:00
|
|
|
float widthM = static_cast<float>(static_cast<int>(edge_manager->AdvanceX * 0.001f)); // Sic
|
|
|
|
float heightM = static_cast<float>(static_cast<int>(edge_manager->AdvanceY * 0.001f));
|
2021-01-07 17:00:38 +01:00
|
|
|
float xMin = x0 - widthM;
|
|
|
|
float xMax = x1 + widthM;
|
|
|
|
float yMin = y0 - heightM;
|
|
|
|
float yMax = y1 + heightM;
|
|
|
|
|
|
|
|
int xMinBox = edge_manager->box_x(xMin);
|
|
|
|
int yMinBox = edge_manager->box_y(yMin);
|
|
|
|
int xMaxBox = edge_manager->box_x(xMax);
|
|
|
|
int yMaxBox = edge_manager->box_y(yMax);
|
|
|
|
|
|
|
|
float boxX = static_cast<float>(xMinBox) * edge_manager->AdvanceX + edge_manager->X;
|
|
|
|
for (int indexX = xMinBox; indexX <= xMaxBox; ++indexX)
|
|
|
|
{
|
2021-01-08 16:50:12 +01:00
|
|
|
float boxY = static_cast<float>(yMinBox) * edge_manager->AdvanceY + edge_manager->Y;
|
2021-01-07 17:00:38 +01:00
|
|
|
for (int indexY = yMinBox; indexY <= yMaxBox; ++indexY)
|
|
|
|
{
|
|
|
|
if (xMax >= boxX && xMin <= boxX + edge_manager->AdvanceX &&
|
|
|
|
yMax >= boxY && yMin <= boxY + edge_manager->AdvanceY)
|
|
|
|
{
|
|
|
|
if (edge)
|
|
|
|
{
|
|
|
|
edge_manager->add_edge_to_box(indexX, indexY, edge);
|
|
|
|
}
|
|
|
|
if (field)
|
|
|
|
{
|
|
|
|
edge_manager->add_field_to_box(indexX, indexY, field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boxY += edge_manager->AdvanceY;
|
|
|
|
}
|
|
|
|
boxX += edge_manager->AdvanceX;
|
|
|
|
}
|
|
|
|
}
|
2021-01-08 16:50:12 +01:00
|
|
|
|
|
|
|
void TTableLayer::edges_insert_circle(circle_type* circle, TEdgeSegment* edge, field_effect_type* field)
|
|
|
|
{
|
|
|
|
ray_type ray{};
|
|
|
|
vector_type vec1{};
|
|
|
|
|
|
|
|
auto radiusM = sqrt(circle->RadiusSq) + edge_manager->AdvanceX * 0.001f;
|
|
|
|
auto radiusMSq = radiusM * radiusM;
|
|
|
|
|
|
|
|
auto xMin = circle->Center.X - radiusM;
|
|
|
|
auto yMin = circle->Center.Y - radiusM;
|
|
|
|
auto xMax = radiusM + circle->Center.X;
|
|
|
|
auto yMax = radiusM + circle->Center.Y;
|
|
|
|
|
|
|
|
auto xMinBox = edge_manager->box_x(xMin);
|
|
|
|
auto yMinBox = edge_manager->box_y(yMin);
|
|
|
|
auto xMaxBox = edge_manager->box_x(xMax);
|
|
|
|
auto yMaxBox = edge_manager->box_y(yMax);
|
|
|
|
|
|
|
|
auto dirX = xMinBox - 1 <= 0 ? 0 : xMinBox - 1;
|
|
|
|
auto dirY = yMinBox - 1 <= 0 ? 0 : yMinBox - 1;
|
|
|
|
|
|
|
|
xMaxBox = edge_manager->increment_box_x(xMaxBox);
|
|
|
|
yMaxBox = edge_manager->increment_box_y(yMaxBox);
|
|
|
|
|
|
|
|
vec1.X = static_cast<float>(dirX) * edge_manager->AdvanceX + edge_manager->X;
|
|
|
|
for (auto indexX = dirX; indexX <= xMaxBox; ++indexX)
|
|
|
|
{
|
|
|
|
vec1.Y = static_cast<float>(dirY) * edge_manager->AdvanceY + edge_manager->Y;
|
|
|
|
for (int indexY = dirY; indexY <= yMaxBox; ++indexY)
|
|
|
|
{
|
|
|
|
auto vec1XAdv = vec1.X + edge_manager->AdvanceX;
|
|
|
|
auto vec1YAdv = vec1.Y + edge_manager->AdvanceY;
|
|
|
|
if (xMax >= vec1.X && xMin <= vec1XAdv &&
|
|
|
|
yMax >= vec1.Y && yMin <= vec1YAdv)
|
|
|
|
{
|
|
|
|
bool collision = true;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (circle->Center.X <= vec1XAdv && circle->Center.X >= vec1.X &&
|
|
|
|
circle->Center.Y <= vec1YAdv && circle->Center.Y >= vec1.Y)
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto vec2 = vec1;
|
|
|
|
if (maths::Distance_Squared(vec1, circle->Center) <= radiusMSq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
vec2.X = vec2.X + edge_manager->AdvanceX;
|
|
|
|
if (maths::Distance_Squared(vec2, circle->Center) <= radiusMSq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
vec2.Y = vec2.Y + edge_manager->AdvanceY;
|
|
|
|
if (maths::Distance_Squared(vec2, circle->Center) <= radiusMSq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
vec2.X = vec2.X - edge_manager->AdvanceX;
|
|
|
|
if (maths::Distance_Squared(vec2, circle->Center) <= radiusMSq)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Origin = vec1;
|
|
|
|
ray.Direction.X = 1.0;
|
|
|
|
ray.Direction.Y = 0.0;
|
|
|
|
ray.MaxDistance = edge_manager->AdvanceX;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.X = -1.0;
|
|
|
|
ray.Origin.X = ray.Origin.X + edge_manager->AdvanceX;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.X = 0.0;
|
|
|
|
ray.Direction.Y = 1.0;
|
|
|
|
ray.MaxDistance = edge_manager->AdvanceY;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.Y = -1.0;
|
|
|
|
ray.Origin.Y = ray.Origin.Y + edge_manager->AdvanceY;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.Y = 0.0;
|
|
|
|
ray.Direction.X = -1.0;
|
|
|
|
ray.MaxDistance = edge_manager->AdvanceX;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.X = 1.0;
|
|
|
|
ray.Origin.X = ray.Origin.X - edge_manager->AdvanceX;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.X = 0.0;
|
|
|
|
ray.Direction.Y = -1.0;
|
|
|
|
ray.MaxDistance = edge_manager->AdvanceY;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ray.Direction.Y = 1.0;
|
|
|
|
ray.Origin.Y = ray.Origin.Y - edge_manager->AdvanceY;
|
|
|
|
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
collision = false;
|
|
|
|
}
|
|
|
|
while (false);
|
|
|
|
if (collision)
|
|
|
|
{
|
|
|
|
if (edge)
|
|
|
|
{
|
|
|
|
edge_manager->add_edge_to_box(indexX, indexY, edge);
|
|
|
|
}
|
|
|
|
if (field)
|
|
|
|
{
|
|
|
|
edge_manager->add_field_to_box(indexX, indexY, field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vec1.Y += edge_manager->AdvanceY;
|
|
|
|
}
|
|
|
|
vec1.X += edge_manager->AdvanceX;
|
|
|
|
}
|
|
|
|
}
|