Skip to content

Commit

Permalink
chore: cleanup typing issues and various other warnings here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
Almamu committed May 11, 2024
1 parent 8a8741d commit d652691
Show file tree
Hide file tree
Showing 41 changed files with 136 additions and 137 deletions.
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CCombinedContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::filesystem::path CCombinedContainer::resolveRealFile (const std::string& fi
throw CAssetLoadException (filename, "Cannot resolve file in any of the containers");
}

const void* CCombinedContainer::readFile (const std::string& filename, uint32_t* length) const {
const uint8_t* CCombinedContainer::readFile (const std::string& filename, uint32_t* length) const {
for (const auto cur : this->m_containers) {
try {
// try to read the file on the current container, if the file doesn't exists
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CCombinedContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CCombinedContainer final : public CContainer {
/** @inheritdoc */
[[nodiscard]] std::filesystem::path resolveRealFile (const std::string& filename) const override;
/** @inheritdoc */
[[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override;
[[nodiscard]] const uint8_t* readFile (const std::string& filename, uint32_t* length) const override;

private:
/** The list of containers to search files off from */
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::string CContainer::readFileAsString (const std::string& filename) const {
uint32_t length = 0;

// read file contents and allocate a buffer for a string
const void* contents = this->readFile (std::move (filename), &length);
const uint8_t* contents = this->readFile (filename, &length);
char* buffer = new char [length + 1];

// ensure there's a 0 at the end
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CContainer {
*
* @return
*/
[[nodiscard]] virtual const void* readFile (const std::string& filename, uint32_t* length) const = 0;
[[nodiscard]] virtual const uint8_t* readFile (const std::string& filename, uint32_t* length) const = 0;

/**
* Wrapper for readFile, appends the texture extension at the end of the filename
Expand Down
4 changes: 2 additions & 2 deletions src/WallpaperEngine/Assets/CDirectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ std::filesystem::path CDirectory::resolveRealFile (const std::string& filename)
return std::filesystem::path (this->m_basepath) / filename;
}

const void* CDirectory::readFile (const std::string& filename, uint32_t* length) const {
const uint8_t* CDirectory::readFile (const std::string& filename, uint32_t* length) const {
const std::filesystem::path final = std::filesystem::path (this->m_basepath) / filename;

// first check the cache, if the file is there already just return the data in there
Expand All @@ -47,7 +47,7 @@ const void* CDirectory::readFile (const std::string& filename, uint32_t* length)
fseek (fp, 0, SEEK_SET);

// now read the whole file
auto* contents = new char [size];
auto* contents = new uint8_t [size];

if (fread (contents, size, 1, fp) != 1) {
delete [] contents;
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CDirectory final : public CContainer {
/** @inheritdoc */
[[nodiscard]] std::filesystem::path resolveRealFile (const std::string& filename) const override;
/** @inheritdoc */
[[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override;
[[nodiscard]] const uint8_t* readFile (const std::string& filename, uint32_t* length) const override;

private:
/** The basepath for the directory */
Expand Down
4 changes: 2 additions & 2 deletions src/WallpaperEngine/Assets/CFileEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace WallpaperEngine::Assets {
*/
class CFileEntry {
public:
CFileEntry (const char* address, uint32_t length) : address (address), length (length) {}
CFileEntry (const uint8_t* address, uint32_t length) : address (address), length (length) {}

~CFileEntry () {
delete [] address;
}

/** File contents */
const char* address;
const uint8_t* address;
/** File length */
uint32_t length;
};
Expand Down
6 changes: 3 additions & 3 deletions src/WallpaperEngine/Assets/CPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CPackage::CPackage (std::filesystem::path path) : m_path (std::move (path)) {
this->init ();
}

const void* CPackage::readFile (const std::string& filename, uint32_t* length) const {
const uint8_t* CPackage::readFile (const std::string& filename, uint32_t* length) const {
const auto it = this->m_contents.find (filename);

if (it == this->m_contents.end ())
Expand All @@ -35,7 +35,7 @@ const void* CPackage::readFile (const std::string& filename, uint32_t* length) c
*length = it->second->length;

// clone original first
auto* result = new char [it->second->length];
auto* result = new uint8_t [it->second->length];

memcpy (result, it->second->address, it->second->length);

Expand Down Expand Up @@ -128,7 +128,7 @@ void CPackage::loadFiles (FILE* fp) {
sLog.exception ("Cannot find file ", cur.filename, " from package ", this->m_path);

// allocate memory for the file's contents and read it from the file
char* fileContents = new char [cur.length];
auto* fileContents = new uint8_t [cur.length];

if (fread (fileContents, cur.length, 1, fp) != 1) {
delete [] fileContents;
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Assets/CPackage.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CPackage final : public CContainer {
public:
explicit CPackage (std::filesystem::path path);

[[nodiscard]] const void* readFile (const std::string& filename, uint32_t* length) const override;
[[nodiscard]] const uint8_t* readFile (const std::string& filename, uint32_t* length) const override;

protected:
/**
Expand Down
8 changes: 4 additions & 4 deletions src/WallpaperEngine/Assets/CVirtualContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

using namespace WallpaperEngine::Assets;

void CVirtualContainer::add (const std::string& filename, const char* contents, uint32_t length) {
void CVirtualContainer::add (const std::string& filename, const uint8_t* contents, uint32_t length) {
this->m_virtualFiles.insert (std::make_pair (filename, new CFileEntry (contents, length)));
}

void CVirtualContainer::add (const std::string& filename, const std::string& contents) {
char* copy = new char [contents.length () + 1];
auto* copy = new uint8_t [contents.length () + 1];

// copy the text AND the \0
memcpy (copy, contents.c_str (), contents.length () + 1);
Expand All @@ -19,7 +19,7 @@ void CVirtualContainer::add (const std::string& filename, const std::string& con
this->add (filename, copy, contents.length () + 1);
}

const void* CVirtualContainer::readFile (const std::string& filename, uint32_t* length) const {
const uint8_t* CVirtualContainer::readFile (const std::string& filename, uint32_t* length) const {
const auto cur = this->m_virtualFiles.find (filename);

if (cur == this->m_virtualFiles.end ())
Expand All @@ -29,7 +29,7 @@ const void* CVirtualContainer::readFile (const std::string& filename, uint32_t*
*length = cur->second->length;

// clone original first
char* result = new char [cur->second->length];
auto* result = new uint8_t [cur->second->length];

memcpy (result, cur->second->address, cur->second->length);

Expand Down
4 changes: 2 additions & 2 deletions src/WallpaperEngine/Assets/CVirtualContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CVirtualContainer final : public CContainer {
* @param contents
* @param length
*/
void add (const std::string& filename, const char* contents, uint32_t length);
void add (const std::string& filename, const uint8_t* contents, uint32_t length);

/**
* Adds a new file to the virtual container
Expand All @@ -29,7 +29,7 @@ class CVirtualContainer final : public CContainer {
*/
void add (const std::string& filename, const std::string& contents);
/** @inheritdoc */
const void* readFile (const std::string& filename, uint32_t* length) const override;
const uint8_t* readFile (const std::string& filename, uint32_t* length) const override;

private:
/** The recorded files in this virtual container */
Expand Down
26 changes: 15 additions & 11 deletions src/WallpaperEngine/Audio/CAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CAudioStream::CAudioStream (CAudioContext& context, const std::string& filename)
this->loadCustomContent (filename.c_str ());
}

CAudioStream::CAudioStream (CAudioContext& context, const void* buffer, int length) :
CAudioStream::CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length) :
m_audioContext (context),
m_swrctx (nullptr) {
// setup a custom context first
Expand Down Expand Up @@ -142,13 +142,17 @@ void CAudioStream::loadCustomContent (const char* filename) {
if (avformat_find_stream_info (this->m_formatContext, nullptr) < 0)
sLog.exception ("Cannot determine file format: ", filename);

bool hasAudioStream = false;

// find the audio stream
for (int i = 0; i < this->m_formatContext->nb_streams; i++) {
if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && this->m_audioStream < 0)
for (unsigned int i = 0; i < this->m_formatContext->nb_streams; i++) {
if (this->m_formatContext->streams [i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && hasAudioStream == false) {
hasAudioStream = true;
this->m_audioStream = i;
}
}

if (this->m_audioStream == -1)
if (!hasAudioStream)
sLog.exception ("Cannot find an audio stream in file ", filename);

// get the decoder for it and alloc the required context
Expand Down Expand Up @@ -308,35 +312,35 @@ AVFormatContext* CAudioStream::getFormatContext () {
return this->m_formatContext;
}

int CAudioStream::getAudioStream () {
unsigned int CAudioStream::getAudioStream () const {
return this->m_audioStream;
}

bool CAudioStream::isInitialized () {
bool CAudioStream::isInitialized () const {
return this->m_initialized;
}

void CAudioStream::setRepeat (bool newRepeat) {
this->m_repeat = newRepeat;
}

bool CAudioStream::isRepeat () {
bool CAudioStream::isRepeat () const {
return this->m_repeat;
}

const void* CAudioStream::getBuffer () {
const uint8_t* CAudioStream::getBuffer () {
return this->m_buffer;
}

int CAudioStream::getLength () {
uint32_t CAudioStream::getLength () const {
return this->m_length;
}

int CAudioStream::getPosition () {
uint32_t CAudioStream::getPosition () const {
return this->m_position;
}

void CAudioStream::setPosition (int current) {
void CAudioStream::setPosition (uint32_t current) {
this->m_position = current;
}

Expand Down
24 changes: 12 additions & 12 deletions src/WallpaperEngine/Audio/CAudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CAudioContext;
class CAudioStream {
public:
CAudioStream (CAudioContext& context, const std::string& filename);
CAudioStream (CAudioContext& context, const void* buffer, int length);
CAudioStream (CAudioContext& context, const uint8_t* buffer, uint32_t length);
CAudioStream (CAudioContext& audioContext, AVCodecContext* context);
~CAudioStream ();

Expand Down Expand Up @@ -56,41 +56,41 @@ class CAudioStream {
/**
* @return The audio stream index of the given file
*/
int getAudioStream ();
[[nodiscard]] unsigned int getAudioStream () const;
/**
* @return If the audio stream can be played or not
*/
bool isInitialized ();
[[nodiscard]] bool isInitialized () const;
/**
* @param newRepeat true = repeat, false = no repeat
*/
void setRepeat (bool newRepeat = true);
/**
* @return If the stream is to be repeated at the end or not
*/
bool isRepeat ();
[[nodiscard]] bool isRepeat () const;
/**
* Stops decoding and playbak of the stream
*/
void stop ();
/**
* @return The file data buffer
*/
const void* getBuffer ();
[[nodiscard]] const uint8_t* getBuffer ();
/**
* @return The length of the file data buffer
*/
int getLength ();
[[nodiscard]] uint32_t getLength () const;
/**
* @return The read position of the data buffer
*/
int getPosition ();
[[nodiscard]] uint32_t getPosition () const;
/**
* Updates the read position of the data buffer
*
* @param current
*/
void setPosition (int current);
void setPosition (uint32_t current);
/**
* @return The SDL_cond used to signal waiting for data
*/
Expand Down Expand Up @@ -175,13 +175,13 @@ class CAudioStream {
/** The format context that controls how data is read off the file */
AVFormatContext* m_formatContext = nullptr;
/** The stream index for the audio being played */
int m_audioStream = -1;
unsigned int m_audioStream;
/** File data pointer */
const void* m_buffer {};
const uint8_t* m_buffer {};
/** The length of the file data pointer */
int m_length {};
uint32_t m_length {};
/** The read position on the file data pointer */
int m_position = 0;
uint32_t m_position = 0;

struct MyAVPacketList {
AVPacket* packet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ void pa_stream_read_cb (pa_stream* stream, const size_t /*nbytes*/, void* userda

// Careful when to pa_stream_peek() and pa_stream_drop()!
// c.f. https://www.freedesktop.org/software/pulseaudio/doxygen/stream_8h.html#ac2838c449cde56e169224d7fe3d00824
const void* data = nullptr;
const uint8_t* data = nullptr;
size_t currentSize;
if (pa_stream_peek (stream, &data, &currentSize) != 0) {
if (pa_stream_peek (stream, reinterpret_cast<const void**> (&data), &currentSize) != 0) {
sLog.error ("Failed to peek at stream data...");
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/WallpaperEngine/Core/CObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace WallpaperEngine::Core;
using namespace WallpaperEngine::Assets;
using namespace WallpaperEngine::Core::UserSettings;

CObject::CObject (CScene* scene, CUserSettingBoolean* visible, uint32_t id, std::string name, std::string type,
CObject::CObject (CScene* scene, CUserSettingBoolean* visible, int id, std::string name, std::string type,
CUserSettingVector3* origin, CUserSettingVector3* scale, const glm::vec3& angles) :
m_scene (scene),
m_visible (visible),
Expand Down Expand Up @@ -108,7 +108,7 @@ const std::vector<Objects::CEffect*>& CObject::getEffects () const {
return this->m_effects;
}

const std::vector<uint32_t>& CObject::getDependencies () const {
const std::vector<int>& CObject::getDependencies () const {
return this->m_dependencies;
}

Expand All @@ -129,6 +129,6 @@ void CObject::insertEffect (Objects::CEffect* effect) {
this->m_effects.push_back (effect);
}

void CObject::insertDependency (uint32_t dependency) {
void CObject::insertDependency (int dependency) {
this->m_dependencies.push_back (dependency);
}

0 comments on commit d652691

Please sign in to comment.