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 "framework.h"
|
||||||
#include "GameScriptPosition.h"
|
#include "GameScriptPosition.h"
|
||||||
#include <sol.hpp>
|
#include <sol.hpp>
|
||||||
|
#include "phd_global.h"
|
||||||
|
|
||||||
void GameScriptPosition::Register(sol::state* state)
|
void GameScriptPosition::Register(sol::state* state)
|
||||||
{
|
{
|
||||||
state->new_usertype<GameScriptPosition>("Position",
|
state->new_usertype<GameScriptPosition>("Position",
|
||||||
sol::constructors<GameScriptPosition(int, int, int)>(),
|
sol::constructors<GameScriptPosition(int, int, int)>(),
|
||||||
"X", sol::property(&GameScriptPosition::GetX, &GameScriptPosition::SetX),
|
"X", &GameScriptPosition::x,
|
||||||
"Y", sol::property(&GameScriptPosition::GetY, &GameScriptPosition::SetY),
|
"Y", &GameScriptPosition::y,
|
||||||
"Z", sol::property(&GameScriptPosition::GetZ, &GameScriptPosition::SetZ)
|
"Z", &GameScriptPosition::z
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameScriptPosition::GameScriptPosition(int x, int y, int z)
|
GameScriptPosition::GameScriptPosition(int aX, int aY, int aZ)
|
||||||
{
|
{
|
||||||
SetX(x);
|
x = aX;
|
||||||
SetY(y);
|
y = aY;
|
||||||
SetZ(z);
|
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)
|
pos.xPos = x;
|
||||||
return;
|
pos.yPos = y;
|
||||||
else
|
pos.zPos = z;
|
||||||
this->x = x;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
namespace sol {
|
||||||
class state;
|
class state;
|
||||||
}
|
}
|
||||||
|
struct PHD_3DPOS;
|
||||||
|
|
||||||
class GameScriptPosition {
|
class GameScriptPosition {
|
||||||
private:
|
public:
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameScriptPosition(int x, int y, int z);
|
GameScriptPosition(int x, int y, int z);
|
||||||
|
GameScriptPosition(PHD_3DPOS const& pos);
|
||||||
static void Register(sol::state*);
|
static void Register(sol::state*);
|
||||||
|
void StoreInPHDPos(PHD_3DPOS& pos) const;
|
||||||
int GetX() const;
|
|
||||||
void SetX(int x);
|
|
||||||
int GetY() const;
|
|
||||||
void SetY(int y);
|
|
||||||
int GetZ() const;
|
|
||||||
void SetZ(int z);
|
|
||||||
};
|
};
|
|
@ -1,58 +1,35 @@
|
||||||
#include "framework.h"
|
#include "framework.h"
|
||||||
#include "GameScriptRotation.h"
|
#include "GameScriptRotation.h"
|
||||||
|
#include "phd_global.h"
|
||||||
|
|
||||||
void GameScriptRotation::Register(sol::state* state)
|
void GameScriptRotation::Register(sol::state* state)
|
||||||
{
|
{
|
||||||
state->new_usertype<GameScriptRotation>("Rotation",
|
state->new_usertype<GameScriptRotation>("Rotation",
|
||||||
sol::constructors<GameScriptRotation(int, int, int)>(),
|
sol::constructors<GameScriptRotation(int, int, int)>(),
|
||||||
"X", sol::property(&GameScriptRotation::GetX, &GameScriptRotation::SetX),
|
"X", &GameScriptRotation::x,
|
||||||
"Y", sol::property(&GameScriptRotation::GetY, &GameScriptRotation::SetY),
|
"Y", &GameScriptRotation::y,
|
||||||
"Z", sol::property(&GameScriptRotation::GetZ, &GameScriptRotation::SetZ)
|
"Z", &GameScriptRotation::z
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GameScriptRotation::GameScriptRotation(int x, int y, int z)
|
GameScriptRotation::GameScriptRotation(int aX, int aY, int aZ)
|
||||||
{
|
{
|
||||||
SetX(x);
|
x = aX;
|
||||||
SetY(y);
|
y = aY;
|
||||||
SetZ(z);
|
z = aZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameScriptRotation::ConvertRotation(int a)
|
void GameScriptRotation::StoreInPHDPos(PHD_3DPOS& pos) const
|
||||||
{
|
{
|
||||||
short component = std::clamp(a, -359, 359);
|
pos.xRot = x;
|
||||||
component = static_cast<int>(lround((component/360.0f) * std::numeric_limits<unsigned short>::max()));
|
pos.yRot = y;
|
||||||
component = component - std::numeric_limits<short>::max();
|
pos.zRot = z;
|
||||||
return component;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GameScriptRotation::GetX() const
|
GameScriptRotation::GameScriptRotation(PHD_3DPOS const & pos)
|
||||||
{
|
{
|
||||||
return x;
|
x = pos.xRot;
|
||||||
}
|
y = pos.yRot;
|
||||||
|
z = pos.zRot;
|
||||||
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);
|
|
||||||
}
|
}
|
|
@ -5,22 +5,17 @@
|
||||||
namespace sol {
|
namespace sol {
|
||||||
class state;
|
class state;
|
||||||
}
|
}
|
||||||
|
struct PHD_3DPOS;
|
||||||
|
|
||||||
class GameScriptRotation {
|
class GameScriptRotation {
|
||||||
private:
|
public:
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int z;
|
int z;
|
||||||
int ConvertRotation(int a);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameScriptRotation(int x, int y, int z);
|
GameScriptRotation(int x, int y, int z);
|
||||||
static void Register(sol::state*);
|
static void Register(sol::state*);
|
||||||
|
void StoreInPHDPos(PHD_3DPOS& pos) const;
|
||||||
int GetX() const;
|
GameScriptRotation(PHD_3DPOS const& pos);
|
||||||
void SetX(int x);
|
|
||||||
int GetY() const;
|
|
||||||
void SetY(int y);
|
|
||||||
int GetZ() const;
|
|
||||||
void SetZ(int z);
|
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue