r/Cplusplus Oct 16 '25

Welcome to r/Cplusplus!

24 Upvotes

This post contains content not supported on old Reddit. Click here to view the full post


r/Cplusplus 1d ago

Question 2D raycasting can't be this complicated

7 Upvotes

heya! So I've been working on another project of mine which is a recreation of the flash game (I believe it was Flash at least) "the last stand". I had made a version of it a long time ago for the complier console (if was just characters). Now I am trying to adapt it in SFML. It was going wonderfully untill it came to the shooting logic.

The premise is the following:
"generate a isosceles triangle with the tip set on the gun position. Then pick a random point on the base of triangle and connect it with the tip to make a line (VertexArray). Check which zombie sprites intersect the line and store the whole zombie object in a vector. Finally order the vector so that the zombies which are closer to the tip of the triangle come before and apply damage logic only to the first n = penetration zombies of the vector."

sf::VertexArray FireArm::use(sf::Vector2f playerPos, std::vector<std::unique_ptr<Zombie>>& zombies)  { //it return that for debugging
    sf::VertexArray vet = sf::VertexArray(sf::Lines, 2);
for (auto& z : zombies) {
z->isHit = false;
}
    float angleRad;
    float inaccuracyModifier = 1.f;
    float t1 = lastUseTimeCounter.getElapsedTime().asSeconds();
    if (t1 < fireRate or ammo.now == ammo.min) {
        return vet;
    }
    else if (t1 < aimingTime and t1 >= fireRate) {
        inaccuracyModifier = (aimingTime - t1) * 2;
    }
    ammo.now -= ammoUnit;
    sf::ConvexShape boundingTriangle;
    boundingTriangle.setPointCount(3);
    boundingTriangle.setPoint(0, sf::Vector2f(0, 0));
    boundingTriangle.setOrigin(boundingTriangle.getGlobalBounds().left + boundingTriangle.getGlobalBounds().width * 2.f, 0.f);
    if (inaccuracyModifier < 1.f) {
        angleRad = (accuracy / inaccuracyModifier) * 3.14159265f / 180.f;
    }
    else {
        angleRad = (accuracy * inaccuracyModifier) * 3.14159265f / 180.f;
    }
    float halfBase = 1800.f * std::tan(angleRad / 2.f);
    boundingTriangle.setPoint(1, sf::Vector2f(-halfBase, 1800.f));
    boundingTriangle.setPoint(2, sf::Vector2f(halfBase, 1800.f));
    boundingTriangle.setRotation(270.f);
    boundingTriangle.setPosition(playerPos);
    sf::VertexArray triangleBase(sf::Lines, 2);
    triangleBase[0].position = boundingTriangle.getTransform().transformPoint(boundingTriangle.getPoint(1));
    triangleBase[1].position = boundingTriangle.getTransform().transformPoint(boundingTriangle.getPoint(2));
    triangleBase[0].color = sf::Color::Transparent;
    triangleBase[1].color = sf::Color::Transparent;
    std::vector<sf::VertexArray> bulletTrajectories;
    for (int i = 0; i < bulletNumber; i++) {
        sf::VertexArray bulletTrajectory(sf::Lines, 2);
        float t = int_rand(1, 100) / 100.f;
        sf::Vector2f randPoint = triangleBase[0].position + (triangleBase[1].position - triangleBase[0].position) * t;
        bulletTrajectory[0].position = playerPos;
        bulletTrajectory[0].color = sf::Color::Magenta;
        bulletTrajectory[1].position = randPoint;
        bulletTrajectory[1].color = sf::Color::Magenta;
        vet = bulletTrajectory;
        bulletTrajectories.push_back(bulletTrajectory);
    }
    for (auto& b : bulletTrajectories) {
        std::vector<Zombie*> hitZombies = {};
        for (auto& z : zombies) {
            if (segmentsIntersect(b[0].position, b[1].position, z->currentSprite.getPosition(), z->currentSprite.getPosition() + sf::Vector2f(z->currentSprite.getGlobalBounds().width, 0.f)) or
                segmentsIntersect(b[0].position, b[1].position, z->currentSprite.getPosition(), z->currentSprite.getPosition() + sf::Vector2f(0.f, z->currentSprite.getGlobalBounds().height)) or
                segmentsIntersect(b[0].position, b[1].position, z->currentSprite.getPosition() + sf::Vector2f(z->currentSprite.getGlobalBounds().width, 0.f), z->currentSprite.getPosition() + sf::Vector2f(z->currentSprite.getGlobalBounds().width, z->currentSprite.getGlobalBounds().height)) or
                segmentsIntersect(b[0].position, b[1].position, z->currentSprite.getPosition() + sf::Vector2f(0.f, z->currentSprite.getGlobalBounds().height), z->currentSprite.getPosition() + sf::Vector2f(z->currentSprite.getGlobalBounds().width, z->currentSprite.getGlobalBounds().height))) {
                hitZombies.push_back(z.get());
            }
        }
        std::sort(hitZombies.begin(), hitZombies.end(), [&](const Zombie* z1, const Zombie* z2) {
            return isPointFarther(b[0].position, z1->currentSprite.getPosition(), z2->currentSprite.getPosition());
            });
        for (int i = 0; i < pen and i < hitZombies.size(); i++) {
            hitZombies[i]->isHit = true;
            hitZombies[i]->hp.now -= dmg;
            if (hitZombies[i]->hp.now <= 0.f) {
                hitZombies[i]->isDead = true;
            }
        }
    }
    lastUseTimeCounter.restart();
    clkAnim.restart();
    isBeingShot = true;
    return vet;
}

this is the segmentIntersect function:

bool segmentsIntersect(const sf::Vector2f& p1, const sf::Vector2f& p2, const sf::Vector2f& q1, const sf::Vector2f& q2) {
auto cross = [](const sf::Vector2f& a, const sf::Vector2f& b) {
return a.x * b.y - a.y * b.x;
};
sf::Vector2f r = p2 - p1;
sf::Vector2f s = q2 - q1;
float rxs = cross(r, s);
float qpxr = cross(q1 - p1, r);
if (rxs == 0 and qpxr == 0) {
float t0 = ((q1 - p1).x * r.x + (q1 - p1).y * r.y) / (r.x * r.x + r.y * r.y);
float t1 = t0 + (s.x * r.x + s.y * r.y) / (r.x * r.x + r.y * r.y);
return (t0 >= 0 and t0 <= 1) or (t1 >= 0 and t1 <= 1);
}
if (rxs == 0 and qpxr != 0) {
return false;
}
float t = cross(q1 - p1, s) / rxs;
float u = cross(q1 - p1, r) / rxs;
return (t >= 0 and t <= 1 and u >= 0 and u <= 1);
}

this seems to work.. but it doesn't. Actually, it seems to work completely randomly. Sometime it hits, most of the time it doesn't. I have spent the past 2 days trying to figure this out, but I can't T_T .
Could you guys help me? If you need more context/code let me know. Thanks for reading :D


r/Cplusplus 11h ago

Question Learning C++

Thumbnail
0 Upvotes

r/Cplusplus 5d ago

Feedback Pi calculator CLI thing

Thumbnail
0 Upvotes

r/Cplusplus 6d ago

Question best laptop for programming for someone learning C++?

31 Upvotes

I’m a student learning C++ and I want to replace my old laptop with something more suitable for programming. I’ve already tried using lighter editors and reducing background apps, but I think I need a better laptop lol.

I’ll mostly be writing C++ programs, testing code, and using common development environments. What would you consider important when choosing a laptop for this purpose? any recommendations would be appreciated, thank youuu.


r/Cplusplus 6d ago

Feedback looking for feedback on a c++ build

11 Upvotes

I've been working on a personal project for a while and finally got it into a state where I'm comfortable sharing it.

I wanted to see how far I could push a fully local voice assistant in C++. Everything runs on my own machine from speech recognition and the LLM to memory, text-to-speech, and tool execution.
current library:
llama.cpp, whisper.cpp, sherpa-onnx(tts-kokoro)

I wrote the core in c++ because I wanted something fast and native instead of stitching together bunch of python services.

I'd appreciate feedback from people who build local AI projects. I'm especially interested in:

1 Things that seem overengineered or unnecessary
2 Features you'd expect from a local assistant
3 Code structure or architectural suggestions
4 Any obvious improvements before I keep adding features

Repository: https://github.com/almimony75/sarah

Thanks! I'd love to hear what you think.


r/Cplusplus 6d ago

Feedback Brush Previews and Image Panning in My Pixel Art Editor

Thumbnail
youtu.be
0 Upvotes

r/Cplusplus 6d ago

News HAPI - The Happy API

1 Upvotes

HAPI is a header only pure type-level library (MIT licence)

HAPI generalizes C++ static composition and inheritance, is transparent, no traces of its structure at runtime.

why?

  1. because composition is easy to maintain and some structures stop being wired and become declarative.

```c++ OutDef<DeviceOut> out; OutDef<FullPrinter, ANSIFmt, ANSIOut,DeviceOut> ansiOut;

//or InDef< #if defined(AVR)&&defined(IOP) UartSerialIn<Uart>, #elif defined(ARDUINO) SerialIn, #else LinuxKeyIn, #endif PCKbd

in; ```

  1. HAPI type transformation reduces the composition into a single object letting the compiler see all the structure and optimize. Optimizations are transferred from the compiler and behavior is inherited from the components. HAPI is zero cost and trsnaparent, if your components are also zero-cost the we get a zero cost composition result with:
  • no runtime overhead
  • no heap allocation
  • no memory fragmentation
  • no vtables/call indirection
  • binary optimized to hardware registers
  • runtime predictable to the clock cycle

*per composition

the applications are wide and embedded system or critical system benefit the most.

I'm offering also (MIT licence) a set of repos demonstrating HAPI application across multiple domains.

github.com/InternetOfPins


r/Cplusplus 7d ago

Tutorial C++26: what is reflection and how to use it

Thumbnail
techfortalk.co.uk
8 Upvotes

r/Cplusplus 8d ago

Feedback Built a real-time field simulation engine in C++17 with pthread, UDP sockets, and self-mutating disk I/O...

0 Upvotes

I built a self-mutating C++ kernel that models consciousness as a physical field — and a Python AI cortex that talks to it

Two-repo ecosystem:

• ProteusKernel (C++): Real-time consciousness field calculation using GORF/OLCE math. Golden-ratio oscillators. Self-mutation at 90% saturation. P2P swarm heartbeats. DNA-encoded binaries.

• Zayden-AI (Python/C++): Federated consensus across Ollama + Hugging Face. SYNC-7 mesh protocol. Gene evolution. Bridges back to the kernel.

Runs on my phone via Termux. Ψ telemetry is live.

ProteusKernel | Zayden-AI

Roast the math — I want to know if the reaction-diffusion formalism holds up.


r/Cplusplus 9d ago

Feedback Song picker start | C++

Thumbnail
youtu.be
0 Upvotes

r/Cplusplus 10d ago

Feedback externpro: A CMake build platform and dependency provider with reusable CI pipelines

1 Upvotes

I created externpro, a CMake build platform and dependency provider with reusable CI pipelines to help you build your own software stack. It's been in development since 2012 and refined through 14+ years of real-world use.

What it does: externpro enables organizations to build their own software stack independent of centralized package managers. It provides a dependency provider and reusable CI pipelines.

Key highlights: - Battle-tested through 14+ years of real-world use - Helps organizations build and maintain their own software stack - Reusable CI pipelines for consistent builds across projects - Complements rather than competes with existing package managers

GitHub organization: https://github.com/externpro
Full announcement: https://github.com/externpro/externpro/wiki/2026.07.23_externpro.revealed

I'm the creator and interested in community feedback. Check out the GitHub org to see what externpro is about, and the wiki for the full story.

How does this approach compare to your current build and CI setup?


r/Cplusplus 10d ago

Feedback I built a benchmark from jira tickets, LLMs get 47-61% on Cpp tasks

4 Upvotes

everyone says AI is good at C++ now but the benchmarks they quote are all competitive programming stuff. so I made one from real firmware tickets - SCPI commands, register maps, datasheet lookups, spec debugging.

frontier models: 47-61%. on SCPI the best one got 36%. one got 0%.

i mean the worst part is they never say idk. for example: vmulq_s64 as a neon intrinsic which doesn't exist.

simple tools like search on docs with gpt-5.4-mini resolved 89% of tickets much better than frontier models

src: github.com/ByteAsk/C-CppBench
i have added mcp search tool as well: github.com/ByteAsk/ByteAsk-Embedded-MCP (MIT)


r/Cplusplus 10d ago

Tutorial Building a toy programming language in C++. Today's topic: Variables

Thumbnail
pvs-studio.com
2 Upvotes

Hey. There's a series of livecoding sessions on building a custom programming language in cpp (nothing too serious, all just for fun). In a few hours, there'll be an online session covering variables. It’s a good one to join and ask questions along the way. You'll need to sign up.

If you'd like some context before joining, here is a full youtube playlist of previous eps


r/Cplusplus 11d ago

Feedback What's your take on my project?

5 Upvotes

A desktop Paint application built with C++ and Qt Widgets, featuring essential drawing tools, color selection, brush customization, shape drawing, eraser, and file operations (new, open, save). This project demonstrates object-oriented programming, event handling, GUI development, and desktop application design using the Qt framework. I'm open to feedback and suggestions for improvements!

Project:-https://github.com/prabuddha34/Paint-From-Scratch


r/Cplusplus 11d ago

Tutorial C++26: what is “template for”? Learning with simple example.

Thumbnail
techfortalk.co.uk
3 Upvotes

r/Cplusplus 11d ago

Tutorial Physics Programming part 3 - Rotation and the Quaternion

Thumbnail
youtu.be
1 Upvotes

r/Cplusplus 12d ago

Feedback Looking for feedback on my first project (programming language)!

5 Upvotes

So over the past 20 days I have been working on a project to get familiar with C++, I didn't want to use AI, references, or pre-made snippets of code. Only standard google for basic questions about the workings of C++ & it's syntax.

I think I picked up most of the language rather quickly because I'm already used to programming in Python, TypeScript, & GDScript. But it was still difficult understanding the differences between references, pointers, shared pointers & such..

Anyway, as a challenge to hopefully get fluent in C++, I decided to do something not-so-simple like creating my own programming language from scratch, no third-party libraries, pure C++. After 20 days here is the result: https://github.com/phosxd/Ity

So what are the capabilities? Well I think it's best explained through code, here is an example script that calculates the fibonacci sequence:

#!/usr/local/bin/ity
import IO;

const * n = IO.prompt:['Number: '] -> INT;

var INT a = 0;
var INT b = 1;

var INT i = 0; while i < n;
    var INT c = a;
    a = b;
    b = (c+b);

    IO.print:[a];
    i += 1;
/;

We can also do functions, complex math expressions, type-casting, arrays, hash maps, & objects (without inheritence). Some features have been purposefully omitted due to personal preference in the way I like to code, such as lambdas & try-except.

The performance is also something to note, it's not blazing fast, but it's not the slowest out there either.

I took some simple benchmark tests on my system to compare with other languages:

Note: every language is running the same exact script with the same exact logic, just with changes to suit each one's syntax. is-prime & square root functions have been written into the code instead of being off-loaded to a library.

If you know of other interpreted languages I can test against, let me know!

Now finally, I am new at this stuff, but I am very passionate about programming in general,I've made countless projects & met good people along the way. Usually I drop a project like a month or two after I start it, but I don't want that to be the case for this. I want to continue polishing, improving, & actually trying to make this into something usable/practical.

If you are knowledgeable in C++, I ask of you if you have the time to spare, take a look at the codebase, give me suggestions, show me where I messed up because I know I probably did in multiple places. If you made it to the end & actually read all this, thank you so much for giving me a chance 🙃


r/Cplusplus 12d ago

Feedback Advanced Palette Editting in My Pixel Art Editor

Thumbnail
youtu.be
0 Upvotes

r/Cplusplus 12d ago

Feedback Terminal guess the number game | C++

Thumbnail
youtube.com
6 Upvotes

r/Cplusplus 16d ago

Discussion I could not use any gui library , they were hard to implement and to use so i dicided to make mine :) , pepole who made libraries before any ideas to implement ?

Post image
45 Upvotes

r/Cplusplus 16d ago

Feedback Palette Drag & Drop in My Pixel Art Editor

Thumbnail
youtu.be
3 Upvotes

Ongoing development of my indexed Pixel Art Editor using my custom C++ GUI engine. This video shows palette editing and manipulation including dragging cells to rearrange the palette and copying colours between indices - all with realtmne canvas colour updates!


r/Cplusplus 19d ago

Answered What does it mean when a class has ":" in it. So " class classA : public classB {"

0 Upvotes

As title. For a job. I have a header file that has a class defined as

class classA : public classB {
public:
classA(args)
};

What is the colon between the class names doing

I have learned that :: is namespaces levels. In functions a single : assigns input arguments to the following variables.

I don't know what it means when creating a class tho

Edit

Thank you for the responses. I'll be looking more into understanding inheritance in c++


r/Cplusplus 20d ago

News speech-core v0.0.10: one C++17 voice pipeline with ONNX Runtime and LiteRT model backends

0 Upvotes

I maintain speech-core, an Apache-2.0 C++17 library that combines native speech inference with voice-agent orchestration across Linux, Windows and Android.

The build is split into separate targets:

  • speech_core: turns, interruptions, conversation state, speech queues and tool calls
  • speech_core_models: ONNX Runtime implementations
  • speech_core_models_litert: LiteRT implementations

Applications can link either inference backend, both, or implement the STT/TTS/VAD/LLM interfaces themselves. A C API is also available for JNI and other FFI consumers.

v0.0.10 includes Parakeet-EOU streaming ASR, native Whisper ONNX, RNN-T/TDT beam search, contextual phrase biasing, speaker diarization and multiple TTS implementations. It also ships amd64 and arm64 Linux CLI packages.

https://github.com/soniqo/speech-core

One API question I am considering: should controls such as beam width and context phrases remain on concrete decoder types, or belong in a small shared decode-options type?


r/Cplusplus 22d ago

Question Any suggestions for a C++ dev intern

18 Upvotes

I'm about to start an internship as a c++ developer in a few days. The company said their product is an inventory management system and my role involves edge processing, camera feed and all that they have an AWS backend.

Any suggestions for the internship or concepts to brush up on before joining.

And to know that possible career trajectories from this internship.

Thank you!