Thx J. Random Programmer

He helped me rewrite the sprite loading functions to be compatible, he should get some credit
master^2
gorbit99 6 years ago committed by GitHub
parent 168a47a365
commit 5d24255fde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 61
      olcConsoleGameEngineSDL.h

@ -289,7 +289,7 @@ public:
Create(w, h);
}
olcSprite(std::wstring sFile)
olcSprite(std::string sFile)
{
if (!Load(sFile))
Create(8, 8);
@ -370,30 +370,15 @@ public:
bool Save(std::string sFile)
{
FILE *f = nullptr;
std::ofstream f(sFile.c_str(), std::ios::out | std::ios::binary);
if (!f.is_open()) return false;
char buff[256];
#ifdef _WIN32
size_t t;
wcstombs_s(&t, buff, sFile.c_str(), 256);
#else
wcstombs(buff, sFile.c_str(), 256);
#endif
#ifdef _WIN32
fopen_s(&f, buff, "wb");
#else
f = std::fopen(buff, "wb");
#endif
if (f == nullptr)
return false;
fwrite(&nWidth, sizeof(int), 1, f);
fwrite(&nHeight, sizeof(int), 1, f);
fwrite(m_Colours, sizeof(short), nWidth * nHeight, f);
fwrite(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f);
f.write((char*)&nWidth, sizeof(int));
f.write((char*)&nHeight, sizeof(int));
f.write((char*)m_Colours, sizeof(short) * nWidth * nHeight);
f.write((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight);
fclose(f);
f.close();
return true;
}
@ -405,32 +390,20 @@ public:
nWidth = 0;
nHeight = 0;
FILE *f = nullptr;
char buff[256];
#ifdef _WIN32
size_t t;
wcstombs_s(&t, buff, sFile.c_str(), 256);
#else
wcstombs(buff, sFile.c_str(), 256);
#endif
#ifdef _WIN32
fopen_s(&f, buff, "rb");
#else
f = std::fopen(buff, "rb");
#endif
if (f == nullptr)
return false;
std::ifstream f(sFile.c_str(), std::ios::in | std::ios::binary);
if (!f.is_open()) return false;
fread(&nWidth, sizeof(int), 1, f);
fread(&nHeight, sizeof(int), 1, f);
// get file data
f.read ((char*)&nWidth, sizeof(int));
f.read ((char*)&nHeight, sizeof(int));
Create(nWidth, nHeight);
fread(m_Colours, sizeof(short), nWidth * nHeight, f);
fread(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f);
f.read ((char*)m_Colours, sizeof(short) * nWidth * nHeight);
f.read ((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight);
f.close();
fclose(f);
return true;
}
};

Loading…
Cancel
Save