Added Movtex and MovetexQC to DynOS level gen

This commit is contained in:
MysterD 2022-04-03 22:12:17 -07:00
parent 03b0520504
commit df346a902a
8 changed files with 380 additions and 2 deletions

View file

@ -5,6 +5,7 @@
#include "dynos.h"
extern "C" {
#include "engine/math_util.h"
#include "src/game/moving_texture.h"
}
#define FUNCTION_CODE (u32) 0x434E5546
@ -30,6 +31,8 @@ enum {
DATA_TYPE_LEVEL_SCRIPT,
DATA_TYPE_MACRO_OBJECT,
DATA_TYPE_TRAJECTORY,
DATA_TYPE_MOVTEX,
DATA_TYPE_MOVTEXQC,
DATA_TYPE_UNUSED,
};
@ -365,6 +368,7 @@ template <typename U, typename V>
using Pair = std::pair<U, V>;
typedef std::string SysPath;
typedef struct MovtexQuadCollection MovtexQC;
class NoCopy {
protected:
@ -428,6 +432,8 @@ struct GfxData : NoCopy {
DataNodes<LevelScript> mLevelScripts;
DataNodes<MacroObject> mMacroObjects;
DataNodes<Trajectory> mTrajectories;
DataNodes<Movtex> mMovtexs;
DataNodes<MovtexQC> mMovtexQCs;
// Animation data
Array<AnimBuffer<s16> *> mAnimValues;
@ -759,6 +765,14 @@ DataNode<Trajectory>* DynOS_Trajectory_Parse(GfxData* aGfxData, DataNode<Traject
void DynOS_Trajectory_Write(FILE* aFile, GfxData* aGfxData, DataNode<Trajectory> *aNode);
DataNode<Trajectory>* DynOS_Trajectory_Load(FILE *aFile, GfxData *aGfxData);
DataNode<Movtex>* DynOS_Movtex_Parse(GfxData* aGfxData, DataNode<Movtex>* aNode, bool aDisplayPercent);
void DynOS_Movtex_Write(FILE* aFile, GfxData* aGfxData, DataNode<Movtex> *aNode);
DataNode<Movtex>* DynOS_Movtex_Load(FILE *aFile, GfxData *aGfxData);
DataNode<MovtexQC>* DynOS_MovtexQC_Parse(GfxData* aGfxData, DataNode<MovtexQC>* aNode);
void DynOS_MovtexQC_Write(FILE* aFile, GfxData* aGfxData, DataNode<MovtexQC> *aNode);
DataNode<MovtexQC>* DynOS_MovtexQC_Load(FILE *aFile, GfxData *aGfxData);
DataNode<TexData>* DynOS_Tex_Parse(GfxData* aGfxData, DataNode<TexData>* aNode);
void DynOS_Tex_Write(FILE* aFile, GfxData* aGfxData, DataNode<TexData> *aNode);
void DynOS_Tex_Load(FILE *aFile, GfxData *aGfxData);

View file

@ -1442,6 +1442,20 @@ static LevelScript ParseLevelScriptSymbolArg(GfxData* aGfxData, DataNode<LevelSc
}
}
// Movtexs
for (auto& _Node : aGfxData->mMovtexs) {
if (_Arg == _Node->mName) {
return (LevelScript) DynOS_Movtex_Parse(aGfxData, _Node, false)->mData;
}
}
// MovtexQCs
for (auto& _Node : aGfxData->mMovtexQCs) {
if (_Arg == _Node->mName) {
return (LevelScript) DynOS_MovtexQC_Parse(aGfxData, _Node)->mData;
}
}
// Integers
s32 x;
if ((_Arg[1] == 'x' && sscanf(_Arg.begin(), "%x", &x) == 1) || (sscanf(_Arg.begin(), "%d", &x) == 1)) {
@ -1455,7 +1469,6 @@ static LevelScript ParseLevelScriptSymbolArg(GfxData* aGfxData, DataNode<LevelSc
return (LevelScript)rdValue;
}
// Unknown
PrintError(" ERROR: Unknown lvl arg: %s", _Arg.begin());
return 0;
@ -1802,6 +1815,16 @@ static bool DynOS_Lvl_WriteBinary(const SysPath &aOutputFilename, GfxData *aGfxD
DynOS_Trajectory_Write(_File, aGfxData, _Node);
}
}
for (auto &_Node : aGfxData->mMovtexs) {
if (_Node->mLoadIndex == i) {
DynOS_Movtex_Write(_File, aGfxData, _Node);
}
}
for (auto &_Node : aGfxData->mMovtexQCs) {
if (_Node->mLoadIndex == i) {
DynOS_MovtexQC_Write(_File, aGfxData, _Node);
}
}
}
fclose(_File);
return true;

199
data/dynos_bin_movtex.cpp Normal file
View file

@ -0,0 +1,199 @@
#include "dynos.cpp.h"
extern "C" {
#include "include/moving_texture_macros.h"
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing"
/////////////
// Parsing //
/////////////
#define MOVTEX_SIZE_PER_TOKEN 4
#define movtex_constant(x) if (_Arg == #x) { return (s64) (x); }
static s64 ParseMovtexSymbolArg(GfxData* aGfxData, DataNode<Movtex>* aNode, u64& aTokenIndex) {
const String& _Arg = aNode->mTokens[aTokenIndex++];
// texture constants
movtex_constant(TEXTURE_WATER);
movtex_constant(TEXTURE_MIST);
movtex_constant(TEXTURE_JRB_WATER);
movtex_constant(TEXTURE_UNK_WATER);
movtex_constant(TEXTURE_LAVA);
movtex_constant(TEX_QUICKSAND_SSL);
movtex_constant(TEX_PYRAMID_SAND_SSL);
movtex_constant(TEX_YELLOW_TRI_TTC);
movtex_constant(ROTATE_CLOCKWISE);
movtex_constant(ROTATE_COUNTER_CLOCKWISE);
// Other constants
movtex_constant(NULL);
// Integers
s32 x;
if ((_Arg[1] == 'x' && sscanf(_Arg.begin(), "%x", &x) == 1) || (sscanf(_Arg.begin(), "%d", &x) == 1)) {
return (s64) x;
}
// Unknown
PrintError(" ERROR: Unknown movtex arg: %s", _Arg.begin());
return 0;
}
#define movtex_symbol_0(symb) \
if (_Symbol == #symb) { \
Movtex _Mt[] = { symb() }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
#define movtex_symbol_1(symb) \
if (_Symbol == #symb) { \
s64 _Arg0 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
Movtex _Mt[] = { symb(_Arg0) }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
#define movtex_symbol_2(symb) \
if (_Symbol == #symb) { \
s64 _Arg0 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg1 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
Movtex _Mt[] = { symb(_Arg0, _Arg1) }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
#define movtex_symbol_5(symb) \
if (_Symbol == #symb) { \
s64 _Arg0 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg1 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg2 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg3 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg4 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
Movtex _Mt[] = { symb(_Arg0, _Arg1, _Arg2, _Arg3, _Arg4) }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
#define movtex_symbol_6(symb) \
if (_Symbol == #symb) { \
s64 _Arg0 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg1 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg2 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg3 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg4 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg5 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
Movtex _Mt[] = { symb(_Arg0, _Arg1, _Arg2, _Arg3, _Arg4, \
_Arg5) }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
#define movtex_symbol_8(symb) \
if (_Symbol == #symb) { \
s64 _Arg0 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg1 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg2 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg3 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg4 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg5 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg6 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
s64 _Arg7 = ParseMovtexSymbolArg(aGfxData, aNode, aTokenIndex); \
Movtex _Mt[] = { symb(_Arg0, _Arg1, _Arg2, _Arg3, _Arg4, \
_Arg5, _Arg6, _Arg7) }; \
memcpy(aHead, _Mt, sizeof(_Mt)); \
aHead += (sizeof(_Mt) / sizeof(_Mt[0])); \
return; \
}
static void ParseMovtexSymbol(GfxData* aGfxData, DataNode<Movtex>* aNode, Movtex*& aHead, u64& aTokenIndex, Array<u64>& aSwitchNodes) {
const String& _Symbol = aNode->mTokens[aTokenIndex++];
movtex_symbol_1(MOV_TEX_INIT_LOAD);
movtex_symbol_2(MOV_TEX_4_BOX_TRIS);
movtex_symbol_1(MOV_TEX_DEFINE);
movtex_symbol_1(MOV_TEX_SPD);
movtex_symbol_1(MOV_TEX_ROT_SPEED);
movtex_symbol_1(MOV_TEX_ROT_SCALE);
movtex_symbol_1(MOV_TEX_ROT);
movtex_symbol_1(MOV_TEX_ALPHA);
movtex_symbol_5(MOV_TEX_TRIS);
movtex_symbol_8(MOV_TEX_ROT_TRIS);
movtex_symbol_6(MOV_TEX_LIGHT_TRIS);
movtex_symbol_0(MOV_TEX_END);
movtex_symbol_0(MOV_TEX_ROT_END);
// Unknown
PrintError(" ERROR: Unknown movtex symbol: %s", _Symbol.begin());
}
DataNode<Movtex>* DynOS_Movtex_Parse(GfxData* aGfxData, DataNode<Movtex>* aNode, bool aDisplayPercent) {
if (aNode->mData) return aNode;
// Movtex data
aNode->mData = New<Movtex>(aNode->mTokens.Count() * MOVTEX_SIZE_PER_TOKEN);
Movtex* _Head = aNode->mData;
Array<u64> _SwitchNodes;
for (u64 _TokenIndex = 0; _TokenIndex < aNode->mTokens.Count();) { // Don't increment _TokenIndex here!
ParseMovtexSymbol(aGfxData, aNode, _Head, _TokenIndex, _SwitchNodes);
if (aDisplayPercent && aGfxData->mErrorCount == 0) { PrintNoNewLine("%3d%%\b\b\b\b", (s32) (_TokenIndex * 100) / aNode->mTokens.Count()); }
}
if (aDisplayPercent && aGfxData->mErrorCount == 0) { Print("100%%"); }
aNode->mSize = (u32)(_Head - aNode->mData);
aNode->mLoadIndex = aGfxData->mLoadIndex++;
return aNode;
}
#pragma GCC diagnostic pop
/////////////
// Writing //
/////////////
void DynOS_Movtex_Write(FILE* aFile, GfxData* aGfxData, DataNode<Movtex> *aNode) {
if (!aNode->mData) return;
// Name
WriteBytes<u8>(aFile, DATA_TYPE_MOVTEX);
aNode->mName.Write(aFile);
// Data
WriteBytes<u32>(aFile, aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
WriteBytes<Movtex>(aFile, aNode->mData[i]);
}
}
/////////////
// Reading //
/////////////
DataNode<Movtex>* DynOS_Movtex_Load(FILE *aFile, GfxData *aGfxData) {
DataNode<Movtex> *_Node = New<DataNode<Movtex>>();
// Name
_Node->mName.Read(aFile);
// Data
_Node->mSize = ReadBytes<u32>(aFile);
_Node->mData = New<Movtex>(_Node->mSize);
for (u32 i = 0; i != _Node->mSize; ++i) {
_Node->mData[i] = ReadBytes<Movtex>(aFile);
}
// Add it
if (aGfxData != NULL) {
aGfxData->mMovtexs.Add(_Node);
}
return _Node;
}

View file

@ -0,0 +1,97 @@
#include "dynos.cpp.h"
extern "C" {
#include "include/level_misc_macros.h"
#include "src/game/moving_texture.h"
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnarrowing"
/////////////
// Parsing //
/////////////
#define movtexqc_constant(x) if (_Arg == #x) { return (s64) (x); }
static Movtex* ParseMovtexQCSymbolArg(GfxData* aGfxData, DataNode<MovtexQC>* aNode, u64 aTokenIndex) {
const String& _Arg = aNode->mTokens[aTokenIndex];
// Other constants
movtexqc_constant(NULL);
// Movtexs
for (auto& _Node : aGfxData->mMovtexs) {
if (_Arg == _Node->mName) {
return DynOS_Movtex_Parse(aGfxData, _Node, false)->mData;
}
}
// Unknown
PrintError(" ERROR: Unknown movtexqc arg: %s", _Arg.begin());
return NULL;
}
DataNode<MovtexQC>* DynOS_MovtexQC_Parse(GfxData* aGfxData, DataNode<MovtexQC>* aNode) {
if (aNode->mData) return aNode;
// MovtexQC data
aNode->mSize = (u32) (aNode->mTokens.Count() / 2);
aNode->mData = New<MovtexQC>(aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
s16 id = (s16) aNode->mTokens[2 * i + 0].ParseInt();
Movtex* quadArraySegmented = ParseMovtexQCSymbolArg(aGfxData, aNode, 2 * i + 1);
aNode->mData[i] = { id, quadArraySegmented };
aGfxData->mPointerList.Add(aNode->mData[i].quadArraySegmented);
}
aNode->mLoadIndex = aGfxData->mLoadIndex++;
return aNode;
}
#pragma GCC diagnostic pop
/////////////
// Writing //
/////////////
void DynOS_MovtexQC_Write(FILE* aFile, GfxData* aGfxData, DataNode<MovtexQC> *aNode) {
if (!aNode->mData) return;
// Name
WriteBytes<u8>(aFile, DATA_TYPE_MOVTEXQC);
aNode->mName.Write(aFile);
// Data
WriteBytes<u32>(aFile, aNode->mSize);
for (u32 i = 0; i != aNode->mSize; ++i) {
WriteBytes<s16>(aFile, aNode->mData[i].id);
DynOS_Pointer_Write(aFile, (const void *) (aNode->mData[i].quadArraySegmented), aGfxData);
}
}
/////////////
// Reading //
/////////////
DataNode<MovtexQC>* DynOS_MovtexQC_Load(FILE *aFile, GfxData *aGfxData) {
DataNode<MovtexQC> *_Node = New<DataNode<MovtexQC>>();
// Name
_Node->mName.Read(aFile);
// Data
_Node->mSize = ReadBytes<u32>(aFile);
_Node->mData = New<MovtexQC>(_Node->mSize);
for (u32 i = 0; i != _Node->mSize; ++i) {
_Node->mData[i].id = ReadBytes<s16>(aFile);
u32 _Value = ReadBytes<u32>(aFile);
void *_Ptr = DynOS_Pointer_Load(aFile, aGfxData, _Value, false);
_Node->mData[i].quadArraySegmented = (Movtex*)_Ptr;
}
// Add it
if (aGfxData != NULL) {
aGfxData->mMovtexQCs.Add(_Node);
}
return _Node;
}

View file

@ -92,6 +92,20 @@ static PointerData GetDataFromPointer(const void* aPtr, GfxData* aGfxData) {
}
}
// Movtexs
for (auto& _Node : aGfxData->mMovtexs) {
if (_Node->mData == aPtr) {
return { _Node->mName, 0 };
}
}
// MovtexQCs
for (auto& _Node : aGfxData->mMovtexQCs) {
if (_Node->mData == aPtr) {
return { _Node->mName, 0 };
}
}
// Behaviors
enum BehaviorId id = get_id_from_vanilla_behavior((const BehaviorScript*) aPtr);
if (id >= 0 && id < id_bhv_max_count) {
@ -160,7 +174,7 @@ void DynOS_Pointer_Write(FILE* aFile, const void* aPtr, GfxData* aGfxData) {
// Pointer
PointerData _PtrData = GetDataFromPointer(aPtr, aGfxData);
if (strlen(_PtrData.first.begin()) == 0) {
_PtrData = _PtrData;
_PtrData = _PtrData; // DO NOT COMMIT
}
WriteBytes<u32>(aFile, POINTER_CODE);
_PtrData.first.Write(aFile);
@ -242,6 +256,20 @@ static void *GetPointerFromData(GfxData *aGfxData, const String &aPtrName, u32 a
}
}
// Movtexs
for (auto &_Node : aGfxData->mMovtexs) {
if (_Node->mName == aPtrName) {
return (void *) _Node->mData;
}
}
// MovtexQCs
for (auto &_Node : aGfxData->mMovtexQCs) {
if (_Node->mName == aPtrName) {
return (void *) _Node->mData;
}
}
// Behaviors
enum BehaviorId id = get_id_from_behavior_name(aPtrName.begin());
if (id >= 0 && id < id_bhv_max_count) {

View file

@ -171,6 +171,8 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) {
// Ignore ALIGNED8 keyword
} else if (_Buffer == "UNUSED") {
// Ignore UNUSED keyword
} else if (_Buffer == "struct") {
// Ignore struct keyword
} else if (_Buffer == "u64") {
_DataType = DATA_TYPE_UNUSED;
} else if (_Buffer == "Lights1") {
@ -193,6 +195,10 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) {
_DataType = DATA_TYPE_MACRO_OBJECT;
} else if (_Buffer == "Trajectory") {
_DataType = DATA_TYPE_TRAJECTORY;
} else if (_Buffer == "Movtex") {
_DataType = DATA_TYPE_MOVTEX;
} else if (_Buffer == "MovtexQuadCollection") {
_DataType = DATA_TYPE_MOVTEXQC;
} else {
PrintError(" ERROR: Unknown type name: %s", _Buffer.begin());
}
@ -220,6 +226,8 @@ void DynOS_Read_Source(GfxData *aGfxData, const SysPath &aFilename) {
case DATA_TYPE_LEVEL_SCRIPT: AppendNewNode(aGfxData, aGfxData->mLevelScripts, _Buffer, pDataName, pDataTokens); break;
case DATA_TYPE_MACRO_OBJECT: AppendNewNode(aGfxData, aGfxData->mMacroObjects, _Buffer, pDataName, pDataTokens); break;
case DATA_TYPE_TRAJECTORY: AppendNewNode(aGfxData, aGfxData->mTrajectories, _Buffer, pDataName, pDataTokens); break;
case DATA_TYPE_MOVTEX: AppendNewNode(aGfxData, aGfxData->mMovtexs, _Buffer, pDataName, pDataTokens); break;
case DATA_TYPE_MOVTEXQC: AppendNewNode(aGfxData, aGfxData->mMovtexQCs, _Buffer, pDataName, pDataTokens); break;
case DATA_TYPE_UNUSED: pDataTokens = (Array<String> *) 1; break;
}
_Buffer.Clear();

View file

@ -46,6 +46,14 @@ void DynOS_Gfx_Free(GfxData* aGfxData) {
Delete(_Node->mData);
Delete(_Node);
}
for (auto& _Node : aGfxData->mMovtexs) {
Delete(_Node->mData);
Delete(_Node);
}
for (auto& _Node : aGfxData->mMovtexQCs) {
Delete(_Node->mData);
Delete(_Node);
}
Delete(aGfxData);
}
}

View file

@ -226,6 +226,7 @@ s32 DynOS_Level_GetCourse(s32 aLevel) {
const void *DynOS_Level_GetScript(s32 aLevel) {
DynOS_Level_Init();
return DynOS_Lvl_Get("level_bob_entry"); // DO NOT COMMIT
return sDynosLevelScripts[aLevel];
}