Skip to content

Commit

Permalink
Add OpenMW 0.47 commits up to 23 Sep 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Sep 23, 2021
2 parents c81f8c9 + f0a77a4 commit a01c874
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 33 deletions.
33 changes: 29 additions & 4 deletions apps/opencs/view/render/commands.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
#include "commands.hpp"

#include <QPointer>

#include <components/debug/debuglog.hpp>
#include <components/esm/loadland.hpp>

#include "editmode.hpp"
#include "terrainselection.hpp"
#include "terrainshapemode.hpp"
#include "terraintexturemode.hpp"
#include "worldspacewidget.hpp"

CSVRender::DrawTerrainSelectionCommand::DrawTerrainSelectionCommand(TerrainSelection& terrainSelection, QUndoCommand* parent)
: mTerrainSelection(terrainSelection)
CSVRender::DrawTerrainSelectionCommand::DrawTerrainSelectionCommand(WorldspaceWidget* worldspaceWidget, QUndoCommand* parent)
: mWorldspaceWidget(worldspaceWidget)
{ }

void CSVRender::DrawTerrainSelectionCommand::redo()
{
mTerrainSelection.update();
tryUpdate();
}

void CSVRender::DrawTerrainSelectionCommand::undo()
{
mTerrainSelection.update();
tryUpdate();
}

void CSVRender::DrawTerrainSelectionCommand::tryUpdate()
{
if (!mWorldspaceWidget)
{
Log(Debug::Verbose) << "Can't update terrain selection, no WorldspaceWidget found!";
return;
}

auto terrainMode = dynamic_cast<CSVRender::TerrainShapeMode*>(mWorldspaceWidget->getEditMode());
if (!terrainMode)
{
Log(Debug::Verbose) << "Can't update terrain selection in current EditMode";
return;
}

terrainMode->getTerrainSelection()->update();
}
11 changes: 9 additions & 2 deletions apps/opencs/view/render/commands.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#ifndef CSV_RENDER_COMMANDS_HPP
#define CSV_RENDER_COMMANDS_HPP

#include <QPointer>

#include <QUndoCommand>

#include "worldspacewidget.hpp"

namespace CSVRender
{
class TerrainSelection;
Expand All @@ -21,14 +25,17 @@ namespace CSVRender
*/
class DrawTerrainSelectionCommand : public QUndoCommand
{

private:
TerrainSelection& mTerrainSelection;
QPointer<WorldspaceWidget> mWorldspaceWidget;

public:
DrawTerrainSelectionCommand(TerrainSelection& terrainSelection, QUndoCommand* parent = nullptr);
DrawTerrainSelectionCommand(WorldspaceWidget* worldspaceWidget, QUndoCommand* parent = nullptr);

void redo() override;
void undo() override;

void tryUpdate();
};
}

Expand Down
13 changes: 9 additions & 4 deletions apps/opencs/view/render/terrainshapemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void CSVRender::TerrainShapeMode::applyTerrainEditChanges()
undoStack.beginMacro ("Edit shape and normal records");

// One command at the beginning of the macro for redrawing the terrain-selection grid when undoing the changes.
undoStack.push(new DrawTerrainSelectionCommand(*mTerrainShapeSelection));
undoStack.push(new DrawTerrainSelectionCommand(&getWorldspaceWidget()));

for(CSMWorld::CellCoordinates cellCoordinates: mAlteredCells)
{
Expand Down Expand Up @@ -358,7 +358,7 @@ void CSVRender::TerrainShapeMode::applyTerrainEditChanges()
pushNormalsEditToCommand(landNormalsNew, document, landTable, cellId);
}
// One command at the end of the macro for redrawing the terrain-selection grid when redoing the changes.
undoStack.push(new DrawTerrainSelectionCommand(*mTerrainShapeSelection));
undoStack.push(new DrawTerrainSelectionCommand(&getWorldspaceWidget()));

undoStack.endMacro();
clearTransientEdits();
Expand Down Expand Up @@ -1049,7 +1049,7 @@ void CSVRender::TerrainShapeMode::handleSelection(int globalSelectionX, int glob
*/
if (xIsAtCellBorder && yIsAtCellBorder)
{
/*
/*
Handle the NW, NE, and SE corner vertices.
NW corner: (+1, -1) offset to reach current cell.
NE corner: (-1, -1) offset to reach current cell.
Expand Down Expand Up @@ -1132,7 +1132,7 @@ void CSVRender::TerrainShapeMode::selectTerrainShapes(const std::pair<int, int>&
selectAction = CSMPrefs::get()["3D Scene Editing"]["primary-select-action"].toString();
else
selectAction = CSMPrefs::get()["3D Scene Editing"]["secondary-select-action"].toString();

if (selectAction == "Select only")
mTerrainShapeSelection->onlySelect(selections);
else if (selectAction == "Add to selection")
Expand Down Expand Up @@ -1444,6 +1444,11 @@ void CSVRender::TerrainShapeMode::mouseMoveEvent (QMouseEvent *event)
mBrushDraw->hide();
}

std::shared_ptr<CSVRender::TerrainSelection> CSVRender::TerrainShapeMode::getTerrainSelection()
{
return mTerrainShapeSelection;
}

void CSVRender::TerrainShapeMode::setBrushSize(int brushSize)
{
mBrushSize = brushSize;
Expand Down
4 changes: 3 additions & 1 deletion apps/opencs/view/render/terrainshapemode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace CSVRender
void dragMoveEvent (QDragMoveEvent *event) override;
void mouseMoveEvent (QMouseEvent *event) override;

std::shared_ptr<TerrainSelection> getTerrainSelection();

private:

/// Remove duplicates and sort mAlteredCells, then limitAlteredHeights forward and reverse
Expand Down Expand Up @@ -176,7 +178,7 @@ namespace CSVRender
int mDragMode = InteractionType_None;
osg::Group* mParentNode;
bool mIsEditing = false;
std::unique_ptr<TerrainSelection> mTerrainShapeSelection;
std::shared_ptr<TerrainSelection> mTerrainShapeSelection;
int mTotalDiffY = 0;
std::vector<CSMWorld::CellCoordinates> mAlteredCells;
osg::Vec3d mEditingPos;
Expand Down
5 changes: 5 additions & 0 deletions apps/opencs/view/render/terraintexturemode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ void CSVRender::TerrainTextureMode::mouseMoveEvent (QMouseEvent *event)
mBrushDraw->hide();
}

std::shared_ptr<CSVRender::TerrainSelection> CSVRender::TerrainTextureMode::getTerrainSelection()
{
return mTerrainTextureSelection;
}


void CSVRender::TerrainTextureMode::setBrushSize(int brushSize)
{
Expand Down
4 changes: 3 additions & 1 deletion apps/opencs/view/render/terraintexturemode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace CSVRender

void mouseMoveEvent (QMouseEvent *event) override;

std::shared_ptr<TerrainSelection> getTerrainSelection();

private:
/// \brief Handle brush mechanics, maths regarding worldspace hit etc.
void editTerrainTextureGrid (const WorldspaceHitResult& hit);
Expand Down Expand Up @@ -115,7 +117,7 @@ namespace CSVRender
int mDragMode;
osg::Group* mParentNode;
bool mIsEditing;
std::unique_ptr<TerrainSelection> mTerrainTextureSelection;
std::shared_ptr<TerrainSelection> mTerrainTextureSelection;

const int cellSize {ESM::Land::REAL_SIZE};
const int landTextureSize {ESM::Land::LAND_TEXTURE_SIZE};
Expand Down
10 changes: 5 additions & 5 deletions apps/opencs/view/render/worldspacewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ CSVRender::WorldspaceHitResult CSVRender::WorldspaceWidget::mousePick (const QPo
return hit;
}

CSVRender::EditMode *CSVRender::WorldspaceWidget::getEditMode()
{
return dynamic_cast<CSVRender::EditMode *> (mEditMode->getCurrent());
}

void CSVRender::WorldspaceWidget::abortDrag()
{
if (mDragging)
Expand Down Expand Up @@ -697,11 +702,6 @@ void CSVRender::WorldspaceWidget::handleInteractionPress (const WorldspaceHitRes
editMode.primaryOpenPressed (hit);
}

CSVRender::EditMode *CSVRender::WorldspaceWidget::getEditMode()
{
return dynamic_cast<CSVRender::EditMode *> (mEditMode->getCurrent());
}

void CSVRender::WorldspaceWidget::primaryOpen(bool activate)
{
handleInteraction(InteractionType_PrimaryOpen, activate);
Expand Down
4 changes: 2 additions & 2 deletions apps/opencs/view/render/worldspacewidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ namespace CSVRender
/// Erase all overrides and restore the visual representation to its true state.
virtual void reset (unsigned int elementMask) = 0;

EditMode *getEditMode();

protected:

/// Visual elements in a scene
Expand All @@ -215,8 +217,6 @@ namespace CSVRender

void settingChanged (const CSMPrefs::Setting *setting) override;

EditMode *getEditMode();

bool getSpeedMode();

private:
Expand Down
19 changes: 10 additions & 9 deletions apps/openmw/mwmechanics/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,7 @@ namespace MWMechanics
// Standing NPCs give way to moving ones if they are not in combat (or pursue) mode and either
// follow player or have a AIWander package with non-empty wander area.
bool shouldAvoidCollision = isMoving;
bool shouldGiveWay = false;
bool shouldTurnToApproachingActor = !isMoving;
MWWorld::Ptr currentTarget; // Combat or pursue target (NPCs should not avoid collision with their targets).
const auto& aiSequence = ptr.getClass().getCreatureStats(ptr).getAiSequence();
Expand All @@ -1941,7 +1942,7 @@ namespace MWMechanics
else if (package->getTypeId() == AiPackageTypeId::Wander && giveWayWhenIdle)
{
if (!static_cast<const AiWander*>(package.get())->isStationary())
shouldAvoidCollision = true;
shouldGiveWay = true;
}
else if (package->getTypeId() == AiPackageTypeId::Combat || package->getTypeId() == AiPackageTypeId::Pursue)
{
Expand All @@ -1951,7 +1952,7 @@ namespace MWMechanics
break;
}
}
if (!shouldAvoidCollision)
if (!shouldAvoidCollision && !shouldGiveWay)
continue;

osg::Vec2f baseSpeed = origMovement * maxSpeed;
Expand All @@ -1960,14 +1961,14 @@ namespace MWMechanics
osg::Vec3f halfExtents = world->getHalfExtents(ptr);
float maxDistToCheck = isMoving ? maxDistForPartialAvoiding : maxDistForStrictAvoiding;

float timeToCollision = maxTimeToCheck;
float timeToCheck = maxTimeToCheck;
if (!shouldGiveWay && !aiSequence.isEmpty())
timeToCheck = std::min(timeToCheck, getTimeToDestination(**aiSequence.begin(), basePos, maxSpeed, duration, halfExtents));

float timeToCollision = timeToCheck;
osg::Vec2f movementCorrection(0, 0);
float angleToApproachingActor = 0;

const float timeToDestination = aiSequence.isEmpty()
? std::numeric_limits<float>::max()
: getTimeToDestination(**aiSequence.begin(), basePos, maxSpeed, duration, halfExtents);

// Iterate through all other actors and predict collisions.
for(PtrActorMap::iterator otherIter(mActors.begin()); otherIter != mActors.end(); ++otherIter)
{
Expand Down Expand Up @@ -2004,7 +2005,7 @@ namespace MWMechanics
continue; // No solution; distance is always >= collisionDist.
float t = (-vr - std::sqrt(Dh)) / v2;

if (t < 0 || t > timeToCollision || t > timeToDestination)
if (t < 0 || t > timeToCollision)
continue;

// Check visibility and awareness last as it's expensive.
Expand All @@ -2024,7 +2025,7 @@ namespace MWMechanics
movementCorrection.y() *= 0.5f;
}

if (timeToCollision < maxTimeToCheck)
if (timeToCollision < timeToCheck)
{
// Try to evade the nearest collision.
osg::Vec2f newMovement = origMovement + movementCorrection;
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwmechanics/aicombat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ namespace MWMechanics

bool runFallback = true;

if (pathgrid && !actor.getClass().isPureWaterCreature(actor))
if (pathgrid != nullptr && !pathgrid->mPoints.empty() && !actor.getClass().isPureWaterCreature(actor))
{
ESM::Pathgrid::PointList points;
Misc::CoordinateConverter coords(storage.mCell->getCell());
Expand Down
3 changes: 3 additions & 0 deletions apps/openmw/mwmechanics/aiwander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ namespace MWMechanics
const ESM::Pathgrid *pathgrid =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Pathgrid>().search(*currentCell->getCell());

if (pathgrid == nullptr || pathgrid->mPoints.empty())
return;

int index = PathFinder::getClosestPoint(pathgrid, PathFinder::makeOsgVec3(dest));

getPathGridGraph(currentCell).getNeighbouringPoints(index, points);
Expand Down
6 changes: 2 additions & 4 deletions apps/openmw/mwmechanics/pathfinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ namespace MWMechanics
endPointInLocalCoords,
startNode);

if (!endNode.second)
return;

// if it's shorter for actor to travel from start to end, than to travel from either
// start or end to nearest pathgrid point, just travel from start to end.
float startToEndLength2 = (endPointInLocalCoords - startPointInLocalCoords).length2();
Expand Down Expand Up @@ -279,7 +276,8 @@ namespace MWMechanics
// unreachable pathgrid point.
//
// The AI routines will have to deal with such situations.
*out++ = endPoint;
if (endNode.second)
*out++ = endPoint;
}

float PathFinder::getZAngleToNext(float x, float y) const
Expand Down

0 comments on commit a01c874

Please sign in to comment.