forward SaveHousesFunction(); public SaveHousesFunction() { //Creates a loop, that goes through all of the files. for(new idx = 1; idx < sizeof(HouseInfo); idx++) //Loops through the houses. { if(!HouseInfo[idx][hLevel]) // If the house level is 0 this means it doesn't exist. (house must have level) { print("Houses saved successfully."); // If look broke we found all existed houses. break;//Breaks the loop if the price is 0(Meaning it doesn't exist) } SaveHouses(idx); // going to another function that saves houses by y_ini into specific house file. } return 1; }
stock LoadHouses() { new string[256]; //Creates a loop, that goes through all of the files. for(new idx = 1; idx < sizeof(HouseInfo); idx++) { format(string, sizeof(string), hPATH, idx);//formats the file path, with the house ID INI_ParseFile(string, "loadhouse_%s", .bExtra = true, .extra = idx ); HouseInfo[idx][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ], 0); if(!strcmp("The State", HouseInfo[idx][hOwner])) format(string, sizeof(string), "{00BC2E}[House]{FFFFFF}\n{00BC2E}Owner{FFFFFF}: %s\n{00BC2E}Type{FFFFFF}: %s\n{00BC2E}Status{FFFFFF}: For Sale\n{00BC2E}Price{FFFFFF}: $%d", HouseInfo[idx][hOwner], HT(idx), HouseInfo[idx][hPrice]); else format(string, sizeof(string), "{00BC2E}[House]{FFFFFF}\n{00BC2E}Owner{FFFFFF}: %s\n{00BC2E}Type{FFFFFF}: %s\n{00BC2E}Status{FFFFFF}: %s", HouseInfo[idx][hOwner], HT(idx), RHS(idx)); HouseInfo[idx][hText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, HouseInfo[idx][hX], HouseInfo[idx][hY], HouseInfo[idx][hZ]+0.3, 20, INVALID_PLAYER_ID, INVALID_VEHICLE_ID); if(HouseInfo[idx][hLevel]) { HouseInfo[idx][hOwned] = 1; } } return 1; }
#define HPATH "Houses/%d.ini", or .file, or .txt etc
HouseDataPath(houseid)
{
new pathname[10+3+1]; //15 coz 11 for the text ones including and 3 for the number one and a null
format(pathname, sizeof pathname, HPATH, houseid);
return pathname;
}
for(new houseid; house < MAX_HOUSES; houseid++)
{
if(fexist(HouseDataPath(houseid))
{
//Your code here
}
}
QueryHouseData(houseid, type)
{
switch(type)
{
case CLEAR_HOUSEDATA:
{
//code here
}
case CREATE_HOUSEDATA:
{
//code here
}
case SAVE_HOUSEDATA:
{
//code here
}
case UPDATE_HOUSEDATA:
{
//code here
}
case LOAD_HOUSEDATA:
{
INI_ParseFile(LoginPath(playerid), "LoadHouse_%s", .bExtra = true, .extra = houseid);
QueryHouseData(houseid, BUFFER_HOUSEDATA);
}
case BUFFER_HOUSEDATA:
{
//code here
}
}
return 1;
}
enum{
CLEAR_HOUSEDATA, CREATE_HOUSEDATA, SAVE_HOUSEDATA, UPDATE_HOUSEDATA, LOAD_HOUSEDATA
}
File based systems are inefficient no matter how you look at it. Even though classic HDDs are being replaced in favor of SSDs, they're still the slowest part in the system. RAM is at least ten times faster to access.
You need to ask yourself whether it is necessary to rewrite the entire file. If nothing has changed, then why bother? I believe it's better to do updates on an "as needed" basis. |
The compiling is that long because pawncc (aka Pawn Compiler) has to compile your script, look for errors, and then giving the answer to you. It takes time, even if you had a Cluster of Computers (I think this is the name.. idk).
|
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase Header size: 38056 bytes Code size: 6014220 bytes Data size: 22585444 bytes Stack/heap size: 16384 bytes; estimated max. usage: unknown, due to recursion Total requirements:28654104 bytes