Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Zeus

Frischling

  • »Zeus« ist der Autor dieses Themas

Beiträge: 83

Beruf: Schule

  • Private Nachricht senden

1

10.02.2010, 17:56

Problem mit Bidirektionaler Assoziation

Hi,
zur zeit arbeite ich an einem ki project, dabei sollen sich ameisen auf einem spielfeld bewegen etc ... jetzt habe ich bei der FSM das problem das die states bei den einzelnen moving entitys probleme (überschneidungen) verursachen (siehe screen) ... ich hab schon alles mögliche versucht und rum experimentiert aber ich habe die lösung nicht gefunden ... wäre klasse wenn jemand von euch weis woran es liegen könnte ... ich kann euch auch größere project ausschnitte geben wenn ihr braucht ...

http://img535.imageshack.us/img535/4416/pici.jpg

gruß zeus

2

10.02.2010, 18:15

1. So nen screenshow ist ganzschön unübersichtlich... Warum machst du nicht einfach mal C++Code beim posten.

2. Bist du dir sicher, dass du nicht irgendwo eine doppelte definition drinne hast. Manchmal hilft aber auch den debug Ordner komplett zu löschen und das Projekt neu zu erstellen.

Da ich dein benutztes Buch kenne und somit viele deienr benutzen Klassen... Muss nicht Telegram eine Referenc sein:

.h
virtual bool HandleMessage(const Telegram& msg);

.cpp
bool Objekt::HandleMessage(const Telegram& msg)

3

10.02.2010, 18:28

ein so riesiges Screenshot in Originalgröße in ein Forum zu stellen, ist irgendwie frech. Verlinke das doch bitte, es nervt extrem, beim lesen horizontal scrollen zu müssen.
Lieber dumm fragen, als dumm bleiben!

Zeus

Frischling

  • »Zeus« ist der Autor dieses Themas

Beiträge: 83

Beruf: Schule

  • Private Nachricht senden

4

10.02.2010, 18:54

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

drakon

Supermoderator

Beiträge: 6 513

Wohnort: Schweiz

Beruf: Entrepreneur

  • Private Nachricht senden

5

10.02.2010, 19:00

Ehm.. Hast du zu viel Java programmiert?!

C-/C++-Quelltext

1
2
public: bool  getFoeInPanicDistance(void);
public: bool getFriendsInViewRange(void); 

Das public brauchst nur einmal bis etwas anderes gewollt ist.

C-/C++-Quelltext

1
2
3
public: 
bool getFoeInPanicDistance(void);
bool getFriendsInViewRange(void); 

Zeus

Frischling

  • »Zeus« ist der Autor dieses Themas

Beiträge: 83

Beruf: Schule

  • Private Nachricht senden

6

10.02.2010, 19:03

ich weiß ... aber auf die weise ist es für mich übersichtlicher ...

7

10.02.2010, 20:08

state_Search.h

sollten die Funktionen nicht inline sein, wenn die im header stehen?

Zeus

Frischling

  • »Zeus« ist der Autor dieses Themas

Beiträge: 83

Beruf: Schule

  • Private Nachricht senden

8

10.02.2010, 20:20

warum ? ... hab einfach nur die definition von der dekleration getrennt ...

habs schnell getestest ... also daran liegts nich ...

9

10.02.2010, 20:36

Ich glaube nicht, dass ich dir da helfen kann, dein Projekt ist zu komplex um dort einen Fehler zu finden. Was noch interessant wäre ist Ant.h und _states.h, da diese im Zusammenhang mit deiner Fehlermeldung stehen.

Nox

Supermoderator

Beiträge: 5 272

Beruf: Student

  • Private Nachricht senden

10

10.02.2010, 21:12

Ich glaube nur die _state.h ist interessant denn:

Zitat

wenn beim bug.cpp oben die "_states.h" drin ist gibt es das link problem wenn es ebenfalls bei ant.cpp drin ist


Wahrscheinlich hast du da irgendwo eine Implementierung außerhalb der Klasse. Das kann z.B. durch includieren von cpp Dateien passieren oder durch:
class A { void blub(void) }; void A::blub(void) {}
afaik
PRO Lernkurs "Wie benutze ich eine Doku richtig"!
CONTRA lasst mal die anderen machen!
networklibbenc - Netzwerklibs im Vergleich | syncsys - Netzwerk lib (MMO-ready) | Schleichfahrt Remake | Firegalaxy | Sammelsurium rund um FPGA&Co.

Werbeanzeige