newLISP Fan Club

Forum => newLISP Graphics & Sound => Topic started by: newdep on September 30, 2007, 09:26:34 AM

Title: [Game] worm
Post by: newdep on September 30, 2007, 09:26:34 AM
Here a Sunday afternoon game ;-)



(load "//http://www.nodep.nl/downloads/newlisp/worm.lsp")



Norman.
Title:
Post by: newdep on September 30, 2007, 12:24:45 PM
version 2 is updated, some tweaking done, added a new worm ;-)...
Title:
Post by: newdep on September 30, 2007, 03:07:33 PM
version 3 is posted... thats it for today ;-)



enjoy..
Title:
Post by: cormullion on September 30, 2007, 03:38:40 PM
Good stuff! Tomorrow, PacMan, perhaps?



I found that it didn't start reliable until I moved this line:


(while (gs:check-event 2000)
   (gs:request-focus 'C)



Also, I tried to change the timings to get the movement smooth but fast. It's not easy! Sometimes I got:



Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 18 >= 14

        at java.util.Vector.elementAt(Vector.java:432)

        at CanvasWidget$MyCanvas.render(CanvasWidget.java:639)
Title:
Post by: newdep on September 30, 2007, 11:47:31 PM
Quote from: "cormullion"Good stuff! Tomorrow, PacMan, perhaps?



I found that it didn't start reliable until I moved this line:


(while (gs:check-event 2000)
   (gs:request-focus 'C)



Also, I tried to change the timings to get the movement smooth but fast. It's not easy! Sometimes I got:



Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 18 >= 14

        at java.util.Vector.elementAt(Vector.java:432)

        at CanvasWidget$MyCanvas.render(CanvasWidget.java:639)




thanks for the test...I thought about packman ;-) ..



Yes the speed is perhpas an issue, though I did not find any strange

behaviour bewtween my AMD64 3200+ and my Intel Dual Core..



the check-even I have left in 10000 and put in a (sleep 1) for the official delay.



I only need to use    (gs:request-focus 'C) once on windows and Linux? I dont

know if macOS needs it inside the while loop..





But there is another problem ;-) that is flickering when the tail gets bigger

than 100.. On linux it realy starts flickering on windows its a little less bad..

But that is because I need to redraw the tags.. I did not find a good way

to "Append" tags actualy without deleting...
Title:
Post by: newdep on October 01, 2007, 03:36:13 AM
new version v0.5 ..lots of changes!!!
Title:
Post by: pjot on October 01, 2007, 03:50:30 AM
First run in Linux delivers this


Quote
peter[~]$ newlisp worm.lsp



array, list or string expected : (env "NEWLISPDIR")


If I put this variable to "/usr/bin" according to the example in the manual, I get this:


Quote
peter[~]$ newlisp worm.lsp



problem accessing file : "/usr/bin/guiserver.lsp"




However, in Linux the file 'guiserver.lsp' by default resides in "/usr/share/newlisp".



So after executing "export NEWLISPDIR=/usr/share/newlisp" in a Bash shell, your game runs fine, even on my Lifebook with a 700Mhz processor :-)



Peter
Title:
Post by: cormullion on October 01, 2007, 03:52:13 AM
I don't think request focus needs to be in the event loop. But worm wouldn't work for me unless I moved it to later in the script. Perhaps just before the event loop is OK.
Title:
Post by: newdep on October 01, 2007, 04:00:35 AM
Cormullion ->

The new version has het focus in the event loop, seems it needs to be there ;-)

better this way.. But is you speed oke on the Mac?





Peter ->

Is the speed fine on the 700 Mhz? (in version v0.5?, just uploaded)
Title:
Post by: newdep on October 01, 2007, 04:07:57 AM
Just found an issue.. v0.5



Seems that under Linux the speed it stable all the time..



But under windows the speed if full after playing it twice.. can find the problem.
Title:
Post by: cormullion on October 01, 2007, 04:10:00 AM
Focus is fine. It's very fast but choppy.



I get game over after five seconds or so. That's no fun... :(
Title:
Post by: newdep on October 01, 2007, 04:20:03 AM
Uploaded v0.7, which runs fine now on Windows and Linux.

Both have steady speed.



Its difficult to regulate the sloppyness, I dont see that here on window and

linux, could be specific MaC+java or even your fast CPU ;-)
Title:
Post by: Lutz on October 01, 2007, 05:42:16 AM
newdep:


QuoteAlso, I tried to change the timings to get the movement smooth but fast. It's not easy! Sometimes I got:



Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 18 >= 14

at java.util.Vector.elementAt(Vector.java:432)

at CanvasWidget$MyCanvas.render(CanvasWidget.java:639)


The exception happens when Java is rendering the array of tagged objects and a tag is deleted at the same time. Try to use 'gs:hide-tag' and 'gs:show-tag' instead. Or do all 'gss:xxx-tag' operation with 'nil' as the last parameter, i.e:


(gs:move-tag 'mytag x y nil) ; suppress screen update

Then after all tag operations do a 'gs:update' or any 'gs:xxx-tag' operation without the the 'nil' flag to force a re-rendering operation. If neither 'nil' or 'true' is given in a tag operation then guiserver.lsp assumes 'true'.





pjot:


Quotearray, list or string expected : (env "NEWLISPDIR")


Since version 9.2.1 NEWLISPDIR is automatically put in the environment when newlisp starts up. In /usr/share/newlisp on all UNIX and into %PROGRAMFILES%/newlisp on Win32.



Unfortunately the not-updated documentation for 'env' also uses NEWLISPDIR in an example but puts it in /usr/bin, this is where the confusion comes from ;). Since the last development version all demo files for guiserver are coded using


(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

and this should work on all platforms since 9.2.1



Lutz
Title:
Post by: newdep on October 01, 2007, 07:08:14 AM
Okido, I changed towards your advice..



Lutz, I do have a sound problem though;-)



gs:play-sound does it 3 or 4 times and then its quiet nothing plays anymore...

Im wondering if that could be a timing issue in the event-loop or perhpas a

"sound close" inside java?



Norman.
Title:
Post by: Lutz on October 01, 2007, 08:02:07 AM
Using sound-demo.lsp and a 11sec .wav file I could not repeat this on Mac OS X, loading the file 20 times.



Can you write a small routine to reproduce this? Did you see this on Linux or on Windows?



Lutz
Title:
Post by: newdep on October 01, 2007, 08:36:43 AM
I think its a key-event or buffer update issue.. but not 100% sure..



here is the demo ->

(load "//http://www.nodep.nl/downloads/newlisp/sound.lsp")

(it includes the wav file)



when you start it... press some random keys on the keyboard

and keep you ear on the sound...



Its also happens without pressing the keyboard checked now...





PS: only happens on Linux as it seems now..



Norman.
Title:
Post by: Lutz on October 01, 2007, 08:55:01 AM
Perhaps a platform issue. On OS X this seems to run forever with or without keyboard input. When doing keyboard input the keyboard events are lined up, and the key doesn't display until the sound has finished. When presssing 1 to 9 in a row, they appear one by one after a plop. Sometimes the same number appears more than once, when 2 plops appear in-between serving the keyboard queue.



Lutz
Title:
Post by: newdep on October 01, 2007, 10:03:34 AM
Yes could very well be a platform issue.. But i would expect Java to take

control of this..like tuning speed and threads in its VM.. But then again we have

the GS in between where we have an IO queue.. On windows its also different..odd ;-)



On linux, while NOT pressing keys its not constant a 1 second beep.. its

very random.. like a hickup in between.. then some silence..etc.. but the key-event

is here synchrone..though not inline with the beep..



well I think i have to live with it ;-)





PS: Could it behaps be related to the disk-read of the sound file? and buffering

related to that action?
Title:
Post by: Lutz on October 01, 2007, 10:32:05 AM
In a later release gs:play-sound could be in an extra Java thread, so other events can be served during sound playing.



The choppiness (hickups) you are observing, is Java's carbage collection kicking in and absorbing cycles. For the time beeing the only thing you can do, is to make sounds as short as possible.



The IO queue will always be something, which has to be dealt with. Thats why real-world gaming software is interrupt driven. The moment you hit the button or move the stick, it gets served as a pirority.



Lutz
Title:
Post by: newdep on October 01, 2007, 11:21:46 AM
Aha..yes i thought so... another java thread would be very welcom but

i think the GS should not have too many java threads running, but GS cant get around that..;-)



Is there a more direct way to communicate towards Java? I could emagine

that IPC's or pipe's are much quicker then network events for example... Or perhpas direct API calls or the whole guiserver.lsp in JAVA itself? ;-)



For now the networking speed is fine the only problem is indeed the Sync

of processes and the speed handling when building game-like applications

with GS... widgets do great and small canvas tools too..but i thing the "worm.lsp"

almost is on its limits regarding interaction of events..



Aaa its still a joy ;-)



regards, Norman.