# Rewrite Stage 1
- Switch to CMake build system - delete everything for a new structure - Add SmartCtor class and saperate New func - New Faster and Open Lithium Command API - Rewritten Text Renderer to ghet rid of all that janky code - New TimeTrace System and use of NanoTime using GetTimeNano - Overall going to a more Object oriented way - Updated vec api to support vec2 input on vec3 ## Todo - Support vec2 and vec3 in vec4 as inputs - Continue UI7 - Fix SystemFont on 3ds freezing the system - Fix TTF Font UV Mapping ## Warning Creating Apps for the 3ds is not possible yet as the 3ds is Freezing and this is only stage 1 of ? Emulator works perfect
This commit is contained in:
@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
void Error(const std::string& msg);
|
||||
inline void InlineError(const std::string& msg) {
|
||||
std::string location = __FILE__ + std::string(":") + std::to_string(__LINE__);
|
||||
Error("Error: \n" + location + "\n" + msg);
|
||||
}
|
||||
inline void InlineAssert(bool v, const std::string& msg = "") {
|
||||
if (v == false) {
|
||||
std::string location =
|
||||
__FILE__ + std::string(":") + std::to_string(__LINE__);
|
||||
Error("Assert Failed:\n" + location + "\n" + msg);
|
||||
}
|
||||
}
|
||||
} // namespace Palladium
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace Palladium {
|
||||
namespace Hardware {
|
||||
/// @brief Initialisize required Services
|
||||
void Initialisize();
|
||||
/// @brief Check if Headphones are Plugged in
|
||||
/// @return true if headphones plugged in
|
||||
bool IsHeadphones();
|
||||
/// @brief Check if the 3ds Is Charging
|
||||
/// @return true if System gets Charged
|
||||
bool IsCharging();
|
||||
/// @brief Check the Battery Percentage
|
||||
/// @return Persentage as int
|
||||
int GetBatteryPercentage();
|
||||
/// @brief Get current State of 3d Slider
|
||||
/// @return current 3dslider poition
|
||||
float Get3dSliderLevel();
|
||||
/// @brief Get Current state of Sound Slider
|
||||
/// @return current SoundSlider state
|
||||
float GetSoundSliderLevel();
|
||||
/// @brief Get Current Wifi Level
|
||||
/// @return current wifi level
|
||||
int GetWifiLevel();
|
||||
} // namespace Hardware
|
||||
} // namespace Palladium
|
@ -1,42 +0,0 @@
|
||||
// WARNING
|
||||
// THIS IS BETA STUFF
|
||||
// ITS MAKE LIKE EXTERNAL BUT
|
||||
// FOR Palladium ITS INTEGRATED
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
namespace Hid {
|
||||
enum Actions {
|
||||
Down = 0,
|
||||
Held = 1,
|
||||
Up = 2,
|
||||
DownRepeat = 3,
|
||||
};
|
||||
// Register Functions
|
||||
// Register Current state values
|
||||
void RegKeyDown(uint32_t &key_down);
|
||||
void RegKeyHeld(uint32_t &key_held);
|
||||
void RegKeyUp(uint32_t &key_up);
|
||||
void RegKeyRepeat(uint32_t &repeat);
|
||||
void RegTouchCoords(NVec2 &touch_pos);
|
||||
// Not Corectly Implemented Yet
|
||||
void RegAnalog1Movement(NVec2 &movement);
|
||||
void RegAnalog2Movement(NVec2 &movement);
|
||||
// Register Keys
|
||||
void RegKeyEvent(const std::string &event, uint32_t key);
|
||||
// KeyEvents
|
||||
bool IsEvent(const std::string &event, Actions action);
|
||||
NVec2 GetTouchPosition();
|
||||
NVec2 GetLastTouchPosition();
|
||||
NVec2 GetTouchDownPosition();
|
||||
void Update();
|
||||
// Lock/Unlock Input api for example for Keyboard
|
||||
void Lock();
|
||||
void Unlock();
|
||||
void Clear();
|
||||
} // namespace Hid
|
||||
} // namespace Palladium
|
@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/Texture.hpp>
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <pd/nimg.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
class Image {
|
||||
public:
|
||||
Image() = default;
|
||||
Image(const std::string& path) { this->Load(path); }
|
||||
~Image() = default;
|
||||
PD_SMART_CTOR(Image)
|
||||
void Load(const std::string& path);
|
||||
void From_NIMG(const nimg& image);
|
||||
void Delete();
|
||||
|
||||
Texture::Ref Get();
|
||||
void Set(Texture::Ref i, NVec4 uvs = NVec4(-1, -1, -1, -1));
|
||||
NVec2 GetSize();
|
||||
NVec4 GetUV() { return (custom_uvs.x() != -1) ? custom_uvs : img->GetUV(); }
|
||||
bool Loadet();
|
||||
|
||||
private:
|
||||
bool ext = false;
|
||||
Texture::Ref img;
|
||||
NVec4 custom_uvs = NVec4(-1, -1, -1, -1);
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h> // Result
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
struct InstallerInfo {
|
||||
unsigned long long total;
|
||||
unsigned long long current;
|
||||
unsigned int mem_size = 0x80000;
|
||||
bool active = false;
|
||||
};
|
||||
Result InstallCia(const std::string& path, bool self);
|
||||
void InstallSetBuffersSize(unsigned int bytes);
|
||||
InstallerInfo InstallGetInfo();
|
||||
} // namespace Palladium
|
@ -1,238 +0,0 @@
|
||||
#pragma once
|
||||
#include <citro3d.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <map>
|
||||
#include <pd/Texture.hpp>
|
||||
#include <pd/base/Allocator.hpp>
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <vector>
|
||||
|
||||
#define MAKEFLAG(x) (1 << x)
|
||||
|
||||
using PDTextFlags = unsigned int;
|
||||
|
||||
enum PDTextFlags_ {
|
||||
PDTextFlags_None = 0, //< Align is Left and Other things are disabled
|
||||
PDTextFlags_AlignRight = MAKEFLAG(0),
|
||||
PDTextFlags_AlignMid = MAKEFLAG(1),
|
||||
PDTextFlags_Shaddow = MAKEFLAG(2), // TextBuf Killer lol (doubled Text)
|
||||
PDTextFlags_Wrap = MAKEFLAG(3),
|
||||
PDTextFlags_Short = MAKEFLAG(4),
|
||||
PDTextFlags_Scroll = MAKEFLAG(5),
|
||||
};
|
||||
|
||||
using PDLithiumFlags = unsigned int;
|
||||
|
||||
enum PDLithiumFlags_ {
|
||||
PDLithiumFlags_None = 0,
|
||||
PDLithiumFlags_TMS = MAKEFLAG(0), // Text Map System
|
||||
PDLithiumFlags_LRS = MAKEFLAG(1), // Layer Render System
|
||||
PDLithiumFlags_FCS = MAKEFLAG(2), // Floor Coords System
|
||||
PDLithiumFlags_Default = PDLithiumFlags_TMS,
|
||||
};
|
||||
|
||||
namespace Palladium {
|
||||
class LIFont {
|
||||
public:
|
||||
struct CPI {
|
||||
CPI()
|
||||
: codepoint(0),
|
||||
uv(NVec4()),
|
||||
tex(nullptr),
|
||||
szs(NVec2()),
|
||||
off(0.f),
|
||||
invalid(false) {}
|
||||
CPI(bool iv)
|
||||
: codepoint(0),
|
||||
uv(NVec4()),
|
||||
tex(nullptr),
|
||||
szs(NVec2()),
|
||||
off(0.f),
|
||||
invalid(iv) {}
|
||||
unsigned int codepoint;
|
||||
NVec4 uv;
|
||||
Texture::Ref tex;
|
||||
NVec2 szs;
|
||||
float off;
|
||||
bool invalid;
|
||||
};
|
||||
LIFont() = default;
|
||||
~LIFont() = default;
|
||||
PD_SMART_CTOR(LIFont)
|
||||
|
||||
void LoadTFF(const std::string path, int px_size = 32);
|
||||
void LoadBitmapFont(const std::string& path);
|
||||
void LoadSystemFont();
|
||||
|
||||
int GetPixelHeight();
|
||||
CPI GetCodepoint(unsigned int c);
|
||||
std::string GetName() { return name; };
|
||||
|
||||
bool IsSystemFont() { return sysfnt; }
|
||||
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
bool sysfnt = false;
|
||||
std::string name;
|
||||
int pixel_height;
|
||||
std::map<unsigned int, CPI> cpmap;
|
||||
std::vector<Texture::Ref> tex;
|
||||
};
|
||||
|
||||
class LI {
|
||||
public:
|
||||
struct Vtx {
|
||||
Vtx() {}
|
||||
Vtx(NVec2 xy, float u, float v, unsigned int clr) {
|
||||
// Coords
|
||||
pos[0] = xy[0];
|
||||
pos[1] = xy[1];
|
||||
pos[2] = 0.f;
|
||||
// UV
|
||||
uv[0] = u;
|
||||
uv[1] = v;
|
||||
col = clr;
|
||||
}
|
||||
NVec3 pos;
|
||||
NVec2 uv;
|
||||
unsigned int col;
|
||||
};
|
||||
/// CMD TYPES ///
|
||||
/// 0 = SKIP
|
||||
/// 2 = TRIANGLE
|
||||
/// 1 = RECT
|
||||
/// 3 = Circle
|
||||
/////////////////
|
||||
struct Cmd {
|
||||
NVec4 top;
|
||||
NVec4 bot;
|
||||
NVec4 uv;
|
||||
int layer = 0;
|
||||
int cmd_type = 0;
|
||||
bool fcs = false; // Floor Coords System
|
||||
unsigned int clr = 0;
|
||||
bool sfr = false; // SysFontRender
|
||||
Texture::Ref tex = nullptr;
|
||||
int index = 0;
|
||||
};
|
||||
/// Text Box ///
|
||||
/// System to Make GetTextDiemnsions
|
||||
/// and Short/Wrap faster
|
||||
struct TextBox {
|
||||
NVec2 size;
|
||||
float time_created;
|
||||
// Optional
|
||||
bool optinal = false;
|
||||
std::string text;
|
||||
};
|
||||
LI() = default;
|
||||
~LI() = default;
|
||||
|
||||
static void Init();
|
||||
static void Exit();
|
||||
|
||||
// Settings
|
||||
static void EnableFeature(PDLithiumFlags flag) { flags |= flag; }
|
||||
static void DisableFeature(PDLithiumFlags flag) { flags &= ~flag; }
|
||||
static PDLithiumFlags& GetFeatures() { return flags; }
|
||||
|
||||
static void OnScreen(bool bottom);
|
||||
static void Render(C3D_RenderTarget* top, C3D_RenderTarget* bot);
|
||||
static NVec2 GetScreenSize() { return screen_size; }
|
||||
static LIFont::Ref GetFont() { return font; }
|
||||
static void SetFont(LIFont::Ref i) {
|
||||
font_update = true;
|
||||
font = i;
|
||||
}
|
||||
static void UseTexture(Texture::Ref tex = nullptr) {
|
||||
active_texture = tex ? tex : single_color;
|
||||
}
|
||||
static bool IsBottomScreen() { return bottom_screen; }
|
||||
static float GetTextScale() { return text_scale; }
|
||||
static void SetTextScale(float scale) {
|
||||
font_update = true;
|
||||
text_scale = scale;
|
||||
}
|
||||
static void DefaultTextScale() {
|
||||
font_update = true;
|
||||
text_scale = default_text_size;
|
||||
}
|
||||
static void Layer(int v) { layer = v; }
|
||||
static int Layer() { return layer; }
|
||||
static void NewLayer() { layer++; }
|
||||
static NVec2 GetTextDimensions(const std::string& text);
|
||||
static std::string ShortText(const std::string& in, int maxlen, NVec2& dim);
|
||||
static std::string WrapText(const std::string& in, int maxlen, NVec2& dim);
|
||||
|
||||
// Drawing Functions
|
||||
static void DrawRect(NVec2 pos, NVec2 size, unsigned int color, NVec4 uvs);
|
||||
static void DrawLine(NVec2 a, NVec2 b, unsigned int clr, int t = 1);
|
||||
static void DrawCircle(NVec2 pos, float r, unsigned int color, int segments);
|
||||
static void DrawRect(NVec2 pos, NVec2 size, unsigned int color) {
|
||||
UseTexture();
|
||||
DrawRect(pos, size, color, NVec4(0, 1, 1, 0));
|
||||
}
|
||||
static void DrawTriangle(NVec2 a, NVec2 b, NVec2 c, unsigned int color);
|
||||
static void DrawImage(NVec2 pos, Texture::Ref tex, NVec2 size, NVec4 uvs) {
|
||||
UseTexture(tex);
|
||||
DrawRect(pos, size, 0xffffffff, uvs);
|
||||
}
|
||||
static void DrawText(NVec2 pos, unsigned int color, const std::string& text,
|
||||
PDTextFlags flags = 0, NVec2 ap = NVec2());
|
||||
|
||||
static int Vertices() { return num_vertices; }
|
||||
static int Indices() { return num_indices; }
|
||||
static int Drawcalls() { return num_drawcalls; }
|
||||
static int DarwCommands() { return num_commands; }
|
||||
static size_t GetMaxVerticesNum() { return vertex_buffer.size(); }
|
||||
|
||||
private:
|
||||
static void RotateCorner(NVec2& v, float s, float c);
|
||||
static void MakeRect(NVec4& top, NVec4& bot, NVec2 pos, NVec2 szs,
|
||||
float angle = 0.f);
|
||||
static bool CompareCommands(const Cmd& a, const Cmd& b);
|
||||
static void RenderFrame(bool bottom);
|
||||
|
||||
/// CTX ///
|
||||
static PDLithiumFlags flags;
|
||||
// Font Stuff
|
||||
// Default Font Size in (px)
|
||||
static const float default_font_size;
|
||||
static const float default_text_size;
|
||||
static float text_scale;
|
||||
|
||||
// Renderer Stuff
|
||||
static NVec2 screen_size;
|
||||
static bool bottom_screen;
|
||||
static int layer;
|
||||
static std::vector<Cmd> draw_lists[2];
|
||||
static Texture::Ref active_texture;
|
||||
static Texture::Ref single_color;
|
||||
static std::vector<Vtx, LinearAllocator<Vtx>> vertex_buffer;
|
||||
static std::vector<unsigned short, LinearAllocator<unsigned short>>
|
||||
idx_buffer;
|
||||
static size_t vertex_index;
|
||||
static size_t idx_index;
|
||||
static LIFont::Ref font;
|
||||
static bool font_update;
|
||||
static bool sysfont_render;
|
||||
static std::map<std::string, TextBox> text_sizes;
|
||||
static int cmd_index;
|
||||
|
||||
// Debug
|
||||
static int num_vertices;
|
||||
static int num_drawcalls;
|
||||
static int num_commands;
|
||||
static int num_indices;
|
||||
|
||||
// Shader
|
||||
static DVLB_s* li7_dvlb;
|
||||
static shaderProgram_s li7_prog;
|
||||
static C3D_AttrInfo li7_attr;
|
||||
static int uLoc_proj;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,27 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
struct Message {
|
||||
Message(std::string t, std::string m) {
|
||||
title = t;
|
||||
message = m;
|
||||
animtime = 0.f;
|
||||
}
|
||||
|
||||
std::string title;
|
||||
std::string message;
|
||||
float animtime;
|
||||
};
|
||||
|
||||
void ProcessMessages();
|
||||
void PushMessage(const Message& msg);
|
||||
inline void PushMessage(const std::string& head, const std::string& msg) {
|
||||
PushMessage(Message(head, msg));
|
||||
}
|
||||
// Config
|
||||
void SetMessageIdleStartFrame(int frame);
|
||||
void SetMessageTotalAnimationFrames(int total_frames);
|
||||
void SetMessageFadeOutStartFrame(int frame);
|
||||
} // namespace Palladium
|
@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/external/json.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
namespace Net {
|
||||
// Define List of Errors
|
||||
enum Error_ {
|
||||
Error_None, // Function Executed Successfully
|
||||
Error_Memory, // Memory Allocation Error
|
||||
Error_Write, // Unable to Write File
|
||||
Error_StatusCode, // Error with Status Code
|
||||
Error_Git, // Git Error
|
||||
Error_CtrStatus, // 3ds Result Code
|
||||
Error_Curl, // Curl Error
|
||||
Error_Busy, // Another Download Taskl is already running
|
||||
Error_Invalid, // Invalid Json struct
|
||||
Error_NoWifi, // Console not connected to wifi
|
||||
};
|
||||
// Set an typedefine for Error code
|
||||
using Error = unsigned long long;
|
||||
// Extract Error_ from Error code
|
||||
inline Error_ ErrorCode(Error err) {
|
||||
return static_cast<Error_>(static_cast<unsigned int>(err & 0xffffffff));
|
||||
}
|
||||
// Extract Http Status code, Curl Error Code or Ctr Result Code
|
||||
inline int StatusCode(Error err) {
|
||||
Error_ c = ErrorCode(err);
|
||||
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl)
|
||||
return 0;
|
||||
return static_cast<unsigned int>(err >> 32);
|
||||
}
|
||||
Error Download(const std::string& url, std::string& data);
|
||||
Error Download2File(const std::string& url, const std::string& path);
|
||||
Error GitDownloadRelease(const std::string& url, const std::string& asset_name,
|
||||
const std::string& path, bool prerelease = false);
|
||||
Error JsonApiRequest(const std::string& api_url, nlohmann::json& res);
|
||||
unsigned long long GetProgressCurrent();
|
||||
unsigned long long GetProgressTotal();
|
||||
} // namespace Net
|
||||
} // namespace Palladium
|
@ -1,107 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/Ovl.hpp>
|
||||
#include <pd/Timer.hpp>
|
||||
#include <pd/base/FunctionTrace.hpp>
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <string>
|
||||
|
||||
typedef int PDKeyboard;
|
||||
|
||||
enum PDKeyboard_ {
|
||||
PDKeyboard_Default,
|
||||
PDKeyboard_Numpad,
|
||||
PDKeyboard_Password,
|
||||
};
|
||||
|
||||
enum PDKeyboardState {
|
||||
PDKeyboardState_None = 0,
|
||||
PDKeyboardState_Cancel = 1,
|
||||
PDKeyboardState_Confirm = 2,
|
||||
};
|
||||
|
||||
using PDKeyboardFlags = unsigned int;
|
||||
enum PDKeyboardFlags_ {
|
||||
PDKeyboardFlags_None = 0,
|
||||
PDKeyboardFlags_BlendTop = 1 << 0,
|
||||
PDKeyboardFlags_BlendBottom = 1 << 1,
|
||||
PDKeyboardFlags_LockControls = 1 << 2,
|
||||
PDKeyboardFlags_Default = PDKeyboardFlags_BlendTop |
|
||||
PDKeyboardFlags_BlendBottom |
|
||||
PDKeyboardFlags_LockControls,
|
||||
};
|
||||
|
||||
namespace Palladium {
|
||||
class Ovl_Ftrace : public Palladium::Ovl {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
Ovl_Ftrace(bool* is_enabled);
|
||||
/// @brief Override for Draw
|
||||
void Draw(void) const override;
|
||||
/// @brief Override for Logic
|
||||
void Logic() override;
|
||||
|
||||
private:
|
||||
bool* i_is_enabled;
|
||||
};
|
||||
|
||||
class Ovl_Metrik : public Palladium::Ovl {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
Ovl_Metrik(bool* is_enabled, bool* screen, unsigned int* mt_color,
|
||||
unsigned int* txt_color, float* txt_size);
|
||||
/// @brief Override for Draw
|
||||
void Draw(void) const override;
|
||||
/// @brief Override for Logic
|
||||
void Logic() override;
|
||||
|
||||
private:
|
||||
// Mutable internal values
|
||||
mutable std::string mt_fps;
|
||||
mutable std::string mt_cpu;
|
||||
mutable std::string mt_gpu;
|
||||
mutable std::string mt_cmd;
|
||||
mutable std::string mt_lfr;
|
||||
mutable std::string mt_vtx;
|
||||
mutable std::string mt_idx;
|
||||
mutable std::string mt_drc;
|
||||
mutable std::string mt_dmc;
|
||||
mutable std::string mt_mem;
|
||||
|
||||
// Importand Adresses
|
||||
bool* i_is_enabled;
|
||||
bool* i_screen;
|
||||
unsigned int* i_mt_color;
|
||||
unsigned int* i_txt_color;
|
||||
float* i_txt_size;
|
||||
mutable Ftrace::TimeStats cpu_stats;
|
||||
mutable Ftrace::TimeStats gpu_stats;
|
||||
mutable Timer v_update;
|
||||
};
|
||||
|
||||
class Ovl_Keyboard : public Palladium::Ovl {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
/// Keyboard Type not Supported for now
|
||||
Ovl_Keyboard(std::string& ref, PDKeyboardState& state,
|
||||
const std::string& hint = "", PDKeyboard type = 0,
|
||||
PDKeyboardFlags flags = PDKeyboardFlags_Default);
|
||||
/// @brief Deconstructor
|
||||
~Ovl_Keyboard();
|
||||
/// @brief Override for Draw
|
||||
void Draw(void) const override;
|
||||
/// @brief Override for Logic
|
||||
void Logic() override;
|
||||
|
||||
private:
|
||||
mutable std::map<unsigned char, char> shared_data;
|
||||
// Pointer to useres String
|
||||
std::string* typed_text = nullptr;
|
||||
std::string str_bak;
|
||||
PDKeyboardState* state;
|
||||
PDKeyboard type;
|
||||
int mode = 0;
|
||||
int ft3 = 0;
|
||||
PDKeyboardFlags flags;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief The Overlay Class (Used for Toasts for example)
|
||||
class Ovl {
|
||||
public:
|
||||
/// @brief Deconstructor
|
||||
virtual ~Ovl() {}
|
||||
/// @brief Function Called to Draw this
|
||||
virtual void Draw() const = 0;
|
||||
/// @brief Logic of the Overlay
|
||||
virtual void Logic() = 0;
|
||||
/// @brief Should the overlay be killed
|
||||
/// @return Killed or Not
|
||||
inline bool IsKilled() { return this->iskilled; }
|
||||
/// @brief Kill The Overlay
|
||||
inline void Kill() { iskilled = true; }
|
||||
|
||||
private:
|
||||
/// @param iskilled For IsKilled();
|
||||
bool iskilled = false;
|
||||
};
|
||||
/// @brief Add an Overlay to the Screen
|
||||
/// @param scene Overlay to push to Screen
|
||||
void AddOvl(std::unique_ptr<Palladium::Ovl> scene);
|
||||
} // namespace Palladium
|
@ -1,54 +0,0 @@
|
||||
#pragma once
|
||||
#include <3ds.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief Decoder for 3ds Result Codes
|
||||
class ResultDecoder {
|
||||
public:
|
||||
/// @brief Constructor
|
||||
ResultDecoder() {}
|
||||
/// @brief Deconstructor
|
||||
~ResultDecoder() {}
|
||||
/// @brief Load a Result into Decoder
|
||||
/// @param rescode Result Code
|
||||
void Load(Result rescode);
|
||||
/// @brief Load A Hex Converted Code into Decoder
|
||||
/// @param rescode Result-Hex Code
|
||||
void Load(std::string rescode);
|
||||
/// @brief Get Hex Code
|
||||
/// @return Hex-Code
|
||||
std::string GetCode();
|
||||
/// @brief Get Level Name
|
||||
/// @return Level Name
|
||||
std::string GetLevel();
|
||||
/// @brief Get Level Value
|
||||
/// @return Level Value
|
||||
int GetLevelInt();
|
||||
/// @brief Get The Mosule Name
|
||||
/// @return Module Name
|
||||
std::string GetModule();
|
||||
/// @brief Get The Module Value
|
||||
/// @return Module Value
|
||||
int GetModuleInt();
|
||||
/// @brief Get The Description
|
||||
/// @return Description
|
||||
std::string GetDescription();
|
||||
/// @brief Get The Description Valur
|
||||
/// @return Description Value
|
||||
int GetDescriptionInt();
|
||||
/// @brief Get the Summary
|
||||
/// @return Summary
|
||||
std::string GetSummary();
|
||||
/// @brief Get the Summary Value
|
||||
/// @return Summary Value
|
||||
int GetSummaryInt();
|
||||
/// @brief Write a Result log file to sd
|
||||
void WriteLog(void);
|
||||
|
||||
private:
|
||||
/// @param m_rescode Result code
|
||||
Result m_rescode;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/nimg.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class Rubidium {
|
||||
public:
|
||||
Rubidium(int w, int h);
|
||||
Rubidium();
|
||||
~Rubidium();
|
||||
PD_SMART_CTOR(Rubidium)
|
||||
nimg& GetNimg() { return image; }
|
||||
void LoadFile(const std::string& path);
|
||||
void LoadNimg(const std::string& path);
|
||||
|
||||
// Rendering
|
||||
void DrawPixel(int x, int y, unsigned int color);
|
||||
void DrawRect(int x, int y, int w, int h, unsigned int color, int t = 1);
|
||||
void DrawRectSolid(int x, int y, int w, int h, unsigned int color);
|
||||
void DrawLine(int x1, int y1, int x2, int y2, unsigned int color, int t = 1);
|
||||
void Flip(bool h, bool v);
|
||||
void EnableAA(bool enable) { enable_aa = enable; }
|
||||
|
||||
private:
|
||||
// Leinwand (dont know english word for that)
|
||||
nimg image;
|
||||
bool enable_aa = true;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include <tex3ds.h>
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/Texture.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class Sheet {
|
||||
public:
|
||||
Sheet() = default;
|
||||
~Sheet() = default;
|
||||
PD_SMART_CTOR(Sheet)
|
||||
void LoadT3X(const std::string& path);
|
||||
Texture::Ref Get(int idx);
|
||||
Image::Ref GetImage(int idx);
|
||||
|
||||
private:
|
||||
std::vector<Texture::Ref> sprites;
|
||||
Tex3DS_Texture sheet;
|
||||
C3D_Tex* sheet_tex = nullptr;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
/** Sound Class */
|
||||
class Sound {
|
||||
public:
|
||||
/// \brief Construct new Soundeffect
|
||||
/// \param path Path to the .wav file
|
||||
/// \param channel the channel 1-23
|
||||
/// \param toloop true:loop the sound, false: don't loop
|
||||
Sound(const std::string &path, int channel = 1, bool toloop = false);
|
||||
/// @brief Deconstructor
|
||||
~Sound();
|
||||
PD_SMART_CTOR(Sound)
|
||||
/// @brief Play the sound
|
||||
void Play();
|
||||
/// @brief Stop the sound
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
/// \param dataSize Size of the filedata
|
||||
u32 dataSize;
|
||||
/// \param waveBuf For ndsp
|
||||
ndspWaveBuf waveBuf;
|
||||
/// \param data Memmory data of the sound
|
||||
uint8_t *data = NULL;
|
||||
/// \param chnl Channel of the sound
|
||||
int chnl;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief Sprite Class
|
||||
class Sprite {
|
||||
public:
|
||||
/// \brief Construct Sprite
|
||||
Sprite() = default;
|
||||
/// \brief Deconstruct Sprite
|
||||
~Sprite() = default;
|
||||
PD_SMART_CTOR(Sprite)
|
||||
/// \brief Load a Sprite From SpriteSheet
|
||||
/// \param img the Image to load from.(Palladium::Image)
|
||||
void FromImage(Palladium::Image::Ref img);
|
||||
/// @brief Draw the Sprite
|
||||
/// @return success ?
|
||||
bool Draw();
|
||||
/// @brief Set the Center Position
|
||||
/// @param x X Pos
|
||||
/// @param y Y Pos
|
||||
void SetCenter(float x, float y);
|
||||
/// @brief Set the Sprite's Position
|
||||
/// @param x X Pos
|
||||
/// @param y Y Pos
|
||||
void SetPos(float x, float y);
|
||||
/// @brief Set The Sprite's Scale
|
||||
/// @param x Scale on X-Axis
|
||||
/// @param y Scale on Y-Axis
|
||||
void SetScale(float x, float y);
|
||||
/// @brief Set the Sprite's Rotation
|
||||
/// @param rotation ratation
|
||||
void SetRotation(float rotation);
|
||||
/// @brief Rotate the Sprite
|
||||
/// @param speed Speed to Rotate
|
||||
void Rotate(float speed);
|
||||
/// @brief Get Tje Sprite's Width
|
||||
/// @return Width
|
||||
float GetWidth();
|
||||
/// @brief Get the Sprite's Height
|
||||
/// @return Height
|
||||
float GetHeight();
|
||||
/// @brief Get The Sprite's X Position
|
||||
/// @return X Position
|
||||
float GetPosX();
|
||||
/// @brief Get the Sprite's Y Position
|
||||
/// @return Y Position
|
||||
float GetPosY();
|
||||
NVec2 GetSize();
|
||||
NVec2 GetPos();
|
||||
void SetPos(NVec2 pos);
|
||||
void SetScale(NVec2 scale);
|
||||
void SetRotCenter(NVec2 percentage);
|
||||
|
||||
private:
|
||||
///// @param sprite The Sprite
|
||||
// C2D_Sprite sprite;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
namespace Palladium {
|
||||
namespace Tasks {
|
||||
/// @brief Push A Task
|
||||
/// @param fun Function of Your Task
|
||||
/// @return index
|
||||
int Create(std::function<void()> fun);
|
||||
/// @brief Destroy all Tasks
|
||||
void DestroyAll();
|
||||
} // namespace Tasks
|
||||
} // namespace Palladium
|
@ -1,77 +0,0 @@
|
||||
#pragma once
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Palladium {
|
||||
class Texture {
|
||||
public:
|
||||
// Define Types supported by the texture loader
|
||||
// For example usefull to waste not as much space
|
||||
// in linear mem
|
||||
enum Type {
|
||||
RGBA32,
|
||||
RGB24,
|
||||
A8,
|
||||
};
|
||||
|
||||
enum Filter {
|
||||
NEAREST,
|
||||
LINEAR,
|
||||
};
|
||||
Texture() {
|
||||
// Set Default UV
|
||||
this->uvs[0] = 0.0f;
|
||||
this->uvs[1] = 1.0f;
|
||||
this->uvs[2] = 1.0f;
|
||||
this->uvs[3] = 0.0f;
|
||||
};
|
||||
~Texture() { Delete(); }
|
||||
PD_SMART_CTOR(Texture)
|
||||
|
||||
void Delete();
|
||||
|
||||
/// @brief Loads an Image [png, jpg, bmp] as texture
|
||||
/// by default it sets up the texture as RGBA32 and
|
||||
/// only supports RGB24 and RGBA32 images
|
||||
/// @param path Path to file
|
||||
void LoadFile(const std::string& path);
|
||||
/// @brief Loads an Image [png, jpg, bmp] as texture
|
||||
/// by default it sets up the texture as RGBA32 and
|
||||
/// only supports RGB24 and RGBA32 images
|
||||
/// @param data Data of file
|
||||
void LoadFromMemory(const std::vector<unsigned char>& data);
|
||||
/// @brief Create Texture by pixel Data. This function supports
|
||||
/// [RGBA32, RGB24, A8]
|
||||
/// @param data Pixel Data
|
||||
/// @param w Width of data
|
||||
/// @param h Height of Data
|
||||
/// @param type Type of Data (default is RGBA32)
|
||||
void LoadPixels(const std::vector<unsigned char>& data, int w, int h,
|
||||
Type type = RGBA32, Filter filter = NEAREST);
|
||||
|
||||
/// @brief This function sets up a texture Object based on the input
|
||||
/// Data and a self setup C3D_Tex. You dont need to delete it as
|
||||
/// This class does this automatically
|
||||
void ExternalLoad(C3D_Tex* tex, NVec2 rszs, NVec4 uvs);
|
||||
|
||||
C3D_Tex* Get() { return this->tex; }
|
||||
NVec2 GetTexSize();
|
||||
NVec2 GetSize() { return img_size; }
|
||||
// As the texture is a pow of 2 we need a uv
|
||||
NVec4 GetUV() { return uvs; }
|
||||
|
||||
void AutoDelete(bool enable) { ad = enable; }
|
||||
|
||||
private:
|
||||
void MakeTex(std::vector<unsigned char>& buf, int w, int h,
|
||||
Type type = RGBA32, Filter filter = NEAREST);
|
||||
C3D_Tex* tex = nullptr;
|
||||
NVec2 img_size;
|
||||
NVec4 uvs;
|
||||
bool ad = true;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/palladium.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class ThemeEditor : public Palladium::Scene {
|
||||
public:
|
||||
ThemeEditor();
|
||||
~ThemeEditor();
|
||||
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
Theme::Ref edit_theme;
|
||||
// Placeholder to save active one to
|
||||
Theme::Ref temp_theme;
|
||||
|
||||
// temp vars for samples
|
||||
bool cm;
|
||||
std::string inpt;
|
||||
int menu = 0;
|
||||
|
||||
// Keyboard
|
||||
PDKeyboardState kbd_state;
|
||||
std::string kbd_text;
|
||||
std::vector<std::string> theme_list;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief Format a String
|
||||
/// @param fmt_str Format To
|
||||
/// @param ... Additional Args
|
||||
/// @return Formatted String
|
||||
std::string FormatString(std::string fmt_str, ...);
|
||||
/// @brief Get Current Time as String
|
||||
/// @return Time-String
|
||||
std::string GetTimeStr(void);
|
||||
} // namespace Palladium
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class Timer {
|
||||
public:
|
||||
Timer(bool autostart = true);
|
||||
~Timer() {}
|
||||
PD_SMART_CTOR(Timer)
|
||||
void Reset();
|
||||
void Tick();
|
||||
void Pause();
|
||||
void Resume();
|
||||
float Get();
|
||||
float GetLive();
|
||||
bool Running();
|
||||
|
||||
private:
|
||||
uint64_t last = 0;
|
||||
uint64_t current = 0;
|
||||
bool is_running = false;
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,134 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/Lithium.hpp>
|
||||
#include <pd/base/Color.hpp>
|
||||
#include <pd/maths/NVec.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
#define UI7MAKEFLAG(x) (1 << x)
|
||||
|
||||
using UI7MenuFlags = unsigned int;
|
||||
|
||||
enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_None = 0,
|
||||
UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0),
|
||||
UI7MenuFlags_TitleMid = UI7MAKEFLAG(1),
|
||||
UI7MenuFlags_HzScrolling = MAKEFLAG(2),
|
||||
UI7MenuFlags_VtScrolling = MAKEFLAG(3),
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
||||
|
||||
enum UI7Horizontal {
|
||||
UI7Horizontal_Left = 0,
|
||||
UI7Horizontal_Center = 1,
|
||||
UI7Horizontal_Right = 2,
|
||||
};
|
||||
|
||||
enum UI7Vertical {
|
||||
UI7Vertical_Top = 0,
|
||||
UI7Vertical_Center = 1,
|
||||
UI7Vertical_Bot = 2,
|
||||
};
|
||||
|
||||
class DrawCmd;
|
||||
class UI7DrawList {
|
||||
public:
|
||||
UI7DrawList() = default;
|
||||
~UI7DrawList() = default;
|
||||
|
||||
void AddRectangle(NVec2 pos, NVec2 szs, PDColor clr);
|
||||
void AddRectangle(NVec2 pos, NVec2 szs, unsigned int clr);
|
||||
void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr);
|
||||
void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, unsigned int clr);
|
||||
void AddText(NVec2 pos, const std::string &text, PDColor clr,
|
||||
PDTextFlags flags = 0, NVec2 box = NVec2());
|
||||
void AddText(NVec2 pos, const std::string &text, unsigned int clr,
|
||||
PDTextFlags flags = 0, NVec2 box = NVec2());
|
||||
void AddImage(NVec2 pos, Palladium::Image::Ref img);
|
||||
void AddCall(std::shared_ptr<DrawCmd> cmd);
|
||||
|
||||
void Process(bool auto_clear = true);
|
||||
void Clear();
|
||||
int Layer() { return layer; }
|
||||
void Layer(int v) { layer = v; }
|
||||
int BaseLayer() { return bl; }
|
||||
void BaseLayer(int v) { bl = v; }
|
||||
|
||||
PD_SMART_CTOR(UI7DrawList)
|
||||
|
||||
private:
|
||||
int layer = 0;
|
||||
int bl = 0;
|
||||
void AddDebugCall(std::shared_ptr<DrawCmd> cmd);
|
||||
std::vector<std::shared_ptr<DrawCmd>> list;
|
||||
};
|
||||
|
||||
namespace UI7 {
|
||||
// Key functions
|
||||
void Init();
|
||||
void Deinit();
|
||||
void Update();
|
||||
float GetTime();
|
||||
float GetDeltaTime();
|
||||
bool &IsDebugging();
|
||||
// Internal Function
|
||||
// Should not be used
|
||||
void Debug();
|
||||
bool &DebugMenu();
|
||||
|
||||
bool Button(const std::string &label, NVec2 size = NVec2(0, 0));
|
||||
void Checkbox(const std::string &label, bool &c);
|
||||
void Label(const std::string &label, PDTextFlags flags = 0);
|
||||
void Progressbar(float value);
|
||||
/// @brief Draw Image in Menu
|
||||
/// @param img Pointer f.e to Palladium::Image2
|
||||
void Image(Palladium::Image::Ref img);
|
||||
void BrowserList(const std::vector<std::string> &entrys, int &selection,
|
||||
PDTextFlags txtflags = 0, NVec2 size = NVec2(0, 0),
|
||||
int max_entrys = 13);
|
||||
void InputText(const std::string &label, std::string &text,
|
||||
const std::string &hint = "");
|
||||
bool BeginMenu(const std::string &title, NVec2 size = NVec2(0, 0),
|
||||
UI7MenuFlags flags = 0);
|
||||
void EndMenu();
|
||||
void Grid(const std::string &name, const NVec2 &size, const NVec2 &entry_size,
|
||||
void (*display_func)(void *, NVec2), void **data_array,
|
||||
size_t num_entrys);
|
||||
void ColorSelector(const std::string &label, unsigned int &color);
|
||||
bool BeginTree(const std::string &text);
|
||||
void EndTree();
|
||||
void Prompt(const std::string &label, int &res,
|
||||
// For Translations
|
||||
const std::string &lcf = "Confirm",
|
||||
const std::string &lcc = "Cancel");
|
||||
void ClosePromts();
|
||||
NVec2 GetCursorPos();
|
||||
void SetCursorPos(NVec2 cp);
|
||||
void RestoreCursor();
|
||||
void SameLine();
|
||||
void Separator();
|
||||
// Internal API (For Creating Custom Objects)
|
||||
bool InBox(NVec2 inpos, NVec2 boxpos, NVec2 boxsize);
|
||||
void MoveCursor(NVec2 size);
|
||||
bool HandleScrolling(NVec2 &pos, NVec2 size);
|
||||
bool InMenu();
|
||||
namespace Menu {
|
||||
// All of them return the Main BG DrawList if Menu is null
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
UI7DrawList::Ref GetList();
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
// Other Menu Specific Functions
|
||||
float GetScrollingOffset();
|
||||
void SetScrollingOffset(float off);
|
||||
bool IsScrolling();
|
||||
} // namespace Menu
|
||||
namespace Next {
|
||||
// Alignment in ScreenSpace
|
||||
void Align(UI7Horizontal hz = UI7Horizontal_Left,
|
||||
UI7Vertical vt = UI7Vertical_Top);
|
||||
} // namespace Next
|
||||
// DrawLists
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
} // namespace UI7
|
@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <memory>
|
||||
#include <pd/Error.hpp>
|
||||
|
||||
// Write own LinearAllocator for learning
|
||||
|
||||
namespace Palladium {
|
||||
template <typename T>
|
||||
class LinearAllocator : public std::allocator<T> {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
|
||||
template <typename T1>
|
||||
struct rebind {
|
||||
typedef LinearAllocator<T1> other;
|
||||
};
|
||||
|
||||
pointer allocate(size_type n, const void* hint = nullptr) {
|
||||
if (n > this->max_size()) {
|
||||
Palladium::Error(
|
||||
"Linear Allocator: \nBad Alloc -> size is larger than free space!");
|
||||
return nullptr;
|
||||
}
|
||||
return (pointer)linearAlloc(n * sizeof(T));
|
||||
}
|
||||
|
||||
void deallocate(pointer p, size_type) { linearFree((void*)p); }
|
||||
|
||||
size_type max_size() { return linearSpaceFree(); }
|
||||
|
||||
LinearAllocator() throw() {}
|
||||
LinearAllocator(const LinearAllocator<T>& a) throw() : std::allocator<T>(a) {}
|
||||
~LinearAllocator() throw() {}
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,204 +0,0 @@
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define UNPACK_RGBA(col) \
|
||||
(unsigned char)(col >> 24), (col >> 16), (col >> 8), (col)
|
||||
#define UNPACK_BGRA(col) \
|
||||
(unsigned char)(col >> 8), (col >> 16), (col >> 24), (col)
|
||||
|
||||
inline unsigned int RGBA8(unsigned char r, unsigned char g, unsigned char b,
|
||||
unsigned char a = 255) {
|
||||
return (r | g << 8 | b << 16 | a << 24);
|
||||
}
|
||||
|
||||
typedef int PDColor;
|
||||
|
||||
// MultiColor (Less FunctionNameLen)
|
||||
|
||||
struct Color2 {
|
||||
unsigned int color0;
|
||||
unsigned int color1;
|
||||
};
|
||||
|
||||
struct Color3 {
|
||||
unsigned int color0;
|
||||
unsigned int color1;
|
||||
unsigned int color2;
|
||||
};
|
||||
|
||||
struct Color4 {
|
||||
unsigned int color0;
|
||||
unsigned int color1;
|
||||
unsigned int color2;
|
||||
unsigned int color3;
|
||||
};
|
||||
|
||||
enum PDColor_ {
|
||||
PDColor_Text, ///< This Color Should always be used for Light Backgrounds
|
||||
PDColor_TextDisabled, /// Text Disabled Color
|
||||
PDColor_Text2, ///< And This want for Texts on Dark Backgrounds
|
||||
PDColor_Background, ///< Your Bg Color
|
||||
PDColor_Header, ///< Header Color (if the header is dark text2 is used)
|
||||
PDColor_Selector, ///< Selector Color
|
||||
PDColor_SelectorFade, ///< Selector FadingTo Color
|
||||
PDColor_List0, ///< List Color1
|
||||
PDColor_List1, ///< List Color2
|
||||
PDColor_MessageBackground, ///< Message Background
|
||||
PDColor_Button, ///< Button Color
|
||||
PDColor_ButtonHovered, ///< Button Color if Hovered
|
||||
PDColor_ButtonDisabled, ///< Button Color if disabled
|
||||
PDColor_ButtonActive, ///< Button Colkor if Clicked
|
||||
PDColor_Checkmark, ///< Checkbox Checkmark Color
|
||||
PDColor_FrameBg, ///< Frame Background Color
|
||||
PDColor_FrameBgHovered, ///< Frame Background Color if hovered
|
||||
PDColor_Progressbar, ///< Progressbar Color
|
||||
/// NON COLOR ///
|
||||
PDColor_Len, ///< Used to define the lengh of this list
|
||||
};
|
||||
|
||||
namespace Palladium {
|
||||
class Theme {
|
||||
public:
|
||||
Theme() = default;
|
||||
~Theme() = default;
|
||||
|
||||
void Load(const std::string &path);
|
||||
void Default();
|
||||
void Save(const std::string &path);
|
||||
|
||||
unsigned int Get(PDColor clr);
|
||||
void Set(PDColor clr, unsigned int v);
|
||||
void Swap(PDColor a, PDColor b);
|
||||
bool Undo();
|
||||
void UndoAll();
|
||||
void TextBy(PDColor bg);
|
||||
PDColor AutoText(PDColor bg);
|
||||
void ClearHistory() { changes.clear(); }
|
||||
|
||||
std::vector<unsigned int> &GetTableRef() { return clr_tab; }
|
||||
// For Smart Pointer
|
||||
PD_SMART_CTOR(Theme);
|
||||
|
||||
// Loader method
|
||||
void CopyOther(Theme::Ref theme);
|
||||
|
||||
private:
|
||||
struct change {
|
||||
change(PDColor a, unsigned int f, unsigned int t)
|
||||
: clr(a), from(f), to(t) {}
|
||||
change(PDColor a, PDColor b, unsigned int f, unsigned int t)
|
||||
: clr(a), clr2(b), from(f), to(t) {}
|
||||
PDColor clr;
|
||||
PDColor clr2 = 0; // Used if Swap
|
||||
unsigned int from;
|
||||
unsigned int to;
|
||||
};
|
||||
// Use a vector for faster access
|
||||
std::vector<unsigned int> clr_tab;
|
||||
std::vector<change> changes;
|
||||
};
|
||||
|
||||
Theme::Ref ThemeActive();
|
||||
/// @brief Change Theme Adress
|
||||
/// @param theme your adress
|
||||
void ThemeSet(Theme::Ref theme);
|
||||
namespace Color {
|
||||
/// @brief RGBA Class
|
||||
class RGBA {
|
||||
public:
|
||||
/// @brief Construct
|
||||
/// @param r
|
||||
/// @param g
|
||||
/// @param b
|
||||
/// @param a
|
||||
RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255)
|
||||
: m_r(r), m_g(g), m_b(b), m_a(a) {}
|
||||
/// @brief Construct
|
||||
/// @param r
|
||||
/// @param g
|
||||
/// @param b
|
||||
/// @param a
|
||||
RGBA(float r, float g, float b, float a = 1.f)
|
||||
: m_r(r * 255.f), m_g(g * 255.f), m_b(b * 255.f), m_a(a * 255.f) {}
|
||||
RGBA(unsigned int in) {
|
||||
#define ISIMPLEUNPAK(x, y) (((x) >> y) & 0xFF)
|
||||
m_r = ISIMPLEUNPAK(in, 0);
|
||||
m_g = ISIMPLEUNPAK(in, 8);
|
||||
m_b = ISIMPLEUNPAK(in, 16);
|
||||
m_a = ISIMPLEUNPAK(in, 24);
|
||||
}
|
||||
RGBA(PDColor in) {
|
||||
if (!Palladium::ThemeActive()) return;
|
||||
unsigned int col = Palladium::ThemeActive()->Get(in);
|
||||
m_r = ISIMPLEUNPAK(col, 0);
|
||||
m_g = ISIMPLEUNPAK(col, 8);
|
||||
m_b = ISIMPLEUNPAK(col, 16);
|
||||
m_a = ISIMPLEUNPAK(col, 24);
|
||||
}
|
||||
RGBA &changeR(unsigned char r) {
|
||||
m_r = r;
|
||||
return *this;
|
||||
}
|
||||
RGBA &changeG(unsigned char g) {
|
||||
m_g = g;
|
||||
return *this;
|
||||
}
|
||||
RGBA &changeB(unsigned char b) {
|
||||
m_b = b;
|
||||
return *this;
|
||||
}
|
||||
RGBA &changeA(unsigned char a) {
|
||||
m_a = a;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RGBA &fade_to(const RGBA &color, float p) {
|
||||
m_a =
|
||||
m_a + static_cast<unsigned char>((color.m_a - m_a) * ((p + 1.0f) / 2));
|
||||
m_b =
|
||||
m_b + static_cast<unsigned char>((color.m_b - m_b) * ((p + 1.0f) / 2));
|
||||
m_g =
|
||||
m_g + static_cast<unsigned char>((color.m_g - m_g) * ((p + 1.0f) / 2));
|
||||
m_r =
|
||||
m_r + static_cast<unsigned char>((color.m_r - m_r) * ((p + 1.0f) / 2));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// @brief Get as Uint32
|
||||
/// @return color
|
||||
unsigned int toRGBA() const { return RGBA8(m_r, m_g, m_b, m_a); }
|
||||
|
||||
// Just calculate the "lightness" f.e. to use Text or Text2
|
||||
float luminance() const {
|
||||
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
||||
return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
|
||||
}
|
||||
|
||||
bool is_light() {
|
||||
// Gives us the light or dark to not
|
||||
// always use the below "if" statement
|
||||
return (luminance() >= 0.5);
|
||||
}
|
||||
|
||||
unsigned char m_r = 0, m_g = 0, m_b = 0, m_a = 0;
|
||||
};
|
||||
std::string RGBA2Hex(unsigned int c32);
|
||||
/// @brief Convert RGB to Hex
|
||||
/// @param r
|
||||
/// @param g
|
||||
/// @param b
|
||||
/// @return Hex-String
|
||||
std::string RGB2Hex(int r, int g, int b);
|
||||
/// @brief Hex to U32
|
||||
/// @param color
|
||||
/// @param a
|
||||
/// @return Color32
|
||||
unsigned int Hex(const std::string &color, unsigned char a = 255);
|
||||
} // namespace Color
|
||||
} // namespace Palladium
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Palladium {
|
||||
namespace FileSystem {
|
||||
/// @brief A Directory Entry
|
||||
struct Entry {
|
||||
/// @brief Patf of The Entry
|
||||
std::string path;
|
||||
/// @brief Name of The Entry
|
||||
std::string name;
|
||||
/// @brief Directory or File
|
||||
bool dir = false;
|
||||
};
|
||||
/// @brief Gets All Entrys of A Directory into a Vector
|
||||
/// @param path The Path of the Directory
|
||||
/// @return The Vector of found Entrys
|
||||
std::vector<Palladium::FileSystem::Entry> GetDirContent(std::string path);
|
||||
std::string GetParentPath(std::string path, std::string mount_point);
|
||||
std::vector<Entry> GetDirContentsExt(
|
||||
std::string &path, const std::vector<std::string> &extensions);
|
||||
} // namespace FileSystem
|
||||
} // namespace Palladium
|
@ -1,137 +0,0 @@
|
||||
#pragma once
|
||||
// Base includes
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// 3ds does not support std::chrono
|
||||
#include <3ds.h>
|
||||
|
||||
/// @brief 3ds System Ticks per milli second
|
||||
#define TICKS_PER_MSEC 268111.856
|
||||
|
||||
#define f2s(x_) #x_
|
||||
#define scomb(x1, x2) std::string(x1 + x2)
|
||||
|
||||
namespace Palladium {
|
||||
namespace Ftrace {
|
||||
class TimeStats {
|
||||
public:
|
||||
TimeStats(int len) : len(len), values(len, 0) {}
|
||||
|
||||
void Add(float v) {
|
||||
values[idx] = v;
|
||||
idx = next_index(idx);
|
||||
num_values = std::min(num_values + 1, len);
|
||||
}
|
||||
|
||||
float GetAverage() {
|
||||
float res = 0.f;
|
||||
if (!num_values) {
|
||||
return res;
|
||||
}
|
||||
for (int i = 0; i < num_values; ++i) {
|
||||
res += values[index(i)];
|
||||
}
|
||||
return res / num_values;
|
||||
}
|
||||
|
||||
float GetMax() {
|
||||
float res = 0.f;
|
||||
if (!num_values) {
|
||||
return res;
|
||||
}
|
||||
for (int i = 0; i < num_values; i++) {
|
||||
res = std::max(res, values[index(i)]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
float GetMin() {
|
||||
float res = 0.f;
|
||||
if (!num_values) {
|
||||
return res;
|
||||
}
|
||||
res = values[0];
|
||||
for (int i = 0; i < num_values; i++) {
|
||||
res = std::min(res, values[index(i)]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const std::vector<float>& GetData() { return values; }
|
||||
const float& operator[](int i) { return values[index(i)]; }
|
||||
const size_t GetLen() { return len; }
|
||||
const size_t GetNumValues() { return num_values; }
|
||||
|
||||
private:
|
||||
// Indexing Functions for better overview
|
||||
size_t next_index(size_t current) const { return (current + 1) % len; }
|
||||
size_t index(size_t v) const { return (idx + len - num_values + v) % len; }
|
||||
|
||||
// Data
|
||||
int len = 0;
|
||||
std::vector<float> values;
|
||||
int idx = 0;
|
||||
int num_values = 0;
|
||||
};
|
||||
/// @brief Result of FTrace
|
||||
struct FTRes {
|
||||
FTRes() : time_start(0), time_end(0), time_of(0.f), is_ovl(false), ts(60) {}
|
||||
std::string group; ///< Group of the Trace
|
||||
std::string func_name; ///< Function Name
|
||||
|
||||
uint64_t time_start; ///< when started
|
||||
uint64_t time_end; ///< when stopped
|
||||
float time_of; ///< stop - start (how long)
|
||||
bool is_ovl; ///< is displayed in overlay?
|
||||
TimeStats ts; ///< Time Stats
|
||||
};
|
||||
|
||||
/// @brief Map of Traces
|
||||
extern std::map<std::string, Palladium::Ftrace::FTRes> pd_traces;
|
||||
|
||||
/// @brief Set a Start TracePoint
|
||||
/// @param group Set a Group Name
|
||||
/// @param func_name Set a Function Name
|
||||
inline void Beg(const std::string& group, const std::string& func_name) {
|
||||
std::string trace_id = scomb(group, func_name);
|
||||
auto& trace = pd_traces[trace_id];
|
||||
trace.group = group;
|
||||
trace.func_name = func_name;
|
||||
trace.time_start = svcGetSystemTick();
|
||||
}
|
||||
/// @brief Set an End TracePoint
|
||||
/// @param group Set a Group Name
|
||||
/// @param func_name Set a Function Name
|
||||
inline void End(const std::string& group, const std::string& func_name) {
|
||||
std::string trace_id = scomb(group, func_name);
|
||||
auto& trace = pd_traces[trace_id];
|
||||
trace.time_end = svcGetSystemTick();
|
||||
trace.time_of =
|
||||
static_cast<float>(trace.time_end - trace.time_start) / TICKS_PER_MSEC;
|
||||
trace.ts.Add(trace.time_of);
|
||||
}
|
||||
/// @brief Trace a function execution
|
||||
/// @param group Set a Group Name
|
||||
/// @param name Set a Function Name
|
||||
inline void Func(const std::string& group, const std::string& name,
|
||||
std::function<void()> fun) {
|
||||
if (!fun) return;
|
||||
Beg(group, name);
|
||||
fun();
|
||||
End(group, name);
|
||||
}
|
||||
|
||||
/// @brief This Starts an Ftrace and
|
||||
/// end ist when going out of scope
|
||||
struct ScopedTrace {
|
||||
ScopedTrace(std::string g, std::string n) : group(g), name(n) {
|
||||
Ftrace::Beg(g, n);
|
||||
}
|
||||
~ScopedTrace() { Ftrace::End(group, name); }
|
||||
std::string group;
|
||||
std::string name;
|
||||
};
|
||||
} // namespace Ftrace
|
||||
} // namespace Palladium
|
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
// clang-format off
|
||||
#include <string>
|
||||
#include <pd/external/json.hpp>
|
||||
// clang-format on
|
||||
|
||||
namespace Palladium {
|
||||
namespace Lang {
|
||||
/// @brief Get 3ds System lang! [en] by default
|
||||
/// @return Sytemlang as string
|
||||
std::string GetSys();
|
||||
/// @brief Get The Translation String
|
||||
/// @param key Key of Translation
|
||||
/// @return The Translated String
|
||||
std::string Get(const std::string &key);
|
||||
/// @brief Load A Language json
|
||||
/// @param lang The Language Key [en], [de], etc, or getSys()
|
||||
void Load(const std::string &lang);
|
||||
// New funcs
|
||||
std::string GetName();
|
||||
std::string GetAuthor();
|
||||
std::string GetShortcut();
|
||||
} // namespace Lang
|
||||
} // namespace Palladium
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Palladium {
|
||||
namespace Memory {
|
||||
/// @brief Metriks struct For the Internal Tracker
|
||||
struct memory_metrics {
|
||||
unsigned int t_TotalAllocated = 0; ///< Total Allocated Memory
|
||||
unsigned int t_TotalFreed = 0; ///< Total Deleted Memory
|
||||
/// @brief Gets the Currently Allocated Memory
|
||||
unsigned int t_CurrentlyAllocated() {
|
||||
return t_TotalAllocated - t_TotalFreed;
|
||||
}
|
||||
};
|
||||
/// @brief Get Total Allocated Memory
|
||||
/// @return Total Allocated Memory
|
||||
size_t GetTotalAllocated();
|
||||
/// @brief Get Total Deleted Memory
|
||||
/// @return Total Deleted Memory
|
||||
size_t GetTotalFreed();
|
||||
/// @brief Get Current Allocated Memory
|
||||
/// @return Current Allocated Memory
|
||||
size_t GetCurrent();
|
||||
} // namespace Memory
|
||||
} // namespace Palladium
|
@ -1,98 +0,0 @@
|
||||
#pragma once
|
||||
#include <format>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief Check if A String ends with
|
||||
/// @param name Input String
|
||||
/// @param extensions Extensions to Check for
|
||||
/// @return Ends with or not
|
||||
inline bool NameIsEndingWith(const std::string &name,
|
||||
const std::vector<std::string> &extensions) {
|
||||
if (name.substr(0, 2) == "._") return false;
|
||||
|
||||
if (name.size() == 0) return false;
|
||||
|
||||
if (extensions.size() == 0) return true;
|
||||
|
||||
for (int i = 0; i < (int)extensions.size(); i++) {
|
||||
const std::string ext = extensions.at(i);
|
||||
if (strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/// @brief Format Milliseconds to clean string (Stolen from one of my Mc
|
||||
/// Plugins)
|
||||
/// @param t_time Time in ms
|
||||
/// @return String
|
||||
inline std::string MsTimeFmt(float t_time, bool dems = false) {
|
||||
std::string res;
|
||||
|
||||
if (t_time < 0.000001f) {
|
||||
res = std::format("{:.2f}ns", t_time * 1000000.f);
|
||||
} else if (t_time < 0.001f) {
|
||||
res = std::format("{:.2f}µs", t_time * 1000.f);
|
||||
} else if (t_time < 1.0f) {
|
||||
res = std::format("{:.2f}ms", t_time);
|
||||
} else if (t_time < 60000.0f) {
|
||||
int seconds = static_cast<int>(t_time / 1000.0f);
|
||||
float milliseconds = t_time - (seconds * 1000.0f);
|
||||
if (seconds) {
|
||||
res = std::format("{}s {:.2f}ms", seconds, milliseconds);
|
||||
}
|
||||
res = std::format("{:.2f}ms", milliseconds);
|
||||
} else {
|
||||
int minutes = static_cast<int>(t_time / 60000.0f);
|
||||
int seconds = static_cast<int>((t_time - (minutes * 60000.0f)) / 1000.0f);
|
||||
float milliseconds = t_time - (minutes * 60000.0f) - (seconds * 1000.0f);
|
||||
|
||||
res = std::format("{}m {}s {:.2f}ms", minutes, seconds, milliseconds);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline std::string FormatBytes(int bytes) {
|
||||
char out[32];
|
||||
|
||||
if (bytes == 1)
|
||||
snprintf(out, sizeof(out), "%d Byte", bytes);
|
||||
|
||||
else if (bytes < 1024)
|
||||
snprintf(out, sizeof(out), "%d Bytes", bytes);
|
||||
|
||||
else if (bytes < 1024 * 1024)
|
||||
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
|
||||
|
||||
else if (bytes < 1024 * 1024 * 1024)
|
||||
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
|
||||
|
||||
else
|
||||
snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
|
||||
|
||||
return out;
|
||||
}
|
||||
} // namespace Palladium
|
||||
|
||||
template <class T>
|
||||
T GetFileName(T const &path, T const &delims = "/\\") {
|
||||
return path.substr(path.find_last_of(delims) + 1);
|
||||
}
|
||||
template <class T>
|
||||
T remove_ext(T const &filename) {
|
||||
typename T::size_type const p(filename.find_last_of('.'));
|
||||
return p > 0 && p != T::npos ? filename.substr(0, p) : filename;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string Int_To_Hex(T i) {
|
||||
std::stringstream stream;
|
||||
stream << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex
|
||||
<< i;
|
||||
return stream.str();
|
||||
}
|
68
include/pd/common/app.hpp
Normal file
68
include/pd/common/app.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/timetrace.hpp>
|
||||
#include <pd/graphics/lithium.hpp>
|
||||
|
||||
namespace PD {
|
||||
/// @brief Template Class for User Application
|
||||
class App : public SmartCtor<App> {
|
||||
public:
|
||||
App() = default;
|
||||
~App() = default;
|
||||
|
||||
/// @brief Templete function where the user can Init his stuff
|
||||
virtual void Init() {}
|
||||
/// @brief Templeta funciton to deinit stuff
|
||||
/// (most of that is done automatically)
|
||||
virtual void Deinit() {}
|
||||
/// @brief App Mainloop
|
||||
/// @param delta Deltatime
|
||||
/// @param time App RunTime
|
||||
/// @return false to exit the app
|
||||
virtual bool MainLoop(u64 delta, float time) { return false; }
|
||||
|
||||
/// @brief Function to run the App
|
||||
/// (int main() {
|
||||
/// auto app = PD::New<UserApp>();
|
||||
/// app->Run();
|
||||
/// return 0;
|
||||
/// })
|
||||
void Run();
|
||||
|
||||
LI::Renderer::Ref Renderer() { return renderer; }
|
||||
|
||||
float GetFps() const { return fps; }
|
||||
|
||||
private:
|
||||
void PreInit();
|
||||
void PostDeinit();
|
||||
LI::Renderer::Ref renderer;
|
||||
u64 last_time;
|
||||
float app_time;
|
||||
float fps;
|
||||
};
|
||||
} // namespace PD
|
71
include/pd/common/common.hpp
Normal file
71
include/pd/common/common.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <chrono>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
#include <filesystem> // Requires C++ 17 or later
|
||||
#include <format> // Requires C++ 20 or later
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace PD {
|
||||
// New Version of Smart CTOR
|
||||
// Using as Template class
|
||||
template <typename T>
|
||||
class SmartCtor {
|
||||
public:
|
||||
/// @brief Type Reference
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
/// @brief Creates a New Shared Pointer
|
||||
/// @param ...args Arguments to forward
|
||||
/// @return Shared Pointer (Reference)
|
||||
template <typename... Args>
|
||||
static Ref New(Args&&... args) {
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
/// @brief Wrapper for SmartCtor<Type>::New
|
||||
/// @tparam T class type
|
||||
/// @param ...args Arguments
|
||||
/// @return SmartCtor<T>::Ref type reference
|
||||
/// @note Not sure if this is solving the problem or
|
||||
/// if I schould switch back to the macro
|
||||
template <typename T, typename... Args>
|
||||
SmartCtor<T>::Ref New(Args&&... args) {
|
||||
return SmartCtor<T>::New(std::forward<Args>(args)...);
|
||||
}
|
||||
// Defines
|
||||
using u64 = unsigned long long;
|
||||
using u32 = unsigned int;
|
||||
using u16 = unsigned short;
|
||||
using u8 = unsigned char;
|
||||
} // namespace PD
|
31
include/pd/common/error.hpp
Normal file
31
include/pd/common/error.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
void Error(const std::string& error);
|
||||
void Assert(bool v, const std::string& msg);
|
||||
} // namespace PD
|
57
include/pd/common/lang.hpp
Normal file
57
include/pd/common/lang.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/// @brief Lang System
|
||||
///< Translations are saved into json files
|
||||
///< Path should point to a directory the fils
|
||||
///< for example the files ar named [en.json, de.json, fr.json]
|
||||
class Lang : public SmartCtor<Lang> {
|
||||
public:
|
||||
Lang() = default;
|
||||
~Lang() = default;
|
||||
|
||||
void SetBasePath(const std::string &path) { langs_path = path; }
|
||||
void Load(const std::string &lang_key) {
|
||||
LoadFile(langs_path + "/" + lang_key + ".json");
|
||||
}
|
||||
void LoadFile(const std::string &path);
|
||||
const std::string &Get(const std::string &k);
|
||||
const std::string &GetName() { return lang_name; }
|
||||
const std::string &GetID() { return lang_id; }
|
||||
const std::string &GetAuthor() { return lang_author; }
|
||||
const std::string &GetPath() { return langs_path; }
|
||||
|
||||
private:
|
||||
const int ver = 0;
|
||||
std::string langs_path = "romfs:/lang";
|
||||
std::string lang_name;
|
||||
std::string lang_id;
|
||||
std::string lang_author;
|
||||
std::map<std::string, std::string> ltable;
|
||||
};
|
||||
} // namespace PD
|
60
include/pd/common/memory.hpp
Normal file
60
include/pd/common/memory.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/error.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T>
|
||||
class LinearAllocator : public std::allocator<T> {
|
||||
public:
|
||||
using size_type = size_t;
|
||||
using pointer = T*;
|
||||
using const_pointer = const T*;
|
||||
|
||||
template <typename T1>
|
||||
struct rebind {
|
||||
using other = LinearAllocator<T1>;
|
||||
};
|
||||
|
||||
pointer allocate(size_type n, const void* hint = nullptr) {
|
||||
if (n > this->max_size()) {
|
||||
Error("Linear Alloc failed (no space left)");
|
||||
return nullptr;
|
||||
}
|
||||
return (pointer)linearAlloc(n * sizeof(T));
|
||||
}
|
||||
void deallocate(pointer p, size_type) { linearFree((void*)p); }
|
||||
size_type max_size() { return linearSpaceFree(); }
|
||||
|
||||
LinearAllocator() noexcept {}
|
||||
LinearAllocator(const LinearAllocator<T>& a) noexcept
|
||||
: std::allocator<T>(a) {}
|
||||
~LinearAllocator() noexcept {}
|
||||
};
|
||||
} // namespace PD
|
42
include/pd/common/strings.hpp
Normal file
42
include/pd/common/strings.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Strings {
|
||||
bool StringEndsWith(const std::string& str,
|
||||
const std::vector<std::string>& exts);
|
||||
std::wstring MakeWstring(const std::string& s);
|
||||
const std::string FormatNanos(unsigned long long nanos);
|
||||
const std::string FormatMillis(unsigned long long millis);
|
||||
const std::string FormatBytes(unsigned long long bytes);
|
||||
const std::string GetFileName(const std::string& path,
|
||||
const std::string& saperators = "/\\");
|
||||
const std::string PathRemoveExtension(const std::string& path);
|
||||
template <typename T>
|
||||
const std::string ToHex(const T& v);
|
||||
} // namespace Strings
|
||||
} // namespace PD
|
37
include/pd/common/sys.hpp
Normal file
37
include/pd/common/sys.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/timetrace.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Sys {
|
||||
using TraceMap = std::map<std::string, TT::Res::Ref>;
|
||||
u64 GetTime();
|
||||
u64 GetNanoTime();
|
||||
TT::Res::Ref& GetTraceRef(const std::string& id);
|
||||
TraceMap& GetTraceMap();
|
||||
} // namespace Sys
|
||||
} // namespace PD
|
44
include/pd/common/timer.hpp
Normal file
44
include/pd/common/timer.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/sys.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Timer {
|
||||
public:
|
||||
Timer() {}
|
||||
~Timer() {}
|
||||
void Start() {}
|
||||
void Pause() {}
|
||||
void Update() {}
|
||||
void Reset() { start_ = Sys::GetTime(); }
|
||||
u64 Get() {}
|
||||
|
||||
private:
|
||||
u64 start_;
|
||||
u64 now_;
|
||||
};
|
||||
} // namespace PD
|
102
include/pd/common/timetrace.hpp
Normal file
102
include/pd/common/timetrace.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class TimeStats : public SmartCtor<TimeStats> {
|
||||
public:
|
||||
TimeStats(int l) : len(l), val(l, 0) {}
|
||||
~TimeStats() = default;
|
||||
|
||||
void Add(unsigned long long v) {
|
||||
val[idx] = v;
|
||||
idx = next(idx);
|
||||
num_val = std::min(num_val + 1, len);
|
||||
}
|
||||
|
||||
unsigned long long GetAverage() {
|
||||
if (!num_val) return 0.f;
|
||||
unsigned long long res = 0;
|
||||
for (int i = 0; i < num_val; i++) {
|
||||
res += val[smart_idx(i)];
|
||||
}
|
||||
return res / num_val;
|
||||
}
|
||||
|
||||
const std::vector<unsigned long long> &GetData() { return val; }
|
||||
const unsigned long long &operator[](int i) { return val[smart_idx(i)]; }
|
||||
const size_t GetLen() { return len; }
|
||||
const size_t GetNumValues() { return num_val; }
|
||||
|
||||
private:
|
||||
size_t next(size_t c) const { return (c + 1) % len; }
|
||||
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
|
||||
|
||||
int len = 0;
|
||||
std::vector<unsigned long long> val;
|
||||
int idx = 0;
|
||||
int num_val = 0;
|
||||
};
|
||||
namespace TT {
|
||||
class Res : public SmartCtor<Res> {
|
||||
public:
|
||||
Res() { protocol = TimeStats::New(60); }
|
||||
~Res() = default;
|
||||
|
||||
void SetID(const std::string &v) { id = v; }
|
||||
const std::string GetID() { return id; }
|
||||
void SetStart(unsigned long long v) { start = v; }
|
||||
unsigned long long GetStart() { return start; }
|
||||
void SetEnd(unsigned long long v) {
|
||||
end = v;
|
||||
protocol->Add(GetLastDiff());
|
||||
}
|
||||
unsigned long long GetEnd() { return end; }
|
||||
|
||||
unsigned long long GetLastDiff() { return end - start; }
|
||||
TimeStats::Ref GetProtocol() { return protocol; }
|
||||
|
||||
private:
|
||||
std::string id;
|
||||
unsigned long long start;
|
||||
unsigned long long end;
|
||||
TimeStats::Ref protocol;
|
||||
};
|
||||
void Beg(const std::string &id);
|
||||
void End(const std::string &id);
|
||||
class Scope {
|
||||
public:
|
||||
Scope(const std::string &id) {
|
||||
this->id = id;
|
||||
Beg(id);
|
||||
}
|
||||
~Scope() { End(id); }
|
||||
|
||||
private:
|
||||
std::string id;
|
||||
};
|
||||
} // namespace TT
|
||||
} // namespace PD
|
15161
include/pd/external/json.hpp
vendored
15161
include/pd/external/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
12841
include/pd/external/stb_image.h
vendored
12841
include/pd/external/stb_image.h
vendored
File diff suppressed because it is too large
Load Diff
2054
include/pd/external/stb_image_write.h
vendored
2054
include/pd/external/stb_image_write.h
vendored
File diff suppressed because it is too large
Load Diff
7891
include/pd/external/stb_truetype.h
vendored
7891
include/pd/external/stb_truetype.h
vendored
File diff suppressed because it is too large
Load Diff
@ -1,78 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/external/json.hpp>
|
||||
#include <pd/palladium.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
namespace IDB {
|
||||
void Start();
|
||||
void Stop();
|
||||
void Restart();
|
||||
} // namespace IDB
|
||||
} // namespace Palladium
|
||||
|
||||
using PDFlags = unsigned int;
|
||||
enum PDFlags_ {
|
||||
PDFlags_None = 0,
|
||||
PDFlags_MemTrack = 1 << 0,
|
||||
PDFlags_SceneSystem = 1 << 1,
|
||||
PDFlags_Default = PDFlags_SceneSystem,
|
||||
};
|
||||
|
||||
using PDMetrikOverlayFlags = unsigned int;
|
||||
enum PDMetrikOverlayFlags_ {
|
||||
PDMetrikOverlayFlags_None = 0, // Displays Nothing
|
||||
PDMetrikOverlayFlags_FPS = 1 << 0, // Display FPS
|
||||
PDMetrikOverlayFlags_CPU = 1 << 1, // Display CPU Usage
|
||||
PDMetrikOverlayFlags_GPU = 1 << 2, // Display GPU Usage
|
||||
PDMetrikOverlayFlags_CMD = 1 << 3, // Display GPU CMD Usage
|
||||
PDMetrikOverlayFlags_LMM = 1 << 4, // Display Linear Space Free
|
||||
PDMetrikOverlayFlags_LVT = 1 << 5, // Display Lithium Vertex Usage
|
||||
PDMetrikOverlayFlags_LID = 1 << 6, // Display Lithium Indices Usage
|
||||
PDMetrikOverlayFlags_LDM = 1 << 7, // Display Lithium Draw Command Num
|
||||
PDMetrikOverlayFlags_LDC = 1 << 8, // Display Lithium Drawcalls Count
|
||||
PDMetrikOverlayFlags_PDO = 1 << 9, // Display Overlay Info String
|
||||
PDMetrikOverlayFlags_MTD = 1 << 10, // Display Memory Usage (if enabled)
|
||||
PDMetrikOverlayFlags_CGR = 1 << 11, // Display CPU Graph
|
||||
PDMetrikOverlayFlags_GGR = 1 << 12, // Display GPU Graph
|
||||
PDMetrikOverlayFlags_Default =
|
||||
PDMetrikOverlayFlags_FPS | PDMetrikOverlayFlags_CPU |
|
||||
PDMetrikOverlayFlags_GPU | PDMetrikOverlayFlags_CMD |
|
||||
PDMetrikOverlayFlags_LMM | PDMetrikOverlayFlags_LVT |
|
||||
PDMetrikOverlayFlags_LID | PDMetrikOverlayFlags_LDM |
|
||||
PDMetrikOverlayFlags_LDC | PDMetrikOverlayFlags_PDO |
|
||||
PDMetrikOverlayFlags_MTD, // Enable All of Them exept Graphs
|
||||
};
|
||||
|
||||
using PDFTraceOverlayFlags = unsigned int;
|
||||
enum PDFTraceOverlayFlags_ {
|
||||
PDFTraceOverlayFlags_None = 0, // Displays Nothing
|
||||
PDFTraceOverlayFlags_DisplayName = 1 << 0, // Display Tracename
|
||||
PDFTraceOverlayFlags_DisplayAverage = 1 << 1, // Display Average Time
|
||||
PDFTraceOverlayFlags_DisplayMin = 1 << 2, // Display Minimum Time
|
||||
PDFTraceOverlayFlags_DisplayMax = 1 << 3, // Display Maximum Time
|
||||
PDFTraceOverlayFlags_FillBg = 1 << 4, // Make Background Darker
|
||||
PDFTraceOverlayFlags_DisplayHelp = 1 << 5, // Display Info for values
|
||||
PDFTraceOverlayFlags_Default =
|
||||
PDFTraceOverlayFlags_DisplayName | PDFTraceOverlayFlags_DisplayAverage |
|
||||
PDFTraceOverlayFlags_DisplayMin | PDFTraceOverlayFlags_DisplayMax |
|
||||
PDFTraceOverlayFlags_FillBg |
|
||||
PDFTraceOverlayFlags_DisplayHelp, // Enable All of Them
|
||||
};
|
||||
|
||||
// Outdated HidApi (HidV2Patched)
|
||||
extern u32 d7_hDown;
|
||||
extern u32 d7_hHeld;
|
||||
extern u32 d7_hUp;
|
||||
extern u32 d7_hRepeat; // Inofficial lol
|
||||
extern touchPosition d7_touch;
|
||||
|
||||
// Modern Global Api
|
||||
extern C3D_RenderTarget *pd_top;
|
||||
extern C3D_RenderTarget *pd_top_right;
|
||||
extern C3D_RenderTarget *pd_bottom;
|
||||
extern PDFlags pd_flags;
|
||||
extern PDMetrikOverlayFlags pd_ovl_flags;
|
||||
extern PDFTraceOverlayFlags pd_ftrace_ovl_flags;
|
||||
// Draw2
|
||||
extern float pd_draw2_tsm;
|
31
include/pd/graphics/li7_shader.hpp
Normal file
31
include/pd/graphics/li7_shader.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
// THIS FILE WAS GENERATED BY build_shaders.py!!!
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern unsigned char li7_shader[];
|
||||
extern size_t li7_shader_size;
|
433
include/pd/graphics/lithium.hpp
Normal file
433
include/pd/graphics/lithium.hpp
Normal file
@ -0,0 +1,433 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/memory.hpp>
|
||||
#include <pd/graphics/screen.hpp>
|
||||
#include <pd/graphics/texture.hpp>
|
||||
#include <pd/maths/vec.hpp>
|
||||
#include <pd/tools/markdown.hpp>
|
||||
|
||||
using LITextFlags = u32;
|
||||
|
||||
enum LITextFlags_ {
|
||||
LITextFlags_None = 0,
|
||||
LITextFlags_AlignRight = 1 << 0,
|
||||
LITextFlags_AlignMid = 1 << 1,
|
||||
LITextFlags_Shaddow = 1 << 2, // Draws the text twice
|
||||
LITextFlags_Wrap = 1 << 3, // May be runs better with TMS
|
||||
LITextFlags_Short = 1 << 4, // May be runs better with TMS
|
||||
LITextFlags_Scroll = 1 << 5, // Not implemented
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
/// @brief Container that holds top and bottom corners of a quad
|
||||
class Rect {
|
||||
public:
|
||||
Rect() = default;
|
||||
Rect(vec4 t, vec4 b) {
|
||||
top = t;
|
||||
bot = b;
|
||||
}
|
||||
Rect(vec2 tl, vec2 tr, vec2 bl, vec2 br) {
|
||||
top = vec4(tl, tr);
|
||||
bot = vec4(bl, br);
|
||||
}
|
||||
~Rect() = default;
|
||||
|
||||
vec4 Top() const { return top; }
|
||||
vec4 Bot() const { return bot; }
|
||||
|
||||
vec2 TopLeft() const { return vec2(top[0], top[1]); }
|
||||
vec2 TopRight() const { return vec2(top[2], top[3]); }
|
||||
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
|
||||
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
|
||||
|
||||
private:
|
||||
vec4 top;
|
||||
vec4 bot;
|
||||
};
|
||||
class Font : public SmartCtor<Font> {
|
||||
public:
|
||||
class Codepoint {
|
||||
public:
|
||||
Codepoint() {}
|
||||
~Codepoint() {}
|
||||
|
||||
u32 cp() const { return m_cp; }
|
||||
Codepoint& cp(u32 v) {
|
||||
m_cp = v;
|
||||
return *this;
|
||||
}
|
||||
vec4 uv() const { return m_uv; }
|
||||
Codepoint& uv(vec4 v) {
|
||||
m_uv = v;
|
||||
return *this;
|
||||
}
|
||||
Texture::Ref tex() const { return m_tex; }
|
||||
Codepoint& tex(Texture::Ref v) {
|
||||
m_tex = v;
|
||||
return *this;
|
||||
}
|
||||
vec2 size() const { return m_size; }
|
||||
Codepoint& size(vec2 v) {
|
||||
m_size = v;
|
||||
return *this;
|
||||
}
|
||||
float off() const { return m_off; }
|
||||
Codepoint& off(float v) {
|
||||
m_off = v;
|
||||
return *this;
|
||||
}
|
||||
bool invalid() const { return m_invalid; }
|
||||
Codepoint& invalid(bool v) {
|
||||
m_invalid = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
u32 m_cp = 0;
|
||||
vec4 m_uv;
|
||||
Texture::Ref m_tex = nullptr;
|
||||
vec2 m_size;
|
||||
float m_off = 0;
|
||||
bool m_invalid = false;
|
||||
};
|
||||
Font() {}
|
||||
~Font() {}
|
||||
void LoadTTF(const std::string& path, int px_height = 32);
|
||||
void LoadSystemFont();
|
||||
int PixelHeight() const { return pixel_height; }
|
||||
Codepoint& GetCodepoint(u32 c);
|
||||
bool SystemFont() const { return sysfont; }
|
||||
|
||||
private:
|
||||
bool sysfont;
|
||||
int pixel_height;
|
||||
std::vector<Texture::Ref> textures;
|
||||
std::map<u32, Codepoint> cpmap;
|
||||
};
|
||||
class Vertex {
|
||||
public:
|
||||
Vertex() {}
|
||||
Vertex(vec2 p, vec2 u, u32 c) {
|
||||
pos[0] = p[0];
|
||||
pos[1] = p[1];
|
||||
pos[2] = 0.f;
|
||||
uv = u;
|
||||
color = c;
|
||||
}
|
||||
~Vertex() {}
|
||||
|
||||
Vertex& Pos(vec3 v) {
|
||||
pos = v;
|
||||
return *this;
|
||||
}
|
||||
// Lets support that as well
|
||||
Vertex& Pos(vec2 v) {
|
||||
pos[0] = v[0];
|
||||
pos[1] = v[1];
|
||||
pos[2] = 0.f;
|
||||
return *this;
|
||||
}
|
||||
Vertex& Uv(vec2 v) {
|
||||
uv = v;
|
||||
return *this;
|
||||
}
|
||||
Vertex& Color(u32 v) {
|
||||
color = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// private:
|
||||
vec3 pos;
|
||||
vec2 uv;
|
||||
u32 color;
|
||||
};
|
||||
/// @brief Required to Set the TexENV
|
||||
enum RenderMode {
|
||||
RenderMode_RGBA,
|
||||
RenderMode_SysFont,
|
||||
};
|
||||
/// @brief Reform the Drawcommand by generating the Vertexbuffer into it
|
||||
class Command : public SmartCtor<Command> {
|
||||
public:
|
||||
Command() {}
|
||||
~Command() {}
|
||||
|
||||
Command& Layer(int v) {
|
||||
layer = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Layer() const { return layer; }
|
||||
|
||||
Command& Index(int v) {
|
||||
index = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Index() const { return index; }
|
||||
|
||||
Command& Tex(Texture::Ref v) {
|
||||
tex = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Texture::Ref Tex() const { return tex; }
|
||||
|
||||
Command& PushVertex(Vertex v) {
|
||||
vertex_buf.push_back(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::vector<u16>& IndexList() const { return index_buf; }
|
||||
const std::vector<Vertex>& VertexList() const { return vertex_buf; }
|
||||
|
||||
Command& PushIndex(u16 v) {
|
||||
index_buf.push_back(vertex_buf.size() + v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Command& Rendermode(const RenderMode& v) {
|
||||
mode = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RenderMode Rendermode() const { return mode; }
|
||||
|
||||
private:
|
||||
/// Using Default std::vector here
|
||||
std::vector<Vertex> vertex_buf;
|
||||
std::vector<u16> index_buf;
|
||||
int layer;
|
||||
Texture::Ref tex;
|
||||
int index;
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
};
|
||||
class TextBox {
|
||||
public:
|
||||
TextBox() {}
|
||||
TextBox(const vec2& s, float time) {
|
||||
size = s;
|
||||
time_created = time;
|
||||
optional = false;
|
||||
}
|
||||
~TextBox() {}
|
||||
|
||||
void TimeCreated(float v) { time_created = v; }
|
||||
void Size(const vec2& v) { size = v; }
|
||||
void Optional(bool v) { optional = v; }
|
||||
void Text(const std::string& v) { text = v; }
|
||||
|
||||
vec2 Size() const { return size; }
|
||||
float TimeCreated() const { return time_created; }
|
||||
bool Optional() const { return optional; }
|
||||
std::string Text() const { return text; }
|
||||
|
||||
private:
|
||||
vec2 size;
|
||||
float time_created;
|
||||
bool optional;
|
||||
std::string text; // TextWrap
|
||||
};
|
||||
using RenderFlags = u32;
|
||||
enum RenderFlags_ {
|
||||
RenderFlags_None = 0,
|
||||
RenderFlags_TMS = 1 << 0, ///< Text Map System
|
||||
RenderFlags_LRS = 1 << 1, ///< Layer Render System
|
||||
RenderFlags_Default = RenderFlags_TMS,
|
||||
};
|
||||
class Renderer : public SmartCtor<Renderer> {
|
||||
public:
|
||||
Renderer(RenderFlags flags = RenderFlags_Default);
|
||||
~Renderer();
|
||||
|
||||
void Render();
|
||||
|
||||
void OnScreen(Screen::Screen_ screen) {
|
||||
if (screen == Screen::Top) {
|
||||
bottom = false;
|
||||
area_size = top->GetSize();
|
||||
} else if (screen == Screen::Bottom) {
|
||||
bottom = true;
|
||||
area_size = bot->GetSize();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void OnScreen(bool bottom) {
|
||||
bottom = bottom;
|
||||
area_size = bottom ? bot->GetSize() : top->GetSize();
|
||||
}
|
||||
|
||||
void Rotation(float v) { rot = v; }
|
||||
float Rotation() const { return rot; }
|
||||
void TextScale(float v) { text_size = v; }
|
||||
void DefaultTextScale() { text_size = default_text_size; }
|
||||
float TextScale() const { return text_size; }
|
||||
|
||||
void UseTex(Texture::Ref v = nullptr) {
|
||||
if (v == nullptr) {
|
||||
current_tex = white;
|
||||
return;
|
||||
}
|
||||
current_tex = v;
|
||||
}
|
||||
|
||||
/// @brief Draws a Rect based on current Texture
|
||||
/// @param pos Pos
|
||||
/// @param size Size
|
||||
/// @param color Color
|
||||
/// @param uv UV Map
|
||||
void DrawRect(vec2 pos, vec2 size, u32 color,
|
||||
vec4 uv = vec4(0.f, 1.f, 1.f, 0.f));
|
||||
/// @brief Draw a Solid Rect (uses white tex)
|
||||
/// @note acts as a simplified Draw rect Wrapper
|
||||
/// @param pos Position
|
||||
/// @param size Size
|
||||
/// @param color Color
|
||||
void DrawRectSolid(vec2 pos, vec2 size, u32 color);
|
||||
/// @brief Render a Triangle
|
||||
/// @param a Position Alpha
|
||||
/// @param b Position Bravo
|
||||
/// @param c Position Delta
|
||||
/// @param color Color
|
||||
/// @note Defaults to Solif Color
|
||||
void DrawTriangle(vec2 a, vec2 b, vec2 c, u32 color);
|
||||
/// @brief Draw a Circle (Supports Textures)
|
||||
/// @param center_pos Center Position
|
||||
/// @param r Radius
|
||||
/// @param color Color
|
||||
/// @param segments Segments to use
|
||||
/// @note Textures could look a bit janky due to uv mapping
|
||||
void DrawCircle(vec2 center_pos, float r, u32 color, int segments);
|
||||
/// @brief Draw a Line between to Positions
|
||||
/// @param a Position Alpha
|
||||
/// @param b Position Bravo
|
||||
/// @param color Color
|
||||
/// @param t Thickness
|
||||
void DrawLine(vec2 a, vec2 b, u32 color, int t);
|
||||
void DrawText(vec2 pos, u32 color, const std::string& text, u32 flags = 0,
|
||||
vec2 ap = vec2());
|
||||
/// @brief Draw a Texture as 2D Image
|
||||
/// @param pos Position
|
||||
/// @param tex Texture reference
|
||||
/// @param scale Scale (cause maybe wants to be resized)
|
||||
/// @note Acts as a Simplified wrapper to DrawRect
|
||||
void DrawImage(vec2 pos, Texture::Ref tex, vec2 scale = vec2(1.f));
|
||||
|
||||
/// Debug STUFF
|
||||
u32 Vertices() const { return vertices; }
|
||||
u32 Indices() const { return indices; }
|
||||
u32 Commands() const { return commands; }
|
||||
u32 DrawCalls() const { return drawcalls; }
|
||||
|
||||
/// TOOLS ///
|
||||
void RotateCorner(vec2& v, float s, float c);
|
||||
Rect CreateRect(vec2 pos, vec2 size, float angle);
|
||||
Rect CreateLine(vec2 a, vec2 b, int t);
|
||||
bool InBox(vec2 pos, vec2 size, vec4 rect);
|
||||
bool InBox(vec2 alpha, vec2 bravo, vec2 charlie, vec4 rect);
|
||||
void OptiCommandList(std::vector<Command::Ref>& list);
|
||||
/// @brief Returns Viewport with xy
|
||||
vec4 GetViewport();
|
||||
/// @brief Push a Self Created command
|
||||
void PushCommand(Command::Ref cmd) { draw_list[bottom].push_back(cmd); }
|
||||
/// @brief Automatically sets up a command
|
||||
void SetupCommand(Command::Ref cmd);
|
||||
/// @brief Creates a default Quad Render Command
|
||||
void QuadCommand(Command::Ref cmd, const Rect& quad, vec4 uv, u32 col);
|
||||
/// @brief Create a Default Triangle
|
||||
void TriangleCommand(Command::Ref cmd, vec2 a, vec2 b, vec2 c, u32 col);
|
||||
/// @brief Create List of a Text Commands
|
||||
/// @param cmds Link to a command List
|
||||
/// @param pos Position
|
||||
/// @param color Color
|
||||
/// @param text Text
|
||||
/// @param flags Flags
|
||||
/// @param box (Size for wrapping / Offset for Centered Text)
|
||||
/// @note Funktion macht noch faxxen (Text nicht sichtbar)
|
||||
void TextCommand(std::vector<Command::Ref>& cmds, vec2 pos, u32 color,
|
||||
const std::string& text, LITextFlags flags, vec2 box);
|
||||
vec2 GetTextDimensions(const std::string& text);
|
||||
|
||||
private:
|
||||
/// Helper Funcitons ///
|
||||
void RenderOn(bool bottom);
|
||||
void UpdateRenderMode(const RenderMode& mode);
|
||||
|
||||
/// @brief Screens ///
|
||||
Screen::Ref top;
|
||||
Screen::Ref bot;
|
||||
|
||||
/// Context Related ///
|
||||
RenderFlags flags = RenderFlags_Default;
|
||||
vec2 area_size;
|
||||
bool bottom = false;
|
||||
int current_layer = 0;
|
||||
Texture::Ref current_tex = nullptr;
|
||||
Texture::Ref white = nullptr; // Single color
|
||||
Font::Ref font = nullptr;
|
||||
bool font_update;
|
||||
RenderMode mode = RenderMode_RGBA;
|
||||
// Text Map System
|
||||
std::map<std::string, TextBox> tms;
|
||||
/// Text Rendering ///
|
||||
const float default_font_h = 24.f;
|
||||
const float default_text_size = 0.7f;
|
||||
float text_size = 0.7f;
|
||||
/// Special ///
|
||||
float rot = 0.f;
|
||||
/// Rendering ///
|
||||
// Use dual drawlist
|
||||
std::vector<Command::Ref> draw_list[2];
|
||||
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
|
||||
std::vector<u16, LinearAllocator<u16>> index_buf;
|
||||
u32 vertex_idx = 0;
|
||||
u32 index_idx = 0;
|
||||
u32 cmd_idx = 0;
|
||||
|
||||
/// Debug ///
|
||||
u32 vertices = 0;
|
||||
u32 indices = 0;
|
||||
u32 commands = 0;
|
||||
u32 drawcalls = 0;
|
||||
|
||||
/// Shader
|
||||
DVLB_s* dvlb = nullptr;
|
||||
shaderProgram_s shader;
|
||||
C3D_AttrInfo attr;
|
||||
int uLoc_projection = 0;
|
||||
|
||||
/// Matrix
|
||||
C3D_Mtx top_proj;
|
||||
C3D_Mtx bot_proj;
|
||||
};
|
||||
} // namespace LI
|
||||
} // namespace PD
|
74
include/pd/graphics/screen.hpp
Normal file
74
include/pd/graphics/screen.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/maths/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Screen : public SmartCtor<Screen> {
|
||||
public:
|
||||
enum Screen_ { Top, Bottom, TopRight };
|
||||
Screen(Screen_ screen) {
|
||||
if (screen == Top) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == Bottom) {
|
||||
target = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
} else if (screen == TopRight) {
|
||||
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
|
||||
GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_RIGHT,
|
||||
DisplayTransferFlags);
|
||||
}
|
||||
}
|
||||
~Screen() {}
|
||||
|
||||
void Clear() { C3D_RenderTargetClear(target, C3D_CLEAR_ALL, 0x00000000, 0); }
|
||||
void Use() { C3D_FrameDrawOn(target); }
|
||||
|
||||
vec2 GetSize() const {
|
||||
return vec2(target->frameBuf.height, target->frameBuf.width);
|
||||
}
|
||||
|
||||
C3D_RenderTarget* Get() const { return target; }
|
||||
operator C3D_RenderTarget*() const { return target; }
|
||||
|
||||
private:
|
||||
const u32 DisplayTransferFlags =
|
||||
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
|
||||
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
|
||||
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
|
||||
C3D_RenderTarget* target;
|
||||
};
|
||||
} // namespace PD
|
123
include/pd/graphics/texture.hpp
Normal file
123
include/pd/graphics/texture.hpp
Normal file
@ -0,0 +1,123 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/maths/vec.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Texture : public SmartCtor<Texture> {
|
||||
public:
|
||||
enum Type {
|
||||
RGBA32,
|
||||
RGB24,
|
||||
A8,
|
||||
};
|
||||
|
||||
enum Filter {
|
||||
NEAREST,
|
||||
LINEAR,
|
||||
};
|
||||
/// @brief Default constructor
|
||||
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
|
||||
/// @brief Load file Constructor
|
||||
/// @param path path to file
|
||||
Texture(const std::string& path) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadFile(path);
|
||||
}
|
||||
/// @brief Load Memory constructor
|
||||
/// @param data File Data reference
|
||||
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadMemory(data);
|
||||
}
|
||||
/// @brief Load Pixels constructor
|
||||
/// @param data Pixel Buffer reference
|
||||
/// @param w width
|
||||
/// @param h height
|
||||
/// @param type Buffer Type
|
||||
/// @param filter Filter
|
||||
Texture(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST)
|
||||
: uv(0.f, 1.f, 1.f, 0.f) {
|
||||
this->LoadPixels(data, w, h, type, filter);
|
||||
}
|
||||
/// @brief Deconstructor (aka auto delete)
|
||||
~Texture() { Delete(); }
|
||||
|
||||
/// @brief Deletes image (if not already unloaded)
|
||||
void Delete();
|
||||
|
||||
/// @brief Load a png/jpg/bmp from fs into a gpu tex
|
||||
/// @param path path to image file
|
||||
void LoadFile(const std::string& path);
|
||||
/// @brief Load a png/jpg/bmp from memory
|
||||
/// @param data reference to data buffer of the file
|
||||
void LoadMemory(const std::vector<u8>& data);
|
||||
/// @brief Create Texture out of Pixel Data
|
||||
/// @param data Data reference
|
||||
/// @param w width
|
||||
/// @param h heigt
|
||||
/// @param type Type of the databuffer
|
||||
/// @param filter Filter (NEAREST OR LINEAR)
|
||||
void LoadPixels(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
|
||||
/// @brief Input a Texture that you had set up on your own
|
||||
/// @param tex Texture reference (deletes itself)
|
||||
/// @param rszs The size of the source image
|
||||
/// @param uvs Your uv Setup
|
||||
void LoadExternal(C3D_Tex* tex, vec2 rszs, vec4 uvs) {
|
||||
this->Delete();
|
||||
this->tex = tex;
|
||||
this->size = rszs;
|
||||
this->uv = uvs;
|
||||
}
|
||||
|
||||
vec2 GetRealSize() {
|
||||
if (!tex) {
|
||||
return vec2();
|
||||
}
|
||||
return vec2(tex->width, tex->height);
|
||||
}
|
||||
vec2 GetSize() const { return size; }
|
||||
C3D_Tex* GetTex() const { return tex; };
|
||||
vec4 GetUV() const { return uv; }
|
||||
bool IsValid() const { return tex != 0; }
|
||||
|
||||
operator C3D_Tex*() const { return tex; }
|
||||
operator vec2() const { return size; }
|
||||
operator vec4() const { return uv; }
|
||||
operator bool() const { return tex != 0; }
|
||||
|
||||
private:
|
||||
void MakeTex(std::vector<u8>& buf, int w, int h, Type type = RGBA32,
|
||||
Filter filter = NEAREST);
|
||||
vec2 size;
|
||||
vec4 uv;
|
||||
C3D_Tex* tex = nullptr;
|
||||
};
|
||||
} // namespace PD
|
@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
#include <pd/Net.hpp>
|
||||
#include <pd/external/json.hpp>
|
||||
#include <pd/global_db.hpp>
|
||||
#include <pd/palladium.hpp>
|
||||
|
||||
#define CFGVER "2"
|
||||
#define THEMEVER "0"
|
||||
|
||||
#ifndef V_PDBTIME
|
||||
#define V_PDBTIME "SUBMODULE"
|
||||
#endif
|
||||
#ifndef V_PDCSTRING
|
||||
#define V_PDCSTRING "SUBMODULE"
|
||||
#endif
|
||||
|
||||
// Base
|
||||
extern bool pdi_enable_scene_system;
|
||||
extern bool pdi_debugging;
|
||||
extern bool pdi_enable_memtrack;
|
||||
extern std::string pdi_app_name;
|
||||
extern std::string pdi_config_path;
|
||||
extern nlohmann::json pdi_config;
|
||||
extern u8 pdi_console_model;
|
||||
extern u8 pdi_system_region;
|
||||
extern bool pdi_is_citra;
|
||||
extern bool pdi_settings;
|
||||
extern NVec2 pdi_hid_touch_pos;
|
||||
extern bool pdi_is_ndsp;
|
||||
extern bool pdi_running;
|
||||
extern std::unique_ptr<Palladium::Scene> pdi_fade_scene;
|
||||
extern std::vector<std::unique_ptr<Palladium::Ovl>> pdi_overlays;
|
||||
extern unsigned int pdi_frames;
|
||||
extern u64 pdi_last_time;
|
||||
extern float pdi_framerate;
|
||||
extern unsigned int pdi_mt_color;
|
||||
extern unsigned int pdi_mt_txtcolor;
|
||||
extern bool pdi_mt_screen;
|
||||
extern float pdi_mt_txtSize;
|
||||
extern bool pdi_metrikd;
|
||||
extern bool pdi_ftraced;
|
||||
extern u64 pdi_delta_time;
|
||||
extern u64 pdi_last_tm;
|
||||
extern float pdi_dtm;
|
||||
extern float pdi_time;
|
||||
extern bool pdi_fadeout;
|
||||
extern bool pdi_fadein;
|
||||
extern bool pdi_fadeout2;
|
||||
extern bool pdi_fadein2;
|
||||
extern int pdi_fadealpha;
|
||||
extern int pdi_fadecolor;
|
||||
extern bool pdi_wait_fade;
|
||||
extern bool pdi_fade_exit;
|
||||
extern bool pdi_fade_scene_wait;
|
||||
extern bool pdi_idb_running;
|
||||
extern bool pdi_graphics_on;
|
||||
extern bool pdi_amdt;
|
||||
extern void* pdi_soc_buf;
|
||||
extern bool pdi_is_am_init;
|
||||
extern Palladium::Theme::Ref pdi_active_theme;
|
||||
extern bool pdi_lggrf;
|
||||
|
||||
Palladium::Net::Error pdi_soc_init();
|
||||
void pdi_soc_deinit();
|
@ -1,8 +0,0 @@
|
||||
// THIS FILE WAS GENERATED BY build_shaders.py!!!
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
extern unsigned char li7_shader[];
|
||||
extern size_t li7_shader_size;
|
@ -1,45 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/maths/NVec.hpp>
|
||||
|
||||
class NMat4 {
|
||||
public:
|
||||
NMat4() { Zeros(); }
|
||||
~NMat4() {}
|
||||
|
||||
void Zeros() { memset(this, 0, sizeof(*this)); }
|
||||
void Identity() { Diagonal(NVec4(1.f, 1.f, 1.f, 1.f)); }
|
||||
void Diagonal(NVec4 xyzw) {
|
||||
Zeros();
|
||||
r[0][0] = xyzw[0];
|
||||
r[1][1] = xyzw[1];
|
||||
r[2][2] = xyzw[2];
|
||||
r[3][3] = xyzw[3];
|
||||
}
|
||||
NMat4& Get() { return *this; }
|
||||
void Add(const NMat4& in) {
|
||||
for (int i = 0; i < 0x10; i++) {
|
||||
m[i] += in[i];
|
||||
}
|
||||
}
|
||||
void Sub(const NMat4& in) {
|
||||
for (int i = 0; i < 0x10; i++) {
|
||||
m[i] -= in[i];
|
||||
}
|
||||
}
|
||||
void Mul(const NMat4& in) {
|
||||
|
||||
}
|
||||
|
||||
void Transpose();
|
||||
float Inverse();
|
||||
|
||||
// Operators
|
||||
float operator[](int i) const { return m[i]; }
|
||||
float& operator[](int i) { return m[i]; }
|
||||
|
||||
union {
|
||||
NVec4 r[4];
|
||||
float m[0x10];
|
||||
};
|
||||
};
|
@ -1,366 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
struct NVec2 {
|
||||
// Init Funcs
|
||||
NVec2() {
|
||||
v[0] = 0;
|
||||
v[1] = 0;
|
||||
}
|
||||
NVec2(float x, float y) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
}
|
||||
NVec2(const NVec2 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
}
|
||||
NVec2(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
NVec2 &operator+=(const NVec2 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 operator+(const NVec2 &i) const {
|
||||
return NVec2(v[0] + i[0], v[1] + i[1]);
|
||||
}
|
||||
NVec2 operator+(const float &i) const { return NVec2(v[0] + i, v[1] + i); }
|
||||
|
||||
// Sub
|
||||
NVec2 &operator-=(const NVec2 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 operator-(const NVec2 &i) const {
|
||||
return NVec2(v[0] - i[0], v[1] - i[1]);
|
||||
}
|
||||
NVec2 operator-(const float &i) const { return NVec2(v[0] - i, v[1] - i); }
|
||||
|
||||
// Mul
|
||||
NVec2 &operator*=(const NVec2 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 operator*(const NVec2 &i) const {
|
||||
return NVec2(v[0] * i[0], v[1] * i[1]);
|
||||
}
|
||||
NVec2 operator*(const float &i) const { return NVec2(v[0] * i, v[1] * i); }
|
||||
|
||||
// Div
|
||||
NVec2 &operator/=(const NVec2 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec2 operator/(const NVec2 &i) const {
|
||||
return NVec2(v[0] / i[0], v[1] / i[1]);
|
||||
}
|
||||
NVec2 operator/(const float &i) const { return NVec2(v[0] / i, v[1] / i); }
|
||||
|
||||
// Compare
|
||||
bool operator==(const NVec2 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1];
|
||||
}
|
||||
|
||||
bool operator!=(const NVec2 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
NVec2 operator-() const { return NVec2(-v[0], -v[1]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
// Internal Values
|
||||
float v[2];
|
||||
};
|
||||
|
||||
struct NVec3 {
|
||||
// Init Funcs
|
||||
NVec3() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
}
|
||||
NVec3(float x, float y, float z) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
}
|
||||
NVec3(const NVec3 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
}
|
||||
NVec3(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
NVec3 &operator+=(const NVec3 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
v[2] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 operator+(const NVec3 &i) const {
|
||||
return NVec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
|
||||
}
|
||||
NVec3 operator+(const float &i) const {
|
||||
return NVec3(v[0] + i, v[1] + i, v[2] + i);
|
||||
}
|
||||
|
||||
// Sub
|
||||
NVec3 &operator-=(const NVec3 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
v[2] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 operator-(const NVec3 &i) const {
|
||||
return NVec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
|
||||
}
|
||||
NVec3 operator-(const float &i) const {
|
||||
return NVec3(v[0] - i, v[1] - i, v[2] - i);
|
||||
}
|
||||
|
||||
// Mul
|
||||
NVec3 &operator*=(const NVec3 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
v[2] *= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
v[2] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 operator*(const NVec3 &i) const {
|
||||
return NVec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
|
||||
}
|
||||
NVec3 operator*(const float &i) const {
|
||||
return NVec3(v[0] * i, v[1] * i, v[2] * i);
|
||||
}
|
||||
|
||||
// Div
|
||||
NVec3 &operator/=(const NVec3 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
v[2] /= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
v[2] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec3 operator/(const NVec3 &i) const {
|
||||
return NVec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
|
||||
}
|
||||
NVec3 operator/(const float &i) const {
|
||||
return NVec3(v[0] / i, v[1] / i, v[2] / i);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const NVec3 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
|
||||
}
|
||||
|
||||
bool operator!=(const NVec3 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
NVec3 operator-() const { return NVec3(-v[0], -v[1], -v[2]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
|
||||
float v[3];
|
||||
};
|
||||
|
||||
struct NVec4 {
|
||||
// Init Funcs
|
||||
NVec4() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
v[3] = 0.f;
|
||||
}
|
||||
NVec4(float x, float y, float z, float w) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = w;
|
||||
}
|
||||
NVec4(const NVec4 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
v[3] = i[3];
|
||||
}
|
||||
|
||||
NVec4(const NVec2 &i0, const NVec2 &i1) {
|
||||
v[0] = i0[0];
|
||||
v[1] = i0[1];
|
||||
v[2] = i1[0];
|
||||
v[3] = i1[1];
|
||||
}
|
||||
NVec4(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
v[3] = i;
|
||||
}
|
||||
|
||||
// Operators
|
||||
// Add
|
||||
NVec4 &operator+=(const NVec4 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
v[3] += i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec4 operator+(const NVec4 &i) const {
|
||||
return NVec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
|
||||
}
|
||||
|
||||
// Sub
|
||||
NVec4 &operator-=(const NVec4 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
v[3] -= i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
NVec4 operator-(const NVec4 &i) const {
|
||||
return NVec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const NVec4 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
|
||||
}
|
||||
|
||||
bool operator!=(const NVec4 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
NVec3 operator-() const { return NVec3(-v[0], -v[1], -v[2]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const {
|
||||
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
|
||||
}
|
||||
|
||||
// Vec Acess
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
float w() const { return v[3]; }
|
||||
float &w() { return v[3]; }
|
||||
// Quaternion Acess
|
||||
float r() const { return v[0]; }
|
||||
float &r() { return v[0]; }
|
||||
float k() const { return v[1]; }
|
||||
float &k() { return v[1]; }
|
||||
float j() const { return v[2]; }
|
||||
float &j() { return v[2]; }
|
||||
float i() const { return v[3]; }
|
||||
float &i() { return v[3]; }
|
||||
// Internal Values
|
||||
float v[4];
|
||||
};
|
34
include/pd/maths/bit_util.hpp
Normal file
34
include/pd/maths/bit_util.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace BitUtil {
|
||||
bool IsSingleBit(u32 v);
|
||||
u32 GetPow2(u32 v);
|
||||
} // namespace BitUtil
|
||||
} // namespace PD
|
102
include/pd/maths/color.hpp
Normal file
102
include/pd/maths/color.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
/// @brief Color class (Supports hex, rgb(a)8, u32 input)
|
||||
/// @note no safeteychecks used here for performance
|
||||
class Color {
|
||||
public:
|
||||
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
|
||||
Color(u32 color) {
|
||||
m_a = (color >> 24) & 0xff;
|
||||
m_b = (color >> 16) & 0xff;
|
||||
m_g = (color >> 8) & 0xff;
|
||||
m_r = color & 0xff;
|
||||
}
|
||||
Color(u8 r, u8 g, u8 b, u8 a = 255) {
|
||||
m_r = r;
|
||||
m_g = g;
|
||||
m_b = b;
|
||||
m_a = a;
|
||||
}
|
||||
Color(float r, float g, float b, float a = 1.f) {
|
||||
m_r = static_cast<u8>(255.f * r);
|
||||
m_g = static_cast<u8>(255.f * g);
|
||||
m_b = static_cast<u8>(255.f * b);
|
||||
m_a = static_cast<u8>(255.f * a);
|
||||
}
|
||||
Color(const std::string& hex) { Hex(hex); }
|
||||
~Color() {}
|
||||
|
||||
Color& Hex(const std::string& hex);
|
||||
std::string Hex(bool rgba = false) const;
|
||||
|
||||
Color& r(u8 v) {
|
||||
m_r = v;
|
||||
return *this;
|
||||
}
|
||||
u8 r() const { return m_r; }
|
||||
Color& g(u8 v) {
|
||||
m_g = v;
|
||||
return *this;
|
||||
}
|
||||
u8 g() const { return m_r; }
|
||||
Color& b(u8 v) {
|
||||
m_b = v;
|
||||
return *this;
|
||||
}
|
||||
u8 b() const { return m_r; }
|
||||
Color& a(u8 v) {
|
||||
m_a = v;
|
||||
return *this;
|
||||
}
|
||||
u8 a() const { return m_r; }
|
||||
|
||||
Color& Fade(const Color& color, float p) {
|
||||
m_a = static_cast<u8>((color.a() - m_a) * ((p + 1.f) / 2));
|
||||
m_b = static_cast<u8>((color.b() - m_b) * ((p + 1.f) / 2));
|
||||
m_g = static_cast<u8>((color.g() - m_g) * ((p + 1.f) / 2));
|
||||
m_r = static_cast<u8>((color.r() - m_r) * ((p + 1.f) / 2));
|
||||
return *this;
|
||||
}
|
||||
u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_r; }
|
||||
float Luminance() const {
|
||||
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
|
||||
return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
|
||||
}
|
||||
bool IsLight() const { return (Luminance() >= 0.5); }
|
||||
|
||||
operator u32() const { return Get(); }
|
||||
|
||||
private:
|
||||
u8 m_r;
|
||||
u8 m_g;
|
||||
u8 m_b;
|
||||
u8 m_a;
|
||||
};
|
||||
} // namespace PD
|
34
include/pd/maths/img_convert.hpp
Normal file
34
include/pd/maths/img_convert.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 tobid7
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace ImgConvert {
|
||||
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
|
||||
const int &w, const int &h);
|
||||
} // namespace ImgConvert
|
||||
} // namespace PD
|
404
include/pd/maths/vec.hpp
Normal file
404
include/pd/maths/vec.hpp
Normal file
@ -0,0 +1,404 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Why Creating this:
|
||||
* Cause using makes coding much better structured
|
||||
* and easy to use like in glsl or glm
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
struct vec2 {
|
||||
// Init Funcs
|
||||
vec2() {
|
||||
v[0] = 0;
|
||||
v[1] = 0;
|
||||
}
|
||||
vec2(float x, float y) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
}
|
||||
vec2(const vec2 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
}
|
||||
vec2(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
vec2 &operator+=(const vec2 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator+(const vec2 &i) const { return vec2(v[0] + i[0], v[1] + i[1]); }
|
||||
vec2 operator+(const float &i) const { return vec2(v[0] + i, v[1] + i); }
|
||||
|
||||
// Sub
|
||||
vec2 &operator-=(const vec2 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator-(const vec2 &i) const { return vec2(v[0] - i[0], v[1] - i[1]); }
|
||||
vec2 operator-(const float &i) const { return vec2(v[0] - i, v[1] - i); }
|
||||
|
||||
// Mul
|
||||
vec2 &operator*=(const vec2 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator*(const vec2 &i) const { return vec2(v[0] * i[0], v[1] * i[1]); }
|
||||
vec2 operator*(const float &i) const { return vec2(v[0] * i, v[1] * i); }
|
||||
|
||||
// Div
|
||||
vec2 &operator/=(const vec2 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec2 operator/(const vec2 &i) const { return vec2(v[0] / i[0], v[1] / i[1]); }
|
||||
vec2 operator/(const float &i) const { return vec2(v[0] / i, v[1] / i); }
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec2 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1];
|
||||
}
|
||||
|
||||
bool operator!=(const vec2 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
vec2 operator-() const { return vec2(-v[0], -v[1]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
// Internal Values
|
||||
float v[2];
|
||||
};
|
||||
|
||||
struct vec3 {
|
||||
// Init Funcs
|
||||
vec3() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
}
|
||||
vec3(float x, float y, float z) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
}
|
||||
vec3(const vec3 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
}
|
||||
vec3(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
}
|
||||
//// PD REWRITE ADDITIONAL CONTENT ////
|
||||
vec3(const vec2 &xy, float z) {
|
||||
v[0] = xy[0];
|
||||
v[1] = xy[1];
|
||||
v[2] = z;
|
||||
}
|
||||
vec3(float x, const vec2 &yz) {
|
||||
v[0] = x;
|
||||
v[1] = yz[0];
|
||||
v[2] = yz[1];
|
||||
}
|
||||
|
||||
// Operations
|
||||
// Add
|
||||
vec3 &operator+=(const vec3 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator+=(const float &i) {
|
||||
v[0] += i;
|
||||
v[1] += i;
|
||||
v[2] += i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator+(const vec3 &i) const {
|
||||
return vec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
|
||||
}
|
||||
vec3 operator+(const float &i) const {
|
||||
return vec3(v[0] + i, v[1] + i, v[2] + i);
|
||||
}
|
||||
|
||||
// Sub
|
||||
vec3 &operator-=(const vec3 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator-=(const float &i) {
|
||||
v[0] -= i;
|
||||
v[1] -= i;
|
||||
v[2] -= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator-(const vec3 &i) const {
|
||||
return vec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
|
||||
}
|
||||
vec3 operator-(const float &i) const {
|
||||
return vec3(v[0] - i, v[1] - i, v[2] - i);
|
||||
}
|
||||
|
||||
// Mul
|
||||
vec3 &operator*=(const vec3 &i) {
|
||||
v[0] *= i[0];
|
||||
v[1] *= i[1];
|
||||
v[2] *= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator*=(const float &i) {
|
||||
v[0] *= i;
|
||||
v[1] *= i;
|
||||
v[2] *= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator*(const vec3 &i) const {
|
||||
return vec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
|
||||
}
|
||||
vec3 operator*(const float &i) const {
|
||||
return vec3(v[0] * i, v[1] * i, v[2] * i);
|
||||
}
|
||||
|
||||
// Div
|
||||
vec3 &operator/=(const vec3 &i) {
|
||||
v[0] /= i[0];
|
||||
v[1] /= i[1];
|
||||
v[2] /= i[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 &operator/=(const float &i) {
|
||||
v[0] /= i;
|
||||
v[1] /= i;
|
||||
v[2] /= i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec3 operator/(const vec3 &i) const {
|
||||
return vec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
|
||||
}
|
||||
vec3 operator/(const float &i) const {
|
||||
return vec3(v[0] / i, v[1] / i, v[2] / i);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec3 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
|
||||
}
|
||||
|
||||
bool operator!=(const vec3 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
vec3 operator-() const { return vec3(-v[0], -v[1], -v[2]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
|
||||
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
|
||||
//// PALLADIUM REWRITE ADDITIONAL CONTENT ////
|
||||
vec2 xy() const { return vec2(v[0], v[1]); }
|
||||
vec2 yz() const { return vec2(v[1], v[2]); }
|
||||
|
||||
float v[3];
|
||||
};
|
||||
|
||||
struct vec4 {
|
||||
// Init Funcs
|
||||
vec4() {
|
||||
v[0] = 0.f;
|
||||
v[1] = 0.f;
|
||||
v[2] = 0.f;
|
||||
v[3] = 0.f;
|
||||
}
|
||||
vec4(float x, float y, float z, float w) {
|
||||
v[0] = x;
|
||||
v[1] = y;
|
||||
v[2] = z;
|
||||
v[3] = w;
|
||||
}
|
||||
vec4(const vec4 &i) {
|
||||
v[0] = i[0];
|
||||
v[1] = i[1];
|
||||
v[2] = i[2];
|
||||
v[3] = i[3];
|
||||
}
|
||||
|
||||
vec4(const vec2 &i0, const vec2 &i1) {
|
||||
v[0] = i0[0];
|
||||
v[1] = i0[1];
|
||||
v[2] = i1[0];
|
||||
v[3] = i1[1];
|
||||
}
|
||||
vec4(float i) {
|
||||
v[0] = i;
|
||||
v[1] = i;
|
||||
v[2] = i;
|
||||
v[3] = i;
|
||||
}
|
||||
|
||||
// Operators
|
||||
// Add
|
||||
vec4 &operator+=(const vec4 &i) {
|
||||
v[0] += i[0];
|
||||
v[1] += i[1];
|
||||
v[2] += i[2];
|
||||
v[3] += i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec4 operator+(const vec4 &i) const {
|
||||
return vec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
|
||||
}
|
||||
|
||||
// Sub
|
||||
vec4 &operator-=(const vec4 &i) {
|
||||
v[0] -= i[0];
|
||||
v[1] -= i[1];
|
||||
v[2] -= i[2];
|
||||
v[3] -= i[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
vec4 operator-(const vec4 &i) const {
|
||||
return vec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
|
||||
}
|
||||
|
||||
// Compare
|
||||
bool operator==(const vec4 &in) const {
|
||||
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
|
||||
}
|
||||
|
||||
bool operator!=(const vec4 &in) const {
|
||||
// use the first comparefuncs result
|
||||
// and swap it lol
|
||||
return !(*this == in);
|
||||
}
|
||||
|
||||
// Base
|
||||
vec3 operator-() const { return vec3(-v[0], -v[1], -v[2]); }
|
||||
float operator[](int i) const { return v[i]; }
|
||||
float &operator[](int i) { return v[i]; }
|
||||
|
||||
float len() const { return sqrt(sqlen()); }
|
||||
float sqlen() const {
|
||||
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
|
||||
}
|
||||
|
||||
// Vec2 Acess
|
||||
float x() const { return v[0]; }
|
||||
float &x() { return v[0]; }
|
||||
float y() const { return v[1]; }
|
||||
float &y() { return v[1]; }
|
||||
float z() const { return v[2]; }
|
||||
float &z() { return v[2]; }
|
||||
float w() const { return v[3]; }
|
||||
float &w() { return v[3]; }
|
||||
// Quaternion Acess
|
||||
float r() const { return v[0]; }
|
||||
float &r() { return v[0]; }
|
||||
float k() const { return v[1]; }
|
||||
float &k() { return v[1]; }
|
||||
float j() const { return v[2]; }
|
||||
float &j() { return v[2]; }
|
||||
float i() const { return v[3]; }
|
||||
float &i() { return v[3]; }
|
||||
// Internal Values
|
||||
float v[4];
|
||||
};
|
||||
} // namespace PD
|
@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define NPI_NIMG_ (uint32_t)0x4e494d47 // Magic: NIMG
|
||||
|
||||
namespace Palladium {
|
||||
struct nimg {
|
||||
unsigned int magic; // Magic number defaults do NPI_NIMG_
|
||||
int width;
|
||||
int height;
|
||||
int format;
|
||||
int compression;
|
||||
std::vector<unsigned char> pixel_buffer;
|
||||
|
||||
nimg(int w = 0, int h = 0, int fmt = 0, int cmp = 0) {
|
||||
magic = NPI_NIMG_;
|
||||
width = w;
|
||||
height = h;
|
||||
format = fmt;
|
||||
compression = cmp;
|
||||
pixel_buffer.resize((w * h) * (format ? 3 : 4));
|
||||
}
|
||||
};
|
||||
nimg NIMG_Load(std::string path);
|
||||
nimg NIMG_LoadFromMem(unsigned char* buffer, size_t bf_size);
|
||||
void NIMG_Save(nimg image, std::string path);
|
||||
} // namespace Palladium
|
@ -1,183 +0,0 @@
|
||||
#pragma once
|
||||
/// c++ Includes
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
/// c includes
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
/// 3ds Includes
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
/// Palladium Includes
|
||||
#include <pd/Hardware.hpp>
|
||||
#include <pd/Overlays.hpp>
|
||||
#include <pd/Ovl.hpp>
|
||||
#include <pd/ResultDecoder.hpp>
|
||||
#include <pd/Sprite.hpp>
|
||||
#include <pd/Tasks.hpp>
|
||||
#include <pd/Time.hpp>
|
||||
#include <pd/base/Color.hpp>
|
||||
#include <pd/base/FunctionTrace.hpp>
|
||||
#include <pd/base/Lang.hpp>
|
||||
#include <pd/base/Memory.hpp>
|
||||
#include <pd/base/stringtool.hpp>
|
||||
#include <pd/parameter.hpp>
|
||||
#include <pd/thread.hpp>
|
||||
|
||||
#define PDVSTRING "1.0.0"
|
||||
|
||||
#define DEFAULT_CENTER 0.5f
|
||||
|
||||
/// @param pd_max_objects Config Param for C2D Mac objects
|
||||
extern int pd_max_objects;
|
||||
|
||||
namespace Palladium {
|
||||
/// @brief Get Deltatime
|
||||
/// @return Deltatime
|
||||
float GetDeltaTime();
|
||||
|
||||
/// @brief Scene Class
|
||||
class Scene {
|
||||
public:
|
||||
/// @brief Stack of the Scenes
|
||||
static std::stack<std::unique_ptr<Scene>> scenes;
|
||||
/// @brief Deconstructor
|
||||
virtual ~Scene() {}
|
||||
virtual void Update() = 0;
|
||||
/// @brief Push a Scene to Stack
|
||||
/// @param scene Scene to Push
|
||||
/// @param fade FadeEffect (Not Correctly Implementet yet)
|
||||
static void Load(std::unique_ptr<Scene> scene, bool fade = false);
|
||||
/// @brief Go Back a Scene
|
||||
static void Back();
|
||||
/// @brief do the Draw (Called in Palladium::MainLoop())
|
||||
static void doUpdate();
|
||||
};
|
||||
|
||||
/// @brief Integrated Setting Menu of Palladium
|
||||
class RSettings : public Palladium::Scene {
|
||||
private:
|
||||
/// @brief State (Define for Menus)
|
||||
enum RState {
|
||||
RSETTINGS, // Main Settings Menu
|
||||
RIDB, // Internal Debugger
|
||||
ROVERLAYS, // Overlay Settings
|
||||
RFTRACE, // FTRace Menu
|
||||
RUI7, // UI7 Menu
|
||||
RLOGS, // Logs
|
||||
RFV, // Font Viewer
|
||||
};
|
||||
|
||||
/// @param shared_request Defines requests from Draw to Logic
|
||||
/// As it is not planned to make Draw non const you'll need
|
||||
/// A map of data or bool values that are mutable ake
|
||||
/// editable by const functions
|
||||
mutable std::map<unsigned int, unsigned int> shared_request;
|
||||
/// @param m_state Current menu State (Default=MainMenu aka RSETTINGS)
|
||||
Palladium::RSettings::RState m_state =
|
||||
Palladium::RSettings::RState::RSETTINGS;
|
||||
|
||||
/// @brief Position in FTrace Menu
|
||||
int ftrace_index = 0;
|
||||
|
||||
/// @param mtovlstate State of Metricks Overlay
|
||||
std::string mtovlstate = "false";
|
||||
/// @param mtscreenstate Screen the Overlay is Set to
|
||||
std::string mtscreenstate = "Top";
|
||||
std::string kbd_test;
|
||||
PDKeyboardState kbd_state;
|
||||
bool statemtold = false;
|
||||
bool stateftold = false;
|
||||
float tmp_txt;
|
||||
|
||||
public:
|
||||
/// @brief Constructor
|
||||
RSettings();
|
||||
/// @brief Deconstructor
|
||||
~RSettings();
|
||||
void Update() override;
|
||||
};
|
||||
|
||||
/// @brief Show Up the Palladium-Settings Menu
|
||||
void LoadSettings();
|
||||
/// @brief Show Up The Theme Editor
|
||||
void LoadThemeEditor();
|
||||
/// @brief Get's The Programs Time running
|
||||
/// @return Time Running
|
||||
float GetTime();
|
||||
/// @brief Get Framerate as Number
|
||||
/// @return FPS
|
||||
int GetFps();
|
||||
|
||||
/// @brief Get A Rendom Int
|
||||
/// @param b From
|
||||
/// @param e To
|
||||
/// @return Random Int
|
||||
int GetRandomInt(int b, int e);
|
||||
/// @brief Fade In
|
||||
/// @param duration Duration in Frames
|
||||
void FadeIn();
|
||||
/// @brief Fade Out
|
||||
/// @param duration Duration in Frames
|
||||
void FadeOut();
|
||||
/// @brief Display Fade Effects
|
||||
void FadeDisplay();
|
||||
|
||||
namespace Init {
|
||||
/// @brief Init Default Palladium
|
||||
/// @param app_name Name of Your App
|
||||
/// @return ResCode
|
||||
Result Main(std::string app_name = "pdGame");
|
||||
/// @brief Init Minimal Palladium (For better Hax2.x support)
|
||||
/// @param app_name Name of Your App
|
||||
/// @return ResCode
|
||||
Result Minimal(std::string app_name = "pdGame");
|
||||
/// @brief Reload the Graphics Engine
|
||||
/// @return ResCode
|
||||
Result Reload();
|
||||
/// @brief Init Graphics Only (NOT SUPPORTET use Reload)
|
||||
void Graphics();
|
||||
/// @brief Init Ndsp for Sounds
|
||||
void NdspFirm();
|
||||
} // namespace Init
|
||||
|
||||
namespace FS {
|
||||
/// @brief Check if File exists
|
||||
/// @param path Path to the File
|
||||
/// @return exists or not
|
||||
bool FileExist(const std::string &path);
|
||||
} // namespace FS
|
||||
|
||||
/// @brief Check if Ndsp is Init
|
||||
/// @return is or not
|
||||
bool IsNdspInit();
|
||||
/// @brief Get Current Framerate as String
|
||||
/// @return Framerate String
|
||||
std::string GetFramerate();
|
||||
/// @brief MainLoop of Palladiums
|
||||
/// @return Is Still Running or not
|
||||
bool MainLoop();
|
||||
/// @brief Exit App (brak the MainLoop)
|
||||
void ExitApp();
|
||||
|
||||
/// @brief Clear the Citro2D TextBuffers
|
||||
/// @param
|
||||
void ClearTextBufs(void);
|
||||
|
||||
/// @brief Draw Overlays And end the Frame. DO NEVER USE C3D_FRAMEEND cause it
|
||||
/// breaks Overlay crash Security
|
||||
void FrameEnd();
|
||||
|
||||
/// @brief Returns App Working Directory path
|
||||
/// @return AppDir Path
|
||||
std::string GetAppDirectory();
|
||||
/// @brief returns path to the Data Directory
|
||||
/// @return data dir path
|
||||
std::string GetDataDirectory();
|
||||
} // namespace Palladium
|
@ -1,134 +0,0 @@
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
|
||||
namespace Palladium {
|
||||
class Parameter {
|
||||
private:
|
||||
using id = size_t;
|
||||
|
||||
template <typename T>
|
||||
struct type {
|
||||
static void id() {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static id type_id() {
|
||||
return reinterpret_cast<id>(&type<T>::id);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using decay = typename std::decay<T>::type;
|
||||
|
||||
template <typename T>
|
||||
using none =
|
||||
typename std::enable_if<!std::is_same<Parameter, T>::value>::type;
|
||||
|
||||
struct base {
|
||||
virtual ~base() {}
|
||||
virtual bool is(id) const = 0;
|
||||
virtual base *copy() const = 0;
|
||||
} *p = nullptr;
|
||||
|
||||
template <typename T>
|
||||
struct data : base, std::tuple<T> {
|
||||
using std::tuple<T>::tuple;
|
||||
|
||||
T &get() & { return std::get<0>(*this); }
|
||||
T const &get() const & { return std::get<0>(*this); }
|
||||
|
||||
bool is(id i) const override { return i == type_id<T>(); }
|
||||
base *copy() const override { return new data{get()}; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T &stat() {
|
||||
return static_cast<data<T> &>(*p).get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const &stat() const {
|
||||
return static_cast<data<T> const &>(*p).get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T &dyn() {
|
||||
return dynamic_cast<data<T> &>(*p).get();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T const &dyn() const {
|
||||
return dynamic_cast<data<T> const &>(*p).get();
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
Parameter() {}
|
||||
|
||||
/**
|
||||
* @brief Destructs the Parameter
|
||||
*/
|
||||
~Parameter() { delete p; }
|
||||
|
||||
/**
|
||||
* @brief Copy constructor
|
||||
* @param s The Parameter to copy
|
||||
*/
|
||||
Parameter(Parameter &&s) : p{s.p} { s.p = nullptr; }
|
||||
|
||||
/**
|
||||
* @brief Const copy constructor
|
||||
* @param s The Parameter to copy
|
||||
*/
|
||||
Parameter(Parameter const &s) : p{s.p->copy()} {}
|
||||
|
||||
/**
|
||||
* @brief Initializes the Parameter with the given value
|
||||
* @param x The value to initialize the Parameter with
|
||||
*/
|
||||
template <typename T, typename U = decay<T>, typename = none<U>>
|
||||
Parameter(T &&x) : p{new data<U>{std::forward<T>(x)}} {}
|
||||
|
||||
/**
|
||||
* @brief Overloads the assignment operator
|
||||
* @param s The value to set the Parameter to
|
||||
*/
|
||||
Parameter &operator=(Parameter s) {
|
||||
swap(*this, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend void swap(Parameter &s, Parameter &r) { std::swap(s.p, r.p); }
|
||||
|
||||
/**
|
||||
* @brief Clears the Parameter
|
||||
*/
|
||||
void clear() {
|
||||
delete p;
|
||||
p = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the Parameter is the given type
|
||||
* @tparam T The type to check
|
||||
* @return Whether the Parameter has the given type or not
|
||||
*/
|
||||
template <typename T>
|
||||
bool is() const {
|
||||
return p ? p->is(type_id<T>()) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the value of the Parameter
|
||||
* @tparam T The type of the Parameter
|
||||
* @return The value of the Parameter
|
||||
* @warning If the type of the Parameter doesn't match the type of it's stored
|
||||
* value, it will result in undefined behaviour.
|
||||
*/
|
||||
template <typename T>
|
||||
T &get() & {
|
||||
return stat<T>();
|
||||
}
|
||||
};
|
||||
} // namespace Palladium
|
@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#define PD_SMART_CTOR(type) \
|
||||
using Ref = std::shared_ptr<type>; \
|
||||
template <typename... args> \
|
||||
static Ref New(args&&... cargs) { \
|
||||
return std::make_shared<type>(std::forward<args>(cargs)...); \
|
||||
}
|
46
include/pd/sound/sound.hpp
Normal file
46
include/pd/sound/sound.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/common/memory.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Sound : public SmartCtor<Sound> {
|
||||
public:
|
||||
Sound();
|
||||
~Sound();
|
||||
|
||||
void Play();
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
u32 dataSize;
|
||||
ndspWaveBuf wavBuf;
|
||||
std::vector<u8, LinearAllocator<u8>> dat;
|
||||
int channel;
|
||||
};
|
||||
} // namespace PD
|
@ -1,122 +0,0 @@
|
||||
#pragma once
|
||||
#include <3ds.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <pd/parameter.hpp>
|
||||
|
||||
using CTRU_Thread = Thread;
|
||||
|
||||
#define THREAD_STACK_SIZE 0x1000
|
||||
|
||||
namespace Palladium {
|
||||
class Thread {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor
|
||||
* @note This should only be called when calling m3d::Thread::initialize()
|
||||
* before calling m3d::Thread::start()
|
||||
*/
|
||||
Thread();
|
||||
|
||||
/**
|
||||
* @brief Constructs the thread
|
||||
* @param t_function The thread function
|
||||
* @param t_parameter The parameter to pass to the function
|
||||
* @param t_autostart Whether the thread should start instantly
|
||||
* @param t_detached Whether the thread starts detached or not
|
||||
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded
|
||||
* to multiples of 8 bytes)
|
||||
* @note t_function needs to be of type `void` and take one (and only one)
|
||||
* parameter of type m3d::Parameter
|
||||
* @warning If the thread priority is lower than the priority of the calling
|
||||
* thread, the thread will never get executed. Use
|
||||
* m3d::Thread::getCurrentPriority() to get the priority of the current thread
|
||||
*/
|
||||
Thread(std::function<void(Palladium::Parameter)> t_function,
|
||||
Palladium::Parameter t_parameter = nullptr, bool t_autostart = false,
|
||||
bool t_detached = false,
|
||||
unsigned long long int t_stackSize = 4 * 1024);
|
||||
|
||||
/**
|
||||
* @brief Destructs the thread
|
||||
*/
|
||||
virtual ~Thread();
|
||||
|
||||
/**
|
||||
* @brief Initializes the thread
|
||||
* @param t_function The thread function
|
||||
* @param t_parameter The parameter to pass to the function
|
||||
* @param t_autostart Whether the thread should start instantly
|
||||
* @param t_detached Whether the thread starts detached or not
|
||||
* @param t_stackSize The stacksize allocated for the thread in bytes (rounded
|
||||
* to multiples of 8 bytes)
|
||||
* @note t_function needs to be of type `void` and take one (and only one)
|
||||
* parameter of type m3d::Parameter
|
||||
* @warning If the thread priority is lower than the priority of the calling
|
||||
* thread, the thread will never get executed. Use
|
||||
* m3d::Thread::getCurrentPriority() to get the priority of the current thread
|
||||
*/
|
||||
void initialize(std::function<void(Palladium::Parameter)> t_function,
|
||||
Palladium::Parameter t_parameter = nullptr,
|
||||
bool t_autostart = false, bool t_detached = false,
|
||||
unsigned long long int t_stackSize = 4 * 1024);
|
||||
|
||||
/**
|
||||
* @brief Sets the size of the stack that gets allocated for the next thread
|
||||
* that get's started
|
||||
* @param t_stackSize The allocated space in bytes (rounded to multiples of 8
|
||||
* bytes)
|
||||
*/
|
||||
void setStackSize(unsigned long long int t_stackSize);
|
||||
|
||||
/**
|
||||
* @brief Starts the thread. To restart it, call Thread::join() before
|
||||
* @param t_detached Whether the thread should start detached or not
|
||||
*/
|
||||
void start(bool t_detached = false);
|
||||
|
||||
/**
|
||||
* @brief Detaches the thread
|
||||
*/
|
||||
void kill();
|
||||
|
||||
/**
|
||||
* @brief Waits for the thread to finish
|
||||
* @param t_timeout The timeout in nanoseconds. Leave it for no timeout
|
||||
*/
|
||||
void join(long long unsigned int t_timeout = U64_MAX);
|
||||
|
||||
bool isRunning();
|
||||
|
||||
/**
|
||||
* @brief Puts the thread to sleep
|
||||
*
|
||||
* This is needed if you have multiple threads running at the same time. It
|
||||
* doesn't affect the execution-time of the thread, it just makes it possible
|
||||
* for the other threads to get their chance to shine.
|
||||
*/
|
||||
static void sleep();
|
||||
|
||||
/**
|
||||
* @brief Sleeps for the given time
|
||||
* @param t_milliseconds The time to sleep in milliseconds
|
||||
*/
|
||||
static void sleep(int t_milliseconds);
|
||||
|
||||
private:
|
||||
struct ThreadData {
|
||||
Palladium::Parameter m_parameter;
|
||||
std::function<void(Palladium::Parameter)> m_function;
|
||||
std::atomic<bool> *m_running;
|
||||
};
|
||||
|
||||
static void threadFunction(void *t_arg);
|
||||
/* data */
|
||||
int m_priority, m_stackSize;
|
||||
bool m_started;
|
||||
std::atomic<bool> m_running;
|
||||
Palladium::Thread::ThreadData m_data;
|
||||
CTRU_Thread m_thread;
|
||||
};
|
||||
} // namespace Palladium
|
103
include/pd/tools/markdown.hpp
Normal file
103
include/pd/tools/markdown.hpp
Normal file
@ -0,0 +1,103 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
class Markdown {
|
||||
public:
|
||||
Markdown() = default;
|
||||
~Markdown() = default;
|
||||
|
||||
void Header(const std::string& hdr, int lvl = 2) {
|
||||
if (task != 0 || lvl < 1 || lvl > 10) {
|
||||
return;
|
||||
}
|
||||
/// Directly create the string with its amount of #
|
||||
std::string str(lvl, '#');
|
||||
str += " ";
|
||||
str += hdr;
|
||||
s << str << std::endl << std::endl;
|
||||
}
|
||||
|
||||
void BeginTable(const std::vector<std::string>& head) {
|
||||
if (task != 0) {
|
||||
return;
|
||||
}
|
||||
ctc = head.size();
|
||||
for (auto& it : head) {
|
||||
s << "| " << it << " ";
|
||||
}
|
||||
s << "|\n";
|
||||
for (int i = 0; i < ctc; i++) {
|
||||
s << "|---";
|
||||
}
|
||||
s << "|\n";
|
||||
task = 1;
|
||||
}
|
||||
|
||||
Markdown& TableAddEntry(const std::string& e) {
|
||||
if (task != 1) {
|
||||
return *this;
|
||||
}
|
||||
ctci++;
|
||||
s << "| " << e << " ";
|
||||
if (ctci == ctc) {
|
||||
s << "|\n";
|
||||
ctci = 0;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void EndTable() {
|
||||
if (task != 1) {
|
||||
return;
|
||||
}
|
||||
s << std::endl;
|
||||
task = 0;
|
||||
}
|
||||
|
||||
void Write(const std::string& path) {
|
||||
std::ofstream f(path);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
f << s.str();
|
||||
f.close();
|
||||
}
|
||||
|
||||
private:
|
||||
/// @brief Tasks
|
||||
/// 0 = free
|
||||
/// 1 = table
|
||||
/// 2 = text
|
||||
int task = 0;
|
||||
/// @brief Current Table Columns
|
||||
int ctc = 0;
|
||||
/// @brief Current Table Column Index
|
||||
int ctci = 0;
|
||||
std::stringstream s;
|
||||
};
|
||||
} // namespace PD
|
37
include/pd/tools/result_decoder.hpp
Normal file
37
include/pd/tools/result_decoder.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <3ds.h>
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/tools/markdown.hpp>
|
||||
|
||||
namespace PD {
|
||||
class ResultDecoder {
|
||||
public:
|
||||
ResultDecoder(Result res);
|
||||
|
||||
};
|
||||
} // namespace PD
|
53
include/pd/ui7/drawlist.hpp
Normal file
53
include/pd/ui7/drawlist.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
#include <pd/graphics/lithium.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
class UI7DrawList : SmartCtor<UI7DrawList> {
|
||||
public:
|
||||
UI7DrawList(LI::Renderer::Ref r) { ren = r; }
|
||||
~UI7DrawList() = default;
|
||||
|
||||
void AddRectangle(vec2 pos, vec2 szs, const UI7Color& clr);
|
||||
void AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2, const UI7Color& clr);
|
||||
void AddText(vec2 pos, const std::string& text, const UI7Color& clr,
|
||||
LITextFlags flags = 0, vec2 box = vec2());
|
||||
void AddImage(vec2 pos, Texture::Ref img);
|
||||
|
||||
void Clear();
|
||||
void Process();
|
||||
|
||||
int Layer() const { return layer; }
|
||||
void Layer(int v) { layer = v; }
|
||||
|
||||
private:
|
||||
int layer;
|
||||
LI::Renderer::Ref ren;
|
||||
std::vector<LI::Command::Ref> commands;
|
||||
};
|
||||
} // namespace PD
|
35
include/pd/ui7/flags.hpp
Normal file
35
include/pd/ui7/flags.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
using UI7MenuFlags = unsigned int;
|
||||
|
||||
enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_None = 0,
|
||||
UI7MenuFlags_NoTitlebar = 1 << 0,
|
||||
UI7MenuFlags_CenterTitle = 1 << 1,
|
||||
UI7MenuFlags_HzScrolling = 1 << 2,
|
||||
UI7MenuFlags_VtScrolling = 1 << 3,
|
||||
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
|
||||
};
|
52
include/pd/ui7/theme.hpp
Normal file
52
include/pd/ui7/theme.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/common/common.hpp>
|
||||
|
||||
using UI7Color = unsigned int;
|
||||
|
||||
enum UI7Color_ {
|
||||
UI7Color_Background,
|
||||
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
/// Using UI7Color as a Class to be able to
|
||||
/// define it as struct as well as using it as enum
|
||||
class UI7Color {
|
||||
public:
|
||||
UI7Color() {
|
||||
/// No Color
|
||||
}
|
||||
UI7Color(unsigned int c) { color = c; }
|
||||
UI7Color(UI7Color_ c) {}
|
||||
~UI7Color() {}
|
||||
|
||||
operator u32() const { return color; }
|
||||
|
||||
private:
|
||||
u32 color;
|
||||
};
|
||||
} // namespace PD
|
53
include/pd/ui7/ui7.hpp
Normal file
53
include/pd/ui7/ui7.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/ui7/drawlist.hpp>
|
||||
#include <pd/ui7/flags.hpp>
|
||||
#include <pd/ui7/theme.hpp>
|
||||
|
||||
namespace PD {
|
||||
class UI7Context : SmartCtor<UI7Context> {
|
||||
public:
|
||||
UI7Context() {}
|
||||
~UI7Context() {}
|
||||
|
||||
private:
|
||||
// Timing
|
||||
float delta;
|
||||
float time;
|
||||
float last;
|
||||
// Context
|
||||
bool in_menu;
|
||||
// Debug
|
||||
bool debug;
|
||||
// Menu Handlers
|
||||
|
||||
// Context DrawList
|
||||
UI7DrawList::Ref debug;
|
||||
UI7DrawList::Ref front;
|
||||
UI7DrawList::Ref back;
|
||||
// Promt Handler
|
||||
};
|
||||
} // namespace PD
|
Reference in New Issue
Block a user