15
class Entity : public Object {
22
class Operation : public Object {
40
NPC() : id(123) {x=y=z = vx=vy=vz = 0.0;}
41
Operation *move(const Operation *op);
42
int getId() {return id;}
49
Operation *NPC::move(const Operation *op)
51
double *new_vel = ((Entity*)op->arg)->velocity;
61
static Entity human_ent;
62
human_ent.parent = &human;
63
human_ent.id = getId();
67
human_ent.velocity[0] = vx;
68
human_ent.velocity[1] = vy;
69
human_ent.velocity[2] = vz;
72
static Operation move_op;
74
move_op.parent = &::move;
75
move_op.arg = &human_ent;
78
static Operation sight_op;
79
sight_op.objtype = OP;
80
sight_op.parent = &sight;
81
sight_op.from = &human_ent;
82
sight_op.arg = &move_op;
87
int main(int argc, char** argv)
91
for(i=0; i<10000000.0; i+=1.0) {
100
ent.velocity[1] = i-1.0;
101
ent.velocity[2] = i+1.0;
106
move_op.parent=&move;
112
sight_op.parent=&sight;
114
sight_op.arg=&move_op;
116
TIME_OFF("Plain creating of sight operation");
122
for(i=0; i<10000000.0; i+=1.0) {
125
human_ent.parent = &human;
126
human_ent.id = npc1.getId();
127
human_ent.velocity[0] = i;
128
human_ent.velocity[1] = i-1.0;
129
human_ent.velocity[2] = i+1.0;
133
move_op.objtype = OP;
134
move_op.parent = &move;
135
move_op.arg = &human_ent;
137
Operation *res_sight = npc1.move(&move_op);
138
Operation *res_move = (Operation*)(res_sight->arg);
139
Entity *res_ent = (Entity*)res_move->arg;
140
double *new_pos = res_ent->pos;
145
TIME_OFF("NPC movements");
146
cout<<"Resulting position: ("<<x<<","<<y<<","<<z<<")"<<endl;