TFlipper, TFlipperEdge ready.

This commit is contained in:
oz
2021-01-10 15:22:06 +03:00
parent 87b4aa27e7
commit 61fe0410b0
8 changed files with 510 additions and 266 deletions

Binary file not shown.

View File

@@ -220,7 +220,7 @@
<Filter>Header Files\TPinballComponent</Filter>
</ClInclude>
<ClInclude Include="TFlipperEdge.h">
<Filter>Header Files</Filter>
<Filter>Header Files\TEdgeSegment</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
@@ -408,7 +408,7 @@
<Filter>Source Files\TPinballComponent</Filter>
</ClCompile>
<ClCompile Include="TFlipperEdge.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\TEdgeSegment</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>

View File

@@ -1,2 +1,188 @@
#include "pch.h"
#include "TFlipper.h"
#include "control.h"
#include "loader.h"
#include "pb.h"
#include "render.h"
#include "TFlipperEdge.h"
#include "timer.h"
#include "TZmapList.h"
TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{
visualStruct visual{};
loader::query_visual(groupIndex, 0, &visual);
SoundIndex1 = visual.SoundIndex4;
SoundIndex2 = visual.SoundIndex3;
UnknownC4F = visual.Unknown2F;
Timer = 0;
UnknownC5F = visual.Unknown1F;
auto floatArr = loader::query_float_attribute(groupIndex, 0, 803);
auto floatArr2 = loader::query_float_attribute(groupIndex, 0, 805);
auto floatArr3 = loader::query_float_attribute(groupIndex, 0, 804);
auto collMult = *floatArr;
auto bmpCoef2 = *floatArr2;
auto bmpCoef1 = *floatArr3;
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 flipperEdge = new TFlipperEdge(
this,
&UnknownBaseFlag2,
visual.Flag,
table,
origin,
vecT1,
vecT2,
bmpCoef1,
bmpCoef2,
collMult,
UnknownC4F,
UnknownC5F);
FlipperEdge = flipperEdge;
if (flipperEdge)
{
BmpCoef1 = flipperEdge->BmpCoef1 / static_cast<float>(ListBitmap->Count() - 1);
BmpCoef2 = flipperEdge->BmpCoef2 / static_cast<float>(ListBitmap->Count() - 1);
}
BmpIndex = 0;
InputTime = 0.0;
}
TFlipper::~TFlipper()
{
delete FlipperEdge;
}
int TFlipper::Message(int code, float value)
{
if (code == 1 || code == 2 || code > 1008 && code <= 1011 || code == 1022)
{
float timerTime;
int soundIndex = 0, code2 = code;
if (code == 1)
{
control::handler(1, this);
TimerTime = BmpCoef1;
soundIndex = SoundIndex1;
}
else if (code == 2)
{
TimerTime = BmpCoef2;
soundIndex = SoundIndex2;
}
else
{
code2 = 2;
TimerTime = BmpCoef2;
}
if (soundIndex)
loader::play_sound(soundIndex);
if (Timer)
{
timer::kill(Timer);
Timer = 0;
}
if (MessageField)
{
auto v10 = value - FlipperEdge->InputTime;
timerTime = v10 - floor(v10 / TimerTime) * TimerTime;
if (timerTime < 0.0)
timerTime = 0.0;
}
else
{
timerTime = TimerTime;
}
MessageField = code2;
InputTime = value;
Timer = timer::set(timerTime, this, TimerExpired);
FlipperEdge->SetMotion(code2, value);
}
if (code == 1020 || code == 1024)
{
if (MessageField)
{
if (Timer)
timer::kill(Timer);
BmpIndex = -1;
MessageField = 2;
TimerExpired(Timer, this);
FlipperEdge->SetMotion(code, value);
}
}
return 0;
}
void TFlipper::port_draw()
{
FlipperEdge->port_draw();
}
void TFlipper::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
{
}
void TFlipper::TimerExpired(int timerId, void* caller)
{
auto flip = static_cast<TFlipper*>(caller);
int timer; // eax
bool bmpIndexOutOfBounds = false;
auto bmpIndexAdvance = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime + 0.5f));
int bmpCount = flip->ListBitmap->Count();
if (bmpIndexAdvance > bmpCount)
bmpIndexAdvance = bmpCount;
if (bmpIndexAdvance < 0)
bmpIndexAdvance = 0;
if (!bmpIndexAdvance)
bmpIndexAdvance = 1;
if (flip->MessageField == 1)
{
flip->BmpIndex += bmpIndexAdvance;
int countSub1 = flip->ListBitmap->Count() - 1;
if (flip->BmpIndex >= countSub1)
{
flip->BmpIndex = countSub1;
bmpIndexOutOfBounds = true;
}
}
if (flip->MessageField == 2)
{
flip->BmpIndex -= bmpIndexAdvance;
timer = 0;
if (flip->BmpIndex <= 0)
{
flip->BmpIndex = 0;
bmpIndexOutOfBounds = true;
}
}
else
{
timer = 0;
}
if (bmpIndexOutOfBounds)
flip->MessageField = 0;
else
timer = timer::set(flip->TimerTime, flip, TimerExpired);
flip->Timer = timer;
auto bmp = static_cast<gdrv_bitmap8*>(flip->ListBitmap->Get(flip->BmpIndex));
auto zMap = static_cast<zmap_header_type*>(flip->ListZMap->Get(flip->BmpIndex));
render::sprite_set(
flip->RenderSprite,
bmp,
zMap,
bmp->XPosition - flip->PinballTable->XOffset,
bmp->YPosition - flip->PinballTable->YOffset);
}

View File

@@ -1,11 +1,26 @@
#pragma once
#include "TCollisionComponent.h"
class TFlipperEdge;
class TFlipper :
public TCollisionComponent
{
public:
TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
{
}
TFlipper(TPinballTable* table, int groupIndex);
~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,
TEdgeSegment* edge) override;
static void TimerExpired(int timerId, void* caller);
int BmpIndex;
TFlipperEdge* FlipperEdge;
int Timer;
float BmpCoef1;
float BmpCoef2;
float TimerTime;
float InputTime;
};

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@ class TFlipperEdge : public TEdgeSegment
{
public:
TFlipperEdge(TCollisionComponent* collComp, char* someFlag, unsigned int visualFlag, TPinballTable* table,
vector_type* origin, vector_type* vecT, vector_type* vec3, float bmpCoef1, float bmpCoef2, float a11,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float bmpCoef1, float bmpCoef2, float collMult,
float c4F, float c5F);
void port_draw() override;
float FindCollisionDistance(ray_type* ray) override;
@@ -33,22 +33,22 @@ public:
float AngleMax;
float Angle2;
float Angle1;
int Unknown15;
int Unknown16;
vector_type Unknown17V;
int CollisionFlag1;
int CollisionFlag2;
vector_type CollisionLinePerp;
vector_type A1Src;
vector_type A2Src;
vector_type B1Src;
vector_type B2Src;
float Unknown32F;
float CollisionMult;
vector_type T1Src;
vector_type Unknown36V;
vector_type T2Src;
float DistanceDivSq;
float Unknown40F;
float CollisionTimeAdvance;
vector_type CollisionDirection;
int Unknown44;
float TimeAngle;
float Unknown46F;
int EdgeCollisionFlag;
float InputTime;
float AngleStopTime;
float AngleMult;
float BmpCoef1;
float BmpCoef2;

View File

@@ -2,6 +2,7 @@
#include "maths.h"
#include "TBall.h"
#include "TFlipperEdge.h"
void maths::enclosing_box(rectangle_type* rect1, rectangle_type* rect2, rectangle_type* dstRect)
@@ -341,5 +342,69 @@ void maths::RotatePt(vector_type* point, float sin, float cos, vector_type* orig
float maths::distance_to_flipper(ray_type* ray1, ray_type* ray2)
{
return 0;
auto distance = 1000000000.0f;
auto distanceType = -1;
auto newDistance = ray_intersect_line(ray1, &TFlipperEdge::lineA);
if (newDistance < 1000000000.0)
{
distance = newDistance;
distanceType = 0;
}
newDistance = ray_intersect_circle(ray1, &TFlipperEdge::circlebase);
if (newDistance < distance)
{
distance = newDistance;
distanceType = 2;
}
newDistance = ray_intersect_circle(ray1, &TFlipperEdge::circleT1);
if (newDistance < distance)
{
distance = newDistance;
distanceType = 3;
}
newDistance = ray_intersect_line(ray1, &TFlipperEdge::lineB);
if (newDistance < distance)
{
distance = newDistance;
distanceType = 1;
}
if (!ray2 || distance >= 1000000000.0)
return distance;
if (distanceType != -1)
{
vector_type* nextOrigin;
if (distanceType)
{
if (distanceType != 1)
{
float dirY;
ray2->Origin.X = distance * ray1->Direction.X + ray1->Origin.X;
ray2->Origin.Y = distance * ray1->Direction.Y + ray1->Origin.Y;
if (distanceType == 2)
{
ray2->Direction.X = ray2->Origin.X - TFlipperEdge::circlebase.Center.X;
dirY = ray2->Origin.Y - TFlipperEdge::circlebase.Center.Y;
}
else
{
ray2->Direction.X = ray2->Origin.X - TFlipperEdge::circleT1.Center.X;
dirY = ray2->Origin.Y - TFlipperEdge::circleT1.Center.Y;
}
ray2->Direction.Y = dirY;
normalize_2d(&ray2->Direction);
return distance;
}
ray2->Direction = TFlipperEdge::lineB.PerpendicularL;
nextOrigin = &TFlipperEdge::lineB.RayIntersect;
}
else
{
ray2->Direction = TFlipperEdge::lineA.PerpendicularL;
nextOrigin = &TFlipperEdge::lineA.RayIntersect;
}
ray2->Origin = *nextOrigin;
return distance;
}
return 1000000000.0;
}

View File

@@ -9,7 +9,7 @@ class pb
{
public:
static int time_ticks;
static float ball_speed_limit;
static float ball_speed_limit, time_now;
static int cheat_mode, game_mode;
static datFileStruct* record_table;
static TPinballTable* MainTable;
@@ -39,7 +39,7 @@ public:
static float collide(float timeNow, float timeDelta, TBall* ball);
private :
static int demo_mode, mode_countdown_;
static float time_now, time_next;
static float time_next;
static high_score_struct highscore_table[5];
static int state;
};