#ifndef HELI_PRIVATE_H
#define HELI_PRIVATE_H
#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 <GL/glext.h>
#include "common.h"
#include "animation.h"
#include "framebuffer.h"
#include "sprite.h"
#include "font.h"
// globals
#define HELI_PRECISION 1e-6
#define HELI_PRECISION_SQR 1e-12
#define HELI_MIN_FPS 1
#define HELI_MAX_FPS 100
#define HELI_DEFAULT_FPS 24
// blobs
extern char heliBlobDefaultFont[] asm("heliBlobDefaultFont");
extern int heliBlobDefaultFontSize asm("heliBlobDefaultFontSize");
extern char heliBlobUnicodeFont[] asm("heliBlobUnicodeFont");
extern int heliBlobUnicodeFontSize asm("heliBlobUnicodeFontSize");
// string
char* heliStringCopy(const char *x);
char* heliStringCopyLower(const char *x);
char* heliStringConcat(const char *a, const char *b);
char* heliStringConcat3(const char *a, const char *b, const char *c);
int heliStringCompareCi(const char *a, const char *b);
int heliStringCompareNCi(const char *a, const char *b, size_t n);
int heliStringEndsWithLowcase(const char *s, const char *tail);
void heliStringLower(char *x);
// common
void heliColorToDouble(unsigned int code, double *rgba);
// 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* heliUIntFind(HeliArray *a, size_t k, int *gtOrEqIndex);
HeliPair* heliUIntGet(HeliArray *a, size_t k);
HeliPair* heliUIntAdd(HeliArray *a, size_t k, void *v, HeliFreeCallback fv);
int heliUIntRemove(HeliArray *a, size_t k);
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);
// geometry
void heliMatrix4Identity(double *r);
void heliMatrix4Translation(double *r, double x, double y, double z);
void heliMatrix4Scale(double *r, double x, double y, double z);
void heliMatrix4RotationZ(double *r, double a);
void heliMatrix4MultVec(double *r, const double *m, const double *v);
void heliMatrix4Mult(double *r, const double *a, const double *b);
int heliMatrix4Invert(double *r, const double *m);
// gl
typedef struct _HeliGLClipPlaneState {
int enabled;
double equation[4];
} HeliGLClipPlaneState;
typedef struct _HeliGLCommonState {
unsigned int flags;
double modelviewMatrix[16];
double projectionMatrix[16];
double clearColor[4];
int viewport[4];
unsigned int framebuffer_read_id;
unsigned int framebuffer_draw_id;
HeliGLClipPlaneState clipPlanes[4];
} HeliGLCommonState;
typedef void (APIENTRY *HeliGLBlendFuncSeparatePtr)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
typedef void (APIENTRY *HeliGLStencilOpSeparatePtr)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
typedef void (APIENTRY *HeliGLTexImage2DMultisamplePtr)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
typedef void (APIENTRY *HeliGLGenFramebuffersPtr)(GLsizei n, GLuint *framebuffers);
typedef void (APIENTRY *HeliGLDeleteFramebuffersPtr)(GLsizei n, const GLuint *framebuffers);
typedef void (APIENTRY *HeliGLBindFramebufferPtr)(GLenum target, GLuint framebuffer);
typedef void (APIENTRY *HeliGLBlitFramebufferPtr)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
typedef void (APIENTRY *HeliGLFramebufferRenderbufferPtr)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
typedef void (APIENTRY *HeliGLFramebufferTexture2DPtr)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
typedef GLenum (APIENTRY *HeliGLCheckFramebufferStatusPtr)(GLenum target);
typedef void (APIENTRY *HeliGLGenRenderbuffersPtr)(GLsizei n, GLuint *renderbuffers);
typedef void (APIENTRY *HeliGLDeleteRenderbuffersPtr)(GLsizei n, const GLuint *renderbuffers);
typedef void (APIENTRY *HeliGLBindRenderbufferPtr)(GLenum target, GLuint renderbuffer);
typedef void (APIENTRY *HeliGLRenderbufferStoragePtr)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
typedef void (APIENTRY *HeliGLRenderbufferStorageMultisamplePtr)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
extern HeliGLBlendFuncSeparatePtr heliGLBlendFuncSeparatePtr;
extern HeliGLStencilOpSeparatePtr heliGLStencilOpSeparatePtr;
extern HeliGLTexImage2DMultisamplePtr heliGLTexImage2DMultisamplePtr;
extern HeliGLGenFramebuffersPtr heliGLGenFramebuffersPtr;
extern HeliGLDeleteFramebuffersPtr heliGLDeleteFramebuffersPtr;
extern HeliGLBindFramebufferPtr heliGLBindFramebufferPtr;
extern HeliGLBlitFramebufferPtr heliGLBlitFramebufferPtr;
extern HeliGLFramebufferRenderbufferPtr heliGLFramebufferRenderbufferPtr;
extern HeliGLFramebufferTexture2DPtr heliGLFramebufferTexture2DPtr;
extern HeliGLCheckFramebufferStatusPtr heliGLCheckFramebufferStatusPtr;
extern HeliGLGenRenderbuffersPtr heliGLGenRenderbuffersPtr;
extern HeliGLDeleteRenderbuffersPtr heliGLDeleteRenderbuffersPtr;
extern HeliGLBindRenderbufferPtr heliGLBindRenderbufferPtr;
extern HeliGLRenderbufferStoragePtr heliGLRenderbufferStoragePtr;
extern HeliGLRenderbufferStorageMultisamplePtr heliGLRenderbufferStorageMultisamplePtr;
extern unsigned int heliGLWindowFramebufferReadId;
extern unsigned int heliGLWindowFramebufferDrawId;
double heliGLGetAAResolution();
double heliGLGetPixelSize();
int heliGLIsIntegerClipping();
int heliGLTransform(double *x, double *y, int reverse);
void heliGLGetCommonState(HeliGLCommonState *state, unsigned int flags);
void heliGLSetCommonState(const HeliGLCommonState *state);
// all objects
extern int heliInitialized;
extern HeliArray heliObjectsSet;
void heliObjectRegister(void *o, HeliFreeCallback fo);
void heliObjectUnregister(void *o);
// drawing
typedef struct _HeliTextureState {
Animation animation;
int fixed;
double genx[4], geny[4];
} HeliTextureState;
typedef struct _HeliDrawingState {
unsigned int flags;
int antialiasing;
double fillColor[4];
double strokeColor[4];
double strokeWidth;
HAlign horAlign;
VAlign vertAlign;
double fontSize;
Font font;
HeliTextureState fillTexture;
HeliTextureState strokeTexture;
HeliGLCommonState glState;
} HeliDrawingState;
extern HeliArray heliDrawingFramebuffersToFlush;
HeliDrawingState *heliDrawingGetState();
HeliDrawingState *heliDrawingGetStateStack();
void heliDrawingApplyTexture(double *color, HeliTextureState *state);
void heliDrawingResetTexture();
void heliFillRectSimple(double x0, double y0, double x1, double y1, double aaBorder, int antialiasing);
void heliFillCircleSimple(double x, double y, double r, double aaBorder, int antialiasing);
void heliDrawingClearFrame();
void heliDrawingPrepareFrame();
void heliDrawingFinish();
// font
void heliFontFinish();
// animation
void heliAnimationUpdate(double dt);
void heliAnimationFinish();
// collider
typedef struct _HeliCollider {
Collider type;
double x;
double y;
double radius;
double width;
double height;
double rotation;
double bounciness;
double bouncinessThreshold;
} HeliCollider;
typedef struct _HeliCollisionInfo {
int actualCollision;
double distance;
double dx, dy;
double vx, vy;
double ax, ay;
} HeliCollisionInfo;
int heliCheckCollision(
HeliCollider *a, HeliCollider *b,
HeliCollisionInfo *info,
double distance );
int heliPointCollision(HeliCollider *c, double x, double y);
// sprite
typedef void (*HeliSpriteEashInt)(Sprite, int);
typedef void (*HeliSpriteEashUInt)(Sprite, unsigned int);
typedef void (*HeliSpriteEashDouble)(Sprite, double);
HeliArray* heliSpriteGetGroups(Sprite sprite);
int heliSpriteCollisionCheck(Sprite a, Sprite b, HeliCollisionInfo *info);
void heliSpriteCollisionApply(Sprite a, Sprite b, HeliCollisionInfo *info);
void heliSpriteDraw(Sprite sprite);
void heliSpriteDrawDebug(Sprite sprite);
void heliSpriteSort(HeliArray *sprites);
void heliSpriteUpdate(double dt);
void heliSpriteFinish();
// sound
void heliSoundUpdate();
void heliSoundFinish();
// window
typedef struct _HeliDialog {
int shown;
const char *question;
char *answer;
char *passwordText;
int maxAnswerSize;
int multiline;
int password;
int pos;
int selPos;
double scrollX;
double scrollY;
int success;
} HeliDialog;
void heliDialogDraw(HeliDialog *dialog);
// test
void heliDoTests();
#endif