Alternative Rendering (CLOSE THIS OR DELETE)


(ReiKGT) #1

Skip to the 2nd paragraph for the nitty gritty.

Alright, so I’m making an isometric tactics game and I’ve been occasionally running into performance problems. Because the map is isometric I can’t just load the map as a single bitmap, otherwise units cant be brawn behind the tiles if necessary. I’ve organized my map so that each XY coordinate of tiles is a single entity, with Image graphics constructed from bitmaps on load. This means I’m dealing with 400 entities minimum. As you can imagine, when you add in units, UI, and the top layers for water I can easily get 600-700 entities. Water is especially taxing. It’s not uncommon to drop below 60FPS. I could deal with it but that’s pretty intense for just rendering. Throw in AI functions and general game logic and FPS can drop to 30 for a few frames. That’s enough background.

I devised an alternative method to rendering that I’ve dubbed Isolated Rendering. When the map is loaded I render all of the tiles to a single bitmap and add it as an entity. Then I divide the screen into a grid of 25x25. This grid functions like a primitive quad tree, so I call it a DeviantTree. I calculate each tile’s position in the grid and add it to each and every node it occupies. I then lock the grid. Any units will be given the type “active”. UI elements will be typed as “ui”.

On each frame I bypass the normal rendering method entirely. I render the cached bitmap of tiles to the screen buffer. I then grab all “active” entities and push them into an array. I then loop through this array and retrieve all tiles it can possibly be drawn over and add them both to a render queue. I then loop through this queue and draw the entities to a bitmap the size of the screen called the isolationBuffer. I will then loop through the “active” entities and use a rectangle to clip the relevant pixels from the isolationBuffer and render it to the screen buffer. This means that the relevant entities won’t ever obscure an other entities that they otherwise wouldn’t. I then grab all “ui” entities and render them like flashpunk normally would, but that part isn’t implmented yet.

There are several restrictions this type of rendering imposes. I won’t be able to use flashpunk’s default particle implentation. I guess I could make it so particles are rendered to the buffer during islation… This also means that UI elements will ALWAYS be drawn on top of tiles and active entities. I can live with that. It also means that I’ll need to add some extra logic to GraphicLists to scale the hitbox in a way that all it’s children are inside it.

Isolated rendering was supposed to be faster than the normal method by a ton. I mean it would make sense right? Instead of rendering every single entity every frame, just render what entities can possibly move. After implementing it I discovered that it was in fact faster than flashpunk’s default method, but only in specific cases. I usually drop below 60FPS after about 35 “active” entities. After that point flashpunk’s default is faster.

So I’m at a loss. It’s taken me quite a lot of time getting this all sorted out. I really need some ideas on how to improve Isolated Rendering or another alternative rendering method. I’m at the end of my wits.

I’d like to show you what kind of map I’m dealing with but “new users can’t post images.” The best I can do is post the relevant code. http://pastebin.com/T0KrmGim


(rostok) #2

First of all make sure that this is rendering you want to optimize. AI may be time consuming, and the most frequent way of improving performance here is to either freeze entities that are far away or update their core logic less often (say every two frames). also if possible lower FPS to 30. Sth to compare with: my old unfinished project http://rostok.3e.pl/thebeast/ has like 1.5K entities with 15+ to be actively updated (rest are just props). I haven’t done any special optimization except collisions based on segment vs polygon intersections and quadtree. I did however observer that FPs layer sorting is troublesome. Note that layer has setter that calls method in Entity - therefore I update them only when entity is on screen.


(ReiKGT) #3

Yeah I’m sure it’s rendering. I can sometimes have 800+ entities when you account for UI and the top layers of water. The tiles themselves have no update logic. I’m betting that on average my normal tile size is greater than your 1.5k entities. It doesn’t matter. This topic should be closed.

I give up on AS3. Last night I downloaded Visual Studio 2010 and I’ve been diving into XNA. I’m tired of running into rendering problems. I’m tired of stopping and sacrificing memory over cpu power on every single function. This decision is not something I’ve made lightly. I’ve been working on my project for about 2 years. The battle system is mostly done. The overworld has been implemented. I have shops and most other features you’d require in an RPG. This is not something I enjoy the thought of recreating in an entirely new language.

I’ve been stewing over my discontent for about 6 months, ever since I found out that stage 3D isn’t easy to exploit. I was disappointed with my results from exploiting workers to multi-thread in hopes of fixing the problems that way. I’m sick of being unable to access the hard drive. It seems like every time I look into AS3 in general I come back with some strange limitation like the fact that you can only have 25-35 sounds playable at once. My game isn’t suited for browsers anyway and it wasn’t the target platform. I used AS3 as a starter language and put off jumping to a different platform for way too long.

So yeah. This topic should be closed. Sorry for the rant.


(Ultima2876) #4

Hmm, you know in a year’s time you’re just going to run into similar problems with XNA, right? Garbage collection is a biggie there. However, C# is an absolutely beautiful language. What platforms are you planning to target? Just desktop?

I’ve been around the block and every platform/language/library has its limitations and problems. There is no such thing as an ideal solution, unfortunately!

Anyway, I probably should’ve weighed in sooner. I am the primary developer/publisher over at http://www.kickbackgames.com and we have a Stage3D engine that might help you. It’s designed to be a 1:1 replacement of FlashPunk (as opposed to StarlingPunk etc that actually have some different functions and require a lot of porting work even for current FlashPunk games) - you drop it into your game and it will (mostly) work. Nothing’s perfect, of course, and some tweaking is usually required (typically an hour’s work - usually fixing some game-specific layering issues and similar). It has to be licensed with us for use on mobile but it’s free to use on desktops/web; if you’d like to give that a try then just shoot me an email at support@kickbackgames.com (we don’t have a public download link yet because it’s still in closed beta).

The way I see it, you may as well have a go because all you have to lose is an hour or two of your time (as opposed to many many hours learning the ins and outs, pros and cons and pitfalls of XNA), and ultimately we might be able to help you bring your game to mobile if you’re interested in that (and thus reach a FAR wider audience than XNA will ever be able to bring it to). Of course, it’s up to you!


(ReiKGT) #5

You should probably remove your “show me your and I’ll show you mine” requirement. It seems terribly unprofessional/scam related. I actually stumbled upon your site a while back and discarded it as an option the second I hit that screen. Also why on earth would you require that any developer waste time writing their game integrated with a different (albeit similar) library? Seems silly. Sorry for being blunt.

Your offer is appreciated but like I said the browser isn’t the target platform, that’d be desktop. C# is more powerful than AS3 on it’s own. I can’t speak for AS3 + Stage3D, but it’s certainly true for vanilla. That said I NEED access to the hard drive. Using the shared object is unacceptable. That was my first complaint with Flash, but I understand why it’s necessary.

Also “Hmm, you know in a year’s time you’re just going to run into similar problems with XNA, right?” I doubt it. One of my best friends uses XNA and has been trying to get me to jump for over a year. He assures me that I’ll be fine. I’m aware of some of it’s pitfalls and I feel I can deal with them. Not all languages and frameworks are as suffocatingly restrictive as Flash. I still love the AS3 syntax though.


(Ultima2876) #6

No worries about being blunt, it’s useful feedback :smile:

It’s not so much “show me yours and I’ll show you mine”; we just like to work closely with the developers at this point in time to make sure any issues are identified and fixed before we make it public. It’s nearly ready to go out, and there’s no actual requirement for us to see your game or anything - it’s pretty much just a case of ‘email us and let us know you’re interested so we can send out the beta of the engine by hand and add you to the list of developers who have it’. Currently it’s a very personal sort of thing - I speak with most of the developers who are using it every few days to see how they’re getting on, help them out, take feature requests etc. However, you’re right; we have completely miscommunicated that and we are actually working on just having a traditional big green ‘download’ button within the next couple of weeks (the engine is basically finished)! [reason here being that when this site was made, I was literally just a regular developer and really had no idea what I was doing with regards to wording it and stuff. Heck, I’m still not exactly Mr Big Time publisher or anything).

With regards to piggybacking off of another engine, our primary goal wasn’t originally for new games to be made with the engine; we designed it with easy porting to mobile in mind. There are a lot of awesome FlashPunk games floating around that are potentially worth thousands of dollars to the developers who are moving onto other platforms and engines. Our idea was to offer a solution that took them only an hour or two to get prepared (as opposed to many hours learning new libraries, re-implementing etc) and could get them that extra cash as well as getting their game out to a wider audience; the fact that people are still actively developing with FlashPunk (because it’s an awesomely easy to use engine) is just a bonus.

It’s not a ‘similar’ library, it’s the same library! Exactly the same - function for function, you put it in (literally, copy and paste) and the expectation is that it will render exactly the same, only a bunch faster. That’s why we use the term ‘drop in’; you don’t have to re-write your game (or ideally, change even more than 1 line of code), we’ve done all the re-writing under the hood so you don’t have to. For all intents and purposes, you’re essentially ‘porting’ your game to the same language and the same library (the reason we expect a few changes to be made is that with a library as open as FlashPunk many different techniques are used and it’s hard to make it work perfectly in every case).

I agree that XNA/C# is faster than Flash. Truth be told, the main reason I left XNA and the Creators Club was that it’s much easier to get flash games to a wide audience than it is with desktop games. The biggest problem with XNA to me is that it’s now a deprecated platform and locked down to ‘desktop only’ (well, and maybe Xbox 360, though I don’t even know if MS are supporting that any more). Yeah, there’s MonoGame and stuff, but it still has the problem that you’re very very likely to spend all this time making a game that no one will know about or play :frowning: For me, that’s the biggest issue. Compare that to the relative ease of getting even an average game to be played by at least 2 million + players with flash games… and for me it’s a no-brainer! That said, if you only ever plan to target desktop and have a strong marketing team etc, then I guess it’s not such a concern. Still, I wouldn’t be able to shake the feeling that I’m spending time and effort learning a library and toolchain that has already been declared officially as being obsolete…

However, I’m not going to try to sway you, you’ve clearly made up your mind. I just wanted to offer an insight into some of my own game development journey :wink:

Thanks for your feedback on our site, it’ll be really useful (and I wish it came sooner, god only knows how many developers have thought the same thing you have and been put off by my blunder :/)


(Ultima2876) #7

This topic was automatically closed after 2 days. New replies are no longer allowed.