From: Mircea Kitsune Date: Fri, 28 Oct 2011 23:09:41 +0000 (+0300) Subject: At the expense of the developer's sanity, get the save system working with arrays... X-Git-Tag: xonotic-v0.6.0~35^2~18^2~63 X-Git-Url: http://git.xonotic.org/?a=commitdiff_plain;h=e96b84d0be4063b8e7f2e08e966009f0c210a006;p=xonotic%2Fxonotic-data.pk3dir.git At the expense of the developer's sanity, get the save system working with arrays. Also fix a code typo that was always there, making the storage get saved each frame. By default, storage is saved every 5 seconds --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 74d2afe7d..f7b33003c 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -547,7 +547,7 @@ seta g_balance_cloaked_alpha 0.25 set g_sandbox 0 "allow players to spawn and edit objects around the map" set g_sandbox_info 1 "print object information to the server. 1 prints info about spawned / removed objects, 2 also prints info about edited objects" set g_sandbox_storage_name default "name of the selected storage to use" -set g_sandbox_storage_autosave 10 "storage is automatically saved every specified number of seconds" +set g_sandbox_storage_autosave 5 "storage is automatically saved every specified number of seconds" set g_sandbox_storage_autoload 1 "if a storage file exists for the given map, automatically load it at startup" set g_sandbox_editor_maxobjects 1000 "maximum number of objects that may exist at a time" set g_sandbox_editor_free 0 "when enabled, players can edit any object on the map, not just the objects they've spawned" diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index cfa7ce960..a53a6fca7 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -1,3 +1,4 @@ +const float MAX_STORAGE_ATTACHMENTS = 16; float object_count; .string object_clipboard; .entity object_attach; @@ -150,40 +151,52 @@ void sandbox_ObjectRemove(entity e) object_count -= 1; } -string sandbox_ObjectPort_Save_string(entity e, float database) -{ - string s; - s = strcat(s, e.model, " "); - s = strcat(s, ftos(e.skin), " "); - s = strcat(s, ftos(e.alpha), " "); - s = strcat(s, sprintf("\"%.9v\"", e.colormod), " "); - s = strcat(s, sprintf("\"%.9v\"", e.glowmod), " "); - s = strcat(s, ftos(e.frame), " "); - s = strcat(s, ftos(e.scale), " "); - s = strcat(s, ftos(e.movetype), " "); - s = strcat(s, ftos(e.damageforcescale), " "); - if(e.material) s = strcat(s, e.material, " "); else s = strcat(s, "- "); // none - if(database) - { - if(e.crypto_idfp) s = strcat(s, e.crypto_idfp, " "); else s = strcat(s, "- "); // none - s = strcat(s, sprintf("\"%.9v\"", e.origin), " "); - s = strcat(s, sprintf("\"%.9v\"", e.angles), " "); - } - s = strcat(s, "; "); - return s; -} +string save_string[MAX_STORAGE_ATTACHMENTS]; // fteqcc crashes if this isn't defined as a global string sandbox_ObjectPort_Save(entity e, float database) { // save object properties + float i; string s; entity head; - // first set the properties of the main object, then those of each child - s = sandbox_ObjectPort_Save_string(e, database); for(head = world; (head = find(head, classname, "object")); ) { - if(head.owner == e) - s = strcat(s, sandbox_ObjectPort_Save_string(head, database)); + // the main object needs to be saved first in the array, with attached objects following after + float tmp; + if(head == e) + tmp = 0; + else if(head.owner == e) + { + i += 1; // child objects start from 1 + tmp = i; + } + else + continue; + + save_string[tmp] = strcat(save_string[tmp], head.model, " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.skin), " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.alpha), " "); + save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.colormod), " "); + save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.glowmod), " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.frame), " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.scale), " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.movetype), " "); + save_string[tmp] = strcat(save_string[tmp], ftos(head.damageforcescale), " "); + if(head.material) save_string[tmp] = strcat(save_string[tmp], head.material, " "); else save_string[tmp] = strcat(save_string[tmp], "- "); // none + if(database) + { + if(head.crypto_idfp) save_string[tmp] = strcat(save_string[tmp], head.crypto_idfp, " "); else save_string[tmp] = strcat(save_string[tmp], "- "); // none + save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.origin), " "); + save_string[tmp] = strcat(save_string[tmp], sprintf("\"%.9v\"", head.angles), " "); + } + } + + // now apply the array to a simple string, with ; separating objects + for(i = 0; i <= MAX_STORAGE_ATTACHMENTS; ++i) + { + if(save_string[i]) + s = strcat(s, save_string[i], "; "); + save_string[i] = string_null; // fully clear the string } return s; @@ -622,7 +635,7 @@ MUTATOR_HOOKFUNCTION(sandbox_StartFrame) { if(!autocvar_g_sandbox_storage_autosave) return FALSE; - if(time < autocvar_g_sandbox_storage_autosave) + if(time < autosave_time) return FALSE; autosave_time = time + autocvar_g_sandbox_storage_autosave;