Add misc and sfml modules with initial implementations, including new classes, assets, and CMake integration.

This commit is contained in:
2026-02-27 16:02:24 +01:00
parent 939e98d5b2
commit 8c726d9cb5
883 changed files with 365 additions and 5 deletions
+1
View File
@@ -5,3 +5,4 @@ add_subdirectory(intro)
add_subdirectory(pointer)
add_subdirectory(classes)
add_subdirectory(containers)
add_subdirectory(misc)
+1 -1
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 4.1)
project(containers)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS -pedantic-errors)
add_executable(containers main.cpp
+17 -2
View File
@@ -26,7 +26,7 @@ int main() {
printArrayAtPosition(numbers, 19);
// vector
std::vector<int> v;
std::vector<int> v = {1, 2, 3, 4, 5};
v.push_back(10);
v.push_back(20);
v.push_back(30);
@@ -54,12 +54,27 @@ int main() {
printArrayAtPosition(v.data(), 1);
// list
std::list<int> l;
std::list<int> l = {1, 2, 3, 4, 5};
l.push_front(0);
std::list<int>::iterator it;
for (it = l.begin(); it != l.end(); ++it) {
std::cout << *it << std::endl;
}
--it; --it;
l.insert(it, 100);
for (it = l.begin(); it != l.end(); ++it) {
std::cout << *it << std::endl;
}
--it; --it;
l.erase(it);
for (it = l.begin(); it != l.end(); ++it) {
std::cout << *it << std::endl;
}
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 4.1)
project(misc)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS -pedantic-errors)
add_executable(misc main.cpp
inlines.cpp)
+6
View File
@@ -0,0 +1,6 @@
#include "inlines.h"
#include <iostream>
void Value::Print() const {
std::cout << "Value: " << value << std::endl;
}
+22
View File
@@ -0,0 +1,22 @@
//
// Created by David Hackbarth on 27.02.26.
//
#ifndef MISC_INLINES_H
#define MISC_INLINES_H
class Value {
public:
Value(int val) : value(val) {} // implicit inline
int getValue() const { return value; } // implicit inline
// explicit inline, but redundant because it is already implicit inline
inline void setValue(int val) { value = val; }
inline void Print() const; // explicit inline
private:
int value;
};
#endif //MISC_INLINES_H
+64
View File
@@ -0,0 +1,64 @@
#include <iostream>
#include <ostream>
#include <random>
#include <chrono>
#include "inlines.h"
#include "structs_enums_unions.h"
#include "templates.h"
int main() {
int* pI = new int(0);
long* pL = new long(0);
safeDelete<int>(pI);
safeDelete(pL);
Node<int> n1(10);
Node<int> n2(20);
Node<int> n3(30);
n1.next = &n2;
n2.next = &n3;
// structs
Vector3 v1 = { 1.0f, 2.0f, 3.0f };
Vector3 v2 = { 4.0f, 5.0f, 6.0f };
bool isEqual = v1 == v2;
v1 = v1 * 3.0f;
v1 *= 3.0f;
Vector3 v3 = 3.0f * v2;
std::cout << "v1: " << v1 << std::endl;
// enums
Weekdays day = Weekdays::Friday;
std::cout << "day: " << day << std::endl;
// union
ScreenSize screen_size;
screen_size.u.width = 1920;
screen_size.u.height = 1080;
// screen_size.width = 1920;
// screen_size.height = 1080;
std::cout << sizeof(screen_size) << std::endl;
// inline
Value v(42);
v.setValue(69);
std::cout << "Value: " << v.getValue() << std::endl;
// random
// rand(); // old c implementation, don't use it
// srand(time(NULL)); // old c implementation, don't use it
std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_int_distribution<int> distribution(0,100);
std::cout << distribution(generator) << std::endl;
for (int i = 0; i < 10; i++) {
std::cout << distribution(generator) << std::endl;
}
return 0;
}
+63
View File
@@ -0,0 +1,63 @@
//
// Created by David Hackbarth on 27.02.26.
//
#ifndef MISC_STRUCTS_ENUMS_UNIONS_H
#define MISC_STRUCTS_ENUMS_UNIONS_H
#include <iostream>
struct Vector3 {
// public
float x, y, z;
bool operator==(const Vector3 &other) const {
return x == other.x && y == other.y && z == other.z;
}
bool operator!=(const Vector3 &other) const { return !(*this == other); }
bool operator<(const Vector3 &other) const { return x < other.x && y < other.y && z < other.z; }
bool operator>(const Vector3 &other) const { return other < *this; }
bool operator<=(const Vector3 &other) const { return !(*this > other); }
bool operator>=(const Vector3 &other) const { return !(*this < other); }
Vector3 operator*(float scalar) const { return {x * scalar, y * scalar, z * scalar}; }
void operator*=(float scalar) {
x *= scalar;
y *= scalar;
z *= scalar;
}
private:
// private
};
inline Vector3 operator*(float scalar, const Vector3 &v) { return v * scalar; }
inline std::ostream &operator<<(std::ostream &os, const Vector3 &v) {
os << "(" << v.x << "/" << v.y << "/" << v.z << ")";
return os;
}
enum Weekdays {
Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday,
FORCE_DWORD = 0x7fffffff // DWORD -> double word -> unsigned 32bit int, word -> unsigned 16bit int
};
union ScreenSize {
// struct {
// unsigned short width; // first 16bit
// unsigned short height; // second 16bit
// };
struct {
unsigned short width; // first 16bit
unsigned short height; // second 16bit
} u;
unsigned int value;
};
#endif //MISC_STRUCTS_ENUMS_UNIONS_H
+26
View File
@@ -0,0 +1,26 @@
//
// Created by David Hackbarth on 27.02.26.
//
#ifndef MISC_TEMPLATES_H
#define MISC_TEMPLATES_H
template<class T>
void safeDelete(T*& pObj)
{
if (pObj != nullptr)
{
delete pObj;
pObj = nullptr;
}
}
template<class T>
class Node {
public:
T data;
Node* next;
Node(T data) : data(data), next(nullptr) {}
};
#endif //MISC_TEMPLATES_H
+23
View File
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.28)
project(CMakeSFMLProject LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include(FetchContent)
FetchContent_Declare(SFML
GIT_REPOSITORY https://github.com/SFML/SFML.git
GIT_TAG 3.0.2
GIT_SHALLOW ON
EXCLUDE_FROM_ALL
SYSTEM)
FetchContent_MakeAvailable(SFML)
add_executable(main src/main.cpp
src/elements/Paddle.cpp
src/elements/Paddle.h
src/elements/Ball.cpp
src/elements/Ball.h)
target_compile_features(main PRIVATE cxx_std_17)
target_link_libraries(main PRIVATE SFML::Graphics)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT main)
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Some files were not shown because too many files have changed in this diff Show More