mirror of
https://github.com/rrika/cdcEngineDXHR.git
synced 2025-02-17 04:07:47 +00:00
script: add ScriptDataCursor
This commit is contained in:
parent
02325d2a82
commit
ea9ad85b3b
@ -3,6 +3,7 @@ target_sources(dxhr PRIVATE
|
||||
GarbageCollector.cpp
|
||||
GCObject.cpp
|
||||
PackageBinaryLoader.cpp
|
||||
ScriptDataCursor.cpp
|
||||
ScriptManager.cpp
|
||||
ScriptObject.cpp
|
||||
ScriptType.cpp)
|
||||
|
50
cdcScript/ScriptDataCursor.cpp
Normal file
50
cdcScript/ScriptDataCursor.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "ScriptDataCursor.h"
|
||||
|
||||
namespace cdc {
|
||||
|
||||
ScriptDataCursor::ScriptDataCursor(ScriptType *_scriptType) : scriptType(_scriptType) {
|
||||
pDataMemberArray = scriptType->blob->m_members;
|
||||
cursor = pDataMemberArray.begin();
|
||||
end = pDataMemberArray.end();
|
||||
refill();
|
||||
}
|
||||
|
||||
void ScriptDataCursor::refill() {
|
||||
if (scriptType == nullptr)
|
||||
return;
|
||||
|
||||
while (cursor == end) {
|
||||
|
||||
scriptType = scriptType->getParentType();
|
||||
if (scriptType == nullptr)
|
||||
break;
|
||||
|
||||
auto blob = scriptType->blob;
|
||||
|
||||
pDataMemberArray = scriptType->blob->m_members;
|
||||
cursor = pDataMemberArray.begin();
|
||||
end = pDataMemberArray.end();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptDataCursor::advance() {
|
||||
cursor++;
|
||||
refill();
|
||||
}
|
||||
|
||||
ScriptUniqueDataCursor::ScriptUniqueDataCursor(ScriptType *scriptType) :
|
||||
ScriptDataCursor(scriptType),
|
||||
field20(0),
|
||||
field24(1)
|
||||
{
|
||||
if (cursor < end)
|
||||
seen.insert(cursor->m_offset);
|
||||
}
|
||||
|
||||
void ScriptUniqueDataCursor::advance() {
|
||||
do {
|
||||
ScriptDataCursor::advance();
|
||||
} while(cursor < end && seen.insert(cursor->m_offset).second == false);
|
||||
}
|
||||
|
||||
}
|
34
cdcScript/ScriptDataCursor.h
Normal file
34
cdcScript/ScriptDataCursor.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "cdcSys/SArray.h"
|
||||
#include "cdcSys/HashSet.h"
|
||||
#include "ScriptType.h"
|
||||
|
||||
namespace cdc {
|
||||
|
||||
class ScriptDataCursor {
|
||||
protected:
|
||||
ScriptType *scriptType;
|
||||
SArray<DataMember> pDataMemberArray;
|
||||
DataMember *cursor;
|
||||
DataMember *end;
|
||||
void refill();
|
||||
|
||||
public:
|
||||
ScriptDataCursor(ScriptType *scriptType);
|
||||
bool done() const { return cursor == end; }
|
||||
DataMember *operator->() const { return cursor; }
|
||||
operator DataMember*() const { return cursor; }
|
||||
virtual ~ScriptDataCursor() = default;
|
||||
virtual void advance();
|
||||
};
|
||||
|
||||
struct ScriptUniqueDataCursor : public ScriptDataCursor {
|
||||
HashSet<uint16_t> seen;
|
||||
uint32_t field20;
|
||||
uint32_t field24;
|
||||
public:
|
||||
ScriptUniqueDataCursor(ScriptType *scriptType);
|
||||
void advance() override;
|
||||
};
|
||||
|
||||
}
|
27
cdcSys/HashSet.h
Normal file
27
cdcSys/HashSet.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <unordered_set>
|
||||
|
||||
namespace cdc {
|
||||
|
||||
template <typename T>
|
||||
using HashSet = std::unordered_set<T>;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
#include <cstdint>
|
||||
#include "Allocator.h"
|
||||
#include "Algorithm.h"
|
||||
|
||||
namespace cdc {
|
||||
|
||||
template <typename T>
|
||||
struct HashSet {
|
||||
using value_type = T;
|
||||
using iterator = int;
|
||||
// TODO
|
||||
Pair<iterator, bool> insert(value_type const&);
|
||||
};
|
||||
|
||||
}
|
||||
*/
|
@ -10,7 +10,7 @@ struct SArray {
|
||||
|
||||
size_t size() { return ((uint32_t*)m_ptr)[-1]; }
|
||||
T *begin() { return m_ptr; }
|
||||
T *end() { return m_ptr + size(); }
|
||||
T *end() { return m_ptr ? m_ptr + size() : m_ptr; }
|
||||
T& operator[](size_t index) { return m_ptr[index]; }
|
||||
T const& operator[](size_t index) const { return m_ptr[index]; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user