Skip to content

Commit

Permalink
Switch to C++20
Browse files Browse the repository at this point in the history
glibc compatibility remains the same, except for the Aarch64 build which
now requires glibc 2.35+ (Ubuntu 22.04 Jammy, Debian 12 Bookworm)
  • Loading branch information
glebm committed Aug 30, 2023
1 parent caa4c2c commit 04fb24d
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 59 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/Linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@ concurrency:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Create Build Environment
run: |
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7
Packaging/nix/debian-cross-aarch64-prep.sh
run: Packaging/nix/debian-cross-aarch64-prep.sh

- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v2-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v2-
key: ${{ github.workflow }}-v5-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v5-

- name: Build
working-directory: ${{github.workspace}}
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/Linux_x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ jobs:
with:
fetch-depth: 0

- name: Install GCC
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -yq --no-install-recommends gcc-13 g++-13 g++-13-multilib
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 --slave /usr/bin/g++ g++ /usr/bin/g++-13
- name: Create Build Environment
run: |
# Work around the somewhat broken packages in the GitHub Actions Ubuntu 20.04 image.
# https://github.com/actions/runner-images/issues/4620#issuecomment-981333260
sudo apt-get -y install --allow-downgrades libpcre2-8-0=10.34-7
Packaging/nix/debian-cross-i386-prep.sh
Packaging/nix/debian-cross-i386-prep.sh --no-gcc
- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v3-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v3-
key: ${{ github.workflow }}-v5-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v5-

- name: Build
working-directory: ${{github.workspace}}
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/Linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ jobs:
with:
fetch-depth: 0

- name: Install GCC
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -yq --no-install-recommends gcc-13 g++-13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 --slave /usr/bin/g++ g++ /usr/bin/g++-13
- name: Create Build Environment
run: Packaging/nix/debian-host-prep.sh
run: Packaging/nix/debian-host-prep.sh --no-gcc

- name: Cache CMake build folder
uses: actions/cache@v3
with:
path: build
key: ${{ github.workflow }}-v2-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v2-
key: ${{ github.workflow }}-v4-${{ github.sha }}
restore-keys: ${{ github.workflow }}-v4-

- name: Build
working-directory: ${{github.workspace}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Linux_x86_64_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,9 @@ if(GPERF)
endif()
endif()

# Despite setting C++ standard to 20, features from this version are not being used.
# DevilutionX is compatible with C++ 17.
# Here we set it to 20 only to take advantage of the fmt::format build time errors.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # for clang-tidy
set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
Expand Down
16 changes: 13 additions & 3 deletions Packaging/nix/debian-cross-aarch64-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ LIST
cat /etc/apt/sources.list
fi


PACKAGES=(
cmake git smpq gettext
libsdl2-dev:arm64 libsdl2-image-dev:arm64 libsodium-dev:arm64
libsimpleini-dev:arm64 libpng-dev:arm64 libbz2-dev:arm64 libfmt-dev:arm64
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(crossbuild-essential-arm64)
fi


sudo dpkg --add-architecture arm64
sudo apt-get update
sudo apt-get install -y cmake git smpq gettext crossbuild-essential-arm64 \
libsdl2-dev:arm64 libsdl2-image-dev:arm64 libsodium-dev:arm64 \
libsimpleini-dev:arm64 libpng-dev:arm64 libbz2-dev:arm64 libfmt-dev:arm64
sudo apt-get install -y "${PACKAGES[@]}"
16 changes: 12 additions & 4 deletions Packaging/nix/debian-cross-i386-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
set -euo pipefail
set -x

PACKAGES=(
cmake git smpq gettext
libsdl2-dev:i386 libsdl2-image-dev:i386 libsodium-dev:i386
libpng-dev:i386 libbz2-dev:i386 libfmt-dev:i386
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(g++-multilib)
fi

sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install --ignore-hold -y \
cmake g++-multilib git smpq gettext \
libsdl2-dev:i386 libsdl2-image-dev:i386 libsodium-dev:i386 \
libpng-dev:i386 libbz2-dev:i386 libfmt-dev:i386
sudo apt-get install --ignore-hold -y "${PACKAGES[@]}"

14 changes: 11 additions & 3 deletions Packaging/nix/debian-host-prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
set -euo pipefail
set -x

sudo apt-get update
sudo apt-get install -y \
rpm pkg-config cmake g++ git smpq gettext libsdl2-dev libsdl2-image-dev libsodium-dev \
PACKAGES=(
rpm pkg-config cmake git smpq gettext libsdl2-dev libsdl2-image-dev libsodium-dev
libpng-dev libbz2-dev libfmt-dev
)

if (( $# < 1 )) || [[ "$1" != --no-gcc ]]; then
PACKAGES+=(g++)
fi

sudo apt-get update
sudo apt-get install -y "${PACKAGES[@]}"

43 changes: 15 additions & 28 deletions Source/towners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ void InitSmith(Towner &towner, const TownerData &townerData)
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\smith\\smithn", 16, 3);
towner.name = _("Griswold the Blacksmith");
towner.gossip = PickRandomlyAmong({ TEXT_GRISWOLD2, TEXT_GRISWOLD3, TEXT_GRISWOLD4, TEXT_GRISWOLD5, TEXT_GRISWOLD6, TEXT_GRISWOLD7, TEXT_GRISWOLD8, TEXT_GRISWOLD9, TEXT_GRISWOLD10, TEXT_GRISWOLD12, TEXT_GRISWOLD13 });
Expand All @@ -100,8 +99,7 @@ void InitBarOwner(Towner &towner, const TownerData &townerData)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\twnf\\twnfn", 16, 3);
towner.name = _("Ogden the Tavern owner");
towner.gossip = PickRandomlyAmong({ TEXT_OGDEN2, TEXT_OGDEN3, TEXT_OGDEN4, TEXT_OGDEN5, TEXT_OGDEN6, TEXT_OGDEN8, TEXT_OGDEN9, TEXT_OGDEN10 });
Expand All @@ -110,8 +108,7 @@ void InitBarOwner(Towner &towner, const TownerData &townerData)
void InitTownDead(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, "towners\\butch\\deadguy", 8, 6);
towner.name = _("Wounded Townsman");
}
Expand All @@ -132,8 +129,7 @@ void InitWitch(Towner &towner, const TownerData &townerData)
0, 1, 0, 18, 17, 18, 0, 1, 0, 1, 2
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\townwmn1\\witch", 19, 6);
towner.name = _("Adria the Witch");
towner.gossip = PickRandomlyAmong({ TEXT_ADRIA2, TEXT_ADRIA3, TEXT_ADRIA4, TEXT_ADRIA5, TEXT_ADRIA6, TEXT_ADRIA7, TEXT_ADRIA8, TEXT_ADRIA9, TEXT_ADRIA10, TEXT_ADRIA12, TEXT_ADRIA13 });
Expand All @@ -142,8 +138,7 @@ void InitWitch(Towner &towner, const TownerData &townerData)
void InitBarmaid(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, "towners\\townwmn1\\wmnn", 18, 6);
towner.name = _("Gillian the Barmaid");
towner.gossip = PickRandomlyAmong({ TEXT_GILLIAN2, TEXT_GILLIAN3, TEXT_GILLIAN4, TEXT_GILLIAN5, TEXT_GILLIAN6, TEXT_GILLIAN7, TEXT_GILLIAN9, TEXT_GILLIAN10 });
Expand All @@ -152,8 +147,7 @@ void InitBarmaid(Towner &towner, const TownerData &townerData)
void InitBoy(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, "towners\\townboy\\pegkid1", 20, 6);
towner.name = _("Wirt the Peg-legged boy");
towner.gossip = PickRandomlyAmong({ TEXT_WIRT2, TEXT_WIRT3, TEXT_WIRT4, TEXT_WIRT5, TEXT_WIRT6, TEXT_WIRT7, TEXT_WIRT8, TEXT_WIRT9, TEXT_WIRT11, TEXT_WIRT12 });
Expand All @@ -175,8 +169,7 @@ void InitHealer(Towner &towner, const TownerData &townerData)
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\healer\\healer", 20, 6);
towner.name = _("Pepin the Healer");
towner.gossip = PickRandomlyAmong({ TEXT_PEPIN2, TEXT_PEPIN3, TEXT_PEPIN4, TEXT_PEPIN5, TEXT_PEPIN6, TEXT_PEPIN7, TEXT_PEPIN9, TEXT_PEPIN10, TEXT_PEPIN11 });
Expand All @@ -193,8 +186,7 @@ void InitTeller(Towner &towner, const TownerData &townerData)
13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\strytell\\strytell", 25, 3);
towner.name = _("Cain the Elder");
towner.gossip = PickRandomlyAmong({ TEXT_STORY2, TEXT_STORY3, TEXT_STORY4, TEXT_STORY5, TEXT_STORY6, TEXT_STORY7, TEXT_STORY9, TEXT_STORY10, TEXT_STORY11 });
Expand All @@ -210,8 +202,7 @@ void InitDrunk(Towner &towner, const TownerData &townerData)
0, 1, 2, 3, 4, 4, 4, 3, 2, 1
// clang-format on
};
towner.animOrder = AnimOrder;
towner.animOrderSize = sizeof(AnimOrder);
towner.animOrder = { AnimOrder };
LoadTownerAnimations(towner, "towners\\drunk\\twndrunk", 18, 3);
towner.name = _("Farnham the Drunk");
towner.gossip = PickRandomlyAmong({ TEXT_FARNHAM2, TEXT_FARNHAM3, TEXT_FARNHAM4, TEXT_FARNHAM5, TEXT_FARNHAM6, TEXT_FARNHAM8, TEXT_FARNHAM9, TEXT_FARNHAM10, TEXT_FARNHAM11, TEXT_FARNHAM12, TEXT_FARNHAM13 });
Expand All @@ -220,8 +211,7 @@ void InitDrunk(Towner &towner, const TownerData &townerData)
void InitCows(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 128;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};

NewTownerAnim(towner, (*CowSprites)[static_cast<size_t>(townerData.dir)], 12, 3);
towner._tAnimFrame = GenerateRnd(11);
Expand All @@ -246,8 +236,7 @@ void InitCows(Towner &towner, const TownerData &townerData)
void InitFarmer(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, "towners\\farmer\\farmrn2", 15, 3);
towner.name = _("Lester the farmer");
}
Expand All @@ -259,17 +248,15 @@ void InitCowFarmer(Towner &towner, const TownerData &townerData)
celPath = "towners\\farmer\\mfrmrn2";
}
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, celPath, 15, 3);
towner.name = _("Complete Nut");
}

void InitGirl(Towner &towner, const TownerData &townerData)
{
towner._tAnimWidth = 96;
towner.animOrder = nullptr;
towner.animOrderSize = 0;
towner.animOrder = {};
LoadTownerAnimations(towner, "towners\\girl\\girlw1", 20, 6);
towner.name = _("Celia");
}
Expand Down Expand Up @@ -887,9 +874,9 @@ void ProcessTowners()

towner._tAnimCnt = 0;

if (towner.animOrderSize > 0) {
if (!towner.animOrder.empty()) {
towner._tAnimFrameCnt++;
if (towner._tAnimFrameCnt > towner.animOrderSize - 1)
if (towner._tAnimFrameCnt > towner.animOrder.size() - 1)
towner._tAnimFrameCnt = 0;

towner._tAnimFrame = towner.animOrder[towner._tAnimFrameCnt];
Expand Down
4 changes: 2 additions & 2 deletions Source/towners.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <span>
#include <string_view>

#include "items.h"
Expand Down Expand Up @@ -39,7 +40,7 @@ struct Towner {
OptionalOwnedClxSpriteList ownedAnim;
OptionalClxSpriteList anim;
/** Specifies the animation frame sequence. */
const uint8_t *animOrder; // unowned
std::span<const uint8_t> animOrder;
void (*talk)(Player &player, Towner &towner);

std::string_view name;
Expand All @@ -58,7 +59,6 @@ struct Towner {
/** Current frame of animation. */
uint8_t _tAnimFrame;
uint8_t _tAnimFrameCnt;
uint8_t animOrderSize;
_talker_id _ttype;

[[nodiscard]] ClxSprite currentSprite() const
Expand Down

0 comments on commit 04fb24d

Please sign in to comment.