🕹️
Game Engine. hardCORE series
Udemy course / C++PatreonBoostyTelegramYouTube
  • 💻Lectures
    • 00. Promo
    • 01. What is game engine?
    • 02. C++ build process. Preprocessing
      • Preprocessor commands
      • Code
    • 03. C++ build process. Compilation Theory. Assembly
      • Compiler commands
      • Code
    • 04. C++ build process. Compiler optimizations
      • Compiler commands
      • Code
    • 05. C++ build process. Linker. Forward declaration
      • Compiler commands
      • Code
    • 06. C++ build process. Linker. Static and Dynamic libraries. PCH
      • Compiler commands
      • Code
      • Books
    • 07. СMAKE. Day1. Basics
      • CMAKE commands
      • Repository
    • 08. СMAKE. Day2. Libs
      • CMAKE commands
      • Repository
    • 09. Conan. C++ package manager
      • Conan commands
      • Repository
    • 10. Raylib. CMAKE additional topics
      • Repository
    • 11. Doodle Jump Game. Raylib. CMAKE pch and other topics
      • Repository
    • 12. Conan and CMAKE integration. Github workflows
      • Commands
      • Repository
    • 13. Engine. Layout
    • 14. Engine. Logging
    • 15. Engine. Window
    • 16. Engine. Window events. Input
  • Мои курсы
    • 🎮Unreal Engine — полное руководство по разработке на С++
    • 🧪Автоматизация и тестирование в Unreal Engine
    • 🔊Metasounds
    • 🏗️Design patterns
    • 🐍Snake game
    • 🧠OpenAI
  • LifeEXE сообщество
    • Ресурсы
Powered by GitBook
On this page
  • Math
  • Weapon
  • Character
  • Main
  • PCH
  1. Lectures
  2. 06. C++ build process. Linker. Static and Dynamic libraries. PCH

Code

Math

// Math.h
#pragma once
#include <vector>

#ifdef _EXPORTING
#define MATH_API    __declspec(dllexport)
#elif _IMPORTING
#define MATH_API    __declspec(dllimport)
#else
#define MATH_API
#endif

namespace LifeExe {
    MATH_API int max(int x, int y);
    MATH_API int factorial(int n);
    MATH_API int sum(int n);
    MATH_API std::vector<int> createLargeVector();
}
// Math.cpp
#include "Math.h"

namespace LifeExe {
    int max(int x, int y)
    {
        return x > y ? x : y;
    }

    int factorial(int n)
    {
        return n <= 1 ? 1 : n * factorial(n - 1);
    }

    int sum(int n)
    {
        return n <= 0 ? 0 : n + sum(n - 1);
    }

    std::vector<int> createLargeVector()
    {
        std::vector<int> vec(100000000, 12);
        return vec;
    }
}

Weapon

// Weapon.h
#pragma once

class Weapon
{
public:
    Weapon();
    void fire();

private:
    int m_bullets{ 23 };
};
// Weapon.cpp
#include "Weapon.h"

Weapon::Weapon()
{

}

void Weapon::fire()
{
    if (m_bullets <= 0) return;
    --m_bullets;
}

Character

// Character.h
#pragma once

#ifdef _EXPORTING
#define GAME_API    __declspec(dllexport)
#elif _IMPORTING
#define GAME_API    __declspec(dllimport)
#else
#define GAME_API
#endif

class Weapon;

class GAME_API Character
{
public:
    Character(const char* name);
    ~Character();

private:
    const char* m_name;
    Weapon* m_weapon;
};
// Character.cpp
#include "Character.h"
#include "Weapon.h"

Character::Character(const char* name) : m_name(name)
{
    m_weapon = new Weapon();
    m_weapon->fire();
}

Character::~Character()
{
    delete m_weapon;
    m_weapon = nullptr;
}

Main

// main.cpp

#include "Character.h"
#include "Math.h"
#include <iostream>

int main() {
    using namespace LifeExe;

    const int result1 = max(10, 20);
    const int result2 = factorial(10);
    const int result3 = sum(10);
    const int result = result1 + result2 + result3;
    std::vector<int> vec = createLargeVector();

    const Character character("Nux");

    std::cout << result << std::endl;
    std::cout << vec.size() << std::endl;
    std::cin.get();

    return 0;
}

PCH

// pch.h

#pragma once

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <memory>
#include <thread>
#include "Math.h"
#include "Character.h"
// pch.cpp
#include "pch.h"
PreviousCompiler commandsNextBooks

Last updated 9 months ago

💻