parent
5d464bc922
commit
ba0cf822f3
14
pl_ds.h
14
pl_ds.h
@ -3,7 +3,7 @@
|
||||
* data structures
|
||||
*/
|
||||
|
||||
// library version
|
||||
// library version (format XYYZZ)
|
||||
#define PL_DS_VERSION "1.0.0"
|
||||
#define PL_DS_VERSION_NUM 10000
|
||||
|
||||
@ -125,16 +125,16 @@ HASHMAPS
|
||||
uint64_t pl_hm_hash(const void* pData, size_t szDataSize, uint64_t uSeed);
|
||||
Returns the CRC64 hash of some arbitrary data.
|
||||
|
||||
pl__hm_resize:
|
||||
void pl__hm_resize(plHashMap*, uint32_t);
|
||||
pl_hm_resize:
|
||||
void pl_hm_resize(plHashMap*, uint32_t);
|
||||
Resizes the hashmap or frees it if zero is used.
|
||||
|
||||
pl_hm_free:
|
||||
void pl_hm_free(plHashMap*);
|
||||
Frees the hashmap internal memory.
|
||||
|
||||
pl__hm_insert:
|
||||
void pl__hm_insert(plHashMap*, uint64_t ulKey, uint64_t ulValue);
|
||||
pl_hm_insert:
|
||||
void pl_hm_insert(plHashMap*, uint64_t ulKey, uint64_t ulValue);
|
||||
Adds an entry to the hashmap where ulKey is a hashed key (usually a string) and
|
||||
ulValue is the index into the value array.
|
||||
|
||||
@ -158,8 +158,8 @@ HASHMAPS
|
||||
bool pl_hm_has_key(plHashMap*, const char*);
|
||||
Same as pl_hm_has_key but performs the hash for you.
|
||||
|
||||
pl__hm_insert_str:
|
||||
void pl__hm_insert_str(plHashMap*, const char* pcKey, uint64_t ulValue);
|
||||
pl_hm_insert_str:
|
||||
void pl_hm_insert_str(plHashMap*, const char* pcKey, uint64_t ulValue);
|
||||
Same as pl__hm_insert but performs the hash for you.
|
||||
|
||||
pl_hm_lookup_str:
|
||||
|
142
pl_math.h
142
pl_math.h
@ -1,5 +1,6 @@
|
||||
/*
|
||||
pl_math.h, v0.6 (WIP)
|
||||
pl_math.h
|
||||
* simple math library
|
||||
|
||||
Do this:
|
||||
#define PL_MATH_INCLUDE_FUNCTIONS
|
||||
@ -12,9 +13,9 @@
|
||||
#include "pl_math.h"
|
||||
*/
|
||||
|
||||
// library version
|
||||
#define PL_MATH_VERSION "0.7.0"
|
||||
#define PL_MATH_VERSION_NUM 00700
|
||||
// library version (format XYYZZ)
|
||||
#define PL_MATH_VERSION "1.0.0"
|
||||
#define PL_MATH_VERSION_NUM 10000
|
||||
|
||||
/*
|
||||
Index of this file:
|
||||
@ -187,7 +188,11 @@ typedef struct _plAABB
|
||||
#include <math.h>
|
||||
#include <stdbool.h> // bool
|
||||
#include <stdint.h> // uint*_t
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef PL_ASSERT
|
||||
#include <assert.h>
|
||||
#define PL_ASSERT(x) assert((x))
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] helpers
|
||||
@ -239,92 +244,89 @@ static inline float pl_clamp01f(float fValue) { re
|
||||
static inline double pl_clamp01d(double dValue) { return pl_clampd(0.0, dValue, 1.0); }
|
||||
static inline size_t pl_align_up(size_t szValue, size_t szAlign) { return ((szValue + (szAlign - 1)) & ~(szAlign - 1)); }
|
||||
|
||||
#define PL__ALIGN_UP(num, align) (((num) + ((align)-1)) & ~((align)-1))
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] vector ops
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// unary ops
|
||||
static inline float pl_length_sqr_vec2 (plVec2 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y); }
|
||||
static inline float pl_length_sqr_vec3 (plVec3 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y) + pl_squaref(tVec.z); }
|
||||
static inline float pl_length_sqr_vec4 (plVec4 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y) + pl_squaref(tVec.z) + pl_squaref(tVec.w); }
|
||||
static inline float pl_length_vec2 (plVec2 tVec) { return sqrtf(pl_length_sqr_vec2(tVec)); }
|
||||
static inline float pl_length_vec3 (plVec3 tVec) { return sqrtf(pl_length_sqr_vec3(tVec)); }
|
||||
static inline float pl_length_vec4 (plVec4 tVec) { return sqrtf(pl_length_sqr_vec4(tVec)); }
|
||||
static inline plVec2 pl_floor_vec2 (plVec2 tVec) { return pl_create_vec2(floorf(tVec.x), floorf(tVec.y));}
|
||||
static inline plVec3 pl_floor_vec3 (plVec3 tVec) { return pl_create_vec3(floorf(tVec.x), floorf(tVec.y), floorf(tVec.z));}
|
||||
static inline plVec4 pl_floor_vec4 (plVec4 tVec) { return pl_create_vec4(floorf(tVec.x), floorf(tVec.y), floorf(tVec.z), floorf(tVec.w));}
|
||||
static inline float pl_length_sqr_vec2(plVec2 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y); }
|
||||
static inline float pl_length_sqr_vec3(plVec3 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y) + pl_squaref(tVec.z); }
|
||||
static inline float pl_length_sqr_vec4(plVec4 tVec) { return pl_squaref(tVec.x) + pl_squaref(tVec.y) + pl_squaref(tVec.z) + pl_squaref(tVec.w); }
|
||||
static inline float pl_length_vec2 (plVec2 tVec) { return sqrtf(pl_length_sqr_vec2(tVec)); }
|
||||
static inline float pl_length_vec3 (plVec3 tVec) { return sqrtf(pl_length_sqr_vec3(tVec)); }
|
||||
static inline float pl_length_vec4 (plVec4 tVec) { return sqrtf(pl_length_sqr_vec4(tVec)); }
|
||||
static inline plVec2 pl_floor_vec2 (plVec2 tVec) { return pl_create_vec2(floorf(tVec.x), floorf(tVec.y));}
|
||||
static inline plVec3 pl_floor_vec3 (plVec3 tVec) { return pl_create_vec3(floorf(tVec.x), floorf(tVec.y), floorf(tVec.z));}
|
||||
static inline plVec4 pl_floor_vec4 (plVec4 tVec) { return pl_create_vec4(floorf(tVec.x), floorf(tVec.y), floorf(tVec.z), floorf(tVec.w));}
|
||||
|
||||
// binary ops
|
||||
static inline plVec2 pl_lerp_vec2(plVec2 t0, plVec2 t1, float fAmount) { return pl_create_vec2(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount);}
|
||||
static inline plVec3 pl_lerp_vec3(plVec3 t0, plVec3 t1, float fAmount) { return pl_create_vec3(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount, t0.z + (t1.z - t0.z) * fAmount);}
|
||||
static inline plVec4 pl_lerp_vec4(plVec4 t0, plVec4 t1, float fAmount) { return pl_create_vec4(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount, t0.z + (t1.z - t0.z) * fAmount, t0.w + (t1.w - t0.w) * fAmount);}
|
||||
|
||||
static inline plVec2 pl_lerp_vec2 (plVec2 t0, plVec2 t1, float fAmount) { return pl_create_vec2(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount);}
|
||||
static inline plVec3 pl_lerp_vec3 (plVec3 t0, plVec3 t1, float fAmount) { return pl_create_vec3(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount, t0.z + (t1.z - t0.z) * fAmount);}
|
||||
static inline plVec4 pl_lerp_vec4 (plVec4 t0, plVec4 t1, float fAmount) { return pl_create_vec4(t0.x + (t1.x - t0.x) * fAmount, t0.y + (t1.y - t0.y) * fAmount, t0.z + (t1.z - t0.z) * fAmount, t0.w + (t1.w - t0.w) * fAmount);}
|
||||
static inline plVec2 pl_clamp_vec2(plVec2 tMin, plVec2 tValue, plVec2 tMax) { return pl_create_vec2(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y));}
|
||||
static inline plVec3 pl_clamp_vec3(plVec3 tMin, plVec3 tValue, plVec3 tMax) { return pl_create_vec3(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y), pl_clampf(tMax.z, tValue.z, tMax.z));}
|
||||
static inline plVec4 pl_clamp_vec4(plVec4 tMin, plVec4 tValue, plVec4 tMax) { return pl_create_vec4(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y), pl_clampf(tMax.z, tValue.z, tMax.z), pl_clampf(tMax.w, tValue.w, tMax.w));}
|
||||
|
||||
static inline plVec2 pl_min_vec2(plVec2 tValue0, plVec2 tValue1) { return pl_create_vec2(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y));}
|
||||
static inline plVec3 pl_min_vec3(plVec3 tValue0, plVec3 tValue1) { return pl_create_vec3(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y), pl_minf(tValue0.z, tValue1.z));}
|
||||
static inline plVec4 pl_min_vec4(plVec4 tValue0, plVec4 tValue1) { return pl_create_vec4(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y), pl_minf(tValue0.z, tValue1.z), pl_minf(tValue0.w, tValue1.w));}
|
||||
static inline plVec2 pl_max_vec2(plVec2 tValue0, plVec2 tValue1) { return pl_create_vec2(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y));}
|
||||
static inline plVec3 pl_max_vec3(plVec3 tValue0, plVec3 tValue1) { return pl_create_vec3(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y), pl_maxf(tValue0.z, tValue1.z));}
|
||||
static inline plVec4 pl_max_vec4(plVec4 tValue0, plVec4 tValue1) { return pl_create_vec4(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y), pl_maxf(tValue0.z, tValue1.z), pl_maxf(tValue0.w, tValue1.w));}
|
||||
|
||||
static inline plVec2 pl_clamp_vec2 (plVec2 tMin, plVec2 tValue, plVec2 tMax) { return pl_create_vec2(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y));}
|
||||
static inline plVec3 pl_clamp_vec3 (plVec3 tMin, plVec3 tValue, plVec3 tMax) { return pl_create_vec3(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y), pl_clampf(tMax.z, tValue.z, tMax.z));}
|
||||
static inline plVec4 pl_clamp_vec4 (plVec4 tMin, plVec4 tValue, plVec4 tMax) { return pl_create_vec4(pl_clampf(tMin.x, tValue.x, tMax.x), pl_clampf(tMin.y, tValue.y, tMax.y), pl_clampf(tMax.z, tValue.z, tMax.z), pl_clampf(tMax.w, tValue.w, tMax.w));}
|
||||
static inline plVec3 pl_cross_vec3(plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.y * tVec2.z - tVec2.y * tVec1.z, tVec1.z * tVec2.x - tVec2.z * tVec1.x, tVec1.x * tVec2.y - tVec2.x * tVec1.y); }
|
||||
|
||||
static inline plVec2 pl_min_vec2 (plVec2 tValue0, plVec2 tValue1) { return pl_create_vec2(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y));}
|
||||
static inline plVec3 pl_min_vec3 (plVec3 tValue0, plVec3 tValue1) { return pl_create_vec3(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y), pl_minf(tValue0.z, tValue1.z));}
|
||||
static inline plVec4 pl_min_vec4 (plVec4 tValue0, plVec4 tValue1) { return pl_create_vec4(pl_minf(tValue0.x, tValue1.x), pl_minf(tValue0.y, tValue1.y), pl_minf(tValue0.z, tValue1.z), pl_minf(tValue0.w, tValue1.w));}
|
||||
static inline plVec2 pl_max_vec2 (plVec2 tValue0, plVec2 tValue1) { return pl_create_vec2(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y));}
|
||||
static inline plVec3 pl_max_vec3 (plVec3 tValue0, plVec3 tValue1) { return pl_create_vec3(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y), pl_maxf(tValue0.z, tValue1.z));}
|
||||
static inline plVec4 pl_max_vec4 (plVec4 tValue0, plVec4 tValue1) { return pl_create_vec4(pl_maxf(tValue0.x, tValue1.x), pl_maxf(tValue0.y, tValue1.y), pl_maxf(tValue0.z, tValue1.z), pl_maxf(tValue0.w, tValue1.w));}
|
||||
static inline float pl_dot_vec2(plVec2 tVec1, plVec2 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y; }
|
||||
static inline float pl_dot_vec3(plVec3 tVec1, plVec3 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y + tVec1.z * tVec2.z; }
|
||||
static inline float pl_dot_vec4(plVec4 tVec1, plVec4 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y + tVec1.z * tVec2.z + tVec1.w * tVec2.w; }
|
||||
|
||||
static inline float pl_dot_vec2 (plVec2 tVec1, plVec2 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y; }
|
||||
static inline float pl_dot_vec3 (plVec3 tVec1, plVec3 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y + tVec1.z * tVec2.z; }
|
||||
static inline float pl_dot_vec4 (plVec4 tVec1, plVec4 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y + tVec1.z * tVec2.z + tVec1.w * tVec2.w; }
|
||||
static inline plVec3 pl_cross_vec3 (plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.y * tVec2.z - tVec2.y * tVec1.z, tVec1.z * tVec2.x - tVec2.z * tVec1.x, tVec1.x * tVec2.y - tVec2.x * tVec1.y); }
|
||||
static inline plVec2 pl_add_vec2(plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x + tVec2.x, tVec1.y + tVec2.y); }
|
||||
static inline plVec3 pl_add_vec3(plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x + tVec2.x, tVec1.y + tVec2.y, tVec1.z + tVec2.z); }
|
||||
static inline plVec4 pl_add_vec4(plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x + tVec2.x, tVec1.y + tVec2.y, tVec1.z + tVec2.z, tVec1.w + tVec2.w); }
|
||||
|
||||
static inline plVec2 pl_add_vec2 (plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x + tVec2.x, tVec1.y + tVec2.y); }
|
||||
static inline plVec3 pl_add_vec3 (plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x + tVec2.x, tVec1.y + tVec2.y, tVec1.z + tVec2.z); }
|
||||
static inline plVec4 pl_add_vec4 (plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x + tVec2.x, tVec1.y + tVec2.y, tVec1.z + tVec2.z, tVec1.w + tVec2.w); }
|
||||
static inline plVec2 pl_sub_vec2(plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x - tVec2.x, tVec1.y - tVec2.y); }
|
||||
static inline plVec3 pl_sub_vec3(plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x - tVec2.x, tVec1.y - tVec2.y, tVec1.z - tVec2.z); }
|
||||
static inline plVec4 pl_sub_vec4(plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x - tVec2.x, tVec1.y - tVec2.y, tVec1.z - tVec2.z, tVec1.w - tVec2.w) ;}
|
||||
|
||||
static inline plVec2 pl_sub_vec2 (plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x - tVec2.x, tVec1.y - tVec2.y); }
|
||||
static inline plVec3 pl_sub_vec3 (plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x - tVec2.x, tVec1.y - tVec2.y, tVec1.z - tVec2.z); }
|
||||
static inline plVec4 pl_sub_vec4 (plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x - tVec2.x, tVec1.y - tVec2.y, tVec1.z - tVec2.z, tVec1.w - tVec2.w) ;}
|
||||
static inline plVec2 pl_mul_vec2(plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x * tVec2.x, tVec1.y * tVec2.y); }
|
||||
static inline plVec3 pl_mul_vec3(plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x * tVec2.x, tVec1.y * tVec2.y, tVec1.z * tVec2.z); }
|
||||
static inline plVec4 pl_mul_vec4(plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x * tVec2.x, tVec1.y * tVec2.y, tVec1.z * tVec2.z, tVec1.w * tVec2.w); }
|
||||
|
||||
static inline plVec2 pl_mul_vec2 (plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x * tVec2.x, tVec1.y * tVec2.y); }
|
||||
static inline plVec3 pl_mul_vec3 (plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x * tVec2.x, tVec1.y * tVec2.y, tVec1.z * tVec2.z); }
|
||||
static inline plVec4 pl_mul_vec4 (plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x * tVec2.x, tVec1.y * tVec2.y, tVec1.z * tVec2.z, tVec1.w * tVec2.w); }
|
||||
static inline plVec2 pl_div_vec2(plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x / tVec2.x, tVec1.y / tVec2.y); }
|
||||
static inline plVec3 pl_div_vec3(plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x / tVec2.x, tVec1.y / tVec2.y, tVec1.z / tVec2.z); }
|
||||
static inline plVec4 pl_div_vec4(plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x / tVec2.x, tVec1.y / tVec2.y, tVec1.z / tVec2.z, tVec1.w / tVec2.w); }
|
||||
|
||||
static inline plVec2 pl_div_vec2 (plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(tVec1.x / tVec2.x, tVec1.y / tVec2.y); }
|
||||
static inline plVec3 pl_div_vec3 (plVec3 tVec1, plVec3 tVec2) { return pl_create_vec3(tVec1.x / tVec2.x, tVec1.y / tVec2.y, tVec1.z / tVec2.z); }
|
||||
static inline plVec4 pl_div_vec4 (plVec4 tVec1, plVec4 tVec2) { return pl_create_vec4(tVec1.x / tVec2.x, tVec1.y / tVec2.y, tVec1.z / tVec2.z, tVec1.w / tVec2.w); }
|
||||
static inline plVec2 pl_mul_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(fValue * tVec.x, fValue * tVec.y); }
|
||||
static inline plVec3 pl_mul_vec3_scalarf(plVec3 tVec, float fValue) { return pl_create_vec3(fValue * tVec.x, fValue * tVec.y, fValue * tVec.z); }
|
||||
static inline plVec4 pl_mul_vec4_scalarf(plVec4 tVec, float fValue) { return pl_create_vec4(fValue * tVec.x, fValue * tVec.y, fValue * tVec.z, fValue * tVec.w); }
|
||||
|
||||
static inline plVec2 pl_mul_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(fValue * tVec.x, fValue * tVec.y); }
|
||||
static inline plVec3 pl_mul_vec3_scalarf(plVec3 tVec, float fValue) { return pl_create_vec3(fValue * tVec.x, fValue * tVec.y, fValue * tVec.z); }
|
||||
static inline plVec4 pl_mul_vec4_scalarf(plVec4 tVec, float fValue) { return pl_create_vec4(fValue * tVec.x, fValue * tVec.y, fValue * tVec.z, fValue * tVec.w); }
|
||||
static inline plVec2 pl_div_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(tVec.x / fValue, tVec.y / fValue); }
|
||||
static inline plVec3 pl_div_vec3_scalarf(plVec3 tVec, float fValue) { return pl_create_vec3(tVec.x / fValue, tVec.y / fValue, tVec.z / fValue); }
|
||||
static inline plVec4 pl_div_vec4_scalarf(plVec4 tVec, float fValue) { return pl_create_vec4(tVec.x / fValue, tVec.y / fValue, tVec.z / fValue, tVec.w / fValue); }
|
||||
|
||||
static inline plVec2 pl_div_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(tVec.x / fValue, tVec.y / fValue); }
|
||||
static inline plVec3 pl_div_vec3_scalarf(plVec3 tVec, float fValue) { return pl_create_vec3(tVec.x / fValue, tVec.y / fValue, tVec.z / fValue); }
|
||||
static inline plVec4 pl_div_vec4_scalarf(plVec4 tVec, float fValue) { return pl_create_vec4(tVec.x / fValue, tVec.y / fValue, tVec.z / fValue, tVec.w / fValue); }
|
||||
static inline plVec2 pl_div_scalarf_vec2(float fValue, plVec2 tVec) { return pl_create_vec2(fValue / tVec.x, fValue / tVec.y); }
|
||||
static inline plVec3 pl_div_scalarf_vec3(float fValue, plVec3 tVec) { return pl_create_vec3(fValue / tVec.x, fValue / tVec.y, fValue / tVec.z); }
|
||||
static inline plVec4 pl_div_scalarf_vec4(float fValue, plVec4 tVec) { return pl_create_vec4(fValue / tVec.x, fValue / tVec.y, fValue / tVec.z, fValue / tVec.w); }
|
||||
|
||||
static inline plVec2 pl_div_scalarf_vec2(float fValue, plVec2 tVec) { return pl_create_vec2(fValue / tVec.x, fValue / tVec.y); }
|
||||
static inline plVec3 pl_div_scalarf_vec3(float fValue, plVec3 tVec) { return pl_create_vec3(fValue / tVec.x, fValue / tVec.y, fValue / tVec.z); }
|
||||
static inline plVec4 pl_div_scalarf_vec4(float fValue, plVec4 tVec) { return pl_create_vec4(fValue / tVec.x, fValue / tVec.y, fValue / tVec.z, fValue / tVec.w); }
|
||||
|
||||
static inline plVec2 pl_norm_vec2 (plVec2 tVec) { float fLength = pl_length_vec2(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec2_scalarf(tVec, fLength); }
|
||||
static inline plVec3 pl_norm_vec3 (plVec3 tVec) { float fLength = pl_length_vec3(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec3_scalarf(tVec, fLength); }
|
||||
static inline plVec4 pl_norm_vec4 (plVec4 tVec) { float fLength = pl_length_vec4(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec4_scalarf(tVec, fLength); }
|
||||
static inline plVec2 pl_norm_vec2(plVec2 tVec) { float fLength = pl_length_vec2(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec2_scalarf(tVec, fLength); }
|
||||
static inline plVec3 pl_norm_vec3(plVec3 tVec) { float fLength = pl_length_vec3(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec3_scalarf(tVec, fLength); }
|
||||
static inline plVec4 pl_norm_vec4(plVec4 tVec) { float fLength = pl_length_vec4(tVec); if(fLength > 0) fLength = 1.0f / fLength; return pl_mul_vec4_scalarf(tVec, fLength); }
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] matrix ops
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// general ops
|
||||
static inline float pl_mat4_get (const plMat4* ptMat, int iRow, int iCol) { return ptMat->col[iCol].d[iRow];}
|
||||
static inline void pl_mat4_set (plMat4* ptMat, int iRow, int iCol, float fValue) { ptMat->col[iCol].d[iRow] = fValue;}
|
||||
static inline plMat4 pl_identity_mat4 (void) { return pl_create_mat4_diag(1.0f, 1.0f, 1.0f, 1.0f);}
|
||||
static inline plMat4 pl_mat4_transpose (const plMat4* ptMat) { plMat4 tResult = {0}; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) pl_mat4_set(&tResult, i, j, pl_mat4_get(ptMat, j, i)); return tResult;}
|
||||
static inline plMat4 pl_mat4_invert (const plMat4* ptMat);
|
||||
static inline plMat4 pl_mul_scalarf_mat4 (float fLeft, const plMat4* ptRight) { plMat4 tResult = {0}; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) pl_mat4_set(&tResult, i, j, fLeft * pl_mat4_get(ptRight, j, i)); return tResult;}
|
||||
static inline plVec3 pl_mul_mat4_vec3 (const plMat4* ptLeft, plVec3 tRight);
|
||||
static inline plVec4 pl_mul_mat4_vec4 (const plMat4* ptLeft, plVec4 tRight);
|
||||
static inline plMat4 pl_mul_mat4 (const plMat4* ptLeft, const plMat4* ptRight);
|
||||
static inline float pl_mat4_get (const plMat4* ptMat, int iRow, int iCol) { return ptMat->col[iCol].d[iRow];}
|
||||
static inline void pl_mat4_set (plMat4* ptMat, int iRow, int iCol, float fValue) { ptMat->col[iCol].d[iRow] = fValue;}
|
||||
static inline plMat4 pl_identity_mat4 (void) { return pl_create_mat4_diag(1.0f, 1.0f, 1.0f, 1.0f);}
|
||||
static inline plMat4 pl_mat4_transpose (const plMat4* ptMat) { plMat4 tResult = {0}; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) pl_mat4_set(&tResult, i, j, pl_mat4_get(ptMat, j, i)); return tResult;}
|
||||
static inline plMat4 pl_mat4_invert (const plMat4* ptMat);
|
||||
static inline plMat4 pl_mul_scalarf_mat4(float fLeft, const plMat4* ptRight) { plMat4 tResult = {0}; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) pl_mat4_set(&tResult, i, j, fLeft * pl_mat4_get(ptRight, j, i)); return tResult;}
|
||||
static inline plVec3 pl_mul_mat4_vec3 (const plMat4* ptLeft, plVec3 tRight);
|
||||
static inline plVec4 pl_mul_mat4_vec4 (const plMat4* ptLeft, plVec4 tRight);
|
||||
static inline plMat4 pl_mul_mat4 (const plMat4* ptLeft, const plMat4* ptRight);
|
||||
|
||||
// translation, rotation, scaling
|
||||
static inline plMat4 pl_mat4_translate_xyz (float fX, float fY, float fZ) { plMat4 tResult = pl_create_mat4_diag(1.0f, 1.0f, 1.0f, 1.0f); tResult.x14 = fX; tResult.x24 = fY; tResult.x34 = fZ; return tResult;}
|
||||
@ -337,8 +339,8 @@ static inline plMat4 pl_mat4_rotate_quat (plVec4 tQ);
|
||||
static inline plMat4 pl_rotation_translation_scale(plVec4 tQ, plVec3 tV, plVec3 tS);
|
||||
|
||||
// transforms (optimized for orthogonal matrices)
|
||||
static inline plMat4 pl_mat4t_invert (const plMat4* ptMat);
|
||||
static inline plMat4 pl_mul_mat4t (const plMat4* ptLeft, const plMat4* ptRight);
|
||||
static inline plMat4 pl_mat4t_invert(const plMat4* ptMat);
|
||||
static inline plMat4 pl_mul_mat4t (const plMat4* ptLeft, const plMat4* ptRight);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] quaternion ops
|
||||
@ -728,7 +730,7 @@ pl_decompose_matrix(const plMat4* ptM, plVec3* ptS, plVec4* ptQ, plVec3* ptT)
|
||||
}
|
||||
}
|
||||
|
||||
assert(!(ptQ->d[3] < 0.0f));
|
||||
PL_ASSERT(!(ptQ->d[3] < 0.0f));
|
||||
}
|
||||
|
||||
static inline plVec4
|
||||
@ -795,4 +797,4 @@ pl_quat_slerp(plVec4 tQ1, plVec4 tQ2, float fT)
|
||||
return tResult;
|
||||
}
|
||||
|
||||
#endif // PL_MATH_INCLUDE_FUNCTIONS
|
||||
#endif // PL_MATH_INCLUDE_FUNCTIONS
|
@ -107,9 +107,9 @@ void pl_stack_allocator_free_bottom_to_marker(plStackAllocator
|
||||
|
||||
// Notes
|
||||
// - setting pBuffer to NULL, will set pszBufferSize to required buffer size
|
||||
// so you can allocate a properly sized buffer for the szItemCount (then call function again)
|
||||
// so you can allocate a properly sized buffer for the requested szItemCount (then call function again)
|
||||
// - to use a stack allocated buffer, first call the function with szItemCount = 0 & pszBufferSize
|
||||
// set to size of the buffer; the function will return the number of items that can be support;
|
||||
// set to size of the buffer; the function will return the number of items that can be supported;
|
||||
// call function again with this number
|
||||
|
||||
size_t pl_pool_allocator_init (plPoolAllocator*, size_t szItemCount, size_t szItemSize, size_t szItemAlignment, size_t* pszBufferSize, void* pBuffer);
|
||||
|
84
pl_profile.h
84
pl_profile.h
@ -1,5 +1,6 @@
|
||||
/*
|
||||
pl_profile
|
||||
pl_profile.h
|
||||
* simple profiling library
|
||||
Do this:
|
||||
#define PL_PROFILE_IMPLEMENTATION
|
||||
before you include this file in *one* C or C++ file to create the implementation.
|
||||
@ -11,9 +12,9 @@
|
||||
#include "pl_profile.h"
|
||||
*/
|
||||
|
||||
// library version
|
||||
#define PL_PROFILE_VERSION "0.2.0"
|
||||
#define PL_PROFILE_VERSION_NUM 00200
|
||||
// library version (format XYYZZ)
|
||||
#define PL_PROFILE_VERSION "1.0.0"
|
||||
#define PL_PROFILE_VERSION_NUM 10000
|
||||
|
||||
/*
|
||||
Index of this file:
|
||||
@ -76,7 +77,7 @@ SAMPLING
|
||||
RETRIEVING RESULTS
|
||||
|
||||
pl_get_last_frame_samples:
|
||||
plProfileSample* pl_get_last_frame_samples(uint32_t* puSize);
|
||||
plProfileSample* pl_get_last_frame_samples(uint32_t* puSizeOut);
|
||||
Returns samples from last frame. Call after "pl_end_profile_frame".
|
||||
|
||||
|
||||
@ -105,8 +106,8 @@ COMPILE TIME OPTIONS
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// forward declarations
|
||||
typedef struct _plProfileSample plProfileSample;
|
||||
typedef struct _plProfileContext plProfileContext;
|
||||
typedef struct _plProfileSample plProfileSample; // single sample result
|
||||
typedef struct _plProfileContext plProfileContext; // opaque type
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] public api
|
||||
@ -150,7 +151,7 @@ typedef struct _plProfileSample
|
||||
// setup/shutdown
|
||||
plProfileContext* pl__create_profile_context (void);
|
||||
void pl__cleanup_profile_context(void);
|
||||
void pl__set_profile_context (plProfileContext* ptContext);
|
||||
void pl__set_profile_context (plProfileContext*);
|
||||
plProfileContext* pl__get_profile_context (void);
|
||||
|
||||
// frames
|
||||
@ -160,7 +161,7 @@ void pl__end_profile_frame (void);
|
||||
// samples
|
||||
void pl__begin_profile_sample(const char* pcName);
|
||||
void pl__end_profile_sample (void);
|
||||
plProfileSample* pl__get_last_frame_samples(uint32_t* puSize);
|
||||
plProfileSample* pl__get_last_frame_samples(uint32_t* puSizeOut);
|
||||
|
||||
#ifndef PL_PROFILE_ON
|
||||
#define pl_create_profile_context(ptContext) NULL
|
||||
@ -212,8 +213,10 @@ Index of this file:
|
||||
// [SECTION] includes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <stdbool.h> // bool
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <time.h> // clock_gettime_nsec_np
|
||||
@ -225,7 +228,7 @@ Index of this file:
|
||||
// [SECTION] global context
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
plProfileContext* gTPProfileContext = NULL;
|
||||
static plProfileContext* gptProfileContext = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] internal structs
|
||||
@ -286,7 +289,7 @@ pl__get_wall_clock(void)
|
||||
{
|
||||
double dResult = 0;
|
||||
#ifdef _WIN32
|
||||
INT64 slPerfFrequency = *(INT64*)gTPProfileContext->pInternal;
|
||||
INT64 slPerfFrequency = *(INT64*)gptProfileContext->pInternal;
|
||||
INT64 slPerfCounter;
|
||||
QueryPerformanceCounter((LARGE_INTEGER*)&slPerfCounter);
|
||||
dResult = (double)slPerfCounter / (double)slPerfFrequency;
|
||||
@ -296,7 +299,7 @@ pl__get_wall_clock(void)
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
uint64_t nsec_count = ts.tv_nsec + ts.tv_sec * 1e9;
|
||||
dResult = (double)nsec_count / *(double*)gTPProfileContext->pInternal;
|
||||
dResult = (double)nsec_count / *(double*)gptProfileContext->pInternal;
|
||||
#endif
|
||||
return dResult;
|
||||
}
|
||||
@ -311,12 +314,18 @@ pl__create_profile_context(void)
|
||||
// allocate context
|
||||
plProfileContext* ptContext = (plProfileContext*)PL_PROFILE_ALLOC(sizeof(plProfileContext));
|
||||
memset(ptContext, 0, sizeof(plProfileContext));
|
||||
gTPProfileContext = ptContext;
|
||||
gptProfileContext = ptContext;
|
||||
|
||||
// clock setup
|
||||
#ifdef _WIN32
|
||||
static INT64 slPerfFrequency = 0;
|
||||
PL_ASSERT(QueryPerformanceFrequency((LARGE_INTEGER*)&slPerfFrequency));
|
||||
BOOL bResult = QueryPerformanceFrequency((LARGE_INTEGER*)&slPerfFrequency);
|
||||
if(!bResult)
|
||||
{
|
||||
PL_PROFILE_FREE(gptProfileContext);
|
||||
gptProfileContext = NULL;
|
||||
return NULL;
|
||||
}
|
||||
ptContext->pInternal = &slPerfFrequency;
|
||||
#elif defined(__APPLE__)
|
||||
// no setup required
|
||||
@ -324,7 +333,10 @@ pl__create_profile_context(void)
|
||||
static struct timespec ts;
|
||||
if (clock_getres(CLOCK_MONOTONIC, &ts) != 0)
|
||||
{
|
||||
PL_ASSERT(false && "clock_getres() failed");
|
||||
// PL_ASSERT(false && "clock_getres() failed");
|
||||
PL_PROFILE_FREE(gptProfileContext);
|
||||
gptProfileContext = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static double dPerFrequency = 0.0;
|
||||
@ -352,54 +364,52 @@ pl__cleanup_profile_context(void)
|
||||
|
||||
for(uint32_t i = 0; i < 2; i++)
|
||||
{
|
||||
if(gTPProfileContext->atFrames[i].bOverflowInUse)
|
||||
PL_PROFILE_FREE(gTPProfileContext->atFrames[i].ptSamples);
|
||||
if(gptProfileContext->atFrames[i].bOverflowInUse)
|
||||
PL_PROFILE_FREE(gptProfileContext->atFrames[i].ptSamples);
|
||||
|
||||
if(gTPProfileContext->atFrames[i].bSampleStackOverflowInUse)
|
||||
PL_PROFILE_FREE(gTPProfileContext->atFrames[i].puSampleStack);
|
||||
if(gptProfileContext->atFrames[i].bSampleStackOverflowInUse)
|
||||
PL_PROFILE_FREE(gptProfileContext->atFrames[i].puSampleStack);
|
||||
}
|
||||
|
||||
PL_PROFILE_FREE(gTPProfileContext);
|
||||
gTPProfileContext = NULL;
|
||||
PL_PROFILE_FREE(gptProfileContext);
|
||||
gptProfileContext = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
pl__set_profile_context(plProfileContext* ptContext)
|
||||
{
|
||||
PL_ASSERT(ptContext && "profile context is NULL");
|
||||
gTPProfileContext = ptContext;
|
||||
gptProfileContext = ptContext;
|
||||
}
|
||||
|
||||
plProfileContext*
|
||||
pl__get_profile_context(void)
|
||||
{
|
||||
PL_ASSERT(gTPProfileContext && "no global log context set");
|
||||
return gTPProfileContext;
|
||||
return gptProfileContext;
|
||||
}
|
||||
|
||||
void
|
||||
pl__begin_profile_frame(void)
|
||||
{
|
||||
gTPProfileContext->ulFrame++;
|
||||
gTPProfileContext->ptCurrentFrame = &gTPProfileContext->atFrames[gTPProfileContext->ulFrame % 2];
|
||||
gTPProfileContext->ptCurrentFrame->dDuration = 0.0;
|
||||
gTPProfileContext->ptCurrentFrame->dInternalDuration = 0.0;
|
||||
gTPProfileContext->ptCurrentFrame->dStartTime = pl__get_wall_clock();
|
||||
gTPProfileContext->ptCurrentFrame->uTotalSampleSize = 0;
|
||||
gptProfileContext->ulFrame++;
|
||||
gptProfileContext->ptCurrentFrame = &gptProfileContext->atFrames[gptProfileContext->ulFrame % 2];
|
||||
gptProfileContext->ptCurrentFrame->dDuration = 0.0;
|
||||
gptProfileContext->ptCurrentFrame->dInternalDuration = 0.0;
|
||||
gptProfileContext->ptCurrentFrame->dStartTime = pl__get_wall_clock();
|
||||
gptProfileContext->ptCurrentFrame->uTotalSampleSize = 0;
|
||||
}
|
||||
|
||||
void
|
||||
pl__end_profile_frame(void)
|
||||
{
|
||||
gTPProfileContext->ptCurrentFrame->dDuration = pl__get_wall_clock() - gTPProfileContext->ptCurrentFrame->dStartTime;
|
||||
gTPProfileContext->ptLastFrame = gTPProfileContext->ptCurrentFrame;
|
||||
gptProfileContext->ptCurrentFrame->dDuration = pl__get_wall_clock() - gptProfileContext->ptCurrentFrame->dStartTime;
|
||||
gptProfileContext->ptLastFrame = gptProfileContext->ptCurrentFrame;
|
||||
}
|
||||
|
||||
void
|
||||
pl__begin_profile_sample(const char* pcName)
|
||||
{
|
||||
const double dCurrentInternalTime = pl__get_wall_clock();
|
||||
plProfileFrame* ptCurrentFrame = gTPProfileContext->ptCurrentFrame;
|
||||
plProfileFrame* ptCurrentFrame = gptProfileContext->ptCurrentFrame;
|
||||
|
||||
uint32_t uSampleIndex = ptCurrentFrame->uTotalSampleSize;
|
||||
plProfileSample* ptSample = pl__get_sample(ptCurrentFrame);
|
||||
@ -417,7 +427,7 @@ void
|
||||
pl__end_profile_sample(void)
|
||||
{
|
||||
const double dCurrentInternalTime = pl__get_wall_clock();
|
||||
plProfileFrame* ptCurrentFrame = gTPProfileContext->ptCurrentFrame;
|
||||
plProfileFrame* ptCurrentFrame = gptProfileContext->ptCurrentFrame;
|
||||
plProfileSample* ptLastSample = &ptCurrentFrame->ptSamples[pl__pop_sample_stack(ptCurrentFrame)];
|
||||
PL_ASSERT(ptLastSample && "Begin/end profile sample mismatch");
|
||||
ptLastSample->dDuration = pl__get_wall_clock() - ptLastSample->dStartTime;
|
||||
@ -428,7 +438,7 @@ pl__end_profile_sample(void)
|
||||
plProfileSample*
|
||||
pl__get_last_frame_samples(uint32_t* puSize)
|
||||
{
|
||||
plProfileFrame* ptFrame = gTPProfileContext->ptLastFrame;
|
||||
plProfileFrame* ptFrame = gptProfileContext->ptLastFrame;
|
||||
|
||||
if(puSize)
|
||||
*puSize = ptFrame->uTotalSampleSize;
|
||||
|
10
pl_stl.h
10
pl_stl.h
@ -2,6 +2,16 @@
|
||||
pl_stl.h
|
||||
* no dependencies
|
||||
* simple asci & binary stl parser
|
||||
|
||||
Do this:
|
||||
#define PL_STL_IMPLEMENTATION
|
||||
before you include this file in *one* C or C++ file to create the implementation.
|
||||
// i.e. it should look like this:
|
||||
#include ...
|
||||
#include ...
|
||||
#include ...
|
||||
#define PL_STL_IMPLEMENTATION
|
||||
#include "pl_stl.h"
|
||||
*/
|
||||
|
||||
// library version (format XYYZZ)
|
||||
|
Loading…
Reference in New Issue
Block a user