From 398d84dd09448d5a7ff41fd5086f3636635d015e Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 01:57:42 +0800
Subject: Update Project_Export.toml
---
Project_Export.toml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Project_Export.toml b/Project_Export.toml
index 50896b1..5261a7b 100644
--- a/Project_Export.toml
+++ b/Project_Export.toml
@@ -31,5 +31,6 @@ win_exes = { raw = "./", target = "./bin", files = [
# Windows dynamic link libraries
dlls = { raw = "./", target = "./lib", files = [
- "nogamepads_c.dll"
+ "nogamepads_c.dll",
+ "nogamepads_c.dll.lib"
] }
\ No newline at end of file
--
cgit
From 3c7e2a2836649667643698278ebda2fd7cb3215b Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 01:58:54 +0800
Subject: Ignore export/dev/
---
.idea/NoGamepads.iml | 1 +
export/.gitignore | 4 +---
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/.idea/NoGamepads.iml b/.idea/NoGamepads.iml
index e375e39..4f201f0 100644
--- a/.idea/NoGamepads.iml
+++ b/.idea/NoGamepads.iml
@@ -16,6 +16,7 @@
+
diff --git a/export/.gitignore b/export/.gitignore
index dc96378..bd18915 100644
--- a/export/.gitignore
+++ b/export/.gitignore
@@ -3,8 +3,6 @@
!Cargo.toml
!src/
!src/**
-!dev/
-!dev/**
!docs/
!docs/**
-/dev/bin/pad.exe
\ No newline at end of file
+/dev/
--
cgit
From 75503a507f6c4a06d138c590273e27be42d3bf74 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:02:08 +0800
Subject: Removed Core Examples
---
core/examples/connect.rs | 27 ---------------------------
core/examples/tcp_server.rs | 43 -------------------------------------------
2 files changed, 70 deletions(-)
delete mode 100644 core/examples/connect.rs
delete mode 100644 core/examples/tcp_server.rs
diff --git a/core/examples/connect.rs b/core/examples/connect.rs
deleted file mode 100644
index e6f70c4..0000000
--- a/core/examples/connect.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-use std::sync::Arc;
-use log::LevelFilter::Trace;
-use nogamepads::logger_utils::logger_build;
-use nogamepads_core::data::controller::structs::ControllerData;
-use nogamepads_core::data::player::structs::Player;
-use nogamepads_core::service::tcp_network::pad_client::structs::PadClientNetwork;
-use nogamepads_core::service::tcp_network::utils::tokio_utils::build_tokio_runtime;
-
-fn main () {
- logger_build(Trace);
-
- let mut player = Player::register(
- env!("TEST_PLAYER_ACCOUNT").to_string(),
- env!("TEST_PLAYER_PASSWORD").to_string()
- );
-
- player.nickname(&env!("TEST_PLAYER_NICKNAME").to_string());
-
- let mut controller = ControllerData::default();
- controller.bind_player(player);
-
- let runtime = controller.runtime();
-
- let client = PadClientNetwork::build(Arc::clone(&runtime));
-
- build_tokio_runtime("Tokio Runtime".to_string()).block_on(client.build_entry())
-}
\ No newline at end of file
diff --git a/core/examples/tcp_server.rs b/core/examples/tcp_server.rs
deleted file mode 100644
index 87e63c8..0000000
--- a/core/examples/tcp_server.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-use clap::CommandFactory;
-use nogamepads::logger_utils::logger_build;
-use nogamepads_core::data::game::game_cli::{process_game_cli, GameCli};
-use nogamepads_core::data::game::structs::{GameData, GameRuntimeDataArchive};
-use nogamepads_core::run_services;
-use nogamepads_core::service::cli_addition::runtime_consoles::RuntimeConsole;
-use nogamepads_core::service::tcp_network::pad_server::structs::PadServerNetwork;
-use std::sync::Arc;
-use log::LevelFilter::Trace;
-
-fn main () {
- logger_build(Trace);
-
- // Initialize game data
- let mut game = GameData::new();
- game.name("My Game".to_string());
- game.version("0.1".to_string());
- game.load_data(
- GameRuntimeDataArchive {
- banned: vec![],
- }
- );
-
- // Generate runtime from game data
- let runtime = game.runtime();
-
- // Establish TCP pad_server using runtime
- let tcp_server = PadServerNetwork::build(Arc::clone(&runtime));
-
- let server = tcp_server.build_entry();
-
- // Cmd
- let cmd = RuntimeConsole::build(
- GameCli::command(),
- "gamecli".to_string(),
- Arc::clone(&runtime),
- |runtime, cmd: GameCli| {
- process_game_cli(runtime, cmd)
- }
- ).build_entry();
-
- run_services!(server, cmd);
-}
\ No newline at end of file
--
cgit
From c1c7d3af8479e2bb879bc9325da2952cf6db6493 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:06:18 +0800
Subject: Move crate nogamepads-c-bindings to ./core/bindings/lang/clang
---
.idea/NoGamepads.iml | 1 +
Cargo.toml | 2 +-
core/bindings/c_lang/Cargo.toml | 12 --
core/bindings/c_lang/headers/ngpd_player.h | 39 -------
core/bindings/c_lang/src/data/mod.rs | 1 -
core/bindings/c_lang/src/data/ngpd_player.rs | 139 -----------------------
core/bindings/c_lang/src/lib.rs | 1 -
core/bindings/lang/clang/Cargo.toml | 12 ++
core/bindings/lang/clang/headers/ngpd_player.h | 39 +++++++
core/bindings/lang/clang/src/data/mod.rs | 1 +
core/bindings/lang/clang/src/data/ngpd_player.rs | 139 +++++++++++++++++++++++
core/bindings/lang/clang/src/lib.rs | 1 +
12 files changed, 194 insertions(+), 193 deletions(-)
delete mode 100644 core/bindings/c_lang/Cargo.toml
delete mode 100644 core/bindings/c_lang/headers/ngpd_player.h
delete mode 100644 core/bindings/c_lang/src/data/mod.rs
delete mode 100644 core/bindings/c_lang/src/data/ngpd_player.rs
delete mode 100644 core/bindings/c_lang/src/lib.rs
create mode 100644 core/bindings/lang/clang/Cargo.toml
create mode 100644 core/bindings/lang/clang/headers/ngpd_player.h
create mode 100644 core/bindings/lang/clang/src/data/mod.rs
create mode 100644 core/bindings/lang/clang/src/data/ngpd_player.rs
create mode 100644 core/bindings/lang/clang/src/lib.rs
diff --git a/.idea/NoGamepads.iml b/.idea/NoGamepads.iml
index 4f201f0..8cf1343 100644
--- a/.idea/NoGamepads.iml
+++ b/.idea/NoGamepads.iml
@@ -8,6 +8,7 @@
+
diff --git a/Cargo.toml b/Cargo.toml
index 10b8c93..5baad5e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,7 +18,7 @@ members = [
"apps/client",
"export",
- "core/bindings/c_lang"
+ "core/bindings/lang/clang"
]
[workspace.package]
diff --git a/core/bindings/c_lang/Cargo.toml b/core/bindings/c_lang/Cargo.toml
deleted file mode 100644
index a0ee61f..0000000
--- a/core/bindings/c_lang/Cargo.toml
+++ /dev/null
@@ -1,12 +0,0 @@
-[package]
-name = "nogamepads-c-bindings"
-edition = "2024"
-version.workspace = true
-
-[dependencies]
-nogamepads-core = { path = "../../../core" }
-libc = "0.2.172"
-
-[lib]
-name = "nogamepads_c"
-crate-type = ["cdylib"]
diff --git a/core/bindings/c_lang/headers/ngpd_player.h b/core/bindings/c_lang/headers/ngpd_player.h
deleted file mode 100644
index 00fbe5b..0000000
--- a/core/bindings/c_lang/headers/ngpd_player.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef PLAYER_FFI_H
-#define PLAYER_FFI_H
-
-#include
-#include
-
-typedef struct FfiAccount {
- char* id;
- char* player_hash;
-} FfiAccount;
-
-typedef struct FfiCustomize {
- char* nickname;
- int32_t color_hue;
- double color_saturation;
- double color_value;
-} FfiCustomize;
-
-typedef struct FfiPlayer {
- FfiAccount account;
- FfiCustomize* customize;
-} FfiPlayer;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-FfiPlayer* player_register(const char* id, const char* password);
-bool player_check(const FfiPlayer* player, const char* password);
-void player_set_nickname(FfiPlayer* player, const char* nickname);
-void player_set_hue(FfiPlayer* player, int hue);
-void player_set_hsv(FfiPlayer* player, int hue, double saturation, double value);
-void player_free(FfiPlayer* player);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file
diff --git a/core/bindings/c_lang/src/data/mod.rs b/core/bindings/c_lang/src/data/mod.rs
deleted file mode 100644
index 32af6d8..0000000
--- a/core/bindings/c_lang/src/data/mod.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod ngpd_player;
\ No newline at end of file
diff --git a/core/bindings/c_lang/src/data/ngpd_player.rs b/core/bindings/c_lang/src/data/ngpd_player.rs
deleted file mode 100644
index 2ab615c..0000000
--- a/core/bindings/c_lang/src/data/ngpd_player.rs
+++ /dev/null
@@ -1,139 +0,0 @@
-use std::ffi::{CStr, CString};
-use std::os::raw::{c_char, c_double, c_int};
-use std::ptr;
-use nogamepads_core::data::player::player_data::{Account, Customize, Player};
-
-#[repr(C)]
-pub struct FfiAccount {
- id: *mut c_char,
- player_hash: *mut c_char,
-}
-
-#[repr(C)]
-pub struct FfiCustomize {
- nickname: *mut c_char,
- color_hue: c_int,
- color_saturation: c_double,
- color_value: c_double,
-}
-
-#[repr(C)]
-pub struct FfiPlayer {
- account: FfiAccount,
- customize: *mut FfiCustomize,
-}
-
-impl From for FfiAccount {
- fn from(acc: Account) -> Self {
- FfiAccount {
- id: CString::new(acc.id).unwrap().into_raw(),
- player_hash: CString::new(acc.player_hash).unwrap().into_raw(),
- }
- }
-}
-
-impl From for FfiPlayer {
- fn from(player: Player) -> Self {
- let account = FfiAccount::from(player.account);
- let customize = player.customize.map(|c| {
- Box::into_raw(Box::new(FfiCustomize {
- nickname: CString::new(c.nickname).unwrap().into_raw(),
- color_hue: c.color_hue,
- color_saturation: c.color_saturation,
- color_value: c.color_value,
- }))
- }).unwrap_or(ptr::null_mut());
-
- FfiPlayer { account, customize }
- }
-}
-
-impl TryFrom<&FfiPlayer> for Player {
- type Error = ();
-
- fn try_from(ffi: &FfiPlayer) -> Result {
- let account = Account {
- id: unsafe { CStr::from_ptr(ffi.account.id) }.to_str().map_err(|_| ())?.to_owned(),
- player_hash: unsafe { CStr::from_ptr(ffi.account.player_hash) }.to_str().map_err(|_| ())?.to_owned(),
- };
-
- let customize = if !ffi.customize.is_null() {
- let c = unsafe { &*ffi.customize };
- Some(Customize {
- nickname: unsafe { CStr::from_ptr(c.nickname) }.to_str().map_err(|_| ())?.to_owned(),
- color_hue: c.color_hue,
- color_saturation: c.color_saturation,
- color_value: c.color_value,
- })
- } else {
- None
- };
-
- Ok(Player { account, customize })
- }
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_register(id: *const c_char, password: *const c_char) -> *mut FfiPlayer {
- let id_str = unsafe { CStr::from_ptr(id) }.to_string_lossy();
- let pass_str = unsafe { CStr::from_ptr(password) }.to_string_lossy();
-
- let player = Player::register(id_str.into_owned(), pass_str.into_owned());
- Box::into_raw(Box::new(FfiPlayer::from(player)))
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_check(player: *const FfiPlayer, password: *const c_char) -> bool {
- let player = unsafe { &*player };
- let pass_str = unsafe { CStr::from_ptr(password) }.to_string_lossy();
-
- Player::try_from(player)
- .map(|p| p.check(pass_str.into_owned()))
- .unwrap_or(false)
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_set_nickname(player: *mut FfiPlayer, nickname: *const c_char) {
- let nickname_str = unsafe { CStr::from_ptr(nickname) }.to_string_lossy().into_owned();
- let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
-
- rust_player.nickname(&nickname_str);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_set_hue(player: *mut FfiPlayer, hue: c_int) {
- let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
-
- rust_player.hue(hue);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_set_hsv(
- player: *mut FfiPlayer, hue: c_int, saturation: c_double, value: c_double
-) {
- let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
-
- rust_player.hsv(hue, saturation, value);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn player_free(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);
- }
-
- // 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); };
- }
-}
\ No newline at end of file
diff --git a/core/bindings/c_lang/src/lib.rs b/core/bindings/c_lang/src/lib.rs
deleted file mode 100644
index 12e35bb..0000000
--- a/core/bindings/c_lang/src/lib.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod data;
\ No newline at end of file
diff --git a/core/bindings/lang/clang/Cargo.toml b/core/bindings/lang/clang/Cargo.toml
new file mode 100644
index 0000000..34d1fed
--- /dev/null
+++ b/core/bindings/lang/clang/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "nogamepads-c-bindings"
+edition = "2024"
+version.workspace = true
+
+[dependencies]
+nogamepads-core = { path = "./../../../../core" }
+libc = "0.2.172"
+
+[lib]
+name = "nogamepads_c"
+crate-type = ["cdylib"]
diff --git a/core/bindings/lang/clang/headers/ngpd_player.h b/core/bindings/lang/clang/headers/ngpd_player.h
new file mode 100644
index 0000000..00fbe5b
--- /dev/null
+++ b/core/bindings/lang/clang/headers/ngpd_player.h
@@ -0,0 +1,39 @@
+#ifndef PLAYER_FFI_H
+#define PLAYER_FFI_H
+
+#include
+#include
+
+typedef struct FfiAccount {
+ char* id;
+ char* player_hash;
+} FfiAccount;
+
+typedef struct FfiCustomize {
+ char* nickname;
+ int32_t color_hue;
+ double color_saturation;
+ double color_value;
+} FfiCustomize;
+
+typedef struct FfiPlayer {
+ FfiAccount account;
+ FfiCustomize* customize;
+} FfiPlayer;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+FfiPlayer* player_register(const char* id, const char* password);
+bool player_check(const FfiPlayer* player, const char* password);
+void player_set_nickname(FfiPlayer* player, const char* nickname);
+void player_set_hue(FfiPlayer* player, int hue);
+void player_set_hsv(FfiPlayer* player, int hue, double saturation, double value);
+void player_free(FfiPlayer* player);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/mod.rs b/core/bindings/lang/clang/src/data/mod.rs
new file mode 100644
index 0000000..32af6d8
--- /dev/null
+++ b/core/bindings/lang/clang/src/data/mod.rs
@@ -0,0 +1 @@
+pub mod ngpd_player;
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/ngpd_player.rs b/core/bindings/lang/clang/src/data/ngpd_player.rs
new file mode 100644
index 0000000..2ab615c
--- /dev/null
+++ b/core/bindings/lang/clang/src/data/ngpd_player.rs
@@ -0,0 +1,139 @@
+use std::ffi::{CStr, CString};
+use std::os::raw::{c_char, c_double, c_int};
+use std::ptr;
+use nogamepads_core::data::player::player_data::{Account, Customize, Player};
+
+#[repr(C)]
+pub struct FfiAccount {
+ id: *mut c_char,
+ player_hash: *mut c_char,
+}
+
+#[repr(C)]
+pub struct FfiCustomize {
+ nickname: *mut c_char,
+ color_hue: c_int,
+ color_saturation: c_double,
+ color_value: c_double,
+}
+
+#[repr(C)]
+pub struct FfiPlayer {
+ account: FfiAccount,
+ customize: *mut FfiCustomize,
+}
+
+impl From for FfiAccount {
+ fn from(acc: Account) -> Self {
+ FfiAccount {
+ id: CString::new(acc.id).unwrap().into_raw(),
+ player_hash: CString::new(acc.player_hash).unwrap().into_raw(),
+ }
+ }
+}
+
+impl From for FfiPlayer {
+ fn from(player: Player) -> Self {
+ let account = FfiAccount::from(player.account);
+ let customize = player.customize.map(|c| {
+ Box::into_raw(Box::new(FfiCustomize {
+ nickname: CString::new(c.nickname).unwrap().into_raw(),
+ color_hue: c.color_hue,
+ color_saturation: c.color_saturation,
+ color_value: c.color_value,
+ }))
+ }).unwrap_or(ptr::null_mut());
+
+ FfiPlayer { account, customize }
+ }
+}
+
+impl TryFrom<&FfiPlayer> for Player {
+ type Error = ();
+
+ fn try_from(ffi: &FfiPlayer) -> Result {
+ let account = Account {
+ id: unsafe { CStr::from_ptr(ffi.account.id) }.to_str().map_err(|_| ())?.to_owned(),
+ player_hash: unsafe { CStr::from_ptr(ffi.account.player_hash) }.to_str().map_err(|_| ())?.to_owned(),
+ };
+
+ let customize = if !ffi.customize.is_null() {
+ let c = unsafe { &*ffi.customize };
+ Some(Customize {
+ nickname: unsafe { CStr::from_ptr(c.nickname) }.to_str().map_err(|_| ())?.to_owned(),
+ color_hue: c.color_hue,
+ color_saturation: c.color_saturation,
+ color_value: c.color_value,
+ })
+ } else {
+ None
+ };
+
+ Ok(Player { account, customize })
+ }
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_register(id: *const c_char, password: *const c_char) -> *mut FfiPlayer {
+ let id_str = unsafe { CStr::from_ptr(id) }.to_string_lossy();
+ let pass_str = unsafe { CStr::from_ptr(password) }.to_string_lossy();
+
+ let player = Player::register(id_str.into_owned(), pass_str.into_owned());
+ Box::into_raw(Box::new(FfiPlayer::from(player)))
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_check(player: *const FfiPlayer, password: *const c_char) -> bool {
+ let player = unsafe { &*player };
+ let pass_str = unsafe { CStr::from_ptr(password) }.to_string_lossy();
+
+ Player::try_from(player)
+ .map(|p| p.check(pass_str.into_owned()))
+ .unwrap_or(false)
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_set_nickname(player: *mut FfiPlayer, nickname: *const c_char) {
+ let nickname_str = unsafe { CStr::from_ptr(nickname) }.to_string_lossy().into_owned();
+ let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
+
+ rust_player.nickname(&nickname_str);
+ *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_set_hue(player: *mut FfiPlayer, hue: c_int) {
+ let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
+
+ rust_player.hue(hue);
+ *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_set_hsv(
+ player: *mut FfiPlayer, hue: c_int, saturation: c_double, value: c_double
+) {
+ let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
+
+ rust_player.hsv(hue, saturation, value);
+ *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn player_free(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);
+ }
+
+ // 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); };
+ }
+}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/lib.rs b/core/bindings/lang/clang/src/lib.rs
new file mode 100644
index 0000000..12e35bb
--- /dev/null
+++ b/core/bindings/lang/clang/src/lib.rs
@@ -0,0 +1 @@
+pub mod data;
\ No newline at end of file
--
cgit
From d780a3a78324e341ad2e706f389e6ffe825d1f8f Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:25:18 +0800
Subject: Add Idea Run Configuration "Build C Bindings"
---
.idea/runConfigurations/Build_C_Bindings.xml | 18 ++++++++++++++++++
.idea/runConfigurations/Build_C_Bindings__Dev_.xml | 18 ++++++++++++++++++
2 files changed, 36 insertions(+)
create mode 100644 .idea/runConfigurations/Build_C_Bindings.xml
create mode 100644 .idea/runConfigurations/Build_C_Bindings__Dev_.xml
diff --git a/.idea/runConfigurations/Build_C_Bindings.xml b/.idea/runConfigurations/Build_C_Bindings.xml
new file mode 100644
index 0000000..26db07f
--- /dev/null
+++ b/.idea/runConfigurations/Build_C_Bindings.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Build_C_Bindings__Dev_.xml b/.idea/runConfigurations/Build_C_Bindings__Dev_.xml
new file mode 100644
index 0000000..e44c9f5
--- /dev/null
+++ b/.idea/runConfigurations/Build_C_Bindings__Dev_.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--
cgit
From 4fe9d04c7a6bee883ff8181930f30a7d9148a650 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:26:22 +0800
Subject: Added the functionality to automatically generate header files.
---
Cargo.lock | 56 +++++++++++++++++++++++++-
Project_Export.toml | 4 +-
core/bindings/lang/clang/Cargo.toml | 7 +++-
core/bindings/lang/clang/Generate.toml | 11 +++++
core/bindings/lang/clang/build.rs | 34 ++++++++++++++++
core/bindings/lang/clang/headers/ngpd_player.h | 39 ------------------
core/bindings/lang/clang/headers/nogamepads.h | 48 ++++++++++++++++++++++
7 files changed, 156 insertions(+), 43 deletions(-)
create mode 100644 core/bindings/lang/clang/Generate.toml
create mode 100644 core/bindings/lang/clang/build.rs
delete mode 100644 core/bindings/lang/clang/headers/ngpd_player.h
create mode 100644 core/bindings/lang/clang/headers/nogamepads.h
diff --git a/Cargo.lock b/Cargo.lock
index 459802c..6b30ef4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1580,6 +1580,25 @@ dependencies = [
"thiserror 1.0.69",
]
+[[package]]
+name = "cbindgen"
+version = "0.29.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684"
+dependencies = [
+ "clap",
+ "heck",
+ "indexmap",
+ "log",
+ "proc-macro2",
+ "quote",
+ "serde",
+ "serde_json",
+ "syn",
+ "tempfile",
+ "toml 0.8.22",
+]
+
[[package]]
name = "cc"
version = "1.2.24"
@@ -3207,6 +3226,7 @@ dependencies = [
name = "nogamepads-c-bindings"
version = "0.1.0"
dependencies = [
+ "cbindgen",
"libc",
"nogamepads-core",
]
@@ -3261,7 +3281,7 @@ version = "0.0.0"
dependencies = [
"nogamepads",
"serde",
- "toml",
+ "toml 0.7.8",
]
[[package]]
@@ -4495,6 +4515,19 @@ dependencies = [
"slotmap",
]
+[[package]]
+name = "tempfile"
+version = "3.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
+dependencies = [
+ "fastrand",
+ "getrandom 0.3.3",
+ "once_cell",
+ "rustix 1.0.7",
+ "windows-sys 0.59.0",
+]
+
[[package]]
name = "termcolor"
version = "1.4.1"
@@ -4622,6 +4655,18 @@ dependencies = [
"toml_edit 0.19.15",
]
+[[package]]
+name = "toml"
+version = "0.8.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit 0.22.26",
+]
+
[[package]]
name = "toml_datetime"
version = "0.6.9"
@@ -4651,10 +4696,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e"
dependencies = [
"indexmap",
+ "serde",
+ "serde_spanned",
"toml_datetime",
+ "toml_write",
"winnow 0.7.10",
]
+[[package]]
+name = "toml_write"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
+
[[package]]
name = "tracing"
version = "0.1.41"
diff --git a/Project_Export.toml b/Project_Export.toml
index 5261a7b..5d09f89 100644
--- a/Project_Export.toml
+++ b/Project_Export.toml
@@ -16,8 +16,8 @@ powershell_complete = { raw = "./.cargo/resources/scripts/", target = "./bin/com
] }
# Headers
-headers = { raw = "./core/bindings/c_lang/headers/", target = "./lib", files = [
- "ngpd_player.h"
+headers = { raw = "./core/bindings/lang/clang/headers/", target = "./lib", files = [
+ "nogamepads.h"
] }
# Items defined in [release.deps]
diff --git a/core/bindings/lang/clang/Cargo.toml b/core/bindings/lang/clang/Cargo.toml
index 34d1fed..e094413 100644
--- a/core/bindings/lang/clang/Cargo.toml
+++ b/core/bindings/lang/clang/Cargo.toml
@@ -3,10 +3,15 @@ name = "nogamepads-c-bindings"
edition = "2024"
version.workspace = true
+build = "build.rs"
+
[dependencies]
nogamepads-core = { path = "./../../../../core" }
libc = "0.2.172"
+[build-dependencies]
+cbindgen = "0.29.0"
+
[lib]
name = "nogamepads_c"
-crate-type = ["cdylib"]
+crate-type = ["cdylib", "rlib"]
diff --git a/core/bindings/lang/clang/Generate.toml b/core/bindings/lang/clang/Generate.toml
new file mode 100644
index 0000000..08d8b00
--- /dev/null
+++ b/core/bindings/lang/clang/Generate.toml
@@ -0,0 +1,11 @@
+language = "C"
+include_guard = "NOGAMEPADS_H"
+header = "// Auto generated by cbindgen 0.29.0"
+cpp_compat = true
+
+[parse]
+parse_deps = true
+include = ["*"]
+
+[fn]
+prefix = "ngp_"
\ No newline at end of file
diff --git a/core/bindings/lang/clang/build.rs b/core/bindings/lang/clang/build.rs
new file mode 100644
index 0000000..c43ee7f
--- /dev/null
+++ b/core/bindings/lang/clang/build.rs
@@ -0,0 +1,34 @@
+fn main() {
+
+ // Get the project root directory
+ let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
+ let root_path = std::path::Path::new(&manifest_dir);
+
+ // Input configuration file path
+ let config_path = root_path.join("Generate.toml");
+
+ // Output directory path (headers folder in the crate directory)
+ let headers_dir = root_path.join("headers");
+
+ // Create the headers directory (if it does not exist)
+ std::fs::create_dir_all(&headers_dir).expect("Failed to create headers directory");
+
+ // Output file path
+ let output_file = headers_dir.join("nogamepads.h");
+
+ // Load configuration from Generate.toml
+ let config = cbindgen::Config::from_file(&config_path)
+ .expect("Failed to parse Generate.toml configuration");
+
+ // Generate header file
+ cbindgen::Builder::new()
+ .with_crate(manifest_dir)
+ .with_config(config)
+ .generate()
+ .expect("Failed to generate C header file")
+ .write_to_file(&output_file);
+
+ println!("cargo:rerun-if-changed={}", config_path.display());
+ println!("cargo:rerun-if-changed=src/mycode.rs");
+ println!("cargo:rerun-if-changed=build.rs");
+}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/headers/ngpd_player.h b/core/bindings/lang/clang/headers/ngpd_player.h
deleted file mode 100644
index 00fbe5b..0000000
--- a/core/bindings/lang/clang/headers/ngpd_player.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef PLAYER_FFI_H
-#define PLAYER_FFI_H
-
-#include
-#include
-
-typedef struct FfiAccount {
- char* id;
- char* player_hash;
-} FfiAccount;
-
-typedef struct FfiCustomize {
- char* nickname;
- int32_t color_hue;
- double color_saturation;
- double color_value;
-} FfiCustomize;
-
-typedef struct FfiPlayer {
- FfiAccount account;
- FfiCustomize* customize;
-} FfiPlayer;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-FfiPlayer* player_register(const char* id, const char* password);
-bool player_check(const FfiPlayer* player, const char* password);
-void player_set_nickname(FfiPlayer* player, const char* nickname);
-void player_set_hue(FfiPlayer* player, int hue);
-void player_set_hsv(FfiPlayer* player, int hue, double saturation, double value);
-void player_free(FfiPlayer* player);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file
diff --git a/core/bindings/lang/clang/headers/nogamepads.h b/core/bindings/lang/clang/headers/nogamepads.h
new file mode 100644
index 0000000..f1ac85a
--- /dev/null
+++ b/core/bindings/lang/clang/headers/nogamepads.h
@@ -0,0 +1,48 @@
+// 自动生成的头文件 - 请勿手动编辑
+
+#ifndef NOGAMEPADS_H
+#define NOGAMEPADS_H
+
+#include
+#include
+#include
+#include
+
+typedef struct FfiAccount {
+ char *id;
+ char *player_hash;
+} FfiAccount;
+
+typedef struct FfiCustomize {
+ char *nickname;
+ int color_hue;
+ double color_saturation;
+ double color_value;
+} FfiCustomize;
+
+typedef struct FfiPlayer {
+ struct FfiAccount account;
+ struct FfiCustomize *customize;
+} FfiPlayer;
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+ngp_ struct FfiPlayer *player_register(const char *id, const char *password);
+
+ngp_ bool player_check(const struct FfiPlayer *player, const char *password);
+
+ngp_ void player_set_nickname(struct FfiPlayer *player, const char *nickname);
+
+ngp_ void player_set_hue(struct FfiPlayer *player, int hue);
+
+ngp_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double value);
+
+ngp_ void player_free(struct FfiPlayer *player);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+#endif /* NOGAMEPADS_H */
--
cgit
From c0c09ef66dd15f209d58dfe64c0c60e64188eb63 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:28:07 +0800
Subject: Modify part of the Run Configuration settings.
---
.idea/NoGamepads.iml | 2 ++
.idea/runConfigurations/Build_All.xml | 2 +-
.idea/runConfigurations/Build_All__Dev_.xml | 2 +-
.idea/runConfigurations/Build_Bevy_Client__Dev_.xml | 3 ++-
.idea/runConfigurations/Build_Console__Dev_.xml | 2 +-
.idea/runConfigurations/Build_Core__Dev_.xml | 2 +-
6 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/.idea/NoGamepads.iml b/.idea/NoGamepads.iml
index 8cf1343..ec9cc89 100644
--- a/.idea/NoGamepads.iml
+++ b/.idea/NoGamepads.iml
@@ -10,6 +10,8 @@
+
+
diff --git a/.idea/runConfigurations/Build_All.xml b/.idea/runConfigurations/Build_All.xml
index 63caef9..2ad3d29 100644
--- a/.idea/runConfigurations/Build_All.xml
+++ b/.idea/runConfigurations/Build_All.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/.idea/runConfigurations/Build_All__Dev_.xml b/.idea/runConfigurations/Build_All__Dev_.xml
index 4e55ed1..2d8b762 100644
--- a/.idea/runConfigurations/Build_All__Dev_.xml
+++ b/.idea/runConfigurations/Build_All__Dev_.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/.idea/runConfigurations/Build_Bevy_Client__Dev_.xml b/.idea/runConfigurations/Build_Bevy_Client__Dev_.xml
index 580a378..985f1be 100644
--- a/.idea/runConfigurations/Build_Bevy_Client__Dev_.xml
+++ b/.idea/runConfigurations/Build_Bevy_Client__Dev_.xml
@@ -1,6 +1,7 @@
-
+
+
diff --git a/.idea/runConfigurations/Build_Console__Dev_.xml b/.idea/runConfigurations/Build_Console__Dev_.xml
index 50cc9a7..9e47a3d 100644
--- a/.idea/runConfigurations/Build_Console__Dev_.xml
+++ b/.idea/runConfigurations/Build_Console__Dev_.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/.idea/runConfigurations/Build_Core__Dev_.xml b/.idea/runConfigurations/Build_Core__Dev_.xml
index 4099321..6d89987 100644
--- a/.idea/runConfigurations/Build_Core__Dev_.xml
+++ b/.idea/runConfigurations/Build_Core__Dev_.xml
@@ -1,6 +1,6 @@
-
+
--
cgit
From f6c6aa60bab42a64aa4e643849d8210e6b490811 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:28:38 +0800
Subject: Removed unused deps "libc"
---
core/bindings/lang/clang/Cargo.toml | 1 -
1 file changed, 1 deletion(-)
diff --git a/core/bindings/lang/clang/Cargo.toml b/core/bindings/lang/clang/Cargo.toml
index e094413..7359db0 100644
--- a/core/bindings/lang/clang/Cargo.toml
+++ b/core/bindings/lang/clang/Cargo.toml
@@ -7,7 +7,6 @@ build = "build.rs"
[dependencies]
nogamepads-core = { path = "./../../../../core" }
-libc = "0.2.172"
[build-dependencies]
cbindgen = "0.29.0"
--
cgit
From de4ed133923190699d2d67019e5e2a0965f42014 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 02:28:43 +0800
Subject: Removed unused deps "libc"
---
Cargo.lock | 1 -
1 file changed, 1 deletion(-)
diff --git a/Cargo.lock b/Cargo.lock
index 6b30ef4..8d0c110 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3227,7 +3227,6 @@ name = "nogamepads-c-bindings"
version = "0.1.0"
dependencies = [
"cbindgen",
- "libc",
"nogamepads-core",
]
--
cgit
From b8eb9924965180dbc236fbda4bc4a8041a10c6a6 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 04:20:11 +0800
Subject: Update CBindings
---
core/bindings/lang/clang/headers/nogamepads.h | 135 +++++-
core/bindings/lang/clang/src/converter/mod.rs | 1 +
.../lang/clang/src/converter/string_converter.rs | 24 +
core/bindings/lang/clang/src/data/mod.rs | 4 +-
.../bindings/lang/clang/src/data/ngpd_game_info.rs | 109 +++++
core/bindings/lang/clang/src/data/ngpd_message.rs | 486 +++++++++++++++++++++
core/bindings/lang/clang/src/data/ngpd_player.rs | 16 +-
core/bindings/lang/clang/src/lib.rs | 3 +-
8 files changed, 767 insertions(+), 11 deletions(-)
create mode 100644 core/bindings/lang/clang/src/converter/mod.rs
create mode 100644 core/bindings/lang/clang/src/converter/string_converter.rs
create mode 100644 core/bindings/lang/clang/src/data/ngpd_game_info.rs
create mode 100644 core/bindings/lang/clang/src/data/ngpd_message.rs
diff --git a/core/bindings/lang/clang/headers/nogamepads.h b/core/bindings/lang/clang/headers/nogamepads.h
index f1ac85a..3242a44 100644
--- a/core/bindings/lang/clang/headers/nogamepads.h
+++ b/core/bindings/lang/clang/headers/nogamepads.h
@@ -1,4 +1,4 @@
-// 自动生成的头文件 - 请勿手动编辑
+// Auto generated by cbindgen 0.29.0
#ifndef NOGAMEPADS_H
#define NOGAMEPADS_H
@@ -8,6 +8,59 @@
#include
#include
+typedef enum FfiConnectionMessageTag {
+ Join,
+ RequestGameInfos,
+ RequestLayoutConfigure,
+ RequestSkinPackage,
+ Ready,
+ Err,
+} FfiConnectionMessageTag;
+
+typedef enum FfiConnectionResponseMessageTag {
+ GameInfos,
+ Deny,
+ Fail,
+ Ok,
+ Welcome,
+ Err,
+} FfiConnectionResponseMessageTag;
+
+typedef enum FfiControlMessageTag {
+ Msg,
+ Pressed,
+ Released,
+ Axis,
+ Dir,
+ Exit,
+ Err,
+ End,
+} FfiControlMessageTag;
+
+typedef enum FfiExitReason {
+ Exit,
+ GameOver,
+ ServerClosed,
+ YouAreKicked,
+ YouAreBanned,
+ Err,
+} FfiExitReason;
+
+typedef enum FfiGameMessageTag {
+ EventTrigger,
+ Msg,
+ LetExit,
+ Err,
+ End,
+} FfiGameMessageTag;
+
+typedef enum FfiJoinFailedMessage {
+ ContainIdenticalPlayer,
+ PlayerBanned,
+ GameLocked,
+ UnknownError,
+} FfiJoinFailedMessage;
+
typedef struct FfiAccount {
char *id;
char *player_hash;
@@ -25,10 +78,76 @@ typedef struct FfiPlayer {
struct FfiCustomize *customize;
} FfiPlayer;
+typedef struct FfiKeyAndAxis {
+ uint8_t key;
+ double axis;
+} FfiKeyAndAxis;
+
+typedef struct FfiKeyAndDirection {
+ uint8_t key;
+ double x;
+ double y;
+} FfiKeyAndDirection;
+
+typedef union FfiControlMessageUnion {
+ char *message;
+ uint8_t key;
+ struct FfiKeyAndAxis key_and_axis;
+ struct FfiKeyAndDirection key_and_direction;
+} FfiControlMessageUnion;
+
+typedef struct FfiControlMessage {
+ enum FfiControlMessageTag tag;
+ union FfiControlMessageUnion data;
+} FfiControlMessage;
+
+typedef union FfiGameMessageUnion {
+ uint8_t key;
+ char *message;
+ enum FfiExitReason exit_reason;
+} FfiGameMessageUnion;
+
+typedef struct FfiGameMessage {
+ enum FfiGameMessageTag tag;
+ union FfiGameMessageUnion data;
+} FfiGameMessage;
+
+typedef union FfiConnectionMessageUnion {
+ struct FfiPlayer player;
+} FfiConnectionMessageUnion;
+
+typedef struct FfiConnectionMessage {
+ enum FfiConnectionMessageTag tag;
+ union FfiConnectionMessageUnion data;
+} FfiConnectionMessage;
+
+typedef struct KeyValuePair {
+ char *key;
+ char *value;
+} KeyValuePair;
+
+typedef struct FfiGameInfo {
+ struct KeyValuePair *data;
+ uintptr_t len;
+ uintptr_t cap;
+} FfiGameInfo;
+
+typedef union FfiConnectionResponseMessageUnion {
+ struct FfiGameInfo game_info;
+ enum FfiJoinFailedMessage failed_message;
+} FfiConnectionResponseMessageUnion;
+
+typedef struct FfiConnectionResponseMessage {
+ enum FfiConnectionResponseMessageTag tag;
+ union FfiConnectionResponseMessageUnion data;
+} FfiConnectionResponseMessage;
+
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
+ngp_ void free_c_string(char *ptr);
+
ngp_ struct FfiPlayer *player_register(const char *id, const char *password);
ngp_ bool player_check(const struct FfiPlayer *player, const char *password);
@@ -41,6 +160,20 @@ ngp_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, d
ngp_ void player_free(struct FfiPlayer *player);
+ngp_ void free_control_message(struct FfiControlMessage msg);
+
+ngp_ void free_game_message(struct FfiGameMessage msg);
+
+ngp_ void free_exit_reason(enum FfiExitReason msg);
+
+ngp_ void free_connection_message(struct FfiConnectionMessage msg);
+
+ngp_ void free_connection_response_message(struct FfiConnectionResponseMessage msg);
+
+ngp_ void free_join_failed_message(enum FfiJoinFailedMessage msg);
+
+ngp_ void free_game_info(struct FfiGameInfo map);
+
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
diff --git a/core/bindings/lang/clang/src/converter/mod.rs b/core/bindings/lang/clang/src/converter/mod.rs
new file mode 100644
index 0000000..86708b0
--- /dev/null
+++ b/core/bindings/lang/clang/src/converter/mod.rs
@@ -0,0 +1 @@
+pub mod string_converter;
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/converter/string_converter.rs b/core/bindings/lang/clang/src/converter/string_converter.rs
new file mode 100644
index 0000000..7345f5a
--- /dev/null
+++ b/core/bindings/lang/clang/src/converter/string_converter.rs
@@ -0,0 +1,24 @@
+use std::ffi::{c_char, CStr, CString};
+
+pub unsafe fn str_rs_to_c(content: String) -> *mut c_char {
+ let c_str = CString::new(content).expect("CString::new failed");
+
+ c_str.into_raw()
+}
+
+pub unsafe fn str_c_to_rs(content_ptr: *mut c_char) -> String {
+ let c_str = unsafe { CStr::from_ptr(content_ptr) };
+
+ c_str.to_str()
+ .expect("Invalid UTF-8 sequence")
+ .to_owned()
+}
+
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn free_c_string(ptr: *mut c_char) {
+ if ptr.is_null() {
+ return;
+ }
+
+ let _ = unsafe { CString::from_raw(ptr) };
+}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/mod.rs b/core/bindings/lang/clang/src/data/mod.rs
index 32af6d8..c93e7f0 100644
--- a/core/bindings/lang/clang/src/data/mod.rs
+++ b/core/bindings/lang/clang/src/data/mod.rs
@@ -1 +1,3 @@
-pub mod ngpd_player;
\ No newline at end of file
+pub mod ngpd_player;
+pub mod ngpd_message;
+mod ngpd_game_info;
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/ngpd_game_info.rs b/core/bindings/lang/clang/src/data/ngpd_game_info.rs
new file mode 100644
index 0000000..af45758
--- /dev/null
+++ b/core/bindings/lang/clang/src/data/ngpd_game_info.rs
@@ -0,0 +1,109 @@
+use std::collections::HashMap;
+use std::ffi::{CStr, CString};
+use std::os::raw::c_char;
+
+#[repr(C)]
+pub struct KeyValuePair {
+ key: *mut c_char,
+ value: *mut c_char,
+}
+
+#[repr(C)]
+pub struct FfiGameInfo {
+ data: *mut KeyValuePair,
+ len: usize,
+ cap: usize,
+}
+
+impl From<&HashMap> for FfiGameInfo {
+ fn from(map: &HashMap) -> Self {
+ let mut kv_pairs: Vec = map
+ .into_iter()
+ .map(|(k, v)| {
+ KeyValuePair {
+ key: CString::new(k.clone()).unwrap().into_raw(),
+ value: CString::new(v.clone()).unwrap().into_raw(),
+ }
+ })
+ .collect();
+
+ let cap = kv_pairs.capacity();
+ let len = kv_pairs.len();
+ let data_ptr = kv_pairs.as_mut_ptr();
+
+ std::mem::forget(kv_pairs);
+
+ FfiGameInfo {
+ data: data_ptr,
+ len,
+ cap,
+ }
+ }
+}
+
+impl TryFrom<&FfiGameInfo> for HashMap {
+ type Error = String;
+
+ fn try_from(ffi_info: &FfiGameInfo) -> Result {
+ if ffi_info.len == 0 {
+ return Ok(HashMap::new());
+ }
+
+ if ffi_info.data.is_null() {
+ return Err("FfiGameInfo data pointer is null".to_string());
+ }
+
+ let kv_slice = unsafe {
+ std::slice::from_raw_parts(ffi_info.data, ffi_info.len)
+ };
+
+ let mut map = HashMap::with_capacity(ffi_info.len);
+
+ for (i, pair) in kv_slice.iter().enumerate() {
+ if pair.key.is_null() {
+ return Err(format!("Key pointer is null at index {}", i));
+ }
+
+ if pair.value.is_null() {
+ return Err(format!("Value pointer is null at index {}", i));
+ }
+
+ let key_str = unsafe {
+ CStr::from_ptr(pair.key)
+ .to_str()
+ .map_err(|_| "Invalid UTF-8 in key")?
+ };
+
+ let value_str = unsafe {
+ CStr::from_ptr(pair.value)
+ .to_str()
+ .map_err(|_| "Invalid UTF-8 in value")?
+ };
+
+ map.insert(key_str.to_owned(), value_str.to_owned());
+ }
+
+ Ok(map)
+ }
+}
+
+impl From<&FfiGameInfo> for Option> {
+ fn from(ffi_info: &FfiGameInfo) -> Self {
+ match HashMap::try_from(ffi_info) {
+ Ok(map) => Some(map),
+ Err(_) => None,
+ }
+ }
+}
+
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn free_game_info(map: FfiGameInfo) {
+ let kv_pairs = unsafe { Vec::from_raw_parts(map.data, map.len, map.cap) };
+
+ for pair in kv_pairs {
+ unsafe {
+ let _ = CString::from_raw(pair.key);
+ let _ = CString::from_raw(pair.value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/ngpd_message.rs b/core/bindings/lang/clang/src/data/ngpd_message.rs
new file mode 100644
index 0000000..c669299
--- /dev/null
+++ b/core/bindings/lang/clang/src/data/ngpd_message.rs
@@ -0,0 +1,486 @@
+use crate::converter::string_converter::{str_c_to_rs, str_rs_to_c};
+use crate::data::ngpd_game_info::FfiGameInfo;
+use crate::data::ngpd_player::FfiPlayer;
+use nogamepads_core::data::message::message_enums::{ConnectionMessage, ConnectionResponseMessage, ControlMessage, ExitReason, GameMessage, JoinFailedMessage};
+use std::mem::ManuallyDrop;
+use std::ops::Deref;
+use std::os::raw::{c_char, c_double};
+
+#[repr(C)]
+pub struct FfiControlMessage {
+ pub tag: FfiControlMessageTag,
+ pub data: FfiControlMessageUnion
+}
+
+#[repr(C)]
+pub enum FfiControlMessageTag {
+ Msg, Pressed, Released, Axis, Dir, Exit, Err, End
+}
+
+#[repr(C)]
+pub union FfiControlMessageUnion {
+ pub none: (),
+ pub message: *mut c_char,
+ pub key: u8,
+ pub key_and_axis: ManuallyDrop,
+ pub key_and_direction: ManuallyDrop,
+}
+
+#[repr(C)]
+pub struct FfiKeyAndAxis {
+ pub key: u8,
+ pub axis: c_double
+}
+
+#[repr(C)]
+pub struct FfiKeyAndDirection {
+ pub key: u8,
+ pub x: c_double,
+ pub y: c_double
+}
+
+#[repr(C)]
+pub struct FfiGameMessage {
+ pub tag: FfiGameMessageTag,
+ pub data: FfiGameMessageUnion
+}
+
+#[repr(C)]
+pub enum FfiGameMessageTag {
+ EventTrigger, Msg, LetExit, Err, End
+}
+
+#[repr(C)]
+pub union FfiGameMessageUnion {
+ pub none: (),
+ pub key: u8,
+ pub message: *mut c_char,
+ pub exit_reason: ManuallyDrop,
+}
+
+#[repr(C)]
+pub enum FfiExitReason {
+ Exit, GameOver, ServerClosed, YouAreKicked, YouAreBanned, Err
+}
+
+#[repr(C)]
+pub struct FfiConnectionMessage {
+ pub tag: FfiConnectionMessageTag,
+ pub data: FfiConnectionMessageUnion
+}
+
+#[repr(C)]
+pub enum FfiConnectionMessageTag {
+ Join, RequestGameInfos, RequestLayoutConfigure, RequestSkinPackage, Ready, Err
+}
+
+#[repr(C)]
+pub union FfiConnectionMessageUnion {
+ pub none: (),
+ pub player: ManuallyDrop
+}
+
+#[repr(C)]
+pub struct FfiConnectionResponseMessage {
+ pub tag: FfiConnectionResponseMessageTag,
+ pub data: FfiConnectionResponseMessageUnion
+}
+
+#[repr(C)]
+pub enum FfiConnectionResponseMessageTag {
+ GameInfos, Deny, Fail, Ok, Welcome, Err
+}
+
+#[repr(C)]
+pub union FfiConnectionResponseMessageUnion {
+ pub none: (),
+ pub game_info: ManuallyDrop,
+ pub failed_message: ManuallyDrop
+}
+
+#[repr(C)]
+pub enum FfiJoinFailedMessage {
+ ContainIdenticalPlayer, PlayerBanned, GameLocked, UnknownError
+}
+
+impl From for FfiControlMessage {
+ fn from(value: ControlMessage) -> Self {
+ match value {
+ ControlMessage::Msg(msg) => unsafe {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Msg,
+ data: FfiControlMessageUnion {
+ message: str_rs_to_c(msg),
+ }
+ }
+ }
+ ControlMessage::Pressed(key) => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Pressed,
+ data: FfiControlMessageUnion {
+ key: key.into()
+ }
+ }
+ }
+ ControlMessage::Released(key) => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Released,
+ data: FfiControlMessageUnion {
+ key: key.into()
+ }
+ }
+ }
+ ControlMessage::Axis(key, axis) => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Axis,
+ data: FfiControlMessageUnion {
+ key_and_axis: ManuallyDrop::new(FfiKeyAndAxis {
+ key: key.into(),
+ axis: axis.into()
+ })
+ }
+ }
+ }
+ ControlMessage::Dir(key, (x, y)) => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Axis,
+ data: FfiControlMessageUnion {
+ key_and_direction: ManuallyDrop::new(FfiKeyAndDirection {
+ key: key.into(),
+ x, y
+ })
+ }
+ }
+ }
+ ControlMessage::Exit => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Axis,
+ data: FfiControlMessageUnion { none: () }
+ }
+ }
+ ControlMessage::Err => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Axis,
+ data: FfiControlMessageUnion { none: () }
+ }
+ }
+ ControlMessage::End => {
+ FfiControlMessage {
+ tag: FfiControlMessageTag::Axis,
+ data: FfiControlMessageUnion { none: () }
+ }
+ }
+ }
+ }
+}
+
+impl From for ControlMessage {
+ fn from(value: FfiControlMessage) -> Self {
+ match value.tag {
+ FfiControlMessageTag::Msg => unsafe {
+ ControlMessage::Msg(str_c_to_rs(value.data.message))
+ }
+ FfiControlMessageTag::Pressed => unsafe {
+ ControlMessage::Pressed(value.data.key.into())
+ }
+ FfiControlMessageTag::Released => unsafe {
+ ControlMessage::Released(value.data.key.into())
+ }
+ FfiControlMessageTag::Axis => {
+ let value = unsafe { value.data.key_and_axis };
+ ControlMessage::Axis(value.key.into(), value.axis.into())
+ }
+ FfiControlMessageTag::Dir => {
+ let value = unsafe { value.data.key_and_direction };
+ ControlMessage::Dir(value.key.into(), (value.x.into(), value.y.into()))
+ }
+ FfiControlMessageTag::Exit => {
+ ControlMessage::Exit
+ }
+ FfiControlMessageTag::Err => {
+ ControlMessage::Err
+ }
+ FfiControlMessageTag::End => {
+ ControlMessage::End
+ }
+ }
+ }
+}
+
+impl From for FfiGameMessage {
+ fn from(value: GameMessage) -> Self {
+ match value {
+ GameMessage::EventTrigger(key) => {
+ FfiGameMessage {
+ tag: FfiGameMessageTag::EventTrigger,
+ data: FfiGameMessageUnion {
+ key: key.into()
+ }
+ }
+ }
+ GameMessage::Msg(msg) => unsafe {
+ FfiGameMessage {
+ tag: FfiGameMessageTag::Msg,
+ data: FfiGameMessageUnion {
+ message: str_rs_to_c(msg)
+ }
+ }
+ }
+ GameMessage::LetExit(reason) => {
+ FfiGameMessage {
+ tag: FfiGameMessageTag::LetExit,
+ data: FfiGameMessageUnion {
+ exit_reason: ManuallyDrop::new(FfiExitReason::from(&reason))
+ }
+ }
+ }
+ GameMessage::Err => {
+ FfiGameMessage {
+ tag: FfiGameMessageTag::Err,
+ data: FfiGameMessageUnion { none: () }
+ }
+ }
+ GameMessage::End => {
+ FfiGameMessage {
+ tag: FfiGameMessageTag::End,
+ data: FfiGameMessageUnion { none: () }
+ }
+ }
+ }
+ }
+}
+
+impl From for GameMessage {
+ fn from(value: FfiGameMessage) -> Self {
+ match value.tag {
+ FfiGameMessageTag::EventTrigger => unsafe {
+ GameMessage::EventTrigger(value.data.key.into())
+ }
+ FfiGameMessageTag::Msg => unsafe {
+ GameMessage::Msg(str_c_to_rs(value.data.message))
+ }
+ FfiGameMessageTag::LetExit => unsafe {
+ GameMessage::LetExit(value.data.exit_reason.deref().into())
+ }
+ FfiGameMessageTag::Err => {
+ GameMessage::Err
+ }
+ FfiGameMessageTag::End => {
+ GameMessage::End
+ }
+ }
+ }
+}
+
+impl From<&ExitReason> for FfiExitReason {
+ fn from(value: &ExitReason) -> Self {
+ match value {
+ ExitReason::Exit => { FfiExitReason::Exit }
+ ExitReason::GameOver => { FfiExitReason::GameOver }
+ ExitReason::ServerClosed => { FfiExitReason::ServerClosed }
+ ExitReason::YouAreKicked => { FfiExitReason::YouAreKicked }
+ ExitReason::YouAreBanned => { FfiExitReason::YouAreBanned }
+ ExitReason::Err => { FfiExitReason::Err }
+ }
+ }
+}
+
+impl From<&FfiExitReason> for ExitReason {
+ fn from(value: &FfiExitReason) -> Self {
+ match value {
+ FfiExitReason::Exit => { ExitReason::Exit }
+ FfiExitReason::GameOver => { ExitReason::GameOver }
+ FfiExitReason::ServerClosed => { ExitReason::ServerClosed }
+ FfiExitReason::YouAreKicked => { ExitReason::YouAreKicked }
+ FfiExitReason::YouAreBanned => { ExitReason::YouAreBanned }
+ FfiExitReason::Err => { ExitReason::Err }
+ }
+ }
+}
+
+impl From for FfiConnectionMessage {
+ fn from(value: ConnectionMessage) -> Self {
+ match value {
+ ConnectionMessage::Join(player) => {
+ let c_player : FfiPlayer = (&player).into();
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::Join,
+ data: FfiConnectionMessageUnion {
+ player: ManuallyDrop::new(c_player),
+ }
+ }
+ }
+ ConnectionMessage::RequestGameInfos => {
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::RequestGameInfos,
+ data: FfiConnectionMessageUnion { none: () }
+ }
+ }
+ ConnectionMessage::RequestLayoutConfigure => {
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::RequestLayoutConfigure,
+ data: FfiConnectionMessageUnion { none: () }
+ }
+ }
+ ConnectionMessage::RequestSkinPackage => {
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::RequestSkinPackage,
+ data: FfiConnectionMessageUnion { none: () }
+ }
+ }
+ ConnectionMessage::Ready => {
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::Ready,
+ data: FfiConnectionMessageUnion { none: () }
+ }
+ }
+ ConnectionMessage::Err => {
+ FfiConnectionMessage {
+ tag: FfiConnectionMessageTag::Err,
+ data: FfiConnectionMessageUnion { none: () }
+ }
+ }
+ }
+ }
+}
+
+impl From for ConnectionMessage {
+ fn from(value: FfiConnectionMessage) -> Self {
+ match value.tag {
+ FfiConnectionMessageTag::Join => unsafe {
+ ConnectionMessage::Join(value.data.player.deref().try_into().unwrap_or_default())
+ }
+ FfiConnectionMessageTag::RequestGameInfos => { ConnectionMessage::RequestGameInfos }
+ FfiConnectionMessageTag::RequestLayoutConfigure => { ConnectionMessage::RequestLayoutConfigure }
+ FfiConnectionMessageTag::RequestSkinPackage => { ConnectionMessage::RequestSkinPackage }
+ FfiConnectionMessageTag::Ready => { ConnectionMessage::Ready }
+ FfiConnectionMessageTag::Err => { ConnectionMessage::Err }
+ }
+ }
+}
+
+impl From for FfiConnectionResponseMessage {
+ fn from(value: ConnectionResponseMessage) -> Self {
+ match value {
+ ConnectionResponseMessage::GameInfos(info) => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::GameInfos,
+ data: FfiConnectionResponseMessageUnion {
+ game_info: ManuallyDrop::new((&info).into())
+ }
+ }
+ }
+ ConnectionResponseMessage::Deny(fail) => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::Deny,
+ data: FfiConnectionResponseMessageUnion {
+ failed_message: ManuallyDrop::new((&fail).into())
+ }
+ }
+ }
+ ConnectionResponseMessage::Fail(fail) => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::Fail,
+ data: FfiConnectionResponseMessageUnion {
+ failed_message: ManuallyDrop::new((&fail).into())
+ }
+ }
+ }
+ ConnectionResponseMessage::Ok => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::Ok,
+ data: FfiConnectionResponseMessageUnion { none: () }
+ }
+ }
+ ConnectionResponseMessage::Welcome => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::Welcome,
+ data: FfiConnectionResponseMessageUnion { none: () }
+ }
+ }
+ ConnectionResponseMessage::Err => {
+ FfiConnectionResponseMessage {
+ tag: FfiConnectionResponseMessageTag::Err,
+ data: FfiConnectionResponseMessageUnion { none: () }
+ }
+ }
+ }
+ }
+}
+
+impl From for ConnectionResponseMessage {
+ fn from(value: FfiConnectionResponseMessage) -> Self {
+ match value.tag {
+ FfiConnectionResponseMessageTag::GameInfos => unsafe {
+ ConnectionResponseMessage::GameInfos(value.data.game_info.deref().try_into().unwrap_or_default())
+ }
+ FfiConnectionResponseMessageTag::Deny => unsafe {
+ ConnectionResponseMessage::Deny(value.data.failed_message.deref().try_into().unwrap_or_default())
+ }
+ FfiConnectionResponseMessageTag::Fail => unsafe {
+ ConnectionResponseMessage::Fail(value.data.failed_message.deref().try_into().unwrap_or_default())
+ }
+ FfiConnectionResponseMessageTag::Ok => {
+ ConnectionResponseMessage::Ok
+ }
+ FfiConnectionResponseMessageTag::Welcome => {
+ ConnectionResponseMessage::Welcome
+ }
+ FfiConnectionResponseMessageTag::Err => {
+ ConnectionResponseMessage::Err
+ }
+ }
+ }
+}
+
+impl From<&JoinFailedMessage> for FfiJoinFailedMessage {
+ fn from(value: &JoinFailedMessage) -> Self {
+ match value {
+ JoinFailedMessage::ContainIdenticalPlayer => { FfiJoinFailedMessage::ContainIdenticalPlayer }
+ JoinFailedMessage::PlayerBanned => { FfiJoinFailedMessage::PlayerBanned }
+ JoinFailedMessage::GameLocked => { FfiJoinFailedMessage::GameLocked }
+ JoinFailedMessage::UnknownError => { FfiJoinFailedMessage::UnknownError }
+ }
+ }
+}
+
+impl From<&FfiJoinFailedMessage> for JoinFailedMessage {
+ fn from(value: &FfiJoinFailedMessage) -> Self {
+ match value {
+ FfiJoinFailedMessage::ContainIdenticalPlayer => { JoinFailedMessage::ContainIdenticalPlayer }
+ FfiJoinFailedMessage::PlayerBanned => { JoinFailedMessage::PlayerBanned }
+ FfiJoinFailedMessage::GameLocked => { JoinFailedMessage::GameLocked }
+ FfiJoinFailedMessage::UnknownError => { JoinFailedMessage::UnknownError }
+ }
+ }
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_control_message(msg: FfiControlMessage) {
+ let _ = msg;
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_game_message(msg: FfiGameMessage) {
+ let _ = msg;
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_exit_reason(msg: FfiExitReason) {
+ let _ = msg;
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_connection_message(msg: FfiConnectionMessage) {
+ let _ = msg;
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_connection_response_message(msg: FfiConnectionResponseMessage) {
+ let _ = msg;
+}
+
+#[unsafe(no_mangle)]
+pub extern "C" fn free_join_failed_message(msg: FfiJoinFailedMessage) {
+ let _ = msg;
+}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/src/data/ngpd_player.rs b/core/bindings/lang/clang/src/data/ngpd_player.rs
index 2ab615c..a1a8370 100644
--- a/core/bindings/lang/clang/src/data/ngpd_player.rs
+++ b/core/bindings/lang/clang/src/data/ngpd_player.rs
@@ -32,10 +32,10 @@ impl From for FfiAccount {
}
}
-impl From for FfiPlayer {
- fn from(player: Player) -> Self {
- let account = FfiAccount::from(player.account);
- let customize = player.customize.map(|c| {
+impl From<&Player> for FfiPlayer {
+ fn from(player: &Player) -> Self {
+ let account = FfiAccount::from(player.account.clone());
+ let customize = player.clone().customize.map(|c| {
Box::into_raw(Box::new(FfiCustomize {
nickname: CString::new(c.nickname).unwrap().into_raw(),
color_hue: c.color_hue,
@@ -79,7 +79,7 @@ pub extern "C" fn player_register(id: *const c_char, password: *const c_char) ->
let pass_str = unsafe { CStr::from_ptr(password) }.to_string_lossy();
let player = Player::register(id_str.into_owned(), pass_str.into_owned());
- Box::into_raw(Box::new(FfiPlayer::from(player)))
+ Box::into_raw(Box::new(FfiPlayer::from(&player)))
}
#[unsafe(no_mangle)]
@@ -98,7 +98,7 @@ pub extern "C" fn player_set_nickname(player: *mut FfiPlayer, nickname: *const c
let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
rust_player.nickname(&nickname_str);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+ *unsafe { &mut *player } = FfiPlayer::from(&rust_player);
}
#[unsafe(no_mangle)]
@@ -106,7 +106,7 @@ pub extern "C" fn player_set_hue(player: *mut FfiPlayer, hue: c_int) {
let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
rust_player.hue(hue);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+ *unsafe { &mut *player } = FfiPlayer::from(&rust_player);
}
#[unsafe(no_mangle)]
@@ -116,7 +116,7 @@ pub extern "C" fn player_set_hsv(
let mut rust_player : Player = unsafe { (&*player).try_into().unwrap() };
rust_player.hsv(hue, saturation, value);
- *unsafe { &mut *player } = FfiPlayer::from(rust_player);
+ *unsafe { &mut *player } = FfiPlayer::from(&rust_player);
}
#[unsafe(no_mangle)]
diff --git a/core/bindings/lang/clang/src/lib.rs b/core/bindings/lang/clang/src/lib.rs
index 12e35bb..9a8fe37 100644
--- a/core/bindings/lang/clang/src/lib.rs
+++ b/core/bindings/lang/clang/src/lib.rs
@@ -1 +1,2 @@
-pub mod data;
\ No newline at end of file
+pub mod converter;
+pub mod data;
--
cgit
From f657a9c2056d4e5692ddbc19217b654277300c75 Mon Sep 17 00:00:00 2001
From: "1992414357@qq.com" <1992414357@qq.com>
Date: Sat, 14 Jun 2025 04:29:52 +0800
Subject: Update CBindings
---
Project_Export.toml | 4 +-
core/bindings/lang/clang/Generate.toml | 11 --
core/bindings/lang/clang/build.rs | 67 +++++---
.../lang/clang/configures/nogamepads_data.toml | 17 ++
core/bindings/lang/clang/headers/nogamepads.h | 181 ---------------------
core/bindings/lang/clang/headers/nogamepads_data.h | 181 +++++++++++++++++++++
.../completeion/install_completion_powershell.ps1 | 39 -----
7 files changed, 247 insertions(+), 253 deletions(-)
delete mode 100644 core/bindings/lang/clang/Generate.toml
create mode 100644 core/bindings/lang/clang/configures/nogamepads_data.toml
delete mode 100644 core/bindings/lang/clang/headers/nogamepads.h
create mode 100644 core/bindings/lang/clang/headers/nogamepads_data.h
delete mode 100644 export/dev/bin/completeion/install_completion_powershell.ps1
diff --git a/Project_Export.toml b/Project_Export.toml
index 5d09f89..9b1e7bd 100644
--- a/Project_Export.toml
+++ b/Project_Export.toml
@@ -5,7 +5,7 @@
# It will search starting from the project directory and copy to the specified location in the target directory.
[release.root]
-# License files, third-party licenses
+# License files
license = { raw = "./", target = "./", files = [
"LICENSE-MIT"
] }
@@ -17,7 +17,7 @@ powershell_complete = { raw = "./.cargo/resources/scripts/", target = "./bin/com
# Headers
headers = { raw = "./core/bindings/lang/clang/headers/", target = "./lib", files = [
- "nogamepads.h"
+ "nogamepads_data.h"
] }
# Items defined in [release.deps]
diff --git a/core/bindings/lang/clang/Generate.toml b/core/bindings/lang/clang/Generate.toml
deleted file mode 100644
index 08d8b00..0000000
--- a/core/bindings/lang/clang/Generate.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-language = "C"
-include_guard = "NOGAMEPADS_H"
-header = "// Auto generated by cbindgen 0.29.0"
-cpp_compat = true
-
-[parse]
-parse_deps = true
-include = ["*"]
-
-[fn]
-prefix = "ngp_"
\ No newline at end of file
diff --git a/core/bindings/lang/clang/build.rs b/core/bindings/lang/clang/build.rs
index c43ee7f..190501e 100644
--- a/core/bindings/lang/clang/build.rs
+++ b/core/bindings/lang/clang/build.rs
@@ -1,34 +1,61 @@
fn main() {
-
// Get the project root directory
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let root_path = std::path::Path::new(&manifest_dir);
- // Input configuration file path
- let config_path = root_path.join("Generate.toml");
+ // Input configuration directory path
+ let config_dir = root_path.join("configures");
// Output directory path (headers folder in the crate directory)
let headers_dir = root_path.join("headers");
- // Create the headers directory (if it does not exist)
- std::fs::create_dir_all(&headers_dir).expect("Failed to create headers directory");
-
- // Output file path
- let output_file = headers_dir.join("nogamepads.h");
+ // Clear existing headers directory (if it exists)
+ if headers_dir.exists() {
+ std::fs::remove_dir_all(&headers_dir).expect("Failed to remove headers directory");
+ }
- // Load configuration from Generate.toml
- let config = cbindgen::Config::from_file(&config_path)
- .expect("Failed to parse Generate.toml configuration");
-
- // Generate header file
- cbindgen::Builder::new()
- .with_crate(manifest_dir)
- .with_config(config)
- .generate()
- .expect("Failed to generate C header file")
- .write_to_file(&output_file);
+ // Create a new headers directory
+ std::fs::create_dir_all(&headers_dir).expect("Failed to create headers directory");
- println!("cargo:rerun-if-changed={}", config_path.display());
+ // Find all TOML files in configures directory
+ let config_files = std::fs::read_dir(&config_dir)
+ .expect("Failed to read configures directory")
+ .filter_map(|entry| {
+ let entry = entry.expect("Failed to read directory entry");
+ let path = entry.path();
+ if path.is_file() && path.extension().map_or(false, |ext| ext == "toml") {
+ Some(path)
+ } else {
+ None
+ }
+ });
+
+ // Process each configuration file
+ for config_path in config_files {
+ // Extract filename without extension
+ let file_stem = config_path.file_stem()
+ .and_then(|s| s.to_str())
+ .expect("Invalid filename")
+ .to_string();
+
+ // Set output file path
+ let output_file = headers_dir.join(format!("{}.h", file_stem));
+
+ // Load configuration from current TOML file
+ let config = cbindgen::Config::from_file(&config_path)
+ .expect(&format!("Failed to parse configuration: {}", config_path.display()));
+
+ // Generate header file
+ cbindgen::Builder::new()
+ .with_crate(&manifest_dir)
+ .with_config(config)
+ .generate()
+ .expect(&format!("Failed to generate header for: {}", config_path.display()))
+ .write_to_file(&output_file);
+ }
+
+ // Print rerun instructions
+ println!("cargo:rerun-if-changed={}", config_dir.display());
println!("cargo:rerun-if-changed=src/mycode.rs");
println!("cargo:rerun-if-changed=build.rs");
}
\ No newline at end of file
diff --git a/core/bindings/lang/clang/configures/nogamepads_data.toml b/core/bindings/lang/clang/configures/nogamepads_data.toml
new file mode 100644
index 0000000..56d645d
--- /dev/null
+++ b/core/bindings/lang/clang/configures/nogamepads_data.toml
@@ -0,0 +1,17 @@
+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"
+]
+
+[fn]
+prefix = "ngpd_data_"
\ No newline at end of file
diff --git a/core/bindings/lang/clang/headers/nogamepads.h b/core/bindings/lang/clang/headers/nogamepads.h
deleted file mode 100644
index 3242a44..0000000
--- a/core/bindings/lang/clang/headers/nogamepads.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// Auto generated by cbindgen 0.29.0
-
-#ifndef NOGAMEPADS_H
-#define NOGAMEPADS_H
-
-#include
-#include
-#include
-#include
-
-typedef enum FfiConnectionMessageTag {
- Join,
- RequestGameInfos,
- RequestLayoutConfigure,
- RequestSkinPackage,
- Ready,
- Err,
-} FfiConnectionMessageTag;
-
-typedef enum FfiConnectionResponseMessageTag {
- GameInfos,
- Deny,
- Fail,
- Ok,
- Welcome,
- Err,
-} FfiConnectionResponseMessageTag;
-
-typedef enum FfiControlMessageTag {
- Msg,
- Pressed,
- Released,
- Axis,
- Dir,
- Exit,
- Err,
- End,
-} FfiControlMessageTag;
-
-typedef enum FfiExitReason {
- Exit,
- GameOver,
- ServerClosed,
- YouAreKicked,
- YouAreBanned,
- Err,
-} FfiExitReason;
-
-typedef enum FfiGameMessageTag {
- EventTrigger,
- Msg,
- LetExit,
- Err,
- End,
-} FfiGameMessageTag;
-
-typedef enum FfiJoinFailedMessage {
- ContainIdenticalPlayer,
- PlayerBanned,
- GameLocked,
- UnknownError,
-} FfiJoinFailedMessage;
-
-typedef struct FfiAccount {
- char *id;
- char *player_hash;
-} FfiAccount;
-
-typedef struct FfiCustomize {
- char *nickname;
- int color_hue;
- double color_saturation;
- double color_value;
-} FfiCustomize;
-
-typedef struct FfiPlayer {
- struct FfiAccount account;
- struct FfiCustomize *customize;
-} FfiPlayer;
-
-typedef struct FfiKeyAndAxis {
- uint8_t key;
- double axis;
-} FfiKeyAndAxis;
-
-typedef struct FfiKeyAndDirection {
- uint8_t key;
- double x;
- double y;
-} FfiKeyAndDirection;
-
-typedef union FfiControlMessageUnion {
- char *message;
- uint8_t key;
- struct FfiKeyAndAxis key_and_axis;
- struct FfiKeyAndDirection key_and_direction;
-} FfiControlMessageUnion;
-
-typedef struct FfiControlMessage {
- enum FfiControlMessageTag tag;
- union FfiControlMessageUnion data;
-} FfiControlMessage;
-
-typedef union FfiGameMessageUnion {
- uint8_t key;
- char *message;
- enum FfiExitReason exit_reason;
-} FfiGameMessageUnion;
-
-typedef struct FfiGameMessage {
- enum FfiGameMessageTag tag;
- union FfiGameMessageUnion data;
-} FfiGameMessage;
-
-typedef union FfiConnectionMessageUnion {
- struct FfiPlayer player;
-} FfiConnectionMessageUnion;
-
-typedef struct FfiConnectionMessage {
- enum FfiConnectionMessageTag tag;
- union FfiConnectionMessageUnion data;
-} FfiConnectionMessage;
-
-typedef struct KeyValuePair {
- char *key;
- char *value;
-} KeyValuePair;
-
-typedef struct FfiGameInfo {
- struct KeyValuePair *data;
- uintptr_t len;
- uintptr_t cap;
-} FfiGameInfo;
-
-typedef union FfiConnectionResponseMessageUnion {
- struct FfiGameInfo game_info;
- enum FfiJoinFailedMessage failed_message;
-} FfiConnectionResponseMessageUnion;
-
-typedef struct FfiConnectionResponseMessage {
- enum FfiConnectionResponseMessageTag tag;
- union FfiConnectionResponseMessageUnion data;
-} FfiConnectionResponseMessage;
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-ngp_ void free_c_string(char *ptr);
-
-ngp_ struct FfiPlayer *player_register(const char *id, const char *password);
-
-ngp_ bool player_check(const struct FfiPlayer *player, const char *password);
-
-ngp_ void player_set_nickname(struct FfiPlayer *player, const char *nickname);
-
-ngp_ void player_set_hue(struct FfiPlayer *player, int hue);
-
-ngp_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double value);
-
-ngp_ void player_free(struct FfiPlayer *player);
-
-ngp_ void free_control_message(struct FfiControlMessage msg);
-
-ngp_ void free_game_message(struct FfiGameMessage msg);
-
-ngp_ void free_exit_reason(enum FfiExitReason msg);
-
-ngp_ void free_connection_message(struct FfiConnectionMessage msg);
-
-ngp_ void free_connection_response_message(struct FfiConnectionResponseMessage msg);
-
-ngp_ void free_join_failed_message(enum FfiJoinFailedMessage msg);
-
-ngp_ void free_game_info(struct FfiGameInfo map);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cplusplus
-
-#endif /* NOGAMEPADS_H */
diff --git a/core/bindings/lang/clang/headers/nogamepads_data.h b/core/bindings/lang/clang/headers/nogamepads_data.h
new file mode 100644
index 0000000..6d9f1ad
--- /dev/null
+++ b/core/bindings/lang/clang/headers/nogamepads_data.h
@@ -0,0 +1,181 @@
+// Auto generated by cbindgen 0.29.0
+
+#ifndef NOGAMEPADS_DATA_H
+#define NOGAMEPADS_DATA_H
+
+#include
+#include
+#include
+#include
+
+typedef enum FfiConnectionMessageTag {
+ Join,
+ RequestGameInfos,
+ RequestLayoutConfigure,
+ RequestSkinPackage,
+ Ready,
+ Err,
+} FfiConnectionMessageTag;
+
+typedef enum FfiConnectionResponseMessageTag {
+ GameInfos,
+ Deny,
+ Fail,
+ Ok,
+ Welcome,
+ Err,
+} FfiConnectionResponseMessageTag;
+
+typedef enum FfiControlMessageTag {
+ Msg,
+ Pressed,
+ Released,
+ Axis,
+ Dir,
+ Exit,
+ Err,
+ End,
+} FfiControlMessageTag;
+
+typedef enum FfiExitReason {
+ Exit,
+ GameOver,
+ ServerClosed,
+ YouAreKicked,
+ YouAreBanned,
+ Err,
+} FfiExitReason;
+
+typedef enum FfiGameMessageTag {
+ EventTrigger,
+ Msg,
+ LetExit,
+ Err,
+ End,
+} FfiGameMessageTag;
+
+typedef enum FfiJoinFailedMessage {
+ ContainIdenticalPlayer,
+ PlayerBanned,
+ GameLocked,
+ UnknownError,
+} FfiJoinFailedMessage;
+
+typedef struct FfiAccount {
+ char *id;
+ char *player_hash;
+} FfiAccount;
+
+typedef struct FfiCustomize {
+ char *nickname;
+ int color_hue;
+ double color_saturation;
+ double color_value;
+} FfiCustomize;
+
+typedef struct FfiPlayer {
+ struct FfiAccount account;
+ struct FfiCustomize *customize;
+} FfiPlayer;
+
+typedef struct FfiKeyAndAxis {
+ uint8_t key;
+ double axis;
+} FfiKeyAndAxis;
+
+typedef struct FfiKeyAndDirection {
+ uint8_t key;
+ double x;
+ double y;
+} FfiKeyAndDirection;
+
+typedef union FfiControlMessageUnion {
+ char *message;
+ uint8_t key;
+ struct FfiKeyAndAxis key_and_axis;
+ struct FfiKeyAndDirection key_and_direction;
+} FfiControlMessageUnion;
+
+typedef struct FfiControlMessage {
+ enum FfiControlMessageTag tag;
+ union FfiControlMessageUnion data;
+} FfiControlMessage;
+
+typedef union FfiGameMessageUnion {
+ uint8_t key;
+ char *message;
+ enum FfiExitReason exit_reason;
+} FfiGameMessageUnion;
+
+typedef struct FfiGameMessage {
+ enum FfiGameMessageTag tag;
+ union FfiGameMessageUnion data;
+} FfiGameMessage;
+
+typedef union FfiConnectionMessageUnion {
+ struct FfiPlayer player;
+} FfiConnectionMessageUnion;
+
+typedef struct FfiConnectionMessage {
+ enum FfiConnectionMessageTag tag;
+ union FfiConnectionMessageUnion data;
+} FfiConnectionMessage;
+
+typedef struct KeyValuePair {
+ char *key;
+ char *value;
+} KeyValuePair;
+
+typedef struct FfiGameInfo {
+ struct KeyValuePair *data;
+ uintptr_t len;
+ uintptr_t cap;
+} FfiGameInfo;
+
+typedef union FfiConnectionResponseMessageUnion {
+ struct FfiGameInfo game_info;
+ enum FfiJoinFailedMessage failed_message;
+} FfiConnectionResponseMessageUnion;
+
+typedef struct FfiConnectionResponseMessage {
+ enum FfiConnectionResponseMessageTag tag;
+ union FfiConnectionResponseMessageUnion data;
+} FfiConnectionResponseMessage;
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+ngpd_data_ void free_c_string(char *ptr);
+
+ngpd_data_ struct FfiPlayer *player_register(const char *id, const char *password);
+
+ngpd_data_ bool player_check(const struct FfiPlayer *player, const char *password);
+
+ngpd_data_ void player_set_nickname(struct FfiPlayer *player, const char *nickname);
+
+ngpd_data_ void player_set_hue(struct FfiPlayer *player, int hue);
+
+ngpd_data_ void player_set_hsv(struct FfiPlayer *player, int hue, double saturation, double value);
+
+ngpd_data_ void player_free(struct FfiPlayer *player);
+
+ngpd_data_ void free_control_message(struct FfiControlMessage msg);
+
+ngpd_data_ void free_game_message(struct FfiGameMessage msg);
+
+ngpd_data_ void free_exit_reason(enum FfiExitReason msg);
+
+ngpd_data_ void free_connection_message(struct FfiConnectionMessage msg);
+
+ngpd_data_ void free_connection_response_message(struct FfiConnectionResponseMessage msg);
+
+ngpd_data_ void free_join_failed_message(enum FfiJoinFailedMessage msg);
+
+ngpd_data_ void free_game_info(struct FfiGameInfo map);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif // __cplusplus
+
+#endif /* NOGAMEPADS_DATA_H */
diff --git a/export/dev/bin/completeion/install_completion_powershell.ps1 b/export/dev/bin/completeion/install_completion_powershell.ps1
deleted file mode 100644
index 8707870..0000000
--- a/export/dev/bin/completeion/install_completion_powershell.ps1
+++ /dev/null
@@ -1,39 +0,0 @@
-$ErrorActionPreference = "Stop"
-
-try {
- # Check if padc.exe exists in the current directory
- if (-not (Test-Path -Path ".\..\padc.exe" -PathType Leaf)) {
- throw "Error: padc.exe program not found in the current directory"
- }
-
- # Generate completion script
- Write-Host "Generating padc.ps1 file..."
- .\..\padc.exe generate-completion powershell | Out-File padc.ps1 -Encoding utf8 -Force
-
- # Get target profile file path
- $targetProfile = $PROFILE.CurrentUserAllHosts
-
- # Ensure the profile directory exists
- $profileDir = Split-Path $targetProfile -Parent
- if (-not (Test-Path $profileDir)) {
- New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
- }
-
- # Copy the generated script to the profile file
- Write-Host "Installing to user profile file..."
- Copy-Item padc.ps1 $targetProfile -Force
-
- # Clean up temporary files (optional)
- # Remove-Item padc.ps1 -Force
-
- Write-Host "`nComplete! Auto-completion has been successfully installed to $targetProfile" -ForegroundColor Green
- Write-Host "Effective in new terminal sessions (restart PowerShell to use)"
-}
-catch {
- Write-Host "`nError: $_" -ForegroundColor Red
- exit 1
-}
-
-# Pause the script
-Write-Host "`nPress any key to continue..."
-$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
\ No newline at end of file
--
cgit