#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include "common.h"
#include "sprite.h"
// globals
#define HELI_PRECISION 1e-6
#define HELI_PRECISION_SQR 1e-12
// blobs
extern char heliBlobDefaultFont[];
extern int heliBlobDefaultFontSize;
// string
char* heliStringCopy(const char *x);
char* heliStringConcat3(const char *a, const char *b, const char *c);
int heliStringEndsWithLowcase(const char *s, const char *tail);
void heliLowercase(char *x);
void heliParseColor(const char *x, double *color);
// pointer array
typedef void (*HeliFreeCallback)(void*);
typedef void* (*HeliCloneCallback)(const void*);
typedef int (*HeliCompareCallback)(const void*, const void*);
typedef struct _HeliPair {
void *key;
void *value;
HeliFreeCallback freeKey;
HeliFreeCallback freeValue;
} HeliPair;
typedef struct _HeliArray {
HeliPair *items;
int count;
int allocated;
} HeliArray;
void heliPairInit(HeliPair *p);
void heliPairDestroy(HeliPair *p);
void heliArrayInit(HeliArray *a);
void heliArrayClear(HeliArray *a);
void heliArrayDestroy(HeliArray *a);
HeliPair* heliArrayGet(HeliArray *a, int i);
void* heliArrayGetKey(HeliArray *a, int i);
void* heliArrayGetValue(HeliArray *a, int i);
HeliPair* heliArrayInsert(HeliArray *a, int i, void *v, HeliFreeCallback fv);
HeliPair* heliArrayInsertPair(HeliArray *a, int i, void *k, HeliFreeCallback fk, void *v, HeliFreeCallback fv);
void heliArrayRemove(HeliArray *a, int i);
HeliPair* heliMapFind(HeliArray *a, const void *k, HeliCompareCallback cmp, int *gtOrEqIndex);
HeliPair* heliMapGet(HeliArray *a, const void *k, HeliCompareCallback cmp);
HeliPair* heliMapAdd(
HeliArray *a, const void *k, HeliCompareCallback cmp,
HeliCloneCallback ck, HeliFreeCallback fk,
void *v, HeliFreeCallback fv );
int heliMapRemove(HeliArray *a, const void *k, HeliCompareCallback cmp);
HeliPair* heliStringmapFind(HeliArray *a, const char *k, int *gtOrEqIndex);
HeliPair* heliStringmapGet(HeliArray *a, const char *k);
HeliPair* heliStringmapAdd(HeliArray *a, const char *k, void *v, HeliFreeCallback fv);
int heliStringmapRemove(HeliArray *a, const char *k);
// all objects
extern int heliInitialized;
extern HeliArray heliObjectsSet;
void heliObjectRegister(void *o, HeliFreeCallback fo);
void heliObjectUnregister(void *o);
// animation
typedef struct _HeliAnimation {
char *path;
HeliArray frames;
int refcount;
} HeliAnimation;
HeliAnimation* heliAnimationLoad(const char *path);
void heliAnimationUnref(HeliAnimation *a);
void heliAnimationFinish();
// collider
typedef struct _HeliCollider {
Collider type;
double x;
double y;
double radius;
double width;
double height;
double rotation;
} HeliCollider;
int heliCheckCollision(
HeliCollider *a, HeliCollider *b,
double *dx, double *dy,
double *vx, double *vy,
double bounciness );
int heliPointCollision(HeliCollider *c, double x, double y);
// sprite
typedef void (*HeliSpriteEashInt)(Sprite, int);
typedef void (*HeliSpriteEashDouble)(Sprite, double);
typedef void (*HeliSpriteEashString)(Sprite, const char*);
HeliArray* heliSpriteGetGroups(Sprite sprite);
void heliSpriteUpdate(double dt);
void heliSpriteFinish();
// drawing
extern double heliDrawingColorStroke[4];
void heliDrawingClearFrame();
void heliDrawingPrepareFrame();
void heliDrawingFinish();
// font
void heliFontFinish();
// sound
void heliSoundUpdate();
void heliSoundFinish();
// test
void heliDoTests();