Skip to content

Commit

Permalink
add draw brush tool, improve exception handling, fix the usual bugs
Browse files Browse the repository at this point in the history
- added: draw brush tool
	- toggle with B (which is no longer the 'cylinder primitive' prompt) or with the new toolbar button
	- click in sequence in the grid view to place corners of a shape, or drag its existing points around
	- backspace to erase last point, enter to commit, doubleclick to place one last point and commit immediately
	- creates a prism of that shape with the same Z dimensions and texture as the workzone
	- a concave shape is legal: qe3 will try very hard to split it into concave brushes in a wise and qbsp-friendly way
	- useful for wiggly rock walls, or making arches without all the clipping
- fixed: constellation of crashes related to the workzone texdef defaulting to null at startup and not the nulltexture (pink checker)
- fixed: clip tool being unable to reposition points placed on a smaller grid than the current grid setting
- fixed: camera indicator in grid view disappearing in clipping mode
- fixed: a number of commands not selecting their results properly after undo/redo, thanks to stupid confusion over what my own virtual functions are named
- fixed: nonworking 'print XY' button was still on the toolbar
- internal: built out the exception handling a little
  • Loading branch information
itslunaranyo committed May 20, 2021
1 parent 6ee93e2 commit daf0631
Show file tree
Hide file tree
Showing 54 changed files with 2,060 additions and 311 deletions.
6 changes: 3 additions & 3 deletions ClipTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ ClipTool::clippoint_t* ClipTool::XYGetNearestClipPoint(XYZView* xyz, int x, int

tdp[0] = tdp[1] = tdp[2] = 256;

xyz->SnapToPoint(x, y, tdp);
xyz->ToPoint(x, y, tdp);
nDim1 = (xyz->GetAxis() == YZ) ? 1 : 0;
nDim2 = (xyz->GetAxis() == XY) ? 1 : 2;

Expand Down Expand Up @@ -795,7 +795,7 @@ void ClipTool::DrawPoints()
sprintf(strMsg, "%i", i);
glCallLists(strlen(strMsg), GL_UNSIGNED_BYTE, strMsg);
}
glEnable(GL_DEPTH_TEST);
//glEnable(GL_DEPTH_TEST);
}

void ClipTool::DrawClipWire(std::vector<Brush*> *brList)
Expand All @@ -808,7 +808,7 @@ void ClipTool::DrawClipWire(std::vector<Brush*> *brList)
for (auto brIt = brList->begin(); brIt != brList->end(); ++brIt)
for (face = (*brIt)->faces; face; face = face->fnext)
face->DrawWire();
glEnable(GL_DEPTH_TEST);
//glEnable(GL_DEPTH_TEST);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions CmdBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void CmdBridge::UseFace(Face *f)
assert(state == LIVE || state == NOOP);

if (f->owner->owner->IsPoint())
Error("Can't Bridge a point entity");
CmdError("Can't Bridge a point entity");
else if (!f->owner->IsHidden())
fBridged.push_back(f);

Expand All @@ -38,7 +38,7 @@ void CmdBridge::Do_Impl()
{
Brush *newbrush = CSG::DoBridge(fBridged);
if (!newbrush)
Error("Faces could not be Bridged");
CmdError("Faces could not be Bridged");

cmdAR.AddedBrush(newbrush);
cmdAR.Do();
Expand Down
2 changes: 1 addition & 1 deletion CmdBrushClip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void CmdBrushClip::SetSide(clipside s)
void CmdBrushClip::CreateSplitLists()
{
if (!pointsSet)
Error("Tried to 3-point clip without 3 points");
CmdError("Tried to 3-point clip without 3 points");

ClearSplitLists();

Expand Down
7 changes: 4 additions & 3 deletions CmdCompound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool CmdCompound::Complete(Command *cmd)
{
assert(state == NOOP || state == LIVE);
if (stalled)
Error("tried to add %s to stalled compound cmd", cmd->name);
CmdError("tried to add %s to stalled compound cmd", cmd->name);

if (cmd->state == NOOP)
{
Expand All @@ -50,10 +50,11 @@ bool CmdCompound::Complete(Command *cmd)
try {
cmd->Do();
}
catch (...) {
catch (qe3_cmd_exception& ex) {
delete cmd;
Undo_Impl(); // revert all prior commands if one fails
state = NOOP;
ReportError(ex);
return false;
}

Expand Down Expand Up @@ -108,7 +109,7 @@ void CmdCompound::Redo_Impl()
(*cmdIt)->Redo();
}

void CmdCompound::Select_Impl()
void CmdCompound::Sel_Impl()
{
for (auto cmdIt = series.begin(); cmdIt != series.end(); ++cmdIt)
(*cmdIt)->Select();
Expand Down
2 changes: 1 addition & 1 deletion CmdCompound.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CmdCompound : public Command
void Do_Impl();
void Undo_Impl();
void Redo_Impl();
void Select_Impl();
void Sel_Impl();

};

Expand Down
8 changes: 4 additions & 4 deletions CmdCone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ CmdCone::~CmdCone() {}
void CmdCone::SetSides(int s)
{
if (s < 3)
Error("Couldn't create cone: too few sides (minimum: 3)");
CmdError("Couldn't create cone: too few sides (minimum: 3)");

if (s >= MAX_POINTS_ON_WINDING - 4)
Error("Couldn't create cone: too many sides (maximum: %i)", MAX_POINTS_ON_WINDING - 4);
CmdError("Couldn't create cone: too many sides (maximum: %i)", MAX_POINTS_ON_WINDING - 4);

sides = s;
}

void CmdCone::SetAxis(int ax)
{
if (ax < 0 || ax > 2)
Error("Bad axis specified (%i)", ax);
CmdError("Bad axis specified (%i)", ax);

axis = ax;
}

void CmdCone::UseBrush(Brush *br)
{
if (br->owner->IsPoint())
Error("Can't make a cone out of a point entity");
CmdError("Can't make a cone out of a point entity");
target = br;
state = LIVE;
}
Expand Down
2 changes: 1 addition & 1 deletion CmdCreateBrushEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CmdCreateBrushEntity::CmdCreateBrushEntity(const char* classname) : Command("Cre
selectOnUndo = true;
modifiesSelection = true;
if (!strcmp(classname, "worldspawn"))
Error("Cannot create a new worldspawn entity.");
CmdError("Cannot create a new worldspawn entity.");

EntClass *ec = EntClass::ForName(classname, true, false);
ent = new Entity();
Expand Down
2 changes: 1 addition & 1 deletion CmdCreatePointEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CmdCreatePointEntity::CmdCreatePointEntity(const char *classname, const vec3 ori
modifiesSelection = true;

if (!strcmp(classname, "worldspawn"))
Error("Cannot create a new worldspawn entity.");
CmdError("Cannot create a new worldspawn entity.");

CreatePointEntity(classname, origin);

Expand Down
8 changes: 4 additions & 4 deletions CmdCylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ CmdCylinder::~CmdCylinder() {}
void CmdCylinder::SetSides(int s)
{
if (s < 3)
Error("Couldn't create cylinder: too few sides (minimum: 3)");
CmdError("Couldn't create cylinder: too few sides (minimum: 3)");

if (s >= MAX_POINTS_ON_WINDING - 4)
Error("Couldn't create cylinder: too many sides (maximum: %i)", MAX_POINTS_ON_WINDING - 4);
CmdError("Couldn't create cylinder: too many sides (maximum: %i)", MAX_POINTS_ON_WINDING - 4);

sides = s;
}

void CmdCylinder::SetAxis(int ax)
{
if (ax < 0 || ax > 2)
Error("Bad axis specified (%i)", ax);
CmdError("Bad axis specified (%i)", ax);

axis = ax;
}

void CmdCylinder::UseBrush(Brush *br)
{
if (br->owner->IsPoint())
Error("Can't make a cylinder out of a point entity");
CmdError("Can't make a cylinder out of a point entity");
target = br;
state = LIVE;
}
Expand Down
111 changes: 38 additions & 73 deletions CmdCzgCylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@
#include "qe3.h"
#include "CmdCzgCylinder.h"

CmdCzgCylinder::CmdCzgCylinder() : degree(1), target(nullptr), axis(2), Command("Make CZG Cylinder") {}
CmdCzgCylinder::CmdCzgCylinder() : degree(1), target(nullptr), axis(2), Command("Make CZG Cylinder")
{
selectOnDo = true;
selectOnUndo = true;
}

CmdCzgCylinder::~CmdCzgCylinder() {}

void CmdCzgCylinder::SetDegree(int d)
{
if (d < 1)
Error("Couldn't create czg cylinder: invalid degree (minimum: 1)");
CmdError("Couldn't create czg cylinder: invalid degree (minimum: 1)");

if (6 * (1 << d) >= MAX_POINTS_ON_WINDING - 2)
Error("Couldn't create czg cylinder: too many sides (maximum degree: 3)");
CmdError("Couldn't create czg cylinder: too many sides (maximum degree: 3)");

degree = d;
}

void CmdCzgCylinder::SetAxis(int ax)
{
if (ax < 0 || ax > 2)
Error("Bad axis specified (%i)", ax);
CmdError("Bad axis specified (%i)", ax);

axis = ax;
}

void CmdCzgCylinder::UseBrush(Brush *br)
{
if (br->owner->IsPoint())
Error("Can't make a czg cylinder out of a point entity");
CmdError("Can't make a czg cylinder out of a point entity");
target = br;
state = LIVE;
}
Expand Down Expand Up @@ -83,12 +88,10 @@ float *CmdCzgCylinder::PatternForDegree(int d)

void CmdCzgCylinder::Do_Impl()
{
vec3 mins, maxs, mid, size;
vec3 p0, p1, p2;
Face *f;
TexDef td;
int i, j, x, y, z, sides;
vec3 mins, maxs, size;
int i, x, y, z, sides;
float *pattern;
std::vector<vec3> points;

z = axis;
x = (axis + 1) % 3;
Expand All @@ -97,91 +100,53 @@ void CmdCzgCylinder::Do_Impl()
sides = 6 * (1 << degree); // 12, 24, 48
pattern = PatternForDegree(degree);

td = target->faces->texdef;
mins = target->mins;
maxs = target->maxs;
size = maxs - mins;

// find center of brush
mid = (mins + maxs) * 0.5f;

cmdBM.ModifyBrush(target);
target->ClearFaces();

// create top face
f = new Face(target);
f->texdef = td;

p0[x] = maxs[x];
p0[y] = maxs[y];
p0[z] = maxs[z];
p1[x] = maxs[x];
p1[y] = mins[y];
p1[z] = maxs[z];
p2[x] = mins[x];
p2[y] = mins[y];
p2[z] = maxs[z];
f->plane.FromPoints(p0, p1, p2);

// create bottom face
f = new Face(target);
f->texdef = td;

p0[x] = mins[x];
p0[y] = mins[y];
p0[z] = mins[z];
p1[x] = maxs[x];
p1[y] = mins[y];
p1[z] = mins[z];
p2[x] = maxs[x];
p2[y] = maxs[y];
p2[z] = mins[z];
f->plane.FromPoints(p0, p1, p2);

for (i = 0; i < sides; i++)
{
j = (i + (sides / 4)) % sides;
int x1, y1, x2, y2;

x1 = mins[x] + floor(pattern[i] * size[x] + 0.5);
x2 = mins[x] + floor(pattern[(i + 1) % sides] * size[x] + 0.5);
y1 = mins[y] + floor(pattern[j] * size[y] + 0.5);
y2 = mins[y] + floor(pattern[(j + 1) % sides] * size[y] + 0.5);

f = new Face(target);
f->texdef = td;

p0[x] = x1;
p0[y] = y1;
p0[z] = mins[z];
p1[x] = x2;
p1[y] = y2;
p1[z] = mins[z];
p2[x] = x2;
p2[y] = y2;
p2[z] = maxs[z];
f->plane.FromPoints(p0, p1, p2);
vec3 pt;
int j = (i + (sides / 4)) % sides;

pt[x] = mins[x] + floor(pattern[i] * size[x] + 0.5);
pt[y] = mins[y] + floor(pattern[j] * size[y] + 0.5);
pt[z] = 0;

points.push_back(pt);
}

target->Build();
cmdBM.Do(); // does nothing, but make sure cmdBM's state is set to DONE
cmdPB.SetAxis(axis);
cmdPB.SetBounds(mins[axis],maxs[axis]);
cmdPB.SetTexDef(target->faces->texdef);
cmdPB.SetPoints(points);

cmdAR.RemovedBrush(target);

cmdAR.Do();
cmdPB.Do();

delete[] pattern;
}

void CmdCzgCylinder::Undo_Impl()
{
cmdBM.Undo();
cmdPB.Undo();
cmdAR.Undo();
}

void CmdCzgCylinder::Redo_Impl()
{
cmdBM.Redo();
cmdAR.Redo();
cmdPB.Redo();
}

void CmdCzgCylinder::Sel_Impl()
{
Selection::SelectBrush(target);
if (state == DONE)
cmdPB.Select();
else
cmdAR.Select();
}


6 changes: 4 additions & 2 deletions CmdCzgCylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#define __COMMAND_CZG_CYLINDER_H__

#include "Command.h"
#include "CmdBrushMod.h"
#include "CmdAddRemove.h"
#include "CmdPolyBrush.h"

class Brush;

Expand All @@ -20,7 +21,8 @@ class CmdCzgCylinder : public Command
void SetAxis(int ax);
void UseBrush(Brush* br);
private:
CmdBrushMod cmdBM;
CmdAddRemove cmdAR;
CmdPolyBrush cmdPB;
Brush *target;
int degree;
int axis;
Expand Down
2 changes: 1 addition & 1 deletion CmdDelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ void CmdDelete::Delete(Brush *brList)
void CmdDelete::Do_Impl() { cmdAR.Do(); }
void CmdDelete::Undo_Impl() { cmdAR.Undo(); }
void CmdDelete::Redo_Impl() { cmdAR.Redo(); }
void CmdDelete::Select_Impl() { cmdAR.Select(); }
void CmdDelete::Sel_Impl() { cmdAR.Select(); }
2 changes: 1 addition & 1 deletion CmdDelete.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CmdDelete : public Command
void Do_Impl();
void Undo_Impl();
void Redo_Impl();
void Select_Impl();
void Sel_Impl();
};

#endif
Loading

0 comments on commit daf0631

Please sign in to comment.