taisei/src/util/crap.h

47 lines
1.1 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT License.
* See COPYING for further information.
* ---
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
2019-07-03 20:00:56 +02:00
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
*/
#pragma once
#include "taisei.h"
#include <SDL.h>
void* memdup(const void *src, size_t size) attr_returns_allocated attr_nonnull(1);
void inherit_missing_pointers(uint num, void *dest[num], void *const base[num]) attr_nonnull(2, 3);
bool is_main_thread(void);
2019-11-12 01:58:22 +01:00
typedef union FloatBits {
float val;
uint32_t bits;
} FloatBits;
typedef union DoubleBits {
double val;
uint64_t bits;
} DoubleBits;
INLINE uint32_t float_to_bits(float f) {
2019-11-12 01:58:22 +01:00
return ((FloatBits) { .val = f }).bits;
2019-04-07 00:55:13 +02:00
}
INLINE float bits_to_float(uint32_t i) {
2019-11-12 01:58:22 +01:00
return ((FloatBits) { .bits = i }).val;
}
2019-11-13 00:52:55 +01:00
INLINE uint64_t double_to_bits(double d) {
return ((DoubleBits) { .val = d }).bits;
2019-11-12 01:58:22 +01:00
}
INLINE double bits_to_double(uint64_t i) {
return ((DoubleBits) { .bits = i }).val;
2019-04-07 00:55:13 +02:00
}
extern SDL_threadID main_thread_id;
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(*(arr)))