Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1] 2 3 ... 35
1  Game Development / Newbie & Debugging Questions / Re: Clean code & Smooth development on: 2014-10-17 01:15:11
I generally keep my code pretty organized, however whenever I struggle on some implementation, it gets messy.

The exact opposite happens to me. The more I am struggling with an implementation or with debugging, the more I I spend cleaning up the messes I have made in order to figure out WTF I just wrote.

I'd try to make methods the most basic unit of cohesion. Whatever is done in a method should be summarized by the name of the method. Then, when you string a bunch of these methods together, what is going on is automatically described and readable (pretty much).

When princec says "Sun's bracket conventions" that means either of the two types that Cero demonstrated, yes? I certainly hope so, as I also prefer what Cero calls the Allman style, and would hate to think this would upset 99% of other programmers. Cero's first example is not exactly correct though, is it? Shouldn't there be more than a single space for the nesting?
2  Game Development / Newbie & Debugging Questions / Re: Best way to iterate through ArrayList? on: 2014-10-15 18:44:31
Here's another.   Wink

1  
2  
3  
4  
try {
    array[idx++];
}
catch(ArrayIndexOutOfBoundsException e){}


Surely that is considered hacky? lol

Yep.

I just found a discussion of the technique:
Quote
try-catch blocks generally use no extra time if no exception is thrown...Throwing an exception and executing the catch block has a significant overhead. This overhead seems to be due mainly to the cost of getting a snapshot of the stack when the exception is created...Generally, the performance cost of throwing an exception is equivalent to several hundred lines of simple code executions...You can reduce the cost by reusing an exception object rather than creating a new one...is two orders of magnitude faster...the sole disadvantage of reusing an exception instance is that the instance does not have the correct stack trace...
From Java Performance Tuning by Jack Shirazi, 2003. (pages 172-176)

It definitely seems like asking for trouble. In chapter 7, Shirazi profiles examples of a few cases where it might eek out a slight performance benefit. The best case that can be made for its use is if the end test is a significant percentage of the looping code (i.e., only a couple statements in the loop) and the number of iterations is really large. Then, perhaps the gain in dropping the iteration-is-done test outweighs the cost (assuming you throw an existing exception rather than generating a new one). But you still have to deal with the inevitable WTF that occurs when looking at the code fresh a few months later.
3  Game Development / Newbie & Debugging Questions / Re: Best way to iterate through ArrayList? on: 2014-10-15 08:20:53
Here's another.   Wink

1  
2  
3  
4  
try {
    array[idx++];
}
catch(ArrayIndexOutOfBoundsException e){}
4  Game Development / Newbie & Debugging Questions / Re: Perlin noise that looks like this on: 2014-10-14 17:02:08
Yesterday I thought I posted another round of playing with this--but I must have bungled it, as the post isn't here. I couldn't resist trying to reverse engineer your example.

Here is the screen shot:


I realize this is over-complicating things a bit, as you are still trying to get the basic function to produce the result on the top right. But I am confident you will get it when you try putting in a scaling factor like I described in the previous post.

In this example, the refinement is that a lower frequency is added (scaled to half of the main track), but I'm first clamping out all the negative values instead of folding them over back into the positives via the ABS function. So, overall, it is providing some nice shading with some "highlights" here and there where the white appears.

The equation for the left side (noiseValueA) in combination with the right side (noiseValueB) would be this:

1  
2  
3  
4  
5  
6  
    noiseValueA = Math.max(0, noise(x * 3 / 256.0, y * 3 / 256.0);
   
    noiseValueB = noise(x * 6 / 256.0, y * 6 / 256.0);
    noiseValueB = Math.abs(noiseValueB);

    noiseValue = (noiseValueA + 2 * noiseValueB) / 3;


Then, transform noiseValue into a meaningful color value, and assign it to pixel (x, y).
5  Game Development / Newbie & Debugging Questions / Re: Perlin noise that looks like this on: 2014-10-14 16:32:53
You might be dividing the x and y by way too much, you want fairly low frequency noise to produce those loops

Actually, I'm guessing the opposite is the case, not dividing by enough.

To get lower frequencies, the rate at which one moves through the Perlin space has to be pretty small. Therefore the increments between one X and the next have to be very small. I'd try dividing X & Y by 64 or 32 to get something in the ballpark of what I displayed.

The "base" scaling factor in my app is 1/256 if I remember correctly, and the example I put up was 6 times that.

So try this:
1  
 noiseValue = noise( (x * 6) / 256.0, (y * 6) / 256.0);  

Or put in a simpler expression like (x / 43.0, y / 43.0);, and be sure and make the division result in a double, don't do integer division.
If you are using Gustavson's SimplexNoise, that should get you pretty close.
6  Game Development / Newbie & Debugging Questions / Re: Perlin noise that looks like this on: 2014-10-13 19:27:04
Just thought I'd add a note about "frequency". It is probably the most confusing thing for people first trying to understand how to use the noise() function.

In the pseudocode in the previous example, I wrote the following:
1  
 noiseValue = noise(x * xScaling, y * yScaling);

The "frequency" is referring to the amount of scaling used on your X & Y values before making the method call. One reason for the use of the term is that folks like to make the combination of noise() methods a fractal process, thus each "frequency" is set to be an octave (or doubling or halving) of another.
7  Game Development / Newbie & Debugging Questions / Re: Perlin noise that looks like this on: 2014-10-13 19:18:09
Playing around with http://hexara.com/SimplexVisualizer.html I got the following, which seems pretty close.


Here is a screen shot of the settings I used:



Basically, what @LiquidNitrogen and @CptSpike is correct. The noise() function returns values between -1 and 1, and we want to scale the results to something like 0 to 255 for graphics output. The method of scaling used for your example includes an absolute value. This form of mapping was termed "Turbulent Noise" by Ken Perlin.

For example, (pseudo code)
1  
2  
3  
4  
5  
for ( all y values)
  for ( all x values)
     noiseValue = noise(x * xScaling, y * yScaling);
     noiseValue = Abs(noiseValue) * 255;
     postValueToImagePixel(x, y, noiseValue);


A "Smooth Noise" mapping would be more like the following:
1  
  noiseValue = ( (noiseValue + 1) / 2.0 ) * 255;


I don't know about your particular noise() function, or why you are putting 4 parameters in it. With Gustavson's Simplex Noise implementation, you only need the X & Y for 2D noise.

Your pattern might have a bit of "clamping" to it on the black end. That can be accomplished by something like the following:

1  
2  
3  
    noiseValue = abs(noiseValue);  // applies 'turbulent noise' algo
    noiseValue = ( noiseValue * 1.2 ) - 0.2; // scale and shift
    noiseValue = max(0, noiseValue);  // "clamp" levels below 0 to 0



Another possibility is that the multiplication in the second step above is omitted, and the values simply shifted downward with the subtraction, then clamped. I say that because it seems to me the results don't get as bright as I expect at the white end, so maybe the shift was uniform across the entire response range, rather than being "stretched" by the multiplication first.

There may be a second noise function being summed in, in which case the noiseValue starts out as the weighted sum of the two calls to the noise() function, before going through the various transforms to make the number an intelligible color value.

You can download the jar of Sivi from here:
http://www.java-gaming.org/user-generated-content/members/27722/sivi.jar
Or, check out the github open source here:
http://github.com/philfrei/SiVi
8  Discussions / General Discussions / Re: painful maths that will hurt your brain... on: 2014-10-12 01:42:14
Is it solve for X?

First thing I would do would be to break it into two pieces. But I'm not sure what the two pieces would be.

Is it

(log x (274625) % 17 

--or--

log x ((274625) % 17 )

??

I've never solved an algebraic equation with a modulus before. It seems to me that the modulus implies that X could be a series of numbers rather than a single number.

For example, if the question were solve for X:

7 = Y % 17, the answer would be

Y = (n * 17) + 7

Some hotshot will have an answer for you, I bet, before too long.
9  Discussions / Miscellaneous Topics / What are possible front ends for a java audio library? on: 2014-10-07 07:00:48
I have a friend that has been dabbling with programming, and is interested making use of some functionality in a Java library that I wrote for mixing and playing back audio files.

I'm trying to brainstorm on some options for GUI building for him.

I don't think he wants to try and tackle Swing (main thing I've used for the little apps I've made), but he seems somewhat interested in JavaFX. He has a bit of experience with Python, so JPython is another real possibility, I assume. I've never actually linked JPython and Java in a single program before though. Is it just a matter of importing libraries, that sort of thing?

He is also intrigued by JQuery/HTML5, but I am not seeing a clear path to connecting from there to functions presented in a Java .jar file without going through some very high latency steps. Perhaps the only way that might work as a front end is if the Java .jar file is converted to Android or JavaScript? I'm not clear if these languages are fast enough to handle audio processing at a reasonable latency.

Or am I mistaken, and if I convert the Java to Android, HTML5/JQuery is not an option, but instead Android's own GUI language would be used?
10  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-06 19:04:02
Just bypass the InputStream step. The InputStream imposes the markability test on the file, and audio files often (usually?) fail this test.

There are two other ways to make an AudioInputStream, using either a File or a URL as the input parameter instead of the InputStream. Neither one of these subjects the audio file to the markability test.

Details can be found at the API for AudioSystem.getAudioInputStream.

A lot of us have run into this very problem, but fortunately the fix is simple.
11  Discussions / General Discussions / Re: How do you come up with ideas for games? on: 2014-10-02 16:20:38
I don't find it hard to come up with ideas, particularly. Last night, for example, watching a PBS Nature video about Penguins (episode 2 of 3-part series), just about every second dramatic scenario shown seemed like it could be turned into a decent little game with a bit of tweaking. Penguins are cute, too.

Animals in general, and nature & science videos in general can provide lots of inspiration. But some days it seems like just about anything could be turned into a game. Some things lend themselves more to strategy than first-person, of course, or to another game type.

I have long entertained the idea of having a first-person game from the point of view of a young mountain lion that has left "home" to establish its own territory, and blunders into civilization. There are many instances of this happening in real life, here in California. I suppose the scenario could be handled from almost any perspective (e.g., you are a state Ranger tasked to capture the animal before it hurts anyone). The thematics are nice in that encroachment on habitat is current & relevant. Could be a good 3D game with neat overland running animations, but would probably require a big team to do well. Not so good for 2D?

Maybe the issue with ideas is to not dismiss them too quickly. Give them time to simmer, play around with them. Also, try and be open to whether or not they strike some sort of internal chord or resonance. I suppose the mountain lion scenario appeals to me because of feeling a bit of a connection to the problem faced by the animal. Maybe the key is to note whatever you come across in life that feels cool or interesting personally, even if it doesn't make sense as a game at first, even if it seems to have dark or embarrassing elements. Then, just try playing around with it, try applying different game models to different aspects, and see if something pops out.

I was always partial to baths for inspiration. It worked for Archimedes.
12  Games Center / WIP games, tools & toy projects / Re: VERBAL - the fast-paced thinking word game on: 2014-09-24 09:32:21
Was hoping to give this a try, but I don't have any Android devices. Is there a .jar version that can be downloaded?
13  Game Development / Shared Code / Re: Like Simplex Noise but don't like the patent? Introducing OpenSimplex Noise! on: 2014-09-24 09:23:30
OP: I just turned up a multiply factor and started to see results in line with my expectations, so I think the problem with your code is that it's isn't returning full range.

Gustavson's version from the paper is out of date, at least the last time I looked at the paper, check the code: http://webstaff.itn.liu.se/~stegu/simplexnoise/

Quote
... all the doubles to floats in ... no measurable performance difference
I use singles because doubles don't bring anything to the table.  On intel the time to issue and latency of single and double add/mul are the same so without reading/writing they should be the same.  Who knows embedded devices might take off sometime in the future which don't use intel desktop/mobile CPUs.
Makes sense. I think the bottom graphic looks a little "faded" compared to the top, which had me wondering if the new version wasn't reaching the same extremes in range.

I didn't know that the difference between floats and doubles are not so much in calculations, but in pipeline. Thanks for that! That is also in line with what I experienced.
14  Game Development / Shared Code / Re: Like Simplex Noise but don't like the patent? Introducing OpenSimplex Noise! on: 2014-09-23 19:16:59
I tried converting all the doubles to floats in Gustavson's version a couple weeks ago, and found no measurable performance difference. Maybe this says more about my benchmarking ability than the code.

This is the first I've heard of patents being an issue with the Simplex algorithm. I have an app with a background graphic where 2D cirrus clouds are floating by, making use of 3D translation. I'm wondering if this use requires any sort of payment. Right now I'm just acknowledging Gustavson, as he requests in his code.

Roquen makes a very good point about performance being relevant. At this point, I'm calling the Simplex graphic effect a "placeholder" because it uses over twice the amount of cpu of the main program, e.g., a usage level of 15% jumps to 45% when I turn on this skin animation. So, I'm glad for the reminder, and will be giving Roquen's a try again.

Roquen: marketing and pitching is an art. (Just finishing reading Jane Bussman's "A Journey into the Dark Heart of Nameless Unspeakable Evil"--Hilarious, with many insights into how the world works. I recommend it to all JGO'ers.) 
15  Discussions / Miscellaneous Topics / Re: Whays the story behind your name on: 2014-09-21 01:31:11
<engage creaky voice> Back in the old days of main frames and CRTs, we were only allowed 8 chars for our names, and a common approach was to take the first four letters of the first and last name and paste them together. So, the name isn't just an uninspired act of non-creativity and boredom, it is referencing a bygone age.

I also use Adonax here and there. This is a shortening of "Arundo Donax" or, a. donax, the cane used to make reeds for clarinets, saxes, bassoons, and my main instrument, the oboe. Oboists get stuck spending a lot of time with a. donax, scraping reeds to play. It cuts into time I'd rather spend playing the instrument or programming, or in fact, into time where I'd rather being doing almost anything else.
16  Discussions / Miscellaneous Topics / Re: The price of Pizza and Games on: 2014-09-19 16:07:45
In a free and open market, price is a result of supply vs. demand. The affect of costs associated with making the product are secondary. But that doesn't stop manufacturers or fear-mongers from invoking the classic "they'll just pass the costs on to consumers" when some measure or another that will potentially lower a profit margin is proposed.

I say "secondary" because the costs don't directly affect demand, or what a consumer is willing to pay. But if the prospect of reduced profits ends up causing some manufacturers to drop a product altogether, then that does affect the supply. In other words, the ability of the producer to "pass on costs" is limited, despite the political/rhetorical threats. They can try to do so, but risk losing significant market share, unless there is a monopoly or oligopoly, in which case you have bigger problems that need to be addressed!

Given that software can be reproduced so easily, by both the producer and by illegal copying, the supply is virtually unlimited. It is hard, in such a situation, to avoid the "race-to-the-bottom" in terms of price competition. I guess the main thing that allows a price to stay high is if there is a sort of de facto monopoly. In other words, the price point can be maintained mostly to the extent that the game is unique or has unique qualities. As far as your average clones are concerned, the near-infinite supply can result in an situation where you can't give them away. Only Google profits from them because they profit from web traffic.

If you are looking for books, I think a basic Econ 101 or Intro to Econ would cover most of this.
17  Discussions / General Discussions / Re: Microsoft to buy Mojang for $2 billion? on: 2014-09-16 21:16:28
In trying to figure out if "luck" was involved or not, it might be useful to look at the discussion around "black swans".

http://en.wikipedia.org/wiki/Black_swan_theory
Quote
The black swan theory or theory of black swan events is a metaphor that describes an event that comes as a surprise, has a major effect, and is often inappropriately rationalized after the fact with the benefit of hindsight.
18  Discussions / General Discussions / Re: Microsoft to buy Mojang for $2 billion? on: 2014-09-15 18:48:04
"Reputation" is a life-long project.

I'm certainly not in a position to judge, never having experienced the amount of responsibility that comes with that much wealth or having creative control of a product with that much mind-share.

Another thought: this is more a conversion of state than anything else, from Kinetic to Potential energy.
19  Discussions / General Discussions / Re: Microsoft to buy Mojang for $2 billion? on: 2014-09-12 22:06:20
It's clearly more than a rumor, though Reuters says it is not a done deal yet. They say there will be an announcement on Monday.

Microsoft needs MineCraft to boost mobile ambitions
http://in.reuters.com/article/2014/09/12/us-mojang-microsoft-idINKBN0H72EV20140912

Figures from article:
  • MineCraft has 100 million players.
  • MineCraft is being offered $2.5 billion
  • MineCraft is being offered about 1/8 of last year's sales <$312.5 million>
20  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-12 06:37:32
Quote
dont you think "send sounds through the microphone" sounds like a microphone acting like speaker, starting to talk ?
Most people understood it like that Tongue

That is what I was thinking when I wrote that. It's not entirely far-fetched as a possibility. I think a couple others also noted that the microphone can be made to vibrate and make a signal, although it isn't very efficient. I have a vague memory of hearing this done once on some crude equipment. And Java has some capabilities about identifying and accessing different lines.

I wasn't intending to be sarcastic, except maybe to poke at some folks that actually do think we are being taped via our speakers by the government. I've run across a few people like that.

I clicked an appreciation for Cero earlier for explaining the question. Thanks again.

Ah well, not every post is a success. I'll accept a face palm.
21  Game Development / Newbie & Debugging Questions / Re: Is it Possible to use Java and send sounds through the microphone? on: 2014-09-11 20:31:21
I'm still stuck at the concept of using a microphone for playback. Am I missing something? I can't imagine that even if the mic line could be manipulated, the physical microphone itself could make an audible sound. Shall we also discuss using speakers as microphones? (Or maybe the NSA/CIA already do this...  persecutioncomplex )

That was a joke.
22  Discussions / General Discussions / Re: Microsoft to buy Mojang for $2 billion? on: 2014-09-11 20:22:12
This might have more to do with access to the user base, not the actual income generated by the game. There is a whole generation of kids that just love Minecraft. That is all they want to do. It is truly huge.
23  Game Development / Newbie & Debugging Questions / Re: Referencing from one obj to another on: 2014-09-05 22:08:46
Or just don't require that the Map knows about the player. I don't see why one would.
When I program sometimes I have a camera object within my player object and then handle the render of tiles within the world map so the player would be required.

Perhaps the "player" can or should be a parameter to the various map methods rather than an instance variable. That would be more of a "Functional Programming" way of coding.

Seems like you are trying to do too many different things with one class. The Map sounds like it should be data-oriented. Another class could be responsible for the rendering, using the map as one of the input parameters.

If you are looking for Java books to read, I'd also like to recommend "Clean Code" by R.C. Martin. I happen to be rereading "Effective Java" at the moment, or rather, consulting it once again. It is a terrific book, but not an easy read at all. It took me 3 or 4 attempt and a couple years of experience to finally get to where I could make sense of the terminology and ideas. I still wouldn't say the book was entirely comprehensible to me.
24  Game Development / Newbie & Debugging Questions / Re: [solved] Updating & Rendering in a timely fashion on: 2014-08-31 04:04:57
@SHC
I always found that quote from Eli to be very puzzling. So, util.Timer was not intended for heavy-lifting? How can a person tell this? It's just code. Nothing in the API warns about this, nor anything in Joshua Bloch's well-documented source code for the class. Code in the TimerTask runs the same as code in a game loop, as far as I can tell, though they rely on different native routines (wait vs sleep).

@BurntPizza
...doesn't the exact same thing happens when update() and render() take more than the allotted time: the next iteration simply gets pushed back? This is the same with the ScheduledExecutorService (as you configured it), with util.Timer and with a game loop. Yes?

But if the NEXT iteration after that takes less than 16 millis, with either the scheduler or timer's .sheduleAtFixedRate(), an attempt to recover the lost time, gratis, no extra coding needed.

I suspect that the poor reputation util.Timer has vs. coding one's own timing mechanisms into game loops has an element of "herding behavior" to it or some sort of echo chamber effect. I have yet to read one rational explanation or see a concrete example that justifies the preference. I point out again, even "Killer Game Programming" from way back when gets the same performance with util.Timer as with their preferred game loops, and then says well, we are going to stick with writing our own game loops anyway. (The book does an excellent job of demolishing the swing.Timer, though!)

But this is okay. It probably doesn't make a bit of difference, and my harping on this is an example of I don't know what. I certainly don't want to try and tell other people they should convert their game loops to TimerTasks.
25  Discussions / Miscellaneous Topics / Re: Music in games? on: 2014-08-30 04:36:13
I haven't really researched this as much as I should, but I think that sometimes a game maker and a composer can work out a mutually beneficial arrangement. For example, the game maker is allowed to use a piece, but provides links to the composer's site or to a place where the game player can buy an mp3 or song file that is an arrangement or version of the game music.

The one example I recall like this was in a game called "Entanglement".
http://entanglement.gopherwoodstudios.com/
Somewhere on their site, if I remember correctly, they talk about the music and give a link to the composer's site where a purchase can be made. They may have payed a small fee upfront. I can't recall the details--it was a couple years ago when I found this and filed it away as something to eventually try out myself.

The music for that particular game is NOT what you described as would fit your game. But maybe if the composer finds those sorts of deals work, chances are the composer can also write something more along the lines of what you are wanting.

If that doesn't work, or you find yourself still looking for music a few weeks from now, I have a special case situation that could allow some sort of trade off. I've been working on a procedural music engine, and am looking for an opportunity to give it a go. Your post reminds me of a poppy, driving synth piece I wrote a long time ago (played it in a rock band in the 1980's actually, but that band didn't make it out of the garage) that I think is exactly the sort of thing you describe. But this isn't a situation where I'd just record it and hand over cues. I want to have the game play the score procedurally. So, your game would have to have some slack processing capacity, and you'd have to have some time. (We'd work out an api between us customized for your game, and I'd supply the needed libraries.)

A very simple working example of the procedural music engine is at this link:
http://www.java-gaming.org/topics/tanpura-drone-tuning-training-jar/34132/view.html
If you listen to the "SquareWave" and "Sawtooth" synths, and imagine that sound with a really punchy attack instead of a slow fade (very easy for me to reprogram their envelopes), those are two synths that can be run for pretty cheap (just two FM oscillators). I've also managed to get flanging/chorusing working and that does a great job of thickening textures. Of course, a circle of notes is a lot less interesting than a good rhythm, but this audio event system I wrote is capable of solid rhythmic precision. As I wrote on that post, that drone tool is a stepping stone project.

Ah, there is a lot here I really want to get to! If not your project, maybe in a few more weeks I'll have a better demo of what I'm talking about, and a proposal like this won't be so speculative. Cool But also, there do remain unproven aspects--I still need to tighten up the coding so it uses less cpu.  Emo
26  Game Development / Newbie & Debugging Questions / Re: *solved* Updating & Rendering in a timely fashion on: 2014-08-29 23:57:02
Quote
using Swing or other "timers" is fine. all of them use System.sleep(1) anyway.
@basil_
Well, sort of. The util.Timer relies on native code implementing Object's wait(long) method. It is set to a value that corresponds to the schedule of the next TimerTask on its internal queue. Thus the wait is probably larger than 1.

Thread.sleep(1) uses native code for sleep(long).

But both do make use of the System Clock which is either limited by larger of the granularity of the milliseconds input parameter, or by the minimum interval at which the clock is updated (about 16 millis for some older Microsoft OS).

I don't think the util.Timer adds much in the way of overhead. The most significant addition is a very nifty queue implementation set up for the TimerTasks (I think it's set to a simple array of 128 unique tasks), but it is a model of efficiency (written by Joshua Bloch). I would guess having a single wait(long) is probably better than multiple calls to sleep(1). But these are quibbles to your main point.
27  Game Development / Newbie & Debugging Questions / Re: *solved* Updating & Rendering in a timely fashion on: 2014-08-29 07:38:08
Quote
Never, Never use Timer and TimerTask for game loops, they are mainly designed with Swing in mind and may not work well for a gameloop.

SHC -- Could you be more specific about your objections to the util.Timer? I've never had a problem with them, and there is nothing that I know about them that is specific to Swing. AFAIK, you can put any commands you want in them. You're not confusing the util.Timer with the Swing Timer, are you? I would agree that the Swing.Timer is not good for game programming due to performance issues arising from the potential EDT bottleneck.

Eventually, one can graduate to an Executor Service with a fixed schedule--that might be slightly preferable. But that would be a lot to learn for a Newbie. Better to get on with entity management, movement physics, collision detection, etc., imho.
28  Game Development / Newbie & Debugging Questions / Re: *solved* Updating & Rendering in a timely fashion on: 2014-08-28 23:04:24
In this section:
1  
2  
3  
4  
5  
6  
    while (System.nanoTime() < startTime + nanosToSleep) {
        try {
            Thread.sleep(1);
            } catch (final InterruptedException e) { }
        }
    }

...I'm not sure the Thread.sleep(1) command actually does what one thinks it should consistently on all systems. The sleep command depends on the system clock, which is a different time source than that of System.nanoTime(). (API for nanoTime() and Thread.sleep() elucidates this.) If you are on an old version of Windows, it might actually be sleeping longer than that.

Can also try the following:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
// import java.util.Timer
// assumes also a reference to the "game"

    Timer timer = new Timer();
    TimerTask task = new TimerTask();

    timer.scheduleAtFixedRate(task, 0, 16);  

    class GameLoopTask implements TimerTask
    {
        game.update();
        game.render();
    }
}


It might be interesting to put in a counter to check the actual frame rate and compare.
29  Game Development / Game Mechanics / Re: Getting into multi-threading. on: 2014-08-25 21:21:43
I think princec's statement about restricting multithreading to situations that don't require synchronization or have dependencies is a good one. What I want to add is the point that if you learn more about "functional programming" techniques and use them, the set of possible situations that do not require synchronization or dependencies will grow, creating more situations where multithreading can be used without the synchronization headaches or complications.

Example of functional programming strategy: using an immutable object, from the Java Tutorials:
http://docs.oracle.com/javase/tutorial/essential/concurrency/imstrat.html
I often use a construction almost identical to this, collecting variables into one object. It's helpful, among other things, for keeping objects subject to multithreading in consistent states, and can work well with the paradigm of separating data/models/presentation.
30  Discussions / Miscellaneous Topics / Re: Best books for programming in general? on: 2014-08-22 23:03:49
LOL for ags1's recommendations!

I'm finding "Clean Code" by Robert C. Hunter helpful. Definitely the newer things I've written that follow his suggestions have proven to be easier to read and modify, and less buggy, than other code I've written.

I'd supplement his approach with learning more about functional programming techniques, but I don't know exactly what to recommend for that. A lot of the FP writing seems to take things to extremes, at least to my spotty programming knowledge and experience.
Pages: [1] 2 3 ... 35
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!