handmade.network » Forums » Work-in-Progress » FPL - a single header platform abstraction c++ library
Finalspace
16 posts

I am finalspace and do programming since about 25 years, started on the C64 and got serious with borland delphi.

#13487 FPL - a single header platform abstraction c++ library
1 week, 1 day ago Edited by on Nov. 13, 2017, 4:24 p.m.

Hi

i wanted to present you my recent project i am working on which is a platform abstraction library.
This library is designed to be simple, non-bloated, can be included however you want and do not require any thirdparty libraries at all. It will simply abstract away all relevant platform specific things in a simple to use api without hiding any data. The main focus is game or simulation development, so you get a window and a rendering context.

Mindset:

- Its written in C++/98 mostly, but uses a few C++/11 features (constexpr, nullptr, enum class).
- The code style is C with C++ features, but no object orientation at all.
- There is just a single header file you have to include and thats it
- Its full open source, so you can use and extend it however you want
- No data hiding in the code, you have control over everything
- Uses just the built-in operating system functions/libraries and the C-Runtime library
- Works well with other libraries as well (ImGUI, Box2D, Glew, etc.)
- Some features can be compiled out as needed (Window, OpenGL, etc.)
- Easy to use api

Why:

- Learning C/C++ and low level programming
- Moving away from object orienation to data oriented programming
- Most platform abstraction libraries are bloated, have a bad api, cannot be debugged, have no control over memory

Features:

- Window creation and handling
- OpenGL legacy and modern rendering context creation
- Memory allocation and deallocation
- Timing operations
- Threading stuff (Incomplete)
- File/Path IO
- String conversion functions
- Atomic operations
- Dynamic library loading
- Console out
- Gamepad input

Current state / Planned:

- Finishing win32 platform implementation which is almost complete
- Linux and unix platform implementation
- Support for Direct3D/Vulcan (Only to get it up and running)
- Audio output (XAudio, ALSA)
- More Guides and Samples
- Let the user allocate memory for storing platform input events as well

History:

Initially the project was fully written with 100% C/89 compability in mind without needing the c-runtime library, but as i see myself always fighting against C or missing any features like console output, i decided to move to a minimal C++ version. Nowadays all compilers understand at least C++/11 - so writing plain C is just not needed, even though i dont like most features in C++.

Source:

https://github.com/f1nalspace/final_game_tech

Feedback/Comments:

I would like to know what you think about, what is missing, how can i improve it, what do you want from it, etc.
Finalspace
16 posts

I am finalspace and do programming since about 25 years, started on the C64 and got serious with borland delphi.

#13525 FPL - a single header platform abstraction c++ library
5 days, 11 hours ago

Update v0.4.0 alpha:

Changed: All FPL_ENABLE_ defines are internal now, the caller must use FPL_NO_ or FPL_YES_ respectivily.
Changed: AtomicCompareExchange is now AtomicCompareAndExchange
Changed: InitFlags::VideoOpenGL is now InitFlags::Video
Added: Software rendering support
Added: VideoDriverType enumeration for selecting the active video driver
Added: video::GetVideoBackBuffer with [Win32] implementation
Added: video::ResizeVideoBackBuffer with [Win32] implementation
Added: FPL_PETABYTES macro
Added: FPL_EXABYTES macro
Added: FPL_ZETTABYTES macro
Added: FPL_YOTTABYTES macro
Added: FPL_MIN macro
Added: FPL_MAX macro
Added: MutexCreate with [Win32] implementation
Added: MutexDestroy with [Win32] implementation
Added: MutexLock with [Win32] implementation
Added: MutexUnlock with [Win32] implementation
Added: SignalCreate with [Win32] implementation
Added: SignalDestroy with [Win32] implementation
Added: SignalWait with [Win32] implementation
Added: SignalWakeUp with [Win32] implementation
Added: GetClipboardAnsiText with [Win32] implementation
Added: GetClipboardWideText with [Win32] implementation
Added: SetClipboardText with [Win32] implementation for ansi and wide strings
Added [MSVC]: AtomicExchangeS32 (Signed integer)
Added [MSVC]: AtomicExchangeS64 (Signed integer)
Added [MSVC]: AtomicAddS32 (Signed integer)
Added [MSVC]: AtomicAddS64 (Signed integer)
Added [MSVC]: AtomicCompareExchangeS32 (Signed integer)
Added [MSVC]: AtomicCompareExchangeS64 (Signed integer)
Fixed [MSVC]: AtomicExchangeU32 was not using unsigned intrinsic
Fixed [MSVC]: AtomicExchangeU64 was not using unsigned intrinsic
Fixed [MSVC]: AtomicAddU32 was not using unsigned intrinsic
Fixed [MSVC]: AtomicAddU64 was not using unsigned intrinsic
Fixed [MSVC]: AtomicCompareExchangeU32 was not using unsigned intrinsic
Fixed [MSVC]: AtomicCompareExchangeU64 was not using unsigned intrinsic
Implemented [Win32]: GetProcessorCoreCount
Implemented [Win32]: Main thread infos
Performance [Win32]: GetProcessorName (3 loop iterations at max)

State:

Its almost feature complete for Win32, only audio output is missing.

Next i will clean up all the ifdef madness to get a more clean code structure - so i have a single ifdef block for each platform/backend. Also i am thinking about removing the sub namespaces, just because its so much useless typing for no reason.
Finalspace
16 posts

I am finalspace and do programming since about 25 years, started on the C64 and got serious with borland delphi.

#13538 FPL - a single header platform abstraction c++ library
3 days, 16 hours ago

Update v0.4.1 alpha:

Cleanup: Internal cleanup
Changed: All the settings constructors removed and replaced by a simple inline function.
Added: Added native C++ unit test project to demos solution
Fixed: FPL_OFFSETOF was not working
Fixed: All file size macros like FPL_MEGABYTES was returning invalid results.
Removed: FPL_PETABYTES and higher are removed, just because its useless.

State:

I cleaned up all the internals so i have a single block per platform and fixed some small bugs. Also i decided to continue with the subnamespace style - one nested level is fine. Next big thing will be audio output using directsound or xaudio and of course implementing the linux platform. But as for now it is working great, i use it in all my C++ stuff know.
mrmixer
Simon Anciaux
285 posts
#13551 FPL - a single header platform abstraction c++ library
2 days, 15 hours ago Edited by Simon Anciaux on Nov. 18, 2017, 2:35 p.m. Reason: Typo

Maybe support wasapi for audio as DirectSound and XAudio are built on top of it ?

As for the namespace things, have you considered that C doesn't support them ?
Finalspace
16 posts

I am finalspace and do programming since about 25 years, started on the C64 and got serious with borland delphi.

#13566 FPL - a single header platform abstraction c++ library
20 hours, 54 minutes ago Edited by on Nov. 20, 2017, 9:25 a.m.

mrmixer
Maybe support wasapi for audio as DirectSound and XAudio are built on top of it ?
As for the namespace things, have you considered that C doesn't support them ?


For audio and win32 i will definitly use directsound + optionally xaudio2.

And for regarding C-Support:

This library is C++/11 only. In the past it was C, but as i was fighting against C all the time i changed it to C++/11 - without introducing any oop concepts or using the std library.

Why:

- Automatic typedef for struct and enums
- constexpr for seeing the expanded constants automatically in the IDE (Very useful)
- Enum class for having proper type checking (Normal C/C++ enums are the worst in < C++/11).

I could live without:

- Method/Operator overloading (Op overload is required for enum class)
- Namespaces (Prevent name conflicts, Categorizing)