Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Question about event handling

Name: Anonymous 2014-06-21 11:42

Let's say I use SDL (1.2 or 2.0) in my program to handle events, should I use callbacks or the good old giant switch statement?

Name: Anonymous 2014-06-21 12:10

Callbacks are much more maintainable and scalable. Is this really a question?

Name: Anonymous 2014-06-21 12:14

>>2
Yes because everyone I have seen uses a switch
Also using a for/while that calls every callback that may not even be needed would be slower instead of using a nice O(1) switch

Name: Anonymous 2014-06-21 12:23

>>3
Also using a for/while that calls every callback that may not even be needed
Why would you even do that? Do you even know what a callback is?

And why are you microoptimizing before profiling? I bet you're going to use dynamic linking, killing any LTO you might have gotten.

Name: Anonymous 2014-06-21 12:30

>>4
Why would you even do that?
any better idea

Do you even know what a callback is?
using ``callback'' in that was a mistake, but I think it was very clear what I meant

And why are you microoptimizing before profiling?
It is not microoptimisation, it is very clear that it is going to be slower that way

I bet you're going to use dynamic linking, killing any LTO you might have gotten.
You do not know me

Name: Anonymous 2014-06-21 12:39

>>4
Are you from /g/? The way you talk makes me think so.

Name: Anonymous 2014-06-21 13:18

>>5
any better idea

Yes. Use callbacks properly.

but I think it was very clear what I meant

Callbacks are real things used for event handling. Whatever you are pretnding to be thinking of probably isn't.

It is not microoptimisation, it is very clear that it is going to be slower that way

It is, and callbacks aren't even slower. Even if you get the compiler to emit an O(1) switch (good luck with that), it's O(n) in terms of events received. Using callbacks is O(n) in terms of events handled.

Name: Anonymous 2014-06-21 13:22

>>7
Yes. Use callbacks properly.
explain

pretnding
what does this even mean?

It is, and callbacks aren't even slower. Even if you get the compiler to emit an O(1) switch (good luck with that), it's O(n) in terms of events received. Using callbacks is O(n) in terms of events handled.
no idea how it would work

Name: Anonymous 2014-06-21 14:30

>>8
Seriously, what do you think a callbacks is?

Name: Anonymous 2014-06-21 14:33

>>9
Why that question?

Name: Anonymous 2014-06-21 14:39

>>8
Who are you quoting?

Name: Anonymous 2014-06-21 14:39

>>11
del

Name: Anonymous 2014-06-21 15:32

>>10
Nevermind then. Hope you got what you needed.

Name: Anonymous 2014-06-21 16:01

>>13
I did not but anyway

Name: Anonymous 2014-06-21 16:31

>>14
Use callbacks.

Name: Anonymous 2014-06-21 16:39

>>2
Callbacks are much more maintainable and scalable
Fuck off, Javashit loving fagstorm. Die in a fire.

Name: Anonymous 2014-06-21 16:40

>>7
Even if you get the compiler to emit an O(1) switch (good luck with that)
What? Ever heard of branch tables?

Name: Anonymous 2014-06-21 16:53

>>17
We've been over this already. For non-trivial case analysis you either end up with a very large table or a forest of conditional guards. So yeah, if you're lucky you'll get O(1), if not you'll get something else. If you're unlucky you'll get O(1) on paper and O(stall) in real life.

Name: Anonymous 2014-06-21 17:14

>>15
I made this thread not because I wannted kikes to say to me ``use callbacks'' but because I wannted to find a good way to handle events without being hell slow
The only way I can think of handling the events it to travel a list of function pointers and call all of them with a pointer to the current event

Name: Anonymous 2014-06-21 17:43

>>1

C/C++ doesn't support lambdas, so callback would have limited value.

Name: Anonymous 2014-06-21 17:46

>>20
what's wrong with event_register (onMove, &player);?

Name: Anonymous 2014-06-21 17:54

>>21

you have to explicitly specify closure (&player in this case)

Name: Anonymous 2014-06-21 18:02

>>22
It's true that in a language like scheme it would look better but I have no problem with that
it's C after all

Name: /g/reat /g/uy 2014-06-21 18:30

>>20
[](){}
That's C++11, in old C++ you may use functors, and in C you can have something like a lambda expression with macros and function pointers. LISP is not that special m8!

Name: Anonymous 2014-06-21 18:37

>>24
in C you can have something like a lambda expression with macros and function pointers
I want a example (except from something like >>21)

Name: Anonymous 2014-06-21 19:06

>>16
I write C++. I never had to learn Java.
>>19
Provide a testcase -- a small snippet of code that is running slower than you'd like.
>>20
See >>2. Also, with embedded languages like Lua, your post is even more out of touch with reality.
>>24
In C (C89/C99/C11) you don't have lambda expressions. Lisp is special especially for its AST.

Name: Anonymous 2014-06-21 19:12

cork my anus

Name: Anonymous 2014-06-21 19:14

Provide a testcase -- a small snippet of code that is running slower than you'd like.
while (SDL_WaitEvent (&e))
for (size_t i = 0; i < events_p; i++)
events[i].fun (e, events[i].arg);

Name: Anonymous 2014-06-21 19:17

Callbacks are much more maintainable and scalable [than big switch statements]
Really?

Name: Anonymous 2014-06-21 19:29

Well, there must be a reason why the nodejs developers decided to use callbacks.

Name: Anonymous 2014-06-21 19:33

>>30
Because they suck!

Name: Anonymous 2014-06-21 19:52

>>28
You are passing the struct by value to your callbacks. Why does this run slower than you'd expect?
>>29
Yes.

Name: Anonymous 2014-06-21 19:54

>>32
You are passing the struct by value to your callbacks. Why does this run slower than you'd expect?
it runs slower even if I use a pointer

Why does this run slower than you'd expect?
because turds

Name: Anonymous 2014-06-21 19:58

Name: Anonymous 2014-06-21 20:04

>>34
Their is* macros are invoking undefined behavior on two different grounds. Mind you, those were the first lines after the #include's. Ergo, the code is shit.

Name: Anonymous 2014-06-21 20:06

>>34
That code is god damn awful. Memory leak at lambda_vector_resize. They don't even know how to properly use realloc. What shitheads.

Name: Anonymous 2014-06-21 20:15

the way they redefine is* incorectly by violotating te standard makes me upset
this was written by my one hannd because I was mastrubuting

Name: Anonymous 2014-06-21 20:25

char *temp = (char*)realloc(source->data, source->length + bs);
char *temp = realloc(vec->chars, vec->length * vec->size);
*vomits*
*farts all over this thread*

Name: Anonymous 2014-06-21 20:43

Why use C/C++ when there's ATS?

Name: Anonymous 2014-06-21 20:46

>>30
imperative programming could be awful for concurrency, so the idea is to do every in one single thread and think asynchronously, i.e., your program will follow an event driven paradigm (not sure if that makes sense in english, sorry)

>>1
http://gameprogrammingpatterns.com/

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List