TWINE: renamed Vec3 to IVec3

This commit is contained in:
Martin Gerhardy 2021-03-17 00:17:51 +01:00
parent fcdba48458
commit 3a6923795d
20 changed files with 89 additions and 89 deletions

View file

@ -96,7 +96,7 @@ public:
* @param actorIdx
*/
void playSample(int32 index, int32 repeat = 1, int32 x = 128, int32 y = 128, int32 z = 128, int32 actorIdx = -1);
void playSample(int32 index, int32 repeat, const Vec3 &pos, int32 actorIdx = -1) {
void playSample(int32 index, int32 repeat, const IVec3 &pos, int32 actorIdx = -1) {
playSample(index, repeat, pos.x, pos.y, pos.z, actorIdx);
}

View file

@ -306,7 +306,7 @@ bool TwinEConsole::doListMenuText(int argc, const char **argv) {
}
bool TwinEConsole::doSetHeroPosition(int argc, const char **argv) {
Vec3 &pos = _engine->_scene->sceneHero->pos;
IVec3 &pos = _engine->_scene->sceneHero->pos;
if (argc < 4) {
debugPrintf("Current hero position: %i:%i:%i\n", pos.x, pos.y, pos.z);
return true;

View file

@ -41,7 +41,7 @@ void DebugScene::drawClip(const Common::Rect &rect) {
_engine->_menu->drawBox(rect);
}
void DebugScene::drawBoundingBoxProjectPoints(Vec3 *pPoint3d, Vec3 *pPoint3dProjected) {
void DebugScene::drawBoundingBoxProjectPoints(IVec3 *pPoint3d, IVec3 *pPoint3dProjected) {
_engine->_renderer->projectPositionOnScreen(pPoint3d->x, pPoint3d->y, pPoint3d->z);
pPoint3dProjected->x = _engine->_renderer->projPos.x;
@ -102,7 +102,7 @@ int32 DebugScene::checkZoneType(int32 type) const {
return 0;
}
DebugScene::ScenePositionsProjected DebugScene::calculateBoxPositions(const Vec3 &bottomLeft, const Vec3 &topRight) {
DebugScene::ScenePositionsProjected DebugScene::calculateBoxPositions(const IVec3 &bottomLeft, const IVec3 &topRight) {
ScenePositionsProjected positions;
// compute the points in 3D
positions.frontBottomLeftPoint.x = bottomLeft.x - _engine->_grid->camera.x;
@ -188,7 +188,7 @@ bool DebugScene::displayActors() {
if (!actorPtr->staticFlags.bIsSpriteActor) {
continue;
}
const Vec3 &pos = actorPtr->pos;
const IVec3 &pos = actorPtr->pos;
const BoundingBox &bbox = actorPtr->boudingBox;
const ScenePositionsProjected &positions = calculateBoxPositions(pos + bbox.mins, pos + bbox.maxs);
if (!drawBox(positions, COLOR_WHITE)) {

View file

@ -35,39 +35,39 @@ class DebugScene {
private:
TwinEEngine *_engine;
void drawBoundingBoxProjectPoints(Vec3 *point3d, Vec3 *point3dProjected);
void drawBoundingBoxProjectPoints(IVec3 *point3d, IVec3 *point3dProjected);
int32 checkZoneType(int32 type) const;
bool displayZones();
bool displayActors();
bool displayTracks();
struct ScenePositionsProjected {
Vec3 frontBottomLeftPoint;
Vec3 frontBottomRightPoint;
IVec3 frontBottomLeftPoint;
IVec3 frontBottomRightPoint;
Vec3 frontTopLeftPoint;
Vec3 frontTopRightPoint;
IVec3 frontTopLeftPoint;
IVec3 frontTopRightPoint;
Vec3 backBottomLeftPoint;
Vec3 backBottomRightPoint;
IVec3 backBottomLeftPoint;
IVec3 backBottomRightPoint;
Vec3 backTopLeftPoint;
Vec3 backTopRightPoint;
IVec3 backTopLeftPoint;
IVec3 backTopRightPoint;
Vec3 frontBottomLeftPoint2D;
Vec3 frontBottomRightPoint2D;
IVec3 frontBottomLeftPoint2D;
IVec3 frontBottomRightPoint2D;
Vec3 frontTopLeftPoint2D;
Vec3 frontTopRightPoint2D;
IVec3 frontTopLeftPoint2D;
IVec3 frontTopRightPoint2D;
Vec3 backBottomLeftPoint2D;
Vec3 backBottomRightPoint2D;
IVec3 backBottomLeftPoint2D;
IVec3 backBottomRightPoint2D;
Vec3 backTopLeftPoint2D;
Vec3 backTopRightPoint2D;
IVec3 backTopLeftPoint2D;
IVec3 backTopRightPoint2D;
};
ScenePositionsProjected calculateBoxPositions(const Vec3 &bottomLeft, const Vec3 &topRight);
ScenePositionsProjected calculateBoxPositions(const IVec3 &bottomLeft, const IVec3 &topRight);
bool drawBox(const ScenePositionsProjected &positions, uint8 color);
public:
DebugScene(TwinEEngine *engine);

View file

@ -126,7 +126,7 @@ void Holomap::prepareHolomapSurface() {
int rotation = 0;
for (int i = 0; i <= ANGLE_11_25; ++i, rotation += ANGLE_11_25) {
const int32 rotX = stream.readByte();
const Vec3& rotVec = _engine->_renderer->getHolomapRotation(rotX, angle, rotation);
const IVec3& rotVec = _engine->_renderer->getHolomapRotation(rotX, angle, rotation);
_holomapSurface[holomapSurfaceArrayIdx].x = rotVec.x;
_holomapSurface[holomapSurfaceArrayIdx].y = rotVec.y;
_holomapSurface[holomapSurfaceArrayIdx].z = rotVec.z;
@ -170,7 +170,7 @@ void Holomap::prepareHolomapPolygons() {
for (int32 angle = -ANGLE_90; angle <= ANGLE_90; angle += ANGLE_11_25) {
int rotation = 0;
for (int32 stepWidth = 0; stepWidth < ANGLE_11_25; ++stepWidth) {
Vec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
IVec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
_engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
if (angle != ANGLE_90) {
_holomapSort[holomapSortArrayIdx].z = _engine->_renderer->destPos.z;
@ -183,7 +183,7 @@ void Holomap::prepareHolomapPolygons() {
rotation += ANGLE_11_25;
++_projectedSurfaceIndex;
}
Vec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
IVec3* vec = &_holomapSurface[holomapSurfaceArrayIdx++];
_engine->_renderer->getBaseRotationPosition(vec->x, vec->y, vec->z);
_engine->_renderer->projectXYPositionOnScreen(_engine->_renderer->destPos);
_projectedSurfacePositions[_projectedSurfaceIndex].x = _engine->_renderer->projPos.x;

View file

@ -45,7 +45,7 @@ private:
bool isTriangleVisible(const Vertex *vertices) const;
struct Location {
Vec3 angle;
IVec3 angle;
uint16 textIndex = 0;
char name[30] = "";
};
@ -62,7 +62,7 @@ private:
HamalayiTransporter = 47
};
Vec3 _holomapSurface[561];
IVec3 _holomapSurface[561];
// original game size: 2244 (lba1)
struct HolomapSort {
@ -84,7 +84,7 @@ private:
int16 locationIdx = -1;
int16 trajLocationIdx = -1;
int16 vehicleIdx = -1;
Vec3 pos;
IVec3 pos;
int16 numAnimFrames = 0;
struct TrajectoryPos {
int16 x = 0;

View file

@ -211,7 +211,7 @@ void Renderer::setCameraAngle(int32 transPosX, int32 transPosY, int32 transPosZ,
baseTransPos = destPos;
}
Vec3 Renderer::getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const {
IVec3 Renderer::getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const {
int32 rotX;
int32 rotY;
int32 rotZ;
@ -238,7 +238,7 @@ Vec3 Renderer::getHolomapRotation(const int32 angleX, const int32 angleY, const
const int32 row3X = baseMatrix.row3[0] * rotX;
const int32 row3Y = baseMatrix.row3[1] * rotY;
const int32 row3Z = baseMatrix.row3[2] * rotZ;
Vec3 vec;
IVec3 vec;
vec.x = (row1X + row1Y + row1Z) / SCENE_SIZE_HALF;
vec.y = (row2X + row2Y + row2Z) / SCENE_SIZE_HALF;
vec.z = (row3X + row3Y + row3Z) / SCENE_SIZE_HALF;

View file

@ -66,7 +66,7 @@ struct Matrix {
int32 row3[3]{0, 0, 0};
};
inline Matrix operator*(const Matrix &matrix, const Vec3 &vec) {
inline Matrix operator*(const Matrix &matrix, const IVec3 &vec) {
Matrix out;
out.row1[0] = matrix.row1[0] * vec.x;
out.row1[1] = matrix.row1[1] * vec.x;
@ -330,7 +330,7 @@ private:
// ---- variables ----
Vec3 baseTransPos;
IVec3 baseTransPos;
int32 cameraDepthOffset = 0; // cameraVar1
int32 cameraScaleY = 0; // cameraVar2
@ -342,14 +342,14 @@ private:
int32 renderAngleY = 0; // _angleY
int32 renderAngleZ = 0; // _angleZ
Vec3 renderPos;
IVec3 renderPos;
// ---
Matrix baseMatrix;
Matrix matricesTable[30 + 1];
Matrix shadeMatrix;
Vec3 lightPos;
IVec3 lightPos;
RenderCommand _renderCmds[1000];
uint8 renderCoordinatesBuffer[10000]{0};
@ -398,12 +398,12 @@ public:
void init(int32 w, int32 h);
Vec3 projPosScreen;
Vec3 projPos;
Vec3 baseRotPos;
Vec3 orthoProjPos;
Vec3 destPos;
Vec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
IVec3 projPosScreen;
IVec3 projPos;
IVec3 baseRotPos;
IVec3 orthoProjPos;
IVec3 destPos;
IVec3 getHolomapRotation(const int32 angleX, const int32 angleY, const int32 angleZ) const;
void setLightVector(int32 angleX, int32 angleY, int32 angleZ);
void getBaseRotationPosition(int32 x, int32 y, int32 z);
@ -411,13 +411,13 @@ public:
static void prepareIsoModel(uint8 *bodyPtr);
void renderPolygons(const CmdRenderPolygon &polygon, Vertex *vertices);
inline int32 projectPositionOnScreen(const Vec3& pos) {
inline int32 projectPositionOnScreen(const IVec3& pos) {
return projectPositionOnScreen(pos.x, pos.y, pos.z);
}
int32 projectPositionOnScreen(int32 cX, int32 cY, int32 cZ);
inline void projectXYPositionOnScreen(const Vec3& pos) {
inline void projectXYPositionOnScreen(const IVec3& pos) {
projectXYPositionOnScreen(pos.x, pos.y, pos.z);
}
void projectXYPositionOnScreen(int32 x,int32 y,int32 z);

View file

@ -247,8 +247,8 @@ void Actor::initModelActor(BodyType bodyIdx, int16 actorIdx) {
localActor->entity = -1;
BoundingBox &bbox = localActor->boudingBox;
bbox.mins = Vec3();
bbox.maxs = Vec3();
bbox.mins = IVec3();
bbox.maxs = IVec3();
debug("Failed to initialize body %i for actor %i", (int)bodyIdx, actorIdx);
return;
}
@ -346,8 +346,8 @@ void Actor::resetActor(int16 actorIdx) {
actor->pos.z = 0;
BoundingBox &bbox = actor->boudingBox;
bbox.mins = Vec3();
bbox.maxs = Vec3();
bbox.mins = IVec3();
bbox.maxs = IVec3();
actor->angle = 0;
actor->speed = 40;

View file

@ -186,7 +186,7 @@ public:
bool isJumpAnimationActive() const;
int16 actorIdx = 0; // own actor index
Vec3 pos;
IVec3 pos;
int32 strengthOfHit = 0; // field_66
int32 hitBy = 0;
BonusParameter bonusParameter; // field_10
@ -208,7 +208,7 @@ public:
void setLife(int32 val);
Vec3 collisionPos;
IVec3 collisionPos;
int32 positionInMoveScript = 0;
uint8 *moveScript = nullptr;
@ -228,7 +228,7 @@ public:
int32 zone = 0;
int32 lastRotationAngle = ANGLE_0;
Vec3 lastPos;
IVec3 lastPos;
int32 previousAnimIdx = 0;
int32 doorStatus = 0;
int32 animPosition = 0;
@ -291,7 +291,7 @@ public:
ActorStruct *processActorPtr = nullptr;
/** Actor shadow coordinate */
Vec3 shadowCoord;
IVec3 shadowCoord;
/** Actor shadow collition type - brick shape */
ShapeType shadowCollisionType = ShapeType::kNone;

View file

@ -37,10 +37,10 @@ private:
public:
Collision(TwinEEngine *engine);
/** Actor collision coordinate */
Vec3 collision;
IVec3 collision;
/** Actor collision coordinate */
Vec3 processCollision;
IVec3 processCollision;
/** Cause damage in current processed actor */
int32 causeActorDamage = 0; //fieldCauseDamage

View file

@ -53,9 +53,9 @@ enum ExtraType {
struct ExtraListStruct {
int16 info0 = 0; /**< a value of -1 indicates that this instance is free to use */
Vec3 pos;
Vec3 lastPos;
Vec3 destPos;
IVec3 pos;
IVec3 lastPos;
IVec3 destPos;
ActorMoveStruct trackActorMove;

View file

@ -197,10 +197,10 @@ public:
const uint8 *getBlockBufferGround(int32 x, int32 y, int32 z, int32 &ground);
/** New grid camera x, y and z coordinates */
Vec3 newCamera;
IVec3 newCamera;
/** Current grid camera x, y and z coordinates */
Vec3 camera;
IVec3 camera;
/** Flag to know if the engine is using celling grids */
int16 useCellingGrid = 0; // useAnotherGrm

View file

@ -149,7 +149,7 @@ int32 Movements::getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) const {
return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (z2 - z1) * (z2 - z1)));
}
int32 Movements::getDistance2D(const Vec3 &v1, const Vec3 &v2) const {
int32 Movements::getDistance2D(const IVec3 &v1, const IVec3 &v2) const {
return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.z - v1.z) * (v2.z - v1.z)));
}
@ -157,7 +157,7 @@ int32 Movements::getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2,
return (int32)sqrt((float)((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1)));
}
int32 Movements::getDistance3D(const Vec3 &v1, const Vec3 &v2) const {
int32 Movements::getDistance3D(const IVec3 &v1, const IVec3 &v2) const {
return (int32)sqrt((float)((v2.x - v1.x) * (v2.x - v1.x) + (v2.y - v1.y) * (v2.y - v1.y) + (v2.z - v1.z) * (v2.z - v1.z)));
}

View file

@ -128,10 +128,10 @@ public:
bool heroMoved = false; // twinsenMove
/** Process actor coordinate */
Vec3 processActor;
IVec3 processActor;
/** Previous process actor coordinate */
Vec3 previousActor;
IVec3 previousActor;
int32 targetActorDistance = 0; // DoTrackVar1
@ -176,7 +176,7 @@ public:
*/
int32 getAngleAndSetTargetActorDistance(int32 x1, int32 z1, int32 x2, int32 z2);
inline int32 getAngleAndSetTargetActorDistance(const Vec3& v1, const Vec3 &v2) {
inline int32 getAngleAndSetTargetActorDistance(const IVec3& v1, const IVec3 &v2) {
return getAngleAndSetTargetActorDistance(v1.x, v1.z, v2.x, v2.z);
}
@ -196,7 +196,7 @@ public:
* @param z2 Actor 2 Z coordinate
*/
int32 getDistance2D(int32 x1, int32 z1, int32 x2, int32 z2) const;
int32 getDistance2D(const Vec3 &v1, const Vec3 &v2) const;
int32 getDistance2D(const IVec3 &v1, const IVec3 &v2) const;
/**
* Get distance value in 3D
@ -208,7 +208,7 @@ public:
* @param z2 Actor 2 Z coordinate
*/
int32 getDistance3D(int32 x1, int32 y1, int32 z1, int32 x2, int32 y2, int32 z2) const;
int32 getDistance3D(const Vec3 &v1, const Vec3 &v2) const;
int32 getDistance3D(const IVec3 &v1, const IVec3 &v2) const;
/**
* Move actor around the scene

View file

@ -262,7 +262,7 @@ bool Scene::loadSceneLBA2() {
sceneNumTracks = stream.readUint16LE();
for (int32 i = 0; i < sceneNumTracks; i++) {
Vec3 *point = &sceneTracks[i];
IVec3 *point = &sceneTracks[i];
point->x = stream.readSint32LE();
point->y = stream.readSint32LE();
point->z = stream.readSint32LE();
@ -387,7 +387,7 @@ bool Scene::loadSceneLBA1() {
sceneNumTracks = stream.readUint16LE();
for (int32 i = 0; i < sceneNumTracks; i++) {
Vec3 *point = &sceneTracks[i];
IVec3 *point = &sceneTracks[i];
point->x = stream.readUint16LE();
point->y = stream.readUint16LE();
point->z = stream.readUint16LE();

View file

@ -49,8 +49,8 @@ enum class ScenePositionType {
* Special actions, like change scene, climbing a ladder, ...
*/
struct ZoneStruct {
Vec3 mins;
Vec3 maxs;
IVec3 mins;
IVec3 maxs;
int16 type = 0;
int16 snap = 0;
union {
@ -293,8 +293,8 @@ private:
int16 _sceneMusic = 0;
Vec3 _sceneHeroPos;
Vec3 _zoneHeroPos;
IVec3 _sceneHeroPos;
IVec3 _zoneHeroPos;
int32 _currentGameOverScene = 0;
@ -317,7 +317,7 @@ public:
int32 alphaLight = ANGLE_0;
int32 betaLight = ANGLE_0;
Vec3 newHeroPos;
IVec3 newHeroPos;
/** Hero Y coordinate before fall */
int16 heroYBeforeFall = 0;
@ -345,7 +345,7 @@ public:
// TRACKS Tell the actor where to go
int32 sceneNumTracks = 0;
Vec3 sceneTracks[NUM_MAX_TRACKS];
IVec3 sceneTracks[NUM_MAX_TRACKS];
bool enableGridTileRendering = true;

View file

@ -1115,7 +1115,7 @@ static int32 lZOOM(TwinEEngine *engine, LifeScriptContext &ctx) {
static int32 lPOS_POINT(TwinEEngine *engine, LifeScriptContext &ctx) {
int32 trackIdx = ctx.stream.readByte();
const Vec3 &sp = engine->_scene->sceneTracks[trackIdx];
const IVec3 &sp = engine->_scene->sceneTracks[trackIdx];
engine->_renderer->destPos.x = sp.x;
engine->_renderer->destPos.y = sp.y;
engine->_renderer->destPos.z = sp.z;

View file

@ -116,7 +116,7 @@ static int32 mANIM(TwinEEngine *engine, MoveScriptContext &ctx) {
static int32 mGOTO_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
engine->_scene->currentScriptValue = ctx.stream.readByte();
const Vec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
const IVec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
engine->_renderer->destPos.x = sp.x;
engine->_renderer->destPos.y = sp.y;
engine->_renderer->destPos.z = sp.z;
@ -188,7 +188,7 @@ static int32 mANGLE(TwinEEngine *engine, MoveScriptContext &ctx) {
static int32 mPOS_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
engine->_scene->currentScriptValue = ctx.stream.readByte();
const Vec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
const IVec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
engine->_renderer->destPos.x = sp.x;
engine->_renderer->destPos.y = sp.y;
engine->_renderer->destPos.z = sp.z;
@ -248,7 +248,7 @@ static int32 mSTOP(TwinEEngine *engine, MoveScriptContext &ctx) {
static int32 mGOTO_SYM_POINT(TwinEEngine *engine, MoveScriptContext &ctx) {
engine->_scene->currentScriptValue = ctx.stream.readByte();
const Vec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
const IVec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
engine->_renderer->destPos.x = sp.x;
engine->_renderer->destPos.y = sp.y;
engine->_renderer->destPos.z = sp.z;
@ -321,7 +321,7 @@ static int32 mGOTO_POINT_3D(TwinEEngine *engine, MoveScriptContext &ctx) {
engine->_scene->currentScriptValue = trackId;
const Vec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
const IVec3 &sp = engine->_scene->sceneTracks[engine->_scene->currentScriptValue];
engine->_renderer->destPos.x = sp.x;
engine->_renderer->destPos.y = sp.y;
engine->_renderer->destPos.z = sp.z;

View file

@ -74,21 +74,21 @@
namespace TwinE {
struct Vec3 {
Vec3() : x(0), y(0), z(0) {}
Vec3(int32 _x, int32 _y, int32 _z) : x(_x), y(_y), z(_z) {}
struct IVec3 {
IVec3() : x(0), y(0), z(0) {}
IVec3(int32 _x, int32 _y, int32 _z) : x(_x), y(_y), z(_z) {}
int32 x;
int32 y;
int32 z;
inline Vec3& operator+=(const Vec3 &other) {
inline IVec3& operator+=(const IVec3 &other) {
x += other.x;
y += other.y;
z += other.z;
return *this;
}
inline Vec3& operator-=(const Vec3 &other) {
inline IVec3& operator-=(const IVec3 &other) {
x -= other.x;
y -= other.y;
z -= other.z;
@ -96,17 +96,17 @@ struct Vec3 {
}
};
inline Vec3 operator+(const Vec3 &lhs, const Vec3 &rhs) {
return Vec3{lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};
inline IVec3 operator+(const IVec3 &lhs, const IVec3 &rhs) {
return IVec3{lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};
}
inline Vec3 operator-(const Vec3 &lhs, const Vec3 &rhs) {
return Vec3{lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
inline IVec3 operator-(const IVec3 &lhs, const IVec3 &rhs) {
return IVec3{lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
}
struct BoundingBox {
Vec3 mins;
Vec3 maxs;
IVec3 mins;
IVec3 maxs;
};
struct ActorBoundingBox {