Jump to content
  • Advertisement
Juku Patka

C++ Handling Input without libraries (Custom Engine)

This topic is 378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi

I have been planning to start developing my own 2D engine in C++ with my friend. The plan is to have have engine handle user input, display 2D art, play simple audio and work on Android and Windows by next Summer.

 

For starters I think that I'll need a way to handle input. I DON'T want to use libraries like SDL, so where should I start? IF I have to use libraries, they must be header-only. I don't want to have dependencies. I know how to read input with cin, but games require real-time input. So, what is good place to start handling input for both Windows and Android?

Share this post


Link to post
Share on other sites
Advertisement
38 minutes ago, Juku Patka said:

So, what is good place to start handling input for both Windows and Android?

SDL. Or an equivalent cross-platform windowing and input abstraction (SFML might also work on Android).

Could you build windowing and input from scratch for each platform? Sure, but that means learning two entirely distinct APIs, and possibly multiple programming languages (since most Android APIs are geared at Java). In the end, you'll build something that works about as well as SDL, and you'll have done that instead of actually writing an engine (or game!).

Dependencies aren't evil. They exist to allow you to get to the actual job of writing software. Would you try and program without the standard library? Without a compiler? Without a text editor? Carl Sagan has something to say on the topic.

If you really want to do this from scratch, you'll need the Android input APIs, and the Win32 Input APIs.

You'll need to write a separate implementation for each, and conditionally compile just the one you need on each platform. You'll also need similarly separate implementations for each platform to get a window in which to receive input in the first place.

Share this post


Link to post
Share on other sites

SDL is great, but it has so much stuff that I don't think I'll ever use. (Inb4 BOOST HAS DIS AWSUM FEATURE). Window making is done by my friend with help from his teacher earlier this year, and it uses OpenGL.

If you can suggest input library with few files and free license, I'll be happy to use it, or if there is way to take only the input-handling files from SDL without anything else I'll be happy to use  it.

Share this post


Link to post
Share on other sites
3 hours ago, Juku Patka said:

Window making is done by my friend with help from his teacher earlier this year, and it uses OpenGL

If your friend has already figured out how to make an OpenGL context from scratch on both Windows and Android, then input is a pretty trivial addon. The links to the APIs I provided above should be easy to plug in since you will already have the message/event loop up and running.

Share this post


Link to post
Share on other sites

Android development is not that hard as it sounds and does not (or at least need some little) Java because NDK could handle calls into C++ code compiled for Unix platforms (as Android is build up on the Linux kernel) and so same is for input. I wont go for the "API's" @swiftcoder mentioned rather than utilize the HID capabilities of Windows/Unix. They are a lot faster and you could handle device/platform specific stuff like multitouch on your own even if that sounds like a lot more of work it isnt and there already exists wrapper libraries arround this too or you go for your own implementation in less than 7 header files and a platform specific cpp file for each platform for a full functional input system. I used it in my game engine/framework as base input system (setting up event driven manager classes on top to handle certain callback functions as 'Actions' to be executed).

Note that you will need some platform specific headers for this and the Windows Driver SDK for Windows while HID is a driver level implementation here. There exists a tutorial I think is the best tutorial I found so far (even it is not english) for Windows focusiing on Gamepad/Controller input but Mouse/Keyboard and Touch Display work the same way very well.

The extra work is worth it, trust me :)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!