Programming Linux Games

Total Page:16

File Type:pdf, Size:1020Kb

Programming Linux Games Programming Linux Games Programming Linux Games Loki Software, Inc. with John R. Hall An imprint of No Starch Press, Inc. San Francisco Programming Linux Games. Copyright c 2001 by Loki Software, Inc. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. Printed in the United States of America 1 2 3 4 5 6 7 8 9 10|04 03 02 01 Trademarked names are used throughout this book. Rather than including a funny little trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Co-publishers: William Pollock and Phil Hughes Project Editor: Karol Jurado Assistant Editor: Nick Hoff Cover and Interior Design: Octopod Studios Copyeditor: Rebecca Pepper Proofreader: Ken DellaPenta Distributed to the book trade in the United States by Publishers Group West, 1700 Fourth Street, Berkeley, California 94710, phone: 800{788{3123 or 510{528{1444, fax: 510{528{3444 Distributed to the book trade in Canada by Jacqueline Gross & Associates, Inc., One Atlantic Avenue, Suite 105, Toronto, Ontario M6K E7 Canada, phone: 416{531-06737, fax: 416{531{4259 For information on translations or book distributors outside the United States, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 555 De Haro Street, Suite 250 San Francisco, CA 94107 phone: 415{863{9900; fax: 415{863{9950; [email protected]; http://www.nostarch.com The information in this book is distributed on an \As Is" basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. Library of Congress Cataloging-in-Publication Data Programming linux games / Loki Software, Inc. p. cm. Includes index. ISBN 1-886411-48-4 (pbk.) 1. Computer games--programming. 2. Linux. I. Loki Software, Inc. QA76.76.C672 .L56 2001 00-052689 794.8'15268--dc21 Contents Foreword i Preface iii Who This Book Is For . iv Online Resources . iv Acknowledgements . v 1 The Anatomy of a Game 1 A Quick Survey of Game Genres . 2 Simulation Games . 2 First-Person Shooters . 4 Real-time Strategy Games . 6 Turn-Based Strategy Games . 7 Role-Playing Games . 7 Puzzle Games . 9 Multiuser Dungeons . 10 A Quick Look Under the Hood . 11 The Input Subsystem . 12 The Display Subsystem . 12 2 CONTENTS The Audio Subsystem . 13 The Network Subsystem . 14 The Update Subsystem . 14 The Game Loop . 15 2 Linux Development Tools 17 Programming Editors . 17 vi......................................... 18 Emacs . 19 NEdit . 20 Compiling Programs Under Linux . 20 Using the Make Utility . 24 Creating Makefiles . 24 Error Handling . 28 Working with Libraries . 29 Static Libraries . 29 Shared Libraries . 29 Linux Linker Quirks . 32 Debugging Linux Applications . 33 Compiling for Debugging . 33 gdb........................................ 34 ddd ....................................... 41 Bug Tracking . 42 Project Management with CVS . 42 A Brief Tutorial on CVS . 43 Other Useful Tools . 49 Rapid Text Searching with grep . 49 CONTENTS 3 Updating Source with diff and patch . 50 3 Linux Gaming APIs 53 Graphics APIs . 55 SVGALib . 55 GGI ....................................... 56 SDL ....................................... 56 ClanLib . 57 OpenGL . 57 Plib ....................................... 57 Glide . 58 Xlib ....................................... 58 Graphical User Interface Toolkits . 59 GTK+...................................... 59 Tk........................................ 59 Fltk ....................................... 60 Qt ........................................ 60 SDL GUI Support . 60 Audio APIs . 61 OSS ....................................... 61 ALSA ...................................... 62 ESD....................................... 62 OpenAL . 63 Scripting Libraries . 63 Tcl........................................ 63 Guile and MzScheme . 63 Python and Perl . 64 4 CONTENTS Networking APIs . 64 BSD Sockets . 65 OpenPlay . 65 IPX and SPX . 65 File Handling . 66 libpng and libjpeg . 66 libaudiofile and libsndfile . 67 Ogg Vorbis . 67 The SDL MPEG Library, SMPEG . 68 zlib........................................ 68 4 Mastering SDL 69 Computer Graphics Hardware . 70 The Framebuffer . 71 The SDL Video API . 72 Setting Up the Display . 74 Direct Surface Drawing . 77 Drawing with Blits . 83 Colorkeys and Transparency . 87 Loading Other Image Formats . 92 Alpha Blending . 92 Achieving Smooth Animation with SDL . 97 Input and Event Processing . 107 Processing Mouse Events . 108 Processing Keyboard Events . 112 Processing Joystick Events . 116 Multithreading with SDL . 120 CONTENTS 5 SDL Audio Programming . 125 Representing Sound with PCM . 125 Feeding a Sound Card . 128 An Example of SDL Audio Playback . 129 Integrating OpenGL with SDL . 140 Penguin Warrior . 144 Creating Graphics . 146 Implementing a Parallaxing Scroller in SDL . 147 A Simple Particle System . 153 Game Timing . 158 5 Linux Audio Programming 161 Competing APIs . 162 Introducing Multi-Play . 163 Loading Sound Files . 164 Using libsndfile . 164 Other Options . 170 Using OSS . 170 Reality Check . 175 Achieving Higher Performance with Direct DMA Buffer Access . 178 Playing Sound with ALSA . 187 Sharing.
Recommended publications
  • GNU/Linux AI & Alife HOWTO
    GNU/Linux AI & Alife HOWTO GNU/Linux AI & Alife HOWTO Table of Contents GNU/Linux AI & Alife HOWTO......................................................................................................................1 by John Eikenberry..................................................................................................................................1 1. Introduction..........................................................................................................................................1 2. Symbolic Systems (GOFAI)................................................................................................................1 3. Connectionism.....................................................................................................................................1 4. Evolutionary Computing......................................................................................................................1 5. Alife & Complex Systems...................................................................................................................1 6. Agents & Robotics...............................................................................................................................1 7. Statistical & Machine Learning...........................................................................................................2 8. Missing & Dead...................................................................................................................................2 1. Introduction.........................................................................................................................................2
    [Show full text]
  • World of Warcraft Online Manual
    Game Experience May Change During Online Play WOWz 9/11/04 4:02 PM Page 2 Copyright ©2004 by Blizzard Entertainment. All rights reserved. The use of this software product is subject to the terms of the enclosed End User License Agreement. You must accept the End User License Agreement before you can use the product. Use of World of Warcraft, is subject to your acceptance of the World of Warcraft® Terms of Use Agreement. World of Warcraft, Warcraft and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment in the U.S. and/or other countries.Windows and DirectX are trademarks or registered trademarks of Microsoft Corporation in the U.S. and/or other countries. Pentium is a registered trademark of Intel Corporation. Power Macintosh is a registered trademark of Apple Computer, Inc. Dolby and the double-D symbol are trademarks of Dolby Laboratory. Monotype is a trademark of Agfa Monotype Limited registered in the U.S. Patent and Trademark ® Office and certain other jurisdictions. Arial is a trademark of The Monotype Corporation registered in the U.S. Patent and Trademark Office and certain other jurisdictions. ITC Friz Quadrata is a trademark of The International Typeface Corporation which may be registered in certain jurisdictions. All other trademarks are the property of their respective owners. Uses high-quality DivX® Video. DivX® and the DivX® Video logo are trademarks of DivXNetworks, Inc. and are used under license. All rights reserved. AMD, the AMD logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc All ATI product and product feature names and logos, including ATI, the ATI Logo, and RADEON are trademarks and / or registered trademarks of ATI Technologies Inc.
    [Show full text]
  • Magazine.Odroid.Com, Is Your Source for All Things Odroidian
    Volumio 2 • Android ADB Debug • Android navigation using IR remote Year Four Issue #41 May 2017 ODROIDMagazine Repurpose your WithN64 the power of ODROID A complete walkthrough allowing you to use the classic Nintendo console case with your favorite board Offering Exploring Native RS485 ODROID-C2 communication Support on C1+ and C2 What we stand for. We strive to symbolize the edge of technology, future, youth, humanity, and engineering. Our philosophy is based on Developers. And our efforts to keep close relationships with developers around the world. For that, you can always count on having the quality and sophistication that is the hallmark of our products. Simple, modern and distinctive. So you can have the best to accomplish everything you can dream of. We are now shipping the ODROID-C2 and ODROID-XU4 devices to EU countries! Come and visit our online store to shop! Address: Max-Pollin-Straße 1 85104 Pförring Germany Telephone & Fax phone: +49 (0) 8403 / 920-920 email: [email protected] Our ODROID products can be found at http://bit.ly/1tXPXwe EDITORIAL o you have an old Nintendo or other gaming console that doesn’t work anymore? Don’t throw it away! You can re- Dfurbish it with an ODROID-XU4 running ODROID GameS- tation Turbo, RetroPie or Lakka and turn it into a multi-platform emulator station that can play thousands of different console games. Our main feature this month details how to fit everything into an N64 shell, breathing new life into an old dusty console case. ODROIDs are extremely versatile, and can be used for music playback, as de- scribed in our Volumio 2 article, developing Android apps, as Nanik demonstrates in his ar- ticle on the Android Debug Bridge, and process control, as shown by Charles and Neal in their discussion of the RS485 communication protocol.
    [Show full text]
  • Apache TOMCAT
    LVM Data Migration • XU4 Fan Control • OSX USB-UART interfacing Year Two Issue #22 Oct 2015 ODROIDMagazine Apache TOMCAT Your web server and servlet container running on the world’s most power-efficient computing platform Plex Linux Gaming: Emulate Sega’s last Media console, the Dreamcast Server What we stand for. We strive to symbolize the edge of technology, future, youth, humanity, and engineering. Our philosophy is based on Developers. And our efforts to keep close relationships with developers around the world. For that, you can always count on having the quality and sophistication that is the hallmark of our products. Simple, modern and distinctive. So you can have the best to accomplish everything you can dream of. We are now shipping the ODROID-U3 device to EU countries! Come and visit our online store to shop! Address: Max-Pollin-Straße 1 85104 Pförring Germany Telephone & Fax phone: +49 (0) 8403 / 920-920 email: [email protected] Our ODROID products can be found at http://bit.ly/1tXPXwe EDITORIAL his month, we feature two extremely useful servers that run very well on the ODROID platform: Apache Tom- Tcat and Plex Media Server. Apache Tomcat is an open- source web server and servlet container that provides a “pure Java” HTTP web server environment for Java code to run in. It allows you to write complex web applications in Java without needing to learn a specific server language such as .NET or PHP. Plex Media Server organizes your vid- eo, music, and photo collections and streams them to all of your screens.
    [Show full text]
  • The Elinks Manual the Elinks Manual Table of Contents Preface
    The ELinks Manual The ELinks Manual Table of Contents Preface.......................................................................................................................................................ix 1. Getting ELinks up and running...........................................................................................................1 1.1. Building and Installing ELinks...................................................................................................1 1.2. Requirements..............................................................................................................................1 1.3. Recommended Libraries and Programs......................................................................................1 1.4. Further reading............................................................................................................................2 1.5. Tips to obtain a very small static elinks binary...........................................................................2 1.6. ECMAScript support?!...............................................................................................................4 1.6.1. Ok, so how to get the ECMAScript support working?...................................................4 1.6.2. The ECMAScript support is buggy! Shall I blame Mozilla people?..............................6 1.6.3. Now, I would still like NJS or a new JS engine from scratch. .....................................6 1.7. Feature configuration file (features.conf).............................................................................7
    [Show full text]
  • November 2008
    >> TOP DECK The Industry's Most Influential Players NOVEMBER 2008 THE LEADING GAME INDUSTRY MAGAZINE >> BUILDING TOOLS >> PRODUCT REVIEW >> LITTLE TOUCHES GOOD DESIGN FOR NVIDIA'S PERFHUD 6 ARTISTIC FLOURISHES INTERNAL SYSTEMS THAT SELL THE ILLUSION CERTAIN AFFINITY'S AGEOFBOOTY 00811gd_cover_vIjf.indd811gd_cover_vIjf.indd 1 110/21/080/21/08 77:01:43:01:43 PPMM “ReplayDIRECTOR rocks. I doubt we'd have found it otherwise. It turned out to be an occasional array overwrite that would cause random memory corruption…” Meilin Wong, Developer, Crystal Dynamics BUGS. PETRIFIED. RECORD. REPLAY. FIXED. ReplayDIRECTOR™ gives you Deep Recording. This is much more than just video capture. Replay records every line of code that you execute and makes certain that it will Replay with the same path of execution through your code. Every time. Instantly Replay any bug you can find. Seriously. DEEP RECORDING. NO SOURCE MODS. download today at www.replaysolutions.com email us at [email protected] REPLAY SOLUTIONS 1600 Seaport Blvd., Suite 310, Redwood City, CA, 94063 - Tel: 650-472-2208 Fax: 650-240-0403 accelerating you to market ©Replay Solutions, LLC. All rights reserved. Product features, specifications, system requirements and availability are subject to change without notice. ReplayDIRECTOR and the Replay Solutions logo are registered trademarks of Replay Solutions, LLC in the United States and/or other countries. All other trademarks contained herein are the property of their respective owners. []CONTENTS NOVEMBER 2008 VOLUME 15, NUMBER 10 FEATURES 7 GAME DEVELOPER'S TOP DECK Not all game developers are cards, but many of them are unique in their way—in Game Developer's first Top Deck feature, we name the top creatives, money makers, and innovators, highlighting both individual and company achievements.
    [Show full text]
  • OM-Cube Project
    OM-Cube project V. Hiribarren, N. Marchand, N. Talfer [email protected] - [email protected] - [email protected] Abstract. The OM-Cube project is composed of several components like a minimal operating system, a multi- media player, a LCD display and an infra-red controller. They should be chosen to fit the hardware of an em- bedded system. Several other similar projects can provide information on the software that can be chosen. This paper aims to examine the different available tools to build the OM-Multimedia machine. The main purpose is to explore different ways to build an embedded system that fits the hardware and fulfills the project. 1 A Minimal Operating System The operating system is the core of the embedded system, and therefore should be chosen with care. Because of its popu- larity, a Linux based system seems the best choice, but other open systems exist and should be considered. After having elected a system, all unnecessary components may be removed to get a minimal operating system. 1.1 A Linux Operating System Using a Linux kernel has several advantages. As it’s a popular kernel, many drivers and documentation are available. Linux is an open source kernel; therefore it enables anyone to modify its sources and to recompile it. Using Linux in an embedded system requires adapting the kernel to the hardware and to the system needs. A simple method for building a Linux embed- ded system is to create a partition on a development host and to mount it on a temporary mount point. This partition is filled as one goes along and then, the final distribution is put on the target host [Fich02] [LFS].
    [Show full text]
  • Accelerate Your Mobile Apps for Android On
    The Developer Summit at ARM® TechCon™ 2013 Accelerate your Mobile Apps and Games for Android™ on ARM Matthew Du Puy! Software Engineer, ARM The Developer Summit at ARM® TechCon™ 2013 Presenter Matthew Du Puy! Software Engineer, ARM! ! Matthew Du Puy is a software engineer at ARM and is currently working to ensuring mobile app performance on the latest ARM technologies. Previously a self employed embedded systems software contractor working primarily on the Linux Kernel and a mountain climber.! ! Contact Details: ! Email: [email protected] Title: Accelerate Your Mobile Apps and Games for Android on ARM Overview: Learn to perform Android application and systems level analysis on Android apps and platforms using tools from Google, ARM, AT&T and others. Find bottlenecks in both SDK and NDK activities and learn different approaches to fixing those bottlenecks and better utilize platform technologies and APIs. Problem: This is not a desktop ▪ Mobile apps require special design considerations that aren’t always clear and tools to solve increasingly complex systems are limited! ▪ Animations and games drop frames! ▪ Networking, display, real time audio and video processing eat battery! ▪ App won’t fit in memory constraints Analysis ▪ Fortunately Google, ARM and many others are developing analysis tools and solutions to these problems! ▪ Is my app … ?! ▪ CPU/GPGPU bound! ▪ I/O or memory constrained! ▪ Power efficient! ▪ What can I do to fix it?# (short of buying everyone who runs my app# a Quad-core ARM® Cortex™-A15 processor # & ARM Mali™-T604 processor or Octo phone) In emerging markets, not everyone has access to the latest and greatest devices but they still want to game, shop, socialize and learn with their mobiles.
    [Show full text]
  • Game Audio Via Openal
    Game Audio via OpenAL Summary In the Graphics For Games module, you learnt how to use OpenGL to create complex graphical scenes, improving your programming skills along the way, and learning about data structures such as scene graphs. In this workshop, you'll see how to add sounds to your game worlds using the OpenAL sound library. New Concepts Sound in games, OpenAL, PCM audio, binary file formats, FourCC codes, WAV files, limited resource management Introduction Audio has played an important part in gaming almost as long as there have been games to play - even Pong back in 1972 had simple sound effects. We've moved a long way from then; the 80s brought dedicated audio hardware such as the Commodore 64's SID chip that could play 3 simultaneous syn- thesised sounds, and later the Amiga brought the ability to play audio samples to the home gaming market. In modern gaming hardware, we can expect to hear many simultaneous sounds and music tracks, often in surround sound. Game developers now employ dedicated sound engineers that will carefully adjust the sounds in each game release to create an immersive aural experience - making sure that each individual sound is uniquely identifiable and correctly equalised, and that every music track suits the situation they will be played in. At the heart of a game's audio experience is the code that plays back the game sounds, and cal- culates which speakers they should use - the sound system. Although we can't hope to compete with the complex sound systems of AAA games, we should still be able to make a robust, simple system for the addition of sound in our 3D games, and that's what this workshop will assist you in creating.
    [Show full text]
  • Recoil Windows Reference Card
    Recoil ref card.qxd 7/5/99 10:59 AM Page 1 READ ME FIRST! Electronic Arts™ presents ® TABLE OF CONTENTS SYSTEM REQUIREMENTS ........................................................................ 2 DISK PREPARATION ................................................................................ 4 DIRECTX INSTALLATION NOTES ................................................................ 4 INSTALLING THE GAME: WINDOWS 95/98 ................................................ 6 Uninstalling/Re-installing the game .................................................... 8 INSTALLING THE GAME: DOS .................................................................. 9 PROBLEMS WITH YOUR SOFTWARE? ...................................................... 10 CD Problems .................................................................................. 10 Video Problems .............................................................................. 11 Memory Problems .......................................................................... 11 Sound Problems ............................................................................ 12 Modem Problems............................................................................ 12 Network Problems............................................................................14 Other Common Questions ................................................................16 USING THE ELECTRONIC DOCUMENTATION..............................................18 CONVERSION CREDITS / HINTS..............................................................19
    [Show full text]
  • Openbsd Gaming Resource
    OPENBSD GAMING RESOURCE A continually updated resource for playing video games on OpenBSD. Mr. Satterly Updated August 7, 2021 P11U17A3B8 III Title: OpenBSD Gaming Resource Author: Mr. Satterly Publisher: Mr. Satterly Date: Updated August 7, 2021 Copyright: Creative Commons Zero 1.0 Universal Email: [email protected] Website: https://MrSatterly.com/ Contents 1 Introduction1 2 Ways to play the games2 2.1 Base system........................ 2 2.2 Ports/Editors........................ 3 2.3 Ports/Emulators...................... 3 Arcade emulation..................... 4 Computer emulation................... 4 Game console emulation................. 4 Operating system emulation .............. 7 2.4 Ports/Games........................ 8 Game engines....................... 8 Interactive fiction..................... 9 2.5 Ports/Math......................... 10 2.6 Ports/Net.......................... 10 2.7 Ports/Shells ........................ 12 2.8 Ports/WWW ........................ 12 3 Notable games 14 3.1 Free games ........................ 14 A-I.............................. 14 J-R.............................. 22 S-Z.............................. 26 3.2 Non-free games...................... 31 4 Getting the games 33 4.1 Games............................ 33 5 Former ways to play games 37 6 What next? 38 Appendices 39 A Clones, models, and variants 39 Index 51 IV 1 Introduction I use this document to help organize my thoughts, files, and links on how to play games on OpenBSD. It helps me to remember what I have gone through while finding new games. The biggest reason to read or at least skim this document is because how can you search for something you do not know exists? I will show you ways to play games, what free and non-free games are available, and give links to help you get started on downloading them.
    [Show full text]
  • Sound-HOWTO.Pdf
    The Linux Sound HOWTO Jeff Tranter [email protected] v1.22, 16 July 2001 Revision History Revision 1.22 2001−07−16 Revised by: jjt Relicensed under the GFDL. Revision 1.21 2001−05−11 Revised by: jjt This document describes sound support for Linux. It lists the supported sound hardware, describes how to configure the kernel drivers, and answers frequently asked questions. The intent is to bring new users up to speed more quickly and reduce the amount of traffic in the Usenet news groups and mailing lists. The Linux Sound HOWTO Table of Contents 1. Introduction.....................................................................................................................................................1 1.1. Acknowledgments.............................................................................................................................1 1.2. New versions of this document.........................................................................................................1 1.3. Feedback...........................................................................................................................................2 1.4. Distribution Policy............................................................................................................................2 2. Sound Card Technology.................................................................................................................................3 3. Supported Hardware......................................................................................................................................4
    [Show full text]