diff --git a/dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj b/dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj index 930e804..06f66a8 100644 --- a/dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj +++ b/dev/msvc/olcPGE3_BuildSH/olcPGE3_BuildSH.vcxproj @@ -92,7 +92,7 @@ false false - false + true false diff --git a/dev/src/core.cpp b/dev/src/core.cpp index c3af8ab..ce776f7 100644 --- a/dev/src/core.cpp +++ b/dev/src/core.cpp @@ -107,10 +107,30 @@ namespace olc return true; } + void PGEWindow::OnUserResize(const olc::vi2d& vNewWindowSize) + { + return; + } + bool PGEWindow::olc_WindowUpdate(const float fElapsedTime, const float fTotalElapsedTime) { float fDT = fElapsedTime; + // This synchronises resizes of windows so we dont draw + // to screens that have changed size + if (bWindowResizeRequest) + { + if(config.bRealWindow) + GetScreen().Resize(vWindowResizeRequest); + + SetWindowSize(vWindowResizeRequest); + bWindowResizeRequest = false; + + // Allow user to react if they want + OnUserResize(vWindowResizeRequest); + } + + // Input Changes mouse.UpdateState(); keyboard.UpdateState(); @@ -391,12 +411,9 @@ namespace olc bool PGEWindow::olc_OnWindowSize(const olc::vi2d& vSize) { - if (config.bRealWindow) - { - GetScreen().Resize(vSize); - } - - return SetWindowSize(vSize); + bWindowResizeRequest = true; + vWindowResizeRequest = vSize; + return true; } diff --git a/dev/src/core.h b/dev/src/core.h index 43e1a76..d9336e2 100644 --- a/dev/src/core.h +++ b/dev/src/core.h @@ -90,6 +90,8 @@ namespace olc virtual bool OnUserUpdate(float fElapsedTime); // Return true if window is to close virtual bool OnUserDestroy(); + + virtual void OnUserResize(const olc::vi2d& vNewWindowSize); public: // olc::Image Handling @@ -147,6 +149,8 @@ namespace olc olc::imload::ImageLoader* pImageLoader = nullptr; olc::vi2d vViewPos = { 0,0 }; olc::vi2d vViewSize = { 0,0 }; + bool bWindowResizeRequest = false; + olc::vi2d vWindowResizeRequest = { 0,0 }; protected: // Extensions bool InstallWindowExtension(olc::PGEWindowExtension* pgex); diff --git a/dev/src/draw.cpp b/dev/src/draw.cpp index bd2e362..9fb9f8c 100644 --- a/dev/src/draw.cpp +++ b/dev/src/draw.cpp @@ -229,6 +229,16 @@ olc::vf2d olc::Draw::ScreenToWorld(const olc::vf2d& v) const return transformAffine.inverse(v); } +olc::vf2d olc::Draw::SizeInWorld(const olc::vf2d& v) const +{ + return v / transformAffine.scale(); +} + +olc::vf2d olc::Draw::SizeOnScreen(const olc::vf2d& v) const +{ + return transformAffine.scale() * v; +} + void Draw::Pixel(const olc::vf2d& pos, const olc::Pixel col, const olc::Pixel tint) { // Check if in bounds diff --git a/dev/src/draw.h b/dev/src/draw.h index 9b92460..2f9f9c4 100644 --- a/dev/src/draw.h +++ b/dev/src/draw.h @@ -226,6 +226,11 @@ namespace olc olc::vf2d WorldToScreen(const olc::vf2d& v) const; olc::vf2d ScreenToWorld(const olc::vf2d& v) const; + // Scale a size in screen pixels to world units + // (essentially scale only, no offsets or rotations) + olc::vf2d SizeInWorld(const olc::vf2d& v) const; + olc::vf2d SizeOnScreen(const olc::vf2d& v) const; + public: // Primitive Drawing Functions // Plot a single pixel void Pixel( diff --git a/dev/src/sh_template.h b/dev/src/sh_template.h index a7444a0..b02f711 100644 --- a/dev/src/sh_template.h +++ b/dev/src/sh_template.h @@ -118,8 +118,9 @@ olcCodeJam 2026 - Beta Testers - Big Thanks! (itch account names shown) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - KrossX, Zalambdodont, mgnooj, bblodget, bootsec, tgd20, AJSquirrel, Linh, pm1001 - tobiasrox, mitchdev1, u2084511felix, BenKyd, Beefpants, objectname, MrB, raoul632 + KrossX, Zalambdodont, mgnooj, bblodget, bootsec, tgd20, AJSquirrel, Linh, pm1001, + tobiasrox, mitchdev1, u2084511felix, BenKyd, Beefpants, objectname, MrB, raoul632, + yolicap, JustBrailey, AlfaDrottning Version History ~~~~~~~~~~~~~~~ diff --git a/dev/src/vector2d.h b/dev/src/vector2d.h index 90d71cc..cf50552 100644 --- a/dev/src/vector2d.h +++ b/dev/src/vector2d.h @@ -13,12 +13,19 @@ //! END CUSTOMHEADER //! START DECLARATION -#if !defined(PGE_VECTOR2D_DECLARED) + +#if !defined(PGE_NUMERIC_CONCEPT_DECLARED) namespace olc { template concept numeric = std::integral || std::floating_point; +} +#define PGE_NUMERIC_CONCEPT_DECLARED 1 +#endif +#if !defined(PGE_VECTOR2D_DECLARED) +namespace olc +{ /* A complete 2D geometric vector structure, with a variety of useful utility functions and operator overloads diff --git a/olcPixelGameEngine3.h b/olcPixelGameEngine3.h index 2a0e918..f873631 100644 --- a/olcPixelGameEngine3.h +++ b/olcPixelGameEngine3.h @@ -118,8 +118,9 @@ olcCodeJam 2026 - Beta Testers - Big Thanks! (itch account names shown) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - KrossX, Zalambdodont, mgnooj, bblodget, bootsec, tgd20, AJSquirrel, Linh, pm1001 - tobiasrox, mitchdev1, u2084511felix, BenKyd, Beefpants, objectname, MrB, raoul632 + KrossX, Zalambdodont, mgnooj, bblodget, bootsec, tgd20, AJSquirrel, Linh, pm1001, + tobiasrox, mitchdev1, u2084511felix, BenKyd, Beefpants, objectname, MrB, raoul632, + yolicap, JustBrailey, AlfaDrottning Version History ~~~~~~~~~~~~~~~ @@ -678,12 +679,19 @@ namespace olc #define PGE_PIXEL_DECLARED 1 #endif -#if !defined(PGE_VECTOR2D_DECLARED) + +#if !defined(PGE_NUMERIC_CONCEPT_DECLARED) namespace olc { template concept numeric = std::integral || std::floating_point; +} +#define PGE_NUMERIC_CONCEPT_DECLARED 1 +#endif +#if !defined(PGE_VECTOR2D_DECLARED) +namespace olc +{ /* A complete 2D geometric vector structure, with a variety of useful utility functions and operator overloads @@ -2921,6 +2929,11 @@ namespace olc olc::vf2d WorldToScreen(const olc::vf2d& v) const; olc::vf2d ScreenToWorld(const olc::vf2d& v) const; + // Scale a size in screen pixels to world units + // (essentially scale only, no offsets or rotations) + olc::vf2d SizeInWorld(const olc::vf2d& v) const; + olc::vf2d SizeOnScreen(const olc::vf2d& v) const; + public: // Primitive Drawing Functions // Plot a single pixel void Pixel( @@ -4435,6 +4448,8 @@ namespace olc virtual bool OnUserUpdate(float fElapsedTime); // Return true if window is to close virtual bool OnUserDestroy(); + + virtual void OnUserResize(const olc::vi2d& vNewWindowSize); public: // olc::Image Handling @@ -4492,6 +4507,8 @@ namespace olc olc::imload::ImageLoader* pImageLoader = nullptr; olc::vi2d vViewPos = { 0,0 }; olc::vi2d vViewSize = { 0,0 }; + bool bWindowResizeRequest = false; + olc::vi2d vWindowResizeRequest = { 0,0 }; protected: // Extensions bool InstallWindowExtension(olc::PGEWindowExtension* pgex); @@ -18322,6 +18339,16 @@ olc::vf2d olc::Draw::ScreenToWorld(const olc::vf2d& v) const return transformAffine.inverse(v); } +olc::vf2d olc::Draw::SizeInWorld(const olc::vf2d& v) const +{ + return v / transformAffine.scale(); +} + +olc::vf2d olc::Draw::SizeOnScreen(const olc::vf2d& v) const +{ + return transformAffine.scale() * v; +} + void Draw::Pixel(const olc::vf2d& pos, const olc::Pixel col, const olc::Pixel tint) { // Check if in bounds @@ -20054,10 +20081,30 @@ namespace olc return true; } + void PGEWindow::OnUserResize(const olc::vi2d& vNewWindowSize) + { + return; + } + bool PGEWindow::olc_WindowUpdate(const float fElapsedTime, const float fTotalElapsedTime) { float fDT = fElapsedTime; + // This synchronises resizes of windows so we dont draw + // to screens that have changed size + if (bWindowResizeRequest) + { + if(config.bRealWindow) + GetScreen().Resize(vWindowResizeRequest); + + SetWindowSize(vWindowResizeRequest); + bWindowResizeRequest = false; + + // Allow user to react if they want + OnUserResize(vWindowResizeRequest); + } + + // Input Changes mouse.UpdateState(); keyboard.UpdateState(); @@ -20338,12 +20385,9 @@ namespace olc bool PGEWindow::olc_OnWindowSize(const olc::vi2d& vSize) { - if (config.bRealWindow) - { - GetScreen().Resize(vSize); - } - - return SetWindowSize(vSize); + bWindowResizeRequest = true; + vWindowResizeRequest = vSize; + return true; } diff --git a/utilities/olcUTIL3_Camera2D.h b/utilities/olcUTIL3_Camera2D.h index f645510..48ed0a3 100644 --- a/utilities/olcUTIL3_Camera2D.h +++ b/utilities/olcUTIL3_Camera2D.h @@ -101,6 +101,11 @@ namespace olc::utils return m_nMode; } + inline void SetScreenSize(const olc::vf2d& vScreenSize) + { + m_vViewSize = vScreenSize / m_vViewScale; + } + // Get the position of the target being tracked by this camera inline const olc::vf2d& GetTarget() const { @@ -361,7 +366,7 @@ namespace olc::utils // Target Vector2D object camera should follow (either ref or ptr) olc::vf2d* m_pTarget = nullptr; - olc::vf2d m_vLocalTarget; + olc::vf2d m_vLocalTarget = { 0,0 }; // World Boundary bool m_bWorldBoundary = false;