Begining game developement help

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Begining game developement help

Postby multiplydivide » Wed Jun 22, 2011 9:31 pm

Hello everyone,
I just got out of school, got my bachelors in computer science, and am planning on spending my summer designing a game that has been festering inside my head for some time now.. I had designed a prototype of sorts but it was rather limited in functionality and used a canvas to draw, for a market worthy version I would like to use opengl... I have read through many tutorials on opengl, and have been successful in getting a floor and walls with some stationary objects to the screen, but I am having some trouble getting a handle on how to move my objects around in the world... not in the sense that i dont understand transforms, rotations and such, but stitching code together that will allow me to smoothly move a series of objects across the screen... the game I want to make has alot of moving parts, they are relatively simple, but many of them...

where I am currently at I am thinking that I will have to create a series of arraylists that hold values for positioning, speed, direction, and rotation where necessary, this array list will then be accessed by my rendering class to put the loaded models at the specified locations within my world... as much as this makes sense to me I am having some trouble implementing it...

is there anyone out there that can offer me some advice and or help on the subject, it would be greatly appreciated... The plan as of now is to work on developing my graphics, animations, and most UI by the end of july...

Thanks again for any and all help,
hopefully by the end of september I will have a beastly game to show for it...

~Spaceaholic
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Top

Re: Begining game developement help

Postby MichaelEGR » Thu Jun 23, 2011 4:13 am

I am releasing a tutorial series on game dev and middleware platform for Android called TyphonRT that will cover a lot of this including time based animation. There will be a initial release quite likely now at the end of July / in August for sure, so it may be a little too late to help, but something to keep an eye on...

http://www.typhonrt.org/

TyphonRT is different as it is a component architecture and the entity system supported is component based. It is most similar to Adam Martin's writing on the subject and you may find this article interesting:
http://t-machine.org/index.php/2010/05/ ... vaandroid/

You may also check out libgdx in the meantime which has some similarities between TyphonRT:
http://libgdx.badlogicgames.com/

This book is good and is from Mario / creator of libgdx:
http://www.amazon.com/Beginning-Android ... 1430230428
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: Begining game developement help

Postby multiplydivide » Thu Jun 23, 2011 4:31 pm

So this is not quite what I had in mind, using someone elses code and all. The reason I would hesitate to use something like this would be that you have to go on faith that the individual(s) who created it made it as efficient as possible... but at the same time, being a bit of a novice, Someone who has spent the time to create such a thing (thing as in game engine that isn't a game engine but rather a cross-platform game development framework not including the kitchen sink) probably has a better understanding of how to efficiently code.

I may be a novice but I am a pretty good coder, once I get my ideas in order, once I see the light, if you will... and maybe it is nothing more then chugging down lots of this good old coffee that sits beside me and playing with code until something clicks(I do only have about the equivalent of 2 full days playing with and reading up on opengl)... but so far the lights remain off... but sometimes I get frustrated and think maybe someone else is standing near the switch and can simply flick it for me.... Overall I guess I will have to play for a couple more days and get more specific with my question(s), because everything I want to ask right now is kind of vague...

Thanks for your reply,
~Spaceaholic
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby MichaelEGR » Thu Jun 23, 2011 11:22 pm

So this is not quite what I had in mind, using someone elses code and all. The reason I would hesitate to use something like this would be that you have to go on faith that the individual(s) who created it made it as efficient as possible... probably has a better understanding of how to efficiently code


In the instance of TyphonRT you have all the source code; same with libgdx of which I'm not involved with or the author. The neat thing about TyphonRT as you mention is that it isn't a kitchen sink framework. You can take what you need and leave the rest. It's also based on 10+ years of performance Java / game dev experience and has been in mainline development spanning J2SE and Android for 8; performance matters which weren't ferreted out on the desktop were for Android. The main demo is a Quake3 class engine (though not complete per se as it's not commercially viable due to licensing issues with Radiant level editor) and I'm considering adding iOS Rage support for a new demo. I've mostly focused on working with new & modern software architecture techniques and using all of the language features of Java while maintaining performance. I'm also almost done with the Java / component layer of TyphonRT and soon will begin experimenting with Scala for modern JVM language support.

I certainly encourage folks who have a go getter attitude to start from scratch, but sometimes there are pre-existing tools and techniques that help one focus on game design and actually making a game rather than wrestling with all of the complexities which await underneath. For instance TyphonRT works across all devices Android 1.5+ and sidesteps various hard fragmentation issues in each OS release. This being the case since I've been working with Android since v1.0. You may find quirks and difficulties in working with older versions if you don't have devices with older OSes. In addition the runtime is component oriented, so if there is a problem on a given device / OS combination just that component can be replaced with a working version for that device / OS combination.

A defining aspect of both TyphonRT and libgdx is to provide a stable base for game engine development though TyphonRT can be used for any app type and not just game dev. You aren't confined to a box per se and have to use all premade tools. TyphonRT will have more premade game engine components, but you are not required to use them and are encouraged to forge your own path and conceivably share it with others (or eventually sell them as a 3rd party to other devs). It's like starting out with a Ferrari frame versus a piece of wood and some casters for a soapbox cart.

I may be a novice but I am a pretty good coder, once I get my ideas in order, once I see the light, if you will... and maybe it is nothing more then chugging down lots of this good old coffee that sits beside me and playing with code until something clicks(I do only have about the equivalent of 2 full days playing with and reading up on opengl)... but so far the lights remain off.


The world needs more good coders; trust me! I recommend rockets BTW; a large coffee and 2 expresso shots (I get an extra for good measure to make it 3). :) It took me more than 2 days to wrap my head around OpenGL; more like a month or two. A lot of game devs don't want to get so low to the metal per se. You are also diving in at a time when it's almost conceivable to start with OpenGL ES 2.x or the programmable pipeline vs the fixed functionality state machine of v1.x. While it's handy to know 1.x as thoroughly as possible there is increasingly less of a need though you'll find most of the tutorials online cover 1.x.

but sometimes I get frustrated and think maybe someone else is standing near the switch and can simply flick it for me.... Overall I guess I will have to play for a couple more days and get more specific with my question(s), because everything I want to ask right now is kind of vague.


For sure, but eventually flicking it oneself is very rewarding. In my career and tech advancement I never had the fortune of a mentor per se; and then I stopped looking for one. You might give that book I linked to a read though as that could likely flick some of it for you and as I mentioned I'll be putting out comprehensive tutorials once I launch TyphonRT, so drop me an email at the contact address and I'll give you a heads up. I plan to do a Khan Academy like series of tutorials and videos taking folks from their first triangle to understanding a BSP based FPS engine and then some. Also extend all of Khan's physics / math videos with actual working code. All in good time though.

Of course certainly ask more specific questions on the forums and such. Another treasure trove is JGO www.javagaming.org
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: Begining game developement help

Postby multiplydivide » Fri Jun 24, 2011 4:48 pm

MichaelEGR, thanks for the much needed moral boost.... I have a tendency to set unrealistic time frames which inevitably causes much unneeded stress and anxiety...

Now I have a question, however at this point I should probably be posting it in the opengl help section ... oooops...
since I am going to need to be drawing upwards of 100 objects to the screen I decided I would try and place this many objects on and move them around to see what happens. in doing this I have a main that creates a renderer and two planes,which have an android icon texture, the main also owns an arraylist called positions, holding the position rotation and destination of a given plane. the array list is passed up to the rendering class as a shallow copy so I can still modify the positions in my main...the first plane is drawn as the floor and is stationary. the second plane has 100 entries in the positions arraylist that correspond to it and they are all moving, so in the main I have a thread that loops through the array 30 so times a second, synchronizing on the array, and then updating each element that is mobile(all but the first which reps the floor)...
they all move, but there is some choppy choppy motion going on here, which for my purposes is completely unaceptable because these graphics on the screen represent maybe 50% or probably less of the cpu time I will be needing... of course I have a feeling it may not be simply bogging down the cpu at this point but rather a big oopsie daisy in coding

I have also modified the synchronize so as to synchronize on each element within the arraylist rather than the entire list at a time, same choppiness...

Any suggestions?

Thanks for any and all help,
~Spaceaholic
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby MichaelEGR » Fri Jun 24, 2011 7:07 pm

Indeed a bit of misapplied coding, but there are remedies.

If you run a memory profiler you'll likely see tons of garbage created via the ArrayList copy; I assume you are using "clone()". That constant churning of not just new object creation, but GC reclaiming the orphaned copies after each render / frame cycle will bring Android to its knees. Not that this would be an OK thing to do on the desktop / J2SE either, but performance on Android will suffer greatly. Run ddms and you'll see a ton of GC messages quite likely. For a Java profiler I really like YourKit. It's a commercial product, but by far has been my profiler of choice for the last 6 years or so and has helped me greatly where other profilers before it failed. You can dump hprof files from the 2nd button from the left in ddms. You need to run hprof converter on the file before the standard Java profilers can open it.
http://developer.android.com/guide/deve ... -conv.html

If you are using Eclipse or want to use a free profiler I've read good things, but haven't used MAT:
http://www.eclipse.org/mat/

In addition another little somewhat innocous, but a major problem with the stock Java collections is that the process of using an Iterator whether in a foreach loop or obtained by creating one through "iterator()" or the like is creating a new object. Everytime an iterator is created in a tight loop "Duke" devours a kitten (and your performance).

With TyphonRT I created a extended set of collection implementations that are backward compatible with the standard collections, but feature resetable and recyclable iterators. There are caveats of course such that you need to specify the number of recycled iterators cached if the algorithm the collection is applied to traverses it more than once otherwise you steal actively used iterators; err and I removed concurrent modification exceptions. However it's real easy to switch back and forth between "legacy" Java collections and my versions. These extensions though make it possible to use collections without object creation overhead.

Since you are doing copies and mention this is in relation to a main loop with a separate thread than the rendering I recommend you stick with a single threaded game loop. IE move your objects, render, repeat sequentially from one thread. I have yet to even fully crack for game development a proper way to handle multiple threads for time based callbacks / clocking. Sure one can use a ThreadPoolExecutor and such for non-deterministic tasks. However, a game rendering loop is often deterministic. Even if a proper sharing of data is possible between a rendering thread and say game logic thread the high FPS from the rendering thread is fake because you'll be rendering duplicate frames if the data isn't updated between frames. So definitely do yourself a favor and switch to a single threaded game loop until the need arises for more (it won't for a while). If it's fine for id tech / Carmack for all these years it'll do nicely for you.. Check the first paragraph here I suppose to confirm...
http://en.wikipedia.org/wiki/Id_Tech_5

Now multi-core / parallelism is the way to the future, but that doesn't mean it's good to start there. Again not a 2 day problem or easy to solve. Copying data is not feasible nor is message passing per se. The latter works great for non-deterministic open ended tasks - a game loop is not that though.

Switching to a single threaded game loop will eliminate your Arraylist copy and synchronization code which BTW you only want to synchronize something that is absolutely necessary to do so. In TyphonRT This is done in only 2 areas. To get by the iterator issue use .get(<index>) method of Arraylist or simply allocate a straight up array.

I don't exactly recommend storing position state for all objects in an array list, but it'll work for a quick hack to get stuff rendered. Having gone down the OOP hell hole for entity systems (main anti-pattern to watch for is the blob anti-pattern) I've fully converted to a component oriented architecture and entity system and it's fantastic. That is what Adam Martin's article is about that I linked to previously and the closest written description though I've implemented and extended things differently.

Heh heh.. Again I recommend the Beginning Android Games book. It'll be the best $25 you can spend to get ahead from where you are at now:
http://www.amazon.com/Beginning-Android ... 1430230428
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Re: Begining game developement help

Postby multiplydivide » Mon Jun 27, 2011 6:37 am

I came to the conclusion that I am not in a position to start designing without coding, I am not familiar enough with any of it, so I am going to hack this thing to pieces that, eventually, can be disassembled and reassembled into the fine piece of software that I am envisioning.

I was a bit unclear when I explained how I was going about getting things to move around so just to clarify.
I create a number of planes with the textures(old news)
i create arraylists of transform and rotation information that corresponds to the given planes
I then pass the array list in as a position setter once, no clones, I just pass it as an argument and it makes a shallow copy on the other end, in my head I think of it as a pointer
I am then able to modify the contents of the array list in my main, i synchronize on the elements i update so as to not have the renderer try and sneak in on me changing(haha)




this has enabled be to draw more than I need to the screen and seems to run very fast, although i am sure it will not be the final implementation, but for now it looks nice on the screen... I fixed the issue of the animations being choppy, my thread running the update was updating at fixed intervals but I forgot to let it sleep when it should have been...

so Ill let the animation part linger in the back of my head while the next couple days will be devoted to UI,,, I need to map a users touches from the screen into my 3d space and determine what they are touching... I have a number of planes sitting perpendicular to a floor, I need to be able to determine if the user touched a building(the perpendicular to the floor planes) or the floor itself... Any suggestions?

Thanks
~Spaceaholic
PS. I am going to try and pick up that book, but at the moment money is tight, hopefully next week...
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby MichaelEGR » Tue Jun 28, 2011 1:50 am

I am not familiar enough with any of it, so I am going to hack this thing to pieces that, eventually, can be disassembled and reassembled into the fine piece of software that I am envisioning.


A fair amount of game devs especially on the indie side quite often make prototypes and disguard them copying over code that worked to the next project. Whether this is for a trying out a tech or game design idea being flexible and testing out ideas / prototypes is usual.

I fixed the issue of the animations being choppy, my thread running the update was updating at fixed intervals but I forgot to let it sleep when it should have been.


In a tight loop for clocking / callback distribution you do need a "sleep(1)" or possibly call "yield()" if it's a multicore device. A do while thread yield loop may consume more juice so to speak, but I've found the "sleep(1)" to be effective on the desktop particularly laptops and fine on Android. Errr.. Things still get a little hot.. :)

This also points out a problem that troubleshooting code unseen especially with game dev and OpenGL is very hard. Especially with OpenGL as problems can occur from other areas than expected due to state machine nature of the beast.

I then pass the array list in as a position setter once, no clones, I just pass it as an argument and it makes a shallow copy on the other end, in my head I think of it as a pointer


I still don't see why this is necessary if you render a full scene frame before this method returns. There is no point in making a copy of this data especially if this other method is not running in a separate thread. It's certainly fine to have sub systems, but having them sequentially execute in one thread / game loop without copying data is fine. Of course it works for your simple scene right now with ~100 planes, but it's extra overhead.

I have a number of planes sitting perpendicular to a floor, I need to be able to determine if the user touched a building(the perpendicular to the floor planes) or the floor itself... Any suggestions?


Ray plane intersection. It's fairly straightA forward and a short test and lots of info online. You can detect the plane that was hit, the intersection point, and the time it will take to hit it depending on the magnitude of the ray (a vector, etc.). Positive time for planes forward of the start position / negative time for planes behind the start position / direction.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Re: Begining game developement help

Postby multiplydivide » Wed Jun 29, 2011 6:18 pm

First off thanks for your continued help, your input has made this process much easier to endure, and it is greatly appreciated....

The reason the copy is necessary is because of the way I have this whole thing coded, it is very sloppy at the moment, there are still large sections of code that are borrowed, everyday I seem to pick up a little bit more of what is going on and I try to implement my own code, but for now I am using alot of snippets from jayways tutorial on opengl.

I have a main activity which creates a glsurfaceview and also implements runnable(for the game loop)
this view creates a renderer,
the renderer has groups, which are groups of meshes
a mesh contains the coordinate plane and the texture that gets drawn to it
at the moment I create all my meshes in the main and pass them up to the renderer who adds them to the proper group(world, building, and man groupings)
the main also creates positions, posistions contain all data required for moving an object about my world, or simply placing it there(mobile/stationary positions) so x,y,z, rotations, momentum all part of a position
positions are put into and array list that is passed to the renderer and then from the renderer into a grouping(man positions with man meshes)

the positions array list is created once in the initialize, passed up as a copy, and then I am able to modify it in the main and the modifications are seen by my renderer... so I am able to modify the coordinates that a man is drawn at in my game loop within the main activity class, and the renderer then draws at my modified positions

I only have one man mesh at the time, but I have 100 positions for which he needs to be drawn and positions are constantly being created and destroyed as troops deploy and reach there destinations..

I am frantically searching for a more efficient way of going about this, I know it is not going to work this way in the end, but at the end of a day I like to see progress on the screen... I have been trying to prove to myself that I am capable of creating the game I want to see at the end because I have had the offer to receive funding for the project but cant allow myself to accept it if I am not positive I can make the game... funding is important because I am currently unemployed(starting to work as a bartender for weddings this weekend, and possibly throughout the summer)... My computer is a POS and needs to be replaced(bought the cheapest dell laptop to get through school, everything about it is starting to fail)... need to feed myself, my dog.... but hay, everyones got problems... and if I do indeed end up making this game, and it turns out anything like I envision it, i dont see how it wont be profitable, or at least find my target market for future apps/ games....
~Spaceaholic
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby multiplydivide » Wed Jun 29, 2011 6:32 pm

I checked out javagaming.org, its a great resource...
They have convinced me that I should implement my touches by rendering all my objects to a buffer with each object being a unique color based on there ID's, then I can retrieve the pixel color at the touch location and compare it with the id's to figure out what they touched... they assured me it would be more efficient given the simplicity of my world... I am trying to implement it but think I need to restructure my drawing in order to do so... been having some issues with accessing the graphics library in a few function calls...
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby multiplydivide » Sat Dec 24, 2011 12:53 am

Hey MichaelEGR,
I would just like to say thank you for helping me through a tough time, Thanks to your help and advice I was able to set myself back on track and now released my first game, its called Guuulp and is available on the android market. While it is nothing like the coding we had talked about, its roots sink deep within the game engine found in mario zechners begining android games, which you had suggested I pick up...
Thank you for all of your help,
Cooper
multiplydivide
Developer
Developer
 
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am

Re: Begining game developement help

Postby MichaelEGR » Wed Dec 28, 2011 2:02 am

Awesome. I gave Guuulp a try and it is a nicely balanced effort with good attention to detail with the game play. For a first game effort you did a great job. I did try it on my tablet and you'll have to address the accelerometer issues with API level 11+ and tablets where the native orientation is different thus you must handle the sensor data in a different way to be generic between all devices. I can provide you some source code for this issue. Other than that all you need to do is provide higher resolution textures for large format devices (most tablets and Galaxy Nexus + new phones sporting high res displays in the future) and Guuulp will be good to go. Drop me a PM w/ your email or contact me at the contact email on the TyphonRT web site.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests