Skip to content

Commit

Permalink
Fix various problems
Browse files Browse the repository at this point in the history
  • Loading branch information
vabold committed Jan 11, 2024
1 parent 9733e07 commit 5feeba2
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 45 deletions.
2 changes: 1 addition & 1 deletion source/egg/math/Quat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Quatf Quatf::conjugate() const {
return Quatf(w, -v);
}

Vector3f Quatf::rotateVector(const EGG::Vector3f &vec) const {
Vector3f Quatf::rotateVector(const Vector3f &vec) const {
Quatf conj = conjugate();
Quatf res = *this * vec;
res *= conj;
Expand Down
15 changes: 9 additions & 6 deletions source/egg/math/Quat.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ struct Quatf {
return Quatf(-v.dot(vec), cross + scale);
}

void operator*=(const Quatf &q) {
Vector3f cross = v.cross(q.v);
Vector3f scaleLhs = v * q.w;
Vector3f scaleRhs = q.v * w;
Quatf operator*(const Quatf &rhs) const {
Vector3f cross = v.cross(rhs.v);
Vector3f scaleLhs = v * rhs.w;
Vector3f scaleRhs = rhs.v * w;

w = w * q.w - v.dot(q.v);
v = cross + scaleRhs + scaleLhs;
return Quatf(w * rhs.w - v.dot(rhs.v), cross + scaleRhs + scaleLhs);
}

Quatf &operator*=(const Quatf &q) {
return *this = *this * q;
}

void setRPY(const Vector3f &rpy);
Expand Down
12 changes: 9 additions & 3 deletions source/game/system/CourseMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ CourseMap *CourseMap::Instance() {
return s_instance;
}

CourseMap::CourseMap() : m_course(nullptr), m_startPoint(nullptr) {}

CourseMap::~CourseMap() = default;
CourseMap::CourseMap()
: m_course(nullptr), m_startPoint(nullptr), m_stageInfo(nullptr), m_startTmpAngle(0.0f),
m_startTmp0(0.0f), m_startTmp1(0.0f), m_startTmp2(0.0f), m_startTmp3(0.0f) {}

CourseMap::~CourseMap() {
delete m_course;
delete m_startPoint;
delete m_stageInfo;
}

void *CourseMap::LoadFile(const char *filename) {
return ResourceManager::Instance()->getFile(filename, nullptr, 1);
Expand Down
12 changes: 12 additions & 0 deletions source/game/system/map/MapdataAccessorBase.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class MapdataAccessorBase {
public:
MapdataAccessorBase(const MapSectionHeader *header)
: m_entries(nullptr), m_entryCount(0), m_sectionHeader(header) {}
MapdataAccessorBase(const MapdataAccessorBase &) = delete;
MapdataAccessorBase(MapdataAccessorBase &&) = delete;

virtual ~MapdataAccessorBase() {
if (m_entries) {
for (size_t i = 0; i < m_entryCount; ++i) {
delete m_entries[i];
}
}

delete[] m_entries;
}

T *get(u16 i) const {
return i < m_entryCount ? m_entries[i] : nullptr;
Expand Down
2 changes: 2 additions & 0 deletions source/game/system/map/MapdataStageInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ MapdataStageInfoAccessor::MapdataStageInfoAccessor(const MapSectionHeader *heade
m_sectionHeader->count);
}

MapdataStageInfoAccessor::~MapdataStageInfoAccessor() = default;

} // namespace System
1 change: 1 addition & 0 deletions source/game/system/map/MapdataStageInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MapdataStageInfoAccessor
: public MapdataAccessorBase<MapdataStageInfo, MapdataStageInfo::SData> {
public:
MapdataStageInfoAccessor(const MapSectionHeader *header);
~MapdataStageInfoAccessor() override;
};

} // namespace System
67 changes: 35 additions & 32 deletions source/game/system/map/MapdataStartPoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@

namespace System {

// We have to define these early so they're available for findKartStartPoint
static constexpr s8 X_TRANSLATION_TABLE[12][12] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 5, -5, 10, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 0, 10, -5, 5, 0, 0, 0, 0, 0, 0, 0},
{-10, -2, 6, -6, 2, 10, 0, 0, 0, 0, 0, 0},
{-5, 5, -10, 0, 10, -5, 5, 0, 0, 0, 0, 0},
{-10, 0, 10, -5, 5, -10, 0, 10, 0, 0, 0, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, 0, 0, 0},
{-10, 0, 10, -5, 5, -10, 0, 10, -5, 5, 0, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, -6, 2, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, -6, 2, 10},
};

static constexpr s8 Z_TRANSLATION_TABLE[12][12] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 2, 2, 2, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0},
{0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 0, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3},
};

MapdataStartPoint::MapdataStartPoint(const SData *data) : m_rawData(data) {
u8 *unsafeData = reinterpret_cast<u8 *>(const_cast<SData *>(data));
EGG::RamStream stream = EGG::RamStream(unsafeData, sizeof(SData));
Expand Down Expand Up @@ -41,12 +72,12 @@ void MapdataStartPoint::findKartStartPoint(EGG::Vector3f &pos, EGG::Vector3f &an
f32 cos = EGG::Mathf::CosFIdx(courseMap->startTmpAngle() * DEG2FIDX);
f32 sin = EGG::Mathf::SinFIdx(courseMap->startTmpAngle() * DEG2FIDX) * translationDirection;

int xTranslation = translationDirection * s_xTranslationTable[playerCount - 1][0];
int xTranslation = translationDirection * X_TRANSLATION_TABLE[playerCount - 1][0];
f32 xScalar =
sin * (courseMap->startTmp0() * (static_cast<f32>(xTranslation) + 10.0f) / 10.0f) / cos;
EGG::Vector3f xTmp = -zAxis * xScalar;

int zTranslation = s_zTranslationTable[playerCount - 1][placement];
int zTranslation = Z_TRANSLATION_TABLE[playerCount - 1][placement];
f32 zScalar = courseMap->startTmp2() * static_cast<f32>(zTranslation / 2) +
courseMap->startTmp1() * static_cast<f32>(zTranslation) +
courseMap->startTmp3() * static_cast<f32>((zTranslation + 1) / 2);
Expand All @@ -61,7 +92,7 @@ void MapdataStartPoint::findKartStartPoint(EGG::Vector3f &pos, EGG::Vector3f &an
EGG::Vector3f vSin = zAxis * sin;
EGG::Vector3f vRes = vCos + vSin;

int tmpTranslation = translationDirection * s_xTranslationTable[playerCount - 1][placement];
int tmpTranslation = translationDirection * X_TRANSLATION_TABLE[playerCount - 1][placement];
f32 tmpScalar =
courseMap->startTmp0() * (static_cast<f32>(tmpTranslation) + 10.0f) / (cos * 10.0f);
EGG::Vector3f tmpRes = vRes * tmpScalar;
Expand All @@ -82,34 +113,6 @@ MapdataStartPointAccessor::MapdataStartPointAccessor(const MapSectionHeader *hea
}
}

const s8 MapdataStartPoint::s_xTranslationTable[12][12] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 5, -5, 10, 0, 0, 0, 0, 0, 0, 0, 0},
{-10, 0, 10, -5, 5, 0, 0, 0, 0, 0, 0, 0},
{-10, -2, 6, -6, 2, 10, 0, 0, 0, 0, 0, 0},
{-5, 5, -10, 0, 10, -5, 5, 0, 0, 0, 0, 0},
{-10, 0, 10, -5, 5, -10, 0, 10, 0, 0, 0, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, 0, 0, 0},
{-10, 0, 10, -5, 5, -10, 0, 10, -5, 5, 0, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, -6, 2, 0},
{-10, -2, 6, -6, 2, 10, -10, -2, 6, -6, 2, 10},
};

const s8 MapdataStartPoint::s_zTranslationTable[12][12] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 2, 2, 2, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 0, 0, 0},
{0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 0, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 0},
{0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3},
};
MapdataStartPointAccessor::~MapdataStartPointAccessor() = default;

} // namespace System
4 changes: 1 addition & 3 deletions source/game/system/map/MapdataStartPoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ private:
EGG::Vector3f m_position;
EGG::Vector3f m_rotation;
s16 m_playerIndex;

static const s8 s_xTranslationTable[12][12];
static const s8 s_zTranslationTable[12][12];
};

class MapdataStartPointAccessor
: public MapdataAccessorBase<MapdataStartPoint, MapdataStartPoint::SData> {
public:
MapdataStartPointAccessor(const MapSectionHeader *header);
~MapdataStartPointAccessor() override;
};

} // namespace System

0 comments on commit 5feeba2

Please sign in to comment.