Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\_kit_private.cpp":
- #include "_kit_common.hpp"
- namespace kit {
- #define ERRORS_INVALID (_gl.errors == nullptr || _gl.errors_len == 0)
- #define LAST_INDEX ((_gl.errors_len>0) ? _gl.errors_len-1 : 0)
- //returns newest last index on success, or < 0 on failure of some kind
- static s64 _changeErrorsSize(s32 change){ //(change is in elements, not bytes)
- if(ERRORS_INVALID) return -1;
- if(change == 0 ) return LAST_INDEX;
- if(((s64)_gl.errors_len)+change <= 0) return -1;
- LOCK_GLOBALS();
- s64 last_index = -1;
- u32 _errors_len = _gl.errors_len + change;
- size_t _errors_size = sizeof(Error) * _errors_len;
- if(memory::realloc(&_gl.errors, _errors_size))
- {
- //if errors array grew, zero out any new memory
- //(this loop won't even start if _errors_len <= _gl.errors_len)
- for(u32 i = _gl.errors_len; i<_errors_len; ++i)
- _gl.errors[i]._0 = 0, _gl.errors[i]._1 = 0;
- _gl.errors_len = _errors_len;
- last_index = LAST_INDEX;
- }
- UNLOCK_GLOBALS();
- return last_index;
- }
- static char _errortext_default[] = "(FAILED TO ALLOCATE MEMORY FOR ERROR TEXT)";
- //push heap error
- //(this assumes only one error will exist per thread at any given time!)
- const char* _pushError(const char* errortext){
- if(ERRORS_INVALID ) return "(THREAD ERROR ARRAY IS NULLPTR)";
- if(errortext == nullptr) return "_pushError(): errortext = nullptr";
- LOCK_GLOBALS();
- //attempt to find an empty space inside already existing errors array
- u32 i = 0;
- for(; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._txt == nullptr) break;
- }
- //if no empty space for an error was found,
- //attempt to grow errors by 1 element
- if(i == _gl.errors_len){
- s64 last_index = _changeErrorsSize(1);
- //if errors failed to change size, and/or last index is not empty
- if(last_index < 0 || _gl.errors[last_index]._txt != nullptr)
- i = KIT_U32_MAX; //indicates failure to find any empty space
- }
- char* _errortext = _errortext_default;
- //if valid index was found, copy error text to new string inside errors array
- if(i < KIT_U32_MAX){
- size_t errortext_len = strnLen(errortext);
- char* _errortext_tmp = (char*)memory::alloc(errortext_len+1);
- //(memory::set is unnecessary here, since all bytes are overwritten anyway)
- if(_errortext_tmp != nullptr){
- _errortext = _errortext_tmp;
- //strcpy basically
- for(size_t c=0; c<errortext_len; ++c)
- _errortext[c] = errortext[c];
- _errortext[errortext_len] = 0; //manually add null terminator
- //set members of new error accordingly
- _gl.errors[i]._txt = _errortext;
- _gl.errors[i]._thread_id = SDL_GetThreadID(nullptr); //error belongs to calling thread
- _gl.errors[i]._heap = true;
- }
- }
- UNLOCK_GLOBALS();
- return (const char*)_errortext;
- }
- //returns true if it found an error to free
- bool _freeError(u32 thread_id){
- if(ERRORS_INVALID) return false;
- if(!thread_id) thread_id = SDL_GetThreadID(nullptr); //id of calling thread
- LOCK_GLOBALS();
- bool error_found = false;
- //try to find error based on its thread id
- u32 i = 0;
- for(; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._thread_id == thread_id){
- if(_gl.errors[i]._txt != nullptr && _gl.errors[i]._heap)
- memory::free(&_gl.errors[i]._txt);
- _gl.errors[i]._txt = nullptr;
- _gl.errors[i]._thread_id = 0;
- _gl.errors[i]._heap = false;
- error_found = true;
- break; //thread error found; break loop
- }
- }
- //shrink errors if the last error is now empty
- if(_gl.errors[_gl.errors_len-1]._txt == nullptr)
- _changeErrorsSize(-1);
- UNLOCK_GLOBALS();
- return error_found;
- }
- void _freeErrors(){
- //(ERRORS_INVALID is not used here)
- if(_gl.errors == nullptr) return;
- LOCK_GLOBALS();
- for(u32 i=0; i<_gl.errors_len; ++i){
- if(_gl.errors[i]._txt != nullptr && _gl.errors[i]._heap)
- memory::free(&_gl.errors[i]._txt); //automatically sets _txt to nullptr
- }
- memory::free(&_gl.errors);
- _gl.errors_len = 0;
- UNLOCK_GLOBALS();
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\audio.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_AUDIO_HPP
- #define _INC_AUDIO_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- #include "_audio_func.hpp"
- #include "_audio_AudioDevice.hpp"
- #include "_audio_AudioStream.hpp"
- #include "_audio_AudioData.hpp"
- #endif /* _INC_AUDIO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\commondef.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _COMMONDEF_HPP
- #define _COMMONDEF_HPP
- namespace kit {
- #ifndef MIN
- #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
- #endif /* MIN(a,b) */
- #ifndef MAX
- #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
- #endif /* MAX(a,b) */
- #ifndef CLAMP
- #define CLAMP(n, mn, mx) MIN(MAX(n,mn),mx)
- #endif /* CLAMP(n, mn, mx) */
- //precise version
- #ifndef LERP
- #define LERP(_v0, _v1, _t) ( (1.0f-(_t)) * (_v0) + (_t) * (_v1) )
- #endif /* LERP */
- //imprecise version
- #ifndef LERP2
- #define LERP2(_v0, _v1, _t) ( (_v0) + (_t) * ((_v1)-(_v0)) )
- #endif /* LERP2 */
- //creates an ABGR color in the form of a u32, not colors::ABGR
- #ifndef ABGR_U32
- #define ABGR_U32(_r,_g,_b,_a) (\
- ((kit::u32)(_a)<<24) | ((kit::u32)(_b)<<16) |\
- ((kit::u32)(_g)<< 8) | ((kit::u32)(_r) ) )
- #endif /* ABGR_U32 */
- //creates an ARGB color in the form of a u32, not colors::ARGB
- #ifndef ARGB_U32
- #define ARGB_U32(_r,_g,_b,_a) (\
- ((kit::u32)(_a)<<24) | ((kit::u32)(_r)<<16) |\
- ((kit::u32)(_g)<< 8) | ((kit::u32)(_b) ) )
- #endif /* ABGR_U32 */
- #ifndef NULLDELETE
- #define NULLDELETE(_ptr_to_thing) { delete _ptr_to_thing; _ptr_to_thing = nullptr; }
- #endif /* NULLDELETE */
- #ifndef PTR_OFFSET
- #define PTR_OFFSET(_ptr, _offset, _type) ( \
- (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)) ) )
- #endif /* PTR_OFFSET */
- #ifndef PTR_OFFSETB
- #define PTR_OFFSETB(_ptr, _offset, _type) ( \
- (_type*)( ((kit::u64)(_ptr)) + ((kit::s64)(_offset)*sizeof(_type)) ) )
- #endif /* PTR_OFFSETB */
- // integer bounds
- #define KIT_U8_MAX (0xFF)
- #define KIT_U16_MAX (0xFFFF)
- #define KIT_U32_MAX (0xFFFFFFFF)
- #define KIT_U64_MAX (0xFFFFFFFFFFFFFFFF)
- //
- #define KIT_S8_MIN (0x80)
- #define KIT_S8_MAX (0x7F)
- #define KIT_S16_MIN (0x8000)
- #define KIT_S16_MAX (0x7FFF)
- #define KIT_S32_MIN (0x80000000)
- #define KIT_S32_MAX (0x7FFFFFFF)
- #define KIT_S64_MIN (0x8000000000000000)
- #define KIT_S64_MAX (0x7FFFFFFFFFFFFFFF)
- // most significant bits/Bytes
- #define KIT_MSb_8 (0x80)
- #define KIT_MSb_16 (0x8000)
- #define KIT_MSb_32 (0x80000000)
- #define KIT_MSb_64 (0x8000000000000000)
- //
- #define KIT_MSB_8 (0xFF)
- #define KIT_MSB_16 (0xFF00)
- #define KIT_MSB_32 (0xFF000000)
- #define KIT_MSB_64 (0xFF00000000000000)
- #define BOOLSTR(_bool_value) ((_bool_value) ? _boolStr_true : _boolStr_false)
- extern const char _boolStr_false[]; // = "false"
- extern const char _boolStr_true[]; // = "true"
- #if defined(_STDINT) || defined(_CSTDINT_)
- typedef uint8_t u8 ;
- typedef uint16_t u16;
- typedef uint32_t u32;
- typedef uint64_t u64;
- typedef int8_t s8 ;
- typedef int16_t s16;
- typedef int32_t s32;
- typedef int64_t s64;
- #else
- typedef unsigned char u8 ;
- typedef unsigned short u16;
- typedef unsigned int u32;
- typedef unsigned long long u64;
- typedef signed char s8 ;
- typedef signed short s16;
- typedef signed int s32;
- typedef signed long long s64;
- #endif
- // for consistency
- typedef float f32;
- typedef double f64;
- #if !defined(_STDDEF_H) && !defined(_STDDEF_H_) && !defined(_GLIBCXX_CSTDDEF)
- #ifndef _SIZE_T_DEFINED
- #define _SIZE_T_DEFINED
- typedef u64 size_t;
- #endif /* _SIZE_T_DEFINED */
- #endif
- //short for Generic Opaque Pointer; mostly used internally
- typedef void* GenOpqPtr;
- namespace colors {
- union ARGB8888 { //4B; 0xAARRGGBB
- //what GDI uses (save for the alpha channel)
- u32 v; //entire color [v]alue
- struct { u8 b, g, r, a; };
- ARGB8888() : v(0) {}
- ARGB8888(u32 _v) : v(_v) {}
- ARGB8888(u8 _r, u8 _g,
- u8 _b, u8 _a) : b(_b), g(_g), r(_r), a(_a) {}
- inline bool operator==(const ARGB8888& c ){ return (v == c.v); }
- inline bool operator!=(const ARGB8888& c ){ return (v != c.v); }
- inline bool operator==(const u32 & cv){ return (v == cv ); }
- inline bool operator!=(const u32 & cv){ return (v != cv ); }
- inline void operator =(const u32 cv){ (v = cv ); }
- };
- typedef ARGB8888 ARGB;
- union ABGR8888 { //4B; 0xAABBGGRR
- u32 v; //entire color [v]alue
- struct { u8 r, g, b, a; };
- ABGR8888() : v(0) {}
- ABGR8888(u32 _v) : v(_v) {}
- ABGR8888(u8 _r, u8 _g,
- u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
- inline bool operator==(const ABGR8888& c ){ return (v == c.v); }
- inline bool operator!=(const ABGR8888& c ){ return (v != c.v); }
- inline bool operator==(const u32 & cv){ return (v == cv ); }
- inline bool operator!=(const u32 & cv){ return (v != cv ); }
- inline void operator =(const u32 cv){ (v = cv ); }
- };
- typedef ABGR8888 ABGR;
- struct BGR888 { //3B; 0xBBGGRR
- //can't use a v of u32 here, or else this turns into a 4 byte struct
- //(which makes assignments from and comparisons of u32 values annoying)
- u8 r, g, b;
- BGR888() : r(0), g(0), b(0) {}
- BGR888(u32 v) : r(v&255), g((v>>8)&255), b((v>>16)&255) {}
- BGR888(u8 _r, u8 _g, u8 _b) : r(_r), g(_g), b(_b) {}
- #define _BGR888_U32_ ((u32)(b)<<16|(u32)(g)<<8|(u32)(r))
- inline bool operator==(const BGR888& c ){ return (r==c.r && g==c.g && b==c.b); }
- inline bool operator!=(const BGR888& c ){ return (r!=c.r && g!=c.g && b!=c.b); }
- inline bool operator==(const u32 & cv){ return (_BGR888_U32_ == cv ); }
- inline bool operator!=(const u32 & cv){ return (_BGR888_U32_ != cv ); }
- inline void operator =(const u32 cv){ r=cv&255, g=(cv>>8)&255, b=(cv>>16)&255; }
- #undef _BGR888_U32_
- };
- typedef BGR888 BGR;
- union ARGB1555 { //2B; 0bARRRRRGGGGGBBBBB
- u16 v; //entire color [v]alue
- struct {
- u16 b : 5;
- u16 g : 5;
- u16 r : 5;
- u16 a : 1;
- };
- ARGB1555() : v(0) {}
- ARGB1555(u16 _v) : v(_v) {}
- ARGB1555(u8 _r, u8 _g,
- u8 _b, u8 _a) : b(_b>>3), g(_g>>3), r(_r>>3), a(_a>>7) {}
- inline bool operator==(const ARGB1555& c ){ return (v == c.v); }
- inline bool operator!=(const ARGB1555& c ){ return (v != c.v); }
- inline bool operator==(const u16 & cv){ return (v == cv ); }
- inline bool operator!=(const u16 & cv){ return (v != cv ); }
- inline void operator =(const u16 cv){ (v = cv ); }
- };
- }; /* namespace color */
- namespace shape {
- struct spoint {
- s16 x, y;
- spoint() : x(0), y(0) {}
- spoint(s16 _x, s16 _y) : x(_x), y(_y) {}
- inline bool operator==(const spoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const spoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct srect {
- s16 x, y; //x & y position of the rectangle's top-left corner
- s16 w, h; //the rectangle's width & height
- srect() : x(0), y(0), w(0), h(0) {}
- srect(s16 _x, s16 _y) : x(_x), y(_y) {}
- srect(s16 _x, s16 _y,
- s16 _w, s16 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const srect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const srect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct sline {
- s16 x0, y0;
- s16 x1, y1;
- sline() : x0(0), y0(0), x1(0), y1(0) {}
- sline(s16 _x0, s16 _y0,
- s16 _x1, s16 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const sline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const sline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct scircle {
- s16 x, y, r;
- scircle() : x(0), y(0), r(0) {}
- scircle(s16 _x, s16 _y, s16 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const scircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const scircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const spoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const spoint& p){ x += p.x; y += p.y; }
- };
- struct spoint3d {
- s16 x, y, z;
- spoint3d() : x(0), y(0), z(0) {}
- spoint3d(s16 _x, s16 _y, s16 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const spoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const spoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct point {
- s32 x, y;
- point() : x(0), y(0) {}
- point(s32 _x, s32 _y) : x(_x), y(_y) {}
- inline bool operator==(const point& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const point& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct rect {
- s32 x, y; //x & y position of the rectangle's top-left corner
- s32 w, h; //the rectangle's width & height
- rect() : x(0), y(0), w(0), h(0) {}
- rect(s32 _x, s32 _y) : x(_x), y(_y) {}
- rect(s32 _x, s32 _y,
- s32 _w, s32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const rect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const rect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct line {
- s32 x0, y0;
- s32 x1, y1;
- line() : x0(0), y0(0), x1(0), y1(0) {}
- line(s32 _x0, s32 _y0,
- s32 _x1, s32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const line& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const line& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct circle {
- s32 x, y, r;
- circle() : x(0), y(0), r(0) {}
- circle(s32 _x, s32 _y, s32 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const circle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const circle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const point& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const point& p){ x += p.x; y += p.y; }
- };
- struct point3d {
- s32 x, y, z;
- point3d() : x(0), y(0), z(0) {}
- point3d(s32 _x, s32 _y, s32 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const point3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const point3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct fpoint {
- f32 x, y;
- fpoint() : x(0.0f), y(0.0f) {}
- fpoint(f32 _x, f32 _y) : x(_x), y(_y) {}
- inline bool operator==(const fpoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const fpoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct frect {
- f32 x, y; //x & y position of rectangle's top-left corner
- f32 w, h; //the rectangle's width & height
- frect() : x(0.0f), y(0.0f), w(0.0f), h(0.0f) {}
- frect(f32 _x, f32 _y) : x(_x), y(_y) {}
- frect(f32 _x, f32 _y,
- f32 _w, f32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const frect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const frect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct fline {
- f32 x0, y0;
- f32 x1, y1;
- fline() : x0(0.0f), y0(0.0f), x1(0.0f), y1(0.0f) {}
- fline(f32 _x0, f32 _y0,
- f32 _x1, f32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const fline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const fline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct fcircle {
- f32 x, y, r;
- fcircle() : x(0.0f), y(0.0f), r(0.0f) {}
- fcircle(f32 _x, f32 _y, f32 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const fcircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const fcircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const fpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const fpoint& p){ x += p.x; y += p.y; }
- };
- struct fpoint3d {
- f32 x, y, z;
- fpoint3d() : x(0.0f), y(0.0f), z(0.0f) {}
- fpoint3d(f32 _x, f32 _y, f32 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const fpoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const fpoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- struct dpoint {
- f64 x, y;
- dpoint() : x(0.0), y(0.0) {}
- dpoint(f64 _x, f64 _y) : x(_x), y(_y) {}
- inline bool operator==(const dpoint& p){ return (x==p.x && y==p.y); };
- inline bool operator!=(const dpoint& p){ return (x!=p.x && y!=p.y); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct drect {
- f64 x, y; //x & y position of rectangle's top-left corner
- f64 w, h; //the rectangle's width & height
- drect() : x(0.0), y(0.0), w(0.0), h(0.0) {}
- drect(f64 _x, f64 _y) : x(_x), y(_y) {}
- drect(f64 _x, f64 _y,
- f64 _w, f64 _h) : x(_x), y(_y), w(_w), h(_h) {}
- inline bool operator==(const drect& r){ return (x==r.x && y==r.y && w==r.w && h==r.h); };
- inline bool operator!=(const drect& r){ return (x!=r.x && y!=r.y && w!=r.w && h!=r.h); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct dline {
- f64 x0, y0;
- f64 x1, y1;
- dline() : x0(0.0), y0(0.0), x1(0.0), y1(0.0) {}
- dline(f64 _x0, f64 _y0,
- f64 _x1, f64 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- inline bool operator==(const dline& l){ return (x0==l.x0 && y0==l.y0 && x1==l.x1 && y1==l.y1); };
- inline bool operator!=(const dline& l){ return (x0!=l.x0 && y0!=l.y0 && x1!=l.x1 && y1!=l.y1); };
- };
- struct dcircle {
- f64 x, y;
- f64 r;
- dcircle() : x(0.0), y(0.0), r(0.0) {}
- dcircle(f64 _x, f64 _y, f64 _r) : x(_x), y(_y), r(_r) {}
- inline bool operator==(const dcircle& c){ return (x==c.x && y==c.y && r==c.r); };
- inline bool operator!=(const dcircle& c){ return (x!=c.x && y!=c.y && r!=c.r); };
- inline void operator-=(const dpoint& p){ x -= p.x; y -= p.y; }
- inline void operator+=(const dpoint& p){ x += p.x; y += p.y; }
- };
- struct dpoint3d {
- f64 x, y, z;
- dpoint3d() : x(0.0), y(0.0), z(0.0) {}
- dpoint3d(f64 _x, f64 _y, f64 _z) : x(_x), y(_y), z(_z) {}
- inline bool operator==(const dpoint3d& p){ return (x==p.x && y==p.y && z==p.z); }
- inline bool operator!=(const dpoint3d& p){ return (x!=p.x && y!=p.y && z!=p.z); }
- };
- }; /* namespace shape */
- //turns a byte into an integer that is printf'able with the format secifier "%08x"
- static inline u32 bin_hex(char n){
- return (n&128)<<21|(n&64)<<18|(n&32)<<15|(n&16)<<12|(n&8)<<9|(n&4)<<6|(n&2)<<3|(n&1);
- }
- }; /* namespace kit */
- #endif /* _COMMONDEF_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\misc.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_MISC_HPP
- #define _INC_MISC_HPP
- #include "commondef.hpp"
- #include "_misc_memory.hpp"
- #include "_misc_Mutex.hpp"
- #include "_misc_Thread.hpp"
- #include "_misc_func.hpp"
- #include "_misc_time.hpp"
- #include "_misc_Event.hpp"
- #include "_misc_EventWatch.hpp"
- #include "_misc_fileio.hpp"
- #endif /* _INC_MISC_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\video.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_VIDEO_HPP
- #define _INC_VIDEO_HPP
- #include "commondef.hpp"
- #include "_video_Window.hpp"
- #include "_video_PixelFmt.hpp"
- #include "_video_Surface.hpp"
- #endif /* _INC_VIDEO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_AudioData.hpp":
- #ifndef _INC__AUDIO_AUDIODATA_HPP
- #define _INC__AUDIO_AUDIODATA_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- namespace kit {
- #define KIT_MAGIC_KPCM (0x4D43506B) // = 'kPCM'
- struct AudioDataHeader { //72B (0x48B)
- u32 magic; // (0x00) = KIT_MAGIC_KPCM = 0x4D43506B = "kPCM"
- u16 format; // (0x04) = one of AudioSampleFormatEnum if fmt_version == 1
- u16 headerSize; // (0x06) = must be >=sizeof(AudioDataHeader)
- u64 dataSize; // (0x08) = size of audio data, in bytes
- u64 loopStart; // (0x10) = which sample to loop back to
- u64 loopEnd; // (0x18) = which sample to jump back to loopStart on
- u64 numSamples; // (0x20) = # of sample frames in audio data
- u32 sampleRate; // (0x28) = the audio data's sample rate, in Hz
- u32 bitRate; // (0x2C) = the audio's bit rate (per second)
- u16 loopCount; // (0x30) = # of times to loop audio (0 = no loop, 0xFFFF = inf loop)
- u16 channels; // (0x32) = # of interlaced channels in the audio data
- u8 bitRemainder; // (0x34) = <bits per sample> % 8
- u8 fmt_version; // (0x35) = 0=kit_w32, 1=kit_sdl2
- u16 mode; // (0x36) = 0 for normal PCM data
- void* samples; // (0x38) = the audio's sample data (appears as nullptr in file)
- void* userdata; // (0x40) = user-defined (also appears nullptr in file)
- // (0x48) = (start of sample data, assuming a .kpcm file)
- };
- class AudioData { //24B
- u32 _type;
- bool _valid = false;
- bool _constructing = true;
- u16 _padding16;
- void _allocate_hdr_unstructured(size_t )
- void _allocate_hdr_structured(u16 format)
- public:
- //(allocated using memory::allocSIMD)
- AudioDataHeader* const hdr;
- f32 volumeL = 1.0f;
- f32 volumeR = 1.0f;
- //AudioData
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_AUDIODATA_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_AudioDevice.hpp":
- #ifndef _INC__AUDIO_AUDIODEVICE_HPP
- #define _INC__AUDIO_AUDIODEVICE_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- namespace kit {
- //if disableFadeDelay == false, audio will be muted for 90ms
- //before fading in over the course of 10ms (100ms in total).
- //if disableFadeDelay == true, only the 10ms fade-in will occur
- class AudioDevice { //64B
- u32 _type;
- bool _valid = false;
- bool _constructing = true;
- u16 _padding16;
- GenOpqPtr _opq = nullptr;
- //(device starts in a paused state!)
- void _construct(const char* name,
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false,
- bool indexed = true);
- public:
- const AudioDeviceInfo info;
- //(internally calls SDL_GetAudioDeviceName to get device's name)
- AudioDevice(s32 index, //-1 to use default device
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false);
- AudioDevice(const char* name, //nullptr to use default device
- const AudioDeviceInfo* desired,
- bool disableFadeDelay = false)
- { _construct(name, desired, disableFadeDelay, false); }
- //this will abruptly stop audio playback with no fade-out, so make sure
- //to have the device be completely paused by the time this is called!
- //(it's technically fine to do this w/o pausing, but it sounds terrible)
- ~AudioDevice();
- inline bool isValid() { return _valid; }
- inline bool isConstructing(){ return _constructing; }
- bool isPlaying(); //'is the user callback actually getting called?'
- bool isActive(); //'is the underlying SDL device actually writing to DAC?'
- //(^^returning true does not necessarily mean
- //that the callback is actually being called!)
- void setCallback(AudioCallback callback);
- void setUserdata(void* userdata);
- void setPlayback(bool playing);
- void setPlaybackAndWait(bool playing); //false,true = wait 10ms, wait 100ms
- inline void play() { setPlayback(true ); }
- inline void pause(){ setPlayback(false); }
- inline void playAndWait() { setPlaybackAndWait(true ); }
- inline void pauseAndWait(){ setPlaybackAndWait(false); }
- void lock(bool locked = true);
- inline void unlock(){ lock(false); }
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_AUDIODEVICE_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_AudioStream.hpp":
- #ifndef _INC__AUDIO_AUDIOSTREAM_HPP
- #define _INC__AUDIO_AUDIOSTREAM_HPP
- #include "commondef.hpp"
- #include "_audio_types.hpp"
- namespace kit {
- //converts an audio buffer to that of a different type,
- //for example, mono s16 @ 44.1kHz -> stereo f32 @ 48kHz
- class AudioStream { //112B
- u32 _type;
- bool _valid = false;
- bool _constructing = true;
- u16 _padding16;
- GenOpqPtr _opq = nullptr;
- public:
- //(only .sampleRate, .sampleFormat, and .numChannels are actually used here)
- const AudioDeviceInfo src; //what will be converted to dst
- const AudioDeviceInfo dst; //what to convert src to
- AudioStream(const AudioDeviceInfo* src_p, const AudioDeviceInfo* dst_p);
- ~AudioStream();
- inline bool isValid() { return _valid; }
- inline bool isConstructing(){ return _constructing; }
- //returns # of converted bytes ready to be read from with a call to get()
- //(if 0 is returned, you can call flush() to make available whatever is
- // left in the buffer. though this might cause audio dropouts if you
- // intend on making additional calls to put() to the stream!)
- u32 getAvailableBytes();
- //tell the stream that you're done sending data, and anything being
- //buffered should be converted/resampled and made available immediately
- void flush();
- //clear any pending data in the stream without converting it
- void clear();
- //read from converted data into buffer_dst
- //returns number of bytes read from stream (to a max of buffer_size bytes)
- u32 get(void* buffer_dst, u32 buffer_size);
- //write samples (from buffer_src) to stream to be converted
- //(buffer_size is also in bytes here)
- void put(void* buffer_src, u32 buffer_size);
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_AUDIOSTREAM_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\include\kit\_audio_types.hpp":
- #ifndef _INC__AUDIO_TYPES_HPP
- #define _INC__AUDIO_TYPES_HPP
- #include "commondef.hpp"
- namespace kit {
- #define KIT_AUDIO_BITSIZE(x) (x & (0xFF ))
- #define KIT_AUDIO_ISFLOAT(x) (x & (1<< 8))
- //#define KIT_AUDIO_ISBIGENDIAN(x) (x & (1<<12))
- #define KIT_AUDIO_ISSIGNED(x) (x & (1<<15))
- #define KIT_AUDIO_BYTESIZE(x) (KIT_AUDIO_BITSIZE(x)/8)
- //(big-endian sample formats are not supported currently)
- enum AudioSampleFormatEnum {
- SMPFMT_U8 = 0x0008, //unsigned 8-bit samples
- SMPFMT_S8 = 0x8008, // signed 8-bit samples
- SMPFMT_U16LSB = 0x0010, //unsigned 16-bit samples
- SMPFMT_S16LSB = 0x8010, // signed 16-bit samples
- //SMPFMT_U16MSB = 0x1010, //as above, but big-endian byte order
- //SMPFMT_S16MSB = 0x9010, //as above, but big-endian byte order
- SMPFMT_S32LSB = 0x8020, // signed 32-bit samples
- //SMPFMT_S32MSB = 0x9020, //As above, but big-endian byte order
- SMPFMT_F32LSB = 0x8120, //32-bit floating point samples
- //SMPFMT_F32MSB = 0x9120, //As above, but big-endian byte order
- SMPFMT_U16 = SMPFMT_U16LSB,
- SMPFMT_S16 = SMPFMT_S16LSB,
- SMPFMT_S32 = SMPFMT_S32LSB,
- SMPFMT_F32 = SMPFMT_F32LSB,
- SMPFMT_UKNOWN = 0xFFFF,
- };
- struct AudioDeviceInfo; //forward declaration
- //returns:
- //< 0: abort playback (pause without fade-out)
- //= 0: continue playing
- //> 0: pause playback (pause with fade-out)
- //(also, _buffer should already be aligned and padded for use
- //with vector operations, like those in SSE and AVX!)
- typedef s32 (*AudioCallback)(void* _buffer, const AudioDeviceInfo* info);
- /* (taken from the SDL2 wiki):
- For multi-channel audio, the default SDL channel mapping is:
- 2: FL FR (stereo)
- 3: FL FR LFE (2.1 surround)
- 4: FL FR BL BR (quad)
- 5: FL FR LFE BL BR (4.1 surround)
- 6: FL FR FC LFE SL SR (5.1 surround - last two can also be BL BR)
- 7: FL FR FC LFE BC SL SR (6.1 surround)
- 8: FL FR FC LFE BL BR SL SR (7.1 surround)
- */
- struct AudioDeviceInfo { //48B
- u64 timeStartTicks = 0; //timestamp (in ticks) at start of callback (read-only)
- u64 timeStartMS = 0; //timestamp (in ms) at start of callback (read-only)
- u32 deviceID = 0; //(read-only)
- u32 sampleRate = 0; //0 to use device's default
- u16 sampleFrames = 0; //0 to use device's default (should always be a power of 2)
- u16 sampleFormat = SMPFMT_F32; //samples are f32 by default
- u8 sampleFrameSize = 0; //size of a single sample frame, in bytes (read only)
- u8 numChannels = 0; //0 to use device's default
- bool isInput = false; //is this a recording device? (rendering/output otherwise)
- bool zeroBuffer = false; //'memset 0 the audio buffer before calling callback?' (output devs only)
- AudioCallback callback = nullptr;
- void* userdata = nullptr; //optional, unlike callback
- };
- union Mono_smp {
- u8* u8_ ;
- s8* s8_ ;
- u16* u16_;
- s16* s16_;
- s32* s32_;
- f32* f32_;
- void* data;
- Mono_smp(void* _data) : data(_data) {}
- };
- struct Stereo_u8 { u8 l, r; };
- struct Stereo_s8 { s8 l, r; };
- struct Stereo_u16 { u16 l, r; };
- struct Stereo_s16 { s16 l, r; };
- struct Stereo_s32 { s32 l, r; };
- struct Stereo_f32 { f32 l, r; };
- union Stereo_smp {
- Stereo_u8* u8_ ;
- Stereo_s8* s8_ ;
- Stereo_u16* u16_;
- Stereo_s16* s16_;
- Stereo_s32* s32_;
- Stereo_f32* f32_;
- void* data;
- Stereo_smp(void* _data) : data(_data) {}
- };
- }; /* namespace kit */
- #endif /* _INC__AUDIO_TYPES_HPP */
Add Comment
Please, Sign In to add comment