a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

types.h (1766B)


      1 #pragma once
      2 
      3 #define global_variable static
      4 #define internal static
      5 #define local_persist static
      6 
      7 typedef uint8_t  u8;
      8 typedef uint16_t u16;
      9 typedef uint32_t u32;
     10 typedef uint64_t u64;
     11 typedef int8_t   i8;
     12 typedef int16_t  i16;
     13 typedef int32_t  i32;
     14 typedef int64_t  i64;
     15 typedef float    f32;
     16 typedef double   f64;
     17 
     18 typedef union
     19 {
     20     struct
     21     {
     22         f32 x, y;
     23     };
     24     struct
     25     {
     26         f32 width, height;
     27     };
     28     f32 E[2];
     29 } v2;
     30 
     31 typedef union
     32 {
     33     struct
     34     {
     35         u32 x, y;
     36     };
     37     struct
     38     {
     39         u32 width, height;
     40     };
     41     u32 E[2];
     42 } v2u;
     43 
     44 typedef union
     45 {
     46     struct
     47     {
     48         i32 x, y;
     49     };
     50     struct
     51     {
     52         i32 width, height;
     53     };
     54     i32 E[2];
     55 } v2i;
     56 
     57 typedef union
     58 {
     59     struct
     60     {
     61         f32 x, y, z;
     62     };
     63     struct
     64     {
     65         v2 xy;
     66         f32 ignored_z;
     67     };
     68     struct
     69     {
     70         f32 ignored_x;
     71         v2 yz;
     72     };
     73     f32 E[3];
     74 } v3;
     75 
     76 typedef union
     77 {
     78     struct
     79     {
     80         union
     81         {
     82             v3 xyz;
     83             struct
     84             {
     85                 f32 x, y, z;
     86             };
     87         };
     88         f32 w;
     89     };
     90     struct
     91     {
     92         v2 xy;
     93         f32 ignored_z_xy;
     94         f32 ignored_w_xy;
     95     };
     96     struct
     97     {
     98         f32 ignored_x_yz;
     99         v2 yz;
    100         f32 ignored_w_yz;
    101     };
    102     struct
    103     {
    104         f32 ignored_x_zw;
    105         f32 ignored_y_zw;
    106         v2 zw;
    107     };
    108     f32 E[4];
    109 } v4;
    110 
    111 typedef struct
    112 {
    113     v2 min, max;
    114 } rect;
    115 
    116 typedef struct
    117 {
    118     v2 min, max;
    119 } segment;
    120 
    121 typedef struct
    122 {
    123     // row-major, so you probably want to transpose before passing to opengl,
    124     // which uses column-major matrices
    125     f32 E[4][4]; // E[row][column]
    126 } m4;
    127 
    128 enum VectorAxis
    129 {
    130     AXIS_X = 0,
    131     AXIS_Y = 1,
    132     AXIS_Z = 2,
    133     AXIS_W = 3,
    134     AXIS_MAX = 4,
    135 };