Started to shift to better defined types

This commit is contained in:
Dennis Eichhorn 2024-10-01 00:22:42 +02:00
parent fd39f1042d
commit 390158687a
42 changed files with 638 additions and 628 deletions

View File

@ -30,7 +30,7 @@ struct Asset {
// Counts the references to this asset
// e.g. textures
int reference_count;
int32 reference_count;
// Describes how much ram/vram the asset uses
// E.g. vram_size = 0 but ram_size > 0 means that it never uses any gpu memory

View File

@ -37,7 +37,7 @@ struct AssetManagementSystem {
Asset* last;
};
void ams_create(AssetManagementSystem* ams, BufferMemory* buf, int chunk_size, int count)
void ams_create(AssetManagementSystem* ams, BufferMemory* buf, int32 chunk_size, int32 count)
{
// setup hash_map
hashmap_create(&ams->hash_map, count, sizeof(HashEntryInt64), buf);
@ -106,7 +106,7 @@ inline
uint64 ams_get_vram_usage(AssetManagementSystem* ams)
{
uint64 size = 0;
for (int i = 0; i < ams->asset_memory.count; ++i) {
for (int32 i = 0; i < ams->asset_memory.count; ++i) {
size += ((Asset *) (ams->asset_memory.memory))[i].vram_size;
}

View File

@ -29,17 +29,17 @@ struct Camera {
v3_f32 up;
v3_f32 world_up;
float speed;
float sensitivity;
float zoom;
f32 speed;
f32 sensitivity;
f32 zoom;
uint16 viewport_width;
uint16 viewport_height;
float fov;
float znear;
float zfar;
float aspect;
f32 fov;
f32 znear;
f32 zfar;
f32 aspect;
};
void
@ -57,7 +57,7 @@ camera_update_vectors(Camera* camera)
vec3_normalize_f32(&camera->up);
}
void camera_rotate(Camera* camera, int32 dx, int32 dy, float dt)
void camera_rotate(Camera* camera, int32 dx, int32 dy, f32 dt)
{
camera->orientation.x += dy * camera->sensitivity;
camera->orientation.y -= dx * camera->sensitivity;
@ -80,12 +80,12 @@ void camera_rotate(Camera* camera, int32 dx, int32 dy, float dt)
}
// you can have up to 4 camera movement inputs at the same time
void camera_movement(Camera* camera, CameraMovement* movement, float dt, bool relative_to_world = true)
void camera_movement(Camera* camera, CameraMovement* movement, f32 dt, bool relative_to_world = true)
{
f32 velocity = camera->speed * dt;
if (relative_to_world) {
for (int i = 0; i < CAMERA_MAX_INPUTS; i++) {
for (int32 i = 0; i < CAMERA_MAX_INPUTS; i++) {
switch(movement[i]) {
case CAMERA_MOVEMENT_FORWARD: {
camera->location.z += velocity;
@ -143,7 +143,7 @@ void camera_movement(Camera* camera, CameraMovement* movement, float dt, bool re
vec3_cross(&up, &right, &forward);
vec3_normalize_f32(&up);
for (int i = 0; i < CAMERA_MAX_INPUTS; i++) {
for (int32 i = 0; i < CAMERA_MAX_INPUTS; i++) {
switch(movement[i]) {
case CAMERA_MOVEMENT_FORWARD: {
camera->location.x += forward.x * velocity;
@ -206,7 +206,7 @@ void camera_movement(Camera* camera, CameraMovement* movement, float dt, bool re
}
inline
void camera_orth_matrix_lh(const Camera* __restrict camera, float* __restrict orth)
void camera_orth_matrix_lh(const Camera* __restrict camera, f32* __restrict orth)
{
mat4_identity_sparse(orth);
mat4_ortho_sparse_lh(
@ -219,7 +219,7 @@ void camera_orth_matrix_lh(const Camera* __restrict camera, float* __restrict or
}
inline
void camera_orth_matrix_rh(const Camera* __restrict camera, float* __restrict orth)
void camera_orth_matrix_rh(const Camera* __restrict camera, f32* __restrict orth)
{
mat4_identity_sparse(orth);
mat4_ortho_sparse_rh(
@ -232,7 +232,7 @@ void camera_orth_matrix_rh(const Camera* __restrict camera, float* __restrict or
}
inline
void camera_projection_matrix_lh(const Camera* __restrict camera, float* __restrict projection)
void camera_projection_matrix_lh(const Camera* __restrict camera, f32* __restrict projection)
{
mat4_identity_sparse(projection);
mat4_perspective_sparse_lh(
@ -245,7 +245,7 @@ void camera_projection_matrix_lh(const Camera* __restrict camera, float* __restr
}
inline
void camera_projection_matrix_rh(const Camera* __restrict camera, float* __restrict projection)
void camera_projection_matrix_rh(const Camera* __restrict camera, f32* __restrict projection)
{
mat4_identity_sparse(projection);
mat4_perspective_sparse_rh(
@ -260,7 +260,7 @@ void camera_projection_matrix_rh(const Camera* __restrict camera, float* __restr
// This is usually not used, since it is included in the view matrix
// expects the identity matrix
inline
void camera_translation_matrix_sparse_rh(const Camera* __restrict camera, float* translation)
void camera_translation_matrix_sparse_rh(const Camera* __restrict camera, f32* translation)
{
translation[12] = camera->location.x;
translation[13] = camera->location.y;
@ -268,7 +268,7 @@ void camera_translation_matrix_sparse_rh(const Camera* __restrict camera, float*
}
inline
void camera_translation_matrix_sparse_lh(const Camera* __restrict camera, float* translation)
void camera_translation_matrix_sparse_lh(const Camera* __restrict camera, f32* translation)
{
translation[3] = camera->location.x;
translation[7] = camera->location.y;
@ -276,7 +276,7 @@ void camera_translation_matrix_sparse_lh(const Camera* __restrict camera, float*
}
void
camera_view_matrix_lh(const Camera* __restrict camera, float* __restrict view)
camera_view_matrix_lh(const Camera* __restrict camera, f32* __restrict view)
{
v3_f32 zaxis = { camera->front.x, camera->front.y, camera->front.z };
@ -306,7 +306,7 @@ camera_view_matrix_lh(const Camera* __restrict camera, float* __restrict view)
}
void
camera_view_matrix_rh(const Camera* __restrict camera, float* __restrict view)
camera_view_matrix_rh(const Camera* __restrict camera, f32* __restrict view)
{
v3_f32 zaxis = { -camera->front.x, -camera->front.y, -camera->front.z };

View File

@ -64,7 +64,7 @@ uint32 decode_lzp(const byte* in, size_t length, byte* out)
byte table[1 << 16] = {0};
uint16 hash = 0;
int i, j;
int32 i, j;
byte mask, c;
uint32 in_pos = 0, out_pos = 0;
@ -102,12 +102,12 @@ uint32 decode_lzp(const byte* in, size_t length, byte* out)
return out_pos;
}
int find_longest_match(char *window, int window_start, char *buffer, int buffer_size, int *match_position) {
int best_length = 0;
int best_offset = 0;
int32 find_longest_match(char *window, int32 window_start, char *buffer, int32 buffer_size, int32 *match_position) {
int32 best_length = 0;
int32 best_offset = 0;
for (int i = window_start; i < 4096 && i < buffer_size; ++i) {
int length = 0;
for (int32 i = window_start; i < 4096 && i < buffer_size; ++i) {
int32 length = 0;
while (length < 18 &&
i + length < 4096 &&
@ -128,14 +128,14 @@ int find_longest_match(char *window, int window_start, char *buffer, int buffer_
uint32 encode_lzp3(const byte* in, size_t length, byte* out) {
char window[4096] = {0};
int window_start = 0;
int32 window_start = 0;
int out_size = 0;
int32 out_size = 0;
int i = 0;
int32 i = 0;
while (i < length) {
int match_position = 0;
int match_length = find_longest_match(window, window_start, (char *)&in[i], (int) (length - i), &match_position);
int32 match_position = 0;
int32 match_length = find_longest_match(window, window_start, (char *)&in[i], (int32) (length - i), &match_position);
if (match_length > 2) {
out[out_size++] = 0xFF;
@ -148,7 +148,7 @@ uint32 encode_lzp3(const byte* in, size_t length, byte* out) {
++i;
}
int shift_length = match_length > 0 ? match_length : 1;
int32 shift_length = match_length > 0 ? match_length : 1;
memmove(window, window + shift_length, 4096 - shift_length);
memcpy(window + (4096 - shift_length), &in[i - shift_length], shift_length);
window_start = (window_start + shift_length) >= 4096 ? 0 : window_start + shift_length;
@ -159,17 +159,17 @@ uint32 encode_lzp3(const byte* in, size_t length, byte* out) {
uint32 decode_lzp3(const byte* in, size_t length, byte* out) {
char window[4096] = {0};
int window_start = 0;
int32 window_start = 0;
int out_size = 0;
int32 out_size = 0;
int i = 0;
int32 i = 0;
while (i < length) {
if (in[i] == 0xFF) {
int match_position = in[i + 1];
int match_length = in[i + 2];
int32 match_position = in[i + 1];
int32 match_length = in[i + 2];
for (int j = 0; j < match_length; j++) {
for (int32 j = 0; j < match_length; j++) {
out[out_size++] = window[(match_position + j) % 4096];
}

View File

@ -14,21 +14,21 @@
#include "../math/matrix/MatrixFloat32.h"
void make_character(
float *data,
float x, float y, float n, float m, char c)
f32 *data,
f32 x, f32 y, f32 n, f32 m, char c)
{
float *d = data;
f32 *d = data;
// Texture atlas is 16 characters
// 1 / 16 = 0.0625
float a = 0.0625;
float b = 0.0625 * 2;
f32 a = 0.0625;
f32 b = 0.0625 * 2;
// ascii offset
int w = c - 32;
int32 w = c - 32;
float du = (w % 16) * a;
float dv = 1 - (w / 16) * b - b;
f32 du = (w % 16) * a;
f32 dv = 1 - (w / 16) * b - b;
// Quad data (2 triangles)
*(d++) = x - n; *(d++) = y - m;
@ -48,9 +48,9 @@ void make_character(
void font_string_dimension(const char *str, v2_int32* dim, const int* width_lookup)
{
size_t length = strlen(str);
int width = 0;
int32 width = 0;
for (int i = 0; i < length; ++i) {
for (int32 i = 0; i < length; ++i) {
if (str[i] == '\n') {
if (width > dim->x) {
dim->x = width;
@ -73,27 +73,27 @@ void font_string_dimension(const char *str, v2_int32* dim, const int* width_look
}
inline
void entity_world_space(float* world_space, const float* local_space, const float* model_mat)
void entity_world_space(f32* world_space, const f32* local_space, const f32* model_mat)
{
mat4vec4_mult(model_mat, local_space, world_space);
}
inline
void entity_view_space(float* view_space, const float* world_space, const float* view_mat)
void entity_view_space(f32* view_space, const f32* world_space, const f32* view_mat)
{
mat4vec4_mult(view_mat, world_space, view_space);
}
inline
void entity_clip_space(float* clip_space, const float* view_space, const float* projection_mat)
void entity_clip_space(f32* clip_space, const f32* view_space, const f32* projection_mat)
{
mat4vec4_mult(projection_mat, view_space, clip_space);
}
inline
void entity_clip_space_mat(float* result_mat, const float* model_mat, const float* view_mat, const float* projection_mat)
void entity_clip_space_mat(f32* result_mat, const f32* model_mat, const f32* view_mat, const f32* projection_mat)
{
float temp[16];
f32 temp[16];
mat4mat4_mult(projection_mat, view_mat, temp);
mat4mat4_mult(temp, model_mat, result_mat);
}
@ -105,7 +105,7 @@ void entity_clip_space_mat(float* result_mat, const float* model_mat, const floa
*
* Vclip = Mprojection * Mview * Mmodel * Vlocal
*/
void entity_clip_space_mat_sse(float* result_mat, const float* model_mat, const float* view_mat, const float* projection_mat)
void entity_clip_space_mat_sse(f32* result_mat, const f32* model_mat, const f32* view_mat, const f32* projection_mat)
{
__m128 temp[4];
@ -144,46 +144,46 @@ void entity_clip_space_mat_sse(float* result_mat, const float* model_mat, const
}
inline
void entity_clip_space_from_local(float* clip_space, const float* local_space, const float* mat)
void entity_clip_space_from_local(f32* clip_space, const f32* local_space, const f32* mat)
{
mat4vec4_mult(mat, local_space, clip_space);
}
inline
void entity_clip_space_from_local_sse(float* clip_space, const float* local_space, const float* mat)
void entity_clip_space_from_local_sse(f32* clip_space, const f32* local_space, const f32* mat)
{
mat4vec4_mult_sse(mat, local_space, clip_space);
}
/*
inline
void entity_screen_space(float* screen_space, const float* clip_space, const float* viewport_mat)
void entity_screen_space(f32* screen_space, const f32* clip_space, const f32* viewport_mat)
{
// @todo implement
}
*/
inline
void entity_world_space_sse(float* world_space, const float* local_space, const float* model_mat)
void entity_world_space_sse(f32* world_space, const f32* local_space, const f32* model_mat)
{
mat4vec4_mult_sse(model_mat, local_space, world_space);
}
inline
void entity_view_space_sse(float* view_space, const float* world_space, const float* view_mat)
void entity_view_space_sse(f32* view_space, const f32* world_space, const f32* view_mat)
{
mat4vec4_mult_sse(view_mat, world_space, view_space);
}
inline
void entity_clip_space_sse(float* clip_space, const float* view_space, const float* projection_mat)
void entity_clip_space_sse(f32* clip_space, const f32* view_space, const f32* projection_mat)
{
mat4vec4_mult_sse(projection_mat, view_space, clip_space);
}
/*
inline
void entity_screen_space_sse(float* screen_space, const float* clip_space, const float* viewport_mat)
void entity_screen_space_sse(f32* screen_space, const f32* clip_space, const f32* viewport_mat)
{
// @todo implement
}

View File

@ -26,7 +26,7 @@
#endif
inline
void change_viewport(Window* w, int offset_x = 0, int offset_y = 0)
void change_viewport(Window* w, int32 offset_x = 0, int32 offset_y = 0)
{
glViewport(offset_x, offset_y, w->width, w->height);
}
@ -34,7 +34,7 @@ void change_viewport(Window* w, int offset_x = 0, int offset_y = 0)
inline
void vsync_set(bool on)
{
wglSwapIntervalEXT((int) on);
wglSwapIntervalEXT((int32) on);
}
inline
@ -49,8 +49,8 @@ void wireframe_mode(bool on)
struct OpenglInfo {
char* renderer;
int major;
int minor;
int32 major;
int32 minor;
};
void opengl_info(OpenglInfo* info)
@ -119,7 +119,7 @@ void prepare_texture(Texture* texture)
}
inline
void load_texture_to_gpu(const Texture* texture, int mipmap_level = 0)
void load_texture_to_gpu(const Texture* texture, int32 mipmap_level = 0)
{
uint32 texture_data_type = get_texture_data_type(texture->texture_data_type);
glTexImage2D(
@ -277,7 +277,7 @@ void shader_use(uint32 id)
}
inline
void draw_triangles_3d(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_3d(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -285,16 +285,16 @@ void draw_triangles_3d(VertexRef* vertices, GLuint buffer, int count) {
glEnableVertexAttribArray(vertices->data_id);
// normal attribute
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(float) * 3));
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(f32) * 3));
glEnableVertexAttribArray(vertices->normal_id);
// texture coord attribute
// vs glVertexAttribPointer
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex3D), (void *) (sizeof(float) * 6));
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex3D), (void *) (sizeof(f32) * 6));
glEnableVertexAttribArray(vertices->tex_coord_id);
// color attribute
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(float) * 8));
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(f32) * 8));
glEnableVertexAttribArray(vertices->color_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -308,7 +308,7 @@ void draw_triangles_3d(VertexRef* vertices, GLuint buffer, int count) {
}
inline
void draw_triangles_3d_textureless(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_3d_textureless(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -316,11 +316,11 @@ void draw_triangles_3d_textureless(VertexRef* vertices, GLuint buffer, int count
glEnableVertexAttribArray(vertices->data_id);
// normal attribute
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(float) * 3));
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(f32) * 3));
glEnableVertexAttribArray(vertices->normal_id);
// color attribute
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(float) * 8));
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(f32) * 8));
glEnableVertexAttribArray(vertices->color_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -333,7 +333,7 @@ void draw_triangles_3d_textureless(VertexRef* vertices, GLuint buffer, int count
}
inline
void draw_triangles_3d_colorless(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_3d_colorless(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -341,11 +341,11 @@ void draw_triangles_3d_colorless(VertexRef* vertices, GLuint buffer, int count)
glEnableVertexAttribArray(vertices->data_id);
// normal attribute
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(float) * 3));
glVertexAttribPointer(vertices->normal_id, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex3D), (void *) (sizeof(f32) * 3));
glEnableVertexAttribArray(vertices->normal_id);
// texture coord attribute
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex3D), (void *) (sizeof(float) * 6));
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex3D), (void *) (sizeof(f32) * 6));
glEnableVertexAttribArray(vertices->tex_coord_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -358,7 +358,7 @@ void draw_triangles_3d_colorless(VertexRef* vertices, GLuint buffer, int count)
}
inline
void draw_triangles_2d(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_2d(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -367,11 +367,11 @@ void draw_triangles_2d(VertexRef* vertices, GLuint buffer, int count) {
// texture coord attribute
// vs glVertexAttribPointer
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex2D), (void *) (sizeof(float) * 2));
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex2D), (void *) (sizeof(f32) * 2));
glEnableVertexAttribArray(vertices->tex_coord_id);
// color attribute
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *) (sizeof(float) * 4));
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *) (sizeof(f32) * 4));
glEnableVertexAttribArray(vertices->color_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -384,7 +384,7 @@ void draw_triangles_2d(VertexRef* vertices, GLuint buffer, int count) {
}
inline
void draw_triangles_2d_textureless(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_2d_textureless(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -392,7 +392,7 @@ void draw_triangles_2d_textureless(VertexRef* vertices, GLuint buffer, int count
glEnableVertexAttribArray(vertices->data_id);
// color attribute
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *) (sizeof(float) * 4));
glVertexAttribPointer(vertices->color_id, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *) (sizeof(f32) * 4));
glEnableVertexAttribArray(vertices->color_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -404,7 +404,7 @@ void draw_triangles_2d_textureless(VertexRef* vertices, GLuint buffer, int count
}
inline
void draw_triangles_2d_colorless(VertexRef* vertices, GLuint buffer, int count) {
void draw_triangles_2d_colorless(VertexRef* vertices, GLuint buffer, int32 count) {
glBindBuffer(GL_ARRAY_BUFFER, buffer);
// position attribute
@ -412,7 +412,7 @@ void draw_triangles_2d_colorless(VertexRef* vertices, GLuint buffer, int count)
glEnableVertexAttribArray(vertices->data_id);
// texture coord attribute
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex2D), (void *) (sizeof(float) * 2));
glVertexAttribIPointer(vertices->tex_coord_id, 2, GL_UNSIGNED_INT, sizeof(Vertex2D), (void *) (sizeof(f32) * 2));
glEnableVertexAttribArray(vertices->tex_coord_id);
glDrawArrays(GL_TRIANGLES, 0, count);
@ -424,7 +424,7 @@ void draw_triangles_2d_colorless(VertexRef* vertices, GLuint buffer, int count)
}
inline
int calculate_face_size(int components, int faces)
int calculate_face_size(int components, int32 faces)
{
return sizeof(GLfloat) * 6 * components * faces;
}
@ -432,7 +432,7 @@ int calculate_face_size(int components, int faces)
// generates faces
// data is no longer needed after this
inline
uint32 gpuapi_buffer_generate(int size, const void* data)
uint32 gpuapi_buffer_generate(int32 size, const void* data)
{
uint32 vbo;
@ -444,7 +444,7 @@ uint32 gpuapi_buffer_generate(int size, const void* data)
}
inline
uint32 gpuapi_buffer_generate_dynamic(int size, const void* data)
uint32 gpuapi_buffer_generate_dynamic(int32 size, const void* data)
{
uint32 vbo;
@ -456,14 +456,14 @@ uint32 gpuapi_buffer_generate_dynamic(int size, const void* data)
}
inline
void gpuapi_buffer_update_dynamic(uint32 vbo, int size, const void* data)
void gpuapi_buffer_update_dynamic(uint32 vbo, int32 size, const void* data)
{
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW);
}
inline
uint32 gpuapi_shaderbuffer_generate(int size, const void* data)
uint32 gpuapi_shaderbuffer_generate(int32 size, const void* data)
{
uint32 sbo;
@ -474,7 +474,7 @@ uint32 gpuapi_shaderbuffer_generate(int size, const void* data)
return sbo;
}
uint32 gpuapi_upload_color_palette(const byte* palette, int count, int sampler_id)
uint32 gpuapi_upload_color_palette(const byte* palette, int32 count, int32 sampler_id)
{
uint32 texture_id;
@ -492,7 +492,7 @@ uint32 gpuapi_upload_color_palette(const byte* palette, int count, int sampler_i
}
inline
uint32 gpuapi_uniformbuffer_generate(int size, const void* data)
uint32 gpuapi_uniformbuffer_generate(int32 size, const void* data)
{
uint32 ubo;
@ -504,7 +504,7 @@ uint32 gpuapi_uniformbuffer_generate(int size, const void* data)
}
inline
uint32 gpuapi_buffer_element_generate(int size, uint32 *data)
uint32 gpuapi_buffer_element_generate(int32 size, uint32 *data)
{
uint32 ebo;
@ -562,7 +562,7 @@ struct TextRender {
uint32 align;
uint32 x;
uint32 y;
float scale;
f32 scale;
VertexRef vertices;
char* text;
@ -579,7 +579,7 @@ struct TextRender {
inline
void render_text_batched(
RingMemory* ring,
int width, int height,
int32 width, int32 height,
TextRender* text_data
) {
glUseProgram(text_data->shader_data.program_id);
@ -588,8 +588,8 @@ void render_text_batched(
// @performance Instead of re-creating the matrix every render call just use the id to activate it
// 2d projection
if (text_data->shader_data.matrix_id == 0) {
float matrix[16] = {};
mat4_ortho_sparse_rh(matrix, 0.0f, (float) width, 0.0f, (float) height, -1.0f, 1.0f);
f32 matrix[16] = {};
mat4_ortho_sparse_rh(matrix, 0.0f, (f32) width, 0.0f, (f32) height, -1.0f, 1.0f);
glUniformMatrix4fv(text_data->shader_data.matrix_addr, 1, GL_FALSE, matrix);
text_data->shader_data.matrix_id = 1;
// @bug this is wrong, we need to make buffer instead. We don't want to upload the matrix every time
@ -601,15 +601,15 @@ void render_text_batched(
//glBindVertexArray(text_data->shader_data.matrix_id);
}
int length = (int) strlen(text_data->text);
float x = text_data->x - text_data->scale * text_data->align * (length - 1) / 2;
int32 length = (int32) strlen(text_data->text);
f32 x = text_data->x - text_data->scale * text_data->align * (length - 1) / 2;
// @performance Only create when the text got removed from memory
if (text_data->vertices.data_id == 0) {
GLfloat *data = (GLfloat *) ring_get_memory(ring, sizeof(GLfloat) * 6 * 4 * length);
for (int i = 0; i < length; i++) {
make_character(data + i * 24, x, (float) text_data->y, text_data->scale / 2, text_data->scale, text_data->text[i]);
for (int32 i = 0; i < length; i++) {
make_character(data + i * 24, x, (f32) text_data->y, text_data->scale / 2, text_data->scale, text_data->text[i]);
x += text_data->scale;
}
@ -631,11 +631,11 @@ void render_text_batched(
/*
void render_9_patch(GLuint texture,
int imgWidth, int imgHeight,
int img_x1, int img_x2,
int img_y1, int img_y2,
int renderWidth, int renderHeight,
int repeat
int32 imgWidth, int32 imgHeight,
int32 img_x1, int32 img_x2,
int32 img_y1, int32 img_y2,
int32 renderWidth, int32 renderHeight,
int32 repeat
)
{

View File

@ -1323,11 +1323,11 @@ static wgl_get_extensions_string_ext* wglGetExtensionsStringEXT;
void set_pixel_format(HDC hdc)
{
int suggested_pixel_format_idx = 0;
unsigned int extended_pick = 0;
int32 suggested_pixel_format_idx = 0;
uint32 extended_pick = 0;
if (wglChoosePixelFormatARB) {
int attr_list[] = {
int32 attr_list[] = {
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,

View File

@ -16,53 +16,53 @@
inline
void shader_set_value(uint32 id, const char* name, bool value)
{
glUniform1i(glGetUniformLocation(id, name), (int) value);
glUniform1i(glGetUniformLocation(id, name), (int32) value);
}
inline
void shader_set_value(uint32 id, const char* name, int value)
void shader_set_value(uint32 id, const char* name, int32 value)
{
glUniform1i(glGetUniformLocation(id, name), value);
}
inline
void shader_set_value(uint32 id, const char* name, float value)
void shader_set_value(uint32 id, const char* name, f32 value)
{
glUniform1f(glGetUniformLocation(id, name), value);
}
inline
void shader_set_v2(uint32 id, const char* name, const float* value)
void shader_set_v2(uint32 id, const char* name, const f32* value)
{
glUniform2fv(glGetUniformLocation(id, name), 1, value);
}
inline
void shader_set_v3(uint32 id, const char* name, const float* value)
void shader_set_v3(uint32 id, const char* name, const f32* value)
{
glUniform3fv(glGetUniformLocation(id, name), 1, value);
}
inline
void shader_set_v4(uint32 id, const char* name, const float* value)
void shader_set_v4(uint32 id, const char* name, const f32* value)
{
glUniform4fv(glGetUniformLocation(id, name), 1, value);
}
inline
void shader_set_m2(uint32 id, const char* name, const float* value)
void shader_set_m2(uint32 id, const char* name, const f32* value)
{
glUniformMatrix2fv(glGetUniformLocation(id, name), 1, GL_FALSE, value);
}
inline
void shader_set_m3(uint32 id, const char* name, const float* value)
void shader_set_m3(uint32 id, const char* name, const f32* value)
{
glUniformMatrix3fv(glGetUniformLocation(id, name), 1, GL_FALSE, value);
}
inline
void shader_set_m4(uint32 id, const char* name, const float* value)
void shader_set_m4(uint32 id, const char* name, const f32* value)
{
glUniformMatrix4fv(glGetUniformLocation(id, name), 1, GL_FALSE, value);
}

View File

@ -13,7 +13,7 @@
uint64 hash_djb2(const char* key) {
uint64 hash = 5381;
int c;
int32 c;
while ((c = *key++)) {
hash = ((hash << 5) + hash) + c;
@ -25,7 +25,7 @@ uint64 hash_djb2(const char* key) {
uint64 hash_sdbm(const byte* key)
{
uint64 hash = 0;
int c;
int32 c;
while (c = *key++) {
hash = c + (hash << 6) + (hash << 16) - hash;
@ -37,7 +37,7 @@ uint64 hash_sdbm(const byte* key)
uint64 hash_lose_lose(const byte* key)
{
uint64 hash = 0;
int c;
int32 c;
while (c = *key++) {
hash += c;
@ -47,8 +47,8 @@ uint64 hash_lose_lose(const byte* key)
}
uint64 hash_polynomial_rolling(const char* str) {
const int p = 31;
const int m = 1000000009;
const int32 p = 31;
const int32 m = 1000000009;
uint64 hash = 0;
uint64 p_pow = 1;

View File

@ -215,7 +215,7 @@ uint8 png_filter_4(const uint8* x, const uint8* a_full, const uint8* b_full, con
return x[channel] + (uint8) paeth;
}
void png_filter_reconstruct(uint32 width, uint32 height, uint32 color_type, const uint8* decompressed, uint8* finalized, int steps = 8)
void png_filter_reconstruct(uint32 width, uint32 height, uint32 color_type, const uint8* decompressed, uint8* finalized, int32 steps = 8)
{
uint64 zero = 0;
uint8* prev_row = (uint8 *) &zero;

View File

@ -28,7 +28,7 @@
// How many buttons together are allowed to form a hotkey
#define MAX_HOTKEY_COMBINATION 3
// These values are used as bit flags to hint if a "key" is a keyboard/primary or mouse/secondary input
// These values are used as bit flags to hint32 if a "key" is a keyboard/primary or mouse/secondary input
// When adding a keybind the "key" can only be uint8 but we expand it to an int and set the first bit accordingly
#define INPUT_MOUSE_PREFIX 0
#define INPUT_KEYBOARD_PREFIX 8192
@ -139,7 +139,7 @@ struct Input {
inline
void input_clean_state(InputState* state)
{
for (int i = 0; i < MAX_KEY_STATES; ++i) {
for (int32 i = 0; i < MAX_KEY_STATES; ++i) {
if (state->state_keys[i].key_state == KEY_STATE_RELEASED) {
state->state_keys[i].key_id = 0;
}
@ -261,7 +261,7 @@ input_add_hotkey(
int32 key0, int32 key1 = 0, int32 key2 = 0
)
{
int count = 0;
int32 count = 0;
// Define required keys for hotkey
if (key0 != 0) {
@ -293,13 +293,13 @@ input_add_hotkey(
key2 *= -1;
}
int key0_offset = ((bool) (key0 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
int32 key0_offset = ((bool) (key0 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
+ ((bool) (key0 & INPUT_CONTROLLER_PREFIX)) * (MAX_MOUSE_KEYS + MAX_KEYBOARD_KEYS);
int key1_offset = ((bool) (key1 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
int32 key1_offset = ((bool) (key1 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
+ ((bool) (key1 & INPUT_CONTROLLER_PREFIX)) * (MAX_MOUSE_KEYS + MAX_KEYBOARD_KEYS);
int key2_offset = ((bool) (key2 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
int32 key2_offset = ((bool) (key2 & INPUT_KEYBOARD_PREFIX)) * MAX_MOUSE_KEYS
+ ((bool) (key2 & INPUT_CONTROLLER_PREFIX)) * (MAX_MOUSE_KEYS + MAX_KEYBOARD_KEYS);
key0 = (key0 & ~(INPUT_KEYBOARD_PREFIX | INPUT_CONTROLLER_PREFIX));
@ -307,7 +307,7 @@ input_add_hotkey(
key2 = (key2 & ~(INPUT_KEYBOARD_PREFIX | INPUT_CONTROLLER_PREFIX));
// Bind key to hotkey
for (int i = 0; i < MAX_KEY_TO_HOTKEY; ++i) {
for (int32 i = 0; i < MAX_KEY_TO_HOTKEY; ++i) {
if (key0 == 0 && key1 == 0 && key2 == 0) {
break;
}
@ -373,7 +373,7 @@ void input_set_state(InputState* state, InputKey* __restrict new_key)
InputKey* free_state = NULL;
bool action_required = true;
for (int i = 0; i < MAX_KEY_STATES; ++i) {
for (int32 i = 0; i < MAX_KEY_STATES; ++i) {
if (!free_state && state->state_keys[i].key_id == 0) {
free_state = &state->state_keys[i];
} else if (state->state_keys[i].key_id == new_key->key_id) {
@ -403,7 +403,7 @@ inline
void input_set_controller_state(Input* input, ControllerInput* controller, uint64 time)
{
// Check active keys that might need to be set to inactive
for (int i = 0; i < MAX_KEY_PRESSES; ++i) {
for (int32 i = 0; i < MAX_KEY_PRESSES; ++i) {
if ((input->state.state_keys[i].key_id & INPUT_CONTROLLER_PREFIX)
&& input->state.state_keys[i].key_state != KEY_STATE_RELEASED
) {
@ -449,7 +449,7 @@ void input_set_controller_state(Input* input, ControllerInput* controller, uint6
}
// General Keys
int count = 0;
int32 count = 0;
InputKey keys[5];
for (uint16 i = 0; i < 32; ++i) {
@ -466,7 +466,7 @@ void input_set_controller_state(Input* input, ControllerInput* controller, uint6
}
if (count > 0) {
for (int i = 0; i < count; ++i) {
for (int32 i = 0; i < count; ++i) {
input_set_state(&input->state, &keys[i]);
}
}
@ -479,7 +479,7 @@ input_hotkey_state(Input* input)
{
memset(input->state.state_hotkeys, 0, sizeof(uint8) * MAX_KEY_PRESSES);
int active_hotkeys = 0;
int32 active_hotkeys = 0;
// Check every key down state
for (int key_state = 0; key_state < MAX_KEY_STATES; ++key_state) {
@ -502,7 +502,7 @@ input_hotkey_state(Input* input)
// @performance Could it make sense to only loop over one mapping (create a pointer that references the correct mapping)
// We then swap this pointer whenever we detect a input from keyboard+mouse vs controller
// This would allow us even to add context specific mappings
for (int i = 0; i < 2; ++i) {
for (int32 i = 0; i < 2; ++i) {
InputMapping* mapping;
if (i == 0) {
mapping = &input->input_mapping1;
@ -548,10 +548,10 @@ input_hotkey_state(Input* input)
// It doesn't always happen but you can test it rather consistently within a couple of seconds
}
bool input_key_is_longpress(InputState* state, uint16 key, uint64 time, float dt = 0.0f) {
for (int i = 0; i < MAX_KEY_STATES; ++i) {
bool input_key_is_longpress(InputState* state, uint16 key, uint64 time, f32 dt = 0.0f) {
for (int32 i = 0; i < MAX_KEY_STATES; ++i) {
if (state->state_keys[i].key_id == key) {
return (float) (time - state->state_keys[i].time) / 1000.0f >= (dt == 0.0f ? INPUT_LONG_PRESS_DURATION : dt);
return (f32) (time - state->state_keys[i].time) / 1000.0f >= (dt == 0.0f ? INPUT_LONG_PRESS_DURATION : dt);
}
}
@ -559,16 +559,16 @@ bool input_key_is_longpress(InputState* state, uint16 key, uint64 time, float dt
}
// @todo I wrote this code at 9am after staying awake for the whole night and that is how that code looks like... fix it!
bool input_hotkey_is_longpress(Input* input, uint8 hotkey, uint64 time, float dt = 0.0f) {
bool input_hotkey_is_longpress(Input* input, uint8 hotkey, uint64 time, f32 dt = 0.0f) {
bool is_longpress = false;
for (int i = 0; i < MAX_KEY_PRESSES; ++i) {
for (int32 i = 0; i < MAX_KEY_PRESSES; ++i) {
if (input->state.state_hotkeys[i] != hotkey) {
continue;
}
is_longpress = true;
for (int j = 0; j < MAX_HOTKEY_COMBINATION; ++j) {
for (int32 j = 0; j < MAX_HOTKEY_COMBINATION; ++j) {
bool potential_miss = true;
bool both_empty = false;
if (input->input_mapping1.hotkeys[hotkey * MAX_HOTKEY_COMBINATION + j] > 0) {

View File

@ -23,7 +23,7 @@ void update_timing_stat(uint32 stat, const char* function)
inline
DebugMemory* debug_memory_find(uint64 start, uint64 size)
{
for (int i = 0; i < debug_container->dmc.memory_size; ++i) {
for (int32 i = 0; i < debug_container->dmc.memory_size; ++i) {
if (debug_container->dmc.memory_stats[i].start <= start
&& debug_container->dmc.memory_stats[i].start + debug_container->dmc.memory_stats[i].size >= start
) {
@ -142,8 +142,8 @@ void debug_memory_reset()
{
uint64 time = __rdtsc() - 1000000000;
for (int i = 0; i < debug_container->dmc.memory_element_idx; ++i) {
for (int j = 0; j < DEBUG_MEMORY_RANGE_MAX; ++j) {
for (int32 i = 0; i < debug_container->dmc.memory_element_idx; ++i) {
for (int32 j = 0; j < DEBUG_MEMORY_RANGE_MAX; ++j) {
if (debug_container->dmc.memory_stats[i].last_action[j].time < time) {
memset(&debug_container->dmc.memory_stats[i].last_action[j], 0, sizeof(DebugMemoryRange));
}

View File

@ -46,7 +46,7 @@ struct LogMemory {
uint32 id;
uint64 size;
uint64 pos;
int alignment;
int32 alignment;
uint64 start;
uint64 end;
};

View File

@ -9,7 +9,7 @@ double fade(double t) {
double grad(int hash, double x, double y, double z)
{
int h = hash & 15;
int32 h = hash & 15;
double u = h < 8 ? x : y;
double v = h < 4 ? y : h == 12 || h == 14 ? x : z;
@ -18,11 +18,11 @@ double grad(int hash, double x, double y, double z)
}
// permutation = 512 elements
double noise(int* permutation, double x, double y, double z)
double noise(int32* permutation, double x, double y, double z)
{
int X = (int) floor(x) & 255;
int Y = (int) floor(y) & 255;
int Z = (int) floor(z) & 255;
int32 X = (int32) floor(x) & 255;
int32 Y = (int32) floor(y) & 255;
int32 Z = (int32) floor(z) & 255;
x -= floor(x);
y -= floor(y);
@ -30,13 +30,13 @@ double noise(int* permutation, double x, double y, double z)
double u = fade(x), v = fade(y), w = fade(z);
int A = permutation[X] + Y;
int AA = permutation[A] + Z;
int AB = permutation[A + 1] + Z;
int32 A = permutation[X] + Y;
int32 AA = permutation[A] + Z;
int32 AB = permutation[A + 1] + Z;
int B = permutation[X + 1] + Y;
int BA = permutation[B] + Z;
int BB = permutation[B + 1] + Z;
int32 B = permutation[X + 1] + Y;
int32 BA = permutation[B] + Z;
int32 BB = permutation[B + 1] + Z;
return lerp_approx(
w,

View File

@ -16,9 +16,9 @@
// @todo Implement intrinsic versions!
void vec2_normalize_f32(float* __restrict x, float* __restrict y)
void vec2_normalize_f32(f32* __restrict x, f32* __restrict y)
{
float d = sqrtf((*x) * (*x) + (*y) * (*y));
f32 d = sqrtf((*x) * (*x) + (*y) * (*y));
*x /= d;
*y /= d;
@ -49,19 +49,19 @@ void vec2_sub(v2_f32* __restrict vec, const v2_f32* b) {
}
inline
void vec2_mul(v2_f32* vec, const v2_f32* a, float s) {
void vec2_mul(v2_f32* vec, const v2_f32* a, f32 s) {
vec->x = a->x * s;
vec->y = a->y * s;
}
inline
void vec2_mul(v2_f32* vec, float s) {
void vec2_mul(v2_f32* vec, f32 s) {
vec->x *= s;
vec->y *= s;
}
inline
float vec2_mul(const v2_f32* a, const v2_f32* b) {
f32 vec2_mul(const v2_f32* a, const v2_f32* b) {
return a->x * b->x + a->y * b->y;
}
@ -78,18 +78,18 @@ void vec2_mul(v2_f32* __restrict vec, const v2_f32* b) {
}
inline
float vec2_cross(const v2_f32* a, const v2_f32* b) {
f32 vec2_cross(const v2_f32* a, const v2_f32* b) {
return a->x * b->y - a->y * b->x;
}
inline
float vec2_dot(const v2_f32* a, const v2_f32* b) {
f32 vec2_dot(const v2_f32* a, const v2_f32* b) {
return a->x * b->x + a->y * b->y;
}
void vec3_normalize_f32(float* __restrict x, float* __restrict y, float* __restrict z)
void vec3_normalize_f32(f32* __restrict x, f32* __restrict y, f32* __restrict z)
{
float d = sqrtf((*x) * (*x) + (*y) * (*y) + (*z) * (*z));
f32 d = sqrtf((*x) * (*x) + (*y) * (*y) + (*z) * (*z));
*x /= d;
*y /= d;
@ -98,7 +98,7 @@ void vec3_normalize_f32(float* __restrict x, float* __restrict y, float* __restr
void vec3_normalize_f32(v3_f32* vec)
{
float d = sqrtf(vec->x * vec->x + vec->y * vec->y + vec->z * vec->z);
f32 d = sqrtf(vec->x * vec->x + vec->y * vec->y + vec->z * vec->z);
vec->x /= d;
vec->y /= d;
@ -134,21 +134,21 @@ void vec3_sub(v3_f32* __restrict vec, const v3_f32* b) {
}
inline
void vec3_mul(v3_f32* vec, const v3_f32* a, float s) {
void vec3_mul(v3_f32* vec, const v3_f32* a, f32 s) {
vec->x = a->x * s;
vec->y = a->y * s;
vec->z = a->z * s;
}
inline
void vec3_mul(v3_f32* vec, float s) {
void vec3_mul(v3_f32* vec, f32 s) {
vec->x *= s;
vec->y *= s;
vec->z *= s;
}
inline
float vec3_mul(const v3_f32* a, const v3_f32* b) {
f32 vec3_mul(const v3_f32* a, const v3_f32* b) {
return a->x * b->x + a->y * b->y + a->z * b->z;
}
@ -172,13 +172,13 @@ void vec3_cross(v3_f32* __restrict vec, const v3_f32* a, const v3_f32* b) {
vec->z = a->x * b->y - a->y * b->x;
}
float vec3_dot(const v3_f32* a, const v3_f32* b) {
f32 vec3_dot(const v3_f32* a, const v3_f32* b) {
return a->x * b->x + a->y * b->y + a->z * b->z;
}
void vec4_normalize_f32(float* __restrict x, float* __restrict y, float* __restrict z, float* __restrict w)
void vec4_normalize_f32(f32* __restrict x, f32* __restrict y, f32* __restrict z, f32* __restrict w)
{
float d = sqrtf((*x) * (*x) + (*y) * (*y) + (*z) * (*z) + (*w) * (*w));
f32 d = sqrtf((*x) * (*x) + (*y) * (*y) + (*z) * (*z) + (*w) * (*w));
*x /= d;
*y /= d;
@ -219,7 +219,7 @@ void vec4_sub(v4_f32* __restrict vec, const v4_f32* b) {
}
inline
void vec4_mul(v4_f32* vec, const v4_f32* a, float s) {
void vec4_mul(v4_f32* vec, const v4_f32* a, f32 s) {
vec->x = a->x * s;
vec->y = a->y * s;
vec->z = a->z * s;
@ -227,7 +227,7 @@ void vec4_mul(v4_f32* vec, const v4_f32* a, float s) {
}
inline
void vec4_mul(v4_f32* vec, float s) {
void vec4_mul(v4_f32* vec, f32 s) {
vec->x *= s;
vec->y *= s;
vec->z *= s;
@ -235,7 +235,7 @@ void vec4_mul(v4_f32* vec, float s) {
}
inline
float vec4_mul(const v4_f32* a, const v4_f32* b) {
f32 vec4_mul(const v4_f32* a, const v4_f32* b) {
return a->x * b->x + a->y * b->y + a->z * b->z + a->w * b->w;
}
@ -256,7 +256,7 @@ void vec4_mul(v4_f32* __restrict vec, const v4_f32* b) {
}
inline
float vec4_dot(const v4_f32* a, const v4_f32* b) {
f32 vec4_dot(const v4_f32* a, const v4_f32* b) {
return a->x * b->x + a->y * b->y + a->z * b->z + a->w * b->w;
}
@ -269,7 +269,7 @@ void vec4_cross(v4_f32* __restrict vec, const v4_f32* a, const v4_f32* b, const
}
inline
void mat3_identity(float* matrix)
void mat3_identity(f32* matrix)
{
matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f;
matrix[3] = 0.0f; matrix[4] = 1.0f; matrix[5] = 0.0f;
@ -277,7 +277,7 @@ void mat3_identity(float* matrix)
}
inline
void mat3_identity_sparse(float* matrix)
void mat3_identity_sparse(f32* matrix)
{
matrix[0] = 1.0f; matrix[4] = 1.0f; matrix[8] = 1.0f;
}
@ -291,7 +291,7 @@ void mat3_identity(__m128* matrix)
}
inline
void mat4_identity(float* matrix)
void mat4_identity(f32* matrix)
{
matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f; matrix[3] = 0.0f;
matrix[4] = 0.0f; matrix[5] = 1.0f; matrix[6] = 0.0f; matrix[7] = 0.0f;
@ -300,7 +300,7 @@ void mat4_identity(float* matrix)
}
inline
void mat4_identity_sparse(float* matrix)
void mat4_identity_sparse(f32* matrix)
{
matrix[0] = 1.0f; matrix[5] = 1.0f; matrix[10] = 1.0f; matrix[15] = 1.0f;
}
@ -316,26 +316,26 @@ void mat4_identity(__m128* matrix)
// x, y, z need to be normalized
// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
void mat4_rotation(float* matrix, float x, float y, float z, float angle)
void mat4_rotation(f32* matrix, f32 x, f32 y, f32 z, f32 angle)
{
ASSERT_SIMPLE(OMS_ABS(x * x + y * y + z * z - 1.0f) < 0.01);
// @todo replace with quaternions
float s = sinf(angle);
float c = cosf(angle);
float m = 1 - c;
f32 s = sinf(angle);
f32 c = cosf(angle);
f32 m = 1 - c;
float mx = m * x;
float my = m * y;
float mz = m * z;
f32 mx = m * x;
f32 my = m * y;
f32 mz = m * z;
float xs = x * s;
float ys = y * s;
float zs = z * s;
f32 xs = x * s;
f32 ys = y * s;
f32 zs = z * s;
float mxy = mx * y;
float mzx = mz * x;
float myz = my * z;
f32 mxy = mx * y;
f32 mzx = mz * x;
f32 myz = my * z;
matrix[0] = mx * x + c;
matrix[1] = mxy - zs;
@ -358,14 +358,14 @@ void mat4_rotation(float* matrix, float x, float y, float z, float angle)
matrix[15] = 1.0f;
}
void mat4_rotation(float* matrix, float pitch, float yaw, float roll)
void mat4_rotation(f32* matrix, f32 pitch, f32 yaw, f32 roll)
{
float cos_pitch = cosf(pitch);
float sin_pitch = sinf(pitch);
float cos_yaw = cosf(yaw);
float sin_yaw = sinf(yaw);
float cos_roll = cosf(roll);
float sin_roll = sinf(roll);
f32 cos_pitch = cosf(pitch);
f32 sin_pitch = sinf(pitch);
f32 cos_yaw = cosf(yaw);
f32 sin_yaw = sinf(yaw);
f32 cos_roll = cosf(roll);
f32 sin_roll = sinf(roll);
matrix[0] = cos_yaw * cos_roll;
matrix[1] = cos_yaw * sin_roll;
@ -389,7 +389,7 @@ void mat4_rotation(float* matrix, float pitch, float yaw, float roll)
}
inline
void mat3vec3_mult(const float* __restrict matrix, const float* __restrict vector, float* __restrict result)
void mat3vec3_mult(const f32* __restrict matrix, const f32* __restrict vector, f32* __restrict result)
{
result[0] = matrix[0] * vector[0] + matrix[1] * vector[1] + matrix[2] * vector[2];
result[1] = matrix[3] * vector[0] + matrix[4] * vector[1] + matrix[5] * vector[2];
@ -397,12 +397,12 @@ void mat3vec3_mult(const float* __restrict matrix, const float* __restrict vecto
}
// @question could simple mul add sse be faster?
void mat3vec3_mult_sse(const float* __restrict matrix, const float* __restrict vector, float* __restrict result)
void mat3vec3_mult_sse(const f32* __restrict matrix, const f32* __restrict vector, f32* __restrict result)
{
__m128 vec = _mm_loadu_ps(vector);
vec = _mm_insert_ps(vec, _mm_setzero_ps(), 0x30); // vec[3] = 0
for (int i = 0; i < 3; ++i) {
for (int32 i = 0; i < 3; ++i) {
__m128 row = _mm_loadu_ps(&matrix[i * 3]);
row = _mm_insert_ps(row, _mm_setzero_ps(), 0x30); // row[3] = 0
@ -413,9 +413,9 @@ void mat3vec3_mult_sse(const float* __restrict matrix, const float* __restrict v
}
// @question could simple mul add sse be faster?
void mat3vec3_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, float* __restrict result)
void mat3vec3_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, f32* __restrict result)
{
for (int i = 0; i < 3; ++i) {
for (int32 i = 0; i < 3; ++i) {
__m128 dot = _mm_dp_ps(matrix[i], *vector, 0xF1);
result[i] = _mm_cvtss_f32(dot);
@ -425,13 +425,13 @@ void mat3vec3_mult_sse(const __m128* __restrict matrix, const __m128* __restrict
// @question could simple mul add sse be faster?
void mat3vec3_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, __m128* __restrict result)
{
for (int i = 0; i < 4; ++i) {
for (int32 i = 0; i < 4; ++i) {
result[i] = _mm_dp_ps(matrix[i], *vector, 0xF1);
}
}
inline
void mat4vec4_mult(const float* __restrict matrix, const float* __restrict vector, float* __restrict result)
void mat4vec4_mult(const f32* __restrict matrix, const f32* __restrict vector, f32* __restrict result)
{
result[0] = matrix[0] * vector[0] + matrix[1] * vector[1] + matrix[2] * vector[2] + matrix[3] * vector[3];
result[1] = matrix[4] * vector[0] + matrix[5] * vector[1] + matrix[6] * vector[2] + matrix[7] * vector[3];
@ -440,11 +440,11 @@ void mat4vec4_mult(const float* __restrict matrix, const float* __restrict vecto
}
// @question could simple mul add sse be faster?
void mat4vec4_mult_sse(const float* __restrict matrix, const float* __restrict vector, float* __restrict result)
void mat4vec4_mult_sse(const f32* __restrict matrix, const f32* __restrict vector, f32* __restrict result)
{
__m128 vec = _mm_loadu_ps(vector);
for (int i = 0; i < 4; ++i) {
for (int32 i = 0; i < 4; ++i) {
__m128 row = _mm_loadu_ps(&matrix[i * 4]);
__m128 dot = _mm_dp_ps(row, vec, 0xF1);
@ -453,9 +453,9 @@ void mat4vec4_mult_sse(const float* __restrict matrix, const float* __restrict v
}
// @question could simple mul add sse be faster?
void mat4vec4_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, float* __restrict result)
void mat4vec4_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, f32* __restrict result)
{
for (int i = 0; i < 4; ++i) {
for (int32 i = 0; i < 4; ++i) {
__m128 dot = _mm_dp_ps(matrix[i], *vector, 0xF1);
result[i] = _mm_cvtss_f32(dot);
@ -465,13 +465,13 @@ void mat4vec4_mult_sse(const __m128* __restrict matrix, const __m128* __restrict
// @question could simple mul add sse be faster?
void mat4vec4_mult_sse(const __m128* __restrict matrix, const __m128* __restrict vector, __m128* __restrict result)
{
for (int i = 0; i < 4; ++i) {
for (int32 i = 0; i < 4; ++i) {
result[i] = _mm_dp_ps(matrix[i], *vector, 0xF1);
}
}
inline
void mat4mat4_mult(const float* __restrict a, const float* __restrict b, float* __restrict result)
void mat4mat4_mult(const f32* __restrict a, const f32* __restrict b, f32* __restrict result)
{
result[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + a[3] * b[12];
result[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + a[3] * b[13];
@ -494,10 +494,10 @@ void mat4mat4_mult(const float* __restrict a, const float* __restrict b, float*
result[15] = a[12] * b[3] + a[13] * b[7] + a[14] * b[11] + a[15] * b[15];
}
void mat4mat4_mult(const float* __restrict a, const float* __restrict b, float* __restrict result, int steps)
void mat4mat4_mult(const f32* __restrict a, const f32* __restrict b, f32* __restrict result, int32 steps)
{
if (steps > 1) {
// @todo check http://fhtr.blogspot.com/2010/02/4x4-float-matrix-multiplication-using.html
// @todo check http://fhtr.blogspot.com/2010/02/4x4-f32-matrix-multiplication-using.html
// @question could simple mul add sse be faster?
// Load rows of matrix a
__m128 a_1 = _mm_loadu_ps(a);
@ -567,7 +567,7 @@ void mat4mat4_mult(const float* __restrict a, const float* __restrict b, float*
}
}
void mat4mat4_mult_sse(const __m128* __restrict a, const __m128* __restrict b_transposed, float* __restrict result)
void mat4mat4_mult_sse(const __m128* __restrict a, const __m128* __restrict b_transposed, f32* __restrict result)
{
__m128 dot;
@ -628,24 +628,24 @@ void mat4mat4_mult_sse(const __m128* __restrict a, const __m128* __restrict b_tr
inline
void mat4mat4_mult_sse(const __m128* __restrict a, const __m128* __restrict b_transpose, __m128* __restrict result)
{
for (int i = 0; i < 4; ++i) {
for (int32 i = 0; i < 4; ++i) {
result[i] = _mm_mul_ps(a[0], b_transpose[i]);
for (int j = 1; j < 4; ++j) {
for (int32 j = 1; j < 4; ++j) {
result[i] = _mm_add_ps(_mm_mul_ps(a[j], b_transpose[4 * j + i]), result[i]);
}
}
}
// @performance Consider to replace with 1d array
void mat4_frustum_planes(float planes[6][4], float radius, float *matrix) {
void mat4_frustum_planes(f32 planes[6][4], f32 radius, f32 *matrix) {
// @todo make this a setting
// @bug fix to row-major system
// @todo don't use 2d arrays
float znear = 0.125;
float zfar = radius * 32 + 64;
f32 znear = 0.125;
f32 zfar = radius * 32 + 64;
float *m = matrix;
f32 *m = matrix;
planes[0][0] = m[3] + m[0];
planes[0][1] = m[7] + m[4];
@ -679,14 +679,14 @@ void mat4_frustum_planes(float planes[6][4], float radius, float *matrix) {
}
void mat4_frustum_sparse_rh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
f32 *matrix,
f32 left, f32 right, f32 bottom, f32 top,
f32 znear, f32 zfar
) {
float temp = 2.0f * znear;
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
f32 temp = 2.0f * znear;
f32 rl_delta = right - left;
f32 tb_delta = top - bottom;
f32 fn_delta = zfar - znear;
matrix[0] = temp / rl_delta;
//matrix[1] = 0.0f;
@ -710,14 +710,14 @@ void mat4_frustum_sparse_rh(
}
void mat4_frustum_sparse_lh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
f32 *matrix,
f32 left, f32 right, f32 bottom, f32 top,
f32 znear, f32 zfar
) {
float temp = 2.0f * znear;
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
f32 temp = 2.0f * znear;
f32 rl_delta = right - left;
f32 tb_delta = top - bottom;
f32 fn_delta = zfar - znear;
matrix[0] = temp / rl_delta;
//matrix[1] = 0.0f;
@ -743,12 +743,12 @@ void mat4_frustum_sparse_lh(
// fov needs to be in rad
inline
void mat4_perspective_sparse_lh(
float *matrix, float fov, float aspect,
float znear, float zfar)
f32 *matrix, f32 fov, f32 aspect,
f32 znear, f32 zfar)
{
ASSERT_SIMPLE(znear > 0.0f);
float ymax, xmax;
f32 ymax, xmax;
ymax = znear * tanf(fov * 0.5f);
xmax = ymax * aspect;
@ -757,12 +757,12 @@ void mat4_perspective_sparse_lh(
inline
void mat4_perspective_sparse_rh(
float *matrix, float fov, float aspect,
float znear, float zfar)
f32 *matrix, f32 fov, f32 aspect,
f32 znear, f32 zfar)
{
ASSERT_SIMPLE(znear > 0.0f);
float ymax, xmax;
f32 ymax, xmax;
ymax = znear * tanf(fov * 0.5f);
xmax = ymax * aspect;
@ -770,13 +770,13 @@ void mat4_perspective_sparse_rh(
}
void mat4_ortho_sparse_lh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
f32 *matrix,
f32 left, f32 right, f32 bottom, f32 top,
f32 znear, f32 zfar
) {
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
f32 rl_delta = right - left;
f32 tb_delta = top - bottom;
f32 fn_delta = zfar - znear;
matrix[0] = 2.0f / rl_delta;
//matrix[1] = 0.0f;
@ -800,13 +800,13 @@ void mat4_ortho_sparse_lh(
}
void mat4_ortho_sparse_rh(
float *matrix,
float left, float right, float bottom, float top,
float znear, float zfar
f32 *matrix,
f32 left, f32 right, f32 bottom, f32 top,
f32 znear, f32 zfar
) {
float rl_delta = right - left;
float tb_delta = top - bottom;
float fn_delta = zfar - znear;
f32 rl_delta = right - left;
f32 tb_delta = top - bottom;
f32 fn_delta = zfar - znear;
matrix[0] = 2.0f / rl_delta;
//matrix[1] = 0.0f;
@ -829,12 +829,12 @@ void mat4_ortho_sparse_rh(
matrix[15] = 1.0f;
}
void mat4_translate(float* matrix, float dx, float dy, float dz)
void mat4_translate(f32* matrix, f32 dx, f32 dy, f32 dz)
{
float temp[16];
memcpy(temp, matrix, sizeof(float) * 16);
f32 temp[16];
memcpy(temp, matrix, sizeof(f32) * 16);
float translation_matrix[16];
f32 translation_matrix[16];
translation_matrix[0] = 1.0f; translation_matrix[1] = 0.0f; translation_matrix[2] = 0.0f; translation_matrix[3] = dx;
translation_matrix[4] = 0.0f; translation_matrix[5] = 1.0f; translation_matrix[6] = 0.0f; translation_matrix[7] = dy;
translation_matrix[8] = 0.0f; translation_matrix[9] = 0.0f; translation_matrix[10] = 1.0f; translation_matrix[11] = dz;
@ -843,12 +843,12 @@ void mat4_translate(float* matrix, float dx, float dy, float dz)
mat4mat4_mult(temp, translation_matrix, matrix);
}
void mat4_translate(float* matrix, float dx, float dy, float dz, int steps)
void mat4_translate(f32* matrix, f32 dx, f32 dy, f32 dz, int32 steps)
{
alignas(64) float temp[16];
memcpy(temp, matrix, sizeof(float) * 16);
alignas(64) f32 temp[16];
memcpy(temp, matrix, sizeof(f32) * 16);
alignas(64) float translation_matrix[16];
alignas(64) f32 translation_matrix[16];
translation_matrix[0] = 1.0f; translation_matrix[1] = 0.0f; translation_matrix[2] = 0.0f; translation_matrix[3] = dx;
translation_matrix[4] = 0.0f; translation_matrix[5] = 1.0f; translation_matrix[6] = 0.0f; translation_matrix[7] = dy;
translation_matrix[8] = 0.0f; translation_matrix[9] = 0.0f; translation_matrix[10] = 1.0f; translation_matrix[11] = dz;
@ -858,7 +858,7 @@ void mat4_translate(float* matrix, float dx, float dy, float dz, int steps)
}
inline
void mat4_translation(float* matrix, float dx, float dy, float dz)
void mat4_translation(f32* matrix, f32 dx, f32 dy, f32 dz)
{
matrix[0] = 1.0f; matrix[1] = 0.0f; matrix[2] = 0.0f; matrix[3] = dx;
matrix[4] = 0.0f; matrix[5] = 1.0f; matrix[6] = 0.0f; matrix[7] = dy;
@ -867,7 +867,7 @@ void mat4_translation(float* matrix, float dx, float dy, float dz)
}
inline
void mat4_translation_sparse(float* matrix, float dx, float dy, float dz)
void mat4_translation_sparse(f32* matrix, f32 dx, f32 dy, f32 dz)
{
matrix[3] = dx;
matrix[7] = dy;
@ -875,7 +875,7 @@ void mat4_translation_sparse(float* matrix, float dx, float dy, float dz)
}
inline
void mat4_scale(float* matrix, float dx, float dy, float dz)
void mat4_scale(f32* matrix, f32 dx, f32 dy, f32 dz)
{
matrix[0] = dx; matrix[1] = 0.0f; matrix[2] = 0.0f; matrix[3] = 0.0f;
matrix[4] = 0.0f; matrix[5] = dy; matrix[6] = 0.0f; matrix[7] = 0.0f;
@ -884,7 +884,7 @@ void mat4_scale(float* matrix, float dx, float dy, float dz)
}
inline
void mat4_scale_sparse(float* matrix, float dx, float dy, float dz)
void mat4_scale_sparse(f32* matrix, f32 dx, f32 dy, f32 dz)
{
matrix[0] = dx;
matrix[5] = dy;
@ -892,7 +892,7 @@ void mat4_scale_sparse(float* matrix, float dx, float dy, float dz)
}
inline
void mat4_transpose(const float* __restrict matrix, float* __restrict transposed)
void mat4_transpose(const f32* __restrict matrix, f32* __restrict transposed)
{
transposed[1] = matrix[4];
transposed[2] = matrix[8];
@ -909,9 +909,9 @@ void mat4_transpose(const float* __restrict matrix, float* __restrict transposed
}
inline
void mat4_transpose(float* matrix)
void mat4_transpose(f32* matrix)
{
float temp;
f32 temp;
temp = matrix[1];
matrix[1] = matrix[4];
@ -939,7 +939,7 @@ void mat4_transpose(float* matrix)
}
inline
void mat3_transpose(const float* __restrict matrix, float* __restrict transposed)
void mat3_transpose(const f32* __restrict matrix, f32* __restrict transposed)
{
transposed[1] = matrix[3];
transposed[2] = matrix[6];
@ -950,9 +950,9 @@ void mat3_transpose(const float* __restrict matrix, float* __restrict transposed
}
inline
void mat3_transpose(float* matrix)
void mat3_transpose(f32* matrix)
{
float temp;
f32 temp;
temp = matrix[1];
matrix[1] = matrix[3];
@ -968,16 +968,16 @@ void mat3_transpose(float* matrix)
}
inline
void mat2_transpose(const float* __restrict matrix, float* __restrict transposed)
void mat2_transpose(const f32* __restrict matrix, f32* __restrict transposed)
{
transposed[1] = matrix[2];
transposed[2] = matrix[1];
}
inline
void mat2_transpose(float* matrix)
void mat2_transpose(f32* matrix)
{
float temp = matrix[1];
f32 temp = matrix[1];
matrix[1] = matrix[2];
matrix[2] = temp;
}

View File

@ -28,19 +28,19 @@ void quaternion_unit(v4_f32* quat)
}
inline
void quaternion_from_euler(v4_f32* quat, float pitch, float yaw, float roll)
void quaternion_from_euler(v4_f32* quat, f32 pitch, f32 yaw, f32 roll)
{
float y = OMS_DEG2RAD(yaw);
float cy = cosf(y / 2);
float sy = sinf(y / 2);
f32 y = OMS_DEG2RAD(yaw);
f32 cy = cosf(y / 2);
f32 sy = sinf(y / 2);
float p = OMS_DEG2RAD(pitch);
float cp = cosf(p / 2);
float sp = sinf(p / 2);
f32 p = OMS_DEG2RAD(pitch);
f32 cp = cosf(p / 2);
f32 sp = sinf(p / 2);
float r = OMS_DEG2RAD(roll);
float cr = cosf(r / 2);
float sr = sinf(r / 2);
f32 r = OMS_DEG2RAD(roll);
f32 cr = cosf(r / 2);
f32 sr = sinf(r / 2);
quat->w = cr * cp * cy + sr * sp * sy;
quat->x = sr * cp * cy - cr * sp * sy;
@ -53,17 +53,17 @@ void quaternion_from_euler(v4_f32* quat, float pitch, float yaw, float roll)
inline
void quaternion_from_euler(v4_f32* __restrict quat, const v3_f32* __restrict v)
{
float y = OMS_RAD2DEG(v->v / 2);
float cy = cosf(y);
float sy = sinf(y);
f32 y = OMS_RAD2DEG(v->v / 2);
f32 cy = cosf(y);
f32 sy = sinf(y);
float p = OMS_RAD2DEG(v->u * 0.5f);
float cp = cosf(p);
float sp = sinf(p);
f32 p = OMS_RAD2DEG(v->u * 0.5f);
f32 cp = cosf(p);
f32 sp = sinf(p);
float r = OMS_RAD2DEG(v->w * 0.5f);
float cr = cosf(r);
float sr = sinf(r);
f32 r = OMS_RAD2DEG(v->w * 0.5f);
f32 cr = cosf(r);
f32 sr = sinf(r);
quat->w = cr * cp * cy + sr * sp * sy;
quat->x = sr * cp * cy - cr * sp * sy;
@ -72,9 +72,9 @@ void quaternion_from_euler(v4_f32* __restrict quat, const v3_f32* __restrict v)
}
inline
void quaternion_from_axis_angle(v4_f32* quat, const v3_f32* __restrict axis, float rad) {
float half_angle = rad / 2.0f;
float s = sinf(half_angle);
void quaternion_from_axis_angle(v4_f32* quat, const v3_f32* __restrict axis, f32 rad) {
f32 half_angle = rad / 2.0f;
f32 s = sinf(half_angle);
quat->x = axis->x * s;
quat->y = axis->y * s;
@ -86,8 +86,8 @@ void quaternion_from_axis_angle(v4_f32* quat, const v3_f32* __restrict axis, flo
void quaternion_to_euler(const v4_f32* __restrict quat, v3_f32* __restrict v) {
// Pitch
float sinp = 2.0f * (quat->w * quat->x + quat->y * quat->z);
float cosp = 1.0f - 2.0f * (quat->x * quat->x + quat->y * quat->y);
f32 sinp = 2.0f * (quat->w * quat->x + quat->y * quat->z);
f32 cosp = 1.0f - 2.0f * (quat->x * quat->x + quat->y * quat->y);
v->pitch = atan2f(sinp, cosp);
// Check for gimbal lock
@ -96,12 +96,12 @@ void quaternion_to_euler(const v4_f32* __restrict quat, v3_f32* __restrict v) {
v->roll = 0.0f;
} else {
// Yaw
float siny = 2.0f * (quat->w * quat->y - quat->z * quat->x);
f32 siny = 2.0f * (quat->w * quat->y - quat->z * quat->x);
v->yaw = asinf(siny);
// Roll
float sinr = 2.0f * (quat->w * quat->z + quat->x * quat->y);
float cosr = 1.0f - 2.0f * (quat->y * quat->y + quat->z * quat->z);
f32 sinr = 2.0f * (quat->w * quat->z + quat->x * quat->y);
f32 cosr = 1.0f - 2.0f * (quat->y * quat->y + quat->z * quat->z);
v->roll = atan2f(sinr, cosr);
}
}
@ -115,7 +115,7 @@ void quaternion_multiply(v4_f32* __restrict quat, const v4_f32* __restrict quat1
}
void quaternion_inverse(v4_f32* __restrict quat, const v4_f32* __restrict quat_origin) {
float norm = quat_origin->w * quat_origin->w
f32 norm = quat_origin->w * quat_origin->w
+ quat_origin->x * quat_origin->x
+ quat_origin->y * quat_origin->y
+ quat_origin->z * quat_origin->z;
@ -245,7 +245,7 @@ void quaternion_rotate_passive(v4_f32* __restrict p, const v4_f32* __restrict qu
// 5. call quat_rotate_*
// 6. convert quat to vec
// @todo Since this is usually done on multiple vecs, we should probably accept an array of vecs and then use simd
void quaternion_rotate_active(v3_f32* vec, float pitch, float yaw, float roll)
void quaternion_rotate_active(v3_f32* vec, f32 pitch, f32 yaw, f32 roll)
{
v4_f32 q;
quaternion_from_euler(&q, pitch, yaw, roll); // q is already in unit length
@ -262,7 +262,7 @@ void quaternion_rotate_active(v3_f32* vec, float pitch, float yaw, float roll)
vec->z = p.z;
}
void quaternion_rotate_active(v4_f32* quat, float pitch, float yaw, float roll)
void quaternion_rotate_active(v4_f32* quat, f32 pitch, f32 yaw, f32 roll)
{
v4_f32 q;
quaternion_from_euler(&q, pitch, yaw, roll); // q is already in unit length
@ -273,7 +273,7 @@ void quaternion_rotate_active(v4_f32* quat, float pitch, float yaw, float roll)
quaternion_rotate_active(quat, &q, &q_inv);
}
void quaternion_rotate_passive(v3_f32* vec, float pitch, float yaw, float roll)
void quaternion_rotate_passive(v3_f32* vec, f32 pitch, f32 yaw, f32 roll)
{
v4_f32 q;
quaternion_from_euler(&q, pitch, yaw, roll); // q is already in unit length
@ -290,7 +290,7 @@ void quaternion_rotate_passive(v3_f32* vec, float pitch, float yaw, float roll)
vec->z = p.z;
}
void quaternion_rotate_passive(v4_f32* quat, float pitch, float yaw, float roll)
void quaternion_rotate_passive(v4_f32* quat, f32 pitch, f32 yaw, f32 roll)
{
v4_f32 q;
quaternion_from_euler(&q, pitch, yaw, roll); // q is already in unit length

View File

@ -32,7 +32,7 @@
}
inline
void* playform_alloc_aligned(size_t size, int alignment)
void* playform_alloc_aligned(size_t size, int32 alignment)
{
void* ptr = VirtualAlloc(NULL, size + alignment + sizeof(void*), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
@ -77,7 +77,7 @@
}
inline
void* playform_alloc_aligned(size_t size, int alignment)
void* playform_alloc_aligned(size_t size, int32 alignment)
{
// Get the system page size
size_t page_size = sysconf(_SC_PAGESIZE);

View File

@ -23,12 +23,12 @@ struct BufferMemory {
uint64 size;
uint64 pos;
int alignment;
int element_alignment;
int32 alignment;
int32 element_alignment;
};
inline
void buffer_alloc(BufferMemory* buf, uint64 size, int alignment = 64)
void buffer_alloc(BufferMemory* buf, uint64 size, int32 alignment = 64)
{
buf->memory = alignment < 2
? (byte *) playform_alloc(size)
@ -60,7 +60,7 @@ void buffer_reset(BufferMemory* buf)
}
inline
byte* buffer_get_memory(BufferMemory* buf, uint64 size, int aligned = 0, bool zeroed = false)
byte* buffer_get_memory(BufferMemory* buf, uint64 size, int32 aligned = 0, bool zeroed = false)
{
ASSERT_SIMPLE(size <= buf->size);

View File

@ -22,7 +22,7 @@ struct ChunkMemory {
uint64 size;
uint64 chunk_size;
int64 last_pos;
int alignment;
int32 alignment;
// length = count
// free describes which locations are used and which are free
@ -30,7 +30,7 @@ struct ChunkMemory {
};
inline
void chunk_alloc(ChunkMemory* buf, uint64 count, uint64 chunk_size, int alignment = 64)
void chunk_alloc(ChunkMemory* buf, uint64 count, uint64 chunk_size, int32 alignment = 64)
{
buf->memory = alignment < 2
? (byte *) playform_alloc(count * chunk_size + sizeof(buf->free) * CEIL_DIV(count, 64))
@ -77,12 +77,12 @@ byte* chunk_get_element(ChunkMemory* buf, uint64 element, bool zeroed = false)
void chunk_reserve_index(ChunkMemory* buf, int64 index, int64 elements = 1, bool zeroed = false)
{
int64 byte_index = index / 64;
int bit_index = index % 64;
int32 bit_index = index % 64;
// Mark the bits as reserved
for (int j = 0; j < elements; ++j) {
for (int32 j = 0; j < elements; ++j) {
int64 current_byte_index = byte_index + (bit_index + j) / 64;
int current_bit_index = (bit_index + j) % 64;
int32 current_bit_index = (bit_index + j) % 64;
buf->free[current_byte_index] |= (1LL << current_bit_index);
}
@ -98,12 +98,12 @@ void chunk_reserve_index(ChunkMemory* buf, int64 index, int64 elements = 1, bool
int64 chunk_reserve(ChunkMemory* buf, uint64 elements = 1, bool zeroed = false)
{
int64 byte_index = (buf->last_pos + 1) / 64;
int bit_index;
int32 bit_index;
int64 free_element = -1;
byte mask;
int i = 0;
int32 i = 0;
int64 max_bytes = (buf->count + 7) / 64;
while (free_element < 0 && i < buf->count) {
@ -121,12 +121,12 @@ int64 chunk_reserve(ChunkMemory* buf, uint64 elements = 1, bool zeroed = false)
// @performance There is some redundancy happening down below, we should ++byte_index in certain conditions?
for (bit_index = 0; bit_index < 64; ++bit_index) {
int consecutive_free_bits = 0;
int32 consecutive_free_bits = 0;
// Check if there are 'elements' consecutive free bits
for (int j = 0; j < elements; ++j) {
for (int32 j = 0; j < elements; ++j) {
uint64 current_byte_index = byte_index + (bit_index + j) / 64;
int current_bit_index = (bit_index + j) % 64;
int32 current_bit_index = (bit_index + j) % 64;
if (current_byte_index >= (buf->count + 7) / 64) {
break;
@ -144,9 +144,9 @@ int64 chunk_reserve(ChunkMemory* buf, uint64 elements = 1, bool zeroed = false)
free_element = byte_index * 64 + bit_index;
// Mark the bits as reserved
for (int j = 0; j < elements; ++j) {
for (int32 j = 0; j < elements; ++j) {
int64 current_byte_index = byte_index + (bit_index + j) / 64;
int current_bit_index = (bit_index + j) % 64;
int32 current_bit_index = (bit_index + j) % 64;
buf->free[current_byte_index] |= (1LL << current_bit_index);
}
@ -176,12 +176,12 @@ int64 chunk_reserve(ChunkMemory* buf, uint64 elements = 1, bool zeroed = false)
byte* chunk_find_free(ChunkMemory* buf)
{
int64 byte_index = (buf->last_pos + 1) / 64;
int bit_index;
int32 bit_index;
int64 free_element = -1;
byte mask;
int i = 0;
int32 i = 0;
int64 max_bytes = (buf->count + 7) / 64;
while (free_element < 0 && i < buf->count) {
@ -223,7 +223,7 @@ void chunk_free_element(ChunkMemory* buf, uint64 element)
DEBUG_MEMORY_DELETE((uint64) (buf->memory + element * buf->chunk_size), buf->chunk_size);
int64 byte_index = element / 64;
int bit_index = element % 64;
int32 bit_index = element % 64;
buf->free[byte_index] &= ~(1 << bit_index);
}

View File

@ -24,8 +24,8 @@ struct RingMemory {
uint64 size;
uint64 pos;
int alignment;
int element_alignment;
int32 alignment;
int32 element_alignment;
// The following two indices are only used in special cases such as iterating through a portion
// of the ring memory. In such cases it may be necessary to know where the start and end are.
@ -40,7 +40,7 @@ struct RingMemory {
};
inline
void ring_alloc(RingMemory* ring, uint64 size, int alignment = 64)
void ring_alloc(RingMemory* ring, uint64 size, int32 alignment = 64)
{
ring->memory = alignment < 2
? (byte *) playform_alloc(size)
@ -56,7 +56,7 @@ void ring_alloc(RingMemory* ring, uint64 size, int alignment = 64)
}
inline
void ring_create(RingMemory* ring, BufferMemory* buf, uint64 size, int alignment = 64)
void ring_create(RingMemory* ring, BufferMemory* buf, uint64 size, int32 alignment = 64)
{
ring->memory = buffer_get_memory(buf, size, alignment);

View File

@ -13,7 +13,7 @@
struct ObjFile {
// Amount of references to this object
int references;
int32 references;
bool facing; // front or back

View File

@ -14,7 +14,7 @@
#include "BracketMatch.h"
struct SimpleBracket {
int size;
int32 size;
BracketMatch* matches;
BracketSeeding seeding;
};
@ -26,13 +26,13 @@ struct DoubleEliminationBracket {
void bracket_single_elim_create(SimpleBracket* bracket)
{
for (int i = 0; i < bracket->size / 2; ++i) {
for (int32 i = 0; i < bracket->size / 2; ++i) {
bracket->matches[i].teams[0] = &bracket->seeding.teams[bracket->seeding.team_seedings[i]];
bracket->matches[i].teams[1] = &bracket->seeding.teams[bracket->seeding.team_seedings[bracket->size - i - 1]];
}
int j = 0;
for (int i = bracket->size / 2; bracket->size - 1; ++i) {
int32 j = 0;
for (int32 i = bracket->size / 2; bracket->size - 1; ++i) {
bracket->matches[i].teams[0] = bracket->matches[j].winner;
bracket->matches[i].teams[0] = bracket->matches[++j].winner;
++j;
@ -43,8 +43,8 @@ void bracket_double_elim_create(DoubleEliminationBracket* bracket)
{
bracket_single_elim_create(&bracket->winners_bracket);
int match_index = 0;
for (int i = 0; i < bracket->winners_bracket.size - 1; ++i) {
int32 match_index = 0;
for (int32 i = 0; i < bracket->winners_bracket.size - 1; ++i) {
if (i % 2 == 0) {
bracket->losers_bracket.matches[match_index].teams[0] = bracket->winners_bracket.matches[i].loser;
bracket->losers_bracket.matches[match_index].teams[1] = bracket->winners_bracket.matches[i + 1].loser;
@ -56,8 +56,8 @@ void bracket_double_elim_create(DoubleEliminationBracket* bracket)
}
}
int j = 0;
for (int i = match_index; i < bracket->losers_bracket.size - 1; ++i) {
int32 j = 0;
for (int32 i = match_index; i < bracket->losers_bracket.size - 1; ++i) {
bracket->losers_bracket.matches[i].teams[0] = bracket->losers_bracket.matches[j].winner;
bracket->losers_bracket.matches[i].teams[1] = bracket->losers_bracket.matches[++j].winner;
++j;

View File

@ -12,7 +12,7 @@
#include "../../stdlib/Types.h"
struct BracketTeam {
int size;
int32 size;
uint64* player_ids;
uint32 rating;
};

View File

@ -35,11 +35,11 @@ static const int grad3_3[12][3] = {
{0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}
};
static inline double simplex_noise_dot2(const int* g, double x, double y) {
static inline double simplex_noise_dot2(const int32* g, double x, double y) {
return g[0] * x + g[1] * y;
}
static inline double simplex_noise_dot3(const int* g, double x, double y, double z) {
static inline double simplex_noise_dot3(const int32* g, double x, double y, double z) {
return g[0] * x + g[1] * y + g[2] * z;
}
@ -48,8 +48,8 @@ double simplex_noise_2d(double x, double y) {
// Skew the input space to determine which simplex cell we're in
double s = (x + y) * SIMPLEX_NOISE_F2; // Hairy factor for 2D
int i = floor(x + s);
int j = floor(y + s);
int32 i = floor(x + s);
int32 j = floor(y + s);
double t = (i + j) * SIMPLEX_NOISE_G2;
double X0 = i - t; // Unskew the cell origin back to (x, y) space
@ -59,7 +59,7 @@ double simplex_noise_2d(double x, double y) {
// For the 2D case, the simplex shape is an equilateral triangle.
// Determine which simplex we are in.
int i1, j1; // Offsets for the second (middle) corner of simplex in (i, j)
int32 i1, j1; // Offsets for the second (middle) corner of simplex in (i, j)
if (x0 > y0) {
i1 = 1; j1 = 0; // Lower triangle, XY order
} else {
@ -76,11 +76,11 @@ double simplex_noise_2d(double x, double y) {
double y2 = y0 - 1.0 + 2.0 * SIMPLEX_NOISE_G2;
// Work out the hashed gradient indices of the three simplex corners
int ii = i & 255;
int jj = j & 255;
int gi0 = perm[ii + perm[jj]] % 12;
int gi1 = perm[ii + i1 + perm[jj + j1]] % 12;
int gi2 = perm[ii + 1 + perm[jj + 1]] % 12;
int32 ii = i & 255;
int32 jj = j & 255;
int32 gi0 = perm[ii + perm[jj]] % 12;
int32 gi1 = perm[ii + i1 + perm[jj + j1]] % 12;
int32 gi2 = perm[ii + 1 + perm[jj + 1]] % 12;
// Calculate the contribution from the three corners
double t0 = 0.5 - x0 * x0 - y0 * y0;

View File

@ -36,10 +36,10 @@ void object_from_file_txt(
char* pos = (char *) file.content;
int object_index = 0;
int group_index = 0;
int32 object_index = 0;
int32 group_index = 0;
mesh->vertices = (float *) mesh->data;
mesh->vertices = (f32 *) mesh->data;
mesh->vertex_count = 0;
mesh->normal_count = 0;
@ -66,7 +66,7 @@ void object_from_file_txt(
// Parse type
// WARNING: The code below could fail if [1] is outside of range
// However that should never happen for well formed files
int state = 0;
int32 state = 0;
if (*pos == 'v' && pos[1] == ' ') {
state = 1;
} else if (*pos == 'v' && pos[1] == 'n') {
@ -199,7 +199,7 @@ void object_from_file_txt(
case 5: {
// 'o'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -217,7 +217,7 @@ void object_from_file_txt(
mesh->faces = (uint32 *) (mesh->vertices + mesh->vertex_count * 3 + mesh->normal_count * 3 + mesh->tex_coord_count * 2 + mesh->color_count * 4);
}
int ftype = 0;
int32 ftype = 0;
char* tmp = pos;
while (*tmp != ' ') {
if (*tmp++ == '/') {
@ -230,8 +230,8 @@ void object_from_file_txt(
}
}
const int max_blocks = 3; // @todo this could actually be N. Might have to change in the future
int block = 0;
const int32 max_blocks = 3; // @todo this could actually be N. Might have to change in the future
int32 block = 0;
while (*pos != '\0' && *pos != '\n') {
if (ftype == 0) {
@ -277,7 +277,7 @@ void object_from_file_txt(
case 8: {
// 'g'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -294,7 +294,7 @@ void object_from_file_txt(
case 10: {
// 'mtllib'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -303,7 +303,7 @@ void object_from_file_txt(
case 11: {
// 'hitlib'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -312,7 +312,7 @@ void object_from_file_txt(
case 12: {
// 'anilib'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -321,7 +321,7 @@ void object_from_file_txt(
case 13: {
// 'usemtl'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -330,7 +330,7 @@ void object_from_file_txt(
case 14: {
// 'usehit'
char text[100];
int i = 0;
int32 i = 0;
while (*pos != '\0' && *pos != ' ') {
text[i++] = *pos++;
}
@ -357,8 +357,8 @@ int32 object_from_file(
const char* path,
Mesh* mesh,
const char* group = NULL,
int load_format = OBJECT_LOADING_RESTRICTION_EVERYTHING,
int size = 8
int32 load_format = OBJECT_LOADING_RESTRICTION_EVERYTHING,
int32 size = 8
)
{
FileBody file;
@ -367,19 +367,19 @@ int32 object_from_file(
byte* pos = file.content;
// Read base data
mesh->vertex_type = *((int *) pos);
mesh->vertex_type = *((int32 *) pos);
pos += sizeof(mesh->vertex_type);
mesh->vertex_count = *((int *) pos);
mesh->vertex_count = *((int32 *) pos);
pos += sizeof(mesh->vertex_count);
mesh->normal_count = *((int *) pos);
mesh->normal_count = *((int32 *) pos);
pos += sizeof(mesh->normal_count);
mesh->tex_coord_count = *((int *) pos);
mesh->tex_coord_count = *((int32 *) pos);
pos += sizeof(mesh->tex_coord_count);
mesh->color_count = *((int *) pos);
mesh->color_count = *((int32 *) pos);
pos += sizeof(mesh->color_count);
#if !_WIN32 && !__LITTLE_ENDIAN
@ -407,53 +407,53 @@ int32 object_from_file(
vertex_size += 4;
}
int offset = 0;
int32 offset = 0;
if (mesh->vertex_count > 0) {
memcpy(mesh->data, pos, sizeof(float) * vertex_size * mesh->vertex_count);
mesh->vertices = (float *) mesh->data;
memcpy(mesh->data, pos, sizeof(f32) * vertex_size * mesh->vertex_count);
mesh->vertices = (f32 *) mesh->data;
pos += sizeof(float) * vertex_size * mesh->vertex_count;
offset += sizeof(float) * vertex_size * mesh->vertex_count;
pos += sizeof(f32) * vertex_size * mesh->vertex_count;
offset += sizeof(f32) * vertex_size * mesh->vertex_count;
}
if (mesh->normal_count > 0) {
memcpy(mesh->data + offset, pos, sizeof(float) * 3 * mesh->normal_count);
mesh->normals = (float *) (mesh->data + offset);
memcpy(mesh->data + offset, pos, sizeof(f32) * 3 * mesh->normal_count);
mesh->normals = (f32 *) (mesh->data + offset);
pos += sizeof(float) * 3 * mesh->normal_count;
offset += sizeof(float) * 3 * mesh->normal_count;
pos += sizeof(f32) * 3 * mesh->normal_count;
offset += sizeof(f32) * 3 * mesh->normal_count;
}
if (mesh->tex_coord_count > 0) {
memcpy(mesh->data + offset, pos, sizeof(float) * 3 * mesh->tex_coord_count);
mesh->tex_coords = (float *) (mesh->data + offset);
memcpy(mesh->data + offset, pos, sizeof(f32) * 3 * mesh->tex_coord_count);
mesh->tex_coords = (f32 *) (mesh->data + offset);
pos += sizeof(float) * 2 * mesh->tex_coord_count;
offset += sizeof(float) * 2 * mesh->tex_coord_count;
pos += sizeof(f32) * 2 * mesh->tex_coord_count;
offset += sizeof(f32) * 2 * mesh->tex_coord_count;
}
if (mesh->color_count > 0) {
memcpy(mesh->data + offset, pos, sizeof(float) * 4 * mesh->color_count);
mesh->colors = (float *) (mesh->data + offset);
memcpy(mesh->data + offset, pos, sizeof(f32) * 4 * mesh->color_count);
mesh->colors = (f32 *) (mesh->data + offset);
pos += sizeof(float) * 4 * mesh->color_count;
offset += sizeof(float) * 4 * mesh->color_count;
pos += sizeof(f32) * 4 * mesh->color_count;
offset += sizeof(f32) * 4 * mesh->color_count;
}
// Read face data
mesh->face_type = *((int *) pos);
mesh->face_type = *((int32 *) pos);
pos += sizeof(mesh->face_type);
mesh->face_count = *((int *) pos);
mesh->face_count = *((int32 *) pos);
pos += sizeof(mesh->face_count);
mesh->face_normal_count = *((int *) pos);
mesh->face_normal_count = *((int32 *) pos);
pos += sizeof(mesh->face_normal_count);
mesh->face_tex_coord_count = *((int *) pos);
mesh->face_tex_coord_count = *((int32 *) pos);
pos += sizeof(mesh->face_tex_coord_count);
mesh->face_color_count = *((int *) pos);
mesh->face_color_count = *((int32 *) pos);
pos += sizeof(mesh->face_color_count);
#if !_WIN32 && !__LITTLE_ENDIAN
@ -464,7 +464,7 @@ int32 object_from_file(
mesh->face_color_count = endian_swap(mesh->face_color_count);
#endif
int face_size = 0;
int32 face_size = 0;
if (mesh->face_type & FACE_TYPE_VERTICES) {
face_size += 3;
}
@ -520,8 +520,8 @@ int32 object_from_file(
}
SWAP_ENDIAN_LITTLE_SIMD(
(int *) mesh->data,
(int *) mesh->data,
(int32 *) mesh->data,
(int32 *) mesh->data,
offset / 4, // everything is 4 bytes -> super easy to swap
steps
);
@ -533,15 +533,15 @@ void object_to_file(
RingMemory* ring,
const char* path,
const Mesh* mesh,
int vertex_save_format = VERTEX_TYPE_POSITION,
int face_save_format = FACE_TYPE_VERTICES,
int size = 8
int32 vertex_save_format = VERTEX_TYPE_POSITION,
int32 face_save_format = FACE_TYPE_VERTICES,
int32 size = 8
)
{
FileBody file;
// Temporary file size for buffer
file.size = sizeof(mesh) + sizeof(Vertex3D) * mesh->vertex_count + sizeof(float) * 12 * mesh->vertex_count + 4096;
file.size = sizeof(mesh) + sizeof(Vertex3D) * mesh->vertex_count + sizeof(f32) * 12 * mesh->vertex_count + 4096;
file.content = ring_get_memory(ring, file.size, 64);
byte* pos = file.content;
@ -577,7 +577,7 @@ void object_to_file(
// verticies
if (mesh->vertex_count > 0) {
int vertex_size = 0;
int32 vertex_size = 0;
if (mesh->vertex_type & VERTEX_TYPE_POSITION) {
vertex_size += 3;
}
@ -594,7 +594,7 @@ void object_to_file(
vertex_size += 4;
}
int out_vertex_size = 0;
int32 out_vertex_size = 0;
if (vertex_save_format & VERTEX_TYPE_POSITION) {
out_vertex_size += 3;
}
@ -615,19 +615,19 @@ void object_to_file(
|| (mesh->vertex_type == VERTEX_TYPE_POSITION && vertex_save_format == VERTEX_TYPE_POSITION)
) {
// data is the same as in the array
memcpy(pos, mesh->vertices, vertex_size * sizeof(float) * mesh->vertex_count);
pos += vertex_size * sizeof(float) * mesh->vertex_count;
memcpy(pos, mesh->vertices, vertex_size * sizeof(f32) * mesh->vertex_count);
pos += vertex_size * sizeof(f32) * mesh->vertex_count;
} else {
float* temp = mesh->vertices;
float* end = mesh->vertices + mesh->vertex_count * vertex_size;
f32* temp = mesh->vertices;
f32* end = mesh->vertices + mesh->vertex_count * vertex_size;
int offset;
int32 offset;
byte* vertice_start = pos;
// @bug index gets increased every iteration BUT different groups and objects in the source may have different data
// This comes again down to how to handle hierarchal data with multiple groups and objects
int index = 0;
int32 index = 0;
// iterate over all vertices to create new output format
while (temp < end) {
@ -637,13 +637,13 @@ void object_to_file(
// First we save everything in one large array if that is the setting
if (vertex_save_format & VERTEX_TYPE_POSITION) {
if (mesh->vertex_type & VERTEX_TYPE_POSITION) {
memcpy(pos, temp, sizeof(float) * 3);
pos += sizeof(float) * 3;
memcpy(pos, temp, sizeof(f32) * 3);
pos += sizeof(f32) * 3;
offset += 3;
} else {
memset(pos, 0, sizeof(float) * 3);
pos += sizeof(float) * 3;
memset(pos, 0, sizeof(f32) * 3);
pos += sizeof(f32) * 3;
}
}
@ -651,19 +651,19 @@ void object_to_file(
if ((mesh->vertex_type & VERTEX_TYPE_NORMAL) && !(vertex_save_format & VERTEX_TYPE_NORMAL)) {
// go to end of vertices * shift by previous array sizes + shift by current vertex -> creates one continous array with this data
memcpy(vertice_start
+ sizeof(float) * out_vertex_size * mesh->vertex_count
+ index * sizeof(float) * 3, temp + offset, sizeof(float) * 3);
+ sizeof(f32) * out_vertex_size * mesh->vertex_count
+ index * sizeof(f32) * 3, temp + offset, sizeof(f32) * 3);
offset += 3;
} else if (vertex_save_format & VERTEX_TYPE_NORMAL) {
if (mesh->vertex_type & VERTEX_TYPE_NORMAL) {
memcpy(pos, temp + offset, sizeof(float) * 3);
pos += sizeof(float) * 3;
memcpy(pos, temp + offset, sizeof(f32) * 3);
pos += sizeof(f32) * 3;
offset += 3;
} else {
memset(pos, 0, sizeof(float) * 3);
pos += sizeof(float) * 3;
memset(pos, 0, sizeof(f32) * 3);
pos += sizeof(f32) * 3;
}
}
@ -671,20 +671,20 @@ void object_to_file(
if ((mesh->vertex_type & VERTEX_TYPE_TEXTURE_COORD) && !(vertex_save_format & VERTEX_TYPE_TEXTURE_COORD)) {
// go to end of vertices * shift by previous array sizes + shift by current vertex -> creates one continous array with this data
memcpy(vertice_start
+ sizeof(float) * out_vertex_size * mesh->vertex_count
+ sizeof(float) * normal_count * 3
+ index * sizeof(float) * 3, temp + offset, sizeof(float) * 3);
+ sizeof(f32) * out_vertex_size * mesh->vertex_count
+ sizeof(f32) * normal_count * 3
+ index * sizeof(f32) * 3, temp + offset, sizeof(f32) * 3);
offset += 2;
} else if (vertex_save_format & VERTEX_TYPE_TEXTURE_COORD) {
if (mesh->vertex_type & VERTEX_TYPE_TEXTURE_COORD) {
memcpy(pos, temp + offset, sizeof(float) * 2);
pos += sizeof(float) * 2;
memcpy(pos, temp + offset, sizeof(f32) * 2);
pos += sizeof(f32) * 2;
offset += 2;
} else {
memset(pos, 0, sizeof(float) * 2);
pos += sizeof(float) * 2;
memset(pos, 0, sizeof(f32) * 2);
pos += sizeof(f32) * 2;
}
}
@ -692,21 +692,21 @@ void object_to_file(
if ((mesh->vertex_type & VERTEX_TYPE_COLOR) && !(vertex_save_format & VERTEX_TYPE_COLOR)) {
// go to end of vertices * shift by previous array sizes + shift by current vertex -> creates one continous array with this data
memcpy(vertice_start
+ sizeof(float) * out_vertex_size * mesh->vertex_count
+ sizeof(float) * normal_count * 3
+ sizeof(float) * tex_coord_count * 2
+ index * sizeof(float) * 4, temp + offset, sizeof(float) * 4);
+ sizeof(f32) * out_vertex_size * mesh->vertex_count
+ sizeof(f32) * normal_count * 3
+ sizeof(f32) * tex_coord_count * 2
+ index * sizeof(f32) * 4, temp + offset, sizeof(f32) * 4);
offset += 4;
} else if (vertex_save_format & VERTEX_TYPE_COLOR) {
if (mesh->vertex_type & VERTEX_TYPE_COLOR) {
memcpy(pos, temp + offset, sizeof(float) * 4);
pos += sizeof(float) * 4;
memcpy(pos, temp + offset, sizeof(f32) * 4);
pos += sizeof(f32) * 4;
offset += 4;
} else {
memset(pos, 0, sizeof(float) * 4);
pos += sizeof(float) * 4;
memset(pos, 0, sizeof(f32) * 4);
pos += sizeof(f32) * 4;
}
}
@ -717,18 +717,18 @@ void object_to_file(
// check if we have clean array data already -> output this array data directly
if (mesh->normals && mesh->normal_count > 0) {
memcpy(pos, mesh->normals, mesh->normal_count * sizeof(float) * 3);
pos += mesh->normal_count * sizeof(float) * 3;
memcpy(pos, mesh->normals, mesh->normal_count * sizeof(f32) * 3);
pos += mesh->normal_count * sizeof(f32) * 3;
}
if (mesh->tex_coords && mesh->tex_coord_count > 0) {
memcpy(pos, mesh->tex_coords, mesh->tex_coord_count * sizeof(float) * 2);
pos += mesh->tex_coord_count * sizeof(float) * 2;
memcpy(pos, mesh->tex_coords, mesh->tex_coord_count * sizeof(f32) * 2);
pos += mesh->tex_coord_count * sizeof(f32) * 2;
}
if (mesh->colors && mesh->color_count > 0) {
memcpy(pos, mesh->colors, mesh->color_count * sizeof(float) * 4);
pos += mesh->color_count * sizeof(float) * 4;
memcpy(pos, mesh->colors, mesh->color_count * sizeof(f32) * 4);
pos += mesh->color_count * sizeof(f32) * 4;
}
}
@ -764,7 +764,7 @@ void object_to_file(
if (mesh->face_count > 0) {
// WARNING: Carefull, we again assume only 3 elements per face
int face_size = 0;
int32 face_size = 0;
if (mesh->face_type & FACE_TYPE_VERTICES) {
face_size += 3;
}
@ -781,7 +781,7 @@ void object_to_file(
face_size += 3;
}
int out_face_size = 0;
int32 out_face_size = 0;
if (face_save_format & FACE_TYPE_VERTICES) {
out_face_size += 3;
}
@ -808,13 +808,13 @@ void object_to_file(
uint32* temp = mesh->faces;
uint32* end = mesh->faces + mesh->face_count * face_size;
int offset;
int32 offset;
byte* face_start = pos;
// @bug index gets increased every iteration BUT different groups and objects in the source may have different data
// This comes again down to how to handle hierarchal data with multiple groups and objects
int index = 0;
int32 index = 0;
// iterate over all faces to create new output format
// one iteration represents 1 block (a block could be v/vt/vn or, v, or v//vn, ...)
@ -830,8 +830,8 @@ void object_to_file(
offset += 1;
} else {
memset(pos, 0, sizeof(float));
pos += sizeof(float);
memset(pos, 0, sizeof(f32));
pos += sizeof(f32);
}
}
@ -923,8 +923,8 @@ void object_to_file(
file.size = pos - file.content;
SWAP_ENDIAN_LITTLE_SIMD(
(int *) file.content,
(int *) file.content,
(int32 *) file.content,
(int32 *) file.content,
(pos - file.content) / 4, // everything in here is 4 bytes -> super easy to swap
steps
);

View File

@ -18,6 +18,12 @@ struct Vertex3D {
v4_f32 color;
};
struct Vertex3DTextureColorIndex {
v3_f32 position;
v2_int32 tex_coord;
f32 color;
};
struct Vertex3DColorIndex {
v3_f32 position;
uint32 color;
@ -44,7 +50,7 @@ struct Vertex2DColorIndex {
// @bug opengl shaders don't support individual bytes,
// otherwise we would use byte here for 256 color palettes.
// Which is bad since the purpose of this was to save 3 bytes by using a color palette
float color;
f32 color;
};
struct VertexRef {

View File

@ -17,51 +17,51 @@
#include "../utils/MathUtils.h"
#include "../memory/RingMemory.h"
float manhattan_2d(v2_f32 a, v2_f32 b) {
f32 manhattan_2d(v2_f32 a, v2_f32 b) {
return fabs(a.x - b.x) + fabs(a.y - b.y);
}
float euclidean_2d(v2_f32 a, v2_f32 b) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
f32 euclidean_2d(v2_f32 a, v2_f32 b) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
return sqrt(dx * dx + dy * dy);
}
float octile_2d(v2_f32 a, v2_f32 b) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
f32 octile_2d(v2_f32 a, v2_f32 b) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
return dx < dy
? (SQRT_2 - 1) * dx + dy
: (SQRT_2 - 1) * dy + dx;
}
float chebyshev_2d(v2_f32 a, v2_f32 b) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
f32 chebyshev_2d(v2_f32 a, v2_f32 b) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
return fmax(dx, dy);
}
float minkowski_2d(v2_f32 a, v2_f32 b, int lambda) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
f32 minkowski_2d(v2_f32 a, v2_f32 b, int32 lambda) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
return pow(pow(dx, lambda) + pow(dy, lambda), 1.0 / lambda);
}
float canberra_2d(v2_f32 a, v2_f32 b) {
f32 canberra_2d(v2_f32 a, v2_f32 b) {
return (fabs(a.x - b.x) / (fabs(a.x) + fabs(b.x)))
+ (fabs(a.y - b.y) / (fabs(a.y) + fabs(b.y)));
}
float bray_curtis_2d(v2_f32 a, v2_f32 b) {
f32 bray_curtis_2d(v2_f32 a, v2_f32 b) {
return (fabs(a.x - b.x) + fabs(a.y - b.y))
/ ((a.x + b.x) + (a.y + b.y));
}
float angular_separation_2d(v2_f32 a, v2_f32 b) {
f32 angular_separation_2d(v2_f32 a, v2_f32 b) {
return (a.x * b.x + a.y * b.y)
/ (sqrt(a.x * a.x + a.y * a.y) * sqrt(b.x * b.x + b.y * b.y));
}

View File

@ -17,35 +17,35 @@
#include "../memory/RingMemory.h"
// Manhattan distance for 3D
float manhattan_3d(v3_f32 a, v3_f32 b) {
f32 manhattan_3d(v3_f32 a, v3_f32 b) {
return fabs(a.x - b.x)
+ fabs(a.y - b.y)
+ fabs(a.z - b.z);
}
// Euclidean distance for 3D
float euclidean_3d(v3_f32 a, v3_f32 b) {
float dx = a.x - b.x;
float dy = a.y - b.y;
float dz = a.z - b.z;
f32 euclidean_3d(v3_f32 a, v3_f32 b) {
f32 dx = a.x - b.x;
f32 dy = a.y - b.y;
f32 dz = a.z - b.z;
return sqrt(dx * dx + dy * dy + dz * dz);
}
// Chebyshev distance for 3D
float chebyshev_3d(v3_f32 a, v3_f32 b) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
float dz = fabs(a.z - b.z);
f32 chebyshev_3d(v3_f32 a, v3_f32 b) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
f32 dz = fabs(a.z - b.z);
return fmax(fmax(dx, dy), dz);
}
// Minkowski distance for 3D
float minkowski_3d(v3_f32 a, v3_f32 b, int lambda) {
float dx = fabs(a.x - b.x);
float dy = fabs(a.y - b.y);
float dz = fabs(a.z - b.z);
f32 minkowski_3d(v3_f32 a, v3_f32 b, int32 lambda) {
f32 dx = fabs(a.x - b.x);
f32 dy = fabs(a.y - b.y);
f32 dz = fabs(a.z - b.z);
return pow(
pow(dx, lambda)
@ -56,29 +56,29 @@ float minkowski_3d(v3_f32 a, v3_f32 b, int lambda) {
}
// Canberra distance for 3D
float canberra_3d(v3_f32 a, v3_f32 b) {
f32 canberra_3d(v3_f32 a, v3_f32 b) {
return fabs(a.x - b.x) / (fabs(a.x) + fabs(b.x))
+ fabs(a.y - b.y) / (fabs(a.y) + fabs(b.y))
+ fabs(a.z - b.z) / (fabs(a.z) + fabs(b.z));
}
// Bray-Curtis distance for 3D
float bray_curtis_3d(v3_f32 a, v3_f32 b) {
f32 bray_curtis_3d(v3_f32 a, v3_f32 b) {
return (fabs(a.x - b.x) + fabs(a.y - b.y) + fabs(a.z - b.z))
/ ((a.x + b.x) + (a.y + b.y) + (a.z + b.z));
}
// Angular separation for 3D
float angular_separation_3d(v3_f32 a, v3_f32 b) {
f32 angular_separation_3d(v3_f32 a, v3_f32 b) {
return (a.x * b.x + a.y * b.y + a.z * b.z)
/ (sqrt(a.x * a.x + a.y * a.y + a.z * a.z) * sqrt(b.x * b.x + b.y * b.y + b.z * b.z));
}
// Hamming distance for arrays
int hamming(int* a, int* b, int size) {
int dist = 0;
int32 hamming(int32* a, int32* b, int32 size) {
int32 dist = 0;
for (int i = 0; i < size; ++i) {
for (int32 i = 0; i < size; ++i) {
if (a[i] != b[i]) {
++dist;
}

View File

@ -21,7 +21,7 @@ struct HashEntryInt32 {
int64 element_id;
char key[MAX_KEY_LENGTH];
HashEntryInt32* next;
int value;
int32 value;
};
struct HashEntryInt64 {
@ -49,7 +49,7 @@ struct HashEntryFloat {
int64 element_id;
char key[MAX_KEY_LENGTH];
HashEntryFloat* next;
float value;
f32 value;
};
struct HashEntryStr {
@ -72,7 +72,7 @@ struct HashMap {
};
// WARNING: element_size = element size + remaining HashEntry data size
void hashmap_create(HashMap* hm, int count, int element_size, RingMemory* ring)
void hashmap_create(HashMap* hm, int32 count, int32 element_size, RingMemory* ring)
{
hm->table = (void **) ring_get_memory(ring, count * sizeof(void *));
@ -85,7 +85,7 @@ void hashmap_create(HashMap* hm, int count, int element_size, RingMemory* ring)
}
// WARNING: element_size = element size + remaining HashEntry data size
void hashmap_create(HashMap* hm, int count, int element_size, BufferMemory* buf)
void hashmap_create(HashMap* hm, int32 count, int32 element_size, BufferMemory* buf)
{
hm->table = (void **) buffer_get_memory(buf, count * sizeof(void *));
@ -98,7 +98,7 @@ void hashmap_create(HashMap* hm, int count, int element_size, BufferMemory* buf)
}
inline
int64 hashmap_get_buffer_size(int count, int element_size)
int64 hashmap_get_buffer_size(int count, int32 element_size)
{
return sizeof(void *) * count // table
+ count * element_size // elements
@ -106,7 +106,7 @@ int64 hashmap_get_buffer_size(int count, int element_size)
}
// WARNING: element_size = element size + remaining HashEntry data size
void hashmap_create(HashMap* hm, int count, int element_size, byte* buf)
void hashmap_create(HashMap* hm, int32 count, int32 element_size, byte* buf)
{
hm->table = (void **) buf;
@ -178,7 +178,7 @@ void hashmap_insert(HashMap* hm, const char* key, void* value) {
hm->table[index] = entry;
}
void hashmap_insert(HashMap* hm, const char* key, float value) {
void hashmap_insert(HashMap* hm, const char* key, f32 value) {
uint64 index = hash_djb2(key) % hm->buf.count;
int64 element = chunk_reserve(&hm->buf, 1);

View File

@ -639,7 +639,7 @@ inline f32_16 &operator|=(f32_16 &a, f32_16 b)
inline f32_4 abs(f32_4 a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_ps(*(float *) &unsigned_mask);
__m128 mask = _mm_set1_ps(*(f32 *) &unsigned_mask);
f32_4 simd;
simd.s = _mm_and_ps(a.s, mask);
@ -650,7 +650,7 @@ inline f32_4 abs(f32_4 a)
inline f32_8 abs(f32_8 a)
{
unsigned int unsigned_mask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_ps(*(float *) &unsigned_mask);
__m256 mask = _mm256_set1_ps(*(f32 *) &unsigned_mask);
f32_8 simd;
simd.s = _mm256_and_ps(a.s, mask);
@ -717,7 +717,7 @@ inline f32_16 simd_max(f32_16 a, f32_16 b)
inline f32_4 sign(f32_4 a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m128 mask = _mm_set1_ps(*(float *) &umask);
__m128 mask = _mm_set1_ps(*(f32 *) &umask);
f32_4 signBit;
signBit.s = _mm_and_ps(a.s, mask);
@ -733,7 +733,7 @@ inline f32_4 sign(f32_4 a)
inline f32_8 sign(f32_8 a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m256 mask = _mm256_set1_ps(*(float *) &umask);
__m256 mask = _mm256_set1_ps(*(f32 *) &umask);
f32_8 signBit;
signBit.s = _mm256_and_ps(a.s, mask);
@ -749,7 +749,7 @@ inline f32_8 sign(f32_8 a)
inline f32_16 sign(f32_16 a)
{
unsigned int umask = (unsigned int) (1 << 31);
__m512 mask = _mm512_set1_ps(*(float *) &umask);
__m512 mask = _mm512_set1_ps(*(f32 *) &umask);
f32_16 signBit;
signBit.s = _mm512_and_ps(a.s, mask);
@ -986,9 +986,9 @@ inline bool all_false(f32_16 a)
// the code is self contained and we could use te intrinsic functions directly
inline
void simd_mult(const f32* a, const f32* b, f32* result, int size, int steps)
void simd_mult(const f32* a, const f32* b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512 a_16;
@ -1047,9 +1047,9 @@ void simd_mult(const f32* a, const f32* b, f32* result, int size, int steps)
}
inline
void simd_mult(const f32* a, f32 b, f32* result, int size, int steps)
void simd_mult(const f32* a, f32 b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512 a_16;
@ -1101,9 +1101,9 @@ void simd_mult(const f32* a, f32 b, f32* result, int size, int steps)
}
inline
void simd_div(const f32* a, f32 b, f32* result, int size, int steps)
void simd_div(const f32* a, f32 b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512 a_16;
@ -1155,10 +1155,10 @@ void simd_div(const f32* a, f32 b, f32* result, int size, int steps)
}
inline
void simd_div(const f32* a, f32 b, __m256* result, int size)
void simd_div(const f32* a, f32 b, __m256* result, int32 size)
{
int i = 0;
int j = 0;
int32 i = 0;
int32 j = 0;
// @todo this his how all the functions should be implemented that take in baseic types and output basic types
__m256 a_8;
@ -1174,10 +1174,10 @@ void simd_div(const f32* a, f32 b, __m256* result, int size)
++j;
}
int diff = size - i;
alignas(32) float temp[8];
int32 diff = size - i;
alignas(32) f32 temp[8];
for (int k = 0; k < diff; k++) {
for (int32 k = 0; k < diff; k++) {
temp[k] = a[i + k] / b;
}
@ -1185,14 +1185,14 @@ void simd_div(const f32* a, f32 b, __m256* result, int size)
}
inline
void simd_cmp_le(const __m256* a, f32 b, bool* result, int size)
void simd_cmp_le(const __m256* a, f32 b, bool* result, int32 size)
{
__m256 b_8 = _mm256_set1_ps(b);
for (int i = 0; i < size; ++i) {
int mask = _mm256_movemask_ps(_mm256_cmp_ps(a[i], b_8, _CMP_LE_OQ));
for (int32 i = 0; i < size; ++i) {
int32 mask = _mm256_movemask_ps(_mm256_cmp_ps(a[i], b_8, _CMP_LE_OQ));
for (int j = 0; j < 8; ++j) {
for (int32 j = 0; j < 8; ++j) {
result[i * 8 + j] = (mask & (1 << j)) != 0;
}
}

View File

@ -12,6 +12,7 @@
#include <stdint.h>
#include <immintrin.h>
#include <xmmintrin.h>
#include "../Types.h"
#ifdef _MSC_VER
#include <intrin.h>
@ -19,10 +20,10 @@
// @todo implement for arm?
inline int max_sse_supported()
inline int32 max_sse_supported()
{
#ifdef _MSC_VER
int cpuInfo[4] = {-1};
int32 cpuInfo[4] = {-1};
__cpuid(cpuInfo, 1); // CPUID function 1
uint32_t ecx = cpuInfo[2];
@ -62,10 +63,10 @@ inline int max_sse_supported()
inline
int max_avx256_supported()
{
int max_version = 0;
int32 max_version = 0;
#ifdef _MSC_VER
int cpuInfo[4];
int32 cpuInfo[4];
__cpuid(cpuInfo, 1);
if ((cpuInfo[2] >> 28) & 1) {
@ -76,7 +77,7 @@ int max_avx256_supported()
}
}
#else
unsigned int eax, ebx, ecx, edx;
unsigned int32 eax, ebx, ecx, edx;
__asm__ __volatile__("cpuid"
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
@ -101,9 +102,9 @@ inline
int max_avx512_supported()
{
#ifdef _MSC_VER
int cpuInfo[4];
int32 cpuInfo[4];
__cpuid(cpuInfo, 1);
int ebx = 0;
int32 ebx = 0;
if ((cpuInfo[2] >> 28) & 1) {
__cpuid(cpuInfo, 7);
@ -111,7 +112,7 @@ int max_avx512_supported()
ebx = cpuInfo[1];
}
#else
unsigned int eax, ebx, ecx, edx;
unsigned int32 eax, ebx, ecx, edx;
__asm__ __volatile__("cpuid"
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)

View File

@ -1029,9 +1029,9 @@ inline bool all_false(int32_16 a)
// the code is self contained and we could use te intrinsic functions directly
inline
void simd_mult(const int32* a, const int32* b, int32* result, int size, int steps)
void simd_mult(const int32* a, const int32* b, int32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1090,9 +1090,9 @@ void simd_mult(const int32* a, const int32* b, int32* result, int size, int step
}
inline
void simd_mult(const int32* a, const f32* b, f32* result, int size, int steps)
void simd_mult(const int32* a, const f32* b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1157,9 +1157,9 @@ void simd_mult(const int32* a, const f32* b, f32* result, int size, int steps)
}
inline
void simd_mult(const int32* a, const f32* b, int32* result, int size, int steps)
void simd_mult(const int32* a, const f32* b, int32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1221,7 +1221,7 @@ void simd_mult(const int32* a, const f32* b, int32* result, int size, int steps)
}
for (; i < size; ++i) {
*result = (int) (*a * *b);
*result = (int32) (*a * *b);
++a;
++b;
@ -1230,9 +1230,9 @@ void simd_mult(const int32* a, const f32* b, int32* result, int size, int steps)
}
inline
void simd_mult(const int32* a, f32 b, int32* result, int size, int steps)
void simd_mult(const int32* a, f32 b, int32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1296,9 +1296,9 @@ void simd_mult(const int32* a, f32 b, int32* result, int size, int steps)
}
inline
void simd_div(const int32* a, f32 b, f32* result, int size, int steps)
void simd_div(const int32* a, f32 b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1357,9 +1357,9 @@ void simd_div(const int32* a, f32 b, f32* result, int size, int steps)
}
inline
void simd_add(const int32* a, const int32* b, int32* result, int size, int steps)
void simd_add(const int32* a, const int32* b, int32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1418,9 +1418,9 @@ void simd_add(const int32* a, const int32* b, int32* result, int size, int steps
}
inline
void simd_add(const int32* a, const f32* b, f32* result, int size, int steps)
void simd_add(const int32* a, const f32* b, f32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1485,9 +1485,9 @@ void simd_add(const int32* a, const f32* b, f32* result, int size, int steps)
}
inline
void simd_add(const int32* a, const f32* b, int32* result, int size, int steps)
void simd_add(const int32* a, const f32* b, int32* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
__m512i a_16;
@ -1567,9 +1567,9 @@ bool str_compare_avx512(const char* str1, const char* str2) {
}
void
endian_swap(const int* val, int* result, int size, int steps)
endian_swap(const int* val, int* result, int32 size, int32 steps)
{
int i = 0;
int32 i = 0;
if (steps == 16) {
const __m512i mask_512 = _mm512_setr_epi8(

View File

@ -827,7 +827,7 @@ inline bool all_false(int8_64 a)
/*
inline
f32 simd_mult(const int8* a, f32 b, int size, int steps)
f32 simd_mult(const int8* a, f32 b, int32 size, int32 steps)
{
if (steps == 16) {
__m512i a_16 = _mm512_loadu_epi8(a);
@ -870,7 +870,7 @@ bool simd_compare_64(const byte* a, const byte* b)
}
int simd_compare(const byte* a, const byte* b, uint32 size, uint32 steps = 8) {
int i = 0;
int32 i = 0;
if (steps == 16) {
if (size >= 128) {

View File

@ -55,7 +55,7 @@
}
inline __m128 _mm_sin_ps(__m128 a) {
alignas(16) float a_array[4], result[4];
alignas(16) f32 a_array[4], result[4];
_mm_storeu_ps(a_array, a);
for (int i = 0; i < 4; ++i) {
result[i] = sinf(a_array[i]);
@ -64,7 +64,7 @@
}
inline __m128 _mm_cos_ps(__m128 a) {
alignas(16) float a_array[4], result[4];
alignas(16) f32 a_array[4], result[4];
_mm_storeu_ps(a_array, a);
for (int i = 0; i < 4; ++i) {
result[i] = cosf(a_array[i]);
@ -73,7 +73,7 @@
}
inline __m128 _mm_asin_ps(__m128 a) {
alignas(16) float a_array[4], result[4];
alignas(16) f32 a_array[4], result[4];
_mm_storeu_ps(a_array, a);
for (int i = 0; i < 4; ++i) {
result[i] = asinf(a_array[i]);
@ -82,7 +82,7 @@
}
inline __m128 _mm_acos_ps(__m128 a) {
alignas(16) float a_array[4], result[4];
alignas(16) f32 a_array[4], result[4];
_mm_storeu_ps(a_array, a);
for (int i = 0; i < 4; ++i) {
result[i] = acosf(a_array[i]);
@ -91,7 +91,7 @@
}
inline __m256 _mm256_sin_ps(__m256 a) {
alignas(32) float a_array[8], result[8];
alignas(32) f32 a_array[8], result[8];
_mm256_storeu_ps(a_array, a);
for (int i = 0; i < 8; ++i) {
result[i] = sinf(a_array[i]);
@ -100,7 +100,7 @@
}
inline __m256 _mm256_cos_ps(__m256 a) {
alignas(32) float a_array[8], result[8];
alignas(32) f32 a_array[8], result[8];
_mm256_storeu_ps(a_array, a);
for (int i = 0; i < 8; ++i) {
result[i] = cosf(a_array[i]);
@ -109,7 +109,7 @@
}
inline __m256 _mm256_asin_ps(__m256 a) {
alignas(32) float a_array[8], result[8];
alignas(32) f32 a_array[8], result[8];
_mm256_storeu_ps(a_array, a);
for (int i = 0; i < 8; ++i) {
result[i] = asinf(a_array[i]);
@ -118,7 +118,7 @@
}
inline __m256 _mm256_acos_ps(__m256 a) {
alignas(32) float a_array[8], result[8];
alignas(32) f32 a_array[8], result[8];
_mm256_storeu_ps(a_array, a);
for (int i = 0; i < 16; ++i) {
result[i] = acosf(a_array[i]);
@ -127,7 +127,7 @@
}
inline __m512 _mm512_sin_ps(__m512 a) {
alignas(64) float a_array[8], result[8];
alignas(64) f32 a_array[8], result[8];
_mm512_storeu_ps(a_array, a);
for (int i = 0; i < 16; ++i) {
result[i] = sinf(a_array[i]);
@ -136,7 +136,7 @@
}
inline __m512 _mm512_cos_ps(__m512 a) {
alignas(64) float a_array[8], result[8];
alignas(64) f32 a_array[8], result[8];
_mm512_storeu_ps(a_array, a);
for (int i = 0; i < 16; ++i) {
result[i] = cosf(a_array[i]);
@ -145,7 +145,7 @@
}
inline __m512 _mm512_asin_ps(__m512 a) {
alignas(64) float a_array[8], result[8];
alignas(64) f32 a_array[8], result[8];
_mm512_storeu_ps(a_array, a);
for (int i = 0; i < 16; ++i) {
result[i] = asinf(a_array[i]);
@ -154,7 +154,7 @@
}
inline __m512 _mm512_acos_ps(__m512 a) {
alignas(64) float a_array[16], result[16];
alignas(64) f32 a_array[16], result[16];
_mm512_storeu_ps(a_array, a);
for (int i = 0; i < 16; ++i) {
result[i] = acosf(a_array[i]);

View File

@ -22,12 +22,12 @@ struct UIButton {
UILayout* layout_default;
UILayout* layout_hover;
float layout_hover_anim_duration;
f32 layout_hover_anim_duration;
AnimationEaseType layout_hover_anim_style;
int hover_sound;
UILayout* layout_click;
float layout_click_anim_duration;
f32 layout_click_anim_duration;
AnimationEaseType layout_click_anim_style;
int click_sound;
};

View File

@ -28,12 +28,12 @@ struct UIWindow {
bool is_resizable;
// window is only movable when holding this area
int movable_area[4];
int32 movable_area[4];
UILayout* layout_default;
float layout_open_anim_duration;
float layout_close_anim_duration;
float layout_min_anim_duration;
f32 layout_open_anim_duration;
f32 layout_close_anim_duration;
f32 layout_min_anim_duration;
};
#endif

View File

@ -305,7 +305,7 @@ uint64 bytes_merge(
}
static
inline int find_first_set_bit(int value) {
inline int32 find_first_set_bit(int32 value) {
if (value == 0) {
return 0;
}
@ -315,12 +315,12 @@ inline int find_first_set_bit(int value) {
#elif _MSC_VER
unsigned long index; // For _BitScanForward, an unsigned long is expected
if (_BitScanForward(&index, value)) {
return (int)index + 1; // Convert to 1-based index
return (int32) index + 1; // Convert to 1-based index
} else {
return 0; // No set bit found
}
#else
int index = 1; // Start at 1 for 1-based index
int32 index = 1; // Start at 1 for 1-based index
while (value) {
if (value & 1) {
return index;

View File

@ -89,15 +89,15 @@ int64 endian_swap(int64 val)
}
inline
float endian_swap(float val)
f32 endian_swap(f32 val)
{
return (float) endian_swap(val);
return (f32) endian_swap(val);
}
inline
double endian_swap(double val)
f64 endian_swap(f64 val)
{
return (double) endian_swap(val);
return (f64) endian_swap(val);
}
#endif

View File

@ -10,6 +10,7 @@
#define TOS_UTILS_FAST_PIPES_H
// requires kernel32.lib and user32.lib
#include "../stdlib/Types.h"
#if _WIN32
#include <windows.h>
@ -19,7 +20,7 @@
static int ENABLE_FAST_PIPES()
{
int result = 0;
int32 result = 0;
wchar_t pipe_name[32];
wsprintfW(pipe_name, L"\\\\.\\pipe\\fastpipe%x", GetCurrentProcessId());
@ -29,8 +30,8 @@
SetStdHandle(STD_OUTPUT_HANDLE, fast_pip);
SetStdHandle(STD_INPUT_HANDLE, fast_pip);
int std_out = _open_osfhandle((intptr_t) fast_pip, O_WRONLY | O_TEXT);
int std_in = _open_osfhandle((intptr_t) fast_pip, O_RDONLY | O_TEXT);
int32 std_out = _open_osfhandle((intptr_t) fast_pip, O_WRONLY | O_TEXT);
int32 std_in = _open_osfhandle((intptr_t) fast_pip, O_RDONLY | O_TEXT);
_dup2(std_out, _fileno(stdout));
_dup2(std_in, _fileno(stdin));

View File

@ -16,7 +16,7 @@
#include "../stdlib/Types.h"
inline
void wchar_to_char(const wchar_t* src, char* dest, int length = 0)
void wchar_to_char(const wchar_t* src, char* dest, int32 length = 0)
{
char* temp = (char* ) src;
size_t len = wcslen(src) * sizeof(wchar_t);
@ -25,7 +25,7 @@ void wchar_to_char(const wchar_t* src, char* dest, int length = 0)
len = length;
}
for (int i = 0; i < len; ++i) {
for (int32 i = 0; i < len; ++i) {
if (*temp != '\0') {
*dest = (char) *temp;
++dest;
@ -38,11 +38,11 @@ void wchar_to_char(const wchar_t* src, char* dest, int length = 0)
}
inline
int str_to_int(const char *str)
int32 str_to_int(const char *str)
{
int result = 0;
int32 result = 0;
int sign = 1;
int32 sign = 1;
if (*str == '-') {
sign = -1;
++str;
@ -134,12 +134,12 @@ char* strtok(char* str, const char* delim, char* *saveptr)
}
inline
void format_number_render(int length, char* buffer, const char thousands = ',')
void format_number_render(int32 length, char* buffer, const char thousands = ',')
{
int count = (int) (length / 3) - (length % 3 == 0 ? 1 : 0);
int32 count = (int32) (length / 3) - (length % 3 == 0 ? 1 : 0);
int j = -1;
for (int i = length; i > 0; --i) {
int32 j = -1;
for (int32 i = length; i > 0; --i) {
++j;
if (j % 3 == 0 && j != 0) {
@ -154,15 +154,15 @@ void format_number_render(int length, char* buffer, const char thousands = ',')
char* format_number(size_t number, char* buffer, const char thousands = ',')
{
int length = snprintf(buffer, 32, "%zu", number);
int32 length = snprintf(buffer, 32, "%zu", number);
format_number_render(length, buffer, thousands);
return buffer;
}
char* format_number(int number, char* buffer, const char thousands = ',')
char* format_number(int32 number, char* buffer, const char thousands = ',')
{
int length = snprintf(buffer, 32, "%i", number);
int32 length = snprintf(buffer, 32, "%i", number);
format_number_render(length, buffer, thousands);
return buffer;
@ -225,14 +225,16 @@ char* strtok_(char* str, const char* delim, char* *key) {
}
bool str_ends_with(const char* str, const char* suffix) {
if (!str || !suffix)
if (!str || !suffix) {
return false;
}
size_t str_len = strlen(str);
size_t suffix_len = strlen(suffix);
if (suffix_len > str_len)
if (suffix_len > str_len) {
return false;
}
return strncmp(str + str_len - suffix_len, suffix, suffix_len) == 0;
}

View File

@ -11,8 +11,8 @@
#include <stdio.h>
#include <stdint.h>
#include "StringUtils.h"
#include "../stdlib/Types.h"
#include "StringUtils.h"
#include "../stdlib/simd/SIMD_Helper.h"
#if _WIN32
@ -39,17 +39,17 @@
// @todo move to platform specifc files
struct CpuCacheInfo {
int level;
int size;
int ways;
int partitions;
int sets;
int line_size;
int32 level;
int32 size;
int32 ways;
int32 partitions;
int32 sets;
int32 line_size;
};
void cache_info_get(int level, CpuCacheInfo* cache) {
unsigned int eax, ebx, ecx, edx;
int type;
void cache_info_get(int32 level, CpuCacheInfo* cache) {
uint32 eax, ebx, ecx, edx;
int32 type;
cache->level = level;
cache->size = 0;
@ -59,7 +59,7 @@ void cache_info_get(int level, CpuCacheInfo* cache) {
cache->line_size = 0;
#if _WIN32
int regs[4];
int32 regs[4];
__cpuidex(regs, 4, level);
eax = regs[0];
ebx = regs[1];
@ -254,7 +254,7 @@ int network_info_get(NetworkInfo* info) {
return 0;
}
int i = 0;
int32 i = 0;
// Iterate over the adapters and print their MAC addresses
pAdapter = pAdapterAddresses;
@ -279,24 +279,24 @@ int network_info_get(NetworkInfo* info) {
}
struct SIMDInfo {
float sse;
int avx256;
int avx512;
f32 sse;
int32 avx256;
int32 avx512;
};
struct CpuInfo {
char vendor[13];
char brand[49];
int model;
int family;
int mhz;
int32 model;
int32 family;
int32 mhz;
CpuCacheInfo cache[4];
int page_size;
int32 page_size;
SIMDInfo simd;
};
void cpu_info_get(CpuInfo* info) {
int temp;
int32 temp;
info->simd.sse = (temp = max_sse_supported()) > 9 ? temp / 10.0f : temp;
info->simd.avx256 = max_avx256_supported();
info->simd.avx512 = max_avx512_supported();
@ -310,7 +310,7 @@ void cpu_info_get(CpuInfo* info) {
GetSystemInfo(&sys_info);
info->page_size = sys_info.dwPageSize;
int cpuInfo[4] = { 0 };
int32 cpuInfo[4] = { 0 };
__cpuid(cpuInfo, 0);
memset(info->vendor, 0, sizeof(info->vendor));
@ -349,8 +349,8 @@ void cpu_info_get(CpuInfo* info) {
struct OSInfo {
char vendor[16];
char name[64];
int major;
int minor;
int32 major;
int32 minor;
};
void os_info_get(OSInfo* info) {
@ -379,7 +379,7 @@ void os_info_get(OSInfo* info) {
}
struct RamInfo {
int memory;
int32 memory;
};
void ram_info_get(RamInfo* info) {
@ -391,10 +391,10 @@ void ram_info_get(RamInfo* info) {
struct GpuInfo {
char name[64];
int vram;
int32 vram;
};
unsigned int gpu_info_get(GpuInfo* info) {
unsigned int32 gpu_info_get(GpuInfo* info) {
IDXGIFactory *pFactory = NULL;
IDXGIAdapter *pAdapter = NULL;
DXGI_ADAPTER_DESC adapterDesc;
@ -427,18 +427,18 @@ unsigned int gpu_info_get(GpuInfo* info) {
struct DisplayInfo {
char name[64];
int width;
int height;
int hz;
int32 width;
int32 height;
int32 hz;
};
unsigned int display_info_get(DisplayInfo* info) {
unsigned int32 display_info_get(DisplayInfo* info) {
DISPLAY_DEVICEA device;
DEVMODEA mode;
device.cb = sizeof(DISPLAY_DEVICEA);
int i = 0;
int32 i = 0;
while (EnumDisplayDevicesA(NULL, i, &device, 0)) {
mode.dmSize = sizeof(mode);
@ -461,16 +461,16 @@ struct SystemInfo {
MainboardInfo mainboard;
NetworkInfo network[4];
int network_count;
int32 network_count;
CpuInfo cpu;
RamInfo ram;
GpuInfo gpu[2];
int gpu_count;
int32 gpu_count;
DisplayInfo display[6];
int display_count;
int32 display_count;
};
void system_info_render(char* buf, const SystemInfo* info) {

View File

@ -51,11 +51,11 @@ f32 fast_rand_percentage(void) {
* Picks n random elements from end and stores them in begin.
*/
inline
void random_unique(int* array, int size) {
for (int i = size - 1; i > 0; --i) {
int j = rand() % (i + 1);
void random_unique(int32* array, int32 size) {
for (int32 i = size - 1; i > 0; --i) {
int32 j = rand() % (i + 1);
int temp = array[i];
int32 temp = array[i];
array[i] = array[j];
array[j] = temp;
}
@ -64,17 +64,17 @@ void random_unique(int* array, int size) {
/**
* Gets random index based value probability
*/
int random_weighted_index(int* arr, int array_count)
int random_weighted_index(int32* arr, int32 array_count)
{
uint32 prob_sum = 0;
for (int i = 0; i < array_count; ++i) {
for (int32 i = 0; i < array_count; ++i) {
prob_sum += arr[i];
}
uint32 random_prob = rand() % (prob_sum + 1);
uint32 current_rarity = 0;
int item_rarity = array_count - 1;
for (int i = 0; i < array_count - 1; ++i) {
int32 item_rarity = array_count - 1;
for (int32 i = 0; i < array_count - 1; ++i) {
current_rarity += arr[i];
if (current_rarity < random_prob) {