mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:50:06 +00:00
Placefile icons looping
This commit is contained in:
parent
d160eb6f94
commit
4feff1cb6e
1 changed files with 93 additions and 27 deletions
|
|
@ -32,6 +32,9 @@ static constexpr std::size_t kIconBufferLength =
|
||||||
static constexpr std::size_t kTextureBufferLength =
|
static constexpr std::size_t kTextureBufferLength =
|
||||||
kNumTriangles * kVerticesPerTriangle * kPointsPerTexCoord;
|
kNumTriangles * kVerticesPerTriangle * kPointsPerTexCoord;
|
||||||
|
|
||||||
|
// Threshold, start time, end time
|
||||||
|
static constexpr std::size_t kIntegersPerVertex_ = 3;
|
||||||
|
|
||||||
struct PlacefileIconInfo
|
struct PlacefileIconInfo
|
||||||
{
|
{
|
||||||
PlacefileIconInfo(
|
PlacefileIconInfo(
|
||||||
|
|
@ -78,6 +81,7 @@ public:
|
||||||
uMapMatrixLocation_(GL_INVALID_INDEX),
|
uMapMatrixLocation_(GL_INVALID_INDEX),
|
||||||
uMapScreenCoordLocation_(GL_INVALID_INDEX),
|
uMapScreenCoordLocation_(GL_INVALID_INDEX),
|
||||||
uMapDistanceLocation_(GL_INVALID_INDEX),
|
uMapDistanceLocation_(GL_INVALID_INDEX),
|
||||||
|
uSelectedTimeLocation_(GL_INVALID_INDEX),
|
||||||
vao_ {GL_INVALID_INDEX},
|
vao_ {GL_INVALID_INDEX},
|
||||||
vbo_ {GL_INVALID_INDEX},
|
vbo_ {GL_INVALID_INDEX},
|
||||||
numVertices_ {0}
|
numVertices_ {0}
|
||||||
|
|
@ -111,9 +115,9 @@ public:
|
||||||
newValidIconList_ {};
|
newValidIconList_ {};
|
||||||
|
|
||||||
std::vector<float> currentIconBuffer_ {};
|
std::vector<float> currentIconBuffer_ {};
|
||||||
std::vector<GLint> currentThresholdBuffer_ {};
|
std::vector<GLint> currentIntegerBuffer_ {};
|
||||||
std::vector<float> newIconBuffer_ {};
|
std::vector<float> newIconBuffer_ {};
|
||||||
std::vector<GLint> newThresholdBuffer_ {};
|
std::vector<GLint> newIntegerBuffer_ {};
|
||||||
|
|
||||||
std::vector<float> textureBuffer_ {};
|
std::vector<float> textureBuffer_ {};
|
||||||
|
|
||||||
|
|
@ -125,6 +129,7 @@ public:
|
||||||
GLint uMapMatrixLocation_;
|
GLint uMapMatrixLocation_;
|
||||||
GLint uMapScreenCoordLocation_;
|
GLint uMapScreenCoordLocation_;
|
||||||
GLint uMapDistanceLocation_;
|
GLint uMapDistanceLocation_;
|
||||||
|
GLint uSelectedTimeLocation_;
|
||||||
|
|
||||||
GLuint vao_;
|
GLuint vao_;
|
||||||
std::array<GLuint, 3> vbo_;
|
std::array<GLuint, 3> vbo_;
|
||||||
|
|
@ -167,6 +172,8 @@ void PlacefileIcons::Initialize()
|
||||||
p->shaderProgram_->GetUniformLocation("uMapScreenCoord");
|
p->shaderProgram_->GetUniformLocation("uMapScreenCoord");
|
||||||
p->uMapDistanceLocation_ =
|
p->uMapDistanceLocation_ =
|
||||||
p->shaderProgram_->GetUniformLocation("uMapDistance");
|
p->shaderProgram_->GetUniformLocation("uMapDistance");
|
||||||
|
p->uSelectedTimeLocation_ =
|
||||||
|
p->shaderProgram_->GetUniformLocation("uSelectedTime");
|
||||||
|
|
||||||
gl.glGenVertexArrays(1, &p->vao_);
|
gl.glGenVertexArrays(1, &p->vao_);
|
||||||
gl.glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
gl.glGenBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data());
|
||||||
|
|
@ -234,6 +241,14 @@ void PlacefileIcons::Initialize()
|
||||||
static_cast<void*>(0));
|
static_cast<void*>(0));
|
||||||
gl.glEnableVertexAttribArray(5);
|
gl.glEnableVertexAttribArray(5);
|
||||||
|
|
||||||
|
// aTimeRange
|
||||||
|
gl.glVertexAttribIPointer(6, //
|
||||||
|
2,
|
||||||
|
GL_INT,
|
||||||
|
kIntegersPerVertex_ * sizeof(GLint),
|
||||||
|
reinterpret_cast<void*>(1 * sizeof(GLint)));
|
||||||
|
gl.glEnableVertexAttribArray(6);
|
||||||
|
|
||||||
p->dirty_ = true;
|
p->dirty_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,6 +283,17 @@ void PlacefileIcons::Render(
|
||||||
gl.glUniform1f(p->uMapDistanceLocation_, 0.0f);
|
gl.glUniform1f(p->uMapDistanceLocation_, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Selected time
|
||||||
|
std::chrono::system_clock::time_point selectedTime =
|
||||||
|
(p->selectedTime_ == std::chrono::system_clock::time_point {}) ?
|
||||||
|
std::chrono::system_clock::now() :
|
||||||
|
p->selectedTime_;
|
||||||
|
gl.glUniform1i(
|
||||||
|
p->uSelectedTimeLocation_,
|
||||||
|
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||||
|
selectedTime.time_since_epoch())
|
||||||
|
.count()));
|
||||||
|
|
||||||
// Interpolate texture coordinates
|
// Interpolate texture coordinates
|
||||||
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
gl.glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
|
@ -290,7 +316,7 @@ void PlacefileIcons::Deinitialize()
|
||||||
p->currentIconFiles_.clear();
|
p->currentIconFiles_.clear();
|
||||||
p->currentHoverIcons_.clear();
|
p->currentHoverIcons_.clear();
|
||||||
p->currentIconBuffer_.clear();
|
p->currentIconBuffer_.clear();
|
||||||
p->currentThresholdBuffer_.clear();
|
p->currentIntegerBuffer_.clear();
|
||||||
p->textureBuffer_.clear();
|
p->textureBuffer_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,7 +358,7 @@ void PlacefileIcons::StartIcons()
|
||||||
p->newValidIconList_.clear();
|
p->newValidIconList_.clear();
|
||||||
p->newIconFiles_.clear();
|
p->newIconFiles_.clear();
|
||||||
p->newIconBuffer_.clear();
|
p->newIconBuffer_.clear();
|
||||||
p->newThresholdBuffer_.clear();
|
p->newIntegerBuffer_.clear();
|
||||||
p->newHoverIcons_.clear();
|
p->newHoverIcons_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -376,7 +402,7 @@ void PlacefileIcons::FinishIcons()
|
||||||
p->currentIconList_.swap(p->newValidIconList_);
|
p->currentIconList_.swap(p->newValidIconList_);
|
||||||
p->currentIconFiles_.swap(p->newIconFiles_);
|
p->currentIconFiles_.swap(p->newIconFiles_);
|
||||||
p->currentIconBuffer_.swap(p->newIconBuffer_);
|
p->currentIconBuffer_.swap(p->newIconBuffer_);
|
||||||
p->currentThresholdBuffer_.swap(p->newThresholdBuffer_);
|
p->currentIntegerBuffer_.swap(p->newIntegerBuffer_);
|
||||||
p->currentHoverIcons_.swap(p->newHoverIcons_);
|
p->currentHoverIcons_.swap(p->newHoverIcons_);
|
||||||
|
|
||||||
// Clear the new buffers
|
// Clear the new buffers
|
||||||
|
|
@ -384,7 +410,7 @@ void PlacefileIcons::FinishIcons()
|
||||||
p->newValidIconList_.clear();
|
p->newValidIconList_.clear();
|
||||||
p->newIconFiles_.clear();
|
p->newIconFiles_.clear();
|
||||||
p->newIconBuffer_.clear();
|
p->newIconBuffer_.clear();
|
||||||
p->newThresholdBuffer_.clear();
|
p->newIntegerBuffer_.clear();
|
||||||
p->newHoverIcons_.clear();
|
p->newHoverIcons_.clear();
|
||||||
|
|
||||||
// Mark the draw item dirty
|
// Mark the draw item dirty
|
||||||
|
|
@ -395,8 +421,9 @@ void PlacefileIcons::Impl::UpdateBuffers()
|
||||||
{
|
{
|
||||||
newIconBuffer_.clear();
|
newIconBuffer_.clear();
|
||||||
newIconBuffer_.reserve(newIconList_.size() * kIconBufferLength);
|
newIconBuffer_.reserve(newIconList_.size() * kIconBufferLength);
|
||||||
newThresholdBuffer_.clear();
|
newIntegerBuffer_.clear();
|
||||||
newThresholdBuffer_.reserve(newIconList_.size() * kVerticesPerRectangle);
|
newIntegerBuffer_.reserve(newIconList_.size() * kVerticesPerRectangle *
|
||||||
|
kIntegersPerVertex_);
|
||||||
|
|
||||||
for (auto& di : newIconList_)
|
for (auto& di : newIconList_)
|
||||||
{
|
{
|
||||||
|
|
@ -425,6 +452,16 @@ void PlacefileIcons::Impl::UpdateBuffers()
|
||||||
units::length::nautical_miles<double> threshold = di->threshold_;
|
units::length::nautical_miles<double> threshold = di->threshold_;
|
||||||
GLint thresholdValue = static_cast<GLint>(std::round(threshold.value()));
|
GLint thresholdValue = static_cast<GLint>(std::round(threshold.value()));
|
||||||
|
|
||||||
|
// Start and end time
|
||||||
|
GLint startTime =
|
||||||
|
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||||
|
di->startTime_.time_since_epoch())
|
||||||
|
.count());
|
||||||
|
GLint endTime =
|
||||||
|
static_cast<GLint>(std::chrono::duration_cast<std::chrono::minutes>(
|
||||||
|
di->endTime_.time_since_epoch())
|
||||||
|
.count());
|
||||||
|
|
||||||
// Latitude and longitude coordinates in degrees
|
// Latitude and longitude coordinates in degrees
|
||||||
const float lat = static_cast<float>(di->latitude_);
|
const float lat = static_cast<float>(di->latitude_);
|
||||||
const float lon = static_cast<float>(di->longitude_);
|
const float lon = static_cast<float>(di->longitude_);
|
||||||
|
|
@ -467,13 +504,25 @@ void PlacefileIcons::Impl::UpdateBuffers()
|
||||||
lat, lon, rx, ty, mc0, mc1, mc2, mc3, a, // TR
|
lat, lon, rx, ty, mc0, mc1, mc2, mc3, a, // TR
|
||||||
lat, lon, lx, ty, mc0, mc1, mc2, mc3, a // TL
|
lat, lon, lx, ty, mc0, mc1, mc2, mc3, a // TL
|
||||||
});
|
});
|
||||||
newThresholdBuffer_.insert(newThresholdBuffer_.end(),
|
newIntegerBuffer_.insert(newIntegerBuffer_.end(),
|
||||||
{thresholdValue, //
|
{thresholdValue,
|
||||||
thresholdValue,
|
startTime,
|
||||||
thresholdValue,
|
endTime,
|
||||||
thresholdValue,
|
thresholdValue,
|
||||||
thresholdValue,
|
startTime,
|
||||||
thresholdValue});
|
endTime,
|
||||||
|
thresholdValue,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
thresholdValue,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
thresholdValue,
|
||||||
|
startTime,
|
||||||
|
endTime,
|
||||||
|
thresholdValue,
|
||||||
|
startTime,
|
||||||
|
endTime});
|
||||||
|
|
||||||
if (!di->hoverText_.empty())
|
if (!di->hoverText_.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -622,8 +671,8 @@ void PlacefileIcons::Impl::Update(bool textureAtlasChanged)
|
||||||
// Buffer threshold data
|
// Buffer threshold data
|
||||||
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]);
|
gl.glBindBuffer(GL_ARRAY_BUFFER, vbo_[2]);
|
||||||
gl.glBufferData(GL_ARRAY_BUFFER,
|
gl.glBufferData(GL_ARRAY_BUFFER,
|
||||||
sizeof(GLint) * currentThresholdBuffer_.size(),
|
sizeof(GLint) * currentIntegerBuffer_.size(),
|
||||||
currentThresholdBuffer_.data(),
|
currentIntegerBuffer_.data(),
|
||||||
GL_DYNAMIC_DRAW);
|
GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
numVertices_ = static_cast<GLsizei>(currentIconBuffer_.size() /
|
numVertices_ = static_cast<GLsizei>(currentIconBuffer_.size() /
|
||||||
|
|
@ -656,24 +705,41 @@ bool PlacefileIcons::RunMousePicking(
|
||||||
(p->thresholded_) ? util::maplibre::GetMapDistance(params) :
|
(p->thresholded_) ? util::maplibre::GetMapDistance(params) :
|
||||||
units::length::meters<double> {0.0};
|
units::length::meters<double> {0.0};
|
||||||
|
|
||||||
|
// If no time has been selected, use the current time
|
||||||
|
std::chrono::system_clock::time_point selectedTime =
|
||||||
|
(p->selectedTime_ == std::chrono::system_clock::time_point {}) ?
|
||||||
|
std::chrono::system_clock::now() :
|
||||||
|
p->selectedTime_;
|
||||||
|
|
||||||
// For each pickable icon
|
// For each pickable icon
|
||||||
auto it = std::find_if(
|
auto it = std::find_if(
|
||||||
std::execution::par_unseq,
|
std::execution::par_unseq,
|
||||||
p->currentHoverIcons_.crbegin(),
|
p->currentHoverIcons_.crbegin(),
|
||||||
p->currentHoverIcons_.crend(),
|
p->currentHoverIcons_.crend(),
|
||||||
[&mapDistance, &mapMatrix, &mousePos](const auto& icon)
|
[&mapDistance, &selectedTime, &mapMatrix, &mousePos](const auto& icon)
|
||||||
{
|
{
|
||||||
if (
|
if ((
|
||||||
// Placefile is thresholded
|
// Placefile is thresholded
|
||||||
mapDistance > units::length::meters<double> {0.0} &&
|
mapDistance > units::length::meters<double> {0.0} &&
|
||||||
|
|
||||||
// Placefile threshold is < 999 nmi
|
// Placefile threshold is < 999 nmi
|
||||||
static_cast<int>(std::round(
|
static_cast<int>(std::round(
|
||||||
units::length::nautical_miles<double> {icon.di_->threshold_}
|
units::length::nautical_miles<double> {icon.di_->threshold_}
|
||||||
.value())) < 999 &&
|
.value())) < 999 &&
|
||||||
|
|
||||||
// Map distance is beyond the threshold
|
// Map distance is beyond the threshold
|
||||||
icon.di_->threshold_ < mapDistance)
|
icon.di_->threshold_ < mapDistance) ||
|
||||||
|
|
||||||
|
(
|
||||||
|
// Line has a start time
|
||||||
|
icon.di_->startTime_ !=
|
||||||
|
std::chrono::system_clock::time_point {} &&
|
||||||
|
|
||||||
|
// The time range has not yet started
|
||||||
|
(selectedTime < icon.di_->startTime_ ||
|
||||||
|
|
||||||
|
// The time range has ended
|
||||||
|
icon.di_->endTime_ <= selectedTime)))
|
||||||
{
|
{
|
||||||
// Icon is not pickable
|
// Icon is not pickable
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue