Blame src/private.h

Ivan Mahonin 534343
#ifndef HELI_PRIVATE_H
Ivan Mahonin 534343
#define HELI_PRIVATE_H
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
#include <assert.h>
Ivan Mahonin 3f9996
#include <string.h>
Ivan Mahonin 3f9996
#include <stdlib.h>
Ivan Mahonin 8535a3
#include <stdio.h>
Ivan Mahonin 3f9996
#include <ctype.h>
Ivan Mahonin 3f9996
#include <math.h>
Ivan Mahonin 3f9996
Ivan Mahonin ba9f06
#define GL_GLEXT_PROTOTYPES
Ivan Mahonin f63775
#include <GL/gl.h>
Ivan Mahonin 87fe10
#include <GL/glext.h>
Ivan Mahonin 8535a3
Ivan Mahonin 3f9996
#include "common.h"
Ivan Mahonin 1d641c
#include "animation.h"
Ivan Mahonin 1d641c
#include "framebuffer.h"
Ivan Mahonin 3f9996
#include "sprite.h"
Ivan Mahonin 3954ba
#include "font.h"
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
// globals
Ivan Mahonin 3f9996
Ivan Mahonin 1c7488
#define HELI_PRECISION 1e-6
Ivan Mahonin 1c7488
#define HELI_PRECISION_SQR 1e-12
Ivan Mahonin dba3fc
#define HELI_MIN_FPS 1
Ivan Mahonin dba3fc
#define HELI_MAX_FPS 100
Ivan Mahonin dba3fc
#define HELI_DEFAULT_FPS 24
Ivan Mahonin 1c7488
Ivan Mahonin f63775
Ivan Mahonin f63775
// blobs
Ivan Mahonin f63775
Ivan Mahonin 87fe10
extern char heliBlobDefaultFont[] asm("heliBlobDefaultFont");
Ivan Mahonin 87fe10
extern int heliBlobDefaultFontSize asm("heliBlobDefaultFontSize");
Ivan Mahonin 2fcd94
extern char heliBlobUnicodeFont[] asm("heliBlobUnicodeFont");
Ivan Mahonin 2fcd94
extern int heliBlobUnicodeFontSize asm("heliBlobUnicodeFontSize");
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
// string
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
char* heliStringCopy(const char *x);
Ivan Mahonin bcaca0
char* heliStringCopyLower(const char *x);
Ivan Mahonin dba3fc
char* heliStringConcat(const char *a, const char *b);
Ivan Mahonin 8535a3
char* heliStringConcat3(const char *a, const char *b, const char *c);
Ivan Mahonin bcaca0
int heliStringCompareCi(const char *a, const char *b);
Ivan Mahonin dac862
int heliStringCompareNCi(const char *a, const char *b, size_t n);
Ivan Mahonin 8535a3
int heliStringEndsWithLowcase(const char *s, const char *tail);
Ivan Mahonin bcaca0
void heliStringLower(char *x);
Ivan Mahonin bcaca0
Ivan Mahonin d4e89f
Ivan Mahonin d4e89f
Ivan Mahonin d4e89f
// common
Ivan Mahonin d4e89f
Ivan Mahonin d4e89f
void heliColorToDouble(unsigned int code, double *rgba);
Ivan Mahonin 3f9996
Ivan Mahonin 09c823
Ivan Mahonin 3f9996
// pointer array
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
typedef void (*HeliFreeCallback)(void*);
Ivan Mahonin 8eb855
typedef void* (*HeliCloneCallback)(const void*);
Ivan Mahonin 8eb855
typedef int (*HeliCompareCallback)(const void*, const void*);
Ivan Mahonin 8535a3
Ivan Mahonin 8535a3
typedef struct _HeliPair {
Ivan Mahonin 8535a3
	void *key;
Ivan Mahonin 8535a3
	void *value;
Ivan Mahonin 8535a3
	HeliFreeCallback freeKey;
Ivan Mahonin 8535a3
	HeliFreeCallback freeValue;
Ivan Mahonin 8535a3
} HeliPair;
Ivan Mahonin 8535a3
Ivan Mahonin 3f9996
typedef struct _HeliArray {
Ivan Mahonin 8535a3
	HeliPair *items;
Ivan Mahonin 3f9996
	int count;
Ivan Mahonin 3f9996
	int allocated;
Ivan Mahonin 3f9996
} HeliArray;
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
void heliPairInit(HeliPair *p);
Ivan Mahonin 8535a3
void heliPairDestroy(HeliPair *p);
Ivan Mahonin 8535a3
Ivan Mahonin 07b70f
void heliArrayInit(HeliArray *a);
Ivan Mahonin 8535a3
void heliArrayClear(HeliArray *a);
Ivan Mahonin 07b70f
void heliArrayDestroy(HeliArray *a);
Ivan Mahonin 8535a3
HeliPair* heliArrayGet(HeliArray *a, int i);
Ivan Mahonin 8535a3
void* heliArrayGetKey(HeliArray *a, int i);
Ivan Mahonin 8535a3
void* heliArrayGetValue(HeliArray *a, int i);
Ivan Mahonin 8535a3
HeliPair* heliArrayInsert(HeliArray *a, int i, void *v, HeliFreeCallback fv);
Ivan Mahonin 8eb855
HeliPair* heliArrayInsertPair(HeliArray *a, int i, void *k, HeliFreeCallback fk, void *v, HeliFreeCallback fv);
Ivan Mahonin 8535a3
void heliArrayRemove(HeliArray *a, int i);
Ivan Mahonin 8535a3
Ivan Mahonin 8eb855
HeliPair* heliMapFind(HeliArray *a, const void *k, HeliCompareCallback cmp, int *gtOrEqIndex);
Ivan Mahonin 8eb855
HeliPair* heliMapGet(HeliArray *a, const void *k, HeliCompareCallback cmp);
Ivan Mahonin 8eb855
HeliPair* heliMapAdd(
Ivan Mahonin 8eb855
	HeliArray *a, const void *k, HeliCompareCallback cmp,
Ivan Mahonin 8eb855
	HeliCloneCallback ck, HeliFreeCallback fk,
Ivan Mahonin 8eb855
	void *v, HeliFreeCallback fv );
Ivan Mahonin 8eb855
int heliMapRemove(HeliArray *a, const void *k, HeliCompareCallback cmp);
Ivan Mahonin 8eb855
Ivan Mahonin 909bc2
HeliPair* heliUIntFind(HeliArray *a, size_t k, int *gtOrEqIndex);
Ivan Mahonin 909bc2
HeliPair* heliUIntGet(HeliArray *a, size_t k);
Ivan Mahonin 909bc2
HeliPair* heliUIntAdd(HeliArray *a, size_t k, void *v, HeliFreeCallback fv);
Ivan Mahonin 909bc2
int heliUIntRemove(HeliArray *a, size_t k);
Ivan Mahonin 909bc2
Ivan Mahonin 8535a3
HeliPair* heliStringmapFind(HeliArray *a, const char *k, int *gtOrEqIndex);
Ivan Mahonin 8535a3
HeliPair* heliStringmapGet(HeliArray *a, const char *k);
Ivan Mahonin 8535a3
HeliPair* heliStringmapAdd(HeliArray *a, const char *k, void *v, HeliFreeCallback fv);
Ivan Mahonin 8535a3
int heliStringmapRemove(HeliArray *a, const char *k);
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
Ivan Mahonin 8bc1f1
// geometry
Ivan Mahonin 8bc1f1
Ivan Mahonin 8bc1f1
void heliMatrix4Identity(double *r);
Ivan Mahonin 8bc1f1
void heliMatrix4Translation(double *r, double x, double y, double z);
Ivan Mahonin 8bc1f1
void heliMatrix4Scale(double *r, double x, double y, double z);
Ivan Mahonin 8bc1f1
void heliMatrix4RotationZ(double *r, double a);
Ivan Mahonin 8bc1f1
void heliMatrix4MultVec(double *r, const double *m, const double *v);
Ivan Mahonin 8bc1f1
void heliMatrix4Mult(double *r, const double *a, const double *b);
Ivan Mahonin 8bc1f1
int heliMatrix4Invert(double *r, const double *m);
Ivan Mahonin 8bc1f1
Ivan Mahonin deef1d
Ivan Mahonin deef1d
// gl
Ivan Mahonin deef1d
Ivan Mahonin deef1d
typedef struct _HeliGLClipPlaneState {
Ivan Mahonin deef1d
	int enabled;
Ivan Mahonin deef1d
	double equation[4];
Ivan Mahonin deef1d
} HeliGLClipPlaneState;
Ivan Mahonin deef1d
Ivan Mahonin deef1d
typedef struct _HeliGLCommonState {
Ivan Mahonin deef1d
	unsigned int flags;
Ivan Mahonin deef1d
	double modelviewMatrix[16];
Ivan Mahonin 1d641c
	double projectionMatrix[16];
Ivan Mahonin d6f40c
	double clearColor[4];
Ivan Mahonin 1d641c
	int viewport[4];
Ivan Mahonin 1d641c
	unsigned int framebuffer_read_id;
Ivan Mahonin 1d641c
	unsigned int framebuffer_draw_id;
Ivan Mahonin deef1d
	HeliGLClipPlaneState clipPlanes[4];
Ivan Mahonin deef1d
} HeliGLCommonState;
Ivan Mahonin deef1d
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLBlendFuncSeparatePtr)(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLStencilOpSeparatePtr)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLTexImage2DMultisamplePtr)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLGenFramebuffersPtr)(GLsizei n, GLuint *framebuffers);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLDeleteFramebuffersPtr)(GLsizei n, const GLuint *framebuffers);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLBindFramebufferPtr)(GLenum target, GLuint framebuffer);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLBlitFramebufferPtr)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLFramebufferRenderbufferPtr)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLFramebufferTexture2DPtr)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
Ivan Mahonin 909bc2
typedef GLenum (APIENTRY *HeliGLCheckFramebufferStatusPtr)(GLenum target);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLGenRenderbuffersPtr)(GLsizei n, GLuint *renderbuffers);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLDeleteRenderbuffersPtr)(GLsizei n, const GLuint *renderbuffers);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLBindRenderbufferPtr)(GLenum target, GLuint renderbuffer);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLRenderbufferStoragePtr)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
Ivan Mahonin 1d641c
typedef void (APIENTRY *HeliGLRenderbufferStorageMultisamplePtr)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
Ivan Mahonin 1d641c
Ivan Mahonin 1d641c
extern HeliGLBlendFuncSeparatePtr       heliGLBlendFuncSeparatePtr;
Ivan Mahonin 1d641c
extern HeliGLStencilOpSeparatePtr       heliGLStencilOpSeparatePtr;
Ivan Mahonin 1d641c
extern HeliGLTexImage2DMultisamplePtr   heliGLTexImage2DMultisamplePtr;
Ivan Mahonin 1d641c
extern HeliGLGenFramebuffersPtr         heliGLGenFramebuffersPtr;
Ivan Mahonin 1d641c
extern HeliGLDeleteFramebuffersPtr      heliGLDeleteFramebuffersPtr;
Ivan Mahonin 1d641c
extern HeliGLBindFramebufferPtr         heliGLBindFramebufferPtr;
Ivan Mahonin 1d641c
extern HeliGLBlitFramebufferPtr         heliGLBlitFramebufferPtr;
Ivan Mahonin 1d641c
extern HeliGLFramebufferRenderbufferPtr heliGLFramebufferRenderbufferPtr;
Ivan Mahonin 1d641c
extern HeliGLFramebufferTexture2DPtr    heliGLFramebufferTexture2DPtr;
Ivan Mahonin 909bc2
extern HeliGLCheckFramebufferStatusPtr  heliGLCheckFramebufferStatusPtr;
Ivan Mahonin 1d641c
extern HeliGLGenRenderbuffersPtr        heliGLGenRenderbuffersPtr;
Ivan Mahonin 1d641c
extern HeliGLDeleteRenderbuffersPtr     heliGLDeleteRenderbuffersPtr;
Ivan Mahonin 1d641c
extern HeliGLBindRenderbufferPtr        heliGLBindRenderbufferPtr;
Ivan Mahonin 1d641c
extern HeliGLRenderbufferStoragePtr     heliGLRenderbufferStoragePtr;
Ivan Mahonin 1d641c
extern HeliGLRenderbufferStorageMultisamplePtr heliGLRenderbufferStorageMultisamplePtr;
Ivan Mahonin 1d641c
Ivan Mahonin 1d641c
extern unsigned int heliGLWindowFramebufferReadId;
Ivan Mahonin 1d641c
extern unsigned int heliGLWindowFramebufferDrawId;
Ivan Mahonin 1d641c
Ivan Mahonin 8bc1f1
double heliGLGetAAResolution();
Ivan Mahonin 812e27
double heliGLGetPixelSize();
Ivan Mahonin 8bc1f1
int heliGLIsIntegerClipping();
Ivan Mahonin 4e392e
int heliGLTransform(double *x, double *y, int reverse);
Ivan Mahonin deef1d
void heliGLGetCommonState(HeliGLCommonState *state, unsigned int flags);
Ivan Mahonin deef1d
void heliGLSetCommonState(const HeliGLCommonState *state);
Ivan Mahonin 8bc1f1
Ivan Mahonin 8bc1f1
Ivan Mahonin 8eb855
// all objects
Ivan Mahonin 8eb855
Ivan Mahonin 8eb855
extern int heliInitialized;
Ivan Mahonin 8eb855
extern HeliArray heliObjectsSet;
Ivan Mahonin 8eb855
void heliObjectRegister(void *o, HeliFreeCallback fo);
Ivan Mahonin 8eb855
void heliObjectUnregister(void *o);
Ivan Mahonin 8eb855
Ivan Mahonin 8eb855
Ivan Mahonin deef1d
// drawing
Ivan Mahonin deef1d
Ivan Mahonin deef1d
typedef struct _HeliTextureState {
Ivan Mahonin deef1d
	Animation animation;
Ivan Mahonin deef1d
	int fixed;
Ivan Mahonin b4b587
	double genx[4], geny[4];
Ivan Mahonin deef1d
} HeliTextureState;
Ivan Mahonin deef1d
Ivan Mahonin deef1d
typedef struct _HeliDrawingState {
Ivan Mahonin deef1d
	unsigned int flags;
Ivan Mahonin b4b587
	int antialiasing;
Ivan Mahonin deef1d
	double fillColor[4];
Ivan Mahonin deef1d
	double strokeColor[4];
Ivan Mahonin deef1d
	double strokeWidth;
Ivan Mahonin deef1d
	HAlign horAlign;
Ivan Mahonin deef1d
	VAlign vertAlign;
Ivan Mahonin deef1d
	double fontSize;
Ivan Mahonin deef1d
	Font font;
Ivan Mahonin deef1d
	HeliTextureState fillTexture;
Ivan Mahonin deef1d
	HeliTextureState strokeTexture;
Ivan Mahonin deef1d
	HeliGLCommonState glState;
Ivan Mahonin deef1d
} HeliDrawingState;
Ivan Mahonin deef1d
Ivan Mahonin 33fee5
extern HeliArray heliDrawingFramebuffersToFlush;
Ivan Mahonin 909bc2
Ivan Mahonin deef1d
HeliDrawingState *heliDrawingGetState();
Ivan Mahonin deef1d
HeliDrawingState *heliDrawingGetStateStack();
Ivan Mahonin deef1d
void heliDrawingApplyTexture(double *color, HeliTextureState *state);
Ivan Mahonin deef1d
void heliDrawingResetTexture();
Ivan Mahonin b4b587
void heliFillRectSimple(double x0, double y0, double x1, double y1, double aaBorder, int antialiasing);
Ivan Mahonin b4b587
void heliFillCircleSimple(double x, double y, double r, double aaBorder, int antialiasing);
Ivan Mahonin deef1d
void heliDrawingClearFrame();
Ivan Mahonin deef1d
void heliDrawingPrepareFrame();
Ivan Mahonin deef1d
void heliDrawingFinish();
Ivan Mahonin deef1d
Ivan Mahonin deef1d
Ivan Mahonin deef1d
// font
Ivan Mahonin deef1d
Ivan Mahonin deef1d
void heliFontFinish();
Ivan Mahonin deef1d
Ivan Mahonin deef1d
Ivan Mahonin 8535a3
// animation
Ivan Mahonin 8535a3
Ivan Mahonin dba3fc
void heliAnimationUpdate(double dt);
Ivan Mahonin 07b70f
void heliAnimationFinish();
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
// collider
Ivan Mahonin 3f9996
Ivan Mahonin 3f9996
typedef struct _HeliCollider {
Ivan Mahonin 3f9996
	Collider type;
Ivan Mahonin 3f9996
	double x;
Ivan Mahonin 3f9996
	double y;
Ivan Mahonin 3f9996
	double radius;
Ivan Mahonin 3f9996
	double width;
Ivan Mahonin 3f9996
	double height;
Ivan Mahonin 3f9996
	double rotation;
Ivan Mahonin 44355f
	double bounciness;
Ivan Mahonin 44355f
	double bouncinessThreshold;
Ivan Mahonin 3f9996
} HeliCollider;
Ivan Mahonin 3f9996
Ivan Mahonin f80a0a
typedef struct _HeliCollisionInfo {
Ivan Mahonin f80a0a
	int actualCollision;
Ivan Mahonin f80a0a
	double distance;
Ivan Mahonin f80a0a
	double dx, dy;
Ivan Mahonin f80a0a
	double vx, vy;
Ivan Mahonin f80a0a
	double ax, ay;
Ivan Mahonin f80a0a
} HeliCollisionInfo;
Ivan Mahonin f80a0a
Ivan Mahonin 1c7488
int heliCheckCollision(
Ivan Mahonin 1c7488
	HeliCollider *a, HeliCollider *b,
Ivan Mahonin f80a0a
	HeliCollisionInfo *info,
Ivan Mahonin f80a0a
	double distance );
Ivan Mahonin 1c7488
Ivan Mahonin 3f9996
int heliPointCollision(HeliCollider *c, double x, double y);
Ivan Mahonin 3f9996
Ivan Mahonin 8535a3
Ivan Mahonin 8535a3
// sprite
Ivan Mahonin 8535a3
Ivan Mahonin 07b70f
typedef void (*HeliSpriteEashInt)(Sprite, int);
Ivan Mahonin d4e89f
typedef void (*HeliSpriteEashUInt)(Sprite, unsigned int);
Ivan Mahonin 07b70f
typedef void (*HeliSpriteEashDouble)(Sprite, double);
Ivan Mahonin 8535a3
HeliArray* heliSpriteGetGroups(Sprite sprite);
Ivan Mahonin f80a0a
int heliSpriteCollisionCheck(Sprite a, Sprite b, HeliCollisionInfo *info);
Ivan Mahonin f80a0a
void heliSpriteCollisionApply(Sprite a, Sprite b, HeliCollisionInfo *info);
Ivan Mahonin 6eadb0
void heliSpriteDraw(Sprite sprite);
Ivan Mahonin 6eadb0
void heliSpriteDrawDebug(Sprite sprite);
Ivan Mahonin 44355f
void heliSpriteSort(HeliArray *sprites);
Ivan Mahonin 07b70f
void heliSpriteUpdate(double dt);
Ivan Mahonin 07b70f
void heliSpriteFinish();
Ivan Mahonin 8535a3
Ivan Mahonin 07b70f
Ivan Mahonin 09c823
// sound
Ivan Mahonin 09c823
Ivan Mahonin 09c823
void heliSoundUpdate();
Ivan Mahonin 09c823
void heliSoundFinish();
Ivan Mahonin 09c823
Ivan Mahonin 09c823
Ivan Mahonin d7d433
// window
Ivan Mahonin 534343
Ivan Mahonin 534343
typedef struct _HeliDialog {
Ivan Mahonin 534343
	int shown;
Ivan Mahonin 534343
	const char *question;
Ivan Mahonin 534343
	char *answer;
Ivan Mahonin 97fe4e
	char *passwordText;
Ivan Mahonin 534343
	int maxAnswerSize;
Ivan Mahonin 534343
	int multiline;
Ivan Mahonin 534343
	int password;
Ivan Mahonin 534343
	int pos;
Ivan Mahonin 534343
	int selPos;
Ivan Mahonin 534343
	double scrollX;
Ivan Mahonin 534343
	double scrollY;
Ivan Mahonin 534343
	int success;
Ivan Mahonin 534343
} HeliDialog;
Ivan Mahonin 534343
Ivan Mahonin 534343
void heliDialogDraw(HeliDialog *dialog);
Ivan Mahonin 534343
Ivan Mahonin 534343
Ivan Mahonin d1f083
// test
Ivan Mahonin d1f083
Ivan Mahonin d1f083
void heliDoTests();
Ivan Mahonin d1f083
Ivan Mahonin 534343
Ivan Mahonin 534343
#endif