Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev libxi-dev libfreetype-dev

- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# StylishVisualizer
This is a program which visualizes a bunch of [sorting algorithms](https://en.wikipedia.org/wiki/Sorting_algorithm).
Made in C++17 using [SFML](https://github.com/SFML/SFML) 2.6.1, [ImGui](https://github.com/ocornut/imgui) 1.88 (+[imgui-sfml](https://github.com/eliasdaler/imgui-sfml) 2.6) and [ImPlot](https://github.com/epezent/implot) 0.16, the code is completely cross platform (checkout the [releases](https://github.com/CosminPerRam/StylishVisualizer/releases) page)!
Made in C++17 using [SFML](https://github.com/SFML/SFML) 3.0.0, [ImGui](https://github.com/ocornut/imgui) 1.91.1 (+[imgui-sfml](https://github.com/eliasdaler/imgui-sfml) 3.0) and [ImPlot](https://github.com/epezent/implot) (`master 3da8bd3`), the code is completely cross platform!

![Default Interface](.github/readme/interface_default.png)
![Sorting ](.github/readme/sorters_variety.jpg)
Expand Down Expand Up @@ -39,7 +39,7 @@ cmake -B build
cmake --build build --config Release
```
*Note:* Every dependency is handled by cmake.
*Windows note:* After building, you need to copy `openal32.dll` (it's at `build\_deps\sfml-src\extlibs\bin\`) to the `sorting-visualizer.exe`'s directory.
*Linux note:* Additional system dependencies are needed for SFML, check [the docs](https://www.sfml-dev.org/tutorials/3.0/getting-started/build-from-source/#introduction) or the [github actions workflow file](.github/workflows/ci.yml).

## Special thanks
[@ChrisTrasher](https://github.com/ChrisThrasher) - for the cmake script, CI script and testing.
9 changes: 4 additions & 5 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ Set(FETCHCONTENT_QUIET FALSE)

FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 2.6.1
GIT_TAG 3.0.0
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(SFML)

FetchContent_Declare(ImGui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG v1.88
GIT_TAG v1.91.1
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(ImGui)

set(IMGUI_DIR "${imgui_SOURCE_DIR}")
set(IMGUI_SFML_FIND_SFML OFF)
set(IMGUI_SFML_IMGUI_DEMO ON)
FetchContent_Declare(ImGui-SFML
GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml
GIT_TAG v2.6
GIT_TAG v3.0
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(ImGui-SFML)

FetchContent_Declare(ImPlot
GIT_REPOSITORY https://github.com/epezent/implot
GIT_TAG v0.16
GIT_TAG 3da8bd34299965d3b0ab124df743fe3e076fa222
GIT_PROGRESS TRUE)
FetchContent_MakeAvailable(ImPlot)

Expand Down
2 changes: 1 addition & 1 deletion include/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Audio
static sf::Sound& sound();
static sf::SoundBuffer& buffer();

inline static sf::Int16 samples[44100];
inline static std::int16_t samples[44100];

public:
inline static bool enabled = true;
Expand Down
4 changes: 2 additions & 2 deletions include/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class Interface
static void shutdown();

static void draw(sf::RenderWindow& window);
static void pollEvent(sf::Event& theEvent);
static void pollEvent(sf::RenderWindow& window, sf::Event& theEvent);
static void update(sf::RenderWindow& window, sf::Time diffTime);
};
};
2 changes: 1 addition & 1 deletion include/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Program
inline static sf::Time lastTime;

static void draw(sf::RenderWindow& window);
static void pollEvent(sf::Event& theEvent);
static void pollEvent(sf::RenderWindow& window, sf::Event& theEvent);
static void update(sf::RenderWindow& window);

public:
Expand Down
8 changes: 6 additions & 2 deletions src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
constexpr auto TWOPI = 6.283185307f;

sf::Sound& Audio::sound() {
static sf::Sound theSound;
static sf::Sound theSound(Audio::buffer());
return theSound;
}

Expand Down Expand Up @@ -59,8 +59,12 @@ void Audio::play(unsigned value) {
samples[i] = SquareWave(i, freq, amp);
}

static auto channelMap = std::vector<sf::SoundChannel>{
sf::SoundChannel::Mono,
};

sound().stop();
buffer().loadFromSamples(&samples[0], 44100, 1, 44100);
bool _might = buffer().loadFromSamples(samples, 44100, 1, 44100, channelMap);
sound().setPitch(pitch);
sound().play();
}
8 changes: 4 additions & 4 deletions src/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void Interface::changedAlgorithm() {
}

void Interface::initialize(sf::RenderWindow& window) {
ImGui::SFML::Init(window);
bool _might = ImGui::SFML::Init(window);

ImGui::CreateContext();
ImPlot::CreateContext();
Expand Down Expand Up @@ -364,7 +364,7 @@ void Interface::draw(sf::RenderWindow& window) {
unsigned numbersSize = Settings::NUMBERS_DOWNSAMPLE == Settings::SAMPLING::NONE ? unsigned(sorterNumbers->size()) : unsigned(downsampledNumbers.size());
const unsigned* numbers = Settings::NUMBERS_DOWNSAMPLE == Settings::SAMPLING::NONE ? sorterNumbers->data() : downsampledNumbers.data();

float plotSizeHeight = ImGui::GetWindowContentRegionMax().y - ImGui::GetTextLineHeightWithSpacing() - 40;
float plotSizeHeight = ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeightWithSpacing() - 40;

ImPlotAxisFlags axisFlags = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoSideSwitch | ImPlotAxisFlags_NoHighlight;
if(Settings::PLOT_SHOW_SCALE && Settings::PLOT_TYPE == Settings::PLOT_TYPES::HEATMAP) {
Expand Down Expand Up @@ -467,8 +467,8 @@ void Interface::draw(sf::RenderWindow& window) {
ImGui::SFML::Render(window);
}

void Interface::pollEvent(sf::Event& theEvent) {
ImGui::SFML::ProcessEvent(theEvent);
void Interface::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
ImGui::SFML::ProcessEvent(window, theEvent);
}

void Interface::update(sf::RenderWindow& window, sf::Time diffTime) {
Expand Down
26 changes: 14 additions & 12 deletions src/Program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ void Program::draw(sf::RenderWindow& window) {
Interface::draw(window);
}

void Program::pollEvent(sf::Event& theEvent) {
Interface::pollEvent(theEvent);
void Program::pollEvent(sf::RenderWindow& window, sf::Event& theEvent) {
Interface::pollEvent(window, theEvent);
}

void Program::update(sf::RenderWindow& window) {
Expand All @@ -26,24 +26,26 @@ void Program::update(sf::RenderWindow& window) {

int Program::start() {
sf::ContextSettings contextSettings;
contextSettings.antialiasingLevel = 16;
sf::RenderWindow window(sf::VideoMode(1290, 720), "ImGui-Visualizer", sf::Style::Default, contextSettings);
contextSettings.antiAliasingLevel = 16;
sf::RenderWindow window(sf::VideoMode(sf::Vector2u(1290, 720)), "ImGui-Visualizer", sf::Style::Default, sf::State::Windowed, contextSettings);
window.setVerticalSyncEnabled(true);

Manager::initialize();
Interface::initialize(window);
Audio::initialize();

while (window.isOpen()) {
sf::Event theEvent;
while (window.pollEvent(theEvent)) {
if (theEvent.type == sf::Event::Closed) {
Interface::shutdown();
window.close();
return 0;
while (const std::optional mightEvent = window.pollEvent()) {
if (mightEvent) {
sf::Event theEvent = mightEvent.value();
if (theEvent.is<sf::Event::Closed>()) {
Interface::shutdown();
window.close();
return 0;
}

Program::pollEvent(window, theEvent);
}

Program::pollEvent(theEvent);
}

Program::update(window);
Expand Down
2 changes: 1 addition & 1 deletion src/SortingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SortingAlgorithm::stepState SortingAlgorithm::checkStep() {
//else
stats.sortTimeMs = stats.sortTimeMs + theClock.getElapsedTime().asSeconds() * 1000;

sf::sleep(sf::microseconds(sf::Int64(Manager::delayMs * 1000)));
sf::sleep(sf::microseconds(std::int64_t(Manager::delayMs * 1000)));
theClock.restart();

if (m_doStep) {
Expand Down