@ -153,6 +153,7 @@ float AiL::SIZE_CHANGE_SPEED=1;
AiL : : AiL ( )
{
debugLogger . open ( " debug.log " ) ;
utils : : datafile : : Read ( DATA , " assets/config/configuration.txt " ) ;
std : : filesystem : : create_directories ( " save_file_path " _S ) ;
@ -207,7 +208,7 @@ AiL::AiL()
std : : vector < std : : string > values = DATA . GetProperty ( " class_list " ) . GetValues ( ) ;
for ( const std : : string & cl : values ) {
std : : cout < < cl < < std : : endl ;
LOG ( cl ) ;
utils : : datafile : : Read ( DATA , CONFIG_PATH + " class_directory " _S + cl + " .txt " ) ;
}
@ -303,7 +304,7 @@ bool AiL::OnUserCreate(){
# ifdef __EMSCRIPTEN__
emscripten_idb_async_load ( " /assets " , ( " save_file_path " _S + " system.conf " ) . c_str ( ) , 0 , [ ] ( void * arg , void * data , int length ) {
std : : cout < < " Loaded System Save File successfully! " < < std : : endl ;
LOG ( " Loaded System Save File successfully! " ) ;
std : : string rawMetadata = ( char * ) data ;
std : : ofstream file ( " save_file_path " _S + " system.conf " ) ;
@ -313,7 +314,7 @@ bool AiL::OnUserCreate(){
file . close ( ) ;
GameSettings : : Initialize ( ) ;
} , [ ] ( void * arg ) {
std : : cout < < " Failed to load System Save File! " < < std : : endl ;
LOG ( " Failed to load System Save File! " ) ;
} ) ;
# else
GameSettings : : Initialize ( ) ;
@ -328,9 +329,9 @@ bool AiL::OnUserCreate(){
SetupDiscord ( ) ;
if ( SteamAPI_RestartAppIfNecessary ( 2895980U ) ) return false ; //Immediately quit if steam is detected and can be started through it.
if ( Steam_Init ( ) ) {
std : : cout < < " Steam API Initialized successfully! " < < std : : endl ;
LOG ( " Steam API Initialized successfully! " ) ;
} else {
std : : cout < < " Steam API failed to initialize! " < < std : : endl ;
LOG ( " Steam API failed to initialize! " ) ;
}
# endif
@ -339,7 +340,7 @@ bool AiL::OnUserCreate(){
if ( ! gamepack . Loaded ( ) & & " GENERATE_GAMEPACK " _B ) {
gamepack . SavePack ( " assets/ " + " gamepack_file " _S , PACK_KEY ) ;
std : : cout < < " Game Pack has been generated! " < < std : : endl < < " ======================== " < < std : : endl < < std : : endl ;
LOG ( " Game Pack has been generated! " < < std : : endl < < " ======================== " < < std : : endl ) ;
}
return true ;
@ -381,7 +382,7 @@ bool AiL::OnUserUpdate(float fElapsedTime){
if ( Discord ) {
auto result = Discord - > RunCallbacks ( ) ;
if ( result ! = : : discord : : Result : : Ok ) {
std : : cout < < " Discord Error Code " < < int ( result ) < < std : : endl ;
LOG ( " Discord Error Code " < < int ( result ) ) ;
delete Discord ;
Discord = nullptr ;
}
@ -1948,7 +1949,7 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . reflectiveData = tileset . GetData ( ) . ReflectiveData ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . isTerrain = tileset . GetData ( ) . isTerrain ;
MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . collision . SetInitialized ( ) ;
std : : cout < < " assets/maps/ " + baseSourceDir < < " Animation Data Size: " < < MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . animationData . size ( ) < < std : : endl ;
LOG ( " assets/maps/ " + baseSourceDir < < " Animation Data Size: " < < MAP_TILESETS [ " assets/maps/ " + baseSourceDir ] . animationData . size ( ) ) ;
std : : string mapPath = " assets/maps/ " + tileset . GetData ( ) . ImageData . data [ " source " ] ;
if ( gamepack . Loaded ( ) ) {
r - > Load ( mapPath , & gamepack ) ;
@ -1959,7 +1960,7 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
gamepack . AddFile ( mapPath ) ;
}
} else {
std : : cout < < " WARNING! " < < mapPath < < " does not exist, auto-generating mock-up texture " < < std : : endl ;
LOG ( " WARNING! " < < mapPath < < " does not exist, auto-generating mock-up texture " ) ;
r - > Create ( tileset . GetData ( ) . imagewidth , tileset . GetData ( ) . imageheight ) ;
SetDrawTarget ( r - > Sprite ( ) ) ;
int tileXCount = tileset . GetData ( ) . imagewidth / tileset . GetData ( ) . tilewidth ;
@ -2001,7 +2002,7 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
}
if ( MAP_DATA [ map ] . MapData . optimized ) {
std : : cout < < " Generating optimized map for Map " < < map < < std : : endl ;
LOG ( " Generating optimized map for Map " < < map ) ;
MAP_DATA [ map ] . optimizedTile = NEW Renderable ( ) ;
MAP_DATA [ map ] . optimizedTile - > Create ( MAP_DATA [ map ] . MapData . width * MAP_DATA [ map ] . MapData . tilewidth , MAP_DATA [ map ] . MapData . height * MAP_DATA [ map ] . MapData . tileheight ) ;
SetDrawTarget ( MAP_DATA [ map ] . optimizedTile - > Sprite ( ) ) ;
@ -2028,7 +2029,7 @@ void AiL::InitializeLevel(std::string mapFile,MapName map){
SetPixelMode ( prevMode ) ;
MAP_DATA [ map ] . optimizedTile - > Decal ( ) - > Update ( ) ;
SetDrawTarget ( nullptr ) ;
std : : cout < < " Clearing Layer Data... " < < std : : endl ;
LOG ( " Clearing Layer Data... " ) ;
MAP_DATA [ map ] . LayerData . clear ( ) ;
}
}
@ -2695,11 +2696,11 @@ int main()
if ( line . find ( " AiL \\ " ) ! = std : : string : : npos ) {
if ( ! leaked ) {
leaked = true ;
std : : cout < < std : : endl < < std : : endl < < std : : endl < < " Memory leak detected! " < < std : : endl ;
LOG ( std : : endl < < std : : endl < < std : : endl < < " Memory leak detected! " ) ;
}
std : : cout < < line < < std : : endl ;
LOG ( line ) ;
std : : getline ( file , line ) ;
std : : cout < < line < < std : : endl ;
LOG ( line ) ;
}
}
if ( leaked ) ERR ( " " )
@ -2710,6 +2711,14 @@ int main()
return 0 ;
}
# ifndef _DEBUG
# ifdef _WIN32
int CALLBACK WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nCmdShow ) {
main ( ) ;
}
# endif
# endif
datafilestringdata operator " " _s ( const char * key , std : : size_t len ) {
AiL : : OutputDebugInfo ( key , len ) ;
return { DATA , std : : string ( key , len ) } ;
@ -2783,7 +2792,7 @@ void AiL::OutputDebugInfo(const char*key,std::size_t len){
if ( utils : : datafile : : DEBUG_ACCESS_OPTIONS ) {
std : : string k = std : : string ( key ) ;
if ( ! k . starts_with ( " debug_ " ) ) {
std : : cout < < " Reading " < < k < < std : : endl ;
LOG ( " Reading " < < k ) ;
}
}
# endif
@ -3152,7 +3161,7 @@ void AiL::InitializeGraphics(){
for ( auto & val : DATA [ " Images " ] . GetKeys ( ) ) {
std : : string key = val . first ;
std : : string imgFile = DATA [ " Images " ] [ key ] . GetString ( 0 ) ;
std : : cout < < " Loading image " + imgFile + " ... " < < std : : endl ;
LOG ( " Loading image " + imgFile + " ... " ) ;
bool filtering = false ;
bool clamping = false ;
if ( DATA [ " Images " ] [ key ] . GetValueCount ( ) > 1 ) {
@ -3196,11 +3205,11 @@ void AiL::InitializeGraphics(){
}
SetPixelMode ( prevMode ) ;
std : : cout < < " Theme " < < themeName < < " Loaded. " < < std : : endl ;
LOG ( " Theme " < < themeName < < " Loaded. " ) ;
if ( DATA [ " Themes " ] [ themeName ] . HasProperty ( " CustomBack " ) ) {
std : : string backPath = DATA [ " Themes " ] [ themeName ] [ " CustomBack " ] . GetString ( ) ;
std : : cout < < " Custom background detected, Loading " < < backPath < < " ... " < < std : : endl ;
LOG ( " Custom background detected, Loading " < < backPath < < " ... " ) ;
if ( ! GFX . count ( backPath ) ) {
Renderable & background = GFX [ backPath ] ;
LoadResource ( background , " GFX_Prefix " _S + backPath , false , false ) ;
@ -3215,15 +3224,15 @@ void AiL::InitializeGraphics(){
Renderable & image = GFX [ img ] ;
LoadResource ( image , " GFX_Prefix " _S + img ) ;
}
std : : cout < < VisualNovel : : graphicsToLoad . size ( ) < < " images for visual novel engine have been loaded. " < < std : : endl ;
LOG ( VisualNovel : : graphicsToLoad . size ( ) < < " images for visual novel engine have been loaded. " ) ;
SetFontSprite ( " GFX_Prefix " _S + " font.png " , & gamepack , " GENERATE_GAMEPACK " _B ) ;
std : : cout < < " Custom font loaded. " < < std : : endl ;
LOG ( " Custom font loaded. " ) ;
Menu : : themes . SetInitialized ( ) ;
std : : cout < < Menu : : themes . size ( ) < < " themes have been loaded. " < < std : : endl ;
LOG ( Menu : : themes . size ( ) < < " themes have been loaded. " ) ;
GFX . SetInitialized ( ) ;
std : : cout < < GFX . size ( ) < < " images have been loaded. " < < std : : endl ;
LOG ( GFX . size ( ) < < " images have been loaded. " ) ;
}
const Map & AiL : : GetCurrentMap ( ) const {
@ -3273,12 +3282,12 @@ void AiL::ValidateGameStatus(){
monsterCounts [ monsterName ] + + ;
}
}
std : : cout < < " Spawns Report for " < < map < < " : " < < std : : endl ;
LOG ( " Spawns Report for " < < map < < " : " ) ;
for ( auto & [ monster , count ] : monsterCounts ) {
std : : cout < < " \t " < < count < < " x " < < monster < < std : : endl ;
LOG ( " \t " < < count < < " x " < < monster ) ;
}
std : : map < ItemInfo * , long > totalDrops ;
std : : cout < < " Monte Carlo Test: 100000 tries: " < < std : : endl ;
LOG ( " Monte Carlo Test: 100000 tries: " ) ;
for ( int i = 0 ; i < 100000 ; i + + ) {
//Try to kill every single monster and see what drops.
for ( auto & [ monster , count ] : monsterCounts ) {
@ -3292,9 +3301,9 @@ void AiL::ValidateGameStatus(){
}
}
}
std : : cout < < " Average: " < < std : : endl ;
LOG ( " Average: " ) ;
for ( auto & [ itemInfo , count ] : totalDrops ) {
std : : cout < < " \t " < < itemInfo - > Name ( ) < < " x " < < std : : format ( " {:.3} " , count / 100000. ) < < std : : endl ;
LOG ( " \t " < < itemInfo - > Name ( ) < < " x " < < std : : format ( " {:.3} " , count / 100000. ) ) ;
}
}
}
@ -3531,10 +3540,10 @@ void AiL::EndGame(){
discord : : LogLevel : : Debug , [ ] ( discord : : LogLevel level , const char * message ) {
std : : cerr < < " Log( " < < static_cast < uint32_t > ( level ) < < " ): " < < message < < " \n " ;
} ) ;
std : : cout < < " Connected to Discord! " < < std : : endl ;
LOG ( " Connected to Discord! " ) ;
UpdateDiscordStatus ( " Main Menu " , player . get ( ) - > GetClassName ( ) ) ;
} else {
std : : cout < < " Could not connect to Discord. Error Code " < < int ( result ) < < std : : endl ;
LOG ( " Could not connect to Discord. Error Code " < < int ( result ) ) ;
}
return result ;
}
@ -3562,9 +3571,9 @@ void AiL::UpdateDiscordStatus(std::string levelName,std::string className){
}
Discord - > ActivityManager ( ) . UpdateActivity ( newActivity , [ ] ( : : discord : : Result result ) {
if ( result = = : : discord : : Result : : Ok ) {
std : : cout < < " Discord Activity successfully updated! " < < std : : endl ;
LOG ( " Discord Activity successfully updated! " ) ;
} else {
std : : cout < < " Could not update Discord Activity. Error Code " < < int ( result ) < < std : : endl ;
LOG ( " Could not update Discord Activity. Error Code " < < int ( result ) ) ;
}
} ) ;
} else {
@ -3583,7 +3592,7 @@ void AiL::UpdateDiscordStatus(std::string levelName,std::string className){
} else {
if ( Steam_Init ( ) ) {
retry = true ;
std : : cout < < " Steam API Initialized successfully! " < < std : : endl ;
LOG ( " Steam API Initialized successfully! " ) ;
}
}
if ( retry ) {
@ -3597,7 +3606,7 @@ void AiL::InitializePlayerLevelCap(){
player - > levelCap + + ;
}
if ( player - > levelCap < = 1 ) ERR ( " Could not detect level cap properly! " )
std : : cout < < " Level cap detected as " < < int ( player - > levelCap ) < < std : : endl ;
LOG ( " Level cap detected as " < < int ( player - > levelCap ) ) ;
}
void AiL : : ResetGame ( bool changeToMainMenu ) {
@ -3796,7 +3805,7 @@ bool AiL::Steam_Init(){
if ( SteamAPI_Init ( ) ) {
if ( SteamUtils ( ) ! = nullptr ) {
SteamUtils ( ) - > SetWarningMessageHook ( [ ] ( int severity , const char * message ) {
std : : cout < < std : : format ( " STEAM[{}]: {} " , severity , std : : string ( message ) ) < < std : : endl ;
LOG ( std : : format ( " STEAM[{}]: {} " , severity , std : : string ( message ) ) ) ;
} ) ;
if ( steamKeyboardCallbackListener = = nullptr ) {
steamKeyboardCallbackListener = new SteamKeyboardCallbackHandler ( ) ;