예제 #1
0
Operation NPC::move(Operation &op)
{
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  Entity op_arg = op->arg;" << endl;
#endif
  Entity op_arg = op->arg;
  double *new_vel = op_arg->velocity;
  vx = new_vel[0];
  vy = new_vel[1];
  vz = new_vel[2];

  x += vx;
  y += vy;
  z += vz;

  //human:
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  Entity human_ent;" << endl;
#endif
  Entity human_ent;
#if !FINE_GRAINED_LISTS
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  human_ent->set_parent(human.asObjectPtr());" << endl;
#endif
  human_ent->set_parent(human.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
  human_ent->id = getId();
  human_ent->pos[0] = x;
  human_ent->pos[1] = y;
  human_ent->pos[2] = z;
  human_ent->velocity[0] = vx;
  human_ent->velocity[1] = vy;
  human_ent->velocity[2] = vz;
  
  //move:
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  Operation move_op;" << endl;
#endif
  Operation move_op;
#if !FINE_GRAINED_LISTS
  move_op->objtype = OP;
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  move_op->set_parent(::move.asObjectPtr());" << endl;
#endif
  move_op->set_parent(::move.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  move_op->set_arg(human_ent.asObjectPtr());" << endl;
#endif
  move_op->set_arg(human_ent.asObjectPtr());
  
  //sight:
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  Operation sight_op;" << endl;
#endif
  Operation sight_op;
#if !FINE_GRAINED_LISTS
  sight_op->objtype = OP;
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  sight_op->set_parent(sight.asObjectPtr());" << endl;
#endif
  sight_op->set_parent(sight.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  sight_op->set_from(human_ent.asObjectPtr());" << endl;
#endif
  sight_op->set_from(human_ent.asObjectPtr());
#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  sight_op->set_arg(move_op.asObjectPtr());" << endl;
#endif
  sight_op->set_arg(move_op.asObjectPtr());

  return sight_op;
}
예제 #2
0
int main(int argc, char** argv)
{
  double i;
  TIME_ON;
  for(i=0; i<MAX_ITER; i+=1.0) {
    //human:
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Entity ent;" << endl;
#endif
    Entity ent;
#if !FINE_GRAINED_LISTS
    ent->objtype=OBJECT;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    ent->set_parent(human.asObjectPtr());" << endl;
#endif
    ent->set_parent(human.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
    ent->pos[0] = i;
    ent->pos[1] = i-1.0;
    ent->pos[2] = i+1.0;
    ent->velocity[0] = i;
    ent->velocity[1] = i-1.0;
    ent->velocity[2] = i+1.0;

    //move:
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Operation move_op;" << endl;
#endif
    Operation move_op;
#if !FINE_GRAINED_LISTS
    move_op->objtype=OP;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    move_op->set_parent(move.asObjectPtr());" << endl;
#endif
    move_op->set_parent(move.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    move_op->set_arg(ent.asObjectPtr());" << endl;
#endif
    move_op->set_arg(ent.asObjectPtr());
    
    //sight:
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Operation sight_op;" << endl;
#endif
    Operation sight_op;
#if !FINE_GRAINED_LISTS
    sight_op->objtype=OP;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    sight_op->set_parent(sight.asObjectPtr());" << endl;
#endif
    sight_op->set_parent(sight.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    sight_op->set_from(ent.asObjectPtr());" << endl;
#endif
    sight_op->set_from(ent.asObjectPtr());
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    sight_op->set_arg(move_op.asObjectPtr());" << endl;
#endif
    sight_op->set_arg(move_op.asObjectPtr());
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    DONE iter" << endl;
#endif
  }
  TIME_OFF("Plain creating of sight operation");


#if DEBUG
  cout << endl << "DEBUG: " << __LINE__ << ":  NPC npc1;" << endl;
#endif
  NPC npc1;
  double x,y,z;
  TIME_ON;
  for(i=0; i<MAX_ITER; i+=1.0) {
    //human:
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Entity human_ent;" << endl;
#endif
    Entity human_ent;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    human_ent->set_parent(human.asObjectPtr());" << endl;
#endif
#if !FINE_GRAINED_LISTS
    human_ent->set_parent(human.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
    human_ent->id = npc1.getId();
    human_ent->velocity[0] = i;
    human_ent->velocity[1] = i-1.0;
    human_ent->velocity[2] = i+1.0;

    //move:
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Operation move_op;" << endl;
#endif
    Operation move_op;
#if !FINE_GRAINED_LISTS
    move_op->objtype = OP;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    move_op->set_parent(move.asObjectPtr());" << endl;
#endif
    move_op->set_parent(move.asObjectPtr());
#endif // !FINE_GRAINED_LISTS
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    move_op->set_arg(human_ent.asObjectPtr());" << endl;
#endif
    move_op->set_arg(human_ent.asObjectPtr());

#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Operation res_sight = npc1.move(move_op);" << endl;
#endif
    Operation res_sight = npc1.move(move_op);
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Operation res_move = res_sight->arg;" << endl;
#endif
    Operation res_move = res_sight->arg;
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    Entity res_ent = res_move->arg;" << endl;
#endif
    Entity res_ent = res_move->arg;
    double *new_pos = res_ent->pos;
    x = new_pos[0];
    y = new_pos[1];
    z = new_pos[2];
#if DEBUG
    cout << endl << "DEBUG: " << __LINE__ << ":    DONE iter" << endl;
#endif
  }
  TIME_OFF("NPC movements");
  cout<<"Resulting position: ("<<x<<","<<y<<","<<z<<")"<<endl;

  return 0;
}
예제 #3
0
FreeList<ObjectData> *test_obj_ptr()
{
  Operation ent;
  ent.incRef();
  return ent.asObjectPtr();
}