Small fixes

This commit is contained in:
momo5502 2022-01-16 10:42:09 +01:00
parent 8d7d4f2d39
commit 9a97d52e2d
4 changed files with 72 additions and 24 deletions

View File

@ -13,13 +13,7 @@ namespace game::scripting
entity::entity(entity&& other) noexcept
{
if (&other == this) return;
this->context_ = other.context_;
this->entity_id_ = other.entity_id_;
other.context_ = nullptr;
other.entity_id_ = 0;
this->operator=(std::move(other));
}
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)
{
this->release();
this->~entity();
this->context_ = other.context_;
this->entity_id_ = other.entity_id_;
@ -51,7 +45,7 @@ namespace game::scripting
{
if (&other != this)
{
this->release();
this->~entity();
this->context_ = other.context_;
this->entity_id_ = other.entity_id_;
@ -114,7 +108,7 @@ namespace game::scripting
{
if (this->entity_id_)
{
native::VariableValue value;
native::VariableValue value{};
value.type = native::SCRIPT_OBJECT;
value.u.entityId = this->entity_id_;
native::AddRefToValue(&value);

View File

@ -1,20 +1,68 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "variable_value.hpp"
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()
{
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_;
}
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;
}
}
}

View File

@ -3,15 +3,25 @@
namespace game::scripting
{
class variable_value final
class variable_value
{
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();
explicit operator native::VariableValue() const;
const native::VariableValue& get() const;
private:
native::VariableValue value_;
void assign(const native::VariableValue& value);
void release();
native::VariableValue value_{{0}, native::SCRIPT_NONE};
};
}

View File

@ -7,11 +7,7 @@ namespace utils::compression
std::string zlib::compress(const std::string& data)
{
memory::allocator allocator;
unsigned long length = (data.size() * 2);
if (!length) length = 2;
if (length < 100) length *= 10;
unsigned long length = compressBound(data.size());
const auto buffer = allocator.allocate_array<char>(length);
if (compress2(reinterpret_cast<Bytef*>(buffer), &length,
reinterpret_cast<Bytef*>(const_cast<char*>(data.data())), data.size(),