@@ -201,6 +201,10 @@ int main(int argc, char *argv[])
201201 pcAppName = argv[i + 1 ];
202202 i++;
203203 }
204+ else if (strcmp (argv[i], " -hr" ) == 0 || strcmp (argv[i], " --hot-reload" ) == 0 )
205+ {
206+ gbHotReloadActive = true ;
207+ }
204208 else if (strcmp (argv[i], " --version" ) == 0 )
205209 {
206210 printf (" \n Pilot Light - light weight game engine\n\n " );
@@ -257,6 +261,8 @@ int main(int argc, char *argv[])
257261 printf (" --apis %s\n " , " Displays embedded apis." );
258262 printf (" -a <app> %s\n " , " Sets app to load. Default is 'editor'." );
259263 printf (" --app <app> %s\n " , " Sets app to load. Default is 'editor'." );
264+ printf (" -hr %s\n " , " Activates hot reloading." );
265+ printf (" --hot-reload %s\n " , " Activates hot reloading." );
260266 return 0 ;
261267 }
262268 }
@@ -448,7 +454,7 @@ int main(int argc, char *argv[])
448454 glfwPollEvents ();
449455
450456 // reload library
451- if (ptLibraryApi->has_changed (gptAppLibrary))
457+ if (gbHotReloadActive && ptLibraryApi->has_changed (gptAppLibrary))
452458 {
453459 pl_reload_library (gptAppLibrary);
454460 #ifdef _WIN32
@@ -1111,15 +1117,18 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11111117 if (*pptLibraryOut == NULL )
11121118 {
11131119
1114- DWORD dwAttrib = GetFileAttributes (pcCacheDirectory);
1115-
1116- if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY ))
1117- {
1118- // do nothing
1119- }
1120- else
1120+ if (gbHotReloadActive)
11211121 {
1122- CreateDirectoryA (pcCacheDirectory, NULL );
1122+ DWORD dwAttrib = GetFileAttributes (pcCacheDirectory);
1123+
1124+ if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY ))
1125+ {
1126+ // do nothing
1127+ }
1128+ else
1129+ {
1130+ CreateDirectoryA (pcCacheDirectory, NULL );
1131+ }
11231132 }
11241133
11251134 *pptLibraryOut = (plSharedLibrary*)PL_ALLOC (sizeof (plSharedLibrary));
@@ -1132,13 +1141,17 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11321141 pl_str_get_directory (tDesc.pcName , ptLibrary->acDirectory , PL_MAX_PATH_LENGTH );
11331142
11341143 if (pl_str_get_file_extension (tDesc.pcName , ptLibrary->acFileExtension , 16 ) == NULL )
1135- strncpy (ptLibrary->acFileExtension , gpcLibraryExtension , 16 );
1144+ strncpy (ptLibrary->acFileExtension , " dll " , 16 );
11361145
11371146 pl_sprintf (ptLibrary->acPath , " %s%s.%s" , ptLibrary->acDirectory , ptLibrary->acName , ptLibrary->acFileExtension );
1138- pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1139- pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1147+
1148+ if (gbHotReloadActive)
1149+ {
1150+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1151+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1152+ }
11401153
1141- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1154+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
11421155 {
11431156
11441157 char acTemporaryName[PL_MAX_PATH_LENGTH ] = {0 };
@@ -1164,7 +1177,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11641177 ptLibrary = *pptLibraryOut;
11651178
11661179
1167- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1180+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
11681181 {
11691182
11701183 ptLibrary->bValid = false ;
@@ -1235,10 +1248,13 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
12351248 strncpy (ptLibrary->acFileExtension , gpcLibraryExtension, 16 );
12361249
12371250 pl_sprintf (ptLibrary->acPath , " %s%s.%s" , ptLibrary->acDirectory , ptLibrary->acName , ptLibrary->acFileExtension );
1238- pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1239- pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1251+ if (gbHotReloadActive)
1252+ {
1253+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1254+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1255+ }
12401256
1241- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1257+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
12421258 {
12431259 ptLibrary->tLastWriteTime = pl__get_last_write_time (ptLibrary->acPath );
12441260 ptLibrary->handle = NULL ;
@@ -1254,7 +1270,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
12541270 else
12551271 ptLibrary = *pptLibraryOut;
12561272
1257- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1273+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
12581274 {
12591275 ptLibrary->bValid = false ;
12601276
@@ -1320,10 +1336,13 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
13201336 strncpy (ptLibrary->acFileExtension , gpcLibraryExtension, 16 );
13211337
13221338 pl_sprintf (ptLibrary->acPath , " %s%s.%s" , ptLibrary->acDirectory , ptLibrary->acName , ptLibrary->acFileExtension );
1323- pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1324- pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1339+ if (gbHotReloadActive)
1340+ {
1341+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1342+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1343+ }
13251344
1326- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1345+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
13271346 {
13281347 ptLibrary->tLastWriteTime = pl__get_last_write_time (ptLibrary->acPath );
13291348 ptLibrary->handle = NULL ;
@@ -1339,7 +1358,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
13391358 else
13401359 ptLibrary = *pptLibraryOut;
13411360
1342- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1361+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
13431362 {
13441363 ptLibrary->bValid = false ;
13451364
0 commit comments