[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Why is Java such a fucking clusterfuck? Do I really need to use
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 47
Thread images: 3
File: Capture.png (62 KB, 1183x788) Image search: [Google]
Capture.png
62 KB, 1183x788
Why is Java such a fucking clusterfuck? Do I really need to use Threads to get a working movement system?

Currently when I press the arrow keys the sprite moves and then stops for half a second before continuing to move
>>
>>53710316
that or a timer
>>
>>53710316
Meanwhile in Haskell

-- Handle input by simply updating the keys set

handle :: Event -> Pong -> Pong
handle (EventKey k s _ _) = keys.contains k .~ (s == Down)
handle _ = id

-- Update the paddles
updatePaddles :: Float -> State Pong ()
updatePaddles time = do
p <- get

let paddleMovement = time * paddleSpeed
keyPressed key = p^.keys.contains (SpecialKey key)

-- Update the player's paddle based on keys
when (keyPressed KeyUp) $ paddle1 += paddleMovement
when (keyPressed KeyDown) $ paddle1 -= paddleMovement
>>
>>53710316
>>Currently when I press the arrow keys the sprite moves and then stops for half a second before continuing to move
That sounds awfully like a repetition delay. Like how when you press a letter it types the first letter and then pauses for half a second and then repeats.
>>
>>53710362
>That sounds awfully like a repetition delay
Exactly, the fucking KeyListener interface even contains a fucking keyTyped method but apparently they had to fuck up the keyPressed method and make it useless
>>
>>53710384
>>That sounds awfully like a repetition delay
What you fucking retard want to do is start moving on keyDown and stop moving on keyUp.
>>
>>53710384
What the fuck do you think "keyPressed" fucking is?
>>
>>53710427
>>53710459
That's what the code should do but the keyPressed adds a fucking delay
>>
>>53710461
No, you're fucking retarded.

keyPressed is called when a key is pressed. The driver/OS is what provides the repetition based on the repetition delay value, functionally repeating the key press.

You're just retarded and using the wrong function for the job.
>>
>>53710499
Oh god you are retarded
>>
>>53710316
Where do you set the booleans to false again?
>>
>>53710543
In the keyReleased method
>>
>>53710316
>Why is Java such a fucking clusterfuck?
I've been asking for over a decade, but it looks like it's just the way it is
>>
>>53710316
your programming is clusterfucked, not Java.
>>
>>53710513
No, you're the one that is retarded.

>Invoked when a key has been pressed.
It is called WHEN THE KEY IS PRESSED.
When you hold down a key it will send the initial key pressed and then delay before repeating the key pressed call.

You fucking coded it wrong. You should be doing >>53710427 because what you fucking want is for it to move constantly while the KEY IS DOWN and stop WHEN THE KEY IS UP.

You're a fucking idiot. You used the wrong function and then blamed the language.

Fuck you.
>>
>>53710651
>being this fucking dumb
THE KEY PRESS EVENT SETS A BOOLEAN TO TRUE, how hard is it to understand?
>>
>This is the current state of /g/
>>
>>53710316
The update method moves the paddle, right?

Where else does is the update method called? I only see it in the keyPressed method.
Presumably you want it to be called every tick/cycle.
>>
whats a good pattern for input anyways. not just java and C++ but like how unity or unreal have a way to just look up the "walk" xy axis from a controller or keypress. is it just having a hash list or something like what is the OOP patterns behind that
>>
>>53710881
>OOP patterns
ew
>>
>>53710316
>dat OOP
That's why I dont use OOP for any real project
>>
>>53710881
fuck off and come de a game entirely on assembly if you're a real man.
>>
>>53710905
how do you even get an opengl context with assembly
>>
>>53710881
bump
>>
>>53711272
Use Javascript like a sane person
>>
File: 1365397190750a.jpg (13 KB, 371x117) Image search: [Google]
1365397190750a.jpg
13 KB, 371x117
>>53711284
almost got me there
>>
>>53710342
event pong pong
k s _ _ k .~
wow this sure is viewtiful code i love haskell now
>>
>>53710881
Id say singleton but I feel like 40 people would dilate my asshole if i mention a signleton
>>
>>53710316
>some weird "keys" array
>an objectList that you just arbitrarily .get() shit from
>Eclipse

sweet fuck what are you doing
you can't possibly write horseshit like that and then blame the language
>>
>>53711339
Haskell doesn't need to look nice or be readable by anyone else, since it never needs maintenance.
>>
>>53711437
thats a good point this way no one has to learn it
>>
>>53710342
>Assuming you can create a GUI game in Haskell
I'm a big Haskell fan myself, but creating games is like the worst usage of it.
>>
>>53711460
>Assuming you can create a GUI game in Haskell
https://github.com/ekmett/lens/blob/master/examples/Pong.hs

It even runs in the browser (if you compile it to JavaScript)
>>
In Java creating a new thread is incredibly easy though.

new Thread(() -> {
while (true)
System.out.println("hello!");

}).start();
>>
>>53711518
>javafags think that's elegant

forkIO $ forever (putStrLn "hello!")
>>
>>53711405
He's literally only calling the update method in keyPressed methods which is why it has the repetition delay.

The guy needs the update method to be called during every tick of the game instead.
>>
>>53711731
>we added some more retarded syntactic sugar because our programmers can't be bothered to write 'while(true)'
>>
File: koji_kondo_laughing.jpg (30 KB, 530x291) Image search: [Google]
koji_kondo_laughing.jpg
30 KB, 530x291
>>53710651
Triggered
>>
>>53711757
Not him, but you are retarded if you think both have the same connotation, especially in a functional programming language
>>
>>53711757
You are retarded if you think that's syntactic sugar.

forever a = do a; forever a


Go ahead, try doing that in your shitty memelang
>>
>>53711518
>>53711731
Creating new threads in Haskell is very cheap compared to Java too.
>>
OP needs to blow their own head off, but they're probably so incompetent they'll only end up hurting someone else.
>>
>>53712030
Creating threads in Haskell is very cheap compared to every other language, really

GHC wins _all_ the thread benchmarks. All of them
>>
>>53711339
> Event -> Pong -> Pong
This is one of the best type systems currently available. It means that it gets passed an Event and a Pong and that it returns a Pong.
>Why isn't it `Event, Pong -> Pong` then?
That's because of currying. Another great feature. I'm not going into detail here, but it means that functions return functions.

> handle (EventKey k s _ _)
This is pattern matching. Really useful and readable. It means that if you call handle with an EventKey that k is bound to the first value of the EventKey, s to the second value, you ignore the other two values and you execute the code on the right.

> .~
This is from the lens package. I agree that its syntax can be weird for some things. But if you learn a few basic rules about which character means what you can understand most of the operators. .~ means set.
>>
>>53712130
>That's because of currying. Another great feature. I'm not going into detail here, but it means that functions are outsourced to India.
ftfy
>>
>>53710316
>Calling update() in keyPressed()
How can you be this fucking retarded?

Stop blaming the programming language for your own incompetence
>>
>>53710688
We don't know that. Op could have shat up his code doing something like

public void kePresssed() {
Spritepos+=5;
}
Thread replies: 47
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.