logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
NWNX-AI ?

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Mar 29, 2011 17:31    Post subject: NWNX-AI ? Reply with quote

Has anyone considered making a multi-threaded AI Plugin for nwnx?


I just had this idea..

Good AI in nwn, would mean complex scripts.
Complex scripts can mean increased instruction count
Higher Instruction Count reduces the amount of concurrent creatures that can use that AI Script, or at least degrades nwn server performance.


But what if we took AI Scripts out of the loop?



nwnx Starts up
o NWNX_AI hooks onto where the Normal AI of creatures 'should' be.
o NWNX_AI then on a non-blocking thread carries out the AI Calculations that would normally be carried out inside nwn via VirtualMachine Script Engine. So far, nothing has blocked nwn script calls, or contributed to Instruction Count.
o NWNX_AI then makes decisions about the NPC's actions etc, and then assigns actions to the Action Queue from the Non-Blocking thread in real time.

Sorta like me telling nwnx_funcs, to put a command on the action queue for npc 1 etc, except it is all done without a script trigger.


Because this is carried out on a thread per npc basis, it means that no TMI or nwn server performance is degraded as much as having a large AI Script.


So...
Im not saying Im gonna code this,
But it seems like an intriguing idea.

Is AI something that nwnx could handle?
Back to top
View user's profile Send private message
Squatting Monk



Joined: 28 Jun 2007
Posts: 76

PostPosted: Tue Mar 29, 2011 21:30    Post subject: Reply with quote

I've been tinkering with Memetic AI for a while now, and the thing that's always struck me is the large amount of memory and script processing that would be needed to deploy it on a large scale. I've been thinking about a similar approach using NWNX. Of course, I know nothing about programming in C++ and making my own plugins.

One thing that piqued my interest is the nwnx_lua plugin. I don't know much about LUA, but I know that quite a few games now use it as their scripting language, and a book I recently bought on AI design uses LUA exclusively. Perhaps this would be a good route to go?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Mar 29, 2011 21:34    Post subject: Reply with quote

Ive used LUA in games such as GarrysMod, a physics sandbox game.

Its a very versatile coding language, that being said... it is only as powerful as the methods that are provided to you.


Here is a 'Power' I coded in LUA a while back.

It is inspired after a tv series called Charmed.
One of the Sister Witches has the power to freeze time.

http://www.youtube.com/watch?v=hGoRGMESXi4&feature=channel_video_title
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Wed Mar 30, 2011 7:32    Post subject: Reply with quote

I don't think this is really feasable. Parallel processing / multithreading (whatever it's called nowadays) is somewhat complex even if you do it from the ground up. To "back hack" it into a program what wasn't designed for it is nearly impossible because you have no real control over concurrency (e.g. the main thread decides to destroy a creature while the ai threat has it scan for enemies). The only way to gain that control would be to rebuild every function dealing with with the memory an ai plugin would access and make them threadsafe.

Of course even without multi threading you could speed up processing by putting it in a plugin but you'd have to weigh speed vs. customizability. (Remember the complaints about all the hardcoding in nwn?)
Back to top
View user's profile Send private message Send e-mail MSN Messenger
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Fri Aug 26, 2011 16:21    Post subject: Reply with quote

I think it would be quite easy if you could pass more interesting things to NWNX than a giant string via setting NWNX!MYPLUGIN!BLAHBLAH.... I think there is a limit to that size, but I don't know how many chars off-hand the NWN engine will let you do.

The key to the multithreading problem is let nwserver handle the polling (that is actually a kind of pseudo-multi thread than a real thread if you want to get technical) of the NPCs.

So like,
Code:

void HeartBeat() {
     AI(var1, var2, var,3 var4, var5, varN);
}


where all those var's are the various environmental factors that would be calculated in your AI script.

The Drawback! - variable assignment within the script engine is probably most of the work anyway -- you're not really saving many cycles beyond the script checking conditionals [if statements, etc..] which are not that costly anyway. It almost reminds me of an old college experience where I had a Prof say Bubble Sort and Insertion Sort were both N^2 algorithms and thus equally fast. My ass. It's that data movement, let me tell ya! Bubble is worse; believe it!

The Second Drawback!: Whatever you saved, you'll probably end up losing or even making worse in trying to transcribe all the data you need into a string format that can be sent to the NWNX plugin.

Off-hand though, I can't even think of how the "object" data type could be represented in a string form.......and back. int, float location, string, and effect seem easy enough though.

edit: apologizing in advance for the threadcromancery.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group