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
+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