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 - Gan

Pages: [1] 2 3 ... 7
Are these issues only inherit to DSFML or flaws in SFML itself?

That's a pretty good idea for a more performant space background.

In my actual game, I don't redraw the rendertextures every frame. Just as soon as they get off screen. Though the same issue happens as if drawing every frame- just slower.

2 issues:
- Anti aliasing doesn't happen on RenderTextures
- Memory usage creeps upward

General / Re: toAnsiString causes crash
« on: February 21, 2015, 07:46:28 am »
I'm not sure if this is helpful but in the documentation, this part jumped out at me:

It automatically handles conversions from/to ANSI and wide strings, so that you can work with standard string classes and still be compatible with functions taking a sf::String.

sf::String s;
std::string s1 = s;  // automatically converted to ANSI string

You shouldn't need to call the ansi function.

Holy crap. Are you creating multiple RenderTextures and then drawing to all of them each frame?

That would be your memory issue. RenderTextures are not light objects and should be used sparingly. I'm surprised it isn't causing performance issues.
Yes. I have a grid of render textures across the screen. I redraw the render textures when they get off screen. It allows me to make a very heavily starred procedurally generated background at 6% CPU perfromance. Producing the same without render textures, just drawing circle shapes uses 100%+ CPU usage.

Would you have a better solution than RenderTextures?

Edit: Despite render textures using inherently more memory, why would the memory continue to rise? Seems like an issue in the RenderTexture itself.

I fixed the text rendering issue.

Turns out you don't want to create any objects before the window is created. Pretty easy fix. Strange though.

As for the lots of ram usage. I made a new example to test that.

I made two tests. Both tests drawing 4000 stars each frame.

  • Test without render textures stabilizes at 35.1mb.
  • Test with 30 render textures doesn't stabilize, goes 137mb and continues to slowly rise.
  • Test without render textures uses anti-aliasing.
  • Test with 30 render textures does not use anti-aliasing despite having smooth set to true.

It seems render textures are flawed in that they use lots of ram and don't anti-alias.
Though they are essential to lower the CPU required to draw a very large, moving, generated parallax background.

Test program:
module main;

import dsfml.graphics;
import std.stdio;
import core.memory;
import std.file;
import std.conv;
import std.string;
import std.random;

void main(string[] args)

        ContextSettings settings;
        settings.antialiasingLevel = 8
        settings.majorVersion = 3;
        settings.minorVersion = 2;

        auto window = new RenderWindow(VideoMode(1152, 720),"SpaceCraft", RenderWindow.Style.DefaultStyle, settings);
        Font GameFont = new Font();
        string path = thisExePath();
        int index = to!int(path.lastIndexOf("/"));
        if (!GameFont.loadFromFile(path[0 .. index]~"/vertiup2.ttf")) {
                writeln("Font failed to load");
        Text text = new Text("Hello DSFML", GameFont, 50);
        text.setColor(Color(255, 0, 0));
        text.origin = Vector2f(0, 0);
        text.position = Vector2f(100, 100);
        CircleShape shape = new CircleShape(30);

        RenderTexture[] textures = new RenderTexture[](0);
        Sprite[] textureSprites = new Sprite[](0);

        for (int i = 0; i < 30; i++) {
                RenderTexture canvas = new RenderTexture();
                canvas.create(512, 512);
                canvas.clear(Color(0, 0, 0, 0));
                canvas.smooth = true;
                textures ~= canvas;
                Sprite tileSprite = new Sprite(canvas.getTexture());
                tileSprite.origin = Vector2f(512/2,512/2);
                textureSprites ~= tileSprite;

    while (window.isOpen())
        Event event;

            if(event.type == event.EventType.Closed)


                drawStarsWithRenderTextures(textureSprites, textures, shape, window);
                //drawStars(shape, window, 4000);




/***************   Hits 137.5mb+, not stabilizing after 5 minutes  **************/
void drawStarsWithRenderTextures(Sprite[] tileSprites, RenderTexture[] textures, CircleShape shape, RenderTarget window) {
        int starCount = to!int(4000/textures.length);
        for (int i = 0; i < textures.length; i++) {
                RenderTexture canvas = textures[i];
                canvas.clear(Color(0, 0, 0, 0));
                drawStars(shape, canvas, starCount);
                Sprite tileSprite = tileSprites[i];
                Random gen;
                int x = uniform(0, window.getSize().x, gen);
                int y = uniform(0, window.getSize().y, gen);
                tileSprite.position = Vector2f(x, y);
/***************   Stabilizes at 35.1mb   **************/
void drawStars(CircleShape shape, RenderTarget window, int starCount) {
        //Draw stars
        for (int i = 0; i < starCount; i++) {
                Random gen;
                int r = uniform(0, 255, gen);
                int g = uniform(0, 255, gen);
                int b = uniform(0, 255, gen);
                int x = uniform(0, window.getSize().x, gen);
                int y = uniform(0, window.getSize().y, gen);
                shape.fillColor = Color(to!ubyte(r), to!ubyte(b), to!ubyte(g));
                shape.position = Vector2f(x, y);
                shape.origin = Vector2f(0.5, 0.5);
                shape.scale = Vector2f(15 / 30.0 , 15 / 30.0);

I optimized it so it only uses one CircleShape now but set it to redraw the maximum amount of stars per frame. Gonna see where it stops gaining memory.
It starts at 50mb still. Using 100% CPU cause I'm forcing it to redraw all tiles every frame so thousands of stars.

It is up to 209.3mb. Increasing incredibly slowly. Like takes a minute to go up another megabyte.

So drawing 1 star thousands of time uses 150+mb slowly over time. Now up to 213.5mb.

On a side note, any idea why text rendering is so finicky? (I'm going to go look at the CircleShape code)

General / Re: Need a tiny little bit of help
« on: February 20, 2015, 10:15:36 pm »
The easiest way would be converting your floats to ints. That would remove trailing decimal and zeros when converting to string.

sf::Vector2f positioncurseur = curseur.getPosition();

std::string cursx = std::to_string ( (int)positioncurseur.x );
std::string cursy = std::to_string ( (int)positioncurseur.y );

title += cursx;
title += " ";
title += cursy;

D / Re: Loving it but a few questions
« on: February 20, 2015, 08:55:30 pm »
To fix this issue, make your own Application Bundle and put the required frameworks in it.

For loading resources in the bundle:
Code: [Select]
string path = thisExePath();
int index = to!int(path.lastIndexOf("/"));
if (!GameFont.loadFromFile(path[0 .. index]~"/vertiup2.ttf")) {
writeln("Font failed to load");

Bundle for editing: http://cl.ly/121f0j0d273S

Tried your ram idea, ram stabilized at 163mb.
I added this code on every loop:
Code: [Select]

Though when I comment the draw star line:
Code: [Select]
//target.draw(star);It stabilizes at 50mb.

I'm trying to figure out why drawing many stars uses 110mb of ram.

I'll try that.

Regarding the text not fully displaying, on my desktop Mac text displays fine but on my laptop mac, it displays half of the text.
Desktop mac:

Figured it out. I hand made a bundle, then to load resources I had to use some custom paths.

For my custom paths:
Code: [Select]
string path = thisExePath();
int index = to!int(path.lastIndexOf("/"));
if (!GameFont.loadFromFile(path[0 .. index]~"/vertiup2.ttf")) {
writeln("Font failed to load");

Problem solved. I'll attach the bundle if anyone wants to edit it for their projects.

Bundle: http://cl.ly/121f0j0d273S

You're right, I did post a question regarding this on the D forum a few hours ago.

There is a link to the «Bundle Programming Guide», follow it.
Please don't respond unless you can be helpful.
How is pointing out that there is a link to the documentation you need not being helpful???

Creating an Application Bundle
The simplest way to create an application bundle is using Xcode. All new application projects include an appropriately configured application target, which defines the rules needed to build an application bundle, including which source files to compile, which resource files to copy to the bundle, and so on. New projects also include a preconfigured Info.plist file and typically several other files to help you get started quickly. You can add any custom files as needed using the project window and configure those files using the Info or Inspector windows. For example, you might use the Info window to specify custom locations for resource files inside your bundle.

For information on how to configure targets in Xcode, see Xcode Build System Guide.

If you're refering to this section of that document, that is as useful as a colander being used to hold tomato soup.
I will look to see if I can take a pre-existing executable and build an Application Bundle through XCode but I don't think that Xcode was designed for that.
In this circumstance, I'm looking for instructions to convert an already compiled executable(from D Language using DUB) into an Application Bundle. I'm not taking just a C or C++ source code and compiling it. If I were, XCode would be my choice. However XCode is not a part of my workflow.

Please take an effort to diagnose the problem before pasting a solution that does not apply.

Sorry for my crankiness, I really do appreciate your attempts to help.

Two problems, I'll start with the text not displaying correctly because that is the most obvious issue:

Only certain letters show. This was not always the case, I tweaked some graphics code in another part of the project and this started happening. In fact, I was trying to solve the second problem when the first problem started happening.

Secondly, the program uses massive amounts of ram. To replicate, fly the ship in one direction. The ram usage climbs upward and upward. After 7 hours it uses 700mb of ram.

I managed to comment code until I found the issue. It is located in source/Game/Misc/SpaceBackground.d at line 254.
Code: [Select]
target.draw(star);I'm drawing a circle shape to a RenderTexture. Comment that line of code and memory usage stabilizes at about 60mb consistently. Keep that line of code in and it climbs above 200mb+ over time.

I've attached the source and the executables.

Instructions to run the executables:
(1) Run the server executable.
(2) cd to the Game Executables directory.
(3) Run the Game executable.
(4) Type in letters for the username. Click Enter. Type in letters for the password. Click Enter. Type in letters for a name. Click Enter.
(5) Fly the space ship using the arrow keys. Watch the ram usage. Also notice the missing letters in the text.

Instructions for running from the source:
Use DUB.
Note: The source is using DSFML with the D Language.

I would appreciate ideas for why SFML is failing to render text and uses lots of memory for drawing circle shapes.

Source: http://cl.ly/2H3D3T3A0J2G
Executables: http://cl.ly/2L2v17471u3b

Pages: [1] 2 3 ... 7