Skip to content

Commit

Permalink
ci: Enforce Linux line-endings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Oct 27, 2024
1 parent ffd7857 commit 8967e20
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 259 deletions.
42 changes: 42 additions & 0 deletions .github/ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

import os

ignores = [
'.git/',
'build/',
'glad/',
'include/',
'.gitlab-ci-local/',
'.cache/',
]

error_count = 0

def error(path: str, msg: str) -> None:
global error_count
error_count += 1
print('\x1b[1;31m{}\x1b[0;31m{}\x1b[0m'.format(path, msg))

for root, directory, filenames in os.walk('.'):
for filename in filenames:
path = os.path.join(root, filename)[2:]
if any([path.startswith(x) for x in ignores]):
continue
with open(path, 'rb') as file:
line_nr = 1
try:
for line in [x.decode() for x in file.readlines()]:
if len(line) == 0 or line[-1] != '\n':
error(path, ' missing newline at end of file.')
if len(line) > 1:
if line[-2] == '\r':
error(path, ' has Windows line endings.')
break
if line[-2] == ' ' or line[-2] == '\t':
error(path, ':{} has trailing whitespace.'.format(line_nr))
line_nr += 1
except UnicodeError:
pass # binary file

exit(error_count)
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Basic linting
run: .github/ci.py
- name: Install dependencies
run: |
sudo apt update
Expand Down
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ linux:
stage: build
script:
- microdnf install -y cmake ninja-build gcc-c++ fontconfig-devel freetype-devel libvorbis-devel libwebp-devel SDL2-devel libtheora-devel clang util-linux >/dev/null
- .github/ci.py
- CXXFLAGS=-fdiagnostics-color cmake -Bbuild -GNinja
- cd build
- ninja
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindVorbisFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FIND_PATH(VorbisFile_INCLUDE_DIRS
/opt
)

FIND_LIBRARY(VorbisFile_LIBRARIES
FIND_LIBRARY(VorbisFile_LIBRARIES
NAMES vorbisfile
HINTS
$ENV{VORBISDIR}
Expand All @@ -47,7 +47,7 @@ FIND_LIBRARY(VorbisFile_LIBRARIES
/opt
)

FIND_LIBRARY(VorbisFile_LIBRARIES_DEBUG
FIND_LIBRARY(VorbisFile_LIBRARIES_DEBUG
NAMES VorbisFile_d
HINTS
$ENV{VORBISDIR}
Expand Down
66 changes: 33 additions & 33 deletions examples/bike/wheel.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#include "wheel.hpp"

#include <jngl.hpp>

void Wheel::CollisionWith(const jngl::Vec2& collisionPoint) {
jngl::Vec2 perpendicular = position_ - collisionPoint;
boost::qvm::normalize(perpendicular);
double temp2 = -1.5 * boost::qvm::dot(perpendicular, speed_);
jngl::Vec2 temp = temp2 * perpendicular;
speed_ += temp;

const double distance = boost::qvm::mag(collisionPoint - position_);
jngl::Vec2 correction = perpendicular * (radius_ - distance + 0.1);
position_ += correction;
otherWheel_->position_ += correction;
}

void Wheel::Move()
{
speed_ += jngl::Vec2(0, 0.04); // Schwerkraft
speed_ *= 0.99; // Luftreibung
}

void Wheel::draw() const {
jngl::draw("wheel", static_cast<int>(position_.x - radius_),
static_cast<int>(position_.y - radius_));
}

Wheel::Wheel(const double x, const double y) : position_(x, y)
{
}

const int Wheel::radius_ = 32;
#include "wheel.hpp"

#include <jngl.hpp>

void Wheel::CollisionWith(const jngl::Vec2& collisionPoint) {
jngl::Vec2 perpendicular = position_ - collisionPoint;
boost::qvm::normalize(perpendicular);
double temp2 = -1.5 * boost::qvm::dot(perpendicular, speed_);
jngl::Vec2 temp = temp2 * perpendicular;
speed_ += temp;

const double distance = boost::qvm::mag(collisionPoint - position_);
jngl::Vec2 correction = perpendicular * (radius_ - distance + 0.1);
position_ += correction;
otherWheel_->position_ += correction;
}

void Wheel::Move()
{
speed_ += jngl::Vec2(0, 0.04); // Schwerkraft
speed_ *= 0.99; // Luftreibung
}

void Wheel::draw() const {
jngl::draw("wheel", static_cast<int>(position_.x - radius_),
static_cast<int>(position_.y - radius_));
}

Wheel::Wheel(const double x, const double y) : position_(x, y)
{
}

const int Wheel::radius_ = 32;
196 changes: 98 additions & 98 deletions src/jngl/Channel.hpp
Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
// Copyright 2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::Channel class
/// \file

#include "Finally.hpp"

#include <memory>
#include <string>

namespace jngl {

class SoundFile;
struct Stream;

/// An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects"
///
/// Example:
/// \code
/// struct Channels : public jngl::Singleton<Channels> {
/// jngl::Channel& main = jngl::Channel::main();
/// jngl::Channel music;
/// jngl::Channel speech;
/// };
///
/// // somewhere else:
/// Channels::handle().music.loop("background_music01.ogg");
/// \endcode
class Channel {
public:
Channel();
~Channel();

/// Play OGG file on this channel
void play(const std::string& filename);

/// Play an OGG audio file on this channel in a loop
///
/// If it's already playing, this function won't play it twice.
std::shared_ptr<SoundFile> loop(const std::string& filename);

/// Stop OGG file playing on this channel
void stop(const std::string& filename);

/// Pauses the Channel; destroying the returned Finally object will resume again
///
/// Note that this doesn't change the status of jngl::isPlaying as that only depends on the
/// status of the SoundFile.
///
/// Example where you want to pause audio in a menu:
/// \code
/// class PauseMenu : public jngl::Work {
/// jngl::Finally paused;
///
/// public:
/// PauseMenu() : paused(jngl::Channel::main().pause()) {}
/// void step() override { /* ... */ }
/// void draw() const override { /* ... */ }
/// };
/// \endcode
///
/// Or if you want to toggle pausing audio using <kbd>Space</kbd>:
/// \code
/// class PauseExample : public jngl::Work {
/// std::optional<jngl::Finally> paused;
///
/// public:
/// void step() override {
/// if (jngl::keyPressed(jngl::key::Space)) {
/// if (paused) {
/// paused = {}; // calls ~Finally() and resumes playback
/// } else {
/// paused = jngl::Channel::main().pause();
/// }
/// }
/// }
/// void draw() const override { /* ... */ }
/// };
/// \endcode
[[nodiscard]] Finally pause();

/// Set volume of this channel in [0, ∞]. Default is 1.0f
void setVolume(float volume);

/// Returns the main Channel on which jngl::play, jngl::loop, jngl::stop operate
static Channel& main();

/// Internal function for now
void add(std::shared_ptr<Stream>);
/// Internal function for now
void remove(const Stream*);

private:
struct Impl;
std::unique_ptr<Impl> impl;
};

} // namespace jngl
// Copyright 2024 Jan Niklas Hasse <jhasse@bixense.com>
// For conditions of distribution and use, see copyright notice in LICENSE.txt
/// Contains jngl::Channel class
/// \file

#include "Finally.hpp"

#include <memory>
#include <string>

namespace jngl {

class SoundFile;
struct Stream;

/// An audio channel, different channels could be for example: "Music", "Speech" and "Sound Effects"
///
/// Example:
/// \code
/// struct Channels : public jngl::Singleton<Channels> {
/// jngl::Channel& main = jngl::Channel::main();
/// jngl::Channel music;
/// jngl::Channel speech;
/// };
///
/// // somewhere else:
/// Channels::handle().music.loop("background_music01.ogg");
/// \endcode
class Channel {
public:
Channel();
~Channel();

/// Play OGG file on this channel
void play(const std::string& filename);

/// Play an OGG audio file on this channel in a loop
///
/// If it's already playing, this function won't play it twice.
std::shared_ptr<SoundFile> loop(const std::string& filename);

/// Stop OGG file playing on this channel
void stop(const std::string& filename);

/// Pauses the Channel; destroying the returned Finally object will resume again
///
/// Note that this doesn't change the status of jngl::isPlaying as that only depends on the
/// status of the SoundFile.
///
/// Example where you want to pause audio in a menu:
/// \code
/// class PauseMenu : public jngl::Work {
/// jngl::Finally paused;
///
/// public:
/// PauseMenu() : paused(jngl::Channel::main().pause()) {}
/// void step() override { /* ... */ }
/// void draw() const override { /* ... */ }
/// };
/// \endcode
///
/// Or if you want to toggle pausing audio using <kbd>Space</kbd>:
/// \code
/// class PauseExample : public jngl::Work {
/// std::optional<jngl::Finally> paused;
///
/// public:
/// void step() override {
/// if (jngl::keyPressed(jngl::key::Space)) {
/// if (paused) {
/// paused = {}; // calls ~Finally() and resumes playback
/// } else {
/// paused = jngl::Channel::main().pause();
/// }
/// }
/// }
/// void draw() const override { /* ... */ }
/// };
/// \endcode
[[nodiscard]] Finally pause();

/// Set volume of this channel in [0, ∞]. Default is 1.0f
void setVolume(float volume);

/// Returns the main Channel on which jngl::play, jngl::loop, jngl::stop operate
static Channel& main();

/// Internal function for now
void add(std::shared_ptr<Stream>);
/// Internal function for now
void remove(const Stream*);

private:
struct Impl;
std::unique_ptr<Impl> impl;
};

} // namespace jngl
5 changes: 3 additions & 2 deletions src/jngl/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void mainLoop(AppParameters);
/// jngl::AppParameters params;
/// params.displayName = "My Game";
/// params.screenSize = { 1920, 1080 };
///
///
/// params.start = []() {
/// return std::make_shared<MyGame>();
/// };
Expand All @@ -53,7 +53,8 @@ JNGL_MAIN_BEGIN { // NOLINT
if (err) {
std::filesystem::current_path("../../data", err); // move out of build/Debug folder
if (err) {
std::filesystem::current_path("../../../data", err); // move out of out\build\x64-Debug
std::filesystem::current_path("../../../data",
err); // move out of out\build\x64-Debug
if (err) {
std::filesystem::current_path(jngl::getBinaryPath() + "data", err);
}
Expand Down
Loading

0 comments on commit 8967e20

Please sign in to comment.