parent
5d464bc922
commit
5e30f8bc3a
14
pl_ds.h
14
pl_ds.h
@ -3,7 +3,7 @@
|
|||||||
* data structures
|
* data structures
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// library version
|
// library version (format XYYZZ)
|
||||||
#define PL_DS_VERSION "1.0.0"
|
#define PL_DS_VERSION "1.0.0"
|
||||||
#define PL_DS_VERSION_NUM 10000
|
#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);
|
uint64_t pl_hm_hash(const void* pData, size_t szDataSize, uint64_t uSeed);
|
||||||
Returns the CRC64 hash of some arbitrary data.
|
Returns the CRC64 hash of some arbitrary data.
|
||||||
|
|
||||||
pl__hm_resize:
|
pl_hm_resize:
|
||||||
void pl__hm_resize(plHashMap*, uint32_t);
|
void pl_hm_resize(plHashMap*, uint32_t);
|
||||||
Resizes the hashmap or frees it if zero is used.
|
Resizes the hashmap or frees it if zero is used.
|
||||||
|
|
||||||
pl_hm_free:
|
pl_hm_free:
|
||||||
void pl_hm_free(plHashMap*);
|
void pl_hm_free(plHashMap*);
|
||||||
Frees the hashmap internal memory.
|
Frees the hashmap internal memory.
|
||||||
|
|
||||||
pl__hm_insert:
|
pl_hm_insert:
|
||||||
void pl__hm_insert(plHashMap*, uint64_t ulKey, uint64_t ulValue);
|
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
|
Adds an entry to the hashmap where ulKey is a hashed key (usually a string) and
|
||||||
ulValue is the index into the value array.
|
ulValue is the index into the value array.
|
||||||
|
|
||||||
@ -158,8 +158,8 @@ HASHMAPS
|
|||||||
bool pl_hm_has_key(plHashMap*, const char*);
|
bool pl_hm_has_key(plHashMap*, const char*);
|
||||||
Same as pl_hm_has_key but performs the hash for you.
|
Same as pl_hm_has_key but performs the hash for you.
|
||||||
|
|
||||||
pl__hm_insert_str:
|
pl_hm_insert_str:
|
||||||
void pl__hm_insert_str(plHashMap*, const char* pcKey, uint64_t ulValue);
|
void pl_hm_insert_str(plHashMap*, const char* pcKey, uint64_t ulValue);
|
||||||
Same as pl__hm_insert but performs the hash for you.
|
Same as pl__hm_insert but performs the hash for you.
|
||||||
|
|
||||||
pl_hm_lookup_str:
|
pl_hm_lookup_str:
|
||||||
|
140
pl_math.h
140
pl_math.h
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
pl_math.h, v0.6 (WIP)
|
pl_math.h
|
||||||
|
* simple math library
|
||||||
|
|
||||||
Do this:
|
Do this:
|
||||||
#define PL_MATH_INCLUDE_FUNCTIONS
|
#define PL_MATH_INCLUDE_FUNCTIONS
|
||||||
@ -12,9 +13,9 @@
|
|||||||
#include "pl_math.h"
|
#include "pl_math.h"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// library version
|
// library version (format XYYZZ)
|
||||||
#define PL_MATH_VERSION "0.7.0"
|
#define PL_MATH_VERSION "1.0.0"
|
||||||
#define PL_MATH_VERSION_NUM 00700
|
#define PL_MATH_VERSION_NUM 10000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Index of this file:
|
Index of this file:
|
||||||
@ -187,7 +188,11 @@ typedef struct _plAABB
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdbool.h> // bool
|
#include <stdbool.h> // bool
|
||||||
#include <stdint.h> // uint*_t
|
#include <stdint.h> // uint*_t
|
||||||
#include <assert.h>
|
|
||||||
|
#ifndef PL_ASSERT
|
||||||
|
#include <assert.h>
|
||||||
|
#define PL_ASSERT(x) assert((x))
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] helpers
|
// [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 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)); }
|
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
|
// [SECTION] vector ops
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// unary 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_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_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_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_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_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 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 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 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 plVec4 pl_floor_vec4 (plVec4 tVec) { return pl_create_vec4(floorf(tVec.x), floorf(tVec.y), floorf(tVec.z), floorf(tVec.w));}
|
||||||
|
|
||||||
// binary ops
|
// 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 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_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 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_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 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_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 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 float pl_dot_vec2(plVec2 tVec1, plVec2 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.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 float pl_dot_vec3(plVec3 tVec1, plVec3 tVec2) { return tVec1.x * tVec2.x + tVec1.y * tVec2.y + tVec1.z * tVec2.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 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 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 plVec2 pl_add_vec2(plVec2 tVec1, plVec2 tVec2) { return pl_create_vec2(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 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 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 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 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 plVec2 pl_sub_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 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_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 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 plVec2 pl_mul_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 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_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 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 plVec2 pl_div_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 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_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 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 plVec2 pl_mul_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(fValue * tVec.x, fValue * tVec.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 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_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 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 plVec2 pl_div_vec2_scalarf(plVec2 tVec, float fValue) { return pl_create_vec2(tVec.x / fValue, tVec.y / fValue); }
|
||||||
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 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_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 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 plVec2 pl_div_scalarf_vec2(float fValue, plVec2 tVec) { return pl_create_vec2(fValue / tVec.x, fValue / tVec.y); }
|
||||||
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 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_vec4_scalarf(plVec4 tVec, float fValue) { return pl_create_vec4(tVec.x / fValue, tVec.y / fValue, tVec.z / fValue, tVec.w / fValue); }
|
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 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_div_scalarf_vec3(float fValue, plVec3 tVec) { return pl_create_vec3(fValue / tVec.x, fValue / tVec.y, fValue / tVec.z); }
|
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_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 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
|
// [SECTION] matrix ops
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// general ops
|
// general ops
|
||||||
static inline float pl_mat4_get (const plMat4* ptMat, int iRow, int iCol) { return ptMat->col[iCol].d[iRow];}
|
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 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_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_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_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 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 plVec3 pl_mul_mat4_vec3 (const plMat4* ptLeft, plVec3 tRight);
|
||||||
static inline plVec4 pl_mul_mat4_vec4 (const plMat4* ptLeft, plVec4 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 plMat4 pl_mul_mat4 (const plMat4* ptLeft, const plMat4* ptRight);
|
||||||
|
|
||||||
// translation, rotation, scaling
|
// 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;}
|
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);
|
static inline plMat4 pl_rotation_translation_scale(plVec4 tQ, plVec3 tV, plVec3 tS);
|
||||||
|
|
||||||
// transforms (optimized for orthogonal matrices)
|
// transforms (optimized for orthogonal matrices)
|
||||||
static inline plMat4 pl_mat4t_invert (const plMat4* ptMat);
|
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_mul_mat4t (const plMat4* ptLeft, const plMat4* ptRight);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] quaternion ops
|
// [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
|
static inline plVec4
|
||||||
|
@ -107,9 +107,9 @@ void pl_stack_allocator_free_bottom_to_marker(plStackAllocator
|
|||||||
|
|
||||||
// Notes
|
// Notes
|
||||||
// - setting pBuffer to NULL, will set pszBufferSize to required buffer size
|
// - 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
|
// - 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
|
// 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);
|
size_t pl_pool_allocator_init (plPoolAllocator*, size_t szItemCount, size_t szItemSize, size_t szItemAlignment, size_t* pszBufferSize, void* pBuffer);
|
||||||
|
177
pl_profile.h
177
pl_profile.h
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
pl_profile
|
pl_profile.h
|
||||||
|
* simple profiling library
|
||||||
Do this:
|
Do this:
|
||||||
#define PL_PROFILE_IMPLEMENTATION
|
#define PL_PROFILE_IMPLEMENTATION
|
||||||
before you include this file in *one* C or C++ file to create the implementation.
|
before you include this file in *one* C or C++ file to create the implementation.
|
||||||
@ -11,9 +12,9 @@
|
|||||||
#include "pl_profile.h"
|
#include "pl_profile.h"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// library version
|
// library version (format XYYZZ)
|
||||||
#define PL_PROFILE_VERSION "0.2.0"
|
#define PL_PROFILE_VERSION "1.0.0"
|
||||||
#define PL_PROFILE_VERSION_NUM 00200
|
#define PL_PROFILE_VERSION_NUM 10000
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Index of this file:
|
Index of this file:
|
||||||
@ -76,7 +77,7 @@ SAMPLING
|
|||||||
RETRIEVING RESULTS
|
RETRIEVING RESULTS
|
||||||
|
|
||||||
pl_get_last_frame_samples:
|
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".
|
Returns samples from last frame. Call after "pl_end_profile_frame".
|
||||||
|
|
||||||
|
|
||||||
@ -105,8 +106,9 @@ COMPILE TIME OPTIONS
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
typedef struct _plProfileSample plProfileSample;
|
typedef struct _plProfileSample plProfileSample; // single sample result
|
||||||
typedef struct _plProfileContext plProfileContext;
|
typedef struct _plProfileInit plProfileInit; // profile context init info
|
||||||
|
typedef struct _plProfileContext plProfileContext; // opaque type
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] public api
|
// [SECTION] public api
|
||||||
@ -115,19 +117,19 @@ typedef struct _plProfileContext plProfileContext;
|
|||||||
#ifdef PL_PROFILE_ON
|
#ifdef PL_PROFILE_ON
|
||||||
|
|
||||||
// setup/shutdown
|
// setup/shutdown
|
||||||
#define pl_create_profile_context(ptContext) pl__create_profile_context()
|
#define pl_create_profile_context(tInit) pl__create_profile_context((tInit))
|
||||||
#define pl_cleanup_profile_context() pl__cleanup_profile_context()
|
#define pl_cleanup_profile_context() pl__cleanup_profile_context()
|
||||||
#define pl_set_profile_context(ptContext) pl__set_profile_context((ptContext))
|
#define pl_set_profile_context(ptContext) pl__set_profile_context((ptContext))
|
||||||
#define pl_get_profile_context() pl__get_profile_context()
|
#define pl_get_profile_context() pl__get_profile_context()
|
||||||
|
|
||||||
// frames
|
// frames
|
||||||
#define pl_begin_profile_frame() pl__begin_profile_frame()
|
#define pl_begin_profile_frame() pl__begin_profile_frame()
|
||||||
#define pl_end_profile_frame() pl__end_profile_frame()
|
#define pl_end_profile_frame() pl__end_profile_frame()
|
||||||
|
|
||||||
// samples
|
// samples
|
||||||
#define pl_begin_profile_sample(pcName) pl__begin_profile_sample((pcName))
|
#define pl_begin_profile_sample(uThreadIndex, pcName) pl__begin_profile_sample((uThreadIndex), (pcName))
|
||||||
#define pl_end_profile_sample() pl__end_profile_sample()
|
#define pl_end_profile_sample(uThreadIndex) pl__end_profile_sample((uThreadIndex))
|
||||||
#define pl_get_last_frame_samples(puSize) pl__get_last_frame_samples((puSize))
|
#define pl_get_last_frame_samples(uThreadIndex, puSize) pl__get_last_frame_samples((uThreadIndex), (puSize))
|
||||||
|
|
||||||
#endif // PL_PROFILE_ON
|
#endif // PL_PROFILE_ON
|
||||||
|
|
||||||
@ -143,24 +145,29 @@ typedef struct _plProfileSample
|
|||||||
uint32_t uDepth;
|
uint32_t uDepth;
|
||||||
} plProfileSample;
|
} plProfileSample;
|
||||||
|
|
||||||
|
typedef struct _plProfileInit
|
||||||
|
{
|
||||||
|
uint32_t uThreadCount;
|
||||||
|
} plProfileInit;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] internal api
|
// [SECTION] internal api
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// setup/shutdown
|
// setup/shutdown
|
||||||
plProfileContext* pl__create_profile_context (void);
|
plProfileContext* pl__create_profile_context (plProfileInit);
|
||||||
void pl__cleanup_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);
|
plProfileContext* pl__get_profile_context (void);
|
||||||
|
|
||||||
// frames
|
// frames
|
||||||
void pl__begin_profile_frame(void);
|
void pl__begin_profile_frame(void);
|
||||||
void pl__end_profile_frame (void);
|
void pl__end_profile_frame (void);
|
||||||
|
|
||||||
// samples
|
// samples
|
||||||
void pl__begin_profile_sample(const char* pcName);
|
void pl__begin_profile_sample(uint32_t uThreadIndex, const char* pcName);
|
||||||
void pl__end_profile_sample (void);
|
void pl__end_profile_sample (uint32_t uThreadIndex);
|
||||||
plProfileSample* pl__get_last_frame_samples(uint32_t* puSize);
|
plProfileSample* pl__get_last_frame_samples(uint32_t uThreadIndex, uint32_t* puSizeOut);
|
||||||
|
|
||||||
#ifndef PL_PROFILE_ON
|
#ifndef PL_PROFILE_ON
|
||||||
#define pl_create_profile_context(ptContext) NULL
|
#define pl_create_profile_context(ptContext) NULL
|
||||||
@ -212,8 +219,10 @@ Index of this file:
|
|||||||
// [SECTION] includes
|
// [SECTION] includes
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <stdbool.h> // bool
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
#include <time.h> // clock_gettime_nsec_np
|
#include <time.h> // clock_gettime_nsec_np
|
||||||
@ -225,7 +234,7 @@ Index of this file:
|
|||||||
// [SECTION] global context
|
// [SECTION] global context
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
plProfileContext* gTPProfileContext = NULL;
|
static plProfileContext* gptProfileContext = NULL;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] internal structs
|
// [SECTION] internal structs
|
||||||
@ -257,14 +266,20 @@ typedef struct _plProfileFrame
|
|||||||
uint32_t uOverflowSampleCapacity;
|
uint32_t uOverflowSampleCapacity;
|
||||||
} plProfileFrame;
|
} plProfileFrame;
|
||||||
|
|
||||||
typedef struct _plProfileContext
|
typedef struct _plProfileThreadData
|
||||||
{
|
{
|
||||||
double dStartTime;
|
|
||||||
uint64_t ulFrame;
|
|
||||||
plProfileFrame atFrames[2];
|
plProfileFrame atFrames[2];
|
||||||
plProfileFrame* ptCurrentFrame;
|
plProfileFrame* ptCurrentFrame;
|
||||||
plProfileFrame* ptLastFrame;
|
plProfileFrame* ptLastFrame;
|
||||||
void* pInternal;
|
} plProfileThreadData;
|
||||||
|
|
||||||
|
typedef struct _plProfileContext
|
||||||
|
{
|
||||||
|
double dStartTime;
|
||||||
|
uint64_t ulFrame;
|
||||||
|
plProfileThreadData* ptThreadData;
|
||||||
|
uint32_t uThreadCount;
|
||||||
|
void* pInternal;
|
||||||
} plProfileContext;
|
} plProfileContext;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -286,7 +301,7 @@ pl__get_wall_clock(void)
|
|||||||
{
|
{
|
||||||
double dResult = 0;
|
double dResult = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
INT64 slPerfFrequency = *(INT64*)gTPProfileContext->pInternal;
|
INT64 slPerfFrequency = *(INT64*)gptProfileContext->pInternal;
|
||||||
INT64 slPerfCounter;
|
INT64 slPerfCounter;
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*)&slPerfCounter);
|
QueryPerformanceCounter((LARGE_INTEGER*)&slPerfCounter);
|
||||||
dResult = (double)slPerfCounter / (double)slPerfFrequency;
|
dResult = (double)slPerfCounter / (double)slPerfFrequency;
|
||||||
@ -296,7 +311,7 @@ pl__get_wall_clock(void)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
uint64_t nsec_count = ts.tv_nsec + ts.tv_sec * 1e9;
|
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
|
#endif
|
||||||
return dResult;
|
return dResult;
|
||||||
}
|
}
|
||||||
@ -306,17 +321,23 @@ pl__get_wall_clock(void)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
plProfileContext*
|
plProfileContext*
|
||||||
pl__create_profile_context(void)
|
pl__create_profile_context(plProfileInit tInit)
|
||||||
{
|
{
|
||||||
// allocate context
|
// allocate context
|
||||||
plProfileContext* ptContext = (plProfileContext*)PL_PROFILE_ALLOC(sizeof(plProfileContext));
|
plProfileContext* ptContext = (plProfileContext*)PL_PROFILE_ALLOC(sizeof(plProfileContext));
|
||||||
memset(ptContext, 0, sizeof(plProfileContext));
|
memset(ptContext, 0, sizeof(plProfileContext));
|
||||||
gTPProfileContext = ptContext;
|
gptProfileContext = ptContext;
|
||||||
|
|
||||||
// clock setup
|
// clock setup
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static INT64 slPerfFrequency = 0;
|
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;
|
ptContext->pInternal = &slPerfFrequency;
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
// no setup required
|
// no setup required
|
||||||
@ -324,7 +345,10 @@ pl__create_profile_context(void)
|
|||||||
static struct timespec ts;
|
static struct timespec ts;
|
||||||
if (clock_getres(CLOCK_MONOTONIC, &ts) != 0)
|
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;
|
static double dPerFrequency = 0.0;
|
||||||
@ -333,73 +357,88 @@ pl__create_profile_context(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ptContext->dStartTime = pl__get_wall_clock();
|
ptContext->dStartTime = pl__get_wall_clock();
|
||||||
ptContext->ptCurrentFrame = &ptContext->atFrames[0];
|
ptContext->uThreadCount = tInit.uThreadCount;
|
||||||
ptContext->atFrames[0].uSampleCapacity = 256;
|
ptContext->ptThreadData = (plProfileThreadData*)PL_PROFILE_ALLOC(sizeof(plProfileThreadData) * tInit.uThreadCount);
|
||||||
ptContext->atFrames[0].uSampleStackCapacity = 256;
|
memset(ptContext->ptThreadData, 0, sizeof(plProfileThreadData) * tInit.uThreadCount);
|
||||||
ptContext->atFrames[1].uSampleCapacity = 256;
|
for(uint32_t i = 0; i < tInit.uThreadCount; i++)
|
||||||
ptContext->atFrames[1].uSampleStackCapacity = 256;
|
{
|
||||||
ptContext->atFrames[0].ptSamples = ptContext->atFrames[0].atSamples;
|
ptContext->ptThreadData[i].ptCurrentFrame = &ptContext->ptThreadData[i].atFrames[0];
|
||||||
ptContext->atFrames[1].ptSamples = ptContext->atFrames[1].atSamples;
|
ptContext->ptThreadData[i].atFrames[0].uSampleCapacity = 256;
|
||||||
ptContext->atFrames[0].puSampleStack = ptContext->atFrames[0].auSampleStack;
|
ptContext->ptThreadData[i].atFrames[0].uSampleStackCapacity = 256;
|
||||||
ptContext->atFrames[1].puSampleStack = ptContext->atFrames[1].auSampleStack;
|
ptContext->ptThreadData[i].atFrames[1].uSampleCapacity = 256;
|
||||||
ptContext->ptLastFrame = &ptContext->atFrames[0];
|
ptContext->ptThreadData[i].atFrames[1].uSampleStackCapacity = 256;
|
||||||
|
ptContext->ptThreadData[i].atFrames[0].ptSamples = ptContext->ptThreadData[i].atFrames[0].atSamples;
|
||||||
|
ptContext->ptThreadData[i].atFrames[1].ptSamples = ptContext->ptThreadData[i].atFrames[1].atSamples;
|
||||||
|
ptContext->ptThreadData[i].atFrames[0].puSampleStack = ptContext->ptThreadData[i].atFrames[0].auSampleStack;
|
||||||
|
ptContext->ptThreadData[i].atFrames[1].puSampleStack = ptContext->ptThreadData[i].atFrames[1].auSampleStack;
|
||||||
|
ptContext->ptThreadData[i].ptLastFrame = &ptContext->ptThreadData[i].atFrames[0];
|
||||||
|
}
|
||||||
return ptContext;
|
return ptContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__cleanup_profile_context(void)
|
pl__cleanup_profile_context(void)
|
||||||
{
|
{
|
||||||
|
for(uint32_t i = 0; i < gptProfileContext->uThreadCount; i++)
|
||||||
for(uint32_t i = 0; i < 2; i++)
|
|
||||||
{
|
{
|
||||||
if(gTPProfileContext->atFrames[i].bOverflowInUse)
|
for(uint32_t j = 0; j < 2; j++)
|
||||||
PL_PROFILE_FREE(gTPProfileContext->atFrames[i].ptSamples);
|
{
|
||||||
|
|
||||||
if(gTPProfileContext->atFrames[i].bSampleStackOverflowInUse)
|
if(gptProfileContext->ptThreadData[i].atFrames[j].bOverflowInUse)
|
||||||
PL_PROFILE_FREE(gTPProfileContext->atFrames[i].puSampleStack);
|
PL_PROFILE_FREE(gptProfileContext->ptThreadData[i].atFrames[j].ptSamples);
|
||||||
|
|
||||||
|
if(gptProfileContext->ptThreadData[i].atFrames[j].bSampleStackOverflowInUse)
|
||||||
|
PL_PROFILE_FREE(gptProfileContext->ptThreadData[i].atFrames[j].puSampleStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PL_PROFILE_FREE(gTPProfileContext);
|
PL_PROFILE_FREE(gptProfileContext->ptThreadData);
|
||||||
gTPProfileContext = NULL;
|
PL_PROFILE_FREE(gptProfileContext);
|
||||||
|
gptProfileContext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__set_profile_context(plProfileContext* ptContext)
|
pl__set_profile_context(plProfileContext* ptContext)
|
||||||
{
|
{
|
||||||
PL_ASSERT(ptContext && "profile context is NULL");
|
gptProfileContext = ptContext;
|
||||||
gTPProfileContext = ptContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
plProfileContext*
|
plProfileContext*
|
||||||
pl__get_profile_context(void)
|
pl__get_profile_context(void)
|
||||||
{
|
{
|
||||||
PL_ASSERT(gTPProfileContext && "no global log context set");
|
return gptProfileContext;
|
||||||
return gTPProfileContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__begin_profile_frame(void)
|
pl__begin_profile_frame(void)
|
||||||
{
|
{
|
||||||
gTPProfileContext->ulFrame++;
|
gptProfileContext->ulFrame++;
|
||||||
gTPProfileContext->ptCurrentFrame = &gTPProfileContext->atFrames[gTPProfileContext->ulFrame % 2];
|
|
||||||
gTPProfileContext->ptCurrentFrame->dDuration = 0.0;
|
for(uint32_t i = 0; i < gptProfileContext->uThreadCount; i++)
|
||||||
gTPProfileContext->ptCurrentFrame->dInternalDuration = 0.0;
|
{
|
||||||
gTPProfileContext->ptCurrentFrame->dStartTime = pl__get_wall_clock();
|
gptProfileContext->ptThreadData[i].ptCurrentFrame = &gptProfileContext->ptThreadData[i].atFrames[gptProfileContext->ulFrame % 2];
|
||||||
gTPProfileContext->ptCurrentFrame->uTotalSampleSize = 0;
|
gptProfileContext->ptThreadData[i].ptCurrentFrame->dDuration = 0.0;
|
||||||
|
gptProfileContext->ptThreadData[i].ptCurrentFrame->dInternalDuration = 0.0;
|
||||||
|
gptProfileContext->ptThreadData[i].ptCurrentFrame->dStartTime = pl__get_wall_clock();
|
||||||
|
gptProfileContext->ptThreadData[i].ptCurrentFrame->uTotalSampleSize = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__end_profile_frame(void)
|
pl__end_profile_frame(void)
|
||||||
{
|
{
|
||||||
gTPProfileContext->ptCurrentFrame->dDuration = pl__get_wall_clock() - gTPProfileContext->ptCurrentFrame->dStartTime;
|
for(uint32_t i = 0; i < gptProfileContext->uThreadCount; i++)
|
||||||
gTPProfileContext->ptLastFrame = gTPProfileContext->ptCurrentFrame;
|
{
|
||||||
|
gptProfileContext->ptThreadData[i].ptCurrentFrame->dDuration = pl__get_wall_clock() - gptProfileContext->ptThreadData[i].ptCurrentFrame->dStartTime;
|
||||||
|
gptProfileContext->ptThreadData[i].ptLastFrame = gptProfileContext->ptThreadData[i].ptCurrentFrame;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__begin_profile_sample(const char* pcName)
|
pl__begin_profile_sample(uint32_t uThreadIndex, const char* pcName)
|
||||||
{
|
{
|
||||||
const double dCurrentInternalTime = pl__get_wall_clock();
|
const double dCurrentInternalTime = pl__get_wall_clock();
|
||||||
plProfileFrame* ptCurrentFrame = gTPProfileContext->ptCurrentFrame;
|
plProfileFrame* ptCurrentFrame = gptProfileContext->ptThreadData[uThreadIndex].ptCurrentFrame;
|
||||||
|
|
||||||
uint32_t uSampleIndex = ptCurrentFrame->uTotalSampleSize;
|
uint32_t uSampleIndex = ptCurrentFrame->uTotalSampleSize;
|
||||||
plProfileSample* ptSample = pl__get_sample(ptCurrentFrame);
|
plProfileSample* ptSample = pl__get_sample(ptCurrentFrame);
|
||||||
@ -414,10 +453,10 @@ pl__begin_profile_sample(const char* pcName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pl__end_profile_sample(void)
|
pl__end_profile_sample(uint32_t uThreadIndex)
|
||||||
{
|
{
|
||||||
const double dCurrentInternalTime = pl__get_wall_clock();
|
const double dCurrentInternalTime = pl__get_wall_clock();
|
||||||
plProfileFrame* ptCurrentFrame = gTPProfileContext->ptCurrentFrame;
|
plProfileFrame* ptCurrentFrame = gptProfileContext->ptThreadData[uThreadIndex].ptCurrentFrame;
|
||||||
plProfileSample* ptLastSample = &ptCurrentFrame->ptSamples[pl__pop_sample_stack(ptCurrentFrame)];
|
plProfileSample* ptLastSample = &ptCurrentFrame->ptSamples[pl__pop_sample_stack(ptCurrentFrame)];
|
||||||
PL_ASSERT(ptLastSample && "Begin/end profile sample mismatch");
|
PL_ASSERT(ptLastSample && "Begin/end profile sample mismatch");
|
||||||
ptLastSample->dDuration = pl__get_wall_clock() - ptLastSample->dStartTime;
|
ptLastSample->dDuration = pl__get_wall_clock() - ptLastSample->dStartTime;
|
||||||
@ -426,9 +465,9 @@ pl__end_profile_sample(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
plProfileSample*
|
plProfileSample*
|
||||||
pl__get_last_frame_samples(uint32_t* puSize)
|
pl__get_last_frame_samples(uint32_t uThreadIndex, uint32_t* puSize)
|
||||||
{
|
{
|
||||||
plProfileFrame* ptFrame = gTPProfileContext->ptLastFrame;
|
plProfileFrame* ptFrame = gptProfileContext->ptThreadData[uThreadIndex].ptLastFrame;
|
||||||
|
|
||||||
if(puSize)
|
if(puSize)
|
||||||
*puSize = ptFrame->uTotalSampleSize;
|
*puSize = ptFrame->uTotalSampleSize;
|
||||||
|
10
pl_stl.h
10
pl_stl.h
@ -2,6 +2,16 @@
|
|||||||
pl_stl.h
|
pl_stl.h
|
||||||
* no dependencies
|
* no dependencies
|
||||||
* simple asci & binary stl parser
|
* 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)
|
// library version (format XYYZZ)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
pl_test.h
|
pl_test.h
|
||||||
|
* simple test librsry
|
||||||
|
|
||||||
Do this:
|
Do this:
|
||||||
#define PL_TEST_IMPLEMENTATION
|
#define PL_TEST_IMPLEMENTATION
|
||||||
before you include this file in *one* C or C++ file to create the implementation.
|
before you include this file in *one* C or C++ file to create the implementation.
|
||||||
|
Loading…
Reference in New Issue
Block a user