X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Freplicate.qh;h=4031352fedbe8c34eb264ca20c22682c4f2e1c0a;hb=988f88a3e0c9ff13570e23b593b69257047188be;hp=6ff77139f83e76f05f089edd397d137592535c10;hpb=c0582a52156c4e74e4c5313e5f360275493a8733;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index 6ff77139f..4031352fe 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -1,49 +1,63 @@ -#ifndef REPLICATE_H -#define REPLICATE_H -#ifndef MENUQC +#pragma once -#define REPLICATE(...) EVAL(OVERLOAD(REPLICATE, __VA_ARGS__)) +#ifdef GAMEQC -[[accumulate]] void ReplicateVars(entity this, string thisname, int i) { } + /** + * Replicate a client cvar into a server field + * + * @param fld The field to replicate into + * @param type The field type + * @param cvar The cvar name + */ + #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__)) + #define EVAL_REPLICATE(...) __VA_ARGS__ -#define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, ) -#define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func) -#define REPLICATE_string(fld, var, func) REPLICATE_7(fld, string, var, , \ - { if (field) strunzone(field); field = strzone(it); }, \ - { if (field) strunzone(field); field = string_null; }, \ - { \ - /* also initialize to the default value of func when requesting cvars */ \ - string s = func(field); \ - if (s != field) { \ - strunzone(field); \ - field = strzone(s); \ - } \ - }) -#define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, { field = stof(it); }, , ) -#define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, { field = boolean(stoi(it)); }, , ) -#define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, { field = stoi(it); }, , ) + ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {} -#if defined(SVQC) - #define REPLICATE_7(fld, type, var, func, create, destroy, after) \ - void ReplicateVars(entity this, string thisname, int i) { \ - type field = this.fld; \ - if (i < 0) { destroy } \ - else { \ - string it = func(argv(i + 1)); \ - bool current = thisname == var; \ - if (i > 0) { \ - if (current) { create } \ - } else { \ - stuffcmd(this, "cl_cmd sendcvar " var "\n"); \ - } \ - if (current) { after } \ - } \ - this.fld = field; \ - } -#elif defined(CSQC) - // TODO - #define REPLICATE_7(fld, type, var, func, create, destroy, after) -#endif + #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, ) + #define REPLICATE_4(fld, type, var, func) REPLICATE_##type(fld, var, func) + #define REPLICATE_string(fld, var, func) \ + REPLICATE_7(fld, string, var, , \ + { strcpy(field, it); }, \ + { if (field) strunzone(field); field = string_null; }, \ + { \ + /* also initialize to the default value of func when requesting cvars */ \ + string s = func(field); \ + if (s != field) \ + { \ + strunzone(field); \ + field = strzone(s); \ + } \ + }) + #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, { field = stof(it); }, , ) + #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, { field = boolean(stoi(it)); }, , ) + #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, { field = stoi(it); }, , ) + + #if defined(SVQC) + #define REPLICATE_7(fld, type, var, func, create, destroy, after) \ + void ReplicateVars(entity this, entity store, string thisname, int i) \ + { \ + type field = store.fld; \ + if (i < 0) { destroy } \ + else \ + { \ + string it = func(argv(i + 1)); \ + bool current = thisname == var; \ + if (i > 0) \ + { \ + if (current) { create } \ + } \ + else \ + { \ + stuffcmd(this, "cl_cmd sendcvar " var "\n"); \ + } \ + if (current) { after } \ + } \ + store.fld = field; \ + } + #elif defined(CSQC) + // TODO + #define REPLICATE_7(fld, type, var, func, create, destroy, after) + #endif -#endif #endif