hsfload fixes

This commit is contained in:
dbalatoni13 2025-04-11 13:51:56 +02:00
parent 1e51c0f60d
commit dfc51f4912
7 changed files with 87 additions and 19 deletions

2
extern/aurora vendored

@ -1 +1 @@
Subproject commit d9de6603c79917a5353abd3a9cc26ec557ceee05
Subproject commit 3b56e337c08a1dd4946c226298011364c319c7a2

View file

@ -350,6 +350,9 @@ typedef struct hsf_track {
float value;
void *data;
};
#ifdef TARGET_PC
void *dataTop;
#endif
} HsfTrack;
typedef struct hsf_motion {

View file

@ -215,6 +215,20 @@ typedef struct HsfBitmapKey32b {
u32 data;
} HsfBitmapKey32b;
typedef struct HsfFace32b {
s16 type;
s16 mat;
union {
struct {
s16 indices[3][4];
u32 count;
u32 data;
} strip;
s16 indices[4][4];
};
Vec nbt;
} HsfFace32b;
void byteswap_u16(u16 *src);
void byteswap_s16(s16 *src);
void byteswap_u32(u32 *src);
@ -248,6 +262,7 @@ void byteswap_hsfobject(HsfObject32b *src, HsfObject *dest);
void byteswap_hsfbitmapkey(HsfBitmapKey32b *src, HsfBitmapKey *dest);
void byteswap_hsftrack(HsfTrack32b *src, HsfTrack *dest);
void byteswap_hsfmotion(HsfMotion32b *src, HsfMotion *dest);
void byteswap_hsfface(HsfFace32b *src, HsfFace *dest);
#ifdef __cplusplus
}

View file

@ -371,8 +371,10 @@ void ObjectSetup(void)
s16 group;
s16 sprite;
AnimData *data;
#ifdef TARGET_PC
return;
#else
option = 0;
#ifdef __MWERKS__
if (OSGetResetCode() != OS_RESET_RESTART) {
return;
}
@ -425,7 +427,6 @@ void ObjectSetup(void)
HuPrcVSleep();
}
#ifdef __MWERKS__
// TODO PC
if (!option) {
OSSetProgressiveMode(OS_PROGRESSIVE_MODE_ON);
VIConfigure(&GXNtsc480Prog);

View file

@ -272,7 +272,7 @@ static void MaterialLoad(void)
new_mat->refAlpha = curr_mat->refAlpha;
new_mat->unk2C = curr_mat->unk2C;
new_mat->numAttrs = curr_mat->numAttrs;
new_mat->attrs = (s32 *)(NSymIndex+((uintptr_t)curr_mat->attrs));
new_mat->attrs = (s32 *)(NSymIndex+((u32)curr_mat->attrs));
rgba[i].r = new_mat->litColor[0];
rgba[i].g = new_mat->litColor[1];
rgba[i].b = new_mat->litColor[2];
@ -458,6 +458,14 @@ static void NormalLoad(void)
new_normal->count = file_normal->count;
new_normal->name = SetName((u32 *)&file_normal->name);
new_normal->data = (void *)((uintptr_t)data+(uintptr_t)temp_data);
#ifdef TARGET_PC
if (cenv_count != 0) {
for (i = 0; i < new_normal->count; i++) {
HsfVector3f *normalData = &((HsfVector3f *)new_normal->data)[i];
byteswap_hsfvec3f(normalData);
}
}
#endif
}
}
}
@ -530,9 +538,10 @@ static void FaceLoad(void)
if(head.face.count) {
#ifdef TARGET_PC
HsfBuffer32b *file_face_real = (HsfBuffer32b *)((uintptr_t)fileptr + head.face.ofs);
HsfFace32b *file_facedata_real = (HsfFace32b *)&file_face_real[head.face.count];
temp_face = file_face = FaceTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBuffer) * head.face.count, MEMORY_DEFAULT_NUM);
for (i = 0; i < head.face.count; i++) {
byteswap_hsfbuffer(&file_face[i], &file_face[i]);
byteswap_hsfbuffer(&file_face_real[i], &file_face[i]);
}
#else
temp_face = file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs);
@ -541,9 +550,7 @@ static void FaceLoad(void)
new_face = temp_face;
Model.face = new_face;
Model.faceCnt = head.face.count;
#ifdef TARGET_PC
data = (void *)&file_face_real[head.face.count];
#else
#ifdef __MWERKS__
file_face = (HsfBuffer *)((u32)fileptr+head.face.ofs);
data = (HsfFace *)&file_face[head.face.count];
#endif
@ -551,22 +558,30 @@ static void FaceLoad(void)
temp_data = file_face->data;
new_face->name = SetName((u32 *)&file_face->name);
new_face->count = file_face->count;
#ifdef TARGET_PC
{
HsfFace32b *facedata_start = (HsfFace32b *)((uintptr_t)file_facedata_real + (uintptr_t)temp_data);
data = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfFace) * new_face->count, MEMORY_DEFAULT_NUM);
for (j = 0; j < new_face->count; j++) {
byteswap_hsfface(&facedata_start[j], &data[j]);
}
new_face->data = data;
strip = (u8 *)(&facedata_start[new_face->count]);
}
#else
new_face->data = (void *)((uintptr_t)data+(uintptr_t)temp_data);
strip = (u8 *)(&((HsfFace *)new_face->data)[new_face->count]);
#endif
}
new_face = temp_face;
for(i=0; i<head.face.count; i++, new_face++) {
file_face_strip = new_face_strip = new_face->data;
for(j=0; j<new_face->count; j++, new_face_strip++, file_face_strip++) {
#ifdef TARGET_PC
byteswap_s16(&file_face_strip->type);
#endif
if(AS_U16(file_face_strip->type) == 4) {
new_face_strip->strip.data = (s16 *)(strip+(uintptr_t)file_face_strip->strip.data*(sizeof(s16)*4));
#ifdef TARGET_PC
{
s32 k;
byteswap_u32(&new_face_strip->strip.count);
for (k = 0; k < new_face_strip->strip.count; k++) {
byteswap_s16(&new_face_strip->strip.data[k]);
}
@ -1554,7 +1569,7 @@ static inline void MotionLoadAttribute(HsfTrack *track, void *data)
{
#ifdef TARGET_PC
HsfBitmapKey32b *file_frame_real = (HsfBitmapKey32b *)((uintptr_t)data + (uintptr_t)track->data);
new_frame = file_frame = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBitmapKey) * track->numKeyframes, MEMORY_DEFAULT_NUM);
new_frame = file_frame = track->dataTop = HuMemDirectMallocNum(HEAP_DATA, sizeof(HsfBitmapKey) * track->numKeyframes, MEMORY_DEFAULT_NUM);
#else
new_frame = file_frame = (HsfBitmapKey *)((uintptr_t)data + (uintptr_t)track->data);
out_track->data = file_frame;
@ -1845,6 +1860,9 @@ void KillHSF(HsfData *data)
HuMemDirectFree(data->bitmap);
HuMemDirectFree(data->cenv);
HuMemDirectFree(data->skeleton);
for (i = 0; i < data->faceCnt; i++) {
HuMemDirectFree(data->face[i].data);
}
HuMemDirectFree(data->face);
HuMemDirectFree(data->material);
for (i = 0; i < data->motionCnt; i++) {
@ -1853,7 +1871,7 @@ void KillHSF(HsfData *data)
HsfTrack *track = data->motion[i].track;
if (track->type == HSF_TRACK_ATTRIBUTE && track->curveType == HSF_CURVE_BITMAP) {
// in this case we needed to allocate space for HsfBitmapKey structs
HuMemDirectFree(track->data);
HuMemDirectFree(track->dataTop);
}
}
HuMemDirectFree(motion->track);

View file

@ -721,6 +721,31 @@ template <typename B> void bswap(B &base, HsfMotion32b &obj, HsfMotion &dest)
dest.len = obj.len;
}
template <typename B> void bswap(B &base, HsfFace32b &obj, HsfFace &dest)
{
bswap(base, obj.type);
bswap(base, obj.mat);
bswap(base, obj.nbt);
dest.type = obj.type;
dest.mat = obj.mat;
dest.nbt = obj.nbt;
if (obj.type == 4) {
bswap(base, obj.strip.count);
bswap(base, obj.strip.data);
bswap_flat(base, obj.strip.indices[0], 3 * 4);
dest.strip.count = obj.strip.count;
dest.strip.data = reinterpret_cast<s16 *>(obj.strip.data);
std::copy(&obj.strip.indices[0][0], &obj.strip.indices[0][0] + 3 * 4, &dest.strip.indices[0][0]);
}
else {
bswap_flat(base, obj.indices[0], 4 * 4);
std::copy(&obj.indices[0][0], &obj.indices[0][0] + 4 * 4, &dest.indices[0][0]);
}
}
void byteswap_u16(u16 *src)
{
bswap(*src, *src);
@ -909,6 +934,12 @@ void byteswap_hsftrack(HsfTrack32b *src, HsfTrack *dest)
}
void byteswap_hsfmotion(HsfMotion32b *src, HsfMotion *dest)
{
bswap(*src, *src, *dest);
sVisitedPtrs.clear();
}
void byteswap_hsfface(HsfFace32b *src, HsfFace *dest)
{
bswap(*src, *src, *dest);
sVisitedPtrs.clear();

View file

@ -198,27 +198,27 @@ s32 CARDWriteAsync(CARDFileInfo *fileInfo, const void *addr, s32 length, s32 off
void DCFlushRange(void *addr, u32 nBytes)
{
puts("DCFlushRange is a stub");
//puts("DCFlushRange is a stub");
}
void DCFlushRangeNoSync(void *addr, u32 nBytes)
{
puts("DCFlushRangeNoSync is a stub");
//puts("DCFlushRangeNoSync is a stub");
}
void DCInvalidateRange(void *addr, u32 nBytes)
{
puts("DCInvalidateRange is a stub");
//puts("DCInvalidateRange is a stub");
}
void DCStoreRange(void *addr, u32 nBytes)
{
puts("DCStoreRange is a stub");
//puts("DCStoreRange is a stub");
}
void DCStoreRangeNoSync(void *addr, u32 nBytes)
{
puts("DCStoreRangeNoSync is a stub");
//puts("DCStoreRangeNoSync is a stub");
}
void DEMOUpdateStats(unsigned char inc)