Immersive AI Engine by Gavin Bunney discussion
by Fyodor -bank- Osokin · in Torque Game Engine · 02/27/2007 (4:46 am) · 191 replies
Let's discuss the iAI engine here, not spamming the .blog is good :)
The first question - is it based on standard AIPlayer.cc from SDK?
May be it's written in documents, but I haven't read all of them yet..
The first question - is it based on standard AIPlayer.cc from SDK?
May be it's written in documents, but I haven't read all of them yet..
About the author
Game developer.
Recent Threads
#142
Is there anywere I can get a copy of the most up to date version of this. Or is anybody willing to zip up a copy with the patches applied.
Thanks
01/10/2008 (7:12 am)
Hello, Is there anywere I can get a copy of the most up to date version of this. Or is anybody willing to zip up a copy with the patches applied.
Thanks
#143
There are many unsettled variables in all this. Many bugs needing fixing which may increase or decrease agent count. I am releasing this before the usual "I need to code clean and bug fix" which inevitably causes code not to be released in the hope that I can get help in fixing bugs and code which will bring this to fruition sooner.
Needless to say, I am quite excited by the agent count increase, and I am sure with smaller models, this resource will allow for well over 250 agents.
Known Bugs
-Spawning Entertainer Crashes
-Targeting unsuccessful, inhibits certain goal evaluations and causes agents to crab and walk backwards
I compiled this in TGEA 1.0.3, commenting out the gl rendering and not replacing it with GFX calls. So viewing the path will not work unless you uncomment the gl calls or for TGEA you could kindly supply the GFX equivalent.
This next bit seemed really important to suppress crashes, in fact when adding the next two lines to iAIPath.cc I did not have anymore crashes, even when adding excessive amounts of agents.
iAIPath::createPath
at the beginning of iAIPath::getNextPosition
Another point to look out for, I am using my own mesh names and paths, you may want to change it to your own else your agents will not spawn.
If you have followed this thread, were able to implement the script version and been interested in the c++ migration, download from these two links kindly offered and supported by Ben Sparks, unzip them into engine and your example folders.
Script Code
Engine Code
01/16/2008 (12:46 pm)
For those interested in the c++ upgrade. I have completed the upgrade to a level which has allowed me to evaluate the performance of using immersiveAI via script vs c++. Based on the models that I used for my testing, without enabling the AI and merely stacking my scene with the models, I could only implement round 180-195 before my machine specifications gave in. Using script immersiveAI, I could load my machine with round about 55-60 agents. With c++ I could fit between 150-160. There are many unsettled variables in all this. Many bugs needing fixing which may increase or decrease agent count. I am releasing this before the usual "I need to code clean and bug fix" which inevitably causes code not to be released in the hope that I can get help in fixing bugs and code which will bring this to fruition sooner.
Needless to say, I am quite excited by the agent count increase, and I am sure with smaller models, this resource will allow for well over 250 agents.
Known Bugs
-Spawning Entertainer Crashes
-Targeting unsuccessful, inhibits certain goal evaluations and causes agents to crab and walk backwards
I compiled this in TGEA 1.0.3, commenting out the gl rendering and not replacing it with GFX calls. So viewing the path will not work unless you uncomment the gl calls or for TGEA you could kindly supply the GFX equivalent.
This next bit seemed really important to suppress crashes, in fact when adding the next two lines to iAIPath.cc I did not have anymore crashes, even when adding excessive amounts of agents.
iAIPath::createPath
iAIPathNode* startNode = pathMap->getClosestNode(start); iAIPathNode* endNode = pathMap->getClosestNode(end); // check if start and end nodes in the same position + if( !startNode || !endNode ) return false;
at the beginning of iAIPath::getNextPosition
+ if ( !this ) return IAIPATHGLOBAL_INVALID_POSITION;
Another point to look out for, I am using my own mesh names and paths, you may want to change it to your own else your agents will not spawn.
If you have followed this thread, were able to implement the script version and been interested in the c++ migration, download from these two links kindly offered and supported by Ben Sparks, unzip them into engine and your example folders.
Script Code
Engine Code
#145
I ran your code and received the following.
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2736) : error C3861: 'getMoveState': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2740) : error C3861: 'getAimOffset': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2742) : error C3861: 'isAimLocationSet': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2776) : error C3861: 'isAimLocationSet': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2802) : error C3861: 'getMoveState': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2842) : error C3861: 'isMoveSlowdown': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2857) : error C3861: 'getLastLocation': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2879) : error C3861: 'isTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2881) : error C3861: 'setTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2885) : error C3861: 'isTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2887) : error C3861: 'setTargetInLOS': identifier not found
How can I fix this?
01/16/2008 (8:01 pm)
Greg:I ran your code and received the following.
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2736) : error C3861: 'getMoveState': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2740) : error C3861: 'getAimOffset': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2742) : error C3861: 'isAimLocationSet': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2776) : error C3861: 'isAimLocationSet': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2802) : error C3861: 'getMoveState': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2842) : error C3861: 'isMoveSlowdown': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2857) : error C3861: 'getLastLocation': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2879) : error C3861: 'isTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2881) : error C3861: 'setTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2885) : error C3861: 'isTargetInLOS': identifier not found
7>c:\develop\torque\tge_1_5_2\engine\immersiveai\agent\iaiagent.cc(2887) : error C3861: 'setTargetInLOS': identifier not found
How can I fix this?
#146
Just want to say NICE JOB, BRILLIANT. Do have some questions though. So looking at the code obviously it seems almost all functions and goals are done via engine, though in script I see the same functions. Your previous post posts the script code and the engine code. Is it safe to say that the script is not needed anymore? Are there a few scripts needed? The reason why I ask is because I have altered my code to be customized to certain goals and tasks that I need. So when I port your version to mine, I just want to make sure that I'm not missing anything. Thanks a bunch for all your efforts.
Cheers,
DALO
01/16/2008 (10:26 pm)
Hey Greg,Just want to say NICE JOB, BRILLIANT. Do have some questions though. So looking at the code obviously it seems almost all functions and goals are done via engine, though in script I see the same functions. Your previous post posts the script code and the engine code. Is it safe to say that the script is not needed anymore? Are there a few scripts needed? The reason why I ask is because I have altered my code to be customized to certain goals and tasks that I need. So when I port your version to mine, I just want to make sure that I'm not missing anything. Thanks a bunch for all your efforts.
Cheers,
DALO
#147
One thing that I came across that sometimes crashed my game after 1 minute other times 15 minutes and it drove me absolutely bonkers. This may be a possible thing for you as well, I'm not sure though. When ever a bot would create a path follow it and delete it when completed or if interrupted it would delete it. I had checks later on based on certain situations to see if the path was a current object, eg.
%test = isObject(%agent.getCurrentPath())
I would also check if it has a next node and whatever else. Well, when the path was not registered as an object, meaning the bot has not path I noticed that sometimes the actually value of the path was either 0, -1, 99345345, -988349534. Fine whatever, but then boom, crash. From what appeared to be happening is that those garbage numbers would somehow turn into objects......? It was weird, so the random memory garbage bugged me so I wrote a function to make sure that it always had a value of zero in there if the path was ever deleted or completed. It hasn't crashed since :-)
This was the previous method, I'm sure it'll be a little altered now that things have changed.
Stuck near the bottom of iAIAgent.cc
ConsoleMethod( iAIAgent, zeroCurrentPath, void, 3, 3,
"bool iAIAgent.setCurrentPath(iAIPath path) - Sets the current path for the agent to zero."){
// ensure pos passed
if (dStrlen(argv[2]) != 0){
// find the path in the Sim and set the agent path
iAIPath *path;
if (Sim::findObject(dAtoi(argv[2]), path)){
object->zeroCurrentPath(0);
return;
}else{
iAIPath *currentPath = object->getCurrentPath();
if (currentPath)
object->zeroCurrentPath(0);
return;
}
}else{
Con::errorf("&^(*&^(*&^(*&^ ALREADY ZERO (_*()&)&^*(&^%!");
return;
}
}
Then in iAIAgent.h
void zeroCurrentPath(iAIPath* path) { this->mCurrentPath = 0; }
Like I said, it may be a small factor, it may not.
DALO
01/16/2008 (11:33 pm)
Hey,One thing that I came across that sometimes crashed my game after 1 minute other times 15 minutes and it drove me absolutely bonkers. This may be a possible thing for you as well, I'm not sure though. When ever a bot would create a path follow it and delete it when completed or if interrupted it would delete it. I had checks later on based on certain situations to see if the path was a current object, eg.
%test = isObject(%agent.getCurrentPath())
I would also check if it has a next node and whatever else. Well, when the path was not registered as an object, meaning the bot has not path I noticed that sometimes the actually value of the path was either 0, -1, 99345345, -988349534. Fine whatever, but then boom, crash. From what appeared to be happening is that those garbage numbers would somehow turn into objects......? It was weird, so the random memory garbage bugged me so I wrote a function to make sure that it always had a value of zero in there if the path was ever deleted or completed. It hasn't crashed since :-)
This was the previous method, I'm sure it'll be a little altered now that things have changed.
Stuck near the bottom of iAIAgent.cc
ConsoleMethod( iAIAgent, zeroCurrentPath, void, 3, 3,
"bool iAIAgent.setCurrentPath(iAIPath path) - Sets the current path for the agent to zero."){
// ensure pos passed
if (dStrlen(argv[2]) != 0){
// find the path in the Sim and set the agent path
iAIPath *path;
if (Sim::findObject(dAtoi(argv[2]), path)){
object->zeroCurrentPath(0);
return;
}else{
iAIPath *currentPath = object->getCurrentPath();
if (currentPath)
object->zeroCurrentPath(0);
return;
}
}else{
Con::errorf("&^(*&^(*&^(*&^ ALREADY ZERO (_*()&)&^*(&^%!");
return;
}
}
Then in iAIAgent.h
void zeroCurrentPath(iAIPath* path) { this->mCurrentPath = 0; }
Like I said, it may be a small factor, it may not.
DALO
#148
@DALO - Out of sheer laziness I left the script codes there, at least 95% of the script codes can go, its really just the initialization of Immersive AI which is required and the spawns for the different agents. Hmmm, it looks like the path problem might be related to the one I experienced in the engine. I do a small validity check, and ignore it if its invalid, is it related ?
01/17/2008 (2:35 am)
@dArchitect - you will need to download that AIPlayer Code file too.@DALO - Out of sheer laziness I left the script codes there, at least 95% of the script codes can go, its really just the initialization of Immersive AI which is required and the spawns for the different agents. Hmmm, it looks like the path problem might be related to the one I experienced in the engine. I do a small validity check, and ignore it if its invalid, is it related ?
#149
01/17/2008 (5:47 pm)
Does anyone have a 'quick start' guide that helps with putting/adding bots, seeing the grid layouts, etc.
#150
I'm using the c++ port and the global function "seek_generatePath" in iAIAgent.cc calls
I've compared this code with the script equivalent and the script uses a global pathMap to start off (does not create a new, empty one), so I'm not sure what exactly is going on here.
Is the global "seek_generatePath" function correct? Is anyone else seeing this problem?
01/23/2008 (8:11 am)
I'm encountering an access violation while AIs are trying to find paths.I'm using the c++ port and the global function "seek_generatePath" in iAIAgent.cc calls
pathmap->getClosestNode(...)" using the "new iAIPathMapThis causes a problem when searching for the closest node, which calls
closestNode = this->mGrids[this->mTerrainGridIndex]->getClosestNode(position);but mGrids is NULL and it crashes.
I've compared this code with the script equivalent and the script uses a global pathMap to start off (does not create a new, empty one), so I'm not sure what exactly is going on here.
Is the global "seek_generatePath" function correct? Is anyone else seeing this problem?
#151
Vector- list; // should I use Item or ItemData?
//obtain all health's on a particular level.
char* groupName = "L1Health";
SimGroup* pMissionGroup = dynamic_cast(Sim::findObject(groupName));
// it does loop the appropriate number of times, so I know that it is finding the objects
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
list->push_back(dynamic_cast- (*itr)); // what does dynamic_cast
- (*itr) do????????
}
Now, I don't know if this is the proper way to obtain a list of pointers to these Items that I need. I think it is but what I really need to know is the position of that object so I can generate a path to it. How do I get that?
I tried doing a for loop on my list to access each object in the list but can't seem to get anything. When I use VS2005 and step through it I can identify some of the component's to that object, but getPosition is not one of them......? I'm not a C++ guru by all means but have slowly been figuring things out, but this I cannot.
Any help would be hugely appreciated.
Thx.
DALO
01/23/2008 (9:05 pm)
Does anyone out there in the world know how to properly obtain objects from sim groups? What I want to do is iterate through a list of items in a specific simgroup and have my bot choose the closest path. For example I want to get a list of all the Health items for a specific level.Vector
//obtain all health's on a particular level.
char* groupName = "L1Health";
SimGroup* pMissionGroup = dynamic_cast
// it does loop the appropriate number of times, so I know that it is finding the objects
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
list->push_back(dynamic_cast
}
Now, I don't know if this is the proper way to obtain a list of pointers to these Items that I need. I think it is but what I really need to know is the position of that object so I can generate a path to it. How do I get that?
I tried doing a for loop on my list to access each object in the list but can't seem to get anything. When I use VS2005 and step through it I can identify some of the component's to that object, but getPosition is not one of them......? I'm not a C++ guru by all means but have slowly been figuring things out, but this I cannot.
Any help would be hugely appreciated.
Thx.
DALO
#152
@DALO - Can you not call item->getPosition()
01/24/2008 (2:24 am)
@Jason - Are you allowing the script to initialize the path. The c++ codes are looking for the original immersiveAI script name, so if you have changed it, it too will fail.@DALO - Can you not call item->getPosition()
#153
01/24/2008 (11:05 am)
@Greg yes the script does build the $iAIPathMap, and I have found something that makes it work, but not sure if it's right. I replaced instances ofiAIPathMap * pathMap = new iAIPathMap();in iAIAgent.cc with
iAIPathMap * pathMap;
if (!Sim::findObject(dAtoi(Con::getVariable("$iAIPathMap")), pathMap)){
return;
}Then things started looking up. I don't know if this is correct, but it is working for me.
#154
// groupName is the name of the simgroup
SimGroup* pMissionGroup = dynamic_cast(Sim::findObject(groupName));
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
Item *pItem = new Item;
pItem = dynamic_cast- (*itr);
list->push_back(pItem);
}
@Jason, good find, same thing was happening to me and your tid bit fixed it, thx :-)
01/24/2008 (11:43 am)
Yeah, I don't know? item->getPosition() would not work but this does for those who ever want to find Item objects in a simgroup:// groupName is the name of the simgroup
SimGroup* pMissionGroup = dynamic_cast
for(SimGroup::iterator itr = pMissionGroup->begin(); itr != pMissionGroup->end(); itr++){
Item *pItem = new Item;
pItem = dynamic_cast
list->push_back(pItem);
}
@Jason, good find, same thing was happening to me and your tid bit fixed it, thx :-)
#155
01/24/2008 (1:30 pm)
Good work Jason ;)
#156
I also think I found the Targetting bug you mentioned on Jan 16.
The iAIAgent supplied its own getAIMove function that looked much like AIPlayer::getAIMove except where AIPlayer says:
The problem here is AIPlayer::setAimLocation removes the reference to the aimobject:
When I removed getAIMove and its prototype (just remove the function, nothing special here), the bots fought it out until one of the teams was completely dead.
01/25/2008 (11:22 am)
@GregI also think I found the Targetting bug you mentioned on Jan 16.
The iAIAgent supplied its own getAIMove function that looked much like AIPlayer::getAIMove except where AIPlayer says:
// Update the aim position if we're aiming for an object
if (mAimObject)
mAimLocation = mAimObject->getPosition() + mAimOffset;iAIAgent says:// Update the aim position if we're aiming for an object
if (getAimObject())
setAimLocation( getAimObject()->getPosition() + getAimOffset() );The problem here is AIPlayer::setAimLocation removes the reference to the aimobject:
void AIPlayer::setAimLocation( const Point3F &location )
{
mAimObject = 0;
...
}When I removed getAIMove and its prototype (just remove the function, nothing special here), the bots fought it out until one of the teams was completely dead.
#157
Thanks a stack for helping to debug !
When u mention removing getAIMove and its prototype, is that from AIPlayer as well as iAIAgent ?
01/25/2008 (11:36 am)
@JasonThanks a stack for helping to debug !
When u mention removing getAIMove and its prototype, is that from AIPlayer as well as iAIAgent ?
#158
01/25/2008 (12:12 pm)
Just remove it from iAIAgent.
#159
SimGroup *g = Sim::getClientGroup();
for (SimGroup::iterator j = g->begin(); j != g->end(); j++){
GameConnection *client = dynamic_cast( *j );
if(client){
Player *enemy= dynamic_cast(client->getControlObject() );
// this next part causes a crash.......
Point3F enemyPosition = enemy->getPosition();
.....
.....
}
It pulls up my client information but for my Player* enemy, all the enemy information does not exist. So when it calls getPosition() it crashes.
Is this how to properly get a player's info?
Any help would be greatly appreciated.
Thx, DALO
*EDIT* well I found that if I put a if(enemy == NULL) the condition will be true and it won't attempt to get position as it exits the function. But since this is the case, how do I get players positions, particularly myself. I'm trying to get the bot to scan the field for any client that is visible, if they see someone, attack. Thx again for any help.
01/25/2008 (2:56 pm)
Well, it's getting close to friday night and I'm hoping that someone will have an answer to this asap. How do I get a list of all clients in the game? I had a solution but it causes errors for example:SimGroup *g = Sim::getClientGroup();
for (SimGroup::iterator j = g->begin(); j != g->end(); j++){
GameConnection *client = dynamic_cast
if(client){
Player *enemy= dynamic_cast
// this next part causes a crash.......
Point3F enemyPosition = enemy->getPosition();
.....
.....
}
It pulls up my client information but for my Player* enemy, all the enemy information does not exist. So when it calls getPosition() it crashes.
Is this how to properly get a player's info?
Any help would be greatly appreciated.
Thx, DALO
*EDIT* well I found that if I put a if(enemy == NULL) the condition will be true and it won't attempt to get position as it exits the function. But since this is the case, how do I get players positions, particularly myself. I'm trying to get the bot to scan the field for any client that is visible, if they see someone, attack. Thx again for any help.
#160
Just wondering if there is a missing step? when I remove the getAIMove from iAIAgent my bot's don't move. The iAIAgent::onReachDestination function never get's called. Any ideas??
Thx.
01/25/2008 (7:52 pm)
@JasonJust wondering if there is a missing step? when I remove the getAIMove from iAIAgent my bot's don't move. The iAIAgent::onReachDestination function never get's called. Any ideas??
Thx.
Torque 3D Owner Greg Davis