Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: config/resetbinds.cfg
- ===================================================================
- --- config/resetbinds.cfg (revision 6646)
- +++ config/resetbinds.cfg (working copy)
- @@ -158,6 +158,8 @@
- bind LSHIFT "crouch"
- bind RCTRL "jump"
- bind LCTRL "jump"
- +editbind RCTRL " "
- +editbind LCTRL " "
- bind RALT ""
- bind LALT "showscores 0; toggleshowmap"
- bind RMETA ""
- Index: source/src/bot/bot_waypoint.cpp
- ===================================================================
- --- source/src/bot/bot_waypoint.cpp (revision 6646)
- +++ source/src/bot/bot_waypoint.cpp (working copy)
- @@ -19,8 +19,9 @@
- #endif
- VAR(xhairwpsel, 0, 1, 1);
- -extern block sel;
- -#define curselection (xhairwpsel ? vec(sel.x, sel.y, S(sel.x, sel.y)->floor+2.0f) : vec(player1->o.x, player1->o.y, player1->o.z))
- +// FIXME: multiple selections support ?
- +extern vector<block> sels;
- +#define curselection (xhairwpsel ? vec(sels.last().x, sels.last().y, S(sels.last().x, sels.last().y)->floor+2.0f) : vec(player1->o.x, player1->o.y, player1->o.z))
- // Waypoint class begin
- Index: source/src/editing.cpp
- ===================================================================
- --- source/src/editing.cpp (revision 6646)
- +++ source/src/editing.cpp (working copy)
- @@ -7,18 +7,17 @@
- // the current selection, used by almost all editing commands
- // invariant: all code assumes that these are kept inside MINBORD distance of the edge of the map
- -block sel =
- -{
- - variable("selx", 0, 0, 4096, &sel.x, NULL, false),
- - variable("sely", 0, 0, 4096, &sel.y, NULL, false),
- - variable("selxs", 0, 0, 4096, &sel.xs, NULL, false),
- - variable("selys", 0, 0, 4096, &sel.ys, NULL, false),
- -};
- +vector<block> sels;
- -int selh = 0;
- -bool selset = false;
- +#define SEL_ATTR(attr) { string buf; loopv(sels) { concatformatstring(buf, "%d ", sels[i].attr); } result(buf); }
- +COMMANDF(selx, ARG_NONE, (void) { SEL_ATTR(x); });
- +COMMANDF(sely, ARG_NONE, (void) { SEL_ATTR(y); });
- +COMMANDF(selxs, ARG_NONE, (void) { SEL_ATTR(xs); });
- +COMMANDF(selys, ARG_NONE, (void) { SEL_ATTR(ys); });
- +#undef SEL_ATTR
- -#define loopselxy(b) { makeundo(); loop(x,sel.xs) loop(y,sel.ys) { sqr *s = S(sel.x+x, sel.y+y); b; } remip(sel); }
- +#define loopselxy(sel, b) { makeundo(sel); loop(x,(sel).xs) loop(y,(sel).ys) { sqr *s = S((sel).x+x, (sel).y+y); b; } remip(sel); }
- +#define loopselsxy(b) { loopv(sels) loopselxy(sels[i], b); }
- int cx, cy, ch;
- @@ -46,7 +45,6 @@
- player1->attacking = false;
- }
- keyrepeat(editmode);
- - selset = false;
- editing = editmode ? 1 : 0;
- player1->state = editing ? CS_EDITING : CS_ALIVE;
- if(editing && player1->onladder) player1->onladder = false;
- @@ -58,29 +56,17 @@
- COMMAND(edittoggle, ARG_NONE);
- -char *editinfo()
- +bool correctsel(block &s) // ensures above invariant
- {
- - static string info;
- - if(!editmode) return NULL;
- - int e = closestent();
- - if(e<0) return NULL;
- - entity &c = ents[e];
- - formatstring(info)("closest entity = %s (%d, %d, %d, %d), selection = (%d, %d)", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, sel.xs, sel.ys);
- - return info;
- + int bsize = ssize - MINBORD;
- + if(s.xs+s.x>bsize) s.xs = bsize-s.x;
- + if(s.ys+s.y>bsize) s.ys = bsize-s.y;
- + if(s.xs<=0 || s.ys<=0) return false;
- + else return !OUTBORD(s.x, s.y);
- }
- -void correctsel() // ensures above invariant
- -{
- - selset = !OUTBORD(sel.x, sel.y);
- - int bsize = ssize-MINBORD;
- - if(sel.xs+sel.x>bsize) sel.xs = bsize-sel.x;
- - if(sel.ys+sel.y>bsize) sel.ys = bsize-sel.y;
- - if(sel.xs<=0 || sel.ys<=0) selset = false;
- -}
- -
- bool noteditmode(const char* func)
- {
- - correctsel();
- if(!editmode)
- {
- if(func && func[0]!='\0') conoutf("\f4[\f3%s\f4]\f5 is only allowed in edit mode", func);
- @@ -89,31 +75,77 @@
- return !editmode;
- }
- +inline bool selset()
- +{
- + return (sels.length() > 0);
- +}
- +
- bool noselection()
- {
- - if(!selset) conoutf("no selection");
- - return !selset;
- + if(!selset()) conoutf("no selection");
- + return !selset();
- }
- +char *editinfo()
- +{
- + static string info;
- + if(!editmode) return NULL;
- + int e = closestent();
- + if(e<0) return NULL;
- + entity &c = ents[e];
- + string selinfo = "no selection";
- + if(selset()) formatstring(selinfo)("selection = (%d, %d)", (sels.last()).xs, (sels.last()).ys);
- + formatstring(info)("closest entity = %s (%d, %d, %d, %d), %s", entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4, selinfo);
- + return info;
- +}
- +
- +
- #define EDITSEL if(noteditmode("EDITSEL") || noselection()) return
- #define EDITSELMP if(noteditmode("EDITSELMP") || noselection() || multiplayer()) return
- #define EDITMP if(noteditmode("EDITMP") || multiplayer()) return
- +// multiple sels
- +
- +// add a selection to the list
- +void addselection(int x, int y, int xs, int ys, int h)
- +{
- + block &s = sels.add();
- + s.x = x; s.y = y; s.xs = xs; s.ys = ys; s.h = h;
- + if(!correctsel(s)) { sels.drop(); }
- +}
- +
- +// reset all selections
- +void resetselections()
- +{
- + sels.shrink(0);
- +}
- +
- +// reset all invalid selections
- +void checkselections()
- +{
- + loopv(sels) if(!correctsel(sels[i])) sels.remove(i);
- +}
- +
- +// selection from cubescript
- void selectpos(int x, int y, int xs, int ys)
- {
- - block s = { x, y, xs, ys };
- - sel = s;
- - selh = 0;
- - correctsel();
- + resetselections();
- + addselection(x, y, xs, ys, 0);
- }
- -void makesel()
- +// update current selection, or add a new one
- +void makesel(bool isnew)
- {
- - block s = { min(lastx,cx), min(lasty,cy), abs(lastx-cx)+1, abs(lasty-cy)+1 };
- - sel = s;
- - selh = max(lasth,ch);
- - correctsel();
- - if(selset) rtex = *S(sel.x, sel.y);
- + if(isnew) addselection(min(lastx, cx), min(lasty, cy), abs(lastx-cx)+1, abs(lasty-cy)+1, max(lasth, ch));
- + else
- + {
- + block &cursel = sels.last();
- + cursel.x = min(lastx, cx); cursel.y = min(lasty, cy);
- + cursel.xs = abs(lastx-cx)+1; cursel.ys = abs(lasty-cy)+1;
- + cursel.h = max(lasth, ch);
- + correctsel(cursel);
- + }
- + if(selset()) rtex = *S((sels.last()).x, (sels.last()).y);
- }
- VAR(flrceil,0,0,2);
- @@ -149,7 +181,7 @@
- if(OUTBORD(cx, cy)) return;
- }
- - if(dragging) makesel();
- + if(dragging) { makesel(false); };
- const int GRIDSIZE = 5;
- const float GRIDW = 0.5f;
- @@ -192,10 +224,10 @@
- ch = (int)ih;
- }
- - if(selset)
- + if(selset())
- {
- linestyle(GRIDS, 0xFF, 0x40, 0x40);
- - box(sel, (float)selh, (float)selh, (float)selh, (float)selh);
- + loopv(sels) box(sels[i], (float)sels[i].h, (float)sels[i].h, (float)sels[i].h, (float)sels[i].h);
- }
- glLineWidth(1);
- @@ -214,7 +246,7 @@
- }
- }
- -void makeundo()
- +void makeundo(block &sel)
- {
- undos.add(blockcopy(sel));
- pruneundos(undomegs<<20);
- @@ -229,27 +261,51 @@
- freeblock(p);
- }
- -block *copybuf = NULL;
- +vector<block *> copybuffers;
- +void resetcopybuffers()
- +{
- + loopv(copybuffers) freeblock(copybuffers[i]);
- + copybuffers.shrink(0);
- +}
- +
- void copy()
- {
- EDITSELMP;
- - freeblock(copybuf);
- - copybuf = blockcopy(sel);
- + resetcopybuffers();
- + loopv(sels)
- + {
- + block *b = blockcopy(sels[i]);
- + copybuffers.add(b);
- + }
- +
- }
- void paste()
- {
- - EDITMP;
- - if(!copybuf) { conoutf("nothing to paste"); return; }
- - sel.xs = copybuf->xs;
- - sel.ys = copybuf->ys;
- - correctsel();
- - if(!selset || sel.xs!=copybuf->xs || sel.ys!=copybuf->ys) { conoutf("incorrect selection"); return; }
- - makeundo();
- - copybuf->x = sel.x;
- - copybuf->y = sel.y;
- - blockpaste(*copybuf);
- + EDITSELMP;
- + if(!copybuffers.length()) { conoutf("nothing to paste"); return; }
- +
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + int selx = sel.x;
- + int sely = sel.y;
- +
- + loopvj(copybuffers)
- + {
- + block *copyblock = copybuffers[j];
- + int dx = copyblock->x - copybuffers[0]->x, dy = copyblock->y - copybuffers[0]->y;
- +
- + sel.xs = copyblock->xs;
- + sel.ys = copyblock->ys;
- + sel.x = selx + dx;
- + sel.y = sely + dy;
- + if(!correctsel(sel) || sel.xs!=copyblock->xs || sel.ys!=copyblock->ys) { conoutf("incorrect selection"); return; }
- + makeundo(sel);
- + blockpaste(*copyblock, sel.x, sel.y);
- + }
- + }
- }
- // Count the walls of type "type" contained in the current selection
- @@ -262,7 +318,7 @@
- conoutf("invalid type");
- return 0;
- }
- - loopselxy(if(s->type==type) counter++)
- + loopselsxy(if(s->type==type) counter++)
- return counter;
- }
- @@ -289,10 +345,14 @@
- lastx = cx;
- lasty = cy;
- lasth = ch;
- - selset = false;
- tofronttex();
- +
- + extern vector<keym> keyms;
- + bool ctrlpressed = false;
- + loopv(keyms) if(keyms[i].pressed && (keyms[i].code == SDLK_RCTRL || keyms[i].code == SDLK_LCTRL)) ctrlpressed = true;
- + if(!ctrlpressed) resetselections();
- }
- - makesel();
- + makesel(isdown);
- }
- // the core editing function. all the *xy functions perform the core operations
- @@ -301,7 +361,7 @@
- void editheightxy(bool isfloor, int amount, block &sel)
- {
- - loopselxy(if(isfloor)
- + loopselxy(sel, if(isfloor)
- {
- s->floor += amount;
- if(s->floor>=s->ceil) s->floor = s->ceil-1;
- @@ -317,8 +377,11 @@
- {
- EDITSEL;
- bool isfloor = flr==0;
- - editheightxy(isfloor, amount, sel);
- - addmsg(SV_EDITH, "ri6", sel.x, sel.y, sel.xs, sel.ys, isfloor, amount);
- + loopv(sels)
- + {
- + editheightxy(isfloor, amount, sels[i]);
- + addmsg(SV_EDITH, "ri6", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, isfloor, amount);
- + }
- }
- COMMAND(editheight, ARG_2INT);
- @@ -327,7 +390,7 @@
- void edittexxy(int type, int t, block &sel)
- {
- - loopselxy(switch(type)
- + loopselxy(sel, switch(type)
- {
- case 0: s->ftex = t; break;
- case 1: s->wtex = t; break;
- @@ -346,8 +409,11 @@
- i = i<0 ? 0 : i+dir;
- curedittex[atype] = i = min(max(i, 0), 255);
- int t = lasttex = hdr.texlists[atype][i];
- - edittexxy(type, t, sel);
- - addmsg(SV_EDITT, "ri6", sel.x, sel.y, sel.xs, sel.ys, type, t);
- + loopv(sels)
- + {
- + edittexxy(type, t, sels[i]);
- + addmsg(SV_EDITT, "ri6", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, type, t);
- + }
- }
- void settex(int texture, int type)
- @@ -366,8 +432,11 @@
- conoutf("invalid/unavaible texture");
- return;
- }
- - edittexxy(type, t, sel);
- - addmsg(SV_EDITT, "ri6", sel.x, sel.y, sel.xs, sel.ys, type, t);
- + loopv(sels)
- + {
- + edittexxy(type, t, sels[i]);
- + addmsg(SV_EDITT, "ri6", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, type, t);
- + }
- }
- void replace()
- @@ -390,17 +459,21 @@
- void edittypexy(int type, block &sel)
- {
- - loopselxy(s->type = type);
- + loopselxy(sel, s->type = type);
- }
- void edittype(int type)
- {
- EDITSEL;
- - if(type==CORNER && (sel.xs!=sel.ys || sel.xs==3 || (sel.xs>4 && sel.xs!=8)
- - || sel.x&~-sel.xs || sel.y&~-sel.ys))
- - { conoutf("corner selection must be power of 2 aligned"); return; }
- - edittypexy(type, sel);
- - addmsg(SV_EDITS, "ri5", sel.x, sel.y, sel.xs, sel.ys, type);
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + if(type==CORNER && (sel.xs!=sel.ys || sel.xs==3 || (sel.xs>4 && sel.xs!=8)
- + || sel.x&~-sel.xs || sel.y&~-sel.ys))
- + { conoutf("corner selection must be power of 2 aligned"); return; }
- + edittypexy(type, sel);
- + addmsg(SV_EDITS, "ri5", sel.x, sel.y, sel.xs, sel.ys, type);
- + }
- }
- void heightfield(int t) { edittype(t==0 ? FHF : CHF); }
- @@ -414,12 +487,12 @@
- void editequalisexy(bool isfloor, block &sel)
- {
- int low = 127, hi = -128;
- - loopselxy(
- + loopselxy(sel,
- {
- if(s->floor<low) low = s->floor;
- if(s->ceil>hi) hi = s->ceil;
- });
- - loopselxy(
- + loopselxy(sel,
- {
- if(isfloor) s->floor = low; else s->ceil = hi;
- if(s->floor>=s->ceil) s->floor = s->ceil-1;
- @@ -430,23 +503,30 @@
- {
- bool isfloor = flr==0;
- EDITSEL;
- - editequalisexy(isfloor, sel);
- - addmsg(SV_EDITE, "ri5", sel.x, sel.y, sel.xs, sel.ys, isfloor);
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + editequalisexy(isfloor, sel);
- + addmsg(SV_EDITE, "ri5", sel.x, sel.y, sel.xs, sel.ys, isfloor);
- + }
- }
- COMMAND(equalize, ARG_1INT);
- void setvdeltaxy(int delta, block &sel)
- {
- - loopselxy(s->vdelta = max(s->vdelta+delta, 0));
- + loopselxy(sel, s->vdelta = max(s->vdelta+delta, 0));
- remipmore(sel);
- }
- void setvdelta(int delta)
- {
- EDITSEL;
- - setvdeltaxy(delta, sel);
- - addmsg(SV_EDITD, "ri5", sel.x, sel.y, sel.xs, sel.ys, delta);
- + loopv(sels)
- + {
- + setvdeltaxy(delta, sels[i]);
- + addmsg(SV_EDITD, "ri5", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, delta);
- + }
- }
- const int MAXARCHVERT = 50;
- @@ -467,43 +547,55 @@
- void arch(int sidedelta, int _a)
- {
- EDITSELMP;
- - sel.xs++;
- - sel.ys++;
- - if(sel.xs>MAXARCHVERT) sel.xs = MAXARCHVERT;
- - if(sel.ys>MAXARCHVERT) sel.ys = MAXARCHVERT;
- - loopselxy(s->vdelta =
- - sel.xs>sel.ys
- - ? (archverts[sel.xs-1][x] + (y==0 || y==sel.ys-1 ? sidedelta : 0))
- - : (archverts[sel.ys-1][y] + (x==0 || x==sel.xs-1 ? sidedelta : 0)));
- - remipmore(sel);
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + sel.xs++;
- + sel.ys++;
- + if(sel.xs>MAXARCHVERT) sel.xs = MAXARCHVERT;
- + if(sel.ys>MAXARCHVERT) sel.ys = MAXARCHVERT;
- + loopselxy(sel, s->vdelta =
- + sel.xs>sel.ys
- + ? (archverts[sel.xs-1][x] + (y==0 || y==sel.ys-1 ? sidedelta : 0))
- + : (archverts[sel.ys-1][y] + (x==0 || x==sel.xs-1 ? sidedelta : 0)));
- + remipmore(sel);
- + }
- }
- void slope(int xd, int yd)
- {
- EDITSELMP;
- - int off = 0;
- - if(xd<0) off -= xd*sel.xs;
- - if(yd<0) off -= yd*sel.ys;
- - sel.xs++;
- - sel.ys++;
- - loopselxy(s->vdelta = xd*x+yd*y+off);
- - remipmore(sel);
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + int off = 0;
- + if(xd<0) off -= xd*sel.xs;
- + if(yd<0) off -= yd*sel.ys;
- + sel.xs++;
- + sel.ys++;
- + loopselxy(sel, s->vdelta = xd*x+yd*y+off);
- + remipmore(sel);
- + }
- }
- void perlin(int scale, int seed, int psize)
- {
- EDITSELMP;
- - sel.xs++;
- - sel.ys++;
- - makeundo();
- - sel.xs--;
- - sel.ys--;
- - perlinarea(sel, scale, seed, psize);
- - sel.xs++;
- - sel.ys++;
- - remipmore(sel);
- - sel.xs--;
- - sel.ys--;
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + sel.xs++;
- + sel.ys++;
- + makeundo(sel);
- + sel.xs--;
- + sel.ys--;
- + perlinarea(sel, scale, seed, psize);
- + sel.xs++;
- + sel.ys++;
- + remipmore(sel);
- + sel.xs--;
- + sel.ys--;
- + }
- }
- VARF(fullbright, 0, 0, 1,
- @@ -518,13 +610,13 @@
- void edittag(int tag)
- {
- EDITSELMP;
- - loopselxy(s->tag = tag);
- + loopselsxy(s->tag = tag);
- }
- void newent(char *what, char *a1, char *a2, char *a3, char *a4)
- {
- EDITSEL;
- - newentity(-1, sel.x, sel.y, (int)camera1->o.z, what, ATOI(a1), ATOI(a2), ATOI(a3), ATOI(a4));
- + loopv(sels) newentity(-1, sels[i].x, sels[i].y, (int)camera1->o.z, what, ATOI(a1), ATOI(a2), ATOI(a3), ATOI(a4));
- }
- void movemap(int xo, int yo, int zo) // move whole map
- @@ -566,9 +658,9 @@
- resetmap(false);
- }
- -void selfliprotate(int dir)
- +void selfliprotate(block &sel, int dir)
- {
- - makeundo();
- + makeundo(sel);
- block *org = blockcopy(sel);
- const sqr *q = (const sqr *)(org + 1);
- int x1 = sel.x, x2 = sel.x + sel.xs - 1, y1 = sel.y, y2 = sel.y + sel.ys - 1, x, y;
- @@ -600,19 +692,21 @@
- dir %= 4;
- if(dir < 0) dir += 4;
- if(!dir) return;
- - if(sel.xs != sel.ys) dir = 2;
- - selfliprotate(dir);
- + loopv(sels)
- + {
- + block &sel = sels[i];
- + if(sel.xs != sel.ys) dir = 2;
- + selfliprotate(sel, dir);
- + }
- }
- void selectionflip(char *axis)
- {
- EDITSELMP;
- if(!axis || !*axis) return;
- - switch(toupper(*axis))
- - {
- - case 'X': selfliprotate(11); break;
- - case 'Y': selfliprotate(12); break;
- - }
- + char c = toupper(*axis);
- + if(c != 'X' && c != 'Y') return;
- + loopv(sels) selfliprotate(sels[i], c == 'X' ? 11 : 12);
- }
- COMMANDN(select, selectpos, ARG_4INT);
- Index: source/src/protos.h
- ===================================================================
- --- source/src/protos.h (revision 6646)
- +++ source/src/protos.h (working copy)
- @@ -472,6 +472,7 @@
- extern void cleardynlights();
- extern void removedynlights(physent *owner);
- extern block *blockcopy(const block &b);
- +extern void blockpaste(const block &b, int bx, int by);
- extern void blockpaste(const block &b);
- extern void freeblock(block *&b);
- @@ -554,6 +555,7 @@
- extern void toggleedit(bool force = false);
- extern char *editinfo();
- extern void editdrag(bool isdown);
- +extern void checkselections();
- extern void setvdeltaxy(int delta, block &sel);
- extern void editequalisexy(bool isfloor, block &sel);
- extern void edittypexy(int type, block &sel);
- Index: source/src/world.cpp
- ===================================================================
- --- source/src/world.cpp (revision 6646)
- +++ source/src/world.cpp (working copy)
- @@ -442,6 +442,8 @@
- sqrdefault(S(x,y));
- }
- + checkselections(); // assert no selection became invalid
- +
- strncpy(hdr.head, "ACMP", 4);
- hdr.version = MAPVERSION;
- hdr.headersize = sizeof(header);
- @@ -471,7 +473,7 @@
- loopi(sizeof(hdr.reserved)/sizeof(hdr.reserved[0])) hdr.reserved[i] = 0;
- loopk(3) loopi(256) hdr.texlists[k][i] = i;
- ents.shrink(0);
- - block b = { 8, 8, ssize-16, ssize-16 };
- + block b = { 8, 8, ssize-16, ssize - 16};
- edittypexy(SPACE, b);
- }
- Index: source/src/world.h
- ===================================================================
- --- source/src/world.h (revision 6646)
- +++ source/src/world.h (working copy)
- @@ -130,7 +130,7 @@
- #define MAXHHITS 6000
- #define MINFF 2500
- -struct block { int x, y, xs, ys; };
- +struct block { int x, y, xs, ys, h; };
- // vertex array format
- Index: source/src/worldlight.cpp
- ===================================================================
- --- source/src/worldlight.cpp (revision 6646)
- +++ source/src/worldlight.cpp (working copy)
- @@ -337,13 +337,18 @@
- return b;
- }
- -void blockpaste(const block &b)
- +void blockpaste(const block &b, int bx, int by)
- {
- const sqr *q = (const sqr *)((&b)+1);
- - for(int y = b.y; y<b.ys+b.y; y++) for(int x = b.x; x<b.xs+b.x; x++) *S(x,y) = *q++;
- + for(int y = by; y<b.ys+by; y++) for(int x = bx; x<b.xs+bx; x++) *S(x,y) = *q++;
- remipmore(b);
- }
- +void blockpaste(const block &b)
- +{
- + blockpaste(b, b.x, b.y);
- +}
- +
- void freeblock(block *&b)
- {
- if(b) { delete[] (uchar *)b; b = NULL; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement