Немного рефакторинга

This commit is contained in:
Kernell 2015-12-04 03:48:53 +03:00
parent 43014102fc
commit c2a5429975
8 changed files with 261 additions and 25 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

156
.gitignore vendored Normal file
View File

@ -0,0 +1,156 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store

View File

@ -12,7 +12,7 @@
#include "CMonoDomain.h"
CMonoDomain::CMonoDomain( CMonoInterface* pMono, MonoDomain* pDomain, CResource* pResource, char* szName )
CMonoDomain::CMonoDomain( CMonoInterface* pMono, MonoDomain* pDomain, CResource* pResource, const char* szName )
{
this->m_pMono = pMono;
this->m_pDomain = pDomain;
@ -43,6 +43,12 @@ CMonoDomain::~CMonoDomain( void )
if( this->m_pDomain )
{
mono_domain_finalize( this->m_pDomain, 2000 );
MonoObject *pException = nullptr;
//mono_domain_try_unload( this->m_pDomain, &pException );
this->HandleException( pException );
}
this->m_pDomain = nullptr;
@ -87,13 +93,7 @@ CMonoClass* CMonoDomain::FindOrAdd( MonoClass* klass )
return nullptr;
}
void CMonoDomain::Init( void )
{
this->m_pCorlib = new CMonoCorlib( this );
this->m_pMTALib = new CMonoMTALib( this );
}
bool CMonoDomain::Start( void )
bool CMonoDomain::Init( void )
{
string sDirectory ( CMonoInterface::GetBinariesDirectory() + "/" + this->m_strName + "/" );
string sPath ( sDirectory + this->m_strName + ".dll" );
@ -109,8 +109,6 @@ bool CMonoDomain::Start( void )
return false;
}
this->GetResource()->RegisterEvents();
this->m_pMonoImage = mono_assembly_get_image( this->m_pMonoAssembly );
if( !this->m_pMonoImage )
@ -129,11 +127,19 @@ bool CMonoDomain::Start( void )
return false;
}
this->m_pCorlib = new CMonoCorlib( this );
this->m_pMTALib = new CMonoMTALib( this );
return true;
}
bool CMonoDomain::Start( void )
{
CMonoMethod* pMethod = this->m_pMonoClass->GetMethod( "Main", 0 );
if( !pMethod )
{
g_pModuleManager->ErrorPrintf( "static method '%s::Main' not found in '%s.dll'\n", sClass.c_str(), this->m_strName.c_str() );
g_pModuleManager->ErrorPrintf( "Assembly '%s.dll' doesn't have an entry point.\n", this->m_strName.c_str() );
return false;
}

View File

@ -42,14 +42,14 @@ private:
string m_strName;
public:
CMonoDomain ( CMonoInterface* pMono, MonoDomain* pDomain, CResource* pResource, char* szName );
CMonoDomain ( CMonoInterface* pMono, MonoDomain* pDomain, CResource* pResource, const char* szName );
~CMonoDomain ( void );
void HandleException ( MonoObject* pException );
CMonoClass* FindOrAdd ( MonoClass* klass );
void Init ( void );
bool Init ( void );
bool Start ( void );
void Unload ( void );
bool Set ( bool bForce );

View File

@ -21,6 +21,8 @@ CMonoInterface::CMonoInterface( void )
mono_debug_init( MONO_DEBUG_FORMAT_MONO );
mono_trace_set_level_string( "error" );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
CMonoFunctions::AddInternals();
@ -35,9 +37,9 @@ CMonoInterface::~CMonoInterface( void )
SAFE_DELETE( this->m_pGC );
}
CMonoDomain* CMonoInterface::CreateAppdomain( CResource* pResource, char* szName, char* szConfig )
CMonoDomain* CMonoInterface::CreateAppdomain( CResource* pResource, const char* szName, char* szConfig )
{
MonoDomain* pMonoDomain = mono_domain_create_appdomain( szName, szConfig );
MonoDomain* pMonoDomain = mono_domain_create_appdomain( const_cast< char* >( szName ), szConfig );
if( pMonoDomain )
{
@ -50,6 +52,4 @@ CMonoDomain* CMonoInterface::CreateAppdomain( CResource* pResource, char* szName
void CMonoInterface::SetDomain( MonoDomain* pDomain, bool bForce )
{
mono_domain_set( pDomain != nullptr ? pDomain : this->m_pMonoDomain, bForce );
mono_domain_set_config( pDomain != nullptr ? pDomain : this->m_pMonoDomain, "mods/deathmatch/", "mods/deathmatch/mono/etc/mono/4.5/machine.config" );
}

View File

@ -30,7 +30,7 @@ public:
CMonoInterface ( void );
~CMonoInterface ( void );
CMonoDomain* CreateAppdomain ( CResource* pResource, char* szName, char* szConfig );
CMonoDomain* CreateAppdomain ( CResource* pResource, const char* szName, char* szConfig );
void SetDomain ( MonoDomain* pDomain = nullptr, bool bForce = false );

View File

@ -27,12 +27,14 @@ CResource::~CResource( void )
this->GetMono()->GetGC()->Collect( this->GetMono()->GetGC()->GetMaxGeneration() );
this->GetMono()->SetDomain( nullptr, true );
//this->GetMono()->SetDomain( nullptr, true );
g_pResourceManager->RemoveFromList( this );
SAFE_DELETE( this->m_pMonoDomain );
this->GetMono()->SetDomain( nullptr, true );
this->m_pMono = nullptr;
this->m_pLuaVM = nullptr;
}
@ -147,7 +149,7 @@ bool CResource::Init( void )
{
if( this->m_pLuaVM )
{
this->m_pMonoDomain = this->GetMono()->CreateAppdomain( this, const_cast< char* >( this->m_sName.c_str() ), nullptr );
this->m_pMonoDomain = this->GetMono()->CreateAppdomain( this, this->m_sName.c_str(), nullptr );
if( !this->m_pMonoDomain )
{
@ -160,12 +162,20 @@ bool CResource::Init( void )
this->m_pMonoDomain->Set( false );
this->m_pMonoDomain->Init();
this->m_pMonoDomain->Start();
if( this->m_pMonoDomain->Init() )
{
this->RegisterEvents();
if( this->m_pMonoDomain->Start() )
{
return true;
}
}
CLuaArguments pLuaArguments;
pLuaArguments.Call( this->m_pLuaVM, "cancelEvent" );
}
return false;
}

View File

@ -42,6 +42,7 @@ extern "C"
#include <mono/metadata/environment.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/mono-gc.h>
#include <mono/utils/mono-logger.h>
#include "Common.h"