Piero V.

I have become a professional FOSS developer

I had the luck to get to know free and open source software when I was still a kid. In this way, the willingness to share my knowledge became a part of my culture and personality.

If you browse this site, you will see that I have shared a lot of small projects, like FlatPress plugins. However, I have never been a long-time contributor to a big project.

Moreover, at the end of my University course of study, I had to do an internship to graduate. I went to a software company that creates proprietary programs for the enterprise. I remained for six months and then was hired as an employee, and I stayed for another two years.

I was on a small team developing a CAD, and I enjoyed working with my coworkers a lot (even though I worked remotely for most of the two years because of COVID).

But I did not like using proprietary libraries.

One of them was Parasolid, a geometry kernel developed by Siemens. It is powerful, but some functions are overly complicated to use. It comes with very prolific documentation, and its subscription includes technical support. But it is the only way to troubleshoot your problems: I could never find any public information online, which is extremely surprising in the 2020s! … [Leggi il resto]

Back to Rust again

In 2010 I tried to program a video game with a friend for the first time. And it was our first time with C++, too. Of course, it was C++2003 since C++11 was the new-not-yet-stable thing.

I must say that our approach was quite naive. For example, we thought we would always play the game on a LAN. Thus, we never worried about lag compensation.

Now, a few years have passed, and I have learned a thing or two, even though I still have to finish a game project.

So, at the beginning of this year, this friend pushed me to learn Rust, and I decided to learn it through game development again.

At a certain point, I decided to use a physics engine, and I found Rapier. I was especially interested in its determinism to finally implement a lag compensation mechanism. But I did not understand how to use it correctly. Only recently, I understood it favors an approach similar to functional programming, whereas I was trying an OOP-like approach. This also led to fights with the borrow checker. So, because of these problems and my usual decrease in interest and focus, I left yet another project incomplete. … [Leggi il resto]

VBO multipli con OpenGL ES 2.0

Emscripten e WebAssembly

Di recente ho iniziato un nuovo progettino, per il quale sto usando SDL e OpenGL ES 2.0.

Durante il lockdown, avevo imparato a fare qualcosa di base con OpenGL 3.3, e avevo usato sempre SDL e un po’ Bullet, ma poi avevo lasciato stare il tutto. Adesso ho ricominciato, ma con OpenGL ES 2.0 perché offre una possibilità molto interessante: con Emscripten, si può compilare il progetto per WebAssembly, e GLES 2.0 viene trasformato direttamente in WebGL.

Pur non essendo più molto appassionato di sviluppo web, questa cosa mi attrae particolarmente. Innanzitutto, pubblicando sul web si possono raggiungere più persone, anche per il solo fatto che aspettare qualche secondo che si carichi una pagina è molto meno impegnativo che far scaricare uno zip, decompattarlo, e far avviare il programma. E non parliamo nemmeno degli installanti…

Il codice può essere sviluppato praticamente in qualsiasi linguaggio (C, C++, o qualcosa che abbia un interprete/una VM scritta in questi linguaggi), ma poi si può interfacciare al JavaScript che gira nel browser. Questo vuol dire che potrei fare le parti di rendering 3D in C++, ma le parti di UI in HTML, CSS e JavaScript. Le ultime volte che ho provato a fare qualcosa in JS mi sono stufato subito, però, per fare UI, lo stack web ha pochi eguali. … [Leggi il resto]

A dynamic character controller for Bullet?

Or, how I tried to create a dynamic character controller for Bullet, but eventually (almost?) gave up.

Motivations

I like spending some time using the Bullet physics library, I already wrote some articles about my experiments with it. This time, I wanted to create a custom character controller.

Bullet alread provides a (kinematic) character controller, but in general it is not regarded as a good one. I also tried to study a bit its code, but, in my opinion, it adds many complications without reason, and even something like managing in the correct way the velocity is a big problem with it. Indeed, Erwin Coumans himself (the main Bullet developer) said that btKinematicCharacterController is not supported anymore.

Therefore I decided to write my own one.

There are two kinds of character controller: kinematic ones and dynamic ones.

The former use the Physics engine, if any, just for collisions, and compute all the movements by themselves. This was the only way at the beginning of the video games, since there was not any Physics engine at all, but only some code for specific purposes. … [Leggi il resto]

C++ Logger

Ultimamente non stavo più andando avanti con progetti di programmazione, ma, riprendendo, ho sentito la necessità di fare un buon sistema di logging basato sugli stream di C++.

In passato avevo già affrontato l’argomento, ma questa è stata una sfida per vedere se riuscivo a fare tutto da capo e da solo. Ce l’ho fatta, così ho deciso di pubblicare qui i risultati.

Come requisiti ho tenuto in mente la versatilità e la sicurezza per l’uso con i thread.

La versatilità l’ho ottenuta mediante la divisione per modulo (per esempio networking, audio etc…) e livello (errore, informazione…). A coordinare tutto c’è il Log Manager, una classe che coordina i vari log. È un singleton (ottenuto tramite la mia classe allegata), e ritorna degli stream, uno per ogni coppia modulo-livello (che insieme fanno il LogId), assicurandosi che queste istanze siano uniche. Inoltre dispone di una funzione per mandare direttamente in output una stringa, dove in più si può specificare anche il file e la linea, magari usando le macro __FILE__ e __LINE__.

Ho pensato come vari output lo standard output e error, in più un file e un’eventuale consolle interna al programma, configurabili per ogni log, con una questa priorità: LogId > Modulo > Livello > Configurazione globale.

Come dipendenze ha gli smart pointer e i mutex/recursive mutex di Boost. Comunque se preferite e potete, C++11 ha integrato tutti questi componenti nella libreria standard, quindi potete usarli da là, ma sinceramente non ho provato a farlo.

Mancano, volendo, una funzione per impostare la configurazione “grezza” tramite gli enum e l’operatore OR e un controllo nei metodi overflow, xputn e sync della classe LogStreamBuf che ritornino subito se l’output è disabilitato, senza fare movimenti di memoria.

Ho fatto un paio di test anche con dei thread e non ho avuto problemi.

Non mi metto a scrivere tutte le funzioni perché mi pare siano già abbastanza spiegate nell’header 😉 .

Rilascio il materiale sotto il pubblico dominio.

Download: cpp_logger.tar.gz