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

tr1 functional and boost bind and stuff

Name: OP 2011-03-20 19:02

I'm trying to make a 2d game engine in c++. It's nearly done, only I have one problem I can't seem to find a solution to:

I have an engine class that acts as an interface for the engine proper (that is, user->engine-renderer/inputHandler/helper). Now, I want to let the user assign a function to be executed when the specified event happens:

>void addFunc(EventType e, std::tr1::function<void(void)> func);

I am using

>std::tr1::unordered_map<EventType, std::tr1::function<void(void)>> map;

to keep track of those. During my main loop, I check if a key was pressed, and if so, I call:

>map[*unicode value of pressed key*]();

Now: I need to bind member functions, and to be sure nothing weird happens (the more standard way doesn't work anyway), I use the following as a function:

>boost::bind(&class::func_to_bind, &instance_of_class)

where func_to_bind is:

>void func_to_bind(void);

so let's say the first argument of addFunc was '1' (since the second argument is the boost::bind-generated function), whenever '1' is pressed, func_to_bind has to trigger.

Instead I get std::tr1::bad_function_call thrown at me by std::tr1::function<void(void)> when it is called.

QUESTION 1:
Is there an easier way to achieve my goal of letting the engine's user bind a function to a key?

QUESTION 2:
What might cause the problem I am encountering?

Name: Anonymous 2011-03-20 19:34

I lol'd.

Name: OP 2011-03-20 19:45

Well, I didn't.

Name: Anonymous 2011-03-20 20:05

OP
failed quoting
mailto:noko

Tsk.

Name: Anonymous 2011-03-20 20:08

>>3
youve just been HURT FEELINGS AND BUTT RANGED go drink ur moms bredt milk u fart commander i bet u hav a fetish FOR MEN LMAO ur just so made all the time its 2 easy 23 own u "i lik to drnikj sperm from my sperm bottle while waring my sperm necklace" - u

Name: Anonymous 2011-03-20 20:33

>>4
Well fuck your shit. I'm on the imageboards usually, I don't frequent those textboards at all. /g/ directed me here.

Name: OP 2011-03-20 20:39

AAAAAAAaaaaaannd... fixed!
I shouldn't have used unicode values when I could use the key press's ascii code (which actually converts to char directly). Didn't notice it was there...

SO, how does one delete a thread?

Name: Anonymous 2011-03-20 20:41

>>7
it will hang around forever, so that the /prog/riders of tomorrow may witness the extend of your stupidity.

Name: OP 2011-03-20 20:50

>>8
there was virtually nothing stupid here, I simply assumed my library was returning a char encoded as unicode (the charset for my toolset is set to unicode, so no incompatibility here), though it gave me an int instead. As for my asking how to delete threads, it is doable on the imageboards, though I don't know how to do it on those textboards.

Name: Anonymous 2011-03-20 23:22

>>1
1)  I'd like to say "function pointers" but then I'd have to say "oh wait ..."  In a program I did recently, where the user had an excessive degree of configuration control, I used a method similar to what you did.  One thing I had to do, however, was implement an intermediate system to keep track of keys held down so that subsequent key presses did not interrupt the activity of the currently depressed keys.  You may have done something similar, or not had the complication?

2) Quoted from http://www.boost.org/doc/libs/1_38_0/doc/html/boost/bad_function_call.html:
An exception type thrown when an instance of a function object is empty when invoked.
I have no clue about Boost so I'm going to go with the function object used in the bind call being (re)moved or destroyed after being constructed on the heap, for some reason, or not throwing an error when it is not created.  What do you expect to happen, by the way, when map[*unicode value of pressed key*](); is called on unbound input?

Name: Anonymous 2011-03-21 3:28

check 'em

Name: VIPPER 2011-03-21 4:26

>>4
You forgot to mention he used sepples.

Name: Anonymous 2011-03-21 7:48

&class::func_to_bind

Readability my arse

Name: OP 2011-03-21 11:38

Well, since the thread is still open...

>>10
This wasn't the whole function: I'm checking if the key exists before attempting to call the corresponding function. As I said, I was basically trying to call map[(char)1234] instead of map[(char)43] (just an example) when I had registered the function to map[(char)43]. And functional is a functor already, which is probably better to use here than a function pointer.

------------------------------
a new problem has arisen!

While trying to clean-up my code, I have decided to create function pointers to the members of the engine's components. So (and I still don't know how to quote here, but:)

[quote]void addFunc(EventType e, std::tr1::function<void(void)> func);[/quote]
is moved back to my event handler, for example.

I have, in my engine (the interface):
[quote]const std::tr1::function<void(EventType, EventFunc)> addFunc;[/quote]

initialized with

[quote]addFunc(boost::bind<void>(&EventHandler::addFunc, eventHandlerInstancePtr, _1, _2))[/quote]

in the engine's initialization list.

I call it in my main with:

[quote]engine.addFunc(KEY_W, boost::bind<void>(&Player::move, playerInstancePtr, UP));[/quote]

but that gives me an access violation error reading 0xffffffffffffffff.

Name: Anonymous 2011-03-21 13:05

>>14
but that gives me an access violation error reading 0xffffffffffffffff.
That's the compiler ranging at you're use of C++ and Sepples0x/boost in particular.  Grab you're debugg'er and see where it crashes (you'll probably have to go a few thousand levels up the stack to find the relevant user code).

Name: OP 2011-03-21 13:26

>>15
It crashes at the line directly following engine.addFunc(KEY_W, boost::bind<void>(&Player::move, playerInstancePtr, UP)); in my main.cpp; adding or commenting function calls confirm that. That's all my debugger is willing to tell me (the engine is a DLL).

Name: Anonymous 2011-03-21 13:27

ACCESS VIOLATE MY ANUS

Name: Anonymous 2011-03-21 13:32

>>14,16
I am penetrating your anus with my hard black dick. take this, white boy! take my black load oh yeahhhhhh

fucking fag

Name: Anonymous 2011-03-21 14:16

void void(void) {return void}

Name: Anonymous 2011-03-21 14:20

>>19
void void(void){void void}

Name: Anonymous 2011-03-21 14:20

>>20
(nil (nil nil) (nil))

Name: Anonymous 2011-03-21 14:39

>>16
Oh, C++ does not support crash-less operation.  You have to rewrite the application in C.

Name: Anonymous 2011-03-21 16:13

>>19-21
((λ(λ)(λ λ))(λ(λ)(λ λ)))

Name: Anonymous 2011-03-21 20:33

>>22
NULL NULL(NULL){NULL NULL}

Name: Anonymous 2011-03-21 20:35

NIGGER NIGGER(NIGGER){NIGGER NIGGER}

Name: Anonymous 2011-03-21 22:58

>>25
That was /b/ quality!

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