Code Monkey home page Code Monkey logo

fbanim's Introduction

fbanim - frame based animation system

fbanim is a 'time' based scheduler written in C. It is used to perodically schedule function calls over an arbitrary timeline.

It is what is normally known as a 'dynamic main loop'.

Frames are run over specified frame boundaries or dynamically at run-time.

The following is a short example:

#include "fbanim.h"
#include "fbanim.c"

void proc1(int arg) {
  printf(".");
}

void proc2(int arg) {
  printf(",");
}

int main() {
  ListInit();
  InitFrameBasedAnimSystem();
  InsertProc(0,		/* start frame	*/
  	     -1,	/* end frame	*/
	     1,		/* period	*/
	     0,		/* priority	*/
	     proc1,	/* function	*/
	     0		/* argument	*/);
  InsertProc(0, -1, 1, 0, proc2, 0);
  RunFrameBasedAnimSystem();
}

This will print a series of dots and commas on the screen until you hit Ctrl-C.

Next Steps

This could be used in conjunction with 'sxc' to generate data to be fed into the scheduler beyond the normal capabilities of C. To do this, one would have to define the data structure to be fed to the scheduler, something like so:

struct {
       unsigned int start_frame;
       unsigned int end_frame;
       unsigned int period;
       unsigned int priority;
       void* function;
       unsigned long argument;
} Process;

The input 'data' file would be C code defining the functions and the array of Proceses to be fed to the scheduler. Here is the code for this:

#include "fbanim.h"
#include "fbanim.c"

typedef struct {
       unsigned int start_frame;
       unsigned int end_frame;
       unsigned int period;
       unsigned int priority;
       void* function;
       unsigned long argument;
} Process;

void proc1(int arg) {
  printf(".");
}

void proc2(int arg) {
  printf(",");
}

Process procs[] = {
  { 0, -1, 1, 0, proc1, 0 },
  { 0, -1, 1, 0, proc2, 0 }
};

int nprocs = sizeof(procs)/sizeof(procs[0]);

void loadup() {
  for(int i = 0; i < nprocs; i++) {
    Process *proc = &procs[i];
    InsertProc(proc->start_frame,
	       proc->end_frame,
	       proc->period,
	       proc->priority,
	       proc->function,
	       proc->argument);
  }
}

int main() {
  ListInit();
  InitFrameBasedAnimSystem();

  loadup();

  RunFrameBasedAnimSystem();
}

TODO

  • turn into shared library.

  • writing bindings for Common Lisp?

  • re-write in Common Lisp.

-- Copyleft - Burton Samograd [email protected] 2016

fbanim's People

Contributors

burtonsamograd avatar

Watchers

 avatar  avatar  avatar

Forkers

busfactor1inc

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.