-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b2c726
commit 15b122a
Showing
8 changed files
with
145 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
*/ | ||
|
||
mod dr_physics; | ||
/// 平台相关的代码 | ||
pub mod platform; | ||
/// Python 交互 | ||
mod python; | ||
/// 也许是一些渲染的东西 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[cfg(windows)] | ||
pub mod win; |
28 changes: 28 additions & 0 deletions
28
mods/dr_game/Difficult_Rocket_rs/src/src/platform/win/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use windows_sys::Win32::{ | ||
Foundation::HWND, | ||
System::Threading::GetCurrentProcessId, | ||
UI::WindowsAndMessaging::{EnumWindows, GetWindowThreadProcessId}, | ||
}; | ||
|
||
unsafe extern "system" fn enum_windows_proc(hwnd: HWND, lparam: isize) -> i32 { | ||
let mut process_id = 0; | ||
GetWindowThreadProcessId(hwnd, &mut process_id); | ||
if process_id == GetCurrentProcessId() { | ||
println!("找到当前的窗口: {:?}", hwnd); | ||
*(lparam as *mut HWND) = hwnd; | ||
return 0; | ||
} | ||
1 | ||
} | ||
|
||
pub fn get_window_handler() -> Option<isize> { | ||
let mut window: HWND = std::ptr::null_mut(); | ||
|
||
let result = unsafe { EnumWindows(Some(enum_windows_proc), &mut window as *mut _ as isize) }; | ||
|
||
if result != 0 { | ||
return None; | ||
} | ||
|
||
Some(window as isize) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pub mod console; | |
pub mod data; | ||
#[allow(unused)] | ||
pub mod editor; | ||
pub mod renders; |
19 changes: 19 additions & 0 deletions
19
mods/dr_game/Difficult_Rocket_rs/src/src/python/renders.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use pyo3::prelude::*; | ||
|
||
#[pyclass] | ||
pub struct WgpuRenderPy { | ||
#[cfg(windows)] | ||
pub app: crate::renders::win_gpu::WgpuContext, | ||
} | ||
|
||
#[pymethods] | ||
impl WgpuRenderPy { | ||
pub fn on_draw(&mut self) { | ||
#[cfg(windows)] | ||
self.app.on_draw(); | ||
} | ||
} | ||
|
||
impl WgpuRenderPy { | ||
pub fn new(app: crate::renders::win_gpu::WgpuContext) -> Self { Self { app } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
#[cfg(windows)] | ||
mod win; | ||
pub mod win; | ||
#[cfg(windows)] | ||
mod win_gpu; | ||
pub mod win_gpu; | ||
|
||
use pyo3::pyfunction; | ||
|
||
#[pyfunction] | ||
pub fn render_hack() { | ||
pub fn render_hack() -> Option<crate::python::renders::WgpuRenderPy> { | ||
println!("render_hacking_start"); | ||
#[cfg(windows)] | ||
win::render_main(); | ||
// let render = win::render_main(); | ||
let render = win_gpu::render_init(); | ||
#[cfg(not(windows))] | ||
println!("对不起不支持非 Windows 捏"); | ||
println!("render_hacking_end"); | ||
render | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters