GithubHelp home page GithubHelp logo

ncatalani / fpsloop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silent-tower-games/fpsloop

0.0 0.0 0.0 54 KB

C library for managing game loop

License: MIT License

Makefile 7.10% C 92.90%

fpsloop's Introduction

FPSLoop

A good & simple gameplay loop for C and SDL2.

Dependencies

  • A C compiler
  • SDL2

Building

The easiest way is just to run make, which will build the shared lib & the test program. There are other methods in the Makefile as well.

Example

// Return 1 to exit, 0 to keep going
int frame()
{
    // Keep going forever
    return 0;
}

int main()
{
    FPSLoop* fps = FPSLoop_Create(
        // How should the app keep time?
        FPSLOOP_TYPE_SLEEPSMART,
        // How many frames per second?
        60,
        // Pointer to the function that holds your game logic
        frame
    );
    
    // Your application will run inside this function
    // It will stop running when your logic function has decided to close
    FPSLoop_Run(fps);
    
    // Free the FPSLoop* memory
    FPSLoop_Destroy(fps);
    
    return 0;
}

Loop Types

You can change the Loop Type mid-application:

FPSLoop_SetLoopType(fps, FPSLOOP_TYPE_SLEEP); // replace _SLEEP with your desired loop type

The enum FPSLoop_Type contains several values:

BURNCPU

This type should have the closest thing to perfect timing, at the cost of a lot of CPU power.

SLEEP

This type will use the least CPU power, but will also potentially sacrifice accurate timing.

SLEEPSMART

This type combines BURNCPU and SLEEP to use a little more CPU power & get a lot more accuracy.

NOTHING

This type does nothing for timing whatsoever. This might be useful if you explicitly use vsync, but also it really might not.

Other Methods

GetAverageFPS

float FPSLoop_GetAverageFPS(FPSLoop*) will return a float value of the average of the last 120 frames (or a different number, if given a compiler flag for FPSLOOP_FRAME_PERFORMANCE_COUNT).

GetLoopTypeString

char* FPSLoop_GetLoopTypeString(FPSLoop*) will return a string denoting which loop type is being used for the given FPSLoop instance.

GetLoopTypeStringFromType

char* FPSLoop_GetLoopTypeStringFromType(FPSLoop_Type) will return a string corresponding to the given FPSLoop_Type value.

fpsloop's People

Contributors

retroswan avatar ncatalani 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.