Format code

This commit is contained in:
2016-09-10 10:47:19 +02:00
committed by Valeriano A.R
parent 4d29388734
commit 6818acdd4e
24 changed files with 2171 additions and 2497 deletions

65
.clang-format Normal file
View File

@@ -0,0 +1,65 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: true
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
...

View File

@@ -17,139 +17,116 @@ Entity ent_Player;
Entity ent_Platform;
Entity ent_Block;
int EntityApplyGravity(Entity e){
float grav=10.0f;
float vTerminal=50.0f;
int EntityApplyGravity(Entity e) {
float grav = 10.0f;
float vTerminal = 50.0f;
vec2 vGrav;
// Only apply gravity to some entity types
if(!(
e->type==Ent_Player ||
0
))
{
return(1);
if (!(e->type == Ent_Player || 0)) {
return (1);
}
// Apply gravity
vec2_set(vGrav,0.0f,grav);
Entity_AddVelLimit(e,vGrav,vTerminal);
vec2_set(vGrav, 0.0f, grav);
Entity_AddVelLimit(e, vGrav, vTerminal);
return(1);
return (1);
}
void player_proc(Entity e, int ft) {
float acel = 8.0f;
float maxVel = 30.0f;
float jumpVel = 50.0f;
float shootVel = 50.0f;
void player_proc(Entity e,int ft){
float acel=8.0f;
float maxVel=30.0f;
float jumpVel=50.0f;
float shootVel=50.0f;
if(Input_GetKey(InputKey_Jump)==InputKey_Pressed ||
Input_GetKey(InputKey_Up)==InputKey_Pressed)
{
if (Input_GetKey(InputKey_Jump) == InputKey_Pressed ||
Input_GetKey(InputKey_Up) == InputKey_Pressed) {
vec2 jump;
// Apply jump
if(e->vel[1]>(-jumpVel)){
e->vel[1]=-jumpVel;
if (e->vel[1] > (-jumpVel)) {
e->vel[1] = -jumpVel;
}
Entity_CalcBBox(e);
// FIXME: play sound
}
if(Input_GetKey(InputKey_Left)){
if (Input_GetKey(InputKey_Left)) {
vec2 left;
// Apply left movement
vec2_set(left,-acel,0.0f);
Entity_AddVelLimit(e,left,maxVel);
vec2_set(left, -acel, 0.0f);
Entity_AddVelLimit(e, left, maxVel);
e->A=0;
e->A = 0;
}
if(Input_GetKey(InputKey_Right)){
if (Input_GetKey(InputKey_Right)) {
vec2 right;
// Apply right movement
vec2_set(right,acel,0.0f)
Entity_AddVelLimit(e,right,maxVel);
vec2_set(right, acel, 0.0f) Entity_AddVelLimit(e, right, maxVel);
e->A=1;
e->A = 1;
}
if(Input_GetKey(InputKey_Action1)==InputKey_Pressed ||
Input_GetKey(InputKey_Action2)==InputKey_Pressed)
{
if (Input_GetKey(InputKey_Action1) == InputKey_Pressed ||
Input_GetKey(InputKey_Action2) == InputKey_Pressed) {
}
// Scroll View
GameLib_MoveToPos(e->pos,0.6f);
GameLib_MoveToPos(e->pos, 0.6f);
}
void GameEnts_Init(){
void GameEnts_Init() {
/////////////////////////////
// Load and initialize media.
//
img_player=Draw_LoadImage("data/player.png");
img_platform=Draw_LoadImage("data/platform.png");
img_block=Draw_LoadImage("data/block.png");
img_player = Draw_LoadImage("data/player.png");
img_platform = Draw_LoadImage("data/platform.png");
img_block = Draw_LoadImage("data/block.png");
/////////////////////////
// Initialize entity types.
//
ent_Player=Entity_New();
ent_Player->type=Ent_Player;
//ent_Player->flags=EntityFlag_Light;
//Entity_SetLight(ent_Player,.2,.2,.2,200);
ent_Player->flags=EntityFlag_Collision|EntityFlag_Overlap;
ent_Player->zorder=0;
AnimPlay_SetImg(&ent_Player->anim,img_player);
ent_Player->proc=player_proc;
ent_Player->mass=1.0f;
ent_Player->radius=12;
ent_Player->width=24;
ent_Player->height=24;
ent_Player->fric_static=0.0f;
ent_Player->fric_dynamic=0.2f;
ent_Player = Entity_New();
ent_Player->type = Ent_Player;
// ent_Player->flags=EntityFlag_Light;
// Entity_SetLight(ent_Player,.2,.2,.2,200);
ent_Player->flags = EntityFlag_Collision | EntityFlag_Overlap;
ent_Player->zorder = 0;
AnimPlay_SetImg(&ent_Player->anim, img_player);
ent_Player->proc = player_proc;
ent_Player->mass = 1.0f;
ent_Player->radius = 12;
ent_Player->width = 24;
ent_Player->height = 24;
ent_Player->fric_static = 0.0f;
ent_Player->fric_dynamic = 0.2f;
ent_Platform=Entity_New();
ent_Platform->type=Ent_Platform;
ent_Platform->flags=EntityFlag_PlatformCollision;
ent_Platform->zorder=-1;
AnimPlay_SetImg(&ent_Platform->anim,img_platform);
ent_Platform->mass=0.0f;
ent_Platform->radius=12;
ent_Platform->width=64;
ent_Platform->height=16;
ent_Platform->fric_static=0.0f;
ent_Platform->fric_dynamic=0.2f;
ent_Block=Entity_New();
ent_Block->type=Ent_Block;
ent_Block->flags=EntityFlag_BlockCollision;
ent_Block->zorder=-1;
AnimPlay_SetImg(&ent_Block->anim,img_block);
ent_Block->mass=0.0f;
ent_Block->radius=32;
ent_Block->width=64;
ent_Block->height=64;
ent_Block->fric_static=0.0f;
ent_Block->fric_dynamic=0.2f;
ent_Platform = Entity_New();
ent_Platform->type = Ent_Platform;
ent_Platform->flags = EntityFlag_PlatformCollision;
ent_Platform->zorder = -1;
AnimPlay_SetImg(&ent_Platform->anim, img_platform);
ent_Platform->mass = 0.0f;
ent_Platform->radius = 12;
ent_Platform->width = 64;
ent_Platform->height = 16;
ent_Platform->fric_static = 0.0f;
ent_Platform->fric_dynamic = 0.2f;
ent_Block = Entity_New();
ent_Block->type = Ent_Block;
ent_Block->flags = EntityFlag_BlockCollision;
ent_Block->zorder = -1;
AnimPlay_SetImg(&ent_Block->anim, img_block);
ent_Block->mass = 0.0f;
ent_Block->radius = 32;
ent_Block->width = 64;
ent_Block->height = 64;
ent_Block->fric_static = 0.0f;
ent_Block->fric_dynamic = 0.2f;
}

View File

@@ -3,8 +3,6 @@
#ifndef _GAMEENTS_H_
#define _GAMEENTS_H_
enum {
Ent_Player,
Ent_Platform,
@@ -22,4 +20,3 @@ int EntityApplyGravity(Entity e);
void GameEnts_Init();
#endif

View File

@@ -10,119 +10,108 @@
#include "GameEnts.h"
#include "GameMap.h"
int ReadLine(FILE *f,char *line,int max){
int ReadLine(FILE *f, char *line, int max) {
int c;
int i=0;
while(i<(max-1)){
c=fgetc(f);
if(c==EOF){
line[i]=0;
return(-1);
int i = 0;
while (i < (max - 1)) {
c = fgetc(f);
if (c == EOF) {
line[i] = 0;
return (-1);
}
if(c=='\r'){
if (c == '\r') {
continue;
}
if(c=='\n'){
line[i]=0;
return(i);
if (c == '\n') {
line[i] = 0;
return (i);
}
line[i]=c;
line[i] = c;
i++;
}
line[i]=0;
return(i);
line[i] = 0;
return (i);
}
Entity GameMapAux_CreateEnt(Entity ent,int i,int j,int res){
Entity GameMapAux_CreateEnt(Entity ent, int i, int j, int res) {
Entity e;
vec2 pos;
e=Entity_Copy(ent);
vec2_set(pos,(res/2)+i*res,(res/2)+j*res);
vec2_plus(e->pos,e->pos,pos);
e = Entity_Copy(ent);
vec2_set(pos, (res / 2) + i * res, (res / 2) + j * res);
vec2_plus(e->pos, e->pos, pos);
Entity_CalcBBox(e);
GameLib_AddEntity(e);
return(e);
return (e);
}
#define MaxLineLen 1024
int GameMap_LoadLevel(char *filename,int res){
int GameMap_LoadLevel(char *filename, int res) {
FILE *file;
char line[MaxLineLen];
int len,i,j;
int width,height;
int len, i, j;
int width, height;
char *map;
// Open the file
file=fopen(filename,"rb");
if(!file){
return(0);
file = fopen(filename, "rb");
if (!file) {
return (0);
}
// Read the file to determine sizes
width=0;
height=0;
do{
len=ReadLine(file,line,MaxLineLen);
if(len>-1){
if(len>height){
height=len;
width = 0;
height = 0;
do {
len = ReadLine(file, line, MaxLineLen);
if (len > -1) {
if (len > height) {
height = len;
}
width++;
}
}while(len>-1);
fseek(file,0,SEEK_SET);
} while (len > -1);
fseek(file, 0, SEEK_SET);
// Build the map
map=malloc(sizeof(char)*width*height);
memset(map,0,width*height);
#define MAP(x,y) map[(x)+((y)*width)]
j=0;
do{
len=ReadLine(file,line,MaxLineLen);
for(i=0;i<len;i++){
MAP(j,(height-1)-i)=line[i];
map = malloc(sizeof(char) * width * height);
memset(map, 0, width * height);
#define MAP(x, y) map[(x) + ((y)*width)]
j = 0;
do {
len = ReadLine(file, line, MaxLineLen);
for (i = 0; i < len; i++) {
MAP(j, (height - 1) - i) = line[i];
}
j++;
}while(len>-1);
} while (len > -1);
// Close the file
fclose(file);
// Parse the map
for(j=0;j<height;j++){
for(i=0;i<width;i++){
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
Entity ent;
if(MAP(i,j)=='P'){
if (MAP(i, j) == 'P') {
// Player
GameMapAux_CreateEnt(ent_Player,i,j,res);
GameMapAux_CreateEnt(ent_Player, i, j, res);
}
if(MAP(i,j)=='#'){
if (MAP(i, j) == '#') {
// Block
ent=GameMapAux_CreateEnt(ent_Block,i,j,res);
ent = GameMapAux_CreateEnt(ent_Block, i, j, res);
}
if(MAP(i,j)=='|'){
if (MAP(i, j) == '|') {
// Platform
ent=GameMapAux_CreateEnt(ent_Platform,i,j,res);
}
ent = GameMapAux_CreateEnt(ent_Platform, i, j, res);
}
}
}
// Cleanup
free(map);
#undef MAP
#undef MAP
return(1);
return (1);
}

View File

@@ -2,7 +2,6 @@
#ifndef _GAMEMAP_H_
#define _GAMEMAP_H_
int GameMap_LoadLevel(char *filename,int res);
int GameMap_LoadLevel(char *filename, int res);
#endif

View File

@@ -12,66 +12,60 @@ extern int gamelib_debug;
#include "GameEnts.h"
#include "GameMap.h"
DrawFnt font;
DrawImg imgBackground;
void MainGame_Text(int x, int y, char *text){
void MainGame_Text(int x, int y, char *text) {
Draw_SetColor(0.0f, 0.0f, 0.0f, 0.5f);
Draw_DrawText(font, text, x+1, y+1);
Draw_DrawText(font, text, x + 1, y + 1);
Draw_SetColor(1.0f, 1.0f, 1.0f, 1.0f);
Draw_DrawText(font, text, x, y);
}
void ProcGame(){
}
void PostProcGame(){
void ProcGame() {}
void PostProcGame() {
// Apply gravity to every entity
GameLib_ForEachEnt(EntityApplyGravity);
}
void PreDrawGame(float f){
void PreDrawGame(float f) {}
void DrawGame(float f) { MainGame_Text(8, 8, "Hello world!"); }
}
void DrawGame(float f){
MainGame_Text(8,8,"Hello world!");
}
int main(int argc,char *argv[]){
int i,j;
int main(int argc, char *argv[]) {
int i, j;
Entity *e;
srand(time(NULL));
if (argc>1) {
if (!strcmp(argv[1],"debug")) {
gamelib_debug=1;
if (argc > 1) {
if (!strcmp(argv[1], "debug")) {
gamelib_debug = 1;
printf("Debug Mode Activated!\n");
}
}
GameLib_Init(640,480,"Game",20,60);
GameLib_Init(640, 480, "Game", 20, 60);
/////////////////////////////
// Load and initialize media.
//
font=Draw_DefaultFont(255,255,255,255);
imgBackground=Draw_LoadImage("data/background.png");
Draw_SetOffset(imgBackground,0,0);
font = Draw_DefaultFont(255, 255, 255, 255);
imgBackground = Draw_LoadImage("data/background.png");
Draw_SetOffset(imgBackground, 0, 0);
GameEnts_Init();
/////////////////////////
// Initialize world.
//
GameLib_DelEnts();
GameMap_LoadLevel("data/level_01.txt",64);
GameMap_LoadLevel("data/level_01.txt", 64);
/////////////////////////
// Run the world.
//
GameLib_CleanParallaxBackgrounds();
GameLib_AddParallaxBackground(imgBackground, (int[2]){512, 512}, (int[2]){0, 0}, (float[2]){0.5f, 0.0f});
GameLib_Loop(ProcGame,PostProcGame,PreDrawGame,DrawGame);
GameLib_AddParallaxBackground(imgBackground, (int[2]){512, 512},
(int[2]){0, 0}, (float[2]){0.5f, 0.0f});
GameLib_Loop(ProcGame, PostProcGame, PreDrawGame, DrawGame);
return(0);
return (0);
}

View File

@@ -6,7 +6,6 @@
#include "Draw.h"
#include "Anim.h"
////////////////////////////////////////////////
// Animation //
///////////////
@@ -20,242 +19,226 @@ typedef struct {
int time;
} Animation;
/////////////////////////////
// Anim_LoadAnim
//
//
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps){
Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps) {
DrawImg img;
Animation *anim;
int w,h;
int w, h;
img=Draw_LoadImage(fichero);
if(!img){
return(NULL);
img = Draw_LoadImage(fichero);
if (!img) {
return (NULL);
}
Draw_GetSize(img,&w,&h);
Draw_SetOffset(img,-(width/2),-(h/2));
Draw_GetSize(img, &w, &h);
Draw_SetOffset(img, -(width / 2), -(h / 2));
// Create the animation container
anim=malloc(sizeof(Animation));
anim->img=img;
anim->w=width;
if(width<=0){
anim->w=w/frames;
anim = malloc(sizeof(Animation));
anim->img = img;
anim->w = width;
if (width <= 0) {
anim->w = w / frames;
}
anim->fps=fps;
anim->frames=frames;
anim->ftime=1000/fps;
anim->time=anim->ftime*frames;
anim->fps = fps;
anim->frames = frames;
anim->ftime = 1000 / fps;
anim->time = anim->ftime * frames;
return((Anim)anim);
return ((Anim)anim);
}
/////////////////////////////
// Anim_GetTime
//
//
int Anim_GetTime(Anim a){
Animation *anim=a;
int Anim_GetTime(Anim a) {
Animation *anim = a;
return(anim->time);
return (anim->time);
}
/////////////////////////////
// Anim_GetSize
//
// Gets the animation size.
void Anim_GetSize(Anim a,int *w,int *h){
Animation *anim=a;
void Anim_GetSize(Anim a, int *w, int *h) {
Animation *anim = a;
int waux;
*w=anim->w;
Draw_GetSize(anim->img,&waux,h);
*w = anim->w;
Draw_GetSize(anim->img, &waux, h);
}
/////////////////////////////
// Anim_SetOffset
// Anim_GetOffset
//
//
void Anim_SetOffset(Anim a,int x,int y){
Animation *anim=a;
void Anim_SetOffset(Anim a, int x, int y) {
Animation *anim = a;
Draw_SetOffset(anim->img,x,y);
Draw_SetOffset(anim->img, x, y);
}
void Anim_GetOffset(Anim a,int *x,int *y){
Animation *anim=a;
void Anim_GetOffset(Anim a, int *x, int *y) {
Animation *anim = a;
Draw_GetOffset(anim->img,x,y);
Draw_GetOffset(anim->img, x, y);
}
/////////////////////////////
// Anim_SetFlip
// Anim_GetFlip
//
//
void Anim_SetFlip(Anim a,int flip){
Animation *anim=a;
void Anim_SetFlip(Anim a, int flip) {
Animation *anim = a;
Draw_SetFlip(anim->img,flip);
Draw_SetFlip(anim->img, flip);
}
int Anim_GetFlip(Anim a){
Animation *anim=a;
int Anim_GetFlip(Anim a) {
Animation *anim = a;
return Draw_GetFlip(anim->img);
}
/////////////////////////////
// Anim_Draw
//
//
void Anim_Draw(Anim a,int time_ms,int x,int y){
Animation *anim=a;
void Anim_Draw(Anim a, int time_ms, int x, int y) {
Animation *anim = a;
int frame;
frame=(time_ms/anim->ftime)%anim->frames;
Draw_DrawImgPartHoriz(anim->img,x,y,anim->w,frame);
frame = (time_ms / anim->ftime) % anim->frames;
Draw_DrawImgPartHoriz(anim->img, x, y, anim->w, frame);
}
/////////////////////////////
// AnimPlay_Copy
//
//
void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao){
ad->img=ao->img;
void AnimPlay_Copy(AnimPlay *ad, AnimPlay *ao) {
ad->img = ao->img;
ad->imgPart=ao->imgPart;
ad->w=ao->w;
ad->h=ao->h;
ad->i=ao->i;
ad->j=ao->j;
ad->imgPart = ao->imgPart;
ad->w = ao->w;
ad->h = ao->h;
ad->i = ao->i;
ad->j = ao->j;
ad->anim=ao->anim;
ad->time_ms=ao->time_ms;
ad->anim = ao->anim;
ad->time_ms = ao->time_ms;
}
/////////////////////////////
// AnimPlay_SetImg
// AnimPlay_SetAnim
// AnimPlay_SetImgPart
//
//
void AnimPlay_SetImg(AnimPlay *ap,DrawImg img){
ap->anim=NULL;
ap->time_ms=0;
void AnimPlay_SetImg(AnimPlay *ap, DrawImg img) {
ap->anim = NULL;
ap->time_ms = 0;
ap->img=img;
ap->img = img;
ap->imgPart=NULL;
ap->imgPart = NULL;
}
void AnimPlay_SetAnim(AnimPlay *ap,Anim ani){
ap->pause=0;
if(ap->anim==ani){
void AnimPlay_SetAnim(AnimPlay *ap, Anim ani) {
ap->pause = 0;
if (ap->anim == ani) {
return;
}
ap->anim=ani;
ap->time_ms=0;
ap->anim = ani;
ap->time_ms = 0;
ap->img=NULL;
ap->img = NULL;
ap->imgPart=NULL;
ap->imgPart = NULL;
}
void AnimPlay_SetImgPart(AnimPlay *ap,DrawImg img,int w,int h,int i,int j){
ap->anim=NULL;
ap->time_ms=0;
void AnimPlay_SetImgPart(AnimPlay *ap, DrawImg img, int w, int h, int i,
int j) {
ap->anim = NULL;
ap->time_ms = 0;
ap->img=NULL;
ap->img = NULL;
ap->imgPart=img;
ap->w=w;
ap->h=h;
ap->i=i;
ap->j=j;
ap->imgPart = img;
ap->w = w;
ap->h = h;
ap->i = i;
ap->j = j;
}
/////////////////////////////
// AnimPlay_Draw
//
//
void AnimPlay_Draw(AnimPlay *ani,int x,int y){
if(ani->anim){
Anim_Draw(ani->anim,ani->time_ms,x,y);
void AnimPlay_Draw(AnimPlay *ani, int x, int y) {
if (ani->anim) {
Anim_Draw(ani->anim, ani->time_ms, x, y);
return;
}
if(ani->img){
Draw_DrawImg(ani->img,x,y);
if (ani->img) {
Draw_DrawImg(ani->img, x, y);
return;
}
if(ani->imgPart){
Draw_DrawImgPart(ani->imgPart,x,y,ani->w,ani->h,ani->i,ani->j);
if (ani->imgPart) {
Draw_DrawImgPart(ani->imgPart, x, y, ani->w, ani->h, ani->i, ani->j);
return;
}
}
/////////////////////////////
// AnimPlay_GetOffset
// AnimPlay_GetSize
//
//
void AnimPlay_GetOffset(AnimPlay *ani,int *x,int *y){
if(ani->anim){
Anim_GetOffset(ani->anim,x,y);
void AnimPlay_GetOffset(AnimPlay *ani, int *x, int *y) {
if (ani->anim) {
Anim_GetOffset(ani->anim, x, y);
return;
}
if(ani->img){
Draw_GetOffset(ani->img,x,y);
if (ani->img) {
Draw_GetOffset(ani->img, x, y);
return;
}
if(ani->imgPart){
Draw_GetOffset(ani->imgPart,x,y);
if (ani->imgPart) {
Draw_GetOffset(ani->imgPart, x, y);
return;
}
}
void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h){
if(ani->anim){
Anim_GetSize(ani->anim,w,h);
void AnimPlay_GetSize(AnimPlay *ani, int *w, int *h) {
if (ani->anim) {
Anim_GetSize(ani->anim, w, h);
return;
}else
if(ani->img){
Draw_GetSize(ani->img,w,h);
} else if (ani->img) {
Draw_GetSize(ani->img, w, h);
return;
}
if(ani->imgPart){
Draw_GetSize(ani->imgPart,w,h);
if (ani->imgPart) {
Draw_GetSize(ani->imgPart, w, h);
return;
}
}
/////////////////////////////
// AnimPlay_SetPause
//
//
void AnimPlay_SetPause(AnimPlay *ani,int p){
ani->pause=p;
}
void AnimPlay_SetPause(AnimPlay *ani, int p) { ani->pause = p; }
/////////////////////////////
// AnimPlay_IncTime
//
//
void AnimPlay_IncTime(AnimPlay *ani,int t){
if(ani->anim){
if(!ani->pause){
ani->time_ms+=t;
void AnimPlay_IncTime(AnimPlay *ani, int t) {
if (ani->anim){
if (!ani->pause) {
ani->time_ms += t;
}
}
}

View File

@@ -5,20 +5,17 @@
#include "Draw.h"
////////////////////////////////////////////////
// Anim //
//////////
//
typedef void *Anim;
/////////////////////////////
// Anim_LoadAnim
//
//
Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps);
Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps);
/////////////////////////////
// Anim_GetTime
@@ -26,38 +23,33 @@ Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps);
//
int Anim_GetTime(Anim anim);
/////////////////////////////
// Anim_GetSize
//
// Gets the animation size.
void Anim_GetSize(Anim anim,int *w,int *h);
void Anim_GetSize(Anim anim, int *w, int *h);
/////////////////////////////
// Anim_SetOffset
// Anim_GetOffset
//
//
void Anim_SetOffset(Anim anim,int x,int y);
void Anim_GetOffset(Anim anim,int *x,int *y);
void Anim_SetOffset(Anim anim, int x, int y);
void Anim_GetOffset(Anim anim, int *x, int *y);
/////////////////////////////
// Anim_SetFlip
// Draw_GetFlip
//
//
void Anim_SetFlip(Anim anim,int flip);
void Anim_SetFlip(Anim anim, int flip);
int Anim_GetFlip(Anim anim);
/////////////////////////////
// Anim_Draw
//
//
void Anim_Draw(Anim anim,int time_ms,int x,int y);
void Anim_Draw(Anim anim, int time_ms, int x, int y);
////////////////////////////////////////////////
// AnimPlay //
@@ -71,17 +63,15 @@ typedef struct {
DrawImg img;
DrawImg imgPart;
int w,h,i,j;
int w, h, i, j;
} AnimPlay;
/////////////////////////////
// AnimPlay_Copy
//
//
void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao);
void AnimPlay_Copy(AnimPlay *ad, AnimPlay *ao);
/////////////////////////////
// AnimPlay_SetImg
@@ -89,38 +79,34 @@ void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao);
// AnimPlay_SetImgPart
//
//
void AnimPlay_SetImg(AnimPlay *ap,DrawImg img);
void AnimPlay_SetAnim(AnimPlay *ap,Anim ani);
void AnimPlay_SetImgPart(AnimPlay *ap,DrawImg img,int w,int h,int i,int j);
void AnimPlay_SetImg(AnimPlay *ap, DrawImg img);
void AnimPlay_SetAnim(AnimPlay *ap, Anim ani);
void AnimPlay_SetImgPart(AnimPlay *ap, DrawImg img, int w, int h, int i, int j);
/////////////////////////////
// AnimPlay_Draw
//
//
void AnimPlay_Draw(AnimPlay *ani,int x,int y);
void AnimPlay_Draw(AnimPlay *ani, int x, int y);
/////////////////////////////
// AnimPlay_GetOffset
// AnimPlay_GetSize
//
//
void AnimPlay_GetOffset(AnimPlay *ani,int *x,int *y);
void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h);
void AnimPlay_GetOffset(AnimPlay *ani, int *x, int *y);
void AnimPlay_GetSize(AnimPlay *ani, int *w, int *h);
/////////////////////////////
// AnimPlay_SetPause
//
//
void AnimPlay_SetPause(AnimPlay *ani,int p);
void AnimPlay_SetPause(AnimPlay *ani, int p);
/////////////////////////////
// AnimPlay_IncTime
//
//
void AnimPlay_IncTime(AnimPlay *ani,int t);
void AnimPlay_IncTime(AnimPlay *ani, int t);
#endif

View File

@@ -1,8 +1,8 @@
// Copyright (C) 2011 Valeriano Alfonso Rodriguez (Kableado)
#ifdef WIN32
#define _WIN32_WINNT 0x0501
#include <windows.h>
#define _WIN32_WINNT 0x0501
#include <windows.h>
#endif
#include <stdlib.h>
#include <stdio.h>
@@ -12,8 +12,7 @@
#include "Audio.h"
static void Audio_MixerCallback(void *ud,Uint8 *stream,int l);
static void Audio_MixerCallback(void *ud, Uint8 *stream, int l);
////////////////////////////////////////////////
// AudioWave //
@@ -30,8 +29,7 @@ struct TAudioWave {
AudioWave next;
};
AudioWave _waves=NULL;
AudioWave _waves = NULL;
////////////////////////////////////////////////
// AudioChan //
@@ -48,26 +46,26 @@ struct TAudioChan {
AudioChan next;
};
AudioChan _channels=NULL;
AudioChan _free_channels=NULL;
AudioChan _channels = NULL;
AudioChan _free_channels = NULL;
/////////////////////////////
// Audio_Init
//
// Initializes the game audio.
int Audio_Init(){
int Audio_Init() {
SDL_AudioSpec as;
SDL_AudioSpec as2;
// Initialize audio subsistem
// Initialize audio subsistem
#ifdef WIN32
// Force DSound Driver on win32
putenv("SDL_AUDIODRIVER=dsound");
#endif
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0){
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
Print("Audio_Init: Failure initializing SDL Audio.\n");
Print("\tSDL Error: %s\n",SDL_GetError());
return(0);
Print("\tSDL Error: %s\n", SDL_GetError());
return (0);
}
// Open the audio device using the desired parameters
@@ -76,155 +74,148 @@ int Audio_Init(){
as.channels = 2;
as.samples = 2048;
as.callback = Audio_MixerCallback;
if(SDL_OpenAudio(&as, &as2) < 0){
if (SDL_OpenAudio(&as, &as2) < 0) {
Print("Audio_Init: Failure opening audio.\n");
Print("\tSDL Error: %s\n",SDL_GetError());
return(0);
Print("\tSDL Error: %s\n", SDL_GetError());
return (0);
}
// Asert results
if( as2.format != AUDIO_S16SYS ||
as2.freq != 44100 ||
as2.channels != 2 )
{
if (as2.format != AUDIO_S16SYS || as2.freq != 44100 || as2.channels != 2) {
Print("Audio_Init: Failure opening audio. (44.1Khz/16b/2c).\n");
SDL_CloseAudio();
return(0);
return (0);
}
// Unpause and ready to go
SDL_PauseAudio(0);
return(1);
return (1);
}
/////////////////////////////
// Audio_MixerCallback
//
// Mixes the audio channels.
static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
signed short *ptr_out,*ptr_wave;
static void Audio_MixerCallback(void *ud, Uint8 *stream, int l) {
signed short *ptr_out, *ptr_wave;
AudioChan prevchan;
AudioChan chan;
AudioWave wave;
int len=l/4; // Asume 16bpb and 2 output chan
int len = l / 4; // Asume 16bpb and 2 output chan
int chan_remain;
int len_mix;
int i;
// Clean
memset(stream,0,l);
memset(stream, 0, l);
// Mix all the channels
prevchan=NULL;
chan=_channels;
while(chan){
if(!chan->wave){
prevchan = NULL;
chan = _channels;
while (chan) {
if (!chan->wave) {
// Remove finished channels
AudioChan aux_chan=chan->next;
chan->next=_free_channels;
_free_channels=chan;
chan=aux_chan;
if(prevchan){
prevchan->next=chan;
}else{
_channels=chan;
AudioChan aux_chan = chan->next;
chan->next = _free_channels;
_free_channels = chan;
chan = aux_chan;
if (prevchan) {
prevchan->next = chan;
} else {
_channels = chan;
}
continue;
}
// Prepare the pointers
ptr_out=(signed short *)stream;
ptr_wave=((signed short *)chan->wave->buffer)+chan->pos;
wave=chan->wave;
ptr_out = (signed short *)stream;
ptr_wave = ((signed short *)chan->wave->buffer) + chan->pos;
wave = chan->wave;
// Determine mixing lenght
chan_remain=wave->len-chan->pos;
if(chan_remain>len){
len_mix=len;
}else{
if(chan->loop){
len_mix=len;
}else{
len_mix=chan_remain;
chan_remain = wave->len - chan->pos;
if (chan_remain > len) {
len_mix = len;
} else {
if (chan->loop) {
len_mix = len;
} else {
len_mix = chan_remain;
}
chan->wave=NULL;
chan->wave = NULL;
}
// Mix the buffer
for(i=0;i<len_mix;i++){
for (i = 0; i < len_mix; i++) {
int temp;
// Left Channel
temp=ptr_out[0];
temp+=(ptr_wave[0]*chan->leftvol)>>8;
if(temp>(1<<14)){
ptr_out[0]=1<<14;
}else if(temp<-(1<<14)){
ptr_out[0]=-(1<<14);
}else{
ptr_out[0]=temp;
temp = ptr_out[0];
temp += (ptr_wave[0] * chan->leftvol) >> 8;
if (temp > (1 << 14)) {
ptr_out[0] = 1 << 14;
} else if (temp < -(1 << 14)) {
ptr_out[0] = -(1 << 14);
} else {
ptr_out[0] = temp;
}
// Right Channel
temp=ptr_out[1];
temp+=(ptr_wave[0]*chan->rightvol)>>8;
if(temp>(1<<14)){
ptr_out[1]=1<<14;
}else if(temp<-(1<<14)){
ptr_out[1]=-(1<<14);
}else{
ptr_out[1]=temp;
temp = ptr_out[1];
temp += (ptr_wave[0] * chan->rightvol) >> 8;
if (temp > (1 << 14)) {
ptr_out[1] = 1 << 14;
} else if (temp < -(1 << 14)) {
ptr_out[1] = -(1 << 14);
} else {
ptr_out[1] = temp;
}
// Next sample
ptr_out+=2;
if(ptr_wave>=(((signed short *)wave->buffer)+(wave->len-1))){
ptr_wave=((signed short *)wave->buffer);
}else{
ptr_out += 2;
if (ptr_wave >=
(((signed short *)wave->buffer) + (wave->len - 1))) {
ptr_wave = ((signed short *)wave->buffer);
} else {
ptr_wave++;
}
}
chan->pos+=len_mix;
chan->pos += len_mix;
if(chan->wave==NULL && chan->loop==1){
chan->wave=wave;
while(chan->pos>wave->len){
chan->pos-=wave->len;
if (chan->wave == NULL && chan->loop == 1) {
chan->wave = wave;
while (chan->pos > wave->len) {
chan->pos -= wave->len;
}
}
// Next channel
prevchan=chan;
chan=chan->next;
prevchan = chan;
chan = chan->next;
}
}
/////////////////////////////
// Audio_Frame
//
// Notify a frame update to the audio subsystem.
void Audio_Frame(){
}
void Audio_Frame() {}
/////////////////////////////
// Audio_LoadSound
//
// Loads a sound, giving a reference.
AudioSnd Audio_LoadSound(char *filename){
AudioSnd Audio_LoadSound(char *filename) {
FILE *f;
char id[5] = { 0, 0, 0, 0, 0 }, *sndBuffer = NULL;
char id[5] = {0, 0, 0, 0, 0}, *sndBuffer = NULL;
short formatTag, channels, bitsPerSample;
int formatLen, sampleRate, dataSize;
f = fopen(filename, "rb");
if (!f) {
Print("Audio_LoadSound: Failure opening file.\n");
return(NULL);
return (NULL);
}
// Read id "RIFF"
@@ -232,7 +223,7 @@ AudioSnd Audio_LoadSound(char *filename){
if (strcmp(id, "RIFF")) {
Print("Audio_LoadSound: File is not RIFF.\n");
fclose(f);
return(NULL);
return (NULL);
}
// File size (-"RIFF")
@@ -243,7 +234,7 @@ AudioSnd Audio_LoadSound(char *filename){
if (strcmp(id, "WAVE")) {
Print("Audio_LoadSound: File is not WAVE.\n");
fclose(f);
return(NULL);
return (NULL);
}
// Read the format
@@ -252,13 +243,13 @@ AudioSnd Audio_LoadSound(char *filename){
if (formatLen < 14) {
Print("Audio_LoadSound: File too short.\n");
fclose(f);
return (NULL );
return (NULL);
}
fread(&formatTag, 1, sizeof(short), f); // 1=PCM
if (formatTag != 1) {
Print("Audio_LoadSound: Not PCM format.\n");
fclose(f);
return (NULL );
return (NULL);
}
fread(&channels, 1, sizeof(short), f);
fread(&sampleRate, 1, sizeof(int), f);
@@ -268,34 +259,36 @@ AudioSnd Audio_LoadSound(char *filename){
fseek(f, formatLen - 14, SEEK_CUR); // Align read
// Assert sound format
if (sampleRate!=44100 || channels!=1 || bitsPerSample!=2) {
if (sampleRate != 44100 || channels != 1 || bitsPerSample != 2) {
Print("Audio_LoadSound: Format not supported: "
"sampleRate:%d; channels:%d; BPB:%d\n",
sampleRate, channels, bitsPerSample);
fclose(f);
return(NULL);
return (NULL);
}
// Skip no "data" blocks
do{
int lenRead=fread(id, 1, sizeof(char) * 4, f);
if(lenRead<4){ break; }
do {
int lenRead = fread(id, 1, sizeof(char) * 4, f);
if (lenRead < 4) {
break;
}
if (strcmp(id, "data")) {
fread(&dataSize, 1, sizeof(int), f);
fseek(f, dataSize, SEEK_CUR);
}else{
} else {
break;
}
}while(1);
} while (1);
if (strcmp(id, "data")) {
Print("Audio_LoadSound: DATA block not found\n");
fclose(f);
return (NULL );
return (NULL);
}
// Read the "data" block
fread(&dataSize, 1, sizeof(int), f);
sndBuffer = malloc(sizeof(char)*dataSize);
sndBuffer = malloc(sizeof(char) * dataSize);
fread(sndBuffer, dataSize, sizeof(char), f);
fclose(f);
@@ -304,69 +297,67 @@ AudioSnd Audio_LoadSound(char *filename){
AudioWave wave = malloc(sizeof(TAudioWave));
wave->sampleRate = sampleRate;
wave->channels = channels;
wave->buffer = (Uint8 *) sndBuffer;
wave->buffer = (Uint8 *)sndBuffer;
wave->BPB = bitsPerSample;
wave->bpb = wave->BPB * 8;
wave->len = dataSize / (wave->BPB * wave->channels);
// Take a reference
wave->next=_waves;
_waves=wave;
wave->next = _waves;
_waves = wave;
return (wave);
}
/////////////////////////////
// Audio_PlaySound
//
// Loads a sound, giving a reference.
AudioChn Audio_PlaySound(AudioSnd snd,
float leftvol, float rightvol,int loop)
{
AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol,
int loop) {
AudioChan chan;
AudioWave wave;
if(!snd){
return(NULL);
if (!snd) {
return (NULL);
}
// Cast AudioSnd to AudioWave
wave=snd;
wave = snd;
// Get a free channel
if(_free_channels){
chan=_free_channels;
_free_channels=chan->next;
chan->next=NULL;
}else{
chan=malloc(sizeof(TAudioChan));
chan->next=NULL;
if (_free_channels) {
chan = _free_channels;
_free_channels = chan->next;
chan->next = NULL;
} else {
chan = malloc(sizeof(TAudioChan));
chan->next = NULL;
}
// Initialize the channel
chan->wave=wave;
chan->pos=0;
chan->rightvol=(rightvol*255);
chan->leftvol=(leftvol*255);
chan->loop=loop;
chan->wave = wave;
chan->pos = 0;
chan->rightvol = (rightvol * 255);
chan->leftvol = (leftvol * 255);
chan->loop = loop;
// Include in sounds list
chan->next=_channels;
_channels=chan;
chan->next = _channels;
_channels = chan;
return chan;
}
/////////////////////////////
// Audio_StopChan
//
// Stops an audio chanel
void Audio_StopChan(AudioChn c){
void Audio_StopChan(AudioChn c) {
AudioChan chan;
chan=c;
if(c==NULL){return;}
chan->loop=0;
chan->wave=NULL;
chan = c;
if (c == NULL) {
return;
}
chan->loop = 0;
chan->wave = NULL;
}

View File

@@ -3,49 +3,41 @@
#ifndef _AUDIO_H_
#define _AUDIO_H_
/////////////////////////////
// Audio_Init
//
// Initializes the game audio.
int Audio_Init();
/////////////////////////////
// Audio_Frame
//
// Notify a frame update to the audio subsystem.
void Audio_Frame();
////////////////////////////////////////////////
// AudioSnd //
//////////////
// Reference to a sound.
typedef void *AudioSnd;
////////////////////////////////////////////////
// AudioChn //
//////////////
// Reference to a playing sound.
typedef void *AudioChn;
/////////////////////////////
// Audio_LoadSound
//
// Loads a sound, giving a reference.
AudioSnd Audio_LoadSound(char *filename);
/////////////////////////////
// Audio_PlaySound
//
// Loads a sound, giving a reference.
AudioChn Audio_PlaySound(AudioSnd snd,
float leftvol, float rightvol,int loop);
AudioChn Audio_PlaySound(AudioSnd snd, float leftvol, float rightvol, int loop);
/////////////////////////////
// Audio_StopChan
@@ -53,5 +45,4 @@ AudioChn Audio_PlaySound(AudioSnd snd,
// Stops an audio chanel
void Audio_StopChan(AudioChn chan);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -3,67 +3,53 @@
#ifndef _DRAW_H_
#define _DRAW_H_
/////////////////////////////
// Draw_Init
//
// Initializes the game window.
int Draw_Init(int width,int height,char *title,int pfps,int fps);
int Draw_Init(int width, int height, char *title, int pfps, int fps);
/////////////////////////////
// Draw_Clean
//
// Cleans the game window.
void Draw_Clean(
unsigned char r,
unsigned char g,
unsigned char b);
void Draw_Clean(unsigned char r, unsigned char g, unsigned char b);
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(
void (*proc)(void *data),
void (*draw)(void *data,float f),
void Draw_Loop(void (*proc)(void *data), void (*draw)(void *data, float f),
void *data);
/////////////////////////////
// Draw_BreakLoop
//
// Breaks the drawing loop
void Draw_BreakLoop();
/////////////////////////////
// Draw_OverrideExit
//
// Overrides the default exit mechanism
void Draw_OverrideExit(int override);
/////////////////////////////
// Draw_Flush
//
// Performs all the queued draw actions.
void Draw_Flush();
////////////////////////////////////////////////
// DrawImg //
/////////////
// Reference to a image.
typedef void *DrawImg;
/////////////////////////////
// Draw_CreateImage
//
DrawImg Draw_CreateImage(int w,int h);
DrawImg Draw_CreateImage(int w, int h);
/////////////////////////////
// Draw_LoadImage
@@ -71,73 +57,64 @@ DrawImg Draw_CreateImage(int w,int h);
// Loads a image, giving a reference.
DrawImg Draw_LoadImage(char *filename);
/////////////////////////////
// Draw_GetSize
//
// Gets the image size.
void Draw_GetSize(DrawImg img,int *w,int *h);
void Draw_GetSize(DrawImg img, int *w, int *h);
/////////////////////////////
// Draw_SetOffset
// Draw_GetOffset
//
// Sets and Gets the image offset.
void Draw_SetOffset(DrawImg img,int x,int y);
void Draw_GetOffset(DrawImg img,int *x,int *y);
void Draw_SetOffset(DrawImg img, int x, int y);
void Draw_GetOffset(DrawImg img, int *x, int *y);
/////////////////////////////
// Draw_SetFlip
// Draw_GetFlip
//
//
void Draw_SetFlip(DrawImg img,int flip);
void Draw_SetFlip(DrawImg img, int flip);
int Draw_GetFlip(DrawImg img);
/////////////////////////////
// Draw_DrawImg
//
// Draws an image.
void Draw_DrawImg(DrawImg img,int x,int y);
void Draw_DrawImg(DrawImg img, int x, int y);
/////////////////////////////
// Draw_DrawImgResized
//
// Draws an image, resizing.
void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h);
void Draw_DrawImgResized(DrawImg img, int x, int y, float w, float h);
/////////////////////////////
// Draw_DrawImgPart
//
// Draws an image part.
void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int h,int i,int j);
void Draw_DrawImgPart(DrawImg img, int x, int y, int w, int h, int i, int j);
/////////////////////////////
// Draw_DrawImgPartHoriz
//
// Draws an image part horizontally.
void Draw_DrawImgPartHoriz(DrawImg img,int x,int y,int w,int i);
void Draw_DrawImgPartHoriz(DrawImg img, int x, int y, int w, int i);
/////////////////////////////
// Draw_ImgParallax
//
//
void Draw_ImgParallax(DrawImg img, int imgSize[2], int imgOffset[2], float parallaxFactor[2], int gamePos[2], int gameSize[2]);
void Draw_ImgParallax(DrawImg img, int imgSize[2], int imgOffset[2],
float parallaxFactor[2], int gamePos[2], int gameSize[2]);
/////////////////////////////
// Draw_SetColor
//
//
void Draw_SetColor(float r,float g,float b,float a);
void Draw_SetColor(float r, float g, float b, float a);
////////////////////////////////////////////////
// DrawFnt //
@@ -145,31 +122,24 @@ void Draw_SetColor(float r,float g,float b,float a);
// Reference to a Font.
typedef void *DrawFnt;
/////////////////////////////
// Draw_DefaultFont
//
// Creates the default font.
DrawFnt Draw_DefaultFont(
unsigned char r,
unsigned char g,
unsigned char b,
DrawFnt Draw_DefaultFont(unsigned char r, unsigned char g, unsigned char b,
unsigned char a);
/////////////////////////////
// Draw_LoadFont
//
// Load a font from a file.
DrawFnt Draw_LoadFont(char *fichero,int min,int max);
DrawFnt Draw_LoadFont(char *fichero, int min, int max);
/////////////////////////////
// Draw_DrawText
//
// Draws text using a font
void Draw_DrawText(DrawFnt f,char *text,int x,int y);
void Draw_DrawText(DrawFnt f, char *text, int x, int y);
/////////////////////////////
// Draw_SaveScreenshoot
@@ -177,5 +147,4 @@ void Draw_DrawText(DrawFnt f,char *text,int x,int y);
//
void Draw_SaveScreenshoot(char *filename);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,6 @@
#include "Draw.h"
#include "Anim.h"
////////////////////////////////////////////////
// Entity
//
@@ -60,9 +59,9 @@ struct TEntity {
void (*oncopy)(Entity ent);
void (*oninit)(Entity ent);
void (*ondelete)(Entity ent);
void (*proc)(Entity ent,int ft);
void (*postproc)(Entity ent,int ft);
int (*collision)(Entity ent, Entity ent2, float t,vec2 n);
void (*proc)(Entity ent, int ft);
void (*postproc)(Entity ent, int ft);
int (*collision)(Entity ent, Entity ent2, float t, vec2 n);
void (*overlap)(Entity ent, Entity ent2);
int A;
@@ -71,81 +70,70 @@ struct TEntity {
int D;
Entity child;
float maxX,minX;
float maxY,minY;
float maxX, minX;
float maxY, minY;
Entity next;
};
/////////////////////////////
// Entity_New
//
Entity Entity_New();
/////////////////////////////
// Entity_Init
//
Entity Entity_Init(Entity e);
/////////////////////////////
// Entity_Destroy
//
void Entity_Destroy(Entity e);
/////////////////////////////
// Entity_Copy
//
Entity Entity_Copy(Entity e);
/////////////////////////////
// Entity_CalcBBox
//
//
void Entity_CalcBBox(Entity e);
/////////////////////////////
// Entity_BBoxIntersect
//
//
int Entity_BBoxIntersect(Entity ent1,Entity ent2);
int Entity_BBoxIntersect(Entity ent1, Entity ent2);
/////////////////////////////
// Entity_Draw
//
void Entity_Draw(Entity e,int x,int y,float f);
void Entity_Draw(Entity e, int x, int y, float f);
/////////////////////////////
// Entity_IsVisible
//
int Entity_IsVisible(Entity e,int x,int y,int w,int h);
int Entity_IsVisible(Entity e, int x, int y, int w, int h);
/////////////////////////////
// Entity_Process
//
void Entity_Process(Entity e,int ft);
void Entity_Process(Entity e, int ft);
/////////////////////////////
// Entity_PostProcess
//
void Entity_PostProcess(Entity e,int ft);
void Entity_PostProcess(Entity e, int ft);
////////////////////////////////////////////////
// CollisionInfo
//
#define CollisionResponse_Circle 1
#define CollisionResponse_Line 2
typedef struct TCollisionInfo TCollisionInfo,*CollisionInfo;
typedef struct TCollisionInfo TCollisionInfo, *CollisionInfo;
struct TCollisionInfo {
int responseType;
Entity ent1;
@@ -157,13 +145,12 @@ struct TCollisionInfo {
CollisionInfo next;
};
/////////////////////////////
// CollisionInfo_New
//
//
CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction);
CollisionInfo CollisionInfo_New(int responseType, Entity ent1, Entity ent2,
float t, vec2 n, int applyFriction);
/////////////////////////////
// CollisionInfo_Destroy
@@ -171,44 +158,38 @@ CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t
//
void CollisionInfo_Destroy(CollisionInfo *collInfoRef);
/////////////////////////////
// CollisionInfo_Add
//
//
void CollisionInfo_Add(CollisionInfo *collInfo,
int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction);
void CollisionInfo_Add(CollisionInfo *collInfo, int responseType, Entity ent1,
Entity ent2, float t, vec2 n, int applyFriction);
/////////////////////////////
// CollisionInfo_CheckRepetition
//
//
int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2);
int CollisionInfo_CheckRepetition(CollisionInfo collInfo, Entity ent1,
Entity ent2);
/////////////////////////////
// Entity_CheckCollision
//
//
int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef);
int Entity_CheckCollision(Entity ent1, Entity ent2, CollisionInfo *collInfoRef);
/////////////////////////////
// Entity_CollisionResponseClircle
//
// Normal response to a collision of spheres.
void Entity_CollisionResponseCircle(
Entity b1,Entity b2,float t,vec2 n);
void Entity_CollisionResponseCircle(Entity b1, Entity b2, float t, vec2 n);
/////////////////////////////
// Entity_CollisionResponseLine
//
// Normal response to a collision with a line.
void Entity_CollisionResponseLine(
Entity ent,Entity ent2,float t,vec2 n,int applyFriction);
void Entity_CollisionResponseLine(Entity ent, Entity ent2, float t, vec2 n,
int applyFriction);
/////////////////////////////
// Entity_CollisionInfoResponse
@@ -216,141 +197,117 @@ void Entity_CollisionResponseLine(
//
int Entity_CollisionInfoResponse(CollisionInfo collInfo);
/////////////////////////////
// Entity_Overlaps
//
void Entity_Overlaps(Entity b1,Entity b2);
void Entity_Overlaps(Entity b1, Entity b2);
/////////////////////////////
// Entity_GetPos
//
void Entity_GetPos(Entity e,vec2 pos);
void Entity_GetPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_SetPos
//
//
void Entity_SetPos(Entity e,vec2 pos);
void Entity_SetPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_AddPos
//
//
void Entity_AddPos(Entity e,vec2 pos);
void Entity_AddPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_UpdatePos
//
void Entity_UpdatePos(Entity e,vec2 pos);
void Entity_UpdatePos(Entity e, vec2 pos);
/////////////////////////////
// Entity_AddVel
//
void Entity_AddVel(Entity e,vec2 vel);
void Entity_AddVel(Entity e, vec2 vel);
/////////////////////////////
// Entity_SetVel
//
void Entity_SetVel(Entity e,vec2 vel);
void Entity_SetVel(Entity e, vec2 vel);
/////////////////////////////
// Entity_SetVelH
//
void Entity_SetVelH(Entity e,float v);
void Entity_SetVelH(Entity e, float v);
/////////////////////////////
// Entity_SetVelV
//
void Entity_SetVelV(Entity e,float v);
void Entity_SetVelV(Entity e, float v);
/////////////////////////////
// Entity_AddVelLimit
//
void Entity_AddVelLimit(Entity e,vec2 vel,float limit);
void Entity_AddVelLimit(Entity e, vec2 vel, float limit);
/////////////////////////////
// Entity_AddVelLimitH
//
void Entity_AddVelLimitH(Entity e,float v,float limit);
void Entity_AddVelLimitH(Entity e, float v, float limit);
/////////////////////////////
// Entity_AddVelLimitH
//
void Entity_AddVelLimitV(Entity e,float v,float limit);
void Entity_AddVelLimitV(Entity e, float v, float limit);
/////////////////////////////
// Entity_SetColor
//
void Entity_SetColor(Entity e,float r,float g,float b,float a);
void Entity_SetColor(Entity e, float r, float g, float b, float a);
/////////////////////////////
// Entity_AddColor
//
void Entity_AddColor(Entity e,float r,float g,float b,float a);
void Entity_AddColor(Entity e, float r, float g, float b, float a);
/////////////////////////////
// Entity_MultColor
//
//
void Entity_MultColor(Entity e,float r,float g,float b,float a);
void Entity_MultColor(Entity e, float r, float g, float b, float a);
/////////////////////////////
// Entity_AddColor
//
void Entity_SetLight(Entity e,float r,float g,float b,float rad);
void Entity_SetLight(Entity e, float r, float g, float b, float rad);
/////////////////////////////
// Entity_SetDefaultColor
//
void Entity_SetDefaultColor(Entity e,float r,float g,float b,float a);
void Entity_SetDefaultColor(Entity e, float r, float g, float b, float a);
/////////////////////////////
// Entity_Iluminate
//
void Entity_Iluminate(Entity e,Entity *elist,int n);
void Entity_Iluminate(Entity e, Entity *elist, int n);
/////////////////////////////
// Entity_MarkUpdateLight
//
void Entity_MarkUpdateLight(Entity e,Entity *elist,int n);
void Entity_MarkUpdateLight(Entity e, Entity *elist, int n);
/////////////////////////////
// Entity_IsLight
//
int Entity_IsLight(Entity e);
/////////////////////////////
// Entity_IsUpdateLight
//
int Entity_IsUpdateLight(Entity e);
/////////////////////////////
// Entity_IsMoving
//
int Entity_IsMoving(Entity e);
#endif

View File

@@ -17,16 +17,16 @@
#include "GameLib.h"
// Globals
Entity *_entity=NULL;
int *_entity_flag=NULL;
int _n_entities=0;
int _n_entities_res=0;
int _entities_lock=0;
int _entities_compactate=0;
void (*_gameproc)()=NULL;
void (*_gamepostproc)()=NULL;
void (*_gamepredraw)(float f)=NULL;
void (*_gamedraw)(float f)=NULL;
Entity *_entity = NULL;
int *_entity_flag = NULL;
int _n_entities = 0;
int _n_entities_res = 0;
int _entities_lock = 0;
int _entities_compactate = 0;
void (*_gameproc)() = NULL;
void (*_gamepostproc)() = NULL;
void (*_gamepredraw)(float f) = NULL;
void (*_gamedraw)(float f) = NULL;
int _pft;
int _game_size[2];
int _game_pos0[2];
@@ -49,421 +49,400 @@ struct TParallaxBackground {
};
#define MaxParallaxBackgrounds 10
TParallaxBackground _parallaxBackground[MaxParallaxBackgrounds];
int _nParallaxBackgrounds=0;
int gamelib_debug=0;
int _nParallaxBackgrounds = 0;
int gamelib_debug = 0;
/////////////////////////////
// GameLib_Init
//
// Initializes the game.
int GameLib_Init(int w,int h,char *title,int pfps,int fps){
if(!Draw_Init(w,h,title,pfps,fps)){
return(0);
int GameLib_Init(int w, int h, char *title, int pfps, int fps) {
if (!Draw_Init(w, h, title, pfps, fps)) {
return (0);
}
if(!Input_Init()){
return(0);
if (!Input_Init()) {
return (0);
}
Audio_Init();
_game_size[0]=w;
_game_size[1]=h;
_game_pos0[0]=0;
_game_pos0[1]=0;
_game_pos1[0]=0;
_game_pos1[1]=0;
_game_size[0] = w;
_game_size[1] = h;
_game_pos0[0] = 0;
_game_pos0[1] = 0;
_game_pos1[0] = 0;
_game_pos1[1] = 0;
_pft=1000/pfps;
_pft = 1000 / pfps;
return(1);
return (1);
}
/////////////////////////////
// GameLib_AddEntity
//
// Adds an entity to the game.
void GameLib_AddEntity(Entity e){
if(_n_entities>=_n_entities_res){
void GameLib_AddEntity(Entity e) {
if (_n_entities >= _n_entities_res) {
Entity *entity_aux;
int *entity_flag_aux;
int i;
// Grow the array
if(_n_entities_res==0)
_n_entities_res=32;
if (_n_entities_res == 0)
_n_entities_res = 32;
else
_n_entities_res*=2;
entity_aux=malloc(sizeof(Entity)*_n_entities_res);
entity_flag_aux=malloc(sizeof(int)*_n_entities_res);
for(i=0;i<_n_entities;i++){
entity_aux[i]=_entity[i];
entity_flag_aux[i]=_entity_flag[i];
_n_entities_res *= 2;
entity_aux = malloc(sizeof(Entity) * _n_entities_res);
entity_flag_aux = malloc(sizeof(int) * _n_entities_res);
for (i = 0; i < _n_entities; i++) {
entity_aux[i] = _entity[i];
entity_flag_aux[i] = _entity_flag[i];
}
if(_entity){
if (_entity) {
free(_entity);
free(_entity_flag);
}
_entity=entity_aux;
_entity_flag=entity_flag_aux;
_entity = entity_aux;
_entity_flag = entity_flag_aux;
}
// Add the entity
_entity[_n_entities]=e;
_entity_flag[_n_entities]=1;
_entity[_n_entities] = e;
_entity_flag[_n_entities] = 1;
_n_entities++;
// Mark for light update
Entity_MarkUpdateLight(e,_entity,_n_entities);
Entity_MarkUpdateLight(e, _entity, _n_entities);
Entity_CalcBBox(e);
Entity_Init(e);
}
/////////////////////////////
// GameLib_UnrefEntity
//
// removes the reference to the entity.
int GameLib_UnrefEntity(Entity e){
int GameLib_UnrefEntity(Entity e) {
int i;
for(i=0;i<_n_entities;i++){
if(e==_entity[i]){
for (i = 0; i < _n_entities; i++) {
if (e == _entity[i]) {
// Mark or unref
if(_entities_lock){
_entity_flag[i]=-2;
}else{
_entity[i]=NULL;
_entity_flag[i]=0;
if (_entities_lock) {
_entity_flag[i] = -2;
} else {
_entity[i] = NULL;
_entity_flag[i] = 0;
}
_entities_compactate=1;
_entities_compactate = 1;
// Mark for light update
Entity_MarkUpdateLight(e,_entity,_n_entities);
return(i);
Entity_MarkUpdateLight(e, _entity, _n_entities);
return (i);
}
}
return(-1);
return (-1);
}
/////////////////////////////
// GameLib_DelEntity
//
// Adds an entity to the game.
int GameLib_DelEntity(Entity e){
int GameLib_DelEntity(Entity e) {
int i;
if((i=GameLib_UnrefEntity(e))==-1){
return(0);
if ((i = GameLib_UnrefEntity(e)) == -1) {
return (0);
}
if(_entities_lock){
if (_entities_lock) {
// Delete latter
_entity[i]=e;
_entity_flag[i]=-1;
}else{
_entity[i] = e;
_entity_flag[i] = -1;
} else {
// Delete now
Entity_Destroy(e);
}
return(1);
return (1);
}
/////////////////////////////
// GameLib_Compactate
//
//
void GameLib_Compactate(){
int i,j;
j=0;
if(!_entities_compactate)
void GameLib_Compactate() {
int i, j;
j = 0;
if (!_entities_compactate)
return;
for(i=0;i<_n_entities;i++){
if(!_entity[i] || _entity_flag[i]==-2)
for (i = 0; i < _n_entities; i++) {
if (!_entity[i] || _entity_flag[i] == -2)
continue;
if(_entity_flag[i]==-1){
if (_entity_flag[i] == -1) {
Entity_Destroy(_entity[i]);
continue;
}
if(i>j){
_entity[j]=_entity[i];
_entity_flag[j]=_entity_flag[i];
if (i > j) {
_entity[j] = _entity[i];
_entity_flag[j] = _entity_flag[i];
}
j++;
}
_n_entities=j;
_entities_compactate=0;
_n_entities = j;
_entities_compactate = 0;
}
/////////////////////////////
// GameLib_ProcLoop
//
// Process the loop.
void GameLib_ProcLoop(void *data){
int i,j;
int repeat,count;
void GameLib_ProcLoop(void *data) {
int i, j;
int repeat, count;
long long time;
// Step the gamePosition
_game_pos0[0]=_game_pos1[0];
_game_pos0[1]=_game_pos1[1];
_game_pos0[0] = _game_pos1[0];
_game_pos0[1] = _game_pos1[1];
// Process
time=Time_GetTime();
_entities_lock=1;
if(_gameproc){
time = Time_GetTime();
_entities_lock = 1;
if (_gameproc) {
_gameproc();
}
for(i=0;i<_n_entities;i++){
if(!_entity[i])
for (i = 0; i < _n_entities; i++) {
if (!_entity[i])
continue;
Entity_Process(_entity[i],_pft);
Entity_Process(_entity[i], _pft);
}
GameLib_Compactate();
_entities_lock=0;
t_proc+=Time_GetTime()-time;
_entities_lock = 0;
t_proc += Time_GetTime() - time;
// Colisions between entities
time=Time_GetTime();
_entities_lock=1;
count=0;
do{
repeat=0;
CollisionInfo collInfo=NULL;
for(i=0;i<_n_entities;i++){
if(!(_entity[i]->flags&EntityFlag_Collision) || _entity[i]->mass<0.0f)
time = Time_GetTime();
_entities_lock = 1;
count = 0;
do {
repeat = 0;
CollisionInfo collInfo = NULL;
for (i = 0; i < _n_entities; i++) {
if (!(_entity[i]->flags & EntityFlag_Collision) ||
_entity[i]->mass < 0.0f)
continue;
if(_entity[i]->vel[0]<=0.0f && _entity[i]->vel[0]>=-0.0f &&
_entity[i]->vel[1]<=0.0f && _entity[i]->vel[1]>=-0.0f)
{
if (_entity[i]->vel[0] <= 0.0f && _entity[i]->vel[0] >= -0.0f &&
_entity[i]->vel[1] <= 0.0f && _entity[i]->vel[1] >= -0.0f) {
continue;
}
for(j=0;j<_n_entities;j++){
if( i==j ||
!(_entity[j]->flags&EntityFlag_Collision) ||
CollisionInfo_CheckRepetition(collInfo,_entity[i],_entity[j]) ||
!Entity_BBoxIntersect(_entity[i],_entity[j]))
{
for (j = 0; j < _n_entities; j++) {
if (i == j || !(_entity[j]->flags & EntityFlag_Collision) ||
CollisionInfo_CheckRepetition(collInfo, _entity[i],
_entity[j]) ||
!Entity_BBoxIntersect(_entity[i], _entity[j])) {
continue;
}
Entity_CheckCollision(_entity[i],_entity[j],&collInfo);
Entity_CheckCollision(_entity[i], _entity[j], &collInfo);
}
}
if(Entity_CollisionInfoResponse(collInfo)){
repeat=1;
if (Entity_CollisionInfoResponse(collInfo)) {
repeat = 1;
}
CollisionInfo_Destroy(&collInfo);
count++;
}while(repeat && count<50);
} while (repeat && count < 50);
// Stop remaining collisions
if(count==10){
for(i=0;i<_n_entities;i++){
if(!(_entity[i]->flags&EntityFlag_Collision) || _entity[i]->mass<0.0f)
if (count == 10) {
for (i = 0; i < _n_entities; i++) {
if (!(_entity[i]->flags & EntityFlag_Collision) ||
_entity[i]->mass < 0.0f)
continue;
for(j=0;j<_n_entities;j++){
if(i==j ||
!(_entity[j]->flags&EntityFlag_Collision) ||
!Entity_BBoxIntersect(_entity[i],_entity[j]))
{
for (j = 0; j < _n_entities; j++) {
if (i == j || !(_entity[j]->flags & EntityFlag_Collision) ||
!Entity_BBoxIntersect(_entity[i], _entity[j])) {
continue;
}
if(Entity_CheckCollision(_entity[i],_entity[j],NULL)){
vec2_set(_entity[i]->vel,0,0);
if (Entity_CheckCollision(_entity[i], _entity[j], NULL)) {
vec2_set(_entity[i]->vel, 0, 0);
Entity_CalcBBox(_entity[i]);
vec2_set(_entity[j]->vel,0,0);
vec2_set(_entity[j]->vel, 0, 0);
Entity_CalcBBox(_entity[j]);
}
}
}
}
GameLib_Compactate();
_entities_lock=0;
t_col+=Time_GetTime()-time;
_entities_lock = 0;
t_col += Time_GetTime() - time;
// Process Overlaps
time=Time_GetTime();
_entities_lock=1;
for(i=0;i<_n_entities;i++){
if(!(_entity[i]->flags&EntityFlag_Overlap) || _entity[i]->mass<0.0f)
time = Time_GetTime();
_entities_lock = 1;
for (i = 0; i < _n_entities; i++) {
if (!(_entity[i]->flags & EntityFlag_Overlap) ||
_entity[i]->mass < 0.0f)
continue;
for(j=0;j<_n_entities;j++){
if(!(_entity[j]->flags&EntityFlag_Overlap) || i==j)
for (j = 0; j < _n_entities; j++) {
if (!(_entity[j]->flags & EntityFlag_Overlap) || i == j)
continue;
Entity_Overlaps(_entity[i],_entity[j]);
Entity_Overlaps(_entity[i], _entity[j]);
}
}
GameLib_Compactate();
_entities_lock=0;
t_over+=Time_GetTime()-time;
_entities_lock = 0;
t_over += Time_GetTime() - time;
// Sort
int n,n2,swap;
n=_n_entities;
do{
n2=0;
for(i=1;i<n;i++){
Entity ent1=_entity[i-1];
Entity ent2=_entity[i];
swap=0;
if(ent1->zorder > ent2->zorder){
int n, n2, swap;
n = _n_entities;
do {
n2 = 0;
for (i = 1; i < n; i++) {
Entity ent1 = _entity[i - 1];
Entity ent2 = _entity[i];
swap = 0;
if (ent1->zorder > ent2->zorder) {
// Lower level
swap=1;
}else
if(ent1->zorder < ent2->zorder){
swap = 1;
} else if (ent1->zorder < ent2->zorder) {
// Upper level
}else{
} else {
// Same level
float y1=ent1->pos[1]+ent1->sortYOffset;
float y2=ent2->pos[1]+ent2->sortYOffset;
if(y1 > y2){
swap=1;
float y1 = ent1->pos[1] + ent1->sortYOffset;
float y2 = ent2->pos[1] + ent2->sortYOffset;
if (y1 > y2) {
swap = 1;
}
}
if(swap){
if (swap) {
Entity ent;
ent=_entity[i];
_entity[i]=_entity[i-1];
_entity[i-1]=ent;
n2=i;
ent = _entity[i];
_entity[i] = _entity[i - 1];
_entity[i - 1] = ent;
n2 = i;
}
}
n=n2;
}while(n>0);
n = n2;
} while (n > 0);
// PostProcess
time=Time_GetTime();
_entities_lock=1;
for(i=0;i<_n_entities;i++){
Entity_PostProcess(_entity[i],_pft);
if(Entity_IsMoving(_entity[i])){
Entity_MarkUpdateLight(_entity[i],_entity,_n_entities);
time = Time_GetTime();
_entities_lock = 1;
for (i = 0; i < _n_entities; i++) {
Entity_PostProcess(_entity[i], _pft);
if (Entity_IsMoving(_entity[i])) {
Entity_MarkUpdateLight(_entity[i], _entity, _n_entities);
}
}
if(_gamepostproc){
if (_gamepostproc) {
_gamepostproc();
}
GameLib_Compactate();
_entities_lock=0;
t_postproc+=Time_GetTime()-time;
_entities_lock = 0;
t_postproc += Time_GetTime() - time;
fproc_count++;
}
/////////////////////////////
// GameLib_DrawLoop
//
//
void GameLib_DrawLoop(void *data, float f){
void GameLib_DrawLoop(void *data, float f) {
long long time;
int i;
int game_pos[2];
GameLib_GetPosInstant(game_pos,f);
GameLib_GetPosInstant(game_pos, f);
time=Time_GetTime();
time = Time_GetTime();
// PreDraw
if(_gamepredraw){
if (_gamepredraw) {
_gamepredraw(f);
}else{
if(_nParallaxBackgrounds==0){
} else {
if (_nParallaxBackgrounds == 0) {
// Clean screen
Draw_Clean(0,0,0);
Draw_Clean(0, 0, 0);
}
}
// Draw parallax backgrounds
for(i=0;i<_nParallaxBackgrounds;i++){
for (i = 0; i < _nParallaxBackgrounds; i++) {
Draw_ImgParallax(
_parallaxBackground[i].img,
_parallaxBackground[i].imgSize,
_parallaxBackground[i].img, _parallaxBackground[i].imgSize,
_parallaxBackground[i].imgOffset,
_parallaxBackground[i].parallaxFactor,
game_pos,
_game_size);
_parallaxBackground[i].parallaxFactor, game_pos, _game_size);
}
// Draw entities
GameLib_Compactate();
for(i=0;i<_n_entities;i++){
Entity e=_entity[i];
for (i = 0; i < _n_entities; i++) {
Entity e = _entity[i];
// Check visivility
if(!Entity_IsVisible(e,
game_pos[0],game_pos[1],
_game_size[0],_game_size[1]))
{
if (!Entity_IsVisible(e, game_pos[0], game_pos[1], _game_size[0],
_game_size[1])) {
continue;
}
// Update ilumination of this entity
if(Entity_IsUpdateLight(e)){
Entity_Iluminate(e,_entity,_n_entities);
if (Entity_IsUpdateLight(e)) {
Entity_Iluminate(e, _entity, _n_entities);
}
Entity_Draw(e,-game_pos[0],-game_pos[1],f);
Entity_Draw(e, -game_pos[0], -game_pos[1], f);
}
Draw_SetColor(1,1,1,1);
_entities_lock=1;
if(_gamedraw){
Draw_SetColor(1, 1, 1, 1);
_entities_lock = 1;
if (_gamedraw) {
_gamedraw(f);
}
GameLib_Compactate();
_entities_lock=0;
_entities_lock = 0;
t_draw+=Time_GetTime()-time;
t_draw += Time_GetTime() - time;
fdraw_count++;
if(Input_GetKey(InputKey_DumpProfiling)==InputKey_Pressed &&
fproc_count>0 && fdraw_count>0)
{
if (Input_GetKey(InputKey_DumpProfiling) == InputKey_Pressed &&
fproc_count > 0 && fdraw_count > 0) {
Print("Profiling:::::::::\n");
Print("t_proc.....:%6lld\n",t_proc/fproc_count);
Print("t_col......:%6lld\n",t_col/fproc_count);
Print("t_over.....:%6lld\n",t_over/fproc_count);
Print("t_postproc.:%6lld\n",t_postproc/fproc_count);
Print("t_draw.....:%6lld\n",t_draw/fdraw_count);
t_proc=0;
t_col=0;
t_over=0;
t_postproc=0;
t_draw=0;
fproc_count=0;
fdraw_count=0;
Print("t_proc.....:%6lld\n", t_proc / fproc_count);
Print("t_col......:%6lld\n", t_col / fproc_count);
Print("t_over.....:%6lld\n", t_over / fproc_count);
Print("t_postproc.:%6lld\n", t_postproc / fproc_count);
Print("t_draw.....:%6lld\n", t_draw / fdraw_count);
t_proc = 0;
t_col = 0;
t_over = 0;
t_postproc = 0;
t_draw = 0;
fproc_count = 0;
fdraw_count = 0;
}
}
/////////////////////////////
// GameLib_Loop
//
// Loops the game.
void GameLib_Loop(
void (*gameproc)(),
void (*gamepostproc)(),
void (*gamepredraw)(float f),
void (*gamedraw)(float f))
{
_gameproc=gameproc;
_gamepostproc=gamepostproc;
_gamepredraw=gamepredraw;
_gamedraw=gamedraw;
t_proc=0;
t_col=0;
t_over=0;
t_postproc=0;
t_draw=0;
fproc_count=0;
fdraw_count=0;
Draw_Loop(GameLib_ProcLoop,GameLib_DrawLoop,NULL);
void GameLib_Loop(void (*gameproc)(), void (*gamepostproc)(),
void (*gamepredraw)(float f), void (*gamedraw)(float f)) {
_gameproc = gameproc;
_gamepostproc = gamepostproc;
_gamepredraw = gamepredraw;
_gamedraw = gamedraw;
t_proc = 0;
t_col = 0;
t_over = 0;
t_postproc = 0;
t_draw = 0;
fproc_count = 0;
fdraw_count = 0;
Draw_Loop(GameLib_ProcLoop, GameLib_DrawLoop, NULL);
}
/////////////////////////////
// GameLib_GetPos
// GameLib_SetPos
@@ -472,248 +451,230 @@ void GameLib_Loop(
// GameLib_GetPosInstant
//
//
void GameLib_GetPos(int pos[2]){
pos[0]=_game_pos1[0];
pos[1]=_game_pos1[1];
void GameLib_GetPos(int pos[2]) {
pos[0] = _game_pos1[0];
pos[1] = _game_pos1[1];
}
void GameLib_SetPos(int pos[2]){
_game_pos0[0]=pos[0];
_game_pos0[1]=pos[1];
_game_pos1[0]=pos[0];
_game_pos1[1]=pos[1];
void GameLib_SetPos(int pos[2]) {
_game_pos0[0] = pos[0];
_game_pos0[1] = pos[1];
_game_pos1[0] = pos[0];
_game_pos1[1] = pos[1];
}
void GameLib_UpdatePos(int pos[2]){
_game_pos1[0]=pos[0];
_game_pos1[1]=pos[1];
void GameLib_UpdatePos(int pos[2]) {
_game_pos1[0] = pos[0];
_game_pos1[1] = pos[1];
}
void GameLib_GetSize(int size[2]){
size[0]=_game_size[0];
size[1]=_game_size[1];
void GameLib_GetSize(int size[2]) {
size[0] = _game_size[0];
size[1] = _game_size[1];
}
void GameLib_GetPosInstant(int pos[2],float f){
pos[0]=_game_pos0[0]+f*(_game_pos1[0]-_game_pos0[0]);
pos[1]=_game_pos0[1]+f*(_game_pos1[1]-_game_pos0[1]);
void GameLib_GetPosInstant(int pos[2], float f) {
pos[0] = _game_pos0[0] + f * (_game_pos1[0] - _game_pos0[0]);
pos[1] = _game_pos0[1] + f * (_game_pos1[1] - _game_pos0[1]);
}
/////////////////////////////
// GameLib_MoveToPos
// GameLib_MoveToPosH
// GameLib_MoveToPosV
//
//
void GameLib_MoveToPos(vec2 pos,float f){
GameLib_MoveToPosH(pos,f);
GameLib_MoveToPosV(pos,f);
void GameLib_MoveToPos(vec2 pos, float f) {
GameLib_MoveToPosH(pos, f);
GameLib_MoveToPosV(pos, f);
}
void GameLib_MoveToPosH(vec2 pos,float f){
_game_pos1[0]=_game_pos1[0]+(pos[0]-(_game_pos1[0]+(_game_size[0]/2.0f)))*f;
void GameLib_MoveToPosH(vec2 pos, float f) {
_game_pos1[0] =
_game_pos1[0] + (pos[0] - (_game_pos1[0] + (_game_size[0] / 2.0f))) * f;
}
void GameLib_MoveToPosV(vec2 pos,float f){
_game_pos1[1]=_game_pos1[1]+(pos[1]-(_game_pos1[1]+(_game_size[1]/2.0f)))*f;
void GameLib_MoveToPosV(vec2 pos, float f) {
_game_pos1[1] =
_game_pos1[1] + (pos[1] - (_game_pos1[1] + (_game_size[1] / 2.0f))) * f;
}
/////////////////////////////
// GameLib_ForEachEn
//
// Deletes every entity.
void GameLib_DelEnts(){
void GameLib_DelEnts() {
int i;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
for (i = 0; i < _n_entities; i++) {
if (!_entity[i])
continue;
Entity_Destroy(_entity[i]);
}
_n_entities=0;
_n_entities = 0;
}
/////////////////////////////
// GameLib_ForEachEn
//
// Iterates every entity.
void GameLib_ForEachEnt(int (*func)(Entity ent)){
void GameLib_ForEachEnt(int (*func)(Entity ent)) {
int i;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
for (i = 0; i < _n_entities; i++) {
if (!_entity[i])
continue;
if(!func(_entity[i])){
if (!func(_entity[i])) {
break;
}
}
}
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d){
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d) {
int i;
Entity ent=NULL;
for(i=0;i<_n_entities;i++){
if(!_entity[i])
Entity ent = NULL;
for (i = 0; i < _n_entities; i++) {
if (!_entity[i])
continue;
if(func(_entity[i],d)){
ent=_entity[i];
if (func(_entity[i], d)) {
ent = _entity[i];
break;
}
}
return ent;
}
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//
//
int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel){
int collision=0;
CollisionInfo collInfo=NULL;
int GameLib_EntityCustomCheckCollision(Entity ent, vec2 vel) {
int collision = 0;
CollisionInfo collInfo = NULL;
vec2 originalVel;
int j;
vec2_copy(originalVel,ent->vel);
vec2_copy(ent->vel,vel);
vec2_copy(originalVel, ent->vel);
vec2_copy(ent->vel, vel);
Entity_CalcBBox(ent);
for(j=0;j<_n_entities;j++){
if(!(_entity[j]->flags&EntityFlag_Collision) ||
!Entity_BBoxIntersect(ent,_entity[j]))
{
for (j = 0; j < _n_entities; j++) {
if (!(_entity[j]->flags & EntityFlag_Collision) ||
!Entity_BBoxIntersect(ent, _entity[j])) {
continue;
}
Entity_CheckCollision(ent,_entity[j],&collInfo);
if(collInfo!=NULL){
collision=1;
Entity_CheckCollision(ent, _entity[j], &collInfo);
if (collInfo != NULL) {
collision = 1;
break;
}
}
vec2_copy(ent->vel,originalVel);
vec2_copy(ent->vel, originalVel);
Entity_CalcBBox(ent);
CollisionInfo_Destroy(&collInfo);
return collision;
}
/////////////////////////////
// GameLib_PlaySound
//
//
void GameLib_PlaySound(AudioSnd snd,int x,int y){
float vleft,vright,dx,dy;
int r,cx,cy,off;
void GameLib_PlaySound(AudioSnd snd, int x, int y) {
float vleft, vright, dx, dy;
int r, cx, cy, off;
// Get the screen context
cx=_game_pos1[0]+_game_size[0]/2;
cy=_game_pos1[1]+_game_size[1]/2;
if(_game_size[0]>_game_size[1]){
r=_game_size[0]/2;
}else{
r=_game_size[1]/2;
cx = _game_pos1[0] + _game_size[0] / 2;
cy = _game_pos1[1] + _game_size[1] / 2;
if (_game_size[0] > _game_size[1]) {
r = _game_size[0] / 2;
} else {
r = _game_size[1] / 2;
}
r=r*1.2f;
off=r/10.0f;
r = r * 1.2f;
off = r / 10.0f;
// Calculate volumes
dx=x-(cx+off);
dy=y-(cy);
vright=1.0f-(sqrtf(dx*dx+dy*dy)/(float)r);
dx=x-(cx-off);
dy=y-(cy);
vleft=1.0f-(sqrtf(dx*dx+dy*dy)/(float)r);
dx = x - (cx + off);
dy = y - (cy);
vright = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
dx = x - (cx - off);
dy = y - (cy);
vleft = 1.0f - (sqrtf(dx * dx + dy * dy) / (float)r);
// Clamp to 0
if(vleft<0.0f)
vleft=0.0f;
if(vright<0.0f)
vright=0.0f;
if(vleft<=0.0f && vright<=0.0f){
if (vleft < 0.0f)
vleft = 0.0f;
if (vright < 0.0f)
vright = 0.0f;
if (vleft <= 0.0f && vright <= 0.0f) {
return;
}
// PLAY!
Audio_PlaySound(snd,vleft,vright,0);
Audio_PlaySound(snd, vleft, vright, 0);
}
/////////////////////////////
// GameLib_PlayLoopingSound
//
//
AudioChn GameLib_PlayLoopingSound(AudioSnd snd){
AudioChn GameLib_PlayLoopingSound(AudioSnd snd) {
// PLAY!
return Audio_PlaySound(snd,1.0f,1.0f,1);
return Audio_PlaySound(snd, 1.0f, 1.0f, 1);
}
/////////////////////////////
// GameLib_EntitySetLight
//
//
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad){
if(Entity_IsLight(e)){
Entity_MarkUpdateLight(e,_entity,_n_entities);
Entity_SetLight(e,r,g,b,rad);
Entity_MarkUpdateLight(e,_entity,_n_entities);
}else{
Entity_SetLight(e,r,g,b,rad);
void GameLib_EntitySetLight(Entity e, float r, float g, float b, float rad) {
if (Entity_IsLight(e)) {
Entity_MarkUpdateLight(e, _entity, _n_entities);
Entity_SetLight(e, r, g, b, rad);
Entity_MarkUpdateLight(e, _entity, _n_entities);
} else {
Entity_SetLight(e, r, g, b, rad);
}
}
/////////////////////////////
// GameLib_ConvertScreenPositionToGamePosition
//
//
void GameLib_ConvertScreenPositionToGamePosition(
vec2 screenPos, vec2 gamePos)
{
void GameLib_ConvertScreenPositionToGamePosition(vec2 screenPos, vec2 gamePos) {
float f;
int game_pos[2];
game_pos[0]=_game_pos0[0]+f*(_game_pos1[0]-_game_pos0[0]);
game_pos[1]=_game_pos0[1]+f*(_game_pos1[1]-_game_pos0[1]);
game_pos[0] = _game_pos0[0] + f * (_game_pos1[0] - _game_pos0[0]);
game_pos[1] = _game_pos0[1] + f * (_game_pos1[1] - _game_pos0[1]);
gamePos[0]=(screenPos[0]*_game_size[0])+game_pos[0];
gamePos[1]=(screenPos[1]*_game_size[1])+game_pos[1];
gamePos[0] = (screenPos[0] * _game_size[0]) + game_pos[0];
gamePos[1] = (screenPos[1] * _game_size[1]) + game_pos[1];
}
/////////////////////////////
// GameLib_AddParallaxBackground
//
//
void GameLib_AddParallaxBackground(DrawImg img, int imgSize[2], int imgOffset[2], float parallaxFactor[2]){
void GameLib_AddParallaxBackground(DrawImg img, int imgSize[2],
int imgOffset[2], float parallaxFactor[2]) {
int idx = _nParallaxBackgrounds;
if((idx+1)>=MaxParallaxBackgrounds){
if ((idx + 1) >= MaxParallaxBackgrounds) {
Print("GameLib: Can't add parallaxBackground, limit reached.");
return;
}
_parallaxBackground[idx].img=img;
_parallaxBackground[idx].imgSize[0]=imgSize[0];
_parallaxBackground[idx].imgSize[1]=imgSize[1];
_parallaxBackground[idx].imgOffset[0]=imgOffset[0];
_parallaxBackground[idx].imgOffset[1]=imgOffset[1];
_parallaxBackground[idx].parallaxFactor[0]=parallaxFactor[0];
_parallaxBackground[idx].parallaxFactor[1]=parallaxFactor[1];
_parallaxBackground[idx].img = img;
_parallaxBackground[idx].imgSize[0] = imgSize[0];
_parallaxBackground[idx].imgSize[1] = imgSize[1];
_parallaxBackground[idx].imgOffset[0] = imgOffset[0];
_parallaxBackground[idx].imgOffset[1] = imgOffset[1];
_parallaxBackground[idx].parallaxFactor[0] = parallaxFactor[0];
_parallaxBackground[idx].parallaxFactor[1] = parallaxFactor[1];
_nParallaxBackgrounds++;
}
/////////////////////////////
// GameLib_CleanParallaxBackgrounds
//
//
void GameLib_CleanParallaxBackgrounds(){
_nParallaxBackgrounds=0;
}
void GameLib_CleanParallaxBackgrounds() { _nParallaxBackgrounds = 0; }

View File

@@ -11,13 +11,11 @@
#include "Anim.h"
#include "Entity.h"
/////////////////////////////
// GameLib_Init
//
// Initializes the game.
int GameLib_Init(int w,int h,char *title,int pfps,int fps);
int GameLib_Init(int w, int h, char *title, int pfps, int fps);
/////////////////////////////
// GameLib_AddEntity
@@ -25,31 +23,24 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps);
// Adds an entity to the game.
void GameLib_AddEntity(Entity e);
/////////////////////////////
// GameLib_UnrefEntity
//
// removes the reference to the entity.
int GameLib_UnrefEntity(Entity e);
/////////////////////////////
// GameLib_DelEntity
//
// Adds an entity to the game.
int GameLib_DelEntity(Entity e);
/////////////////////////////
// GameLib_Loop
//
// Loops the game.
void GameLib_Loop(
void (*gameproc)(),
void (*gamepostproc)(),
void (*gamepredraw)(float f),
void (*gamedraw)(float f));
void GameLib_Loop(void (*gameproc)(), void (*gamepostproc)(),
void (*gamepredraw)(float f), void (*gamedraw)(float f));
/////////////////////////////
// GameLib_GetPos
@@ -63,8 +54,7 @@ void GameLib_GetPos(int pos[2]);
void GameLib_SetPos(int pos[2]);
void GameLib_UpdatePos(int pos[2]);
void GameLib_GetSize(int size[2]);
void GameLib_GetPosInstant(int pos[2],float f);
void GameLib_GetPosInstant(int pos[2], float f);
/////////////////////////////
// GameLib_MoveToPos
@@ -72,10 +62,9 @@ void GameLib_GetPosInstant(int pos[2],float f);
// GameLib_MoveToPosV
//
//
void GameLib_MoveToPos(vec2 pos,float f);
void GameLib_MoveToPosH(vec2 pos,float f);
void GameLib_MoveToPosV(vec2 pos,float f);
void GameLib_MoveToPos(vec2 pos, float f);
void GameLib_MoveToPosH(vec2 pos, float f);
void GameLib_MoveToPosV(vec2 pos, float f);
/////////////////////////////
// GameLib_ForEachEn
@@ -83,34 +72,29 @@ void GameLib_MoveToPosV(vec2 pos,float f);
// Deletes every entity.
void GameLib_DelEnts();
/////////////////////////////
// GameLib_ForEachEnt
//
// Iterates every entity.
void GameLib_ForEachEnt(int (*func)(Entity ent));
/////////////////////////////
// GameLib_SearchEnt
//
// Searches throught the entities.
Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d);
Entity GameLib_SearchEnt(int (*func)(Entity ent, void *d), void *d);
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//
//
int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel);
int GameLib_EntityCustomCheckCollision(Entity ent, vec2 vel);
/////////////////////////////
// GameLib_PlaySound
//
// Play a sound position aware.
void GameLib_PlaySound(AudioSnd snd,int x,int y);
void GameLib_PlaySound(AudioSnd snd, int x, int y);
/////////////////////////////
// GameLib_PlayLoopingSound
@@ -118,28 +102,24 @@ void GameLib_PlaySound(AudioSnd snd,int x,int y);
// Play a sound looping
AudioChn GameLib_PlayLoopingSound(AudioSnd snd);
/////////////////////////////
// GameLib_EntitySetLight
//
//
void GameLib_EntitySetLight(Entity e,float r,float g,float b,float rad);
void GameLib_EntitySetLight(Entity e, float r, float g, float b, float rad);
/////////////////////////////
// GameLib_ConvertScreenPositionToGamePosition
//
//
void GameLib_ConvertScreenPositionToGamePosition(
vec2 screenPos, vec2 gamePos);
void GameLib_ConvertScreenPositionToGamePosition(vec2 screenPos, vec2 gamePos);
/////////////////////////////
// GameLib_AddParallaxBackground
//
//
void GameLib_AddParallaxBackground(DrawImg img, int imgSize[2], int imgOffset[2], float parallaxFactor[2]);
void GameLib_AddParallaxBackground(DrawImg img, int imgSize[2],
int imgOffset[2], float parallaxFactor[2]);
/////////////////////////////
// GameLib_CleanParallaxBackgrounds

View File

@@ -9,194 +9,180 @@
#include "Util.h"
#include "Input.h"
// Globals
InputKeyStatus _keys[InputKey_Max];
int _pointerDown=0;
float _pointerX=0;
float _pointerY=0;
int _clicked=0;
float _clickedPositionX=0;
float _clickedPositionY=0;
int _pointerDown = 0;
float _pointerX = 0;
float _pointerY = 0;
int _clicked = 0;
float _clickedPositionX = 0;
float _clickedPositionY = 0;
/////////////////////////////
// Input_Init
//
// Initializes the game input.
int Input_Init(){
int Input_Init() {
int i;
// Mark released all the keys
for(i=0;i<InputKey_Max;i++){
_keys[i]=InputKey_Released;
for (i = 0; i < InputKey_Max; i++) {
_keys[i] = InputKey_Released;
}
return(1);
return (1);
}
/////////////////////////////
// Input_Frame
//
// Notify a frame update to the input subsystem.
void Input_Frame(){
Uint8* keys;
void Input_Frame() {
Uint8 *keys;
// Get keyboard state
keys=(Uint8 *)SDL_GetKeyState(NULL);
keys = (Uint8 *)SDL_GetKeyState(NULL);
// Process Keys
Input_SetKey(InputKey_Action1,keys[SDLK_z]);
Input_SetKey(InputKey_Action2,keys[SDLK_x]);
Input_SetKey(InputKey_Up,keys[SDLK_UP]);
Input_SetKey(InputKey_Down,keys[SDLK_DOWN]);
Input_SetKey(InputKey_Left,keys[SDLK_LEFT]);
Input_SetKey(InputKey_Right,keys[SDLK_RIGHT]);
Input_SetKey(InputKey_Jump,keys[SDLK_SPACE]);
Input_SetKey(InputKey_Continue,keys[SDLK_RETURN]|keys[SDLK_KP_ENTER]|_pointerDown);
Input_SetKey(InputKey_Action1, keys[SDLK_z]);
Input_SetKey(InputKey_Action2, keys[SDLK_x]);
Input_SetKey(InputKey_Up, keys[SDLK_UP]);
Input_SetKey(InputKey_Down, keys[SDLK_DOWN]);
Input_SetKey(InputKey_Left, keys[SDLK_LEFT]);
Input_SetKey(InputKey_Right, keys[SDLK_RIGHT]);
Input_SetKey(InputKey_Jump, keys[SDLK_SPACE]);
Input_SetKey(InputKey_Continue,
keys[SDLK_RETURN] | keys[SDLK_KP_ENTER] | _pointerDown);
Input_SetKey(InputKey_DumpProfiling,keys[SDLK_p]);
Input_SetKey(InputKey_DumpProfiling, keys[SDLK_p]);
}
/////////////////////////////
// Input_PostFrame
//
// Notify a frame update to the input subsystem.
void Input_PostFrame(){
Input_SetKey(InputKey_Exit,0);
_clicked=0;
void Input_PostFrame() {
Input_SetKey(InputKey_Exit, 0);
_clicked = 0;
}
/////////////////////////////
// Input_SetKey
//
// Notify a key press to the input subsystem.
void Input_SetKey(InputKey key,int status){
if(!status){
_keys[key]=InputKey_Released;
}else{
if(_keys[key]>=InputKey_Pressed){
_keys[key]=InputKey_Holded;
}else{
_keys[key]=InputKey_Pressed;
void Input_SetKey(InputKey key, int status) {
if (!status) {
_keys[key] = InputKey_Released;
} else {
if (_keys[key] >= InputKey_Pressed) {
_keys[key] = InputKey_Holded;
} else {
_keys[key] = InputKey_Pressed;
}
}
}
/////////////////////////////
// Input_GetKey
//
// Reports a the status of a key.
InputKeyStatus Input_GetKey(InputKey key){
return(_keys[key]);
}
InputKeyStatus Input_GetKey(InputKey key) { return (_keys[key]); }
/////////////////////////////
// Input_SetPointerPosition
//
void Input_SetPointerPosition(float x, float y){
_pointerX=x;
_pointerY=y;
void Input_SetPointerPosition(float x, float y) {
_pointerX = x;
_pointerY = y;
}
/////////////////////////////
// Input_SetPointerDown
//
void Input_SetPointerDown(int pointerDown){
if(pointerDown==0 && _pointerDown==1){
_clicked=1;
_clickedPositionX=_pointerX;
_clickedPositionY=_pointerY;
void Input_SetPointerDown(int pointerDown) {
if (pointerDown == 0 && _pointerDown == 1) {
_clicked = 1;
_clickedPositionX = _pointerX;
_clickedPositionY = _pointerY;
}
_pointerDown=pointerDown;
_pointerDown = pointerDown;
}
/////////////////////////////
// Input_GetPointerPosition
//
int Input_GetPointerPosition(vec2 pointer){
pointer[0]=_pointerX;
pointer[1]=_pointerY;
int Input_GetPointerPosition(vec2 pointer) {
pointer[0] = _pointerX;
pointer[1] = _pointerY;
return _pointerDown;
}
/////////////////////////////
// Input_GetClickedPosition
//
int Input_GetClickedPosition(vec2 clickPosition){
clickPosition[0]=_clickedPositionX;
clickPosition[1]=_clickedPositionY;
int Input_GetClickedPosition(vec2 clickPosition) {
clickPosition[0] = _clickedPositionX;
clickPosition[1] = _clickedPositionY;
return _clicked;
}
/////////////////////////////
// Input_AnyKey
//
//
int Input_AnyKey(){
int Input_AnyKey() {
int i;
for(i=0;i<InputKey_Max;i++){
if(_keys[i]==InputKey_Pressed){
return(1);
for (i = 0; i < InputKey_Max; i++) {
if (_keys[i] == InputKey_Pressed) {
return (1);
}
}
return(0);
return (0);
}
/////////////////////////////
// Input_GetDir
//
// Reports the direction of the dpad.
int Input_GetDir(vec2 dir){
int Input_GetDir(vec2 dir) {
float vlen;
Uint8 buttons;
int mx,my;
int mx, my;
float dlen;
extern int _width,_height;
extern int _width, _height;
// Get mouse state
buttons=SDL_GetMouseState(&mx,&my);
if(buttons){
buttons = SDL_GetMouseState(&mx, &my);
if (buttons) {
// Use the mouse
vec2_set(dir,mx-(_width/2),my-(_height/2.0f));
dlen=1.0f/sqrtf(vec2_dot(dir,dir));
vec2_scale(dir,dir,dlen);
return(1);
}else{
vec2_set(dir, mx - (_width / 2), my - (_height / 2.0f));
dlen = 1.0f / sqrtf(vec2_dot(dir, dir));
vec2_scale(dir, dir, dlen);
return (1);
} else {
// Use the keyboar
vec2_set(dir,0.0f,0.0f);
if(Input_GetKey(InputKey_Up) ){
dir[1]-=1.0f;
vec2_set(dir, 0.0f, 0.0f);
if (Input_GetKey(InputKey_Up)) {
dir[1] -= 1.0f;
}
if(Input_GetKey(InputKey_Down) ){
dir[1]+=1.0f;
if (Input_GetKey(InputKey_Down)) {
dir[1] += 1.0f;
}
if(Input_GetKey(InputKey_Left) ){
dir[0]-=1.0f;
if (Input_GetKey(InputKey_Left)) {
dir[0] -= 1.0f;
}
if(Input_GetKey(InputKey_Right) ){
dir[0]+=1.0f;
if (Input_GetKey(InputKey_Right)) {
dir[0] += 1.0f;
}
vlen=vec2_dot(dir,dir);
if(vlen>0.0f){
vlen=sqrtf(vlen);
vec2_scale(dir,dir,1.0f/vlen);
return(1);
}else{
return(0);
vlen = vec2_dot(dir, dir);
if (vlen > 0.0f) {
vlen = sqrtf(vlen);
vec2_scale(dir, dir, 1.0f / vlen);
return (1);
} else {
return (0);
}
}
}

View File

@@ -5,28 +5,24 @@
#include "Util.h"
/////////////////////////////
// Input_Init
//
// Initializes the game input.
int Input_Init();
/////////////////////////////
// Input_Frame
//
// Notify a frame update to the input subsystem.
void Input_Frame();
/////////////////////////////
// Input_PostFrame
//
// Notify a frame update end to the input subsystem.
void Input_PostFrame();
////////////////////////////////////////////////
// InputKey //
//////////////
@@ -47,13 +43,11 @@ typedef enum {
InputKey_Max
} InputKey;
/////////////////////////////
// Input_SetKey
//
// Notify a key press to the input subsystem.
void Input_SetKey(InputKey key,int status);
void Input_SetKey(InputKey key, int status);
////////////////////////////////////////////////
// InputKeyStatus //
@@ -65,50 +59,42 @@ typedef enum {
InputKey_Holded
} InputKeyStatus;
/////////////////////////////
// Input_GetKey
//
// Reports a the status of a key.
InputKeyStatus Input_GetKey(InputKey key);
/////////////////////////////
// Input_SetPointerPosition
//
void Input_SetPointerPosition(float x, float y);
/////////////////////////////
// Input_SetPointerDown
//
void Input_SetPointerDown(int pointerDown);
/////////////////////////////
// Input_GetPointerPosition
//
int Input_GetPointerPosition(vec2 pointer);
/////////////////////////////
// Input_GetClickedPosition
//
int Input_GetClickedPosition(vec2 clickPosition);
/////////////////////////////
// Input_AnyKey
//
//
int Input_AnyKey();
/////////////////////////////
// Input_GetDir
//
// Reports the direction of the dpad.
int Input_GetDir(vec2 dir);
#endif

View File

@@ -6,73 +6,91 @@
#include "QuadArray2D.h"
QuadArray2D QuadArray2D_Create(int resVertex) {
QuadArray2D quadArray = NULL;
QuadArray2D QuadArray2D_Create(int resVertex){
QuadArray2D quadArray=NULL;
quadArray = malloc(sizeof(TQuadArray2D));
quadArray=malloc(sizeof(TQuadArray2D));
quadArray->vertexData=malloc(sizeof(float)*Vertex2D_Length*resVertex);
quadArray->nVertex=0;
quadArray->resVertex=resVertex;
quadArray->vertexData = malloc(sizeof(float) * Vertex2D_Length * resVertex);
quadArray->nVertex = 0;
quadArray->resVertex = resVertex;
return quadArray;
}
void QuadArray2D_Destroy(QuadArray2D *quadArray){
if(!quadArray) return;
if(!quadArray[0]) return;
void QuadArray2D_Destroy(QuadArray2D *quadArray) {
if (!quadArray)
return;
if (!quadArray[0])
return;
free(quadArray[0]->vertexData);
free(quadArray[0]);
quadArray[0]=NULL;
quadArray[0] = NULL;
}
void QuadArray2D_Clean(QuadArray2D quadArray){
quadArray->nVertex=0;
}
void QuadArray2D_Clean(QuadArray2D quadArray) { quadArray->nVertex = 0; }
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]){
if(quadArray->resVertex<=quadArray->nVertex){
void QuadArray2D_AddVertex(QuadArray2D quadArray, float v[]) {
if (quadArray->resVertex <= quadArray->nVertex) {
// Grow vertexData
quadArray->resVertex*=2;
float *newVertexData=malloc(sizeof(float)*Vertex2D_Length*
quadArray->resVertex);
memcpy(newVertexData,quadArray->vertexData,
sizeof(float)*Vertex2D_Length*quadArray->nVertex);
quadArray->resVertex *= 2;
float *newVertexData =
malloc(sizeof(float) * Vertex2D_Length * quadArray->resVertex);
memcpy(newVertexData, quadArray->vertexData,
sizeof(float) * Vertex2D_Length * quadArray->nVertex);
free(quadArray->vertexData);
quadArray->vertexData=newVertexData;
quadArray->vertexData = newVertexData;
}
// Add the vertex
memcpy(
quadArray->vertexData+
(Vertex2D_Length*quadArray->nVertex),
v,sizeof(float)*Vertex2D_Length);
memcpy(quadArray->vertexData + (Vertex2D_Length * quadArray->nVertex), v,
sizeof(float) * Vertex2D_Length);
quadArray->nVertex++;
}
void QuadArray2D_AddQuad(QuadArray2D quadArray,
float x0, float y0,float u0, float v0,
float x1, float y1,float u1, float v1,
float color[])
{
void QuadArray2D_AddQuad(QuadArray2D quadArray, float x0, float y0, float u0,
float v0, float x1, float y1, float u1, float v1,
float color[]) {
float v[Vertex2D_Length];
int firstIndex=quadArray->nVertex;
int firstIndex = quadArray->nVertex;
// Set the color
v[4]=color[0];
v[5]=color[1];
v[6]=color[2];
v[7]=color[3];
v[4] = color[0];
v[5] = color[1];
v[6] = color[2];
v[7] = color[3];
// Add the vertexes
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y0; v[2]=u1; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0] = x0;
v[1] = y0;
v[2] = u0;
v[3] = v0;
QuadArray2D_AddVertex(quadArray, v);
v[0] = x1;
v[1] = y0;
v[2] = u1;
v[3] = v0;
QuadArray2D_AddVertex(quadArray, v);
v[0] = x1;
v[1] = y1;
v[2] = u1;
v[3] = v1;
QuadArray2D_AddVertex(quadArray, v);
v[0]=x1; v[1]=y1; v[2]=u1; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y1; v[2]=u0; v[3]=v1; QuadArray2D_AddVertex(quadArray,v);
v[0]=x0; v[1]=y0; v[2]=u0; v[3]=v0; QuadArray2D_AddVertex(quadArray,v);
v[0] = x1;
v[1] = y1;
v[2] = u1;
v[3] = v1;
QuadArray2D_AddVertex(quadArray, v);
v[0] = x0;
v[1] = y1;
v[2] = u0;
v[3] = v1;
QuadArray2D_AddVertex(quadArray, v);
v[0] = x0;
v[1] = y0;
v[2] = u0;
v[3] = v0;
QuadArray2D_AddVertex(quadArray, v);
}

View File

@@ -6,7 +6,6 @@
// Vertex2D -> (x,y) (u,v) (r,g,b,a)
#define Vertex2D_Length 8
////////////////////////////////////////////////
// QuadArray2D
//
@@ -17,19 +16,16 @@ struct TQuadArray2D {
int resVertex;
};
QuadArray2D QuadArray2D_Create(int resVertex);
void QuadArray2D_Destroy(QuadArray2D *quadArray);
void QuadArray2D_Clean(QuadArray2D quadArray);
void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]);
void QuadArray2D_AddVertex(QuadArray2D quadArray, float v[]);
void QuadArray2D_AddQuad(QuadArray2D quadArray,
float x0, float y0,float u0, float v0,
float x1, float y1,float u1, float v1,
void QuadArray2D_AddQuad(QuadArray2D quadArray, float x0, float y0, float u0,
float v0, float x1, float y1, float u1, float v1,
float color[]);
#endif

View File

@@ -8,7 +8,6 @@
#include "Time.h"
/////////////////////////////
// Time_GetTime
//
@@ -20,46 +19,44 @@
#if WIN32
#include <windows.h>
// WIN32
long long Time_GetTime(){
long long Time_GetTime() {
LARGE_INTEGER freq;
LARGE_INTEGER tim;
long long int microt;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&tim);
microt=(tim.QuadPart*1000000)/freq.QuadPart;
return(microt);
microt = (tim.QuadPart * 1000000) / freq.QuadPart;
return (microt);
}
void Time_Pause(int pausa){
long long tend,t,diff;
void Time_Pause(int pausa) {
long long tend, t, diff;
t=Time_GetTime();
tend=t+pausa;
do{
diff=tend-t;
if(diff>1000){
Sleep(diff/1000);
}else{
t = Time_GetTime();
tend = t + pausa;
do {
diff = tend - t;
if (diff > 1000) {
Sleep(diff / 1000);
} else {
Sleep(0);
}
t=Time_GetTime();
}while(tend>=t);
t = Time_GetTime();
} while (tend >= t);
}
#else
// UNIX
long long Time_GetTime(){
long long Time_GetTime() {
struct timeval t;
long long usecs;
gettimeofday(&t,NULL);
usecs=(t.tv_sec*1000000ll)+(t.tv_usec);
return(usecs);
gettimeofday(&t, NULL);
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
return (usecs);
}
void Time_Pause(int pausa){
void Time_Pause(int pausa) {
struct timeval tv;
tv.tv_sec=(long long)pausa/1000000;
tv.tv_usec=(long long)pausa%1000000;
tv.tv_sec = (long long)pausa / 1000000;
tv.tv_usec = (long long)pausa % 1000000;
select(0, NULL, NULL, NULL, &tv);
}
#endif // if WIN32

View File

@@ -9,7 +9,6 @@
// Gets the current time in usecs.
long long Time_GetTime();
/////////////////////////////
// Time_Pause
//

View File

@@ -8,42 +8,40 @@
#include "Util.h"
/////////////////////////////
// SolveQuadratic
//
// Solves a Quadratic equation using a, b and c coeficients.
int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax){
int SolveQuadratic(float a, float b, float c, float *Rmin, float *Rmax) {
float root;
float divisor;
float b2;
b2=b*b;
root=b2-4.0*a*c;
if(root<0){
b2 = b * b;
root = b2 - 4.0 * a * c;
if (root < 0) {
// Complex
return(0);
return (0);
}
divisor=(2.0*a);
if(fabs(divisor)==0.0f){
divisor = (2.0 * a);
if (fabs(divisor) == 0.0f) {
// +inf -inf
return(0);
return (0);
}
root=sqrtf(root);
Rmin[0]=(float)((-b-root)/divisor);
Rmax[0]=(float)((-b+root)/divisor);
return(1);
root = sqrtf(root);
Rmin[0] = (float)((-b - root) / divisor);
Rmax[0] = (float)((-b + root) / divisor);
return (1);
}
////////////////////////////////////////////////
// vec2 //
//////////
// A 2D vector.
float vec2_norm(vec2 v){
float vec2_norm(vec2 v) {
float len;
len=vec2_len(v);
vec2_scale(v,v,1.0f/len);
return(len);
len = vec2_len(v);
vec2_scale(v, v, 1.0f / len);
return (len);
}
void vec2_orthogonalize4(vec2 v) {
@@ -100,187 +98,174 @@ void vec2_orthogonalize8(vec2 v) {
}
}
/////////////////////////////
// Intersec_RayUnitCircle
//
// Intersection between a ray and a Unit Circle.
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t){
float a,b,c;
float Rmin,Rmax;
int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t) {
float a, b, c;
float Rmin, Rmax;
vec2 distv;
float qlvel;
float qdistv;
// Check if the collision is even posible
qlvel=vec2_dot(vel,vel);
if(fabs(qlvel)<=0.0f)
return(0);
vec2_minus(distv,orig,center);
qdistv=vec2_dot(distv,distv);
qlvel = vec2_dot(vel, vel);
if (fabs(qlvel) <= 0.0f)
return (0);
vec2_minus(distv, orig, center);
qdistv = vec2_dot(distv, distv);
// Solve as a unit circle
a=qlvel;
b=2.0f*vec2_dot(distv,vel);
c=qdistv-1.0f;
if(SolveQuadratic(a,b,c,&Rmin,&Rmax)){
if(Rmin>=-0.0f && Rmin<Rmax && Rmin<=1.0f){
*t=Rmin;
return(1);
a = qlvel;
b = 2.0f * vec2_dot(distv, vel);
c = qdistv - 1.0f;
if (SolveQuadratic(a, b, c, &Rmin, &Rmax)) {
if (Rmin >= -0.0f && Rmin < Rmax && Rmin <= 1.0f) {
*t = Rmin;
return (1);
}
if(Rmax>=-0.0f && Rmin>Rmax && Rmax<=1.0f){
*t=Rmax;
return(1);
if (Rmax >= -0.0f && Rmin > Rmax && Rmax <= 1.0f) {
*t = Rmax;
return (1);
}
}
return(0);
return (0);
}
/////////////////////////////
// Colision_CircleCircle
//
// Colision point of a circle against another circle.
int Colision_CircleCircle(
vec2 cir1,float rad1,vec2 vel,
vec2 cir2,float rad2,
float *t,vec2 n)
{
vec2 vel_a,orig_a,cen_a,temp;
float rads,invrads;
float maxx,minx;
float maxy,miny;
int Colision_CircleCircle(vec2 cir1, float rad1, vec2 vel, vec2 cir2,
float rad2, float *t, vec2 n) {
vec2 vel_a, orig_a, cen_a, temp;
float rads, invrads;
float maxx, minx;
float maxy, miny;
// Check if the collision is even posible
rads=rad1+rad2;
minx=cir1[0]-rads;
maxx=cir1[0]+rads;
if(vel[0]>0){
maxx+=vel[0];
}else{
minx+=vel[0];
rads = rad1 + rad2;
minx = cir1[0] - rads;
maxx = cir1[0] + rads;
if (vel[0] > 0) {
maxx += vel[0];
} else {
minx += vel[0];
}
if(cir2[0]<minx || cir2[0]>maxx)
return(0);
miny=cir1[1]-rads;
maxy=cir1[1]+rads;
if(vel[1]>0){
maxy+=vel[1];
}else{
miny+=vel[1];
if (cir2[0] < minx || cir2[0] > maxx)
return (0);
miny = cir1[1] - rads;
maxy = cir1[1] + rads;
if (vel[1] > 0) {
maxy += vel[1];
} else {
miny += vel[1];
}
if(cir2[1]<miny || cir2[1]>maxy)
return(0);
if (cir2[1] < miny || cir2[1] > maxy)
return (0);
// Convert to a unit circle vs ray
invrads=1.0f/rads;
vec2_scale(vel_a,vel,invrads);
vec2_scale(orig_a,cir1,invrads);
vec2_scale(cen_a,cir2,invrads);
if(Intersec_RayUnitCircle(orig_a,vel_a,cen_a,t)){
invrads = 1.0f / rads;
vec2_scale(vel_a, vel, invrads);
vec2_scale(orig_a, cir1, invrads);
vec2_scale(cen_a, cir2, invrads);
if (Intersec_RayUnitCircle(orig_a, vel_a, cen_a, t)) {
// Calculate n
vec2_scaleadd(temp,cir1,vel,*t);
vec2_minus(n,temp,cir2);
vec2_scale(n,n,invrads);
return(1);
vec2_scaleadd(temp, cir1, vel, *t);
vec2_minus(n, temp, cir2);
vec2_scale(n, n, invrads);
return (1);
}
return(0);
return (0);
}
/////////////////////////////
// Intersect_RayEdge
//
// Intersection between a ray and a edge.
int Intersect_RayEdge(
vec2 pos,vec2 vel,
vec2 norm,vec2 edgePos,float len,
float *t)
{
vec2 pos2,intersection,perp,edgePos2;
float delta,d1,d2,hLen;
int Intersect_RayEdge(vec2 pos, vec2 vel, vec2 norm, vec2 edgePos, float len,
float *t) {
vec2 pos2, intersection, perp, edgePos2;
float delta, d1, d2, hLen;
vec2_plus(pos2,pos,vel);
hLen=len/2;
vec2_plus(pos2, pos, vel);
hLen = len / 2;
// Check intersection against the line
delta=vec2_dot(norm,edgePos);
d1=vec2_dot(pos ,norm)-delta;
d2=vec2_dot(pos2,norm)-delta;
if(d1>=-0.0001f && d2<=0.0001f){
delta = vec2_dot(norm, edgePos);
d1 = vec2_dot(pos, norm) - delta;
d2 = vec2_dot(pos2, norm) - delta;
if (d1 >= -0.0001f && d2 <= 0.0001f) {
// Intersection with line, Calculate intersection point
*t=d1/(d1-d2);
vec2_scaleadd(intersection,pos,vel,*t);
*t = d1 / (d1 - d2);
vec2_scaleadd(intersection, pos, vel, *t);
// Perpendicular
vec2_perp(perp,norm);
vec2_perp(perp, norm);
// Check sides
vec2_scaleadd(edgePos2,edgePos,perp,-hLen);
delta=-vec2_dot(perp,edgePos2);
d1=(-vec2_dot(perp,intersection))-delta;
vec2_scaleadd(edgePos2, edgePos, perp, -hLen);
delta = -vec2_dot(perp, edgePos2);
d1 = (-vec2_dot(perp, intersection)) - delta;
vec2_scaleadd(edgePos2,edgePos,perp,hLen);
delta=vec2_dot(perp,edgePos2);
d2=vec2_dot(perp,intersection)-delta;
vec2_scaleadd(edgePos2, edgePos, perp, hLen);
delta = vec2_dot(perp, edgePos2);
d2 = vec2_dot(perp, intersection) - delta;
if(d1<=0.0f && d2<=0.0f){
if (d1 <= 0.0f && d2 <= 0.0f) {
// Intersection inside Edge.
return(1);
return (1);
}
}
return(0);
return (0);
}
/////////////////////////////
// absmod
//
int absmod(int v,int d){
if(v<0){
v+=d*(((v/d)*(-1))+1);
return(v);
}else{
return(v%d);
int absmod(int v, int d) {
if (v < 0) {
v += d * (((v / d) * (-1)) + 1);
return (v);
} else {
return (v % d);
}
}
float fabsmod(float v,int d){
if(v<0){
v+=d*((((int)(v/d))*(-1))+1);
return(v);
}else{
v-=d*(((int)(v/d))+1);
return(v);
float fabsmod(float v, int d) {
if (v < 0) {
v += d * ((((int)(v / d)) * (-1)) + 1);
return (v);
} else {
v -= d * (((int)(v / d)) + 1);
return (v);
}
}
/////////////////////////////
// IsBigEndian
//
int IsBigEndian(){
union{
int IsBigEndian() {
union {
unsigned int i;
char c[4];
} bint={0x01020304};
return bint.c[0]==1;
} bint = {0x01020304};
return bint.c[0] == 1;
}
/////////////////////////////
// EndsWith
//
int EndsWith(char *str, char *suffix){
int EndsWith(char *str, char *suffix) {
if (!str || !suffix)
return 0;
int lenStr = strlen(str);
int lenSuffix = strlen(suffix);
if (lenSuffix > lenStr)
return 0;
return strncmp(str+lenStr-lenSuffix, suffix, lenSuffix)==0;
return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0;
}
/////////////////////////////
// Rand
//
@@ -356,7 +341,6 @@ unsigned Rand_Get() {
return (val);
}
/////////////////////////////
// Print
//
@@ -372,6 +356,5 @@ int Print(char *fmt, ...) {
// Flush
fflush(stdout);
return(n);
return (n);
}

View File

@@ -10,84 +10,85 @@
// SolveQuadratic
//
// Solves a Quadratic equation using a, b and c coeficients.
int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax);
int SolveQuadratic(float a, float b, float c, float *Rmin, float *Rmax);
////////////////////////////////////////////////
// vec2 //
//////////
// A 2D vector.
typedef float vec2[2];
#define vec2_set(v,x,y) (v)[0]=(x);(v)[1]=(y);
#define vec2_copy(v1,v2) (v1)[0]=(v2)[0];(v1)[1]=(v2)[1];
#define vec2_plus(v,v1,v2) (v)[0]=(v1)[0]+(v2)[0];(v)[1]=(v1)[1]+(v2)[1];
#define vec2_minus(v,v1,v2) (v)[0]=(v1)[0]-(v2)[0];(v)[1]=(v1)[1]-(v2)[1];
#define vec2_scale(v,v1,s) (v)[0]=(v1)[0]*(s);(v)[1]=(v1)[1]*(s);
#define vec2_dot(v1,v2) ((v1)[0]*(v2)[0]+(v1)[1]*(v2)[1])
#define vec2_len(v) sqrtf((v)[0]*(v)[0]+(v)[1]*(v)[1])
#define vec2_perp(v,n) (v)[0]=-(n)[1];(v)[1]=(n)[0];
#define vec2_scaleadd(v,v1,v2,s) (v)[0]=(v2)[0]*(s)+(v1)[0];(v)[1]=(v2)[1]*(s)+(v1)[1];
#define vec2_set(v, x, y) \
(v)[0] = (x); \
(v)[1] = (y);
#define vec2_copy(v1, v2) \
(v1)[0] = (v2)[0]; \
(v1)[1] = (v2)[1];
#define vec2_plus(v, v1, v2) \
(v)[0] = (v1)[0] + (v2)[0]; \
(v)[1] = (v1)[1] + (v2)[1];
#define vec2_minus(v, v1, v2) \
(v)[0] = (v1)[0] - (v2)[0]; \
(v)[1] = (v1)[1] - (v2)[1];
#define vec2_scale(v, v1, s) \
(v)[0] = (v1)[0] * (s); \
(v)[1] = (v1)[1] * (s);
#define vec2_dot(v1, v2) ((v1)[0] * (v2)[0] + (v1)[1] * (v2)[1])
#define vec2_len(v) sqrtf((v)[0] * (v)[0] + (v)[1] * (v)[1])
#define vec2_perp(v, n) \
(v)[0] = -(n)[1]; \
(v)[1] = (n)[0];
#define vec2_scaleadd(v, v1, v2, s) \
(v)[0] = (v2)[0] * (s) + (v1)[0]; \
(v)[1] = (v2)[1] * (s) + (v1)[1];
float vec2_norm(vec2 v);
#define vec2_interpol(v,v1,v2,f) \
(v)[0]=(v1)[0]-f*((v1)[0]-(v2)[0]);\
(v)[1]=(v1)[1]-f*((v1)[1]-(v2)[1]);
#define vec2_interpol(v, v1, v2, f) \
(v)[0] = (v1)[0] - f * ((v1)[0] - (v2)[0]); \
(v)[1] = (v1)[1] - f * ((v1)[1] - (v2)[1]);
void vec2_orthogonalize4(vec2 v);
void vec2_orthogonalize8(vec2 v);
/////////////////////////////
// Intersec_RayUnitCircle
//
// Intersection between a ray and a Unit Circle.
int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t);
int Intersec_RayUnitCircle(vec2 orig, vec2 vel, vec2 center, float *t);
/////////////////////////////
// Intersect_CircleCircle
//
// Colision point of a circle against another circle.
int Colision_CircleCircle(
vec2 cir1,float ra,vec2 vel,
vec2 cb,float rb,
float *t,vec2 n);
int Colision_CircleCircle(vec2 cir1, float ra, vec2 vel, vec2 cb, float rb,
float *t, vec2 n);
/////////////////////////////
// Intersect_RayEdge
//
// Intersection between a ray and a edge.
int Intersect_RayEdge(
vec2 pos,vec2 vel,
vec2 norm,vec2 edgePos,float len,
int Intersect_RayEdge(vec2 pos, vec2 vel, vec2 norm, vec2 edgePos, float len,
float *t);
/////////////////////////////
// absmod
//
int absmod(int v,int d);
float fabsmod(float v,int d);
int absmod(int v, int d);
float fabsmod(float v, int d);
/////////////////////////////
// IsBigEndian
//
int IsBigEndian();
/////////////////////////////
// EndsWith
//
int EndsWith(char *str, char *suffix);
/////////////////////////////
// Rand
//
void Rand_Seed(unsigned seed);
unsigned Rand_Get();
#define Rand_GetFloat(x) (((float)(Rand_Get()%1048576))/1048576.0f)
#define Rand_GetFloat(x) (((float)(Rand_Get() % 1048576)) / 1048576.0f)
/////////////////////////////
// Print
@@ -95,5 +96,4 @@ unsigned Rand_Get();
// Prints the formated text
int Print(char *fmt, ...);
#endif