Compare commits
	
		
			2 Commits
		
	
	
		
			fc20602531
			...
			e812b36604
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e812b36604 | |||
| 7c79190a18 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -5,3 +5,4 @@ compile_commands.json
 | 
			
		||||
raylib
 | 
			
		||||
raylib-build
 | 
			
		||||
*_stats
 | 
			
		||||
*.data
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
CC         = clang
 | 
			
		||||
CFLAGS     = -g -O3 -Iraylib/include -Iwapp/src
 | 
			
		||||
LDFLAGS    = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib -lprofiler
 | 
			
		||||
LDFLAGS    = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib
 | 
			
		||||
 | 
			
		||||
.PHONY: all raylib no_dod dod
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								common.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								common.h
									
									
									
									
									
								
							@@ -10,7 +10,7 @@
 | 
			
		||||
#define BG_COLOR (Color){.r = 0xea, .g = 0xf2, .b = 0xe3, .a = 0xff}
 | 
			
		||||
#define FG_COLOR (Color){.r = 0x42, .g = 0x4C, .b = 0x55, .a = 0xff}
 | 
			
		||||
#define ZONE_COLOR (Color){.r = 0xb4, .g = 0x65, .b = 0x4a, .a = 0xff}
 | 
			
		||||
#define WANDERER_COUNT 300000
 | 
			
		||||
#define WANDERER_COUNT 500000
 | 
			
		||||
#define ZONE_COUNT 5
 | 
			
		||||
#define WANDERER_SLOWDOWN_FACTOR 0.5f
 | 
			
		||||
#define WANDERER_SPEEDUP_FACTOR 2.0f
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								dod.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								dod.c
									
									
									
									
									
								
							@@ -61,8 +61,7 @@ void init_scale_wanderer(Scale *scale, XOR256State *state);
 | 
			
		||||
void init_scale_zone(Scale *scale, XOR256State *state);
 | 
			
		||||
void init_velocity(Velocity *velocity, XOR256State *state);
 | 
			
		||||
void zero_velocity(Velocity *velocity, XOR256State *state);
 | 
			
		||||
void check_collisions(u8 *tags, Rect *rects, u64 count);
 | 
			
		||||
void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 count);
 | 
			
		||||
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count);
 | 
			
		||||
void render_entities(const u8 *tags, const Rect *rects, u64 count);
 | 
			
		||||
u64 collides(const Rect *rect, const Rect *collider);
 | 
			
		||||
f32 get_random_float(XOR256State *state);
 | 
			
		||||
@@ -70,7 +69,7 @@ f32 get_random_float(XOR256State *state);
 | 
			
		||||
int main(void) {
 | 
			
		||||
  SetTraceLogLevel(LOG_NONE);
 | 
			
		||||
  InitWindow(WIDTH, HEIGHT, "DOD test");
 | 
			
		||||
  SetTargetFPS(120);
 | 
			
		||||
  // SetTargetFPS(120);
 | 
			
		||||
 | 
			
		||||
  Allocator arena = wapp_mem_arena_allocator_init(MB(20));
 | 
			
		||||
  assert(!wapp_mem_allocator_invalid(&arena));
 | 
			
		||||
@@ -100,15 +99,13 @@ int main(void) {
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    check_collisions(manager.tags, manager.rects, manager.count);
 | 
			
		||||
 | 
			
		||||
    update_positions(manager.tags, manager.rects, manager.velocities, manager.count);
 | 
			
		||||
 | 
			
		||||
    BeginDrawing();
 | 
			
		||||
 | 
			
		||||
    ClearBackground(BG_COLOR);
 | 
			
		||||
 | 
			
		||||
    render_entities(manager.tags, manager.rects, manager.count);
 | 
			
		||||
    // render_entities(manager.tags, manager.rects, manager.count);
 | 
			
		||||
 | 
			
		||||
    DrawFPS(10, 10);
 | 
			
		||||
 | 
			
		||||
@@ -170,11 +167,17 @@ void zero_velocity(Velocity *velocity, XOR256State *state) {
 | 
			
		||||
  velocity->y = 0.0f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 count) {
 | 
			
		||||
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count) {
 | 
			
		||||
  u8 index = 0;
 | 
			
		||||
  f32 multipliers[2] = {1.0f, 0.5f};
 | 
			
		||||
  persistent u64 inside_zone_mask = 0x7;
 | 
			
		||||
 | 
			
		||||
  for (u64 i = ZONE_COUNT; i < count; ++i) {
 | 
			
		||||
    tags[i] &= inside_zone_mask;
 | 
			
		||||
    for (u64 j = 0; j < ZONE_COUNT; ++j) {
 | 
			
		||||
      tags[i] |= collides(&rects[i], &rects[j]) << 3;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  for (u64 i = 0; i < count; ++i) {
 | 
			
		||||
    index = (tags[i] & ENTITY_TAG_INSIDE_ZONE) == ENTITY_TAG_INSIDE_ZONE;
 | 
			
		||||
 | 
			
		||||
    rects[i].position.x += velocities[i].x * multipliers[index];
 | 
			
		||||
@@ -195,16 +198,6 @@ void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 cou
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void check_collisions(u8 *tags, Rect *rects, u64 count) {
 | 
			
		||||
  persistent u64 inside_zone_mask = 0x7;
 | 
			
		||||
  for (u64 i = ZONE_COUNT; i < count; ++i) {
 | 
			
		||||
    tags[i] &= inside_zone_mask;
 | 
			
		||||
    for (u64 j = 0; j < ZONE_COUNT; ++j) {
 | 
			
		||||
      tags[i] |= collides(&rects[i], &rects[j]) << 3;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void render_entities(const u8 *tags, const Rect *rects, u64 count) {
 | 
			
		||||
  persistent RaylibDrawRectFunc renderers[2] = {DrawRectangle, DrawRectangleLines};
 | 
			
		||||
  persistent Color colors[2]                 = {FG_COLOR, ZONE_COLOR};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								no_dod.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								no_dod.c
									
									
									
									
									
								
							@@ -51,7 +51,7 @@ f32 get_random_float(XOR256State *state);
 | 
			
		||||
int main(void) {
 | 
			
		||||
  SetTraceLogLevel(LOG_NONE);
 | 
			
		||||
  InitWindow(WIDTH, HEIGHT, "No-DOD test");
 | 
			
		||||
  SetTargetFPS(120);
 | 
			
		||||
  // SetTargetFPS(120);
 | 
			
		||||
 | 
			
		||||
  Allocator arena       = wapp_mem_arena_allocator_init(MB(20));
 | 
			
		||||
  XOR256State state     = wapp_prng_xorshift_init_state();
 | 
			
		||||
@@ -85,13 +85,13 @@ int main(void) {
 | 
			
		||||
 | 
			
		||||
    ClearBackground(BG_COLOR);
 | 
			
		||||
 | 
			
		||||
    for (u64 i = 0; i < ZONE_COUNT; ++i) {
 | 
			
		||||
      render_slow_zone(&(zones[i]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (u64 i = 0; i < WANDERER_COUNT; ++i) {
 | 
			
		||||
      render_wanderer(&(wanderers[i]));
 | 
			
		||||
    }
 | 
			
		||||
    // for (u64 i = 0; i < ZONE_COUNT; ++i) {
 | 
			
		||||
    //   render_slow_zone(&(zones[i]));
 | 
			
		||||
    // }
 | 
			
		||||
    //
 | 
			
		||||
    // for (u64 i = 0; i < WANDERER_COUNT; ++i) {
 | 
			
		||||
    //   render_wanderer(&(wanderers[i]));
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    DrawFPS(10, 10);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user