Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8a33c93
Draw UI with OpenGL, delete Surf_Display
Jul 1, 2026
c650bdd
Draw()
morganchristiansson Jul 3, 2026
76531bd
drawMinimap
morganchristiansson Jul 3, 2026
4332feb
Obvious review fixes, remove multiline
morganchristiansson Jul 4, 2026
eca9e13
Revert changes to Texture
morganchristiansson Jul 4, 2026
71ace85
getPos and struct FrameInserts
morganchristiansson Jul 4, 2026
e4163e8
drawButtonBox()
morganchristiansson Jul 4, 2026
fcf7e67
Rect/Position/Extent
morganchristiansson Jul 4, 2026
b20ae0d
Rect/Position/Extent
morganchristiansson Jul 4, 2026
96e188c
draw()
morganchristiansson Jul 4, 2026
37be0ae
unsigned idx
morganchristiansson Jul 4, 2026
19e0f0f
Position/Extent
morganchristiansson Jul 4, 2026
795cbbb
color args
morganchristiansson Jul 4, 2026
22c6a56
draw() checks isValid
morganchristiansson Jul 4, 2026
1ded529
Texture.drawTiled
morganchristiansson Jul 4, 2026
33c9ee0
setText early return
morganchristiansson Jul 4, 2026
e398e7a
makePos simpler
morganchristiansson Jul 4, 2026
a64dda3
num_x/y > scale
morganchristiansson Jul 4, 2026
00cc538
std::vector<Texture>
morganchristiansson Jul 4, 2026
c1c7b98
Fix text in load&save
morganchristiansson Jul 4, 2026
5feba0d
Extent textSize
morganchristiansson Jul 4, 2026
599428d
Cleanup and dead code
morganchristiansson Jul 5, 2026
8b749da
drawButtonBox
morganchristiansson Jul 5, 2026
9f1f347
Position/Extent
morganchristiansson Jul 5, 2026
506e0a3
clamp
morganchristiansson Jul 5, 2026
c165b70
getBmpTexture().draw()
morganchristiansson Jul 5, 2026
b37716b
clang-format
morganchristiansson Jul 5, 2026
345ddc6
unused forward declaration
morganchristiansson Jul 5, 2026
e9610ce
clamp window
morganchristiansson Jul 5, 2026
a85ffea
Positioning fixes, window size clamped to on screen
morganchristiansson Jul 5, 2026
09f9e19
glColor is already reset where used
morganchristiansson Jul 5, 2026
dd1f304
dead code ensureBmpText()
morganchristiansson Jul 5, 2026
8ab3cb2
unsigned bmpArray idx
morganchristiansson Jul 5, 2026
0d3f877
inlined origin and winRect
morganchristiansson Jul 5, 2026
84608ca
tidy
morganchristiansson Jul 5, 2026
5b6284c
clang-format
morganchristiansson Jul 5, 2026
e364d69
Restore docstrings
morganchristiansson Jul 6, 2026
66bb4be
Restore docstrings
morganchristiansson Jul 6, 2026
4040fd9
Apply docstring suggestions
morganchristiansson Jul 7, 2026
2a5ad4d
getRect()
morganchristiansson Jul 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,8 @@ int CGame::Execute()

void CGame::RenderPresent()
{
displayTexture_.upload(Surf_Display->pixels);
displayTexture_.Draw(Rect(0, 0, GameResolution.x, GameResolution.y));

const auto& cursorImg = Cursor.clicked ? (Cursor.button.right ? cross_ : cursorClicked_) : cursor_;
cursorImg.Draw(Cursor.pos);
cursorImg.draw(Cursor.pos);

SDL_GL_SwapWindow(window_.get());
}
Expand Down
5 changes: 1 addition & 4 deletions CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#pragma once

#include "CIO/CFont.h"
#include "SdlSurface.h"
#include "Texture.h"
#include <boost/filesystem/path.hpp>
#include <Point.h>
Expand All @@ -27,8 +26,6 @@ class CGame

bool Running;
bool showLoadScreen;
SdlSurface Surf_Display;
Texture displayTexture_;
SDL_GLContext glContext_ = nullptr;
SdlWindow window_;

Expand All @@ -52,6 +49,7 @@ class CGame
Texture cursor_;
Texture cursorClicked_;
Texture cross_;
Texture mapTex_; ///< Texture for the map/terrain (Surf_Map may be 8-bit)

// structure for mouse cursor
struct
Expand Down Expand Up @@ -111,6 +109,5 @@ class CGame
CMap* getMapObj();
void delMapObj();
void enterEditor(const boost::filesystem::path& filepath);
SDL_Surface* getDisplaySurface() const { return Surf_Display.get(); };
auto getRes() const { return GameResolution; }
};
13 changes: 4 additions & 9 deletions CGame_Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "CIO/CWindow.h"
#include "CMap.h"
#include "CSurface.h"
#include "CollisionDetection.h"
#include "callbacks.h"
#include "globals.h"

Expand Down Expand Up @@ -195,9 +196,7 @@ void CGame::EventHandling(SDL_Event* Event)
if(!Window->isWaste() && Window->getPriority() == actualPriority)
{
// is the cursor INSIDE the window or does the user move or resize the window?
if(((Event->motion.x >= Window->getX()) && (Event->motion.x < Window->getX() + Window->getW())
&& (Event->motion.y >= Window->getY())
&& (Event->motion.y < Window->getY() + Window->getH()))
if(IsPointInRect(Event->motion.x, Event->motion.y, Rect(Window->getPos(), Window->getSize()))
|| Window->isMoving() || Window->isResizing())
{
// Windows[i]->setActive();
Expand Down Expand Up @@ -275,9 +274,7 @@ void CGame::EventHandling(SDL_Event* Event)
if(!Window->isWaste() && Window->getPriority() == actualPriority)
{
// is the cursor INSIDE the window?
if((Event->button.x >= Window->getX()) && (Event->button.x < Window->getX() + Window->getW())
&& (Event->button.y >= Window->getY())
&& (Event->button.y < Window->getY() + Window->getH()))
if(IsPointInRect(Event->button.x, Event->button.y, Rect(Window->getPos(), Window->getSize())))
{
Window->setActive();
Window->setPriority(highestPriority + 1);
Expand Down Expand Up @@ -338,9 +335,7 @@ void CGame::EventHandling(SDL_Event* Event)
if(!Window->isWaste() && Window->getPriority() == actualPriority)
{
// is the cursor INSIDE the window?
if((Event->button.x >= Window->getX()) && (Event->button.x < Window->getX() + Window->getW())
&& (Event->button.y >= Window->getY())
&& (Event->button.y < Window->getY() + Window->getH()))
if(IsPointInRect(Event->button.x, Event->button.y, Rect(Window->getPos(), Window->getSize())))
{
// Windows[i]->setActive();
// Windows[i]->setPriority(highestPriority+1);
Expand Down
13 changes: 1 addition & 12 deletions CGame_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ bool CGame::CreateWindow()
SDL_ShowWindow(window_.get());

ApplyWindowChanges();
if(!displayTexture_.isValid() || !Surf_Display)
return false;

SetAppIcon();

Expand Down Expand Up @@ -125,16 +123,7 @@ void CGame::UpdateDisplaySize(const Extent& newSize)
appliedResolution_ = GameResolution;
appliedFullscreen_ = fullscreen;

Surf_Display = makeRGBSurface(GameResolution.x, GameResolution.y, true);
displayTexture_.createEmpty(GameResolution);

setGLViewport();
for(auto& menu : Menus)
{
menu->resetSurface();
}
for(auto& wnd : Windows)
wnd->resetSurface();
}

bool CGame::Init()
Expand Down Expand Up @@ -182,7 +171,7 @@ bool CGame::Init()
// std::cout << "\nShow loading screen...";
showLoadScreen = true;
glClear(GL_COLOR_BUFFER_BIT);
splashBg_.Draw(Rect(0, 0, GameResolution.x, GameResolution.y));
splashBg_.draw(Rect(0, 0, GameResolution.x, GameResolution.y));
SDL_GL_SwapWindow(window_.get());

GameDataLoader gdLoader(global::worldDesc);
Expand Down
64 changes: 37 additions & 27 deletions CGame_Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CIO/CWindow.h"
#include "CMap.h"
#include "CSurface.h"
#include "Texture.h"
#include "globals.h"
#include <glad/glad.h>
#ifdef _WIN32
Expand Down Expand Up @@ -40,46 +41,49 @@ void CGame::SetAppIcon()
void CGame::Render()
{
glClear(GL_COLOR_BUFFER_BIT);
SDL_FillRect(Surf_Display.get(), nullptr, SDL_MapRGBA(Surf_Display->format, 0, 0, 0, 0));
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// if the S2 loading screen is shown, render only this until user clicks a mouse button
if(showLoadScreen)
{
splashBg_.Draw(Rect(0, 0, GameResolution.x, GameResolution.y));
splashBg_.draw(Rect(0, 0, GameResolution.x, GameResolution.y));
SDL_GL_SwapWindow(window_.get());
return;
}

// render the map if active
if(MapObj && MapObj->isActive())
{
CSurface::Draw(Surf_Display, MapObj->getSurface(), 0, 0);
std::array<char, 100> textBuffer;
// text for x and y of vertex (shown in upper left corner)
std::snprintf(textBuffer.data(), textBuffer.size(), "%d %d", MapObj->getVertexX(), MapObj->getVertexY());
CFont::writeText(Surf_Display, textBuffer.data(), Position(20, 20));
// text for MinReduceHeight and MaxRaiseHeight
std::snprintf(textBuffer.data(), textBuffer.size(),
"min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A",
MapObj->getMinReduceHeight(), MapObj->getMaxRaiseHeight());
CFont::writeText(Surf_Display, textBuffer.data(), Position(100, 20));
// text for MovementLocked
if(MapObj->isHorizontalMovementLocked() && MapObj->isVerticalMovementLocked())
CFont::writeText(Surf_Display, "Movement locked (F9 or F10 to unlock)", Position(20, 40), FontSize::Large,
FontColor::Orange);
else if(MapObj->isHorizontalMovementLocked())
CFont::writeText(Surf_Display, "Horizontal movement locked (F9 to unlock)", Position(20, 40),
FontSize::Large, FontColor::Orange);
else if(MapObj->isVerticalMovementLocked())
CFont::writeText(Surf_Display, "Vertical movement locked (F10 to unlock)", Position(20, 40),
FontSize::Large, FontColor::Orange);
if(auto* mapSurf = MapObj->getSurface())
{
std::array<char, 100> textBuffer;
std::snprintf(textBuffer.data(), textBuffer.size(), "%d %d", MapObj->getVertexX(), MapObj->getVertexY());
CFont::writeText(mapSurf, textBuffer.data(), 20, 20);
std::snprintf(textBuffer.data(), textBuffer.size(),
"min. height: %#04x/0x3C max. height: %#04x/0x3C NormalNull: 0x0A",
MapObj->getMinReduceHeight(), MapObj->getMaxRaiseHeight());
CFont::writeText(mapSurf, textBuffer.data(), 100, 20);
if(MapObj->isHorizontalMovementLocked() && MapObj->isVerticalMovementLocked())
CFont::writeText(mapSurf, "Movement locked (F9 or F10 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);
else if(MapObj->isHorizontalMovementLocked())
CFont::writeText(mapSurf, "Horizontal movement locked (F9 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);
else if(MapObj->isVerticalMovementLocked())
CFont::writeText(mapSurf, "Vertical movement locked (F10 to unlock)", 20, 40, FontSize::Large,
FontColor::Orange);

mapTex_.load(mapSurf);
mapTex_.draw(Rect(0, 0, GameResolution.x, GameResolution.y));
}
}

// render active menus
for(auto& Menu : Menus)
{
if(Menu->isActive())
CSurface::Draw(Surf_Display, Menu->getSurface(), 0, 0);
Menu->draw(Position(0, 0));
}

// render windows ordered by priority
Expand All @@ -96,7 +100,7 @@ void CGame::Render()
for(auto& Window : Windows)
{
if(Window->getPriority() == actualPriority)
CSurface::Draw(Surf_Display, Window->getSurface(), Window->getX(), Window->getY());
Window->draw(Position(0, 0));
}
}

Expand All @@ -105,7 +109,6 @@ void CGame::Render()
#endif

++framesPassedSinceLastFps;

const auto curTicks = SDL_GetTicks();
const auto diffTicks = curTicks - lastFpsTick;
if(diffTicks > 1000)
Expand All @@ -114,9 +117,16 @@ void CGame::Render()
framesPassedSinceLastFps = 0;
lastFpsTick = curTicks;
}
CSurface::Draw(Surf_Display, lastFps.getSurface(), 0, 0);
lastFps.draw(Position(0, 0));

const auto& cursorImg = Cursor.clicked ? (Cursor.button.right ? cross_ : cursorClicked_) : cursor_;
cursorImg.draw(Cursor.pos);

RenderPresent();
SDL_GL_SwapWindow(window_.get());

#ifdef _ADMINMODE
FrameCounter++;
#endif

if(msWait)
SDL_Delay(msWait);
Expand Down
Loading