Compare commits

..

1 commit

Author SHA1 Message Date
Robert Müller 68ae1afa18
Merge fe2f73b518 into b5d662622c 2024-09-09 23:18:13 +03:00
5 changed files with 21 additions and 55 deletions

View file

@ -300,7 +300,7 @@ void CGraphics_Threaded::UnloadTexture(CTextureHandle *pIndex)
FreeTextureIndex(pIndex); FreeTextureIndex(pIndex);
} }
bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage) static bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage)
{ {
if(SrcImage.m_Format == CImageInfo::FORMAT_RGBA) if(SrcImage.m_Format == CImageInfo::FORMAT_RGBA)
{ {

View file

@ -124,8 +124,6 @@ public:
} }
}; };
bool ConvertToRGBA(uint8_t *pDest, const CImageInfo &SrcImage);
/* /*
Structure: CVideoMode Structure: CVideoMode
*/ */

View file

@ -70,18 +70,18 @@ void CEcon::Init(CConfig *pConfig, IConsole *pConsole, CNetBan *pNetBan)
} }
NETADDR BindAddr; NETADDR BindAddr;
if(g_Config.m_EcBindaddr[0] && net_host_lookup(g_Config.m_EcBindaddr, &BindAddr, NETTYPE_ALL) == 0) if(g_Config.m_EcBindaddr[0] == '\0')
{ {
// got bindaddr mem_zero(&BindAddr, sizeof(BindAddr));
BindAddr.port = g_Config.m_EcPort;
} }
else else if(net_host_lookup(g_Config.m_EcBindaddr, &BindAddr, NETTYPE_ALL) != 0)
{ {
char aBuf[256]; char aBuf[256];
str_format(aBuf, sizeof(aBuf), "The configured bindaddr '%s' cannot be resolved.", g_Config.m_EcBindaddr); str_format(aBuf, sizeof(aBuf), "The configured bindaddr '%s' cannot be resolved.", g_Config.m_Bindaddr);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf);
return;
} }
BindAddr.type = NETTYPE_ALL;
BindAddr.port = g_Config.m_EcPort;
if(m_NetConsole.Open(BindAddr, pNetBan)) if(m_NetConsole.Open(BindAddr, pNetBan))
{ {

View file

@ -4384,7 +4384,7 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup
} }
} }
CImageInfo ImgInfo; CEditorImage ImgInfo(this);
if(!Graphics()->LoadPng(ImgInfo, pFileName, StorageType)) if(!Graphics()->LoadPng(ImgInfo, pFileName, StorageType))
{ {
ShowFileDialogError("Failed to load image from file '%s'.", pFileName); ShowFileDialogError("Failed to load image from file '%s'.", pFileName);
@ -4394,33 +4394,21 @@ bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDup
std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage]; std::shared_ptr<CEditorImage> pImg = m_Map.m_vpImages[m_SelectedImage];
Graphics()->UnloadTexture(&(pImg->m_Texture)); Graphics()->UnloadTexture(&(pImg->m_Texture));
pImg->Free(); pImg->Free();
pImg->m_Width = ImgInfo.m_Width; *pImg = ImgInfo;
pImg->m_Height = ImgInfo.m_Height;
pImg->m_Format = ImgInfo.m_Format;
pImg->m_pData = ImgInfo.m_pData;
str_copy(pImg->m_aName, aBuf); str_copy(pImg->m_aName, aBuf);
pImg->m_External = IsVanillaImage(pImg->m_aName); pImg->m_External = IsVanillaImage(pImg->m_aName);
if(!pImg->m_External && pImg->m_Format != CImageInfo::FORMAT_RGBA) if(!pImg->m_External && g_Config.m_ClEditorDilate == 1 && pImg->m_Format == CImageInfo::FORMAT_RGBA)
{ {
uint8_t *pRgbaData = static_cast<uint8_t *>(malloc((size_t)pImg->m_Width * pImg->m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); DilateImage(ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height);
ConvertToRGBA(pRgbaData, *pImg);
free(pImg->m_pData);
pImg->m_pData = pRgbaData;
pImg->m_Format = CImageInfo::FORMAT_RGBA;
}
if(!pImg->m_External && g_Config.m_ClEditorDilate == 1)
{
DilateImage(pImg->m_pData, pImg->m_Width, pImg->m_Height);
} }
pImg->m_AutoMapper.Load(pImg->m_aName); pImg->m_AutoMapper.Load(pImg->m_aName);
int TextureLoadFlag = Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; int TextureLoadFlag = Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0) if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0)
TextureLoadFlag = 0; TextureLoadFlag = 0;
pImg->m_Texture = Graphics()->LoadTextureRaw(*pImg, TextureLoadFlag, pFileName); pImg->m_Texture = Graphics()->LoadTextureRaw(ImgInfo, TextureLoadFlag, pFileName);
ImgInfo.m_pData = nullptr;
SortImages(); SortImages();
for(size_t i = 0; i < m_Map.m_vpImages.size(); ++i) for(size_t i = 0; i < m_Map.m_vpImages.size(); ++i)
{ {
@ -4459,7 +4447,7 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser)
return false; return false;
} }
CImageInfo ImgInfo; CEditorImage ImgInfo(pEditor);
if(!pEditor->Graphics()->LoadPng(ImgInfo, pFileName, StorageType)) if(!pEditor->Graphics()->LoadPng(ImgInfo, pFileName, StorageType))
{ {
pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFileName); pEditor->ShowFileDialogError("Failed to load image from file '%s'.", pFileName);
@ -4467,30 +4455,19 @@ bool CEditor::AddImage(const char *pFileName, int StorageType, void *pUser)
} }
std::shared_ptr<CEditorImage> pImg = std::make_shared<CEditorImage>(pEditor); std::shared_ptr<CEditorImage> pImg = std::make_shared<CEditorImage>(pEditor);
pImg->m_Width = ImgInfo.m_Width; *pImg = ImgInfo;
pImg->m_Height = ImgInfo.m_Height;
pImg->m_Format = ImgInfo.m_Format;
pImg->m_pData = ImgInfo.m_pData;
pImg->m_External = IsVanillaImage(aBuf); pImg->m_External = IsVanillaImage(aBuf);
if(pImg->m_Format != CImageInfo::FORMAT_RGBA) if(!pImg->m_External && g_Config.m_ClEditorDilate == 1 && pImg->m_Format == CImageInfo::FORMAT_RGBA)
{ {
uint8_t *pRgbaData = static_cast<uint8_t *>(malloc((size_t)pImg->m_Width * pImg->m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA))); DilateImage(ImgInfo.m_pData, ImgInfo.m_Width, ImgInfo.m_Height);
ConvertToRGBA(pRgbaData, *pImg);
free(pImg->m_pData);
pImg->m_pData = pRgbaData;
pImg->m_Format = CImageInfo::FORMAT_RGBA;
}
if(!pImg->m_External && g_Config.m_ClEditorDilate == 1)
{
DilateImage(pImg->m_pData, pImg->m_Width, pImg->m_Height);
} }
int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; int TextureLoadFlag = pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
if(pImg->m_Width % 16 != 0 || pImg->m_Height % 16 != 0) if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0)
TextureLoadFlag = 0; TextureLoadFlag = 0;
pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(*pImg, TextureLoadFlag, pFileName); pImg->m_Texture = pEditor->Graphics()->LoadTextureRaw(ImgInfo, TextureLoadFlag, pFileName);
ImgInfo.m_pData = nullptr;
str_copy(pImg->m_aName, aBuf); str_copy(pImg->m_aName, aBuf);
pImg->m_AutoMapper.Load(pImg->m_aName); pImg->m_AutoMapper.Load(pImg->m_aName);
pEditor->m_Map.m_vpImages.push_back(pImg); pEditor->m_Map.m_vpImages.push_back(pImg);

View file

@ -509,15 +509,6 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio
pImg->m_Height = ImgInfo.m_Height; pImg->m_Height = ImgInfo.m_Height;
pImg->m_Format = ImgInfo.m_Format; pImg->m_Format = ImgInfo.m_Format;
pImg->m_pData = ImgInfo.m_pData; pImg->m_pData = ImgInfo.m_pData;
if(pImg->m_Format != CImageInfo::FORMAT_RGBA)
{
uint8_t *pRgbaData = static_cast<uint8_t *>(malloc((size_t)pImg->m_Width * pImg->m_Height * CImageInfo::PixelSize(CImageInfo::FORMAT_RGBA)));
ConvertToRGBA(pRgbaData, *pImg);
free(pImg->m_pData);
pImg->m_pData = pRgbaData;
pImg->m_Format = CImageInfo::FORMAT_RGBA;
}
int TextureLoadFlag = m_pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; int TextureLoadFlag = m_pEditor->Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0) if(ImgInfo.m_Width % 16 != 0 || ImgInfo.m_Height % 16 != 0)
TextureLoadFlag = 0; TextureLoadFlag = 0;