Jump to content

  • Log In with Google      Sign In   
  • Create Account

RobTheBloke

Member Since 22 Jun 2002
Offline Last Active May 28 2016 07:34 AM

#5291358 Bubble Sort Algorithm Review

Posted by RobTheBloke on 12 May 2016 - 07:51 PM

Your display list function....

It could take a const ref to the vector (rather than making a copy each time).

Again, that counter has returned!

If you want to see if the vector is empty, use the empty method! (size is typically implemented as a subtraction, so can be very modestly more expensive). Therefore repeatedly checking whether counter is equal to the size() is not considered good practice!

The if(iter != list.end()) check in the for loop is pointless. That condition is already checked by the for loop condition, so it can never enter the 'else'

Repeatedly doing if/else's for commas is probably a bad idea.


if(theList.empty()) {

// blah

}

else {

  auto it = theList.begin();

  auto end = theList.end();

  cout << *it++;

  for(; it != end; ++it)

    cout << ", " << *it;

}




#5291356 Bubble Sort Algorithm Review

Posted by RobTheBloke on 12 May 2016 - 07:36 PM

Your for loop seems a bit rubbish :)

Why use iterators as your for loop condition, and also employ a counter? You could just use a counter? That would allow you to avoid the constant if/else within the loop (since your end condition can be size - 1).

The alternative, would be to use two iterators (which may save some additional costs associated with the array element access - not in itself expensive - but since you are passing in a reference to a vector, some compilers may force an additional pointless load op on 'begin' for each element access). Again, you can engineer your loop to test the 'next' element is not equal to end.


if(theList.size() < 2) return;


auto end = theList.end();

bool altered_list = true;

while(altered_list) 

{

  altered_list = false;


  auto it = theList.begin();

  auto next = it + 1;


  for(; next != end; ++it, ++next) {

    if(*it > *next) { 

      std::swap(*it, *next);

      altered_list = true;

    }

  }

}



I suppose the correct way to swap elements would be with std::swap, which would remove the 'temp' variable, and make the code a little clearer to read.

The pass through counter seems to be a little superfluous (unless it's just a formatting thing).

The 'sorted' flag serves no purpose. You already have 'altered_list', which gives you the same information.


#5288154 N64, 3DO, Atari Jaguar, and PS1 Game Engines

Posted by RobTheBloke on 22 April 2016 - 10:44 AM

Back in the day there was the net yaroze, and you can still find them on eBay: http://pages.ebay.com/link/?nav=item.view&alt=web&id=351701873219&globalID=EBAY-GB

To be honest though, they're expensive, and woefully underpowered with limited information around to help you develop games. I had one, but it wasn't as exciting as playing with newer hardware (Multi-texturing on an OpenGL 1.2 capable ATI rage fury + overclocked celeron 300 in my case)

This stuff is interesting from a historical perspective I guess, but I've always found new shiny to be more interesting....


#5287539 What is more expensive in float?

Posted by RobTheBloke on 18 April 2016 - 03:24 PM

My guess would be that the square root and one trigonometric function might be slightly faster, but I don't know which CPU you are using, so YMMV.

<insert obligatory rant about premature optimization here, blablabla>

Thanks for the guess tho, it is a cpu standard op, who knows of what advanced math lib, wheather intel or amd native ops, I believe they should not differ on this?
Sines/cosines are standard maths functions. It is possible to Improve on the standard library implementations (depending on how much accuracy you are willing to sacrifice). So yeah, if you can find a way to reduce N cmath calls by one or more, then it's typically a good thing. I would be semi-inclined to make the switch from 4 funcs to 1 + sqrt without bothering to profile. It's highly unlikely that it will be slower (and that code can change between platforms, so an improvement on one platform might not be better on another).

*IF* fast math is enabled in your compiler settings, then sqrt is a CPU instruction (if using strict or precise, then typically a standard library function will be used).

I think otherwise, inverse number is so expensive, while trigonometric functions can be aproximated by tylor polynomes in few degrees so well. I am going to profile, but I hope for more guesses :)
Thanks.

There are some fairly decent arc-cos / arc-sin approximations around. Certainly the approximations I use aren't substantially worse than the non inverse functions.

Worth reading these:

http://forum.devmaster.net/t/fast-and-accurate-sine-cosine/9648
https://www.ecse.rpi.edu/~wrf/Research/Short_Notes/arcsin/onlyelem.html

Generally speaking, using floats will be quicker than double, but YMMV. (Long topic, so I'll leave that can of worms shut for now)


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

Posted by RobTheBloke on 30 March 2016 - 12:14 PM

It's not really a question of how much maths/physics you need to learn (the more the better, but you have enough to start with). Matrices, vectors, mechanics (f=ma, describing forces, etc), solving linear and quadratic equations (collision detection), statistics (compression schemes, AI). The only esoteric thing you may not have come across is a quarternion (essentially a rotation only matrix - but with a few additional advantages).

If you hit most of those, cool. If not, they can be learned.

The biggest problem though, is not really how the maths/physics works, but how and when you need to apply calculation X to game feature Y. That can admittedly take some time, but that won't stop you enjoying games development / programming for the sake of it


#5284107 What game is suitable for a beginner to make (with C++)?

Posted by RobTheBloke on 29 March 2016 - 02:44 PM

Guys, the OP has already tried working on Snake, but there's a lack of fundamental programming knowledge that needs to be learned.  So, my suggestion was to get a better foundation of programming before trying to make a game.
 
And, snake does have a little more complexity than other beginner games when the snake is growing, and how to handle moving the body parts.  Pong is a much better suggestion IMO, although the text-based one would probably be best at this point.


Respectfully disagree, strongly. I've taught games programming at university. I've taught games programming at school. I've taught seasoned veterans the nuances of SIMD/threading/mathematics/physics, and all manner of subjects.

For some people, spending six months understanding the concepts underlying programming is useful. For the vast majority, it simply removes the thing that makes programming enjoyable - overcoming challenges in the way of *your goals*.

The greatest challenge facing any recruiter in games or film vfx right now, is that For every
Million graduates who know what a pointer is, only 5000 have spent their time building software (rather than learning languages), and of those 5000, only 100 have a deep enough understanding to be able to jump right into a programming role.

you can read a C++ book cover to cover. You can read the Intel intrinsics guide and optimisation manuals. You can read the latest vulkan/d3d specs. You can do all of that, and you will have learnt nothing.

All of those are vital steps along the way to becoming a professional game developer, but so is experience. So is learning from mistakes. So is biting off more than you can chew, and battling your way through the pain to a workable solution. Mistakes and wrong turns, are by far the fastest way to learn. Implement something (badly), read that c++ book again, and very rapidly you will learn how this programming stuff fits together.

Be cautious, choose 'simple' excercises, and you'll find that your learning cannot keep pace with the technology.


#5283868 What's wrong with this snake game code?

Posted by RobTheBloke on 28 March 2016 - 10:50 AM

Well, this is a bit off topic, but:
I think you should be using Object-Oriented Programming, it makes the code easier to understand for others, and also it makes less chance of errors in your own code. Are you learning SFML on your own, I don't think any book or guide will recommend not using OOP. So, yeah if you want to reduce problems and increase ease, do use OOP. I am actually learning SFML even myself, from the book SFML Game Development and some online tutorials and well even from the SFML documentation. Hope it helps.


That a bit dogmatic. I hear people say the same thing of functional programming. Just write code that is simple, stupid, easy to understand, and works. OOP is a useful tool, but not a one size fits all solution.


#5283517 What game is suitable for a beginner to make (with C++)?

Posted by RobTheBloke on 25 March 2016 - 09:26 PM

The best game to start with is one that is simple enough to complete, but complex enough to be challenging. Snake fits that bill. If you only ever look for simple challenges, you won't progress beyond hello world. The joy of programming is finally solving that problem that has had you stumped for 3 days.


#5275441 Windows 10 - OpenGL Version

Posted by RobTheBloke on 12 February 2016 - 12:58 PM

It did cause a hilarious FUD storm at the time though, with the people-who-spell-it-Micro$oft-and-read-slashdot crowd completely losing their mind and jumping to the conclusion that this meant that OpenGL drivers would be restricted, and GL would always just be an inefficient API-emulation layer on top of D3D.


That's a slight misrepresentation of the past there!

It wasn't entirely a FUD storm, OpenGL was going to end up being relegated to a second class citizen, but not for the reasons you state. The original plan was that when OpenGL was run, the aero theme would switch off (no transparency on the desktop). If you wanted your app to be compatible with aero, you needed to use d3d (or the OpenGL 1.4 -> d3d wrapper). This was the behaviour in the first vista release candidates (I actually remember having serious discussions about porting our 3d app to d3d)

If you were a game developer using gl then, none of this was a concern (you'd be full screen anyway). For 3d app devs though, this was a pretty big concern back in the day (your competitor, with a d3d viewport, would have a nicer looking gui than you).

Microsoft eventually backed down after autodesk/Adobe and others pointed out they needed OpenGL for their products.


#5275373 MSVC generating much slower code compared to GCC

Posted by RobTheBloke on 11 February 2016 - 09:16 PM

Visual C++ tends to err on the side of code safety, and has a habit of assuming everything is volatile. It can be persuaded to optimise your code (and can do a very good job of it), but it can be very picky as to when it applies the optimisations. As ApochPiQ mentions, make sure you disable the security checks in the compiler settings, but without seeing any of the code, it's kinda hard to say much more than that. 

 

 Maybe the linux version discovered that it can optimize intermediate steps of a loop out because those steps aren't used?
 

It's unlikely. VC++ is pretty good at stripping unused code paths. VC++ tends to assume that variables are volatile, so accessing values through references (or this) can prevent vectorisation in tight loops (and a few other fun situations like that). clang and gcc are little bit aggressive in this respect (occasionally too aggressive!). Fire a profiler over the code, look at the disassembly, and tackle those hot spots one at a time. If you see lots of instructions ending in 'ss' or 'sd' (instead of 'ps' or 'pd') then the vectorisation has failed.


#5274871 Cache misses and VTune

Posted by RobTheBloke on 08 February 2016 - 11:07 AM

You aren't doing anything with 'c'. So VC++ will strip all the code that was used to generate that value. That leaves you with an empty switch, which it will strip. That leaves you with an empty for loop, which it will also strip. Since there's now no point in your object arrays, it will also strip those. Your program now consists of a single system call. :/

As I said, don't profile for loops, because even a poor compiler will strip them out. Profile applications instead.


#5274860 Cache misses and VTune

Posted by RobTheBloke on 08 February 2016 - 10:20 AM

Ugh.

1. Are you compiling this on release? It's pointless profiling debug builds.
2. Visual c++ will remove all of that code, because it's completely pointless. VC++ isn't that stupid.
3. Don't profile for loops.
4. Don't profile for loops.
5. Don't profile for loops.


#5192266 Software Fallback?

Posted by RobTheBloke on 11 November 2014 - 09:10 AM

AFAIK, HD 3xxx series should go up to OpenGL 3.1 on Windows, 3.3 on Linux with Mesa. Not sure what's the situation in OSX world, didn't they supported up to 3.2 with those cards?

 

Technically 3.1 (due to a few missing features from 3.2 and 3.3), but the HD 3000 supports version 400 GLSL strangely.




#5167628 How to pack your assests into one binary file (custom file format etc)

Posted by RobTheBloke on 18 July 2014 - 10:11 AM

How you do this is entirely up to the developer. There is no standard approach really.... 

 

On some occasions, it can be nothing more complicated than a zip or tar file.

Sometimes it may be a custom compressed file (probably using something like libZip to do the compression/decompression, and a custom header that will ensure it can't be opened as an archive). 

Sometimes it may simply be a serialised memory dump containing all of the assets for a level. 

And every so often, you may come across someone who uses encryption to add another layer of annoyance for people trying to rip the assets! 

 

Whether or not a developer wants people to be able to navigate their asset packages, is going to depend largely on whether they care about protecting their art assets or not. For some games companies that support extensive modding in their games, they are likely to be much more open with their asset packages than a company that does not support modding. Ultimately there is no company wide standard governing this.... 




#5157409 Programming for software intermingling(?)

Posted by RobTheBloke on 01 June 2014 - 03:13 PM

How would I find that out? Its a very basic file of a frequency wave and a few text saved as a ".dat".

 

Open it in a HEX editor?  (or text editor if it's a text based file?) Or consult the file format spec? Swiftcoder is right. Effectively you have a data-structure, albeit one that's been serialized to disk. The structure of your data will, to a large extent, influence how relevant or applicable the advice we give will be. This returns the contents of any file as a string:

 

std::string loadFile(const char* filename)

{
  std::string p;
  std::FILE* fp = std::fopen(filename, "rb");

  if(fp)
  {

    std::fseek(fp, 0, SEEK_END);

    size_t s = std::ftell(fp);

    if(s)  

    {
      std::fseek(fp, 0, SEEK_SET);
      p.resize(s);

      std::fread(&p[0], 1, s, fp);
    }
    std::fclose(fp);

  }
  return p;

}

 

Now, you wouldn't actually want to use that. Probably. Maybe. Possibly. Who the hell knows? Take the gamble? Phone a friend? I don't know, nor does anyone else.

 

To use a car analogy:  The above code gives permission for a passenger to open a car door. Swiftcoder is merely asking what your passengers will find beyond that door. Will they find that the car is stationary? Will they find the ground rushing past them at 70mph? Will they find that the car has actually been compressed, in a vice, and that the doors cannot open?

 

How you tackle problems of this sort are 'usually' formulaic. I'm happy to step onto tarmac that isn't moving, less enthusiastic when it's moving at speed (stop first!), and would like to know whether I should keep my mobile on me, just in case someone tries to squish me in a vice. 






PARTNERS