this is difficult to explain, i'll do my best, thank you in advance for any help... I have a cocos2d game, everything is working as it should, but the weirdest thing happens when i add another integer or other variable to the top of the .m file, some removeChild processes stop working.
I define integer, int endGame; then when i run the game my label "Round 1" comes up, but the removeChild process doesn't work.
If I removed the defined integer, int endGame; then the removeChild works.
Why does this happen?
Related
This question already has answers here:
Non-blocking console input C++
(13 answers)
Closed 6 years ago.
First of all let me state that I am new to C++. I received an assignment to make a mini "snake" game meaning I need to make a grid and have a box move around in it. It is a simple 1x1 box, and no fruits to catch or anything.
I am able to create the grid, and have a box exist in it that I can move up, down, left, right using user input. My problem is I need the box to move automatically every second in the direction it was headed. I have no problems with the sleep command (I think), my problem is that when I am waiting for the user to enter his direction the program stops until that input is given. I need a way to have the box continue moving while I wait for input. For this I need either to just have the code continue while waiting for the input, or to redirect it to doing a function while waiting for input.
I have been googling this and trying things for some hours now and all I keep finding is multi-threading. I tried using thread, pthread, boost/thread.hpp but I can't get any of them to work.
In any case multi-threading is way more advanced than what my class is doing and there is no chance that is what my professor want's us to do. He said something about having a function of cin that allows such things, but I can't find it anywhere.
Is there a simple way of doing this?
From what I'm understanding from the question, it seems that you need to implement a timer of sorts that will move the move the box every second. I'm not sure if g++ has something similar to System::Timers as visual studio does but here's a link that shows how to make a timer yourself (though it's written in C). With a timer in place (created, started, and your code to get input and moving of the box happens within the timer's tick function) you could use a following if statement to keeping moving the box. Here's a link to the .NET's timer for more information on how it works. This has code for a timer class that Matthew Hoggan has created for C++ in linux. Hope this helps.
if (user input)
{
change direction
}
move the box
I'm trying to make a roguelike game in visual c++ 2010, which involves printing out a screen every time the player makes a move. Unfortunately, it uses 8000 characters, and so it takes a second or so to print them out every refresh. It might not seem like much, but given the number of moves involved in the game, it adds up.
I've tried unsyncing with stdio, compiling all the characters into a string and then printing the string with cout, and printing the characters with _putch();, but there was still a significant printing time for each method. I tried printing out an unchanging string repeatedly to test if it was something else causing the delay, but there was still a delay when the only task was printing.
My question is, is there anything I could try that could potentially speed up the process? A friend of mine suggested ncurses, would that be worth a try? If so, how would I do it, and if not, what else could I try?
I would agree with cornstalks. However if you are looking to make a pure console game I would suggest you take advantage of the built in ctime library. Learn from a library (such as SDL1.2) or a source on how to handle hard-coding time based events with entity systems. There are many efficient ways to store these characters and print them in a jiff. Or you can use SDL and make the game window seem like a console and handle everything as raster-graphics.
I am running a simple c/c++ code on a Raspberry Pi 2 with Raspbian kernel version 4.1.6-v7+ in order to view the thermal images from my new FLIR Lepton camera. I also want to see the actual temperature of the object I am pointing it at, but as the temperature is expressed as relative to the internal temperature of the camera, I need to call a function
lepton_temperature()
which requires
i2c-dev
module to be activated. When I activate it and run the function the program slows down from around 9fps to around two frames per minute. I didn't really modify anything in the provided code, so I don't understand why that is happening. Here's the function:
int lepton_temperature() {
if(!_connected) {
lepton_connect();
}
result = ((LEP_GetSysFpaTemperatureKelvin(&_port, &fpa_temp_kelvin)));
return ( fpa_temp_kelvin);
}
Without i2c-dev turned on the program works normally, but of course then I am getting a zero instead the temperature value. Anyone maybe has an idea on what is going on and how to solve it/make it faster?
It might sound obvious, but your question suggests to me that you overlooked it: use a separate thread for the lepton_temperature call.
Turns out Alex was right, as i2c commands are done by ioctl which is synchronous, using the command after each loaded frame was making the program too slow. I didn't consider it as every pixel value of every frame is calculated according to that temperature, so I was sure that can't possibly be the case. Turns out I was wrong.
Thanks to everyone anyway, sorry for posting a question without checking a pretty obvious solution first!
I've read the thread break whenever a file(or class) is entered. And I now understood the basic mechanism how to automatically set breakpoints in the classes. However, the solution that thread provided is focused on .net framework. My problem is how to deal with it in standard C++. We use vc 10 compiler on windows 7 platform.
Besides, we prefer methods which do not need recompile when we rechoose the class which we want to inspect since it is a huge project and recompilation takes a lot of time.
Thanks in advanceļ¼
You can do it from the IDE:
http://blogs.msdn.com/b/habibh/archive/2009/09/10/class-breakpoint-how-to-set-a-breakpoint-on-a-c-class-in-the-visual-studio-debugger.aspx
The answer Emile Cormier gives is a good solution. When I try to add a breakpoint "Stack::* " as the link says, I found there is no red point on the left of code lines until I start debugging the program. After stopping the program, the red points disappear, but the break point window will keep track of every breakpoint and you can turn to the code by double clicking the breakpoint in the breakpoint window.
As far as i know, you can only set memory breakpoints (break whenever the contents of a certain memory address is read/written) and then manual breakpoints (break on a certain line of code).
Your best bet may be to set a breakpoint at the beginning of the function call(s) you want to debug.
I have written a small program using Borland's C++ builder, and along the way, everything seemed fine. My program has a map window and a table window, and when a user presses a button, a long process is started that reads in all the map and table information and then displays that. Every time i ran it through the debugger, I had no issues. Then today, I decided to test it without running it through the debugger. To my horror, The program reads in the map information and then displays it on the paintbox canvas without a problem, but when it loads the information for the grid, the map gets erased!!! It appears to happen during the load phase for the table. this takes about 4 seconds, and during which time, the window tells me that it isnt responding. This is when the map gets erased. Anyone have any ideas on why this is happening? Its driving me nuts, and I dont really understand whats going on under the hood here.
UPDATE:
I have fixed the problem to some degree. I was poking around and found this: Avoiding "(Not Responding)" label in windows while processing lots of data in one lump
I added the code to run once in the middle of the data read in for the table. this fixed my problems. however, I was wondering if anyone knows why this is the case? why does my program going unresponsive cause my canvases to be erased?
Marcus Junglas wrote a detailed explanation of the problem, which affects both Delphi and C++Builder.
When programming an event handler in
Delphi (like the OnClick event of a
TButton), there comes the time when
your application needs to be busy for
a while, e.g. the code needs to write
a big file or compress some data.
If you do that you'll notice that your
application seems to be locked. Your
form cannot be moved anymore and the
buttons are showing no sign of life.
It seems to be crashed.
The reason is that a Delpi application
is single threaded. The code you are
writing represents just a bunch of
procedures which are called by
Delphi's main thread whenever an event
occured. The rest of the time the main
thread is handling system messages and
other things like form and component
handling functions.
So, if you don't finish your event
handling by doing some lengthy work,
you will prevent the application to
handle those messages.
You can reduce the problem by calling Application->ProcessMessages(), while loading your map data, however I recomend using a separate thread to load the data.
I have never used C++ Builder, but i used Delphi. I think the libraries are the same.
Does that component you use store the image data? It may only draw to the screen. Try covering the window of your app with another window. If it erases it, you have to use a component which stores the image.
See this, it is for Delphi, but it may help. There should be a Image component in C++ Builder. Try using that instead of PaintBox.
You can solve the unresponsivenes problem by running the time consuming task in a separate thread or calling some function that processes the window's messages.