


해당 모델 vertis 및 faces 정보 표시
Edit > Preferences > Interface > Status Bar > Scene Statistics 체크
그냥 나오는 정보는 씬 전체 오브젝트에 대한 정보. Edit 모드를 들어가야 해당 오브젝트에 대한 정보가 표시됨.

최적화 팁
: 지금 import한 texture의 resolution은 2048x2048(2k)인데, Max Size를 1024(1K)로 줄이면 퀄리티의 차이는 거의 없으면서 용량은 줄어든다





c++에서도 malloc과 free 쓸 수 있는데
언어 차원에서 new와 delete를 지원함.
#include <iostream>
int main() {
int* p = new int;
*p = 10;
std::cout << *p << std::endl;
delete p;
return 0;
}
배열도 할당 가능
int main() {
int arr_size;
std::cout << "array size : ";
std::cin >> arr_size;
int* list = new int[arr_size];
for (int i = 0; i < arr_size; i++) {
std::cin >> list[i];
}
for (int i = 0; i < arr_size; i++) {
std::cout << i << "the element of list : " << list[i] << std::endl;
}
delete[] list;
return 0;
}
class Animal {
private:
int food;
int weight;
public:
void set_animal(int _food, int _weight) {
food = _food;
weight = _weight;
}
void increase_food(int inc) {
food += inc;
weight += (inc / 3);
}
void view_stat() {
std::cout << "이 동물의 food : " << food << std::endl;
std::cout << "이 동물의 weight : " << weight << std::endl;
}
};
int main() {
Animal animal;
animal.set_animal(100, 50);
animal.increase_food(30);
animal.view_stat();
return 0;
}
c++에선 new 이런거 없이 그냥 선언 가능함?
C++에서는 클래스 객체를 생성할 때 기본적으로 스택 메모리에 할당됩니다. 따라서 new를 사용하지 않아도 자동으로 생성됩니다. 이것이 C#과는 큰 차이점 중 하나입니다.
C++에서는:
1. 스택 메모리에 객체를 생성(기본 방식).
2. 필요한 경우에만 new를 사용해 힙 메모리에서 동적 생성.
C#에서는 객체 생성 시 무조건 힙 메모리에 동적 할당됩니다. 따라서 new 키워드 없이 객체를 생성할 수 없으며, 메모리는 가비지 컬렉터(GC)가 자동으로 관리합니다.
void print(int x) { std::cout << "int : " << x << std::endl; }
void print(char x) { std::cout << "char : " << x << std::endl; }
void print(double x) { std::cout << "double : " << x << std::endl; }
int main() {
int a = 1;
char b = 'c';
double c = 3.2f;
print(a);
print(b);
print(c);
return 0;
}
매개변수 달라지면 함수 작동 방식도 달라지게 하는 오버로딩 c++ 구현 예시
void print(int x) { std::cout << "int : " << x << std::endl; }
void print(char x) { std::cout << "char : " << x << std::endl; }
int main() {
int a = 1;
char b = 'c';
double c = 3.2f;
print(a);
print(b);
print(c);
return 0;
}
정확히 일치하는거 못 찾으면 컴파일러가 비슷한 자료형으로 바꾸는데,
이 경우엔 c를 int로도 바꿀 수 있고 char로도 바꿀 수 있어서 애매해지니까 오류 발생.
#include <iostream>
class Date {
int year_;
int month_;
int day_;
public:
void ShowDate() {
std::cout << "year_ : " << year_ << std::endl;
std::cout << "month_ : " << month_ << std::endl;
std::cout << "day_ : " << day_ << std::endl;
}
Date(int year, int month, int day) {
year_ = year;
month_ = month;
day_ = day;
}
};
int main() {
Date day(2011, 3, 1);
day.ShowDate();
return 0;
}
생성 후 초기화해주는 생성자 함수
Date() {
year = 2012;
month = 7;
day = 12;
}
이런 디폴트 생성자 정의해놓고
Date day = Date();
Date day2;
이렇게 하면 무리없이 객체 생성되는데
Date day3();
이렇게 하면 Date 자료형을 반환하는 day3() 함수를 선언하게 되니까 조심
#include <iostream>
class Marine {
int hp;
int coord_x, coord_y;
int damage;
bool is_dead;
public:
Marine();
Marine(int x, int y);
int attack();
void be_attacked(int damage_earn);
void move(int x, int y);
void show_status();
};
Marine::Marine() {
hp = 50;
coord_x = coord_y = 0;
damage = 5;
is_dead = false;
}
Marine::Marine(int x, int y) {
coord_x = x;
coord_y = y;
hp = 50;
damage = 5;
is_dead = false;
}
void Marine::move(int x, int y) {
coord_x = x;
coord_y = y;
}
int Marine::attack() { return damage; }
void Marine::be_attacked(int damage_earn) {
hp -= damage_earn;
if (hp <= 0) is_dead = true;
}
void Marine::show_status() {
std::cout << " *** Marine *** " << std::endl;
std::cout << " Location : ( " << coord_x << " , " << coord_y << " ) "
<< std::endl;
std::cout << " HP : " << hp << std::endl;
}
int main() {
Marine marine1(2, 3);
Marine marine2(3, 5);
marine1.show_status();
marine2.show_status();
std::cout << std::endl << "마린 1 이 마린 2 를 공격! " << std::endl;
marine2.be_attacked(marine1.attack());
marine1.show_status();
marine2.show_status();
}
왜 함수 선언 따로, 구현 따로 하는 거임?
C++에서 클래스 내부에 함수 구현을 작성하면 그 함수는 기본적으로 inline 함수로 간주됩니다.
Marine::는 범위 지정 연산자로, 클래스 외부에서 멤버 함수의 정의를 작성할 때 사용됩니다.
헤더와 소스 파일로 분리
int main() {
Marine* marines[100];
marines[0] = new Marine(2, 3);
marines[1] = new Marine(3, 5);
marines[0]->show_status();
marines[1]->show_status();
std::cout << std::endl << "마린 1 이 마린 2 를 공격! " << std::endl;
marines[0]->be_attacked(marines[1]->attack());
marines[0]->show_status();
marines[1]->show_status();
delete marines[0];
delete marines[1];
}
여러 개의 객체들을 배열에 넣어서 관리하는 예시
객체 생성할 때 new 쓰면 생성자 자동 호출해준다고 얘기하는데
생성자는 원래 자동으로 호출하지 않나? gpt한테 물어봤더니 자동 호출이 맞다고 하고, 이전 내용하고도 모순되는 내용이라 그냥 넘어가면 될듯?
Marine::Marine(int x, int y, const char* marine_name) {
name = new char[strlen(marine_name) + 1];
strcpy_s(name, strlen(marine_name) + 1, marine_name);
coord_x = x;
coord_y = y;
hp = 50;
damage = 5;
is_dead = false;
}
marine의 이름을 지정해주는 오버로드 추가
strcpy 썼더니 오류 남

https://seewol.tistory.com/163
이름 생성한 건 좋은데, Marine이 사라져도 new로 할당했던 name은 정리가 되질 않는다.
객체가 사라질 때 자동으로 호출되어 메모리 정리를 도와주는 함수가 소멸자.
Marine::~Marine() {
std::cout << name << " 의 소멸자 호출!" << std::endl;
if (name != NULL) {
delete[] name;
}
}
Photon_Cannon::Photon_Cannon(const Photon_Cannon& pc) {
std::cout << "복사 생성자 호출 !" << std::endl;
hp = pc.hp;
shield = pc.shield;
coord_x = pc.coord_x;
coord_y = pc.coord_y;
damage = pc.damage;
}
const로 인자를 받았기 때문에 기존 포톤 캐논을 변경할 순 없고, 값을 가져올 수만 있다.
Photon_Cannon pc1(3, 3);
Photon_Cannon pc2(pc1);
이렇게 하면 pc1이 복사되는 건 당연하고
Photon_Cannon pc3 = pc2;
이렇게 해도 pc2가 복사된다
Photon_Cannon pc3;
pc3 = pc2;
이렇게 하면 복사 생성자 호출 안된다.
그리고 사실 Photon_Cannon(const Photon_Cannon& pc) 이거 구현 안 해도 그냥 Photon_Cannon pc3 = pc2; 이렇게 적으면 복사 생성자 자동으로 만들어져서 대응되는 원소들이 복사된다.
근데 소멸자 때문에 오류 발생할 수 있다. 같은 char *을 멤버로 갖고 있는데 소멸자에서 메모리 할당 취소해버리면 다시 접근해서 할당 해제 하려다 오류 나버림.
name = new char[strlen(pc.name) + 1];
strcpy(name, pc.name);
이럴 땐 주소값 말고 값을 아예 복사해버리면 된다.
당연히 디폴트 복사 생성자는 안될 것.