Anim import
This commit is contained in:
parent
367b76b8df
commit
ba93f02379
@ -2,6 +2,94 @@
|
||||
|
||||
namespace Assets
|
||||
{
|
||||
void IXAnimParts::Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Components::FileSystem::File animFile(Utils::VA("xanim/%s.iw4xAnim", name.data()));
|
||||
|
||||
if (animFile.Exists())
|
||||
{
|
||||
Utils::Stream::Reader reader(builder->GetAllocator(), animFile.GetBuffer());
|
||||
|
||||
Game::XAnimParts* xanim = reader.ReadArray<Game::XAnimParts>();
|
||||
|
||||
if (xanim)
|
||||
{
|
||||
if (xanim->name)
|
||||
{
|
||||
xanim->name = reader.ReadCString();
|
||||
}
|
||||
|
||||
if (xanim->tagnames)
|
||||
{
|
||||
xanim->tagnames = builder->GetAllocator()->AllocateArray<short>(xanim->boneCount[Game::XAnimPartType::PART_TYPE_ALL]);
|
||||
for (int i = 0; i < xanim->boneCount[Game::XAnimPartType::PART_TYPE_ALL]; ++i)
|
||||
{
|
||||
xanim->tagnames[i] = Game::SL_GetString(reader.ReadCString(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (xanim->notetracks)
|
||||
{
|
||||
xanim->notetracks = reader.ReadArray<Game::XAnimNotifyInfo>(xanim->notetrackCount);
|
||||
|
||||
for (int i = 0; i < xanim->notetrackCount; ++i)
|
||||
{
|
||||
xanim->notetracks[i].name = Game::SL_GetString(reader.ReadCString(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (xanim->dataByte)
|
||||
{
|
||||
xanim->dataByte = reader.ReadArray<char>(xanim->dataByteCount);
|
||||
}
|
||||
|
||||
if (xanim->dataShort)
|
||||
{
|
||||
xanim->dataShort = reader.ReadArray<short>(xanim->dataShortCount);
|
||||
}
|
||||
|
||||
if (xanim->dataInt)
|
||||
{
|
||||
xanim->dataInt = reader.ReadArray<int>(xanim->dataIntCount);
|
||||
}
|
||||
|
||||
if (xanim->randomDataByte)
|
||||
{
|
||||
xanim->randomDataByte = reader.ReadArray<char>(xanim->randomDataByteCount);
|
||||
}
|
||||
|
||||
if (xanim->randomDataShort)
|
||||
{
|
||||
xanim->randomDataShort = reader.ReadArray<short>(xanim->randomDataShortCount);
|
||||
}
|
||||
|
||||
if (xanim->randomDataInt)
|
||||
{
|
||||
xanim->randomDataInt = reader.ReadArray<int>(xanim->randomDataIntCount);
|
||||
}
|
||||
|
||||
if (xanim->indices.data)
|
||||
{
|
||||
if (xanim->framecount < 256)
|
||||
{
|
||||
xanim->indices._1 = reader.ReadArray<char>(xanim->indexcount);
|
||||
}
|
||||
else
|
||||
{
|
||||
xanim->indices._2 = reader.ReadArray<unsigned short>(xanim->indexcount);
|
||||
}
|
||||
}
|
||||
|
||||
if (!reader.End())
|
||||
{
|
||||
Components::Logger::Error(0, "Reading animation '%s' failed, remaining raw data found!", name.data());
|
||||
}
|
||||
|
||||
header->xanim = xanim;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IXAnimParts::Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Game::XAnimParts* asset = header.xanim;
|
||||
|
@ -7,6 +7,7 @@ namespace Assets
|
||||
|
||||
virtual void Mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
||||
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
||||
virtual void Load(Game::XAssetHeader* header, std::string name, Components::ZoneBuilder::Zone* builder) override;
|
||||
|
||||
private:
|
||||
void Save_XAnimDeltaPart(Game::XAnimDeltaPart* delta, unsigned short framecount, Components::ZoneBuilder::Zone* builder);
|
||||
|
@ -116,7 +116,7 @@ namespace Components
|
||||
info.Set("protocol", Utils::VA("%i", PROTOCOL));
|
||||
info.Set("shortversion", VERSION_STR);
|
||||
info.Set("mapname", Dvar::Var("mapname").Get<const char*>());
|
||||
info.Set("isPrivate", (Dvar::Var("g_password").Get<std::string>().size() ? "1" : "0"));
|
||||
info.Set("isPrivate", (Dvar::Var("g_password").Get<std::string>().empty() ? "0" : "1"));
|
||||
|
||||
std::string time = Utils::VA("%u", Game::Com_Milliseconds());
|
||||
info.Set("checksum", Utils::VA("%X", Utils::Cryptography::JenkinsOneAtATime::Compute(time.data(), time.size())));
|
||||
|
@ -1605,7 +1605,7 @@ namespace Game
|
||||
|
||||
struct XAnimParts
|
||||
{
|
||||
char * name; // 0
|
||||
const char * name; // 0
|
||||
unsigned short dataByteCount; // 4
|
||||
unsigned short dataShortCount; // 6
|
||||
unsigned short dataIntCount; // 8
|
||||
|
@ -2,6 +2,63 @@
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
std::string Stream::Reader::ReadString()
|
||||
{
|
||||
std::string str;
|
||||
|
||||
while (char byte = Stream::Reader::ReadByte())
|
||||
{
|
||||
str.append(&byte, 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
const char* Stream::Reader::ReadCString()
|
||||
{
|
||||
return Stream::Reader::Allocator->DuplicateString(Stream::Reader::ReadString());
|
||||
}
|
||||
|
||||
char Stream::Reader::ReadByte()
|
||||
{
|
||||
if ((Stream::Reader::Position + 1) <= Stream::Reader::Buffer.size())
|
||||
{
|
||||
return Stream::Reader::Buffer[Stream::Reader::Position++];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* Stream::Reader::Read(size_t size, size_t count)
|
||||
{
|
||||
size_t bytes = size * count;
|
||||
|
||||
if ((Stream::Reader::Position + bytes) <= Stream::Reader::Buffer.size())
|
||||
{
|
||||
void* buffer = Stream::Reader::Allocator->Allocate(bytes);
|
||||
|
||||
std::memcpy(buffer, Stream::Reader::Buffer.data() + Stream::Reader::Position, bytes);
|
||||
Stream::Reader::Position += bytes;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Stream::Reader::End()
|
||||
{
|
||||
return (Stream::Reader::Buffer.size() == Stream::Reader::Position);
|
||||
}
|
||||
|
||||
void Stream::Reader::Seek(unsigned int position)
|
||||
{
|
||||
if (Stream::Reader::Buffer.size() >= position)
|
||||
{
|
||||
Stream::Reader::Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
Stream::Stream() : CriticalSectionState(0)
|
||||
{
|
||||
memset(Stream::BlockSize, 0, sizeof(Stream::BlockSize));
|
||||
|
@ -9,6 +9,31 @@ namespace Utils
|
||||
std::string Buffer;
|
||||
|
||||
public:
|
||||
class Reader
|
||||
{
|
||||
public:
|
||||
Reader(Utils::Memory::Allocator* allocator, std::string& buffer) : Buffer(buffer), Allocator(allocator), Position(0) {}
|
||||
|
||||
std::string ReadString();
|
||||
const char* ReadCString();
|
||||
|
||||
char ReadByte();
|
||||
|
||||
void* Read(size_t size, size_t count = 1);
|
||||
template <typename T> T* ReadArray(size_t count = 1)
|
||||
{
|
||||
return reinterpret_cast<T*>(Read(sizeof(T), count));
|
||||
}
|
||||
|
||||
bool End();
|
||||
void Seek(unsigned int position);
|
||||
|
||||
private:
|
||||
unsigned int Position;
|
||||
std::string Buffer;
|
||||
Utils::Memory::Allocator* Allocator;
|
||||
};
|
||||
|
||||
enum Alignment
|
||||
{
|
||||
ALIGN_2,
|
||||
|
Loading…
Reference in New Issue
Block a user