Recursion is what it is called when a function calls itself. Like a paradox
If the base case (is = 0 etc) doesn't stop it will last forever!
If it is on the stack it will overflow and cause major problems at runtime.
Recursive calls can slow down memory - if they are endless, there could be millions of things happening at the same time... even if you have enough space for them all
A continuous (contiguous - in a row) block of memory is required for a static array
Static arrays are a fixed size, hence static (which means lacking movement, change etc)
Due to this, there might be memory allocated that is never used...
Dynamic arrays also require contiguous memory blocks but the size is not fixed - the size can change as required, so as not to waste any memory, and to never have too high a quantity
example array syntax: Item inventory [2] [5]; this is a table with 2 rows and 5 columns
Dynamic arrays should be constant (const) referenced if variable is not going to be changed
Cannot have null references and they must be initialised when created
And only return references and pointers when you know the data is still valid.
Friday, 16 October 2015
Friday, 9 October 2015
Session 3
Ship
+turn ()
+move()
+shoot()
-rotation:float
-momentum:float
-thrust:float
(example of UML diagram)
Looked for common functionality
Looked at how the objects inherit
All gameobjects have potential for animation
Polymorphism - one version of attack (boss for example) can be different if virtual is used. Attack would also be used by a regular monster if boss is also a monster
Do not override non-virtual stuff!
#ifndef (headername)
#define (headername)
#endif
or use
#pragma once
these make sure headers and such are only included once during compilation
Forward declaration tells the compiler the identifier's size and data type; this is all the compiler needs to run
Forward declaration is a performance saver (less hardware intensive)
Static memory - memory is allocated but once it drops off it deallocates.
Cleanup is automatic and this prevents memory leak
Static things need to know their quantity though...
Memory gets popped off the stack after its space, first in last out
Dynamic memory allocation is separate from spaces so it is up to you (me!) to point to it and deallocate... otherwise problems
+turn ()
+move()
+shoot()
-rotation:float
-momentum:float
-thrust:float
(example of UML diagram)
Looked for common functionality
Looked at how the objects inherit
All gameobjects have potential for animation
Polymorphism - one version of attack (boss for example) can be different if virtual is used. Attack would also be used by a regular monster if boss is also a monster
Do not override non-virtual stuff!
#ifndef (headername)
#define (headername)
#endif
or use
#pragma once
these make sure headers and such are only included once during compilation
Forward declaration tells the compiler the identifier's size and data type; this is all the compiler needs to run
Forward declaration is a performance saver (less hardware intensive)
Static memory - memory is allocated but once it drops off it deallocates.
Cleanup is automatic and this prevents memory leak
Static things need to know their quantity though...
Memory gets popped off the stack after its space, first in last out
Dynamic memory allocation is separate from spaces so it is up to you (me!) to point to it and deallocate... otherwise problems
Thursday, 1 October 2015
Session 2
Use initialiser list for constructor
Don't call virtual functions from constructors
Construction happens FIRST - variables don't exist yet!
Constructors can be chained - eg call another constructor from default
We should only see virtual variables in public
example of syntax: class rock: (is a) public IsAGameObject
Composition - model an object: door has handle, but door is not handle
Private inheritance implemented as you may have a base class you want to use
Virtual variables are determined at runtime - dynamic override can only be used on virtual variables
Diamond problem is objects inherit from a gameobject, but then another object inherits from both of those
Use virtual (pointer) to make sure object is not replicated
Using virtual may be more hardware intensive...
The most derived (original source?) class initialises
Using = delete can help to stop other classes inheriting or calling the object
Binding is designating memory addresses. Static is early, dynamic is late
Don't call virtual functions from constructors
Construction happens FIRST - variables don't exist yet!
Constructors can be chained - eg call another constructor from default
We should only see virtual variables in public
example of syntax: class rock: (is a) public IsAGameObject
Composition - model an object: door has handle, but door is not handle
Private inheritance implemented as you may have a base class you want to use
Virtual variables are determined at runtime - dynamic override can only be used on virtual variables
Diamond problem is objects inherit from a gameobject, but then another object inherits from both of those
Use virtual (pointer) to make sure object is not replicated
Using virtual may be more hardware intensive...
The most derived (original source?) class initialises
Using = delete can help to stop other classes inheriting or calling the object
Binding is designating memory addresses. Static is early, dynamic is late
Subscribe to:
Posts (Atom)