summaryrefslogtreecommitdiff
path: root/data/client.h
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-07-14 17:29:02 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-08-30 16:24:48 +0200
commit1961b4b237083f4cfac9ca6b249c1d6cb665d149 (patch)
treefd9fc8260360e2ac30be9747ca558bcfc824a4c4 /data/client.h
Initial (refactor)HEADmaster
Diffstat (limited to 'data/client.h')
-rw-r--r--data/client.h137
1 files changed, 137 insertions, 0 deletions
diff --git a/data/client.h b/data/client.h
new file mode 100644
index 0000000..77ff948
--- /dev/null
+++ b/data/client.h
@@ -0,0 +1,137 @@
+// file : data/client.h
+// project : Salis-VM
+// author : Paul Oliver <contact@pauloliver.dev>
+
+// index:
+// [section] macros
+// [section] trace declarations
+// [section] plot declarations
+
+// ----------------------------------------------------------------------------
+// [section] macros
+// ----------------------------------------------------------------------------
+#define CLIENT_DEFVAL_ENTRIES 0x800l
+#define CLIENT_DEFVAL_HM_LEFT 0l
+#define CLIENT_DEFVAL_HM_PIXEL_COUNT 0x400l
+#define CLIENT_DEFVAL_NTH 1l
+#define CLIENT_DEFVAL_X_AXIS 0
+#define CLIENT_DEFVAL_X_HIGH INT64_MAX
+#define CLIENT_DEFVAL_X_LOW 0l
+
+// Client implementation must define this.
+// Server implementation must not (as it's C not C++).
+#if defined(CLIENT_DECLARE_TRACES_AND_PLOTS)
+
+// ----------------------------------------------------------------------------
+// [section] trace declarations
+// ----------------------------------------------------------------------------
+struct StringComparator {
+ bool operator()(const char *a, const char *b) const;
+};
+
+template <class T>
+struct Trace : public std::vector<T> {
+ Trace();
+ virtual ~Trace();
+ virtual size_t start_offset() const;
+ virtual void trim();
+#if !defined(NDEBUG)
+ virtual void validate() const;
+#endif
+ void clear();
+ void push_back(T value);
+ T *start();
+ T &operator[](size_t n);
+ T operator[](size_t n) const;
+protected:
+ void trim_spec(int64_t multiplier = 1);
+};
+
+template <class T>
+struct TraceNamed : public Trace<T> {
+ TraceNamed(const char *name, const char *label);
+ const char *get_name() const;
+ const char *get_label() const;
+private:
+ const char *m_name;
+ const char *m_label;
+};
+
+template <class T>
+struct TraceHeatmap : public TraceNamed<T> {
+ TraceHeatmap(const char *name, const char *label);
+ size_t start_offset() const;
+ void trim();
+#if !defined(NDEBUG)
+ void validate() const;
+#endif
+};
+
+// ----------------------------------------------------------------------------
+// [section] plot declarations
+// ----------------------------------------------------------------------------
+typedef int (*AxisFormatter)(double value, char *buff, int size, void *data);
+
+struct Plot {
+ Plot(const char *name, const char *section);
+ virtual ~Plot();
+ virtual void handle_input(int key, int mods);
+ virtual void flag_for_reset();
+ const char *get_name() const;
+ const char *get_section() const;
+ void render(const ImVec2 &frame_size);
+ bool m_visible;
+private:
+ static int hex_formatter(double value, char *buff, int size, void *data);
+ virtual AxisFormatter x_formatter() const;
+ virtual AxisFormatter y_formatter() const;
+ virtual float right_margin() const;
+ virtual int flags() const;
+ virtual void render_internal(const ImVec2 &frame_size) = 0;
+ virtual void render_post(const ImVec2 &frame_size);
+ const char *m_name;
+ const char *m_section;
+};
+
+struct PlotLines : public Plot {
+ PlotLines(const char *name, const char *section, std::vector<const char *> trace_keys);
+private:
+ void render_internal(const ImVec2 &frame_size);
+ std::vector<const char *> m_trace_keys;
+};
+
+struct PlotStacked : public Plot {
+ PlotStacked(const char *name, const char *section, std::vector<const char *> trace_keys);
+ void flag_for_reset();
+private:
+ static int percent_formatter(double value, char *buff, int size, void *data);
+ AxisFormatter y_formatter() const;
+ void render_internal(const ImVec2 &frame_size);
+ std::vector<const char *> m_trace_keys;
+ std::vector<bool> m_trace_states;
+ Trace<ImS64> m_trace_totals;
+ std::vector<Trace<double>> m_trace_normals;
+ bool m_needs_reset;
+};
+
+struct PlotHeatmap : public Plot {
+ PlotHeatmap(const char *name, const char *section, const char *trace_key);
+ void handle_input(int key, int mods);
+ void flag_for_reset();
+private:
+ float right_margin() const;
+ int flags() const;
+ void render_internal(const ImVec2 &frame_size);
+ void render_end(const ImVec2 &frame_size);
+ void render_post(const ImVec2 &frame_size);
+ const char *m_trace_key;
+ float m_tex_scale_pow;
+ float m_tex_scale_high;
+ size_t m_tex_rendered_last;
+ size_t m_rows_rendered;
+ GLuint m_tex_id;
+ std::vector<uint8_t> m_tex_render;
+ bool m_needs_reset;
+};
+
+#endif