本文整理汇总了C++中ActiveObject类的典型用法代码示例。如果您正苦于以下问题:C++ ActiveObject类的具体用法?C++ ActiveObject怎么用?C++ ActiveObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ActiveObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
ActiveObject ao;
std::string id = "abc";
std::string id2 = "def";
boost::shared_future<Message> fmessage = ao.getMessage(id);
boost::shared_future<Message> fmessage2 = ao.getMessage(id2);
while ( !fmessage.is_ready() )
{
std::cout << "+";
boost::this_thread::sleep( boost::posix_time::millisec(500) );
}
std::cout << std::endl;
Message message = fmessage.get();
std::cout << message.report() << std::endl;
std::cout << "+" << std::endl;;
message = fmessage2.get();
std::cout << message.report() << std::endl;
return 0;
}
示例2: ThreadFunc
// The thread executes the run function of its handler
DWORD WINAPI ActiveObject::ThreadFunc( void* pAO )
{
ActiveObject* ActiveObj = static_cast<ActiveObject*>(pAO);
ActiveObj->InitThread();
ActiveObj->Run();
return 0; // no one cares what we return in this case
}
示例3: testVoidInOut
void ActiveMethodTest::testVoidInOut()
{
ActiveObject activeObj;
ActiveResult<void> result = activeObj.testVoidInOut();
activeObj.cont();
result.wait();
assert (result.available());
assert (!result.failed());
}
示例4: testVoidIn
void ActiveMethodTest::testVoidIn()
{
ActiveObject activeObj;
ActiveResult<int> result = activeObj.testVoidIn();
activeObj.cont();
result.wait();
assert (result.available());
assert (!result.failed());
assert (result.data() == 123);
}
示例5: testFailure
void ActiveDispatcherTest::testFailure()
{
ActiveObject activeObj;
ActiveResult<int> result = activeObj.testMethod(100);
result.wait();
assert (result.available());
assert (result.failed());
std::string msg = result.error();
assert (msg == "n == 100");
}
示例6: testVoid
void ActiveDispatcherTest::testVoid()
{
ActiveObject activeObj;
ActiveResult<void> result = activeObj.testVoid(123);
assert (!result.available());
activeObj.cont();
result.wait();
assert (result.available());
assert (!result.failed());
}
示例7: testWait
void ActiveDispatcherTest::testWait()
{
ActiveObject activeObj;
ActiveResult<int> result = activeObj.testMethod(123);
assert (!result.available());
activeObj.cont();
result.wait();
assert (result.available());
assert (result.data() == 123);
assert (!result.failed());
}
示例8: testTryWait
void ActiveMethodTest::testTryWait()
{
ActiveObject activeObj;
ActiveResult<int> result = activeObj.testMethod(123);
assert (!result.available());
assert (!result.tryWait(200));
activeObj.cont();
assert (result.tryWait(10000));
assert (result.available());
assert (result.data() == 123);
assert (!result.failed());
}
示例9: main
int main()
{
std::cout << "main thread id: " << std::this_thread::get_id() << std::endl;
ActiveObject obj;
std::chrono::milliseconds dura(200);
std::this_thread::sleep_for(dura);
for(int i=0; i < SIZE; ++i)
{
obj.doSomething(); // call is nonblocking
}
std::this_thread::sleep_for(std::chrono::seconds(2));
std::cout << "main thread exited " << std::endl;
}
示例10: _Run
unsigned int ActiveObject::_Run(LPVOID lpParam)
{
ActiveObject *pThread = reinterpret_cast<ActiveObject*>(lpParam);
if(pThread)
{
try
{
pThread->Run( );
}
catch(std::exception&)
{
}
pThread->ClearUp( );
}
return (0);
}
示例11: testWaitInterval
void ActiveDispatcherTest::testWaitInterval()
{
ActiveObject activeObj;
ActiveResult<int> result = activeObj.testMethod(123);
assert (!result.available());
try
{
result.wait(100);
fail("wait must fail");
}
catch (Exception&)
{
}
activeObj.cont();
result.wait(10000);
assert (result.available());
assert (result.data() == 123);
assert (!result.failed());
}
示例12: testActivity
void ActivityTest::testActivity()
{
ActiveObject activeObj;
assert (activeObj.activity().isStopped());
activeObj.activity().start();
assert (!activeObj.activity().isStopped());
Thread::sleep(1000);
assert (activeObj.activity().isRunning());
activeObj.activity().stop();
activeObj.activity().wait();
assert (activeObj.count() > 0);
}
示例13: ii
void ActiveMethodTest::testCopy()
{
ActiveObject activeObj;
ActiveObject::IntIntType ii = activeObj.testMethod;
ActiveResult<int> rii = ii(123);
assert (!rii.available());
activeObj.cont();
rii.wait();
assert (rii.available());
assert (rii.data() == 123);
assert (!rii.failed());
ActiveObject::VoidIntType vi = activeObj.testVoid;
ActiveResult<void> rvi = vi(123);
assert (!rvi.available());
activeObj.cont();
rvi.wait();
assert (rvi.available());
assert (!rvi.failed());
ActiveObject::VoidVoidType vv = activeObj.testVoidInOut;
ActiveResult<void> rvv = vv();
assert (!rvv.available());
activeObj.cont();
rvv.wait();
assert (rvv.available());
assert (!rvv.failed());
ActiveObject::IntVoidType iv = activeObj.testVoidIn;
ActiveResult<int> riv = iv();
assert (!riv.available());
activeObj.cont();
riv.wait();
assert (riv.available());
assert (riv.data() == 123);
assert (!riv.failed());
}
示例14: main
int main () {
ActiveObject activeObject;
activeObject.doSomething();
activeObject.doSomething2();
activeObject.doSomething2();
activeObject.doSomething();
activeObject.doSomething();
activeObject.run();
activeObject.waitAllFinished();
}
示例15: collisionMoveSimple
collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
f32 pos_max_d, const aabb3f &box_0,
f32 stepheight, f32 dtime,
v3f *pos_f, v3f *speed_f,
v3f accel_f, ActiveObject *self,
bool collideWithObjects)
{
static bool time_notification_done = false;
Map *map = &env->getMap();
//TimeTaker tt("collisionMoveSimple");
/*
ScopeProfiler sp(g_profiler, "collisionMoveSimple avg", SPT_AVG);
*/
collisionMoveResult result;
/*
Calculate new velocity
*/
if (dtime > 1) {
if (!time_notification_done) {
time_notification_done = true;
infostream << "collisionMoveSimple: maximum step interval exceeded,"
" lost movement details!"<<std::endl;
}
dtime = 1;
} else {
time_notification_done = false;
}
*speed_f += accel_f * dtime;
// If there is no speed, there are no collisions
if (speed_f->getLength() == 0)
return result;
// Limit speed for avoiding hangs
speed_f->Y = rangelim(speed_f->Y, -1000, 1000);
speed_f->X = rangelim(speed_f->X, -1000, 1000);
speed_f->Z = rangelim(speed_f->Z, -1000, 1000);
/*
Collect node boxes in movement range
*/
std::vector<aabb3f> cboxes;
std::vector<bool> is_unloaded;
std::vector<bool> is_step_up;
std::vector<bool> is_object;
std::vector<int> bouncy_values;
std::vector<v3s16> node_positions;
{
//TimeTaker tt2("collisionMoveSimple collect boxes");
/*
ScopeProfiler sp(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
*/
v3s16 oldpos_i = floatToInt(*pos_f, BS);
v3s16 newpos_i = floatToInt(*pos_f + *speed_f * dtime, BS);
s16 min_x = MYMIN(oldpos_i.X, newpos_i.X) + (box_0.MinEdge.X / BS) - 1;
s16 min_y = MYMIN(oldpos_i.Y, newpos_i.Y) + (box_0.MinEdge.Y / BS) - 1;
s16 min_z = MYMIN(oldpos_i.Z, newpos_i.Z) + (box_0.MinEdge.Z / BS) - 1;
s16 max_x = MYMAX(oldpos_i.X, newpos_i.X) + (box_0.MaxEdge.X / BS) + 1;
s16 max_y = MYMAX(oldpos_i.Y, newpos_i.Y) + (box_0.MaxEdge.Y / BS) + 1;
s16 max_z = MYMAX(oldpos_i.Z, newpos_i.Z) + (box_0.MaxEdge.Z / BS) + 1;
bool any_position_valid = false;
for(s16 x = min_x; x <= max_x; x++)
for(s16 y = min_y; y <= max_y; y++)
for(s16 z = min_z; z <= max_z; z++)
{
v3s16 p(x,y,z);
bool is_position_valid;
MapNode n = map->getNodeNoEx(p, &is_position_valid);
if (is_position_valid) {
// Object collides into walkable nodes
any_position_valid = true;
INodeDefManager *nodedef = gamedef->getNodeDefManager();
const ContentFeatures &f = nodedef->get(n);
if(f.walkable == false)
continue;
int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
int neighbors = 0;
if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) {
v3s16 p2 = p;
p2.Y++;
getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
p2 = p;
p2.Y--;
getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
p2 = p;
p2.Z--;
getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
//.........这里部分代码省略.........