Я столкнулся с проблемой при использовании std :: map. Я хотел использовать его в качестве словаря для моего ландшафта и хотел получить доступ к фрагментам с помощью glm :: ivec2. Я думаю, проблема в том, что у glm :: ivec2 нет оператора less <. Я видел несколько похожих постов с собственными структурами, но я не знаю, могу ли я применить их здесь или как мне go об этом. (извините, если какая-то информация отсутствует, это мой первый пост) </p>
// init of the dictionary
std::map<glm::ivec2,Chunk> m_chunkDictionary; // init of the dictionary
//uses of the dictionary
glm::ivec2 currentChunk = glm::ivec2(round(m_scene->cam->Position.x / m_patchSize),
round(m_scene->cam->Position.z / m_patchSize));
for (int x = -m_patchSize; x <= m_patchSize; x++)
{
for (int z = -m_patchSize; z <= m_patchSize; z++)
{
glm::ivec2 viewedChunk = glm::ivec2(currentChunk.x + x, currentChunk.y + z );
if(!contains(viewedChunk)) // contains is available in c++20, so i needed to write one myself
{
m_chunkDictionary[viewedChunk] = Chunk(m_patchSize, viewedChunk.x, viewedChunk.y, m_seed);
}
m_chunkDictionary[viewedChunk].render();
}
}
EDIT: я пытался реализовать компаратор, но он не работал
struct cmpVecs{
bool operator()(const glm::ivec2& a, const glm::ivec2& b) const {
return a.x == b.x && a.y == b.y;
}
};
std::map<glm::ivec2,Chunk,cmpVecs> m_chunkDictionary ;
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xstddef(127): error C2676: Bin„rer Operator "<": "const _Ty" definiert diesen Operator oder eine Konvertierung in einen f�r den vordefinierten Operator geeigneten Typ nicht
with
[
_Ty=glm::ivec2
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xstddef(126): note: beim Kompilieren der Klasse Vorlage-Memberfunktion "bool std::less<glm::ivec2>::operator ()(const _Ty &,const _Ty &) const"
with
[
_Ty=glm::ivec2
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xutility(1518): note: Siehe Verweis auf die gerade kompilierte Instanziierung "bool std::less<glm::ivec2>::operator ()(const _Ty &,const _Ty &) const" der Funktions-Vorlage.
with
[
_Ty=glm::ivec2
]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xmemory(1318): note: Siehe Verweis auf die gerade kompilierte Klasse Vorlage-Instanziierung "std::less<glm::ivec2>".
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\xmemory(1318): note: Weitere Informationen finden Sie in der Referenz zur Kompilierung der Variablenvorlage "const bool is_empty_v<std::less<glm::vec<2,int,0> > >".
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\map(75): note: Siehe Verweis auf die gerade kompilierte Klasse Vorlage-Instanziierung "std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>".
with
[
_Kty=glm::ivec2,
_Ty=Chunk,
_Pr=std::less<glm::ivec2>,
_Alloc=std::allocator<std::pair<const glm::ivec2,Chunk>>
]
E:\Desktop\Projekte\EZR\EZR\Glitter\Sources\Terrain.h(53): note: Siehe Verweis auf die gerade kompilierte Klasse Vorlage-Instanziierung "std::map<glm::ivec2,Chunk,std::less<glm::ivec2>,std::allocator<std::pair<const glm::ivec2,Chunk>>>".