0 registered members (),
1,459
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Arrows with too much memory
#461543
08/10/16 08:23
08/10/16 08:23
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
I set it up in my game so that an ogre can shoot arrows toward the player using a long bow in its possession. So far, I did not give a limit to the number of arrows that the ogre has on hand, and it just shoots an unlimited amount of arrows toward the player (I will change this for realism in the future). I also set it up so that the .mdl models serving as the arrows that get shot by the ogre, ricochet against hard walls (in the event of missing the player), and fall on the ground (staying visible), so that the player can choose to pick up the arrows and add to its inventory, if need be. However, I notice that after a little while of the ogre shooting unlimited arrows toward the player, and missing (missed arrows falling on ground), the game starts to get really slow and choppy. I assume this happens because the more .mdl model arrows that get shot and fall on the ground while staying visible for the player to pick up if she/he so chooses, the more memory that takes up. Each .mdl arrow model is 372 KB. Here is my code making this happen:
action shootArrowEnemy()
{
...
while(1)
{
...
if (you == player) // arrow hit player?
{
snd_play ( sndExplo, 100, 0 );
ent_remove(me);
return;
}
else // arrow missed player
{
vec_to_angle(my.pan,bounce); // and bounce off any
// obstacles
}
...
wait(1);
}
}
action ogre_archer()
{
...
vec_set(temp, hero.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan, temp); // turn the enemy towards the
// player
my.ANIMATION += 3*time_step;
ent_animate(me,"bowShoot",my.ANIMATION,ANM_CYCLE);
if (my.ANIMATION > 100)
{ // shoot the bow
ent_create("arrow.mdl",vec_for_vertex(v, me,
164),shootArrowEnemy);
snd_play ( sndShootArrow, 100, 0 );
my.ANIMATION -= 100; // continue the cycle from the
// beginning
}
...
}
Is there a way to make the fallen (missed) and visible arrows (that the player can pick up) to have a smaller memory footprint, so that the game does not slow to a crawl and crash, after so many arrows are fired and fallen to the ground?
Last edited by Ruben; 08/10/16 08:59.
|
|
|
Re: Arrows with too much memory
[Re: Superku]
#461545
08/10/16 10:01
08/10/16 10:01
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Is there a way to make the fallen (missed) and visible arrows (that the player can pick up) to have a smaller memory footprint, so that the game does not slow to a crawl and crash, after so many arrows are fired and fallen to the ground? , yes but be sure that the action of arrow is not running anymore (break; in the loop) cause you can have a max 1000 functions running at the same time iirc. With how many arrows does the project get really slow? Fps wise: make sure the arrow does not have to many polygons, low textures and disable its shadow if using a heavy shadow system like stencil_shadows(!). Also in many games arrows and such are removed after some time, you could add that too (like after 1-2 minutes). Another thing which is connected to the max 1000 functions, iirc many functions running can also slow down the game.
Last edited by Reconnoiter; 08/10/16 10:02.
|
|
|
Re: Arrows with too much memory
[Re: Reconnoiter]
#461565
08/11/16 10:56
08/11/16 10:56
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
The more arrows that get shot, the more steadily progressing the slowness and choppiness becomes. It gets so bad that every little slight move with my mouse (which moves the camera) gives this weird zoom in/out effect toward the player, to the point where the camera just zooms away from the player and the world environment that the player is in altogether, and flies infinitely into the blue void. This happened after the ogre shot 55 missed arrows.
By the way Reconnoiter, I have been trying to find a good function or method that can measure time, such as waiting 1 to 2 minutes before removing an arrow. I looked into the timer() and dtimer() functions, but they seem really awkward to use. They seem more geared for testing something, rather than using them in game use. Are one of those functions what you would use to measure 1-2 minutes, or some other function?
Last edited by Ruben; 08/11/16 11:14.
|
|
|
Re: Arrows with too much memory
[Re: Ruben]
#461571
08/11/16 13:01
08/11/16 13:01
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
Serious User
|
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Great By the way Reconnoiter, I have been trying to find a good function or method that can measure time, such as waiting 1 to 2 minutes before removing an arrow. I looked into the timer() and dtimer() functions, but they seem really awkward to use. They seem more geared for testing something, rather than using them in game use. Are one of those functions what you would use to measure 1-2 minutes, or some other function? , I personally never used timer(). What I do is either use a global var, a local var or just a wait();. Depends on the task. In your case I would do something like this:
...
var lifetime = 120; //in seconds
while(1) //your while function of the arrow
{
lifetime -= time_step / 16; //always subtract 1 per second
if (lifetime <= 0) break;
...
wait(1);
}
|
|
|
Re: Arrows with too much memory
[Re: Ruben]
#461575
08/11/16 18:46
08/11/16 18:46
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
that is a bad approach , that is a loop per arrow .
use one main loop that removes one arrow every n-seconds/ticks/frame from a list/array which you use to manage your arrow storage/reference .
eg .
if ( current_time >= remove_arrow_time) { if (myarrowlist.itemscount>0) { myarrowlist.remove(0);//remove first item in list } }
or better yet is to use a frame count instead of time
.
Compulsive compiler
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|