Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Dec 2004
Online Last Active Today, 08:09 PM

#5314477 Why didn't somebody tell me?

Posted by on 09 October 2016 - 06:42 PM

Also, at least in explorer, in the tree view, pressing left repeatly closes the folder you're in (if it's expanded) or moves to the next parent (if it's closed).
Alt-Numblock-* will open the next level of all sub folders under the selected one.


Whooa, this one is nice! Appears to be standard treeview controls too, works in an app I work on as well, except it appears to do fully recursive expansion. Not recommended on unlimited dynamic nodes..

#5314409 DirectX C++ DLL for C# Problem?

Posted by on 09 October 2016 - 08:28 AM

BadImageFormatException tends to mean you are trying to load a 32-bit dll from a 64-bit process or the other way around, so start by making sure you are not doing that. For example, using Any CPU in your C# project means your process might be 32-bits, it might be 64 bits. If you need to use Any Cpu, you'll need to compile your native dll for both 32 and 64 bits, then use the one that makes sense at runtime.

#5313645 What's it called when you resize an image to dimensions that are not a fa...

Posted by on 02 October 2016 - 06:51 PM

Stretching? Sampling is a popular method for doing this, with some form of interpolation/filtering. Point aka near filtering means you pick the color of the closest pixel, linear filtering means you do some form of interpolation between the closest pixels.


Most engines, frameworks and/or graphics libraries will provide you with methods for this built in, so what are you using?


Edit: The easiest way to get good results might be to draw the map using a fixed predefined size onto a new image/buffer, then stretch that one.

#5313355 When should I use int32_t rather than int

Posted by on 30 September 2016 - 02:50 AM

I see your point now and while I agree I also think it is a bit of a strawman argument.  When the architectural differences are that large you end up having to write completely different code for the platforms.  You just can't use the least common denominator code in such a case because it will typically perform horribly on one or the other platform until you just bite the bullet and write code to the target specifically.  Some things will be shareable, but I just don't believe it would be enough to justify the added work involved to attempt it beyond the trivial.


Let's say we are working on a library, maybe for parsing a new awesome image format, maybe for scripting. It needs to be portable. Now, I'd use well defined types all across the board here, since I'd much rather have consistent but potentially slow behavior across all platforms than better performance with (rare) bugs that I cannot reproduce on my primary development platform. It's likely that I may need to hand optimize/rewrite certain parts for certain platforms in the end, but now I at least know where and when I need to do that. I have a base on which to profile and a reference implementation that users can fall back to in case they encounter bugs with my optimized implementation.


Basically, I default to consistency and opt out to speed when safe or needed, instead of defaulting to speed and opting out to consistency for specific algorithms/formats.

#5313296 When should I use int32_t rather than int

Posted by on 29 September 2016 - 03:11 PM

It is unlikely the compiler would actually choose an int16_t, that may have been a poor example .  On the other hand, the optimizer is allowed to do quite a few things which might surprise you if you look at the generated assembly.  Usually the peephole optimizer can be allowed, under verified safe conditions, to modify types as it see's fit.  A simple loop as described is an obvious case that it can look at and decide if the size can be modified to provide smaller or faster code depending on your compile settings.  Typically the constraints are that the code does not ever assign to the loop value and that the loop declaration is idempotent.  In such a case, on a 64 bit target, it can change from 64 to 32 bit or the other way around as most appropriate.  Like I said, using 16 bit was probably a bad example.  


I think you misunderstood me. Disclaimer: I have not actually looked at any compilers to verify my claims here so I might be dead wrong, but the rest of this post describes my current understanding/impression/whatever.


For a particular compiler, platform and settings combo, 'int' is well defined to a particular size, such as 32 bits. The behavior of the program will match that size across the entire project (assuming you don't compile different files with different compilers or settings). On that particular platform/compiler/settings combo, where 'int' is 32 bits, using 'int' or 'int32_t' will be identical and give the compiler the exact same optimization opportunities. For storage, it will be 32 bits. For operations, it might use 16 bits, it might use 64 bits, as long as the end result is the same as if it was done in 32 bits. The difference comes when you switch to another platform, such as an Arduino or similar. Now, on this new small target, 'int' will be defined to be 16-bits, and the behavior of all int math will be that of 16-bit ints. The compiler may still choose to use 32 bits if there's a scenario where it would be faster, but it must ensure that the behavior remains that of 16 bits. This means that when using 'int', the behavior of the program can change across targets/platforms. If we were to use 'int32_t', the behavior would be the same on both targets, but likely incredibly slow on the small target. When using 'int32_t', the compiler may still choose to use 16 bits on the small target in all cases where it can ensure that the behavior matches that of 32 bit types/math/whatever. The same can go the other way as well, a specific target/compiler combo might decide that the size and behavior of 'int' will be that of 64 bits, and use that across the whole project.


For cases where I might actually want this change in behavior across platforms, I'd use a custom typedef so that I can control it and put a more explicit "I know what I'm doing" stamp on it.

#5313130 When should I use int32_t rather than int

Posted by on 28 September 2016 - 05:51 PM

How would I detect a scenario where there is a performance difference between the two?

You would have to use some form of profiling tool or perhaps a code analysis tool to find such performance problems.
I personally recommend using typedefs for things like status codes so that you can easily optimize for particular targets if it becomes necessary (it probably won't!).


If you are targeting "big" cpus like those in computers, phones, tablets, consoles etc, 'int' will almost always be 32 bits and the performance impact of using the "wrong" size will be negligible unless you are processing large arrays of data. I'd be more worried about memory usage and cache efficiency on those platforms. If you really do want to go for optimal performance, I still recommend using typedefs to the well defined types (such as int32_t) and manually selecting which ones to use for a particular task on a particular platform. I much prefer to have consistent behavior across all (potential) targets over optimal performance, but this is a personal preference that is far from universal.
Selecting the "right" type matters a lot more if you are targeting small processors/microcontrolles, such as Arduinos and similar. Those platforms tend to have small amounts of really really fast memory (1-512kb or so). The effect is that the relative impact of every non-memory access instruction is much bigger, so if you use a 16-bit int for a processor that can only work with 32 bits, the performance can suffer greatly (as in a single operation might take 3-20 times as long). On "big" cpus, the memory tends to be so slow that a couple of extra non-memory-access instructions makes little difference.

You should only specify the size when it actually matters and let the compiler do the work of figuring out the best size as much as possible.  The places specific sizes will matter vary but an incomplete list would be things such as file formats, network IO, talking to hardware at a low level and various other relatively uncommon tasks.  So, for instance:

  for (int32_t i=0; i<10; ++i)  // Don't do this.  

instead use:

  for (int i=0; i<10; ++i)

I disagree with this. If you suddenly compile for a platform where int is 16 bits, you may end up with all sorts of weird and hard to find bugs. This has actually happend to me. I've always considered the part where int/long/etc are compiler defined to be an incredibly flawed design decision. It's supposed to help with portability, but in my opionion/experience it does the exact opposite since the same code might behave completely different on another target. Anyway, this is a rant that most C/C++ people won't agree with and that is off topic, so I'll just leave it at this.

#5313115 When should I use int32_t rather than int

Posted by on 28 September 2016 - 04:03 PM

int/short/long etc might use a type that is faster for that particular target, potentially causing your application to behave differently. Using int32_t etc will make the behavior consistent, but possibly sacrifising performance in doing so. I highly recommend focusing on correct/consistent behavior until you find a specific scenario where it makes a large difference in performance without causing bugs.


A typical example of where one might want to use int instead of int32_t is for function returns that just return a status code of some sort. In C, you don't have bools, so you use int instead. In that case, int would be better than int32_t, but for storing actual data, I highly recommend picking a type that fits that data.

#5312984 Coding-Style Poll

Posted by on 28 September 2016 - 03:04 AM

I think I'd be more productive with the style I'm most comfortable with, but as long as the IDE can support the style properly, it shouldn't be too much of a problem.


For example, I use ReSharper which automatically reformats code on paste, semicolon and closing braces. If I can configure it to match your style, then I can work with it. Same thing with naming, if I can set it up to detect incorrect naming etc, then it's probably fine. It needs to work well with intellisense though. For example, if there's a member named m_someProperty, intellisense should be able to list it when I type m_s.., som.., sp.. (acronym) etc. As long as you have VAX and/or ReShaper, that's typically fine.

#5312939 Biome based map generation?

Posted by on 27 September 2016 - 06:40 PM

Perhaps I could use a regular grid of points, then use some form of noise to move those points around a bit (something like up to half the distance between two points). Using that, I should be able to figure out the closest point for a given X,Y pair and sample that point on another noise map to figure out a biome id..

This approach seems rather promising at the moment. I just need to fix the borders, control the frequency of biomes and add some more data (ie. height multiplier, turbulence multiplier, ..) to the biome types so they become more interesting.

Attached Thumbnails

  • z-out-636106268085331483.png

#5312826 Coding-Style Poll

Posted by on 27 September 2016 - 07:31 AM

I think every project/codebase should have a defined style all the way through.


I'm just sooo happy I work in C# where there's basically one universally accepted naming convention and one almost universally accepted formatting convention. Sure, there are differences between projects sometimes, but the differences are typically negligible compared to many other languages. 

#5312818 Why no Liero remake?

Posted by on 27 September 2016 - 06:53 AM

I wont do this, but why didnt anyone do it so far?

Liero was a simple yet VERY fun game to play with friends. A modern version with better graphics, effects and maybe more polished weapons selection while retaining most of the original gameplay would make a lot of sence.


So why do you think this hasnt been implemented? Design-wise its a splendid game.


Umm. Gusanos? LieroAI aka LieroSDL? There was a game with squirels, same concept (WarKurre or something). LieroXtreme, NiL, YALC, .. There was one with pretty good graphics and stuff, but that was rather unpopular with the Liero community since the jump was animated and not instantaneus.. NiM2 I think. There was a VB game called something like Nex7+. Soldat was popular with the community and IIRC developed by a member of the Liero community. A friend of mine made an Android version for some school project.


There has been tons of them, it's just that the genre isn't that popular. Local multiplayer is pretty much for consoles only these days, and Liero type games are very difficult to sync over network due to large amounts of objects and large butterfly effect type problems.

#5312580 Visual studios 2010 debugger variable doesn't update

Posted by on 25 September 2016 - 06:07 PM

Can you restart VS and do a clean + rebuild all?


Edit: Things like this tend to happen when builds fail and you run an old executable or something. Also, if you have an antivirus solution, check if it has any issues with your program.

#5311894 Biome based map generation?

Posted by on 22 September 2016 - 07:29 AM

Hi everyone!


I'm working on an RTS where I want to generate maps. The concept of biomes are very important as some buildings can only exist in some biomes etc. What are some of my options here?


I've found tons of articles, tutorials, samples and libraries, but almost all of them use a height map to determine biome. This gives reasonably realistic results etc, but boring since certain biome types will always be next to eachother. I want a technique that can result in a mountain with a lake to the north, a forrest to the west and a dessert to the right.


My current generator uses a fixed size tile map, randomly places some biome "centers" on it, then does an incremental flood fill to spread these biomes. The results are rather nice, but it's extremely slow and does not support expansion.


How does games like Minecraft do this? What are some other options?


* It must support populating a presized tilemap at the very least, but ability to seamlessly expand is a big plus

* Control over biome density is a huge plus. Some are supposed to be rare, others are supposed to be common, all players need reasonable access to some etc.




#5311516 Why C# all of a sudden?

Posted by on 19 September 2016 - 05:03 PM

C# is a really powerful and expressive language that can easily interop with other .NET languages as well as C. It has really good development tools. Performance wise, it's not as fast as optimized C++, but for a lot of use cases it's more than fast enough (faster than many alternatives) with some serious stability and security benefits. It's typically very hassle-free compared to Java and many other solutions on Windows, which is the platform of choice for most gamers and probably also game devs (though this seems to be changing rapidly).


Java was designed with various academic values and best-practices in mind, where C# was designed as a more practical language for real world scenarios. For example, C# has unsafe and P/Invoke integrated into the language. This makes it very good at interfacing with existing code, but is arguably unclean. C# also has both value types and reference types with the same syntax. This can be confusing and is arguably also "ugly", but extremely practical when trying to interface with native code and/or trying to control memory layouts. For things like vector math, vertex arrays and tile maps, this can make a huge difference.


C# has been embeddable since an early age, making it easy to use as a scripting language. It's very easy to use for tools that interface with whatever engine you are using. The overall cross platform support is probably worse than Java etc, but it's good enough on all platforms that are relevant for games.

#5309502 Faster Sin and Cos

Posted by on 05 September 2016 - 05:11 AM


But your link is broken.

Works for me (just tried).


It's broken for me too. You probably have cookies on your system, if you look at the link you can see that the url does not contain any names or IDs, so there's no way it could identify your snippet. The ideone link works though. :)