ddnet/src/game/editor/auto_map.cpp

544 lines
15 KiB
C++
Raw Normal View History

2022-02-14 23:22:52 +00:00
#include <cinttypes>
#include <cstdio> // sscanf
#include <engine/console.h>
#include <engine/shared/linereader.h>
#include <engine/storage.h>
#include "auto_map.h"
#include "editor.h"
// Based on triple32inc from https://github.com/skeeto/hash-prospector/tree/79a6074062a84907df6e45b756134b74e2956760
static uint32_t HashUInt32(uint32_t Num)
{
Num++;
Num ^= Num >> 17;
Num *= 0xed5ad4bbu;
Num ^= Num >> 11;
Num *= 0xac4c1b51u;
Num ^= Num >> 15;
Num *= 0x31848babu;
Num ^= Num >> 14;
return Num;
}
#define HASH_MAX 65536
static int HashLocation(uint32_t Seed, uint32_t Run, uint32_t Rule, uint32_t X, uint32_t Y)
{
const uint32_t Prime = 31;
uint32_t Hash = 1;
Hash = Hash * Prime + HashUInt32(Seed);
Hash = Hash * Prime + HashUInt32(Run);
Hash = Hash * Prime + HashUInt32(Rule);
Hash = Hash * Prime + HashUInt32(X);
Hash = Hash * Prime + HashUInt32(Y);
Hash = HashUInt32(Hash * Prime); // Just to double-check that values are well-distributed
return Hash % HASH_MAX;
}
CAutoMapper::CAutoMapper(CEditor *pEditor)
{
m_pEditor = pEditor;
m_FileLoaded = false;
}
void CAutoMapper::Load(const char *pTileName)
{
char aPath[256];
str_format(aPath, sizeof(aPath), "editor/%s.rules", pTileName);
IOHANDLE RulesFile = m_pEditor->Storage()->OpenFile(aPath, IOFLAG_READ | IOFLAG_SKIP_BOM, IStorage::TYPE_ALL);
if(!RulesFile)
return;
2011-08-11 08:59:14 +00:00
CLineReader LineReader;
LineReader.Init(RulesFile);
2011-08-11 08:59:14 +00:00
CConfiguration *pCurrentConf = nullptr;
CRun *pCurrentRun = nullptr;
CIndexRule *pCurrentIndex = nullptr;
2011-08-11 08:59:14 +00:00
char aBuf[256];
2011-08-11 08:59:14 +00:00
// read each line
while(char *pLine = LineReader.Get())
{
// skip blank/empty lines as well as comments
if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ')
{
if(pLine[0] == '[')
{
// new configuration, get the name
pLine++;
CConfiguration NewConf;
NewConf.m_aName[0] = '\0';
NewConf.m_StartX = 0;
NewConf.m_StartY = 0;
NewConf.m_EndX = 0;
NewConf.m_EndY = 0;
m_vConfigs.push_back(NewConf);
int ConfigurationID = m_vConfigs.size() - 1;
pCurrentConf = &m_vConfigs[ConfigurationID];
str_copy(pCurrentConf->m_aName, pLine, str_length(pLine));
2015-02-19 23:15:09 +00:00
// add start run
CRun NewRun;
2018-07-19 15:09:29 +00:00
NewRun.m_AutomapCopy = true;
pCurrentConf->m_vRuns.push_back(NewRun);
int RunID = pCurrentConf->m_vRuns.size() - 1;
pCurrentRun = &pCurrentConf->m_vRuns[RunID];
}
else if(str_startswith(pLine, "NewRun") && pCurrentConf)
{
2015-02-19 23:15:09 +00:00
// add new run
CRun NewRun;
2018-07-19 15:09:29 +00:00
NewRun.m_AutomapCopy = true;
pCurrentConf->m_vRuns.push_back(NewRun);
int RunID = pCurrentConf->m_vRuns.size() - 1;
pCurrentRun = &pCurrentConf->m_vRuns[RunID];
2015-02-19 23:15:09 +00:00
}
else if(str_startswith(pLine, "Index") && pCurrentRun)
2015-02-19 23:15:09 +00:00
{
// new index
int ID = 0;
char aOrientation1[128] = "";
char aOrientation2[128] = "";
char aOrientation3[128] = "";
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
sscanf(pLine, "Index %d %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3);
2013-12-27 17:32:58 +00:00
2015-02-19 23:15:09 +00:00
CIndexRule NewIndexRule;
NewIndexRule.m_ID = ID;
NewIndexRule.m_Flag = 0;
2019-07-08 21:08:42 +00:00
NewIndexRule.m_RandomProbability = 1.0f;
2015-02-19 23:15:09 +00:00
NewIndexRule.m_DefaultRule = true;
2019-04-26 19:36:49 +00:00
NewIndexRule.m_SkipEmpty = false;
2018-08-11 01:01:25 +00:00
NewIndexRule.m_SkipFull = false;
2014-09-27 08:11:28 +00:00
2015-02-19 23:15:09 +00:00
if(str_length(aOrientation1) > 0)
{
if(!str_comp(aOrientation1, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation1, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation1, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
if(str_length(aOrientation2) > 0)
{
if(!str_comp(aOrientation2, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation2, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation2, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
2015-02-19 23:15:09 +00:00
if(str_length(aOrientation3) > 0)
{
2015-02-19 23:15:09 +00:00
if(!str_comp(aOrientation3, "XFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation3, "YFLIP"))
NewIndexRule.m_Flag |= TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation3, "ROTATE"))
NewIndexRule.m_Flag |= TILEFLAG_ROTATE;
}
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
// add the index rule object and make it current
pCurrentRun->m_vIndexRules.push_back(NewIndexRule);
int IndexRuleID = pCurrentRun->m_vIndexRules.size() - 1;
pCurrentIndex = &pCurrentRun->m_vIndexRules[IndexRuleID];
2015-02-19 23:15:09 +00:00
}
else if(str_startswith(pLine, "Pos") && pCurrentIndex)
2015-02-19 23:15:09 +00:00
{
int x = 0, y = 0;
char aValue[128];
int Value = CPosRule::NORULE;
2022-06-15 17:34:41 +00:00
std::vector<CIndexInfo> vNewIndexList;
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue);
2015-02-19 21:54:47 +00:00
2015-02-19 23:15:09 +00:00
if(!str_comp(aValue, "EMPTY"))
{
Value = CPosRule::INDEX;
2018-08-09 21:45:04 +00:00
CIndexInfo NewIndexInfo = {0, 0, false};
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
}
else if(!str_comp(aValue, "FULL"))
{
Value = CPosRule::NOTINDEX;
2018-08-09 21:45:04 +00:00
CIndexInfo NewIndexInfo1 = {0, 0, false};
//CIndexInfo NewIndexInfo2 = {-1, 0};
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo1);
//vNewIndexList.push_back(NewIndexInfo2);
2015-02-19 23:15:09 +00:00
}
else if(!str_comp(aValue, "INDEX") || !str_comp(aValue, "NOTINDEX"))
{
if(!str_comp(aValue, "INDEX"))
Value = CPosRule::INDEX;
else
Value = CPosRule::NOTINDEX;
int pWord = 4;
while(true)
{
2015-02-19 23:15:09 +00:00
int ID = 0;
char aOrientation1[128] = "";
char aOrientation2[128] = "";
char aOrientation3[128] = "";
char aOrientation4[128] = "";
sscanf(str_trim_words(pLine, pWord), "%d %127s %127s %127s %127s", &ID, aOrientation1, aOrientation2, aOrientation3, aOrientation4);
CIndexInfo NewIndexInfo;
NewIndexInfo.m_ID = ID;
2018-08-09 21:45:04 +00:00
NewIndexInfo.m_Flag = 0;
NewIndexInfo.m_TestFlag = false;
2015-02-19 23:15:09 +00:00
if(!str_comp(aOrientation1, "OR"))
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
pWord += 2;
continue;
}
else if(str_length(aOrientation1) > 0)
{
2018-08-09 21:45:04 +00:00
NewIndexInfo.m_TestFlag = true;
2015-02-19 23:15:09 +00:00
if(!str_comp(aOrientation1, "XFLIP"))
NewIndexInfo.m_Flag = TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation1, "YFLIP"))
NewIndexInfo.m_Flag = TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation1, "ROTATE"))
2018-07-26 12:49:43 +00:00
NewIndexInfo.m_Flag = TILEFLAG_ROTATE;
2018-07-19 15:09:29 +00:00
else if(!str_comp(aOrientation1, "NONE"))
NewIndexInfo.m_Flag = 0;
2018-08-09 21:45:04 +00:00
else
NewIndexInfo.m_TestFlag = false;
}
else
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
break;
}
2015-02-19 21:54:47 +00:00
if(!str_comp(aOrientation2, "OR"))
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
pWord += 3;
continue;
}
else if(str_length(aOrientation2) > 0 && NewIndexInfo.m_Flag != 0)
{
2015-02-19 23:15:09 +00:00
if(!str_comp(aOrientation2, "XFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation2, "YFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation2, "ROTATE"))
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
}
else
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
break;
}
2015-02-19 21:54:47 +00:00
if(!str_comp(aOrientation3, "OR"))
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
pWord += 4;
continue;
}
else if(str_length(aOrientation3) > 0 && NewIndexInfo.m_Flag != 0)
{
2015-02-19 23:15:09 +00:00
if(!str_comp(aOrientation3, "XFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_XFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation3, "YFLIP"))
NewIndexInfo.m_Flag |= TILEFLAG_YFLIP;
2015-02-19 23:15:09 +00:00
else if(!str_comp(aOrientation3, "ROTATE"))
NewIndexInfo.m_Flag |= TILEFLAG_ROTATE;
}
else
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
break;
2015-02-19 21:54:47 +00:00
}
if(!str_comp(aOrientation4, "OR"))
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
pWord += 5;
continue;
}
else
{
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
2015-02-19 23:15:09 +00:00
break;
}
2015-02-19 21:54:47 +00:00
}
}
2015-02-19 23:15:09 +00:00
if(Value != CPosRule::NORULE)
{
2022-06-15 17:34:41 +00:00
CPosRule NewPosRule = {x, y, Value, vNewIndexList};
pCurrentIndex->m_vRules.push_back(NewPosRule);
2018-08-11 01:01:25 +00:00
2019-04-26 19:36:49 +00:00
pCurrentConf->m_StartX = minimum(pCurrentConf->m_StartX, NewPosRule.m_X);
pCurrentConf->m_StartY = minimum(pCurrentConf->m_StartY, NewPosRule.m_Y);
pCurrentConf->m_EndX = maximum(pCurrentConf->m_EndX, NewPosRule.m_X);
pCurrentConf->m_EndY = maximum(pCurrentConf->m_EndY, NewPosRule.m_Y);
if(x == 0 && y == 0)
{
2022-06-15 17:34:41 +00:00
for(const auto &Index : vNewIndexList)
2019-04-26 19:36:49 +00:00
{
if(Value == CPosRule::INDEX && Index.m_ID == 0)
2019-04-26 19:36:49 +00:00
pCurrentIndex->m_SkipFull = true;
else
pCurrentIndex->m_SkipEmpty = true;
}
2018-08-11 01:01:25 +00:00
}
}
}
else if(str_startswith(pLine, "Random") && pCurrentIndex)
2015-02-19 23:15:09 +00:00
{
float Value;
char Specifier = ' ';
sscanf(pLine, "Random %f%c", &Value, &Specifier);
if(Specifier == '%')
{
2019-07-08 21:08:42 +00:00
pCurrentIndex->m_RandomProbability = Value / 100.0f;
}
else
{
2019-07-08 21:08:42 +00:00
pCurrentIndex->m_RandomProbability = 1.0f / Value;
}
2015-02-19 23:15:09 +00:00
}
else if(str_startswith(pLine, "NoDefaultRule") && pCurrentIndex)
2015-02-19 23:15:09 +00:00
{
pCurrentIndex->m_DefaultRule = false;
}
else if(str_startswith(pLine, "NoLayerCopy") && pCurrentRun)
2018-07-19 15:09:29 +00:00
{
pCurrentRun->m_AutomapCopy = false;
}
}
}
2011-08-11 08:59:14 +00:00
2013-12-28 00:09:47 +00:00
// add default rule for Pos 0 0 if there is none
for(auto &Config : m_vConfigs)
2013-12-28 00:09:47 +00:00
{
for(auto &Run : Config.m_vRuns)
2013-12-28 00:09:47 +00:00
{
for(auto &IndexRule : Run.m_vIndexRules)
2013-12-28 00:09:47 +00:00
{
2015-02-19 23:15:09 +00:00
bool Found = false;
for(const auto &Rule : IndexRule.m_vRules)
2013-12-28 12:59:14 +00:00
{
if(Rule.m_X == 0 && Rule.m_Y == 0)
2015-02-19 23:15:09 +00:00
{
Found = true;
break;
}
}
if(!Found && IndexRule.m_DefaultRule)
2015-02-19 23:15:09 +00:00
{
2022-06-15 17:34:41 +00:00
std::vector<CIndexInfo> vNewIndexList;
2018-08-09 21:45:04 +00:00
CIndexInfo NewIndexInfo = {0, 0, false};
2022-06-15 17:34:41 +00:00
vNewIndexList.push_back(NewIndexInfo);
CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, vNewIndexList};
IndexRule.m_vRules.push_back(NewPosRule);
2019-04-26 19:36:49 +00:00
IndexRule.m_SkipEmpty = true;
IndexRule.m_SkipFull = false;
2019-04-26 19:36:49 +00:00
}
if(IndexRule.m_SkipEmpty && IndexRule.m_SkipFull)
2019-04-26 19:36:49 +00:00
{
IndexRule.m_SkipEmpty = false;
IndexRule.m_SkipFull = false;
2013-12-28 12:59:14 +00:00
}
2013-12-28 00:09:47 +00:00
}
}
}
io_close(RulesFile);
2011-08-11 08:59:14 +00:00
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor", aBuf);
2011-08-11 08:59:14 +00:00
m_FileLoaded = true;
}
const char *CAutoMapper::GetConfigName(int Index)
{
if(Index < 0 || Index >= (int)m_vConfigs.size())
return "";
return m_vConfigs[Index].m_aName;
}
void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed, int X, int Y, int Width, int Height)
{
if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_vConfigs.size())
return;
if(Width < 0)
Width = pLayer->m_Width;
if(Height < 0)
Height = pLayer->m_Height;
CConfiguration *pConf = &m_vConfigs[ConfigID];
2019-01-10 14:39:11 +00:00
int CommitFromX = clamp(X + pConf->m_StartX, 0, pLayer->m_Width);
int CommitFromY = clamp(Y + pConf->m_StartY, 0, pLayer->m_Height);
int CommitToX = clamp(X + Width + pConf->m_EndX, 0, pLayer->m_Width);
int CommitToY = clamp(Y + Height + pConf->m_EndY, 0, pLayer->m_Height);
int UpdateFromX = clamp(X + 3 * pConf->m_StartX, 0, pLayer->m_Width);
int UpdateFromY = clamp(Y + 3 * pConf->m_StartY, 0, pLayer->m_Height);
int UpdateToX = clamp(X + Width + 3 * pConf->m_EndX, 0, pLayer->m_Width);
int UpdateToY = clamp(Y + Height + 3 * pConf->m_EndY, 0, pLayer->m_Height);
CLayerTiles *pUpdateLayer = new CLayerTiles(UpdateToX - UpdateFromX, UpdateToY - UpdateFromY);
for(int y = UpdateFromY; y < UpdateToY; y++)
{
for(int x = UpdateFromX; x < UpdateToX; x++)
{
CTile *pIn = &pLayer->m_pTiles[y * pLayer->m_Width + x];
CTile *pOut = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
pOut->m_Index = pIn->m_Index;
pOut->m_Flags = pIn->m_Flags;
}
}
Proceed(pUpdateLayer, ConfigID, Seed, UpdateFromX, UpdateFromY);
for(int y = CommitFromY; y < CommitToY; y++)
{
for(int x = CommitFromX; x < CommitToX; x++)
{
CTile *pIn = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
CTile *pOut = &pLayer->m_pTiles[y * pLayer->m_Width + x];
pOut->m_Index = pIn->m_Index;
pOut->m_Flags = pIn->m_Flags;
}
}
delete pUpdateLayer;
}
void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedOffsetX, int SeedOffsetY)
{
if(!m_FileLoaded || pLayer->m_Readonly || ConfigID < 0 || ConfigID >= (int)m_vConfigs.size())
return;
2011-08-11 08:59:14 +00:00
if(Seed == 0)
Seed = rand();
CConfiguration *pConf = &m_vConfigs[ConfigID];
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
// for every run: copy tiles, automap, overwrite tiles
for(size_t h = 0; h < pConf->m_vRuns.size(); ++h)
{
CRun *pRun = &pConf->m_vRuns[h];
2013-12-28 00:09:47 +00:00
2018-07-26 16:26:12 +00:00
// don't make copy if it's requested
2018-07-26 16:59:29 +00:00
CLayerTiles *pReadLayer;
if(pRun->m_AutomapCopy)
2018-07-26 20:58:05 +00:00
{
2018-07-26 16:26:12 +00:00
pReadLayer = new CLayerTiles(pLayer->m_Width, pLayer->m_Height);
2013-12-28 00:09:47 +00:00
for(int y = 0; y < pLayer->m_Height; y++)
{
2018-07-26 16:26:12 +00:00
for(int x = 0; x < pLayer->m_Width; x++)
{
CTile *pIn = &pLayer->m_pTiles[y * pLayer->m_Width + x];
CTile *pOut = &pReadLayer->m_pTiles[y * pLayer->m_Width + x];
pOut->m_Index = pIn->m_Index;
pOut->m_Flags = pIn->m_Flags;
2018-07-26 16:26:12 +00:00
}
2015-02-19 23:15:09 +00:00
}
2013-12-28 00:09:47 +00:00
}
else
{
pReadLayer = pLayer;
}
2013-12-28 00:09:47 +00:00
2015-02-19 23:15:09 +00:00
// auto map
for(int y = 0; y < pLayer->m_Height; y++)
{
2015-02-19 23:15:09 +00:00
for(int x = 0; x < pLayer->m_Width; x++)
{
CTile *pTile = &(pLayer->m_pTiles[y * pLayer->m_Width + x]);
2015-02-19 23:15:09 +00:00
m_pEditor->m_Map.m_Modified = true;
2011-08-11 08:59:14 +00:00
for(size_t i = 0; i < pRun->m_vIndexRules.size(); ++i)
2015-02-19 23:15:09 +00:00
{
CIndexRule *pIndexRule = &pRun->m_vIndexRules[i];
2019-04-26 19:36:49 +00:00
if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles
continue;
if(pIndexRule->m_SkipFull && pTile->m_Index != 0) // skip full tiles
2018-08-11 01:01:25 +00:00
continue;
2015-02-19 23:15:09 +00:00
bool RespectRules = true;
for(size_t j = 0; j < pIndexRule->m_vRules.size() && RespectRules; ++j)
{
CPosRule *pRule = &pIndexRule->m_vRules[j];
int CheckIndex, CheckFlags;
int CheckX = x + pRule->m_X;
int CheckY = y + pRule->m_Y;
if(CheckX >= 0 && CheckX < pLayer->m_Width && CheckY >= 0 && CheckY < pLayer->m_Height)
{
int CheckTile = CheckY * pLayer->m_Width + CheckX;
2018-07-26 20:58:05 +00:00
CheckIndex = pReadLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_XFLIP | TILEFLAG_YFLIP);
}
else
{
CheckIndex = -1;
CheckFlags = 0;
}
2015-07-09 00:08:14 +00:00
if(pRule->m_Value == CPosRule::INDEX)
2015-02-19 21:54:47 +00:00
{
2018-07-27 05:51:16 +00:00
RespectRules = false;
Declare variables as `const` when possible According to cppcheck's `constVariable` error: ``` src\engine\client\backend\opengl\opengl_sl.cpp:74:43: style: Variable 'Define' can be declared as reference to const [constVariable] for(CGLSLCompiler::SGLSLCompilerDefine &Define : pCompiler->m_vDefines) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:2149:12: style: Variable 'GraphicThreadCommandBuffer' can be declared as reference to const [constVariable] auto &GraphicThreadCommandBuffer = m_vvThreadDrawCommandBuffers[i + 1][m_CurImageIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3192:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3200:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[State.m_Texture].m_VKStandard3DTexturedDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3810:13: style: Variable 'Mode' can be declared as reference to const [constVariable] for(auto &Mode : vPresentModeList) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3818:13: style: Variable 'Mode' can be declared as reference to const [constVariable] for(auto &Mode : vPresentModeList) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6511:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6555:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_VKStandard3DTexturedDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6660:9: style: Variable 'MemBlock' can be declared as reference to const [constVariable] auto &MemBlock = m_vBufferObjects[BufferIndex].m_BufferObject.m_Mem; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6799:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6808:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6902:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6907:9: style: Variable 'TextTextureDescr' can be declared as reference to const [constVariable] auto &TextTextureDescr = m_vTextures[pCommand->m_TextTextureIndex].m_VKTextDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6961:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6970:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\game\client\components\hud.cpp:178:8: style: Variable 'aFlagCarrier' can be declared as const array [constVariable] int aFlagCarrier[2] = { ^ src\game\client\components\hud.cpp:519:16: style: Variable 's_aTextWidth' can be declared as const array [constVariable] static float s_aTextWidth[5] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000}; ^ src\game\client\components\killmessages.cpp:305:30: style: Variable 'Client' can be declared as reference to const [constVariable] CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_KillerID]; ^ src\game\client\components\killmessages.cpp:314:30: style: Variable 'Client' can be declared as reference to const [constVariable] CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_VictimID]; ^ src\game\client\components\menus_ingame.cpp:243:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable] for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName) ^ src\game\client\components\menus_ingame.cpp:530:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable] for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName) ^ src\game\client\components\players.cpp:767:44: style: Variable 'CharacterInfo' can be declared as reference to const [constVariable] CGameClient::CSnapState::CCharacterInfo &CharacterInfo = m_pClient->m_Snap.m_aCharacters[i]; ^ src\game\client\components\spectator.cpp:122:27: style: Variable 'Snap' can be declared as reference to const [constVariable] CGameClient::CSnapState &Snap = pSelf->m_pClient->m_Snap; ^ src\game\client\components\spectator.cpp:221:12: style: Variable 'pInfo' can be declared as reference to const [constVariable] for(auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName) ^ src\game\client\gameclient.cpp:2220:15: style: Variable 'OwnClientData' can be declared as reference to const [constVariable] CClientData &OwnClientData = m_aClients[ownID]; ^ src\game\client\gameclient.cpp:2227:16: style: Variable 'cData' can be declared as reference to const [constVariable] CClientData &cData = m_aClients[i]; ^ src\game\client\prediction\entities\character.cpp:397:11: style: Variable 'aSpreading' can be declared as const array [constVariable] float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; ^ src\game\client\prediction\entities\laser.cpp:53:9: style: Variable 'HitPos' can be declared as reference to const [constVariable] vec2 &HitPos = pHit->Core()->m_Pos; ^ src\game\editor\auto_map.cpp:507:18: style: Variable 'Index' can be declared as reference to const [constVariable] for(auto &Index : pRule->m_vIndexList) ^ src\game\editor\auto_map.cpp:518:18: style: Variable 'Index' can be declared as reference to const [constVariable] for(auto &Index : pRule->m_vIndexList) ^ src\game\editor\editor.cpp:118:12: style: Variable 'Item' can be declared as reference to const [constVariable] for(auto &Item : vList) ^ src\game\editor\editor.cpp:2983:11: style: Variable 'aAspects' can be declared as const array [constVariable] float aAspects[] = {4.0f / 3.0f, 16.0f / 10.0f, 5.0f / 4.0f, 16.0f / 9.0f}; ^ src\game\editor\editor.cpp:3141:15: style: Variable 's_aShift' can be declared as const array [constVariable] static int s_aShift[] = {24, 16, 8, 0}; ^ src\engine\server\server.cpp:2807:14: style: Variable 'Client' can be declared as reference to const [constVariable] for(auto &Client : m_aClients) ^ src\engine\server\sql_string_helpers.cpp:51:6: style: Variable 'aTimes' can be declared as const array [constVariable] int aTimes[7] = ^ src\test\secure_random.cpp:24:6: style: Variable 'BOUNDS' can be declared as const array [constVariable] int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129}; ^ ```
2022-11-13 15:29:13 +00:00
for(const auto &Index : pRule->m_vIndexList)
{
if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag))
2018-07-27 05:51:16 +00:00
{
RespectRules = true;
break;
}
2015-02-19 23:15:09 +00:00
}
}
else if(pRule->m_Value == CPosRule::NOTINDEX)
{
Declare variables as `const` when possible According to cppcheck's `constVariable` error: ``` src\engine\client\backend\opengl\opengl_sl.cpp:74:43: style: Variable 'Define' can be declared as reference to const [constVariable] for(CGLSLCompiler::SGLSLCompilerDefine &Define : pCompiler->m_vDefines) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:2149:12: style: Variable 'GraphicThreadCommandBuffer' can be declared as reference to const [constVariable] auto &GraphicThreadCommandBuffer = m_vvThreadDrawCommandBuffers[i + 1][m_CurImageIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3192:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3200:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[State.m_Texture].m_VKStandard3DTexturedDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3810:13: style: Variable 'Mode' can be declared as reference to const [constVariable] for(auto &Mode : vPresentModeList) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:3818:13: style: Variable 'Mode' can be declared as reference to const [constVariable] for(auto &Mode : vPresentModeList) ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6511:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6555:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_VKStandard3DTexturedDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6660:9: style: Variable 'MemBlock' can be declared as reference to const [constVariable] auto &MemBlock = m_vBufferObjects[BufferIndex].m_BufferObject.m_Mem; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6799:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6808:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[pCommand->m_State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6902:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6907:9: style: Variable 'TextTextureDescr' can be declared as reference to const [constVariable] auto &TextTextureDescr = m_vTextures[pCommand->m_TextTextureIndex].m_VKTextDescrSet; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6961:9: style: Variable 'BufferObject' can be declared as reference to const [constVariable] auto &BufferObject = m_vBufferObjects[BufferObjectIndex]; ^ src\engine\client\backend\vulkan\backend_vulkan.cpp:6970:10: style: Variable 'DescrSet' can be declared as reference to const [constVariable] auto &DescrSet = m_vTextures[State.m_Texture].m_aVKStandardTexturedDescrSets[AddressModeIndex]; ^ src\game\client\components\hud.cpp:178:8: style: Variable 'aFlagCarrier' can be declared as const array [constVariable] int aFlagCarrier[2] = { ^ src\game\client\components\hud.cpp:519:16: style: Variable 's_aTextWidth' can be declared as const array [constVariable] static float s_aTextWidth[5] = {s_TextWidth0, s_TextWidth00, s_TextWidth000, s_TextWidth0000, s_TextWidth00000}; ^ src\game\client\components\killmessages.cpp:305:30: style: Variable 'Client' can be declared as reference to const [constVariable] CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_KillerID]; ^ src\game\client\components\killmessages.cpp:314:30: style: Variable 'Client' can be declared as reference to const [constVariable] CGameClient::CClientData &Client = GameClient()->m_aClients[m_aKillmsgs[r].m_VictimID]; ^ src\game\client\components\menus_ingame.cpp:243:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable] for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName) ^ src\game\client\components\menus_ingame.cpp:530:12: style: Variable 'pInfoByName' can be declared as reference to const [constVariable] for(auto &pInfoByName : m_pClient->m_Snap.m_apInfoByName) ^ src\game\client\components\players.cpp:767:44: style: Variable 'CharacterInfo' can be declared as reference to const [constVariable] CGameClient::CSnapState::CCharacterInfo &CharacterInfo = m_pClient->m_Snap.m_aCharacters[i]; ^ src\game\client\components\spectator.cpp:122:27: style: Variable 'Snap' can be declared as reference to const [constVariable] CGameClient::CSnapState &Snap = pSelf->m_pClient->m_Snap; ^ src\game\client\components\spectator.cpp:221:12: style: Variable 'pInfo' can be declared as reference to const [constVariable] for(auto &pInfo : m_pClient->m_Snap.m_apInfoByDDTeamName) ^ src\game\client\gameclient.cpp:2220:15: style: Variable 'OwnClientData' can be declared as reference to const [constVariable] CClientData &OwnClientData = m_aClients[ownID]; ^ src\game\client\gameclient.cpp:2227:16: style: Variable 'cData' can be declared as reference to const [constVariable] CClientData &cData = m_aClients[i]; ^ src\game\client\prediction\entities\character.cpp:397:11: style: Variable 'aSpreading' can be declared as const array [constVariable] float aSpreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; ^ src\game\client\prediction\entities\laser.cpp:53:9: style: Variable 'HitPos' can be declared as reference to const [constVariable] vec2 &HitPos = pHit->Core()->m_Pos; ^ src\game\editor\auto_map.cpp:507:18: style: Variable 'Index' can be declared as reference to const [constVariable] for(auto &Index : pRule->m_vIndexList) ^ src\game\editor\auto_map.cpp:518:18: style: Variable 'Index' can be declared as reference to const [constVariable] for(auto &Index : pRule->m_vIndexList) ^ src\game\editor\editor.cpp:118:12: style: Variable 'Item' can be declared as reference to const [constVariable] for(auto &Item : vList) ^ src\game\editor\editor.cpp:2983:11: style: Variable 'aAspects' can be declared as const array [constVariable] float aAspects[] = {4.0f / 3.0f, 16.0f / 10.0f, 5.0f / 4.0f, 16.0f / 9.0f}; ^ src\game\editor\editor.cpp:3141:15: style: Variable 's_aShift' can be declared as const array [constVariable] static int s_aShift[] = {24, 16, 8, 0}; ^ src\engine\server\server.cpp:2807:14: style: Variable 'Client' can be declared as reference to const [constVariable] for(auto &Client : m_aClients) ^ src\engine\server\sql_string_helpers.cpp:51:6: style: Variable 'aTimes' can be declared as const array [constVariable] int aTimes[7] = ^ src\test\secure_random.cpp:24:6: style: Variable 'BOUNDS' can be declared as const array [constVariable] int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129}; ^ ```
2022-11-13 15:29:13 +00:00
for(const auto &Index : pRule->m_vIndexList)
{
if(CheckIndex == Index.m_ID && (!Index.m_TestFlag || CheckFlags == Index.m_Flag))
2018-07-27 05:51:16 +00:00
{
RespectRules = false;
break;
}
2015-02-19 21:54:47 +00:00
}
}
}
2011-08-11 08:59:14 +00:00
2015-02-19 23:15:09 +00:00
if(RespectRules &&
2019-07-08 21:08:42 +00:00
(pIndexRule->m_RandomProbability >= 1.0f || HashLocation(Seed, h, i, x + SeedOffsetX, y + SeedOffsetY) < HASH_MAX * pIndexRule->m_RandomProbability))
2015-02-19 23:15:09 +00:00
{
2019-04-26 19:36:49 +00:00
pTile->m_Index = pIndexRule->m_ID;
2018-08-11 01:01:25 +00:00
pTile->m_Flags = pIndexRule->m_Flag;
2015-02-19 23:15:09 +00:00
}
}
}
2013-12-28 00:09:47 +00:00
}
2018-07-26 16:26:12 +00:00
// clean-up
if(pRun->m_AutomapCopy && pReadLayer != pLayer)
2018-07-26 16:26:12 +00:00
delete pReadLayer;
2015-02-19 23:15:09 +00:00
}
}