From 5c9083ce5610ee2546bc05d2f2a1ab647156dca2 Mon Sep 17 00:00:00 2001 From: pietrorinaldiunive <898756@stud.unive.it> Date: Sat, 11 Nov 2023 11:39:41 +0100 Subject: [PATCH 1/7] added optional counterparts from libprimis --- cube.h | 1 + iengine.h | 3 ++- slot.h | 10 +++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cube.h b/cube.h index 381b140..bd407a9 100644 --- a/cube.h +++ b/cube.h @@ -47,6 +47,7 @@ #include #include #include +#include #ifdef WIN32 #define WIN32_LEAN_AND_MEAN diff --git a/iengine.h b/iengine.h index 4405e91..b9a9418 100644 --- a/iengine.h +++ b/iengine.h @@ -7,6 +7,7 @@ * the game code to expose functions to the game. */ +#include "cube.h" #ifndef IENGINE_H_ #define IENGINE_H_ @@ -2062,7 +2063,7 @@ extern int showmat; /**< treat as bool, determines whether material outlines are * * @return an integer corresponding to the bitmask value of the material */ -extern int findmaterial(const char *name); +extern std::optional findmaterial(const char *name); // octaworld diff --git a/slot.h b/slot.h index 44d8ddf..bb790a4 100644 --- a/slot.h +++ b/slot.h @@ -112,7 +112,7 @@ struct Slot virtual VSlot &emptyvslot(); - virtual int cancombine(int type)const; + virtual std::optional cancombine(int type) const; virtual bool shouldpremul(int) const { return false; @@ -122,14 +122,14 @@ struct Slot * @brief Attempts to find a tex with index type. * * Searches for a tex with the type passed, searching only for the part of the - * sts vector after `last`. If none is found, returns -1. + * sts vector after `last`. * * @param type the type to seach for * @param last the last index to not look at * - * @return the index where the type was found + * @return the index where the type was found, else std::nullopt. */ - int findtextype(int type, int last = -1) const; + std::optional findtextype(int type, int last = -1) const; void load(int index, Slot::Tex &t); void load(); @@ -265,7 +265,7 @@ struct DecalSlot : Slot, VSlot return *this; } - int cancombine(int type) const; + std::optional cancombine(int type) const; bool shouldpremul(int type) const; void reset() From 1035bd82edf50a5d5729d595e9b9159d34e379e2 Mon Sep 17 00:00:00 2001 From: pietrorinaldiunive <898756@stud.unive.it> Date: Sat, 11 Nov 2023 12:00:47 +0100 Subject: [PATCH 2/7] oopsie --- iengine.h | 1 - 1 file changed, 1 deletion(-) diff --git a/iengine.h b/iengine.h index b9a9418..a912f23 100644 --- a/iengine.h +++ b/iengine.h @@ -7,7 +7,6 @@ * the game code to expose functions to the game. */ -#include "cube.h" #ifndef IENGINE_H_ #define IENGINE_H_ From d0ab3a00995935d680438848c56e7723c4bddfff Mon Sep 17 00:00:00 2001 From: pietrorinaldiunive <898756@stud.unive.it> Date: Sat, 11 Nov 2023 12:07:14 +0100 Subject: [PATCH 3/7] added optionals for sound --- sound.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound.h b/sound.h index 582f26b..97b8fa7 100644 --- a/sound.h +++ b/sound.h @@ -63,7 +63,7 @@ class SoundEngine * @param radius distance over which sound is audible (in size 0 cubes) * @param expire maximum time before the sound stops playing */ - int playsound(int n, const vec *loc = nullptr, extentity *ent = nullptr, int flags = 0, int loops = 0, int fade = 0, int chanid = -1, int radius = 0, int expire = -1); + std::optional playsound(int n, const vec *loc = nullptr, extentity *ent = nullptr, int flags = 0, int loops = 0, int fade = 0, int chanid = -1, int radius = 0, int expire = -1); /** * @brief Stops playing a sound of index n in the specificied channel. @@ -415,7 +415,7 @@ class SoundEngine std::vector configs; const char *dir; SoundType(const char *dir, SoundEngine& p); - int findsound(const char *name, int vol); + std::optional findsound(const char *name, int vol); int addslot(const char *name, int vol); int addsound(const char *name, int vol, int maxuses = 0); void addalt(const char *name, int vol); From 24143cd7852bd83e4e8c61ec2ca7ede7f55a89d1 Mon Sep 17 00:00:00 2001 From: Duskhorn Date: Tue, 21 Nov 2023 09:58:46 +0100 Subject: [PATCH 4/7] updated documentation --- sound.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound.h b/sound.h index 97b8fa7..aa2b9dc 100644 --- a/sound.h +++ b/sound.h @@ -52,6 +52,9 @@ class SoundEngine /** * @brief Plays a sound with the given attributes. + * + * Returns the wrapped channel id + * Returns std::nullopt in case of failure * * @param n index of the sound to play * @param loc world location to play at From ea6b7297662e3f819d65a57c4af41ab4d01efecb Mon Sep 17 00:00:00 2001 From: Duskhorn Date: Tue, 21 Nov 2023 09:59:12 +0100 Subject: [PATCH 5/7] updated documentation 2 --- sound.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound.h b/sound.h index aa2b9dc..2cabd61 100644 --- a/sound.h +++ b/sound.h @@ -53,8 +53,8 @@ class SoundEngine /** * @brief Plays a sound with the given attributes. * - * Returns the wrapped channel id - * Returns std::nullopt in case of failure + * Returns the wrapped channel id. + * Returns std::nullopt in case of failure. * * @param n index of the sound to play * @param loc world location to play at From c23fe74f8b41612ceb16e2fdd786ebea47ea388d Mon Sep 17 00:00:00 2001 From: Duskhorn Date: Tue, 21 Nov 2023 10:02:37 +0100 Subject: [PATCH 6/7] further updated docs --- iengine.h | 2 +- sound.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iengine.h b/iengine.h index a912f23..803fcf8 100644 --- a/iengine.h +++ b/iengine.h @@ -2060,7 +2060,7 @@ extern int showmat; /**< treat as bool, determines whether material outlines are * * @param name a C string with the name of the material to look up * - * @return an integer corresponding to the bitmask value of the material + * @return an integer corresponding to the bitmask value of the material or std::nullopt if it fails */ extern std::optional findmaterial(const char *name); diff --git a/sound.h b/sound.h index 2cabd61..80a0e9e 100644 --- a/sound.h +++ b/sound.h @@ -53,8 +53,6 @@ class SoundEngine /** * @brief Plays a sound with the given attributes. * - * Returns the wrapped channel id. - * Returns std::nullopt in case of failure. * * @param n index of the sound to play * @param loc world location to play at @@ -65,6 +63,8 @@ class SoundEngine * @param chanid music channel index to use * @param radius distance over which sound is audible (in size 0 cubes) * @param expire maximum time before the sound stops playing + * + * @return the channel id or std::nullopt in case of failure. */ std::optional playsound(int n, const vec *loc = nullptr, extentity *ent = nullptr, int flags = 0, int loops = 0, int fade = 0, int chanid = -1, int radius = 0, int expire = -1); From 5ed31f69254dcc51fd50fd2e97d1bcda29e01549 Mon Sep 17 00:00:00 2001 From: Duskhorn Date: Tue, 21 Nov 2023 10:04:59 +0100 Subject: [PATCH 7/7] added playsoundname --- sound.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound.h b/sound.h index 80a0e9e..79376ff 100644 --- a/sound.h +++ b/sound.h @@ -104,8 +104,10 @@ class SoundEngine * @param chanid music channel index to use * @param radius distance over which sound is audible (in size 0 cubes) * @param expire maximum time before the sound stops playing + * + * @return the channel id where the song gets played or std::nullopt if it fails */ - int playsoundname(const char *s, const vec *loc, int vol, int flags, int loops, int fade, int chanid, int radius, int expire); + std::optional playsoundname(const char *s, const vec *loc, int vol, int flags, int loops, int fade, int chanid, int radius, int expire); /** * @brief Starts SDL_Mixer and initializes startup sound channels.