Skip to content

Commit c08e3f8

Browse files
committed
wip from like two weeks ago
1 parent 0a7fb16 commit c08e3f8

File tree

5 files changed

+50
-57
lines changed

5 files changed

+50
-57
lines changed

Cargo.lock

Lines changed: 19 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
]
77

88
[workspace.package]
9-
version = "2.0.4"
9+
version = "3.0.0"
1010
edition = "2024"
1111
homepage = "https://github.com/srcwr/srcwrfloppy"
1212
repository = "https://github.com/srcwr/srcwrfloppy"

srcwrtimer/addons/sourcemod/scripting/include/srcwr/floppy.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ typeset ReplaySavedCallback {
1717
native void SRCWRFloppy_AsyncSaveReplay(
1818
ReplaySavedCallback callback // what to call when saved
1919
, any value // what to pass along to the callback
20-
, char[] wrpath
21-
, char[] copypath
20+
, char[][] paths
2221
, char[] header
2322
, int headersize
2423
, ArrayList playerrecording

srcwr💾/src/lib.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ static mut THREAD: Option<JoinHandle<()>> = None;
3636
struct Msg {
3737
forward: NonNull<c_void>,
3838
value: i32,
39-
wrpath: String,
40-
copypath: String,
39+
paths: Vec<String>,
4140
header: Vec<u8>,
4241
playerrecording: *mut ICellArray,
4342
totalframes: usize,
@@ -79,16 +78,22 @@ pub extern "C" fn rust_KILL_replay_thread() {
7978
pub extern "C" fn rust_post_to_replay_thread(
8079
forward: NonNull<c_void>,
8180
value: i32,
82-
wrpath: *const c_char,
83-
copypath: *const c_char,
81+
mut pathschars: *const *const c_char,
8482
header: *const u8,
8583
headersize: usize,
8684
playerrecording: *mut ICellArray,
8785
totalframes: usize,
8886
sm_friendly_path: *const c_char,
8987
) {
90-
let wrpath = strxx(wrpath, false, 0).unwrap_or_default().to_string();
91-
let copypath = strxx(copypath, false, 0).unwrap_or_default().to_string();
88+
let mut pathsvec = vec![];
89+
90+
unsafe {
91+
while !((*pathschars).is_null()) {
92+
pathsvec.push(strxx(*pathschars, false, 0).unwrap_or_default().to_string());
93+
pathschars = pathschars.add(1);
94+
}
95+
}
96+
9297
let sm_friendly_path = strxx(sm_friendly_path, false, 0).unwrap().to_string();
9398

9499
let header = unsafe { std::slice::from_raw_parts(header, headersize).to_vec() };
@@ -100,8 +105,7 @@ pub extern "C" fn rust_post_to_replay_thread(
100105
.send(Msg {
101106
forward,
102107
value,
103-
wrpath,
104-
copypath,
108+
paths: pathsvec,
105109
header,
106110
playerrecording,
107111
totalframes,
@@ -117,30 +121,19 @@ fn replay_thread(recv: Receiver<Msg>) {
117121
while let Ok(msg) = recv.recv() {
118122
//println!("received {msg:?}");
119123

120-
let mut fcopy = None;
121-
let mut fwr = None;
122-
123-
if !msg.copypath.is_empty() {
124-
if let Ok(f) = std::fs::File::create(&msg.copypath).map(std::io::BufWriter::new) {
125-
fcopy = Some(f);
126-
} else {
127-
log_error(format!("Failed to open 'copy' replay file for writing. ('{}')", msg.copypath));
128-
}
129-
}
124+
let mut writers = vec![];
130125

131-
if !msg.wrpath.is_empty() {
132-
if let Ok(f) = std::fs::File::create(&msg.wrpath).map(std::io::BufWriter::new) {
133-
fwr = Some(f);
126+
for path in msg.paths {
127+
if let Ok(f) = std::fs::File::create(&path).map(std::io::BufWriter::new) {
128+
writers.push(f);
134129
} else {
135-
log_error(format!("Failed to open WR replay file for writing. ('{}')", msg.wrpath));
130+
log_error(format!("Failed to open '{path}' replay file for writing."));
136131
}
137132
}
138133

139-
let mut saved = false;
140-
141-
if fcopy.is_some() || fwr.is_some() {
142-
saved = true;
134+
let saved = !writers.is_empty();
143135

136+
if saved {
144137
let cellarray = unsafe { &mut *msg.playerrecording };
145138
let frames = unsafe {
146139
std::slice::from_raw_parts(
@@ -149,31 +142,24 @@ fn replay_thread(recv: Receiver<Msg>) {
149142
)
150143
};
151144

152-
if let Some(f) = &mut fwr {
145+
for f in writers.iter_mut() {
153146
let _ = f.write_all(&msg.header);
154147
let _ = f.write_all(frames);
155-
}
156-
if let Some(f) = &mut fcopy {
157-
let _ = f.write_all(&msg.header);
158-
let _ = f.write_all(frames);
159-
}
160-
161-
if let Some(mut f) = fcopy {
162-
let _ = f.flush();
163-
}
164-
if let Some(mut f) = fwr {
165148
let _ = f.flush();
166149
}
167150
}
168151

152+
drop(writers);
153+
169154
unsafe {
170155
cpp_add_frame_action(
171156
do_callback,
172157
Box::leak(Box::new(Callbacker {
173158
forward: msg.forward,
174-
saved: saved,
175-
value: msg.value,
176-
path: msg.sm_friendly_path,
159+
saved,
160+
value: msg.value,
161+
// TODO: not necessarily a path that was actually saved to but whatever for now...
162+
path: msg.sm_friendly_path,
177163
})) as *mut _ as *mut c_void,
178164
);
179165
}

srcwr💾/src/natives.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ void rust_KILL_replay_thread();
1313
void rust_post_to_replay_thread(
1414
IChangeableForward* forward // what to pass along to the callback
1515
, int value // what to pass along to the callback
16-
, const char* wrpath
17-
, const char* copypath
16+
, const char** paths
1817
, const char* header
1918
, size_t headersize
2019
, void* playerrecording
@@ -52,6 +51,8 @@ static cell_t N_SRCWRFloppy_AsyncSaveReplay(IPluginContext* ctx, const cell_t* p
5251
cell_t callback = params[1];
5352
int value = params[2];
5453

54+
std::vector<const char*> paths{};
55+
5556
char *wrpath_friendly, *copypath_friendly, wrpath[PLATFORM_MAX_PATH]{}, copypath[PLATFORM_MAX_PATH]{};
5657
(void)ctx->LocalToString(params[3], &wrpath_friendly);
5758
(void)ctx->LocalToString(params[4], &copypath_friendly);

0 commit comments

Comments
 (0)