Spawning Enemies in Groups from Bottom to Top without Lag in Big Levels

maxman

Well-known member
I have no problem when it comes to platformers starting from either left to right or vice versa. It's where you have enemies spawn at the specific X coords before they do. Plus, the direction value in the level is set as both. I've gotten used to platforming since Unelmia. However, when I spawn all entities including types enemy, trap, obstacle, and other stuff without group, if I want to move from bottom to top, the lag starts to happen. The level is already scrollable though. So, I have to use group for limiting how many enemies should spawn in a certain amount of its max value, leaving 4-7 minumum within the group.

Code:
group 7 45
at 0

Even though I have many other non-enemy type entities placed outside of group, there are still so many sounds around coming from them which you can hardly hear anything. Let's say, for example, the ones with sounds are trap type entities. One of them is the spikes. The spikes do play its idle with sound.

What I wanna do is not to have many spawned traps play too many sounds since they override some or other sounds. Plus, when I'm far away from the trap, the trap plays its idle with sound.

Even when I have the level spawn too many existing entities without grouping them, it becomes laggy.

What I'm very confused about is putting the trap type entities in group, as group probably requires you to defeat all the existing ones especially enemies until you finish it. I know I'm not going to attack a trap type entity, but I don't know if having the trap type in group would be necessary or not for certain spawning points, especially you're far away below them until you go near them (within the same range). Should I put all obstacle and trap type ones into groups? If I put them into groups, it would prevent lagging and not override sounds, but I worry about not proceeding to the next group of spawns after.
 
Last edited:
You might need to draw a graph of what you're doing @maxman. I'm afraid I don't really understand from your description. This would also be something to tag @Bloodbane in, since he has experience with vertically scrolling levels with lots of high speed action:


DC
 
@maxman

i would suggest that those trap entities change animation when off screen,
can think of some ways, like them changing model, or them displaying their Idle only when they are a certain range in relation to "x" or trhe player's proximity

or maybe a script related to this:

or have the traps work more like proximity mines,
where at a cartain range they perform a harmless attack that produces the sound, and the real attack on the closer range

or have them act as enemies that react within a range of the player

or you could have a center screen invisible decoration entitiy that plays the sound when its near those traps

@Kratus has some on-scroll scripts that may help if you can understand them
 
there is also this portion of code that NSX had,
it kills any entity that exceds a range,
BIG caveat, this code works on a stage that does not scroll at all,
but it seems that it works in relation to the player´s position


void main(){
int i, dx,dz;
void ent, parent;
int ent_max = openborvariant("ent_max");
for(i=0; i<ent_max; i++){
ent = getentity(i);
if(getentityproperty(ent, "exists")){
parent = getentityproperty(ent, "parent");
if(!parent || getentityproperty(parent, "type")!=openborconstant("TYPE_PLAYER")){
if(getentityproperty(ent, "x")<-500 && getentityproperty(ent, "x")>880)
killentity(ent);

if( getentityproperty(ent, "setlayer")<400
&& getentityproperty(ent, "model")!="aramer"
&& getentityproperty(ent, "model")!="aramerX"
&& getentityproperty(ent, "model")!="aramerX-2"
&& getentityproperty(ent, "model")!="aramerX-3"
&& getentityproperty(ent, "model")!="aramerX-7"
&& getentityproperty(ent, "model")!="aramerX-10"
&& (getentityproperty(ent, "type")==openborconstant("TYPE_ENEMY") ||
getentityproperty(ent, "type")==openborconstant("TYPE_PLAYER") ||
getentityproperty(ent, "type")==openborconstant("TYPE_OBSTACLE") ||
getentityproperty(ent, "type")==openborconstant("TYPE_NONE") ||
getentityproperty(ent, "aiflag", "blink")==1 ||
getentityproperty(ent, "setlayer")==5)
//&& !(getentityproperty(ent, "type")==openborconstant("TYPE_PLAYER") &&(getentityproperty(ent, "animationid")==openborconstant("ANI_SPAWN") || getentityproperty(ent, "animationid")==openborconstant("ANI_RESPAWN")))
){
if(0==getentityproperty(ent, "base")){
if( getentityproperty(ent, "a")<10 ){
if(getentityproperty(ent, "health")>0) {damageentity(ent, ent, 10000, 1, openborconstant("ATK_NORMAL5")); }
changeentityproperty(ent, "velocity", -3.5, 0, 0);
changeentityproperty(ent, "subject_to_wall", 0);
changeentityproperty(ent, "no_adjust_base", 1);
changeentityproperty(ent, "subject_to_screen", 0);
changeentityproperty(ent, "setlayer", -2);
changeentityproperty(ent, "position", getentityproperty(ent, "x"), getentityproperty(ent, "z"), 0);
}else if( getentityproperty(ent, "a")<50){
bindentity(ent, NULL());
if(getentityproperty(ent, "x")<399 && getentityproperty(ent, "x")>356){
changeentityproperty(ent, "position", 420, getentityproperty(ent, "z"), getentityproperty(ent, "a"));
}
}
}else if(getentityproperty(ent, "dead") && 0==checkwall(getentityproperty(ent, "x")-100, getentityproperty(ent, "z")) ){
changeentityproperty(ent, "base", 0);
changeentityproperty(ent, "no_adjust_base", 1);
}
}
}
}
}

}


maybe it can be modified to change the animations of those traps instead of killing them.

you have to put this code in the level .txt as
updatescript data/scripts/offscreenpixels death.c

apologize for the spoiler mess...

@Kratus - not sure, but i think you have posted code that somehow highlights stuff in red, how do you do it (if you have done it)
 
Last edited:
@maxman - Did you try with noscroll position script? I'm not sure if that's a fix but I remember having to use it in DOOM so I could have exploding barrels everywhere and it didn't matter if the player destroyed them or not. SO I am thinking part of the script or a side affect is that it prevents any group stuff affecting obstacles and it's why I was told to use it.
 
You might need to draw a graph of what you're doing @maxman. I'm afraid I don't really understand from your description. This would also be something to tag @Bloodbane in, since he has experience with vertically scrolling levels with lots of high speed action:


DC
I originally thought about adding the graph, but I forgot about it. But there has probably over 100-200 spawned entities in the level, kind of too many due to lag, but I haven't counted them all except enemies.

I've told you before maxman in other thread that it's best to use scripted camera and remove any enemies and traps left behind or below.
Well. This thread is about maintaining enemies spawning from bottom to top or vice versa, but in a similar fashion to Unelmia which you scroll from left to right. However, you're right about it where I did mention the problem with the lag in my other thread, but it's for enemies and traps detecting players' range, which I kinda figured out. For the scripted camera, I decided I'm not gonna use it, but I'm gonna minimize a number of enemies and obstacles into groups for preventing the lag and hitting them to proceed. Plus, I find that changing the "position" entity property helps spawn entities better for that level. I'll save it for another mod or another level whenever there's time. Let's leave all enemies to exist for us to defeat before the boss in the bottom-to-top side-scrolling level because you have a choice whether you go to the checkpoint or not. If you avoid any checkpoints, you will have to start all over again. But fortunately, I do have a better plan upon meeting the boss after defeating all enemies for this. The good thing is that I set group 1 1 for the boss to appear after defeating all enemies.

I get the range part thanks to you and @oldyz. I will start changing the range distance of the trap depending on how far away the player is, and make it act like it's not active. Sorry for making this thread about this.
 
@maxman
if you manage to create a "range" script, to lessen the load i would suggest that after a certain range (lets say, a 100 pixel buffer in all 4 offscreen directions), you force those traps to change to a model that uses 2 to 4 frames at most, with a 1 pixel png for frames, no sound, within a certain range their model changes to the normal traps.

(crossing fingers you can pull it off, the aplications of such range scripts can also help with other issues related to avoidance or wander AI)

but would that be enough to lessen the load?

bloodbane is right, maybe some level planning is in order, and you must get rid of some stuff and re-spawn it again when needed - going to be one heck of re-calculating, so you can re-spawn traps and deco things when going back to some areas.

the other option is to force Openbor to act like a poly 3D engine , where things that are not on screen are culled and only loaded again when needed, that is something that i can only guess is probably, maybe going to be somewhat related to methods/techniques used to store weapons and such to carry things from one level to the next....
 
Back
Top Bottom