Ways to optimize gigantic amounts of spawners

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Alfred Don
Posts: 45
Joined: Mon Aug 01, 2022 11:52 am
Contact:

Ways to optimize gigantic amounts of spawners

Post by Alfred Don »

In the mod I'm currently working on, I have 1000+ actors in my map, most of which are spawners for either cars or pedestrians. Over the course of development, the car actors and pedestrian actors became more and more advanced, and the map got bigger and bigger. I initially just limited the range where these objects can spawn in, but then I limited the amount of objects that can be spawned, and their distance to eachother. The problem is, I have basically ran out of ways to squeeze any more performance using this system, as the large amount of spawner actors has started to destroy the performance of the game.

This is my code for the spawner:

Code: Select all

actor TrafficCarSpawner 11801
{
	States
	{
	Spawn:
	stop
	TNT1 A random(10,30) nodelay A_CheckSight("SpawnCar")
	loop
	SpawnCar:
	TNT1 A 1 
	TNT1 A 0 A_CheckProximity("Spawn","TrafficCar",10000, GetCVar("t3_vehicle_density"))
	TNT1 A 0 A_CheckProximity("Spawn","TrafficCar",256)
	TNT1 A 0 A_CheckRange(GetCVar("t3_cull_distance"), "Spawn", True)
	TNT1 A 200 A_SpawnItem("TrafficCar")
	goto Spawn
	}
}
I'm contemplating replacing the large amount of actors with an ACS array, which might improve performance.

EDIT: The function A_CheckSight is rather expensive on processing power and caused all the slowdown here.
Last edited by Alfred Don on Wed Jan 24, 2024 12:18 pm, edited 1 time in total.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Ways to optimize gigantic amounts of spawners

Post by Dan_The_Noob »

does adding extra tics on the checks help at all? I noticed a few mods have a delay at the start of each level for this kind of thing.
User avatar
Alfred Don
Posts: 45
Joined: Mon Aug 01, 2022 11:52 am
Contact:

Re: Ways to optimize gigantic amounts of spawners

Post by Alfred Don »

Dan_The_Noob wrote:
> does adding extra tics on the checks help at all? I noticed a few mods have
> a delay at the start of each level for this kind of thing.

Maybe. I'll see if I can figure out where the overhead lag actually is in the actor, whether it's just constantly checking for player location or if it's actually related to spawning things in. From what I can currently understand, it's just the amount of actors that ruins it.

It also depends on what you actually mean, too.
User avatar
Dan_The_Noob
Posts: 880
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Ways to optimize gigantic amounts of spawners

Post by Dan_The_Noob »

Alfred Don wrote: Sun Aug 06, 2023 6:49 pm Dan_The_Noob wrote:
> does adding extra tics on the checks help at all? I noticed a few mods have
> a delay at the start of each level for this kind of thing.

Maybe. I'll see if I can figure out where the overhead lag actually is in the actor, whether it's just constantly checking for player location or if it's actually related to spawning things in. From what I can currently understand, it's just the amount of actors that ruins it.

It also depends on what you actually mean, too.
just that you have it checking 3 things in 1 tic, depending how many spawners you have it could be building up some lag. but I'm just throwing out possible ideas.
Post Reply

Return to “Scripting”