Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Mouse Click Question

Author
Message
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 16th Apr 2010 05:54
The project I am working on I am making it so that when I click somewhere I make a new object.



the problem is since it is updating so quick it makes more than one object before I let go of the mouse. How could I make it so it only makes one object when I click even if I'm holding the mouse button down?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 16th Apr 2010 06:16
Here's my Keyboard and Mouse Classes that I use, maybe you could put them to work for you:

mouse.h


mouse.cpp


keyboard.h


keyboard.cpp



And to use them, you do this:




I love this approach. I based it on some java-code I found on the internet somewhere... works like a charm for me. Of course, I left out my specific header files, but I'm sure you'll be able to figure the appropriate #includes out for yourself.

Enjoy,

JTK
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 16th Apr 2010 10:02 Edited at: 16th Apr 2010 10:03
or make it pretty simple like this:


and oh well, you better make a class or something for mouse and/or keyboard input if you will use it alot, it makes thing more organized

Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 16th Apr 2010 23:13
JTK:Thanks for the sharing your code. That is going to help me a lot in my project. I will make sure to go over all the code so I understand it before using. I might have some questions for you in the future about it just to get a better understanding.

Hassan: That was definitely the basic code I was looking for. For some reason everything I tried would just keep creating multiple objects or nothing at all.

Thanks again for the reply guys.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 17th Apr 2010 09:39
Well, if the MYASSERT() macros throw you off, I've posted that source code in the "Code Snippets" forum here.

The code isn't overly complicated; and since most of the methods are simply class instance member-variable lookups, they are mostly inlined code (in release build that is)...

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 19th May 2010 12:05
Hey this is a bit of an old thread but I was wondering if you could help me out JTK. I have been using your Keyboard and mouse code and it has been working great (Thanks a lot for letting me use that in my project btw). I have come across one issue and basically this is what I am doing:



Okay all this code works and it's basically just waiting for me to click to go to the next game state. The problem I have been having is when I use your mouse input and try this I have to keep clicking over and over and then all of the sudden it realizes that I hit the mouse button and runs the code. Now when I use dbMouseClick() I just have to click it once and it works. I have also had this exact same problem with the Dark Form. Is there something I am doing wrong?

Wow sorry for the long post this has just really been bothering me these past couple of days haha.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 19th May 2010 16:18
That should be in a loop. I use mouse.poll inside the


sorry for bad example but short on time - better response later if you still need it.


JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 19th May 2010 22:37 Edited at: 19th May 2010 22:40
Yeah that's where I put it.It kind of works like this:


Now in game it is a switch case:



And then it hits my gametitle state after the game setup is ran and all that is in the while loop. That's why it has been confusing me because it has been updating....But it hasn't =)
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 01:33
Ok, I'm assuming this is basically the same code as you've posted here. As such, I'll show you how I would integrate input-handling as an overview...



In short, you've already polled the input devices for this frame at the top of the loop. Everytime you call Poll() the state of the device is requeried...

Hope this helps,


JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 20th May 2010 01:56
That didn't work it still takes a bunch of clicks until I get it to change states, do you think it could be something else?
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 03:11
Ok, here's a working sample - based on your code. Note: The Keyboard/Mouse classes have been modified since posting the version you currently have. Those modifications have not been thoroughly tested yet - but this demo doesn't use them so you should be ok...

See if this project works for you, if it does, you have a road-map to go by; if not then we'll need to see more of your code cause something is wrong in there...

Let me know, I'll be here for a bit more tonight...

JTK

Attachments

Login to view attachments
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 20th May 2010 03:50
Okay I just ran your program and it works fine.So I will read through it and see if there is anything I have done differently and post back a little later. Before I do, did you change anything about the Keyboard or mouse class or any other classes that I am using that isn't my code. Just want to make sure so I can change those files to match the ones in my project.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 04:03
Keyboard, Mouse. I've added (but not tested yet) the ability to get/set Toggle-Key States (CAPS,NUM,SCROLL locks) and to programmatically inject key-strokes/mouse events.

None of this is tested! I've not had much time to work with Capt. Ooze lately and that's what those changes were for. You're welcome to test them and let me know how things go - but just be warned, they're not tested on my end...

main.h - simply redefines some macros that I use, mostly to do nothing for this particular example. Here shortly, you will be given access to the entire shabang when I upload the Capt. Ooze game. Keep an eye out for the DarkGDK Competition thread that keeps reappearing near the top from time to time... lol

Regards,
JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 20th May 2010 04:19
So Got it to work and maybe you can explain exactly why but this was how I was doing it originally:



Now because it was in a loop every time it stepped through my game title it would load the image which is why I think it wasn't able to know that I was clicking now this is where I'm not to sure as to why it would eventually work but maybe you can help me out with that.

Also I know you would probably have to see my code but right when I got this to work it really killed the frame rate of my game:

Here is what I tried:



Now the reason I did it this way is so I load it once and then just hit that while loop until I hit the button. I also tried this:


I tried this the first time so I could keep the dbSync and mouse and keyboard polls in the actually while loop. You see anything that I could be doing wrong?

Thanks for that example to by the way made me realize it was the load image that was screwing things up
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 05:24
Quote: "Now because it was in a loop every time it stepped through my game title it would load the image which is why I think it wasn't able to know that I was clicking now this is where I'm not to sure as to why it would eventually work but maybe you can help me out with that."


A couple of things come to mind here: code-cache and threads. Now, I'm not entirely sure if either of these would cause the "occassional" acceptance of the click - but that's the first things that seem to come to my mind.

As for the slowed frame rate...

Keep in mind that Poll() should be called once per frame - to save the current state of the keyboard/mouse at that moment in time. You will then query that brief moment in time for various states(ButtonUp/ButtonDown/ButtonPressed/ButtonRelease/ButtonOnce).

Your example above (calling poll within the while(bTitle) loop) was not a single call per frame but more like hundreds of calls - theoretically every call to dbSync() updates the screen and hence the frame ends, but every call to keyboard.Poll() places 256-individual calls to GetAsyncKeyState() - so, your hundreds of while(bTitle) loop passes *each* called GetAsyncKeyState() 256 times... Most likely the source of your slow-down...

Remove the while(bTitle) loop from the equation and you remove the 256*X calls to GetAsyncKeyState()... The code I provide in that sample above does just that...

Did I get all of them? I seems like you had several questions in there but I wasn't able to determine what they really were...

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 20th May 2010 07:06
Well I changed all my code to look like this:



Now the mouse.poll() and keyboard.poll() are in the main loop but I am still having some really bad frame rate is there anyway to test what it might be?

Also I had been using that same while loop in my FireLevel() function and it had worked fine in there without any lag until I got the title menu to work. Just want to let you know we can narrow it down a little better.
entomophobiac
22
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 20th May 2010 12:12
You can run a profiler, such as http://www.codersnotes.com/sleepy, to see which processes are running inside the application. It's not a failsafe method to find framedrop issues, but it's a good way to expose which processes are running often.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 20th May 2010 16:55
how much drop you talking? You have the frame rate set to 60fps. is it falling below that? If so I'd say we need a look at your character and element classes.

I'm not seeing anything obvious in the code above and I know my projects don't drop below 60...

JTK
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 20th May 2010 23:27 Edited at: 21st May 2010 03:25
Hey sorry for the late response. It's just strange to me that it would do this right after I change that one function. I'm sure it has nothing to do with any of your classes so I think I am just going to have to mess with it for awhile. If I just cant seem to figure it out I will try to post what I have a little later today.

Thanks for all the help again really appreciate it.

EDIT:

Got it to work. Again it had some thing to do with the dbloadImage() I basically made a function that loads all of my images before I start my game and then just call the id's when I want to use them. So thanks again for all your help and good luck with your game I look forward to seeing how it turns out

Login to post a reply

Server time is: 2024-11-19 23:22:21
Your offset time is: 2024-11-19 23:22:21