Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/commit-checker.yml
#	src/industry_cmd.cpp
#	src/industry_gui.cpp
#	src/landscape.cpp
#	src/linkgraph/linkgraph_gui.cpp
#	src/order_base.h
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/saveload/afterload.cpp
#	src/saveload/league_sl.cpp
#	src/saveload/saveload.h
#	src/script/api/script_object.hpp
#	src/script/squirrel_helper.hpp
#	src/settings_table.cpp
#	src/station_cmd.cpp
#	src/table/settings.h.preamble
#	src/tree_cmd.cpp
#	src/tree_map.h
#	src/vehicle.cpp
#	src/waypoint_cmd.cpp
This commit is contained in:
Jonathan G Rennison
2023-03-04 16:44:23 +00:00
94 changed files with 1075 additions and 1558 deletions

View File

@@ -19,6 +19,8 @@
#include "../script_suspend.hpp"
#include "../squirrel.hpp"
#include <utility>
struct CommandAuxiliaryBase;
/**
@@ -342,4 +344,68 @@ private:
static Randomizer random_states[OWNER_END]; ///< Random states for each of the scripts (game script uses OWNER_DEITY)
};
/**
* Internally used class to automate the ScriptObject reference counting.
* @api -all
*/
template <typename T>
class ScriptObjectRef {
private:
T *data; ///< The reference counted object.
public:
/**
* Create the reference counter for the given ScriptObject instance.
* @param data The underlying object.
*/
ScriptObjectRef(T *data) : data(data)
{
this->data->AddRef();
}
/* No copy constructor. */
ScriptObjectRef(const ScriptObjectRef<T> &ref) = delete;
/* Move constructor. */
ScriptObjectRef(ScriptObjectRef<T> &&ref) noexcept : data(std::exchange(ref.data, nullptr))
{
}
/* No copy assignment. */
ScriptObjectRef& operator=(const ScriptObjectRef<T> &other) = delete;
/* Move assignment. */
ScriptObjectRef& operator=(ScriptObjectRef<T> &&other) noexcept
{
std::swap(this->data, other.data);
return *this;
}
/**
* Release the reference counted object.
*/
~ScriptObjectRef()
{
if (this->data != nullptr) this->data->Release();
}
/**
* Dereferencing this reference returns a reference to the reference
* counted object
* @return Reference to the underlying object.
*/
T &operator*()
{
return *this->data;
}
/**
* The arrow operator on this reference returns the reference counted object.
* @return Pointer to the underlying object.
*/
T *operator->()
{
return this->data;
}
};
#endif /* SCRIPT_OBJECT_HPP */