Dynamic Objects freezing the server
#1

Hey!

I made a script to loop through .map file and get all the object's coordinates, then createdynamicobject to use these coordinates. But I have a problem that for the amount of time server is creating these objects, you cannot type anything in chat, it seems freezed.. for aprox 20sec's or less on some maps. I'm thinking about creating a timer but i'm not completely sure how to do it so it would load 1k objects and then wait 2 secs and another 1k or something. Thanks for help in advance. There are usually aprox 5k objects to loop through and create afterwards
Reply
#2

SA-MP servers are single threaded, so every action won’t be processed until the previous one has been completed.

So for things like this you’d be better off converting the coordinates once and making them into a constant array in your script or add them to some sort of database or table, to make readability a little easier.
Reply
#3

Quote:
Originally Posted by Threshold
Посмотреть сообщение
SA-MP servers are single threaded, so every action won’t be processed until the previous one has been completed.

So for things like this you’d be better off converting the coordinates once and making them into a constant array in your script or add them to some sort of database or table, to make readability a little easier.
I made enum for it if thats what u meant

#define OBJECTS 30000

enum ObjectData //Object Data
{
id,
model,
FloatosX,
FloatosY,
FloatosZ,
Float:rotX,
Float:rotY,
Float:rotZ
}

new oInfo[OBJECTS][ObjectData];
Reply
#4

Quote:
Originally Posted by NoteND
Посмотреть сообщение
I made enum for it if thats what u meant

#define OBJECTS 30000

enum ObjectData //Object Data
{
id,
model,
FloatosX,
FloatosY,
FloatosZ,
Float:rotX,
Float:rotY,
Float:rotZ
}

new oInfo[OBJECTS][ObjectData];
What he meant is you paste the coordinates in the script
so you'd fill your oInfo with a predefined values like
Код:
// Note, object is just an example
new oInfo[OBJECTS][Objects] = {
	{INVALID_OBJECT_ID, 2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0},
	// ....
};

for (new i = 0; i < OBJECTS; i++)
{
	oInfo[i][model] = CreateDynamicObject(oInfo[i][model], oInfo[i][posX], oInfo[i][posY], oInfo[i][posZ], oInfo[i][rotZ], oInfo[i][rotY], oInfo[i][rotZ]);
}

// or 2nd
oInfo[0][model] = 2976,
oInfo[0][posX] = 1.0,
oInfo[0][posY] = 2.0,
oInfo[0][posZ] = 3.0,
oInfo[0][rotY] = 0.0,
oInfo[0][rotZ] = 0.0,
oInfo[0][rotZ] = 180.0,
oInfo[0][id] = CreateDynamicObject(oInfo[0][model], oInfo[0][posX], oInfo[0][posY], oInfo[0][posZ], oInfo[0][rotZ], oInfo[0][rotY], oInfo[0][rotZ]); // or loop it like 1st way

// or 3rd
oInfo[0][id] = CreateDynamicObject(2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0);
oInfo[0][model] = 2976,
oInfo[0][posX] = 1.0,
oInfo[0][posY] = 2.0,
oInfo[0][posZ] = 3.0,
oInfo[0][rotY] = 0.0,
oInfo[0][rotZ] = 0.0,
oInfo[0][rotZ] = 180.0;
// ...
1st way is preferable

Well forget the second way, even if it's possible that wont be friendly with the coder and the compiler.

Instead of having .map you'd better convert it to CreateDynamicObject ready like using https://convertffs.com/
So you'd just paste the CreateDynamicObject line without having it stored in any variables (unless you want to do it like 3rd way which is the worst)
Код:
CreateDynamicObject(2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0);
Well going too rough off with the topic, you should explain how you actually loop the .map files with
If you are using PAWN to fopen every MTA's .map files and XML Parse, and storing it again to the variables & enums you mentioned above, you'd expect such slowness...


Get your maps manually converted first in a batch, if you want it to load on run time, utilize a database with objects structures, it's actually easy to convert map & store .xml data to .sql, then from PAWN code, use a threaded query for a map (or two and more), create the objects (or store it to your variable first), then process another file, you can schedule this so after creating a map, your system CPU will idle a bit for "some rest", and continue again the next second(s). Decide how many map/cycles to process, it depends on your server's system performance (and the script ofc), since three maps at once could be faster than loading 1 map three times, while loading 6 maps at once is slower (relative to the map size).


Now if you don't care with that all, and just want the map to be created, use ConvertFFS, convert your map, paste your CreateObject, no need variable/enums or database / system that loop files in your pawn script and your overhead will be at compile time.


But to be honest, you need to add more details on what you want to achieve....
Reply
#5

Quote:
Originally Posted by RoboN1X
Посмотреть сообщение
What he meant is you paste the coordinates in the script
so you'd fill your oInfo with a predefined values like
Код:
// Note, object is just an example
new oInfo[OBJECTS][Objects] = {
	{INVALID_OBJECT_ID, 2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0},
	// ....
};

for (new i = 0; i < OBJECTS; i++)
{
	oInfo[i][model] = CreateDynamicObject(oInfo[i][model], oInfo[i][posX], oInfo[i][posY], oInfo[i][posZ], oInfo[i][rotZ], oInfo[i][rotY], oInfo[i][rotZ]);
}

// or 2nd
oInfo[0][model] = 2976,
oInfo[0][posX] = 1.0,
oInfo[0][posY] = 2.0,
oInfo[0][posZ] = 3.0,
oInfo[0][rotY] = 0.0,
oInfo[0][rotZ] = 0.0,
oInfo[0][rotZ] = 180.0,
oInfo[0][id] = CreateDynamicObject(oInfo[0][model], oInfo[0][posX], oInfo[0][posY], oInfo[0][posZ], oInfo[0][rotZ], oInfo[0][rotY], oInfo[0][rotZ]); // or loop it like 1st way

// or 3rd
oInfo[0][id] = CreateDynamicObject(2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0);
oInfo[0][model] = 2976,
oInfo[0][posX] = 1.0,
oInfo[0][posY] = 2.0,
oInfo[0][posZ] = 3.0,
oInfo[0][rotY] = 0.0,
oInfo[0][rotZ] = 0.0,
oInfo[0][rotZ] = 180.0;
// ...
1st way is preferable

Well forget the second way, even if it's possible that wont be friendly with the coder and the compiler.

Instead of having .map you'd better convert it to CreateDynamicObject ready like using https://convertffs.com/
So you'd just paste the CreateDynamicObject line without having it stored in any variables (unless you want to do it like 3rd way which is the worst)
Код:
CreateDynamicObject(2976, 1.0, 2.0, 3.0, 0.0, 0.0, 180.0);
Well going too rough off with the topic, you should explain how you actually loop the .map files with
If you are using PAWN to fopen every MTA's .map files and XML Parse, and storing it again to the variables & enums you mentioned above, you'd expect such slowness...


Get your maps manually converted first in a batch, if you want it to load on run time, utilize a database with objects structures, it's actually easy to convert map & store .xml data to .sql, then from PAWN code, use a threaded query for a map (or two and more), create the objects (or store it to your variable first), then process another file, you can schedule this so after creating a map, your system CPU will idle a bit for "some rest", and continue again the next second(s). Decide how many map/cycles to process, it depends on your server's system performance (and the script ofc), since three maps at once could be faster than loading 1 map three times, while loading 6 maps at once is slower (relative to the map size).


Now if you don't care with that all, and just want the map to be created, use ConvertFFS, convert your map, paste your CreateObject, no need variable/enums or database / system that loop files in your pawn script.


But to be honest, you need to add more details on what you want to achieve....
Thats how I convert my objects, pickups and spawnpoints..
Slowness is only on objects, since I tested only pickups and spawnpoints and they've converted in 0.5sec or less.

https://pastebin.com/j1p4DvVk
Reply
#6

Quote:
Originally Posted by NoteND
Посмотреть сообщение
Thats how I convert my objects, pickups and spawnpoints..
Slowness is only on objects, since I tested only pickups and spawnpoints and they've converted in 0.5sec or less.

https://pastebin.com/j1p4DvVk
Your overhead could be on the XML parsing because the plugin need times to find a tag and the closing tag to fetch the value, it is more complicated than INI. (Note: i have not used that XML plugin)

Also overhead at loading files if that plugin does not support operation on external thread (like MySQL database plugin do with threaded queries) or the repeated operation with open/close the file (which i think Y_INI handle it better)

Even i think that using a CSV format of the map objects and load each line with sscanf would be faster (note: still overhead on finding/opening the file.

Still 30000 objects loading wouldn't take a second, maybe you could optimize it up to only 10 seconds
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)