Small fixes
This commit is contained in:
parent
8d7d4f2d39
commit
9a97d52e2d
@ -13,13 +13,7 @@ namespace game::scripting
|
|||||||
|
|
||||||
entity::entity(entity&& other) noexcept
|
entity::entity(entity&& other) noexcept
|
||||||
{
|
{
|
||||||
if (&other == this) return;
|
this->operator=(std::move(other));
|
||||||
|
|
||||||
this->context_ = other.context_;
|
|
||||||
this->entity_id_ = other.entity_id_;
|
|
||||||
|
|
||||||
other.context_ = nullptr;
|
|
||||||
other.entity_id_ = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
entity::entity(context* context, const unsigned int entity_id) : context_(context), entity_id_(entity_id)
|
entity::entity(context* context, const unsigned int entity_id) : context_(context), entity_id_(entity_id)
|
||||||
@ -36,7 +30,7 @@ namespace game::scripting
|
|||||||
{
|
{
|
||||||
if (&other != this)
|
if (&other != this)
|
||||||
{
|
{
|
||||||
this->release();
|
this->~entity();
|
||||||
|
|
||||||
this->context_ = other.context_;
|
this->context_ = other.context_;
|
||||||
this->entity_id_ = other.entity_id_;
|
this->entity_id_ = other.entity_id_;
|
||||||
@ -51,7 +45,7 @@ namespace game::scripting
|
|||||||
{
|
{
|
||||||
if (&other != this)
|
if (&other != this)
|
||||||
{
|
{
|
||||||
this->release();
|
this->~entity();
|
||||||
|
|
||||||
this->context_ = other.context_;
|
this->context_ = other.context_;
|
||||||
this->entity_id_ = other.entity_id_;
|
this->entity_id_ = other.entity_id_;
|
||||||
@ -114,7 +108,7 @@ namespace game::scripting
|
|||||||
{
|
{
|
||||||
if (this->entity_id_)
|
if (this->entity_id_)
|
||||||
{
|
{
|
||||||
native::VariableValue value;
|
native::VariableValue value{};
|
||||||
value.type = native::SCRIPT_OBJECT;
|
value.type = native::SCRIPT_OBJECT;
|
||||||
value.u.entityId = this->entity_id_;
|
value.u.entityId = this->entity_id_;
|
||||||
native::AddRefToValue(&value);
|
native::AddRefToValue(&value);
|
||||||
|
@ -1,20 +1,68 @@
|
|||||||
#include "std_include.hpp"
|
#include <std_include.hpp>
|
||||||
#include "variable_value.hpp"
|
#include "variable_value.hpp"
|
||||||
|
|
||||||
namespace game::scripting
|
namespace game::scripting
|
||||||
{
|
{
|
||||||
variable_value::variable_value(native::VariableValue value) : value_(value)
|
variable_value::variable_value(const native::VariableValue& value)
|
||||||
{
|
{
|
||||||
native::AddRefToValue(&value);
|
this->assign(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
variable_value::variable_value(const variable_value& other) noexcept
|
||||||
|
{
|
||||||
|
this->operator=(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
variable_value::variable_value(variable_value&& other) noexcept
|
||||||
|
{
|
||||||
|
this->operator=(std::move(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
variable_value& variable_value::operator=(const variable_value& other) noexcept
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
this->release();
|
||||||
|
this->assign(other.value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
variable_value& variable_value::operator=(variable_value&& other) noexcept
|
||||||
|
{
|
||||||
|
if (this != &other)
|
||||||
|
{
|
||||||
|
this->release();
|
||||||
|
this->value_ = other.value_;
|
||||||
|
other.value_.type = native::SCRIPT_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
variable_value::~variable_value()
|
variable_value::~variable_value()
|
||||||
{
|
{
|
||||||
native::RemoveRefToValue(this->value_.type, this->value_.u);
|
this->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
variable_value::operator native::VariableValue() const
|
const native::VariableValue& variable_value::get() const
|
||||||
{
|
{
|
||||||
return this->value_;
|
return this->value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void variable_value::assign(const native::VariableValue& value)
|
||||||
|
{
|
||||||
|
this->value_ = value;
|
||||||
|
native::AddRefToValue(&this->value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void variable_value::release()
|
||||||
|
{
|
||||||
|
if (this->value_.type != native::SCRIPT_NONE)
|
||||||
|
{
|
||||||
|
native::RemoveRefToValue(this->value_.type, this->value_.u);
|
||||||
|
this->value_.type = native::SCRIPT_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,25 @@
|
|||||||
|
|
||||||
namespace game::scripting
|
namespace game::scripting
|
||||||
{
|
{
|
||||||
class variable_value final
|
class variable_value
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit variable_value(native::VariableValue value);
|
variable_value() = default;
|
||||||
|
variable_value(const native::VariableValue& value);
|
||||||
|
variable_value(const variable_value& other) noexcept;
|
||||||
|
variable_value(variable_value&& other) noexcept;
|
||||||
|
|
||||||
|
variable_value& operator=(const variable_value& other) noexcept;
|
||||||
|
variable_value& operator=(variable_value&& other) noexcept;
|
||||||
|
|
||||||
~variable_value();
|
~variable_value();
|
||||||
|
|
||||||
explicit operator native::VariableValue() const;
|
const native::VariableValue& get() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
native::VariableValue value_;
|
void assign(const native::VariableValue& value);
|
||||||
|
void release();
|
||||||
|
|
||||||
|
native::VariableValue value_{{0}, native::SCRIPT_NONE};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,7 @@ namespace utils::compression
|
|||||||
std::string zlib::compress(const std::string& data)
|
std::string zlib::compress(const std::string& data)
|
||||||
{
|
{
|
||||||
memory::allocator allocator;
|
memory::allocator allocator;
|
||||||
unsigned long length = (data.size() * 2);
|
unsigned long length = compressBound(data.size());
|
||||||
if (!length) length = 2;
|
|
||||||
|
|
||||||
if (length < 100) length *= 10;
|
|
||||||
|
|
||||||
const auto buffer = allocator.allocate_array<char>(length);
|
const auto buffer = allocator.allocate_array<char>(length);
|
||||||
if (compress2(reinterpret_cast<Bytef*>(buffer), &length,
|
if (compress2(reinterpret_cast<Bytef*>(buffer), &length,
|
||||||
reinterpret_cast<Bytef*>(const_cast<char*>(data.data())), data.size(),
|
reinterpret_cast<Bytef*>(const_cast<char*>(data.data())), data.size(),
|
||||||
|
Loading…
Reference in New Issue
Block a user