Jump to content

  • Log In with Google      Sign In   
  • Create Account


We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Member Since 19 Aug 2002
Offline Last Active Today, 12:20 AM

#5199866 Visual studio 2013 (exe release) runs slower compare to VS2010

Posted by Nypyren on 24 December 2014 - 11:53 AM

If your code is using less than one full core, that means you're giving up CPU time to other processes.

Typical reasons why this would happen:

- Your process is voluntarily waiting for something (Sleep, GPU, disk I/O, network I/O, etc)
- Another process on the system is preempting you (this almost never happens to a noticeable degree on a system with that many cores...unless all of your other cores are in use, or you and another process have restricted your thread affinity to only one core)

Personally, I would investigate any uses of Sleep first.

#5199609 Is it possible to automatically download music in python

Posted by Nypyren on 22 December 2014 - 05:19 PM

If you intend to bulk download, make sure to put in a rate limiter of some kind. Many sites can detect high request rates and bandwidth spikes coming from a single user and may ban access from your IP address. Make sure to abort your script if there's any kind of unusual response - don't get stuck in a retry loop. That's the fastest way to get perma-banned.

A five or ten second delay between page/file requests makes such apps a lot more friendly towards sites.

#5199011 Easiest coding language?

Posted by Nypyren on 18 December 2014 - 03:55 PM

Some languages are great for beginners learning how to program, but bad for teams of developers trying to maintain large projects.

Dynamic typing is one of those things that is great for beginners, small projects, and single-programmer teams. Once you start dealing with non-trivial projects and large teams, static typing becomes much more important because it DRAMATICALLY increases the reliability and ease of maintaining a codebase.

#5198608 A Python Program that can Interpret a sentence (help)

Posted by Nypyren on 16 December 2014 - 03:08 PM

At the bare minimum, you need: http://en.wikipedia.org/wiki/Tokenization_(lexical_analysis)

Tokenization on English isn't too hard unless you need to handle input with lots of typos. Let's ignore typos for now. The fast-and-easy way is: Treat a continuous series of alphanumeric characters (also known as "word characters") as one token and treat all other characters as individual tokens. Discard whitespace after tokenization if it's not important to the rest of your code.

Tokenization for other languages (mainly those without spaces) is MUCH harder: http://en.wikipedia.org/wiki/Text_segmentation

So: "What's yours is mine, and what's mine is yours." would turn into:
NOTE: Contractions can be ambiguous. "I'd" could mean either "I would", "I had" and perhaps other possibilities. I wouldn't deal with them at this point unless they're completely unambiguous since you'll need a lot more information in order to decide which possibility is the most likely.

#5198476 How Do Terraria Animations Work?

Posted by Nypyren on 16 December 2014 - 01:59 AM

Lots of things are multi-sprite animations, but other things like swinging a weapon/tool just rotate a single sprite.

Complex things like worms or most of the bosses have a sprite for each individual part, each being individually positioned and rotated by code.

All of the animation is hardcoded into the game itself rather than being driven by the assets themselves. (hardcoding the amount of content that Terraria has is generally a terrible idea if you have non-programmers who want to add content - but hey, they shipped a successful game and made a ton of money, so shows what I know smile.png ).

You can actually make an XNA 4.0 project and load Terraria's XNB image files into it to view what they contain if you're interested in particular parts.

#5198434 I don't know how can I solve that problem in efficient way .

Posted by Nypyren on 15 December 2014 - 04:47 PM

I have no idea what collision algorithm would compute E before C in your example...

From the OP, I believe the code used right now is something like this:
foreach (other circle)
  if (line segment and circle intersect)
    handle collision;
    break; // may or may not exist in the OP's code, I'm just speculating.
, where the circle list is {circle e, circle d}.

The proper solution is to find *all intersections* first, DO NOT handle collisions yet, pick the intersection with the least amount of travel from the starting point, THEN handle only that collision.

#5198265 best way to send an receive multivarible data by socket

Posted by Nypyren on 15 December 2014 - 01:55 AM


I would recommend *against* using BinaryFormatter for a couple major reasons:

- There is a lot of per-serialization overhead (in the output data) that will DRAMATICALLY waste bandwidth unless your object graphs are large.
- The BinaryFormatter class itself is missing from most frameworks other than desktop .Net and Mono (in particular: WP8, WinRT and 360 cannot use it).

You can write your own reflection-based serializer, but it has a performance impact, and is kind of difficult to get it to handle all of the possible types that you might want to serialize.

The main alternative is using BinaryReader/BinaryWriter and a common interface on classes that use it. This is much more efficient at runtime but more tedious for the programmer (less tedious than dealing with the string-oriented approaches above, since you don't have to parse the values from strings back into numbers and error-check them first). The big thing to be aware of when using binary data transfer is byte ordering (endianness). This is pretty simple to deal with - you can create your own class that does what the BinaryReader/Writer pair does that keeps it consistent no matter what the host endianness is.

#5198255 Minimalist Programming Environment

Posted by Nypyren on 15 December 2014 - 12:54 AM

I'm talking about the software equivalent to going out into the woods and living off the land.

Fair enough. It sounds like you're embarking on a learning experience. But why a forum thread? How could we possibly contribute when you want to do something that nobody else is doing?

#5197678 Can't keep the car straight. Why on earth does this happen?

Posted by Nypyren on 11 December 2014 - 04:18 PM

C++ has a lot of major differences that could affect you.

The most likely difference in my opinion that would cause dramatic differences in behavior would be that C++ allows uninitialized variables. C# automatically initializes member variables to their defaults (zero, false, or null) and prevents local variables from being read before they're assigned. If you're porting from C# to C++, it's very easy to forget that you need to initialize everything explicitly.

If you forget to initialize a variable in C++, the variable can start off containing *anything*.

Another thing that is slightly different is casting behavior - C# is more strict about preventing implicit casting between different numeric values, and C++ is less strict. However, this normally only affects me when I'm porting code from C++ to C#, not the other way.

It might also depend on which floating point mode your C++ code is compiled with - precise, fast, etc. http://msdn.microsoft.com/en-us/library/e7s85ffb.aspx I'm not sure what C#'s equivalent is, but this may be a factor in accumulating math differences over long periods of time.

#5197539 how to know the number of different paths in a given graph

Posted by Nypyren on 11 December 2014 - 02:54 AM

I'll try to explain this in a less abstract manner (still using K4).

Your starting matrix starts out:
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
In this example, what each cell is saying at this point is "how many ways can I get from vertex X to vertex Y in one step?"

Multiply it by itself once, and you get:
3 2 2 2
2 3 2 2
2 2 3 2
2 2 2 3
At this point you have "how many ways can I get from vertex X to vertex Y in 2 steps?"

Notice that the diagonal cells have 3, and everything else has 2.

Let's double check to make sure the cells contain what makes sense...

The diagonals represent the number of ways you can go from a vertex back to itself in two steps. Since all edges are bidirectional, you can just follow an edge and then come back on the same edge. Since K4's vertices all have 3 edges, there are 3 paths.

The cells with 2 in them are because you must use 2 edges - if your first move was to go to the goal vertex, your second move would require you to leave the goal, invalidating that path. Since there are only two alternatives, there are only two paths.

So, everything checks out so far.

If you multiply a third time, you get:
6 7 7 7
7 6 7 7
7 7 6 7
7 7 7 6
Note: For this particular problem, you don't even need to multiply by a column vector like Alvaro suggests; you can just extract the desired [from,to] cell right out of the matrix itself, since that's what's going to happen any time you multiply by a column vector that has a 1 and the rest 0 (this extracts the column that the 1 corresponds to). Multiplying by a column vector IS necessary when you're trying to solve a more complex problem (such as a probability problem with a stochastic matrix).

So, the real question is: Why does the matrix multiply operation work on this problem? Let's take a look at what one step of matrix multiplication is doing. Let's go back to the 2-length path, multiplying the matrix by itself once, and look at two of the result cells.

For the upper left cell, the involved cells during multiplication are:
0 1 1 1     0 . . .     3 . . .     
. . . .  *  1 . . .  =  . . . .
. . . .     1 . . .     . . . .
. . . .     1 . . .     . . . .
The first step of multiplying is 0*0. This is essentially saying "There aren't any ways to go from vertex 0 to vertex 0, and then to vertex 0".
The second step is 1*1. This is saying "There's one path from vertex 0 to vertex 1, and one path from vertex 1 back to vertex 0, so combine them by multiplying them together and there's one total path."
(The last two steps are the same as step 2)
Then each of the four partial results are added together and put in the result cell.

For the non-diagonal cells:
0 1 1 1     . 1 . .     . 2 . .
. . . .  *  . 0 . .  =  . . . .
. . . .     . 1 . .     . . . .
. . . .     . 1 . .     . . . .
0 paths from V0 -> V0 in one step * 1 path from V0 -> V1 in one step = 0 paths.
1 path from V0 -> V1 in one step * 0 paths from V1 -> V1 in one step = 0 paths.
1 path from V0 -> V2 in one step * 1 path from V2 -> V1 in one step = 1 path.
1 path from V0 -> V3 in one step * 1 path from V3 -> V1 in one step = 1 path.
Total: 2 paths starting at V0 and ending at V1 taking 2 steps.

For the second multiply (paths of length 3), let's do the same thing.

Using our M^2 matrix and multiplying it again by M, let's examine the first two result cells again.
3 2 2 2     0 . . .     6 . . .     
. . . .  *  1 . . .  =  . . . .
. . . .     1 . . .     . . . .
. . . .     1 . . .     . . . .
There are 3 ways to move from V0 -> V0 in two steps, but no way to go from V0 -> V0 in one step, so no valid paths using this combination of steps.
There are 2 ways to move from V0 -> V1 in two steps, and one way to go from V1 -> V0 in one step, so two total paths.
(same for the remaining two options)
Total: 6 paths.
3 2 2 2     . 1 . .     . 7 . .     
. . . .  *  . 0 . .  =  . . . .
. . . .     . 1 . .     . . . .
. . . .     . 1 . .     . . . .
3 paths from V0 -> V0 in 2 steps * 1 path from V0 -> V1 in 1 step = 3 paths.
2 paths from V0 -> V1 in 2 steps * 0 paths from V1 -> V1 in 1 step = 0 paths.
2 paths from V0 -> V2 in 2 steps * 1 path from V2 -> V1 in 1 step = 2 paths.
2 paths from V0 -> V3 in 2 steps * 1 path from V3 -> V1 in 1 step = 2 paths.
Total: 7 paths.

This method works:
- On digraphs.
- On graphs with multiple edges connecting the same pair of vertices.
- On graphs with loops.

It does NOT work:
- If you need to exclude cycles.

I haven't tried proving it, but you might be able to modify the algorithm to discard cycles if you zero out the diagonal manually before each single-step matrix multiply. Maybe. I'll have to try it sometime and see if that actually works.

#5197253 Xbox 2 error #1

Posted by Nypyren on 09 December 2014 - 02:28 PM

(I will refer to it as XBOX 2 in every post from now on)

Please don't invent your own names for things when perfectly acceptable names already exist.

When I try to install it, I get the error in my image... I have no idea how I can resolve this error.

1. Google for the thing you're trying to install + the error message.
2. Find a result that matches what your problem is.
3. A solution should exist that explains what to do.

The error message you're seeing typically means you're trying to install a patch when the product to patch has not been installed yet.

#5196182 Weird stuff happening when stepping through a threaded code

Posted by Nypyren on 03 December 2014 - 10:18 PM

Generally if you have access to the more recent versions of .Net, you should be using stuff from the Task Parallel Library ( http://msdn.microsoft.com/en-us/library/dd460717(v=vs.110).aspx )

If you're using older versions of .Net, what you're doing sounds like it would work with ThreadPool.QueueUserWorkItem ( http://msdn.microsoft.com/en-us/library/4yd16hza(v=vs.110).aspx ) pretty easily.

#5196155 Default font texts from windows

Posted by Nypyren on 03 December 2014 - 05:44 PM

No, the fonts included in Windows are not for distribution in your own software. However, if your program does not distribute the fonts and simply accesses ones already installed on your customer's computer, that's fine.

If you need distributable fonts, you'll have to either license some from a vendor or find some free ones, such as the ones here: https://code.google.com/p/ankidroid/wiki/FreelyDistributableFonts

#5195619 I am all prepared to get into game development, how do I start then?

Posted by Nypyren on 30 November 2014 - 09:58 PM

Another update: The Express editions have been superseded* by the Community edition (as of earlier this month).

* Unless you are using the Express editions in large commercial teams due to its unrestrictive license...

#5195612 *. not the same as ->

Posted by Nypyren on 30 November 2014 - 09:11 PM

Programming languages use FORMAL grammars. You can't just throw arbitrary tokens together like you can in English and have the compiler figure out what you mean.

* and . have different operator precedence. Exactly like addition and mutliplication.
a*.b      // completely illegal
*a.b      // access a.b, then dereference the result.
(*a).b    // dereference a, then access member b of the result