generally transplanted FA2sp image handling logic, but still WIP

TODO: Fix palette background issue. Fix voxel handling .
This commit is contained in:
Zero Fanker 2024-05-18 21:19:01 -04:00
parent 981059c2b4
commit 800cd951b6
17 changed files with 1058 additions and 1163 deletions

View file

@ -27,6 +27,15 @@ public:
CString GetStringOr(const CString& section, const CString& key, const CString& def) const;
IniSectionGroup GetSection(const CString& section) const;
bool GetBool(const CString& pSection, const CString& pKey, bool def = false) const
{
return INIHelper::StringToBool(GetString(pSection, pKey), def);
}
int GetInteger(const CString& pSection, const CString& pKey, int def = 0) const
{
return INIHelper::StringToInteger(GetString(pSection, pKey), def);
}
auto Size() const { return m_group.size(); }
void Append(const CIniFile& INI);

View file

@ -19,7 +19,7 @@ private:
};
IniFileGroup IniMegaFile::GetRules()
inline IniFileGroup IniMegaFile::GetRules()
{
IniFileGroup m_group;
m_group.Append(rules);
@ -27,7 +27,7 @@ IniFileGroup IniMegaFile::GetRules()
return m_group;
}
bool IniMegaFile::isNullOrEmpty(const CString& value)
inline bool IniMegaFile::isNullOrEmpty(const CString& value)
{
return !value.GetLength() || value == "none" || value == "<none>";
}

View file

@ -547,7 +547,7 @@ inline void CalculateHouseColorPalette(int house_pal[houseColorRelMax + 1], cons
/*
There is no need for newpal
*/
__forceinline void BlitPic(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, int* newPal = NULL)//BYTE* src, int swidth, int sheight)
__forceinline void BlitPic(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, const int* newPal = NULL)//BYTE* src, int swidth, int sheight)
{
ASSERT(pd.bType != PICDATA_TYPE_BMP);
@ -650,7 +650,7 @@ __forceinline void BlitPic(void* dst, int x, int y, int dleft, int dtop, int dpi
}
}
__forceinline void BlitPicHalfTransp(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, int* newPal = NULL)//BYTE* src, int swidth, int sheight)
__forceinline void BlitPicHalfTransp(void* dst, int x, int y, int dleft, int dtop, int dpitch, int dright, int dbottom, PICDATA& pd, int* color = NULL, const int* newPal = NULL)//BYTE* src, int swidth, int sheight)
{
ASSERT(pd.bType != PICDATA_TYPE_BMP);
@ -5372,7 +5372,7 @@ void CIsoView::DrawMap()
int w = 1, h = 1;
PICDATA pic;
if (id > -1 && id < 0x0F00) {
if (id > -1 && id < buildingInfoCapacity) {
w = buildinginfo[id].w;
h = buildinginfo[id].h;
int dir = objp.direction / 32;
@ -5402,7 +5402,9 @@ void CIsoView::DrawMap()
::Map->UpdateBuildingInfo(&objp.type);
int dir = (7 - objp.direction / 32) % 8;
pic = buildinginfo[id].pic[dir];
if (pic.pic == NULL) pic = buildinginfo[id].pic[0];
if (pic.pic == NULL) {
pic = buildinginfo[id].pic[0];
}
}
if (pic.pic == NULL) {
#ifndef NOSURFACES
@ -5480,7 +5482,7 @@ void CIsoView::DrawMap()
int id = m.node.type;
int w = 1, h = 1;
PICDATA pic;
if (id > -1 && id < 0x0F00) {
if (id > -1 && id < buildingInfoCapacity) {
w = buildinginfo[id].w;
h = buildinginfo[id].h;
pic = buildinginfo[id].pic[0];
@ -5694,7 +5696,7 @@ void CIsoView::DrawMap()
int id = m.terraintype;
int w = 1, h = 1;
PICDATA pic;
if (id > -1 && id < 0x0F00) {
if (id > -1 && id < buildingInfoCapacity) {
w = treeinfo[id].w;
h = treeinfo[id].h;
pic = treeinfo[id].pic;
@ -5745,7 +5747,7 @@ void CIsoView::DrawMap()
int id = m.smudgetype;
PICDATA pic;
if (id > -1 && id < 0x0F00) {
if (id > -1 && id < buildingInfoCapacity) {
pic = smudgeinfo[id].pic;
}

File diff suppressed because it is too large Load diff

View file

@ -91,7 +91,7 @@ class CLoading : public CDialog
{
// Construction
public:
void PrepareUnitGraphic(LPCSTR lpUnittype);
void PrepareUnitGraphic(const CString& lpUnittype);
void LoadStrings();
void FreeAll();
void FreeTileSet();
@ -109,6 +109,18 @@ public:
CLoading(CWnd* pParent = NULL); // Standardconstructor
void InitPics(CProgressCtrl* prog = NULL);
void Load();
bool LoadSingleFrameShape(const CString& name, int nFrame = 0, int deltaX = 0, int deltaY = 0);
void LoadBuilding(const CString& ID);
void LoadInfantry(const CString& ID);
void LoadTerrainOrSmudge(const CString& ID);
void LoadVehicleOrAircraft(const CString& ID);
void SetImageData(unsigned char* pBuffer, const CString& NameInDict, int FullWidth, int FullHeight, Palette* pPal);
void SetImageData(unsigned char* pBuffer, PICDATA& pData, const int FullWidth, const int FullHeight, Palette* pPal);
void UnionSHP_Add(unsigned char* pBuffer, int Width, int Height, int DeltaX = 0, int DeltaY = 0, bool UseTemp = false);
void UnionSHP_GetAndClear(unsigned char*& pOutBuffer, int* OutWidth, int* OutHeight, bool UseTemp = false);
void VXL_Add(const unsigned char* pCache, int X, int Y, int Width, int Height);
void VXL_GetAndClear(unsigned char*& pBuffer, int* OutWidth, int* OutHeight);
BOOL LoadUnitGraphic(const CString& lpUnittype);
void LoadBuildingSubGraphic(const CString& subkey, const CIniFileSection& artSection, BOOL bAlwaysSetChar, char theat, HMIXFILE hShpMix, SHPHEADER& shp_h, BYTE*& shp);
void LoadOverlayGraphic(const CString& lpOvrlName, int iOvrlNum);
@ -125,6 +137,24 @@ public:
return m_hExpand;
}
enum class ObjectType
{
Unknown = -1,
Infantry = 0,
Vehicle = 1,
Aircraft = 2,
Building = 3,
Terrain = 4,
Smudge = 5
};
ObjectType GetItemType(const CString& ID);
CString GetArtID(const CString& ID);
CString GetVehicleOrAircraftFileID(const CString& ID);
CString GetTerrainOrSmudgeFileID(const CString& ID);
CString GetBuildingFileID(const CString& ID);
CString GetInfantryFileID(const CString& ID);
// Dialog data
//{{AFX_DATA(CLoading)
enum { IDD = IDD_LOADING };
@ -197,7 +227,18 @@ private:
std::unique_ptr<VoxelNormalTables> m_voxelNormalTables;
struct SHPUnionData
{
unsigned char* pBuffer;
int Width;
int Height;
int DeltaX;
int DeltaY;
};
std::map<CString, ObjectType> ObjectTypes;
std::vector<SHPUnionData> UnionSHP_Data[2];
unsigned char VXL_Data[0x10000];
};
//{{AFX_INSERT_LOCATION}}

View file

@ -3453,7 +3453,7 @@ void CMapData::UpdateBuildingInfo(const CString* lpUnitType)
CIniFile& ini = GetIniFile();
if (!lpUnitType) {
memset(buildinginfo, 0, 0x0F00 * sizeof(BUILDING_INFO));
memset(buildinginfo, 0, buildingInfoCapacity * sizeof(BUILDING_INFO));
for (auto const& [seq, id] : rules.GetSection("BuildingTypes")) {
auto const& type = id;
@ -3464,7 +3464,7 @@ void CMapData::UpdateBuildingInfo(const CString* lpUnitType)
int n = Map->GetUnitTypeID(type);
if (n >= 0 && n < 0x0F00) {
if (n >= 0 && n < buildingInfoCapacity) {
buildinginfo[n].w = foundation.Width;
buildinginfo[n].h = foundation.Height;
@ -3525,7 +3525,7 @@ void CMapData::UpdateBuildingInfo(const CString* lpUnitType)
int n = Map->GetUnitTypeID(type);
if (n >= 0 && n < 0x0F00) {
if (n >= 0 && n < buildingInfoCapacity) {
buildinginfo[n].w = foundation.Width;
buildinginfo[n].h = foundation.Height;
buildinginfo[n].bSnow = TRUE;
@ -3560,7 +3560,7 @@ void CMapData::UpdateBuildingInfo(const CString* lpUnitType)
int n = Map->GetUnitTypeID(type);
if (n >= 0 && n < 0x0F00) {
if (n >= 0 && n < buildingInfoCapacity) {
buildinginfo[n].w = foundation.Width;
buildinginfo[n].h = foundation.Height;
CString lpPicFile = GetUnitPictureFilename(type, 0);

View file

@ -522,6 +522,7 @@
<ClCompile Include="NewMapSpDlg.cpp" />
<ClCompile Include="NewMapTypeDlg.cpp" />
<ClCompile Include="NewRA2HouseDlg.cpp" />
<ClCompile Include="Palettes.cpp" />
<ClCompile Include="ProgressDlg.cpp" />
<ClCompile Include="RightFrame.cpp" />
<ClCompile Include="RTPDlg.cpp" />
@ -610,6 +611,7 @@
<ClInclude Include="ComboUInputDlg.h" />
<ClInclude Include="defines.h" />
<ClInclude Include="IniHelper.h" />
<ClInclude Include="IniMega.h" />
<ClInclude Include="INIMeta.h" />
<ClInclude Include="LineDrawer.h" />
<ClInclude Include="DynamicGraphDlg.h" />
@ -650,6 +652,7 @@
<ClInclude Include="NewMapTypeDlg.h" />
<ClInclude Include="NewRA2HouseDlg.h" />
<ClInclude Include="ovrlinline.h" />
<ClInclude Include="Palettes.h" />
<ClInclude Include="ProgressDlg.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="RightFrame.h" />

View file

@ -285,6 +285,9 @@
<ClCompile Include="INIMeta.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Palettes.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MissionEditor.rc">
@ -577,6 +580,12 @@
<ClInclude Include="INIMeta.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IniMega.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Palettes.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="res\clifftoo.bmp">

View file

@ -1,3 +1,4 @@
#include "stdafx.h"
#include "Palettes.h"
#include "variables.h"
#include "functions.h"

View file

@ -4,6 +4,8 @@
#include <map>
#include "MissionEditorPackLib.h"
class CLoading;
struct BGRStruct
{
unsigned char B, G, R, Zero;
@ -39,6 +41,8 @@ public:
ret.blue = tmp.B;
return ret;
}
const BGRStruct* GetData() const { return Data; }
private:
BGRStruct Data[256];
};

View file

@ -118,7 +118,7 @@ struct PICDATA {
#else
void* pic = nullptr; // BYTE* to image, exception: if bType==PICDATA_TYPE_BMP then this is a LPDIRECTDRAWSURFACE!
VBORDER* vborder = nullptr;
int* pal = nullptr;
const int* pal = nullptr;
std::shared_ptr<std::vector<BYTE>> lighting;
std::shared_ptr<std::vector<BYTE>> rawPic;
std::shared_ptr<std::vector<VBORDER>> _vBorder;

View file

@ -37,6 +37,8 @@ using IgnoreSet = std::unordered_set<std::string>;
static const IgnoreSet CollectIgnoreSet();
extern CIniFile rules;
class TreeRoot {
friend class TreeViewBuilder;
friend class CViewObjects;

View file

@ -47,8 +47,10 @@ inline BOOL isFalse(CString expr)
return FALSE;
}
// retrieve the picture filename of a unit (as it is saved in the pics map). The returned file may not exist in the pics map (you need to do a check!).
inline CString GetUnitPictureFilename(LPCTSTR lpUnitName, DWORD dwPicIndex)
inline CString GetUnitPictureFilename(const CString& lpUnitName, DWORD dwPicIndex)
{
CIniFile& ini = Map->GetIniFile();
@ -71,17 +73,16 @@ inline CString GetUnitPictureFilename(LPCTSTR lpUnitName, DWORD dwPicIndex)
char n[50];
_itoa_s(dwPicIndex, n, 10);
if (pics.find((artname + n)) != pics.end()) {
filename = artname; // yes, found
// store differently for each type even they shares same image,
// because they can have different components, e.g. turret image
if (pics.find((lpUnitName + n)) != pics.end()) {
filename = lpUnitName; // yes, found
filename += n;
} else if (pics.find(artname + ".bmp") != pics.end()) // since June, 15th (Matze): Only use BMP if no SHP/VXL exists
{
} else if (pics.find(artname + ".bmp") != pics.end()) { // since June, 15th (Matze): Only use BMP if no SHP/VXL exists
filename = (CString)artname + ".bmp";
} else
} else {
filename = "";
}
return filename;
}

View file

@ -176,7 +176,8 @@ bool bAllowAccessBehindCliffs = false;
// infos for buildings and trees (should be extended to infantry, units, and aircraft)
// they are initialized in CIsoView, should be changed to CMapData
BUILDING_INFO buildinginfo[0x0F00];
BUILDING_INFO buildinginfo[buildingInfoCapacity];
TREE_INFO treeinfo[0x0F00];
#ifdef SMUDGE_SUPP
SMUDGE_INFO smudgeinfo[0x0F00];

View file

@ -104,7 +104,10 @@ extern vector<CString> rndterrainsrc;
// infos for buildings and trees (should be extended to infantry, units, and aircraft)
// they are initialized in CIsoView, should be changed to CMapData
extern BUILDING_INFO buildinginfo[0x0F00];
size_t constexpr buildingInfoCapacity = 0x0F000;
extern BUILDING_INFO buildinginfo[buildingInfoCapacity];
extern TREE_INFO treeinfo[0x0F00];
#ifdef SMUDGE_SUPP
extern SMUDGE_INFO smudgeinfo[0x0F00];

View file

@ -413,7 +413,7 @@ namespace FSunPackLib
BOOL XCC_DoesFileExist(LPCSTR szFile, HMIXFILE hOwner)
{
if (hOwner == 0)
if (hOwner == NULL)
return FALSE;
if (hOwner > dwMixFileCount)
return FALSE;
@ -1819,8 +1819,22 @@ namespace FSunPackLib
return TRUE;
}
BOOL LoadVXLImage(const VoxelNormalTables& normalTables, Vec3f lightDirection, const Vec3f rotation, const Vec3f modelOffset, std::vector<BYTE>& image, std::vector<BYTE>& lighting, int* lpXCenter, int* lpYCenter, int ZAdjust, int* lpXCenterZMax, int* lpYCenterZMax, int i3dCenterX, int i3dCenterY, RECT* vxlrect)
{
BOOL LoadVXLImage(
const VoxelNormalTables& normalTables,
Vec3f lightDirection,
const Vec3f rotation,
const Vec3f modelOffset,
OUT std::vector<BYTE>& image,
OUT std::vector<BYTE>& lighting,
OUT OPTIONAL int* lpXCenter,
OUT OPTIONAL int* lpYCenter,
int ZAdjust,
OUT OPTIONAL int* lpXCenterZMax,
OUT OPTIONAL int* lpYCenterZMax,
int i3dCenterX,
int i3dCenterY,
OUT OPTIONAL RECT* vxlrect
) {
last_succeeded_operation = 1;
int i;

View file

@ -28,6 +28,18 @@
#include <string>
#include "Vec3.h"
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
#ifndef OPTIONAL
#define OPTIONAL
#endif
class VoxelNormalTables;
typedef DWORD HMIXFILE;
@ -217,7 +229,20 @@ namespace FSunPackLib
BOOL LoadVXLImageInSurface(const VoxelNormalTables& normalTables, Vec3f lightDirection, IDirectDraw4* pdd, int iStart, int iCount, Vec3f rotation, Vec3f modelOffset, LPDIRECTDRAWSURFACE4* pdds, HTSPALETTE hPalette, int* lpXCenter = NULL, int* lpYCenter = NULL, int ZAdjust = 0, int* lpXCenterZMax = NULL, int* lpYCenterZMax = NULL, int i3dCenterX = -1, int i3dCenterY = -1);
// modelOffset is applied before VXL/HVA translates and scales and before model-to-world rotation
BOOL LoadVXLImage(const VoxelNormalTables& normalTables, Vec3f lightDirection, Vec3f rotation, Vec3f modelOffset, std::vector<BYTE>& image, std::vector<BYTE>& lighting, int* lpXCenter = NULL, int* lpYCenter = NULL, int ZAdjust = 0, int* lpXCenterZMax = NULL, int* lpYCenterZMax = NULL, int i3dCenterX = -1, int i3dCenterY = -1, RECT* vxlrect = NULL);
BOOL LoadVXLImage(const VoxelNormalTables& normalTables,
Vec3f lightDirection,
Vec3f rotation,
Vec3f modelOffset,
OUT std::vector<BYTE>& image,
OUT std::vector<BYTE>& lighting,
OUT OPTIONAL int* lpXCenter = NULL,
OUT OPTIONAL int* lpYCenter = NULL,
int ZAdjust = 0,
OUT OPTIONAL int* lpXCenterZMax = NULL,
OUT OPTIONAL int* lpYCenterZMax = NULL,
int i3dCenterX = -1,
int i3dCenterY = -1,
OUT OPTIONAL RECT* vxlrect = NULL);
BOOL WriteMixFile(LPCTSTR lpMixFile, LPCSTR* lpFiles, DWORD dwFileCount, Game game);