Author Topic: Optimization Question  (Read 2936 times)

chuk2bp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 13
    • View Profile
Optimization Question
« on: February 02, 2014, 11:14:19 PM »
Hey Michael,

Just a quick question here on optimization. Were building out a tower defense game and planning on doing creeps in 2D so thought I'd go ahead and just utilize nGUI for them as well. In an effort to save pixel space so we can keep atlas sizing down (to maximize animation potential), we were planning on trimming transparency from enemy sprites as much as possible.

Obviously this means there is no consistency in Sprite Size... so my question is, if I utilize the UISprite's MakePixelPerfect() method for each creep on each update function what kind of impact can I expect on performance? Obviously only having a few creeps on the screen would not be much of an issue, but I'm thinking if a 100 were on screen (which is not unheard of for a TD game) there might be issues. Would you recommend taking the hit on pixel space and just standardize sprite dimensions instead?

Thanks for the advice/insight ahead of time!

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Optimization Question
« Reply #1 on: February 03, 2014, 05:46:27 AM »
Hi,

I wouldn't use NGUI for gameplay purpose, it is an UI framework.

Why don't you use the built in 2D support in unity ? if you don't have Unity pro for the automatic Atlas Backing, just build your own atlas to make batching possible.

100 units on the screen is not a lot. Targeting and Pathfinding will have to be optimized otherwise.

Just use NGUI for the UI of your game.

Ps : I'm a dev of Arcane's Tower defense : http://www.youtube.com/watch?v=9jNaK2P1WL0
Graphicstream Dev.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Optimization Question
« Reply #2 on: February 04, 2014, 02:14:29 AM »
If you're already swapping out a sprite, changing its dimensions by calling MakePixelPerfect won't make any difference. But as Cripple said, although you certainly can use NGUI for 2D, it was originally meant as a GUI framework.

In Starlink, I actually used raw GL calls to draw the stars, paths between stars, auras, and effects.

chuk2bp

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 13
    • View Profile
Re: Optimization Question
« Reply #3 on: February 09, 2014, 11:42:45 PM »
Sorry about the delayed response here guys-- but just wanted to voice my appreciation for the responses.

Cripple, its great to have the opportunity to talk with another TD Dev. I'm certainly happy and willing to have your advice as far as 2D implementation for Creeps go.

We don't have a pro license for Unity (yet), so at the moment I'd have to build my own atlases. Though, it seems sensible to me to just utilize nGui's Atlas Maker to do this easily and quickly right from Unity. However, past that, if you think performance would be improved by utilizing unity's 2D capabilities I'd certainly love to have some insight into your own process!

As for pathfinding and targeting, I'll be building those ground up myself. I've picked up a pretty good pool manager so I expect optimization to be fairly manageable. If you'd like/be willing to carry on this conversation outside of the forums here feel free to email me. Thanks in advance for the help! And thanks for the response as well Michael.   

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: Optimization Question
« Reply #4 on: February 10, 2014, 04:18:42 AM »
If you need a good pathfinder, use this one : http://arongranberg.com/astar/features#
It is well documented, open source and the free version features are fine for your needs (you have to use the grid graph).

PoolManager will be only useful for memory optimization, to avoid garbage collection, it is a must have however :)

If you use Unity-2D, juste pack the textures of your objects in the same big texture, and create the sprites that you need using this same big texture. You can use the NGUI atlas maker to create this texture for you!

For the targeting, split the update over frames, don't do it for all towers at the same time, put the enemies into Octree. There are a lot of possible optimization right there. For me I use Physics to detect when an enemy enters or leaves the area of my towers, I save it in a list and I do precise targeting only for those items.

And for the GUI of the game, of course use NGUI :p
« Last Edit: February 10, 2014, 04:25:17 AM by Cripple »
Graphicstream Dev.