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,20 +17,13 @@ Entity ent_Player;
Entity ent_Platform;
Entity ent_Block;
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
))
{
if (!(e->type == Ent_Player || 0)) {
return (1);
}
@@ -38,13 +31,9 @@ int EntityApplyGravity(Entity e){
vec2_set(vGrav, 0.0f, grav);
Entity_AddVelLimit(e, vGrav, vTerminal);
return (1);
}
void player_proc(Entity e, int ft) {
float acel = 8.0f;
float maxVel = 30.0f;
@@ -52,8 +41,7 @@ void player_proc(Entity e,int ft){
float shootVel = 50.0f;
if (Input_GetKey(InputKey_Jump) == InputKey_Pressed ||
Input_GetKey(InputKey_Up)==InputKey_Pressed)
{
Input_GetKey(InputKey_Up) == InputKey_Pressed) {
vec2 jump;
// Apply jump
@@ -77,28 +65,20 @@ void player_proc(Entity e,int ft){
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;
}
if (Input_GetKey(InputKey_Action1) == InputKey_Pressed ||
Input_GetKey(InputKey_Action2)==InputKey_Pressed)
{
Input_GetKey(InputKey_Action2) == InputKey_Pressed) {
}
// Scroll View
GameLib_MoveToPos(e->pos, 0.6f);
}
void GameEnts_Init() {
/////////////////////////////
// Load and initialize media.
//
@@ -107,7 +87,6 @@ void GameEnts_Init(){
img_platform = Draw_LoadImage("data/platform.png");
img_block = Draw_LoadImage("data/block.png");
/////////////////////////
// Initialize entity types.
//
@@ -150,6 +129,4 @@ void GameEnts_Init(){
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,7 +10,6 @@
#include "GameEnts.h"
#include "GameMap.h"
int ReadLine(FILE *f, char *line, int max) {
int c;
int i = 0;
@@ -34,7 +33,6 @@ int ReadLine(FILE *f,char *line,int max){
return (i);
}
Entity GameMapAux_CreateEnt(Entity ent, int i, int j, int res) {
Entity e;
vec2 pos;
@@ -46,7 +44,6 @@ Entity GameMapAux_CreateEnt(Entity ent,int i,int j,int res){
return (e);
}
#define MaxLineLen 1024
int GameMap_LoadLevel(char *filename, int res) {
@@ -56,7 +53,6 @@ int GameMap_LoadLevel(char *filename,int res){
int width, height;
char *map;
// Open the file
file = fopen(filename, "rb");
if (!file) {
@@ -77,7 +73,6 @@ int GameMap_LoadLevel(char *filename,int res){
} while (len > -1);
fseek(file, 0, SEEK_SET);
// Build the map
map = malloc(sizeof(char) * width * height);
memset(map, 0, width * height);
@@ -91,18 +86,14 @@ int GameMap_LoadLevel(char *filename,int res){
j++;
} while (len > -1);
// Close the file
fclose(file);
// Parse the map
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
Entity ent;
if (MAP(i, j) == 'P') {
// Player
GameMapAux_CreateEnt(ent_Player, i, j, res);
@@ -115,11 +106,9 @@ int GameMap_LoadLevel(char *filename,int res){
// Platform
ent = GameMapAux_CreateEnt(ent_Platform, i, j, res);
}
}
}
// Cleanup
free(map);
#undef MAP

View File

@@ -4,5 +4,4 @@
int GameMap_LoadLevel(char *filename, int res);
#endif

View File

@@ -12,7 +12,6 @@ extern int gamelib_debug;
#include "GameEnts.h"
#include "GameMap.h"
DrawFnt font;
DrawImg imgBackground;
@@ -23,19 +22,13 @@ void MainGame_Text(int x, int y, char *text){
Draw_DrawText(font, text, x, y);
}
void ProcGame(){
}
void ProcGame() {}
void PostProcGame() {
// Apply gravity to every entity
GameLib_ForEachEnt(EntityApplyGravity);
}
void PreDrawGame(float f){
}
void DrawGame(float f){
MainGame_Text(8,8,"Hello world!");
}
void PreDrawGame(float f) {}
void DrawGame(float f) { MainGame_Text(8, 8, "Hello world!"); }
int main(int argc, char *argv[]) {
int i, j;
@@ -70,7 +63,8 @@ int main(int argc,char *argv[]){
// Run the world.
//
GameLib_CleanParallaxBackgrounds();
GameLib_AddParallaxBackground(imgBackground, (int[2]){512, 512}, (int[2]){0, 0}, (float[2]){0.5f, 0.0f});
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);

View File

@@ -6,7 +6,6 @@
#include "Draw.h"
#include "Anim.h"
////////////////////////////////////////////////
// Animation //
///////////////
@@ -20,7 +19,6 @@ typedef struct {
int time;
} Animation;
/////////////////////////////
// Anim_LoadAnim
//
@@ -52,7 +50,6 @@ Anim Anim_LoadAnim(char *fichero,int width,int frames,float fps){
return ((Anim)anim);
}
/////////////////////////////
// Anim_GetTime
//
@@ -63,7 +60,6 @@ int Anim_GetTime(Anim a){
return (anim->time);
}
/////////////////////////////
// Anim_GetSize
//
@@ -76,7 +72,6 @@ void Anim_GetSize(Anim a,int *w,int *h){
Draw_GetSize(anim->img, &waux, h);
}
/////////////////////////////
// Anim_SetOffset
// Anim_GetOffset
@@ -93,7 +88,6 @@ void Anim_GetOffset(Anim a,int *x,int *y){
Draw_GetOffset(anim->img, x, y);
}
/////////////////////////////
// Anim_SetFlip
// Anim_GetFlip
@@ -110,7 +104,6 @@ int Anim_GetFlip(Anim a){
return Draw_GetFlip(anim->img);
}
/////////////////////////////
// Anim_Draw
//
@@ -123,7 +116,6 @@ void Anim_Draw(Anim a,int time_ms,int x,int y){
Draw_DrawImgPartHoriz(anim->img, x, y, anim->w, frame);
}
/////////////////////////////
// AnimPlay_Copy
//
@@ -141,7 +133,6 @@ void AnimPlay_Copy(AnimPlay *ad,AnimPlay *ao){
ad->time_ms = ao->time_ms;
}
/////////////////////////////
// AnimPlay_SetImg
// AnimPlay_SetAnim
@@ -168,7 +159,8 @@ void AnimPlay_SetAnim(AnimPlay *ap,Anim ani){
ap->imgPart = NULL;
}
void AnimPlay_SetImgPart(AnimPlay *ap,DrawImg img,int w,int h,int i,int j){
void AnimPlay_SetImgPart(AnimPlay *ap, DrawImg img, int w, int h, int i,
int j) {
ap->anim = NULL;
ap->time_ms = 0;
@@ -181,7 +173,6 @@ void AnimPlay_SetImgPart(AnimPlay *ap,DrawImg img,int w,int h,int i,int j){
ap->j = j;
}
/////////////////////////////
// AnimPlay_Draw
//
@@ -201,7 +192,6 @@ void AnimPlay_Draw(AnimPlay *ani,int x,int y){
}
}
/////////////////////////////
// AnimPlay_GetOffset
// AnimPlay_GetSize
@@ -225,8 +215,7 @@ void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h){
if (ani->anim) {
Anim_GetSize(ani->anim, w, h);
return;
}else
if(ani->img){
} else if (ani->img) {
Draw_GetSize(ani->img, w, h);
return;
}
@@ -236,16 +225,11 @@ void AnimPlay_GetSize(AnimPlay *ani,int *w,int *h){
}
}
/////////////////////////////
// AnimPlay_SetPause
//
//
void AnimPlay_SetPause(AnimPlay *ani,int p){
ani->pause=p;
}
void AnimPlay_SetPause(AnimPlay *ani, int p) { ani->pause = p; }
/////////////////////////////
// AnimPlay_IncTime
@@ -258,4 +242,3 @@ void AnimPlay_IncTime(AnimPlay *ani,int t){
}
}
}

View File

@@ -5,35 +5,30 @@
#include "Draw.h"
////////////////////////////////////////////////
// Anim //
//////////
//
typedef void *Anim;
/////////////////////////////
// Anim_LoadAnim
//
//
Anim Anim_LoadAnim(char *fichero, int width, int frames, float fps);
/////////////////////////////
// Anim_GetTime
//
//
int Anim_GetTime(Anim anim);
/////////////////////////////
// Anim_GetSize
//
// Gets the animation size.
void Anim_GetSize(Anim anim, int *w, int *h);
/////////////////////////////
// Anim_SetOffset
// Anim_GetOffset
@@ -42,7 +37,6 @@ void Anim_GetSize(Anim anim,int *w,int *h);
void Anim_SetOffset(Anim anim, int x, int y);
void Anim_GetOffset(Anim anim, int *x, int *y);
/////////////////////////////
// Anim_SetFlip
// Draw_GetFlip
@@ -51,14 +45,12 @@ void Anim_GetOffset(Anim anim,int *x,int *y);
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);
////////////////////////////////////////////////
// AnimPlay //
//////////////
@@ -75,14 +67,12 @@ typedef struct {
} AnimPlay;
/////////////////////////////
// AnimPlay_Copy
//
//
void AnimPlay_Copy(AnimPlay *ad, AnimPlay *ao);
/////////////////////////////
// AnimPlay_SetImg
// AnimPlay_SetAnim
@@ -93,14 +83,12 @@ 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);
/////////////////////////////
// AnimPlay_GetOffset
// AnimPlay_GetSize
@@ -109,7 +97,6 @@ void AnimPlay_Draw(AnimPlay *ani,int x,int y);
void AnimPlay_GetOffset(AnimPlay *ani, int *x, int *y);
void AnimPlay_GetSize(AnimPlay *ani, int *w, int *h);
/////////////////////////////
// AnimPlay_SetPause
//
@@ -122,5 +109,4 @@ void AnimPlay_SetPause(AnimPlay *ani,int p);
//
void AnimPlay_IncTime(AnimPlay *ani, int t);
#endif

View File

@@ -14,7 +14,6 @@
static void Audio_MixerCallback(void *ud, Uint8 *stream, int l);
////////////////////////////////////////////////
// AudioWave //
///////////////
@@ -32,7 +31,6 @@ struct TAudioWave {
};
AudioWave _waves = NULL;
////////////////////////////////////////////////
// AudioChan //
///////////////
@@ -83,10 +81,7 @@ int Audio_Init(){
}
// 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);
@@ -98,7 +93,6 @@ int Audio_Init(){
return (1);
}
/////////////////////////////
// Audio_MixerCallback
//
@@ -180,7 +174,8 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
// Next sample
ptr_out += 2;
if(ptr_wave>=(((signed short *)wave->buffer)+(wave->len-1))){
if (ptr_wave >=
(((signed short *)wave->buffer) + (wave->len - 1))) {
ptr_wave = ((signed short *)wave->buffer);
} else {
ptr_wave++;
@@ -201,15 +196,11 @@ static void Audio_MixerCallback(void *ud,Uint8 *stream,int l){
}
}
/////////////////////////////
// Audio_Frame
//
// Notify a frame update to the audio subsystem.
void Audio_Frame(){
}
void Audio_Frame() {}
/////////////////////////////
// Audio_LoadSound
@@ -279,7 +270,9 @@ AudioSnd Audio_LoadSound(char *filename){
// Skip no "data" blocks
do {
int lenRead = fread(id, 1, sizeof(char) * 4, f);
if(lenRead<4){ break; }
if (lenRead < 4) {
break;
}
if (strcmp(id, "data")) {
fread(&dataSize, 1, sizeof(int), f);
fseek(f, dataSize, SEEK_CUR);
@@ -316,14 +309,12 @@ AudioSnd Audio_LoadSound(char *filename){
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) {
@@ -357,7 +348,6 @@ AudioChn Audio_PlaySound(AudioSnd snd,
return chan;
}
/////////////////////////////
// Audio_StopChan
//
@@ -365,8 +355,9 @@ AudioChn Audio_PlaySound(AudioSnd snd,
void Audio_StopChan(AudioChn c) {
AudioChan chan;
chan = c;
if(c==NULL){return;}
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

View File

@@ -51,7 +51,6 @@
#include "Input.h"
#include "Draw.h"
////////////////////////////////////////////////
// DrawImage //
///////////////
@@ -65,8 +64,6 @@ struct TDrawImage {
GLuint tex;
};
// Globals
SDL_Surface *_screen = NULL;
int _width;
@@ -103,14 +100,13 @@ GLuint Draw_CompileShader(GLenum type, const char *source){
return shader;
}
GLuint Draw_BuildProgram(
const char *vertexShaderSource,
const char *fragmentShaderSource)
{
GLuint Draw_BuildProgram(const char *vertexShaderSource,
const char *fragmentShaderSource) {
// Compile shaders
GLuint vertexShader = Draw_CompileShader(GL_VERTEX_SHADER, vertexShaderSource);
GLuint fragmentShader = Draw_CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
GLuint vertexShader =
Draw_CompileShader(GL_VERTEX_SHADER, vertexShaderSource);
GLuint fragmentShader =
Draw_CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSource);
if (vertexShader == 0 || fragmentShader == 0) {
return 0;
}
@@ -124,8 +120,7 @@ GLuint Draw_BuildProgram(
// check if the program linked successfully
GLint linked;
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if (!linked)
{
if (!linked) {
glDeleteProgram(programObject);
return 0;
}
@@ -199,7 +194,6 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
SDL_GL_SwapBuffers();
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
@@ -208,8 +202,7 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
#if USE_OpenGLES
const char vertexShaderSource[] =
"attribute vec4 aPosition; \n"
const char vertexShaderSource[] = "attribute vec4 aPosition; \n"
"attribute vec2 aTexCoord; \n"
"attribute vec4 aColor; \n"
"varying vec2 vTexCoord; \n"
@@ -231,9 +224,7 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
" gl_FragColor = texture2D(sTexture, vTexCoord)*vColor; \n"
"} \n";
programObject=Draw_BuildProgram(
vertexShaderSource,
fragmentShaderSource);
programObject = Draw_BuildProgram(vertexShaderSource, fragmentShaderSource);
glUseProgram(programObject);
vertPosLoc = glGetAttribLocation(programObject, "aPosition");
@@ -241,23 +232,28 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
vertColorLoc = glGetAttribLocation(programObject, "aColor");
textureLoc = glGetUniformLocation(programObject, "sTexture");
projectionMatrixLoc = glGetUniformLocation(programObject, "sProjectionMatrix");
projectionMatrixLoc =
glGetUniformLocation(programObject, "sProjectionMatrix");
glUniform1i(textureLoc, 0);
glGenBuffers(1, &vertexObject);
glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
glBufferData(GL_ARRAY_BUFFER, Vertex2D_Length*sizeof(float)*Max_Vertices,
NULL, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER,
Vertex2D_Length * sizeof(float) * Max_Vertices, NULL,
GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, vertexObject);
glVertexAttribPointer(vertPosLoc, 2, GL_FLOAT, GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(0*sizeof(float)));
Vertex2D_Length * sizeof(float),
(void *)(0 * sizeof(float)));
glVertexAttribPointer(vertTexLoc, 2, GL_FLOAT, GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(2*sizeof(float)));
Vertex2D_Length * sizeof(float),
(void *)(2 * sizeof(float)));
glVertexAttribPointer(vertColorLoc, 4, GL_FLOAT, GL_FALSE,
Vertex2D_Length*sizeof(float), (void*)(4*sizeof(float)));
Vertex2D_Length * sizeof(float),
(void *)(4 * sizeof(float)));
glEnableVertexAttribArray(vertPosLoc);
glEnableVertexAttribArray(vertTexLoc);
@@ -270,11 +266,8 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
// Set the proyection (2D)
glViewport(0, 0, _width, _height);
float projectionMatrix[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
float projectionMatrix[16] = {1, 0, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 1};
projectionMatrix[0] = (2.0f / _width);
projectionMatrix[5] = -(2.0f / _height);
projectionMatrix[10] = -0.001f;
@@ -294,7 +287,6 @@ int Draw_Init(int width,int height,char *title,int pfps,int fps){
return (1);
}
/////////////////////////////
// Draw_ShowInfo
//
@@ -312,27 +304,23 @@ void Draw_ShowInfo(){
Print("*********************************\n");
}
/////////////////////////////
// Draw_SetMatrix
//
// Sets the render matrix
void Draw_SetMatrix(float matrix[16]) {
#if USE_OpenGL
float tempMatrix[16] = {
matrix[0], matrix[4], matrix[ 8], matrix[12],
float tempMatrix[16] = {matrix[0], matrix[4], matrix[8], matrix[12],
matrix[1], matrix[5], matrix[9], matrix[13],
matrix[2], matrix[6], matrix[10], matrix[14],
matrix[3], matrix[7], matrix[11], matrix[15]};
glLoadMatrixf(tempMatrix);
#endif
#if USE_OpenGLES
glUniformMatrix4fv(projectionMatrixLoc,
1, GL_FALSE, matrix);
glUniformMatrix4fv(projectionMatrixLoc, 1, GL_FALSE, matrix);
#endif
}
/////////////////////////////
// Draw_UploadGLTexture
//
@@ -354,14 +342,12 @@ GLuint Draw_UploadGLTexture(int w, int h, unsigned char *pixels){
glPixelStorei(GL_UNPACK_ROW_LENGTH, w);
#endif
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
w, h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
pixels);
return (tex);
}
/////////////////////////////
// Draw_Flush
//
@@ -371,7 +357,8 @@ void Draw_Flush(){
return;
}
if (_currentImg->tex == -1) {
_currentImg->tex=Draw_UploadGLTexture(_currentImg->w, _currentImg->h, _currentImg->data);
_currentImg->tex = Draw_UploadGLTexture(_currentImg->w, _currentImg->h,
_currentImg->data);
}
#if USE_OpenGL
@@ -400,16 +387,11 @@ void Draw_Flush(){
QuadArray2D_Clean(_quadArray);
}
/////////////////////////////
// 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) {
#ifndef EMSCRIPTEN
glClearColor(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@@ -449,7 +431,6 @@ void Draw_Clean(
#endif
}
/////////////////////////////
// Draw_LoopIteration
//
@@ -475,49 +456,36 @@ int Draw_LoopIteration(){
}
}
if (event.type == SDL_MOUSEMOTION) {
Input_SetPointerPosition(
event.motion.x/(float)_width,
Input_SetPointerPosition(event.motion.x / (float)_width,
event.motion.y / (float)_height);
}
if (event.type == SDL_MOUSEBUTTONDOWN) {
Input_SetPointerPosition(
event.button.x/(float)_width,
Input_SetPointerPosition(event.button.x / (float)_width,
event.button.y / (float)_height);
Input_SetPointerDown(1);
}
if (event.type == SDL_FINGERMOTION) {
Input_SetPointerPosition(
event.tfinger.x,
event.tfinger.y);
Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
}
if (event.type == SDL_FINGERDOWN) {
Input_SetPointerPosition(
event.tfinger.x,
event.tfinger.y);
Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
Input_SetPointerDown(1);
}
if (event.type == SDL_TOUCHBUTTONDOWN) {
Input_SetPointerPosition(
event.tfinger.x,
event.tfinger.y);
Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
Input_SetPointerDown(1);
}
if (event.type == SDL_MOUSEBUTTONUP) {
Input_SetPointerPosition(
event.button.x/(float)_width,
Input_SetPointerPosition(event.button.x / (float)_width,
event.button.y / (float)_height);
Input_SetPointerDown(0);
}
if (event.type == SDL_FINGERUP) {
Input_SetPointerPosition(
event.tfinger.x,
event.tfinger.y);
Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
Input_SetPointerDown(0);
}
if (event.type == SDL_TOUCHBUTTONUP) {
Input_SetPointerPosition(
event.tfinger.x,
event.tfinger.y);
Input_SetPointerPosition(event.tfinger.x, event.tfinger.y);
Input_SetPointerDown(0);
}
}
@@ -538,19 +506,16 @@ int Draw_LoopIteration(){
}
}
if (event.type == SDL_MOUSEMOTION) {
Input_SetPointerPosition(
event.motion.x/(float)_width,
Input_SetPointerPosition(event.motion.x / (float)_width,
event.motion.y / (float)_height);
}
if (event.type == SDL_MOUSEBUTTONDOWN) {
Input_SetPointerPosition(
event.button.x/(float)_width,
Input_SetPointerPosition(event.button.x / (float)_width,
event.button.y / (float)_height);
Input_SetPointerDown(1);
}
if (event.type == SDL_MOUSEBUTTONUP) {
Input_SetPointerPosition(
event.button.x/(float)_width,
Input_SetPointerPosition(event.button.x / (float)_width,
event.button.y / (float)_height);
Input_SetPointerDown(0);
}
@@ -616,16 +581,15 @@ void Draw_LoopIterationAux(){
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(
void (*proc)(void *data),
void (*draw)(void *data,float f),
void *data)
{
void Draw_Loop(void (*proc)(void *data), void (*draw)(void *data, float f),
void *data) {
_proc_func = proc;
_draw_func = draw;
_data = data;
if(_draw_looping){return;}
if (_draw_looping) {
return;
}
_draw_looping = 1;
#ifndef EMSCRIPTEN
long long procTime1, procTime2, drawTime1, drawTime2;
@@ -655,7 +619,6 @@ void Draw_Loop(
#endif
}
/////////////////////////////
// Draw_BreakLoop
//
@@ -666,15 +629,11 @@ void Draw_BreakLoop(){
#endif
}
/////////////////////////////
// Draw_OverrideExit
//
// Overrides the default exit mechanism
void Draw_OverrideExit(int override){
_draw_exitoverrided=override;
}
void Draw_OverrideExit(int override) { _draw_exitoverrided = override; }
/////////////////////////////
// Draw_CreateImage
@@ -695,7 +654,6 @@ DrawImg Draw_CreateImage(int w,int h){
return ((DrawImg)image);
}
/////////////////////////////
// Draw_LoadImage
//
@@ -706,13 +664,12 @@ DrawImg Draw_LoadImage(char *filename){
// Try loading PNG images
if (EndsWith(filename, ".png") || EndsWith(filename, ".PNG")) {
image = malloc(sizeof(TDrawImage));
unsigned error = lodepng_decode32_file(
&image->data,
(unsigned*)&image->w,
(unsigned*)&image->h,
filename);
unsigned error =
lodepng_decode32_file(&image->data, (unsigned *)&image->w,
(unsigned *)&image->h, filename);
if (error) {
Print("Draw_LoadImage: PNG decoder error %u: %s on file %s\n", error, lodepng_error_text(error),filename);
Print("Draw_LoadImage: PNG decoder error %u: %s on file %s\n",
error, lodepng_error_text(error), filename);
return (NULL);
}
image->x = -(int)(image->w / 2);
@@ -726,7 +683,6 @@ DrawImg Draw_LoadImage(char *filename){
return (NULL);
}
/////////////////////////////
// Draw_GetSize
//
@@ -739,7 +695,6 @@ void Draw_GetSize(DrawImg img,int *w,int *h){
*h = image->h;
}
/////////////////////////////
// Draw_SetOffset
// Draw_GetOffset
@@ -760,7 +715,6 @@ void Draw_GetOffset(DrawImg img,int *x,int *y){
*y = image->y;
}
/////////////////////////////
// Draw_SetFlip
// Draw_GetFlip
@@ -775,7 +729,6 @@ int Draw_GetFlip(DrawImg img){
return image->flip;
}
/////////////////////////////
// Draw_DrawImg
//
@@ -794,10 +747,14 @@ void Draw_DrawImg(DrawImg img,int x,int y){
// Apply flipping
if (image->flip & 1) {
float t=u1; u1=u2; u2=t;
float t = u1;
u1 = u2;
u2 = t;
}
if (image->flip & 2) {
float t=v1; v1=v2; v2=t;
float t = v1;
v1 = v2;
v2 = t;
}
// Draw a quad
@@ -805,13 +762,9 @@ void Draw_DrawImg(DrawImg img,int x,int y){
Draw_Flush();
_currentImg = image;
}
QuadArray2D_AddQuad(_quadArray,
x1,y1,u1,v1,
x2,y2,u2,v2,
_color);
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
}
/////////////////////////////
// Draw_DrawImgResized
//
@@ -830,10 +783,14 @@ void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
// Apply flipping
if (image->flip & 1) {
float t=u1; u1=u2; u2=t;
float t = u1;
u1 = u2;
u2 = t;
}
if (image->flip & 2) {
float t=v1; v1=v2; v2=t;
float t = v1;
v1 = v2;
v2 = t;
}
// Draw a quad
@@ -841,13 +798,9 @@ void Draw_DrawImgResized(DrawImg img,int x,int y,float w,float h){
Draw_Flush();
_currentImg = image;
}
QuadArray2D_AddQuad(_quadArray,
x1,y1,u1,v1,
x2,y2,u2,v2,
_color);
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
}
/////////////////////////////
// Draw_DrawImgPart
//
@@ -872,10 +825,14 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int h,int i,int j){
// Apply flipping
if (image->flip & 1) {
float t=u1; u1=u2; u2=t;
float t = u1;
u1 = u2;
u2 = t;
}
if (image->flip & 2) {
float t=v1; v1=v2; v2=t;
float t = v1;
v1 = v2;
v2 = t;
}
// Draw a quad
@@ -883,13 +840,9 @@ void Draw_DrawImgPart(DrawImg img,int x,int y,int w,int h,int i,int j){
Draw_Flush();
_currentImg = image;
}
QuadArray2D_AddQuad(_quadArray,
x1,y1,u1,v1,
x2,y2,u2,v2,
_color);
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
}
/////////////////////////////
// Draw_DrawImgPartHoriz
//
@@ -911,10 +864,14 @@ void Draw_DrawImgPartHoriz(DrawImg img,int x,int y,int w,int i){
// Apply flipping
if (image->flip & 1) {
float t=u1; u1=u2; u2=t;
float t = u1;
u1 = u2;
u2 = t;
}
if (image->flip & 2) {
float t=v1; v1=v2; v2=t;
float t = v1;
v1 = v2;
v2 = t;
}
// Draw a quad
@@ -922,18 +879,16 @@ void Draw_DrawImgPartHoriz(DrawImg img,int x,int y,int w,int i){
Draw_Flush();
_currentImg = image;
}
QuadArray2D_AddQuad(_quadArray,
x1,y1,u1,v1,
x2,y2,u2,v2,
_color);
QuadArray2D_AddQuad(_quadArray, x1, y1, u1, v1, x2, y2, u2, v2, _color);
}
/////////////////////////////
// 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]) {
int paralaxPos[2];
int mult[2];
int x, y;
@@ -942,9 +897,13 @@ void Draw_ImgParallax(DrawImg img, int imgSize[2], int imgOffset[2], float paral
paralaxPos[1] = (gamePos[1] * parallaxFactor[1]) + imgOffset[1];
mult[0] = floor(paralaxPos[0] / imgSize[0]);
if(paralaxPos[0] < 0 ){ mult[0]--; }
if (paralaxPos[0] < 0) {
mult[0]--;
}
mult[1] = floor(paralaxPos[1] / imgSize[1]);
if(paralaxPos[1] < 0 ){ mult[1]--; }
if (paralaxPos[1] < 0) {
mult[1]--;
}
y = (mult[1] * imgSize[1]) - paralaxPos[1];
while (y < gameSize[1]) {
@@ -957,7 +916,6 @@ void Draw_ImgParallax(DrawImg img, int imgSize[2], int imgOffset[2], float paral
}
}
/////////////////////////////
// Draw_SetColor
//
@@ -969,7 +927,6 @@ void Draw_SetColor(float r,float g,float b,float a){
_color[3] = a;
}
////////////////////////////////////////////////
// DrawFnt //
/////////////
@@ -980,18 +937,13 @@ typedef struct {
int min, max;
} DrawFont;
/////////////////////////////
// Draw_DefaultImage
//
// Creates a image with the default font.
#include "FontData.h"
DrawImage Draw_DefaultFontImage(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a)
{
DrawImage Draw_DefaultFontImage(unsigned char r, unsigned char g,
unsigned char b, unsigned char a) {
DrawImage img;
int x, y, c;
@@ -1018,17 +970,12 @@ DrawImage Draw_DefaultFontImage(
return (img);
}
/////////////////////////////
// Draw_DefaultFont
//
// Creates the default font.
DrawFnt Draw_DefaultFont(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a)
{
DrawFnt Draw_DefaultFont(unsigned char r, unsigned char g, unsigned char b,
unsigned char a) {
DrawFont *font;
// Create the default font
@@ -1060,7 +1007,6 @@ DrawFnt Draw_LoadFont(char *fichero,int min,int max){
return ((DrawFnt)font);
}
/////////////////////////////
// Draw_DrawText
//
@@ -1080,7 +1026,6 @@ void Draw_DrawText(DrawFnt f,char *text,int x,int y){
}
}
/////////////////////////////
// Draw_SaveScreenshoot
//
@@ -1092,17 +1037,15 @@ void Draw_SaveScreenshoot(char *filename){
int i, half_height, line_size;
// Create the surface
surf = SDL_CreateRGBSurface(SDL_SWSURFACE,
_width, _height, 32,0,0,0,0);
surf = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, 32, 0, 0, 0, 0);
surf->format->Amask = 0xFF000000;
surf->format->Ashift = 24;
SDL_SetAlpha(surf, SDL_SRCALPHA, 255);
// Get the screenshot
SDL_LockSurface(surf);
glReadPixels(0, 0,
_width, _height, GL_RGBA,
GL_UNSIGNED_BYTE, surf->pixels);
glReadPixels(0, 0, _width, _height, GL_RGBA, GL_UNSIGNED_BYTE,
surf->pixels);
SDL_UnlockSurface(surf);
// Flip the image data
@@ -1111,8 +1054,10 @@ void Draw_SaveScreenshoot(char *filename){
image_line = malloc(line_size);
for (i = 0; i < half_height; i++) {
memcpy(image_line, surf->pixels + i * line_size, line_size);
memcpy(surf->pixels+i*line_size,surf->pixels+(_height-(i+1))*line_size,line_size);
memcpy(surf->pixels+(_height-(i+1))*line_size,image_line,line_size);
memcpy(surf->pixels + i * line_size,
surf->pixels + (_height - (i + 1)) * line_size, line_size);
memcpy(surf->pixels + (_height - (i + 1)) * line_size, image_line,
line_size);
}
// Swap RGB to BGR
@@ -1140,6 +1085,3 @@ void Draw_SaveScreenshoot(char *filename){
SDL_FreeSurface(surf);
#endif
}

View File

@@ -3,82 +3,66 @@
#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);
/////////////////////////////
// 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);
/////////////////////////////
// Draw_LoadImage
//
// 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);
/////////////////////////////
// Draw_SetOffset
// Draw_GetOffset
@@ -87,7 +71,6 @@ void Draw_GetSize(DrawImg img,int *w,int *h);
void Draw_SetOffset(DrawImg img, int x, int y);
void Draw_GetOffset(DrawImg img, int *x, int *y);
/////////////////////////////
// Draw_SetFlip
// Draw_GetFlip
@@ -96,41 +79,36 @@ void Draw_GetOffset(DrawImg img,int *x,int *y);
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);
/////////////////////////////
// Draw_DrawImgResized
//
// Draws an image, resizing.
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);
/////////////////////////////
// Draw_DrawImgPartHoriz
//
// Draws an image part horizontally.
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
@@ -138,44 +116,35 @@ void Draw_ImgParallax(DrawImg img, int imgSize[2], int imgOffset[2], float paral
//
void Draw_SetColor(float r, float g, float b, float a);
////////////////////////////////////////////////
// DrawFnt //
/////////////
// 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);
/////////////////////////////
// Draw_DrawText
//
// Draws text using a font
void Draw_DrawText(DrawFnt f, char *text, int x, int y);
/////////////////////////////
// Draw_SaveScreenshoot
//
//
void Draw_SaveScreenshoot(char *filename);
#endif

View File

@@ -10,15 +10,11 @@
#include "Entity.h"
#define EntityIntFlag_UpdateLight 1
#define EntityIntFlag_UpdatedPos 2
#define EntityIntFlag_UpdatedColor 4
#define EntityIntFlag_UpdateColor 8
/////////////////////////////
// Entity_New
//
@@ -82,8 +78,8 @@ Entity Entity_New(){
e->color[0] = e->color[1] = e->color[2] = e->color[3] = 1.0f;
e->light[0] = e->light[1] = e->light[2] = e->light[3] = 1.0f;
e->defaultColor[0]=e->defaultColor[1]=
e->defaultColor[2]=e->defaultColor[3]=1.0f;
e->defaultColor[0] = e->defaultColor[1] = e->defaultColor[2] =
e->defaultColor[3] = 1.0f;
e->oncopy = NULL;
e->oninit = NULL;
@@ -104,7 +100,6 @@ Entity Entity_New(){
return (e);
}
/////////////////////////////
// Entity_Init
//
@@ -114,7 +109,6 @@ Entity Entity_Init(Entity e){
}
}
/////////////////////////////
// Entity_Destroy
//
@@ -127,7 +121,6 @@ void Entity_Destroy(Entity e){
_free_entity = e;
}
/////////////////////////////
// Entity_Copy
//
@@ -198,7 +191,6 @@ Entity Entity_Copy(Entity e){
return (n);
}
/////////////////////////////
// Entity_CalcBBox
//
@@ -224,21 +216,18 @@ void Entity_CalcBBox(Entity e){
}
}
/////////////////////////////
// Entity_BBoxIntersect
//
//
int Entity_BBoxIntersect(Entity ent1, Entity ent2) {
if (ent1->maxX >= ent2->minX && ent1->minX <= ent2->maxX &&
ent1->maxY>=ent2->minY && ent1->minY<=ent2->maxY )
{
ent1->maxY >= ent2->minY && ent1->minY <= ent2->maxY) {
return (1);
}
return (0);
}
/////////////////////////////
// Entity_Draw
//
@@ -246,12 +235,10 @@ int Entity_BBoxIntersect(Entity ent1,Entity ent2){
void Entity_Draw(Entity e, int x, int y, float f) {
vec2 fPos;
if (e->internalFlags & EntityIntFlag_UpdatedColor) {
Draw_SetColor(
e->color0[0]-f*(e->color0[0]-e->color[0]),
Draw_SetColor(e->color0[0] - f * (e->color0[0] - e->color[0]),
e->color0[1] - f * (e->color0[1] - e->color[1]),
e->color0[2] - f * (e->color0[2] - e->color[2]),
e->color0[3]-f*(e->color0[3]-e->color[3])
);
e->color0[3] - f * (e->color0[3] - e->color[3]));
} else {
Draw_SetColor(e->color[0], e->color[1], e->color[2], e->color[3]);
}
@@ -263,7 +250,6 @@ void Entity_Draw(Entity e,int x,int y,float f){
}
}
/////////////////////////////
// Entity_IsVisible
//
@@ -280,18 +266,13 @@ int Entity_IsVisible(Entity e,int x,int y,int w,int h){
ymin = y - ih;
ymax = y + h + ih;
if(e->pos[0]<xmin ||
e->pos[0]>xmax ||
e->pos[1]<ymin ||
e->pos[1]>ymax)
{
if (e->pos[0] < xmin || e->pos[0] > xmax || e->pos[1] < ymin ||
e->pos[1] > ymax) {
return (0);
}
return (1);
}
/////////////////////////////
// Entity_Process
//
@@ -305,7 +286,6 @@ void Entity_Process(Entity b,int ft){
}
}
/////////////////////////////
// Entity_PostProcess
//
@@ -335,8 +315,8 @@ void Entity_PostProcess(Entity e,int ft){
vec2_set(e->vel, 0, 0);
} else {
// Apply dynamic friction
vec2_scale(e->vel,e->vel,
1.0f-(e->backFric_dynamic+(e->backFric_static/len)));
vec2_scale(e->vel, e->vel, 1.0f - (e->backFric_dynamic +
(e->backFric_static / len)));
}
// Mark the update of the position.
@@ -355,13 +335,13 @@ void Entity_PostProcess(Entity e,int ft){
AnimPlay_IncTime(&e->anim, ft);
}
/////////////////////////////
// CollisionInfo_New
//
//
CollisionInfo _free_collInfo = NULL;
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 collInfo;
if (!_free_collInfo) {
@@ -382,13 +362,14 @@ CollisionInfo CollisionInfo_New(int responseType,Entity ent1,Entity ent2,float t
return collInfo;
}
/////////////////////////////
// CollisionInfo_Destroy
//
//
void CollisionInfo_Destroy(CollisionInfo *collInfoRef) {
if(collInfoRef==NULL || collInfoRef[0]==NULL){return;}
if (collInfoRef == NULL || collInfoRef[0] == NULL) {
return;
}
CollisionInfo collInfo = collInfoRef[0];
CollisionInfo nextCollInfo;
@@ -401,18 +382,20 @@ void CollisionInfo_Destroy(CollisionInfo *collInfoRef){
collInfoRef[0] = NULL;
}
/////////////////////////////
// CollisionInfo_Add
//
//
void CollisionInfo_Add(CollisionInfo *collInfoRef,
int responseType,Entity ent1,Entity ent2,float t,vec2 n,int applyFriction)
{
if(collInfoRef==NULL){return;}
void CollisionInfo_Add(CollisionInfo *collInfoRef, int responseType,
Entity ent1, Entity ent2, float t, vec2 n,
int applyFriction) {
if (collInfoRef == NULL) {
return;
}
CollisionInfo prevCollInfo = NULL;
CollisionInfo collInfo = collInfoRef[0];
CollisionInfo newCollInfo=CollisionInfo_New(responseType,ent1,ent2,t,n,applyFriction);
CollisionInfo newCollInfo =
CollisionInfo_New(responseType, ent1, ent2, t, n, applyFriction);
while (collInfo != NULL && collInfo->t < t) {
prevCollInfo = collInfo;
@@ -426,17 +409,15 @@ void CollisionInfo_Add(CollisionInfo *collInfoRef,
newCollInfo->next = collInfo;
}
/////////////////////////////
// CollisionInfo_CheckRepetition
//
//
int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2)
{
int CollisionInfo_CheckRepetition(CollisionInfo collInfo, Entity ent1,
Entity ent2) {
while (collInfo != NULL) {
if ((collInfo->ent1 == ent1 && collInfo->ent2 == ent2) ||
(collInfo->ent1==ent2 && collInfo->ent2==ent1))
{
(collInfo->ent1 == ent2 && collInfo->ent2 == ent1)) {
return (1);
}
collInfo = collInfo->next;
@@ -444,18 +425,17 @@ int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2
return (0);
}
/////////////////////////////
// Entity_CheckCollisions
//
//
int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
int Entity_CheckCollision(Entity ent1, Entity ent2,
CollisionInfo *collInfoRef) {
float t;
vec2 n;
vec2 vel;
int flags = ent1->flags | ent2->flags;
if (flags & EntityFlag_Block) {
// One of the entities is a block and none is a platform
Entity ent, ent_block;
@@ -467,8 +447,7 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if (ent1->mass <= 0.0f && ent2->mass > 0.0f) {
ent = ent2;
ent_block = ent1;
}else
if(ent2->mass<=0.0f && ent1->mass>0.0f){
} else if (ent2->mass <= 0.0f && ent1->mass > 0.0f) {
ent = ent1;
ent_block = ent2;
} else {
@@ -482,11 +461,11 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if (flags & EntityFlag_BlockTop) {
vec2_set(auxN, 0, -1);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->height+ent_block->height)/2);
vec2_scaleadd(p, ent_block->pos, auxN,
(ent->height + ent_block->height) / 2);
block_len = ent_block->width + ent->width;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if (Intersect_RayEdge(ent->pos, ent->vel, auxN, p, block_len,
&auxT)) {
if (auxT < t) {
vec2_copy(n, auxN);
t = auxT;
@@ -497,11 +476,11 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if (flags & EntityFlag_BlockBottom) {
vec2_set(auxN, 0, 1);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->height+ent_block->height)/2);
vec2_scaleadd(p, ent_block->pos, auxN,
(ent->height + ent_block->height) / 2);
block_len = ent_block->width + ent->width;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if (Intersect_RayEdge(ent->pos, ent->vel, auxN, p, block_len,
&auxT)) {
if (auxT < t) {
vec2_copy(n, auxN);
t = auxT;
@@ -512,11 +491,11 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if (flags & EntityFlag_BlockRight) {
vec2_set(auxN, 1, 0);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->width+ent_block->width)/2);
vec2_scaleadd(p, ent_block->pos, auxN,
(ent->width + ent_block->width) / 2);
block_len = ent_block->height + ent->height;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if (Intersect_RayEdge(ent->pos, ent->vel, auxN, p, block_len,
&auxT)) {
if (auxT < t) {
vec2_copy(n, auxN);
t = auxT;
@@ -527,11 +506,11 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
if (flags & EntityFlag_BlockLeft) {
vec2_set(auxN, -1, 0);
vec2_scaleadd(p,ent_block->pos,auxN,(ent->width+ent_block->width)/2);
vec2_scaleadd(p, ent_block->pos, auxN,
(ent->width + ent_block->width) / 2);
block_len = ent_block->height + ent->height;
if(Intersect_RayEdge(ent->pos,ent->vel,
auxN,p,block_len,&auxT))
{
if (Intersect_RayEdge(ent->pos, ent->vel, auxN, p, block_len,
&auxT)) {
if (auxT < t) {
vec2_copy(n, auxN);
t = auxT;
@@ -541,8 +520,8 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
}
if (t < 1.0f) {
CollisionInfo_Add(collInfoRef,
CollisionResponse_Line,ent,ent_block,t,n,applyFriction);
CollisionInfo_Add(collInfoRef, CollisionResponse_Line, ent,
ent_block, t, n, applyFriction);
return (1);
}
@@ -551,22 +530,20 @@ int Entity_CheckCollision(Entity ent1,Entity ent2,CollisionInfo *collInfoRef){
// Circle-Circle test from ent1
vec2_minus(vel, ent1->vel, ent2->vel);
if(Colision_CircleCircle(ent1->pos,ent1->radius,vel,ent2->pos,ent2->radius,&t,n)){
CollisionInfo_Add(collInfoRef,
CollisionResponse_Circle,ent1,ent2,t,n,0);
if (Colision_CircleCircle(ent1->pos, ent1->radius, vel, ent2->pos,
ent2->radius, &t, n)) {
CollisionInfo_Add(collInfoRef, CollisionResponse_Circle, ent1, ent2, t,
n, 0);
return (1);
}
return (0);
}
/////////////////////////////
// Entity_CollisionResponseCircle
//
// Normal response to a collision between circles.
void Entity_CollisionResponseCircle(
Entity b1,Entity b2,float t,vec2 n)
{
void Entity_CollisionResponseCircle(Entity b1, Entity b2, float t, vec2 n) {
float moment;
vec2 temp;
float elast;
@@ -578,28 +555,24 @@ void Entity_CollisionResponseCircle(
// Collision between two massed balls
moment = ((1.0f + elast) * b1->mass * b2->mass *
(fabs(vec2_dot(b1->vel,n))+fabs(vec2_dot(b2->vel,n))))
/(b1->mass+b2->mass);
(fabs(vec2_dot(b1->vel, n)) + fabs(vec2_dot(b2->vel, n)))) /
(b1->mass + b2->mass);
vec2_scale(temp, n, moment / b1->mass);
vec2_minus(b1->vel, b1->vel, temp);
Entity_CalcBBox(b1);
vec2_scale(temp, n, moment / b2->mass);
vec2_plus(b2->vel, b2->vel, temp);
Entity_CalcBBox(b2);
}else
if(b1->mass>0.0f && b2->mass<=0.0f){
} else if (b1->mass > 0.0f && b2->mass <= 0.0f) {
// Collision between a massed ball and a fixed ball
moment=(1.0f+b1->elast)*
(vec2_dot(b1->vel,n));
moment = (1.0f + b1->elast) * (vec2_dot(b1->vel, n));
vec2_scale(temp, n, moment);
vec2_minus(b1->vel, b1->vel, temp);
Entity_CalcBBox(b1);
}else
if(b1->mass<=0.0f && b2->mass>0.0f){
} else if (b1->mass <= 0.0f && b2->mass > 0.0f) {
// Collision between a massed ball and a fixed ball
// (imposible, but better safe)
moment=(1.0f+b2->elast)*
(vec2_dot(b2->vel,n));
moment = (1.0f + b2->elast) * (vec2_dot(b2->vel, n));
vec2_scale(temp, n, moment);
vec2_plus(b2->vel, b2->vel, temp);
Entity_CalcBBox(b2);
@@ -613,14 +586,12 @@ void Entity_CollisionResponseCircle(
}
}
/////////////////////////////
// Entity_CollisionResponseLine
//
// Normal response to a collision with a line.
void Entity_CollisionResponseLine(
Entity ent,Entity ent2,float t,vec2 norm,int applyFriction)
{
void Entity_CollisionResponseLine(Entity ent, Entity ent2, float t, vec2 norm,
int applyFriction) {
vec2 pos2, vel2, velFric, intersection;
float dist, fric_static, fric_dynamic, fricLen;
@@ -650,8 +621,7 @@ void Entity_CollisionResponseLine(
vec2_scaleadd(pos2, intersection, velFric,
1.0f - (fric_dynamic + (fric_static / fricLen)));
} else {
vec2_scaleadd(pos2,intersection,velFric,
1.0f-fric_dynamic);
vec2_scaleadd(pos2, intersection, velFric, 1.0f - fric_dynamic);
}
}
}
@@ -663,7 +633,6 @@ void Entity_CollisionResponseLine(
Entity_CalcBBox(ent);
}
/////////////////////////////
// Entity_CollisionInfoResponse
//
@@ -680,14 +649,16 @@ int Entity_CollisionInfoResponse(CollisionInfo collInfo){
// Check the collision methods
if (collInfo->ent1->collision) {
rc=collInfo->ent1->collision(collInfo->ent1,collInfo->ent2,collInfo->t,n1);
rc = collInfo->ent1->collision(collInfo->ent1, collInfo->ent2,
collInfo->t, n1);
if (rc == 0)
response = 0;
if (rc > 1)
response = 2;
}
if (collInfo->ent2->collision) {
rc=collInfo->ent2->collision(collInfo->ent2,collInfo->ent1,collInfo->t,n2);
rc = collInfo->ent2->collision(collInfo->ent2, collInfo->ent1,
collInfo->t, n2);
if (rc == 0)
response = 0;
if (rc > 1)
@@ -697,16 +668,17 @@ int Entity_CollisionInfoResponse(CollisionInfo collInfo){
// Collision response
if (response == 1) {
if (collInfo->responseType == CollisionResponse_Line) {
Entity_CollisionResponseLine(
collInfo->ent1,collInfo->ent2,collInfo->t,collInfo->n,collInfo->applyFriction);
}else
if(collInfo->responseType==CollisionResponse_Circle){
Entity_CollisionResponseLine(collInfo->ent1, collInfo->ent2,
collInfo->t, collInfo->n,
collInfo->applyFriction);
} else if (collInfo->responseType == CollisionResponse_Circle) {
if (vec2_dot(collInfo->ent1->vel, collInfo->ent1->vel) >
vec2_dot(collInfo->ent2->vel,collInfo->ent2->vel))
{
Entity_CollisionResponseCircle(collInfo->ent1,collInfo->ent2,collInfo->t,n2);
vec2_dot(collInfo->ent2->vel, collInfo->ent2->vel)) {
Entity_CollisionResponseCircle(
collInfo->ent1, collInfo->ent2, collInfo->t, n2);
} else {
Entity_CollisionResponseCircle(collInfo->ent2,collInfo->ent1,collInfo->t,n1);
Entity_CollisionResponseCircle(
collInfo->ent2, collInfo->ent1, collInfo->t, n1);
}
}
return (1);
@@ -720,7 +692,6 @@ int Entity_CollisionInfoResponse(CollisionInfo collInfo){
return (0);
}
/////////////////////////////
// Entity_Overlaps
//
@@ -732,30 +703,22 @@ void Entity_Overlaps(Entity b1,Entity b2){
vec2_set(len, fabs(b1->pos[0] - b2->pos[0]), fabs(b1->pos[1] - b2->pos[1]));
if (b1->overlap) {
if( len[0]<=b1->radius &&
len[1]<=b1->radius)
{
if (len[0] <= b1->radius && len[1] <= b1->radius) {
b1->overlap(b1, b2);
}
}
if (b2->overlap) {
if( len[0]<=b2->radius &&
len[1]<=b2->radius)
{
if (len[0] <= b2->radius && len[1] <= b2->radius) {
b2->overlap(b2, b1);
}
}
}
/////////////////////////////
// Entity_GetPos
//
//
void Entity_GetPos(Entity e,vec2 pos){
vec2_copy(pos,e->pos);
}
void Entity_GetPos(Entity e, vec2 pos) { vec2_copy(pos, e->pos); }
/////////////////////////////
// Entity_SetPos
@@ -768,7 +731,6 @@ void Entity_SetPos(Entity e,vec2 pos){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_AddPos
//
@@ -780,7 +742,6 @@ void Entity_AddPos(Entity e,vec2 pos){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_UpdatePos
//
@@ -794,7 +755,6 @@ void Entity_UpdatePos(Entity e,vec2 pos){
vec2_copy(e->pos, pos);
}
/////////////////////////////
// Entity_AddVel
//
@@ -803,7 +763,6 @@ void Entity_AddVel(Entity e,vec2 vel){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_SetVel
//
@@ -812,7 +771,6 @@ void Entity_SetVel(Entity e,vec2 vel){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_SetVelH
//
@@ -821,7 +779,6 @@ void Entity_SetVelH(Entity e,float v){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_SetVelV
//
@@ -830,7 +787,6 @@ void Entity_SetVelV(Entity e,float v){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_AddVelLimit
//
@@ -856,7 +812,6 @@ void Entity_AddVelLimit(Entity e,vec2 vel,float limit){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_AddVelLimitH
//
@@ -874,7 +829,6 @@ void Entity_AddVelLimitH(Entity e,float v,float limit){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_AddVelLimitH
//
@@ -892,7 +846,6 @@ void Entity_AddVelLimitV(Entity e,float v,float limit){
Entity_CalcBBox(e);
}
/////////////////////////////
// Entity_SetColor
//
@@ -909,7 +862,6 @@ void Entity_SetColor(Entity e,float r,float g,float b,float a){
e->internalFlags &= ~EntityIntFlag_UpdatedColor;
}
/////////////////////////////
// Entity_AddColor
//
@@ -942,7 +894,6 @@ void Entity_MultColor(Entity e,float r,float g,float b,float a){
e->internalFlags |= EntityIntFlag_UpdatedColor;
}
/////////////////////////////
// Entity_SetLight
//
@@ -958,7 +909,6 @@ void Entity_SetLight(Entity e,float r,float g,float b,float rad){
}
}
/////////////////////////////
// Entity_SetDefaultColor
//
@@ -970,7 +920,6 @@ void Entity_SetDefaultColor(Entity e,float r,float g,float b,float a){
e->defaultColor[3] = a;
}
/////////////////////////////
// Entity_Iluminate
//
@@ -982,11 +931,8 @@ void Entity_Iluminate(Entity e,Entity *elist,int n){
float qrad;
if (e->flags & EntityFlag_Light) {
Entity_SetColor(e,
e->defaultColor[0],
e->defaultColor[1],
e->defaultColor[2],
e->defaultColor[3]);
Entity_SetColor(e, e->defaultColor[0], e->defaultColor[1],
e->defaultColor[2], e->defaultColor[3]);
return;
}
@@ -1004,19 +950,13 @@ void Entity_Iluminate(Entity e,Entity *elist,int n){
qrad = elist[i]->light[3] * elist[i]->light[3];
if (qdist < qrad) {
f = 1.0f - qdist / qrad;
Entity_AddColor(e,
f*elist[i]->light[0],
f*elist[i]->light[1],
f*elist[i]->light[2],
0.0f);
Entity_AddColor(e, f * elist[i]->light[0], f * elist[i]->light[1],
f * elist[i]->light[2], 0.0f);
}
}
Entity_MultColor(e,
e->defaultColor[0],
e->defaultColor[1],
e->defaultColor[2],
e->defaultColor[3]);
Entity_MultColor(e, e->defaultColor[0], e->defaultColor[1],
e->defaultColor[2], e->defaultColor[3]);
e->internalFlags &= ~EntityIntFlag_UpdateLight;
if (e->internalFlags & EntityIntFlag_UpdateColor) {
@@ -1028,7 +968,6 @@ void Entity_Iluminate(Entity e,Entity *elist,int n){
}
}
/////////////////////////////
// Entity_MarkUpdateLight
//
@@ -1053,12 +992,9 @@ void Entity_MarkUpdateLight(Entity e,Entity *elist,int n){
max[1] = e->pos0[1] + e->light[3];
}
for (i = 0; i < n; i++) {
if( elist[i]!=NULL &&
min[0]<=elist[i]->pos0[0] &&
max[0]>=elist[i]->pos0[0] &&
min[1]<=elist[i]->pos0[1] &&
max[1]>=elist[i]->pos0[1])
{
if (elist[i] != NULL && min[0] <= elist[i]->pos0[0] &&
max[0] >= elist[i]->pos0[0] && min[1] <= elist[i]->pos0[1] &&
max[1] >= elist[i]->pos0[1]) {
elist[i]->internalFlags |= EntityIntFlag_UpdateLight;
}
}
@@ -1067,14 +1003,10 @@ void Entity_MarkUpdateLight(Entity e,Entity *elist,int n){
}
}
/////////////////////////////
// Entity_IsLight
//
int Entity_IsLight(Entity e){
return (e->flags&EntityFlag_Light);
}
int Entity_IsLight(Entity e) { return (e->flags & EntityFlag_Light); }
/////////////////////////////
// Entity_IsUpdateLight
@@ -1083,13 +1015,9 @@ int Entity_IsUpdateLight(Entity e){
return (e->internalFlags & EntityIntFlag_UpdateLight);
}
/////////////////////////////
// Entity_IsMoving
//
int Entity_IsMoving(Entity e) {
return (e->internalFlags & EntityIntFlag_UpdatedPos);
}

View File

@@ -7,7 +7,6 @@
#include "Draw.h"
#include "Anim.h"
////////////////////////////////////////////////
// Entity
//
@@ -77,69 +76,58 @@ struct TEntity {
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);
/////////////////////////////
// Entity_Draw
//
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);
/////////////////////////////
// Entity_Process
//
void Entity_Process(Entity e, int ft);
/////////////////////////////
// Entity_PostProcess
//
void Entity_PostProcess(Entity e, int ft);
////////////////////////////////////////////////
// CollisionInfo
//
@@ -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,21 +158,19 @@ 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
@@ -193,22 +178,18 @@ int CollisionInfo_CheckRepetition(CollisionInfo collInfo,Entity ent1,Entity ent2
//
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);
/////////////////////////////
// Entity_GetPos
//
void Entity_GetPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_SetPos
//
//
void Entity_SetPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_AddPos
//
//
void Entity_AddPos(Entity e, vec2 pos);
/////////////////////////////
// Entity_UpdatePos
//
void Entity_UpdatePos(Entity e, vec2 pos);
/////////////////////////////
// Entity_AddVel
//
void Entity_AddVel(Entity e, vec2 vel);
/////////////////////////////
// Entity_SetVel
//
void Entity_SetVel(Entity e, vec2 vel);
/////////////////////////////
// Entity_SetVelH
//
void Entity_SetVelH(Entity e, float v);
/////////////////////////////
// Entity_SetVelV
//
void Entity_SetVelV(Entity e, float v);
/////////////////////////////
// Entity_AddVelLimit
//
void Entity_AddVelLimit(Entity e, vec2 vel, float limit);
/////////////////////////////
// Entity_AddVelLimitH
//
void Entity_AddVelLimitH(Entity e, float v, float limit);
/////////////////////////////
// Entity_AddVelLimitH
//
void Entity_AddVelLimitV(Entity e, float v, float limit);
/////////////////////////////
// Entity_SetColor
//
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);
/////////////////////////////
// Entity_MultColor
//
//
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);
/////////////////////////////
// Entity_SetDefaultColor
//
void Entity_SetDefaultColor(Entity e, float r, float g, float b, float a);
/////////////////////////////
// Entity_Iluminate
//
void Entity_Iluminate(Entity e, Entity *elist, int n);
/////////////////////////////
// Entity_MarkUpdateLight
//
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

@@ -53,7 +53,6 @@ int _nParallaxBackgrounds=0;
int gamelib_debug = 0;
/////////////////////////////
// GameLib_Init
//
@@ -79,7 +78,6 @@ int GameLib_Init(int w,int h,char *title,int pfps,int fps){
return (1);
}
/////////////////////////////
// GameLib_AddEntity
//
@@ -122,7 +120,6 @@ void GameLib_AddEntity(Entity e){
Entity_Init(e);
}
/////////////////////////////
// GameLib_UnrefEntity
//
@@ -148,7 +145,6 @@ int GameLib_UnrefEntity(Entity e){
return (-1);
}
/////////////////////////////
// GameLib_DelEntity
//
@@ -169,7 +165,6 @@ int GameLib_DelEntity(Entity e){
return (1);
}
/////////////////////////////
// GameLib_Compactate
//
@@ -196,7 +191,6 @@ void GameLib_Compactate(){
_entities_compactate = 0;
}
/////////////////////////////
// GameLib_ProcLoop
//
@@ -233,19 +227,18 @@ void GameLib_ProcLoop(void *data){
repeat = 0;
CollisionInfo collInfo = NULL;
for (i = 0; i < _n_entities; i++) {
if(!(_entity[i]->flags&EntityFlag_Collision) || _entity[i]->mass<0.0f)
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)
{
_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]))
{
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);
@@ -261,13 +254,12 @@ void GameLib_ProcLoop(void *data){
// 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 (!(_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]))
{
if (i == j || !(_entity[j]->flags & EntityFlag_Collision) ||
!Entity_BBoxIntersect(_entity[i], _entity[j])) {
continue;
}
if (Entity_CheckCollision(_entity[i], _entity[j], NULL)) {
@@ -287,7 +279,8 @@ void GameLib_ProcLoop(void *data){
time = Time_GetTime();
_entities_lock = 1;
for (i = 0; i < _n_entities; i++) {
if(!(_entity[i]->flags&EntityFlag_Overlap) || _entity[i]->mass<0.0f)
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)
@@ -311,8 +304,7 @@ void GameLib_ProcLoop(void *data){
if (ent1->zorder > ent2->zorder) {
// Lower level
swap = 1;
}else
if(ent1->zorder < ent2->zorder){
} else if (ent1->zorder < ent2->zorder) {
// Upper level
} else {
// Same level
@@ -352,7 +344,6 @@ void GameLib_ProcLoop(void *data){
fproc_count++;
}
/////////////////////////////
// GameLib_DrawLoop
//
@@ -379,12 +370,9 @@ void GameLib_DrawLoop(void *data, float f){
// Draw parallax backgrounds
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
@@ -393,10 +381,8 @@ void GameLib_DrawLoop(void *data, float f){
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;
}
@@ -420,8 +406,7 @@ void GameLib_DrawLoop(void *data, float f){
fdraw_count++;
if (Input_GetKey(InputKey_DumpProfiling) == InputKey_Pressed &&
fproc_count>0 && fdraw_count>0)
{
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);
@@ -438,17 +423,12 @@ void GameLib_DrawLoop(void *data, float f){
}
}
/////////////////////////////
// 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)) {
_gameproc = gameproc;
_gamepostproc = gamepostproc;
_gamepredraw = gamepredraw;
@@ -463,7 +443,6 @@ void GameLib_Loop(
Draw_Loop(GameLib_ProcLoop, GameLib_DrawLoop, NULL);
}
/////////////////////////////
// GameLib_GetPos
// GameLib_SetPos
@@ -495,9 +474,6 @@ void GameLib_GetPosInstant(int pos[2],float f){
pos[1] = _game_pos0[1] + f * (_game_pos1[1] - _game_pos0[1]);
}
/////////////////////////////
// GameLib_MoveToPos
// GameLib_MoveToPosH
@@ -509,15 +485,14 @@ void GameLib_MoveToPos(vec2 pos,float 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;
_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;
_game_pos1[1] =
_game_pos1[1] + (pos[1] - (_game_pos1[1] + (_game_size[1] / 2.0f))) * f;
}
/////////////////////////////
// GameLib_ForEachEn
//
@@ -533,7 +508,6 @@ void GameLib_DelEnts(){
_n_entities = 0;
}
/////////////////////////////
// GameLib_ForEachEn
//
@@ -549,7 +523,6 @@ void GameLib_ForEachEnt(int (*func)(Entity ent)){
}
}
/////////////////////////////
// GameLib_SearchEnt
//
@@ -568,7 +541,6 @@ Entity GameLib_SearchEnt(int (*func)(Entity ent,void *d),void *d){
return ent;
}
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//
@@ -585,8 +557,7 @@ int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel){
for (j = 0; j < _n_entities; j++) {
if (!(_entity[j]->flags & EntityFlag_Collision) ||
!Entity_BBoxIntersect(ent,_entity[j]))
{
!Entity_BBoxIntersect(ent, _entity[j])) {
continue;
}
Entity_CheckCollision(ent, _entity[j], &collInfo);
@@ -603,7 +574,6 @@ int GameLib_EntityCustomCheckCollision(Entity ent,vec2 vel){
return collision;
}
/////////////////////////////
// GameLib_PlaySound
//
@@ -644,7 +614,6 @@ void GameLib_PlaySound(AudioSnd snd,int x,int y){
Audio_PlaySound(snd, vleft, vright, 0);
}
/////////////////////////////
// GameLib_PlayLoopingSound
//
@@ -654,7 +623,6 @@ AudioChn GameLib_PlayLoopingSound(AudioSnd snd){
return Audio_PlaySound(snd, 1.0f, 1.0f, 1);
}
/////////////////////////////
// GameLib_EntitySetLight
//
@@ -669,14 +637,11 @@ 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) {
float f;
int game_pos[2];
@@ -687,12 +652,12 @@ void GameLib_ConvertScreenPositionToGamePosition(
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) {
Print("GameLib: Can't add parallaxBackground, limit reached.");
@@ -708,12 +673,8 @@ void GameLib_AddParallaxBackground(DrawImg img, int imgSize[2], int imgOffset[2]
_nParallaxBackgrounds++;
}
/////////////////////////////
// GameLib_CleanParallaxBackgrounds
//
//
void GameLib_CleanParallaxBackgrounds(){
_nParallaxBackgrounds=0;
}
void GameLib_CleanParallaxBackgrounds() { _nParallaxBackgrounds = 0; }

View File

@@ -11,45 +11,36 @@
#include "Anim.h"
#include "Entity.h"
/////////////////////////////
// GameLib_Init
//
// Initializes the game.
int GameLib_Init(int w, int h, char *title, int pfps, int fps);
/////////////////////////////
// GameLib_AddEntity
//
// 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
@@ -65,7 +56,6 @@ void GameLib_UpdatePos(int pos[2]);
void GameLib_GetSize(int size[2]);
void GameLib_GetPosInstant(int pos[2], float f);
/////////////////////////////
// GameLib_MoveToPos
// GameLib_MoveToPosH
@@ -76,70 +66,60 @@ void GameLib_MoveToPos(vec2 pos,float f);
void GameLib_MoveToPosH(vec2 pos, float f);
void GameLib_MoveToPosV(vec2 pos, float f);
/////////////////////////////
// GameLib_ForEachEn
//
// 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);
/////////////////////////////
// GameLib_EntityCustomCheckCollision
//
//
int GameLib_EntityCustomCheckCollision(Entity ent, vec2 vel);
/////////////////////////////
// GameLib_PlaySound
//
// Play a sound position aware.
void GameLib_PlaySound(AudioSnd snd, int x, int y);
/////////////////////////////
// GameLib_PlayLoopingSound
//
// Play a sound looping
AudioChn GameLib_PlayLoopingSound(AudioSnd snd);
/////////////////////////////
// GameLib_EntitySetLight
//
//
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,8 +9,6 @@
#include "Util.h"
#include "Input.h"
// Globals
InputKeyStatus _keys[InputKey_Max];
@@ -22,7 +20,6 @@ int _clicked=0;
float _clickedPositionX = 0;
float _clickedPositionY = 0;
/////////////////////////////
// Input_Init
//
@@ -38,7 +35,6 @@ int Input_Init(){
return (1);
}
/////////////////////////////
// Input_Frame
//
@@ -57,12 +53,12 @@ void Input_Frame(){
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_Continue,
keys[SDLK_RETURN] | keys[SDLK_KP_ENTER] | _pointerDown);
Input_SetKey(InputKey_DumpProfiling, keys[SDLK_p]);
}
/////////////////////////////
// Input_PostFrame
//
@@ -72,7 +68,6 @@ void Input_PostFrame(){
_clicked = 0;
}
/////////////////////////////
// Input_SetKey
//
@@ -89,15 +84,11 @@ void Input_SetKey(InputKey key,int status){
}
}
/////////////////////////////
// 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
@@ -107,7 +98,6 @@ void Input_SetPointerPosition(float x, float y){
_pointerY = y;
}
/////////////////////////////
// Input_SetPointerDown
//
@@ -120,7 +110,6 @@ void Input_SetPointerDown(int pointerDown){
_pointerDown = pointerDown;
}
/////////////////////////////
// Input_GetPointerPosition
//
@@ -130,7 +119,6 @@ int Input_GetPointerPosition(vec2 pointer){
return _pointerDown;
}
/////////////////////////////
// Input_GetClickedPosition
//
@@ -140,7 +128,6 @@ int Input_GetClickedPosition(vec2 clickPosition){
return _clicked;
}
/////////////////////////////
// Input_AnyKey
//
@@ -155,7 +142,6 @@ int Input_AnyKey(){
return (0);
}
/////////////////////////////
// Input_GetDir
//

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,14 +43,12 @@ typedef enum {
InputKey_Max
} InputKey;
/////////////////////////////
// Input_SetKey
//
// Notify a key press to the input subsystem.
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,7 +6,6 @@
#include "QuadArray2D.h"
QuadArray2D QuadArray2D_Create(int resVertex) {
QuadArray2D quadArray = NULL;
@@ -20,24 +19,24 @@ QuadArray2D QuadArray2D_Create(int resVertex){
}
void QuadArray2D_Destroy(QuadArray2D *quadArray) {
if(!quadArray) return;
if(!quadArray[0]) return;
if (!quadArray)
return;
if (!quadArray[0])
return;
free(quadArray[0]->vertexData);
free(quadArray[0]);
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) {
// Grow vertexData
quadArray->resVertex *= 2;
float *newVertexData=malloc(sizeof(float)*Vertex2D_Length*
quadArray->resVertex);
float *newVertexData =
malloc(sizeof(float) * Vertex2D_Length * quadArray->resVertex);
memcpy(newVertexData, quadArray->vertexData,
sizeof(float) * Vertex2D_Length * quadArray->nVertex);
free(quadArray->vertexData);
@@ -45,18 +44,14 @@ void QuadArray2D_AddVertex(QuadArray2D quadArray,float v[]){
}
// 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;
@@ -67,12 +62,35 @@ void QuadArray2D_AddQuad(QuadArray2D quadArray,
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,7 +16,6 @@ struct TQuadArray2D {
int resVertex;
};
QuadArray2D QuadArray2D_Create(int resVertex);
void QuadArray2D_Destroy(QuadArray2D *quadArray);
@@ -26,10 +24,8 @@ void QuadArray2D_Clean(QuadArray2D quadArray);
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
//
@@ -61,5 +60,3 @@ void Time_Pause(int pausa){
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,7 +8,6 @@
#include "Util.h"
/////////////////////////////
// SolveQuadratic
//
@@ -34,7 +33,6 @@ int SolveQuadratic(float a,float b,float c,float *Rmin,float *Rmax){
return (1);
}
////////////////////////////////////////////////
// vec2 //
//////////
@@ -100,7 +98,6 @@ void vec2_orthogonalize8(vec2 v) {
}
}
/////////////////////////////
// Intersec_RayUnitCircle
//
@@ -136,16 +133,12 @@ int Intersec_RayUnitCircle(vec2 orig,vec2 vel,vec2 center,float *t){
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)
{
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;
@@ -187,16 +180,12 @@ int Colision_CircleCircle(
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)
{
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;
@@ -232,7 +221,6 @@ int Intersect_RayEdge(
return (0);
}
/////////////////////////////
// absmod
//
@@ -254,7 +242,6 @@ float fabsmod(float v,int d){
}
}
/////////////////////////////
// IsBigEndian
//
@@ -266,7 +253,6 @@ int IsBigEndian(){
return bint.c[0] == 1;
}
/////////////////////////////
// EndsWith
//
@@ -280,7 +266,6 @@ int EndsWith(char *str, char *suffix){
return strncmp(str + lenStr - lenSuffix, suffix, lenSuffix) == 0;
}
/////////////////////////////
// Rand
//
@@ -356,7 +341,6 @@ unsigned Rand_Get() {
return (val);
}
/////////////////////////////
// Print
//
@@ -374,4 +358,3 @@ int Print(char *fmt, ...) {
fflush(stdout);
return (n);
}

View File

@@ -12,21 +12,34 @@
// Solves a Quadratic equation using a, b and c coeficients.
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_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_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]); \
@@ -34,53 +47,42 @@ float vec2_norm(vec2 v);
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);
/////////////////////////////
// Intersect_CircleCircle
//
// Colision point of a circle against another circle.
int Colision_CircleCircle(
vec2 cir1,float ra,vec2 vel,
vec2 cb,float rb,
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);
/////////////////////////////
// IsBigEndian
//
int IsBigEndian();
/////////////////////////////
// EndsWith
//
int EndsWith(char *str, char *suffix);
/////////////////////////////
// Rand
//
@@ -88,12 +90,10 @@ void Rand_Seed(unsigned seed);
unsigned Rand_Get();
#define Rand_GetFloat(x) (((float)(Rand_Get() % 1048576)) / 1048576.0f)
/////////////////////////////
// Print
//
// Prints the formated text
int Print(char *fmt, ...);
#endif