Compare commits
15 Commits
c6dc37c696
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 45e3bc83a9 | |||
| 40b5bb1634 | |||
| 054a3bbdd7 | |||
|
|
f8b859b4e8 | ||
|
|
d94c7f8c63 | ||
|
|
cdb02bd209 | ||
| cadba71330 | |||
| e6d39028fb | |||
| a9d4b4eae1 | |||
| 61f66ae554 | |||
| a7d255dba6 | |||
| 961afcd4f4 | |||
| 3696205f47 | |||
| c6cac7be8a | |||
| 60df7c5fbb |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,3 +8,4 @@ raylib-build
|
|||||||
*.data
|
*.data
|
||||||
*.ods
|
*.ods
|
||||||
*.dSYM
|
*.dSYM
|
||||||
|
*.out
|
||||||
|
|||||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -1,6 +1,6 @@
|
|||||||
[submodule "wapp"]
|
[submodule "wapp"]
|
||||||
path = wapp
|
path = wapp
|
||||||
url = git@git.thewizardapprentice.com:abdelrahman/wizapp-stdlib
|
url = https://git.thewizardapprentice.com/abdelrahman/wizapp-stdlib
|
||||||
[submodule "raylib-src"]
|
[submodule "raylib-src"]
|
||||||
path = raylib-src
|
path = raylib-src
|
||||||
url = git@github.com:raysan5/raylib
|
url = https://github.com/raysan5/raylib
|
||||||
|
|||||||
19
Makefile
19
Makefile
@@ -1,28 +1,30 @@
|
|||||||
CC = clang
|
CC = clang
|
||||||
CFLAGS = -g -O3 -Iraylib/include -Iwapp/src
|
CFLAGS = -g -O3 -Iraylib/include -Iwapp/src
|
||||||
LDFLAGS = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib
|
LDFLAGS = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib -lm -lpthread
|
||||||
BASEDIR = $(shell realpath ./)
|
BASEDIR = $(shell realpath ./)
|
||||||
RL_SRCDIR = ${BASEDIR}/raylib-src/src
|
RL_SRCDIR = ${BASEDIR}/raylib-src/src
|
||||||
RL_BUILDDIR = ${BASEDIR}/raylib-build
|
RL_BUILDDIR = ${BASEDIR}/raylib-build
|
||||||
RL_DESTDIR = ${BASEDIR}/raylib
|
RL_DESTDIR = ${BASEDIR}/raylib
|
||||||
RL_LIBDIR = ${RL_DESTDIR}/lib
|
RL_LIBDIR = ${RL_DESTDIR}/lib
|
||||||
RL_INCLUDEDIR = ${RL_DESTDIR}/include
|
RL_INCLUDEDIR = ${RL_DESTDIR}/include
|
||||||
|
PLATFORM = $(shell uname)
|
||||||
|
|
||||||
.PHONY: all raylib wapp no_dod dod
|
.PHONY: all raylib wapp no_dod dod clean
|
||||||
|
|
||||||
all: no_dod dod
|
all: no_dod dod
|
||||||
|
|
||||||
# raylib:
|
|
||||||
# cmake -S raylib-src -B raylib-build -DCMAKE_INSTALL_PREFIX=raylib -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_SHARED_LIBS=ON -G "Ninja Multi-Config"
|
|
||||||
# cmake --build raylib-build --config=Release
|
|
||||||
# cmake --install raylib-build --config=Release
|
|
||||||
|
|
||||||
raylib:
|
raylib:
|
||||||
|
ifeq ($(PLATFORM), Linux)
|
||||||
|
cmake -S raylib-src -B raylib-build -DCMAKE_INSTALL_PREFIX=raylib -DCMAKE_CONFIGURATION_TYPES=Release -DBUILD_SHARED_LIBS=ON -G "Ninja Multi-Config"
|
||||||
|
cmake --build raylib-build --config=Release
|
||||||
|
cmake --install raylib-build --config=Release
|
||||||
|
else
|
||||||
mkdir -p ${RL_BUILDDIR} ${RL_LIBDIR} ${RL_INCLUDEDIR}
|
mkdir -p ${RL_BUILDDIR} ${RL_LIBDIR} ${RL_INCLUDEDIR}
|
||||||
cd ${RL_SRCDIR} && \
|
cd ${RL_SRCDIR} && \
|
||||||
make PLATFORM=PLATFORM_DESKTOP RAYLIB_RELEASE_PATH=${RL_BUILDDIR} RAYLIB_LIBTYPE=SHARED && \
|
make PLATFORM=PLATFORM_DESKTOP RAYLIB_RELEASE_PATH=${RL_BUILDDIR} RAYLIB_LIBTYPE=SHARED && \
|
||||||
cp ${RL_BUILDDIR}/* ${RL_LIBDIR} && \
|
cp ${RL_BUILDDIR}/* ${RL_LIBDIR} && \
|
||||||
cp ${RL_SRCDIR}/*.h ${RL_INCLUDEDIR}
|
cp ${RL_SRCDIR}/*.h ${RL_INCLUDEDIR}
|
||||||
|
endif
|
||||||
|
|
||||||
wapp:
|
wapp:
|
||||||
cd wapp && python3 -m codegen
|
cd wapp && python3 -m codegen
|
||||||
@@ -32,3 +34,6 @@ no_dod: raylib wapp
|
|||||||
|
|
||||||
dod: raylib wapp
|
dod: raylib wapp
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) dod.c wapp/src/wapp.c -o dod
|
$(CC) $(CFLAGS) $(LDFLAGS) dod.c wapp/src/wapp.c -o dod
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf ${RL_BUILDDIR} ${RL_DESTDIR}
|
||||||
|
|||||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Data-Oriented Design Test
|
||||||
|
|
||||||
|
Playing around with [DOD](https://en.wikipedia.org/wiki/Data-oriented_design) concepts and comparing performance of resulting applications.
|
||||||
3
common.h
3
common.h
@@ -7,6 +7,8 @@
|
|||||||
#define MAX_WANDERER_DIM 8
|
#define MAX_WANDERER_DIM 8
|
||||||
#define MIN_WANDERER_DIM 3
|
#define MIN_WANDERER_DIM 3
|
||||||
#define MIN_ZONE_DIM 30
|
#define MIN_ZONE_DIM 30
|
||||||
|
#define MIN_ABS_VELOCITY 200
|
||||||
|
#define MAX_ABS_VELOCITY 600
|
||||||
#define BG_COLOR (Color){.r = 0xea, .g = 0xf2, .b = 0xe3, .a = 0xff}
|
#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 FG_COLOR (Color){.r = 0x42, .g = 0x4C, .b = 0x55, .a = 0xff}
|
||||||
#define ZONE_COLOR (Color){.r = 0xb4, .g = 0x65, .b = 0x4a, .a = 0xff}
|
#define ZONE_COLOR (Color){.r = 0xb4, .g = 0x65, .b = 0x4a, .a = 0xff}
|
||||||
@@ -15,6 +17,7 @@
|
|||||||
#define WANDERER_SLOWDOWN_FACTOR 0.5f
|
#define WANDERER_SLOWDOWN_FACTOR 0.5f
|
||||||
#define WANDERER_SPEEDUP_FACTOR 2.0f
|
#define WANDERER_SPEEDUP_FACTOR 2.0f
|
||||||
#define MSG_BUF_LEN 4096
|
#define MSG_BUF_LEN 4096
|
||||||
|
|
||||||
#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)
|
||||||
#define max(A, B) (A > B ? A : B)
|
#define max(A, B) (A > B ? A : B)
|
||||||
|
|||||||
173
dod.c
173
dod.c
@@ -1,10 +1,14 @@
|
|||||||
#include "wapp.h"
|
#include "wapp.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include <math.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#define THREAD_COUNT 4
|
||||||
|
|
||||||
#define MOVABLE_TAG_SHIFT 0
|
#define MOVABLE_TAG_SHIFT 0
|
||||||
#define RENDERABLE_TAG_SHIFT 1
|
#define RENDERABLE_TAG_SHIFT 1
|
||||||
@@ -20,19 +24,19 @@ enum EntityTag {
|
|||||||
|
|
||||||
typedef struct Entity Entity;
|
typedef struct Entity Entity;
|
||||||
struct Entity {
|
struct Entity {
|
||||||
u16 id;
|
u32 id;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Position Position;
|
typedef struct Position Position;
|
||||||
struct Position {
|
struct Position {
|
||||||
f32 x;
|
i16 x;
|
||||||
f32 y;
|
i16 y;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Scale Scale;
|
typedef struct Scale Scale;
|
||||||
struct Scale {
|
struct Scale {
|
||||||
f32 width;
|
i16 width;
|
||||||
f32 height;
|
i16 height;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Rect Rect;
|
typedef struct Rect Rect;
|
||||||
@@ -43,8 +47,8 @@ struct Rect {
|
|||||||
|
|
||||||
typedef struct Velocity Velocity;
|
typedef struct Velocity Velocity;
|
||||||
struct Velocity {
|
struct Velocity {
|
||||||
f32 x;
|
i16 x;
|
||||||
f32 y;
|
i16 y;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Manager Manager;
|
typedef struct Manager Manager;
|
||||||
@@ -56,6 +60,17 @@ struct Manager {
|
|||||||
u64 count;
|
u64 count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct PositionThreadArgs PositionThreadArgs;
|
||||||
|
struct PositionThreadArgs {
|
||||||
|
const Rect *zones;
|
||||||
|
Rect *rects;
|
||||||
|
Velocity *velocities;
|
||||||
|
u8 *tags;
|
||||||
|
u64 count;
|
||||||
|
f32 delta;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void *(*PThreadRoutine)(void *);
|
||||||
typedef void (*ScaleInitialiser)(Scale *scale, XOR256State *state);
|
typedef void (*ScaleInitialiser)(Scale *scale, XOR256State *state);
|
||||||
typedef void (*VelocityInitialiser)(Velocity *velocity, XOR256State *state);
|
typedef void (*VelocityInitialiser)(Velocity *velocity, XOR256State *state);
|
||||||
typedef void (*RaylibDrawRectFunc)(int posX, int posY, int width, int height, Color color);
|
typedef void (*RaylibDrawRectFunc)(int posX, int posY, int width, int height, Color color);
|
||||||
@@ -66,15 +81,18 @@ 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);
|
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta);
|
||||||
|
void *update_position_thread(PositionThreadArgs *args);
|
||||||
void render_entities(const u8 *tags, const Rect *rects, u64 count);
|
void render_entities(const u8 *tags, const Rect *rects, u64 count);
|
||||||
u64 collides(const Rect *rect, const Rect *collider);
|
u8 collides(const Rect *rect, const Rect *collider);
|
||||||
f32 get_random_float(XOR256State *state);
|
i16 get_random_velocity(XOR256State *state);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
i32 target_fps = 120;
|
||||||
|
|
||||||
SetTraceLogLevel(LOG_NONE);
|
SetTraceLogLevel(LOG_NONE);
|
||||||
InitWindow(WIDTH, HEIGHT, "DOD test");
|
InitWindow(WIDTH, HEIGHT, "DOD test");
|
||||||
// SetTargetFPS(120);
|
SetTargetFPS(target_fps);
|
||||||
|
|
||||||
Allocator arena = wapp_mem_arena_allocator_init(MB(20));
|
Allocator arena = wapp_mem_arena_allocator_init(MB(20));
|
||||||
assert(!wapp_mem_allocator_invalid(&arena));
|
assert(!wapp_mem_allocator_invalid(&arena));
|
||||||
@@ -98,19 +116,25 @@ int main(void) {
|
|||||||
velocity_initialisers[is_zone](&(manager.velocities[i]), &state);
|
velocity_initialisers[is_zone](&(manager.velocities[i]), &state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f32 last_time = GetFrameTime();
|
||||||
|
f32 delta, cur_time;
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
f64 time = GetTime();
|
f64 time = GetTime();
|
||||||
if (time >= 20.0) {
|
if (time >= 20.0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
update_positions(manager.tags, manager.rects, manager.velocities, manager.count);
|
cur_time = GetFrameTime();
|
||||||
|
delta = cur_time - last_time;
|
||||||
|
|
||||||
|
update_positions(manager.tags, manager.rects, manager.velocities, manager.count, delta);
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(BG_COLOR);
|
ClearBackground(BG_COLOR);
|
||||||
|
|
||||||
// render_entities(manager.tags, manager.rects, manager.count);
|
render_entities(manager.tags, manager.rects, manager.count);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
@@ -128,6 +152,8 @@ void init_manager(const Allocator *allocator, Manager *manager) {
|
|||||||
assert(allocator != NULL && manager != NULL);
|
assert(allocator != NULL && manager != NULL);
|
||||||
|
|
||||||
u64 total_count = (u64)WANDERER_COUNT + (u64)ZONE_COUNT;
|
u64 total_count = (u64)WANDERER_COUNT + (u64)ZONE_COUNT;
|
||||||
|
assert(total_count < (1lu << 32)); // Ensure we're not exceeding the maximum limit of entities
|
||||||
|
|
||||||
u64 entities_size = sizeof(Entity) * total_count;
|
u64 entities_size = sizeof(Entity) * total_count;
|
||||||
u64 rects_size = sizeof(Rect) * total_count;
|
u64 rects_size = sizeof(Rect) * total_count;
|
||||||
u64 velocities_size = sizeof(Velocity) * total_count;
|
u64 velocities_size = sizeof(Velocity) * total_count;
|
||||||
@@ -147,24 +173,24 @@ void init_manager(const Allocator *allocator, Manager *manager) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init_position(Position *position, XOR256State *state) {
|
void init_position(Position *position, XOR256State *state) {
|
||||||
position->x = wapp_prng_xorshift_256(state) % WIDTH;
|
position->x = wapp_prng_xorshift_256ss(state) % WIDTH;
|
||||||
position->y = wapp_prng_xorshift_256(state) % HEIGHT;
|
position->y = wapp_prng_xorshift_256ss(state) % HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_scale_wanderer(Scale *scale, XOR256State *state) {
|
void init_scale_wanderer(Scale *scale, XOR256State *state) {
|
||||||
f32 value = (f32)((wapp_prng_xorshift_256(state) % (MAX_WANDERER_DIM + 1 - MIN_WANDERER_DIM)) + MIN_WANDERER_DIM);
|
i16 value = (i16)((wapp_prng_xorshift_256p(state) % (MAX_WANDERER_DIM + 1 - MIN_WANDERER_DIM)) + MIN_WANDERER_DIM);
|
||||||
scale->width = value;
|
scale->width = value;
|
||||||
scale->height = value;
|
scale->height = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_scale_zone(Scale *scale, XOR256State *state) {
|
void init_scale_zone(Scale *scale, XOR256State *state) {
|
||||||
scale->width = wapp_prng_xorshift_256(state) % ((u64)HALF_WIDTH - MIN_ZONE_DIM) + MIN_ZONE_DIM;
|
scale->width = wapp_prng_xorshift_256p(state) % ((u64)HALF_WIDTH - MIN_ZONE_DIM) + MIN_ZONE_DIM;
|
||||||
scale->height = wapp_prng_xorshift_256(state) % ((u64)HALF_HEIGHT - MIN_ZONE_DIM) + MIN_ZONE_DIM;
|
scale->height = wapp_prng_xorshift_256p(state) % ((u64)HALF_HEIGHT - MIN_ZONE_DIM) + MIN_ZONE_DIM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_velocity(Velocity *velocity, XOR256State *state) {
|
void init_velocity(Velocity *velocity, XOR256State *state) {
|
||||||
velocity->x = get_random_float(state);
|
velocity->x = get_random_velocity(state);
|
||||||
velocity->y = get_random_float(state);
|
velocity->y = get_random_velocity(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void zero_velocity(Velocity *velocity, XOR256State *state) {
|
void zero_velocity(Velocity *velocity, XOR256State *state) {
|
||||||
@@ -172,35 +198,83 @@ 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) {
|
void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count, f32 delta) {
|
||||||
u8 index = 0;
|
persistent pthread_t threads[THREAD_COUNT] = {0};
|
||||||
f32 multipliers[2] = {1.0f, 0.5f};
|
persistent PositionThreadArgs args[THREAD_COUNT] = {0};
|
||||||
|
|
||||||
|
u64 total_entities_count = count - ZONE_COUNT;
|
||||||
|
u64 thread_entities_count = (u64)(ceil((f64)total_entities_count / THREAD_COUNT));
|
||||||
|
|
||||||
|
i32 result;
|
||||||
|
u64 start = ZONE_COUNT;
|
||||||
|
u64 end, args_count;
|
||||||
|
|
||||||
|
for (u64 i = 0; i < THREAD_COUNT; ++i) {
|
||||||
|
if (total_entities_count > thread_entities_count) {
|
||||||
|
end = start + thread_entities_count;
|
||||||
|
total_entities_count -= thread_entities_count;
|
||||||
|
} else {
|
||||||
|
end = start + total_entities_count;
|
||||||
|
total_entities_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
args_count = end - start;
|
||||||
|
|
||||||
|
args[i].zones = &(rects[0]);
|
||||||
|
args[i].tags = &(tags[start]);
|
||||||
|
args[i].rects = &(rects[start]);
|
||||||
|
args[i].velocities = &(velocities[start]);
|
||||||
|
args[i].count = args_count;
|
||||||
|
args[i].delta = delta;
|
||||||
|
|
||||||
|
start += args_count;
|
||||||
|
|
||||||
|
result = pthread_create(&(threads[i]), NULL, (PThreadRoutine)update_position_thread, (void *)&(args[i]));
|
||||||
|
assert(result == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (u64 i = 0; i < THREAD_COUNT; ++i) {
|
||||||
|
pthread_join(threads[i], NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *update_position_thread(PositionThreadArgs *args) {
|
||||||
|
persistent f32 multipliers[2] = {1.0f, 0.5f};
|
||||||
persistent u64 inside_zone_mask = 0x7;
|
persistent u64 inside_zone_mask = 0x7;
|
||||||
|
|
||||||
for (u64 i = ZONE_COUNT; i < count; ++i) {
|
u8 index = 0;
|
||||||
tags[i] &= inside_zone_mask;
|
f32 pos_x, pos_y;
|
||||||
|
f32 max_x, max_y;
|
||||||
|
|
||||||
|
for (u64 i = 0; i < args->count; ++i) {
|
||||||
|
args->tags[i] &= inside_zone_mask;
|
||||||
for (u64 j = 0; j < ZONE_COUNT; ++j) {
|
for (u64 j = 0; j < ZONE_COUNT; ++j) {
|
||||||
tags[i] |= collides(&rects[i], &rects[j]) << INSIDE_ZONE_TAG_SHIFT;
|
args->tags[i] |= collides(&args->rects[i], &args->zones[j]) << INSIDE_ZONE_TAG_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = (tags[i] & ENTITY_TAG_INSIDE_ZONE) >> INSIDE_ZONE_TAG_SHIFT;
|
index = (args->tags[i] & ENTITY_TAG_INSIDE_ZONE) >> INSIDE_ZONE_TAG_SHIFT;
|
||||||
|
|
||||||
rects[i].position.x += velocities[i].x * multipliers[index];
|
max_x = WIDTH - args->rects[i].scale.width;
|
||||||
rects[i].position.y += velocities[i].y * multipliers[index];
|
max_y = HEIGHT - args->rects[i].scale.height;
|
||||||
|
|
||||||
f32 max_x = WIDTH - rects[i].scale.width;
|
pos_x = args->rects[i].position.x + args->velocities[i].x * multipliers[index] * args->delta;
|
||||||
f32 max_y = HEIGHT - rects[i].scale.height;
|
pos_y = args->rects[i].position.y + args->velocities[i].y * multipliers[index] * args->delta;
|
||||||
|
|
||||||
if (rects[i].position.x < 0 || rects[i].position.x >= max_x) {
|
if (pos_x < 0 || pos_x >= max_x) {
|
||||||
rects[i].position.x = min(max(rects[i].position.x, 0), max_x);
|
pos_x = min(max(pos_x, 0), max_x);
|
||||||
velocities[i].x *= -1;
|
args->velocities[i].x *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rects[i].position.y < 0 || rects[i].position.y >= max_y) {
|
if (pos_y < 0 || pos_y >= max_y) {
|
||||||
rects[i].position.y = min(max(rects[i].position.y, 0), max_y);
|
pos_y = min(max(pos_y, 0), max_y);
|
||||||
velocities[i].y *= -1;
|
args->velocities[i].y *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args->rects[i].position.x = roundf(pos_x);
|
||||||
|
args->rects[i].position.y = roundf(pos_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_entities(const u8 *tags, const Rect *rects, u64 count) {
|
void render_entities(const u8 *tags, const Rect *rects, u64 count) {
|
||||||
@@ -221,22 +295,21 @@ void render_entities(const u8 *tags, const Rect *rects, u64 count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 collides(const Rect *rect, const Rect *collider) {
|
u8 collides(const Rect *rect, const Rect *collider) {
|
||||||
f32 rect_min_x = rect->position.x + rect->scale.width;
|
i16 rect_min_x = rect->position.x + rect->scale.width;
|
||||||
f32 rect_min_y = rect->position.y + rect->scale.height;
|
i16 rect_min_y = rect->position.y + rect->scale.height;
|
||||||
f32 rect_max_x = rect->position.x;
|
i16 rect_max_x = rect->position.x;
|
||||||
f32 rect_max_y = rect->position.y;
|
i16 rect_max_y = rect->position.y;
|
||||||
|
|
||||||
f32 zone_x0 = collider->position.x;
|
i16 zone_x0 = collider->position.x;
|
||||||
f32 zone_y0 = collider->position.y;
|
i16 zone_y0 = collider->position.y;
|
||||||
f32 zone_x1 = collider->position.x + collider->scale.width;
|
i16 zone_x1 = collider->position.x + collider->scale.width;
|
||||||
f32 zone_y1 = collider->position.y + collider->scale.height;
|
i16 zone_y1 = collider->position.y + collider->scale.height;
|
||||||
|
|
||||||
return (u64)(rect_min_x > zone_x0 && rect_min_y > zone_y0 &&
|
return (u8)(rect_min_x > zone_x0 && rect_min_y > zone_y0 &&
|
||||||
rect_max_x < zone_x1 && rect_max_y < zone_y1);
|
rect_max_x < zone_x1 && rect_max_y < zone_y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 get_random_float(XOR256State *state) {
|
i16 get_random_velocity(XOR256State *state) {
|
||||||
i64 random = (i64)wapp_prng_xorshift_256(state) - INT64_MAX;
|
return (wapp_prng_xorshift_256(state) % (MAX_ABS_VELOCITY + 1 - MIN_ABS_VELOCITY)) + MIN_ABS_VELOCITY;
|
||||||
return (f32)(random) / (f32)(INT64_MAX);
|
|
||||||
}
|
}
|
||||||
|
|||||||
16
no_dod.c
16
no_dod.c
@@ -50,7 +50,7 @@ f32 get_random_float(XOR256State *state);
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
SetTraceLogLevel(LOG_NONE);
|
SetTraceLogLevel(LOG_NONE);
|
||||||
InitWindow(WIDTH, HEIGHT, "No-DOD test");
|
InitWindow(WIDTH, HEIGHT, "No-DOD test");
|
||||||
// SetTargetFPS(120);
|
SetTargetFPS(120);
|
||||||
|
|
||||||
Allocator arena = wapp_mem_arena_allocator_init(MB(20));
|
Allocator arena = wapp_mem_arena_allocator_init(MB(20));
|
||||||
XOR256State state = wapp_prng_xorshift_init_state();
|
XOR256State state = wapp_prng_xorshift_init_state();
|
||||||
@@ -84,13 +84,13 @@ int main(void) {
|
|||||||
|
|
||||||
ClearBackground(BG_COLOR);
|
ClearBackground(BG_COLOR);
|
||||||
|
|
||||||
// for (u64 i = 0; i < ZONE_COUNT; ++i) {
|
for (u64 i = 0; i < ZONE_COUNT; ++i) {
|
||||||
// render_slow_zone(&(zones[i]));
|
render_slow_zone(&(zones[i]));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for (u64 i = 0; i < WANDERER_COUNT; ++i) {
|
for (u64 i = 0; i < WANDERER_COUNT; ++i) {
|
||||||
// render_wanderer(&(wanderers[i]));
|
render_wanderer(&(wanderers[i]));
|
||||||
// }
|
}
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user