Initial work on physics
This commit is contained in:
21
util/assert.h
Normal file
21
util/assert.h
Normal file
@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
inline static void __panicf(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int ret = vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
#define ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) \
|
||||
__panicf("Assertion failed: " __FILE__ ":%d[%s]\n Expression: %s", __LINE__, __func__, #expr); \
|
||||
} while (0)
|
@ -36,6 +36,18 @@ void *vector_Push(vector_Vector *vec, const void *data) {
|
||||
return vec->data + vec->size - vec->objectSize;
|
||||
}
|
||||
|
||||
bool vector_Pop(vector_Vector *vec, void *out_data) {
|
||||
if (!vector_Size(vec))
|
||||
return false;
|
||||
|
||||
if (out_data)
|
||||
memcpy(out_data, vec->data + (vec->size - vec->objectSize), vec->objectSize);
|
||||
|
||||
vector_Resize(vec, vector_Size(vec) - 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void vector_Append(vector_Vector *vec, const void *data, uintptr_t n) {
|
||||
uintptr_t oldsize = vec->size, addsize = vec->objectSize * n;
|
||||
vector_Resize(vec, oldsize + addsize);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -27,6 +28,14 @@ void vector_Destroy(vector_Vector *vec);
|
||||
// Returns a pointer to data.
|
||||
void *vector_Push(vector_Vector *vec, const void *data);
|
||||
|
||||
// Pop pops one object at the back of the vector.
|
||||
//
|
||||
// If out_data is not NULL, the popped data is copied.
|
||||
//
|
||||
// If the vector is already empty, return false.
|
||||
// Returns true otherwise.
|
||||
bool vector_Pop(vector_Vector *vec, void *out_data);
|
||||
|
||||
// Append pushes multiple objects at the back of the buffer.
|
||||
//
|
||||
// If data is NULL, the data is zeroed.
|
||||
|
Reference in New Issue
Block a user