Skip to content

Commit f87acdb

Browse files
committed
Clean up client Vector/Matrix luadefs
1 parent 8b74e3f commit f87acdb

File tree

10 files changed

+186
-199
lines changed

10 files changed

+186
-199
lines changed

MTA10/mods/shared_logic/lua/CLuaMain.cpp

Lines changed: 4 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,184 +1654,14 @@ void CLuaMain::AddBrowserClass ( lua_State* luaVM )
16541654
}
16551655

16561656

1657-
void CLuaMain::AddVector4DClass ( lua_State* luaVM )
1658-
{
1659-
lua_newclass ( luaVM );
1660-
1661-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector4Defs::ToString );
1662-
lua_classmetamethod ( luaVM, "__gc", CLuaVector4Defs::Destroy );
1663-
1664-
lua_classmetamethod ( luaVM, "__add", CLuaVector4Defs::Add );
1665-
lua_classmetamethod ( luaVM, "__sub", CLuaVector4Defs::Sub );
1666-
lua_classmetamethod ( luaVM, "__mul", CLuaVector4Defs::Mul );
1667-
lua_classmetamethod ( luaVM, "__div", CLuaVector4Defs::Div );
1668-
lua_classmetamethod ( luaVM, "__pow", CLuaVector4Defs::Pow );
1669-
lua_classmetamethod ( luaVM, "__unm", CLuaVector4Defs::Unm );
1670-
lua_classmetamethod ( luaVM, "__eq", CLuaVector4Defs::Eq );
1671-
lua_classmetamethod ( luaVM, "__len", CLuaVector4Defs::GetLength );
1672-
1673-
lua_classfunction ( luaVM, "create", CLuaVector4Defs::Create );
1674-
lua_classfunction ( luaVM, "normalize", CLuaVector4Defs::Normalize );
1675-
lua_classfunction ( luaVM, "dot", CLuaVector4Defs::Dot );
1676-
1677-
lua_classfunction ( luaVM, "getLength", CLuaVector4Defs::GetLength );
1678-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector4Defs::GetLengthSquared );
1679-
lua_classfunction ( luaVM, "getNormalized", CLuaVector4Defs::GetNormalized );
1680-
lua_classfunction ( luaVM, "getX", CLuaVector4Defs::GetX );
1681-
lua_classfunction ( luaVM, "getY", CLuaVector4Defs::GetY );
1682-
lua_classfunction ( luaVM, "getZ", CLuaVector4Defs::GetZ );
1683-
lua_classfunction ( luaVM, "getW", CLuaVector4Defs::GetW );
1684-
1685-
lua_classfunction ( luaVM, "setX", CLuaVector4Defs::SetX );
1686-
lua_classfunction ( luaVM, "setY", CLuaVector4Defs::SetY );
1687-
lua_classfunction ( luaVM, "setZ", CLuaVector4Defs::SetZ );
1688-
lua_classfunction ( luaVM, "setW", CLuaVector4Defs::SetW );
1689-
1690-
lua_classvariable ( luaVM, "x", CLuaVector4Defs::SetX, CLuaVector4Defs::GetX );
1691-
lua_classvariable ( luaVM, "y", CLuaVector4Defs::SetY, CLuaVector4Defs::GetY );
1692-
lua_classvariable ( luaVM, "z", CLuaVector4Defs::SetZ, CLuaVector4Defs::GetZ );
1693-
lua_classvariable ( luaVM, "w", CLuaVector4Defs::SetW, CLuaVector4Defs::GetW );
1694-
1695-
lua_classvariable ( luaVM, "length", NULL, CLuaVector4Defs::GetLength );
1696-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector4Defs::GetLengthSquared );
1697-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector4Defs::GetNormalized );
1698-
1699-
lua_registerclass ( luaVM, "Vector4" );
1700-
}
1701-
1702-
1703-
void CLuaMain::AddVector3DClass ( lua_State* luaVM )
1704-
{
1705-
lua_newclass ( luaVM );
1706-
1707-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector3Defs::ToString );
1708-
lua_classmetamethod ( luaVM, "__gc", CLuaVector3Defs::Destroy );
1709-
1710-
lua_classmetamethod ( luaVM, "__add", CLuaVector3Defs::Add );
1711-
lua_classmetamethod ( luaVM, "__sub", CLuaVector3Defs::Sub );
1712-
lua_classmetamethod ( luaVM, "__mul", CLuaVector3Defs::Mul );
1713-
lua_classmetamethod ( luaVM, "__div", CLuaVector3Defs::Div );
1714-
lua_classmetamethod ( luaVM, "__pow", CLuaVector3Defs::Pow );
1715-
lua_classmetamethod ( luaVM, "__unm", CLuaVector3Defs::Unm );
1716-
lua_classmetamethod ( luaVM, "__eq", CLuaVector3Defs::Eq );
1717-
lua_classmetamethod ( luaVM, "__len", CLuaVector3Defs::GetLength );
1718-
1719-
lua_classfunction ( luaVM, "create", CLuaVector3Defs::Create );
1720-
lua_classfunction ( luaVM, "normalize", CLuaVector3Defs::Normalize );
1721-
lua_classfunction ( luaVM, "cross", CLuaVector3Defs::Cross );
1722-
lua_classfunction ( luaVM, "dot", CLuaVector3Defs::Dot );
1723-
1724-
lua_classfunction ( luaVM, "getLength", CLuaVector3Defs::GetLength );
1725-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector3Defs::GetLengthSquared );
1726-
lua_classfunction ( luaVM, "getNormalized", CLuaVector3Defs::GetNormalized );
1727-
lua_classfunction ( luaVM, "getX", CLuaVector3Defs::GetX );
1728-
lua_classfunction ( luaVM, "getY", CLuaVector3Defs::GetY );
1729-
lua_classfunction ( luaVM, "getZ", CLuaVector3Defs::GetZ );
1730-
1731-
lua_classfunction ( luaVM, "setX", CLuaVector3Defs::SetX );
1732-
lua_classfunction ( luaVM, "setY", CLuaVector3Defs::SetY );
1733-
lua_classfunction ( luaVM, "setZ", CLuaVector3Defs::SetZ );
1734-
1735-
lua_classvariable ( luaVM, "x", CLuaVector3Defs::SetX, CLuaVector3Defs::GetX );
1736-
lua_classvariable ( luaVM, "y", CLuaVector3Defs::SetY, CLuaVector3Defs::GetY );
1737-
lua_classvariable ( luaVM, "z", CLuaVector3Defs::SetZ, CLuaVector3Defs::GetZ );
1738-
lua_classvariable ( luaVM, "length", NULL, CLuaVector3Defs::GetLength );
1739-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector3Defs::GetLengthSquared );
1740-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector3Defs::GetNormalized );
1741-
1742-
lua_registerclass ( luaVM, "Vector3" );
1743-
}
1744-
1745-
1746-
void CLuaMain::AddVector2DClass ( lua_State* luaVM )
1747-
{
1748-
lua_newclass ( luaVM );
1749-
1750-
1751-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector2Defs::ToString );
1752-
lua_classmetamethod ( luaVM, "__gc", CLuaVector2Defs::Destroy );
1753-
1754-
lua_classmetamethod ( luaVM, "__add", CLuaVector2Defs::Add );
1755-
lua_classmetamethod ( luaVM, "__sub", CLuaVector2Defs::Sub );
1756-
lua_classmetamethod ( luaVM, "__mul", CLuaVector2Defs::Mul );
1757-
lua_classmetamethod ( luaVM, "__div", CLuaVector2Defs::Div );
1758-
lua_classmetamethod ( luaVM, "__pow", CLuaVector2Defs::Pow );
1759-
lua_classmetamethod ( luaVM, "__unm", CLuaVector2Defs::Unm );
1760-
lua_classmetamethod ( luaVM, "__eq", CLuaVector2Defs::Eq );
1761-
lua_classmetamethod ( luaVM, "__len", CLuaVector2Defs::GetLength );
1762-
1763-
lua_classfunction ( luaVM, "create", CLuaVector2Defs::Create );
1764-
lua_classfunction ( luaVM, "normalize", CLuaVector2Defs::Normalize );
1765-
lua_classfunction ( luaVM, "dot", CLuaVector2Defs::Dot );
1766-
1767-
lua_classfunction ( luaVM, "getLength", CLuaVector2Defs::GetLength );
1768-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector2Defs::GetLengthSquared );
1769-
lua_classfunction ( luaVM, "getNormalized", CLuaVector2Defs::GetNormalized );
1770-
lua_classfunction ( luaVM, "getX", CLuaVector2Defs::GetX );
1771-
lua_classfunction ( luaVM, "getY", CLuaVector2Defs::GetY );
1772-
1773-
lua_classfunction ( luaVM, "setX", CLuaVector2Defs::SetX );
1774-
lua_classfunction ( luaVM, "setY", CLuaVector2Defs::SetY );
1775-
1776-
lua_classvariable ( luaVM, "x", CLuaVector2Defs::SetX, CLuaVector2Defs::GetX );
1777-
lua_classvariable ( luaVM, "y", CLuaVector2Defs::SetY, CLuaVector2Defs::GetY );
1778-
1779-
lua_classvariable ( luaVM, "length", NULL, CLuaVector2Defs::GetLength );
1780-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector2Defs::GetLengthSquared );
1781-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector2Defs::GetNormalized );
1782-
1783-
lua_registerclass ( luaVM, "Vector2" );
1784-
}
1785-
1786-
1787-
void CLuaMain::AddMatrixClass ( lua_State* luaVM )
1788-
{
1789-
lua_newclass ( luaVM );
1790-
1791-
lua_classmetamethod ( luaVM, "__tostring", CLuaMatrixDefs::ToString );
1792-
lua_classmetamethod ( luaVM, "__gc", CLuaMatrixDefs::Destroy );
1793-
1794-
lua_classmetamethod ( luaVM, "__add", CLuaMatrixDefs::Add );
1795-
lua_classmetamethod ( luaVM, "__sub", CLuaMatrixDefs::Sub );
1796-
lua_classmetamethod ( luaVM, "__mul", CLuaMatrixDefs::Mul );
1797-
lua_classmetamethod ( luaVM, "__div", CLuaMatrixDefs::Div );
1798-
1799-
lua_classfunction ( luaVM, "create", CLuaMatrixDefs::Create );
1800-
1801-
lua_classfunction ( luaVM, "transformPosition", CLuaMatrixDefs::TransformPosition );
1802-
lua_classfunction ( luaVM, "transformDirection", CLuaMatrixDefs::TransformDirection );
1803-
lua_classfunction ( luaVM, "inverse", CLuaMatrixDefs::Inverse );
1804-
1805-
lua_classfunction ( luaVM, "getPosition", CLuaMatrixDefs::GetPosition );
1806-
lua_classfunction ( luaVM, "getRotation", CLuaMatrixDefs::GetRotation );
1807-
lua_classfunction ( luaVM, "getForward", CLuaMatrixDefs::GetForward );
1808-
lua_classfunction ( luaVM, "getRight", CLuaMatrixDefs::GetRight );
1809-
lua_classfunction ( luaVM, "getUp", CLuaMatrixDefs::GetUp );
1810-
1811-
lua_classfunction ( luaVM, "setPosition", CLuaMatrixDefs::SetPosition );
1812-
lua_classfunction ( luaVM, "setRotation", CLuaMatrixDefs::SetRotation );
1813-
lua_classfunction ( luaVM, "setForward", CLuaMatrixDefs::SetForward );
1814-
lua_classfunction ( luaVM, "setRight", CLuaMatrixDefs::SetRight );
1815-
lua_classfunction ( luaVM, "setUp", CLuaMatrixDefs::SetUp );
1816-
1817-
lua_classvariable ( luaVM, "position", CLuaMatrixDefs::SetPosition, CLuaMatrixDefs::GetPosition );
1818-
lua_classvariable ( luaVM, "rotation", CLuaMatrixDefs::SetRotation, CLuaMatrixDefs::GetRotation );
1819-
lua_classvariable ( luaVM, "forward", CLuaMatrixDefs::SetForward, CLuaMatrixDefs::GetForward );
1820-
lua_classvariable ( luaVM, "right", CLuaMatrixDefs::SetRight, CLuaMatrixDefs::GetRight );
1821-
lua_classvariable ( luaVM, "up", CLuaMatrixDefs::SetUp, CLuaMatrixDefs::GetUp );
1822-
1823-
lua_registerclass ( luaVM, "Matrix" );
1824-
}
1825-
1826-
18271657
void CLuaMain::InitClasses ( lua_State* luaVM )
18281658
{
18291659
lua_initclasses ( luaVM );
18301660

1831-
AddVector4DClass ( luaVM );
1832-
AddVector3DClass ( luaVM );
1833-
AddVector2DClass ( luaVM );
1834-
AddMatrixClass ( luaVM );
1661+
CLuaVector4Defs::AddClass ( luaVM );
1662+
CLuaVector3Defs::AddClass ( luaVM );
1663+
CLuaVector2Defs::AddClass ( luaVM );
1664+
CLuaMatrixDefs::AddClass ( luaVM );
18351665

18361666
if ( !m_bEnableOOP )
18371667
return;

MTA10/mods/shared_logic/lua/CLuaMain.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ class CLuaMain //: public CClient
124124

125125
void AddCameraClass ( lua_State* luaVM );
126126

127-
void AddVector4DClass ( lua_State* luaVM );
128-
void AddVector3DClass ( lua_State* luaVM );
129-
void AddVector2DClass ( lua_State* luaVM );
130-
void AddMatrixClass ( lua_State* luaVM );
131-
132127
void AddDxMaterialClass ( lua_State* luaVM );
133128
void AddDxTextureClass ( lua_State* luaVM );
134129
void AddDxFontClass ( lua_State* luaVM );

MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@
1212

1313
#include "StdInc.h"
1414

15+
void CLuaMatrixDefs::AddClass ( lua_State* luaVM )
16+
{
17+
lua_newclass ( luaVM );
18+
19+
lua_classmetamethod ( luaVM, "__tostring", ToString );
20+
lua_classmetamethod ( luaVM, "__gc", Destroy );
21+
22+
lua_classmetamethod ( luaVM, "__add", Add );
23+
lua_classmetamethod ( luaVM, "__sub", Sub );
24+
lua_classmetamethod ( luaVM, "__mul", Mul );
25+
lua_classmetamethod ( luaVM, "__div", Div );
26+
27+
lua_classfunction ( luaVM, "create", Create );
28+
29+
lua_classfunction ( luaVM, "transformPosition", TransformPosition );
30+
lua_classfunction ( luaVM, "transformDirection", TransformDirection );
31+
lua_classfunction ( luaVM, "inverse", Inverse );
32+
33+
lua_classfunction ( luaVM, "getPosition", GetPosition );
34+
lua_classfunction ( luaVM, "getRotation", GetRotation );
35+
lua_classfunction ( luaVM, "getForward", GetForward );
36+
lua_classfunction ( luaVM, "getRight", GetRight );
37+
lua_classfunction ( luaVM, "getUp", GetUp );
38+
39+
lua_classfunction ( luaVM, "setPosition", SetPosition );
40+
lua_classfunction ( luaVM, "setRotation", SetRotation );
41+
lua_classfunction ( luaVM, "setForward", SetForward );
42+
lua_classfunction ( luaVM, "setRight", SetRight );
43+
lua_classfunction ( luaVM, "setUp", SetUp );
44+
45+
lua_classvariable ( luaVM, "position", SetPosition, GetPosition );
46+
lua_classvariable ( luaVM, "rotation", SetRotation, GetRotation );
47+
lua_classvariable ( luaVM, "forward", SetForward, GetForward );
48+
lua_classvariable ( luaVM, "right", SetRight, GetRight );
49+
lua_classvariable ( luaVM, "up", SetUp, GetUp );
50+
51+
lua_registerclass ( luaVM, "Matrix" );
52+
}
53+
54+
1555
int CLuaMatrixDefs::Create ( lua_State* luaVM )
1656
{
1757
CMatrix matrix;

MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*
1111
*****************************************************************************/
1212

13-
#ifndef __CLUAMATRIXDEFS_H
14-
#define __CLUAMATRIXDEFS_H
13+
#pragma once
1514

1615
extern "C"
1716
{
@@ -23,6 +22,7 @@ extern "C"
2322
class CLuaMatrixDefs: public CLuaDefs
2423
{
2524
public:
25+
static void AddClass ( lua_State* luaVM );
2626
LUA_DECLARE ( Create );
2727
LUA_DECLARE ( Destroy );
2828

@@ -48,6 +48,4 @@ class CLuaMatrixDefs: public CLuaDefs
4848
LUA_DECLARE ( Sub );
4949
LUA_DECLARE ( Mul );
5050
LUA_DECLARE ( Div );
51-
};
52-
53-
#endif
51+
};

MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,47 @@
1212

1313
#include "StdInc.h"
1414

15+
void CLuaVector2Defs::AddClass ( lua_State* luaVM )
16+
{
17+
lua_newclass ( luaVM );
18+
19+
20+
lua_classmetamethod ( luaVM, "__tostring", ToString );
21+
lua_classmetamethod ( luaVM, "__gc", Destroy );
22+
23+
lua_classmetamethod ( luaVM, "__add", Add );
24+
lua_classmetamethod ( luaVM, "__sub", Sub );
25+
lua_classmetamethod ( luaVM, "__mul", Mul );
26+
lua_classmetamethod ( luaVM, "__div", Div );
27+
lua_classmetamethod ( luaVM, "__pow", Pow );
28+
lua_classmetamethod ( luaVM, "__unm", Unm );
29+
lua_classmetamethod ( luaVM, "__eq", Eq );
30+
lua_classmetamethod ( luaVM, "__len", GetLength );
31+
32+
lua_classfunction ( luaVM, "create", Create );
33+
lua_classfunction ( luaVM, "normalize", Normalize );
34+
lua_classfunction ( luaVM, "dot", Dot );
35+
36+
lua_classfunction ( luaVM, "getLength", GetLength );
37+
lua_classfunction ( luaVM, "getSquaredLength", GetLengthSquared );
38+
lua_classfunction ( luaVM, "getNormalized", GetNormalized );
39+
lua_classfunction ( luaVM, "getX", GetX );
40+
lua_classfunction ( luaVM, "getY", GetY );
41+
42+
lua_classfunction ( luaVM, "setX", SetX );
43+
lua_classfunction ( luaVM, "setY", SetY );
44+
45+
lua_classvariable ( luaVM, "x", SetX, GetX );
46+
lua_classvariable ( luaVM, "y", SetY, GetY );
47+
48+
lua_classvariable ( luaVM, "length", NULL, GetLength );
49+
lua_classvariable ( luaVM, "squaredLength", NULL, GetLengthSquared );
50+
lua_classvariable ( luaVM, "normalized", NULL, GetNormalized );
51+
52+
lua_registerclass ( luaVM, "Vector2" );
53+
}
54+
55+
1556
int CLuaVector2Defs::Create ( lua_State* luaVM )
1657
{
1758
CVector2D vector;

MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*
1111
*****************************************************************************/
1212

13-
#ifndef __LUAVECTORDEFS_H
14-
#define __LUAVECTORDEFS_H
13+
#pragma once
1514

1615
extern "C"
1716
{
@@ -23,6 +22,7 @@ extern "C"
2322
class CLuaVector2Defs : public CLuaDefs
2423
{
2524
public:
25+
static void AddClass ( lua_State* luaVM );
2626
LUA_DECLARE ( Create );
2727
LUA_DECLARE ( Destroy );
2828

@@ -47,6 +47,4 @@ class CLuaVector2Defs : public CLuaDefs
4747
LUA_DECLARE ( Pow );
4848
LUA_DECLARE ( Unm );
4949
LUA_DECLARE ( Eq );
50-
};
51-
52-
#endif
50+
};

0 commit comments

Comments
 (0)