Initial Commit
This commit is contained in:
40
include/pd/Allocator.hpp
Normal file
40
include/pd/Allocator.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
#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
|
204
include/pd/Color.hpp
Normal file
204
include/pd/Color.hpp
Normal file
@ -0,0 +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
|
18
include/pd/Error.hpp
Normal file
18
include/pd/Error.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#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
|
24
include/pd/FileSystem.hpp
Normal file
24
include/pd/FileSystem.hpp
Normal file
@ -0,0 +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
|
||||
} // namespace Palladium
|
36
include/pd/Font.hpp
Normal file
36
include/pd/Font.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#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
|
76
include/pd/FunctionTrace.hpp
Normal file
76
include/pd/FunctionTrace.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
#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
|
26
include/pd/Hardware.hpp
Normal file
26
include/pd/Hardware.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#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
|
42
include/pd/Hid.hpp
Normal file
42
include/pd/Hid.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
// WARNING
|
||||
// THIS IS BETA STUFF
|
||||
// ITS MAKE LIKE EXTERNAL BUT
|
||||
// FOR Palladium ITS INTEGRATED
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pd/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
|
33
include/pd/Image.hpp
Normal file
33
include/pd/Image.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <3ds.h>
|
||||
#include <citro2d.h>
|
||||
|
||||
#include <pd/NVec.hpp>
|
||||
#include <pd/nimg.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
class Image {
|
||||
public:
|
||||
Image() = default;
|
||||
Image(C2D_Image img) { this->img = img; }
|
||||
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();
|
||||
|
||||
C2D_Image Get();
|
||||
C2D_Image& GetRef();
|
||||
void Set(const C2D_Image& i);
|
||||
NVec2 GetSize();
|
||||
bool Loadet();
|
||||
|
||||
private:
|
||||
bool ext = false;
|
||||
C2D_Image img;
|
||||
};
|
||||
} // namespace Palladium
|
16
include/pd/Installer.hpp
Normal file
16
include/pd/Installer.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <3ds.h> // Result
|
||||
|
||||
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
|
125
include/pd/LI7.hpp
Normal file
125
include/pd/LI7.hpp
Normal file
@ -0,0 +1,125 @@
|
||||
#include <pd/NVec.hpp>
|
||||
#include <pd/Allocator.hpp>
|
||||
#include <pd/Texture.hpp>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Palladium {
|
||||
class LIFont {
|
||||
public:
|
||||
struct CPI {
|
||||
unsigned char codepoint;
|
||||
NVec4 uv;
|
||||
Texture::Ref tex;
|
||||
};
|
||||
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();
|
||||
|
||||
private:
|
||||
int pixel_height;
|
||||
unsigned char fontw[256];
|
||||
int charsize;
|
||||
std::vector<Texture::Ref> tex;
|
||||
};
|
||||
class LI7 {
|
||||
public:
|
||||
struct Vtx
|
||||
{
|
||||
float xyz[3];
|
||||
float uv[2];
|
||||
unsigned int col;
|
||||
};
|
||||
/// CMD TYPES ///
|
||||
/// 0 = SKIP
|
||||
/// 1 = TRIANGLE
|
||||
/// 2 = RECT
|
||||
/////////////////
|
||||
struct Cmd {
|
||||
NVec2 ppos;
|
||||
NVec2 pszs;
|
||||
NVec2 apos;
|
||||
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 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 int DrawText(int x, int y, int z, unsigned int color, bool shadow,
|
||||
int wrap, int* ySize, const char* fmt, ...);
|
||||
|
||||
static int Vertices() { return m_d_vertices; }
|
||||
static int Drawcalls() { return m_d_drawcalls; }
|
||||
static int DarwCommandss() { return m_d_commands; }
|
||||
private:
|
||||
static bool CompareCommands(const Cmd& a,
|
||||
const Cmd& b);
|
||||
static void RenderFrame(bool bottom);
|
||||
static int DrawTextVargs(int x, int y, int z, unsigned int color, bool shadow,
|
||||
int wrap, int* ySize, const char* fmt, va_list arg);
|
||||
|
||||
// Default Font Size in (px)
|
||||
static const float m_dffs;
|
||||
|
||||
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
|
||||
static float m_rot;
|
||||
|
||||
// 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 std::vector<Vtx, LinearAllocator<Vtx>> m_vtx_list[2];
|
||||
//static Font* m_font;
|
||||
static std::vector<char> m_text_buffer;
|
||||
|
||||
// Matrix
|
||||
static C3D_Mtx m_icon_model_matrix;
|
||||
|
||||
// Ctx Stuff
|
||||
static bool m_bottom_active;
|
||||
|
||||
// Shader
|
||||
static DVLB_s *li7_dvlb;
|
||||
static shaderProgram_s li7_shader;
|
||||
static C3D_AttrInfo li7_attr;
|
||||
};
|
||||
}
|
35
include/pd/Logger.hpp
Normal file
35
include/pd/Logger.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#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
|
24
include/pd/Memory.hpp
Normal file
24
include/pd/Memory.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
#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
|
27
include/pd/Message.hpp
Normal file
27
include/pd/Message.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Palladium {
|
||||
struct Message {
|
||||
Message(std::string t, std::string m) {
|
||||
title = t;
|
||||
message = m;
|
||||
animationframe = 0;
|
||||
}
|
||||
|
||||
std::string title;
|
||||
std::string message;
|
||||
int animationframe;
|
||||
};
|
||||
|
||||
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
|
104
include/pd/NVec.hpp
Normal file
104
include/pd/NVec.hpp
Normal file
@ -0,0 +1,104 @@
|
||||
#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;
|
||||
};
|
42
include/pd/Net.hpp
Normal file
42
include/pd/Net.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
#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
|
85
include/pd/Overlays.hpp
Normal file
85
include/pd/Overlays.hpp
Normal file
@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/Ovl.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,
|
||||
};
|
||||
|
||||
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, uint32_t* mt_color,
|
||||
uint32_t* 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_tbs;
|
||||
mutable std::string mt_mem;
|
||||
|
||||
// Importand Adresses
|
||||
bool* i_is_enabled;
|
||||
bool* i_screen;
|
||||
uint32_t* i_mt_color;
|
||||
uint32_t* i_txt_color;
|
||||
float* i_txt_size;
|
||||
};
|
||||
|
||||
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);
|
||||
/// @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;
|
||||
};
|
||||
} // namespace Palladium
|
28
include/pd/Ovl.hpp
Normal file
28
include/pd/Ovl.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#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
|
97
include/pd/Render2.hpp
Normal file
97
include/pd/Render2.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <pd/Color.hpp>
|
||||
#include <pd/Font.hpp>
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/NVec.hpp>
|
||||
#include <pd/Sprite.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
#define MAKEFLAG(x) (1 << x)
|
||||
|
||||
typedef unsigned int PDTextFlags;
|
||||
|
||||
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),
|
||||
};
|
||||
|
||||
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
|
54
include/pd/ResultDecoder.hpp
Normal file
54
include/pd/ResultDecoder.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#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
|
35
include/pd/Sheet.hpp
Normal file
35
include/pd/Sheet.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include <3ds.h> // Result
|
||||
#include <citro2d.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <string>
|
||||
|
||||
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; }
|
||||
|
||||
private:
|
||||
/// \param spritesheet The Sheet
|
||||
C2D_SpriteSheet spritesheet;
|
||||
};
|
||||
} // namespace Palladium
|
35
include/pd/Sound.hpp
Normal file
35
include/pd/Sound.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#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
|
71
include/pd/Sprite.hpp
Normal file
71
include/pd/Sprite.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <citro2d.h>
|
||||
#include <citro3d.h>
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/Sheet.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 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
|
||||
/// @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 tint ImageTint (unused)
|
||||
C2D_ImageTint tint;
|
||||
/// @param sprite The Sprite
|
||||
C2D_Sprite sprite;
|
||||
};
|
||||
} // namespace Palladium
|
43
include/pd/SpriteAnimation.hpp
Normal file
43
include/pd/SpriteAnimation.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
#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
|
13
include/pd/Tasks.hpp
Normal file
13
include/pd/Tasks.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#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
|
35
include/pd/Texture.hpp
Normal file
35
include/pd/Texture.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <pd/smart_ctor.hpp>
|
||||
#include <pd/NVec.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <citro3d.h>
|
||||
|
||||
namespace Palladium {
|
||||
class Texture {
|
||||
public:
|
||||
Texture() = default;
|
||||
~Texture() = default;
|
||||
PD_SMART_CTOR(Texture)
|
||||
|
||||
void Delete();
|
||||
|
||||
void LoadFile(const std::string& path);
|
||||
void LoadFromMemory(const std::vector<unsigned char>& data);
|
||||
void LoadPixels(const std::vector<unsigned char>& data, int w, int h);
|
||||
|
||||
C3D_Tex* Get() { return this->tex; }
|
||||
NVec2 GetTexSize() { return tex_size; }
|
||||
NVec2 GetSize() { return img_size; }
|
||||
// As the texture is a pow of 2 we need a uv
|
||||
NVec4 GetUV() { return uvs; }
|
||||
|
||||
private:
|
||||
void MakeTex(std::vector<unsigned char> &buf, int w, int h);
|
||||
C3D_Tex* tex;
|
||||
NVec2 img_size;
|
||||
NVec2 tex_size;
|
||||
NVec4 uvs;
|
||||
};
|
||||
}
|
29
include/pd/ThemeEditor.hpp
Normal file
29
include/pd/ThemeEditor.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/palladium.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class ThemeEditor : public Palladium::Scene {
|
||||
public:
|
||||
ThemeEditor();
|
||||
~ThemeEditor();
|
||||
|
||||
void Draw(void) const override;
|
||||
void Logic() override;
|
||||
|
||||
private:
|
||||
Theme::Ref edit_theme;
|
||||
// Placeholder to save active one to
|
||||
Theme::Ref temp_theme;
|
||||
|
||||
// temp vars for samples
|
||||
mutable bool cm;
|
||||
mutable std::string inpt;
|
||||
mutable int menu = 0;
|
||||
|
||||
// Keyboard
|
||||
mutable PDKeyboardState kbd_state;
|
||||
mutable std::string kbd_text;
|
||||
mutable std::vector<std::string> theme_list;
|
||||
};
|
||||
} // namespace Palladium
|
13
include/pd/Time.hpp
Normal file
13
include/pd/Time.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#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
|
26
include/pd/Timer.hpp
Normal file
26
include/pd/Timer.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#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
|
102
include/pd/UI7.hpp
Normal file
102
include/pd/UI7.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/Image.hpp>
|
||||
#include <pd/NVec.hpp>
|
||||
#include <pd/Render2.hpp>
|
||||
#include <pd/smart_ctor.hpp>
|
||||
|
||||
#define UI7MAKEFLAG(x) (1 << x)
|
||||
|
||||
typedef int UI7MenuFlags;
|
||||
|
||||
enum UI7MenuFlags_ {
|
||||
UI7MenuFlags_None = 0,
|
||||
UI7MenuFlags_NoTitlebar = UI7MAKEFLAG(0),
|
||||
UI7MenuFlags_TitleMid = UI7MAKEFLAG(1),
|
||||
UI7MenuFlags_Scrolling = MAKEFLAG(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();
|
||||
|
||||
PD_SMART_CTOR(UI7DrawList)
|
||||
|
||||
private:
|
||||
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();
|
||||
NVec2 GetCursorPos();
|
||||
void SetCursorPos(NVec2 cp);
|
||||
void RestoreCursor();
|
||||
void SameLine();
|
||||
// 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
|
||||
// DrawLists
|
||||
UI7DrawList::Ref GetForegroundList();
|
||||
UI7DrawList::Ref GetBackgroundList();
|
||||
} // namespace UI7
|
25447
include/pd/external/json.hpp
vendored
Normal file
25447
include/pd/external/json.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8681
include/pd/external/stb_image.h
vendored
Normal file
8681
include/pd/external/stb_image.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2054
include/pd/external/stb_image_write.h
vendored
Normal file
2054
include/pd/external/stb_image_write.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5636
include/pd/external/stb_truetype.h
vendored
Normal file
5636
include/pd/external/stb_truetype.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
38
include/pd/global_db.hpp
Normal file
38
include/pd/global_db.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
#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 = int;
|
||||
enum PDFlags_ {
|
||||
PDFlags_None = 0,
|
||||
PDFlags_MemTrack = 1 << 0,
|
||||
PDFlags_SceneSystem = 1 << 1,
|
||||
PDFlags_ShowSplash = 1 << 2,
|
||||
PDFlags_Default = PDFlags_SceneSystem,
|
||||
};
|
||||
|
||||
// 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 int pd_max_objects;
|
||||
extern C3D_RenderTarget *pd_top;
|
||||
extern C3D_RenderTarget *pd_top_right;
|
||||
extern C3D_RenderTarget *pd_bottom;
|
||||
extern PDFlags pd_flags;
|
||||
|
||||
// Draw2
|
||||
extern float pd_draw2_tsm;
|
70
include/pd/internal_db.hpp
Normal file
70
include/pd/internal_db.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#include <pd/Net.hpp>
|
||||
#include <pd/external/json.hpp>
|
||||
#include <pd/global_db.hpp>
|
||||
#include <pd/palladium.hpp>
|
||||
|
||||
#define CFGVER "1"
|
||||
#define THEMEVER "0"
|
||||
|
||||
#ifndef V_PDBTIME
|
||||
#define V_PDBTIME "SUBMODULE"
|
||||
#endif
|
||||
#ifndef V_PDCSTRING
|
||||
#define V_PDCSTRING "SUBMODULE"
|
||||
#endif
|
||||
|
||||
// Base
|
||||
extern bool pdi_do_splash;
|
||||
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 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;
|
||||
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 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;
|
||||
|
||||
// Use function for protection
|
||||
Palladium::LoggerBase::Ref _pdi_logger();
|
||||
Palladium::Net::Error pdi_soc_init();
|
||||
void pdi_soc_deinit();
|
24
include/pd/lang.hpp
Normal file
24
include/pd/lang.hpp
Normal file
@ -0,0 +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
|
30
include/pd/nimg.hpp
Normal file
30
include/pd/nimg.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
#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
|
194
include/pd/palladium.hpp
Normal file
194
include/pd/palladium.hpp
Normal file
@ -0,0 +1,194 @@
|
||||
#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 <citro2d.h>
|
||||
#include <citro3d.h>
|
||||
/// Palladium Includes
|
||||
#include <pd/Color.hpp>
|
||||
#include <pd/FunctionTrace.hpp>
|
||||
#include <pd/Hardware.hpp>
|
||||
#include <pd/Logger.hpp>
|
||||
#include <pd/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/parameter.hpp>
|
||||
#include <pd/stringtool.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 {
|
||||
// Reference to Global Logger
|
||||
LoggerBase::Ref Logger();
|
||||
/// @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 Logic() = 0;
|
||||
/// @brief Draw Func to Override
|
||||
virtual void Draw() const = 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 doDraw();
|
||||
static void doLogic();
|
||||
};
|
||||
|
||||
/// @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
|
||||
};
|
||||
|
||||
/// @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 Override for Draw
|
||||
/// @param
|
||||
void Draw(void) const override;
|
||||
/// @brief Deconstructor
|
||||
~RSettings();
|
||||
void Logic() 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
|
134
include/pd/parameter.hpp
Normal file
134
include/pd/parameter.hpp
Normal file
@ -0,0 +1,134 @@
|
||||
#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
|
10
include/pd/smart_ctor.hpp
Normal file
10
include/pd/smart_ctor.hpp
Normal file
@ -0,0 +1,10 @@
|
||||
#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)...); \
|
||||
}
|
103
include/pd/stringtool.hpp
Normal file
103
include/pd/stringtool.hpp
Normal file
@ -0,0 +1,103 @@
|
||||
#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();
|
||||
}
|
25
include/pd/swr.hpp
Normal file
25
include/pd/swr.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/nimg.hpp>
|
||||
|
||||
namespace Palladium {
|
||||
class swr {
|
||||
public:
|
||||
swr(int w, int h);
|
||||
swr();
|
||||
~swr();
|
||||
nimg& get_image() { return image; }
|
||||
void load_file(const std::string& path);
|
||||
void load_nimg(const std::string& path);
|
||||
|
||||
// Rendering
|
||||
void draw_pixel(int x, int y, unsigned int color);
|
||||
void draw_rect(int x, int y, int w, int h, unsigned int color, int t = 1);
|
||||
void draw_rect_solid(int x, int y, int w, int h, unsigned int color);
|
||||
void draw_line(int x1, int y1, int x2, int y2, unsigned int color, int t = 1);
|
||||
void flip(bool h, bool v);
|
||||
|
||||
private:
|
||||
nimg image;
|
||||
};
|
||||
} // namespace Palladium
|
122
include/pd/thread.hpp
Normal file
122
include/pd/thread.hpp
Normal file
@ -0,0 +1,122 @@
|
||||
#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
|
Reference in New Issue
Block a user