mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
scheduler: removing task IDs
These no longer serve any purpose that can't be replaced with a structure like Ds\Set, SplObjectStorage, or just using spl_object_id().
This commit is contained in:
parent
d738504e24
commit
6bca38999d
@ -37,14 +37,6 @@ abstract class Task{
|
||||
return $this->taskHandler;
|
||||
}
|
||||
|
||||
final public function getTaskId() : int{
|
||||
if($this->taskHandler !== null){
|
||||
return $this->taskHandler->getTaskId();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getName() : string{
|
||||
return Utils::getNiceClassName($this);
|
||||
}
|
||||
|
@ -31,9 +31,6 @@ class TaskHandler{
|
||||
/** @var Task */
|
||||
protected $task;
|
||||
|
||||
/** @var int */
|
||||
protected $taskId;
|
||||
|
||||
/** @var int */
|
||||
protected $delay;
|
||||
|
||||
@ -54,12 +51,11 @@ class TaskHandler{
|
||||
/** @var string */
|
||||
private $ownerName;
|
||||
|
||||
public function __construct(Task $task, int $taskId, int $delay = -1, int $period = -1, ?string $ownerName = null){
|
||||
public function __construct(Task $task, int $delay = -1, int $period = -1, ?string $ownerName = null){
|
||||
if($task->getHandler() !== null){
|
||||
throw new \InvalidArgumentException("Cannot assign multiple handlers to the same task");
|
||||
}
|
||||
$this->task = $task;
|
||||
$this->taskId = $taskId;
|
||||
$this->delay = $delay;
|
||||
$this->period = $period;
|
||||
$this->taskName = $task->getName();
|
||||
@ -80,10 +76,6 @@ class TaskHandler{
|
||||
$this->nextRun = $ticks;
|
||||
}
|
||||
|
||||
public function getTaskId() : int{
|
||||
return $this->taskId;
|
||||
}
|
||||
|
||||
public function getTask() : Task{
|
||||
return $this->task;
|
||||
}
|
||||
|
@ -49,9 +49,6 @@ class TaskScheduler{
|
||||
*/
|
||||
protected $tasks;
|
||||
|
||||
/** @var int */
|
||||
private $ids = 1;
|
||||
|
||||
/** @var int */
|
||||
protected $currentTick = 0;
|
||||
|
||||
@ -85,7 +82,6 @@ class TaskScheduler{
|
||||
while(!$this->queue->isEmpty()){
|
||||
$this->queue->extract();
|
||||
}
|
||||
$this->ids = 1;
|
||||
}
|
||||
|
||||
public function isQueued(TaskHandler $task) : bool{
|
||||
@ -110,7 +106,7 @@ class TaskScheduler{
|
||||
$period = 1;
|
||||
}
|
||||
|
||||
return $this->handle(new TaskHandler($task, $this->nextId(), $delay, $period, $this->owner));
|
||||
return $this->handle(new TaskHandler($task, $delay, $period, $this->owner));
|
||||
}
|
||||
|
||||
private function handle(TaskHandler $handler) : TaskHandler{
|
||||
@ -159,8 +155,4 @@ class TaskScheduler{
|
||||
private function isReady(int $currentTick) : bool{
|
||||
return !$this->queue->isEmpty() and $this->queue->current()->getNextRun() <= $currentTick;
|
||||
}
|
||||
|
||||
private function nextId() : int{
|
||||
return $this->ids++;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user