engine/quakec/csaddon/src/brush_history.qc

233 lines
6.1 KiB
Plaintext
Raw Normal View History

openxr plugin: tweaked - inputs should be working properly now, and are visible to csqc. subject to further breaking changes, however. _pext_vrinputs: added cvar to enable vr inputs protocol extension allowing vr inputs to be networked to ssqc too. defaults to 0 for now, will be renamed when deemed final. updates menu: the prompt to enable sources is now more explicit instead of expecting the user to have a clue. updates menu: added a v3 sources format, which should be more maintainable. not final. updates menu: try to give reasons why sources might be failing (to help blame ISPs if they try fucking over TTH dns again). presets menu: no longer closes the instant a preset is chosen. some presets have a couple of modifiers listed. force the demo loop in the background to serve as a preview. prompts menus: now does word wrapping. ftemaster: support importing server lists from other master servers (requested by Eukara). server: try to detect when non-reply inbound packets are blocked by firewalls/nats/etc (using ftemaster to do so). qcvm: added pointcontentsmask builtin, allowing it to probe more than just world, with fte's full contentbit range instead of just q1 legacy. qcvm: memfill8 builtin now works on createbuffer() pointers. qcvm: add missing unsigned ops. Fixed double comparison ops. fixed bug with op_store_i64. added missing OP_LOADP_I64 qcc: added '#pragma framerate RATE' for overriding implicit nextthink durations. qcc: fixed '#pragma DONT_COMPILE_THIS_FILE' to not screw up comments. qcc: added __GITURL__ __GITHASH__ __GITDATE__ __GITDATETIME__ __GITDESC__ for any mods that might want to make use of that. qcc: fix up -Fhashonly a little setrenderer: support for vulkan gpu enumeration. rulesets: reworked to support custom rulesets (using hashes to catch haxxors, though still nothing prevents just changing the client to ignore rulesets) bspx: use our BIH code for the bspx BRUSHLIST lump instead of the older less efficient code. (static)iqm+obj: these model formats can now be used for the worldmodel (with a suitable .ent file). Also using BIH for much better collision performance. pmove: tried to optimise PM_NudgePosition, should boost fps in stress tests. wayland: fix a crash on startup. mousegrabs now works better. imagetool: uses sdl for previews. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5813 fc73d0e0-1445-4013-8a0c-d673dee63da5
2021-04-13 22:21:04 -07:00
//history is implemented using a ringbuffer
typedef struct
{
float timestamp;
int brushmodel;
int wasdelete;
int id;
brushface_t *brushdata; //list of faces
patchvert_t *patchdata; //list of control points
union
{
struct
{
int numfaces;
int contents;
} brushinfo;
patchinfo_t patchinfo;
};
} history_t;
history_t *historyring;
int historyring_length;
int history_min; //oldest we can go
int history; //updated on each change
int history_max; //max value for redo
//when replaying history, ids get changed, which makes things fun. this updates selection state for edited brushes.
void(int modelidx, int old, int new) history_remap =
{
for (int i = history_min; i < history_max; i++)
{
history_t *h = &historyring[i & (historyring_length-1)];
if (h->id == old)
h->id = new;
}
int i = brush_isselected(modelidx, old);
if (i)
{
i--;
brush_selected(modelidx, old, -1, FALSE);
brush_selected(modelidx, new, -1, TRUE);
selectedbrushes[i].id = new;
}
};
void() brush_undo =
{
if (history == history_min)
print("Nothing to undo.\n");
do
{
if (history <= history_min)
return;
history--;
history_t *h = &historyring[history & (historyring_length-1)];
//we're undoing, so deletes create and creates delete. weird, yes.
if (h->wasdelete)
{
int newid;
if (h->patchdata)
newid = patch_create(h->brushmodel, 0, h->patchdata, h->patchinfo);
else
newid = brush_create(h->brushmodel, h->brushdata, h->brushinfo.numfaces, h->brushinfo.contents);
history_remap(h->brushmodel, h->id, newid);
h->id = newid;
}
else
{
brush_delete(h->brushmodel, h->id);
h->id = 0;
}
if (history == history_min)
break; //as far back as we can go, more timestamps are invalid
} while (historyring[(history-1) & (historyring_length-1)].timestamp == h->timestamp);
};
void() brush_redo =
{
if (history == history_max)
print("Nothing to redo.");
do
{
if (history >= history_max)
return;
history_t *h = &historyring[history & (historyring_length-1)];
//we're redoing stuff that has previously been done. yay.
if (h->wasdelete)
{
brush_delete(h->brushmodel, h->id);
h->id = 0;
}
else
{
int newid;
if (h->patchdata)
newid = patch_create(h->brushmodel, 0, h->patchdata, h->patchinfo);
else
newid = brush_create(h->brushmodel, h->brushdata, h->brushinfo.numfaces, h->brushinfo.contents);
history_remap(h->brushmodel, h->id, newid);
h->id = newid;
}
history++;
if (history == history_max)
return; //don't poke beyond the end...
} while (historyring[history & (historyring_length-1)].timestamp == h->timestamp);
};
history_t *() history_allocate = //returns a new history entry.
{
if (!historyring)
{
history_min = history_max = history;
historyring_length = 512;
historyring = memalloc(sizeof(*historyring)*historyring_length);
}
history_t *h = &historyring[history & (historyring_length-1)];
history++;
history_max = history; //always break any pending redos
if (history_min < history_max - historyring_length)
history_min = history_max - historyring_length;
h->timestamp = time;
memfree(h->brushdata);
h->brushdata = __NULL__;
return h;
};
void(history_t *h) history_deallocate = //cancels a newly created history entry, in case something went wrong.
{
history--;
if (h == &historyring[history & (historyring_length-1)])
history_max--;
};
//create and journal.
int(int mod, brushface_t *faces, int numfaces, int contents, float selectnow) brush_history_create =
{
history_t *h = history_allocate();
h->brushdata = memalloc(sizeof(brushface_t) * numfaces);
memcpy(h->brushdata, faces, sizeof(brushface_t) * numfaces);
h->brushinfo.numfaces = numfaces;
h->brushinfo.contents = contents;
h->brushmodel = mod;
h->wasdelete = FALSE;
h->id = brush_create(h->brushmodel, h->brushdata, h->brushinfo.numfaces, h->brushinfo.contents);
if (!h->id)
history_deallocate(h);
else if (selectnow)
brush_select(mod, h->id);
return h->id;
};
2023-04-16 19:39:30 -07:00
//create and journal.
int(int mod, patchvert_t *vert, patchinfo_t info, float selectnow) patch_history_create =
{
int totalcp = info.cpwidth * info.cpheight;
history_t *h = history_allocate();
h->patchdata = memalloc(sizeof(patchvert_t) * totalcp);
memcpy(h->patchdata, vert, sizeof(patchvert_t) * totalcp);
h->patchinfo = info;
h->brushmodel = mod;
h->wasdelete = FALSE;
h->id = patch_create(h->brushmodel, 0, vert, info);
if (!h->id)
history_deallocate(h);
else if (selectnow)
brush_select(mod, h->id);
return h->id;
};
openxr plugin: tweaked - inputs should be working properly now, and are visible to csqc. subject to further breaking changes, however. _pext_vrinputs: added cvar to enable vr inputs protocol extension allowing vr inputs to be networked to ssqc too. defaults to 0 for now, will be renamed when deemed final. updates menu: the prompt to enable sources is now more explicit instead of expecting the user to have a clue. updates menu: added a v3 sources format, which should be more maintainable. not final. updates menu: try to give reasons why sources might be failing (to help blame ISPs if they try fucking over TTH dns again). presets menu: no longer closes the instant a preset is chosen. some presets have a couple of modifiers listed. force the demo loop in the background to serve as a preview. prompts menus: now does word wrapping. ftemaster: support importing server lists from other master servers (requested by Eukara). server: try to detect when non-reply inbound packets are blocked by firewalls/nats/etc (using ftemaster to do so). qcvm: added pointcontentsmask builtin, allowing it to probe more than just world, with fte's full contentbit range instead of just q1 legacy. qcvm: memfill8 builtin now works on createbuffer() pointers. qcvm: add missing unsigned ops. Fixed double comparison ops. fixed bug with op_store_i64. added missing OP_LOADP_I64 qcc: added '#pragma framerate RATE' for overriding implicit nextthink durations. qcc: fixed '#pragma DONT_COMPILE_THIS_FILE' to not screw up comments. qcc: added __GITURL__ __GITHASH__ __GITDATE__ __GITDATETIME__ __GITDESC__ for any mods that might want to make use of that. qcc: fix up -Fhashonly a little setrenderer: support for vulkan gpu enumeration. rulesets: reworked to support custom rulesets (using hashes to catch haxxors, though still nothing prevents just changing the client to ignore rulesets) bspx: use our BIH code for the bspx BRUSHLIST lump instead of the older less efficient code. (static)iqm+obj: these model formats can now be used for the worldmodel (with a suitable .ent file). Also using BIH for much better collision performance. pmove: tried to optimise PM_NudgePosition, should boost fps in stress tests. wayland: fix a crash on startup. mousegrabs now works better. imagetool: uses sdl for previews. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5813 fc73d0e0-1445-4013-8a0c-d673dee63da5
2021-04-13 22:21:04 -07:00
//delete and journal.
void(int mod, int id) brush_history_delete =
{
int numfaces = brush_get(mod, id, __NULL__, 0, __NULL__);
int numcp = patch_getcp(mod, id, __NULL__, 0, __NULL__);
brush_deselect(mod, id);
if (!numfaces && !numcp)
return; //doesn't exist or something, some kind of error. we can't log a delete if it didn't delete anything, if only because we can't recreate it if its undone.
history_t *h = history_allocate();
h->brushmodel = mod;
h->id = id;
h->wasdelete = TRUE;
if (numcp)
{
h->patchdata = memalloc(sizeof(patchvert_t) * numcp);
patch_getcp(mod, id, h->patchdata, numcp, &h->patchinfo);
}
else
{
h->brushdata = memalloc(sizeof(brushface_t) * numfaces);
h->brushinfo.numfaces = brush_get(mod, id, h->brushdata, numfaces, &h->brushinfo.contents);
}
brush_delete(mod, id);
};
int(int mod, int id, brushface_t *faces, int numfaces, int contents) brush_history_edit =
{
int wasselected = brush_isselected(mod, id);
if (wasselected)
selectedbrushes[wasselected-1].id = -id; //hack so that brush_history_delete won't remove this entry.
brush_history_delete(mod, id);
id = brush_history_create(mod, faces, numfaces, contents, FALSE);
if (wasselected)
{
selectedbrushes[wasselected-1].id = id;
brush_selected(mod, id, -1, TRUE);
}
return id;
2023-04-16 19:39:30 -07:00
};
int(int mod, int id, patchvert_t *vert, patchinfo_t info) patch_history_edit =
{
int wasselected = brush_isselected(mod, id);
if (wasselected)
selectedbrushes[wasselected-1].id = -id; //hack so that brush_history_delete won't remove this entry.
brush_history_delete(mod, id);
id = patch_history_create(mod, vert, info, FALSE);
if (wasselected)
{
selectedbrushes[wasselected-1].id = id;
brush_selected(mod, id, -1, TRUE);
}
return id;
openxr plugin: tweaked - inputs should be working properly now, and are visible to csqc. subject to further breaking changes, however. _pext_vrinputs: added cvar to enable vr inputs protocol extension allowing vr inputs to be networked to ssqc too. defaults to 0 for now, will be renamed when deemed final. updates menu: the prompt to enable sources is now more explicit instead of expecting the user to have a clue. updates menu: added a v3 sources format, which should be more maintainable. not final. updates menu: try to give reasons why sources might be failing (to help blame ISPs if they try fucking over TTH dns again). presets menu: no longer closes the instant a preset is chosen. some presets have a couple of modifiers listed. force the demo loop in the background to serve as a preview. prompts menus: now does word wrapping. ftemaster: support importing server lists from other master servers (requested by Eukara). server: try to detect when non-reply inbound packets are blocked by firewalls/nats/etc (using ftemaster to do so). qcvm: added pointcontentsmask builtin, allowing it to probe more than just world, with fte's full contentbit range instead of just q1 legacy. qcvm: memfill8 builtin now works on createbuffer() pointers. qcvm: add missing unsigned ops. Fixed double comparison ops. fixed bug with op_store_i64. added missing OP_LOADP_I64 qcc: added '#pragma framerate RATE' for overriding implicit nextthink durations. qcc: fixed '#pragma DONT_COMPILE_THIS_FILE' to not screw up comments. qcc: added __GITURL__ __GITHASH__ __GITDATE__ __GITDATETIME__ __GITDESC__ for any mods that might want to make use of that. qcc: fix up -Fhashonly a little setrenderer: support for vulkan gpu enumeration. rulesets: reworked to support custom rulesets (using hashes to catch haxxors, though still nothing prevents just changing the client to ignore rulesets) bspx: use our BIH code for the bspx BRUSHLIST lump instead of the older less efficient code. (static)iqm+obj: these model formats can now be used for the worldmodel (with a suitable .ent file). Also using BIH for much better collision performance. pmove: tried to optimise PM_NudgePosition, should boost fps in stress tests. wayland: fix a crash on startup. mousegrabs now works better. imagetool: uses sdl for previews. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5813 fc73d0e0-1445-4013-8a0c-d673dee63da5
2021-04-13 22:21:04 -07:00
};