C++

xolio xeleo xodyo
*N = 4
*2^N = 16
*2^N - 1 = 15
*2^(N-1) = 8
*2^(N-1) - 1 = 7
*16 8 4 2 1
Binary	Unsigned	Sign and magnitude	Ones' complement	Two's complement	Excess-8	Base −2
0000 	0 	0 	0 	0 	−8 	0
0001 	1 	1 	1 	1 	−7 	1
0010 	2 	2 	2 	2 	−6 	−2
0011 	3 	3 	3 	3 	−5 	−1
0100 	4 	4 	4 	4 	−4 	4
0101 	5 	5 	5 	5 	−3 	5
0110 	6 	6 	6 	6 	−2 	2
0111 	7 	7 	7 	7 	−1 	3
1000 	8 	−0 	−7 	−8 	0 	−8
1001 	9 	−1 	−6 	−7 	1 	−7
1010 	10 	−2 	−5 	−6 	2 	−10
1011 	11 	−3 	−4 	−5 	3 	−9
1100 	12 	−4 	−3 	−4 	4 	−4
1101 	13 	−5 	−2 	−3 	5 	−3
1110 	14 	−6 	−1 	−2 	6 	−6
1111 	15 	−7 	−0 	−1 	7 	−5
==游戏编程==
*http://gamecodeschool.com/c-plus-plus-tutorials/
**http://gamecodeschool.com/sfml-projects/
***https://www.gamefromscratch.com/post/2015/09/14/A-Closer-Look-at-SFML.aspx
*http://gamecodeschool.com/c-sharp-tutorials/ 
问题: 
*ImGUI example solution didn't add all example projects into solution
**Right click anywhere in solution manager, then add existing/new item, then pick the desired sln or vscproj file
*Using vcxproj to open project rather than sln? 
**Yes, that's what's supposed to happen, if that's the only thing the author provides
*How do all the files fit together for ImGUI example? 
**As long as include path is complete, nesting structure of the files can be set by adding filters (see end of section 0)
==便笺==
*Unity + C# (window's version of java) for game development. 
*GUI creation:
**sfml (more class heavy C++ type of style rather than the pointer heavy C style sdl2) + ImGUI
***https://github.com/ocornut/imgui/tree/master/examples
***ImGUI with SFML tutorial: https://eliasdaler.github.io/using-imgui-with-sfml-pt1/
***ImGUI requires: [1] Renderers (low level api talking with GPU: DirectX9, DirectX10, DirectX11, DirectX12, OpenGL (legacy), OpenGL3/ES/ES2 (modern), Vulkan, Metal), [2] Libraries/Platforms (which handle low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video Framebuffer: GLFW, SDL2, Win32, Glut, OSX), and [3] possibly frameworks: Emscripten, Allegro5, Marmalade.
****(e.g. imgui_impl_win32.cpp + imgui_impl_dx11.cpp) or (e.g. imgui_impl_sdl2.cpp + imgui_impl_dx11.cpp)
****You will need a backend to integrate Dear ImGui in your app. The backend passes mouse/keyboard/gamepad inputs and variety of settings to Dear ImGui, and is in charge of rendering the resulting vertices.
****ImGui outputs vertex buffers and command lists that you can easily render in your application. Because Dear ImGui doesn't know or touch graphics state directly, you can call its functions anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). 
***Related translations：https://guildwars.huijiwiki.com/wiki/%E9%87%8D%E8%AF%91
**QT Quick QML declarative, more mobile oriented? /QT Widget, traditional desktop oriented? Needs to learn their ModelViewControl pattern
***https://deplinenoise.wordpress.com/2017/03/05/why-qt-and-not-imgui/
***https://www.cleanqt.io/blog/crash-course-in-qt-for-c%2B%2B-developers,-part-6
**Lower level framework: winapi/mfc (unfriendly)
==0==
===Connecting to Github===
*Incorrect credential causing push errors:
**Cause: Visual Studio may be using the default git credential that is displayed under the Credential Manager in Windows Control Panel
**Change the default credential, see screen cap here: https://jessehouwing.net/configure-visual-studio-to-use-a-different-git-credential-manager-for-windows/
===0.2===
*diagrams: https://www.learncpp.com/cpp-tutorial/introduction-to-programming-languages/
===0.3===
C++ excels in situations where high performance and precise control over memory and other resources is needed.
===0.4===
Good solutions require a study of programming paradigms, each of which will contribute to having code that is:
*straightforward (not overly complicated or confusing).
*well documented/more easily explained (especially around any assumptions being made or limitations).
*modular, so parts can be reused or changed later without impacting other parts of the program.
*robust, can be proven correct and can recover or give useful error messages when something unexpected happens.
Remember, code is written for people to read.
===0.5===
*compiler: turn source into machine language files
*linker: links your various files now in machine language with precompiled library files also in machine language. In this process, linker also resolves problems with dependencies such as bad references, if any.
* For complex projects, some development environments use a makefile, which is a file that describes how to build a program (e.g. which files to compile and link, or otherwise process in various ways)
**Random notes on internet suggests that (accuracy NOT verified): You can consider *proj and *sln files as makefiles.
===0.6===
*after the source has been turned into exe, how does the IDE do debugging? 
**how is the IDE different from such tools as OllyDbug?
===0.7===
*A project is a container that holds all of your source code files, images, data files, etc… that are needed to produce an executable (or library, website, etc…) that you can run or use. The project also saves various IDE, compiler, and linker settings, as well as remembering where you left off, so that when you reopen the project later, the state of the IDE can be restored to wherever you left off.
**One ought to create a new project for each new program they write.
*When you create a new project for your program, many IDEs will automatically add your project to a “workspace” or a “solution” (the term varies by IDE). A workspace or solution is a container that can hold one or more related projects. For example, if you were writing a game and wanted to have a separate executable for single player and multiplayer, you’d need to create two projects. It wouldn’t make sense for both of these projects to be completely independent -- after all, they are part of the same game. Mostly likely, each would be configured as a separate project within a single workspace/solution.
*Although you can add multiple projects to a single solution, we generally recommend creating a new workspace or solution for each program, especially while learning. It’s simpler and there’s less chance of something going wrong.
**VS2019 Create Project: It’s recommended that you also check the Place solution and project in the same directory, as this reduces the number of subdirectories that get created with each project.
*.vcxproj stores project information in an XML format, including references to source code files and application assets. The file is used for developing and building executable programs.
*.sln is a structure file used for organizing projects in Microsoft Visual Studio. It contains text-based information about the project environment and project state. 
*makefile possibly makes use of vcxproj/sln. makefile probably provides a superset of functionalities over .vcxproj and .sln. See "Build Configuration" below, "Build Configuration" probably does the job of makefile in Visual Studio
===0.8===
The build configuration typically includes things like what the executable will be named, what directories the IDE will look in for other code and library files, whether to keep or strip out debugging information, how much to have the compiler optimize your program, etc… Generally, you will want to leave these settings at their default values unless you have a specific reason to change something.
===0.11/0.12===
*Only name the parent folder in the "Location" box. Don't create a project folder for project, let IDE do it
*View -> Team Explorer: click to turn on the tab.
**also turn on Solution Explorer, Output, and Error List
**Adding new project items requires: Project -> Add New Item, and not File -> New
*Whichever file has main() function is the main file, regardless of source file name
*Project -> Right Click -> Properties -> C/C++ - > General -> Additional Include Directories: Set to whatever path one requires, for example: ".." [OR] "..\.."
*Project -> Right Click -> Properties -> C/C++ - > General -> Warning Level: Set to 4
*Project -> Right Click -> Properties -> C/C++ - > Language -> Disable Language Extensions: Set to Yes
*Project -> Right Click -> Properties -> C/C++ - > Language -> C++ Language Standard: Set to C++ 17
*Start-up project (the only one automatically built) bold font in multi-project solutions: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2008/a1awth7y%28v%3dvs.90%29
*Solution Explorer folder structure nesting (rule stored in filter file): https://docs.microsoft.com/en-us/cpp/build/reference/vcxproj-filters-files?view=vs-2019
**(right click PROJECT -> ADD -> New Filter, or dropdown menu PROJECT -> New Filter)
*VS2019中文界面: https://agirlamonggeeks.com/2019/03/10/how-to-change-language-in-visual-studio-2019-after-installation/
*中文源代码，概括：****https://www.zhihu.com/question/37252051 (例 (未曾需要过)：#pragma execution_character_set("utf-8"))
*#也可见以下附录链接，此外，可用 Open with 默认 ***Editor (with Encoding)。但是，日后在打开cpp文件时，每次都需自行选定 Encoding
*#或需另行设定："project properties -> c/c++ -> command line -> additional options:" /source-charset:utf-8
**附录: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-save-and-open-files-with-encoding?view=vs-2019
**重要: 汉化函数名：https://www.fluentcpp.com/2017/10/27/function-aliases-cpp/ 或 https://discordapp.com/channels/613733622192668672/613733622721019908
*中文Console或Powershell:
**https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window/57134096#57134096
**https://stackoverflow.com/questions/49476326/displaying-unicode-in-powershell
*ImGUI:
**仅以下两步即可:
**#io.Fonts->AddFontFromFileTTF("c:/windows/fonts/simhei.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
**#外加在字条前加上 u8 字样，例： u8"你好"
***其他选择：字体：simsun.ttc，msyh.ttc 选择：io.Fonts->GetGlyphRangesChineseSimplifiedCommon()，但这选择只有~2500字，会漏掉很多字
**好像无需另行设置 Save with Encoding 或 Open with Encoding 及 /source-charset:utf-8，
***但不清楚；由于测试过程过于繁琐混乱，无法判断导致那最初错误的疏漏究竟是什么
**注意：若在以上加载前加了 io.Fonts->AddFontDefault()，那中文字体就会被默认字体所掩盖
**其他:
***https://github.com/ocornut/imgui/blob/master/docs/FONTS.txt
***https://github.com/ocornut/imgui/wiki/Loading-Font-Example
***https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-load-a-different-font-than-the-default
==1==
===1.1===
*A statement is a type of instruction that causes the program to perform some action (去做事，务，实施，办理，执行，施行，履行). 
**the smallest independent unit of computation in the C++ language. In that regard, they act much like sentences do in natural language. 
**Most but NOT ALL statements end in semicolon
===1.2===
*Purpose of comments:
//what the function is trying to achieve
int stuff(){
//how the function achieves its objectives
//justify choices in data structure and algorithm
std::cout<<"test\n";
return 0; //Since what each statement is doing should be obvious, comments should be reserved for explaining why the statement is here at all
 //i.e., the purpose of the statement, or why the code is doing something
 //e.g., in terms of algorithm and/or what the statement represents
 //e.g., in a game, player just drank something, so some variable is being set to something
}
*Comment your code liberally, and write your comments as if speaking to someone who has no idea what the code does. 
*Don’t assume you’ll remember why you made specific choices.
*If you do need to comment out a code block that contains multi-line comments, you can also consider using the #if 0 preprocessor directive, which we discuss in lesson 2.10 -- Introduction to the preprocessor.
#if 0 // Don't compile anything starting here
 std::cout << "Bob\n";
 std::cout << "Steve\n";
#endif // until this point
*回忆"开图工具"那长篇乱编，事后无法读懂。。。
===1.3===
*Data locations (REVISIT this as one moves through the tutorial):
**Some hard coded into the assembly instructions of the exe
**Some kept in the data section of the compiled exe
***Function parameters have their values pushed onto the stack
**Dynamically created data (new/delete) are created on the heap
*An object is a region of storage (usually memory) that has a value and other associated properties (that we’ll cover in future lessons). 
**A named object is called a variable, and the name of the object is called an identifier.
====Variable Creation / Creating named objects====
*Use Declaration Statements 
**Specifically, Definition Statements 
***例子：int x; (无需授值)