Add class 'SimpleDynamic' to base-writer, migrate AnimValue to use it

This commit is contained in:
2023-10-17 19:34:50 -04:00
parent edea43839f
commit 5373182a59
4 changed files with 166 additions and 199 deletions

View File

@@ -93,6 +93,7 @@
#include "wrap-deque.hpp"
#include "wrap-unordered-map.hpp"
#include "base-writer.hpp"
#include "luastack.hpp"
#include "streambuffer.hpp"
#include "debugcollector.hpp"
@@ -101,36 +102,15 @@
#include <cassert>
#include <ostream>
enum AnimValueType {
T_STRING,
T_NUMBER,
T_BOOLEAN,
T_XYZ,
T_UNINITIALIZED
};
struct AnimValue {
AnimValue() : persistent(false), type(T_UNINITIALIZED) {}
struct AnimValue : public SimpleDynamic {
bool persistent;
AnimValueType type;
eng::string str;
util::DXYZ xyz;
// These set the type, str, and xyz fields in a consistent way.
void set_boolean(bool b);
void set_number(double n);
void set_xyz(const util::DXYZ &xyz);
void set_string(std::string_view s);
AnimValue() { persistent = false; }
// The get the type, str, and xyz fields in a consistent way.
bool get_boolean() const;
double get_number() const;
const util::DXYZ &get_xyz() const;
std::string_view get_string() const;
// Copy the value from another animvalue. Don't copy the persistent flag.
void copy_value(const AnimValue &other);
void set_dxyz(const util::DXYZ &xyz) {
type = SimpleDynamicTag::VECTOR;
s.clear(); x = xyz.x; y = xyz.y; z = xyz.z;
}
};
@@ -158,20 +138,12 @@ public:
//
bool contains(const eng::string &name) { return map_.find(name) != map_.end(); }
// Get the value of a specific variable.
// If the variable isn't present, return a default value.
//
bool get_boolean(const eng::string &name);
double get_number(const eng::string &name);
util::DXYZ get_xyz(const eng::string &name);
std::string_view get_string(const eng::string &name);
// Set a single variable to a value of a specified type.
// If the variable isn't present, add it.
//
void set_boolean(const eng::string &name, bool v);
void set_number(const eng::string &name, double v);
void set_xyz(const eng::string &name, const util::DXYZ &value);
void set_dxyz(const eng::string &name, const util::DXYZ &value);
void set_string(const eng::string &name, std::string_view value);
// Print a debug string into the stringstream.