Skip to content

Commit

Permalink
extra work i did that i forgot to commit (#330)
Browse files Browse the repository at this point in the history
* oops! i never committed these

* oop

* oop 2
  • Loading branch information
ieee802dot11ac authored Sep 3, 2024
1 parent 8bb3efb commit 235b0ca
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 23 deletions.
1 change: 1 addition & 0 deletions config/SZBE69_B8/objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cflags": "band3",
"objects": {
"band3/bandtrack/Gem.cpp": "NonMatching",
"band3/bandtrack/GemRepTemplate.cpp": "NonMatching",
"band3/bandtrack/GemSmasher.cpp": "Matching",
"band3/bandtrack/GraphicsUtl.cpp": "Matching",
"band3/bandtrack/TrackConfig.cpp": "Matching",
Expand Down
113 changes: 113 additions & 0 deletions src/band3/bandtrack/GemRepTemplate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "GemRepTemplate.h"
#include "bandtrack/GraphicsUtl.h"
#include "bandtrack/TrackConfig.h"
#include "os/Debug.h"
#include "os/System.h"
#include "rndobj/Mat.h"
#include <algorithm>

#define kNumGemSlotMats 1

GemRepTemplate::GemRepTemplate(const TrackConfig& tc) : mConfig(SystemConfig("track_graphics", "gem")),
kTailPulseRate(mConfig->FindArray("tail_pulse_rate", true)->Float(1)),
kTailPulseSmoothing(mConfig->FindArray("tail_pulse_smoothing", true)->Float(1)),
kTailOffsetX(mConfig->FindArray("tail_offset_x", true)->Float(1)),
kTailMinAlpha(mConfig->FindArray("tail_min_alpha", true)->Float(1)),
kTailMaxAlpha(mConfig->FindArray("tail_max_alpha", true)->Float(1)),
kTailAlphaSmoothing(mConfig->FindArray("tail_alpha_smoothing", true)->Float(1)),
kTailFadeDistance(mConfig->FindArray("tail_fade_distance", true)->Float(1)),
kTailMaxLength(mConfig->FindArray("tail_max_length", true)->Float(1)),
kTailFrequencyRange(mConfig->FindArray("tail_min_freq", true)->Float(1), mConfig->FindArray("tail_max_freq", true)->Float(1)),
kTailAmplitudeRange(mConfig->FindArray("tail_min_amp", true)->Float(1), mConfig->FindArray("tail_max_amp", true)->Float(1)),
mTrackCfg(tc), unk_0x3C(0), unk_0x40(1.0f), objectDir(NULL) {
mSlots = (RndMat**)new void*[tc.GetMaxSlots()]; // it doesn't call the ctors, so i have to do This to just alloc
}

GemRepTemplate::~GemRepTemplate() {
RndMesh* end = *mTails.end();
for (RndMesh* it = *mTails.begin(); it != end; it++) delete it; // i hate how well this matches
mTails.clear();
delete[] mSlots;
}

void GemRepTemplate::Init(ObjectDir*) {

}

RndMesh* GemRepTemplate::GetTail() {
RndMesh* m;
if (mTails.size() == 0) m = CreateTail();
else {
m = mTails.back();
mTails.pop_back();
}
return m;
}

void GemRepTemplate::ReturnTail(RndMesh* m) {
if (m != NULL) {
UnhookAllParents(m);
mTails.push_back(m);
}
}

RndMesh* GemRepTemplate::CreateTail() {
RndMesh* m = Hmx::Object::New<RndMesh>();
m->mOwner->unk_0xF0 = 0x3f;
m->mOwner->mVerts.reserve(mTailVerts.size() * (1 + mNumTailSections), true);
std::vector<RndMesh::Face>* asdf = &m->mOwner->mFaces;
asdf->reserve((mTailVerts.size() - 1) * mNumTailSections * 2);
return m;
}

int GemRepTemplate::GetRequiredVertCount(int i) const {
return mTailVerts.size() * (i + 1);
}

int GemRepTemplate::GetRequiredFaceCount(int i) const {
return (mTailVerts.size() - 1) * i * 2;
}

RndMat* GemRepTemplate::GetMatByTag(const char* c, int slot) {
const char* s = mConfig->FindArray("mat_formats", true)->FindArray(c, true)->Str(1);
return objectDir->Find<RndMat>(MakeString("%s.mat", MakeString(s, slot < mTrackCfg.GetMaxSlots() ? mTrackCfg.GetSlotColor(slot) : "star")), true);
}

bool VertLess(const RndMesh::Vert& v1, const RndMesh::Vert& v2) {
if ((float)__fabs(v1.pos.y - v2.pos.y) < 0.1f) { // nonsense regswap
return v1.pos.x < v2.pos.x;
}
return v1.pos.y < v2.pos.y;
}

void GemRepTemplate::SetupTailVerts() {
objectDir->Find<RndMesh>("tail02.mesh", false)->mOwner->mVerts = mTailVerts; // where assert
MILO_ASSERT(!(mTailVerts.size()%2), 212);
std::sort(mTailVerts.begin(), mTailVerts.end(), VertLess);
unk_0x64 = mTailVerts;
int i = 420;
mTailVerts.resize(i, true);
unk_0x64.resize(i, true);
}

int GemRepTemplate::GetNumTailSections(GemRepTemplate::TailType type) const {
MILO_ASSERT(type < kNumTailTypes, 232);
return this[type * 4].mNumTailSections; // ????
}

float GemRepTemplate::GetTailSectionLength(GemRepTemplate::TailType type) const {
MILO_ASSERT(type < kNumTailTypes, 238);
return this[type * 4].mTailSectionLen; // ????
}

RndMat* GemRepTemplate::GetSlotMat(int matIndex, int slotIndex) const {
MILO_ASSERT(( 0) <= (matIndex) && (matIndex) < ( kNumGemSlotMats), 244);
MILO_ASSERT(( 0) <= (slotIndex) && (slotIndex) < ( mTrackCfg.GetMaxSlots()), 245);
return mSlots[matIndex + slotIndex];
}

void GemRepTemplate::SetSlotMat(int matIndex, int slotIndex, RndMat* mat) {
MILO_ASSERT(( 0) <= (matIndex) && (matIndex) < ( kNumGemSlotMats), 251);
MILO_ASSERT(( 0) <= (slotIndex) && (slotIndex) < ( mTrackCfg.GetMaxSlots()), 252);
mSlots[matIndex + slotIndex] = mat;
}
57 changes: 57 additions & 0 deletions src/band3/bandtrack/GemRepTemplate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include "bandtrack/TrackConfig.h"
#include "obj/Data.h"
#include "obj/Dir.h"
#include "rndobj/Mesh.h"
#include <vector>

class GemRepTemplate {
enum TailType {
type0,
type1,
kNumTailTypes
};

GemRepTemplate(const TrackConfig&);
~GemRepTemplate();
void Init(ObjectDir*);
RndMesh* GetTail();
void ReturnTail(RndMesh*);
RndMesh* CreateTail();
int GetRequiredVertCount(int) const;
int GetRequiredFaceCount(int) const;
RndMat* GetMatByTag(const char*, int);
void SetupTailVerts();
int GetNumTailSections(TailType) const;
float GetTailSectionLength(TailType) const;
RndMat* GetSlotMat(int, int) const;
void SetSlotMat(int, int, RndMat*);

DataArray* mConfig; // 0x0
float kTailPulseRate; // 0x4 // why is it k. why
float kTailPulseSmoothing; // 0x8
float kTailOffsetX; // 0xC
float kTailMinAlpha; // 0x10
float kTailMaxAlpha; // 0x14
float kTailAlphaSmoothing; // 0x18
float kTailFadeDistance; // 0x1C
float kTailMaxLength; // 0x20
Vector2 kTailFrequencyRange; // 0x24
Vector2 kTailAmplitudeRange; // 0x2C
const TrackConfig& mTrackCfg; // 0x34
RndMat** mSlots; // 0x38
float unk_0x3C;
float unk_0x40;
ObjectDir* objectDir; // 0x44
uint mNumTailSections;
u32 pad1;
float mTailSectionLen;
u32 pad2;

RndMesh::VertVector mTailVerts; // 0x58
RndMesh::VertVector unk_0x64;

int pad[3];

std::vector<RndMesh*> mTails; // 0x7C
};
15 changes: 8 additions & 7 deletions src/system/obj/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ class DataNode {

class DataArray {
public:
DataNode* mNodes;
Symbol mFile;
short mSize;
short mRefs;
short mLine;
short mDeprecated;
DataNode* mNodes; // 0x0
Symbol mFile; // 0x4
short mSize; // 0x8
short mRefs; // 0xA
short mLine; // 0xC
short mDeprecated; // 0xE
static Symbol gFile;
static DataFunc* sDefaultHandler;

Expand Down Expand Up @@ -260,6 +260,7 @@ inline DataNode::~DataNode(){

DataNode& DataVariable(Symbol);
bool DataVarExists(Symbol);
bool DataArrayDefined();

// to properly generate DataArray::Node const vs non-const
#define CONST_ARRAY(array) ((const DataArray*)(array))
Expand Down Expand Up @@ -324,4 +325,4 @@ class DataArrayPtr {

inline BinStream& operator>>(BinStream& bs, DataArrayPtr& ptr) { ptr.mData->Load(bs); return bs; }

#endif
#endif
50 changes: 47 additions & 3 deletions src/system/obj/DataArray.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "obj/Data.h"
#include "types.h"
#include <stdlib.h>
#include <string.h>
#include <list>
#include "utl/MemMgr.h"
#include "math/MathFuncs.h"
#include "obj/Object.h"
#include "utl/Symbol.h"
#include "obj/DataUtl.h"
#include "os/Debug.h"
#include "math/MathFuncs.h"
#include "utl/MemMgr.h"
#include "utl/Symbol.h"

std::list<bool> gDataArrayConditional;
Symbol DataArray::gFile;
Expand Down Expand Up @@ -460,6 +462,48 @@ void DataArray::Save(BinStream &bs) const {
}
}

bool DataArrayDefined() {
for (std::list<bool>::iterator it = gDataArrayConditional.begin(); it != gDataArrayConditional.end(); it++) {
if (*it == false) return false;
}
return true;
}

void DataArray::Load(BinStream& bs) {
mFile = gFile;
u16 num_root_nodes;
bs >> num_root_nodes;
{
MemDoTempAllocations mem(true, false);
Resize(num_root_nodes);
}
bs >> mLine;
bs >> mDeprecated;
int i = 0;
while (i != num_root_nodes) {
DataNode& n = mNodes[i];
n.Load(bs);
if (!DataArrayDefined() && n.Type() < kDataIfdef) {
if (n.Type() != kDataIfndef) {
num_root_nodes--;
}
} else {
DataArray* da;
bool b = n.Type() == kDataSymbol && (da = DataGetMacro(STR_TO_SYM(n.mValue.symbol))) != 0;
if (b) {
{
num_root_nodes += (da->mSize - 1);
MemDoTempAllocations mem(true, false);
Resize(num_root_nodes);
}
}
}


i++;
}
}

void DataArray::SaveGlob(BinStream &bs, bool b) const {
if (b) {
int i = -1 - mSize;
Expand Down
16 changes: 8 additions & 8 deletions src/system/rndobj/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void RndMesh::PostLoad(BinStream& bs) {
bs >> mBones[1] >> mBones[2] >> mBones[3];
bs >> mBones[0].mOffset >> mBones[1].mOffset >> mBones[2].mOffset >> mBones[3].mOffset;
if (gRev < 25) { // incoming headache
for (std::vector<Vert>::iterator it = mVerts.begin(); it != mVerts.end(); it++) {
for (Vert* it = mVerts.begin(); it != mVerts.end(); it++) {
// it->why.Set(1 - it->why.GetX() - it->why.GetY() - it->why.GetZ(),
// it->why.GetX(), it->why.GetY(), it->why.GetZ());
}
Expand All @@ -206,7 +206,7 @@ void RndMesh::PostLoad(BinStream& bs) {
RemoveInvalidBones();


for (std::vector<Vert>::iterator it = mVerts.begin(); it != mVerts.end(); it++) {
for (Vert* it = mVerts.begin(); it != mVerts.end(); it++) {

}
if (gRev > 37) { bool b; bs >> b; unk9p0 = b;}
Expand Down Expand Up @@ -304,7 +304,7 @@ DataNode RndMesh::OnGetVertNorm(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2446);
v = &mVerts[index];
v = mVerts[index];
*da->Var(3) = DataNode(v->norm.x);
*da->Var(4) = DataNode(v->norm.y);
*da->Var(5) = DataNode(v->norm.z);
Expand All @@ -315,7 +315,7 @@ DataNode RndMesh::OnSetVertNorm(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2457);
v = &mVerts[index];
v = mVerts[index];
v->norm.x = da->Float(3);
v->norm.y = da->Float(4);
v->norm.z = da->Float(5);
Expand All @@ -327,7 +327,7 @@ DataNode RndMesh::OnGetVertXYZ(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2469);
v = &mVerts[index];
v = mVerts[index];
*da->Var(3) = DataNode(v->pos.x);
*da->Var(4) = DataNode(v->pos.y);
*da->Var(5) = DataNode(v->pos.z);
Expand All @@ -338,7 +338,7 @@ DataNode RndMesh::OnSetVertXYZ(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2480);
v = &mVerts[index];
v = mVerts[index];
v->pos.x = da->Float(3);
v->pos.y = da->Float(4);
v->pos.z = da->Float(5);
Expand All @@ -350,7 +350,7 @@ DataNode RndMesh::OnGetVertUV(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2492);
v = &mVerts[index];
v = mVerts[index];
*da->Var(3) = DataNode(v->uv.x);
*da->Var(4) = DataNode(v->uv.y);
return DataNode();
Expand All @@ -360,7 +360,7 @@ DataNode RndMesh::OnSetVertUV(const DataArray* da) {
Vert* v;
s32 index = da->Int(2);
MILO_ASSERT(index >= 0 && index < mVerts.size(), 2502);
v = &mVerts[index];
v = mVerts[index];
v->uv.x = da->Float(3);
v->uv.y = da->Float(4);
Sync(31);
Expand Down
20 changes: 15 additions & 5 deletions src/system/rndobj/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,22 @@ class RndMesh : public RndDrawable, public RndTransformable {
kVolumeBox
};

class VertVector : public std::vector<Vert, s32> { // ???????
public:
class VertVector { // more custom STL! woohoo!!!! i crave death
public:
VertVector() { mVerts = NULL; mSize = 0; mCapacity = 0;}
~VertVector() { mCapacity = 0; resize(0, true); }
u32 size() const { return mSize; };
void resize(int, bool);
void reserve(int, bool);
std::vector<Vert>::iterator begin() { return std::vector<Vert, s32>::begin(); }
std::vector<Vert>::iterator end() { return std::vector<Vert, s32>::end(); }
Vert* operator[](int);
Vert* operator[](int) const;
VertVector& operator=(const VertVector&);
Vert* begin();
Vert* end();

Vert* mVerts;
u32 mSize;
u16 mCapacity;
};

RndMesh();
Expand Down Expand Up @@ -86,7 +96,7 @@ class RndMesh : public RndDrawable, public RndTransformable {
virtual void OnSync(int);

const Vector3& VertPos(int idx) const {
return mOwner->mVerts[idx].pos;
return mOwner->mVerts[idx]->pos;
}

// TODO: figure out what RndMesh's members do
Expand Down

0 comments on commit 235b0ca

Please sign in to comment.