Coder Social home page Coder Social logo

jerboaburrow / hop Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 33.12 MB

Lightweight, cross-platform, 2D game engine | ECS; Lua Console; Physics; Tile based

License: MIT License

CMake 3.59% Shell 0.65% C 0.02% C++ 92.67% GLSL 0.88% Lua 2.19%
cpp opengl entity-component-system lua physics-2d tile-based android linux macos windows

hop's Introduction

Hop

A lightweight 2D game engine, in C++ with embedded Lua

Features

  • Free, MIT open sourced
  • Use as a standalone (GLFW based) engine or as a drop in component (e.g. with SFML)
  • Entity component system (ECS) based
  • Rigid and soft body physics (Discrete element method)
  • OpenGL rendering (provided by jGL, Vulkan is a WIP)
  • Perlin (marching squares) and Tile map, editable tile based worlds
  • Lua console, interoperating with the ECS, physics, and rendering systems

Setup

  • clone, and init the submodules (you can use submodules.sh)
  • the build.sh can be used to build

OSS Dependencies and Licenses

  • Freetype is licensed under the The FreeType Project LICENSE
  • GLEW is licensed under aModified BSD License, the Mesa 3-D License (MIT) and the Khronos License (MIT).
  • GLFW is licensed under the zlib/libpng
  • GLM is licensed under the MIT License (but also, no bunnies have been made unhappy)
  • Lua is licensed under the MIT license
  • Miniaudio is licensed under the MIT-0 license
  • stduuid is licensed under the MIT license
  • vorbis and ogg is licensed under a BSD license
  • zlib is licensed under the zlib license

We thank: David Turner, Robert Wilhelm, and Werner Lemberg (Freetype), Milan Ikits <milan ikits[]ieee org>, Marcelo E. Magallon <mmagallo[]debian org>, and Lev Povalahev Brian Paul, The Khronos Group Inc (GLEW), Marcus Geelnard and Camilla Lƶwy (GLFW), G-Truc Creation (GLM), Lua.org, PUC-Rio (Lua), David Reid (Miniaudio), Marius Bancila https://github.com/mariusbancila/stduuid#MIT-1-ov-file (stduuid), Xiph.org Foundation (vorbis, ogg), and Jean-loup Gailly and Mark Adler (zlib).

hop's People

Contributors

jerboa-app avatar

Watchers

 avatar

Forkers

aismann

hop's Issues

Create Android example and benchmark using NDK wrapper

  • hop as a lib #45
  • refactor GLSkeleton app with Balance's and SPP's compose updates
  • refactor GLSkeleton app with Balance's OnlineServices API
  • test play games services
  • build Hop for android using NDK
  • map in example
  • move around map
  • add particles
  • benchmark on Nexus 5
  • add hop android build to yml
  • add android example to yml (emulator)

Map and world

  • Procedural map generation
  • Tile based, top down
  • Lighting and physics informed by map

Borked rectangles

  • unstable oscillations near settling
  • collision detection issue?
  • does abate at dt 1/9000, 10 subsamples...

Texture Atlasing

const char * texturedQuadVertexShader = "#version 330 core\n"
    "layout(location=0) in vec4 a_position;\n"
    "layout(location=1) in vec4 a_offset;\n"
    "layout(location=2) in vec4 a_colour;\n"
    "uniform mat4 proj;\n"
    "out vec2 texCoord;\n"
    "void main(){\n"
        "gl_Position = proj*vec4(a_offset.z*a_position.xy+a_offset.xy,0.0,1.0);\n"
        "texCoord = a_position.zw;\n"
    "}";

const char * texturedQuadFragmentShader = "#version 330 core\n"
    "in vec2 texCoord;\n"
    "uniform sampler2D tex; out vec4 colour;\n"
    "void main(){"
        "colour=texture(tex,texCoord);"
    "\n}";

Camera

  • Support zooming
  • Support different resolutions and aspect ratios

C++17 and Style

Fully adopt the following

  • std::filesystem
  • parallel STL (find, sort etc.)
  • range-for

Style

  • Brace initialisation (e.g. int a {7}
  • no forward declaration of types ala Fortran

Higher order integration; subsampling

Explore possibility for higher order integration and timestep subsampling

  • Yoshida integrator (4th order)
  • Yoshida with linear force model (rather than recomputing forces)
  • Yoshida with non-linear force model (rather than recomputing forces)
  • Sub-sample time step option

Windows support

Build types working need to test threading also works

  • build auto test
  • add windows artifact action step
  • human test threads work

Refactor to use brace style (and spacing); define style guide

  • brace style refactored
  • style guide doc
  • deal with warnings

E.g from this

    for (int i = 0; i < DYNAMICS_REGION_BUFFER_SIZE; i++){
        for (int j = 0; j < DYNAMICS_REGION_BUFFER_SIZE; j++){
            renderRegionBuffer[i*DYNAMICS_REGION_BUFFER_SIZE+j] = map->getAtCoordinate(i,j);
        }
    }

to

    for (int i = 0; i < DYNAMICS_REGION_BUFFER_SIZE; i++)
    {

        for (int j = 0; j < DYNAMICS_REGION_BUFFER_SIZE; j++)
        {

            renderRegionBuffer[i*DYNAMICS_REGION_BUFFER_SIZE+j] = map->getAtCoordinate(i,j);
        
        }
        
    }

Lua

  • embed Lua into engine
  • support object creation via Lua scripts (to begin with)

Physics

cell list based collisions

256x256 cells worked at 60fps for 100k particles on CellLists repo!

android might be an issue, but that could be just Kotlin (balance repo)

e: roughly 100 particles per object with (100k)

  • object-object collisions
  • object-world collisions (marching squares)
  • object-world collisions (tile based)

Collision Primitives

Support both lines and circles as collision Primitives within collision mesh

  • refactor collision mesh/ vertex to use collision primitive

  • Circle primitive

  • Ellipse primitive

  • square primitive

Using Rectangle primitive

  • deprecate LineSegment
  • Rectangle - world vertices update
  • Use p-axis to cull, Then test each vertex and apply
  • Apply forces at point (for rotation)
  • Rect-Rect force
  • Rect-Circle force
  • add debug shaders for CollisionMesh
  • spawn rectangles for bounds col with rect object
  • spawn rectangles for world col with rect object
  • Rect-world (Rect) force
  • test example

Lua lbaselib.c coloured print adds extra "read" to string

  • [case] The colour code prints, print("text") as "[LUA] readtext", where [LUA] was correctly in blue, but the extra "read" string was added

// #if !defined(ANDROID) && !defined(WINDOWS)
// const char * LUA_PRINT_ENTRY = "\033[1;34m[LUA] \033[0m";
// const size_t LUA_ENTRY_LENGTH = 23;
// #else
// it is more complicated than this, LUA interprets some of
// the escapes differently
const char * LUA_PRINT_ENTRY = "[LUA] ";
const size_t LUA_ENTRY_LENGTH = 6;
// #endif

False sharing

thread jobs in system allocate as object 0 to thread 0, 1 to 1, i to i % threads

this leads to threaded data locality and false sharing??

  • implement new job loading scheme

Thread Utilisation

Currently with 8 threads util is

main 99%
1-7 ~50%

More threading in collision system maybe?

OSX support

No support, need to work out how to test on a mac

Behaviour

Embed Lua to script 'AI' behaviour, items, etc

MarchingWorld and TileWorld

  • Marching squares based worlds cannot form all tile based worlds

  • Split world into MarchingXWorld and TileWorld

  • TileWorld will need more careful collision treatment

  • refactor to World[MarchingWorld,TileWorld] World [MarchingWorld[PerlinWorld,FixedWorld],TileWorld] abstraction (FixedWorld here is a TileWorld

  • specify map file type

  • refactor TileWorld to use the MapSource abstraction

  • Support different sources for the MarchingWorld's scalar field as FieldSource[FixedSource,PerlinSource]

  • Support collisions in TileWorld (see image). Will require 3x3 tile checking for additional walls

  • Support PerlinSource with a FixedSource (overrider?), (i.e. save user interactions with world ala minceraft and co)

  • Specify a .map file format which is accessible (good docs) yet efficient (compressed)

Hop - page 12

Integrate GLFW windowing

Use as a default for displaying windows and manipulating context etc

SFML and SDL2 would supersede

  • GLFW in project
  • Add optional "window loop" to Engine just provide a display class, for a user loop like sfml
  • add base example copied from sfml example (i.e. alongside sfml example)

Object Renderer

Interface ObjectRenderer with cRenderable component

Group object vertices by shader

How to link shader to component?

independent thread memory

Did not work (too slow copying)

But now CellList takes a ref to component arrays rather than all threads accessing the arrays via ObjectManager

This is much faster.

maintain one of each component array for each thread

- [ ] copy from root šŸ«š

- [ ] threaded operations act on their local memory

- [ ] sync back to root šŸ«š

- [ ] eliminates false sharing for certain

Multi-threaded Construction of Neighbour

Lists for Particle Systems in OpenMP, Rene Halver, Godehard Sutmann, 2016 : pure copy solution pretty close to more advanced
MPI solutions with threads <10

Textured Quads using Atlas textures

https://gamedev.stackexchange.com/a/174791

Texture atlas e.g n x n tiles
pass texture coords (1.0/n,1.0/n) to shader
and add offset to select correct tex coords for
requested texture

     const char * texturedQuadVertexShader = "#version 330 core\n"
    "layout(location=0) in vec4 a_position;\n"
    "layout(location=1) in vec3 a_offset;\n"
    "uniform mat4 proj;\n"
    "out vec2 texCoord;\n"
    "void main(){\n"
        "gl_Position = proj*vec4(a_offset.z*a_position.xy+a_offset.xy,0.0,1.0);\n"
        "texCoord = a_position.zw;\n"
    "}";

    const char * texturedQuadFragmentShader = "#version 330 core\n"
    "in vec2 texCoord;\n"
    "uniform sampler2D tex; out vec4 colour;\n"
    "void main(){"
        "colour=texture(tex,texCoord);"
    "\n}";

Lighting

ambient light cast by view distance

shadow quads cast by:

agent blind angles (zones)
map geometry

GL bugs in Collision Mesh's debug drawing?

  • [suspected case] release build, no particles are spawned (or just not drawn?) (debug meshes)
  • [case] 256 random balls, debug build, after a few seconds toggled debug, crashed on glyph texture reading (Setting data for Glyph texture 68 : GLERROR: GL_INVALID_VALUE)

cTransform

For use-abilities sake the position, orientation and size have been removed from cPhysics and cRenerable
and placed into cTransform.

this aids both speed and engineering

Move bounds checking out of TileWorld into World

  • move outOfBounds, pointOutOfBounds, and cameraOutOfBounds functionality to World
  • merge bounds checking with Boundary object
  • Test with MarchingWorld (perlin only for now) and TileWorld (map file)

window entry point undefined

demo builds from 18.04 fail on running in windows with something like

The procedure entry point
xxxbasic_stringxxx could not be located

apparently caused by an incorrect glibc and

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.