Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Java  (Read 24334 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Java
« on: May 21, 2009, 01:25:09 pm »
One question :

Is there a real probability that someone writes a java-wrapper for sfml??

i really like sfml but much of my code is java and i dont like java2d

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Java
« Reply #1 on: May 21, 2009, 07:20:56 pm »
I won't do it myself, and so far I've never seen someone interested to write such a binding. Why don't you do it? :)
Laurent Gomila - SFML developer

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
Java
« Reply #2 on: November 17, 2009, 01:58:56 pm »
Quote from: "Laurent"
I won't do it myself, and so far I've never seen someone interested to write such a binding. Why don't you do it? :)

Hi. I am interested in writing such a binding. In fact I started it few days ago. For this I am using JNI. I am right now under heavy deadline at work, so development moves slow. Implemented things so far:
sf::Clock
sf::Randomizer
sf::Vector2
sf::Style
sf::VideoMode
sf::Window (90%)
sf::WindowSettings

Right now I am focused on implementing and wrapping Event and Window GetEvent method and all events in overall. I will release code when i will consider it working enough and have ported few examples of SFML applications. Window creation looks like that:
Code: [Select]
Window window = new Window(new VideoMode(800, 600, 32), "jSFML", Style.Close|Style.Titlebar, new WindowSettings() );
Constructor takes these arguments:
Code: [Select]
public Window(VideoMode, String, int, WindowSettings)

I will try to provide posts with weekly updates and changes in jSFML binding. Anyone even interested in using such a binding :?: Except me and ravenheart :].

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Java
« Reply #3 on: November 17, 2009, 03:54:51 pm »
Maybe you should wait for SFML2 (or already start working on it from SVN), a lot of things have/will change.
Laurent Gomila - SFML developer

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
Java
« Reply #4 on: November 17, 2009, 04:08:50 pm »
Quote from: "Laurent"
Maybe you should wait for SFML2 (or already start working on it from SVN), a lot of things have/will change.

Ok. Thats good idea. SFML2 code is available at http://sfml.svn.sourceforge.net/viewvc/sfml/ ? I cannot checkout this repository, I'm getting message "Error: Repository moved temporarily to '/viewvc/sfml/'; please relocate". I don't get it what I'm doing wrong? I'm using windows TortoiseSVN.

JannoT

  • Guest
Java
« Reply #5 on: November 17, 2009, 04:40:44 pm »
Quote from: "solgar"
Quote from: "Laurent"
Maybe you should wait for SFML2 (or already start working on it from SVN), a lot of things have/will change.

Ok. Thats good idea. SFML2 code is available at http://sfml.svn.sourceforge.net/viewvc/sfml/ ? I cannot checkout this repository, I'm getting message "Error: Repository moved temporarily to '/viewvc/sfml/'; please relocate". I don't get it what I'm doing wrong? I'm using windows TortoiseSVN.

https://sfml.svn.sf.net/svnroot/sfml
and SFML2 branch:
https://sfml.svn.sf.net/svnroot/sfml/branches/sfml2/

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
Java
« Reply #6 on: November 17, 2009, 04:54:35 pm »
Quote from: "JannoT"
https://sfml.svn.sf.net/svnroot/sfml
and SFML2 branch:
https://sfml.svn.sf.net/svnroot/sfml/branches/sfml2/


Thanks. I didnt got it that url on download page was for browser and not for svn client.

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
Java
« Reply #7 on: November 26, 2009, 01:06:59 am »
Weekly changes report:
- sf::Window is fully implemented (all events implemented)
- sf::Drawable implemented
- sf::Shape implemented
- sf::RenderWindow in progress (40%)

In next few days I will finish work on sf::RenderWindow and I will start working on sf::Image and sf::Sprite classes.

Sample code:
Code: [Select]
import SFML.System.*;
import SFML.Window.*;
import SFML.Graphics.*;

public class jSFML
{

    static
    {
        System.loadLibrary("jSFML");
    }

    public static void main(String[] args)
    {
        RenderWindow wnd = new RenderWindow(new VideoMode(800, 600), "jSFML", Style.Close|Style.Resize|Style.Titlebar, new ContextSettings());
        Shape shape = Shape.CreateCircle(new Vector2f(400, 300), 250, new Color(255,0,0), 8, new Color(0, 255, 0));
        Color background = new Color(0, 0, 0);
        while(wnd.isOpened())
        {
            Event event = new Event();
            while(wnd.getEvent(event))
            {
                if( (event.type == EventType.KeyPressed && event.key.code == KeyCode.Escape) || (event.type == EventType.Closed) )
                    wnd.close();
                else if (event.type == EventType.KeyPressed && event.key.code == KeyCode.Space)
                    System.out.println("fps: " + 1/wnd.getFrameTime());
            }
            if( wnd.getInput().isKeyDown(KeyCode.Return) )
            {
                background.r = Randomizer.randomI(0, 255);
                background.g = Randomizer.randomI(0, 255);
                background.b = Randomizer.randomI(0, 255);
            }
            wnd.clear(background);
            wnd.draw(shape);
            wnd.display();
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Java
« Reply #8 on: November 26, 2009, 08:25:18 am »
Awesome :)

I have two small questions:

1. Why did you renamed Shape::Circle to Shape.CreateCircle? If it's not for a technical reason, I think you should keep the C++ API's names in order not to confuse people (don't forget that the only documentation available is the C++ one).

2. I don't know how events are usually handled in Java, but if there's a "standard" way of doing it, do not hesitate to use it. For example, this is how SFML.Net handles events:
Code: [Select]
window.Closed     += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

Same for anything else that might have a more standard syntax than in the C++ API.

By the way, did you have any issue with the GC? In SFML.Net, the graphics objects are destroyed in the GC thread, after the main thread has ended; I had to write a workaround to make it work properly.
Laurent Gomila - SFML developer

solgar

  • Newbie
  • *
  • Posts: 36
    • View Profile
Java
« Reply #9 on: November 26, 2009, 01:04:16 pm »
Quote from: "Laurent"
1. Why did you renamed Shape::Circle to Shape.CreateCircle? If it's not for a technical reason, I think you should keep the C++ API's names in order not to confuse people (don't forget that the only documentation available is the C++ one).

I think that "Create" prefix is handy. If you type "Shape.C" and press ctrl+space you will see list of all predefined shapes and I am thinking of adding few additional shapes like pentagon, hexagon and octagon.

Quote from: "Laurent"
2. I don't know how events are usually handled in Java, but if there's a "standard" way of doing it, do not hesitate to use it. For example, this is how SFML.Net handles events:
Code: [Select]
window.Closed     += new EventHandler(OnClosed);
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
window.Resized    += new EventHandler<SizeEventArgs>(OnResized);

Same for anything else that might have a more standard syntax than in the C++ API.

I do not know C# and have no idea what this code supposed to do and where it supposed to be used. My goal is to have syntax as much similar to C++ as it can be. Only method names (except static ones) and variable names will have small first letter.

Quote from: "Laurent"
By the way, did you have any issue with the GC? In SFML.Net, the graphics objects are destroyed in the GC thread, after the main thread has ended; I had to write a workaround to make it work properly.

I don't have any issue with GC at this moment. Why this GC thread is issue? Does this really matter when those objects are destroyed? If it does please tell me why.

// edit
About documentation. I have in plans to write Javadoc for jSFML so everything will be documented.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Java
« Reply #10 on: November 26, 2009, 02:05:48 pm »
Quote
I think that "Create" prefix is handy. If you type "Shape.C" and press ctrl+space you will see list of all predefined shapes and I am thinking of adding few additional shapes like pentagon, hexagon and octagon.

My advice would be to stick to the original API regarding functions names. But you're the boss ;)

Quote
I do not know C# and have no idea what this code supposed to do and where it supposed to be used. My goal is to have syntax as much similar to C++ as it can be. Only method names (except static ones) and variable names will have small first letter.

This code binds functions to events, so that they are automatically called whenever a SFML event is triggered. This is the standard way of handling events in C# (the concept of events is well defined in the language, and there's native support for it). Maybe there's no native or standard way of handling events in Java, I don't know; it was just a general comment to tell you that if a language has native or standard support for a concept, it's better to use it rather than sticking with the C++ API.

Quote
I don't have any issue with GC at this moment. Why this GC thread is issue? Does this really matter when those objects are destroyed? If it does please tell me why.

OpenGL is very picky about how and when things are done when multiple threads are invovlved. In particular, you must always have a valid context activated on a thread if you're calling an OpenGL function, and a context can be active only in one thread at a time. Thus, when things happen in the GC thread, there's no OpenGL context available and OpenGL functions can't be called. But if there's nothing wrong with your binding when you exit a graphics application, then it's fine, don't worry about that.

Quote
About documentation. I have in plans to write Javadoc for jSFML so everything will be documented.

Great :)
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Java
« Reply #11 on: November 27, 2009, 02:45:52 pm »
Quote from: "Laurent"
1. Why did you renamed Shape::Circle to Shape.CreateCircle? If it's not for a technical reason, I think you should keep the C++ API's names in order not to confuse people (don't forget that the only documentation available is the C++ one).
I also think that names should remain consistent where possible in order to reduce confusion.

But there comes up the question why the factory method Circle() in C++ isn't called CreateCircle()? Here were some people being confused because they didn't know that Circle() is a static function; in my opinion, "Create" would clarify the construction of a new, independent object. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Java
« Reply #12 on: November 27, 2009, 03:03:50 pm »
I don't know, it sounds more intuitive to me. It looks more like a constructor than a regular function.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Java
« Reply #13 on: November 27, 2009, 03:16:00 pm »
Quote from: "Nexus"
Here were some people being confused because they didn't know that Circle() is a static function
As you have to write :: …

Quote from: "Laurent"
I don't know, it sounds more intuitive to me. It looks more like a constructor than a regular function.
I agree with you.
SFML / OS X developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Java
« Reply #14 on: November 27, 2009, 03:50:08 pm »
Quote from: "Laurent"
I don't know, it sounds more intuitive to me. It looks more like a constructor than a regular function.
Okay, I can reconstruct this. Probably a matter of taste... :)

Quote from: "Hiura"
As you have to write :: …
You don't have to. You may invoke static methods with the syntax a of non-static member function call.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything