]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
make the cpp hack for ACCUMULATE_FUNCTION optional
authorRudolf Polzer <divverent@xonotic.org>
Wed, 26 Sep 2012 07:32:14 +0000 (09:32 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 26 Sep 2012 07:32:14 +0000 (09:32 +0200)
I had found a way to achieve the same using DP_QC_ENTITYDATA,
FRIK_FILE string handling, and DP_QC_ENTITYSTRING.

qcsrc/client/Main.qc
qcsrc/common/util-pre.qh
qcsrc/common/util.qh
qcsrc/dpdefs/csprogsdefs.qc
qcsrc/dpdefs/menudefs.qc
qcsrc/menu/menu.qc
qcsrc/server/g_world.qc

index 076b255a358f206d76a9b4d5b58f7a7a6daa332e..c71c787c6e679cd74ecba9c869f3f7b604ff8b21 100644 (file)
@@ -152,8 +152,8 @@ void CSQC_Init(void)
        GetTeam(COLOR_SPECTATOR, true); // add specs first
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        WaypointSprite_Load();
 
index b65193d44ce26e6341b042b09c24c6283cf1da59..da86e98014a9e26fe625d23e2f5e95e8f65ae999 100644 (file)
@@ -1,6 +1,9 @@
 #pragma flag enable subscope
 #pragma flag enable lo
 
+// FTEQCC can do this
+#define HAVE_YO_DAWG_CPP
+
 #ifndef NOCOMPAT
 //# define WORKAROUND_XON010
 //# define COMPAT_XON010_CHANNELS
index 49e51b0ffda7a4f95d23a08d41e1d46f6f75a398..faa605f887598c0dba17c7a6d5ae99654eb8e409 100644 (file)
@@ -1,12 +1,13 @@
 // a dummy macro that prevents the "hanging ;" warning
 #define ENDS_WITH_CURLY_BRACE
 
+#ifdef HAVE_YO_DAWG_CPP
 // TODO make ascii art pic of xzibit
 // YO DAWG!
 // I HERD YO LIEK MACROS
 // SO I PUT A MACRO DEFINITION IN YO MACRO DEFINITION
 // SO YO CAN EXPAND MACROS WHILE YO EXPAND MACROS
-#define ACCUMULATE_FUNCTION(func,otherfunc) \
+# define ACCUMULATE_FUNCTION(func,otherfunc) \
        #ifdef func \
        void __merge__##otherfunc() { func(); otherfunc(); } \
        #undef func \
        #else \
        #define func otherfunc \
        #endif
+# define CALL_ACCUMULATED_FUNCTION(func) \
+       func()
+#else
+# define ACCUMULATE_FUNCTION(func,otherfunc) \
+       .void _ACCUMULATE_##func##__##otherfunc;
+void ACCUMULATE_call(string func)
+{
+       float i;
+       float n = numentityfields();
+       string funcprefix = strcat("_ACCUMULATE_", func, "__");
+       float funcprefixlen = strlen(funcprefix);
+       for(i = 0; i < n; ++i)
+       {
+               string name = entityfieldname(i);
+               if(substring(name, 0, funcprefixlen) == funcprefix)
+                       callfunction(substring(name, funcprefixlen, -1));
+       }
+}
+# define CALL_ACCUMULATED_FUNCTION(func) \
+       ACCUMULATE_call(#func)
+#endif
 
 // this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline
 // NOTE: s IS allowed to be a tempstring
index 7b0644e3e83ebee82c888d3ad6ce4140a90e7c74..c9b9ce9cbc358056fa13b34169ac04c5c015559c 100644 (file)
@@ -1403,6 +1403,39 @@ void() example_skel_player_delete =
 // END OF EXAMPLES FOR FTE_CSQC_SKELETONOBJECTS
 //
 
+//DP_QC_ENTITYDATA
+//idea: KrimZon
+//darkplaces implementation: KrimZon
+//builtin definitions:
+float() numentityfields = #496;
+string(float fieldnum) entityfieldname = #497;
+float(float fieldnum) entityfieldtype = #498;
+string(float fieldnum, entity ent) getentityfieldstring = #499;
+float(float fieldnum, entity ent, string s) putentityfieldstring = #500;
+//constants:
+//Returned by entityfieldtype
+float FIELD_STRING   = 1;
+float FIELD_FLOAT    = 2;
+float FIELD_VECTOR   = 3;
+float FIELD_ENTITY   = 4;
+float FIELD_FUNCTION = 6;
+//description:
+//Versatile functions intended for storing data from specific entities between level changes, but can be customized for some kind of partial savegame.
+//WARNING: .entity fields cannot be saved and restored between map loads as they will leave dangling pointers.
+//numentityfields returns the number of entity fields. NOT offsets. Vectors comprise 4 fields: v, v_x, v_y and v_z.
+//entityfieldname returns the name as a string, eg. "origin" or "classname" or whatever.
+//entityfieldtype returns a value that the constants represent, but the field may be of another type in more exotic progs.dat formats or compilers.
+//getentityfieldstring returns data as would be written to a savegame, eg... "0.05" (float), "0 0 1" (vector), or "Hello World!" (string). Function names can also be returned.
+//putentityfieldstring puts the data returned by getentityfieldstring back into the entity.
+
+//DP_QC_ENTITYSTRING
+void(string s) loadfromdata = #529;
+void(string s) loadfromfile = #530;
+void(string s) callfunction = #605;
+void(float fh, entity e) writetofile = #606;
+float(string s) isfunction = #607;
+void(entity e, string s) parseentitydata = #608;
+
 // assorted builtins
 const float            STAT_MOVEVARS_TICRATE           = 240;
 const float            STAT_MOVEVARS_TIMESCALE         = 241;
index ad8666ed3548786759d2faeb6b9c59dcd5711377..c1198746171f79dd03925f9c2bbac36261717732 100644 (file)
@@ -504,6 +504,31 @@ float(string url, float id) uri_get = #513;
 float(string url, float id, string content_type, string data) uri_post = #513;
 float(string url, float id, string content_type, string delim, float buf) uri_postbuf = #513;
 
+//DP_QC_ENTITYDATA
+//idea: KrimZon
+//darkplaces implementation: KrimZon
+//builtin definitions:
+float() numentityfields = #496;
+string(float fieldnum) entityfieldname = #497;
+float(float fieldnum) entityfieldtype = #498;
+string(float fieldnum, entity ent) getentityfieldstring = #499;
+float(float fieldnum, entity ent, string s) putentityfieldstring = #500;
+//constants:
+//Returned by entityfieldtype
+float FIELD_STRING   = 1;
+float FIELD_FLOAT    = 2;
+float FIELD_VECTOR   = 3;
+float FIELD_ENTITY   = 4;
+float FIELD_FUNCTION = 6;
+//description:
+//Versatile functions intended for storing data from specific entities between level changes, but can be customized for some kind of partial savegame.
+//WARNING: .entity fields cannot be saved and restored between map loads as they will leave dangling pointers.
+//numentityfields returns the number of entity fields. NOT offsets. Vectors comprise 4 fields: v, v_x, v_y and v_z.
+//entityfieldname returns the name as a string, eg. "origin" or "classname" or whatever.
+//entityfieldtype returns a value that the constants represent, but the field may be of another type in more exotic progs.dat formats or compilers.
+//getentityfieldstring returns data as would be written to a savegame, eg... "0.05" (float), "0 0 1" (vector), or "Hello World!" (string). Function names can also be returned.
+//putentityfieldstring puts the data returned by getentityfieldstring back into the entity.
+
 // assorted undocumented extensions
 string(string, float) netaddress_resolve = #625;
 string(string search, string replace, string subject) strreplace = #484;
index b4c7ce746a8cd749a1eeed4cfd8d2d9b08b23da3..d3bf2ec6298996246eeabdf0c3424f51ca790187 100644 (file)
@@ -73,8 +73,8 @@ void m_init()
        }
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        float ddsload = cvar("r_texture_dds_load");
        float texcomp = cvar("gl_texturecompression");
index 120fa671625b2f4b6836fd624c379918e31d4afd..4cd5cc810a1c9f456bc372c0e8106e9b2d274488 100644 (file)
@@ -551,8 +551,8 @@ void spawnfunc___init_dedicated_server(void)
        self.classname = "worldspawn"; // safeguard against various stuff ;)
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        MapInfo_Enumerate();
        MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
@@ -560,7 +560,6 @@ void spawnfunc___init_dedicated_server(void)
 
 void Map_MarkAsRecent(string m);
 float world_already_spawned;
-void RegisterWeapons();
 void Nagger_Init();
 void ClientInit_Spawn();
 void WeaponStats_Init();
@@ -598,8 +597,8 @@ void spawnfunc_worldspawn (void)
        }
 
        // needs to be done so early because of the constants they create
-       RegisterWeapons();
-       RegisterGametypes();
+       CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
+       CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
 
        ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));