graph: light levels are now recalculated on every level change
This commit is contained in:
parent
d11f071b72
commit
9e67232c07
6 changed files with 40 additions and 17 deletions
|
|
@ -448,6 +448,10 @@ public:
|
||||||
return ptr->string;
|
return ptr->string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringRef name () const {
|
||||||
|
return ptr->name;
|
||||||
|
}
|
||||||
|
|
||||||
void set (float val) {
|
void set (float val) {
|
||||||
engfuncs.pfnCVarSetFloat (ptr->name, val);
|
engfuncs.pfnCVarSetFloat (ptr->name, val);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ private:
|
||||||
bool m_hasChanged {};
|
bool m_hasChanged {};
|
||||||
bool m_narrowChecked {};
|
bool m_narrowChecked {};
|
||||||
bool m_silenceMessages {};
|
bool m_silenceMessages {};
|
||||||
|
bool m_lightChecked {};
|
||||||
|
|
||||||
Vector m_learnVelocity {};
|
Vector m_learnVelocity {};
|
||||||
Vector m_learnPosition {};
|
Vector m_learnPosition {};
|
||||||
|
|
|
||||||
|
|
@ -801,6 +801,14 @@ int BotControl::cmdNodeUpload () {
|
||||||
msg ("Sorry, unable to upload graph file that contains errors. Please type \"graph check\" to verify graph consistency.");
|
msg ("Sorry, unable to upload graph file that contains errors. Please type \"graph check\" to verify graph consistency.");
|
||||||
return BotCommandResult::Handled;
|
return BotCommandResult::Handled;
|
||||||
}
|
}
|
||||||
|
String uploadUrlAddress = cv_graph_url_upload.str ();
|
||||||
|
|
||||||
|
// only allow to upload to non-https endpoint
|
||||||
|
if (uploadUrlAddress.startsWith ("http")) {
|
||||||
|
msg ("Value of \"%s\" cvar should not contain URL scheme, only the host name and path.", cv_graph_url_upload.name ());
|
||||||
|
return BotCommandResult::Handled;
|
||||||
|
}
|
||||||
|
String uploadUrl = strings.format ("http://%s", uploadUrlAddress);
|
||||||
|
|
||||||
msg ("\n");
|
msg ("\n");
|
||||||
msg ("WARNING!");
|
msg ("WARNING!");
|
||||||
|
|
@ -808,8 +816,6 @@ int BotControl::cmdNodeUpload () {
|
||||||
msg ("you may notice the game freezes a bit during upload and issue request creation. Please, be patient.");
|
msg ("you may notice the game freezes a bit during upload and issue request creation. Please, be patient.");
|
||||||
msg ("\n");
|
msg ("\n");
|
||||||
|
|
||||||
String uploadUrl = strings.format ("https://%s", cv_graph_url_upload.str ());
|
|
||||||
|
|
||||||
// try to upload the file
|
// try to upload the file
|
||||||
if (http.uploadFile (uploadUrl, bstor.buildPath (BotFile::Graph))) {
|
if (http.uploadFile (uploadUrl, bstor.buildPath (BotFile::Graph))) {
|
||||||
msg ("Graph file was successfully validated and uploaded to the YaPB Graph DB (%s).", product.download);
|
msg ("Graph file was successfully validated and uploaded to the YaPB Graph DB (%s).", product.download);
|
||||||
|
|
|
||||||
|
|
@ -1183,7 +1183,7 @@ template <typename S, typename M> bool LightMeasure::recursiveLightPoint (const
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine which side of the node plane our points are on, fixme: optimize for axial
|
// determine which side of the node plane our points are on, fixme: optimize for axial
|
||||||
auto plane = node->plane;
|
const auto plane = node->plane;
|
||||||
|
|
||||||
const float front = (start | plane->normal) - plane->dist;
|
const float front = (start | plane->normal) - plane->dist;
|
||||||
const float back = (end | plane->normal) - plane->dist;
|
const float back = (end | plane->normal) - plane->dist;
|
||||||
|
|
@ -1252,7 +1252,7 @@ template <typename S, typename M> bool LightMeasure::recursiveLightPoint (const
|
||||||
auto lightmap = surf->samples + dt * smax + ds;
|
auto lightmap = surf->samples + dt * smax + ds;
|
||||||
|
|
||||||
// compute the lightmap color at a particular point
|
// compute the lightmap color at a particular point
|
||||||
for (int maps = 0u; maps < MAX_LIGHTMAPS && surf->styles[maps] != 255u; ++maps) {
|
for (int maps = 0; maps < MAX_LIGHTMAPS && surf->styles[maps] != 255; ++maps) {
|
||||||
const uint32_t scale = m_lightstyleValue[surf->styles[maps]];
|
const uint32_t scale = m_lightstyleValue[surf->styles[maps]];
|
||||||
|
|
||||||
m_point.red += lightmap->r * scale;
|
m_point.red += lightmap->r * scale;
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ void BotGraph::reset () {
|
||||||
m_autoPathDistance = 250.0f;
|
m_autoPathDistance = 250.0f;
|
||||||
m_hasChanged = false;
|
m_hasChanged = false;
|
||||||
m_narrowChecked = false;
|
m_narrowChecked = false;
|
||||||
|
m_lightChecked = false;
|
||||||
|
|
||||||
m_graphAuthor.clear ();
|
m_graphAuthor.clear ();
|
||||||
m_graphModified.clear ();
|
m_graphModified.clear ();
|
||||||
|
|
@ -1332,23 +1333,31 @@ void BotGraph::calculatePathRadius (int index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BotGraph::syncInitLightLevels () {
|
void BotGraph::syncInitLightLevels () {
|
||||||
// this function get's the light level for each waypoin on the map
|
// this function get's the light level for each node on the map
|
||||||
|
|
||||||
// no nodes ? no light levels, and only one-time init
|
|
||||||
if (m_paths.empty () || !cr::fequal (m_paths[0].light, kInvalidLightLevel)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update light levels for all nodes
|
// update light levels for all nodes
|
||||||
for (auto &path : m_paths) {
|
for (auto &path : m_paths) {
|
||||||
path.light = illum.getLightLevel (path.origin);
|
path.light = illum.getLightLevel (path.origin + Vector { 0.0f, 0.0f, 16.0f} );
|
||||||
}
|
}
|
||||||
|
m_lightChecked = true;
|
||||||
|
|
||||||
// disable lightstyle animations on finish (will be auto-enabled on mapchange)
|
// disable lightstyle animations on finish (will be auto-enabled on mapchange)
|
||||||
illum.enableAnimation (false);
|
illum.enableAnimation (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BotGraph::initLightLevels () {
|
void BotGraph::initLightLevels () {
|
||||||
// this function get's the light level for each waypoin on the map
|
// this function get's the light level for each node on the map
|
||||||
|
|
||||||
|
// no nodes ? no light levels, and only one-time init
|
||||||
|
if (m_paths.empty () || m_lightChecked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto players = bots.countTeamPlayers ();
|
||||||
|
|
||||||
|
// do calculation if some-one is already playing on the server
|
||||||
|
if (!players.first && !players.second) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
worker.enqueue ([this] () {
|
worker.enqueue ([this] () {
|
||||||
syncInitLightLevels ();
|
syncInitLightLevels ();
|
||||||
|
|
@ -1664,6 +1673,8 @@ bool BotGraph::saveGraphData () {
|
||||||
|
|
||||||
// ensure narrow places saved into file
|
// ensure narrow places saved into file
|
||||||
m_narrowChecked = false;
|
m_narrowChecked = false;
|
||||||
|
m_lightChecked = false;
|
||||||
|
|
||||||
initNarrowPlaces ();
|
initNarrowPlaces ();
|
||||||
|
|
||||||
return bstor.save <Path> (m_paths, &exten, options);
|
return bstor.save <Path> (m_paths, &exten, options);
|
||||||
|
|
@ -2553,6 +2564,7 @@ BotGraph::BotGraph () {
|
||||||
m_jumpLearnNode = false;
|
m_jumpLearnNode = false;
|
||||||
m_hasChanged = false;
|
m_hasChanged = false;
|
||||||
m_narrowChecked = false;
|
m_narrowChecked = false;
|
||||||
|
m_lightChecked = false;
|
||||||
m_timeJumpStarted = 0.0f;
|
m_timeJumpStarted = 0.0f;
|
||||||
|
|
||||||
m_lastJumpNode = kInvalidNodeIndex;
|
m_lastJumpNode = kInvalidNodeIndex;
|
||||||
|
|
|
||||||
|
|
@ -1639,7 +1639,7 @@ bool Bot::findNextBestNode () {
|
||||||
}
|
}
|
||||||
int selected = kInvalidNodeIndex;
|
int selected = kInvalidNodeIndex;
|
||||||
|
|
||||||
// now pick random one from choosen
|
// now pick random one from chosen
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
// choice from found
|
// choice from found
|
||||||
|
|
@ -1766,7 +1766,7 @@ int Bot::findNearestNode () {
|
||||||
const float distanceSq = path.origin.distanceSq (pev->origin);
|
const float distanceSq = path.origin.distanceSq (pev->origin);
|
||||||
|
|
||||||
if (distanceSq < nearestDistanceSq) {
|
if (distanceSq < nearestDistanceSq) {
|
||||||
// if bot doing navigation, make sure node really visible and reacheable
|
// if bot doing navigation, make sure node really visible and reachable
|
||||||
if (isReachableNode (path.number)) {
|
if (isReachableNode (path.number)) {
|
||||||
index = path.number;
|
index = path.number;
|
||||||
nearestDistanceSq = distanceSq;
|
nearestDistanceSq = distanceSq;
|
||||||
|
|
@ -1774,7 +1774,7 @@ int Bot::findNearestNode () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to search ANYTHING that can be reachaed
|
// try to search ANYTHING that can be reached
|
||||||
if (!graph.exists (index)) {
|
if (!graph.exists (index)) {
|
||||||
nearestDistanceSq = cr::sqrf (kMaxDistance);
|
nearestDistanceSq = cr::sqrf (kMaxDistance);
|
||||||
const auto &nearestNodes = graph.getNarestInRadius (kMaxDistance, pev->origin);
|
const auto &nearestNodes = graph.getNarestInRadius (kMaxDistance, pev->origin);
|
||||||
|
|
@ -1899,7 +1899,7 @@ int Bot::findDefendNode (const Vector &origin) {
|
||||||
// use the 'real' path finding distances
|
// use the 'real' path finding distances
|
||||||
auto distance = planner.dist (srcIndex, path.number);
|
auto distance = planner.dist (srcIndex, path.number);
|
||||||
|
|
||||||
// skip wayponts too far
|
// skip nodes too far
|
||||||
if (distance > kMaxDistance) {
|
if (distance > kMaxDistance) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue