// file : data/client.h // project : Salis-VM // author : Paul Oliver // 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 struct Trace : public std::vector { 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 struct TraceNamed : public Trace { 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 struct TraceHeatmap : public TraceNamed { 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 trace_keys); private: void render_internal(const ImVec2 &frame_size); std::vector m_trace_keys; }; struct PlotStacked : public Plot { PlotStacked(const char *name, const char *section, std::vector 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 m_trace_keys; std::vector m_trace_states; Trace m_trace_totals; std::vector> 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 m_tex_render; bool m_needs_reset; }; #endif