Skip to content

Instantly share code, notes, and snippets.

@SalatielSauer

SalatielSauer/octaedit.cpp

Last active Jun 28, 2019
Embed
What would you like to do?
src/engine/octaedit.cpp
VARP(editinview, 0, 1, 1);
bool noedit(bool view, bool msg)
{
if(!editmode) { if(msg) conoutf(CON_ERROR, "operation only allowed in edit mode"); return true; }
if(view || haveselent()) return false;
float r = 1.0f;
vec o = sel.o.tovec(), s = sel.s.tovec();
s.mul(float(sel.grid) / 2.0f);
o.add(s);
r = float(max(s.x, max(s.y, s.z)));
bool viewable = (isvisiblesphere(r, o) != VFC_NOT_VISIBLE);
//if(!viewable && msg) conoutf(CON_ERROR, "selection not in view");
//return !viewable;
if(!viewable && editinview && msg) {conoutf(CON_ERROR, "selection not in view");}
if (editinview){return !viewable;} else {return false;}
}
ICOMMAND(getselpos, "", (),
{
defformatstring(pos)("%s %s %s", floatstr(sel.o.x), floatstr(sel.o.y), floatstr(sel.o.z));
result(pos);
});
void setselpos(int* posx, int* posy, int* posz)
{
if(noedit(moving!=0)) return;
if(!havesel){havesel = true;};
sel.o.x = *posx - *posx % gridsize;
sel.o.y = *posy - *posy % gridsize;
sel.o.z = *posz - *posz % gridsize;
}
COMMAND(setselpos, "iii");
void movesel(int *dir, int *pface)
{
if(noedit(moving!=0)) return;
if((*pface > 2) || (*pface < 0)) return;
int s = *dir;
sel.o[*pface] += s*sel.grid;
}
COMMAND(movesel, "ii");
@SalatielSauer

This comment has been minimized.

Copy link
Owner Author

@SalatielSauer SalatielSauer commented Jun 27, 2019

Simple commands to expand map editing possibilities in Sauerbraten, by Salatiel.

The main goal is to allow geometry editing almost instantly using CubeScript.
The description below is based on the line numbers of the above document, it does not represent the line numbers in the original octaedit.cpp.

Line 1:

  • Defining the editinview variable, if 0 the player can edit even if the selection is off the screen, if 1 edit is blocked if the selection is off screen, default is 1.

Line 12/13:

  • The original commands are commented.

Line 14/15:

  • The new commands that use the value of the editinview variable to allow or deny off-screen editing.

Line 18/22:

  • getselpos command is based on the getcampos command, and returns the position of the current edit selection.

Line 24/32

  • setselpos command sets the position of the edit selection based on 3 int values ​​(x, y, z), if a current selection does not exist, it will be created.
    There is special attention to always place the selection in the closest coordinate that is multiple of gridsize (I actually do not know if that's the correct term, but it works the way I expected it to), avoiding an impossible selection in the "middle" between two possible selections, this is also the reason for using int instead of float...

Line 34/41:

  • movesel Moves the edit selection toward a direction.
    First argument is the number of cubes to move (-1, 1).
    Second argument is the direction (0 = x, 1 = y, 2 = z).
    Example:
    /movesel 1 2 will move the selection 1 cube up.

Where to install it

These commands goes somewhere after line 90 in the original file (src/engine/octaedit.cpp, before VARF(gridpower, 0, 3, 12... ).
Be careful to not multiply the bool noedit function, it already exists (line 149), it is only necessary to comment and add the lines mentioned above (12/13 and 14/15).

if anyone knows an easier way to do some of these functions, feel free to leave your feedback :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.