aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
author1992414357@qq.com <1992414357@qq.com>2025-06-14 19:27:34 +0800
committer1992414357@qq.com <1992414357@qq.com>2025-06-14 19:27:34 +0800
commit4223455b0716871ebf0cfcafaa0e9c350b88cda7 (patch)
tree6b6105f9910e5464673c69523ca23f84e6780e71 /core
parent05807482b074f6402ea94858efebba5e072f0936 (diff)
Update ngpd_player.rs free_player(*FfiPlayer player);
Diffstat (limited to 'core')
-rw-r--r--core/bindings/lang/clang/configures/nogamepads_data_cpp.toml15
-rw-r--r--core/bindings/lang/clang/headers/nogamepads_data.h6
-rw-r--r--core/bindings/lang/clang/headers/nogamepads_data_cpp.h245
-rw-r--r--core/bindings/lang/clang/src/data/ngpd_player.rs32
4 files changed, 284 insertions, 14 deletions
diff --git a/core/bindings/lang/clang/configures/nogamepads_data_cpp.toml b/core/bindings/lang/clang/configures/nogamepads_data_cpp.toml
new file mode 100644
index 0000000..82afbf4
--- /dev/null
+++ b/core/bindings/lang/clang/configures/nogamepads_data_cpp.toml
@@ -0,0 +1,15 @@
+language = "C++"
+include_guard = "NOGAMEPADS_DATA_H"
+header = "// Auto generated by cbindgen 0.29.0"
+cpp_compat = true
+
+[parse]
+parse_deps = true
+include = [
+ "string_converter",
+
+ "ngpd_game_info",
+ "ngpd_message",
+ "ngpd_player",
+ "ngpd_controller",
+] \ No newline at end of file
diff --git a/core/bindings/lang/clang/headers/nogamepads_data.h b/core/bindings/lang/clang/headers/nogamepads_data.h
index 102aaef..81dca74 100644
--- a/core/bindings/lang/clang/headers/nogamepads_data.h
+++ b/core/bindings/lang/clang/headers/nogamepads_data.h
@@ -185,7 +185,7 @@ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double
/**
* Free the player
*/
-void player_free(struct FfiPlayer *player);
+void free_player(struct FfiPlayer *player);
/**
* Free ControlMessage
@@ -268,12 +268,12 @@ void controller_runtime_press_a_button(struct FfiControllerRuntime *runtime, uin
void controller_runtime_release_a_button(struct FfiControllerRuntime *runtime, uint8_t key);
/**
- * Release a button
+ * Change axis value
*/
void controller_runtime_change_axis(struct FfiControllerRuntime *runtime, uint8_t key, double axis);
/**
- * Release a button
+ * Change direction value
*/
void controller_runtime_change_direction(struct FfiControllerRuntime *runtime,
uint8_t key,
diff --git a/core/bindings/lang/clang/headers/nogamepads_data_cpp.h b/core/bindings/lang/clang/headers/nogamepads_data_cpp.h
new file mode 100644
index 0000000..2c128bb
--- /dev/null
+++ b/core/bindings/lang/clang/headers/nogamepads_data_cpp.h
@@ -0,0 +1,245 @@
+// Auto generated by cbindgen 0.29.0
+
+#ifndef NOGAMEPADS_DATA_H
+#define NOGAMEPADS_DATA_H
+
+#include <cstdarg>
+#include <cstdint>
+#include <cstdlib>
+#include <ostream>
+#include <new>
+
+enum class FfiConnectionMessageTag {
+ ConnectionJoin,
+ ConnectionRequestGameInfos,
+ ConnectionRequestLayoutConfigure,
+ ConnectionRequestSkinPackage,
+ ConnectionReady,
+ ConnectionError,
+};
+
+enum class FfiConnectionResponseMessageTag {
+ GameInfosResponse,
+ DenyResponse,
+ FailResponse,
+ OkResponse,
+ WelcomeResponse,
+ ErrorResponse,
+};
+
+enum class FfiControlMessageTag {
+ CtrlMsg,
+ CtrlPressed,
+ CtrlReleased,
+ CtrlAxis,
+ CtrlDir,
+ CtrlExit,
+ CtrlError,
+ CtrlEnd,
+};
+
+enum class FfiExitReason {
+ ExitReason,
+ GameOverReason,
+ ServerClosedReason,
+ YouAreKickedReason,
+ YouAreBannedReason,
+ ErrorReason,
+};
+
+enum class FfiGameMessageTag {
+ GameEventTrigger,
+ GameMsg,
+ GameLetExit,
+ GameError,
+ GameEnd,
+};
+
+enum class FfiJoinFailedMessage {
+ ContainIdenticalPlayer,
+ PlayerBanned,
+ GameLocked,
+ UnknownError,
+};
+
+template<typename T = void>
+struct ManuallyDrop;
+
+struct FfiAccount {
+ char *id;
+ char *player_hash;
+};
+
+struct FfiCustomize {
+ char *nickname;
+ int color_hue;
+ double color_saturation;
+ double color_value;
+};
+
+struct FfiPlayer {
+ FfiAccount account;
+ FfiCustomize *customize;
+};
+
+struct FfiKeyAndAxis {
+ uint8_t key;
+ double axis;
+};
+
+struct FfiKeyAndDirection {
+ uint8_t key;
+ double x;
+ double y;
+};
+
+union FfiControlMessageUnion {
+ char *message;
+ uint8_t key;
+ ManuallyDrop<FfiKeyAndAxis> key_and_axis;
+ ManuallyDrop<FfiKeyAndDirection> key_and_direction;
+};
+
+struct FfiControlMessage {
+ FfiControlMessageTag tag;
+ FfiControlMessageUnion data;
+};
+
+union FfiGameMessageUnion {
+ uint8_t key;
+ char *message;
+ ManuallyDrop<FfiExitReason> exit_reason;
+};
+
+struct FfiGameMessage {
+ FfiGameMessageTag tag;
+ FfiGameMessageUnion data;
+};
+
+union FfiConnectionMessageUnion {
+ ManuallyDrop<FfiPlayer> player;
+};
+
+struct FfiConnectionMessage {
+ FfiConnectionMessageTag tag;
+ FfiConnectionMessageUnion data;
+};
+
+struct KeyValuePair {
+ char *key;
+ char *value;
+};
+
+struct FfiGameInfo {
+ KeyValuePair *data;
+ uintptr_t len;
+ uintptr_t cap;
+};
+
+union FfiConnectionResponseMessageUnion {
+ ManuallyDrop<FfiGameInfo> game_info;
+ ManuallyDrop<FfiJoinFailedMessage> failed_message;
+};
+
+struct FfiConnectionResponseMessage {
+ FfiConnectionResponseMessageTag tag;
+ FfiConnectionResponseMessageUnion data;
+};
+
+struct FfiControllerData {
+ void *_0;
+};
+
+struct FfiControllerRuntime {
+ void *inner;
+ void (*drop_fn)(void*);
+};
+
+extern "C" {
+
+void free_c_string(char *ptr);
+
+/// Register a player
+FfiPlayer *player_register(const char *id, const char *password);
+
+/// Check if the player's password is correct
+bool player_check(const FfiPlayer *player, const char *password);
+
+/// Set the player's nickname
+void player_set_nickname(FfiPlayer *player, const char *nickname);
+
+/// Set the player's hue
+void player_set_hue(FfiPlayer *player, int hue);
+
+/// Set the player's HSV color
+void player_set_hsv(FfiPlayer *player, int hue, double saturation, double value);
+
+/// Free the player
+void free_player(FfiPlayer *player);
+
+/// Free ControlMessage
+void free_control_message(FfiControlMessage msg);
+
+/// Free GameMessage
+void free_game_message(FfiGameMessage msg);
+
+/// Free ExitReason
+void free_exit_reason(FfiExitReason msg);
+
+/// Free ConnectionMessage
+void free_connection_message(FfiConnectionMessage msg);
+
+/// Free ConnectionResponseMessage
+void free_connection_response_message(FfiConnectionResponseMessage msg);
+
+/// Free JoinFailedMessage
+void free_join_failed_message(FfiJoinFailedMessage msg);
+
+void free_game_info(FfiGameInfo map);
+
+/// Create controller data
+FfiControllerData *controller_data_new();
+
+/// Bind player to controller
+void controller_data_bind_player(FfiControllerData *controller, FfiPlayer *ffi_player);
+
+/// Build runtime
+FfiControllerRuntime *controller_data_build_runtime(FfiControllerData *controller);
+
+/// Free ControllerData memory
+void controller_data_free(FfiControllerData *controller);
+
+/// Close runtime and exit game
+void controller_runtime_close(FfiControllerRuntime *runtime);
+
+/// Send control message
+void controller_runtime_send_message(FfiControllerRuntime *runtime,
+ FfiControlMessage *control_message);
+
+/// Send text message
+void controller_runtime_send_text_message(FfiControllerRuntime *runtime, const char *message_ptr);
+
+/// Press a button
+void controller_runtime_press_a_button(FfiControllerRuntime *runtime, uint8_t key);
+
+/// Release a button
+void controller_runtime_release_a_button(FfiControllerRuntime *runtime, uint8_t key);
+
+/// Change axis value
+void controller_runtime_change_axis(FfiControllerRuntime *runtime, uint8_t key, double axis);
+
+/// Change direction value
+void controller_runtime_change_direction(FfiControllerRuntime *runtime,
+ uint8_t key,
+ double x,
+ double y);
+
+/// Pop a message from the queue
+FfiGameMessage *controller_runtime_pop(FfiControllerRuntime *runtime);
+
+/// Free runtime memory
+void controller_runtime_free(FfiControllerRuntime *runtime);
+
+} // extern "C"
+
+#endif // NOGAMEPADS_DATA_H
diff --git a/core/bindings/lang/clang/src/data/ngpd_player.rs b/core/bindings/lang/clang/src/data/ngpd_player.rs
index 3f6a84a..c2c3378 100644
--- a/core/bindings/lang/clang/src/data/ngpd_player.rs
+++ b/core/bindings/lang/clang/src/data/ngpd_player.rs
@@ -125,20 +125,30 @@ pub extern "C" fn player_set_hsv(
/// Free the player
#[unsafe(no_mangle)]
-pub extern "C" fn player_free(player: *mut FfiPlayer) {
+pub extern "C" fn free_player(player: *mut FfiPlayer) {
if player.is_null() { return; }
- let ffi_player = unsafe { Box::from_raw(player) };
-
- // Free account strings
unsafe {
- let _ = CString::from_raw(ffi_player.account.id);
- let _ = CString::from_raw(ffi_player.account.player_hash);
- }
+ let player = &mut *player;
+
+ if !player.account.id.is_null() {
+ drop(CString::from_raw(player.account.id));
+ player.account.id = ptr::null_mut();
+ }
+
+ if !player.account.player_hash.is_null() {
+ drop(CString::from_raw(player.account.player_hash));
+ player.account.player_hash = ptr::null_mut();
+ }
+
+ if !player.customize.is_null() {
+ let customize = &mut *player.customize;
+ if !customize.nickname.is_null() {
+ drop(CString::from_raw(customize.nickname));
+ }
+ player.customize = ptr::null_mut();
+ }
- // Free customize if present
- if !ffi_player.customize.is_null() {
- let ffi_custom = unsafe { Box::from_raw(ffi_player.customize) };
- unsafe { let _ = CString::from_raw(ffi_custom.nickname); };
+ drop(Box::from_raw(player));
}
} \ No newline at end of file