Skip to content

Commit

Permalink
Clean up client Vector/Matrix luadefs
Browse files Browse the repository at this point in the history
  • Loading branch information
qaisjp committed Jan 23, 2016
1 parent 8b74e3f commit f87acdb
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 199 deletions.
178 changes: 4 additions & 174 deletions MTA10/mods/shared_logic/lua/CLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,184 +1654,14 @@ void CLuaMain::AddBrowserClass ( lua_State* luaVM )
}


void CLuaMain::AddVector4DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaVector4Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector4Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector4Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector4Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector4Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector4Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector4Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector4Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector4Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector4Defs::GetLength );

lua_classfunction ( luaVM, "create", CLuaVector4Defs::Create );
lua_classfunction ( luaVM, "normalize", CLuaVector4Defs::Normalize );
lua_classfunction ( luaVM, "dot", CLuaVector4Defs::Dot );

lua_classfunction ( luaVM, "getLength", CLuaVector4Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector4Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", CLuaVector4Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", CLuaVector4Defs::GetX );
lua_classfunction ( luaVM, "getY", CLuaVector4Defs::GetY );
lua_classfunction ( luaVM, "getZ", CLuaVector4Defs::GetZ );
lua_classfunction ( luaVM, "getW", CLuaVector4Defs::GetW );

lua_classfunction ( luaVM, "setX", CLuaVector4Defs::SetX );
lua_classfunction ( luaVM, "setY", CLuaVector4Defs::SetY );
lua_classfunction ( luaVM, "setZ", CLuaVector4Defs::SetZ );
lua_classfunction ( luaVM, "setW", CLuaVector4Defs::SetW );

lua_classvariable ( luaVM, "x", CLuaVector4Defs::SetX, CLuaVector4Defs::GetX );
lua_classvariable ( luaVM, "y", CLuaVector4Defs::SetY, CLuaVector4Defs::GetY );
lua_classvariable ( luaVM, "z", CLuaVector4Defs::SetZ, CLuaVector4Defs::GetZ );
lua_classvariable ( luaVM, "w", CLuaVector4Defs::SetW, CLuaVector4Defs::GetW );

lua_classvariable ( luaVM, "length", NULL, CLuaVector4Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector4Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector4Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector4" );
}


void CLuaMain::AddVector3DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaVector3Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector3Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector3Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector3Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector3Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector3Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector3Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector3Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector3Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector3Defs::GetLength );

lua_classfunction ( luaVM, "create", CLuaVector3Defs::Create );
lua_classfunction ( luaVM, "normalize", CLuaVector3Defs::Normalize );
lua_classfunction ( luaVM, "cross", CLuaVector3Defs::Cross );
lua_classfunction ( luaVM, "dot", CLuaVector3Defs::Dot );

lua_classfunction ( luaVM, "getLength", CLuaVector3Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector3Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", CLuaVector3Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", CLuaVector3Defs::GetX );
lua_classfunction ( luaVM, "getY", CLuaVector3Defs::GetY );
lua_classfunction ( luaVM, "getZ", CLuaVector3Defs::GetZ );

lua_classfunction ( luaVM, "setX", CLuaVector3Defs::SetX );
lua_classfunction ( luaVM, "setY", CLuaVector3Defs::SetY );
lua_classfunction ( luaVM, "setZ", CLuaVector3Defs::SetZ );

lua_classvariable ( luaVM, "x", CLuaVector3Defs::SetX, CLuaVector3Defs::GetX );
lua_classvariable ( luaVM, "y", CLuaVector3Defs::SetY, CLuaVector3Defs::GetY );
lua_classvariable ( luaVM, "z", CLuaVector3Defs::SetZ, CLuaVector3Defs::GetZ );
lua_classvariable ( luaVM, "length", NULL, CLuaVector3Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector3Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector3Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector3" );
}


void CLuaMain::AddVector2DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );


lua_classmetamethod ( luaVM, "__tostring", CLuaVector2Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector2Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector2Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector2Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector2Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector2Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector2Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector2Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector2Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector2Defs::GetLength );

lua_classfunction ( luaVM, "create", CLuaVector2Defs::Create );
lua_classfunction ( luaVM, "normalize", CLuaVector2Defs::Normalize );
lua_classfunction ( luaVM, "dot", CLuaVector2Defs::Dot );

lua_classfunction ( luaVM, "getLength", CLuaVector2Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector2Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", CLuaVector2Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", CLuaVector2Defs::GetX );
lua_classfunction ( luaVM, "getY", CLuaVector2Defs::GetY );

lua_classfunction ( luaVM, "setX", CLuaVector2Defs::SetX );
lua_classfunction ( luaVM, "setY", CLuaVector2Defs::SetY );

lua_classvariable ( luaVM, "x", CLuaVector2Defs::SetX, CLuaVector2Defs::GetX );
lua_classvariable ( luaVM, "y", CLuaVector2Defs::SetY, CLuaVector2Defs::GetY );

lua_classvariable ( luaVM, "length", NULL, CLuaVector2Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector2Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector2Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector2" );
}


void CLuaMain::AddMatrixClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaMatrixDefs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaMatrixDefs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaMatrixDefs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaMatrixDefs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaMatrixDefs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaMatrixDefs::Div );

lua_classfunction ( luaVM, "create", CLuaMatrixDefs::Create );

lua_classfunction ( luaVM, "transformPosition", CLuaMatrixDefs::TransformPosition );
lua_classfunction ( luaVM, "transformDirection", CLuaMatrixDefs::TransformDirection );
lua_classfunction ( luaVM, "inverse", CLuaMatrixDefs::Inverse );

lua_classfunction ( luaVM, "getPosition", CLuaMatrixDefs::GetPosition );
lua_classfunction ( luaVM, "getRotation", CLuaMatrixDefs::GetRotation );
lua_classfunction ( luaVM, "getForward", CLuaMatrixDefs::GetForward );
lua_classfunction ( luaVM, "getRight", CLuaMatrixDefs::GetRight );
lua_classfunction ( luaVM, "getUp", CLuaMatrixDefs::GetUp );

lua_classfunction ( luaVM, "setPosition", CLuaMatrixDefs::SetPosition );
lua_classfunction ( luaVM, "setRotation", CLuaMatrixDefs::SetRotation );
lua_classfunction ( luaVM, "setForward", CLuaMatrixDefs::SetForward );
lua_classfunction ( luaVM, "setRight", CLuaMatrixDefs::SetRight );
lua_classfunction ( luaVM, "setUp", CLuaMatrixDefs::SetUp );

lua_classvariable ( luaVM, "position", CLuaMatrixDefs::SetPosition, CLuaMatrixDefs::GetPosition );
lua_classvariable ( luaVM, "rotation", CLuaMatrixDefs::SetRotation, CLuaMatrixDefs::GetRotation );
lua_classvariable ( luaVM, "forward", CLuaMatrixDefs::SetForward, CLuaMatrixDefs::GetForward );
lua_classvariable ( luaVM, "right", CLuaMatrixDefs::SetRight, CLuaMatrixDefs::GetRight );
lua_classvariable ( luaVM, "up", CLuaMatrixDefs::SetUp, CLuaMatrixDefs::GetUp );

lua_registerclass ( luaVM, "Matrix" );
}


void CLuaMain::InitClasses ( lua_State* luaVM )
{
lua_initclasses ( luaVM );

AddVector4DClass ( luaVM );
AddVector3DClass ( luaVM );
AddVector2DClass ( luaVM );
AddMatrixClass ( luaVM );
CLuaVector4Defs::AddClass ( luaVM );
CLuaVector3Defs::AddClass ( luaVM );
CLuaVector2Defs::AddClass ( luaVM );
CLuaMatrixDefs::AddClass ( luaVM );

if ( !m_bEnableOOP )
return;
Expand Down
5 changes: 0 additions & 5 deletions MTA10/mods/shared_logic/lua/CLuaMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,6 @@ class CLuaMain //: public CClient

void AddCameraClass ( lua_State* luaVM );

void AddVector4DClass ( lua_State* luaVM );
void AddVector3DClass ( lua_State* luaVM );
void AddVector2DClass ( lua_State* luaVM );
void AddMatrixClass ( lua_State* luaVM );

void AddDxMaterialClass ( lua_State* luaVM );
void AddDxTextureClass ( lua_State* luaVM );
void AddDxFontClass ( lua_State* luaVM );
Expand Down
40 changes: 40 additions & 0 deletions MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,46 @@

#include "StdInc.h"

void CLuaMatrixDefs::AddClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", ToString );
lua_classmetamethod ( luaVM, "__gc", Destroy );

lua_classmetamethod ( luaVM, "__add", Add );
lua_classmetamethod ( luaVM, "__sub", Sub );
lua_classmetamethod ( luaVM, "__mul", Mul );
lua_classmetamethod ( luaVM, "__div", Div );

lua_classfunction ( luaVM, "create", Create );

lua_classfunction ( luaVM, "transformPosition", TransformPosition );
lua_classfunction ( luaVM, "transformDirection", TransformDirection );
lua_classfunction ( luaVM, "inverse", Inverse );

lua_classfunction ( luaVM, "getPosition", GetPosition );
lua_classfunction ( luaVM, "getRotation", GetRotation );
lua_classfunction ( luaVM, "getForward", GetForward );
lua_classfunction ( luaVM, "getRight", GetRight );
lua_classfunction ( luaVM, "getUp", GetUp );

lua_classfunction ( luaVM, "setPosition", SetPosition );
lua_classfunction ( luaVM, "setRotation", SetRotation );
lua_classfunction ( luaVM, "setForward", SetForward );
lua_classfunction ( luaVM, "setRight", SetRight );
lua_classfunction ( luaVM, "setUp", SetUp );

lua_classvariable ( luaVM, "position", SetPosition, GetPosition );
lua_classvariable ( luaVM, "rotation", SetRotation, GetRotation );
lua_classvariable ( luaVM, "forward", SetForward, GetForward );
lua_classvariable ( luaVM, "right", SetRight, GetRight );
lua_classvariable ( luaVM, "up", SetUp, GetUp );

lua_registerclass ( luaVM, "Matrix" );
}


int CLuaMatrixDefs::Create ( lua_State* luaVM )
{
CMatrix matrix;
Expand Down
8 changes: 3 additions & 5 deletions MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*
*****************************************************************************/

#ifndef __CLUAMATRIXDEFS_H
#define __CLUAMATRIXDEFS_H
#pragma once

extern "C"
{
Expand All @@ -23,6 +22,7 @@ extern "C"
class CLuaMatrixDefs: public CLuaDefs
{
public:
static void AddClass ( lua_State* luaVM );
LUA_DECLARE ( Create );
LUA_DECLARE ( Destroy );

Expand All @@ -48,6 +48,4 @@ class CLuaMatrixDefs: public CLuaDefs
LUA_DECLARE ( Sub );
LUA_DECLARE ( Mul );
LUA_DECLARE ( Div );
};

#endif
};
41 changes: 41 additions & 0 deletions MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,47 @@

#include "StdInc.h"

void CLuaVector2Defs::AddClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );


lua_classmetamethod ( luaVM, "__tostring", ToString );
lua_classmetamethod ( luaVM, "__gc", Destroy );

lua_classmetamethod ( luaVM, "__add", Add );
lua_classmetamethod ( luaVM, "__sub", Sub );
lua_classmetamethod ( luaVM, "__mul", Mul );
lua_classmetamethod ( luaVM, "__div", Div );
lua_classmetamethod ( luaVM, "__pow", Pow );
lua_classmetamethod ( luaVM, "__unm", Unm );
lua_classmetamethod ( luaVM, "__eq", Eq );
lua_classmetamethod ( luaVM, "__len", GetLength );

lua_classfunction ( luaVM, "create", Create );
lua_classfunction ( luaVM, "normalize", Normalize );
lua_classfunction ( luaVM, "dot", Dot );

lua_classfunction ( luaVM, "getLength", GetLength );
lua_classfunction ( luaVM, "getSquaredLength", GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", GetNormalized );
lua_classfunction ( luaVM, "getX", GetX );
lua_classfunction ( luaVM, "getY", GetY );

lua_classfunction ( luaVM, "setX", SetX );
lua_classfunction ( luaVM, "setY", SetY );

lua_classvariable ( luaVM, "x", SetX, GetX );
lua_classvariable ( luaVM, "y", SetY, GetY );

lua_classvariable ( luaVM, "length", NULL, GetLength );
lua_classvariable ( luaVM, "squaredLength", NULL, GetLengthSquared );
lua_classvariable ( luaVM, "normalized", NULL, GetNormalized );

lua_registerclass ( luaVM, "Vector2" );
}


int CLuaVector2Defs::Create ( lua_State* luaVM )
{
CVector2D vector;
Expand Down
8 changes: 3 additions & 5 deletions MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*
*****************************************************************************/

#ifndef __LUAVECTORDEFS_H
#define __LUAVECTORDEFS_H
#pragma once

extern "C"
{
Expand All @@ -23,6 +22,7 @@ extern "C"
class CLuaVector2Defs : public CLuaDefs
{
public:
static void AddClass ( lua_State* luaVM );
LUA_DECLARE ( Create );
LUA_DECLARE ( Destroy );

Expand All @@ -47,6 +47,4 @@ class CLuaVector2Defs : public CLuaDefs
LUA_DECLARE ( Pow );
LUA_DECLARE ( Unm );
LUA_DECLARE ( Eq );
};

#endif
};
Loading

0 comments on commit f87acdb

Please sign in to comment.