Jump to content

  • Log In with Google      Sign In   
  • Create Account

Olof Hedman

Member Since 24 Aug 2011
Offline Last Active Yesterday, 03:15 PM

#5293048 c++: sprintf but return chars. Possible?

Posted by Olof Hedman on Yesterday, 07:11 AM

If we reinvent std::string, you can get half way there :P

 

Or, you could just ignore the extra copy and just use std::string.

Here's a c++11 templated version I'm using.

template<class... Args >
std::string makeString(const char* format, Args&&... args) {
  char buffer[256];
  int len = snprintf(buffer, 256, format, std::forward<Args>(args)...);
  if(len >= 256) {
    // if string is too long, try again with a bigger buffer
    char buffer[len + 1];
    snprintf(buffer, len + 1, format, std::forward<Args>(args)...);
    return buffer;
  }
  return buffer;
}

.

 

 

 

Edit: Hmm. Maybe I should read the topic more carefully before answering. Oh well, I'll leave this here anyway. Back to work and getting stuff compiling I guess...




#5290800 Colorimetry: Violet

Posted by Olof Hedman on 09 May 2016 - 08:31 AM

 

Wouldn't that mean that in RGB to see violet we would need values of R40%, G40%, B90% ?

(while in reality violete is more like R40%, G0%, B60%)

 

 

RGB really has quite little to do with the peak of the response curves, it is just a simplification that covers the perceivable color spectra reasonably good.

Both the "red" and the "green" cones are quite close to each other, and most of the colors they are sensitive to is really in the "green" to "greenish yellow" part (very useful if you live in the woods)

A surprisingly big percentage of the human population can't even see the difference between red and green, they only have one type of cone in this part of the spectra.

 

Seeing red is of course very beneficial to spot ripe fruit in said woods, but it seems you can do well without it.




#5289862 Hiding Company Nationality

Posted by Olof Hedman on 03 May 2016 - 03:49 AM

Ok, hiding your nationality could matter if you want to market yourself in a region who happens to be bigoted against your nationality.

(regardless if you are a US guy selling in Russia, or a Pakistani selling in India)

I guess that might be a bigger or smaller problem depending on what nationality you have...

 

But when you sell your game in literally every single country in the world (yes, even that tiny African country), this fixation with nationality just seems curious and outdated... I'm sure most people in the industry just don't care, they are used to working with people from all over the world in different capacities.

 

So that's why they don't show a huge flag and whatever national animal they like on their front page, they just write "Here is our software", and if anyone really cares (like they want to visit or something) you can just check the "about us" page and see an address, or check company registration, or just ask...




#5289711 Hiding Company Nationality

Posted by Olof Hedman on 02 May 2016 - 06:03 AM

Do you think the nationality of the developer can affect the initial perceived quality of a piece of software?

 

I'm sure it _can_.

In most cases though, the nationality of the developer is totally irrelevant, and not something the end user cares about.

I'm sure most gamers doesn't even know the name of the developer of many of the games they play. (or they think the game developer is named "EA")




#5288888 what is meant by Gameplay?

Posted by Olof Hedman on 27 April 2016 - 02:54 AM

 

Not necessarily -- its true that many scripting languages are compact or have features (e.g. actor-model, prototypal inheritance model) that lend themselves to scripting game entities and game interactions, but that does not mean that writing gameplay code in C++ has to more difficult or more verbose for the people "scripting" the gameplay elements, albeit in C++.

 

Many custom scripting languages are basically just stripped down C-syntax anyway.  :)

 

There is no reason you _have_ to use a scripting language.

 

From my view, as a small scale developer with our own engine, I've always seen adding a scripting language as just unnecessary extra work and more stuff to maintain.

Our engine needs a proper C++ API anyhow, so why spend the extra work adding another API, which most likely will just be a subset of the engines true capabilities.

 

Also increases the work to add new features.

Plus you have an extra layer of code that can introduce bugs, while it also often makes debugging harder.

And when you try to push the boundaries of what the scripting language is capable of, it can get messy...

 

I imagine the cost-benefit will be better in a larger organisation where you have a lot of people that need to implement game specific stuff, and you also have a support organisation to keep the scripting language with enough features and debugging tools to be useful.

 

With just a few people, where everyone is part engine part game implementers, and everyone already know C++ well, there is little reason to use a scripting language.




#5286848 Simple code for reading and writing file in UTF-16 mode

Posted by Olof Hedman on 14 April 2016 - 05:55 AM

The problem seems to be std::endl outputting ascii line endings instead of UTF-16 encoded line endings (notice the missing 00 between them, which is there in the input).

 

This makes the whole string get shifted after it, so all code points are no longer aligned to word boundaries. Only reason the second line works at all is because there is two line endings after the first line making the string aligned again.

 

Unfortunately I have no idea why std::endl would behave in this way when you have set the locale on the stream...  I would expect that to work, but I don't know, since I haven't used UTF-16 strings much, I usually have my strings in UTF-8.




#5286636 I need a book (or somebody's project source code) which properly explains...

Posted by Olof Hedman on 13 April 2016 - 05:37 AM

Jazon Yamamoto's book has very elaborate example code - there's a space shooter game included - but the code is spread over 20 or 30 files. I can find a function prototype but then I struggle to find the function call. It's an expertly written program structured to be extendable, not structured easy to understand - "easy" would be poorly structured, with nearly everything in one or two files.

 

I think you should give Jazon's code a bit more of your effort.

I havn't looked through it, but I highly doubt it isn't written to be easy to understand, since it is example code from a book.

20-30 files is a quite small C++ project, and you should be able to wrap your head around it if you just try a bit harder.

It is normal to have 2 files per class in C++, so that should just be 10-15 classes. 

Really not that much.

 

(As a real world example, our latest iOS game, which is on the small and simple side (even though the graphics are gorgeous), has approximately 300 source files, and that is just application code, there are another 900+ files in our engine library it uses)

 

If you have problems finding stuff, learn and use the functions in your IDE that are there to help you with exactly this. You have shortcuts to jump to definitions and declarations, and if that is not enough, just open the search and search for it in all files in the project. Then you are guaranteed to get all places where the function/class/variable in mentioned.

Pen and paper can also be useful when mapping out and trying to understand source code.

 

Copying and pasting stuff and permutate it until it "works" is a horrible idea for any programming, and for C++ in particular.

Learn how it works, and you will be writing much less error prone code much faster.

 

Programming is like a puzzle game, or LEGO. Lots of pieces that can fit together in multiple ways, and in many cases there is not one "right" answer you can google up. You just need to understand what you want to do and what pieces are available. Then put them together in the way you choose.




#5286462 programming language for android.....

Posted by Olof Hedman on 12 April 2016 - 06:30 AM

 Just about every survey I can find shows that C++ usage has been declining for years.

 

 

Do you have any references to those surveys?

I'm interested to know if they compare it in absolute or relative numbers.

 

With so many "new" languages and frameworks being invented for many reasons, I don't doubt C++ is declining as a percentage of total development done.

But at the same time, programming in general is increasing a lot, so I also suspect the number of C++ projects in absolute numbers are actually increasing, and not decreasing.

 

And as others have said, C++ is still the language in existance today that is most likely to be around in 10, 20 and possibly 100 years (unless AI programmers have taken over by then, but even then, they'll probably still maintain a few C++ projects..)




#5286270 Access violation reading location 0xDDDDDDDD.

Posted by Olof Hedman on 11 April 2016 - 04:44 AM

How are you creating and using the Sprite class?

 

The bitpattern DDDDDDDD in all variables means the whole Sprite object was deallocated before you tried to use it. (-572662307 in decimal is also 0xDDDDDDDD in hex)

 

So it seems you are keeping a pointer to a Sprite object after the object went out of scope.

 

(This is only true for debug builds. Debug memory allocators commonly write bitpatterns like this when deallocating objects to make errors like this crash faster and be easier to find)




#5286263 programming language for android.....

Posted by Olof Hedman on 11 April 2016 - 03:32 AM


With the likes of xamarin there is actually no requirement to write any Java at all, the same with using xamarin for iOS you do not have to see a single line of objective-c 

 

That is actually true for C++ too, on Android, using the NativeActivity.

 

Of course, to actually ship a quality product, you'd likely need a bit of Java/obj-c code.

So it is a good idea to understand how the interaction works, so you can extend it when needed.

 

Regardless of which language you choose to do your main development in, there will always be some Java code involved on Android, and some Obj-C code involved on iOS.




#5285225 Is it bad to use macros such as __LINE__ or __DATE__?

Posted by Olof Hedman on 05 April 2016 - 04:14 AM

As BitMaster says.

 

Which leads me to ask: What do you think these macros do exactly? I feel there is some confusion here.

Those macros are just used for testing and debugging, and not really useful for the actual application. (why would an end user be interested in what line in a source code file a printout happened at, or when the app was compiled?)

 

Absolutely not a bad idea to use them, if you feel you need to embed that information to help you track down errors.

Just make sure all the compilers you want to use to compile the source code support the ones you use.




#5283914 How much Maths/Physics do I have to know?

Posted by Olof Hedman on 28 March 2016 - 02:20 PM

Matrixes, dot and cross products are your greatest tools for programming games, and generally solving geometry problems in 3D space (and beyond)!

Definitely learn them, and learn them well! :)




#5281876 how could unlimited speed and ram simplify game code?

Posted by Olof Hedman on 18 March 2016 - 10:37 AM


turns out AlphaGo's move was totally brilliant

 

Its also interesting to note that in the game where the human won, Lee Sedol made a move that AlphaGo calculated at 1/10000 chance of being played, which also turned out to be a brilliant move.

AlphaGo likely hadn't explored that path properly, and did a few bad moves in response, which guaranteed the win for Lee




#5281872 how could unlimited speed and ram simplify game code?

Posted by Olof Hedman on 18 March 2016 - 10:15 AM


Go is about image pattern matching and pattern recognition, not pathing.

 

Well, choosing the right move through the different possible states to arrive at the highest probability to win is a pathfinding problem.

The problem is the graph is too complex for regular pathfinding algorithms.

 

The way they tackle this pathfinding problem is the same way as humans do, which is image recognition and experience to select which paths to explore.

 

I highly recommend watching the games, they are commented by a very proficient go-player, and they have guys from the AlphaGo team as guests, which give a lot of really interesting insights both into the game of Go and how the AlphaGo team tackled it.

 

To go into a bit more detail, they actually use two different NNs, one to chose which moves are plausible, and another to evaluate the board position (another really hard problem). But maybe we are derailing the thread now smile.png




#5281844 how could unlimited speed and ram simplify game code?

Posted by Olof Hedman on 18 March 2016 - 07:06 AM


Yes of course, but you do not need to explore every possible move throughout 400 turns in order to win against a human, do you? I don't play Go, so it's a bit difficult to tell for me, but what do you think the average master Go player's brain capacity allows for? 20 moves ahead? With 3-4 possible alternatives at each node? That's a lot of thinking, and a lot to remember, I don't think I could do that.

 

No, but the trick is to evaluate the _right_ moves. Just randomly selecting a few to evaluate does not work, as shown by the failure of monte carlo based go players.

 

Apparently pro go-players report that a lot of their decision making comes from an "intuition" of where it is a good idea to play. They then focus their analysis to these moves.

This intuition comes from massive experience of playing the game from a very young age.

It is not that far fetched to believe that a well trained neural network can do the same, which is what Google has shown to be true with AlphaGo.






PARTNERS