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

Pages: 1 ... 12 13 [14]
196
Graphics / CircleShape performance
« on: September 23, 2015, 03:37:45 pm »
I caught some performance issues with CircleShape.
When the total count of circles grows up to 1000 per frame, the performance slows down dramaticaly. When it's count grows up to 2000, I get 5-10 fps... :(
I run profiler and it shows that SFML consumes for about 80% of time in drawing circles...

Could you please suggest any optimization techniques to improve performance?
I added condition to render rectangles instead of circles when it's physical size is lower than 3-4 pixels. It helps very well (fps increased for 1,5 times), but it's not enough. I need more optimizations. Any ideas are welcome.
Thanks

197
Graphics / Re: Some unicode characters is not rendered with Text
« on: September 23, 2015, 03:18:18 pm »
I think that render of each letter separately is not a good idea, because I already have some issues with performance.
It's because I need to render white text with black shadow around it. Its needed to make a text to be highly contrast (something like outline).
I didn't find better solution than render it with black color and small shifts around actual text position. So, to render one string I need to render it 8+1 times.
The issue with performance appears because total count of strings may be up to 2000-3000 per frame. And it eats valuable time (15-20% of total render time).
So I think that font merge will be better solution...

198
Audio / Re: Does SFML support playing realtime raw sample stream?
« on: September 23, 2015, 02:56:45 pm »
Format is 16 bit stereo, engine has it's own resampler, and is able to produce stream with any sample rate supported by hardware. Higher sample rate is better, because sounds may contains complex sound effects with wide range frequencies (up to 115 kHz), usually I'm using 192 kHz.

Does SoundBuffer support loopback playing with notifications of current position?
I want to write at position just before sound card will read it.
Actually it's how I implemented it in DirectSound...
I used the folowing technique:
1) create surface with loopback buffer for 160 ms
2) set position notifications for each 20 ms segment
3) when notification is raised I read current  playback position, calculate current segment number and write next portion of samples into previous segment (which playback is just completed)

Can I use the same technique in SFML?

199
Audio / Does SFML support playing realtime raw sample stream?
« on: September 23, 2015, 02:18:59 pm »
I need to play raw sound stream which is produced in realtime.

Actually, I wrote some interactive engine which produces realtime raw audio & video streams.
The content is interactive, so buffering is possible for a very short time - 50-100 ms.
Currently I'm using Direct3D and DirectSound directly.
But it's hardly linked with Windows, and I want to porting it into Linux and iOS.

I tested SFML and its really simple and beautiful :)
So, I'm thinking about using SFML...
Does SFML support such functionality?

200
Graphics / Re: Some unicode characters is not rendered with Text
« on: September 23, 2015, 01:56:11 pm »
Thanks man, could you please help me - how can I fix the issue?
Is there any way to implement the same fallback mechanism as it used in the Chrome browser?
Maybe there is any way to include missing glyphs into ubuntu font?
I mean some kind of font merge...
Is it possible?

I just need to display texts which may include characters like this (from unicode symbol set)...


201
Graphics / Re: Some unicode characters is not rendered with Text
« on: September 23, 2015, 09:43:38 am »
Yes, I'm using Visual Studio and C#.
Also I can see with debugger that variable passed into Text object contains valid unicode symbols.
So, there is no issue with text editor or memory representation.

The test string "☺☻♥♠" binary representation is the following:

UTF32: 0x3A, 0x26, 0x00, 0x00, 0x3B, 0x26, 0x00, 0x00, 0x65, 0x26, 0x00, 0x00, 0x60, 0x26, 0x00, 0x00

UTF8: 0xE2, 0x98, 0xBA, 0xE2, 0x98, 0xBB, 0xE2, 0x99, 0xA5, 0xE2, 0x99, 0xA0

Unicode: 0x3A, 0x26, 0x3B, 0x26, 0x65, 0x26, 0x60, 0x26

Symbol codes (Unicode):
"☺" - 0x263A
"☻" - 0x263B
"♥" - 0x2665
"♠" - 0x2660

These symbols are standard, but they didn't worked in SFML with ubuntu font.
I'm not sure, may be there is some kind of issue with decoding of specific symbol set...


PS: also here is special symbol which is specific for ubuntu font and it displayed correctly in SFML (you can download and test the font here: http://font.ubuntu.com/ ):

"" - 0xE0FF   (displayed good with SFML)
"" - 0xF000   (tricky symbol, it displays the number as two 8-segment led, the number should depends on render context)



202
Graphics / Some unicode characters is not rendered with Text
« on: September 23, 2015, 05:24:30 am »
I'm using Text object to render the text with Ubuntu font: http://font.ubuntu.com/

There are some issues with performance, but it works ok.
Except for some symbol characters...

For exampel, try to render the following unicode string: "☺☻♥♠"

SFML displays square symbols instead of these symbols, so it displayed as "□□□□"

It's strange, because unicode symbols like this "" (just copy the text and use ubuntu font, because it will displayed incorrectly on the web site) is displayed correctly ...

I tested these characters on the site http://font.ubuntu.com/ and the ubuntu font contains it.
But it didn't works with SFML... (actually I'm using C# binding SFML.NET)

Any ideas on how to fix it?
Thanks


203
Hi guys,

I'm looking for a solution to add shortcut key to switch between window and fullscreen mode.
I tried to recreate the window like it's recommended for C++, but there is a problem with event handling.

Example:

        private RenderWindow _window;
        private bool _isFullScreen;

        public void Run()
        {
            Init();

            _window = new RenderWindow(
                _isFullScreen ? VideoMode.DesktopMode : new VideoMode(800, 800),
                "MyApp",
                _isFullScreen ? Styles.Fullscreen : Styles.Default,
                new ContextSettings() { AntialiasingLevel = 16 });
            _window.KeyPressed += Window_OnKeyPressed;
            _window.Closed += (s, e) => _window.Close();
            _window.SetVisible(true);
            _window.SetActive(true);

            while (_window.IsOpen)
            {
                _window.DispatchEvents();   // <== Exception appears here

                Update();
                Render();
            }
        }

        private void Window_OnKeyPressed(object sender, KeyEventArgs e)
        {
            if (e.Code == Keyboard.Key.F11)
            {
                // close exist window
                _window.KeyPressed -= Window_OnKeyPressed;
                _window.MouseButtonPressed -= Window_OnMouseButtonPressed;
                _window.MouseButtonReleased -= Window_OnMouseButtonReleased;
                _window.MouseWheelMoved -= Window_OnMouseWheelMoved;
                _window.Close();
                _window.Dispose();

                // create new one
                _window = new RenderWindow(
                                _isFullScreen ? VideoMode.DesktopMode : new VideoMode(800, 800),
                                "MyApp",
                                _isFullScreen ? Styles.Fullscreen : Styles.Default,
                                new ContextSettings() { AntialiasingLevel = 16 });
                _window.KeyPressed += Window_OnKeyPressed;
                _window.Closed += (s, e) => _window.Close();
                _window.SetVisible(true);
                _window.SetActive(true);
            }
        }
 

This code will produce Access violation exception inside DispatchEvents method:
Quote
System.AccessViolationException occurred
  HResult=-2147467261
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=sfmlnet-graphics-2
  StackTrace:
       at SFML.Graphics.RenderWindow.sfRenderWindow_pollEvent(IntPtr CPointer, Event& Evt)
       at SFML.Graphics.RenderWindow.PollEvent(Event& eventToFill)
       at SFML.Window.Window.DispatchEvents()

Any idea on how to handle keyboard event with no call to DispatchEvent?
Thanks

UPDATED: I found the reason, it's because I call the method Window.Dispose. I commented it and now it works :)
But there is still question - how to dispose window in such case?

204
DotNet / Automatic load x32/x64 asseblies
« on: September 23, 2015, 04:13:46 am »
Hi guys,

I'm looking for a good way to load SFML.NET libraries automatically depends on current process architecture.

Currently I implemented a small trick which allows to use Any CPU target for the main project, and it will run on both 32 and 64 bit system with correct loading of SFML.NET assemblies.

Here is the sample:
    class Program
    {
        static Program()
        {
            AppDomain.CurrentDomain.AssemblyResolve += AppDomain_OnAssemblyResolve;
        }

        static void Main(string[] args)
        {
            Logger.Info("System:  {0}", Environment.Is64BitOperatingSystem ? "x64" : "x32");
            Logger.Info("Process: {0}", Environment.Is64BitProcess ? "x64" : "x32");
            using (var myApp = new MyApp())
            {
                myApp.Run();
            }
        }

        private static readonly string[] SfmlAsms = new[]
        {
            "sfmlnet-audio-2",
            "sfmlnet-graphics-2",
            "sfmlnet-system-2",
            "sfmlnet-window-2",
        };

        private static Assembly AppDomain_OnAssemblyResolve(object sender, ResolveEventArgs e)
        {
            if (e.Name == null ||
                !SfmlAsms.Any(arg => e.Name.StartsWith(arg, StringComparison.InvariantCultureIgnoreCase)))
            {
                return null;
            }
            var name = e.Name;
            var commaIndex = name.IndexOf(',');
            if (commaIndex >= 0)
            {
                name = name.Substring(0, commaIndex);
            }
            var folder = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            folder = Path.Combine(folder, Environment.Is64BitProcess ? "x64" : "x32");
            var fileInfo = new FileInfo(Path.Combine(folder, name+".dll"));
            if (!fileInfo.Exists)
            {
                return null;
            }
            return Assembly.LoadFrom(fileInfo.FullName);
        }
    }
 

With this code you should place all SFML.NET assemblies and libraries into the folders "x32" and "x64" near exe.
The code catch assembly resolving event and set correct path depends on process architecture.
So, there is no need to build several executable for each platforms.

If you have any idea on how to add support for linux/mono, any comments are welcome :)

UPDATED: added minor fix

205
Audio / Re: SFML stack overflow exception
« on: September 23, 2015, 01:25:52 am »
I posted minimal code. Initialization is the following:

        private readonly List<Sound> _sound = new List<Sound>();
        private readonly Dictionary<SoundEffect, SoundBuffer> _sndMap = new Dictionary<SoundEffect, SoundBuffer>();

        private void LoadResources()
        {
            _sound.Add(new Sound());
            _sound.Add(new Sound());
            _sndMap[SoundEffect.GameStart] = new SoundBuffer(getPath("gamestart.ogg"));
            _sndMap[SoundEffect.GameOver] = new SoundBuffer(getPath("gameover.ogg"));
        }

I tried different things and found that app crash disappears when I call Sound.Play from the UI thread only and will not use it when it is still in Playing state.
So, probably this method isn't thread safe.

Also I found that there is some kind of bug. Sometimes it may crash app if I call it when it is still in playing state. I tried to execute Stop before action, but it didn't help. So I think it will be better to wait while playback will be completed.

206
Audio / SFML stack overflow exception
« on: September 22, 2015, 01:39:45 am »
I'm using SFML.Net 2.2, x64 build under Windows 7 x64.
And I caught a strange bug which sometimes unexpectedly terminates process.

Visual Studio 2012 didn't break execution, it just shows that process has exited with code 0x80000003...
I got the following error details from WinDbg64:

Critical error detected c0000374
(f8c.d94): Break instruction exception - code 80000003 (first chance)
ntdll!RtlUnhandledExceptionFilter+0x29f:
00000000`7718ff8f cc              int     3
0:019> ~* k

[...skipped...]

# 19  Id: f8c.d94 Suspend: 1 Teb: 000007ff`ffefe000 Unfrozen
Child-SP          RetAddr           Call Site
00000000`26b8ea00 00000000`77190606 ntdll!RtlUnhandledExceptionFilter+0x29f
00000000`26b8ead0 00000000`77191812 ntdll!EtwEnumerateProcessRegGuids+0x216
00000000`26b8eb00 00000000`771934f4 ntdll!RtlQueryProcessLockInformation+0x972
00000000`26b8eb30 00000000`7712b015 ntdll!RtlLogStackBackTrace+0x444
00000000`26b8eb60 00000000`76fd1a7a ntdll!RtlIsDosDeviceName_U+0x5555
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for G:\****\bin\Debug\x64\csfml-audio-2.DLL -
00000000`26b8ebe0 000007fe`ea27ef64 KERNEL32!HeapFree+0xa
00000000`26b8ec10 000007fe`ea278b7a csfml_audio_2!sfSoundStream_destroy+0xc0e4
00000000`26b8ec40 000007fe`ea279419 csfml_audio_2!sfSoundStream_destroy+0x5cfa
00000000`26b8ec70 000007fe`ea279807 csfml_audio_2!sfSoundStream_destroy+0x6599
00000000`26b8eca0 000007fe`ea277cdc csfml_audio_2!sfSoundStream_destroy+0x6987
00000000`26b8ecd0 000007fe`ea271b1a csfml_audio_2!sfSoundStream_destroy+0x4e5c
00000000`26b8ed00 000007fe`90c3f0e3 csfml_audio_2!sfSound_setBuffer+0x1a
00000000`26b8ed30 000007fe`90c3eab1 0x000007fe`90c3f0e3
00000000`26b8ee00 000007fe`ef0739a5 0x000007fe`90c3eab1
00000000`26b8eeb0 000007fe`ef073719 mscorlib_ni+0x4a39a5
00000000`26b8f010 000007fe`ef0a216f mscorlib_ni+0x4a3719
00000000`26b8f040 000007fe`ef0a136a mscorlib_ni+0x4d216f
00000000`26b8f090 000007fe`f026a7f3 mscorlib_ni+0x4d136a
00000000`26b8f150 000007fe`f026a6de clr+0xa7f3
00000000`26b8f190 000007fe`f026ae76 clr+0xa6de
00000000`26b8f1d0 000007fe`f02f0221 clr+0xae76
00000000`26b8f380 000007fe`f026c121 clr!GetMetaDataInternalInterface+0x31d01
00000000`26b8f470 000007fe`f026c0a8 clr+0xc121
00000000`26b8f4b0 000007fe`f026c019 clr+0xc0a8
00000000`26b8f5b0 000007fe`f026c15f clr+0xc019
00000000`26b8f640 000007fe`f02f01ae clr+0xc15f
00000000`26b8f6a0 000007fe`f02ef046 clr!GetMetaDataInternalInterface+0x31c8e
00000000`26b8f830 000007fe`f02eef3a clr!GetMetaDataInternalInterface+0x30b26
00000000`26b8f860 000007fe`f03afcb6 clr!GetMetaDataInternalInterface+0x30a1a
00000000`26b8f8f0 00000000`76fc5a4d clr!CopyPDBs+0x44a2
00000000`26b8f930 00000000`770fb831 KERNEL32!BaseThreadInitThunk+0xd
00000000`26b8f960 00000000`00000000 ntdll!RtlUserThreadStart+0x21

I'm using two instances of Sound to play the game sound effects.
I'm need two instances, because sound events may be raised quickly, but the class Sound is able to play a single SoundBuffer simultaneously.

The code is here:
        private void PlaySound(SoundEffect sfx)
        {
            if (_sound.Count == 0 || !_sndMap.ContainsKey(sfx))
            {
                return;
            }
            ThreadPool.QueueUserWorkItem(state =>
            {
                var sound = _sound
                    .FirstOrDefault(arg => arg.Status != SoundStatus.Playing);
                sound = sound ?? _sound.FirstOrDefault();
                if (sound != null && _sndMap.ContainsKey(sfx))
                {
                    sound.SoundBuffer = _sndMap[sfx];
                    sound.Play();
                }
            });
        }

The dictionary _sndMap contains instances of SoundBuffer with pre-loaded OGG file (with duration 1-2 seconds).

Could you please help me to fix that issue?
I'm using .net framework 4.5.2 if it helps.
Thanks


Pages: 1 ... 12 13 [14]