Skip to content

Commit e38fa39

Browse files
committed
Merge branch 'release/v0.3.0' into main
2 parents 376a3d2 + 6b7538a commit e38fa39

7 files changed

Lines changed: 83 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
In this document, all remarkable changes are listed. Not mentioned are smaller code cleanups or documentation improvements.
4+
5+
## Unreleased
6+
7+
## 0.3.0
8+
9+
- Added `get_events()` function to `GodotGGRSP2PSpectatorSession` which calls `events()` on the GGRS Session
10+
- Added `get_events()` function to `GodotGGRSP2PSession` which calls `events()` on the GGRS Session
11+
12+
## 0.2.0
13+
14+
- Implemented SyncTestSession
15+
- Implemented P2PSpectatorSession
16+
- Implemented additional setters for P2PSession
17+
- Improved code architecture
18+
19+
## 0.1.0
20+
21+
- `P2PSession` has been implemented and tested in Godot 3.3.2

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "godot-ggrs-wrapper"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2018"
55
authors = ["Marcello Haddeman <haddemanmarcello@gmail.com>"]
66

src/godotggrs_p2psession.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::helper_functions::*;
1+
use crate::*;
22
use gdnative::core_types::ToVariant;
3-
use gdnative::prelude::*;
43
use ggrs::*;
54
use std::convert::TryInto;
65
use std::option::*;
@@ -186,6 +185,27 @@ impl GodotGGRSP2PSession {
186185
}
187186
}
188187

188+
#[export]
189+
fn get_events(&mut self, _owner: &Node)->Vec<(&str, Variant)>{
190+
let mut result: Vec<(&str, Variant)> = Vec::new();
191+
match &mut self.sess{
192+
Some(s) => {
193+
for event in s.events(){
194+
match event {
195+
GGRSEvent::WaitRecommendation { skip_frames } => result.push(("WaitRecommendation", skip_frames.to_variant())),
196+
GGRSEvent::NetworkInterrupted { player_handle, disconnect_timeout} => result.push(("NetworkInterrupted", (player_handle, disconnect_timeout as u64).to_variant())),
197+
GGRSEvent::NetworkResumed { player_handle } => result.push(("NetworkResumed", player_handle.to_variant())),
198+
GGRSEvent::Disconnected { player_handle } => result.push(("Disconnected", player_handle.to_variant())),
199+
GGRSEvent::Synchronized { player_handle } => result.push(("Synchronized", player_handle.to_variant())),
200+
GGRSEvent::Synchronizing { player_handle, total, count} => result.push(("Synchronizing", (player_handle, total, count).to_variant())),
201+
}
202+
}
203+
},
204+
None => godot_error!("{}", ERR_MESSAGE_NO_SESSION_MADE)
205+
};
206+
return result
207+
}
208+
189209
//NON-EXPORTED FUNCTIONS
190210
fn handle_requests(&mut self, requests: Vec<GGRSRequest>) {
191211
for item in requests {
@@ -218,7 +238,7 @@ impl GodotGGRSP2PSession {
218238
.to_variant();
219239
godot_array.push(result);
220240
}
221-
unsafe { node.call("ggrs_advance_frame", &[godot_array.to_variant()]) };
241+
unsafe { node.call(CALLBACK_FUNC_ADVANCE_FRAME, &[godot_array.to_variant()]) };
222242
}
223243
None => {
224244
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -236,7 +256,7 @@ impl GodotGGRSP2PSession {
236256
let buffer =
237257
ByteArray::from_vec(game_state.buffer.unwrap_or_default()).to_variant();
238258
let checksum = game_state.checksum.to_variant();
239-
unsafe { node.call("ggrs_load_game_state", &[frame, buffer, checksum]) };
259+
unsafe { node.call(CALLBACK_FUNC_LOAD_GAME_STATE, &[frame, buffer, checksum]) };
240260
}
241261
None => {
242262
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -250,7 +270,7 @@ impl GodotGGRSP2PSession {
250270
Some(s) => {
251271
let node = unsafe { s.assume_safe() };
252272
let state: Variant =
253-
unsafe { node.call("ggrs_save_game_state", &[frame.to_variant()]) };
273+
unsafe { node.call(CALLBACK_FUNC_SAVE_GAME_STATE, &[frame.to_variant()]) };
254274
let state_bytes = ByteArray::from_variant(&state).unwrap_or_default();
255275
let mut state_bytes_vec = Vec::new();
256276
for i in 0..state_bytes.len() {

src/godotggrs_p2pspectatorsession.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::helper_functions::*;
2-
use gdnative::prelude::*;
1+
use crate::*;
32
use ggrs::*;
43
use std::convert::TryInto;
54
use std::option::*;
@@ -152,6 +151,28 @@ impl GodotGGRSP2PSpectatorSession {
152151
None => godot_error!("{}", ERR_MESSAGE_NO_SESSION_MADE),
153152
}
154153
}
154+
155+
#[export]
156+
fn get_events(&mut self, _owner: &Node)->Vec<(&str, Variant)>{
157+
let mut result: Vec<(&str, Variant)> = Vec::new();
158+
match &mut self.sess{
159+
Some(s) => {
160+
for event in s.events(){
161+
match event {
162+
GGRSEvent::WaitRecommendation { skip_frames } => result.push(("WaitRecommendation", skip_frames.to_variant())),
163+
GGRSEvent::NetworkInterrupted { player_handle, disconnect_timeout} => result.push(("NetworkInterrupted", (player_handle, disconnect_timeout as u64).to_variant())),
164+
GGRSEvent::NetworkResumed { player_handle } => result.push(("NetworkResumed", player_handle.to_variant())),
165+
GGRSEvent::Disconnected { player_handle } => result.push(("Disconnected", player_handle.to_variant())),
166+
GGRSEvent::Synchronized { player_handle } => result.push(("Synchronized", player_handle.to_variant())),
167+
GGRSEvent::Synchronizing { player_handle, total, count} => result.push(("Synchronizing", (player_handle, total, count).to_variant())),
168+
}
169+
}
170+
},
171+
None => godot_error!("{}", ERR_MESSAGE_NO_SESSION_MADE)
172+
};
173+
return result
174+
}
175+
155176
//NON-EXPORTED FUNCTIONS
156177
fn handle_requests(&mut self, requests: Vec<GGRSRequest>) {
157178
for item in requests {
@@ -185,7 +206,7 @@ impl GodotGGRSP2PSpectatorSession {
185206
.to_variant();
186207
godot_array.push(result);
187208
}
188-
unsafe { node.call("ggrs_advance_frame", &[godot_array.to_variant()]) };
209+
unsafe { node.call(CALLBACK_FUNC_ADVANCE_FRAME, &[godot_array.to_variant()]) };
189210
}
190211
None => {
191212
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -203,7 +224,7 @@ impl GodotGGRSP2PSpectatorSession {
203224
let buffer =
204225
ByteArray::from_vec(game_state.buffer.unwrap_or_default()).to_variant();
205226
let checksum = game_state.checksum.to_variant();
206-
unsafe { node.call("ggrs_load_game_state", &[frame, buffer, checksum]) };
227+
unsafe { node.call(CALLBACK_FUNC_LOAD_GAME_STATE, &[frame, buffer, checksum]) };
207228
}
208229
None => {
209230
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -217,7 +238,7 @@ impl GodotGGRSP2PSpectatorSession {
217238
Some(s) => {
218239
let node = unsafe { s.assume_safe() };
219240
let state: Variant =
220-
unsafe { node.call("ggrs_save_game_state", &[frame.to_variant()]) };
241+
unsafe { node.call(CALLBACK_FUNC_SAVE_GAME_STATE, &[frame.to_variant()]) };
221242
let state_bytes = ByteArray::from_variant(&state).unwrap_or_default();
222243
let mut state_bytes_vec = Vec::new();
223244
for i in 0..state_bytes.len() {

src/godotggrs_synctest.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::helper_functions::*;
2-
use gdnative::prelude::*;
1+
use crate::*;
32
use ggrs::*;
43
use std::convert::TryInto;
54

@@ -104,7 +103,7 @@ impl GodotGGRSSyncTest {
104103
.to_variant();
105104
godot_array.push(result);
106105
}
107-
unsafe { node.call("ggrs_advance_frame", &[godot_array.to_variant()]) };
106+
unsafe { node.call(CALLBACK_FUNC_ADVANCE_FRAME, &[godot_array.to_variant()]) };
108107
}
109108
None => {
110109
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -122,7 +121,7 @@ impl GodotGGRSSyncTest {
122121
let buffer =
123122
ByteArray::from_vec(game_state.buffer.unwrap_or_default()).to_variant();
124123
let checksum = game_state.checksum.to_variant();
125-
unsafe { node.call("ggrs_load_game_state", &[frame, buffer, checksum]) };
124+
unsafe { node.call(CALLBACK_FUNC_LOAD_GAME_STATE, &[frame, buffer, checksum]) };
126125
}
127126
None => {
128127
godot_error!("{}", ERR_MESSAGE_NO_CALLBACK_NODE);
@@ -136,7 +135,7 @@ impl GodotGGRSSyncTest {
136135
Some(s) => {
137136
let node = unsafe { s.assume_safe() };
138137
let state: Variant =
139-
unsafe { node.call("ggrs_save_game_state", &[frame.to_variant()]) };
138+
unsafe { node.call(CALLBACK_FUNC_SAVE_GAME_STATE, &[frame.to_variant()]) };
140139
let state_bytes = ByteArray::from_variant(&state).unwrap_or_default();
141140
let mut state_bytes_vec = Vec::new();
142141
for i in 0..state_bytes.len() {

src/helper_functions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//This function can make a hash out of binary data.
2-
pub const ERR_MESSAGE_NO_SESSION_MADE: &str = "No session was made.";
3-
pub const ERR_MESSAGE_NO_CALLBACK_NODE: &str = "No callback node was specified.";
42

53
pub fn fletcher16(data: &[u8]) -> u16 {
64
let mut sum1: u16 = 0;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ mod godotggrs_p2pspectatorsession;
55
mod godotggrs_synctest;
66
mod helper_functions;
77

8+
pub const ERR_MESSAGE_NO_SESSION_MADE: &str = "No session was made.";
9+
pub const ERR_MESSAGE_NO_CALLBACK_NODE: &str = "No callback node was specified.";
10+
pub const CALLBACK_FUNC_SAVE_GAME_STATE: &str = "ggrs_save_game_state";
11+
pub const CALLBACK_FUNC_LOAD_GAME_STATE: &str = "ggrs_load_game_state";
12+
pub const CALLBACK_FUNC_ADVANCE_FRAME: &str = "ggrs_advance_frame";
13+
814
pub fn init_panic_hook() {
915
// To enable backtrace, you will need the `backtrace` crate to be included in your cargo.toml, or
1016
// a version of rust where backtrace is included in the standard library (e.g. Rust nightly as of the date of publishing)

0 commit comments

Comments
 (0)