- Start Restructuring Project
- Add Makefile for Testbuilds
- Optimize Lithium as much as possible
- Remove Render2 to get wasted time
- Optimize UI7 for LRS
This commit is contained in:
2024-08-30 14:54:49 +02:00
parent a58dc20562
commit 224daffaf7
54 changed files with 3723 additions and 3107 deletions

View File

@ -1,25 +1,26 @@
#pragma once
#include <pd/Allocator.hpp>
#include <pd/base/Allocator.hpp>
#include <pd/Error.hpp>
#include <pd/FileSystem.hpp>
#include <pd/base/FileSystem.hpp>
#include <pd/Hid.hpp>
#include <pd/Image.hpp>
#include <pd/Installer.hpp>
#include <pd/LI7.hpp>
#include <pd/Lithium.hpp>
#include <pd/Message.hpp>
#include <pd/Net.hpp>
#include <pd/Overlays.hpp>
#include <pd/Rubidium.hpp>
#include <pd/Sound.hpp>
#include <pd/Texture.hpp>
#include <pd/Sheet.hpp>
#include <pd/Timer.hpp>
#include <pd/UI7.hpp>
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
namespace Palladium {
using Render2 = R2;
using Lithium = LI;
using RB = Rubidium;
} // namespace Palladium

View File

@ -1,36 +0,0 @@
#pragma once
#include <citro2d.h>
#include <fstream>
#include <memory>
#include <pd/Error.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
class Font {
public:
Font() = default;
Font(const std::string& path) { Load(path); };
~Font() { Unload(); }
PD_SMART_CTOR(Font)
void Load(const std::string& path) {
std::ifstream ft(path, std::ios::in | std::ios::binary);
bool io = ft.is_open();
ft.close();
Palladium::InlineAssert(io, "File not Found!");
fnt = C2D_FontLoad(path.c_str());
Palladium::InlineAssert(fnt, "Font could not be loaded!");
}
C2D_Font Ptr() { return fnt; }
void Unload() {
if (!fnt) return;
C2D_FontFree(fnt);
fnt = nullptr;
}
private:
C2D_Font fnt = nullptr;
};
} // namespace Palladium

View File

@ -5,7 +5,7 @@
#pragma once
#include <pd/NVec.hpp>
#include <pd/maths/NVec.hpp>
#include <string>
namespace Palladium {

View File

@ -2,7 +2,7 @@
#include <3ds.h>
#include <pd/NVec.hpp>
#include <pd/maths/NVec.hpp>
#include <pd/Texture.hpp>
#include <pd/nimg.hpp>
#include <pd/smart_ctor.hpp>
@ -23,7 +23,7 @@ class Image {
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();
return (custom_uvs.x() != -1) ? custom_uvs : img->GetUV();
}
bool Loadet();

View File

@ -1,166 +0,0 @@
#pragma once
#include <citro3d.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <pd/Allocator.hpp>
#include <pd/NVec.hpp>
#include <pd/Texture.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),
};
namespace Palladium {
class LIFont {
public:
struct CPI {
unsigned char codepoint;
NVec4 uv;
Texture::Ref tex;
NVec2 szs;
float off;
};
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(char c);
std::string GetName() { return name; };
void Dump();
private:
std::string name;
int pixel_height;
std::vector<CPI> cpmap;
std::vector<Texture::Ref> tex;
};
class LI7 {
public:
struct Vtx {
Vtx() {}
Vtx(NVec2 xy, float u, float v, unsigned int clr) {
// Coords
xyz[0] = xy.x;
xyz[1] = xy.y;
xyz[2] = 0.5f; // Always 0
// UV
uv[0] = u;
uv[1] = v;
col = clr;
}
float xyz[3];
float uv[2];
unsigned int col;
};
/// CMD TYPES ///
/// 0 = SKIP
/// 1 = TRIANGLE
/// 2 = RECT
/// 3 = RECT2P (2 Positions instead of pos,szs)
/////////////////
struct Cmd {
NVec2 ppos;
NVec2 pszs;
NVec2 apos;
NVec4 top;
NVec4 bot;
NVec4 uv;
int layer = 0;
int cmd_type = 0;
unsigned int clr = 0;
Texture::Ref tex = nullptr;
};
LI7() = default;
~LI7() = default;
static void Init();
static void Exit();
static void OnScreen(bool bottom);
static void Render(C3D_RenderTarget* top, C3D_RenderTarget* bot);
static void Scale(float i) { m_scale = i; }
static float Scale() { return m_scale; }
static void BindTexture(Texture::Ref tex);
static NVec2 ScreenSize() { return NVec2(m_width, m_height); }
static LIFont::Ref GetFont() { return m_font; }
static void ColorRect(NVec2 pos, NVec2 szs, NVec4 uvs, unsigned int clr);
static void Rect(NVec2 pos, NVec2 szs, NVec4 uvs);
static void ColorRect(NVec2 pos, NVec2 szs, unsigned int clr);
static void Rect(NVec2 pos, NVec2 szs);
static void TexCutRect(NVec2 pos, NVec2 szs, NVec2 cb, NVec2 ce);
static void Line(NVec2 a, NVec2 b, unsigned int clr, int t = 1);
static void Triangle(NVec2 a, NVec2 b, NVec2 c, unsigned int clr);
static void UseTexture(Texture::Ref tex = nullptr) {
m_current_texture = tex ? tex : m_white;
}
static NVec2 GetTextDimensions(const std::string& text);
static void DrawText(NVec2 pos, unsigned int color, const std::string& text,
PDTextFlags flags = 0, NVec2 ap = NVec2());
static float GetTextScale() { return m_txt_scale; }
static void SetTextScale(float scale) { m_txt_scale = scale; }
static void DefaultTextScale() { m_txt_scale = m_dts; }
static int Vertices() { return m_d_vertices; }
static int Drawcalls() { return m_d_drawcalls; }
static int DarwCommands() { return m_d_commands; }
private:
static bool CompareCommands(const Cmd& a, const Cmd& b);
static void RenderFrame(bool bottom);
// Default Font Size in (px)
static const float m_dffs;
static const float m_dts;
static float m_txt_scale;
static int m_uLoc_proj;
static float m_scale;
static int m_width, m_height;
static int m_d_vertices;
static int m_d_drawcalls;
static int m_d_commands;
static const int m_char_height; // Constant
// UI Stuff
static std::vector<Cmd> m_top_draw_cmds;
static std::vector<Cmd> m_bot_draw_cmds;
static Texture::Ref m_current_texture;
static Texture::Ref m_white;
static std::vector<Vtx, LinearAllocator<Vtx>> m_vtx_list[2];
// static Font* m_font;
static LIFont::Ref m_font;
static std::vector<char> m_text_buffer;
// Ctx Stuff
static bool m_bottom_active;
// Shader
static DVLB_s* li7_dvlb;
static shaderProgram_s li7_prog;
static C3D_AttrInfo li7_attr;
};
} // namespace Palladium

236
include/pd/Lithium.hpp Normal file
View File

@ -0,0 +1,236 @@
#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_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;
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

View File

@ -1,35 +0,0 @@
#pragma once
#include <fstream>
#include <pd/smart_ctor.hpp>
#include <string>
#include <vector>
namespace Palladium {
/// @brief Logger base Class
class LoggerBase {
public:
/// @brief Constructor
LoggerBase() = default;
/// @brief Deconstructor
~LoggerBase();
PD_SMART_CTOR(LoggerBase)
/// @brief Init the Logger
/// @param filename name[_date_time.txt]
void Init(const std::string& name, bool fileless = false);
/// @brief Write a String
/// @param debug_text string
/// @param lvl Logger LVL 0 = ERR, 1 =WARNING, >=2= Default
void Write(const std::string& debug_text, int lvl = 2);
void SetLvl(int lvl) { writelvl = lvl; }
const std::vector<std::string>& Lines();
private:
/// \param filename the name of the logfile
std::string filename;
std::string log_path;
std::ofstream _log;
int writelvl = 1; // Only log errors/Warnings
std::vector<std::string> lines;
};
} // namespace Palladium

View File

@ -7,12 +7,12 @@ struct Message {
Message(std::string t, std::string m) {
title = t;
message = m;
animationframe = 0;
animtime = 0.f;
}
std::string title;
std::string message;
int animationframe;
float animtime;
};
void ProcessMessages();

View File

@ -1,105 +0,0 @@
#pragma once
struct NVec2 {
// Init Funcs
NVec2() : x(0), y(0) {}
NVec2(float i0, float i1) : x(i0), y(i1) {}
NVec2(const NVec2 &i) {
x = i.x;
y = i.y;
}
// Operators
// Add
NVec2 &operator+=(const NVec2 &i) {
x += i.x;
y += i.y;
return *this;
}
NVec2 operator+(const NVec2 &i) const { return NVec2(x + i.x, y + i.y); }
// Sub
NVec2 &operator-=(const NVec2 &i) {
x -= i.x;
y -= i.y;
return *this;
}
NVec2 operator-(const NVec2 &i) const { return NVec2(x - i.x, y - i.y); }
// Compare
bool operator==(const NVec2 &in) const { return x == in.x && y == in.y; }
bool operator!=(const NVec2 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Internal Values
float x;
float y;
};
struct NVec4 {
// Init Funcs
NVec4() : x(0), y(0), z(0), w(0) {}
NVec4(float i0, float i1, float i2, float i3) : x(i0), y(i1), z(i2), w(i3) {}
NVec4(const NVec4 &i) {
x = i.x;
y = i.y;
z = i.z;
w = i.w;
}
NVec4(const NVec2 &i0, const NVec2 &i1) {
x = i0.x;
y = i0.y;
z = i1.x;
w = i1.y;
}
// Operators
// Add
NVec4 &operator+=(const NVec4 &i) {
x += i.x;
y += i.y;
z += i.z;
w += i.w;
return *this;
}
NVec4 operator+(const NVec4 &i) const {
return NVec4(x + i.x, y + i.y, z + i.z, w + i.w);
}
// Sub
NVec4 &operator-=(const NVec4 &i) {
x -= i.x;
y -= i.y;
z -= i.z;
w -= i.w;
return *this;
}
NVec4 operator-(const NVec4 &i) const {
return NVec4(x - i.x, y - i.y, z - i.z, w - i.w);
}
// Compare
bool operator==(const NVec4 &in) const {
return x == in.x && y == in.y && z == in.z && w == in.w;
}
bool operator!=(const NVec4 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Internal Values
float x;
float y;
float z;
float w;
};

View File

@ -1,6 +1,9 @@
#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;
@ -17,6 +20,16 @@ enum PDKeyboardState {
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:
@ -34,8 +47,8 @@ class Ovl_Ftrace : public Palladium::Ovl {
class Ovl_Metrik : public Palladium::Ovl {
public:
/// @brief Constructor
Ovl_Metrik(bool* is_enabled, bool* screen, uint32_t* mt_color,
uint32_t* txt_color, float* txt_size);
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
@ -49,6 +62,7 @@ class Ovl_Metrik : public Palladium::Ovl {
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;
@ -56,9 +70,12 @@ class Ovl_Metrik : public Palladium::Ovl {
// Importand Adresses
bool* i_is_enabled;
bool* i_screen;
uint32_t* i_mt_color;
uint32_t* i_txt_color;
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 {
@ -66,7 +83,8 @@ class Ovl_Keyboard : public Palladium::Ovl {
/// @brief Constructor
/// Keyboard Type not Supported for now
Ovl_Keyboard(std::string& ref, PDKeyboardState& state,
const std::string& hint = "", PDKeyboard type = 0);
const std::string& hint = "", PDKeyboard type = 0,
PDKeyboardFlags flags = PDKeyboardFlags_Default);
/// @brief Deconstructor
~Ovl_Keyboard();
/// @brief Override for Draw
@ -83,5 +101,6 @@ class Ovl_Keyboard : public Palladium::Ovl {
PDKeyboard type;
int mode = 0;
int ft3 = 0;
PDKeyboardFlags flags;
};
} // namespace Palladium

View File

@ -1,83 +0,0 @@
#pragma once
#include <map>
#include <pd/Color.hpp>
#include <pd/Font.hpp>
#include <pd/Image.hpp>
#include <pd/LI7.hpp>
#include <pd/NVec.hpp>
#include <pd/Sprite.hpp>
#include <pd/smart_ctor.hpp>
enum R2Screen {
R2Screen_Bottom,
R2Screen_Top,
// TopRight,
};
namespace Palladium {
class R2 {
public:
struct R2Cmd {
NVec2 pos; //< Position
NVec2 pszs; //< Position or (TextBox) Size
NVec2 ap; //< Additional Pos
unsigned int clr; //< Color
bool Screen; //< TopScreen
Image::Ref img; //< Image Reference
Sprite::Ref spr; //< Sprite Reference
// 0 = skip, 1 = rect, 2 = tri, 3 = text,
// 4 = image, 5 = sprite, 6 = Line
int type; //< Command Type
bool lined = false; //< Draw Lined Rect/Tri
// Text Specific
PDTextFlags flags; // Text Flags
std::string text; // Text
PD_SMART_CTOR(R2Cmd)
};
R2() = default;
~R2() = default;
static void Init();
// Settings
static void SetFont(Font::Ref fnt);
static Font::Ref GetFont();
static void DefaultFont();
static void DrawNextLined();
static void OnScreen(R2Screen screen);
static R2Screen GetCurrentScreen();
static void SetTextSize(float szs);
static void DefaultTextSize();
static float GetTextSize();
static NVec2 GetCurrentScreenSize();
// Processing
static void Process();
static NVec2 GetTextDimensions(const std::string& text);
static std::string WrapText(const std ::string& in, int maxlen);
static std::string ShortText(const std::string& in, int maxlen);
// Draw Functions
static void AddRect(NVec2 pos, NVec2 size, PDColor clr);
static void AddRect(NVec2 pos, NVec2 size, unsigned int clr);
static void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, PDColor clr);
static void AddTriangle(NVec2 pos0, NVec2 pos1, NVec2 pos2, unsigned int clr);
static void AddText(NVec2 pos, const std::string& text, PDColor clr,
PDTextFlags flags = 0, NVec2 tmb = NVec2());
static void AddText(NVec2 pos, const std::string& text, unsigned int clr,
PDTextFlags flags = 0, NVec2 tmb = NVec2());
static void AddImage(NVec2 pos, Image::Ref img);
static void AddSprite(Sprite::Ref spr);
static void AddLine(NVec2 pos_a, NVec2 pos_b, PDColor clr, int t = 1);
static void AddLine(NVec2 pos_a, NVec2 pos_b, unsigned int clr, int t = 1);
private:
static const float default_text_size;
static float text_size;
static Font::Ref font;
static std::map<std::string, float> ts;
static std::map<std::string, int> mln;
static bool next_lined;
static std::vector<R2Cmd::Ref> commands;
static R2Screen current_screen;
};
} // namespace Palladium

View File

@ -1,35 +1,24 @@
#pragma once
#include <3ds.h> // Result
#include <citro2d.h>
#include <citro3d.h>
#include <pd/Image.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
#include <pd/Texture.hpp>
#include <pd/Image.hpp>
namespace Palladium {
/// @brief SpriteSheet Class
class Sheet {
public:
/// @brief Constructor
Sheet() = default;
Sheet(const std::string& path) { this->Load(path); }
/// @brief Deconstructor
~Sheet() {
if (spritesheet) Free();
}
PD_SMART_CTOR(Sheet);
/// @brief Load A Spritesheet File
/// @param path Path to the t3x
/// @return Result Code
Result Load(const std::string& path);
/// @brief Unload the Sheet
void Free();
C2D_Image GetImage(int idx);
C2D_SpriteSheet Get() { return this->spritesheet; }
#include <tex3ds.h>
private:
/// \param spritesheet The Sheet
C2D_SpriteSheet spritesheet;
};
} // namespace Palladium
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

View File

@ -1,10 +1,8 @@
#pragma once
#include <citro2d.h>
#include <citro3d.h>
#include <pd/Image.hpp>
#include <pd/Sheet.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
@ -17,10 +15,6 @@ class Sprite {
~Sprite() = default;
PD_SMART_CTOR(Sprite)
/// \brief Load a Sprite From SpriteSheet
/// \param sheet the Sheet to load from.(Palladium::Sheet)
/// \param index the number of the Sprite in the Sheet
void FromSheet(Palladium::Sheet::Ref sheet, size_t index);
/// \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
@ -63,9 +57,7 @@ class Sprite {
void SetRotCenter(NVec2 percentage);
private:
/// @param tint ImageTint (unused)
C2D_ImageTint tint;
/// @param sprite The Sprite
C2D_Sprite sprite;
///// @param sprite The Sprite
//C2D_Sprite sprite;
};
} // namespace Palladium

View File

@ -1,43 +0,0 @@
#pragma once
#include <citro2d.h>
#include <citro3d.h>
#include <pd/Sheet.hpp>
#include <pd/Sprite.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
/// @brief SpriteSheetAnimation Class
class SpriteSheetAnimation : public Palladium::Sprite {
public:
/// @brief Constructor
SpriteSheetAnimation() = default;
/// @brief Deconstructor
~SpriteSheetAnimation() = default;
PD_SMART_CTOR(SpriteSheetAnimation);
/// @brief Setup an Animation
/// @param sheet Input Spritesheet
/// @param imagecount Count of Images
/// @param startimage Where to Start the Loop
/// @param frame_begin Current Time (Should be 0)
/// @param frame_finish Time Length
void Setup(Palladium::Sheet::Ref sheet, size_t imagecount, size_t startimage,
float frame_begin, float frame_finish);
/// @brief Play the Animation
/// @param timespeed Speed of the animation
void Play(float timespeed);
private:
/// @param images Count of Images
size_t images;
/// @param imgs Another Count of images ???
size_t imgs = 0;
/// @param D_totaltime Current Time
float D_totaltime;
/// @param sheet The Sheet of Images
Palladium::Sheet::Ref sheet;
/// @param time Total Time from frame_finish
float time;
};
} // namespace Palladium

View File

@ -1,7 +1,7 @@
#pragma once
#include <citro3d.h>
#include <pd/NVec.hpp>
#include <pd/maths/NVec.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
#include <vector>
@ -19,10 +19,10 @@ class Texture {
};
Texture() {
// Set Default UV
this->uvs.x = 0.0f;
this->uvs.y = 1.0f;
this->uvs.z = 1.0f;
this->uvs.w = 0.0f;
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)

View File

@ -1,13 +1,14 @@
#pragma once
#include <pd/Image.hpp>
#include <pd/NVec.hpp>
#include <pd/Render2.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)
typedef int UI7MenuFlags;
using UI7MenuFlags = unsigned int;
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0,
@ -16,6 +17,18 @@ enum UI7MenuFlags_ {
UI7MenuFlags_Scrolling = MAKEFLAG(2),
};
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:
@ -35,10 +48,16 @@ class UI7DrawList {
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;
};
@ -77,10 +96,16 @@ void Grid(const std::string &name, const NVec2 &size, const NVec2 &entry_size,
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);

View File

@ -1,204 +1,204 @@
#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
#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

View File

@ -1,24 +1,24 @@
#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
#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

View File

@ -1,76 +1,137 @@
#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 {
/// @brief Result of FTrace
struct FTRes {
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)
float time_ofm; ///< max time off
bool is_ovl; ///< is displayed in overlay?
};
/// @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();
if (trace.time_of > trace.time_ofm) trace.time_ofm = trace.time_of;
trace.time_of =
static_cast<float>(trace.time_end - trace.time_start) / TICKS_PER_MSEC;
}
/// @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
#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

View File

@ -1,24 +1,24 @@
#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
#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

View File

@ -1,26 +1,26 @@
#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
#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

View File

@ -1,103 +1,98 @@
#pragma once
#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::ostringstream oss;
if (t_time < 0.001f) {
oss << std::fixed << std::setprecision(2) << t_time * 1000.0f << "ns";
} else if (t_time < 1.0f) {
oss << std::fixed << std::setprecision(2) << t_time << "ms";
} else if (t_time < 60000.0f) {
int seconds = static_cast<int>(t_time / 1000.0f);
float milliseconds = t_time - (seconds * 1000.0f);
if (seconds > 0) {
oss << seconds << "s ";
}
if (!dems)
oss << std::fixed << std::setprecision(2) << milliseconds << "ms";
} 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);
oss << minutes << "m ";
if (seconds > 0 || milliseconds > 0.0f) {
oss << seconds << "s ";
}
if (milliseconds > 0.0f && !dems) {
oss << std::fixed << std::setprecision(2) << milliseconds << "ms";
}
}
return oss.str();
}
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();
#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();
}

View File

@ -11,7 +11,7 @@ void Restart();
} // namespace IDB
} // namespace Palladium
using PDFlags = int;
using PDFlags = unsigned int;
enum PDFlags_ {
PDFlags_None = 0,
PDFlags_MemTrack = 1 << 0,
@ -19,6 +19,47 @@ enum PDFlags_ {
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;
@ -27,11 +68,11 @@ extern u32 d7_hRepeat; // Inofficial lol
extern touchPosition d7_touch;
// Modern Global Api
extern int pd_max_objects;
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;

View File

@ -4,7 +4,7 @@
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
#define CFGVER "1"
#define CFGVER "2"
#define THEMEVER "0"
#ifndef V_PDBTIME
@ -26,9 +26,6 @@ extern u8 pdi_system_region;
extern bool pdi_is_citra;
extern bool pdi_settings;
extern NVec2 pdi_hid_touch_pos;
extern C2D_TextBuf pdi_text_buffer;
extern C2D_TextBuf pdi_d2_dimbuf;
extern C2D_Font pdi_base_font;
extern bool pdi_is_ndsp;
extern bool pdi_running;
extern std::unique_ptr<Palladium::Scene> pdi_fade_scene;
@ -36,8 +33,8 @@ 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 u32 pdi_mt_color;
extern u32 pdi_mt_txtcolor;
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;
@ -63,7 +60,5 @@ extern bool pdi_is_am_init;
extern Palladium::Theme::Ref pdi_active_theme;
extern bool pdi_lggrf;
// Use function for protection
Palladium::LoggerBase::Ref _pdi_logger();
Palladium::Net::Error pdi_soc_init();
void pdi_soc_deinit();

45
include/pd/maths/NMat.hpp Normal file
View File

@ -0,0 +1,45 @@
#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];
};
};

366
include/pd/maths/NVec.hpp Normal file
View File

@ -0,0 +1,366 @@
#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];
};

View File

@ -13,26 +13,21 @@
#include <unistd.h>
/// 3ds Includes
#include <3ds.h>
#include <citro2d.h>
#include <citro3d.h>
/// Palladium Includes
#include <pd/Color.hpp>
#include <pd/FunctionTrace.hpp>
#include <pd/base/Color.hpp>
#include <pd/base/FunctionTrace.hpp>
#include <pd/Hardware.hpp>
#include <pd/Logger.hpp>
#include <pd/Memory.hpp>
#include <pd/base/Memory.hpp>
#include <pd/Overlays.hpp>
#include <pd/Ovl.hpp>
#include <pd/Render2.hpp>
#include <pd/ResultDecoder.hpp>
#include <pd/Sheet.hpp>
#include <pd/Sprite.hpp>
#include <pd/SpriteAnimation.hpp>
#include <pd/Tasks.hpp>
#include <pd/Time.hpp>
#include <pd/lang.hpp>
#include <pd/base/Lang.hpp>
#include <pd/parameter.hpp>
#include <pd/stringtool.hpp>
#include <pd/base/stringtool.hpp>
#include <pd/thread.hpp>
#define PDVSTRING "1.0.0"
@ -43,8 +38,6 @@
extern int pd_max_objects;
namespace Palladium {
// Reference to Global Logger
LoggerBase::Ref Logger();
/// @brief Get Deltatime
/// @return Deltatime
float GetDeltaTime();