The Fundamentals of C/C++ Game Programming
The Fundamentals of C/C++ Game Programming
Using Target-Based Development on SBCs
Brian Beuken
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
2018 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
No claim to original U.S. Government works
Printed on acid-free paper
International Standard Book Number-13: 978-1-4987-8874-8 (Paperback)
978-0-8153-5527-4 (Hardback)
This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe.
Library of Congress Cataloging-in-Publication Data
Names: Beuken, Brian, author.
Title: The Fundamentals of C/C++ Game Development : using Target-based Development on SBCs / Brian Beuken.
Description: First edition. | Boca Raton, FL : CRC Press, Taylor & Francis Group, 2018. | A CRC title, part of the Taylor & Francis imprint, a member of the Taylor & Francis Group, the academic division of T&F Informa plc.
Identifiers: LCCN 2017048100 | ISBN 9781498788748 (pbk. : acid-free paper) |
ISBN 9780815355274 (hardback : acid-free paper)
Subjects: LCSH: Computer games--Programming. | C (Computer program language) | C++ (Computer program language)
Classification: LCC QA76.76.C672 B49 2018 | DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2017048100
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Contents
Who Is This Book for?
The Fundamentals of C/C++ Game Programming: Using Target-Based SBCs , is quite a mouthful, isnt it, as a title, its also making a few promises that it probably cant keep, because there are so many definitions of what are the fundamental skills a game programmer needs to have. But its my view that there are a few things that can get people up and running and develop their hunger for learning, and its those things I want to bring to you here. This is for people who want to be game programmers, but probably dont quite know how to do it or feel a little daunted that their coding skills dont really let them explore their game-creation skills. Although this is very much a beginners book, it is not really aimed at a total novice who has never programmed before; you should be able to understand at least the basic concepts and syntax of C/C++ programming.
There are some excellent beginners books that I recommend to all my students, such as Michael Dawsons excellent Beginning C++ Through Game Programming (2014; Cengage Learning; Australia), which though it throws little light on actual graphic gaming, is a superb foundation for C++. I will give some very simple getting-started examples and build on those, so even the most code wary the beginner, should pick things up as they go.
None of the code in this book is complex, indeed it can be comfortably argued that its oversimplified, its designed as a jumping-off point for a novice to expand their knowledge and most of the initial explanations are going to be understandable even for a total beginner. Ill start slowly and explain much at first, but the pace will pick up as we get going and Ill let the online source code go into more detail as I explain the overall intent of what we are doing rather than the specific functions. If you still dont understand the syntax of the code, you should undertake a beginners coding course, there are several online.
In addition, despite the title, this isnt a book solely about programming Single Board Computers (SBCs). The use of a cheap target system is a means to an end to encourage the reader to limit expectations and work within tight constraints, which game programmers, especially console programmers have to work with. I want primarily to focus on gameplay concepts and game structures, which will let us get games up and running really quickly. However, we do have to introduce some technical concepts later, when were a bit more comfortable, because most of these technical concepts will have a direct impact on the performance of your games. You will need to know just enough to avoid some pitfalls and get things up and running correctly.
SBCs are usually quite simple systems, so building a working knowledge of the fairly generic hardware to produce graphics, sound, and data storage is generally easier to learn on them, than it would be on your up to the minute PC, which will shield you from errors by virtue of massive processing performance and near unlimited memory.
Once understood, all of the concepts and projects in this book are easily transferrable to any development target where the reader can stretch their growing skills on more powerful systems while still being mindful of the need to work within constraints of hardware, which are hard to push, and personal limits, which should always be pushed.
But SBCs are really fun to work with, cheap to acquire, and present a real sense of achievement when you make them to do more than just act as media servers or control units.
Most important, this is not a how to do x, with y kind of book. I want to take you through a journey of discovery, mine as well as yours, and provide suggestions and working examples on how to do things that games need, and let you decide if the approach Ive taken is valid. I want to make you question things and hopefully come to different conclusions, using what I supply as a base for debate and expansion rather than a gospel to be followed. When working with beginners, I dont believe in imposing the right way , I prefer to have faith in, this works for me, can I make it better? The right way , for you at least, will come with practice and the joy of achievement.