Mich Robinson

Ranch Hand
+ Follow
since Jun 28, 2009
Merit badge: grant badges
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mich Robinson

I don't think I have access to a profiler so I spent a bit of time looking for likely suspects in my code and then playing the game for approximately 30 mins each time and manually getting some stats. If calls take less than 1ms then they show as 0ms.

I looked into assigning the offscreen buffer to the onscreen buffer. I'll admit it's not very efficient but it just showed up as running in 0ms each time.

A few things could be moved to a background thread (collisions between bullets and things and things and other things, the movement of explosions and smoke etc) but these again seemed to run fairly quickly. I'm not sure it would be worth the effort to create a separate thread. There'd also be the inevitable issues from having 2 threads playing with the same data. There is a fancy sun animation that could also run independently but, again, it ran fairly quickly.

The major culprit seemed to be a drawExplosions call which mostly ran very quickly (average of 0ms) but there were 5 calls when it took longer than 20ms and one call that took 41ms. It would be totally OK if the paint was happening in the background but, because it's running in the main loop, there's a slight pause in play. The explosions are either flames, solid bits that fly through the air when aliens are shot or particle effects. It's the particle bit which seems to take the time as one explosion might have 20 small rectangles of colour being drawn with the colour slowly fading to transparent. I think I can get round this by seeing what type of explosions affect the draw times and then monitor the time to age out these explosions more quickly when timings are getting affected.

I assume there's no easy way of altering my existing structure so the paint simply happens in the background? (I'm reading through the article that was linked to).

7 months ago
I believe that's what I'm doing. I write to the offscreen framebuffer "og" and, when the work's done, I write it to the main framebuffer "g". That's done in the current paint routine. The game is fairly smooth at 28 FPS (at 800x600) but obviously the paint is being done in the main loop. This means that if there's any delay in the drawing then this delay is reflected in the movement. It doesn't happen often, maybe once every 10 mins on a slowish PC, but it's annoying. This is the main reason for trying to get the paint done outside the loop.

I was hoping for a simple hint/explanation on how I could tweak my code but maybe that's not possible with how it is.
7 months ago
I'm not actually sure what a Swing display is It's in full-screen exclusive mode if that helps and the resolution has been changed to 800 x 600. I will admit that it doesn't work for wide screen laptops as it just creates the game in a window. The display is created just using lots of drawImage calls. Not sure if it helps but the title screen looks a bit like this.

Is there a simple way of getting the paint method to run independently of the main method using the structure I have?
7 months ago
I'm in the middle of writing a game and I'm fairly pleased with it's progress. However, at the moment, I call paint directly from the main game loop. So the FPS is linked directly to the main loop. I'd like to have the paint method running independently so the FPS will be independent of the main loop but I'm not sure how to do this.

I tried to show the bits of code that illustrate my question. Can anyone suggest how to get paint running independently?  Preferably in a way that a fool like me can understand

7 months ago
Thanks for the advice. I'll admit I come from a very procedural background and find OO a little weird. I did wonder why I saw definitions of arrays in the 2 formats ow I know.
Is there any performance cost in using arrays like this? or do I need to be more careful with garbage collection? I know this might not look pretty but it's infinitely better than the other approaches I've tried.

Many thanks for the fast responses!
Much appreciated.
2 years ago
I'm trying to develop a fairly flexible routine to move text  and images around a screen as part of a games library. There's a whole bunch of params that can be used so the position part might have X & Y and optionally a starting X & Y or perhaps no position info in which case it goes in the centre of the screen or perhaps it might reference one of the items on screen in which case the message will get printed near by. I have similar options on movement and timings and colours plus other random stuff. I don't want to have a single method with a 100 params. I tried defining different versions of the method that used different sets of params but I'd end up with 100's of methods instead. Today I started experimenting with passing a number of variable length arrays for the position, movement and timing info. This looked like a viable solution but

Is there a way of writing it like (A) that I'm missing?
Is there a better approach altogether?
The problem with (B) is that it looks messy and I'm not sure whether defining and creating all these arrays is efficient as it's used in various real time games.

Thanks for reading
2 years ago
Thanks for the replies. The manuals are useful when you know what you're looking for but personally I just don't know. I don't use maven etc but one of these days I might work it out. The post about the jars made me wonder what would happen if I just put the jar files in a zip along with the exe. This seemed to work when I created a new directory for the program but unfortunately it didn't work when a friend downloaded the zip, extracted it and tried to run it. It unpacked ok but nothing happened when they clicked the exe. If I did the same on my PC it runs fine. The exe was created by launch4j and is supposed to include its own java run time etc. I have to admit this is a little infuriating.

Any other suggestions for generating an exe program that people can just run? The game plays fine but my goal is to put the program on Steam and have it loaded (and run) from there.
3 years ago
A fat jar just includes all the dependant classes in the jar file.
I need the fat jar because I'm deploying the application as an exe via Launch4J.
When I move the exe to a different directory then it won't without the dependant classes being present.

My problem is I'm a bit of a dinosaur when it comes to java in that I don't use IDE's etc.
The commands I use to build my game and run it are:

How do I change this so the jar becomes a fat jar?

Many thanks

3 years ago
That's pretty much where I got the original code for doing full screen.
4 years ago
I write old style arcade games as a hobby but I'd like to try selling them on steam (you have to dream). I like to use low resolutions (800x600) because this matches the styles of the games. At the moment I use basic java for everything but I find it isn't very reliable when it comes to producing a full screen application and that's my big issue. I use the standard full screen stuff but on my own PC I need to set the run time flag nodraw=true else I just get a black screen while it runs fine on my son's PC. On my moderately widescreen laptop it just runs in a small window. I thought Java would be naturally suited to this but ...

I wondered about JavaFX but obviously I'd have the issue of learning a new library (I'm a bit slow witted when it comes to other peoples code). All I need is the ability to draw an image and write text, certainly nothing special. Does anyone else have this issue and did they find a solution? Any suggestions or simple examples?

4 years ago
... and I should of said that the above calls do load the native calls etc so I didn't have to do anything there.
4 years ago
I managed to get in touch with the developer and it simply turns out the init had to be called before the restartAppIfNecessary call. This sounds obvious but was a bit confusing in the docs (at least to me). It's all connecting quite well now! I guess I have to be a little patient and wait for my AppId to be issued before getting any further but I'm quite pleased with progress so far.
4 years ago
I suppose that does make sense. I guess the jar file provides an interface to the native library but doesn't actually supply the native library. I'll try and work out how to load that up now.

I'll admit I'm not very comfortable when I'm using other folks code. Even if they're much better coders than me. Hey ho.
4 years ago
Sort of. The program now compiles with the new jar file which is great but raises an error when calling the new stuff. I don't have a lot of luck when working with libraries which is why I tend not to use them. I think my code is doing the right thing. 'm using a publicly available AppId of 480 just to try and connect to the Steam. It's a baby first step of connecting and disconnecting but I'm getting an error. I have the jar file in the same directory and use code like the following:

But when I compile and run I get the following:
Looking up on the web this seems to indicate an unsatisfied native link error. My mind went a bit blank at this point. Am I missing something with how I'm importing stuff?

4 years ago
Yep, already been through those pages. My question is really simple. How do I import the jar package so it will compile. I don't use other folks packages much and I don't use an environment that does all this for me. I assume I store the the jar file locally and then reference it via an import statement. I've tried just about every combo I could think of but haven't hit upon the right answer yet. Any suggestions?

4 years ago