This commit is contained in:
alice
2026-07-27 03:57:20 +02:00
parent 933192724a
commit befebc4b6e
17 changed files with 88 additions and 99 deletions
+21 -20
View File
@@ -15,30 +15,30 @@ namespace scripting
}
const auto value = game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::VariableValue variable;
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
this->value_ = variable;
}
void array_value::operator=(const script_value& _value)
void array_value::operator=(const script_value& value)
{
if (!this->id_)
{
return;
}
const auto value = _value.get_raw();
const auto& value_raw = value.get_raw();
const auto variable = &game::scr_VarGlob->childVariableValue[this->id_ + 0xC800 * (this->parent_id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
variable->type = value_raw.type;
variable->u.u = value_raw.u;
this->value_ = value;
this->value_ = value_raw;
}
array::array(const unsigned int id)
@@ -170,7 +170,7 @@ namespace scripting
return game::Scr_GetSelf(this->id_);
}
unsigned int array::push(script_value value) const
unsigned int array::push(const script_value& value) const
{
this->set(this->size(), value);
return this->size();
@@ -225,7 +225,7 @@ namespace scripting
}
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable;
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
@@ -242,7 +242,7 @@ namespace scripting
}
const auto value = game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::VariableValue variable;
game::VariableValue variable{};
variable.u = value.u.u;
variable.type = (game::scriptType_e)value.type;
@@ -261,9 +261,9 @@ namespace scripting
}
}
void array::set(const std::string& key, const script_value& value_) const
void array::set(const std::string& key, const script_value& value) const
{
const auto value = value_.get_raw();
const auto& value_raw = value.get_raw();
const auto variable_id = this->get_value_id(key);
if (!variable_id)
@@ -273,16 +273,16 @@ namespace scripting
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
variable->type = value_raw.type;
variable->u.u = value_raw.u;
}
void array::set(const unsigned int index, const script_value& value_) const
void array::set(const unsigned int index, const script_value& value) const
{
const auto value = value_.get_raw();
const auto& value_raw = value.get_raw();
const auto variable_id = this->get_value_id(index);
if (!variable_id)
@@ -292,11 +292,11 @@ namespace scripting
const auto variable = &game::scr_VarGlob->childVariableValue[variable_id + 0xC800 * (this->id_ & 1)];
game::AddRefToValue(value.type, value.u);
game::AddRefToValue(value_raw.type, value_raw.u);
game::RemoveRefToValue(variable->type, variable->u.u);
variable->type = value.type;
variable->u.u = value.u;
variable->type = value_raw.type;
variable->u.u = value_raw.u;
}
unsigned int array::get_entity_id() const
@@ -320,6 +320,7 @@ namespace scripting
unsigned int array::get_value_id(const unsigned int index) const
{
const auto variable_id = game::FindVariable(this->id_, (index - 0x800000) & 0xFFFFFF);
if (!variable_id)
{
return game::GetNewArrayVariable(this->id_, index);
+3 -3
View File
@@ -34,7 +34,7 @@ namespace scripting
std::vector<script_value> get_keys() const;
unsigned int size() const;
unsigned int push(script_value) const;
unsigned int push(const script_value&) const;
void erase(const unsigned int) const;
void erase(const std::string&) const;
script_value pop() const;
@@ -69,12 +69,12 @@ namespace scripting
{
if (key.is<I>())
{
return { this->id_, this->get_value_id(key.as<I>()) };
return {this->id_, this->get_value_id(key.as<I>())};
}
if (key.is<S>())
{
return { this->id_, this->get_value_id(key.as<S>()) };
return {this->id_, this->get_value_id(key.as<S>())};
}
}
+2 -3
View File
@@ -11,10 +11,9 @@ namespace scripting
script_value function::get_raw() const
{
game::VariableValue value;
game::VariableValue value{};
value.type = game::SCRIPT_FUNCTION;
value.u.codePosValue = this->pos_;
return value;
}
@@ -23,7 +22,7 @@ namespace scripting
return this->pos_;
}
script_value function::call(const entity& self, std::vector<script_value> arguments) const
script_value function::call(const entity& self, const std::vector<script_value>& arguments) const
{
return exec_ent_thread(self, this->pos_, arguments);
}
+5 -3
View File
@@ -12,14 +12,14 @@ namespace scripting
script_value get_raw() const;
const char* get_pos() const;
script_value call(const entity& self, std::vector<script_value> arguments) const;
script_value call(const entity& self, const std::vector<script_value>& arguments) const;
script_value operator()(const entity& self, std::vector<script_value> arguments) const
script_value operator()(const entity& self, const std::vector<script_value>& arguments) const
{
return this->call(self, arguments);
}
script_value operator()(std::vector<script_value> arguments) const
script_value operator()(const std::vector<script_value>& arguments) const
{
return this->call(*game::levelEntityId, arguments);
}
@@ -28,7 +28,9 @@ namespace scripting
{
return this->call(*game::levelEntityId, {});
}
private:
const char* pos_;
};
}
-9
View File
@@ -1,9 +0,0 @@
#include <stdinc.hpp>
#include "functions.hpp"
#include <utils/string.hpp>
namespace scripting
{
}
-7
View File
@@ -1,7 +0,0 @@
#pragma once
#include "game/game.hpp"
namespace scripting
{
using script_function = void(*)(game::scr_entref_t);
}
+1 -1
View File
@@ -321,7 +321,7 @@ namespace scripting
return this->value_.get();
}
value_wrap::value_wrap(const scripting::script_value& value, int argument_index)
value_wrap::value_wrap(const scripting::script_value& value, const std::uint32_t argument_index)
: value_(value)
, argument_index_(argument_index)
{
+3 -3
View File
@@ -164,7 +164,7 @@ namespace scripting
class value_wrap
{
public:
value_wrap(const scripting::script_value& value, int argument_index);
value_wrap(const scripting::script_value& value, const std::uint32_t);
template <typename T>
T as() const
@@ -179,7 +179,7 @@ namespace scripting
}
}
template <typename T, typename I = int>
template <typename T>
T* as_ptr()
{
try
@@ -203,7 +203,7 @@ namespace scripting
return this->value_.get_raw();
}
int argument_index_{};
std::uint32_t argument_index_{};
scripting::script_value value_;
};
}
+1 -1
View File
@@ -26,6 +26,6 @@ namespace scripting
void set_z(float value);
private:
game::vec3_t value_{ 0 };
game::vec3_t value_{};
};
}