Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4752db1
Switched to linear blur to reduce performance cost in prep for realti…
marcushutchings May 25, 2022
550e960
Switched to linear blur to reduce performance cost in prep for realti…
marcushutchings May 25, 2022
da7149e
Merge branch 'BAR105-smooth-mesh-dynamic-udpates' of github.com:beyon…
marcushutchings May 25, 2022
da143b2
Smooth mesh generation can operate on ranges rather than the whole map.
marcushutchings May 26, 2022
bb26e04
addressed issue where wider area was updated than was supposed to be
marcushutchings May 26, 2022
08fd455
realigned smooth mesh over heightmap
marcushutchings May 27, 2022
ad68c02
Further optimisations.
marcushutchings May 28, 2022
668a6cb
address edge cases.
marcushutchings May 28, 2022
6e21f9d
addressed outstanding issues.
marcushutchings May 30, 2022
683fd88
Tidying code.
marcushutchings May 30, 2022
841e1f6
Added smooth mesh debug to show damage due to be processed on the min…
marcushutchings May 31, 2022
b1fbeef
Fixed Height above water bug.
marcushutchings May 31, 2022
78d5293
Refactored part of mesh copying.
marcushutchings May 31, 2022
058e416
code refactoring.
marcushutchings May 31, 2022
8b65caf
adjusted assertion expectations.
marcushutchings May 31, 2022
9be30f7
added mod option to enable/disable smooth mesh.
marcushutchings May 31, 2022
2b6fcab
cleaned by mess in Game.cpp
marcushutchings May 31, 2022
12e6465
fixed issue with Lua commands that modify the smooth mesh.
marcushutchings Jun 1, 2022
59dc41a
Adjusted airmesh drawing to avoid overdraw.
marcushutchings Jun 1, 2022
a1f12df
Ensured SmoothHeightMeshDrawer gets cleared between matches.
marcushutchings Jun 2, 2022
490aed0
use spring safe delete
marcushutchings Jun 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rts/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ void CGame::PreLoadSimulation(LuaParser* defsParser)
ENTER_SYNCED_CODE();

loadscreen->SetLoadMessage("Creating Smooth Height Mesh");
smoothGround.Init(float3::maxxpos, float3::maxzpos, SQUARE_SIZE * 2, SQUARE_SIZE * 40);
smoothGround.Init(int2(mapDims.mapx, mapDims.mapy), 2, 40);

loadscreen->SetLoadMessage("Creating QuadField & CEGs");
moveDefHandler.Init(defsParser);
Expand Down Expand Up @@ -1761,6 +1761,7 @@ void CGame::SimFrame() {

helper->Update();
readMap->Update();
smoothGround.UpdateSmoothMesh();
mapDamage->Update();
pathManager->Update();
unitHandler.Update();
Expand Down
15 changes: 9 additions & 6 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4214,8 +4214,10 @@ static inline void ParseSmoothMeshParams(lua_State* L, const char* caller,
float& factor, int& x1, int& z1, int& x2, int& z2)
{
ParseParams(L, caller, factor, x1, z1, x2, z2,
smoothGround.GetResolution(), smoothGround.GetMaxX(),
smoothGround.GetMaxY());
smoothGround.GetResolution(),
smoothGround.GetMaxX() - 1,
smoothGround.GetMaxY() - 1);

}


Expand All @@ -4231,6 +4233,7 @@ int LuaSyncedCtrl::LevelSmoothMesh(lua_State* L)
smoothGround.SetHeight(index, height);
}
}

return 0;
}

Expand Down Expand Up @@ -4298,8 +4301,8 @@ int LuaSyncedCtrl::AddSmoothMesh(lua_State* L)
const int z = (int)(zl / smoothGround.GetResolution());

// discard invalid coordinates
if ((x < 0) || (x > smoothGround.GetMaxX()) ||
(z < 0) || (z > smoothGround.GetMaxY())) {
if ((x < 0) || (x > smoothGround.GetMaxX() - 1) ||
(z < 0) || (z > smoothGround.GetMaxY() - 1)) {
return 0;
}

Expand Down Expand Up @@ -4328,8 +4331,8 @@ int LuaSyncedCtrl::SetSmoothMesh(lua_State* L)
const int z = (int)(zl / smoothGround.GetResolution());

// discard invalid coordinates
if ((x < 0) || (x > smoothGround.GetMaxX()) ||
(z < 0) || (z > smoothGround.GetMaxY())) {
if ((x < 0) || (x > smoothGround.GetMaxX() - 1) ||
(z < 0) || (z > smoothGround.GetMaxY() - 1)) {
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions rts/Map/BasicMapDamage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Sim/Misc/GroundBlockingObjectMap.h"
#include "Sim/Misc/LosHandler.h"
#include "Sim/Misc/QuadField.h"
#include "Sim/Misc/SmoothHeightMesh.h"
#include "Sim/Units/Unit.h"
#include "Sim/Units/UnitHandler.h"
#include "Sim/Path/IPathManager.h"
Expand Down Expand Up @@ -227,6 +228,7 @@ void CBasicMapDamage::RecalcArea(int x1, int x2, int y1, int y2)

readMap->UpdateHeightMapSynced(updRect);
featureHandler.TerrainChanged(x1, y1, x2, y2);
smoothGround.MapChanged(x1, y1, x2, y2);
{
SCOPED_TIMER("Sim::BasicMapDamage::Los");
losHandler->UpdateHeightMapSynced(updRect);
Expand Down
82 changes: 75 additions & 7 deletions rts/Rendering/SmoothHeightMeshDrawer.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,86 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "SmoothHeightMeshDrawer.h"
#include "Sim/Misc/SmoothHeightMesh.h"

#include "Game/UI/MiniMap.h"
#include "Map/ReadMap.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/GL/VertexArray.h"
#include "Sim/Misc/GlobalSynced.h"
#include "Sim/Misc/SmoothHeightMesh.h"
#include "System/EventHandler.h"
#include "System/float3.h"
#include "System/SafeUtil.h"

using namespace SmoothHeightMeshNamespace;

static SmoothHeightMeshDrawer* smoothMeshDrawer = nullptr;

SmoothHeightMeshDrawer* SmoothHeightMeshDrawer::GetInstance() {
static SmoothHeightMeshDrawer drawer;
return &drawer;
if (smoothMeshDrawer == nullptr) {
smoothMeshDrawer = new SmoothHeightMeshDrawer();
}
return smoothMeshDrawer;
}

void SmoothHeightMeshDrawer::FreeInstance() {
if (smoothMeshDrawer != nullptr) {
spring::SafeDelete(smoothMeshDrawer);
}
}

SmoothHeightMeshDrawer::SmoothHeightMeshDrawer()
: CEventClient("[SmoothHeightMeshDrawer]", 300002, false)
, drawEnabled(false)
{
eventHandler.AddClient(this);
}
SmoothHeightMeshDrawer::~SmoothHeightMeshDrawer() {
eventHandler.RemoveClient(this);
}

void SmoothHeightMeshDrawer::DrawInMiniMap()
{
if (!(drawEnabled && gs->cheatEnabled))
return;

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0, -1.0);
minimap->ApplyConstraintsMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef3(UpVector);
glScalef(1.0f / mapDims.mapx, -1.0f / mapDims.mapy, 1.0f);

glDisable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 0.0f, 0.7f);

const SmoothHeightMesh::MapChangeTrack& mapChangeTrack = smoothGround.mapChangeTrack;
const float tileSize = SAMPLES_PER_QUAD * smoothGround.resolution;
int i = 0;
for (auto changed : mapChangeTrack.damageMap) {
if (changed){
const float x = (i % mapChangeTrack.width) * tileSize;
const float y = (i / mapChangeTrack.width) * tileSize;
glRectf(x, y, x + tileSize, y + tileSize);
}
i++;
}

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_2D);

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}

void SmoothHeightMeshDrawer::Draw(float yoffset) {
if (!drawEnabled)
if (!(drawEnabled && gs->cheatEnabled))
return;

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Expand All @@ -28,10 +96,10 @@ void SmoothHeightMeshDrawer::Draw(float yoffset) {

CVertexArray* va = GetVertexArray();
va->Initialize();
va->EnlargeArrays((numQuadsX + 1) * (numQuadsZ + 1) * 4, 0, VA_SIZE_0);
va->EnlargeArrays(numQuadsX * numQuadsZ * 4, 0, VA_SIZE_0);

for (unsigned int zq = 0; zq <= numQuadsZ; zq++) {
for (unsigned int xq = 0; xq <= numQuadsX; xq++) {
for (unsigned int zq = 0; zq < numQuadsZ; zq++) {
for (unsigned int xq = 0; xq < numQuadsX; xq++) {
const float x = xq * quadSize;
const float z = zq * quadSize;

Expand Down
15 changes: 14 additions & 1 deletion rts/Rendering/SmoothHeightMeshDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
#ifndef SMOOTH_HEIGHTMESH_DRAWER_H
#define SMOOTH_HEIGHTMESH_DRAWER_H

struct SmoothHeightMeshDrawer {
#include "System/EventClient.h"

struct SmoothHeightMeshDrawer: public CEventClient {
public:
static SmoothHeightMeshDrawer* GetInstance();
static void FreeInstance();

SmoothHeightMeshDrawer();
~SmoothHeightMeshDrawer();

// CEventClient interface
bool WantsEvent(const std::string& eventName) override {
return (eventName == "DrawInMiniMap");
}
void DrawInMiniMap() override;


void Draw(float yoffset);
bool& DrawEnabled() { return drawEnabled; }
Expand Down
1 change: 1 addition & 0 deletions rts/Rendering/WorldDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void CWorldDrawer::Kill()
IGroundDecalDrawer::FreeInstance();
CShaderHandler::FreeInstance(shaderHandler);
LuaObjectDrawer::Kill();
SmoothHeightMeshDrawer::FreeInstance();

numUpdates = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions rts/Sim/Misc/ModInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void CModInfo::ResetState()
pfRawDistMult = 1.25f;
pfUpdateRate = 0.007f;

enableSmoothMesh = true;

allowTake = true;
}
}
Expand Down Expand Up @@ -137,6 +139,8 @@ void CModInfo::Init(const std::string& modFileName)
pfRawDistMult = system.GetFloat("pathFinderRawDistMult", pfRawDistMult);
pfUpdateRate = system.GetFloat("pathFinderUpdateRate", pfUpdateRate);

enableSmoothMesh = system.GetBool("enableSmoothMesh", enableSmoothMesh);

allowTake = system.GetBool("allowTake", allowTake);
}

Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Misc/ModInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class CModInfo
float pfRawDistMult;
float pfUpdateRate;

bool enableSmoothMesh;

bool allowTake;
};

Expand Down
Loading