|
|
@ -2,7 +2,7 @@ |
|
|
|
olcPixelGameEngine.h |
|
|
|
olcPixelGameEngine.h |
|
|
|
|
|
|
|
|
|
|
|
+-------------------------------------------------------------+ |
|
|
|
+-------------------------------------------------------------+ |
|
|
|
| OneLoneCoder Pixel Game Engine v1.17 | |
|
|
|
| OneLoneCoder Pixel Game Engine v1.19 | |
|
|
|
| "Like the command prompt console one, but not..." - javidx9 | |
|
|
|
| "Like the command prompt console one, but not..." - javidx9 | |
|
|
|
+-------------------------------------------------------------+ |
|
|
|
+-------------------------------------------------------------+ |
|
|
|
|
|
|
|
|
|
|
@ -119,8 +119,8 @@ |
|
|
|
I'd like to extend thanks to Eremiell, slavka, gurkanctn, Phantim, |
|
|
|
I'd like to extend thanks to Eremiell, slavka, gurkanctn, Phantim, |
|
|
|
JackOJC, KrossX, Huhlig, Dragoneye, Appa, JustinRichardsMusic, SliceNDice |
|
|
|
JackOJC, KrossX, Huhlig, Dragoneye, Appa, JustinRichardsMusic, SliceNDice |
|
|
|
Ralakus, Gorbit99, raoul, joshinils, benedani & MagetzUb for advice, ideas and |
|
|
|
Ralakus, Gorbit99, raoul, joshinils, benedani & MagetzUb for advice, ideas and |
|
|
|
testing, and I'd like to extend my appreciation to the 40K YouTube followers, |
|
|
|
testing, and I'd like to extend my appreciation to the 96K YouTube followers, |
|
|
|
22 Patreons and 2.6K Discord server members who give me the motivation to keep |
|
|
|
47 Patreons and 4.5K Discord server members who give me the motivation to keep |
|
|
|
going with all this :D |
|
|
|
going with all this :D |
|
|
|
|
|
|
|
|
|
|
|
Special thanks to those who bring gifts! |
|
|
|
Special thanks to those who bring gifts! |
|
|
@ -250,6 +250,9 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace |
|
|
|
Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); |
|
|
|
Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255); |
|
|
|
Pixel(uint32_t p); |
|
|
|
Pixel(uint32_t p); |
|
|
|
enum Mode { NORMAL, MASK, ALPHA, CUSTOM }; |
|
|
|
enum Mode { NORMAL, MASK, ALPHA, CUSTOM }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const Pixel& p) const; |
|
|
|
|
|
|
|
bool operator!=(const Pixel& p) const; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Some constants for symbolic naming of Pixels
|
|
|
|
// Some constants for symbolic naming of Pixels
|
|
|
@ -284,6 +287,7 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace |
|
|
|
inline v2d_generic(T _x, T _y) : x(_x), y(_y) { } |
|
|
|
inline v2d_generic(T _x, T _y) : x(_x), y(_y) { } |
|
|
|
inline v2d_generic(const v2d_generic& v) : x(v.x), y(v.y){ } |
|
|
|
inline v2d_generic(const v2d_generic& v) : x(v.x), y(v.y){ } |
|
|
|
inline T mag() { return sqrt(x * x + y * y); } |
|
|
|
inline T mag() { return sqrt(x * x + y * y); } |
|
|
|
|
|
|
|
inline T mag2() { return x * x + y * y; } |
|
|
|
inline v2d_generic norm() { T r = 1 / mag(); return v2d_generic(x*r, y*r); } |
|
|
|
inline v2d_generic norm() { T r = 1 / mag(); return v2d_generic(x*r, y*r); } |
|
|
|
inline v2d_generic perp() { return v2d_generic(-y, x); } |
|
|
|
inline v2d_generic perp() { return v2d_generic(-y, x); } |
|
|
|
inline T dot(const v2d_generic& rhs) { return this->x * rhs.x + this->y * rhs.y; } |
|
|
|
inline T dot(const v2d_generic& rhs) { return this->x * rhs.x + this->y * rhs.y; } |
|
|
@ -413,7 +417,7 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace |
|
|
|
PixelGameEngine(); |
|
|
|
PixelGameEngine(); |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
olc::rcode Construct(uint32_t screen_w, uint32_t screen_h, uint32_t pixel_w, uint32_t pixel_h, bool full_screen = false); |
|
|
|
olc::rcode Construct(uint32_t screen_w, uint32_t screen_h, uint32_t pixel_w, uint32_t pixel_h, bool full_screen = false, bool vsync = false); |
|
|
|
olc::rcode Start(); |
|
|
|
olc::rcode Start(); |
|
|
|
|
|
|
|
|
|
|
|
public: // Override Interfaces
|
|
|
|
public: // Override Interfaces
|
|
|
@ -492,6 +496,8 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace |
|
|
|
void DrawString(int32_t x, int32_t y, std::string sText, Pixel col = olc::WHITE, uint32_t scale = 1); |
|
|
|
void DrawString(int32_t x, int32_t y, std::string sText, Pixel col = olc::WHITE, uint32_t scale = 1); |
|
|
|
// Clears entire draw target to Pixel
|
|
|
|
// Clears entire draw target to Pixel
|
|
|
|
void Clear(Pixel p); |
|
|
|
void Clear(Pixel p); |
|
|
|
|
|
|
|
// Resize the primary screen sprite
|
|
|
|
|
|
|
|
void SetScreenSize(int w, int h); |
|
|
|
|
|
|
|
|
|
|
|
public: // Branding
|
|
|
|
public: // Branding
|
|
|
|
std::string sAppName; |
|
|
|
std::string sAppName; |
|
|
@ -524,12 +530,13 @@ namespace olc // All OneLoneCoder stuff will now exist in the "olc" namespace |
|
|
|
float fSubPixelOffsetY = 0.0f; |
|
|
|
float fSubPixelOffsetY = 0.0f; |
|
|
|
bool bHasInputFocus = false; |
|
|
|
bool bHasInputFocus = false; |
|
|
|
bool bHasMouseFocus = false; |
|
|
|
bool bHasMouseFocus = false; |
|
|
|
|
|
|
|
bool bEnableVSYNC = false; |
|
|
|
float fFrameTimer = 1.0f; |
|
|
|
float fFrameTimer = 1.0f; |
|
|
|
int nFrameCount = 0; |
|
|
|
int nFrameCount = 0; |
|
|
|
Sprite *fontSprite = nullptr; |
|
|
|
Sprite *fontSprite = nullptr; |
|
|
|
std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode; |
|
|
|
std::function<olc::Pixel(const int x, const int y, const olc::Pixel&, const olc::Pixel&)> funcPixelMode; |
|
|
|
|
|
|
|
|
|
|
|
static std::map<uint16_t, uint8_t> mapKeys; |
|
|
|
static std::map<size_t, uint8_t> mapKeys; |
|
|
|
bool pKeyNewState[256]{ 0 }; |
|
|
|
bool pKeyNewState[256]{ 0 }; |
|
|
|
bool pKeyOldState[256]{ 0 }; |
|
|
|
bool pKeyOldState[256]{ 0 }; |
|
|
|
HWButton pKeyboardState[256]; |
|
|
|
HWButton pKeyboardState[256]; |
|
|
@ -635,6 +642,16 @@ namespace olc |
|
|
|
n = p; |
|
|
|
n = p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Pixel::operator==(const Pixel& p) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return n == p.n; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Pixel::operator!=(const Pixel& p) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return n != p.n; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//==========================================================
|
|
|
|
//==========================================================
|
|
|
|
|
|
|
|
|
|
|
|
std::wstring ConvertS2W(std::string s) |
|
|
|
std::wstring ConvertS2W(std::string s) |
|
|
@ -1005,15 +1022,15 @@ namespace olc |
|
|
|
if (!ifs.is_open()) return olc::FAIL; |
|
|
|
if (!ifs.is_open()) return olc::FAIL; |
|
|
|
|
|
|
|
|
|
|
|
// 1) Read Map
|
|
|
|
// 1) Read Map
|
|
|
|
size_t nMapEntries; |
|
|
|
uint32_t nMapEntries; |
|
|
|
ifs.read((char*)&nMapEntries, sizeof(size_t)); |
|
|
|
ifs.read((char*)&nMapEntries, sizeof(uint32_t)); |
|
|
|
for (size_t i = 0; i < nMapEntries; i++) |
|
|
|
for (uint32_t i = 0; i < nMapEntries; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t nFilePathSize = 0; |
|
|
|
uint32_t nFilePathSize = 0; |
|
|
|
ifs.read((char*)&nFilePathSize, sizeof(size_t)); |
|
|
|
ifs.read((char*)&nFilePathSize, sizeof(uint32_t)); |
|
|
|
|
|
|
|
|
|
|
|
std::string sFileName(nFilePathSize, ' '); |
|
|
|
std::string sFileName(nFilePathSize, ' '); |
|
|
|
for (size_t j = 0; j < nFilePathSize; j++) |
|
|
|
for (uint32_t j = 0; j < nFilePathSize; j++) |
|
|
|
sFileName[j] = ifs.get(); |
|
|
|
sFileName[j] = ifs.get(); |
|
|
|
|
|
|
|
|
|
|
|
sEntry e; |
|
|
|
sEntry e; |
|
|
@ -1062,13 +1079,14 @@ namespace olc |
|
|
|
olc::PGEX::pge = this; |
|
|
|
olc::PGEX::pge = this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
olc::rcode PixelGameEngine::Construct(uint32_t screen_w, uint32_t screen_h, uint32_t pixel_w, uint32_t pixel_h, bool full_screen) |
|
|
|
olc::rcode PixelGameEngine::Construct(uint32_t screen_w, uint32_t screen_h, uint32_t pixel_w, uint32_t pixel_h, bool full_screen, bool vsync) |
|
|
|
{ |
|
|
|
{ |
|
|
|
nScreenWidth = screen_w; |
|
|
|
nScreenWidth = screen_w; |
|
|
|
nScreenHeight = screen_h; |
|
|
|
nScreenHeight = screen_h; |
|
|
|
nPixelWidth = pixel_w; |
|
|
|
nPixelWidth = pixel_w; |
|
|
|
nPixelHeight = pixel_h; |
|
|
|
nPixelHeight = pixel_h; |
|
|
|
bFullScreen = full_screen; |
|
|
|
bFullScreen = full_screen; |
|
|
|
|
|
|
|
bEnableVSYNC = vsync; |
|
|
|
|
|
|
|
|
|
|
|
fPixelX = 2.0f / (float)(nScreenWidth); |
|
|
|
fPixelX = 2.0f / (float)(nScreenWidth); |
|
|
|
fPixelY = 2.0f / (float)(nScreenHeight); |
|
|
|
fPixelY = 2.0f / (float)(nScreenHeight); |
|
|
@ -1092,6 +1110,24 @@ namespace olc |
|
|
|
return olc::OK; |
|
|
|
return olc::OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PixelGameEngine::SetScreenSize(int w, int h) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
delete pDefaultDrawTarget; |
|
|
|
|
|
|
|
nScreenWidth = w; |
|
|
|
|
|
|
|
nScreenHeight = h; |
|
|
|
|
|
|
|
pDefaultDrawTarget = new Sprite(nScreenWidth, nScreenHeight); |
|
|
|
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
|
|
|
|
SwapBuffers(glDeviceContext); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
glXSwapBuffers(olc_Display, olc_Window); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
|
|
|
olc_UpdateViewport(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
olc::rcode PixelGameEngine::Start() |
|
|
|
olc::rcode PixelGameEngine::Start() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Construct the window
|
|
|
|
// Construct the window
|
|
|
@ -2054,7 +2090,7 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
// Define window furniture
|
|
|
|
// Define window furniture
|
|
|
|
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; |
|
|
|
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; |
|
|
|
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE; // | WS_THICKFRAME;
|
|
|
|
DWORD dwStyle = WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_THICKFRAME; |
|
|
|
|
|
|
|
|
|
|
|
int nCosmeticOffset = 30; |
|
|
|
int nCosmeticOffset = 30; |
|
|
|
nViewW = nWindowWidth; |
|
|
|
nViewW = nWindowWidth; |
|
|
@ -2146,7 +2182,7 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
// Remove Frame cap
|
|
|
|
// Remove Frame cap
|
|
|
|
wglSwapInterval = (wglSwapInterval_t*)wglGetProcAddress("wglSwapIntervalEXT"); |
|
|
|
wglSwapInterval = (wglSwapInterval_t*)wglGetProcAddress("wglSwapIntervalEXT"); |
|
|
|
if (wglSwapInterval) wglSwapInterval(0); |
|
|
|
if (wglSwapInterval && !bEnableVSYNC) wglSwapInterval(0); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2289,7 +2325,7 @@ namespace olc |
|
|
|
|
|
|
|
|
|
|
|
glSwapIntervalEXT = nullptr; |
|
|
|
glSwapIntervalEXT = nullptr; |
|
|
|
glSwapIntervalEXT = (glSwapInterval_t*)glXGetProcAddress((unsigned char*)"glXSwapIntervalEXT"); |
|
|
|
glSwapIntervalEXT = (glSwapInterval_t*)glXGetProcAddress((unsigned char*)"glXSwapIntervalEXT"); |
|
|
|
if (glSwapIntervalEXT) |
|
|
|
if (glSwapIntervalEXT && !bEnableVSYNC) |
|
|
|
glSwapIntervalEXT(olc_Display, olc_Window, 0); |
|
|
|
glSwapIntervalEXT(olc_Display, olc_Window, 0); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2306,7 +2342,7 @@ namespace olc |
|
|
|
// Need a couple of statics as these are singleton instances
|
|
|
|
// Need a couple of statics as these are singleton instances
|
|
|
|
// read from multiple locations
|
|
|
|
// read from multiple locations
|
|
|
|
std::atomic<bool> PixelGameEngine::bAtomActive{ false }; |
|
|
|
std::atomic<bool> PixelGameEngine::bAtomActive{ false }; |
|
|
|
std::map<uint16_t, uint8_t> PixelGameEngine::mapKeys; |
|
|
|
std::map<size_t, uint8_t> PixelGameEngine::mapKeys; |
|
|
|
olc::PixelGameEngine* olc::PGEX::pge = nullptr; |
|
|
|
olc::PixelGameEngine* olc::PGEX::pge = nullptr; |
|
|
|
#ifdef OLC_DBG_OVERDRAW |
|
|
|
#ifdef OLC_DBG_OVERDRAW |
|
|
|
int olc::Sprite::nOverdrawCount = 0; |
|
|
|
int olc::Sprite::nOverdrawCount = 0; |
|
|
|