Skip to content

Commit

Permalink
Format code with clang-format
Browse files Browse the repository at this point in the history
I thought that I had a formatter enabled in my IDE already, but
apparently I don't. Add the .clang-format file so that CLion uses
ClangFormat and format every file so that my C++ code looks way less
embarrassing.
  • Loading branch information
meisekimiu committed Jun 12, 2024
1 parent c632330 commit 5119c03
Show file tree
Hide file tree
Showing 108 changed files with 2,851 additions and 2,941 deletions.
Empty file added .clang-format
Empty file.
19 changes: 11 additions & 8 deletions src/audio/AudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
#include "Stream.h"

namespace Adagio {
template<class SampleType, class StreamType>
class AudioDevice {
public:
virtual void playSample(const Sample &sample, AudioLibrary<SampleType, StreamType> &audioLibrary) = 0;
template <class SampleType, class StreamType> class AudioDevice {
public:
virtual void
playSample(const Sample &sample,
AudioLibrary<SampleType, StreamType> &audioLibrary) = 0;

virtual void playStream(const Stream &stream, AudioLibrary<SampleType, StreamType> &audioLibrary) = 0;
};
}
virtual void
playStream(const Stream &stream,
AudioLibrary<SampleType, StreamType> &audioLibrary) = 0;
};
} // namespace Adagio

#endif //GL_ADAGIO_AUDIODEVICE_H
#endif // GL_ADAGIO_AUDIODEVICE_H
72 changes: 33 additions & 39 deletions src/audio/AudioLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,36 @@
#include "Stream.h"

namespace Adagio {
template<class SampleType, class StreamType>
class AudioLibrary {
public:
explicit AudioLibrary(AssetLoader<SampleType, AudioMetadata> *sampleLoader,
AssetLoader<StreamType, AudioMetadata> *streamLoader) : sampleLibrary(sampleLoader),
streamLibrary(streamLoader) {
}

Sample loadSample(const std::string &resource) {
return Sample(sampleLibrary.load(resource));
}

SampleType useSample(const Sample &sample) {
return sampleLibrary.useResource(sample);
}

Stream loadStream(const std::string &resource) {
return Stream(streamLibrary.load(resource));
}

StreamType useStream(const Stream &stream) {
return streamLibrary.useResource(stream);
}

void unload(Sample &sample) {
sampleLibrary.unload(sample);
}

void unload(Stream &stream) {
streamLibrary.unload(stream);
}

private:
ResourceLibrary<SampleType, AudioMetadata, AudioHandle> sampleLibrary;
ResourceLibrary<StreamType, AudioMetadata, AudioHandle> streamLibrary;
};
}

#endif //GL_ADAGIO_AUDIOLIBRARY_H
template <class SampleType, class StreamType> class AudioLibrary {
public:
explicit AudioLibrary(AssetLoader<SampleType, AudioMetadata> *sampleLoader,
AssetLoader<StreamType, AudioMetadata> *streamLoader)
: sampleLibrary(sampleLoader), streamLibrary(streamLoader) {}

Sample loadSample(const std::string &resource) {
return Sample(sampleLibrary.load(resource));
}

SampleType useSample(const Sample &sample) {
return sampleLibrary.useResource(sample);
}

Stream loadStream(const std::string &resource) {
return Stream(streamLibrary.load(resource));
}

StreamType useStream(const Stream &stream) {
return streamLibrary.useResource(stream);
}

void unload(Sample &sample) { sampleLibrary.unload(sample); }

void unload(Stream &stream) { streamLibrary.unload(stream); }

private:
ResourceLibrary<SampleType, AudioMetadata, AudioHandle> sampleLibrary;
ResourceLibrary<StreamType, AudioMetadata, AudioHandle> streamLibrary;
};
} // namespace Adagio

#endif // GL_ADAGIO_AUDIOLIBRARY_H
14 changes: 7 additions & 7 deletions src/audio/AudioMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define GL_ADAGIO_AUDIOMETADATA_H

namespace Adagio {
typedef unsigned int AudioHandle;
struct AudioMetadata {
double duration;
};
}
#endif //GL_ADAGIO_AUDIOMETADATA_H
typedef unsigned int AudioHandle;

struct AudioMetadata {
double duration;
};
} // namespace Adagio
#endif // GL_ADAGIO_AUDIOMETADATA_H
37 changes: 16 additions & 21 deletions src/audio/AudioService.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@
#include "AudioMetadata.h"

namespace Adagio {
typedef unsigned int AudioHandle;
typedef unsigned int AudioHandle;

template<class SampleType, class StreamType>
class AudioService {
public:
explicit AudioService(AudioDevice<SampleType, StreamType> *audioPlayer,
AudioLibrary<SampleType, StreamType> *audioLibrary) {
audioDevice = audioPlayer;
this->audioLibrary = audioLibrary;
}
template <class SampleType, class StreamType> class AudioService {
public:
explicit AudioService(AudioDevice<SampleType, StreamType> *audioPlayer,
AudioLibrary<SampleType, StreamType> *audioLibrary) {
audioDevice = audioPlayer;
this->audioLibrary = audioLibrary;
}

void play(Sample sample) {
audioDevice->playSample(sample, *audioLibrary);
}
void play(Sample sample) { audioDevice->playSample(sample, *audioLibrary); }

void play(Stream stream) {
audioDevice->playStream(stream, *audioLibrary);
}
void play(Stream stream) { audioDevice->playStream(stream, *audioLibrary); }

private:
AudioDevice<SampleType, StreamType> *audioDevice;
AudioLibrary<SampleType, StreamType> *audioLibrary;
};
}
private:
AudioDevice<SampleType, StreamType> *audioDevice;
AudioLibrary<SampleType, StreamType> *audioLibrary;
};
} // namespace Adagio

#endif //GL_ADAGIO_AUDIOSERVICE_H
#endif // GL_ADAGIO_AUDIOSERVICE_H
14 changes: 6 additions & 8 deletions src/audio/Sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
#include "AudioMetadata.h"

namespace Adagio {
struct Sample : public Asset<AudioHandle, AudioMetadata> {
Sample(const Asset<AudioHandle, AudioMetadata> &&asset) : Asset(asset.handle, asset.getSecretId(),
asset.getMetadata()) {
struct Sample : public Asset<AudioHandle, AudioMetadata> {
explicit Sample(const Asset<AudioHandle, AudioMetadata> &&asset)
: Asset(asset.handle, asset.getSecretId(), asset.getMetadata()) {}
};
} // namespace Adagio

}
};
}

#endif //GL_ADAGIO_SAMPLE_H
#endif // GL_ADAGIO_SAMPLE_H
14 changes: 7 additions & 7 deletions src/audio/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "AudioMetadata.h"

namespace Adagio {
struct Stream : public Asset<AudioHandle, AudioMetadata> {
Stream(Asset<AudioHandle, AudioMetadata> &&asset) : Asset<AudioHandle, AudioMetadata>(asset.handle,
asset.getSecretId(),
asset.getMetadata()) {}
};
}
struct Stream : public Asset<AudioHandle, AudioMetadata> {
explicit Stream(Asset<AudioHandle, AudioMetadata> &&asset)
: Asset<AudioHandle, AudioMetadata>(asset.handle, asset.getSecretId(),
asset.getMetadata()) {}
};
} // namespace Adagio

#endif //GL_ADAGIO_STREAM_H
#endif // GL_ADAGIO_STREAM_H
40 changes: 21 additions & 19 deletions src/backends/raylib/RaylibGraphicsDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#include "RaylibGraphicsDevice.h"

void RaylibGraphicsDevice::begin() {
ClearBackground({clearColor.r, clearColor.g, clearColor.b, clearColor.a});
BeginDrawing();
ClearBackground({clearColor.r, clearColor.g, clearColor.b, clearColor.a});
BeginDrawing();
}

void RaylibGraphicsDevice::end() {
EndDrawing();
}
void RaylibGraphicsDevice::end() { EndDrawing(); }

void RaylibGraphicsDevice::setClearColor(const Adagio::Color &color) {
clearColor = color;
clearColor = color;
}

static Rectangle AdagioRectToRaylibRect(const Adagio::RectF &rect) {
return {rect.x(), rect.y(), rect.width(), rect.height()};
return {rect.x(), rect.y(), rect.width(), rect.height()};
}

void
RaylibGraphicsDevice::drawTexture(Adagio::Texture2D &texture, const Adagio::RectF &source, const Adagio::RectF &dest,
const Adagio::Vector2d &origin, float rotation, const Adagio::Color &tint) {
RaylibTexture raylibTex = textureManager.useTexture(texture);
DrawTexturePro(raylibTex, AdagioRectToRaylibRect(source), AdagioRectToRaylibRect(dest),
{static_cast<float>(origin.x), static_cast<float>(origin.y)}, rotation,
{tint.r, tint.g, tint.b, tint.a});
void RaylibGraphicsDevice::drawTexture(Adagio::Texture2D &texture,
const Adagio::RectF &source,
const Adagio::RectF &dest,
const Adagio::Vector2d &origin,
float rotation,
const Adagio::Color &tint) {
RaylibTexture raylibTex = textureManager.useTexture(texture);
DrawTexturePro(raylibTex, AdagioRectToRaylibRect(source),
AdagioRectToRaylibRect(dest),
{static_cast<float>(origin.x), static_cast<float>(origin.y)},
rotation, {tint.r, tint.g, tint.b, tint.a});
}

Adagio::AbstractTextureManager *RaylibGraphicsDevice::getTextureManager() {
return &textureManager;
return &textureManager;
}

void RaylibGraphicsDevice::drawText(Font &font, const char *text, const Adagio::Vector2d &position, float fontSize,
float spacing, const Adagio::Color &tint) {

}
void RaylibGraphicsDevice::drawText(Font &font, const char *text,
const Adagio::Vector2d &position,
float fontSize, float spacing,
const Adagio::Color &tint) {}
33 changes: 17 additions & 16 deletions src/backends/raylib/RaylibGraphicsDevice.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
#ifndef GL_ADAGIO_RAYLIBGRAPHICSDEVICE_H
#define GL_ADAGIO_RAYLIBGRAPHICSDEVICE_H

#include "raylib.h"
#include "RaylibTextureLoader.h"
#include "../../graphics/GraphicsDevice.h"
#include "RaylibTextureLoader.h"
#include "raylib.h"

typedef Texture2D RaylibTexture;

class RaylibGraphicsDevice : public Adagio::GraphicsDevice {
private:
RaylibTextureLoader loader;
Adagio::TextureManager<RaylibTexture> textureManager{&loader};
Adagio::Color clearColor{0, 0, 0, 255};
public:
void begin() override;
RaylibTextureLoader loader;
Adagio::TextureManager<RaylibTexture> textureManager{&loader};
Adagio::Color clearColor{0, 0, 0, 255};

void end() override;
public:
void begin() override;

void setClearColor(const Adagio::Color &color) override;
void end() override;

Adagio::AbstractTextureManager *getTextureManager() override;
void setClearColor(const Adagio::Color &color) override;

void drawTexture(Adagio::Texture2D &texture, const Adagio::RectF &source, const Adagio::RectF &dest,
const Adagio::Vector2d &origin, float rotation, const Adagio::Color &tint) override;
Adagio::AbstractTextureManager *getTextureManager() override;

void drawText(Font &font, const char *text, const Adagio::Vector2d &position, float fontSize, float spacing,
const Adagio::Color &tint) override;
void drawTexture(Adagio::Texture2D &texture, const Adagio::RectF &source,
const Adagio::RectF &dest, const Adagio::Vector2d &origin,
float rotation, const Adagio::Color &tint) override;

void drawText(Font &font, const char *text, const Adagio::Vector2d &position,
float fontSize, float spacing,
const Adagio::Color &tint) override;
};


#endif //GL_ADAGIO_RAYLIBGRAPHICSDEVICE_H
#endif // GL_ADAGIO_RAYLIBGRAPHICSDEVICE_H
2 changes: 1 addition & 1 deletion src/backends/raylib/RaylibTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

typedef Texture2D RaylibTexture;

#endif //GL_ADAGIO_RAYLIBTEXTURE_H
#endif // GL_ADAGIO_RAYLIBTEXTURE_H
12 changes: 7 additions & 5 deletions src/backends/raylib/RaylibTextureLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "RaylibTextureLoader.h"
#include <utility>

std::pair<RaylibTexture, Adagio::TextureDimensions> RaylibTextureLoader::load(const char *resource) {
RaylibTexture tex = LoadTexture(resource);
Adagio::TextureDimensions dims{static_cast<unsigned int>(tex.width), static_cast<unsigned int>(tex.height)};
return std::make_pair(tex, dims);
std::pair<RaylibTexture, Adagio::TextureDimensions>
RaylibTextureLoader::load(const char *resource) {
RaylibTexture tex = LoadTexture(resource);
Adagio::TextureDimensions dims{static_cast<unsigned int>(tex.width),
static_cast<unsigned int>(tex.height)};
return std::make_pair(tex, dims);
}

void RaylibTextureLoader::unload(RaylibTexture texture) {
UnloadTexture(texture);
UnloadTexture(texture);
}
10 changes: 5 additions & 5 deletions src/backends/raylib/RaylibTextureLoader.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef GL_ADAGIO_RAYLIBTEXTURELOADER_H
#define GL_ADAGIO_RAYLIBTEXTURELOADER_H

#include "RaylibTexture.h"
#include "../../graphics/TextureLoader.h"
#include "RaylibTexture.h"

class RaylibTextureLoader : public Adagio::TextureLoader<RaylibTexture> {
public:
std::pair<RaylibTexture, Adagio::TextureDimensions> load(const char *resource) override;
std::pair<RaylibTexture, Adagio::TextureDimensions>
load(const char *resource) override;

void unload(RaylibTexture texture) override;
void unload(RaylibTexture texture) override;
};


#endif //GL_ADAGIO_RAYLIBTEXTURELOADER_H
#endif // GL_ADAGIO_RAYLIBTEXTURELOADER_H
10 changes: 4 additions & 6 deletions src/game/SandboxGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
SandboxGame::SandboxGame(Adagio::SpriteBatch &sb) : Adagio::Game(sb) {}

void SandboxGame::init() {
InitWindow(640, 480, "Raylib Test");
SetTargetFPS(60);
InitWindow(640, 480, "Raylib Test");
SetTargetFPS(60);
}

void SandboxGame::loadContent() {
// load game statez
// load game statez
}

void SandboxGame::cleanup() {
CloseWindow();
}
void SandboxGame::cleanup() { CloseWindow(); }
12 changes: 6 additions & 6 deletions src/game/SandboxGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

class SandboxGame : public Adagio::Game {
public:
explicit SandboxGame(Adagio::SpriteBatch &sb);

void init() override;
explicit SandboxGame(Adagio::SpriteBatch &sb);

void loadContent() override;
void init() override;

void cleanup() override;
void loadContent() override;

void cleanup() override;
};

#endif //GL_ADAGIO_SANDBOXGAME_H
#endif // GL_ADAGIO_SANDBOXGAME_H
Loading

0 comments on commit 5119c03

Please sign in to comment.