Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
2c9ce46dd2 | |||
cec1cd8714 | |||
611f6038db |
138 changed files with 107 additions and 106 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -126,10 +126,6 @@ version = "0.2.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nat_traversal"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
|
|
22
Cargo.toml
22
Cargo.toml
|
@ -1,12 +1,18 @@
|
|||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"lib/dt_p2p",
|
||||
"lib/nat_traversal"
|
||||
]
|
||||
[package]
|
||||
name = "dt_p2p"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[unstable]
|
||||
build-std = true
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.144"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.65.1"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
|
||||
# [profile.dev.package.backtrace]
|
||||
# opt-level = 3
|
||||
|
|
2
lib/dt_p2p/.gitignore
vendored
2
lib/dt_p2p/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
/Cargo.lock
|
|
@ -1,15 +0,0 @@
|
|||
[package]
|
||||
name = "dt_p2p"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.144"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.65.1"
|
|
@ -1,53 +0,0 @@
|
|||
mod stingray_sdk;
|
||||
|
||||
use std::ffi::c_char;
|
||||
use std::ffi::CString;
|
||||
|
||||
use stingray_sdk::GetApiFunction;
|
||||
use stingray_sdk::PluginApi;
|
||||
use stingray_sdk::PluginApiID;
|
||||
|
||||
use crate::stingray_sdk::LoggingApi;
|
||||
|
||||
const PLUGIN_NAME: &str = "dt_p2p";
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_name() -> *const c_char {
|
||||
let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name");
|
||||
s.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setup_game(get_engine_api: GetApiFunction) {
|
||||
println!("setup_game");
|
||||
|
||||
let log = LoggingApi::get(get_engine_api);
|
||||
|
||||
log.info(
|
||||
PLUGIN_NAME,
|
||||
format!("Hello, world! This is {}!", PLUGIN_NAME),
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn shutdown_game() {
|
||||
println!("shutdown_game");
|
||||
|
||||
// log.info(PLUGIN_NAME, format!("Goodbye, world!", PLUGIN_NAME));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_plugin_api(id: PluginApiID) -> *mut PluginApi {
|
||||
if id == PluginApiID::PLUGIN_API_ID {
|
||||
let api = PluginApi {
|
||||
get_name: Some(get_name),
|
||||
setup_game: Some(setup_game),
|
||||
shutdown_game: Some(shutdown_game),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Box::into_raw(Box::new(api))
|
||||
} else {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
}
|
2
lib/nat_traversal/.gitignore
vendored
2
lib/nat_traversal/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
/Cargo.lock
|
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "nat_traversal"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -1,14 +0,0 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
60
src/lib.rs
Normal file
60
src/lib.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
use std::ffi::{c_char, CString};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
mod plugin;
|
||||
mod stingray_sdk;
|
||||
|
||||
use plugin::Plugin;
|
||||
use stingray_sdk::{GetApiFunction, PluginApi, PluginApiID};
|
||||
|
||||
pub const PLUGIN_NAME: &str = "dt_p2p";
|
||||
|
||||
static PLUGIN: OnceLock<Plugin> = OnceLock::new();
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_name() -> *const c_char {
|
||||
let s = CString::new(PLUGIN_NAME).expect("Failed to create CString from plugin name");
|
||||
s.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn setup_game(get_engine_api: GetApiFunction) {
|
||||
let plugin = Plugin::new(get_engine_api);
|
||||
plugin.setup_game();
|
||||
PLUGIN
|
||||
.set(plugin)
|
||||
.expect("Failed to initalize global plugin object.");
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn shutdown_game() {
|
||||
// Safety: The engine ensures that `setup_game` was called before this, where `PLUGIN` was
|
||||
// initialized.
|
||||
let plugin = unsafe { PLUGIN.get().unwrap_unchecked() };
|
||||
plugin.shutdown_game();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn update_game(dt: f32) {
|
||||
// Safety: The engine ensures that `setup_game` was called before this, where `PLUGIN` was
|
||||
// initialized.
|
||||
let plugin = unsafe { PLUGIN.get().unwrap_unchecked() };
|
||||
plugin.update_game(dt);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_plugin_api(id: PluginApiID) -> *mut PluginApi {
|
||||
if id == PluginApiID::PLUGIN_API_ID {
|
||||
let api = PluginApi {
|
||||
get_name: Some(get_name),
|
||||
setup_game: Some(setup_game),
|
||||
update_game: Some(update_game),
|
||||
shutdown_game: Some(shutdown_game),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Box::into_raw(Box::new(api))
|
||||
} else {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
}
|
33
src/plugin.rs
Normal file
33
src/plugin.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use crate::stingray_sdk::{GetApiFunction, LoggingApi};
|
||||
use crate::PLUGIN_NAME;
|
||||
|
||||
pub(crate) struct Plugin {
|
||||
log: LoggingApi,
|
||||
}
|
||||
|
||||
impl Plugin {
|
||||
pub fn new(get_engine_api: GetApiFunction) -> Self {
|
||||
let log = LoggingApi::get(get_engine_api);
|
||||
Self { log }
|
||||
}
|
||||
|
||||
pub fn setup_game(&self) {
|
||||
self.log.info(
|
||||
PLUGIN_NAME,
|
||||
format!("[setup_game] Hello, world! This is {}!", PLUGIN_NAME),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn shutdown_game(&self) {
|
||||
self.log
|
||||
.info(PLUGIN_NAME, format!("[shutdown_game] Goodbye, world!"));
|
||||
}
|
||||
|
||||
pub fn update_game(&self, dt: f32) {}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Plugin {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str("PluginApi")
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue