diff options
Diffstat (limited to 'libphysics/test')
| -rw-r--r-- | libphysics/test/Makefile | 26 | ||||
| -rw-r--r-- | libphysics/test/aabbcheck.c | 115 | ||||
| -rw-r--r-- | libphysics/test/perf.c | 35 | ||||
| -rw-r--r-- | libphysics/test/vis.c | 135 |
4 files changed, 0 insertions, 311 deletions
diff --git a/libphysics/test/Makefile b/libphysics/test/Makefile deleted file mode 100644 index 7826f84..0000000 --- a/libphysics/test/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -CFLAGS=-I../../include -g -O3 -flto -LDFLAGS=-L../ -lphysics `pkg-config --libs sdl3` -lm -flto -O3 - -all: vis perf aabbcheck - -clean: - rm -f vis - rm -f vis.o - -vis: ../libphysics.a vis.o - $(CC) $^ $(LDFLAGS) -o $@ - -perf: ../libphysics.a perf.o - $(CC) $^ $(LDFLAGS) -o $@ - -aabbcheck: ../libphysics.a aabbcheck.o - $(CC) $^ $(LDFLAGS) -o $@ - - -%.o: %.c - $(CC) $< $(CFLAGS) -c -o $@ - -../libphysics.a: - $(MAKE) -C .. all - -.PHONY: all clean ../libphysics.a diff --git a/libphysics/test/aabbcheck.c b/libphysics/test/aabbcheck.c deleted file mode 100644 index 788035b..0000000 --- a/libphysics/test/aabbcheck.c +++ /dev/null @@ -1,115 +0,0 @@ -#include <stdio.h> -#include <stdbool.h> -#include <SDL3/SDL.h> - -#include <vecmath.h> -#include <physics.h> -#include "../dat.h" - -static void process_events(); - -static SDL_Window *window; -static SDL_Renderer *renderer; -static bool running; -static Uint64 old_ticks, new_ticks; - -static void renderbody(Body *); - -static Body mousebody = { - .size = { 25, 25 }, -}; - -static Body body = { - .pos = { 400, 300 }, - .size = { 200, 200 } -}; - -int -main() -{ - if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { - fprintf(stderr, "SDL_Init(): %s\n", SDL_GetError()); - return 1; - } - - if(!SDL_CreateWindowAndRenderer("window", 800, 600, SDL_WINDOW_OPENGL, &window, &renderer)) { - fprintf(stderr, "SDL_CreateWindowAndRenderer: %s\n", SDL_GetError()); - return -1; - } - - running = true; - old_ticks = SDL_GetTicksNS(); - while(running) { - double delta; - process_events(); - - new_ticks = SDL_GetTicksNS(); - delta = (new_ticks - old_ticks) / 1000000000.0; - old_ticks = new_ticks; - - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00); - SDL_RenderClear(renderer); - if(phxaabbcheck(&body, &mousebody)) { - SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0x00); - } else { - SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0x00); - } - - renderbody(&body); - renderbody(&mousebody); - - if(phxaabbcheck(&body, &mousebody)) { - float n[2], p[2]; - - phxaabbresolv(&body, &mousebody, p, n); - SDL_RenderLine(renderer, - body.pos[0], - body.pos[1], - body.pos[0] + n[0] * body.size[0], - body.pos[1] + n[1] * body.size[1] - ); - - SDL_RenderLine(renderer, - mousebody.pos[0] - n[0] * mousebody.size[0], - mousebody.pos[1] - n[1] * mousebody.size[1], - mousebody.pos[0] - n[0] * mousebody.size[0] + p[0], - mousebody.pos[1] - n[1] * mousebody.size[1] + p[1] - ); - } - - SDL_RenderPresent(renderer); - } - - SDL_DestroyWindow(window); - SDL_Quit(); - return 0; -} - -void -process_events() -{ - SDL_Event event; - - while(SDL_PollEvent(&event)) { - switch(event.type) { - case SDL_EVENT_QUIT: - running = false; - break; - case SDL_EVENT_MOUSE_MOTION: - mousebody.pos[0] = event.motion.x; - mousebody.pos[1] = event.motion.y; - } - } -} - -void -renderbody(Body *b) -{ - SDL_RenderRect(renderer, &(SDL_FRect){ - .x = b->pos[0] - b->size[0], - .y = b->pos[1] - b->size[1], - .w = b->size[0] * 2.0, - .h = b->size[1] * 2.0 - }); -} - diff --git a/libphysics/test/perf.c b/libphysics/test/perf.c deleted file mode 100644 index 7e2dd51..0000000 --- a/libphysics/test/perf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <physics.h> -#include <assert.h> - -#define SBODY 8192 -#define FLOAT_RAND (2 * (rand() / (float)RAND_MAX) - 1) - -int -main() -{ - for(int i = 0; i < SBODY; i++) { - BodyID b = phxnew(BTYPE_AABB); - assert(b != -1); - - phxsetpos(b, rand() % 800, rand() % 600); - phxsetsize(b, 5.0, 5.0); - phxapplyaccel(b, (float[]){ 50000 * FLOAT_RAND, 50000 * FLOAT_RAND }); - } - - phxsetmap(8, 8, (int[]) { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 1, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 0, 1, 0, 0, 0, 1, 0, - }); - - phxtick(10.0); - - return 0; -} diff --git a/libphysics/test/vis.c b/libphysics/test/vis.c deleted file mode 100644 index 63e2b9d..0000000 --- a/libphysics/test/vis.c +++ /dev/null @@ -1,135 +0,0 @@ -#include <SDL3/SDL.h> -#include <vecmath.h> -#include <physics.h> - -#include <stdlib.h> -#include <assert.h> - -#include "../dat.h" - -#define SBODY 4096 - -static void process_events(void); -static void render(void); - -static SDL_Window *window; -static SDL_Renderer *renderer; -static bool running; -static Uint64 old_ticks, new_ticks; - -void -renderrect(vec2 p, vec2 s) -{ - SDL_RenderRect(renderer, &(SDL_FRect){ - .x = p[0] - s[0], - .y = p[1] - s[1], - .w = s[0] * 2.0, - .h = s[1] * 2.0 - }); -} - -int -main() -{ - if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { - fprintf(stderr, "SDL_Init(): %s\n", SDL_GetError()); - return 1; - } - - if(!SDL_CreateWindowAndRenderer("window", 800, 600, SDL_WINDOW_OPENGL, &window, &renderer)) { - fprintf(stderr, "SDL_CreateWindowAndRenderer: %s\n", SDL_GetError()); - return -1; - } - SDL_SetRenderVSync(renderer, 1); - - #define FLOAT_RAND (2 * (rand() / (float)RAND_MAX) - 1) - - for(int i = 0; i < SBODY; i++) { - BodyID b = phxnew(BTYPE_AABB); - assert(b != -1); - - phxsetpos(b, rand() % 800, rand() % 600); - phxsetsize(b, 5.0, 5.0); - phxapplyaccel(b, (float[]){ (150 / PHX_TICK_TIME) * FLOAT_RAND, (150 / PHX_TICK_TIME) * FLOAT_RAND }); - } - - phxsetmap(8, 8, (int[]) { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 0, 1, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 1, 1, 0, 0, 1, 1, 0, - 0, 0, 1, 0, 0, 0, 1, 0, - }); - - running = 1; - old_ticks = SDL_GetTicksNS(); - while(running) { - CollisionEvent event; - double delta; - process_events(); - - new_ticks = SDL_GetTicksNS(); - delta = (new_ticks - old_ticks) / 1000000000.0; - old_ticks = new_ticks; - - static float accum = 0; - - accum += delta; - while(accum >= PHX_TICK_TIME) { - phxfixtick(); - while(phxnextcollevent(&event)) { - printf("Collision with %d and %d\n", event.body1, event.body2); - } - accum -= PHX_TICK_TIME; - } - - render(); - } - - SDL_DestroyWindow(window); - SDL_Quit(); - return 0; -} - -void -process_events() -{ - SDL_Event event; - - while(SDL_PollEvent(&event)) { - switch(event.type) { - case SDL_EVENT_QUIT: - running = false; - break; - } - } -} - -void -render(void) -{ - SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(renderer); - - SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0xFF, 0xFF); - for(int y = 0; y < phxmapheight; y++) - for(int x = 0; x < phxmapwidth; x++) { - if(!phxmapbuffer[x + y * phxmapwidth]) - continue; - - renderrect((vec2){ x * 32, y * 32 }, (vec2){ 16, 16 }); - } - - SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF); - for(int i = 0; i < phxbodypoolsize; i++) { - vec2 p, s; - Body *b = phxbodypool + i; - if(!b->active) - continue; - renderrect(b->pos, b->size); - } - SDL_RenderPresent(renderer); -} |
