1use std::ffi::{c_char, CString};
2
3macro_rules! typed_ptr {
4 ( $name:ident ) => {
5 #[repr(C)]
6 pub struct $name {
7 ptr: *mut c_char
8 }
9 };
10}
11
12typed_ptr!(_ColorNote);
13typed_ptr!(_BombNote);
14typed_ptr!(_Arc);
15typed_ptr!(_Wall);
16typed_ptr!(_Saber);
17typed_ptr!(_Player);
18
19extern "C" {
20 fn _create_color_note(beat: f32) -> _ColorNote;
21 fn _create_bomb_note(beat: f32) -> _BombNote;
22
23 fn _beatmap_add_color_note(note: _ColorNote);
24 fn _beatmap_add_bomb_note(bomb: _BombNote);
25
26 fn _log(message: *const c_char);
27}
28
29macro_rules! cstr {
30 ( $str:expr ) => {
31 CString::new($str).unwrap()
32 };
33}
34
35pub struct Log {}
38impl Log {
39 pub fn info(message: &str) {
40 let s = format!("info: {}", message);
41 let c = cstr!(s);
42 unsafe { _log(c.as_ptr()) };
43 }
44
45 pub fn warning(message: &str) {
46 let s = format!("warning: {}", message);
47 let c = cstr!(s);
48 unsafe { _log(c.as_ptr()) };
49 }
50
51 pub fn error(message: &str) {
52 let s = format!("error: {}", message);
53 let c = cstr!(s);
54 unsafe { _log(c.as_ptr()) };
55 }
56
57 pub fn debug(message: &str) {
58 let s = format!("debug: {}", message);
59 let c = cstr!(s);
60 unsafe { _log(c.as_ptr()) };
61 }
62
63}
64
65
66pub struct ColorNote {
68 _note: _ColorNote
69}
70
71pub struct BombNote {
73 _bomb: _BombNote
74}
75
76pub struct Beatmap {
78}
79
80
81pub fn create_note(beat: f32) -> ColorNote {
83 unsafe { ColorNote { _note: _create_color_note(beat) } }
84}
85
86pub fn create_bomb(beat: f32) -> BombNote {
88 unsafe { BombNote { _bomb: _create_bomb_note(beat) } }
89}
90
91impl Beatmap {
92 pub fn add_color_note(note: ColorNote) {
94 unsafe {
95 _beatmap_add_color_note(note._note);
96 }
97 }
98
99 pub fn add_bomb_note(bomb: BombNote) {
100 unsafe {
101 _beatmap_add_bomb_note(bomb._bomb);
102 }
103 }
104
105}