• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tom_mai78101

What do you do if your gameUpdate() method can't update fast enough?

10 posts in this topic

Regardless of what language any programmer is using, they would have to come to some point in the development stages where their game would not update fast enough.

I realized that my game isn't updating quick enough, and causes the game play to stutter. The more objects, the heavier stuttering it gets. Below is a picture of me benchmarking my game loop. "Start" means the CPU has entered the game loop, and "Finish" means the CPU has left the game loop.

I have utilized two concurrent threads. One is for rendering the objects onto the screen, and the other is for updating the objects' properties. I only benchmarked the updating thread, and not the rendering thread.

[img]http://i.imgur.com/8O5Me.png[/img]

I find that there's a noticable, average lag of 0.07 seconds. That's enough for the game to stutter, since I can easily see it stutter.

I am now pondering what techniques the more experienced developers did to mitigate this issue? Thanks in advance.
0

Share this post


Link to post
Share on other sites
For larger-scale algorithmic improvs, should I consider using the "layer of classes" approach?

The approach is described, as follows:

[img]http://i.imgur.com/BfPBR.png[/img]
0

Share this post


Link to post
Share on other sites
There are lots of things you don't HAVE to update
some things you can skip, some things you can do every 2nd or 10th or 100th frame

if you time things correctly: let's say you have a double max_time is 0.0125 or 0.012 for decent margin,
then your gameupdate() function should do all the _absolutely_ necessary work _first_, and when it runs out of time - exit immediately
the small margin will help you avoid stuttering because there are functions in gameUpdate() that could take some time to do

i hope this helps, because i had to find this out myself, but i learned alot from it =)
don't be afraid to frameskip!
0

Share this post


Link to post
Share on other sites
i couldn't figure out how to edit my post, so i might as well post another, which is on another topic:
there are some annoying functions in any game that just takes time - pathing, raycasting, AI, physics

to avoid getting run over by cpu time, you could do any number of cheap things like only doing pathing for 4 and 4 'NPCs' at a time
or if its critical work - see if you can't get away with doing half the work this frame, and the other half next frame

sometimes it can even be unnoticable if you are a frame late, or run 'something' (anything) at a different framerate!

other things to consider are - things that are very far away from the camera don't need to be as 'fine' or 'smooth', so you can do less there
but it's generally harder to accomplish...
in my case i would progressively 'frameskip' depending on distance from camera any AI or pathing :)
0

Share this post


Link to post
Share on other sites
Getting to know which parts of the game are likely to be performance hogs usually comes down to lots of profiling and experience ..

Profiling is key at every stage of development. But having an eye for performance is also essential in game design even before you start the main coding. You may have to do tests beforehand .. how many characters can you have on screen? How rich can the environments be? How far can you see into the distance? How much animation? How much physics? How many ray tests, path finds etc? [img]http://public.gamedev.net//public/style_emoticons/default/ph34r.png[/img]

As you develop each part you will get a better handle on how long it takes so you can budget your performance time better. This will feedback into the game design - changes may need to be made, but hopefully not too major if you were in the correct ballpark with your tests / calculations etc.

If you get it wrong, it can be a disaster, because you can end up having to redo large sections of the code / game design, or else release a laggy mess that won't sell, in the hope that in 10 years time processors will have caught up with your 'vision' (sloppiness).[img]http://public.gamedev.net//public/style_emoticons/default/wacko.png[/img]

One technique I've seen to help is to draw 'performance bars' on screen each frame, a little bar chart which can give you an idea of the time taken by each section of the code. You can see with this as you work what is using up lots of performance, and what is spiking performance too, which can be as big an issue. You can also see as you develop, oops, I just made something incredibly performance sapping.

I won't say too much on making your code fast as there's loads written on this already, it's a massive topic.

You may also be facing some rendering / gameloop synchronization issues, which can be a bit fiddly to get right.

As hodgman says, 0.07 seconds sounds like way over for a gametick. However, to play devil's advocate, if you fixed your timestep at 10 ticks per second, and used interpolating rendering as you should, you'd get silky smooth gameplay (assuming your rendering was totally independent). In fact if you write your code right, you can just change your tickrate #define to e.g. once per second, and it will still look silky smooth (just the physics / reactions etc will be well stodgy lol).[img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]

However in the real world, with spikes in gametick times, you'll probably need a bigger comfort zone to prevent the render thread getting 'starved' of updates, and stuttering.

Also, if you are talking about a non-fixed platform (i.e. not a console) then remember people might be playing on a lower spec machine than your development box. It's great if your PC game runs just about on top spec hardware, but not so great if it becomes unplayable on the other 90% of people's machines.

Personally I tend to shoot for great performance on a machine that is about quarter the power of current 'high spec'. That covers most of the bases. It's crucial that the game tick rate at least runs fine on low spec machines, because then at least the rendering can be scaled back without 'breaking' the game.
0

Share this post


Link to post
Share on other sites
a few pieces of generic advice (Since you've not posted the slow code):

1) Make sure you are actually doing an optimized build when you profile, (Debug builds can be horribly slow).
2) Avoid making unnecessary calculations in tight loops, (If a part of a longer expression is constant you can calculate it outside the loop and reuse it).
3) Avoid creating/destroying objects frequently. (keep short lived objects (bullets, particles, etc) in a pool and reuse them instead of constantly creating new ones)
4) Use appropriate containers for your objects. (vectors tend to be faster than lists for most purposes unless you need to frequently remove items from the middle while retaining object order).
5) If you are doing things like collission detection between many objects try to use some form of space partitioning to cut down the number of checks made or use fast coarse checks before the more detailed checks. (AABB or Sphere/Distance checks are fast, mesh or per pixel checks are relativly slow)
6) If you are comparing distances/vector lengths, use the squared distance/length to eliminate the sqrt call (They're fairly expensive and often unnecessary). (This trick makes circle or sphere collision checks even faster)
0

Share this post


Link to post
Share on other sites
Iam quite new to this (Scenegraph Operations) but Frustum and Occlusionculling could be 1) Twek to get more Renderperformance.
For math it might be usefully to shorten the formulars (espacially cosinus ect) as set of matrices methods or functions wich should
be inlined, to get opcode cache benefits. Just my 2 cents.

Peter
0

Share this post


Link to post
Share on other sites
Thank you, everyone.

To answer SimonForsman, the question itself is about a general problem, so I wouldn't think it is helpful to post my codes, as it might make the topic more specific than what I intended.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0