简体   繁体   中英

Wait for instruction without stopping while loop

I designed a C++ application that represents an mechanical arm. The simulation is running inside a while loop. I have the following class Motherboard that interacts with the simulation

class Motherboard
{
public:
void receiveInstruction(double angle);
}

I have as well an event receiver that waits for keyboard instruction during the simulation. I won't copy the full class but here is the interesting part (the prefix irr comes from the fact that I am using Irrlicht 3D engine) :

case irr::KEY_SPACE:
     // Do something
     return true;
case irr::KEY_RETURN:
     std::cin << angle
     motherboard->receiveInstruction(atof(angle))
     return true;

where angle is of type char[] and atof converts a string into a double. When I enter the RETURN key on my keyboard the simulation freezes until i complete typing the angle instruction.

How shall I proceed to let the simulation running while I am typing the instruction, and send the instruction as soon as I am done entering the information ? Are threads unavoidable ? (I am running on Windows)

Best regards

Vincent

是的,似乎是不可避免的,或者至少是最优雅的方式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM