Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Sep 2011
Offline Last Active Today, 02:13 PM

#5258098 C# Float text format in other countries

Posted by lwm on 20 October 2015 - 08:07 AM

You can set the default culture for a thread:

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#5256487 Basic constant buffer question

Posted by lwm on 10 October 2015 - 12:15 AM

Yes, the last SetShader call will determine what shader will run. Methods like SetConstantBuffer bind things to the pipeline (device context), not a specific shader.


You can do this for example and both draw calls will use the same constant buffer:

SetConstantBuffer(0, B1)

#5255834 Possible to read back vertex from GPU?

Posted by lwm on 06 October 2015 - 10:29 AM

Tessellation happens before the Geometry Shader, so I'm pretty sure you can use the Stream-Out stage to write your tessellated mesh to a buffer and read that back to the CPU.

#5254470 Need help for game. C#

Posted by lwm on 28 September 2015 - 02:13 PM

I don't really understand what you mean by the "C# framework" and you can't really put XNA and Unity in the same category. XNA is/was a framework while Unity is an entire ecosystem.

If you want a useful answer you will have to tell us what you're aiming for.

#5249825 How to Set Pixel Shader Constants

Posted by lwm on 31 August 2015 - 12:10 AM

The idea is to create one buffer per update frequency. So for example, one buffer for all the parameters that change only once per frame, one buffer for parameters that change occasionally and a buffer for parameters that change with every draw call.


Each cbuffer in HLSL essentially declares a struct. You then duplicate that struct in C++ and fill a buffer with that data. The memory layout of the HLSL and the C++ struct have to be identical, so watch out for the packing rules.

#5223502 Why high level languages are slow

Posted by lwm on 15 April 2015 - 01:23 PM

This discussion is soooo old smile.png


The project I work on at my day job is *very* large scale. Some parts of it have hard real-time requirements and are basically written in C with classes. Some parts are C++ because they are compute-bound. But the majority of the components is written in C#, because performance simply isn't the top priority, productivity is.


Use the right tool for the job and be done with it.


Most developers I meet every day are entrenched in "their" world, but I love switching between the worlds and the languages. Spend the morning writing "fast" code, go to lunch and then switch over to writing "nice" code. What really annoys me though, is the fact that everyone and their dog calls themselves a "C# developer" nowadays after reading a few tutorials. It's sad to see so many programmers being completely oblivious of all the nice aspects of the "high level" languages that we willingly paid for by sacrificing performance.

#5218347 String: How to find the most common character occurrence.

Posted by lwm on 22 March 2015 - 04:56 PM

Unless there are predetermined performance constraints, I would always go for a simple solution first:

private static string GetAnyMostFrequentCharacter(string input)
        throw new ArgumentOutOfRangeException("input");
    var group = input.GroupBy(c => c).OrderByDescending(g => g.Count()).First();
    return string.Format("<{0}, {1}>", group.Key, group.Count());

Or to get all most frequent characters:

private static string GetAllMostFrequentCharacters(string input)
    if (!input.Any())
        throw new ArgumentOutOfRangeException("input");
    var groups = input.GroupBy(c => c).OrderByDescending(g => g.Count());
    var firstLargestGroup = groups.First();
    var allLargestGroups = groups.Where(g => g.Count() == firstLargestGroup.Count());
    var stringBuilder = new StringBuilder();
    foreach (var group in allLargestGroups)
        stringBuilder.AppendLine(string.Format("<{0}, {1}>", group.Key, group.Count()));
    return stringBuilder.ToString();

#5201877 Server socket with select, thread pool and queue based approach

Posted by lwm on 05 January 2015 - 02:08 AM

Now lets say as you said, fd1 is currently in process and meanwhile we get the data from fd1 again. Again that fd1 will be added in deque in main function and any thread whichever is free can consume that. If all threads are busy in processing, we will be keeping that fd1 in deque.  

What exactly is "fd" referring to? Did I accidentally skip over an explanation somewhere?

rip-off already mentioned that a single receive-call does not necessarily correspond with one single logical request. You may need multiple receive-calls until you have a full request. Or you may receive multiple requests (the first and last ones possibly being incomplete) with one receive call.


You mentioned 100 concurrent clients. Is that a realistic goal?

If so, using blocking IO calls is probably not a good idea. Use asynchronous IO wherever possible.

I just finished implementing a diagnostics server with soft real-time requirements at work and was pleasantly surprised how elegant the whole thing became once I left all the nasty waiting and blocking to the software that does it best: the operating system.

Is boost::asio an option for you?

#5186887 Example code wanted for Broad Phase Collision Detection.

Posted by lwm on 14 October 2014 - 05:28 AM

There are many ways of implementing a broad phase and there is no single correct way. It depends on many factors like whether you're in 2D or 3D, the number of entities, the average distance between entities, whether most of them are static or dynamic, etc. You could try:


  • Brute Force: This can actually be a good choice for a reasonable number of entities if you can make your data structures cache-friendly.
  • Spatial Partitioning: There are many examples on Quadtrees and Octrees out there.
  • Spatial Hashing: Good for many moving entities since reinsertion is fast, but has other drawbacks instead.

I've been using BepuPhysics for some time now. You can look at the source code at CodePlex.

#5175210 Destructor in vector called too often

Posted by lwm on 21 August 2014 - 03:21 AM

Would still be nice though if anybody with visual studio 2013 or the 2012 November compiler CTP could also test the code and confirm that this is happening for him too.


I'm sorry to say that I can't reproduce the problem with Visual Studio 2013 Update 2.

#5174628 How can I display Unicode characters like "ä" or "语" in my game?

Posted by lwm on 19 August 2014 - 12:40 AM

DirectWrite uses a 2D render target. I don't know if and how I can use this for a 3D game with a 3D render target...


Combining DirectWrite/Direct2D with D3D11 is definitely possible. I used them both for a project a while ago (it used SharpDX, but that doesn't really make a difference). Unfortunately, I don't have access to that project right now.


SpriteFont uses Windows 8.1 SDK and DirectX 11.1 math. Will it work with Windows Vista, Windows 7 and Windows 8(.1) and on graphic cards that only support DirectX 11?

DirectXTK should be usable on all platforms that support DX11 (you can still use a lower feature level). According to the Codeplex page, Vista SP2 and higher are supported.


And is there a way to get the size of the text before it is rendered? I need to know the width of each word (or letter) to implement scrolling, so how can I do this with DirectWrite or SpriteFont?

SpriteFont provides a MeasureString method that returns the size of a given string in pixels.

DirectWrite allows you to do get all kinds of information on the text to be rendered and implements many formatting options.

#5174440 How Would You Make A Quad Based On a Direction in 3D.

Posted by lwm on 18 August 2014 - 07:26 AM

Some pseudocode: 

dir = normalize(target - start)
up = (0, 1, 0)
halfSize = size / 2

// todo: handle case when (dir == up)
o1 = cross(dir, up) * halfSize
o2 = cross(o1, dir) * halfSize

p1 = start + o1 + o2
p2 = start + o1 - o2
p3 = start - o1 - o2
p4 = start - o1 + o2

#5174436 How can I display Unicode characters like "ä" or "语" in my game?

Posted by lwm on 18 August 2014 - 07:09 AM

What about DirectWrite?

#5173833 [SharpDX] Unable to render texured models using BasicEffect

Posted by lwm on 15 August 2014 - 03:06 AM

When you inspect the loaded model in the debugger, what do the InputElements in the VertexInputLayouts look like? Do they include a "TEXCOORD" element? If they don't, are you sure that your model contains texture coordinates?

The SharpDX Toolkit automatically chooses an appropriate Vertex struct and corresponding VertexInputLayout for you. If there is no InputElement for texture coordinates, the model compiler probably wasn't able to find any texture coordinates in the source model.

#5173812 [SharpDX] Unable to render texured models using BasicEffect

Posted by lwm on 15 August 2014 - 01:33 AM

When you set TextureEnabled to true, BasicEffect will switch to a version of the shader that expects your vertices' texture coordinates to be in element "TEXCOORD0". However, according to the error message, your vertices don't provide any coordinates with that name. How are you loading the model and what vertex type are you using? If you're using a custom one, maybe you forgot to add the attribute to the struct's field that holds the texture coordinates?