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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tienery

Pages: [1]
1
General / Re: Converting from VertexArray& to const Vertex*
« on: March 05, 2016, 01:14:12 pm »
The binding is complete now, but thanks anyway :)

2
Audio / Re: SoundRecorder::getAvailableDevices() only prints "true"
« on: February 23, 2016, 10:26:42 pm »
Okay, yeah, I have done so but have been getting different results than before. Instead of three "true"'s I get nothing:

std::vector<std::string> values = sf::SoundRecorder::getAvailableDevices();
std::cout << values.size();
 

Result:


3
Audio / SoundRecorder::getAvailableDevices() only prints "true"
« on: February 23, 2016, 08:51:39 pm »
Using the sf::SoundRecorder::getAvailableDevices() seems to be only printing "true" in the output:



The implementation is in C++, because Haxe does not handle std::vector's that well, but whether this is a bug in the core or just simply my implementation I'm unsure. The below code is the C++ implementation by extracting the results of the getAvailableDevices() function and adding each element into a native Haxe Array. I would not have thought this would affect the output of the results, but "true" is all I'm getting, which seems rather unusual.

Calling getDefaultDevice(), however, does get the result you expect.

    Array< ::String > SoundHelper::getAvailableDevices()
    {
        std::vector<std::string> devices = sf::SoundRecorder::getAvailableDevices();
        Array< ::String > values = Array_obj< ::String >::__new();
       
        for (int i = 0; i < devices.size(); i++)
        {
            const char* n_v = devices[i].c_str();
            String v = n_v;
            values->push(v);
        }
       
        return values;
    }

4
General / Converting from VertexArray& to const Vertex*
« on: February 21, 2016, 04:51:18 am »
I'm trying to figure out how one would convert VertexArray to const Vertex* so that the binding in my latest commit is correct.

Because the draw function in sf::Window has the const Vertex* signature as the first param, I need to match that param so that the compiler can match the signature when resolving. Unfortunately, I can't just pass in a standard VertexArray type because the Haxe compiler complains that the types mismatch. Obviously this is nothing to do with C++.

I have an extern that identifies the type needed to match the signature:

Code: [Select]
@:include("SFML/Graphics.hpp")
@:native("const sf::Vertex *")
extern class ConstVertexArray { }

But I need a way to convert the standard extern over to this one. The standard extern looks like this:

Code: [Select]
@:include("SFML/Graphics.hpp")
@:structAccess
@:native("sf::VertexArray&")
extern class VertexArray implements Drawable {
...

Any help would be greatly appreciated.

5
General / Haxe Binding for SFML
« on: February 20, 2016, 03:21:04 pm »
Hello, everyone!

I am writing a binding for SFML in the Haxe programming language, for anyone who is interested.

You can take a look here. The binding part of the library is complete. I will move onto completing the wrapper portion, which will allow you to use Haxe more naturally. The following is a list of things implemented into the binding:

  • Windows and RenderWindow's
  • Shapes: Circles, Convex and Rectangles
  • Text: Font, Font Info and drawing text
  • Sprites, Images, Textures and RenderTextures
  • Events: Mouse, Keyboard, Text and more.
  • Shaders (Untested)
  • Audio, music and sound (Untested)

Things that have not been implemented, such as networking, do not exist because the Haxe Standard Library provides the utilities to do these things, including creating input/output streams. Some functions may appear missing, such as loadFromMemory functions within their respective places, simply because of my lack of understanding for implementing void * signatures in Haxe. Apparently, it's easy, but extra care has to be taken when implementing this kind of functionality, something I am not confident in risking yet.

If, however, you believe you can implement it, you can make a pull request on Github.

You can use the OpenGL context with the use of linc_opengl. I have just recently added the functions into RenderTarget in the binding to allow you to mix OpenGL calls with SFML ones.

If you have any problems, you can post an issue on Github.

Thank you for your interest.

6
General / Re: Polling events in Haxe wrapper does not get detected
« on: February 18, 2016, 06:41:59 pm »
Okay, nevermind. Adding an ampersand in front of the binding to `sf::Event` generated the correct C++ code for it to work. So don't need help after all ;)

7
General / Polling events in Haxe wrapper does not get detected
« on: February 18, 2016, 06:18:42 pm »
Hello, everyone! I'm new here so let me introduce myself.

My name is tienery, and I am a contributor to many Haxe projects, and currently I have embarked on making my own wrapper for SFML in the Haxe programming language. Now, before I go forward into explaining my problem, I am no expert with either C++ or Haxe, of course the reason I am here is to learn new things and to resolve my mistakes.

So now I shall talk about the issue I am currently having in Haxe. Because Haxe does not know how to resolve a native C++ enum in its own language, I need to do a comparison with events some other way. One of those ways were to create another C++ file that has some "helper" functions to deal with the abstraction between the `EventType` enum type in SFML, and returning an integer that identifies what event type it was.

Here is the full code of this helper class:

#include "SFML/Window.hpp"

namespace hx {
   
    namespace sfml {
       
        class Event {
            public:
                static sf::Event createEvent();
                static int getEventType(sf::Event &event);
               
        };
       
        sf::Event Event::createEvent()
        {
            sf::Event event;
            return event;
        }
       
        int Event::getEventType(sf::Event &event)
        {
            if (event.type == sf::Event::Closed)
                return 1;
            else if (event.type == sf::Event::Resized)
                return 2;
            else
                return 0;
        }
       
    } //sfml
   
} //hx
 

I then make an extern for this helper class so that I can use it in the context of Haxe:

Code: [Select]
package window;

import cpp.Int32;
import sfml.window.Event in SFMLEvent;

@:include("hx/sfml/Event.cpp")
extern class EventHelper {
    @:native("hx::sfml::Event::createEvent") public static function createEvent():SFMLEvent;
    @:native("hx::sfml::Event::getEventType") public static function getEventType(event:SFMLEvent):Int32;
}

So the idea is to create an event by declaring it and returning the variable to the context of Haxe, so that we can use that variable to pollEvents in a window and get its type.

So the final test code is the following:

Code: [Select]
package;

import sfml.window.*;
import window.EventHelper;

@:buildXml('<include name="${haxelib:hxsfml}/../Build.xml" />')
class Main
{
   
    public static function main()
    {
        var window:Window = Window.create(VideoMode.create(800, 600), "Test 01 - Blank Window");
       
        while (window.isOpen())
        {
            var event = EventHelper.createEvent();
            while (window.pollEvent(event))
            {
                if (EventHelper.getEventType(event) == 1) {
                    window.close();
                }
            }
           
            window.display();
        }
       
        return 0;
    }
   
}

For the full code, I have a public repository on Github with the externs and wrappers. If you wish to test the code, you will need to download Haxe and a library called hxcpp using the command:
Code: [Select]
haxelib install hxcpp
So what's the problem? The comparison doesn't work.

Where the if statement checks to identify what the event is, the window does not close. I even traced it in another example and it never returned 1, ultimately resulting in the window closing as it should.

Image result:



I just don't know how to resolve what is otherwise a very simple concept.

Any help would be greatly appreciated.

Pages: [1]