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

Author Topic: Candidate for new official DSFML  (Read 4952 times)

0 Members and 1 Guest are viewing this topic.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Candidate for new official DSFML
« on: March 25, 2013, 05:16:35 pm »
Hey all!

A while back I became very interested in the D programming language and had already fallen in love with SFML, but when I looked into it there didn't seem to be much support. Unfortunately, deadalnix's repo for a DSFML seems to not have had much work done on it in about a year and I think we deserve a good D binding. I wrote this(https://github.com/Jebbs/DSFML) from scratch, and I think I did a pretty good job of making it work well and as if it was an actual D API. There are definitely some parts that could use improvement, but I plan on doing active development to make sure everything is up to date and that the binding continues to improve overall! Hopefully I didn't jump the gun on giving it the name DSFML!

It's very similar to krzat's binding in a lot of ways, so if you were able to get his working then the same process will apply to mine for the most part. Things my binding feature are lot's of code compatibility with the C++ API, overloaded operators for many things, and a general avoidance of pointers in favor of built in D types. I also wrote some code to make Drawable inheritance possible and only have the need to write the draw code once and still it work with a RenderTexture and a RenderWindow. More cool updates/improvements to follow!

In any case, let me know what you guys think! This is my first project I have ever had done that other people would use. The very next things I want to work on for the binding are getting it up to date and then writing some tutorials, which I will do soon, but I wanted to finally release something for others to see!
DSFML - SFML for the D Programming Language.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6157
  • Thor Developer
    • View Profile
    • Bromeon
Re: Candidate for new official DSFML
« Reply #1 on: March 25, 2013, 08:07:47 pm »
Cool that you take the effort to write a D binding! Have you considered working together with other people that port SFML to the D language? If you have a similar philosophy, you might achieve more. On the other hand, it is more difficult to have a single code style.

Why don't you divide the classes to separate files? Especially if you plan to provide more than a plain wrapper, things get a real mess if you have only one file per module.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #2 on: March 26, 2013, 12:36:46 am »
I wanted to work with other people before I first started the project, and even had started a thread about it, but not a lot of people were active in the D section and it didn't go anywhere so I started writing one myself. It wasn't until I had a good chunk done that other people started posting stuff. I considered helping krzat, but he posted once and was done, so I kept working on my own binding. I really don't mind working on it by myself though, mostly because once I improve it and get everything fully functioning the way I want it I plan putting the project in my portfolio to help get me into a certain program at a university.

As for the way the modules are set up , I see what you are saying. I actually had it that way originally, but I have encountered reasons in which it makes more sense for it to be all in one file rather than in separate ones. Plus, I have some plans that will reduce the number of lines of code and make things look quite a bit cleaner.
DSFML - SFML for the D Programming Language.

esquinn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Candidate for new official DSFML
« Reply #3 on: March 26, 2013, 12:18:23 pm »
This might be a newbie mistake, but I'm trying to futz around with your code, but I haven't even quite gotten to the point of calling any of your functions. I've tried the latest DMD for both D1 and D2, and both of them error out with this snippet.

module main;

import dsfml.window;
import dsfml.audio;
import dsfml.graphics;
import dsfml.network;
import dsfml.system;

import std.stdio;


int main (string[] args)
{
        writefln ("Hi! I'm a bug.");
        return 0;
}
 

I'm running dmd -run test.d

d1 gives this string of errors:

dsfml\window.d(106): Error: Declaration expected, not '('
dsfml\window.d(112): Error: Declaration expected, not 'TOK216'
dsfml\window.d(117): Error: unrecognized declaration
dsfml\audio.d(26): Error: Declaration expected, not 'TOK216'
dsfml\audio.d(37): Error: unrecognized declaration
dsfml\graphics.d(65): Error: semicolon expected following function declaration
dsfml\graphics.d(67): Error: Declaration expected, not 'return'
dsfml\graphics.d(71): Error: Declaration expected, not 'TOK216'
dsfml\graphics.d(81): Error: unrecognized declaration
dsfml\network.d(130): Error: found '!' when expecting ';' following statement
dsfml\network.d(161): Error: Declaration expected, not '('
dsfml\network.d(175): Error: basic type expected, not const
dsfml\network.d(175): Error: default argument expected for int
dsfml\network.d(175): Error: found 'const' when expecting ')'
dsfml\network.d(175): Error: semicolon expected following function declaration
dsfml\network.d(175): Error: Declaration expected, not '('
dsfml\network.d(178): Error: no identifier for declarator Message
dsfml\network.d(178): Error: semicolon expected to close declaration, not '!'
dsfml\network.d(178): Error: Declaration expected, not '!'
dsfml\network.d(251): Error: unrecognized declaration
dsfml\system.d(44): Error: semicolon expected following function declaration
 


Compiling with D2, on the other hand, gets me this:

dsfml\window.d(70): Error: ContextSettings(0u, 0u, 0u, 2u, 0u) is not an lvalue
dsfml\window.d(76): Error: ContextSettings(0u, 0u, 0u, 2u, 0u) is not an lvalue
dsfml\graphics.d(1006): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1008): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1101): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1100): Deprecation: overriding base class function without using override attribute is deprecated (dsfml.graphics.RenderTexture.draw overrides dsfml.graphics.RenderTarget.draw)
dsfml\graphics.d(1107): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1106): Deprecation: overriding base class function without using override attribute is deprecated (dsfml.graphics.RenderTexture.draw overrides dsfml.graphics.RenderTarget.draw)
dsfml\graphics.d(1136): Error: ContextSettings(0u, 0u, 0u, 2u, 0u) is not an lvalue
dsfml\graphics.d(1142): Error: ContextSettings(0u, 0u, 0u, 2u, 0u) is not an lvalue
dsfml\graphics.d(1238): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1237): Deprecation: overriding base class function without using override attribute is deprecated (dsfml.graphics.RenderWindow.draw overrides dsfml.graphics.RenderTarget.draw)
dsfml\graphics.d(1243): Error: RenderStates(cast(BlendMode)0, Transform(sfTransform([1F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 1F])), null, null, sfRenderStates(cast(BlendMode)0, sfTransform([nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF, nanF]), null, null)) is not an lvalue
dsfml\graphics.d(1242): Deprecation: overriding base class function without using override attribute is deprecated (dsfml.graphics.RenderWindow.draw overrides dsfml.graphics.RenderTarget.draw)
 


Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #4 on: March 26, 2013, 03:58:17 pm »
To be honest, I'm not even sure what you could be doing wrong. Just to test, I pulled the source from the git, compiled it with the code you posted, and it worked fine. The only reason I can see it throwing errors like that would be if lines of code were missing :/ Maybe you could try downloading the source files again?

And I don't think it will work for D1, but that isn't being updated anymore anyways so I had my focus on D2.


Edit:
Is there anyway you could send me your project stuff as well as any build scripts if you use them?
DSFML - SFML for the D Programming Language.

esquinn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Candidate for new official DSFML
« Reply #5 on: March 26, 2013, 05:22:32 pm »
Here's the "project" as such--At the moment, I'm compiling entirely on the command line. I have that in my Documents\projects\dsfmltest folder, cd into it with the command prompt, and manually run "dmd test.d".

https://dl.dropbox.com/u/187059/dsfmltest.zip

If it helps, I'm running on windows 7 x64, though to the best of my knowledge, my entire build chain is 32-bit. My DMD reads version 2.062

esquinn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Candidate for new official DSFML
« Reply #6 on: March 26, 2013, 06:18:19 pm »
Okay, I'm not actually all that familiar with the deeper intracacies of D, and  this might be some really bad hackery and might even segfault once I start actually calling DSFML code, but...

The compiler seems to be having difficulty with the format "ref StructName argument = StructName ()"



sooooo, playing with window.d, I put this at the top of the module:

const ContextSettings DefaultContextSettings = ContextSettings ();


then changed every instance of "ref ContextSettings settings = ContextSettings ()" to "ref ContextSettings settings = DefaultContextSettings"

for DefaultRenderstates, however, I had to leave the 'const' out of the declaration up top. I hope *that* doesn't bode ill.

and it compiles.
« Last Edit: March 26, 2013, 06:23:05 pm by esquinn »

esquinn

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Candidate for new official DSFML
« Reply #7 on: March 26, 2013, 07:11:01 pm »
Alrighty. Did a quick best-as-possible conversion of the SFML wiki's little sample program, and I've got something that not only compiles, but runs.

Caveats: You've got a typo in your Font class--the loadFromFile () method is listed as lodFromFile.

And you don't seem to have the openFromFile methods implemented for your Audio classes

But, with that said and done, this compiled and ran on my end, with the modifications I made.

module main;

import dsfml.window;
import dsfml.audio;
import dsfml.graphics;
import dsfml.network;
import dsfml.system;

import std.stdio;

int main (string[] args)
{
        auto window = new dsfml.graphics.RenderWindow (dsfml.graphics.VideoMode (800,600), "SFML window");

        auto texture = new dsfml.graphics.Texture ();
       
        writefln ("phase!");

        if (!texture.loadFromFile("cute_image.jpg"))
                return 1;
        writefln ("phase!");

        auto sprite = new dsfml.graphics.Sprite (texture);

        writefln ("phase!");

        auto font = new dsfml.graphics.Font();
        if (!font.loadFromFile("arial.ttf"))
                return 1;

        writefln ("phase!");

        auto text = new dsfml.graphics.Text ("Hello SFML", font, 50);

        writefln ("phase!");

        auto music = new dsfml.audio.Music ("nice_music.ogg");

        writefln ("phase!");

/*      if (!music.openFromFile("nice_music.ogg"))
                return 1;*/


        music.play ();

        while (window.isOpen())
        {
                dsfml.window.Event event;

                while (window.pollEvent (event))
                {
                        if (event.type == dsfml.window.Event.Closed)
                                window.close();
                }

                window.clear (dsfml.graphics.Color.Black);
                window.draw (sprite);
                window.draw (text);
                window.display ();
        }


        writefln ("Hi! I'm not a bug.");

        return 0;
}
 

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #8 on: March 26, 2013, 08:03:43 pm »
I'm glad you got it working! I never played much with the the command line  so it took me a few minutes and you had already posted before I had a chance to reply!

Thanks for the info on the other stuff.  I'll fix the typo shortly! As for the audio stuff, I used to have everything initialized in the constructors instead of having load from methods. I decided it was better to be consistent with SFML so I added them in, but it appears I missed the audio module. I'll fix that too!

Feel free to let me know if you find anything else. I also built the most up to date CSFML libs last night so I will update everything soon as well.
DSFML - SFML for the D Programming Language.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #9 on: March 26, 2013, 09:52:11 pm »
All of the issues you described have been fixed in the repo! Thanks again for finding those!

Also, I just wanted to mention a couple of things. The modules are set up to auto-import any other modules they depend upon. So just like in SFML, importing dsfml.window will auto-import dsfml.system, dsfml.graphics will auto-import dsfml.window which auto-imports dsfml.system, etc.

Your import section for using everything you can just be:
import dsfml.audio;
import dsfml.graphics;
import dsfml.network;

Secondly, you don't need to include the type location when referring to things. For example:

auto window = new dsfml.graphics.RenderWindow (dsfml.graphics.VideoMode (800,600), "SFML window");

can be rewritten as

auto window = new RenderWindow (VideoMode (800,600), "SFML window");

Hopefully that makes thing a little better for you!

DSFML - SFML for the D Programming Language.

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
Re: Candidate for new official DSFML
« Reply #10 on: April 13, 2013, 05:55:25 am »
Looks great! It's good to have someone working on this again.

It really fits into the D style, yet remains faithful to the C++ API, which is great to see.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #11 on: April 30, 2013, 07:42:47 am »
Thanks for the kind words!


I figured I'd also give a little bit of an update since I just uploaded some code: The binding is about as complete as I am willing to make it while still being based off of CSFML.

There's a lot of stuff I still want to do to improve things though, and so I have started rewriting the C interface this binding is based off of. This will eliminate the need for a lot of the CSFML intermediate types as well as give me better control over how the D code interacts with the C code. Plus the libraries will be named DSFML instead of CSFML, which is pretty sweet. :P

It'll be a while before any of these major changes happen, so for now enjoy the binding as is. I'll still be maintaining this version until the new version get's up off the ground.  I'll also be active on this board, so feel free to ask any questions here!
DSFML - SFML for the D Programming Language.

con

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Candidate for new official DSFML
« Reply #12 on: June 05, 2013, 03:55:04 am »
Hello there.

Nice wrapper, I think that this project rocks.

How do you compile this example application?

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Candidate for new official DSFML
« Reply #13 on: June 05, 2013, 05:37:54 am »
Thanks for the kind words!


How do you compile this example application?


Which example application? I'd be more than happy to help though.
DSFML - SFML for the D Programming Language.

con

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Candidate for new official DSFML
« Reply #14 on: June 05, 2013, 02:01:27 pm »
This example made by esquinn.

The only thing that bothers me is the syntax of the command line.
dmd ...

Thanks for the help.


 

anything