Friday, 20 November 2015

Session 8

Do not use windows.h
Windows.h bloats codespace (possible code duplication, slower performance etc)
You also lose portability using windows.h as it will only work with Windows systems
Also avoid using console commands like system(" ")
Instead, to sleep (pause), use: std::this_thread::sleep_for(std::chrono::milliseconds(frameWait));
In C++14 and higher, literals can be used if you #include chronos, you can write 5s for 5 seconds, 10ms for 10 milliseconds, etc.
Polling for input also - getting key input

Clear screen - can't use system commands so an alternative is to simply print enough new lines to replace all onscreen.
#ifndef is a pre-processing statement, happens before any compilation
If using C++ 11 or higher there is a C++ specific clear screen function that can be used
As well as a Visual Studio-specific one...
#ifndef _MSC_VER to use Visual Studio version
must #endif

Auto - the auto keyword can be used to save time.
Auto deduces the correct variable type, like float/int/char etc based on what follows.
For example, a number with a decimal point should be classed as a float, if auto is used
Only safe to use when you are certain of what the computer will treat the variable as

example syntax of using auto in a for loop:
for(auto& player : players)
{
//for every player in players
}

Weak pointers can only be created from shared pointers
Weak pointers cannot influence when an item gets destroyed, hence 'weak'
Locking a weak pointer creates a shared version for that line (temporarily)

Big O notation
O = order
Complexity refers to how the numbers of inputs impact the processing time
The order is the rate of growth
T(n) = O(n^2) where T is time, and grows in the order of n^2, this is an exponential growth
An order of magnitude lets us see the scale or magnitude of the algorithm in a nice, easy to follow visual example - no need to see the numbers explicitly
Given x number, how does that impact processing time

Algorithm - sort of like a recipe, it is a set of rules that govern a series of calculations or problem-solving solutions
Every line, operation or formation can be considered an algorithm as it tells the computer what to do
Algorithms are unambiguous, very specific

In a constant expression, time taken will never change
In a linear expression, time taken increasing with more inputs can be represented using a straight line
Polynomial expressions show a steep curve in growth
Still all just a visual representation without explicit values
Logarithmic expressions are the opposite of polynomial; diminishing returns (smaller difference between inputs, the more inputs there are)

No comments:

Post a Comment