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

Pages: 1 2 [3] 4
31
DotNet / Is it important to Dispose SFML objects?
« on: September 07, 2011, 11:27:34 am »
You can leak OS handles (for fonts, bitmaps etc) so if your application runs for a long time, it can become a problem. It will eventually all be freed in the end, but you should Dispose() everything after you're done with it - this will improve your code's performance and lessen memory usage. I actually blogged about this very issue recently, so if you are interested - Optimizing Garbage Collector performance in your .NET application.

32
Sometimes if you need the best performance and not much functionality, you can rewrite it... I did that once, replacing std::list with a dynamic array implementation which was much faster. But that was a specific case, I was number crunching some genetic algorithms and needed the speed. ;) But for general cases it's usually good enough.

33
Feature requests / Bitmap fonts?
« on: September 05, 2011, 03:20:24 pm »
Make sure to not limit character number to only ASCII range if you end up implementing that. :)

34
General / VS2010 C#/.NET and SFML 2.0
« on: September 04, 2011, 08:25:30 pm »
You can use BitConverter class for simple types (but manual byte extraction using bitwise operators is faster). For more complex objects, use MemoryStream with BinaryFormatter:

Code: [Select]

using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;

        /// <summary>
        /// Serializes object into a byte array.
        /// </summary>
        /// <param name="o">Object to serialize.</param>
        /// <returns>Serialized bytes.</returns>
        public byte[] SerializeObject(object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, o);
            return ms.ToArray();
        }

        /// <summary>
        /// Deserializes object from a byte array.
        /// </summary>
        /// <param name="data">Serialized data.</param>
        /// <returns>Deserialized object.</returns>
        public object DeserializeObject(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);
            BinaryFormatter bf = new BinaryFormatter();
            ms.Position = 0;
            return bf.Deserialize(ms);
        }

35
General discussions / Who Are You? (the obligatory interview thread)
« on: September 02, 2011, 03:04:59 pm »
Right, I guess it won't hurt to write something here. ;)

I'm 32 years old antisocial guy living in Poland. Currently working for a small consulting company specializing in information security. Previously worked for a few years for Symantec, but big corporations turned out to not be my thing. ;) Even before that, I was a contractor for the biggest Polish game distributor (and now developer), CD Projekt (you may have heard of The Witcher ;)). I did technical side of localizing games for them, that is extracting all localizable (translatable) resources and importing them after they have been translated. May sound easy, but I was working on games that did not have any SDKs most of the time, no documentation of game file format etc - needed to analyze them myself, write tools to unpack/repack game data, find all translatable stuff (not only text - also images containing text, voiceovers, fonts if they lack diacritic marks specific to Polish language etc). It was very fun, but unfortunately they didn't pay much, so I moved on. :P

I'm a sort of hybrid of a "logical thinking" person and a "creative" one. I love programming, math, modern physics and science-fiction, but I also love creative writing, classical literature and music. I was always fascinated in computers and how they work (or how all things work I guess ;)). Unfortunately Poland was a poor country back then so I didn't have access to such hardware.

My first contact with a computer was a friend's C-64. What a great machine! We played games of course, but I also started to dabble in BASIC. C-64 didn't have any "operating system" proper, all it has was a BASIC command prompt. So I learned it and wrote some simple programs, but soon it was not enough. BASIC was very limited and slow, and if you wanted to do something really cool, you needed to do it in assembly. So I learned 6502 assembly. :D Compared to todays CPUs it was a beautiful machine code in its simplicity. I coded some silly "demos" (more like intros), and also learned how to debug machine code to hack games. Those were my first steps in reverse engineering - it's this curiosity that drives you to take things (and code) apart to see how they work, and to change them.

My biggest achievement back then was a "code interpreter/debugger" that could take two C-64 binary programs and execute them "in parallel", taking one machine code instruction at a time alternately from both of them. That was an 8-bit CPU, there was no multithreading back then. ;) Of course it only worked for simple programs that didn't use conflicting registers and all that, but it was nice.

I've seen a PC for the first time somewhere at the end of elementary school. I've learned Pascal and Logo (Logo is awesome for one-liner fractals ;)). Later I learned basics of C and C++ (strings? pointers? what the hell?). I started to take interest in inner workings of Windows - gaining reverse engineering knowledge on that platform. I got my own PC only a year after I started a technical university, believe it or not. It was also the time of more prevalent Internet access and knowledge became easier to acquire. I've learned a great deal about software protections - how to break them and how to create them.

At Uni I started playing on a private server of Ultima Online. Maybe some of you remember the first popular graphical MMORPG. :) Later I became a developer and an admin of the server. Even later I became involved in another UO server project, this time based around RunUO - an emulator written in C#. That was my first contact with C# and the .Net platform.

This is a good moment for an interlude. As you can see I'm a guy with a pretty low-level background. I know assembly of several CPUs. I know how Windows works under the hood. I'm also kind of a performance freak - I like profiling code, analyzing compiler output and the like. And now I'll almost always choose C# for a new project if it doesn't require much low-level OS access. What gives? "C# is slow, bloated yadda yadda!!1one!" If you say that in front of me, I'll rip your head off. ;)

For me the biggest gain in using C# and .Net is productivity. Yes, it is a little slower than C/C++, although not much and mostly only in specific circumstances. Yes, it does have higher memory overhead - but again, not by much. So what do you get in return?
  • Much, MUCH simpler memory management. It's not gone completely, contrary to what many people believe. You still need to (well, should) know how garbage collector works and when to dispose some objects if they hold unmanaged resources. But it's easier.
  • You don't need to worry about proper support for strings, unicode, events, networking, data structures and other really basic things. Yes, C++ has STL and other libraries, but I personally loathe STL and would kill it with fire if I could.
  • No more access violations, heap corruptions and other nonsense. Of course you can still have null pointer dereferences. ;)
  • You can use pointers and direct memory access if you like. Another popular myth is that you can't.
  • It's faster to code, easier to debug, more compact, open standard and cross-platform (yes Mono can run any .Net binaries on Linux), base class library contains tons of useful things.
People argue that you can't write games in C#. Is that so? RunUO server team did a stress test once, the server could handle nearly ten thousand online clients at once. Take a look a Magicka, Terraria or Space Pirates and Zombies, some very popular and fun Indie games (at least I'd recommend playing them all if you didn't). Thay are all written in C# (well, SPAZ uses Unity, but its core scripts are in C#). OK, rant over. :P

What else can I say... Along the way I also learned a bit about electronics. I have a mini-lab with lots of stuff but lack time to do something bigger with it. :( I have an Arduino (AVR based microcontroller prototyping board) and like to do some fun stuff with it. If only a day had 50 hours or somrthing...

One of my biggest interests is in complexity, chaos theory and self-emergence. Artificial life, artificial intelligence, fractal geometry, cellular automata, all these things fascinate me. My master thesis was about artificial life and genetic algorithms - it was something similar to Avida.

So, why the hell I'm using SFML in the first place? :D Basically, I needed some .NET-compatible 2D gfx library for a game client for my project. I'm creating an isometric MMO engine similar to UO, mostly out of nostalgia and for the learning experience. A lot of the basic things are done and now is the time to actually create a graphical client instead of console one. :P Currently my focus is on porting Gwen to .NET - this will be my GUI library. Again, why the day is so short...

As for the games - I'm mostly a fan of good cRPGs - here, Planescape: Torment is the king. Baldur's Gate 2, Morrowind, The Witcher (2), Fallouts, and of course Deus Ex (need time for the new installment...) I also like to play a shooter every now and then (Bulletstorm was awesome). Mass Effect (2) was good for the "movie-like" experience. Maybe some arcade shooters like Beat Hazard or good old Crimsonland (man, that was insane). Used to play a lot of Heroes of Might&Magic 3 back in the days. Also spent a lot of time getting killed in various ways in ADoM - an awesome roguelike game. Managed to beat it a few times, felt good. :)

 :shock: Didn't think this will be such a wall of text. :lol: I've also recently created a blog, so if you are curious, you can have a look at that. ;)

36
Window / Event handling advice\best prectices
« on: August 31, 2011, 12:27:45 pm »
Or use C# which has built-in support for events. :wink:

37
DotNet / A really big bug...
« on: August 31, 2011, 12:07:49 pm »
You can try creating new image from source pixel data:
Code: [Select]

Image newImg = new Image(oldImg.Width, oldImg.Height, oldImg.Pixels);

38
Graphics / Most effiecient way to 'blit'?
« on: August 31, 2011, 09:36:30 am »
Don't use SetPixel/GetPixel - they are always very slow. What you want is to change pixel data in memory and then set everything at once. SFML.Graphics.Image has a constructor that takes a byte array of pixel data, you want to use that. Here is an example from my GWEN.Net SFML renderer:
Code: [Select]
       // [omeg] added, pixelData is in RGBA format
        public override void LoadTextureRaw(Texture texture, byte[] pixelData)
        {
            if (null == texture) return;
            if (texture.RendererData != null) FreeTexture(texture);

            global::SFML.Graphics.Texture tex;
            Sprite sprite;

            try
            {
                var img = new Image((uint)texture.Width, (uint)texture.Height, pixelData); // SFML Image
                tex = new global::SFML.Graphics.Texture(img);
                tex.Smooth = true;
                sprite = new Sprite(tex);
                img.Dispose();
            }
            catch (LoadingFailedException)
            {
                texture.Failed = true;
                return;
            }

            texture.RendererData = sprite;
        }


and here an example of how to build raw pixel data:
Code: [Select]
           if (m_Texture == null)
            {
                byte[] pixelData = new byte[Width*Height*4];

                for (int x = 0; x < Width; x++)
                {
                    for (int y = 0; y < Height; y++)
                    {
                        Color c = GetColorAt(x, y);
                        pixelData[4*(x + y*Width)] = c.R;
                        pixelData[4*(x + y*Width) + 1] = c.G;
                        pixelData[4*(x + y*Width) + 2] = c.B;
                        pixelData[4*(x + y*Width) + 3] = c.A;
                    }
                }

                m_Texture = new Texture(skin.Renderer);
                m_Texture.Width = Width;
                m_Texture.Height = Height;
                m_Texture.LoadRaw(Width, Height, pixelData);
            }

39
DotNet / SFML.Net 2 for linux download?
« on: August 25, 2011, 03:18:33 pm »
Make sure you have names exactly like in my post. You may also need to set
Code: [Select]
LD_LIBRARY_PATH=. to make it load libraries from current directory.

Edit: also there is a setting for mono to show verbosely where it looks for libraries, it can help you.

40
DotNet / SFML.Net 2 for linux download?
« on: August 25, 2011, 09:28:28 am »
You need to build CSFML and SFML for linux. sfmlnet assemblies need following libraries:
Code: [Select]

libsfml-graphics.so.2 (SFML)
libsfml-window.so.2 (SFML)
libsfml-system.so.2 (SFML)

libcsfml-graphics-2.so (CSFML)
libcsfml-window-2.so (CSFML)


https://github.com/SFML/CSFML
https://github.com/SFML/SFML

41
DotNet / glVertexPointer in Tao
« on: August 24, 2011, 10:30:37 pm »
This seems to be a bug in Tao binding: glVertexPointer that takes object as the last parameter incorrectly computes pointer to data. The fix is to use IntPtr version (unsafe code necessary...):
Code: [Select]
fixed (float* ptr1 = &coord[0])
    Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, (IntPtr)ptr1);

42
DotNet / glVertexPointer in Tao
« on: August 24, 2011, 09:55:14 pm »
I'm trying to use glVertexPointer function from Tao framework without much luck. Following sample draws nothing (commented out lines do draw triangle).

Initialization code:
Code: [Select]
float[] coord = new float[16];
float[] color = new float[16];
// all white
for (int i = 0; i < 16; i++)
    color[i] = 1;

// triangle
coord[0] = 0.5f;
coord[1] = 1;
coord[2] = 0;
coord[3] = 0;
coord[4] = 0;
coord[5] = 0;
coord[6] = 1;
coord[7] = 0;
coord[8] = 0;

Gl.glClearColor(1f, 0f, 0f, 1f);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glOrtho(0, 1, 0, 1, -1, 1);


and then in render loop

Code: [Select]
Gl.glColor3f(0, 1, 0);
// this works
//Gl.glBegin(Gl.GL_TRIANGLES);
//Gl.glVertex3f(0.5f, 1f, 0); Gl.glVertex3f(0, 0, 0); Gl.glVertex3f(1f, 0, 0);
//Gl.glEnd();
               
// this doesn't
Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glEnableClientState(Gl.GL_COLOR_ARRAY);
Gl.glVertexPointer(3, Gl.GL_FLOAT, 0, coord[0]);
Gl.glColorPointer(3, Gl.GL_FLOAT, 0, color[0]);

Gl.glDrawArrays(Gl.GL_TRIANGLES, 0, 3);
Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);
Gl.glDisableClientState(Gl.GL_COLOR_ARRAY);


Both arrays have 3 elements per vertex, 0 stride (tightly packed). Debugger shows correct values in memory. I guess it's some glitch in Tao or between managed and unmanaged code... Any advice would be appreciated.

43
General discussions / [IDEA] Move sf::Rect into System Module?
« on: August 23, 2011, 10:41:04 am »
Another thing to keep in mind is that for example in SFML.Net there is no System library since it's not needed, all its functionality is in base class library anyway. ;)

44
General / Cannot find or open the PDB file
« on: August 23, 2011, 08:30:54 am »
Debugger tries to find and a PDB  file (symbols information) for every module it loads. Obviously some external DLLs don't have it available, so debugger won't be able to give detailed information *if* you were to debug those DLLs ;)

45
Window / Getting supported resolutions.
« on: August 22, 2011, 08:01:44 pm »
if( (mode.Width/mode.Height) == (4/3) )

This is integer division. Cast the numbers to float/double (and remember that floating-point comparisons are not exact).

Pages: 1 2 [3] 4