mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-04 13:47:04 -04:00
iff2html is working and can properly parse STR# chunks.
I also added my TSOSimulatorClient work to the trunk.
This commit is contained in:
parent
a4a7b82bb7
commit
64fddcf78e
16 changed files with 963 additions and 80 deletions
|
@ -17,6 +17,8 @@ set(FILEHANDLER_MINOR 0)
|
|||
set(FILEHANDLER_SOURCES
|
||||
File.cpp
|
||||
Image.cpp
|
||||
iff/chunks.c
|
||||
iff/iff.c
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/Libraries/FileHandler)
|
||||
|
|
|
@ -4,7 +4,6 @@ project(iff)
|
|||
set(IFF_SOURCES
|
||||
chunks.c
|
||||
iff.c
|
||||
iffexport.c
|
||||
)
|
||||
|
||||
add_executable(iffexport ${IFF_SOURCES})
|
||||
add_executable(iffexport iffexport.c ${IFF_SOURCES})
|
|
@ -19,6 +19,239 @@
|
|||
#include <stdint.h>
|
||||
#include "iff.h"
|
||||
|
||||
int iff_read_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize, unsigned IFFSize){
|
||||
int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
if(!strcmp(ChunkInfo->Type, "STR#"))
|
||||
return iff_parse_str(ChunkInfo, Buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer){
|
||||
/* No bounds checking yet */
|
||||
IFF_STR * StringData;
|
||||
unsigned Size = ChunkInfo->Size - 64;
|
||||
if(Size < 4)
|
||||
return 0;
|
||||
ChunkInfo->FormattedData = malloc(sizeof(IFF_STR));
|
||||
if(ChunkInfo->FormattedData == NULL)
|
||||
return 0;
|
||||
memset(ChunkInfo->FormattedData, 0, sizeof(IFF_STR));
|
||||
StringData = (IFF_STR*) ChunkInfo->FormattedData;
|
||||
StringData->Format = read_int16le(Buffer);
|
||||
Buffer += 2;
|
||||
|
||||
switch(StringData->Format){
|
||||
|
||||
case 0: {
|
||||
unsigned i;
|
||||
IFFStringPairNode * PrevPair = NULL;
|
||||
|
||||
StringData->LanguageSets[0].PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2;
|
||||
if(StringData->LanguageSets[0].PairCount == 0)
|
||||
return 1;
|
||||
|
||||
for(i=0; i<StringData->LanguageSets[0].PairCount; i++){
|
||||
IFFStringPairNode * CurrentPair;
|
||||
unsigned length;
|
||||
CurrentPair = malloc(sizeof(IFFStringPairNode));
|
||||
memset(CurrentPair, 0, sizeof(IFFStringPairNode));
|
||||
|
||||
if(i == 0) StringData->LanguageSets[0].FirstPair = CurrentPair;
|
||||
else PrevPair->NextPair = CurrentPair;
|
||||
CurrentPair->PrevPair = PrevPair;
|
||||
|
||||
/* Key */
|
||||
length = read_uint8le(Buffer);
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Key = malloc(length+1);
|
||||
memcpy(CurrentPair->Pair.Key, Buffer+1, length);
|
||||
CurrentPair->Pair.Key[length] = 0x00;
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
PrevPair = CurrentPair;
|
||||
}
|
||||
StringData->LanguageSets[0].LastPair = PrevPair;
|
||||
} return 1;
|
||||
|
||||
case -1: {
|
||||
unsigned i;
|
||||
IFFStringPairNode * PrevPair = NULL;
|
||||
|
||||
StringData->LanguageSets[0].PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2;
|
||||
if(StringData->LanguageSets[0].PairCount == 0)
|
||||
return 1;
|
||||
|
||||
for(i=0; i<StringData->LanguageSets[0].PairCount; i++){
|
||||
IFFStringPairNode * CurrentPair;
|
||||
unsigned length;
|
||||
CurrentPair = malloc(sizeof(IFFStringPairNode));
|
||||
memset(CurrentPair, 0, sizeof(IFFStringPairNode));
|
||||
|
||||
if(i == 0) StringData->LanguageSets[0].FirstPair = CurrentPair;
|
||||
else PrevPair->NextPair = CurrentPair;
|
||||
CurrentPair->PrevPair = PrevPair;
|
||||
|
||||
/* Key */
|
||||
length = strlen((char*)Buffer);
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Key = malloc(length+1);
|
||||
strcpy(CurrentPair->Pair.Key, (char*)Buffer);
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
PrevPair = CurrentPair;
|
||||
}
|
||||
StringData->LanguageSets[0].LastPair = PrevPair;
|
||||
} return 1;
|
||||
|
||||
case -2: {
|
||||
unsigned i;
|
||||
IFFStringPairNode * PrevPair = NULL;
|
||||
|
||||
StringData->LanguageSets[0].PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2;
|
||||
if(StringData->LanguageSets[0].PairCount == 0)
|
||||
return 1;
|
||||
|
||||
for(i=0; i<StringData->LanguageSets[0].PairCount; i++){
|
||||
IFFStringPairNode * CurrentPair;
|
||||
unsigned length;
|
||||
CurrentPair = malloc(sizeof(IFFStringPairNode));
|
||||
memset(CurrentPair, 0, sizeof(IFFStringPairNode));
|
||||
|
||||
if(i == 0) StringData->LanguageSets[0].FirstPair = CurrentPair;
|
||||
else PrevPair->NextPair = CurrentPair;
|
||||
CurrentPair->PrevPair = PrevPair;
|
||||
|
||||
/* Key */
|
||||
length = strlen((char*)Buffer);
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Key = malloc(length+1);
|
||||
strcpy(CurrentPair->Pair.Key, (char*)Buffer);
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
/* Value */
|
||||
length = strlen((char*)Buffer);
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Value = malloc(length+1);
|
||||
strcpy(CurrentPair->Pair.Value, (char*)Buffer);
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
PrevPair = CurrentPair;
|
||||
}
|
||||
StringData->LanguageSets[0].LastPair = PrevPair;
|
||||
} return 1;
|
||||
|
||||
case -3: {
|
||||
unsigned i, TotalPairCount;
|
||||
|
||||
TotalPairCount = read_uint16le(Buffer);
|
||||
Buffer += 2;
|
||||
if(TotalPairCount == 0)
|
||||
return 1;
|
||||
|
||||
for(i=0; i<TotalPairCount; i++){
|
||||
IFFStringPairNode * Pair;
|
||||
unsigned length;
|
||||
Pair = malloc(sizeof(IFFStringPairNode));
|
||||
memset(Pair, 0, sizeof(IFFStringPairNode));
|
||||
Pair->Pair.LanguageSet = read_uint8le(Buffer) - 1;
|
||||
Buffer++;
|
||||
|
||||
/* Key */
|
||||
length = strlen((char*)Buffer);
|
||||
if(length != 0){
|
||||
Pair->Pair.Key = malloc(length+1);
|
||||
strcpy(Pair->Pair.Key, (char*)Buffer);
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
/* Value */
|
||||
length = strlen((char*)Buffer);
|
||||
if(length != 0){
|
||||
Pair->Pair.Value = malloc(length+1);
|
||||
strcpy(Pair->Pair.Value, (char*)Buffer);
|
||||
}
|
||||
Buffer += length+1;
|
||||
|
||||
/* Add the pair to the end of the associated language set */
|
||||
Pair->PrevPair = StringData->LanguageSets[0].LastPair;
|
||||
if(StringData->LanguageSets[0].PairCount == 0)
|
||||
StringData->LanguageSets[0].FirstPair = Pair;
|
||||
else
|
||||
StringData->LanguageSets[0].LastPair->NextPair = Pair;
|
||||
StringData->LanguageSets[0].PairCount++;
|
||||
StringData->LanguageSets[0].LastPair = Pair;
|
||||
}
|
||||
} return 1;
|
||||
|
||||
case -4: {
|
||||
unsigned LanguageSet;
|
||||
unsigned LanguageSetCount = read_uint8le(Buffer);
|
||||
Buffer++;
|
||||
if(LanguageSetCount > 20) LanguageSetCount = 20;
|
||||
|
||||
for(LanguageSet=0; LanguageSet<LanguageSetCount; LanguageSet++){
|
||||
unsigned i;
|
||||
IFFStringPairNode * PrevPair = NULL;
|
||||
|
||||
StringData->LanguageSets[LanguageSet].PairCount = read_uint16le(Buffer);
|
||||
Buffer += 2;
|
||||
if(StringData->LanguageSets[LanguageSet].PairCount == 0)
|
||||
continue;
|
||||
|
||||
for(i=0; i<StringData->LanguageSets[LanguageSet].PairCount; i++){
|
||||
IFFStringPairNode * CurrentPair;
|
||||
unsigned length;
|
||||
CurrentPair = malloc(sizeof(IFFStringPairNode));
|
||||
memset(CurrentPair, 0, sizeof(IFFStringPairNode));
|
||||
|
||||
if(i == 0) StringData->LanguageSets[LanguageSet].FirstPair = CurrentPair;
|
||||
else PrevPair->NextPair = CurrentPair;
|
||||
CurrentPair->PrevPair = PrevPair;
|
||||
|
||||
Buffer++; /* Skip over LanguageSet */
|
||||
|
||||
/* Key */
|
||||
length = read_uint8le(Buffer);
|
||||
if(length > 127){
|
||||
length = (length & 127) | (read_uint8le(Buffer+1) << 7);
|
||||
Buffer++;
|
||||
}
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Key = malloc(length+1);
|
||||
memcpy(CurrentPair->Pair.Key, Buffer+1, length);
|
||||
CurrentPair->Pair.Key[length] = 0x00;
|
||||
}
|
||||
Buffer += length + 1;
|
||||
|
||||
/* Value */
|
||||
length = read_uint8le(Buffer);
|
||||
if(length > 127){
|
||||
length = (length & 127) | (read_uint8le(Buffer+1) << 7);
|
||||
Buffer++;
|
||||
}
|
||||
if(length != 0){
|
||||
CurrentPair->Pair.Value = malloc(length+1);
|
||||
memcpy(CurrentPair->Pair.Value, Buffer+1, length);
|
||||
CurrentPair->Pair.Value[length] = 0x00;
|
||||
}
|
||||
Buffer += length + 1;
|
||||
|
||||
PrevPair = CurrentPair;
|
||||
}
|
||||
StringData->LanguageSets[LanguageSet].LastPair = PrevPair;
|
||||
}
|
||||
} return 1;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize){
|
||||
return 1;
|
||||
}
|
|
@ -15,6 +15,14 @@
|
|||
*/
|
||||
|
||||
#ifndef read_uint32be
|
||||
#define read_int32be(x) (signed)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
|
||||
#define read_int24be(x) (signed)(((x)[0]<<(8*2)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*0)))
|
||||
#define read_int16be(x) (signed)(((x)[0]<<(8*1)) | ((x)[1]<<(8*0)))
|
||||
#define read_int8be(x) (signed)(((x)[0]<<(8*0)))
|
||||
#define read_int32le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)) | ((x)[3]<<(8*3)))
|
||||
#define read_int24le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*2)))
|
||||
#define read_int16le(x) (signed)(((x)[0]<<(8*0)) | ((x)[1]<<(8*1)))
|
||||
#define read_int8le(x) (signed)(((x)[0]<<(8*0)))
|
||||
#define read_uint32be(x) (unsigned)(((x)[0]<<(8*3)) | ((x)[1]<<(8*2)) | ((x)[2]<<(8*1)) | ((x)[3]<<(8*0)))
|
||||
#define read_uint24be(x) (unsigned)(((x)[0]<<(8*2)) | ((x)[1]<<(8*1)) | ((x)[2]<<(8*0)))
|
||||
#define read_uint16be(x) (unsigned)(((x)[0]<<(8*1)) | ((x)[1]<<(8*0)))
|
||||
|
@ -25,6 +33,10 @@
|
|||
#define read_uint8le(x) (unsigned)(((x)[0]<<(8*0)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** IFF file headers
|
||||
*/
|
||||
|
||||
typedef struct IFFChunk_struct
|
||||
{
|
||||
char Type[5];
|
||||
|
@ -55,6 +67,63 @@ typedef struct IFFFile_struct
|
|||
|
||||
static const uint8_t Header_IFF[] = "IFF FILE 2.5:TYPE FOLLOWED BY SIZE\0 JAMIE DOORNBOS & MAXIS 1";
|
||||
|
||||
/*
|
||||
** IFF chunk structs
|
||||
*/
|
||||
|
||||
/* STR# chunk */
|
||||
|
||||
enum IFFLanguage {
|
||||
IFFLANG_DEFAULT = 0,
|
||||
IFFLANG_EN_US = 1,
|
||||
IFFLANG_EN_INTERNATIONAL = 2,
|
||||
IFFLANG_FRENCH = 3,
|
||||
IFFLANG_GERMAN = 4,
|
||||
IFFLANG_ITALIAN = 5,
|
||||
IFFLANG_SPANISH = 6,
|
||||
IFFLANG_DUTCH = 7,
|
||||
IFFLANG_DANISH = 8,
|
||||
IFFLANG_SWEDISH = 9,
|
||||
IFFLANG_NORWEGIAN = 10,
|
||||
IFFLANG_FINNISH = 11,
|
||||
IFFLANG_HEBREW = 12,
|
||||
IFFLANG_RUSSIAN = 13,
|
||||
IFFLANG_PORTUGUESE = 14,
|
||||
IFFLANG_JAPANESE = 15,
|
||||
IFFLANG_POLISH = 16,
|
||||
IFFLANG_CHINESE_SIMPLIFIED = 17,
|
||||
IFFLANG_CHINESE_TRADITIONAL = 18,
|
||||
IFFLANG_THAI = 19,
|
||||
IFFLANG_KOREAN = 20
|
||||
};
|
||||
|
||||
typedef struct IFFStringPair_struct
|
||||
{
|
||||
uint8_t LanguageSet;
|
||||
char * Key;
|
||||
char * Value;
|
||||
} IFFStringPair;
|
||||
|
||||
typedef struct IFFStringPairNode_struct
|
||||
{
|
||||
IFFStringPair Pair;
|
||||
struct IFFStringPairNode_struct * PrevPair;
|
||||
struct IFFStringPairNode_struct * NextPair;
|
||||
} IFFStringPairNode;
|
||||
|
||||
typedef struct IFFLanguageSet_struct
|
||||
{
|
||||
uint16_t PairCount;
|
||||
IFFStringPairNode * FirstPair;
|
||||
IFFStringPairNode * LastPair;
|
||||
} IFFLanguageSet;
|
||||
|
||||
typedef struct IFF_STR_struct
|
||||
{
|
||||
int16_t Format;
|
||||
IFFLanguageSet LanguageSets[20];
|
||||
} IFF_STR;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -78,7 +147,9 @@ void iff_delete(IFFFile * IFFFileInfo);
|
|||
** IFF chunk functions
|
||||
*/
|
||||
|
||||
int iff_read_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned MaxChunkSize, unsigned IFFSize);
|
||||
int iff_parse_rsmp(IFFChunk * ChunkInfo, const uint8_t * Buffer, unsigned IFFSize);
|
||||
int iff_parse_chunk(IFFChunk * ChunkInfo, const uint8_t * Buffer);
|
||||
int iff_parse_str(IFFChunk * ChunkInfo, const uint8_t * Buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -288,8 +288,7 @@ void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float TimeDelta)
|
|||
{
|
||||
float Duration = (float)Animation.Motions[0].FrameCount/30;
|
||||
AnimationTime += TimeDelta;
|
||||
while(AnimationTime >= Duration) AnimationTime -= Duration;
|
||||
if(AnimationTime<0) AnimationTime = 0; //Safe-guard against rounding error
|
||||
AnimationTime = fmodf(AnimationTime, Duration); //Loop the animation
|
||||
|
||||
for(unsigned i=0; i<Animation.MotionsCount; i++){
|
||||
unsigned BoneIndex = FindBone(Skeleton, Animation.Motions[i].BoneName, Skeleton.BoneCount);
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
#define PACKAGE "libvitaboy"
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION_A 0
|
||||
#define VERSION_A 1
|
||||
#define VERSION_B 0
|
||||
#define VERSION_C 1
|
||||
#define VERSION_STR "0.0.1"
|
||||
#define VERSION_STR "1.0.1"
|
||||
/* You should fill the revision in if you're compiling from the trunk */
|
||||
#define REVISION 0
|
|
@ -85,11 +85,6 @@ void ReadMesh(Mesh_t& Mesh){
|
|||
//Blended vertex
|
||||
Mesh.TransformedVertexData[i].BlendData.Weight = BlendData[i-Mesh.RealVertexCount].Weight;
|
||||
Mesh.TransformedVertexData[i].BlendData.OtherVertex = BlendData[i-Mesh.RealVertexCount].OtherVertex;
|
||||
|
||||
//Inherit texture coordinates
|
||||
TextureVertex_t& Parent = TextureVertexData[Mesh.TransformedVertexData[i].BlendData.OtherVertex];
|
||||
Mesh.TransformedVertexData[i].TextureCoord.u = Parent.u;
|
||||
Mesh.TransformedVertexData[i].TextureCoord.v = Parent.v;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue