Skip to content

Commit

Permalink
Merge pull request #11 from Tokeiburu/tile-feature
Browse files Browse the repository at this point in the history
Added a feature from version 586 and improved "lag" issues.
  • Loading branch information
Borf authored Dec 8, 2023
2 parents f08e433 + ab39e0d commit 1edf5ec
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 92 deletions.
3 changes: 3 additions & 0 deletions browedit/HotkeyActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ void BrowEdit::registerActions()
HotkeyRegistry::registerAction(HotkeyAction::GatEdit_Tile7, [this]() { windowData.gatEdit.gatIndex = 7; heightDoodle = false; windowData.gatEdit.doodle = true; }, hasActiveMapViewGatMode);
HotkeyRegistry::registerAction(HotkeyAction::GatEdit_Tile8, [this]() { windowData.gatEdit.gatIndex = 8; heightDoodle = false; windowData.gatEdit.doodle = true; }, hasActiveMapViewGatMode);
HotkeyRegistry::registerAction(HotkeyAction::GatEdit_Tile9, [this]() { windowData.gatEdit.gatIndex = 9; heightDoodle = false; windowData.gatEdit.doodle = true; }, hasActiveMapViewGatMode);
HotkeyRegistry::registerAction(HotkeyAction::GatEdit_AdjustToGround, [this]() {
activeMapView->gatEdit_adjustToGround(this);
}, hasActiveMapViewGatMode);

HotkeyRegistry::registerAction(HotkeyAction::ColorEdit_Dropper, [this]() { dropperEnabled = !dropperEnabled; cursor = dropperEnabled ? dropperCursor : nullptr; }, hasActiveMapViewGatMode);

Expand Down
1 change: 1 addition & 0 deletions browedit/HotkeyRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ enum class HotkeyAction
GatEdit_Tile7,
GatEdit_Tile8,
GatEdit_Tile9,
GatEdit_AdjustToGround,

ColorEdit_Dropper,

Expand Down
12 changes: 6 additions & 6 deletions browedit/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,9 @@ void Map::wallAddSelected(BrowEdit* browEdit)
t->v4 = calculation.g_uv4;

if (w.z == 1 && cube->tileSide == -1)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, cube->tileFront, id));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, cube->tileFront, id));
if (w.z == 2 && cube->tileFront == -1)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, id, cube->tileSide));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, id, cube->tileSide));
ga->addAction(new TileNewAction(t));
id++;
}
Expand Down Expand Up @@ -1062,9 +1062,9 @@ void Map::wallReApplySelected(BrowEdit* browEdit)
t->v4 = calculation.g_uv4;

if (w.z == 1)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, cube->tileFront, id));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, cube->tileFront, id));
if (w.z == 2)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, id, cube->tileSide));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, id, cube->tileSide));
ga->addAction(new TileNewAction(t));
id++;
}
Expand All @@ -1083,9 +1083,9 @@ void Map::wallRemoveSelected(BrowEdit* browEdit)
{
auto cube = gnd->cubes[w.x][w.y];
if (w.z == 1 && cube->tileSide != -1)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, cube->tileFront, -1));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, cube->tileFront, -1));
if (w.z == 2 && cube->tileFront != -1)
ga->addAction(new CubeTileChangeAction(cube, cube->tileUp, -1, cube->tileSide));
ga->addAction(new CubeTileChangeAction(w, cube, cube->tileUp, -1, cube->tileSide));

}
doAction(ga, browEdit);
Expand Down
88 changes: 81 additions & 7 deletions browedit/MapView.Gatmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
if (browEdit->heightDoodle && hovered)
{
static std::map<Gat::Cube*, float[4]> originalHeights;
static std::vector<glm::ivec2> tilesProcessed;

glm::vec2 tileHoveredOffset((mouse3D.x / 5) - tileHovered.x, tileHovered.y - (gat->height - mouse3D.z / 5) - 1);
int index = 0;
if (tileHoveredOffset.x < 0.5 && tileHoveredOffset.y > 0.5)
Expand Down Expand Up @@ -198,9 +200,11 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
float& snapHeight = gat->cubes[tt.x][tt.y]->heights[ti];
if (ImGui::IsMouseDown(ImGuiMouseButton_Left))
{
if (originalHeights.find(gat->cubes[tt.x][tt.y]) == originalHeights.end())
if (originalHeights.find(gat->cubes[tt.x][tt.y]) == originalHeights.end()) {
for (int i = 0; i < 4; i++)
originalHeights[gat->cubes[tt.x][tt.y]][i] = gat->cubes[tt.x][tt.y]->heights[i];
tilesProcessed.push_back(tt);
}

if (ImGui::GetIO().KeyShift)
snapHeight = glm::min(minMax, snapHeight + browEdit->windowData.gatEdit.doodleSpeed * (glm::mix(1.0f, glm::max(0.0f, 1.0f - glm::length(glm::vec2(x - browEdit->windowData.gatEdit.doodleSize / 2.0f, y - browEdit->windowData.gatEdit.doodleSize / 2.0f)) / browEdit->windowData.gatEdit.doodleSize), browEdit->windowData.gatEdit.doodleHardness)));
Expand Down Expand Up @@ -230,15 +234,17 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
for (int i = 0; i < 4; i++)
newHeights[kv.first][i] = kv.first->heights[i];

map->doAction(new CubeHeightChangeAction<Gat, Gat::Cube>(originalHeights, newHeights), browEdit);
map->doAction(new CubeHeightChangeAction<Gat, Gat::Cube>(originalHeights, newHeights, tilesProcessed), browEdit);
}
originalHeights.clear();
tilesProcessed.clear();
}

}
else if (browEdit->windowData.gatEdit.doodle && hovered)
{
static GroupAction* gatGroupAction = nullptr;
static std::vector<int> gatProcessed;
std::vector<VertexP3T2N3> verts;
float dist = 0.002f * cameraDistance;

Expand All @@ -261,13 +267,14 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
verts.push_back(VertexP3T2N3(glm::vec3(5 * tile.x, -cube->h3 + dist, 5 * gat->height - 5 * tile.y + 5), glm::vec2(t1.x, t1.y), cube->normal));
verts.push_back(VertexP3T2N3(glm::vec3(5 * tile.x + 5, -cube->h2 + dist, 5 * gat->height - 5 * tile.y + 10), glm::vec2(t2.x, t2.y), cube->normal));

if (ImGui::IsMouseDown(ImGuiMouseButton_Left))
if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && std::find(gatProcessed.begin(), gatProcessed.end(), tile.x + tile.y * gat->width) == gatProcessed.end())
{
auto action = new GatTileChangeAction(gat->cubes[tile.x][tile.y], browEdit->windowData.gatEdit.gatIndex);
auto action = new GatTileChangeAction(tile, gat->cubes[tile.x][tile.y], browEdit->windowData.gatEdit.gatIndex);
action->perform(map, browEdit);
if (gatGroupAction == nullptr)
gatGroupAction = new GroupAction();
gatGroupAction->addAction(action);
gatProcessed.push_back(tile.x + tile.y * gat->width);
}
}
}
Expand All @@ -277,10 +284,9 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
{
map->doAction(gatGroupAction, browEdit);
gatGroupAction = nullptr;
gatProcessed.clear();
}



if(verts.size() > 0)
{
glEnableVertexAttribArray(0);
Expand Down Expand Up @@ -424,7 +430,7 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)
for (auto& t : originalValues)
for (int ii = 0; ii < 4; ii++)
newValues[t.first][ii] = t.first->heights[ii];
map->doAction(new CubeHeightChangeAction<Gat, Gat::Cube>(originalValues, newValues), browEdit);
map->doAction(new CubeHeightChangeAction<Gat, Gat::Cube>(originalValues, newValues, map->gatSelection), browEdit);
}
else if (gadgetHeight[i].axisDragged)
{
Expand Down Expand Up @@ -906,4 +912,72 @@ void MapView::postRenderGatMode(BrowEdit* browEdit)


fbo->unbind();
}

void MapView::gatEdit_adjustToGround(BrowEdit* browEdit)
{
std::map<Gat::Cube*, float[4]> originalValues;
std::map<Gat::Cube*, float[4]> newValues;
auto gnd = map->rootNode->getComponent<Gnd>();
auto gat = map->rootNode->getComponent<Gat>();
std::vector<glm::ivec2> selection;

if (browEdit->windowData.gatEdit.doodle || browEdit->heightDoodle) {
auto mouse3D = gat->rayCast(mouseRay);
glm::ivec2 tileHovered((int)glm::floor(mouse3D.x / 5), gat->height - (int)glm::floor(mouse3D.z / 5) + 1);

for (int x = 0; x <= browEdit->windowData.gatEdit.doodleSize; x++)
{
for (int y = 0; y <= browEdit->windowData.gatEdit.doodleSize; y++)
{
glm::ivec2 t = tileHovered + glm::ivec2(x, y) - glm::ivec2(browEdit->windowData.gatEdit.doodleSize / 2, browEdit->windowData.gatEdit.doodleSize / 2);

if (gat->inMap(t))
{
selection.push_back(t);
}
}
}
}
else if (map->gatSelection.size() > 0) {
selection = map->gatSelection;
}

if (selection.size() > 0) {
for (auto& t : selection) {
for (int ii = 0; ii < 4; ii++) {
originalValues[gat->cubes[t.x][t.y]][ii] = gat->cubes[t.x][t.y]->heights[ii];
}

auto& c = gnd->cubes[t.x / 2][t.y / 2];
float avg = (c->heights[0] + c->heights[1] + c->heights[2] + c->heights[3]) / 4;

if (t.x % 2 == 0 && t.y % 2 == 0) {
newValues[gat->cubes[t.x][t.y]][0] = c->heights[0];
newValues[gat->cubes[t.x][t.y]][1] = (c->heights[0] + c->heights[1]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][2] = (c->heights[0] + c->heights[2]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][3] = avg;
}
else if (t.x % 2 == 1 && t.y % 2 == 0) {
newValues[gat->cubes[t.x][t.y]][0] = (c->heights[0] + c->heights[1]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][1] = c->heights[1];
newValues[gat->cubes[t.x][t.y]][2] = avg;
newValues[gat->cubes[t.x][t.y]][3] = (c->heights[1] + c->heights[3]) / 2.0f;
}
else if (t.x % 2 == 0 && t.y % 2 == 1) {
newValues[gat->cubes[t.x][t.y]][0] = (c->heights[0] + c->heights[2]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][1] = avg;
newValues[gat->cubes[t.x][t.y]][2] = c->heights[2];
newValues[gat->cubes[t.x][t.y]][3] = (c->heights[2] + c->heights[3]) / 2.0f;
}
else {
newValues[gat->cubes[t.x][t.y]][0] = avg;
newValues[gat->cubes[t.x][t.y]][1] = (c->heights[1] + c->heights[3]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][2] = (c->heights[2] + c->heights[3]) / 2.0f;
newValues[gat->cubes[t.x][t.y]][3] = c->heights[3];
}
}

map->doAction(new CubeHeightChangeAction<Gat, Gat::Cube>(originalValues, newValues, selection), browEdit);
}
}
45 changes: 30 additions & 15 deletions browedit/MapView.Heightmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
}
ga->addAction(new GatTileSelectAction(map, cubeSelected));
auto action1 = new CubeHeightChangeAction<Gat, Gat::Cube>(gat, cubeSelected);

for (auto c : browEdit->pasteData["gats"])
{
glm::ivec2 pos = glm::ivec2(c["pos"]) + 2 * tileHovered;
if (gat->inMap(pos))
from_json(c, *gat->cubes[pos.x][pos.y]);
}


action1->setNewHeights(gat, cubeSelected);
ga->addAction(action1);
}
map->doAction(ga, browEdit);

Expand All @@ -259,6 +261,7 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
if (browEdit->heightDoodle && hovered)
{
static std::map<Gnd::Cube*, float[4]> originalHeights;
static std::vector<glm::ivec2> tilesProcessed;

glm::vec2 tileHoveredOffset((mouse3D.x / 10) - tileHovered.x, tileHovered.y - (gnd->height - mouse3D.z / 10));
int index = 0;
Expand Down Expand Up @@ -314,9 +317,11 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
float& snapHeight = gnd->cubes[tt.x][tt.y]->heights[ti];
if (ImGui::IsMouseDown(ImGuiMouseButton_Left))
{
if (originalHeights.find(gnd->cubes[tt.x][tt.y]) == originalHeights.end())
if (originalHeights.find(gnd->cubes[tt.x][tt.y]) == originalHeights.end()) {
for (int i = 0; i < 4; i++)
originalHeights[gnd->cubes[tt.x][tt.y]][i] = gnd->cubes[tt.x][tt.y]->heights[i];
tilesProcessed.push_back(tt);
}

if (ImGui::GetIO().KeyShift)
snapHeight = glm::min(minMax, snapHeight + browEdit->windowData.heightEdit.doodleSpeed * (glm::mix(1.0f, glm::max(0.0f, 1.0f - glm::length(glm::vec2(x - browEdit->windowData.heightEdit.doodleSize / 2.0f, y - browEdit->windowData.heightEdit.doodleSize / 2.0f))/ browEdit->windowData.heightEdit.doodleSize), browEdit->windowData.heightEdit.doodleHardness)));
Expand Down Expand Up @@ -345,9 +350,10 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
for (int i = 0; i < 4; i++)
newHeights[kv.first][i] = kv.first->heights[i];

map->doAction(new CubeHeightChangeAction<Gnd, Gnd::Cube>(originalHeights, newHeights), browEdit);
map->doAction(new CubeHeightChangeAction<Gnd, Gnd::Cube>(originalHeights, newHeights, tilesProcessed), browEdit);
}
originalHeights.clear();
tilesProcessed.clear();
}

}
Expand Down Expand Up @@ -401,15 +407,16 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
static glm::vec3 originalCorners[4];

glm::vec3 pos[9];
pos[0] = gnd->getPos(minValues.x, minValues.y, 0);
pos[1] = gnd->getPos(maxValues.x, minValues.y, 1);
pos[2] = gnd->getPos(minValues.x, maxValues.y, 2);
pos[3] = gnd->getPos(maxValues.x, maxValues.y, 3);
pos[4] = (pos[0] + pos[1] + pos[2] + pos[3]) / 4.0f;
pos[5] = (pos[0] + pos[1]) / 2.0f;
pos[6] = (pos[2] + pos[3]) / 2.0f;
pos[7] = (pos[0] + pos[2]) / 2.0f;
pos[8] = (pos[1] + pos[3]) / 2.0f;
glm::vec3 posGadget[9];
posGadget[0] = pos[0] = gnd->getPos(minValues.x, minValues.y, 0);
posGadget[1] = pos[1] = gnd->getPos(maxValues.x, minValues.y, 1);
posGadget[2] = pos[2] = gnd->getPos(minValues.x, maxValues.y, 2);
posGadget[3] = pos[3] = gnd->getPos(maxValues.x, maxValues.y, 3);
posGadget[4] = pos[4] = (pos[0] + pos[1] + pos[2] + pos[3]) / 4.0f;
posGadget[5] = pos[5] = (pos[0] + pos[1]) / 2.0f;
posGadget[6] = pos[6] = (pos[2] + pos[3]) / 2.0f;
posGadget[7] = pos[7] = (pos[0] + pos[2]) / 2.0f;
posGadget[8] = pos[8] = (pos[1] + pos[3]) / 2.0f;

ImGui::Begin("Height Edit");
if (ImGui::CollapsingHeader("Selection Details", ImGuiTreeNodeFlags_DefaultOpen))
Expand Down Expand Up @@ -441,7 +448,7 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
continue;
if (!browEdit->windowData.heightEdit.showEdgeArrows && i > 4)
continue;
glm::mat4 mat = glm::translate(glm::mat4(1.0f), pos[i]);
glm::mat4 mat = glm::translate(glm::mat4(1.0f), posGadget[i]);
if (maxValues.x - minValues.x <= 1 || maxValues.y - minValues.y <= 1)
mat = glm::scale(mat, glm::vec3(0.25f, 0.25f, 0.25f));

Expand Down Expand Up @@ -483,7 +490,7 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)
for (auto& t : originalValues)
for (int ii = 0; ii < 4; ii++)
newValues[t.first][ii] = t.first->heights[ii];
map->doAction(new CubeHeightChangeAction<Gnd, Gnd::Cube>(originalValues, newValues), browEdit);
map->doAction(new CubeHeightChangeAction<Gnd, Gnd::Cube>(originalValues, newValues, map->tileSelection), browEdit);
}
else if (gadgetHeight[i].axisDragged)
{
Expand Down Expand Up @@ -577,8 +584,16 @@ void MapView::postRenderHeightMode(BrowEdit* browEdit)

for (auto& t : map->tileSelection)
{
if (gndRenderer)
if (gndRenderer) {
gndRenderer->setChunkDirty(t.x, t.y);

// For walls on the chunk's edge
if (gnd->inMap(glm::ivec2(t.x, t.y - 1)))
gndRenderer->setChunkDirty(t.x, t.y - 1);

if (gnd->inMap(glm::ivec2(t.x - 1, t.y)))
gndRenderer->setChunkDirty(t.x - 1, t.y);
}
for (int ii = 0; ii < 4; ii++)
{
// 0 1
Expand Down
8 changes: 4 additions & 4 deletions browedit/MapView.Texturemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void MapView::postRenderTextureMode(BrowEdit* browEdit)
t->color = gnd->tiles[cube->tileUp]->color;

ga->addAction(new TileNewAction(t));
ga->addAction(new CubeTileChangeAction(cube, id, cube->tileFront, cube->tileSide));
ga->addAction(new CubeTileChangeAction(glm::ivec2(topleft.x + x, topleft.y + y), cube, id, cube->tileFront, cube->tileSide));
cube->tileUp = id;
id++;
}
Expand Down Expand Up @@ -421,7 +421,7 @@ void MapView::postRenderTextureMode(BrowEdit* browEdit)
t->textureIndex = textureStampLookup[t->textureIndex];
}
ga->addAction(new TileNewAction(t));
ga->addAction(new CubeTileChangeAction(cube, id, cube->tileFront, cube->tileSide));
ga->addAction(new CubeTileChangeAction(glm::ivec2(x, y), cube, id, cube->tileFront, cube->tileSide));
cube->tileUp = id;
id++;
}
Expand Down Expand Up @@ -549,7 +549,7 @@ void MapView::postRenderTextureMode(BrowEdit* browEdit)
gndRenderer->setChunkDirty(tile.x, tile.y);

ga->addAction(new TileNewAction(t));
ga->addAction(new CubeTileChangeAction(cube, id, cube->tileFront, cube->tileSide));
ga->addAction(new CubeTileChangeAction(tile, cube, id, cube->tileFront, cube->tileSide));
id++;
}
map->doAction(ga, browEdit);
Expand Down Expand Up @@ -979,7 +979,7 @@ void MapView::postRenderTextureMode(BrowEdit* browEdit)
gndRenderer->setChunkDirty(tile.x, tile.y);

ga->addAction(new TileNewAction(t));
ga->addAction(new CubeTileChangeAction(cube, id, cube->tileFront, cube->tileSide));
ga->addAction(new CubeTileChangeAction(tile, cube, id, cube->tileFront, cube->tileSide));
id++;
}
map->doAction(ga, browEdit);
Expand Down
2 changes: 2 additions & 0 deletions browedit/MapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class MapView
void postRenderWallMode(BrowEdit* browEdit);
void postRenderColorMode(BrowEdit* browEdit);
void postRenderCinematicMode(BrowEdit* browEdit);

void gatEdit_adjustToGround(BrowEdit* browEdit);

bool drawCameraWidget();

Expand Down
Loading

0 comments on commit 1edf5ec

Please sign in to comment.