Skip to content

Commit

Permalink
Undo/Redo resources (Meshes, Materials ...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benualdo committed Oct 1, 2024
1 parent c0bb375 commit afa0de4
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 85 deletions.
16 changes: 14 additions & 2 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ Size=860,400
Collapsed=0

[Window][Delete GameObject]
Pos=1093,649
Size=373,70
Pos=1055,636
Size=450,96
Collapsed=0

[Window][ About]
Expand Down Expand Up @@ -2711,6 +2711,18 @@ Column 0 Sort=0v
RefScale=14
Column 0 Sort=0v

[Table][0x17202F13,3]
RefScale=14
Column 0 Width=96
Column 1 Width=96
Column 2 Weight=1.0000

[Table][0x8A83873C,3]
RefScale=14
Column 0 Width=96
Column 1 Width=96
Column 2 Weight=1.0000

[Docking][Data]
DockNode ID=0x0000001B Pos=517,135 Size=821,613 Selected=0x766639F3
DockSpace ID=0x09EF459F Pos=0,24 Size=1920,1056 Split=X
Expand Down
3 changes: 3 additions & 0 deletions src/core/File/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace vg::core::io
void resetRead();
void resetWrite();

size_t getReadOffset() const { return m_read; }
size_t getWriteOffset() const { return m_write; }

private:
size_t m_read = 0;
size_t m_write = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/core/File/Buffer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ namespace vg::core::io
return write(&_value, sizeof(u32));
}

//--------------------------------------------------------------------------------------
inline bool Buffer::read(u64 * _value)
{
return read(_value, sizeof(u64));
}

//--------------------------------------------------------------------------------------
inline bool Buffer::write(u64 _value)
{
return write(&_value, sizeof(u64));
}

//--------------------------------------------------------------------------------------
inline bool Buffer::read(float * _value)
{
Expand Down
9 changes: 7 additions & 2 deletions src/core/IFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace vg::core

using UID = core::u32;

vg_enum_class(BufferType, core::u8,
InitValue = 0,
UndoRedo
);

class IFactory
{
public:
Expand All @@ -40,8 +45,8 @@ namespace vg::core
virtual void ReleaseAsync (core::IObject * _object) = 0;
virtual void FlushReleaseAsync () = 0;

virtual bool SaveProperties (core::IObject * _object) = 0;
virtual bool RestoreProperties (core::IObject * _object) = 0;
virtual bool SaveProperties (core::IObject * _object, BufferType _bufferType) = 0;
virtual bool RestoreProperties (core::IObject * _object, BufferType _bufferType) = 0;
virtual bool CopyProperties (const core::IObject * _srcObj, core::IObject * _dstObj) = 0;
virtual bool CanCopyProperty (const core::IProperty * _srcProp, const core::IProperty * _dstProp) const = 0;
virtual bool CopyProperty (const core::IProperty * _srcProp, const core::IObject * _srcObj, const core::IProperty * _dstProp, core::IObject * _dstObj) = 0;
Expand Down
33 changes: 32 additions & 1 deletion src/core/Misc/BitMask/BitMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace vg::core
if (!_value._Starts_with("0x"))
return false;

uint itemCount = (_bitCount + getNumBitsPerItem() - 1) / getNumBitsPerItem(); //(_value.length() - 2) / (sizeof(T) << 1);
uint itemCount = (_bitCount + getNumBitsPerItem() - 1) / getNumBitsPerItem();
uint charCount = sizeof(T) << 1;
core::vector<T> bits;

Expand All @@ -141,4 +141,35 @@ namespace vg::core

return true;
}

//--------------------------------------------------------------------------------------
bool BitMask::toBuffer(io::Buffer & _buffer)
{
bool result = _buffer.write((u32)m_bitCount);
result |= _buffer.write((u32)m_bits.size());

for (uint i = 0; i < m_bits.size(); ++i)
result |= _buffer.write((u64)m_bits[i]);

return result;
}

//--------------------------------------------------------------------------------------
bool BitMask::fromBuffer(io::Buffer & _buffer)
{
u32 bitCount = 0;
bool result = _buffer.read(&bitCount);

u32 size = 0;
result |= _buffer.read(&size);

if (result)
{
setBitCount(bitCount);
for (uint i = 0; i < size; ++i)
result |= _buffer.read(&m_bits[i]);
}

return result;
}
}
4 changes: 4 additions & 0 deletions src/core/Misc/BitMask/BitMask.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "core/Types/Types.h"
#include "core/File/Buffer.h"

namespace vg::core
{
Expand All @@ -21,6 +22,9 @@ namespace vg::core

core::string toString(bool _leadingZeroes = false) const;
bool fromString(const core::string & _value, core::uint _bitCount);

bool toBuffer(io::Buffer & _buffer);
bool fromBuffer(io::Buffer & _buffer);

private:
VG_INLINE core::uint getNumBitsPerItem() const;
Expand Down
Loading

0 comments on commit afa0de4

Please sign in to comment.