#pragma once

#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include <cglm/cglm.h>

#include "STRINGS.h"

#define PI (GLM_PI)
#define TAU (PI * 2)
#define PI_HALF (PI / 2)
#define PI_FOURTH (PI / 4)
#define RADIANS(x) (x * (PI / 180))
#define DEGREES(x) (x * (180 / PI))
#define RADIANS_MIN (0)
#define RADIANS_MAX (TAU)

#define MIN(x, min) (x < min ? min : x)
#define MAX(x, max) (x > max ? max : x)
#define CLAMP(x, min, max) (MIN(MAX(x, max), min))

#define RANDOM_SEED_SET(seed) (srand(seed))
#define RANDOM ((f32)rand() / (f32)RAND_MAX)
#define RANDOM_F32(min, max) ((f32)((RANDOM * (max - min + 1)) + min))
#define RANDOM_S32(min, max) ((s32)((RANDOM * (max - min + 1)) + min))
#define RANDOM_BOOL() (RANDOM_S32(0, 2))

#define DISTANCE_2D(x1, x2, y1, y2) (sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))
#define ATAN(x1, x2, y1, y2) (atan2(y2 - y1, x2 - x1))

#define MILLISECOND_TICK 600
#define SECOND_TICK 60
#define SECOND_TICK 60
#define MINUTE_TICK 3600
#define HOUR_TICK 216000

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;

typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

typedef float f32;
typedef double f64;

static const vec4 COLOR_TRANSPARENT = {1.0f, 1.0f, 1.0f, 0.0f};
static const vec4 COLOR_OPAQUE = {1.0f, 1.0f, 1.0f, 1.0f};

#define DIRECTION_COUNT DIRECTION_NORTH_WEST + 1
typedef enum Direction
{
	DIRECTION_NORTH,
	DIRECTION_EAST,
	DIRECTION_SOUTH,
	DIRECTION_WEST,
	DIRECTION_NORTH_EAST,
	DIRECTION_SOUTH_EAST,
	DIRECTION_SOUTH_WEST,
	DIRECTION_NORTH_WEST
} Direction;

static const f32 DIRECTION_ANGLES[DIRECTION_COUNT] =
{
	PI - PI_HALF,
	PI,
	PI + PI_HALF,
	0.0f,
	PI - PI_FOURTH,
	PI + PI_FOURTH,
	TAU - PI_FOURTH,
	PI_FOURTH
};
