summaryrefslogtreecommitdiff
path: root/libphysics/test/vis.c
diff options
context:
space:
mode:
Diffstat (limited to 'libphysics/test/vis.c')
-rw-r--r--libphysics/test/vis.c135
1 files changed, 0 insertions, 135 deletions
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);
-}