-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement API for new camera features #5832
Draft
IvanCraft623
wants to merge
7
commits into
pmmp:minor-next
Choose a base branch
from
IvanCraft623:camera2
base: minor-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0692b70
Initial camera stuff
IvanCraft623 769279e
Implement camera set instruction
IvanCraft623 e9dd78b
Little fixes
IvanCraft623 c5493ef
Allow multiple instructions in a single packet
IvanCraft623 43086f2
CS fix
IvanCraft623 1041478
Fix code consistency
IvanCraft623 a726c19
Remove useless return value
IvanCraft623 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ _ __ __ _ __ __ ____ | ||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author PocketMine Team | ||
* @link http://www.pocketmine.net/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\data\bedrock; | ||
|
||
use pocketmine\player\camera\CameraEaseType; | ||
use pocketmine\utils\SingletonTrait; | ||
use function array_key_exists; | ||
|
||
final class CameraEaseTypeIdMap{ | ||
use SingletonTrait; | ||
|
||
/** | ||
* @var CameraEaseType[] | ||
* @phpstan-var array<string, CameraEaseType> | ||
*/ | ||
private array $idToEnum = []; | ||
/** | ||
* @var string[] | ||
* @phpstan-var array<int, string> | ||
*/ | ||
private array $enumToId = []; | ||
|
||
public function __construct(){ | ||
$this->register("linear", CameraEaseType::LINEAR()); | ||
$this->register("spring", CameraEaseType::SPRING()); | ||
$this->register("in_quad", CameraEaseType::IN_QUAD()); | ||
$this->register("out_quad", CameraEaseType::OUT_QUAD()); | ||
$this->register("in_out_quad", CameraEaseType::IN_OUT_QUAD()); | ||
$this->register("in_cubic", CameraEaseType::IN_CUBIC()); | ||
$this->register("out_cubic", CameraEaseType::OUT_CUBIC()); | ||
$this->register("in_out_cubic", CameraEaseType::IN_OUT_CUBIC()); | ||
$this->register("in_quart", CameraEaseType::IN_QUART()); | ||
$this->register("out_quart", CameraEaseType::OUT_QUART()); | ||
$this->register("in_out_quart", CameraEaseType::IN_OUT_QUART()); | ||
$this->register("in_quint", CameraEaseType::IN_QUINT()); | ||
$this->register("out_quint", CameraEaseType::OUT_QUINT()); | ||
$this->register("in_out_quint", CameraEaseType::IN_OUT_QUINT()); | ||
$this->register("in_sine", CameraEaseType::IN_SINE()); | ||
$this->register("out_sine", CameraEaseType::OUT_SINE()); | ||
$this->register("in_out_sine", CameraEaseType::IN_OUT_SINE()); | ||
$this->register("in_expo", CameraEaseType::IN_EXPO()); | ||
$this->register("out_expo", CameraEaseType::OUT_EXPO()); | ||
$this->register("in_out_expo", CameraEaseType::IN_OUT_EXPO()); | ||
$this->register("in_circ", CameraEaseType::IN_CIRC()); | ||
$this->register("out_circ", CameraEaseType::OUT_CIRC()); | ||
$this->register("in_out_circ", CameraEaseType::IN_OUT_CIRC()); | ||
$this->register("in_bounce", CameraEaseType::IN_BOUNCE()); | ||
$this->register("out_bounce", CameraEaseType::OUT_BOUNCE()); | ||
$this->register("in_out_bounce", CameraEaseType::IN_OUT_BOUNCE()); | ||
$this->register("in_back", CameraEaseType::IN_BACK()); | ||
$this->register("out_back", CameraEaseType::OUT_BACK()); | ||
$this->register("in_out_back", CameraEaseType::IN_OUT_BACK()); | ||
$this->register("in_elastic", CameraEaseType::IN_ELASTIC()); | ||
$this->register("out_elastic", CameraEaseType::OUT_ELASTIC()); | ||
$this->register("in_out_elastic", CameraEaseType::IN_OUT_ELASTIC()); | ||
} | ||
|
||
public function register(string $stringId, CameraEaseType $type) : void{ | ||
$this->idToEnum[$stringId] = $type; | ||
$this->enumToId[$type->id()] = $stringId; | ||
} | ||
|
||
public function fromId(string $id) : ?CameraEaseType{ | ||
return $this->idToEnum[$id] ?? null; | ||
} | ||
|
||
public function toId(CameraEaseType $type) : string{ | ||
if(!array_key_exists($type->id(), $this->enumToId)){ | ||
throw new \InvalidArgumentException("Missing mapping for camere ease type " . $type->name()); | ||
} | ||
return $this->enumToId[$type->id()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ | |
use pocketmine\permission\DefaultPermissions; | ||
use pocketmine\permission\PermissibleBase; | ||
use pocketmine\permission\PermissibleDelegateTrait; | ||
use pocketmine\player\camera\instruction\CameraInstruction; | ||
use pocketmine\player\chat\StandardChatFormatter; | ||
use pocketmine\Server; | ||
use pocketmine\timings\Timings; | ||
|
@@ -2095,6 +2096,10 @@ public function sendToastNotification(string $title, string $body) : void{ | |
$this->getNetworkSession()->onToastNotification($title, $body); | ||
} | ||
|
||
public function sendCameraInstruction(CameraInstruction ...$instructions) : void{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put it this way because most of the time only a single instruction is sent |
||
$this->getNetworkSession()->onCameraInstruction(...$instructions); | ||
} | ||
|
||
/** | ||
* Sends a Form to the player, or queue to send it if a form is already open. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ _ __ __ _ __ __ ____ | ||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author PocketMine Team | ||
* @link http://www.pocketmine.net/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\player\camera; | ||
|
||
use pocketmine\utils\EnumTrait; | ||
|
||
/** | ||
* This doc-block is generated automatically, do not modify it manually. | ||
* This must be regenerated whenever registry members are added, removed or changed. | ||
* @see build/generate-registry-annotations.php | ||
* @generate-registry-docblock | ||
* | ||
* @method static CameraEaseType LINEAR() | ||
* @method static CameraEaseType SPRING() | ||
* @method static CameraEaseType IN_QUAD() | ||
* @method static CameraEaseType OUT_QUAD() | ||
* @method static CameraEaseType IN_OUT_QUAD() | ||
* @method static CameraEaseType IN_CUBIC() | ||
* @method static CameraEaseType OUT_CUBIC() | ||
* @method static CameraEaseType IN_OUT_CUBIC() | ||
* @method static CameraEaseType IN_QUART() | ||
* @method static CameraEaseType OUT_QUART() | ||
* @method static CameraEaseType IN_OUT_QUART() | ||
* @method static CameraEaseType IN_QUINT() | ||
* @method static CameraEaseType OUT_QUINT() | ||
* @method static CameraEaseType IN_OUT_QUINT() | ||
* @method static CameraEaseType IN_SINE() | ||
* @method static CameraEaseType OUT_SINE() | ||
* @method static CameraEaseType IN_OUT_SINE() | ||
* @method static CameraEaseType IN_EXPO() | ||
* @method static CameraEaseType OUT_EXPO() | ||
* @method static CameraEaseType IN_OUT_EXPO() | ||
* @method static CameraEaseType IN_CIRC() | ||
* @method static CameraEaseType OUT_CIRC() | ||
* @method static CameraEaseType IN_OUT_CIRC() | ||
* @method static CameraEaseType IN_BOUNCE() | ||
* @method static CameraEaseType OUT_BOUNCE() | ||
* @method static CameraEaseType IN_OUT_BOUNCE() | ||
* @method static CameraEaseType IN_BACK() | ||
* @method static CameraEaseType OUT_BACK() | ||
* @method static CameraEaseType IN_OUT_BACK() | ||
* @method static CameraEaseType IN_ELASTIC() | ||
* @method static CameraEaseType OUT_ELASTIC() | ||
* @method static CameraEaseType IN_OUT_ELASTIC() | ||
*/ | ||
final class CameraEaseType{ | ||
use EnumTrait; | ||
|
||
protected static function setup() : void{ | ||
self::registerAll( | ||
new self("linear"), | ||
new self("spring"), | ||
new self("in_quad"), | ||
new self("out_quad"), | ||
new self("in_out_quad"), | ||
new self("in_cubic"), | ||
new self("out_cubic"), | ||
new self("in_out_cubic"), | ||
new self("in_quart"), | ||
new self("out_quart"), | ||
new self("in_out_quart"), | ||
new self("in_quint"), | ||
new self("out_quint"), | ||
new self("in_out_quint"), | ||
new self("in_sine"), | ||
new self("out_sine"), | ||
new self("in_out_sine"), | ||
new self("in_expo"), | ||
new self("out_expo"), | ||
new self("in_out_expo"), | ||
new self("in_circ"), | ||
new self("out_circ"), | ||
new self("in_out_circ"), | ||
new self("in_bounce"), | ||
new self("out_bounce"), | ||
new self("in_out_bounce"), | ||
new self("in_back"), | ||
new self("out_back"), | ||
new self("in_out_back"), | ||
new self("in_elastic"), | ||
new self("out_elastic"), | ||
new self("in_out_elastic") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* | ||
* ____ _ _ __ __ _ __ __ ____ | ||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* @author PocketMine Team | ||
* @link http://www.pocketmine.net/ | ||
* | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace pocketmine\player\camera; | ||
|
||
use pocketmine\nbt\tag\CompoundTag; | ||
use pocketmine\player\camera\element\CameraState; | ||
|
||
final class CameraPreset{ | ||
|
||
private const TAG_IDENTIFIER = "identifier"; //TAG_String | ||
private const TAG_INHERIT_FROM = "inherit_from"; //TAG_String | ||
|
||
private const TAG_POSITION_X = "pos_x"; //TAG_Float | ||
private const TAG_POSITION_Y = "pos_y"; //TAG_Float | ||
private const TAG_POSITION_Z = "pos_z"; //TAG_Float | ||
|
||
private const TAG_ROTATION_YAW = "rot_x"; //TAG_Float | ||
private const TAG_ROTATION_PITCH = "rot_y"; //TAG_Float | ||
|
||
public function __construct( | ||
private string $identifier, | ||
private string $inheritFrom = "", | ||
private ?CameraState $state = null | ||
){ | ||
} | ||
|
||
public function getIdentifier() : string{ | ||
return $this->identifier; | ||
} | ||
|
||
public function getInheritFrom() : string{ | ||
return $this->inheritFrom; | ||
} | ||
|
||
public function getCameraState() : ?CameraState{ | ||
return $this->state; | ||
} | ||
|
||
public function toCompoundTag() : CompoundTag{ | ||
$tag = CompoundTag::create() | ||
->setString(self::TAG_IDENTIFIER, $this->identifier) | ||
->setString(self::TAG_INHERIT_FROM, $this->inheritFrom); | ||
|
||
if ($this->state !== null) { | ||
if (($position = $this->state->getPosition()) !== null) { | ||
$tag->setFloat(self::TAG_POSITION_X, $position->x) | ||
->setFloat(self::TAG_POSITION_Y, $position->y) | ||
->setFloat(self::TAG_POSITION_Z, $position->z); | ||
} | ||
if (($yaw = $this->state->getYaw()) !== null && ($pitch = $this->state->getPitch()) !== null) { | ||
$tag->setFloat(self::TAG_ROTATION_YAW, $yaw) | ||
->setFloat(self::TAG_ROTATION_PITCH, $pitch); | ||
} | ||
} | ||
|
||
return $tag; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sendCameraInstructions()
would more fit according to the parameter.