Difference between revisions of "Intermediate C++ Game Programming Tutorial 1"

From Chilipedia
Jump to: navigation, search
(Created page with "This video talks about the course syllabus for the Intermediate C++ tutorial series (the shit we gonna learn) and the prerequisites for following this series (what you need to...")
 
(Homework)
 
(26 intermediate revisions by the same user not shown)
Line 1: Line 1:
This video talks about the course syllabus for the Intermediate C++ tutorial series (the shit we gonna learn) and the prerequisites for following this series (what you need to know, and what you need to have). Use it to get an idea of what this series is about, and whether you have what it takes to follow along. If you don't know this shit, check out the links below for my Beginner C++ series. Check out the [[Beginner C++ Game Programming Series#Topics Covered|list of topics learned in Beginner]] for more details on what you need to know to follow Intermediate.
+
We've been using <code>int</code>s and <code>float</code>s and <code>bool</code>s this whole time, but have you ever wondered about a day in the life of a variable? In this video, we find that shit out, and so much more. We also learn about the cousins of <code>int</code> and <code>float</code>, adding to our arsenal of basic data types we can use in our programs. What's the endgame you ask? This stuff is gonna help us understand pointers and strings, and it's just interesting shit.
  
 
== Topics Covered ==
 
== Topics Covered ==
*
+
* The concept of memory (RAM)
 +
* Binary and hexadecimal number systems
 +
* <code>char</code>, <code>short</code>, <code>long long</code>, <code>double</code>
 +
* <code>unsigned</code> integral types
 +
* The ranges and sizes of basic data types
 +
* Layout of variables in memory
 +
* Correspondence between C++ code and CPU operations
  
== Basic Plan for Intermediate ==
+
== Video Timestamp Index ==
We're gonna start low level, and work our way up quickly to the good shit. This first arc of Intermediate is gonna be 100% console app land. First comes a little lecture on memory, variables, and the binary number system. Then we cover pointers, c-strings and console I/O, basic file I/O, and heap allocation. This is where we ascend to a higher plane of thought. We will migrate from c-strings and basic I/O to awesome <code>std::string</code> and std streams. While we're on the topic of containers, let's get a taste of <code>std::vector</code>. Then, we'll wrap up the console app section with a fun little word game, putting together everything learned so far in Intermediate.
+
[https://youtu.be/CDVWSDt4tB4 Tutorial 1]
  
After the console section, the plan is to learn how to load an image from a bitmap file, and then to cover basic sprite drawing operations, so we can abandon the nasty <code>PutPixel</code> calls once and for all. After this we'll cover more standard library containers, iterators, and algorithms. We're gonna learn OOP concepts like inheritance and polymorphism. We're gonna learn sweet C++11 stuff like lambda functions and move semantics. And we're gonna make more games.
+
== Bonus Video: Red Pill [The Stack] ==
 +
The description of how variables are organized in memory in Tutorial 1 is a simplified model that will help us understand memory and pointers; it is not 100% accurate.
  
== Video Timestamp Index ==
+
Chili had originally planned to teach the full details of how variables are allocated, explaining things like storage classes (stack, heap, static), the details of stack management and function stack frames, and exploration of the memory and machine instructions using the debugger. But then he realized that this amount of detail and complexity might be too much of a mind fuck for too many people, so he cut that content from Tutorial 1.
[https://youtu.be/kOsnq5JJvawfuttbucker Tutorial 1]
+
 
 +
Since the video is already recorded, it will be released as optional content for people who are interested in the nitty-gritty details, but the keyword here is ''optional''; you are not required to know this content to continue on with the tutorials and it will not be referred to in the mainline tutorial series. It is, however, very interesting shit.
 +
 
 +
Video link: [https://youtu.be/Cjx5C2I3UrA Red Pill - The Stack]
  
 
== Homework ==
 
== Homework ==
None!
+
 
 +
This lesson's homework is to answer the following questions. When you think you have the answer, click "expand" to reveal the correct answer.
 +
 
 +
1. In Microsoft Visual C++, what is the size in bytes of the following data types: <code>int</code>, <code>char</code>, <code>double</code>, <code>unsigned int</code>, <code>short</code>, <code>bool</code>
 +
<div class="mw-collapsed mw-collapsible"><br />
 +
<code>int</code>: 4<br />
 +
<code>char</code>: 1<br />
 +
<code>double</code>: 8<br />
 +
<code>unsigned int</code>: 4<br />
 +
<code>short</code>: 2<br />
 +
<code>bool</code>: 1
 +
</div><br />
 +
2. Make the following conversions: 01000111b -> dec, 11001111b -> hex, 10h -> dec, 7Ah -> bin, 193d -> bin
 +
<div class="mw-collapsed mw-collapsible" style="width:450px"><br />
 +
01000111b -> dec: 71<br />
 +
11001111b -> hex: CF<br />
 +
10h -> dec: 16<br />
 +
7Ah -> bin: 01111010<br />
 +
193d -> bin: 11000001<br />
 +
</div><br />
 +
3. What is the size of this class in bytes with default compiler settings in Microsoft Visual C++, and how many of those bytes are padding:<br />
 +
<syntaxhighlight lang="cpp" line="1" >
 +
class Foo
 +
{
 +
public:
 +
int a;
 +
char b[3];
 +
short c;
 +
int d;
 +
};
 +
</syntaxhighlight>
 +
<div class="mw-collapsed mw-collapsible" style="width:450px"><br />
 +
16 bytes (3 bytes padding)
 +
</div><br />
 +
4. Why is hexadecimal commonly used to represent values in programming?<br />
 +
<div class="mw-collapsed mw-collapsible" style="width:450px"><br />
 +
It's easy to convert between hexadecimal and binary representations, and hexadecimal takes far fewer digits to represent the same number.
 +
</div><br />
 +
5. When accessing variables in memory, often times many addition/multiplication operations must be performed to index into arrays or access elements of classes/structures. What is one way the compiler can optimize this for runtime performance?<br />
 +
<div class="mw-collapsed mw-collapsible" style="width:450px"><br />
 +
If the indices and offsets are values that are known at compile time, the addresses will be pre-computed at compile time and not at runtime.
 +
</div><br />
  
 
== See also ==
 
== See also ==

Latest revision as of 22:20, 13 October 2019

We've been using ints and floats and bools this whole time, but have you ever wondered about a day in the life of a variable? In this video, we find that shit out, and so much more. We also learn about the cousins of int and float, adding to our arsenal of basic data types we can use in our programs. What's the endgame you ask? This stuff is gonna help us understand pointers and strings, and it's just interesting shit.

Topics Covered

  • The concept of memory (RAM)
  • Binary and hexadecimal number systems
  • char, short, long long, double
  • unsigned integral types
  • The ranges and sizes of basic data types
  • Layout of variables in memory
  • Correspondence between C++ code and CPU operations

Video Timestamp Index

Tutorial 1

Bonus Video: Red Pill [The Stack]

The description of how variables are organized in memory in Tutorial 1 is a simplified model that will help us understand memory and pointers; it is not 100% accurate.

Chili had originally planned to teach the full details of how variables are allocated, explaining things like storage classes (stack, heap, static), the details of stack management and function stack frames, and exploration of the memory and machine instructions using the debugger. But then he realized that this amount of detail and complexity might be too much of a mind fuck for too many people, so he cut that content from Tutorial 1.

Since the video is already recorded, it will be released as optional content for people who are interested in the nitty-gritty details, but the keyword here is optional; you are not required to know this content to continue on with the tutorials and it will not be referred to in the mainline tutorial series. It is, however, very interesting shit.

Video link: Red Pill - The Stack

Homework

This lesson's homework is to answer the following questions. When you think you have the answer, click "expand" to reveal the correct answer.

1. In Microsoft Visual C++, what is the size in bytes of the following data types: int, char, double, unsigned int, short, bool


int: 4
char: 1
double: 8
unsigned int: 4
short: 2
bool: 1


2. Make the following conversions: 01000111b -> dec, 11001111b -> hex, 10h -> dec, 7Ah -> bin, 193d -> bin


01000111b -> dec: 71
11001111b -> hex: CF
10h -> dec: 16
7Ah -> bin: 01111010
193d -> bin: 11000001


3. What is the size of this class in bytes with default compiler settings in Microsoft Visual C++, and how many of those bytes are padding:

class Foo
{
public:
	int a;
	char b[3];
	short c;
	int d;
};

16 bytes (3 bytes padding)


4. Why is hexadecimal commonly used to represent values in programming?


It's easy to convert between hexadecimal and binary representations, and hexadecimal takes far fewer digits to represent the same number.


5. When accessing variables in memory, often times many addition/multiplication operations must be performed to index into arrays or access elements of classes/structures. What is one way the compiler can optimize this for runtime performance?


If the indices and offsets are values that are known at compile time, the addresses will be pre-computed at compile time and not at runtime.


See also