GithubHelp home page GithubHelp logo

kerwinzxc / shooterdemo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from giulian2003/shooterdemo

0.0 1.0 0.0 46.47 MB

Small 1st/3rd person shooter which I made to investigate the usefulness of the Entity Component System (ECS) design pattern when working on an actual game. (Data Oriented Design, C++11, OpenGL 4.5, SDL, GLEW, NanoVG, CTPL lock free multi-threading, ASSIMP skeletal animation and model loading, Recast&Detour navigation mesh, Q3 BSP map format)

License: Other

CMake 0.10% C 50.13% C++ 49.53% Objective-C 0.25%

shooterdemo's Introduction

Shooter Demo

ShooterDemo is a small 1st/3rd person shooter which I made in C++11 to investigate the usefulness of the Entity-Component-System (ECS) design pattern when working on an actual game and if it facilitates the use of lock free multi-threading.

Why this Demo?

After more then 10 years of working with OOP design patterns and reading a number of books on OOP (Modern C++ Design, Effective C++, More Effective C++, Effective STL, etc.) I decided to try something a bit less complex and see what are the benefits. I read about the Entity-Component-System design pattern and I liked it's simplicity, but since not everything you read in a book it's actually useful, I decided to give it a try in a small project.

Design decisions

  • Prefer Data Oriented Design over Object Oriented Design. It's been my experience that, in applications dealing with large amounts of data, it's more useful to reason about the data and how it can be processed in an efficient way, rather then think about objects and what design pattern to use. A very interesting talk on this subject is Mike Acton's "Data-Oriented Design and C++" talk at CppCon 2014.
  • Keep data separate from functionality. According to ECS, I tried to put all data in Components and all functionality in Systems, with a few exceptions (mainly lib and resource wrapper classes). One notable exception is the SysRenderer class which is a System and also contains data (OpenGL objects), but since this data it's used by all Systems, I didn't see the harm leaving it there.
  • Prefer Structure of Arrays over Array of Structures. Organizing the data this way it's more cache friendly, since each System only iterates over the data that it needs to process and also facilitates the use of lock free multi-threading.
  • Avoid memory reallocation. Reallocating memory causes a performance hit and also memory fragmentation. It's a heavy price to pay and reallocation should only be used when absolutely necessary!
  • All functions should have clear Input and Output parameters. All functions in Systems are static functions. I found that writing functions this way makes them easier to access from other parts of code (weak dependencies) and easier to use in a different thread without locks, since it's clear what data will be read and what data will be written by the function.
  • Minimize the number cache misses. In my experience cache misses, especially in loops, cause a big performance hit. I tried as much as possible to reason about data locality when working on this project.
  • Lock free multi-threading. Using a Data Oriented Design with data organized as Structure of Arrays in the Scene and having functions with clear input and output parameters, made it easy to reason about how the data can be read/written safely from different threads and I could make the app lock free.

Libraries

  • OpenGL 4.5 - rendering
  • GLEW - cross-platform OpenGL 4.5 extensions
  • SDL2 - cross-platform access to keyboard, mouse and graphic hardware
  • CTPL - multi-threading
  • NanoVG - text rendering
  • GLM - OpenGL and vector math
  • Minizip - read the map from a zip archive
  • Q3Loader (modified) - loading maps in Quake3 BSP format
  • Assimp - loading 3D models
  • Recast&Detour - create a navigation mesh and calculate walking paths and jump down links on it.

Build (Windows OS)##

Dependencies: CMake 3.3, Visual Studio 2013-2015 (for #include <filesystem>)

./cmake .

Open ShooterDemo.sln, set the ShooterDemo as StartUp Project and set the Working Directory to $(ProjectDir)/bin for each Configuration that you are using (Debug, Release, etc.)

Run (Windows OS)##

Dependencies: OpenGL 4.5, Visual C++ Redistributable for Visual Studio 2015

Extract the bin/ShooterDemo_win7_x32_bin.tar.gz and lib/DemoShooter_win7_x32_lib.tar.gz files into each directory. (Running ./cmake . would do this automatically or just use 7Zip)

cd ./bin

./ShooterDemo.exe

Screenshots

shooterdemo's People

Contributors

giulian2003 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.