This commit is contained in:
Mikulas Florek 2021-03-09 21:31:55 +01:00
parent 7336a01120
commit 92b67a402b
66 changed files with 731 additions and 752 deletions

View file

@ -638,10 +638,10 @@ struct AnimationSceneImpl final : AnimationScene
animator.ctx->model = model;
animator.ctx->time_delta = Time::fromSeconds(time_delta);
animator.ctx->root_bone_hash = crc32(animator.resource->m_root_motion_bone);
animator.resource->update(*animator.ctx, Ref(animator.root_motion));
animator.resource->update(*animator.ctx, animator.root_motion);
model->getRelativePose(*pose);
animator.resource->getPose(*animator.ctx, Ref(*pose));
animator.resource->getPose(*animator.ctx, *pose);
for (Animator::IK& ik : animator.inverse_kinematics) {
if (ik.weight == 0) break;

View file

@ -84,7 +84,7 @@ RuntimeContext* Controller::createRuntime(u32 anim_set) {
return ctx;
}
void Controller::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const {
void Controller::update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const {
ASSERT(&ctx.controller == this);
// TODO better allocation strategy
const Span<u8> mem = ctx.data.releaseOwnership();
@ -98,18 +98,18 @@ void Controller::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motio
const int root_bone_idx = root_bone_iter.value();
const Model::Bone& bone = ctx.model->getBone(root_bone_idx);
if (m_flags.isSet(Flags::XZ_ROOT_MOTION)) {
root_motion->rot = Quat::IDENTITY;
root_motion->pos = bone.transform.rot.rotate(root_motion->pos);
root_motion->pos.y = 0;
root_motion.rot = Quat::IDENTITY;
root_motion.pos = bone.transform.rot.rotate(root_motion.pos);
root_motion.pos.y = 0;
}
else {
root_motion->rot = bone.transform.rot * root_motion->rot * bone.transform.rot.conjugated();
root_motion->pos = bone.transform.rot.rotate(root_motion->pos);
root_motion.rot = bone.transform.rot * root_motion.rot * bone.transform.rot.conjugated();
root_motion.pos = bone.transform.rot.rotate(root_motion.pos);
}
}
}
void Controller::getPose(RuntimeContext& ctx, Ref<Pose> pose) {
void Controller::getPose(RuntimeContext& ctx, Pose& pose) {
ASSERT(&ctx.controller == this);
ctx.input_runtime.set(ctx.data.data(), ctx.data.size());
@ -117,8 +117,8 @@ void Controller::getPose(RuntimeContext& ctx, Ref<Pose> pose) {
auto root_bone_iter = ctx.model->getBoneIndex(ctx.root_bone_hash);
if (root_bone_iter.isValid()) {
const int root_bone_idx = root_bone_iter.value();
root_bind_pose.pos = pose->positions[root_bone_idx];
root_bind_pose.rot = pose->rotations[root_bone_idx];
root_bind_pose.pos = pose.positions[root_bone_idx];
root_bind_pose.rot = pose.rotations[root_bone_idx];
}
m_root->getPose(ctx, 1.f, pose, 0xffFFffFF);
@ -127,12 +127,12 @@ void Controller::getPose(RuntimeContext& ctx, Ref<Pose> pose) {
if (root_bone_iter.isValid()) {
const int root_bone_idx = root_bone_iter.value();
if (m_flags.isSet(Flags::XZ_ROOT_MOTION)) {
pose->positions[root_bone_idx].x = root_bind_pose.pos.x;
pose->positions[root_bone_idx].z = root_bind_pose.pos.z;
pose.positions[root_bone_idx].x = root_bind_pose.pos.x;
pose.positions[root_bone_idx].z = root_bind_pose.pos.z;
}
else {
pose->positions[root_bone_idx] = root_bind_pose.pos;
pose->rotations[root_bone_idx] = root_bind_pose.rot;
pose.positions[root_bone_idx] = root_bind_pose.pos;
pose.rotations[root_bone_idx] = root_bind_pose.rot;
}
}
}

View file

@ -26,8 +26,8 @@ public:
RuntimeContext* createRuntime(u32 anim_set);
void destroyRuntime(RuntimeContext& ctx);
void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const;
void getPose(RuntimeContext& ctx, Ref<struct Pose> pose);
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const;
void getPose(RuntimeContext& ctx, struct Pose& pose);
void initEmpty();
void destroy();

View file

@ -209,7 +209,7 @@ struct ControllerEditorImpl : ControllerEditor {
for (GroupNode::Child& c : group->m_children) {
if (c.node != &node) continue;
changed = conditionInput("Condition", m_controller->m_inputs, Ref(c.condition_str), Ref(c.condition)) || changed;
changed = conditionInput("Condition", m_controller->m_inputs, c.condition_str, c.condition) || changed;
break;
}
}
@ -282,7 +282,7 @@ struct ControllerEditorImpl : ControllerEditor {
IAllocator& allocator = m_app.getAllocator();
OutputMemoryStream data(allocator);
if (fs.getContentSync(Path(path), Ref(data))) {
if (fs.getContentSync(Path(path), data)) {
ResourceManager* res_manager = m_app.getEngine().getResourceManager().get(Controller::TYPE);
InputMemoryStream str(data);
UniquePtr<Controller> new_controller = UniquePtr<Controller>::create(allocator, Path("anim_editor"), *res_manager, allocator);
@ -301,23 +301,23 @@ struct ControllerEditorImpl : ControllerEditor {
}
}
static bool conditionInput(const char* label, InputDecl& input, Ref<String> condition_str, Ref<Condition> condition) {
static bool conditionInput(const char* label, InputDecl& input, String& condition_str, Condition& condition) {
char tmp[1024];
copyString(tmp, condition_str->c_str());
if (condition->error != Condition::Error::NONE) {
ImGui::TextUnformatted(Condition::errorToString(condition->error));
copyString(tmp, condition_str.c_str());
if (condition.error != Condition::Error::NONE) {
ImGui::TextUnformatted(Condition::errorToString(condition.error));
}
ImGuiEx::Label(label);
if (ImGui::InputText(StaticString<64>("##_", label), tmp, sizeof(tmp), ImGuiInputTextFlags_EnterReturnsTrue)) {
condition_str = tmp;
condition->compile(tmp, input);
condition.compile(tmp, input);
return true;
}
return false;
}
static bool nodeInput(const char* label, Ref<u32> value, const Array<GroupNode::Child>& children) {
static bool nodeInput(const char* label, u32& value, const Array<GroupNode::Child>& children) {
ImGuiEx::Label(label);
if (!ImGui::BeginCombo(StaticString<64>("##_", label), children[value].node->m_name.c_str())) return false;
@ -475,7 +475,7 @@ struct ControllerEditorImpl : ControllerEditor {
m_controller->serialize(str);
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (fs.open(path, Ref(file))) {
if (fs.open(path, file)) {
if (!file.write(str.data(), str.size())) {
logError("Failed to write ", path);
}
@ -782,15 +782,15 @@ struct ControllerEditorImpl : ControllerEditor {
if (!ImGui::TreeNodeEx(&tr, 0, "%s -> %s", name_from, name_to)) continue;
u32 from = u32(&child - children.begin());
if (nodeInput("From", Ref(from), children)) {
if (nodeInput("From", from, children)) {
children[from].transitions.push(tr);
child.transitions.erase(u32(&tr - child.transitions.begin()));
ImGui::TreePop();
break;
}
nodeInput("To", Ref(tr.to), children);
conditionInput("Condition", m_controller->m_inputs, Ref(tr.condition_str), Ref(tr.condition));
nodeInput("To", tr.to, children);
conditionInput("Condition", m_controller->m_inputs, tr.condition_str, tr.condition);
ImGui::TreePop();
}

View file

@ -144,7 +144,7 @@ static Blend1DActivePair getActivePair(const Blend1DNode& node, float input_val)
return { &children[0], nullptr, 0 };
}
void Blend1DNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const {
void Blend1DNode::update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const {
Time t = ctx.input_runtime.read<Time>();
const Time t0 = t;
t += ctx.time_delta;
@ -156,7 +156,7 @@ void Blend1DNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_moti
root_motion = getRootMotion(ctx, pair.a->slot, t0, t);
if (pair.b) {
const LocalRigidTransform tr1 = getRootMotion(ctx, pair.b->slot, t0, t);
root_motion = root_motion->interpolate(tr1, pair.t);
root_motion = root_motion.interpolate(tr1, pair.t);
}
}
@ -169,7 +169,7 @@ void Blend1DNode::skip(RuntimeContext& ctx) const {
ctx.input_runtime.skip(sizeof(Time));
}
static void getPose(const RuntimeContext& ctx, Time time, float weight, u32 slot, Ref<Pose> pose, u32 mask_idx, bool looped) {
static void getPose(const RuntimeContext& ctx, Time time, float weight, u32 slot, Pose& pose, u32 mask_idx, bool looped) {
Animation* anim = ctx.animations[slot];
if (!anim) return;
if (!ctx.model->isReady()) return;
@ -181,7 +181,7 @@ static void getPose(const RuntimeContext& ctx, Time time, float weight, u32 slot
anim->getRelativePose(anim_time, pose, *ctx.model, weight, mask);
}
void Blend1DNode::getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const {
void Blend1DNode::getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const {
const Time t = ctx.input_runtime.read<Time>();
if (m_children.empty()) return;
@ -219,7 +219,7 @@ AnimationNode::AnimationNode(GroupNode* parent, IAllocator& allocator)
: Node(parent, allocator)
{}
void AnimationNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const {
void AnimationNode::update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const {
Time t = ctx.input_runtime.read<Time>();
Time prev_t = t;
t += ctx.time_delta;
@ -251,7 +251,7 @@ void AnimationNode::skip(RuntimeContext& ctx) const {
ctx.input_runtime.skip(sizeof(Time));
}
void AnimationNode::getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const {
void AnimationNode::getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const {
const Time t = ctx.input_runtime.read<Time>();
anim::getPose(ctx, t, weight, m_slot, pose, mask, m_flags & LOOPED);
}
@ -281,10 +281,10 @@ LayersNode::LayersNode(GroupNode* parent, IAllocator& allocator)
{
}
void LayersNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const {
void LayersNode::update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const {
for (const Layer& layer : m_layers) {
LocalRigidTransform tmp_rm;
layer.node.update(ctx, Ref(tmp_rm));
layer.node.update(ctx, tmp_rm);
if (&layer == m_layers.begin()) {
root_motion = tmp_rm;
}
@ -303,7 +303,7 @@ void LayersNode::skip(RuntimeContext& ctx) const {
}
}
void LayersNode::getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const {
void LayersNode::getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const {
for (const Layer& layer : m_layers) {
layer.node.getPose(ctx, weight, pose, layer.mask);
}
@ -341,7 +341,7 @@ GroupNode::~GroupNode() {
}
}
void GroupNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const {
void GroupNode::update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const {
RuntimeData data = ctx.input_runtime.read<RuntimeData>();
if(data.from != data.to) {
@ -361,8 +361,8 @@ void GroupNode::update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion
m_children[data.from].node->update(ctx, root_motion);
LocalRigidTransform tmp;
m_children[data.to].node->update(ctx, Ref(tmp));
root_motion = root_motion->interpolate(tmp, data.t.seconds() / m_blend_length.seconds());
m_children[data.to].node->update(ctx, tmp);
root_motion = root_motion.interpolate(tmp, data.t.seconds() / m_blend_length.seconds());
return;
}
@ -422,7 +422,7 @@ void GroupNode::skip(RuntimeContext& ctx) const {
}
}
void GroupNode::getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const {
void GroupNode::getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const {
const RuntimeData data = ctx.input_runtime.read<RuntimeData>();
m_children[data.from].node->getPose(ctx, weight, pose, mask);

View file

@ -49,10 +49,10 @@ struct Node {
virtual ~Node() {}
virtual Type type() const = 0;
virtual void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const = 0;
virtual void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const = 0;
virtual void enter(RuntimeContext& ctx) const = 0;
virtual void skip(RuntimeContext& ctx) const = 0;
virtual void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const = 0;
virtual void getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const = 0;
virtual void serialize(OutputMemoryStream& stream) const = 0;
virtual void deserialize(InputMemoryStream& stream, Controller& ctrl) = 0;
@ -66,10 +66,10 @@ struct AnimationNode final : Node {
AnimationNode(GroupNode* parent, IAllocator& allocator);
Type type() const override { return ANIMATION; }
void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const override;
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const override;
void enter(RuntimeContext& ctx) const override;
void skip(RuntimeContext& ctx) const override;
void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const override;
void getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const override;
void serialize(OutputMemoryStream& stream) const override;
void deserialize(InputMemoryStream& stream, Controller& ctrl) override;
@ -85,10 +85,10 @@ struct Blend1DNode final : Node {
Blend1DNode(GroupNode* parent, IAllocator& allocator);
Type type() const override { return BLEND1D; }
void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const override;
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const override;
void enter(RuntimeContext& ctx) const override;
void skip(RuntimeContext& ctx) const override;
void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const override;
void getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const override;
void serialize(OutputMemoryStream& stream) const override;
void deserialize(InputMemoryStream& stream, Controller& ctrl) override;
@ -107,10 +107,10 @@ struct GroupNode final : Node {
~GroupNode();
Type type() const override { return GROUP; }
void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const override;
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const override;
void enter(RuntimeContext& ctx) const override;
void skip(RuntimeContext& ctx) const override;
void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const override;
void getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const override;
void serialize(OutputMemoryStream& stream) const override;
void deserialize(InputMemoryStream& stream, Controller& ctrl) override;
@ -159,10 +159,10 @@ struct LayersNode final : Node {
LayersNode(GroupNode* parent, IAllocator& allocator);
Type type() const override { return LAYERS; }
void update(RuntimeContext& ctx, Ref<LocalRigidTransform> root_motion) const override;
void update(RuntimeContext& ctx, LocalRigidTransform& root_motion) const override;
void enter(RuntimeContext& ctx) const override;
void skip(RuntimeContext& ctx) const override;
void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const override;
void getPose(RuntimeContext& ctx, float weight, Pose& pose, u32 mask) const override;
void serialize(OutputMemoryStream& stream) const override;
void deserialize(InputMemoryStream& stream, Controller& ctrl) override;

View file

@ -106,7 +106,7 @@ struct Runner final
bool loadUniverse(const char* path) {
FileSystem& fs = m_engine->getFileSystem();
OutputMemoryStream data(m_allocator);
if (!fs.getContentSync(Path(path), Ref(data))) return false;
if (!fs.getContentSync(Path(path), data)) return false;
InputMemoryStream tmp(data);
EntityMap entity_map(m_allocator);
@ -117,10 +117,10 @@ struct Runner final
u32 engine_hash;
} header;
tmp.read(Ref(header));
tmp.read(header);
m_universe->setName("main");
if (!m_engine->deserialize(*m_universe, tmp, Ref(entity_map))) {
if (!m_engine->deserialize(*m_universe, tmp, entity_map)) {
logError("Failed to deserialize ", path);
return false;
}
@ -227,7 +227,7 @@ int main(int args, char* argv[])
data->app.onInit();
while(!data->app.m_finished) {
os::Event e;
while(os::getEvent(Ref(e))) {
while(os::getEvent(e)) {
data->app.onEvent(e);
}
data->app.onIdle();

View file

@ -49,7 +49,7 @@ struct AssetBrowserPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
bool compile(const Path& src) override {
FileSystem& fs = m_app.getEngine().getFileSystem();
OutputMemoryStream src_data(m_app.getAllocator());
if (!fs.getContentSync(src, Ref(src_data))) return false;
if (!fs.getContentSync(src, src_data)) return false;
Meta meta = getMeta(src);

View file

@ -573,7 +573,7 @@ void AssetBrowser::fileColumn()
IScene* scene = universe->getScene(model_inst_type);
if (scene && universe->hasComponent(e, model_inst_type)) {
Path source;
if (reflection::getPropertyValue(*scene, e, model_inst_type, "Source", Ref(source))) {
if (reflection::getPropertyValue(*scene, e, model_inst_type, "Source", source)) {
copyString(Span(m_prefab_name), Path::getBasename(source.c_str()));
}
}
@ -948,7 +948,7 @@ bool AssetBrowser::resourceInput(const char* str_id, Span<char> buf, ResourceTyp
if (ImGuiEx::BeginResizablePopup("popup", ImVec2(300, 300))) {
static u32 selected_path_hash = 0;
if (resourceList(buf, Ref(selected_path_hash), type, 0, true)) {
if (resourceList(buf, selected_path_hash, type, 0, true)) {
ImGui::EndPopup();
ImGui::PopID();
return true;
@ -975,7 +975,7 @@ void AssetBrowser::endSaveResource(Resource& resource, OutputMemoryStream& strea
// use temporary because otherwise the resource is reloaded during saving
StaticString<LUMIX_MAX_PATH> tmp_path(resource.getPath().c_str(), ".tmp");
os::OutputFile f;
if (!fs.open(tmp_path, Ref(f)))
if (!fs.open(tmp_path, f))
{
LUMIX_DELETE(m_app.getAllocator(), &stream);
logError("Could not save file ", resource.getPath());
@ -1040,7 +1040,7 @@ void AssetBrowser::tile(const Path& path, bool selected) {
}
}
bool AssetBrowser::resourceList(Span<char> buf, Ref<u32> selected_path_hash, ResourceType type, float height, bool can_create_new) const {
bool AssetBrowser::resourceList(Span<char> buf, u32& selected_path_hash, ResourceType type, float height, bool can_create_new) const {
auto iter = m_plugins.find(type);
if (!iter.isValid()) return false;

View file

@ -57,7 +57,7 @@ public:
void removePlugin(IPlugin& plugin);
void openInExternalEditor(Resource* resource) const;
void openInExternalEditor(const char* path) const;
bool resourceList(Span<char> buf, Ref<u32> selected_idx, ResourceType type, float height, bool can_create_new) const;
bool resourceList(Span<char> buf, u32& selected_idx, ResourceType type, float height, bool can_create_new) const;
void tile(const Path& path, bool selected);
OutputMemoryStream* beginSaveResource(Resource& resource);
void endSaveResource(Resource& resource, OutputMemoryStream& file, bool success);

View file

@ -120,7 +120,7 @@ struct AssetCompilerImpl : AssetCompiler
{
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (fs.open(".lumix/assets/_list.txt_tmp", Ref(file))) {
if (fs.open(".lumix/assets/_list.txt_tmp", file)) {
file << "resources = {\n";
for (const ResourceItem& ri : m_resources) {
file << "\"" << ri.path.c_str() << "\",\n";
@ -182,7 +182,7 @@ struct AssetCompilerImpl : AssetCompiler
FileSystem& fs = m_app.getEngine().getFileSystem();
StaticString<LUMIX_MAX_PATH> out_path(".lumix/assets/", hash, ".res");
os::OutputFile file;
if(!fs.open(out_path, Ref(file))) {
if(!fs.open(out_path, file)) {
logError("Could not create ", out_path);
return false;
}
@ -310,7 +310,7 @@ struct AssetCompilerImpl : AssetCompiler
FileSystem& fs = m_app.getEngine().getFileSystem();
const StaticString<LUMIX_MAX_PATH> list_path(fs.getBasePath(), ".lumix/assets/_list.txt");
OutputMemoryStream content(m_app.getAllocator());
if (fs.getContentSync(Path(".lumix/assets/_list.txt"), Ref(content))) {
if (fs.getContentSync(Path(".lumix/assets/_list.txt"), content)) {
lua_State* L = luaL_newstate();
[&](){
if (luaL_loadbuffer(L, (const char*)content.data(), content.size(), "lumix_asset_list") != 0) {
@ -438,7 +438,7 @@ struct AssetCompilerImpl : AssetCompiler
FileSystem& fs = m_app.getEngine().getFileSystem();
OutputMemoryStream buf(m_app.getAllocator());
if (!fs.getContentSync(Path(meta_path), Ref(buf))) return false;
if (!fs.getContentSync(Path(meta_path), buf)) return false;
lua_State* L = luaL_newstate();
if (luaL_loadbuffer(L, (const char*)buf.data(), buf.size(), meta_path) != 0) {
@ -466,7 +466,7 @@ struct AssetCompilerImpl : AssetCompiler
const StaticString<LUMIX_MAX_PATH> meta_path(res.c_str(), ".meta");
FileSystem& fs = m_app.getEngine().getFileSystem();
if (!fs.open(meta_path, Ref(file))) {
if (!fs.open(meta_path, file)) {
logError("Could not create ", meta_path);
return;
}

View file

@ -1,4 +1,5 @@
#include "entity_folders.h"
#include "engine/string.h"
namespace Lumix {
@ -13,7 +14,7 @@ EntityFolders::EntityFolders(Universe& universe, IAllocator& allocator)
universe.entityCreated().bind<&EntityFolders::onEntityCreated>(this);
m_root = m_folder_allocator.alloc();
m_root->name = "root";
copyString(m_root->name, "root");
m_selected_folder = 0;
}
@ -117,7 +118,7 @@ EntityFolders::FolderID EntityFolders::emplaceFolder(FolderID folder, FolderID p
}
Folder& f = m_folder_allocator.getObject(folder);
f.name = "Folder";
copyString(f.name, "Folder");
f.parent_folder = parent;
Folder& p = m_folder_allocator.getObject(parent);
if (p.child_folder != INVALID_FOLDER) {

View file

@ -16,7 +16,7 @@ struct EntityFolders final {
FolderID next_folder = INVALID_FOLDER;
FolderID prev_folder = INVALID_FOLDER;
EntityPtr first_entity = INVALID_ENTITY;
StaticString<116> name;
char name[116];
};
struct Entity {

View file

@ -3,6 +3,7 @@
#include "engine/geometry.h"
#include "engine/math.h"
#include "engine/os.h"
#include "engine/string.h"
#include "engine/universe.h"
#include "render_interface.h"
@ -121,24 +122,24 @@ float getScale(const Viewport& viewport, const DVec3& pos, float base_scale) {
}
template <typename T>
T getGizmo(UniverseView& view, Ref<Transform> tr, const Gizmo::Config& cfg)
T getGizmo(UniverseView& view, Transform& tr, const Gizmo::Config& cfg)
{
T gizmo;
gizmo.pos = tr->pos;
gizmo.pos = tr.pos;
const float scale = getScale(view.getViewport(), tr->pos, cfg.scale);
const float scale = getScale(view.getViewport(), tr.pos, cfg.scale);
if (cfg.coord_system == Gizmo::Config::GLOBAL) {
gizmo.x = Vec3(scale, 0, 0);
gizmo.y = Vec3(0, scale, 0);
gizmo.z = Vec3(0, 0, scale);
}
else {
gizmo.x = tr->rot.rotate(Vec3(scale, 0, 0));
gizmo.y = tr->rot.rotate(Vec3(0, scale, 0));
gizmo.z = tr->rot.rotate(Vec3(0, 0, scale));
gizmo.x = tr.rot.rotate(Vec3(scale, 0, 0));
gizmo.y = tr.rot.rotate(Vec3(0, scale, 0));
gizmo.z = tr.rot.rotate(Vec3(0, 0, scale));
}
const Vec3 cam_dir = normalize(Vec3(tr->pos - view.getViewport().pos));
const Vec3 cam_dir = normalize(Vec3(tr.pos - view.getViewport().pos));
if (dot(cam_dir, gizmo.x) > 0) gizmo.x = -gizmo.x;
if (dot(cam_dir, gizmo.y) > 0) gizmo.y = -gizmo.y;
if (dot(cam_dir, gizmo.z) > 0) gizmo.z = -gizmo.z;
@ -543,8 +544,8 @@ void setDragged(u64 id) {
g_gizmo_state.dragged_id = id;
}
bool translate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config& cfg) {
const float scale = getScale(view.getViewport(), tr->pos, cfg.scale);
bool translate(u64 id, UniverseView& view, Transform& tr, const Gizmo::Config& cfg) {
const float scale = getScale(view.getViewport(), tr.pos, cfg.scale);
TranslationGizmo gizmo = getGizmo<TranslationGizmo>(view, tr, cfg);
const bool none_active = g_gizmo_state.dragged_id == ~(u64)0;
@ -578,11 +579,11 @@ bool translate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Confi
const DVec3 pos = getMousePlaneIntersection(view, gizmo, g_gizmo_state.axis);
const Vec3 delta_vec = Vec3(pos - g_gizmo_state.prev_point);
DVec3 res = tr->pos + delta_vec;
DVec3 res = tr.pos + delta_vec;
auto print_delta = [&](){
const Vec2 p = view.getViewport().worldToScreenPixels(gizmo.pos);
const Vec3 from_start = Vec3(tr->pos - g_gizmo_state.start_pos);
const Vec3 from_start = Vec3(tr.pos - g_gizmo_state.start_pos);
StaticString<128> tmp("", from_start.x, "; ", from_start.y, "; ", from_start.z);
view.addText2D(p.x + 31, p.y + 31, 0xff000000, tmp);
view.addText2D(p.x + 30, p.y + 30, 0xffffFFFF, tmp);
@ -590,7 +591,7 @@ bool translate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Confi
if (!cfg.is_step || cfg.getStep() <= 0) {
g_gizmo_state.prev_point = pos;
tr->pos = res;
tr.pos = res;
print_delta();
return squaredLength(delta_vec) > 0.f;
}
@ -599,9 +600,9 @@ bool translate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Confi
res.x = double(i64((res.x + signum(res.x) * step * 0.5f) / step)) * step;
res.y = double(i64((res.y + signum(res.y) * step * 0.5f) / step)) * step;
res.z = double(i64((res.z + signum(res.z) * step * 0.5f) / step)) * step;
if (res.x != tr->pos.x || res.y != tr->pos.y || res.z != tr->pos.z) {
if (res.x != tr.pos.x || res.y != tr.pos.y || res.z != tr.pos.z) {
g_gizmo_state.prev_point = res;
tr->pos = res;
tr.pos = res;
print_delta();
return true;
}
@ -609,7 +610,7 @@ bool translate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Confi
return false;
}
bool scale(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config& cfg) {
bool scale(u64 id, UniverseView& view, Transform& tr, const Gizmo::Config& cfg) {
ScaleGizmo gizmo = getGizmo<ScaleGizmo>(view, tr, cfg);
const bool none_active = g_gizmo_state.dragged_id == ~(u64)0;
@ -645,14 +646,14 @@ bool scale(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config& c
draw(view, gizmo, g_gizmo_state.axis, cfg);
if (squaredLength(delta) > 0) {
g_gizmo_state.prev_point = p;
tr->scale += length(delta) * sign;
tr.scale += length(delta) * sign;
return true;
}
return false;
}
bool rotate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config& cfg) {
bool rotate(u64 id, UniverseView& view, Transform& tr, const Gizmo::Config& cfg) {
RotationGizmo gizmo = getGizmo<RotationGizmo>(view, tr, cfg);
const bool none_active = g_gizmo_state.dragged_id == ~(u64)0;
@ -671,7 +672,7 @@ bool rotate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config&
g_gizmo_state.dragged_id = id;
g_gizmo_state.axis = axis;
g_gizmo_state.prev_point = getMousePlaneIntersection(view, gizmo, toPlane(axis));
g_gizmo_state.start_rot = tr->rot;
g_gizmo_state.start_rot = tr.rot;
}
return false;
}
@ -696,13 +697,13 @@ bool rotate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config&
}
if (!cfg.is_step || cfg.getStep() <= 0) {
tr->rot = normalize(Quat(normalize(normal), angle) * g_gizmo_state.start_rot);
tr.rot = normalize(Quat(normalize(normal), angle) * g_gizmo_state.start_rot);
return true;
}
if (cfg.is_step && fabs(angle) > degreesToRadians(cfg.getStep())) {
angle = angle - fmodf(angle, degreesToRadians(cfg.getStep()));
tr->rot = normalize(Quat(normalize(normal), angle) * g_gizmo_state.start_rot);
tr.rot = normalize(Quat(normalize(normal), angle) * g_gizmo_state.start_rot);
return true;
}
}
@ -713,18 +714,18 @@ bool rotate(u64 id, UniverseView& view, Ref<Transform> tr, const Gizmo::Config&
bool isActive() { return g_gizmo_state.active_id != ~(u64)0 || g_gizmo_state.dragged_id != ~(u64)0; }
bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents, const Config& cfg, bool keep_center) {
bool box(u64 id, UniverseView& view, Transform& tr, Vec3& half_extents, const Config& cfg, bool keep_center) {
id |= u64(0xff) << 56;
const Vec3 xn = tr->rot.rotate(Vec3(1, 0, 0));
const Vec3 yn = tr->rot.rotate(Vec3(0, 1, 0));
const Vec3 zn = tr->rot.rotate(Vec3(0, 0, 1));
const Vec3 x = xn * half_extents->x;
const Vec3 y = yn * half_extents->y;
const Vec3 z = zn * half_extents->z;
addCube(view, tr->pos, x, y, z, Color::BLUE);
const Vec3 xn = tr.rot.rotate(Vec3(1, 0, 0));
const Vec3 yn = tr.rot.rotate(Vec3(0, 1, 0));
const Vec3 zn = tr.rot.rotate(Vec3(0, 0, 1));
const Vec3 x = xn * half_extents.x;
const Vec3 y = yn * half_extents.y;
const Vec3 z = zn * half_extents.z;
addCube(view, tr.pos, x, y, z, Color::BLUE);
const Viewport vp = view.getViewport();
const float scale = getScale(vp, tr->pos, cfg.scale) * 0.1f;
const float scale = getScale(vp, tr.pos, cfg.scale) * 0.1f;
DVec3 origin;
Vec3 dir;
@ -737,11 +738,11 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
u32 zp_color = X_COLOR;
u32 zn_color = X_COLOR;
const Vec3 pos = Vec3(origin - tr->pos);
const Vec3 center = Vec3(tr->pos - vp.pos);
auto cube = [&](u32 color, Vec3 p, Ref<float> prev_t){
const Vec3 pos = Vec3(origin - tr.pos);
const Vec3 center = Vec3(tr.pos - vp.pos);
auto cube = [&](u32 color, Vec3 p, float& prev_t){
float t;
if (getRaySphereIntersection(pos, dir, p, scale * 1.414f, Ref(t)) && (prev_t.value < 0 || t < prev_t.value)) {
if (getRaySphereIntersection(pos, dir, p, scale * 1.414f, t) && (prev_t < 0 || t < prev_t)) {
renderCube(view, SELECTED_COLOR, center + p, scale, xn, yn, zn);
UniverseView::Vertex* line = view.render(true, 2);
line[0].pos = center;
@ -761,12 +762,12 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
BoxAxis axis = BoxAxis::NONE;
float t = -1;
if (cube(X_COLOR, x, Ref(t))) axis = BoxAxis::XP;
if (cube(X_COLOR, -x, Ref(t))) axis = BoxAxis::XN;
if (cube(Y_COLOR, y, Ref(t))) axis = BoxAxis::YP;
if (cube(Y_COLOR, -y, Ref(t))) axis = BoxAxis::YN;
if (cube(Z_COLOR, z, Ref(t))) axis = BoxAxis::ZP;
if (cube(Z_COLOR, -z, Ref(t))) axis = BoxAxis::ZN;
if (cube(X_COLOR, x, t)) axis = BoxAxis::XP;
if (cube(X_COLOR, -x, t)) axis = BoxAxis::XN;
if (cube(Y_COLOR, y, t)) axis = BoxAxis::YP;
if (cube(Y_COLOR, -y, t)) axis = BoxAxis::YN;
if (cube(Z_COLOR, z, t)) axis = BoxAxis::ZP;
if (cube(Z_COLOR, -z, t)) axis = BoxAxis::ZN;
if (axis != BoxAxis::NONE) g_gizmo_state.active_id = id;
BoxGizmo gizmo = getGizmo<BoxGizmo>(view, tr, cfg);
@ -808,13 +809,13 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
const DVec3 e0 = g_gizmo_state.box.start_transform.pos - xn * g_gizmo_state.box.start_half_extents.x * sign;
if (keep_center) {
const float half = g_gizmo_state.box.start_half_extents.x + dot(diff, xn) * sign;
half_extents->x = half;
half_extents.x = half;
}
else {
const float half = g_gizmo_state.box.start_half_extents.x + dot(diff, xn) * 0.5f * sign;
const DVec3 c = e0 + xn * half * sign;
tr->pos = c;
half_extents->x = half;
tr.pos = c;
half_extents.x = half;
}
return true;
}
@ -824,13 +825,13 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
const DVec3 e0 = g_gizmo_state.box.start_transform.pos - yn * g_gizmo_state.box.start_half_extents.y * sign;
if (keep_center) {
const float half = g_gizmo_state.box.start_half_extents.y + dot(diff, yn) * sign;
half_extents->y = half;
half_extents.y = half;
}
else {
const float half = g_gizmo_state.box.start_half_extents.y + dot(diff, yn) * 0.5f * sign;
const DVec3 c = e0 + yn * half * sign;
tr->pos = c;
half_extents->y = half;
tr.pos = c;
half_extents.y = half;
}
return true;
}
@ -840,13 +841,13 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
const DVec3 e0 = g_gizmo_state.box.start_transform.pos - zn * g_gizmo_state.box.start_half_extents.z * sign;
if (keep_center) {
const float half = g_gizmo_state.box.start_half_extents.z + dot(diff, zn) * sign;
half_extents->z = half;
half_extents.z = half;
}
else {
const float half = g_gizmo_state.box.start_half_extents.z + dot(diff, zn) * 0.5f * sign;
const DVec3 c = e0 + zn * half * sign;
tr->pos = c;
half_extents->z = half;
tr.pos = c;
half_extents.z = half;
}
return true;
}
@ -856,7 +857,7 @@ bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents,
}
bool manipulate(u64 id, UniverseView& view, Ref<Transform> tr, const Config& cfg) {
bool manipulate(u64 id, UniverseView& view, Transform& tr, const Config& cfg) {
g_gizmo_state.last_manipulate_frame = g_gizmo_state.frame;
switch (cfg.mode) {
case Gizmo::Config::TRANSLATE: return translate(id, view, tr, cfg);

View file

@ -49,8 +49,8 @@ struct LUMIX_EDITOR_API Config {
void setOffset(Vec3 val) { offset = val; }
};
LUMIX_EDITOR_API bool manipulate(u64 id, UniverseView& view, Ref<Transform> tr, const Config& cfg);
LUMIX_EDITOR_API bool box(u64 id, UniverseView& view, Ref<Transform> tr, Ref<Vec3> half_extents, const Config& cfg, bool keep_center);
LUMIX_EDITOR_API bool manipulate(u64 id, UniverseView& view, Transform& tr, const Config& cfg);
LUMIX_EDITOR_API bool box(u64 id, UniverseView& view, Transform& tr, Vec3& half_extents, const Config& cfg, bool keep_center);
LUMIX_EDITOR_API void setDragged(u64 id);
LUMIX_EDITOR_API bool isActive();
LUMIX_EDITOR_API void frame();

View file

@ -97,7 +97,7 @@ struct PrefabSystemImpl final : PrefabSystem
ASSERT(prefab.isReady());
auto& system = (PrefabSystemImpl&)editor.getPrefabSystem();
system.doInstantiatePrefabs(prefab, transforms, Ref(entities));
system.doInstantiatePrefabs(prefab, transforms, entities);
if (output) {
*output = entities[0];
output = nullptr;
@ -222,7 +222,7 @@ public:
}
void doInstantiatePrefabs(PrefabResource& prefab_res, const Array<Transform>& transforms, Ref<Array<EntityRef>> entities)
void doInstantiatePrefabs(PrefabResource& prefab_res, const Array<Transform>& transforms, Array<EntityRef>& entities)
{
ASSERT(prefab_res.isReady());
if (!m_resources.find(prefab_res.getPath().getHash()).isValid())
@ -238,7 +238,7 @@ public:
for (const Transform& tr : transforms) {
entity_map.m_map.clear();
if (!engine.instantiatePrefab(*m_universe, prefab_res, tr.pos, tr.rot, tr.scale, Ref(entity_map))) {
if (!engine.instantiatePrefab(*m_universe, prefab_res, tr.pos, tr.rot, tr.scale, entity_map)) {
logError("Failed to instantiate prefab ", prefab_res.getPath());
return;
}
@ -249,7 +249,7 @@ public:
const EntityRef root = (EntityRef)entity_map.m_map[0];
m_roots.insert(root, prefab);
entities->push(root);
entities.push(root);
}
}
@ -264,7 +264,7 @@ public:
}
EntityMap entity_map(m_editor.getAllocator());
if (!m_editor.getEngine().instantiatePrefab(*m_universe, prefab_res, pos, rot, scale, Ref(entity_map))) {
if (!m_editor.getEngine().instantiatePrefab(*m_universe, prefab_res, pos, rot, scale, entity_map)) {
logError("Failed to instantiate prefab ", prefab_res.getPath());
return INVALID_ENTITY;
}
@ -383,8 +383,8 @@ public:
};
EntityRef cloneEntity(Universe& src_u, EntityRef src_e, Universe& dst_u, EntityPtr dst_parent, Ref<Array<EntityRef>> entities, const HashMap<EntityPtr, EntityPtr>& map) {
entities->push(src_e);
EntityRef cloneEntity(Universe& src_u, EntityRef src_e, Universe& dst_u, EntityPtr dst_parent, Array<EntityRef>& entities, const HashMap<EntityPtr, EntityPtr>& map) {
entities.push(src_e);
const EntityRef dst_e = (EntityRef)map[src_e];
if (dst_parent.isValid()) {
dst_u.setParent(dst_parent, dst_e);
@ -425,12 +425,12 @@ public:
return dst_e;
}
void cloneHierarchy(const Universe& src, EntityRef src_e, Universe& dst, bool clone_siblings, Ref<HashMap<EntityPtr, EntityPtr>> map) {
void cloneHierarchy(const Universe& src, EntityRef src_e, Universe& dst, bool clone_siblings, HashMap<EntityPtr, EntityPtr>& map) {
const EntityPtr child = src.getFirstChild(src_e);
const EntityPtr sibling = src.getNextSibling(src_e);
const EntityRef dst_e = dst.createEntity({0, 0, 0}, Quat::IDENTITY);
map->insert(src_e, dst_e);
map.insert(src_e, dst_e);
if (child.isValid()) {
cloneHierarchy(src, (EntityRef)child, dst, true, map);
@ -440,14 +440,14 @@ public:
}
}
Universe& createPrefabUniverse(EntityRef src_e, Ref<Array<EntityRef>> entities) {
Universe& createPrefabUniverse(EntityRef src_e, Array<EntityRef>& entities) {
Engine& engine = m_editor.getEngine();
Universe& dst = engine.createUniverse(false);
Universe& src = *m_editor.getUniverse();
HashMap<EntityPtr, EntityPtr> map(m_editor.getAllocator());
map.reserve(256);
cloneHierarchy(src, src_e, dst, false, Ref(map));
cloneHierarchy(src, src_e, dst, false, map);
cloneEntity(src, src_e, dst, INVALID_ENTITY, entities, map);
return dst;
}
@ -497,7 +497,7 @@ public:
Engine& engine = m_editor.getEngine();
FileSystem& fs = engine.getFileSystem();
os::OutputFile file;
if (!fs.open(path.c_str(), Ref(file)))
if (!fs.open(path.c_str(), file))
{
logError("Failed to create ", path);
return;
@ -507,7 +507,7 @@ public:
blob.reserve(4096);
Array<EntityRef> src_entities(m_editor.getAllocator());
src_entities.reserve(256);
Universe& prefab_universe = createPrefabUniverse(entity, Ref(src_entities));
Universe& prefab_universe = createPrefabUniverse(entity, src_entities);
engine.serialize(prefab_universe, blob);
engine.destroyUniverse(prefab_universe);

View file

@ -58,11 +58,11 @@ struct ThreadContextProxy {
{
InputMemoryStream blob(ptr, 9000);
name = blob.readString();
blob.read(Ref(thread_id));
blob.read(Ref(begin));
blob.read(Ref(end));
blob.read(thread_id);
blob.read(begin);
blob.read(end);
default_show = blob.read<u8>();
blob.read(Ref(buffer_size));
blob.read(buffer_size);
buffer = (u8*)blob.getData() + blob.getPosition();
}
@ -571,7 +571,7 @@ void ProfilerUIImpl::showAllocationTree(AllocationStackNode* node, int column) c
{
char fn_name[100];
int line;
if (debug::StackTree::getFunction(node->m_stack_node, Span(fn_name), Ref(line)))
if (debug::StackTree::getFunction(node->m_stack_node, Span(fn_name), line))
{
if (line >= 0)
{

View file

@ -642,7 +642,7 @@ static bool componentTreeNode(StudioApp& app, WorldEditor& editor, ComponentType
bool is_open;
bool enabled = true;
IScene* scene = editor.getUniverse()->getScene(cmp_type);
if (entities_count == 1 && reflection::getPropertyValue(*scene, entities[0], cmp_type, "Enabled", Ref(enabled))) {
if (entities_count == 1 && reflection::getPropertyValue(*scene, entities[0], cmp_type, "Enabled", enabled)) {
is_open = ImGui::TreeNodeEx((void*)(uintptr)cmp_type.index, flags, "%s", "");
ImGui::SameLine();
ComponentUID cmp;

View file

@ -186,18 +186,18 @@ static void saveStyle(os::OutputFile& file)
}
static bool shortcutInput(Ref<Action> action, bool edit)
static bool shortcutInput(Action& action, bool edit)
{
char button_label[64];
action->shortcutText(Span(button_label));
action.shortcutText(Span(button_label));
bool res = false;
ImGui::SetNextItemWidth(-30);
ImGui::InputText("", button_label, sizeof(button_label), ImGuiInputTextFlags_ReadOnly);
if (ImGui::IsItemActive()) {
if (os::isKeyDown(os::Keycode::SHIFT)) action->modifiers |= (u8)Action::Modifiers::SHIFT;
if (os::isKeyDown(os::Keycode::MENU)) action->modifiers |= (u8)Action::Modifiers::ALT;
if (os::isKeyDown(os::Keycode::CTRL)) action->modifiers |= (u8)Action::Modifiers::CTRL;
if (os::isKeyDown(os::Keycode::SHIFT)) action.modifiers |= (u8)Action::Modifiers::SHIFT;
if (os::isKeyDown(os::Keycode::MENU)) action.modifiers |= (u8)Action::Modifiers::ALT;
if (os::isKeyDown(os::Keycode::CTRL)) action.modifiers |= (u8)Action::Modifiers::CTRL;
for (int i = 0; i < (int)os::Keycode::MAX; ++i) {
const auto kc= (os::Keycode)i;
@ -212,15 +212,15 @@ static bool shortcutInput(Ref<Action> action, bool edit)
|| kc == os::Keycode::LCTRL
|| kc == os::Keycode::RCTRL;
if (os::isKeyDown(kc) && !is_mouse && !is_modifier) {
action->shortcut = (os::Keycode)i;
action.shortcut = (os::Keycode)i;
break;
}
}
}
ImGui::SameLine();
if (ImGuiEx::IconButton(ICON_FA_TRASH, "Clear")) {
action->modifiers = 0;
action->shortcut = os::Keycode::INVALID;
action.modifiers = 0;
action.shortcut = os::Keycode::INVALID;
}
return res;
@ -320,7 +320,7 @@ bool Settings::load()
const char* path = has_settings ? SETTINGS_PATH : DEFAULT_SETTINGS_PATH;
OutputMemoryStream buf(m_app.getAllocator());
if (!fs.getContentSync(Path(path), Ref(buf))) {
if (!fs.getContentSync(Path(path), buf)) {
logError("Failed to open ", path);
return false;
}
@ -339,7 +339,7 @@ bool Settings::load()
lua_pop(L, 1);
if (!valid_version) {
if (!fs.getContentSync(Path(DEFAULT_SETTINGS_PATH), Ref(buf))) {
if (!fs.getContentSync(Path(DEFAULT_SETTINGS_PATH), buf)) {
logError("Failed to open ", DEFAULT_SETTINGS_PATH);
return false;
}
@ -483,7 +483,7 @@ bool Settings::save()
auto& actions = m_app.getActions();
os::OutputFile file;
FileSystem& fs = m_app.getEngine().getFileSystem();
if (!fs.open(SETTINGS_PATH, Ref(file))) return false;
if (!fs.open(SETTINGS_PATH, file)) return false;
file << "version = 1\n";
@ -579,7 +579,7 @@ void Settings::showShortcutSettings()
{
ImGui::PushID(&a);
ImGuiEx::Label(a.label_long.data);
if (shortcutInput(Ref(a), &a == m_edit_action)) {
if (shortcutInput(a, &a == m_edit_action)) {
m_edit_action = &a;
}
ImGui::PopID();

View file

@ -193,7 +193,7 @@ struct StudioAppImpl final : StudioApp
{
u32 cpus_count = minimum(os::getCPUsCount(), 64);
u32 workers;
if (workersCountOption(Ref(workers))) {
if (workersCountOption(workers)) {
cpus_count = workers;
}
if (!jobs::init(cpus_count, m_allocator)) {
@ -331,7 +331,7 @@ struct StudioAppImpl final : StudioApp
data->that->onInit();
while (!data->that->m_finished) {
os::Event e;
while(os::getEvent(Ref(e))) {
while(os::getEvent(e)) {
data->that->onEvent(e);
}
data->that->onIdle();
@ -503,7 +503,7 @@ struct StudioAppImpl final : StudioApp
bool makeFile(const char* path, const char* content) override
{
os::OutputFile file;
if (!m_engine->getFileSystem().open(path, Ref(file))) return false;
if (!m_engine->getFileSystem().open(path, file)) return false;
file << content;
file.close();
return file.isError();
@ -610,7 +610,7 @@ struct StudioAppImpl final : StudioApp
char buf[LUMIX_MAX_PATH];
bool create_empty = ImGui::MenuItem("Empty");
static u32 selected_res_hash = 0;
if (asset_browser->resourceList(Span(buf), Ref(selected_res_hash), resource_type, 0, true) || create_empty) {
if (asset_browser->resourceList(Span(buf), selected_res_hash, resource_type, 0, true) || create_empty) {
if (create_entity) {
EntityRef entity = editor->addEntity();
editor->selectEntities(Span(&entity, 1), false);
@ -924,7 +924,7 @@ struct StudioAppImpl final : StudioApp
const u8* ptr = (const u8*)str.getData() + str.getPosition();
str.read(&header, sizeof(header));
u32 size;
fromCStringOctal(Span(header.size, sizeof(header.size)), Ref(size));
fromCStringOctal(Span(header.size, sizeof(header.size)), size);
if (header.name[0] && header.typeflag == 0 || header.typeflag == '0') {
const StaticString<LUMIX_MAX_PATH> path(m_engine->getFileSystem().getBasePath(), "/", header.name);
char dir[LUMIX_MAX_PATH];
@ -1826,7 +1826,7 @@ struct StudioAppImpl final : StudioApp
ImGui::PopStyleColor();
}
else {
node_open = ImGui::TreeNodeEx((void*)&folder, flags, "%s%s", ICON_FA_FOLDER, folder.name.data);
node_open = ImGui::TreeNodeEx((void*)&folder, flags, "%s%s", ICON_FA_FOLDER, folder.name);
}
if (ImGui::BeginDragDropTarget()) {
@ -1998,7 +1998,7 @@ struct StudioAppImpl final : StudioApp
ImFont* addFontFromFile(const char* path, float size, bool merge_icons) {
FileSystem& fs = m_engine->getFileSystem();
OutputMemoryStream data(m_allocator);
if (!fs.getContentSync(Path(path), Ref(data))) return nullptr;
if (!fs.getContentSync(Path(path), data)) return nullptr;
ImGuiIO& io = ImGui::GetIO();
ImFontConfig cfg;
copyString(cfg.Name, path);
@ -2012,13 +2012,13 @@ struct StudioAppImpl final : StudioApp
config.GlyphMinAdvanceX = size; // Use if you want to make the icon monospaced
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
OutputMemoryStream icons_data(m_allocator);
if (fs.getContentSync(Path("editor/fonts/fa-regular-400.ttf"), Ref(icons_data))) {
if (fs.getContentSync(Path("editor/fonts/fa-regular-400.ttf"), icons_data)) {
ImFont* icons_font = io.Fonts->AddFontFromMemoryTTF((void*)icons_data.data(), (i32)icons_data.size(), size * 0.75f, &config, icon_ranges);
ASSERT(icons_font);
}
copyString(config.Name, "editor/fonts/fa-solid-900.ttf");
icons_data.clear();
if (fs.getContentSync(Path("editor/fonts/fa-solid-900.ttf"), Ref(icons_data))) {
if (fs.getContentSync(Path("editor/fonts/fa-solid-900.ttf"), icons_data)) {
ImFont* icons_font = io.Fonts->AddFontFromMemoryTTF((void*)icons_data.data(), (i32)icons_data.size(), size * 0.75f, &config, icon_ranges);
ASSERT(icons_font);
}
@ -2140,7 +2140,7 @@ struct StudioAppImpl final : StudioApp
m_bold_font = addFontFromFile("editor/fonts/NotoSans-Bold.ttf", (float)m_settings.m_font_size * font_scale, true);
OutputMemoryStream data(m_allocator);
if (fs.getContentSync(Path("editor/fonts/fa-solid-900.ttf"), Ref(data))) {
if (fs.getContentSync(Path("editor/fonts/fa-solid-900.ttf"), data)) {
const float size = (float)m_settings.m_font_size * font_scale * 1.25f;
ImFontConfig cfg;
copyString(cfg.Name, "editor/fonts/fa-solid-900.ttf");
@ -2150,7 +2150,7 @@ struct StudioAppImpl final : StudioApp
m_big_icon_font = io.Fonts->AddFontFromMemoryTTF((void*)data.data(), (i32)data.size(), size, &cfg, icon_ranges);
cfg.MergeMode = true;
copyString(cfg.Name, "editor/fonts/fa-regular-400.ttf");
if (fs.getContentSync(Path("editor/fonts/fa-regular-400.ttf"), Ref(data))) {
if (fs.getContentSync(Path("editor/fonts/fa-regular-400.ttf"), data)) {
ImFont* icons_font = io.Fonts->AddFontFromMemoryTTF((void*)data.data(), (i32)data.size(), size, &cfg, icon_ranges);
ASSERT(icons_font);
}
@ -2473,7 +2473,7 @@ struct StudioAppImpl final : StudioApp
ASSERT(false);
}
bool workersCountOption(Ref<u32> workers_count) {
bool workersCountOption(u32& workers_count) {
char cmd_line[2048];
os::getCommandLine(Span(cmd_line));
@ -2968,7 +2968,7 @@ struct StudioAppImpl final : StudioApp
parser.getCurrent(tmp, lengthOf(tmp));
OutputMemoryStream content(m_allocator);
if (m_engine->getFileSystem().getContentSync(Path(tmp), Ref(content))) {
if (m_engine->getFileSystem().getContentSync(Path(tmp), content)) {
content.write('\0');
runScript((const char*)content.data(), tmp);
}
@ -3020,7 +3020,7 @@ struct StudioAppImpl final : StudioApp
Span<const char> basename = Path::getBasename(info.filename);
PackFileInfo rec;
fromCString(Span(basename), Ref(rec.hash));
fromCString(Span(basename), rec.hash);
rec.offset = 0;
rec.size = os::getFileSize(StaticString<LUMIX_MAX_PATH>(base_path, ".lumix/assets/", info.filename));
copyString(rec.path, ".lumix/assets/");
@ -3157,7 +3157,7 @@ struct StudioAppImpl final : StudioApp
OutputMemoryStream src(m_allocator);
u64 total_size = 0;
for (auto& info : infos) {
if (!fs.getContentSync(Path(info.path), Ref(src))) {
if (!fs.getContentSync(Path(info.path), src)) {
logError("Could not open ", info.path);
return;
}
@ -3234,7 +3234,7 @@ struct StudioAppImpl final : StudioApp
StaticString<LUMIX_MAX_PATH> path(dir, filename);
OutputMemoryStream src(m_engine->getAllocator());
if (m_engine->getFileSystem().getContentSync(Path(path), Ref(src))) {
if (m_engine->getFileSystem().getContentSync(Path(path), src)) {
LuaPlugin* plugin = LUMIX_NEW(m_editor->getAllocator(), LuaPlugin)(*this, Span((const char*)src.data(), (u32)src.size()), filename);
addPlugin(*plugin);
}

View file

@ -86,7 +86,7 @@ void Action::init(const char* label_short,
is_selected.bind<falseConst>();
}
bool Action::shortcutText(Span<char> out) {
bool Action::shortcutText(Span<char> out) const {
if (shortcut == os::Keycode::INVALID && modifiers == 0) {
copyString(out, "");
return false;

View file

@ -28,7 +28,7 @@ struct LUMIX_EDITOR_API Action
void init(const char* label_short, const char* label_long, const char* name, const char* font_icon, bool is_global);
bool toolbarButton(struct ImFont* font);
bool isActive();
bool shortcutText(Span<char> out);
bool shortcutText(Span<char> out) const;
static bool falseConst() { return false; }

View file

@ -23,6 +23,7 @@
#include "engine/resource.h"
#include "engine/resource_manager.h"
#include "engine/stream.h"
#include "engine/string.h"
#include "engine/universe.h"
#include "render_interface.h"
@ -387,11 +388,11 @@ template <> void writeToStream<const char*>(OutputMemoryStream& stream, const ch
struct PropertyDeserializeVisitor : reflection::IPropertyVisitor {
PropertyDeserializeVisitor(Ref<InputMemoryStream> deserializer
PropertyDeserializeVisitor(InputMemoryStream& deserializer
, ComponentUID cmp
, const HashMap<EntityPtr, u32>& map
, Span<const EntityRef> entities)
: deserializer(deserializer.value) //-V1041
: deserializer(deserializer) //-V1041
, cmp(cmp)
, map(map)
, entities(entities)
@ -442,7 +443,7 @@ struct PropertyDeserializeVisitor : reflection::IPropertyVisitor {
void visit(const reflection::Property<EntityPtr>& prop) override {
EntityPtr value;
deserializer.read(Ref(value));
deserializer.read(value);
auto iter = map.find(value);
if (iter.isValid()) value = entities[iter.value()];
@ -451,7 +452,7 @@ struct PropertyDeserializeVisitor : reflection::IPropertyVisitor {
void visit(const reflection::ArrayProperty& prop) override {
u32 count;
deserializer.read(Ref(count));
deserializer.read(count);
const int idx_backup = idx;
while (prop.getCount(cmp) > count) {
prop.removeItem(cmp, prop.getCount(cmp) - 1);
@ -474,8 +475,8 @@ struct PropertyDeserializeVisitor : reflection::IPropertyVisitor {
};
struct PropertySerializeVisitor : reflection::IPropertyVisitor {
PropertySerializeVisitor(Ref<OutputMemoryStream> serializer, ComponentUID cmp)
: serializer(serializer.value) //-V1041
PropertySerializeVisitor(OutputMemoryStream& serializer, ComponentUID cmp)
: serializer(serializer) //-V1041
, cmp(cmp)
{}
@ -535,13 +536,13 @@ struct PropertySerializeVisitor : reflection::IPropertyVisitor {
};
static void save(ComponentUID cmp, Ref<OutputMemoryStream> out) {
static void save(ComponentUID cmp, OutputMemoryStream& out) {
PropertySerializeVisitor save(out, cmp);
save.idx = -1;
reflection::getComponent(cmp.type)->visit(save);
}
static void load(ComponentUID cmp, Ref<InputMemoryStream> blob)
static void load(ComponentUID cmp, InputMemoryStream& blob)
{
struct : IAllocator {
void* allocate(size_t size) override { ASSERT(false); return nullptr; }
@ -1004,7 +1005,7 @@ public:
, m_property(property, editor.getAllocator())
, m_old_values(editor.getAllocator())
{
save(m_component, Ref(m_old_values));
save(m_component, m_old_values);
}
@ -1030,7 +1031,7 @@ public:
void undo() override
{
InputMemoryStream old_values(m_old_values);
load(m_component, Ref(old_values));
load(m_component, old_values);
}
@ -1159,7 +1160,7 @@ public:
ComponentUID component = universe->getComponent(entities[i], component_type);
if (!component.isValid()) continue;
PropertySerializeVisitor v(Ref<OutputMemoryStream>(m_old_values), component);
PropertySerializeVisitor v(m_old_values, component);
v.idx = -1;
cmp_desc->visit(v);
m_entities.push(entities[i]);
@ -1167,15 +1168,15 @@ public:
}
template <typename T2> static void set(Ref<reflection::DynamicProperties::Value> v, T2) { ASSERT(false); }
static void set(Ref<reflection::DynamicProperties::Value> v, i32 val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, float val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, const Path& val) { reflection::set(v.value, val.c_str()); }
static void set(Ref<reflection::DynamicProperties::Value> v, const char* val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, EntityPtr val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, bool val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, Vec3 val) { reflection::set(v.value, val); }
static void set(Ref<reflection::DynamicProperties::Value> v, const String& val) { reflection::set(v.value, val.c_str()); }
template <typename T2> static void set(reflection::DynamicProperties::Value& v, T2) { ASSERT(false); }
static void set(reflection::DynamicProperties::Value& v, i32 val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, float val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, const Path& val) { reflection::set(v, val.c_str()); }
static void set(reflection::DynamicProperties::Value& v, const char* val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, EntityPtr val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, bool val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, Vec3 val) { reflection::set(v, val); }
static void set(reflection::DynamicProperties::Value& v, const String& val) { reflection::set(v, val.c_str()); }
bool execute() override
@ -1209,7 +1210,7 @@ public:
if (!equalStrings(prop_name, name)) continue;
found = true;
reflection::DynamicProperties::Value v;
set(Ref(v), cmd->m_new_value);
set(v, cmd->m_new_value);
prop.set(cmp, cmd->m_index, i, v);
}
}
@ -1237,7 +1238,7 @@ public:
Span<const EntityRef> entities(nullptr, nullptr);
for (int i = 0; i < m_entities.size(); ++i) {
const ComponentUID cmp = universe->getComponent(m_entities[i], m_component_type);
PropertyDeserializeVisitor v(Ref<InputMemoryStream>(blob), cmp, map, entities);
PropertyDeserializeVisitor v(blob, cmp, map, entities);
cmp_desc->visit(v);
}
}
@ -1302,7 +1303,8 @@ private:
void undo() override {
m_editor.m_entity_folders->emplaceFolder(m_folder, m_parent);
m_editor.m_entity_folders->getFolder(m_folder).name = m_folder_name.c_str();
EntityFolders::Folder& f = m_editor.m_entity_folders->getFolder(m_folder);
copyString(f.name, m_folder_name.c_str());
}
const char* getType() override { return "destroy_entity_folder"; }
@ -1353,12 +1355,14 @@ private:
}
bool execute() override {
m_editor.m_entity_folders->getFolder(m_folder).name = m_new_name.c_str();
EntityFolders::Folder& f = m_editor.m_entity_folders->getFolder(m_folder);
copyString(f.name, m_new_name.c_str());
return true;
}
void undo() override {
m_editor.m_entity_folders->getFolder(m_folder).name = m_old_name.c_str();
EntityFolders::Folder& f = m_editor.m_entity_folders->getFolder(m_folder);
copyString(f.name, m_old_name.c_str());
}
const char* getType() override { return "rename_entity_folder"; }
@ -1551,7 +1555,7 @@ private:
pushChildren(entities[i]);
}
if (!m_entities.empty()) {
fastRemoveDuplicates(Ref(m_entities));
fastRemoveDuplicates(m_entities);
}
m_transformations.reserve(m_entities.size());
}
@ -1626,7 +1630,7 @@ private:
gather.resource_manager = &resource_manager;
cmp_desc->visit(gather);
Lumix::save(cmp, Ref(m_old_values));
Lumix::save(cmp, m_old_values);
}
const PrefabHandle prefab = m_editor.getPrefabSystem().getPrefab(m_entities[i]);
m_old_values.write(prefab);
@ -1691,7 +1695,7 @@ private:
new_component.scene = scene;
new_component.type = cmp_type;
::Lumix::load(new_component, Ref(blob));
::Lumix::load(new_component, blob);
}
PrefabHandle tpl;
blob.read(tpl);
@ -1761,7 +1765,7 @@ private:
{
cmp.entity = entity;
universe->createComponent(cmp.type, entity);
::Lumix::load(cmp, Ref(blob));
::Lumix::load(cmp, blob);
}
}
@ -1785,7 +1789,7 @@ private:
for (EntityRef entity : m_entities) {
cmp.entity = entity;
Lumix::save(cmp, Ref(m_old_values));
Lumix::save(cmp, m_old_values);
GatherResourcesVisitor gather;
gather.cmp = cmp;
@ -2364,7 +2368,7 @@ public:
serializer.write(cmp_type);
const reflection::ComponentBase* cmp_desc = reflection::getComponent(cmp.type);
PropertySerializeVisitor visitor(Ref<OutputMemoryStream>(serializer), cmp);
PropertySerializeVisitor visitor(serializer, cmp);
visitor.idx = -1;
cmp_desc->visit(visitor);
}
@ -2372,14 +2376,14 @@ public:
}
}
void gatherHierarchy(EntityRef e, Ref<Array<EntityRef>> entities) {
entities->push(e);
void gatherHierarchy(EntityRef e, Array<EntityRef>& entities) {
entities.push(e);
for (EntityPtr child = m_universe->getFirstChild(e);
child.isValid();
child = m_universe->getNextSibling((EntityRef)child))
{
const EntityRef ch = (EntityRef)child;
if (entities->indexOf(ch) < 0) {
if (entities.indexOf(ch) < 0) {
gatherHierarchy(ch, entities);
}
}
@ -2394,7 +2398,7 @@ public:
Array<EntityRef> entities(m_allocator);
entities.reserve(m_selected_entities.size());
for (EntityRef e : m_selected_entities) {
gatherHierarchy(e, Ref(entities));
gatherHierarchy(e, entities);
}
copyEntities(entities, m_copy_buffer);
}
@ -2446,7 +2450,7 @@ public:
bool loadProject() override {
OutputMemoryStream data(m_allocator);
if (!m_engine.getFileSystem().getContentSync(Path("lumix.prj"), Ref(data))) return false;
if (!m_engine.getFileSystem().getContentSync(Path("lumix.prj"), data)) return false;
InputMemoryStream stream(data);
return m_engine.deserializeProject(stream);
@ -2556,7 +2560,7 @@ public:
}
EntityMap entity_map(m_allocator);
if (m_engine.deserialize(*m_universe, blob, Ref(entity_map)))
if (m_engine.deserialize(*m_universe, blob, entity_map))
{
m_prefab_system->deserialize(blob, entity_map);
if (header.version > (i32)SerializedVersion::ENTITY_FOLDERS) {
@ -2660,12 +2664,12 @@ public:
void setProperty(ComponentType cmp, const char* array, int idx, const char* prop, Span<const EntityRef> entities, const Vec4& val) override { set(cmp, array, idx, prop, entities, val); }
void setProperty(ComponentType cmp, const char* array, int idx, const char* prop, Span<const EntityRef> entities, const IVec3& val) override { set(cmp, array, idx, prop, entities, val); }
static void fastRemoveDuplicates(Ref<Array<EntityRef>> entities) {
qsort(entities->begin(), entities->size(), sizeof(entities.value[0]), [](const void* a, const void* b){
static void fastRemoveDuplicates(Array<EntityRef>& entities) {
qsort(entities.begin(), entities.size(), sizeof(entities[0]), [](const void* a, const void* b){
return memcmp(a, b, sizeof(EntityRef));
});
for (i32 i = entities->size() - 2; i >= 0; --i) {
if (entities.value[i] == entities.value[i + 1]) entities->swapAndPop(i);
for (i32 i = entities.size() - 2; i >= 0; --i) {
if (entities[i] == entities[i + 1]) entities.swapAndPop(i);
}
}
@ -2687,7 +2691,7 @@ public:
}
}
}
fastRemoveDuplicates(Ref(m_selected_entities));
fastRemoveDuplicates(m_selected_entities);
}
@ -2869,7 +2873,7 @@ public:
Universe& universe = *m_editor.getUniverse();
int entity_count;
blob.read(Ref(entity_count));
blob.read(entity_count);
bool is_redo = !m_entities.empty();
if (is_redo)
{
@ -2892,17 +2896,17 @@ public:
m_map.reserve(entity_count);
for (int i = 0; i < entity_count; ++i) {
EntityRef orig_e;
blob.read(Ref(orig_e));
blob.read(orig_e);
if (!is_redo) m_map.insert(orig_e, i);
}
for (int i = 0; i < entity_count; ++i)
{
Transform tr;
blob.read(Ref(tr));
blob.read(tr);
const char* name = blob.readString();
if (name[0]) universe.setEntityName(m_entities[i], name);
EntityPtr parent;
blob.read(Ref(parent));
blob.read(parent);
auto iter = m_map.find(parent);
if (iter.isValid()) parent = m_entities[iter.value()];
@ -2928,7 +2932,7 @@ public:
universe.setParent(parent, new_entity);
for (;;) {
u32 hash;
blob.read(Ref(hash));
blob.read(hash);
if (hash == 0) break;
ComponentUID cmp;
@ -2938,7 +2942,7 @@ public:
cmp.scene->getUniverse().createComponent(cmp.type, new_entity);
PropertyDeserializeVisitor visitor(Ref<InputMemoryStream>(blob), cmp, m_map, m_entities);
PropertyDeserializeVisitor visitor(blob, cmp, m_map, m_entities);
visitor.idx = -1;
reflection::getComponent(cmp.type)->visit(visitor);
}

View file

@ -28,7 +28,7 @@ public:
StackNode* record();
void printCallstack(StackNode* node);
static bool getFunction(StackNode* node, Span<char> out, Ref<int> line);
static bool getFunction(StackNode* node, Span<char> out, int& line);
static StackNode* getParent(StackNode* node);
static int getPath(StackNode* node, Span<StackNode*> output);
static void refreshModuleList();

View file

@ -7,7 +7,6 @@
#include "engine/plugin.h"
#include "engine/job_system.h"
#include "engine/log.h"
#include "engine/lua_wrapper.h"
#include "engine/math.h"
#include "engine/page_allocator.h"
#include "engine/path.h"
@ -15,8 +14,9 @@
#include "engine/profiler.h"
#include "engine/resource_manager.h"
#include "engine/stream.h"
#include "engine/string.h"
#include "engine/universe.h"
#include <lua.hpp>
namespace Lumix
{
@ -191,7 +191,7 @@ public:
const struct DVec3& pos,
const struct Quat& rot,
float scale,
Ref<EntityMap> entity_map) override
EntityMap& entity_map) override
{
ASSERT(prefab.isReady());
InputMemoryStream blob(prefab.data);
@ -200,8 +200,8 @@ public:
return false;
}
ASSERT(!entity_map->m_map.empty());
const EntityRef root = (EntityRef)entity_map->m_map[0];
ASSERT(!entity_map.m_map.empty());
const EntityRef root = (EntityRef)entity_map.m_map[0];
ASSERT(!universe.getParent(root).isValid());
ASSERT(!universe.getNextSibling(root).isValid());
universe.setTransform(root, pos, rot, scale);
@ -222,7 +222,6 @@ public:
if (is_main_universe) {
lua_State* L = m_state;
LuaWrapper::DebugGuard guard(L);
lua_getglobal(L, "Lumix"); // [ Lumix ]
lua_getfield(L, -1, "Universe"); // [ Lumix, Universe ]
lua_getfield(L, -1, "new"); // [ Lumix, Universe, new ]
@ -434,7 +433,7 @@ public:
}
bool deserialize(Universe& ctx, InputMemoryStream& serializer, Ref<EntityMap> entity_map) override
bool deserialize(Universe& ctx, InputMemoryStream& serializer, EntityMap& entity_map) override
{
SerializedEngineHeader header;
serializer.read(header);

View file

@ -40,14 +40,14 @@ struct LUMIX_ENGINE_API Engine {
const struct DVec3& pos,
const struct Quat& rot,
float scale,
Ref<struct EntityMap> entity_map) = 0;
struct EntityMap& entity_map) = 0;
virtual void startGame(Universe& context) = 0;
virtual void stopGame(Universe& context) = 0;
virtual void update(Universe& context) = 0;
virtual u32 serialize(Universe& ctx, struct OutputMemoryStream& serializer) = 0;
virtual bool deserialize(Universe& ctx, struct InputMemoryStream& serializer, Ref<struct EntityMap> entity_map) = 0;
virtual bool deserialize(Universe& ctx, struct InputMemoryStream& serializer, struct EntityMap& entity_map) = 0;
virtual bool deserializeProject(InputMemoryStream& serializer) = 0;
virtual void serializeProject(OutputMemoryStream& serializer) const = 0;
virtual float getLastTimeDelta() const = 0;

View file

@ -94,14 +94,14 @@ struct FileSystemImpl : FileSystem {
}
}
bool getContentSync(const Path& path, Ref<OutputMemoryStream> content) override {
bool getContentSync(const Path& path, OutputMemoryStream& content) override {
os::InputFile file;
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path.c_str());
if (!file.open(full_path)) return false;
content->resize((int)file.size());
if (!file.read(content->getMutableData(), content->size())) {
content.resize((int)file.size());
if (!file.read(content.getMutableData(), content.size())) {
logError("Could not read ", path);
file.close();
return false;
@ -146,17 +146,17 @@ struct FileSystemImpl : FileSystem {
}
bool open(const char* path, Ref<os::InputFile> file) override
bool open(const char* path, os::InputFile& file) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
return file->open(full_path);
return file.open(full_path);
}
bool open(const char* path, Ref<os::OutputFile> file) override
bool open(const char* path, os::OutputFile& file) override
{
StaticString<LUMIX_MAX_PATH> full_path(m_base_path, path);
return file->open(full_path);
return file.open(full_path);
}
@ -285,7 +285,7 @@ int FSTask::task()
}
OutputMemoryStream data(m_fs.m_allocator);
bool success = m_fs.getContentSync(Path(path), Ref(data));
bool success = m_fs.getContentSync(Path(path), data);
{
MutexGuard lock(m_fs.m_mutex);
@ -333,10 +333,10 @@ struct PackFileSystem : FileSystemImpl {
m_file.close();
}
bool getContentSync(const Path& path, Ref<OutputMemoryStream> content) override {
bool getContentSync(const Path& path, OutputMemoryStream& content) override {
Span<const char> basename = Path::getBasename(path.c_str());
u32 hash;
fromCString(basename, Ref(hash));
fromCString(basename, hash);
if (basename[0] < '0' || basename[0] > '9' || hash == 0) {
hash = path.getHash();
}
@ -352,10 +352,10 @@ struct PackFileSystem : FileSystemImpl {
return false;
}
content->resize(iter.value().size);
const i32 res = LZ4_decompress_safe((const char*)compressed.data(), (char*)content->getMutableData(), (i32)iter.value().compressed_size, (i32)content->size());
content.resize(iter.value().size);
const i32 res = LZ4_decompress_safe((const char*)compressed.data(), (char*)content.getMutableData(), (i32)iter.value().compressed_size, (i32)content.size());
if (res != content->size()) {
if (res != content.size()) {
logError("Could not decompress ", path);
return false;
}

View file

@ -34,8 +34,8 @@ struct LUMIX_ENGINE_API FileSystem {
virtual bool deleteFile(const char* path) = 0;
virtual bool fileExists(const char* path) = 0;
virtual os::FileIterator* createFileIterator(const char* dir) = 0;
virtual bool open(const char* path, Ref<os::InputFile> file) = 0;
virtual bool open(const char* path, Ref<os::OutputFile> file) = 0;
virtual bool open(const char* path, os::InputFile& file) = 0;
virtual bool open(const char* path, os::OutputFile& file) = 0;
virtual void setBasePath(const char* path) = 0;
virtual const char* getBasePath() const = 0;
@ -44,7 +44,7 @@ struct LUMIX_ENGINE_API FileSystem {
[[nodiscard]] virtual bool makeRelative(Span<char> relative, const char* absolute) const = 0;
virtual void makeAbsolute(Span<char> absolute, const char* relative) const = 0;
[[nodiscard]] virtual bool getContentSync(const struct Path& file, Ref<struct OutputMemoryStream> content) = 0;
[[nodiscard]] virtual bool getContentSync(const struct Path& file, struct OutputMemoryStream& content) = 0;
virtual AsyncHandle getContent(const Path& file, const ContentCallback& callback) = 0;
virtual void cancel(AsyncHandle handle) = 0;
};

View file

@ -3,10 +3,12 @@
#include "engine.h"
#include "file_system.h"
#include "input_system.h"
#include "log.h"
#include "lua_wrapper.h"
#include "plugin.h"
#include "prefab.h"
#include "reflection.h"
#include "string.h"
#include "universe.h"
@ -395,7 +397,7 @@ static int LUA_packageLoader(lua_State* L)
lua_pop(L, 1);
auto& fs = engine->getFileSystem();
OutputMemoryStream buf(engine->getAllocator());
if (!fs.getContentSync(Path(tmp), Ref(buf))) {
if (!fs.getContentSync(Path(tmp), buf)) {
logError("Failed to open file ", tmp);
StaticString<LUMIX_MAX_PATH + 40> msg("Failed to open file ");
msg << tmp;
@ -668,7 +670,7 @@ static int LUA_loadUniverse(lua_State* L)
blob.read(&header, sizeof(header));
EntityMap entity_map(engine->getAllocator());
if (!engine->deserialize(*universe, blob, Ref(entity_map)))
if (!engine->deserialize(*universe, blob, entity_map))
{
logError("Failed to deserialize universe ", path);
}
@ -732,7 +734,7 @@ static int LUA_instantiatePrefab(lua_State* L) {
luaL_error(L, "Prefab '%s' is not ready, preload it.", prefab->getPath().c_str());
}
EntityMap entity_map(engine->getAllocator());
if (engine->instantiatePrefab(*universe, *prefab, position, {0, 0, 0, 1}, 1, Ref(entity_map))) {
if (engine->instantiatePrefab(*universe, *prefab, position, {0, 0, 0, 1}, 1, entity_map)) {
LuaWrapper::pushEntity(L, entity_map.m_map[0], universe);
return 1;
}

View file

@ -1,7 +1,30 @@
#include "lua_wrapper.h"
#include "log.h"
#include "string.h"
namespace Lumix::LuaWrapper {
#ifdef LUMIX_DEBUG
DebugGuard::DebugGuard(lua_State* L)
: L(L)
{
top = lua_gettop(L);
}
DebugGuard::DebugGuard(lua_State* L, int offset)
: L(L)
{
top = lua_gettop(L) + offset;
}
DebugGuard::~DebugGuard()
{
const int current_top = lua_gettop(L);
ASSERT(current_top == top);
}
#endif
int traceback (lua_State *L) {
if (!lua_isstring(L, 1)) return 1;
@ -60,4 +83,158 @@ bool execute(lua_State* L
return true;
}
}
bool checkStringField(lua_State* L, int idx, const char* k, Span<char> out) {
lua_getfield(L, idx, k);
if (!isType<const char*>(L, -1)) {
lua_pop(L, 1);
return false;
}
const char* tmp = toType<const char*>(L, -1);
copyString(out, tmp);
lua_pop(L, 1);
return true;
}
void push(lua_State* L, EntityRef value) {
lua_pushinteger(L, value.index);
}
bool toEntity(lua_State* L, int idx, Universe*& universe, EntityRef& entity) {
if (!lua_istable(L, idx)) return false;
if (getField(L, 1, "_entity") != LUA_TNUMBER) {
lua_pop(L, 1);
return false;
}
entity = EntityRef{toType<i32>(L, -1)};
lua_pop(L, 1);
if (getField(L, 1, "_universe") != LUA_TLIGHTUSERDATA) {
lua_pop(L, 1);
return false;
}
universe = toType<Universe*>(L, -1);
lua_pop(L, 1);
return true;
}
void pushEntity(lua_State* L, EntityPtr value, Universe* universe) {
if (!value.isValid()) {
lua_newtable(L); // [env, {}]
return;
}
lua_getglobal(L, "Lumix"); // [Lumix]
lua_getfield(L, -1, "Entity"); // [Lumix, Lumix.Entity]
lua_remove(L, -2); // [Lumix.Entity]
lua_getfield(L, -1, "new"); // [Lumix.Entity, Entity.new]
lua_pushvalue(L, -2); // [Lumix.Entity, Entity.new, Lumix.Entity]
lua_remove(L, -3); // [Entity.new, Lumix.Entity]
lua_pushlightuserdata(L, universe); // [Entity.new, Lumix.Entity, universe]
lua_pushnumber(L, value.index); // [Entity.new, Lumix.Entity, universe, entity_index]
const bool error = !LuaWrapper::pcall(L, 3, 1); // [entity]
ASSERT(!error);
}
int getField(lua_State* L, int idx, const char* k) {
lua_getfield(L, idx, k);
return lua_type(L, -1);
}
bool getOptionalStringField(lua_State* L, int idx, const char* field_name, Span<char> out) {
bool ret = false;
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<const char*>(L, -1)) {
const char* src = toType<const char*>(L, -1);
;
copyString(out, src);
ret = true;
}
lua_pop(L, 1);
return ret;
}
void checkTableArg(lua_State* L, int index) {
if (!lua_istable(L, index)) {
argError(L, index, "table");
}
}
void createSystemVariable(lua_State* L, const char* system, const char* var_name, void* value) {
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL) {
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushlightuserdata(L, value);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
void createSystemVariable(lua_State* L, const char* system, const char* var_name, int value) {
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL) {
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushinteger(L, value);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
void createSystemFunction(lua_State* L, const char* system, const char* var_name, lua_CFunction fn) {
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL) {
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushcfunction(L, fn);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
void createSystemClosure(lua_State* L, const char* system, void* system_ptr, const char* var_name, lua_CFunction fn) {
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL) {
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushlightuserdata(L, system_ptr);
lua_pushcclosure(L, fn, 1);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
const char* luaTypeToString(int type) {
switch (type) {
case LUA_TNUMBER: return "number";
case LUA_TBOOLEAN: return "boolean";
case LUA_TFUNCTION: return "function";
case LUA_TLIGHTUSERDATA: return "light userdata";
case LUA_TNIL: return "nil";
case LUA_TSTRING: return "string";
case LUA_TTABLE: return "table";
case LUA_TUSERDATA: return "userdata";
default: return "Unknown";
}
}
void argError(lua_State* L, int index, const char* expected_type) {
char buf[128];
copyString(buf, "expected ");
catString(buf, expected_type);
catString(buf, ", got ");
int type = lua_type(L, index);
catString(buf, LuaWrapper::luaTypeToString(type));
luaL_argerror(L, index, buf);
}
} // namespace Lumix::LuaWrapper

View file

@ -1,11 +1,9 @@
#pragma once
#include "engine/log.h"
#include "engine/math.h"
#include "engine/metaprogramming.h"
#include "engine/path.h"
#include "engine/string.h"
#include <lua.hpp>
#include <lauxlib.h>
@ -19,33 +17,17 @@ namespace LuaWrapper {
#ifdef LUMIX_DEBUG
struct DebugGuard
{
DebugGuard(lua_State* L)
: L(L)
{
top = lua_gettop(L);
}
struct DebugGuard {
DebugGuard(lua_State* L);
DebugGuard(lua_State* L, int offset);
~DebugGuard();
DebugGuard(lua_State* L, int offset)
: L(L)
{
top = lua_gettop(L) + offset;
}
~DebugGuard()
{
const int current_top = lua_gettop(L);
ASSERT(current_top == top);
}
private:
lua_State* L;
int top;
};
#else
struct DebugGuard
{
struct DebugGuard {
DebugGuard(lua_State* L) {}
DebugGuard(lua_State* L, int offset) {}
};
@ -67,31 +49,10 @@ struct Optional {
bool valid = false;
};
int traceback (lua_State *L);
bool pcall(lua_State* L, int nargs, int nres);
bool execute(lua_State* L, Span<const char> content, const char* name, int nresults);
inline void get_tail(lua_State* L) {}
template <typename... Args>
void get_tail(lua_State* L, const char* head, Args... tail) {
lua_getfield(L, -1, head);
lua_remove(L, -2);
get_tail(L, tail...);
}
template <typename... Args>
void get(lua_State* L, const char* head, Args... tail) {
lua_getglobal(L, head);
get_tail(L, tail...);
}
inline int getField(lua_State* L, int idx, const char* k)
{
lua_getfield(L, idx, k);
return lua_type(L, -1);
}
LUMIX_ENGINE_API int traceback (lua_State *L);
LUMIX_ENGINE_API bool pcall(lua_State* L, int nargs, int nres);
LUMIX_ENGINE_API bool execute(lua_State* L, Span<const char> content, const char* name, int nresults);
LUMIX_ENGINE_API int getField(lua_State* L, int idx, const char* k);
template <typename T> inline bool isType(lua_State* L, int index)
{
@ -185,7 +146,6 @@ template <> inline bool isType<void*>(lua_State* L, int index)
return lua_islightuserdata(L, index) != 0;
}
template <typename T> inline T toType(lua_State* L, int index)
{
return (T)lua_touserdata(L, index);
@ -193,24 +153,13 @@ template <typename T> inline T toType(lua_State* L, int index)
template <> CameraParams toType(lua_State* L, int idx);
template <> inline int toType(lua_State* L, int index)
{
return (int)lua_tointeger(L, index);
}
template <> inline u16 toType(lua_State* L, int index)
{
return (u16)lua_tointeger(L, index);
}
template <> inline Path toType(lua_State* L, int index)
{
return Path(lua_tostring(L, index));
}
template <> inline u8 toType(lua_State* L, int index)
{
return (u8)lua_tointeger(L, index);
}
template <> inline EntityRef toType(lua_State* L, int index)
{
template <> inline int toType(lua_State* L, int index) { return (int)lua_tointeger(L, index); }
template <> inline u16 toType(lua_State* L, int index) { return (u16)lua_tointeger(L, index); }
template <> inline Path toType(lua_State* L, int index) { return Path(lua_tostring(L, index)); }
template <> inline u8 toType(lua_State* L, int index) { return (u8)lua_tointeger(L, index); }
template <> inline ComponentType toType(lua_State* L, int index) { return {(int)lua_tointeger(L, index)}; }
template <> inline EntityRef toType(lua_State* L, int index) {
if (getField(L, index, "_entity") == LUA_TNUMBER) {
const EntityRef e = {(i32)lua_tointeger(L, -1)};
lua_pop(L, 1);
@ -220,8 +169,8 @@ template <> inline EntityRef toType(lua_State* L, int index)
ASSERT(false);
return {};
}
template <> inline EntityPtr toType(lua_State* L, int index)
{
template <> inline EntityPtr toType(lua_State* L, int index) {
if (getField(L, index, "_entity") == LUA_TNUMBER) {
const EntityRef e = {(i32)lua_tointeger(L, -1)};
lua_pop(L, 1);
@ -230,12 +179,8 @@ template <> inline EntityPtr toType(lua_State* L, int index)
lua_pop(L, 1);
return INVALID_ENTITY;
}
template <> inline ComponentType toType(lua_State* L, int index)
{
return { (int)lua_tointeger(L, index) };
}
template <> inline Vec3 toType(lua_State* L, int index)
{
template <> inline Vec3 toType(lua_State* L, int index) {
Vec3 v;
lua_rawgeti(L, index, 1);
v.x = (float)lua_tonumber(L, -1);
@ -248,8 +193,8 @@ template <> inline Vec3 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline IVec3 toType(lua_State* L, int index)
{
template <> inline IVec3 toType(lua_State* L, int index) {
IVec3 v;
lua_rawgeti(L, index, 1);
v.x = (int)lua_tonumber(L, -1);
@ -262,8 +207,8 @@ template <> inline IVec3 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline DVec3 toType(lua_State* L, int index)
{
template <> inline DVec3 toType(lua_State* L, int index) {
DVec3 v;
lua_rawgeti(L, index, 1);
v.x = (double)lua_tonumber(L, -1);
@ -276,8 +221,8 @@ template <> inline DVec3 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline Vec4 toType(lua_State* L, int index)
{
template <> inline Vec4 toType(lua_State* L, int index) {
Vec4 v;
lua_rawgeti(L, index, 1);
v.x = (float)lua_tonumber(L, -1);
@ -293,8 +238,8 @@ template <> inline Vec4 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline Quat toType(lua_State* L, int index)
{
template <> inline Quat toType(lua_State* L, int index) {
Quat v;
lua_rawgeti(L, index, 1);
v.x = (float)lua_tonumber(L, -1);
@ -310,8 +255,8 @@ template <> inline Quat toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline Vec2 toType(lua_State* L, int index)
{
template <> inline Vec2 toType(lua_State* L, int index) {
Vec2 v;
lua_rawgeti(L, index, 1);
v.x = (float)lua_tonumber(L, -1);
@ -321,19 +266,18 @@ template <> inline Vec2 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline Matrix toType(lua_State* L, int index)
{
template <> inline Matrix toType(lua_State* L, int index) {
Matrix v;
for (int i = 0; i < 16; ++i)
{
for (int i = 0; i < 16; ++i) {
lua_rawgeti(L, index, i + 1);
(&(v.columns[0].x))[i] = (float)lua_tonumber(L, -1);
lua_pop(L, 1);
}
return v;
}
template <> inline IVec2 toType(lua_State* L, int index)
{
template <> inline IVec2 toType(lua_State* L, int index) {
IVec2 v;
lua_rawgeti(L, index, 1);
v.x = (int)lua_tointeger(L, -1);
@ -343,35 +287,17 @@ template <> inline IVec2 toType(lua_State* L, int index)
lua_pop(L, 1);
return v;
}
template <> inline i64 toType(lua_State* L, int index)
{
return (i64)lua_tointeger(L, index);
}
template <> inline u32 toType(lua_State* L, int index)
{
return (u32)lua_tointeger(L, index);
}
template <> inline u64 toType(lua_State* L, int index)
{
return (u64)lua_tointeger(L, index);
}
template <> inline bool toType(lua_State* L, int index)
{
return lua_toboolean(L, index) != 0;
}
template <> inline float toType(lua_State* L, int index)
{
return (float)lua_tonumber(L, index);
}
template <> inline const char* toType(lua_State* L, int index)
{
template <> inline i64 toType(lua_State* L, int index) { return (i64)lua_tointeger(L, index); }
template <> inline u32 toType(lua_State* L, int index) { return (u32)lua_tointeger(L, index); }
template <> inline u64 toType(lua_State* L, int index) { return (u64)lua_tointeger(L, index); }
template <> inline bool toType(lua_State* L, int index) { return lua_toboolean(L, index) != 0; }
template <> inline float toType(lua_State* L, int index) { return (float)lua_tonumber(L, index); }
template <> inline void* toType(lua_State* L, int index) { return lua_touserdata(L, index); }
template <> inline const char* toType(lua_State* L, int index) {
const char* res = lua_tostring(L, index);
return res ? res : "";
}
template <> inline void* toType(lua_State* L, int index)
{
return lua_touserdata(L, index);
}
template <typename T> inline bool checkField(lua_State* L, int idx, const char* k, T* out)
{
@ -385,19 +311,6 @@ template <typename T> inline bool checkField(lua_State* L, int idx, const char*
return true;
}
inline bool checkStringField(lua_State* L, int idx, const char* k, Span<char> out)
{
lua_getfield(L, idx, k);
if(!isType<const char*>(L, -1)) {
lua_pop(L, 1);
return false;
}
const char* tmp = toType<const char*>(L, -1);
copyString(out, tmp);
lua_pop(L, 1);
return true;
}
template <typename T, typename F> bool forEachArrayItem(lua_State* L, int index, const char* error_msg, F&& func)
{
if (!lua_istable(L, index)) {
@ -424,7 +337,6 @@ template <typename T, typename F> bool forEachArrayItem(lua_State* L, int index,
return all_match;
}
template <typename T> inline const char* typeToString()
{
return "userdata";
@ -479,58 +391,15 @@ template <typename T> inline void push(lua_State* L, T* value)
void push(lua_State* L, const CameraParams& value);
void push(lua_State* L, const PipelineTexture& value);
inline void push(lua_State* L, float value)
{
lua_pushnumber(L, value);
}
template <typename T> inline void push(lua_State* L, const T* value)
{
lua_pushlightuserdata(L, (T*)value);
}
inline void push(lua_State* L, EntityRef value)
inline void push(lua_State* L, float value)
{
lua_pushinteger(L, value.index);
lua_pushnumber(L, value);
}
inline bool toEntity(lua_State* L, int idx, Ref<Universe*> universe, Ref<EntityRef> entity)
{
if (!lua_istable(L, idx)) return false;
if (getField(L, 1, "_entity") != LUA_TNUMBER) {
lua_pop(L, 1);
return false;
}
entity = EntityRef {toType<i32>(L, -1)};
lua_pop(L, 1);
if (getField(L, 1, "_universe") != LUA_TLIGHTUSERDATA) {
lua_pop(L, 1);
return false;
}
universe = toType<Universe*>(L, -1);
lua_pop(L, 1);
return true;
}
inline void pushEntity(lua_State* L, EntityPtr value, Universe* universe)
{
if (!value.isValid()) {
lua_newtable(L); // [env, {}]
return;
}
lua_getglobal(L, "Lumix"); // [Lumix]
lua_getfield(L, -1, "Entity"); // [Lumix, Lumix.Entity]
lua_remove(L, -2); // [Lumix.Entity]
lua_getfield(L, -1, "new"); // [Lumix.Entity, Entity.new]
lua_pushvalue(L, -2); // [Lumix.Entity, Entity.new, Lumix.Entity]
lua_remove(L, -3); // [Entity.new, Lumix.Entity]
lua_pushlightuserdata(L, universe); // [Entity.new, Lumix.Entity, universe]
lua_pushnumber(L, value.index); // [Entity.new, Lumix.Entity, universe, entity_index]
const bool error = !LuaWrapper::pcall(L, 3, 1); // [entity]
ASSERT(!error);
}
inline void push(lua_State* L, ComponentType value)
{
lua_pushinteger(L, value.index);
@ -679,100 +548,18 @@ template <typename T> inline void setField(lua_State* L, int table_idx, const ch
lua_setfield(L, table_idx - 1, name);
}
inline void createSystemVariable(lua_State* L, const char* system, const char* var_name, void* value)
{
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushlightuserdata(L, value);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
inline void createSystemVariable(lua_State* L, const char* system, const char* var_name, int value)
{
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushinteger(L, value);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
inline void createSystemFunction(lua_State* L, const char* system, const char* var_name, lua_CFunction fn)
{
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushcfunction(L, fn);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
inline void createSystemClosure(lua_State* L, const char* system, void* system_ptr, const char* var_name, lua_CFunction fn)
{
lua_getglobal(L, system);
if (lua_type(L, -1) == LUA_TNIL)
{
lua_pop(L, 1);
lua_newtable(L);
lua_setglobal(L, system);
lua_getglobal(L, system);
}
lua_pushlightuserdata(L, system_ptr);
lua_pushcclosure(L, fn, 1);
lua_setfield(L, -2, var_name);
lua_pop(L, 1);
}
inline const char* luaTypeToString(int type)
{
switch (type)
{
case LUA_TNUMBER: return "number";
case LUA_TBOOLEAN: return "boolean";
case LUA_TFUNCTION: return "function";
case LUA_TLIGHTUSERDATA: return "light userdata";
case LUA_TNIL: return "nil";
case LUA_TSTRING: return "string";
case LUA_TTABLE: return "table";
case LUA_TUSERDATA: return "userdata";
default: return "Unknown";
}
}
inline void argError(lua_State* L, int index, const char* expected_type)
{
char buf[128];
copyString(buf, "expected ");
catString(buf, expected_type);
catString(buf, ", got ");
int type = lua_type(L, index);
catString(buf, LuaWrapper::luaTypeToString(type));
luaL_argerror(L, index, buf);
}
LUMIX_ENGINE_API void createSystemVariable(lua_State* L, const char* system, const char* var_name, void* value);
LUMIX_ENGINE_API void createSystemVariable(lua_State* L, const char* system, const char* var_name, int value);
LUMIX_ENGINE_API void createSystemFunction(lua_State* L, const char* system, const char* var_name, lua_CFunction fn);
LUMIX_ENGINE_API void createSystemClosure(lua_State* L, const char* system, void* system_ptr, const char* var_name, lua_CFunction fn);
LUMIX_ENGINE_API const char* luaTypeToString(int type);
LUMIX_ENGINE_API void argError(lua_State* L, int index, const char* expected_type);
LUMIX_ENGINE_API void checkTableArg(lua_State* L, int index);
LUMIX_ENGINE_API bool getOptionalStringField(lua_State* L, int idx, const char* field_name, Span<char> out);
LUMIX_ENGINE_API void push(lua_State* L, EntityRef value);
LUMIX_ENGINE_API bool toEntity(lua_State* L, int idx, Universe*& universe, EntityRef& entity);
LUMIX_ENGINE_API void pushEntity(lua_State* L, EntityPtr value, Universe* universe);
LUMIX_ENGINE_API bool checkStringField(lua_State* L, int idx, const char* k, Span<char> out);
template <typename T> void argError(lua_State* L, int index)
{
@ -817,8 +604,7 @@ template <typename T, u32 C> Array<T, C> checkArg(lua_State* L, int index, Tag<A
for (u32 i = 0; i < res.size; ++i) {
lua_rawgeti(L, index, i + 1);
if (!isType<T>(L, -1)) {
StaticString<128> buf("expected array of ", typeToString<T>());
luaL_argerror(L, index, buf);
luaL_error(L, "expected array of %s as %d-th argument", typeToString<T>(), index);
}
res.values[i] = toType<T>(L, -1);
lua_pop(L, 1);
@ -832,16 +618,8 @@ template <typename T> T checkArg(lua_State* L, int index)
return checkArg(L, index, Tag<T>{});
}
inline void checkTableArg(lua_State* L, int index)
{
if (!lua_istable(L, index))
{
argError(L, index, "table");
}
}
template <typename T>
inline void getOptionalField(lua_State* L, int idx, const char* field_name, T* out)
void getOptionalField(lua_State* L, int idx, const char* field_name, T* out)
{
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<T>(L, -1))
{
@ -850,9 +628,8 @@ inline void getOptionalField(lua_State* L, int idx, const char* field_name, T* o
lua_pop(L, 1);
}
template <typename T>
inline void getOptionalFlagField(lua_State* L, int idx, const char* field_name, T* out, T flag, bool default_value)
void getOptionalFlagField(lua_State* L, int idx, const char* field_name, T* out, T flag, bool default_value)
{
bool value = default_value;
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<bool>(L, -1)) {
@ -863,19 +640,6 @@ inline void getOptionalFlagField(lua_State* L, int idx, const char* field_name,
else *out = *out & ~flag;
}
inline bool getOptionalStringField(lua_State* L, int idx, const char* field_name, Span<char> out)
{
bool ret = false;
if (LuaWrapper::getField(L, idx, field_name) != LUA_TNIL && isType<const char*>(L, -1))
{
const char* src = toType<const char*>(L, -1);;
copyString(out, src);
ret = true;
}
lua_pop(L, 1);
return ret;
}
namespace details
{
@ -1044,11 +808,9 @@ template <auto t> int wrapMethodClosure(lua_State* L)
using C = typename ClassOf<decltype(t)>::Type;
using indices = typename BuildIndices<0, details::arity(t)>::result;
int index = lua_upvalueindex(1);
if (!isType<C>(L, index))
{
logError("Invalid Lua closure");
if (!isType<C>(L, index)) {
ASSERT(false);
return 0;
return luaL_error(L, "Invalid Lua closure");
}
auto* inst = checkArg<C*>(L, index);
return details::Caller<indices>::callMethod(inst, t, L);

View file

@ -95,19 +95,6 @@ template <typename T, u32 count> constexpr u32 lengthOf(const T (&)[count])
return count;
};
// use this instead non-const reference parameter to show intention
template <typename T>
struct Ref {
Ref(const Ref<T>& value) : value(value.value) {}
explicit Ref(T& value) : value(value) {}
operator T&() { return value; }
T* operator->() { return &value; }
void operator =(const Ref<T>& rhs) { value = rhs.value; }
void operator =(const T& rhs) { value = rhs; }
template <typename T2> void operator =(const T2& rhs) { value = rhs; }
T& value;
};
template <typename T>
struct Span
{

View file

@ -1191,7 +1191,7 @@ bool getRaySphereIntersection(const Vec3& origin,
const Vec3& dir,
const Vec3& center,
float radius,
Ref<float> out)
float& out)
{
ASSERT(length(dir) < 1.01f && length(dir) > 0.99f);
Vec3 L = center - origin;

View file

@ -423,7 +423,7 @@ LUMIX_ENGINE_API Vec3 cross(const Vec3& op1, const Vec3& op2);
LUMIX_ENGINE_API DVec3 cross(const DVec3& op1, const DVec3& op2);
LUMIX_ENGINE_API bool getRayPlaneIntersecion(const Vec3& origin, const Vec3& dir, const Vec3& plane_point, const Vec3& normal, float& out);
LUMIX_ENGINE_API bool getRaySphereIntersection(const Vec3& origin, const Vec3& dir, const Vec3& center, float radius, Ref<float> out);
LUMIX_ENGINE_API bool getRaySphereIntersection(const Vec3& origin, const Vec3& dir, const Vec3& center, float radius, float& out);
LUMIX_ENGINE_API bool getRayAABBIntersection(const Vec3& origin, const Vec3& dir, const Vec3& min, const Vec3& size, Vec3& out);
LUMIX_ENGINE_API float getLineSegmentDistance(const Vec3& origin, const Vec3& dir, const Vec3& a, const Vec3& b);
LUMIX_ENGINE_API bool getRayTriangleIntersection(const Vec3& origin, const Vec3& dir, const Vec3& a, const Vec3& b, const Vec3& c, float* out_t);

View file

@ -204,7 +204,7 @@ LUMIX_ENGINE_API void showCursor(bool show);
LUMIX_ENGINE_API u32 getMonitors(Span<Monitor> monitors);
LUMIX_ENGINE_API Point toScreen(WindowHandle win, int x, int y);
LUMIX_ENGINE_API WindowHandle createWindow(const InitWindowArgs& args);
LUMIX_ENGINE_API bool getEvent(Ref<Event> event);
LUMIX_ENGINE_API bool getEvent(Event& event);
LUMIX_ENGINE_API void destroyWindow(WindowHandle wnd);
LUMIX_ENGINE_API Rect getWindowScreenRect(WindowHandle win);
LUMIX_ENGINE_API Rect getWindowClientRect(WindowHandle win);

View file

@ -4,6 +4,8 @@
#include "engine/crc32.h"
#include "engine/log.h"
#include "engine/stream.h"
#include "engine/string.h"
#include "engine/universe.h"
namespace Lumix
{

View file

@ -504,7 +504,7 @@ struct ComponentBase {
};
template <typename T>
bool getPropertyValue(IScene& scene, EntityRef e, ComponentType cmp_type, const char* prop_name, Ref<T> out) {
bool getPropertyValue(IScene& scene, EntityRef e, ComponentType cmp_type, const char* prop_name, T& out) {
struct : IEmptyPropertyVisitor {
void visit(const Property<T>& prop) override {
if (equalStrings(prop.name, prop_name)) {

View file

@ -28,7 +28,6 @@ struct LUMIX_ENGINE_API IInputStream {
template <typename T> void read(T& value) { read(&value, sizeof(T)); }
template <typename T> T read();
template <typename T> void read(Ref<T> val) { val = read<T>(); }
};

View file

@ -562,15 +562,15 @@ static void reverse(char* str, int length)
}
}
const char* fromCString(Span<const char> input, Ref<i32> value)
const char* fromCString(Span<const char> input, i32& value)
{
i64 val;
const char* ret = fromCString(input, Ref(val));
const char* ret = fromCString(input, val);
value = (i32)val;
return ret;
}
const char* fromCString(Span<const char> input, Ref<i64> value)
const char* fromCString(Span<const char> input, i64& value)
{
u32 length = input.length();
if (length > 0)
@ -602,15 +602,15 @@ const char* fromCString(Span<const char> input, Ref<i64> value)
return nullptr;
}
const char* fromCString(Span<const char> input, Ref<u16> value)
const char* fromCString(Span<const char> input, u16& value)
{
u32 tmp;
const char* ret = fromCString(input, Ref(tmp));
const char* ret = fromCString(input, tmp);
value = u16(tmp);
return ret;
}
const char* fromCString(Span<const char> input, Ref<u32> value)
const char* fromCString(Span<const char> input, u32& value)
{
u32 length = input.length();
if (length > 0)
@ -633,7 +633,7 @@ const char* fromCString(Span<const char> input, Ref<u32> value)
return nullptr;
}
const char* fromCStringOctal(Span<const char> input, Ref<u32> value)
const char* fromCStringOctal(Span<const char> input, u32& value)
{
u32 length = input.length();
if (length > 0)
@ -654,7 +654,7 @@ const char* fromCStringOctal(Span<const char> input, Ref<u32> value)
return nullptr;
}
const char* fromCString(Span<const char> input, Ref<u64> value)
const char* fromCString(Span<const char> input, u64& value)
{
u32 length = input.length();
if (length > 0)
@ -677,7 +677,7 @@ const char* fromCString(Span<const char> input, Ref<u64> value)
return nullptr;
}
const char* fromCString(Span<const char> input, Ref<bool> value)
const char* fromCString(Span<const char> input, bool& value)
{
value = equalIStrings(input, "true");
return input.end();

View file

@ -26,14 +26,14 @@ LUMIX_ENGINE_API bool toCString(u32 value, Span<char> output);
LUMIX_ENGINE_API bool toCString(float value, Span<char> output, int after_point);
LUMIX_ENGINE_API bool toCString(double value, Span<char> output, int after_point);
LUMIX_ENGINE_API const char* reverseFind(const char* begin_haystack, const char* end_haystack, char c);
LUMIX_ENGINE_API const char* fromCStringOctal(Span<const char> input, Ref<u32> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<i32> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<u64> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<i64> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<u32> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<u16> value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, Ref<bool> value);
inline const char* fromCString(Span<const char> input, Ref<EntityPtr> value) { return fromCString(input, Ref(value->index)); };
LUMIX_ENGINE_API const char* fromCStringOctal(Span<const char> input, u32& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, i32& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, u64& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, i64& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, u32& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, u16& value);
LUMIX_ENGINE_API const char* fromCString(Span<const char> input, bool& value);
inline const char* fromCString(Span<const char> input, EntityPtr& value) { return fromCString(input, value.index); };
LUMIX_ENGINE_API bool copyString(Span<char> output, const char* source);
LUMIX_ENGINE_API bool copyString(Span<char> output, Span<const char> source);
LUMIX_ENGINE_API bool copyNString(Span<char> output, const char* source, int N);

View file

@ -6,6 +6,7 @@
#include "engine/plugin.h"
#include "engine/prefab.h"
#include "engine/reflection.h"
#include "engine/string.h"
namespace Lumix
@ -56,7 +57,7 @@ Universe::Universe(Engine& engine, IAllocator& allocator)
, m_scenes(m_allocator)
, m_hierarchy(m_allocator)
, m_transforms(m_allocator)
, m_name(m_allocator)
, m_name("")
{
m_entities.reserve(RESERVED_ENTITIES_COUNT);
m_transforms.reserve(RESERVED_ENTITIES_COUNT);
@ -668,17 +669,20 @@ void Universe::serialize(OutputMemoryStream& serializer)
if (!m_hierarchy.empty()) serializer.write(&m_hierarchy[0], m_hierarchy.byte_size());
}
void Universe::setName(const char* name) {
copyString(m_name, name);
}
void Universe::deserialize(InputMemoryStream& serializer, Ref<EntityMap> entity_map)
void Universe::deserialize(InputMemoryStream& serializer, EntityMap& entity_map)
{
u32 to_reserve;
serializer.read(to_reserve);
entity_map->reserve(to_reserve);
entity_map.reserve(to_reserve);
for (EntityPtr e = serializer.read<EntityPtr>(); e.isValid(); e = serializer.read<EntityPtr>()) {
EntityRef orig = (EntityRef)e;
const EntityRef new_e = createEntity({0, 0, 0}, {0, 0, 0, 1});
entity_map->set(orig, new_e);
entity_map.set(orig, new_e);
serializer.read(m_transforms[new_e.index]);
}
@ -687,7 +691,7 @@ void Universe::deserialize(InputMemoryStream& serializer, Ref<EntityMap> entity_
for (u32 i = 0; i < count; ++i) {
EntityName& name = m_names.emplace();
serializer.read(name.entity);
name.entity = entity_map->get(name.entity);
name.entity = entity_map.get(name.entity);
copyString(name.name, serializer.readString());
m_entities[name.entity.index].name = m_names.size() - 1;
}
@ -699,10 +703,10 @@ void Universe::deserialize(InputMemoryStream& serializer, Ref<EntityMap> entity_
serializer.read(&m_hierarchy[old_count], sizeof(m_hierarchy[0]) * count);
for (u32 i = old_count; i < count + old_count; ++i) {
m_hierarchy[i].entity = entity_map->get(m_hierarchy[i].entity);
m_hierarchy[i].first_child = entity_map->get(m_hierarchy[i].first_child);
m_hierarchy[i].next_sibling = entity_map->get(m_hierarchy[i].next_sibling);
m_hierarchy[i].parent = entity_map->get(m_hierarchy[i].parent);
m_hierarchy[i].entity = entity_map.get(m_hierarchy[i].entity);
m_hierarchy[i].first_child = entity_map.get(m_hierarchy[i].first_child);
m_hierarchy[i].next_sibling = entity_map.get(m_hierarchy[i].next_sibling);
m_hierarchy[i].parent = entity_map.get(m_hierarchy[i].parent);
m_entities[m_hierarchy[i].entity.index].hierarchy = i;
}
}

View file

@ -5,7 +5,6 @@
#include "engine/delegate_list.h"
#include "engine/lumix.h"
#include "engine/math.h"
#include "engine/string.h"
namespace Lumix {
@ -94,8 +93,8 @@ struct LUMIX_ENGINE_API Universe {
float getScale(EntityRef entity) const;
const DVec3& getPosition(EntityRef entity) const;
const Quat& getRotation(EntityRef entity) const;
const char* getName() const { return m_name.c_str(); }
void setName(const char* name) { m_name = name; }
const char* getName() const { return m_name; }
void setName(const char* name);
DelegateList<void(EntityRef)>& entityCreated() { return m_entity_created; }
DelegateList<void(EntityRef)>& entityTransformed() { return m_entity_moved; }
@ -104,7 +103,7 @@ struct LUMIX_ENGINE_API Universe {
DelegateList<void(const ComponentUID&)>& componentAdded() { return m_component_added; }
void serialize(struct OutputMemoryStream& serializer);
void deserialize(struct InputMemoryStream& serializer, Ref<EntityMap> entity_map);
void deserialize(struct InputMemoryStream& serializer, EntityMap& entity_map);
IScene* getScene(ComponentType type) const;
IScene* getScene(u32 hash) const;
@ -149,7 +148,7 @@ private:
DelegateList<void(const ComponentUID&)> m_component_destroyed;
DelegateList<void(const ComponentUID&)> m_component_added;
int m_first_free_slot;
String m_name;
char m_name[64];
};
struct LUMIX_ENGINE_API ComponentUID final {

View file

@ -125,7 +125,7 @@ StackNode* StackTree::getParent(StackNode* node)
}
bool StackTree::getFunction(StackNode* node, Span<char> out, Ref<int> line)
bool StackTree::getFunction(StackNode* node, Span<char> out, int& line)
{
HANDLE process = GetCurrentProcess();
alignas(SYMBOL_INFO) u8 symbol_mem[sizeof(SYMBOL_INFO) + 256 * sizeof(char)] = {};

View file

@ -315,7 +315,7 @@ static void UTF32ToUTF8(u32 utf32, char* utf8)
}
}
bool getEvent(Ref<Event> event) {
bool getEvent(Event& event) {
if (!G.event_queue.empty()) {
event = G.event_queue.popFront();
return true;
@ -325,34 +325,34 @@ bool getEvent(Ref<Event> event) {
MSG msg;
if (!PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) return false;
event->window = msg.hwnd;
event.window = msg.hwnd;
switch (msg.message) {
case WM_DROPFILES:
event->type = Event::Type::DROP_FILE;
event->file_drop.handle = (HDROP)msg.wParam;
event.type = Event::Type::DROP_FILE;
event.file_drop.handle = (HDROP)msg.wParam;
break;
case WM_QUIT:
event->type = Event::Type::QUIT;
event.type = Event::Type::QUIT;
break;
case WM_CLOSE:
event->type = Event::Type::WINDOW_CLOSE;
event.type = Event::Type::WINDOW_CLOSE;
break;
case WM_SYSKEYDOWN:
if (msg.wParam == VK_MENU) goto retry;
break;
case WM_KEYDOWN:
event->type = Event::Type::KEY;
event->key.down = true;
event->key.keycode = (Keycode)msg.wParam;
event.type = Event::Type::KEY;
event.key.down = true;
event.key.keycode = (Keycode)msg.wParam;
break;
case WM_KEYUP:
event->type = Event::Type::KEY;
event->key.down = false;
event->key.keycode = (Keycode)msg.wParam;
event.type = Event::Type::KEY;
event.key.down = false;
event.key.keycode = (Keycode)msg.wParam;
break;
case WM_CHAR: {
event->type = Event::Type::CHAR;
event->text_input.utf8 = 0;
event.type = Event::Type::CHAR;
event.text_input.utf8 = 0;
u32 c = (u32)msg.wParam;
if (c >= 0xd800 && c <= 0xdbff) {
G.surrogate = (u16)c;
@ -368,7 +368,7 @@ bool getEvent(Ref<Event> event) {
}
G.surrogate = 0;
UTF32ToUTF8(c, (char*)&event->text_input.utf8);
UTF32ToUTF8(c, (char*)&event.text_input.utf8);
break;
}
case WM_INPUT: {

View file

@ -4,6 +4,9 @@
#ifndef _W64
#define _W64 __w64
#endif
#define SymGetLineFromAddr SymGetLineFromAddr64
#define CaptureStackBackTrace RtlCaptureStackBackTrace
#define IMAGEHLP_LINE IMAGEHLP_LINE64
#define ERROR_SUCCESS 0L
#define XUSER_MAX_COUNT 4
#define MEM_COMMIT 0x00001000
@ -24,9 +27,12 @@
#define WSABASEERR 10000
#define WSAEWOULDBLOCK (WSABASEERR + 35)
#define DECLSPEC_IMPORT __declspec(dllimport)
#define IMAGEAPI DECLSPEC_IMPORT __stdcall
#define WINBASEAPI DECLSPEC_IMPORT
#define WINUSERAPI DECLSPEC_IMPORT
#define NTSYSAPI DECLSPEC_IMPORT
#define WINAPI __stdcall
#define NTAPI __stdcall
#define GENERIC_READ (0x80000000L)
#define GENERIC_WRITE (0x40000000L)
#define FILE_SHARE_READ 0x00000001
@ -238,13 +244,41 @@ typedef unsigned int UINT;
typedef void* HINSTANCE;
typedef wchar_t WCHAR;
typedef WCHAR *NWPSTR, *LPWSTR, *PWSTR;
typedef unsigned __int64 ULONG64, *PULONG64;
typedef unsigned __int64 DWORD64, *PDWORD64;
typedef DWORD* PDWORD;
typedef CHAR* PCHAR;
typedef VOID (WINAPI *PFIBER_START_ROUTINE)(LPVOID lpFiberParameter);
typedef PFIBER_START_ROUTINE LPFIBER_START_ROUTINE;
typedef DWORD(WINAPI* PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
typedef struct _IMAGEHLP_LINE64 {
DWORD SizeOfStruct;
PVOID Key;
DWORD LineNumber;
PCHAR FileName;
DWORD64 Address;
} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
typedef struct _SYMBOL_INFO {
ULONG SizeOfStruct;
ULONG TypeIndex;
ULONG64 Reserved[2];
ULONG Index;
ULONG Size;
ULONG64 ModBase;
ULONG Flags;
ULONG64 Value;
ULONG64 Address;
ULONG Register;
ULONG Scope;
ULONG Tag;
ULONG NameLen;
ULONG MaxNameLen;
CHAR Name[1];
} SYMBOL_INFO, *PSYMBOL_INFO;
typedef struct in_addr
{
@ -282,6 +316,7 @@ typedef unsigned short WORD;
typedef short SHORT;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct _XINPUT_GAMEPAD
{
WORD wButtons;
@ -644,7 +679,13 @@ WINBASEAPI VOID WINAPI OutputDebugStringA(LPCSTR lpOutputString);
WINBASEAPI DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName);
WINUSERAPI BOOL WINAPI OpenClipboard(HWND hWndNewOwner);
WINUSERAPI HANDLE WINAPI SetClipboardData(UINT uFormat, HANDLE hMem);
WINBASEAPI VOID WINAPI DebugBreak(VOID);
BOOL IMAGEAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
BOOL IMAGEAPI SymCleanup(HANDLE hProcess);
BOOL IMAGEAPI SymRefreshModuleList(HANDLE hProcess);
BOOL IMAGEAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
BOOL IMAGEAPI SymGetLineFromAddr64(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line64);
NTSYSAPI WORD NTAPI RtlCaptureStackBackTrace(DWORD FramesToSkip, DWORD FramesToCapture, PVOID* BackTrace, PDWORD BackTraceHash);
WINBASEAPI HGLOBAL WINAPI LoadResource(HMODULE hModule, HRSRC hResInfo);
WINBASEAPI HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR lpName, LPCSTR lpType);
WINBASEAPI DWORD WINAPI SizeofResource(HMODULE hModule, HRSRC hResInfo);

View file

@ -351,7 +351,7 @@ private:
void set(GUIScene* scene, EntityRef e, const char* prop_name)
{
const bool found = reflection::getPropertyValue(*scene, e, GUI_RECT_TYPE, prop_name, Ref(value));
const bool found = reflection::getPropertyValue(*scene, e, GUI_RECT_TYPE, prop_name, value);
ASSERT(found);
prop = prop_name;
}

View file

@ -9,6 +9,7 @@
#include "engine/os.h"
#include "engine/reflection.h"
#include "engine/resource_manager.h"
#include "engine/string.h"
#include "engine/universe.h"
#include "gui_scene.h"
#include "gui_system.h"

View file

@ -3,6 +3,7 @@
#include "engine/lua_wrapper.h"
#include "engine/resource_manager.h"
#include "engine/stream.h"
#include "engine/string.h"
#include "renderer/texture.h"

View file

@ -14,13 +14,13 @@
#include "engine/file_system.h"
#include "engine/allocator.h"
#include "engine/log.h"
#include "engine/lua_wrapper.h"
#include "engine/os.h"
#include "engine/path.h"
#include "engine/stream.h"
#include "engine/universe.h"
#include "lua_script/lua_script.h"
#include "lua_script/lua_script_system.h"
#include <lua.hpp>
using namespace Lumix;
@ -66,7 +66,7 @@ struct AssetPlugin : AssetBrowser::IPlugin, AssetCompiler::IPlugin
{
FileSystem& fs = m_app.getEngine().getFileSystem();
os::OutputFile file;
if (!fs.open(script->getPath().c_str(), Ref(file)))
if (!fs.open(script->getPath().c_str(), file))
{
logWarning("Could not save ", script->getPath());
return;
@ -407,7 +407,7 @@ struct AddComponentPlugin final : StudioApp::IAddComponentPlugin
bool create_empty = ImGui::Selectable("Empty", false);
static u32 selected_res_hash = 0;
if (asset_browser.resourceList(Span(buf), Ref(selected_res_hash), LuaScript::TYPE, 0, false) || create_empty || new_created)
if (asset_browser.resourceList(Span(buf), selected_res_hash, LuaScript::TYPE, 0, false) || create_empty || new_created)
{
WorldEditor& editor = app.getWorldEditor();
if (create_entity)

View file

@ -51,7 +51,7 @@ namespace Lumix
lua_remove(L, -2); // [obj]
}
static void toVariant(reflection::Variant::Type type, lua_State* L, int idx, Ref<reflection::Variant> val) {
static void toVariant(reflection::Variant::Type type, lua_State* L, int idx, reflection::Variant& val) {
switch(type) {
case reflection::Variant::BOOL: val = LuaWrapper::toType<bool>(L, idx); break;
case reflection::Variant::U32: val = LuaWrapper::toType<u32>(L, idx); break;
@ -107,7 +107,7 @@ namespace Lumix
ASSERT(f->getArgCount() <= lengthOf(args));
for (u32 i = 0; i < f->getArgCount(); ++i) {
reflection::Variant::Type type = f->getArgType(i);
toVariant(type, L, i + 2, Ref(args[i]));
toVariant(type, L, i + 2, args[i]);
}
const reflection::Variant res = f->invoke(obj, Span(args, f->getArgCount()));
@ -127,7 +127,7 @@ namespace Lumix
ASSERT(f->getArgCount() <= lengthOf(args));
for (u32 i = 0; i < f->getArgCount(); ++i) {
reflection::Variant::Type type = f->getArgType(i);
toVariant(type, L, i + 2, Ref(args[i]));
toVariant(type, L, i + 2, args[i]);
}
const reflection::Variant res = f->invoke(scene, Span(args, f->getArgCount()));
if (res.type == reflection::Variant::ENTITY) {
@ -161,7 +161,7 @@ namespace Lumix
args[0] = entity;
for (u32 i = 1; i < f->getArgCount(); ++i) {
reflection::Variant::Type type = f->getArgType(i);
toVariant(type, L, i + 1, Ref(args[i]));
toVariant(type, L, i + 1, args[i]);
}
const reflection::Variant res = f->invoke(scene, Span(args, f->getArgCount()));
if (res.type == reflection::Variant::ENTITY) {
@ -214,7 +214,7 @@ namespace Lumix
template <typename T> static T fromString(const char* val) {
T res;
fromCString(Span(val, stringLength(val) + 1), Ref(res));
fromCString(Span(val, stringLength(val) + 1), res);
return res;
}
@ -232,19 +232,19 @@ namespace Lumix
return r;
}
template <typename T> static void toString(T val, Ref<String> out) {
template <typename T> static void toString(T val, String& out) {
char tmp[128];
toCString(val, Span(tmp));
out = tmp;
}
template <> void toString(float val, Ref<String> out) {
template <> void toString(float val, String& out) {
char tmp[128];
toCString(val, Span(tmp), 10);
out = tmp;
}
template <> void toString(Vec3 val, Ref<String> out) {
template <> void toString(Vec3 val, String& out) {
StaticString<512> tmp("{", val.x, ", ", val.y, ", ", val.z, "}");
out = tmp;
}
@ -1341,7 +1341,7 @@ namespace Lumix
if (!script_cmp) return;
Property& prop = getScriptProperty(entity, scr_index, property_name);
if (!script_cmp->m_scripts[scr_index].m_state) {
toString(value, Ref(prop.stored_value));
toString(value, prop.stored_value);
return;
}
@ -1778,7 +1778,7 @@ namespace Lumix
const char* tmp = serializer.readString();
if (type == Property::ENTITY) {
EntityPtr entity;
fromCString(Span(tmp, stringLength(tmp)), Ref(entity.index));
fromCString(Span(tmp, stringLength(tmp)), entity.index);
entity = entity_map.get(entity);
StaticString<64> buf(entity.index);
prop.stored_value = buf;

View file

@ -686,7 +686,7 @@ struct NavigationSceneImpl final : NavigationScene
FileSystem& fs = m_engine.getFileSystem();
os::OutputFile file;
if (!fs.open(path, Ref(file))) return false;
if (!fs.open(path, file)) return false;
bool success = file.write(&m_num_tiles_x, sizeof(m_num_tiles_x));
success = success && file.write(&m_num_tiles_z, sizeof(m_num_tiles_z));

View file

@ -14,6 +14,7 @@
#include "engine/log.h"
#include "engine/lua_wrapper.h"
#include "engine/resource_manager.h"
#include "engine/string.h"
#include "engine/universe.h"
#include "physics/physics_geometry.h"
#include "physics/physics_scene.h"

View file

@ -3,6 +3,7 @@
#include "engine/lua_wrapper.h"
#include "engine/os.h"
#include "engine/stream.h"
#include "engine/string.h"
namespace Lumix {
@ -103,7 +104,7 @@ CompositeTexture::CompositeTexture(IAllocator& allocator)
bool CompositeTexture::loadSync(FileSystem& fs, const Path& path) {
OutputMemoryStream data(allocator);
if (!fs.getContentSync(path, Ref(data))) return false;
if (!fs.getContentSync(path, data)) return false;
if (!init(Span(data.data(), (u32)data.size()), path.c_str())) return false;
return true;
@ -111,7 +112,7 @@ bool CompositeTexture::loadSync(FileSystem& fs, const Path& path) {
bool CompositeTexture::save(FileSystem& fs, const Path& path) {
os::OutputFile file;
if (fs.open(path.c_str(), Ref(file))) {
if (fs.open(path.c_str(), file)) {
for (CompositeTexture::Layer& layer : layers) {
file << "layer {\n";
file << "\tred = { \"" << layer.red.path.c_str() << "\", " << layer.red.src_channel << " },\n";

View file

@ -422,7 +422,7 @@ static int getMaterialIndex(const ofbx::Mesh& mesh, const ofbx::Material& materi
}
static void centerMesh(const ofbx::Vec3* vertices, int vertices_count, bool bottom, Ref<Matrix> transform, Ref<Vec3> center)
static void centerMesh(const ofbx::Vec3* vertices, int vertices_count, bool bottom, Matrix& transform, Vec3& center)
{
if (vertices_count <= 0) return;
@ -442,15 +442,15 @@ static void centerMesh(const ofbx::Vec3* vertices, int vertices_count, bool bott
max.z = maximum(max.z, v.z);
}
center->x = float(min.x + max.x) * 0.5f;
center->y = float(min.y + max.y) * 0.5f;
center->z = float(min.z + max.z) * 0.5f;
center.x = float(min.x + max.x) * 0.5f;
center.y = float(min.y + max.y) * 0.5f;
center.z = float(min.z + max.z) * 0.5f;
if (bottom) center->y = (float)min.y;
if (bottom) center.y = (float)min.y;
const Vec3 p = transform->getTranslation();
transform->setTranslation(-center.value);
center.value += p;
const Vec3 p = transform.getTranslation();
transform.setTranslation(-center);
center += p;
}
@ -687,7 +687,7 @@ void FBXImporter::postprocessMeshes(const ImportConfig& cfg, const char* path)
if (cancel_mesh_transforms) transform_matrix.setTranslation({0, 0, 0});
if (cfg.origin != ImportConfig::Origin::SOURCE) {
const bool bottom = cfg.origin == FBXImporter::ImportConfig::Origin::BOTTOM;
centerMesh(vertices, vertex_count, bottom, Ref(transform_matrix), Ref(import_mesh.origin));
centerMesh(vertices, vertex_count, bottom, transform_matrix, import_mesh.origin);
}
import_mesh.transform_matrix = transform_matrix.inverted();
@ -796,7 +796,7 @@ static int detectMeshLOD(const FBXImporter::ImportMesh& mesh)
lod_str += stringLength("_LOD");
int lod;
fromCString(Span(lod_str, stringLength(lod_str)), Ref(lod));
fromCString(Span(lod_str, stringLength(lod_str)), lod);
return lod;
}
@ -890,7 +890,7 @@ bool FBXImporter::setSource(const char* filename, bool ignore_geometry, bool for
}
OutputMemoryStream data(m_allocator);
if (!m_filesystem.getContentSync(Path(filename), Ref(data))) return false;
if (!m_filesystem.getContentSync(Path(filename), data)) return false;
const u64 flags = ignore_geometry ? (u64)ofbx::LoadFlags::IGNORE_GEOMETRY : (u64)ofbx::LoadFlags::TRIANGULATE;
scene = ofbx::load(data.data(), (i32)data.size(), flags, &ofbx_job_processor, nullptr);
@ -945,7 +945,7 @@ static Vec3 impostorToWorld(Vec2 uv) {
static constexpr u32 IMPOSTOR_TILE_SIZE = 512;
static constexpr u32 IMPOSTOR_COLS = 9;
static void getBBProjection(const AABB& aabb, Ref<Vec2> out_min, Ref<Vec2> out_max) {
static void getBBProjection(const AABB& aabb, Vec2& out_min, Vec2& out_max) {
const float radius = length(aabb.max - aabb.min) * 0.5f;
const Vec3 center = (aabb.min + aabb.max) * 0.5f;
@ -978,7 +978,7 @@ static void getBBProjection(const AABB& aabb, Ref<Vec2> out_min, Ref<Vec2> out_m
struct CaptureImpostorJob : Renderer::RenderJob {
CaptureImpostorJob(Ref<Array<u32>> gb0, Ref<Array<u32>> gb1, Ref<Array<u32>> shadow, Ref<IVec2> size, IAllocator& allocator)
CaptureImpostorJob(Array<u32>& gb0, Array<u32>& gb1, Array<u32>& shadow, IVec2& size, IAllocator& allocator)
: m_gb0(gb0)
, m_gb1(gb1)
, m_shadow(shadow)
@ -1013,13 +1013,13 @@ struct CaptureImpostorJob : Renderer::RenderJob {
const Vec3 center = Vec3(0, (m_aabb.min + m_aabb.max).y * 0.5f, 0);
Vec2 min, max;
getBBProjection(m_aabb, Ref(min), Ref(max));
getBBProjection(m_aabb, min, max);
const Vec2 size = max - min;
m_tile_size = IVec2(int(IMPOSTOR_TILE_SIZE * size.x / size.y), IMPOSTOR_TILE_SIZE);
m_tile_size->x = (m_tile_size->x + 3) & ~3;
m_tile_size->y = (m_tile_size->y + 3) & ~3;
const IVec2 texture_size = m_tile_size.value * IMPOSTOR_COLS;
m_tile_size.x = (m_tile_size.x + 3) & ~3;
m_tile_size.y = (m_tile_size.y + 3) & ~3;
const IVec2 texture_size = m_tile_size * IMPOSTOR_COLS;
gpu::createTexture(gbs[0], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb0");
gpu::createTexture(gbs[1], texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS, nullptr, "impostor_gb1");
gpu::createTexture(gbs[2], texture_size.x, texture_size.y, 1, gpu::TextureFormat::D32, gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::POINT_FILTER, nullptr, "impostor_gbd");
@ -1030,7 +1030,7 @@ struct CaptureImpostorJob : Renderer::RenderJob {
for (u32 j = 0; j < IMPOSTOR_COLS; ++j) {
for (u32 i = 0; i < IMPOSTOR_COLS; ++i) {
gpu::viewport(i * m_tile_size->x, j * m_tile_size->y, m_tile_size->x, m_tile_size->y);
gpu::viewport(i * m_tile_size.x, j * m_tile_size.y, m_tile_size.x, m_tile_size.y);
const Vec3 v = impostorToWorld({i / (float)(IMPOSTOR_COLS - 1), j / (float)(IMPOSTOR_COLS - 1)});
Matrix model_mtx;
@ -1067,9 +1067,9 @@ struct CaptureImpostorJob : Renderer::RenderJob {
gpu::setFramebuffer(nullptr, 0, gpu::INVALID_TEXTURE, gpu::FramebufferFlags::NONE);
m_gb0->resize(texture_size.x * texture_size.y);
m_gb1->resize(m_gb0->size());
m_shadow->resize(m_gb0->size());
m_gb0.resize(texture_size.x * texture_size.y);
m_gb1.resize(m_gb0.size());
m_shadow.resize(m_gb0.size());
gpu::TextureHandle shadow = gpu::allocTextureHandle();
gpu::createTexture(shadow, texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::COMPUTE_WRITE, nullptr, "impostor_shadow");
@ -1097,11 +1097,11 @@ struct CaptureImpostorJob : Renderer::RenderJob {
data.projection = projection;
data.center = Vec4(center, 1);
data.tile = IVec2(i, j);
data.tile_size = m_tile_size.value;
data.tile_size = m_tile_size;
data.size = IMPOSTOR_COLS;
data.radius = m_radius;
gpu::update(ub, &data, sizeof(data));
gpu::dispatch((m_tile_size->x + 15) / 16, (m_tile_size->y + 15) / 16, 1);
gpu::dispatch((m_tile_size.x + 15) / 16, (m_tile_size.y + 15) / 16, 1);
}
}
@ -1109,13 +1109,13 @@ struct CaptureImpostorJob : Renderer::RenderJob {
const gpu::TextureFlags flags = gpu::TextureFlags::NO_MIPS | gpu::TextureFlags::READBACK;
gpu::createTexture(staging, texture_size.x, texture_size.y, 1, gpu::TextureFormat::RGBA8, flags, nullptr, "staging_buffer");
gpu::copy(staging, gbs[0], 0, 0);
gpu::readTexture(staging, 0, Span((u8*)m_gb0->begin(), m_gb0->byte_size()));
gpu::readTexture(staging, 0, Span((u8*)m_gb0.begin(), m_gb0.byte_size()));
gpu::copy(staging, gbs[1], 0, 0);
gpu::readTexture(staging, 0, Span((u8*)m_gb1->begin(), m_gb1->byte_size()));
gpu::readTexture(staging, 0, Span((u8*)m_gb1.begin(), m_gb1.byte_size()));
gpu::copy(staging, shadow, 0, 0);
gpu::readTexture(staging, 0, Span((u8*)m_shadow->begin(), m_shadow->byte_size()));
gpu::readTexture(staging, 0, Span((u8*)m_shadow.begin(), m_shadow.byte_size()));
gpu::destroy(staging);
gpu::destroy(ub);
@ -1136,15 +1136,15 @@ struct CaptureImpostorJob : Renderer::RenderJob {
AABB m_aabb;
float m_radius;
gpu::BufferHandle m_material_ub;
Ref<Array<u32>> m_gb0;
Ref<Array<u32>> m_gb1;
Ref<Array<u32>> m_shadow;
Array<u32>& m_gb0;
Array<u32>& m_gb1;
Array<u32>& m_shadow;
Model* m_model;
u32 m_capture_define;
Ref<IVec2> m_tile_size;
IVec2& m_tile_size;
};
bool FBXImporter::createImpostorTextures(Model* model, Ref<Array<u32>> gb0_rgba, Ref<Array<u32>> gb1_rgba, Ref<Array<u32>> shadow, Ref<IVec2> size)
bool FBXImporter::createImpostorTextures(Model* model, Array<u32>& gb0_rgba, Array<u32>& gb1_rgba, Array<u32>& shadow, IVec2& size)
{
ASSERT(model->isReady());
ASSERT(m_impostor_shadow_shader->isReady());
@ -1166,7 +1166,7 @@ bool FBXImporter::createImpostorTextures(Model* model, Ref<Array<u32>> gb0_rgba,
const PathInfo src_info(model->getPath().c_str());
const StaticString<LUMIX_MAX_PATH> mat_src(src_info.m_dir, src_info.m_basename, "_impostor.mat");
os::OutputFile f;
if (!m_filesystem.open(mat_src, Ref(f))) {
if (!m_filesystem.open(mat_src, f)) {
logError("Failed to create ", mat_src);
}
else {
@ -1204,7 +1204,7 @@ void FBXImporter::writeMaterials(const char* src, const ImportConfig& cfg)
if (m_filesystem.fileExists(mat_src)) continue;
os::OutputFile f;
if (!m_filesystem.open(mat_src, Ref(f)))
if (!m_filesystem.open(mat_src, f))
{
logError("Failed to create ", mat_src);
continue;
@ -1220,7 +1220,7 @@ void FBXImporter::writeMaterials(const char* src, const ImportConfig& cfg)
const StaticString<LUMIX_MAX_PATH> meta_path(texture.src, ".meta");
if (!m_filesystem.fileExists(meta_path)) {
os::OutputFile file;
if (m_filesystem.open(meta_path, Ref(file))) {
if (m_filesystem.open(meta_path, file)) {
file << (idx == 0 ? "srgb = true\n" : "normalmap = true\n");
file.close();
@ -1261,7 +1261,7 @@ void FBXImporter::writeMaterials(const char* src, const ImportConfig& cfg)
const StaticString<LUMIX_MAX_PATH> mat_src(src_info.m_dir, src_info.m_basename, "_impostor.mat");
if (!m_filesystem.fileExists(mat_src)) {
os::OutputFile f;
if (!m_filesystem.open(mat_src, Ref(f))) {
if (!m_filesystem.open(mat_src, f)) {
logError("Failed to create ", mat_src);
}
else {
@ -1277,7 +1277,7 @@ void FBXImporter::writeMaterials(const char* src, const ImportConfig& cfg)
}
}
static void convert(const ofbx::Matrix& mtx, Ref<Vec3> pos, Ref<Quat> rot)
static void convert(const ofbx::Matrix& mtx, Vec3& pos, Quat& rot)
{
Matrix m = toLumix(mtx);
m.normalizeScale();
@ -1286,23 +1286,23 @@ static void convert(const ofbx::Matrix& mtx, Ref<Vec3> pos, Ref<Quat> rot)
}
template <typename T>
static void fillTimes(const ofbx::AnimationCurve* curve, Ref<Array<T>> out){
static void fillTimes(const ofbx::AnimationCurve* curve, Array<T>& out){
if(!curve) return;
const i64* times = curve->getKeyTime();
for (u32 i = 0, c = curve->getKeyCount(); i < c; ++i) {
if (out->empty()) {
out->emplace().time = times[i];
if (out.empty()) {
out.emplace().time = times[i];
}
else if (times[i] > out->back().time) {
out->emplace().time = times[i];
else if (times[i] > out.back().time) {
out.emplace().time = times[i];
}
else {
for (const T& k : out.value) {
for (const T& k : out) {
if (k.time == times[i]) break;
if (times[i] < k.time) {
const u32 idx = u32(&k - out->begin());
out->emplaceAt(idx).time = times[i];
const u32 idx = u32(&k - out.begin());
out.emplaceAt(idx).time = times[i];
break;
}
}
@ -1334,9 +1334,8 @@ static float evalCurve(i64 time, const ofbx::AnimationCurve& curve) {
// parent_scale - animated scale is not supported, but we can get rid of static scale if we ignore
// it in writeSkeleton() and use `parent_scale` in this function
static void compressPositions(float error, float parent_scale, Ref<Array<FBXImporter::Key>> keys)
static void compressPositions(float error, float parent_scale, Array<FBXImporter::Key>& out)
{
Array<FBXImporter::Key>& out = keys.value;
if (out.empty()) return;
Vec3 dir = out[1].pos - out[0].pos;
@ -1359,10 +1358,8 @@ static void compressPositions(float error, float parent_scale, Ref<Array<FBXImpo
}
}
static void compressRotations(float error,
Ref<Array<FBXImporter::Key>> keys)
static void compressRotations(float error, Array<FBXImporter::Key>& out)
{
Array<FBXImporter::Key>& out = keys.value;
if (out.empty()) return;
u32 prev = 0;
@ -1387,13 +1384,13 @@ static float getScaleX(const ofbx::Matrix& mtx)
return length(v);
}
static void fill(const ofbx::Object& bone, double anim_len, const ofbx::AnimationLayer& layer, Ref<Array<FBXImporter::Key>> keys) {
static void fill(const ofbx::Object& bone, double anim_len, const ofbx::AnimationLayer& layer, Array<FBXImporter::Key>& keys) {
const ofbx::AnimationCurveNode* translation_node = layer.getCurveNode(bone, "Lcl Translation");
const ofbx::AnimationCurveNode* rotation_node = layer.getCurveNode(bone, "Lcl Rotation");
if (!translation_node && !rotation_node) return;
keys->emplace().time = 0;
keys->emplace().time = ofbx::secondsToFbxTime(anim_len);
keys.emplace().time = 0;
keys.emplace().time = ofbx::secondsToFbxTime(anim_len);
if (translation_node) {
fillTimes(translation_node->getCurve(0), keys);
fillTimes(translation_node->getCurve(1), keys);
@ -1409,13 +1406,13 @@ static void fill(const ofbx::Object& bone, double anim_len, const ofbx::Animatio
auto fill_rot = [&](u32 idx, const ofbx::AnimationCurve* curve) {
if (!curve) {
const ofbx::Vec3 lcl_rot = bone.getLocalRotation();
for (FBXImporter::Key& k : keys.value) {
for (FBXImporter::Key& k : keys) {
(&k.rot.x)[idx] = float((&lcl_rot.x)[idx]);
}
return;
}
for (FBXImporter::Key& k : keys.value) {
for (FBXImporter::Key& k : keys) {
(&k.rot.x)[idx] = evalCurve(k.time, *curve);
}
};
@ -1423,13 +1420,13 @@ static void fill(const ofbx::Object& bone, double anim_len, const ofbx::Animatio
auto fill_pos = [&](u32 idx, const ofbx::AnimationCurve* curve) {
if (!curve) {
const ofbx::Vec3 lcl_pos = bone.getLocalTranslation();
for (FBXImporter::Key& k : keys.value) {
for (FBXImporter::Key& k : keys) {
(&k.pos.x)[idx] = float((&lcl_pos.x)[idx]);
}
return;
}
for (FBXImporter::Key& k : keys.value) {
for (FBXImporter::Key& k : keys) {
(&k.pos.x)[idx] = evalCurve(k.time, *curve);
}
};
@ -1442,9 +1439,9 @@ static void fill(const ofbx::Object& bone, double anim_len, const ofbx::Animatio
fill_pos(1, translation_node ? translation_node->getCurve(1) : nullptr);
fill_pos(2, translation_node ? translation_node->getCurve(2) : nullptr);
for (FBXImporter::Key& key : keys.value) {
for (FBXImporter::Key& key : keys) {
const ofbx::Matrix mtx = bone.evalLocal({key.pos.x, key.pos.y, key.pos.z}, {key.rot.x, key.rot.y, key.rot.z});
convert(mtx, Ref(key.pos), Ref(key.rot));
convert(mtx, key.pos, key.rot);
}
}
@ -1486,7 +1483,7 @@ static LocalRigidTransform sample(const ofbx::Object& bone, const ofbx::Animatio
}
const ofbx::Matrix mtx = bone.evalLocal({res.pos.x, res.pos.y, res.pos.z}, {euler_angles.x, euler_angles.y, euler_angles.z});
convert(mtx, Ref(res.pos), Ref(res.rot));
convert(mtx, res.pos, res.rot);
return res;
}
@ -1557,7 +1554,7 @@ void FBXImporter::writeAnimations(const char* src, const ImportConfig& cfg)
all_keys.reserve(m_bones.size());
for (const ofbx::Object* bone : m_bones) {
Array<Key>& keys = all_keys.emplace(m_allocator);
fill(*bone, anim_len, *layer, Ref(keys));
fill(*bone, anim_len, *layer, keys);
}
for (const ofbx::Object*& bone : m_bones) {
@ -1565,8 +1562,8 @@ void FBXImporter::writeAnimations(const char* src, const ImportConfig& cfg)
ofbx::Object* parent = bone->getParent();
const float parent_scale = parent ? (float)getScaleX(parent->getGlobalTransform()) : 1;
// TODO skip curves which do not change anything
compressRotations(cfg.rotation_error, Ref(keys));
compressPositions(cfg.position_error, parent_scale, Ref(keys));
compressRotations(cfg.rotation_error, keys);
compressPositions(cfg.position_error, parent_scale, keys);
}
const u64 stream_translations_count_pos = out_file.size();
@ -1816,7 +1813,7 @@ void FBXImporter::writeImpostorVertices(const AABB& aabb)
const Vec3 center = Vec3(0, (aabb.max + aabb.min).y * 0.5f, 0);
Vec2 min, max;
getBBProjection(aabb, Ref(min), Ref(max));
getBBProjection(aabb, min, max);
const Vertex vertices[] = {
{{center.x + min.x, center.y + min.y, center.z}, {128, 255, 128, 0}, {255, 128, 128, 0}, {0, 0}},
@ -2219,7 +2216,7 @@ void FBXImporter::writePrefab(const char* src, const ImportConfig& cfg)
os::OutputFile file;
PathInfo file_info(src);
StaticString<LUMIX_MAX_PATH> tmp(file_info.m_dir, "/", file_info.m_basename, ".fab");
if (!m_filesystem.open(tmp, Ref(file))) {
if (!m_filesystem.open(tmp, file)) {
logError("Could not create ", tmp);
return;
}

View file

@ -153,7 +153,7 @@ struct FBXImporter
void writePrefab(const char* src, const ImportConfig& cfg);
void writeModel(const char* src, const ImportConfig& cfg);
void writePhysics(const char* src, const ImportConfig& cfg);
bool createImpostorTextures(struct Model* model, Ref<Array<u32>> gb0_rgba, Ref<Array<u32>> gb1_rgba, Ref<Array<u32>> shadow, Ref<IVec2> size);
bool createImpostorTextures(struct Model* model, Array<u32>& gb0_rgba, Array<u32>& gb1_rgba, Array<u32>& shadow, IVec2& size);
const Array<ImportMesh>& getMeshes() const { return m_meshes; }
const Array<ImportAnimation>& getAnimations() const { return m_animations; }

View file

@ -368,7 +368,7 @@ struct ParticleEmitterPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlug
bool compile(const Path& src) override {
FileSystem& fs = m_app.getEngine().getFileSystem();
OutputMemoryStream src_data(m_app.getAllocator());
if (!fs.getContentSync(src, Ref(src_data))) return false;
if (!fs.getContentSync(src, src_data)) return false;
InputMemoryStream input(src_data);
OutputMemoryStream output(m_app.getAllocator());
@ -927,7 +927,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
if (sources.find(ch.path.getHash()).isValid()) return true;
tmp_src.clear();
if (!fs.getContentSync(ch.path, Ref(tmp_src))) {
if (!fs.getContentSync(ch.path, tmp_src)) {
return false;
}
@ -1152,7 +1152,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
FileSystem& fs = m_app.getEngine().getFileSystem();
OutputMemoryStream src_data(m_app.getAllocator());
if (!fs.getContentSync(src, Ref(src_data))) return false;
if (!fs.getContentSync(src, src_data)) return false;
OutputMemoryStream out(m_app.getAllocator());
Meta meta = getMeta(src);
@ -1216,7 +1216,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
m_composite_tag = &texture;
IAllocator& allocator = m_app.getAllocator();
OutputMemoryStream content(allocator);
if (fs.getContentSync(texture.getPath(), Ref(content))) {
if (fs.getContentSync(texture.getPath(), content)) {
m_composite.init(Span(content.data(), (u32)content.size()), texture.getPath().c_str());
}
else {
@ -1858,14 +1858,14 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
}
static void postprocessImpostor(Ref<Array<u32>> gb0, Ref<Array<u32>> gb1, const IVec2& tile_size, IAllocator& allocator) {
static void postprocessImpostor(Array<u32>& gb0, Array<u32>& gb1, const IVec2& tile_size, IAllocator& allocator) {
struct Cell {
i16 x, y;
};
const IVec2 size = tile_size * 9;
Array<Cell> cells(allocator);
cells.resize(gb0->size());
const u32* data = gb0->begin();
cells.resize(gb0.size());
const u32* data = gb0.begin();
for (i32 j = 0; j < size.y; ++j) {
for (i32 i = 0; i < size.x; ++i) {
const u32 idx = i + j * size.x;
@ -1937,7 +1937,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
}
Array<u32> tmp(allocator);
tmp.resize(gb0->size());
tmp.resize(gb0.size());
if (cells[0].x >= 0) {
for (i32 j = 0; j < size.y; ++j) {
for (i32 i = 0; i < size.x; ++i) {
@ -1947,21 +1947,21 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
tmp[idx] = (alpha << 24) | (tmp[idx] & 0xffFFff);
}
}
memcpy(gb0->begin(), tmp.begin(), tmp.byte_size());
memcpy(gb0.begin(), tmp.begin(), tmp.byte_size());
const u32* gb1_data = gb1->begin();
const u32* gb1_data = gb1.begin();
for (i32 j = 0; j < size.y; ++j) {
for (i32 i = 0; i < size.x; ++i) {
const u32 idx = i + j * size.x;
tmp[idx] = gb1_data[cells[idx].x + cells[idx].y * size.x];
}
}
memcpy(gb1->begin(), tmp.begin(), tmp.byte_size());
memcpy(gb1.begin(), tmp.begin(), tmp.byte_size());
}
else {
// nothing was rendered
memset(gb0->begin(), 0xff, gb0->byte_size());
memset(gb1->begin(), 0xff, gb1->byte_size());
memset(gb0.begin(), 0xff, gb0.byte_size());
memset(gb1.begin(), 0xff, gb1.byte_size());
}
}
@ -2169,15 +2169,15 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
Array<u32> gb1(allocator);
Array<u32> shadow(allocator);
IVec2 tile_size;
importer.createImpostorTextures(model, Ref(gb0), Ref(gb1), Ref(shadow), Ref(tile_size));
postprocessImpostor(Ref(gb0), Ref(gb1), tile_size, allocator);
importer.createImpostorTextures(model, gb0, gb1, shadow, tile_size);
postprocessImpostor(gb0, gb1, tile_size, allocator);
const PathInfo fi(model->getPath().c_str());
StaticString<LUMIX_MAX_PATH> img_path(fi.m_dir, fi.m_basename, "_impostor0.tga");
ASSERT(gb0.size() == tile_size.x * 9 * tile_size.y * 9);
os::OutputFile file;
FileSystem& fs = m_app.getWorldEditor().getEngine().getFileSystem();
if (fs.open(img_path, Ref(file))) {
if (fs.open(img_path, file)) {
Texture::saveTGA(&file, tile_size.x * 9, tile_size.y * 9, gpu::TextureFormat::RGBA8, (const u8*)gb0.begin(), gpu::isOriginBottomLeft(), Path(img_path), allocator);
file.close();
}
@ -2187,7 +2187,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
img_path = fi.m_dir;
img_path << fi.m_basename << "_impostor1.tga";
if (fs.open(img_path, Ref(file))) {
if (fs.open(img_path, file)) {
Texture::saveTGA(&file, tile_size.x * 9, tile_size.y * 9, gpu::TextureFormat::RGBA8, (const u8*)gb1.begin(), gpu::isOriginBottomLeft(), Path(img_path), allocator);
file.close();
}
@ -2197,7 +2197,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
img_path = fi.m_dir;
img_path << fi.m_basename << "_impostor2.tga";
if (fs.open(img_path, Ref(file))) {
if (fs.open(img_path, file)) {
Texture::saveTGA(&file, tile_size.x * 9, tile_size.y * 9, gpu::TextureFormat::RGBA8, (const u8*)shadow.begin(), gpu::isOriginBottomLeft(), Path(img_path), allocator);
file.close();
}
@ -2333,7 +2333,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin
if (!renderer) return;
EntityMap entity_map(m_app.getAllocator());
if (!engine.instantiatePrefab(*m_tile.universe, *prefab, DVec3(0), Quat::IDENTITY, 1, Ref(entity_map))) return;
if (!engine.instantiatePrefab(*m_tile.universe, *prefab, DVec3(0), Quat::IDENTITY, 1, entity_map)) return;
if (entity_map.m_map.empty() || !entity_map.m_map[0].isValid()) return;
m_tile.path_hash = prefab->getPath().getHash();
@ -2696,7 +2696,7 @@ void captureCubemap(StudioApp& app
, Pipeline& pipeline
, const u32 texture_size
, const DVec3& position
, Ref<Array<Vec4>> data
, Array<Vec4>& data
, F&& f) {
memoryBarrier();
@ -2721,7 +2721,7 @@ void captureCubemap(StudioApp& app
Vec3 ups[] = {{0, 1, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, 1, 0}};
Vec3 ups_opengl[] = { { 0, -1, 0 },{ 0, -1, 0 },{ 0, 0, 1 },{ 0, 0, -1 },{ 0, -1, 0 },{ 0, -1, 0 } };
data->resize(6 * texture_size * texture_size);
data.resize(6 * texture_size * texture_size);
const bool ndc_bottom_left = gpu::isOriginBottomLeft();
for (int i = 0; i < 6; ++i) {
@ -2741,7 +2741,7 @@ void captureCubemap(StudioApp& app
, texture_size
, texture_size
, gpu::TextureFormat::RGBA32F
, Span((u8*)(data->begin() + (i * texture_size * texture_size)), u32(texture_size * texture_size * sizeof(*data->begin())))
, Span((u8*)(data.begin() + (i * texture_size * texture_size)), u32(texture_size * texture_size * sizeof(*data.begin())))
);
}
@ -2917,7 +2917,7 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
void render(ProbeJob& job) {
const u32 texture_size = job.is_reflection ? job.reflection_probe.size : 128;
captureCubemap(m_app, *m_pipeline, texture_size, job.position, Ref(job.data), [&job](){
captureCubemap(m_app, *m_pipeline, texture_size, job.position, job.data, [&job](){
jobs::run(&job, [](void* ptr) {
ProbeJob* pjob = (ProbeJob*)ptr;
pjob->plugin.processData(*pjob);
@ -3361,7 +3361,7 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
{
}
gpu::ProgramHandle getProgram(void* window_handle, Ref<bool> new_program) {
gpu::ProgramHandle getProgram(void* window_handle, bool& new_program) {
auto iter = plugin->m_programs.find(window_handle);
if (!iter.isValid()) {
plugin->m_programs.insert(window_handle, gpu::allocProgramHandle());
@ -3388,7 +3388,7 @@ struct EditorUIRenderPlugin final : StudioApp::GUIPlugin
dd.x = i32(draw_data->DisplayPos.x);
dd.y = i32(draw_data->DisplayPos.y);
dd.window = vp->PlatformHandle;
dd.program = getProgram(dd.window, Ref(dd.new_program));
dd.program = getProgram(dd.window, dd.new_program);
dd.cmd_lists.reserve(draw_data->CmdListsCount);
for (int i = 0; i < draw_data->CmdListsCount; ++i) {
@ -3795,7 +3795,7 @@ struct AddTerrainComponentPlugin final : StudioApp::IAddComponentPlugin
}
bool create_empty = ImGui::Selectable("Empty", false);
static u32 selected_res_hash = 0;
if (asset_browser.resourceList(Span(buf), Ref(selected_res_hash), Material::TYPE, 0, false) || create_empty || new_created)
if (asset_browser.resourceList(Span(buf), selected_res_hash, Material::TYPE, 0, false) || create_empty || new_created)
{
if (create_entity)
{
@ -3937,13 +3937,13 @@ struct StudioAppPlugin : StudioApp::IPlugin
const Gizmo::Config& cfg = m_app.getGizmoConfig();
WorldEditor& editor = m_app.getWorldEditor();
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 33), view, Ref(tr), Ref(p.inner_range), cfg, true)) {
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 33), view, tr, p.inner_range, cfg, true)) {
editor.beginCommandGroup("env_probe_inner_range");
editor.setProperty(ENVIRONMENT_PROBE_TYPE, "", -1, "Inner range", Span(&e, 1), p.inner_range);
editor.setEntitiesPositions(&e, &tr.pos, 1);
editor.endCommandGroup();
}
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 32), view, Ref(tr), Ref(p.outer_range), cfg, false)) {
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 32), view, tr, p.outer_range, cfg, false)) {
editor.beginCommandGroup("env_probe_outer_range");
editor.setProperty(ENVIRONMENT_PROBE_TYPE, "", -1, "Outer range", Span(&e, 1), p.outer_range);
editor.setEntitiesPositions(&e, &tr.pos, 1);
@ -3963,7 +3963,7 @@ struct StudioAppPlugin : StudioApp::IPlugin
const Gizmo::Config& cfg = m_app.getGizmoConfig();
WorldEditor& editor = m_app.getWorldEditor();
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 32), view, Ref(tr), Ref(p.half_extents), cfg, false)) {
if (Gizmo::box(u64(cmp.entity.index) | (u64(1) << 32), view, tr, p.half_extents, cfg, false)) {
editor.beginCommandGroup("refl_probe_half_ext");
editor.setProperty(ENVIRONMENT_PROBE_TYPE, "", -1, "Half extents", Span(&e, 1), p.half_extents);
editor.setEntitiesPositions(&e, &tr.pos, 1);
@ -4057,14 +4057,14 @@ struct StudioAppPlugin : StudioApp::IPlugin
Gizmo::Config cfg;
const DVec3 p0 = tr.transform(DVec3(decal.bezier_p0.x, 0, decal.bezier_p0.y));
Transform p0_tr = { p0, Quat::IDENTITY, 1 };
if (Gizmo::manipulate((u64(1) << 32) | cmp.entity.index, view, Ref(p0_tr), cfg)) {
if (Gizmo::manipulate((u64(1) << 32) | cmp.entity.index, view, p0_tr, cfg)) {
const Vec2 p0 = Vec2(tr.inverted().transform(p0_tr.pos).xz());
m_app.getWorldEditor().setProperty(CURVE_DECAL_TYPE, "", 0, "Bezier P0", Span(&e, 1), p0);
}
const DVec3 p2 = tr.transform(DVec3(decal.bezier_p2.x, 0, decal.bezier_p2.y));
Transform p2_tr = { p2, Quat::IDENTITY, 1 };
if (Gizmo::manipulate((u64(2) << 32) | cmp.entity.index, view, Ref(p2_tr), cfg)) {
if (Gizmo::manipulate((u64(2) << 32) | cmp.entity.index, view, p2_tr, cfg)) {
const Vec2 p2 = Vec2(tr.inverted().transform(p2_tr.pos).xz());
m_app.getWorldEditor().setProperty(CURVE_DECAL_TYPE, "", 0, "Bezier P2", Span(&e, 1), p2);
}

View file

@ -685,7 +685,7 @@ void SceneView::manipulate() {
m_copy_moved = false;
}
if (!Gizmo::manipulate((*selected)[0].index, *m_view, Ref(tr), cfg)) return;
if (!Gizmo::manipulate((*selected)[0].index, *m_view, tr, cfg)) return;
if (copy_move && !m_copy_moved) {
m_editor.duplicateEntities();

View file

@ -826,8 +826,8 @@ bool TerrainEditor::onMouseDown(UniverseView& view, int x, int y)
static void getProjections(const Vec3& axis,
const Vec3 vertices[8],
Ref<float> min,
Ref<float> max)
float& min,
float& max)
{
max = dot(vertices[0], axis);
min = max;
@ -858,8 +858,8 @@ static bool testOBBCollision(const AABB& a,
for(int i = 0; i < 3; i++)
{
float box_a_min, box_a_max, box_b_min, box_b_max;
getProjections(normals[i], box_a_points, Ref(box_a_min), Ref(box_a_max));
getProjections(normals[i], box_b_points, Ref(box_b_min), Ref(box_b_max));
getProjections(normals[i], box_a_points, box_a_min, box_a_max);
getProjections(normals[i], box_b_points, box_b_min, box_b_max);
if(!overlaps(box_a_min, box_a_max, box_b_min, box_b_max))
{
return false;
@ -871,8 +871,8 @@ static bool testOBBCollision(const AABB& a,
for(int i = 0; i < 3; i++)
{
float box_a_min, box_a_max, box_b_min, box_b_max;
getProjections(normals_b[i], box_a_points, Ref(box_a_min), Ref(box_a_max));
getProjections(normals_b[i], box_b_points, Ref(box_b_min), Ref(box_b_max));
getProjections(normals_b[i], box_a_points, box_a_min, box_a_max);
getProjections(normals_b[i], box_b_points, box_b_min, box_b_max);
if(!overlaps(box_a_min, box_a_max, box_b_min, box_b_max))
{
return false;

View file

@ -1736,18 +1736,18 @@ void preinit(IAllocator& allocator, bool load_renderdoc)
}
bool getMemoryStats(Ref<MemoryStats> stats) {
bool getMemoryStats(MemoryStats& stats) {
if (!gl->has_gpu_mem_info_ext) return false;
GLint tmp;
glGetIntegerv(GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &tmp);
stats->total_available_mem = (u64)tmp * 1024;
stats.total_available_mem = (u64)tmp * 1024;
glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &tmp);
stats->current_available_mem = (u64)tmp * 1024;
stats.current_available_mem = (u64)tmp * 1024;
glGetIntegerv(GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &tmp);
stats->dedicated_vidmem = (u64)tmp * 1024;
stats.dedicated_vidmem = (u64)tmp * 1024;
return true;
}

View file

@ -214,7 +214,7 @@ void preinit(IAllocator& allocator, bool load_renderdoc);
bool init(void* window_handle, InitFlags flags);
void launchRenderDoc();
void setCurrentWindow(void* window_handle);
bool getMemoryStats(Ref<MemoryStats> stats);
bool getMemoryStats(MemoryStats& stats);
u32 swapBuffers();
void waitFrame(u32 frame);
bool frameFinished(u32 frame);

View file

@ -290,7 +290,7 @@ static u8 getIndexBySemantic(Mesh::AttributeSemantic semantic) {
}
static bool parseVertexDecl(IInputStream& file, gpu::VertexDecl* vertex_decl, Mesh::AttributeSemantic* semantics, Ref<u32> vb_stride)
static bool parseVertexDecl(IInputStream& file, gpu::VertexDecl* vertex_decl, Mesh::AttributeSemantic* semantics, u32& vb_stride)
{
u32 attribute_count;
file.read(&attribute_count, sizeof(attribute_count));
@ -468,7 +468,7 @@ bool Model::parseMeshes(InputMemoryStream& file, FileVersion version)
Mesh::AttributeSemantic semantics[gpu::VertexDecl::MAX_ATTRIBUTES];
for(auto& i : semantics) i = Mesh::AttributeSemantic::NONE;
u32 vb_stride;
if (!parseVertexDecl(file, &vertex_decl, semantics, Ref(vb_stride))) return false;
if (!parseVertexDecl(file, &vertex_decl, semantics, vb_stride)) return false;
u32 mat_path_length;
char mat_path[LUMIX_MAX_PATH + 128];

View file

@ -4741,7 +4741,7 @@ struct PipelineImpl final : Pipeline
gpu::destroy(staging);
os::OutputFile file;
if (fs->open(path, Ref(file))) {
if (fs->open(path, file)) {
Texture::saveTGA(&file, w, h, gpu::TextureFormat::RGBA8, (u8*)pixels.begin(), false, Path(path), allocator);
file.close();
}

View file

@ -771,7 +771,7 @@ public:
Job& job = m_renderer.createJob<Job>(m_allocator);
// TODO async load
if (!m_engine.getFileSystem().getContentSync(Path(path_str), Ref(job.data))) {
if (!m_engine.getFileSystem().getContentSync(Path(path_str), job.data)) {
logError("Could not load ", path_str);
}
job.layer = probe.texture_id;
@ -2149,13 +2149,13 @@ public:
float intersection_t;
Vec3 rel_pos = Vec3(origin - pos);
if (getRaySphereIntersection(rel_pos, dir, Vec3::ZERO, radius, Ref(intersection_t)) && intersection_t >= 0) {
if (getRaySphereIntersection(rel_pos, dir, Vec3::ZERO, radius, intersection_t) && intersection_t >= 0) {
Vec3 aabb_hit;
const Quat rot = universe.getRotation(entity).conjugated();
const Vec3 rel_dir = rot.rotate(dir);
const AABB& aabb = r.model->getAABB();
rel_pos = rot.rotate(rel_pos / scale);
if (getRayAABBIntersection(rel_pos, rel_dir, aabb.min, aabb.max - aabb.min, Ref(aabb_hit))) {
if (getRayAABBIntersection(rel_pos, rel_dir, aabb.min, aabb.max - aabb.min, aabb_hit)) {
RayCastModelHit new_hit = r.model->castRay(rel_pos, rel_dir, r.pose);
if (new_hit.is_hit && (!hit.is_hit || new_hit.t * scale < hit.t)) {
new_hit.entity = entity;

View file

@ -451,7 +451,7 @@ struct RendererImpl final : Renderer
}
gpu::MemoryStats mem_stats;
if (gpu::getMemoryStats(Ref(mem_stats))) {
if (gpu::getMemoryStats(mem_stats)) {
logInfo("Initial GPU memory stats:\n",
"total: ", (mem_stats.total_available_mem / (1024.f * 1024.f)), "MB\n"
"currect: ", (mem_stats.current_available_mem / (1024.f * 1024.f)), "MB\n"
@ -1104,7 +1104,7 @@ struct RendererImpl final : Renderer
frame.transient_buffer.prepareToRender();
gpu::MemoryStats mem_stats;
if (gpu::getMemoryStats(Ref(mem_stats))) {
if (gpu::getMemoryStats(mem_stats)) {
profiler::gpuMemStats(mem_stats.total_available_mem, mem_stats.current_available_mem, mem_stats.dedicated_vidmem);
}

View file

@ -338,7 +338,7 @@ int include(lua_State* L)
FileSystem& fs = shader->m_renderer.getEngine().getFileSystem();
OutputMemoryStream content(shader->m_allocator);
if (!fs.getContentSync(Path(path), Ref(content))) {
if (!fs.getContentSync(Path(path), content)) {
logError("Failed to open/read include ", path, " included from ", shader->getPath());
return 0;
}

View file

@ -193,7 +193,7 @@ static void saveTGA(Texture& texture)
os::OutputFile file;
FileSystem& fs = texture.getResourceManager().getOwner().getFileSystem();
if (!fs.open(texture.getPath().c_str(), Ref(file))) {
if (!fs.open(texture.getPath().c_str(), file)) {
logError("Failed to create file ", texture.getPath());
return;
}
@ -219,7 +219,7 @@ void Texture::save()
{
FileSystem& fs = m_resource_manager.getOwner().getFileSystem();
os::OutputFile file;
if (!fs.open(getPath().c_str(), Ref(file))) {
if (!fs.open(getPath().c_str(), file)) {
logError("Failed to create file ", getPath());
return;
}