mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Make GameScriptPosition and GameScriptRotation convertible from PHD_3POS and add a function which puts their position or rotation data into a PHD_3POS. Make their members public since their setters and getters were trivial, aside from some tests which seem to serve no purpose (an int can't be larger than INT_MAX or smaller than INT_MIN).
This commit is contained in:
parent
1a361ebfe7
commit
5f0b5f699f
4 changed files with 43 additions and 98 deletions
|
@ -1,59 +1,36 @@
|
|||
#include "framework.h"
|
||||
#include "GameScriptPosition.h"
|
||||
#include <sol.hpp>
|
||||
#include "phd_global.h"
|
||||
|
||||
void GameScriptPosition::Register(sol::state* state)
|
||||
{
|
||||
state->new_usertype<GameScriptPosition>("Position",
|
||||
sol::constructors<GameScriptPosition(int, int, int)>(),
|
||||
"X", sol::property(&GameScriptPosition::GetX, &GameScriptPosition::SetX),
|
||||
"Y", sol::property(&GameScriptPosition::GetY, &GameScriptPosition::SetY),
|
||||
"Z", sol::property(&GameScriptPosition::GetZ, &GameScriptPosition::SetZ)
|
||||
"X", &GameScriptPosition::x,
|
||||
"Y", &GameScriptPosition::y,
|
||||
"Z", &GameScriptPosition::z
|
||||
);
|
||||
}
|
||||
|
||||
GameScriptPosition::GameScriptPosition(int x, int y, int z)
|
||||
GameScriptPosition::GameScriptPosition(int aX, int aY, int aZ)
|
||||
{
|
||||
SetX(x);
|
||||
SetY(y);
|
||||
SetZ(z);
|
||||
x = aX;
|
||||
y = aY;
|
||||
z = aZ;
|
||||
}
|
||||
|
||||
int GameScriptPosition::GetX() const
|
||||
GameScriptPosition::GameScriptPosition(PHD_3DPOS const& pos)
|
||||
{
|
||||
return x;
|
||||
x = pos.xPos;
|
||||
y = pos.yPos;
|
||||
z = pos.zPos;
|
||||
}
|
||||
|
||||
void GameScriptPosition::SetX(int x)
|
||||
void GameScriptPosition::StoreInPHDPos(PHD_3DPOS& pos) const
|
||||
{
|
||||
if (x < INT_MIN || x > INT_MAX)
|
||||
return;
|
||||
else
|
||||
this->x = x;
|
||||
pos.xPos = x;
|
||||
pos.yPos = y;
|
||||
pos.zPos = z;
|
||||
}
|
||||
|
||||
int GameScriptPosition::GetY() const
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
void GameScriptPosition::SetY(int y)
|
||||
{
|
||||
if (y < INT_MIN || y > INT_MAX)
|
||||
return;
|
||||
else
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
int GameScriptPosition::GetZ() const
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
void GameScriptPosition::SetZ(int z)
|
||||
{
|
||||
if (z < INT_MIN || z > INT_MAX)
|
||||
return;
|
||||
else
|
||||
this->z = z;
|
||||
}
|
|
@ -5,21 +5,17 @@
|
|||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
struct PHD_3DPOS;
|
||||
|
||||
class GameScriptPosition {
|
||||
private:
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
public:
|
||||
GameScriptPosition(int x, int y, int z);
|
||||
GameScriptPosition(PHD_3DPOS const& pos);
|
||||
static void Register(sol::state*);
|
||||
|
||||
int GetX() const;
|
||||
void SetX(int x);
|
||||
int GetY() const;
|
||||
void SetY(int y);
|
||||
int GetZ() const;
|
||||
void SetZ(int z);
|
||||
void StoreInPHDPos(PHD_3DPOS& pos) const;
|
||||
};
|
|
@ -1,58 +1,35 @@
|
|||
#include "framework.h"
|
||||
#include "GameScriptRotation.h"
|
||||
#include "phd_global.h"
|
||||
|
||||
void GameScriptRotation::Register(sol::state* state)
|
||||
{
|
||||
state->new_usertype<GameScriptRotation>("Rotation",
|
||||
sol::constructors<GameScriptRotation(int, int, int)>(),
|
||||
"X", sol::property(&GameScriptRotation::GetX, &GameScriptRotation::SetX),
|
||||
"Y", sol::property(&GameScriptRotation::GetY, &GameScriptRotation::SetY),
|
||||
"Z", sol::property(&GameScriptRotation::GetZ, &GameScriptRotation::SetZ)
|
||||
"X", &GameScriptRotation::x,
|
||||
"Y", &GameScriptRotation::y,
|
||||
"Z", &GameScriptRotation::z
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
GameScriptRotation::GameScriptRotation(int x, int y, int z)
|
||||
GameScriptRotation::GameScriptRotation(int aX, int aY, int aZ)
|
||||
{
|
||||
SetX(x);
|
||||
SetY(y);
|
||||
SetZ(z);
|
||||
x = aX;
|
||||
y = aY;
|
||||
z = aZ;
|
||||
}
|
||||
|
||||
int GameScriptRotation::ConvertRotation(int a)
|
||||
void GameScriptRotation::StoreInPHDPos(PHD_3DPOS& pos) const
|
||||
{
|
||||
short component = std::clamp(a, -359, 359);
|
||||
component = static_cast<int>(lround((component/360.0f) * std::numeric_limits<unsigned short>::max()));
|
||||
component = component - std::numeric_limits<short>::max();
|
||||
return component;
|
||||
pos.xRot = x;
|
||||
pos.yRot = y;
|
||||
pos.zRot = z;
|
||||
}
|
||||
|
||||
int GameScriptRotation::GetX() const
|
||||
GameScriptRotation::GameScriptRotation(PHD_3DPOS const & pos)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
void GameScriptRotation::SetX(int x)
|
||||
{
|
||||
this->x = ConvertRotation(x);
|
||||
}
|
||||
|
||||
int GameScriptRotation::GetY() const
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
void GameScriptRotation::SetY(int y)
|
||||
{
|
||||
this->y = ConvertRotation(y);
|
||||
}
|
||||
|
||||
int GameScriptRotation::GetZ() const
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
void GameScriptRotation::SetZ(int z)
|
||||
{
|
||||
this->z = ConvertRotation(z);
|
||||
x = pos.xRot;
|
||||
y = pos.yRot;
|
||||
z = pos.zRot;
|
||||
}
|
|
@ -5,22 +5,17 @@
|
|||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
struct PHD_3DPOS;
|
||||
|
||||
class GameScriptRotation {
|
||||
private:
|
||||
public:
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
int ConvertRotation(int a);
|
||||
|
||||
public:
|
||||
GameScriptRotation(int x, int y, int z);
|
||||
static void Register(sol::state*);
|
||||
|
||||
int GetX() const;
|
||||
void SetX(int x);
|
||||
int GetY() const;
|
||||
void SetY(int y);
|
||||
int GetZ() const;
|
||||
void SetZ(int z);
|
||||
void StoreInPHDPos(PHD_3DPOS& pos) const;
|
||||
GameScriptRotation(PHD_3DPOS const& pos);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue