programming

C++ – Basic Input Output

C++ – Basic Input Output

C++ uses a convenient abstraction called streams to perform input and output operations in sequential media such as the screen, the keyboard or a file.
The standard library defines:

cin standard input stream
cout standard output stream

Sample


// i/o example

#include <iostream>
using namespace std;

int main ()
{
  int i;
  // character output
  cout << "Please enter an integer value: ";
  // character input is stored in variable
  cin >> i;
  cout << "The value you entered is " << i;
  cout << " and its double is " << i*2 << ".\n";
  return 0;
}

The result is:
Please enter an integer value: 702
The value you entered is 702 and its double is 1404.

By |C++, Video Games Development|Commenti disabilitati su C++ – Basic Input Output

C++ – Variables and Datatypes

C++ – Variables and Datatypes

Variables let you store values dynamically.

Declare a variable

First you have to declare the variable type, the most used are:

Character types
– char Exactly one byte in size. At least 8 bits.
– char16_t Not smaller than char. At least 16 bits.
– char32_t Not smaller than char16_t. At least 32 bits.
– wchar_t Can represent the largest supported character set.

Integer types (signed)
– signed char Same size as char. At least 8 bits.
– signed short int Not smaller than char. At least 16 bits.
– signed int Not smaller than short. At least 16 bits.
– signed long int Not smaller than int. At least 32 bits.
– signed long long int Not smaller than long. At least 64 bits.

Integer types (unsigned) Same size as their signed counterparts
– unsigned char
– unsigned short int
– unsigned int
– unsigned long int
– unsigned long long int

Floating-point types
– float
– double Precision not less than float
– long double Precision not less than double

Boolean type
– bool

Void type
– void no storage

Null pointer
– decltype(nullptr)

Declaration of variables sample:


#include <iostream>
using namespace std;

int main ()
{
  // declaring variables:
  int a, b;
  int result;

  // process:
  a = 5;
  b = 2;
  a = a + 1;
  result = a - b;

  // print out the result:
  cout << result;

  // terminate the program:
  return 0;
}

Initialization

Initialization of variables, the initial value of a variable:


#include <iostream>
using namespace std;

int main ()
{
  // initialization of variables
  int a=5;               // initial value: 5
  int b(3);              // initial value: 3
  int c{2};              // initial value: 2
  int result;            // initial value undetermined

  a = a + b;
  result = a - c;
  cout << result; // the result is 6

  return 0;
}

Type deduction: auto and decltype


// auto
int foo = 0;
auto bar = foo;  // the same as: int bar = foo; 

//decltype
int foo = 0;
decltype(foo) bar;  // the same as: int bar; 

By |C++, Video Games Development|Commenti disabilitati su C++ – Variables and Datatypes

Unreal Game Engine – Create New Project an New Levels

Unreal Game Engine – Create New Project an New Levels

Create

1. File> New Project
2. New Project Window> Blank
3. Check ‘Include starter content’
4. Name: yournameProject
5. on the right click over the button to expand window and choose a Folder
6. click ‘Create Project’ button

Setup

The project will be opened, after that:

1. MAIN TOP MENU> Edit> Editor Preferences>
– General Appearance> User Interface> check ‘Use Small Tool Bar Icons’
– Loading & Saving > uncheck Autosave

2. MAIN TOP MENU> Edit> Project Settings>
– Game> Supported Platforms
– Engine> Input
– Platforms> iOS / Windows

Viewports

Setup Viewport

1. Window> Viewports> Viewport2
2. DRAG AND DROP the viewport label under TOP Toolbar to create a new stable window in the workarea

Levels

A videogame project can be divided in different levels: Level1, Level2, Level3 etc…

To create new levels: MAIN TOP MENU> File> New Level
To save levels: MAIN TOP MENU> File> Save or Save As… -> Unreal will create the file ‘Level1.umap’ (Unreal Map)

By |Unreal Engine, Video Games Development|Commenti disabilitati su Unreal Game Engine – Create New Project an New Levels

Unreal Engine – Installation and folder structure

Unreal Engine – Installation and folder structure

Installation

1. Install Visual C++ Redistributable Packages for Visual Studio 2013, you can find it at: http://www.microsoft.com/en-us/download/details.aspx?id=40784

Download and install vcredist_x64.exe for 64 bit OS

The Visual C++ Redistributable Packages install run-time components that are required to run C++ applications that are built by using Visual Studio 2013.

If you do not install the package you will have the message ‘MSVCP120.dll is missing from your computer’.

2. Install Unreal Engine

Installation Folder Structure

If you use the installation folder C:/UnrealEngine, you will find some important folders inside:

/Engine/Binaries/Win64/UE4Editor.exe -> execute this to start the editor

/Samples/StarterContent
/Architecture -> *.uasset (unreal assets) – risorse
/Audio
/Blueprints
/Maps
/Materials
/Particles
/Props
/Shapes
/Textures

/Templates
/TP_2DSideScroller -> based on C++ -> you need Visual Studio 2013 installed to compile
/TP_2DSideScrollerBP -> based on Blue Print -> visual scripting, do not require additional software
/TP_FirstPerson
/TP_FirstPersonBP

Project Folder Structure

If you store your project on D:/Unreal you will find

/Yourproject
/YourProject.uproject (unreal project)
/Config -> configuration files for Editor, Engine, Game, Input
/Content -> your *.uasset, Animations, Architecture, Audio etc…
/DerivatedDataCache
/Intermediate
/Saved

By |Unreal Engine, Video Games Development|Commenti disabilitati su Unreal Engine – Installation and folder structure

Unreal Game Engine – C++ – Variables

Unreal Game Engine – C++ – Variables

You have to declare variables in your header file, see the sample below:

HelloWorldPrinter.h


#pragma once

#include "GameFramework/Actor.h"
#include "HelloWorldPrinter.generated.h"

/**
*
*/
UCLASS() // Questo rende Unreal Engine consapevoli della vostra nuova classe
class CODETESTPROJECT_API AHelloWorldPrinter : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY() // Questo rende Unreal Engine consapevole della vostra nuova proprietà

	int32 MyNumberInt;   // declare an integer variable, 32-bit unsigned
	float MyNumberFloat; // declare a float number

	virtual void BeginPlay() override;


};// END UCLASS

To display variables values use your source file, see the sample below:


#include "CodeTestProject.h"
#include "HelloWorldPrinter.h" 

//Your class constructor
AHelloWorldPrinter::AHelloWorldPrinter(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
	MyNumberInt = 12;
	MyNumberFloat = 4.5;
}

// Dichiara la funzione - eseguita in BeginPlay() che è la funziona che unreal esegue all'inizio del game
void AHelloWorldPrinter::BeginPlay()
{
	Super::BeginPlay();

	if (GEngine) // Controllo se è valido l'oggetto globale GEngine
	{
		// Visualizza il testo a video
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("My Variables: "));
		// Visualizza le varibili - key - time - color - string - variable
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNumberInt));
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::SanitizeFloat(MyNumberFloat));
	
	}
}

The result is:
4.5
12
My Variables:

NOTA BENE: sono messaggi di debug, vengono dati in sequenza, quello più in alto è l’ultimo.

By |Unity3D, Video Games Development|Commenti disabilitati su Unreal Game Engine – C++ – Variables