6 Replies - 278 Views - Last Post: 17 March 2012 - 05:06 PM Rate Topic: -----

#1 Air Legend  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 101
  • Joined: 28-November 11

Game Engine - Memory Issue

Posted 17 March 2012 - 03:50 PM

I am making a Java game engine and am writing the api currently. How can I lower the amount of memory needed to run the game? For example, currently I have a timer for each animation that must run. Yes the timer is canceled when it is no longer in use but if I run like 25 animations simultaniously my memory usage is around 800,000 kb (which is kinda a lot :P) The best answer you guys can probably give me is to "tighten up the code." Meaning only initialize variables when they are in use, limit threads, etc. but I was just wondering if anyone had any further suggestions. Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Game Engine - Memory Issue

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5469
  • View blog
  • Posts: 11,749
  • Joined: 02-June 10

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 04:36 PM

A timer shouldn't be consuming any memory, running or not.
So you're doing something in the animation that is causing it. Creating objects that aren't being disposed of for example.
Then again, that might just be the need of your game depending on the number of objects, bitmaps in use and so on.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,533
  • Joined: 29-July 11

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 04:36 PM

Why do you need 25 different timer objects? Why not just add all of them to a single timer?
Was This Post Helpful? 1
  • +
  • -

#4 Air Legend  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 101
  • Joined: 28-November 11

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 04:43 PM

Actually, I didn't realize timers were so lightweight. You are right. The main operation the timers perform is the following:
(first images are changed at a fixed, specified rate, and then this is called to display the update)
JPanel panel = client.getMainPanel();

		Graphics2D buffer;
		Graphics2D g = (Graphics2D) panel.getGraphics();

		Image offscreen;

		offscreen = panel.createImage(panel.getWidth(), panel.getHeight());
		buffer = (Graphics2D) offscreen.getGraphics();

		buffer.setBackground(panel.getBackground());
		buffer.fillRect(0,0,offscreen.getWidth(null), offscreen.getHeight(null));
		buffer.drawImage(getImage(), getLocX(),getLocY(), null);


		g.drawImage(offscreen,0,0,null);
		g.dispose();
		buffer.dispose();
		Toolkit.getDefaultToolkit().sync();



I've been having so much trouble with double buffering my animations. The above but the sprite can only walk in a certain "rectangle" rather than the whole screen. I strongly dislike coding GUIs and that is part of the reason I took on this project. I have strong knowledge of java but GUIs hurt me...

View Postfarrell2k, on 17 March 2012 - 04:36 PM, said:

Why do you need 25 different timer objects? Why not just add all of them to a single timer?


Creating 25 animations was just to test how much memory consumption my game engine can consume. The reason the can't go on a single timer in the first place is they are all each different independent animations.

This post has been edited by Air Legend: 17 March 2012 - 04:44 PM

Was This Post Helpful? 0
  • +
  • -

#5 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,533
  • Joined: 29-July 11

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 04:51 PM

View PostAir Legend, on 17 March 2012 - 11:43 PM, said:

View Postfarrell2k, on 17 March 2012 - 04:36 PM, said:

Why do you need 25 different timer objects? Why not just add all of them to a single timer?


Creating 25 animations was just to test how much memory consumption my game engine can consume. The reason the can't go on a single timer in the first place is they are all each different independent animations.


All of your animation can go in a single timer just fine. Remember, just because you have all animation in one timer, that doesn't mean you have to animate everything at one time. You could easily animate one object every tick through the loop, and then only animate another every two ticks, or only animate another based upon the state of another object, etc. When you say you have 25 different timers, I picture 25 of javax.util.Timer, which doesn't make much sense to me.
Was This Post Helpful? 0
  • +
  • -

#6 Air Legend  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 101
  • Joined: 28-November 11

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 04:55 PM

View Postfarrell2k, on 17 March 2012 - 04:51 PM, said:

View PostAir Legend, on 17 March 2012 - 11:43 PM, said:

View Postfarrell2k, on 17 March 2012 - 04:36 PM, said:

Why do you need 25 different timer objects? Why not just add all of them to a single timer?


Creating 25 animations was just to test how much memory consumption my game engine can consume. The reason the can't go on a single timer in the first place is they are all each different independent animations.


All of your animation can go in a single timer just fine. Remember, just because you have all animation in one timer, that doesn't mean you have to animate everything at one time. You could easily animate one object every tick through the loop, and then only animate another every two ticks, or only animate another based upon the state of another object, etc. When you say you have 25 different timers, I picture 25 of javax.util.Timer, which doesn't make much sense to me.



Quote

Remember, just because you have all animation in one timer, that doesn't mean you have to animate everything at one time.

Because it is a game engine, I would like to be able to run simultaneous animations. The purpose of setting up 20 animations running at once is to see how much memory is needed if the user of the engine desires to have multiple animations running.


Quote

You could easily animate one object every tick through the loop, and then only animate another every two ticks, or only animate another based upon the state of another object, etc.


I'm slightly confused what you mean by this but I think you are referring to your previous statement, correct?

Quote

When you say you have 25 different timers, I picture 25 of javax.util.Timer, which doesn't make much sense to me.


I can see why you picture 25 declarations of a timer haha, I did not mean that. Again, it is a game engine so I have an Animation class that has one timer but that class is referenced each time an animation has to run.

This post has been edited by Air Legend: 17 March 2012 - 04:57 PM

Was This Post Helpful? 0
  • +
  • -

#7 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,533
  • Joined: 29-July 11

Re: Game Engine - Memory Issue

Posted 17 March 2012 - 05:06 PM

It's too difficult to discern exactly what is happening without code. I know I would enjoy looking at it, and I am sure so would others. Maybe one of us could find a more efficient way of doing what you're doing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1