• 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

Can anyone teach me how to debug Java codes, however messy it may be?

7 posts in this topic

I have finished implementing A* pathfinding in my game. Here's the situation: (If I don't give a situation, everyone's going to give generic contexts and generic answers.)

 

Before implementation: The game is running smoothly at 60FPS. The game itself is simple, all thanks to easy grid movements for moving entities.

After implementation: The game is now lagging badly and it's unacceptable. The only thing I know that's causing the lag is the Map of nodes, in which the size is 160x120. Every 256 + X game ticks, once a unit entity spawns, it calls upon the pathfinding system to create a path that lets the unit entity to go from point A to point B. The X is arbitrary, since the player has to click on the screen to place down the spawners, which they automatically initiate themselves. At 60FPS, that's about every 4 to 5 seconds, the pathfinding system starts execution, which may lasts several seconds, due to the size of the nodes.

 

I heard many things about debugging code, such as profiling, logging, and simple step in/step out with breakpoints. Of the first two, I only know how to debug codes with the last option. Perhaps maybe if I do profiling, I might be able to see where the game is lagging, and then ask for more help on what I should do to solve it.

 

Of course, the most obvious solution is to cut down the number of nodes in the map. Unfortunately, each node is also binded to a color value. All nodes are pixel data taken from a BufferedImage, or in this case, a Canvas. So, I can't just edit out the size. Otherwise, I would have to do a complete rewrite, and I want to avoid that by all means, unless it's absolutely necessary. Speaking of A*, maybe I could adapt the algorithm so that it uses a greedy method of approach, but I don't have the knowledge to do such a thing, let alone tweaking the heuristics. I'm such a noobie here.

 

And how do you supposed to know when you're supposed to delegate the task (A* algorithm) into a concurrent task, and how to go from there? I don't have that much experiences with concurrency, so I hoped to hear what experienced experts would say about this.

0

Share this post


Link to post
Share on other sites

I'd have a different structure for path finding. An enum matrix for example (with constants like StateEnum.SOLID, StateEnum.AIR, StateEnum.WATER, etc). Or, if you want the traversing as fast as possible, maybe a matrix of ints and some tag values (0 air, 1 solid, 2 water, etc).

 

There is no need for the pathfinding to be attached to the actual pixel values.

0

Share this post


Link to post
Share on other sites

The debugger is your best friend as a programmer, learn to use it :). But there's other ways too, like dumping stuffs in a file, using messagebeep to know if some code is executed, or simple messages print in the console.

2

Share this post


Link to post
Share on other sites

A naive approach: set up a chronometer to test how much time is spent by a procedure each frame. Maybe it can helps you find the real bottleneck. Log values on the console or on a file. I'm pretty sure you have not to reduce the size of the map, but improve your current implementation of A* instead.

0

Share this post


Link to post
Share on other sites

About debugging:

 

It will help to know what IDE are you using to dev.

 

If you are using eclipse: The IDE has tools to help you with debug and profile.  ( Right click your main file - the one with 'main' method - and choose Profile As... or Debug As... )

 

If you does not want to use your IDE Resources, you can use the JVisualVM ( JDK_HOME\bin\jvisualvm.exe ). This app is a visual tool to help you measure your memory consumption, alive threads, etc etc... you can even take a screenshot of you heap to see what objects are using more memory, etc etc... This tool also have the   "Profiler" option. Its simple to use... Just click on Profile, start CPU measurements... play your game for a while and get back to "Profiler" and stop the measures... You will be able to see how much invocations each method has, how much time spent, etc etc.. so you can focus on you major time consuming methods and try to find a way to reduce its time...

 

Well... if you want to be serious about improving java performance I recommend the book "Java Performance" ( http://www.amazon.com/Java-Performance-Charlie-Hunt/dp/0137142528 ) it give you a "Big Picture" about common mistakes made by programmers, and how to avoid it, also how to use the right tools to find your application bottlenecks. 

 

Hope it helps... there is a lot of material on google about how to profile and maybe you can find good material on Oracle´s website.

2

Share this post


Link to post
Share on other sites


If you does not want to use your IDE Resources, you can use the JVisualVM ( JDK_HOME\bin\jvisualvm.exe ). This app is a visual tool to help you measure your memory consumption, alive threads, etc etc... you can even take a screenshot of you heap to see what objects are using more memory, etc etc... This tool also have the   "Profiler" option. Its simple to use... Just click on Profile, start CPU measurements... play your game for a while and get back to "Profiler" and stop the measures... You will be able to see how much invocations each method has, how much time spent, etc etc.. so you can focus on you major time consuming methods and try to find a way to reduce its time...

 

Yes, give JVisualVM a try. If you can grab a profile during the time your game is frozen, you'll at least be able to post a more specific request for help.

0

Share this post


Link to post
Share on other sites

Besides the debugger and jvisualvm which have already been pointed out, I would like to throw "Logging" in.

 

You should log stuff in your application and you should never System.out.println or System.err.println. 

You should always wrap the log output by a Logging system (e.g. Java Logging Framework, or SLF4J).

There should also not be a "e.printStackTrace()" somewhere in your code.

Logging also helps to find setup problems, because 3rd part libraries/frameworks usualy complain about problems.

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