xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit ddfe16ce8fbc008780002313177298bd8befcdd7
parent de985dfacdce7d29ee08180d5a015a803e7e6e34
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Fri, 30 Dec 2022 08:37:17 +0900

unite header files

Diffstat:
Mex7/ex7.c | 7++++---
Aex7/ex7.h | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mex7/physics.c | 2+-
Dex7/physics.h | 63---------------------------------------------------------------
Mex7/x.c | 2+-
Dex7/x.h | 18------------------
6 files changed, 93 insertions(+), 86 deletions(-)

diff --git a/ex7/ex7.c b/ex7/ex7.c @@ -4,9 +4,8 @@ #include <unistd.h> #include <string.h> -#include "x.h" +#include "ex7.h" #include "world_map.h" -#include "physics.h" /* macros */ #define FPS (60) @@ -16,7 +15,9 @@ #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) -// #define COUNT_FPS +/* +#define COUNT_FPS +*/ enum keys { KEY_D, diff --git a/ex7/ex7.h b/ex7/ex7.h @@ -0,0 +1,87 @@ +/* + * physics.c + */ +enum object_shape { + SRECTANGLE, + STRIANGLE, + SCIRCLE, +}; + +struct Point { + float x; + float y; +}; + +struct Rectangle { // origin is top left corner + int w, h; +}; + +struct Triangle { + struct Point v2; + struct Point v3; +}; + +struct Circle { // origin is center + float r; +}; + +union Body { + struct Circle circle; + struct Triangle triangle; + struct Rectangle rectangle; +}; + +struct Object { + enum object_shape shape; + struct Point pp; + struct Point p; + struct Point v; + struct Point a; + union Body body; + int m; +}; + +struct rect { + struct Point pp; + struct Point p; + struct Point v; + struct Point a; + int w, h; + int m; +}; + +struct circle { + struct Point pp; + struct Point p; + struct Point v; + struct Point a; + int r; + int m; +}; + +int test_collision(struct Object *, struct Object *); // 1 if collide, 0 if not +void next_tick(struct Object *o, long); +void handle_collision_mf(struct Object *, struct Object *); +int object_is_falling(struct Object *o, struct Object *fb, int num_f); + +/* + * x.c + */ +enum event_type { + XKEYPRESS, + XKEYRELEASE, + XEXPOSE, + XWINDEL, + NOEVENT, +}; + +int x_setup_window(int, int, unsigned int, unsigned int, unsigned long, char *); +void x_clear_area(void); +void x_draw_string(unsigned long color, int x, int y, const char *str, int length); +void x_draw_rectangle(unsigned long color, int x, int y, + unsigned int w, unsigned int h); +void x_flush(void); +void x_clean_up(void); +int x_next_event(char *c); +int x_pending(void); +void x_get_win_wh(int *, int *); diff --git a/ex7/physics.c b/ex7/physics.c @@ -1,6 +1,6 @@ #include <stdio.h> -#include "physics.h" +#include "ex7.h" static int test_collision_rr(struct Object *, struct Object *); static void rect_next_tick(struct Object *, long); diff --git a/ex7/physics.h b/ex7/physics.h @@ -1,63 +0,0 @@ -enum object_shape { - SRECTANGLE, - STRIANGLE, - SCIRCLE, -}; - -struct Point { - float x; - float y; -}; - -struct Rectangle { // origin is top left corner - int w, h; -}; - -struct Triangle { - struct Point v2; - struct Point v3; -}; - -struct Circle { // origin is center - float r; -}; - -union Body { - struct Circle circle; - struct Triangle triangle; - struct Rectangle rectangle; -}; - -struct Object { - enum object_shape shape; - struct Point pp; - struct Point p; - struct Point v; - struct Point a; - union Body body; - int m; -}; - -struct rect { - struct Point pp; - struct Point p; - struct Point v; - struct Point a; - int w, h; - int m; -}; - -struct circle { - struct Point pp; - struct Point p; - struct Point v; - struct Point a; - int r; - int m; -}; - -int test_collision(struct Object *, struct Object *); // 1 if collide, 0 if not -void next_tick(struct Object *o, long); -void handle_collision_mf(struct Object *, struct Object *); -int object_is_falling(struct Object *o, struct Object *fb, int num_f); - diff --git a/ex7/x.c b/ex7/x.c @@ -2,7 +2,7 @@ #include <X11/Xlib.h> -#include "x.h" +#include "ex7.h" Display *display; Atom wm_delete_window; diff --git a/ex7/x.h b/ex7/x.h @@ -1,18 +0,0 @@ -enum event_type { - XKEYPRESS, - XKEYRELEASE, - XEXPOSE, - XWINDEL, - NOEVENT, -}; - -int x_setup_window(int, int, unsigned int, unsigned int, unsigned long, char *); -void x_clear_area(void); -void x_draw_string(unsigned long color, int x, int y, const char *str, int length); -void x_draw_rectangle(unsigned long color, int x, int y, - unsigned int w, unsigned int h); -void x_flush(void); -void x_clean_up(void); -int x_next_event(char *c); -int x_pending(void); -void x_get_win_wh(int *, int *);