Skip to content

Commit

Permalink
WIP on adding a guide layer to automaps
Browse files Browse the repository at this point in the history
hotfix

Much cleaner hotfix

Compile error fixes, to be squashed

Error fixes to be squashed 2: electric boogaloo

check_style fix to be squashed
  • Loading branch information
VoxelDoesCode committed Jan 27, 2025
1 parent 510a1f7 commit 11eedbb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 31 deletions.
66 changes: 40 additions & 26 deletions src/game/editor/auto_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ void CAutoMapper::Load(const char *pTileName)
int IndexRuleId = pCurrentRun->m_vIndexRules.size() - 1;
pCurrentIndex = &pCurrentRun->m_vIndexRules[IndexRuleId];
}
else if(str_startswith(pLine, "Pos") && pCurrentIndex)
else if((str_startswith(pLine, "Pos") || str_startswith(pLine, "Guide")) && pCurrentIndex)
{
int x = 0, y = 0;
char aValue[128];
int Value = CPosRule::NORULE;
std::vector<CIndexInfo> vNewIndexList;
bool IsGuide = str_startswith(pLine, "Guide");

sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue);
if(IsGuide)
sscanf(pLine, "Guide %d %d %127s", &x, &y, aValue);
else
sscanf(pLine, "Pos %d %d %127s", &x, &y, aValue);

if(!str_comp(aValue, "EMPTY"))
{
Expand Down Expand Up @@ -281,7 +285,7 @@ void CAutoMapper::Load(const char *pTileName)

if(Value != CPosRule::NORULE)
{
CPosRule NewPosRule = {x, y, Value, vNewIndexList};
CPosRule NewPosRule = {x, y, Value, vNewIndexList, IsGuide};
pCurrentIndex->m_vRules.push_back(NewPosRule);

pCurrentConf->m_StartX = minimum(pCurrentConf->m_StartX, NewPosRule.m_X);
Expand Down Expand Up @@ -327,8 +331,10 @@ void CAutoMapper::Load(const char *pTileName)
{
int ModX = 0, ModY = 0, OffsetX = 0, OffsetY = 0;
sscanf(pLine, "Modulo %d %d %d %d", &ModX, &ModY, &OffsetX, &OffsetY);
if(ModX == 0) ModX = 1;
if(ModY == 0) ModY = 1;
if(ModX == 0)
ModX = 1;
if(ModY == 0)
ModY = 1;
CModuloRule NewModuloRule = {ModX, ModY, OffsetX, OffsetY};
pCurrentIndex->m_vModuloRules.push_back(NewModuloRule);
}
Expand Down Expand Up @@ -406,7 +412,7 @@ const char *CAutoMapper::GetConfigName(int Index)
return m_vConfigs[Index].m_aName;
}

void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, class CLayerTiles *pGameLayer, int ReferenceId, int ConfigId, int Seed, int X, int Y, int Width, int Height)
void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, CLayerTiles *pGameLayer, CLayerTiles *pGuideLayer, int ReferenceId, 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;
Expand Down Expand Up @@ -442,7 +448,7 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, class CLayerTiles *pGame
}
}

Proceed(pUpdateLayer, pGameLayer, ReferenceId, ConfigId, Seed, UpdateFromX, UpdateFromY);
Proceed(pUpdateLayer, pGameLayer, pGuideLayer, ReferenceId, ConfigId, Seed, UpdateFromX, UpdateFromY);

for(int y = CommitFromY; y < CommitToY; y++)
{
Expand All @@ -460,7 +466,7 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, class CLayerTiles *pGame
delete pUpdateLayer;
}

void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int ReferenceId, int ConfigId, int Seed, int SeedOffsetX, int SeedOffsetY)
void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, CLayerTiles *pGuideLayer, int ReferenceId, int ConfigId, int Seed, int SeedOffsetX, int SeedOffsetY)
{
if(!m_FileLoaded || pLayer->m_Readonly || ConfigId < 0 || ConfigId >= (int)m_vConfigs.size())
return;
Expand All @@ -471,8 +477,8 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int Refe
CConfiguration *pConf = &m_vConfigs[ConfigId];
pLayer->ClearHistory();

int layerWidth = pLayer->m_Width;
int layerHeight = pLayer->m_Height;
int LayerWidth = pLayer->m_Width;
int LayerHeight = pLayer->m_Height;

static const int s_aTileIndex[6] = {TILE_SOLID, TILE_DEATH, TILE_NOHOOK, TILE_THROUGH_CUT, TILE_FREEZE, TILE_UNFREEZE};

Expand All @@ -487,14 +493,14 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int Refe
CLayerTiles *pBuffer = IsFilterable ? pGameLayer : pLayer;
if(pRun->m_AutomapCopy)
{
pReadLayer = new CLayerTiles(Editor(), layerWidth, layerHeight);
pReadLayer = new CLayerTiles(Editor(), LayerWidth, LayerHeight);

for(int y = 0; y < layerHeight; y++)
for(int y = 0; y < LayerHeight; y++)
{
for(int x = 0; x < layerWidth; x++)
for(int x = 0; x < LayerWidth; x++)
{
CTile *pIn = &pBuffer->m_pTiles[y * layerWidth + x];
CTile *pOut = &pReadLayer->m_pTiles[y * layerWidth + x];
CTile *pIn = &pBuffer->m_pTiles[y * LayerWidth + x];
CTile *pOut = &pReadLayer->m_pTiles[y * LayerWidth + x];
if(h == 0 && ReferenceId >= 1 && pIn->m_Index != s_aTileIndex[ReferenceId - 1])
pOut->m_Index = 0;
else
Expand All @@ -509,12 +515,12 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int Refe
}

// auto map
for(int y = 0; y < layerHeight; y++)
for(int y = 0; y < LayerHeight; y++)
{
for(int x = 0; x < layerWidth; x++)
for(int x = 0; x < LayerWidth; x++)
{
CTile *pTile = &(pLayer->m_pTiles[y * layerWidth + x]);
const CTile *pReadTile = &(pReadLayer->m_pTiles[y * layerWidth + x]);
CTile *pTile = &(pLayer->m_pTiles[y * LayerWidth + x]);
const CTile *pReadTile = &(pReadLayer->m_pTiles[y * LayerWidth + x]);
Editor()->m_Map.OnModify();

for(size_t i = 0; i < pRun->m_vIndexRules.size(); ++i)
Expand Down Expand Up @@ -545,11 +551,19 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int Refe
int CheckIndex, CheckFlags;
int CheckX = x + pRule->m_X;
int CheckY = y + pRule->m_Y;
if(CheckX >= 0 && CheckX < layerWidth && CheckY >= 0 && CheckY < layerHeight)
if(CheckX >= 0 && CheckX < LayerWidth && CheckY >= 0 && CheckY < LayerHeight)
{
int CheckTile = CheckY * layerWidth + CheckX;
CheckIndex = pReadLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_XFLIP | TILEFLAG_YFLIP);
int CheckTile = CheckY * LayerWidth + CheckX;
if(pRule->m_IsGuide)
{
CheckIndex = pGuideLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pGuideLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_XFLIP | TILEFLAG_YFLIP);
}
else
{
CheckIndex = pReadLayer->m_pTiles[CheckTile].m_Index;
CheckFlags = pReadLayer->m_pTiles[CheckTile].m_Flags & (TILEFLAG_ROTATE | TILEFLAG_XFLIP | TILEFLAG_YFLIP);
}
}
else
{
Expand Down Expand Up @@ -582,17 +596,17 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, CLayerTiles *pGameLayer, int Refe
}
}

bool RespectModulo = pIndexRule->m_vModuloRules.size() == 0;
bool PassesModuloCheck = pIndexRule->m_vModuloRules.empty();
for(size_t k = 0; k < pIndexRule->m_vModuloRules.size() && RespectRules; ++k)
{
CModuloRule *pModuloRule = &pIndexRule->m_vModuloRules[k];
if((x + pModuloRule->m_OffsetX) % pModuloRule->m_ModX == 0 && (y + pModuloRule->m_OffsetY) % pModuloRule->m_ModY == 0)
{
RespectModulo = true;
PassesModuloCheck = true;
}
}

if(RespectRules && RespectModulo &&
if(RespectRules && PassesModuloCheck &&
(pIndexRule->m_RandomProbability >= 1.0f || HashLocation(Seed, h, i, x + SeedOffsetX, y + SeedOffsetY) < HASH_MAX * pIndexRule->m_RandomProbability))
{
CTile Previous = *pTile;
Expand Down
5 changes: 3 additions & 2 deletions src/game/editor/auto_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CAutoMapper : public CEditorComponent
int m_Y;
int m_Value;
std::vector<CIndexInfo> m_vIndexList;
bool m_IsGuide;

enum
{
Expand Down Expand Up @@ -68,8 +69,8 @@ class CAutoMapper : public CEditorComponent
explicit CAutoMapper(CEditor *pEditor);

void Load(const char *pTileName);
void ProceedLocalized(class CLayerTiles *pLayer, class CLayerTiles *pGameLayer, int ReferenceId, int ConfigId, int Seed = 0, int X = 0, int Y = 0, int Width = -1, int Height = -1);
void Proceed(class CLayerTiles *pLayer, class CLayerTiles *pGameLayer, int ReferenceId, int ConfigId, int Seed = 0, int SeedOffsetX = 0, int SeedOffsetY = 0);
void ProceedLocalized(class CLayerTiles *pLayer, class CLayerTiles *pGameLayer, class CLayerTiles *pGuideLayer, int ReferenceId, int ConfigId, int Seed = 0, int X = 0, int Y = 0, int Width = -1, int Height = -1);
void Proceed(class CLayerTiles *pLayer, class CLayerTiles *pGameLayer, class CLayerTiles *pGuideLayer, int ReferenceId, int ConfigId, int Seed = 0, int SeedOffsetX = 0, int SeedOffsetY = 0);
int ConfigNamesNum() const { return m_vConfigs.size(); }
const char *GetConfigName(int Index);

Expand Down
4 changes: 2 additions & 2 deletions src/game/editor/mapitems/layer_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ CUi::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox)
static int s_AutoMapperButton = 0;
if(m_pEditor->DoButton_Editor(&s_AutoMapperButton, "Automap", 0, &Button, 0, "Run the automapper"))
{
m_pEditor->m_Map.m_vpImages[m_Image]->m_AutoMapper.Proceed(this, m_pEditor->m_Map.m_pGameLayer.get(), m_AutoMapperReference, m_AutoMapperConfig, m_Seed);
m_pEditor->m_Map.m_vpImages[m_Image]->m_AutoMapper.Proceed(this, m_pEditor->m_Map.m_pGameLayer.get(), m_pEditor->m_Map.m_pGameLayer.get(), m_AutoMapperReference, m_AutoMapperConfig, m_Seed);
// record undo
m_pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionTileChanges>(m_pEditor, m_pEditor->m_SelectedGroup, m_pEditor->m_vSelectedLayers[0], "Auto map", m_TilesHistory));
ClearHistory();
Expand Down Expand Up @@ -1294,7 +1294,7 @@ void CLayerTiles::FlagModified(int x, int y, int w, int h)
m_pEditor->m_Map.OnModify();
if(m_Seed != 0 && m_AutoMapperConfig != -1 && m_AutoAutoMap && m_Image >= 0)
{
m_pEditor->m_Map.m_vpImages[m_Image]->m_AutoMapper.ProceedLocalized(this, m_pEditor->m_Map.m_pGameLayer.get(), m_AutoMapperReference, m_AutoMapperConfig, m_Seed, x, y, w, h);
m_pEditor->m_Map.m_vpImages[m_Image]->m_AutoMapper.ProceedLocalized(this, m_pEditor->m_Map.m_pGameLayer.get(), m_pEditor->m_Map.m_pGameLayer.get(), m_AutoMapperReference, m_AutoMapperConfig, m_Seed, x, y, w, h);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/editor/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ CUi::EPopupMenuFunctionResult CEditor::PopupSelectAutoMapReference(void *pContex
s_ListBox.DoStart(ButtonHeight, std::size(s_apAutoMapReferenceButtonNames) + 1, 1, 4, s_AutoMapReferenceCurrent + 1, &View, false);
s_ListBox.DoAutoSpacing(ButtonMargin);

for(int i = 0; i < std::size(s_apAutoMapReferenceButtonNames) + 1; i++)
for(int i = 0; i < static_cast<int>(std::size(s_apAutoMapReferenceButtonNames)) + 1; i++)
{
static int s_NoneButton = 0;
CListboxItem Item = s_ListBox.DoNextItem(i == 0 ? (void *)&s_NoneButton : s_apAutoMapReferenceButtonNames[i - 1], (i - 1) == s_AutoMapReferenceCurrent, 3.0f);
Expand Down

0 comments on commit 11eedbb

Please sign in to comment.