The fundamentals of c c++ game programming using target based development on SBCs

533 133 0
The fundamentals of c c++ game programming using target based development on SBCs

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

The Fundamentals of C/C++ Game Programming The Fundamentals of C/C++ Game Programming Using Target-Based Development on SBC’s 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 SBC’s / 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 “From Hello World to Halo—It’s Just Code!” xv Thanks xxvii Brian Beuken: Who Is He? xxix Getting Started Mine Looks Different? First Steps Setting Things Up Introducing Visual Studio Hello World 10 Hello Place of My Choosing 11 Getting Our Target Ready 13 Setting Up the Target 13 Oh Wait…Did We Plug-In? 15 Starting Up VisualGDB for the First Time 16 vii Getting the Machines to Talk 17 Sending Our First Program 18 Debugger Hangs Too Much? 28 Using the Target 31 Ready to Rock and Ermm Indeed Roll! 31 Graphics Explained! 32 So It Be OpenGL ES Ye Be Wanting Arrgghhh! 33 Where Is OpenGLES2 on My Target? 33 A Nice New Project with Graphics 35 So Much Typing? 35 Our First Graphics Project! 36 Are We There Yet? 41 Houston We Have a Triangle 41 Behold the Triangle Code! 44 Why Are We Working in a Window? 50 2D 51 Putting It All Together 53 Expanding Our First Graphics Program 53 Loading Graphics or Other Assets 53 Adding Assets to the Build Chain 57 Keeping Things Tidy 58 Add Some Code 59 Displaying More Images 64 But I Didn’t Do Anything Wrong? 65 But I Fixed It? 66 Making a Dynamic Playfield 68 Old School Frame Buffers 68 Setting Up the Frame Buffer and Switch System 74 Finally Our First Games 77 Invaders from Space 77 Using the OS 78 Start as We Mean to Go on 85 We’re Here Now 87 Inheritance 88 Every Story Needs a Villan 91 Arrays or Vectors 93 Move Em Out! 96 Animation 101 98 Hand Me a Bag of Bullets 100 viii Contents Did We Hit It? 101 Box Checks 102 Circle Checks 102 Give Me Shelter 104 So Which Is Better? 110 Final Details 110 Simple Text Display 111 A Simple Font 113 How Did We Do? The Infamous Postmortem 118 Fix Question 119 A Pat on the Back 122 Kamikazi Invaders 123 The Ship 128 Da Baddies! 130 Now We’re Talking 132 Make Them Move 135 Get Them Flying 136 A Nice Arc 137 Step by Step 141 Dive Dive Dive 142 Bombs Away 144 Get Back to Where You Once Belonged 145 Home Again! 145 Vectors, Our Flexible Friends 146 Lets Get Lethal 151 Bombs Away for Real Now 154 Danger UXB 161 Stepping Back, Deciding When to Go 162 Breaker Breaker Rubber Duck 167 Fred Reacts! 169 Tidy Up the Logic 173 Twiddles and Tweaks 173 Postmortem 173 Jumping around a Bit Though? 174 Crawling Over, Time for Baby Steps 175 Object-Oriented Programming Is Not an Error 175 Encapsulation 176 Abstraction 176 Inheritance 176 Polymorphism 176 Start the Music 176 Welcome to OpenAL 177 Installing OpenAL 177 Getting OpenAL Working 179 Contents ix If you have a multicore CPU you might want to try using OpenMP to handle some of your multicore work It should already have OpenMP’s libs installed but you can check by trying to install anyway All single-core system will still work and compile but you won’t see any benefit and indeed you might see a slow down, as threads are being constantly set up and the CPU is time slicing rather than processing on idle cores sudo apt-get install libgomp1 On the PC End We also downloaded a couple of header style libraries, which we then compiled to be part of the finished executable, so they will not be affected by a new storage setup, but in case you change PCs and forget what you used you can reinstall these SOIL, or more correctly the STB file loading was downloaded from https://www github com/nothings/stb GLM The Maths Lib was downloaded from (but check for latest versions) http:// www glm g-truc net/0 8/index html Tiny Object Loader for loading our basic OBJ files from https://www github com/ syoyo/tinyobjloader 488 Appendix VI Appendix VII Writing My Own Games? Oh boy this is a biggie… I get asked so often by people, how I write my own games, I’ve got a great idea? Well technically the answers are in here; everything you need to know is here and can be built on, except for that one crucial thing A vision! There’s no real way to get past this, but most programmers don’t have that vision, we see the project as a series of logical and technical problems, which must be overcome to do… what? Without vision, the clear and full picture of what the game is going to be, starting out on a technical path of superfast fancy wizardry, is going to be wasted and frustrating I’ve tried to simulate vision by using game genres that we should all be familiar with, so you can even a basic bit of research to understand what the games are hoping to turn out like, but if I were to suggest to you we a game about Doggies Piloting Atomic Power Balloons, In Space! You might quite rightly scratch your head in confusion This is why we have designers, those happy smiling people who want you to deliver the moon on a stick, and convince you that making it 30% more fun is somehow possible The days when we could take a cool programming effect and turn it into a game are largely gone, despite the occasional exception (I’m looking at you Flappy Bird)! Games need to have a clear outline of what they plan to be 489 So if you have an idea for a game, the first thing you should be doing is writing it down on paper and planning it out Identify the goals and aims of the game What will the player be asked to achieve, how will that be done? What are the aims of the AI? What obstacles will be put in the way? What will be the progression of the game? There are a great many design questions you need to answer before you touch a coding keyboard in anger Be fully aware of what the tasks are that you need to tackle, the scale of them, and most important, the feasibility of them Some things are just not possible on the hardware you choose, are there alternative means to them? Once you have planned your game, consider its core make up I’ve put forward the notion that all games are basically variations on Space Invaders, but, of course, some games bend that notion to near-breaking point At the core of the game, technically it will still have a main loop, taking input, processing, and rendering, so you can take some comfort in that The issue is how you create a play world, what will be in it, and how will they all interact Focus on those points! You should be clear about what it will look like, how the objects move or are moved, what influences the user will have in the game, and what random factors will it have Once you have that vision, get a designer to check it out for you…they’ll tear it apart for sure, but that’s good You need to be sure that what you want is going to be fun, playable, and possible 490 Appendix VII Appendix VIII Visual Studio 2017 It had to happen; this book took so long to write that Microsoft came out with a new and improved version of Visual Studio, version 2017 Aside from all the usual improvements you might expect in optimization and changes of format that I might take a look at in or 3 years It has included a new development for Linux option This was available as an extension for VS2015 but I felt it was a little clunky then, so didn’t spend much time on it This new version is much less clunky and indeed provides a way of directly targeting Linux systems from your PC It has a few issues, though It does not redirect console output to the development machine, making printf and cout less useful to us And it only does an on target build, at least through that configuration manager, but cross compiling can be worked out with a bit of head scratching as can redirecting the output But it does indeed send files to the target, which then compiles them and sets up a debugger so that you can work through your code So as a target-base compiler system it works just fine and with a bit of work you can get pretty much all the same features that VisualGDB provides, for free 491 If you find that you are following all the VisualGDB concepts ok, you should be able to adapt them very simply to the new VS2017 properties it provides But for now I’m still going to continue with VS2015 and VisualGDB, its less effort to get things working But maybe if there’s a next edition of this book I might swap over I will put an update on the support site when I get round to using VS2017, sometime around the spring of 2023 492 Appendix VIII Index

Ngày đăng: 02/03/2019, 10:32

Từ khóa liên quan

Mục lục

  • Cover

  • Half Title

  • Title Page

  • Copyright Page

  • Table of Contents

  • “From Hello World to Halo—It’s Just Code!”

  • Thanks

  • Brian Beuken: Who Is He?

  • 1: Getting Started

    • Mine Looks Different?

    • First Steps

    • Setting Things Up

    • Introducing Visual Studio

    • Hello World

    • Hello Place of My Choosing

    • 2: Getting Our Target Ready

      • Setting Up the Target

      • Oh Wait…Did We Plug-In?

      • Starting Up VisualGDB for the First Time

      • Getting the Machines to Talk

      • Sending Our First Program

      • Debugger Hangs Too Much?

Tài liệu cùng người dùng

Tài liệu liên quan