Struct godot_ggrs_wrapper::GodotGGRSP2PSession
source · [−]pub struct GodotGGRSP2PSession { /* private fields */ }
Expand description
A Godot implementation of P2PSession
Implementations
sourceimpl GodotGGRSP2PSession
impl GodotGGRSP2PSession
sourcepub fn create_new_session(
&mut self,
_owner: &Node,
local_port: u16,
num_players: u32,
max_pred: usize
)
pub fn create_new_session(
&mut self,
_owner: &Node,
local_port: u16,
num_players: u32,
max_pred: usize
)
Creates a P2PSession, call this when you want to start setting up a P2P Session takes the local port, total number of players and max prediction frames as parameters.
Notes
- Max prediction frames is the maximum number of frames GGRS will roll back. Every gamestate older than this is guaranteed to be correct if the players did not desync.
- This value used to default to
8 frames
, but this has been made adjustable withGGRS 0.7.0
sourcepub fn create_session(
&mut self,
_owner: &Node,
local_port: u16,
num_players: u32
)
👎 Deprecated since 0.5.0: please use create_new_session()
instead
pub fn create_session(
&mut self,
_owner: &Node,
local_port: u16,
num_players: u32
)
please use create_new_session()
instead
Deprecated method to create a P2PSession. Use Self::create_new_session() instead.
sourcepub fn add_local_player(&mut self, _owner: &Node) -> PlayerHandle
pub fn add_local_player(&mut self, _owner: &Node) -> PlayerHandle
Adds a local player to the session and return the handle.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn add_remote_player(
&mut self,
_owner: &Node,
address: String
) -> PlayerHandle
pub fn add_remote_player(
&mut self,
_owner: &Node,
address: String
) -> PlayerHandle
Adds a remote player to the session and returns the handle.
Example
The following example shows how to format an address string, starting with the IP and ending with the port.
p2p.add_remote_player("127.0.0.1:7070")
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
- Will panic if the address string could not be converted to an std::net::SocketAddr
sourcepub fn add_spectator(&mut self, _owner: &Node, address: String) -> PlayerHandle
pub fn add_spectator(&mut self, _owner: &Node, address: String) -> PlayerHandle
Adds a spectator to the session and returns the handle
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
- Will panic if the address string could not be converted to an std::net::SocketAddr
sourcepub fn start_session(&mut self, _owner: &Node)
pub fn start_session(&mut self, _owner: &Node)
Starts the P2PSession
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn is_running(&mut self, _owner: &Node) -> bool
pub fn is_running(&mut self, _owner: &Node) -> bool
Returns true if connection has been established with remote players and is ready to start taking inputs via Self::advance_frame()
sourcepub fn get_current_state(&mut self, _owner: &Node) -> String
pub fn get_current_state(&mut self, _owner: &Node) -> String
Returns the current sate of the session as a String. Take a look at SessionState for all possible states.
sourcepub fn advance_frame(
&mut self,
_owner: &Node,
local_player_handle: usize,
local_input: u32
)
pub fn advance_frame(
&mut self,
_owner: &Node,
local_player_handle: usize,
local_input: u32
)
This function will advance the frame using the inputs given as a parameter (currently an int in Godot) Before using this function you have to set the callback node and make sure it has the following callback functions implemented
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
- Will print a ERR_MESSAGE_NO_CALLBACK_NODE error if a callback node has not been set
sourcepub fn set_fps(&mut self, _owner: &Node, fps: u32)
pub fn set_fps(&mut self, _owner: &Node, fps: u32)
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn set_callback_node(&mut self, _owner: &Node, callback: Ref<Node>)
pub fn set_callback_node(&mut self, _owner: &Node, callback: Ref<Node>)
Sets the callback node that will be called when using Self::advance_frame()
sourcepub fn poll_remote_clients(&mut self, _owner: &Node)
pub fn poll_remote_clients(&mut self, _owner: &Node)
Calls P2PSession::poll_remote_clients()
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn print_network_stats(&mut self, _owner: &Node, handle: PlayerHandle)
pub fn print_network_stats(&mut self, _owner: &Node, handle: PlayerHandle)
Prints out network stats of specified handle
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_network_stats(
&mut self,
_owner: &Node,
handle: PlayerHandle
) -> (usize, u64, usize, i32, i32)
pub fn get_network_stats(
&mut self,
_owner: &Node,
handle: PlayerHandle
) -> (usize, u64, usize, i32, i32)
Will return network stats of specified handle as a tuple
, which will be converted to an Array
inside godot.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn set_frame_delay(
&mut self,
_owner: &Node,
frame_delay: u32,
player_handle: PlayerHandle
)
pub fn set_frame_delay(
&mut self,
_owner: &Node,
frame_delay: u32,
player_handle: PlayerHandle
)
Sets P2PSession::set_frame_delay() of specified handle.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn set_disconnect_timeout(&mut self, _owner: &Node, secs: u64)
pub fn set_disconnect_timeout(&mut self, _owner: &Node, secs: u64)
Sets P2PSession::set_disconnect_timeout() converting the u64 to secconds.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn set_disconnect_notify_delay(&mut self, _owner: &Node, secs: u64)
pub fn set_disconnect_notify_delay(&mut self, _owner: &Node, secs: u64)
Sets P2PSession::set_disconnect_notify_delay() converting the u64 to secconds.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn set_sparse_saving(&mut self, _owner: &Node, sparse_saving: bool)
pub fn set_sparse_saving(&mut self, _owner: &Node, sparse_saving: bool)
Sets P2PSession::set_sparse_saving().
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn disconnect_player(&mut self, _owner: &Node, player_handle: PlayerHandle)
pub fn disconnect_player(&mut self, _owner: &Node, player_handle: PlayerHandle)
Disconnects specified player handle.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_events(&mut self, _owner: &Node) -> Vec<(&str, Variant)>
pub fn get_events(&mut self, _owner: &Node) -> Vec<(&str, Variant)>
Returns an Array
of events which contain usefull information, while you don’t have to implement everything, the one thing you should implement is the WaitRecommendation.
For details regarding the events please take a loot at GGRSEvent.
Example
var events = ggrs.get_events()
for item in events:
match item[0]:
"WaitRecommendation":
frames_to_skip += item[1]
"NetworkInterrupted":
var handle = item[1][0]
var disconnect_timeout = item[1][1]
"NetworkResumed":
var handle = item[1]
"Disconnected":
var handle = item[1]
"Synchronized":
var handle = item[1]
"Synchronizing":
var handle = item[1][0]
var total = item[1][1]
var count = item[1][2]
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_frames_ahead(&mut self, _owner: &Node) -> i32
pub fn get_frames_ahead(&mut self, _owner: &Node) -> i32
Calls and returns P2PSession::frames_ahead(). Will return a 0 if no session was made.
Errors
- Will print a ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_max_prediction(&mut self, _owner: &Node) -> usize
pub fn get_max_prediction(&mut self, _owner: &Node) -> usize
Calls and returns P2PSession::max_prediction(). Will return a 0 if no session was made.
Errors
- Will print an ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_current_frame(&mut self, _owner: &Node) -> Frame
pub fn get_current_frame(&mut self, _owner: &Node) -> Frame
Calls and returns P2PSession::current_frame(). Will return a 0 if no session was made.
Errors
- Will print an ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
sourcepub fn get_confirmed_frame(&mut self, _owner: &Node) -> Frame
pub fn get_confirmed_frame(&mut self, _owner: &Node) -> Frame
Calls and returns P2PSession::confirmed_frame(). Will return a 0 if no session was made.
Errors
- Will print an ERR_MESSAGE_NO_SESSION_MADE error if a session has not been made
Trait Implementations
sourceimpl NativeClass for GodotGGRSP2PSession
impl NativeClass for GodotGGRSP2PSession
type UserData = DefaultUserData<GodotGGRSP2PSession>
type UserData = DefaultUserData<GodotGGRSP2PSession>
User-data wrapper type of the class. Read more
sourcefn class_name() -> &'static str
fn class_name() -> &'static str
The name of the class. Read more
sourcefn init(owner: TRef<'_, Self::Base>) -> Self
fn init(owner: TRef<'_, Self::Base>) -> Self
Function that creates a value of Self
, used for the script-instance. The default
implementation simply panics. Read more
sourcefn register_properties(builder: &ClassBuilder<Self>)
fn register_properties(builder: &ClassBuilder<Self>)
Register any exported properties to Godot.
fn new_instance() -> Instance<Self, Unique> where
Self::Base: Instanciable,
fn new_instance() -> Instance<Self, Unique> where
Self::Base: Instanciable,
Convenience method to create an Instance<Self, Unique>
. This is a new Self::Base
with the script attached. Read more
sourceimpl NativeClassMethods for GodotGGRSP2PSession
impl NativeClassMethods for GodotGGRSP2PSession
Auto Trait Implementations
impl !RefUnwindSafe for GodotGGRSP2PSession
impl Send for GodotGGRSP2PSession
impl Sync for GodotGGRSP2PSession
impl Unpin for GodotGGRSP2PSession
impl !UnwindSafe for GodotGGRSP2PSession
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more