19 #include "shared/shared.h"
26 float sr, sp, sy, cr, cp, cy;
28 angle = angles[YAW] * (M_PI * 2 / 360);
31 angle = angles[PITCH] * (M_PI * 2 / 360);
34 angle = angles[ROLL] * (M_PI * 2 / 360);
44 right[0] = (-1 * sr * sp * cy + -1 * cr * -sy);
45 right[1] = (-1 * sr * sp * sy + -1 * cr * cy);
46 right[2] = -1 * sr * cp;
49 up[0] = (cr * sp * cy + -sr * -sy);
50 up[1] = (cr * sp * sy + -sr * cy);
57 float length, ilength;
59 length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
60 length = sqrtf(length);
75 float length, ilength;
77 length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
78 length = sqrtf(length);
82 out[0] = v[0] * ilength;
83 out[1] = v[1] * ilength;
84 out[2] = v[2] * ilength;
93 mins[0] = mins[1] = mins[2] = 99999;
94 maxs[0] = maxs[1] = maxs[2] = -99999;
102 for (i = 0; i < 3; i++) {
113 c[0][0] = b[0][0] < a[0][0] ? b[0][0] : a[0][0];
114 c[0][1] = b[0][1] < a[0][1] ? b[0][1] : a[0][1];
115 c[0][2] = b[0][2] < a[0][2] ? b[0][2] : a[0][2];
117 c[1][0] = b[1][0] > a[1][0] ? b[1][0] : a[1][0];
118 c[1][1] = b[1][1] > a[1][1] ? b[1][1] : a[1][1];
119 c[1][2] = b[1][2] > a[1][2] ? b[1][2] : a[1][2];
133 for (i = 0; i < 3; i++) {
136 corner[i] = a > b ? a : b;
139 return VectorLength(corner);
157 Com_Error(ERR_FATAL,
"%s: NULL", __func__);
160 last = (
char *)pathname;
162 if (*pathname ==
'/')
163 last = (
char *)pathname + 1;
180 s = out + strlen(out);
205 Com_Error(ERR_FATAL,
"%s: NULL", __func__);
233 s = in + strlen(in) - 1;
235 while (s != in && *s !=
'.')
238 for (s2 = s; s2 != in && *s2 !=
'/'; s2--)
245 strncpy(out, s2 + 1, s - s2);
262 s = strrchr(out,
'/');
286 src = path + len - 1;
288 while (*src !=
'/' && src != path) {
322 }
else if (!Q_isdigit(
c)) {
382 return strcmp(*(
const char **)p1, *(
const char **)p2);
387 return Q_stricmp(*(
const char **)p1, *(
const char **)p2);
429 char *
va(
const char *format, ...)
432 static char buffers[2][0x2800];
437 va_start(argptr, format);
438 Q_vsnprintf(buffers[index],
sizeof(buffers[0]), format, argptr);
441 return buffers[index];
473 while ((
c = *data) <=
' ') {
482 if (
c ==
'/' && data[1] ==
'/') {
484 while (*data && *data !=
'\n')
490 if (
c ==
'/' && data[1] ==
'*') {
493 if (data[0] ==
'*' && data[1] ==
'/') {
507 if (
c ==
'\"' || !
c) {
511 if (len < MAX_TOKEN_CHARS - 1) {
519 if (len < MAX_TOKEN_CHARS - 1) {
546 char *s = data, *d = data;
566 if (s[0] ==
'/' && s[1] ==
'/') {
569 while (*s && *s !=
'\n') {
576 if (s[0] ==
'/' && s[1] ==
'*') {
580 if (s[0] ==
'*' && s[1] ==
'/') {
613 if (*s ==
'\\' && s[1] ==
'\n') {
617 if (*s ==
'\\' && s[1] ==
'\r' && s[2] ==
'\n') {
715 size_t Q_strlcpy(
char *dst,
const char *src,
size_t size)
717 size_t ret = strlen(src);
720 size_t len = ret >= size ? size - 1 : ret;
721 memcpy(dst, src, len);
735 size_t Q_strlcat(
char *dst,
const char *src,
size_t size)
737 size_t ret, len = strlen(dst);
740 Com_Error(ERR_FATAL,
"%s: already overflowed", __func__);
743 ret =
Q_strlcpy(dst + len, src, size - len);
762 size_t len, total = 0;
764 va_start(argptr, size);
765 while ((s = va_arg(argptr,
const char *)) != NULL) {
767 if (total + len < size) {
768 memcpy(dest, s, len);
791 size_t Q_vsnprintf(
char *dest,
size_t size,
const char *fmt, va_list argptr)
796 Com_Error(ERR_FATAL,
"%s: bad buffer size", __func__);
800 ret = _vsnprintf(dest, size - 1, fmt, argptr);
801 if (ret < 0 || ret >= size - 1)
804 ret = _vscprintf(fmt, argptr);
807 ret = vsnprintf(dest, size, fmt, argptr);
823 size_t Q_vscnprintf(
char *dest,
size_t size,
const char *fmt, va_list argptr)
846 size_t Q_snprintf(
char *dest,
size_t size,
const char *fmt, ...)
851 va_start(argptr, fmt);
872 va_start(argptr, fmt);
881 while (*s && *s !=
c) {
895 void *
Q_memccpy(
void *dst,
const void *src,
int c,
size_t size)
901 if ((*d++ = *s++) ==
c) {
915 #if (_MSC_VER >= 1400)
916 _putenv_s(name, value);
918 _putenv(
va(
"%s=%s", name, value));
922 setenv(name, value, 1);
948 static char value[4][MAX_INFO_STRING];
949 static int valueindex;
950 char pkey[MAX_INFO_STRING];
966 o = value[valueindex & 3];
967 while (*s !=
'\\' && *s) {
972 if (!strcmp(key, pkey))
973 return value[valueindex & 3];
981 o = value[valueindex & 3];
994 char pkey[MAX_INFO_STRING];
1002 while (*s !=
'\\') {
1010 while (*s !=
'\\' && *s) {
1014 if (!strcmp(key, pkey)) {
1052 if (++total == MAX_INFO_STRING) {
1060 while (*s !=
'\\') {
1062 if (!Q_isprint(
c) ||
c ==
'\"' ||
c ==
';') {
1065 if (++len == MAX_INFO_KEY) {
1068 if (++total == MAX_INFO_STRING) {
1080 if (++total == MAX_INFO_STRING) {
1087 while (*s !=
'\\') {
1089 if (!Q_isprint(
c) ||
c ==
'\"' ||
c ==
';') {
1092 if (++len == MAX_INFO_VALUE) {
1095 if (++total == MAX_INFO_STRING) {
1121 if (
c ==
'\\' ||
c ==
'\"' ||
c ==
';') {
1124 if (++len == MAX_QPATH) {
1139 char newi[MAX_INFO_STRING], *v;
1145 if (kl >= MAX_QPATH) {
1151 if (vl >= MAX_QPATH) {
1161 if (l + kl + vl + 2 >= MAX_INFO_STRING) {
1166 memcpy(newi + 1, key, kl);
1167 newi[kl + 1] =
'\\';
1168 memcpy(newi + kl + 2, value, vl + 1);
1210 while (*s && *s !=
'\\') {
1222 while (*s && *s !=
'\\') {
1237 char key[MAX_INFO_STRING];
1238 char value[MAX_INFO_STRING];
1246 strcpy(key,
"<MISSING KEY>");
1249 strcpy(value,
"<MISSING VALUE>");
1251 Com_Printf(
"%-20s %s\n", key, value);