Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Olof Hedman

Member Since 24 Aug 2011
Offline Last Active Today, 03:58 AM

#5226815 Learning programming well

Posted by Olof Hedman on Yesterday, 03:19 AM

I didnt know that once, and I used if...then...else with more than 15 options...
If I just code and code and code I cant really learn new commands?! Why should I think of using a select case command if I know if then else?


Don't worry about it :)

No-one knows everything, and you are just starting out.


Write code, get stuck, look for solutions, read others code, write some more code, throw everything away and start from scratch because the code sucked, write more code, ,google, write code, read a book, write code, read on forums, write more code, and then write some code.


Its the normal way of programming.

Before you know it, you know everything you need to know.

#5226080 Random Number Generation

Posted by Olof Hedman on 28 April 2015 - 09:10 AM

How can it be cryptographically secure if iy's only pseudo-random?  That doesn't sound secure at all!



#5226065 Is it necessary to license your game?

Posted by Olof Hedman on 28 April 2015 - 08:17 AM

The main confusion here comes from that you use "licence" incorrectly.


What your composer asks you to do is not to "license your game" (well he might, but then he too isn't using the word correctly), but he ask you to "licence the music (for your game)"


Licensing immaterial goods like music and software means getting permission to use it.

#5225845 Why Does Everyone Tell Newbies To Make Games?

Posted by Olof Hedman on 27 April 2015 - 08:22 AM

The whole point of giving a task, of reasonable size, is that it is easier to focus your learning if you have a task that needs to be fulfilled.


It's the basis of "Problem Based Learning".


Pong is about as simple as you can get, but still have something that classifies as a fully interactive graphical game.

You can also build upon it pretty far, to learn even more. (make it an arkanoid clone)


I would say it can be excellent to do in Unity, to learn the ropes of what is existing in the Unity framework. or Unreal. or any other engine.

You'll just learn other things then if you do it in SDL or SFML.

#5225822 Android game resolutions

Posted by Olof Hedman on 27 April 2015 - 06:44 AM

Welcome to developing for mobile devices smile.png

Unfortunately it doesn't have a universal solution, specially if you try think about all devices (there are even devices with square screens!)


Stretching never looks good, so no-one uses that (I hope)

I think the most common way is your no2, show more of the world, just as you say, make sure to show parts that doesn't affect the gameplay. (too much)

Some games, rather then letterboxing, adds "decoration" outside. I think this works best with puzzle style games.


As for what base to use, I'd recommend using an aspect ratio around 16:9 as a base, since many of the most popular phones use that.

#5225192 box2d pixels per meter scaling

Posted by Olof Hedman on 24 April 2015 - 03:01 AM

Moving Box2D objects should be about 0.1 - 10 meters big in order to run a stable simulation. Hence, their FAQ strongly discourages 1:1 pixel to meter conversions so I would not recommend defining 100x100 sprites as 100x100 meter objects.


Also, apart from stability, If you want your simulation to look natural, you should define your objects size to match their real world counterparts

A 100mx100m object behaves very differently from a 1x1m object.

The amount of pixels you use to draw them should be totally irrelevant when deciding how big you define your objects in your physics simulation.

Only what you try to simulate should matter (is it a soda can, a truck, or a planet?)


Box 2D is optimised to simulate things in the size range of soda cans to trucks.

#5224851 C++ Ternary operator ?: surprising conversion rules.

Posted by Olof Hedman on 22 April 2015 - 08:30 AM

I thought I knew how the ?: operator worked, but today someone surprised me by telling me this code does not compile:

class A {
class B : public A {
class C : public A {
A* example1(bool condition) {
  return condition?new B():new C();

LLVM says "Incompatible operand types (B* and C*)"




Doing this works fine:

A* example2(bool condition) {
  return condition?new A():new C();

Searching a bit tells me that the second operand must be convertible into the third, or vice versa, which B and C obviously isn't.


But what is the logic behind this?

Why is it not "enough" that they can be converted to a common base type?

Why do they need to be converted into each other anyhow, isn't it enough to convert the result, if needed?


I'm sure all this has a very logical explanation, anyone who wants to enlighten me? smile.png

#5224667 FastCall Is Alll

Posted by Olof Hedman on 21 April 2015 - 05:44 AM

On some keyboard layouts some of those characters are still hard to type and can hurt the hands in the long term



On the swedish mac layout, both {} and [] is some kind of hand breaking 3-key combination, I tried to code using it for about 10 minutes, before I decided to just switch to english layout while coding.

That was an awesome decision I have never regretted, all of the "special" characters are so much easier to type.

I'm sure it even helped my productivity, not mainly because of typing speed, but less cognitive overload.

#5224496 Write ToLower As Efficient, Portable As Possible

Posted by Olof Hedman on 20 April 2015 - 08:48 AM

Others have said it with more words, but I think it should be underlined a few times:

If you want to support more languages then simple 7bit ascii, you simply do not want to write this yourself, it is way to complicated for any single dev that has no intention of becoming a full time unicode AND language expert. Use a library.


Then the next question, why the lowercasing?

If it is to search for keys, and you want to support more then simple english 7bit ascii, just lowercasing is not enough.

You also need to handle language dependant rules of what characters match with others.

A unicode library will provide also this for you, by creating a "folded" version of the string.

#5223919 get string value from x-plane

Posted by Olof Hedman on 17 April 2015 - 04:36 AM

It would have been easier to help if you specify what "errors" you get, and if you try to understand them, you might be able to fix the problem yourself.


In this case, I'm guessing this line is your problem:


string Nfms1 = XPLMGetDataf (fms1);


since the manual says that GetDataf returns a float, not a string.


I think you need to use XPLMGetDatab to get bytes, since the manual says "sim/cockpit2/radios/indicators/gps_nav_id" is an array of bytes.


Maybe this will work?


char buff[256];


XPLMDrawString(color, PanelLeft1 + 70, PanelTop1 - 40, buff, NULL, xplmFont_Proportional);

#5222577 C++ cant find a match for 16 bit float and how to convert 32 bit float to 16...

Posted by Olof Hedman on 11 April 2015 - 05:14 AM

Just letting glTexImage do the conversion should be the easiest and most compatible way to do it, which could be important if you target android.


You don't know the combination of cpu and gpu the customer will have in their phone, and what float format they expect, so instead of handling all cases, just let the driver do it.

#5222384 How would I read/write bit by bit from/to a file?

Posted by Olof Hedman on 10 April 2015 - 04:35 AM

I would recommend you to try use std::bitset instead (http://www.cplusplus.com/reference/bitset/bitset/)


It has methods to convert it to a binary representation you can easily write to file and read back. (either as long or long long if the bitfield is small enough, or as a std::string)


Edit: heh, just read your other thread, where you give your reason for not using bitset.

As you've heard, std::vector<bool> is a bit "special", this unfortunately means it is a bit tricky to read and write it to a file.

Seems you have to iterate through it and convert it to a binary representation. This could be done as a custom << stream operator.


Maybe someone else have some trick up their sleeve :)

#5221449 What exactly is a file header?

Posted by Olof Hedman on 05 April 2015 - 04:43 AM

The thing with binary files is that they do not in them selves have any structure. (like an xml file)

It is just one big blob of data.


To help parse the data, the designer of the file format has defined a "file header" which contain information on how the data blob should be interpreted.

For an image, it could for example be the pixel format, width, height, and what compression is used.


Technically, it is just the first few kB of the file contents (how much depends on the format).

So to read it, you just read the file as normal.

The first reads from the file will be from the "header"


More complex file formats typically have more then one header. Each header in front of its own blob/block of data, defining how that block should be read back.

This way, some blocks can be optional, and older versions of the software might be able to read files from newer versions, just ignoring the blocks it does not understand.

#5219644 AI conquest deadlock

Posted by Olof Hedman on 27 March 2015 - 10:11 AM

I think, going into direction of "even more smart" is pointless...


Well, your AI is very smart within the parameters it evaluates... 

But is the end result really that smart?


How rational is it really to grind billions into a never-ending war that gain nothing?

I'd say... not really.

It sounds a bit like your "perfect AI" need to read "The Art of War" to start with smile.png


My point is just that your AI need to take more parameters into consideration, and that would mean being "smarter", not trying to make it less smart. Lorenzo again gives good examples of what these parameters could be.


Other parameters could be that which we call "emotions". A never-ending war will for example likely run your troops morale into the ground, which makes your war even more costly and pointless (unless everyone is robots, then I guess a never-ending war is plausible, but still sounds more like a programmer bug on the part of the creators of said robot civilization). Technically, this is just a float somewhere that get reduced every turn the war continues and modify the "importance" of this planet, but it is more fun and useful to think of it as "morale"


Another way to say it, I guess, is: The game should be balanced such that stupid and boring strategies simply isn't perceived as advantageous. Then the AI won't pick them.

#5219264 AI conquest deadlock

Posted by Olof Hedman on 26 March 2015 - 03:26 AM

I think your "perfect" AI needs to be smarter smile.png

It's obviously not really a good strategy if it can easily be beaten by sidestepping the AI.


DifferentName and LorenzoGatti has some good points, it's not a sane strategy to always just go all in on the most important planet, you should also consider where other agents are, and what can be conquered for low cost.


Also, adding some personality besides just random factors could be fun. Maybe some faction is very vindictive, and like to punish other factions that attacks them. Maybe some like to prey on the weak. Etc.