Test without Raylib
This commit is contained in:
69
no_dod.c
69
no_dod.c
@@ -1,9 +1,10 @@
|
||||
#include "wapp.h"
|
||||
#include "common.h"
|
||||
#include "raylib.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define OBJECT_COMMON struct {Position position; Scale scale;}
|
||||
|
||||
@@ -39,19 +40,11 @@ struct SlowZone {
|
||||
|
||||
void init_wanderer(Wanderer *wanderer, XOR256State *state);
|
||||
void move_wanderer(Wanderer *wanderer, const SlowZone *zones);
|
||||
void render_wanderer(const Wanderer *wanderer);
|
||||
void init_slow_zone(SlowZone *zone, XOR256State *state);
|
||||
|
||||
void render_slow_zone(const SlowZone *zone);
|
||||
|
||||
bool inside_zone(const Wanderer *wanderer, const SlowZone *zone);
|
||||
f32 get_random_float(XOR256State *state);
|
||||
|
||||
int main(void) {
|
||||
SetTraceLogLevel(LOG_NONE);
|
||||
InitWindow(WIDTH, HEIGHT, "No-DOD test");
|
||||
SetTargetFPS(120);
|
||||
|
||||
Allocator arena = wapp_mem_arena_allocator_init(MB(20));
|
||||
XOR256State state = wapp_prng_xorshift_init_state();
|
||||
u64 wanderers_size = sizeof(Wanderer) * WANDERER_COUNT;
|
||||
@@ -70,37 +63,38 @@ int main(void) {
|
||||
init_slow_zone(&(zones[i]),&state);
|
||||
}
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
f64 time = GetTime();
|
||||
if (time >= 20.0) {
|
||||
break;
|
||||
}
|
||||
FILE *fp = fopen("no_dod.out", "w");
|
||||
assert(fp != NULL);
|
||||
|
||||
time_t start = time(NULL);
|
||||
time_t elapsed = (time_t)-1;
|
||||
while (elapsed < 20) {
|
||||
for (u64 i = 0; i < WANDERER_COUNT; ++i) {
|
||||
move_wanderer(&(wanderers[i]), zones);
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(BG_COLOR);
|
||||
|
||||
for (u64 i = 0; i < ZONE_COUNT; ++i) {
|
||||
render_slow_zone(&(zones[i]));
|
||||
}
|
||||
char line[LINE_BUF_LEN] = {0};
|
||||
|
||||
for (u64 i = 0; i < WANDERER_COUNT; ++i) {
|
||||
render_wanderer(&(wanderers[i]));
|
||||
snprintf(
|
||||
line, LINE_BUF_LEN,
|
||||
"x: %f, y: %f, width: %f, height: %f\n",
|
||||
wanderers[i].position.x,
|
||||
wanderers[i].position.y,
|
||||
wanderers[i].scale.width,
|
||||
wanderers[i].scale.height
|
||||
);
|
||||
u64 size = strlen(line);
|
||||
fwrite(line, sizeof(char), size, fp);
|
||||
memset(line, 0, size);
|
||||
}
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
elapsed = time(NULL) - start;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
wapp_mem_arena_allocator_destroy(&arena);
|
||||
|
||||
CloseWindow();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -157,17 +151,6 @@ void move_wanderer(Wanderer *wanderer, const SlowZone *zones) {
|
||||
}
|
||||
}
|
||||
|
||||
void render_wanderer(const Wanderer *wanderer) {
|
||||
Color color = wanderer->slow ? ZONE_COLOR : FG_COLOR;
|
||||
DrawRectangle(
|
||||
(i32)wanderer->position.x,
|
||||
(i32)wanderer->position.y,
|
||||
(i32)wanderer->scale.width,
|
||||
(i32)wanderer->scale.height,
|
||||
color
|
||||
);
|
||||
}
|
||||
|
||||
void init_slow_zone(SlowZone *zone, XOR256State *state) {
|
||||
zone->position = (Position){
|
||||
.x = wapp_prng_xorshift_256(state) % WIDTH,
|
||||
@@ -180,16 +163,6 @@ void init_slow_zone(SlowZone *zone, XOR256State *state) {
|
||||
};
|
||||
}
|
||||
|
||||
void render_slow_zone(const SlowZone *zone) {
|
||||
DrawRectangleLines(
|
||||
zone->position.x,
|
||||
zone->position.y,
|
||||
zone->scale.width,
|
||||
zone->scale.height,
|
||||
ZONE_COLOR
|
||||
);
|
||||
}
|
||||
|
||||
bool inside_zone(const Wanderer *wanderer, const SlowZone *zone) {
|
||||
f32 wanderer_min_x = wanderer->position.x + wanderer->scale.width;
|
||||
f32 wanderer_min_y = wanderer->position.y + wanderer->scale.height;
|
||||
|
||||
Reference in New Issue
Block a user