Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 7 8 [9] 10
  ignore  |  Print  
  Things you disagree with in the java language  (Read 38282 times)
0 Members and 1 Guest are viewing this topic.
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #240 - Posted 2012-09-10 23:48:30 »

Then to add 2 pixels together:
1  
int pixel = (0xff << 24) | (((r1+r2) & 0xff) << 16) | (((g1+g2) & 0xff) << 8) | ((b1+b2) & 0xff);


Without wishing to hijack this thread (which I'm finding quite interesting) with a further discussion on pixel bit operations, that example from ra4king is wrong (doesn't do clamping).  I recommend this old thread which contains loads of working pixel blend modes based on bit shift operations.  Maybe start a new thread if you want to discuss further - I'd be tempted to claim it's off-topic, though this thread seems to be pretty much everything goes.  Grin
Oh damn I forgot about clamping!

1  
2  
3  
4  
5  
int pixel = (0xff << 24) | ((clamp(r1+r2,0,0xff) & 0xff) << 16) | ((clamp(g1+g2,0,0xff) & 0xff) << 8) | (clamp(b1+b2,0,0xff) & 0xff);

public static int clamp(int value, int low, int high) {
    return Math.min(Math.max(value, low), high);
}

Offline Icecore

Senior Member


Medals: 5



« Reply #241 - Posted 2012-09-11 00:17:27 »

As an aside: a fair number of unsigned ops are already in JDK8 mainline.
I become happy on 1 min ,before I don’t see this
http://cr.openjdk.java.net/~darcy/4504839.2/raw_files/new/src/share/classes/java/lang/Byte.java
1  
2  
3  
public static int toUnsignedInt(byte x) {
        return ((int) x) & 0xff;
}

Omg, is that so hard to add new primitive types ubyte, ushort, uint ? ;( (its rhetoric question)
Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #242 - Posted 2012-09-11 00:25:00 »

They can't add new primitives, since that would require new reserved keywords. This would break all applications that use 'ubyte', 'ushort', 'uint', and 'ulong' as identifiers.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #243 - Posted 2012-09-11 00:25:52 »

No it would require new bytecodes, which is a much bigger issue.

Cas Smiley

Offline ra4king

JGO Kernel


Medals: 341
Projects: 2
Exp: 5 years


I'm the King!


« Reply #244 - Posted 2012-09-11 00:26:53 »

No it would require new bytecodes, which is a much bigger issue.

Cas Smiley
Was that to me?

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 749
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #245 - Posted 2012-09-11 00:39:19 »

No it would require new bytecodes, which is a much bigger issue.
Not necessarily. The compiler can accept (the syntax of) the new primitives, use (elaborate) existing bytecodes to make a slow but correct implementation of the unsigned primitives. HotSpot can then optimize it back to native instructions. It's cumbersome, but doable.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #246 - Posted 2012-09-11 01:04:08 »

I suppose it could. My knowledge of bytecode is miniscule.

Cas Smiley

Online Roquen
« Reply #247 - Posted 2012-09-11 07:58:05 »

As an aside: a fair number of unsigned ops are already in JDK8 mainline.
I become happy on 1 min ,before I don’t see this
http://cr.openjdk.java.net/~darcy/4504839.2/raw_files/new/src/share/classes/java/lang/Byte.java
1  
2  
3  
public static int toUnsignedInt(byte x) {
        return ((int) x) & 0xff;
}

Omg, is that so hard to add new primitive types ubyte, ushort, uint ? ;( (its rhetoric question)

Intrinsics
Offline kaffiene
« Reply #248 - Posted 2012-09-11 11:00:29 »

The thread just gives me sympathy for James Gosling and the other language designers. All the devs at Sun telling them Do This, Do That... A pretty thankless task. All I know is I found C and C++ stressful and Java a joy to work with. As a self-taught programmer, I feel I can do creative things with Java, while with the C-team I spent my time worrying about memory allocation and pointer math.

Heh!  I totally agree with you.  That's why a said about a billion posts ago that despite the 1000s of things that are "wrong" with Java, there's actually not a lot wrong with it and it's really a very productive language to use.  Not to say that I hate C/C++ just that I get-shit-done(tm!) much faster, with less rework, less surprises and easier maintainability in Java than those languages.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #249 - Posted 2012-09-11 11:22:41 »

Everybody goes quiet for a while, and there is much supping and wiping of foam from programmer beardy moustaches.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #250 - Posted 2012-09-11 17:11:07 »

I have to agree with kaffeine there: most of Java's problems are sins of omission, which is a hell of a lot more than I can say for freakshows like PHP.
Online Roquen
« Reply #251 - Posted 2012-09-11 17:23:20 »

Designing a good language that's usable is very hard and Java is a quite well designed language.  I think that most of us can agree the most of the 'issues' are omissions of which the greater part of are due to the reality of timetables...couple with it's hard to remember "research" which is post some feature.  (example: someone said it would have been great if java had generics from the start...sure, but all the research was performed ON java, so without a time machine, it would have been tricky)

BTW: generics are contracts (I don't think that's been mentioned)
Offline sproingie

JGO Kernel


Medals: 202



« Reply #252 - Posted 2012-09-11 18:11:30 »

Parametric polymorphism has been around since ML in the 70's.  GJ and Pizza (both Java forks) had it well before Java was pushed into supporting it by more or less adopting GJ's version of generics.  Fact is, Java was conceived as a replacement for the Display PostScript system in NeWS, then positioned toward "set top boxes" which were a thing at the time.  At no time in the design of Oak was there really any intention of doing anything particularly revolutionary or even all that advanced (it's harder to write compact bytecode from advanced compilers), so it got caught playing catch-up for a while after it became Java.

One thing that served Java well was that Sun had the good sense to hire smart people or otherwise listen to them, such as hiring back the Self team who had moved on to do Strongtalk and get them to write Hotspot, or listening to Phil Wadler and getting GJ turned into generics.  The latter happened because of good relations with the academic community, something I fear Oracle is not going to pull off, if they even bother at all.
Online Roquen
« Reply #253 - Posted 2012-09-11 21:38:29 »

Correct me if I'm mistaken, but I was speaking mechanically.
Offline philfrei
« Reply #254 - Posted 2012-09-11 23:01:30 »

I am studying for the basic java certification test on and off. One thing I am finding annoying is that with Enums are "a special kind of class". Does anyone use them much? Ever take advantage of the benefits of having a "constant specific class body"?  Tongue

I do write my own final "constants" and use them, but haven't had or taken many opportunities to use Enum. That is probably why I am having trouble remembering how they work.

+++++++++++

For those of you wrangling about color operations on the int itself, have you checked out the JGO index? Here's one of several:

http://www.java-gaming.org/topics/fastest-color-addition-with-clamp-0-255-of-rgb/18379/view.html

Even has Markus_Persson's stamp of approval. I recall seeing a couple other in our archives, including some "fast" implementations by Markus.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #255 - Posted 2012-09-11 23:07:25 »

I use enums nearly all the time now instead of static final ints.

Cas Smiley

Offline pjt33
« Reply #256 - Posted 2012-09-12 00:02:06 »

No it would require new bytecodes, which is a much bigger issue.
Not necessarily. The compiler can accept (the syntax of) the new primitives, use (elaborate) existing bytecodes to make a slow but correct implementation of the unsigned primitives. HotSpot can then optimize it back to native instructions. It's cumbersome, but doable.
The operations are the same as twos complement for everything except division (and modulus, which is really the same thing). The VM would at the very least need bytecodes to convert the unsigned types to the signed ones prior to division and back after.
Offline actual

JGO Coder


Medals: 23



« Reply #257 - Posted 2012-09-12 02:45:07 »

I am studying for the basic java certification test on and off. One thing I am finding annoying is that with Enums are "a special kind of class". Does anyone use them much? Ever take advantage of the benefits of having a "constant specific class body"?  Tongue

I do write my own final "constants" and use them, but haven't had or taken many opportunities to use Enum. That is probably why I am having trouble remembering how they work.

Here is an article that shows you some of the neat things you can do with enums.
Offline kaffiene
« Reply #258 - Posted 2012-09-12 06:15:18 »

I am studying for the basic java certification test on and off. One thing I am finding annoying is that with Enums are "a special kind of class". Does anyone use them much? Ever take advantage of the benefits of having a "constant specific class body"?  Tongue


Hell Yeah!  I love Enums.

Here's an example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   
 enum HexType {
        SEA      (Resource.NONE,   new Color(0.5f, 0.7f, 0.9f)),
        PASTURE  (Resource.WOOL,   new Color(0.5f, 0.8f, 0.3f)),
        FIELD    (Resource.GRAIN,  new Color(0.9f, 0.9f, 0.5f)),
        MOUNTAIN (Resource.ORE,    new Color(0.5f, 0.5f, 0.6f)),
        HILLS    (Resource.BRICK,  new Color(0.7f, 0.4f, 0.3f)),
        FOREST   (Resource.LUMBER, new Color(0.1f, 0.5f, 0.1f)),
        DESERT   (Resource.NONE,   new Color(0.8f, 0.7f, 0.6f));
       
        public final Resource resource;
        public final Color    color;
       
        HexType(Resource r, Color c){
            resource = r;
            color    = c;
        }
    }


That allows me to have a collections of hex objects where each hex can tell me what resource type it produces and what color it should be on the map.  If I were using constants, I'd need associated lists or maps containing hex->resource mappings and hex-> color mappings.  It's much tidier this way because it keeps all the hex-related info in one place.
Online Roquen
« Reply #259 - Posted 2012-09-12 06:30:34 »

WRT: Unsigned again, no need for new bytecodes.  You almost never need new bytecodes.  Shifts and masks are trivial transforms and HotSpot is not a simple JIT.  Signed/Unsigned conversion has been fast forever.  Compares, divides & multiples have harder and more numerous patterns...JDK8 adds methods (with software backup implementations), runtime coverts to a single opcode, done.
Offline philfrei
« Reply #260 - Posted 2012-09-12 06:56:15 »

@princec, @actual, @kaffienne

Thank you for the thumbs up and the link and example. I have bookmarked the link. My brain is a little overfull--reading about the math for curves and having to keep going back and reviewing things like how to invert matrices. Tomorrow morning should be fresher and able to read the enum link.

I thought I was doing okay with enums until I hit an example certification question pertaining to the "constant specific class body" at which point my brain went tilt. (Some of the questions in Sierra/Bates SCJP are just nasty hard.)

It is a lot easier to deal with classes if the rules for classes stay the same, rather than have special cases and exceptions. This is why Clojure appeals to me so much more than Scala. (Haven't checked out the other new language people are mentioning here...ugh tired, can't recall it's name.)

Mostly, I think Java is the best. I am perfectly fine with verbose and explicit. (Can you tell from my tldr posts?) I also am coming from a Microsoft background, and find that world very frustrating and arbitrary. Consistency is a good thing, not at all a hobgoblin, in language design.

"Greetings my friends! We are all interested in the future, for that is where you and I are going to spend the rest of our lives!" -- The Amazing Criswell
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #261 - Posted 2012-09-12 11:07:21 »

The important thing about enums in Java is that they are consistent. It's all implemented under the hood just like ordinary classes and prior to Java 5 that's what everyone did. What enums do is just take out all the boilerplate and do it all for you and make sure you can't trip over the various gotchas that befall you if you do it manually (eg. forgetting to make them serializable properly)

Cas Smiley

Online Roquen
« Reply #262 - Posted 2012-09-12 11:53:53 »

Enums are really nice (and I don't see this used much) for ordered anonymous classes.
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #263 - Posted 2012-09-12 12:18:20 »

Enums never seem to quite fit my specific needs when I look at them, but I'm blaming the lackluster reference I often have to work with.

If I may go on a bit of a tangent, it bothers me a lot when I'm researching for a way to solve a problem using Java, and most documentation I find settles for the least effort most generic approach (and thus less flexible), barely scratching the surface of what the language is capable of.

I think I'm going to start pointing people to this thread so they realize how little they really know about Java. (I'm saying this as someone who is humbled by the knowledge on display here)

Online Roquen
« Reply #264 - Posted 2012-09-12 12:35:59 »

My goal is to always spend the least time possible building systems that are just sufficient for my currently needed usage..and move on.
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #265 - Posted 2012-09-12 14:08:59 »

Certainly, but there are situations when the requirements go beyond the possibilities of the standard solutions.

For example, most tutorials and books on Java Game Programming I've come across usually rely on Java2d objects for image presentation. That is fine and dandy for most users, but I may want to do some manipulation that goes beyond what those classes can handle, and it becomes frustrating when a sizable portion of the community simply state that it isn't possible, when in reality they mean "I don't know".

And in case you're wondering, my frustrations in this regard come from the StackOverflow forums mostly.


Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #266 - Posted 2012-09-12 14:27:10 »

Yes, that'd be a great option for Eclipse to support.

You can get most of the way there with the @NonNullByDefault annotation - you can apply this at the package, type or method level so it's not a lot of work to cover the entire codebase, and you can leave bits out if you want.
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #267 - Posted 2012-09-12 14:54:11 »

Shame it's not in 3.8 though Sad

Cas Smiley

Offline Icecore

Senior Member


Medals: 5



« Reply #268 - Posted 2012-09-12 15:44:52 »

For those of you wrangling about color operations on the int itself, have you checked out the JGO index? Here's one of several:

http://www.java-gaming.org/topics/fastest-color-addition-with-clamp-0-255-of-rgb/18379/view.html

Even has Markus_Persson's stamp of approval. I recall seeing a couple other in our archives, including some "fast" implementations by Markus.

Good idea, sad that I can't implement its with alpha Sad
I also understand that’s main time eat work with array, for example
Code by link takes 2594962 ns in (for 1000000)
Clear for eat         2101255 ns;
While simple int pixel = ar_Ints[0];
                          3466137 ns in same for
And you need three of array access: two for get pixels and one for put back;
                          5512280 ns
Like you see main problem not in math calculation Wink
Thanks all, I really tiered trying optimize rendering at this point its work
                          9482898 ns =)
And give in game 100-300 fps Wink
Offline 65K
« Reply #269 - Posted 2012-09-12 15:53:08 »

I would always trade fancy language features for great libraries and tools.

Pages: 1 ... 7 8 [9] 10
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
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!