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

Pages: [1]
1
Well, statistically speaking...


Around 100-300K should do ;)

The data, programmatically fetched from Ohloh.

2
General / Handling simultaneous, interdependent, game loop updates
« on: July 13, 2013, 11:21:07 am »
This is more of a general game programming than an SFML question, but I still thought you might have some insight:

Say, I was going to implement "The Game of Life". As you probably know this game consists of an infinite two dimensional grid of square "cells" that live under very simple rules. Each iteration of the game, each cell can be "born", can "continue living" or can "die". This only depends on the number of adjacent cells that are alive.

Something like this:

class Cell : public bool
{
public.
  void update(int numberOfLiveNeighbors)
  {
    *this = numberOfLiveNeighbours == 3 || (numberOfLiveNeighbours == 2 && *this);
  }
};
 

Now, if I was to follow the standard implementation recommended by most game tutorials, my naive game loop would look something like this:

for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
{
  int n = countLiveNeighbors(x, y);
  cells[x * height + y].update(n);
}
 

That is, update each cell after the other. Obviously, that won't work, because each cell needs the data about the last generation, and some of the neighbors have already updated when they are counted.

Variant a) One solution would be to have a game state: store a copy of the "board", compute next generation based on that copy, replace, rinse & repeat. This is the standard board game approach, but means a lot of copy operations. Which is bad, if the board is large. (it's supposed to be infinite after all)

Variant b)Another option would be to do something similar, but on the cell level:

class Cell : public bool
{
public:
  void preUpdate(int numberOfLiveNeighbors)
  {
    inescapableFate = numberOfLiveNeighbours == 3 || (numberOfLiveNeighbours == 2 && *this);
  }

  void update(int numberOfLiveNeighbors)
  {
    *this = inescapableFate;
  }
private:
  bool inescapableFate;
};
 

Then, run the loop twice: Once to "precompute", once to actually update. That works, but is also terrible: you still are copying a lot of data (the same amount in this case), and increase the complexity of your code by counter-intuitively breaking a method in two. The advantage is, you don't have to copy stuff that doesn't change.

Of course, I am not really coding this "game", but the problem I am facing is basically the same. What would you do in this case?

3
DotNet / Threading errors (Something to do with object disposal?)
« on: July 11, 2013, 03:59:08 am »
Hello, all. I have been running into these threading errors:

Code: [Select]
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
mono: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) SFML.Graphics.RenderWindow.sfRenderWindow_getViewport (intptr,intptr) <IL 0x00012, 0xffffffff>
  at SFML.Graphics.RenderWindow.GetViewport (SFML.Graphics.View) [0x00001] in /home/camilo/Proyectos/Pax/Libraries/SFML.Net/src/Graphics/RenderWindow.cs:332
  at Gwen.Renderer.SFML.StartClip () [0x000a2] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen.Renderer.SFML/Renderer/SFML.cs:415
  at Gwen.Control.Base.RenderRecursive (Gwen.Skin.Base,System.Drawing.Rectangle) [0x00056] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Base.cs:1146
  at Gwen.Control.Base.DoRender (Gwen.Skin.Base) [0x00045] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Base.cs:1113
  at Gwen.Control.Canvas.RenderCanvas () [0x0006d] in /home/camilo/Proyectos/Pax/Libraries/GwenCS/Gwen/Control/Canvas.cs:127
  at Pax.Client.MainWindow.Update () [0x0002a] in /home/camilo/Proyectos/Pax/Programs/Pax.Client/MainWindow.cs:82
  at Pax.Client.MainClass.Main (string[]) [0x0000d] in /home/camilo/Proyectos/Pax/Programs/Pax.Client/Main.cs:34
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>

Native stacktrace:

    /usr/bin/mono() [0x4a9301]
    /lib/x86_64-linux-gnu/libpthread.so.0(+0xf210) [0x7fdb9ed30210]
    /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x35) [0x7fdb9e9aa1e5]
    /lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7fdb9e9ad398]
    /lib/x86_64-linux-gnu/libc.so.6(+0x2e272) [0x7fdb9e9a3272]
    /lib/x86_64-linux-gnu/libc.so.6(+0x2e322) [0x7fdb9e9a3322]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(+0x433dc) [0x7fdb96e803dc]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(_XReply+0x23b) [0x7fdb96e8121b]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(_XGetWindowAttributes+0xa4) [0x7fdb96e68974]
    /usr/lib/x86_64-linux-gnu/libX11.so.6(XGetWindowAttributes+0x31) [0x7fdb96e68ae1]
    /usr/lib/libsfml-window.so.2(+0xd31d) [0x7fdb9c3fa31d]
    /usr/lib/libsfml-window.so.2(_ZNK2sf6Window7getSizeEv+0x15) [0x7fdb9c3f6165]
    /usr/lib/libsfml-graphics.so.2(_ZNK2sf12RenderWindow7getSizeEv+0x9) [0x7fdb9c62b389]
    /usr/lib/libsfml-graphics.so.2(_ZNK2sf12RenderTarget11getViewportERKNS_4ViewE+0x12) [0x7fdb9c62a8e2]
    /usr/lib/libcsfml-graphics.so.2(sfRenderWindow_getViewport+0xd) [0x7fdb9c85104d]
    [0x40b1db98]

Further down it lists the threads that are running, but marks the 1st (main) thread as active, if I understand correctly.

Code: [Select]
* 1    Thread 0x7fdb9f833740 (LWP 12975) "mono" 0x00007fdb9ed2fe07 in __libc_waitpid (pid=<optimized out>, stat_loc=<optimized out>, options=<optimized out>) at ../sysdeps/unix/sysv/linux/waitpid.c:40

I have found one "solution", but I don't know what I might be breaking. To comment out the Dispose in SFML.Net's ObjectBase destructor (or whatever it's called in C#).

public abstract class ObjectBase : IDisposable
{
//...
        ~ObjectBase()
        {
            //Dispose(false);
        }
//...
}
 

So, my suspcion is, the finalizer disposes something the main thread is still using. But I have no idea what it could be, and why it happens. Any hints?

4


EDIT: Fixed broken image link

In the above image, the nice colorful rectangle near the center is generated by a VertexArray, while the ugly triangle to the left is generated by a Vertex[]. I would have expected them to be the same. Here's the code:

using SFML.Graphics;
using SFML.Window;

public class TestProgram
{
    private RenderWindow window;

        static void Main()
    {
                RenderWindow window = new RenderWindow(new VideoMode(800, 600), "VA test");
                window.SetVerticalSyncEnabled(true);
                window.Closed += (sender, e) => window.Close();

                Vertex v1 = new Vertex(new Vector2f(300, 100), Color.White);
                Vertex v2 = new Vertex(new Vector2f(450, 100), Color.Green);
                Vertex v3 = new Vertex(new Vector2f(450, 300), Color.Magenta);
                Vertex v4 = new Vertex(new Vector2f(300, 300), Color.Yellow);

                VertexArray vertexArray = new VertexArray(PrimitiveType.Quads, 4);
                vertexArray.Append(v1);
                vertexArray.Append(v2);
                vertexArray.Append(v3);
                vertexArray.Append(v4);

                Vertex[] arrayOfVertices = new Vertex[64];
                arrayOfVertices[0] = v1;
                arrayOfVertices[1] = v2;
                arrayOfVertices[2] = v3;
                arrayOfVertices[3] = v4;

                while (window.IsOpen())
        {
            window.DispatchEvents();
            window.Clear();
                        window.Draw(vertexArray);
                        window.Draw(arrayOfVertices, 0, 4, PrimitiveType.Quads);
            window.Display();
        }
        window.Dispose();
    }
}

Note, the bug is also present if you use other PrimitiveTypes. I am not sure if this is a bug in SFML, in SFML.Net or I just don't know how to use RenderWindow.Draw(Vertex[], ...).
c.f. the issue in Gwen.Net that lead me to this

5
Graphics / Curved text drawing
« on: July 03, 2013, 06:54:30 pm »
So, I am trying to draw some curved text. The results so far:


And my code (C#): EDIT: See wiki.

There are a few problems:
  • It's not *that* great to use one Text object for each character, but I can't think  of another way that still takes advantage of SFML's text loading and rendering.
  • Rendering bugs. I think they are related to using the bounds of the Texts to calculate position (rotation anchor), and they seem to not exactly match the size of the glyph.
  • I wanted to do the rotation on the glyphs instead of on the state's transform, but Text.Transform is not writtable. Why?
  • Ignoring kerning. Left that for when the rest works better.

6
DotNet / [SOLVED]SFML.Net on Windows
« on: June 30, 2013, 07:00:56 am »
Hello all, here I am with another noob question.
My game prototype is, despite some minor annoyances, working on Mono/Linux, so I decided to check how well it would run on windows, and am stuck with one of the most basic issues: missing dependencies.

As I am using GTK#, which is only available for x86 windows, I am targeting that architecture. I have set the Configuration accordingly:


Then, copied the csfml-*-2.dll, openal32.dll and libsndfile1.dll DLLs present in the SFML.Net installation to the executable's dir (build/Debug & build/Release).

Trying to execute the game, I get the following run time error: DllNotFoundException: Unable to load DLL 'csfml-graphics-2': The specified module could not be found. Details: http://pastebin.com/9edTcQMV

I then tried using the csfml libraries downloadable from this website (both x86 and 64 bit versions, just in case), and also tried building SFML.Net myself (which works, btw). Tried putting the DLLs in windows/system32. Then, switched from VS2012 to Xamarin Studio. None of that solves the problem.

I strongly suspect it has something to do with architecture incompabilities, but I don't know what I can do to solve the problem. Any hints?

EDIT: Forgot to say, I deleted the *.dll.config files I was using in Linux.

7
DotNet / Mix OpenGL with SFML.Net? [Also: Where's my AA?]
« on: June 29, 2013, 01:12:20 pm »
So, I want to draw some Antialiased shapes. Since SFML refuses to do so (I think it is because I am drawing to a GTK widget), I thought I might enable AA myself, via some GL calls. I might want to use some OpenGL later anyways, so not a bad idea to make sure it works.
My first try with OpenTK failed, I couldn't find out how to pass it the context it needs, so I got a whole bunch of null pointer exceptions and the like. So now I am using the much simpler Tao:

Gl.glEnable(Gl.GL_POLYGON_SMOOTH);
Gl.glEnable(Gl.GL_LINE_SMOOTH);
Gl.glHint(Gl.GL_POLYGON_SMOOTH_HINT, Gl.GL_NICEST);
Gl.glHint(Gl.GL_LINE_SMOOTH_HINT, Gl.GL_NICEST);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
Color transparent = new Color(0, 0, 0, 0);
Vector2f origin = new Vector2f();
Vector2f loopOffset = new Vector2f(3600f, 0f);
foreach (ConvexShape part in Parts)
{
        part.FillColor = transparent;
        part.OutlineColor = Color.White;
        part.OutlineThickness = 2f;
        Draw(part);
        part.Origin -= loopOffset;
        Draw(part);
        part.Origin = origin;
}
 

But I still get no AA! Are all my enables reset by SFML when I call Draw(), or what else could I be doing wrong?

8
DotNet / C# resource manager
« on: June 27, 2013, 02:40:22 am »
Hello,
I need a resource manager for my project, to make sure resources are only loaded once and to make them easily editable by users. Apart from textures, fonts and strings it's very important to me that this manager supports custom types. E.g. I have a "Mosaic" type which is basically a multilayered map that loads and unloads textures on demand. Ideally, mosaics would be defined in the resources somewhat like this:

<resources>
        <!-- other resources... textures, fonts, strings, etc -->
        <mosaic name="background">
                <tileset name="background_small"
                                        basename="resources/back_small_{n}.png"
                                        width="4" height="2"/>
                <tileset name="background_medium"
                                        basename="resources/back_medium_{n}.png"
                                        width="8" height="4"/>
                <tileset name="background_large"
                                        basename="resources/back_large_{n}.png"
                                        width="20" height="10"/>
        </mosaic>
        <!-- other resources... -->
</resources>

The question is: Does a class exist that does this for me? That Microsoft resx thing, would that fit the bill? Or would you write your own?

Sorry if the question seems basic, I am quite new to .NET and thanks for your help.

Pages: [1]
anything