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 Ruby
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux development
View previous topic :: View next topic  
Author Message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Feb 09, 2009 12:25    Post subject: Reply with quote

Please send me the patch to my email (with "NWNX" in the subject field) or post it here.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
JeffSheets



Joined: 04 Feb 2009
Posts: 18

PostPosted: Mon Feb 09, 2009 19:07    Post subject: Reply with quote

virusman wrote:
Please send me the patch to my email (with "NWNX" in the subject field) or post it here.


Link to a pastebin: here Hmmm... if that mangled the diff file too much, PM me your email address, virusman, and I'll send the original. I'd post the text here, but it's 35 KB.
Back to top
View user's profile Send private message
JeffSheets



Joined: 04 Feb 2009
Posts: 18

PostPosted: Tue Feb 10, 2009 0:42    Post subject: Reply with quote

Now that I've got item properties working, I've begun work on a workaround to the ActionDoCommand, AssignCommand, and DelayCommand problems. I believe I may have a fix, that only requires three small scripts to be loaded into the module, and one Relatively short ruby source file that overrides the NWScript module's definitions for those commands.

If it all goes as planned, this will be one less thing to be concerned over... and the Talent functions are unimportant to me... at least for now.
Back to top
View user's profile Send private message
JeffSheets



Joined: 04 Feb 2009
Posts: 18

PostPosted: Tue Feb 10, 2009 5:12    Post subject: Reply with quote

Okay... I'm certain that my action type workarounds are working perfectly, so here's the source code:
Code:
// relay_action.nss
#include "nwnx_ruby"

void main() {
    object oMod = GetModule();
    string sCmd = IntToString(GetLocalInt(oMod,"RELAY_CMD"));
    ActionDoCommand(RubyEvalVoid("ActionSingleton.ExecCommand("+sCmd+")"));
    DeleteLocalInt(oMod,"RELAY_CMD");
}

Code:
// relay_assign.nss
#include "nwnx_ruby"

void main() {
    object oMod = GetModule();
    object oRelay = GetLocalObject(oMod,"RELAY_OBJECT");
    string sCmd = IntToString(GetLocalInt(oMod,"RELAY_CMD"));
    AssignCommand(oRelay,RubyEvalVoid("ActionSingleton.ExecCommand("+sCmd+")"));
    DeleteLocalObject(oMod,"RELAY_OBJECT");
    DeleteLocalInt(oMod,"RELAY_CMD");
}

Code:
// relay_delay.nss
#include "nwnx_ruby"

void main() {
    object oMod = GetModule();
    float fDelay = GetLocalFloat(oMod,"RELAY_DELAY");
    string sCmd = IntToString(GetLocalInt(oMod,"RELAY_CMD"));
    DelayCommand(fDelay,RubyEvalVoid("ActionSingleton.ExecCommand("+sCmd+")"));
    DeleteLocalFloat(oMod,"RELAY_DELAY");
    DeleteLocalInt(oMod,"RELAY_CMD");
}

Here's the code for RubyEvalVoid, which you can, and probably ought to update with an exception catching system:
Code:
void RubyEvalVoid(string sCode) {
    object oMod = GetModule();
    SetLocalString(oMod,"NWNX!RUBY!EVAL",sCode);
}

And now the ruby interface file. This file or code should be loaded in your preload ruby script, or during OnModuleLoad. At the very least it needs to be run before you ever use one of the three action based commands.
Code:
module ActionSingleton
   def ActionSingleton.Store(action)
      @cmds = Hash.new unless @cmds
      unless @cmdnext
         @cmdnext = 1
      else
         @cmdnext += 1
      end
      @cmds[@cmdnext] = action
      @cmdnext
   end
   def ActionSingleton.ExecCommand(idx)
      cmd = @cmds[idx]
      if cmd.is_a? Proc then
         cmd.call
      end
      @cmds[idx] = nil
   end
end

module NWScript
   def NWScript.AssignCommand(obj, &action)
      cmd = ActionSingleton.Store(action)
      mod = NWScript.GetModule()
      NWScript.SetLocalObject(mod,"RELAY_OBJECT",obj)
      NWScript.SetLocalInt(mod,"RELAY_CMD",cmd)
      NWScript.ExecuteScript("relay_assign",$OBJECT_SELF)
   end
   def NWScript.ActionDoCommand(&action)
      cmd = ActionSingleton.Store(action)
      mod = NWScript.GetModule()
      NWScript.SetLocalInt(mod,"RELAY_CMD",cmd)
      NWScript.ExecuteScript("relay_action",$OBJECT_SELF)
   end
   def NWScript.DelayCommand(t, &action)
      cmd = ActionSingleton.Store(action)
      mod = NWScript.GetModule()
      NWScript.SetLocalFloat(mod,"RELAY_DELAY",t)
      NWScript.SetLocalInt(mod,"RELAY_CMD",cmd)
      NWScript.ExecuteScript("relay_delay",$OBJECT_SELF)
   end
end

You can call the functions as follows:
Code:
NWScript.DelayCommand(10.0) {
   // code to delay 10 seconds.
}
NWScript.AssignCommand(oCreature) {
   // code to execute with oCreature as $OBJECT_SELF.
}
NWScript.ActionDoCommand {
   // Code to execute as a command in $OBJECT_SELF's action queue.
}

You can, to my knowledge, nest the commands as much as you want.
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Tue Feb 10, 2009 21:05    Post subject: Reply with quote

Nice one! Any idea what the performance is like? Well whatever - this is a great development whether it's 100% optimal or not.
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Tue Feb 10, 2009 21:59    Post subject: Reply with quote

As I have described here, I am using a very similar approach with roe. Properly done, performance impact is negligible.
Back to top
View user's profile Send private message
JeffSheets



Joined: 04 Feb 2009
Posts: 18

PostPosted: Wed Feb 11, 2009 4:31    Post subject: Reply with quote

Yeah, unless you're calling a large number of action commands one after another, the performance impact shouldn't be noticeable. If you need to assign lots of commands to a single object, just do it once and put all of the commands within a single 'do || end' or { } block in ruby. Both my method and elven's method are practically identical, so which one you use shouldn't make any difference either.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sun Aug 02, 2009 17:51    Post subject: Reply with quote

Hint: elven's nwn-lib is a complete replacement for LetoScript. Smile
Combined with NWNX Ruby, it's 100 times more powerful tool than NWNX-Leto.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Mon Oct 05, 2009 13:18    Post subject: Reply with quote

I can't compile the ruby plugin - all times i try i get an error...

Code:

g++ -w -fPIC -shared -W -Wall  -o nwnx_ruby.so FunctionHooks.o ruby_int.o NWNXRuby.o plugin-ruby.o -lruby1.8  -DHAVE_CONFIG_H
/usr/lib/gcc/i586-suse-linux/4.1.0/../../../../i586-suse-linux/bin/ld: cannot find -lruby1.8
collect2: ld returned 1 exit status
make: *** [nwnx_ruby.so] Error 1

...

ruby -v
ruby 1.8.4 (2005-12-24) [i586-linux]


Can you see what i'm making wrong? I'm Running Suse 10.3 on my Root-Server...
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Mon Oct 05, 2009 13:22    Post subject: Reply with quote

Some distros name the shared library without the version number. Try -lruby.
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Mon Oct 05, 2009 14:09    Post subject: Reply with quote

damn - that's the reason Wink

Ruby now compiles without any errors...
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Tue Oct 06, 2009 8:00    Post subject: Reply with quote

Another day - another error...

After activating the nwnx_ruby plugin i get a segmentation fault error. I have set the correct path to roe in nwnx2.ini
Code:

[ruby]
preload=/home/nwn/svn/roe/preload_wrap.rb

nwn is located in /home/nwn

Have i missed something? Currently i have disabled the plugin upon i know how to solve this error...
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Tue Oct 06, 2009 10:46    Post subject: Reply with quote

Any exception thrown in preloadable ruby code will segfault the server. With the roe wrapper script, the only line that is not wrapped inside begin/rescue is the rubygems require. If I had to hazard a guess, I'd say you do not have rubygems installed.
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Tue Oct 06, 2009 10:59    Post subject: Reply with quote

Also: Plase note that I am not working actively on roe at the moment. roe is workable, if I recall correctly, but the API is still incomplete and it will probably have a few bugs of varying severity.

The little time I have for NWN, I put into nwnx_ice and kobold (but that does not mean that roe is abandoned). I found the roe drb approach to be lacking in performance with certain usecases. YMMV.
Back to top
View user's profile Send private message
Mikel of Avalon



Joined: 29 Dec 2004
Posts: 72
Location: Germany

PostPosted: Wed Oct 28, 2009 9:40    Post subject: Reply with quote

While i currently not using ruby yet and i only want to make some expirience with it, do you think i should switch to nwnx ice? Kobold? Whats this - are there any documentations?
_________________
Mikel of Avalon

Kalandur - Die vergessene Welt
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux development All times are GMT + 2 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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