Blob Blame Raw
#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 "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");


// string

char* heliStringCopy(const char *x);
char* heliStringConcat(const char *a, const char *b);
char* heliStringConcat3(const char *a, const char *b, const char *c);
int heliStringEndsWithLowcase(const char *s, const char *tail);
void heliLowercase(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* 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];
	HeliGLClipPlaneState clipPlanes[4];
} HeliGLCommonState;

double heliGLGetAAResolution();
int heliGLIsIntegerClipping();
int heliGLBackTransform(double *x, double *y);
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 {
	double color[4];
	Animation animation;
	int fixed;
	double x, y, width, height;
} HeliTextureState;

typedef struct _HeliDrawingState {
	unsigned int flags;
	double fillColor[4];
	double strokeColor[4];
	double strokeWidth;
	HAlign horAlign;
	VAlign vertAlign;
	double fontSize;
	Font font;
	HeliTextureState fillTexture;
	HeliTextureState strokeTexture;
	HeliGLCommonState glState;
} HeliDrawingState;

typedef void (APIENTRY *HeliGlStencilOpSeparatePtr)(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
extern HeliGlStencilOpSeparatePtr heliGlStencilOpSeparatePtr;

HeliDrawingState *heliDrawingGetState();
HeliDrawingState *heliDrawingGetStateStack();
void heliDrawingApplyTexture(double *color, HeliTextureState *state);
void heliDrawingResetTexture();
void heliFillRectSimple(double x0, double y0, double x1, double y1, double aaBorder);
void heliFillCircleSimple(double x, double y, double r, double aaBorder);
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;
} 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 (*HeliSpriteEashUInt)(Sprite, unsigned int);
typedef void (*HeliSpriteEashDouble)(Sprite, double);
HeliArray* heliSpriteGetGroups(Sprite sprite);
void heliSpriteUpdate(double dt);
void heliSpriteFinish();


// sound

void heliSoundUpdate();
void heliSoundFinish();


// world

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;
	char newText[4096];	
} HeliDialog;

void heliDialogDraw(HeliDialog *dialog);


// test

void heliDoTests();


#endif