@@ -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 }
@@ -281,6 +287,7 @@ int main(int argc, char *argv[])
281287 pl__load_core_apis ();
282288
283289 gptIOCtx = gptIOI->get_io ();
290+ gptIOCtx->bHotReloadActive = gbHotReloadActive;
284291
285292 // clipboard
286293 gptIOCtx->set_clipboard_text_fn = [](void * pUnused, const char * text) { glfwSetClipboardString (nullptr , text); };
@@ -448,7 +455,7 @@ int main(int argc, char *argv[])
448455 glfwPollEvents ();
449456
450457 // reload library
451- if (ptLibraryApi->has_changed (gptAppLibrary))
458+ if (gbHotReloadActive && ptLibraryApi->has_changed (gptAppLibrary))
452459 {
453460 pl_reload_library (gptAppLibrary);
454461 #ifdef _WIN32
@@ -1111,15 +1118,18 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11111118 if (*pptLibraryOut == NULL )
11121119 {
11131120
1114- DWORD dwAttrib = GetFileAttributes (pcCacheDirectory);
1115-
1116- if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY ))
1117- {
1118- // do nothing
1119- }
1120- else
1121+ if (gbHotReloadActive)
11211122 {
1122- CreateDirectoryA (pcCacheDirectory, NULL );
1123+ DWORD dwAttrib = GetFileAttributes (pcCacheDirectory);
1124+
1125+ if (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY ))
1126+ {
1127+ // do nothing
1128+ }
1129+ else
1130+ {
1131+ CreateDirectoryA (pcCacheDirectory, NULL );
1132+ }
11231133 }
11241134
11251135 *pptLibraryOut = (plSharedLibrary*)PL_ALLOC (sizeof (plSharedLibrary));
@@ -1135,10 +1145,14 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11351145 strncpy (ptLibrary->acFileExtension , gpcLibraryExtension, 16 );
11361146
11371147 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 );
1148+
1149+ if (gbHotReloadActive)
1150+ {
1151+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1152+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1153+ }
11401154
1141- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1155+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
11421156 {
11431157
11441158 char acTemporaryName[PL_MAX_PATH_LENGTH ] = {0 };
@@ -1164,7 +1178,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
11641178 ptLibrary = *pptLibraryOut;
11651179
11661180
1167- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1181+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
11681182 {
11691183
11701184 ptLibrary->bValid = false ;
@@ -1235,10 +1249,13 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
12351249 strncpy (ptLibrary->acFileExtension , gpcLibraryExtension, 16 );
12361250
12371251 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 );
1252+ if (gbHotReloadActive)
1253+ {
1254+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1255+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1256+ }
12401257
1241- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1258+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
12421259 {
12431260 ptLibrary->tLastWriteTime = pl__get_last_write_time (ptLibrary->acPath );
12441261 ptLibrary->handle = NULL ;
@@ -1254,7 +1271,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
12541271 else
12551272 ptLibrary = *pptLibraryOut;
12561273
1257- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1274+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
12581275 {
12591276 ptLibrary->bValid = false ;
12601277
@@ -1320,10 +1337,13 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
13201337 strncpy (ptLibrary->acFileExtension , gpcLibraryExtension, 16 );
13211338
13221339 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 );
1340+ if (gbHotReloadActive)
1341+ {
1342+ pl_sprintf (ptLibrary->acLockFile , " %s%s" , ptLibrary->acDirectory , pcLockFile);
1343+ pl_sprintf (ptLibrary->acTransitionalPath , " %s/%s_" , pcCacheDirectory, ptLibrary->acName );
1344+ }
13251345
1326- if (!(tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
1346+ if (!gbHotReloadActive || ! (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE ))
13271347 {
13281348 ptLibrary->tLastWriteTime = pl__get_last_write_time (ptLibrary->acPath );
13291349 ptLibrary->handle = NULL ;
@@ -1339,7 +1359,7 @@ pl_load_library(plLibraryDesc tDesc, plSharedLibrary** pptLibraryOut)
13391359 else
13401360 ptLibrary = *pptLibraryOut;
13411361
1342- if (tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
1362+ if (gbHotReloadActive && tDesc.tFlags & PL_LIBRARY_FLAGS_RELOADABLE )
13431363 {
13441364 ptLibrary->bValid = false ;
13451365
0 commit comments