Commit 8e33cb82 authored by Jack Andersen's avatar Jack Andersen

Merge branch 'master' of ssh://git.axiodl.com:6431/AxioDL/urde into particle-metaclass

parents 63a748e7 668f8da9
......@@ -1750,7 +1750,8 @@ bool CBallCamera::DetectCollision(const zeus::CVector3f& from, const zeus::CVect
zeus::CVector3f delta = to - from;
float deltaMag = delta.magnitude();
zeus::CVector3f deltaNorm = delta * (1.f / deltaMag);
float clear = true;
bool clear = true;
if (deltaMag > 0.000001f) {
float margin = 2.f * radius;
zeus::CAABox aabb;
......
......@@ -8,7 +8,7 @@ namespace urde {
const CCollisionPrimitive::Type CCollidableAABox::sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox");
u32 CCollidableAABox::sTableIndex = -1;
CCollidableAABox::CCollidableAABox() {}
CCollidableAABox::CCollidableAABox() = default;
CCollidableAABox::CCollidableAABox(const zeus::CAABox& aabox, const CMaterialList& list)
: CCollisionPrimitive(list), x10_aabox(aabox) {}
......
#include "CCollisionPrimitive.hpp"
#include "CInternalRayCastStructure.hpp"
#include "CMaterialFilter.hpp"
#include "InternalColliders.hpp"
#include "CCollisionInfoList.hpp"
#include "Runtime/Collision/CCollisionPrimitive.hpp"
#include <algorithm>
#include <climits>
#include <cstring>
#include <iterator>
#include "Runtime/Collision/CCollisionInfoList.hpp"
#include "Runtime/Collision/CInternalRayCastStructure.hpp"
#include "Runtime/Collision/CMaterialFilter.hpp"
#include "Runtime/Collision/InternalColliders.hpp"
namespace urde {
s32 CCollisionPrimitive::sNumTypes = 0;
......@@ -29,6 +35,11 @@ CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const
return CastRayInternal(CInternalRayCastStructure(start, dir, length, xf, filter));
}
std::vector<CCollisionPrimitive::Type>::const_iterator CCollisionPrimitive::FindCollisionType(const char* name) {
return std::find_if(sCollisionTypeList->cbegin(), sCollisionTypeList->cend(),
[name](const auto& type) { return std::strcmp(name, type.GetInfo()) == 0; });
}
bool CCollisionPrimitive::InternalCollide(const CInternalCollisionStructure& collision, CCollisionInfoList& list) {
u32 idx0 = collision.GetLeft().GetPrim().GetTableIndex();
u32 idx1 = collision.GetRight().GetPrim().GetTableIndex();
......@@ -176,28 +187,19 @@ void CCollisionPrimitive::InitBeginColliders() {
InternalColliders::AddColliders();
}
void CCollisionPrimitive::InitAddBooleanCollider(const CCollisionPrimitive::BooleanComparison& cmp) {
int idx0 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType1(), (*sCollisionTypeList)[i].GetInfo())) {
idx0 = i;
break;
}
}
void CCollisionPrimitive::InitAddBooleanCollider(const BooleanComparison& cmp) {
const auto iter1 = FindCollisionType(cmp.GetType1());
const auto iter2 = FindCollisionType(cmp.GetType2());
const auto index1 = std::distance(sCollisionTypeList->cbegin(), iter1);
const auto index2 = std::distance(sCollisionTypeList->cbegin(), iter2);
const bool hasReachedEnd = iter1 == sCollisionTypeList->cend() || iter2 == sCollisionTypeList->cend();
int idx1 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType2(), (*sCollisionTypeList)[i].GetInfo())) {
idx1 = i;
break;
}
}
if (idx0 < 0 || idx1 < 0 || idx0 >= sNumTypes || idx1 >= sNumTypes)
if (index1 >= sNumTypes || index2 >= sNumTypes || hasReachedEnd) {
return;
}
BooleanComparisonFunc& funcOut =
(idx0 == -1 || idx1 == -1) ? sNullBooleanCollider : (*sTableOfBooleanCollidables)[idx1 * sNumTypes + idx0];
hasReachedEnd ? sNullBooleanCollider : (*sTableOfBooleanCollidables)[index2 * sNumTypes + index1];
funcOut = cmp.GetCollider();
}
......@@ -205,28 +207,19 @@ void CCollisionPrimitive::InitAddBooleanCollider(BooleanComparisonFunc cmp, cons
InitAddBooleanCollider({cmp, a, b});
}
void CCollisionPrimitive::InitAddMovingCollider(const CCollisionPrimitive::MovingComparison& cmp) {
int idx0 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType1(), (*sCollisionTypeList)[i].GetInfo())) {
idx0 = i;
break;
}
}
int idx1 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType2(), (*sCollisionTypeList)[i].GetInfo())) {
idx1 = i;
break;
}
}
void CCollisionPrimitive::InitAddMovingCollider(const MovingComparison& cmp) {
const auto iter1 = FindCollisionType(cmp.GetType1());
const auto iter2 = FindCollisionType(cmp.GetType2());
const auto index1 = std::distance(sCollisionTypeList->cbegin(), iter1);
const auto index2 = std::distance(sCollisionTypeList->cbegin(), iter2);
const bool hasReachedEnd = iter1 == sCollisionTypeList->cend() || iter2 == sCollisionTypeList->cend();
if (idx0 < 0 || idx1 < 0 || idx0 >= sNumTypes || idx1 >= sNumTypes)
if (index1 >= sNumTypes || index2 >= sNumTypes || hasReachedEnd) {
return;
}
MovingComparisonFunc& funcOut =
(idx0 == -1 || idx1 == -1) ? sNullMovingCollider : (*sTableOfMovingCollidables)[idx1 * sNumTypes + idx0];
hasReachedEnd ? sNullMovingCollider : (*sTableOfMovingCollidables)[index2 * sNumTypes + index1];
funcOut = cmp.GetCollider();
}
......@@ -234,28 +227,18 @@ void CCollisionPrimitive::InitAddMovingCollider(MovingComparisonFunc cmp, const
InitAddMovingCollider({cmp, a, b});
}
void CCollisionPrimitive::InitAddCollider(const CCollisionPrimitive::Comparison& cmp) {
int idx0 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType1(), (*sCollisionTypeList)[i].GetInfo())) {
idx0 = i;
break;
}
}
void CCollisionPrimitive::InitAddCollider(const Comparison& cmp) {
const auto iter1 = FindCollisionType(cmp.GetType1());
const auto iter2 = FindCollisionType(cmp.GetType2());
const auto index1 = std::distance(sCollisionTypeList->cbegin(), iter1);
const auto index2 = std::distance(sCollisionTypeList->cbegin(), iter2);
const bool hasReachedEnd = iter1 == sCollisionTypeList->cend() || iter2 == sCollisionTypeList->cend();
int idx1 = -1;
for (int i = 0; i < sCollisionTypeList->size(); ++i) {
if (!strcmp(cmp.GetType2(), (*sCollisionTypeList)[i].GetInfo())) {
idx1 = i;
break;
}
}
if (idx0 < 0 || idx1 < 0 || idx0 >= sNumTypes || idx1 >= sNumTypes)
if (index1 >= sNumTypes || index2 >= sNumTypes || hasReachedEnd) {
return;
}
ComparisonFunc& funcOut =
(idx0 == -1 || idx1 == -1) ? sNullCollider : (*sTableOfCollidables)[idx1 * sNumTypes + idx0];
ComparisonFunc& funcOut = hasReachedEnd ? sNullCollider : (*sTableOfCollidables)[index2 * sNumTypes + index1];
funcOut = cmp.GetCollider();
}
......
......@@ -44,11 +44,12 @@ class COBBTree;
class CCollisionInfo;
class CCollisionInfoList;
class CInternalRayCastStructure;
typedef bool (*ComparisonFunc)(const CInternalCollisionStructure&, CCollisionInfoList&);
typedef bool (*MovingComparisonFunc)(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
typedef bool (*BooleanComparisonFunc)(const CInternalCollisionStructure&);
typedef void (*PrimitiveSetter)(u32);
using BooleanComparisonFunc = bool (*)(const CInternalCollisionStructure&);
using ComparisonFunc = bool (*)(const CInternalCollisionStructure&, CCollisionInfoList&);
using MovingComparisonFunc = bool (*)(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
using PrimitiveSetter = void (*)(u32);
class CCollisionPrimitive {
public:
......@@ -122,6 +123,10 @@ private:
static BooleanComparisonFunc sNullBooleanCollider;
static MovingComparisonFunc sNullMovingCollider;
// Attempts to locate an entry within the collision type list that matches the supplied name.
// Returns the end iterator in the event of no matches.
static std::vector<Type>::const_iterator FindCollisionType(const char* name);
static bool InternalCollide(const CInternalCollisionStructure& collision, CCollisionInfoList& list);
static bool InternalCollideBoolean(const CInternalCollisionStructure& collision);
static bool InternalCollideMoving(const CInternalCollisionStructure& collision, const zeus::CVector3f& dir,
......@@ -136,7 +141,7 @@ public:
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const = 0;
virtual zeus::CAABox CalculateLocalAABox() const = 0;
virtual FourCC GetPrimType() const = 0;
virtual ~CCollisionPrimitive() {}
virtual ~CCollisionPrimitive() = default;
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const = 0;
CRayCastResult CastRay(const zeus::CVector3f& start, const zeus::CVector3f& dir, float length,
const CMaterialFilter& filter, const zeus::CTransform& xf) const;
......
......@@ -14,38 +14,48 @@ CUVEAnimTexture::CUVEAnimTexture(TToken<CTexture>&& tex, std::unique_ptr<CIntEle
strideW->GetValue(0, x18_strideW);
strideH->GetValue(0, x1c_strideH);
int width = x4_tex.GetObj()->GetWidth();
int height = x4_tex.GetObj()->GetHeight();
float widthF = width;
float heightF = height;
int xTiles = std::max(1, width / x18_strideW);
int yTiles = std::max(1, height / x1c_strideH);
const int width = int(x4_tex.GetObj()->GetWidth());
const int height = int(x4_tex.GetObj()->GetHeight());
const float widthF = float(width);
const float heightF = float(height);
const int xTiles = std::max(1, width / x18_strideW);
const int yTiles = std::max(1, height / x1c_strideH);
x20_tiles = xTiles * yTiles;
x2c_uvElems.reserve(x20_tiles);
for (int y = yTiles - 1; y >= 0; --y) {
for (int x = 0; x < xTiles; ++x) {
int px = x18_strideW * x;
int px2 = px + x10_tileW;
int py = x1c_strideH * y;
int py2 = py + x14_tileH;
x2c_uvElems.push_back({px / widthF, py / heightF, px2 / widthF, py2 / heightF});
const int px = x18_strideW * x;
const int px2 = px + x10_tileW;
const int py = x1c_strideH * y;
const int py2 = py + x14_tileH;
x2c_uvElems.push_back({
float(px) / widthF,
float(py) / heightF,
float(px2) / widthF,
float(py2) / heightF,
});
}
}
}
void CUVEAnimTexture::GetValueUV(int frame, SUVElementSet& valOut) const {
int cv;
int cv = 1;
x28_cycleFrames->GetValue(frame, cv);
float cvf = cv / float(x20_tiles);
cvf = frame / cvf;
float cvf = float(cv) / float(x20_tiles);
cvf = float(frame) / cvf;
int tile = cvf;
int tile = int(cvf);
if (x24_loop) {
if (cvf >= x20_tiles)
if (cvf >= float(x20_tiles)) {
tile = int(cvf) % x20_tiles;
}
} else {
if (cvf >= x20_tiles)
if (cvf >= float(x20_tiles)) {
tile = x20_tiles - 1;
}
}
valOut = x2c_uvElems[tile];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment