Permalink
Browse files

Defer to the C++ implementation of IsPlayerMinimized

  • Loading branch information...
RussellLVP committed Oct 19, 2016
1 parent e1708c5 commit 6a16d01471a8d9da1cadb3ba44d46e35ab6ba315
@@ -50,7 +50,6 @@ forward OnPlayerExitedMenu(playerid);
forward OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid);
forward OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
forward OnRconLoginAttempt( ip[], password[], success );
# forward OnPlayerUpdate(playerid);
forward OnPlayerStreamIn(playerid, forplayerid);
forward OnPlayerStreamOut(playerid, forplayerid);
forward OnVehicleStreamIn(vehicleid, forplayerid);
@@ -38,6 +38,9 @@ class Player {
// Returns whether the player is still connected to the server.
isConnected() { return this.connected_; }
// Returns whether the player is connected, but has minimized their game.
isMinimized() { return isPlayerMinimized(this.id_); }
// Returns whether the player is currently in process of disconnecting.
isDisconnecting() { return this.disconnecting_; }
@@ -46,6 +46,7 @@ class MockPlayer {
this.streamerObjectsUpdated_ = false;
this.connected_ = true;
this.minimized_ = false;
this.disconnecting_ = false;
this.vehicle_ = null;
@@ -59,6 +60,9 @@ class MockPlayer {
isConnected() { return this.connected_; }
isMinimized() { return this.minimized_; }
setMinimized(minimized) { this.minimized_ = minimized; }
isDisconnecting() { return this.disconnecting_; }
notifyDisconnecting() {
@@ -16,10 +16,6 @@ class Player <playerId (MAX_PLAYERS)> {
// How many hours does a player need to have been in-game before they're considered a regular?
public const RegularHours = 50;
// How many milliseconds do we need to be without update before we detect this player as having
// their game minimized?
const DetectAsMinimizedThresholdMilliseconds = 1000;
// ---- MEMBER VARIABLES FOR EACH PLAYER -------------------------------------------------------
// What are the flags that apply to the current player?
@@ -31,9 +27,6 @@ class Player <playerId (MAX_PLAYERS)> {
// Store their nickname in a string, as we could be needing this a lot.
new m_nickname[MAX_PLAYER_NAME+1];
// What is the timestamp at which this player last send an update to the game?
new m_lastUpdate;
// When did this player connect to the server? Useful for measuring in-game time.
new m_connectionTime;
@@ -87,7 +80,6 @@ class Player <playerId (MAX_PLAYERS)> {
public onConnect() {
m_flags = 0;
m_level = PlayerLevel;
m_lastUpdate = Time->currentHighResolutionTime();
m_connectionTime = Time->currentTime();
this->enableFlag(IsConnectedPlayerFlag);
@@ -243,16 +235,6 @@ class Player <playerId (MAX_PLAYERS)> {
return m_level;
}
/**
* Returns whether the player currently has minimized their Grand Theft Auto game. Certain
* timers and countdowns can be stopped when this is the case, and we may want to pause them.
*
* @return boolean Is this player currently minimized?
*/
public inline bool: isMinimized() {
return ((Time->currentHighResolutionTime() - m_lastUpdate) >= DetectAsMinimizedThresholdMilliseconds);
}
/**
* Returns whether this player is a regular player on Las Venturas Playground, which will be
* decided by the amount of hours they've spent on the server.
@@ -313,15 +295,6 @@ class Player <playerId (MAX_PLAYERS)> {
m_level = level;
}
/**
* Updates the time we last received an update from this player with the given value.
*
* @param time The last update time an update was received.
*/
public inline setLastUpdate(time) {
m_lastUpdate = time;
}
// ---- GETTERS FOR IMMUTABLE FLAGS ------------------------------------------------------------
/**
@@ -148,19 +148,6 @@ class PlayerEvents <playerId (MAX_PLAYERS)> {
return 1;
}
/**
* Called up to fifty times per second for every player in the game. This is a very hot function
* so please don't randomly add your code in here. Critical functionality should be optimized as
* much as you can, as this historically shows up in profiles.
*/
public onPlayerUpdate() {
// Mark when we received the last update for this player, so that we can monitor whether
// they've minimized their Grand Theft Auto game or not.
Player(playerId)->setLastUpdate(Time->currentHighResolutionTime());
return 1;
}
/**
* Invoked when the player right-clicks anywhere on the San Andreas map, through the option
* available to them in GTA's menu.
@@ -206,6 +193,5 @@ class PlayerEvents <playerId (MAX_PLAYERS)> {
public OnIncomingConnection(playerid, ip_address[], port) { PlayerEvents(playerid)->onIncomingConnection(ip_address, port); return 1; }
public OnPlayerConnect(playerid) { return PlayerEvents(playerid)->onPlayerConnect(); }
public OnPlayerDisconnect(playerid, reason) { return PlayerEvents(playerid)->onPlayerDisconnect(reason); }
public OnPlayerUpdate(playerid) { return PlayerEvents(playerid)->onPlayerUpdate(); }
public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ) { PlayerEvents(playerid)->onPlayerClickMap(fX, fY, fZ); return 1; }
public OnPlayerClickTextDraw(playerid, Text:clickedid) { return PlayerEvents(playerid)->onPlayerClickTextDraw(clickedid); }
@@ -181,7 +181,7 @@ public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float: fX, Float:
return 0;
// A paused player should not be able to take damage.
if (Player(hitid)->isMinimized())
if (IsPlayerMinimized(hitid))
return 0;
// Crew members using god-mode should not be able to take damage.
@@ -248,7 +248,7 @@ class JailController {
// If the player has minimized their game, increase their jail time so they won't be
// unjailed without actually having to sit out the punishment.
if (Player(playerId)->isMinimized() == true) {
if (IsPlayerMinimized(playerId)) {
if (m_playerMinimizedRemainingTime[playerId] == 0)
m_playerMinimizedRemainingTime[playerId] = remainingTime;
@@ -267,7 +267,7 @@ class JailController {
// Automatically unjail them when they served their jail time. We'll have compensated
// for potential minimizing of Grand Theft Auto: San Andreas now.
if (remainingTime < 0 && Player(playerId)->isMinimized() == false) {
if (remainingTime < 0 && !IsPlayerMinimized(playerId)) {
SendClientMessage(playerId, Color::Success, "You have been released from jail because your punishment is over.");
this->unjailPlayer(playerId);
continue;
@@ -8,6 +8,9 @@
native gpci(playerid, serial[], len);
native IsValidVehicle(vehicleid);
// Provided by the PlaygroundJS plugin.
native IsPlayerMinimized(playerId);
// Provided by the Communication feature in JavaScript.
native GetPlayerTeleportStatus(playerId, timeLimited);
native ReportPlayerTeleport(playerId, timeLimited);

0 comments on commit 6a16d01

Please sign in to comment.