~ubuntu-branches/ubuntu/breezy/atlas-cpp/breezy

« back to all changes in this revision

Viewing changes to benchmark/Static_Move.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2005-10-02 11:41:44 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051002114144-8qmn4d1cdn9g27ta
Tags: 0.5.98-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "timer.h"
 
2
 
 
3
#include <iostream>
 
4
#include <cassert>
 
5
 
 
6
using namespace std;
 
7
 
 
8
class Object {
 
9
public:
 
10
  int id;
 
11
  Object *parent;
 
12
  int objtype;
 
13
};
 
14
 
 
15
class Entity : public Object {
 
16
public:
 
17
  Object *loc;
 
18
  double pos[3];
 
19
  double velocity[3];
 
20
};
 
21
 
 
22
class Operation : public Object {
 
23
public:
 
24
  Object *from, *to;
 
25
  Object* arg;
 
26
};
 
27
 
 
28
enum {
 
29
  OBJECT,
 
30
  OP
 
31
};
 
32
 
 
33
Entity human;
 
34
Operation move;
 
35
Operation sight;
 
36
 
 
37
class NPC
 
38
{
 
39
public:
 
40
  NPC() : id(123) {x=y=z = vx=vy=vz = 0.0;}
 
41
  Operation *move(const Operation *op);
 
42
  int getId() {return id;}
 
43
private:
 
44
  int id;
 
45
  double x,y,z;
 
46
  double vx,vy,vz;
 
47
};
 
48
 
 
49
Operation *NPC::move(const Operation *op)
 
50
{
 
51
  double *new_vel = ((Entity*)op->arg)->velocity;
 
52
  vx = new_vel[0];
 
53
  vy = new_vel[1];
 
54
  vz = new_vel[2];
 
55
 
 
56
  x += vx;
 
57
  y += vy;
 
58
  z += vz;
 
59
 
 
60
  //human:
 
61
  static Entity human_ent;
 
62
  human_ent.parent = &human;
 
63
  human_ent.id = getId();
 
64
  human_ent.pos[0] = x;
 
65
  human_ent.pos[1] = y;
 
66
  human_ent.pos[2] = z;
 
67
  human_ent.velocity[0] = vx;
 
68
  human_ent.velocity[1] = vy;
 
69
  human_ent.velocity[2] = vz;
 
70
  
 
71
  //move:
 
72
  static Operation move_op;
 
73
  move_op.objtype = OP;
 
74
  move_op.parent = &::move;
 
75
  move_op.arg = &human_ent;
 
76
  
 
77
  //sight:
 
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;
 
83
 
 
84
  return &sight_op;
 
85
}
 
86
 
 
87
int main(int argc, char** argv)
 
88
{
 
89
  double i;
 
90
  TIME_ON;
 
91
  for(i=0; i<10000000.0; i+=1.0) {
 
92
    //human:
 
93
    Entity ent;
 
94
    ent.objtype=OBJECT;
 
95
    ent.parent=&human;
 
96
    ent.pos[0] = i;
 
97
    ent.pos[1] = i-1.0;
 
98
    ent.pos[2] = i+1.0;
 
99
    ent.velocity[0] = i;
 
100
    ent.velocity[1] = i-1.0;
 
101
    ent.velocity[2] = i+1.0;
 
102
 
 
103
    //move:
 
104
    Operation move_op;
 
105
    move_op.objtype=OP;
 
106
    move_op.parent=&move;
 
107
    move_op.arg=&ent;
 
108
    
 
109
    //sight:
 
110
    Operation sight_op;
 
111
    sight_op.objtype=OP;
 
112
    sight_op.parent=&sight;
 
113
    sight_op.from=&ent;
 
114
    sight_op.arg=&move_op;
 
115
  }
 
116
  TIME_OFF("Plain creating of sight operation");
 
117
 
 
118
 
 
119
  NPC npc1;
 
120
  double x,y,z;
 
121
  TIME_ON;
 
122
  for(i=0; i<10000000.0; i+=1.0) {
 
123
    //human:
 
124
    Entity human_ent;
 
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;
 
130
 
 
131
    //move:
 
132
    Operation move_op;
 
133
    move_op.objtype = OP;
 
134
    move_op.parent = &move;
 
135
    move_op.arg = &human_ent;
 
136
 
 
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;
 
141
    x = new_pos[0];
 
142
    y = new_pos[1];
 
143
    z = new_pos[2];
 
144
  }
 
145
  TIME_OFF("NPC movements");
 
146
  cout<<"Resulting position: ("<<x<<","<<y<<","<<z<<")"<<endl;
 
147
 
 
148
  return 0;
 
149
}