17.02.2014, 13:33
Quote:
Using non-threaded queries that let your script wait until data is loaded, or intentionally block the rest of OnFilterScriptInit to be executed by adding a loop that checks for flags to be set from within the callbacks of those queries? Either way, the server will be held back to be started until data has been loaded, which is exactly what I need. |
pawn Code:
new
Cache:players = mysql_query(MySQL, "SELECT COUNT(`id`) FROM `players`")
;
printf("There are %d players", cache_get_row_int(0, 0, MySQL));
cache_delete(players, MySQL);
new
Cache:vehicles = mysql_query(MySQL, "SELECT COUNT(`id`) FROM `vehicles`")
;
printf("There are %d vehicles", cache_get_row_int(0, 0, MySQL));
cache_delete(vehicles, MySQL);
printf("Everything done!");
pawn Code:
new
loadQueriesStatus = 0,
;
//(...)
public OnGameModeInit()
{
inline PHandle() {
printf("There are %d players", cache_get_row_int(0, 0, MySQL));
loadQueriesStatus |= 1;
StartupSequence();
}
mysql_tquery_inline(MySQL, "SELECT 2 + 2 FROM dual", using inline PHandle, "");
inline VHandle() {
printf("There are %d vehicles", cache_get_row_int(0, 0, MySQL));
loadQueriesStatus |= 2;
StartupSequence();
}
mysql_tquery_inline(MySQL, "SELECT 3 + 3 FROM dual", using inline VHandle, "");
printf("Everything done!");
return 1;
}
stock StartupSequence()
{
if(loadQueriesStatus != (1 | 2)) return 0;
printf("Let's do it!");
return 1;
}
So, assuming you have 4 queries taking 1.6s each (gigantic stuff, yeah) it will take:
Unthreaded - 4x1.6 = 6.4s
Threaded - 1.6s
And still you have an option to wait until everything is done before allowing players to join.
#e: note to self, use less word "query"