Refactor, separate docs from headers, add ru docs
Doxygen kind'a sucks and I need multilanguage documentation, so I did that. Also, separated massive Math.h file into smaller files.
This commit is contained in:
@@ -5,32 +5,11 @@
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
/**
|
||||
* Exchanges values between \a src and \a dest elements of sizze \a size.
|
||||
*
|
||||
* \param dest Destination element pointer
|
||||
* \param src Source element pointer
|
||||
* \param size Element size in bytes
|
||||
*/
|
||||
void BH_Swap(void *dest,
|
||||
void *src,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Partitions the \a array (with specified \a size and \a element size)
|
||||
* relative to specified \a pivot element.
|
||||
*
|
||||
* The \a pivot element can be part of the partitioned \a array.
|
||||
*
|
||||
* \param pivot Pivot element pointer
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparision function
|
||||
*
|
||||
* \return Pointer to the first element of the second partition.
|
||||
*/
|
||||
void *BH_Partition(void *pivot,
|
||||
void *array,
|
||||
size_t size,
|
||||
@@ -38,65 +17,24 @@ void *BH_Partition(void *pivot,
|
||||
BH_EqualCallback equal);
|
||||
|
||||
|
||||
/**
|
||||
* Sorts the \a array (with specified \a size and \a element size).
|
||||
*
|
||||
* The sorting algorithm is implementation defined and may change between
|
||||
* revisions.
|
||||
*
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparision function
|
||||
*/
|
||||
void BH_Sort(void *array,
|
||||
size_t size,
|
||||
size_t element,
|
||||
BH_EqualCallback equal);
|
||||
|
||||
|
||||
/**
|
||||
* Heapifies an \a array (with specified \a size and \a element size).
|
||||
*
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparision function
|
||||
*/
|
||||
void BH_HeapMake(void *array,
|
||||
size_t size,
|
||||
size_t element,
|
||||
BH_EqualCallback equal);
|
||||
|
||||
|
||||
/**
|
||||
* Removes top value from the heapified \a array (with specified \a size
|
||||
* and \a element size).
|
||||
*
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparasion function
|
||||
*/
|
||||
void BH_HeapRemove(void *array,
|
||||
size_t size,
|
||||
size_t element,
|
||||
BH_EqualCallback equal);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts new \a value into heapified \a array in an array (with specified
|
||||
* \a size and \a element size)
|
||||
*
|
||||
* If \a value pointer is NULL, it is assumed that new value is placed at the
|
||||
* end of the array.
|
||||
*
|
||||
* \param value Value pointer
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparasion function
|
||||
*/
|
||||
void BH_HeapInsert(void *value,
|
||||
void *array,
|
||||
size_t size,
|
||||
@@ -104,19 +42,6 @@ void BH_HeapInsert(void *value,
|
||||
BH_EqualCallback equal);
|
||||
|
||||
|
||||
/**
|
||||
* Removes top value from heapified \a array (with specified \a size and
|
||||
* \a element size) and inserts new \a value.
|
||||
*
|
||||
* If value pointer is NULL, it is assumed that new value is placed at the
|
||||
* end of the array.
|
||||
*
|
||||
* \param value Value pointer
|
||||
* \param array Array pointer
|
||||
* \param size Array size
|
||||
* \param element Array element size
|
||||
* \param equal Comparasion function
|
||||
*/
|
||||
void BH_HeapReplace(void *value,
|
||||
void *array,
|
||||
size_t size,
|
||||
|
||||
@@ -24,32 +24,6 @@ typedef struct BH_ArgsOption
|
||||
typedef int (*BH_ArgsCallback)(int key, char *arg, void *data);
|
||||
|
||||
|
||||
/**
|
||||
* Parses command line \a options (given by \a argc and \a argv) and calls the
|
||||
* specified \a callback with \a data.
|
||||
*
|
||||
* There are few internal rules:
|
||||
* - If the "--" argument is specified, option parsing stops, and the rest of
|
||||
* the arguments are processed as is.
|
||||
* - If the "-" argument is specified, it is processed as is.
|
||||
* - For long options, if a value is required, the string after the equal sign
|
||||
* or the next argument will be used as the value ("--define=Value" or
|
||||
* "--define Value").
|
||||
* - For short options, if a value is required, the string after the option
|
||||
* letter or the next argument will be used as the value ("-DValue" or
|
||||
* "-D Value").
|
||||
*
|
||||
* Options array should have last element filled with zeros.
|
||||
*
|
||||
* \param argc Arguments count
|
||||
* \param argv Arguments array
|
||||
* \param options Options array pointer
|
||||
* \param callback Callback function
|
||||
* \param data Callback data
|
||||
*
|
||||
* \return On success, returns zero value.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_ArgsParse(int argc,
|
||||
char **argv,
|
||||
BH_ArgsOption *options,
|
||||
@@ -57,12 +31,6 @@ int BH_ArgsParse(int argc,
|
||||
void *data);
|
||||
|
||||
|
||||
/**
|
||||
* Prints documentation for \a options (with specified \a padding).
|
||||
*
|
||||
* \param options Options array pointer
|
||||
* \param padding Padding
|
||||
*/
|
||||
void BH_ArgsHelp(BH_ArgsOption *options,
|
||||
int padding);
|
||||
|
||||
|
||||
@@ -8,215 +8,82 @@
|
||||
typedef struct BH_Hashmap BH_Hashmap;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the new hashmap with specified \a equal and \a hash callbacks.
|
||||
*
|
||||
* \param equal Comparision function
|
||||
* \param hash Key hash function
|
||||
*
|
||||
* \return On success, returns hashmap pointer.
|
||||
* \return On failure, returns a null pointer.
|
||||
*/
|
||||
|
||||
BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal,
|
||||
BH_HashCallback hash);
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*/
|
||||
|
||||
void BH_HashmapFree(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*/
|
||||
|
||||
void BH_HashmapClear(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Reserves space for \a size amount of elements in the \a hashmap.
|
||||
*
|
||||
* This function can both expand and shrink the available space in hashmap.
|
||||
* This function takes into account current hashmap load factor.
|
||||
*
|
||||
* \param hashmap Hahsmap pointer
|
||||
* \param size Capacity
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \note Actual hashmap capacity can be bigger then requested.
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_HashmapReserve(BH_Hashmap *hashmap,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the pair \a key \a value pair into the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param key Key
|
||||
* \param value Value
|
||||
*
|
||||
* \note This function allows duplicates to be inserted.
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_HashmapInsert(BH_Hashmap *hashmap,
|
||||
void *key,
|
||||
void *value);
|
||||
|
||||
|
||||
/**
|
||||
* Removes value from the \a hashmap by \a key.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param key Key
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \note If hashmap contains several elements with the same key, this function
|
||||
* will remove only one key-value pair.
|
||||
*/
|
||||
|
||||
void BH_HashmapRemove(BH_Hashmap *hashmap,
|
||||
void *key);
|
||||
|
||||
|
||||
/**
|
||||
* Returns \a value from the \a hashmap by \a key.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param key Key
|
||||
* \param value Value (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_HashmapAt(BH_Hashmap *hashmap,
|
||||
void *key,
|
||||
void **value);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the \a hashmap is empty.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*
|
||||
* \return If hashmap is empty, returns non-zero value
|
||||
* \return If hashmap is not empty, returns zero
|
||||
*/
|
||||
|
||||
int BH_HashmapEmpty(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*
|
||||
* \return Returns the size of the hashmap.
|
||||
*/
|
||||
|
||||
size_t BH_HashmapSize(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the capacity of the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*
|
||||
* \return Returns the capacity of the hashmap.
|
||||
*/
|
||||
|
||||
size_t BH_HashmapCapacity(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the load factor of the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
*
|
||||
* \return Returns the load factor of the hashmap.
|
||||
*/
|
||||
|
||||
float BH_HashmapFactor(BH_Hashmap *hashmap);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the load \a factor of the \a hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param factor Load factor
|
||||
*
|
||||
* \note New load factor will be applied on the next reserve/insert operation.
|
||||
*/
|
||||
|
||||
void BH_HashmapSetFactor(BH_Hashmap *hashmap,
|
||||
float factor);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the iterator to the element in the \a hashmap by \a key.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return On success, returns iterator value.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*
|
||||
* \note If hashmap contains several elements with the same key, this function
|
||||
* will return iterator to one of them
|
||||
*/
|
||||
|
||||
void *BH_HashmapIterAt(BH_Hashmap *hashmap,
|
||||
void *key);
|
||||
|
||||
|
||||
/**
|
||||
* Returns next element \a iter in the \a hashmap.
|
||||
*
|
||||
* If \a iter is NULL pointer, then this function will return iter to the
|
||||
* first element of the hashmap.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return On success, returns new iterator value for the next element.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
void *BH_HashmapIterNext(BH_Hashmap *hashmap,
|
||||
void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Removes key-value from the \a hashmap pointed by \a iter.
|
||||
*
|
||||
* \param hashmap Hashmap pointer
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*/
|
||||
|
||||
void BH_HashmapIterRemove(BH_Hashmap *hashmap,
|
||||
void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Returns key, pointed by the \a iter.
|
||||
*
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return Returns key.
|
||||
*/
|
||||
|
||||
void *BH_HashmapIterKey(void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Returns value, pointed by the \a iter.
|
||||
*
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return Returns value.
|
||||
*/
|
||||
|
||||
void *BH_HashmapIterValue(void *iter);
|
||||
|
||||
|
||||
|
||||
154
include/BH/IO.h
154
include/BH/IO.h
@@ -81,231 +81,77 @@ typedef struct BH_IOSeekInfo
|
||||
} BH_IOSeekInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an input/output device representing a file at the given \a path.
|
||||
*
|
||||
* \param path File path
|
||||
* \param mode Open mode
|
||||
* \param result Result code
|
||||
*
|
||||
* \return On success, returns IO device pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
BH_IO *BH_FileNew(const char *path,
|
||||
int mode,
|
||||
int *result);
|
||||
|
||||
|
||||
/**
|
||||
* Creates an input/output deivce that buffers access to other \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param size Buffer size
|
||||
* \param result Result code
|
||||
*
|
||||
* \return On success, returns IO device pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
BH_IO *BH_BufferNew(BH_IO *device,
|
||||
size_t size,
|
||||
int *result);
|
||||
|
||||
|
||||
/**
|
||||
* Creates an input/output devices that access memory buffer.
|
||||
*
|
||||
* \param data Buffer pointer
|
||||
* \param size Buffer size
|
||||
* \param result Result code
|
||||
*
|
||||
* \return On success, returns IO device pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
BH_IO *BH_BytesNew(char *data,
|
||||
size_t size,
|
||||
int *result);
|
||||
|
||||
|
||||
/**
|
||||
* Destroys the input/output \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
*/
|
||||
void BH_IOFree(BH_IO *device);
|
||||
|
||||
|
||||
/**
|
||||
* Reads up to \a size bytes from the \a device into \a buffer.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param buffer Buffer pointer
|
||||
* \param size Buffer size
|
||||
* \param actual Bytes read (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IORead(BH_IO *device,
|
||||
char *buffer,
|
||||
size_t size,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Writes up to \a size bytes to the \a device from \a buffer.
|
||||
*
|
||||
* \param io IO device pointer
|
||||
* \param buffer Buffer pointer
|
||||
* \param size Buffer size
|
||||
* \param actual Bytes written (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOWrite(BH_IO *io,
|
||||
const char *buffer,
|
||||
size_t size,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Manupulates an input/output \a device with specific \a op and and \a arg.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param op Operation
|
||||
* \param arg Argument
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOCtl(BH_IO *device,
|
||||
int op,
|
||||
void *arg);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if an input/output \a device supports specific \a op.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param op Operation
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOCap(BH_IO *device,
|
||||
int op);
|
||||
|
||||
|
||||
/**
|
||||
* Peeks up to \a size bytes from the \a device into \a buffer.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param buffer Buffer pointer
|
||||
* \param size Buffer size
|
||||
* \param actial Bytes peeked (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOPeek(BH_IO *device,
|
||||
char *buffer,
|
||||
size_t size,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Tells current \a offset in the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param offset Position
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOTell(BH_IO *device,
|
||||
int64_t *offset);
|
||||
|
||||
|
||||
/**
|
||||
* Seeks to specified \a offset and \a whence in the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param offset Position
|
||||
* \param whence Direction
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOSeek(BH_IO *device,
|
||||
int64_t offset,
|
||||
int whence);
|
||||
|
||||
|
||||
/**
|
||||
* Flushes the internal buffers of the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOFlush(BH_IO *device);
|
||||
|
||||
|
||||
/**
|
||||
* Returns total or available size of the \a device.
|
||||
*
|
||||
* \param device IO pointer
|
||||
* \param size Available/total size
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOSize(BH_IO *device,
|
||||
int64_t *size);
|
||||
|
||||
|
||||
/**
|
||||
* Returns flags of the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
* \param flags Flags
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOFlags(BH_IO *device,
|
||||
int *flags);
|
||||
|
||||
|
||||
/**
|
||||
* Returns error flag of the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
*
|
||||
* \return Returns error flag.
|
||||
*/
|
||||
int BH_IOError(BH_IO *device);
|
||||
|
||||
|
||||
/**
|
||||
* Returns end-of-file flag of the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
*
|
||||
* \return Returns end-of-file flag.
|
||||
*/
|
||||
int BH_IOEndOfFile(BH_IO *device);
|
||||
|
||||
|
||||
/**
|
||||
* Clears errors of the \a device.
|
||||
*
|
||||
* \param device IO device pointer
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
int BH_IOClear(BH_IO *device);
|
||||
|
||||
|
||||
|
||||
2148
include/BH/Math.h
2148
include/BH/Math.h
File diff suppressed because it is too large
Load Diff
37
include/BH/Math/Box2f.h
Normal file
37
include/BH/Math/Box2f.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef BH_MATH_BOX2F_H
|
||||
#define BH_MATH_BOX2F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Box2fUnion(const float aMin[2],
|
||||
const float aMax[2],
|
||||
const float bMin[2],
|
||||
const float bMax[2],
|
||||
float outMin[2],
|
||||
float outMax[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Box2fIntersect(const float aMin[2],
|
||||
const float aMax[2],
|
||||
const float bMin[2],
|
||||
const float bMax[2],
|
||||
float outMin[2],
|
||||
float outMax[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Box2fContains(const float aMin[2],
|
||||
const float aMax[2],
|
||||
const float point[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Box2fEnclose(const float *points,
|
||||
size_t size,
|
||||
float outMin[2],
|
||||
float outMax[2]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_BOX2F_H */
|
||||
37
include/BH/Math/Box3f.h
Normal file
37
include/BH/Math/Box3f.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef BH_MATH_BOX3F_H
|
||||
#define BH_MATH_BOX3F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Box3fUnion(const float aMin[3],
|
||||
const float aMax[3],
|
||||
const float bMin[3],
|
||||
const float bMax[3],
|
||||
float outMin[3],
|
||||
float outMax[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Box3fIntersect(const float aMin[3],
|
||||
const float aMax[3],
|
||||
const float bMin[3],
|
||||
const float bMax[3],
|
||||
float outMin[3],
|
||||
float outMax[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Box3fContains(const float aMin[3],
|
||||
const float aMax[3],
|
||||
const float point[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Box3fEnclose(const float *points,
|
||||
size_t size,
|
||||
float outMin[3],
|
||||
float outMax[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_BOX3F_H */
|
||||
23
include/BH/Math/Line.h
Normal file
23
include/BH/Math/Line.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef BH_MATH_LINE_H
|
||||
#define BH_MATH_LINE_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
int BH_LineFromPoints(const float a[2],
|
||||
const float b[2],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
float BH_LineDistance(const float line[3],
|
||||
const float point[2]);
|
||||
|
||||
|
||||
|
||||
void BH_LineClosestPoint(const float line[3],
|
||||
const float point[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_LINE_H */
|
||||
81
include/BH/Math/Mat3f.h
Normal file
81
include/BH/Math/Mat3f.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef BH_MATH_MAT3F_H
|
||||
#define BH_MATH_MAT3F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Mat3fIdentity(float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fAdd(const float a[9],
|
||||
const float b[9],
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fSub(const float a[9],
|
||||
const float b[9],
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fMul(const float a[9],
|
||||
const float b[9],
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fScale(const float a[9],
|
||||
float b,
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fTranspose(const float in[9],
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
float BH_Mat3fTrace(const float in[9]);
|
||||
|
||||
|
||||
|
||||
float BH_Mat3fDet(const float in[9]);
|
||||
|
||||
|
||||
|
||||
int BH_Mat3fInverse(const float in[9],
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fFromScale(float x,
|
||||
float y,
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fFromTranslation(float x,
|
||||
float y,
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fFromRotation(float angle,
|
||||
float out[9]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fApplyVec3f(float a[9],
|
||||
float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat3fApplyVec2f(float a[9],
|
||||
float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_MAT3F */
|
||||
136
include/BH/Math/Mat4f.h
Normal file
136
include/BH/Math/Mat4f.h
Normal file
@@ -0,0 +1,136 @@
|
||||
#ifndef BH_MATH_MAT4F_H
|
||||
#define BH_MATH_MAT4F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Mat4fIdentity(float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fAdd(const float a[16],
|
||||
const float b[16],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fSub(const float a[16],
|
||||
const float b[16],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fMul(const float a[16],
|
||||
const float b[16],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fScale(const float a[16],
|
||||
float b,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fTranspose(const float in[16],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
float BH_Mat4fTrace(const float in[16]);
|
||||
|
||||
|
||||
|
||||
float BH_Mat4fDet(const float in[16]);
|
||||
|
||||
|
||||
|
||||
int BH_Mat4fInverse(const float in[16],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromScale(float x,
|
||||
float y,
|
||||
float z,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromTranslation(float x,
|
||||
float y,
|
||||
float z,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromRotationX(float angle,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromRotationY(float angle,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromRotationZ(float angle,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromAxis(const float axis[3],
|
||||
float angle,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromEuler(float roll,
|
||||
float pitch,
|
||||
float yaw,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromQuat4f(const float in[4],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromOrtho(float xMin,
|
||||
float xMax,
|
||||
float yMin,
|
||||
float yMax,
|
||||
float zMin,
|
||||
float zMax,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromFrustum(float fov,
|
||||
float aspect,
|
||||
float zMin,
|
||||
float zMax,
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fFromLookAt(const float position[3],
|
||||
const float at[3],
|
||||
const float up[3],
|
||||
float out[16]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fApplyVec4f(const float a[16],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Mat4fApplyVec3f(const float a[16],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_MAT4F */
|
||||
17
include/BH/Math/Misc.h
Normal file
17
include/BH/Math/Misc.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef BH_MATH_MISC_H
|
||||
#define BH_MATH_MISC_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
float BH_Lerpf(float a, float b, float t);
|
||||
|
||||
|
||||
|
||||
void BH_Triangle3fBarycentric(const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
const float point[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_MISC */
|
||||
24
include/BH/Math/Plane.h
Normal file
24
include/BH/Math/Plane.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef BH_MATH_PLANE_H
|
||||
#define BH_MATH_PLANE_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
int BH_PlaneFromPoints(const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
float BH_PlaneDistance(const float plane[4],
|
||||
const float point[3]);
|
||||
|
||||
|
||||
|
||||
void BH_PlaneClosestPoint(const float plane[4],
|
||||
const float point[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_PLANE_H */
|
||||
105
include/BH/Math/Quat.h
Normal file
105
include/BH/Math/Quat.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef BH_MATH_QUAT_H
|
||||
#define BH_MATH_QUAT_H
|
||||
|
||||
#include "../Common.h"
|
||||
#include "Vec4f.h"
|
||||
|
||||
|
||||
#define BH_Quat4fAdd(a, b, out) \
|
||||
BH_Vec4fAdd(a, b, out)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fSub(a, b, out) \
|
||||
BH_Vec4fSub(a, b, out)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fScale(a, b, out) \
|
||||
BH_Vec4fScale(a, b, out)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fNegate(in, out) \
|
||||
BH_Vec4fNegate(in, out)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fDot(a, b) \
|
||||
BH_Vec4fDot(a, b)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fLength(in) \
|
||||
BH_Vec4fLength(in)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fNormal(in, out) \
|
||||
BH_Vec4fNormal(in, out)
|
||||
|
||||
|
||||
|
||||
#define BH_Quat4fLerp(a, b, t, out) \
|
||||
BH_Vec4fLerp(a, b, t, out)
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fIdentity(float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fConjugate(const float in[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fInverse(const float in[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fMul(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fSlerp(const float a[4],
|
||||
const float b[4],
|
||||
float t,
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fFromEuler(float roll,
|
||||
float pitch,
|
||||
float yaw,
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fFromAxis(const float axis[3],
|
||||
float angle,
|
||||
float out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fToEuler(const float in[4],
|
||||
float *roll,
|
||||
float *pitch,
|
||||
float *yaw);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fToAxis(const float in[4],
|
||||
float axis[3],
|
||||
float *angle);
|
||||
|
||||
|
||||
|
||||
void BH_Quat4fToMat4f(const float in[4],
|
||||
float out[16]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_QUAT */
|
||||
76
include/BH/Math/Ray2f.h
Normal file
76
include/BH/Math/Ray2f.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef BH_MATH_RAY2F_H
|
||||
#define BH_MATH_RAY2F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
int BH_Ray2fIntersectLine(const float start[2],
|
||||
const float direction[2],
|
||||
const float line[3],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Ray2fIntersectTime(const float aStart[2],
|
||||
const float aDirection[2],
|
||||
const float bStart[2],
|
||||
const float bDirection[2],
|
||||
float *time1,
|
||||
float *time2);
|
||||
|
||||
|
||||
|
||||
int BH_Ray2fIntersectRay(const float aStart[2],
|
||||
const float aDirection[2],
|
||||
const float bStart[2],
|
||||
const float bDirection[2],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Ray2fIntersectSegment(const float aStart[2],
|
||||
const float aDirection[2],
|
||||
const float bStart[2],
|
||||
const float bEnd[2],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment2fIntersectLine(const float start[2],
|
||||
const float end[2],
|
||||
const float line[3],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment2fIntersectSegment(const float aStart[2],
|
||||
const float aEnd[2],
|
||||
const float bStart[2],
|
||||
const float bEnd[2],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Ray2fIntersectBox2f(const float aStart[2],
|
||||
const float aDirection[2],
|
||||
const float bMin[2],
|
||||
const float bMax[2],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment2fIntersectBox2f(const float aStart[2],
|
||||
const float aEnd[2],
|
||||
const float bMin[2],
|
||||
const float bMax[2],
|
||||
float *t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_RAY2F_H */
|
||||
58
include/BH/Math/Ray3f.h
Normal file
58
include/BH/Math/Ray3f.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef BH_MATH_RAY3F_H
|
||||
#define BH_MATH_RAY3F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
int BH_Ray3fIntersectPlane(const float start[3],
|
||||
const float direction[3],
|
||||
const float plane[4],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Ray3fIntersectTriangle(const float start[3],
|
||||
const float direction[3],
|
||||
const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment3fIntersectPlane(const float start[3],
|
||||
const float end[3],
|
||||
const float plane[4],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment3fIntersectTriangle(const float start[3],
|
||||
const float end[3],
|
||||
const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
int BH_Ray3fIntersectBox3f(const float aStart[3],
|
||||
const float aDirection[3],
|
||||
const float bMin[3],
|
||||
const float bMax[3],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
int BH_Segment3fIntersectBox3f(const float aStart[3],
|
||||
const float aEnd[3],
|
||||
const float bMin[3],
|
||||
const float bMax[3],
|
||||
float *t,
|
||||
float out[3]);
|
||||
|
||||
#endif /* BH_MATH_RAY3F_H */
|
||||
100
include/BH/Math/Vec2f.h
Normal file
100
include/BH/Math/Vec2f.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef BH_MATH_VEC2F_H
|
||||
#define BH_MATH_VEC2F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
void BH_Vec2fAdd(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fSub(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fMul(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fScale(const float a[2],
|
||||
float b,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fMulAdd(const float a[2],
|
||||
const float b[2],
|
||||
const float c[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fNegate(const float in[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec2fDot(const float a[2],
|
||||
const float b[2]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec2fCross(const float a[2],
|
||||
const float b[2]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec2fLength(const float in[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fNormal(const float in[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec2fNormalEx(const float in[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fMin(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fMax(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fLerp(const float a[2],
|
||||
const float b[2],
|
||||
float t,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fProject(const float a[2],
|
||||
const float b[2],
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2fBarycentric(const float a[2],
|
||||
const float b[2],
|
||||
const float c[2],
|
||||
float v,
|
||||
float w,
|
||||
float out[2]);
|
||||
|
||||
|
||||
|
||||
#endif /* BH_MATH_VEC2F */
|
||||
52
include/BH/Math/Vec2i.h
Normal file
52
include/BH/Math/Vec2i.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef BH_MATH_VEC2I_H
|
||||
#define BH_MATH_VEC2I_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
void BH_Vec2iAdd(const int a[2],
|
||||
const int b[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iSub(const int a[2],
|
||||
const int b[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iMul(const int a[2],
|
||||
const int b[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iScale(const int a[2],
|
||||
int b,
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iMulAdd(const int a[2],
|
||||
const int b[2],
|
||||
const int c[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iNegate(const int in[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iMin(const int a[2],
|
||||
const int b[2],
|
||||
int out[2]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec2iMax(const int a[2],
|
||||
const int b[2],
|
||||
int out[2]);
|
||||
|
||||
#endif /* BH_MATH_VEC2I */
|
||||
100
include/BH/Math/Vec3f.h
Normal file
100
include/BH/Math/Vec3f.h
Normal file
@@ -0,0 +1,100 @@
|
||||
#ifndef BH_MATH_VEC3F_H
|
||||
#define BH_MATH_VEC3F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fAdd(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fSub(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fMul(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fScale(const float a[3],
|
||||
float b,
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fMulAdd(const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fNegate(const float in[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec3fDot(const float a[3],
|
||||
const float b[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fCross(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec3fLength(const float in[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fNormal(const float in[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
float BH_Vec3fNormalEx(const float in[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fMin(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fMax(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3fLerp(const float a[3],
|
||||
const float b[3],
|
||||
float t,
|
||||
float out[3]);
|
||||
|
||||
|
||||
void BH_Vec3fProject(const float a[3],
|
||||
const float b[3],
|
||||
float out[3]);
|
||||
|
||||
|
||||
void BH_Vec3fBarycentric(const float a[3],
|
||||
const float b[3],
|
||||
const float c[3],
|
||||
float v,
|
||||
float w,
|
||||
float out[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_VEC3F_H */
|
||||
53
include/BH/Math/Vec3i.h
Normal file
53
include/BH/Math/Vec3i.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef BH_MATH_VEC3I_H
|
||||
#define BH_MATH_VEC3I_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
void BH_Vec3iAdd(const int a[3],
|
||||
const int b[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iSub(const int a[3],
|
||||
const int b[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iMul(const int a[3],
|
||||
const int b[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iScale(const int a[3],
|
||||
int b,
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iMulAdd(const int a[3],
|
||||
const int b[3],
|
||||
const int c[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iNegate(const int in[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iMin(const int a[3],
|
||||
const int b[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec3iMax(const int a[3],
|
||||
const int b[3],
|
||||
int out[3]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_VEC3I */
|
||||
80
include/BH/Math/Vec4f.h
Normal file
80
include/BH/Math/Vec4f.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef BH_MATH_VEC4F_H
|
||||
#define BH_MATH_VEC4F_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Vec4fAdd(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fSub(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fMul(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fScale(const float a[4],
|
||||
float b,
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fMulAdd(const float a[4],
|
||||
const float b[4],
|
||||
const float c[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fNegate(const float in[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
float BH_Vec4fDot(const float a[4],
|
||||
const float b[4]);
|
||||
|
||||
|
||||
float BH_Vec4fLength(const float in[4]);
|
||||
|
||||
|
||||
void BH_Vec4fNormal(const float in[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
float BH_Vec4fNormalEx(const float in[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fMin(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fMax(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fLerp(const float a[4],
|
||||
const float b[4],
|
||||
float t,
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fProject(const float a[4],
|
||||
const float b[4],
|
||||
float out[4]);
|
||||
|
||||
|
||||
void BH_Vec4fBarycentric(const float a[4],
|
||||
const float b[4],
|
||||
const float c[4],
|
||||
float v,
|
||||
float w,
|
||||
float out[4]);
|
||||
|
||||
#endif /* BH_MATH_VEC4F */
|
||||
54
include/BH/Math/Vec4i.h
Normal file
54
include/BH/Math/Vec4i.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef BH_MATH_VEC4I_H
|
||||
#define BH_MATH_VEC4I_H
|
||||
|
||||
#include "../Common.h"
|
||||
|
||||
|
||||
void BH_Vec4iAdd(const int a[4],
|
||||
const int b[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iSub(const int a[4],
|
||||
const int b[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iMul(const int a[4],
|
||||
const int b[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iScale(const int a[4],
|
||||
int b,
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iMulAdd(const int a[4],
|
||||
const int b[4],
|
||||
const int c[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iNegate(const int in[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iMin(const int a[4],
|
||||
const int b[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
|
||||
void BH_Vec4iMax(const int a[4],
|
||||
const int b[4],
|
||||
int out[4]);
|
||||
|
||||
|
||||
#endif /* BH_MATH_VEC4I */
|
||||
@@ -8,138 +8,55 @@
|
||||
typedef struct BH_Queue BH_Queue;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the new queue.
|
||||
*
|
||||
* \return On success, returns the queue pointer.
|
||||
* \return On failure, returns a null pointer.
|
||||
*/
|
||||
|
||||
BH_Queue *BH_QueueNew(void);
|
||||
|
||||
|
||||
/**
|
||||
* Frees the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*/
|
||||
|
||||
void BH_QueueFree(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Clears the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*/
|
||||
|
||||
void BH_QueueClear(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Reserves the space for \a size amount of value in the \a queue.
|
||||
*
|
||||
* This function can both expand and shrink the available space in queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
* \param size Capacity
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
* \note Actual queue capacity can be bigger then requested.
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_QueueReserve(BH_Queue *queue,
|
||||
size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Inserts the \a value into the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
* \param value Value
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_QueueInsert(BH_Queue *queue,
|
||||
void *value);
|
||||
|
||||
|
||||
/**
|
||||
* Removes front value from the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*
|
||||
* \note Calling this function will invalidate iterators.
|
||||
*/
|
||||
|
||||
void BH_QueueRemove(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns front \a value from the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
* \param value Value
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_QueueFront(BH_Queue *queue,
|
||||
void **value);
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the \a queue is empty.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*
|
||||
* \return If queue is empty, returns non-zero value
|
||||
* \return If queue is not empty, returns zero
|
||||
*/
|
||||
|
||||
int BH_QueueEmpty(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*
|
||||
* \return Returns the size of the queue.
|
||||
*/
|
||||
|
||||
size_t BH_QueueSize(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the capacity of the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
*
|
||||
* \return Returns the capacity of the queue.
|
||||
*/
|
||||
|
||||
size_t BH_QueueCapacity(BH_Queue *queue);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the iterator to the next element in the \a queue.
|
||||
*
|
||||
* \param queue Queue pointer
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return On success, returns new iterator value for the next element.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
void *BH_QueueIterNext(BH_Queue *queue,
|
||||
void *iter);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the value, pointed by the \a iter.
|
||||
*
|
||||
* \param iter Iterator
|
||||
*
|
||||
* \return Returns value, pointed by iterator.
|
||||
*/
|
||||
|
||||
void *BH_QueueIterValue(void *iter);
|
||||
|
||||
|
||||
|
||||
@@ -5,31 +5,7 @@
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
/**
|
||||
* Formats a double \a value into a zero terminated \a string (limited by
|
||||
* \a size) using the provided \a format and \a precision and stores \a actual
|
||||
* length (if it's provided).
|
||||
*
|
||||
* Formats supported:
|
||||
* - Scientific or fixed format ('g' or 'G')
|
||||
* - Scientific format ('e' or 'E')
|
||||
* - Fixed format ('f' or 'F')
|
||||
*
|
||||
* If precision is negative, string will contain shortest representation of the
|
||||
* double that can round-trip (i.e. converted back without information loss).
|
||||
*
|
||||
* This function follows IEEE 754 round to even to break ties during rounding.
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param format Format
|
||||
* \param precision Precision
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromDouble(char *string,
|
||||
size_t size,
|
||||
double value,
|
||||
@@ -38,19 +14,7 @@ int BH_StringFromDouble(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats signed 8-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt8s(char *string,
|
||||
size_t size,
|
||||
int8_t value,
|
||||
@@ -58,19 +22,7 @@ int BH_StringFromInt8s(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats signed 16-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt16s(char *string,
|
||||
size_t size,
|
||||
int16_t value,
|
||||
@@ -78,19 +30,7 @@ int BH_StringFromInt16s(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats signed 32-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt32s(char *string,
|
||||
size_t size,
|
||||
int32_t value,
|
||||
@@ -98,19 +38,7 @@ int BH_StringFromInt32s(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats signed 64-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt64s(char *string,
|
||||
size_t size,
|
||||
int64_t value,
|
||||
@@ -118,19 +46,7 @@ int BH_StringFromInt64s(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats unsigned 8-bit \a value into a \a string (limited by \a size) with
|
||||
* provides \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt8u(char *string,
|
||||
size_t size,
|
||||
uint8_t value,
|
||||
@@ -138,19 +54,7 @@ int BH_StringFromInt8u(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats unsigned 16-bit \a value into a \a string (limited by \a size) with
|
||||
* provides \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt16u(char *string,
|
||||
size_t size,
|
||||
uint16_t value,
|
||||
@@ -158,19 +62,7 @@ int BH_StringFromInt16u(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats unsigned 32-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt32u(char *string,
|
||||
size_t size,
|
||||
uint32_t value,
|
||||
@@ -178,19 +70,7 @@ int BH_StringFromInt32u(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Formats unsigned 64-bit \a value into a \a string (limited by \a size) with
|
||||
* provided \a base and stores \a actual length (if it's provided).
|
||||
*
|
||||
* \param string String
|
||||
* \param size String size
|
||||
* \param value Value
|
||||
* \param base Base
|
||||
* \param actual Written size (optional)
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_StringFromInt64u(char *string,
|
||||
size_t size,
|
||||
uint64_t value,
|
||||
@@ -198,385 +78,58 @@ int BH_StringFromInt64u(char *string,
|
||||
size_t *actual);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing double value in fixed or scientific format,
|
||||
* optionally reports \a size amount of characters consumed and returns
|
||||
* the result value.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
*
|
||||
* \return On success, returns parsed double value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
double BH_StringToDouble(const char *string,
|
||||
size_t *size);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
int8_t BH_StringToInt8s(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
int16_t BH_StringToInt16s(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
int32_t BH_StringToInt32s(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
int64_t BH_StringToInt64s(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
uint8_t BH_StringToInt8u(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
uint16_t BH_StringToInt16u(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
uint32_t BH_StringToInt32u(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Reads \a string containing value in specified \a base, optionally reports
|
||||
* \a size amount of characters consumed and returns the result value.
|
||||
*
|
||||
* If base is 0, function will automaticly detect input base by the prefix:
|
||||
* - Base 2 if prefix is 0b
|
||||
* - Base 8 if prefix is 0
|
||||
* - Base 16 if prefix is 0x
|
||||
* - Base 10 in other cases
|
||||
*
|
||||
* \param string String
|
||||
* \param size Optional size
|
||||
* \param base Base
|
||||
*
|
||||
* \return On success, returns parsed value.
|
||||
* \return On failure, returns zero.
|
||||
*/
|
||||
|
||||
uint64_t BH_StringToInt64u(const char *string,
|
||||
size_t *size,
|
||||
int base);
|
||||
|
||||
|
||||
/**
|
||||
* Converts unicode \a unit codepoint to lowercase.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return On success, returns lowercased codepoint.
|
||||
* \return On failure, returns codepoint without a change.
|
||||
*/
|
||||
uint32_t BH_UnicodeLower(uint32_t unit);
|
||||
|
||||
|
||||
/**
|
||||
* Converts unicode \a unit codepoint to uppercase.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return On success, returns uppercased codepoint.
|
||||
* \return On failure, returns codepoint without a change.
|
||||
*/
|
||||
uint32_t BH_UnicodeUpper(uint32_t unit);
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a UTF-8 sequence from a \a string (with the given \a size), storing
|
||||
* the result in a \a unit and returning the number of bytes read.
|
||||
*
|
||||
* Invalid UTF-8 sequences result in a -1 codepoint.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Size
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return Returns readed amount of bytes
|
||||
* \return Returns zero if the string contains only a portion of the sequence.
|
||||
*/
|
||||
size_t BH_UnicodeDecodeUtf8(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
/**
|
||||
* Encodes a Unicode \a unit to UTF-8 encoded bytes (stored in a \a string)
|
||||
* and returns the number of bytes written.
|
||||
*
|
||||
* String are assumed to have 4 bytes of space.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
* \param string String
|
||||
*
|
||||
* \return On success, returns written amount of bytes.
|
||||
* \return Of faulure, returns zero.
|
||||
*/
|
||||
size_t BH_UnicodeEncodeUtf8(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a UTF-16LE sequence from a \a string (with the given \a size),
|
||||
* storing the result in a \a unit and returning the number of bytes read.
|
||||
*
|
||||
* Invalid UTF-16 sequences result in a -1 codepoint.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Size
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return Returns readed amount of bytes
|
||||
* \return Returns zero if the string contains only a portion of the sequence.
|
||||
*/
|
||||
size_t BH_UnicodeDecodeUtf16LE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a UTF-16BE sequence from a \a string (with the given \a size),
|
||||
* storing the result in a \a unit and returning the number of bytes read.
|
||||
*
|
||||
* Invalid UTF-16 sequences result in a -1 codepoint.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Size
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return Returns readed amount of bytes
|
||||
* \return Returns zero if the string contains only a portion of the sequence.
|
||||
*/
|
||||
size_t BH_UnicodeDecodeUtf16BE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
/**
|
||||
* Encodes a Unicode \a unit to UTF-16LE encoded bytes (stored in a \a string)
|
||||
* and returns the number of bytes written.
|
||||
*
|
||||
* String are assumed to have 4 bytes of space.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
* \param string String
|
||||
*
|
||||
* \return On success, returns written amount of bytes.
|
||||
* \return Of faulure, returns zero.
|
||||
*/
|
||||
size_t BH_UnicodeEncodeUtf16LE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
/**
|
||||
* Encodes a Unicode \a unit to UTF-16BE encoded bytes (stored in a \a string)
|
||||
* and returns the number of bytes written.
|
||||
*
|
||||
* String are assumed to have 4 bytes of space.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
* \param string String
|
||||
*
|
||||
* \return On success, returns written amount of bytes.
|
||||
* \return Of faulure, returns zero.
|
||||
*/
|
||||
size_t BH_UnicodeEncodeUtf16BE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a UTF-32LE symbol from a \a string (with the given \a size),
|
||||
* storing the result in a \a unit and returning the number of bytes read.
|
||||
*
|
||||
* Invalid UTF-32 result in a -1 codepoint.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Size
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return Returns readed amount of bytes
|
||||
* \return Returns zero if the string contains only a portion of the sequence.
|
||||
*/
|
||||
size_t BH_UnicodeDecodeUtf32LE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
/**
|
||||
* Decodes a UTF-32BE symbol from a \a string (with the given \a size),
|
||||
* storing the result in a \a unit and returning the number of bytes read.
|
||||
*
|
||||
* Invalid UTF-32 result in a -1 codepoint.
|
||||
*
|
||||
* \param string String
|
||||
* \param size Size
|
||||
* \param unit Codepoint
|
||||
*
|
||||
* \return Returns readed amount of bytes
|
||||
* \return Returns zero if the string contains only a portion of the sequence.
|
||||
*/
|
||||
size_t BH_UnicodeDecodeUtf32BE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
/**
|
||||
* Encodes a Unicode \a unit to UTF-32LE encoded bytes (stored in a \a string)
|
||||
* and returns the number of bytes written.
|
||||
*
|
||||
* String are assumed to have 4 bytes of space.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
* \param string String
|
||||
*
|
||||
* \return On success, returns written amount of bytes.
|
||||
* \return Of faulure, returns zero.
|
||||
*/
|
||||
size_t BH_UnicodeEncodeUtf32LE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
/**
|
||||
* Encodes a Unicode \a unit to UTF-32LE encoded bytes (stored in a \a string)
|
||||
* and returns the number of bytes written.
|
||||
*
|
||||
* String are assumed to have 4 bytes of space.
|
||||
*
|
||||
* \param unit Codepoint
|
||||
* \param string String
|
||||
*
|
||||
* \return On success, returns written amount of bytes.
|
||||
* \return Of faulure, returns zero.
|
||||
*/
|
||||
size_t BH_UnicodeEncodeUtf32BE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
#endif /* BH_STRING_H */
|
||||
|
||||
@@ -16,284 +16,113 @@ typedef struct BH_Condition BH_Condition;
|
||||
typedef int (*BH_ThreadCallback)(void *);
|
||||
|
||||
|
||||
/**
|
||||
* Creates new thread with specified \a stack size, thread \a callback
|
||||
* function and \a data.
|
||||
*
|
||||
* \param stack Stack size
|
||||
* \param callback Callback function
|
||||
* \param data User data
|
||||
*
|
||||
* \return On success, returns thread pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
BH_Thread *BH_ThreadNew(size_t stack,
|
||||
BH_ThreadCallback callback,
|
||||
void *data);
|
||||
|
||||
|
||||
/**
|
||||
* Joins the specified \a thread.
|
||||
*
|
||||
* \param thread Thread
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ThreadJoin(BH_Thread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Detaches the specified \a thread.
|
||||
*
|
||||
* \param thread Thread
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ThreadDetach(BH_Thread *thread);
|
||||
|
||||
|
||||
/**
|
||||
* Creates new mutex.
|
||||
*
|
||||
* \return On success, returns mutex pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
BH_Mutex *BH_MutexNew(void);
|
||||
|
||||
|
||||
/**
|
||||
* Frees the \a mutex.
|
||||
*
|
||||
* \param mutex Mutex
|
||||
*/
|
||||
|
||||
void BH_MutexFree(BH_Mutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Locks the \a mutex.
|
||||
*
|
||||
* \param mutex Mutex
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_MutexLock(BH_Mutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks the \a mutex.
|
||||
*
|
||||
* \param mutex Mutex
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_MutexUnlock(BH_Mutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Tries to lock the \a mutex.
|
||||
*
|
||||
* \param mutex Mutex
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_MutexLockTry(BH_Mutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Creates new semaphore.
|
||||
*
|
||||
* \param value Semaphore value
|
||||
*
|
||||
* \return On success, returns thread pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
BH_Semaphore *BH_SemaphoreNew(int value);
|
||||
|
||||
|
||||
/**
|
||||
* Frees the \a semaphore.
|
||||
*
|
||||
* \param semaphore Semaphore
|
||||
*/
|
||||
|
||||
void BH_SemaphoreFree(BH_Semaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Posts/increments the \a semaphore.
|
||||
*
|
||||
* \param semaphore Semaphore
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_SemaphorePost(BH_Semaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Waits/decrements the \a semaphore.
|
||||
*
|
||||
* \param semaphore Semaphore
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_SemaphoreWait(BH_Semaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Tries to wait/decrement the \a semaphore.
|
||||
*
|
||||
* \param semaphore Semaphore
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_SemaphoreWaitTry(BH_Semaphore *semaphore);
|
||||
|
||||
|
||||
/**
|
||||
* Waits/decrements the \a semaphore with \a timeout.
|
||||
*
|
||||
* If timeout occures, return code will be BH_TIMEOUT.
|
||||
*
|
||||
* \param semaphore Semaphore
|
||||
* \param timeout Timeout in milliseconds
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
|
||||
uint32_t timeout);
|
||||
|
||||
|
||||
/**
|
||||
* Creates new condition variable.
|
||||
*
|
||||
* \return On success, returns condition variable pointer.
|
||||
* \return On failure, returns NULL pointer.
|
||||
*/
|
||||
|
||||
BH_Condition *BH_ConditionNew(void);
|
||||
|
||||
|
||||
/**
|
||||
* Frees the \a condition variable.
|
||||
*
|
||||
* \param condition Condition
|
||||
*/
|
||||
|
||||
void BH_ConditionFree(BH_Condition *condition);
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks the \a mutex and waits for the \a condition variable.
|
||||
*
|
||||
* \param condition Condition variable
|
||||
* \param mutex Mutex
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ConditionWait(BH_Condition *condition,
|
||||
BH_Mutex *mutex);
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks the \a mutex and waits for the \a condition variable with \a timeout.
|
||||
*
|
||||
* If timeout occures, return code will be BH_TIMEOUT.
|
||||
*
|
||||
* \param condition Condition variable
|
||||
* \param mutex Mutex
|
||||
* \param timeout Timeout in milliseconds
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ConditionWaitFor(BH_Condition *condition,
|
||||
BH_Mutex *mutex,
|
||||
uint32_t timeout);
|
||||
|
||||
|
||||
/**
|
||||
* Signals the \a condition variable.
|
||||
*
|
||||
* \param condition Condition variable
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ConditionSignal(BH_Condition *condition);
|
||||
|
||||
|
||||
/**
|
||||
* Broadcasts the \a condition variable.
|
||||
*
|
||||
* \param condition Condition variable
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_ConditionBroadcast(BH_Condition *condition);
|
||||
|
||||
|
||||
/**
|
||||
* Locks the \a spinlock.
|
||||
*
|
||||
* \param lock Spinlock
|
||||
*/
|
||||
|
||||
void BH_SpinlockLock(int *lock);
|
||||
|
||||
|
||||
/**
|
||||
* Tries to lock the \a spinlock.
|
||||
*
|
||||
* \param lock Spinlock
|
||||
*
|
||||
* \return On success, returns zero.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_SpinlockLockTry(int *lock);
|
||||
|
||||
|
||||
/**
|
||||
* Unlocks the \a spinlock.
|
||||
*
|
||||
* \param lock Spinlock
|
||||
*/
|
||||
|
||||
void BH_SpinlockUnlock(int *lock);
|
||||
|
||||
|
||||
/**
|
||||
* Create new TSS/TLS slot index and destruction \a callback.
|
||||
*
|
||||
* \param callback Destruction callback
|
||||
*
|
||||
* \return On success, returns slot index.
|
||||
* \return On failure, returns error code.
|
||||
*/
|
||||
|
||||
int BH_TssCreate(BH_GenericCallback callback);
|
||||
|
||||
|
||||
/**
|
||||
* Reads the value associated with the TSS \a index.
|
||||
*
|
||||
* \param index TSS index
|
||||
*
|
||||
* \return Index value
|
||||
*/
|
||||
|
||||
void *BH_TssRead(int index);
|
||||
|
||||
|
||||
/**
|
||||
* Writes the \a value to the TSS \a index.
|
||||
*
|
||||
* \param index TSS index to
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_TssWrite(int index,
|
||||
void *value);
|
||||
|
||||
|
||||
70
include/BH/Unicode.h
Normal file
70
include/BH/Unicode.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#ifndef BH_UNICODE_H
|
||||
#define BH_UNICODE_H
|
||||
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
|
||||
uint32_t BH_UnicodeLower(uint32_t unit);
|
||||
|
||||
|
||||
|
||||
uint32_t BH_UnicodeUpper(uint32_t unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeDecodeUtf8(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeEncodeUtf8(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeDecodeUtf16LE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeDecodeUtf16BE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeEncodeUtf16LE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeEncodeUtf16BE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeDecodeUtf32LE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeDecodeUtf32BE(const char *string,
|
||||
size_t size,
|
||||
uint32_t *unit);
|
||||
|
||||
|
||||
|
||||
size_t BH_UnicodeEncodeUtf32LE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
size_t BH_UnicodeEncodeUtf32BE(uint32_t unit,
|
||||
char *string);
|
||||
|
||||
|
||||
#endif /* BH_UNICODE_H */
|
||||
@@ -12,255 +12,116 @@
|
||||
#define BH_FP_NEGATIVE 0x0020
|
||||
|
||||
|
||||
/**
|
||||
* Classifies the floating point \a value.
|
||||
*
|
||||
* \param value Value
|
||||
*
|
||||
* \return On success, returns BH_FP_NORMAL, BH_FP_ZERO, BH_FP_INFINITE,
|
||||
* BH_FP_NAN or BH_FP_NEGATIVE.
|
||||
*/
|
||||
|
||||
int BH_ClassifyDouble(double value);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 16-bit unsigned integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 16-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint16_t BH_Read16LEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 16-bit signed integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 16-bit signed integer value.
|
||||
*/
|
||||
|
||||
int16_t BH_Read16LEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 32-bit unsigned integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 32-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint32_t BH_Read32LEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 32-bit signed integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 32-bit signed integer value.
|
||||
*/
|
||||
|
||||
int32_t BH_Read32LEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 64-bit unsigned integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 64-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint64_t BH_Read64LEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 64-bit signed integer from the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 64-bit signed integer value.
|
||||
*/
|
||||
|
||||
int64_t BH_Read64LEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 16-bit unsigned integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 16-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint16_t BH_Read16BEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 16-bit signed integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 16-bit signed integer value.
|
||||
*/
|
||||
|
||||
int16_t BH_Read16BEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 32-bit unsigned integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 32-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint32_t BH_Read32BEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 32-bit signed integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 32-bit signed integer value.
|
||||
*/
|
||||
|
||||
int32_t BH_Read32BEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 64-bit unsigned integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 64-bit unsigned integer value.
|
||||
*/
|
||||
|
||||
uint64_t BH_Read64BEu(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Reads 64-bit signed integer from the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
*
|
||||
* \return Returns 64-bit signed integer value.
|
||||
*/
|
||||
|
||||
int64_t BH_Read64BEs(const char *buffer);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 16-bit unsigned integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write16LEu(char *buffer,
|
||||
uint16_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 16-bit signed integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write16LEs(char *buffer,
|
||||
int16_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 32-bit unsigned integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer\param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write32LEu(char *buffer,
|
||||
uint32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 32-bit signed integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write32LEs(char *buffer,
|
||||
int32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 64-bit unsigned integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write64LEu(char *buffer,
|
||||
uint64_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 64-bit signed integer to the \a buffer in little-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write64LEs(char *buffer,
|
||||
int64_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 16-bit unsigned integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write16BEu(char *buffer,
|
||||
uint16_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 16-bit signed integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write16BEs(char *buffer,
|
||||
int16_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 32-bit unsigned integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write32BEu(char *buffer,
|
||||
uint32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 32-bit signed integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write32BEs(char *buffer,
|
||||
int32_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 64-bit unsigned integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write64BEu(char *buffer,
|
||||
uint64_t value);
|
||||
|
||||
|
||||
/**
|
||||
* Writes 64-bit signed integer to the \a buffer in big-endian format.
|
||||
*
|
||||
* \param buffer Buffer pointer
|
||||
* \param value Value
|
||||
*/
|
||||
|
||||
void BH_Write64BEs(char *buffer,
|
||||
int64_t value);
|
||||
|
||||
|
||||
#endif /* BH_UTIL_H */
|
||||
#endif /* BH_UTIL_H */
|
||||
Reference in New Issue
Block a user