summaryrefslogtreecommitdiff
path: root/ZAPD/ZVtx.cpp
blob: 06762bbcb65896579f50c98e12ff3e1feaf8b03c (plain)
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
#include "ZVtx.h"
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "ZFile.h"

REGISTER_ZFILENODE(Vtx, ZVtx);

ZVtx::ZVtx(ZFile* nParent) : ZResource(nParent)
{
	x = 0;
	y = 0;
	z = 0;
	flag = 0;
	s = 0;
	t = 0;
	r = 0;
	g = 0;
	b = 0;
	a = 0;
}

void ZVtx::ParseRawData()
{
	ZResource::ParseRawData();

	const auto& rawData = parent->GetRawData();
	x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
	y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
	z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
	flag = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
	s = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
	t = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
	r = rawData[rawDataIndex + 12];
	g = rawData[rawDataIndex + 13];
	b = rawData[rawDataIndex + 14];
	a = rawData[rawDataIndex + 15];
}

std::string ZVtx::GetBodySourceCode() const
{
	return StringHelper::Sprintf("    VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b,
	                             a);
}

std::string ZVtx::GetSourceOutputCode([[maybe_unused]] const std::string& prefix)
{
	std::string output = GetBodySourceCode();

	if (parent != nullptr)
	{
		Declaration* decl =
			parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
		                           GetSourceTypeName(), name, output);
		decl->isExternal = true;
	}

	return "";
}

size_t ZVtx::GetRawDataSize() const
{
	return 16;
}

bool ZVtx::DoesSupportArray() const
{
	return true;
}

ZResourceType ZVtx::GetResourceType() const
{
	return ZResourceType::Vertex;
}

bool ZVtx::IsExternalResource() const
{
	return true;
}

std::string ZVtx::GetSourceTypeName() const
{
	return "Vtx";
}

std::string ZVtx::GetExternalExtension() const
{
	return "vtx";
}