Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (blaurock), 750 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Arrows with too much memory #461543
08/10/16 08:23
08/10/16 08:23
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline 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:

Code:
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: Ruben] #461544
08/10/16 09:12
08/10/16 09:12
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
mdls and entities are not the same (as you are aware). You load the file once and entities who use that arrow.mdl only "link" to it. Each new entity takes about 3-4KB of memory if I'm not mistaken, unless you (ent_)clone it (and some other stuff like c_updatehull consume more memory I guess).
Your problem probably lies somewhere else. Debug your code, check the statistics panel, not just the FPS. I bet the number of concurrent functions/ actions rises constantly, or maybe the performance impact comes (to some extent) from rendering more stuff (and/ or c_trace with USE_BOX and a bunch of arrows lying on the ground (which you can speed up with c_ignore)).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
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 Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Quote:
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 Offline OP
User
Ruben  Offline 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] #461567
08/11/16 11:39
08/11/16 11:39
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Reconnoiter! I set it up so that if the my.GRAVITY_VAR of the individual arrow in question goes lower than -200 (since its my.GRAVITY_VAR rapidly decrements when falling), to "break" the function. I used that, and got the ogre to fire 55+ arrows at me. The game does not seem to be getting noticeably slower or more choppy. Thank you again! :-)

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 Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Great

Originally Posted By: Ruben
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:

Code:
...
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: Reconnoiter] #461572
08/11/16 14:26
08/11/16 14:26
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Reconnoiter. I will probably find a good use for that timing method later in the game.

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
W
Wjbender Offline
User
Wjbender  Offline
User
W

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

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1