2016-03-04 23:04:53 +00:00
# include "logvisor/logvisor.hpp"
# include "boo/boo.hpp"
# include "specter/specter.hpp"
# include "hecl/CVarManager.hpp"
2016-12-24 06:08:48 +00:00
# include "Runtime/CBasics.hpp"
2015-12-06 01:27:02 +00:00
# include "ViewManager.hpp"
2017-11-19 07:10:54 +00:00
# include "hecl/hecl.hpp"
2018-01-10 06:20:34 +00:00
# include "hecl/CVarCommons.hpp"
2018-01-11 09:38:08 +00:00
# include "hecl/Console.hpp"
2015-11-21 01:16:07 +00:00
2016-03-07 22:48:54 +00:00
static logvisor : : Module AthenaLog ( " Athena " ) ;
static void AthenaExc ( athena : : error : : Level level , const char * file ,
const char * , int line , const char * fmt , . . . )
{
va_list ap ;
va_start ( ap , fmt ) ;
2016-09-11 21:17:27 +00:00
AthenaLog . report ( logvisor : : Level ( level ) , fmt , ap ) ;
2016-03-07 22:48:54 +00:00
va_end ( ap ) ;
}
2016-03-05 00:03:41 +00:00
namespace urde
2015-11-21 01:16:07 +00:00
{
2016-03-05 00:03:41 +00:00
static logvisor : : Module Log { " URDE " } ;
2016-02-15 17:35:20 +00:00
2017-12-12 02:06:19 +00:00
static hecl : : SystemString CPUFeatureString ( const zeus : : CPUInfo & cpuInf )
{
hecl : : SystemString features ;
2017-12-27 00:51:02 +00:00
auto AddFeature = [ & features ] ( const hecl : : SystemChar * str )
2017-12-12 02:06:19 +00:00
{
if ( ! features . empty ( ) )
2017-12-27 00:51:02 +00:00
features + = _S ( " , " ) ;
features + = str ;
} ;
if ( cpuInf . AESNI )
AddFeature ( _S ( " AES-NI " ) ) ;
if ( cpuInf . SSE1 )
AddFeature ( _S ( " SSE " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSE2 )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSE2 " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSE3 )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSE3 " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSSE3 )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSSE3 " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSE4a )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSE4a " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSE41 )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSE4.1 " ) ) ;
2017-12-12 02:06:19 +00:00
if ( cpuInf . SSE42 )
2017-12-27 00:51:02 +00:00
AddFeature ( _S ( " SSE4.2 " ) ) ;
if ( cpuInf . AVX )
AddFeature ( _S ( " AVX " ) ) ;
if ( cpuInf . AVX2 )
AddFeature ( _S ( " AVX2 " ) ) ;
2017-12-12 02:06:19 +00:00
return features ;
}
2015-11-21 01:16:07 +00:00
struct Application : boo : : IApplicationCallback
{
2016-03-04 23:04:53 +00:00
hecl : : Runtime : : FileStoreManager m_fileMgr ;
hecl : : CVarManager m_cvarManager ;
2018-01-10 06:20:34 +00:00
hecl : : CVarCommons m_cvarCommons ;
2016-02-20 05:49:47 +00:00
std : : unique_ptr < ViewManager > m_viewManager ;
2015-12-06 01:27:02 +00:00
2018-06-02 00:03:31 +00:00
std : : atomic_bool m_running = { true } ;
2015-11-22 04:35:24 +00:00
2015-11-23 08:47:57 +00:00
Application ( ) :
2016-01-05 09:53:16 +00:00
m_fileMgr ( _S ( " urde " ) ) ,
2018-01-10 06:20:34 +00:00
m_cvarManager ( m_fileMgr ) ,
2018-04-26 21:12:20 +00:00
m_cvarCommons ( m_cvarManager )
2016-02-20 05:49:47 +00:00
{
2017-08-08 22:12:14 +00:00
m_viewManager = std : : make_unique < ViewManager > ( m_fileMgr , m_cvarManager ) ;
2016-02-20 05:49:47 +00:00
}
2015-11-22 04:35:24 +00:00
2016-07-09 06:53:20 +00:00
virtual ~ Application ( ) = default ;
2015-11-21 01:16:07 +00:00
int appMain ( boo : : IApplication * app )
{
2016-02-15 17:35:20 +00:00
initialize ( app ) ;
2016-02-20 05:49:47 +00:00
m_viewManager - > init ( app ) ;
2018-06-02 00:03:31 +00:00
while ( m_running . load ( ) )
2015-11-22 04:35:24 +00:00
{
2016-02-20 05:49:47 +00:00
if ( ! m_viewManager - > proc ( ) )
2015-11-26 23:04:11 +00:00
break ;
2015-11-22 04:35:24 +00:00
}
2016-02-20 05:49:47 +00:00
m_viewManager - > stop ( ) ;
2016-12-13 02:56:43 +00:00
m_viewManager - > projectManager ( ) . saveProject ( ) ;
2015-12-04 01:44:35 +00:00
m_cvarManager . serialize ( ) ;
2016-02-20 05:49:47 +00:00
m_viewManager . reset ( ) ;
2015-11-21 01:16:07 +00:00
return 0 ;
}
void appQuitting ( boo : : IApplication * )
{
2018-06-02 00:03:31 +00:00
m_running . store ( false ) ;
2015-11-21 01:16:07 +00:00
}
2017-01-22 06:28:55 +00:00
void appFilesOpen ( boo : : IApplication * , const std : : vector < boo : : SystemString > & paths )
{
for ( const auto & path : paths )
{
hecl : : ProjectRootPath projPath = hecl : : SearchForProject ( path ) ;
if ( projPath )
{
2017-01-23 10:13:36 +00:00
m_viewManager - > deferOpenProject ( path ) ;
2017-01-22 06:28:55 +00:00
break ;
}
}
}
2016-02-15 17:35:20 +00:00
2017-01-22 06:28:55 +00:00
void initialize ( boo : : IApplication * app )
2016-02-15 17:35:20 +00:00
{
2016-03-04 23:04:53 +00:00
zeus : : detectCPU ( ) ;
2018-06-04 19:15:35 +00:00
createGlobalCVars ( ) ;
2017-01-22 06:28:55 +00:00
for ( const boo : : SystemString & arg : app - > getArgs ( ) )
{
2017-08-08 22:12:14 +00:00
if ( arg . find ( _S ( " --verbosity= " ) ) = = 0 | | arg . find ( _S ( " -v= " ) ) = = 0 )
2017-01-22 06:28:55 +00:00
{
2017-11-13 06:19:18 +00:00
hecl : : SystemUTF8Conv utf8Arg ( arg . substr ( arg . find_last_of ( ' = ' ) + 1 ) ) ;
2017-01-22 06:28:55 +00:00
hecl : : VerbosityLevel = atoi ( utf8Arg . c_str ( ) ) ;
hecl : : LogModule . report ( logvisor : : Info , " Set verbosity level to %i " , hecl : : VerbosityLevel ) ;
}
}
2016-02-15 17:35:20 +00:00
2018-04-30 03:12:41 +00:00
m_cvarManager . parseCommandLine ( app - > getArgs ( ) ) ;
2016-03-04 23:04:53 +00:00
const zeus : : CPUInfo & cpuInf = zeus : : cpuFeatures ( ) ;
Log . report ( logvisor : : Info , " CPU Name: %s " , cpuInf . cpuBrand ) ;
Log . report ( logvisor : : Info , " CPU Vendor: %s " , cpuInf . cpuVendor ) ;
2017-12-12 02:06:19 +00:00
Log . report ( logvisor : : Info , _S ( " CPU Features: %s " ) , CPUFeatureString ( cpuInf ) . c_str ( ) ) ;
2016-02-15 17:35:20 +00:00
}
2018-01-07 05:19:49 +00:00
2018-01-10 06:20:34 +00:00
std : : string getGraphicsApi ( ) const
{
return m_cvarCommons . getGraphicsApi ( ) ;
}
uint32_t getSamples ( ) const
2018-01-07 05:19:49 +00:00
{
2018-01-10 06:20:34 +00:00
return m_cvarCommons . getSamples ( ) ;
2018-01-07 05:19:49 +00:00
}
2018-01-10 06:20:34 +00:00
uint32_t getAnisotropy ( ) const
2018-01-07 05:19:49 +00:00
{
2018-01-10 06:20:34 +00:00
return m_cvarCommons . getAnisotropy ( ) ;
2018-01-07 05:19:49 +00:00
}
2018-01-11 09:38:08 +00:00
2018-01-16 06:42:28 +00:00
bool getDeepColor ( ) const
{
return m_cvarCommons . getDeepColor ( ) ;
}
2018-06-04 19:15:35 +00:00
void createGlobalCVars ( )
{
m_cvarManager . findOrMakeCVar ( " debugOverlay.playerInfo " sv , " Displays information about the player, such as location and orientation " sv , false ,
hecl : : CVar : : EFlags : : Game | hecl : : CVar : : EFlags : : Archive | hecl : : CVar : : EFlags : : ReadOnly ) ;
m_cvarManager . findOrMakeCVar ( " debugOverlay.worldInfo " sv , " Displays information about the current world, such as world asset ID, and areaId " sv , false ,
hecl : : CVar : : EFlags : : Game | hecl : : CVar : : EFlags : : Archive | hecl : : CVar : : EFlags : : ReadOnly ) ;
m_cvarManager . findOrMakeCVar ( " debugOverlay.areaInfo " sv , " Displays information about the current area, such as asset ID, object/layer counts, and active layer bits " sv , false ,
hecl : : CVar : : EFlags : : Game | hecl : : CVar : : EFlags : : Archive | hecl : : CVar : : EFlags : : ReadOnly ) ;
m_cvarManager . findOrMakeCVar ( " debugOverlay.showFrameCounter " sv , " Displays the current frame index " sv , false ,
hecl : : CVar : : EFlags : : Game | hecl : : CVar : : EFlags : : Archive | hecl : : CVar : : EFlags : : ReadOnly ) ;
}
2015-11-21 01:16:07 +00:00
} ;
}
2017-02-24 08:28:44 +00:00
static hecl : : SystemChar CwdBuf [ 1024 ] ;
hecl : : SystemString ExeDir ;
2017-11-19 07:10:54 +00:00
static void SetupBasics ( bool logging )
2017-10-24 03:12:10 +00:00
{
2017-12-12 02:06:19 +00:00
auto result = zeus : : validateCPU ( ) ;
if ( ! result . first )
{
# if _WIN32 && !WINDOWS_STORE
char * msg ;
asprintf ( & msg , " ERROR: This build of URDE requires the following CPU features: \n %s \n " ,
urde : : CPUFeatureString ( result . second ) . c_str ( ) ) ;
MessageBoxA ( nullptr , msg , " CPU error " , MB_OK | MB_ICONERROR ) ;
free ( msg ) ;
# else
fprintf ( stderr , " ERROR: This build of URDE requires the following CPU features: \n %s \n " ,
urde : : CPUFeatureString ( result . second ) . c_str ( ) ) ;
# endif
exit ( 1 ) ;
}
2017-10-24 03:12:10 +00:00
logvisor : : RegisterStandardExceptions ( ) ;
2017-11-19 07:10:54 +00:00
if ( logging )
logvisor : : RegisterConsoleLogger ( ) ;
2017-10-24 03:12:10 +00:00
atSetExceptionHandler ( AthenaExc ) ;
}
2017-11-19 07:10:54 +00:00
static bool IsClientLoggingEnabled ( int argc , const boo : : SystemChar * * argv )
{
for ( int i = 1 ; i < argc ; + + i )
if ( ! hecl : : StrNCmp ( argv [ i ] , _S ( " -l " ) , 2 ) )
2017-12-06 03:26:15 +00:00
return true ;
return false ;
2017-11-19 07:10:54 +00:00
}
2017-12-06 03:26:15 +00:00
# if !WINDOWS_STORE
2015-11-21 01:16:07 +00:00
# if _WIN32
int wmain ( int argc , const boo : : SystemChar * * argv )
# else
int main ( int argc , const boo : : SystemChar * * argv )
# endif
{
2017-12-27 04:12:28 +00:00
if ( argc > 1 & & ! hecl : : StrCmp ( argv [ 1 ] , _S ( " --dlpackage " ) ) )
2017-12-27 00:51:02 +00:00
{
printf ( " %s \n " , URDE_DLPACKAGE ) ;
return 100 ;
}
2017-11-19 07:10:54 +00:00
SetupBasics ( IsClientLoggingEnabled ( argc , argv ) ) ;
2017-02-24 08:28:44 +00:00
if ( hecl : : SystemChar * cwd = hecl : : Getcwd ( CwdBuf , 1024 ) )
{
2017-02-25 07:59:37 +00:00
if ( hecl : : PathRelative ( argv [ 0 ] ) )
2017-02-24 08:28:44 +00:00
ExeDir = hecl : : SystemString ( cwd ) + _S ( ' / ' ) ;
hecl : : SystemString Argv0 ( argv [ 0 ] ) ;
hecl : : SystemString : : size_type lastIdx = Argv0 . find_last_of ( _S ( " / \\ " ) ) ;
if ( lastIdx ! = hecl : : SystemString : : npos )
ExeDir . insert ( ExeDir . end ( ) , Argv0 . begin ( ) , Argv0 . begin ( ) + lastIdx ) ;
}
2016-03-05 00:03:41 +00:00
urde : : Application appCb ;
2015-12-06 01:27:02 +00:00
int ret = boo : : ApplicationRun ( boo : : IApplication : : EPlatformType : : Auto ,
2018-01-10 06:20:34 +00:00
appCb , _S ( " urde " ) , _S ( " URDE " ) , argc , argv , appCb . getGraphicsApi ( ) ,
2018-01-16 06:42:28 +00:00
appCb . getSamples ( ) , appCb . getAnisotropy ( ) , appCb . getDeepColor ( ) , false ) ;
2018-01-10 06:20:34 +00:00
//printf("IM DYING!!\n");
2015-11-21 01:16:07 +00:00
return ret ;
}
2017-12-06 03:26:15 +00:00
# endif
2015-11-21 01:16:07 +00:00
2017-12-06 03:26:15 +00:00
# if WINDOWS_STORE
2017-12-07 04:13:12 +00:00
# include "boo/UWPViewProvider.hpp"
2017-10-24 03:12:10 +00:00
using namespace Windows : : ApplicationModel : : Core ;
[ Platform : : MTAThread ]
int WINAPIV main ( Platform : : Array < Platform : : String ^ > ^ params )
{
2017-12-06 03:26:15 +00:00
SetupBasics ( false ) ;
2017-10-24 03:12:10 +00:00
urde : : Application appCb ;
2017-12-06 03:26:15 +00:00
auto viewProvider = ref new boo : : ViewProvider ( appCb , _S ( " urde " ) , _S ( " URDE " ) , _S ( " urde " ) , params , false ) ;
2017-10-24 03:12:10 +00:00
CoreApplication : : Run ( viewProvider ) ;
return 0 ;
}
# elif _WIN32
2015-11-21 01:16:07 +00:00
int APIENTRY wWinMain ( HINSTANCE hInstance , HINSTANCE , LPWSTR lpCmdLine , int )
{
int argc = 0 ;
2018-05-28 20:27:41 +00:00
const boo : : SystemChar * * argv ;
if ( lpCmdLine [ 0 ] )
argv = ( const wchar_t * * ) ( CommandLineToArgvW ( lpCmdLine , & argc ) ) ;
2015-11-21 01:16:07 +00:00
static boo : : SystemChar selfPath [ 1024 ] ;
GetModuleFileNameW ( nullptr , selfPath , 1024 ) ;
static const boo : : SystemChar * booArgv [ 32 ] = { } ;
booArgv [ 0 ] = selfPath ;
for ( int i = 0 ; i < argc ; + + i )
booArgv [ i + 1 ] = argv [ i ] ;
2017-11-19 07:10:54 +00:00
if ( IsClientLoggingEnabled ( argc + 1 , booArgv ) )
logvisor : : CreateWin32Console ( ) ;
2018-05-28 20:27:41 +00:00
return wmain ( argc + 1 , booArgv ) ;
2015-11-21 01:16:07 +00:00
}
# endif
2017-10-24 03:12:10 +00:00