Last active
June 28, 2019 12:17
-
-
Save SalatielSauer/d0c3f7676d7962c8451eb701fc1220f3 to your computer and use it in GitHub Desktop.
src/engine/octaedit.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Line 12/13:
Line 14/15:
Line 18/22:
Line 24/32
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:
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 :-)