Adapted from Changelog:

- swr -> Rubidium
- LIFont (TTF Font Renderer)
- Implement shbin as c++ array
- Larger Mesaage Box
- Add Texture Loader
- Update Image/Error and other sytems to Lithium
- Optimize Render2 for Lithium
This commit is contained in:
2024-08-02 13:50:36 +02:00
parent 02172d8aef
commit a58dc20562
41 changed files with 1182 additions and 922 deletions

View File

@ -6,19 +6,21 @@
#include <pd/Hid.hpp>
#include <pd/Image.hpp>
#include <pd/Installer.hpp>
#include <pd/LI7.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/Timer.hpp>
#include <pd/UI7.hpp>
#include <pd/global_db.hpp>
#include <pd/palladium.hpp>
#include <pd/swr.hpp>
#include <pd/Texture.hpp>
namespace Palladium {
using Render2 = R2;
}
using Render2 = R2;
using RB = Rubidium;
} // namespace Palladium
namespace PD = Palladium;

View File

@ -44,11 +44,11 @@ enum PDColor_ {
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_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

View File

@ -8,7 +8,7 @@ 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) {
inline void InlineAssert(bool v, const std::string& msg = "") {
if (v == false) {
std::string location =
__FILE__ + std::string(":") + std::to_string(__LINE__);

View File

@ -1,9 +1,9 @@
#pragma once
#include <3ds.h>
#include <citro2d.h>
#include <pd/NVec.hpp>
#include <pd/Texture.hpp>
#include <pd/nimg.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
@ -12,7 +12,6 @@ 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)
@ -20,14 +19,17 @@ class Image {
void From_NIMG(const nimg& image);
void Delete();
C2D_Image Get();
C2D_Image& GetRef();
void Set(const C2D_Image& i);
Texture::Ref Get();
void Set(Texture::Ref i, NVec4 uvs = NVec4(-1, -1, -1, -1));
NVec2 GetSize();
NVec4 GetUV() {
return (custom_uvs.x != -1) ? custom_uvs : img->GetUV();
}
bool Loadet();
private:
bool ext = false;
C2D_Image img;
Texture::Ref img;
NVec4 custom_uvs = NVec4(-1, -1, -1, -1);
};
} // namespace Palladium

View File

@ -1,7 +1,8 @@
#pragma once
#include <3ds.h> // Result
#include <string>
#include <3ds.h> // Result
namespace Palladium {
struct InstallerInfo {

View File

@ -1,62 +1,94 @@
#include <pd/NVec.hpp>
#include <pd/Allocator.hpp>
#include <pd/Texture.hpp>
#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;
};
LIFont() = default;
~LIFont() = default;
PD_SMART_CTOR(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();
void LoadTFF(const std::string path, int px_size = 32);
void LoadBitmapFont(const std::string& path);
void LoadSystemFont();
int GetPixelHeight();
CPI GetCodepoint();
int GetPixelHeight();
CPI GetCodepoint(char c);
std::string GetName() { return name; };
private:
int pixel_height;
unsigned char fontw[256];
int charsize;
std::vector<Texture::Ref> tex;
void Dump();
private:
std::string name;
int pixel_height;
std::vector<CPI> cpmap;
std::vector<Texture::Ref> tex;
};
class LI7 {
public:
struct Vtx
{
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
/////////////////
struct Cmd {
};
/// 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;
@ -69,28 +101,39 @@ struct Cmd {
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 int DrawText(int x, int y, int z, unsigned int color, bool shadow,
int wrap, int* ySize, const char* fmt, ...);
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 DarwCommandss() { return m_d_commands; }
static int DarwCommands() { return m_d_commands; }
private:
static bool CompareCommands(const Cmd& a,
const Cmd& b);
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 const float m_dts;
static float m_txt_scale;
static int m_uLoc_proj;
static float m_scale;
@ -101,25 +144,23 @@ struct Cmd {
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 Texture::Ref m_white;
static std::vector<Vtx, LinearAllocator<Vtx>> m_vtx_list[2];
//static Font* m_font;
// static Font* m_font;
static LIFont::Ref 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 DVLB_s* li7_dvlb;
static shaderProgram_s li7_prog;
static C3D_AttrInfo li7_attr;
};
}
} // namespace Palladium

View File

@ -9,7 +9,9 @@ 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; }
unsigned int t_CurrentlyAllocated() {
return t_TotalAllocated - t_TotalFreed;
}
};
/// @brief Get Total Allocated Memory
/// @return Total Allocated Memory

View File

@ -36,6 +36,7 @@ struct NVec2 {
// and swap it lol
return !(*this == in);
}
// Internal Values
float x;
float y;

View File

@ -48,7 +48,9 @@ class Ovl_Metrik : public Palladium::Ovl {
mutable std::string mt_gpu;
mutable std::string mt_cmd;
mutable std::string mt_lfr;
mutable std::string mt_tbs;
mutable std::string mt_vtx;
mutable std::string mt_drc;
mutable std::string mt_dmc;
mutable std::string mt_mem;
// Importand Adresses

View File

@ -4,24 +4,11 @@
#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>
#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,
@ -32,9 +19,9 @@ namespace Palladium {
class R2 {
public:
struct R2Cmd {
NVec2 pos; //< Position
NVec2 pszs; //< Position or (TextBox) Size
NVec2 ap; //< Additional Pos
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
@ -45,7 +32,7 @@ class R2 {
bool lined = false; //< Draw Lined Rect/Tri
// Text Specific
PDTextFlags flags; // Text Flags
std::string text; // Text
std::string text; // Text
PD_SMART_CTOR(R2Cmd)
};
R2() = default;
@ -73,8 +60,7 @@ class R2 {
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 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,

30
include/pd/Rubidium.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include <pd/nimg.hpp>
#include <pd/smart_ctor.hpp>
namespace Palladium {
class Rubidium {
public:
Rubidium(int w, int h);
Rubidium();
~Rubidium();
PD_SMART_CTOR(Rubidium)
nimg& GetNimg() { return image; }
void LoadFile(const std::string& path);
void LoadNimg(const std::string& path);
// Rendering
void DrawPixel(int x, int y, unsigned int color);
void DrawRect(int x, int y, int w, int h, unsigned int color, int t = 1);
void DrawRectSolid(int x, int y, int w, int h, unsigned int color);
void DrawLine(int x1, int y1, int x2, int y2, unsigned int color, int t = 1);
void Flip(bool h, bool v);
void EnableAA(bool enable) { enable_aa = enable; }
private:
// Leinwand (dont know english word for that)
nimg image;
bool enable_aa = true;
};
} // namespace Palladium

View File

@ -1,35 +1,70 @@
#include <pd/smart_ctor.hpp>
#include <pd/NVec.hpp>
#include <vector>
#include <string>
#pragma once
#include <citro3d.h>
#include <pd/NVec.hpp>
#include <pd/smart_ctor.hpp>
#include <string>
#include <vector>
namespace Palladium {
class Texture {
public:
Texture() = default;
~Texture() = default;
PD_SMART_CTOR(Texture)
class Texture {
public:
// Define Types supported by the texture loader
// For example usefull to waste not as much space
// in linear mem
enum Type {
RGBA32,
RGB24,
A8,
};
Texture() {
// Set Default UV
this->uvs.x = 0.0f;
this->uvs.y = 1.0f;
this->uvs.z = 1.0f;
this->uvs.w = 0.0f;
};
~Texture() { Delete(); }
PD_SMART_CTOR(Texture)
void Delete();
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);
/// @brief Loads an Image [png, jpg, bmp] as texture
/// by default it sets up the texture as RGBA32 and
/// only supports RGB24 and RGBA32 images
/// @param path Path to file
void LoadFile(const std::string& path);
/// @brief Loads an Image [png, jpg, bmp] as texture
/// by default it sets up the texture as RGBA32 and
/// only supports RGB24 and RGBA32 images
/// @param data Data of file
void LoadFromMemory(const std::vector<unsigned char>& data);
/// @brief Create Texture by pixel Data. This function supports
/// [RGBA32, RGB24, A8]
/// @param data Pixel Data
/// @param w Width of data
/// @param h Height of Data
/// @param type Type of Data (default is RGBA32)
void LoadPixels(const std::vector<unsigned char>& data, int w, int h, Type type = RGBA32);
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; }
/// @brief This function sets up a texture Object based on the input
/// Data and a self setup C3D_Tex. You dont need to delete it as
/// This class does this automatically
void ExternalLoad(C3D_Tex* tex, NVec2 rszs, NVec4 uvs);
private:
void MakeTex(std::vector<unsigned char> &buf, int w, int h);
C3D_Tex* tex;
NVec2 img_size;
NVec2 tex_size;
NVec4 uvs;
};
}
C3D_Tex* Get() { return this->tex; }
NVec2 GetTexSize();
NVec2 GetSize() { return img_size; }
// As the texture is a pow of 2 we need a uv
NVec4 GetUV() { return uvs; }
void AutoDelete(bool enable) { ad = enable; }
private:
void MakeTex(std::vector<unsigned char>& buf, int w, int h, Type type = RGBA32);
C3D_Tex* tex = nullptr;
NVec2 img_size;
NVec4 uvs;
bool ad = true;
};
} // namespace Palladium

View File

@ -0,0 +1,8 @@
// THIS FILE WAS GENERATED BY build_shaders.py!!!
#pragma once
#include <cstddef>
extern unsigned char li7_shader[];
extern size_t li7_shader_size;

View File

@ -81,6 +81,7 @@ class RSettings : public Palladium::Scene {
RFTRACE, // FTRace Menu
RUI7, // UI7 Menu
RLOGS, // Logs
RFV, // Font Viewer
};
/// @param shared_request Defines requests from Draw to Logic
@ -89,7 +90,8 @@ class RSettings : public Palladium::Scene {
/// 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;
Palladium::RSettings::RState m_state =
Palladium::RSettings::RState::RSETTINGS;
/// @brief Position in FTrace Menu
int ftrace_index = 0;

View File

@ -2,7 +2,7 @@
#include <memory>
#define PD_SMART_CTOR(type) \
#define PD_SMART_CTOR(type) \
using Ref = std::shared_ptr<type>; \
template <typename... args> \
static Ref New(args&&... cargs) { \

View File

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