[Plugin] [ALPHA] Project Shoebill - Java for SA:MP Development Kit - Milestone 1 (20110701)
#1

Has moved to: https://sampforum.blast.hk/showthread.php?tid=397735
Reply
#2

Preparation for Shoebill development (ex. Eclipse)

1. Eclipse -> File -> New -> Java Project -> Enter your project name -> Finish.
2. Right click at the new project -> new -> Choose "Folder" -> enter "lib" -> Finish.
3. Copy the Shoebill.JAR into the new "lib" folder in your project.
4. Right click at the project -> Properties -> Java Build Path -> Libraries -> Add JARS -> find lib/Shoebill.JAR
5. Create your own GameMode class, and extend net.gtaun.samp.GameModeBase.
6. Finished! Now you can program your own code.

*How To export your gamemode to JAR?
Just right click at your project -> export -> JAR File -> assign where to save your .jar


Preparation for Shoebill execution

1. Prepare samp_server folder, include samp_server.exe
2. Copy Shoebill.AMX & Shoebill.JAR into "gamemodes". Copy Shoebill.DLL into "plugins"
3. Copy your own gamemode.jar(ex. LVDM.JAR) into "gamemodes"
4. Prepare server.CFG. Modify gamemode0 to "gamemode0 Shoebill 1", and plugins to "plugins Shoebill", and delete the filterscripts line.
5. Add a new line into server.CFG, that would be "modeclass [your GameMode class name]" (ex. "modeclass com.samp.lvdm.GameMode")
6. Prepare your scriptfiles for GameMode
7. Now you can try to execute the samp-server.exe


Example GameMode: LVDM

Download: LVDM(Java).zip
(Updated in 02/07/2011)

*Convertd by JoJLlmAn, all copyright belongs to Jax and SA-MP TEAM.


That's it!, enjoy using it.
Greetings to all Java lovers.
Reply
#3

One of the best ideas I have seen so far.
Have you tested the speed yet? I guess java will be slightly slower, but OO is a great feature that could compensate it, nice to see it already works.
Reply
#4

A suggestion on optimization, initialize all amx_FindFunction(***) pointers in initialization and CACHE them so they aren't always looked up on each native calls, but are known in advance.
Reply
#5

Awesome work, I was initially developing a Java-based gamemode that would communicate with the native server using my plugin. This cuts out the middle man, good luck!
Reply
#6

This is very nice! Still kinda bummed about the Linux thing though ;-;.
Reply
#7

This sounds pretty epic. But it kinda sucks that it won't be compatible with Linux.
Reply
#8

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
One of the best ideas I have seen so far.
Have you tested the speed yet? I guess java will be slightly slower, but OO is a great feature that could compensate it, nice to see it already works.
I second that, nice work.
Reply
#9

Hard...i will try but i am 100% sure that i can't use it.
Reply
#10

Quote:
Originally Posted by JernejL
Посмотреть сообщение
A suggestion on optimization, initialize all amx_FindFunction(***) pointers in initialization and CACHE them so they aren't always looked up on each native calls, but are known in advance.
I think they've already been cached in initialization, they're static, will only be assigned once.


Quote:
Originally Posted by ******
Посмотреть сообщение
is that really the only way to set a vehicles numberplate on spawn!?
Not really, you can just add listener into vehicle.eventSpawn
or player.vehicle().setNxxxx... in GameMode class.
or....well, depends on you.
And LVDM is just an example btw...

I just tend to do more in LVDM, you know.
There's only two class when I done the conversion....
but seems like it's a little bit superfluous =)


Anyway, enjoy using it.
Reply
#11

Started learning Java some days ago..
Great work.
Reply
#12

Great work! mk
Reply
#13

This is very nice. I am definitely hoping to see future releases and improvements.
Reply
#14

What about the Java memory leaks and the common ram spikes?
I assume the Java runs on the server which innitially shouldn't pose a problem, since they are super computers.
If not, please read the following:

Java is known for it's object orientated programming and easy DOM functions.
But there is a huge fail in Java. The system that makes it all easy often makes a mistake causing RAM memory to be taken massively. Now in small appplications this should be barely noticable.
However, considering the idea of writing gamemodes in java, I suppose this message should be said.

For those who know the game Minecraft, they might experienced this issue many times.
Minecraft, a file of barely 200mb can take up to 1,5gb ram due these leaks. (In heavy use).
Now any sane mind knows this is happening because of the DOM functions that create the visual effects.
3D, explosions, damage, destroying blocks 'and computer intelligence'.

Now I assume javascript doesn't execute the visual effects but still the original game engine, so that wouldn't pose a problem.

Because java keeps running a leak can be very dangerous. Please, for your own regard and server computer safety, learn how to java properly before starting using this plugin.
This means you must be able to track down leaks and recognize them.

Try to avoid RAM taking functions, even if it increases the complexity of the codes.


=====
This is a great plugin. I'd rather use this than the PWN system that is in place now.
It adds a lot to understandability to objects ingame and adds a new dimension to newly started scripters.
I haven't seen the plugin its source, but I surely hope it is commented through.
Something like this is worth viewing!
Reply
#15

- English translation by JoJLlmAn.


Running System

CPU: Intel Pentium Dual T2370
OS: Windows 7
SA:MP: v0.3c R2
Java: JDK6 Update 24 (Java HotSpot Server VM)


Timing Code

Java:
Код:
long lastTick = System.nanoTime();
// Put the code you want to count time
long time = System.nanoTime() - lastTick;
		
System.out.println( "Java: " + time/1000/1000 + " ms." );
Pawn:
Код:
new lastTick = GetTickCount();
// Put the code you want to count time
new Time = GetTickCount() - lastTick;
	
printf( "Pawn: %d ms.", Time );
Performance of calling Native function

Java: 28ms.
Код:
for( int i=0; i<1000000; i++ ) this.allowAdminTeleport(true);
Pawn: 70ms.
Код:
for( new i=0; i<1000000; i++ ) AllowAdminTeleport(1);
Performance of calling Native function (with strings)

Java: 291ms.
Код:
for( int i=0; i<100000; i++ ) this.setGameModeText( "Shoebill" );
Pawn: 116ms.
Код:
for( new i=0; i<100000; i++ ) SetGameModeText( "Shoebill" );
Performance of calculating primes

Java: 77ms.
Код:
boolean isPrime( int num )
{
	int divisor = 3, limit = num;
	if( num%2 == 0 ) return false;
	
	while( limit > divisor )
	{
		if( num%divisor == 0 ) return false;
		limit = num / divisor;
		divisor += 2;
	}
	
	return true;
}

for( int i=0; i<100; i++ ) isPrime(2147483647);
Pawn: 590ms.
Код:
isPrime( num )
{
	new divisor = 3, limit = num;
	if( num%2 == 0 ) return 0;

	while( limit > divisor )
	{
		if( num%divisor == 0 ) return 0;
		limit = num / divisor;
		divisor += 2;
	}

	return 1;
}

for( new i = 0; i < 100; i++ ) isPrime(2147483647);
Summary

In performance of calling native, java is 2.5 times faster than pawn.
The other one with strings, pawn is 2.5 times faster*
In calculating primes, java is 7.5 times faster**

*for reference only, maybe the Windows codepage conversion(UTF16->MBCS) slows it. more complicated the string is, more difference between them.
**for reference only, depends on what algorithm you use.
Reply
#16

I wonder if this might just replace PAWN..;O
Reply
#17

If it is in good hands, I suppose that wouldn't be a bad idea.
However, The Sa-MP already declared that they will NOT change pawn to any other language for whatever convenience. Off the record, yes it might replace pawn.
But considering the general crowd's coding qualities, I'd rather have a new category for advanced programmers and leave the script kiddies behind.

Question for the tester:
Can you do a RAM overflow test? How good does it handle creating hundreds of objects and destroying it afterwards? The amount of ram used for it + the time.
This is not a versus comparation I am asking for. If you don't feel like doing this test no-one will complaint. I am not doing the test either. However the information may be useful for the java programmers who passed the point of 'trial-and-error' in skills.

Thanks for doing this test.
Reply
#18

Quote:
Originally Posted by maij
Посмотреть сообщение
What about the Java memory leaks and the common ram spikes?
Thanks for the reply, I love the minecraft part, it did blow mine before.

But I have to say that MK considered this when shoebill project just started.
So he uses some weak reference stuff to avoid it. (ex. timer and dialog)
Others don't have to because of SA-MP, you have to destroy by yourself.

And java is different from javascript, there's no easy DOM stuff in java, I dont know what you're talking, exactly.

BTW in some object which has a destroy function, you have to call it by yourself, or it will be keep in the pool.
And yes, learn how to java properly, that can prevent from leak.

Thank you, for pointing it out

And enjoy using it.
Reply
#19

First of, I must credit you for your proper reaction. This how feedback should be.

Secondly, my bad about the easy DOM. For some reason I always confuse java with javascript, even though I use javascript all the time and did java in the past.
Thanks for pointing that out.

But it doesn't change the fact that you MUST be careful.
As you said, if you create an object, you need to destroy it otherwise it will float aloaf with no home to go back to.

Think of it as cats. if you manage them properly,they will die of age, otherwise they might end up running away and you don't know what happened to him. Most likely it is wandering the streets where to go to find food.
Meanwhile the world gets more crowded and crowded and if the cats don't die, the world is overflown with cats.
At a certain point cats can no longer live with the quantity of cats on the world, causing the ecosystem to collapse.

In other words, if you don't delete objects properly, your server will freeze or crash your computer at some point.

PS: Sorry for the cat-story, I felt like doing it.

Message to all the users of this plugin:
1. Debug your codes PROPERLY. No trial and error.
2. Prevent leaks, build up some skills. Not those 'I can code by copy-pasting' OR 'I claim for other's efforts' skills.
3. Always test using simulated data that exceeds normal uses.
4. Have fun using this plugin! This for once is a great plugin, or so far I know of.
Reply
#20

what about function overheads?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)