so ... erstmal sry wegen dem screenshot ... mir fällt das nich wirklich auf da ich auf 6000px arbeit ...
@HighligerBimBam:
1.: ... ja hast recht ... hätt ich auch drauf kommen können
2.: ich hab alle dateien durch gesucht aber nix gefunden ... entweder stell ich mich doof an oder ka ...
das mit den referencen hatte ich ansich auch so gemacht ... mein liebenswerter compiler quitierte es mir allerdings sehr schnell mit nem haufen fehlern ... is aber auch nich so schlimm ... geht auch so ohne probs ...
hier mal ein state (noch nicht fertig geschrieben da ich da wie gesagt gerade bin)
state_Search.h
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#pragma once
#include "state.h"
#include "TSingelton.h"
#include "Telegram.h"
#include "GameMovingEntity.h"
#include "SteeringBehaviors.h"
class state_Search : public state , public TSingelton<state_Search>
{
void Enter(GameMovingEntity* p);
void Execute(GameMovingEntity* p);
void Exit(GameMovingEntity* p);
bool OnMessage(GameMovingEntity* p, Telegram t);
};
void state_Search::Enter(GameMovingEntity* p)
{
p->getSteering()->WanderOn();
}
void state_Search::Execute(GameMovingEntity* p)
{
p->moveEntity(p->getSteering()->Calculate());
}
void state_Search::Exit(GameMovingEntity* p)
{
p->getSteering()->WanderOn();
}
bool state_Search::OnMessage(GameMovingEntity* p, Telegram t)
{
return true;
}
|
state.h
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#pragma once
struct Telegram;
class GameMovingEntity;
class state
{
public: virtual ~state(void){};
public: virtual void Enter(GameMovingEntity*) = 0;
public: virtual void Execute(GameMovingEntity*) = 0;
public: virtual void Exit(GameMovingEntity*) = 0;
public: virtual bool OnMessage(GameMovingEntity*, Telegram t) = 0;
};
|
TSingeltone.h (um mir die dauernde singeltone implimentierung zu sparen ...)
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#pragma once
#include <iostream>
using namespace std;
template<class TDerived>
class TSingelton
{
//instance
private: static TDerived* instance;
protected: TSingelton(void){};
private: TSingelton(const TSingelton &){};
private: TSingelton& operator = (const TSingelton &){};
//get instance
public: static TDerived* Instance(void)
{
if(instance == NULL)
instance = new TDerived;
return instance;
}
//destr
public: ~TSingelton(void)
{
if(instance)
{
delete instance;
instance = NULL;
}
}
};
template<class TDerived>
TDerived* TSingelton<TDerived>::instance = NULL;
|
GameMovingEntity.h
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#pragma once
#include "GameBaseEntity.h"
#include "Random.h"
#include "scale.h"
#include "stateMachine.h"
#include "TList.h"
#include "Tree.h"
using namespace std;
class MassageDispatcher;
class SteeringBehaviors;
class GameMovingEntity : public GameBaseEntity
{
protected: SteeringBehaviors* m_steering;
protected: stateMachine* m_sm;
protected: core::vector3df m_Velocity;
protected: core::vector3df m_Heading;
protected: core::vector3df m_Side;
protected: GameBaseEntity* m_target;
protected: TList<GameBaseEntity*>* m_ObjInViewRange;
protected: double m_viewRange;
protected: double m_Speed;
protected: double m_maxSpeed;
protected: double m_Mass;
protected: double m_Force;
protected: double m_elapsedTime;
public: GameMovingEntity( entity_type type,
MessageDispatcher * post,
double collisionSize,
core::vector3df position,
double rotation,
double ViewRangeMin,
double ViewRangeMax,
double SpeedMin,
double SpeedMax,
double ForceMin,
double ForceMax,
double MassMin,
double MassMax
);
public: virtual ~GameMovingEntity(void);
public: virtual void Update( float elapsed) = 0;
//public: virtual int getFoeInPanicDistance(void) = 0;
public: bool getAppleInViewRange(void);
public: bool getSweetInViewRange(void);
//public: virtual int getFriendsInViewRange(void) = 0;
public: bool getTargetExists(void);
public: core::vector3df getTargetPosition(void);
public: GameBaseEntity* getTargetAgent(void);
public: core::vector3df getVelocity(void);
public: core::vector3df getHeading(void);
public: core::vector3df getSide(void);
public: void setVelocity(core::vector3df v);
public: void setHeading(core::vector3df h);
public: void setSide(core::vector3df s);
public: double getViewRange(void);
public: double getSpeed(void);
public: double getMaxSpeed(void);
public: double getForce(void);
public: double getMass(void);
public: double TimeElapsed(void);
public: core::vector3df getSteeringForce(void);
public: SteeringBehaviors* getSteering(void);
public: stateMachine* getStateMachine(void);
public: void moveEntity(core::vector3df steeringForce);
public: TList<GameBaseEntity*>* getObjInViewRange(void);
public: TList<Tree*>*getHidingSpots(void);
};
|
GameMovingEntity.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
#include "GameMovingEntity.h"
#include "SteeringBehaviors.h"
GameMovingEntity::GameMovingEntity( entity_type type,
MessageDispatcher * post,
double collisionSize,
core::vector3df position,
double rotation,
double ViewRangeMin,
double ViewRangeMax,
double SpeedMin,
double SpeedMax,
double ForceMin,
double ForceMax,
double MassMin,
double MassMax
):GameBaseEntity(type,post,position,rotation,collisionSize)
{
this->m_viewRange = this->m_rand.dRand(ViewRangeMin,ViewRangeMax);
this->m_maxSpeed = this->m_rand.dRand(SpeedMin,SpeedMax);
this->m_Speed = this->m_maxSpeed;
this->m_Mass = this->m_rand.dRand(MassMin,MassMax);
this->m_Force = this->m_rand.dRand(ForceMin, ForceMax);
this->m_target = NULL;
this->m_steering = new SteeringBehaviors(this);
this->m_sm = new stateMachine(this);
this->m_ObjInViewRange = new TList<GameBaseEntity*>();
}
GameMovingEntity::~GameMovingEntity(void)
{
delete this->m_sm;
delete this->m_steering;
}
bool GameMovingEntity::getAppleInViewRange()
{
double dist = math::MaxDouble;
GameBaseEntity* target = NULL;
for(int x = 0; x < this->m_ObjInViewRange->size(); x++)
{
GameBaseEntity* e = this->m_ObjInViewRange->get(x);
if(e->getType() == ET_APPLE)
{
double d = math::distance(this->getPosition(),e->getPosition());
if(d < dist)
{
dist = d;
target = e;
}
}
}
if(dist != math::MaxDouble)
{
this->m_target = target;
return true;
}
this->m_target = NULL;
return false;
}
bool GameMovingEntity::getSweetInViewRange()
{
double dist = math::MaxDouble;
GameBaseEntity* target = NULL;
for(int x = 0; x < this->m_ObjInViewRange->size(); x++)
{
GameBaseEntity* e = this->m_ObjInViewRange->get(x);
if(e->getType() == ET_SWEET)
{
double d = math::distance(this->getPosition(),e->getPosition());
if(d < dist)
{
dist = d;
target = e;
}
}
}
if(dist != math::MaxDouble)
{
this->m_target = target;
return true;
}
this->m_target = NULL;
return false;
}
bool GameMovingEntity::getTargetExists()
{
if(this->m_target != NULL)
return true;
return false;
}
GameBaseEntity* GameMovingEntity::getTargetAgent()
{
return this->m_target;
}
core::vector3df GameMovingEntity::getTargetPosition()
{
return this->m_target->getPosition();
}
core::vector3df GameMovingEntity::getVelocity()
{
return this->m_Velocity;
}
void GameMovingEntity::setVelocity(core::vector3df v)
{
this->m_Velocity = v;
}
core::vector3df GameMovingEntity::getHeading()
{
return this->m_Heading;
}
void GameMovingEntity::setHeading(core::vector3df h)
{
this->m_Heading = h;
}
core::vector3df GameMovingEntity::getSide()
{
return this->m_Side;
}
void GameMovingEntity::setSide(core::vector3df s)
{
this->m_Side = s;
}
double GameMovingEntity::getViewRange()
{
return this->m_viewRange;
}
double GameMovingEntity::getSpeed()
{
return this->m_Speed;
}
double GameMovingEntity::getMaxSpeed()
{
return this->m_maxSpeed;
}
double GameMovingEntity::getForce()
{
return this->m_Force;
}
double GameMovingEntity::getMass()
{
return this->m_Mass;
}
double GameMovingEntity::TimeElapsed()
{
return this->m_elapsedTime;
}
core::vector3df GameMovingEntity::getSteeringForce()
{
return this->m_steering->Force();
}
SteeringBehaviors* GameMovingEntity::getSteering()
{
return this->m_steering;
}
stateMachine* GameMovingEntity::getStateMachine()
{
return this->m_sm;
}
TList<GameBaseEntity*>* GameMovingEntity::getObjInViewRange()
{
return this->m_ObjInViewRange;
}
void GameMovingEntity::moveEntity(core::vector3df steeringForce)
{
core::vector3df acceleration = steeringForce / this->m_Mass;
this->m_Velocity += (acceleration * this->m_elapsedTime);
this->m_Velocity = math::Truncate(this->m_Velocity, this->m_maxSpeed);
this->m_position += (this->m_Velocity * this->m_elapsedTime);
if(this->m_Velocity.getLengthSQ() > 0.00000001)
{
core::vector3df v = this->m_Velocity;
this->m_Heading = v.normalize();
this->m_Side = math::Perp(this->m_Heading);
}
}
TList<Tree*>* GameMovingEntity::getHidingSpots()
{
TList<Tree*>* trees = new TList<Tree*>();
for(int x = 0; x < this->m_ObjInViewRange->size(); x++)
{
if(this->m_ObjInViewRange->get(x)->getType() == ET_TREE)
trees->insert(dynamic_cast<Tree*>(this->m_ObjInViewRange->get(x)));
}
return trees;
}
|
und exemplarisch der bug
bug.h
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#pragma once
#include "GameMovingEntity.h"
#include "Telegram.h"
#include "GameBaseEntity.h"
#include "world.h"
#include "stateMachine.h"
#include "scale.h"
using namespace scale;
class Bug : public GameMovingEntity
{
public: Bug(MessageDispatcher *post,core::vector3df position,double rotation,double collisionSize);
public: ~Bug(void);
public: void Update( float elapsed);
public: bool HandleMessage(Telegram t);
public: bool getFoeInPanicDistance(void);
public: bool getFriendsInViewRange(void);
};
|
bug.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "_states.h"
#include "Bug.h"
Bug::Bug(MessageDispatcher *post,core::vector3df position, double rotation, double collisionSize):GameMovingEntity(ET_BUG,post,collisionSize,position,rotation, scale::EntityMinViewRange,scale::BugViewRange,scale::EntityMinSpeed,scale::BugMaxSpeed,scale::EntityMinForce,scale::BugMaxForce,scale::BugMinMass,scale::BugMaxMass)
{
this->m_sm->ChangeState(state_Search::Instance());
}
Bug::~Bug(void)
{
//delete this->m_sm;
}
void Bug::Update( float elapsed)
{
//this->m_position.Y+=scale::BugMaxSpeed*elapsed;
this->m_elapsedTime = elapsed;
this->m_sm->Update();
}
bool Bug::HandleMessage(Telegram t)
{
return true;
}
bool Bug::getFoeInPanicDistance()
{
return true;
}
bool Bug::getFriendsInViewRange()
{
return true;
}
|
und das problem is jetzt ... wenn beim bug.cpp oben die "_states.h" drin ist gibt es das link problem wenn es ebenfalls bei ant.cpp drin ist ... ansich sind weder ant noch bug in state oder stateMachine drin ... immer nur die basisklasse gamemovingentity ...
gruß zeus