2024-03-13 15:08:37 +00:00
|
|
|
#ifndef UTILS_PLAYER_HPP
|
|
|
|
#define UTILS_PLAYER_HPP
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <optional>
|
2024-04-16 09:44:58 +00:00
|
|
|
#include <godot_cpp/variant/transform3d.hpp>
|
|
|
|
|
2024-05-28 14:28:36 +00:00
|
|
|
namespace gd = godot;
|
|
|
|
|
2024-05-29 15:36:53 +00:00
|
|
|
namespace godot { class Node; }
|
|
|
|
|
2024-05-28 14:28:36 +00:00
|
|
|
namespace utils {
|
2024-03-13 15:08:37 +00:00
|
|
|
class PlayerInput;
|
|
|
|
|
2024-05-29 15:36:53 +00:00
|
|
|
/*! Interface required for player nodes.
|
|
|
|
*
|
|
|
|
* Use multiple inheritance and implement IPlayer to make a regular node usable as a player with GameRoot3D.
|
|
|
|
*/
|
2024-03-13 15:08:37 +00:00
|
|
|
class IPlayer {
|
2024-05-06 09:03:00 +00:00
|
|
|
friend class GameRoot3D;
|
2024-03-13 15:08:37 +00:00
|
|
|
public:
|
2024-05-29 15:36:53 +00:00
|
|
|
/*! Called by GameRoot3D when this player is instantiated or assigned a new PlayerInput.
|
|
|
|
*
|
|
|
|
* Use PlayerInput::listen_to to register input callbacks. There's no need to keep the input pointer around. As the instance is managed by the GameRoot3D.
|
|
|
|
*/
|
2024-03-13 15:08:37 +00:00
|
|
|
virtual void setup_player_input(PlayerInput *input) = 0;
|
2024-05-29 15:36:53 +00:00
|
|
|
//! Convert IPlayer instance to node.
|
2024-05-28 14:28:36 +00:00
|
|
|
virtual gd::Node *to_node() = 0;
|
2024-05-29 15:36:53 +00:00
|
|
|
//! Spawn the player at a given transform, usually the global transform of a SpawnPoint3D.
|
2024-05-28 14:28:36 +00:00
|
|
|
virtual void spawn_at_position(gd::Transform3D const &at) = 0;
|
2024-03-13 15:08:37 +00:00
|
|
|
|
2024-05-29 15:36:53 +00:00
|
|
|
uint32_t get_player_id(); //!< Returns the player id assigned to this instance.
|
2024-03-13 15:08:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::optional<uint32_t> player_id{std::nullopt};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !UTILS_PLAYER_HPP
|