Game Development Community

Game Optimization

by rennie moffat · in iTorque 2D · 07/23/2010 (5:28 pm) · 45 replies

Ok, So I have my game up in my iDevice, however it is PAINFULLY slow. I thought perhaps my levels, on average were too much data, too many on onUpdates etc. So I built a test level, extremely small, no bigger than a quarter of the screen's size, with my player and the "tiles" the object he uses to move. Tap a tile, player moves to it. However it is still extremely slow.

I would like to use this thread to garner help for game optimization. The only thing that I can think of that perhaps I am doing wrong is loading all my datablocks into one level datablock, the emptyLevel_datablock, but really I don't have much in there. I would not think this would be much of an issue because I thought once a datablock is loaded, it stays, thus, by the time I get to my last level, (assuming a player starts at level 1 and works his/her way up to the last) that all datablocks will have been loaded, and all, due to my understanding that datablocks are not deleted (unless asked) that the game would run as smooth as if they were all just loaded from the beginning. Make sense?


If any one has suggestions to help me optimize this, I would greatly appreciate it.






Help Me Obi Wan, you are my only hope.






Factors in my game are.
1. all images are POT, and have been reduced in memory so that my Images folder is only 300Kb
2. no object in my game uses Torque Physics. I do use "UsePhysics ="1';" however in my levels so objects that need to move can.
3. many objects use onUpdates, but I have built a test level which uses virtually no onUpdates and it still is far to slow.

So the situation for me right now is that my game, loads as,...
1. Default.png
2. EmptyLevel.t2d(acts as a mock loading screen)
3 MainMenuLevel (here I can choose level, start new game, instructions, about)
4. For beta testing I have been "Choosing Level" which take me to level chooseLevel.t2d. Here I can choose any level.
5. I choose any level, my main idle animation is farrrr to slow.
6. I built a test level, a very mini level, that in no way could be strenuous on the machine, if it is, I am f-worded. However on this new level, the animation is better but not optimal, but reactions to movement instructions by the player are ridiculously slow, as in I say move here and it takes the player 30 seconds to react.



Something must be overwhelming the iDevice. It must be my dataBlocks. Perhaps I need to better understand how levels, the game is loaded. A behavior is not added until the relevant level is loaded, correct? Any how I will be working on this today.

Any help, is greatly appreciated.


Thank you
Rennie






About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.

Page «Previous 1 2 3 Last »
#1
07/23/2010 (7:13 pm)
Rennie, starter for 10 - build a debug build on the iDevice - set configuration to debug. Build and run the game. Open the console from xcode - Run->Console - look at what gets printed.

- look for errors
- memory warnings etc
- you should also see a number being printed every second - this is your FPS.

Report back what you see or post a snippet from the log.

Meanwhile ... some things to check in your image datablocks -

- filterPad = "0";
- optimized = "1";
#2
07/23/2010 (7:16 pm)
Oh ok, never thought of running debug on the device.

Thanks Man,




Your perfect score is in tact. expect a check at some point baby.



Cheers!




Also,
Re
- filterPad = "0";
- optimized = "1";

Should all images be set as this?

#3
07/23/2010 (7:25 pm)
Hi Scott,
I checked the console but I did not see anything out of the ordinary.


I am trying to think of what type of echos I should call. Is there a way I check time? as in the speed at which the app is running.
#4
07/23/2010 (7:36 pm)
@rennie

Did you try

function initializeProject()
{
$timeAdvance = 33;
...
}

in the file gamemain.cs

******************************
Off Topic: When you send me those files, I will get them back to you in about an hour. I have today off :)
#5
07/23/2010 (7:45 pm)
Rennie, all POT images should have those flags.
#6
07/23/2010 (7:47 pm)
@scott

Thanks again, I was wondering if you could show the console.

Run->Console
#7
07/23/2010 (8:18 pm)
@Dean,
That seems to have done the trick. What does it do, just speed up the engine?


And thanks!
I will get you those in the next hour. AS long as they are back by Sunday, we are good.


Thanks so much guys!!!!
:::)()(()(((((((((



And @Scott, just to be safe, what did you mean but Flags? Re; POT images.

#8
07/23/2010 (8:58 pm)
Rennie, there is a thread here:

www.torquepowered.com/community/forums/viewthread/79726

To be safe just set filterPad = "0"; and optimised = "1";
#9
07/23/2010 (9:02 pm)
Is that for all images.
Edit. @ Scott. I did change the optimized and filterPad settings and unfortunately it has had no impact.

AND

I have just retested with $gameAdvance set to 33 and 1000 and my game is still painfully slow. It worked with it on the small test level but an average level is still uselessly slow.


Am working through.
Thanks.
#10
07/23/2010 (9:08 pm)
@rennie

Did you try 45, 55, etc... using 1000 might not work properly.

I sent those files back to you.

#11
07/23/2010 (9:37 pm)
@Dean
I tried 33, 55, 77, 100, 333, 1000. All are too slow. Not sure what to do. I know it is having an effect as loading times are much more reactive/accurate. but no where near releasable.


@Scott, and all, going through Marc's Thread you provided
http://www.torquepowered.com/community/forums/viewthread/79726
Quote:
2. State changes are expensive. What this means is that especially many distinct textures will hurt performance.
as I say, if I can interpret a texture as an object, then I may be in for trouble as I have 100's of objects per level.

At the moment I can not think of an alternative solution to replace all my objects. I need them since, for 98% of them they allow my player to move. They are the fundamentals of basic game play.







#12
07/23/2010 (9:56 pm)
@rennie

What about below 33, does it slow down? My game, I have 0.6 I am using scheduled calls and it runs great on all versions of iphones.

One thing I do, on each level data file, I only load the pictures I need.

For each image, the only checks I have are prefer speed, allow unload and optimised.

After the level is unloaded, I delete all objects.


#13
07/23/2010 (10:16 pm)
@Dean
I had run into some problems with my datablocks. Some images were not showing on some levels, however, if I erased level X databock, images that existed in emptyLevel_datablock still appeared in level x. So what I did was load all datablocks into the emptylevel_datablock. Since most levels have pretty much the same I didn't think this would be a huge deal and may infact save loading time since all datablocks were already loaded.


Anyhow, I just removed all level databloacks except emptyLevel_datablock just to see. On the small test level it still seems choppy and on an average level it is still too slow, at least 30 seconds behind schedule it seems.



How do you go about deleting datablocks per level?




Edit:
I have just noticed that my emptyLevel_datablock, with all datablocks has 1800 plus lines of code in it while the average level datablock has 400 or so. Would that effect game play much? anyhow, am checking.



#14
07/23/2010 (11:53 pm)
What I have done before:

Step One
Load the file in a text editor

MyProjects/AirFireRescue/projectFiles/game/managed/datablocks.cs

Step Two
Copy all the lines EXCEPT the first 3 lines

$managedDatablockSet = new SimSet() {
   canSaveDynamicFields = "1";
      setType = "Datablocks";

Step Three
Load the file in a text editor (what ever your text level is)

Level1_datablocks.cs

DELETE all line EXCEPT the first 3 lines

$levelDatablocks = new SimSet() {
   canSaveDynamicFields = "1";
      setType = "Datablocks";

Step Four
Paste the lines that you copied from step two.

Save file.


Notes:
Keep that file as a master file.

Remove any objects that are not being used in the current level. Save the updated file as that current level.
#15
07/23/2010 (11:57 pm)
NOTE: iT2D 1.4 has the ability to remove and edit t2dImageMapDatablock's from the menu. (chain with green plus sign) The documents have instructions how to do this.

How to deleted datablocks. My datablock master file would have level images 1-5. If I was creating Level1_datablocks.cs file

Load my master file (has 5 level images), I only need level1 images for level1.

master file:
$levelDatablocks = new SimSet() {
   canSaveDynamicFields = "1";
      setType = "Datablocks";

   new t2dImageMapDatablock(level1ImageMap) {
      imageName = "~/data/images/level1.png";
      imageMode = "FULL";
      frameCount = "-1";
      filterMode = "NONE";
      filterPad = "0";
      preferPerf = "1";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "0";
      cellHeight = "0";
      preload = "0";
      allowUnload = "1";
      compressPVR = "0";
      optimised = "1";
      force16bit = "0";
   };
   new t2dImageMapDatablock(level2ImageMap) {
      imageName = "~/data/images/level2.png";
      imageMode = "FULL";
      frameCount = "-1";
      filterMode = "NONE";
      filterPad = "0";
      preferPerf = "1";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "0";
      cellHeight = "0";
      preload = "0";
      allowUnload = "1";
      compressPVR = "0";
      optimised = "1";
      force16bit = "0";
   };
   new t2dImageMapDatablock(level3ImageMap) {}
   new t2dImageMapDatablock(level4ImageMap) {}
   new t2dImageMapDatablock(level5ImageMap) {}

... other items ...
}


Delete the t2dImageMapDatablock's level2,level3,level4 and level5.

Save the new file as Level1_datablocks.cs
$levelDatablocks = new SimSet() {
   canSaveDynamicFields = "1";
      setType = "Datablocks";

   new t2dImageMapDatablock(level1ImageMap) {
      imageName = "~/data/images/level1.png";
      imageMode = "FULL";
      frameCount = "-1";
      filterMode = "NONE";
      filterPad = "0";
      preferPerf = "1";
      cellRowOrder = "1";
      cellOffsetX = "0";
      cellOffsetY = "0";
      cellStrideX = "0";
      cellStrideY = "0";
      cellCountX = "-1";
      cellCountY = "-1";
      cellWidth = "0";
      cellHeight = "0";
      preload = "0";
      allowUnload = "1";
      compressPVR = "0";
      optimised = "1";
      force16bit = "0";
   };

... other items ...
}
#16
07/24/2010 (12:11 am)
So your Level1 Datablock is your master file. It contains all datablocks. Correct?

Then for each level datablock you only allow the essentials, what should be there. No extras right?

See, I thought you were deleteing datablocks. So load level 1, level1 datablocks loaded, end level 1, delete level1 datablocks.

:::?? Am I on target with you?





Also, I have been reluctant to finish the game off on iT2D 1.4, but do you think that would make much of a difference?





And thanks.
#17
07/24/2010 (12:24 am)
My master file (datablocksMaster.cs) would have all the datablocks.
This master file is NOT included with the final game.

My level files are:

Level1.t2d
Level2.t2d
Level3.t2d
Level4.t2d
Level5.t2d

My datablocks are:

Level1_datablocks.cs
- only has t2dImageMapDatablock(level1ImageMap)
- Deleted: level2ImageMap,level3ImageMap,level4ImageMap,level5ImageMap

Level2_datablocks.cs
- only has t2dImageMapDatablock(level2ImageMap)
- Deleted: level1ImageMap,level3ImageMap,level4ImageMap,level5ImageMap

Level3_datablocks.cs
- only has t2dImageMapDatablock(level3ImageMap)
- Deleted: level1ImageMap,level2ImageMap,level4ImageMap,level5ImageMap

Level4_datablocks.cs
- only has t2dImageMapDatablock(level4ImageMap)
- Deleted: level1ImageMap,level2ImageMap,level3ImageMap,level5ImageMap

Level5_datablocks.cs
- only has t2dImageMapDatablock(level5ImageMap)
- Deleted: level1ImageMap,level2ImageMap,level3ImageMap,level4ImageMap
#18
07/24/2010 (12:32 am)
I get that, but my understanding from Marc, was that once a datablock is loaded, it is NEVER deleted. What I got from what you were saying was that you deleted datablocks, by some code I figured, so...


if level 1 endLevel()
{
delete level1_datablocks.cs
}



correct me if I am wrong but you are just making sure each level only has the datablock needed, for that level.





Am I right? And I am megauploading now, hopefully it sends.


::)()(
#19
07/24/2010 (12:37 am)
I use the following code on my images.

The preload = don't load until the datablock is loaded/used.
the allowunload = allows me to delete it.

preload = "0";   
  allowUnload = "1";

The delete level1_datablocks.cs won't work.

*****************
my delete code for end of level
*****************

function cleanLevel()
{
	for (%i = 0; %i < $levelDatablocks.getCount(); %i++)
	{
		%datablock = $levelDatablocks.getObject(%i);
		%datablock.delete();
	}
	
  %sceneObjectList = playfield.getSceneObjectList();
   for (%i = 0; %i < getWordCount(%sceneObjectList); %i++)
   {
      %sceneObject = getWord(%sceneObjectList, %i);
      if(isObject(%sceneObject))
         %sceneObject.delete();			 
   }

	return;
}

#20
07/24/2010 (12:40 am)
ok so where would the "cleanLevel function" be placed? how is it called? As in does something like endLevel() need to happen in order for cleanLevel() to happen?



Page «Previous 1 2 3 Last »