Loop for set count instead of time
This commit is contained in:
		
							
								
								
									
										1
									
								
								common.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								common.h
									
									
									
									
									
								
							@@ -18,6 +18,7 @@
 | 
				
			|||||||
#define WANDERER_SPEEDUP_FACTOR 2.0f
 | 
					#define WANDERER_SPEEDUP_FACTOR 2.0f
 | 
				
			||||||
#define MSG_BUF_LEN 4096
 | 
					#define MSG_BUF_LEN 4096
 | 
				
			||||||
#define LINE_BUF_LEN 1024
 | 
					#define LINE_BUF_LEN 1024
 | 
				
			||||||
 | 
					#define LOOPS 100
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define abs(A) (A < 0 ? A * -1 : A)
 | 
					#define abs(A) (A < 0 ? A * -1 : A)
 | 
				
			||||||
#define min(A, B) (A < B ? A : B)
 | 
					#define min(A, B) (A < B ? A : B)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										34
									
								
								dod.c
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								dod.c
									
									
									
									
									
								
							@@ -5,7 +5,6 @@
 | 
				
			|||||||
#include <stdbool.h>
 | 
					#include <stdbool.h>
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <time.h>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MOVABLE_TAG_SHIFT     0
 | 
					#define MOVABLE_TAG_SHIFT     0
 | 
				
			||||||
#define RENDERABLE_TAG_SHIFT  1
 | 
					#define RENDERABLE_TAG_SHIFT  1
 | 
				
			||||||
@@ -66,12 +65,12 @@ void init_scale_wanderer(Scale *scale, XOR256State *state);
 | 
				
			|||||||
void init_scale_zone(Scale *scale, XOR256State *state);
 | 
					void init_scale_zone(Scale *scale, XOR256State *state);
 | 
				
			||||||
void init_velocity(Velocity *velocity, XOR256State *state);
 | 
					void init_velocity(Velocity *velocity, XOR256State *state);
 | 
				
			||||||
void zero_velocity(Velocity *velocity, XOR256State *state);
 | 
					void zero_velocity(Velocity *velocity, XOR256State *state);
 | 
				
			||||||
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta);
 | 
					u64 update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta);
 | 
				
			||||||
void render_entities(const u8 *tags, const Rect *rects, u64 count);
 | 
					void render_entities(const u8 *tags, const Rect *rects, u64 count);
 | 
				
			||||||
u8 collides(const Rect *rect, const Rect *collider);
 | 
					u8 collides(const Rect *rect, const Rect *collider);
 | 
				
			||||||
i16 get_random_velocity(XOR256State *state);
 | 
					i16 get_random_velocity(XOR256State *state);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void log_data(const Rect *rects, u64 count, FILE *fp, char *line);
 | 
					u64 log_data(const Rect *rects, u64 count, FILE *fp, char *line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(void) {
 | 
					int main(void) {
 | 
				
			||||||
  Allocator arena = wapp_mem_arena_allocator_init(MB(20));
 | 
					  Allocator arena = wapp_mem_arena_allocator_init(MB(20));
 | 
				
			||||||
@@ -99,21 +98,22 @@ int main(void) {
 | 
				
			|||||||
  FILE *fp = fopen("dod.out", "w");
 | 
					  FILE *fp = fopen("dod.out", "w");
 | 
				
			||||||
  assert(fp != NULL);
 | 
					  assert(fp != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  time_t start   = time(NULL);
 | 
					  u64 update_counter = 0;
 | 
				
			||||||
  time_t elapsed = (time_t)-1;
 | 
					  u64 render_counter = 0;
 | 
				
			||||||
  f32 delta = 0.016666666f;
 | 
					  f32 delta = 0.016666666f;
 | 
				
			||||||
  while (elapsed < 20) {
 | 
					  for (u64 i = 0; i < LOOPS; ++i) {
 | 
				
			||||||
    update_positions(manager.tags, manager.rects, manager.velocities, manager.count, delta);
 | 
					    update_counter += update_positions(manager.tags, manager.rects, manager.velocities, manager.count, delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char line[LINE_BUF_LEN] = {0};
 | 
					    char line[LINE_BUF_LEN] = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    log_data(manager.rects, manager.count, fp, line);
 | 
					    render_counter += log_data(manager.rects, manager.count, fp, line);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    elapsed = time(NULL) - start;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  fclose(fp);
 | 
				
			||||||
  wapp_mem_arena_allocator_destroy(&arena);
 | 
					  wapp_mem_arena_allocator_destroy(&arena);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  printf("UPDATE: %lu, RENDER: %lu\n", update_counter, render_counter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -167,7 +167,7 @@ void zero_velocity(Velocity *velocity, XOR256State *state) {
 | 
				
			|||||||
  velocity->y = 0.0f;
 | 
					  velocity->y = 0.0f;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta) {
 | 
					u64 update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta) {
 | 
				
			||||||
  persistent f32 multipliers[2] = {1.0f, 0.5f};
 | 
					  persistent f32 multipliers[2] = {1.0f, 0.5f};
 | 
				
			||||||
  persistent u64 inside_zone_mask = 0x7;
 | 
					  persistent u64 inside_zone_mask = 0x7;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -175,6 +175,7 @@ void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f3
 | 
				
			|||||||
  f32 pos_x, pos_y;
 | 
					  f32 pos_x, pos_y;
 | 
				
			||||||
  f32 max_x, max_y;
 | 
					  f32 max_x, max_y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  u64 total = 0;
 | 
				
			||||||
  for (u64 i = ZONE_COUNT; i < count; ++i) {
 | 
					  for (u64 i = ZONE_COUNT; i < count; ++i) {
 | 
				
			||||||
    tags[i] &= inside_zone_mask;
 | 
					    tags[i] &= inside_zone_mask;
 | 
				
			||||||
    for (u64 j = 0; j < ZONE_COUNT; ++j) {
 | 
					    for (u64 j = 0; j < ZONE_COUNT; ++j) {
 | 
				
			||||||
@@ -201,7 +202,11 @@ void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f3
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    rects[i].position.x = roundf(pos_x);
 | 
					    rects[i].position.x = roundf(pos_x);
 | 
				
			||||||
    rects[i].position.y = roundf(pos_y);
 | 
					    rects[i].position.y = roundf(pos_y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ++total;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u8 collides(const Rect *rect, const Rect *collider) {
 | 
					u8 collides(const Rect *rect, const Rect *collider) {
 | 
				
			||||||
@@ -223,7 +228,8 @@ i16 get_random_velocity(XOR256State *state) {
 | 
				
			|||||||
  return (wapp_prng_xorshift_256(state) % (MAX_ABS_VELOCITY + 1 - MIN_ABS_VELOCITY)) + MIN_ABS_VELOCITY;
 | 
					  return (wapp_prng_xorshift_256(state) % (MAX_ABS_VELOCITY + 1 - MIN_ABS_VELOCITY)) + MIN_ABS_VELOCITY;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void log_data(const Rect *rects, u64 count, FILE *fp, char *line) {
 | 
					u64 log_data(const Rect *rects, u64 count, FILE *fp, char *line) {
 | 
				
			||||||
 | 
					  u64 total = 0;
 | 
				
			||||||
  for (u64 i = 0; i < count; ++i) {
 | 
					  for (u64 i = 0; i < count; ++i) {
 | 
				
			||||||
    snprintf(
 | 
					    snprintf(
 | 
				
			||||||
      line, LINE_BUF_LEN,
 | 
					      line, LINE_BUF_LEN,
 | 
				
			||||||
@@ -236,5 +242,9 @@ void log_data(const Rect *rects, u64 count, FILE *fp, char *line) {
 | 
				
			|||||||
    u64 size = strlen(line);
 | 
					    u64 size = strlen(line);
 | 
				
			||||||
    fwrite(line, sizeof(char), size, fp);
 | 
					    fwrite(line, sizeof(char), size, fp);
 | 
				
			||||||
    memset(line, 0, size);
 | 
					    memset(line, 0, size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ++total;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return total;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								no_dod.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								no_dod.c
									
									
									
									
									
								
							@@ -66,11 +66,12 @@ int main(void) {
 | 
				
			|||||||
  FILE *fp = fopen("no_dod.out", "w");
 | 
					  FILE *fp = fopen("no_dod.out", "w");
 | 
				
			||||||
  assert(fp != NULL);
 | 
					  assert(fp != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  time_t start   = time(NULL);
 | 
					  u64 update_counter = 0;
 | 
				
			||||||
  time_t elapsed = (time_t)-1;
 | 
					  u64 render_counter = 0;
 | 
				
			||||||
  while (elapsed < 20) {
 | 
					  for (u64 i = 0; i < LOOPS; ++i) {
 | 
				
			||||||
    for (u64 i = 0; i < WANDERER_COUNT; ++i) {
 | 
					    for (u64 i = 0; i < WANDERER_COUNT; ++i) {
 | 
				
			||||||
      move_wanderer(&(wanderers[i]), zones);
 | 
					      move_wanderer(&(wanderers[i]), zones);
 | 
				
			||||||
 | 
					      ++update_counter;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    char line[LINE_BUF_LEN] = {0};
 | 
					    char line[LINE_BUF_LEN] = {0};
 | 
				
			||||||
@@ -87,14 +88,15 @@ int main(void) {
 | 
				
			|||||||
      u64 size = strlen(line);
 | 
					      u64 size = strlen(line);
 | 
				
			||||||
      fwrite(line, sizeof(char), size, fp);
 | 
					      fwrite(line, sizeof(char), size, fp);
 | 
				
			||||||
      memset(line, 0, size);
 | 
					      memset(line, 0, size);
 | 
				
			||||||
 | 
					      ++render_counter;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    elapsed = time(NULL) - start;
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fclose(fp);
 | 
					  fclose(fp);
 | 
				
			||||||
  wapp_mem_arena_allocator_destroy(&arena);
 | 
					  wapp_mem_arena_allocator_destroy(&arena);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  printf("UPDATE: %lu, RENDER: %lu\n", update_counter, render_counter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return 0;
 | 
					  return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user