@@ -68,14 +68,15 @@ var background_maps_len: u32 = 0;
68
68
pub var viewport : Vec2 = .{ .x = 0 , .y = 0 };
69
69
70
70
// Various infos about the last frame
71
- // struct {
72
- // int entities;
73
- // int checks;
74
- // int draw_calls;
75
- // float update;
76
- // float draw;
77
- // float total;
78
- // } perf;
71
+ const Perf = struct {
72
+ entities : usize ,
73
+ checks : usize ,
74
+ draw_calls : usize ,
75
+ update : f32 ,
76
+ draw : f32 ,
77
+ total : f32 ,
78
+ };
79
+ pub var perf : Perf = undefined ;
79
80
80
81
var scene : ? * Scene = null ;
81
82
var scene_next : ? * Scene = null ;
@@ -125,7 +126,7 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
125
126
}
126
127
127
128
pub fn update () void {
128
- // const time_frame_start = platform.now();
129
+ const time_frame_start = platform .now ();
129
130
130
131
// Do we want to switch scenes?
131
132
if (scene_next ) | scene_n | {
@@ -174,7 +175,7 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
174
175
sceneBaseUpdate ();
175
176
}
176
177
177
- // perf.update = platform_now( ) - time_real_now;
178
+ perf .update = @floatCast ( platform . now ( ) - time_real_now ) ;
178
179
179
180
render .framePrepare ();
180
181
@@ -186,16 +187,16 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
186
187
}
187
188
188
189
render .frameEnd ();
189
- // engine. perf.draw = (platform_now( ) - time_real_now) - engine. perf.update;
190
+ perf .draw = @as ( f32 , @floatCast ( platform . now ( ) - time_real_now )) - perf .update ;
190
191
alloc .bumpReset (mark );
191
192
mark .index = 0xFFFFFFFF ;
192
193
}
193
194
194
195
input .clear ();
195
196
// temp.alloc_check();
196
197
197
- // engine. perf.draw_calls = render_draw_calls ();
198
- // engine. perf.total = platform_now( ) - time_frame_start;
198
+ // perf.draw_calls = render.drawCalls ();
199
+ perf .total = @floatCast ( platform . now ( ) - time_frame_start ) ;
199
200
}
200
201
201
202
pub fn cleanup () void {
@@ -347,19 +348,17 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
347
348
const len : usize = entities_len ;
348
349
349
350
// Sweep touches
350
- // engine. perf.checks = 0;
351
+ perf .checks = 0 ;
351
352
i = 0 ;
352
- for (entities ) | e1 | {
353
- if (i == len ) break ;
354
-
353
+ for (entities [0.. len ]) | e1 | {
355
354
if (e1 .base .check_against != ett .ENTITY_GROUP_NONE or
356
355
e1 .base .group != ett .ENTITY_GROUP_NONE or (e1 .base .physics > ett .ENTITY_COLLIDES_LITE ))
357
356
{
358
357
const max_pos = e1 .base .pos .x + e1 .base .size .x ;
359
358
var j : usize = i + 1 ;
360
359
while (j < len and entities [j ].base .pos .x < max_pos ) {
361
360
const e2 = entities [j ];
362
- // engine. perf.checks += 1;
361
+ perf .checks += 1 ;
363
362
364
363
if (entityIsTouching (e1 , e2 )) {
365
364
if (contains (e1 .base .check_against , e2 .base .group )) {
@@ -383,15 +382,16 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
383
382
i += 1 ;
384
383
}
385
384
386
- //engine. perf.entities = entities_len;
385
+ perf .entities = entities_len ;
387
386
}
387
+
388
388
fn contains (g1 : u8 , g2 : u8 ) bool {
389
389
return (g1 & g2 ) != 0 ;
390
390
}
391
391
392
392
fn cmpEntityPos (context : void , a : * T , b : * T ) bool {
393
393
_ = context ;
394
- return a .base .pos .x > b .base .pos .x ;
394
+ return a .base .pos .x <= b .base .pos .x ;
395
395
}
396
396
397
397
fn initEntity (entity : * T ) void {
@@ -631,7 +631,18 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
631
631
.base = .{
632
632
.id = entity_unique_id ,
633
633
.is_alive = true ,
634
+ .on_ground = false ,
635
+ .draw_order = 0 ,
636
+ .physics = ett .ENTITY_GROUP_NONE ,
637
+ .group = ett .ENTITY_GROUP_NONE ,
638
+ .check_against = ett .ENTITY_GROUP_NONE ,
634
639
.pos = pos ,
640
+ .vel = vec2 (0 , 0 ),
641
+ .accel = vec2 (0 , 0 ),
642
+ .friction = vec2 (0 , 0 ),
643
+ .offset = vec2 (0 , 0 ),
644
+ .health = 0 ,
645
+ .restitution = 0 ,
635
646
.max_ground_normal = 0.69 , // cosf(to_radians(46)),
636
647
.min_slide_normal = 1 , // cosf(to_radians(0)),
637
648
.gravity = 1 ,
@@ -725,7 +736,7 @@ pub fn Engine(comptime T: type, comptime TKind: type) type {
725
736
726
737
fn cmpEntity (context : void , lhs : * T , rhs : * T ) bool {
727
738
_ = context ;
728
- return lhs .base .draw_order > rhs .base .draw_order ;
739
+ return lhs .base .draw_order <= rhs .base .draw_order ;
729
740
}
730
741
731
742
const EntitySettings = struct {
0 commit comments