• 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
fir

android fluid frames and gc

10 posts in this topic

 
 
 
I am new to android Im watching some example source of simple game and there is stated
 
 
 This code is not as beauty as could be. It is optimized to avoid garbage collection
 
which would make the display updates stutter.
 
 
Does it mean that when you make game for android you have to do such things regularry? Is there some way of programming in java that let you not engage garbage collection ;/
 
 
 
sorry for banal question maybe but i am quite green here Im curious and it would be hard probably to get this answer with my zero experience 
0

Share this post


Link to post
Share on other sites

Since you didn't post any actual code it is hard to give a proper answer but.... yes, when you make games using Java(and other languages with a hard to control GC) you want to write your code in a way that keeps the GC from kicking in during gameplay. Hold on to your references, re-use allready allocated objects instead of reallocating them, avoid modifying immutable objects(such as strings) and try to do your cleanup (drop references and force the GC to run) during your loading screens,

Edited by SimonForsman
2

Share this post


Link to post
Share on other sites

Since you didn't post any actual code it is hard to give a proper answer but.... yes, when you make games using Java(and other languages with a hard to control GC) you want to write your code in a way that keeps the GC from kicking in during gameplay. Hold on to your references, re-use allready allocated objects instead of reallocating them, avoid modifying immutable objects(such as strings) and try to do your cleanup (drop references and force the GC to run) during your loading screens,

 

Isnt this something you do against the language? Im a bit schocked. Is it really possible to not involve garbage collection in java? I mean it would be something like c style writing in java ;/

 

I understand that procedural c-like way of writing in java on android is impossible because of heavy objective api, or this is also possoble?

 

(sad I got no experience here, come from couple of years in pure c/winapi world, maybe I will learn something about this very crazy world of android this year ;\)

 

PS as to source i just wathing some very simple random pice of android game code 

 

https://github.com/tinkerlog/PongTime/blob/master/src/com/tinkerlog/android/pongtime/PongTimeView.java

 

and trying to get know what is going on here; 

If someone would like volountinery explain me a bit what is goin on here it would be welcome too...

Edited by fir
0

Share this post


Link to post
Share on other sites
Java follows a different model than C.

As for the link, the source file seems self-explanatory. Precisely WHAT about it do you not understand?

If you are having trouble with the language broadly, a good old fashioned book on the subject is probably in order, followed with writing your own toy programs and learning by trial and error.
1

Share this post


Link to post
Share on other sites

Java follows a different model than C.

As for the link, the source file seems self-explanatory. Precisely WHAT about it do you not understand?

If you are having trouble with the language broadly, a good old fashioned book on the subject is probably in order, followed with writing your own toy programs and learning by trial and error.

 

 

Answer coud be quicker ;/ In general I know (probably) most 

syntax of java and thiings but do not unrerstand at all the 

objective 'rush' and android api elements ;/

 

precise question? could be like "could you mention most important elements in this program (both program defined or androids api) and say to me how they interract  ?" I am lost in this :C I understand the View idea and some overrides, but not quite a idea of extending thread, (yet less other elements) and Im generally lost in code flow here

Edited by fir
0

Share this post


Link to post
Share on other sites
That code is not particularly complex. If you do not understand it, I suggest more study, more reading, more experimentation, and less posting on the forums.

You tend to ask questions on the forums before applying enough thought. Think first. Then experiment and think again.

The code you linked to is not particularly difficult to modify, and is very easy to modify and experiment with. I recommend you do more experimentation.
2

Share this post


Link to post
Share on other sites

 

Since you didn't post any actual code it is hard to give a proper answer but.... yes, when you make games using Java(and other languages with a hard to control GC) you want to write your code in a way that keeps the GC from kicking in during gameplay. Hold on to your references, re-use allready allocated objects instead of reallocating them, avoid modifying immutable objects(such as strings) and try to do your cleanup (drop references and force the GC to run) during your loading screens,

 

Isnt this something you do against the language? Im a bit schocked. Is it really possible to not involve garbage collection in java? I mean it would be something like c style writing in java ;/

 

I understand that procedural c-like way of writing in java on android is impossible because of heavy objective api, or this is also possoble?

 

(sad I got no experience here, come from couple of years in pure c/winapi world, maybe I will learn something about this very crazy world of android this year ;\)

 

PS as to source i just wathing some very simple random pice of android game code 

 

https://github.com/tinkerlog/PongTime/blob/master/src/com/tinkerlog/android/pongtime/PongTimeView.java

 

and trying to get know what is going on here; 

If someone would like volountinery explain me a bit what is goin on here it would be welcome too...

 

 

No, its not possible to "not involve" the garbage collector, but it is possible to keep it from running when you don't want it to run. (The GC will not run(or will atleast run really really quickly) if there is no garbage to clean up) and you can coax the GC to run when you want it to run (By asking it nicely and sleeping repeatedly until it runs).

 

That code being ugly has nothing to do with the GC though (for a simple game like pong the GC is irrelevant as you can create all your objects at startup and hold on to them until the program closes)

1

Share this post


Link to post
Share on other sites

Specifically I do not understand this here, maybe someone culd explain it a bit 

 

 

 public PongTimeView(Context context, AttributeSet attrs) {
        super(context, attrs);
 
        // register our interest in hearing about changes to our surface
 
        SurfaceHolder holder = getHolder();
        holder.addCallback(this);
 
        // create thread only; it's started in surfaceCreated()
        thread = new PongThread(holder);
        setFocusable(true); // make sure we get key events
    }
 
I understand a surfaceHolder is set of "in and out" methods you use to "react and act" on surface
 
 
 
but here it is passed to two objects to pongtimeView and also to pongThread - why is that so shouldnt just one object reach it and use it (isnt it a mess when botk object react or act on the same surfaceHolder methods and callbacks?) or for convenience this is done and pongtimeviev uses some methods and pongthread other methods?
 
yet some mysterious things - is there a need to create such sperate thread like here? cannot be this done in more classic way (more classic i mean for example program everything just in one "view" setting onlu a timer to some update method - like In javascript canvas games i tiny know )
 
also this is a bit mysterious
 
  SurfaceHolder holder = getHolder();
 
isnt it some violation of OOP rules (i know almost nothing about) to get some "holder" to some surface just from nothing, some global space? I do not understand this - how man shopuld understand it
Edited by fir
0

Share this post


Link to post
Share on other sites

PS as to source i just wathing some very simple random pice of android game code



https://github.com/tinkerlog/PongTime/blob/master/src/com/tinkerlog/android/pongtime/PongTimeView.java
 

 

There are integer divisions with no comments in that code. Always makes you wonder if it's on purpose.

 

The GC will cause problems if you allocate objects at each update. You can also get strange GC problems if you allocate a lot of memory.

 

However, my experience with Java and Android says that it's not the GC that is the big problem. The main problem is almost always with the resolution and correctness of the timer. I have one phone where the resolution of the timer is no more than 10ms. Also, the sum of small time intervalls can be different from the complete time interval.

 

What you also need to now is that the frame rate is fixed on most Android phones. You will probably get about 60Hz. In one of my new projects I've started to use that as a timer.

 

About that code example. There is no need to understand everything. Get the code to run first and then start to change it. Add features and so on.

Edited by Apptelope
1

Share this post


Link to post
Share on other sites


Isnt this something you do against the language? Im a bit schocked. Is it really possible to not involve garbage collection in java? 

 

It's not that much stranger then avoiding to do unnecessary memory allocations and copies in your inner loops in C to increase performance.

1

Share this post


Link to post
Share on other sites


also this is a bit mysterious
 
  SurfaceHolder holder = getHolder();

It is exactly the same as it works in C, since you are already familiar with C.  It calls a function and stores the result. However, as Java works slightly different from C, it would be a SurfaceHolder pointer rather than a SurfaceHolder structure, but the concept is the same. Call a function, store the result.

 


isnt it some violation of OOP rules (i know almost nothing about) to get some "holder" to some surface just from nothing, some global space? I do not understand this - how man shopuld understand it

It calls a function that is within the current scope. It might be inside the class, it might be inside a parent class, it might be somewhere else.  All you need to know is that the compiler can find the function somewhere.

 

 

As for the rest, why doesn't the code follow some other design, those are bigger design questions. Even though it adds a tiny bit of complexity by requiring additional knowledge, it radically simplifies the design because components can be reused.

 

Even though it might be simpler in some ways to weld and epoxy everything together, people use bolts and screws and other standard parts because they can be easily reused.

1

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