How C++ Resolves a Function Call
Preshing on Programming
by Jeff Preshing
3y ago
C is a simple language. You’re only allowed to have one function with each name. C++, on the other hand, gives you much more flexibility: You can have multiple functions with the same name (overloading). You can overload built-in operators like + and ==. You can write function templates. Namespaces help you avoid naming conflicts. I like these C++ features. With these features, you can make str1 + str2 return the concatenation of two strings. You can have a pair of 2D points, and another pair of 3D points, and overload dot(a, b) to work with either type. You can have a bunch of array-like cl ..read more
Visit website
Flap Hero Code Review
Preshing on Programming
by Jeff Preshing
3y ago
Flap Hero is a small game written entirely in C++ without using an existing game engine. All of its source code is available on GitHub. I think it can serve as an interesting resource for novice and intermediate game developers to study. In this post, I’ll explain how Flap Hero’s code is organized, how it differs from larger game projects, why it was written that way, and what could have been done better. Very little information in this post is specific to C++. Most of it would still be relevant if Flap Hero was written in another language like C#, Rust or plain C. That said, if you browse (o ..read more
Visit website
A Small Open Source Game In C++
Preshing on Programming
by Jeff Preshing
3y ago
I just released a mobile game called Flap Hero. It’s a Flappy Bird clone with cartoony graphics and a couple of twists: You can go in the pipes (wow!) and it takes two collisions to end the game. Flap Hero is free, quick to download (between 3 - 5 MB) and opens instantly. Give it a try! Flap Hero is open source, too. Its source code is released under the MIT license and its assets (3D models, sounds, music) are dedicated to the public domain. Do whatever you want with them! Everything’s available on GitHub. I’m releasing this game to promote Plywood, a Patreon-supported open source C++ fram ..read more
Visit website
Automatically Detecting Text Encodings in C++
Preshing on Programming
by Jeff Preshing
4y ago
Consider the lowly text file. This text file can take on a surprising number of different formats. The text could be encoded as ASCII, UTF-8, UTF-16 (little or big-endian), Windows-1252, Shift JIS, or any of dozens of other encodings. The file may or may not begin with a byte order mark (BOM). Lines of text could be terminated with a linefeed character \n (typical on UNIX), a CRLF sequence \r\n (typical on Windows) or, if the file was created on an older system, some other character sequence. Sometimes it’s impossible to determine the encoding used by a particular text file. For example, supp ..read more
Visit website
I/O in Plywood
Preshing on Programming
by Jeff Preshing
4y ago
Plywood is an open-source C++ framework I released a few weeks ago. It includes, among other things, a runtime module that exposes a cross-platform API for I/O, memory, threads, process management and more. This post is about the I/O part. For those who don’t know, I/O stands for input/output, and refers to the part of a computer system that either writes serialized data to or reads serialized data from an external interface. The external interface could be a storage device, pipe, network connection or any other type of communication channel. Typically, it’s the operating system’s responsibil ..read more
Visit website
A New Cross-Platform Open Source C++ Framework
Preshing on Programming
by Jeff Preshing
4y ago
For the past little while – OK, long while – I’ve been working on a custom game engine in C++. Today, I’m releasing part of that game engine as an open source framework. It’s called the Plywood framework. View the documentation View on GitHub Please note that Plywood, by itself, is not a game engine! It’s a framework for building all kinds of software using C++. For example, Plywood’s documentation is generated with the help of a C++ parser, formatted by a Markdown parser, and runs on a custom webserver all written using Plywood. Integrating third-party libraries can a pain in C++, but Ply ..read more
Visit website
A Flexible Reflection System in C++: Part 2
Preshing on Programming
by Jeff Preshing
4y ago
In the previous post, I presented a basic system for runtime reflection in C++11. The post included a sample project that created a type descriptor using a block of macros: // Define Node's type descriptor REFLECT_STRUCT_BEGIN(Node) REFLECT_STRUCT_MEMBER(key) REFLECT_STRUCT_MEMBER(value) REFLECT_STRUCT_MEMBER(children) REFLECT_STRUCT_END() At runtime, the type descriptor was found by calling reflect::TypeResolver<Node>::get(). This reflection system is small but very flexible. In this post, I’ll extend it to support additional built-in types. You can clone the project from GitHub to f ..read more
Visit website
A Flexible Reflection System in C++: Part 1
Preshing on Programming
by Jeff Preshing
4y ago
In this post, I’ll present a small, flexible system for runtime reflection using C++11 language features. This is a system to generate metadata for C++ types. The metadata takes the form of TypeDescriptor objects, created at runtime, that describe the structure of other runtime objects. I’ll call these objects type descriptors. My initial motivation for writing a reflection system was to support serialization in my custom C++ game engine, since I have very specific needs. Once that worked, I began to use runtime reflection for other engine features, too: 3D rendering: Every time the game eng ..read more
Visit website
How to Write Your Own C++ Game Engine
Preshing on Programming
by Jeff Preshing
4y ago
Lately I’ve been writing a game engine in C++. I’m using it to make a little mobile game called Hop Out. Here’s a clip captured from my iPhone 6. (Unmute for sound!) Hop Out is the kind of game I want to play: Retro arcade gameplay with a 3D cartoon look. The goal is to change the color of every pad, like in Q*Bert. Hop Out is still in development, but the engine powering it is starting to become quite mature, so I thought I’d share a few tips about engine development here. Why would you want to write a game engine? There are many possible reasons: You’re a tinkerer. You love building system ..read more
Visit website
Can Reordering of Release/Acquire Operations Introduce Deadlock?
Preshing on Programming
by Jeff Preshing
4y ago
I wasn’t planning to write about lock-free programming again, but a commenter named Mike recently asked an interesting question on my Acquire and Release Semantics post from 2012. It’s a question I wondered about years ago, but could never really reconcile until (possibly) now. A quick recap: A read-acquire operation cannot be reordered, either by the compiler or the CPU, with any read or write operation that follows it in program order. A write-release operation cannot be reordered with any read or write operation that precedes it in program order. Those rules don’t prevent the reordering of ..read more
Visit website

Follow Preshing on Programming on FeedSpot

Continue with Google
Continue with Apple
OR