Merge branch 'master' into Playerbot

This commit is contained in:
Yunfan Li
2025-02-19 22:29:36 +08:00
parent d1032678ff
commit 7d431dc796
277 changed files with 7092 additions and 5050 deletions

View File

@@ -22,6 +22,7 @@
#include "DetourNavMesh.h"
#define MAX_NUMBER_OF_GRIDS 64
#define MAX_NUMBER_OF_CELLS 8
#define SIZE_OF_GRIDS 533.3333f
#define MMAP_MAGIC 0x4d4d4150 // 'MMAP'

View File

@@ -138,18 +138,28 @@ namespace Acore::Containers
}
/*
* Select a random element from a container.
* @brief Selects a random element from a container that matches the given predicate
*
* @param container Source container to select from
* @param predicate Unary predicate to filter elements
* @return Iterator to the randomly selected element, or end iterator if no elements match the predicate
*
* Note: container cannot be empty
*/
template<class C, class Predicate>
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> typename std::add_const<decltype(*std::begin(container))>::type&
inline auto SelectRandomContainerElementIf(C const& container, Predicate&& predicate) -> decltype(std::begin(container))
{
C containerCopy;
std::copy_if(std::begin(container), std::end(container), std::inserter(containerCopy, std::end(containerCopy)), predicate);
auto it = std::begin(containerCopy);
std::advance(it, urand(0, uint32(std::size(containerCopy)) - 1));
return *it;
std::vector<decltype(std::begin(container))> matchingElements;
for (auto it = std::begin(container); it != std::end(container); ++it)
if (predicate(*it))
matchingElements.push_back(it);
if (matchingElements.empty())
return std::end(container);
auto randomIt = matchingElements[urand(0, matchingElements.size() - 1)];
return randomIt;
}
/*

View File

@@ -17,7 +17,8 @@
#ifndef Random_h__
#define Random_h__
#undef max
#undef min
#include "Define.h"
#include "Duration.h"
#include <limits>