Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (581)
Games in Android Showcase (162)
games submitted by our members
Games in WIP (632)
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 ... 70
1  Game Development / Newbie & Debugging Questions / Re: HashMap issues... on: 2015-05-25 21:46:31
Well it is a HashMap, isn't it?  Pointing

But as a general rule: http://stackoverflow.com/a/2707554

Quote
If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
2  Game Development / Newbie & Debugging Questions / Re: HashMap issues... on: 2015-05-25 21:37:25
Man that's the first time I've seen strictfp actually being used.

You probably aren't [correctly] overriding equals() and/or hashCode() for Vector.
3  Game Development / Networking & Multiplayer / Re: NitroNet - New, High-Level Networking Library on: 2015-05-25 19:55:52
I'd buy that. Hell I'd review it on amazon.
4  Discussions / General Discussions / Re: Java 8 - Stream vs Loop on: 2015-05-25 02:35:19
The lambda/stream combo is especially good for ease of parallelization:
list.parallelStream().anyMatch(i -> i.check());
which may also yield improvement if your list is large enough.
5  Discussions / General Discussions / Re: Java 8 - Stream vs Loop on: 2015-05-25 02:30:03
It generates an Iterator instance and uses it to loop over the list, which means overhead and garbage.

The lambda version most likely does the same.


Only if the object allocation isn't elided. It's quite possible to reduce the iterator to simply an index in a register (the same as the c-for loop). Unfortunately you can't really rely on it.
6  Discussions / General Discussions / Re: Java 8 - Stream vs Loop on: 2015-05-25 02:08:08
Possible algorithmic improvement instead:

You say that items are rarely added or removed, but are they modified often while in the list?
You could cache the truthiness of anyMatch and update it accordingly upon modification instead of computing it every query.

EDIT: since you're asking this question, I'm assuming you've already determined this is a performance problem. Say yes.  Pointing
7  Discussions / General Discussions / Re: Java 8 - Stream vs Loop on: 2015-05-25 02:02:00
The only way to know for sure is to measure. (preferably in real usage, not microbenchmarks)

Theoretically the JIT can optimize both into
1  
2  
3  
4  
5  
int size = list.size();
for(int i = 0; i < size; i++)
    if (/*No bounds check*/list.get(i).check())
        return true;
return false;


and yield the same performance, but the former is definitely farther abstracted and thus less likely to make it all the way down.

What is the context? If these are called only once, then any suboptimalities will be dwarfed by the work done on the list.
8  Discussions / General Discussions / Re: Teaching Kids to be Independent on: 2015-05-22 05:55:15
Quote
I really need advice from some of you guys on how to teach kids to work independently let their interests drag them towards some kind of hobby, because the most I hear from people around here is their hobby is generally "Facebook and Netflix".

I may be taking a job towards teaching kids a bunch of cool computer science stuffs, how can I make sure they take up a hobby in it and teach them to be independent?

Well you can't force it like Heroes said, but enabling interest is the first step. Make/show some cool demos of real stuff one can do with the concepts. Follow up with interactive examples with visual output to leverage that sweet, sweet instant gratification. Stir some friendly competition via sites like Hackerrank (also plenty of exercise for learning languages and concepts) or the codegolf.stackexchange.com challenges for anyone more ambitious. This one was fun, if involved: (it's also multiplayer and you can host your own) http://codegolf.stackexchange.com/questions/25347/survival-game-create-your-wolf

Math class etc. is boring for most because it's (usually) very dry: just rote memorization of things in the textbook in a vacuum, never any showing of what any of it could be used for.
9  Discussions / Miscellaneous Topics / Re: What I did today on: 2015-05-22 05:03:34
Canada Wide Science Fair was a bust, didn't win anything, It was fun though! I've been learning and programming neural networks for about 2 weeks now.

Reminds me of my first major science fairs, I did neural nets, albeit really basic stuff. Seemed to go over well with judges though, they probably didn't expect that at an 8th grade gig.
You would like this, currently at the top of /r/programming: http://karpathy.github.io/2015/05/21/rnn-effectiveness/
10  Game Development / Shared Code / Re: A convenient method that tells you if a rectangle is intersecting a line on: 2015-05-22 00:20:19
Well yeah, it's not too bad but relative to other simple intersection tests it requires a fair bit of code.
11  Game Development / Shared Code / Re: A convenient method that tells you if a rectangle is intersecting a line on: 2015-05-21 19:01:22
There's also the stdlib Rectangle2D's implementation:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
public boolean intersectsLine(double x1, double y1, double x2, double y2) {
    int out1, out2;
    if ((out2 = outcode(x2, y2)) == 0) {
        return true;
    }
    while ((out1 = outcode(x1, y1)) != 0) {
        if ((out1 & out2) != 0) {
            return false;
        }
        if ((out1 & (OUT_LEFT | OUT_RIGHT)) != 0) {
            double x = getX();
            if ((out1 & OUT_RIGHT) != 0) {
                x += getWidth();
            }
            y1 = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
            x1 = x;
        } else {
            double y = getY();
            if ((out1 & OUT_BOTTOM) != 0) {
                y += getHeight();
            }
            x1 = x1 + (y - y1) * (x2 - x1) / (y2 - y1);
            y1 = y;
        }
    }
    return true;
}


I guess I never realized the complexity of rect-line intersection testing.
12  Discussions / Miscellaneous Topics / Re: I'm baaaaack... on: 2015-05-20 01:52:19
Either way, keep doing what makes you happy, and try not to take things so personally. We're all doing the same thing. Welcome back.

Biggest lesson I learned throughout school (read: maturation period) had nothing to do with academics: everyone just needs to chill. Identify what is actually important and care about that.
13  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-18 17:24:29
But see that's one of the things I like most about Rust, it's quite abstract in many ways (albeit not the runtime) while still native. You get a lot of programmer convenience without the abstracted runtime (and associated costs).
14  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-18 16:58:51
It was admittedly an orthogonal statement, not sure why I decided to include it in that post.

But then again, as the whole Internet-of-things and VR trends keep picking up, it becomes closer and closer to everyday/gamedev.
I doubt the nanobots of the future will be running JVMs  Smiley
15  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-18 16:46:34
Yes, I know about specialty Java runtimes, but are we using those in the everyday or for gamedev? No.
Is android fast? No. Is it faster when you use C++? Yes.
Android systems are also pretty heavy compared to the small stuff that has only several K of RAM, etc. Good luck using even the best JVMs there, they won't even fit on the device. That's what I meant by embedded.

Don't get me wrong, I like Java and managed environments for what they are good at, but they aren't a silver bullet.
16  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-18 16:20:36
Compile speed is not great, but has much low-hanging fruit and is one of the current top priorities post-1.0 according to the core team.
These fruit include rustc generating very verbose IR that takes LLVM a while to optimize down (when building an optimized build), and no incremental or parallel compilation.

Speedwise it's apparently approximately the same as Java/C# JIT code.

I believe the attitude is "if it's slower than the equivalent C++, that's a perf bug."

I know I've noticed the GC, although maybe perhaps I don't make enough of an effort to please it, but one of Rust's goals is to be usable wherever you might use C/C++, including embedded and realtime systems, where GC isn't really an option, perceived 'lag' or not.
17  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-16 22:24:15
If you really did want java-esque fields you could type alias to reduce noise, a feature which I sometimes with java had:

1  
type Field<T> = Rc<RefCell<Option<T>>>;


One might also need something like an Arena or weak pointers to get java-style GC heavy code to type check.
But idiomatically these features are not needed as often as a java programmer might think, partially because not everything is assumed to be heap allocated all the time, like Heroes said.
18  Game Development / Newbie & Debugging Questions / Re: Will the second code be faster than the first ? on: 2015-05-16 05:42:19
Dunno. Measure it.
19  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-16 04:35:24
I think he meant you can't straight port the class-inheritance style java uses to rust's traits. (for reference traits are very similar to haskell's typeclasses if you know them)
And semantically since java has null, every field would be Option if translated procedurally, so that's not a problem in that sense.
20  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-16 02:27:17
Yeah currently the only "GC" is reference-counted pointers, Rc<T> and Arc<T> in the stdlib.
It's pretty much a different language from what it was in 2013 as from that article.

Another useful guarantee is if you code segfaults, it had to have been a bug in an unsafe region of code (marked by the unsafe keyword, so grep-able). So if your software doesn't have unsafe blocks, then it won't have memory errors. (including concurrency errors such as data races, although stuff like deadlock can happen, as it's not a memory error)
21  Discussions / Miscellaneous Topics / Re: Rust 1.0 has been released on: 2015-05-15 23:12:15
It would also be interesting to have a discussion on what you think of the language.

I think it's great; it's a lot of what I've been wanting in a language: heavily systems-oriented (native, compiled/static guarantees, performance-oriented) with a functional flavor while not being too rigid in purity and such philosophy (large ML influence, but still highly relatable to C++ people/etc.). C/C++ are the de facto systems langs, but are laden with cruft and footguns. Haskell and similar are powerful, but I'm just not quite enough of a mathematician to truly appreciate. Rust seems an intelligent middle ground, with positive aspects from each "domain."
22  Discussions / Miscellaneous Topics / Re: What are your habits while you're programming? on: 2015-05-14 11:12:38
Let the subconscious to its tricks, don't suppress it by consciously thinking about the problem.

I believe I've linked this before, and it's worth linking again: https://www.youtube.com/watch?v=f84n5oFoZBc
23  Game Development / Newbie & Debugging Questions / Re: Creating an instance of an object in Array List supplied by another ArrayList? on: 2015-05-14 00:58:58
Ah, try List<Class<? extends Entity>>.
I wondered if that would happen.
24  Game Development / Newbie & Debugging Questions / Re: Creating an instance of an object in Array List supplied by another ArrayList? on: 2015-05-14 00:10:03
Wooo! Thank you for the tips! Didn't know you could add an extra set of these thingamajigs <> to an array list!

It's not "to the array list", it's the Class type:

List<Class<Entity>> = List of ( Class objects that represent some sub-type of ( Entity ) )

https://docs.oracle.com/javase/tutorial/java/generics/
25  Game Development / Newbie & Debugging Questions / Re: Creating an instance of an object in Array List supplied by another ArrayList? on: 2015-05-14 00:03:00
If you just want to be able to instantiate random classes, then just do that, ditch the bureaucracy. (at least as much as is possible in Java...)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
case "Hostile": // consider using an enum variant here instead of typo-able strings
    doSomethingWith(randomEnemy());
break;

...

static List<Class<Entity>> enemyClassList; // fill this somewhere with class objects e.g. add(Orc.class)

public static Entity randomEnemy() {
   // warning: assumes list isn't empty!
   return enemyClassList.get((int) (Math.random() * enemyClassList.size())).newInstance(); // alternatively use a java.util.Random with nextInt(n)
}
26  Java Game APIs & Engines / Java Sound & OpenAL / Re: Getting TinySound to play .oggs in a .jar on: 2015-05-12 23:03:53
It means your launch/run configuration is incorrect. Make sure you're specifying the correct one in the jar wizard.
27  Discussions / General Discussions / Re: Is there a term for this? on: 2015-05-12 19:06:57
Inexperience (with specific new domain)?

At least quite related is the term XY Problem.
28  Discussions / Miscellaneous Topics / Re: Most unusual/weird syntax features in non-joke languages on: 2015-05-12 17:30:14
EDIT: ninja'd

If you think that's funny, try hiding this somewhere in a static block:

1  
2  
3  
Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set(1, 2); // or similar


1  
System.out.println(Arrays.asList(0, 1, 2, 3));


Quote
[0, 2, 2, 3]
29  Discussions / Miscellaneous Topics / Re: Most unusual/weird syntax features in non-joke languages on: 2015-05-11 20:48:59
MUMPS is essentially an exercise in horrifying language design, here's some syntactical highlights:

http://thedailywtf.com/articles/A_Case_of_the_MUMPS

Quote
CASE SENSITIVITY: Commands and intrinsic functions are case-insensitive. Variable names and labels are case-sensitive.

COMMANDS: may be abbreviated to one letter, case-insensitive. Includes commands such as IF, ELSE, GOTO, WRITE, and XECUTE [which is my personal favorite, it allows arbitrary execution of code contained in a variable]

OPERATORS: No precedence, executed left to right, parenthesize as desired. 2+3*10 yields 50.

DECLARATIONS: NONE. Everything dynamically created on first reference.

LINES: important syntactic entities. Multiple statements per line are idiomatic. Scope of IF and FOR is "remainder of current line."

There's also some nice non-lexical scoping type problems:

http://stackoverflow.com/a/2015215

Quote
1  
2  
if x>10 do myTag(x)    ; in MUMPS "tag" means procedure/function
else  do otherTag(x)


[...] in MUMPS, the else statement isn't syntactically part of the if block, it is a separate statement that works by examining the built-in variable $TEST. Every time you execute an if statement it sets $TEST to the result of the if statement. The else statement actually means "execute the rest of line if $TEST is false, otherwise skip to the next line".

This means that if x was greater than 10 and thus the first line called myTag, and myTag contains if statements, then the behavior of the else depends not on the if in the line above it but on the last if evaluated inside of myTag! Because of this "feature", MUMPS coders are generally taught write the above code like this to be safe:

1  
2  
if x>10 do myTag(x) if 1
else  do otherTag(x)


The if 1 at the end of the first line ensures that $TEST is set correctly before control proceeds to the next line. (BTW, the spacing here has to be just so, with two spaces after the else and one space in all the other places. [...])
30  Discussions / Miscellaneous Topics / Re: Most unusual/weird syntax features in non-joke languages on: 2015-05-10 18:10:14
@KevinWorkman

Similarly, odd usages of this:

1  
2  
3  
4  
5  
6  
7  
class Outer {
    class Inner {
        void foo() {
            Outer o = Outer.this;
        }
    }
}
Pages: [1] 2 3 ... 70
 
MrMapcom (16 views)
2015-05-23 20:26:16

MrMapcom (22 views)
2015-05-23 20:23:34

Waterwolf (29 views)
2015-05-20 15:01:45

chrislo27 (36 views)
2015-05-20 03:42:21

BurntPizza (72 views)
2015-05-10 15:53:18

FrozenShade (56 views)
2015-05-07 09:11:21

TheLopais (219 views)
2015-05-06 13:36:48

TheLopais (202 views)
2015-05-06 13:35:14

TheLopais (207 views)
2015-05-06 13:33:39

TheLopais (228 views)
2015-05-06 13:32:48
List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!