This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!

Stephen Bell

Ranch Hand
+ Follow
since May 11, 2013
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
12
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephen Bell

Paul Clapham wrote:
I don't believe the compiler will look through your class hierarchy



Thanks Paul, yes I agree that is probably the case, I just wanted to make sure I was on the right page and understanding things.  It just confused me because I know when casting objects the compiler does seem to look through the hierarchy and making classes final can affect whether the compiler will allow something to compile or throw an error.  I thought it might be the same when using Generics but I guess not.

Thanks very much!!
2 years ago
Just out of interest, I've noticed that the opposite will not compile (assigning a Upper-Bounded ArrayList to a Lower-Bounded List reference) even when I would expect it too...

   

So, the above list can only really be of type 'SemiDet' as that is the 'lowest' class in my hierarchy, ie, it has no subclasses.  Now, if I try this...

   

... it doesn't compile even thought 'upperBoundedList' must be of type 'SemiDet' and 'lowerBoundedList' can assign an ArrayList with a type of SemiDet all the way up to 'Object'.

I think I understand why, but I'd like to run it by you guys, I think it's because although SemiDet has no subclasses, the compiler doesn't take this into consideration.  Because I've declared my upperBoundedList with a Upper Bounded wildcard, <? extends SemiDet> it just assumes that subclasses could exist and therefore won't allow me to assign it. (say I had a TwoBedSemiDet that extended SemiDet, then upperBoundedList could be of type TwoBedSemiDet which obviously wouldn't be assignable to my lowerBoundedList reference (as its lower bounds is SemiDet).

It's odd though that it still doesn't compile even if I make SemiDet final and therefore exclude the possibility of subclassing it.

As alway thanks for your valuable help! :-)
2 years ago

Henry Wong wrote:

Can someone with deep knowledge of generics explain this one? First, it is using the diamond operator. This means that the type of the generics (that is being instantiated) is inferred. However, it is also using the wildcard. So, what is the type of the generic? How is it inferred? I have seen code like this before, and this always bothered me....



That's interesting because I've wondered this too!  I've always assumed that the inferred type of the instantiated ArrayList is the actual Upper/Lower bound, so in the following example...



I've always assumed the inferred type is 'Residential' - can anyone confirm this?
2 years ago
Piet,

I think I just got what you mean :-)

I'm forgetting about 'Object' and not factoring that in, so in fact, upperBList isn't compatible with all possible types of lowerBList because lowerBList also includes 'Object'?!

Thank you so much  for pointing that out - I can't believe I didn't see it, I've been trying understand this for hours!!

Regards
2 years ago
Hi Piet and many thanks for the reply!

Yes, I've been starting at the compiler message for ages and I can't figure it out.

I realise that the last 4 examples I gave compile OK - that's what was confusing me, they seem to be equivalent to the line that doesn't compile (ie, all the possible types of 'lowerBList' are valid for 'upperBList' (or so it seems)).  I know that list with upper bounds are not modifiable (well, apart from clearing it or removing elements). But I just can't understand for the life of me why the assignment doesn't compile - it's very confusing :-(

the 'So the compiler cannot guarantee that '? extends Building' is correct, and therefore it won't compile.



Could you clarify this part for me please?

Many thanks for your help, really appreciate it!
2 years ago
Sure, the compiler throws this at me...

incompatible types: List<CAP#1> cannot be converted to List<? extends Building>
where CAP#1 is a fresh type-variable: CAP#1 extends Object super: Residential from
capture of ? super Residential



Many thanks
2 years ago
Greetings all,

I'm Having a few issues understanding something regarding Upper and Lower Bounded Lists and would really appreciate if someone could help me understand what's going on here!!

Let's say I have a simple class hierarchy: Building > Residential > House > SemiDet (SemiDet extends House, House extends Residential and Residential extends Building).

Then let's say I create a List with a Lower Bounded type...



Now, the type of the above List can only be Residential or Building.  So, let's say I now create another List reference (this time Upper Bounded) to which I will attempt to assign my first List...



I'm trying to figure out why the above fails to compile.  The type of of upperBList can be either Building, Residential, House or SemiDet and lowerBList can be either Residential or Building, so should this not be assignable?

In other words, all of the following are valid...



Am I missing something!?

Thanks all, appreciate any advise that could improve my understanding :-)
2 years ago
Thanks for the replies all, much appreciated!
4 years ago
Greetings all :-)

I have a question regarding basic object creation and would be grateful for any guidance.

Let's say I have a class 'Vehicle' and from this class, I want to create 3 objects.

So, I might have:


Now, lets also say, that each 'vehicle' has a variable that is only useful for a particular Vehicle type. For example:

The car object needs:

The plane object needs:

And the bicycle object needs:

I could create 3 new classes that all extend from the Vehicle class.

So I could then do something like:


Where the classes Car, Plane & Bicycle, all extend the class Vehicle.

All of my specific variables could then of course go into their respective classes.

Is it excessive to create child classes simply to hold a few or boolean/ints?

What are the other options?

I could just put all three variables into the Vehicle class, but each object would have 2 unused and irrelevant variables (more, if I had to create more vehicles with specific and unique properties).

So is the first option the 'correct' way to do this or am I missing something!?

Thanks!
4 years ago
Hi all,

Prior to Lollipop I was doing the following ('bd' and 'backgrounds' are both declared prior (not shown here)):



This did work great, however since updating my Nexus 10 to Lollipop, this no longer works correctly.

When I exit and re-launch my app, sometimes, the bitmap (backgrounds) is, by all accounts, already recycled (even before I've actually called recycle on it - as if its remembering being recycled from the last time the app was launched).

This bitmap is being applied as a texture to Open GL Quads, so as soon as this has been done, they are no longer required. They are also pretty big so I really want to get rid of them.

Why does this happen? How do I correctly recycle these types of bitmaps (from XML)? If I get it via BitmapFactory all is OK, however, in my case, BitmapFactory unfortunately isn't an option.

Thanks all - hope someone can advise
5 years ago
Hi All

I'm attempting to smooth out the animation of my sprites using interpolation and am have a lot of problems.

I've managed to get some success using this method of applying the interpolation during my render call:



When the sprite is moving, it is almost perfectly smooth (it's like a 95% improvement on no interpolation) but when the sprite is static, the interpolation is still applied and the sprite therefore has a 'wobbling' effect. (It also play havoc with my collision detection but that's for another day!)

Now, I've come across another method, which seems more sensible. This method necessitates us saving the sprites previous position so the following calculation can be made in the render call:


Now, this doesn't wobble when the sprite is static, because the difference between the current and old positions would be 0. However, when the sprite moves, there is no improvement in the choppiness. It also seems to behave better with regards to collision (but this is probably because it's not actually interpolating correctly!)

Oh, and this is my game loop showing how I work out my interpolation value:



I would be very grateful if somone could tell me why the 2nd method doesn't seem to be doing anything.... is the calculation wrong? How do I go about interpolating between an object's previous and current positions?!

Thanks all!


5 years ago
Hi all

Really hoping someone can help me out here. I've written an android Open GL ES 2.0 game and my logic update calls and rendering calls are running on the GL Rendering thread. I'm also using a fixed time delta, not variable.

The code for my loop is below. The problem is that the animation just isn't smooth. It will run for a second or 2 smoothly, then it will become 'choppy' for a little while, then return to normal.

The 'choppiness' is present if the sprite is moving fast or slow, but is a lot more noticeable with faster moving sprites.

I have 2 test devices, a Google Nexus 10 running KitKat and an old Samsung Galaxy Ace running Gingerbread. Now, if I change my 'maxFramesSkip' value from 5 to 1 it runs perfectly on my Nexus 10, however, on the Galaxy Ace, it seems to speed up and slow down, so I changed it back to 5. At andvalue other than 1, the animation is choppy.

I've tried interpolation but this has no effect. I've included my code here for that too.

I can't understand why this is happening. I should point out that my rendering takes a maxumum of 14ms to complete and the logic updates take a maximum of 4ms to complete. So there should be no frame skipping. I'm therefore wondering if there is something wrong with my loop? I'v spent literally months trying various things, but nothing produces smoother animation. So i'm hoping someone with a better understanding of game loops can help me out!!

Any help would be apprecated!

Main Game Loop



Interpolation in render()

5 years ago
I'm nearing completion of my first Android app (a game written using openGL ES 2.0) - I've tried to put AdMob banners in and found they don't fit :-(

My game is a single/fixed screen 2d platformer. I have the game area and a control panel at the bottom which houses the controls, score, lives etc

I had left a space under the score but, being a complete AdMob beginner, didn't realise the banners could only be delivered using 'standard' sizes.

So now I realise I can't scale the banners, I have 2 choices:

1) Completely re-design the game/'s UI and put a banner at the top - this, I guess, is an option but would mean the controls actually being on the game play area which, on a small phone, could be quite annoying. It's also proving extremely difficult getting the ads to fit nicely across different devices. I've tried various things, and am going to keep attempting to make this work.

2) Do away with banners while the game is actually being played. This would mean that I have a banner on the main menu, the level-select screen, the get ready screen, game over screen, game completed screen, and any other non-gameplay screen

I'd appreciate a bit of advice from seasoned mobile developers. I obviously want to monetise my app as best I can.

Which of the 2 options would you take? Am I likely to miss out on many click trough's by omitting the ads in game-play? Any help anyone could offer would really help - thanks!
5 years ago
Hi All

My game is written using openGL on Android and I'm having a bit of a hard time trying to understand the main game-loop

I've read Dewitters Game Loop many times, and it's a really good article. However there are some things it doesn't address.

At the moment, this is what I have:



At the moment, all I'm concerned with is limiting the game updates (ticks per second). As for rendering I can leave that for another day, so right now, this loop is supposed to limit the ticks per second to 60 and let the rendering go as fast as the device can handle.

However, when I run this on my tablet (Nexus 10) the result isn't quite what I'd hoped, it averages between 62 and 65 and when I run it on an old Galaxy Ace handset, it could be the same or slightly higher.

Can anyone see anything obviously wrong with my code?

Many thank all!


6 years ago