|
| 1 | +use std::marker::PhantomData; |
| 2 | +use std::ptr::null_mut; |
1 | 3 | use crate::define_unity_interface; |
2 | 4 | use crate::interface::UnityInterface; |
3 | 5 | use crate::bitflag; |
@@ -377,6 +379,24 @@ define_unity_interface!( |
377 | 379 |
|
378 | 380 | pub type ProfilerCounterStatePtrCallback = UnityProfilerCounterStatePtrCallback; |
379 | 381 |
|
| 382 | +pub struct ProfilerCounter<T> { |
| 383 | + pub(crate) counter: *mut ::std::os::raw::c_void, |
| 384 | +} |
| 385 | + |
| 386 | +impl<T> ProfilerCounter<T> { |
| 387 | + pub fn value(&self) -> &T { |
| 388 | + unsafe { |
| 389 | + self.counter as &T |
| 390 | + } |
| 391 | + } |
| 392 | + |
| 393 | + pub fn value_mut(&mut self) -> &mut T { |
| 394 | + unsafe { |
| 395 | + self.counter as &mut T |
| 396 | + } |
| 397 | + } |
| 398 | +} |
| 399 | + |
380 | 400 | macro_rules! impl_profiler_v2 { |
381 | 401 | () => { |
382 | 402 | impl_profiler!(); |
@@ -404,12 +424,34 @@ macro_rules! impl_profiler_v2 { |
404 | 424 | activate_func: ProfilerCounterStatePtrCallback, |
405 | 425 | deactivate_func: ProfilerCounterStatePtrCallback, |
406 | 426 | user_data: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void { |
407 | | - self.interface().CreateCounterValue.expect("CreateCounterValue")(category, name.as_ptr(), flags.into(), value_type.into(), value_unit.into(), value_size, counter_flags.into(), activate_func, deactivate_func, user_data) |
| 427 | + self.interface().CreateCounterValue.expect("CreateCounterValue")(category, name.as_ptr(), flags.into(), value_type as u8, value_unit as u8, value_size, counter_flags.into(), activate_func, deactivate_func, user_data) |
408 | 428 | } |
409 | 429 |
|
410 | 430 | pub unsafe fn flush_counter_value(&self, counter: *mut ::std::os::raw::c_void) { |
411 | 431 | self.interface().FlushCounterValue.expect("FlushCounterValue")(counter) |
412 | 432 | } |
| 433 | + |
| 434 | + pub unsafe fn create_counter<T>(&self, |
| 435 | + category: ProfilerCategoryId, |
| 436 | + name: &std::ffi::CStr, |
| 437 | + flags: ProfilerMarkerFlags, |
| 438 | + value_type: ProfilerMarkerDataType, |
| 439 | + value_unit: ProfilerMarkerDataUnit, |
| 440 | + counter_flags: ProfilerCounterFlags, |
| 441 | + activate_func: ProfilerCounterStatePtrCallback, |
| 442 | + deactivate_func: ProfilerCounterStatePtrCallback, |
| 443 | + user_data: *mut ::std::os::raw::c_void) -> Option<ProfilerCounter<T>> { |
| 444 | + let r = self.create_counter_value(category, name, flags, value_type, value_unit, std::mem::size_of::<T>(), counter_flags.into(), activate_func, deactivate_func, user_data); |
| 445 | + if r != null_mut() { |
| 446 | + Some(ProfilerCounter::<T> { counter: r }) |
| 447 | + } else { |
| 448 | + None |
| 449 | + } |
| 450 | + } |
| 451 | + |
| 452 | + pub unsafe fn flush_counter<T>(&self, counter: &mut ProfilerCounter<T>) { |
| 453 | + self.flush_counter_value(counter.counter); |
| 454 | + } |
413 | 455 | } |
414 | 456 | } |
415 | 457 |
|
|
0 commit comments