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.


Topics - FRex

Pages: 1 2 [3] 4 5
31
General discussions / github SFML organisation
« on: December 26, 2014, 04:33:02 am »
Is this github organisation of SFML official?
https://github.com/SFML
If yes - why is no one signed into it.

32
Feature requests / small & stupid api changes: radians, vectors, colors
« on: September 20, 2014, 12:12:19 am »
1.
setRadians and getRadians functions for angles in sf::Transformable. It would be backwards compatible, would not break the API, would let everyone use degrees OR radians, whichever they wish.
Yes, I know there is this thread, but it seems that it degraded into pointless argument about what is more 'friendly'...
http://en.sfml-dev.org/forums/index.php?topic=205.0
But yeah, sure - radians are less friendly and SFML is not hardcore-math-knowing-programmer's library. Only more reason for this change - it's very OK that 'default' unit is degrees and radians have to be explicitly present by name in functions that use them.
Yes, public API can do that but it's (literally) few lines of SFML code to save anyone working with radians from few lines of their own code, having to include the header with that code and then calling that single function differently than all other functions on all SFML transformables. It'll allow consistency in common user code. Radians are less common and friendly than angles but still common. This isn't as obscure and user specific as something like asking for allowing sin+cos for rotation would be.
It's a dumb change code wise, it won't break anything that now works with SFML and it'll make radians work out of the box.


2.
Small backwards compatible convenience change to sf::Vector2 constructor, instead of what we have now for casting from different SFML vector types (https://github.com/SFML/SFML/blob/master/include/SFML/System/Vector2.inl#L47) we could have this:
template <typename T>
template <typename U>
inline Vector2<T>::Vector2(const U& vector) :
x(static_cast<T>(vector.x)),
y(static_cast<T>(vector.y))
{
}
 
which just requires x and y fields in the class, not that it's SFML own class with another type, so vector from another library (say Box2D...) can be passed and work out of the box. This constructor is explicit anyway so it's pretty OK to do that IMO. It really makes sense that vector can be constructed out of something that has x and y in it (in particular - another vector with x and y in it).


3. Color should really have implicit constructor from sf::Uint32 (and possibly operator= too).
It's a bit annoying that I have to write that function myself and use it instead of just doing sf::Color(0xff0000ff) (or even passing number directly to function needing a color). Color and sf::Uint32 actually have same memory layout even, so you could memcpy from one to another so it's really funny there is no function to do that.
There is even implicit constructor from single UTF32 character to sf::String for convenience (which once bit someone in the ass) so why no that too?
HTML, GIMP, Ogre and probably many other use hex numbers like that already. Irrlicht has that kind of constructor so you can pass number to some of its' functions that need a color (some need float 0..1 colors, can't pass the number there).
It's really not at all obscure or unknown and it's really unlikely someone will pass a number instead of color accidentally and wonder what went wrong.

33
SFML projects / LuLDev aka Laurent Simulator 2014
« on: September 08, 2014, 01:33:15 am »
YES. I'm serious. This has to be the dumbest thing I ever wrote, at least it took little time.
The idea is totally stolen from: http://hackertyper.net/
You press any keys and it makes kernel code appear as if you are pro hacker.. ;D
I did the same for SFML code, using SFML itself. It's as if SFML is self-hosting itself. ;D I intended to use Network module to download source file you choose from github but ended up shipping them with the 'game' because I had problems doing that.

Here is the git repo:
https://github.com/FRex/LuLDev

There is just single .hpp and single .cpp, game also requires font file and the SFML directory which has most of .hpp and .cpp files of SFML for you to 'edit'.
I also added to repo a bash/find/sed script I used to make the list of relative paths and the usual - README and LICENSE.
The idea is same as in 'original' - you launch the program and type random keys to make source code of SFML appear. ;D
There are some options to pick font, file to 'edit', color of font, size of font, source code characters that appear per key press and size of window. All are described in kHelpString which gets printed if you launch with single '-h'.
There are also sane defaults for everything so just launching the program works.

34
SFML projects / WideVM for particles
« on: August 27, 2014, 02:54:26 am »
Based on general idea in this paper ( http://www.bitsquid.se/presentations/scripting-particles.pdf ) I've coded a VM that decodes a single instruction and then does it on a lot of data. No sse, avx or anything fancy and parallel though, just plain C++. It's few times slower (2-4x) than native C++ with O2 doing same operations (much slower with no O, since debug mode and simple optimizations give native a huge head start) which I'd say is pretty good for a VM that lazily coded in a day with no optimization in mind at all.

Here is the git repo, there is simple pixel particles example code in there too, just compile and link all .cpp provided:
https://github.com/FRex/WideVM

Opcodes function and their mnemonics can be read from opcodes header and source and op* functions in VM source.
If anyone is interested in actually using that for real or is interested about something in it or wants to constructively criticize it then please drop a post here.

35
Network / nitpicking in Packet.cpp
« on: August 05, 2014, 09:45:21 pm »
There are weird places, such as checking if sf::String length is more than 0 before iterating through it and adding characters (as if there is something to iterate through if length is 0) instead of just letting the iteration do 0 passes.
Taking size of std::string::value_type or char (which is always 1).
Sometimes (so not always, some functions do, some don't ie. <<std::string does, <<const char * doesn't) checking if length in bytes of data is 0 before passing it to append, while append ignores data of 0 length anyway.

36
Audio / OpenAL issues in SFML code
« on: August 03, 2014, 04:26:53 pm »
Using 1.1 spec from openal.org I've seen a couple discrepancies in the sf::SoundBuffer:
1. the samples vector is kept when it's not needed at all, this is uncompressed sound, it takes (relatively) a lot of space (compared to most things people do, like short strings, ints, sf::Textures which live on GPU memory not normal RAM etc.). This is not needed*:
Quote
void alBufferData (ALuint bufferName, ALenum format, const ALvoid *data, ALsizei size, ALsizei frequency);
The data specified is copied to an internal software, or if possible, hardware buffer.
and
Quote
The application is free to reuse the memory specified by the data pointer once the call to alBufferData returns. The implementation has to dereference, e.g. copy, the data during alBufferData execution.
*There is a 'use case'. Buffer can save to file, so it needs the samples for that, but that is like keeping sf::Image inside sf::Texture all the time instead of just creating one for loading. It's also probably not the most used feature so maybe it's not worth potentially doubling the memory used just for ease of saving the buffer back.

If that spec applies to OpenAL Soft (and it probably does..? it's a spec after all..) then this means there should be two classes, one that is OpenAL buffer, just like we have OpenGL texture and one that is software buffer just like there is software image, with same convenience function like texture has that will make a temporary software buffer, load it and then load from it to AL.
Right now, if you want to yourself edit the sounds in code, stitch, mix etc. them, you will load them into AL as well, which is a waste. And if you just want to play them in AL, you will keep them in memory, which is again a waste.


2. This is very minor - there is an if check in destructor to not call alDeleteBuffers on buffer that is 0, but that's not needed:
Quote
Deleting buffer name 0 is a legal NOP.

37
SFML projects / LuaConsole (command console for Lua, with completions)
« on: August 03, 2014, 12:17:51 am »
Lua Console

Code, instructions and minimal example here:
https://github.com/FRex/LuaConsole





I'm open to ideas and suggestions about features/API.
The console itself is independent of rendering and input, they are provided by additional classes (SFML implementation of both is of course in the repo and is used by the demo code in main.cpp).

38
SFML projects / WireGame [screens]
« on: June 17, 2014, 03:58:36 am »
These are screens of neat little thing I've been working on lately. It's a game that is based solely on making a circuit out of given chips connected by wires and then putting that chip to the test. There is nothing fancy, just a board where you build the circuit.
The core functionality is ready. All that is left is ux polishing, writing a lot of challenges and shipping.

(click to show/hide)

39
DotNet / Is Color equality right?
« on: May 25, 2014, 04:35:52 am »
This line looks very weird to me even though I don't really know C#:
https://github.com/SFML/SFML.Net/blob/master/src/Graphics/Color.cs#L81
Isn't it always true if obj is a color?
shouldn't it instead read one of these or similar?
return (obj is Color) && Equals(obj as Color);
return (obj is Color) && Equals((Color)obj);

40
General discussions / Complying with zlib license
« on: February 09, 2014, 05:38:00 pm »
This is mainly a Laurent question, since it's his property after all. :P
If I take code from SFML (but not copy verbatim a file, just a single method from somewhere) is it enough to put notice like that just above the method in .cpp file
//code below was taken from SFML Text.cpp and MODIFIED,
//it is NOT the original software, if looking for original software see:
//https://github.com/SFML/SFML/
followed by exact copy of zlib text that appeared in the file I took a method from?

So it goes like:
1. my code in my .cpp
2. that notice
3. SFML original (c) text
4. SFML code (modified or not)
5. end of file

I'd say I'm fulfilling all three: I don't misrepresent the origin, I plainly mark the (changed) copy as not the original and I don't remove or modify the original notice. (I feel a bit fishy about the last.)
Zlib lib/license FAQ doesn't really help, it talks more about what steps to take when releasing own fork of entire library. http://www.zlib.net/zlib_faq.html#faq24

41
Code:
https://github.com/FRex/HardLight

If you want to try it the easiest way would be to include the files in own project and link ClipperLib(see link in readme) and SFML yourself. There's also a class I used for debug drawing of polygons, circles, lines, segments, etc. included in repo. I have gcc (GCC) 4.8.2 20131212 (Red Hat 4.8.2-7), I have no idea if it'll work under VS 2012 and 2013, I know 2010 won't because of ranged for and earlier won't because of unique ptr and auto.

Based on first few posts in this thread: http://en.sfml-dev.org/forums/index.php?topic=14154.msg99291#msg99291 I decided one week ago to implement lightning system that'd do hard shadows, some post of mine there are about my ideas but most changed since, the result came out rather nice IMO. Well, I don't really know what to say : I might soon, after I do more work, post it on github under same license as SFML but there are still some features to add and things to check/clean up so I'm not doing that for now (also I need to relearn how to upload to github from git, and I need to delete my old master branch in which I had the polygons not lines  :-[).

Questions and opinions are very welcome.

Here are line counts, although more than half of is Box2D dynamic tree code that I ripped out(and that still needs cleaning, even after I spent an hour or two getting it self contained, less Cish and not tied to anything else in Box2D).
[frex@localhost shadows]$ cloc src/
      14 text files.
      14 unique files.                              
       0 files ignored.

http://cloc.sourceforge.net v 1.60  T=0.11 s (125.3 files/s, 25493.7 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C++                              7            335            105           1336
C/C++ Header                     7            277            154            641
-------------------------------------------------------------------------------
SUM:                            14            612            259           1977
-------------------------------------------------------------------------------
 

Here's a screen of bunch of white lights and shadow lines casting shadows + one red light under cursor that has pi/2 spread code set on it.


Here is the code that I used to that effect, as you can see it's quite intuitive what is going on.
BTW - the LightPainter is not tied in any way to ShadowWorld, you can retrieve the points of final light volume or individual shadows for each light and draw/use them any way you want. This is what LightPainter is doing, iterating over all QueriedLights and drawing with an optional shader using the calculated light volume.
#include <SFML/Graphics.hpp>
#include "ShadowWorld.hpp"
#include "LightPainter.hpp"

int main()
{
    sf::RenderWindow app(sf::VideoMode(640u, 480u), "lights");
    app.setFramerateLimit(60u);

    //prepare shadow world and set its view
    ee::ShadowWorld sw;
    sw.setViewRect(sf::FloatRect(0.f, 0.f, 640.f, 480.f));

    //prepare light painter and set internal texture size
    ee::LightPainter lp;
    lp.setSize(640u, 480u);
    lp.enableFragFromFile("light.frag");

    ee::Light * lit = sw.addLight(sf::Vector2f(0.f, 0.f), 100.f);
    lit->setColor(sf::Color::Red);
    lit->setSpread(ee::halfpi);

    bool adding = false;
    sf::Vector2f p1;

    while (app.isOpen())
    {
        sf::Event eve;
        while (app.pollEvent(eve))
        {
            switch (eve.type)
            {
                case sf::Event::Closed:
                    app.close();
                    break;
                case sf::Event::MouseMoved:
                    lit->setPosition(sf::Vector2f(eve.mouseMove.x, eve.mouseMove.y));
                    break;
                case sf::Event::MouseButtonPressed:
                    if (eve.mouseButton.button == sf::Mouse::Left)
                    {
                        adding = true;
                        p1 = sf::Vector2f(eve.mouseButton.x, eve.mouseButton.y);
                    }
                    else if (eve.mouseButton.button == sf::Mouse::Right)
                    {
                        sw.addLight(sf::Vector2f(eve.mouseButton.x, eve.mouseButton.y), 150.f);
                    }
                    break;
                case sf::Event::MouseButtonReleased:
                    if (eve.mouseButton.button == sf::Mouse::Left)
                    {
                        sw.addLine(p1, sf::Vector2f(eve.mouseButton.x, eve.mouseButton.y));
                        adding = false;
                    }
                    break;
            }//switch eve.type
        }//while pollEvent

        app.clear(sf::Color::White);

        //update shadow world and then render that
        sw.update();
        lp.render(sw);

        //multiply texture of painters render texture with scene
        app.draw(sf::Sprite(lp.getCanvas()), sf::BlendMultiply);

        //if space pressed draw all lines that participated in last update
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
        {
            for (unsigned i = 0u; i < sw.getQueriedLinesCount(); ++i)
            {
                sf::Vertex vert[2];
                vert[0].position = sw.getQueriedLine(i).a;
                vert[1].position = sw.getQueriedLine(i).b;
                app.draw(vert, 2u, sf::Lines);
            }
        }

        if (adding)
        {
            sf::Vertex vert[2];
            vert[0].position = p1;
            vert[1].position = sf::Vector2f(sf::Mouse::getPosition(app));
            vert[0].color = vert[1].color = sf::Color::Yellow;
            app.draw(vert, 2u, sf::Lines);
        }

        app.display();
    }//while app is open
}
 

42
Graphics / Text garbage after Font reload
« on: January 03, 2014, 03:16:57 am »
#include <SFML/Graphics.hpp>
#include <cstdlib>

void breakFont(sf::Font& f)
{
    for (int i = 0; i < 30; ++i)
    {
        char a = 'a' + std::rand() % ('z' - 'a' + 1); //random char from 'a'..'z'
        f.getGlyph(a, 30u, false);
    }
}

int main(int argc, char * argv[])
{
    std::srand(std::time(0x0));

    sf::RenderWindow app(sf::VideoMode(640u, 480u), "Font");
    app.setFramerateLimit(30u);
    bool broken = false;

    const std::string filename("OpenDyslexic-Regular.ttf");

    sf::Font font;
    font.loadFromFile(filename);

    sf::Text text("font is broken", font, 30u);

    while (app.isOpen())
    {
        sf::Event eve;
        while (app.pollEvent(eve))
        {

            if (eve.type == sf::Event::Closed) app.close();

            if (!broken && eve.type == sf::Event::KeyPressed)
            {
                broken = true;
                font.loadFromFile(filename);
                breakFont(font);
            }

        }

        app.clear();
        app.draw(text);
        app.display();
    }

}
 
Change filename to any font you want to use, it shouldn't matter, I used OpenDyslexic from http://opendyslexic.org/

Basically sf::Text displays garbage when sf::Font is reloaded and glyphs of same size get loaded in other order, if no glyphs get loaded it'll just display nothing, but is well defined, operator[] on map will insert new default constructed GlyphTable and return it's default constructed sf::Texture resulting in nothing.

It's a non issue for almost all sane use cases but I'm putting it out here with example so that it's known, I couldn't find it when I searched, if you want to ensure sf::Text is ok you can call text.setString(text.getString()) clear the string and set it again to force updateGeometry to be called (you can't call it directly, it's private).

43
SFML projects / LuaSFG/MoonSFG (WIP)
« on: November 30, 2013, 01:53:54 am »
Yes, SFGUI bound to Lua. ;)
It's not a full binding, it just binds widgets and allows for signals in Lua.
It doesn't allow defining styles but it lets you set class and id of widget so you can use a css file with it too.
It's more work in progress than SFGUI's docs. (So quite rough for now) :P

Here is the repo with everything tucked into /src/:
https://github.com/FRex/LuaSFG
This is where code is in /src/, grouped into files, not fully ready but ok-ish state already, this will be just the base c++ code, in separate files. Ideally there might be cmake/premake file, /include/ and /src/ directories and import/export macros in code but oh.. well.. use MoonSFG if you're desperate already..

Here is MoonSFG repo, with monolithic .hpp and .cpp:
https://github.com/FRex/MoonSFG
I just cat'd files together and removed some includes, it compiled but it's stupid and dirty as hell.. I'll have to make a script for generating this two in a saner way from LuaSFG.
This is also the repo that will (ideally) contain examples in both languages, the script used to build monolithic files, lua script to remove explicit casting(see thread and example lua code to see what I mean) and so on.


Monolithic hpp and cpp is what you'd download right now if you want to test it, you link your own Lua, you link your own SFML and you link your own SFGUI. Then add these two to your project and call ee::openLuaSFG(L); No linking, no Lua C/c++ issues, you provide all includes and link and it'll work.

There is example right now of guess my number on official SFG forum: http://sfgui.sfml-dev.de/forum/post1513.html#p1513

There might be bugs, crashes, leaks, errors, typos, things are missing, but it's mostly complete etc.

Strings are passed to/from Lua as ASCII, they'll be UTF-8 later.

The ee namespace is what I use for myself and I didn't plan to share until it got a bit long and just went with it so it might change to something like luasfg or LuaSFGUI or something.

44
Feature requests / Grabbing focus
« on: November 21, 2013, 10:36:43 pm »
Forcing the sf::Window to be the one that currently has focus and is on top.
On Linux it's XRaiseWindow, on Windows - SetForegroundWindow, in both cases we already store variables needed for the call anyway in the window impl for that platform, I don't know what it is on Mac OS X but I doubt it's much worse.

45
SFML projects / Lazarus rewrite of Packet
« on: November 02, 2013, 05:05:17 am »
I've rewritten(not bound) sf::Packet in Free Pascal for my own use, just with UTF-8 strings though, no wide or UTF32 ones. It's a bit less pretty and has read and write based on C API and might contain bugs since I'm (re)learning 'Delphi compatible Object Pascal' after knowing small bits of Delphi long ago.
Here's the unit: https://gist.github.com/FRex/7275301
Here are screens of example Lazarus app that sends over TCP to a c++ command line app that will just print and then echo back a thanks to Lazarus side:
http://oi39.tinypic.com/34ns6px.jpg
http://oi39.tinypic.com/2ivz442.jpg

Pages: 1 2 [3] 4 5
anything