Skip to content

Commit 58809b8

Browse files
committed
Correct frame count.
1 parent 5c6bde8 commit 58809b8

5 files changed

Lines changed: 36 additions & 6 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from mewnala import *
2+
3+
4+
def setup():
5+
size(200, 200)
6+
background(100, 0, 0)
7+
print(width)
8+
9+
def draw():
10+
pass
11+
12+
run()

crates/processing_pyo3/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ mod mewnala {
859859
graphics.begin_draw()?;
860860
}
861861

862+
processing::prelude::advance_frame_count()
863+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
864+
862865
sync_globals(module, &globals)?;
863866
dispatch_event_callbacks(&locals)?;
864867

crates/processing_render/src/graphics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ pub fn create(
201201
Camera {
202202
// always load the previous frame (provides sketch like behavior)
203203
clear_color: ClearColorConfig::None,
204-
// TODO: toggle this conditionally based on whether we need to write back MSAA
205-
// when doing manual pixel updates
206-
msaa_writeback: MsaaWriteback::Off,
204+
msaa_writeback: MsaaWriteback::Auto,
207205
..default()
208206
},
209207
target,

crates/processing_render/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl Plugin for ProcessingRenderPlugin {
4343

4444
let config = app.world().resource::<Config>().clone();
4545

46+
app.init_resource::<time::ProcessingFrame>();
47+
4648
let has_sketch_file = config
4749
.get(ConfigKey::SketchFileName)
4850
.is_some_and(|f| !f.is_empty());
@@ -1393,6 +1395,15 @@ pub fn frame_count() -> error::Result<u32> {
13931395
})
13941396
}
13951397

1398+
pub fn advance_frame_count() -> error::Result<()> {
1399+
app_mut(|app| {
1400+
app.world_mut()
1401+
.run_system_cached(time::advance_frame_count)
1402+
.unwrap();
1403+
Ok(())
1404+
})
1405+
}
1406+
13961407
pub fn delta_time() -> error::Result<f32> {
13971408
app_mut(|app| Ok(app.world_mut().run_system_cached(time::delta_secs).unwrap()))
13981409
}

crates/processing_render/src/time.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
use bevy::diagnostic::FrameCount;
21
use bevy::prelude::*;
32
use bevy::time::Time;
43

5-
pub fn frame_count(count: Option<Res<FrameCount>>) -> u32 {
6-
count.map(|c| c.0).unwrap_or(0)
4+
#[derive(Resource, Default, Debug, Clone, Copy)]
5+
pub struct ProcessingFrame(pub u32);
6+
7+
pub fn frame_count(frame: Option<Res<ProcessingFrame>>) -> u32 {
8+
frame.map(|f| f.0).unwrap_or(0)
9+
}
10+
11+
pub fn advance_frame_count(mut frame: ResMut<ProcessingFrame>) {
12+
frame.0 = frame.0.wrapping_add(1);
713
}
814

915
pub fn delta_secs(time: Option<Res<Time>>) -> f32 {

0 commit comments

Comments
 (0)