-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
305 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.