-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.hh
More file actions
134 lines (107 loc) · 3.34 KB
/
core.hh
File metadata and controls
134 lines (107 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once
#define BYTE4N_FLT(x) ((static_cast<f32>(x) / 255.f) * 2.f - 1.f)
namespace core
{
using namespace UFG;
const char* GetParamValue(const char* arg, const qString& param)
{
if (const char* find = qStringFindInsensitive(arg, param)) {
return &find[param.Length()];
}
return 0;
}
bool IsPermFile(const qString& path)
{
qString path2 = path.ToLower();
return (path2.EndsWith(".bin") && !path2.EndsWith(".temp.bin"));
}
void LoadPermFiles(const qString& find_path)
{
WIN32_FIND_DATAA wFindData = { 0 };
HANDLE hFind = FindFirstFileA(find_path, &wFindData);
if (hFind == INVALID_HANDLE_VALUE) {
return;
}
char* end = &find_path.mData[find_path.mLength - 2];
bool recursive = (end[0] == '*' && end[1] == '*');
qString folder = find_path.GetFilePath() + "\\";
do
{
qString file_path = (folder + wFindData.cFileName);
if (wFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (wFindData.cFileName[0] == '.') {
continue;
}
if (recursive)
{
file_path += "\\**";
LoadPermFiles(file_path);
}
continue;
}
if (IsPermFile(file_path)) {
StreamResourceLoader::LoadResourceFile(file_path);
}
} while (FindNextFileA(hFind, &wFindData));
FindClose(hFind);
}
Illusion::VertexStreamDescriptor* GetVertexStreamDescriptor(u32 name_uid)
{
auto streamDescriptors = Illusion::VertexStreamDescriptor::GetStreamDescriptors();
for (auto streamDescriptor = streamDescriptors->begin(); streamDescriptor != streamDescriptors->end(); streamDescriptor = streamDescriptor->next())
{
if (streamDescriptor->mNameUID == name_uid) {
return streamDescriptor;
}
}
return 0;
}
Illusion::VertexStreamElement* GetVertexStreamElement(Illusion::VertexStreamDescriptor* stream_descriptor, Illusion::VertexStreamElementUsage usage)
{
for (int i = 0; stream_descriptor->GetTotalElements() > i; ++i)
{
auto stream_element = stream_descriptor->GetElement(i);
if (stream_element && stream_element->mUsage == usage) {
return stream_element;
}
}
return 0;
}
void* GetVertexStreamData(Illusion::VertexStreamDescriptor* stream_descriptor, Illusion::VertexStreamElement* stream_element, Illusion::Buffer* vertex_buffer, u32 index)
{
const u32 offset = stream_element->mOffset + (stream_descriptor->GetStreamSize(stream_element->mStream) * index);
return vertex_buffer->mData.Get(offset);
}
void InitMeshHandles(Illusion::Mesh* mesh)
{
auto warehouse = qResourceWarehouse::Instance();
mesh->mMaterialHandle.mData = warehouse->DebugGet(RTypeUID_Material, mesh->mMaterialHandle.mNameUID);
mesh->mIndexBufferHandle.mData = warehouse->DebugGet(RTypeUID_Buffer, mesh->mIndexBufferHandle.mNameUID);
for (auto& vertexBufferHandle : mesh->mVertexBufferHandles) {
vertexBufferHandle.mData = warehouse->DebugGet(RTypeUID_Buffer, vertexBufferHandle.mNameUID);
}
}
bool ValidateBonesWithRig(RigResource* rig, Illusion::BonePalette* bone_palette)
{
auto skeleton = rig->mSkeleton;
for (u32 b = 0; bone_palette->mNumBones > b; ++b)
{
bool found = 0;
u32 bone_uid = *bone_palette->mBoneUIDTable[b];
for (int i = 0; skeleton->m_bones.m_size > i; ++i)
{
auto bone = &skeleton->m_bones.m_data[i];
if (qStringHashUpper32(bone->m_name) == bone_uid)
{
found = 1;
break;
}
}
if (!found) {
return 0;
}
}
return 1;
}
}