View previous topic :: View next topic |
Author |
Message |
Fireboar
Joined: 17 Feb 2008 Posts: 323
|
Posted: Tue Jan 19, 2010 17:08 Post subject: |
|
|
Yes, I was anticipating using finals to pass variables into the delayed method but that just seems like such a hack.
I'd say pseudo-heartbeat isn't exactly the right word for what I'm after. An event triggers a DelayCommand, which then triggers in itself a DelayCommand to the same function. And so on, until a given stopping condition. An example application would be a bleeding script, in which the stopping condition would be when the PC reaches -10 or 0 HP. The only way I can think of is something like this...
Code: | final NWObject bleeding = NWScript.getLastPlayerDying();
final Anon<Void> bleed = new Anon<Void>() {
public Void e() {
// do stuff, probably make a save and a point of damage
if (not still bleeding) {
Scheduler.delay(bleeding, 6, bleed);
}
return null;
}
};
Scheduler.delay(bleeding, 6, bleed); |
But that doesn't work, because bleed hasn't been initialised so it would throw a compiler error at the delay in e().
In NWScript this would be straightforward:
Code: | void bleed() {
// do stuff, probably make a save and a point of damage
if (not still bleeding) {
DelayCommand(6.0, bleed());
}
}
void main() {
AssignCommand(GetLastPlayerDying(), DelayCommand(6.0, bleed()));
} |
On an unrelated note, where's Runnable coming from? I didn't see anything like that in jvm.jar. |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Tue Jan 19, 2010 17:17 Post subject: |
|
|
Code: |
ScheduledEvery sched = new ScheduledEvery(2000, new ScheduledAnon() {
@Override
public void e(ScheduledEvery x) {
if (x.getRunCount() > 10) x.stop();
// blah
}
}, Policy.AS_AVAILABLE);
Scheduler.every(sched);
|
That doesn't solve your context issue. Java doesn't really do with dynamic closures and keeping state somewhere else is a viable alternative (NWScript does it the same way, just has different syntax). I'll give that some thought later on - gotta go for now.
Runnable. |
|
Back to top |
|
|
Fireboar
Joined: 17 Feb 2008 Posts: 323
|
Posted: Tue Jan 19, 2010 17:39 Post subject: |
|
|
Ah, perfect. That answers the question, thanks. |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Tue Jan 19, 2010 19:27 Post subject: |
|
|
Sorry, I haven't slept tonight. A bit tired.
To keep per-tick state, just use local variables on your anonymous Runnable. If you need external access, create a custom class for it and pass that around.
Code: |
ScheduledEvery sched = new ScheduledEvery(2000, new ScheduledAnon() {
private boolean bleeding = false; // whatever
@Override
public void e(ScheduledEvery x) {
if (bleeding) // whatever
if (x.getRunCount() > 10) x.stop();
}
}, Policy.AS_AVAILABLE);
Scheduler.every(sched);
|
|
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Sun Feb 14, 2010 14:18 Post subject: |
|
|
Small update: I have very little time these days to actually spend on NWNXJVM. However, it's NOT dead, Jim! I just don't know when I find some quality time to hack on it.
Also, I have published some prototype OSGi bundles at the usual location:
* AspectJ support: Annotations that manage all lowlevel nwn context scheduling for you:
Code: |
public class MyBundle extends ... {
@ScheduleWait int someMethod() {
// executed synchronously inside nwn context
return NWScript.getLocalInt(...);
}
}
|
To build your OSGi bundles with AspectJ and Eclipse integration, be sure to check "Use class files compiled in the workspace" (under "Export plugin, Options" when for example clicking on the button at the topright corner in the manifest file editor) when building your bundle; the aspectj-weaved files will be discarded otherwise and you'll be left wondering why it doesn't seem to work at all.
* IdleState bundle providing Listener notifications for creature action queue changes/movement
There is so much to do still ..
* document all of OSGi on the wiki
* cleanup all other plugins and publish them
* some minor core fixes and tests: string handling for non-latin1 charsets
* some struct wraps perhaps
Anyone wanting to try it out meanwhile would be best served with catching me on Jabber or ICQ.
Also, some updates to the libraries (haven't built a new .jar yet):
* Color class providing String color helpers
* ScheduledEvery has been de-parametrised (not needed)
* SchedulerListeners now a SortedSet, add some remove methods
* some useful methods in Effect, Iprp, Vector and Location
Last edited by elven on Tue May 01, 2012 23:21; edited 1 time in total |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Fri Mar 26, 2010 12:50 Post subject: |
|
|
The newest git master requires NWNX 2.8 alpha and uses the new plugin/event system to subscribe to SCO/RCO and resman events. Please be aware that it will not build against trunk anymore, since that does not provide the features required. You can simply build a 2.8 core nwnx2.so and use your trunk plugins (except odbc2 from 2.8, which is required for sco/rco, and resman from 2.8 for resman support if desired) as they are.
The real work is happening on the OSGi side, which now approaches something resembling production-readiness. I'm afraid you're on your own (for now) in getting to know all that is to be had.
Last edited by elven on Tue May 01, 2012 23:21; edited 1 time in total |
|
Back to top |
|
|
Hialmar
Joined: 15 Jun 2005 Posts: 32
|
Posted: Sun May 29, 2011 18:23 Post subject: |
|
|
Just a FYI that I am working on a version of this for NWNX4.
A first version is working and is referenced here:
http://www.nwnx.org/phpBB2/viewtopic.php?t=1772 _________________ Hialmar, A Land Far Away Infrastructure Administrator |
|
Back to top |
|
|
Mefisto
Joined: 20 Dec 2011 Posts: 4
|
Posted: Wed Jun 05, 2013 19:21 Post subject: |
|
|
Code: | blah blah blah registering
.
.
.
[Registering JNI native method org.nwnx.nwnx2.jvm.NWScript.getObjectsInPersistentObject]
[Dynamic-linking native method java.io.FileOutputStream.writeBytes ... JNI]
Initializing TestRunner. This class runs various sanity tests and benchmarks.
If anything in this class makes your server crash, something is wrong and NEEDs to be fixed!
You need to load a module that has at least one event firing on a creature sometime.
JVM plugin registered.
OPTIMIZATIONS plugin registered.
CHAT plugin registered.
FUNCS plugin registered.
EVENTS plugin registered.
ODBC plugin registered.
AREAS plugin registered.
FIXES plugin registered.
WEAPONS plugin registered.
TMI plugin registered.
* NWNX2 activated.
Neverwinter Nights Server
Build:8109
Copyright BioWare Corp 1998-2004
Server: Loading...
Checked JNI functions are being used to validate JNI usage
FATAL ERROR in native method: Bad global or local ref passed to JNI |
Java:
Code: | OpenJDK Runtime Environment (IcedTea6 1.11.11) (rhel-1.61.1.11.11.el6_4-i386)
OpenJDK Server VM (build 20.0-b12, mixed mode) |
I am using NWN Extender v2.8-dev compiled on CentOS 6.3. Any ideas?[/code] |
|
Back to top |
|
|
Mefisto
Joined: 20 Dec 2011 Posts: 4
|
Posted: Wed Jun 05, 2013 19:28 Post subject: |
|
|
Code: | blah blah blah registering
.
.
.
[Registering JNI native method org.nwnx.nwnx2.jvm.NWScript.getObjectsInPersistentObject]
[Dynamic-linking native method java.io.FileOutputStream.writeBytes ... JNI]
Initializing TestRunner. This class runs various sanity tests and benchmarks.
If anything in this class makes your server crash, something is wrong and NEEDs to be fixed!
You need to load a module that has at least one event firing on a creature sometime.
JVM plugin registered.
OPTIMIZATIONS plugin registered.
CHAT plugin registered.
FUNCS plugin registered.
EVENTS plugin registered.
ODBC plugin registered.
AREAS plugin registered.
FIXES plugin registered.
WEAPONS plugin registered.
TMI plugin registered.
* NWNX2 activated.
Neverwinter Nights Server
Build:8109
Copyright BioWare Corp 1998-2004
Server: Loading...
Checked JNI functions are being used to validate JNI usage
FATAL ERROR in native method: Bad global or local ref passed to JNI |
Java:
Code: | OpenJDK Runtime Environment (IcedTea6 1.11.11) (rhel-1.61.1.11.11.el6_4-i386)
OpenJDK Server VM (build 20.0-b12, mixed mode) |
I am using NWN Extender v2.8-dev compiled on CentOS 6.3. Any ideas? |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Sun Jun 16, 2013 12:55 Post subject: |
|
|
This is probably because of recent-ish changes in the JNI api.
Try removing -Xcheck:jni from your configuration string. It should still *run* but you will probably break things if you do fancy after-the-fact classloading. |
|
Back to top |
|
|
pixelord
Joined: 24 Oct 2011 Posts: 15
|
Posted: Tue Jun 25, 2013 6:51 Post subject: |
|
|
While trying to load the nwnx_jvm.so it is showing this error/message:
Cannot hook SCORCO or ResMan events!
Am I missing something?
Is that common?
Thanks a lot in advance. _________________ Pixelord |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Tue Jun 25, 2013 10:08 Post subject: |
|
|
ResMan is the resource manager plugin (nwnx_resman), which can be used by nwnx_jvm to load arbitary resource files into the game (like new areas in conjunction with nwnx_areas).
SCO/RCO is shorthand for Store/RetrieveCampaignObject(), which can be hooked to load item, creature and placeable resrefs from a database. nwnx_jvm hooks those that you can just send arbitary bytestream data to load into the game.
Neither are neccessary for nwnx_jvm to work, unless you specifically want to use those features. |
|
Back to top |
|
|
Zunath
Joined: 06 Jul 2006 Posts: 183
|
Posted: Sun Jan 18, 2015 2:28 Post subject: |
|
|
Hey,
I think I'm getting close to setting this up. I seem to be running into a problem though.
I've added this line to my script:
export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
However, when I go to start my server I get a segfault when it tries to load nwnx_jvm. I know it's this plugin because I've taken it out of the NWN folder and the server loaded just fine.
I'm not sure what to do here - I'm guessing it has to do with the fact that I'm using OpenJava but that was the only version I was able to locate on Ubuntu.
Not sure if anyone is still watching this thread but if there are any lurkers I would really appreciate some help. Been looking forward to using this plugin.
Thanks in advance for any help! |
|
Back to top |
|
|
elven
Joined: 28 Jul 2006 Posts: 259 Location: Germany
|
Posted: Sun Jan 18, 2015 2:44 Post subject: |
|
|
Zunath wrote: | Hey,
I think I'm getting close to setting this up. I seem to be running into a problem though.
I've added this line to my script:
export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server
However, when I go to start my server I get a segfault when it tries to load nwnx_jvm. I know it's this plugin because I've taken it out of the NWN folder and the server loaded just fine.
I'm not sure what to do here - I'm guessing it has to do with the fact that I'm using OpenJava but that was the only version I was able to locate on Ubuntu.
Not sure if anyone is still watching this thread but if there are any lurkers I would really appreciate some help. Been looking forward to using this plugin.
Thanks in advance for any help! |
If you get a segfault you can inspect it with gdb. Additionally, the JVM should give you a hs_error_something.txt file that shows where it crashes, if the JVM comes up at all. Check for those files for starters. |
|
Back to top |
|
|
Zunath
Joined: 06 Jul 2006 Posts: 183
|
Posted: Sun Jan 18, 2015 3:08 Post subject: |
|
|
For future readers, elven provided this in a PM:
Quote: |
You can check where it crashes, if you get a corefile, with
$ gdb -c corefile_name ./nwserver
Then just type "bt" to get the backtrace.
If you dont get a core, try
$ ulimit -c unlimited
|
I was able to track down the problem - my nwnx2.so file was out of date. Moving that in from the latest build fixed my problem.
Thanks so much elven - now I can really give this thing a shot! |
|
Back to top |
|
|
|
|
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
|