Исходный код и шапка отделено

This commit is contained in:
Kernell 2015-11-28 04:37:49 +03:00
parent 7e62cf4d7e
commit 9b0242c67b
6 changed files with 592 additions and 492 deletions

View File

@ -0,0 +1,102 @@
/*********************************************************
*
* Copyright © 2013, Innovation Roleplay Engine.
*
* All Rights Reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification,
* is permitted only for authors.
*
*********************************************************/
#include "CResourceManager.h"
CResourceManager::CResourceManager( void )
{
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
CMonoFunctions::AddInternals();
}
CResourceManager::~CResourceManager( void )
{
for( auto iter : this->m_List )
{
delete iter;
}
mono_jit_cleanup( this->m_pMonoDomain );
}
CResource* CResourceManager::Create( lua_State* luaVM, string strName )
{
if( !this->GetFromList( luaVM ) )
{
string sPath( "mods/deathmatch/resources/[ire]/" + strName + "/" + strName + ".dll" );
struct stat buf;
if( stat( sPath.c_str(), &buf ) == -1 )
{
return nullptr;
}
CResource *pResource = new CResource( luaVM, strName );
this->AddToList( pResource );
return pResource;
}
return nullptr;
}
void CResourceManager::AddToList( CResource* pResource )
{
this->m_List.push_back( pResource );
}
CResource* CResourceManager::GetFromList( lua_State* pLuaVM )
{
for( auto iter : this->m_List )
{
if( iter->m_pLuaVM == pLuaVM )
{
return iter;
}
}
return nullptr;
}
CResource* CResourceManager::GetFromList( MonoDomain* pDomain )
{
for( auto iter : this->m_List )
{
if( iter->m_pMonoDomain == pDomain )
{
return iter;
}
}
return nullptr;
}
void CResourceManager::RemoveFromList( CResource* pResource )
{
if( !this->m_List.empty() )
{
this->m_List.remove( pResource );
}
}
void CResourceManager::DoPulse( void )
{
for( auto iter : this->m_List )
{
iter->DoPulse();
}
}

View File

@ -22,116 +22,19 @@ extern ILuaModuleManager10 *g_pModuleManager;
class CResourceManager class CResourceManager
{ {
private: private:
std::list< CResource* > m_List; list< CResource* > m_List;
MonoDomain *m_pMonoDomain; MonoDomain *m_pMonoDomain;
public: public:
CResourceManager( void ) CResourceManager ( void );
{ ~CResourceManager ( void );
// #ifdef _WIN32
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" );
// #endif
// mono_config_parse( NULL ); CResource* Create ( lua_State* luaVM, string strName );
void AddToList ( CResource* pResource );
// mono_debug_init( MONO_DEBUG_FORMAT_MONO ); CResource* GetFromList ( lua_State* pLuaVM );
CResource* GetFromList ( MonoDomain* pDomain );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" ); void RemoveFromList ( CResource* pResource );
void DoPulse ( void );
CMonoFunctions::AddInternals();
}
~CResourceManager( void )
{
std::list< CResource* >::const_iterator iter = this->m_List.begin();
for( ; iter != this->m_List.end(); iter++ )
{
delete *iter;
}
mono_jit_cleanup( this->m_pMonoDomain );
}
CResource* Create( lua_State* luaVM )
{
if( !this->GetFromList( luaVM ) )
{
string sName = "";
g_pModuleManager->GetResourceName( luaVM, sName );
string sPath( "mods/deathmatch/resources/[ire]/" + sName + "/" + sName + ".dll" );
struct stat buf;
if( stat( sPath.c_str(), &buf ) == -1 )
{
return NULL;
}
CResource *pResource = new CResource( luaVM, sName );
this->AddToList( pResource );
return pResource;
}
return NULL;
}
void AddToList( CResource* pResource )
{
this->m_List.push_back( pResource );
}
CResource* GetFromList( lua_State* pLuaVM )
{
std::list< CResource* >::const_iterator iter = this->m_List.begin();
for( ; iter != this->m_List.end(); iter++ )
{
if( (*iter)->m_pLuaVM == pLuaVM )
{
return *iter;
}
}
return NULL;
}
CResource* GetFromList( MonoDomain* pDomain )
{
std::list< CResource* >::const_iterator iter = this->m_List.begin();
for( ; iter != this->m_List.end(); iter++ )
{
if( (*iter)->m_pMonoDomain == pDomain )
{
return *iter;
}
}
return NULL;
}
void RemoveFromList( CResource* pResource )
{
if( !this->m_List.empty() )
{
this->m_List.remove( pResource );
}
}
void DoPulse( void )
{
std::list< CResource* >::const_iterator iter = this->m_List.begin();
for( ; iter != this->m_List.end(); iter++ )
{
(*iter)->DoPulse();
}
}
}; };
#endif #endif

View File

@ -0,0 +1,134 @@
#include "Vector2.h"
Vector2::Vector2( void )
{
fX = 0;
fY = 0;
}
Vector2::Vector2( float _fX, float _fY )
{
fX = _fX;
fY = _fY;
}
Vector2::Vector2( MonoObject* pObject )
{
this->fX = CMonoObject::GetPropertyValue< float >( pObject, "X" );
this->fY = CMonoObject::GetPropertyValue< float >( pObject, "Y" );
}
float Vector2::DotProduct( Vector2& other ) const
{
return fX*other.fX + fY*other.fY;
}
float Vector2::Length() const
{
return sqrt( fX * fX + fY * fY );
}
float Vector2::LengthSquared( void ) const
{
return ( fX*fX ) + ( fY*fY );
}
void Vector2::Normalize( void )
{
float fLength = Length();
if( fLength > 0.0f )
{
fX /= fLength;
fY /= fLength;
}
}
Vector2 Vector2::operator * ( float fRight ) const
{
return Vector2( fX * fRight, fY * fRight );
}
Vector2 Vector2::operator / ( float fRight ) const
{
float fRcpValue = 1 / fRight;
return Vector2( fX * fRcpValue, fY * fRcpValue );
}
Vector2 Vector2::operator + ( const Vector2& vecRight ) const
{
return Vector2( fX + vecRight.fX, fY + vecRight.fY );
}
Vector2 Vector2::operator - ( const Vector2& vecRight ) const
{
return Vector2( fX - vecRight.fX, fY - vecRight.fY );
}
Vector2 Vector2::operator * ( const Vector2& vecRight ) const
{
return Vector2( fX * vecRight.fX, fY * vecRight.fY );
}
Vector2 Vector2::operator / ( const Vector2& vecRight ) const
{
return Vector2( fX / vecRight.fX, fY / vecRight.fY );
}
void Vector2::operator += ( float fRight )
{
fX += fRight;
fY += fRight;
}
void Vector2::operator += ( const Vector2& vecRight )
{
fX += vecRight.fX;
fY += vecRight.fY;
}
void Vector2::operator -= ( float fRight )
{
fX -= fRight;
fY -= fRight;
}
void Vector2::operator -= ( const Vector2& vecRight )
{
fX -= vecRight.fX;
fY -= vecRight.fY;
}
void Vector2::operator *= ( float fRight )
{
fX *= fRight;
fY *= fRight;
}
void Vector2::operator *= ( const Vector2& vecRight )
{
fX *= vecRight.fX;
fY *= vecRight.fY;
}
void Vector2::operator /= ( float fRight )
{
fX /= fRight;
fY /= fRight;
}
void Vector2::operator /= ( const Vector2& vecRight )
{
fX /= vecRight.fX;
fY /= vecRight.fY;
}
bool Vector2::operator == ( const Vector2& param ) const
{
return ( ( fabs( fX - param.fX ) < FLOAT_EPSILON ) && ( fabs( fY - param.fY ) < FLOAT_EPSILON ) );
}
bool Vector2::operator != ( const Vector2& param ) const
{
return ( ( fabs( fX - param.fX ) >= FLOAT_EPSILON ) || ( fabs( fY - param.fY ) >= FLOAT_EPSILON ) );
}

View File

@ -14,6 +14,7 @@
#include <cmath> #include <cmath>
#include "Vector3.h" #include "Vector3.h"
#include "../CMonoObject.h"
/** /**
* CVector2D Structure used to store a 2D vertex. * CVector2D Structure used to store a 2D vertex.
@ -21,136 +22,35 @@
class Vector2 class Vector2
{ {
public: public:
Vector2 ( void ) float fX;
{ float fY;
fX = 0;
fY = 0;
}
Vector2 ( float _fX, float _fY ) Vector2( void );
{ Vector2( float _fX, float _fY );
fX = _fX; Vector2( MonoObject* pObject );
fY = _fY;
}
float DotProduct ( Vector2& other ) const float DotProduct ( Vector2& other ) const;
{ float Length ( void ) const;
return fX*other.fX + fY*other.fY; float LengthSquared ( void ) const;
} void Normalize ( void );
float Length () const Vector2 operator * ( float fRight ) const;
{ Vector2 operator / ( float fRight ) const;
return sqrt ( fX * fX + fY * fY ); Vector2 operator + ( const Vector2& vecRight ) const;
} Vector2 operator - ( const Vector2& vecRight ) const;
Vector2 operator * ( const Vector2& vecRight ) const;
Vector2 operator / ( const Vector2& vecRight ) const;
float LengthSquared ( void ) const void operator += ( float fRight );
{ void operator += ( const Vector2& vecRight );
return (fX*fX) + (fY*fY); void operator -= ( float fRight );
} void operator -= ( const Vector2& vecRight );
void operator *= ( float fRight );
void Normalize ( void ) void operator *= ( const Vector2& vecRight );
{ void operator /= ( float fRight );
float fLength = Length (); void operator /= ( const Vector2& vecRight );
if ( fLength > 0.0f ) bool operator == ( const Vector2& param ) const;
{ bool operator != ( const Vector2& param ) const;
fX /= fLength;
fY /= fLength;
}
}
Vector2 operator * ( float fRight ) const
{
return Vector2 ( fX * fRight, fY * fRight );
}
Vector2 operator / ( float fRight ) const
{
float fRcpValue = 1 / fRight;
return Vector2 ( fX * fRcpValue, fY * fRcpValue );
}
Vector2 operator + ( const Vector2& vecRight ) const
{
return Vector2 ( fX + vecRight.fX, fY + vecRight.fY );
}
Vector2 operator - ( const Vector2& vecRight ) const
{
return Vector2 ( fX - vecRight.fX, fY - vecRight.fY );
}
Vector2 operator * ( const Vector2& vecRight ) const
{
return Vector2 ( fX * vecRight.fX, fY * vecRight.fY );
}
Vector2 operator / ( const Vector2& vecRight ) const
{
return Vector2 ( fX / vecRight.fX, fY / vecRight.fY );
}
void operator += ( float fRight )
{
fX += fRight;
fY += fRight;
}
void operator += ( const Vector2& vecRight )
{
fX += vecRight.fX;
fY += vecRight.fY;
}
void operator -= ( float fRight )
{
fX -= fRight;
fY -= fRight;
}
void operator -= ( const Vector2& vecRight )
{
fX -= vecRight.fX;
fY -= vecRight.fY;
}
void operator *= ( float fRight )
{
fX *= fRight;
fY *= fRight;
}
void operator *= ( const Vector2& vecRight )
{
fX *= vecRight.fX;
fY *= vecRight.fY;
}
void operator /= ( float fRight )
{
fX /= fRight;
fY /= fRight;
}
void operator /= ( const Vector2& vecRight )
{
fX /= vecRight.fX;
fY /= vecRight.fY;
}
bool operator== ( const Vector2& param ) const
{
return ( ( fabs ( fX - param.fX ) < FLOAT_EPSILON ) &&
( fabs ( fY - param.fY ) < FLOAT_EPSILON ) );
}
bool operator!= ( const Vector2& param ) const
{
return ( ( fabs ( fX - param.fX ) >= FLOAT_EPSILON ) ||
( fabs ( fY - param.fY ) >= FLOAT_EPSILON ) );
}
float fX;
float fY;
}; };

View File

@ -0,0 +1,203 @@
#include "Vector3.h"
Vector3::Vector3( void )
{
this->fX = 0;
this->fY = 0;
this->fZ = 0;
};
Vector3::Vector3( float fX, float fY, float fZ )
{
this->fX = fX;
this->fY = fY;
this->fZ = fZ;
}
Vector3::Vector3( MonoObject *pObject )
{
this->fX = CMonoObject::GetPropertyValue< float >( pObject, "X" );
this->fY = CMonoObject::GetPropertyValue< float >( pObject, "Y" );
this->fZ = CMonoObject::GetPropertyValue< float >( pObject, "Z" );
}
float Vector3::Normalize( void )
{
float t = sqrt( this->fX * this->fX + this->fY * this->fY + this->fZ * this->fZ );
if( t > FLOAT_EPSILON )
{
float fRcpt = 1 / t;
this->fX *= fRcpt;
this->fY *= fRcpt;
this->fZ *= fRcpt;
}
else
{
t = 0;
}
return t;
}
float Vector3::Length( void ) const
{
return sqrt( ( fX*fX ) + ( fY*fY ) + ( fZ*fZ ) );
}
float Vector3::LengthSquared( void ) const
{
return ( fX*fX ) + ( fY*fY ) + ( fZ*fZ );
}
float Vector3::DotProduct( const Vector3 * param ) const
{
return fX*param->fX + fY*param->fY + fZ*param->fZ;
}
void Vector3::CrossProduct( const Vector3 * param )
{
float _fX = fX, _fY = fY, _fZ = fZ;
fX = _fY * param->fZ - param->fY * _fZ;
fY = _fZ * param->fX - param->fZ * _fX;
fZ = _fX * param->fY - param->fX * _fY;
}
Vector3 Vector3::ToRotation( void ) const
{
Vector3 vecRotation;
vecRotation.fZ = atan2( fY, fX );
Vector3 vecTemp( sqrt( fX * fX + fY * fY ), fZ, 0 );
vecTemp.Normalize();
vecRotation.fY = atan2( vecTemp.fX, vecTemp.fY ) - PI / 2;
return vecRotation;
}
Vector3 Vector3::GetOtherAxis( void ) const
{
Vector3 vecResult;
if( abs( fX ) > abs( fY ) )
{
vecResult = Vector3( fZ, 0, -fX );
}
else
{
vecResult = Vector3( 0, -fZ, fY );
}
vecResult.Normalize();
return vecResult;
}
Vector3 Vector3::operator + ( const Vector3& vecRight ) const
{
return Vector3( fX + vecRight.fX, fY + vecRight.fY, fZ + vecRight.fZ );
}
Vector3 Vector3::operator - ( const Vector3& vecRight ) const
{
return Vector3( fX - vecRight.fX, fY - vecRight.fY, fZ - vecRight.fZ );
}
Vector3 Vector3::operator * ( const Vector3& vecRight ) const
{
return Vector3( fX * vecRight.fX, fY * vecRight.fY, fZ * vecRight.fZ );
}
Vector3 Vector3::operator * ( float fRight ) const
{
return Vector3( fX * fRight, fY * fRight, fZ * fRight );
}
Vector3 Vector3::operator / ( const Vector3& vecRight ) const
{
return Vector3( fX / vecRight.fX, fY / vecRight.fY, fZ / vecRight.fZ );
}
Vector3 Vector3::operator / ( float fRight ) const
{
float fRcpValue = 1 / fRight;
return Vector3( fX * fRcpValue, fY * fRcpValue, fZ * fRcpValue );
}
Vector3 Vector3::operator - ( ) const
{
return Vector3( -fX, -fY, -fZ );
}
void Vector3::operator += ( float fRight )
{
fX += fRight;
fY += fRight;
fZ += fRight;
}
void Vector3::operator += ( const Vector3& vecRight )
{
fX += vecRight.fX;
fY += vecRight.fY;
fZ += vecRight.fZ;
}
void Vector3::operator -= ( float fRight )
{
fX -= fRight;
fY -= fRight;
fZ -= fRight;
}
void Vector3::operator -= ( const Vector3& vecRight )
{
fX -= vecRight.fX;
fY -= vecRight.fY;
fZ -= vecRight.fZ;
}
void Vector3::operator *= ( float fRight )
{
fX *= fRight;
fY *= fRight;
fZ *= fRight;
}
void Vector3::operator *= ( const Vector3& vecRight )
{
fX *= vecRight.fX;
fY *= vecRight.fY;
fZ *= vecRight.fZ;
}
void Vector3::operator /= ( float fRight )
{
float fRcpValue = 1 / fRight;
fX *= fRcpValue;
fY *= fRcpValue;
fZ *= fRcpValue;
}
void Vector3::operator /= ( const Vector3& vecRight )
{
fX /= vecRight.fX;
fY /= vecRight.fY;
fZ /= vecRight.fZ;
}
bool Vector3::operator== ( const Vector3& param ) const
{
return ( ( fabs( fX - param.fX ) < FLOAT_EPSILON ) && ( fabs( fY - param.fY ) < FLOAT_EPSILON ) && ( fabs( fZ - param.fZ ) < FLOAT_EPSILON ) );
}
bool Vector3::operator!= ( const Vector3& param ) const
{
return ( ( fabs( fX - param.fX ) >= FLOAT_EPSILON ) || ( fabs( fY - param.fY ) >= FLOAT_EPSILON ) || ( fabs( fZ - param.fZ ) >= FLOAT_EPSILON ) );
}

View File

@ -17,198 +17,56 @@
#endif #endif
#include <math.h> #include <math.h>
#include "../CMonoObject.h"
#define FLOAT_EPSILON 0.0001f #define FLOAT_EPSILON 0.0001f
#define PI (3.14159265358979323846f) #define PI 3.14159265358979323846f
/** /**
* CVector Structure used to store a 3D vertex. * CVector Structure used to store a 3D vertex.
*/ */
class Vector3 class Vector3
{ {
public: public:
float fX, fY, fZ; float fX, fY, fZ;
Vector3 () Vector3 ( void );
{ Vector3 ( float fX, float fY, float fZ );
this->fX = 0; Vector3 ( MonoObject *pObject );
this->fY = 0;
this->fZ = 0;
};
Vector3 ( float fX, float fY, float fZ) float Normalize ( void );
{ float Length ( void ) const;
this->fX = fX; float LengthSquared ( void ) const;
this->fY = fY; float DotProduct ( const Vector3 * param ) const;
this->fZ = fZ; void CrossProduct ( const Vector3 * param );
}
float Normalize ( void ) // Convert (direction) to rotation
{ Vector3 ToRotation ( void ) const;
float t = sqrt(fX*fX + fY*fY + fZ*fZ);
if ( t > FLOAT_EPSILON )
{
float fRcpt = 1 / t;
fX *= fRcpt;
fY *= fRcpt;
fZ *= fRcpt;
}
else
t = 0;
return t;
}
float Length ( void ) const // Return a perpendicular direction
{ Vector3 GetOtherAxis ( void ) const;
return sqrt ( (fX*fX) + (fY*fY) + (fZ*fZ) );
}
float LengthSquared ( void ) const Vector3 operator + ( const Vector3& vecRight ) const;
{ Vector3 operator - ( const Vector3& vecRight ) const;
return (fX*fX) + (fY*fY) + (fZ*fZ); Vector3 operator * ( const Vector3& vecRight ) const;
} Vector3 operator * ( float fRight ) const;
Vector3 operator / ( const Vector3& vecRight ) const;
Vector3 operator / ( float fRight ) const;
Vector3 operator - () const;
float DotProduct ( const Vector3 * param ) const void operator += ( float fRight );
{ void operator += ( const Vector3& vecRight );
return fX*param->fX + fY*param->fY + fZ*param->fZ;
}
void CrossProduct ( const Vector3 * param ) void operator -= ( float fRight );
{ void operator -= ( const Vector3& vecRight );
float _fX = fX, _fY = fY, _fZ = fZ;
fX = _fY * param->fZ - param->fY * _fZ;
fY = _fZ * param->fX - param->fZ * _fX;
fZ = _fX * param->fY - param->fX * _fY;
}
// Convert (direction) to rotation void operator *= ( float fRight );
Vector3 ToRotation ( void ) const void operator *= ( const Vector3& vecRight );
{
Vector3 vecRotation;
vecRotation.fZ = atan2 ( fY, fX );
Vector3 vecTemp ( sqrt ( fX * fX + fY * fY ), fZ, 0 );
vecTemp.Normalize ();
vecRotation.fY = atan2 ( vecTemp.fX, vecTemp.fY ) - PI / 2;
return vecRotation;
}
// Return a perpendicular direction void operator /= ( float fRight );
Vector3 GetOtherAxis ( void ) const void operator /= ( const Vector3& vecRight );
{
Vector3 vecResult;
if ( abs( fX ) > abs( fY ) )
vecResult = Vector3( fZ, 0, -fX );
else
vecResult = Vector3( 0, -fZ, fY );
vecResult.Normalize();
return vecResult;
}
Vector3 operator + ( const Vector3& vecRight ) const bool operator == ( const Vector3& param ) const;
{ bool operator != ( const Vector3& param ) const;
return Vector3 ( fX + vecRight.fX, fY + vecRight.fY, fZ + vecRight.fZ );
}
Vector3 operator - ( const Vector3& vecRight ) const
{
return Vector3 ( fX - vecRight.fX, fY - vecRight.fY, fZ - vecRight.fZ );
}
Vector3 operator * ( const Vector3& vecRight ) const
{
return Vector3 ( fX * vecRight.fX, fY * vecRight.fY, fZ * vecRight.fZ );
}
Vector3 operator * ( float fRight ) const
{
return Vector3 ( fX * fRight, fY * fRight, fZ * fRight );
}
Vector3 operator / ( const Vector3& vecRight ) const
{
return Vector3 ( fX / vecRight.fX, fY / vecRight.fY, fZ / vecRight.fZ );
}
Vector3 operator / ( float fRight ) const
{
float fRcpValue = 1 / fRight;
return Vector3 ( fX * fRcpValue, fY * fRcpValue, fZ * fRcpValue );
}
Vector3 operator - () const
{
return Vector3 ( -fX, -fY, -fZ );
}
void operator += ( float fRight )
{
fX += fRight;
fY += fRight;
fZ += fRight;
}
void operator += ( const Vector3& vecRight )
{
fX += vecRight.fX;
fY += vecRight.fY;
fZ += vecRight.fZ;
}
void operator -= ( float fRight )
{
fX -= fRight;
fY -= fRight;
fZ -= fRight;
}
void operator -= ( const Vector3& vecRight )
{
fX -= vecRight.fX;
fY -= vecRight.fY;
fZ -= vecRight.fZ;
}
void operator *= ( float fRight )
{
fX *= fRight;
fY *= fRight;
fZ *= fRight;
}
void operator *= ( const Vector3& vecRight )
{
fX *= vecRight.fX;
fY *= vecRight.fY;
fZ *= vecRight.fZ;
}
void operator /= ( float fRight )
{
float fRcpValue = 1 / fRight;
fX *= fRcpValue;
fY *= fRcpValue;
fZ *= fRcpValue;
}
void operator /= ( const Vector3& vecRight )
{
fX /= vecRight.fX;
fY /= vecRight.fY;
fZ /= vecRight.fZ;
}
bool operator== ( const Vector3& param ) const
{
return ( ( fabs ( fX - param.fX ) < FLOAT_EPSILON ) &&
( fabs ( fY - param.fY ) < FLOAT_EPSILON ) &&
( fabs ( fZ - param.fZ ) < FLOAT_EPSILON ) );
}
bool operator!= ( const Vector3& param ) const
{
return ( ( fabs ( fX - param.fX ) >= FLOAT_EPSILON ) ||
( fabs ( fY - param.fY ) >= FLOAT_EPSILON ) ||
( fabs ( fZ - param.fZ ) >= FLOAT_EPSILON ) );
}
}; };
#endif #endif