Skip to content

Commit

Permalink
raz forced me to push this
Browse files Browse the repository at this point in the history
- lists corrupted games
- option to stop scanning for games and exit early
- option to select all games for deletion
- minor ui improvements
- add missing assets folder
  • Loading branch information
ITotalJustice committed Apr 24, 2023
1 parent db3ed31 commit 85b453a
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
*.nacp
nxbuild/
.vscode/
assets/
switch/
*.zip
*.lst
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
APP_TITLE := untitled
APP_AUTHOR := TotalJustice
APP_VERSION := 1.2.0
# ICON := assets/app_icon.jpg
APP_VERSION := 1.3.0
ICON := assets/icon.jpg

TARGET := untitled
BUILD := nxbuild
Expand All @@ -62,7 +62,7 @@ ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE
# basic
C_OPTIMISE := -O3 -DNDEBUG
# lto
C_OPTIMISE += -flto -ffat-lto-objects -fuse-linker-plugin -flto-compression-level=9 -ffunction-sections -fdata-sections -fmerge-all-constants -Wl,--gc-sections
C_OPTIMISE += -flto=3 -ffat-lto-objects -fuse-linker-plugin -flto-compression-level=9 -ffunction-sections -fdata-sections -fmerge-all-constants -Wl,--gc-sections

# warns
MY_DEFINES := -Wall #-Wextra #-Werror # todo: fix warns soon
Expand All @@ -75,7 +75,7 @@ CFLAGS := $(C_OPTIMISE) $(ARCH) $(DEFINES) $(MY_DEFINES)

CFLAGS += $(INCLUDE) -D__SWITCH__

CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti
CXXFLAGS := $(CFLAGS) -std=c++23 -fno-exceptions -fno-rtti

ASFLAGS := $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
Expand Down
Binary file added assets/icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/romfs/default_icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/romfs/shaders/fill_aa_fsh.dksh
Binary file not shown.
Binary file added assets/romfs/shaders/fill_fsh.dksh
Binary file not shown.
Binary file added assets/romfs/shaders/fill_vsh.dksh
Binary file not shown.
293 changes: 213 additions & 80 deletions src/app.cpp

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "nanovg/nanovg.h"
#include "nanovg/deko3d/dk_renderer.hpp"
#include "async.hpp"

#include <switch.h>
#include <cstdint>
#include <vector>
Expand All @@ -10,12 +12,14 @@
#include <mutex>
#include <optional>
#include <functional>
#include <stop_token>
#include <utility>

namespace tj {

using AppID = std::uint64_t;

enum class MenuMode { LIST, CONFIRM, PROGRESS };
enum class MenuMode { LOAD, LIST, CONFIRM, PROGRESS };

struct Controller final {
// these are tap only
Expand Down Expand Up @@ -62,8 +66,6 @@ struct NsDeleteData final {
std::function<void(void)> done_cb; // called when finished
};

void NsDeleteAppsAsync(const NsDeleteData& data);

class App final {
public:
App();
Expand All @@ -85,9 +87,10 @@ class App final {
std::size_t sdcard_storage_size_used{};
std::size_t sdcard_storage_size_free{};

std::future<void> async_thread;
util::AsyncFurture<void> async_thread;
std::mutex mutex{};
std::size_t delete_index{}; // mutex locked
bool finished_scanning{false}; // mutex locked
bool finished_deleting{false}; // mutex locked

// this is just bad code, ignore it
Expand All @@ -97,7 +100,8 @@ class App final {
std::size_t start{0};
std::size_t delete_count{0};
std::size_t index{}; // where i am in the array
MenuMode menu_mode{MenuMode::LIST};
MenuMode menu_mode{MenuMode::LOAD};
bool has_correupted{false};
bool quit{false};

enum class SortType {
Expand All @@ -108,20 +112,22 @@ class App final {
MAX,
};

uint8_t sort_type{static_cast<uint8_t>(SortType::Size_BigSmall)};
uint8_t sort_type{std::to_underlying(SortType::Size_BigSmall)};

void Draw();
void Update();
void Poll();
bool Scan(); // called on init
void Scan(std::stop_token stop_token); // called on init
void Sort();
const char* GetSortStr();

void UpdateLoad();
void UpdateList();
void UpdateConfirm();
void UpdateProgress();

void DrawBackground();
void DrawLoad();
void DrawList();
void DrawConfirm();
void DrawProgress();
Expand Down
107 changes: 107 additions & 0 deletions src/async.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#pragma once

#include <future>
#include <stop_token>

namespace util {

// simple wrapper for future + stop token.
// todo: write my own std::async with token source added, like jthread.
template<typename T>
class AsyncFurture {
public:
constexpr AsyncFurture() = default;
constexpr AsyncFurture(AsyncFurture&& token)
: future{std::move(token.future)}
, stop_source{std::move(token.stop_source)} {}
constexpr AsyncFurture(std::future<T>&& f)
: future{std::forward<std::future<T>>(f)} {}
constexpr AsyncFurture(std::future<T>&& f, std::stop_source&& ss)
: future{std::forward<std::future<T>>(f)}
, stop_source{std::forward<std::stop_source>(ss)} {}
~AsyncFurture() {
if (this->future.valid()) {
this->stop_source.request_stop();
this->future.get();
}
}

// disable copying
AsyncFurture(const AsyncFurture&) = delete;
AsyncFurture& operator=(const AsyncFurture& f) = delete;

AsyncFurture<T>& operator=(AsyncFurture<T>&& f) noexcept {
this->future = std::move(f.future);
this->stop_source = std::move(f.stop_source);
return *this;
}

[[nodiscard]]
auto get() {
return this->future.get();
}

[[nodiscard]]
auto get_token() const noexcept {
return this->stop_source.get_token();
}

auto request_stop() {
return this->stop_source.request_stop();
}

[[nodiscard]]
auto stop_possible() {
return this->stop_source.stop_possible();
}

[[nodiscard]]
auto wait() {
return this->future.wait();
}

template<typename Rep, typename Period>
[[nodiscard]]
auto wait_for(const std::chrono::duration<Rep, Period>& wait_time) {
return this->future.wait_for(wait_time);
}

template<typename Clock, typename Duration>
[[nodiscard]]
auto wait_until(const std::chrono::time_point<Clock, Duration>& wait_time) {
return this->future.wait_until(wait_time);
}

[[nodiscard]]
auto valid() const noexcept {
return this->future.valid();
}

private:
std::future<T> future{};
std::stop_source stop_source{};
};

template<typename Fn, typename... Args>
using AsyncResult = typename std::invoke_result<
typename std::decay<Fn>::type, typename std::decay<Args>::type...>::type;

// enabled if function DOES start with std::stop_token
template<typename Fn, typename... Args, typename = std::enable_if<std::is_invocable_v<std::decay_t<Fn>, std::stop_token, std::decay_t<Args>...>>>
auto async(Fn&& fn, Args&&... args) -> AsyncFurture<AsyncResult<Fn, std::stop_token, Args...>> {
std::stop_source source_token;
return AsyncFurture{
std::async(std::launch::async, std::forward<Fn>(fn), source_token.get_token(), std::forward<Args>(args)...),
std::move(source_token)
};
}

// enabled if function does NOT start with std::stop_token
template<typename Fn, typename... Args, typename = std::enable_if<!std::is_invocable_v<std::decay_t<Fn>, std::stop_token, std::decay_t<Args>...>>>
auto async(Fn&& fn, Args&&... args) -> AsyncFurture<AsyncResult<Fn, Args...>> {
return AsyncFurture{
std::async(std::launch::async, std::forward<Fn>(fn), std::forward<Args>(args)...)
};
}

} // namespace util

0 comments on commit 85b453a

Please sign in to comment.