Merge branch 'k4zmu2a:master' into powerpc

This commit is contained in:
iAmInAction 2022-05-14 23:52:13 +02:00 committed by GitHub
commit e17b69671d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 435 additions and 503 deletions

View File

@ -221,10 +221,10 @@ endif()
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
install(TARGETS "${PROJECT_NAME}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES "Platform/Linux/${PROJECT_NAME}.desktop" DESTINATION "share/applications")
install(FILES "Platform/Linux/${PROJECT_NAME}.metainfo.xml" DESTINATION "share/metainfo")
install(FILES "${CMAKE_SOURCE_DIR}/Platform/Linux/${PROJECT_NAME}.desktop" DESTINATION "share/applications")
install(FILES "${CMAKE_SOURCE_DIR}/Platform/Linux/${PROJECT_NAME}.metainfo.xml" DESTINATION "share/metainfo")
foreach(S 16 32 48 128 192)
install(FILES "${PROJECT_NAME}/Icon_${S}x${S}.png" DESTINATION
install(FILES "${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/Icon_${S}x${S}.png" DESTINATION
"share/icons/hicolor/${S}x${S}/apps" RENAME "${PROJECT_NAME}.png")
endforeach(S)
endif()

View File

@ -10,4 +10,7 @@
<Item Name="[Color]" ExcludeView="simple">Color</Item>
</Expand>
</Type>
<Type Name="vector3">
<DisplayString>{{ X={X} Y={Y} Z={Z} }}</DisplayString>
</Type>
</AutoVisualizer>

View File

@ -49,7 +49,7 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false)
loader::query_visual(groupIndex, index, &visual);
if (ListBitmap)
ListBitmap->push_back(visual.Bitmap);
auto visVec = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, index, 501));
auto visVec = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, index, 501));
auto zDepth = proj::z_distance(visVec);
VisualZArray[index] = zDepth;
}
@ -129,13 +129,13 @@ int TBall::Message(int code, float value)
return 0;
}
void TBall::throw_ball(TBall* ball, vector_type* acceleration, float angleMult, float speedMult1, float speedMult2)
void TBall::throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1, float speedMult2)
{
ball->CollisionComp = nullptr;
ball->Acceleration = *acceleration;
float rnd = RandFloat();
float angle = (1.0f - (rnd + rnd)) * angleMult;
maths::RotateVector(&ball->Acceleration, angle);
maths::RotateVector(ball->Acceleration, angle);
rnd = RandFloat();
ball->Speed = (1.0f - (rnd + rnd)) * (speedMult1 * speedMult2) + speedMult1;
}

View File

@ -14,22 +14,22 @@ public :
bool already_hit(TEdgeSegment* edge);
int Message(int code, float value) override;
static void throw_ball(TBall* ball, struct vector_type* acceleration, float angleMult, float speedMult1,
static void throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1,
float speedMult2);
vector_type Position{};
vector_type Acceleration{};
vector3 Position{};
vector3 Acceleration{};
float Speed;
float RayMaxDistance;
float TimeDelta;
float TimeNow;
vector_type InvAcceleration{};
vector_type RampFieldForce{};
vector2 InvAcceleration{};
vector2 RampFieldForce{};
TCollisionComponent* CollisionComp;
int FieldFlag;
TEdgeSegment* Collisions[5]{};
int EdgeCollisionCount;
vector_type CollisionOffset{};
vector3 CollisionOffset{};
int CollisionFlag;
float Offset;
float VisualZArray[50]{};

View File

@ -100,7 +100,7 @@ int TBumper::Message(int code, float value)
return 0;
}
void TBumper::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TBumper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (DefaultCollision(ball, nextPosition, direction))
{

View File

@ -14,7 +14,7 @@ public:
TBumper(TPinballTable* table, int groupIndex);
~TBumper() override = default;
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;

View File

@ -5,7 +5,7 @@
#include "TCollisionComponent.h"
#include "TTableLayer.h"
TCircle::TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned collisionGroup, vector_type* center,
TCircle::TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned collisionGroup, vector2* center,
float radius): TEdgeSegment(collComp, activeFlag, collisionGroup)
{
Circle.RadiusSq = radius * radius;
@ -14,18 +14,18 @@ TCircle::TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned colli
float TCircle::FindCollisionDistance(ray_type* ray)
{
return maths::ray_intersect_circle(ray, &Circle);
return maths::ray_intersect_circle(*ray, Circle);
}
void TCircle::EdgeCollision(TBall* ball, float coef)
{
vector_type direction{}, nextPosition{};
vector2 direction{}, nextPosition{};
nextPosition.X = coef * ball->Acceleration.X + ball->Position.X;
nextPosition.Y = coef * ball->Acceleration.Y + ball->Position.Y;
direction.X = nextPosition.X - Circle.Center.X;
direction.Y = nextPosition.Y - Circle.Center.Y;
maths::normalize_2d(&direction);
maths::normalize_2d(direction);
CollisionComponent->Collision(ball, &nextPosition, &direction, coef, this);
}

View File

@ -8,7 +8,7 @@ class TCircle :
public:
circle_type Circle{};
TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, vector_type* center,
TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, vector2* center,
float radius);
float FindCollisionDistance(ray_type* ray) override;
void EdgeCollision(TBall* ball, float coef) override;

View File

@ -51,7 +51,7 @@ void TCollisionComponent::port_draw()
edge->port_draw();
}
int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)
int TCollisionComponent::DefaultCollision(TBall* ball, vector2* nextPosition, vector2* direction)
{
if (PinballTable->TiltLockFlag)
{
@ -73,7 +73,7 @@ int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition
return 1;
}
void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction,
void TCollisionComponent::Collision(TBall* ball, vector2* nextPosition, vector2* direction,
float coef, TEdgeSegment* edge)
{
int soundIndex;
@ -105,7 +105,7 @@ void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vect
loader::play_sound(soundIndex);
}
int TCollisionComponent::FieldEffect(TBall* ball, vector_type* vecDst)
int TCollisionComponent::FieldEffect(TBall* ball, vector2* vecDst)
{
return 0;
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "TPinballComponent.h"
struct vector_type;
struct vector2;
class TEdgeSegment;
class TBall;
@ -19,8 +19,8 @@ public:
TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall);
~TCollisionComponent() override;
void port_draw() override;
virtual void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
virtual void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge);
virtual int FieldEffect(TBall* ball, vector_type* vecDst);
int DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction);
virtual int FieldEffect(TBall* ball, vector2* vecDst);
int DefaultCollision(TBall* ball, vector2* nextPosition, vector2* direction);
};

View File

@ -93,7 +93,7 @@ int TDemo::Message(int code, float value)
return 0;
}
void TDemo::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TDemo::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
ball->not_again(edge);
ball->Position.X = nextPosition->X;

View File

@ -7,7 +7,7 @@ class TDemo :
public:
TDemo(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void PlungerRelease(int timerId, void* caller);

View File

@ -28,7 +28,7 @@ int TDrain::Message(int code, float value)
return 0;
}
void TDrain::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TDrain::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
ball->Message(1024, 0.0);
PinballTable->BallInSink = 1;

View File

@ -7,7 +7,7 @@ class TDrain :
public:
TDrain(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerCallback(int timerId, void* caller);

View File

@ -87,9 +87,9 @@ int TEdgeManager::TestGridBox(int x, int y, float* distPtr, TEdgeSegment** edgeD
return edgeIndex;
}
void TEdgeManager::FieldEffects(TBall* ball, vector_type* dstVec)
void TEdgeManager::FieldEffects(TBall* ball, vector2* dstVec)
{
vector_type vec{};
vector2 vec{};
TEdgeBox* edgeBox = &BoxArray[box_x(ball->Position.X) + box_y(ball->Position.Y) *
MaxBoxX];
@ -100,7 +100,7 @@ void TEdgeManager::FieldEffects(TBall* ball, vector_type* dstVec)
{
if (field->CollisionComp->FieldEffect(ball, &vec))
{
maths::vector_add(dstVec, &vec);
maths::vector_add(*dstVec, vec);
}
}
}

View File

@ -16,7 +16,7 @@ class TEdgeManager
public:
TEdgeManager(float posX, float posY, float width, float height);
~TEdgeManager();
void FieldEffects(TBall* ball, struct vector_type* dstVec);
void FieldEffects(TBall* ball, struct vector2* dstVec);
int box_x(float x);
int box_y(float y);
int increment_box_x(int x);

View File

@ -20,7 +20,8 @@ void TEdgeSegment::port_draw()
TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* collComp, char* activeFlagPtr,
unsigned int collisionGroup, float offset, size_t wallValue)
{
vector_type center{}, start{}, end{}, prevCenter{}, vec1{}, vec2{}, dstVec{};
vector2 center{}, start{}, end{}, prevCenter{};
vector3 vec1{}, vec2{}, dstVec{};
TEdgeSegment* edge = nullptr;
wall_type wallType = static_cast<wall_type>(static_cast<int>(floor(*floatArr) - 1.0f));
@ -49,7 +50,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
start.Y = floatArr[2];
end.X = floatArr[3];
end.Y = floatArr[4];
auto line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end);
auto line = new TLine(collComp, activeFlagPtr, collisionGroup, start, end);
edge = line;
if (line)
@ -92,7 +93,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
vec1.Y = center.Y - prevCenter.Y;
vec2.X = centerX2 - centerX1;
vec2.Y = centerY2 - center.Y;
maths::cross(&vec1, &vec2, &dstVec);
maths::cross(vec1, vec2, dstVec);
if ((dstVec.Z > 0.0f && offset > 0.0f) ||
(dstVec.Z < 0.0f && offset < 0.0f))
{
@ -112,7 +113,7 @@ TEdgeSegment* TEdgeSegment::install_wall(float* floatArr, TCollisionComponent* c
start.Y = floatArrPtr[1];
end.X = floatArrPtr[2];
end.Y = floatArrPtr[3];
auto line = new TLine(collComp, activeFlagPtr, collisionGroup, &start, &end);
auto line = new TLine(collComp, activeFlagPtr, collisionGroup, start, end);
edge = line;
if (line)

View File

@ -13,7 +13,7 @@
TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{
visualStruct visual{};
vector_type end{}, start{};
vector2 end{}, start{};
Timer = 0;
loader::query_visual(groupIndex, 0, &visual);
@ -21,14 +21,14 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom
end.Y = visual.FloatArr[1];
start.X = visual.FloatArr[2];
start.Y = visual.FloatArr[3];
auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &start, &end);
auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, start, end);
if (line)
{
line->place_in_grid();
EdgeList.push_back(line);
}
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &end, &start);
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, end, start);
PrevCollider = line;
if (line)
{
@ -72,7 +72,7 @@ int TFlagSpinner::Message(int code, float value)
return 0;
}
void TFlagSpinner::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TFlagSpinner::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
ball->Position.X = nextPosition->X;

View File

@ -7,7 +7,7 @@ class TFlagSpinner :
public:
TFlagSpinner(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;

View File

@ -31,9 +31,9 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t
retractTime = 0.08f;
extendTime = 0.04f;
}
auto vecT2 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 802));
auto vecT1 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 801));
auto origin = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 800));
auto vecT2 = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 802));
auto vecT1 = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 801));
auto origin = reinterpret_cast<vector3*>(loader::query_float_attribute(groupIndex, 0, 800));
auto flipperEdge = new TFlipperEdge(
this,
&ActiveFlag,
@ -128,7 +128,7 @@ void TFlipper::port_draw()
FlipperEdge->port_draw();
}
void TFlipper::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TFlipper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
}

View File

@ -11,7 +11,7 @@ public:
~TFlipper() override;
int Message(int code, float value) override;
void port_draw() override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);

View File

@ -7,15 +7,15 @@
#include "TTableLayer.h"
float TFlipperEdge::flipper_sin_angle, TFlipperEdge::flipper_cos_angle;
vector_type TFlipperEdge::A1, TFlipperEdge::A2, TFlipperEdge::B1, TFlipperEdge::B2, TFlipperEdge::T1;
vector2 TFlipperEdge::A1, TFlipperEdge::A2, TFlipperEdge::B1, TFlipperEdge::B2, TFlipperEdge::T1;
line_type TFlipperEdge::lineA, TFlipperEdge::lineB;
circle_type TFlipperEdge::circlebase, TFlipperEdge::circleT1;
TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime,
vector3* origin, vector3* vecT1, vector3* vecT2, float extendTime, float retractTime,
float collMult, float elasticity, float smoothness): TEdgeSegment(collComp, activeFlag, collisionGroup)
{
vector_type crossProd{}, vecDir1{}, vecDir2{};
vector3 crossProd{}, vecDir1{}, vecDir2{};
Elasticity = elasticity;
Smoothness = smoothness;
@ -23,8 +23,8 @@ TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsi
RetractTime = retractTime;
CollisionMult = collMult;
T1Src = *vecT1;
T2Src = *vecT2;
T1Src = static_cast<vector2>(*vecT1);
T2Src = static_cast<vector2>(*vecT2);
RotOrigin.X = origin->X;
RotOrigin.Y = origin->Y;
@ -39,15 +39,15 @@ TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsi
vecDir1.X = vecT1->X - origin->X;
vecDir1.Y = vecT1->Y - origin->Y;
vecDir1.Z = 0.0;
maths::normalize_2d(&vecDir1);
maths::normalize_2d(vecDir1);
vecDir2.X = vecT2->X - origin->X;
vecDir2.Y = vecT2->Y - origin->Y;
vecDir2.Z = 0.0;
maths::normalize_2d(&vecDir2);
maths::normalize_2d(vecDir2);
AngleMax = acos(maths::DotProduct(&vecDir1, &vecDir2));
maths::cross(&vecDir1, &vecDir2, &crossProd);
AngleMax = acos(maths::DotProduct(vecDir1, vecDir2));
maths::cross(vecDir1, vecDir2, crossProd);
if (crossProd.Z < 0.0f)
AngleMax = -AngleMax;
FlipperFlag = 0;
@ -69,8 +69,8 @@ TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsi
if (AngleMax < 0.0f)
{
maths::vswap(&A1Src, &B1Src);
maths::vswap(&A2Src, &B2Src);
std::swap(A1Src, B1Src);
std::swap(A2Src, B2Src);
}
auto dx = vecT1->X - RotOrigin.X;
@ -79,7 +79,7 @@ TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsi
DistanceDivSq = distance1 * distance1;
float minMoveTime = std::min(ExtendTime, RetractTime);
auto distance = maths::Distance(vecT1, vecT2);
auto distance = maths::Distance(*vecT1, *vecT2);
CollisionTimeAdvance = minMoveTime / (distance / CircleT1Radius + distance / CircleT1Radius);
TFlipperEdge::place_in_grid();
@ -139,12 +139,12 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
{
if (maths::Distance_Squared(ogRay->Origin, T1) >= CircleT1RadiusMSq)
{
srcRay.Direction.Y = lineB.PerpendicularL.Y;
srcRay.Direction.X = lineB.PerpendicularL.X;
srcRay.Direction.Y = lineB.PerpendicularC.Y;
srcRay.Direction.X = lineB.PerpendicularC.X;
if (ballInside == 4)
{
srcRay.Direction.Y = lineA.PerpendicularL.Y;
srcRay.Direction.X = lineA.PerpendicularL.X;
srcRay.Direction.Y = lineA.PerpendicularC.Y;
srcRay.Direction.X = lineA.PerpendicularC.X;
}
srcRay.Direction.X = -srcRay.Direction.X;
srcRay.Direction.Y = -srcRay.Direction.Y;
@ -153,14 +153,14 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
{
srcRay.Direction.X = T1.X - ogRay->Origin.X;
srcRay.Direction.Y = T1.Y - ogRay->Origin.Y;
maths::normalize_2d(&srcRay.Direction);
maths::normalize_2d(srcRay.Direction);
}
}
else
{
srcRay.Direction.X = RotOrigin.X - ogRay->Origin.X;
srcRay.Direction.Y = RotOrigin.Y - ogRay->Origin.Y;
maths::normalize_2d(&srcRay.Direction);
maths::normalize_2d(srcRay.Direction);
}
srcRay.Origin.X = ogRay->Origin.X - srcRay.Direction.X * 5.0f;
@ -170,7 +170,7 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
{
srcRay.Direction.X = RotOrigin.X - ogRay->Origin.X;
srcRay.Direction.Y = RotOrigin.Y - ogRay->Origin.Y;
maths::normalize_2d(&srcRay.Direction);
maths::normalize_2d(srcRay.Direction);
srcRay.Origin.X = ogRay->Origin.X - srcRay.Direction.X * 5.0f;
srcRay.Origin.Y = ogRay->Origin.Y - srcRay.Direction.Y * 5.0f;
if (maths::distance_to_flipper(&srcRay, &dstRay) >= 1e+09f)
@ -200,12 +200,12 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
auto ballInside = is_ball_inside(posX, posY);
if (ballInside != 0)
{
vector_type* linePtr;
vector2* linePtr;
if (FlipperFlag == 1 && ballInside != 5)
{
linePtr = &lineA.PerpendicularL;
srcRay.Direction.Y = lineA.PerpendicularL.Y;
srcRay.Direction.X = lineA.PerpendicularL.X;
linePtr = &lineA.PerpendicularC;
srcRay.Direction.Y = lineA.PerpendicularC.Y;
srcRay.Direction.X = lineA.PerpendicularC.X;
}
else
{
@ -215,7 +215,7 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
CollisionFlag2 = 1;
srcRay.Direction.X = RotOrigin.X - posX;
srcRay.Direction.Y = RotOrigin.Y - posY;
maths::normalize_2d(&srcRay.Direction);
maths::normalize_2d(srcRay.Direction);
srcRay.Origin.X = posX - srcRay.Direction.X * 5.0f;
srcRay.Origin.Y = posY - srcRay.Direction.Y * 5.0f;
@ -235,9 +235,9 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
return 0.0;
}
linePtr = &lineB.PerpendicularL;
srcRay.Direction.Y = lineB.PerpendicularL.Y;
srcRay.Direction.X = lineB.PerpendicularL.X;
linePtr = &lineB.PerpendicularC;
srcRay.Direction.Y = lineB.PerpendicularC.Y;
srcRay.Direction.X = lineB.PerpendicularC.X;
}
CollisionLinePerp = *linePtr;
@ -271,16 +271,16 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray)
NextBallPosition = dstRay.Origin;
NextBallPosition.X -= srcRay.Direction.X * 1e-05f;
NextBallPosition.Y -= srcRay.Direction.Y * 1e-05f;
vector_type* linePtr;
vector2* linePtr;
if (FlipperFlag == 2)
{
linePtr = &lineB.PerpendicularL;
linePtr = &lineB.PerpendicularC;
CollisionFlag1 = AngleMax <= 0.0f;
}
else
{
CollisionFlag1 = AngleMax > 0.0f;
linePtr = &lineA.PerpendicularL;
linePtr = &lineA.PerpendicularC;
}
CollisionLinePerp = *linePtr;
CollisionDirection = dstRay.Direction;
@ -313,7 +313,7 @@ void TFlipperEdge::EdgeCollision(TBall* ball, float coef)
{
float v11;
float v20 = sqrt(distance / DistanceDivSq) * (fabs(AngleMax) / AngleMult);
float dot1 = maths::DotProduct(&CollisionLinePerp, &CollisionDirection);
float dot1 = maths::DotProduct(CollisionLinePerp, CollisionDirection);
if (dot1 >= 0.0f)
v11 = dot1 * v20;
else
@ -395,11 +395,11 @@ void TFlipperEdge::set_control_points(float timeNow)
B1 = B1Src;
B2 = B2Src;
T1 = T1Src;
maths::RotatePt(&A1, flipper_sin_angle, flipper_cos_angle, &RotOrigin);
maths::RotatePt(&A2, flipper_sin_angle, flipper_cos_angle, &RotOrigin);
maths::RotatePt(&T1, flipper_sin_angle, flipper_cos_angle, &RotOrigin);
maths::RotatePt(&B1, flipper_sin_angle, flipper_cos_angle, &RotOrigin);
maths::RotatePt(&B2, flipper_sin_angle, flipper_cos_angle, &RotOrigin);
maths::RotatePt(A1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
maths::RotatePt(A2, flipper_sin_angle, flipper_cos_angle, RotOrigin);
maths::RotatePt(T1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
maths::RotatePt(B1, flipper_sin_angle, flipper_cos_angle, RotOrigin);
maths::RotatePt(B2, flipper_sin_angle, flipper_cos_angle, RotOrigin);
}
void TFlipperEdge::build_edges_in_motion()
@ -435,7 +435,7 @@ float TFlipperEdge::flipper_angle(float timeNow)
int TFlipperEdge::is_ball_inside(float x, float y)
{
vector_type testPoint{};
vector2 testPoint{};
float dx = RotOrigin.X - x;
float dy = RotOrigin.Y - y;
if (((A2.X - A1.X) * (y - A1.Y) - (A2.Y - A1.Y) * (x - A1.X) >= 0.0f &&

View File

@ -8,7 +8,7 @@ class TFlipperEdge : public TEdgeSegment
{
public:
TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime, float collMult,
vector3* origin, vector3* vecT1, vector3* vecT2, float extendTime, float retractTime, float collMult,
float elasticity, float smoothness);
void port_draw() override;
float FindCollisionDistance(ray_type* ray) override;
@ -23,7 +23,7 @@ public:
int FlipperFlag;
float Elasticity;
float Smoothness;
vector_type RotOrigin{};
vector2 RotOrigin{};
float CirclebaseRadius;
float CircleT1Radius;
float CirclebaseRadiusSq;
@ -35,27 +35,27 @@ public:
float Angle1;
int CollisionFlag1;
int CollisionFlag2{};
vector_type CollisionLinePerp{};
vector_type A1Src{};
vector_type A2Src{};
vector_type B1Src{};
vector_type B2Src{};
vector2 CollisionLinePerp{};
vector2 A1Src{};
vector2 A2Src{};
vector2 B1Src{};
vector2 B2Src{};
float CollisionMult;
vector_type T1Src{};
vector_type T2Src{};
vector2 T1Src{};
vector2 T2Src{};
float DistanceDivSq;
float CollisionTimeAdvance;
vector_type CollisionDirection{};
vector2 CollisionDirection{};
int EdgeCollisionFlag;
float InputTime;
float AngleStopTime;
float AngleMult;
float ExtendTime;
float RetractTime;
vector_type NextBallPosition{};
vector2 NextBallPosition{};
static float flipper_sin_angle, flipper_cos_angle;
static vector_type A1, A2, B1, B2, T1;
static vector2 A1, A2, B1, B2, T1;
static line_type lineA, lineB;
static circle_type circlebase, circleT1;
};

View File

@ -31,7 +31,7 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
Circle.RadiusSq = 0.001f;
auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup,
reinterpret_cast<vector_type*>(visual.FloatArr),
reinterpret_cast<vector3*>(visual.FloatArr),
Circle.RadiusSq);
if (tCircle)
{
@ -50,7 +50,6 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
circle.RadiusSq = Circle.RadiusSq;
circle.Center.X = Circle.Center.X;
circle.Center.Y = Circle.Center.Y;
circle.Center.Z = Circle.Center.Z;
Field.Flag2Ptr = &ActiveFlag;
Field.CollisionComp = this;
@ -70,7 +69,7 @@ int THole::Message(int code, float value)
return 0;
}
void THole::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void THole::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (!BallCapturedFlag)
{
@ -94,10 +93,10 @@ void THole::Collision(TBall* ball, vector_type* nextPosition, vector_type* direc
}
}
int THole::FieldEffect(TBall* ball, vector_type* vecDst)
int THole::FieldEffect(TBall* ball, vector2* vecDst)
{
int result;
vector_type direction{};
vector2 direction{};
if (BallCapturedFlag)
{
@ -128,7 +127,7 @@ int THole::FieldEffect(TBall* ball, vector_type* vecDst)
direction.Y = Circle.Center.Y - ball->Position.Y;
if (direction.X * direction.X + direction.Y * direction.Y <= Circle.RadiusSq)
{
maths::normalize_2d(&direction);
maths::normalize_2d(direction);
vecDst->X = direction.X * GravityPull - ball->Acceleration.X * ball->Speed;
vecDst->Y = direction.Y * GravityPull - ball->Acceleration.Y * ball->Speed;
result = 1;

View File

@ -9,9 +9,9 @@ class THole :
public:
THole(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
int FieldEffect(TBall* ball, vector_type* vecDst) override;
int FieldEffect(TBall* ball, vector2* vecDst) override;
static void TimerExpired(int timerId, void* caller);

View File

@ -33,7 +33,7 @@ int TKickback::Message(int code, float value)
return 0;
}
void TKickback::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TKickback::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
if (PinballTable->TiltLockFlag)

View File

@ -7,7 +7,7 @@ class TKickback :
public:
TKickback(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);

View File

@ -36,7 +36,7 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis
if (Circle.RadiusSq == 0.0f)
Circle.RadiusSq = 0.001f;
auto tCircle = new TCircle(this, &ActiveFlag, visual.CollisionGroup,
reinterpret_cast<vector_type*>(visual.FloatArr), Circle.RadiusSq);
reinterpret_cast<vector3*>(visual.FloatArr), Circle.RadiusSq);
if (tCircle)
{
tCircle->place_in_grid();
@ -54,7 +54,6 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis
circle.RadiusSq = Circle.RadiusSq;
circle.Center.X = Circle.Center.X;
circle.Center.Y = Circle.Center.Y;
circle.Center.Z = Circle.Center.Z;
Field.Flag2Ptr = &ActiveFlag;
Field.CollisionComp = this;
Field.Mask = visual.CollisionGroup;
@ -105,7 +104,7 @@ int TKickout::get_scoring(int index)
return index < 5 ? Scores[index] : 0;
}
void TKickout::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (!KickFlag1)
{
@ -129,9 +128,9 @@ void TKickout::Collision(TBall* ball, vector_type* nextPosition, vector_type* di
}
}
int TKickout::FieldEffect(TBall* ball, vector_type* dstVec)
int TKickout::FieldEffect(TBall* ball, vector2* dstVec)
{
vector_type direction{};
vector2 direction{};
if (KickFlag1)
return 0;
@ -139,7 +138,7 @@ int TKickout::FieldEffect(TBall* ball, vector_type* dstVec)
direction.Y = Circle.Center.Y - ball->Position.Y;
if (direction.Y * direction.Y + direction.X * direction.X > Circle.RadiusSq)
return 0;
maths::normalize_2d(&direction);
maths::normalize_2d(direction);
dstVec->X = direction.X * FieldMult - ball->Acceleration.X * ball->Speed;
dstVec->Y = direction.Y * FieldMult - ball->Acceleration.Y * ball->Speed;
return 1;

View File

@ -11,9 +11,9 @@ public:
int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
int FieldEffect(TBall* ball, vector_type* vecDst) override;
int FieldEffect(TBall* ball, vector2* vecDst) override;
static void TimerExpired(int timerId, void* caller);
static void ResetTimerExpired(int timerId, void* caller);
@ -28,7 +28,7 @@ public:
float FieldMult;
circle_type Circle{};
float OriginalBallZ{};
vector_type BallAcceleration{};
vector3 BallAcceleration{};
float ThrowAngleMult;
float ThrowSpeedMult1;
float ThrowSpeedMult2;

View File

@ -34,7 +34,7 @@ int TLightRollover::Message(int code, float value)
return 0;
}
void TLightRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TLightRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
ball->Position.X = nextPosition->X;

View File

@ -8,7 +8,7 @@ public:
TLightRollover(TPinballTable* table, int groupIndex);
~TLightRollover() override = default;
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void delay_expired(int timerId, void* caller);

View File

@ -14,20 +14,20 @@ TLine::TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collis
maths::line_init(&Line, x0, y0, x1, y1);
}
TLine::TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, struct vector_type* start,
struct vector_type* end) : TEdgeSegment(collCmp, activeFlag, collisionGroup)
TLine::TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, const vector2& start,
const vector2& end) : TEdgeSegment(collCmp, activeFlag, collisionGroup)
{
X0 = start->X;
Y0 = start->Y;
X1 = end->X;
Y1 = end->Y;
X0 = start.X;
Y0 = start.Y;
X1 = end.X;
Y1 = end.Y;
maths::line_init(&Line, X0, Y0, X1, Y1);
}
void TLine::Offset(float offset)
{
float offX = offset * Line.PerpendicularL.X;
float offY = offset * Line.PerpendicularL.Y;
float offX = offset * Line.PerpendicularC.X;
float offY = offset * Line.PerpendicularC.Y;
X0 += offX;
Y0 += offY;
@ -46,7 +46,7 @@ void TLine::EdgeCollision(TBall* ball, float coef)
CollisionComponent->Collision(
ball,
&Line.RayIntersect,
&Line.PerpendicularL,
&Line.PerpendicularC,
coef,
this);
}

View File

@ -9,7 +9,7 @@ public:
line_type Line{};
float X0, Y0, X1, Y1;
TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, float x0, float y0, float x1, float y1);
TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, vector_type* start, vector_type* end);
TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, const vector2& start, const vector2& end);
void Offset(float offset);
float FindCollisionDistance(ray_type* ray) override;
void EdgeCollision(TBall* ball, float coef) override;

View File

@ -11,7 +11,7 @@
TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{
visualStruct visual{};
vector_type linePt1{}, linePt2{};
vector2 linePt1{}, linePt2{};
loader::query_visual(groupIndex, 0, &visual);
if (visual.FloatArrCount == 2)
@ -21,7 +21,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab
linePt1.X = visual.FloatArr[2];
linePt1.Y = visual.FloatArr[3];
auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt2, &linePt1);
auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, linePt2, linePt1);
if (line)
{
line->Offset(table->CollisionCompOffset);
@ -29,7 +29,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab
EdgeList.push_back(line);
}
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2);
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, linePt1, linePt2);
Line = line;
if (line)
{
@ -40,7 +40,7 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab
}
}
void TOneway::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TOneway::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (edge == Line)
{

View File

@ -8,7 +8,7 @@ class TOneway : public TCollisionComponent
public:
TOneway(TPinballTable* table, int groupIndex);
~TOneway() override = default;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;

View File

@ -59,7 +59,7 @@ TPinballComponent::TPinballComponent(TPinballTable* table, int groupIndex, bool
tmpRect.YPosition = bmp->YPosition - table->YOffset;
tmpRect.Width = bmp->Width;
tmpRect.Height = bmp->Height;
maths::enclosing_box(&bmp1Rect, &tmpRect, &bmp1Rect);
maths::enclosing_box(bmp1Rect, tmpRect, bmp1Rect);
}
RenderSprite = render::create_sprite(

View File

@ -617,7 +617,7 @@ void TPinballTable::replay_timer_callback(int timerId, void* caller)
void TPinballTable::tilt_timeout(int timerId, void* caller)
{
auto table = static_cast<TPinballTable*>(caller);
vector_type vec{};
vector2 vec{};
table->TiltTimeoutTimer = 0;
if (table->TiltLockFlag)

View File

@ -33,7 +33,7 @@ TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(t
table->PlungerPositionY = floatArr[1];
}
void TPlunger::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TPlunger::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (PinballTable->TiltLockFlag)
Message(1017, 0.0);

View File

@ -7,7 +7,7 @@ class TPlunger :
public:
TPlunger(TPinballTable* table, int groupIndex);
~TPlunger() override = default;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
int Message(int code, float value) override;

View File

@ -62,7 +62,7 @@ int TPopupTarget::get_scoring(int index)
return index < 3 ? Scores[index] : 0;
}
void TPopupTarget::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
if (this->PinballTable->TiltLockFlag)

View File

@ -9,7 +9,7 @@ public:
int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);

View File

@ -14,7 +14,7 @@
TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{
visualStruct visual{};
vector_type end{}, start{}, *end2, *start2, *start3, *end3;
vector2 end{}, start{}, end2{}, start2{}, start3{}, end3{};
MessageField = 0;
UnusedBaseFlag = 1;
@ -33,7 +33,7 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
end.Y = floatArr4[3];
start.X = floatArr4[4];
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.push_back(Line1);
if (Line1)
{
@ -49,8 +49,8 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
RampPlane,
RampPlaneCount,
reinterpret_cast<wall_point_type*>(floatArr5WallPoint + 3),
&end2,
&start2);
end2,
start2);
Line2 = new TLine(this, &ActiveFlag, CollisionGroup, start2, end2);
EdgeList.push_back(Line2);
if (Line2)
@ -67,8 +67,8 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
RampPlane,
RampPlaneCount,
reinterpret_cast<wall_point_type*>(floatArr6WallPoint + 3),
&end3,
&start3);
end3,
start3);
Line3 = new TLine(this, &ActiveFlag, CollisionGroup, start3, end3);
EdgeList.push_back(Line3);
if (Line3)
@ -84,20 +84,17 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
auto xMax = -1000000000.0f;
for (auto index = 0; index < RampPlaneCount; index++)
{
auto plane = &RampPlane[index];
auto pVec1 = reinterpret_cast<vector_type*>(&plane->V1);
auto pVec2 = reinterpret_cast<vector_type*>(&plane->V2);
auto pVec3 = reinterpret_cast<vector_type*>(&plane->V3);
auto& plane = RampPlane[index];
vector2* pointOrder[4] = { &plane.V1, &plane.V2, &plane.V3, &plane.V1 };
xMin = std::min(std::min(std::min(plane->V3.X, plane->V1.X), plane->V2.X), xMin);
yMin = std::min(std::min(std::min(plane->V3.Y, plane->V1.Y), plane->V2.Y), xMin); // Sic
xMax = std::max(std::max(std::max(plane->V3.X, plane->V1.X), plane->V2.X), xMin);
yMax = std::max(std::max(std::max(plane->V3.Y, plane->V1.Y), plane->V2.Y), xMin);
vector_type* pointOrder[4] = {pVec1, pVec2, pVec3, pVec1};
xMin = std::min(std::min(std::min(plane.V3.X, plane.V1.X), plane.V2.X), xMin);
yMin = std::min(std::min(std::min(plane.V3.Y, plane.V1.Y), plane.V2.Y), xMin); // Sic
xMax = std::max(std::max(std::max(plane.V3.X, plane.V1.X), plane.V2.X), xMin);
yMax = std::max(std::max(std::max(plane.V3.Y, plane.V1.Y), plane.V2.Y), xMin);
for (auto pt = 0; pt < 3; pt++)
{
auto point1 = pointOrder[pt], point2 = pointOrder[pt + 1];
auto& point1 = *pointOrder[pt], point2 = *pointOrder[pt + 1];
auto collisionGroup = 0;
if (point1 != end2 || point2 != start2)
{
@ -120,15 +117,15 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
EdgeList.push_back(line);
if (line)
{
line->WallValue = plane;
line->WallValue = &plane;
line->place_in_grid();
}
}
}
plane->FieldForce.X = cos(plane->GravityAngle2) * sin(plane->GravityAngle1) *
plane.FieldForce.X = cos(plane.GravityAngle2) * sin(plane.GravityAngle1) *
PinballTable->GravityDirVectMult;
plane->FieldForce.Y = sin(plane->GravityAngle2) * sin(plane->GravityAngle1) *
plane.FieldForce.Y = sin(plane.GravityAngle2) * sin(plane.GravityAngle1) *
PinballTable->GravityDirVectMult;
}
@ -154,7 +151,7 @@ int TRamp::get_scoring(int index)
return index < 4 ? Scores[index] : 0;
}
void TRamp::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
ball->not_again(edge);
ball->Position.X = nextPosition->X;
@ -204,7 +201,7 @@ void TRamp::Collision(TBall* ball, vector_type* nextPosition, vector_type* direc
}
}
int TRamp::FieldEffect(TBall* ball, vector_type* vecDst)
int TRamp::FieldEffect(TBall* ball, vector2* vecDst)
{
vecDst->X = ball->RampFieldForce.X - ball->Acceleration.X * ball->Speed * BallFieldMult;
vecDst->Y = ball->RampFieldForce.Y - ball->Acceleration.Y * ball->Speed * BallFieldMult;

View File

@ -12,9 +12,9 @@ public:
TRamp(TPinballTable* table, int groupIndex);
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
int FieldEffect(TBall* ball, vector_type* vecDst) override;
int FieldEffect(TBall* ball, vector2* vecDst) override;
void port_draw() override;
int Scores[4]{};

View File

@ -37,7 +37,7 @@ int TRollover::Message(int code, float value)
return 0;
}
void TRollover::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
ball->Position.X = nextPosition->X;

View File

@ -10,7 +10,7 @@ public:
TRollover(TPinballTable* table, int groupIndex);
~TRollover() override = default;
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;

View File

@ -75,7 +75,7 @@ int TSink::get_scoring(int index)
return index < 3 ? Scores[index] : 0;
}
void TSink::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TSink::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
Timer = 0;
if (PinballTable->TiltLockFlag)

View File

@ -10,15 +10,15 @@ public:
int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);
int Timer;
float TimerTime;
vector_type BallPosition{};
vector_type BallAcceleration{};
vector2 BallPosition{};
vector3 BallAcceleration{};
float ThrowAngleMult;
float ThrowSpeedMult1;
float ThrowSpeedMult2;

View File

@ -64,7 +64,7 @@ int TSoloTarget::get_scoring(int index)
return index < 1 ? Scores[index] : 0;
}
void TSoloTarget::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
if (DefaultCollision(ball, nextPosition, direction))

View File

@ -9,7 +9,7 @@ public:
int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);

View File

@ -111,7 +111,7 @@ TTableLayer::~TTableLayer()
delete edge_manager;
}
int TTableLayer::FieldEffect(TBall* ball, vector_type* vecDst)
int TTableLayer::FieldEffect(TBall* ball, vector2* vecDst)
{
vecDst->X = GraityDirX - (0.5f - RandFloat() + ball->Acceleration.X) *
ball->Speed * GraityMult;
@ -161,7 +161,7 @@ void TTableLayer::edges_insert_square(float y0, float x0, float y1, float x1, TE
void TTableLayer::edges_insert_circle(circle_type* circle, TEdgeSegment* edge, field_effect_type* field)
{
ray_type ray{};
vector_type vec1{};
vector2 vec1{};
auto radiusM = sqrt(circle->RadiusSq) + edge_manager->AdvanceX * 0.001f;
auto radiusMSq = radiusM * radiusM;
@ -220,45 +220,45 @@ void TTableLayer::edges_insert_circle(circle_type* circle, TEdgeSegment* edge, f
ray.Direction.X = 1.0;
ray.Direction.Y = 0.0;
ray.MaxDistance = edge_manager->AdvanceX;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.X = -1.0;
ray.Origin.X = ray.Origin.X + edge_manager->AdvanceX;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.X = 0.0;
ray.Direction.Y = 1.0;
ray.MaxDistance = edge_manager->AdvanceY;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.Y = -1.0;
ray.Origin.Y = ray.Origin.Y + edge_manager->AdvanceY;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.Y = 0.0;
ray.Direction.X = -1.0;
ray.MaxDistance = edge_manager->AdvanceX;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.X = 1.0;
ray.Origin.X = ray.Origin.X - edge_manager->AdvanceX;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.X = 0.0;
ray.Direction.Y = -1.0;
ray.MaxDistance = edge_manager->AdvanceY;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
ray.Direction.Y = 1.0;
ray.Origin.Y = ray.Origin.Y - edge_manager->AdvanceY;
if (maths::ray_intersect_circle(&ray, circle) < 1000000000.0f)
if (maths::ray_intersect_circle(ray, *circle) < 1000000000.0f)
break;
collision = false;

View File

@ -14,7 +14,7 @@ class TTableLayer :
public:
TTableLayer(TPinballTable* table);
~TTableLayer() override;
int FieldEffect(TBall* ball, vector_type* vecDst) override;
int FieldEffect(TBall* ball, vector2* vecDst) override;
static void edges_insert_square(float y0, float x0, float y1, float x1, TEdgeSegment* edge,
field_effect_type* field);

View File

@ -10,7 +10,7 @@ TTripwire::TTripwire(TPinballTable* table, int groupIndex) : TRollover(table, gr
{
}
void TTripwire::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void TTripwire::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge)
{
ball->Position.X = nextPosition->X;

View File

@ -7,6 +7,6 @@ class TTripwire :
public:
TTripwire(TPinballTable* table, int groupIndex);
~TTripwire() override = default;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
};

View File

@ -24,7 +24,7 @@ int TWall::Message(int code, float value)
return 0;
}
void TWall::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
void TWall::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge)
{
if (DefaultCollision(ball, nextPosition, direction))
{

View File

@ -10,7 +10,7 @@ class TWall :
public:
TWall(TPinballTable* table, int groupIndex);
int Message(int code, float value) override;
void Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef,
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef,
TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;

View File

@ -55,7 +55,9 @@
// SDL
#include <SDL.h>
#ifdef _WIN32
#include <SDL_syswm.h>
#endif
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif

View File

@ -396,7 +396,7 @@ int loader::kicker(int groupIndex, visualKickerStruct* kicker)
kicker->ThrowBallMult = *floatArr;
break;
case 404:
kicker->ThrowBallAcceleration = *reinterpret_cast<vector_type*>(floatArr);
kicker->ThrowBallAcceleration = *reinterpret_cast<vector3*>(floatArr);
floatArr += 3;
index += 4;
break;

View File

@ -25,7 +25,7 @@ struct visualKickerStruct
float Threshold;
float Boost;
float ThrowBallMult;
vector_type ThrowBallAcceleration;
vector3 ThrowBallAcceleration;
float ThrowBallAngleMult;
int HardHitSoundId;
};

View File

@ -5,163 +5,125 @@
#include "TFlipperEdge.h"
void maths::enclosing_box(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect)
// Performs AABB merge, creating rect that is just large enough to contain both source rects.
void maths::enclosing_box(const rectangle_type& rect1, const rectangle_type& rect2, rectangle_type& dstRect)
{
int xPos1 = rect1->XPosition;
int yPos1 = rect1->YPosition;
int width1 = rect1->Width;
int height1 = rect1->Height;
int xPos2 = rect2->XPosition;
bool rect2XPosLessRect1 = rect2->XPosition < rect1->XPosition;
int yPos2 = rect2->YPosition;
int width2 = rect2->Width;
int height2 = rect2->Height;
int xPos2_2 = rect2->XPosition;
if (rect2XPosLessRect1)
auto xPos = rect1.XPosition, width = rect1.Width;
if (rect2.XPosition < rect1.XPosition)
{
width1 += xPos1 - xPos2;
xPos1 = xPos2;
xPos = rect2.XPosition;
width += rect1.XPosition - rect2.XPosition;
}
if (yPos2 < yPos1)
auto yPos = rect1.YPosition, height = rect1.Height;
if (rect2.YPosition < rect1.YPosition)
{
height1 += yPos1 - yPos2;
yPos1 = yPos2;
yPos = rect2.YPosition;
height += rect1.YPosition - rect2.YPosition;
}
if (width2 + xPos2 > xPos1 + width1)
width1 = xPos2_2 + width2 - xPos1;
int height1_2 = height1;
if (height2 + yPos2 > height1 + yPos1)
height1_2 = yPos2 + height2 - yPos1;
dstRect->YPosition = yPos1;
dstRect->Height = height1_2;
dstRect->XPosition = xPos1;
dstRect->Width = width1;
auto xEnd2 = rect2.XPosition + rect2.Width;
if (xEnd2 > xPos + width)
width = xEnd2 - xPos;
auto yEnd2 = rect2.YPosition + rect2.Height;
if (yEnd2 > yPos + height)
height = yEnd2 - yPos;
dstRect.XPosition = xPos;
dstRect.YPosition = yPos;
dstRect.Width = width;
dstRect.Height = height;
}
int maths::rectangle_clip(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect)
// Creates rect that represents an intersection of rect1 and rect2.
// Return true when intersection exists.
bool maths::rectangle_clip(const rectangle_type& rect1, const rectangle_type& rect2, rectangle_type* dstRect)
{
int xPos1 = rect1->XPosition;
int yPos1 = rect1->YPosition;
int height1 = rect1->Height;
int xRight2 = rect2->XPosition + rect2->Width;
int width1 = rect1->Width;
int yRight2 = rect2->YPosition + rect2->Height;
if (xPos1 + width1 < rect2->XPosition)
auto xEnd2 = rect2.XPosition + rect2.Width;
if (rect2.XPosition >= rect1.XPosition + rect1.Width || rect1.XPosition >= xEnd2)
return 0;
if (xPos1 >= xRight2)
auto yEnd2 = rect2.YPosition + rect2.Height;
if (rect2.YPosition >= rect1.YPosition + rect1.Height || rect1.YPosition >= yEnd2)
return 0;
int yPos2 = yPos1;
if (yPos1 + height1 < rect2->YPosition || yPos1 >= yRight2)
return 0;
if (xPos1 < rect2->XPosition)
auto xPos = rect1.XPosition, width = rect1.Width;
if (rect1.XPosition < rect2.XPosition)
{
width1 += xPos1 - rect2->XPosition;
xPos1 = rect2->XPosition;
xPos = rect2.XPosition;
width += rect1.XPosition - rect2.XPosition;
}
if (xPos1 + width1 > xRight2)
width1 = xRight2 - xPos1;
int height2 = height1;
if (yPos1 < rect2->YPosition)
auto yPos = rect1.YPosition, height = rect1.Height;
if (rect1.YPosition < rect2.YPosition)
{
height2 = yPos1 - rect2->YPosition + height1;
yPos2 = rect2->YPosition;
yPos = rect2.YPosition;
height += rect1.YPosition - rect2.YPosition;
}
if (height2 + yPos2 > yRight2)
height2 = yRight2 - yPos2;
if (!width1 || !height2)
return 0;
if (xPos + width > xEnd2)
width = xEnd2 - xPos;
if (yPos + height > yEnd2)
height = yEnd2 - yPos;
if (width == 0 || height == 0)
return false;
if (dstRect)
{
dstRect->XPosition = xPos1;
dstRect->YPosition = yPos2;
dstRect->Width = width1;
dstRect->Height = height2;
dstRect->XPosition = xPos;
dstRect->YPosition = yPos;
dstRect->Width = width;
dstRect->Height = height;
}
return 1;
return true;
}
int maths::overlapping_box(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect)
{
int v3;
int v4;
int v6;
int v7;
if (rect1->XPosition >= rect2->XPosition)
{
dstRect->XPosition = rect2->XPosition;
v3 = rect1->Width - rect2->XPosition;
v4 = rect1->XPosition;
}
else
{
dstRect->XPosition = rect1->XPosition;
v3 = rect2->Width - rect1->XPosition;
v4 = rect2->XPosition;
}
dstRect->Width = v3 + v4 + 1;
int v5 = rect1->YPosition;
if (v5 >= rect2->YPosition)
{
dstRect->YPosition = rect2->YPosition;
v6 = rect1->Height - rect2->YPosition;
v7 = rect1->YPosition;
}
else
{
dstRect->YPosition = v5;
v6 = rect2->Height - rect1->YPosition;
v7 = rect2->YPosition;
}
dstRect->Height = v6 + v7 + 1;
return dstRect->Width <= rect2->Width + rect1->Width && dstRect->Height <= rect2->Height + rect1->Height;
}
float maths::ray_intersect_circle(ray_type* ray, circle_type* circle)
// Returns the distance from ray origin to the first ray-circle intersection point.
float maths::ray_intersect_circle(const ray_type& ray, const circle_type& circle)
{
// O - ray origin
// D - ray direction
// C - circle center
// R - circle radius
// L, C - O, vector between O and C
float Lx = circle->Center.X - ray->Origin.X;
float Ly = circle->Center.Y - ray->Origin.Y;
auto L = vector_sub(circle.Center, ray.Origin);
// Tca, L dot D, projection of L on D
float Tca = Ly * ray->Direction.Y + Lx * ray->Direction.X;
float Tca = DotProduct(L, ray.Direction);
if (Tca < 0.0f) // No intersection if Tca is negative
return 1000000000.0f;
// L dot L, distance from ray origin to circle center
float LMagSq = Ly * Ly + Lx * Lx;
float LMagSq = DotProduct(L, L);
// If ray origin is inside of the circle
// T0 = Tca - Sqrt(rad^2 - d^2). d = sqrt(L dot L - Tca dot Tca)
if (LMagSq < circle->RadiusSq)
return Tca - sqrt(circle->RadiusSq - LMagSq + Tca * Tca);
// Thc^2 = rad^2 - d = rad^2 - L dot L + Tca dot Tca
float ThcSq = circle->RadiusSq - LMagSq + Tca * Tca;
if (ThcSq < 0.0f) // No intersection if Thc is negative
return 1000000000.0f;
// Thc^2 = rad^2 - d^2; d = sqrt(L dot L - Tca * Tca)
float ThcSq = circle.RadiusSq - LMagSq + Tca * Tca;
// T0 = Tca - Thc, distance from origin to first intersection
// If ray origin is inside of the circle, then T0 is negative
if (LMagSq < circle.RadiusSq)
return Tca - sqrt(ThcSq);
// No intersection if ThcSq is negative, that is if d > rad
if (ThcSq < 0.0f)
return 1000000000.0f;
// T0 should be positive and less that max ray distance
float T0 = Tca - sqrt(ThcSq);
if (T0 < 0.0f || T0 > ray->MaxDistance)
if (T0 < 0.0f || T0 > ray.MaxDistance)
return 1000000000.0f;
return T0;
}
float maths::normalize_2d(vector_type* vec)
float maths::normalize_2d(vector2& vec)
{
float mag = sqrt(vec->X * vec->X + vec->Y * vec->Y);
float mag = sqrt(vec.X * vec.X + vec.Y * vec.Y);
if (mag != 0.0f)
{
vec->X = 1.0f / mag * vec->X;
vec->Y = 1.0f / mag * vec->Y;
vec.X /= mag;
vec.Y /= mag;
}
return mag;
}
@ -169,93 +131,75 @@ float maths::normalize_2d(vector_type* vec)
void maths::line_init(line_type* line, float x0, float y0, float x1, float y1)
{
float v9;
bool lineDirection;
float v11;
line->Origin = { x0, y0 };
line->Direction.X = x1 - x0;
line->Direction.Y = y1 - y0;
normalize_2d(&line->Direction);
line->PerpendicularL.X = line->Direction.Y;
line->PerpendicularL.Y = -line->Direction.X;
line->PreComp1 = -(line->Direction.Y * x0) + line->Direction.X * y0;
if (line->Direction.X >= 0.000000001f || line->Direction.X <= -0.000000001f)
{
v9 = x1;
lineDirection = x0 >= x1;
v11 = x0;
}
else
normalize_2d(line->Direction);
// Clockwise perpendicular to the line direction vector
line->PerpendicularC = { line->Direction.Y, -line->Direction.X };
auto lineStart = x0, lineEnd = x1;
if (std::abs(line->Direction.X) < 0.000000001f)
{
line->Direction.X = 0.0;
v9 = y1;
lineDirection = y0 >= y1;
v11 = y0;
}
if (lineDirection)
{
line->OriginX = v9;
line->OriginY = v11;
}
else
{
line->OriginY = v9;
line->OriginX = v11;
lineStart = y0;
lineEnd = y1;
}
line->MinCoord = std::min(lineStart, lineEnd);
line->MaxCoord = std::max(lineStart, lineEnd);
}
// Returns the distance from ray origin to the ray-line segment intersection point.
float maths::ray_intersect_line(ray_type* ray, line_type* line)
{
bool v5;
bool v6;
// V1 vector between ray origin and line origin
// V2 ray direction
// V3 line perpendicular clockwise
auto v1 = vector_sub(ray->Origin, line->Origin);
auto v2 = line->Direction;
auto v3 = vector2{ -ray->Direction.Y, ray->Direction.X };
float perpDot = line->PerpendicularL.Y * ray->Direction.Y + ray->Direction.X * line->PerpendicularL.X;
if (perpDot < 0.0f)
// Project line on ray perpendicular, no intersection if ray is pointing away from the line
auto v2DotV3 = DotProduct(v2, v3);
if (v2DotV3 < 0.0f)
{
float result = -((ray->Origin.X * line->PerpendicularL.X + ray->Origin.Y * line->PerpendicularL.Y + line->
PreComp1)
/ perpDot);
if (result >= -ray->MinDistance && result <= ray->MaxDistance)
// Distance to the intersect point: (V2 X V1) / (V2 dot V3)
auto distance = cross(v2, v1) / v2DotV3;
if (distance >= -ray->MinDistance && distance <= ray->MaxDistance)
{
line->RayIntersect.X = result * ray->Direction.X + ray->Origin.X;
float v4 = result * ray->Direction.Y + ray->Origin.Y;
line->RayIntersect.Y = v4;
if (line->Direction.X == 0.0f)
line->RayIntersect.X = distance * ray->Direction.X + ray->Origin.X;
line->RayIntersect.Y = distance * ray->Direction.Y + ray->Origin.Y;
// Check if intersection point is inside line segment
auto testPoint = line->Direction.X != 0.0f ? line->RayIntersect.X : line->RayIntersect.Y;
if (testPoint >= line->MinCoord && testPoint <= line->MaxCoord)
{
if (v4 >= line->OriginX)
{
v5 = v4 < line->OriginY;
v6 = v4 == line->OriginY;
if (v5 || v6)
return result;
return 1000000000.0;
}
}
else if (line->OriginX <= line->RayIntersect.X)
{
float v7 = line->RayIntersect.X;
v5 = v7 < line->OriginY;
v6 = v7 == line->OriginY;
if (v5 || v6)
return result;
return 1000000000.0;
return distance;
}
}
}
return 1000000000.0;
}
void maths::cross(vector_type* vec1, vector_type* vec2, vector_type* dstVec)
void maths::cross(const vector3& vec1, const vector3& vec2, vector3& dstVec)
{
dstVec->X = vec2->Z * vec1->Y - vec2->Y * vec1->Z;
dstVec->Y = vec2->X * vec1->Z - vec1->X * vec2->Z;
dstVec->Z = vec1->X * vec2->Y - vec2->X * vec1->Y;
dstVec.X = vec2.Z * vec1.Y - vec2.Y * vec1.Z;
dstVec.Y = vec2.X * vec1.Z - vec1.X * vec2.Z;
dstVec.Z = vec1.X * vec2.Y - vec2.X * vec1.Y;
}
float maths::magnitude(vector_type* vec)
float maths::cross(const vector2& vec1, const vector2& vec2)
{
return vec1.X * vec2.Y - vec1.Y * vec2.X;
}
float maths::magnitude(const vector3& vec)
{
float result;
auto magSq = vec->X * vec->X + vec->Y * vec->Y + vec->Z * vec->Z;
auto magSq = vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z;
if (magSq == 0.0f)
result = 0.0;
else
@ -263,13 +207,18 @@ float maths::magnitude(vector_type* vec)
return result;
}
void maths::vector_add(vector_type* vec1Dst, vector_type* vec2)
void maths::vector_add(vector2& vec1Dst, const vector2& vec2)
{
vec1Dst->X += vec2->X;
vec1Dst->Y += vec2->Y;
vec1Dst.X += vec2.X;
vec1Dst.Y += vec2.Y;
}
float maths::basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity, float smoothness,
vector2 maths::vector_sub(const vector2& vec1, const vector2& vec2)
{
return { vec1.X - vec2.X, vec1.Y - vec2.Y };
}
float maths::basic_collision(TBall* ball, vector2* nextPosition, vector2* direction, float elasticity, float smoothness,
float threshold, float boost)
{
ball->Position.X = nextPosition->X;
@ -285,7 +234,7 @@ float maths::basic_collision(TBall* ball, vector_type* nextPosition, vector_type
float dy1 = proj * direction->Y;
ball->Acceleration.X = (dx1 + ball->Acceleration.X) * smoothness + dx1 * elasticity;
ball->Acceleration.Y = (dy1 + ball->Acceleration.Y) * smoothness + dy1 * elasticity;
normalize_2d(&ball->Acceleration);
normalize_2d(ball->Acceleration);
}
float projSpeed = proj * ball->Speed;
float newSpeed = ball->Speed - (1.0f - elasticity) * projSpeed;
@ -294,33 +243,26 @@ float maths::basic_collision(TBall* ball, vector_type* nextPosition, vector_type
{
ball->Acceleration.X = newSpeed * ball->Acceleration.X + direction->X * boost;
ball->Acceleration.Y = newSpeed * ball->Acceleration.Y + direction->Y * boost;
ball->Speed = normalize_2d(&ball->Acceleration);
ball->Speed = normalize_2d(ball->Acceleration);
}
return projSpeed;
}
float maths::Distance_Squared(vector_type& vec1, vector_type& vec2)
float maths::Distance_Squared(const vector2& vec1, const vector2& vec2)
{
return (vec1.Y - vec2.Y) * (vec1.Y - vec2.Y) + (vec1.X - vec2.X) * (vec1.X - vec2.X);
auto dx = vec1.X - vec2.X;
auto dy = vec1.Y - vec2.Y;
return dy * dy + dx * dx;
}
float maths::DotProduct(vector_type* vec1, vector_type* vec2)
float maths::DotProduct(const vector2& vec1, const vector2& vec2)
{
return vec1->Y * vec2->Y + vec1->X * vec2->X;
return vec1.X * vec2.X + vec1.Y * vec2.Y;
}
void maths::vswap(vector_type* vec1, vector_type* vec2)
float maths::Distance(const vector2& vec1, const vector2& vec2)
{
vector_type tmp = *vec1;
*vec1 = *vec2;
*vec2 = tmp;
}
float maths::Distance(vector_type* vec1, vector_type* vec2)
{
auto dx = vec1->X - vec2->X;
auto dy = vec1->Y - vec2->Y;
return sqrt(dy * dy + dx * dx);
return sqrt(Distance_Squared(vec1, vec2));
}
void maths::SinCos(float angle, float* sinOut, float* cosOut)
@ -329,12 +271,12 @@ void maths::SinCos(float angle, float* sinOut, float* cosOut)
*cosOut = cos(angle);
}
void maths::RotatePt(vector_type* point, float sin, float cos, vector_type* origin)
void maths::RotatePt(vector2& point, float sin, float cos, const vector2& origin)
{
auto dirX = point->X - origin->X;
auto dirY = point->Y - origin->Y;
point->X = dirX * cos - dirY * sin + origin->X;
point->Y = dirX * sin + dirY * cos + origin->Y;
auto dirX = point.X - origin.X;
auto dirY = point.Y - origin.Y;
point.X = dirX * cos - dirY * sin + origin.X;
point.Y = dirX * sin + dirY * cos + origin.Y;
}
float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
@ -347,13 +289,13 @@ float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
distance = newDistance;
distanceType = 0;
}
newDistance = ray_intersect_circle(ray1, &TFlipperEdge::circlebase);
newDistance = ray_intersect_circle(*ray1, TFlipperEdge::circlebase);
if (newDistance < distance)
{
distance = newDistance;
distanceType = 2;
}
newDistance = ray_intersect_circle(ray1, &TFlipperEdge::circleT1);
newDistance = ray_intersect_circle(*ray1, TFlipperEdge::circleT1);
if (newDistance < distance)
{
distance = newDistance;
@ -370,7 +312,7 @@ float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
if (distanceType != -1)
{
vector_type* nextOrigin;
vector2* nextOrigin;
if (distanceType)
{
if (distanceType != 1)
@ -389,15 +331,15 @@ float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
dirY = ray2->Origin.Y - TFlipperEdge::circleT1.Center.Y;
}
ray2->Direction.Y = dirY;
normalize_2d(&ray2->Direction);
normalize_2d(ray2->Direction);
return distance;
}
ray2->Direction = TFlipperEdge::lineB.PerpendicularL;
ray2->Direction = TFlipperEdge::lineB.PerpendicularC;
nextOrigin = &TFlipperEdge::lineB.RayIntersect;
}
else
{
ray2->Direction = TFlipperEdge::lineA.PerpendicularL;
ray2->Direction = TFlipperEdge::lineA.PerpendicularC;
nextOrigin = &TFlipperEdge::lineA.RayIntersect;
}
ray2->Origin = *nextOrigin;
@ -406,22 +348,24 @@ float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
return 1000000000.0;
}
void maths::RotateVector(vector_type* vec, float angle)
void maths::RotateVector(vector2& vec, float angle)
{
float s = sin(angle), c = cos(angle);
vec->X = c * vec->X - s * vec->Y;
vec->Y = s * vec->X + c * vec->Y;
vec.X = c * vec.X - s * vec.Y;
vec.Y = s * vec.X + c * vec.Y;
/* Error in the original, should be:
* tmp = c * vec->X - s * vec->Y;
* vec->Y = s * vec->X + c * vec->Y;
* vec->X = tmp
* auto newX = c * vec.X - s * vec.Y;
* vec.Y = s * vec.X + c * vec.Y;
* vec.X = newX;
*/
// Original code rotates the point on a figure eight curve.
// Luckily, it is never used with angle always set to 0.
}
void maths::find_closest_edge(ramp_plane_type* plane, int planeCount, wall_point_type* wall, vector_type** lineEnd,
vector_type** lineStart)
void maths::find_closest_edge(ramp_plane_type* planes, int planeCount, wall_point_type* wall, vector2& lineEnd,
vector2& lineStart)
{
vector_type wallEnd{}, wallStart{};
vector2 wallEnd{}, wallStart{};
wallStart.X = wall->X0;
wallStart.Y = wall->Y0;
@ -429,35 +373,22 @@ void maths::find_closest_edge(ramp_plane_type* plane, int planeCount, wall_point
wallEnd.X = wall->X1;
float maxDistance = 1000000000.0f;
ramp_plane_type* planePtr = plane;
for (auto index = 0; index < planeCount; index++)
{
auto vec1 = reinterpret_cast<vector_type*>(&planePtr->V1),
vec2 = reinterpret_cast<vector_type*>(&planePtr->V2),
vec3 = reinterpret_cast<vector_type*>(&planePtr->V3);
auto distance = Distance(&wallStart, vec1) + Distance(&wallEnd, vec2);
if (distance < maxDistance)
{
maxDistance = distance;
*lineEnd = vec1;
*lineStart = vec2;
}
auto& plane = planes[index];
vector2* pointOrder[4] = { &plane.V1, &plane.V2, &plane.V3, &plane.V1 };
distance = Distance(&wallStart, vec2) + Distance(&wallEnd, vec3);
if (distance < maxDistance)
for (auto pt = 0; pt < 3; pt++)
{
maxDistance = distance;
*lineEnd = vec2;
*lineStart = vec3;
}
auto& point1 = *pointOrder[pt], point2 = *pointOrder[pt + 1];
distance = Distance(&wallStart, vec3) + Distance(&wallEnd, vec1);
if (distance < maxDistance)
{
maxDistance = distance;
*lineEnd = vec3;
*lineStart = vec1;
auto distance = Distance(wallStart, point1) + Distance(wallEnd, point2);
if (distance < maxDistance)
{
maxDistance = distance;
lineEnd = point1;
lineStart = point2;
}
}
++planePtr;
}
}

View File

@ -2,13 +2,25 @@
class TBall;
struct vector_type
struct vector2
{
float X;
float Y;
float Z;
bool operator==(const vector2& vec)
{
return X == vec.X && Y == vec.Y;
}
bool operator!=(const vector2& vec)
{
return X != vec.X || Y != vec.Y;
}
};
struct vector3 :vector2
{
float Z;
};
struct rectangle_type
{
@ -20,14 +32,14 @@ struct rectangle_type
struct circle_type
{
vector_type Center;
vector2 Center;
float RadiusSq;
};
struct ray_type
{
vector_type Origin;
vector_type Direction;
vector2 Origin;
vector2 Direction;
float MaxDistance;
float MinDistance;
float TimeNow;
@ -37,18 +49,12 @@ struct ray_type
struct line_type
{
vector_type PerpendicularL;
vector_type Direction;
float PreComp1;
float OriginX;
float OriginY;
vector_type RayIntersect;
};
struct vector_type2
{
float X;
float Y;
vector2 PerpendicularC;
vector2 Direction;
vector2 Origin;
float MinCoord;
float MaxCoord;
vector2 RayIntersect;
};
struct wall_point_type
@ -61,40 +67,40 @@ struct wall_point_type
struct ramp_plane_type
{
vector_type BallCollisionOffset;
vector_type2 V1;
vector_type2 V2;
vector_type2 V3;
vector3 BallCollisionOffset;
vector2 V1;
vector2 V2;
vector2 V3;
float GravityAngle1;
float GravityAngle2;
vector_type2 FieldForce;
vector2 FieldForce;
};
class maths
{
public:
static void enclosing_box(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect);
static int rectangle_clip(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect);
static int overlapping_box(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect);
static float ray_intersect_circle(ray_type* ray, circle_type* circle);
static float normalize_2d(vector_type* vec);
static void enclosing_box(const rectangle_type& rect1, const rectangle_type& rect2, rectangle_type& dstRect);
static bool rectangle_clip(const rectangle_type& rect1, const rectangle_type& rect2, rectangle_type* dstRect);
static float ray_intersect_circle(const ray_type& ray, const circle_type& circle);
static float normalize_2d(vector2& vec);
static void line_init(line_type* line, float x0, float y0, float x1, float y1);
static float ray_intersect_line(ray_type* ray, line_type* line);
static void cross(vector_type* vec1, vector_type* vec2, vector_type* dstVec);
static float magnitude(vector_type* vec);
static void vector_add(vector_type* vec1Dst, vector_type* vec2);
static float basic_collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float elasticity,
static void cross(const vector3& vec1, const vector3& vec2, vector3& dstVec);
static float cross(const vector2& vec1, const vector2& vec2);
static float magnitude(const vector3& vec);
static void vector_add(vector2& vec1Dst, const vector2& vec2);
static vector2 vector_sub(const vector2& vec1, const vector2& vec2);
static float basic_collision(TBall* ball, vector2* nextPosition, vector2* direction, float elasticity,
float smoothness,
float threshold, float boost);
static float Distance_Squared(vector_type& vec1, vector_type& vec2);
static float DotProduct(vector_type* vec1, vector_type* vec2);
static void vswap(vector_type* vec1, vector_type* vec2);
static float Distance(vector_type* vec1, vector_type* vec2);
static float Distance_Squared(const vector2& vec1, const vector2& vec2);
static float DotProduct(const vector2& vec1, const vector2& vec2);
static float Distance(const vector2& vec1, const vector2& vec2);
static void SinCos(float angle, float* sinOut, float* cosOut);
static void RotatePt(vector_type* point, float sin, float cos, vector_type* origin);
static void RotatePt(vector2& point, float sin, float cos, const vector2& origin);
static float distance_to_flipper(ray_type* ray1, ray_type* ray2);
static void RotateVector(vector_type* vec, float angle);
static void find_closest_edge(ramp_plane_type* plane, int planeCount, wall_point_type* wall, vector_type** lineEnd,
vector_type** lineStart);
static void RotateVector(vector2& vec, float angle);
static void find_closest_edge(ramp_plane_type* plane, int planeCount, wall_point_type* wall, vector2& lineEnd,
vector2& lineStart);
};

View File

@ -64,7 +64,7 @@ void nudge::nudge_up()
void nudge::_nudge(float xDiff, float yDiff)
{
vector_type accelMod;
vector2 accelMod;
float invAccelX, invAccelY;
accelMod.X = xDiff * 0.5f;
@ -75,8 +75,8 @@ void nudge::_nudge(float xDiff, float yDiff)
{
ball->Acceleration.X = ball->Acceleration.X * ball->Speed;
ball->Acceleration.Y = ball->Acceleration.Y * ball->Speed;
maths::vector_add(&ball->Acceleration, &accelMod);
ball->Speed = maths::normalize_2d(&ball->Acceleration);
maths::vector_add(ball->Acceleration, accelMod);
ball->Speed = maths::normalize_2d(ball->Acceleration);
if (ball->Acceleration.X == 0.0f)
invAccelX = 1000000000.0;
else

View File

@ -244,7 +244,7 @@ void pb::ballset(float dx, float dy)
TBall* ball = MainTable->BallList.at(0);
ball->Acceleration.X = dx * sensitivity;
ball->Acceleration.Y = dy * sensitivity;
ball->Speed = maths::normalize_2d(&ball->Acceleration);
ball->Speed = maths::normalize_2d(ball->Acceleration);
}
void pb::frame(float dtMilliSec)
@ -291,7 +291,7 @@ void pb::frame(float dtMilliSec)
void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
{
vector_type vec1{}, vec2{};
vector2 vec1{}, vec2{};
for (auto ball : MainTable->BallList)
{
@ -309,14 +309,13 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
{
vec2.X = 0.0;
vec2.Y = 0.0;
vec2.Z = 0.0;
TTableLayer::edge_manager->FieldEffects(ball, &vec2);
vec2.X = vec2.X * timeDelta;
vec2.Y = vec2.Y * timeDelta;
ball->Acceleration.X = ball->Speed * ball->Acceleration.X;
ball->Acceleration.Y = ball->Speed * ball->Acceleration.Y;
maths::vector_add(&ball->Acceleration, &vec2);
ball->Speed = maths::normalize_2d(&ball->Acceleration);
maths::vector_add(ball->Acceleration, vec2);
ball->Speed = maths::normalize_2d(ball->Acceleration);
ball->InvAcceleration.X = ball->Acceleration.X == 0.0f ? 1.0e9f : 1.0f / ball->Acceleration.X;
ball->InvAcceleration.Y = ball->Acceleration.Y == 0.0f ? 1.0e9f : 1.0f / ball->Acceleration.Y;
}
@ -492,8 +491,8 @@ void pb::InputDown(GameInput input)
}
}
}
ball->Position.X = 1.0;
ball->ActiveFlag = 1;
ball->Position.X = 1.0;
ball->Position.Z = ball->Offset;
ball->Position.Y = 1.0;
ball->Acceleration.Z = 0.0;
@ -604,7 +603,7 @@ bool pb::chk_highscore()
float pb::collide(float timeNow, float timeDelta, TBall* ball)
{
ray_type ray{};
vector_type positionMod{};
vector2 positionMod{};
if (ball->ActiveFlag && !ball->CollisionComp)
{
@ -616,12 +615,8 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball)
ball->RayMaxDistance = maxDistance;
ball->TimeNow = timeNow;
ray.Origin.X = ball->Position.X;
ray.Origin.Y = ball->Position.Y;
ray.Origin.Z = ball->Position.Z;
ray.Direction.X = ball->Acceleration.X;
ray.Direction.Y = ball->Acceleration.Y;
ray.Direction.Z = ball->Acceleration.Z;
ray.Origin = ball->Position;
ray.Direction = ball->Acceleration;
ray.MaxDistance = maxDistance;
ray.FieldFlag = ball->FieldFlag;
ray.TimeNow = timeNow;
@ -637,8 +632,7 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball)
ball->RayMaxDistance = maxDistance;
positionMod.X = maxDistance * ball->Acceleration.X;
positionMod.Y = maxDistance * ball->Acceleration.Y;
positionMod.Z = 0.0;
maths::vector_add(&ball->Position, &positionMod);
maths::vector_add(ball->Position, positionMod);
}
else
{

View File

@ -26,7 +26,7 @@ void proj::init(float* mat4x3, float d, float centerX, float centerY)
centery = centerY;
}
void proj::matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_type* dstVec)
void proj::matrix_vector_multiply(mat4_row_major* mat, vector3* vec, vector3* dstVec)
{
const float x = vec->X, y = vec->Y, z = vec->Z;
dstVec->X = z * mat->Row0.Z + y * mat->Row0.Y + x * mat->Row0.X + mat->Row0.W;
@ -34,17 +34,17 @@ void proj::matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_
dstVec->Z = z * mat->Row2.Z + y * mat->Row2.Y + x * mat->Row2.X + mat->Row2.W;
}
float proj::z_distance(vector_type* vec)
float proj::z_distance(vector3* vec)
{
vector_type dstVec{};
vector3 dstVec{};
matrix_vector_multiply(&matrix, vec, &dstVec);
return maths::magnitude(&dstVec);
return maths::magnitude(dstVec);
}
void proj::xform_to_2d(vector_type* vec, int* dst)
void proj::xform_to_2d(vector3* vec, int* dst)
{
float projCoef;
vector_type dstVec2{};
vector3 dstVec2{};
matrix_vector_multiply(&matrix, vec, &dstVec2);
if (dstVec2.Z == 0.0f)

View File

@ -22,9 +22,9 @@ class proj
{
public:
static void init(float* mat4x3, float d, float centerX, float centerY);
static void matrix_vector_multiply(mat4_row_major* mat, vector_type* vec, vector_type* dstVec);
static float z_distance(vector_type* vec);
static void xform_to_2d(vector_type* vec, int* dst);
static void matrix_vector_multiply(mat4_row_major* mat, vector3* vec, vector3* dstVec);
static float z_distance(vector3* vec);
static void xform_to_2d(vector3* vec, int* dst);
static void recenter(float centerX, float centerY);
private:
static mat4_row_major matrix;

View File

@ -76,15 +76,15 @@ void render::update()
{
case VisualTypes::Sprite:
if (curSprite->DirtyRectPrev.Width > 0)
maths::enclosing_box(&curSprite->DirtyRectPrev, &curSprite->BmpRect, &curSprite->DirtyRect);
maths::enclosing_box(curSprite->DirtyRectPrev, curSprite->BmpRect, curSprite->DirtyRect);
if (maths::rectangle_clip(&curSprite->DirtyRect, &vscreen_rect, &curSprite->DirtyRect))
if (maths::rectangle_clip(curSprite->DirtyRect, vscreen_rect, &curSprite->DirtyRect))
clearSprite = true;
else
curSprite->DirtyRect.Width = -1;
break;
case VisualTypes::None:
if (maths::rectangle_clip(&curSprite->BmpRect, &vscreen_rect, &curSprite->DirtyRect))
if (maths::rectangle_clip(curSprite->BmpRect, vscreen_rect, &curSprite->DirtyRect))
clearSprite = !curSprite->Bmp;
else
curSprite->DirtyRect.Width = -1;
@ -291,7 +291,7 @@ void render::repaint(struct render_sprite_type_struct* sprite)
{
if (!refSprite->UnknownFlag && refSprite->Bmp)
{
if (maths::rectangle_clip(&refSprite->BmpRect, &sprite->DirtyRect, &clipRect))
if (maths::rectangle_clip(refSprite->BmpRect, sprite->DirtyRect, &clipRect))
zdrv::paint(
clipRect.Width,
clipRect.Height,
@ -334,7 +334,7 @@ void render::paint_balls()
{
auto ball = ball_list[index];
auto dirty = &ball->DirtyRect;
if (ball->Bmp && maths::rectangle_clip(&ball->BmpRect, &vscreen_rect, &ball->DirtyRect))
if (ball->Bmp && maths::rectangle_clip(ball->BmpRect, vscreen_rect, &ball->DirtyRect))
{
int xPos = dirty->XPosition;
int yPos = dirty->YPosition;
@ -407,7 +407,7 @@ void render::build_occlude_list()
{
if (!refSprite->UnknownFlag
&& refSprite->BoundingRect.Width != -1
&& maths::rectangle_clip(&mainSprite->BoundingRect, &refSprite->BoundingRect, nullptr)
&& maths::rectangle_clip(mainSprite->BoundingRect, refSprite->BoundingRect, nullptr)
&& spriteArr)
{
spriteArr->push_back(refSprite);