This site requires JavaScript, please enable it in your browser!
Greenfoot back
Gazzzah
Gazzzah wrote ...

2012/2/26

Combating lag

Gazzzah Gazzzah

2012/2/26

#
It seems to be that detailed scenarios I write up are a bit demanding on the computer. I get lag spikes and on certain computers it just runs slowly. It's interesting, with something like Call of Duty or even Minecraft running smoothly, you wouldn't expect a greenfoot scenario to cause lag. I can't find a pattern in the lag spikes. What causes a scenario to be difficult to run? How can I solve these problems. I know for a fact that I can run minecraft (also Java) on full graphic settings with no lag. Maybe is there a limit on assigned RAM? I don't know, answers would be helpful.
Duta Duta

2012/2/26

#
First off, commercial games are coded to be incredibly efficient, however as I don't know how detailed your scenario's are, I don't know if just-too-much-happening is the problem, or, as you say, a limit on assigned RAM. If you export your scenario to a .jar file, there is a method to give it more RAM: Open up notepad, and type in the following - @echo off java -Xmx1024m -jar "<JarFilePath>" and save it as "<AName>.bat" Obviously <AName> can be anything, but I reccomend something like "Run_<YourProgramName>.bat" replace <JarFilePath> with the link to your program. if it is in the same directory as where this will be saved, then just do YourJarName.jar - however if not, you do C:\Users\YourName\...\YourJarName.jar (except obviously change it to the real path to your jar file). What -Xmx1024m is doing is setting the maximum heap size for your program (in this case 1024mb, or 1gb). You can change it to whatever memory you need for your program. If you change it to -Xms1024m then its setting the starting heap size. Other than saying there's a problem with Greenfoot or some huge inefficiency in your code, that's all I can suggest
Gazzzah Gazzzah

2012/2/27

#
I don't know if it helps your understanding at all but the scenario itself is 2.7mb in memory. Ok, I'll try the increase RAM thing. Aside from that are there any tips or anything I can generally do to achieve efficiency in my scenario?
Duta Duta

2012/2/27

#
Upload your scenario and when I get back from college (I'm leaving in half an hour) I'll look over it and see what's up
Gazzzah Gazzzah

2012/2/28

#
Sorry I didn't get that earlier, I'll upload it now. But I should probably just warn you, it's not documented. I'm pretty new to programming so this is like an experimental before I document and complete the finished product. Edit: Actually, change of plan, I'm a little cautious about publishing it right now. It is yet to be finished and I don't really want the source code to be public now anyway. I'll send you a private message with a link off my dropbox so you can download it. Edit: Awkward :S Seems you can't send messages on greenfoot.org. Never mind then here's the link.
Gazzzah Gazzzah

2012/2/28

#
PS: Press "R" to spawn
Gazzzah Gazzzah

2012/2/28

#
PSS: also, WASD to move, left click to attack, right click to block
Duta Duta

2012/2/28

#
I'm currently at college so can't access dropbox - if you upload it to the gallery (you can delete it once I've downloaded it) then I'll check it sooner, else I'll look over it when I get home.
Gazzzah Gazzzah

2012/2/28

#
Ok I'll upload it to greenfoot.org then
Gazzzah Gazzzah

2012/2/28

#
Here it is! Let me know once you have it and I'll take it down. There are no inbuilt instructions, so just keep in mind: "R" to spawn/respawn, WASD to move, left and right click to attack and block.
Duta Duta

2012/2/28

#
Sorry I couldn't get on at college later in the day, but I've just got home so I'm downloading it now (so you can take it down) Will post again soon when I've had time to look at it EDIT: Before I say anything more, I've got to say that I love the game - both the physics and the fact that you've conquered good graphics and sound (something that I'm always too lazy to do, even on my scenario's that I don't upload). Well, that and the lightsaber - it takes me back :). That aside, I haven't experienced any lag whatsoever yet - can I ask two questions? The first being where are you experiencing lag? (All the time/past a certain number of enemies/when attacking/etc) The second question is what speed processor do you have? I'm on a 3.0 GHz Intel Core i5 (with 6 GB RAM), and its running perfectly. I'll check these forums again in about 40 minutes, I've got to make a start on an essay that's due.
Builderboy2005 Builderboy2005

2012/2/28

#
I myself get no lag or slowdown at all on that scenario, and I am running on a not-so-recent laptop. It's also good to keep in mind that games like Minecraft and Call Of Duty use the graphics card almost exclusively for their graphics, which is the reason they can be run so quickly. Greenfoot on the other hand uses pure java, without any graphics card interfaces. This means the CPU itself is forced to do all the drawing and calculating for your games, instead of the graphics card. If this wasn't slow enough, Java itself is being run through a virtual machine, which slows down all code a significant amount.
Gazzzah Gazzzah

2012/2/28

#
I'm glad you like it Duta :) Ahh, thanks Builderboy, that makes a bit more sense. It still seems kind of odd though, such a massive game can work fine, and then my little scenario puts on the pressure :S I encounter it in occasional spikes. It's not really a serious issue and I figured I could ignore it, but I showed a friend and he was complaining, so I figured it would be good to address it. I made a video a short while ago to show some friends. While keeping in mind that this was while recording with fraps, it does show a couple of the "spikes" that I am referring to. They occur at 1:28 and 3:23. It's interesting though, because in the first one there is not much going on, in the second one there is and it was already lagging a bit (due to fraps), it seems quite random. Sometimes when playing on the exported scenario I would get it 3 times under wave 15 (a rough estimate of the waves). I have an Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz and 4GB of RAM. I have a limited understanding of the hardware stuff so I'll just leave it for you to interpret.
Gazzzah Gazzzah

2012/2/28

#
The only pattern I can notice in the spikes is that it seems to be when objects interact with each other, most of the time it works fine but sometimes just randomly when a projectile hits an enemy, something blows up, I swing the sabre etc.
You need to login to post a reply.