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. 87
      olcConsoleGameEngineSDL.h

@ -289,7 +289,7 @@ public:
Create(w, h); Create(w, h);
} }
olcSprite(std::wstring sFile) olcSprite(std::string sFile)
{ {
if (!Load(sFile)) if (!Load(sFile))
Create(8, 8); Create(8, 8);
@ -368,71 +368,44 @@ public:
return m_Colours[sy * nWidth + sx]; return m_Colours[sy * nWidth + sx];
} }
bool Save(std::string sFile) 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]; f.write((char*)&nWidth, sizeof(int));
#ifdef _WIN32 f.write((char*)&nHeight, sizeof(int));
size_t t; f.write((char*)m_Colours, sizeof(short) * nWidth * nHeight);
wcstombs_s(&t, buff, sFile.c_str(), 256); f.write((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight);
#else
wcstombs(buff, sFile.c_str(), 256);
#endif
#ifdef _WIN32 f.close();
fopen_s(&f, buff, "wb");
#else
f = std::fopen(buff, "wb");
#endif
if (f == nullptr)
return false;
fwrite(&nWidth, sizeof(int), 1, f); return true;
fwrite(&nHeight, sizeof(int), 1, f); }
fwrite(m_Colours, sizeof(short), nWidth * nHeight, f);
fwrite(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f);
fclose(f); bool Load(std::string sFile)
{
delete[] m_Glyphs;
delete[] m_Colours;
nWidth = 0;
nHeight = 0;
return true; std::ifstream f(sFile.c_str(), std::ios::in | std::ios::binary);
} if (!f.is_open()) return false;
bool Load(std::string sFile) // get file data
{ f.read ((char*)&nWidth, sizeof(int));
delete[] m_Glyphs; f.read ((char*)&nHeight, sizeof(int));
delete[] m_Colours;
nWidth = 0;
nHeight = 0;
FILE *f = nullptr; Create(nWidth, nHeight);
char buff[256];
#ifdef _WIN32 f.read ((char*)m_Colours, sizeof(short) * nWidth * nHeight);
size_t t; f.read ((char*)m_Glyphs, sizeof(wchar_t) * nWidth * nHeight);
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;
fread(&nWidth, sizeof(int), 1, f);
fread(&nHeight, sizeof(int), 1, f);
Create(nWidth, nHeight); f.close();
fread(m_Colours, sizeof(short), nWidth * nHeight, f); return true;
fread(m_Glyphs, sizeof(wchar_t), nWidth * nHeight, f); }
fclose(f);
return true;
}
}; };
int len = 0, done = 0, bits = 0, which = 0, int len = 0, done = 0, bits = 0, which = 0,

Loading…
Cancel
Save