Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::optional #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <set>
#include <unordered_set>
#include <fstream>
#include <optional>

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
Expand Down
4 changes: 2 additions & 2 deletions iengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2145,9 +2145,9 @@ 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 int findmaterial(const char *name);
extern std::optional<int> findmaterial(const char *name);

// octaworld

Expand Down
10 changes: 5 additions & 5 deletions slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct Slot

virtual VSlot &emptyvslot();

virtual int cancombine(int type)const;
virtual std::optional<int> cancombine(int type) const;
virtual bool shouldpremul(int) const
{
return false;
Expand All @@ -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<int> findtextype(int type, int last = -1) const;

void load(int index, Slot::Tex &t);
void load();
Expand Down Expand Up @@ -265,7 +265,7 @@ struct DecalSlot final : Slot, VSlot
return *this;
}

int cancombine(int type) const override final;
std::optional<int> cancombine(int type) const override final;
bool shouldpremul(int type) const override final;

void reset()
Expand Down
11 changes: 8 additions & 3 deletions sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SoundEngine

/**
* @brief Plays a sound with the given attributes.
*
*
* @param n index of the sound to play
* @param loc world location to play at
Expand All @@ -62,8 +63,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 or std::nullopt in case of failure.
*/
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<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);

/**
* @brief Stops playing a sound of index n in the specificied channel.
Expand Down Expand Up @@ -101,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<int> 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.
Expand Down Expand Up @@ -415,7 +420,7 @@ class SoundEngine
std::vector<SoundConfig> configs;
const char *dir;
SoundType(const char *dir, SoundEngine& p);
int findsound(const char *name, int vol);
std::optional<int> 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);
Expand Down