There are scripts available to revert `once` to include guards should they be needed
#include "lazy.qh"
#include "linkedlist.qh"
#include "log.qh"
-#include "map.qc"
+#include "map.qh"
#include "math.qh"
#include "misc.qh"
#include "net.qh"
#include "nil.qh"
-#include "noise.qc"
+#include "noise.qh"
#include "oo.qh"
#include "p2mathlib.qc"
#include "progname.qh"
-#ifndef ACCUMULATE_H
-#define ACCUMULATE_H
+#pragma once
#ifdef QCC_SUPPORT_ACCUMULATE
#define ACCUMULATE_FUNCTION(func, otherfunc) \
if (!field) { field = (first + count); ++count; }
#define CHECK_MAX_COUNT(name, max, count, type) \
if (count > max) { error(strcat("Maximum ", type, " hit: ", #name, ": ", ftos(count), ".\n")); }
-
-#endif
-#ifndef ARRAYLIST_H
-#define ARRAYLIST_H
+#pragma once
typedef entity ArrayList;
.int al_buf;
if (cond) { body } \
} \
} MACRO_END
-
-#endif
-#ifndef BITS_H
-#define BITS_H
+#pragma once
+
#include "log.qh"
#define BIT(n) (1 << (n))
int v1 = e.(fld);
return v0 != v1;
}
-
-#endif
-#ifndef BOOL_H
-#define BOOL_H
+#pragma once
#ifndef QCC_SUPPORT_BOOL
// Boolean Constants
default: return boolean(stof(input));
}
}
-
-#endif
-#ifndef COLOR_H
-#define COLOR_H
+#pragma once
#include "string.qh"
DEC_TO_HEXDIGIT(floor(rgb.z * 15 + 0.5))
);
}
-
-#endif
-#ifndef COMPILER_H
-#define COMPILER_H
+#pragma once
#ifndef QCC_SUPPORT_ACCUMULATE
#ifdef GMQCC
#define QCC_SUPPORT_NIL
#endif
#endif
-
-#endif
-#ifndef COUNTING_H
-#define COUNTING_H
+#pragma once
#include "i18n.qh"
}
return "";
}
-#endif
-#ifndef CVAR_H
-#define CVAR_H
+#pragma once
#include "nil.qh"
#include "progname.qh"
#define EVAL__AUTOCVAR(...) __VA_ARGS__
#define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__)
#define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__)
-
-#endif
-#ifndef DEFER_H
-#define DEFER_H
+#pragma once
+
#ifndef MENUQC
#include "oo.qh"
}
#endif
-#endif
+#pragma once
+
#ifdef CSQC
-#ifndef DRAW_H
- #define DRAW_H
#include "i18n.qh"
#include "vector.qh"
}
#endif
-#endif
-#ifndef ENUMCLASS_H
-#define ENUMCLASS_H
+#pragma once
#include "oo.qh"
#define ENUMCLASS_END(id) ENDCLASS(id)
#endif
-
-#endif
-#ifndef FILE_H
-#define FILE_H
+#pragma once
bool fexists(string f)
{
fclose(fh);
return true;
}
-
-#endif
-#ifndef FUNCTIONAL_H
-#define FUNCTIONAL_H
+#pragma once
#define MAP(f, ...) EVAL(OVERLOAD(MAP, f, __VA_ARGS__))
#define MAP_2(f, it) f(it)
#endif
#define IF(cond, f, ...) cond(f, __VA_ARGS__)
-
-#endif
-#ifndef I18N_H
-#define I18N_H
+#pragma once
#include "log.qh"
-#include "map.qc"
+#include "map.qh"
#include "unsafe.qh"
// translation helpers
}
#define ZCTX(s) strzone(CTX(s))
-
-#endif
-#ifndef INT_H
-#define INT_H
+#pragma once
#ifndef QCC_SUPPORT_INT
#define stoi(s) stof(s)
#define stob(s) ((bool) stof(s))
#define itos(i) ftos(i)
#endif
-
-#endif
-#ifndef ITER_H
-#define ITER_H
+#pragma once
#define FOREACH_ARRAY(arr, start, end, cond, body) \
MACRO_BEGIN \
#define FOREACH_ENTITY(cond, body) FOREACH_ENTITY_UNORDERED(cond, body)
#define FOREACH(list, cond, body) FOREACH_LIST(list, enemy, cond, body)
-
-#endif
-#ifndef LAZY_H
-#define LAZY_H
+#pragma once
#include "oo.qh"
if (!done) { it = compute; done = true; } \
return it; \
}
-#endif
-#ifndef LINKEDLIST_H
-#define LINKEDLIST_H
+#pragma once
CLASS(LinkedListNode, Object)
ATTRIB(LinkedListNode, ll_data, entity, NULL)
if (cond) { body } \
} \
} MACRO_END
-
-#endif
-#ifndef LOG_H
-#define LOG_H
+#pragma once
#define assert(expr, ...) _assert(LOG_SEVERE, expr, __VA_ARGS__)
#define devassert(...) MACRO_BEGIN if (autocvar_developer) assert(__VA_ARGS__); MACRO_END
bt_cvar_set("developer", ftos(dev)); \
bt_cvar_set("prvm_backtraceforwarnings", ftos(war)); \
} MACRO_END
-
-#endif
-#ifndef MACRO_H
-#define MACRO_H
+#pragma once
#if 1
void voidfunc() { error("voidfunc"); }
#define _STR(it) #it
#define STR(it) _STR(it)
-
-#endif
+++ /dev/null
-#ifndef MAP_H
-#define MAP_H
-
-#include "int.qh"
-
-// Databases (hash tables)
-const int DB_BUCKETS = 8192;
-void db_save(int db, string filename)
-{
- int fh = fopen(filename, FILE_WRITE);
- if (fh < 0)
- {
- LOG_WARNINGF("^1Can't write DB to %s\n", filename);
- return;
- }
- fputs(fh, strcat(ftos(DB_BUCKETS), "\n"));
- for (int i = 0, n = buf_getsize(db); i < n; ++i)
- fputs(fh, strcat(bufstr_get(db, i), "\n"));
- fclose(fh);
-}
-
-typedef int HashMap;
-
-int db_create()
-{
- return buf_create();
-}
-#define HM_NEW(this) (this = db_create())
-
-void db_put(int db, string key, string value);
-
-int db_load(string filename)
-{
- int db = buf_create();
- if (db < 0) return -1;
- int fh = fopen(filename, FILE_READ);
- if (fh < 0) return db;
- string l = fgets(fh);
- if (stoi(l) == DB_BUCKETS)
- {
- for (int i = 0; (l = fgets(fh)); ++i)
- {
- if (l != "") bufstr_set(db, i, l);
- }
- }
- else
- {
- // different count of buckets, or a dump?
- // need to reorganize the database then (SLOW)
- //
- // note: we also parse the first line (l) in case the DB file is
- // missing the bucket count
- do
- {
- int n = tokenizebyseparator(l, "\\");
- for (int j = 2; j < n; j += 2)
- db_put(db, argv(j - 1), uri_unescape(argv(j)));
- }
- while ((l = fgets(fh)));
- }
- fclose(fh);
- return db;
-}
-
-void db_dump(int db, string filename)
-{
- int fh = fopen(filename, FILE_WRITE);
- if (fh < 0) LOG_FATALF("Can't dump DB to %s\n");
- fputs(fh, "0\n");
- for (int i = 0, n = buf_getsize(db); i < n; ++i)
- {
- int m = tokenizebyseparator(bufstr_get(db, i), "\\");
- for (int j = 2; j < m; j += 2)
- fputs(fh, strcat("\\", argv(j - 1), "\\", argv(j), "\n"));
- }
- fclose(fh);
-}
-
-void db_close(int db)
-{
- buf_del(db);
-}
-#define HM_DELETE(this) db_close(this)
-
-string db_get(int db, string key)
-{
- int h = crc16(false, key) % DB_BUCKETS;
- return uri_unescape(infoget(bufstr_get(db, h), key));
-}
-#define HM_gets(this, k) db_get(this, k)
-
-#define db_remove(db, key) db_put(db, key, "")
-
-void db_put(int db, string key, string value)
-{
- int h = crc16(false, key) % DB_BUCKETS;
- bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value)));
-}
-#define HM_sets(this, key, val) db_put(this, key, val)
-
-void db_test()
-{
- LOG_INFO("LOAD...\n");
- int db = db_load("foo.db");
- LOG_INFO("LOADED. FILL...\n");
- for (int i = 0; i < DB_BUCKETS; ++i)
- db_put(db, ftos(random()), "X");
- LOG_INFO("FILLED. SAVE...\n");
- db_save(db, "foo.db");
- LOG_INFO("SAVED. CLOSE...\n");
- db_close(db);
- LOG_INFO("CLOSED.\n");
-}
-
-#endif
--- /dev/null
+#pragma once
+
+#include "int.qh"
+
+// Databases (hash tables)
+const int DB_BUCKETS = 8192;
+void db_save(int db, string filename)
+{
+ int fh = fopen(filename, FILE_WRITE);
+ if (fh < 0)
+ {
+ LOG_WARNINGF("^1Can't write DB to %s\n", filename);
+ return;
+ }
+ fputs(fh, strcat(ftos(DB_BUCKETS), "\n"));
+ for (int i = 0, n = buf_getsize(db); i < n; ++i)
+ fputs(fh, strcat(bufstr_get(db, i), "\n"));
+ fclose(fh);
+}
+
+typedef int HashMap;
+
+int db_create()
+{
+ return buf_create();
+}
+#define HM_NEW(this) (this = db_create())
+
+void db_put(int db, string key, string value);
+
+int db_load(string filename)
+{
+ int db = buf_create();
+ if (db < 0) return -1;
+ int fh = fopen(filename, FILE_READ);
+ if (fh < 0) return db;
+ string l = fgets(fh);
+ if (stoi(l) == DB_BUCKETS)
+ {
+ for (int i = 0; (l = fgets(fh)); ++i)
+ {
+ if (l != "") bufstr_set(db, i, l);
+ }
+ }
+ else
+ {
+ // different count of buckets, or a dump?
+ // need to reorganize the database then (SLOW)
+ //
+ // note: we also parse the first line (l) in case the DB file is
+ // missing the bucket count
+ do
+ {
+ int n = tokenizebyseparator(l, "\\");
+ for (int j = 2; j < n; j += 2)
+ db_put(db, argv(j - 1), uri_unescape(argv(j)));
+ }
+ while ((l = fgets(fh)));
+ }
+ fclose(fh);
+ return db;
+}
+
+void db_dump(int db, string filename)
+{
+ int fh = fopen(filename, FILE_WRITE);
+ if (fh < 0) LOG_FATALF("Can't dump DB to %s\n");
+ fputs(fh, "0\n");
+ for (int i = 0, n = buf_getsize(db); i < n; ++i)
+ {
+ int m = tokenizebyseparator(bufstr_get(db, i), "\\");
+ for (int j = 2; j < m; j += 2)
+ fputs(fh, strcat("\\", argv(j - 1), "\\", argv(j), "\n"));
+ }
+ fclose(fh);
+}
+
+void db_close(int db)
+{
+ buf_del(db);
+}
+#define HM_DELETE(this) db_close(this)
+
+string db_get(int db, string key)
+{
+ int h = crc16(false, key) % DB_BUCKETS;
+ return uri_unescape(infoget(bufstr_get(db, h), key));
+}
+#define HM_gets(this, k) db_get(this, k)
+
+#define db_remove(db, key) db_put(db, key, "")
+
+void db_put(int db, string key, string value)
+{
+ int h = crc16(false, key) % DB_BUCKETS;
+ bufstr_set(db, h, infoadd(bufstr_get(db, h), key, uri_escape(value)));
+}
+#define HM_sets(this, key, val) db_put(this, key, val)
+
+void db_test()
+{
+ LOG_INFO("LOAD...\n");
+ int db = db_load("foo.db");
+ LOG_INFO("LOADED. FILL...\n");
+ for (int i = 0; i < DB_BUCKETS; ++i)
+ db_put(db, ftos(random()), "X");
+ LOG_INFO("FILLED. SAVE...\n");
+ db_save(db, "foo.db");
+ LOG_INFO("SAVED. CLOSE...\n");
+ db_close(db);
+ LOG_INFO("CLOSED.\n");
+}
-#ifndef MATH_H
-#define MATH_H
+#pragma once
void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight)
{
}
return v;
}
-
-#endif
-#ifndef MISC_H
-#define MISC_H
+#pragma once
#ifdef __STDC__
#define EMPTY()
LAMBDA(block) \
name = __with_save; \
} MACRO_END
-
-#endif
-#ifndef NET_H
-#define NET_H
+#pragma once
#include "registry.qh"
#include "sort.qh"
} MACRO_END
#endif
#endif
-
-#endif
-#ifndef NIL_H
-#define NIL_H
+#pragma once
#ifdef QCC_SUPPORT_NIL
#define func_null nil
var void func_null();
string string_null;
#endif
-
-#endif
+++ /dev/null
-// noises "usually" start in the range -1..1
-entityclass(Noise);
-class(Noise).float noise_baccum;
-class(Noise).float noise_paccum;
-class(Noise).float noise_paccum2;
-class(Noise).float noise_paccum3;
-class(Noise).float noise_bstate;
-
-float Noise_Brown(entity e, float dt)
-{
- e.noise_baccum += random() * sqrt(dt); // same stddev for all dt
- return e.noise_baccum;
-}
-float Noise_Pink(entity e, float dt)
-{
- float f;
- f = dt * 60;
- // http://home.earthlink.net/~ltrammell/tech/pinkalg.htm
- if (random() > pow(0.3190, f)) e.noise_paccum = 0.34848 * (2 * random() - 1);
- if (random() > pow(0.7756, f)) e.noise_paccum2 = 0.28768 * (2 * random() - 1);
- if (random() > pow(0.9613, f)) e.noise_paccum3 = 0.43488 * (2 * random() - 1);
- return e.noise_paccum + e.noise_paccum2 + e.noise_paccum3;
-}
-float Noise_White(entity e, float dt)
-{
- return random() * 2 - 1;
-}
-/** +1 or -1 */
-float Noise_Burst(entity e, float dt, float p)
-{
- if (random() > pow(p, dt)) e.noise_bstate = !e.noise_bstate;
- return 2 * e.noise_bstate - 1;
-}
--- /dev/null
+#pragma once
+
+// noises "usually" start in the range -1..1
+entityclass(Noise);
+class(Noise).float noise_baccum;
+class(Noise).float noise_paccum;
+class(Noise).float noise_paccum2;
+class(Noise).float noise_paccum3;
+class(Noise).float noise_bstate;
+
+float Noise_Brown(entity e, float dt)
+{
+ e.noise_baccum += random() * sqrt(dt); // same stddev for all dt
+ return e.noise_baccum;
+}
+float Noise_Pink(entity e, float dt)
+{
+ float f;
+ f = dt * 60;
+ // http://home.earthlink.net/~ltrammell/tech/pinkalg.htm
+ if (random() > pow(0.3190, f)) e.noise_paccum = 0.34848 * (2 * random() - 1);
+ if (random() > pow(0.7756, f)) e.noise_paccum2 = 0.28768 * (2 * random() - 1);
+ if (random() > pow(0.9613, f)) e.noise_paccum3 = 0.43488 * (2 * random() - 1);
+ return e.noise_paccum + e.noise_paccum2 + e.noise_paccum3;
+}
+float Noise_White(entity e, float dt)
+{
+ return random() * 2 - 1;
+}
+/** +1 or -1 */
+float Noise_Burst(entity e, float dt, float p)
+{
+ if (random() > pow(p, dt)) e.noise_bstate = !e.noise_bstate;
+ return 2 * e.noise_bstate - 1;
+}
-#ifndef OO_H
-#define OO_H
+#pragma once
#include "misc.qh"
#include "nil.qh"
#undef spawn_static
#undef spawn_1
#undef _vtbl
-
-#endif
+#pragma once
+
/*
Copyright (C) 2015 Micah Talkiewicz.
-#ifndef PROGNAME_H
-#define PROGNAME_H
+#pragma once
#if defined(MENUQC)
#define PROGNAME "MENUQC"
#else
#error "Unable to detect PROGNAME"
#endif
-
-#endif
-#ifndef RANDOM_H
-#define RANDOM_H
+#pragma once
float RandomSelection_totalweight;
float RandomSelection_best_priority;
#define psrandom(x)
#define prandom_debug()
#endif
-#endif
-#ifndef REGISTRY_H
-#define REGISTRY_H
+#pragma once
#include "oo.qh"
ATTRIB(id##Registry, REGISTRY_NEXT, entity, id##_first) \
ENDCLASS(id##Registry) \
REGISTER(Registries, REGISTRY, id, m_id, NEW(id##Registry));
-
-
-#endif
-#ifndef REGISTRY_NET_H
-#define REGISTRY_NET_H
+#pragma once
#include "net.qh"
WriteString(channel, hash);
}
#endif
-
-#endif
-#ifndef REPLICATE_H
-#define REPLICATE_H
+#pragma once
+
#ifndef MENUQC
#define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__))
#endif
#endif
-#endif
-#ifndef SELF_H
-#define SELF_H
+#pragma once
// Transition from global 'self' to local 'this'
#define SELFPARAM() noref const entity this = __self
#define self this
#endif
-
-#endif
-#ifndef SORT_H
-#define SORT_H
+#pragma once
/** is only ever called for i1 < i2 */
typedef void (int i1, int i2, entity pass) swapfunc_t;
if (j != i) swap(j, i, pass);
}
}
-
-#endif
-#ifndef SORTLIST_H
-#define SORTLIST_H
+#pragma once
entityclass(Sort);
// .float(entity,entity) sort_cmp;
if (a.sort_prev) a.sort_prev.sort_next = b; \
a.sort_prev = b; \
b.sort_next = a
-
-#endif
-#ifndef SPAWNFUNC_H
-#define SPAWNFUNC_H
+#pragma once
/** If this global exists, only functions with spawnfunc_ name prefix qualify as spawn functions */
noref bool require_spawnfunc_prefix;
#define spawnfunc(...) EVAL_spawnfunc(OVERLOAD(spawnfunc, __VA_ARGS__))
#define EVAL_spawnfunc(...) __VA_ARGS__
-
-#endif
-#ifndef STATIC_H
-#define STATIC_H
+#pragma once
void __static_init() {}
#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
#define STATIC_INIT_LATE(func) _STATIC_INIT(__static_init_late, func##_late)
#define PRECACHE(func) _STATIC_INIT(__static_init_precache, func##_precache)
#define SHUTDOWN(func) _STATIC_INIT(__shutdown, func##_shutdown)
-
-#endif
-#ifndef LIB_STATS_H
-#define LIB_STATS_H
+#pragma once
// TODO: rename to 'netvars'
#ifdef SVQC
STATIC_INIT(stats_add) { stats_add(); }
#endif
-
-#endif
-#ifndef STRING_H
-#define STRING_H
+#pragma once
#include "nil.qh"
#include "sort.qh"
#define HEXDIGIT_TO_DEC_RAW(d) (strstrofs(HEXDIGITS, (d), 0))
#define HEXDIGIT_TO_DEC(d) ((HEXDIGIT_TO_DEC_RAW(d) | 0x10) - 0x10)
#define DEC_TO_HEXDIGIT(d) (substring(HEXDIGITS, (d), 1))
-
-#endif
-#ifndef STRUCT_H
-#define STRUCT_H
+#pragma once
#ifndef QCC_SUPPORT_STRUCT
#define _STRUCT_DECLARE(x, id, type, END) noref type x##_##id;
#define _STRUCT_MEMBER(my, id, type, END) type id;
#define STRUCT(id, s) struct STRUCT_##id { s(_STRUCT_MEMBER, ) };
#endif
-
-#endif
-#ifndef TEST_H
-#define TEST_H
+#pragma once
#define TEST(id) \
void _TEST_##id(); \
bool TEST_RunAll();
bool TEST_Run(string test);
-
-#endif
-#ifndef UNSAFE_H
-#define UNSAFE_H
+#pragma once
#define reinterpret_cast(T, it) _unsafe_cast_##T(0, it)
#define X(T) T _unsafe_cast_##T(int dummy, ...) { return ...(0, T); }
{
INTEGER_ONE = reinterpret_cast(int, _unsafe_fld2) - reinterpret_cast(int, _unsafe_fld1);
}
-
-#endif
-#ifndef URLLIB_H
-#define URLLIB_H
+#pragma once
// URI handles
const int URI_GET_DISCARD = 0;
#define NUM_URL_ID (URI_GET_URLLIB_END - URI_GET_URLLIB + 1)
void url_multi_fopen(string url, float mode, url_ready_func rdy, entity pass);
-#endif
-#ifndef VECTOR_H
-#define VECTOR_H
+#pragma once
noref vector _vlen2;
#define vlen2(v) (_vlen2 = (v), dotproduct(_vlen2, _vlen2))
return ret;
}
#endif
-
-#endif
-#ifndef YENC_H
-#define YENC_H
+#pragma once
#include "test.qh"
}
TEST_OK();
}
-
-#endif