Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\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 */
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\src\kit_sdl2\kit_load_wav.h":
- /*
- * Copyright (c) 2024, Conlan Walker
- * SPDX-License-Identifier: Zlib
- *
- * File: kit_load_wav.h
- *
- * Purpose: A parser for most common types of Microsoft Waveform Audio Files
- *
- * Version: r1.4
- */
- #ifndef KIT_LOAD_WAV_H
- #define KIT_LOAD_WAV_H
- #ifdef __cplusplus
- extern "C" {
- #endif /* __cplusplus */
- #include <stdint.h>
- /* Relevant with respect to .format and .sub.format */
- typedef enum {
- WAVEDATA_FORMAT_PCM = 1,
- WAVEDATA_FORMAT_FLOAT = 3,
- WAVEDATA_FORMAT_ALAW = 6, /* assumes A = 87.6 (I think) */
- WAVEDATA_FORMAT_ULAW = 7, /* assumes u = 255 (I think) */
- /* If ".format" equals this, the actual format tag (as in
- the above four format tags) will be in ".sub.format" */
- WAVEDATA_FORMAT_EXTENSIBLE = 0xFFFE,
- } kit_WavData_formats;
- /* Combines info from: .format/.sub.format, .bitsPerSample, and .validBits */
- #define DEF_WAVEDATA_TYPE(_sgn, _fmt, _vbt, _tbt) \
- ( (_sgn)<<15 | (_fmt)<<12 | (_vbt)<<6 | (_tbt) )
- typedef enum {
- WAVEDATA_TYPE_UNKNOWN = 0,
- WAVEDATA_TYPE_U8 = DEF_WAVEDATA_TYPE(0, WAVEDATA_FORMAT_PCM , 7, 7),
- WAVEDATA_TYPE_S16 = DEF_WAVEDATA_TYPE(1, WAVEDATA_FORMAT_PCM , 15, 15),
- WAVEDATA_TYPE_S24 = DEF_WAVEDATA_TYPE(1, WAVEDATA_FORMAT_PCM , 23, 23),
- WAVEDATA_TYPE_S32 = DEF_WAVEDATA_TYPE(1, WAVEDATA_FORMAT_PCM , 31, 31),
- WAVEDATA_TYPE_F32 = DEF_WAVEDATA_TYPE(1, WAVEDATA_FORMAT_FLOAT, 31, 31),
- WAVEDATA_TYPE_F64 = DEF_WAVEDATA_TYPE(1, WAVEDATA_FORMAT_FLOAT, 63, 63),
- WAVEDATA_TYPE_ALAW = DEF_WAVEDATA_TYPE(0, WAVEDATA_FORMAT_ALAW , 7, 7),
- WAVEDATA_TYPE_ULAW = DEF_WAVEDATA_TYPE(0, WAVEDATA_FORMAT_ULAW , 7, 7),
- } kit_WavData_types;
- #define WAVEDATA_TYPE_ISSIGNED(_value) ( ((_value)>>15) & 1 )
- #define WAVEDATA_TYPE_FORMAT(_value) ( ((_value)>>12) & 7 )
- #define WAVEDATA_TYPE_VALIDBITS(_value) ( ((_value)>> 6) & 63 )
- #define WAVEDATA_TYPE_TOTALBITS(_value) ( (_value) & 63 )
- typedef union {
- uint16_t value;
- struct {
- uint16_t totalBits : 6;
- uint16_t validBits : 6; /* 0 for 1-bit, 63 for 64-bits, etc. */
- uint16_t format : 3; /* one of kit_WavData_formats (minus EXTENSIBLE) */
- uint16_t isSigned : 1;
- };
- } kit_WavData_type;
- typedef struct kit_WavData { /* 72B (excluding actual sample data, of course) */
- /********************** PRESENT IN ALL "fmt" SUBCHUNKS **********************/
- uint16_t format; /* one of kit_WaveData_formats */
- uint16_t channels; /* # of interleaved channels; L&R for stereo (2) */
- uint32_t sampleRate; /* Sample frames per second */
- uint32_t byteRate; /* = blockAlign*sampleRate */
- uint16_t blockAlign; /* Size of smp frame = (channels*bitsPerSample)/8 */
- uint16_t bitsPerSample; /* Assumed to be unsigned if 8 and .format is PCM */
- /********************* WAVEDATA_FORMAT_EXTENSIBLE ONLY **********************/
- uint16_t extSize; /* Size of the extension (should = 0 OR 22) */
- uint16_t validBits; /* # of bits used (must bs <= bitsPerSample) */
- uint32_t channelMask; /* Speaker bitmask */
- union { /* */
- uint32_t format; /* Subformat; same as .format (minus EXTENSIBLE) */
- char GUID_str[16]; /* */
- uint64_t GUID_num[2]; /* */
- } /************/ sub; /* GUID, (+ data format tag; 1st 4 bytes of GUID) */
- /***************************** kit_WavData ONLY *****************************/
- void* userdata; /* = NULL when returned by kit_<load/parse>_wav() */
- uint32_t _reserved_0; /* */
- uint16_t _reserved_1; /* */
- /* */
- uint16_t samples_type; /* May be set to 0 if calculation attempt failed */
- uint32_t samples_size; /* In bytes */
- uint32_t samples_len; /* In sample frames */
- void* samples; /* = &this_struct.samples + sizeof(void*) */
- } kit_WavData;
- typedef enum {
- WAVEERROR_SUCCESS = 0,
- WAVEERROR_NULLPTR = 1, /* Non-optional argument pointer was NULL */
- WAVEERROR_FILE_READ = 2, /* Failed to read file */
- WAVEERROR_FILE_SIZE = 3, /* FileSize was < 44 (minimum needed for header) */
- WAVEERROR_NOT_RIFF = 4, /* First 4 bytes of file != "RIFF" */
- WAVEERROR_MALFORMED = 5, /* Inconsistent subchunk sizes, bad ids, etc. */
- WAVEERROR_NOT_WAVE = 6, /* 4 bytes from offset 8 != "WAVE" */
- WAVEERROR_MALLOC = 7, /* Failed to allocate memory */
- WAVEERROR_NO_FMT = 8, /* Wav doesn't contain a f[or]m[a]t subchunk */
- WAVEERROR_NO_DATA = 9, /* Wav doesn't contain a data subchunk */
- WAVEERROR_FORMAT = 10, /* Wav uses an unsupported format tag */
- WAVEERROR_CHANNELS = 11, /* .channels = 0 */
- WAVEERROR_SAMPLERATE = 12, /* .sampleRate = 0 */
- WAVEERROR_BYTERATE = 13, /* .byteRate != .blockAlign*.sampleRate */
- WAVEERROR_BLOCKALIGN = 14, /* .blockAlign != (.channels*.bitsPerSample)/8 */
- WAVEERROR_BITSPERSMP = 15, /* .bitsPerSample%8 != 0 OR = 0 OR > 64 */
- WAVEERROR_EXTSIZE = 16, /* .extSize < 22 (if format is EXTENSIBLE) */
- WAVEERROR_VALIDBITS = 17, /* .validBits > .bitsPerSample OR = 0 */
- WAVEERROR_UNKNOWN = -1,
- } kit_load_wav_errors;
- /* Read and parse a .wav file (Calls kit_read_wav and kit_parse_wav internally!)
- *
- * Returns a pointer to a kit_WavData struct that contains
- * the .wav's header and sample data, or NULL on failure.
- *
- * if error_out != NULL, the int it points to will be
- * filled with the resulting kit_load_wav_errors code.
- *
- * The returned pointer should be freed after use (if successful).
- *
- * Only PCM, float, A-law, and u-law samples are supported.
- *
- * (.samples is contiguous with the returned struct's memory block,
- * so when the struct is freed, the samples are too!)
- */
- kit_WavData* kit_load_wav(const char* filePath,
- int32_t* error_out);
- /* Allocate memory for and read a .wav file.
- *
- * if fileSize_out != NULL, the int it points to will be
- * filled with the size of the read file in bytes.
- *
- * Returns a pointer to the raw file data, or NULL on failure.
- *
- * The returned pointer should be freed after use (if successful).
- *
- * (#define KIT_LOAD_WAV_CUSTOM_READ to make
- * kit_load_wav() use your own implementation!)
- * (Files > 2^31-1 bytes will fail to read!)
- */
- void* kit_read_wav(const char* filePath, int32_t* fileSize_out);
- /* Parse the file data of a .wav in memory.
- *
- * Returns a pointer to a kit_WavData struct that contains
- * the .wav's header and sample data, or NULL on failure.
- *
- * if error_out != NULL, the int it points to will be
- * filled with the resulting kit_load_wav_errors code.
- *
- * The returned pointer should be freed after use.
- *
- * Only PCM, float, A-law, and u-law samples are supported.
- *
- * (.samples is contiguous with the struct's memory block,
- * so when the struct is freed, the samples are too!)
- * (Sample data is copied from fileData, not referenced!)
- */
- kit_WavData* kit_parse_wav(const void* fileData, int32_t fileSize,
- int32_t* error_out);
- #ifdef __cplusplus
- }
- #endif /* __cplusplus */
- #endif /* KIT_LOAD_WAV_H */
- /******************************************************************************/
- #ifdef KIT_LOAD_WAV_IMPLEMENTATION
- #ifndef KIT_LOAD_WAV_MALLOC
- #define KIT_LOAD_WAV_MALLOC(_ptr) malloc(_ptr)
- #include <stdlib.h>
- #endif /* KIT_LOAD_WAV_MALLOC */
- #ifndef KIT_LOAD_WAV_FREE
- #define KIT_LOAD_WAV_FREE(_ptr) free(_ptr)
- #include <stdlib.h>
- #endif /* KIT_LOAD_WAV_FREE */
- #ifndef KIT_LOAD_WAV_MEMSET
- #define KIT_LOAD_WAV_MEMSET(_ptr_or_arr, _value, _size) \
- memset((_ptr_or_arr), (_value), (_size))
- #include <string.h>
- #endif /* KIT_LOAD_WAV_MEMSET */
- #ifndef KIT_LOAD_WAV_MEMCPY
- #define KIT_LOAD_WAV_MEMCPY(_dst_ptr, _src_ptr, _size) \
- memcpy((_dst_ptr), (_src_ptr), (_size))
- #include <string.h>
- #endif /* KIT_LOAD_WAV_MEMCPY */
- #ifndef KIT_LOAD_WAV_CHUNKSIZE
- #define KIT_LOAD_WAV_CHUNKSIZE 4096 /* How many bytes to read at a time */
- #endif /* KIT_LOAD_WAV_CHUNKSIZE */
- #define LDWAV_ASSERT(_success, _errcode) \
- if(!(_success)){ error = (_errcode); goto _return_wavData; }
- kit_WavData* kit_load_wav(const char* filePath,
- int32_t* error_out)
- {
- int32_t error = WAVEERROR_SUCCESS;
- kit_WavData* wavData = NULL;
- if(0){
- _return_wavData:
- if(error_out != NULL) *error_out = error;
- return (error == WAVEERROR_SUCCESS) ? wavData : NULL;
- }
- LDWAV_ASSERT(filePath, WAVEERROR_NULLPTR);
- int32_t fileSize = -1;
- void* fileData = kit_read_wav(filePath, &fileSize);
- LDWAV_ASSERT(fileData, WAVEERROR_FILE_READ);
- wavData = kit_parse_wav(fileData, fileSize, &error);
- KIT_LOAD_WAV_FREE(fileData);
- goto _return_wavData;
- }
- #ifndef KIT_LOAD_WAV_CUSTOM_READ
- #include <stdio.h>
- void* kit_read_wav(const char* filePath, int32_t* fileSize_out){
- if(filePath == NULL) return NULL;
- FILE* file = fopen(filePath, "rb");
- if(file == NULL) return NULL;
- /* get size of file */
- if(fseek(file, 0L, SEEK_END)){
- _fclose_err:
- fclose(file);
- return NULL;
- }
- int32_t fileSize = ftell(file);
- if(fileSize == -1L) goto _fclose_err;
- if(fseek(file, 0L, SEEK_SET) != 0) goto _fclose_err;
- /* allocate memory for file data */
- void* fileData = (void*)KIT_LOAD_WAV_MALLOC(fileSize);
- if(fileData == NULL) goto _fclose_err;
- /* read data from file */
- size_t chunkSize = fileSize%KIT_LOAD_WAV_CHUNKSIZE;
- size_t chunkCount = fileSize/KIT_LOAD_WAV_CHUNKSIZE;
- if(!chunkSize) chunkSize = KIT_LOAD_WAV_CHUNKSIZE;
- else ++chunkCount;
- uint8_t* fileDataPtr = (uint8_t*)fileData;
- for(size_t i=0; i<chunkCount; ++i){
- if(fread(fileDataPtr, 1, chunkSize, file) != chunkSize)
- goto _free_fclose_err;
- fileDataPtr += chunkSize;
- chunkSize = KIT_LOAD_WAV_CHUNKSIZE;
- }
- /* tidy up before returning file data */
- if(fclose(file) != 0){
- _free_fclose_err:
- KIT_LOAD_WAV_FREE(fileData);
- goto _fclose_err;
- }
- if(fileSize_out != NULL) *fileSize_out = fileSize;
- return fileData;
- }
- #endif /* KIT_LOAD_WAV_CUSTOM_READ */
- #include <stdbool.h>
- typedef enum {
- wid_RIFF = 0x46464952, /* = "RIFF" */
- wid_WAVE = 0x45564157, /* = "WAVE" */
- wid_fmt_ = 0x20746D66, /* = "fmt " */
- wid_data = 0x61746164, /* = "data" */
- wid_fact = 0x74636166, /* = "fact" */
- wid_PEAK = 0x4B414550, /* = "PEAK" */
- } _wav_ids;
- typedef struct _wav_PEAK_pos {
- float value; /* Value of peak (-1.0f -> 1.0f) */
- uint32_t position; /* Sample frame of peak */
- } _wav_PEAK_pos;
- typedef struct _wav_PEAK {
- uint32_t version; /* Version of the PEAK subchunk */
- uint32_t timeStamp; /* Seconds since 1970-1-1 */
- _wav_PEAK_pos peaks[1]; /* Peak info array */
- } _wav_PEAK;
- typedef struct _wav_fmtEx {
- struct {
- /********************** PRESENT IN ALL "fmt" SUBCHUNKS **********************/
- uint16_t format; /* one of kit_WaveData_formats */
- uint16_t channels; /* # of interleaved channels; L&R for stereo (2) */
- uint32_t sampleRate; /* Sample frames per second */
- uint32_t byteRate; /* = blockAlign*sampleRate */
- uint16_t blockAlign; /* Size of smp frame = (channels*bitsPerSample)/8 */
- uint16_t bitsPerSample; /* Assumed to be unsigned if 8 and .format is PCM */
- } a;
- struct {
- /********************* WAVEDATA_FORMAT_EXTENSIBLE ONLY **********************/
- uint16_t extSize; /* Size of the extension (should = 0 OR 22) */
- uint16_t validBits; /* # of bits used (must bs <= bitsPerSample) */
- uint32_t channelMask; /* Speaker bitmask */
- union { /* */
- uint32_t format; /* Subformat; same as .format (minus EXTENSIBLE) */
- char GUID_str[16]; /* */
- uint64_t GUID_num[2]; /* */
- } /************/ sub; /* GUID, (+ data format tag; 1st 4 bytes of GUID) */
- } x;
- } _wav_fmtEx;
- typedef struct _wav_chunk {
- uint32_t id;
- uint32_t size;
- /* fmt and data are the only subchunks that kit_parse_wav
- recognizes, so no "fact" or "PEAK" subchunks! */
- union {
- _wav_PEAK PEAK; /* Currently unused */
- _wav_fmtEx fmt;
- uint8_t data[1];
- uint32_t value_u32;
- };
- } _wav_chunk;
- static inline uint32_t _check_format(kit_WavData headerInfo){
- uint32_t formatTag = headerInfo.format;
- if(formatTag == WAVEDATA_FORMAT_EXTENSIBLE)
- formatTag = headerInfo.sub.format;
- switch(formatTag){
- case WAVEDATA_FORMAT_PCM :
- case WAVEDATA_FORMAT_FLOAT:
- case WAVEDATA_FORMAT_ALAW :
- case WAVEDATA_FORMAT_ULAW :
- break;
- default: return 0; /* Invalid format */
- }
- return formatTag;
- }
- #define CHUNK_ADVANCE(_bytes) \
- ( chunk = (const _wav_chunk*)(data+=(_bytes)) )
- kit_WavData* kit_parse_wav(const void* fileData, int32_t fileSize,
- int32_t* error_out)
- {
- int32_t error = WAVEERROR_SUCCESS;
- kit_WavData* wavData = NULL;
- if(0){
- _return_wavData:
- if(error_out != NULL) *error_out = error;
- if(error == WAVEERROR_SUCCESS){
- return wavData;
- } else {
- if(wavData != NULL) KIT_LOAD_WAV_FREE(wavData);
- return NULL;
- }
- }
- LDWAV_ASSERT(fileData, WAVEERROR_NULLPTR);
- LDWAV_ASSERT(fileSize >= 44, WAVEERROR_FILE_SIZE);
- bool has_fmt_ = false;
- bool has_data = false;
- kit_WavData hdr; /* AKA h[ea]d[e]r [info] */
- KIT_LOAD_WAV_MEMSET(&hdr, 0, sizeof(kit_WavData));
- const uint8_t* data = (const uint8_t*)fileData;
- const uint8_t* dataEnd = (const uint8_t*)fileData + fileSize;
- const _wav_chunk* chunk = (const _wav_chunk*)data;
- LDWAV_ASSERT(chunk->id == wid_RIFF, WAVEERROR_NOT_RIFF);
- LDWAV_ASSERT(chunk->size == (uint32_t)(fileSize-8), WAVEERROR_MALFORMED);
- LDWAV_ASSERT(chunk->value_u32 == wid_WAVE, WAVEERROR_NOT_WAVE);
- CHUNK_ADVANCE(sizeof(uint32_t)*3);
- while(data < dataEnd){
- /* Safeguard to make sure heap isn't overshot (hopefully) */
- LDWAV_ASSERT((data + 8+chunk->size) <= dataEnd, WAVEERROR_MALFORMED);
- switch(chunk->id){
- case wid_fmt_: {
- LDWAV_ASSERT(!has_fmt_, WAVEERROR_MALFORMED);
- ((_wav_fmtEx*)&hdr)->a = chunk->fmt.a;
- if(hdr.format == WAVEDATA_FORMAT_EXTENSIBLE)
- ((_wav_fmtEx*)&hdr)->x = chunk->fmt.x;
- has_fmt_ = true;
- } break;
- case wid_data: {
- LDWAV_ASSERT(!has_data, WAVEERROR_MALFORMED);
- size_t wavDataSize = sizeof(kit_WavData)+chunk->size;
- LDWAV_ASSERT(wavDataSize > sizeof(kit_WavData), WAVEERROR_MALFORMED);
- wavData = (kit_WavData*)KIT_LOAD_WAV_MALLOC(wavDataSize);
- LDWAV_ASSERT(wavData, WAVEERROR_MALLOC);
- hdr.samples_size = chunk->size;
- hdr.samples = (uint8_t*)(wavData)+sizeof(kit_WavData);
- KIT_LOAD_WAV_MEMCPY(hdr.samples, chunk->data, chunk->size);
- has_data = true;
- } break;
- default:; /* Other subchunks are ignored */
- }
- CHUNK_ADVANCE(8+chunk->size);
- }
- LDWAV_ASSERT(data == dataEnd, WAVEERROR_MALFORMED);
- LDWAV_ASSERT(has_fmt_, WAVEERROR_NO_FMT);
- LDWAV_ASSERT(has_data, WAVEERROR_NO_DATA);
- LDWAV_ASSERT(wavData, WAVEERROR_MALLOC); /* Just in case */
- uint32_t formatTag = _check_format(hdr);
- LDWAV_ASSERT(formatTag != 0, WAVEERROR_FORMAT);
- LDWAV_ASSERT(hdr.channels != 0, WAVEERROR_CHANNELS);
- LDWAV_ASSERT(hdr.sampleRate != 0, WAVEERROR_SAMPLERATE);
- LDWAV_ASSERT((hdr.bitsPerSample&7) == 0 && hdr.bitsPerSample != 0 &&
- hdr.bitsPerSample <= 64, WAVEERROR_BITSPERSMP);
- LDWAV_ASSERT(hdr.blockAlign == (hdr.channels*hdr.bitsPerSample)/8,
- WAVEERROR_BLOCKALIGN);
- LDWAV_ASSERT(hdr.byteRate == hdr.blockAlign*hdr.sampleRate,
- WAVEERROR_BYTERATE);
- if(hdr.format == WAVEDATA_FORMAT_EXTENSIBLE){
- LDWAV_ASSERT(hdr.extSize >= 22,
- WAVEERROR_EXTSIZE);
- LDWAV_ASSERT(hdr.validBits <= hdr.bitsPerSample && hdr.validBits != 0 &&
- hdr.validBits <= 64, WAVEERROR_VALIDBITS);
- }
- kit_WavData_type smps_type;
- smps_type.isSigned = formatTag == WAVEDATA_FORMAT_FLOAT;
- if(formatTag == WAVEDATA_FORMAT_PCM)
- smps_type.isSigned = hdr.bitsPerSample > 8;
- smps_type.format = formatTag;
- smps_type.validBits = hdr.bitsPerSample-1;
- smps_type.totalBits = hdr.bitsPerSample-1;
- if(hdr.format == WAVEDATA_FORMAT_EXTENSIBLE)
- smps_type.validBits = hdr.validBits-1;
- hdr.samples_type = smps_type.value;
- /* (.samples_size should already be set) */
- hdr.samples_len = hdr.samples_size/hdr.blockAlign;
- *((_wav_fmtEx*)wavData) = *((_wav_fmtEx*)&hdr);
- wavData->userdata = hdr.userdata;
- wavData->_reserved_0 = hdr._reserved_0;
- wavData->_reserved_1 = hdr._reserved_1;
- wavData->samples_type = hdr.samples_type;
- wavData->samples_size = hdr.samples_size;
- wavData->samples_len = hdr.samples_len;
- wavData->samples = hdr.samples;
- goto _return_wavData;
- }
- #endif /* KIT_LOAD_WAV_IMPLEMENTATION */
- /* Revision log:
- *
- * r1.4 2024-11-06 @ 15:56, Conlan
- * Fixed memory leak in kit_load_wav (whoops!)
- *
- * r1.3 2024-11-05 @ 21:04, Conlan
- * Fixed description of WAVEERROR_BITSPERSMP in kit_load_wav_errors
- *
- * r1.2 2024-11-05 @ 13:44, Conlan
- * Fixed stuff related to 'uninitialized member'
- * and 'signedness comparison' warnings
- *
- * r1.1 2024-10-28 @ 21:14, Conlan
- * Removed const keyword from kit_WavData.samples,
- * and every punning hack that was the direct result of that keyword
- *
- * r1.0 2024-10-28 @ 18:40, Conlan
- * Finished kit_load_wav(), kit_read_wav(), and kit_parse_wav()
- */
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\include\demo\include_all.hpp":
- #ifndef _INCLUDE_ALL_HPP
- #define _INCLUDE_ALL_HPP
- #pragma GCC diagnostic ignored "-Wreorder"
- #include <box2d-lite/World.h>
- #include <box2d-lite/Body.h>
- #include <box2d-lite/Joint.h>
- #pragma GCC diagnostic pop
- #include <kit/all.hpp>
- #define WIN_X 1280 //640
- #define WIN_Y 720 //480
- #define CNV_DIV 4 //1, 2, 4, 5, 8, 10, 16, 20, 40, 80
- #define CNV_X (WIN_X/CNV_DIV)
- #define CNV_Y (WIN_Y/CNV_DIV)
- #define BLACK 0xFF000000
- #define FALLTHROUGH __attribute__((fallthrough))
- #define DEF_KIT(_thing, _equal_to) extern kit::_thing;
- #define DEF_GLOBAL_PTRS /* listed by destruction order */ \
- \
- DEF_KIT(Window* win , nullptr)\
- DEF_KIT(Surface* canvas , nullptr)\
- DEF_KIT(Mutex* canvas_lock, nullptr)\
- DEF_KIT(BFont_Surface* font0 , nullptr)\
- DEF_KIT(BFont_Surface* font1 , nullptr)\
- \
- DEF_KIT(AudioData* sfx_tick , nullptr)\
- DEF_KIT(AudioData* sfx_alert, nullptr)\
- DEF_KIT(SoundEngine* sfx , nullptr)\
- DEF_KIT(AudioDevice* audio , nullptr)\
- DEF_KIT(SoundEngine* music , nullptr)\
- DEF_GLOBAL_PTRS
- extern kit::f64 simSpeed;
- extern kit::f32 timeStep;
- extern World world;
- kit::f64 frand(); // 0.0f -> 1.0f
- kit::f64 frand2(); //-1.0f -> 1.0f
- kit::f32 frandf(); // 0.0f -> 1.0f
- kit::f32 frandf2(); //-1.0f -> 1.0f
- static inline void clearCanvas(){ canvas->fillRects(BLACK); }
- void presentCanvas();
- void drawLine(kit::s32 x_0, kit::s32 y_0, kit::s32 x_1, kit::s32 y_1,
- kit::colors::ABGR lineColor);
- void drawBody(Body& body);
- //draws whatever is currently in font's format buffer
- void drawCursorText(kit::s32 x, kit::s32 y, const char* fmt, ...);
- void drawSpeedBar(kit::f32 speed = simSpeed);
- void setSimSpeed(kit::f64 newSpeed);
- struct Box : kit::shape::rect {
- kit::colors::ABGR c = 0xFFC0C0C0;
- Box(){}
- Box(kit::f32 _x, kit::f32 _y, kit::f32 _w, kit::f32 _h){ x=_x; y=_y; w=_w; h=_h; }
- Box(kit::s32 _x, kit::s32 _y, kit::s32 _w, kit::s32 _h){ x=_x; y=_y; w=_w; h=_h; }
- void draw(){
- drawLine(x , y , x+w-1, y , c);
- drawLine(x+w-1, y , x+w-1, y+h-1, c);
- drawLine(x+w-1, y+h-1, x , y+h-1, c);
- drawLine(x , y+h-1, x , y , c);
- }
- };
- #undef DEF_KIT
- #define DEF_KIT(_thing, _equal_to) _thing = _equal_to;
- #endif /* _INCLUDE_ALL_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\include\kit\all.hpp":
- //THIS LIBRARY WAS MADE TO USE SDL2 VERSION 2.28.2
- #ifndef _INC_ALL_HPP
- #define _INC_ALL_HPP
- #include "commondef.hpp"
- #include "misc.hpp"
- #include "video.hpp"
- #include "audio.hpp"
- #endif /* _INC_ALL_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\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"
- #include "_audio_SoundEngine.hpp"
- #endif /* _INC_AUDIO_HPP */
- /******************************************************************************/
- /******************************************************************************/
- //"2024-11-21\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, _type_of_thing) { \
- _type_of_thing* _long_ptr_name_dont_name_anything_else_this = (_type_of_thing*)_ptr_to_thing; \
- _ptr_to_thing = nullptr; \
- delete _long_ptr_name_dont_name_anything_else_this; \
- }
- #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_U24_MAX 0xFFFFFF
- #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_S24_MIN 0x800000
- #define KIT_S24_MAX 0x7FFFFF
- #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_24 0x800000
- #define KIT_MSb_32 0x80000000
- #define KIT_MSb_64 0x8000000000000000
- //
- #define KIT_MSB_8 0xFF
- #define KIT_MSB_16 0xFF00
- #define KIT_MSB_24 0xFF0000
- #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 (if not solely) used internally
- typedef void* GenOpqPtr;
- //used for parameters which require a value between 0 and 0x7FFFFFFF
- union u31 {
- u32 v;
- struct {
- u32 n : 31;
- u32 s : 1;
- };
- inline u31(){}
- template <typename T>
- inline u31(T _v) : v(static_cast<u32>(_v)) {}
- };
- 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 */
Add Comment
Please, Sign In to add comment