Skip to content

Commit f9902bb

Browse files
committed
More mocking on the drift system
1 parent 015d6d3 commit f9902bb

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
lines changed

javascript/features/derbies/derby_registry.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('DerbyRegistry', it => {
88
it('should be able to initialize all derbies known to the server', assert => {
99
const registry = new DerbyRegistry();
1010

11-
// Initialize all the JSON files that exist in the //data/ directory.
11+
// Initialize all the JSON files that exist in the //data/derbies/ directory.
1212
registry.initialize();
1313

1414
assert.isAbove(registry.size, 0);

pawn/Driver/Drift/DriftHelpers.pwn

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
new g_playerDriftUpdateCounter[MAX_PLAYERS];
1212

13+
new g_playerDriftPoints[MAX_PLAYERS];
14+
new Float: g_playerDriftPosition[MAX_PLAYERS][3];
15+
new g_playerDriftStartTime[MAX_PLAYERS] = { 0, ... };
16+
new g_playerDriftUpdateTime[MAX_PLAYERS] = { 0, ... };
17+
1318
// Calculates the vehicle's principal axes based on it's rotation quaternion, which allows us to
1419
// determine the vehicle's orientation during a drift. Drifts on a flat plane are great, but they
1520
// become a lot more interesting when exercised on e.g. a hill.
@@ -84,6 +89,25 @@ GetVehicleDriftValues(vehicleId, &bool: backwards, &Float: driftAngle, &Float: d
8489
return 1;
8590
}
8691

92+
// Calculates the expiration time of a drift, in milliseconds. The |timeDifference| details the
93+
// number of milliseconds since their last drift, and the |driftDuration| details the time in
94+
// milliseconds since the player started their drift.
95+
CalculateDriftExpiration(timeDifference, driftDuration) {
96+
return 0;
97+
}
98+
99+
// Calculates the amount of drifting points to award as a bonus, given the vehicle's |pitch|, |roll|
100+
// and |yaw| values, each of which make for harder circumstances to maintain a drift.
101+
CalculateDriftBonus(timeDifference, Float: pitch, Float: roll, Float: yaw) {
102+
return 0;
103+
}
104+
105+
// Calculates the amount of drifting points to award for a drift at the given |driftSpeed| and the
106+
// |driftAngle|, which took place in the given |timeDifference| in milliseconds.
107+
CalculateDriftPoints(timeDifference, Float: driftSpeed, Float: driftAngle, Float: driftDistance) {
108+
return 0;
109+
}
110+
87111
// Processes drift updates for the given |playerId|. Only works when they're in a vehicle, and only
88112
// processed a certain ratio of player updates as this method is called a lot.
89113
ProcessDriftUpdateForPlayer(playerId) {
@@ -110,6 +134,50 @@ ProcessDriftUpdateForPlayer(playerId) {
110134
driftAngle >= g_driftingMinAngle && driftAngle <= g_driftingMaxAngle &&
111135
!backwards;
112136

113-
printf("[%d] P:[%.f4] R:[%.4f] Y:[%.f4] A:[%.4f] S:[%.f4] B:[%d] D:[%d]",
114-
playerId, pitch, roll, yaw, driftAngle, driftSpeed, backwards ? 1 : 0, isDrifting ? 1 : 0);
137+
// If the player wasn't drifting, and isn't currently drifting, just bail out.
138+
if (g_playerDriftStartTime[playerId] == 0 && !isDrifting)
139+
return;
140+
141+
new const currentTime = GetTickCount();
142+
143+
// (1) The player is currently drifting, and was drifting during the previous tick as well.
144+
if (g_playerDriftStartTime[playerId] > 0 && isDrifting) {
145+
new const difference = currentTime - g_playerDriftUpdateTime[playerId];
146+
new const Float: distance = GetVehicleDistanceFromPoint(
147+
vehicleId, g_playerDriftPosition[playerId][0], g_playerDriftPosition[playerId][1],
148+
g_playerDriftPosition[playerId][2]);
149+
150+
g_playerDriftUpdateTime[playerId] = currentTime;
151+
g_playerDriftPoints[playerId] +=
152+
CalculateDriftBonus(difference, pitch, roll, yaw) +
153+
CalculateDriftPoints(difference, driftSpeed, driftAngle, distance);
154+
155+
printf("[%d] Drift: %d", playerId, g_playerDriftPoints[playerId]);
156+
157+
} else if (g_playerDriftStartTime[playerId] == 0 && isDrifting) {
158+
// (2) The player is currently drifting, but wasn't yet drifting during their previous tick.
159+
g_playerDriftPoints[playerId] = 0;
160+
g_playerDriftStartTime[playerId] = currentTime;
161+
g_playerDriftUpdateTime[playerId] = currentTime;
162+
163+
printf("[%d] Drift started", playerId);
164+
165+
} else {
166+
// (3) The player is currently in a drift, but missed the thresholds for this tick.
167+
new const difference = currentTime - g_playerDriftUpdateTime[playerId];
168+
new const duration = currentTime - g_playerDriftStartTime[playerId];
169+
170+
// If the |difference| is larger than the expiration we'd award for this moment in the drift
171+
// then we'll mark the drift as having finished.
172+
if (difference > CalculateDriftExpiration(difference, duration)) {
173+
g_playerDriftStartTime[playerId] = 0;
174+
175+
printf("[%d] Drift finished", playerId);
176+
}
177+
}
178+
179+
// Store the position so that we can calculate the moved drift distance during the next tick.
180+
GetVehiclePos(
181+
vehicleId, g_playerDriftPosition[playerId][0], g_playerDriftPosition[playerId][1],
182+
g_playerDriftPosition[playerId][2]);
115183
}

pawn/Driver/Driver.pwn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public OnPlayerConnect(playerid) {
9898
g_playerGravity[playerid] = 0.008;
9999
g_isDisconnecting[playerid] = false;
100100

101+
g_playerDriftStartTime[playerid] = 0;
102+
101103
// Proceed with legacy processing.
102104
return PlayerEvents(playerid)->onPlayerConnect();
103105
}

pawn/config.pwn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
class Version {
1010
public const Major = 49;
11-
public const Minor = 2;
11+
public const Minor = 3;
1212
};
1313

1414
// Set this to 1 if you'd like to build Las Venturas Playground in release mode. This affects

0 commit comments

Comments
 (0)