2025-01-14 13:59:44 +01:00
|
|
|
#ifndef _LCR_GENERAL_H
|
|
|
|
#define _LCR_GENERAL_H
|
2023-08-03 21:12:23 +02:00
|
|
|
|
2025-01-29 16:27:47 +01:00
|
|
|
/** @file general.h
|
|
|
|
|
2025-01-20 21:33:05 +01:00
|
|
|
Licar: general
|
|
|
|
|
|
|
|
This file holds general definitions used by all modules.
|
2025-01-14 13:59:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-09-17 13:21:19 +02:00
|
|
|
#include "settings.h"
|
|
|
|
|
2025-01-14 13:59:44 +01:00
|
|
|
// constants (not supposed to be changed, doing so may break stuff):
|
|
|
|
|
2023-09-11 20:56:04 +02:00
|
|
|
#define LCR_EFFECTIVE_RESOLUTION_X \
|
|
|
|
(LCR_SETTING_RESOLUTION_X / LCR_SETTING_RESOLUTION_SUBDIVIDE)
|
|
|
|
|
|
|
|
#define LCR_EFFECTIVE_RESOLUTION_Y \
|
|
|
|
(LCR_SETTING_RESOLUTION_Y / LCR_SETTING_RESOLUTION_SUBDIVIDE)
|
|
|
|
|
2024-07-24 20:28:57 +02:00
|
|
|
#define LCR_MAP_SIZE_BLOCKS 64
|
|
|
|
|
2024-09-05 22:51:11 +02:00
|
|
|
/** Physics FPS, i.e. the number of physics ticks per second. */
|
2024-09-20 15:22:18 +02:00
|
|
|
#define LCR_RACING_FPS 30
|
2024-09-05 22:51:11 +02:00
|
|
|
|
2025-01-15 23:24:07 +01:00
|
|
|
#define LCR_RACING_TICK_MS \
|
|
|
|
(100000 / (LCR_RACING_FPS * LCR_SETTING_TIME_MULTIPLIER))
|
2024-09-05 22:51:11 +02:00
|
|
|
|
2025-01-14 13:59:44 +01:00
|
|
|
char _LCR_hexDigit(int i)
|
|
|
|
{
|
|
|
|
return i < 10 ? '0' + i : ('a' - 10 + i);
|
|
|
|
}
|
|
|
|
|
2025-01-15 23:08:31 +01:00
|
|
|
int _LCR_hexDigitVal(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
return c - '0';
|
|
|
|
|
|
|
|
if (c >= 'a' && c <= 'f')
|
|
|
|
return c - 'a' + 10;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2025-01-19 22:19:44 +01:00
|
|
|
/**
|
|
|
|
Computes simple hash of a string represented by a function returning next
|
|
|
|
string character, ending at 0 or endChar. This is intended for simple (but
|
|
|
|
not 100% reliable) string comparison.
|
|
|
|
*/
|
|
|
|
uint16_t _LCR_simpleStrHash(char (*nextChar)(void), char endChar)
|
|
|
|
{
|
|
|
|
uint16_t r = 0;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
char c = nextChar();
|
|
|
|
|
|
|
|
if (c == 0 || c == endChar)
|
|
|
|
break;
|
|
|
|
|
|
|
|
r = ((r << 5) | (r >> 11)) + c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2025-01-27 23:46:44 +01:00
|
|
|
int _LCR_strCmp(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (*s1 != *s2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (*s1 == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2025-02-04 00:15:45 +01:00
|
|
|
char _LCR_triangleWinding(int x0, int y0, int x1, int y1, int x2, int y2)
|
|
|
|
{
|
|
|
|
x0 = (y1 - y0) * (x2 - x1) - (x1 - x0) * (y2 - y1);
|
|
|
|
return x0 != 0 ? (x0 > 0 ? 1 : -1) : 0;
|
|
|
|
}
|
|
|
|
|
2025-01-14 13:59:44 +01:00
|
|
|
#endif // guard
|