Skip to content

Commit de96882

Browse files
committed
Port to SDL3
1 parent 10839e8 commit de96882

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+330
-307
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ jobs:
3434
triplet: x64-linux
3535
platform-name: linux.x64
3636
butler-url: https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default
37+
# libltdl-dev needed to build libxcrypt sub-dependency, others needed for sdl3
38+
apt-packages: libltdl-dev libx11-dev libxft-dev libxext-dev libwayland-dev libxkbcommon-dev libegl1-mesa-dev libibus-1.0-dev
3739

3840
env:
3941
# Indicates the CMake build directory where project files and binaries are being produced.
4042
CMAKE_BUILD_DIR: ${{ github.workspace }}/build
4143
archive-name:
4244

4345
steps:
46+
- name: Install APT packages
47+
if: matrix.apt-packages
48+
run: sudo apt-get install ${{ matrix.apt-packages }}
4449
# fetch-depth=0 and v1 are needed for 'git describe' to work correctly.
4550
- uses: actions/checkout@v4
4651
with:

.vscode/settings.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@
8686
"xtree": "cpp",
8787
"*.rh": "cpp",
8888
"set": "cpp",
89-
"random": "cpp"
89+
"random": "cpp",
90+
"any": "cpp",
91+
"bitset": "cpp",
92+
"complex": "cpp",
93+
"condition_variable": "cpp",
94+
"coroutine": "cpp",
95+
"expected": "cpp",
96+
"fstream": "cpp",
97+
"mutex": "cpp",
98+
"source_location": "cpp",
99+
"stop_token": "cpp",
100+
"thread": "cpp",
101+
"typeindex": "cpp",
102+
"variant": "cpp",
103+
"cfenv": "cpp",
104+
"queue": "cpp",
105+
"ranges": "cpp",
106+
"span": "cpp",
107+
"stack": "cpp"
90108
}
91109
}

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE NO_LUA)
3939

4040
add_subdirectory(umbra)
4141

42-
find_package(SDL2 CONFIG REQUIRED)
42+
find_package(SDL3 CONFIG REQUIRED)
4343
find_package(libtcod CONFIG REQUIRED)
4444
target_link_libraries(
4545
${PROJECT_NAME}
4646
PRIVATE
47-
SDL2::SDL2
48-
SDL2::SDL2main
47+
SDL3::SDL3
4948
libtcod::libtcod
5049
umbra::umbra
5150
)

src/bas_aidirector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void AiDirector::setLevelCoef(float coef) {
4747
levelCoef=coef;
4848
waitTimer=0.0f;
4949
float maxHorde=config.getIntProperty("config.aidirector.hordeDelay")* (1.0f-0.5f*coef);
50-
hordeTimer=MIN(maxHorde,hordeTimer);
50+
hordeTimer=std::min(maxHorde,hordeTimer);
5151
}
5252
void AiDirector::update(float elapsed) {
5353
static float waveLength=config.getFloatProperty("config.aidirector.waveLength");
@@ -126,7 +126,7 @@ void AiDirector::spawnMiniBoss(Creature *cr, bool withItem) {
126126
void AiDirector::spawnMiniBosses() {
127127
#define MAXNUM 2
128128
int level=gameEngine->dungeon->level;
129-
level=MIN(MAXNUM,level);
129+
level=std::min(MAXNUM,level);
130130
int typ=TCODRandom::getInstance()->getInt(0,level);
131131
Creature *cr=NULL;
132132
switch (typ) {

src/bas_entity.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ DynamicEntity::CollisionType DynamicEntity::updateMove(float elapsed, float boun
8686
// ##
8787
// ##
8888
// .
89-
float fdx=ABS(dx);
90-
float fdy=ABS(dy);
89+
float fdx=std::abs(dx);
90+
float fdy=std::abs(dy);
9191
if ( fdx >= fdy ) dy=-dy;
9292
if ( fdy >= fdx ) dx=-dx;
9393
} else if (! xwalk ) {
@@ -107,8 +107,8 @@ DynamicEntity::CollisionType DynamicEntity::updateMove(float elapsed, float boun
107107
}
108108
} else {
109109
// on a walkable cell
110-
if ( hitPlayer && ABS(curoldx - (int)gameEngine->player->x) < 2
111-
&& ABS(curoldy - (int)gameEngine->player->y) < 2 ) {
110+
if ( hitPlayer && std::abs(curoldx - (int)gameEngine->player->x) < 2
111+
&& std::abs(curoldy - (int)gameEngine->player->y) < 2 ) {
112112
x=oldx;y=oldy;
113113
speed=0;
114114
return PLAYER;

src/bas_entity.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ public :
8888
}
8989
// smallest rectangle containing this and r
9090
void merge(const Rect &r) {
91-
float minx = MIN(x,r.x);
92-
float maxx = MAX(x+w,r.x+r.w);
93-
float miny = MIN(y,r.y);
94-
float maxy = MAX(y+h,r.y+r.h);
91+
float minx = std::min(x,r.x);
92+
float maxx = std::max(x+w,r.x+r.w);
93+
float miny = std::min(y,r.y);
94+
float maxy = std::max(y+h,r.y+r.h);
9595
x = minx;
9696
w = (int)(maxx-minx);
9797
y = miny;
9898
h = (int)(maxy-miny);
9999
}
100100
// intersection of this and r
101101
void intersect(const Rect &r) {
102-
float minx = MAX(x,r.x);
103-
float maxx = MIN(x+w,r.x+r.w);
104-
float miny = MAX(y,r.y);
105-
float maxy = MIN(y+h,r.y+r.h);
102+
float minx = std::max(x,r.x);
103+
float maxx = std::min(x+w,r.x+r.w);
104+
float miny = std::max(y,r.y);
105+
float maxy = std::min(y+h,r.y+r.h);
106106
x=minx;
107107
y=miny;
108108
w=(int)(maxx-minx);

src/bas_gameengine.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ void GameEngine::recomputeCanopy(Item *it) {
9696
if (it) {
9797
// reset only for one tree
9898
Rect r(it->x*2-treeRadius-1,it->y*2-treeRadius-1,treeRadius*2+2,treeRadius*2+2);
99-
r.x=MAX(0,r.x);
100-
r.y=MAX(0,r.y);
101-
r.w=(int)MIN(dungeon->width*2-1-r.x,r.w);
102-
r.h=(int)MIN(dungeon->height*2-1-r.y,r.h);
99+
r.x=std::max(0.0f,r.x);
100+
r.y=std::max(0.0f,r.y);
101+
r.w=std::min<int>(dungeon->width * 2 - 1 - r.x, r.w);
102+
r.h=std::min<int>(dungeon->height * 2 - 1 - r.y, r.h);
103103
for (int x=(int)r.x; x < (int)(r.x+r.w); x++) {
104104
for (int y=(int)r.y; y < (int)(r.y+r.h); y++) {
105105
if ( IN_RECTANGLE(x,y,dungeon->width*2,dungeon->height*2)) {
@@ -186,7 +186,7 @@ void GameEngine::computeAspectRatio() {
186186
void GameEngine::hitFlash() {
187187
static float hitFlashDelay=config.getFloatProperty("config.display.hitFlashDelay");
188188
hitFlashAmount+=hitFlashDelay;
189-
hitFlashAmount=MIN(5*hitFlashDelay,hitFlashAmount);
189+
hitFlashAmount=std::min(5*hitFlashDelay,hitFlashAmount);
190190
}
191191

192192
TCODColor GameEngine::setSepia(const TCODColor &col, float coef) {

src/effects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ bool DamageEffect::execute(int x, int y, Creature *cr, Creature *caster, Skill *
263263
//new Bubble(cr->x,cr->y-1, cr->isPlayer ? TCODColor::lightRed : TCODColor::lightBlue, "blocked");
264264
dmg=0;
265265
//cr->curSta+=5;
266-
//cr->curSta = MIN(cr->maxSta,cr->curSta);
266+
//cr->curSta = std::min(cr->maxSta,cr->curSta);
267267
}
268268
}
269269
if ( dmg > 0 ) {

src/input_movement.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <array>
33
#include <tuple>
44

5-
#include <SDL.h>
5+
#include <SDL3/SDL_events.h>
66

77
/// @brief Simple mapping of movement keys to directions.
88
struct MoveKey {

src/item.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -985,11 +985,11 @@ Item *Item::getRandomWeapon(const char *typeName,ItemClass itemClass) {
985985
switch(modType) {
986986
case MOD_RELOAD :
987987
weapon->reloadDelay -= rng->getFloat(0.05f, MAX_RELOAD_BONUS);
988-
weapon->reloadDelay = MAX(0.1f,weapon->reloadDelay);
988+
weapon->reloadDelay = std::max(0.1f,weapon->reloadDelay);
989989
break;
990990
case MOD_CAST :
991991
weapon->castDelay -= rng->getFloat(0.05f, MAX_CAST_BONUS);
992-
weapon->castDelay = MAX(0.1f,weapon->reloadDelay);
992+
weapon->castDelay = std::max(0.1f,weapon->reloadDelay);
993993
break;
994994
case MOD_MODIFIER :
995995
ItemModifierId id=(ItemModifierId)0;
@@ -1007,7 +1007,7 @@ Item *Item::getRandomWeapon(const char *typeName,ItemClass itemClass) {
10071007
}
10081008
}
10091009
weapon->damages += weapon->damages * (int)(itemClass)*0.2f; // 20% increase per color level
1010-
weapon->damages = MIN(1.0f,weapon->damages);
1010+
weapon->damages = std::min(1.0f,weapon->damages);
10111011
// build components
10121012
weapon->generateComponents();
10131013
return weapon;
@@ -1308,8 +1308,8 @@ void Item::renderGenericDescription(int x, int y, bool below, bool frame) {
13081308
float maxDamages = 15 * (featAttack->maxCastDelay + featAttack->maxReloadDelay ) * featAttack->maxDamagesCoef;
13091309
minDamages += minDamages * (int)(itemClass)*0.2f;
13101310
maxDamages += maxDamages * (int)(itemClass)*0.2f;
1311-
minDamages=(int)MIN(1.0f,minDamages);
1312-
maxDamages=(int)MIN(1.0f,maxDamages);
1311+
minDamages=std::min<int>(1.0f,minDamages);
1312+
maxDamages=std::min<int>(1.0f,maxDamages);
13131313

13141314
if ( minDamages != maxDamages ) {
13151315
descCon->print(CON_W/4,cy++,"%d-%d damages/hit", (int)minDamages,(int)maxDamages);
@@ -1530,8 +1530,8 @@ bool Item::update(float elapsed, TCOD_key_t key, TCOD_mouse_t *mouse) {
15301530
// ##
15311531
// ##
15321532
// .
1533-
float fdx=ABS(dx);
1534-
float fdy=ABS(dy);
1533+
float fdx=std::abs(dx);
1534+
float fdy=std::abs(dy);
15351535
if ( fdx >= fdy ) dy=-dy;
15361536
if ( fdy >= fdx ) dx=-dx;
15371537
} else if (! xwalk ) {
@@ -1552,8 +1552,8 @@ bool Item::update(float elapsed, TCOD_key_t key, TCOD_mouse_t *mouse) {
15521552
} else {
15531553
ItemFeatureAttack *feat=(ItemFeatureAttack *)getFeature(ItemFeature::ATTACK);
15541554
if ( feat ) {
1555-
if (!owner->isPlayer() && ABS(curoldx - (int)gameEngine->player->x) < 2
1556-
&& ABS(curoldy - (int)gameEngine->player->y) < 2 ) {
1555+
if (!owner->isPlayer() && std::abs(curoldx - (int)gameEngine->player->x) < 2
1556+
&& std::abs(curoldy - (int)gameEngine->player->y) < 2 ) {
15571557
// a projectile hits the player
15581558
gameEngine->player->takeDamage(TCODRandom::getInstance()->getFloat(feat->minDamagesCoef,feat->maxDamagesCoef));
15591559
x=oldx;y=oldy;

0 commit comments

Comments
 (0)